mpparse_64.c 21 KB

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