mpparse_64.c 22 KB

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