/kern_oII/arch/x86/kernel/acpi/boot.c

http://omnia2droid.googlecode.com/ · C · 1846 lines · 1237 code · 281 blank · 328 comment · 223 complexity · 521c377fcf2caed5294fa5565b3785ec MD5 · raw file

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