sys_wildfire.c 8.6 KB

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