sys_sio.c 12 KB

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