visws_quirks.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  1. /*
  2. * SGI Visual Workstation support and quirks, unmaintained.
  3. *
  4. * Split out from setup.c by davej@suse.de
  5. *
  6. * Copyright (C) 1999 Bent Hagemark, Ingo Molnar
  7. *
  8. * SGI Visual Workstation interrupt controller
  9. *
  10. * The Cobalt system ASIC in the Visual Workstation contains a "Cobalt" APIC
  11. * which serves as the main interrupt controller in the system. Non-legacy
  12. * hardware in the system uses this controller directly. Legacy devices
  13. * are connected to the PIIX4 which in turn has its 8259(s) connected to
  14. * a of the Cobalt APIC entry.
  15. *
  16. * 09/02/2000 - Updated for 2.4 by jbarnes@sgi.com
  17. *
  18. * 25/11/2002 - Updated for 2.5 by Andrey Panin <pazke@orbita1.ru>
  19. */
  20. #include <linux/interrupt.h>
  21. #include <linux/module.h>
  22. #include <linux/init.h>
  23. #include <linux/smp.h>
  24. #include <asm/visws/cobalt.h>
  25. #include <asm/visws/piix4.h>
  26. #include <asm/arch_hooks.h>
  27. #include <asm/fixmap.h>
  28. #include <asm/reboot.h>
  29. #include <asm/setup.h>
  30. #include <asm/e820.h>
  31. #include <asm/smp.h>
  32. #include <asm/io.h>
  33. #include <mach_ipi.h>
  34. #include "mach_apic.h"
  35. #include <linux/init.h>
  36. #include <linux/smp.h>
  37. #include <linux/kernel_stat.h>
  38. #include <linux/interrupt.h>
  39. #include <linux/init.h>
  40. #include <asm/io.h>
  41. #include <asm/apic.h>
  42. #include <asm/i8259.h>
  43. #include <asm/irq_vectors.h>
  44. #include <asm/visws/cobalt.h>
  45. #include <asm/visws/lithium.h>
  46. #include <asm/visws/piix4.h>
  47. #include <linux/sched.h>
  48. #include <linux/kernel.h>
  49. #include <linux/init.h>
  50. #include <linux/pci.h>
  51. #include <linux/pci_ids.h>
  52. extern int no_broadcast;
  53. #include <asm/io.h>
  54. #include <asm/apic.h>
  55. #include <asm/arch_hooks.h>
  56. #include <asm/visws/cobalt.h>
  57. #include <asm/visws/lithium.h>
  58. char visws_board_type = -1;
  59. char visws_board_rev = -1;
  60. int is_visws_box(void)
  61. {
  62. return visws_board_type >= 0;
  63. }
  64. static int __init visws_time_init_quirk(void)
  65. {
  66. printk(KERN_INFO "Starting Cobalt Timer system clock\n");
  67. /* Set the countdown value */
  68. co_cpu_write(CO_CPU_TIMEVAL, CO_TIME_HZ/HZ);
  69. /* Start the timer */
  70. co_cpu_write(CO_CPU_CTRL, co_cpu_read(CO_CPU_CTRL) | CO_CTRL_TIMERUN);
  71. /* Enable (unmask) the timer interrupt */
  72. co_cpu_write(CO_CPU_CTRL, co_cpu_read(CO_CPU_CTRL) & ~CO_CTRL_TIMEMASK);
  73. /*
  74. * Zero return means the generic timer setup code will set up
  75. * the standard vector:
  76. */
  77. return 0;
  78. }
  79. static int __init visws_pre_intr_init_quirk(void)
  80. {
  81. init_VISWS_APIC_irqs();
  82. /*
  83. * We dont want ISA irqs to be set up by the generic code:
  84. */
  85. return 1;
  86. }
  87. /* Quirk for machine specific memory setup. */
  88. #define MB (1024 * 1024)
  89. unsigned long sgivwfb_mem_phys;
  90. unsigned long sgivwfb_mem_size;
  91. EXPORT_SYMBOL(sgivwfb_mem_phys);
  92. EXPORT_SYMBOL(sgivwfb_mem_size);
  93. long long mem_size __initdata = 0;
  94. static char * __init visws_memory_setup_quirk(void)
  95. {
  96. long long gfx_mem_size = 8 * MB;
  97. mem_size = boot_params.alt_mem_k;
  98. if (!mem_size) {
  99. printk(KERN_WARNING "Bootloader didn't set memory size, upgrade it !\n");
  100. mem_size = 128 * MB;
  101. }
  102. /*
  103. * this hardcodes the graphics memory to 8 MB
  104. * it really should be sized dynamically (or at least
  105. * set as a boot param)
  106. */
  107. if (!sgivwfb_mem_size) {
  108. printk(KERN_WARNING "Defaulting to 8 MB framebuffer size\n");
  109. sgivwfb_mem_size = 8 * MB;
  110. }
  111. /*
  112. * Trim to nearest MB
  113. */
  114. sgivwfb_mem_size &= ~((1 << 20) - 1);
  115. sgivwfb_mem_phys = mem_size - gfx_mem_size;
  116. e820_add_region(0, LOWMEMSIZE(), E820_RAM);
  117. e820_add_region(HIGH_MEMORY, mem_size - sgivwfb_mem_size - HIGH_MEMORY, E820_RAM);
  118. e820_add_region(sgivwfb_mem_phys, sgivwfb_mem_size, E820_RESERVED);
  119. return "PROM";
  120. }
  121. static void visws_machine_emergency_restart(void)
  122. {
  123. /*
  124. * Visual Workstations restart after this
  125. * register is poked on the PIIX4
  126. */
  127. outb(PIIX4_RESET_VAL, PIIX4_RESET_PORT);
  128. }
  129. static void visws_machine_power_off(void)
  130. {
  131. unsigned short pm_status;
  132. /* extern unsigned int pci_bus0; */
  133. while ((pm_status = inw(PMSTS_PORT)) & 0x100)
  134. outw(pm_status, PMSTS_PORT);
  135. outw(PM_SUSPEND_ENABLE, PMCNTRL_PORT);
  136. mdelay(10);
  137. #define PCI_CONF1_ADDRESS(bus, devfn, reg) \
  138. (0x80000000 | (bus << 16) | (devfn << 8) | (reg & ~3))
  139. /* outl(PCI_CONF1_ADDRESS(pci_bus0, SPECIAL_DEV, SPECIAL_REG), 0xCF8); */
  140. outl(PIIX_SPECIAL_STOP, 0xCFC);
  141. }
  142. static int __init visws_get_smp_config_quirk(unsigned int early)
  143. {
  144. /*
  145. * Prevent MP-table parsing by the generic code:
  146. */
  147. return 1;
  148. }
  149. extern unsigned int __cpuinitdata maxcpus;
  150. /*
  151. * The Visual Workstation is Intel MP compliant in the hardware
  152. * sense, but it doesn't have a BIOS(-configuration table).
  153. * No problem for Linux.
  154. */
  155. static void __init MP_processor_info (struct mpc_config_processor *m)
  156. {
  157. int ver, logical_apicid;
  158. physid_mask_t apic_cpus;
  159. if (!(m->mpc_cpuflag & CPU_ENABLED))
  160. return;
  161. logical_apicid = m->mpc_apicid;
  162. printk(KERN_INFO "%sCPU #%d %u:%u APIC version %d\n",
  163. m->mpc_cpuflag & CPU_BOOTPROCESSOR ? "Bootup " : "",
  164. m->mpc_apicid,
  165. (m->mpc_cpufeature & CPU_FAMILY_MASK) >> 8,
  166. (m->mpc_cpufeature & CPU_MODEL_MASK) >> 4,
  167. m->mpc_apicver);
  168. if (m->mpc_cpuflag & CPU_BOOTPROCESSOR)
  169. boot_cpu_physical_apicid = m->mpc_apicid;
  170. ver = m->mpc_apicver;
  171. if ((ver >= 0x14 && m->mpc_apicid >= 0xff) || m->mpc_apicid >= 0xf) {
  172. printk(KERN_ERR "Processor #%d INVALID. (Max ID: %d).\n",
  173. m->mpc_apicid, MAX_APICS);
  174. return;
  175. }
  176. apic_cpus = apicid_to_cpu_present(m->mpc_apicid);
  177. physids_or(phys_cpu_present_map, phys_cpu_present_map, apic_cpus);
  178. /*
  179. * Validate version
  180. */
  181. if (ver == 0x0) {
  182. printk(KERN_ERR "BIOS bug, APIC version is 0 for CPU#%d! "
  183. "fixing up to 0x10. (tell your hw vendor)\n",
  184. m->mpc_apicid);
  185. ver = 0x10;
  186. }
  187. apic_version[m->mpc_apicid] = ver;
  188. }
  189. int __init visws_find_smp_config_quirk(unsigned int reserve)
  190. {
  191. struct mpc_config_processor *mp = phys_to_virt(CO_CPU_TAB_PHYS);
  192. unsigned short ncpus = readw(phys_to_virt(CO_CPU_NUM_PHYS));
  193. if (ncpus > CO_CPU_MAX) {
  194. printk(KERN_WARNING "find_visws_smp: got cpu count of %d at %p\n",
  195. ncpus, mp);
  196. ncpus = CO_CPU_MAX;
  197. }
  198. if (ncpus > maxcpus)
  199. ncpus = maxcpus;
  200. #ifdef CONFIG_X86_LOCAL_APIC
  201. smp_found_config = 1;
  202. #endif
  203. while (ncpus--)
  204. MP_processor_info(mp++);
  205. mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
  206. return 1;
  207. }
  208. extern int visws_trap_init_quirk(void);
  209. void __init visws_early_detect(void)
  210. {
  211. int raw;
  212. visws_board_type = (char)(inb_p(PIIX_GPI_BD_REG) & PIIX_GPI_BD_REG)
  213. >> PIIX_GPI_BD_SHIFT;
  214. if (visws_board_type < 0)
  215. return;
  216. /*
  217. * Install special quirks for timer, interrupt and memory setup:
  218. */
  219. arch_time_init_quirk = visws_time_init_quirk;
  220. arch_pre_intr_init_quirk = visws_pre_intr_init_quirk;
  221. arch_memory_setup_quirk = visws_memory_setup_quirk;
  222. /*
  223. * Fall back to generic behavior for traps:
  224. */
  225. arch_intr_init_quirk = NULL;
  226. arch_trap_init_quirk = visws_trap_init_quirk;
  227. /*
  228. * Install reboot quirks:
  229. */
  230. pm_power_off = visws_machine_power_off;
  231. machine_ops.emergency_restart = visws_machine_emergency_restart;
  232. /*
  233. * Do not use broadcast IPIs:
  234. */
  235. no_broadcast = 0;
  236. /*
  237. * Override generic MP-table parsing:
  238. */
  239. mach_get_smp_config_quirk = visws_get_smp_config_quirk;
  240. mach_find_smp_config_quirk = visws_find_smp_config_quirk;
  241. #ifdef CONFIG_X86_IO_APIC
  242. /*
  243. * Turn off IO-APIC detection and initialization:
  244. */
  245. skip_ioapic_setup = 1;
  246. #endif
  247. /*
  248. * Get Board rev.
  249. * First, we have to initialize the 307 part to allow us access
  250. * to the GPIO registers. Let's map them at 0x0fc0 which is right
  251. * after the PIIX4 PM section.
  252. */
  253. outb_p(SIO_DEV_SEL, SIO_INDEX);
  254. outb_p(SIO_GP_DEV, SIO_DATA); /* Talk to GPIO regs. */
  255. outb_p(SIO_DEV_MSB, SIO_INDEX);
  256. outb_p(SIO_GP_MSB, SIO_DATA); /* MSB of GPIO base address */
  257. outb_p(SIO_DEV_LSB, SIO_INDEX);
  258. outb_p(SIO_GP_LSB, SIO_DATA); /* LSB of GPIO base address */
  259. outb_p(SIO_DEV_ENB, SIO_INDEX);
  260. outb_p(1, SIO_DATA); /* Enable GPIO registers. */
  261. /*
  262. * Now, we have to map the power management section to write
  263. * a bit which enables access to the GPIO registers.
  264. * What lunatic came up with this shit?
  265. */
  266. outb_p(SIO_DEV_SEL, SIO_INDEX);
  267. outb_p(SIO_PM_DEV, SIO_DATA); /* Talk to GPIO regs. */
  268. outb_p(SIO_DEV_MSB, SIO_INDEX);
  269. outb_p(SIO_PM_MSB, SIO_DATA); /* MSB of PM base address */
  270. outb_p(SIO_DEV_LSB, SIO_INDEX);
  271. outb_p(SIO_PM_LSB, SIO_DATA); /* LSB of PM base address */
  272. outb_p(SIO_DEV_ENB, SIO_INDEX);
  273. outb_p(1, SIO_DATA); /* Enable PM registers. */
  274. /*
  275. * Now, write the PM register which enables the GPIO registers.
  276. */
  277. outb_p(SIO_PM_FER2, SIO_PM_INDEX);
  278. outb_p(SIO_PM_GP_EN, SIO_PM_DATA);
  279. /*
  280. * Now, initialize the GPIO registers.
  281. * We want them all to be inputs which is the
  282. * power on default, so let's leave them alone.
  283. * So, let's just read the board rev!
  284. */
  285. raw = inb_p(SIO_GP_DATA1);
  286. raw &= 0x7f; /* 7 bits of valid board revision ID. */
  287. if (visws_board_type == VISWS_320) {
  288. if (raw < 0x6) {
  289. visws_board_rev = 4;
  290. } else if (raw < 0xc) {
  291. visws_board_rev = 5;
  292. } else {
  293. visws_board_rev = 6;
  294. }
  295. } else if (visws_board_type == VISWS_540) {
  296. visws_board_rev = 2;
  297. } else {
  298. visws_board_rev = raw;
  299. }
  300. printk(KERN_INFO "Silicon Graphics Visual Workstation %s (rev %d) detected\n",
  301. (visws_board_type == VISWS_320 ? "320" :
  302. (visws_board_type == VISWS_540 ? "540" :
  303. "unknown")), visws_board_rev);
  304. }
  305. #define A01234 (LI_INTA_0 | LI_INTA_1 | LI_INTA_2 | LI_INTA_3 | LI_INTA_4)
  306. #define BCD (LI_INTB | LI_INTC | LI_INTD)
  307. #define ALLDEVS (A01234 | BCD)
  308. static __init void lithium_init(void)
  309. {
  310. set_fixmap(FIX_LI_PCIA, LI_PCI_A_PHYS);
  311. set_fixmap(FIX_LI_PCIB, LI_PCI_B_PHYS);
  312. if ((li_pcia_read16(PCI_VENDOR_ID) != PCI_VENDOR_ID_SGI) ||
  313. (li_pcia_read16(PCI_DEVICE_ID) != PCI_DEVICE_ID_SGI_LITHIUM)) {
  314. printk(KERN_EMERG "Lithium hostbridge %c not found\n", 'A');
  315. /* panic("This machine is not SGI Visual Workstation 320/540"); */
  316. }
  317. if ((li_pcib_read16(PCI_VENDOR_ID) != PCI_VENDOR_ID_SGI) ||
  318. (li_pcib_read16(PCI_DEVICE_ID) != PCI_DEVICE_ID_SGI_LITHIUM)) {
  319. printk(KERN_EMERG "Lithium hostbridge %c not found\n", 'B');
  320. /* panic("This machine is not SGI Visual Workstation 320/540"); */
  321. }
  322. li_pcia_write16(LI_PCI_INTEN, ALLDEVS);
  323. li_pcib_write16(LI_PCI_INTEN, ALLDEVS);
  324. }
  325. static __init void cobalt_init(void)
  326. {
  327. /*
  328. * On normal SMP PC this is used only with SMP, but we have to
  329. * use it and set it up here to start the Cobalt clock
  330. */
  331. set_fixmap(FIX_APIC_BASE, APIC_DEFAULT_PHYS_BASE);
  332. setup_local_APIC();
  333. printk(KERN_INFO "Local APIC Version %#x, ID %#x\n",
  334. (unsigned int)apic_read(APIC_LVR),
  335. (unsigned int)apic_read(APIC_ID));
  336. set_fixmap(FIX_CO_CPU, CO_CPU_PHYS);
  337. set_fixmap(FIX_CO_APIC, CO_APIC_PHYS);
  338. printk(KERN_INFO "Cobalt Revision %#lx, APIC ID %#lx\n",
  339. co_cpu_read(CO_CPU_REV), co_apic_read(CO_APIC_ID));
  340. /* Enable Cobalt APIC being careful to NOT change the ID! */
  341. co_apic_write(CO_APIC_ID, co_apic_read(CO_APIC_ID) | CO_APIC_ENABLE);
  342. printk(KERN_INFO "Cobalt APIC enabled: ID reg %#lx\n",
  343. co_apic_read(CO_APIC_ID));
  344. }
  345. int __init visws_trap_init_quirk(void)
  346. {
  347. lithium_init();
  348. cobalt_init();
  349. return 1;
  350. }
  351. /*
  352. * IRQ controller / APIC support:
  353. */
  354. static DEFINE_SPINLOCK(cobalt_lock);
  355. /*
  356. * Set the given Cobalt APIC Redirection Table entry to point
  357. * to the given IDT vector/index.
  358. */
  359. static inline void co_apic_set(int entry, int irq)
  360. {
  361. co_apic_write(CO_APIC_LO(entry), CO_APIC_LEVEL | (irq + FIRST_EXTERNAL_VECTOR));
  362. co_apic_write(CO_APIC_HI(entry), 0);
  363. }
  364. /*
  365. * Cobalt (IO)-APIC functions to handle PCI devices.
  366. */
  367. static inline int co_apic_ide0_hack(void)
  368. {
  369. extern char visws_board_type;
  370. extern char visws_board_rev;
  371. if (visws_board_type == VISWS_320 && visws_board_rev == 5)
  372. return 5;
  373. return CO_APIC_IDE0;
  374. }
  375. static int is_co_apic(unsigned int irq)
  376. {
  377. if (IS_CO_APIC(irq))
  378. return CO_APIC(irq);
  379. switch (irq) {
  380. case 0: return CO_APIC_CPU;
  381. case CO_IRQ_IDE0: return co_apic_ide0_hack();
  382. case CO_IRQ_IDE1: return CO_APIC_IDE1;
  383. default: return -1;
  384. }
  385. }
  386. /*
  387. * This is the SGI Cobalt (IO-)APIC:
  388. */
  389. static void enable_cobalt_irq(unsigned int irq)
  390. {
  391. co_apic_set(is_co_apic(irq), irq);
  392. }
  393. static void disable_cobalt_irq(unsigned int irq)
  394. {
  395. int entry = is_co_apic(irq);
  396. co_apic_write(CO_APIC_LO(entry), CO_APIC_MASK);
  397. co_apic_read(CO_APIC_LO(entry));
  398. }
  399. /*
  400. * "irq" really just serves to identify the device. Here is where we
  401. * map this to the Cobalt APIC entry where it's physically wired.
  402. * This is called via request_irq -> setup_irq -> irq_desc->startup()
  403. */
  404. static unsigned int startup_cobalt_irq(unsigned int irq)
  405. {
  406. unsigned long flags;
  407. spin_lock_irqsave(&cobalt_lock, flags);
  408. if ((irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS | IRQ_WAITING)))
  409. irq_desc[irq].status &= ~(IRQ_DISABLED | IRQ_INPROGRESS | IRQ_WAITING);
  410. enable_cobalt_irq(irq);
  411. spin_unlock_irqrestore(&cobalt_lock, flags);
  412. return 0;
  413. }
  414. static void ack_cobalt_irq(unsigned int irq)
  415. {
  416. unsigned long flags;
  417. spin_lock_irqsave(&cobalt_lock, flags);
  418. disable_cobalt_irq(irq);
  419. apic_write(APIC_EOI, APIC_EIO_ACK);
  420. spin_unlock_irqrestore(&cobalt_lock, flags);
  421. }
  422. static void end_cobalt_irq(unsigned int irq)
  423. {
  424. unsigned long flags;
  425. spin_lock_irqsave(&cobalt_lock, flags);
  426. if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS)))
  427. enable_cobalt_irq(irq);
  428. spin_unlock_irqrestore(&cobalt_lock, flags);
  429. }
  430. static struct irq_chip cobalt_irq_type = {
  431. .typename = "Cobalt-APIC",
  432. .startup = startup_cobalt_irq,
  433. .shutdown = disable_cobalt_irq,
  434. .enable = enable_cobalt_irq,
  435. .disable = disable_cobalt_irq,
  436. .ack = ack_cobalt_irq,
  437. .end = end_cobalt_irq,
  438. };
  439. /*
  440. * This is the PIIX4-based 8259 that is wired up indirectly to Cobalt
  441. * -- not the manner expected by the code in i8259.c.
  442. *
  443. * there is a 'master' physical interrupt source that gets sent to
  444. * the CPU. But in the chipset there are various 'virtual' interrupts
  445. * waiting to be handled. We represent this to Linux through a 'master'
  446. * interrupt controller type, and through a special virtual interrupt-
  447. * controller. Device drivers only see the virtual interrupt sources.
  448. */
  449. static unsigned int startup_piix4_master_irq(unsigned int irq)
  450. {
  451. init_8259A(0);
  452. return startup_cobalt_irq(irq);
  453. }
  454. static void end_piix4_master_irq(unsigned int irq)
  455. {
  456. unsigned long flags;
  457. spin_lock_irqsave(&cobalt_lock, flags);
  458. enable_cobalt_irq(irq);
  459. spin_unlock_irqrestore(&cobalt_lock, flags);
  460. }
  461. static struct irq_chip piix4_master_irq_type = {
  462. .typename = "PIIX4-master",
  463. .startup = startup_piix4_master_irq,
  464. .ack = ack_cobalt_irq,
  465. .end = end_piix4_master_irq,
  466. };
  467. static struct irq_chip piix4_virtual_irq_type = {
  468. .typename = "PIIX4-virtual",
  469. .shutdown = disable_8259A_irq,
  470. .enable = enable_8259A_irq,
  471. .disable = disable_8259A_irq,
  472. };
  473. /*
  474. * PIIX4-8259 master/virtual functions to handle interrupt requests
  475. * from legacy devices: floppy, parallel, serial, rtc.
  476. *
  477. * None of these get Cobalt APIC entries, neither do they have IDT
  478. * entries. These interrupts are purely virtual and distributed from
  479. * the 'master' interrupt source: CO_IRQ_8259.
  480. *
  481. * When the 8259 interrupts its handler figures out which of these
  482. * devices is interrupting and dispatches to its handler.
  483. *
  484. * CAREFUL: devices see the 'virtual' interrupt only. Thus disable/
  485. * enable_irq gets the right irq. This 'master' irq is never directly
  486. * manipulated by any driver.
  487. */
  488. static irqreturn_t piix4_master_intr(int irq, void *dev_id)
  489. {
  490. int realirq;
  491. irq_desc_t *desc;
  492. unsigned long flags;
  493. spin_lock_irqsave(&i8259A_lock, flags);
  494. /* Find out what's interrupting in the PIIX4 master 8259 */
  495. outb(0x0c, 0x20); /* OCW3 Poll command */
  496. realirq = inb(0x20);
  497. /*
  498. * Bit 7 == 0 means invalid/spurious
  499. */
  500. if (unlikely(!(realirq & 0x80)))
  501. goto out_unlock;
  502. realirq &= 7;
  503. if (unlikely(realirq == 2)) {
  504. outb(0x0c, 0xa0);
  505. realirq = inb(0xa0);
  506. if (unlikely(!(realirq & 0x80)))
  507. goto out_unlock;
  508. realirq = (realirq & 7) + 8;
  509. }
  510. /* mask and ack interrupt */
  511. cached_irq_mask |= 1 << realirq;
  512. if (unlikely(realirq > 7)) {
  513. inb(0xa1);
  514. outb(cached_slave_mask, 0xa1);
  515. outb(0x60 + (realirq & 7), 0xa0);
  516. outb(0x60 + 2, 0x20);
  517. } else {
  518. inb(0x21);
  519. outb(cached_master_mask, 0x21);
  520. outb(0x60 + realirq, 0x20);
  521. }
  522. spin_unlock_irqrestore(&i8259A_lock, flags);
  523. desc = irq_desc + realirq;
  524. /*
  525. * handle this 'virtual interrupt' as a Cobalt one now.
  526. */
  527. kstat_cpu(smp_processor_id()).irqs[realirq]++;
  528. if (likely(desc->action != NULL))
  529. handle_IRQ_event(realirq, desc->action);
  530. if (!(desc->status & IRQ_DISABLED))
  531. enable_8259A_irq(realirq);
  532. return IRQ_HANDLED;
  533. out_unlock:
  534. spin_unlock_irqrestore(&i8259A_lock, flags);
  535. return IRQ_NONE;
  536. }
  537. static struct irqaction master_action = {
  538. .handler = piix4_master_intr,
  539. .name = "PIIX4-8259",
  540. };
  541. static struct irqaction cascade_action = {
  542. .handler = no_action,
  543. .name = "cascade",
  544. };
  545. void init_VISWS_APIC_irqs(void)
  546. {
  547. int i;
  548. for (i = 0; i < CO_IRQ_APIC0 + CO_APIC_LAST + 1; i++) {
  549. irq_desc[i].status = IRQ_DISABLED;
  550. irq_desc[i].action = 0;
  551. irq_desc[i].depth = 1;
  552. if (i == 0) {
  553. irq_desc[i].chip = &cobalt_irq_type;
  554. }
  555. else if (i == CO_IRQ_IDE0) {
  556. irq_desc[i].chip = &cobalt_irq_type;
  557. }
  558. else if (i == CO_IRQ_IDE1) {
  559. irq_desc[i].chip = &cobalt_irq_type;
  560. }
  561. else if (i == CO_IRQ_8259) {
  562. irq_desc[i].chip = &piix4_master_irq_type;
  563. }
  564. else if (i < CO_IRQ_APIC0) {
  565. irq_desc[i].chip = &piix4_virtual_irq_type;
  566. }
  567. else if (IS_CO_APIC(i)) {
  568. irq_desc[i].chip = &cobalt_irq_type;
  569. }
  570. }
  571. setup_irq(CO_IRQ_8259, &master_action);
  572. setup_irq(2, &cascade_action);
  573. }