mpparse.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083
  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_cpu *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_ioapic *m)
  117. {
  118. if (!(m->flags & MPC_APIC_USABLE))
  119. return;
  120. printk(KERN_INFO "I/O APIC #%d Version %d at 0x%X.\n",
  121. m->apicid, m->apicver, m->apicaddr);
  122. if (bad_ioapic(m->apicaddr))
  123. return;
  124. mp_ioapics[nr_ioapics].mp_apicaddr = m->apicaddr;
  125. mp_ioapics[nr_ioapics].mp_apicid = m->apicid;
  126. mp_ioapics[nr_ioapics].mp_type = m->type;
  127. mp_ioapics[nr_ioapics].mp_apicver = m->apicver;
  128. mp_ioapics[nr_ioapics].mp_flags = m->flags;
  129. nr_ioapics++;
  130. }
  131. static void print_MP_intsrc_info(struct mpc_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_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_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_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_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_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 mpc_oemtable *oem_table = (void *)(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_cpu *m = (struct mpc_cpu *)mpt;
  281. /* ACPI may have already provided this data */
  282. if (!acpi_lapic)
  283. MP_processor_info(m);
  284. mpt += sizeof(*m);
  285. count += sizeof(*m);
  286. break;
  287. }
  288. case MP_BUS:
  289. {
  290. struct mpc_bus *m = (struct mpc_bus *)mpt;
  291. #ifdef CONFIG_X86_IO_APIC
  292. MP_bus_info(m);
  293. #endif
  294. mpt += sizeof(*m);
  295. count += sizeof(*m);
  296. break;
  297. }
  298. case MP_IOAPIC:
  299. {
  300. #ifdef CONFIG_X86_IO_APIC
  301. struct mpc_ioapic *m = (struct mpc_ioapic *)mpt;
  302. MP_ioapic_info(m);
  303. #endif
  304. mpt += sizeof(struct mpc_ioapic);
  305. count += sizeof(struct mpc_ioapic);
  306. break;
  307. }
  308. case MP_INTSRC:
  309. {
  310. #ifdef CONFIG_X86_IO_APIC
  311. struct mpc_intsrc *m = (struct mpc_intsrc *)mpt;
  312. MP_intsrc_info(m);
  313. #endif
  314. mpt += sizeof(struct mpc_intsrc);
  315. count += sizeof(struct mpc_intsrc);
  316. break;
  317. }
  318. case MP_LINTSRC:
  319. {
  320. struct mpc_lintsrc *m =
  321. (struct mpc_lintsrc *)mpt;
  322. MP_lintsrc_info(m);
  323. mpt += sizeof(*m);
  324. count += sizeof(*m);
  325. break;
  326. }
  327. default:
  328. /* wrong mptable */
  329. printk(KERN_ERR "Your mptable is wrong, contact your HW vendor!\n");
  330. printk(KERN_ERR "type %x\n", *mpt);
  331. print_hex_dump(KERN_ERR, " ", DUMP_PREFIX_ADDRESS, 16,
  332. 1, mpc, mpc->mpc_length, 1);
  333. count = mpc->mpc_length;
  334. break;
  335. }
  336. if (x86_quirks->mpc_record)
  337. (*x86_quirks->mpc_record)++;
  338. }
  339. #ifdef CONFIG_X86_GENERICARCH
  340. generic_bigsmp_probe();
  341. #endif
  342. #ifdef CONFIG_X86_32
  343. setup_apic_routing();
  344. #endif
  345. if (!num_processors)
  346. printk(KERN_ERR "MPTABLE: no processors registered!\n");
  347. return num_processors;
  348. }
  349. #ifdef CONFIG_X86_IO_APIC
  350. static int __init ELCR_trigger(unsigned int irq)
  351. {
  352. unsigned int port;
  353. port = 0x4d0 + (irq >> 3);
  354. return (inb(port) >> (irq & 7)) & 1;
  355. }
  356. static void __init construct_default_ioirq_mptable(int mpc_default_type)
  357. {
  358. struct mpc_intsrc intsrc;
  359. int i;
  360. int ELCR_fallback = 0;
  361. intsrc.mpc_type = MP_INTSRC;
  362. intsrc.mpc_irqflag = 0; /* conforming */
  363. intsrc.mpc_srcbus = 0;
  364. intsrc.mpc_dstapic = mp_ioapics[0].mp_apicid;
  365. intsrc.mpc_irqtype = mp_INT;
  366. /*
  367. * If true, we have an ISA/PCI system with no IRQ entries
  368. * in the MP table. To prevent the PCI interrupts from being set up
  369. * incorrectly, we try to use the ELCR. The sanity check to see if
  370. * there is good ELCR data is very simple - IRQ0, 1, 2 and 13 can
  371. * never be level sensitive, so we simply see if the ELCR agrees.
  372. * If it does, we assume it's valid.
  373. */
  374. if (mpc_default_type == 5) {
  375. printk(KERN_INFO "ISA/PCI bus type with no IRQ information... "
  376. "falling back to ELCR\n");
  377. if (ELCR_trigger(0) || ELCR_trigger(1) || ELCR_trigger(2) ||
  378. ELCR_trigger(13))
  379. printk(KERN_ERR "ELCR contains invalid data... "
  380. "not using ELCR\n");
  381. else {
  382. printk(KERN_INFO
  383. "Using ELCR to identify PCI interrupts\n");
  384. ELCR_fallback = 1;
  385. }
  386. }
  387. for (i = 0; i < 16; i++) {
  388. switch (mpc_default_type) {
  389. case 2:
  390. if (i == 0 || i == 13)
  391. continue; /* IRQ0 & IRQ13 not connected */
  392. /* fall through */
  393. default:
  394. if (i == 2)
  395. continue; /* IRQ2 is never connected */
  396. }
  397. if (ELCR_fallback) {
  398. /*
  399. * If the ELCR indicates a level-sensitive interrupt, we
  400. * copy that information over to the MP table in the
  401. * irqflag field (level sensitive, active high polarity).
  402. */
  403. if (ELCR_trigger(i))
  404. intsrc.mpc_irqflag = 13;
  405. else
  406. intsrc.mpc_irqflag = 0;
  407. }
  408. intsrc.mpc_srcbusirq = i;
  409. intsrc.mpc_dstirq = i ? i : 2; /* IRQ0 to INTIN2 */
  410. MP_intsrc_info(&intsrc);
  411. }
  412. intsrc.mpc_irqtype = mp_ExtINT;
  413. intsrc.mpc_srcbusirq = 0;
  414. intsrc.mpc_dstirq = 0; /* 8259A to INTIN0 */
  415. MP_intsrc_info(&intsrc);
  416. }
  417. static void __init construct_ioapic_table(int mpc_default_type)
  418. {
  419. struct mpc_ioapic ioapic;
  420. struct mpc_bus bus;
  421. bus.mpc_type = MP_BUS;
  422. bus.mpc_busid = 0;
  423. switch (mpc_default_type) {
  424. default:
  425. printk(KERN_ERR "???\nUnknown standard configuration %d\n",
  426. mpc_default_type);
  427. /* fall through */
  428. case 1:
  429. case 5:
  430. memcpy(bus.mpc_bustype, "ISA ", 6);
  431. break;
  432. case 2:
  433. case 6:
  434. case 3:
  435. memcpy(bus.mpc_bustype, "EISA ", 6);
  436. break;
  437. case 4:
  438. case 7:
  439. memcpy(bus.mpc_bustype, "MCA ", 6);
  440. }
  441. MP_bus_info(&bus);
  442. if (mpc_default_type > 4) {
  443. bus.mpc_busid = 1;
  444. memcpy(bus.mpc_bustype, "PCI ", 6);
  445. MP_bus_info(&bus);
  446. }
  447. ioapic.type = MP_IOAPIC;
  448. ioapic.apicid = 2;
  449. ioapic.apicver = mpc_default_type > 4 ? 0x10 : 0x01;
  450. ioapic.flags = MPC_APIC_USABLE;
  451. ioapic.apicaddr = 0xFEC00000;
  452. MP_ioapic_info(&ioapic);
  453. /*
  454. * We set up most of the low 16 IO-APIC pins according to MPS rules.
  455. */
  456. construct_default_ioirq_mptable(mpc_default_type);
  457. }
  458. #else
  459. static inline void __init construct_ioapic_table(int mpc_default_type) { }
  460. #endif
  461. static inline void __init construct_default_ISA_mptable(int mpc_default_type)
  462. {
  463. struct mpc_cpu processor;
  464. struct mpc_lintsrc lintsrc;
  465. int linttypes[2] = { mp_ExtINT, mp_NMI };
  466. int i;
  467. /*
  468. * local APIC has default address
  469. */
  470. mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
  471. /*
  472. * 2 CPUs, numbered 0 & 1.
  473. */
  474. processor.mpc_type = MP_PROCESSOR;
  475. /* Either an integrated APIC or a discrete 82489DX. */
  476. processor.mpc_apicver = mpc_default_type > 4 ? 0x10 : 0x01;
  477. processor.mpc_cpuflag = CPU_ENABLED;
  478. processor.mpc_cpufeature = (boot_cpu_data.x86 << 8) |
  479. (boot_cpu_data.x86_model << 4) | boot_cpu_data.x86_mask;
  480. processor.mpc_featureflag = boot_cpu_data.x86_capability[0];
  481. processor.mpc_reserved[0] = 0;
  482. processor.mpc_reserved[1] = 0;
  483. for (i = 0; i < 2; i++) {
  484. processor.mpc_apicid = i;
  485. MP_processor_info(&processor);
  486. }
  487. construct_ioapic_table(mpc_default_type);
  488. lintsrc.mpc_type = MP_LINTSRC;
  489. lintsrc.mpc_irqflag = 0; /* conforming */
  490. lintsrc.mpc_srcbusid = 0;
  491. lintsrc.mpc_srcbusirq = 0;
  492. lintsrc.mpc_destapic = MP_APIC_ALL;
  493. for (i = 0; i < 2; i++) {
  494. lintsrc.mpc_irqtype = linttypes[i];
  495. lintsrc.mpc_destapiclint = i;
  496. MP_lintsrc_info(&lintsrc);
  497. }
  498. }
  499. static struct intel_mp_floating *mpf_found;
  500. /*
  501. * Scan the memory blocks for an SMP configuration block.
  502. */
  503. static void __init __get_smp_config(unsigned int early)
  504. {
  505. struct intel_mp_floating *mpf = mpf_found;
  506. if (!mpf)
  507. return;
  508. if (acpi_lapic && early)
  509. return;
  510. /*
  511. * MPS doesn't support hyperthreading, aka only have
  512. * thread 0 apic id in MPS table
  513. */
  514. if (acpi_lapic && acpi_ioapic)
  515. return;
  516. if (x86_quirks->mach_get_smp_config) {
  517. if (x86_quirks->mach_get_smp_config(early))
  518. return;
  519. }
  520. printk(KERN_INFO "Intel MultiProcessor Specification v1.%d\n",
  521. mpf->mpf_specification);
  522. #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86_32)
  523. if (mpf->mpf_feature2 & (1 << 7)) {
  524. printk(KERN_INFO " IMCR and PIC compatibility mode.\n");
  525. pic_mode = 1;
  526. } else {
  527. printk(KERN_INFO " Virtual Wire compatibility mode.\n");
  528. pic_mode = 0;
  529. }
  530. #endif
  531. /*
  532. * Now see if we need to read further.
  533. */
  534. if (mpf->mpf_feature1 != 0) {
  535. if (early) {
  536. /*
  537. * local APIC has default address
  538. */
  539. mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
  540. return;
  541. }
  542. printk(KERN_INFO "Default MP configuration #%d\n",
  543. mpf->mpf_feature1);
  544. construct_default_ISA_mptable(mpf->mpf_feature1);
  545. } else if (mpf->mpf_physptr) {
  546. /*
  547. * Read the physical hardware table. Anything here will
  548. * override the defaults.
  549. */
  550. if (!smp_read_mpc(phys_to_virt(mpf->mpf_physptr), early)) {
  551. #ifdef CONFIG_X86_LOCAL_APIC
  552. smp_found_config = 0;
  553. #endif
  554. printk(KERN_ERR
  555. "BIOS bug, MP table errors detected!...\n");
  556. printk(KERN_ERR "... disabling SMP support. "
  557. "(tell your hw vendor)\n");
  558. return;
  559. }
  560. if (early)
  561. return;
  562. #ifdef CONFIG_X86_IO_APIC
  563. /*
  564. * If there are no explicit MP IRQ entries, then we are
  565. * broken. We set up most of the low 16 IO-APIC pins to
  566. * ISA defaults and hope it will work.
  567. */
  568. if (!mp_irq_entries) {
  569. struct mpc_bus bus;
  570. printk(KERN_ERR "BIOS bug, no explicit IRQ entries, "
  571. "using default mptable. "
  572. "(tell your hw vendor)\n");
  573. bus.mpc_type = MP_BUS;
  574. bus.mpc_busid = 0;
  575. memcpy(bus.mpc_bustype, "ISA ", 6);
  576. MP_bus_info(&bus);
  577. construct_default_ioirq_mptable(0);
  578. }
  579. #endif
  580. } else
  581. BUG();
  582. if (!early)
  583. printk(KERN_INFO "Processors: %d\n", num_processors);
  584. /*
  585. * Only use the first configuration found.
  586. */
  587. }
  588. void __init early_get_smp_config(void)
  589. {
  590. __get_smp_config(1);
  591. }
  592. void __init get_smp_config(void)
  593. {
  594. __get_smp_config(0);
  595. }
  596. static int __init smp_scan_config(unsigned long base, unsigned long length,
  597. unsigned reserve)
  598. {
  599. unsigned int *bp = phys_to_virt(base);
  600. struct intel_mp_floating *mpf;
  601. apic_printk(APIC_VERBOSE, "Scan SMP from %p for %ld bytes.\n",
  602. 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. printk(KERN_INFO "found SMP MP-table at [%p] %08lx\n",
  616. mpf, virt_to_phys(mpf));
  617. if (!reserve)
  618. return 1;
  619. reserve_bootmem_generic(virt_to_phys(mpf), PAGE_SIZE,
  620. BOOTMEM_DEFAULT);
  621. if (mpf->mpf_physptr) {
  622. unsigned long size = PAGE_SIZE;
  623. #ifdef CONFIG_X86_32
  624. /*
  625. * We cannot access to MPC table to compute
  626. * table size yet, as only few megabytes from
  627. * the bottom is mapped now.
  628. * PC-9800's MPC table places on the very last
  629. * of physical memory; so that simply reserving
  630. * PAGE_SIZE from mpg->mpf_physptr yields BUG()
  631. * in reserve_bootmem.
  632. */
  633. unsigned long end = max_low_pfn * PAGE_SIZE;
  634. if (mpf->mpf_physptr + size > end)
  635. size = end - mpf->mpf_physptr;
  636. #endif
  637. reserve_bootmem_generic(mpf->mpf_physptr, size,
  638. BOOTMEM_DEFAULT);
  639. }
  640. return 1;
  641. }
  642. bp += 4;
  643. length -= 16;
  644. }
  645. return 0;
  646. }
  647. static void __init __find_smp_config(unsigned int reserve)
  648. {
  649. unsigned int address;
  650. if (x86_quirks->mach_find_smp_config) {
  651. if (x86_quirks->mach_find_smp_config(reserve))
  652. return;
  653. }
  654. /*
  655. * FIXME: Linux assumes you have 640K of base ram..
  656. * this continues the error...
  657. *
  658. * 1) Scan the bottom 1K for a signature
  659. * 2) Scan the top 1K of base RAM
  660. * 3) Scan the 64K of bios
  661. */
  662. if (smp_scan_config(0x0, 0x400, reserve) ||
  663. smp_scan_config(639 * 0x400, 0x400, reserve) ||
  664. smp_scan_config(0xF0000, 0x10000, reserve))
  665. return;
  666. /*
  667. * If it is an SMP machine we should know now, unless the
  668. * configuration is in an EISA/MCA bus machine with an
  669. * extended bios data area.
  670. *
  671. * there is a real-mode segmented pointer pointing to the
  672. * 4K EBDA area at 0x40E, calculate and scan it here.
  673. *
  674. * NOTE! There are Linux loaders that will corrupt the EBDA
  675. * area, and as such this kind of SMP config may be less
  676. * trustworthy, simply because the SMP table may have been
  677. * stomped on during early boot. These loaders are buggy and
  678. * should be fixed.
  679. *
  680. * MP1.4 SPEC states to only scan first 1K of 4K EBDA.
  681. */
  682. address = get_bios_ebda();
  683. if (address)
  684. smp_scan_config(address, 0x400, reserve);
  685. }
  686. void __init early_find_smp_config(void)
  687. {
  688. __find_smp_config(0);
  689. }
  690. void __init find_smp_config(void)
  691. {
  692. __find_smp_config(1);
  693. }
  694. #ifdef CONFIG_X86_IO_APIC
  695. static u8 __initdata irq_used[MAX_IRQ_SOURCES];
  696. static int __init get_MP_intsrc_index(struct mpc_intsrc *m)
  697. {
  698. int i;
  699. if (m->mpc_irqtype != mp_INT)
  700. return 0;
  701. if (m->mpc_irqflag != 0x0f)
  702. return 0;
  703. /* not legacy */
  704. for (i = 0; i < mp_irq_entries; i++) {
  705. if (mp_irqs[i].mp_irqtype != mp_INT)
  706. continue;
  707. if (mp_irqs[i].mp_irqflag != 0x0f)
  708. continue;
  709. if (mp_irqs[i].mp_srcbus != m->mpc_srcbus)
  710. continue;
  711. if (mp_irqs[i].mp_srcbusirq != m->mpc_srcbusirq)
  712. continue;
  713. if (irq_used[i]) {
  714. /* already claimed */
  715. return -2;
  716. }
  717. irq_used[i] = 1;
  718. return i;
  719. }
  720. /* not found */
  721. return -1;
  722. }
  723. #define SPARE_SLOT_NUM 20
  724. static struct mpc_intsrc __initdata *m_spare[SPARE_SLOT_NUM];
  725. #endif
  726. static int __init replace_intsrc_all(struct mpc_table *mpc,
  727. unsigned long mpc_new_phys,
  728. unsigned long mpc_new_length)
  729. {
  730. #ifdef CONFIG_X86_IO_APIC
  731. int i;
  732. int nr_m_spare = 0;
  733. #endif
  734. int count = sizeof(*mpc);
  735. unsigned char *mpt = ((unsigned char *)mpc) + count;
  736. printk(KERN_INFO "mpc_length %x\n", mpc->mpc_length);
  737. while (count < mpc->mpc_length) {
  738. switch (*mpt) {
  739. case MP_PROCESSOR:
  740. {
  741. struct mpc_cpu *m = (struct mpc_cpu *)mpt;
  742. mpt += sizeof(*m);
  743. count += sizeof(*m);
  744. break;
  745. }
  746. case MP_BUS:
  747. {
  748. struct mpc_bus *m = (struct mpc_bus *)mpt;
  749. mpt += sizeof(*m);
  750. count += sizeof(*m);
  751. break;
  752. }
  753. case MP_IOAPIC:
  754. {
  755. mpt += sizeof(struct mpc_ioapic);
  756. count += sizeof(struct mpc_ioapic);
  757. break;
  758. }
  759. case MP_INTSRC:
  760. {
  761. #ifdef CONFIG_X86_IO_APIC
  762. struct mpc_intsrc *m = (struct mpc_intsrc *)mpt;
  763. printk(KERN_INFO "OLD ");
  764. print_MP_intsrc_info(m);
  765. i = get_MP_intsrc_index(m);
  766. if (i > 0) {
  767. assign_to_mpc_intsrc(&mp_irqs[i], m);
  768. printk(KERN_INFO "NEW ");
  769. print_mp_irq_info(&mp_irqs[i]);
  770. } else if (!i) {
  771. /* legacy, do nothing */
  772. } else if (nr_m_spare < SPARE_SLOT_NUM) {
  773. /*
  774. * not found (-1), or duplicated (-2)
  775. * are invalid entries,
  776. * we need to use the slot later
  777. */
  778. m_spare[nr_m_spare] = m;
  779. nr_m_spare++;
  780. }
  781. #endif
  782. mpt += sizeof(struct mpc_intsrc);
  783. count += sizeof(struct mpc_intsrc);
  784. break;
  785. }
  786. case MP_LINTSRC:
  787. {
  788. struct mpc_lintsrc *m =
  789. (struct mpc_lintsrc *)mpt;
  790. mpt += sizeof(*m);
  791. count += sizeof(*m);
  792. break;
  793. }
  794. default:
  795. /* wrong mptable */
  796. printk(KERN_ERR "Your mptable is wrong, contact your HW vendor!\n");
  797. printk(KERN_ERR "type %x\n", *mpt);
  798. print_hex_dump(KERN_ERR, " ", DUMP_PREFIX_ADDRESS, 16,
  799. 1, mpc, mpc->mpc_length, 1);
  800. goto out;
  801. }
  802. }
  803. #ifdef CONFIG_X86_IO_APIC
  804. for (i = 0; i < mp_irq_entries; i++) {
  805. if (irq_used[i])
  806. continue;
  807. if (mp_irqs[i].mp_irqtype != mp_INT)
  808. continue;
  809. if (mp_irqs[i].mp_irqflag != 0x0f)
  810. continue;
  811. if (nr_m_spare > 0) {
  812. printk(KERN_INFO "*NEW* found ");
  813. nr_m_spare--;
  814. assign_to_mpc_intsrc(&mp_irqs[i], m_spare[nr_m_spare]);
  815. m_spare[nr_m_spare] = NULL;
  816. } else {
  817. struct mpc_intsrc *m = (struct mpc_intsrc *)mpt;
  818. count += sizeof(struct mpc_intsrc);
  819. if (!mpc_new_phys) {
  820. printk(KERN_INFO "No spare slots, try to append...take your risk, new mpc_length %x\n", count);
  821. } else {
  822. if (count <= mpc_new_length)
  823. printk(KERN_INFO "No spare slots, try to append..., new mpc_length %x\n", count);
  824. else {
  825. printk(KERN_ERR "mpc_new_length %lx is too small\n", mpc_new_length);
  826. goto out;
  827. }
  828. }
  829. assign_to_mpc_intsrc(&mp_irqs[i], m);
  830. mpc->mpc_length = count;
  831. mpt += sizeof(struct mpc_intsrc);
  832. }
  833. print_mp_irq_info(&mp_irqs[i]);
  834. }
  835. #endif
  836. out:
  837. /* update checksum */
  838. mpc->mpc_checksum = 0;
  839. mpc->mpc_checksum -= mpf_checksum((unsigned char *)mpc,
  840. mpc->mpc_length);
  841. return 0;
  842. }
  843. static int __initdata enable_update_mptable;
  844. static int __init update_mptable_setup(char *str)
  845. {
  846. enable_update_mptable = 1;
  847. return 0;
  848. }
  849. early_param("update_mptable", update_mptable_setup);
  850. static unsigned long __initdata mpc_new_phys;
  851. static unsigned long mpc_new_length __initdata = 4096;
  852. /* alloc_mptable or alloc_mptable=4k */
  853. static int __initdata alloc_mptable;
  854. static int __init parse_alloc_mptable_opt(char *p)
  855. {
  856. enable_update_mptable = 1;
  857. alloc_mptable = 1;
  858. if (!p)
  859. return 0;
  860. mpc_new_length = memparse(p, &p);
  861. return 0;
  862. }
  863. early_param("alloc_mptable", parse_alloc_mptable_opt);
  864. void __init early_reserve_e820_mpc_new(void)
  865. {
  866. if (enable_update_mptable && alloc_mptable) {
  867. u64 startt = 0;
  868. #ifdef CONFIG_X86_TRAMPOLINE
  869. startt = TRAMPOLINE_BASE;
  870. #endif
  871. mpc_new_phys = early_reserve_e820(startt, mpc_new_length, 4);
  872. }
  873. }
  874. static int __init update_mp_table(void)
  875. {
  876. char str[16];
  877. char oem[10];
  878. struct intel_mp_floating *mpf;
  879. struct mpc_table *mpc, *mpc_new;
  880. if (!enable_update_mptable)
  881. return 0;
  882. mpf = mpf_found;
  883. if (!mpf)
  884. return 0;
  885. /*
  886. * Now see if we need to go further.
  887. */
  888. if (mpf->mpf_feature1 != 0)
  889. return 0;
  890. if (!mpf->mpf_physptr)
  891. return 0;
  892. mpc = phys_to_virt(mpf->mpf_physptr);
  893. if (!smp_check_mpc(mpc, oem, str))
  894. return 0;
  895. printk(KERN_INFO "mpf: %lx\n", virt_to_phys(mpf));
  896. printk(KERN_INFO "mpf_physptr: %x\n", mpf->mpf_physptr);
  897. if (mpc_new_phys && mpc->mpc_length > mpc_new_length) {
  898. mpc_new_phys = 0;
  899. printk(KERN_INFO "mpc_new_length is %ld, please use alloc_mptable=8k\n",
  900. mpc_new_length);
  901. }
  902. if (!mpc_new_phys) {
  903. unsigned char old, new;
  904. /* check if we can change the postion */
  905. mpc->mpc_checksum = 0;
  906. old = mpf_checksum((unsigned char *)mpc, mpc->mpc_length);
  907. mpc->mpc_checksum = 0xff;
  908. new = mpf_checksum((unsigned char *)mpc, mpc->mpc_length);
  909. if (old == new) {
  910. printk(KERN_INFO "mpc is readonly, please try alloc_mptable instead\n");
  911. return 0;
  912. }
  913. printk(KERN_INFO "use in-positon replacing\n");
  914. } else {
  915. mpf->mpf_physptr = mpc_new_phys;
  916. mpc_new = phys_to_virt(mpc_new_phys);
  917. memcpy(mpc_new, mpc, mpc->mpc_length);
  918. mpc = mpc_new;
  919. /* check if we can modify that */
  920. if (mpc_new_phys - mpf->mpf_physptr) {
  921. struct intel_mp_floating *mpf_new;
  922. /* steal 16 bytes from [0, 1k) */
  923. printk(KERN_INFO "mpf new: %x\n", 0x400 - 16);
  924. mpf_new = phys_to_virt(0x400 - 16);
  925. memcpy(mpf_new, mpf, 16);
  926. mpf = mpf_new;
  927. mpf->mpf_physptr = mpc_new_phys;
  928. }
  929. mpf->mpf_checksum = 0;
  930. mpf->mpf_checksum -= mpf_checksum((unsigned char *)mpf, 16);
  931. printk(KERN_INFO "mpf_physptr new: %x\n", mpf->mpf_physptr);
  932. }
  933. /*
  934. * only replace the one with mp_INT and
  935. * MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
  936. * already in mp_irqs , stored by ... and mp_config_acpi_gsi,
  937. * may need pci=routeirq for all coverage
  938. */
  939. replace_intsrc_all(mpc, mpc_new_phys, mpc_new_length);
  940. return 0;
  941. }
  942. late_initcall(update_mp_table);