boot.c 44 KB

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