sys_wildfire.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  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 struct irq_chip wildfire_irq_type = {
  115. .name = "WILDFIRE",
  116. .unmask = wildfire_enable_irq,
  117. .mask = wildfire_disable_irq,
  118. .mask_ack = wildfire_mask_and_ack_irq,
  119. };
  120. static void __init
  121. wildfire_init_irq_per_pca(int qbbno, int pcano)
  122. {
  123. int i, irq_bias;
  124. unsigned long io_bias;
  125. static struct irqaction isa_enable = {
  126. .handler = no_action,
  127. .name = "isa_enable",
  128. };
  129. irq_bias = qbbno * (WILDFIRE_PCA_PER_QBB * WILDFIRE_IRQ_PER_PCA)
  130. + pcano * WILDFIRE_IRQ_PER_PCA;
  131. /* Only need the following for first PCI bus per PCA. */
  132. io_bias = WILDFIRE_IO(qbbno, pcano<<1) - WILDFIRE_IO_BIAS;
  133. #if 0
  134. outb(0, DMA1_RESET_REG + io_bias);
  135. outb(0, DMA2_RESET_REG + io_bias);
  136. outb(DMA_MODE_CASCADE, DMA2_MODE_REG + io_bias);
  137. outb(0, DMA2_MASK_REG + io_bias);
  138. #endif
  139. #if 0
  140. /* ??? Not sure how to do this, yet... */
  141. init_i8259a_irqs(); /* ??? */
  142. #endif
  143. for (i = 0; i < 16; ++i) {
  144. if (i == 2)
  145. continue;
  146. irq_to_desc(i+irq_bias)->status |= IRQ_LEVEL;
  147. set_irq_chip_and_handler(i+irq_bias, &wildfire_irq_type,
  148. handle_level_irq);
  149. }
  150. irq_to_desc(36+irq_bias)->status |= IRQ_LEVEL;
  151. set_irq_chip_and_handler(36+irq_bias, &wildfire_irq_type,
  152. handle_level_irq);
  153. for (i = 40; i < 64; ++i) {
  154. irq_to_desc(i+irq_bias)->status |= IRQ_LEVEL;
  155. set_irq_chip_and_handler(i+irq_bias, &wildfire_irq_type,
  156. handle_level_irq);
  157. }
  158. setup_irq(32+irq_bias, &isa_enable);
  159. }
  160. static void __init
  161. wildfire_init_irq(void)
  162. {
  163. int qbbno, pcano;
  164. #if 1
  165. wildfire_init_irq_hw();
  166. init_i8259a_irqs();
  167. #endif
  168. for (qbbno = 0; qbbno < WILDFIRE_MAX_QBB; qbbno++) {
  169. if (WILDFIRE_QBB_EXISTS(qbbno)) {
  170. for (pcano = 0; pcano < WILDFIRE_PCA_PER_QBB; pcano++) {
  171. if (WILDFIRE_PCA_EXISTS(qbbno, pcano)) {
  172. wildfire_init_irq_per_pca(qbbno, pcano);
  173. }
  174. }
  175. }
  176. }
  177. }
  178. static void
  179. wildfire_device_interrupt(unsigned long vector)
  180. {
  181. int irq;
  182. irq = (vector - 0x800) >> 4;
  183. /*
  184. * bits 10-8: source QBB ID
  185. * bits 7-6: PCA
  186. * bits 5-0: irq in PCA
  187. */
  188. handle_irq(irq);
  189. return;
  190. }
  191. /*
  192. * PCI Fixup configuration.
  193. *
  194. * Summary per PCA (2 PCI or HIPPI buses):
  195. *
  196. * Bit Meaning
  197. * 0-15 ISA
  198. *
  199. *32 ISA summary
  200. *33 SMI
  201. *34 NMI
  202. *36 builtin QLogic SCSI (or slot 0 if no IO module)
  203. *40 Interrupt Line A from slot 2 PCI0
  204. *41 Interrupt Line B from slot 2 PCI0
  205. *42 Interrupt Line C from slot 2 PCI0
  206. *43 Interrupt Line D from slot 2 PCI0
  207. *44 Interrupt Line A from slot 3 PCI0
  208. *45 Interrupt Line B from slot 3 PCI0
  209. *46 Interrupt Line C from slot 3 PCI0
  210. *47 Interrupt Line D from slot 3 PCI0
  211. *
  212. *48 Interrupt Line A from slot 4 PCI1
  213. *49 Interrupt Line B from slot 4 PCI1
  214. *50 Interrupt Line C from slot 4 PCI1
  215. *51 Interrupt Line D from slot 4 PCI1
  216. *52 Interrupt Line A from slot 5 PCI1
  217. *53 Interrupt Line B from slot 5 PCI1
  218. *54 Interrupt Line C from slot 5 PCI1
  219. *55 Interrupt Line D from slot 5 PCI1
  220. *56 Interrupt Line A from slot 6 PCI1
  221. *57 Interrupt Line B from slot 6 PCI1
  222. *58 Interrupt Line C from slot 6 PCI1
  223. *50 Interrupt Line D from slot 6 PCI1
  224. *60 Interrupt Line A from slot 7 PCI1
  225. *61 Interrupt Line B from slot 7 PCI1
  226. *62 Interrupt Line C from slot 7 PCI1
  227. *63 Interrupt Line D from slot 7 PCI1
  228. *
  229. *
  230. * IdSel
  231. * 0 Cypress Bridge I/O (ISA summary interrupt)
  232. * 1 64 bit PCI 0 option slot 1 (SCSI QLogic builtin)
  233. * 2 64 bit PCI 0 option slot 2
  234. * 3 64 bit PCI 0 option slot 3
  235. * 4 64 bit PCI 1 option slot 4
  236. * 5 64 bit PCI 1 option slot 5
  237. * 6 64 bit PCI 1 option slot 6
  238. * 7 64 bit PCI 1 option slot 7
  239. */
  240. static int __init
  241. wildfire_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
  242. {
  243. static char irq_tab[8][5] __initdata = {
  244. /*INT INTA INTB INTC INTD */
  245. { -1, -1, -1, -1, -1}, /* IdSel 0 ISA Bridge */
  246. { 36, 36, 36+1, 36+2, 36+3}, /* IdSel 1 SCSI builtin */
  247. { 40, 40, 40+1, 40+2, 40+3}, /* IdSel 2 PCI 0 slot 2 */
  248. { 44, 44, 44+1, 44+2, 44+3}, /* IdSel 3 PCI 0 slot 3 */
  249. { 48, 48, 48+1, 48+2, 48+3}, /* IdSel 4 PCI 1 slot 4 */
  250. { 52, 52, 52+1, 52+2, 52+3}, /* IdSel 5 PCI 1 slot 5 */
  251. { 56, 56, 56+1, 56+2, 56+3}, /* IdSel 6 PCI 1 slot 6 */
  252. { 60, 60, 60+1, 60+2, 60+3}, /* IdSel 7 PCI 1 slot 7 */
  253. };
  254. long min_idsel = 0, max_idsel = 7, irqs_per_slot = 5;
  255. struct pci_controller *hose = dev->sysdata;
  256. int irq = COMMON_TABLE_LOOKUP;
  257. if (irq > 0) {
  258. int qbbno = hose->index >> 3;
  259. int pcano = (hose->index >> 1) & 3;
  260. irq += (qbbno << 8) + (pcano << 6);
  261. }
  262. return irq;
  263. }
  264. /*
  265. * The System Vectors
  266. */
  267. struct alpha_machine_vector wildfire_mv __initmv = {
  268. .vector_name = "WILDFIRE",
  269. DO_EV6_MMU,
  270. DO_DEFAULT_RTC,
  271. DO_WILDFIRE_IO,
  272. .machine_check = wildfire_machine_check,
  273. .max_isa_dma_address = ALPHA_MAX_ISA_DMA_ADDRESS,
  274. .min_io_address = DEFAULT_IO_BASE,
  275. .min_mem_address = DEFAULT_MEM_BASE,
  276. .nr_irqs = WILDFIRE_NR_IRQS,
  277. .device_interrupt = wildfire_device_interrupt,
  278. .init_arch = wildfire_init_arch,
  279. .init_irq = wildfire_init_irq,
  280. .init_rtc = common_init_rtc,
  281. .init_pci = common_init_pci,
  282. .kill_arch = wildfire_kill_arch,
  283. .pci_map_irq = wildfire_map_irq,
  284. .pci_swizzle = common_swizzle,
  285. .pa_to_nid = wildfire_pa_to_nid,
  286. .cpuid_to_nid = wildfire_cpuid_to_nid,
  287. .node_mem_start = wildfire_node_mem_start,
  288. .node_mem_size = wildfire_node_mem_size,
  289. };
  290. ALIAS_MV(wildfire)