sys_takara.c 7.9 KB

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