mpparse_64.c 21 KB

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