mpparse.c 25 KB

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