visws_quirks.c 15 KB

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