sys_eiger.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. /*
  2. * linux/arch/alpha/kernel/sys_eiger.c
  3. *
  4. * Copyright (C) 1995 David A Rusling
  5. * Copyright (C) 1996, 1999 Jay A Estabrook
  6. * Copyright (C) 1998, 1999 Richard Henderson
  7. * Copyright (C) 1999 Iain Grant
  8. *
  9. * Code supporting the EIGER (EV6+TSUNAMI).
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/types.h>
  13. #include <linux/mm.h>
  14. #include <linux/sched.h>
  15. #include <linux/pci.h>
  16. #include <linux/init.h>
  17. #include <linux/bitops.h>
  18. #include <asm/ptrace.h>
  19. #include <asm/system.h>
  20. #include <asm/dma.h>
  21. #include <asm/irq.h>
  22. #include <asm/mmu_context.h>
  23. #include <asm/io.h>
  24. #include <asm/pci.h>
  25. #include <asm/pgtable.h>
  26. #include <asm/core_tsunami.h>
  27. #include <asm/hwrpb.h>
  28. #include <asm/tlbflush.h>
  29. #include "proto.h"
  30. #include "irq_impl.h"
  31. #include "pci_impl.h"
  32. #include "machvec_impl.h"
  33. /* Note that this interrupt code is identical to TAKARA. */
  34. /* Note mask bit is true for DISABLED irqs. */
  35. static unsigned long cached_irq_mask[2] = { -1, -1 };
  36. static inline void
  37. eiger_update_irq_hw(unsigned long irq, unsigned long mask)
  38. {
  39. int regaddr;
  40. mask = (irq >= 64 ? mask << 16 : mask >> ((irq - 16) & 0x30));
  41. regaddr = 0x510 + (((irq - 16) >> 2) & 0x0c);
  42. outl(mask & 0xffff0000UL, regaddr);
  43. }
  44. static inline void
  45. eiger_enable_irq(unsigned int irq)
  46. {
  47. unsigned long mask;
  48. mask = (cached_irq_mask[irq >= 64] &= ~(1UL << (irq & 63)));
  49. eiger_update_irq_hw(irq, mask);
  50. }
  51. static void
  52. eiger_disable_irq(unsigned int irq)
  53. {
  54. unsigned long mask;
  55. mask = (cached_irq_mask[irq >= 64] |= 1UL << (irq & 63));
  56. eiger_update_irq_hw(irq, mask);
  57. }
  58. static unsigned int
  59. eiger_startup_irq(unsigned int irq)
  60. {
  61. eiger_enable_irq(irq);
  62. return 0; /* never anything pending */
  63. }
  64. static void
  65. eiger_end_irq(unsigned int irq)
  66. {
  67. if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
  68. eiger_enable_irq(irq);
  69. }
  70. static struct hw_interrupt_type eiger_irq_type = {
  71. .typename = "EIGER",
  72. .startup = eiger_startup_irq,
  73. .shutdown = eiger_disable_irq,
  74. .enable = eiger_enable_irq,
  75. .disable = eiger_disable_irq,
  76. .ack = eiger_disable_irq,
  77. .end = eiger_end_irq,
  78. };
  79. static void
  80. eiger_device_interrupt(unsigned long vector)
  81. {
  82. unsigned intstatus;
  83. /*
  84. * The PALcode will have passed us vectors 0x800 or 0x810,
  85. * which are fairly arbitrary values and serve only to tell
  86. * us whether an interrupt has come in on IRQ0 or IRQ1. If
  87. * it's IRQ1 it's a PCI interrupt; if it's IRQ0, it's
  88. * probably ISA, but PCI interrupts can come through IRQ0
  89. * as well if the interrupt controller isn't in accelerated
  90. * mode.
  91. *
  92. * OTOH, the accelerator thing doesn't seem to be working
  93. * overly well, so what we'll do instead is try directly
  94. * examining the Master Interrupt Register to see if it's a
  95. * PCI interrupt, and if _not_ then we'll pass it on to the
  96. * ISA handler.
  97. */
  98. intstatus = inw(0x500) & 15;
  99. if (intstatus) {
  100. /*
  101. * This is a PCI interrupt. Check each bit and
  102. * despatch an interrupt if it's set.
  103. */
  104. if (intstatus & 8) handle_irq(16+3);
  105. if (intstatus & 4) handle_irq(16+2);
  106. if (intstatus & 2) handle_irq(16+1);
  107. if (intstatus & 1) handle_irq(16+0);
  108. } else {
  109. isa_device_interrupt(vector);
  110. }
  111. }
  112. static void
  113. eiger_srm_device_interrupt(unsigned long vector)
  114. {
  115. int irq = (vector - 0x800) >> 4;
  116. handle_irq(irq);
  117. }
  118. static void __init
  119. eiger_init_irq(void)
  120. {
  121. long i;
  122. outb(0, DMA1_RESET_REG);
  123. outb(0, DMA2_RESET_REG);
  124. outb(DMA_MODE_CASCADE, DMA2_MODE_REG);
  125. outb(0, DMA2_MASK_REG);
  126. if (alpha_using_srm)
  127. alpha_mv.device_interrupt = eiger_srm_device_interrupt;
  128. for (i = 16; i < 128; i += 16)
  129. eiger_update_irq_hw(i, -1);
  130. init_i8259a_irqs();
  131. for (i = 16; i < 128; ++i) {
  132. irq_desc[i].status = IRQ_DISABLED | IRQ_LEVEL;
  133. irq_desc[i].chip = &eiger_irq_type;
  134. }
  135. }
  136. static int __init
  137. eiger_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
  138. {
  139. u8 irq_orig;
  140. /* The SRM console has already calculated out the IRQ value's for
  141. option cards. As this works lets just read in the value already
  142. set and change it to a useable value by Linux.
  143. All the IRQ values generated by the console are greater than 90,
  144. so we subtract 80 because it is (90 - allocated ISA IRQ's). */
  145. pci_read_config_byte(dev, PCI_INTERRUPT_LINE, &irq_orig);
  146. return irq_orig - 0x80;
  147. }
  148. static u8 __init
  149. eiger_swizzle(struct pci_dev *dev, u8 *pinp)
  150. {
  151. struct pci_controller *hose = dev->sysdata;
  152. int slot, pin = *pinp;
  153. int bridge_count = 0;
  154. /* Find the number of backplane bridges. */
  155. int backplane = inw(0x502) & 0x0f;
  156. switch (backplane)
  157. {
  158. case 0x00: bridge_count = 0; break; /* No bridges */
  159. case 0x01: bridge_count = 1; break; /* 1 */
  160. case 0x03: bridge_count = 2; break; /* 2 */
  161. case 0x07: bridge_count = 3; break; /* 3 */
  162. case 0x0f: bridge_count = 4; break; /* 4 */
  163. };
  164. slot = PCI_SLOT(dev->devfn);
  165. while (dev->bus->self) {
  166. /* Check for built-in bridges on hose 0. */
  167. if (hose->index == 0
  168. && (PCI_SLOT(dev->bus->self->devfn)
  169. > 20 - bridge_count)) {
  170. slot = PCI_SLOT(dev->devfn);
  171. break;
  172. }
  173. /* Must be a card-based bridge. */
  174. pin = pci_swizzle_interrupt_pin(dev, pin);
  175. /* Move up the chain of bridges. */
  176. dev = dev->bus->self;
  177. }
  178. *pinp = pin;
  179. return slot;
  180. }
  181. /*
  182. * The System Vectors
  183. */
  184. struct alpha_machine_vector eiger_mv __initmv = {
  185. .vector_name = "Eiger",
  186. DO_EV6_MMU,
  187. DO_DEFAULT_RTC,
  188. DO_TSUNAMI_IO,
  189. .machine_check = tsunami_machine_check,
  190. .max_isa_dma_address = ALPHA_MAX_ISA_DMA_ADDRESS,
  191. .min_io_address = DEFAULT_IO_BASE,
  192. .min_mem_address = DEFAULT_MEM_BASE,
  193. .pci_dac_offset = TSUNAMI_DAC_OFFSET,
  194. .nr_irqs = 128,
  195. .device_interrupt = eiger_device_interrupt,
  196. .init_arch = tsunami_init_arch,
  197. .init_irq = eiger_init_irq,
  198. .init_rtc = common_init_rtc,
  199. .init_pci = common_init_pci,
  200. .kill_arch = tsunami_kill_arch,
  201. .pci_map_irq = eiger_map_irq,
  202. .pci_swizzle = eiger_swizzle,
  203. };
  204. ALIAS_MV(eiger)