mpparse.c 28 KB

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