sys_wildfire.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. /*
  2. * linux/arch/alpha/kernel/sys_wildfire.c
  3. *
  4. * Wildfire support.
  5. *
  6. * Copyright (C) 2000 Andrea Arcangeli <andrea@suse.de> SuSE
  7. */
  8. #include <linux/kernel.h>
  9. #include <linux/types.h>
  10. #include <linux/mm.h>
  11. #include <linux/sched.h>
  12. #include <linux/pci.h>
  13. #include <linux/init.h>
  14. #include <linux/bitops.h>
  15. #include <asm/ptrace.h>
  16. #include <asm/system.h>
  17. #include <asm/dma.h>
  18. #include <asm/irq.h>
  19. #include <asm/mmu_context.h>
  20. #include <asm/io.h>
  21. #include <asm/pgtable.h>
  22. #include <asm/core_wildfire.h>
  23. #include <asm/hwrpb.h>
  24. #include <asm/tlbflush.h>
  25. #include "proto.h"
  26. #include "irq_impl.h"
  27. #include "pci_impl.h"
  28. #include "machvec_impl.h"
  29. static unsigned long cached_irq_mask[WILDFIRE_NR_IRQS/(sizeof(long)*8)];
  30. DEFINE_SPINLOCK(wildfire_irq_lock);
  31. static int doing_init_irq_hw = 0;
  32. static void
  33. wildfire_update_irq_hw(unsigned int irq)
  34. {
  35. int qbbno = (irq >> 8) & (WILDFIRE_MAX_QBB - 1);
  36. int pcano = (irq >> 6) & (WILDFIRE_PCA_PER_QBB - 1);
  37. wildfire_pca *pca;
  38. volatile unsigned long * enable0;
  39. if (!WILDFIRE_PCA_EXISTS(qbbno, pcano)) {
  40. if (!doing_init_irq_hw) {
  41. printk(KERN_ERR "wildfire_update_irq_hw:"
  42. " got irq %d for non-existent PCA %d"
  43. " on QBB %d.\n",
  44. irq, pcano, qbbno);
  45. }
  46. return;
  47. }
  48. pca = WILDFIRE_pca(qbbno, pcano);
  49. enable0 = (unsigned long *) &pca->pca_int[0].enable; /* ??? */
  50. *enable0 = cached_irq_mask[qbbno * WILDFIRE_PCA_PER_QBB + pcano];
  51. mb();
  52. *enable0;
  53. }
  54. static void __init
  55. wildfire_init_irq_hw(void)
  56. {
  57. #if 0
  58. register wildfire_pca * pca = WILDFIRE_pca(0, 0);
  59. volatile unsigned long * enable0, * enable1, * enable2, *enable3;
  60. volatile unsigned long * target0, * target1, * target2, *target3;
  61. enable0 = (unsigned long *) &pca->pca_int[0].enable;
  62. enable1 = (unsigned long *) &pca->pca_int[1].enable;
  63. enable2 = (unsigned long *) &pca->pca_int[2].enable;
  64. enable3 = (unsigned long *) &pca->pca_int[3].enable;
  65. target0 = (unsigned long *) &pca->pca_int[0].target;
  66. target1 = (unsigned long *) &pca->pca_int[1].target;
  67. target2 = (unsigned long *) &pca->pca_int[2].target;
  68. target3 = (unsigned long *) &pca->pca_int[3].target;
  69. *enable0 = *enable1 = *enable2 = *enable3 = 0;
  70. *target0 = (1UL<<8) | WILDFIRE_QBB(0);
  71. *target1 = *target2 = *target3 = 0;
  72. mb();
  73. *enable0; *enable1; *enable2; *enable3;
  74. *target0; *target1; *target2; *target3;
  75. #else
  76. int i;
  77. doing_init_irq_hw = 1;
  78. /* Need to update only once for every possible PCA. */
  79. for (i = 0; i < WILDFIRE_NR_IRQS; i+=WILDFIRE_IRQ_PER_PCA)
  80. wildfire_update_irq_hw(i);
  81. doing_init_irq_hw = 0;
  82. #endif
  83. }
  84. static void
  85. wildfire_enable_irq(unsigned int irq)
  86. {
  87. if (irq < 16)
  88. i8259a_enable_irq(irq);
  89. spin_lock(&wildfire_irq_lock);
  90. set_bit(irq, &cached_irq_mask);
  91. wildfire_update_irq_hw(irq);
  92. spin_unlock(&wildfire_irq_lock);
  93. }
  94. static void
  95. wildfire_disable_irq(unsigned int irq)
  96. {
  97. if (irq < 16)
  98. i8259a_disable_irq(irq);
  99. spin_lock(&wildfire_irq_lock);
  100. clear_bit(irq, &cached_irq_mask);
  101. wildfire_update_irq_hw(irq);
  102. spin_unlock(&wildfire_irq_lock);
  103. }
  104. static void
  105. wildfire_mask_and_ack_irq(unsigned int irq)
  106. {
  107. if (irq < 16)
  108. i8259a_mask_and_ack_irq(irq);
  109. spin_lock(&wildfire_irq_lock);
  110. clear_bit(irq, &cached_irq_mask);
  111. wildfire_update_irq_hw(irq);
  112. spin_unlock(&wildfire_irq_lock);
  113. }
  114. static unsigned int
  115. wildfire_startup_irq(unsigned int irq)
  116. {
  117. wildfire_enable_irq(irq);
  118. return 0; /* never anything pending */
  119. }
  120. static void
  121. wildfire_end_irq(unsigned int irq)
  122. {
  123. #if 0
  124. if (!irq_desc[irq].action)
  125. printk("got irq %d\n", irq);
  126. #endif
  127. if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
  128. wildfire_enable_irq(irq);
  129. }
  130. static struct hw_interrupt_type wildfire_irq_type = {
  131. .typename = "WILDFIRE",
  132. .startup = wildfire_startup_irq,
  133. .shutdown = wildfire_disable_irq,
  134. .enable = wildfire_enable_irq,
  135. .disable = wildfire_disable_irq,
  136. .ack = wildfire_mask_and_ack_irq,
  137. .end = wildfire_end_irq,
  138. };
  139. static void __init
  140. wildfire_init_irq_per_pca(int qbbno, int pcano)
  141. {
  142. int i, irq_bias;
  143. unsigned long io_bias;
  144. static struct irqaction isa_enable = {
  145. .handler = no_action,
  146. .name = "isa_enable",
  147. };
  148. irq_bias = qbbno * (WILDFIRE_PCA_PER_QBB * WILDFIRE_IRQ_PER_PCA)
  149. + pcano * WILDFIRE_IRQ_PER_PCA;
  150. /* Only need the following for first PCI bus per PCA. */
  151. io_bias = WILDFIRE_IO(qbbno, pcano<<1) - WILDFIRE_IO_BIAS;
  152. #if 0
  153. outb(0, DMA1_RESET_REG + io_bias);
  154. outb(0, DMA2_RESET_REG + io_bias);
  155. outb(DMA_MODE_CASCADE, DMA2_MODE_REG + io_bias);
  156. outb(0, DMA2_MASK_REG + io_bias);
  157. #endif
  158. #if 0
  159. /* ??? Not sure how to do this, yet... */
  160. init_i8259a_irqs(); /* ??? */
  161. #endif
  162. for (i = 0; i < 16; ++i) {
  163. if (i == 2)
  164. continue;
  165. irq_desc[i+irq_bias].status = IRQ_DISABLED | IRQ_LEVEL;
  166. irq_desc[i+irq_bias].chip = &wildfire_irq_type;
  167. }
  168. irq_desc[36+irq_bias].status = IRQ_DISABLED | IRQ_LEVEL;
  169. irq_desc[36+irq_bias].chip = &wildfire_irq_type;
  170. for (i = 40; i < 64; ++i) {
  171. irq_desc[i+irq_bias].status = IRQ_DISABLED | IRQ_LEVEL;
  172. irq_desc[i+irq_bias].chip = &wildfire_irq_type;
  173. }
  174. setup_irq(32+irq_bias, &isa_enable);
  175. }
  176. static void __init
  177. wildfire_init_irq(void)
  178. {
  179. int qbbno, pcano;
  180. #if 1
  181. wildfire_init_irq_hw();
  182. init_i8259a_irqs();
  183. #endif
  184. for (qbbno = 0; qbbno < WILDFIRE_MAX_QBB; qbbno++) {
  185. if (WILDFIRE_QBB_EXISTS(qbbno)) {
  186. for (pcano = 0; pcano < WILDFIRE_PCA_PER_QBB; pcano++) {
  187. if (WILDFIRE_PCA_EXISTS(qbbno, pcano)) {
  188. wildfire_init_irq_per_pca(qbbno, pcano);
  189. }
  190. }
  191. }
  192. }
  193. }
  194. static void
  195. wildfire_device_interrupt(unsigned long vector)
  196. {
  197. int irq;
  198. irq = (vector - 0x800) >> 4;
  199. /*
  200. * bits 10-8: source QBB ID
  201. * bits 7-6: PCA
  202. * bits 5-0: irq in PCA
  203. */
  204. handle_irq(irq);
  205. return;
  206. }
  207. /*
  208. * PCI Fixup configuration.
  209. *
  210. * Summary per PCA (2 PCI or HIPPI buses):
  211. *
  212. * Bit Meaning
  213. * 0-15 ISA
  214. *
  215. *32 ISA summary
  216. *33 SMI
  217. *34 NMI
  218. *36 builtin QLogic SCSI (or slot 0 if no IO module)
  219. *40 Interrupt Line A from slot 2 PCI0
  220. *41 Interrupt Line B from slot 2 PCI0
  221. *42 Interrupt Line C from slot 2 PCI0
  222. *43 Interrupt Line D from slot 2 PCI0
  223. *44 Interrupt Line A from slot 3 PCI0
  224. *45 Interrupt Line B from slot 3 PCI0
  225. *46 Interrupt Line C from slot 3 PCI0
  226. *47 Interrupt Line D from slot 3 PCI0
  227. *
  228. *48 Interrupt Line A from slot 4 PCI1
  229. *49 Interrupt Line B from slot 4 PCI1
  230. *50 Interrupt Line C from slot 4 PCI1
  231. *51 Interrupt Line D from slot 4 PCI1
  232. *52 Interrupt Line A from slot 5 PCI1
  233. *53 Interrupt Line B from slot 5 PCI1
  234. *54 Interrupt Line C from slot 5 PCI1
  235. *55 Interrupt Line D from slot 5 PCI1
  236. *56 Interrupt Line A from slot 6 PCI1
  237. *57 Interrupt Line B from slot 6 PCI1
  238. *58 Interrupt Line C from slot 6 PCI1
  239. *50 Interrupt Line D from slot 6 PCI1
  240. *60 Interrupt Line A from slot 7 PCI1
  241. *61 Interrupt Line B from slot 7 PCI1
  242. *62 Interrupt Line C from slot 7 PCI1
  243. *63 Interrupt Line D from slot 7 PCI1
  244. *
  245. *
  246. * IdSel
  247. * 0 Cypress Bridge I/O (ISA summary interrupt)
  248. * 1 64 bit PCI 0 option slot 1 (SCSI QLogic builtin)
  249. * 2 64 bit PCI 0 option slot 2
  250. * 3 64 bit PCI 0 option slot 3
  251. * 4 64 bit PCI 1 option slot 4
  252. * 5 64 bit PCI 1 option slot 5
  253. * 6 64 bit PCI 1 option slot 6
  254. * 7 64 bit PCI 1 option slot 7
  255. */
  256. static int __init
  257. wildfire_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
  258. {
  259. static char irq_tab[8][5] __initdata = {
  260. /*INT INTA INTB INTC INTD */
  261. { -1, -1, -1, -1, -1}, /* IdSel 0 ISA Bridge */
  262. { 36, 36, 36+1, 36+2, 36+3}, /* IdSel 1 SCSI builtin */
  263. { 40, 40, 40+1, 40+2, 40+3}, /* IdSel 2 PCI 0 slot 2 */
  264. { 44, 44, 44+1, 44+2, 44+3}, /* IdSel 3 PCI 0 slot 3 */
  265. { 48, 48, 48+1, 48+2, 48+3}, /* IdSel 4 PCI 1 slot 4 */
  266. { 52, 52, 52+1, 52+2, 52+3}, /* IdSel 5 PCI 1 slot 5 */
  267. { 56, 56, 56+1, 56+2, 56+3}, /* IdSel 6 PCI 1 slot 6 */
  268. { 60, 60, 60+1, 60+2, 60+3}, /* IdSel 7 PCI 1 slot 7 */
  269. };
  270. long min_idsel = 0, max_idsel = 7, irqs_per_slot = 5;
  271. struct pci_controller *hose = dev->sysdata;
  272. int irq = COMMON_TABLE_LOOKUP;
  273. if (irq > 0) {
  274. int qbbno = hose->index >> 3;
  275. int pcano = (hose->index >> 1) & 3;
  276. irq += (qbbno << 8) + (pcano << 6);
  277. }
  278. return irq;
  279. }
  280. /*
  281. * The System Vectors
  282. */
  283. struct alpha_machine_vector wildfire_mv __initmv = {
  284. .vector_name = "WILDFIRE",
  285. DO_EV6_MMU,
  286. DO_DEFAULT_RTC,
  287. DO_WILDFIRE_IO,
  288. .machine_check = wildfire_machine_check,
  289. .max_isa_dma_address = ALPHA_MAX_ISA_DMA_ADDRESS,
  290. .min_io_address = DEFAULT_IO_BASE,
  291. .min_mem_address = DEFAULT_MEM_BASE,
  292. .nr_irqs = WILDFIRE_NR_IRQS,
  293. .device_interrupt = wildfire_device_interrupt,
  294. .init_arch = wildfire_init_arch,
  295. .init_irq = wildfire_init_irq,
  296. .init_rtc = common_init_rtc,
  297. .init_pci = common_init_pci,
  298. .kill_arch = wildfire_kill_arch,
  299. .pci_map_irq = wildfire_map_irq,
  300. .pci_swizzle = common_swizzle,
  301. .pa_to_nid = wildfire_pa_to_nid,
  302. .cpuid_to_nid = wildfire_cpuid_to_nid,
  303. .node_mem_start = wildfire_node_mem_start,
  304. .node_mem_size = wildfire_node_mem_size,
  305. };
  306. ALIAS_MV(wildfire)