sys_wildfire.c 8.6 KB

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