mpparse_64.c 22 KB

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