mpparse_64.c 25 KB

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