mpparse_64.c 22 KB

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