boot.c 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744
  1. /*
  2. * boot.c - Architecture-Specific Low-Level ACPI Boot Support
  3. *
  4. * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
  5. * Copyright (C) 2001 Jun Nakajima <jun.nakajima@intel.com>
  6. *
  7. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. *
  23. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  24. */
  25. #include <linux/init.h>
  26. #include <linux/acpi.h>
  27. #include <linux/acpi_pmtmr.h>
  28. #include <linux/efi.h>
  29. #include <linux/cpumask.h>
  30. #include <linux/module.h>
  31. #include <linux/dmi.h>
  32. #include <linux/irq.h>
  33. #include <linux/bootmem.h>
  34. #include <linux/ioport.h>
  35. #include <linux/pci.h>
  36. #include <asm/pgtable.h>
  37. #include <asm/io_apic.h>
  38. #include <asm/apic.h>
  39. #include <asm/io.h>
  40. #include <asm/mpspec.h>
  41. #include <asm/smp.h>
  42. static int __initdata acpi_force = 0;
  43. u32 acpi_rsdt_forced;
  44. int acpi_disabled;
  45. EXPORT_SYMBOL(acpi_disabled);
  46. #ifdef CONFIG_X86_64
  47. # include <asm/proto.h>
  48. # include <asm/numa_64.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 void acpi_map_cpu2node(acpi_handle handle, int cpu, int physid)
  381. {
  382. #ifdef CONFIG_ACPI_NUMA
  383. int nid;
  384. nid = acpi_get_node(handle);
  385. if (nid == -1 || !node_online(nid))
  386. return;
  387. #ifdef CONFIG_X86_64
  388. apicid_to_node[physid] = nid;
  389. numa_set_node(cpu, nid);
  390. #else /* CONFIG_X86_32 */
  391. apicid_2_node[physid] = nid;
  392. cpu_to_node_map[cpu] = nid;
  393. #endif
  394. #endif
  395. }
  396. static int __cpuinit _acpi_map_lsapic(acpi_handle handle, int *pcpu)
  397. {
  398. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  399. union acpi_object *obj;
  400. struct acpi_madt_local_apic *lapic;
  401. cpumask_var_t tmp_map, new_map;
  402. u8 physid;
  403. int cpu;
  404. int retval = -ENOMEM;
  405. if (ACPI_FAILURE(acpi_evaluate_object(handle, "_MAT", NULL, &buffer)))
  406. return -EINVAL;
  407. if (!buffer.length || !buffer.pointer)
  408. return -EINVAL;
  409. obj = buffer.pointer;
  410. if (obj->type != ACPI_TYPE_BUFFER ||
  411. obj->buffer.length < sizeof(*lapic)) {
  412. kfree(buffer.pointer);
  413. return -EINVAL;
  414. }
  415. lapic = (struct acpi_madt_local_apic *)obj->buffer.pointer;
  416. if (lapic->header.type != ACPI_MADT_TYPE_LOCAL_APIC ||
  417. !(lapic->lapic_flags & ACPI_MADT_ENABLED)) {
  418. kfree(buffer.pointer);
  419. return -EINVAL;
  420. }
  421. physid = lapic->id;
  422. kfree(buffer.pointer);
  423. buffer.length = ACPI_ALLOCATE_BUFFER;
  424. buffer.pointer = NULL;
  425. if (!alloc_cpumask_var(&tmp_map, GFP_KERNEL))
  426. goto out;
  427. if (!alloc_cpumask_var(&new_map, GFP_KERNEL))
  428. goto free_tmp_map;
  429. cpumask_copy(tmp_map, cpu_present_mask);
  430. acpi_register_lapic(physid, lapic->lapic_flags & ACPI_MADT_ENABLED);
  431. /*
  432. * If mp_register_lapic successfully generates a new logical cpu
  433. * number, then the following will get us exactly what was mapped
  434. */
  435. cpumask_andnot(new_map, cpu_present_mask, tmp_map);
  436. if (cpumask_empty(new_map)) {
  437. printk ("Unable to map lapic to logical cpu number\n");
  438. retval = -EINVAL;
  439. goto free_new_map;
  440. }
  441. cpu = cpumask_first(new_map);
  442. acpi_map_cpu2node(handle, cpu, physid);
  443. *pcpu = cpu;
  444. retval = 0;
  445. free_new_map:
  446. free_cpumask_var(new_map);
  447. free_tmp_map:
  448. free_cpumask_var(tmp_map);
  449. out:
  450. return retval;
  451. }
  452. /* wrapper to silence section mismatch warning */
  453. int __ref acpi_map_lsapic(acpi_handle handle, int *pcpu)
  454. {
  455. return _acpi_map_lsapic(handle, pcpu);
  456. }
  457. EXPORT_SYMBOL(acpi_map_lsapic);
  458. int acpi_unmap_lsapic(int cpu)
  459. {
  460. per_cpu(x86_cpu_to_apicid, cpu) = -1;
  461. set_cpu_present(cpu, false);
  462. num_processors--;
  463. return (0);
  464. }
  465. EXPORT_SYMBOL(acpi_unmap_lsapic);
  466. #endif /* CONFIG_ACPI_HOTPLUG_CPU */
  467. int acpi_register_ioapic(acpi_handle handle, u64 phys_addr, u32 gsi_base)
  468. {
  469. /* TBD */
  470. return -EINVAL;
  471. }
  472. EXPORT_SYMBOL(acpi_register_ioapic);
  473. int acpi_unregister_ioapic(acpi_handle handle, u32 gsi_base)
  474. {
  475. /* TBD */
  476. return -EINVAL;
  477. }
  478. EXPORT_SYMBOL(acpi_unregister_ioapic);
  479. static int __init acpi_parse_sbf(struct acpi_table_header *table)
  480. {
  481. struct acpi_table_boot *sb;
  482. sb = (struct acpi_table_boot *)table;
  483. if (!sb) {
  484. printk(KERN_WARNING PREFIX "Unable to map SBF\n");
  485. return -ENODEV;
  486. }
  487. sbf_port = sb->cmos_index; /* Save CMOS port */
  488. return 0;
  489. }
  490. #ifdef CONFIG_HPET_TIMER
  491. #include <asm/hpet.h>
  492. static struct __initdata resource *hpet_res;
  493. static int __init acpi_parse_hpet(struct acpi_table_header *table)
  494. {
  495. struct acpi_table_hpet *hpet_tbl;
  496. hpet_tbl = (struct acpi_table_hpet *)table;
  497. if (!hpet_tbl) {
  498. printk(KERN_WARNING PREFIX "Unable to map HPET\n");
  499. return -ENODEV;
  500. }
  501. if (hpet_tbl->address.space_id != ACPI_SPACE_MEM) {
  502. printk(KERN_WARNING PREFIX "HPET timers must be located in "
  503. "memory.\n");
  504. return -1;
  505. }
  506. hpet_address = hpet_tbl->address.address;
  507. hpet_blockid = hpet_tbl->sequence;
  508. /*
  509. * Some broken BIOSes advertise HPET at 0x0. We really do not
  510. * want to allocate a resource there.
  511. */
  512. if (!hpet_address) {
  513. printk(KERN_WARNING PREFIX
  514. "HPET id: %#x base: %#lx is invalid\n",
  515. hpet_tbl->id, hpet_address);
  516. return 0;
  517. }
  518. #ifdef CONFIG_X86_64
  519. /*
  520. * Some even more broken BIOSes advertise HPET at
  521. * 0xfed0000000000000 instead of 0xfed00000. Fix it up and add
  522. * some noise:
  523. */
  524. if (hpet_address == 0xfed0000000000000UL) {
  525. if (!hpet_force_user) {
  526. printk(KERN_WARNING PREFIX "HPET id: %#x "
  527. "base: 0xfed0000000000000 is bogus\n "
  528. "try hpet=force on the kernel command line to "
  529. "fix it up to 0xfed00000.\n", hpet_tbl->id);
  530. hpet_address = 0;
  531. return 0;
  532. }
  533. printk(KERN_WARNING PREFIX
  534. "HPET id: %#x base: 0xfed0000000000000 fixed up "
  535. "to 0xfed00000.\n", hpet_tbl->id);
  536. hpet_address >>= 32;
  537. }
  538. #endif
  539. printk(KERN_INFO PREFIX "HPET id: %#x base: %#lx\n",
  540. hpet_tbl->id, hpet_address);
  541. /*
  542. * Allocate and initialize the HPET firmware resource for adding into
  543. * the resource tree during the lateinit timeframe.
  544. */
  545. #define HPET_RESOURCE_NAME_SIZE 9
  546. hpet_res = alloc_bootmem(sizeof(*hpet_res) + HPET_RESOURCE_NAME_SIZE);
  547. hpet_res->name = (void *)&hpet_res[1];
  548. hpet_res->flags = IORESOURCE_MEM;
  549. snprintf((char *)hpet_res->name, HPET_RESOURCE_NAME_SIZE, "HPET %u",
  550. hpet_tbl->sequence);
  551. hpet_res->start = hpet_address;
  552. hpet_res->end = hpet_address + (1 * 1024) - 1;
  553. return 0;
  554. }
  555. /*
  556. * hpet_insert_resource inserts the HPET resources used into the resource
  557. * tree.
  558. */
  559. static __init int hpet_insert_resource(void)
  560. {
  561. if (!hpet_res)
  562. return 1;
  563. return insert_resource(&iomem_resource, hpet_res);
  564. }
  565. late_initcall(hpet_insert_resource);
  566. #else
  567. #define acpi_parse_hpet NULL
  568. #endif
  569. static int __init acpi_parse_fadt(struct acpi_table_header *table)
  570. {
  571. #ifdef CONFIG_X86_PM_TIMER
  572. /* detect the location of the ACPI PM Timer */
  573. if (acpi_gbl_FADT.header.revision >= FADT2_REVISION_ID) {
  574. /* FADT rev. 2 */
  575. if (acpi_gbl_FADT.xpm_timer_block.space_id !=
  576. ACPI_ADR_SPACE_SYSTEM_IO)
  577. return 0;
  578. pmtmr_ioport = acpi_gbl_FADT.xpm_timer_block.address;
  579. /*
  580. * "X" fields are optional extensions to the original V1.0
  581. * fields, so we must selectively expand V1.0 fields if the
  582. * corresponding X field is zero.
  583. */
  584. if (!pmtmr_ioport)
  585. pmtmr_ioport = acpi_gbl_FADT.pm_timer_block;
  586. } else {
  587. /* FADT rev. 1 */
  588. pmtmr_ioport = acpi_gbl_FADT.pm_timer_block;
  589. }
  590. if (pmtmr_ioport)
  591. printk(KERN_INFO PREFIX "PM-Timer IO Port: %#x\n",
  592. pmtmr_ioport);
  593. #endif
  594. return 0;
  595. }
  596. #ifdef CONFIG_X86_LOCAL_APIC
  597. /*
  598. * Parse LAPIC entries in MADT
  599. * returns 0 on success, < 0 on error
  600. */
  601. static void __init acpi_register_lapic_address(unsigned long address)
  602. {
  603. mp_lapic_addr = address;
  604. set_fixmap_nocache(FIX_APIC_BASE, address);
  605. if (boot_cpu_physical_apicid == -1U) {
  606. boot_cpu_physical_apicid = read_apic_id();
  607. apic_version[boot_cpu_physical_apicid] =
  608. GET_APIC_VERSION(apic_read(APIC_LVR));
  609. }
  610. }
  611. static int __init early_acpi_parse_madt_lapic_addr_ovr(void)
  612. {
  613. int count;
  614. if (!cpu_has_apic)
  615. return -ENODEV;
  616. /*
  617. * Note that the LAPIC address is obtained from the MADT (32-bit value)
  618. * and (optionally) overriden by a LAPIC_ADDR_OVR entry (64-bit value).
  619. */
  620. count =
  621. acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE,
  622. acpi_parse_lapic_addr_ovr, 0);
  623. if (count < 0) {
  624. printk(KERN_ERR PREFIX
  625. "Error parsing LAPIC address override entry\n");
  626. return count;
  627. }
  628. acpi_register_lapic_address(acpi_lapic_addr);
  629. return count;
  630. }
  631. static int __init acpi_parse_madt_lapic_entries(void)
  632. {
  633. int count;
  634. int x2count = 0;
  635. if (!cpu_has_apic)
  636. return -ENODEV;
  637. /*
  638. * Note that the LAPIC address is obtained from the MADT (32-bit value)
  639. * and (optionally) overriden by a LAPIC_ADDR_OVR entry (64-bit value).
  640. */
  641. count =
  642. acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE,
  643. acpi_parse_lapic_addr_ovr, 0);
  644. if (count < 0) {
  645. printk(KERN_ERR PREFIX
  646. "Error parsing LAPIC address override entry\n");
  647. return count;
  648. }
  649. acpi_register_lapic_address(acpi_lapic_addr);
  650. count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_SAPIC,
  651. acpi_parse_sapic, MAX_APICS);
  652. if (!count) {
  653. x2count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_X2APIC,
  654. acpi_parse_x2apic, MAX_APICS);
  655. count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC,
  656. acpi_parse_lapic, MAX_APICS);
  657. }
  658. if (!count && !x2count) {
  659. printk(KERN_ERR PREFIX "No LAPIC entries present\n");
  660. /* TBD: Cleanup to allow fallback to MPS */
  661. return -ENODEV;
  662. } else if (count < 0 || x2count < 0) {
  663. printk(KERN_ERR PREFIX "Error parsing LAPIC entry\n");
  664. /* TBD: Cleanup to allow fallback to MPS */
  665. return count;
  666. }
  667. x2count =
  668. acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_X2APIC_NMI,
  669. acpi_parse_x2apic_nmi, 0);
  670. count =
  671. acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_NMI, acpi_parse_lapic_nmi, 0);
  672. if (count < 0 || x2count < 0) {
  673. printk(KERN_ERR PREFIX "Error parsing LAPIC NMI entry\n");
  674. /* TBD: Cleanup to allow fallback to MPS */
  675. return count;
  676. }
  677. return 0;
  678. }
  679. #endif /* CONFIG_X86_LOCAL_APIC */
  680. #ifdef CONFIG_X86_IO_APIC
  681. #define MP_ISA_BUS 0
  682. #ifdef CONFIG_X86_ES7000
  683. extern int es7000_plat;
  684. #endif
  685. int __init acpi_probe_gsi(void)
  686. {
  687. int idx;
  688. int gsi;
  689. int max_gsi = 0;
  690. if (acpi_disabled)
  691. return 0;
  692. if (!acpi_ioapic)
  693. return 0;
  694. max_gsi = 0;
  695. for (idx = 0; idx < nr_ioapics; idx++) {
  696. gsi = mp_gsi_routing[idx].gsi_end;
  697. if (gsi > max_gsi)
  698. max_gsi = gsi;
  699. }
  700. return max_gsi + 1;
  701. }
  702. static void assign_to_mp_irq(struct mpc_intsrc *m,
  703. struct mpc_intsrc *mp_irq)
  704. {
  705. memcpy(mp_irq, m, sizeof(struct mpc_intsrc));
  706. }
  707. static int mp_irq_cmp(struct mpc_intsrc *mp_irq,
  708. struct mpc_intsrc *m)
  709. {
  710. return memcmp(mp_irq, m, sizeof(struct mpc_intsrc));
  711. }
  712. static void save_mp_irq(struct mpc_intsrc *m)
  713. {
  714. int i;
  715. for (i = 0; i < mp_irq_entries; i++) {
  716. if (!mp_irq_cmp(&mp_irqs[i], m))
  717. return;
  718. }
  719. assign_to_mp_irq(m, &mp_irqs[mp_irq_entries]);
  720. if (++mp_irq_entries == MAX_IRQ_SOURCES)
  721. panic("Max # of irq sources exceeded!!\n");
  722. }
  723. void __init mp_override_legacy_irq(u8 bus_irq, u8 polarity, u8 trigger, u32 gsi)
  724. {
  725. int ioapic;
  726. int pin;
  727. struct mpc_intsrc mp_irq;
  728. /*
  729. * Convert 'gsi' to 'ioapic.pin'.
  730. */
  731. ioapic = mp_find_ioapic(gsi);
  732. if (ioapic < 0)
  733. return;
  734. pin = mp_find_ioapic_pin(ioapic, gsi);
  735. /*
  736. * TBD: This check is for faulty timer entries, where the override
  737. * erroneously sets the trigger to level, resulting in a HUGE
  738. * increase of timer interrupts!
  739. */
  740. if ((bus_irq == 0) && (trigger == 3))
  741. trigger = 1;
  742. mp_irq.type = MP_INTSRC;
  743. mp_irq.irqtype = mp_INT;
  744. mp_irq.irqflag = (trigger << 2) | polarity;
  745. mp_irq.srcbus = MP_ISA_BUS;
  746. mp_irq.srcbusirq = bus_irq; /* IRQ */
  747. mp_irq.dstapic = mp_ioapics[ioapic].apicid; /* APIC ID */
  748. mp_irq.dstirq = pin; /* INTIN# */
  749. save_mp_irq(&mp_irq);
  750. }
  751. void __init mp_config_acpi_legacy_irqs(void)
  752. {
  753. int i;
  754. int ioapic;
  755. unsigned int dstapic;
  756. struct mpc_intsrc mp_irq;
  757. #if defined (CONFIG_MCA) || defined (CONFIG_EISA)
  758. /*
  759. * Fabricate the legacy ISA bus (bus #31).
  760. */
  761. mp_bus_id_to_type[MP_ISA_BUS] = MP_BUS_ISA;
  762. #endif
  763. set_bit(MP_ISA_BUS, mp_bus_not_pci);
  764. pr_debug("Bus #%d is ISA\n", MP_ISA_BUS);
  765. #ifdef CONFIG_X86_ES7000
  766. /*
  767. * Older generations of ES7000 have no legacy identity mappings
  768. */
  769. if (es7000_plat == 1)
  770. return;
  771. #endif
  772. /*
  773. * Locate the IOAPIC that manages the ISA IRQs (0-15).
  774. */
  775. ioapic = mp_find_ioapic(0);
  776. if (ioapic < 0)
  777. return;
  778. dstapic = mp_ioapics[ioapic].apicid;
  779. /*
  780. * Use the default configuration for the IRQs 0-15. Unless
  781. * overridden by (MADT) interrupt source override entries.
  782. */
  783. for (i = 0; i < 16; i++) {
  784. int idx;
  785. for (idx = 0; idx < mp_irq_entries; idx++) {
  786. struct mpc_intsrc *irq = mp_irqs + idx;
  787. /* Do we already have a mapping for this ISA IRQ? */
  788. if (irq->srcbus == MP_ISA_BUS && irq->srcbusirq == i)
  789. break;
  790. /* Do we already have a mapping for this IOAPIC pin */
  791. if (irq->dstapic == dstapic && irq->dstirq == i)
  792. break;
  793. }
  794. if (idx != mp_irq_entries) {
  795. printk(KERN_DEBUG "ACPI: IRQ%d used by override.\n", i);
  796. continue; /* IRQ already used */
  797. }
  798. mp_irq.type = MP_INTSRC;
  799. mp_irq.irqflag = 0; /* Conforming */
  800. mp_irq.srcbus = MP_ISA_BUS;
  801. mp_irq.dstapic = dstapic;
  802. mp_irq.irqtype = mp_INT;
  803. mp_irq.srcbusirq = i; /* Identity mapped */
  804. mp_irq.dstirq = i;
  805. save_mp_irq(&mp_irq);
  806. }
  807. }
  808. static int mp_config_acpi_gsi(struct device *dev, u32 gsi, int trigger,
  809. int polarity)
  810. {
  811. #ifdef CONFIG_X86_MPPARSE
  812. struct mpc_intsrc mp_irq;
  813. struct pci_dev *pdev;
  814. unsigned char number;
  815. unsigned int devfn;
  816. int ioapic;
  817. u8 pin;
  818. if (!acpi_ioapic)
  819. return 0;
  820. if (!dev)
  821. return 0;
  822. if (dev->bus != &pci_bus_type)
  823. return 0;
  824. pdev = to_pci_dev(dev);
  825. number = pdev->bus->number;
  826. devfn = pdev->devfn;
  827. pin = pdev->pin;
  828. /* print the entry should happen on mptable identically */
  829. mp_irq.type = MP_INTSRC;
  830. mp_irq.irqtype = mp_INT;
  831. mp_irq.irqflag = (trigger == ACPI_EDGE_SENSITIVE ? 4 : 0x0c) |
  832. (polarity == ACPI_ACTIVE_HIGH ? 1 : 3);
  833. mp_irq.srcbus = number;
  834. mp_irq.srcbusirq = (((devfn >> 3) & 0x1f) << 2) | ((pin - 1) & 3);
  835. ioapic = mp_find_ioapic(gsi);
  836. mp_irq.dstapic = mp_ioapics[ioapic].apicid;
  837. mp_irq.dstirq = mp_find_ioapic_pin(ioapic, gsi);
  838. save_mp_irq(&mp_irq);
  839. #endif
  840. return 0;
  841. }
  842. int mp_register_gsi(struct device *dev, u32 gsi, int trigger, int polarity)
  843. {
  844. int ioapic;
  845. int ioapic_pin;
  846. struct io_apic_irq_attr irq_attr;
  847. if (acpi_irq_model != ACPI_IRQ_MODEL_IOAPIC)
  848. return gsi;
  849. /* Don't set up the ACPI SCI because it's already set up */
  850. if (acpi_gbl_FADT.sci_interrupt == gsi)
  851. return gsi;
  852. ioapic = mp_find_ioapic(gsi);
  853. if (ioapic < 0) {
  854. printk(KERN_WARNING "No IOAPIC for GSI %u\n", gsi);
  855. return gsi;
  856. }
  857. ioapic_pin = mp_find_ioapic_pin(ioapic, gsi);
  858. #ifdef CONFIG_X86_32
  859. if (ioapic_renumber_irq)
  860. gsi = ioapic_renumber_irq(ioapic, gsi);
  861. #endif
  862. if (ioapic_pin > MP_MAX_IOAPIC_PIN) {
  863. printk(KERN_ERR "Invalid reference to IOAPIC pin "
  864. "%d-%d\n", mp_ioapics[ioapic].apicid,
  865. ioapic_pin);
  866. return gsi;
  867. }
  868. if (enable_update_mptable)
  869. mp_config_acpi_gsi(dev, gsi, trigger, polarity);
  870. set_io_apic_irq_attr(&irq_attr, ioapic, ioapic_pin,
  871. trigger == ACPI_EDGE_SENSITIVE ? 0 : 1,
  872. polarity == ACPI_ACTIVE_HIGH ? 0 : 1);
  873. io_apic_set_pci_routing(dev, gsi, &irq_attr);
  874. return gsi;
  875. }
  876. /*
  877. * Parse IOAPIC related entries in MADT
  878. * returns 0 on success, < 0 on error
  879. */
  880. static int __init acpi_parse_madt_ioapic_entries(void)
  881. {
  882. int count;
  883. /*
  884. * ACPI interpreter is required to complete interrupt setup,
  885. * so if it is off, don't enumerate the io-apics with ACPI.
  886. * If MPS is present, it will handle them,
  887. * otherwise the system will stay in PIC mode
  888. */
  889. if (acpi_disabled || acpi_noirq)
  890. return -ENODEV;
  891. if (!cpu_has_apic)
  892. return -ENODEV;
  893. /*
  894. * if "noapic" boot option, don't look for IO-APICs
  895. */
  896. if (skip_ioapic_setup) {
  897. printk(KERN_INFO PREFIX "Skipping IOAPIC probe "
  898. "due to 'noapic' option.\n");
  899. return -ENODEV;
  900. }
  901. count =
  902. acpi_table_parse_madt(ACPI_MADT_TYPE_IO_APIC, acpi_parse_ioapic,
  903. MAX_IO_APICS);
  904. if (!count) {
  905. printk(KERN_ERR PREFIX "No IOAPIC entries present\n");
  906. return -ENODEV;
  907. } else if (count < 0) {
  908. printk(KERN_ERR PREFIX "Error parsing IOAPIC entry\n");
  909. return count;
  910. }
  911. count =
  912. acpi_table_parse_madt(ACPI_MADT_TYPE_INTERRUPT_OVERRIDE, acpi_parse_int_src_ovr,
  913. nr_irqs);
  914. if (count < 0) {
  915. printk(KERN_ERR PREFIX
  916. "Error parsing interrupt source overrides entry\n");
  917. /* TBD: Cleanup to allow fallback to MPS */
  918. return count;
  919. }
  920. /*
  921. * If BIOS did not supply an INT_SRC_OVR for the SCI
  922. * pretend we got one so we can set the SCI flags.
  923. */
  924. if (!acpi_sci_override_gsi)
  925. acpi_sci_ioapic_setup(acpi_gbl_FADT.sci_interrupt, 0, 0);
  926. /* Fill in identity legacy mappings where no override */
  927. mp_config_acpi_legacy_irqs();
  928. count =
  929. acpi_table_parse_madt(ACPI_MADT_TYPE_NMI_SOURCE, acpi_parse_nmi_src,
  930. nr_irqs);
  931. if (count < 0) {
  932. printk(KERN_ERR PREFIX "Error parsing NMI SRC entry\n");
  933. /* TBD: Cleanup to allow fallback to MPS */
  934. return count;
  935. }
  936. return 0;
  937. }
  938. #else
  939. static inline int acpi_parse_madt_ioapic_entries(void)
  940. {
  941. return -1;
  942. }
  943. #endif /* !CONFIG_X86_IO_APIC */
  944. static void __init early_acpi_process_madt(void)
  945. {
  946. #ifdef CONFIG_X86_LOCAL_APIC
  947. int error;
  948. if (!acpi_table_parse(ACPI_SIG_MADT, acpi_parse_madt)) {
  949. /*
  950. * Parse MADT LAPIC entries
  951. */
  952. error = early_acpi_parse_madt_lapic_addr_ovr();
  953. if (!error) {
  954. acpi_lapic = 1;
  955. smp_found_config = 1;
  956. }
  957. if (error == -EINVAL) {
  958. /*
  959. * Dell Precision Workstation 410, 610 come here.
  960. */
  961. printk(KERN_ERR PREFIX
  962. "Invalid BIOS MADT, disabling ACPI\n");
  963. disable_acpi();
  964. }
  965. }
  966. #endif
  967. }
  968. static void __init acpi_process_madt(void)
  969. {
  970. #ifdef CONFIG_X86_LOCAL_APIC
  971. int error;
  972. if (!acpi_table_parse(ACPI_SIG_MADT, acpi_parse_madt)) {
  973. /*
  974. * Parse MADT LAPIC entries
  975. */
  976. error = acpi_parse_madt_lapic_entries();
  977. if (!error) {
  978. acpi_lapic = 1;
  979. /*
  980. * Parse MADT IO-APIC entries
  981. */
  982. error = acpi_parse_madt_ioapic_entries();
  983. if (!error) {
  984. acpi_irq_model = ACPI_IRQ_MODEL_IOAPIC;
  985. acpi_ioapic = 1;
  986. smp_found_config = 1;
  987. }
  988. }
  989. if (error == -EINVAL) {
  990. /*
  991. * Dell Precision Workstation 410, 610 come here.
  992. */
  993. printk(KERN_ERR PREFIX
  994. "Invalid BIOS MADT, disabling ACPI\n");
  995. disable_acpi();
  996. }
  997. } else {
  998. /*
  999. * ACPI found no MADT, and so ACPI wants UP PIC mode.
  1000. * In the event an MPS table was found, forget it.
  1001. * Boot with "acpi=off" to use MPS on such a system.
  1002. */
  1003. if (smp_found_config) {
  1004. printk(KERN_WARNING PREFIX
  1005. "No APIC-table, disabling MPS\n");
  1006. smp_found_config = 0;
  1007. }
  1008. }
  1009. /*
  1010. * ACPI supports both logical (e.g. Hyper-Threading) and physical
  1011. * processors, where MPS only supports physical.
  1012. */
  1013. if (acpi_lapic && acpi_ioapic)
  1014. printk(KERN_INFO "Using ACPI (MADT) for SMP configuration "
  1015. "information\n");
  1016. else if (acpi_lapic)
  1017. printk(KERN_INFO "Using ACPI for processor (LAPIC) "
  1018. "configuration information\n");
  1019. #endif
  1020. return;
  1021. }
  1022. static int __init disable_acpi_irq(const struct dmi_system_id *d)
  1023. {
  1024. if (!acpi_force) {
  1025. printk(KERN_NOTICE "%s detected: force use of acpi=noirq\n",
  1026. d->ident);
  1027. acpi_noirq_set();
  1028. }
  1029. return 0;
  1030. }
  1031. static int __init disable_acpi_pci(const struct dmi_system_id *d)
  1032. {
  1033. if (!acpi_force) {
  1034. printk(KERN_NOTICE "%s detected: force use of pci=noacpi\n",
  1035. d->ident);
  1036. acpi_disable_pci();
  1037. }
  1038. return 0;
  1039. }
  1040. static int __init dmi_disable_acpi(const struct dmi_system_id *d)
  1041. {
  1042. if (!acpi_force) {
  1043. printk(KERN_NOTICE "%s detected: acpi off\n", d->ident);
  1044. disable_acpi();
  1045. } else {
  1046. printk(KERN_NOTICE
  1047. "Warning: DMI blacklist says broken, but acpi forced\n");
  1048. }
  1049. return 0;
  1050. }
  1051. /*
  1052. * Limit ACPI to CPU enumeration for HT
  1053. */
  1054. static int __init force_acpi_ht(const struct dmi_system_id *d)
  1055. {
  1056. if (!acpi_force) {
  1057. printk(KERN_NOTICE "%s detected: force use of acpi=ht\n",
  1058. d->ident);
  1059. disable_acpi();
  1060. acpi_ht = 1;
  1061. } else {
  1062. printk(KERN_NOTICE
  1063. "Warning: acpi=force overrules DMI blacklist: acpi=ht\n");
  1064. }
  1065. return 0;
  1066. }
  1067. /*
  1068. * Force ignoring BIOS IRQ0 pin2 override
  1069. */
  1070. static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
  1071. {
  1072. /*
  1073. * The ati_ixp4x0_rev() early PCI quirk should have set
  1074. * the acpi_skip_timer_override flag already:
  1075. */
  1076. if (!acpi_skip_timer_override) {
  1077. WARN(1, KERN_ERR "ati_ixp4x0 quirk not complete.\n");
  1078. pr_notice("%s detected: Ignoring BIOS IRQ0 pin2 override\n",
  1079. d->ident);
  1080. acpi_skip_timer_override = 1;
  1081. }
  1082. return 0;
  1083. }
  1084. /*
  1085. * If your system is blacklisted here, but you find that acpi=force
  1086. * works for you, please contact linux-acpi@vger.kernel.org
  1087. */
  1088. static struct dmi_system_id __initdata acpi_dmi_table[] = {
  1089. /*
  1090. * Boxes that need ACPI disabled
  1091. */
  1092. {
  1093. .callback = dmi_disable_acpi,
  1094. .ident = "IBM Thinkpad",
  1095. .matches = {
  1096. DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
  1097. DMI_MATCH(DMI_BOARD_NAME, "2629H1G"),
  1098. },
  1099. },
  1100. /*
  1101. * Boxes that need acpi=ht
  1102. */
  1103. {
  1104. .callback = force_acpi_ht,
  1105. .ident = "FSC Primergy T850",
  1106. .matches = {
  1107. DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
  1108. DMI_MATCH(DMI_PRODUCT_NAME, "PRIMERGY T850"),
  1109. },
  1110. },
  1111. {
  1112. .callback = force_acpi_ht,
  1113. .ident = "HP VISUALIZE NT Workstation",
  1114. .matches = {
  1115. DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
  1116. DMI_MATCH(DMI_PRODUCT_NAME, "HP VISUALIZE NT Workstation"),
  1117. },
  1118. },
  1119. {
  1120. .callback = force_acpi_ht,
  1121. .ident = "Compaq Workstation W8000",
  1122. .matches = {
  1123. DMI_MATCH(DMI_SYS_VENDOR, "Compaq"),
  1124. DMI_MATCH(DMI_PRODUCT_NAME, "Workstation W8000"),
  1125. },
  1126. },
  1127. {
  1128. .callback = force_acpi_ht,
  1129. .ident = "ASUS CUR-DLS",
  1130. .matches = {
  1131. DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
  1132. DMI_MATCH(DMI_BOARD_NAME, "CUR-DLS"),
  1133. },
  1134. },
  1135. {
  1136. .callback = force_acpi_ht,
  1137. .ident = "ABIT i440BX-W83977",
  1138. .matches = {
  1139. DMI_MATCH(DMI_BOARD_VENDOR, "ABIT <http://www.abit.com>"),
  1140. DMI_MATCH(DMI_BOARD_NAME, "i440BX-W83977 (BP6)"),
  1141. },
  1142. },
  1143. {
  1144. .callback = force_acpi_ht,
  1145. .ident = "IBM Bladecenter",
  1146. .matches = {
  1147. DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
  1148. DMI_MATCH(DMI_BOARD_NAME, "IBM eServer BladeCenter HS20"),
  1149. },
  1150. },
  1151. {
  1152. .callback = force_acpi_ht,
  1153. .ident = "IBM eServer xSeries 360",
  1154. .matches = {
  1155. DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
  1156. DMI_MATCH(DMI_BOARD_NAME, "eServer xSeries 360"),
  1157. },
  1158. },
  1159. {
  1160. .callback = force_acpi_ht,
  1161. .ident = "IBM eserver xSeries 330",
  1162. .matches = {
  1163. DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
  1164. DMI_MATCH(DMI_BOARD_NAME, "eserver xSeries 330"),
  1165. },
  1166. },
  1167. {
  1168. .callback = force_acpi_ht,
  1169. .ident = "IBM eserver xSeries 440",
  1170. .matches = {
  1171. DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
  1172. DMI_MATCH(DMI_PRODUCT_NAME, "eserver xSeries 440"),
  1173. },
  1174. },
  1175. /*
  1176. * Boxes that need ACPI PCI IRQ routing disabled
  1177. */
  1178. {
  1179. .callback = disable_acpi_irq,
  1180. .ident = "ASUS A7V",
  1181. .matches = {
  1182. DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC"),
  1183. DMI_MATCH(DMI_BOARD_NAME, "<A7V>"),
  1184. /* newer BIOS, Revision 1011, does work */
  1185. DMI_MATCH(DMI_BIOS_VERSION,
  1186. "ASUS A7V ACPI BIOS Revision 1007"),
  1187. },
  1188. },
  1189. {
  1190. /*
  1191. * Latest BIOS for IBM 600E (1.16) has bad pcinum
  1192. * for LPC bridge, which is needed for the PCI
  1193. * interrupt links to work. DSDT fix is in bug 5966.
  1194. * 2645, 2646 model numbers are shared with 600/600E/600X
  1195. */
  1196. .callback = disable_acpi_irq,
  1197. .ident = "IBM Thinkpad 600 Series 2645",
  1198. .matches = {
  1199. DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
  1200. DMI_MATCH(DMI_BOARD_NAME, "2645"),
  1201. },
  1202. },
  1203. {
  1204. .callback = disable_acpi_irq,
  1205. .ident = "IBM Thinkpad 600 Series 2646",
  1206. .matches = {
  1207. DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
  1208. DMI_MATCH(DMI_BOARD_NAME, "2646"),
  1209. },
  1210. },
  1211. /*
  1212. * Boxes that need ACPI PCI IRQ routing and PCI scan disabled
  1213. */
  1214. { /* _BBN 0 bug */
  1215. .callback = disable_acpi_pci,
  1216. .ident = "ASUS PR-DLS",
  1217. .matches = {
  1218. DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
  1219. DMI_MATCH(DMI_BOARD_NAME, "PR-DLS"),
  1220. DMI_MATCH(DMI_BIOS_VERSION,
  1221. "ASUS PR-DLS ACPI BIOS Revision 1010"),
  1222. DMI_MATCH(DMI_BIOS_DATE, "03/21/2003")
  1223. },
  1224. },
  1225. {
  1226. .callback = disable_acpi_pci,
  1227. .ident = "Acer TravelMate 36x Laptop",
  1228. .matches = {
  1229. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  1230. DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 360"),
  1231. },
  1232. },
  1233. {}
  1234. };
  1235. /* second table for DMI checks that should run after early-quirks */
  1236. static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
  1237. /*
  1238. * HP laptops which use a DSDT reporting as HP/SB400/10000,
  1239. * which includes some code which overrides all temperature
  1240. * trip points to 16C if the INTIN2 input of the I/O APIC
  1241. * is enabled. This input is incorrectly designated the
  1242. * ISA IRQ 0 via an interrupt source override even though
  1243. * it is wired to the output of the master 8259A and INTIN0
  1244. * is not connected at all. Force ignoring BIOS IRQ0 pin2
  1245. * override in that cases.
  1246. */
  1247. {
  1248. .callback = dmi_ignore_irq0_timer_override,
  1249. .ident = "HP nx6115 laptop",
  1250. .matches = {
  1251. DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
  1252. DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6115"),
  1253. },
  1254. },
  1255. {
  1256. .callback = dmi_ignore_irq0_timer_override,
  1257. .ident = "HP NX6125 laptop",
  1258. .matches = {
  1259. DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
  1260. DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6125"),
  1261. },
  1262. },
  1263. {
  1264. .callback = dmi_ignore_irq0_timer_override,
  1265. .ident = "HP NX6325 laptop",
  1266. .matches = {
  1267. DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
  1268. DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6325"),
  1269. },
  1270. },
  1271. {
  1272. .callback = dmi_ignore_irq0_timer_override,
  1273. .ident = "HP 6715b laptop",
  1274. .matches = {
  1275. DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
  1276. DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq 6715b"),
  1277. },
  1278. },
  1279. {}
  1280. };
  1281. /*
  1282. * acpi_boot_table_init() and acpi_boot_init()
  1283. * called from setup_arch(), always.
  1284. * 1. checksums all tables
  1285. * 2. enumerates lapics
  1286. * 3. enumerates io-apics
  1287. *
  1288. * acpi_table_init() is separate to allow reading SRAT without
  1289. * other side effects.
  1290. *
  1291. * side effects of acpi_boot_init:
  1292. * acpi_lapic = 1 if LAPIC found
  1293. * acpi_ioapic = 1 if IOAPIC found
  1294. * if (acpi_lapic && acpi_ioapic) smp_found_config = 1;
  1295. * if acpi_blacklisted() acpi_disabled = 1;
  1296. * acpi_irq_model=...
  1297. * ...
  1298. */
  1299. void __init acpi_boot_table_init(void)
  1300. {
  1301. dmi_check_system(acpi_dmi_table);
  1302. /*
  1303. * If acpi_disabled, bail out
  1304. * One exception: acpi=ht continues far enough to enumerate LAPICs
  1305. */
  1306. if (acpi_disabled && !acpi_ht)
  1307. return;
  1308. /*
  1309. * Initialize the ACPI boot-time table parser.
  1310. */
  1311. if (acpi_table_init()) {
  1312. disable_acpi();
  1313. return;
  1314. }
  1315. acpi_table_parse(ACPI_SIG_BOOT, acpi_parse_sbf);
  1316. /*
  1317. * blacklist may disable ACPI entirely
  1318. */
  1319. if (acpi_blacklisted()) {
  1320. if (acpi_force) {
  1321. printk(KERN_WARNING PREFIX "acpi=force override\n");
  1322. } else {
  1323. printk(KERN_WARNING PREFIX "Disabling ACPI support\n");
  1324. disable_acpi();
  1325. return;
  1326. }
  1327. }
  1328. }
  1329. int __init early_acpi_boot_init(void)
  1330. {
  1331. /*
  1332. * If acpi_disabled, bail out
  1333. * One exception: acpi=ht continues far enough to enumerate LAPICs
  1334. */
  1335. if (acpi_disabled && !acpi_ht)
  1336. return 1;
  1337. /*
  1338. * Process the Multiple APIC Description Table (MADT), if present
  1339. */
  1340. early_acpi_process_madt();
  1341. return 0;
  1342. }
  1343. int __init acpi_boot_init(void)
  1344. {
  1345. /* those are executed after early-quirks are executed */
  1346. dmi_check_system(acpi_dmi_table_late);
  1347. /*
  1348. * If acpi_disabled, bail out
  1349. * One exception: acpi=ht continues far enough to enumerate LAPICs
  1350. */
  1351. if (acpi_disabled && !acpi_ht)
  1352. return 1;
  1353. acpi_table_parse(ACPI_SIG_BOOT, acpi_parse_sbf);
  1354. /*
  1355. * set sci_int and PM timer address
  1356. */
  1357. acpi_table_parse(ACPI_SIG_FADT, acpi_parse_fadt);
  1358. /*
  1359. * Process the Multiple APIC Description Table (MADT), if present
  1360. */
  1361. acpi_process_madt();
  1362. acpi_table_parse(ACPI_SIG_HPET, acpi_parse_hpet);
  1363. return 0;
  1364. }
  1365. static int __init parse_acpi(char *arg)
  1366. {
  1367. if (!arg)
  1368. return -EINVAL;
  1369. /* "acpi=off" disables both ACPI table parsing and interpreter */
  1370. if (strcmp(arg, "off") == 0) {
  1371. disable_acpi();
  1372. }
  1373. /* acpi=force to over-ride black-list */
  1374. else if (strcmp(arg, "force") == 0) {
  1375. acpi_force = 1;
  1376. acpi_ht = 1;
  1377. acpi_disabled = 0;
  1378. }
  1379. /* acpi=strict disables out-of-spec workarounds */
  1380. else if (strcmp(arg, "strict") == 0) {
  1381. acpi_strict = 1;
  1382. }
  1383. /* Limit ACPI just to boot-time to enable HT */
  1384. else if (strcmp(arg, "ht") == 0) {
  1385. if (!acpi_force)
  1386. disable_acpi();
  1387. acpi_ht = 1;
  1388. }
  1389. /* acpi=rsdt use RSDT instead of XSDT */
  1390. else if (strcmp(arg, "rsdt") == 0) {
  1391. acpi_rsdt_forced = 1;
  1392. }
  1393. /* "acpi=noirq" disables ACPI interrupt routing */
  1394. else if (strcmp(arg, "noirq") == 0) {
  1395. acpi_noirq_set();
  1396. } else {
  1397. /* Core will printk when we return error. */
  1398. return -EINVAL;
  1399. }
  1400. return 0;
  1401. }
  1402. early_param("acpi", parse_acpi);
  1403. /* FIXME: Using pci= for an ACPI parameter is a travesty. */
  1404. static int __init parse_pci(char *arg)
  1405. {
  1406. if (arg && strcmp(arg, "noacpi") == 0)
  1407. acpi_disable_pci();
  1408. return 0;
  1409. }
  1410. early_param("pci", parse_pci);
  1411. int __init acpi_mps_check(void)
  1412. {
  1413. #if defined(CONFIG_X86_LOCAL_APIC) && !defined(CONFIG_X86_MPPARSE)
  1414. /* mptable code is not built-in*/
  1415. if (acpi_disabled || acpi_noirq) {
  1416. printk(KERN_WARNING "MPS support code is not built-in.\n"
  1417. "Using acpi=off or acpi=noirq or pci=noacpi "
  1418. "may have problem\n");
  1419. return 1;
  1420. }
  1421. #endif
  1422. return 0;
  1423. }
  1424. #ifdef CONFIG_X86_IO_APIC
  1425. static int __init parse_acpi_skip_timer_override(char *arg)
  1426. {
  1427. acpi_skip_timer_override = 1;
  1428. return 0;
  1429. }
  1430. early_param("acpi_skip_timer_override", parse_acpi_skip_timer_override);
  1431. static int __init parse_acpi_use_timer_override(char *arg)
  1432. {
  1433. acpi_use_timer_override = 1;
  1434. return 0;
  1435. }
  1436. early_param("acpi_use_timer_override", parse_acpi_use_timer_override);
  1437. #endif /* CONFIG_X86_IO_APIC */
  1438. static int __init setup_acpi_sci(char *s)
  1439. {
  1440. if (!s)
  1441. return -EINVAL;
  1442. if (!strcmp(s, "edge"))
  1443. acpi_sci_flags = ACPI_MADT_TRIGGER_EDGE |
  1444. (acpi_sci_flags & ~ACPI_MADT_TRIGGER_MASK);
  1445. else if (!strcmp(s, "level"))
  1446. acpi_sci_flags = ACPI_MADT_TRIGGER_LEVEL |
  1447. (acpi_sci_flags & ~ACPI_MADT_TRIGGER_MASK);
  1448. else if (!strcmp(s, "high"))
  1449. acpi_sci_flags = ACPI_MADT_POLARITY_ACTIVE_HIGH |
  1450. (acpi_sci_flags & ~ACPI_MADT_POLARITY_MASK);
  1451. else if (!strcmp(s, "low"))
  1452. acpi_sci_flags = ACPI_MADT_POLARITY_ACTIVE_LOW |
  1453. (acpi_sci_flags & ~ACPI_MADT_POLARITY_MASK);
  1454. else
  1455. return -EINVAL;
  1456. return 0;
  1457. }
  1458. early_param("acpi_sci", setup_acpi_sci);
  1459. int __acpi_acquire_global_lock(unsigned int *lock)
  1460. {
  1461. unsigned int old, new, val;
  1462. do {
  1463. old = *lock;
  1464. new = (((old & ~0x3) + 2) + ((old >> 1) & 0x1));
  1465. val = cmpxchg(lock, old, new);
  1466. } while (unlikely (val != old));
  1467. return (new < 3) ? -1 : 0;
  1468. }
  1469. int __acpi_release_global_lock(unsigned int *lock)
  1470. {
  1471. unsigned int old, new, val;
  1472. do {
  1473. old = *lock;
  1474. new = old & ~0x3;
  1475. val = cmpxchg(lock, old, new);
  1476. } while (unlikely (val != old));
  1477. return old & 0x1;
  1478. }