sys_eiger.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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(struct irq_data *d)
  46. {
  47. unsigned int irq = d->irq;
  48. unsigned long mask;
  49. mask = (cached_irq_mask[irq >= 64] &= ~(1UL << (irq & 63)));
  50. eiger_update_irq_hw(irq, mask);
  51. }
  52. static void
  53. eiger_disable_irq(struct irq_data *d)
  54. {
  55. unsigned int irq = d->irq;
  56. unsigned long mask;
  57. mask = (cached_irq_mask[irq >= 64] |= 1UL << (irq & 63));
  58. eiger_update_irq_hw(irq, mask);
  59. }
  60. static struct irq_chip eiger_irq_type = {
  61. .name = "EIGER",
  62. .irq_unmask = eiger_enable_irq,
  63. .irq_mask = eiger_disable_irq,
  64. .irq_mask_ack = eiger_disable_irq,
  65. };
  66. static void
  67. eiger_device_interrupt(unsigned long vector)
  68. {
  69. unsigned intstatus;
  70. /*
  71. * The PALcode will have passed us vectors 0x800 or 0x810,
  72. * which are fairly arbitrary values and serve only to tell
  73. * us whether an interrupt has come in on IRQ0 or IRQ1. If
  74. * it's IRQ1 it's a PCI interrupt; if it's IRQ0, it's
  75. * probably ISA, but PCI interrupts can come through IRQ0
  76. * as well if the interrupt controller isn't in accelerated
  77. * mode.
  78. *
  79. * OTOH, the accelerator thing doesn't seem to be working
  80. * overly well, so what we'll do instead is try directly
  81. * examining the Master Interrupt Register to see if it's a
  82. * PCI interrupt, and if _not_ then we'll pass it on to the
  83. * ISA handler.
  84. */
  85. intstatus = inw(0x500) & 15;
  86. if (intstatus) {
  87. /*
  88. * This is a PCI interrupt. Check each bit and
  89. * despatch an interrupt if it's set.
  90. */
  91. if (intstatus & 8) handle_irq(16+3);
  92. if (intstatus & 4) handle_irq(16+2);
  93. if (intstatus & 2) handle_irq(16+1);
  94. if (intstatus & 1) handle_irq(16+0);
  95. } else {
  96. isa_device_interrupt(vector);
  97. }
  98. }
  99. static void
  100. eiger_srm_device_interrupt(unsigned long vector)
  101. {
  102. int irq = (vector - 0x800) >> 4;
  103. handle_irq(irq);
  104. }
  105. static void __init
  106. eiger_init_irq(void)
  107. {
  108. long i;
  109. outb(0, DMA1_RESET_REG);
  110. outb(0, DMA2_RESET_REG);
  111. outb(DMA_MODE_CASCADE, DMA2_MODE_REG);
  112. outb(0, DMA2_MASK_REG);
  113. if (alpha_using_srm)
  114. alpha_mv.device_interrupt = eiger_srm_device_interrupt;
  115. for (i = 16; i < 128; i += 16)
  116. eiger_update_irq_hw(i, -1);
  117. init_i8259a_irqs();
  118. for (i = 16; i < 128; ++i) {
  119. irq_set_chip_and_handler(i, &eiger_irq_type, handle_level_irq);
  120. irq_set_status_flags(i, IRQ_LEVEL);
  121. }
  122. }
  123. static int __init
  124. eiger_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
  125. {
  126. u8 irq_orig;
  127. /* The SRM console has already calculated out the IRQ value's for
  128. option cards. As this works lets just read in the value already
  129. set and change it to a useable value by Linux.
  130. All the IRQ values generated by the console are greater than 90,
  131. so we subtract 80 because it is (90 - allocated ISA IRQ's). */
  132. pci_read_config_byte(dev, PCI_INTERRUPT_LINE, &irq_orig);
  133. return irq_orig - 0x80;
  134. }
  135. static u8 __init
  136. eiger_swizzle(struct pci_dev *dev, u8 *pinp)
  137. {
  138. struct pci_controller *hose = dev->sysdata;
  139. int slot, pin = *pinp;
  140. int bridge_count = 0;
  141. /* Find the number of backplane bridges. */
  142. int backplane = inw(0x502) & 0x0f;
  143. switch (backplane)
  144. {
  145. case 0x00: bridge_count = 0; break; /* No bridges */
  146. case 0x01: bridge_count = 1; break; /* 1 */
  147. case 0x03: bridge_count = 2; break; /* 2 */
  148. case 0x07: bridge_count = 3; break; /* 3 */
  149. case 0x0f: bridge_count = 4; break; /* 4 */
  150. };
  151. slot = PCI_SLOT(dev->devfn);
  152. while (dev->bus->self) {
  153. /* Check for built-in bridges on hose 0. */
  154. if (hose->index == 0
  155. && (PCI_SLOT(dev->bus->self->devfn)
  156. > 20 - bridge_count)) {
  157. slot = PCI_SLOT(dev->devfn);
  158. break;
  159. }
  160. /* Must be a card-based bridge. */
  161. pin = pci_swizzle_interrupt_pin(dev, pin);
  162. /* Move up the chain of bridges. */
  163. dev = dev->bus->self;
  164. }
  165. *pinp = pin;
  166. return slot;
  167. }
  168. /*
  169. * The System Vectors
  170. */
  171. struct alpha_machine_vector eiger_mv __initmv = {
  172. .vector_name = "Eiger",
  173. DO_EV6_MMU,
  174. DO_DEFAULT_RTC,
  175. DO_TSUNAMI_IO,
  176. .machine_check = tsunami_machine_check,
  177. .max_isa_dma_address = ALPHA_MAX_ISA_DMA_ADDRESS,
  178. .min_io_address = DEFAULT_IO_BASE,
  179. .min_mem_address = DEFAULT_MEM_BASE,
  180. .pci_dac_offset = TSUNAMI_DAC_OFFSET,
  181. .nr_irqs = 128,
  182. .device_interrupt = eiger_device_interrupt,
  183. .init_arch = tsunami_init_arch,
  184. .init_irq = eiger_init_irq,
  185. .init_rtc = common_init_rtc,
  186. .init_pci = common_init_pci,
  187. .kill_arch = tsunami_kill_arch,
  188. .pci_map_irq = eiger_map_irq,
  189. .pci_swizzle = eiger_swizzle,
  190. };
  191. ALIAS_MV(eiger)