mpparse.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778
  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. * (c) 2008 Alexey Starikovskiy <astarikovskiy@suse.de>
  8. */
  9. #include <linux/mm.h>
  10. #include <linux/init.h>
  11. #include <linux/delay.h>
  12. #include <linux/bootmem.h>
  13. #include <linux/kernel_stat.h>
  14. #include <linux/mc146818rtc.h>
  15. #include <linux/bitops.h>
  16. #include <linux/acpi.h>
  17. #include <linux/module.h>
  18. #include <asm/smp.h>
  19. #include <asm/mtrr.h>
  20. #include <asm/mpspec.h>
  21. #include <asm/pgalloc.h>
  22. #include <asm/io_apic.h>
  23. #include <asm/proto.h>
  24. #include <asm/acpi.h>
  25. #include <asm/bios_ebda.h>
  26. #include <mach_apic.h>
  27. #ifdef CONFIG_X86_32
  28. #include <mach_apicdef.h>
  29. #include <mach_mpparse.h>
  30. #endif
  31. /*
  32. * Checksum an MP configuration block.
  33. */
  34. static int __init mpf_checksum(unsigned char *mp, int len)
  35. {
  36. int sum = 0;
  37. while (len--)
  38. sum += *mp++;
  39. return sum & 0xFF;
  40. }
  41. #ifdef CONFIG_X86_NUMAQ
  42. /*
  43. * Have to match translation table entries to main table entries by counter
  44. * hence the mpc_record variable .... can't see a less disgusting way of
  45. * doing this ....
  46. */
  47. static int mpc_record;
  48. static struct mpc_config_translation *translation_table[MAX_MPC_ENTRY]
  49. __cpuinitdata;
  50. #endif
  51. static void __cpuinit MP_processor_info(struct mpc_config_processor *m)
  52. {
  53. int apicid;
  54. char *bootup_cpu = "";
  55. if (!(m->mpc_cpuflag & CPU_ENABLED)) {
  56. disabled_cpus++;
  57. return;
  58. }
  59. #ifdef CONFIG_X86_NUMAQ
  60. apicid = mpc_apic_id(m, translation_table[mpc_record]);
  61. #else
  62. apicid = m->mpc_apicid;
  63. #endif
  64. if (m->mpc_cpuflag & CPU_BOOTPROCESSOR) {
  65. bootup_cpu = " (Bootup-CPU)";
  66. boot_cpu_physical_apicid = m->mpc_apicid;
  67. }
  68. printk(KERN_INFO "Processor #%d%s\n", m->mpc_apicid, bootup_cpu);
  69. generic_processor_info(apicid, m->mpc_apicver);
  70. }
  71. static void __init MP_bus_info(struct mpc_config_bus *m)
  72. {
  73. char str[7];
  74. memcpy(str, m->mpc_bustype, 6);
  75. str[6] = 0;
  76. #ifdef CONFIG_X86_NUMAQ
  77. mpc_oem_bus_info(m, str, translation_table[mpc_record]);
  78. #else
  79. printk(KERN_INFO "Bus #%d is %s\n", m->mpc_busid, str);
  80. #endif
  81. #if MAX_MP_BUSSES < 256
  82. if (m->mpc_busid >= MAX_MP_BUSSES) {
  83. printk(KERN_WARNING "MP table busid value (%d) for bustype %s "
  84. " is too large, max. supported is %d\n",
  85. m->mpc_busid, str, MAX_MP_BUSSES - 1);
  86. return;
  87. }
  88. #endif
  89. if (strncmp(str, BUSTYPE_ISA, sizeof(BUSTYPE_ISA) - 1) == 0) {
  90. set_bit(m->mpc_busid, mp_bus_not_pci);
  91. #if defined(CONFIG_EISA) || defined (CONFIG_MCA)
  92. mp_bus_id_to_type[m->mpc_busid] = MP_BUS_ISA;
  93. #endif
  94. } else if (strncmp(str, BUSTYPE_PCI, sizeof(BUSTYPE_PCI) - 1) == 0) {
  95. #ifdef CONFIG_X86_NUMAQ
  96. mpc_oem_pci_bus(m, translation_table[mpc_record]);
  97. #endif
  98. clear_bit(m->mpc_busid, mp_bus_not_pci);
  99. #if defined(CONFIG_EISA) || defined (CONFIG_MCA)
  100. mp_bus_id_to_type[m->mpc_busid] = MP_BUS_PCI;
  101. } else if (strncmp(str, BUSTYPE_EISA, sizeof(BUSTYPE_EISA) - 1) == 0) {
  102. mp_bus_id_to_type[m->mpc_busid] = MP_BUS_EISA;
  103. } else if (strncmp(str, BUSTYPE_MCA, sizeof(BUSTYPE_MCA) - 1) == 0) {
  104. mp_bus_id_to_type[m->mpc_busid] = MP_BUS_MCA;
  105. #endif
  106. } else
  107. printk(KERN_WARNING "Unknown bustype %s - ignoring\n", str);
  108. }
  109. #ifdef CONFIG_X86_IO_APIC
  110. static int bad_ioapic(unsigned long address)
  111. {
  112. if (nr_ioapics >= MAX_IO_APICS) {
  113. printk(KERN_ERR "ERROR: Max # of I/O APICs (%d) exceeded "
  114. "(found %d)\n", MAX_IO_APICS, nr_ioapics);
  115. panic("Recompile kernel with bigger MAX_IO_APICS!\n");
  116. }
  117. if (!address) {
  118. printk(KERN_ERR "WARNING: Bogus (zero) I/O APIC address"
  119. " found in table, skipping!\n");
  120. return 1;
  121. }
  122. return 0;
  123. }
  124. static void __init MP_ioapic_info(struct mpc_config_ioapic *m)
  125. {
  126. if (!(m->mpc_flags & MPC_APIC_USABLE))
  127. return;
  128. printk(KERN_INFO "I/O APIC #%d Version %d at 0x%X.\n",
  129. m->mpc_apicid, m->mpc_apicver, m->mpc_apicaddr);
  130. if (bad_ioapic(m->mpc_apicaddr))
  131. return;
  132. mp_ioapics[nr_ioapics].mp_apicaddr = m->mpc_apicaddr;
  133. mp_ioapics[nr_ioapics].mp_apicid = m->mpc_apicid;
  134. mp_ioapics[nr_ioapics].mp_type = m->mpc_type;
  135. mp_ioapics[nr_ioapics].mp_apicver = m->mpc_apicver;
  136. mp_ioapics[nr_ioapics].mp_flags = m->mpc_flags;
  137. nr_ioapics++;
  138. }
  139. static void __init MP_intsrc_info(struct mpc_config_intsrc *m)
  140. {
  141. printk(KERN_INFO "Int: type %d, pol %d, trig %d, bus %02x,"
  142. " IRQ %02x, APIC ID %x, APIC INT %02x\n",
  143. m->mpc_irqtype, m->mpc_irqflag & 3,
  144. (m->mpc_irqflag >> 2) & 3, m->mpc_srcbus,
  145. m->mpc_srcbusirq, m->mpc_dstapic, m->mpc_dstirq);
  146. mp_irqs[mp_irq_entries].mp_dstapic = m->mpc_dstapic;
  147. mp_irqs[mp_irq_entries].mp_type = m->mpc_type;
  148. mp_irqs[mp_irq_entries].mp_irqtype = m->mpc_irqtype;
  149. mp_irqs[mp_irq_entries].mp_irqflag = m->mpc_irqflag;
  150. mp_irqs[mp_irq_entries].mp_srcbus = m->mpc_srcbus;
  151. mp_irqs[mp_irq_entries].mp_srcbusirq = m->mpc_srcbusirq;
  152. mp_irqs[mp_irq_entries].mp_dstirq = m->mpc_dstirq;
  153. if (++mp_irq_entries == MAX_IRQ_SOURCES)
  154. panic("Max # of irq sources exceeded!!\n");
  155. }
  156. #endif
  157. static void __init MP_lintsrc_info(struct mpc_config_lintsrc *m)
  158. {
  159. printk(KERN_INFO "Lint: type %d, pol %d, trig %d, bus %02x,"
  160. " IRQ %02x, APIC ID %x, APIC LINT %02x\n",
  161. m->mpc_irqtype, m->mpc_irqflag & 3,
  162. (m->mpc_irqflag >> 2) & 3, m->mpc_srcbusid,
  163. m->mpc_srcbusirq, m->mpc_destapic, m->mpc_destapiclint);
  164. }
  165. #ifdef CONFIG_X86_NUMAQ
  166. static void __init MP_translation_info(struct mpc_config_translation *m)
  167. {
  168. printk(KERN_INFO
  169. "Translation: record %d, type %d, quad %d, global %d, local %d\n",
  170. mpc_record, m->trans_type, m->trans_quad, m->trans_global,
  171. m->trans_local);
  172. if (mpc_record >= MAX_MPC_ENTRY)
  173. printk(KERN_ERR "MAX_MPC_ENTRY exceeded!\n");
  174. else
  175. translation_table[mpc_record] = m; /* stash this for later */
  176. if (m->trans_quad < MAX_NUMNODES && !node_online(m->trans_quad))
  177. node_set_online(m->trans_quad);
  178. }
  179. /*
  180. * Read/parse the MPC oem tables
  181. */
  182. static void __init smp_read_mpc_oem(struct mp_config_oemtable *oemtable,
  183. unsigned short oemsize)
  184. {
  185. int count = sizeof(*oemtable); /* the header size */
  186. unsigned char *oemptr = ((unsigned char *)oemtable) + count;
  187. mpc_record = 0;
  188. printk(KERN_INFO "Found an OEM MPC table at %8p - parsing it ... \n",
  189. oemtable);
  190. if (memcmp(oemtable->oem_signature, MPC_OEM_SIGNATURE, 4)) {
  191. printk(KERN_WARNING
  192. "SMP mpc oemtable: bad signature [%c%c%c%c]!\n",
  193. oemtable->oem_signature[0], oemtable->oem_signature[1],
  194. oemtable->oem_signature[2], oemtable->oem_signature[3]);
  195. return;
  196. }
  197. if (mpf_checksum((unsigned char *)oemtable, oemtable->oem_length)) {
  198. printk(KERN_WARNING "SMP oem mptable: checksum error!\n");
  199. return;
  200. }
  201. while (count < oemtable->oem_length) {
  202. switch (*oemptr) {
  203. case MP_TRANSLATION:
  204. {
  205. struct mpc_config_translation *m =
  206. (struct mpc_config_translation *)oemptr;
  207. MP_translation_info(m);
  208. oemptr += sizeof(*m);
  209. count += sizeof(*m);
  210. ++mpc_record;
  211. break;
  212. }
  213. default:
  214. {
  215. printk(KERN_WARNING
  216. "Unrecognised OEM table entry type! - %d\n",
  217. (int)*oemptr);
  218. return;
  219. }
  220. }
  221. }
  222. }
  223. static inline void mps_oem_check(struct mp_config_table *mpc, char *oem,
  224. char *productid)
  225. {
  226. if (strncmp(oem, "IBM NUMA", 8))
  227. printk("Warning! May not be a NUMA-Q system!\n");
  228. if (mpc->mpc_oemptr)
  229. smp_read_mpc_oem((struct mp_config_oemtable *)mpc->mpc_oemptr,
  230. mpc->mpc_oemsize);
  231. }
  232. #endif /* CONFIG_X86_NUMAQ */
  233. /*
  234. * Read/parse the MPC
  235. */
  236. static int __init smp_read_mpc(struct mp_config_table *mpc, unsigned early)
  237. {
  238. char str[16];
  239. char oem[10];
  240. int count = sizeof(*mpc);
  241. unsigned char *mpt = ((unsigned char *)mpc) + count;
  242. if (memcmp(mpc->mpc_signature, MPC_SIGNATURE, 4)) {
  243. printk(KERN_ERR "MPTABLE: bad signature [%c%c%c%c]!\n",
  244. mpc->mpc_signature[0], mpc->mpc_signature[1],
  245. mpc->mpc_signature[2], mpc->mpc_signature[3]);
  246. return 0;
  247. }
  248. if (mpf_checksum((unsigned char *)mpc, mpc->mpc_length)) {
  249. printk(KERN_ERR "MPTABLE: checksum error!\n");
  250. return 0;
  251. }
  252. if (mpc->mpc_spec != 0x01 && mpc->mpc_spec != 0x04) {
  253. printk(KERN_ERR "MPTABLE: bad table version (%d)!!\n",
  254. mpc->mpc_spec);
  255. return 0;
  256. }
  257. if (!mpc->mpc_lapic) {
  258. printk(KERN_ERR "MPTABLE: null local APIC address!\n");
  259. return 0;
  260. }
  261. memcpy(oem, mpc->mpc_oem, 8);
  262. oem[8] = 0;
  263. printk(KERN_INFO "MPTABLE: OEM ID: %s\n", oem);
  264. memcpy(str, mpc->mpc_productid, 12);
  265. str[12] = 0;
  266. #ifdef CONFIG_X86_32
  267. mps_oem_check(mpc, oem, str);
  268. #endif
  269. printk(KERN_INFO "MPTABLE: Product ID: %s\n", str);
  270. printk(KERN_INFO "MPTABLE: APIC at: 0x%X\n", mpc->mpc_lapic);
  271. /* save the local APIC address, it might be non-default */
  272. if (!acpi_lapic)
  273. mp_lapic_addr = mpc->mpc_lapic;
  274. if (early)
  275. return 1;
  276. /*
  277. * Now process the configuration blocks.
  278. */
  279. #ifdef CONFIG_X86_NUMAQ
  280. mpc_record = 0;
  281. #endif
  282. while (count < mpc->mpc_length) {
  283. switch (*mpt) {
  284. case MP_PROCESSOR:
  285. {
  286. struct mpc_config_processor *m =
  287. (struct mpc_config_processor *)mpt;
  288. /* ACPI may have already provided this data */
  289. if (!acpi_lapic)
  290. MP_processor_info(m);
  291. mpt += sizeof(*m);
  292. count += sizeof(*m);
  293. break;
  294. }
  295. case MP_BUS:
  296. {
  297. struct mpc_config_bus *m =
  298. (struct mpc_config_bus *)mpt;
  299. MP_bus_info(m);
  300. mpt += sizeof(*m);
  301. count += sizeof(*m);
  302. break;
  303. }
  304. case MP_IOAPIC:
  305. {
  306. #ifdef CONFIG_X86_IO_APIC
  307. struct mpc_config_ioapic *m =
  308. (struct mpc_config_ioapic *)mpt;
  309. MP_ioapic_info(m);
  310. #endif
  311. mpt += sizeof(struct mpc_config_ioapic);
  312. count += sizeof(struct mpc_config_ioapic);
  313. break;
  314. }
  315. case MP_INTSRC:
  316. {
  317. #ifdef CONFIG_X86_IO_APIC
  318. struct mpc_config_intsrc *m =
  319. (struct mpc_config_intsrc *)mpt;
  320. MP_intsrc_info(m);
  321. #endif
  322. mpt += sizeof(struct mpc_config_intsrc);
  323. count += sizeof(struct mpc_config_intsrc);
  324. break;
  325. }
  326. case MP_LINTSRC:
  327. {
  328. struct mpc_config_lintsrc *m =
  329. (struct mpc_config_lintsrc *)mpt;
  330. MP_lintsrc_info(m);
  331. mpt += sizeof(*m);
  332. count += sizeof(*m);
  333. break;
  334. }
  335. default:
  336. /* wrong mptable */
  337. printk(KERN_ERR "Your mptable is wrong, contact your HW vendor!\n");
  338. printk(KERN_ERR "type %x\n", *mpt);
  339. print_hex_dump(KERN_ERR, " ", DUMP_PREFIX_ADDRESS, 16,
  340. 1, mpc, mpc->mpc_length, 1);
  341. count = mpc->mpc_length;
  342. break;
  343. }
  344. #ifdef CONFIG_X86_NUMAQ
  345. ++mpc_record;
  346. #endif
  347. }
  348. setup_apic_routing();
  349. if (!num_processors)
  350. printk(KERN_ERR "MPTABLE: no processors registered!\n");
  351. return num_processors;
  352. }
  353. #ifdef CONFIG_X86_IO_APIC
  354. static int __init ELCR_trigger(unsigned int irq)
  355. {
  356. unsigned int port;
  357. port = 0x4d0 + (irq >> 3);
  358. return (inb(port) >> (irq & 7)) & 1;
  359. }
  360. static void __init construct_default_ioirq_mptable(int mpc_default_type)
  361. {
  362. struct mpc_config_intsrc intsrc;
  363. int i;
  364. int ELCR_fallback = 0;
  365. intsrc.mpc_type = MP_INTSRC;
  366. intsrc.mpc_irqflag = 0; /* conforming */
  367. intsrc.mpc_srcbus = 0;
  368. intsrc.mpc_dstapic = mp_ioapics[0].mp_apicid;
  369. intsrc.mpc_irqtype = mp_INT;
  370. /*
  371. * If true, we have an ISA/PCI system with no IRQ entries
  372. * in the MP table. To prevent the PCI interrupts from being set up
  373. * incorrectly, we try to use the ELCR. The sanity check to see if
  374. * there is good ELCR data is very simple - IRQ0, 1, 2 and 13 can
  375. * never be level sensitive, so we simply see if the ELCR agrees.
  376. * If it does, we assume it's valid.
  377. */
  378. if (mpc_default_type == 5) {
  379. printk(KERN_INFO "ISA/PCI bus type with no IRQ information... "
  380. "falling back to ELCR\n");
  381. if (ELCR_trigger(0) || ELCR_trigger(1) || ELCR_trigger(2) ||
  382. ELCR_trigger(13))
  383. printk(KERN_ERR "ELCR contains invalid data... "
  384. "not using ELCR\n");
  385. else {
  386. printk(KERN_INFO
  387. "Using ELCR to identify PCI interrupts\n");
  388. ELCR_fallback = 1;
  389. }
  390. }
  391. for (i = 0; i < 16; i++) {
  392. switch (mpc_default_type) {
  393. case 2:
  394. if (i == 0 || i == 13)
  395. continue; /* IRQ0 & IRQ13 not connected */
  396. /* fall through */
  397. default:
  398. if (i == 2)
  399. continue; /* IRQ2 is never connected */
  400. }
  401. if (ELCR_fallback) {
  402. /*
  403. * If the ELCR indicates a level-sensitive interrupt, we
  404. * copy that information over to the MP table in the
  405. * irqflag field (level sensitive, active high polarity).
  406. */
  407. if (ELCR_trigger(i))
  408. intsrc.mpc_irqflag = 13;
  409. else
  410. intsrc.mpc_irqflag = 0;
  411. }
  412. intsrc.mpc_srcbusirq = i;
  413. intsrc.mpc_dstirq = i ? i : 2; /* IRQ0 to INTIN2 */
  414. MP_intsrc_info(&intsrc);
  415. }
  416. intsrc.mpc_irqtype = mp_ExtINT;
  417. intsrc.mpc_srcbusirq = 0;
  418. intsrc.mpc_dstirq = 0; /* 8259A to INTIN0 */
  419. MP_intsrc_info(&intsrc);
  420. }
  421. #endif
  422. static inline void __init construct_default_ISA_mptable(int mpc_default_type)
  423. {
  424. struct mpc_config_processor processor;
  425. struct mpc_config_bus bus;
  426. #ifdef CONFIG_X86_IO_APIC
  427. struct mpc_config_ioapic ioapic;
  428. #endif
  429. struct mpc_config_lintsrc lintsrc;
  430. int linttypes[2] = { mp_ExtINT, mp_NMI };
  431. int i;
  432. /*
  433. * local APIC has default address
  434. */
  435. mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
  436. /*
  437. * 2 CPUs, numbered 0 & 1.
  438. */
  439. processor.mpc_type = MP_PROCESSOR;
  440. /* Either an integrated APIC or a discrete 82489DX. */
  441. processor.mpc_apicver = mpc_default_type > 4 ? 0x10 : 0x01;
  442. processor.mpc_cpuflag = CPU_ENABLED;
  443. processor.mpc_cpufeature = (boot_cpu_data.x86 << 8) |
  444. (boot_cpu_data.x86_model << 4) | boot_cpu_data.x86_mask;
  445. processor.mpc_featureflag = boot_cpu_data.x86_capability[0];
  446. processor.mpc_reserved[0] = 0;
  447. processor.mpc_reserved[1] = 0;
  448. for (i = 0; i < 2; i++) {
  449. processor.mpc_apicid = i;
  450. MP_processor_info(&processor);
  451. }
  452. bus.mpc_type = MP_BUS;
  453. bus.mpc_busid = 0;
  454. switch (mpc_default_type) {
  455. default:
  456. printk(KERN_ERR "???\nUnknown standard configuration %d\n",
  457. mpc_default_type);
  458. /* fall through */
  459. case 1:
  460. case 5:
  461. memcpy(bus.mpc_bustype, "ISA ", 6);
  462. break;
  463. case 2:
  464. case 6:
  465. case 3:
  466. memcpy(bus.mpc_bustype, "EISA ", 6);
  467. break;
  468. case 4:
  469. case 7:
  470. memcpy(bus.mpc_bustype, "MCA ", 6);
  471. }
  472. MP_bus_info(&bus);
  473. if (mpc_default_type > 4) {
  474. bus.mpc_busid = 1;
  475. memcpy(bus.mpc_bustype, "PCI ", 6);
  476. MP_bus_info(&bus);
  477. }
  478. #ifdef CONFIG_X86_IO_APIC
  479. ioapic.mpc_type = MP_IOAPIC;
  480. ioapic.mpc_apicid = 2;
  481. ioapic.mpc_apicver = mpc_default_type > 4 ? 0x10 : 0x01;
  482. ioapic.mpc_flags = MPC_APIC_USABLE;
  483. ioapic.mpc_apicaddr = 0xFEC00000;
  484. MP_ioapic_info(&ioapic);
  485. /*
  486. * We set up most of the low 16 IO-APIC pins according to MPS rules.
  487. */
  488. construct_default_ioirq_mptable(mpc_default_type);
  489. #endif
  490. lintsrc.mpc_type = MP_LINTSRC;
  491. lintsrc.mpc_irqflag = 0; /* conforming */
  492. lintsrc.mpc_srcbusid = 0;
  493. lintsrc.mpc_srcbusirq = 0;
  494. lintsrc.mpc_destapic = MP_APIC_ALL;
  495. for (i = 0; i < 2; i++) {
  496. lintsrc.mpc_irqtype = linttypes[i];
  497. lintsrc.mpc_destapiclint = i;
  498. MP_lintsrc_info(&lintsrc);
  499. }
  500. }
  501. static struct intel_mp_floating *mpf_found;
  502. /*
  503. * Scan the memory blocks for an SMP configuration block.
  504. */
  505. static void __init __get_smp_config(unsigned early)
  506. {
  507. struct intel_mp_floating *mpf = mpf_found;
  508. if (acpi_lapic && early)
  509. return;
  510. /*
  511. * ACPI supports both logical (e.g. Hyper-Threading) and physical
  512. * processors, where MPS only supports physical.
  513. */
  514. if (acpi_lapic && acpi_ioapic) {
  515. printk(KERN_INFO "Using ACPI (MADT) for SMP configuration "
  516. "information\n");
  517. return;
  518. } else if (acpi_lapic)
  519. printk(KERN_INFO "Using ACPI for processor (LAPIC) "
  520. "configuration information\n");
  521. printk(KERN_INFO "Intel MultiProcessor Specification v1.%d\n",
  522. mpf->mpf_specification);
  523. #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86_32)
  524. if (mpf->mpf_feature2 & (1 << 7)) {
  525. printk(KERN_INFO " IMCR and PIC compatibility mode.\n");
  526. pic_mode = 1;
  527. } else {
  528. printk(KERN_INFO " Virtual Wire compatibility mode.\n");
  529. pic_mode = 0;
  530. }
  531. #endif
  532. /*
  533. * Now see if we need to read further.
  534. */
  535. if (mpf->mpf_feature1 != 0) {
  536. if (early) {
  537. /*
  538. * local APIC has default address
  539. */
  540. mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
  541. return;
  542. }
  543. printk(KERN_INFO "Default MP configuration #%d\n",
  544. mpf->mpf_feature1);
  545. construct_default_ISA_mptable(mpf->mpf_feature1);
  546. } else if (mpf->mpf_physptr) {
  547. /*
  548. * Read the physical hardware table. Anything here will
  549. * override the defaults.
  550. */
  551. if (!smp_read_mpc(phys_to_virt(mpf->mpf_physptr), early)) {
  552. #ifdef CONFIG_X86_LOCAL_APIC
  553. smp_found_config = 0;
  554. #endif
  555. printk(KERN_ERR
  556. "BIOS bug, MP table errors detected!...\n");
  557. printk(KERN_ERR "... disabling SMP support. "
  558. "(tell your hw vendor)\n");
  559. return;
  560. }
  561. if (early)
  562. return;
  563. #ifdef CONFIG_X86_IO_APIC
  564. /*
  565. * If there are no explicit MP IRQ entries, then we are
  566. * broken. We set up most of the low 16 IO-APIC pins to
  567. * ISA defaults and hope it will work.
  568. */
  569. if (!mp_irq_entries) {
  570. struct mpc_config_bus bus;
  571. printk(KERN_ERR "BIOS bug, no explicit IRQ entries, "
  572. "using default mptable. "
  573. "(tell your hw vendor)\n");
  574. bus.mpc_type = MP_BUS;
  575. bus.mpc_busid = 0;
  576. memcpy(bus.mpc_bustype, "ISA ", 6);
  577. MP_bus_info(&bus);
  578. construct_default_ioirq_mptable(0);
  579. }
  580. #endif
  581. } else
  582. BUG();
  583. if (!early)
  584. printk(KERN_INFO "Processors: %d\n", num_processors);
  585. /*
  586. * Only use the first configuration found.
  587. */
  588. }
  589. void __init early_get_smp_config(void)
  590. {
  591. __get_smp_config(1);
  592. }
  593. void __init get_smp_config(void)
  594. {
  595. __get_smp_config(0);
  596. }
  597. static int __init smp_scan_config(unsigned long base, unsigned long length,
  598. unsigned reserve)
  599. {
  600. unsigned int *bp = phys_to_virt(base);
  601. struct intel_mp_floating *mpf;
  602. printk(KERN_DEBUG "Scan SMP from %p for %ld bytes.\n", bp, length);
  603. BUILD_BUG_ON(sizeof(*mpf) != 16);
  604. while (length > 0) {
  605. mpf = (struct intel_mp_floating *)bp;
  606. if ((*bp == SMP_MAGIC_IDENT) &&
  607. (mpf->mpf_length == 1) &&
  608. !mpf_checksum((unsigned char *)bp, 16) &&
  609. ((mpf->mpf_specification == 1)
  610. || (mpf->mpf_specification == 4))) {
  611. #ifdef CONFIG_X86_LOCAL_APIC
  612. smp_found_config = 1;
  613. #endif
  614. mpf_found = mpf;
  615. #ifdef CONFIG_X86_32
  616. printk(KERN_INFO "found SMP MP-table at [%p] %08lx\n",
  617. mpf, virt_to_phys(mpf));
  618. reserve_bootmem(virt_to_phys(mpf), PAGE_SIZE,
  619. BOOTMEM_DEFAULT);
  620. if (mpf->mpf_physptr) {
  621. /*
  622. * We cannot access to MPC table to compute
  623. * table size yet, as only few megabytes from
  624. * the bottom is mapped now.
  625. * PC-9800's MPC table places on the very last
  626. * of physical memory; so that simply reserving
  627. * PAGE_SIZE from mpg->mpf_physptr yields BUG()
  628. * in reserve_bootmem.
  629. */
  630. unsigned long size = PAGE_SIZE;
  631. unsigned long end = max_low_pfn * PAGE_SIZE;
  632. if (mpf->mpf_physptr + size > end)
  633. size = end - mpf->mpf_physptr;
  634. reserve_bootmem(mpf->mpf_physptr, size,
  635. BOOTMEM_DEFAULT);
  636. }
  637. #else
  638. if (!reserve)
  639. return 1;
  640. reserve_bootmem_generic(virt_to_phys(mpf), PAGE_SIZE);
  641. if (mpf->mpf_physptr)
  642. reserve_bootmem_generic(mpf->mpf_physptr,
  643. PAGE_SIZE);
  644. #endif
  645. return 1;
  646. }
  647. bp += 4;
  648. length -= 16;
  649. }
  650. return 0;
  651. }
  652. static void __init __find_smp_config(unsigned reserve)
  653. {
  654. unsigned int address;
  655. /*
  656. * FIXME: Linux assumes you have 640K of base ram..
  657. * this continues the error...
  658. *
  659. * 1) Scan the bottom 1K for a signature
  660. * 2) Scan the top 1K of base RAM
  661. * 3) Scan the 64K of bios
  662. */
  663. if (smp_scan_config(0x0, 0x400, reserve) ||
  664. smp_scan_config(639 * 0x400, 0x400, reserve) ||
  665. smp_scan_config(0xF0000, 0x10000, reserve))
  666. return;
  667. /*
  668. * If it is an SMP machine we should know now, unless the
  669. * configuration is in an EISA/MCA bus machine with an
  670. * extended bios data area.
  671. *
  672. * there is a real-mode segmented pointer pointing to the
  673. * 4K EBDA area at 0x40E, calculate and scan it here.
  674. *
  675. * NOTE! There are Linux loaders that will corrupt the EBDA
  676. * area, and as such this kind of SMP config may be less
  677. * trustworthy, simply because the SMP table may have been
  678. * stomped on during early boot. These loaders are buggy and
  679. * should be fixed.
  680. *
  681. * MP1.4 SPEC states to only scan first 1K of 4K EBDA.
  682. */
  683. address = get_bios_ebda();
  684. if (address)
  685. smp_scan_config(address, 0x400, reserve);
  686. }
  687. void __init early_find_smp_config(void)
  688. {
  689. __find_smp_config(0);
  690. }
  691. void __init find_smp_config(void)
  692. {
  693. __find_smp_config(1);
  694. }