mpparse_32.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146
  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/acpi.h>
  18. #include <linux/delay.h>
  19. #include <linux/bootmem.h>
  20. #include <linux/kernel_stat.h>
  21. #include <linux/mc146818rtc.h>
  22. #include <linux/bitops.h>
  23. #include <asm/smp.h>
  24. #include <asm/acpi.h>
  25. #include <asm/mtrr.h>
  26. #include <asm/mpspec.h>
  27. #include <asm/io_apic.h>
  28. #include <mach_apic.h>
  29. #include <mach_apicdef.h>
  30. #include <mach_mpparse.h>
  31. #include <bios_ebda.h>
  32. /* Have we found an MP table */
  33. int smp_found_config;
  34. unsigned int __cpuinitdata maxcpus = NR_CPUS;
  35. /*
  36. * Various Linux-internal data structures created from the
  37. * MP-table.
  38. */
  39. int apic_version [MAX_APICS];
  40. int mp_bus_id_to_type [MAX_MP_BUSSES];
  41. DECLARE_BITMAP(mp_bus_not_pci, MAX_MP_BUSSES);
  42. int mp_bus_id_to_node [MAX_MP_BUSSES];
  43. int mp_bus_id_to_local [MAX_MP_BUSSES];
  44. int mp_bus_id_to_pci_bus [MAX_MP_BUSSES] = { [0 ... MAX_MP_BUSSES-1] = -1 };
  45. static int mp_current_pci_id;
  46. /* I/O APIC entries */
  47. struct mpc_config_ioapic mp_ioapics[MAX_IO_APICS];
  48. /* # of MP IRQ source entries */
  49. struct mpc_config_intsrc mp_irqs[MAX_IRQ_SOURCES];
  50. /* MP IRQ source entries */
  51. int mp_irq_entries;
  52. int nr_ioapics;
  53. int pic_mode;
  54. unsigned long mp_lapic_addr;
  55. unsigned int def_to_bigsmp = 0;
  56. /* Processor that is doing the boot up */
  57. unsigned int boot_cpu_physical_apicid = -1U;
  58. /* Internal processor count */
  59. unsigned int num_processors;
  60. unsigned disabled_cpus __cpuinitdata;
  61. /* Bitmask of physically existing CPUs */
  62. physid_mask_t phys_cpu_present_map;
  63. u8 bios_cpu_apicid[NR_CPUS] = { [0 ... NR_CPUS-1] = BAD_APICID };
  64. /*
  65. * Intel MP BIOS table parsing routines:
  66. */
  67. /*
  68. * Checksum an MP configuration block.
  69. */
  70. static int __init mpf_checksum(unsigned char *mp, int len)
  71. {
  72. int sum = 0;
  73. while (len--)
  74. sum += *mp++;
  75. return sum & 0xFF;
  76. }
  77. /*
  78. * Have to match translation table entries to main table entries by counter
  79. * hence the mpc_record variable .... can't see a less disgusting way of
  80. * doing this ....
  81. */
  82. static int mpc_record;
  83. static struct mpc_config_translation *translation_table[MAX_MPC_ENTRY] __cpuinitdata;
  84. static void __cpuinit MP_processor_info (struct mpc_config_processor *m)
  85. {
  86. int ver, apicid;
  87. physid_mask_t phys_cpu;
  88. if (!(m->mpc_cpuflag & CPU_ENABLED)) {
  89. disabled_cpus++;
  90. return;
  91. }
  92. apicid = mpc_apic_id(m, translation_table[mpc_record]);
  93. if (m->mpc_featureflag&(1<<0))
  94. Dprintk(" Floating point unit present.\n");
  95. if (m->mpc_featureflag&(1<<7))
  96. Dprintk(" Machine Exception supported.\n");
  97. if (m->mpc_featureflag&(1<<8))
  98. Dprintk(" 64 bit compare & exchange supported.\n");
  99. if (m->mpc_featureflag&(1<<9))
  100. Dprintk(" Internal APIC present.\n");
  101. if (m->mpc_featureflag&(1<<11))
  102. Dprintk(" SEP present.\n");
  103. if (m->mpc_featureflag&(1<<12))
  104. Dprintk(" MTRR present.\n");
  105. if (m->mpc_featureflag&(1<<13))
  106. Dprintk(" PGE present.\n");
  107. if (m->mpc_featureflag&(1<<14))
  108. Dprintk(" MCA present.\n");
  109. if (m->mpc_featureflag&(1<<15))
  110. Dprintk(" CMOV present.\n");
  111. if (m->mpc_featureflag&(1<<16))
  112. Dprintk(" PAT present.\n");
  113. if (m->mpc_featureflag&(1<<17))
  114. Dprintk(" PSE present.\n");
  115. if (m->mpc_featureflag&(1<<18))
  116. Dprintk(" PSN present.\n");
  117. if (m->mpc_featureflag&(1<<19))
  118. Dprintk(" Cache Line Flush Instruction present.\n");
  119. /* 20 Reserved */
  120. if (m->mpc_featureflag&(1<<21))
  121. Dprintk(" Debug Trace and EMON Store present.\n");
  122. if (m->mpc_featureflag&(1<<22))
  123. Dprintk(" ACPI Thermal Throttle Registers present.\n");
  124. if (m->mpc_featureflag&(1<<23))
  125. Dprintk(" MMX present.\n");
  126. if (m->mpc_featureflag&(1<<24))
  127. Dprintk(" FXSR present.\n");
  128. if (m->mpc_featureflag&(1<<25))
  129. Dprintk(" XMM present.\n");
  130. if (m->mpc_featureflag&(1<<26))
  131. Dprintk(" Willamette New Instructions present.\n");
  132. if (m->mpc_featureflag&(1<<27))
  133. Dprintk(" Self Snoop present.\n");
  134. if (m->mpc_featureflag&(1<<28))
  135. Dprintk(" HT present.\n");
  136. if (m->mpc_featureflag&(1<<29))
  137. Dprintk(" Thermal Monitor present.\n");
  138. /* 30, 31 Reserved */
  139. if (m->mpc_cpuflag & CPU_BOOTPROCESSOR) {
  140. Dprintk(" Bootup CPU\n");
  141. boot_cpu_physical_apicid = m->mpc_apicid;
  142. }
  143. ver = m->mpc_apicver;
  144. /*
  145. * Validate version
  146. */
  147. if (ver == 0x0) {
  148. printk(KERN_WARNING "BIOS bug, APIC version is 0 for CPU#%d! "
  149. "fixing up to 0x10. (tell your hw vendor)\n",
  150. m->mpc_apicid);
  151. ver = 0x10;
  152. }
  153. apic_version[m->mpc_apicid] = ver;
  154. phys_cpu = apicid_to_cpu_present(apicid);
  155. physids_or(phys_cpu_present_map, phys_cpu_present_map, phys_cpu);
  156. if (num_processors >= NR_CPUS) {
  157. printk(KERN_WARNING "WARNING: NR_CPUS limit of %i reached."
  158. " Processor ignored.\n", NR_CPUS);
  159. return;
  160. }
  161. if (num_processors >= maxcpus) {
  162. printk(KERN_WARNING "WARNING: maxcpus limit of %i reached."
  163. " Processor ignored.\n", maxcpus);
  164. return;
  165. }
  166. cpu_set(num_processors, cpu_possible_map);
  167. num_processors++;
  168. /*
  169. * Would be preferable to switch to bigsmp when CONFIG_HOTPLUG_CPU=y
  170. * but we need to work other dependencies like SMP_SUSPEND etc
  171. * before this can be done without some confusion.
  172. * if (CPU_HOTPLUG_ENABLED || num_processors > 8)
  173. * - Ashok Raj <ashok.raj@intel.com>
  174. */
  175. if (num_processors > 8) {
  176. switch (boot_cpu_data.x86_vendor) {
  177. case X86_VENDOR_INTEL:
  178. if (!APIC_XAPIC(ver)) {
  179. def_to_bigsmp = 0;
  180. break;
  181. }
  182. /* If P4 and above fall through */
  183. case X86_VENDOR_AMD:
  184. def_to_bigsmp = 1;
  185. }
  186. }
  187. bios_cpu_apicid[num_processors - 1] = m->mpc_apicid;
  188. }
  189. static void __init MP_bus_info (struct mpc_config_bus *m)
  190. {
  191. char str[7];
  192. memcpy(str, m->mpc_bustype, 6);
  193. str[6] = 0;
  194. mpc_oem_bus_info(m, str, translation_table[mpc_record]);
  195. #if MAX_MP_BUSSES < 256
  196. if (m->mpc_busid >= MAX_MP_BUSSES) {
  197. printk(KERN_WARNING "MP table busid value (%d) for bustype %s "
  198. " is too large, max. supported is %d\n",
  199. m->mpc_busid, str, MAX_MP_BUSSES - 1);
  200. return;
  201. }
  202. #endif
  203. set_bit(m->mpc_busid, mp_bus_not_pci);
  204. if (strncmp(str, BUSTYPE_PCI, sizeof(BUSTYPE_PCI)-1) == 0) {
  205. mpc_oem_pci_bus(m, translation_table[mpc_record]);
  206. clear_bit(m->mpc_busid, mp_bus_not_pci);
  207. mp_bus_id_to_type[m->mpc_busid] = MP_BUS_PCI;
  208. mp_bus_id_to_pci_bus[m->mpc_busid] = mp_current_pci_id;
  209. mp_current_pci_id++;
  210. } else if (strncmp(str, BUSTYPE_ISA, sizeof(BUSTYPE_ISA)-1) == 0) {
  211. mp_bus_id_to_type[m->mpc_busid] = MP_BUS_ISA;
  212. } else if (strncmp(str, BUSTYPE_EISA, sizeof(BUSTYPE_EISA)-1) == 0) {
  213. mp_bus_id_to_type[m->mpc_busid] = MP_BUS_EISA;
  214. } else if (strncmp(str, BUSTYPE_MCA, sizeof(BUSTYPE_MCA)-1) == 0) {
  215. mp_bus_id_to_type[m->mpc_busid] = MP_BUS_MCA;
  216. } else {
  217. printk(KERN_WARNING "Unknown bustype %s - ignoring\n", str);
  218. }
  219. }
  220. static void __init MP_ioapic_info (struct mpc_config_ioapic *m)
  221. {
  222. if (!(m->mpc_flags & MPC_APIC_USABLE))
  223. return;
  224. printk(KERN_INFO "I/O APIC #%d Version %d at 0x%X.\n",
  225. m->mpc_apicid, m->mpc_apicver, m->mpc_apicaddr);
  226. if (nr_ioapics >= MAX_IO_APICS) {
  227. printk(KERN_CRIT "Max # of I/O APICs (%d) exceeded (found %d).\n",
  228. MAX_IO_APICS, nr_ioapics);
  229. panic("Recompile kernel with bigger MAX_IO_APICS!.\n");
  230. }
  231. if (!m->mpc_apicaddr) {
  232. printk(KERN_ERR "WARNING: bogus zero I/O APIC address"
  233. " found in MP table, skipping!\n");
  234. return;
  235. }
  236. mp_ioapics[nr_ioapics] = *m;
  237. nr_ioapics++;
  238. }
  239. static void __init MP_intsrc_info (struct mpc_config_intsrc *m)
  240. {
  241. mp_irqs [mp_irq_entries] = *m;
  242. Dprintk("Int: type %d, pol %d, trig %d, bus %d,"
  243. " IRQ %02x, APIC ID %x, APIC INT %02x\n",
  244. m->mpc_irqtype, m->mpc_irqflag & 3,
  245. (m->mpc_irqflag >> 2) & 3, m->mpc_srcbus,
  246. m->mpc_srcbusirq, m->mpc_dstapic, m->mpc_dstirq);
  247. if (++mp_irq_entries == MAX_IRQ_SOURCES)
  248. panic("Max # of irq sources exceeded!!\n");
  249. }
  250. static void __init MP_lintsrc_info (struct mpc_config_lintsrc *m)
  251. {
  252. Dprintk("Lint: type %d, pol %d, trig %d, bus %d,"
  253. " IRQ %02x, APIC ID %x, APIC LINT %02x\n",
  254. m->mpc_irqtype, m->mpc_irqflag & 3,
  255. (m->mpc_irqflag >> 2) &3, m->mpc_srcbusid,
  256. m->mpc_srcbusirq, m->mpc_destapic, m->mpc_destapiclint);
  257. }
  258. #ifdef CONFIG_X86_NUMAQ
  259. static void __init MP_translation_info (struct mpc_config_translation *m)
  260. {
  261. printk(KERN_INFO "Translation: record %d, type %d, quad %d, global %d, local %d\n", mpc_record, m->trans_type, m->trans_quad, m->trans_global, m->trans_local);
  262. if (mpc_record >= MAX_MPC_ENTRY)
  263. printk(KERN_ERR "MAX_MPC_ENTRY exceeded!\n");
  264. else
  265. translation_table[mpc_record] = m; /* stash this for later */
  266. if (m->trans_quad < MAX_NUMNODES && !node_online(m->trans_quad))
  267. node_set_online(m->trans_quad);
  268. }
  269. /*
  270. * Read/parse the MPC oem tables
  271. */
  272. static void __init smp_read_mpc_oem(struct mp_config_oemtable *oemtable, \
  273. unsigned short oemsize)
  274. {
  275. int count = sizeof (*oemtable); /* the header size */
  276. unsigned char *oemptr = ((unsigned char *)oemtable)+count;
  277. mpc_record = 0;
  278. printk(KERN_INFO "Found an OEM MPC table at %8p - parsing it ... \n", oemtable);
  279. if (memcmp(oemtable->oem_signature,MPC_OEM_SIGNATURE,4))
  280. {
  281. printk(KERN_WARNING "SMP mpc oemtable: bad signature [%c%c%c%c]!\n",
  282. oemtable->oem_signature[0],
  283. oemtable->oem_signature[1],
  284. oemtable->oem_signature[2],
  285. oemtable->oem_signature[3]);
  286. return;
  287. }
  288. if (mpf_checksum((unsigned char *)oemtable,oemtable->oem_length))
  289. {
  290. printk(KERN_WARNING "SMP oem mptable: checksum error!\n");
  291. return;
  292. }
  293. while (count < oemtable->oem_length) {
  294. switch (*oemptr) {
  295. case MP_TRANSLATION:
  296. {
  297. struct mpc_config_translation *m=
  298. (struct mpc_config_translation *)oemptr;
  299. MP_translation_info(m);
  300. oemptr += sizeof(*m);
  301. count += sizeof(*m);
  302. ++mpc_record;
  303. break;
  304. }
  305. default:
  306. {
  307. printk(KERN_WARNING "Unrecognised OEM table entry type! - %d\n", (int) *oemptr);
  308. return;
  309. }
  310. }
  311. }
  312. }
  313. static inline void mps_oem_check(struct mp_config_table *mpc, char *oem,
  314. char *productid)
  315. {
  316. if (strncmp(oem, "IBM NUMA", 8))
  317. printk("Warning! May not be a NUMA-Q system!\n");
  318. if (mpc->mpc_oemptr)
  319. smp_read_mpc_oem((struct mp_config_oemtable *) mpc->mpc_oemptr,
  320. mpc->mpc_oemsize);
  321. }
  322. #endif /* CONFIG_X86_NUMAQ */
  323. /*
  324. * Read/parse the MPC
  325. */
  326. static int __init smp_read_mpc(struct mp_config_table *mpc)
  327. {
  328. char str[16];
  329. char oem[10];
  330. int count=sizeof(*mpc);
  331. unsigned char *mpt=((unsigned char *)mpc)+count;
  332. if (memcmp(mpc->mpc_signature,MPC_SIGNATURE,4)) {
  333. printk(KERN_ERR "SMP mptable: bad signature [0x%x]!\n",
  334. *(u32 *)mpc->mpc_signature);
  335. return 0;
  336. }
  337. if (mpf_checksum((unsigned char *)mpc,mpc->mpc_length)) {
  338. printk(KERN_ERR "SMP mptable: checksum error!\n");
  339. return 0;
  340. }
  341. if (mpc->mpc_spec!=0x01 && mpc->mpc_spec!=0x04) {
  342. printk(KERN_ERR "SMP mptable: bad table version (%d)!!\n",
  343. mpc->mpc_spec);
  344. return 0;
  345. }
  346. if (!mpc->mpc_lapic) {
  347. printk(KERN_ERR "SMP mptable: null local APIC address!\n");
  348. return 0;
  349. }
  350. memcpy(oem,mpc->mpc_oem,8);
  351. oem[8]=0;
  352. printk(KERN_INFO "OEM ID: %s ",oem);
  353. memcpy(str,mpc->mpc_productid,12);
  354. str[12]=0;
  355. printk("Product ID: %s ",str);
  356. mps_oem_check(mpc, oem, str);
  357. printk("APIC at: 0x%X\n", mpc->mpc_lapic);
  358. /*
  359. * Save the local APIC address (it might be non-default) -- but only
  360. * if we're not using ACPI.
  361. */
  362. if (!acpi_lapic)
  363. mp_lapic_addr = mpc->mpc_lapic;
  364. /*
  365. * Now process the configuration blocks.
  366. */
  367. mpc_record = 0;
  368. while (count < mpc->mpc_length) {
  369. switch(*mpt) {
  370. case MP_PROCESSOR:
  371. {
  372. struct mpc_config_processor *m=
  373. (struct mpc_config_processor *)mpt;
  374. /* ACPI may have already provided this data */
  375. if (!acpi_lapic)
  376. MP_processor_info(m);
  377. mpt += sizeof(*m);
  378. count += sizeof(*m);
  379. break;
  380. }
  381. case MP_BUS:
  382. {
  383. struct mpc_config_bus *m=
  384. (struct mpc_config_bus *)mpt;
  385. MP_bus_info(m);
  386. mpt += sizeof(*m);
  387. count += sizeof(*m);
  388. break;
  389. }
  390. case MP_IOAPIC:
  391. {
  392. struct mpc_config_ioapic *m=
  393. (struct mpc_config_ioapic *)mpt;
  394. MP_ioapic_info(m);
  395. mpt+=sizeof(*m);
  396. count+=sizeof(*m);
  397. break;
  398. }
  399. case MP_INTSRC:
  400. {
  401. struct mpc_config_intsrc *m=
  402. (struct mpc_config_intsrc *)mpt;
  403. MP_intsrc_info(m);
  404. mpt+=sizeof(*m);
  405. count+=sizeof(*m);
  406. break;
  407. }
  408. case MP_LINTSRC:
  409. {
  410. struct mpc_config_lintsrc *m=
  411. (struct mpc_config_lintsrc *)mpt;
  412. MP_lintsrc_info(m);
  413. mpt+=sizeof(*m);
  414. count+=sizeof(*m);
  415. break;
  416. }
  417. default:
  418. {
  419. count = mpc->mpc_length;
  420. break;
  421. }
  422. }
  423. ++mpc_record;
  424. }
  425. setup_apic_routing();
  426. if (!num_processors)
  427. printk(KERN_ERR "SMP mptable: no processors registered!\n");
  428. return num_processors;
  429. }
  430. static int __init ELCR_trigger(unsigned int irq)
  431. {
  432. unsigned int port;
  433. port = 0x4d0 + (irq >> 3);
  434. return (inb(port) >> (irq & 7)) & 1;
  435. }
  436. static void __init construct_default_ioirq_mptable(int mpc_default_type)
  437. {
  438. struct mpc_config_intsrc intsrc;
  439. int i;
  440. int ELCR_fallback = 0;
  441. intsrc.mpc_type = MP_INTSRC;
  442. intsrc.mpc_irqflag = 0; /* conforming */
  443. intsrc.mpc_srcbus = 0;
  444. intsrc.mpc_dstapic = mp_ioapics[0].mpc_apicid;
  445. intsrc.mpc_irqtype = mp_INT;
  446. /*
  447. * If true, we have an ISA/PCI system with no IRQ entries
  448. * in the MP table. To prevent the PCI interrupts from being set up
  449. * incorrectly, we try to use the ELCR. The sanity check to see if
  450. * there is good ELCR data is very simple - IRQ0, 1, 2 and 13 can
  451. * never be level sensitive, so we simply see if the ELCR agrees.
  452. * If it does, we assume it's valid.
  453. */
  454. if (mpc_default_type == 5) {
  455. printk(KERN_INFO "ISA/PCI bus type with no IRQ information... falling back to ELCR\n");
  456. if (ELCR_trigger(0) || ELCR_trigger(1) || ELCR_trigger(2) || ELCR_trigger(13))
  457. printk(KERN_WARNING "ELCR contains invalid data... not using ELCR\n");
  458. else {
  459. printk(KERN_INFO "Using ELCR to identify PCI interrupts\n");
  460. ELCR_fallback = 1;
  461. }
  462. }
  463. for (i = 0; i < 16; i++) {
  464. switch (mpc_default_type) {
  465. case 2:
  466. if (i == 0 || i == 13)
  467. continue; /* IRQ0 & IRQ13 not connected */
  468. /* fall through */
  469. default:
  470. if (i == 2)
  471. continue; /* IRQ2 is never connected */
  472. }
  473. if (ELCR_fallback) {
  474. /*
  475. * If the ELCR indicates a level-sensitive interrupt, we
  476. * copy that information over to the MP table in the
  477. * irqflag field (level sensitive, active high polarity).
  478. */
  479. if (ELCR_trigger(i))
  480. intsrc.mpc_irqflag = 13;
  481. else
  482. intsrc.mpc_irqflag = 0;
  483. }
  484. intsrc.mpc_srcbusirq = i;
  485. intsrc.mpc_dstirq = i ? i : 2; /* IRQ0 to INTIN2 */
  486. MP_intsrc_info(&intsrc);
  487. }
  488. intsrc.mpc_irqtype = mp_ExtINT;
  489. intsrc.mpc_srcbusirq = 0;
  490. intsrc.mpc_dstirq = 0; /* 8259A to INTIN0 */
  491. MP_intsrc_info(&intsrc);
  492. }
  493. static inline void __init construct_default_ISA_mptable(int mpc_default_type)
  494. {
  495. struct mpc_config_processor processor;
  496. struct mpc_config_bus bus;
  497. struct mpc_config_ioapic ioapic;
  498. struct mpc_config_lintsrc lintsrc;
  499. int linttypes[2] = { mp_ExtINT, mp_NMI };
  500. int i;
  501. /*
  502. * local APIC has default address
  503. */
  504. mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
  505. /*
  506. * 2 CPUs, numbered 0 & 1.
  507. */
  508. processor.mpc_type = MP_PROCESSOR;
  509. /* Either an integrated APIC or a discrete 82489DX. */
  510. processor.mpc_apicver = mpc_default_type > 4 ? 0x10 : 0x01;
  511. processor.mpc_cpuflag = CPU_ENABLED;
  512. processor.mpc_cpufeature = (boot_cpu_data.x86 << 8) |
  513. (boot_cpu_data.x86_model << 4) |
  514. boot_cpu_data.x86_mask;
  515. processor.mpc_featureflag = boot_cpu_data.x86_capability[0];
  516. processor.mpc_reserved[0] = 0;
  517. processor.mpc_reserved[1] = 0;
  518. for (i = 0; i < 2; i++) {
  519. processor.mpc_apicid = i;
  520. MP_processor_info(&processor);
  521. }
  522. bus.mpc_type = MP_BUS;
  523. bus.mpc_busid = 0;
  524. switch (mpc_default_type) {
  525. default:
  526. printk("???\n");
  527. printk(KERN_ERR "Unknown standard configuration %d\n",
  528. mpc_default_type);
  529. /* fall through */
  530. case 1:
  531. case 5:
  532. memcpy(bus.mpc_bustype, "ISA ", 6);
  533. break;
  534. case 2:
  535. case 6:
  536. case 3:
  537. memcpy(bus.mpc_bustype, "EISA ", 6);
  538. break;
  539. case 4:
  540. case 7:
  541. memcpy(bus.mpc_bustype, "MCA ", 6);
  542. }
  543. MP_bus_info(&bus);
  544. if (mpc_default_type > 4) {
  545. bus.mpc_busid = 1;
  546. memcpy(bus.mpc_bustype, "PCI ", 6);
  547. MP_bus_info(&bus);
  548. }
  549. ioapic.mpc_type = MP_IOAPIC;
  550. ioapic.mpc_apicid = 2;
  551. ioapic.mpc_apicver = mpc_default_type > 4 ? 0x10 : 0x01;
  552. ioapic.mpc_flags = MPC_APIC_USABLE;
  553. ioapic.mpc_apicaddr = 0xFEC00000;
  554. MP_ioapic_info(&ioapic);
  555. /*
  556. * We set up most of the low 16 IO-APIC pins according to MPS rules.
  557. */
  558. construct_default_ioirq_mptable(mpc_default_type);
  559. lintsrc.mpc_type = MP_LINTSRC;
  560. lintsrc.mpc_irqflag = 0; /* conforming */
  561. lintsrc.mpc_srcbusid = 0;
  562. lintsrc.mpc_srcbusirq = 0;
  563. lintsrc.mpc_destapic = MP_APIC_ALL;
  564. for (i = 0; i < 2; i++) {
  565. lintsrc.mpc_irqtype = linttypes[i];
  566. lintsrc.mpc_destapiclint = i;
  567. MP_lintsrc_info(&lintsrc);
  568. }
  569. }
  570. static struct intel_mp_floating *mpf_found;
  571. /*
  572. * Scan the memory blocks for an SMP configuration block.
  573. */
  574. void __init get_smp_config (void)
  575. {
  576. struct intel_mp_floating *mpf = mpf_found;
  577. /*
  578. * ACPI supports both logical (e.g. Hyper-Threading) and physical
  579. * processors, where MPS only supports physical.
  580. */
  581. if (acpi_lapic && acpi_ioapic) {
  582. printk(KERN_INFO "Using ACPI (MADT) for SMP configuration information\n");
  583. return;
  584. }
  585. else if (acpi_lapic)
  586. printk(KERN_INFO "Using ACPI for processor (LAPIC) configuration information\n");
  587. printk(KERN_INFO "Intel MultiProcessor Specification v1.%d\n", mpf->mpf_specification);
  588. if (mpf->mpf_feature2 & (1<<7)) {
  589. printk(KERN_INFO " IMCR and PIC compatibility mode.\n");
  590. pic_mode = 1;
  591. } else {
  592. printk(KERN_INFO " Virtual Wire compatibility mode.\n");
  593. pic_mode = 0;
  594. }
  595. /*
  596. * Now see if we need to read further.
  597. */
  598. if (mpf->mpf_feature1 != 0) {
  599. printk(KERN_INFO "Default MP configuration #%d\n", mpf->mpf_feature1);
  600. construct_default_ISA_mptable(mpf->mpf_feature1);
  601. } else if (mpf->mpf_physptr) {
  602. /*
  603. * Read the physical hardware table. Anything here will
  604. * override the defaults.
  605. */
  606. if (!smp_read_mpc(phys_to_virt(mpf->mpf_physptr))) {
  607. smp_found_config = 0;
  608. printk(KERN_ERR "BIOS bug, MP table errors detected!...\n");
  609. printk(KERN_ERR "... disabling SMP support. (tell your hw vendor)\n");
  610. return;
  611. }
  612. /*
  613. * If there are no explicit MP IRQ entries, then we are
  614. * broken. We set up most of the low 16 IO-APIC pins to
  615. * ISA defaults and hope it will work.
  616. */
  617. if (!mp_irq_entries) {
  618. struct mpc_config_bus bus;
  619. printk(KERN_ERR "BIOS bug, no explicit IRQ entries, using default mptable. (tell your hw vendor)\n");
  620. bus.mpc_type = MP_BUS;
  621. bus.mpc_busid = 0;
  622. memcpy(bus.mpc_bustype, "ISA ", 6);
  623. MP_bus_info(&bus);
  624. construct_default_ioirq_mptable(0);
  625. }
  626. } else
  627. BUG();
  628. printk(KERN_INFO "Processors: %d\n", num_processors);
  629. /*
  630. * Only use the first configuration found.
  631. */
  632. }
  633. static int __init smp_scan_config (unsigned long base, unsigned long length)
  634. {
  635. unsigned long *bp = phys_to_virt(base);
  636. struct intel_mp_floating *mpf;
  637. printk(KERN_INFO "Scan SMP from %p for %ld bytes.\n", bp,length);
  638. if (sizeof(*mpf) != 16)
  639. printk("Error: MPF size\n");
  640. while (length > 0) {
  641. mpf = (struct intel_mp_floating *)bp;
  642. if ((*bp == SMP_MAGIC_IDENT) &&
  643. (mpf->mpf_length == 1) &&
  644. !mpf_checksum((unsigned char *)bp, 16) &&
  645. ((mpf->mpf_specification == 1)
  646. || (mpf->mpf_specification == 4)) ) {
  647. smp_found_config = 1;
  648. printk(KERN_INFO "found SMP MP-table at [%p] %08lx\n",
  649. mpf, virt_to_phys(mpf));
  650. reserve_bootmem(virt_to_phys(mpf), PAGE_SIZE,
  651. BOOTMEM_DEFAULT);
  652. if (mpf->mpf_physptr) {
  653. /*
  654. * We cannot access to MPC table to compute
  655. * table size yet, as only few megabytes from
  656. * the bottom is mapped now.
  657. * PC-9800's MPC table places on the very last
  658. * of physical memory; so that simply reserving
  659. * PAGE_SIZE from mpg->mpf_physptr yields BUG()
  660. * in reserve_bootmem.
  661. */
  662. unsigned long size = PAGE_SIZE;
  663. unsigned long end = max_low_pfn * PAGE_SIZE;
  664. if (mpf->mpf_physptr + size > end)
  665. size = end - mpf->mpf_physptr;
  666. reserve_bootmem(mpf->mpf_physptr, size,
  667. BOOTMEM_DEFAULT);
  668. }
  669. mpf_found = mpf;
  670. return 1;
  671. }
  672. bp += 4;
  673. length -= 16;
  674. }
  675. return 0;
  676. }
  677. void __init find_smp_config (void)
  678. {
  679. unsigned int address;
  680. /*
  681. * FIXME: Linux assumes you have 640K of base ram..
  682. * this continues the error...
  683. *
  684. * 1) Scan the bottom 1K for a signature
  685. * 2) Scan the top 1K of base RAM
  686. * 3) Scan the 64K of bios
  687. */
  688. if (smp_scan_config(0x0,0x400) ||
  689. smp_scan_config(639*0x400,0x400) ||
  690. smp_scan_config(0xF0000,0x10000))
  691. return;
  692. /*
  693. * If it is an SMP machine we should know now, unless the
  694. * configuration is in an EISA/MCA bus machine with an
  695. * extended bios data area.
  696. *
  697. * there is a real-mode segmented pointer pointing to the
  698. * 4K EBDA area at 0x40E, calculate and scan it here.
  699. *
  700. * NOTE! There are Linux loaders that will corrupt the EBDA
  701. * area, and as such this kind of SMP config may be less
  702. * trustworthy, simply because the SMP table may have been
  703. * stomped on during early boot. These loaders are buggy and
  704. * should be fixed.
  705. *
  706. * MP1.4 SPEC states to only scan first 1K of 4K EBDA.
  707. */
  708. address = get_bios_ebda();
  709. if (address)
  710. smp_scan_config(address, 0x400);
  711. }
  712. int es7000_plat;
  713. /* --------------------------------------------------------------------------
  714. ACPI-based MP Configuration
  715. -------------------------------------------------------------------------- */
  716. #ifdef CONFIG_ACPI
  717. void __init mp_register_lapic_address(u64 address)
  718. {
  719. mp_lapic_addr = (unsigned long) address;
  720. set_fixmap_nocache(FIX_APIC_BASE, mp_lapic_addr);
  721. if (boot_cpu_physical_apicid == -1U)
  722. boot_cpu_physical_apicid = GET_APIC_ID(apic_read(APIC_ID));
  723. Dprintk("Boot CPU = %d\n", boot_cpu_physical_apicid);
  724. }
  725. void __cpuinit mp_register_lapic (u8 id, u8 enabled)
  726. {
  727. struct mpc_config_processor processor;
  728. int boot_cpu = 0;
  729. if (MAX_APICS - id <= 0) {
  730. printk(KERN_WARNING "Processor #%d invalid (max %d)\n",
  731. id, MAX_APICS);
  732. return;
  733. }
  734. if (id == boot_cpu_physical_apicid)
  735. boot_cpu = 1;
  736. processor.mpc_type = MP_PROCESSOR;
  737. processor.mpc_apicid = id;
  738. processor.mpc_apicver = GET_APIC_VERSION(apic_read(APIC_LVR));
  739. processor.mpc_cpuflag = (enabled ? CPU_ENABLED : 0);
  740. processor.mpc_cpuflag |= (boot_cpu ? CPU_BOOTPROCESSOR : 0);
  741. processor.mpc_cpufeature = (boot_cpu_data.x86 << 8) |
  742. (boot_cpu_data.x86_model << 4) | boot_cpu_data.x86_mask;
  743. processor.mpc_featureflag = boot_cpu_data.x86_capability[0];
  744. processor.mpc_reserved[0] = 0;
  745. processor.mpc_reserved[1] = 0;
  746. MP_processor_info(&processor);
  747. }
  748. #ifdef CONFIG_X86_IO_APIC
  749. #define MP_ISA_BUS 0
  750. #define MP_MAX_IOAPIC_PIN 127
  751. static struct mp_ioapic_routing {
  752. int apic_id;
  753. int gsi_base;
  754. int gsi_end;
  755. u32 pin_programmed[4];
  756. } mp_ioapic_routing[MAX_IO_APICS];
  757. static int mp_find_ioapic (int gsi)
  758. {
  759. int i = 0;
  760. /* Find the IOAPIC that manages this GSI. */
  761. for (i = 0; i < nr_ioapics; i++) {
  762. if ((gsi >= mp_ioapic_routing[i].gsi_base)
  763. && (gsi <= mp_ioapic_routing[i].gsi_end))
  764. return i;
  765. }
  766. printk(KERN_ERR "ERROR: Unable to locate IOAPIC for GSI %d\n", gsi);
  767. return -1;
  768. }
  769. void __init mp_register_ioapic(u8 id, u32 address, u32 gsi_base)
  770. {
  771. int idx = 0;
  772. int tmpid;
  773. if (nr_ioapics >= MAX_IO_APICS) {
  774. printk(KERN_ERR "ERROR: Max # of I/O APICs (%d) exceeded "
  775. "(found %d)\n", MAX_IO_APICS, nr_ioapics);
  776. panic("Recompile kernel with bigger MAX_IO_APICS!\n");
  777. }
  778. if (!address) {
  779. printk(KERN_ERR "WARNING: Bogus (zero) I/O APIC address"
  780. " found in MADT table, skipping!\n");
  781. return;
  782. }
  783. idx = nr_ioapics++;
  784. mp_ioapics[idx].mpc_type = MP_IOAPIC;
  785. mp_ioapics[idx].mpc_flags = MPC_APIC_USABLE;
  786. mp_ioapics[idx].mpc_apicaddr = address;
  787. set_fixmap_nocache(FIX_IO_APIC_BASE_0 + idx, address);
  788. if ((boot_cpu_data.x86_vendor == X86_VENDOR_INTEL)
  789. && !APIC_XAPIC(apic_version[boot_cpu_physical_apicid]))
  790. tmpid = io_apic_get_unique_id(idx, id);
  791. else
  792. tmpid = id;
  793. if (tmpid == -1) {
  794. nr_ioapics--;
  795. return;
  796. }
  797. mp_ioapics[idx].mpc_apicid = tmpid;
  798. mp_ioapics[idx].mpc_apicver = io_apic_get_version(idx);
  799. /*
  800. * Build basic GSI lookup table to facilitate gsi->io_apic lookups
  801. * and to prevent reprogramming of IOAPIC pins (PCI GSIs).
  802. */
  803. mp_ioapic_routing[idx].apic_id = mp_ioapics[idx].mpc_apicid;
  804. mp_ioapic_routing[idx].gsi_base = gsi_base;
  805. mp_ioapic_routing[idx].gsi_end = gsi_base +
  806. io_apic_get_redir_entries(idx);
  807. printk("IOAPIC[%d]: apic_id %d, version %d, address 0x%x, "
  808. "GSI %d-%d\n", idx, mp_ioapics[idx].mpc_apicid,
  809. mp_ioapics[idx].mpc_apicver, mp_ioapics[idx].mpc_apicaddr,
  810. mp_ioapic_routing[idx].gsi_base,
  811. mp_ioapic_routing[idx].gsi_end);
  812. }
  813. void __init
  814. mp_override_legacy_irq(u8 bus_irq, u8 polarity, u8 trigger, u32 gsi)
  815. {
  816. struct mpc_config_intsrc intsrc;
  817. int ioapic = -1;
  818. int pin = -1;
  819. /*
  820. * Convert 'gsi' to 'ioapic.pin'.
  821. */
  822. ioapic = mp_find_ioapic(gsi);
  823. if (ioapic < 0)
  824. return;
  825. pin = gsi - mp_ioapic_routing[ioapic].gsi_base;
  826. /*
  827. * TBD: This check is for faulty timer entries, where the override
  828. * erroneously sets the trigger to level, resulting in a HUGE
  829. * increase of timer interrupts!
  830. */
  831. if ((bus_irq == 0) && (trigger == 3))
  832. trigger = 1;
  833. intsrc.mpc_type = MP_INTSRC;
  834. intsrc.mpc_irqtype = mp_INT;
  835. intsrc.mpc_irqflag = (trigger << 2) | polarity;
  836. intsrc.mpc_srcbus = MP_ISA_BUS;
  837. intsrc.mpc_srcbusirq = bus_irq; /* IRQ */
  838. intsrc.mpc_dstapic = mp_ioapics[ioapic].mpc_apicid; /* APIC ID */
  839. intsrc.mpc_dstirq = pin; /* INTIN# */
  840. Dprintk("Int: type %d, pol %d, trig %d, bus %d, irq %d, %d-%d\n",
  841. intsrc.mpc_irqtype, intsrc.mpc_irqflag & 3,
  842. (intsrc.mpc_irqflag >> 2) & 3, intsrc.mpc_srcbus,
  843. intsrc.mpc_srcbusirq, intsrc.mpc_dstapic, intsrc.mpc_dstirq);
  844. mp_irqs[mp_irq_entries] = intsrc;
  845. if (++mp_irq_entries == MAX_IRQ_SOURCES)
  846. panic("Max # of irq sources exceeded!\n");
  847. }
  848. void __init mp_config_acpi_legacy_irqs (void)
  849. {
  850. struct mpc_config_intsrc intsrc;
  851. int i = 0;
  852. int ioapic = -1;
  853. /*
  854. * Fabricate the legacy ISA bus (bus #31).
  855. */
  856. mp_bus_id_to_type[MP_ISA_BUS] = MP_BUS_ISA;
  857. set_bit(MP_ISA_BUS, mp_bus_not_pci);
  858. Dprintk("Bus #%d is ISA\n", MP_ISA_BUS);
  859. /*
  860. * Older generations of ES7000 have no legacy identity mappings
  861. */
  862. if (es7000_plat == 1)
  863. return;
  864. /*
  865. * Locate the IOAPIC that manages the ISA IRQs (0-15).
  866. */
  867. ioapic = mp_find_ioapic(0);
  868. if (ioapic < 0)
  869. return;
  870. intsrc.mpc_type = MP_INTSRC;
  871. intsrc.mpc_irqflag = 0; /* Conforming */
  872. intsrc.mpc_srcbus = MP_ISA_BUS;
  873. intsrc.mpc_dstapic = mp_ioapics[ioapic].mpc_apicid;
  874. /*
  875. * Use the default configuration for the IRQs 0-15. Unless
  876. * overridden by (MADT) interrupt source override entries.
  877. */
  878. for (i = 0; i < 16; i++) {
  879. int idx;
  880. for (idx = 0; idx < mp_irq_entries; idx++) {
  881. struct mpc_config_intsrc *irq = mp_irqs + idx;
  882. /* Do we already have a mapping for this ISA IRQ? */
  883. if (irq->mpc_srcbus == MP_ISA_BUS && irq->mpc_srcbusirq == i)
  884. break;
  885. /* Do we already have a mapping for this IOAPIC pin */
  886. if ((irq->mpc_dstapic == intsrc.mpc_dstapic) &&
  887. (irq->mpc_dstirq == i))
  888. break;
  889. }
  890. if (idx != mp_irq_entries) {
  891. printk(KERN_DEBUG "ACPI: IRQ%d used by override.\n", i);
  892. continue; /* IRQ already used */
  893. }
  894. intsrc.mpc_irqtype = mp_INT;
  895. intsrc.mpc_srcbusirq = i; /* Identity mapped */
  896. intsrc.mpc_dstirq = i;
  897. Dprintk("Int: type %d, pol %d, trig %d, bus %d, irq %d, "
  898. "%d-%d\n", intsrc.mpc_irqtype, intsrc.mpc_irqflag & 3,
  899. (intsrc.mpc_irqflag >> 2) & 3, intsrc.mpc_srcbus,
  900. intsrc.mpc_srcbusirq, intsrc.mpc_dstapic,
  901. intsrc.mpc_dstirq);
  902. mp_irqs[mp_irq_entries] = intsrc;
  903. if (++mp_irq_entries == MAX_IRQ_SOURCES)
  904. panic("Max # of irq sources exceeded!\n");
  905. }
  906. }
  907. #define MAX_GSI_NUM 4096
  908. #define IRQ_COMPRESSION_START 64
  909. int mp_register_gsi(u32 gsi, int triggering, int polarity)
  910. {
  911. int ioapic = -1;
  912. int ioapic_pin = 0;
  913. int idx, bit = 0;
  914. static int pci_irq = IRQ_COMPRESSION_START;
  915. /*
  916. * Mapping between Global System Interrupts, which
  917. * represent all possible interrupts, and IRQs
  918. * assigned to actual devices.
  919. */
  920. static int gsi_to_irq[MAX_GSI_NUM];
  921. /* Don't set up the ACPI SCI because it's already set up */
  922. if (acpi_gbl_FADT.sci_interrupt == gsi)
  923. return gsi;
  924. ioapic = mp_find_ioapic(gsi);
  925. if (ioapic < 0) {
  926. printk(KERN_WARNING "No IOAPIC for GSI %u\n", gsi);
  927. return gsi;
  928. }
  929. ioapic_pin = gsi - mp_ioapic_routing[ioapic].gsi_base;
  930. if (ioapic_renumber_irq)
  931. gsi = ioapic_renumber_irq(ioapic, gsi);
  932. /*
  933. * Avoid pin reprogramming. PRTs typically include entries
  934. * with redundant pin->gsi mappings (but unique PCI devices);
  935. * we only program the IOAPIC on the first.
  936. */
  937. bit = ioapic_pin % 32;
  938. idx = (ioapic_pin < 32) ? 0 : (ioapic_pin / 32);
  939. if (idx > 3) {
  940. printk(KERN_ERR "Invalid reference to IOAPIC pin "
  941. "%d-%d\n", mp_ioapic_routing[ioapic].apic_id,
  942. ioapic_pin);
  943. return gsi;
  944. }
  945. if ((1<<bit) & mp_ioapic_routing[ioapic].pin_programmed[idx]) {
  946. Dprintk(KERN_DEBUG "Pin %d-%d already programmed\n",
  947. mp_ioapic_routing[ioapic].apic_id, ioapic_pin);
  948. return (gsi < IRQ_COMPRESSION_START ? gsi : gsi_to_irq[gsi]);
  949. }
  950. mp_ioapic_routing[ioapic].pin_programmed[idx] |= (1<<bit);
  951. /*
  952. * For GSI >= 64, use IRQ compression
  953. */
  954. if ((gsi >= IRQ_COMPRESSION_START)
  955. && (triggering == ACPI_LEVEL_SENSITIVE)) {
  956. /*
  957. * For PCI devices assign IRQs in order, avoiding gaps
  958. * due to unused I/O APIC pins.
  959. */
  960. int irq = gsi;
  961. if (gsi < MAX_GSI_NUM) {
  962. /*
  963. * Retain the VIA chipset work-around (gsi > 15), but
  964. * avoid a problem where the 8254 timer (IRQ0) is setup
  965. * via an override (so it's not on pin 0 of the ioapic),
  966. * and at the same time, the pin 0 interrupt is a PCI
  967. * type. The gsi > 15 test could cause these two pins
  968. * to be shared as IRQ0, and they are not shareable.
  969. * So test for this condition, and if necessary, avoid
  970. * the pin collision.
  971. */
  972. if (gsi > 15 || (gsi == 0 && !timer_uses_ioapic_pin_0))
  973. gsi = pci_irq++;
  974. /*
  975. * Don't assign IRQ used by ACPI SCI
  976. */
  977. if (gsi == acpi_gbl_FADT.sci_interrupt)
  978. gsi = pci_irq++;
  979. gsi_to_irq[irq] = gsi;
  980. } else {
  981. printk(KERN_ERR "GSI %u is too high\n", gsi);
  982. return gsi;
  983. }
  984. }
  985. io_apic_set_pci_routing(ioapic, ioapic_pin, gsi,
  986. triggering == ACPI_EDGE_SENSITIVE ? 0 : 1,
  987. polarity == ACPI_ACTIVE_HIGH ? 0 : 1);
  988. return gsi;
  989. }
  990. #endif /* CONFIG_X86_IO_APIC */
  991. #endif /* CONFIG_ACPI */