boot.c 41 KB

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