sys_cabriolet.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * linux/arch/alpha/kernel/sys_cabriolet.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 PC164 and LX164.
  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/dma.h>
  20. #include <asm/irq.h>
  21. #include <asm/mmu_context.h>
  22. #include <asm/io.h>
  23. #include <asm/core_cia.h>
  24. #include <asm/tlbflush.h>
  25. #include "proto.h"
  26. #include "irq_impl.h"
  27. #include "pci_impl.h"
  28. #include "machvec_impl.h"
  29. #include "pc873xx.h"
  30. /* Note mask bit is true for DISABLED irqs. */
  31. static unsigned long cached_irq_mask = ~0UL;
  32. static inline void
  33. cabriolet_update_irq_hw(unsigned int irq, unsigned long mask)
  34. {
  35. int ofs = (irq - 16) / 8;
  36. outb(mask >> (16 + ofs * 8), 0x804 + ofs);
  37. }
  38. static inline void
  39. cabriolet_enable_irq(struct irq_data *d)
  40. {
  41. cabriolet_update_irq_hw(d->irq, cached_irq_mask &= ~(1UL << d->irq));
  42. }
  43. static void
  44. cabriolet_disable_irq(struct irq_data *d)
  45. {
  46. cabriolet_update_irq_hw(d->irq, cached_irq_mask |= 1UL << d->irq);
  47. }
  48. static struct irq_chip cabriolet_irq_type = {
  49. .name = "CABRIOLET",
  50. .irq_unmask = cabriolet_enable_irq,
  51. .irq_mask = cabriolet_disable_irq,
  52. .irq_mask_ack = cabriolet_disable_irq,
  53. };
  54. static void
  55. cabriolet_device_interrupt(unsigned long v)
  56. {
  57. unsigned long pld;
  58. unsigned int i;
  59. /* Read the interrupt summary registers */
  60. pld = inb(0x804) | (inb(0x805) << 8) | (inb(0x806) << 16);
  61. /*
  62. * Now for every possible bit set, work through them and call
  63. * the appropriate interrupt handler.
  64. */
  65. while (pld) {
  66. i = ffz(~pld);
  67. pld &= pld - 1; /* clear least bit set */
  68. if (i == 4) {
  69. isa_device_interrupt(v);
  70. } else {
  71. handle_irq(16 + i);
  72. }
  73. }
  74. }
  75. static void __init
  76. common_init_irq(void (*srm_dev_int)(unsigned long v))
  77. {
  78. init_i8259a_irqs();
  79. if (alpha_using_srm) {
  80. alpha_mv.device_interrupt = srm_dev_int;
  81. init_srm_irqs(35, 0);
  82. }
  83. else {
  84. long i;
  85. outb(0xff, 0x804);
  86. outb(0xff, 0x805);
  87. outb(0xff, 0x806);
  88. for (i = 16; i < 35; ++i) {
  89. irq_set_chip_and_handler(i, &cabriolet_irq_type,
  90. handle_level_irq);
  91. irq_set_status_flags(i, IRQ_LEVEL);
  92. }
  93. }
  94. common_init_isa_dma();
  95. if (request_irq(16 + 4, no_action, 0, "isa-cascade", NULL))
  96. pr_err("Failed to register isa-cascade interrupt\n");
  97. }
  98. #ifndef CONFIG_ALPHA_PC164
  99. static void __init
  100. cabriolet_init_irq(void)
  101. {
  102. common_init_irq(srm_device_interrupt);
  103. }
  104. #endif
  105. #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_PC164)
  106. /* In theory, the PC164 has the same interrupt hardware as the other
  107. Cabriolet based systems. However, something got screwed up late
  108. in the development cycle which broke the interrupt masking hardware.
  109. Repeat, it is not possible to mask and ack interrupts. At all.
  110. In an attempt to work around this, while processing interrupts,
  111. we do not allow the IPL to drop below what it is currently. This
  112. prevents the possibility of recursion.
  113. ??? Another option might be to force all PCI devices to use edge
  114. triggered rather than level triggered interrupts. That might be
  115. too invasive though. */
  116. static void
  117. pc164_srm_device_interrupt(unsigned long v)
  118. {
  119. __min_ipl = getipl();
  120. srm_device_interrupt(v);
  121. __min_ipl = 0;
  122. }
  123. static void
  124. pc164_device_interrupt(unsigned long v)
  125. {
  126. __min_ipl = getipl();
  127. cabriolet_device_interrupt(v);
  128. __min_ipl = 0;
  129. }
  130. static void __init
  131. pc164_init_irq(void)
  132. {
  133. common_init_irq(pc164_srm_device_interrupt);
  134. }
  135. #endif
  136. /*
  137. * The EB66+ is very similar to the EB66 except that it does not have
  138. * the on-board NCR and Tulip chips. In the code below, I have used
  139. * slot number to refer to the id select line and *not* the slot
  140. * number used in the EB66+ documentation. However, in the table,
  141. * I've given the slot number, the id select line and the Jxx number
  142. * that's printed on the board. The interrupt pins from the PCI slots
  143. * are wired into 3 interrupt summary registers at 0x804, 0x805 and
  144. * 0x806 ISA.
  145. *
  146. * In the table, -1 means don't assign an IRQ number. This is usually
  147. * because it is the Saturn IO (SIO) PCI/ISA Bridge Chip.
  148. */
  149. static inline int
  150. eb66p_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
  151. {
  152. static char irq_tab[5][5] = {
  153. /*INT INTA INTB INTC INTD */
  154. {16+0, 16+0, 16+5, 16+9, 16+13}, /* IdSel 6, slot 0, J25 */
  155. {16+1, 16+1, 16+6, 16+10, 16+14}, /* IdSel 7, slot 1, J26 */
  156. { -1, -1, -1, -1, -1}, /* IdSel 8, SIO */
  157. {16+2, 16+2, 16+7, 16+11, 16+15}, /* IdSel 9, slot 2, J27 */
  158. {16+3, 16+3, 16+8, 16+12, 16+6} /* IdSel 10, slot 3, J28 */
  159. };
  160. const long min_idsel = 6, max_idsel = 10, irqs_per_slot = 5;
  161. return COMMON_TABLE_LOOKUP;
  162. }
  163. /*
  164. * The AlphaPC64 is very similar to the EB66+ except that its slots
  165. * are numbered differently. In the code below, I have used slot
  166. * number to refer to the id select line and *not* the slot number
  167. * used in the AlphaPC64 documentation. However, in the table, I've
  168. * given the slot number, the id select line and the Jxx number that's
  169. * printed on the board. The interrupt pins from the PCI slots are
  170. * wired into 3 interrupt summary registers at 0x804, 0x805 and 0x806
  171. * ISA.
  172. *
  173. * In the table, -1 means don't assign an IRQ number. This is usually
  174. * because it is the Saturn IO (SIO) PCI/ISA Bridge Chip.
  175. */
  176. static inline int
  177. cabriolet_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
  178. {
  179. static char irq_tab[5][5] = {
  180. /*INT INTA INTB INTC INTD */
  181. { 16+2, 16+2, 16+7, 16+11, 16+15}, /* IdSel 5, slot 2, J21 */
  182. { 16+0, 16+0, 16+5, 16+9, 16+13}, /* IdSel 6, slot 0, J19 */
  183. { 16+1, 16+1, 16+6, 16+10, 16+14}, /* IdSel 7, slot 1, J20 */
  184. { -1, -1, -1, -1, -1}, /* IdSel 8, SIO */
  185. { 16+3, 16+3, 16+8, 16+12, 16+16} /* IdSel 9, slot 3, J22 */
  186. };
  187. const long min_idsel = 5, max_idsel = 9, irqs_per_slot = 5;
  188. return COMMON_TABLE_LOOKUP;
  189. }
  190. static inline void __init
  191. cabriolet_enable_ide(void)
  192. {
  193. if (pc873xx_probe() == -1) {
  194. printk(KERN_ERR "Probing for PC873xx Super IO chip failed.\n");
  195. } else {
  196. printk(KERN_INFO "Found %s Super IO chip at 0x%x\n",
  197. pc873xx_get_model(), pc873xx_get_base());
  198. pc873xx_enable_ide();
  199. }
  200. }
  201. static inline void __init
  202. cia_cab_init_pci(void)
  203. {
  204. cia_init_pci();
  205. cabriolet_enable_ide();
  206. }
  207. /*
  208. * The PC164 and LX164 have 19 PCI interrupts, four from each of the four
  209. * PCI slots, the SIO, PCI/IDE, and USB.
  210. *
  211. * Each of the interrupts can be individually masked. This is
  212. * accomplished by setting the appropriate bit in the mask register.
  213. * A bit is set by writing a "1" to the desired position in the mask
  214. * register and cleared by writing a "0". There are 3 mask registers
  215. * located at ISA address 804h, 805h and 806h.
  216. *
  217. * An I/O read at ISA address 804h, 805h, 806h will return the
  218. * state of the 11 PCI interrupts and not the state of the MASKED
  219. * interrupts.
  220. *
  221. * Note: A write to I/O 804h, 805h, and 806h the mask register will be
  222. * updated.
  223. *
  224. *
  225. * ISA DATA<7:0>
  226. * ISA +--------------------------------------------------------------+
  227. * ADDRESS | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
  228. * +==============================================================+
  229. * 0x804 | INTB0 | USB | IDE | SIO | INTA3 |INTA2 | INTA1 | INTA0 |
  230. * +--------------------------------------------------------------+
  231. * 0x805 | INTD0 | INTC3 | INTC2 | INTC1 | INTC0 |INTB3 | INTB2 | INTB1 |
  232. * +--------------------------------------------------------------+
  233. * 0x806 | Rsrv | Rsrv | Rsrv | Rsrv | Rsrv |INTD3 | INTD2 | INTD1 |
  234. * +--------------------------------------------------------------+
  235. * * Rsrv = reserved bits
  236. * Note: The mask register is write-only.
  237. *
  238. * IdSel
  239. * 5 32 bit PCI option slot 2
  240. * 6 64 bit PCI option slot 0
  241. * 7 64 bit PCI option slot 1
  242. * 8 Saturn I/O
  243. * 9 32 bit PCI option slot 3
  244. * 10 USB
  245. * 11 IDE
  246. *
  247. */
  248. static inline int
  249. alphapc164_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
  250. {
  251. static char irq_tab[7][5] = {
  252. /*INT INTA INTB INTC INTD */
  253. { 16+2, 16+2, 16+9, 16+13, 16+17}, /* IdSel 5, slot 2, J20 */
  254. { 16+0, 16+0, 16+7, 16+11, 16+15}, /* IdSel 6, slot 0, J29 */
  255. { 16+1, 16+1, 16+8, 16+12, 16+16}, /* IdSel 7, slot 1, J26 */
  256. { -1, -1, -1, -1, -1}, /* IdSel 8, SIO */
  257. { 16+3, 16+3, 16+10, 16+14, 16+18}, /* IdSel 9, slot 3, J19 */
  258. { 16+6, 16+6, 16+6, 16+6, 16+6}, /* IdSel 10, USB */
  259. { 16+5, 16+5, 16+5, 16+5, 16+5} /* IdSel 11, IDE */
  260. };
  261. const long min_idsel = 5, max_idsel = 11, irqs_per_slot = 5;
  262. return COMMON_TABLE_LOOKUP;
  263. }
  264. static inline void __init
  265. alphapc164_init_pci(void)
  266. {
  267. cia_init_pci();
  268. SMC93x_Init();
  269. }
  270. /*
  271. * The System Vector
  272. */
  273. #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_LX164)
  274. struct alpha_machine_vector lx164_mv __initmv = {
  275. .vector_name = "LX164",
  276. DO_EV5_MMU,
  277. DO_DEFAULT_RTC,
  278. DO_PYXIS_IO,
  279. .machine_check = cia_machine_check,
  280. .max_isa_dma_address = ALPHA_MAX_ISA_DMA_ADDRESS,
  281. .min_io_address = DEFAULT_IO_BASE,
  282. .min_mem_address = DEFAULT_MEM_BASE,
  283. .pci_dac_offset = PYXIS_DAC_OFFSET,
  284. .nr_irqs = 35,
  285. .device_interrupt = cabriolet_device_interrupt,
  286. .init_arch = pyxis_init_arch,
  287. .init_irq = cabriolet_init_irq,
  288. .init_rtc = common_init_rtc,
  289. .init_pci = alphapc164_init_pci,
  290. .kill_arch = cia_kill_arch,
  291. .pci_map_irq = alphapc164_map_irq,
  292. .pci_swizzle = common_swizzle,
  293. };
  294. ALIAS_MV(lx164)
  295. #endif
  296. #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_PC164)
  297. struct alpha_machine_vector pc164_mv __initmv = {
  298. .vector_name = "PC164",
  299. DO_EV5_MMU,
  300. DO_DEFAULT_RTC,
  301. DO_CIA_IO,
  302. .machine_check = cia_machine_check,
  303. .max_isa_dma_address = ALPHA_MAX_ISA_DMA_ADDRESS,
  304. .min_io_address = DEFAULT_IO_BASE,
  305. .min_mem_address = CIA_DEFAULT_MEM_BASE,
  306. .nr_irqs = 35,
  307. .device_interrupt = pc164_device_interrupt,
  308. .init_arch = cia_init_arch,
  309. .init_irq = pc164_init_irq,
  310. .init_rtc = common_init_rtc,
  311. .init_pci = alphapc164_init_pci,
  312. .kill_arch = cia_kill_arch,
  313. .pci_map_irq = alphapc164_map_irq,
  314. .pci_swizzle = common_swizzle,
  315. };
  316. ALIAS_MV(pc164)
  317. #endif