mpparse.c 21 KB

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