boot.c 41 KB

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