sys_wildfire.c 8.4 KB

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