mpparse.c 24 KB

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