mpparse_32.c 27 KB

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