sys_sio.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  1. /*
  2. * linux/arch/alpha/kernel/sys_sio.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 for all boards that route the PCI interrupts through the SIO
  9. * PCI/ISA bridge. This includes Noname (AXPpci33), Multia (UDB),
  10. * Kenetics's Platform 2000, Avanti (AlphaStation), XL, and AlphaBook1.
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/types.h>
  14. #include <linux/mm.h>
  15. #include <linux/sched.h>
  16. #include <linux/pci.h>
  17. #include <linux/init.h>
  18. #include <linux/screen_info.h>
  19. #include <asm/compiler.h>
  20. #include <asm/ptrace.h>
  21. #include <asm/dma.h>
  22. #include <asm/irq.h>
  23. #include <asm/mmu_context.h>
  24. #include <asm/io.h>
  25. #include <asm/pgtable.h>
  26. #include <asm/core_apecs.h>
  27. #include <asm/core_lca.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. #include "pc873xx.h"
  34. #if defined(ALPHA_RESTORE_SRM_SETUP)
  35. /* Save LCA configuration data as the console had it set up. */
  36. struct
  37. {
  38. unsigned int orig_route_tab; /* for SAVE/RESTORE */
  39. } saved_config __attribute((common));
  40. #endif
  41. static void __init
  42. sio_init_irq(void)
  43. {
  44. if (alpha_using_srm)
  45. alpha_mv.device_interrupt = srm_device_interrupt;
  46. init_i8259a_irqs();
  47. common_init_isa_dma();
  48. }
  49. static inline void __init
  50. alphabook1_init_arch(void)
  51. {
  52. /* The AlphaBook1 has LCD video fixed at 800x600,
  53. 37 rows and 100 cols. */
  54. screen_info.orig_y = 37;
  55. screen_info.orig_video_cols = 100;
  56. screen_info.orig_video_lines = 37;
  57. lca_init_arch();
  58. }
  59. /*
  60. * sio_route_tab selects irq routing in PCI/ISA bridge so that:
  61. * PIRQ0 -> irq 15
  62. * PIRQ1 -> irq 9
  63. * PIRQ2 -> irq 10
  64. * PIRQ3 -> irq 11
  65. *
  66. * This probably ought to be configurable via MILO. For
  67. * example, sound boards seem to like using IRQ 9.
  68. *
  69. * This is NOT how we should do it. PIRQ0-X should have
  70. * their own IRQs, the way intel uses the IO-APIC IRQs.
  71. */
  72. static void __init
  73. sio_pci_route(void)
  74. {
  75. unsigned int orig_route_tab;
  76. /* First, ALWAYS read and print the original setting. */
  77. pci_bus_read_config_dword(pci_isa_hose->bus, PCI_DEVFN(7, 0), 0x60,
  78. &orig_route_tab);
  79. printk("%s: PIRQ original 0x%x new 0x%x\n", __func__,
  80. orig_route_tab, alpha_mv.sys.sio.route_tab);
  81. #if defined(ALPHA_RESTORE_SRM_SETUP)
  82. saved_config.orig_route_tab = orig_route_tab;
  83. #endif
  84. /* Now override with desired setting. */
  85. pci_bus_write_config_dword(pci_isa_hose->bus, PCI_DEVFN(7, 0), 0x60,
  86. alpha_mv.sys.sio.route_tab);
  87. }
  88. static unsigned int __init
  89. sio_collect_irq_levels(void)
  90. {
  91. unsigned int level_bits = 0;
  92. struct pci_dev *dev = NULL;
  93. /* Iterate through the devices, collecting IRQ levels. */
  94. for_each_pci_dev(dev) {
  95. if ((dev->class >> 16 == PCI_BASE_CLASS_BRIDGE) &&
  96. (dev->class >> 8 != PCI_CLASS_BRIDGE_PCMCIA))
  97. continue;
  98. if (dev->irq)
  99. level_bits |= (1 << dev->irq);
  100. }
  101. return level_bits;
  102. }
  103. static void __init
  104. sio_fixup_irq_levels(unsigned int level_bits)
  105. {
  106. unsigned int old_level_bits;
  107. /*
  108. * Now, make all PCI interrupts level sensitive. Notice:
  109. * these registers must be accessed byte-wise. inw()/outw()
  110. * don't work.
  111. *
  112. * Make sure to turn off any level bits set for IRQs 9,10,11,15,
  113. * so that the only bits getting set are for devices actually found.
  114. * Note that we do preserve the remainder of the bits, which we hope
  115. * will be set correctly by ARC/SRM.
  116. *
  117. * Note: we at least preserve any level-set bits on AlphaBook1
  118. */
  119. old_level_bits = inb(0x4d0) | (inb(0x4d1) << 8);
  120. level_bits |= (old_level_bits & 0x71ff);
  121. outb((level_bits >> 0) & 0xff, 0x4d0);
  122. outb((level_bits >> 8) & 0xff, 0x4d1);
  123. }
  124. static inline int __init
  125. noname_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
  126. {
  127. /*
  128. * The Noname board has 5 PCI slots with each of the 4
  129. * interrupt pins routed to different pins on the PCI/ISA
  130. * bridge (PIRQ0-PIRQ3). The table below is based on
  131. * information available at:
  132. *
  133. * http://ftp.digital.com/pub/DEC/axppci/ref_interrupts.txt
  134. *
  135. * I have no information on the Avanti interrupt routing, but
  136. * the routing seems to be identical to the Noname except
  137. * that the Avanti has an additional slot whose routing I'm
  138. * unsure of.
  139. *
  140. * pirq_tab[0] is a fake entry to deal with old PCI boards
  141. * that have the interrupt pin number hardwired to 0 (meaning
  142. * that they use the default INTA line, if they are interrupt
  143. * driven at all).
  144. */
  145. static char irq_tab[][5] __initdata = {
  146. /*INT A B C D */
  147. { 3, 3, 3, 3, 3}, /* idsel 6 (53c810) */
  148. {-1, -1, -1, -1, -1}, /* idsel 7 (SIO: PCI/ISA bridge) */
  149. { 2, 2, -1, -1, -1}, /* idsel 8 (Hack: slot closest ISA) */
  150. {-1, -1, -1, -1, -1}, /* idsel 9 (unused) */
  151. {-1, -1, -1, -1, -1}, /* idsel 10 (unused) */
  152. { 0, 0, 2, 1, 0}, /* idsel 11 KN25_PCI_SLOT0 */
  153. { 1, 1, 0, 2, 1}, /* idsel 12 KN25_PCI_SLOT1 */
  154. { 2, 2, 1, 0, 2}, /* idsel 13 KN25_PCI_SLOT2 */
  155. { 0, 0, 0, 0, 0}, /* idsel 14 AS255 TULIP */
  156. };
  157. const long min_idsel = 6, max_idsel = 14, irqs_per_slot = 5;
  158. int irq = COMMON_TABLE_LOOKUP, tmp;
  159. tmp = __kernel_extbl(alpha_mv.sys.sio.route_tab, irq);
  160. return irq >= 0 ? tmp : -1;
  161. }
  162. static inline int __init
  163. p2k_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
  164. {
  165. static char irq_tab[][5] __initdata = {
  166. /*INT A B C D */
  167. { 0, 0, -1, -1, -1}, /* idsel 6 (53c810) */
  168. {-1, -1, -1, -1, -1}, /* idsel 7 (SIO: PCI/ISA bridge) */
  169. { 1, 1, 2, 3, 0}, /* idsel 8 (slot A) */
  170. { 2, 2, 3, 0, 1}, /* idsel 9 (slot B) */
  171. {-1, -1, -1, -1, -1}, /* idsel 10 (unused) */
  172. {-1, -1, -1, -1, -1}, /* idsel 11 (unused) */
  173. { 3, 3, -1, -1, -1}, /* idsel 12 (CMD0646) */
  174. };
  175. const long min_idsel = 6, max_idsel = 12, irqs_per_slot = 5;
  176. int irq = COMMON_TABLE_LOOKUP, tmp;
  177. tmp = __kernel_extbl(alpha_mv.sys.sio.route_tab, irq);
  178. return irq >= 0 ? tmp : -1;
  179. }
  180. static inline void __init
  181. noname_init_pci(void)
  182. {
  183. common_init_pci();
  184. sio_pci_route();
  185. sio_fixup_irq_levels(sio_collect_irq_levels());
  186. if (pc873xx_probe() == -1) {
  187. printk(KERN_ERR "Probing for PC873xx Super IO chip failed.\n");
  188. } else {
  189. printk(KERN_INFO "Found %s Super IO chip at 0x%x\n",
  190. pc873xx_get_model(), pc873xx_get_base());
  191. /* Enabling things in the Super IO chip doesn't actually
  192. * configure and enable things, the legacy drivers still
  193. * need to do the actual configuration and enabling.
  194. * This only unblocks them.
  195. */
  196. #if !defined(CONFIG_ALPHA_AVANTI)
  197. /* Don't bother on the Avanti family.
  198. * None of them had on-board IDE.
  199. */
  200. pc873xx_enable_ide();
  201. #endif
  202. pc873xx_enable_epp19();
  203. }
  204. }
  205. static inline void __init
  206. alphabook1_init_pci(void)
  207. {
  208. struct pci_dev *dev;
  209. unsigned char orig, config;
  210. common_init_pci();
  211. sio_pci_route();
  212. /*
  213. * On the AlphaBook1, the PCMCIA chip (Cirrus 6729)
  214. * is sensitive to PCI bus bursts, so we must DISABLE
  215. * burst mode for the NCR 8xx SCSI... :-(
  216. *
  217. * Note that the NCR810 SCSI driver must preserve the
  218. * setting of the bit in order for this to work. At the
  219. * moment (2.0.29), ncr53c8xx.c does NOT do this, but
  220. * 53c7,8xx.c DOES.
  221. */
  222. dev = NULL;
  223. while ((dev = pci_get_device(PCI_VENDOR_ID_NCR, PCI_ANY_ID, dev))) {
  224. if (dev->device == PCI_DEVICE_ID_NCR_53C810
  225. || dev->device == PCI_DEVICE_ID_NCR_53C815
  226. || dev->device == PCI_DEVICE_ID_NCR_53C820
  227. || dev->device == PCI_DEVICE_ID_NCR_53C825) {
  228. unsigned long io_port;
  229. unsigned char ctest4;
  230. io_port = dev->resource[0].start;
  231. ctest4 = inb(io_port+0x21);
  232. if (!(ctest4 & 0x80)) {
  233. printk("AlphaBook1 NCR init: setting"
  234. " burst disable\n");
  235. outb(ctest4 | 0x80, io_port+0x21);
  236. }
  237. }
  238. }
  239. /* Do not set *ANY* level triggers for AlphaBook1. */
  240. sio_fixup_irq_levels(0);
  241. /* Make sure that register PR1 indicates 1Mb mem */
  242. outb(0x0f, 0x3ce); orig = inb(0x3cf); /* read PR5 */
  243. outb(0x0f, 0x3ce); outb(0x05, 0x3cf); /* unlock PR0-4 */
  244. outb(0x0b, 0x3ce); config = inb(0x3cf); /* read PR1 */
  245. if ((config & 0xc0) != 0xc0) {
  246. printk("AlphaBook1 VGA init: setting 1Mb memory\n");
  247. config |= 0xc0;
  248. outb(0x0b, 0x3ce); outb(config, 0x3cf); /* write PR1 */
  249. }
  250. outb(0x0f, 0x3ce); outb(orig, 0x3cf); /* (re)lock PR0-4 */
  251. }
  252. void
  253. sio_kill_arch(int mode)
  254. {
  255. #if defined(ALPHA_RESTORE_SRM_SETUP)
  256. /* Since we cannot read the PCI DMA Window CSRs, we
  257. * cannot restore them here.
  258. *
  259. * However, we CAN read the PIRQ route register, so restore it
  260. * now...
  261. */
  262. pci_bus_write_config_dword(pci_isa_hose->bus, PCI_DEVFN(7, 0), 0x60,
  263. saved_config.orig_route_tab);
  264. #endif
  265. }
  266. /*
  267. * The System Vectors
  268. */
  269. #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_BOOK1)
  270. struct alpha_machine_vector alphabook1_mv __initmv = {
  271. .vector_name = "AlphaBook1",
  272. DO_EV4_MMU,
  273. DO_DEFAULT_RTC,
  274. DO_LCA_IO,
  275. .machine_check = lca_machine_check,
  276. .max_isa_dma_address = ALPHA_MAX_ISA_DMA_ADDRESS,
  277. .min_io_address = DEFAULT_IO_BASE,
  278. .min_mem_address = APECS_AND_LCA_DEFAULT_MEM_BASE,
  279. .nr_irqs = 16,
  280. .device_interrupt = isa_device_interrupt,
  281. .init_arch = alphabook1_init_arch,
  282. .init_irq = sio_init_irq,
  283. .init_rtc = common_init_rtc,
  284. .init_pci = alphabook1_init_pci,
  285. .kill_arch = sio_kill_arch,
  286. .pci_map_irq = noname_map_irq,
  287. .pci_swizzle = common_swizzle,
  288. .sys = { .sio = {
  289. /* NCR810 SCSI is 14, PCMCIA controller is 15. */
  290. .route_tab = 0x0e0f0a0a,
  291. }}
  292. };
  293. ALIAS_MV(alphabook1)
  294. #endif
  295. #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_AVANTI)
  296. struct alpha_machine_vector avanti_mv __initmv = {
  297. .vector_name = "Avanti",
  298. DO_EV4_MMU,
  299. DO_DEFAULT_RTC,
  300. DO_APECS_IO,
  301. .machine_check = apecs_machine_check,
  302. .max_isa_dma_address = ALPHA_MAX_ISA_DMA_ADDRESS,
  303. .min_io_address = DEFAULT_IO_BASE,
  304. .min_mem_address = APECS_AND_LCA_DEFAULT_MEM_BASE,
  305. .nr_irqs = 16,
  306. .device_interrupt = isa_device_interrupt,
  307. .init_arch = apecs_init_arch,
  308. .init_irq = sio_init_irq,
  309. .init_rtc = common_init_rtc,
  310. .init_pci = noname_init_pci,
  311. .kill_arch = sio_kill_arch,
  312. .pci_map_irq = noname_map_irq,
  313. .pci_swizzle = common_swizzle,
  314. .sys = { .sio = {
  315. .route_tab = 0x0b0a050f, /* leave 14 for IDE, 9 for SND */
  316. }}
  317. };
  318. ALIAS_MV(avanti)
  319. #endif
  320. #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_NONAME)
  321. struct alpha_machine_vector noname_mv __initmv = {
  322. .vector_name = "Noname",
  323. DO_EV4_MMU,
  324. DO_DEFAULT_RTC,
  325. DO_LCA_IO,
  326. .machine_check = lca_machine_check,
  327. .max_isa_dma_address = ALPHA_MAX_ISA_DMA_ADDRESS,
  328. .min_io_address = DEFAULT_IO_BASE,
  329. .min_mem_address = APECS_AND_LCA_DEFAULT_MEM_BASE,
  330. .nr_irqs = 16,
  331. .device_interrupt = srm_device_interrupt,
  332. .init_arch = lca_init_arch,
  333. .init_irq = sio_init_irq,
  334. .init_rtc = common_init_rtc,
  335. .init_pci = noname_init_pci,
  336. .kill_arch = sio_kill_arch,
  337. .pci_map_irq = noname_map_irq,
  338. .pci_swizzle = common_swizzle,
  339. .sys = { .sio = {
  340. /* For UDB, the only available PCI slot must not map to IRQ 9,
  341. since that's the builtin MSS sound chip. That PCI slot
  342. will map to PIRQ1 (for INTA at least), so we give it IRQ 15
  343. instead.
  344. Unfortunately we have to do this for NONAME as well, since
  345. they are co-indicated when the platform type "Noname" is
  346. selected... :-( */
  347. .route_tab = 0x0b0a0f0d,
  348. }}
  349. };
  350. ALIAS_MV(noname)
  351. #endif
  352. #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_P2K)
  353. struct alpha_machine_vector p2k_mv __initmv = {
  354. .vector_name = "Platform2000",
  355. DO_EV4_MMU,
  356. DO_DEFAULT_RTC,
  357. DO_LCA_IO,
  358. .machine_check = lca_machine_check,
  359. .max_isa_dma_address = ALPHA_MAX_ISA_DMA_ADDRESS,
  360. .min_io_address = DEFAULT_IO_BASE,
  361. .min_mem_address = APECS_AND_LCA_DEFAULT_MEM_BASE,
  362. .nr_irqs = 16,
  363. .device_interrupt = srm_device_interrupt,
  364. .init_arch = lca_init_arch,
  365. .init_irq = sio_init_irq,
  366. .init_rtc = common_init_rtc,
  367. .init_pci = noname_init_pci,
  368. .kill_arch = sio_kill_arch,
  369. .pci_map_irq = p2k_map_irq,
  370. .pci_swizzle = common_swizzle,
  371. .sys = { .sio = {
  372. .route_tab = 0x0b0a090f,
  373. }}
  374. };
  375. ALIAS_MV(p2k)
  376. #endif
  377. #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_XL)
  378. struct alpha_machine_vector xl_mv __initmv = {
  379. .vector_name = "XL",
  380. DO_EV4_MMU,
  381. DO_DEFAULT_RTC,
  382. DO_APECS_IO,
  383. .machine_check = apecs_machine_check,
  384. .max_isa_dma_address = ALPHA_XL_MAX_ISA_DMA_ADDRESS,
  385. .min_io_address = DEFAULT_IO_BASE,
  386. .min_mem_address = XL_DEFAULT_MEM_BASE,
  387. .nr_irqs = 16,
  388. .device_interrupt = isa_device_interrupt,
  389. .init_arch = apecs_init_arch,
  390. .init_irq = sio_init_irq,
  391. .init_rtc = common_init_rtc,
  392. .init_pci = noname_init_pci,
  393. .kill_arch = sio_kill_arch,
  394. .pci_map_irq = noname_map_irq,
  395. .pci_swizzle = common_swizzle,
  396. .sys = { .sio = {
  397. .route_tab = 0x0b0a090f,
  398. }}
  399. };
  400. ALIAS_MV(xl)
  401. #endif