mpparse.c 29 KB

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