sys_wildfire.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:9k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

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