mpparse.c 22 KB

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