mpparse.c 24 KB

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