mpparse.c 25 KB

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