boot.c 41 KB

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