2 * linux/arch/alpha/kernel/sys_titan.c
4 * Copyright (C) 1995 David A Rusling
5 * Copyright (C) 1996, 1999 Jay A Estabrook
6 * Copyright (C) 1998, 1999 Richard Henderson
7 * Copyright (C) 1999, 2000 Jeff Wiedemeier
9 * Code supporting TITAN systems (EV6+TITAN), currently:
15 #include <linux/kernel.h>
16 #include <linux/types.h>
18 #include <linux/sched.h>
19 #include <linux/pci.h>
20 #include <linux/init.h>
21 #include <linux/bitops.h>
23 #include <asm/ptrace.h>
24 #include <asm/system.h>
27 #include <asm/mmu_context.h>
29 #include <asm/pgtable.h>
30 #include <asm/core_titan.h>
31 #include <asm/hwrpb.h>
32 #include <asm/tlbflush.h>
37 #include "machvec_impl.h"
46 * Titan supports up to 4 CPUs
48 static unsigned long titan_cpu_irq_affinity[4] = { ~0UL, ~0UL, ~0UL, ~0UL };
51 * Mask is set (1) if enabled
53 static unsigned long titan_cached_irq_mask;
56 * Need SMP-safe access to interrupt CSRs
58 DEFINE_SPINLOCK(titan_irq_lock);
61 titan_update_irq_hw(unsigned long mask)
63 register titan_cchip *cchip = TITAN_cchip;
64 unsigned long isa_enable = 1UL << 55;
65 register int bcpu = boot_cpuid;
69 volatile unsigned long *dim0, *dim1, *dim2, *dim3;
70 unsigned long mask0, mask1, mask2, mask3, dummy;
72 cpumask_copy(&cpm, cpu_present_mask);
74 mask0 = mask & titan_cpu_irq_affinity[0];
75 mask1 = mask & titan_cpu_irq_affinity[1];
76 mask2 = mask & titan_cpu_irq_affinity[2];
77 mask3 = mask & titan_cpu_irq_affinity[3];
79 if (bcpu == 0) mask0 |= isa_enable;
80 else if (bcpu == 1) mask1 |= isa_enable;
81 else if (bcpu == 2) mask2 |= isa_enable;
82 else mask3 |= isa_enable;
84 dim0 = &cchip->dim0.csr;
85 dim1 = &cchip->dim1.csr;
86 dim2 = &cchip->dim2.csr;
87 dim3 = &cchip->dim3.csr;
88 if (!cpumask_test_cpu(0, &cpm)) dim0 = &dummy;
89 if (!cpumask_test_cpu(1, &cpm)) dim1 = &dummy;
90 if (!cpumask_test_cpu(2, &cpm)) dim2 = &dummy;
91 if (!cpumask_test_cpu(3, &cpm)) dim3 = &dummy;
103 volatile unsigned long *dimB;
104 dimB = &cchip->dim0.csr;
105 if (bcpu == 1) dimB = &cchip->dim1.csr;
106 else if (bcpu == 2) dimB = &cchip->dim2.csr;
107 else if (bcpu == 3) dimB = &cchip->dim3.csr;
109 *dimB = mask | isa_enable;
116 titan_enable_irq(struct irq_data *d)
118 unsigned int irq = d->irq;
119 spin_lock(&titan_irq_lock);
120 titan_cached_irq_mask |= 1UL << (irq - 16);
121 titan_update_irq_hw(titan_cached_irq_mask);
122 spin_unlock(&titan_irq_lock);
126 titan_disable_irq(struct irq_data *d)
128 unsigned int irq = d->irq;
129 spin_lock(&titan_irq_lock);
130 titan_cached_irq_mask &= ~(1UL << (irq - 16));
131 titan_update_irq_hw(titan_cached_irq_mask);
132 spin_unlock(&titan_irq_lock);
136 titan_cpu_set_irq_affinity(unsigned int irq, cpumask_t affinity)
140 for (cpu = 0; cpu < 4; cpu++) {
141 if (cpumask_test_cpu(cpu, &affinity))
142 titan_cpu_irq_affinity[cpu] |= 1UL << irq;
144 titan_cpu_irq_affinity[cpu] &= ~(1UL << irq);
150 titan_set_irq_affinity(struct irq_data *d, const struct cpumask *affinity,
153 unsigned int irq = d->irq;
154 spin_lock(&titan_irq_lock);
155 titan_cpu_set_irq_affinity(irq - 16, *affinity);
156 titan_update_irq_hw(titan_cached_irq_mask);
157 spin_unlock(&titan_irq_lock);
163 titan_device_interrupt(unsigned long vector)
165 printk("titan_device_interrupt: NOT IMPLEMENTED YET!!\n");
169 titan_srm_device_interrupt(unsigned long vector)
173 irq = (vector - 0x800) >> 4;
179 init_titan_irqs(struct irq_chip * ops, int imin, int imax)
182 for (i = imin; i <= imax; ++i) {
183 irq_set_chip_and_handler(i, ops, handle_level_irq);
184 irq_set_status_flags(i, IRQ_LEVEL);
188 static struct irq_chip titan_irq_type = {
190 .irq_unmask = titan_enable_irq,
191 .irq_mask = titan_disable_irq,
192 .irq_mask_ack = titan_disable_irq,
193 .irq_set_affinity = titan_set_irq_affinity,
197 titan_intr_nop(int irq, void *dev_id)
200 * This is a NOP interrupt handler for the purposes of
201 * event counting -- just return.
209 if (alpha_using_srm && !alpha_mv.device_interrupt)
210 alpha_mv.device_interrupt = titan_srm_device_interrupt;
211 if (!alpha_mv.device_interrupt)
212 alpha_mv.device_interrupt = titan_device_interrupt;
214 titan_update_irq_hw(0);
216 init_titan_irqs(&titan_irq_type, 16, 63 + 16);
220 titan_legacy_init_irq(void)
222 /* init the legacy dma controller */
223 outb(0, DMA1_RESET_REG);
224 outb(0, DMA2_RESET_REG);
225 outb(DMA_MODE_CASCADE, DMA2_MODE_REG);
226 outb(0, DMA2_MASK_REG);
228 /* init the legacy irq controller */
231 /* init the titan irqs */
236 titan_dispatch_irqs(u64 mask)
238 unsigned long vector;
241 * Mask down to those interrupts which are enable on this processor
243 mask &= titan_cpu_irq_affinity[smp_processor_id()];
246 * Dispatch all requested interrupts
249 /* convert to SRM vector... priority is <63> -> <0> */
250 vector = 63 - __kernel_ctlz(mask);
251 mask &= ~(1UL << vector); /* clear it out */
252 vector = 0x900 + (vector << 4); /* convert to SRM vector */
255 alpha_mv.device_interrupt(vector);
264 titan_request_irq(unsigned int irq, irq_handler_t handler,
265 unsigned long irqflags, const char *devname,
269 err = request_irq(irq, handler, irqflags, devname, dev_id);
271 printk("titan_request_irq for IRQ %d returned %d; ignoring\n",
277 titan_late_init(void)
280 * Enable the system error interrupts. These interrupts are
281 * all reported to the kernel as machine checks, so the handler
282 * is a nop so it can be called to count the individual events.
284 titan_request_irq(63+16, titan_intr_nop, IRQF_DISABLED,
285 "CChip Error", NULL);
286 titan_request_irq(62+16, titan_intr_nop, IRQF_DISABLED,
287 "PChip 0 H_Error", NULL);
288 titan_request_irq(61+16, titan_intr_nop, IRQF_DISABLED,
289 "PChip 1 H_Error", NULL);
290 titan_request_irq(60+16, titan_intr_nop, IRQF_DISABLED,
291 "PChip 0 C_Error", NULL);
292 titan_request_irq(59+16, titan_intr_nop, IRQF_DISABLED,
293 "PChip 1 C_Error", NULL);
296 * Register our error handlers.
298 titan_register_error_handlers();
301 * Check if the console left us any error logs.
303 cdl_check_console_data_log();
308 titan_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
313 /* Get the current intline. */
314 pci_read_config_byte(dev, PCI_INTERRUPT_LINE, &intline);
317 /* Is it explicitly routed through ISA? */
318 if ((irq & 0xF0) == 0xE0)
321 /* Offset by 16 to make room for ISA interrupts 0 - 15. */
329 * This isn't really the right place, but there's some init
330 * that needs to be done after everything is basically up.
337 locate_and_init_vga(NULL);
345 privateer_init_pci(void)
348 * Hook a couple of extra err interrupts that the
349 * common titan code won't.
351 titan_request_irq(53+16, titan_intr_nop, IRQF_DISABLED,
353 titan_request_irq(50+16, titan_intr_nop, IRQF_DISABLED,
354 "Temperature Warning", NULL);
357 * Finish with the common version.
359 return titan_init_pci();
364 * The System Vectors.
366 struct alpha_machine_vector titan_mv __initmv = {
367 .vector_name = "TITAN",
371 .machine_check = titan_machine_check,
372 .max_isa_dma_address = ALPHA_MAX_ISA_DMA_ADDRESS,
373 .min_io_address = DEFAULT_IO_BASE,
374 .min_mem_address = DEFAULT_MEM_BASE,
375 .pci_dac_offset = TITAN_DAC_OFFSET,
377 .nr_irqs = 80, /* 64 + 16 */
378 /* device_interrupt will be filled in by titan_init_irq */
380 .agp_info = titan_agp_info,
382 .init_arch = titan_init_arch,
383 .init_irq = titan_legacy_init_irq,
384 .init_rtc = common_init_rtc,
385 .init_pci = titan_init_pci,
387 .kill_arch = titan_kill_arch,
388 .pci_map_irq = titan_map_irq,
389 .pci_swizzle = common_swizzle,
393 struct alpha_machine_vector privateer_mv __initmv = {
394 .vector_name = "PRIVATEER",
398 .machine_check = privateer_machine_check,
399 .max_isa_dma_address = ALPHA_MAX_ISA_DMA_ADDRESS,
400 .min_io_address = DEFAULT_IO_BASE,
401 .min_mem_address = DEFAULT_MEM_BASE,
402 .pci_dac_offset = TITAN_DAC_OFFSET,
404 .nr_irqs = 80, /* 64 + 16 */
405 /* device_interrupt will be filled in by titan_init_irq */
407 .agp_info = titan_agp_info,
409 .init_arch = titan_init_arch,
410 .init_irq = titan_legacy_init_irq,
411 .init_rtc = common_init_rtc,
412 .init_pci = privateer_init_pci,
414 .kill_arch = titan_kill_arch,
415 .pci_map_irq = titan_map_irq,
416 .pci_swizzle = common_swizzle,
418 /* No alpha_mv alias for privateer since we compile it
419 in unconditionally with titan; setup_arch knows how to cope. */