boot.c 40 KB

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