mpparse_64.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824
  1. /*
  2. * Intel Multiprocessor Specification 1.1 and 1.4
  3. * compliant MP-table parsing routines.
  4. *
  5. * (c) 1995 Alan Cox, Building #3 <alan@redhat.com>
  6. * (c) 1998, 1999, 2000 Ingo Molnar <mingo@redhat.com>
  7. *
  8. * Fixes
  9. * Erich Boleyn : MP v1.4 and additional changes.
  10. * Alan Cox : Added EBDA scanning
  11. * Ingo Molnar : various cleanups and rewrites
  12. * Maciej W. Rozycki: Bits for default MP configurations
  13. * Paul Diefenbaugh: Added full ACPI support
  14. */
  15. #include <linux/mm.h>
  16. #include <linux/init.h>
  17. #include <linux/delay.h>
  18. #include <linux/bootmem.h>
  19. #include <linux/kernel_stat.h>
  20. #include <linux/mc146818rtc.h>
  21. #include <linux/acpi.h>
  22. #include <linux/module.h>
  23. #include <asm/smp.h>
  24. #include <asm/mtrr.h>
  25. #include <asm/mpspec.h>
  26. #include <asm/pgalloc.h>
  27. #include <asm/io_apic.h>
  28. #include <asm/proto.h>
  29. #include <asm/acpi.h>
  30. #include <asm/bios_ebda.h>
  31. #include <mach_apic.h>
  32. /* Have we found an MP table */
  33. int smp_found_config;
  34. /*
  35. * Various Linux-internal data structures created from the
  36. * MP-table.
  37. */
  38. DECLARE_BITMAP(mp_bus_not_pci, MAX_MP_BUSSES);
  39. int mp_bus_id_to_pci_bus[MAX_MP_BUSSES] = {[0 ... MAX_MP_BUSSES - 1] = -1 };
  40. static int mp_current_pci_id = 0;
  41. /*
  42. * Intel MP BIOS table parsing routines:
  43. */
  44. /*
  45. * Checksum an MP configuration block.
  46. */
  47. static int __init mpf_checksum(unsigned char *mp, int len)
  48. {
  49. int sum = 0;
  50. while (len--)
  51. sum += *mp++;
  52. return sum & 0xFF;
  53. }
  54. static void __cpuinit MP_processor_info(struct mpc_config_processor *m)
  55. {
  56. int apicid;
  57. char *bootup_cpu = "";
  58. if (!(m->mpc_cpuflag & CPU_ENABLED)) {
  59. disabled_cpus++;
  60. return;
  61. }
  62. #ifdef CONFIG_X86_NUMAQ
  63. apicid = mpc_apic_id(m, translation_table[mpc_record]);
  64. #else
  65. apicid = m->mpc_apicid;
  66. #endif
  67. if (m->mpc_cpuflag & CPU_BOOTPROCESSOR) {
  68. bootup_cpu = " (Bootup-CPU)";
  69. boot_cpu_physical_apicid = m->mpc_apicid;
  70. }
  71. printk(KERN_INFO "Processor #%d%s\n", m->mpc_apicid, bootup_cpu);
  72. generic_processor_info(apicid, m->mpc_apicver);
  73. }
  74. static void __init MP_bus_info(struct mpc_config_bus *m)
  75. {
  76. char str[7];
  77. memcpy(str, m->mpc_bustype, 6);
  78. str[6] = 0;
  79. Dprintk("Bus #%d is %s\n", m->mpc_busid, str);
  80. if (strncmp(str, "ISA", 3) == 0) {
  81. set_bit(m->mpc_busid, mp_bus_not_pci);
  82. } else if (strncmp(str, "PCI", 3) == 0) {
  83. clear_bit(m->mpc_busid, mp_bus_not_pci);
  84. mp_bus_id_to_pci_bus[m->mpc_busid] = mp_current_pci_id;
  85. mp_current_pci_id++;
  86. } else {
  87. printk(KERN_ERR "Unknown bustype %s\n", str);
  88. }
  89. }
  90. static int bad_ioapic(unsigned long address)
  91. {
  92. if (nr_ioapics >= MAX_IO_APICS) {
  93. printk(KERN_ERR "ERROR: Max # of I/O APICs (%d) exceeded "
  94. "(found %d)\n", MAX_IO_APICS, nr_ioapics);
  95. panic("Recompile kernel with bigger MAX_IO_APICS!\n");
  96. }
  97. if (!address) {
  98. printk(KERN_ERR "WARNING: Bogus (zero) I/O APIC address"
  99. " found in table, skipping!\n");
  100. return 1;
  101. }
  102. return 0;
  103. }
  104. static void __init MP_ioapic_info(struct mpc_config_ioapic *m)
  105. {
  106. if (!(m->mpc_flags & MPC_APIC_USABLE))
  107. return;
  108. printk(KERN_INFO "I/O APIC #%d at 0x%X.\n", m->mpc_apicid,
  109. m->mpc_apicaddr);
  110. if (bad_ioapic(m->mpc_apicaddr))
  111. return;
  112. mp_ioapics[nr_ioapics] = *m;
  113. nr_ioapics++;
  114. }
  115. static void __init MP_intsrc_info(struct mpc_config_intsrc *m)
  116. {
  117. mp_irqs[mp_irq_entries] = *m;
  118. Dprintk("Int: type %d, pol %d, trig %d, bus %d,"
  119. " IRQ %02x, APIC ID %x, APIC INT %02x\n",
  120. m->mpc_irqtype, m->mpc_irqflag & 3,
  121. (m->mpc_irqflag >> 2) & 3, m->mpc_srcbus,
  122. m->mpc_srcbusirq, m->mpc_dstapic, m->mpc_dstirq);
  123. if (++mp_irq_entries >= MAX_IRQ_SOURCES)
  124. panic("Max # of irq sources exceeded!!\n");
  125. }
  126. static void __init MP_lintsrc_info(struct mpc_config_lintsrc *m)
  127. {
  128. Dprintk("Lint: type %d, pol %d, trig %d, bus %d,"
  129. " IRQ %02x, APIC ID %x, APIC LINT %02x\n",
  130. m->mpc_irqtype, m->mpc_irqflag & 3,
  131. (m->mpc_irqflag >> 2) & 3, m->mpc_srcbusid,
  132. m->mpc_srcbusirq, m->mpc_destapic, m->mpc_destapiclint);
  133. }
  134. /*
  135. * Read/parse the MPC
  136. */
  137. static int __init smp_read_mpc(struct mp_config_table *mpc, unsigned early)
  138. {
  139. char str[16];
  140. int count = sizeof(*mpc);
  141. unsigned char *mpt = ((unsigned char *)mpc) + count;
  142. if (memcmp(mpc->mpc_signature, MPC_SIGNATURE, 4)) {
  143. printk(KERN_ERR "MPTABLE: bad signature [%c%c%c%c]!\n",
  144. mpc->mpc_signature[0],
  145. mpc->mpc_signature[1],
  146. mpc->mpc_signature[2], mpc->mpc_signature[3]);
  147. return 0;
  148. }
  149. if (mpf_checksum((unsigned char *)mpc, mpc->mpc_length)) {
  150. printk(KERN_ERR "MPTABLE: checksum error!\n");
  151. return 0;
  152. }
  153. if (mpc->mpc_spec != 0x01 && mpc->mpc_spec != 0x04) {
  154. printk(KERN_ERR "MPTABLE: bad table version (%d)!!\n",
  155. mpc->mpc_spec);
  156. return 0;
  157. }
  158. if (!mpc->mpc_lapic) {
  159. printk(KERN_ERR "MPTABLE: null local APIC address!\n");
  160. return 0;
  161. }
  162. memcpy(str, mpc->mpc_oem, 8);
  163. str[8] = 0;
  164. printk(KERN_INFO "MPTABLE: OEM ID: %s ", str);
  165. memcpy(str, mpc->mpc_productid, 12);
  166. str[12] = 0;
  167. printk(KERN_INFO "MPTABLE: Product ID: %s ", str);
  168. printk(KERN_INFO "MPTABLE: APIC at: 0x%X\n", mpc->mpc_lapic);
  169. /* save the local APIC address, it might be non-default */
  170. if (!acpi_lapic)
  171. mp_lapic_addr = mpc->mpc_lapic;
  172. if (early)
  173. return 1;
  174. /*
  175. * Now process the configuration blocks.
  176. */
  177. while (count < mpc->mpc_length) {
  178. switch (*mpt) {
  179. case MP_PROCESSOR:
  180. {
  181. struct mpc_config_processor *m =
  182. (struct mpc_config_processor *)mpt;
  183. if (!acpi_lapic)
  184. MP_processor_info(m);
  185. mpt += sizeof(*m);
  186. count += sizeof(*m);
  187. break;
  188. }
  189. case MP_BUS:
  190. {
  191. struct mpc_config_bus *m =
  192. (struct mpc_config_bus *)mpt;
  193. MP_bus_info(m);
  194. mpt += sizeof(*m);
  195. count += sizeof(*m);
  196. break;
  197. }
  198. case MP_IOAPIC:
  199. {
  200. struct mpc_config_ioapic *m =
  201. (struct mpc_config_ioapic *)mpt;
  202. MP_ioapic_info(m);
  203. mpt += sizeof(*m);
  204. count += sizeof(*m);
  205. break;
  206. }
  207. case MP_INTSRC:
  208. {
  209. struct mpc_config_intsrc *m =
  210. (struct mpc_config_intsrc *)mpt;
  211. MP_intsrc_info(m);
  212. mpt += sizeof(*m);
  213. count += sizeof(*m);
  214. break;
  215. }
  216. case MP_LINTSRC:
  217. {
  218. struct mpc_config_lintsrc *m =
  219. (struct mpc_config_lintsrc *)mpt;
  220. MP_lintsrc_info(m);
  221. mpt += sizeof(*m);
  222. count += sizeof(*m);
  223. break;
  224. }
  225. }
  226. }
  227. setup_apic_routing();
  228. if (!num_processors)
  229. printk(KERN_ERR "MPTABLE: no processors registered!\n");
  230. return num_processors;
  231. }
  232. static int __init ELCR_trigger(unsigned int irq)
  233. {
  234. unsigned int port;
  235. port = 0x4d0 + (irq >> 3);
  236. return (inb(port) >> (irq & 7)) & 1;
  237. }
  238. static void __init construct_default_ioirq_mptable(int mpc_default_type)
  239. {
  240. struct mpc_config_intsrc intsrc;
  241. int i;
  242. int ELCR_fallback = 0;
  243. intsrc.mpc_type = MP_INTSRC;
  244. intsrc.mpc_irqflag = 0; /* conforming */
  245. intsrc.mpc_srcbus = 0;
  246. intsrc.mpc_dstapic = mp_ioapics[0].mpc_apicid;
  247. intsrc.mpc_irqtype = mp_INT;
  248. /*
  249. * If true, we have an ISA/PCI system with no IRQ entries
  250. * in the MP table. To prevent the PCI interrupts from being set up
  251. * incorrectly, we try to use the ELCR. The sanity check to see if
  252. * there is good ELCR data is very simple - IRQ0, 1, 2 and 13 can
  253. * never be level sensitive, so we simply see if the ELCR agrees.
  254. * If it does, we assume it's valid.
  255. */
  256. if (mpc_default_type == 5) {
  257. printk(KERN_INFO "ISA/PCI bus type with no IRQ information... "
  258. "falling back to ELCR\n");
  259. if (ELCR_trigger(0) || ELCR_trigger(1) || ELCR_trigger(2) ||
  260. ELCR_trigger(13))
  261. printk(KERN_ERR "ELCR contains invalid data... "
  262. "not using ELCR\n");
  263. else {
  264. printk(KERN_INFO
  265. "Using ELCR to identify PCI interrupts\n");
  266. ELCR_fallback = 1;
  267. }
  268. }
  269. for (i = 0; i < 16; i++) {
  270. switch (mpc_default_type) {
  271. case 2:
  272. if (i == 0 || i == 13)
  273. continue; /* IRQ0 & IRQ13 not connected */
  274. /* fall through */
  275. default:
  276. if (i == 2)
  277. continue; /* IRQ2 is never connected */
  278. }
  279. if (ELCR_fallback) {
  280. /*
  281. * If the ELCR indicates a level-sensitive interrupt, we
  282. * copy that information over to the MP table in the
  283. * irqflag field (level sensitive, active high polarity).
  284. */
  285. if (ELCR_trigger(i))
  286. intsrc.mpc_irqflag = 13;
  287. else
  288. intsrc.mpc_irqflag = 0;
  289. }
  290. intsrc.mpc_srcbusirq = i;
  291. intsrc.mpc_dstirq = i ? i : 2; /* IRQ0 to INTIN2 */
  292. MP_intsrc_info(&intsrc);
  293. }
  294. intsrc.mpc_irqtype = mp_ExtINT;
  295. intsrc.mpc_srcbusirq = 0;
  296. intsrc.mpc_dstirq = 0; /* 8259A to INTIN0 */
  297. MP_intsrc_info(&intsrc);
  298. }
  299. static inline void __init construct_default_ISA_mptable(int mpc_default_type)
  300. {
  301. struct mpc_config_processor processor;
  302. struct mpc_config_bus bus;
  303. struct mpc_config_ioapic ioapic;
  304. struct mpc_config_lintsrc lintsrc;
  305. int linttypes[2] = { mp_ExtINT, mp_NMI };
  306. int i;
  307. /*
  308. * local APIC has default address
  309. */
  310. mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
  311. /*
  312. * 2 CPUs, numbered 0 & 1.
  313. */
  314. processor.mpc_type = MP_PROCESSOR;
  315. processor.mpc_apicver = 0;
  316. processor.mpc_cpuflag = CPU_ENABLED;
  317. processor.mpc_cpufeature = 0;
  318. processor.mpc_featureflag = 0;
  319. processor.mpc_reserved[0] = 0;
  320. processor.mpc_reserved[1] = 0;
  321. for (i = 0; i < 2; i++) {
  322. processor.mpc_apicid = i;
  323. MP_processor_info(&processor);
  324. }
  325. bus.mpc_type = MP_BUS;
  326. bus.mpc_busid = 0;
  327. switch (mpc_default_type) {
  328. default:
  329. printk(KERN_ERR "???\nUnknown standard configuration %d\n",
  330. mpc_default_type);
  331. /* fall through */
  332. case 1:
  333. case 5:
  334. memcpy(bus.mpc_bustype, "ISA ", 6);
  335. break;
  336. }
  337. MP_bus_info(&bus);
  338. if (mpc_default_type > 4) {
  339. bus.mpc_busid = 1;
  340. memcpy(bus.mpc_bustype, "PCI ", 6);
  341. MP_bus_info(&bus);
  342. }
  343. ioapic.mpc_type = MP_IOAPIC;
  344. ioapic.mpc_apicid = 2;
  345. ioapic.mpc_apicver = 0;
  346. ioapic.mpc_flags = MPC_APIC_USABLE;
  347. ioapic.mpc_apicaddr = 0xFEC00000;
  348. MP_ioapic_info(&ioapic);
  349. /*
  350. * We set up most of the low 16 IO-APIC pins according to MPS rules.
  351. */
  352. construct_default_ioirq_mptable(mpc_default_type);
  353. lintsrc.mpc_type = MP_LINTSRC;
  354. lintsrc.mpc_irqflag = 0; /* conforming */
  355. lintsrc.mpc_srcbusid = 0;
  356. lintsrc.mpc_srcbusirq = 0;
  357. lintsrc.mpc_destapic = MP_APIC_ALL;
  358. for (i = 0; i < 2; i++) {
  359. lintsrc.mpc_irqtype = linttypes[i];
  360. lintsrc.mpc_destapiclint = i;
  361. MP_lintsrc_info(&lintsrc);
  362. }
  363. }
  364. static struct intel_mp_floating *mpf_found;
  365. /*
  366. * Scan the memory blocks for an SMP configuration block.
  367. */
  368. static void __init __get_smp_config(unsigned early)
  369. {
  370. struct intel_mp_floating *mpf = mpf_found;
  371. if (acpi_lapic && early)
  372. return;
  373. /*
  374. * ACPI supports both logical (e.g. Hyper-Threading) and physical
  375. * processors, where MPS only supports physical.
  376. */
  377. if (acpi_lapic && acpi_ioapic) {
  378. printk(KERN_INFO "Using ACPI (MADT) for SMP configuration "
  379. "information\n");
  380. return;
  381. } else if (acpi_lapic)
  382. printk(KERN_INFO "Using ACPI for processor (LAPIC) "
  383. "configuration information\n");
  384. printk(KERN_INFO "Intel MultiProcessor Specification v1.%d\n",
  385. mpf->mpf_specification);
  386. /*
  387. * Now see if we need to read further.
  388. */
  389. if (mpf->mpf_feature1 != 0) {
  390. if (early) {
  391. /*
  392. * local APIC has default address
  393. */
  394. mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
  395. return;
  396. }
  397. printk(KERN_INFO "Default MP configuration #%d\n",
  398. mpf->mpf_feature1);
  399. construct_default_ISA_mptable(mpf->mpf_feature1);
  400. } else if (mpf->mpf_physptr) {
  401. /*
  402. * Read the physical hardware table. Anything here will
  403. * override the defaults.
  404. */
  405. if (!smp_read_mpc(phys_to_virt(mpf->mpf_physptr), early)) {
  406. smp_found_config = 0;
  407. printk(KERN_ERR
  408. "BIOS bug, MP table errors detected!...\n");
  409. printk(KERN_ERR "... disabling SMP support. "
  410. "(tell your hw vendor)\n");
  411. return;
  412. }
  413. if (early)
  414. return;
  415. /*
  416. * If there are no explicit MP IRQ entries, then we are
  417. * broken. We set up most of the low 16 IO-APIC pins to
  418. * ISA defaults and hope it will work.
  419. */
  420. if (!mp_irq_entries) {
  421. struct mpc_config_bus bus;
  422. printk(KERN_ERR "BIOS bug, no explicit IRQ entries, "
  423. "using default mptable. "
  424. "(tell your hw vendor)\n");
  425. bus.mpc_type = MP_BUS;
  426. bus.mpc_busid = 0;
  427. memcpy(bus.mpc_bustype, "ISA ", 6);
  428. MP_bus_info(&bus);
  429. construct_default_ioirq_mptable(0);
  430. }
  431. } else
  432. BUG();
  433. if (!early)
  434. printk(KERN_INFO "Processors: %d\n", num_processors);
  435. /*
  436. * Only use the first configuration found.
  437. */
  438. }
  439. void __init early_get_smp_config(void)
  440. {
  441. __get_smp_config(1);
  442. }
  443. void __init get_smp_config(void)
  444. {
  445. __get_smp_config(0);
  446. }
  447. static int __init smp_scan_config(unsigned long base, unsigned long length,
  448. unsigned reserve)
  449. {
  450. extern void __bad_mpf_size(void);
  451. unsigned int *bp = phys_to_virt(base);
  452. struct intel_mp_floating *mpf;
  453. Dprintk("Scan SMP from %p for %ld bytes.\n", bp, length);
  454. if (sizeof(*mpf) != 16)
  455. __bad_mpf_size();
  456. while (length > 0) {
  457. mpf = (struct intel_mp_floating *)bp;
  458. if ((*bp == SMP_MAGIC_IDENT) &&
  459. (mpf->mpf_length == 1) &&
  460. !mpf_checksum((unsigned char *)bp, 16) &&
  461. ((mpf->mpf_specification == 1)
  462. || (mpf->mpf_specification == 4))) {
  463. smp_found_config = 1;
  464. mpf_found = mpf;
  465. if (!reserve)
  466. return 1;
  467. reserve_bootmem_generic(virt_to_phys(mpf), PAGE_SIZE);
  468. if (mpf->mpf_physptr)
  469. reserve_bootmem_generic(mpf->mpf_physptr,
  470. PAGE_SIZE);
  471. return 1;
  472. }
  473. bp += 4;
  474. length -= 16;
  475. }
  476. return 0;
  477. }
  478. static void __init __find_smp_config(unsigned reserve)
  479. {
  480. unsigned int address;
  481. /*
  482. * FIXME: Linux assumes you have 640K of base ram..
  483. * this continues the error...
  484. *
  485. * 1) Scan the bottom 1K for a signature
  486. * 2) Scan the top 1K of base RAM
  487. * 3) Scan the 64K of bios
  488. */
  489. if (smp_scan_config(0x0, 0x400, reserve) ||
  490. smp_scan_config(639 * 0x400, 0x400, reserve) ||
  491. smp_scan_config(0xF0000, 0x10000, reserve))
  492. return;
  493. /*
  494. * If it is an SMP machine we should know now.
  495. *
  496. * there is a real-mode segmented pointer pointing to the
  497. * 4K EBDA area at 0x40E, calculate and scan it here.
  498. *
  499. * NOTE! There are Linux loaders that will corrupt the EBDA
  500. * area, and as such this kind of SMP config may be less
  501. * trustworthy, simply because the SMP table may have been
  502. * stomped on during early boot. These loaders are buggy and
  503. * should be fixed.
  504. *
  505. * MP1.4 SPEC states to only scan first 1K of 4K EBDA.
  506. */
  507. address = get_bios_ebda();
  508. if (address)
  509. smp_scan_config(address, 0x400, reserve);
  510. }
  511. void __init early_find_smp_config(void)
  512. {
  513. __find_smp_config(0);
  514. }
  515. void __init find_smp_config(void)
  516. {
  517. __find_smp_config(1);
  518. }
  519. /* --------------------------------------------------------------------------
  520. ACPI-based MP Configuration
  521. -------------------------------------------------------------------------- */
  522. #ifdef CONFIG_ACPI
  523. #define MP_ISA_BUS 0
  524. #define MP_MAX_IOAPIC_PIN 127
  525. extern struct mp_ioapic_routing mp_ioapic_routing[MAX_IO_APICS];
  526. static int mp_find_ioapic(int gsi)
  527. {
  528. int i = 0;
  529. /* Find the IOAPIC that manages this GSI. */
  530. for (i = 0; i < nr_ioapics; i++) {
  531. if ((gsi >= mp_ioapic_routing[i].gsi_base)
  532. && (gsi <= mp_ioapic_routing[i].gsi_end))
  533. return i;
  534. }
  535. printk(KERN_ERR "ERROR: Unable to locate IOAPIC for GSI %d\n", gsi);
  536. return -1;
  537. }
  538. static u8 uniq_ioapic_id(u8 id)
  539. {
  540. int i;
  541. DECLARE_BITMAP(used, 256);
  542. bitmap_zero(used, 256);
  543. for (i = 0; i < nr_ioapics; i++) {
  544. struct mpc_config_ioapic *ia = &mp_ioapics[i];
  545. __set_bit(ia->mpc_apicid, used);
  546. }
  547. if (!test_bit(id, used))
  548. return id;
  549. return find_first_zero_bit(used, 256);
  550. }
  551. void __init mp_register_ioapic(int id, u32 address, u32 gsi_base)
  552. {
  553. int idx = 0;
  554. if (bad_ioapic(address))
  555. return;
  556. idx = nr_ioapics;
  557. mp_ioapics[idx].mpc_type = MP_IOAPIC;
  558. mp_ioapics[idx].mpc_flags = MPC_APIC_USABLE;
  559. mp_ioapics[idx].mpc_apicaddr = address;
  560. set_fixmap_nocache(FIX_IO_APIC_BASE_0 + idx, address);
  561. mp_ioapics[idx].mpc_apicid = uniq_ioapic_id(id);
  562. mp_ioapics[idx].mpc_apicver = 0;
  563. /*
  564. * Build basic IRQ lookup table to facilitate gsi->io_apic lookups
  565. * and to prevent reprogramming of IOAPIC pins (PCI IRQs).
  566. */
  567. mp_ioapic_routing[idx].apic_id = mp_ioapics[idx].mpc_apicid;
  568. mp_ioapic_routing[idx].gsi_base = gsi_base;
  569. mp_ioapic_routing[idx].gsi_end = gsi_base +
  570. io_apic_get_redir_entries(idx);
  571. printk(KERN_INFO "IOAPIC[%d]: apic_id %d, address 0x%x, "
  572. "GSI %d-%d\n", idx, mp_ioapics[idx].mpc_apicid,
  573. mp_ioapics[idx].mpc_apicaddr,
  574. mp_ioapic_routing[idx].gsi_base,
  575. mp_ioapic_routing[idx].gsi_end);
  576. nr_ioapics++;
  577. }
  578. void __init mp_override_legacy_irq(u8 bus_irq, u8 polarity, u8 trigger, u32 gsi)
  579. {
  580. struct mpc_config_intsrc intsrc;
  581. int ioapic = -1;
  582. int pin = -1;
  583. /*
  584. * Convert 'gsi' to 'ioapic.pin'.
  585. */
  586. ioapic = mp_find_ioapic(gsi);
  587. if (ioapic < 0)
  588. return;
  589. pin = gsi - mp_ioapic_routing[ioapic].gsi_base;
  590. /*
  591. * TBD: This check is for faulty timer entries, where the override
  592. * erroneously sets the trigger to level, resulting in a HUGE
  593. * increase of timer interrupts!
  594. */
  595. if ((bus_irq == 0) && (trigger == 3))
  596. trigger = 1;
  597. intsrc.mpc_type = MP_INTSRC;
  598. intsrc.mpc_irqtype = mp_INT;
  599. intsrc.mpc_irqflag = (trigger << 2) | polarity;
  600. intsrc.mpc_srcbus = MP_ISA_BUS;
  601. intsrc.mpc_srcbusirq = bus_irq; /* IRQ */
  602. intsrc.mpc_dstapic = mp_ioapics[ioapic].mpc_apicid; /* APIC ID */
  603. intsrc.mpc_dstirq = pin; /* INTIN# */
  604. Dprintk("Int: type %d, pol %d, trig %d, bus %d, irq %d, %d-%d\n",
  605. intsrc.mpc_irqtype, intsrc.mpc_irqflag & 3,
  606. (intsrc.mpc_irqflag >> 2) & 3, intsrc.mpc_srcbus,
  607. intsrc.mpc_srcbusirq, intsrc.mpc_dstapic, intsrc.mpc_dstirq);
  608. mp_irqs[mp_irq_entries] = intsrc;
  609. if (++mp_irq_entries == MAX_IRQ_SOURCES)
  610. panic("Max # of irq sources exceeded!\n");
  611. }
  612. void __init mp_config_acpi_legacy_irqs(void)
  613. {
  614. struct mpc_config_intsrc intsrc;
  615. int i = 0;
  616. int ioapic = -1;
  617. /*
  618. * Fabricate the legacy ISA bus (bus #31).
  619. */
  620. set_bit(MP_ISA_BUS, mp_bus_not_pci);
  621. /*
  622. * Locate the IOAPIC that manages the ISA IRQs (0-15).
  623. */
  624. ioapic = mp_find_ioapic(0);
  625. if (ioapic < 0)
  626. return;
  627. intsrc.mpc_type = MP_INTSRC;
  628. intsrc.mpc_irqflag = 0; /* Conforming */
  629. intsrc.mpc_srcbus = MP_ISA_BUS;
  630. intsrc.mpc_dstapic = mp_ioapics[ioapic].mpc_apicid;
  631. /*
  632. * Use the default configuration for the IRQs 0-15. Unless
  633. * overridden by (MADT) interrupt source override entries.
  634. */
  635. for (i = 0; i < 16; i++) {
  636. int idx;
  637. for (idx = 0; idx < mp_irq_entries; idx++) {
  638. struct mpc_config_intsrc *irq = mp_irqs + idx;
  639. /* Do we already have a mapping for this ISA IRQ? */
  640. if (irq->mpc_srcbus == MP_ISA_BUS
  641. && irq->mpc_srcbusirq == i)
  642. break;
  643. /* Do we already have a mapping for this IOAPIC pin */
  644. if ((irq->mpc_dstapic == intsrc.mpc_dstapic) &&
  645. (irq->mpc_dstirq == i))
  646. break;
  647. }
  648. if (idx != mp_irq_entries) {
  649. printk(KERN_DEBUG "ACPI: IRQ%d used by override.\n", i);
  650. continue; /* IRQ already used */
  651. }
  652. intsrc.mpc_irqtype = mp_INT;
  653. intsrc.mpc_srcbusirq = i; /* Identity mapped */
  654. intsrc.mpc_dstirq = i;
  655. Dprintk("Int: type %d, pol %d, trig %d, bus %d, irq %d, "
  656. "%d-%d\n", intsrc.mpc_irqtype, intsrc.mpc_irqflag & 3,
  657. (intsrc.mpc_irqflag >> 2) & 3, intsrc.mpc_srcbus,
  658. intsrc.mpc_srcbusirq, intsrc.mpc_dstapic,
  659. intsrc.mpc_dstirq);
  660. mp_irqs[mp_irq_entries] = intsrc;
  661. if (++mp_irq_entries == MAX_IRQ_SOURCES)
  662. panic("Max # of irq sources exceeded!\n");
  663. }
  664. }
  665. int mp_register_gsi(u32 gsi, int triggering, int polarity)
  666. {
  667. int ioapic = -1;
  668. int ioapic_pin = 0;
  669. int idx, bit = 0;
  670. if (acpi_irq_model != ACPI_IRQ_MODEL_IOAPIC)
  671. return gsi;
  672. /* Don't set up the ACPI SCI because it's already set up */
  673. if (acpi_gbl_FADT.sci_interrupt == gsi)
  674. return gsi;
  675. ioapic = mp_find_ioapic(gsi);
  676. if (ioapic < 0) {
  677. printk(KERN_WARNING "No IOAPIC for GSI %u\n", gsi);
  678. return gsi;
  679. }
  680. ioapic_pin = gsi - mp_ioapic_routing[ioapic].gsi_base;
  681. /*
  682. * Avoid pin reprogramming. PRTs typically include entries
  683. * with redundant pin->gsi mappings (but unique PCI devices);
  684. * we only program the IOAPIC on the first.
  685. */
  686. bit = ioapic_pin % 32;
  687. idx = (ioapic_pin < 32) ? 0 : (ioapic_pin / 32);
  688. if (idx > 3) {
  689. printk(KERN_ERR "Invalid reference to IOAPIC pin "
  690. "%d-%d\n", mp_ioapic_routing[ioapic].apic_id,
  691. ioapic_pin);
  692. return gsi;
  693. }
  694. if ((1 << bit) & mp_ioapic_routing[ioapic].pin_programmed[idx]) {
  695. Dprintk(KERN_DEBUG "Pin %d-%d already programmed\n",
  696. mp_ioapic_routing[ioapic].apic_id, ioapic_pin);
  697. return gsi;
  698. }
  699. mp_ioapic_routing[ioapic].pin_programmed[idx] |= (1 << bit);
  700. io_apic_set_pci_routing(ioapic, ioapic_pin, gsi,
  701. triggering == ACPI_EDGE_SENSITIVE ? 0 : 1,
  702. polarity == ACPI_ACTIVE_HIGH ? 0 : 1);
  703. return gsi;
  704. }
  705. #endif /* CONFIG_ACPI */