mpparse.c 24 KB

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