2 * linux/arch/alpha/kernel/sys_sable.c
4 * Copyright (C) 1995 David A Rusling
5 * Copyright (C) 1996 Jay A Estabrook
6 * Copyright (C) 1998, 1999 Richard Henderson
8 * Code supporting the Sable, Sable-Gamma, and Lynx systems.
11 #include <linux/config.h>
12 #include <linux/kernel.h>
13 #include <linux/types.h>
15 #include <linux/sched.h>
16 #include <linux/pci.h>
17 #include <linux/init.h>
19 #include <asm/ptrace.h>
20 #include <asm/system.h>
23 #include <asm/mmu_context.h>
25 #include <asm/pgtable.h>
26 #include <asm/core_t2.h>
27 #include <asm/tlbflush.h>
32 #include "machvec_impl.h"
34 DEFINE_SPINLOCK(sable_lynx_irq_lock);
36 typedef struct irq_swizzle_struct
41 /* Note mask bit is true for DISABLED irqs. */
42 unsigned long shadow_mask;
44 void (*update_irq_hw)(unsigned long bit, unsigned long mask);
45 void (*ack_irq_hw)(unsigned long bit);
49 static irq_swizzle_t *sable_lynx_irq_swizzle;
51 static void sable_lynx_init_irq(int nr_irqs);
53 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_SABLE)
55 /***********************************************************************/
57 * For SABLE, which is really baroque, we manage 40 IRQ's, but the
58 * hardware really only supports 24, not via normal ISA PIC,
59 * but cascaded custom 8259's, etc.
64 * Summary Registers (536/53a/53c):
66 * Bit Meaning Kernel IRQ
67 *------------------------------------------
69 * 1 NCR810 (builtin) 33
70 * 2 TULIP (builtin) 32
95 sable_update_irq_hw(unsigned long bit, unsigned long mask)
102 } else if (bit >= 8) {
111 sable_ack_irq_hw(unsigned long bit)
113 int port, val1, val2;
117 val1 = 0xE0 | (bit - 16);
119 } else if (bit >= 8) {
121 val1 = 0xE0 | (bit - 8);
125 val1 = 0xE0 | (bit - 0);
129 outb(val1, port); /* ack the slave */
130 outb(val2, 0x534); /* ack the master */
133 static irq_swizzle_t sable_irq_swizzle = {
135 -1, 6, -1, 8, 15, 12, 7, 9, /* pseudo PIC 0-7 */
136 -1, 16, 17, 18, 3, -1, 21, 22, /* pseudo PIC 8-15 */
137 -1, -1, -1, -1, -1, -1, -1, -1, /* pseudo EISA 0-7 */
138 -1, -1, -1, -1, -1, -1, -1, -1, /* pseudo EISA 8-15 */
139 2, 1, 0, 4, 5, -1, -1, -1, /* pseudo PCI */
140 -1, -1, -1, -1, -1, -1, -1, -1, /* */
141 -1, -1, -1, -1, -1, -1, -1, -1, /* */
142 -1, -1, -1, -1, -1, -1, -1, -1 /* */
145 34, 33, 32, 12, 35, 36, 1, 6, /* mask 0-7 */
146 3, 7, -1, -1, 5, -1, -1, 4, /* mask 8-15 */
147 9, 10, 11, -1, -1, 14, 15, -1, /* mask 16-23 */
148 -1, -1, -1, -1, -1, -1, -1, -1, /* */
149 -1, -1, -1, -1, -1, -1, -1, -1, /* */
150 -1, -1, -1, -1, -1, -1, -1, -1, /* */
151 -1, -1, -1, -1, -1, -1, -1, -1, /* */
152 -1, -1, -1, -1, -1, -1, -1, -1 /* */
162 outb(-1, 0x537); /* slave 0 */
163 outb(-1, 0x53b); /* slave 1 */
164 outb(-1, 0x53d); /* slave 2 */
165 outb(0x44, 0x535); /* enable cascades in master */
167 sable_lynx_irq_swizzle = &sable_irq_swizzle;
168 sable_lynx_init_irq(40);
172 * PCI Fixup configuration for ALPHA SABLE (2100).
174 * The device to slot mapping looks like:
183 * 6 PCI on board slot 0
184 * 7 PCI on board slot 1
185 * 8 PCI on board slot 2
188 * This two layered interrupt approach means that we allocate IRQ 16 and
189 * above for PCI interrupts. The IRQ relates to which bit the interrupt
190 * comes in on. This makes interrupt processing much easier.
193 * NOTE: the IRQ assignments below are arbitrary, but need to be consistent
194 * with the values in the irq swizzling tables above.
198 sable_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
200 static char irq_tab[9][5] __initdata = {
201 /*INT INTA INTB INTC INTD */
202 { 32+0, 32+0, 32+0, 32+0, 32+0}, /* IdSel 0, TULIP */
203 { 32+1, 32+1, 32+1, 32+1, 32+1}, /* IdSel 1, SCSI */
204 { -1, -1, -1, -1, -1}, /* IdSel 2, SIO */
205 { -1, -1, -1, -1, -1}, /* IdSel 3, none */
206 { -1, -1, -1, -1, -1}, /* IdSel 4, none */
207 { -1, -1, -1, -1, -1}, /* IdSel 5, none */
208 { 32+2, 32+2, 32+2, 32+2, 32+2}, /* IdSel 6, slot 0 */
209 { 32+3, 32+3, 32+3, 32+3, 32+3}, /* IdSel 7, slot 1 */
210 { 32+4, 32+4, 32+4, 32+4, 32+4} /* IdSel 8, slot 2 */
212 long min_idsel = 0, max_idsel = 8, irqs_per_slot = 5;
213 return COMMON_TABLE_LOOKUP;
215 #endif /* defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_SABLE) */
217 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_LYNX)
219 /***********************************************************************/
220 /* LYNX hardware specifics
223 * For LYNX, which is also baroque, we manage 64 IRQs, via a custom IC.
225 * Bit Meaning Kernel IRQ
226 *------------------------------------------
255 *28 NCR810 (builtin) 28
259 *32 PCI 0 slot 4 A primary bus 32
260 *33 PCI 0 slot 4 B primary bus 33
261 *34 PCI 0 slot 4 C primary bus 34
262 *35 PCI 0 slot 4 D primary bus
263 *36 PCI 0 slot 5 A primary bus
264 *37 PCI 0 slot 5 B primary bus
265 *38 PCI 0 slot 5 C primary bus
266 *39 PCI 0 slot 5 D primary bus
267 *40 PCI 0 slot 6 A primary bus
268 *41 PCI 0 slot 6 B primary bus
269 *42 PCI 0 slot 6 C primary bus
270 *43 PCI 0 slot 6 D primary bus
271 *44 PCI 0 slot 7 A primary bus
272 *45 PCI 0 slot 7 B primary bus
273 *46 PCI 0 slot 7 C primary bus
274 *47 PCI 0 slot 7 D primary bus
275 *48 PCI 0 slot 0 A secondary bus
276 *49 PCI 0 slot 0 B secondary bus
277 *50 PCI 0 slot 0 C secondary bus
278 *51 PCI 0 slot 0 D secondary bus
279 *52 PCI 0 slot 1 A secondary bus
280 *53 PCI 0 slot 1 B secondary bus
281 *54 PCI 0 slot 1 C secondary bus
282 *55 PCI 0 slot 1 D secondary bus
283 *56 PCI 0 slot 2 A secondary bus
284 *57 PCI 0 slot 2 B secondary bus
285 *58 PCI 0 slot 2 C secondary bus
286 *59 PCI 0 slot 2 D secondary bus
287 *60 PCI 0 slot 3 A secondary bus
288 *61 PCI 0 slot 3 B secondary bus
289 *62 PCI 0 slot 3 C secondary bus
290 *63 PCI 0 slot 3 D secondary bus
294 lynx_update_irq_hw(unsigned long bit, unsigned long mask)
297 * Write the AIR register on the T3/T4 with the
298 * address of the IC mask register (offset 0x40)
300 *(vulp)T2_AIR = 0x40;
302 *(vulp)T2_AIR; /* re-read to force write */
304 *(vulp)T2_DIR = mask;
310 lynx_ack_irq_hw(unsigned long bit)
312 *(vulp)T2_VAR = (u_long) bit;
317 static irq_swizzle_t lynx_irq_swizzle = {
319 -1, 6, -1, 8, 15, 12, 7, 9, /* pseudo PIC 0-7 */
320 -1, 16, 17, 18, 3, -1, 21, 22, /* pseudo PIC 8-15 */
321 -1, -1, -1, -1, -1, -1, -1, -1, /* pseudo */
322 -1, -1, -1, -1, 28, -1, -1, -1, /* pseudo */
323 32, 33, 34, 35, 36, 37, 38, 39, /* mask 32-39 */
324 40, 41, 42, 43, 44, 45, 46, 47, /* mask 40-47 */
325 48, 49, 50, 51, 52, 53, 54, 55, /* mask 48-55 */
326 56, 57, 58, 59, 60, 61, 62, 63 /* mask 56-63 */
329 -1, -1, -1, 12, -1, -1, 1, 6, /* mask 0-7 */
330 3, 7, -1, -1, 5, -1, -1, 4, /* mask 8-15 */
331 9, 10, 11, -1, -1, 14, 15, -1, /* mask 16-23 */
332 -1, -1, -1, -1, 28, -1, -1, -1, /* mask 24-31 */
333 32, 33, 34, 35, 36, 37, 38, 39, /* mask 32-39 */
334 40, 41, 42, 43, 44, 45, 46, 47, /* mask 40-47 */
335 48, 49, 50, 51, 52, 53, 54, 55, /* mask 48-55 */
336 56, 57, 58, 59, 60, 61, 62, 63 /* mask 56-63 */
346 sable_lynx_irq_swizzle = &lynx_irq_swizzle;
347 sable_lynx_init_irq(64);
351 * PCI Fixup configuration for ALPHA LYNX (2100A)
353 * The device to slot mapping looks like:
360 * 4 NCR 810 (Demi-Lynx only)
362 * 6 PCI on board slot 4
363 * 7 PCI on board slot 5
364 * 8 PCI on board slot 6
365 * 9 PCI on board slot 7
367 * And behind the PPB we have:
369 * 11 PCI on board slot 0
370 * 12 PCI on board slot 1
371 * 13 PCI on board slot 2
372 * 14 PCI on board slot 3
375 * NOTE: the IRQ assignments below are arbitrary, but need to be consistent
376 * with the values in the irq swizzling tables above.
380 lynx_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
382 static char irq_tab[19][5] __initdata = {
383 /*INT INTA INTB INTC INTD */
384 { -1, -1, -1, -1, -1}, /* IdSel 13, PCEB */
385 { -1, -1, -1, -1, -1}, /* IdSel 14, PPB */
386 { 28, 28, 28, 28, 28}, /* IdSel 15, NCR demi */
387 { -1, -1, -1, -1, -1}, /* IdSel 16, none */
388 { 32, 32, 33, 34, 35}, /* IdSel 17, slot 4 */
389 { 36, 36, 37, 38, 39}, /* IdSel 18, slot 5 */
390 { 40, 40, 41, 42, 43}, /* IdSel 19, slot 6 */
391 { 44, 44, 45, 46, 47}, /* IdSel 20, slot 7 */
392 { -1, -1, -1, -1, -1}, /* IdSel 22, none */
393 /* The following are actually behind the PPB. */
394 { -1, -1, -1, -1, -1}, /* IdSel 16 none */
395 { 28, 28, 28, 28, 28}, /* IdSel 17 NCR lynx */
396 { -1, -1, -1, -1, -1}, /* IdSel 18 none */
397 { -1, -1, -1, -1, -1}, /* IdSel 19 none */
398 { -1, -1, -1, -1, -1}, /* IdSel 20 none */
399 { -1, -1, -1, -1, -1}, /* IdSel 21 none */
400 { 48, 48, 49, 50, 51}, /* IdSel 22 slot 0 */
401 { 52, 52, 53, 54, 55}, /* IdSel 23 slot 1 */
402 { 56, 56, 57, 58, 59}, /* IdSel 24 slot 2 */
403 { 60, 60, 61, 62, 63} /* IdSel 25 slot 3 */
405 const long min_idsel = 2, max_idsel = 20, irqs_per_slot = 5;
406 return COMMON_TABLE_LOOKUP;
410 lynx_swizzle(struct pci_dev *dev, u8 *pinp)
412 int slot, pin = *pinp;
414 if (dev->bus->number == 0) {
415 slot = PCI_SLOT(dev->devfn);
417 /* Check for the built-in bridge */
418 else if (PCI_SLOT(dev->bus->self->devfn) == 3) {
419 slot = PCI_SLOT(dev->devfn) + 11;
423 /* Must be a card-based bridge. */
425 if (PCI_SLOT(dev->bus->self->devfn) == 3) {
426 slot = PCI_SLOT(dev->devfn) + 11;
429 pin = bridge_swizzle(pin, PCI_SLOT(dev->devfn)) ;
431 /* Move up the chain of bridges. */
432 dev = dev->bus->self;
433 /* Slot of the next bridge. */
434 slot = PCI_SLOT(dev->devfn);
435 } while (dev->bus->self);
441 #endif /* defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_LYNX) */
443 /***********************************************************************/
444 /* GENERIC irq routines */
447 sable_lynx_enable_irq(unsigned int irq)
449 unsigned long bit, mask;
451 bit = sable_lynx_irq_swizzle->irq_to_mask[irq];
452 spin_lock(&sable_lynx_irq_lock);
453 mask = sable_lynx_irq_swizzle->shadow_mask &= ~(1UL << bit);
454 sable_lynx_irq_swizzle->update_irq_hw(bit, mask);
455 spin_unlock(&sable_lynx_irq_lock);
457 printk("%s: mask 0x%lx bit 0x%x irq 0x%x\n",
458 __FUNCTION__, mask, bit, irq);
463 sable_lynx_disable_irq(unsigned int irq)
465 unsigned long bit, mask;
467 bit = sable_lynx_irq_swizzle->irq_to_mask[irq];
468 spin_lock(&sable_lynx_irq_lock);
469 mask = sable_lynx_irq_swizzle->shadow_mask |= 1UL << bit;
470 sable_lynx_irq_swizzle->update_irq_hw(bit, mask);
471 spin_unlock(&sable_lynx_irq_lock);
473 printk("%s: mask 0x%lx bit 0x%x irq 0x%x\n",
474 __FUNCTION__, mask, bit, irq);
479 sable_lynx_startup_irq(unsigned int irq)
481 sable_lynx_enable_irq(irq);
486 sable_lynx_end_irq(unsigned int irq)
488 if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
489 sable_lynx_enable_irq(irq);
493 sable_lynx_mask_and_ack_irq(unsigned int irq)
495 unsigned long bit, mask;
497 bit = sable_lynx_irq_swizzle->irq_to_mask[irq];
498 spin_lock(&sable_lynx_irq_lock);
499 mask = sable_lynx_irq_swizzle->shadow_mask |= 1UL << bit;
500 sable_lynx_irq_swizzle->update_irq_hw(bit, mask);
501 sable_lynx_irq_swizzle->ack_irq_hw(bit);
502 spin_unlock(&sable_lynx_irq_lock);
505 static struct hw_interrupt_type sable_lynx_irq_type = {
506 .typename = "SABLE/LYNX",
507 .startup = sable_lynx_startup_irq,
508 .shutdown = sable_lynx_disable_irq,
509 .enable = sable_lynx_enable_irq,
510 .disable = sable_lynx_disable_irq,
511 .ack = sable_lynx_mask_and_ack_irq,
512 .end = sable_lynx_end_irq,
516 sable_lynx_srm_device_interrupt(unsigned long vector, struct pt_regs * regs)
518 /* Note that the vector reported by the SRM PALcode corresponds
519 to the interrupt mask bits, but we have to manage via the
520 so-called legacy IRQs for many common devices. */
524 bit = (vector - 0x800) >> 4;
525 irq = sable_lynx_irq_swizzle->mask_to_irq[bit];
527 printk("%s: vector 0x%lx bit 0x%x irq 0x%x\n",
528 __FUNCTION__, vector, bit, irq);
530 handle_irq(irq, regs);
534 sable_lynx_init_irq(int nr_irqs)
538 for (i = 0; i < nr_irqs; ++i) {
539 irq_desc[i].status = IRQ_DISABLED | IRQ_LEVEL;
540 irq_desc[i].chip = &sable_lynx_irq_type;
543 common_init_isa_dma();
547 sable_lynx_init_pci(void)
552 /*****************************************************************/
556 * In order that T2_HAE_ADDRESS should be a constant, we play
557 * these games with GAMMA_BIAS.
560 #if defined(CONFIG_ALPHA_GENERIC) || \
561 (defined(CONFIG_ALPHA_SABLE) && !defined(CONFIG_ALPHA_GAMMA))
564 struct alpha_machine_vector sable_mv __initmv = {
565 .vector_name = "Sable",
569 .machine_check = t2_machine_check,
570 .max_isa_dma_address = ALPHA_SABLE_MAX_ISA_DMA_ADDRESS,
571 .min_io_address = EISA_DEFAULT_IO_BASE,
572 .min_mem_address = T2_DEFAULT_MEM_BASE,
575 .device_interrupt = sable_lynx_srm_device_interrupt,
577 .init_arch = t2_init_arch,
578 .init_irq = sable_init_irq,
579 .init_rtc = common_init_rtc,
580 .init_pci = sable_lynx_init_pci,
581 .kill_arch = t2_kill_arch,
582 .pci_map_irq = sable_map_irq,
583 .pci_swizzle = common_swizzle,
590 #endif /* GENERIC || (SABLE && !GAMMA) */
592 #if defined(CONFIG_ALPHA_GENERIC) || \
593 (defined(CONFIG_ALPHA_SABLE) && defined(CONFIG_ALPHA_GAMMA))
595 #define GAMMA_BIAS _GAMMA_BIAS
596 struct alpha_machine_vector sable_gamma_mv __initmv = {
597 .vector_name = "Sable-Gamma",
601 .machine_check = t2_machine_check,
602 .max_isa_dma_address = ALPHA_SABLE_MAX_ISA_DMA_ADDRESS,
603 .min_io_address = EISA_DEFAULT_IO_BASE,
604 .min_mem_address = T2_DEFAULT_MEM_BASE,
607 .device_interrupt = sable_lynx_srm_device_interrupt,
609 .init_arch = t2_init_arch,
610 .init_irq = sable_init_irq,
611 .init_rtc = common_init_rtc,
612 .init_pci = sable_lynx_init_pci,
613 .kill_arch = t2_kill_arch,
614 .pci_map_irq = sable_map_irq,
615 .pci_swizzle = common_swizzle,
618 .gamma_bias = _GAMMA_BIAS
621 ALIAS_MV(sable_gamma)
622 #endif /* GENERIC || (SABLE && GAMMA) */
624 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_LYNX)
626 #define GAMMA_BIAS _GAMMA_BIAS
627 struct alpha_machine_vector lynx_mv __initmv = {
628 .vector_name = "Lynx",
632 .machine_check = t2_machine_check,
633 .max_isa_dma_address = ALPHA_SABLE_MAX_ISA_DMA_ADDRESS,
634 .min_io_address = EISA_DEFAULT_IO_BASE,
635 .min_mem_address = T2_DEFAULT_MEM_BASE,
638 .device_interrupt = sable_lynx_srm_device_interrupt,
640 .init_arch = t2_init_arch,
641 .init_irq = lynx_init_irq,
642 .init_rtc = common_init_rtc,
643 .init_pci = sable_lynx_init_pci,
644 .kill_arch = t2_kill_arch,
645 .pci_map_irq = lynx_map_irq,
646 .pci_swizzle = lynx_swizzle,
649 .gamma_bias = _GAMMA_BIAS
653 #endif /* GENERIC || LYNX */