mpparse.c 25 KB

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