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

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  * linux/arch/alpha/kernel/sys_takara.c
  3.  *
  4.  * Copyright (C) 1995 David A Rusling
  5.  * Copyright (C) 1996 Jay A Estabrook
  6.  * Copyright (C) 1998, 1999 Richard Henderson
  7.  *
  8.  * Code supporting the TAKARA.
  9.  */
  10. #include <linux/kernel.h>
  11. #include <linux/types.h>
  12. #include <linux/mm.h>
  13. #include <linux/sched.h>
  14. #include <linux/pci.h>
  15. #include <linux/init.h>
  16. #include <asm/ptrace.h>
  17. #include <asm/system.h>
  18. #include <asm/dma.h>
  19. #include <asm/irq.h>
  20. #include <asm/mmu_context.h>
  21. #include <asm/io.h>
  22. #include <asm/pgtable.h>
  23. #include <asm/core_cia.h>
  24. #include "proto.h"
  25. #include "irq_impl.h"
  26. #include "pci_impl.h"
  27. #include "machvec_impl.h"
  28. /* Note mask bit is true for DISABLED irqs.  */
  29. static unsigned long cached_irq_mask[2] = { -1, -1 };
  30. static inline void
  31. takara_update_irq_hw(unsigned long irq, unsigned long mask)
  32. {
  33. int regaddr;
  34. mask = (irq >= 64 ? mask << 16 : mask >> ((irq - 16) & 0x30));
  35. regaddr = 0x510 + (((irq - 16) >> 2) & 0x0c);
  36. outl(mask & 0xffff0000UL, regaddr);
  37. }
  38. static inline void
  39. takara_enable_irq(unsigned int irq)
  40. {
  41. unsigned long mask;
  42. mask = (cached_irq_mask[irq >= 64] &= ~(1UL << (irq & 63)));
  43. takara_update_irq_hw(irq, mask);
  44. }
  45. static void
  46. takara_disable_irq(unsigned int irq)
  47. {
  48. unsigned long mask;
  49. mask = (cached_irq_mask[irq >= 64] |= 1UL << (irq & 63));
  50. takara_update_irq_hw(irq, mask);
  51. }
  52. static unsigned int
  53. takara_startup_irq(unsigned int irq)
  54. {
  55. takara_enable_irq(irq);
  56. return 0; /* never anything pending */
  57. }
  58. static void
  59. takara_end_irq(unsigned int irq)
  60. {
  61. if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
  62. takara_enable_irq(irq);
  63. }
  64. static struct hw_interrupt_type takara_irq_type = {
  65. typename: "TAKARA",
  66. startup: takara_startup_irq,
  67. shutdown: takara_disable_irq,
  68. enable: takara_enable_irq,
  69. disable: takara_disable_irq,
  70. ack: takara_disable_irq,
  71. end: takara_end_irq,
  72. };
  73. static void
  74. takara_device_interrupt(unsigned long vector, struct pt_regs *regs)
  75. {
  76. unsigned intstatus;
  77. /*
  78.  * The PALcode will have passed us vectors 0x800 or 0x810,
  79.  * which are fairly arbitrary values and serve only to tell
  80.  * us whether an interrupt has come in on IRQ0 or IRQ1. If
  81.  * it's IRQ1 it's a PCI interrupt; if it's IRQ0, it's
  82.  * probably ISA, but PCI interrupts can come through IRQ0
  83.  * as well if the interrupt controller isn't in accelerated
  84.  * mode.
  85.  *
  86.  * OTOH, the accelerator thing doesn't seem to be working
  87.  * overly well, so what we'll do instead is try directly
  88.  * examining the Master Interrupt Register to see if it's a
  89.  * PCI interrupt, and if _not_ then we'll pass it on to the
  90.  * ISA handler.
  91.  */
  92. intstatus = inw(0x500) & 15;
  93. if (intstatus) {
  94. /*
  95.  * This is a PCI interrupt. Check each bit and
  96.  * despatch an interrupt if it's set.
  97.  */
  98. if (intstatus & 8) handle_irq(16+3, regs);
  99. if (intstatus & 4) handle_irq(16+2, regs);
  100. if (intstatus & 2) handle_irq(16+1, regs);
  101. if (intstatus & 1) handle_irq(16+0, regs);
  102. } else {
  103. isa_device_interrupt (vector, regs);
  104. }
  105. }
  106. static void 
  107. takara_srm_device_interrupt(unsigned long vector, struct pt_regs * regs)
  108. {
  109. int irq = (vector - 0x800) >> 4;
  110. handle_irq(irq, regs);
  111. }
  112. static void __init
  113. takara_init_irq(void)
  114. {
  115. long i;
  116. init_i8259a_irqs();
  117. if (alpha_using_srm) {
  118. alpha_mv.device_interrupt = takara_srm_device_interrupt;
  119. } else {
  120. unsigned int ctlreg = inl(0x500);
  121. /* Return to non-accelerated mode.  */
  122. ctlreg &= ~0x8000;
  123. outl(ctlreg, 0x500);
  124. /* Enable the PCI interrupt register.  */
  125. ctlreg = 0x05107c00;
  126. outl(ctlreg, 0x500);
  127. }
  128. for (i = 16; i < 128; i += 16)
  129. takara_update_irq_hw(i, -1);
  130. for (i = 16; i < 128; ++i) {
  131. irq_desc[i].status = IRQ_DISABLED | IRQ_LEVEL;
  132. irq_desc[i].handler = &takara_irq_type;
  133. }
  134. common_init_isa_dma();
  135. }
  136. /*
  137.  * The Takara has PCI devices 1, 2, and 3 configured to slots 20,
  138.  * 19, and 18 respectively, in the default configuration. They can
  139.  * also be jumpered to slots 8, 7, and 6 respectively, which is fun
  140.  * because the SIO ISA bridge can also be slot 7. However, the SIO
  141.  * doesn't explicitly generate PCI-type interrupts, so we can
  142.  * assign it whatever the hell IRQ we like and it doesn't matter.
  143.  */
  144. static int __init
  145. takara_map_irq_srm(struct pci_dev *dev, u8 slot, u8 pin)
  146. {
  147. static char irq_tab[15][5] __initdata = {
  148. { 16+3, 16+3, 16+3, 16+3, 16+3},   /* slot  6 == device 3 */
  149. { 16+2, 16+2, 16+2, 16+2, 16+2},   /* slot  7 == device 2 */
  150. { 16+1, 16+1, 16+1, 16+1, 16+1},   /* slot  8 == device 1 */
  151. {   -1,   -1,   -1,   -1,   -1},   /* slot  9 == nothing */
  152. {   -1,   -1,   -1,   -1,   -1},   /* slot 10 == nothing */
  153. {   -1,   -1,   -1,   -1,   -1},   /* slot 11 == nothing */
  154. /* These are behind the bridges.  */
  155. {   12,   12,   13,   14,   15},   /* slot 12 == nothing */
  156. {    8,    8,    9,   19,   11},   /* slot 13 == nothing */
  157. {    4,    4,    5,    6,    7},   /* slot 14 == nothing */
  158. {    0,    0,    1,    2,    3},   /* slot 15 == nothing */
  159. {   -1,   -1,   -1,   -1,   -1},   /* slot 16 == nothing */
  160. {64+ 0, 64+0, 64+1, 64+2, 64+3},   /* slot 17= device 4 */
  161. {48+ 0, 48+0, 48+1, 48+2, 48+3},   /* slot 18= device 3 */
  162. {32+ 0, 32+0, 32+1, 32+2, 32+3},   /* slot 19= device 2 */
  163. {16+ 0, 16+0, 16+1, 16+2, 16+3},   /* slot 20= device 1 */
  164. };
  165. const long min_idsel = 6, max_idsel = 20, irqs_per_slot = 5;
  166.         int irq = COMMON_TABLE_LOOKUP;
  167. if (irq >= 0 && irq < 16) {
  168. /* Guess that we are behind a bridge.  */
  169. unsigned int busslot = PCI_SLOT(dev->bus->self->devfn);
  170. irq += irq_tab[busslot-min_idsel][0];
  171. }
  172. return irq;
  173. }
  174. static int __init
  175. takara_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
  176. {
  177. static char irq_tab[15][5] __initdata = {
  178. { 16+3, 16+3, 16+3, 16+3, 16+3},   /* slot  6 == device 3 */
  179. { 16+2, 16+2, 16+2, 16+2, 16+2},   /* slot  7 == device 2 */
  180. { 16+1, 16+1, 16+1, 16+1, 16+1},   /* slot  8 == device 1 */
  181. {   -1,   -1,   -1,   -1,   -1},   /* slot  9 == nothing */
  182. {   -1,   -1,   -1,   -1,   -1},   /* slot 10 == nothing */
  183. {   -1,   -1,   -1,   -1,   -1},   /* slot 11 == nothing */
  184. {   -1,   -1,   -1,   -1,   -1},   /* slot 12 == nothing */
  185. {   -1,   -1,   -1,   -1,   -1},   /* slot 13 == nothing */
  186. {   -1,   -1,   -1,   -1,   -1},   /* slot 14 == nothing */
  187. {   -1,   -1,   -1,   -1,   -1},   /* slot 15 == nothing */
  188. {   -1,   -1,   -1,   -1,   -1},   /* slot 16 == nothing */
  189. {   -1,   -1,   -1,   -1,   -1},   /* slot 17 == nothing */
  190. { 16+3, 16+3, 16+3, 16+3, 16+3},   /* slot 18 == device 3 */
  191. { 16+2, 16+2, 16+2, 16+2, 16+2},   /* slot 19 == device 2 */
  192. { 16+1, 16+1, 16+1, 16+1, 16+1},   /* slot 20 == device 1 */
  193. };
  194. const long min_idsel = 6, max_idsel = 20, irqs_per_slot = 5;
  195. return COMMON_TABLE_LOOKUP;
  196. }
  197. static u8 __init
  198. takara_swizzle(struct pci_dev *dev, u8 *pinp)
  199. {
  200. int slot = PCI_SLOT(dev->devfn);
  201. int pin = *pinp;
  202. unsigned int ctlreg = inl(0x500);
  203. unsigned int busslot = PCI_SLOT(dev->bus->self->devfn);
  204. /* Check for built-in bridges.  */
  205. if (dev->bus->number != 0
  206.     && busslot > 16
  207.     && ((1<<(36-busslot)) & ctlreg)) {
  208. if (pin == 1)
  209. pin += (20 - busslot);
  210. else {
  211. printk(KERN_WARNING "takara_swizzle: can only "
  212.        "handle cards with INTA IRQ pin.n");
  213. }
  214. } else {
  215. /* Must be a card-based bridge.  */
  216. printk(KERN_WARNING "takara_swizzle: cannot handle "
  217.        "card-bridge behind builtin bridge yet.n");
  218. }
  219. *pinp = pin;
  220. return slot;
  221. }
  222. static void __init
  223. takara_init_pci(void)
  224. {
  225. if (alpha_using_srm)
  226. alpha_mv.pci_map_irq = takara_map_irq_srm;
  227. cia_init_pci();
  228. ns87312_enable_ide(0x26e);
  229. }
  230. /*
  231.  * The System Vector
  232.  */
  233. struct alpha_machine_vector takara_mv __initmv = {
  234. vector_name: "Takara",
  235. DO_EV5_MMU,
  236. DO_DEFAULT_RTC,
  237. DO_CIA_IO,
  238. DO_CIA_BUS,
  239. machine_check: cia_machine_check,
  240. max_dma_address: ALPHA_MAX_DMA_ADDRESS,
  241. min_io_address: DEFAULT_IO_BASE,
  242. min_mem_address: CIA_DEFAULT_MEM_BASE,
  243. nr_irqs: 128,
  244. device_interrupt: takara_device_interrupt,
  245. init_arch: cia_init_arch,
  246. init_irq: takara_init_irq,
  247. init_rtc: common_init_rtc,
  248. init_pci: takara_init_pci,
  249. kill_arch: NULL,
  250. pci_map_irq: takara_map_irq,
  251. pci_swizzle: takara_swizzle,
  252. };
  253. ALIAS_MV(takara)