mpparse.c 25 KB

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