boot.c 39 KB

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