boot.c 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696
  1. /*
  2. * boot.c - Architecture-Specific Low-Level ACPI Boot Support
  3. *
  4. * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
  5. * Copyright (C) 2001 Jun Nakajima <jun.nakajima@intel.com>
  6. *
  7. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. *
  23. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  24. */
  25. #include <linux/init.h>
  26. #include <linux/acpi.h>
  27. #include <linux/acpi_pmtmr.h>
  28. #include <linux/efi.h>
  29. #include <linux/cpumask.h>
  30. #include <linux/module.h>
  31. #include <linux/dmi.h>
  32. #include <linux/irq.h>
  33. #include <linux/slab.h>
  34. #include <linux/bootmem.h>
  35. #include <linux/ioport.h>
  36. #include <linux/pci.h>
  37. #include <asm/pci_x86.h>
  38. #include <asm/pgtable.h>
  39. #include <asm/io_apic.h>
  40. #include <asm/apic.h>
  41. #include <asm/io.h>
  42. #include <asm/mpspec.h>
  43. #include <asm/smp.h>
  44. static int __initdata acpi_force = 0;
  45. u32 acpi_rsdt_forced;
  46. int acpi_disabled;
  47. EXPORT_SYMBOL(acpi_disabled);
  48. #ifdef CONFIG_X86_64
  49. # include <asm/proto.h>
  50. # include <asm/numa_64.h>
  51. #endif /* X86 */
  52. #define BAD_MADT_ENTRY(entry, end) ( \
  53. (!entry) || (unsigned long)entry + sizeof(*entry) > end || \
  54. ((struct acpi_subtable_header *)entry)->length < sizeof(*entry))
  55. #define PREFIX "ACPI: "
  56. int acpi_noirq; /* skip ACPI IRQ initialization */
  57. int acpi_pci_disabled; /* skip ACPI PCI scan and IRQ initialization */
  58. EXPORT_SYMBOL(acpi_pci_disabled);
  59. int acpi_lapic;
  60. int acpi_ioapic;
  61. int acpi_strict;
  62. u8 acpi_sci_flags __initdata;
  63. int acpi_sci_override_gsi __initdata;
  64. int acpi_skip_timer_override __initdata;
  65. int acpi_use_timer_override __initdata;
  66. #ifdef CONFIG_X86_LOCAL_APIC
  67. static u64 acpi_lapic_addr __initdata = APIC_DEFAULT_PHYS_BASE;
  68. #endif
  69. #ifndef __HAVE_ARCH_CMPXCHG
  70. #warning ACPI uses CMPXCHG, i486 and later hardware
  71. #endif
  72. /* --------------------------------------------------------------------------
  73. Boot-time Configuration
  74. -------------------------------------------------------------------------- */
  75. /*
  76. * The default interrupt routing model is PIC (8259). This gets
  77. * overridden if IOAPICs are enumerated (below).
  78. */
  79. enum acpi_irq_model_id acpi_irq_model = ACPI_IRQ_MODEL_PIC;
  80. /*
  81. * ISA irqs by default are the first 16 gsis but can be
  82. * any gsi as specified by an interrupt source override.
  83. */
  84. static u32 isa_irq_to_gsi[NR_IRQS_LEGACY] __read_mostly = {
  85. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
  86. };
  87. static unsigned int gsi_to_irq(unsigned int gsi)
  88. {
  89. unsigned int irq = gsi + NR_IRQS_LEGACY;
  90. unsigned int i;
  91. for (i = 0; i < NR_IRQS_LEGACY; i++) {
  92. if (isa_irq_to_gsi[i] == gsi) {
  93. return i;
  94. }
  95. }
  96. /* Provide an identity mapping of gsi == irq
  97. * except on truly weird platforms that have
  98. * non isa irqs in the first 16 gsis.
  99. */
  100. if (gsi >= NR_IRQS_LEGACY)
  101. irq = gsi;
  102. else
  103. irq = gsi_top + gsi;
  104. return irq;
  105. }
  106. static u32 irq_to_gsi(int irq)
  107. {
  108. unsigned int gsi;
  109. if (irq < NR_IRQS_LEGACY)
  110. gsi = isa_irq_to_gsi[irq];
  111. else if (irq < gsi_top)
  112. gsi = irq;
  113. else if (irq < (gsi_top + NR_IRQS_LEGACY))
  114. gsi = irq - gsi_top;
  115. else
  116. gsi = 0xffffffff;
  117. return gsi;
  118. }
  119. /*
  120. * Temporarily use the virtual area starting from FIX_IO_APIC_BASE_END,
  121. * to map the target physical address. The problem is that set_fixmap()
  122. * provides a single page, and it is possible that the page is not
  123. * sufficient.
  124. * By using this area, we can map up to MAX_IO_APICS pages temporarily,
  125. * i.e. until the next __va_range() call.
  126. *
  127. * Important Safety Note: The fixed I/O APIC page numbers are *subtracted*
  128. * from the fixed base. That's why we start at FIX_IO_APIC_BASE_END and
  129. * count idx down while incrementing the phys address.
  130. */
  131. char *__init __acpi_map_table(unsigned long phys, unsigned long size)
  132. {
  133. if (!phys || !size)
  134. return NULL;
  135. return early_ioremap(phys, size);
  136. }
  137. void __init __acpi_unmap_table(char *map, unsigned long size)
  138. {
  139. if (!map || !size)
  140. return;
  141. early_iounmap(map, size);
  142. }
  143. #ifdef CONFIG_X86_LOCAL_APIC
  144. static int __init acpi_parse_madt(struct acpi_table_header *table)
  145. {
  146. struct acpi_table_madt *madt = NULL;
  147. if (!cpu_has_apic)
  148. return -EINVAL;
  149. madt = (struct acpi_table_madt *)table;
  150. if (!madt) {
  151. printk(KERN_WARNING PREFIX "Unable to map MADT\n");
  152. return -ENODEV;
  153. }
  154. if (madt->address) {
  155. acpi_lapic_addr = (u64) madt->address;
  156. printk(KERN_DEBUG PREFIX "Local APIC address 0x%08x\n",
  157. madt->address);
  158. }
  159. default_acpi_madt_oem_check(madt->header.oem_id,
  160. madt->header.oem_table_id);
  161. return 0;
  162. }
  163. static void __cpuinit acpi_register_lapic(int id, u8 enabled)
  164. {
  165. unsigned int ver = 0;
  166. if (!enabled) {
  167. ++disabled_cpus;
  168. return;
  169. }
  170. if (boot_cpu_physical_apicid != -1U)
  171. ver = apic_version[boot_cpu_physical_apicid];
  172. generic_processor_info(id, ver);
  173. }
  174. static int __init
  175. acpi_parse_x2apic(struct acpi_subtable_header *header, const unsigned long end)
  176. {
  177. struct acpi_madt_local_x2apic *processor = NULL;
  178. processor = (struct acpi_madt_local_x2apic *)header;
  179. if (BAD_MADT_ENTRY(processor, end))
  180. return -EINVAL;
  181. acpi_table_print_madt_entry(header);
  182. #ifdef CONFIG_X86_X2APIC
  183. /*
  184. * We need to register disabled CPU as well to permit
  185. * counting disabled CPUs. This allows us to size
  186. * cpus_possible_map more accurately, to permit
  187. * to not preallocating memory for all NR_CPUS
  188. * when we use CPU hotplug.
  189. */
  190. acpi_register_lapic(processor->local_apic_id, /* APIC ID */
  191. processor->lapic_flags & ACPI_MADT_ENABLED);
  192. #else
  193. printk(KERN_WARNING PREFIX "x2apic entry ignored\n");
  194. #endif
  195. return 0;
  196. }
  197. static int __init
  198. acpi_parse_lapic(struct acpi_subtable_header * header, const unsigned long end)
  199. {
  200. struct acpi_madt_local_apic *processor = NULL;
  201. processor = (struct acpi_madt_local_apic *)header;
  202. if (BAD_MADT_ENTRY(processor, end))
  203. return -EINVAL;
  204. acpi_table_print_madt_entry(header);
  205. /*
  206. * We need to register disabled CPU as well to permit
  207. * counting disabled CPUs. This allows us to size
  208. * cpus_possible_map more accurately, to permit
  209. * to not preallocating memory for all NR_CPUS
  210. * when we use CPU hotplug.
  211. */
  212. acpi_register_lapic(processor->id, /* APIC ID */
  213. processor->lapic_flags & ACPI_MADT_ENABLED);
  214. return 0;
  215. }
  216. static int __init
  217. acpi_parse_sapic(struct acpi_subtable_header *header, const unsigned long end)
  218. {
  219. struct acpi_madt_local_sapic *processor = NULL;
  220. processor = (struct acpi_madt_local_sapic *)header;
  221. if (BAD_MADT_ENTRY(processor, end))
  222. return -EINVAL;
  223. acpi_table_print_madt_entry(header);
  224. acpi_register_lapic((processor->id << 8) | processor->eid,/* APIC ID */
  225. processor->lapic_flags & ACPI_MADT_ENABLED);
  226. return 0;
  227. }
  228. static int __init
  229. acpi_parse_lapic_addr_ovr(struct acpi_subtable_header * header,
  230. const unsigned long end)
  231. {
  232. struct acpi_madt_local_apic_override *lapic_addr_ovr = NULL;
  233. lapic_addr_ovr = (struct acpi_madt_local_apic_override *)header;
  234. if (BAD_MADT_ENTRY(lapic_addr_ovr, end))
  235. return -EINVAL;
  236. acpi_lapic_addr = lapic_addr_ovr->address;
  237. return 0;
  238. }
  239. static int __init
  240. acpi_parse_x2apic_nmi(struct acpi_subtable_header *header,
  241. const unsigned long end)
  242. {
  243. struct acpi_madt_local_x2apic_nmi *x2apic_nmi = NULL;
  244. x2apic_nmi = (struct acpi_madt_local_x2apic_nmi *)header;
  245. if (BAD_MADT_ENTRY(x2apic_nmi, end))
  246. return -EINVAL;
  247. acpi_table_print_madt_entry(header);
  248. if (x2apic_nmi->lint != 1)
  249. printk(KERN_WARNING PREFIX "NMI not connected to LINT 1!\n");
  250. return 0;
  251. }
  252. static int __init
  253. acpi_parse_lapic_nmi(struct acpi_subtable_header * header, const unsigned long end)
  254. {
  255. struct acpi_madt_local_apic_nmi *lapic_nmi = NULL;
  256. lapic_nmi = (struct acpi_madt_local_apic_nmi *)header;
  257. if (BAD_MADT_ENTRY(lapic_nmi, end))
  258. return -EINVAL;
  259. acpi_table_print_madt_entry(header);
  260. if (lapic_nmi->lint != 1)
  261. printk(KERN_WARNING PREFIX "NMI not connected to LINT 1!\n");
  262. return 0;
  263. }
  264. #endif /*CONFIG_X86_LOCAL_APIC */
  265. #ifdef CONFIG_X86_IO_APIC
  266. static int __init
  267. acpi_parse_ioapic(struct acpi_subtable_header * header, const unsigned long end)
  268. {
  269. struct acpi_madt_io_apic *ioapic = NULL;
  270. ioapic = (struct acpi_madt_io_apic *)header;
  271. if (BAD_MADT_ENTRY(ioapic, end))
  272. return -EINVAL;
  273. acpi_table_print_madt_entry(header);
  274. mp_register_ioapic(ioapic->id,
  275. ioapic->address, ioapic->global_irq_base);
  276. return 0;
  277. }
  278. /*
  279. * Parse Interrupt Source Override for the ACPI SCI
  280. */
  281. static void __init acpi_sci_ioapic_setup(u8 bus_irq, u16 polarity, u16 trigger, u32 gsi)
  282. {
  283. if (trigger == 0) /* compatible SCI trigger is level */
  284. trigger = 3;
  285. if (polarity == 0) /* compatible SCI polarity is low */
  286. polarity = 3;
  287. /* Command-line over-ride via acpi_sci= */
  288. if (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK)
  289. trigger = (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK) >> 2;
  290. if (acpi_sci_flags & ACPI_MADT_POLARITY_MASK)
  291. polarity = acpi_sci_flags & ACPI_MADT_POLARITY_MASK;
  292. /*
  293. * mp_config_acpi_legacy_irqs() already setup IRQs < 16
  294. * If GSI is < 16, this will update its flags,
  295. * else it will create a new mp_irqs[] entry.
  296. */
  297. mp_override_legacy_irq(bus_irq, polarity, trigger, gsi);
  298. /*
  299. * stash over-ride to indicate we've been here
  300. * and for later update of acpi_gbl_FADT
  301. */
  302. acpi_sci_override_gsi = gsi;
  303. return;
  304. }
  305. static int __init
  306. acpi_parse_int_src_ovr(struct acpi_subtable_header * header,
  307. const unsigned long end)
  308. {
  309. struct acpi_madt_interrupt_override *intsrc = NULL;
  310. intsrc = (struct acpi_madt_interrupt_override *)header;
  311. if (BAD_MADT_ENTRY(intsrc, end))
  312. return -EINVAL;
  313. acpi_table_print_madt_entry(header);
  314. if (intsrc->source_irq == acpi_gbl_FADT.sci_interrupt) {
  315. acpi_sci_ioapic_setup(intsrc->source_irq,
  316. intsrc->inti_flags & ACPI_MADT_POLARITY_MASK,
  317. (intsrc->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2,
  318. intsrc->global_irq);
  319. return 0;
  320. }
  321. if (acpi_skip_timer_override &&
  322. intsrc->source_irq == 0 && intsrc->global_irq == 2) {
  323. printk(PREFIX "BIOS IRQ0 pin2 override ignored.\n");
  324. return 0;
  325. }
  326. mp_override_legacy_irq(intsrc->source_irq,
  327. intsrc->inti_flags & ACPI_MADT_POLARITY_MASK,
  328. (intsrc->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2,
  329. intsrc->global_irq);
  330. return 0;
  331. }
  332. static int __init
  333. acpi_parse_nmi_src(struct acpi_subtable_header * header, const unsigned long end)
  334. {
  335. struct acpi_madt_nmi_source *nmi_src = NULL;
  336. nmi_src = (struct acpi_madt_nmi_source *)header;
  337. if (BAD_MADT_ENTRY(nmi_src, end))
  338. return -EINVAL;
  339. acpi_table_print_madt_entry(header);
  340. /* TBD: Support nimsrc entries? */
  341. return 0;
  342. }
  343. #endif /* CONFIG_X86_IO_APIC */
  344. /*
  345. * acpi_pic_sci_set_trigger()
  346. *
  347. * use ELCR to set PIC-mode trigger type for SCI
  348. *
  349. * If a PIC-mode SCI is not recognized or gives spurious IRQ7's
  350. * it may require Edge Trigger -- use "acpi_sci=edge"
  351. *
  352. * Port 0x4d0-4d1 are ECLR1 and ECLR2, the Edge/Level Control Registers
  353. * for the 8259 PIC. bit[n] = 1 means irq[n] is Level, otherwise Edge.
  354. * ECLR1 is IRQs 0-7 (IRQ 0, 1, 2 must be 0)
  355. * ECLR2 is IRQs 8-15 (IRQ 8, 13 must be 0)
  356. */
  357. void __init acpi_pic_sci_set_trigger(unsigned int irq, u16 trigger)
  358. {
  359. unsigned int mask = 1 << irq;
  360. unsigned int old, new;
  361. /* Real old ELCR mask */
  362. old = inb(0x4d0) | (inb(0x4d1) << 8);
  363. /*
  364. * If we use ACPI to set PCI IRQs, then we should clear ELCR
  365. * since we will set it correctly as we enable the PCI irq
  366. * routing.
  367. */
  368. new = acpi_noirq ? old : 0;
  369. /*
  370. * Update SCI information in the ELCR, it isn't in the PCI
  371. * routing tables..
  372. */
  373. switch (trigger) {
  374. case 1: /* Edge - clear */
  375. new &= ~mask;
  376. break;
  377. case 3: /* Level - set */
  378. new |= mask;
  379. break;
  380. }
  381. if (old == new)
  382. return;
  383. printk(PREFIX "setting ELCR to %04x (from %04x)\n", new, old);
  384. outb(new, 0x4d0);
  385. outb(new >> 8, 0x4d1);
  386. }
  387. int acpi_gsi_to_irq(u32 gsi, unsigned int *irq)
  388. {
  389. *irq = gsi_to_irq(gsi);
  390. #ifdef CONFIG_X86_IO_APIC
  391. if (acpi_irq_model == ACPI_IRQ_MODEL_IOAPIC)
  392. setup_IO_APIC_irq_extra(gsi);
  393. #endif
  394. return 0;
  395. }
  396. int acpi_isa_irq_to_gsi(unsigned isa_irq, u32 *gsi)
  397. {
  398. if (isa_irq >= 16)
  399. return -1;
  400. *gsi = irq_to_gsi(isa_irq);
  401. return 0;
  402. }
  403. /*
  404. * success: return IRQ number (>=0)
  405. * failure: return < 0
  406. */
  407. int acpi_register_gsi(struct device *dev, u32 gsi, int trigger, int polarity)
  408. {
  409. unsigned int irq;
  410. unsigned int plat_gsi = gsi;
  411. #ifdef CONFIG_PCI
  412. /*
  413. * Make sure all (legacy) PCI IRQs are set as level-triggered.
  414. */
  415. if (acpi_irq_model == ACPI_IRQ_MODEL_PIC) {
  416. if (trigger == ACPI_LEVEL_SENSITIVE)
  417. eisa_set_level_irq(gsi);
  418. }
  419. #endif
  420. #ifdef CONFIG_X86_IO_APIC
  421. if (acpi_irq_model == ACPI_IRQ_MODEL_IOAPIC) {
  422. plat_gsi = mp_register_gsi(dev, gsi, trigger, polarity);
  423. }
  424. #endif
  425. irq = gsi_to_irq(plat_gsi);
  426. return irq;
  427. }
  428. /*
  429. * ACPI based hotplug support for CPU
  430. */
  431. #ifdef CONFIG_ACPI_HOTPLUG_CPU
  432. #include <acpi/processor.h>
  433. static void acpi_map_cpu2node(acpi_handle handle, int cpu, int physid)
  434. {
  435. #ifdef CONFIG_ACPI_NUMA
  436. int nid;
  437. nid = acpi_get_node(handle);
  438. if (nid == -1 || !node_online(nid))
  439. return;
  440. #ifdef CONFIG_X86_64
  441. apicid_to_node[physid] = nid;
  442. numa_set_node(cpu, nid);
  443. #else /* CONFIG_X86_32 */
  444. apicid_2_node[physid] = nid;
  445. cpu_to_node_map[cpu] = nid;
  446. #endif
  447. #endif
  448. }
  449. static int __cpuinit _acpi_map_lsapic(acpi_handle handle, int *pcpu)
  450. {
  451. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  452. union acpi_object *obj;
  453. struct acpi_madt_local_apic *lapic;
  454. cpumask_var_t tmp_map, new_map;
  455. u8 physid;
  456. int cpu;
  457. int retval = -ENOMEM;
  458. if (ACPI_FAILURE(acpi_evaluate_object(handle, "_MAT", NULL, &buffer)))
  459. return -EINVAL;
  460. if (!buffer.length || !buffer.pointer)
  461. return -EINVAL;
  462. obj = buffer.pointer;
  463. if (obj->type != ACPI_TYPE_BUFFER ||
  464. obj->buffer.length < sizeof(*lapic)) {
  465. kfree(buffer.pointer);
  466. return -EINVAL;
  467. }
  468. lapic = (struct acpi_madt_local_apic *)obj->buffer.pointer;
  469. if (lapic->header.type != ACPI_MADT_TYPE_LOCAL_APIC ||
  470. !(lapic->lapic_flags & ACPI_MADT_ENABLED)) {
  471. kfree(buffer.pointer);
  472. return -EINVAL;
  473. }
  474. physid = lapic->id;
  475. kfree(buffer.pointer);
  476. buffer.length = ACPI_ALLOCATE_BUFFER;
  477. buffer.pointer = NULL;
  478. if (!alloc_cpumask_var(&tmp_map, GFP_KERNEL))
  479. goto out;
  480. if (!alloc_cpumask_var(&new_map, GFP_KERNEL))
  481. goto free_tmp_map;
  482. cpumask_copy(tmp_map, cpu_present_mask);
  483. acpi_register_lapic(physid, lapic->lapic_flags & ACPI_MADT_ENABLED);
  484. /*
  485. * If mp_register_lapic successfully generates a new logical cpu
  486. * number, then the following will get us exactly what was mapped
  487. */
  488. cpumask_andnot(new_map, cpu_present_mask, tmp_map);
  489. if (cpumask_empty(new_map)) {
  490. printk ("Unable to map lapic to logical cpu number\n");
  491. retval = -EINVAL;
  492. goto free_new_map;
  493. }
  494. acpi_processor_set_pdc(handle);
  495. cpu = cpumask_first(new_map);
  496. acpi_map_cpu2node(handle, cpu, physid);
  497. *pcpu = cpu;
  498. retval = 0;
  499. free_new_map:
  500. free_cpumask_var(new_map);
  501. free_tmp_map:
  502. free_cpumask_var(tmp_map);
  503. out:
  504. return retval;
  505. }
  506. /* wrapper to silence section mismatch warning */
  507. int __ref acpi_map_lsapic(acpi_handle handle, int *pcpu)
  508. {
  509. return _acpi_map_lsapic(handle, pcpu);
  510. }
  511. EXPORT_SYMBOL(acpi_map_lsapic);
  512. int acpi_unmap_lsapic(int cpu)
  513. {
  514. per_cpu(x86_cpu_to_apicid, cpu) = -1;
  515. set_cpu_present(cpu, false);
  516. num_processors--;
  517. return (0);
  518. }
  519. EXPORT_SYMBOL(acpi_unmap_lsapic);
  520. #endif /* CONFIG_ACPI_HOTPLUG_CPU */
  521. int acpi_register_ioapic(acpi_handle handle, u64 phys_addr, u32 gsi_base)
  522. {
  523. /* TBD */
  524. return -EINVAL;
  525. }
  526. EXPORT_SYMBOL(acpi_register_ioapic);
  527. int acpi_unregister_ioapic(acpi_handle handle, u32 gsi_base)
  528. {
  529. /* TBD */
  530. return -EINVAL;
  531. }
  532. EXPORT_SYMBOL(acpi_unregister_ioapic);
  533. static int __init acpi_parse_sbf(struct acpi_table_header *table)
  534. {
  535. struct acpi_table_boot *sb;
  536. sb = (struct acpi_table_boot *)table;
  537. if (!sb) {
  538. printk(KERN_WARNING PREFIX "Unable to map SBF\n");
  539. return -ENODEV;
  540. }
  541. sbf_port = sb->cmos_index; /* Save CMOS port */
  542. return 0;
  543. }
  544. #ifdef CONFIG_HPET_TIMER
  545. #include <asm/hpet.h>
  546. static struct __initdata resource *hpet_res;
  547. static int __init acpi_parse_hpet(struct acpi_table_header *table)
  548. {
  549. struct acpi_table_hpet *hpet_tbl;
  550. hpet_tbl = (struct acpi_table_hpet *)table;
  551. if (!hpet_tbl) {
  552. printk(KERN_WARNING PREFIX "Unable to map HPET\n");
  553. return -ENODEV;
  554. }
  555. if (hpet_tbl->address.space_id != ACPI_SPACE_MEM) {
  556. printk(KERN_WARNING PREFIX "HPET timers must be located in "
  557. "memory.\n");
  558. return -1;
  559. }
  560. hpet_address = hpet_tbl->address.address;
  561. hpet_blockid = hpet_tbl->sequence;
  562. /*
  563. * Some broken BIOSes advertise HPET at 0x0. We really do not
  564. * want to allocate a resource there.
  565. */
  566. if (!hpet_address) {
  567. printk(KERN_WARNING PREFIX
  568. "HPET id: %#x base: %#lx is invalid\n",
  569. hpet_tbl->id, hpet_address);
  570. return 0;
  571. }
  572. #ifdef CONFIG_X86_64
  573. /*
  574. * Some even more broken BIOSes advertise HPET at
  575. * 0xfed0000000000000 instead of 0xfed00000. Fix it up and add
  576. * some noise:
  577. */
  578. if (hpet_address == 0xfed0000000000000UL) {
  579. if (!hpet_force_user) {
  580. printk(KERN_WARNING PREFIX "HPET id: %#x "
  581. "base: 0xfed0000000000000 is bogus\n "
  582. "try hpet=force on the kernel command line to "
  583. "fix it up to 0xfed00000.\n", hpet_tbl->id);
  584. hpet_address = 0;
  585. return 0;
  586. }
  587. printk(KERN_WARNING PREFIX
  588. "HPET id: %#x base: 0xfed0000000000000 fixed up "
  589. "to 0xfed00000.\n", hpet_tbl->id);
  590. hpet_address >>= 32;
  591. }
  592. #endif
  593. printk(KERN_INFO PREFIX "HPET id: %#x base: %#lx\n",
  594. hpet_tbl->id, hpet_address);
  595. /*
  596. * Allocate and initialize the HPET firmware resource for adding into
  597. * the resource tree during the lateinit timeframe.
  598. */
  599. #define HPET_RESOURCE_NAME_SIZE 9
  600. hpet_res = alloc_bootmem(sizeof(*hpet_res) + HPET_RESOURCE_NAME_SIZE);
  601. hpet_res->name = (void *)&hpet_res[1];
  602. hpet_res->flags = IORESOURCE_MEM;
  603. snprintf((char *)hpet_res->name, HPET_RESOURCE_NAME_SIZE, "HPET %u",
  604. hpet_tbl->sequence);
  605. hpet_res->start = hpet_address;
  606. hpet_res->end = hpet_address + (1 * 1024) - 1;
  607. return 0;
  608. }
  609. /*
  610. * hpet_insert_resource inserts the HPET resources used into the resource
  611. * tree.
  612. */
  613. static __init int hpet_insert_resource(void)
  614. {
  615. if (!hpet_res)
  616. return 1;
  617. return insert_resource(&iomem_resource, hpet_res);
  618. }
  619. late_initcall(hpet_insert_resource);
  620. #else
  621. #define acpi_parse_hpet NULL
  622. #endif
  623. static int __init acpi_parse_fadt(struct acpi_table_header *table)
  624. {
  625. #ifdef CONFIG_X86_PM_TIMER
  626. /* detect the location of the ACPI PM Timer */
  627. if (acpi_gbl_FADT.header.revision >= FADT2_REVISION_ID) {
  628. /* FADT rev. 2 */
  629. if (acpi_gbl_FADT.xpm_timer_block.space_id !=
  630. ACPI_ADR_SPACE_SYSTEM_IO)
  631. return 0;
  632. pmtmr_ioport = acpi_gbl_FADT.xpm_timer_block.address;
  633. /*
  634. * "X" fields are optional extensions to the original V1.0
  635. * fields, so we must selectively expand V1.0 fields if the
  636. * corresponding X field is zero.
  637. */
  638. if (!pmtmr_ioport)
  639. pmtmr_ioport = acpi_gbl_FADT.pm_timer_block;
  640. } else {
  641. /* FADT rev. 1 */
  642. pmtmr_ioport = acpi_gbl_FADT.pm_timer_block;
  643. }
  644. if (pmtmr_ioport)
  645. printk(KERN_INFO PREFIX "PM-Timer IO Port: %#x\n",
  646. pmtmr_ioport);
  647. #endif
  648. return 0;
  649. }
  650. #ifdef CONFIG_X86_LOCAL_APIC
  651. /*
  652. * Parse LAPIC entries in MADT
  653. * returns 0 on success, < 0 on error
  654. */
  655. static void __init acpi_register_lapic_address(unsigned long address)
  656. {
  657. mp_lapic_addr = address;
  658. set_fixmap_nocache(FIX_APIC_BASE, address);
  659. if (boot_cpu_physical_apicid == -1U) {
  660. boot_cpu_physical_apicid = read_apic_id();
  661. apic_version[boot_cpu_physical_apicid] =
  662. GET_APIC_VERSION(apic_read(APIC_LVR));
  663. }
  664. }
  665. static int __init early_acpi_parse_madt_lapic_addr_ovr(void)
  666. {
  667. int count;
  668. if (!cpu_has_apic)
  669. return -ENODEV;
  670. /*
  671. * Note that the LAPIC address is obtained from the MADT (32-bit value)
  672. * and (optionally) overriden by a LAPIC_ADDR_OVR entry (64-bit value).
  673. */
  674. count =
  675. acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE,
  676. acpi_parse_lapic_addr_ovr, 0);
  677. if (count < 0) {
  678. printk(KERN_ERR PREFIX
  679. "Error parsing LAPIC address override entry\n");
  680. return count;
  681. }
  682. acpi_register_lapic_address(acpi_lapic_addr);
  683. return count;
  684. }
  685. static int __init acpi_parse_madt_lapic_entries(void)
  686. {
  687. int count;
  688. int x2count = 0;
  689. if (!cpu_has_apic)
  690. return -ENODEV;
  691. /*
  692. * Note that the LAPIC address is obtained from the MADT (32-bit value)
  693. * and (optionally) overriden by a LAPIC_ADDR_OVR entry (64-bit value).
  694. */
  695. count =
  696. acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE,
  697. acpi_parse_lapic_addr_ovr, 0);
  698. if (count < 0) {
  699. printk(KERN_ERR PREFIX
  700. "Error parsing LAPIC address override entry\n");
  701. return count;
  702. }
  703. acpi_register_lapic_address(acpi_lapic_addr);
  704. count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_SAPIC,
  705. acpi_parse_sapic, MAX_APICS);
  706. if (!count) {
  707. x2count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_X2APIC,
  708. acpi_parse_x2apic, MAX_APICS);
  709. count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC,
  710. acpi_parse_lapic, MAX_APICS);
  711. }
  712. if (!count && !x2count) {
  713. printk(KERN_ERR PREFIX "No LAPIC entries present\n");
  714. /* TBD: Cleanup to allow fallback to MPS */
  715. return -ENODEV;
  716. } else if (count < 0 || x2count < 0) {
  717. printk(KERN_ERR PREFIX "Error parsing LAPIC entry\n");
  718. /* TBD: Cleanup to allow fallback to MPS */
  719. return count;
  720. }
  721. x2count =
  722. acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_X2APIC_NMI,
  723. acpi_parse_x2apic_nmi, 0);
  724. count =
  725. acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_NMI, acpi_parse_lapic_nmi, 0);
  726. if (count < 0 || x2count < 0) {
  727. printk(KERN_ERR PREFIX "Error parsing LAPIC NMI entry\n");
  728. /* TBD: Cleanup to allow fallback to MPS */
  729. return count;
  730. }
  731. return 0;
  732. }
  733. #endif /* CONFIG_X86_LOCAL_APIC */
  734. #ifdef CONFIG_X86_IO_APIC
  735. #define MP_ISA_BUS 0
  736. #ifdef CONFIG_X86_ES7000
  737. extern int es7000_plat;
  738. #endif
  739. static void assign_to_mp_irq(struct mpc_intsrc *m,
  740. struct mpc_intsrc *mp_irq)
  741. {
  742. memcpy(mp_irq, m, sizeof(struct mpc_intsrc));
  743. }
  744. static int mp_irq_cmp(struct mpc_intsrc *mp_irq,
  745. struct mpc_intsrc *m)
  746. {
  747. return memcmp(mp_irq, m, sizeof(struct mpc_intsrc));
  748. }
  749. static void save_mp_irq(struct mpc_intsrc *m)
  750. {
  751. int i;
  752. for (i = 0; i < mp_irq_entries; i++) {
  753. if (!mp_irq_cmp(&mp_irqs[i], m))
  754. return;
  755. }
  756. assign_to_mp_irq(m, &mp_irqs[mp_irq_entries]);
  757. if (++mp_irq_entries == MAX_IRQ_SOURCES)
  758. panic("Max # of irq sources exceeded!!\n");
  759. }
  760. void __init mp_override_legacy_irq(u8 bus_irq, u8 polarity, u8 trigger, u32 gsi)
  761. {
  762. int ioapic;
  763. int pin;
  764. struct mpc_intsrc mp_irq;
  765. /*
  766. * Convert 'gsi' to 'ioapic.pin'.
  767. */
  768. ioapic = mp_find_ioapic(gsi);
  769. if (ioapic < 0)
  770. return;
  771. pin = mp_find_ioapic_pin(ioapic, gsi);
  772. /*
  773. * TBD: This check is for faulty timer entries, where the override
  774. * erroneously sets the trigger to level, resulting in a HUGE
  775. * increase of timer interrupts!
  776. */
  777. if ((bus_irq == 0) && (trigger == 3))
  778. trigger = 1;
  779. mp_irq.type = MP_INTSRC;
  780. mp_irq.irqtype = mp_INT;
  781. mp_irq.irqflag = (trigger << 2) | polarity;
  782. mp_irq.srcbus = MP_ISA_BUS;
  783. mp_irq.srcbusirq = bus_irq; /* IRQ */
  784. mp_irq.dstapic = mp_ioapics[ioapic].apicid; /* APIC ID */
  785. mp_irq.dstirq = pin; /* INTIN# */
  786. save_mp_irq(&mp_irq);
  787. isa_irq_to_gsi[bus_irq] = gsi;
  788. }
  789. void __init mp_config_acpi_legacy_irqs(void)
  790. {
  791. int i;
  792. struct mpc_intsrc mp_irq;
  793. #if defined (CONFIG_MCA) || defined (CONFIG_EISA)
  794. /*
  795. * Fabricate the legacy ISA bus (bus #31).
  796. */
  797. mp_bus_id_to_type[MP_ISA_BUS] = MP_BUS_ISA;
  798. #endif
  799. set_bit(MP_ISA_BUS, mp_bus_not_pci);
  800. pr_debug("Bus #%d is ISA\n", MP_ISA_BUS);
  801. #ifdef CONFIG_X86_ES7000
  802. /*
  803. * Older generations of ES7000 have no legacy identity mappings
  804. */
  805. if (es7000_plat == 1)
  806. return;
  807. #endif
  808. /*
  809. * Use the default configuration for the IRQs 0-15. Unless
  810. * overridden by (MADT) interrupt source override entries.
  811. */
  812. for (i = 0; i < 16; i++) {
  813. int ioapic, pin;
  814. unsigned int dstapic;
  815. int idx;
  816. u32 gsi;
  817. /* Locate the gsi that irq i maps to. */
  818. if (acpi_isa_irq_to_gsi(i, &gsi))
  819. continue;
  820. /*
  821. * Locate the IOAPIC that manages the ISA IRQ.
  822. */
  823. ioapic = mp_find_ioapic(gsi);
  824. if (ioapic < 0)
  825. continue;
  826. pin = mp_find_ioapic_pin(ioapic, gsi);
  827. dstapic = mp_ioapics[ioapic].apicid;
  828. for (idx = 0; idx < mp_irq_entries; idx++) {
  829. struct mpc_intsrc *irq = mp_irqs + idx;
  830. /* Do we already have a mapping for this ISA IRQ? */
  831. if (irq->srcbus == MP_ISA_BUS && irq->srcbusirq == i)
  832. break;
  833. /* Do we already have a mapping for this IOAPIC pin */
  834. if (irq->dstapic == dstapic && irq->dstirq == pin)
  835. break;
  836. }
  837. if (idx != mp_irq_entries) {
  838. printk(KERN_DEBUG "ACPI: IRQ%d used by override.\n", i);
  839. continue; /* IRQ already used */
  840. }
  841. mp_irq.type = MP_INTSRC;
  842. mp_irq.irqflag = 0; /* Conforming */
  843. mp_irq.srcbus = MP_ISA_BUS;
  844. mp_irq.dstapic = dstapic;
  845. mp_irq.irqtype = mp_INT;
  846. mp_irq.srcbusirq = i; /* Identity mapped */
  847. mp_irq.dstirq = pin;
  848. save_mp_irq(&mp_irq);
  849. }
  850. }
  851. static int mp_config_acpi_gsi(struct device *dev, u32 gsi, int trigger,
  852. int polarity)
  853. {
  854. #ifdef CONFIG_X86_MPPARSE
  855. struct mpc_intsrc mp_irq;
  856. struct pci_dev *pdev;
  857. unsigned char number;
  858. unsigned int devfn;
  859. int ioapic;
  860. u8 pin;
  861. if (!acpi_ioapic)
  862. return 0;
  863. if (!dev)
  864. return 0;
  865. if (dev->bus != &pci_bus_type)
  866. return 0;
  867. pdev = to_pci_dev(dev);
  868. number = pdev->bus->number;
  869. devfn = pdev->devfn;
  870. pin = pdev->pin;
  871. /* print the entry should happen on mptable identically */
  872. mp_irq.type = MP_INTSRC;
  873. mp_irq.irqtype = mp_INT;
  874. mp_irq.irqflag = (trigger == ACPI_EDGE_SENSITIVE ? 4 : 0x0c) |
  875. (polarity == ACPI_ACTIVE_HIGH ? 1 : 3);
  876. mp_irq.srcbus = number;
  877. mp_irq.srcbusirq = (((devfn >> 3) & 0x1f) << 2) | ((pin - 1) & 3);
  878. ioapic = mp_find_ioapic(gsi);
  879. mp_irq.dstapic = mp_ioapics[ioapic].apicid;
  880. mp_irq.dstirq = mp_find_ioapic_pin(ioapic, gsi);
  881. save_mp_irq(&mp_irq);
  882. #endif
  883. return 0;
  884. }
  885. int mp_register_gsi(struct device *dev, u32 gsi, int trigger, int polarity)
  886. {
  887. int ioapic;
  888. int ioapic_pin;
  889. struct io_apic_irq_attr irq_attr;
  890. if (acpi_irq_model != ACPI_IRQ_MODEL_IOAPIC)
  891. return gsi;
  892. /* Don't set up the ACPI SCI because it's already set up */
  893. if (acpi_gbl_FADT.sci_interrupt == gsi)
  894. return gsi;
  895. ioapic = mp_find_ioapic(gsi);
  896. if (ioapic < 0) {
  897. printk(KERN_WARNING "No IOAPIC for GSI %u\n", gsi);
  898. return gsi;
  899. }
  900. ioapic_pin = mp_find_ioapic_pin(ioapic, gsi);
  901. if (ioapic_pin > MP_MAX_IOAPIC_PIN) {
  902. printk(KERN_ERR "Invalid reference to IOAPIC pin "
  903. "%d-%d\n", mp_ioapics[ioapic].apicid,
  904. ioapic_pin);
  905. return gsi;
  906. }
  907. if (enable_update_mptable)
  908. mp_config_acpi_gsi(dev, gsi, trigger, polarity);
  909. set_io_apic_irq_attr(&irq_attr, ioapic, ioapic_pin,
  910. trigger == ACPI_EDGE_SENSITIVE ? 0 : 1,
  911. polarity == ACPI_ACTIVE_HIGH ? 0 : 1);
  912. io_apic_set_pci_routing(dev, gsi_to_irq(gsi), &irq_attr);
  913. return gsi;
  914. }
  915. /*
  916. * Parse IOAPIC related entries in MADT
  917. * returns 0 on success, < 0 on error
  918. */
  919. static int __init acpi_parse_madt_ioapic_entries(void)
  920. {
  921. int count;
  922. /*
  923. * ACPI interpreter is required to complete interrupt setup,
  924. * so if it is off, don't enumerate the io-apics with ACPI.
  925. * If MPS is present, it will handle them,
  926. * otherwise the system will stay in PIC mode
  927. */
  928. if (acpi_disabled || acpi_noirq)
  929. return -ENODEV;
  930. if (!cpu_has_apic)
  931. return -ENODEV;
  932. /*
  933. * if "noapic" boot option, don't look for IO-APICs
  934. */
  935. if (skip_ioapic_setup) {
  936. printk(KERN_INFO PREFIX "Skipping IOAPIC probe "
  937. "due to 'noapic' option.\n");
  938. return -ENODEV;
  939. }
  940. count =
  941. acpi_table_parse_madt(ACPI_MADT_TYPE_IO_APIC, acpi_parse_ioapic,
  942. MAX_IO_APICS);
  943. if (!count) {
  944. printk(KERN_ERR PREFIX "No IOAPIC entries present\n");
  945. return -ENODEV;
  946. } else if (count < 0) {
  947. printk(KERN_ERR PREFIX "Error parsing IOAPIC entry\n");
  948. return count;
  949. }
  950. count =
  951. acpi_table_parse_madt(ACPI_MADT_TYPE_INTERRUPT_OVERRIDE, acpi_parse_int_src_ovr,
  952. nr_irqs);
  953. if (count < 0) {
  954. printk(KERN_ERR PREFIX
  955. "Error parsing interrupt source overrides entry\n");
  956. /* TBD: Cleanup to allow fallback to MPS */
  957. return count;
  958. }
  959. /*
  960. * If BIOS did not supply an INT_SRC_OVR for the SCI
  961. * pretend we got one so we can set the SCI flags.
  962. */
  963. if (!acpi_sci_override_gsi)
  964. acpi_sci_ioapic_setup(acpi_gbl_FADT.sci_interrupt, 0, 0,
  965. acpi_gbl_FADT.sci_interrupt);
  966. /* Fill in identity legacy mappings where no override */
  967. mp_config_acpi_legacy_irqs();
  968. count =
  969. acpi_table_parse_madt(ACPI_MADT_TYPE_NMI_SOURCE, acpi_parse_nmi_src,
  970. nr_irqs);
  971. if (count < 0) {
  972. printk(KERN_ERR PREFIX "Error parsing NMI SRC entry\n");
  973. /* TBD: Cleanup to allow fallback to MPS */
  974. return count;
  975. }
  976. return 0;
  977. }
  978. #else
  979. static inline int acpi_parse_madt_ioapic_entries(void)
  980. {
  981. return -1;
  982. }
  983. #endif /* !CONFIG_X86_IO_APIC */
  984. static void __init early_acpi_process_madt(void)
  985. {
  986. #ifdef CONFIG_X86_LOCAL_APIC
  987. int error;
  988. if (!acpi_table_parse(ACPI_SIG_MADT, acpi_parse_madt)) {
  989. /*
  990. * Parse MADT LAPIC entries
  991. */
  992. error = early_acpi_parse_madt_lapic_addr_ovr();
  993. if (!error) {
  994. acpi_lapic = 1;
  995. smp_found_config = 1;
  996. }
  997. if (error == -EINVAL) {
  998. /*
  999. * Dell Precision Workstation 410, 610 come here.
  1000. */
  1001. printk(KERN_ERR PREFIX
  1002. "Invalid BIOS MADT, disabling ACPI\n");
  1003. disable_acpi();
  1004. }
  1005. }
  1006. #endif
  1007. }
  1008. static void __init acpi_process_madt(void)
  1009. {
  1010. #ifdef CONFIG_X86_LOCAL_APIC
  1011. int error;
  1012. if (!acpi_table_parse(ACPI_SIG_MADT, acpi_parse_madt)) {
  1013. /*
  1014. * Parse MADT LAPIC entries
  1015. */
  1016. error = acpi_parse_madt_lapic_entries();
  1017. if (!error) {
  1018. acpi_lapic = 1;
  1019. /*
  1020. * Parse MADT IO-APIC entries
  1021. */
  1022. error = acpi_parse_madt_ioapic_entries();
  1023. if (!error) {
  1024. acpi_irq_model = ACPI_IRQ_MODEL_IOAPIC;
  1025. acpi_ioapic = 1;
  1026. smp_found_config = 1;
  1027. }
  1028. }
  1029. if (error == -EINVAL) {
  1030. /*
  1031. * Dell Precision Workstation 410, 610 come here.
  1032. */
  1033. printk(KERN_ERR PREFIX
  1034. "Invalid BIOS MADT, disabling ACPI\n");
  1035. disable_acpi();
  1036. }
  1037. } else {
  1038. /*
  1039. * ACPI found no MADT, and so ACPI wants UP PIC mode.
  1040. * In the event an MPS table was found, forget it.
  1041. * Boot with "acpi=off" to use MPS on such a system.
  1042. */
  1043. if (smp_found_config) {
  1044. printk(KERN_WARNING PREFIX
  1045. "No APIC-table, disabling MPS\n");
  1046. smp_found_config = 0;
  1047. }
  1048. }
  1049. /*
  1050. * ACPI supports both logical (e.g. Hyper-Threading) and physical
  1051. * processors, where MPS only supports physical.
  1052. */
  1053. if (acpi_lapic && acpi_ioapic)
  1054. printk(KERN_INFO "Using ACPI (MADT) for SMP configuration "
  1055. "information\n");
  1056. else if (acpi_lapic)
  1057. printk(KERN_INFO "Using ACPI for processor (LAPIC) "
  1058. "configuration information\n");
  1059. #endif
  1060. return;
  1061. }
  1062. static int __init disable_acpi_irq(const struct dmi_system_id *d)
  1063. {
  1064. if (!acpi_force) {
  1065. printk(KERN_NOTICE "%s detected: force use of acpi=noirq\n",
  1066. d->ident);
  1067. acpi_noirq_set();
  1068. }
  1069. return 0;
  1070. }
  1071. static int __init disable_acpi_pci(const struct dmi_system_id *d)
  1072. {
  1073. if (!acpi_force) {
  1074. printk(KERN_NOTICE "%s detected: force use of pci=noacpi\n",
  1075. d->ident);
  1076. acpi_disable_pci();
  1077. }
  1078. return 0;
  1079. }
  1080. static int __init dmi_disable_acpi(const struct dmi_system_id *d)
  1081. {
  1082. if (!acpi_force) {
  1083. printk(KERN_NOTICE "%s detected: acpi off\n", d->ident);
  1084. disable_acpi();
  1085. } else {
  1086. printk(KERN_NOTICE
  1087. "Warning: DMI blacklist says broken, but acpi forced\n");
  1088. }
  1089. return 0;
  1090. }
  1091. /*
  1092. * Force ignoring BIOS IRQ0 pin2 override
  1093. */
  1094. static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
  1095. {
  1096. /*
  1097. * The ati_ixp4x0_rev() early PCI quirk should have set
  1098. * the acpi_skip_timer_override flag already:
  1099. */
  1100. if (!acpi_skip_timer_override) {
  1101. WARN(1, KERN_ERR "ati_ixp4x0 quirk not complete.\n");
  1102. pr_notice("%s detected: Ignoring BIOS IRQ0 pin2 override\n",
  1103. d->ident);
  1104. acpi_skip_timer_override = 1;
  1105. }
  1106. return 0;
  1107. }
  1108. /*
  1109. * If your system is blacklisted here, but you find that acpi=force
  1110. * works for you, please contact linux-acpi@vger.kernel.org
  1111. */
  1112. static struct dmi_system_id __initdata acpi_dmi_table[] = {
  1113. /*
  1114. * Boxes that need ACPI disabled
  1115. */
  1116. {
  1117. .callback = dmi_disable_acpi,
  1118. .ident = "IBM Thinkpad",
  1119. .matches = {
  1120. DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
  1121. DMI_MATCH(DMI_BOARD_NAME, "2629H1G"),
  1122. },
  1123. },
  1124. /*
  1125. * Boxes that need ACPI PCI IRQ routing disabled
  1126. */
  1127. {
  1128. .callback = disable_acpi_irq,
  1129. .ident = "ASUS A7V",
  1130. .matches = {
  1131. DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC"),
  1132. DMI_MATCH(DMI_BOARD_NAME, "<A7V>"),
  1133. /* newer BIOS, Revision 1011, does work */
  1134. DMI_MATCH(DMI_BIOS_VERSION,
  1135. "ASUS A7V ACPI BIOS Revision 1007"),
  1136. },
  1137. },
  1138. {
  1139. /*
  1140. * Latest BIOS for IBM 600E (1.16) has bad pcinum
  1141. * for LPC bridge, which is needed for the PCI
  1142. * interrupt links to work. DSDT fix is in bug 5966.
  1143. * 2645, 2646 model numbers are shared with 600/600E/600X
  1144. */
  1145. .callback = disable_acpi_irq,
  1146. .ident = "IBM Thinkpad 600 Series 2645",
  1147. .matches = {
  1148. DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
  1149. DMI_MATCH(DMI_BOARD_NAME, "2645"),
  1150. },
  1151. },
  1152. {
  1153. .callback = disable_acpi_irq,
  1154. .ident = "IBM Thinkpad 600 Series 2646",
  1155. .matches = {
  1156. DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
  1157. DMI_MATCH(DMI_BOARD_NAME, "2646"),
  1158. },
  1159. },
  1160. /*
  1161. * Boxes that need ACPI PCI IRQ routing and PCI scan disabled
  1162. */
  1163. { /* _BBN 0 bug */
  1164. .callback = disable_acpi_pci,
  1165. .ident = "ASUS PR-DLS",
  1166. .matches = {
  1167. DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
  1168. DMI_MATCH(DMI_BOARD_NAME, "PR-DLS"),
  1169. DMI_MATCH(DMI_BIOS_VERSION,
  1170. "ASUS PR-DLS ACPI BIOS Revision 1010"),
  1171. DMI_MATCH(DMI_BIOS_DATE, "03/21/2003")
  1172. },
  1173. },
  1174. {
  1175. .callback = disable_acpi_pci,
  1176. .ident = "Acer TravelMate 36x Laptop",
  1177. .matches = {
  1178. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  1179. DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 360"),
  1180. },
  1181. },
  1182. {}
  1183. };
  1184. /* second table for DMI checks that should run after early-quirks */
  1185. static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
  1186. /*
  1187. * HP laptops which use a DSDT reporting as HP/SB400/10000,
  1188. * which includes some code which overrides all temperature
  1189. * trip points to 16C if the INTIN2 input of the I/O APIC
  1190. * is enabled. This input is incorrectly designated the
  1191. * ISA IRQ 0 via an interrupt source override even though
  1192. * it is wired to the output of the master 8259A and INTIN0
  1193. * is not connected at all. Force ignoring BIOS IRQ0 pin2
  1194. * override in that cases.
  1195. */
  1196. {
  1197. .callback = dmi_ignore_irq0_timer_override,
  1198. .ident = "HP nx6115 laptop",
  1199. .matches = {
  1200. DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
  1201. DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6115"),
  1202. },
  1203. },
  1204. {
  1205. .callback = dmi_ignore_irq0_timer_override,
  1206. .ident = "HP NX6125 laptop",
  1207. .matches = {
  1208. DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
  1209. DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6125"),
  1210. },
  1211. },
  1212. {
  1213. .callback = dmi_ignore_irq0_timer_override,
  1214. .ident = "HP NX6325 laptop",
  1215. .matches = {
  1216. DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
  1217. DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6325"),
  1218. },
  1219. },
  1220. {
  1221. .callback = dmi_ignore_irq0_timer_override,
  1222. .ident = "HP 6715b laptop",
  1223. .matches = {
  1224. DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
  1225. DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq 6715b"),
  1226. },
  1227. },
  1228. {}
  1229. };
  1230. /*
  1231. * acpi_boot_table_init() and acpi_boot_init()
  1232. * called from setup_arch(), always.
  1233. * 1. checksums all tables
  1234. * 2. enumerates lapics
  1235. * 3. enumerates io-apics
  1236. *
  1237. * acpi_table_init() is separate to allow reading SRAT without
  1238. * other side effects.
  1239. *
  1240. * side effects of acpi_boot_init:
  1241. * acpi_lapic = 1 if LAPIC found
  1242. * acpi_ioapic = 1 if IOAPIC found
  1243. * if (acpi_lapic && acpi_ioapic) smp_found_config = 1;
  1244. * if acpi_blacklisted() acpi_disabled = 1;
  1245. * acpi_irq_model=...
  1246. * ...
  1247. */
  1248. void __init acpi_boot_table_init(void)
  1249. {
  1250. dmi_check_system(acpi_dmi_table);
  1251. /*
  1252. * If acpi_disabled, bail out
  1253. */
  1254. if (acpi_disabled)
  1255. return;
  1256. /*
  1257. * Initialize the ACPI boot-time table parser.
  1258. */
  1259. if (acpi_table_init()) {
  1260. disable_acpi();
  1261. return;
  1262. }
  1263. acpi_table_parse(ACPI_SIG_BOOT, acpi_parse_sbf);
  1264. /*
  1265. * blacklist may disable ACPI entirely
  1266. */
  1267. if (acpi_blacklisted()) {
  1268. if (acpi_force) {
  1269. printk(KERN_WARNING PREFIX "acpi=force override\n");
  1270. } else {
  1271. printk(KERN_WARNING PREFIX "Disabling ACPI support\n");
  1272. disable_acpi();
  1273. return;
  1274. }
  1275. }
  1276. }
  1277. int __init early_acpi_boot_init(void)
  1278. {
  1279. /*
  1280. * If acpi_disabled, bail out
  1281. */
  1282. if (acpi_disabled)
  1283. return 1;
  1284. /*
  1285. * Process the Multiple APIC Description Table (MADT), if present
  1286. */
  1287. early_acpi_process_madt();
  1288. return 0;
  1289. }
  1290. int __init acpi_boot_init(void)
  1291. {
  1292. /* those are executed after early-quirks are executed */
  1293. dmi_check_system(acpi_dmi_table_late);
  1294. /*
  1295. * If acpi_disabled, bail out
  1296. */
  1297. if (acpi_disabled)
  1298. return 1;
  1299. acpi_table_parse(ACPI_SIG_BOOT, acpi_parse_sbf);
  1300. /*
  1301. * set sci_int and PM timer address
  1302. */
  1303. acpi_table_parse(ACPI_SIG_FADT, acpi_parse_fadt);
  1304. /*
  1305. * Process the Multiple APIC Description Table (MADT), if present
  1306. */
  1307. acpi_process_madt();
  1308. acpi_table_parse(ACPI_SIG_HPET, acpi_parse_hpet);
  1309. if (!acpi_noirq)
  1310. x86_init.pci.init = pci_acpi_init;
  1311. return 0;
  1312. }
  1313. static int __init parse_acpi(char *arg)
  1314. {
  1315. if (!arg)
  1316. return -EINVAL;
  1317. /* "acpi=off" disables both ACPI table parsing and interpreter */
  1318. if (strcmp(arg, "off") == 0) {
  1319. disable_acpi();
  1320. }
  1321. /* acpi=force to over-ride black-list */
  1322. else if (strcmp(arg, "force") == 0) {
  1323. acpi_force = 1;
  1324. acpi_disabled = 0;
  1325. }
  1326. /* acpi=strict disables out-of-spec workarounds */
  1327. else if (strcmp(arg, "strict") == 0) {
  1328. acpi_strict = 1;
  1329. }
  1330. /* acpi=rsdt use RSDT instead of XSDT */
  1331. else if (strcmp(arg, "rsdt") == 0) {
  1332. acpi_rsdt_forced = 1;
  1333. }
  1334. /* "acpi=noirq" disables ACPI interrupt routing */
  1335. else if (strcmp(arg, "noirq") == 0) {
  1336. acpi_noirq_set();
  1337. }
  1338. /* "acpi=copy_dsdt" copys DSDT */
  1339. else if (strcmp(arg, "copy_dsdt") == 0) {
  1340. acpi_gbl_copy_dsdt_locally = 1;
  1341. } else {
  1342. /* Core will printk when we return error. */
  1343. return -EINVAL;
  1344. }
  1345. return 0;
  1346. }
  1347. early_param("acpi", parse_acpi);
  1348. /* FIXME: Using pci= for an ACPI parameter is a travesty. */
  1349. static int __init parse_pci(char *arg)
  1350. {
  1351. if (arg && strcmp(arg, "noacpi") == 0)
  1352. acpi_disable_pci();
  1353. return 0;
  1354. }
  1355. early_param("pci", parse_pci);
  1356. int __init acpi_mps_check(void)
  1357. {
  1358. #if defined(CONFIG_X86_LOCAL_APIC) && !defined(CONFIG_X86_MPPARSE)
  1359. /* mptable code is not built-in*/
  1360. if (acpi_disabled || acpi_noirq) {
  1361. printk(KERN_WARNING "MPS support code is not built-in.\n"
  1362. "Using acpi=off or acpi=noirq or pci=noacpi "
  1363. "may have problem\n");
  1364. return 1;
  1365. }
  1366. #endif
  1367. return 0;
  1368. }
  1369. #ifdef CONFIG_X86_IO_APIC
  1370. static int __init parse_acpi_skip_timer_override(char *arg)
  1371. {
  1372. acpi_skip_timer_override = 1;
  1373. return 0;
  1374. }
  1375. early_param("acpi_skip_timer_override", parse_acpi_skip_timer_override);
  1376. static int __init parse_acpi_use_timer_override(char *arg)
  1377. {
  1378. acpi_use_timer_override = 1;
  1379. return 0;
  1380. }
  1381. early_param("acpi_use_timer_override", parse_acpi_use_timer_override);
  1382. #endif /* CONFIG_X86_IO_APIC */
  1383. static int __init setup_acpi_sci(char *s)
  1384. {
  1385. if (!s)
  1386. return -EINVAL;
  1387. if (!strcmp(s, "edge"))
  1388. acpi_sci_flags = ACPI_MADT_TRIGGER_EDGE |
  1389. (acpi_sci_flags & ~ACPI_MADT_TRIGGER_MASK);
  1390. else if (!strcmp(s, "level"))
  1391. acpi_sci_flags = ACPI_MADT_TRIGGER_LEVEL |
  1392. (acpi_sci_flags & ~ACPI_MADT_TRIGGER_MASK);
  1393. else if (!strcmp(s, "high"))
  1394. acpi_sci_flags = ACPI_MADT_POLARITY_ACTIVE_HIGH |
  1395. (acpi_sci_flags & ~ACPI_MADT_POLARITY_MASK);
  1396. else if (!strcmp(s, "low"))
  1397. acpi_sci_flags = ACPI_MADT_POLARITY_ACTIVE_LOW |
  1398. (acpi_sci_flags & ~ACPI_MADT_POLARITY_MASK);
  1399. else
  1400. return -EINVAL;
  1401. return 0;
  1402. }
  1403. early_param("acpi_sci", setup_acpi_sci);
  1404. int __acpi_acquire_global_lock(unsigned int *lock)
  1405. {
  1406. unsigned int old, new, val;
  1407. do {
  1408. old = *lock;
  1409. new = (((old & ~0x3) + 2) + ((old >> 1) & 0x1));
  1410. val = cmpxchg(lock, old, new);
  1411. } while (unlikely (val != old));
  1412. return (new < 3) ? -1 : 0;
  1413. }
  1414. int __acpi_release_global_lock(unsigned int *lock)
  1415. {
  1416. unsigned int old, new, val;
  1417. do {
  1418. old = *lock;
  1419. new = old & ~0x3;
  1420. val = cmpxchg(lock, old, new);
  1421. } while (unlikely (val != old));
  1422. return old & 0x1;
  1423. }