mpparse_64.c 22 KB

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