sys_noritake.c 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. /*
  2. * linux/arch/alpha/kernel/sys_noritake.c
  3. *
  4. * Copyright (C) 1995 David A Rusling
  5. * Copyright (C) 1996 Jay A Estabrook
  6. * Copyright (C) 1998, 1999 Richard Henderson
  7. *
  8. * Code supporting the NORITAKE (AlphaServer 1000A),
  9. * CORELLE (AlphaServer 800), and ALCOR Primo (AlphaStation 600A).
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/types.h>
  13. #include <linux/mm.h>
  14. #include <linux/sched.h>
  15. #include <linux/pci.h>
  16. #include <linux/init.h>
  17. #include <linux/bitops.h>
  18. #include <asm/ptrace.h>
  19. #include <asm/mce.h>
  20. #include <asm/dma.h>
  21. #include <asm/irq.h>
  22. #include <asm/mmu_context.h>
  23. #include <asm/io.h>
  24. #include <asm/pgtable.h>
  25. #include <asm/core_apecs.h>
  26. #include <asm/core_cia.h>
  27. #include <asm/tlbflush.h>
  28. #include "proto.h"
  29. #include "irq_impl.h"
  30. #include "pci_impl.h"
  31. #include "machvec_impl.h"
  32. /* Note mask bit is true for ENABLED irqs. */
  33. static int cached_irq_mask;
  34. static inline void
  35. noritake_update_irq_hw(int irq, int mask)
  36. {
  37. int port = 0x54a;
  38. if (irq >= 32) {
  39. mask >>= 16;
  40. port = 0x54c;
  41. }
  42. outw(mask, port);
  43. }
  44. static void
  45. noritake_enable_irq(struct irq_data *d)
  46. {
  47. noritake_update_irq_hw(d->irq, cached_irq_mask |= 1 << (d->irq - 16));
  48. }
  49. static void
  50. noritake_disable_irq(struct irq_data *d)
  51. {
  52. noritake_update_irq_hw(d->irq, cached_irq_mask &= ~(1 << (d->irq - 16)));
  53. }
  54. static struct irq_chip noritake_irq_type = {
  55. .name = "NORITAKE",
  56. .irq_unmask = noritake_enable_irq,
  57. .irq_mask = noritake_disable_irq,
  58. .irq_mask_ack = noritake_disable_irq,
  59. };
  60. static void
  61. noritake_device_interrupt(unsigned long vector)
  62. {
  63. unsigned long pld;
  64. unsigned int i;
  65. /* Read the interrupt summary registers of NORITAKE */
  66. pld = (((unsigned long) inw(0x54c) << 32)
  67. | ((unsigned long) inw(0x54a) << 16)
  68. | ((unsigned long) inb(0xa0) << 8)
  69. | inb(0x20));
  70. /*
  71. * Now for every possible bit set, work through them and call
  72. * the appropriate interrupt handler.
  73. */
  74. while (pld) {
  75. i = ffz(~pld);
  76. pld &= pld - 1; /* clear least bit set */
  77. if (i < 16) {
  78. isa_device_interrupt(vector);
  79. } else {
  80. handle_irq(i);
  81. }
  82. }
  83. }
  84. static void
  85. noritake_srm_device_interrupt(unsigned long vector)
  86. {
  87. int irq;
  88. irq = (vector - 0x800) >> 4;
  89. /*
  90. * I really hate to do this, too, but the NORITAKE SRM console also
  91. * reports PCI vectors *lower* than I expected from the bit numbers
  92. * in the documentation.
  93. * But I really don't want to change the fixup code for allocation
  94. * of IRQs, nor the alpha_irq_mask maintenance stuff, both of which
  95. * look nice and clean now.
  96. * So, here's this additional grotty hack... :-(
  97. */
  98. if (irq >= 16)
  99. irq = irq + 1;
  100. handle_irq(irq);
  101. }
  102. static void __init
  103. noritake_init_irq(void)
  104. {
  105. long i;
  106. if (alpha_using_srm)
  107. alpha_mv.device_interrupt = noritake_srm_device_interrupt;
  108. outw(0, 0x54a);
  109. outw(0, 0x54c);
  110. for (i = 16; i < 48; ++i) {
  111. irq_set_chip_and_handler(i, &noritake_irq_type,
  112. handle_level_irq);
  113. irq_set_status_flags(i, IRQ_LEVEL);
  114. }
  115. init_i8259a_irqs();
  116. common_init_isa_dma();
  117. }
  118. /*
  119. * PCI Fixup configuration.
  120. *
  121. * Summary @ 0x542, summary register #1:
  122. * Bit Meaning
  123. * 0 All valid ints from summary regs 2 & 3
  124. * 1 QLOGIC ISP1020A SCSI
  125. * 2 Interrupt Line A from slot 0
  126. * 3 Interrupt Line B from slot 0
  127. * 4 Interrupt Line A from slot 1
  128. * 5 Interrupt line B from slot 1
  129. * 6 Interrupt Line A from slot 2
  130. * 7 Interrupt Line B from slot 2
  131. * 8 Interrupt Line A from slot 3
  132. * 9 Interrupt Line B from slot 3
  133. *10 Interrupt Line A from slot 4
  134. *11 Interrupt Line B from slot 4
  135. *12 Interrupt Line A from slot 5
  136. *13 Interrupt Line B from slot 5
  137. *14 Interrupt Line A from slot 6
  138. *15 Interrupt Line B from slot 6
  139. *
  140. * Summary @ 0x544, summary register #2:
  141. * Bit Meaning
  142. * 0 OR of all unmasked ints in SR #2
  143. * 1 OR of secondary bus ints
  144. * 2 Interrupt Line C from slot 0
  145. * 3 Interrupt Line D from slot 0
  146. * 4 Interrupt Line C from slot 1
  147. * 5 Interrupt line D from slot 1
  148. * 6 Interrupt Line C from slot 2
  149. * 7 Interrupt Line D from slot 2
  150. * 8 Interrupt Line C from slot 3
  151. * 9 Interrupt Line D from slot 3
  152. *10 Interrupt Line C from slot 4
  153. *11 Interrupt Line D from slot 4
  154. *12 Interrupt Line C from slot 5
  155. *13 Interrupt Line D from slot 5
  156. *14 Interrupt Line C from slot 6
  157. *15 Interrupt Line D from slot 6
  158. *
  159. * The device to slot mapping looks like:
  160. *
  161. * Slot Device
  162. * 7 Intel PCI-EISA bridge chip
  163. * 8 DEC PCI-PCI bridge chip
  164. * 11 PCI on board slot 0
  165. * 12 PCI on board slot 1
  166. * 13 PCI on board slot 2
  167. *
  168. *
  169. * This two layered interrupt approach means that we allocate IRQ 16 and
  170. * above for PCI interrupts. The IRQ relates to which bit the interrupt
  171. * comes in on. This makes interrupt processing much easier.
  172. */
  173. static int __init
  174. noritake_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
  175. {
  176. static char irq_tab[15][5] __initdata = {
  177. /*INT INTA INTB INTC INTD */
  178. /* note: IDSELs 16, 17, and 25 are CORELLE only */
  179. { 16+1, 16+1, 16+1, 16+1, 16+1}, /* IdSel 16, QLOGIC */
  180. { -1, -1, -1, -1, -1}, /* IdSel 17, S3 Trio64 */
  181. { -1, -1, -1, -1, -1}, /* IdSel 18, PCEB */
  182. { -1, -1, -1, -1, -1}, /* IdSel 19, PPB */
  183. { -1, -1, -1, -1, -1}, /* IdSel 20, ???? */
  184. { -1, -1, -1, -1, -1}, /* IdSel 21, ???? */
  185. { 16+2, 16+2, 16+3, 32+2, 32+3}, /* IdSel 22, slot 0 */
  186. { 16+4, 16+4, 16+5, 32+4, 32+5}, /* IdSel 23, slot 1 */
  187. { 16+6, 16+6, 16+7, 32+6, 32+7}, /* IdSel 24, slot 2 */
  188. { 16+8, 16+8, 16+9, 32+8, 32+9}, /* IdSel 25, slot 3 */
  189. /* The following 5 are actually on PCI bus 1, which is
  190. across the built-in bridge of the NORITAKE only. */
  191. { 16+1, 16+1, 16+1, 16+1, 16+1}, /* IdSel 16, QLOGIC */
  192. { 16+8, 16+8, 16+9, 32+8, 32+9}, /* IdSel 17, slot 3 */
  193. {16+10, 16+10, 16+11, 32+10, 32+11}, /* IdSel 18, slot 4 */
  194. {16+12, 16+12, 16+13, 32+12, 32+13}, /* IdSel 19, slot 5 */
  195. {16+14, 16+14, 16+15, 32+14, 32+15}, /* IdSel 20, slot 6 */
  196. };
  197. const long min_idsel = 5, max_idsel = 19, irqs_per_slot = 5;
  198. return COMMON_TABLE_LOOKUP;
  199. }
  200. static u8 __init
  201. noritake_swizzle(struct pci_dev *dev, u8 *pinp)
  202. {
  203. int slot, pin = *pinp;
  204. if (dev->bus->number == 0) {
  205. slot = PCI_SLOT(dev->devfn);
  206. }
  207. /* Check for the built-in bridge */
  208. else if (PCI_SLOT(dev->bus->self->devfn) == 8) {
  209. slot = PCI_SLOT(dev->devfn) + 15; /* WAG! */
  210. }
  211. else
  212. {
  213. /* Must be a card-based bridge. */
  214. do {
  215. if (PCI_SLOT(dev->bus->self->devfn) == 8) {
  216. slot = PCI_SLOT(dev->devfn) + 15;
  217. break;
  218. }
  219. pin = pci_swizzle_interrupt_pin(dev, pin);
  220. /* Move up the chain of bridges. */
  221. dev = dev->bus->self;
  222. /* Slot of the next bridge. */
  223. slot = PCI_SLOT(dev->devfn);
  224. } while (dev->bus->self);
  225. }
  226. *pinp = pin;
  227. return slot;
  228. }
  229. #if defined(CONFIG_ALPHA_GENERIC) || !defined(CONFIG_ALPHA_PRIMO)
  230. static void
  231. noritake_apecs_machine_check(unsigned long vector, unsigned long la_ptr)
  232. {
  233. #define MCHK_NO_DEVSEL 0x205U
  234. #define MCHK_NO_TABT 0x204U
  235. struct el_common *mchk_header;
  236. unsigned int code;
  237. mchk_header = (struct el_common *)la_ptr;
  238. /* Clear the error before any reporting. */
  239. mb();
  240. mb(); /* magic */
  241. draina();
  242. apecs_pci_clr_err();
  243. wrmces(0x7);
  244. mb();
  245. code = mchk_header->code;
  246. process_mcheck_info(vector, la_ptr, "NORITAKE APECS",
  247. (mcheck_expected(0)
  248. && (code == MCHK_NO_DEVSEL
  249. || code == MCHK_NO_TABT)));
  250. }
  251. #endif
  252. /*
  253. * The System Vectors
  254. */
  255. #if defined(CONFIG_ALPHA_GENERIC) || !defined(CONFIG_ALPHA_PRIMO)
  256. struct alpha_machine_vector noritake_mv __initmv = {
  257. .vector_name = "Noritake",
  258. DO_EV4_MMU,
  259. DO_DEFAULT_RTC,
  260. DO_APECS_IO,
  261. .machine_check = noritake_apecs_machine_check,
  262. .max_isa_dma_address = ALPHA_MAX_ISA_DMA_ADDRESS,
  263. .min_io_address = EISA_DEFAULT_IO_BASE,
  264. .min_mem_address = APECS_AND_LCA_DEFAULT_MEM_BASE,
  265. .nr_irqs = 48,
  266. .device_interrupt = noritake_device_interrupt,
  267. .init_arch = apecs_init_arch,
  268. .init_irq = noritake_init_irq,
  269. .init_rtc = common_init_rtc,
  270. .init_pci = common_init_pci,
  271. .pci_map_irq = noritake_map_irq,
  272. .pci_swizzle = noritake_swizzle,
  273. };
  274. ALIAS_MV(noritake)
  275. #endif
  276. #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_PRIMO)
  277. struct alpha_machine_vector noritake_primo_mv __initmv = {
  278. .vector_name = "Noritake-Primo",
  279. DO_EV5_MMU,
  280. DO_DEFAULT_RTC,
  281. DO_CIA_IO,
  282. .machine_check = cia_machine_check,
  283. .max_isa_dma_address = ALPHA_MAX_ISA_DMA_ADDRESS,
  284. .min_io_address = EISA_DEFAULT_IO_BASE,
  285. .min_mem_address = CIA_DEFAULT_MEM_BASE,
  286. .nr_irqs = 48,
  287. .device_interrupt = noritake_device_interrupt,
  288. .init_arch = cia_init_arch,
  289. .init_irq = noritake_init_irq,
  290. .init_rtc = common_init_rtc,
  291. .init_pci = cia_init_pci,
  292. .kill_arch = cia_kill_arch,
  293. .pci_map_irq = noritake_map_irq,
  294. .pci_swizzle = noritake_swizzle,
  295. };
  296. ALIAS_MV(noritake_primo)
  297. #endif