sys_ruffian.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * linux/arch/alpha/kernel/sys_ruffian.c
  4. *
  5. * Copyright (C) 1995 David A Rusling
  6. * Copyright (C) 1996 Jay A Estabrook
  7. * Copyright (C) 1998, 1999, 2000 Richard Henderson
  8. *
  9. * Code supporting the RUFFIAN.
  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/ioport.h>
  17. #include <linux/timex.h>
  18. #include <linux/init.h>
  19. #include <asm/ptrace.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/core_cia.h>
  25. #include <asm/tlbflush.h>
  26. #include "proto.h"
  27. #include "irq_impl.h"
  28. #include "pci_impl.h"
  29. #include "machvec_impl.h"
  30. static void __init
  31. ruffian_init_irq(void)
  32. {
  33. /* Invert 6&7 for i82371 */
  34. *(vulp)PYXIS_INT_HILO = 0x000000c0UL; mb();
  35. *(vulp)PYXIS_INT_CNFG = 0x00002064UL; mb(); /* all clear */
  36. outb(0x11,0xA0);
  37. outb(0x08,0xA1);
  38. outb(0x02,0xA1);
  39. outb(0x01,0xA1);
  40. outb(0xFF,0xA1);
  41. outb(0x11,0x20);
  42. outb(0x00,0x21);
  43. outb(0x04,0x21);
  44. outb(0x01,0x21);
  45. outb(0xFF,0x21);
  46. /* Finish writing the 82C59A PIC Operation Control Words */
  47. outb(0x20,0xA0);
  48. outb(0x20,0x20);
  49. init_i8259a_irqs();
  50. /* Not interested in the bogus interrupts (0,3,6),
  51. NMI (1), HALT (2), flash (5), or 21142 (8). */
  52. init_pyxis_irqs(0x16f0000);
  53. common_init_isa_dma();
  54. }
  55. #define RUFFIAN_LATCH DIV_ROUND_CLOSEST(PIT_TICK_RATE, HZ)
  56. static void __init
  57. ruffian_init_rtc(void)
  58. {
  59. /* Ruffian does not have the RTC connected to the CPU timer
  60. interrupt. Instead, it uses the PIT connected to IRQ 0. */
  61. /* Setup interval timer. */
  62. outb(0x34, 0x43); /* binary, mode 2, LSB/MSB, ch 0 */
  63. outb(RUFFIAN_LATCH & 0xff, 0x40); /* LSB */
  64. outb(RUFFIAN_LATCH >> 8, 0x40); /* MSB */
  65. outb(0xb6, 0x43); /* pit counter 2: speaker */
  66. outb(0x31, 0x42);
  67. outb(0x13, 0x42);
  68. if (request_irq(0, rtc_timer_interrupt, 0, "timer", NULL))
  69. pr_err("Failed to request irq 0 (timer)\n");
  70. }
  71. static void
  72. ruffian_kill_arch (int mode)
  73. {
  74. cia_kill_arch(mode);
  75. #if 0
  76. /* This only causes re-entry to ARCSBIOS */
  77. /* Perhaps this works for other PYXIS as well? */
  78. *(vuip) PYXIS_RESET = 0x0000dead;
  79. mb();
  80. #endif
  81. }
  82. /*
  83. * Interrupt routing:
  84. *
  85. * Primary bus
  86. * IdSel INTA INTB INTC INTD
  87. * 21052 13 - - - -
  88. * SIO 14 23 - - -
  89. * 21143 15 44 - - -
  90. * Slot 0 17 43 42 41 40
  91. *
  92. * Secondary bus
  93. * IdSel INTA INTB INTC INTD
  94. * Slot 0 8 (18) 19 18 17 16
  95. * Slot 1 9 (19) 31 30 29 28
  96. * Slot 2 10 (20) 27 26 25 24
  97. * Slot 3 11 (21) 39 38 37 36
  98. * Slot 4 12 (22) 35 34 33 32
  99. * 53c875 13 (23) 20 - - -
  100. *
  101. */
  102. static int
  103. ruffian_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
  104. {
  105. static char irq_tab[11][5] = {
  106. /*INT INTA INTB INTC INTD */
  107. {-1, -1, -1, -1, -1}, /* IdSel 13, 21052 */
  108. {-1, -1, -1, -1, -1}, /* IdSel 14, SIO */
  109. {44, 44, 44, 44, 44}, /* IdSel 15, 21143 */
  110. {-1, -1, -1, -1, -1}, /* IdSel 16, none */
  111. {43, 43, 42, 41, 40}, /* IdSel 17, 64-bit slot */
  112. /* the next 6 are actually on PCI bus 1, across the bridge */
  113. {19, 19, 18, 17, 16}, /* IdSel 8, slot 0 */
  114. {31, 31, 30, 29, 28}, /* IdSel 9, slot 1 */
  115. {27, 27, 26, 25, 24}, /* IdSel 10, slot 2 */
  116. {39, 39, 38, 37, 36}, /* IdSel 11, slot 3 */
  117. {35, 35, 34, 33, 32}, /* IdSel 12, slot 4 */
  118. {20, 20, 20, 20, 20}, /* IdSel 13, 53c875 */
  119. };
  120. const long min_idsel = 13, max_idsel = 23, irqs_per_slot = 5;
  121. return COMMON_TABLE_LOOKUP;
  122. }
  123. static u8
  124. ruffian_swizzle(struct pci_dev *dev, u8 *pinp)
  125. {
  126. int slot, pin = *pinp;
  127. if (dev->bus->number == 0) {
  128. slot = PCI_SLOT(dev->devfn);
  129. }
  130. /* Check for the built-in bridge. */
  131. else if (PCI_SLOT(dev->bus->self->devfn) == 13) {
  132. slot = PCI_SLOT(dev->devfn) + 10;
  133. }
  134. else
  135. {
  136. /* Must be a card-based bridge. */
  137. do {
  138. if (PCI_SLOT(dev->bus->self->devfn) == 13) {
  139. slot = PCI_SLOT(dev->devfn) + 10;
  140. break;
  141. }
  142. pin = pci_swizzle_interrupt_pin(dev, pin);
  143. /* Move up the chain of bridges. */
  144. dev = dev->bus->self;
  145. /* Slot of the next bridge. */
  146. slot = PCI_SLOT(dev->devfn);
  147. } while (dev->bus->self);
  148. }
  149. *pinp = pin;
  150. return slot;
  151. }
  152. #ifdef BUILDING_FOR_MILO
  153. /*
  154. * The DeskStation Ruffian motherboard firmware does not place
  155. * the memory size in the PALimpure area. Therefore, we use
  156. * the Bank Configuration Registers in PYXIS to obtain the size.
  157. */
  158. static unsigned long __init
  159. ruffian_get_bank_size(unsigned long offset)
  160. {
  161. unsigned long bank_addr, bank, ret = 0;
  162. /* Valid offsets are: 0x800, 0x840 and 0x880
  163. since Ruffian only uses three banks. */
  164. bank_addr = (unsigned long)PYXIS_MCR + offset;
  165. bank = *(vulp)bank_addr;
  166. /* Check BANK_ENABLE */
  167. if (bank & 0x01) {
  168. static unsigned long size[] __initdata = {
  169. 0x40000000UL, /* 0x00, 1G */
  170. 0x20000000UL, /* 0x02, 512M */
  171. 0x10000000UL, /* 0x04, 256M */
  172. 0x08000000UL, /* 0x06, 128M */
  173. 0x04000000UL, /* 0x08, 64M */
  174. 0x02000000UL, /* 0x0a, 32M */
  175. 0x01000000UL, /* 0x0c, 16M */
  176. 0x00800000UL, /* 0x0e, 8M */
  177. 0x80000000UL, /* 0x10, 2G */
  178. };
  179. bank = (bank & 0x1e) >> 1;
  180. if (bank < ARRAY_SIZE(size))
  181. ret = size[bank];
  182. }
  183. return ret;
  184. }
  185. #endif /* BUILDING_FOR_MILO */
  186. /*
  187. * The System Vector
  188. */
  189. struct alpha_machine_vector ruffian_mv __initmv = {
  190. .vector_name = "Ruffian",
  191. DO_EV5_MMU,
  192. DO_DEFAULT_RTC,
  193. DO_PYXIS_IO,
  194. .machine_check = cia_machine_check,
  195. .max_isa_dma_address = ALPHA_RUFFIAN_MAX_ISA_DMA_ADDRESS,
  196. .min_io_address = DEFAULT_IO_BASE,
  197. .min_mem_address = DEFAULT_MEM_BASE,
  198. .pci_dac_offset = PYXIS_DAC_OFFSET,
  199. .nr_irqs = 48,
  200. .device_interrupt = pyxis_device_interrupt,
  201. .init_arch = pyxis_init_arch,
  202. .init_irq = ruffian_init_irq,
  203. .init_rtc = ruffian_init_rtc,
  204. .init_pci = cia_init_pci,
  205. .kill_arch = ruffian_kill_arch,
  206. .pci_map_irq = ruffian_map_irq,
  207. .pci_swizzle = ruffian_swizzle,
  208. };
  209. ALIAS_MV(ruffian)