mpparse.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089
  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 <linux/smp.h>
  19. #include <linux/acpi.h>
  20. #include <asm/mtrr.h>
  21. #include <asm/mpspec.h>
  22. #include <asm/pgalloc.h>
  23. #include <asm/io_apic.h>
  24. #include <asm/proto.h>
  25. #include <asm/bios_ebda.h>
  26. #include <asm/e820.h>
  27. #include <asm/trampoline.h>
  28. #include <asm/setup.h>
  29. #include <mach_apic.h>
  30. #ifdef CONFIG_X86_32
  31. #include <mach_apicdef.h>
  32. #include <mach_mpparse.h>
  33. #endif
  34. /*
  35. * Checksum an MP configuration block.
  36. */
  37. static int __init mpf_checksum(unsigned char *mp, int len)
  38. {
  39. int sum = 0;
  40. while (len--)
  41. sum += *mp++;
  42. return sum & 0xFF;
  43. }
  44. static void __init MP_processor_info(struct mpc_config_processor *m)
  45. {
  46. int apicid;
  47. char *bootup_cpu = "";
  48. if (!(m->mpc_cpuflag & CPU_ENABLED)) {
  49. disabled_cpus++;
  50. return;
  51. }
  52. if (x86_quirks->mpc_apic_id)
  53. apicid = x86_quirks->mpc_apic_id(m);
  54. else
  55. apicid = m->mpc_apicid;
  56. if (m->mpc_cpuflag & CPU_BOOTPROCESSOR) {
  57. bootup_cpu = " (Bootup-CPU)";
  58. boot_cpu_physical_apicid = m->mpc_apicid;
  59. }
  60. printk(KERN_INFO "Processor #%d%s\n", m->mpc_apicid, bootup_cpu);
  61. generic_processor_info(apicid, m->mpc_apicver);
  62. }
  63. #ifdef CONFIG_X86_IO_APIC
  64. static void __init MP_bus_info(struct mpc_bus *m)
  65. {
  66. char str[7];
  67. memcpy(str, m->mpc_bustype, 6);
  68. str[6] = 0;
  69. if (x86_quirks->mpc_oem_bus_info)
  70. x86_quirks->mpc_oem_bus_info(m, str);
  71. else
  72. apic_printk(APIC_VERBOSE, "Bus #%d is %s\n", m->mpc_busid, str);
  73. #if MAX_MP_BUSSES < 256
  74. if (m->mpc_busid >= MAX_MP_BUSSES) {
  75. printk(KERN_WARNING "MP table busid value (%d) for bustype %s "
  76. " is too large, max. supported is %d\n",
  77. m->mpc_busid, str, MAX_MP_BUSSES - 1);
  78. return;
  79. }
  80. #endif
  81. if (strncmp(str, BUSTYPE_ISA, sizeof(BUSTYPE_ISA) - 1) == 0) {
  82. set_bit(m->mpc_busid, mp_bus_not_pci);
  83. #if defined(CONFIG_EISA) || defined(CONFIG_MCA)
  84. mp_bus_id_to_type[m->mpc_busid] = MP_BUS_ISA;
  85. #endif
  86. } else if (strncmp(str, BUSTYPE_PCI, sizeof(BUSTYPE_PCI) - 1) == 0) {
  87. if (x86_quirks->mpc_oem_pci_bus)
  88. x86_quirks->mpc_oem_pci_bus(m);
  89. clear_bit(m->mpc_busid, mp_bus_not_pci);
  90. #if defined(CONFIG_EISA) || defined(CONFIG_MCA)
  91. mp_bus_id_to_type[m->mpc_busid] = MP_BUS_PCI;
  92. } else if (strncmp(str, BUSTYPE_EISA, sizeof(BUSTYPE_EISA) - 1) == 0) {
  93. mp_bus_id_to_type[m->mpc_busid] = MP_BUS_EISA;
  94. } else if (strncmp(str, BUSTYPE_MCA, sizeof(BUSTYPE_MCA) - 1) == 0) {
  95. mp_bus_id_to_type[m->mpc_busid] = MP_BUS_MCA;
  96. #endif
  97. } else
  98. printk(KERN_WARNING "Unknown bustype %s - ignoring\n", str);
  99. }
  100. #endif
  101. #ifdef CONFIG_X86_IO_APIC
  102. static int bad_ioapic(unsigned long address)
  103. {
  104. if (nr_ioapics >= MAX_IO_APICS) {
  105. printk(KERN_ERR "ERROR: Max # of I/O APICs (%d) exceeded "
  106. "(found %d)\n", MAX_IO_APICS, nr_ioapics);
  107. panic("Recompile kernel with bigger MAX_IO_APICS!\n");
  108. }
  109. if (!address) {
  110. printk(KERN_ERR "WARNING: Bogus (zero) I/O APIC address"
  111. " found in table, skipping!\n");
  112. return 1;
  113. }
  114. return 0;
  115. }
  116. static void __init MP_ioapic_info(struct mpc_config_ioapic *m)
  117. {
  118. if (!(m->mpc_flags & MPC_APIC_USABLE))
  119. return;
  120. printk(KERN_INFO "I/O APIC #%d Version %d at 0x%X.\n",
  121. m->mpc_apicid, m->mpc_apicver, m->mpc_apicaddr);
  122. if (bad_ioapic(m->mpc_apicaddr))
  123. return;
  124. mp_ioapics[nr_ioapics].mp_apicaddr = m->mpc_apicaddr;
  125. mp_ioapics[nr_ioapics].mp_apicid = m->mpc_apicid;
  126. mp_ioapics[nr_ioapics].mp_type = m->mpc_type;
  127. mp_ioapics[nr_ioapics].mp_apicver = m->mpc_apicver;
  128. mp_ioapics[nr_ioapics].mp_flags = m->mpc_flags;
  129. nr_ioapics++;
  130. }
  131. static void print_MP_intsrc_info(struct mpc_config_intsrc *m)
  132. {
  133. apic_printk(APIC_VERBOSE, "Int: type %d, pol %d, trig %d, bus %02x,"
  134. " IRQ %02x, APIC ID %x, APIC INT %02x\n",
  135. m->mpc_irqtype, m->mpc_irqflag & 3,
  136. (m->mpc_irqflag >> 2) & 3, m->mpc_srcbus,
  137. m->mpc_srcbusirq, m->mpc_dstapic, m->mpc_dstirq);
  138. }
  139. static void __init print_mp_irq_info(struct mp_config_intsrc *mp_irq)
  140. {
  141. apic_printk(APIC_VERBOSE, "Int: type %d, pol %d, trig %d, bus %02x,"
  142. " IRQ %02x, APIC ID %x, APIC INT %02x\n",
  143. mp_irq->mp_irqtype, mp_irq->mp_irqflag & 3,
  144. (mp_irq->mp_irqflag >> 2) & 3, mp_irq->mp_srcbus,
  145. mp_irq->mp_srcbusirq, mp_irq->mp_dstapic, mp_irq->mp_dstirq);
  146. }
  147. static void __init assign_to_mp_irq(struct mpc_config_intsrc *m,
  148. struct mp_config_intsrc *mp_irq)
  149. {
  150. mp_irq->mp_dstapic = m->mpc_dstapic;
  151. mp_irq->mp_type = m->mpc_type;
  152. mp_irq->mp_irqtype = m->mpc_irqtype;
  153. mp_irq->mp_irqflag = m->mpc_irqflag;
  154. mp_irq->mp_srcbus = m->mpc_srcbus;
  155. mp_irq->mp_srcbusirq = m->mpc_srcbusirq;
  156. mp_irq->mp_dstirq = m->mpc_dstirq;
  157. }
  158. static void __init assign_to_mpc_intsrc(struct mp_config_intsrc *mp_irq,
  159. struct mpc_config_intsrc *m)
  160. {
  161. m->mpc_dstapic = mp_irq->mp_dstapic;
  162. m->mpc_type = mp_irq->mp_type;
  163. m->mpc_irqtype = mp_irq->mp_irqtype;
  164. m->mpc_irqflag = mp_irq->mp_irqflag;
  165. m->mpc_srcbus = mp_irq->mp_srcbus;
  166. m->mpc_srcbusirq = mp_irq->mp_srcbusirq;
  167. m->mpc_dstirq = mp_irq->mp_dstirq;
  168. }
  169. static int __init mp_irq_mpc_intsrc_cmp(struct mp_config_intsrc *mp_irq,
  170. struct mpc_config_intsrc *m)
  171. {
  172. if (mp_irq->mp_dstapic != m->mpc_dstapic)
  173. return 1;
  174. if (mp_irq->mp_type != m->mpc_type)
  175. return 2;
  176. if (mp_irq->mp_irqtype != m->mpc_irqtype)
  177. return 3;
  178. if (mp_irq->mp_irqflag != m->mpc_irqflag)
  179. return 4;
  180. if (mp_irq->mp_srcbus != m->mpc_srcbus)
  181. return 5;
  182. if (mp_irq->mp_srcbusirq != m->mpc_srcbusirq)
  183. return 6;
  184. if (mp_irq->mp_dstirq != m->mpc_dstirq)
  185. return 7;
  186. return 0;
  187. }
  188. static void __init MP_intsrc_info(struct mpc_config_intsrc *m)
  189. {
  190. int i;
  191. print_MP_intsrc_info(m);
  192. for (i = 0; i < mp_irq_entries; i++) {
  193. if (!mp_irq_mpc_intsrc_cmp(&mp_irqs[i], m))
  194. return;
  195. }
  196. assign_to_mp_irq(m, &mp_irqs[mp_irq_entries]);
  197. if (++mp_irq_entries == MAX_IRQ_SOURCES)
  198. panic("Max # of irq sources exceeded!!\n");
  199. }
  200. #endif
  201. static void __init MP_lintsrc_info(struct mpc_config_lintsrc *m)
  202. {
  203. apic_printk(APIC_VERBOSE, "Lint: type %d, pol %d, trig %d, bus %02x,"
  204. " IRQ %02x, APIC ID %x, APIC LINT %02x\n",
  205. m->mpc_irqtype, m->mpc_irqflag & 3,
  206. (m->mpc_irqflag >> 2) & 3, m->mpc_srcbusid,
  207. m->mpc_srcbusirq, m->mpc_destapic, m->mpc_destapiclint);
  208. }
  209. /*
  210. * Read/parse the MPC
  211. */
  212. static int __init smp_check_mpc(struct mpc_table *mpc, char *oem, char *str)
  213. {
  214. if (memcmp(mpc->mpc_signature, MPC_SIGNATURE, 4)) {
  215. printk(KERN_ERR "MPTABLE: bad signature [%c%c%c%c]!\n",
  216. mpc->mpc_signature[0], mpc->mpc_signature[1],
  217. mpc->mpc_signature[2], mpc->mpc_signature[3]);
  218. return 0;
  219. }
  220. if (mpf_checksum((unsigned char *)mpc, mpc->mpc_length)) {
  221. printk(KERN_ERR "MPTABLE: checksum error!\n");
  222. return 0;
  223. }
  224. if (mpc->mpc_spec != 0x01 && mpc->mpc_spec != 0x04) {
  225. printk(KERN_ERR "MPTABLE: bad table version (%d)!!\n",
  226. mpc->mpc_spec);
  227. return 0;
  228. }
  229. if (!mpc->mpc_lapic) {
  230. printk(KERN_ERR "MPTABLE: null local APIC address!\n");
  231. return 0;
  232. }
  233. memcpy(oem, mpc->mpc_oem, 8);
  234. oem[8] = 0;
  235. printk(KERN_INFO "MPTABLE: OEM ID: %s\n", oem);
  236. memcpy(str, mpc->mpc_productid, 12);
  237. str[12] = 0;
  238. printk(KERN_INFO "MPTABLE: Product ID: %s\n", str);
  239. printk(KERN_INFO "MPTABLE: APIC at: 0x%X\n", mpc->mpc_lapic);
  240. return 1;
  241. }
  242. static int __init smp_read_mpc(struct mpc_table *mpc, unsigned early)
  243. {
  244. char str[16];
  245. char oem[10];
  246. int count = sizeof(*mpc);
  247. unsigned char *mpt = ((unsigned char *)mpc) + count;
  248. if (!smp_check_mpc(mpc, oem, str))
  249. return 0;
  250. #ifdef CONFIG_X86_32
  251. /*
  252. * need to make sure summit and es7000's mps_oem_check is safe to be
  253. * called early via genericarch 's mps_oem_check
  254. */
  255. if (early) {
  256. #ifdef CONFIG_X86_NUMAQ
  257. numaq_mps_oem_check(mpc, oem, str);
  258. #endif
  259. } else
  260. mps_oem_check(mpc, oem, str);
  261. #endif
  262. /* save the local APIC address, it might be non-default */
  263. if (!acpi_lapic)
  264. mp_lapic_addr = mpc->mpc_lapic;
  265. if (early)
  266. return 1;
  267. if (mpc->mpc_oemptr && x86_quirks->smp_read_mpc_oem) {
  268. struct mp_config_oemtable *oem_table = (struct mp_config_oemtable *)(unsigned long)mpc->mpc_oemptr;
  269. x86_quirks->smp_read_mpc_oem(oem_table, mpc->mpc_oemsize);
  270. }
  271. /*
  272. * Now process the configuration blocks.
  273. */
  274. if (x86_quirks->mpc_record)
  275. *x86_quirks->mpc_record = 0;
  276. while (count < mpc->mpc_length) {
  277. switch (*mpt) {
  278. case MP_PROCESSOR:
  279. {
  280. struct mpc_config_processor *m =
  281. (struct mpc_config_processor *)mpt;
  282. /* ACPI may have already provided this data */
  283. if (!acpi_lapic)
  284. MP_processor_info(m);
  285. mpt += sizeof(*m);
  286. count += sizeof(*m);
  287. break;
  288. }
  289. case MP_BUS:
  290. {
  291. struct mpc_bus *m = (struct mpc_bus *)mpt;
  292. #ifdef CONFIG_X86_IO_APIC
  293. MP_bus_info(m);
  294. #endif
  295. mpt += sizeof(*m);
  296. count += sizeof(*m);
  297. break;
  298. }
  299. case MP_IOAPIC:
  300. {
  301. #ifdef CONFIG_X86_IO_APIC
  302. struct mpc_config_ioapic *m =
  303. (struct mpc_config_ioapic *)mpt;
  304. MP_ioapic_info(m);
  305. #endif
  306. mpt += sizeof(struct mpc_config_ioapic);
  307. count += sizeof(struct mpc_config_ioapic);
  308. break;
  309. }
  310. case MP_INTSRC:
  311. {
  312. #ifdef CONFIG_X86_IO_APIC
  313. struct mpc_config_intsrc *m =
  314. (struct mpc_config_intsrc *)mpt;
  315. MP_intsrc_info(m);
  316. #endif
  317. mpt += sizeof(struct mpc_config_intsrc);
  318. count += sizeof(struct mpc_config_intsrc);
  319. break;
  320. }
  321. case MP_LINTSRC:
  322. {
  323. struct mpc_config_lintsrc *m =
  324. (struct mpc_config_lintsrc *)mpt;
  325. MP_lintsrc_info(m);
  326. mpt += sizeof(*m);
  327. count += sizeof(*m);
  328. break;
  329. }
  330. default:
  331. /* wrong mptable */
  332. printk(KERN_ERR "Your mptable is wrong, contact your HW vendor!\n");
  333. printk(KERN_ERR "type %x\n", *mpt);
  334. print_hex_dump(KERN_ERR, " ", DUMP_PREFIX_ADDRESS, 16,
  335. 1, mpc, mpc->mpc_length, 1);
  336. count = mpc->mpc_length;
  337. break;
  338. }
  339. if (x86_quirks->mpc_record)
  340. (*x86_quirks->mpc_record)++;
  341. }
  342. #ifdef CONFIG_X86_GENERICARCH
  343. generic_bigsmp_probe();
  344. #endif
  345. #ifdef CONFIG_X86_32
  346. setup_apic_routing();
  347. #endif
  348. if (!num_processors)
  349. printk(KERN_ERR "MPTABLE: no processors registered!\n");
  350. return num_processors;
  351. }
  352. #ifdef CONFIG_X86_IO_APIC
  353. static int __init ELCR_trigger(unsigned int irq)
  354. {
  355. unsigned int port;
  356. port = 0x4d0 + (irq >> 3);
  357. return (inb(port) >> (irq & 7)) & 1;
  358. }
  359. static void __init construct_default_ioirq_mptable(int mpc_default_type)
  360. {
  361. struct mpc_config_intsrc intsrc;
  362. int i;
  363. int ELCR_fallback = 0;
  364. intsrc.mpc_type = MP_INTSRC;
  365. intsrc.mpc_irqflag = 0; /* conforming */
  366. intsrc.mpc_srcbus = 0;
  367. intsrc.mpc_dstapic = mp_ioapics[0].mp_apicid;
  368. intsrc.mpc_irqtype = mp_INT;
  369. /*
  370. * If true, we have an ISA/PCI system with no IRQ entries
  371. * in the MP table. To prevent the PCI interrupts from being set up
  372. * incorrectly, we try to use the ELCR. The sanity check to see if
  373. * there is good ELCR data is very simple - IRQ0, 1, 2 and 13 can
  374. * never be level sensitive, so we simply see if the ELCR agrees.
  375. * If it does, we assume it's valid.
  376. */
  377. if (mpc_default_type == 5) {
  378. printk(KERN_INFO "ISA/PCI bus type with no IRQ information... "
  379. "falling back to ELCR\n");
  380. if (ELCR_trigger(0) || ELCR_trigger(1) || ELCR_trigger(2) ||
  381. ELCR_trigger(13))
  382. printk(KERN_ERR "ELCR contains invalid data... "
  383. "not using ELCR\n");
  384. else {
  385. printk(KERN_INFO
  386. "Using ELCR to identify PCI interrupts\n");
  387. ELCR_fallback = 1;
  388. }
  389. }
  390. for (i = 0; i < 16; i++) {
  391. switch (mpc_default_type) {
  392. case 2:
  393. if (i == 0 || i == 13)
  394. continue; /* IRQ0 & IRQ13 not connected */
  395. /* fall through */
  396. default:
  397. if (i == 2)
  398. continue; /* IRQ2 is never connected */
  399. }
  400. if (ELCR_fallback) {
  401. /*
  402. * If the ELCR indicates a level-sensitive interrupt, we
  403. * copy that information over to the MP table in the
  404. * irqflag field (level sensitive, active high polarity).
  405. */
  406. if (ELCR_trigger(i))
  407. intsrc.mpc_irqflag = 13;
  408. else
  409. intsrc.mpc_irqflag = 0;
  410. }
  411. intsrc.mpc_srcbusirq = i;
  412. intsrc.mpc_dstirq = i ? i : 2; /* IRQ0 to INTIN2 */
  413. MP_intsrc_info(&intsrc);
  414. }
  415. intsrc.mpc_irqtype = mp_ExtINT;
  416. intsrc.mpc_srcbusirq = 0;
  417. intsrc.mpc_dstirq = 0; /* 8259A to INTIN0 */
  418. MP_intsrc_info(&intsrc);
  419. }
  420. static void __init construct_ioapic_table(int mpc_default_type)
  421. {
  422. struct mpc_config_ioapic ioapic;
  423. struct mpc_bus bus;
  424. bus.mpc_type = MP_BUS;
  425. bus.mpc_busid = 0;
  426. switch (mpc_default_type) {
  427. default:
  428. printk(KERN_ERR "???\nUnknown standard configuration %d\n",
  429. mpc_default_type);
  430. /* fall through */
  431. case 1:
  432. case 5:
  433. memcpy(bus.mpc_bustype, "ISA ", 6);
  434. break;
  435. case 2:
  436. case 6:
  437. case 3:
  438. memcpy(bus.mpc_bustype, "EISA ", 6);
  439. break;
  440. case 4:
  441. case 7:
  442. memcpy(bus.mpc_bustype, "MCA ", 6);
  443. }
  444. MP_bus_info(&bus);
  445. if (mpc_default_type > 4) {
  446. bus.mpc_busid = 1;
  447. memcpy(bus.mpc_bustype, "PCI ", 6);
  448. MP_bus_info(&bus);
  449. }
  450. ioapic.mpc_type = MP_IOAPIC;
  451. ioapic.mpc_apicid = 2;
  452. ioapic.mpc_apicver = mpc_default_type > 4 ? 0x10 : 0x01;
  453. ioapic.mpc_flags = MPC_APIC_USABLE;
  454. ioapic.mpc_apicaddr = 0xFEC00000;
  455. MP_ioapic_info(&ioapic);
  456. /*
  457. * We set up most of the low 16 IO-APIC pins according to MPS rules.
  458. */
  459. construct_default_ioirq_mptable(mpc_default_type);
  460. }
  461. #else
  462. static inline void __init construct_ioapic_table(int mpc_default_type) { }
  463. #endif
  464. static inline void __init construct_default_ISA_mptable(int mpc_default_type)
  465. {
  466. struct mpc_config_processor processor;
  467. struct mpc_config_lintsrc lintsrc;
  468. int linttypes[2] = { mp_ExtINT, mp_NMI };
  469. int i;
  470. /*
  471. * local APIC has default address
  472. */
  473. mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
  474. /*
  475. * 2 CPUs, numbered 0 & 1.
  476. */
  477. processor.mpc_type = MP_PROCESSOR;
  478. /* Either an integrated APIC or a discrete 82489DX. */
  479. processor.mpc_apicver = mpc_default_type > 4 ? 0x10 : 0x01;
  480. processor.mpc_cpuflag = CPU_ENABLED;
  481. processor.mpc_cpufeature = (boot_cpu_data.x86 << 8) |
  482. (boot_cpu_data.x86_model << 4) | boot_cpu_data.x86_mask;
  483. processor.mpc_featureflag = boot_cpu_data.x86_capability[0];
  484. processor.mpc_reserved[0] = 0;
  485. processor.mpc_reserved[1] = 0;
  486. for (i = 0; i < 2; i++) {
  487. processor.mpc_apicid = i;
  488. MP_processor_info(&processor);
  489. }
  490. construct_ioapic_table(mpc_default_type);
  491. lintsrc.mpc_type = MP_LINTSRC;
  492. lintsrc.mpc_irqflag = 0; /* conforming */
  493. lintsrc.mpc_srcbusid = 0;
  494. lintsrc.mpc_srcbusirq = 0;
  495. lintsrc.mpc_destapic = MP_APIC_ALL;
  496. for (i = 0; i < 2; i++) {
  497. lintsrc.mpc_irqtype = linttypes[i];
  498. lintsrc.mpc_destapiclint = i;
  499. MP_lintsrc_info(&lintsrc);
  500. }
  501. }
  502. static struct intel_mp_floating *mpf_found;
  503. /*
  504. * Scan the memory blocks for an SMP configuration block.
  505. */
  506. static void __init __get_smp_config(unsigned int early)
  507. {
  508. struct intel_mp_floating *mpf = mpf_found;
  509. if (!mpf)
  510. return;
  511. if (acpi_lapic && early)
  512. return;
  513. /*
  514. * MPS doesn't support hyperthreading, aka only have
  515. * thread 0 apic id in MPS table
  516. */
  517. if (acpi_lapic && acpi_ioapic)
  518. return;
  519. if (x86_quirks->mach_get_smp_config) {
  520. if (x86_quirks->mach_get_smp_config(early))
  521. return;
  522. }
  523. printk(KERN_INFO "Intel MultiProcessor Specification v1.%d\n",
  524. mpf->mpf_specification);
  525. #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86_32)
  526. if (mpf->mpf_feature2 & (1 << 7)) {
  527. printk(KERN_INFO " IMCR and PIC compatibility mode.\n");
  528. pic_mode = 1;
  529. } else {
  530. printk(KERN_INFO " Virtual Wire compatibility mode.\n");
  531. pic_mode = 0;
  532. }
  533. #endif
  534. /*
  535. * Now see if we need to read further.
  536. */
  537. if (mpf->mpf_feature1 != 0) {
  538. if (early) {
  539. /*
  540. * local APIC has default address
  541. */
  542. mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
  543. return;
  544. }
  545. printk(KERN_INFO "Default MP configuration #%d\n",
  546. mpf->mpf_feature1);
  547. construct_default_ISA_mptable(mpf->mpf_feature1);
  548. } else if (mpf->mpf_physptr) {
  549. /*
  550. * Read the physical hardware table. Anything here will
  551. * override the defaults.
  552. */
  553. if (!smp_read_mpc(phys_to_virt(mpf->mpf_physptr), early)) {
  554. #ifdef CONFIG_X86_LOCAL_APIC
  555. smp_found_config = 0;
  556. #endif
  557. printk(KERN_ERR
  558. "BIOS bug, MP table errors detected!...\n");
  559. printk(KERN_ERR "... disabling SMP support. "
  560. "(tell your hw vendor)\n");
  561. return;
  562. }
  563. if (early)
  564. return;
  565. #ifdef CONFIG_X86_IO_APIC
  566. /*
  567. * If there are no explicit MP IRQ entries, then we are
  568. * broken. We set up most of the low 16 IO-APIC pins to
  569. * ISA defaults and hope it will work.
  570. */
  571. if (!mp_irq_entries) {
  572. struct mpc_bus bus;
  573. printk(KERN_ERR "BIOS bug, no explicit IRQ entries, "
  574. "using default mptable. "
  575. "(tell your hw vendor)\n");
  576. bus.mpc_type = MP_BUS;
  577. bus.mpc_busid = 0;
  578. memcpy(bus.mpc_bustype, "ISA ", 6);
  579. MP_bus_info(&bus);
  580. construct_default_ioirq_mptable(0);
  581. }
  582. #endif
  583. } else
  584. BUG();
  585. if (!early)
  586. printk(KERN_INFO "Processors: %d\n", num_processors);
  587. /*
  588. * Only use the first configuration found.
  589. */
  590. }
  591. void __init early_get_smp_config(void)
  592. {
  593. __get_smp_config(1);
  594. }
  595. void __init get_smp_config(void)
  596. {
  597. __get_smp_config(0);
  598. }
  599. static int __init smp_scan_config(unsigned long base, unsigned long length,
  600. unsigned reserve)
  601. {
  602. unsigned int *bp = phys_to_virt(base);
  603. struct intel_mp_floating *mpf;
  604. apic_printk(APIC_VERBOSE, "Scan SMP from %p for %ld bytes.\n",
  605. bp, length);
  606. BUILD_BUG_ON(sizeof(*mpf) != 16);
  607. while (length > 0) {
  608. mpf = (struct intel_mp_floating *)bp;
  609. if ((*bp == SMP_MAGIC_IDENT) &&
  610. (mpf->mpf_length == 1) &&
  611. !mpf_checksum((unsigned char *)bp, 16) &&
  612. ((mpf->mpf_specification == 1)
  613. || (mpf->mpf_specification == 4))) {
  614. #ifdef CONFIG_X86_LOCAL_APIC
  615. smp_found_config = 1;
  616. #endif
  617. mpf_found = mpf;
  618. printk(KERN_INFO "found SMP MP-table at [%p] %08lx\n",
  619. mpf, virt_to_phys(mpf));
  620. if (!reserve)
  621. return 1;
  622. reserve_bootmem_generic(virt_to_phys(mpf), PAGE_SIZE,
  623. BOOTMEM_DEFAULT);
  624. if (mpf->mpf_physptr) {
  625. unsigned long size = PAGE_SIZE;
  626. #ifdef CONFIG_X86_32
  627. /*
  628. * We cannot access to MPC table to compute
  629. * table size yet, as only few megabytes from
  630. * the bottom is mapped now.
  631. * PC-9800's MPC table places on the very last
  632. * of physical memory; so that simply reserving
  633. * PAGE_SIZE from mpg->mpf_physptr yields BUG()
  634. * in reserve_bootmem.
  635. */
  636. unsigned long end = max_low_pfn * PAGE_SIZE;
  637. if (mpf->mpf_physptr + size > end)
  638. size = end - mpf->mpf_physptr;
  639. #endif
  640. reserve_bootmem_generic(mpf->mpf_physptr, size,
  641. BOOTMEM_DEFAULT);
  642. }
  643. return 1;
  644. }
  645. bp += 4;
  646. length -= 16;
  647. }
  648. return 0;
  649. }
  650. static void __init __find_smp_config(unsigned int reserve)
  651. {
  652. unsigned int address;
  653. if (x86_quirks->mach_find_smp_config) {
  654. if (x86_quirks->mach_find_smp_config(reserve))
  655. return;
  656. }
  657. /*
  658. * FIXME: Linux assumes you have 640K of base ram..
  659. * this continues the error...
  660. *
  661. * 1) Scan the bottom 1K for a signature
  662. * 2) Scan the top 1K of base RAM
  663. * 3) Scan the 64K of bios
  664. */
  665. if (smp_scan_config(0x0, 0x400, reserve) ||
  666. smp_scan_config(639 * 0x400, 0x400, reserve) ||
  667. smp_scan_config(0xF0000, 0x10000, reserve))
  668. return;
  669. /*
  670. * If it is an SMP machine we should know now, unless the
  671. * configuration is in an EISA/MCA bus machine with an
  672. * extended bios data area.
  673. *
  674. * there is a real-mode segmented pointer pointing to the
  675. * 4K EBDA area at 0x40E, calculate and scan it here.
  676. *
  677. * NOTE! There are Linux loaders that will corrupt the EBDA
  678. * area, and as such this kind of SMP config may be less
  679. * trustworthy, simply because the SMP table may have been
  680. * stomped on during early boot. These loaders are buggy and
  681. * should be fixed.
  682. *
  683. * MP1.4 SPEC states to only scan first 1K of 4K EBDA.
  684. */
  685. address = get_bios_ebda();
  686. if (address)
  687. smp_scan_config(address, 0x400, reserve);
  688. }
  689. void __init early_find_smp_config(void)
  690. {
  691. __find_smp_config(0);
  692. }
  693. void __init find_smp_config(void)
  694. {
  695. __find_smp_config(1);
  696. }
  697. #ifdef CONFIG_X86_IO_APIC
  698. static u8 __initdata irq_used[MAX_IRQ_SOURCES];
  699. static int __init get_MP_intsrc_index(struct mpc_config_intsrc *m)
  700. {
  701. int i;
  702. if (m->mpc_irqtype != mp_INT)
  703. return 0;
  704. if (m->mpc_irqflag != 0x0f)
  705. return 0;
  706. /* not legacy */
  707. for (i = 0; i < mp_irq_entries; i++) {
  708. if (mp_irqs[i].mp_irqtype != mp_INT)
  709. continue;
  710. if (mp_irqs[i].mp_irqflag != 0x0f)
  711. continue;
  712. if (mp_irqs[i].mp_srcbus != m->mpc_srcbus)
  713. continue;
  714. if (mp_irqs[i].mp_srcbusirq != m->mpc_srcbusirq)
  715. continue;
  716. if (irq_used[i]) {
  717. /* already claimed */
  718. return -2;
  719. }
  720. irq_used[i] = 1;
  721. return i;
  722. }
  723. /* not found */
  724. return -1;
  725. }
  726. #define SPARE_SLOT_NUM 20
  727. static struct mpc_config_intsrc __initdata *m_spare[SPARE_SLOT_NUM];
  728. #endif
  729. static int __init replace_intsrc_all(struct mpc_table *mpc,
  730. unsigned long mpc_new_phys,
  731. unsigned long mpc_new_length)
  732. {
  733. #ifdef CONFIG_X86_IO_APIC
  734. int i;
  735. int nr_m_spare = 0;
  736. #endif
  737. int count = sizeof(*mpc);
  738. unsigned char *mpt = ((unsigned char *)mpc) + count;
  739. printk(KERN_INFO "mpc_length %x\n", mpc->mpc_length);
  740. while (count < mpc->mpc_length) {
  741. switch (*mpt) {
  742. case MP_PROCESSOR:
  743. {
  744. struct mpc_config_processor *m =
  745. (struct mpc_config_processor *)mpt;
  746. mpt += sizeof(*m);
  747. count += sizeof(*m);
  748. break;
  749. }
  750. case MP_BUS:
  751. {
  752. struct mpc_bus *m = (struct mpc_bus *)mpt;
  753. mpt += sizeof(*m);
  754. count += sizeof(*m);
  755. break;
  756. }
  757. case MP_IOAPIC:
  758. {
  759. mpt += sizeof(struct mpc_config_ioapic);
  760. count += sizeof(struct mpc_config_ioapic);
  761. break;
  762. }
  763. case MP_INTSRC:
  764. {
  765. #ifdef CONFIG_X86_IO_APIC
  766. struct mpc_config_intsrc *m =
  767. (struct mpc_config_intsrc *)mpt;
  768. printk(KERN_INFO "OLD ");
  769. print_MP_intsrc_info(m);
  770. i = get_MP_intsrc_index(m);
  771. if (i > 0) {
  772. assign_to_mpc_intsrc(&mp_irqs[i], m);
  773. printk(KERN_INFO "NEW ");
  774. print_mp_irq_info(&mp_irqs[i]);
  775. } else if (!i) {
  776. /* legacy, do nothing */
  777. } else if (nr_m_spare < SPARE_SLOT_NUM) {
  778. /*
  779. * not found (-1), or duplicated (-2)
  780. * are invalid entries,
  781. * we need to use the slot later
  782. */
  783. m_spare[nr_m_spare] = m;
  784. nr_m_spare++;
  785. }
  786. #endif
  787. mpt += sizeof(struct mpc_config_intsrc);
  788. count += sizeof(struct mpc_config_intsrc);
  789. break;
  790. }
  791. case MP_LINTSRC:
  792. {
  793. struct mpc_config_lintsrc *m =
  794. (struct mpc_config_lintsrc *)mpt;
  795. mpt += sizeof(*m);
  796. count += sizeof(*m);
  797. break;
  798. }
  799. default:
  800. /* wrong mptable */
  801. printk(KERN_ERR "Your mptable is wrong, contact your HW vendor!\n");
  802. printk(KERN_ERR "type %x\n", *mpt);
  803. print_hex_dump(KERN_ERR, " ", DUMP_PREFIX_ADDRESS, 16,
  804. 1, mpc, mpc->mpc_length, 1);
  805. goto out;
  806. }
  807. }
  808. #ifdef CONFIG_X86_IO_APIC
  809. for (i = 0; i < mp_irq_entries; i++) {
  810. if (irq_used[i])
  811. continue;
  812. if (mp_irqs[i].mp_irqtype != mp_INT)
  813. continue;
  814. if (mp_irqs[i].mp_irqflag != 0x0f)
  815. continue;
  816. if (nr_m_spare > 0) {
  817. printk(KERN_INFO "*NEW* found ");
  818. nr_m_spare--;
  819. assign_to_mpc_intsrc(&mp_irqs[i], m_spare[nr_m_spare]);
  820. m_spare[nr_m_spare] = NULL;
  821. } else {
  822. struct mpc_config_intsrc *m =
  823. (struct mpc_config_intsrc *)mpt;
  824. count += sizeof(struct mpc_config_intsrc);
  825. if (!mpc_new_phys) {
  826. printk(KERN_INFO "No spare slots, try to append...take your risk, new mpc_length %x\n", count);
  827. } else {
  828. if (count <= mpc_new_length)
  829. printk(KERN_INFO "No spare slots, try to append..., new mpc_length %x\n", count);
  830. else {
  831. printk(KERN_ERR "mpc_new_length %lx is too small\n", mpc_new_length);
  832. goto out;
  833. }
  834. }
  835. assign_to_mpc_intsrc(&mp_irqs[i], m);
  836. mpc->mpc_length = count;
  837. mpt += sizeof(struct mpc_config_intsrc);
  838. }
  839. print_mp_irq_info(&mp_irqs[i]);
  840. }
  841. #endif
  842. out:
  843. /* update checksum */
  844. mpc->mpc_checksum = 0;
  845. mpc->mpc_checksum -= mpf_checksum((unsigned char *)mpc,
  846. mpc->mpc_length);
  847. return 0;
  848. }
  849. static int __initdata enable_update_mptable;
  850. static int __init update_mptable_setup(char *str)
  851. {
  852. enable_update_mptable = 1;
  853. return 0;
  854. }
  855. early_param("update_mptable", update_mptable_setup);
  856. static unsigned long __initdata mpc_new_phys;
  857. static unsigned long mpc_new_length __initdata = 4096;
  858. /* alloc_mptable or alloc_mptable=4k */
  859. static int __initdata alloc_mptable;
  860. static int __init parse_alloc_mptable_opt(char *p)
  861. {
  862. enable_update_mptable = 1;
  863. alloc_mptable = 1;
  864. if (!p)
  865. return 0;
  866. mpc_new_length = memparse(p, &p);
  867. return 0;
  868. }
  869. early_param("alloc_mptable", parse_alloc_mptable_opt);
  870. void __init early_reserve_e820_mpc_new(void)
  871. {
  872. if (enable_update_mptable && alloc_mptable) {
  873. u64 startt = 0;
  874. #ifdef CONFIG_X86_TRAMPOLINE
  875. startt = TRAMPOLINE_BASE;
  876. #endif
  877. mpc_new_phys = early_reserve_e820(startt, mpc_new_length, 4);
  878. }
  879. }
  880. static int __init update_mp_table(void)
  881. {
  882. char str[16];
  883. char oem[10];
  884. struct intel_mp_floating *mpf;
  885. struct mpc_table *mpc, *mpc_new;
  886. if (!enable_update_mptable)
  887. return 0;
  888. mpf = mpf_found;
  889. if (!mpf)
  890. return 0;
  891. /*
  892. * Now see if we need to go further.
  893. */
  894. if (mpf->mpf_feature1 != 0)
  895. return 0;
  896. if (!mpf->mpf_physptr)
  897. return 0;
  898. mpc = phys_to_virt(mpf->mpf_physptr);
  899. if (!smp_check_mpc(mpc, oem, str))
  900. return 0;
  901. printk(KERN_INFO "mpf: %lx\n", virt_to_phys(mpf));
  902. printk(KERN_INFO "mpf_physptr: %x\n", mpf->mpf_physptr);
  903. if (mpc_new_phys && mpc->mpc_length > mpc_new_length) {
  904. mpc_new_phys = 0;
  905. printk(KERN_INFO "mpc_new_length is %ld, please use alloc_mptable=8k\n",
  906. mpc_new_length);
  907. }
  908. if (!mpc_new_phys) {
  909. unsigned char old, new;
  910. /* check if we can change the postion */
  911. mpc->mpc_checksum = 0;
  912. old = mpf_checksum((unsigned char *)mpc, mpc->mpc_length);
  913. mpc->mpc_checksum = 0xff;
  914. new = mpf_checksum((unsigned char *)mpc, mpc->mpc_length);
  915. if (old == new) {
  916. printk(KERN_INFO "mpc is readonly, please try alloc_mptable instead\n");
  917. return 0;
  918. }
  919. printk(KERN_INFO "use in-positon replacing\n");
  920. } else {
  921. mpf->mpf_physptr = mpc_new_phys;
  922. mpc_new = phys_to_virt(mpc_new_phys);
  923. memcpy(mpc_new, mpc, mpc->mpc_length);
  924. mpc = mpc_new;
  925. /* check if we can modify that */
  926. if (mpc_new_phys - mpf->mpf_physptr) {
  927. struct intel_mp_floating *mpf_new;
  928. /* steal 16 bytes from [0, 1k) */
  929. printk(KERN_INFO "mpf new: %x\n", 0x400 - 16);
  930. mpf_new = phys_to_virt(0x400 - 16);
  931. memcpy(mpf_new, mpf, 16);
  932. mpf = mpf_new;
  933. mpf->mpf_physptr = mpc_new_phys;
  934. }
  935. mpf->mpf_checksum = 0;
  936. mpf->mpf_checksum -= mpf_checksum((unsigned char *)mpf, 16);
  937. printk(KERN_INFO "mpf_physptr new: %x\n", mpf->mpf_physptr);
  938. }
  939. /*
  940. * only replace the one with mp_INT and
  941. * MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
  942. * already in mp_irqs , stored by ... and mp_config_acpi_gsi,
  943. * may need pci=routeirq for all coverage
  944. */
  945. replace_intsrc_all(mpc, mpc_new_phys, mpc_new_length);
  946. return 0;
  947. }
  948. late_initcall(update_mp_table);