sys_noritake.c 9.3 KB

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