mpparse_64.c 22 KB

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