mpparse_32.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062
  1. /*
  2. * Intel Multiprocessor Specification 1.1 and 1.4
  3. * compliant MP-table parsing routines.
  4. *
  5. * (c) 1995 Alan Cox, Building #3 <alan@redhat.com>
  6. * (c) 1998, 1999, 2000 Ingo Molnar <mingo@redhat.com>
  7. *
  8. * Fixes
  9. * Erich Boleyn : MP v1.4 and additional changes.
  10. * Alan Cox : Added EBDA scanning
  11. * Ingo Molnar : various cleanups and rewrites
  12. * Maciej W. Rozycki: Bits for default MP configurations
  13. * Paul Diefenbaugh: Added full ACPI support
  14. */
  15. #include <linux/mm.h>
  16. #include <linux/init.h>
  17. #include <linux/acpi.h>
  18. #include <linux/delay.h>
  19. #include <linux/bootmem.h>
  20. #include <linux/kernel_stat.h>
  21. #include <linux/mc146818rtc.h>
  22. #include <linux/bitops.h>
  23. #include <asm/smp.h>
  24. #include <asm/acpi.h>
  25. #include <asm/mtrr.h>
  26. #include <asm/mpspec.h>
  27. #include <asm/io_apic.h>
  28. #include <asm/bios_ebda.h>
  29. #include <mach_apic.h>
  30. #include <mach_apicdef.h>
  31. #include <mach_mpparse.h>
  32. /* Have we found an MP table */
  33. int smp_found_config;
  34. /*
  35. * Various Linux-internal data structures created from the
  36. * MP-table.
  37. */
  38. #if defined (CONFIG_MCA) || defined (CONFIG_EISA)
  39. int mp_bus_id_to_type[MAX_MP_BUSSES];
  40. #endif
  41. DECLARE_BITMAP(mp_bus_not_pci, MAX_MP_BUSSES);
  42. int mp_bus_id_to_pci_bus[MAX_MP_BUSSES] = {[0 ... MAX_MP_BUSSES - 1] = -1 };
  43. static int mp_current_pci_id;
  44. int pic_mode;
  45. /*
  46. * Intel MP BIOS table parsing routines:
  47. */
  48. /*
  49. * Checksum an MP configuration block.
  50. */
  51. static int __init mpf_checksum(unsigned char *mp, int len)
  52. {
  53. int sum = 0;
  54. while (len--)
  55. sum += *mp++;
  56. return sum & 0xFF;
  57. }
  58. #ifdef CONFIG_X86_NUMAQ
  59. /*
  60. * Have to match translation table entries to main table entries by counter
  61. * hence the mpc_record variable .... can't see a less disgusting way of
  62. * doing this ....
  63. */
  64. static int mpc_record;
  65. static struct mpc_config_translation *translation_table[MAX_MPC_ENTRY]
  66. __cpuinitdata;
  67. #endif
  68. static void __cpuinit MP_processor_info(struct mpc_config_processor *m)
  69. {
  70. int apicid;
  71. char *bootup_cpu = "";
  72. if (!(m->mpc_cpuflag & CPU_ENABLED)) {
  73. disabled_cpus++;
  74. return;
  75. }
  76. #ifdef CONFIG_X86_NUMAQ
  77. apicid = mpc_apic_id(m, translation_table[mpc_record]);
  78. #else
  79. apicid = m->mpc_apicid;
  80. #endif
  81. if (m->mpc_cpuflag & CPU_BOOTPROCESSOR) {
  82. bootup_cpu = " (Bootup-CPU)";
  83. boot_cpu_physical_apicid = m->mpc_apicid;
  84. }
  85. printk(KERN_INFO "Processor #%d%s\n", m->mpc_apicid, bootup_cpu);
  86. generic_processor_info(apicid, m->mpc_apicver);
  87. }
  88. static void __init MP_bus_info(struct mpc_config_bus *m)
  89. {
  90. char str[7];
  91. memcpy(str, m->mpc_bustype, 6);
  92. str[6] = 0;
  93. #ifdef CONFIG_X86_NUMAQ
  94. mpc_oem_bus_info(m, str, translation_table[mpc_record]);
  95. #else
  96. Dprintk("Bus #%d is %s\n", m->mpc_busid, str);
  97. #endif
  98. #if MAX_MP_BUSSES < 256
  99. if (m->mpc_busid >= MAX_MP_BUSSES) {
  100. printk(KERN_WARNING "MP table busid value (%d) for bustype %s "
  101. " is too large, max. supported is %d\n",
  102. m->mpc_busid, str, MAX_MP_BUSSES - 1);
  103. return;
  104. }
  105. #endif
  106. set_bit(m->mpc_busid, mp_bus_not_pci);
  107. if (strncmp(str, BUSTYPE_PCI, sizeof(BUSTYPE_PCI) - 1) == 0) {
  108. #ifdef CONFIG_X86_NUMAQ
  109. mpc_oem_pci_bus(m, translation_table[mpc_record]);
  110. #endif
  111. clear_bit(m->mpc_busid, mp_bus_not_pci);
  112. mp_bus_id_to_pci_bus[m->mpc_busid] = mp_current_pci_id;
  113. mp_current_pci_id++;
  114. #if defined(CONFIG_EISA) || defined (CONFIG_MCA)
  115. mp_bus_id_to_type[m->mpc_busid] = MP_BUS_PCI;
  116. } else if (strncmp(str, BUSTYPE_ISA, sizeof(BUSTYPE_ISA) - 1) == 0) {
  117. mp_bus_id_to_type[m->mpc_busid] = MP_BUS_ISA;
  118. } else if (strncmp(str, BUSTYPE_EISA, sizeof(BUSTYPE_EISA) - 1) == 0) {
  119. mp_bus_id_to_type[m->mpc_busid] = MP_BUS_EISA;
  120. } else if (strncmp(str, BUSTYPE_MCA, sizeof(BUSTYPE_MCA) - 1) == 0) {
  121. mp_bus_id_to_type[m->mpc_busid] = MP_BUS_MCA;
  122. } else {
  123. printk(KERN_WARNING "Unknown bustype %s - ignoring\n", str);
  124. #endif
  125. }
  126. }
  127. #ifdef CONFIG_X86_IO_APIC
  128. static int bad_ioapic(unsigned long address)
  129. {
  130. if (nr_ioapics >= MAX_IO_APICS) {
  131. printk(KERN_ERR "ERROR: Max # of I/O APICs (%d) exceeded "
  132. "(found %d)\n", MAX_IO_APICS, nr_ioapics);
  133. panic("Recompile kernel with bigger MAX_IO_APICS!\n");
  134. }
  135. if (!address) {
  136. printk(KERN_ERR "WARNING: Bogus (zero) I/O APIC address"
  137. " found in table, skipping!\n");
  138. return 1;
  139. }
  140. return 0;
  141. }
  142. static void __init MP_ioapic_info(struct mpc_config_ioapic *m)
  143. {
  144. if (!(m->mpc_flags & MPC_APIC_USABLE))
  145. return;
  146. printk(KERN_INFO "I/O APIC #%d Version %d at 0x%X.\n",
  147. m->mpc_apicid, m->mpc_apicver, m->mpc_apicaddr);
  148. if (bad_ioapic(m->mpc_apicaddr))
  149. return;
  150. mp_ioapics[nr_ioapics] = *m;
  151. nr_ioapics++;
  152. }
  153. static void __init MP_intsrc_info(struct mpc_config_intsrc *m)
  154. {
  155. mp_irqs[mp_irq_entries] = *m;
  156. Dprintk("Int: type %d, pol %d, trig %d, bus %d,"
  157. " IRQ %02x, APIC ID %x, APIC INT %02x\n",
  158. m->mpc_irqtype, m->mpc_irqflag & 3,
  159. (m->mpc_irqflag >> 2) & 3, m->mpc_srcbus,
  160. m->mpc_srcbusirq, m->mpc_dstapic, m->mpc_dstirq);
  161. if (++mp_irq_entries == MAX_IRQ_SOURCES)
  162. panic("Max # of irq sources exceeded!!\n");
  163. }
  164. #endif
  165. static void __init MP_lintsrc_info(struct mpc_config_lintsrc *m)
  166. {
  167. Dprintk("Lint: type %d, pol %d, trig %d, bus %d,"
  168. " IRQ %02x, APIC ID %x, APIC LINT %02x\n",
  169. m->mpc_irqtype, m->mpc_irqflag & 3,
  170. (m->mpc_irqflag >> 2) & 3, m->mpc_srcbusid,
  171. m->mpc_srcbusirq, m->mpc_destapic, m->mpc_destapiclint);
  172. }
  173. #ifdef CONFIG_X86_NUMAQ
  174. static void __init MP_translation_info(struct mpc_config_translation *m)
  175. {
  176. printk(KERN_INFO
  177. "Translation: record %d, type %d, quad %d, global %d, local %d\n",
  178. mpc_record, m->trans_type, m->trans_quad, m->trans_global,
  179. m->trans_local);
  180. if (mpc_record >= MAX_MPC_ENTRY)
  181. printk(KERN_ERR "MAX_MPC_ENTRY exceeded!\n");
  182. else
  183. translation_table[mpc_record] = m; /* stash this for later */
  184. if (m->trans_quad < MAX_NUMNODES && !node_online(m->trans_quad))
  185. node_set_online(m->trans_quad);
  186. }
  187. /*
  188. * Read/parse the MPC oem tables
  189. */
  190. static void __init smp_read_mpc_oem(struct mp_config_oemtable *oemtable,
  191. unsigned short oemsize)
  192. {
  193. int count = sizeof(*oemtable); /* the header size */
  194. unsigned char *oemptr = ((unsigned char *)oemtable) + count;
  195. mpc_record = 0;
  196. printk(KERN_INFO "Found an OEM MPC table at %8p - parsing it ... \n",
  197. oemtable);
  198. if (memcmp(oemtable->oem_signature, MPC_OEM_SIGNATURE, 4)) {
  199. printk(KERN_WARNING
  200. "SMP mpc oemtable: bad signature [%c%c%c%c]!\n",
  201. oemtable->oem_signature[0], oemtable->oem_signature[1],
  202. oemtable->oem_signature[2], oemtable->oem_signature[3]);
  203. return;
  204. }
  205. if (mpf_checksum((unsigned char *)oemtable, oemtable->oem_length)) {
  206. printk(KERN_WARNING "SMP oem mptable: checksum error!\n");
  207. return;
  208. }
  209. while (count < oemtable->oem_length) {
  210. switch (*oemptr) {
  211. case MP_TRANSLATION:
  212. {
  213. struct mpc_config_translation *m =
  214. (struct mpc_config_translation *)oemptr;
  215. MP_translation_info(m);
  216. oemptr += sizeof(*m);
  217. count += sizeof(*m);
  218. ++mpc_record;
  219. break;
  220. }
  221. default:
  222. {
  223. printk(KERN_WARNING
  224. "Unrecognised OEM table entry type! - %d\n",
  225. (int)*oemptr);
  226. return;
  227. }
  228. }
  229. }
  230. }
  231. static inline void mps_oem_check(struct mp_config_table *mpc, char *oem,
  232. char *productid)
  233. {
  234. if (strncmp(oem, "IBM NUMA", 8))
  235. printk("Warning! May not be a NUMA-Q system!\n");
  236. if (mpc->mpc_oemptr)
  237. smp_read_mpc_oem((struct mp_config_oemtable *)mpc->mpc_oemptr,
  238. mpc->mpc_oemsize);
  239. }
  240. #endif /* CONFIG_X86_NUMAQ */
  241. /*
  242. * Read/parse the MPC
  243. */
  244. static int __init smp_read_mpc(struct mp_config_table *mpc, unsigned early)
  245. {
  246. char str[16];
  247. char oem[10];
  248. int count = sizeof(*mpc);
  249. unsigned char *mpt = ((unsigned char *)mpc) + count;
  250. if (memcmp(mpc->mpc_signature, MPC_SIGNATURE, 4)) {
  251. printk(KERN_ERR "SMP mptable: bad signature [0x%x]!\n",
  252. *(u32 *) mpc->mpc_signature);
  253. return 0;
  254. }
  255. if (mpf_checksum((unsigned char *)mpc, mpc->mpc_length)) {
  256. printk(KERN_ERR "SMP mptable: checksum error!\n");
  257. return 0;
  258. }
  259. if (mpc->mpc_spec != 0x01 && mpc->mpc_spec != 0x04) {
  260. printk(KERN_ERR "SMP mptable: bad table version (%d)!!\n",
  261. mpc->mpc_spec);
  262. return 0;
  263. }
  264. if (!mpc->mpc_lapic) {
  265. printk(KERN_ERR "SMP mptable: null local APIC address!\n");
  266. return 0;
  267. }
  268. memcpy(oem, mpc->mpc_oem, 8);
  269. oem[8] = 0;
  270. printk(KERN_INFO "OEM ID: %s ", oem);
  271. memcpy(str, mpc->mpc_productid, 12);
  272. str[12] = 0;
  273. printk("Product ID: %s ", str);
  274. mps_oem_check(mpc, oem, str);
  275. printk("APIC at: 0x%X\n", mpc->mpc_lapic);
  276. /*
  277. * Save the local APIC address (it might be non-default) -- but only
  278. * if we're not using ACPI.
  279. */
  280. if (!acpi_lapic)
  281. mp_lapic_addr = mpc->mpc_lapic;
  282. if (early)
  283. return 1;
  284. /*
  285. * Now process the configuration blocks.
  286. */
  287. #ifdef CONFIG_X86_NUMAQ
  288. mpc_record = 0;
  289. #endif
  290. while (count < mpc->mpc_length) {
  291. switch (*mpt) {
  292. case MP_PROCESSOR:
  293. {
  294. struct mpc_config_processor *m =
  295. (struct mpc_config_processor *)mpt;
  296. /* ACPI may have already provided this data */
  297. if (!acpi_lapic)
  298. MP_processor_info(m);
  299. mpt += sizeof(*m);
  300. count += sizeof(*m);
  301. break;
  302. }
  303. case MP_BUS:
  304. {
  305. struct mpc_config_bus *m =
  306. (struct mpc_config_bus *)mpt;
  307. MP_bus_info(m);
  308. mpt += sizeof(*m);
  309. count += sizeof(*m);
  310. break;
  311. }
  312. case MP_IOAPIC:
  313. {
  314. #ifdef CONFIG_X86_IO_APIC
  315. struct mpc_config_ioapic *m =
  316. (struct mpc_config_ioapic *)mpt;
  317. MP_ioapic_info(m);
  318. #endif
  319. mpt += sizeof(struct mpc_config_ioapic);
  320. count += sizeof(struct mpc_config_ioapic);
  321. break;
  322. }
  323. case MP_INTSRC:
  324. {
  325. #ifdef CONFIG_X86_IO_APIC
  326. struct mpc_config_intsrc *m =
  327. (struct mpc_config_intsrc *)mpt;
  328. MP_intsrc_info(m);
  329. #endif
  330. mpt += sizeof(struct mpc_config_intsrc);
  331. count += sizeof(struct mpc_config_intsrc);
  332. break;
  333. }
  334. case MP_LINTSRC:
  335. {
  336. struct mpc_config_lintsrc *m =
  337. (struct mpc_config_lintsrc *)mpt;
  338. MP_lintsrc_info(m);
  339. mpt += sizeof(*m);
  340. count += sizeof(*m);
  341. break;
  342. }
  343. default:
  344. {
  345. count = mpc->mpc_length;
  346. break;
  347. }
  348. }
  349. #ifdef CONFIG_X86_NUMAQ
  350. ++mpc_record;
  351. #endif
  352. }
  353. setup_apic_routing();
  354. if (!num_processors)
  355. printk(KERN_ERR "SMP mptable: no processors registered!\n");
  356. return num_processors;
  357. }
  358. #ifdef CONFIG_X86_IO_APIC
  359. static int __init ELCR_trigger(unsigned int irq)
  360. {
  361. unsigned int port;
  362. port = 0x4d0 + (irq >> 3);
  363. return (inb(port) >> (irq & 7)) & 1;
  364. }
  365. static void __init construct_default_ioirq_mptable(int mpc_default_type)
  366. {
  367. struct mpc_config_intsrc intsrc;
  368. int i;
  369. int ELCR_fallback = 0;
  370. intsrc.mpc_type = MP_INTSRC;
  371. intsrc.mpc_irqflag = 0; /* conforming */
  372. intsrc.mpc_srcbus = 0;
  373. intsrc.mpc_dstapic = mp_ioapics[0].mpc_apicid;
  374. intsrc.mpc_irqtype = mp_INT;
  375. /*
  376. * If true, we have an ISA/PCI system with no IRQ entries
  377. * in the MP table. To prevent the PCI interrupts from being set up
  378. * incorrectly, we try to use the ELCR. The sanity check to see if
  379. * there is good ELCR data is very simple - IRQ0, 1, 2 and 13 can
  380. * never be level sensitive, so we simply see if the ELCR agrees.
  381. * If it does, we assume it's valid.
  382. */
  383. if (mpc_default_type == 5) {
  384. printk(KERN_INFO
  385. "ISA/PCI bus type with no IRQ information... falling back to ELCR\n");
  386. if (ELCR_trigger(0) || ELCR_trigger(1) || ELCR_trigger(2)
  387. || ELCR_trigger(13))
  388. printk(KERN_WARNING
  389. "ELCR contains invalid data... not using ELCR\n");
  390. else {
  391. printk(KERN_INFO
  392. "Using ELCR to identify PCI interrupts\n");
  393. ELCR_fallback = 1;
  394. }
  395. }
  396. for (i = 0; i < 16; i++) {
  397. switch (mpc_default_type) {
  398. case 2:
  399. if (i == 0 || i == 13)
  400. continue; /* IRQ0 & IRQ13 not connected */
  401. /* fall through */
  402. default:
  403. if (i == 2)
  404. continue; /* IRQ2 is never connected */
  405. }
  406. if (ELCR_fallback) {
  407. /*
  408. * If the ELCR indicates a level-sensitive interrupt, we
  409. * copy that information over to the MP table in the
  410. * irqflag field (level sensitive, active high polarity).
  411. */
  412. if (ELCR_trigger(i))
  413. intsrc.mpc_irqflag = 13;
  414. else
  415. intsrc.mpc_irqflag = 0;
  416. }
  417. intsrc.mpc_srcbusirq = i;
  418. intsrc.mpc_dstirq = i ? i : 2; /* IRQ0 to INTIN2 */
  419. MP_intsrc_info(&intsrc);
  420. }
  421. intsrc.mpc_irqtype = mp_ExtINT;
  422. intsrc.mpc_srcbusirq = 0;
  423. intsrc.mpc_dstirq = 0; /* 8259A to INTIN0 */
  424. MP_intsrc_info(&intsrc);
  425. }
  426. #endif
  427. static inline void __init construct_default_ISA_mptable(int mpc_default_type)
  428. {
  429. struct mpc_config_processor processor;
  430. struct mpc_config_bus bus;
  431. #ifdef CONFIG_X86_IO_APIC
  432. struct mpc_config_ioapic ioapic;
  433. #endif
  434. struct mpc_config_lintsrc lintsrc;
  435. int linttypes[2] = { mp_ExtINT, mp_NMI };
  436. int i;
  437. /*
  438. * local APIC has default address
  439. */
  440. mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
  441. /*
  442. * 2 CPUs, numbered 0 & 1.
  443. */
  444. processor.mpc_type = MP_PROCESSOR;
  445. /* Either an integrated APIC or a discrete 82489DX. */
  446. processor.mpc_apicver = mpc_default_type > 4 ? 0x10 : 0x01;
  447. processor.mpc_cpuflag = CPU_ENABLED;
  448. processor.mpc_cpufeature = (boot_cpu_data.x86 << 8) |
  449. (boot_cpu_data.x86_model << 4) | boot_cpu_data.x86_mask;
  450. processor.mpc_featureflag = boot_cpu_data.x86_capability[0];
  451. processor.mpc_reserved[0] = 0;
  452. processor.mpc_reserved[1] = 0;
  453. for (i = 0; i < 2; i++) {
  454. processor.mpc_apicid = i;
  455. MP_processor_info(&processor);
  456. }
  457. bus.mpc_type = MP_BUS;
  458. bus.mpc_busid = 0;
  459. switch (mpc_default_type) {
  460. default:
  461. printk("???\n");
  462. printk(KERN_ERR "Unknown standard configuration %d\n",
  463. mpc_default_type);
  464. /* fall through */
  465. case 1:
  466. case 5:
  467. memcpy(bus.mpc_bustype, "ISA ", 6);
  468. break;
  469. case 2:
  470. case 6:
  471. case 3:
  472. memcpy(bus.mpc_bustype, "EISA ", 6);
  473. break;
  474. case 4:
  475. case 7:
  476. memcpy(bus.mpc_bustype, "MCA ", 6);
  477. }
  478. MP_bus_info(&bus);
  479. if (mpc_default_type > 4) {
  480. bus.mpc_busid = 1;
  481. memcpy(bus.mpc_bustype, "PCI ", 6);
  482. MP_bus_info(&bus);
  483. }
  484. #ifdef CONFIG_X86_IO_APIC
  485. ioapic.mpc_type = MP_IOAPIC;
  486. ioapic.mpc_apicid = 2;
  487. ioapic.mpc_apicver = mpc_default_type > 4 ? 0x10 : 0x01;
  488. ioapic.mpc_flags = MPC_APIC_USABLE;
  489. ioapic.mpc_apicaddr = 0xFEC00000;
  490. MP_ioapic_info(&ioapic);
  491. /*
  492. * We set up most of the low 16 IO-APIC pins according to MPS rules.
  493. */
  494. construct_default_ioirq_mptable(mpc_default_type);
  495. #endif
  496. lintsrc.mpc_type = MP_LINTSRC;
  497. lintsrc.mpc_irqflag = 0; /* conforming */
  498. lintsrc.mpc_srcbusid = 0;
  499. lintsrc.mpc_srcbusirq = 0;
  500. lintsrc.mpc_destapic = MP_APIC_ALL;
  501. for (i = 0; i < 2; i++) {
  502. lintsrc.mpc_irqtype = linttypes[i];
  503. lintsrc.mpc_destapiclint = i;
  504. MP_lintsrc_info(&lintsrc);
  505. }
  506. }
  507. static struct intel_mp_floating *mpf_found;
  508. /*
  509. * Scan the memory blocks for an SMP configuration block.
  510. */
  511. static void __init __get_smp_config(unsigned early)
  512. {
  513. struct intel_mp_floating *mpf = mpf_found;
  514. if (acpi_lapic && early)
  515. return;
  516. /*
  517. * ACPI supports both logical (e.g. Hyper-Threading) and physical
  518. * processors, where MPS only supports physical.
  519. */
  520. if (acpi_lapic && acpi_ioapic) {
  521. printk(KERN_INFO
  522. "Using ACPI (MADT) for SMP configuration information\n");
  523. return;
  524. } else if (acpi_lapic)
  525. printk(KERN_INFO
  526. "Using ACPI for processor (LAPIC) configuration information\n");
  527. printk(KERN_INFO "Intel MultiProcessor Specification v1.%d\n",
  528. mpf->mpf_specification);
  529. if (mpf->mpf_feature2 & (1 << 7)) {
  530. printk(KERN_INFO " IMCR and PIC compatibility mode.\n");
  531. pic_mode = 1;
  532. } else {
  533. printk(KERN_INFO " Virtual Wire compatibility mode.\n");
  534. pic_mode = 0;
  535. }
  536. /*
  537. * Now see if we need to read further.
  538. */
  539. if (mpf->mpf_feature1 != 0) {
  540. if (early) {
  541. /*
  542. * local APIC has default address
  543. */
  544. mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
  545. return;
  546. }
  547. printk(KERN_INFO "Default MP configuration #%d\n",
  548. mpf->mpf_feature1);
  549. construct_default_ISA_mptable(mpf->mpf_feature1);
  550. } else if (mpf->mpf_physptr) {
  551. /*
  552. * Read the physical hardware table. Anything here will
  553. * override the defaults.
  554. */
  555. if (!smp_read_mpc(phys_to_virt(mpf->mpf_physptr), early)) {
  556. smp_found_config = 0;
  557. printk(KERN_ERR
  558. "BIOS bug, MP table errors detected!...\n");
  559. printk(KERN_ERR
  560. "... disabling SMP support. (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_config_bus bus;
  573. printk(KERN_ERR
  574. "BIOS bug, no explicit IRQ entries, using default mptable. (tell your hw vendor)\n");
  575. bus.mpc_type = MP_BUS;
  576. bus.mpc_busid = 0;
  577. memcpy(bus.mpc_bustype, "ISA ", 6);
  578. MP_bus_info(&bus);
  579. construct_default_ioirq_mptable(0);
  580. }
  581. #endif
  582. } else
  583. BUG();
  584. if (!early)
  585. printk(KERN_INFO "Processors: %d\n", num_processors);
  586. /*
  587. * Only use the first configuration found.
  588. */
  589. }
  590. void __init early_get_smp_config(void)
  591. {
  592. __get_smp_config(1);
  593. }
  594. void __init get_smp_config(void)
  595. {
  596. __get_smp_config(0);
  597. }
  598. static int __init smp_scan_config(unsigned long base, unsigned long length,
  599. unsigned reserve)
  600. {
  601. unsigned long *bp = phys_to_virt(base);
  602. struct intel_mp_floating *mpf;
  603. printk(KERN_INFO "Scan SMP from %p for %ld bytes.\n", bp, length);
  604. if (sizeof(*mpf) != 16)
  605. printk("Error: MPF size\n");
  606. while (length > 0) {
  607. mpf = (struct intel_mp_floating *)bp;
  608. if ((*bp == SMP_MAGIC_IDENT) &&
  609. (mpf->mpf_length == 1) &&
  610. !mpf_checksum((unsigned char *)bp, 16) &&
  611. ((mpf->mpf_specification == 1)
  612. || (mpf->mpf_specification == 4))) {
  613. smp_found_config = 1;
  614. printk(KERN_INFO "found SMP MP-table at [%p] %08lx\n",
  615. mpf, virt_to_phys(mpf));
  616. reserve_bootmem(virt_to_phys(mpf), PAGE_SIZE,
  617. BOOTMEM_DEFAULT);
  618. if (mpf->mpf_physptr) {
  619. /*
  620. * We cannot access to MPC table to compute
  621. * table size yet, as only few megabytes from
  622. * the bottom is mapped now.
  623. * PC-9800's MPC table places on the very last
  624. * of physical memory; so that simply reserving
  625. * PAGE_SIZE from mpg->mpf_physptr yields BUG()
  626. * in reserve_bootmem.
  627. */
  628. unsigned long size = PAGE_SIZE;
  629. unsigned long end = max_low_pfn * PAGE_SIZE;
  630. if (mpf->mpf_physptr + size > end)
  631. size = end - mpf->mpf_physptr;
  632. reserve_bootmem(mpf->mpf_physptr, size,
  633. BOOTMEM_DEFAULT);
  634. }
  635. mpf_found = mpf;
  636. return 1;
  637. }
  638. bp += 4;
  639. length -= 16;
  640. }
  641. return 0;
  642. }
  643. static void __init __find_smp_config(unsigned reserve)
  644. {
  645. unsigned int address;
  646. /*
  647. * FIXME: Linux assumes you have 640K of base ram..
  648. * this continues the error...
  649. *
  650. * 1) Scan the bottom 1K for a signature
  651. * 2) Scan the top 1K of base RAM
  652. * 3) Scan the 64K of bios
  653. */
  654. if (smp_scan_config(0x0, 0x400, reserve) ||
  655. smp_scan_config(639 * 0x400, 0x400, reserve) ||
  656. smp_scan_config(0xF0000, 0x10000, reserve))
  657. return;
  658. /*
  659. * If it is an SMP machine we should know now, unless the
  660. * configuration is in an EISA/MCA bus machine with an
  661. * extended bios data area.
  662. *
  663. * there is a real-mode segmented pointer pointing to the
  664. * 4K EBDA area at 0x40E, calculate and scan it here.
  665. *
  666. * NOTE! There are Linux loaders that will corrupt the EBDA
  667. * area, and as such this kind of SMP config may be less
  668. * trustworthy, simply because the SMP table may have been
  669. * stomped on during early boot. These loaders are buggy and
  670. * should be fixed.
  671. *
  672. * MP1.4 SPEC states to only scan first 1K of 4K EBDA.
  673. */
  674. address = get_bios_ebda();
  675. if (address)
  676. smp_scan_config(address, 0x400, reserve);
  677. }
  678. void __init early_find_smp_config(void)
  679. {
  680. __find_smp_config(0);
  681. }
  682. void __init find_smp_config(void)
  683. {
  684. __find_smp_config(1);
  685. }
  686. /* --------------------------------------------------------------------------
  687. ACPI-based MP Configuration
  688. -------------------------------------------------------------------------- */
  689. #ifdef CONFIG_ACPI
  690. #ifdef CONFIG_X86_IO_APIC
  691. #define MP_ISA_BUS 0
  692. #define MP_MAX_IOAPIC_PIN 127
  693. extern struct mp_ioapic_routing mp_ioapic_routing[MAX_IO_APICS];
  694. static int mp_find_ioapic(int gsi)
  695. {
  696. int i = 0;
  697. /* Find the IOAPIC that manages this GSI. */
  698. for (i = 0; i < nr_ioapics; i++) {
  699. if ((gsi >= mp_ioapic_routing[i].gsi_base)
  700. && (gsi <= mp_ioapic_routing[i].gsi_end))
  701. return i;
  702. }
  703. printk(KERN_ERR "ERROR: Unable to locate IOAPIC for GSI %d\n", gsi);
  704. return -1;
  705. }
  706. static u8 uniq_ioapic_id(u8 id)
  707. {
  708. if ((boot_cpu_data.x86_vendor == X86_VENDOR_INTEL) &&
  709. !APIC_XAPIC(apic_version[boot_cpu_physical_apicid]))
  710. return io_apic_get_unique_id(nr_ioapics, id);
  711. else
  712. return id;
  713. }
  714. void __init mp_register_ioapic(int id, u32 address, u32 gsi_base)
  715. {
  716. int idx = 0;
  717. if (bad_ioapic(address))
  718. return;
  719. idx = nr_ioapics;
  720. mp_ioapics[idx].mpc_type = MP_IOAPIC;
  721. mp_ioapics[idx].mpc_flags = MPC_APIC_USABLE;
  722. mp_ioapics[idx].mpc_apicaddr = address;
  723. set_fixmap_nocache(FIX_IO_APIC_BASE_0 + idx, address);
  724. mp_ioapics[idx].mpc_apicid = uniq_ioapic_id(id);
  725. mp_ioapics[idx].mpc_apicver = io_apic_get_version(idx);
  726. /*
  727. * Build basic GSI lookup table to facilitate gsi->io_apic lookups
  728. * and to prevent reprogramming of IOAPIC pins (PCI GSIs).
  729. */
  730. mp_ioapic_routing[idx].apic_id = mp_ioapics[idx].mpc_apicid;
  731. mp_ioapic_routing[idx].gsi_base = gsi_base;
  732. mp_ioapic_routing[idx].gsi_end = gsi_base +
  733. io_apic_get_redir_entries(idx);
  734. printk("IOAPIC[%d]: apic_id %d, version %d, address 0x%x, "
  735. "GSI %d-%d\n", idx, mp_ioapics[idx].mpc_apicid,
  736. mp_ioapics[idx].mpc_apicver,
  737. mp_ioapics[idx].mpc_apicaddr,
  738. mp_ioapic_routing[idx].gsi_base, mp_ioapic_routing[idx].gsi_end);
  739. nr_ioapics++;
  740. }
  741. void __init mp_override_legacy_irq(u8 bus_irq, u8 polarity, u8 trigger, u32 gsi)
  742. {
  743. struct mpc_config_intsrc intsrc;
  744. int ioapic = -1;
  745. int pin = -1;
  746. /*
  747. * Convert 'gsi' to 'ioapic.pin'.
  748. */
  749. ioapic = mp_find_ioapic(gsi);
  750. if (ioapic < 0)
  751. return;
  752. pin = gsi - mp_ioapic_routing[ioapic].gsi_base;
  753. /*
  754. * TBD: This check is for faulty timer entries, where the override
  755. * erroneously sets the trigger to level, resulting in a HUGE
  756. * increase of timer interrupts!
  757. */
  758. if ((bus_irq == 0) && (trigger == 3))
  759. trigger = 1;
  760. intsrc.mpc_type = MP_INTSRC;
  761. intsrc.mpc_irqtype = mp_INT;
  762. intsrc.mpc_irqflag = (trigger << 2) | polarity;
  763. intsrc.mpc_srcbus = MP_ISA_BUS;
  764. intsrc.mpc_srcbusirq = bus_irq; /* IRQ */
  765. intsrc.mpc_dstapic = mp_ioapics[ioapic].mpc_apicid; /* APIC ID */
  766. intsrc.mpc_dstirq = pin; /* INTIN# */
  767. Dprintk("Int: type %d, pol %d, trig %d, bus %d, irq %d, %d-%d\n",
  768. intsrc.mpc_irqtype, intsrc.mpc_irqflag & 3,
  769. (intsrc.mpc_irqflag >> 2) & 3, intsrc.mpc_srcbus,
  770. intsrc.mpc_srcbusirq, intsrc.mpc_dstapic, intsrc.mpc_dstirq);
  771. mp_irqs[mp_irq_entries] = intsrc;
  772. if (++mp_irq_entries == MAX_IRQ_SOURCES)
  773. panic("Max # of irq sources exceeded!\n");
  774. }
  775. int es7000_plat;
  776. void __init mp_config_acpi_legacy_irqs(void)
  777. {
  778. struct mpc_config_intsrc intsrc;
  779. int i = 0;
  780. int ioapic = -1;
  781. #if defined (CONFIG_MCA) || defined (CONFIG_EISA)
  782. /*
  783. * Fabricate the legacy ISA bus (bus #31).
  784. */
  785. mp_bus_id_to_type[MP_ISA_BUS] = MP_BUS_ISA;
  786. #endif
  787. set_bit(MP_ISA_BUS, mp_bus_not_pci);
  788. Dprintk("Bus #%d is ISA\n", MP_ISA_BUS);
  789. /*
  790. * Older generations of ES7000 have no legacy identity mappings
  791. */
  792. if (es7000_plat == 1)
  793. return;
  794. /*
  795. * Locate the IOAPIC that manages the ISA IRQs (0-15).
  796. */
  797. ioapic = mp_find_ioapic(0);
  798. if (ioapic < 0)
  799. return;
  800. intsrc.mpc_type = MP_INTSRC;
  801. intsrc.mpc_irqflag = 0; /* Conforming */
  802. intsrc.mpc_srcbus = MP_ISA_BUS;
  803. #ifdef CONFIG_X86_IO_APIC
  804. intsrc.mpc_dstapic = mp_ioapics[ioapic].mpc_apicid;
  805. #endif
  806. /*
  807. * Use the default configuration for the IRQs 0-15. Unless
  808. * overridden by (MADT) interrupt source override entries.
  809. */
  810. for (i = 0; i < 16; i++) {
  811. int idx;
  812. for (idx = 0; idx < mp_irq_entries; idx++) {
  813. struct mpc_config_intsrc *irq = mp_irqs + idx;
  814. /* Do we already have a mapping for this ISA IRQ? */
  815. if (irq->mpc_srcbus == MP_ISA_BUS
  816. && irq->mpc_srcbusirq == i)
  817. break;
  818. /* Do we already have a mapping for this IOAPIC pin */
  819. if ((irq->mpc_dstapic == intsrc.mpc_dstapic) &&
  820. (irq->mpc_dstirq == i))
  821. break;
  822. }
  823. if (idx != mp_irq_entries) {
  824. printk(KERN_DEBUG "ACPI: IRQ%d used by override.\n", i);
  825. continue; /* IRQ already used */
  826. }
  827. intsrc.mpc_irqtype = mp_INT;
  828. intsrc.mpc_srcbusirq = i; /* Identity mapped */
  829. intsrc.mpc_dstirq = i;
  830. Dprintk("Int: type %d, pol %d, trig %d, bus %d, irq %d, "
  831. "%d-%d\n", intsrc.mpc_irqtype, intsrc.mpc_irqflag & 3,
  832. (intsrc.mpc_irqflag >> 2) & 3, intsrc.mpc_srcbus,
  833. intsrc.mpc_srcbusirq, intsrc.mpc_dstapic,
  834. intsrc.mpc_dstirq);
  835. mp_irqs[mp_irq_entries] = intsrc;
  836. if (++mp_irq_entries == MAX_IRQ_SOURCES)
  837. panic("Max # of irq sources exceeded!\n");
  838. }
  839. }
  840. #define MAX_GSI_NUM 4096
  841. #define IRQ_COMPRESSION_START 64
  842. int mp_register_gsi(u32 gsi, int triggering, int polarity)
  843. {
  844. int ioapic = -1;
  845. int ioapic_pin = 0;
  846. int idx, bit = 0;
  847. static int pci_irq = IRQ_COMPRESSION_START;
  848. /*
  849. * Mapping between Global System Interrupts, which
  850. * represent all possible interrupts, and IRQs
  851. * assigned to actual devices.
  852. */
  853. static int gsi_to_irq[MAX_GSI_NUM];
  854. /* Don't set up the ACPI SCI because it's already set up */
  855. if (acpi_gbl_FADT.sci_interrupt == gsi)
  856. return gsi;
  857. ioapic = mp_find_ioapic(gsi);
  858. if (ioapic < 0) {
  859. printk(KERN_WARNING "No IOAPIC for GSI %u\n", gsi);
  860. return gsi;
  861. }
  862. ioapic_pin = gsi - mp_ioapic_routing[ioapic].gsi_base;
  863. if (ioapic_renumber_irq)
  864. gsi = ioapic_renumber_irq(ioapic, gsi);
  865. /*
  866. * Avoid pin reprogramming. PRTs typically include entries
  867. * with redundant pin->gsi mappings (but unique PCI devices);
  868. * we only program the IOAPIC on the first.
  869. */
  870. bit = ioapic_pin % 32;
  871. idx = (ioapic_pin < 32) ? 0 : (ioapic_pin / 32);
  872. if (idx > 3) {
  873. printk(KERN_ERR "Invalid reference to IOAPIC pin "
  874. "%d-%d\n", mp_ioapic_routing[ioapic].apic_id,
  875. ioapic_pin);
  876. return gsi;
  877. }
  878. if ((1 << bit) & mp_ioapic_routing[ioapic].pin_programmed[idx]) {
  879. Dprintk(KERN_DEBUG "Pin %d-%d already programmed\n",
  880. mp_ioapic_routing[ioapic].apic_id, ioapic_pin);
  881. return (gsi < IRQ_COMPRESSION_START ? gsi : gsi_to_irq[gsi]);
  882. }
  883. mp_ioapic_routing[ioapic].pin_programmed[idx] |= (1 << bit);
  884. /*
  885. * For GSI >= 64, use IRQ compression
  886. */
  887. if ((gsi >= IRQ_COMPRESSION_START)
  888. && (triggering == ACPI_LEVEL_SENSITIVE)) {
  889. /*
  890. * For PCI devices assign IRQs in order, avoiding gaps
  891. * due to unused I/O APIC pins.
  892. */
  893. int irq = gsi;
  894. if (gsi < MAX_GSI_NUM) {
  895. /*
  896. * Retain the VIA chipset work-around (gsi > 15), but
  897. * avoid a problem where the 8254 timer (IRQ0) is setup
  898. * via an override (so it's not on pin 0 of the ioapic),
  899. * and at the same time, the pin 0 interrupt is a PCI
  900. * type. The gsi > 15 test could cause these two pins
  901. * to be shared as IRQ0, and they are not shareable.
  902. * So test for this condition, and if necessary, avoid
  903. * the pin collision.
  904. */
  905. gsi = pci_irq++;
  906. /*
  907. * Don't assign IRQ used by ACPI SCI
  908. */
  909. if (gsi == acpi_gbl_FADT.sci_interrupt)
  910. gsi = pci_irq++;
  911. gsi_to_irq[irq] = gsi;
  912. } else {
  913. printk(KERN_ERR "GSI %u is too high\n", gsi);
  914. return gsi;
  915. }
  916. }
  917. io_apic_set_pci_routing(ioapic, ioapic_pin, gsi,
  918. triggering == ACPI_EDGE_SENSITIVE ? 0 : 1,
  919. polarity == ACPI_ACTIVE_HIGH ? 0 : 1);
  920. return gsi;
  921. }
  922. #endif /* CONFIG_X86_IO_APIC */
  923. #endif /* CONFIG_ACPI */