aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2014-08-06 23:34:19 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2014-08-06 23:34:19 -0400
commit7725131982477bffff8ffdea143434dcc69f5d90 (patch)
tree099440f6a8b11c8221ea99effec4c22818b3b577
parent6b22df74f7af62137772c280791c932855f7635b (diff)
parent7ef97e0e3a0f4b02601dde384127cc85d27e46e2 (diff)
Merge tag 'pm+acpi-3.17-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm
Pull ACPI and power management updates from Rafael Wysocki: "Again, ACPICA leads the pack (47 commits), followed by cpufreq (18 commits) and system suspend/hibernation (9 commits). From the new code perspective, the ACPICA update brings ACPI 5.1 to the table, including a new device configuration object called _DSD (Device Specific Data) that will hopefully help us to operate device properties like Device Trees do (at least to some extent) and changes related to supporting ACPI on ARM. Apart from that we have hibernation changes making it use radix trees to store memory bitmaps which should speed up some operations carried out by it quite significantly. We also have some power management changes related to suspend-to-idle (the "freeze" sleep state) support and more preliminary changes needed to support ACPI on ARM (outside of ACPICA). The rest is fixes and cleanups pretty much everywhere. Specifics: - ACPICA update to upstream version 20140724. That includes ACPI 5.1 material (support for the _CCA and _DSD predefined names, changes related to the DMAR and PCCT tables and ARM support among other things) and cleanups related to using ACPICA's header files. A major part of it is related to acpidump and the core code used by that utility. Changes from Bob Moore, David E Box, Lv Zheng, Sascha Wildner, Tomasz Nowicki, Hanjun Guo. - Radix trees for memory bitmaps used by the hibernation core from Joerg Roedel. - Support for waking up the system from suspend-to-idle (also known as the "freeze" sleep state) using ACPI-based PCI wakeup signaling (Rafael J Wysocki). - Fixes for issues related to ACPI button events (Rafael J Wysocki). - New device ID for an ACPI-enumerated device included into the Wildcat Point PCH from Jie Yang. - ACPI video updates related to backlight handling from Hans de Goede and Linus Torvalds. - Preliminary changes needed to support ACPI on ARM from Hanjun Guo and Graeme Gregory. - ACPI PNP core cleanups from Arjun Sreedharan and Zhang Rui. - Cleanups related to ACPI_COMPANION() and ACPI_HANDLE() macros (Rafael J Wysocki). - ACPI-based device hotplug cleanups from Wei Yongjun and Rafael J Wysocki. - Cleanups and improvements related to system suspend from Lan Tianyu, Randy Dunlap and Rafael J Wysocki. - ACPI battery cleanup from Wei Yongjun. - cpufreq core fixes from Viresh Kumar. - Elimination of a deadband effect from the cpufreq ondemand governor and intel_pstate driver cleanups from Stratos Karafotis. - 350MHz CPU support for the powernow-k6 cpufreq driver from Mikulas Patocka. - Fix for the imx6 cpufreq driver from Anson Huang. - cpuidle core and governor cleanups from Daniel Lezcano, Sandeep Tripathy and Mohammad Merajul Islam Molla. - Build fix for the big_little cpuidle driver from Sachin Kamat. - Configuration fix for the Operation Performance Points (OPP) framework from Mark Brown. - APM cleanup from Jean Delvare. - cpupower utility fixes and cleanups from Peter Senna Tschudin, Andrey Utkin, Himangi Saraogi, Rickard Strandqvist, Thomas Renninger" * tag 'pm+acpi-3.17-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm: (118 commits) ACPI / LPSS: add LPSS device for Wildcat Point PCH ACPI / PNP: Replace faulty is_hex_digit() by isxdigit() ACPICA: Update version to 20140724. ACPICA: ACPI 5.1: Update for PCCT table changes. ACPICA/ARM: ACPI 5.1: Update for GTDT table changes. ACPICA/ARM: ACPI 5.1: Update for MADT changes. ACPICA/ARM: ACPI 5.1: Update for FADT changes. ACPICA: ACPI 5.1: Support for the _CCA predifined name. ACPICA: ACPI 5.1: New notify value for System Affinity Update. ACPICA: ACPI 5.1: Support for the _DSD predefined name. ACPICA: Debug object: Add current value of Timer() to debug line prefix. ACPICA: acpihelp: Add UUID support, restructure some existing files. ACPICA: Utilities: Fix local printf issue. ACPICA: Tables: Update for DMAR table changes. ACPICA: Remove some extraneous printf arguments. ACPICA: Update for comments/formatting. No functional changes. ACPICA: Disassembler: Add support for the ToUUID opererator (macro). ACPICA: Remove a redundant cast to acpi_size for ACPI_OFFSET() macro. ACPICA: Work around an ancient GCC bug. ACPI / processor: Make it possible to get local x2apic id via _MAT ...
-rw-r--r--Documentation/power/opp.txt3
-rw-r--r--MAINTAINERS4
-rw-r--r--arch/arm/mach-exynos/Kconfig1
-rw-r--r--arch/arm/mach-highbank/Kconfig1
-rw-r--r--arch/arm/mach-imx/Kconfig1
-rw-r--r--arch/arm/mach-omap2/Kconfig1
-rw-r--r--arch/arm/mach-shmobile/Kconfig2
-rw-r--r--arch/arm/mach-vexpress/Kconfig1
-rw-r--r--arch/arm/mach-zynq/Kconfig1
-rw-r--r--arch/ia64/Kconfig1
-rw-r--r--arch/ia64/include/asm/acenv.h4
-rw-r--r--arch/ia64/include/asm/acpi.h5
-rw-r--r--arch/x86/Kconfig2
-rw-r--r--arch/x86/include/asm/acenv.h4
-rw-r--r--arch/x86/include/asm/acpi.h5
-rw-r--r--drivers/acpi/Kconfig6
-rw-r--r--drivers/acpi/Makefile1
-rw-r--r--drivers/acpi/acpi_extlog.c18
-rw-r--r--drivers/acpi/acpi_lpss.c10
-rw-r--r--drivers/acpi/acpi_pnp.c8
-rw-r--r--drivers/acpi/acpi_processor.c2
-rw-r--r--drivers/acpi/acpica/Makefile10
-rw-r--r--drivers/acpi/acpica/acapps.h9
-rw-r--r--drivers/acpi/acpica/acdebug.h3
-rw-r--r--drivers/acpi/acpica/acglobal.h8
-rw-r--r--drivers/acpi/acpica/aclocal.h18
-rw-r--r--drivers/acpi/acpica/acpredef.h16
-rw-r--r--drivers/acpi/acpica/acutils.h48
-rw-r--r--drivers/acpi/acpica/evgpe.c32
-rw-r--r--drivers/acpi/acpica/evxfgpe.c61
-rw-r--r--drivers/acpi/acpica/exdebug.c11
-rw-r--r--drivers/acpi/acpica/exdump.c6
-rw-r--r--drivers/acpi/acpica/exfield.c26
-rw-r--r--drivers/acpi/acpica/hwregs.c3
-rw-r--r--drivers/acpi/acpica/nsobject.c10
-rw-r--r--drivers/acpi/acpica/utbuffer.c128
-rw-r--r--drivers/acpi/acpica/utcopy.c6
-rw-r--r--drivers/acpi/acpica/utdebug.c26
-rw-r--r--drivers/acpi/acpica/utdecode.c32
-rw-r--r--drivers/acpi/acpica/utfileio.c331
-rw-r--r--drivers/acpi/acpica/utglobal.c146
-rw-r--r--drivers/acpi/acpica/uthex.c100
-rw-r--r--drivers/acpi/acpica/utinit.c145
-rw-r--r--drivers/acpi/acpica/utprint.c664
-rw-r--r--drivers/acpi/acpica/utuuid.c96
-rw-r--r--drivers/acpi/apei/apei-internal.h10
-rw-r--r--drivers/acpi/apei/ghes.c32
-rw-r--r--drivers/acpi/battery.c1
-rw-r--r--drivers/acpi/blacklist.c68
-rw-r--r--drivers/acpi/bus.c3
-rw-r--r--drivers/acpi/button.c25
-rw-r--r--drivers/acpi/device_pm.c148
-rw-r--r--drivers/acpi/internal.h7
-rw-r--r--drivers/acpi/osl.c4
-rw-r--r--drivers/acpi/pci_root.c2
-rw-r--r--drivers/acpi/processor_core.c200
-rw-r--r--drivers/acpi/processor_pdc.c206
-rw-r--r--drivers/acpi/scan.c33
-rw-r--r--drivers/acpi/sleep.c5
-rw-r--r--drivers/acpi/video.c121
-rw-r--r--drivers/base/power/main.c5
-rw-r--r--drivers/cpufreq/cpufreq.c74
-rw-r--r--drivers/cpufreq/cpufreq_ondemand.c11
-rw-r--r--drivers/cpufreq/freq_table.c12
-rw-r--r--drivers/cpufreq/imx6q-cpufreq.c35
-rw-r--r--drivers/cpufreq/intel_pstate.c131
-rw-r--r--drivers/cpufreq/powernow-k6.c1
-rw-r--r--drivers/cpuidle/Kconfig7
-rw-r--r--drivers/cpuidle/Kconfig.arm1
-rw-r--r--drivers/cpuidle/cpuidle.c2
-rw-r--r--drivers/cpuidle/driver.c11
-rw-r--r--drivers/cpuidle/governors/ladder.c4
-rw-r--r--drivers/cpuidle/governors/menu.c1
-rw-r--r--drivers/cpuidle/sysfs.c2
-rw-r--r--drivers/devfreq/Kconfig1
-rw-r--r--drivers/firmware/efi/cper.c20
-rw-r--r--drivers/iommu/dmar.c28
-rw-r--r--drivers/pci/hotplug/acpiphp_glue.c33
-rw-r--r--drivers/pci/pci-acpi.c76
-rw-r--r--drivers/pnp/pnpacpi/core.c91
-rw-r--r--include/acpi/acconfig.h18
-rw-r--r--include/acpi/acnames.h1
-rw-r--r--include/acpi/acpi_bus.h42
-rw-r--r--include/acpi/acpiosxf.h31
-rw-r--r--include/acpi/acpixf.h54
-rw-r--r--include/acpi/actbl.h12
-rw-r--r--include/acpi/actbl1.h58
-rw-r--r--include/acpi/actbl2.h14
-rw-r--r--include/acpi/actbl3.h118
-rw-r--r--include/acpi/actypes.h19
-rw-r--r--include/acpi/ghes.h2
-rw-r--r--include/acpi/platform/acenv.h53
-rw-r--r--include/acpi/platform/aclinux.h12
-rw-r--r--include/acpi/platform/aclinuxex.h22
-rw-r--r--include/linux/acpi.h6
-rw-r--r--include/linux/cpufreq.h1
-rw-r--r--include/linux/pci-acpi.h13
-rw-r--r--include/linux/pm_runtime.h11
-rw-r--r--include/linux/sfi_acpi.h3
-rw-r--r--kernel/power/Kconfig3
-rw-r--r--kernel/power/main.c25
-rw-r--r--kernel/power/power.h7
-rw-r--r--kernel/power/snapshot.c494
-rw-r--r--kernel/power/suspend.c152
-rw-r--r--kernel/power/suspend_test.c12
-rw-r--r--kernel/sched/idle.c4
-rw-r--r--tools/power/acpi/Makefile5
-rw-r--r--tools/power/acpi/common/cmfsize.c20
-rw-r--r--tools/power/acpi/common/getopt.c14
-rw-r--r--tools/power/acpi/os_specific/service_layers/oslibcfs.c214
-rw-r--r--tools/power/acpi/os_specific/service_layers/oslinuxtbl.c48
-rw-r--r--tools/power/acpi/os_specific/service_layers/osunixxf.c1311
-rw-r--r--tools/power/acpi/tools/acpidump/acpidump.h3
-rw-r--r--tools/power/acpi/tools/acpidump/apdump.c108
-rw-r--r--tools/power/acpi/tools/acpidump/apfiles.c92
-rw-r--r--tools/power/acpi/tools/acpidump/apmain.c96
-rw-r--r--tools/power/cpupower/bench/parse.c39
-rw-r--r--tools/power/cpupower/utils/cpufreq-set.c11
-rw-r--r--tools/power/cpupower/utils/helpers/sysfs.c2
-rw-r--r--tools/power/cpupower/utils/idle_monitor/mperf_monitor.c2
120 files changed, 5084 insertions, 1495 deletions
diff --git a/Documentation/power/opp.txt b/Documentation/power/opp.txt
index a9adad828cdc..c6279c2be47c 100644
--- a/Documentation/power/opp.txt
+++ b/Documentation/power/opp.txt
@@ -51,9 +51,6 @@ Typical usage of the OPP library is as follows:
51SoC framework -> modifies on required cases certain OPPs -> OPP layer 51SoC framework -> modifies on required cases certain OPPs -> OPP layer
52 -> queries to search/retrieve information -> 52 -> queries to search/retrieve information ->
53 53
54Architectures that provide a SoC framework for OPP should select ARCH_HAS_OPP
55to make the OPP layer available.
56
57OPP layer expects each domain to be represented by a unique device pointer. SoC 54OPP layer expects each domain to be represented by a unique device pointer. SoC
58framework registers a set of initial OPPs per device with the OPP layer. This 55framework registers a set of initial OPPs per device with the OPP layer. This
59list is expected to be an optimally small number typically around 5 per device. 56list is expected to be an optimally small number typically around 5 per device.
diff --git a/MAINTAINERS b/MAINTAINERS
index e33ca844f352..05e545096100 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2556,8 +2556,8 @@ F: arch/x86/kernel/cpuid.c
2556F: arch/x86/kernel/msr.c 2556F: arch/x86/kernel/msr.c
2557 2557
2558CPU POWER MONITORING SUBSYSTEM 2558CPU POWER MONITORING SUBSYSTEM
2559M: Dominik Brodowski <linux@dominikbrodowski.net>
2560M: Thomas Renninger <trenn@suse.de> 2559M: Thomas Renninger <trenn@suse.de>
2560L: linux-pm@vger.kernel.org
2561S: Maintained 2561S: Maintained
2562F: tools/power/cpupower/ 2562F: tools/power/cpupower/
2563 2563
@@ -7066,8 +7066,10 @@ F: include/linux/timer*
7066F: kernel/time/*timer* 7066F: kernel/time/*timer*
7067 7067
7068POWER SUPPLY CLASS/SUBSYSTEM and DRIVERS 7068POWER SUPPLY CLASS/SUBSYSTEM and DRIVERS
7069M: Sebastian Reichel <sre@kernel.org>
7069M: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> 7070M: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
7070M: David Woodhouse <dwmw2@infradead.org> 7071M: David Woodhouse <dwmw2@infradead.org>
7072L: linux-pm@vger.kernel.org
7071T: git git://git.infradead.org/battery-2.6.git 7073T: git git://git.infradead.org/battery-2.6.git
7072S: Maintained 7074S: Maintained
7073F: include/linux/power_supply.h 7075F: include/linux/power_supply.h
diff --git a/arch/arm/mach-exynos/Kconfig b/arch/arm/mach-exynos/Kconfig
index 5d4ff6571dcd..2d0240f241b8 100644
--- a/arch/arm/mach-exynos/Kconfig
+++ b/arch/arm/mach-exynos/Kconfig
@@ -100,7 +100,6 @@ config SOC_EXYNOS5440
100 default y 100 default y
101 depends on ARCH_EXYNOS5 101 depends on ARCH_EXYNOS5
102 select ARCH_DMA_ADDR_T_64BIT if ARM_LPAE 102 select ARCH_DMA_ADDR_T_64BIT if ARM_LPAE
103 select ARCH_HAS_OPP
104 select HAVE_ARM_ARCH_TIMER 103 select HAVE_ARM_ARCH_TIMER
105 select AUTO_ZRELADDR 104 select AUTO_ZRELADDR
106 select MIGHT_HAVE_PCI 105 select MIGHT_HAVE_PCI
diff --git a/arch/arm/mach-highbank/Kconfig b/arch/arm/mach-highbank/Kconfig
index a5960e2ac090..31aa866c3317 100644
--- a/arch/arm/mach-highbank/Kconfig
+++ b/arch/arm/mach-highbank/Kconfig
@@ -2,7 +2,6 @@ config ARCH_HIGHBANK
2 bool "Calxeda ECX-1000/2000 (Highbank/Midway)" if ARCH_MULTI_V7 2 bool "Calxeda ECX-1000/2000 (Highbank/Midway)" if ARCH_MULTI_V7
3 select ARCH_DMA_ADDR_T_64BIT if ARM_LPAE 3 select ARCH_DMA_ADDR_T_64BIT if ARM_LPAE
4 select ARCH_HAS_HOLES_MEMORYMODEL 4 select ARCH_HAS_HOLES_MEMORYMODEL
5 select ARCH_HAS_OPP
6 select ARCH_SUPPORTS_BIG_ENDIAN 5 select ARCH_SUPPORTS_BIG_ENDIAN
7 select ARM_AMBA 6 select ARM_AMBA
8 select ARM_ERRATA_764369 if SMP 7 select ARM_ERRATA_764369 if SMP
diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig
index 4b5185748f74..ab6bcfd2e220 100644
--- a/arch/arm/mach-imx/Kconfig
+++ b/arch/arm/mach-imx/Kconfig
@@ -1,6 +1,5 @@
1menuconfig ARCH_MXC 1menuconfig ARCH_MXC
2 bool "Freescale i.MX family" if ARCH_MULTI_V4_V5 || ARCH_MULTI_V6_V7 2 bool "Freescale i.MX family" if ARCH_MULTI_V4_V5 || ARCH_MULTI_V6_V7
3 select ARCH_HAS_OPP
4 select ARCH_REQUIRE_GPIOLIB 3 select ARCH_REQUIRE_GPIOLIB
5 select ARM_CPU_SUSPEND if PM 4 select ARM_CPU_SUSPEND if PM
6 select CLKSRC_MMIO 5 select CLKSRC_MMIO
diff --git a/arch/arm/mach-omap2/Kconfig b/arch/arm/mach-omap2/Kconfig
index 1c1ed737f7ab..e7189dcc9309 100644
--- a/arch/arm/mach-omap2/Kconfig
+++ b/arch/arm/mach-omap2/Kconfig
@@ -15,7 +15,6 @@ config ARCH_OMAP3
15 bool "TI OMAP3" 15 bool "TI OMAP3"
16 depends on ARCH_MULTI_V7 16 depends on ARCH_MULTI_V7
17 select ARCH_OMAP2PLUS 17 select ARCH_OMAP2PLUS
18 select ARCH_HAS_OPP
19 select ARM_CPU_SUSPEND if PM 18 select ARM_CPU_SUSPEND if PM
20 select OMAP_INTERCONNECT 19 select OMAP_INTERCONNECT
21 select PM_OPP if PM 20 select PM_OPP if PM
diff --git a/arch/arm/mach-shmobile/Kconfig b/arch/arm/mach-shmobile/Kconfig
index 798073057e51..3a6e3c20a86d 100644
--- a/arch/arm/mach-shmobile/Kconfig
+++ b/arch/arm/mach-shmobile/Kconfig
@@ -85,7 +85,6 @@ config ARCH_R8A73A4
85 select CPU_V7 85 select CPU_V7
86 select SH_CLK_CPG 86 select SH_CLK_CPG
87 select RENESAS_IRQC 87 select RENESAS_IRQC
88 select ARCH_HAS_OPP
89 select SYS_SUPPORTS_SH_CMT 88 select SYS_SUPPORTS_SH_CMT
90 select SYS_SUPPORTS_SH_TMU 89 select SYS_SUPPORTS_SH_TMU
91 90
@@ -263,7 +262,6 @@ config MACH_KOELSCH
263config MACH_KZM9G 262config MACH_KZM9G
264 bool "KZM-A9-GT board" 263 bool "KZM-A9-GT board"
265 depends on ARCH_SH73A0 264 depends on ARCH_SH73A0
266 select ARCH_HAS_OPP
267 select ARCH_REQUIRE_GPIOLIB 265 select ARCH_REQUIRE_GPIOLIB
268 select REGULATOR_FIXED_VOLTAGE if REGULATOR 266 select REGULATOR_FIXED_VOLTAGE if REGULATOR
269 select SND_SOC_AK4642 if SND_SIMPLE_CARD 267 select SND_SOC_AK4642 if SND_SIMPLE_CARD
diff --git a/arch/arm/mach-vexpress/Kconfig b/arch/arm/mach-vexpress/Kconfig
index d8b9330f896a..1af70329b88d 100644
--- a/arch/arm/mach-vexpress/Kconfig
+++ b/arch/arm/mach-vexpress/Kconfig
@@ -64,7 +64,6 @@ config ARCH_VEXPRESS_DCSCB
64 64
65config ARCH_VEXPRESS_SPC 65config ARCH_VEXPRESS_SPC
66 bool "Versatile Express Serial Power Controller (SPC)" 66 bool "Versatile Express Serial Power Controller (SPC)"
67 select ARCH_HAS_OPP
68 select PM_OPP 67 select PM_OPP
69 help 68 help
70 The TC2 (A15x2 A7x3) versatile express core tile integrates a logic 69 The TC2 (A15x2 A7x3) versatile express core tile integrates a logic
diff --git a/arch/arm/mach-zynq/Kconfig b/arch/arm/mach-zynq/Kconfig
index 0c164f81e72d..aaa5162c1509 100644
--- a/arch/arm/mach-zynq/Kconfig
+++ b/arch/arm/mach-zynq/Kconfig
@@ -1,6 +1,5 @@
1config ARCH_ZYNQ 1config ARCH_ZYNQ
2 bool "Xilinx Zynq ARM Cortex A9 Platform" if ARCH_MULTI_V7 2 bool "Xilinx Zynq ARM Cortex A9 Platform" if ARCH_MULTI_V7
3 select ARCH_HAS_OPP
4 select ARCH_SUPPORTS_BIG_ENDIAN 3 select ARCH_SUPPORTS_BIG_ENDIAN
5 select ARM_AMBA 4 select ARM_AMBA
6 select ARM_GIC 5 select ARM_GIC
diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
index 2f3abcf8f6bc..44a6915ab13d 100644
--- a/arch/ia64/Kconfig
+++ b/arch/ia64/Kconfig
@@ -10,6 +10,7 @@ config IA64
10 select ARCH_MIGHT_HAVE_PC_SERIO 10 select ARCH_MIGHT_HAVE_PC_SERIO
11 select PCI if (!IA64_HP_SIM) 11 select PCI if (!IA64_HP_SIM)
12 select ACPI if (!IA64_HP_SIM) 12 select ACPI if (!IA64_HP_SIM)
13 select ARCH_MIGHT_HAVE_ACPI_PDC if ACPI
13 select PM if (!IA64_HP_SIM) 14 select PM if (!IA64_HP_SIM)
14 select HAVE_UNSTABLE_SCHED_CLOCK 15 select HAVE_UNSTABLE_SCHED_CLOCK
15 select HAVE_IDE 16 select HAVE_IDE
diff --git a/arch/ia64/include/asm/acenv.h b/arch/ia64/include/asm/acenv.h
index 3f9eaeec9873..35ff13afbf34 100644
--- a/arch/ia64/include/asm/acenv.h
+++ b/arch/ia64/include/asm/acenv.h
@@ -19,8 +19,6 @@
19 19
20/* Asm macros */ 20/* Asm macros */
21 21
22#ifdef CONFIG_ACPI
23
24static inline int 22static inline int
25ia64_acpi_acquire_global_lock(unsigned int *lock) 23ia64_acpi_acquire_global_lock(unsigned int *lock)
26{ 24{
@@ -51,6 +49,4 @@ ia64_acpi_release_global_lock(unsigned int *lock)
51#define ACPI_RELEASE_GLOBAL_LOCK(facs, Acq) \ 49#define ACPI_RELEASE_GLOBAL_LOCK(facs, Acq) \
52 ((Acq) = ia64_acpi_release_global_lock(&facs->global_lock)) 50 ((Acq) = ia64_acpi_release_global_lock(&facs->global_lock))
53 51
54#endif
55
56#endif /* _ASM_IA64_ACENV_H */ 52#endif /* _ASM_IA64_ACENV_H */
diff --git a/arch/ia64/include/asm/acpi.h b/arch/ia64/include/asm/acpi.h
index 75dc59a793d6..a1d91ab4c5ef 100644
--- a/arch/ia64/include/asm/acpi.h
+++ b/arch/ia64/include/asm/acpi.h
@@ -40,6 +40,11 @@ extern int acpi_lapic;
40#define acpi_noirq 0 /* ACPI always enabled on IA64 */ 40#define acpi_noirq 0 /* ACPI always enabled on IA64 */
41#define acpi_pci_disabled 0 /* ACPI PCI always enabled on IA64 */ 41#define acpi_pci_disabled 0 /* ACPI PCI always enabled on IA64 */
42#define acpi_strict 1 /* no ACPI spec workarounds on IA64 */ 42#define acpi_strict 1 /* no ACPI spec workarounds on IA64 */
43
44static inline bool acpi_has_cpu_in_madt(void)
45{
46 return !!acpi_lapic;
47}
43#endif 48#endif
44#define acpi_processor_cstate_check(x) (x) /* no idle limits on IA64 :) */ 49#define acpi_processor_cstate_check(x) (x) /* no idle limits on IA64 :) */
45static inline void disable_acpi(void) { } 50static inline void disable_acpi(void) { }
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 6cfeb082a422..bf2405053af5 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -21,6 +21,7 @@ config X86_64
21### Arch settings 21### Arch settings
22config X86 22config X86
23 def_bool y 23 def_bool y
24 select ARCH_MIGHT_HAVE_ACPI_PDC if ACPI
24 select ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS 25 select ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
25 select ARCH_MIGHT_HAVE_PC_PARPORT 26 select ARCH_MIGHT_HAVE_PC_PARPORT
26 select ARCH_MIGHT_HAVE_PC_SERIO 27 select ARCH_MIGHT_HAVE_PC_SERIO
@@ -133,6 +134,7 @@ config X86
133 select ARCH_SUPPORTS_ATOMIC_RMW 134 select ARCH_SUPPORTS_ATOMIC_RMW
134 select HAVE_ACPI_APEI if ACPI 135 select HAVE_ACPI_APEI if ACPI
135 select HAVE_ACPI_APEI_NMI if ACPI 136 select HAVE_ACPI_APEI_NMI if ACPI
137 select ACPI_LEGACY_TABLES_LOOKUP if ACPI
136 138
137config INSTRUCTION_DECODER 139config INSTRUCTION_DECODER
138 def_bool y 140 def_bool y
diff --git a/arch/x86/include/asm/acenv.h b/arch/x86/include/asm/acenv.h
index 66873297e9f5..1b010a859b8b 100644
--- a/arch/x86/include/asm/acenv.h
+++ b/arch/x86/include/asm/acenv.h
@@ -18,8 +18,6 @@
18 18
19#define ACPI_FLUSH_CPU_CACHE() wbinvd() 19#define ACPI_FLUSH_CPU_CACHE() wbinvd()
20 20
21#ifdef CONFIG_ACPI
22
23int __acpi_acquire_global_lock(unsigned int *lock); 21int __acpi_acquire_global_lock(unsigned int *lock);
24int __acpi_release_global_lock(unsigned int *lock); 22int __acpi_release_global_lock(unsigned int *lock);
25 23
@@ -44,6 +42,4 @@ int __acpi_release_global_lock(unsigned int *lock);
44 : "=r"(n_hi), "=r"(n_lo) \ 42 : "=r"(n_hi), "=r"(n_lo) \
45 : "0"(n_hi), "1"(n_lo)) 43 : "0"(n_hi), "1"(n_lo))
46 44
47#endif
48
49#endif /* _ASM_X86_ACENV_H */ 45#endif /* _ASM_X86_ACENV_H */
diff --git a/arch/x86/include/asm/acpi.h b/arch/x86/include/asm/acpi.h
index e06225eda635..0ab4f9fd2687 100644
--- a/arch/x86/include/asm/acpi.h
+++ b/arch/x86/include/asm/acpi.h
@@ -121,6 +121,11 @@ static inline void arch_acpi_set_pdc_bits(u32 *buf)
121 buf[2] &= ~(ACPI_PDC_C_C2C3_FFH); 121 buf[2] &= ~(ACPI_PDC_C_C2C3_FFH);
122} 122}
123 123
124static inline bool acpi_has_cpu_in_madt(void)
125{
126 return !!acpi_lapic;
127}
128
124#else /* !CONFIG_ACPI */ 129#else /* !CONFIG_ACPI */
125 130
126#define acpi_lapic 0 131#define acpi_lapic 0
diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig
index 206942b8d105..d0f3265fb85d 100644
--- a/drivers/acpi/Kconfig
+++ b/drivers/acpi/Kconfig
@@ -42,6 +42,12 @@ menuconfig ACPI
42 42
43if ACPI 43if ACPI
44 44
45config ACPI_LEGACY_TABLES_LOOKUP
46 bool
47
48config ARCH_MIGHT_HAVE_ACPI_PDC
49 bool
50
45config ACPI_SLEEP 51config ACPI_SLEEP
46 bool 52 bool
47 depends on SUSPEND || HIBERNATION 53 depends on SUSPEND || HIBERNATION
diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index ea55e0179f81..505d4d79fe3e 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -36,6 +36,7 @@ acpi-y += scan.o
36acpi-y += resource.o 36acpi-y += resource.o
37acpi-y += acpi_processor.o 37acpi-y += acpi_processor.o
38acpi-y += processor_core.o 38acpi-y += processor_core.o
39acpi-$(CONFIG_ARCH_MIGHT_HAVE_ACPI_PDC) += processor_pdc.o
39acpi-y += ec.o 40acpi-y += ec.o
40acpi-$(CONFIG_ACPI_DOCK) += dock.o 41acpi-$(CONFIG_ACPI_DOCK) += dock.o
41acpi-y += pci_root.o pci_link.o pci_irq.o 42acpi-y += pci_root.o pci_link.o pci_irq.o
diff --git a/drivers/acpi/acpi_extlog.c b/drivers/acpi/acpi_extlog.c
index 0ad6f389d922..b3842ffc19ba 100644
--- a/drivers/acpi/acpi_extlog.c
+++ b/drivers/acpi/acpi_extlog.c
@@ -71,11 +71,11 @@ static u32 l1_percpu_entry;
71#define ELOG_ENTRY_ADDR(phyaddr) \ 71#define ELOG_ENTRY_ADDR(phyaddr) \
72 (phyaddr - elog_base + (u8 *)elog_addr) 72 (phyaddr - elog_base + (u8 *)elog_addr)
73 73
74static struct acpi_generic_status *extlog_elog_entry_check(int cpu, int bank) 74static struct acpi_hest_generic_status *extlog_elog_entry_check(int cpu, int bank)
75{ 75{
76 int idx; 76 int idx;
77 u64 data; 77 u64 data;
78 struct acpi_generic_status *estatus; 78 struct acpi_hest_generic_status *estatus;
79 79
80 WARN_ON(cpu < 0); 80 WARN_ON(cpu < 0);
81 idx = ELOG_IDX(cpu, bank); 81 idx = ELOG_IDX(cpu, bank);
@@ -84,7 +84,7 @@ static struct acpi_generic_status *extlog_elog_entry_check(int cpu, int bank)
84 return NULL; 84 return NULL;
85 85
86 data &= EXT_ELOG_ENTRY_MASK; 86 data &= EXT_ELOG_ENTRY_MASK;
87 estatus = (struct acpi_generic_status *)ELOG_ENTRY_ADDR(data); 87 estatus = (struct acpi_hest_generic_status *)ELOG_ENTRY_ADDR(data);
88 88
89 /* if no valid data in elog entry, just return */ 89 /* if no valid data in elog entry, just return */
90 if (estatus->block_status == 0) 90 if (estatus->block_status == 0)
@@ -94,7 +94,7 @@ static struct acpi_generic_status *extlog_elog_entry_check(int cpu, int bank)
94} 94}
95 95
96static void __print_extlog_rcd(const char *pfx, 96static void __print_extlog_rcd(const char *pfx,
97 struct acpi_generic_status *estatus, int cpu) 97 struct acpi_hest_generic_status *estatus, int cpu)
98{ 98{
99 static atomic_t seqno; 99 static atomic_t seqno;
100 unsigned int curr_seqno; 100 unsigned int curr_seqno;
@@ -113,7 +113,7 @@ static void __print_extlog_rcd(const char *pfx,
113} 113}
114 114
115static int print_extlog_rcd(const char *pfx, 115static int print_extlog_rcd(const char *pfx,
116 struct acpi_generic_status *estatus, int cpu) 116 struct acpi_hest_generic_status *estatus, int cpu)
117{ 117{
118 /* Not more than 2 messages every 5 seconds */ 118 /* Not more than 2 messages every 5 seconds */
119 static DEFINE_RATELIMIT_STATE(ratelimit_corrected, 5*HZ, 2); 119 static DEFINE_RATELIMIT_STATE(ratelimit_corrected, 5*HZ, 2);
@@ -139,8 +139,8 @@ static int extlog_print(struct notifier_block *nb, unsigned long val,
139 struct mce *mce = (struct mce *)data; 139 struct mce *mce = (struct mce *)data;
140 int bank = mce->bank; 140 int bank = mce->bank;
141 int cpu = mce->extcpu; 141 int cpu = mce->extcpu;
142 struct acpi_generic_status *estatus, *tmp; 142 struct acpi_hest_generic_status *estatus, *tmp;
143 struct acpi_generic_data *gdata; 143 struct acpi_hest_generic_data *gdata;
144 const uuid_le *fru_id = &NULL_UUID_LE; 144 const uuid_le *fru_id = &NULL_UUID_LE;
145 char *fru_text = ""; 145 char *fru_text = "";
146 uuid_le *sec_type; 146 uuid_le *sec_type;
@@ -154,7 +154,7 @@ static int extlog_print(struct notifier_block *nb, unsigned long val,
154 /* clear record status to enable BIOS to update it again */ 154 /* clear record status to enable BIOS to update it again */
155 estatus->block_status = 0; 155 estatus->block_status = 0;
156 156
157 tmp = (struct acpi_generic_status *)elog_buf; 157 tmp = (struct acpi_hest_generic_status *)elog_buf;
158 158
159 if (!ras_userspace_consumers()) { 159 if (!ras_userspace_consumers()) {
160 print_extlog_rcd(NULL, tmp, cpu); 160 print_extlog_rcd(NULL, tmp, cpu);
@@ -163,7 +163,7 @@ static int extlog_print(struct notifier_block *nb, unsigned long val,
163 163
164 /* log event via trace */ 164 /* log event via trace */
165 err_seq++; 165 err_seq++;
166 gdata = (struct acpi_generic_data *)(tmp + 1); 166 gdata = (struct acpi_hest_generic_data *)(tmp + 1);
167 if (gdata->validation_bits & CPER_SEC_VALID_FRU_ID) 167 if (gdata->validation_bits & CPER_SEC_VALID_FRU_ID)
168 fru_id = (uuid_le *)gdata->fru_id; 168 fru_id = (uuid_le *)gdata->fru_id;
169 if (gdata->validation_bits & CPER_SEC_VALID_FRU_TEXT) 169 if (gdata->validation_bits & CPER_SEC_VALID_FRU_TEXT)
diff --git a/drivers/acpi/acpi_lpss.c b/drivers/acpi/acpi_lpss.c
index 9cb65b0e7597..ce06149088c5 100644
--- a/drivers/acpi/acpi_lpss.c
+++ b/drivers/acpi/acpi_lpss.c
@@ -113,6 +113,14 @@ static void lpss_i2c_setup(struct lpss_private_data *pdata)
113 writel(val, pdata->mmio_base + offset); 113 writel(val, pdata->mmio_base + offset);
114} 114}
115 115
116static struct lpss_device_desc wpt_dev_desc = {
117 .clk_required = true,
118 .prv_offset = 0x800,
119 .ltr_required = true,
120 .clk_divider = true,
121 .clk_gate = true,
122};
123
116static struct lpss_device_desc lpt_dev_desc = { 124static struct lpss_device_desc lpt_dev_desc = {
117 .clk_required = true, 125 .clk_required = true,
118 .prv_offset = 0x800, 126 .prv_offset = 0x800,
@@ -226,6 +234,8 @@ static const struct acpi_device_id acpi_lpss_device_ids[] = {
226 { "INT3436", LPSS_ADDR(lpt_sdio_dev_desc) }, 234 { "INT3436", LPSS_ADDR(lpt_sdio_dev_desc) },
227 { "INT3437", }, 235 { "INT3437", },
228 236
237 { "INT3438", LPSS_ADDR(wpt_dev_desc) },
238
229 { } 239 { }
230}; 240};
231 241
diff --git a/drivers/acpi/acpi_pnp.c b/drivers/acpi/acpi_pnp.c
index 4ddb0dca56f6..996fa1959eea 100644
--- a/drivers/acpi/acpi_pnp.c
+++ b/drivers/acpi/acpi_pnp.c
@@ -12,6 +12,7 @@
12 12
13#include <linux/acpi.h> 13#include <linux/acpi.h>
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/ctype.h>
15 16
16static const struct acpi_device_id acpi_pnp_device_ids[] = { 17static const struct acpi_device_id acpi_pnp_device_ids[] = {
17 /* soc_button_array */ 18 /* soc_button_array */
@@ -320,11 +321,6 @@ static const struct acpi_device_id acpi_pnp_device_ids[] = {
320 {""}, 321 {""},
321}; 322};
322 323
323static bool is_hex_digit(char c)
324{
325 return (c >= 0 && c <= '9') || (c >= 'A' && c <= 'F');
326}
327
328static bool matching_id(char *idstr, char *list_id) 324static bool matching_id(char *idstr, char *list_id)
329{ 325{
330 int i; 326 int i;
@@ -335,7 +331,7 @@ static bool matching_id(char *idstr, char *list_id)
335 for (i = 3; i < 7; i++) { 331 for (i = 3; i < 7; i++) {
336 char c = toupper(idstr[i]); 332 char c = toupper(idstr[i]);
337 333
338 if (!is_hex_digit(c) 334 if (!isxdigit(c)
339 || (list_id[i] != 'X' && c != toupper(list_id[i]))) 335 || (list_id[i] != 'X' && c != toupper(list_id[i])))
340 return false; 336 return false;
341 } 337 }
diff --git a/drivers/acpi/acpi_processor.c b/drivers/acpi/acpi_processor.c
index 1c085742644f..1fdf5e07a1c7 100644
--- a/drivers/acpi/acpi_processor.c
+++ b/drivers/acpi/acpi_processor.c
@@ -268,7 +268,7 @@ static int acpi_processor_get_info(struct acpi_device *device)
268 pr->apic_id = apic_id; 268 pr->apic_id = apic_id;
269 269
270 cpu_index = acpi_map_cpuid(pr->apic_id, pr->acpi_id); 270 cpu_index = acpi_map_cpuid(pr->apic_id, pr->acpi_id);
271 if (!cpu0_initialized && !acpi_lapic) { 271 if (!cpu0_initialized && !acpi_has_cpu_in_madt()) {
272 cpu0_initialized = 1; 272 cpu0_initialized = 1;
273 /* Handle UP system running SMP kernel, with no LAPIC in MADT */ 273 /* Handle UP system running SMP kernel, with no LAPIC in MADT */
274 if ((cpu_index == -1) && (num_online_cpus() == 1)) 274 if ((cpu_index == -1) && (num_online_cpus() == 1))
diff --git a/drivers/acpi/acpica/Makefile b/drivers/acpi/acpica/Makefile
index 8bb43f06e11f..c1a963581dc0 100644
--- a/drivers/acpi/acpica/Makefile
+++ b/drivers/acpi/acpica/Makefile
@@ -2,7 +2,7 @@
2# Makefile for ACPICA Core interpreter 2# Makefile for ACPICA Core interpreter
3# 3#
4 4
5ccflags-y := -Os 5ccflags-y := -Os -DBUILDING_ACPICA
6ccflags-$(CONFIG_ACPI_DEBUG) += -DACPI_DEBUG_OUTPUT 6ccflags-$(CONFIG_ACPI_DEBUG) += -DACPI_DEBUG_OUTPUT
7 7
8# use acpi.o to put all files here into acpi.o modparam namespace 8# use acpi.o to put all files here into acpi.o modparam namespace
@@ -157,6 +157,7 @@ acpi-y += \
157 uterror.o \ 157 uterror.o \
158 uteval.o \ 158 uteval.o \
159 utglobal.o \ 159 utglobal.o \
160 uthex.o \
160 utids.o \ 161 utids.o \
161 utinit.o \ 162 utinit.o \
162 utlock.o \ 163 utlock.o \
@@ -175,5 +176,10 @@ acpi-y += \
175 utxferror.o \ 176 utxferror.o \
176 utxfmutex.o 177 utxfmutex.o
177 178
178acpi-$(ACPI_FUTURE_USAGE) += uttrack.o utcache.o 179acpi-$(ACPI_FUTURE_USAGE) += \
180 utcache.o \
181 utfileio.o \
182 utprint.o \
183 uttrack.o \
184 utuuid.o
179 185
diff --git a/drivers/acpi/acpica/acapps.h b/drivers/acpi/acpica/acapps.h
index 8698ffba6f39..3d2c88289da9 100644
--- a/drivers/acpi/acpica/acapps.h
+++ b/drivers/acpi/acpica/acapps.h
@@ -79,10 +79,13 @@
79/* Macros for usage messages */ 79/* Macros for usage messages */
80 80
81#define ACPI_USAGE_HEADER(usage) \ 81#define ACPI_USAGE_HEADER(usage) \
82 printf ("Usage: %s\nOptions:\n", usage); 82 acpi_os_printf ("Usage: %s\nOptions:\n", usage);
83
84#define ACPI_USAGE_TEXT(description) \
85 acpi_os_printf (description);
83 86
84#define ACPI_OPTION(name, description) \ 87#define ACPI_OPTION(name, description) \
85 printf (" %-18s%s\n", name, description); 88 acpi_os_printf (" %-18s%s\n", name, description);
86 89
87#define FILE_SUFFIX_DISASSEMBLY "dsl" 90#define FILE_SUFFIX_DISASSEMBLY "dsl"
88#define ACPI_TABLE_FILE_SUFFIX ".dat" 91#define ACPI_TABLE_FILE_SUFFIX ".dat"
@@ -102,7 +105,7 @@ extern char *acpi_gbl_optarg;
102/* 105/*
103 * cmfsize - Common get file size function 106 * cmfsize - Common get file size function
104 */ 107 */
105u32 cm_get_file_size(FILE * file); 108u32 cm_get_file_size(ACPI_FILE file);
106 109
107#ifndef ACPI_DUMP_APP 110#ifndef ACPI_DUMP_APP
108/* 111/*
diff --git a/drivers/acpi/acpica/acdebug.h b/drivers/acpi/acpica/acdebug.h
index 68a91eb0fa48..1d026ff1683f 100644
--- a/drivers/acpi/acpica/acdebug.h
+++ b/drivers/acpi/acpica/acdebug.h
@@ -233,9 +233,6 @@ acpi_status acpi_db_load_acpi_table(char *filename);
233acpi_status 233acpi_status
234acpi_db_get_table_from_file(char *filename, struct acpi_table_header **table); 234acpi_db_get_table_from_file(char *filename, struct acpi_table_header **table);
235 235
236acpi_status
237acpi_db_read_table_from_file(char *filename, struct acpi_table_header **table);
238
239/* 236/*
240 * dbhistry - debugger HISTORY command 237 * dbhistry - debugger HISTORY command
241 */ 238 */
diff --git a/drivers/acpi/acpica/acglobal.h b/drivers/acpi/acpica/acglobal.h
index 115eedcade1e..ebf02cc10a43 100644
--- a/drivers/acpi/acpica/acglobal.h
+++ b/drivers/acpi/acpica/acglobal.h
@@ -297,7 +297,7 @@ ACPI_GLOBAL(u32, acpi_gbl_trace_dbg_layer);
297 * 297 *
298 ****************************************************************************/ 298 ****************************************************************************/
299 299
300ACPI_GLOBAL(u8, acpi_gbl_db_output_flags); 300ACPI_INIT_GLOBAL(u8, acpi_gbl_db_output_flags, ACPI_DB_CONSOLE_OUTPUT);
301 301
302#ifdef ACPI_DISASSEMBLER 302#ifdef ACPI_DISASSEMBLER
303 303
@@ -362,6 +362,12 @@ ACPI_GLOBAL(u32, acpi_gbl_num_objects);
362#ifdef ACPI_APPLICATION 362#ifdef ACPI_APPLICATION
363 363
364ACPI_INIT_GLOBAL(ACPI_FILE, acpi_gbl_debug_file, NULL); 364ACPI_INIT_GLOBAL(ACPI_FILE, acpi_gbl_debug_file, NULL);
365ACPI_INIT_GLOBAL(ACPI_FILE, acpi_gbl_output_file, NULL);
366
367/* Print buffer */
368
369ACPI_GLOBAL(acpi_spinlock, acpi_gbl_print_lock); /* For print buffer */
370ACPI_GLOBAL(char, acpi_gbl_print_buffer[1024]);
365 371
366#endif /* ACPI_APPLICATION */ 372#endif /* ACPI_APPLICATION */
367 373
diff --git a/drivers/acpi/acpica/aclocal.h b/drivers/acpi/acpica/aclocal.h
index 91f801a2e689..1f9aba5fb81f 100644
--- a/drivers/acpi/acpica/aclocal.h
+++ b/drivers/acpi/acpica/aclocal.h
@@ -730,12 +730,13 @@ union acpi_parse_value {
730#define ACPI_DASM_STRING 0x02 /* Buffer is a ASCII string */ 730#define ACPI_DASM_STRING 0x02 /* Buffer is a ASCII string */
731#define ACPI_DASM_UNICODE 0x03 /* Buffer is a Unicode string */ 731#define ACPI_DASM_UNICODE 0x03 /* Buffer is a Unicode string */
732#define ACPI_DASM_PLD_METHOD 0x04 /* Buffer is a _PLD method bit-packed buffer */ 732#define ACPI_DASM_PLD_METHOD 0x04 /* Buffer is a _PLD method bit-packed buffer */
733#define ACPI_DASM_EISAID 0x05 /* Integer is an EISAID */ 733#define ACPI_DASM_UUID 0x05 /* Buffer is a UUID/GUID */
734#define ACPI_DASM_MATCHOP 0x06 /* Parent opcode is a Match() operator */ 734#define ACPI_DASM_EISAID 0x06 /* Integer is an EISAID */
735#define ACPI_DASM_LNOT_PREFIX 0x07 /* Start of a Lnot_equal (etc.) pair of opcodes */ 735#define ACPI_DASM_MATCHOP 0x07 /* Parent opcode is a Match() operator */
736#define ACPI_DASM_LNOT_SUFFIX 0x08 /* End of a Lnot_equal (etc.) pair of opcodes */ 736#define ACPI_DASM_LNOT_PREFIX 0x08 /* Start of a Lnot_equal (etc.) pair of opcodes */
737#define ACPI_DASM_HID_STRING 0x09 /* String is a _HID or _CID */ 737#define ACPI_DASM_LNOT_SUFFIX 0x09 /* End of a Lnot_equal (etc.) pair of opcodes */
738#define ACPI_DASM_IGNORE 0x0A /* Not used at this time */ 738#define ACPI_DASM_HID_STRING 0x0A /* String is a _HID or _CID */
739#define ACPI_DASM_IGNORE 0x0B /* Not used at this time */
739 740
740/* 741/*
741 * Generic operation (for example: If, While, Store) 742 * Generic operation (for example: If, While, Store)
@@ -1154,4 +1155,9 @@ struct ah_device_id {
1154 char *description; 1155 char *description;
1155}; 1156};
1156 1157
1158struct ah_uuid {
1159 char *description;
1160 char *string;
1161};
1162
1157#endif /* __ACLOCAL_H__ */ 1163#endif /* __ACLOCAL_H__ */
diff --git a/drivers/acpi/acpica/acpredef.h b/drivers/acpi/acpica/acpredef.h
index bd08817cafd8..bd3908d26c4f 100644
--- a/drivers/acpi/acpica/acpredef.h
+++ b/drivers/acpi/acpica/acpredef.h
@@ -105,6 +105,11 @@
105 * count = 0 (optional) 105 * count = 0 (optional)
106 * (Used for _DLM) 106 * (Used for _DLM)
107 * 107 *
108 * ACPI_PTYPE2_UUID_PAIR: Each subpackage is preceded by a UUID Buffer. The UUID
109 * defines the format of the package. Zero-length parent package is
110 * allowed.
111 * (Used for _DSD)
112 *
108 *****************************************************************************/ 113 *****************************************************************************/
109 114
110enum acpi_return_package_types { 115enum acpi_return_package_types {
@@ -117,7 +122,8 @@ enum acpi_return_package_types {
117 ACPI_PTYPE2_FIXED = 7, 122 ACPI_PTYPE2_FIXED = 7,
118 ACPI_PTYPE2_MIN = 8, 123 ACPI_PTYPE2_MIN = 8,
119 ACPI_PTYPE2_REV_FIXED = 9, 124 ACPI_PTYPE2_REV_FIXED = 9,
120 ACPI_PTYPE2_FIX_VAR = 10 125 ACPI_PTYPE2_FIX_VAR = 10,
126 ACPI_PTYPE2_UUID_PAIR = 11
121}; 127};
122 128
123/* Support macros for users of the predefined info table */ 129/* Support macros for users of the predefined info table */
@@ -364,6 +370,9 @@ const union acpi_predefined_info acpi_gbl_predefined_methods[] = {
364 {{"_CBA", METHOD_0ARGS, 370 {{"_CBA", METHOD_0ARGS,
365 METHOD_RETURNS(ACPI_RTYPE_INTEGER)}}, /* See PCI firmware spec 3.0 */ 371 METHOD_RETURNS(ACPI_RTYPE_INTEGER)}}, /* See PCI firmware spec 3.0 */
366 372
373 {{"_CCA", METHOD_0ARGS,
374 METHOD_RETURNS(ACPI_RTYPE_INTEGER)}}, /* ACPI 5.1 */
375
367 {{"_CDM", METHOD_0ARGS, 376 {{"_CDM", METHOD_0ARGS,
368 METHOD_RETURNS(ACPI_RTYPE_INTEGER)}}, 377 METHOD_RETURNS(ACPI_RTYPE_INTEGER)}},
369 378
@@ -436,6 +445,11 @@ const union acpi_predefined_info acpi_gbl_predefined_methods[] = {
436 {{"_DOS", METHOD_1ARGS(ACPI_TYPE_INTEGER), 445 {{"_DOS", METHOD_1ARGS(ACPI_TYPE_INTEGER),
437 METHOD_NO_RETURN_VALUE}}, 446 METHOD_NO_RETURN_VALUE}},
438 447
448 {{"_DSD", METHOD_0ARGS,
449 METHOD_RETURNS(ACPI_RTYPE_PACKAGE)}}, /* Variable-length (Pkgs) each: 1 Buf, 1 Pkg */
450 PACKAGE_INFO(ACPI_PTYPE2_UUID_PAIR, ACPI_RTYPE_BUFFER, 1,
451 ACPI_RTYPE_PACKAGE, 1, 0),
452
439 {{"_DSM", 453 {{"_DSM",
440 METHOD_4ARGS(ACPI_TYPE_BUFFER, ACPI_TYPE_INTEGER, ACPI_TYPE_INTEGER, 454 METHOD_4ARGS(ACPI_TYPE_BUFFER, ACPI_TYPE_INTEGER, ACPI_TYPE_INTEGER,
441 ACPI_TYPE_PACKAGE), 455 ACPI_TYPE_PACKAGE),
diff --git a/drivers/acpi/acpica/acutils.h b/drivers/acpi/acpica/acutils.h
index 1e256c5bda20..486d342e74b6 100644
--- a/drivers/acpi/acpica/acutils.h
+++ b/drivers/acpi/acpica/acutils.h
@@ -95,7 +95,6 @@ extern const char *acpi_gbl_pt_decode[];
95#ifdef ACPI_ASL_COMPILER 95#ifdef ACPI_ASL_COMPILER
96 96
97#include <stdio.h> 97#include <stdio.h>
98extern FILE *acpi_gbl_output_file;
99 98
100#define ACPI_MSG_REDIRECT_BEGIN \ 99#define ACPI_MSG_REDIRECT_BEGIN \
101 FILE *output_file = acpi_gbl_output_file; \ 100 FILE *output_file = acpi_gbl_output_file; \
@@ -195,6 +194,8 @@ char *acpi_ut_get_event_name(u32 event_id);
195 194
196char acpi_ut_hex_to_ascii_char(u64 integer, u32 position); 195char acpi_ut_hex_to_ascii_char(u64 integer, u32 position);
197 196
197u8 acpi_ut_ascii_char_to_hex(int hex_char);
198
198u8 acpi_ut_valid_object_type(acpi_object_type type); 199u8 acpi_ut_valid_object_type(acpi_object_type type);
199 200
200/* 201/*
@@ -211,6 +212,8 @@ void acpi_ut_subsystem_shutdown(void);
211 212
212acpi_size acpi_ut_strlen(const char *string); 213acpi_size acpi_ut_strlen(const char *string);
213 214
215char *acpi_ut_strchr(const char *string, int ch);
216
214char *acpi_ut_strcpy(char *dst_string, const char *src_string); 217char *acpi_ut_strcpy(char *dst_string, const char *src_string);
215 218
216char *acpi_ut_strncpy(char *dst_string, 219char *acpi_ut_strncpy(char *dst_string,
@@ -257,7 +260,7 @@ extern const u8 _acpi_ctype[];
257#define ACPI_IS_XDIGIT(c) (_acpi_ctype[(unsigned char)(c)] & (_ACPI_XD)) 260#define ACPI_IS_XDIGIT(c) (_acpi_ctype[(unsigned char)(c)] & (_ACPI_XD))
258#define ACPI_IS_UPPER(c) (_acpi_ctype[(unsigned char)(c)] & (_ACPI_UP)) 261#define ACPI_IS_UPPER(c) (_acpi_ctype[(unsigned char)(c)] & (_ACPI_UP))
259#define ACPI_IS_LOWER(c) (_acpi_ctype[(unsigned char)(c)] & (_ACPI_LO)) 262#define ACPI_IS_LOWER(c) (_acpi_ctype[(unsigned char)(c)] & (_ACPI_LO))
260#define ACPI_IS_PRINT(c) (_acpi_ctype[(unsigned char)(c)] & (_ACPI_LO | _ACPI_UP | _ACPI_DI | _ACPI_SP | _ACPI_PU)) 263#define ACPI_IS_PRINT(c) (_acpi_ctype[(unsigned char)(c)] & (_ACPI_LO | _ACPI_UP | _ACPI_DI | _ACPI_XS | _ACPI_PU))
261#define ACPI_IS_ALPHA(c) (_acpi_ctype[(unsigned char)(c)] & (_ACPI_LO | _ACPI_UP)) 264#define ACPI_IS_ALPHA(c) (_acpi_ctype[(unsigned char)(c)] & (_ACPI_LO | _ACPI_UP))
262 265
263#endif /* !ACPI_USE_SYSTEM_CLIBRARY */ 266#endif /* !ACPI_USE_SYSTEM_CLIBRARY */
@@ -352,6 +355,13 @@ acpi_ut_debug_dump_buffer(u8 *buffer, u32 count, u32 display, u32 component_id);
352 355
353void acpi_ut_dump_buffer(u8 *buffer, u32 count, u32 display, u32 offset); 356void acpi_ut_dump_buffer(u8 *buffer, u32 count, u32 display, u32 offset);
354 357
358#ifdef ACPI_APPLICATION
359void
360acpi_ut_dump_buffer_to_file(ACPI_FILE file,
361 u8 *buffer,
362 u32 count, u32 display, u32 base_offset);
363#endif
364
355void acpi_ut_report_error(char *module_name, u32 line_number); 365void acpi_ut_report_error(char *module_name, u32 line_number);
356 366
357void acpi_ut_report_info(char *module_name, u32 line_number); 367void acpi_ut_report_info(char *module_name, u32 line_number);
@@ -394,6 +404,14 @@ acpi_ut_execute_power_methods(struct acpi_namespace_node *device_node,
394 u8 method_count, u8 *out_values); 404 u8 method_count, u8 *out_values);
395 405
396/* 406/*
407 * utfileio - file operations
408 */
409#ifdef ACPI_APPLICATION
410acpi_status
411acpi_ut_read_table_from_file(char *filename, struct acpi_table_header **table);
412#endif
413
414/*
397 * utids - device ID support 415 * utids - device ID support
398 */ 416 */
399acpi_status 417acpi_status
@@ -743,4 +761,30 @@ const struct ah_predefined_name *acpi_ah_match_predefined_name(char *nameseg);
743 761
744const struct ah_device_id *acpi_ah_match_hardware_id(char *hid); 762const struct ah_device_id *acpi_ah_match_hardware_id(char *hid);
745 763
764const char *acpi_ah_match_uuid(u8 *data);
765
766/*
767 * utprint - printf/vprintf output functions
768 */
769const char *acpi_ut_scan_number(const char *string, u64 *number_ptr);
770
771const char *acpi_ut_print_number(char *string, u64 number);
772
773int
774acpi_ut_vsnprintf(char *string,
775 acpi_size size, const char *format, va_list args);
776
777int acpi_ut_snprintf(char *string, acpi_size size, const char *format, ...);
778
779#ifdef ACPI_APPLICATION
780int acpi_ut_file_vprintf(ACPI_FILE file, const char *format, va_list args);
781
782int acpi_ut_file_printf(ACPI_FILE file, const char *format, ...);
783#endif
784
785/*
786 * utuuid -- UUID support functions
787 */
788void acpi_ut_convert_string_to_uuid(char *in_string, u8 *uuid_buffer);
789
746#endif /* _ACUTILS_H */ 790#endif /* _ACUTILS_H */
diff --git a/drivers/acpi/acpica/evgpe.c b/drivers/acpi/acpica/evgpe.c
index 48f70013b488..e4ba4dec86af 100644
--- a/drivers/acpi/acpica/evgpe.c
+++ b/drivers/acpi/acpica/evgpe.c
@@ -698,21 +698,6 @@ acpi_ev_gpe_dispatch(struct acpi_namespace_node *gpe_device,
698 } 698 }
699 699
700 /* 700 /*
701 * If edge-triggered, clear the GPE status bit now. Note that
702 * level-triggered events are cleared after the GPE is serviced.
703 */
704 if ((gpe_event_info->flags & ACPI_GPE_XRUPT_TYPE_MASK) ==
705 ACPI_GPE_EDGE_TRIGGERED) {
706 status = acpi_hw_clear_gpe(gpe_event_info);
707 if (ACPI_FAILURE(status)) {
708 ACPI_EXCEPTION((AE_INFO, status,
709 "Unable to clear GPE %02X",
710 gpe_number));
711 return_UINT32(ACPI_INTERRUPT_NOT_HANDLED);
712 }
713 }
714
715 /*
716 * Always disable the GPE so that it does not keep firing before 701 * Always disable the GPE so that it does not keep firing before
717 * any asynchronous activity completes (either from the execution 702 * any asynchronous activity completes (either from the execution
718 * of a GPE method or an asynchronous GPE handler.) 703 * of a GPE method or an asynchronous GPE handler.)
@@ -729,6 +714,23 @@ acpi_ev_gpe_dispatch(struct acpi_namespace_node *gpe_device,
729 } 714 }
730 715
731 /* 716 /*
717 * If edge-triggered, clear the GPE status bit now. Note that
718 * level-triggered events are cleared after the GPE is serviced.
719 */
720 if ((gpe_event_info->flags & ACPI_GPE_XRUPT_TYPE_MASK) ==
721 ACPI_GPE_EDGE_TRIGGERED) {
722 status = acpi_hw_clear_gpe(gpe_event_info);
723 if (ACPI_FAILURE(status)) {
724 ACPI_EXCEPTION((AE_INFO, status,
725 "Unable to clear GPE %02X",
726 gpe_number));
727 (void)acpi_hw_low_set_gpe(gpe_event_info,
728 ACPI_GPE_CONDITIONAL_ENABLE);
729 return_UINT32(ACPI_INTERRUPT_NOT_HANDLED);
730 }
731 }
732
733 /*
732 * Dispatch the GPE to either an installed handler or the control 734 * Dispatch the GPE to either an installed handler or the control
733 * method associated with this GPE (_Lxx or _Exx). If a handler 735 * method associated with this GPE (_Lxx or _Exx). If a handler
734 * exists, we invoke it and do not attempt to run the method. 736 * exists, we invoke it and do not attempt to run the method.
diff --git a/drivers/acpi/acpica/evxfgpe.c b/drivers/acpi/acpica/evxfgpe.c
index cb534faf5369..0cf159cc6e6d 100644
--- a/drivers/acpi/acpica/evxfgpe.c
+++ b/drivers/acpi/acpica/evxfgpe.c
@@ -126,11 +126,19 @@ acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number)
126 126
127 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); 127 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
128 128
129 /* Ensure that we have a valid GPE number */ 129 /*
130 130 * Ensure that we have a valid GPE number and that there is some way
131 * of handling the GPE (handler or a GPE method). In other words, we
132 * won't allow a valid GPE to be enabled if there is no way to handle it.
133 */
131 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number); 134 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
132 if (gpe_event_info) { 135 if (gpe_event_info) {
133 status = acpi_ev_add_gpe_reference(gpe_event_info); 136 if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) !=
137 ACPI_GPE_DISPATCH_NONE) {
138 status = acpi_ev_add_gpe_reference(gpe_event_info);
139 } else {
140 status = AE_NO_HANDLER;
141 }
134 } 142 }
135 143
136 acpi_os_release_lock(acpi_gbl_gpe_lock, flags); 144 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
@@ -179,6 +187,53 @@ ACPI_EXPORT_SYMBOL(acpi_disable_gpe)
179 187
180/******************************************************************************* 188/*******************************************************************************
181 * 189 *
190 * FUNCTION: acpi_mark_gpe_for_wake
191 *
192 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
193 * gpe_number - GPE level within the GPE block
194 *
195 * RETURN: Status
196 *
197 * DESCRIPTION: Mark a GPE as having the ability to wake the system. Simply
198 * sets the ACPI_GPE_CAN_WAKE flag.
199 *
200 * Some potential callers of acpi_setup_gpe_for_wake may know in advance that
201 * there won't be any notify handlers installed for device wake notifications
202 * from the given GPE (one example is a button GPE in Linux). For these cases,
203 * acpi_mark_gpe_for_wake should be used instead of acpi_setup_gpe_for_wake.
204 * This will set the ACPI_GPE_CAN_WAKE flag for the GPE without trying to
205 * setup implicit wake notification for it (since there's no handler method).
206 *
207 ******************************************************************************/
208acpi_status acpi_mark_gpe_for_wake(acpi_handle gpe_device, u32 gpe_number)
209{
210 struct acpi_gpe_event_info *gpe_event_info;
211 acpi_status status = AE_BAD_PARAMETER;
212 acpi_cpu_flags flags;
213
214 ACPI_FUNCTION_TRACE(acpi_mark_gpe_for_wake);
215
216 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
217
218 /* Ensure that we have a valid GPE number */
219
220 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
221 if (gpe_event_info) {
222
223 /* Mark the GPE as a possible wake event */
224
225 gpe_event_info->flags |= ACPI_GPE_CAN_WAKE;
226 status = AE_OK;
227 }
228
229 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
230 return_ACPI_STATUS(status);
231}
232
233ACPI_EXPORT_SYMBOL(acpi_mark_gpe_for_wake)
234
235/*******************************************************************************
236 *
182 * FUNCTION: acpi_setup_gpe_for_wake 237 * FUNCTION: acpi_setup_gpe_for_wake
183 * 238 *
184 * PARAMETERS: wake_device - Device associated with the GPE (via _PRW) 239 * PARAMETERS: wake_device - Device associated with the GPE (via _PRW)
diff --git a/drivers/acpi/acpica/exdebug.c b/drivers/acpi/acpica/exdebug.c
index 4cfc3d3b5c97..6fbfad47518c 100644
--- a/drivers/acpi/acpica/exdebug.c
+++ b/drivers/acpi/acpica/exdebug.c
@@ -75,6 +75,7 @@ acpi_ex_do_debug_object(union acpi_operand_object *source_desc,
75 u32 level, u32 index) 75 u32 level, u32 index)
76{ 76{
77 u32 i; 77 u32 i;
78 u32 timer;
78 79
79 ACPI_FUNCTION_TRACE_PTR(ex_do_debug_object, source_desc); 80 ACPI_FUNCTION_TRACE_PTR(ex_do_debug_object, source_desc);
80 81
@@ -86,11 +87,19 @@ acpi_ex_do_debug_object(union acpi_operand_object *source_desc,
86 } 87 }
87 88
88 /* 89 /*
90 * We will emit the current timer value (in microseconds) with each
91 * debug output. Only need the lower 26 bits. This allows for 67
92 * million microseconds or 67 seconds before rollover.
93 */
94 timer = ((u32)acpi_os_get_timer() / 10); /* (100 nanoseconds to microseconds) */
95 timer &= 0x03FFFFFF;
96
97 /*
89 * Print line header as long as we are not in the middle of an 98 * Print line header as long as we are not in the middle of an
90 * object display 99 * object display
91 */ 100 */
92 if (!((level > 0) && index == 0)) { 101 if (!((level > 0) && index == 0)) {
93 acpi_os_printf("[ACPI Debug] %*s", level, " "); 102 acpi_os_printf("[ACPI Debug %.8u] %*s", timer, level, " ");
94 } 103 }
95 104
96 /* Display the index for package output only */ 105 /* Display the index for package output only */
diff --git a/drivers/acpi/acpica/exdump.c b/drivers/acpi/acpica/exdump.c
index 925202acc3e4..0f23c3f2678e 100644
--- a/drivers/acpi/acpica/exdump.c
+++ b/drivers/acpi/acpica/exdump.c
@@ -494,7 +494,7 @@ acpi_ex_dump_object(union acpi_operand_object *obj_desc,
494 } 494 }
495 } 495 }
496 496
497 acpi_os_printf("\n", next); 497 acpi_os_printf("\n");
498 break; 498 break;
499 499
500 case ACPI_EXD_HDLR_LIST: 500 case ACPI_EXD_HDLR_LIST:
@@ -528,7 +528,7 @@ acpi_ex_dump_object(union acpi_operand_object *obj_desc,
528 } 528 }
529 } 529 }
530 530
531 acpi_os_printf("\n", next); 531 acpi_os_printf("\n");
532 break; 532 break;
533 533
534 case ACPI_EXD_RGN_LIST: 534 case ACPI_EXD_RGN_LIST:
@@ -562,7 +562,7 @@ acpi_ex_dump_object(union acpi_operand_object *obj_desc,
562 } 562 }
563 } 563 }
564 564
565 acpi_os_printf("\n", next); 565 acpi_os_printf("\n");
566 break; 566 break;
567 567
568 case ACPI_EXD_NODE: 568 case ACPI_EXD_NODE:
diff --git a/drivers/acpi/acpica/exfield.c b/drivers/acpi/acpica/exfield.c
index 12878e1982f7..6907ce0c704c 100644
--- a/drivers/acpi/acpica/exfield.c
+++ b/drivers/acpi/acpica/exfield.c
@@ -56,7 +56,7 @@ acpi_ex_get_serial_access_length(u32 accessor_type, u32 access_length);
56 56
57/******************************************************************************* 57/*******************************************************************************
58 * 58 *
59 * FUNCTION: acpi_get_serial_access_bytes 59 * FUNCTION: acpi_ex_get_serial_access_length
60 * 60 *
61 * PARAMETERS: accessor_type - The type of the protocol indicated by region 61 * PARAMETERS: accessor_type - The type of the protocol indicated by region
62 * field access attributes 62 * field access attributes
@@ -103,7 +103,7 @@ acpi_ex_get_serial_access_length(u32 accessor_type, u32 access_length)
103 case AML_FIELD_ATTRIB_BLOCK_CALL: 103 case AML_FIELD_ATTRIB_BLOCK_CALL:
104 default: 104 default:
105 105
106 length = ACPI_GSBUS_BUFFER_SIZE; 106 length = ACPI_GSBUS_BUFFER_SIZE - 2;
107 break; 107 break;
108 } 108 }
109 109
@@ -186,12 +186,11 @@ acpi_ex_read_data_from_field(struct acpi_walk_state * walk_state,
186 access_length); 186 access_length);
187 187
188 /* 188 /*
189 * Add additional 2 bytes for modeled generic_serial_bus data buffer: 189 * Add additional 2 bytes for the generic_serial_bus data buffer:
190 * typedef struct { 190 *
191 * BYTEStatus; // Byte 0 of the data buffer 191 * Status; (Byte 0 of the data buffer)
192 * BYTELength; // Byte 1 of the data buffer 192 * Length; (Byte 1 of the data buffer)
193 * BYTE[x-1]Data; // Bytes 2-x of the arbitrary length data buffer, 193 * Data[x-1]; (Bytes 2-x of the arbitrary length data buffer)
194 * }
195 */ 194 */
196 length += 2; 195 length += 2;
197 function = ACPI_READ | (accessor_type << 16); 196 function = ACPI_READ | (accessor_type << 16);
@@ -368,12 +367,11 @@ acpi_ex_write_data_to_field(union acpi_operand_object *source_desc,
368 access_length); 367 access_length);
369 368
370 /* 369 /*
371 * Add additional 2 bytes for modeled generic_serial_bus data buffer: 370 * Add additional 2 bytes for the generic_serial_bus data buffer:
372 * typedef struct { 371 *
373 * BYTEStatus; // Byte 0 of the data buffer 372 * Status; (Byte 0 of the data buffer)
374 * BYTELength; // Byte 1 of the data buffer 373 * Length; (Byte 1 of the data buffer)
375 * BYTE[x-1]Data; // Bytes 2-x of the arbitrary length data buffer, 374 * Data[x-1]; (Bytes 2-x of the arbitrary length data buffer)
376 * }
377 */ 375 */
378 length += 2; 376 length += 2;
379 function = ACPI_WRITE | (accessor_type << 16); 377 function = ACPI_WRITE | (accessor_type << 16);
diff --git a/drivers/acpi/acpica/hwregs.c b/drivers/acpi/acpica/hwregs.c
index e0fd9b4978cd..a4c34d2c556b 100644
--- a/drivers/acpi/acpica/hwregs.c
+++ b/drivers/acpi/acpica/hwregs.c
@@ -278,8 +278,9 @@ acpi_status acpi_hw_clear_acpi_status(void)
278 278
279 acpi_os_release_lock(acpi_gbl_hardware_lock, lock_flags); 279 acpi_os_release_lock(acpi_gbl_hardware_lock, lock_flags);
280 280
281 if (ACPI_FAILURE(status)) 281 if (ACPI_FAILURE(status)) {
282 goto exit; 282 goto exit;
283 }
283 284
284 /* Clear the GPE Bits in all GPE registers in all GPE blocks */ 285 /* Clear the GPE Bits in all GPE registers in all GPE blocks */
285 286
diff --git a/drivers/acpi/acpica/nsobject.c b/drivers/acpi/acpica/nsobject.c
index fe54a8c73b8c..a42ee9d6970d 100644
--- a/drivers/acpi/acpica/nsobject.c
+++ b/drivers/acpi/acpica/nsobject.c
@@ -237,6 +237,16 @@ void acpi_ns_detach_object(struct acpi_namespace_node *node)
237 (node->object->common.type != ACPI_TYPE_LOCAL_DATA)) { 237 (node->object->common.type != ACPI_TYPE_LOCAL_DATA)) {
238 node->object = node->object->common.next_object; 238 node->object = node->object->common.next_object;
239 } 239 }
240
241 /*
242 * Detach the object from any data objects (which are still held by
243 * the namespace node)
244 */
245 if (obj_desc->common.next_object &&
246 ((obj_desc->common.next_object)->common.type ==
247 ACPI_TYPE_LOCAL_DATA)) {
248 obj_desc->common.next_object = NULL;
249 }
240 } 250 }
241 251
242 /* Reset the node type to untyped */ 252 /* Reset the node type to untyped */
diff --git a/drivers/acpi/acpica/utbuffer.c b/drivers/acpi/acpica/utbuffer.c
index 3c1699740653..038ea887f562 100644
--- a/drivers/acpi/acpica/utbuffer.c
+++ b/drivers/acpi/acpica/utbuffer.c
@@ -199,3 +199,131 @@ acpi_ut_debug_dump_buffer(u8 *buffer, u32 count, u32 display, u32 component_id)
199 199
200 acpi_ut_dump_buffer(buffer, count, display, 0); 200 acpi_ut_dump_buffer(buffer, count, display, 0);
201} 201}
202
203#ifdef ACPI_APPLICATION
204/*******************************************************************************
205 *
206 * FUNCTION: acpi_ut_dump_buffer_to_file
207 *
208 * PARAMETERS: file - File descriptor
209 * buffer - Buffer to dump
210 * count - Amount to dump, in bytes
211 * display - BYTE, WORD, DWORD, or QWORD display:
212 * DB_BYTE_DISPLAY
213 * DB_WORD_DISPLAY
214 * DB_DWORD_DISPLAY
215 * DB_QWORD_DISPLAY
216 * base_offset - Beginning buffer offset (display only)
217 *
218 * RETURN: None
219 *
220 * DESCRIPTION: Generic dump buffer in both hex and ascii to a file.
221 *
222 ******************************************************************************/
223
224void
225acpi_ut_dump_buffer_to_file(ACPI_FILE file,
226 u8 *buffer, u32 count, u32 display, u32 base_offset)
227{
228 u32 i = 0;
229 u32 j;
230 u32 temp32;
231 u8 buf_char;
232
233 if (!buffer) {
234 acpi_ut_file_printf(file,
235 "Null Buffer Pointer in DumpBuffer!\n");
236 return;
237 }
238
239 if ((count < 4) || (count & 0x01)) {
240 display = DB_BYTE_DISPLAY;
241 }
242
243 /* Nasty little dump buffer routine! */
244
245 while (i < count) {
246
247 /* Print current offset */
248
249 acpi_ut_file_printf(file, "%6.4X: ", (base_offset + i));
250
251 /* Print 16 hex chars */
252
253 for (j = 0; j < 16;) {
254 if (i + j >= count) {
255
256 /* Dump fill spaces */
257
258 acpi_ut_file_printf(file, "%*s",
259 ((display * 2) + 1), " ");
260 j += display;
261 continue;
262 }
263
264 switch (display) {
265 case DB_BYTE_DISPLAY:
266 default: /* Default is BYTE display */
267
268 acpi_ut_file_printf(file, "%02X ",
269 buffer[(acpi_size) i + j]);
270 break;
271
272 case DB_WORD_DISPLAY:
273
274 ACPI_MOVE_16_TO_32(&temp32,
275 &buffer[(acpi_size) i + j]);
276 acpi_ut_file_printf(file, "%04X ", temp32);
277 break;
278
279 case DB_DWORD_DISPLAY:
280
281 ACPI_MOVE_32_TO_32(&temp32,
282 &buffer[(acpi_size) i + j]);
283 acpi_ut_file_printf(file, "%08X ", temp32);
284 break;
285
286 case DB_QWORD_DISPLAY:
287
288 ACPI_MOVE_32_TO_32(&temp32,
289 &buffer[(acpi_size) i + j]);
290 acpi_ut_file_printf(file, "%08X", temp32);
291
292 ACPI_MOVE_32_TO_32(&temp32,
293 &buffer[(acpi_size) i + j +
294 4]);
295 acpi_ut_file_printf(file, "%08X ", temp32);
296 break;
297 }
298
299 j += display;
300 }
301
302 /*
303 * Print the ASCII equivalent characters but watch out for the bad
304 * unprintable ones (printable chars are 0x20 through 0x7E)
305 */
306 acpi_ut_file_printf(file, " ");
307 for (j = 0; j < 16; j++) {
308 if (i + j >= count) {
309 acpi_ut_file_printf(file, "\n");
310 return;
311 }
312
313 buf_char = buffer[(acpi_size) i + j];
314 if (ACPI_IS_PRINT(buf_char)) {
315 acpi_ut_file_printf(file, "%c", buf_char);
316 } else {
317 acpi_ut_file_printf(file, ".");
318 }
319 }
320
321 /* Done with that line. */
322
323 acpi_ut_file_printf(file, "\n");
324 i += 16;
325 }
326
327 return;
328}
329#endif
diff --git a/drivers/acpi/acpica/utcopy.c b/drivers/acpi/acpica/utcopy.c
index 270c16464dd9..ff601c0f7c7a 100644
--- a/drivers/acpi/acpica/utcopy.c
+++ b/drivers/acpi/acpica/utcopy.c
@@ -1001,5 +1001,11 @@ acpi_ut_copy_iobject_to_iobject(union acpi_operand_object *source_desc,
1001 status = acpi_ut_copy_simple_object(source_desc, *dest_desc); 1001 status = acpi_ut_copy_simple_object(source_desc, *dest_desc);
1002 } 1002 }
1003 1003
1004 /* Delete the allocated object if copy failed */
1005
1006 if (ACPI_FAILURE(status)) {
1007 acpi_ut_remove_reference(*dest_desc);
1008 }
1009
1004 return_ACPI_STATUS(status); 1010 return_ACPI_STATUS(status);
1005} 1011}
diff --git a/drivers/acpi/acpica/utdebug.c b/drivers/acpi/acpica/utdebug.c
index 21a20ac5b1e1..e516254c63b2 100644
--- a/drivers/acpi/acpica/utdebug.c
+++ b/drivers/acpi/acpica/utdebug.c
@@ -561,3 +561,29 @@ acpi_ut_ptr_exit(u32 line_number,
561} 561}
562 562
563#endif 563#endif
564
565#ifdef ACPI_APPLICATION
566/*******************************************************************************
567 *
568 * FUNCTION: acpi_log_error
569 *
570 * PARAMETERS: format - Printf format field
571 * ... - Optional printf arguments
572 *
573 * RETURN: None
574 *
575 * DESCRIPTION: Print error message to the console, used by applications.
576 *
577 ******************************************************************************/
578
579void ACPI_INTERNAL_VAR_XFACE acpi_log_error(const char *format, ...)
580{
581 va_list args;
582
583 va_start(args, format);
584 (void)acpi_ut_file_vprintf(ACPI_FILE_ERR, format, args);
585 va_end(args);
586}
587
588ACPI_EXPORT_SYMBOL(acpi_log_error)
589#endif
diff --git a/drivers/acpi/acpica/utdecode.c b/drivers/acpi/acpica/utdecode.c
index 90ec37c473c6..40e923e675fc 100644
--- a/drivers/acpi/acpica/utdecode.c
+++ b/drivers/acpi/acpica/utdecode.c
@@ -88,33 +88,6 @@ const u8 acpi_gbl_ns_properties[ACPI_NUM_NS_TYPES] = {
88 88
89/******************************************************************************* 89/*******************************************************************************
90 * 90 *
91 * FUNCTION: acpi_ut_hex_to_ascii_char
92 *
93 * PARAMETERS: integer - Contains the hex digit
94 * position - bit position of the digit within the
95 * integer (multiple of 4)
96 *
97 * RETURN: The converted Ascii character
98 *
99 * DESCRIPTION: Convert a hex digit to an Ascii character
100 *
101 ******************************************************************************/
102
103/* Hex to ASCII conversion table */
104
105static const char acpi_gbl_hex_to_ascii[] = {
106 '0', '1', '2', '3', '4', '5', '6', '7',
107 '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
108};
109
110char acpi_ut_hex_to_ascii_char(u64 integer, u32 position)
111{
112
113 return (acpi_gbl_hex_to_ascii[(integer >> position) & 0xF]);
114}
115
116/*******************************************************************************
117 *
118 * FUNCTION: acpi_ut_get_region_name 91 * FUNCTION: acpi_ut_get_region_name
119 * 92 *
120 * PARAMETERS: Space ID - ID for the region 93 * PARAMETERS: Space ID - ID for the region
@@ -475,7 +448,8 @@ static const char *acpi_gbl_generic_notify[ACPI_NOTIFY_MAX + 1] = {
475 /* 09 */ "Device PLD Check", 448 /* 09 */ "Device PLD Check",
476 /* 0A */ "Reserved", 449 /* 0A */ "Reserved",
477 /* 0B */ "System Locality Update", 450 /* 0B */ "System Locality Update",
478 /* 0C */ "Shutdown Request" 451 /* 0C */ "Shutdown Request",
452 /* 0D */ "System Resource Affinity Update"
479}; 453};
480 454
481static const char *acpi_gbl_device_notify[4] = { 455static const char *acpi_gbl_device_notify[4] = {
@@ -502,7 +476,7 @@ static const char *acpi_gbl_thermal_notify[4] = {
502const char *acpi_ut_get_notify_name(u32 notify_value, acpi_object_type type) 476const char *acpi_ut_get_notify_name(u32 notify_value, acpi_object_type type)
503{ 477{
504 478
505 /* 00 - 0C are common to all object types */ 479 /* 00 - 0D are common to all object types */
506 480
507 if (notify_value <= ACPI_NOTIFY_MAX) { 481 if (notify_value <= ACPI_NOTIFY_MAX) {
508 return (acpi_gbl_generic_notify[notify_value]); 482 return (acpi_gbl_generic_notify[notify_value]);
diff --git a/drivers/acpi/acpica/utfileio.c b/drivers/acpi/acpica/utfileio.c
new file mode 100644
index 000000000000..4e263a8cc6f0
--- /dev/null
+++ b/drivers/acpi/acpica/utfileio.c
@@ -0,0 +1,331 @@
1/*******************************************************************************
2 *
3 * Module Name: utfileio - simple file I/O routines
4 *
5 ******************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2014, Intel Corp.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
44#include <acpi/acpi.h>
45#include "accommon.h"
46#include "actables.h"
47#include "acapps.h"
48
49#ifdef ACPI_ASL_COMPILER
50#include "aslcompiler.h"
51#endif
52
53#define _COMPONENT ACPI_CA_DEBUGGER
54ACPI_MODULE_NAME("utfileio")
55
56#ifdef ACPI_APPLICATION
57/* Local prototypes */
58static acpi_status
59acpi_ut_check_text_mode_corruption(u8 *table,
60 u32 table_length, u32 file_length);
61
62static acpi_status
63acpi_ut_read_table(FILE * fp,
64 struct acpi_table_header **table, u32 *table_length);
65
66/*******************************************************************************
67 *
68 * FUNCTION: acpi_ut_check_text_mode_corruption
69 *
70 * PARAMETERS: table - Table buffer
71 * table_length - Length of table from the table header
72 * file_length - Length of the file that contains the table
73 *
74 * RETURN: Status
75 *
76 * DESCRIPTION: Check table for text mode file corruption where all linefeed
77 * characters (LF) have been replaced by carriage return linefeed
78 * pairs (CR/LF).
79 *
80 ******************************************************************************/
81
82static acpi_status
83acpi_ut_check_text_mode_corruption(u8 *table, u32 table_length, u32 file_length)
84{
85 u32 i;
86 u32 pairs = 0;
87
88 if (table_length != file_length) {
89 ACPI_WARNING((AE_INFO,
90 "File length (0x%X) is not the same as the table length (0x%X)",
91 file_length, table_length));
92 }
93
94 /* Scan entire table to determine if each LF has been prefixed with a CR */
95
96 for (i = 1; i < file_length; i++) {
97 if (table[i] == 0x0A) {
98 if (table[i - 1] != 0x0D) {
99
100 /* The LF does not have a preceding CR, table not corrupted */
101
102 return (AE_OK);
103 } else {
104 /* Found a CR/LF pair */
105
106 pairs++;
107 }
108 i++;
109 }
110 }
111
112 if (!pairs) {
113 return (AE_OK);
114 }
115
116 /*
117 * Entire table scanned, each CR is part of a CR/LF pair --
118 * meaning that the table was treated as a text file somewhere.
119 *
120 * NOTE: We can't "fix" the table, because any existing CR/LF pairs in the
121 * original table are left untouched by the text conversion process --
122 * meaning that we cannot simply replace CR/LF pairs with LFs.
123 */
124 acpi_os_printf("Table has been corrupted by text mode conversion\n");
125 acpi_os_printf("All LFs (%u) were changed to CR/LF pairs\n", pairs);
126 acpi_os_printf("Table cannot be repaired!\n");
127 return (AE_BAD_VALUE);
128}
129
130/*******************************************************************************
131 *
132 * FUNCTION: acpi_ut_read_table
133 *
134 * PARAMETERS: fp - File that contains table
135 * table - Return value, buffer with table
136 * table_length - Return value, length of table
137 *
138 * RETURN: Status
139 *
140 * DESCRIPTION: Load the DSDT from the file pointer
141 *
142 ******************************************************************************/
143
144static acpi_status
145acpi_ut_read_table(FILE * fp,
146 struct acpi_table_header **table, u32 *table_length)
147{
148 struct acpi_table_header table_header;
149 u32 actual;
150 acpi_status status;
151 u32 file_size;
152 u8 standard_header = TRUE;
153 s32 count;
154
155 /* Get the file size */
156
157 file_size = cm_get_file_size(fp);
158 if (file_size == ACPI_UINT32_MAX) {
159 return (AE_ERROR);
160 }
161
162 if (file_size < 4) {
163 return (AE_BAD_HEADER);
164 }
165
166 /* Read the signature */
167
168 fseek(fp, 0, SEEK_SET);
169
170 count = fread(&table_header, 1, sizeof(struct acpi_table_header), fp);
171 if (count != sizeof(struct acpi_table_header)) {
172 acpi_os_printf("Could not read the table header\n");
173 return (AE_BAD_HEADER);
174 }
175
176 /* The RSDP table does not have standard ACPI header */
177
178 if (ACPI_VALIDATE_RSDP_SIG(table_header.signature)) {
179 *table_length = file_size;
180 standard_header = FALSE;
181 } else {
182
183#if 0
184 /* Validate the table header/length */
185
186 status = acpi_tb_validate_table_header(&table_header);
187 if (ACPI_FAILURE(status)) {
188 acpi_os_printf("Table header is invalid!\n");
189 return (status);
190 }
191#endif
192
193 /* File size must be at least as long as the Header-specified length */
194
195 if (table_header.length > file_size) {
196 acpi_os_printf
197 ("TableHeader length [0x%X] greater than the input file size [0x%X]\n",
198 table_header.length, file_size);
199
200#ifdef ACPI_ASL_COMPILER
201 status = fl_check_for_ascii(fp, NULL, FALSE);
202 if (ACPI_SUCCESS(status)) {
203 acpi_os_printf
204 ("File appears to be ASCII only, must be binary\n");
205 }
206#endif
207 return (AE_BAD_HEADER);
208 }
209#ifdef ACPI_OBSOLETE_CODE
210 /* We only support a limited number of table types */
211
212 if (!ACPI_COMPARE_NAME
213 ((char *)table_header.signature, ACPI_SIG_DSDT)
214 && !ACPI_COMPARE_NAME((char *)table_header.signature,
215 ACPI_SIG_PSDT)
216 && !ACPI_COMPARE_NAME((char *)table_header.signature,
217 ACPI_SIG_SSDT)) {
218 acpi_os_printf
219 ("Table signature [%4.4s] is invalid or not supported\n",
220 (char *)table_header.signature);
221 ACPI_DUMP_BUFFER(&table_header,
222 sizeof(struct acpi_table_header));
223 return (AE_ERROR);
224 }
225#endif
226
227 *table_length = table_header.length;
228 }
229
230 /* Allocate a buffer for the table */
231
232 *table = acpi_os_allocate((size_t) file_size);
233 if (!*table) {
234 acpi_os_printf
235 ("Could not allocate memory for ACPI table %4.4s (size=0x%X)\n",
236 table_header.signature, *table_length);
237 return (AE_NO_MEMORY);
238 }
239
240 /* Get the rest of the table */
241
242 fseek(fp, 0, SEEK_SET);
243 actual = fread(*table, 1, (size_t) file_size, fp);
244 if (actual == file_size) {
245 if (standard_header) {
246
247 /* Now validate the checksum */
248
249 status = acpi_tb_verify_checksum((void *)*table,
250 ACPI_CAST_PTR(struct
251 acpi_table_header,
252 *table)->
253 length);
254
255 if (status == AE_BAD_CHECKSUM) {
256 status =
257 acpi_ut_check_text_mode_corruption((u8 *)
258 *table,
259 file_size,
260 (*table)->
261 length);
262 return (status);
263 }
264 }
265 return (AE_OK);
266 }
267
268 if (actual > 0) {
269 acpi_os_printf("Warning - reading table, asked for %X got %X\n",
270 file_size, actual);
271 return (AE_OK);
272 }
273
274 acpi_os_printf("Error - could not read the table file\n");
275 acpi_os_free(*table);
276 *table = NULL;
277 *table_length = 0;
278 return (AE_ERROR);
279}
280
281/*******************************************************************************
282 *
283 * FUNCTION: acpi_ut_read_table_from_file
284 *
285 * PARAMETERS: filename - File where table is located
286 * table - Where a pointer to the table is returned
287 *
288 * RETURN: Status
289 *
290 * DESCRIPTION: Get an ACPI table from a file
291 *
292 ******************************************************************************/
293
294acpi_status
295acpi_ut_read_table_from_file(char *filename, struct acpi_table_header ** table)
296{
297 FILE *file;
298 u32 file_size;
299 u32 table_length;
300 acpi_status status = AE_ERROR;
301
302 /* Open the file, get current size */
303
304 file = fopen(filename, "rb");
305 if (!file) {
306 perror("Could not open input file");
307 return (status);
308 }
309
310 file_size = cm_get_file_size(file);
311 if (file_size == ACPI_UINT32_MAX) {
312 goto exit;
313 }
314
315 /* Get the entire file */
316
317 fprintf(stderr,
318 "Loading Acpi table from file %10s - Length %.8u (%06X)\n",
319 filename, file_size, file_size);
320
321 status = acpi_ut_read_table(file, table, &table_length);
322 if (ACPI_FAILURE(status)) {
323 acpi_os_printf("Could not get table from the file\n");
324 }
325
326exit:
327 fclose(file);
328 return (status);
329}
330
331#endif
diff --git a/drivers/acpi/acpica/utglobal.c b/drivers/acpi/acpica/utglobal.c
index d69be3cb3fae..77ceac715f28 100644
--- a/drivers/acpi/acpica/utglobal.c
+++ b/drivers/acpi/acpica/utglobal.c
@@ -214,152 +214,6 @@ struct acpi_fixed_event_info acpi_gbl_fixed_event_info[ACPI_NUM_FIXED_EVENTS] =
214}; 214};
215#endif /* !ACPI_REDUCED_HARDWARE */ 215#endif /* !ACPI_REDUCED_HARDWARE */
216 216
217/*******************************************************************************
218 *
219 * FUNCTION: acpi_ut_init_globals
220 *
221 * PARAMETERS: None
222 *
223 * RETURN: Status
224 *
225 * DESCRIPTION: Initialize ACPICA globals. All globals that require specific
226 * initialization should be initialized here. This allows for
227 * a warm restart.
228 *
229 ******************************************************************************/
230
231acpi_status acpi_ut_init_globals(void)
232{
233 acpi_status status;
234 u32 i;
235
236 ACPI_FUNCTION_TRACE(ut_init_globals);
237
238 /* Create all memory caches */
239
240 status = acpi_ut_create_caches();
241 if (ACPI_FAILURE(status)) {
242 return_ACPI_STATUS(status);
243 }
244
245 /* Address Range lists */
246
247 for (i = 0; i < ACPI_ADDRESS_RANGE_MAX; i++) {
248 acpi_gbl_address_range_list[i] = NULL;
249 }
250
251 /* Mutex locked flags */
252
253 for (i = 0; i < ACPI_NUM_MUTEX; i++) {
254 acpi_gbl_mutex_info[i].mutex = NULL;
255 acpi_gbl_mutex_info[i].thread_id = ACPI_MUTEX_NOT_ACQUIRED;
256 acpi_gbl_mutex_info[i].use_count = 0;
257 }
258
259 for (i = 0; i < ACPI_NUM_OWNERID_MASKS; i++) {
260 acpi_gbl_owner_id_mask[i] = 0;
261 }
262
263 /* Last owner_ID is never valid */
264
265 acpi_gbl_owner_id_mask[ACPI_NUM_OWNERID_MASKS - 1] = 0x80000000;
266
267 /* Event counters */
268
269 acpi_method_count = 0;
270 acpi_sci_count = 0;
271 acpi_gpe_count = 0;
272
273 for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++) {
274 acpi_fixed_event_count[i] = 0;
275 }
276
277#if (!ACPI_REDUCED_HARDWARE)
278
279 /* GPE/SCI support */
280
281 acpi_gbl_all_gpes_initialized = FALSE;
282 acpi_gbl_gpe_xrupt_list_head = NULL;
283 acpi_gbl_gpe_fadt_blocks[0] = NULL;
284 acpi_gbl_gpe_fadt_blocks[1] = NULL;
285 acpi_current_gpe_count = 0;
286
287 acpi_gbl_global_event_handler = NULL;
288 acpi_gbl_sci_handler_list = NULL;
289
290#endif /* !ACPI_REDUCED_HARDWARE */
291
292 /* Global handlers */
293
294 acpi_gbl_global_notify[0].handler = NULL;
295 acpi_gbl_global_notify[1].handler = NULL;
296 acpi_gbl_exception_handler = NULL;
297 acpi_gbl_init_handler = NULL;
298 acpi_gbl_table_handler = NULL;
299 acpi_gbl_interface_handler = NULL;
300
301 /* Global Lock support */
302
303 acpi_gbl_global_lock_semaphore = NULL;
304 acpi_gbl_global_lock_mutex = NULL;
305 acpi_gbl_global_lock_acquired = FALSE;
306 acpi_gbl_global_lock_handle = 0;
307 acpi_gbl_global_lock_present = FALSE;
308
309 /* Miscellaneous variables */
310
311 acpi_gbl_DSDT = NULL;
312 acpi_gbl_cm_single_step = FALSE;
313 acpi_gbl_shutdown = FALSE;
314 acpi_gbl_ns_lookup_count = 0;
315 acpi_gbl_ps_find_count = 0;
316 acpi_gbl_acpi_hardware_present = TRUE;
317 acpi_gbl_last_owner_id_index = 0;
318 acpi_gbl_next_owner_id_offset = 0;
319 acpi_gbl_trace_dbg_level = 0;
320 acpi_gbl_trace_dbg_layer = 0;
321 acpi_gbl_debugger_configuration = DEBUGGER_THREADING;
322 acpi_gbl_db_output_flags = ACPI_DB_CONSOLE_OUTPUT;
323 acpi_gbl_osi_mutex = NULL;
324 acpi_gbl_reg_methods_executed = FALSE;
325
326 /* Hardware oriented */
327
328 acpi_gbl_events_initialized = FALSE;
329 acpi_gbl_system_awake_and_running = TRUE;
330
331 /* Namespace */
332
333 acpi_gbl_module_code_list = NULL;
334 acpi_gbl_root_node = NULL;
335 acpi_gbl_root_node_struct.name.integer = ACPI_ROOT_NAME;
336 acpi_gbl_root_node_struct.descriptor_type = ACPI_DESC_TYPE_NAMED;
337 acpi_gbl_root_node_struct.type = ACPI_TYPE_DEVICE;
338 acpi_gbl_root_node_struct.parent = NULL;
339 acpi_gbl_root_node_struct.child = NULL;
340 acpi_gbl_root_node_struct.peer = NULL;
341 acpi_gbl_root_node_struct.object = NULL;
342
343#ifdef ACPI_DISASSEMBLER
344 acpi_gbl_external_list = NULL;
345 acpi_gbl_num_external_methods = 0;
346 acpi_gbl_resolved_external_methods = 0;
347#endif
348
349#ifdef ACPI_DEBUG_OUTPUT
350 acpi_gbl_lowest_stack_pointer = ACPI_CAST_PTR(acpi_size, ACPI_SIZE_MAX);
351#endif
352
353#ifdef ACPI_DBG_TRACK_ALLOCATIONS
354 acpi_gbl_display_final_mem_stats = FALSE;
355 acpi_gbl_disable_mem_tracking = FALSE;
356#endif
357
358 ACPI_DEBUGGER_EXEC(acpi_gbl_db_terminate_threads = FALSE);
359
360 return_ACPI_STATUS(AE_OK);
361}
362
363/* Public globals */ 217/* Public globals */
364 218
365ACPI_EXPORT_SYMBOL(acpi_gbl_FADT) 219ACPI_EXPORT_SYMBOL(acpi_gbl_FADT)
diff --git a/drivers/acpi/acpica/uthex.c b/drivers/acpi/acpica/uthex.c
new file mode 100644
index 000000000000..9afa9441b183
--- /dev/null
+++ b/drivers/acpi/acpica/uthex.c
@@ -0,0 +1,100 @@
1/******************************************************************************
2 *
3 * Module Name: uthex -- Hex/ASCII support functions
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2014, Intel Corp.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
44#include <acpi/acpi.h>
45#include "accommon.h"
46
47#define _COMPONENT ACPI_COMPILER
48ACPI_MODULE_NAME("uthex")
49
50/* Hex to ASCII conversion table */
51static char acpi_gbl_hex_to_ascii[] = {
52 '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D',
53 'E', 'F'
54};
55
56/*******************************************************************************
57 *
58 * FUNCTION: acpi_ut_hex_to_ascii_char
59 *
60 * PARAMETERS: integer - Contains the hex digit
61 * position - bit position of the digit within the
62 * integer (multiple of 4)
63 *
64 * RETURN: The converted Ascii character
65 *
66 * DESCRIPTION: Convert a hex digit to an Ascii character
67 *
68 ******************************************************************************/
69
70char acpi_ut_hex_to_ascii_char(u64 integer, u32 position)
71{
72
73 return (acpi_gbl_hex_to_ascii[(integer >> position) & 0xF]);
74}
75
76/*******************************************************************************
77 *
78 * FUNCTION: acpi_ut_hex_char_to_value
79 *
80 * PARAMETERS: ascii_char - Hex character in Ascii
81 *
82 * RETURN: The binary value of the ascii/hex character
83 *
84 * DESCRIPTION: Perform ascii-to-hex translation
85 *
86 ******************************************************************************/
87
88u8 acpi_ut_ascii_char_to_hex(int hex_char)
89{
90
91 if (hex_char <= 0x39) {
92 return ((u8)(hex_char - 0x30));
93 }
94
95 if (hex_char <= 0x46) {
96 return ((u8)(hex_char - 0x37));
97 }
98
99 return ((u8)(hex_char - 0x57));
100}
diff --git a/drivers/acpi/acpica/utinit.c b/drivers/acpi/acpica/utinit.c
index 5f56fc49021e..77120ec9ea86 100644
--- a/drivers/acpi/acpica/utinit.c
+++ b/drivers/acpi/acpica/utinit.c
@@ -102,6 +102,151 @@ static void acpi_ut_free_gpe_lists(void)
102} 102}
103#endif /* !ACPI_REDUCED_HARDWARE */ 103#endif /* !ACPI_REDUCED_HARDWARE */
104 104
105/*******************************************************************************
106 *
107 * FUNCTION: acpi_ut_init_globals
108 *
109 * PARAMETERS: None
110 *
111 * RETURN: Status
112 *
113 * DESCRIPTION: Initialize ACPICA globals. All globals that require specific
114 * initialization should be initialized here. This allows for
115 * a warm restart.
116 *
117 ******************************************************************************/
118
119acpi_status acpi_ut_init_globals(void)
120{
121 acpi_status status;
122 u32 i;
123
124 ACPI_FUNCTION_TRACE(ut_init_globals);
125
126 /* Create all memory caches */
127
128 status = acpi_ut_create_caches();
129 if (ACPI_FAILURE(status)) {
130 return_ACPI_STATUS(status);
131 }
132
133 /* Address Range lists */
134
135 for (i = 0; i < ACPI_ADDRESS_RANGE_MAX; i++) {
136 acpi_gbl_address_range_list[i] = NULL;
137 }
138
139 /* Mutex locked flags */
140
141 for (i = 0; i < ACPI_NUM_MUTEX; i++) {
142 acpi_gbl_mutex_info[i].mutex = NULL;
143 acpi_gbl_mutex_info[i].thread_id = ACPI_MUTEX_NOT_ACQUIRED;
144 acpi_gbl_mutex_info[i].use_count = 0;
145 }
146
147 for (i = 0; i < ACPI_NUM_OWNERID_MASKS; i++) {
148 acpi_gbl_owner_id_mask[i] = 0;
149 }
150
151 /* Last owner_ID is never valid */
152
153 acpi_gbl_owner_id_mask[ACPI_NUM_OWNERID_MASKS - 1] = 0x80000000;
154
155 /* Event counters */
156
157 acpi_method_count = 0;
158 acpi_sci_count = 0;
159 acpi_gpe_count = 0;
160
161 for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++) {
162 acpi_fixed_event_count[i] = 0;
163 }
164
165#if (!ACPI_REDUCED_HARDWARE)
166
167 /* GPE/SCI support */
168
169 acpi_gbl_all_gpes_initialized = FALSE;
170 acpi_gbl_gpe_xrupt_list_head = NULL;
171 acpi_gbl_gpe_fadt_blocks[0] = NULL;
172 acpi_gbl_gpe_fadt_blocks[1] = NULL;
173 acpi_current_gpe_count = 0;
174
175 acpi_gbl_global_event_handler = NULL;
176 acpi_gbl_sci_handler_list = NULL;
177
178#endif /* !ACPI_REDUCED_HARDWARE */
179
180 /* Global handlers */
181
182 acpi_gbl_global_notify[0].handler = NULL;
183 acpi_gbl_global_notify[1].handler = NULL;
184 acpi_gbl_exception_handler = NULL;
185 acpi_gbl_init_handler = NULL;
186 acpi_gbl_table_handler = NULL;
187 acpi_gbl_interface_handler = NULL;
188
189 /* Global Lock support */
190
191 acpi_gbl_global_lock_semaphore = NULL;
192 acpi_gbl_global_lock_mutex = NULL;
193 acpi_gbl_global_lock_acquired = FALSE;
194 acpi_gbl_global_lock_handle = 0;
195 acpi_gbl_global_lock_present = FALSE;
196
197 /* Miscellaneous variables */
198
199 acpi_gbl_DSDT = NULL;
200 acpi_gbl_cm_single_step = FALSE;
201 acpi_gbl_shutdown = FALSE;
202 acpi_gbl_ns_lookup_count = 0;
203 acpi_gbl_ps_find_count = 0;
204 acpi_gbl_acpi_hardware_present = TRUE;
205 acpi_gbl_last_owner_id_index = 0;
206 acpi_gbl_next_owner_id_offset = 0;
207 acpi_gbl_trace_dbg_level = 0;
208 acpi_gbl_trace_dbg_layer = 0;
209 acpi_gbl_debugger_configuration = DEBUGGER_THREADING;
210 acpi_gbl_osi_mutex = NULL;
211 acpi_gbl_reg_methods_executed = FALSE;
212
213 /* Hardware oriented */
214
215 acpi_gbl_events_initialized = FALSE;
216 acpi_gbl_system_awake_and_running = TRUE;
217
218 /* Namespace */
219
220 acpi_gbl_module_code_list = NULL;
221 acpi_gbl_root_node = NULL;
222 acpi_gbl_root_node_struct.name.integer = ACPI_ROOT_NAME;
223 acpi_gbl_root_node_struct.descriptor_type = ACPI_DESC_TYPE_NAMED;
224 acpi_gbl_root_node_struct.type = ACPI_TYPE_DEVICE;
225 acpi_gbl_root_node_struct.parent = NULL;
226 acpi_gbl_root_node_struct.child = NULL;
227 acpi_gbl_root_node_struct.peer = NULL;
228 acpi_gbl_root_node_struct.object = NULL;
229
230#ifdef ACPI_DISASSEMBLER
231 acpi_gbl_external_list = NULL;
232 acpi_gbl_num_external_methods = 0;
233 acpi_gbl_resolved_external_methods = 0;
234#endif
235
236#ifdef ACPI_DEBUG_OUTPUT
237 acpi_gbl_lowest_stack_pointer = ACPI_CAST_PTR(acpi_size, ACPI_SIZE_MAX);
238#endif
239
240#ifdef ACPI_DBG_TRACK_ALLOCATIONS
241 acpi_gbl_display_final_mem_stats = FALSE;
242 acpi_gbl_disable_mem_tracking = FALSE;
243#endif
244
245 ACPI_DEBUGGER_EXEC(acpi_gbl_db_terminate_threads = FALSE);
246
247 return_ACPI_STATUS(AE_OK);
248}
249
105/****************************************************************************** 250/******************************************************************************
106 * 251 *
107 * FUNCTION: acpi_ut_terminate 252 * FUNCTION: acpi_ut_terminate
diff --git a/drivers/acpi/acpica/utprint.c b/drivers/acpi/acpica/utprint.c
new file mode 100644
index 000000000000..0ce3f5a0dd67
--- /dev/null
+++ b/drivers/acpi/acpica/utprint.c
@@ -0,0 +1,664 @@
1/******************************************************************************
2 *
3 * Module Name: utprint - Formatted printing routines
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2014, Intel Corp.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
44#include <acpi/acpi.h>
45#include "accommon.h"
46
47#define _COMPONENT ACPI_UTILITIES
48ACPI_MODULE_NAME("utprint")
49
50#define ACPI_FORMAT_SIGN 0x01
51#define ACPI_FORMAT_SIGN_PLUS 0x02
52#define ACPI_FORMAT_SIGN_PLUS_SPACE 0x04
53#define ACPI_FORMAT_ZERO 0x08
54#define ACPI_FORMAT_LEFT 0x10
55#define ACPI_FORMAT_UPPER 0x20
56#define ACPI_FORMAT_PREFIX 0x40
57/* Local prototypes */
58static acpi_size
59acpi_ut_bound_string_length(const char *string, acpi_size count);
60
61static char *acpi_ut_bound_string_output(char *string, const char *end, char c);
62
63static char *acpi_ut_format_number(char *string,
64 char *end,
65 u64 number,
66 u8 base, s32 width, s32 precision, u8 type);
67
68static char *acpi_ut_put_number(char *string, u64 number, u8 base, u8 upper);
69
70/* Module globals */
71
72static const char acpi_gbl_lower_hex_digits[] = "0123456789abcdef";
73static const char acpi_gbl_upper_hex_digits[] = "0123456789ABCDEF";
74
75/*******************************************************************************
76 *
77 * FUNCTION: acpi_ut_bound_string_length
78 *
79 * PARAMETERS: string - String with boundary
80 * count - Boundary of the string
81 *
82 * RETURN: Length of the string. Less than or equal to Count.
83 *
84 * DESCRIPTION: Calculate the length of a string with boundary.
85 *
86 ******************************************************************************/
87
88static acpi_size
89acpi_ut_bound_string_length(const char *string, acpi_size count)
90{
91 u32 length = 0;
92
93 while (*string && count) {
94 length++;
95 string++;
96 count--;
97 }
98
99 return (length);
100}
101
102/*******************************************************************************
103 *
104 * FUNCTION: acpi_ut_bound_string_output
105 *
106 * PARAMETERS: string - String with boundary
107 * end - Boundary of the string
108 * c - Character to be output to the string
109 *
110 * RETURN: Updated position for next valid character
111 *
112 * DESCRIPTION: Output a character into a string with boundary check.
113 *
114 ******************************************************************************/
115
116static char *acpi_ut_bound_string_output(char *string, const char *end, char c)
117{
118
119 if (string < end) {
120 *string = c;
121 }
122
123 ++string;
124 return (string);
125}
126
127/*******************************************************************************
128 *
129 * FUNCTION: acpi_ut_put_number
130 *
131 * PARAMETERS: string - Buffer to hold reverse-ordered string
132 * number - Integer to be converted
133 * base - Base of the integer
134 * upper - Whether or not using upper cased digits
135 *
136 * RETURN: Updated position for next valid character
137 *
138 * DESCRIPTION: Convert an integer into a string, note that, the string holds a
139 * reversed ordered number without the trailing zero.
140 *
141 ******************************************************************************/
142
143static char *acpi_ut_put_number(char *string, u64 number, u8 base, u8 upper)
144{
145 const char *digits;
146 u64 digit_index;
147 char *pos;
148
149 pos = string;
150 digits = upper ? acpi_gbl_upper_hex_digits : acpi_gbl_lower_hex_digits;
151
152 if (number == 0) {
153 *(pos++) = '0';
154 } else {
155 while (number) {
156 (void)acpi_ut_divide(number, base, &number,
157 &digit_index);
158 *(pos++) = digits[digit_index];
159 }
160 }
161
162 /* *(Pos++) = '0'; */
163 return (pos);
164}
165
166/*******************************************************************************
167 *
168 * FUNCTION: acpi_ut_scan_number
169 *
170 * PARAMETERS: string - String buffer
171 * number_ptr - Where the number is returned
172 *
173 * RETURN: Updated position for next valid character
174 *
175 * DESCRIPTION: Scan a string for a decimal integer.
176 *
177 ******************************************************************************/
178
179const char *acpi_ut_scan_number(const char *string, u64 *number_ptr)
180{
181 u64 number = 0;
182
183 while (ACPI_IS_DIGIT(*string)) {
184 number *= 10;
185 number += *(string++) - '0';
186 }
187
188 *number_ptr = number;
189 return (string);
190}
191
192/*******************************************************************************
193 *
194 * FUNCTION: acpi_ut_print_number
195 *
196 * PARAMETERS: string - String buffer
197 * number - The number to be converted
198 *
199 * RETURN: Updated position for next valid character
200 *
201 * DESCRIPTION: Print a decimal integer into a string.
202 *
203 ******************************************************************************/
204
205const char *acpi_ut_print_number(char *string, u64 number)
206{
207 char ascii_string[20];
208 const char *pos1;
209 char *pos2;
210
211 pos1 = acpi_ut_put_number(ascii_string, number, 10, FALSE);
212 pos2 = string;
213
214 while (pos1 != ascii_string) {
215 *(pos2++) = *(--pos1);
216 }
217
218 *pos2 = 0;
219 return (string);
220}
221
222/*******************************************************************************
223 *
224 * FUNCTION: acpi_ut_format_number
225 *
226 * PARAMETERS: string - String buffer with boundary
227 * end - Boundary of the string
228 * number - The number to be converted
229 * base - Base of the integer
230 * width - Field width
231 * precision - Precision of the integer
232 * type - Special printing flags
233 *
234 * RETURN: Updated position for next valid character
235 *
236 * DESCRIPTION: Print an integer into a string with any base and any precision.
237 *
238 ******************************************************************************/
239
240static char *acpi_ut_format_number(char *string,
241 char *end,
242 u64 number,
243 u8 base, s32 width, s32 precision, u8 type)
244{
245 char *pos;
246 char sign;
247 char zero;
248 u8 need_prefix;
249 u8 upper;
250 s32 i;
251 char reversed_string[66];
252
253 /* Parameter validation */
254
255 if (base < 2 || base > 16) {
256 return (NULL);
257 }
258
259 if (type & ACPI_FORMAT_LEFT) {
260 type &= ~ACPI_FORMAT_ZERO;
261 }
262
263 need_prefix = ((type & ACPI_FORMAT_PREFIX)
264 && base != 10) ? TRUE : FALSE;
265 upper = (type & ACPI_FORMAT_UPPER) ? TRUE : FALSE;
266 zero = (type & ACPI_FORMAT_ZERO) ? '0' : ' ';
267
268 /* Calculate size according to sign and prefix */
269
270 sign = '\0';
271 if (type & ACPI_FORMAT_SIGN) {
272 if ((s64) number < 0) {
273 sign = '-';
274 number = -(s64) number;
275 width--;
276 } else if (type & ACPI_FORMAT_SIGN_PLUS) {
277 sign = '+';
278 width--;
279 } else if (type & ACPI_FORMAT_SIGN_PLUS_SPACE) {
280 sign = ' ';
281 width--;
282 }
283 }
284 if (need_prefix) {
285 width--;
286 if (base == 16) {
287 width--;
288 }
289 }
290
291 /* Generate full string in reverse order */
292
293 pos = acpi_ut_put_number(reversed_string, number, base, upper);
294 i = ACPI_PTR_DIFF(pos, reversed_string);
295
296 /* Printing 100 using %2d gives "100", not "00" */
297
298 if (i > precision) {
299 precision = i;
300 }
301
302 width -= precision;
303
304 /* Output the string */
305
306 if (!(type & (ACPI_FORMAT_ZERO | ACPI_FORMAT_LEFT))) {
307 while (--width >= 0) {
308 string = acpi_ut_bound_string_output(string, end, ' ');
309 }
310 }
311 if (sign) {
312 string = acpi_ut_bound_string_output(string, end, sign);
313 }
314 if (need_prefix) {
315 string = acpi_ut_bound_string_output(string, end, '0');
316 if (base == 16) {
317 string = acpi_ut_bound_string_output(string, end,
318 upper ? 'X' : 'x');
319 }
320 }
321 if (!(type & ACPI_FORMAT_LEFT)) {
322 while (--width >= 0) {
323 string = acpi_ut_bound_string_output(string, end, zero);
324 }
325 }
326
327 while (i <= --precision) {
328 string = acpi_ut_bound_string_output(string, end, '0');
329 }
330 while (--i >= 0) {
331 string = acpi_ut_bound_string_output(string, end,
332 reversed_string[i]);
333 }
334 while (--width >= 0) {
335 string = acpi_ut_bound_string_output(string, end, ' ');
336 }
337
338 return (string);
339}
340
341/*******************************************************************************
342 *
343 * FUNCTION: acpi_ut_vsnprintf
344 *
345 * PARAMETERS: string - String with boundary
346 * size - Boundary of the string
347 * format - Standard printf format
348 * args - Argument list
349 *
350 * RETURN: Number of bytes actually written.
351 *
352 * DESCRIPTION: Formatted output to a string using argument list pointer.
353 *
354 ******************************************************************************/
355
356int
357acpi_ut_vsnprintf(char *string,
358 acpi_size size, const char *format, va_list args)
359{
360 u8 base = 10;
361 u8 type = 0;
362 s32 width = -1;
363 s32 precision = -1;
364 char qualifier = 0;
365 u64 number;
366 char *pos;
367 char *end;
368 char c;
369 const char *s;
370 const void *p;
371 s32 length;
372 int i;
373
374 pos = string;
375 end = string + size;
376
377 for (; *format; ++format) {
378 if (*format != '%') {
379 pos = acpi_ut_bound_string_output(pos, end, *format);
380 continue;
381 }
382
383 /* Process sign */
384
385 do {
386 ++format;
387 if (*format == '#') {
388 type |= ACPI_FORMAT_PREFIX;
389 } else if (*format == '0') {
390 type |= ACPI_FORMAT_ZERO;
391 } else if (*format == '+') {
392 type |= ACPI_FORMAT_SIGN_PLUS;
393 } else if (*format == ' ') {
394 type |= ACPI_FORMAT_SIGN_PLUS_SPACE;
395 } else if (*format == '-') {
396 type |= ACPI_FORMAT_LEFT;
397 } else {
398 break;
399 }
400 } while (1);
401
402 /* Process width */
403
404 width = -1;
405 if (ACPI_IS_DIGIT(*format)) {
406 format = acpi_ut_scan_number(format, &number);
407 width = (s32) number;
408 } else if (*format == '*') {
409 ++format;
410 width = va_arg(args, int);
411 if (width < 0) {
412 width = -width;
413 type |= ACPI_FORMAT_LEFT;
414 }
415 }
416
417 /* Process precision */
418
419 precision = -1;
420 if (*format == '.') {
421 ++format;
422 if (ACPI_IS_DIGIT(*format)) {
423 format = acpi_ut_scan_number(format, &number);
424 precision = (s32) number;
425 } else if (*format == '*') {
426 ++format;
427 precision = va_arg(args, int);
428 }
429 if (precision < 0) {
430 precision = 0;
431 }
432 }
433
434 /* Process qualifier */
435
436 qualifier = -1;
437 if (*format == 'h' || *format == 'l' || *format == 'L') {
438 qualifier = *format;
439 ++format;
440
441 if (qualifier == 'l' && *format == 'l') {
442 qualifier = 'L';
443 ++format;
444 }
445 }
446
447 switch (*format) {
448 case '%':
449
450 pos = acpi_ut_bound_string_output(pos, end, '%');
451 continue;
452
453 case 'c':
454
455 if (!(type & ACPI_FORMAT_LEFT)) {
456 while (--width > 0) {
457 pos =
458 acpi_ut_bound_string_output(pos,
459 end,
460 ' ');
461 }
462 }
463
464 c = (char)va_arg(args, int);
465 pos = acpi_ut_bound_string_output(pos, end, c);
466
467 while (--width > 0) {
468 pos =
469 acpi_ut_bound_string_output(pos, end, ' ');
470 }
471 continue;
472
473 case 's':
474
475 s = va_arg(args, char *);
476 if (!s) {
477 s = "<NULL>";
478 }
479 length = acpi_ut_bound_string_length(s, precision);
480 if (!(type & ACPI_FORMAT_LEFT)) {
481 while (length < width--) {
482 pos =
483 acpi_ut_bound_string_output(pos,
484 end,
485 ' ');
486 }
487 }
488 for (i = 0; i < length; ++i) {
489 pos = acpi_ut_bound_string_output(pos, end, *s);
490 ++s;
491 }
492 while (length < width--) {
493 pos =
494 acpi_ut_bound_string_output(pos, end, ' ');
495 }
496 continue;
497
498 case 'o':
499
500 base = 8;
501 break;
502
503 case 'X':
504
505 type |= ACPI_FORMAT_UPPER;
506
507 case 'x':
508
509 base = 16;
510 break;
511
512 case 'd':
513 case 'i':
514
515 type |= ACPI_FORMAT_SIGN;
516
517 case 'u':
518
519 break;
520
521 case 'p':
522
523 if (width == -1) {
524 width = 2 * sizeof(void *);
525 type |= ACPI_FORMAT_ZERO;
526 }
527
528 p = va_arg(args, void *);
529 pos = acpi_ut_format_number(pos, end,
530 ACPI_TO_INTEGER(p), 16,
531 width, precision, type);
532 continue;
533
534 default:
535
536 pos = acpi_ut_bound_string_output(pos, end, '%');
537 if (*format) {
538 pos =
539 acpi_ut_bound_string_output(pos, end,
540 *format);
541 } else {
542 --format;
543 }
544 continue;
545 }
546
547 if (qualifier == 'L') {
548 number = va_arg(args, u64);
549 if (type & ACPI_FORMAT_SIGN) {
550 number = (s64) number;
551 }
552 } else if (qualifier == 'l') {
553 number = va_arg(args, unsigned long);
554 if (type & ACPI_FORMAT_SIGN) {
555 number = (s32) number;
556 }
557 } else if (qualifier == 'h') {
558 number = (u16)va_arg(args, int);
559 if (type & ACPI_FORMAT_SIGN) {
560 number = (s16) number;
561 }
562 } else {
563 number = va_arg(args, unsigned int);
564 if (type & ACPI_FORMAT_SIGN) {
565 number = (signed int)number;
566 }
567 }
568
569 pos = acpi_ut_format_number(pos, end, number, base,
570 width, precision, type);
571 }
572
573 if (size > 0) {
574 if (pos < end) {
575 *pos = '\0';
576 } else {
577 end[-1] = '\0';
578 }
579 }
580
581 return (ACPI_PTR_DIFF(pos, string));
582}
583
584/*******************************************************************************
585 *
586 * FUNCTION: acpi_ut_snprintf
587 *
588 * PARAMETERS: string - String with boundary
589 * size - Boundary of the string
590 * Format, ... - Standard printf format
591 *
592 * RETURN: Number of bytes actually written.
593 *
594 * DESCRIPTION: Formatted output to a string.
595 *
596 ******************************************************************************/
597
598int acpi_ut_snprintf(char *string, acpi_size size, const char *format, ...)
599{
600 va_list args;
601 int length;
602
603 va_start(args, format);
604 length = acpi_ut_vsnprintf(string, size, format, args);
605 va_end(args);
606
607 return (length);
608}
609
610#ifdef ACPI_APPLICATION
611/*******************************************************************************
612 *
613 * FUNCTION: acpi_ut_file_vprintf
614 *
615 * PARAMETERS: file - File descriptor
616 * format - Standard printf format
617 * args - Argument list
618 *
619 * RETURN: Number of bytes actually written.
620 *
621 * DESCRIPTION: Formatted output to a file using argument list pointer.
622 *
623 ******************************************************************************/
624
625int acpi_ut_file_vprintf(ACPI_FILE file, const char *format, va_list args)
626{
627 acpi_cpu_flags flags;
628 int length;
629
630 flags = acpi_os_acquire_lock(acpi_gbl_print_lock);
631 length = acpi_ut_vsnprintf(acpi_gbl_print_buffer,
632 sizeof(acpi_gbl_print_buffer), format, args);
633
634 (void)acpi_os_write_file(file, acpi_gbl_print_buffer, length, 1);
635 acpi_os_release_lock(acpi_gbl_print_lock, flags);
636
637 return (length);
638}
639
640/*******************************************************************************
641 *
642 * FUNCTION: acpi_ut_file_printf
643 *
644 * PARAMETERS: file - File descriptor
645 * Format, ... - Standard printf format
646 *
647 * RETURN: Number of bytes actually written.
648 *
649 * DESCRIPTION: Formatted output to a file.
650 *
651 ******************************************************************************/
652
653int acpi_ut_file_printf(ACPI_FILE file, const char *format, ...)
654{
655 va_list args;
656 int length;
657
658 va_start(args, format);
659 length = acpi_ut_file_vprintf(file, format, args);
660 va_end(args);
661
662 return (length);
663}
664#endif
diff --git a/drivers/acpi/acpica/utuuid.c b/drivers/acpi/acpica/utuuid.c
new file mode 100644
index 000000000000..4dc33130f134
--- /dev/null
+++ b/drivers/acpi/acpica/utuuid.c
@@ -0,0 +1,96 @@
1/******************************************************************************
2 *
3 * Module Name: utuuid -- UUID support functions
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2014, Intel Corp.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
44#include <acpi/acpi.h>
45#include "accommon.h"
46
47#define _COMPONENT ACPI_COMPILER
48ACPI_MODULE_NAME("utuuid")
49
50/*
51 * UUID support functions.
52 *
53 * This table is used to convert an input UUID ascii string to a 16 byte
54 * buffer and the reverse. The table maps a UUID buffer index 0-15 to
55 * the index within the 36-byte UUID string where the associated 2-byte
56 * hex value can be found.
57 *
58 * 36-byte UUID strings are of the form:
59 * aabbccdd-eeff-gghh-iijj-kkllmmnnoopp
60 * Where aa-pp are one byte hex numbers, made up of two hex digits
61 *
62 * Note: This table is basically the inverse of the string-to-offset table
63 * found in the ACPI spec in the description of the to_UUID macro.
64 */
65const u8 acpi_gbl_map_to_uuid_offset[UUID_BUFFER_LENGTH] = {
66 6, 4, 2, 0, 11, 9, 16, 14, 19, 21, 24, 26, 28, 30, 32, 34
67};
68
69/*******************************************************************************
70 *
71 * FUNCTION: acpi_ut_convert_string_to_uuid
72 *
73 * PARAMETERS: in_string - 36-byte formatted UUID string
74 * uuid_buffer - Where the 16-byte UUID buffer is returned
75 *
76 * RETURN: None. Output data is returned in the uuid_buffer
77 *
78 * DESCRIPTION: Convert a 36-byte formatted UUID string to 16-byte UUID buffer
79 *
80 ******************************************************************************/
81
82void acpi_ut_convert_string_to_uuid(char *in_string, u8 *uuid_buffer)
83{
84 u32 i;
85
86 for (i = 0; i < UUID_BUFFER_LENGTH; i++) {
87 uuid_buffer[i] =
88 (acpi_ut_ascii_char_to_hex
89 (in_string[acpi_gbl_map_to_uuid_offset[i]]) << 4);
90
91 uuid_buffer[i] |=
92 acpi_ut_ascii_char_to_hex(in_string
93 [acpi_gbl_map_to_uuid_offset[i] +
94 1]);
95 }
96}
diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
index e5bcd919d4e6..16129c78b489 100644
--- a/drivers/acpi/apei/apei-internal.h
+++ b/drivers/acpi/apei/apei-internal.h
@@ -121,11 +121,11 @@ struct dentry;
121struct dentry *apei_get_debugfs_dir(void); 121struct dentry *apei_get_debugfs_dir(void);
122 122
123#define apei_estatus_for_each_section(estatus, section) \ 123#define apei_estatus_for_each_section(estatus, section) \
124 for (section = (struct acpi_generic_data *)(estatus + 1); \ 124 for (section = (struct acpi_hest_generic_data *)(estatus + 1); \
125 (void *)section - (void *)estatus < estatus->data_length; \ 125 (void *)section - (void *)estatus < estatus->data_length; \
126 section = (void *)(section+1) + section->error_data_length) 126 section = (void *)(section+1) + section->error_data_length)
127 127
128static inline u32 cper_estatus_len(struct acpi_generic_status *estatus) 128static inline u32 cper_estatus_len(struct acpi_hest_generic_status *estatus)
129{ 129{
130 if (estatus->raw_data_length) 130 if (estatus->raw_data_length)
131 return estatus->raw_data_offset + \ 131 return estatus->raw_data_offset + \
@@ -135,9 +135,9 @@ static inline u32 cper_estatus_len(struct acpi_generic_status *estatus)
135} 135}
136 136
137void cper_estatus_print(const char *pfx, 137void cper_estatus_print(const char *pfx,
138 const struct acpi_generic_status *estatus); 138 const struct acpi_hest_generic_status *estatus);
139int cper_estatus_check_header(const struct acpi_generic_status *estatus); 139int cper_estatus_check_header(const struct acpi_hest_generic_status *estatus);
140int cper_estatus_check(const struct acpi_generic_status *estatus); 140int cper_estatus_check(const struct acpi_hest_generic_status *estatus);
141 141
142int apei_osc_setup(void); 142int apei_osc_setup(void);
143#endif 143#endif
diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
index e05d84e7b06d..fc5f780bb61d 100644
--- a/drivers/acpi/apei/ghes.c
+++ b/drivers/acpi/apei/ghes.c
@@ -74,13 +74,13 @@
74#define GHES_ESTATUS_CACHE_LEN(estatus_len) \ 74#define GHES_ESTATUS_CACHE_LEN(estatus_len) \
75 (sizeof(struct ghes_estatus_cache) + (estatus_len)) 75 (sizeof(struct ghes_estatus_cache) + (estatus_len))
76#define GHES_ESTATUS_FROM_CACHE(estatus_cache) \ 76#define GHES_ESTATUS_FROM_CACHE(estatus_cache) \
77 ((struct acpi_generic_status *) \ 77 ((struct acpi_hest_generic_status *) \
78 ((struct ghes_estatus_cache *)(estatus_cache) + 1)) 78 ((struct ghes_estatus_cache *)(estatus_cache) + 1))
79 79
80#define GHES_ESTATUS_NODE_LEN(estatus_len) \ 80#define GHES_ESTATUS_NODE_LEN(estatus_len) \
81 (sizeof(struct ghes_estatus_node) + (estatus_len)) 81 (sizeof(struct ghes_estatus_node) + (estatus_len))
82#define GHES_ESTATUS_FROM_NODE(estatus_node) \ 82#define GHES_ESTATUS_FROM_NODE(estatus_node) \
83 ((struct acpi_generic_status *) \ 83 ((struct acpi_hest_generic_status *) \
84 ((struct ghes_estatus_node *)(estatus_node) + 1)) 84 ((struct ghes_estatus_node *)(estatus_node) + 1))
85 85
86bool ghes_disable; 86bool ghes_disable;
@@ -388,7 +388,7 @@ static void ghes_clear_estatus(struct ghes *ghes)
388 ghes->flags &= ~GHES_TO_CLEAR; 388 ghes->flags &= ~GHES_TO_CLEAR;
389} 389}
390 390
391static void ghes_handle_memory_failure(struct acpi_generic_data *gdata, int sev) 391static void ghes_handle_memory_failure(struct acpi_hest_generic_data *gdata, int sev)
392{ 392{
393#ifdef CONFIG_ACPI_APEI_MEMORY_FAILURE 393#ifdef CONFIG_ACPI_APEI_MEMORY_FAILURE
394 unsigned long pfn; 394 unsigned long pfn;
@@ -421,10 +421,10 @@ static void ghes_handle_memory_failure(struct acpi_generic_data *gdata, int sev)
421} 421}
422 422
423static void ghes_do_proc(struct ghes *ghes, 423static void ghes_do_proc(struct ghes *ghes,
424 const struct acpi_generic_status *estatus) 424 const struct acpi_hest_generic_status *estatus)
425{ 425{
426 int sev, sec_sev; 426 int sev, sec_sev;
427 struct acpi_generic_data *gdata; 427 struct acpi_hest_generic_data *gdata;
428 428
429 sev = ghes_severity(estatus->error_severity); 429 sev = ghes_severity(estatus->error_severity);
430 apei_estatus_for_each_section(estatus, gdata) { 430 apei_estatus_for_each_section(estatus, gdata) {
@@ -476,7 +476,7 @@ static void ghes_do_proc(struct ghes *ghes,
476 476
477static void __ghes_print_estatus(const char *pfx, 477static void __ghes_print_estatus(const char *pfx,
478 const struct acpi_hest_generic *generic, 478 const struct acpi_hest_generic *generic,
479 const struct acpi_generic_status *estatus) 479 const struct acpi_hest_generic_status *estatus)
480{ 480{
481 static atomic_t seqno; 481 static atomic_t seqno;
482 unsigned int curr_seqno; 482 unsigned int curr_seqno;
@@ -498,7 +498,7 @@ static void __ghes_print_estatus(const char *pfx,
498 498
499static int ghes_print_estatus(const char *pfx, 499static int ghes_print_estatus(const char *pfx,
500 const struct acpi_hest_generic *generic, 500 const struct acpi_hest_generic *generic,
501 const struct acpi_generic_status *estatus) 501 const struct acpi_hest_generic_status *estatus)
502{ 502{
503 /* Not more than 2 messages every 5 seconds */ 503 /* Not more than 2 messages every 5 seconds */
504 static DEFINE_RATELIMIT_STATE(ratelimit_corrected, 5*HZ, 2); 504 static DEFINE_RATELIMIT_STATE(ratelimit_corrected, 5*HZ, 2);
@@ -520,13 +520,13 @@ static int ghes_print_estatus(const char *pfx,
520 * GHES error status reporting throttle, to report more kinds of 520 * GHES error status reporting throttle, to report more kinds of
521 * errors, instead of just most frequently occurred errors. 521 * errors, instead of just most frequently occurred errors.
522 */ 522 */
523static int ghes_estatus_cached(struct acpi_generic_status *estatus) 523static int ghes_estatus_cached(struct acpi_hest_generic_status *estatus)
524{ 524{
525 u32 len; 525 u32 len;
526 int i, cached = 0; 526 int i, cached = 0;
527 unsigned long long now; 527 unsigned long long now;
528 struct ghes_estatus_cache *cache; 528 struct ghes_estatus_cache *cache;
529 struct acpi_generic_status *cache_estatus; 529 struct acpi_hest_generic_status *cache_estatus;
530 530
531 len = cper_estatus_len(estatus); 531 len = cper_estatus_len(estatus);
532 rcu_read_lock(); 532 rcu_read_lock();
@@ -551,12 +551,12 @@ static int ghes_estatus_cached(struct acpi_generic_status *estatus)
551 551
552static struct ghes_estatus_cache *ghes_estatus_cache_alloc( 552static struct ghes_estatus_cache *ghes_estatus_cache_alloc(
553 struct acpi_hest_generic *generic, 553 struct acpi_hest_generic *generic,
554 struct acpi_generic_status *estatus) 554 struct acpi_hest_generic_status *estatus)
555{ 555{
556 int alloced; 556 int alloced;
557 u32 len, cache_len; 557 u32 len, cache_len;
558 struct ghes_estatus_cache *cache; 558 struct ghes_estatus_cache *cache;
559 struct acpi_generic_status *cache_estatus; 559 struct acpi_hest_generic_status *cache_estatus;
560 560
561 alloced = atomic_add_return(1, &ghes_estatus_cache_alloced); 561 alloced = atomic_add_return(1, &ghes_estatus_cache_alloced);
562 if (alloced > GHES_ESTATUS_CACHE_ALLOCED_MAX) { 562 if (alloced > GHES_ESTATUS_CACHE_ALLOCED_MAX) {
@@ -599,7 +599,7 @@ static void ghes_estatus_cache_rcu_free(struct rcu_head *head)
599 599
600static void ghes_estatus_cache_add( 600static void ghes_estatus_cache_add(
601 struct acpi_hest_generic *generic, 601 struct acpi_hest_generic *generic,
602 struct acpi_generic_status *estatus) 602 struct acpi_hest_generic_status *estatus)
603{ 603{
604 int i, slot = -1, count; 604 int i, slot = -1, count;
605 unsigned long long now, duration, period, max_period = 0; 605 unsigned long long now, duration, period, max_period = 0;
@@ -757,7 +757,7 @@ static void ghes_proc_in_irq(struct irq_work *irq_work)
757 struct llist_node *llnode, *next; 757 struct llist_node *llnode, *next;
758 struct ghes_estatus_node *estatus_node; 758 struct ghes_estatus_node *estatus_node;
759 struct acpi_hest_generic *generic; 759 struct acpi_hest_generic *generic;
760 struct acpi_generic_status *estatus; 760 struct acpi_hest_generic_status *estatus;
761 u32 len, node_len; 761 u32 len, node_len;
762 762
763 llnode = llist_del_all(&ghes_estatus_llist); 763 llnode = llist_del_all(&ghes_estatus_llist);
@@ -790,7 +790,7 @@ static void ghes_print_queued_estatus(void)
790 struct llist_node *llnode; 790 struct llist_node *llnode;
791 struct ghes_estatus_node *estatus_node; 791 struct ghes_estatus_node *estatus_node;
792 struct acpi_hest_generic *generic; 792 struct acpi_hest_generic *generic;
793 struct acpi_generic_status *estatus; 793 struct acpi_hest_generic_status *estatus;
794 u32 len, node_len; 794 u32 len, node_len;
795 795
796 llnode = llist_del_all(&ghes_estatus_llist); 796 llnode = llist_del_all(&ghes_estatus_llist);
@@ -849,7 +849,7 @@ static int ghes_notify_nmi(unsigned int cmd, struct pt_regs *regs)
849#ifdef CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG 849#ifdef CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG
850 u32 len, node_len; 850 u32 len, node_len;
851 struct ghes_estatus_node *estatus_node; 851 struct ghes_estatus_node *estatus_node;
852 struct acpi_generic_status *estatus; 852 struct acpi_hest_generic_status *estatus;
853#endif 853#endif
854 if (!(ghes->flags & GHES_TO_CLEAR)) 854 if (!(ghes->flags & GHES_TO_CLEAR))
855 continue; 855 continue;
@@ -991,7 +991,7 @@ static int ghes_probe(struct platform_device *ghes_dev)
991 991
992 rc = -EIO; 992 rc = -EIO;
993 if (generic->error_block_length < 993 if (generic->error_block_length <
994 sizeof(struct acpi_generic_status)) { 994 sizeof(struct acpi_hest_generic_status)) {
995 pr_warning(FW_BUG GHES_PFX "Invalid error block length: %u for generic hardware error source: %d\n", 995 pr_warning(FW_BUG GHES_PFX "Invalid error block length: %u for generic hardware error source: %d\n",
996 generic->error_block_length, 996 generic->error_block_length,
997 generic->header.source_id); 997 generic->header.source_id);
diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index 130f513e08c9..48bcf38a0ea8 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -35,7 +35,6 @@
35#include <linux/delay.h> 35#include <linux/delay.h>
36#include <linux/slab.h> 36#include <linux/slab.h>
37#include <linux/suspend.h> 37#include <linux/suspend.h>
38#include <linux/delay.h>
39#include <asm/unaligned.h> 38#include <asm/unaligned.h>
40 39
41#ifdef CONFIG_ACPI_PROCFS_POWER 40#ifdef CONFIG_ACPI_PROCFS_POWER
diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
index 3d8413d02a97..36eb42e3b0bb 100644
--- a/drivers/acpi/blacklist.c
+++ b/drivers/acpi/blacklist.c
@@ -247,75 +247,11 @@ static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
247 }, 247 },
248 248
249 /* 249 /*
250 * The following machines have broken backlight support when reporting 250 * These machines will power on immediately after shutdown when
251 * the Windows 2012 OSI, so disable it until their support is fixed. 251 * reporting the Windows 2012 OSI.
252 */ 252 */
253 { 253 {
254 .callback = dmi_disable_osi_win8, 254 .callback = dmi_disable_osi_win8,
255 .ident = "ASUS Zenbook Prime UX31A",
256 .matches = {
257 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
258 DMI_MATCH(DMI_PRODUCT_NAME, "UX31A"),
259 },
260 },
261 {
262 .callback = dmi_disable_osi_win8,
263 .ident = "ThinkPad Edge E530",
264 .matches = {
265 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
266 DMI_MATCH(DMI_PRODUCT_VERSION, "3259A2G"),
267 },
268 },
269 {
270 .callback = dmi_disable_osi_win8,
271 .ident = "ThinkPad Edge E530",
272 .matches = {
273 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
274 DMI_MATCH(DMI_PRODUCT_VERSION, "3259CTO"),
275 },
276 },
277 {
278 .callback = dmi_disable_osi_win8,
279 .ident = "ThinkPad Edge E530",
280 .matches = {
281 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
282 DMI_MATCH(DMI_PRODUCT_VERSION, "3259HJG"),
283 },
284 },
285 {
286 .callback = dmi_disable_osi_win8,
287 .ident = "Acer Aspire V5-573G",
288 .matches = {
289 DMI_MATCH(DMI_SYS_VENDOR, "Acer Aspire"),
290 DMI_MATCH(DMI_PRODUCT_VERSION, "V5-573G/Dazzle_HW"),
291 },
292 },
293 {
294 .callback = dmi_disable_osi_win8,
295 .ident = "Acer Aspire V5-572G",
296 .matches = {
297 DMI_MATCH(DMI_SYS_VENDOR, "Acer Aspire"),
298 DMI_MATCH(DMI_PRODUCT_VERSION, "V5-572G/Dazzle_CX"),
299 },
300 },
301 {
302 .callback = dmi_disable_osi_win8,
303 .ident = "ThinkPad T431s",
304 .matches = {
305 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
306 DMI_MATCH(DMI_PRODUCT_VERSION, "20AACTO1WW"),
307 },
308 },
309 {
310 .callback = dmi_disable_osi_win8,
311 .ident = "ThinkPad T430",
312 .matches = {
313 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
314 DMI_MATCH(DMI_PRODUCT_VERSION, "2349D15"),
315 },
316 },
317 {
318 .callback = dmi_disable_osi_win8,
319 .ident = "Dell Inspiron 7737", 255 .ident = "Dell Inspiron 7737",
320 .matches = { 256 .matches = {
321 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 257 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c
index c5bc8cfe09fa..8581f5b84f48 100644
--- a/drivers/acpi/bus.c
+++ b/drivers/acpi/bus.c
@@ -477,9 +477,6 @@ static int __init acpi_bus_init_irq(void)
477 return 0; 477 return 0;
478} 478}
479 479
480u8 acpi_gbl_permanent_mmap;
481
482
483void __init acpi_early_init(void) 480void __init acpi_early_init(void)
484{ 481{
485 acpi_status status; 482 acpi_status status;
diff --git a/drivers/acpi/button.c b/drivers/acpi/button.c
index db35594d4df7..6d5d1832a588 100644
--- a/drivers/acpi/button.c
+++ b/drivers/acpi/button.c
@@ -79,11 +79,13 @@ static int acpi_button_remove(struct acpi_device *device);
79static void acpi_button_notify(struct acpi_device *device, u32 event); 79static void acpi_button_notify(struct acpi_device *device, u32 event);
80 80
81#ifdef CONFIG_PM_SLEEP 81#ifdef CONFIG_PM_SLEEP
82static int acpi_button_suspend(struct device *dev);
82static int acpi_button_resume(struct device *dev); 83static int acpi_button_resume(struct device *dev);
83#else 84#else
85#define acpi_button_suspend NULL
84#define acpi_button_resume NULL 86#define acpi_button_resume NULL
85#endif 87#endif
86static SIMPLE_DEV_PM_OPS(acpi_button_pm, NULL, acpi_button_resume); 88static SIMPLE_DEV_PM_OPS(acpi_button_pm, acpi_button_suspend, acpi_button_resume);
87 89
88static struct acpi_driver acpi_button_driver = { 90static struct acpi_driver acpi_button_driver = {
89 .name = "button", 91 .name = "button",
@@ -102,6 +104,7 @@ struct acpi_button {
102 struct input_dev *input; 104 struct input_dev *input;
103 char phys[32]; /* for input device */ 105 char phys[32]; /* for input device */
104 unsigned long pushed; 106 unsigned long pushed;
107 bool suspended;
105}; 108};
106 109
107static BLOCKING_NOTIFIER_HEAD(acpi_lid_notifier); 110static BLOCKING_NOTIFIER_HEAD(acpi_lid_notifier);
@@ -293,15 +296,19 @@ static void acpi_button_notify(struct acpi_device *device, u32 event)
293 if (button->type == ACPI_BUTTON_TYPE_LID) { 296 if (button->type == ACPI_BUTTON_TYPE_LID) {
294 acpi_lid_send_state(device); 297 acpi_lid_send_state(device);
295 } else { 298 } else {
296 int keycode = test_bit(KEY_SLEEP, input->keybit) ? 299 int keycode;
297 KEY_SLEEP : KEY_POWER; 300
301 pm_wakeup_event(&device->dev, 0);
302 if (button->suspended)
303 break;
298 304
305 keycode = test_bit(KEY_SLEEP, input->keybit) ?
306 KEY_SLEEP : KEY_POWER;
299 input_report_key(input, keycode, 1); 307 input_report_key(input, keycode, 1);
300 input_sync(input); 308 input_sync(input);
301 input_report_key(input, keycode, 0); 309 input_report_key(input, keycode, 0);
302 input_sync(input); 310 input_sync(input);
303 311
304 pm_wakeup_event(&device->dev, 0);
305 acpi_bus_generate_netlink_event( 312 acpi_bus_generate_netlink_event(
306 device->pnp.device_class, 313 device->pnp.device_class,
307 dev_name(&device->dev), 314 dev_name(&device->dev),
@@ -316,11 +323,21 @@ static void acpi_button_notify(struct acpi_device *device, u32 event)
316} 323}
317 324
318#ifdef CONFIG_PM_SLEEP 325#ifdef CONFIG_PM_SLEEP
326static int acpi_button_suspend(struct device *dev)
327{
328 struct acpi_device *device = to_acpi_device(dev);
329 struct acpi_button *button = acpi_driver_data(device);
330
331 button->suspended = true;
332 return 0;
333}
334
319static int acpi_button_resume(struct device *dev) 335static int acpi_button_resume(struct device *dev)
320{ 336{
321 struct acpi_device *device = to_acpi_device(dev); 337 struct acpi_device *device = to_acpi_device(dev);
322 struct acpi_button *button = acpi_driver_data(device); 338 struct acpi_button *button = acpi_driver_data(device);
323 339
340 button->suspended = false;
324 if (button->type == ACPI_BUTTON_TYPE_LID) 341 if (button->type == ACPI_BUTTON_TYPE_LID)
325 return acpi_lid_send_state(device); 342 return acpi_lid_send_state(device);
326 return 0; 343 return 0;
diff --git a/drivers/acpi/device_pm.c b/drivers/acpi/device_pm.c
index 49a51277f81d..67075f800e34 100644
--- a/drivers/acpi/device_pm.c
+++ b/drivers/acpi/device_pm.c
@@ -367,29 +367,61 @@ EXPORT_SYMBOL(acpi_bus_power_manageable);
367#ifdef CONFIG_PM 367#ifdef CONFIG_PM
368static DEFINE_MUTEX(acpi_pm_notifier_lock); 368static DEFINE_MUTEX(acpi_pm_notifier_lock);
369 369
370static void acpi_pm_notify_handler(acpi_handle handle, u32 val, void *not_used)
371{
372 struct acpi_device *adev;
373
374 if (val != ACPI_NOTIFY_DEVICE_WAKE)
375 return;
376
377 adev = acpi_bus_get_acpi_device(handle);
378 if (!adev)
379 return;
380
381 mutex_lock(&acpi_pm_notifier_lock);
382
383 if (adev->wakeup.flags.notifier_present) {
384 __pm_wakeup_event(adev->wakeup.ws, 0);
385 if (adev->wakeup.context.work.func)
386 queue_pm_work(&adev->wakeup.context.work);
387 }
388
389 mutex_unlock(&acpi_pm_notifier_lock);
390
391 acpi_bus_put_acpi_device(adev);
392}
393
370/** 394/**
371 * acpi_add_pm_notifier - Register PM notifier for given ACPI device. 395 * acpi_add_pm_notifier - Register PM notify handler for given ACPI device.
372 * @adev: ACPI device to add the notifier for. 396 * @adev: ACPI device to add the notify handler for.
373 * @context: Context information to pass to the notifier routine. 397 * @dev: Device to generate a wakeup event for while handling the notification.
398 * @work_func: Work function to execute when handling the notification.
374 * 399 *
375 * NOTE: @adev need not be a run-wake or wakeup device to be a valid source of 400 * NOTE: @adev need not be a run-wake or wakeup device to be a valid source of
376 * PM wakeup events. For example, wakeup events may be generated for bridges 401 * PM wakeup events. For example, wakeup events may be generated for bridges
377 * if one of the devices below the bridge is signaling wakeup, even if the 402 * if one of the devices below the bridge is signaling wakeup, even if the
378 * bridge itself doesn't have a wakeup GPE associated with it. 403 * bridge itself doesn't have a wakeup GPE associated with it.
379 */ 404 */
380acpi_status acpi_add_pm_notifier(struct acpi_device *adev, 405acpi_status acpi_add_pm_notifier(struct acpi_device *adev, struct device *dev,
381 acpi_notify_handler handler, void *context) 406 void (*work_func)(struct work_struct *work))
382{ 407{
383 acpi_status status = AE_ALREADY_EXISTS; 408 acpi_status status = AE_ALREADY_EXISTS;
384 409
410 if (!dev && !work_func)
411 return AE_BAD_PARAMETER;
412
385 mutex_lock(&acpi_pm_notifier_lock); 413 mutex_lock(&acpi_pm_notifier_lock);
386 414
387 if (adev->wakeup.flags.notifier_present) 415 if (adev->wakeup.flags.notifier_present)
388 goto out; 416 goto out;
389 417
390 status = acpi_install_notify_handler(adev->handle, 418 adev->wakeup.ws = wakeup_source_register(dev_name(&adev->dev));
391 ACPI_SYSTEM_NOTIFY, 419 adev->wakeup.context.dev = dev;
392 handler, context); 420 if (work_func)
421 INIT_WORK(&adev->wakeup.context.work, work_func);
422
423 status = acpi_install_notify_handler(adev->handle, ACPI_SYSTEM_NOTIFY,
424 acpi_pm_notify_handler, NULL);
393 if (ACPI_FAILURE(status)) 425 if (ACPI_FAILURE(status))
394 goto out; 426 goto out;
395 427
@@ -404,8 +436,7 @@ acpi_status acpi_add_pm_notifier(struct acpi_device *adev,
404 * acpi_remove_pm_notifier - Unregister PM notifier from given ACPI device. 436 * acpi_remove_pm_notifier - Unregister PM notifier from given ACPI device.
405 * @adev: ACPI device to remove the notifier from. 437 * @adev: ACPI device to remove the notifier from.
406 */ 438 */
407acpi_status acpi_remove_pm_notifier(struct acpi_device *adev, 439acpi_status acpi_remove_pm_notifier(struct acpi_device *adev)
408 acpi_notify_handler handler)
409{ 440{
410 acpi_status status = AE_BAD_PARAMETER; 441 acpi_status status = AE_BAD_PARAMETER;
411 442
@@ -416,10 +447,17 @@ acpi_status acpi_remove_pm_notifier(struct acpi_device *adev,
416 447
417 status = acpi_remove_notify_handler(adev->handle, 448 status = acpi_remove_notify_handler(adev->handle,
418 ACPI_SYSTEM_NOTIFY, 449 ACPI_SYSTEM_NOTIFY,
419 handler); 450 acpi_pm_notify_handler);
420 if (ACPI_FAILURE(status)) 451 if (ACPI_FAILURE(status))
421 goto out; 452 goto out;
422 453
454 if (adev->wakeup.context.work.func) {
455 cancel_work_sync(&adev->wakeup.context.work);
456 adev->wakeup.context.work.func = NULL;
457 }
458 adev->wakeup.context.dev = NULL;
459 wakeup_source_unregister(adev->wakeup.ws);
460
423 adev->wakeup.flags.notifier_present = false; 461 adev->wakeup.flags.notifier_present = false;
424 462
425 out: 463 out:
@@ -558,7 +596,6 @@ static int acpi_dev_pm_get_state(struct device *dev, struct acpi_device *adev,
558 */ 596 */
559int acpi_pm_device_sleep_state(struct device *dev, int *d_min_p, int d_max_in) 597int acpi_pm_device_sleep_state(struct device *dev, int *d_min_p, int d_max_in)
560{ 598{
561 acpi_handle handle = ACPI_HANDLE(dev);
562 struct acpi_device *adev; 599 struct acpi_device *adev;
563 int ret, d_min, d_max; 600 int ret, d_min, d_max;
564 601
@@ -573,8 +610,9 @@ int acpi_pm_device_sleep_state(struct device *dev, int *d_min_p, int d_max_in)
573 d_max_in = ACPI_STATE_D3_HOT; 610 d_max_in = ACPI_STATE_D3_HOT;
574 } 611 }
575 612
576 if (!handle || acpi_bus_get_device(handle, &adev)) { 613 adev = ACPI_COMPANION(dev);
577 dev_dbg(dev, "ACPI handle without context in %s!\n", __func__); 614 if (!adev) {
615 dev_dbg(dev, "ACPI companion missing in %s!\n", __func__);
578 return -ENODEV; 616 return -ENODEV;
579 } 617 }
580 618
@@ -600,26 +638,25 @@ int acpi_pm_device_sleep_state(struct device *dev, int *d_min_p, int d_max_in)
600} 638}
601EXPORT_SYMBOL(acpi_pm_device_sleep_state); 639EXPORT_SYMBOL(acpi_pm_device_sleep_state);
602 640
603#ifdef CONFIG_PM_RUNTIME
604/** 641/**
605 * acpi_wakeup_device - Wakeup notification handler for ACPI devices. 642 * acpi_pm_notify_work_func - ACPI devices wakeup notification work function.
606 * @handle: ACPI handle of the device the notification is for. 643 * @work: Work item to handle.
607 * @event: Type of the signaled event.
608 * @context: Device corresponding to @handle.
609 */ 644 */
610static void acpi_wakeup_device(acpi_handle handle, u32 event, void *context) 645static void acpi_pm_notify_work_func(struct work_struct *work)
611{ 646{
612 struct device *dev = context; 647 struct device *dev;
613 648
614 if (event == ACPI_NOTIFY_DEVICE_WAKE && dev) { 649 dev = container_of(work, struct acpi_device_wakeup_context, work)->dev;
650 if (dev) {
615 pm_wakeup_event(dev, 0); 651 pm_wakeup_event(dev, 0);
616 pm_runtime_resume(dev); 652 pm_runtime_resume(dev);
617 } 653 }
618} 654}
619 655
620/** 656/**
621 * __acpi_device_run_wake - Enable/disable runtime remote wakeup for device. 657 * acpi_device_wakeup - Enable/disable wakeup functionality for device.
622 * @adev: ACPI device to enable/disable the remote wakeup for. 658 * @adev: ACPI device to enable/disable wakeup functionality for.
659 * @target_state: State the system is transitioning into.
623 * @enable: Whether to enable or disable the wakeup functionality. 660 * @enable: Whether to enable or disable the wakeup functionality.
624 * 661 *
625 * Enable/disable the GPE associated with @adev so that it can generate 662 * Enable/disable the GPE associated with @adev so that it can generate
@@ -629,7 +666,8 @@ static void acpi_wakeup_device(acpi_handle handle, u32 event, void *context)
629 * Callers must ensure that @adev is a valid ACPI device node before executing 666 * Callers must ensure that @adev is a valid ACPI device node before executing
630 * this function. 667 * this function.
631 */ 668 */
632int __acpi_device_run_wake(struct acpi_device *adev, bool enable) 669static int acpi_device_wakeup(struct acpi_device *adev, u32 target_state,
670 bool enable)
633{ 671{
634 struct acpi_device_wakeup *wakeup = &adev->wakeup; 672 struct acpi_device_wakeup *wakeup = &adev->wakeup;
635 673
@@ -637,7 +675,7 @@ int __acpi_device_run_wake(struct acpi_device *adev, bool enable)
637 acpi_status res; 675 acpi_status res;
638 int error; 676 int error;
639 677
640 error = acpi_enable_wakeup_device_power(adev, ACPI_STATE_S0); 678 error = acpi_enable_wakeup_device_power(adev, target_state);
641 if (error) 679 if (error)
642 return error; 680 return error;
643 681
@@ -653,6 +691,7 @@ int __acpi_device_run_wake(struct acpi_device *adev, bool enable)
653 return 0; 691 return 0;
654} 692}
655 693
694#ifdef CONFIG_PM_RUNTIME
656/** 695/**
657 * acpi_pm_device_run_wake - Enable/disable remote wakeup for given device. 696 * acpi_pm_device_run_wake - Enable/disable remote wakeup for given device.
658 * @dev: Device to enable/disable the platform to wake up. 697 * @dev: Device to enable/disable the platform to wake up.
@@ -661,63 +700,42 @@ int __acpi_device_run_wake(struct acpi_device *adev, bool enable)
661int acpi_pm_device_run_wake(struct device *phys_dev, bool enable) 700int acpi_pm_device_run_wake(struct device *phys_dev, bool enable)
662{ 701{
663 struct acpi_device *adev; 702 struct acpi_device *adev;
664 acpi_handle handle;
665 703
666 if (!device_run_wake(phys_dev)) 704 if (!device_run_wake(phys_dev))
667 return -EINVAL; 705 return -EINVAL;
668 706
669 handle = ACPI_HANDLE(phys_dev); 707 adev = ACPI_COMPANION(phys_dev);
670 if (!handle || acpi_bus_get_device(handle, &adev)) { 708 if (!adev) {
671 dev_dbg(phys_dev, "ACPI handle without context in %s!\n", 709 dev_dbg(phys_dev, "ACPI companion missing in %s!\n", __func__);
672 __func__);
673 return -ENODEV; 710 return -ENODEV;
674 } 711 }
675 712
676 return __acpi_device_run_wake(adev, enable); 713 return acpi_device_wakeup(adev, enable, ACPI_STATE_S0);
677} 714}
678EXPORT_SYMBOL(acpi_pm_device_run_wake); 715EXPORT_SYMBOL(acpi_pm_device_run_wake);
679#else
680static inline void acpi_wakeup_device(acpi_handle handle, u32 event,
681 void *context) {}
682#endif /* CONFIG_PM_RUNTIME */ 716#endif /* CONFIG_PM_RUNTIME */
683 717
684#ifdef CONFIG_PM_SLEEP 718#ifdef CONFIG_PM_SLEEP
685/** 719/**
686 * __acpi_device_sleep_wake - Enable or disable device to wake up the system.
687 * @dev: Device to enable/desible to wake up the system.
688 * @target_state: System state the device is supposed to wake up from.
689 * @enable: Whether to enable or disable @dev to wake up the system.
690 */
691int __acpi_device_sleep_wake(struct acpi_device *adev, u32 target_state,
692 bool enable)
693{
694 return enable ?
695 acpi_enable_wakeup_device_power(adev, target_state) :
696 acpi_disable_wakeup_device_power(adev);
697}
698
699/**
700 * acpi_pm_device_sleep_wake - Enable or disable device to wake up the system. 720 * acpi_pm_device_sleep_wake - Enable or disable device to wake up the system.
701 * @dev: Device to enable/desible to wake up the system from sleep states. 721 * @dev: Device to enable/desible to wake up the system from sleep states.
702 * @enable: Whether to enable or disable @dev to wake up the system. 722 * @enable: Whether to enable or disable @dev to wake up the system.
703 */ 723 */
704int acpi_pm_device_sleep_wake(struct device *dev, bool enable) 724int acpi_pm_device_sleep_wake(struct device *dev, bool enable)
705{ 725{
706 acpi_handle handle;
707 struct acpi_device *adev; 726 struct acpi_device *adev;
708 int error; 727 int error;
709 728
710 if (!device_can_wakeup(dev)) 729 if (!device_can_wakeup(dev))
711 return -EINVAL; 730 return -EINVAL;
712 731
713 handle = ACPI_HANDLE(dev); 732 adev = ACPI_COMPANION(dev);
714 if (!handle || acpi_bus_get_device(handle, &adev)) { 733 if (!adev) {
715 dev_dbg(dev, "ACPI handle without context in %s!\n", __func__); 734 dev_dbg(dev, "ACPI companion missing in %s!\n", __func__);
716 return -ENODEV; 735 return -ENODEV;
717 } 736 }
718 737
719 error = __acpi_device_sleep_wake(adev, acpi_target_system_state(), 738 error = acpi_device_wakeup(adev, acpi_target_system_state(), enable);
720 enable);
721 if (!error) 739 if (!error)
722 dev_info(dev, "System wakeup %s by ACPI\n", 740 dev_info(dev, "System wakeup %s by ACPI\n",
723 enable ? "enabled" : "disabled"); 741 enable ? "enabled" : "disabled");
@@ -775,13 +793,13 @@ int acpi_dev_runtime_suspend(struct device *dev)
775 793
776 remote_wakeup = dev_pm_qos_flags(dev, PM_QOS_FLAG_REMOTE_WAKEUP) > 794 remote_wakeup = dev_pm_qos_flags(dev, PM_QOS_FLAG_REMOTE_WAKEUP) >
777 PM_QOS_FLAGS_NONE; 795 PM_QOS_FLAGS_NONE;
778 error = __acpi_device_run_wake(adev, remote_wakeup); 796 error = acpi_device_wakeup(adev, ACPI_STATE_S0, remote_wakeup);
779 if (remote_wakeup && error) 797 if (remote_wakeup && error)
780 return -EAGAIN; 798 return -EAGAIN;
781 799
782 error = acpi_dev_pm_low_power(dev, adev, ACPI_STATE_S0); 800 error = acpi_dev_pm_low_power(dev, adev, ACPI_STATE_S0);
783 if (error) 801 if (error)
784 __acpi_device_run_wake(adev, false); 802 acpi_device_wakeup(adev, ACPI_STATE_S0, false);
785 803
786 return error; 804 return error;
787} 805}
@@ -804,7 +822,7 @@ int acpi_dev_runtime_resume(struct device *dev)
804 return 0; 822 return 0;
805 823
806 error = acpi_dev_pm_full_power(adev); 824 error = acpi_dev_pm_full_power(adev);
807 __acpi_device_run_wake(adev, false); 825 acpi_device_wakeup(adev, ACPI_STATE_S0, false);
808 return error; 826 return error;
809} 827}
810EXPORT_SYMBOL_GPL(acpi_dev_runtime_resume); 828EXPORT_SYMBOL_GPL(acpi_dev_runtime_resume);
@@ -860,13 +878,13 @@ int acpi_dev_suspend_late(struct device *dev)
860 878
861 target_state = acpi_target_system_state(); 879 target_state = acpi_target_system_state();
862 wakeup = device_may_wakeup(dev); 880 wakeup = device_may_wakeup(dev);
863 error = __acpi_device_sleep_wake(adev, target_state, wakeup); 881 error = acpi_device_wakeup(adev, target_state, wakeup);
864 if (wakeup && error) 882 if (wakeup && error)
865 return error; 883 return error;
866 884
867 error = acpi_dev_pm_low_power(dev, adev, target_state); 885 error = acpi_dev_pm_low_power(dev, adev, target_state);
868 if (error) 886 if (error)
869 __acpi_device_sleep_wake(adev, ACPI_STATE_UNKNOWN, false); 887 acpi_device_wakeup(adev, ACPI_STATE_UNKNOWN, false);
870 888
871 return error; 889 return error;
872} 890}
@@ -889,7 +907,7 @@ int acpi_dev_resume_early(struct device *dev)
889 return 0; 907 return 0;
890 908
891 error = acpi_dev_pm_full_power(adev); 909 error = acpi_dev_pm_full_power(adev);
892 __acpi_device_sleep_wake(adev, ACPI_STATE_UNKNOWN, false); 910 acpi_device_wakeup(adev, ACPI_STATE_UNKNOWN, false);
893 return error; 911 return error;
894} 912}
895EXPORT_SYMBOL_GPL(acpi_dev_resume_early); 913EXPORT_SYMBOL_GPL(acpi_dev_resume_early);
@@ -1048,11 +1066,11 @@ int acpi_dev_pm_attach(struct device *dev, bool power_on)
1048 if (dev->pm_domain) 1066 if (dev->pm_domain)
1049 return -EEXIST; 1067 return -EEXIST;
1050 1068
1051 acpi_add_pm_notifier(adev, acpi_wakeup_device, dev); 1069 acpi_add_pm_notifier(adev, dev, acpi_pm_notify_work_func);
1052 dev->pm_domain = &acpi_general_pm_domain; 1070 dev->pm_domain = &acpi_general_pm_domain;
1053 if (power_on) { 1071 if (power_on) {
1054 acpi_dev_pm_full_power(adev); 1072 acpi_dev_pm_full_power(adev);
1055 __acpi_device_run_wake(adev, false); 1073 acpi_device_wakeup(adev, ACPI_STATE_S0, false);
1056 } 1074 }
1057 return 0; 1075 return 0;
1058} 1076}
@@ -1076,7 +1094,7 @@ void acpi_dev_pm_detach(struct device *dev, bool power_off)
1076 1094
1077 if (adev && dev->pm_domain == &acpi_general_pm_domain) { 1095 if (adev && dev->pm_domain == &acpi_general_pm_domain) {
1078 dev->pm_domain = NULL; 1096 dev->pm_domain = NULL;
1079 acpi_remove_pm_notifier(adev, acpi_wakeup_device); 1097 acpi_remove_pm_notifier(adev);
1080 if (power_off) { 1098 if (power_off) {
1081 /* 1099 /*
1082 * If the device's PM QoS resume latency limit or flags 1100 * If the device's PM QoS resume latency limit or flags
@@ -1086,7 +1104,7 @@ void acpi_dev_pm_detach(struct device *dev, bool power_off)
1086 */ 1104 */
1087 dev_pm_qos_hide_latency_limit(dev); 1105 dev_pm_qos_hide_latency_limit(dev);
1088 dev_pm_qos_hide_flags(dev); 1106 dev_pm_qos_hide_flags(dev);
1089 __acpi_device_run_wake(adev, false); 1107 acpi_device_wakeup(adev, ACPI_STATE_S0, false);
1090 acpi_dev_pm_low_power(dev, adev, ACPI_STATE_S0); 1108 acpi_dev_pm_low_power(dev, adev, ACPI_STATE_S0);
1091 } 1109 }
1092 } 1110 }
diff --git a/drivers/acpi/internal.h b/drivers/acpi/internal.h
index 7de5b603f272..4c5cf77e7576 100644
--- a/drivers/acpi/internal.h
+++ b/drivers/acpi/internal.h
@@ -84,8 +84,6 @@ void acpi_init_device_object(struct acpi_device *device, acpi_handle handle,
84 int type, unsigned long long sta); 84 int type, unsigned long long sta);
85void acpi_device_add_finalize(struct acpi_device *device); 85void acpi_device_add_finalize(struct acpi_device *device);
86void acpi_free_pnp_ids(struct acpi_device_pnp *pnp); 86void acpi_free_pnp_ids(struct acpi_device_pnp *pnp);
87int acpi_bind_one(struct device *dev, struct acpi_device *adev);
88int acpi_unbind_one(struct device *dev);
89bool acpi_device_is_present(struct acpi_device *adev); 87bool acpi_device_is_present(struct acpi_device *adev);
90bool acpi_device_is_battery(struct acpi_device *adev); 88bool acpi_device_is_battery(struct acpi_device *adev);
91 89
@@ -108,7 +106,12 @@ int acpi_power_transition(struct acpi_device *device, int state);
108int acpi_device_update_power(struct acpi_device *device, int *state_p); 106int acpi_device_update_power(struct acpi_device *device, int *state_p);
109 107
110int acpi_wakeup_device_init(void); 108int acpi_wakeup_device_init(void);
109
110#ifdef CONFIG_ARCH_MIGHT_HAVE_ACPI_PDC
111void acpi_early_processor_set_pdc(void); 111void acpi_early_processor_set_pdc(void);
112#else
113static inline void acpi_early_processor_set_pdc(void) {}
114#endif
112 115
113/* -------------------------------------------------------------------------- 116/* --------------------------------------------------------------------------
114 Embedded Controller 117 Embedded Controller
diff --git a/drivers/acpi/osl.c b/drivers/acpi/osl.c
index bad25b070fe0..3abe9b223ba7 100644
--- a/drivers/acpi/osl.c
+++ b/drivers/acpi/osl.c
@@ -259,12 +259,14 @@ acpi_physical_address __init acpi_os_get_root_pointer(void)
259 "System description tables not found\n"); 259 "System description tables not found\n");
260 return 0; 260 return 0;
261 } 261 }
262 } else { 262 } else if (IS_ENABLED(CONFIG_ACPI_LEGACY_TABLES_LOOKUP)) {
263 acpi_physical_address pa = 0; 263 acpi_physical_address pa = 0;
264 264
265 acpi_find_root_pointer(&pa); 265 acpi_find_root_pointer(&pa);
266 return pa; 266 return pa;
267 } 267 }
268
269 return 0;
268} 270}
269 271
270/* Must be called with 'acpi_ioremap_lock' or RCU read lock held. */ 272/* Must be called with 'acpi_ioremap_lock' or RCU read lock held. */
diff --git a/drivers/acpi/pci_root.c b/drivers/acpi/pci_root.c
index d388f13d48b4..e6ae603ed1a1 100644
--- a/drivers/acpi/pci_root.c
+++ b/drivers/acpi/pci_root.c
@@ -593,7 +593,7 @@ static int acpi_pci_root_add(struct acpi_device *device,
593 if (no_aspm) 593 if (no_aspm)
594 pcie_no_aspm(); 594 pcie_no_aspm();
595 595
596 pci_acpi_add_bus_pm_notifier(device, root->bus); 596 pci_acpi_add_bus_pm_notifier(device);
597 if (device->wakeup.flags.run_wake) 597 if (device->wakeup.flags.run_wake)
598 device_set_run_wake(root->bus->bridge, true); 598 device_set_run_wake(root->bus->bridge, true);
599 599
diff --git a/drivers/acpi/processor_core.c b/drivers/acpi/processor_core.c
index 71e2065639a6..e32321ce9a5c 100644
--- a/drivers/acpi/processor_core.c
+++ b/drivers/acpi/processor_core.c
@@ -4,17 +4,11 @@
4 * 4 *
5 * Alex Chiang <achiang@hp.com> 5 * Alex Chiang <achiang@hp.com>
6 * - Unified x86/ia64 implementations 6 * - Unified x86/ia64 implementations
7 * Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
8 * - Added _PDC for platforms with Intel CPUs
9 */ 7 */
10#include <linux/export.h> 8#include <linux/export.h>
11#include <linux/dmi.h>
12#include <linux/slab.h>
13#include <linux/acpi.h> 9#include <linux/acpi.h>
14#include <acpi/processor.h> 10#include <acpi/processor.h>
15 11
16#include "internal.h"
17
18#define _COMPONENT ACPI_PROCESSOR_COMPONENT 12#define _COMPONENT ACPI_PROCESSOR_COMPONENT
19ACPI_MODULE_NAME("processor_core"); 13ACPI_MODULE_NAME("processor_core");
20 14
@@ -135,6 +129,8 @@ static int map_mat_entry(acpi_handle handle, int type, u32 acpi_id)
135 map_lapic_id(header, acpi_id, &apic_id); 129 map_lapic_id(header, acpi_id, &apic_id);
136 } else if (header->type == ACPI_MADT_TYPE_LOCAL_SAPIC) { 130 } else if (header->type == ACPI_MADT_TYPE_LOCAL_SAPIC) {
137 map_lsapic_id(header, type, acpi_id, &apic_id); 131 map_lsapic_id(header, type, acpi_id, &apic_id);
132 } else if (header->type == ACPI_MADT_TYPE_LOCAL_X2APIC) {
133 map_x2apic_id(header, type, acpi_id, &apic_id);
138 } 134 }
139 135
140exit: 136exit:
@@ -208,195 +204,3 @@ int acpi_get_cpuid(acpi_handle handle, int type, u32 acpi_id)
208 return acpi_map_cpuid(apic_id, acpi_id); 204 return acpi_map_cpuid(apic_id, acpi_id);
209} 205}
210EXPORT_SYMBOL_GPL(acpi_get_cpuid); 206EXPORT_SYMBOL_GPL(acpi_get_cpuid);
211
212static bool __init processor_physically_present(acpi_handle handle)
213{
214 int cpuid, type;
215 u32 acpi_id;
216 acpi_status status;
217 acpi_object_type acpi_type;
218 unsigned long long tmp;
219 union acpi_object object = { 0 };
220 struct acpi_buffer buffer = { sizeof(union acpi_object), &object };
221
222 status = acpi_get_type(handle, &acpi_type);
223 if (ACPI_FAILURE(status))
224 return false;
225
226 switch (acpi_type) {
227 case ACPI_TYPE_PROCESSOR:
228 status = acpi_evaluate_object(handle, NULL, NULL, &buffer);
229 if (ACPI_FAILURE(status))
230 return false;
231 acpi_id = object.processor.proc_id;
232 break;
233 case ACPI_TYPE_DEVICE:
234 status = acpi_evaluate_integer(handle, "_UID", NULL, &tmp);
235 if (ACPI_FAILURE(status))
236 return false;
237 acpi_id = tmp;
238 break;
239 default:
240 return false;
241 }
242
243 type = (acpi_type == ACPI_TYPE_DEVICE) ? 1 : 0;
244 cpuid = acpi_get_cpuid(handle, type, acpi_id);
245
246 if (cpuid == -1)
247 return false;
248
249 return true;
250}
251
252static void acpi_set_pdc_bits(u32 *buf)
253{
254 buf[0] = ACPI_PDC_REVISION_ID;
255 buf[1] = 1;
256
257 /* Enable coordination with firmware's _TSD info */
258 buf[2] = ACPI_PDC_SMP_T_SWCOORD;
259
260 /* Twiddle arch-specific bits needed for _PDC */
261 arch_acpi_set_pdc_bits(buf);
262}
263
264static struct acpi_object_list *acpi_processor_alloc_pdc(void)
265{
266 struct acpi_object_list *obj_list;
267 union acpi_object *obj;
268 u32 *buf;
269
270 /* allocate and initialize pdc. It will be used later. */
271 obj_list = kmalloc(sizeof(struct acpi_object_list), GFP_KERNEL);
272 if (!obj_list) {
273 printk(KERN_ERR "Memory allocation error\n");
274 return NULL;
275 }
276
277 obj = kmalloc(sizeof(union acpi_object), GFP_KERNEL);
278 if (!obj) {
279 printk(KERN_ERR "Memory allocation error\n");
280 kfree(obj_list);
281 return NULL;
282 }
283
284 buf = kmalloc(12, GFP_KERNEL);
285 if (!buf) {
286 printk(KERN_ERR "Memory allocation error\n");
287 kfree(obj);
288 kfree(obj_list);
289 return NULL;
290 }
291
292 acpi_set_pdc_bits(buf);
293
294 obj->type = ACPI_TYPE_BUFFER;
295 obj->buffer.length = 12;
296 obj->buffer.pointer = (u8 *) buf;
297 obj_list->count = 1;
298 obj_list->pointer = obj;
299
300 return obj_list;
301}
302
303/*
304 * _PDC is required for a BIOS-OS handshake for most of the newer
305 * ACPI processor features.
306 */
307static acpi_status
308acpi_processor_eval_pdc(acpi_handle handle, struct acpi_object_list *pdc_in)
309{
310 acpi_status status = AE_OK;
311
312 if (boot_option_idle_override == IDLE_NOMWAIT) {
313 /*
314 * If mwait is disabled for CPU C-states, the C2C3_FFH access
315 * mode will be disabled in the parameter of _PDC object.
316 * Of course C1_FFH access mode will also be disabled.
317 */
318 union acpi_object *obj;
319 u32 *buffer = NULL;
320
321 obj = pdc_in->pointer;
322 buffer = (u32 *)(obj->buffer.pointer);
323 buffer[2] &= ~(ACPI_PDC_C_C2C3_FFH | ACPI_PDC_C_C1_FFH);
324
325 }
326 status = acpi_evaluate_object(handle, "_PDC", pdc_in, NULL);
327
328 if (ACPI_FAILURE(status))
329 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
330 "Could not evaluate _PDC, using legacy perf. control.\n"));
331
332 return status;
333}
334
335void acpi_processor_set_pdc(acpi_handle handle)
336{
337 struct acpi_object_list *obj_list;
338
339 if (arch_has_acpi_pdc() == false)
340 return;
341
342 obj_list = acpi_processor_alloc_pdc();
343 if (!obj_list)
344 return;
345
346 acpi_processor_eval_pdc(handle, obj_list);
347
348 kfree(obj_list->pointer->buffer.pointer);
349 kfree(obj_list->pointer);
350 kfree(obj_list);
351}
352
353static acpi_status __init
354early_init_pdc(acpi_handle handle, u32 lvl, void *context, void **rv)
355{
356 if (processor_physically_present(handle) == false)
357 return AE_OK;
358
359 acpi_processor_set_pdc(handle);
360 return AE_OK;
361}
362
363#if defined(CONFIG_X86) || defined(CONFIG_IA64)
364static int __init set_no_mwait(const struct dmi_system_id *id)
365{
366 pr_notice(PREFIX "%s detected - disabling mwait for CPU C-states\n",
367 id->ident);
368 boot_option_idle_override = IDLE_NOMWAIT;
369 return 0;
370}
371
372static struct dmi_system_id processor_idle_dmi_table[] __initdata = {
373 {
374 set_no_mwait, "Extensa 5220", {
375 DMI_MATCH(DMI_BIOS_VENDOR, "Phoenix Technologies LTD"),
376 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
377 DMI_MATCH(DMI_PRODUCT_VERSION, "0100"),
378 DMI_MATCH(DMI_BOARD_NAME, "Columbia") }, NULL},
379 {},
380};
381
382static void __init processor_dmi_check(void)
383{
384 /*
385 * Check whether the system is DMI table. If yes, OSPM
386 * should not use mwait for CPU-states.
387 */
388 dmi_check_system(processor_idle_dmi_table);
389}
390#else
391static inline void processor_dmi_check(void) {}
392#endif
393
394void __init acpi_early_processor_set_pdc(void)
395{
396 processor_dmi_check();
397
398 acpi_walk_namespace(ACPI_TYPE_PROCESSOR, ACPI_ROOT_OBJECT,
399 ACPI_UINT32_MAX,
400 early_init_pdc, NULL, NULL, NULL);
401 acpi_get_devices(ACPI_PROCESSOR_DEVICE_HID, early_init_pdc, NULL, NULL);
402}
diff --git a/drivers/acpi/processor_pdc.c b/drivers/acpi/processor_pdc.c
new file mode 100644
index 000000000000..e5dd80800930
--- /dev/null
+++ b/drivers/acpi/processor_pdc.c
@@ -0,0 +1,206 @@
1/*
2 * Copyright (C) 2005 Intel Corporation
3 * Copyright (C) 2009 Hewlett-Packard Development Company, L.P.
4 *
5 * Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
6 * - Added _PDC for platforms with Intel CPUs
7 */
8
9#define pr_fmt(fmt) "ACPI: " fmt
10
11#include <linux/dmi.h>
12#include <linux/slab.h>
13#include <linux/acpi.h>
14#include <acpi/processor.h>
15
16#include "internal.h"
17
18#define _COMPONENT ACPI_PROCESSOR_COMPONENT
19ACPI_MODULE_NAME("processor_pdc");
20
21static bool __init processor_physically_present(acpi_handle handle)
22{
23 int cpuid, type;
24 u32 acpi_id;
25 acpi_status status;
26 acpi_object_type acpi_type;
27 unsigned long long tmp;
28 union acpi_object object = { 0 };
29 struct acpi_buffer buffer = { sizeof(union acpi_object), &object };
30
31 status = acpi_get_type(handle, &acpi_type);
32 if (ACPI_FAILURE(status))
33 return false;
34
35 switch (acpi_type) {
36 case ACPI_TYPE_PROCESSOR:
37 status = acpi_evaluate_object(handle, NULL, NULL, &buffer);
38 if (ACPI_FAILURE(status))
39 return false;
40 acpi_id = object.processor.proc_id;
41 break;
42 case ACPI_TYPE_DEVICE:
43 status = acpi_evaluate_integer(handle, "_UID", NULL, &tmp);
44 if (ACPI_FAILURE(status))
45 return false;
46 acpi_id = tmp;
47 break;
48 default:
49 return false;
50 }
51
52 type = (acpi_type == ACPI_TYPE_DEVICE) ? 1 : 0;
53 cpuid = acpi_get_cpuid(handle, type, acpi_id);
54
55 if (cpuid == -1)
56 return false;
57
58 return true;
59}
60
61static void acpi_set_pdc_bits(u32 *buf)
62{
63 buf[0] = ACPI_PDC_REVISION_ID;
64 buf[1] = 1;
65
66 /* Enable coordination with firmware's _TSD info */
67 buf[2] = ACPI_PDC_SMP_T_SWCOORD;
68
69 /* Twiddle arch-specific bits needed for _PDC */
70 arch_acpi_set_pdc_bits(buf);
71}
72
73static struct acpi_object_list *acpi_processor_alloc_pdc(void)
74{
75 struct acpi_object_list *obj_list;
76 union acpi_object *obj;
77 u32 *buf;
78
79 /* allocate and initialize pdc. It will be used later. */
80 obj_list = kmalloc(sizeof(struct acpi_object_list), GFP_KERNEL);
81 if (!obj_list)
82 goto out;
83
84 obj = kmalloc(sizeof(union acpi_object), GFP_KERNEL);
85 if (!obj) {
86 kfree(obj_list);
87 goto out;
88 }
89
90 buf = kmalloc(12, GFP_KERNEL);
91 if (!buf) {
92 kfree(obj);
93 kfree(obj_list);
94 goto out;
95 }
96
97 acpi_set_pdc_bits(buf);
98
99 obj->type = ACPI_TYPE_BUFFER;
100 obj->buffer.length = 12;
101 obj->buffer.pointer = (u8 *) buf;
102 obj_list->count = 1;
103 obj_list->pointer = obj;
104
105 return obj_list;
106out:
107 pr_err("Memory allocation error\n");
108 return NULL;
109}
110
111/*
112 * _PDC is required for a BIOS-OS handshake for most of the newer
113 * ACPI processor features.
114 */
115static acpi_status
116acpi_processor_eval_pdc(acpi_handle handle, struct acpi_object_list *pdc_in)
117{
118 acpi_status status = AE_OK;
119
120 if (boot_option_idle_override == IDLE_NOMWAIT) {
121 /*
122 * If mwait is disabled for CPU C-states, the C2C3_FFH access
123 * mode will be disabled in the parameter of _PDC object.
124 * Of course C1_FFH access mode will also be disabled.
125 */
126 union acpi_object *obj;
127 u32 *buffer = NULL;
128
129 obj = pdc_in->pointer;
130 buffer = (u32 *)(obj->buffer.pointer);
131 buffer[2] &= ~(ACPI_PDC_C_C2C3_FFH | ACPI_PDC_C_C1_FFH);
132
133 }
134 status = acpi_evaluate_object(handle, "_PDC", pdc_in, NULL);
135
136 if (ACPI_FAILURE(status))
137 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
138 "Could not evaluate _PDC, using legacy perf. control.\n"));
139
140 return status;
141}
142
143void acpi_processor_set_pdc(acpi_handle handle)
144{
145 struct acpi_object_list *obj_list;
146
147 if (arch_has_acpi_pdc() == false)
148 return;
149
150 obj_list = acpi_processor_alloc_pdc();
151 if (!obj_list)
152 return;
153
154 acpi_processor_eval_pdc(handle, obj_list);
155
156 kfree(obj_list->pointer->buffer.pointer);
157 kfree(obj_list->pointer);
158 kfree(obj_list);
159}
160
161static acpi_status __init
162early_init_pdc(acpi_handle handle, u32 lvl, void *context, void **rv)
163{
164 if (processor_physically_present(handle) == false)
165 return AE_OK;
166
167 acpi_processor_set_pdc(handle);
168 return AE_OK;
169}
170
171static int __init set_no_mwait(const struct dmi_system_id *id)
172{
173 pr_notice("%s detected - disabling mwait for CPU C-states\n",
174 id->ident);
175 boot_option_idle_override = IDLE_NOMWAIT;
176 return 0;
177}
178
179static struct dmi_system_id processor_idle_dmi_table[] __initdata = {
180 {
181 set_no_mwait, "Extensa 5220", {
182 DMI_MATCH(DMI_BIOS_VENDOR, "Phoenix Technologies LTD"),
183 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
184 DMI_MATCH(DMI_PRODUCT_VERSION, "0100"),
185 DMI_MATCH(DMI_BOARD_NAME, "Columbia") }, NULL},
186 {},
187};
188
189static void __init processor_dmi_check(void)
190{
191 /*
192 * Check whether the system is DMI table. If yes, OSPM
193 * should not use mwait for CPU-states.
194 */
195 dmi_check_system(processor_idle_dmi_table);
196}
197
198void __init acpi_early_processor_set_pdc(void)
199{
200 processor_dmi_check();
201
202 acpi_walk_namespace(ACPI_TYPE_PROCESSOR, ACPI_ROOT_OBJECT,
203 ACPI_UINT32_MAX,
204 early_init_pdc, NULL, NULL, NULL);
205 acpi_get_devices(ACPI_PROCESSOR_DEVICE_HID, early_init_pdc, NULL, NULL);
206}
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index f775fa0d850f..5d592e17d760 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -77,7 +77,9 @@ void acpi_initialize_hp_context(struct acpi_device *adev,
77 void (*uevent)(struct acpi_device *, u32)) 77 void (*uevent)(struct acpi_device *, u32))
78{ 78{
79 acpi_lock_hp_context(); 79 acpi_lock_hp_context();
80 acpi_set_hp_context(adev, hp, notify, uevent, NULL); 80 hp->notify = notify;
81 hp->uevent = uevent;
82 acpi_set_hp_context(adev, hp);
81 acpi_unlock_hp_context(); 83 acpi_unlock_hp_context();
82} 84}
83EXPORT_SYMBOL_GPL(acpi_initialize_hp_context); 85EXPORT_SYMBOL_GPL(acpi_initialize_hp_context);
@@ -1421,14 +1423,13 @@ static int acpi_bus_extract_wakeup_device_power_package(acpi_handle handle,
1421 wakeup->sleep_state = sleep_state; 1423 wakeup->sleep_state = sleep_state;
1422 } 1424 }
1423 } 1425 }
1424 acpi_setup_gpe_for_wake(handle, wakeup->gpe_device, wakeup->gpe_number);
1425 1426
1426 out: 1427 out:
1427 kfree(buffer.pointer); 1428 kfree(buffer.pointer);
1428 return err; 1429 return err;
1429} 1430}
1430 1431
1431static void acpi_bus_set_run_wake_flags(struct acpi_device *device) 1432static void acpi_wakeup_gpe_init(struct acpi_device *device)
1432{ 1433{
1433 struct acpi_device_id button_device_ids[] = { 1434 struct acpi_device_id button_device_ids[] = {
1434 {"PNP0C0C", 0}, 1435 {"PNP0C0C", 0},
@@ -1436,29 +1437,33 @@ static void acpi_bus_set_run_wake_flags(struct acpi_device *device)
1436 {"PNP0C0E", 0}, 1437 {"PNP0C0E", 0},
1437 {"", 0}, 1438 {"", 0},
1438 }; 1439 };
1440 struct acpi_device_wakeup *wakeup = &device->wakeup;
1439 acpi_status status; 1441 acpi_status status;
1440 acpi_event_status event_status; 1442 acpi_event_status event_status;
1441 1443
1442 device->wakeup.flags.notifier_present = 0; 1444 wakeup->flags.notifier_present = 0;
1443 1445
1444 /* Power button, Lid switch always enable wakeup */ 1446 /* Power button, Lid switch always enable wakeup */
1445 if (!acpi_match_device_ids(device, button_device_ids)) { 1447 if (!acpi_match_device_ids(device, button_device_ids)) {
1446 device->wakeup.flags.run_wake = 1; 1448 wakeup->flags.run_wake = 1;
1447 if (!acpi_match_device_ids(device, &button_device_ids[1])) { 1449 if (!acpi_match_device_ids(device, &button_device_ids[1])) {
1448 /* Do not use Lid/sleep button for S5 wakeup */ 1450 /* Do not use Lid/sleep button for S5 wakeup */
1449 if (device->wakeup.sleep_state == ACPI_STATE_S5) 1451 if (wakeup->sleep_state == ACPI_STATE_S5)
1450 device->wakeup.sleep_state = ACPI_STATE_S4; 1452 wakeup->sleep_state = ACPI_STATE_S4;
1451 } 1453 }
1454 acpi_mark_gpe_for_wake(wakeup->gpe_device, wakeup->gpe_number);
1452 device_set_wakeup_capable(&device->dev, true); 1455 device_set_wakeup_capable(&device->dev, true);
1453 return; 1456 return;
1454 } 1457 }
1455 1458
1456 status = acpi_get_gpe_status(device->wakeup.gpe_device, 1459 acpi_setup_gpe_for_wake(device->handle, wakeup->gpe_device,
1457 device->wakeup.gpe_number, 1460 wakeup->gpe_number);
1458 &event_status); 1461 status = acpi_get_gpe_status(wakeup->gpe_device, wakeup->gpe_number,
1459 if (status == AE_OK) 1462 &event_status);
1460 device->wakeup.flags.run_wake = 1463 if (ACPI_FAILURE(status))
1461 !!(event_status & ACPI_EVENT_FLAG_HANDLE); 1464 return;
1465
1466 wakeup->flags.run_wake = !!(event_status & ACPI_EVENT_FLAG_HANDLE);
1462} 1467}
1463 1468
1464static void acpi_bus_get_wakeup_device_flags(struct acpi_device *device) 1469static void acpi_bus_get_wakeup_device_flags(struct acpi_device *device)
@@ -1478,7 +1483,7 @@ static void acpi_bus_get_wakeup_device_flags(struct acpi_device *device)
1478 1483
1479 device->wakeup.flags.valid = 1; 1484 device->wakeup.flags.valid = 1;
1480 device->wakeup.prepare_count = 0; 1485 device->wakeup.prepare_count = 0;
1481 acpi_bus_set_run_wake_flags(device); 1486 acpi_wakeup_gpe_init(device);
1482 /* Call _PSW/_DSW object to disable its ability to wake the sleeping 1487 /* Call _PSW/_DSW object to disable its ability to wake the sleeping
1483 * system for the ACPI device with the _PRW object. 1488 * system for the ACPI device with the _PRW object.
1484 * The _PSW object is depreciated in ACPI 3.0 and is replaced by _DSW. 1489 * The _PSW object is depreciated in ACPI 3.0 and is replaced by _DSW.
diff --git a/drivers/acpi/sleep.c b/drivers/acpi/sleep.c
index b3e3cc73ba79..54da4a3fe65e 100644
--- a/drivers/acpi/sleep.c
+++ b/drivers/acpi/sleep.c
@@ -322,6 +322,11 @@ static struct dmi_system_id acpisleep_dmi_table[] __initdata = {
322 322
323static void acpi_sleep_dmi_check(void) 323static void acpi_sleep_dmi_check(void)
324{ 324{
325 int year;
326
327 if (dmi_get_date(DMI_BIOS_DATE, &year, NULL, NULL) && year >= 2012)
328 acpi_nvs_nosave_s3();
329
325 dmi_check_system(acpisleep_dmi_table); 330 dmi_check_system(acpisleep_dmi_table);
326} 331}
327 332
diff --git a/drivers/acpi/video.c b/drivers/acpi/video.c
index 350d52a8f781..826884392e6b 100644
--- a/drivers/acpi/video.c
+++ b/drivers/acpi/video.c
@@ -204,6 +204,8 @@ struct acpi_video_device {
204 struct acpi_video_device_flags flags; 204 struct acpi_video_device_flags flags;
205 struct acpi_video_device_cap cap; 205 struct acpi_video_device_cap cap;
206 struct list_head entry; 206 struct list_head entry;
207 struct delayed_work switch_brightness_work;
208 int switch_brightness_event;
207 struct acpi_video_bus *video; 209 struct acpi_video_bus *video;
208 struct acpi_device *dev; 210 struct acpi_device *dev;
209 struct acpi_video_device_brightness *brightness; 211 struct acpi_video_device_brightness *brightness;
@@ -230,8 +232,7 @@ static int acpi_video_device_lcd_get_level_current(
230 unsigned long long *level, bool raw); 232 unsigned long long *level, bool raw);
231static int acpi_video_get_next_level(struct acpi_video_device *device, 233static int acpi_video_get_next_level(struct acpi_video_device *device,
232 u32 level_current, u32 event); 234 u32 level_current, u32 event);
233static int acpi_video_switch_brightness(struct acpi_video_device *device, 235static void acpi_video_switch_brightness(struct work_struct *work);
234 int event);
235 236
236static bool acpi_video_use_native_backlight(void) 237static bool acpi_video_use_native_backlight(void)
237{ 238{
@@ -275,6 +276,7 @@ static int acpi_video_set_brightness(struct backlight_device *bd)
275 int request_level = bd->props.brightness + 2; 276 int request_level = bd->props.brightness + 2;
276 struct acpi_video_device *vd = bl_get_data(bd); 277 struct acpi_video_device *vd = bl_get_data(bd);
277 278
279 cancel_delayed_work(&vd->switch_brightness_work);
278 return acpi_video_device_lcd_set_level(vd, 280 return acpi_video_device_lcd_set_level(vd,
279 vd->brightness->levels[request_level]); 281 vd->brightness->levels[request_level]);
280} 282}
@@ -461,6 +463,14 @@ static struct dmi_system_id video_dmi_table[] __initdata = {
461 }, 463 },
462 { 464 {
463 .callback = video_set_use_native_backlight, 465 .callback = video_set_use_native_backlight,
466 .ident = "ThinkPad X230",
467 .matches = {
468 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
469 DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad X230"),
470 },
471 },
472 {
473 .callback = video_set_use_native_backlight,
464 .ident = "ThinkPad T430 and T430s", 474 .ident = "ThinkPad T430 and T430s",
465 .matches = { 475 .matches = {
466 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), 476 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
@@ -469,10 +479,42 @@ static struct dmi_system_id video_dmi_table[] __initdata = {
469 }, 479 },
470 { 480 {
471 .callback = video_set_use_native_backlight, 481 .callback = video_set_use_native_backlight,
472 .ident = "ThinkPad X230", 482 .ident = "ThinkPad T430",
473 .matches = { 483 .matches = {
474 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), 484 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
475 DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad X230"), 485 DMI_MATCH(DMI_PRODUCT_VERSION, "2349D15"),
486 },
487 },
488 {
489 .callback = video_set_use_native_backlight,
490 .ident = "ThinkPad T431s",
491 .matches = {
492 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
493 DMI_MATCH(DMI_PRODUCT_VERSION, "20AACTO1WW"),
494 },
495 },
496 {
497 .callback = video_set_use_native_backlight,
498 .ident = "ThinkPad Edge E530",
499 .matches = {
500 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
501 DMI_MATCH(DMI_PRODUCT_VERSION, "3259A2G"),
502 },
503 },
504 {
505 .callback = video_set_use_native_backlight,
506 .ident = "ThinkPad Edge E530",
507 .matches = {
508 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
509 DMI_MATCH(DMI_PRODUCT_VERSION, "3259CTO"),
510 },
511 },
512 {
513 .callback = video_set_use_native_backlight,
514 .ident = "ThinkPad Edge E530",
515 .matches = {
516 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
517 DMI_MATCH(DMI_PRODUCT_VERSION, "3259HJG"),
476 }, 518 },
477 }, 519 },
478 { 520 {
@@ -572,6 +614,30 @@ static struct dmi_system_id video_dmi_table[] __initdata = {
572 }, 614 },
573 }, 615 },
574 { 616 {
617 .callback = video_set_use_native_backlight,
618 .ident = "Acer Aspire V5-572G",
619 .matches = {
620 DMI_MATCH(DMI_SYS_VENDOR, "Acer Aspire"),
621 DMI_MATCH(DMI_PRODUCT_VERSION, "V5-572G/Dazzle_CX"),
622 },
623 },
624 {
625 .callback = video_set_use_native_backlight,
626 .ident = "Acer Aspire V5-573G",
627 .matches = {
628 DMI_MATCH(DMI_SYS_VENDOR, "Acer Aspire"),
629 DMI_MATCH(DMI_PRODUCT_VERSION, "V5-573G/Dazzle_HW"),
630 },
631 },
632 {
633 .callback = video_set_use_native_backlight,
634 .ident = "ASUS Zenbook Prime UX31A",
635 .matches = {
636 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
637 DMI_MATCH(DMI_PRODUCT_NAME, "UX31A"),
638 },
639 },
640 {
575 .callback = video_set_use_native_backlight, 641 .callback = video_set_use_native_backlight,
576 .ident = "HP ProBook 4340s", 642 .ident = "HP ProBook 4340s",
577 .matches = { 643 .matches = {
@@ -607,6 +673,15 @@ static struct dmi_system_id video_dmi_table[] __initdata = {
607 }, 673 },
608 { 674 {
609 .callback = video_set_use_native_backlight, 675 .callback = video_set_use_native_backlight,
676 .ident = "HP EliteBook 2014 models",
677 .matches = {
678 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
679 DMI_MATCH(DMI_PRODUCT_NAME, "HP EliteBook "),
680 DMI_MATCH(DMI_PRODUCT_NAME, " G2"),
681 },
682 },
683 {
684 .callback = video_set_use_native_backlight,
610 .ident = "HP ZBook 14", 685 .ident = "HP ZBook 14",
611 .matches = { 686 .matches = {
612 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"), 687 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
@@ -1188,6 +1263,8 @@ acpi_video_bus_get_one_device(struct acpi_device *device,
1188 data->device_id = device_id; 1263 data->device_id = device_id;
1189 data->video = video; 1264 data->video = video;
1190 data->dev = device; 1265 data->dev = device;
1266 INIT_DELAYED_WORK(&data->switch_brightness_work,
1267 acpi_video_switch_brightness);
1191 1268
1192 attribute = acpi_video_get_device_attr(video, device_id); 1269 attribute = acpi_video_get_device_attr(video, device_id);
1193 1270
@@ -1410,15 +1487,18 @@ acpi_video_get_next_level(struct acpi_video_device *device,
1410 } 1487 }
1411} 1488}
1412 1489
1413static int 1490static void
1414acpi_video_switch_brightness(struct acpi_video_device *device, int event) 1491acpi_video_switch_brightness(struct work_struct *work)
1415{ 1492{
1493 struct acpi_video_device *device = container_of(to_delayed_work(work),
1494 struct acpi_video_device, switch_brightness_work);
1416 unsigned long long level_current, level_next; 1495 unsigned long long level_current, level_next;
1496 int event = device->switch_brightness_event;
1417 int result = -EINVAL; 1497 int result = -EINVAL;
1418 1498
1419 /* no warning message if acpi_backlight=vendor or a quirk is used */ 1499 /* no warning message if acpi_backlight=vendor or a quirk is used */
1420 if (!acpi_video_verify_backlight_support()) 1500 if (!acpi_video_verify_backlight_support())
1421 return 0; 1501 return;
1422 1502
1423 if (!device->brightness) 1503 if (!device->brightness)
1424 goto out; 1504 goto out;
@@ -1440,8 +1520,6 @@ acpi_video_switch_brightness(struct acpi_video_device *device, int event)
1440out: 1520out:
1441 if (result) 1521 if (result)
1442 printk(KERN_ERR PREFIX "Failed to switch the brightness\n"); 1522 printk(KERN_ERR PREFIX "Failed to switch the brightness\n");
1443
1444 return result;
1445} 1523}
1446 1524
1447int acpi_video_get_edid(struct acpi_device *device, int type, int device_id, 1525int acpi_video_get_edid(struct acpi_device *device, int type, int device_id,
@@ -1609,6 +1687,16 @@ static void acpi_video_bus_notify(struct acpi_device *device, u32 event)
1609 return; 1687 return;
1610} 1688}
1611 1689
1690static void brightness_switch_event(struct acpi_video_device *video_device,
1691 u32 event)
1692{
1693 if (!brightness_switch_enabled)
1694 return;
1695
1696 video_device->switch_brightness_event = event;
1697 schedule_delayed_work(&video_device->switch_brightness_work, HZ / 10);
1698}
1699
1612static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data) 1700static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
1613{ 1701{
1614 struct acpi_video_device *video_device = data; 1702 struct acpi_video_device *video_device = data;
@@ -1626,28 +1714,23 @@ static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
1626 1714
1627 switch (event) { 1715 switch (event) {
1628 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */ 1716 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */
1629 if (brightness_switch_enabled) 1717 brightness_switch_event(video_device, event);
1630 acpi_video_switch_brightness(video_device, event);
1631 keycode = KEY_BRIGHTNESS_CYCLE; 1718 keycode = KEY_BRIGHTNESS_CYCLE;
1632 break; 1719 break;
1633 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */ 1720 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */
1634 if (brightness_switch_enabled) 1721 brightness_switch_event(video_device, event);
1635 acpi_video_switch_brightness(video_device, event);
1636 keycode = KEY_BRIGHTNESSUP; 1722 keycode = KEY_BRIGHTNESSUP;
1637 break; 1723 break;
1638 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */ 1724 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */
1639 if (brightness_switch_enabled) 1725 brightness_switch_event(video_device, event);
1640 acpi_video_switch_brightness(video_device, event);
1641 keycode = KEY_BRIGHTNESSDOWN; 1726 keycode = KEY_BRIGHTNESSDOWN;
1642 break; 1727 break;
1643 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightness */ 1728 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightness */
1644 if (brightness_switch_enabled) 1729 brightness_switch_event(video_device, event);
1645 acpi_video_switch_brightness(video_device, event);
1646 keycode = KEY_BRIGHTNESS_ZERO; 1730 keycode = KEY_BRIGHTNESS_ZERO;
1647 break; 1731 break;
1648 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */ 1732 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */
1649 if (brightness_switch_enabled) 1733 brightness_switch_event(video_device, event);
1650 acpi_video_switch_brightness(video_device, event);
1651 keycode = KEY_DISPLAY_OFF; 1734 keycode = KEY_DISPLAY_OFF;
1652 break; 1735 break;
1653 default: 1736 default:
diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
index bf412961a934..b67d9aef9fe4 100644
--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -465,6 +465,7 @@ static void dpm_watchdog_clear(struct dpm_watchdog *wd)
465 * device_resume_noirq - Execute an "early resume" callback for given device. 465 * device_resume_noirq - Execute an "early resume" callback for given device.
466 * @dev: Device to handle. 466 * @dev: Device to handle.
467 * @state: PM transition of the system being carried out. 467 * @state: PM transition of the system being carried out.
468 * @async: If true, the device is being resumed asynchronously.
468 * 469 *
469 * The driver of @dev will not receive interrupts while this function is being 470 * The driver of @dev will not receive interrupts while this function is being
470 * executed. 471 * executed.
@@ -594,6 +595,7 @@ static void dpm_resume_noirq(pm_message_t state)
594 * device_resume_early - Execute an "early resume" callback for given device. 595 * device_resume_early - Execute an "early resume" callback for given device.
595 * @dev: Device to handle. 596 * @dev: Device to handle.
596 * @state: PM transition of the system being carried out. 597 * @state: PM transition of the system being carried out.
598 * @async: If true, the device is being resumed asynchronously.
597 * 599 *
598 * Runtime PM is disabled for @dev while this function is being executed. 600 * Runtime PM is disabled for @dev while this function is being executed.
599 */ 601 */
@@ -1004,6 +1006,7 @@ static pm_message_t resume_event(pm_message_t sleep_state)
1004 * device_suspend_noirq - Execute a "late suspend" callback for given device. 1006 * device_suspend_noirq - Execute a "late suspend" callback for given device.
1005 * @dev: Device to handle. 1007 * @dev: Device to handle.
1006 * @state: PM transition of the system being carried out. 1008 * @state: PM transition of the system being carried out.
1009 * @async: If true, the device is being suspended asynchronously.
1007 * 1010 *
1008 * The driver of @dev will not receive interrupts while this function is being 1011 * The driver of @dev will not receive interrupts while this function is being
1009 * executed. 1012 * executed.
@@ -1144,6 +1147,7 @@ static int dpm_suspend_noirq(pm_message_t state)
1144 * device_suspend_late - Execute a "late suspend" callback for given device. 1147 * device_suspend_late - Execute a "late suspend" callback for given device.
1145 * @dev: Device to handle. 1148 * @dev: Device to handle.
1146 * @state: PM transition of the system being carried out. 1149 * @state: PM transition of the system being carried out.
1150 * @async: If true, the device is being suspended asynchronously.
1147 * 1151 *
1148 * Runtime PM is disabled for @dev while this function is being executed. 1152 * Runtime PM is disabled for @dev while this function is being executed.
1149 */ 1153 */
@@ -1298,6 +1302,7 @@ EXPORT_SYMBOL_GPL(dpm_suspend_end);
1298 * @dev: Device to suspend. 1302 * @dev: Device to suspend.
1299 * @state: PM transition of the system being carried out. 1303 * @state: PM transition of the system being carried out.
1300 * @cb: Suspend callback to execute. 1304 * @cb: Suspend callback to execute.
1305 * @info: string description of caller.
1301 */ 1306 */
1302static int legacy_suspend(struct device *dev, pm_message_t state, 1307static int legacy_suspend(struct device *dev, pm_message_t state,
1303 int (*cb)(struct device *dev, pm_message_t state), 1308 int (*cb)(struct device *dev, pm_message_t state),
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 6f024852c6fb..d9fdeddcef96 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -1076,10 +1076,20 @@ static void cpufreq_policy_free(struct cpufreq_policy *policy)
1076 kfree(policy); 1076 kfree(policy);
1077} 1077}
1078 1078
1079static void update_policy_cpu(struct cpufreq_policy *policy, unsigned int cpu) 1079static int update_policy_cpu(struct cpufreq_policy *policy, unsigned int cpu,
1080 struct device *cpu_dev)
1080{ 1081{
1082 int ret;
1083
1081 if (WARN_ON(cpu == policy->cpu)) 1084 if (WARN_ON(cpu == policy->cpu))
1082 return; 1085 return 0;
1086
1087 /* Move kobject to the new policy->cpu */
1088 ret = kobject_move(&policy->kobj, &cpu_dev->kobj);
1089 if (ret) {
1090 pr_err("%s: Failed to move kobj: %d\n", __func__, ret);
1091 return ret;
1092 }
1083 1093
1084 down_write(&policy->rwsem); 1094 down_write(&policy->rwsem);
1085 1095
@@ -1090,6 +1100,8 @@ static void update_policy_cpu(struct cpufreq_policy *policy, unsigned int cpu)
1090 1100
1091 blocking_notifier_call_chain(&cpufreq_policy_notifier_list, 1101 blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
1092 CPUFREQ_UPDATE_POLICY_CPU, policy); 1102 CPUFREQ_UPDATE_POLICY_CPU, policy);
1103
1104 return 0;
1093} 1105}
1094 1106
1095static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif) 1107static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif)
@@ -1153,12 +1165,10 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif)
1153 * the creation of a brand new one. So we need to perform this update 1165 * the creation of a brand new one. So we need to perform this update
1154 * by invoking update_policy_cpu(). 1166 * by invoking update_policy_cpu().
1155 */ 1167 */
1156 if (recover_policy && cpu != policy->cpu) { 1168 if (recover_policy && cpu != policy->cpu)
1157 update_policy_cpu(policy, cpu); 1169 WARN_ON(update_policy_cpu(policy, cpu, dev));
1158 WARN_ON(kobject_move(&policy->kobj, &dev->kobj)); 1170 else
1159 } else {
1160 policy->cpu = cpu; 1171 policy->cpu = cpu;
1161 }
1162 1172
1163 cpumask_copy(policy->cpus, cpumask_of(cpu)); 1173 cpumask_copy(policy->cpus, cpumask_of(cpu));
1164 1174
@@ -1309,38 +1319,11 @@ static int cpufreq_add_dev(struct device *dev, struct subsys_interface *sif)
1309 return __cpufreq_add_dev(dev, sif); 1319 return __cpufreq_add_dev(dev, sif);
1310} 1320}
1311 1321
1312static int cpufreq_nominate_new_policy_cpu(struct cpufreq_policy *policy,
1313 unsigned int old_cpu)
1314{
1315 struct device *cpu_dev;
1316 int ret;
1317
1318 /* first sibling now owns the new sysfs dir */
1319 cpu_dev = get_cpu_device(cpumask_any_but(policy->cpus, old_cpu));
1320
1321 sysfs_remove_link(&cpu_dev->kobj, "cpufreq");
1322 ret = kobject_move(&policy->kobj, &cpu_dev->kobj);
1323 if (ret) {
1324 pr_err("%s: Failed to move kobj: %d\n", __func__, ret);
1325
1326 down_write(&policy->rwsem);
1327 cpumask_set_cpu(old_cpu, policy->cpus);
1328 up_write(&policy->rwsem);
1329
1330 ret = sysfs_create_link(&cpu_dev->kobj, &policy->kobj,
1331 "cpufreq");
1332
1333 return -EINVAL;
1334 }
1335
1336 return cpu_dev->id;
1337}
1338
1339static int __cpufreq_remove_dev_prepare(struct device *dev, 1322static int __cpufreq_remove_dev_prepare(struct device *dev,
1340 struct subsys_interface *sif) 1323 struct subsys_interface *sif)
1341{ 1324{
1342 unsigned int cpu = dev->id, cpus; 1325 unsigned int cpu = dev->id, cpus;
1343 int new_cpu, ret; 1326 int ret;
1344 unsigned long flags; 1327 unsigned long flags;
1345 struct cpufreq_policy *policy; 1328 struct cpufreq_policy *policy;
1346 1329
@@ -1380,14 +1363,23 @@ static int __cpufreq_remove_dev_prepare(struct device *dev,
1380 if (cpu != policy->cpu) { 1363 if (cpu != policy->cpu) {
1381 sysfs_remove_link(&dev->kobj, "cpufreq"); 1364 sysfs_remove_link(&dev->kobj, "cpufreq");
1382 } else if (cpus > 1) { 1365 } else if (cpus > 1) {
1383 new_cpu = cpufreq_nominate_new_policy_cpu(policy, cpu); 1366 /* Nominate new CPU */
1384 if (new_cpu >= 0) { 1367 int new_cpu = cpumask_any_but(policy->cpus, cpu);
1385 update_policy_cpu(policy, new_cpu); 1368 struct device *cpu_dev = get_cpu_device(new_cpu);
1386 1369
1387 if (!cpufreq_suspended) 1370 sysfs_remove_link(&cpu_dev->kobj, "cpufreq");
1388 pr_debug("%s: policy Kobject moved to cpu: %d from: %d\n", 1371 ret = update_policy_cpu(policy, new_cpu, cpu_dev);
1389 __func__, new_cpu, cpu); 1372 if (ret) {
1373 if (sysfs_create_link(&cpu_dev->kobj, &policy->kobj,
1374 "cpufreq"))
1375 pr_err("%s: Failed to restore kobj link to cpu:%d\n",
1376 __func__, cpu_dev->id);
1377 return ret;
1390 } 1378 }
1379
1380 if (!cpufreq_suspended)
1381 pr_debug("%s: policy Kobject moved to cpu: %d from: %d\n",
1382 __func__, new_cpu, cpu);
1391 } else if (cpufreq_driver->stop_cpu && cpufreq_driver->setpolicy) { 1383 } else if (cpufreq_driver->stop_cpu && cpufreq_driver->setpolicy) {
1392 cpufreq_driver->stop_cpu(policy); 1384 cpufreq_driver->stop_cpu(policy);
1393 } 1385 }
diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
index 18d409189092..ad3f38fd3eb9 100644
--- a/drivers/cpufreq/cpufreq_ondemand.c
+++ b/drivers/cpufreq/cpufreq_ondemand.c
@@ -170,21 +170,24 @@ static void od_check_cpu(int cpu, unsigned int load)
170 dbs_freq_increase(policy, policy->max); 170 dbs_freq_increase(policy, policy->max);
171 } else { 171 } else {
172 /* Calculate the next frequency proportional to load */ 172 /* Calculate the next frequency proportional to load */
173 unsigned int freq_next; 173 unsigned int freq_next, min_f, max_f;
174 freq_next = load * policy->cpuinfo.max_freq / 100; 174
175 min_f = policy->cpuinfo.min_freq;
176 max_f = policy->cpuinfo.max_freq;
177 freq_next = min_f + load * (max_f - min_f) / 100;
175 178
176 /* No longer fully busy, reset rate_mult */ 179 /* No longer fully busy, reset rate_mult */
177 dbs_info->rate_mult = 1; 180 dbs_info->rate_mult = 1;
178 181
179 if (!od_tuners->powersave_bias) { 182 if (!od_tuners->powersave_bias) {
180 __cpufreq_driver_target(policy, freq_next, 183 __cpufreq_driver_target(policy, freq_next,
181 CPUFREQ_RELATION_L); 184 CPUFREQ_RELATION_C);
182 return; 185 return;
183 } 186 }
184 187
185 freq_next = od_ops.powersave_bias_target(policy, freq_next, 188 freq_next = od_ops.powersave_bias_target(policy, freq_next,
186 CPUFREQ_RELATION_L); 189 CPUFREQ_RELATION_L);
187 __cpufreq_driver_target(policy, freq_next, CPUFREQ_RELATION_L); 190 __cpufreq_driver_target(policy, freq_next, CPUFREQ_RELATION_C);
188 } 191 }
189} 192}
190 193
diff --git a/drivers/cpufreq/freq_table.c b/drivers/cpufreq/freq_table.c
index 1632981c4b25..df14766a8e06 100644
--- a/drivers/cpufreq/freq_table.c
+++ b/drivers/cpufreq/freq_table.c
@@ -117,7 +117,7 @@ int cpufreq_frequency_table_target(struct cpufreq_policy *policy,
117 .frequency = 0, 117 .frequency = 0,
118 }; 118 };
119 struct cpufreq_frequency_table *pos; 119 struct cpufreq_frequency_table *pos;
120 unsigned int freq, i = 0; 120 unsigned int freq, diff, i = 0;
121 121
122 pr_debug("request for target %u kHz (relation: %u) for cpu %u\n", 122 pr_debug("request for target %u kHz (relation: %u) for cpu %u\n",
123 target_freq, relation, policy->cpu); 123 target_freq, relation, policy->cpu);
@@ -127,6 +127,7 @@ int cpufreq_frequency_table_target(struct cpufreq_policy *policy,
127 suboptimal.frequency = ~0; 127 suboptimal.frequency = ~0;
128 break; 128 break;
129 case CPUFREQ_RELATION_L: 129 case CPUFREQ_RELATION_L:
130 case CPUFREQ_RELATION_C:
130 optimal.frequency = ~0; 131 optimal.frequency = ~0;
131 break; 132 break;
132 } 133 }
@@ -168,6 +169,15 @@ int cpufreq_frequency_table_target(struct cpufreq_policy *policy,
168 } 169 }
169 } 170 }
170 break; 171 break;
172 case CPUFREQ_RELATION_C:
173 diff = abs(freq - target_freq);
174 if (diff < optimal.frequency ||
175 (diff == optimal.frequency &&
176 freq > table[optimal.driver_data].frequency)) {
177 optimal.frequency = diff;
178 optimal.driver_data = i;
179 }
180 break;
171 } 181 }
172 } 182 }
173 if (optimal.driver_data > i) { 183 if (optimal.driver_data > i) {
diff --git a/drivers/cpufreq/imx6q-cpufreq.c b/drivers/cpufreq/imx6q-cpufreq.c
index af366c21d4b4..c2d30765bf3d 100644
--- a/drivers/cpufreq/imx6q-cpufreq.c
+++ b/drivers/cpufreq/imx6q-cpufreq.c
@@ -66,10 +66,12 @@ static int imx6q_set_target(struct cpufreq_policy *policy, unsigned int index)
66 66
67 /* scaling up? scale voltage before frequency */ 67 /* scaling up? scale voltage before frequency */
68 if (new_freq > old_freq) { 68 if (new_freq > old_freq) {
69 ret = regulator_set_voltage_tol(pu_reg, imx6_soc_volt[index], 0); 69 if (!IS_ERR(pu_reg)) {
70 if (ret) { 70 ret = regulator_set_voltage_tol(pu_reg, imx6_soc_volt[index], 0);
71 dev_err(cpu_dev, "failed to scale vddpu up: %d\n", ret); 71 if (ret) {
72 return ret; 72 dev_err(cpu_dev, "failed to scale vddpu up: %d\n", ret);
73 return ret;
74 }
73 } 75 }
74 ret = regulator_set_voltage_tol(soc_reg, imx6_soc_volt[index], 0); 76 ret = regulator_set_voltage_tol(soc_reg, imx6_soc_volt[index], 0);
75 if (ret) { 77 if (ret) {
@@ -121,10 +123,12 @@ static int imx6q_set_target(struct cpufreq_policy *policy, unsigned int index)
121 dev_warn(cpu_dev, "failed to scale vddsoc down: %d\n", ret); 123 dev_warn(cpu_dev, "failed to scale vddsoc down: %d\n", ret);
122 ret = 0; 124 ret = 0;
123 } 125 }
124 ret = regulator_set_voltage_tol(pu_reg, imx6_soc_volt[index], 0); 126 if (!IS_ERR(pu_reg)) {
125 if (ret) { 127 ret = regulator_set_voltage_tol(pu_reg, imx6_soc_volt[index], 0);
126 dev_warn(cpu_dev, "failed to scale vddpu down: %d\n", ret); 128 if (ret) {
127 ret = 0; 129 dev_warn(cpu_dev, "failed to scale vddpu down: %d\n", ret);
130 ret = 0;
131 }
128 } 132 }
129 } 133 }
130 134
@@ -182,9 +186,9 @@ static int imx6q_cpufreq_probe(struct platform_device *pdev)
182 } 186 }
183 187
184 arm_reg = regulator_get(cpu_dev, "arm"); 188 arm_reg = regulator_get(cpu_dev, "arm");
185 pu_reg = regulator_get(cpu_dev, "pu"); 189 pu_reg = regulator_get_optional(cpu_dev, "pu");
186 soc_reg = regulator_get(cpu_dev, "soc"); 190 soc_reg = regulator_get(cpu_dev, "soc");
187 if (IS_ERR(arm_reg) || IS_ERR(pu_reg) || IS_ERR(soc_reg)) { 191 if (IS_ERR(arm_reg) || IS_ERR(soc_reg)) {
188 dev_err(cpu_dev, "failed to get regulators\n"); 192 dev_err(cpu_dev, "failed to get regulators\n");
189 ret = -ENOENT; 193 ret = -ENOENT;
190 goto put_reg; 194 goto put_reg;
@@ -268,9 +272,11 @@ soc_opp_out:
268 ret = regulator_set_voltage_time(soc_reg, imx6_soc_volt[0], imx6_soc_volt[num - 1]); 272 ret = regulator_set_voltage_time(soc_reg, imx6_soc_volt[0], imx6_soc_volt[num - 1]);
269 if (ret > 0) 273 if (ret > 0)
270 transition_latency += ret * 1000; 274 transition_latency += ret * 1000;
271 ret = regulator_set_voltage_time(pu_reg, imx6_soc_volt[0], imx6_soc_volt[num - 1]); 275 if (!IS_ERR(pu_reg)) {
272 if (ret > 0) 276 ret = regulator_set_voltage_time(pu_reg, imx6_soc_volt[0], imx6_soc_volt[num - 1]);
273 transition_latency += ret * 1000; 277 if (ret > 0)
278 transition_latency += ret * 1000;
279 }
274 280
275 /* 281 /*
276 * OPP is maintained in order of increasing frequency, and 282 * OPP is maintained in order of increasing frequency, and
@@ -327,7 +333,8 @@ static int imx6q_cpufreq_remove(struct platform_device *pdev)
327 cpufreq_unregister_driver(&imx6q_cpufreq_driver); 333 cpufreq_unregister_driver(&imx6q_cpufreq_driver);
328 dev_pm_opp_free_cpufreq_table(cpu_dev, &freq_table); 334 dev_pm_opp_free_cpufreq_table(cpu_dev, &freq_table);
329 regulator_put(arm_reg); 335 regulator_put(arm_reg);
330 regulator_put(pu_reg); 336 if (!IS_ERR(pu_reg))
337 regulator_put(pu_reg);
331 regulator_put(soc_reg); 338 regulator_put(soc_reg);
332 clk_put(arm_clk); 339 clk_put(arm_clk);
333 clk_put(pll1_sys_clk); 340 clk_put(pll1_sys_clk);
diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
index 86631cb6f7de..c5eac949760d 100644
--- a/drivers/cpufreq/intel_pstate.c
+++ b/drivers/cpufreq/intel_pstate.c
@@ -37,7 +37,6 @@
37#define BYT_TURBO_RATIOS 0x66c 37#define BYT_TURBO_RATIOS 0x66c
38#define BYT_TURBO_VIDS 0x66d 38#define BYT_TURBO_VIDS 0x66d
39 39
40
41#define FRAC_BITS 8 40#define FRAC_BITS 8
42#define int_tofp(X) ((int64_t)(X) << FRAC_BITS) 41#define int_tofp(X) ((int64_t)(X) << FRAC_BITS)
43#define fp_toint(X) ((X) >> FRAC_BITS) 42#define fp_toint(X) ((X) >> FRAC_BITS)
@@ -50,7 +49,7 @@ static inline int32_t mul_fp(int32_t x, int32_t y)
50 49
51static inline int32_t div_fp(int32_t x, int32_t y) 50static inline int32_t div_fp(int32_t x, int32_t y)
52{ 51{
53 return div_s64((int64_t)x << FRAC_BITS, (int64_t)y); 52 return div_s64((int64_t)x << FRAC_BITS, y);
54} 53}
55 54
56struct sample { 55struct sample {
@@ -148,7 +147,7 @@ static struct perf_limits limits = {
148}; 147};
149 148
150static inline void pid_reset(struct _pid *pid, int setpoint, int busy, 149static inline void pid_reset(struct _pid *pid, int setpoint, int busy,
151 int deadband, int integral) { 150 int deadband, int integral) {
152 pid->setpoint = setpoint; 151 pid->setpoint = setpoint;
153 pid->deadband = deadband; 152 pid->deadband = deadband;
154 pid->integral = int_tofp(integral); 153 pid->integral = int_tofp(integral);
@@ -167,7 +166,6 @@ static inline void pid_i_gain_set(struct _pid *pid, int percent)
167 166
168static inline void pid_d_gain_set(struct _pid *pid, int percent) 167static inline void pid_d_gain_set(struct _pid *pid, int percent)
169{ 168{
170
171 pid->d_gain = div_fp(int_tofp(percent), int_tofp(100)); 169 pid->d_gain = div_fp(int_tofp(percent), int_tofp(100));
172} 170}
173 171
@@ -207,16 +205,13 @@ static inline void intel_pstate_busy_pid_reset(struct cpudata *cpu)
207 pid_d_gain_set(&cpu->pid, pid_params.d_gain_pct); 205 pid_d_gain_set(&cpu->pid, pid_params.d_gain_pct);
208 pid_i_gain_set(&cpu->pid, pid_params.i_gain_pct); 206 pid_i_gain_set(&cpu->pid, pid_params.i_gain_pct);
209 207
210 pid_reset(&cpu->pid, 208 pid_reset(&cpu->pid, pid_params.setpoint, 100, pid_params.deadband, 0);
211 pid_params.setpoint,
212 100,
213 pid_params.deadband,
214 0);
215} 209}
216 210
217static inline void intel_pstate_reset_all_pid(void) 211static inline void intel_pstate_reset_all_pid(void)
218{ 212{
219 unsigned int cpu; 213 unsigned int cpu;
214
220 for_each_online_cpu(cpu) { 215 for_each_online_cpu(cpu) {
221 if (all_cpu_data[cpu]) 216 if (all_cpu_data[cpu])
222 intel_pstate_busy_pid_reset(all_cpu_data[cpu]); 217 intel_pstate_busy_pid_reset(all_cpu_data[cpu]);
@@ -230,13 +225,13 @@ static int pid_param_set(void *data, u64 val)
230 intel_pstate_reset_all_pid(); 225 intel_pstate_reset_all_pid();
231 return 0; 226 return 0;
232} 227}
228
233static int pid_param_get(void *data, u64 *val) 229static int pid_param_get(void *data, u64 *val)
234{ 230{
235 *val = *(u32 *)data; 231 *val = *(u32 *)data;
236 return 0; 232 return 0;
237} 233}
238DEFINE_SIMPLE_ATTRIBUTE(fops_pid_param, pid_param_get, 234DEFINE_SIMPLE_ATTRIBUTE(fops_pid_param, pid_param_get, pid_param_set, "%llu\n");
239 pid_param_set, "%llu\n");
240 235
241struct pid_param { 236struct pid_param {
242 char *name; 237 char *name;
@@ -253,9 +248,9 @@ static struct pid_param pid_files[] = {
253 {NULL, NULL} 248 {NULL, NULL}
254}; 249};
255 250
256static struct dentry *debugfs_parent; 251static void __init intel_pstate_debug_expose_params(void)
257static void intel_pstate_debug_expose_params(void)
258{ 252{
253 struct dentry *debugfs_parent;
259 int i = 0; 254 int i = 0;
260 255
261 debugfs_parent = debugfs_create_dir("pstate_snb", NULL); 256 debugfs_parent = debugfs_create_dir("pstate_snb", NULL);
@@ -263,8 +258,8 @@ static void intel_pstate_debug_expose_params(void)
263 return; 258 return;
264 while (pid_files[i].name) { 259 while (pid_files[i].name) {
265 debugfs_create_file(pid_files[i].name, 0660, 260 debugfs_create_file(pid_files[i].name, 0660,
266 debugfs_parent, pid_files[i].value, 261 debugfs_parent, pid_files[i].value,
267 &fops_pid_param); 262 &fops_pid_param);
268 i++; 263 i++;
269 } 264 }
270} 265}
@@ -280,10 +275,11 @@ static void intel_pstate_debug_expose_params(void)
280 } 275 }
281 276
282static ssize_t store_no_turbo(struct kobject *a, struct attribute *b, 277static ssize_t store_no_turbo(struct kobject *a, struct attribute *b,
283 const char *buf, size_t count) 278 const char *buf, size_t count)
284{ 279{
285 unsigned int input; 280 unsigned int input;
286 int ret; 281 int ret;
282
287 ret = sscanf(buf, "%u", &input); 283 ret = sscanf(buf, "%u", &input);
288 if (ret != 1) 284 if (ret != 1)
289 return -EINVAL; 285 return -EINVAL;
@@ -296,10 +292,11 @@ static ssize_t store_no_turbo(struct kobject *a, struct attribute *b,
296} 292}
297 293
298static ssize_t store_max_perf_pct(struct kobject *a, struct attribute *b, 294static ssize_t store_max_perf_pct(struct kobject *a, struct attribute *b,
299 const char *buf, size_t count) 295 const char *buf, size_t count)
300{ 296{
301 unsigned int input; 297 unsigned int input;
302 int ret; 298 int ret;
299
303 ret = sscanf(buf, "%u", &input); 300 ret = sscanf(buf, "%u", &input);
304 if (ret != 1) 301 if (ret != 1)
305 return -EINVAL; 302 return -EINVAL;
@@ -307,14 +304,16 @@ static ssize_t store_max_perf_pct(struct kobject *a, struct attribute *b,
307 limits.max_sysfs_pct = clamp_t(int, input, 0 , 100); 304 limits.max_sysfs_pct = clamp_t(int, input, 0 , 100);
308 limits.max_perf_pct = min(limits.max_policy_pct, limits.max_sysfs_pct); 305 limits.max_perf_pct = min(limits.max_policy_pct, limits.max_sysfs_pct);
309 limits.max_perf = div_fp(int_tofp(limits.max_perf_pct), int_tofp(100)); 306 limits.max_perf = div_fp(int_tofp(limits.max_perf_pct), int_tofp(100));
307
310 return count; 308 return count;
311} 309}
312 310
313static ssize_t store_min_perf_pct(struct kobject *a, struct attribute *b, 311static ssize_t store_min_perf_pct(struct kobject *a, struct attribute *b,
314 const char *buf, size_t count) 312 const char *buf, size_t count)
315{ 313{
316 unsigned int input; 314 unsigned int input;
317 int ret; 315 int ret;
316
318 ret = sscanf(buf, "%u", &input); 317 ret = sscanf(buf, "%u", &input);
319 if (ret != 1) 318 if (ret != 1)
320 return -EINVAL; 319 return -EINVAL;
@@ -342,17 +341,16 @@ static struct attribute *intel_pstate_attributes[] = {
342static struct attribute_group intel_pstate_attr_group = { 341static struct attribute_group intel_pstate_attr_group = {
343 .attrs = intel_pstate_attributes, 342 .attrs = intel_pstate_attributes,
344}; 343};
345static struct kobject *intel_pstate_kobject;
346 344
347static void intel_pstate_sysfs_expose_params(void) 345static void __init intel_pstate_sysfs_expose_params(void)
348{ 346{
347 struct kobject *intel_pstate_kobject;
349 int rc; 348 int rc;
350 349
351 intel_pstate_kobject = kobject_create_and_add("intel_pstate", 350 intel_pstate_kobject = kobject_create_and_add("intel_pstate",
352 &cpu_subsys.dev_root->kobj); 351 &cpu_subsys.dev_root->kobj);
353 BUG_ON(!intel_pstate_kobject); 352 BUG_ON(!intel_pstate_kobject);
354 rc = sysfs_create_group(intel_pstate_kobject, 353 rc = sysfs_create_group(intel_pstate_kobject, &intel_pstate_attr_group);
355 &intel_pstate_attr_group);
356 BUG_ON(rc); 354 BUG_ON(rc);
357} 355}
358 356
@@ -360,6 +358,7 @@ static void intel_pstate_sysfs_expose_params(void)
360static int byt_get_min_pstate(void) 358static int byt_get_min_pstate(void)
361{ 359{
362 u64 value; 360 u64 value;
361
363 rdmsrl(BYT_RATIOS, value); 362 rdmsrl(BYT_RATIOS, value);
364 return (value >> 8) & 0x7F; 363 return (value >> 8) & 0x7F;
365} 364}
@@ -367,6 +366,7 @@ static int byt_get_min_pstate(void)
367static int byt_get_max_pstate(void) 366static int byt_get_max_pstate(void)
368{ 367{
369 u64 value; 368 u64 value;
369
370 rdmsrl(BYT_RATIOS, value); 370 rdmsrl(BYT_RATIOS, value);
371 return (value >> 16) & 0x7F; 371 return (value >> 16) & 0x7F;
372} 372}
@@ -374,6 +374,7 @@ static int byt_get_max_pstate(void)
374static int byt_get_turbo_pstate(void) 374static int byt_get_turbo_pstate(void)
375{ 375{
376 u64 value; 376 u64 value;
377
377 rdmsrl(BYT_TURBO_RATIOS, value); 378 rdmsrl(BYT_TURBO_RATIOS, value);
378 return value & 0x7F; 379 return value & 0x7F;
379} 380}
@@ -407,7 +408,6 @@ static void byt_get_vid(struct cpudata *cpudata)
407{ 408{
408 u64 value; 409 u64 value;
409 410
410
411 rdmsrl(BYT_VIDS, value); 411 rdmsrl(BYT_VIDS, value);
412 cpudata->vid.min = int_tofp((value >> 8) & 0x7f); 412 cpudata->vid.min = int_tofp((value >> 8) & 0x7f);
413 cpudata->vid.max = int_tofp((value >> 16) & 0x7f); 413 cpudata->vid.max = int_tofp((value >> 16) & 0x7f);
@@ -420,10 +420,10 @@ static void byt_get_vid(struct cpudata *cpudata)
420 cpudata->vid.turbo = value & 0x7f; 420 cpudata->vid.turbo = value & 0x7f;
421} 421}
422 422
423
424static int core_get_min_pstate(void) 423static int core_get_min_pstate(void)
425{ 424{
426 u64 value; 425 u64 value;
426
427 rdmsrl(MSR_PLATFORM_INFO, value); 427 rdmsrl(MSR_PLATFORM_INFO, value);
428 return (value >> 40) & 0xFF; 428 return (value >> 40) & 0xFF;
429} 429}
@@ -431,6 +431,7 @@ static int core_get_min_pstate(void)
431static int core_get_max_pstate(void) 431static int core_get_max_pstate(void)
432{ 432{
433 u64 value; 433 u64 value;
434
434 rdmsrl(MSR_PLATFORM_INFO, value); 435 rdmsrl(MSR_PLATFORM_INFO, value);
435 return (value >> 8) & 0xFF; 436 return (value >> 8) & 0xFF;
436} 437}
@@ -439,9 +440,10 @@ static int core_get_turbo_pstate(void)
439{ 440{
440 u64 value; 441 u64 value;
441 int nont, ret; 442 int nont, ret;
443
442 rdmsrl(MSR_NHM_TURBO_RATIO_LIMIT, value); 444 rdmsrl(MSR_NHM_TURBO_RATIO_LIMIT, value);
443 nont = core_get_max_pstate(); 445 nont = core_get_max_pstate();
444 ret = ((value) & 255); 446 ret = (value) & 255;
445 if (ret <= nont) 447 if (ret <= nont)
446 ret = nont; 448 ret = nont;
447 return ret; 449 return ret;
@@ -493,12 +495,12 @@ static struct cpu_defaults byt_params = {
493 }, 495 },
494}; 496};
495 497
496
497static void intel_pstate_get_min_max(struct cpudata *cpu, int *min, int *max) 498static void intel_pstate_get_min_max(struct cpudata *cpu, int *min, int *max)
498{ 499{
499 int max_perf = cpu->pstate.turbo_pstate; 500 int max_perf = cpu->pstate.turbo_pstate;
500 int max_perf_adj; 501 int max_perf_adj;
501 int min_perf; 502 int min_perf;
503
502 if (limits.no_turbo) 504 if (limits.no_turbo)
503 max_perf = cpu->pstate.max_pstate; 505 max_perf = cpu->pstate.max_pstate;
504 506
@@ -507,8 +509,7 @@ static void intel_pstate_get_min_max(struct cpudata *cpu, int *min, int *max)
507 cpu->pstate.min_pstate, cpu->pstate.turbo_pstate); 509 cpu->pstate.min_pstate, cpu->pstate.turbo_pstate);
508 510
509 min_perf = fp_toint(mul_fp(int_tofp(max_perf), limits.min_perf)); 511 min_perf = fp_toint(mul_fp(int_tofp(max_perf), limits.min_perf));
510 *min = clamp_t(int, min_perf, 512 *min = clamp_t(int, min_perf, cpu->pstate.min_pstate, max_perf);
511 cpu->pstate.min_pstate, max_perf);
512} 513}
513 514
514static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate) 515static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
@@ -529,21 +530,6 @@ static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
529 pstate_funcs.set(cpu, pstate); 530 pstate_funcs.set(cpu, pstate);
530} 531}
531 532
532static inline void intel_pstate_pstate_increase(struct cpudata *cpu, int steps)
533{
534 int target;
535 target = cpu->pstate.current_pstate + steps;
536
537 intel_pstate_set_pstate(cpu, target);
538}
539
540static inline void intel_pstate_pstate_decrease(struct cpudata *cpu, int steps)
541{
542 int target;
543 target = cpu->pstate.current_pstate - steps;
544 intel_pstate_set_pstate(cpu, target);
545}
546
547static void intel_pstate_get_cpu_pstates(struct cpudata *cpu) 533static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
548{ 534{
549 cpu->pstate.min_pstate = pstate_funcs.get_min(); 535 cpu->pstate.min_pstate = pstate_funcs.get_min();
@@ -559,13 +545,9 @@ static inline void intel_pstate_calc_busy(struct cpudata *cpu)
559{ 545{
560 struct sample *sample = &cpu->sample; 546 struct sample *sample = &cpu->sample;
561 int64_t core_pct; 547 int64_t core_pct;
562 int32_t rem;
563 548
564 core_pct = int_tofp(sample->aperf) * int_tofp(100); 549 core_pct = int_tofp(sample->aperf) * int_tofp(100);
565 core_pct = div_u64_rem(core_pct, int_tofp(sample->mperf), &rem); 550 core_pct = div64_u64(core_pct, int_tofp(sample->mperf));
566
567 if ((rem << 1) >= int_tofp(sample->mperf))
568 core_pct += 1;
569 551
570 sample->freq = fp_toint( 552 sample->freq = fp_toint(
571 mul_fp(int_tofp(cpu->pstate.max_pstate * 1000), core_pct)); 553 mul_fp(int_tofp(cpu->pstate.max_pstate * 1000), core_pct));
@@ -576,12 +558,12 @@ static inline void intel_pstate_calc_busy(struct cpudata *cpu)
576static inline void intel_pstate_sample(struct cpudata *cpu) 558static inline void intel_pstate_sample(struct cpudata *cpu)
577{ 559{
578 u64 aperf, mperf; 560 u64 aperf, mperf;
561 unsigned long flags;
579 562
563 local_irq_save(flags);
580 rdmsrl(MSR_IA32_APERF, aperf); 564 rdmsrl(MSR_IA32_APERF, aperf);
581 rdmsrl(MSR_IA32_MPERF, mperf); 565 rdmsrl(MSR_IA32_MPERF, mperf);
582 566 local_irq_restore(flags);
583 aperf = aperf >> FRAC_BITS;
584 mperf = mperf >> FRAC_BITS;
585 567
586 cpu->last_sample_time = cpu->sample.time; 568 cpu->last_sample_time = cpu->sample.time;
587 cpu->sample.time = ktime_get(); 569 cpu->sample.time = ktime_get();
@@ -598,10 +580,9 @@ static inline void intel_pstate_sample(struct cpudata *cpu)
598 580
599static inline void intel_pstate_set_sample_time(struct cpudata *cpu) 581static inline void intel_pstate_set_sample_time(struct cpudata *cpu)
600{ 582{
601 int sample_time, delay; 583 int delay;
602 584
603 sample_time = pid_params.sample_rate_ms; 585 delay = msecs_to_jiffies(pid_params.sample_rate_ms);
604 delay = msecs_to_jiffies(sample_time);
605 mod_timer_pinned(&cpu->timer, jiffies + delay); 586 mod_timer_pinned(&cpu->timer, jiffies + delay);
606} 587}
607 588
@@ -616,12 +597,12 @@ static inline int32_t intel_pstate_get_scaled_busy(struct cpudata *cpu)
616 current_pstate = int_tofp(cpu->pstate.current_pstate); 597 current_pstate = int_tofp(cpu->pstate.current_pstate);
617 core_busy = mul_fp(core_busy, div_fp(max_pstate, current_pstate)); 598 core_busy = mul_fp(core_busy, div_fp(max_pstate, current_pstate));
618 599
619 sample_time = (pid_params.sample_rate_ms * USEC_PER_MSEC); 600 sample_time = pid_params.sample_rate_ms * USEC_PER_MSEC;
620 duration_us = (u32) ktime_us_delta(cpu->sample.time, 601 duration_us = (u32) ktime_us_delta(cpu->sample.time,
621 cpu->last_sample_time); 602 cpu->last_sample_time);
622 if (duration_us > sample_time * 3) { 603 if (duration_us > sample_time * 3) {
623 sample_ratio = div_fp(int_tofp(sample_time), 604 sample_ratio = div_fp(int_tofp(sample_time),
624 int_tofp(duration_us)); 605 int_tofp(duration_us));
625 core_busy = mul_fp(core_busy, sample_ratio); 606 core_busy = mul_fp(core_busy, sample_ratio);
626 } 607 }
627 608
@@ -632,20 +613,15 @@ static inline void intel_pstate_adjust_busy_pstate(struct cpudata *cpu)
632{ 613{
633 int32_t busy_scaled; 614 int32_t busy_scaled;
634 struct _pid *pid; 615 struct _pid *pid;
635 signed int ctl = 0; 616 signed int ctl;
636 int steps;
637 617
638 pid = &cpu->pid; 618 pid = &cpu->pid;
639 busy_scaled = intel_pstate_get_scaled_busy(cpu); 619 busy_scaled = intel_pstate_get_scaled_busy(cpu);
640 620
641 ctl = pid_calc(pid, busy_scaled); 621 ctl = pid_calc(pid, busy_scaled);
642 622
643 steps = abs(ctl); 623 /* Negative values of ctl increase the pstate and vice versa */
644 624 intel_pstate_set_pstate(cpu, cpu->pstate.current_pstate - ctl);
645 if (ctl < 0)
646 intel_pstate_pstate_increase(cpu, steps);
647 else
648 intel_pstate_pstate_decrease(cpu, steps);
649} 625}
650 626
651static void intel_pstate_timer_func(unsigned long __data) 627static void intel_pstate_timer_func(unsigned long __data)
@@ -705,8 +681,7 @@ static int intel_pstate_init_cpu(unsigned int cpunum)
705 681
706 init_timer_deferrable(&cpu->timer); 682 init_timer_deferrable(&cpu->timer);
707 cpu->timer.function = intel_pstate_timer_func; 683 cpu->timer.function = intel_pstate_timer_func;
708 cpu->timer.data = 684 cpu->timer.data = (unsigned long)cpu;
709 (unsigned long)cpu;
710 cpu->timer.expires = jiffies + HZ/100; 685 cpu->timer.expires = jiffies + HZ/100;
711 intel_pstate_busy_pid_reset(cpu); 686 intel_pstate_busy_pid_reset(cpu);
712 intel_pstate_sample(cpu); 687 intel_pstate_sample(cpu);
@@ -751,7 +726,7 @@ static int intel_pstate_set_policy(struct cpufreq_policy *policy)
751 limits.min_perf_pct = clamp_t(int, limits.min_perf_pct, 0 , 100); 726 limits.min_perf_pct = clamp_t(int, limits.min_perf_pct, 0 , 100);
752 limits.min_perf = div_fp(int_tofp(limits.min_perf_pct), int_tofp(100)); 727 limits.min_perf = div_fp(int_tofp(limits.min_perf_pct), int_tofp(100));
753 728
754 limits.max_policy_pct = policy->max * 100 / policy->cpuinfo.max_freq; 729 limits.max_policy_pct = (policy->max * 100) / policy->cpuinfo.max_freq;
755 limits.max_policy_pct = clamp_t(int, limits.max_policy_pct, 0 , 100); 730 limits.max_policy_pct = clamp_t(int, limits.max_policy_pct, 0 , 100);
756 limits.max_perf_pct = min(limits.max_policy_pct, limits.max_sysfs_pct); 731 limits.max_perf_pct = min(limits.max_policy_pct, limits.max_sysfs_pct);
757 limits.max_perf = div_fp(int_tofp(limits.max_perf_pct), int_tofp(100)); 732 limits.max_perf = div_fp(int_tofp(limits.max_perf_pct), int_tofp(100));
@@ -763,8 +738,8 @@ static int intel_pstate_verify_policy(struct cpufreq_policy *policy)
763{ 738{
764 cpufreq_verify_within_cpu_limits(policy); 739 cpufreq_verify_within_cpu_limits(policy);
765 740
766 if ((policy->policy != CPUFREQ_POLICY_POWERSAVE) && 741 if (policy->policy != CPUFREQ_POLICY_POWERSAVE &&
767 (policy->policy != CPUFREQ_POLICY_PERFORMANCE)) 742 policy->policy != CPUFREQ_POLICY_PERFORMANCE)
768 return -EINVAL; 743 return -EINVAL;
769 744
770 return 0; 745 return 0;
@@ -797,7 +772,7 @@ static int intel_pstate_cpu_init(struct cpufreq_policy *policy)
797 772
798 rdmsrl(MSR_IA32_MISC_ENABLE, misc_en); 773 rdmsrl(MSR_IA32_MISC_ENABLE, misc_en);
799 if (misc_en & MSR_IA32_MISC_ENABLE_TURBO_DISABLE || 774 if (misc_en & MSR_IA32_MISC_ENABLE_TURBO_DISABLE ||
800 cpu->pstate.max_pstate == cpu->pstate.turbo_pstate) { 775 cpu->pstate.max_pstate == cpu->pstate.turbo_pstate) {
801 limits.turbo_disabled = 1; 776 limits.turbo_disabled = 1;
802 limits.no_turbo = 1; 777 limits.no_turbo = 1;
803 } 778 }
@@ -839,8 +814,8 @@ static int intel_pstate_msrs_not_valid(void)
839 rdmsrl(MSR_IA32_MPERF, mperf); 814 rdmsrl(MSR_IA32_MPERF, mperf);
840 815
841 if (!pstate_funcs.get_max() || 816 if (!pstate_funcs.get_max() ||
842 !pstate_funcs.get_min() || 817 !pstate_funcs.get_min() ||
843 !pstate_funcs.get_turbo()) 818 !pstate_funcs.get_turbo())
844 return -ENODEV; 819 return -ENODEV;
845 820
846 rdmsrl(MSR_IA32_APERF, tmp); 821 rdmsrl(MSR_IA32_APERF, tmp);
@@ -922,14 +897,14 @@ static bool intel_pstate_platform_pwr_mgmt_exists(void)
922 struct acpi_table_header hdr; 897 struct acpi_table_header hdr;
923 struct hw_vendor_info *v_info; 898 struct hw_vendor_info *v_info;
924 899
925 if (acpi_disabled 900 if (acpi_disabled ||
926 || ACPI_FAILURE(acpi_get_table_header(ACPI_SIG_FADT, 0, &hdr))) 901 ACPI_FAILURE(acpi_get_table_header(ACPI_SIG_FADT, 0, &hdr)))
927 return false; 902 return false;
928 903
929 for (v_info = vendor_info; v_info->valid; v_info++) { 904 for (v_info = vendor_info; v_info->valid; v_info++) {
930 if (!strncmp(hdr.oem_id, v_info->oem_id, ACPI_OEM_ID_SIZE) 905 if (!strncmp(hdr.oem_id, v_info->oem_id, ACPI_OEM_ID_SIZE) &&
931 && !strncmp(hdr.oem_table_id, v_info->oem_table_id, ACPI_OEM_TABLE_ID_SIZE) 906 !strncmp(hdr.oem_table_id, v_info->oem_table_id, ACPI_OEM_TABLE_ID_SIZE) &&
932 && intel_pstate_no_acpi_pss()) 907 intel_pstate_no_acpi_pss())
933 return true; 908 return true;
934 } 909 }
935 910
diff --git a/drivers/cpufreq/powernow-k6.c b/drivers/cpufreq/powernow-k6.c
index c8012bc86910..f91027259c3c 100644
--- a/drivers/cpufreq/powernow-k6.c
+++ b/drivers/cpufreq/powernow-k6.c
@@ -55,6 +55,7 @@ static const struct {
55 unsigned freq; 55 unsigned freq;
56 unsigned mult; 56 unsigned mult;
57} usual_frequency_table[] = { 57} usual_frequency_table[] = {
58 { 350000, 35 }, // 100 * 3.5
58 { 400000, 40 }, // 100 * 4 59 { 400000, 40 }, // 100 * 4
59 { 450000, 45 }, // 100 * 4.5 60 { 450000, 45 }, // 100 * 4.5
60 { 475000, 50 }, // 95 * 5 61 { 475000, 50 }, // 95 * 5
diff --git a/drivers/cpuidle/Kconfig b/drivers/cpuidle/Kconfig
index 1b96fb91d32c..32748c36c477 100644
--- a/drivers/cpuidle/Kconfig
+++ b/drivers/cpuidle/Kconfig
@@ -15,12 +15,7 @@ config CPU_IDLE
15if CPU_IDLE 15if CPU_IDLE
16 16
17config CPU_IDLE_MULTIPLE_DRIVERS 17config CPU_IDLE_MULTIPLE_DRIVERS
18 bool "Support multiple cpuidle drivers" 18 bool
19 default n
20 help
21 Allows the cpuidle framework to use different drivers for each CPU.
22 This is useful if you have a system with different CPU latencies and
23 states. If unsure say N.
24 19
25config CPU_IDLE_GOV_LADDER 20config CPU_IDLE_GOV_LADDER
26 bool "Ladder governor (for periodic timer tick)" 21 bool "Ladder governor (for periodic timer tick)"
diff --git a/drivers/cpuidle/Kconfig.arm b/drivers/cpuidle/Kconfig.arm
index b6d69e899f5d..a186dec8e5df 100644
--- a/drivers/cpuidle/Kconfig.arm
+++ b/drivers/cpuidle/Kconfig.arm
@@ -10,6 +10,7 @@ config ARM_ARMADA_370_XP_CPUIDLE
10config ARM_BIG_LITTLE_CPUIDLE 10config ARM_BIG_LITTLE_CPUIDLE
11 bool "Support for ARM big.LITTLE processors" 11 bool "Support for ARM big.LITTLE processors"
12 depends on ARCH_VEXPRESS_TC2_PM 12 depends on ARCH_VEXPRESS_TC2_PM
13 depends on MCPM
13 select ARM_CPU_SUSPEND 14 select ARM_CPU_SUSPEND
14 select CPU_IDLE_MULTIPLE_DRIVERS 15 select CPU_IDLE_MULTIPLE_DRIVERS
15 help 16 help
diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
index cb7019977c50..ee9df5e3f5eb 100644
--- a/drivers/cpuidle/cpuidle.c
+++ b/drivers/cpuidle/cpuidle.c
@@ -119,11 +119,13 @@ int cpuidle_enter_state(struct cpuidle_device *dev, struct cpuidle_driver *drv,
119 ktime_t time_start, time_end; 119 ktime_t time_start, time_end;
120 s64 diff; 120 s64 diff;
121 121
122 trace_cpu_idle_rcuidle(index, dev->cpu);
122 time_start = ktime_get(); 123 time_start = ktime_get();
123 124
124 entered_state = target_state->enter(dev, drv, index); 125 entered_state = target_state->enter(dev, drv, index);
125 126
126 time_end = ktime_get(); 127 time_end = ktime_get();
128 trace_cpu_idle_rcuidle(PWR_EVENT_EXIT, dev->cpu);
127 129
128 if (!cpuidle_state_is_coupled(dev, drv, entered_state)) 130 if (!cpuidle_state_is_coupled(dev, drv, entered_state))
129 local_irq_enable(); 131 local_irq_enable();
diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
index 9634f20e3926..e431d11abf8d 100644
--- a/drivers/cpuidle/driver.c
+++ b/drivers/cpuidle/driver.c
@@ -182,10 +182,6 @@ static void __cpuidle_driver_init(struct cpuidle_driver *drv)
182static int poll_idle(struct cpuidle_device *dev, 182static int poll_idle(struct cpuidle_device *dev,
183 struct cpuidle_driver *drv, int index) 183 struct cpuidle_driver *drv, int index)
184{ 184{
185 ktime_t t1, t2;
186 s64 diff;
187
188 t1 = ktime_get();
189 local_irq_enable(); 185 local_irq_enable();
190 if (!current_set_polling_and_test()) { 186 if (!current_set_polling_and_test()) {
191 while (!need_resched()) 187 while (!need_resched())
@@ -193,13 +189,6 @@ static int poll_idle(struct cpuidle_device *dev,
193 } 189 }
194 current_clr_polling(); 190 current_clr_polling();
195 191
196 t2 = ktime_get();
197 diff = ktime_to_us(ktime_sub(t2, t1));
198 if (diff > INT_MAX)
199 diff = INT_MAX;
200
201 dev->last_residency = (int) diff;
202
203 return index; 192 return index;
204} 193}
205 194
diff --git a/drivers/cpuidle/governors/ladder.c b/drivers/cpuidle/governors/ladder.c
index 9f08e8cce1af..044ee0df5871 100644
--- a/drivers/cpuidle/governors/ladder.c
+++ b/drivers/cpuidle/governors/ladder.c
@@ -144,7 +144,7 @@ static int ladder_enable_device(struct cpuidle_driver *drv,
144 144
145 ldev->last_state_idx = CPUIDLE_DRIVER_STATE_START; 145 ldev->last_state_idx = CPUIDLE_DRIVER_STATE_START;
146 146
147 for (i = 0; i < drv->state_count; i++) { 147 for (i = CPUIDLE_DRIVER_STATE_START; i < drv->state_count; i++) {
148 state = &drv->states[i]; 148 state = &drv->states[i];
149 lstate = &ldev->states[i]; 149 lstate = &ldev->states[i];
150 150
@@ -156,7 +156,7 @@ static int ladder_enable_device(struct cpuidle_driver *drv,
156 156
157 if (i < drv->state_count - 1) 157 if (i < drv->state_count - 1)
158 lstate->threshold.promotion_time = state->exit_latency; 158 lstate->threshold.promotion_time = state->exit_latency;
159 if (i > 0) 159 if (i > CPUIDLE_DRIVER_STATE_START)
160 lstate->threshold.demotion_time = state->exit_latency; 160 lstate->threshold.demotion_time = state->exit_latency;
161 } 161 }
162 162
diff --git a/drivers/cpuidle/governors/menu.c b/drivers/cpuidle/governors/menu.c
index c4f80c15a48d..c3732fa74f82 100644
--- a/drivers/cpuidle/governors/menu.c
+++ b/drivers/cpuidle/governors/menu.c
@@ -35,7 +35,6 @@
35#define RESOLUTION 1024 35#define RESOLUTION 1024
36#define DECAY 8 36#define DECAY 8
37#define MAX_INTERESTING 50000 37#define MAX_INTERESTING 50000
38#define STDDEV_THRESH 400
39 38
40 39
41/* 40/*
diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
index efe2f175168f..97c5903b4606 100644
--- a/drivers/cpuidle/sysfs.c
+++ b/drivers/cpuidle/sysfs.c
@@ -445,7 +445,7 @@ static void cpuidle_remove_state_sysfs(struct cpuidle_device *device)
445 445
446#define define_one_driver_ro(_name, show) \ 446#define define_one_driver_ro(_name, show) \
447 static struct cpuidle_driver_attr attr_driver_##_name = \ 447 static struct cpuidle_driver_attr attr_driver_##_name = \
448 __ATTR(_name, 0644, show, NULL) 448 __ATTR(_name, 0444, show, NULL)
449 449
450struct cpuidle_driver_kobj { 450struct cpuidle_driver_kobj {
451 struct cpuidle_driver *drv; 451 struct cpuidle_driver *drv;
diff --git a/drivers/devfreq/Kconfig b/drivers/devfreq/Kconfig
index 49e74c1fc639..3dced0a9eae3 100644
--- a/drivers/devfreq/Kconfig
+++ b/drivers/devfreq/Kconfig
@@ -68,7 +68,6 @@ comment "DEVFREQ Drivers"
68config ARM_EXYNOS4_BUS_DEVFREQ 68config ARM_EXYNOS4_BUS_DEVFREQ
69 bool "ARM Exynos4210/4212/4412 Memory Bus DEVFREQ Driver" 69 bool "ARM Exynos4210/4212/4412 Memory Bus DEVFREQ Driver"
70 depends on (CPU_EXYNOS4210 || SOC_EXYNOS4212 || SOC_EXYNOS4412) && !ARCH_MULTIPLATFORM 70 depends on (CPU_EXYNOS4210 || SOC_EXYNOS4212 || SOC_EXYNOS4412) && !ARCH_MULTIPLATFORM
71 select ARCH_HAS_OPP
72 select DEVFREQ_GOV_SIMPLE_ONDEMAND 71 select DEVFREQ_GOV_SIMPLE_ONDEMAND
73 select PM_OPP 72 select PM_OPP
74 help 73 help
diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
index 437e6fd47311..5b53d6183b6b 100644
--- a/drivers/firmware/efi/cper.c
+++ b/drivers/firmware/efi/cper.c
@@ -344,7 +344,7 @@ static const char * const pcie_port_type_strs[] = {
344}; 344};
345 345
346static void cper_print_pcie(const char *pfx, const struct cper_sec_pcie *pcie, 346static void cper_print_pcie(const char *pfx, const struct cper_sec_pcie *pcie,
347 const struct acpi_generic_data *gdata) 347 const struct acpi_hest_generic_data *gdata)
348{ 348{
349 if (pcie->validation_bits & CPER_PCIE_VALID_PORT_TYPE) 349 if (pcie->validation_bits & CPER_PCIE_VALID_PORT_TYPE)
350 printk("%s""port_type: %d, %s\n", pfx, pcie->port_type, 350 printk("%s""port_type: %d, %s\n", pfx, pcie->port_type,
@@ -380,7 +380,7 @@ static void cper_print_pcie(const char *pfx, const struct cper_sec_pcie *pcie,
380} 380}
381 381
382static void cper_estatus_print_section( 382static void cper_estatus_print_section(
383 const char *pfx, const struct acpi_generic_data *gdata, int sec_no) 383 const char *pfx, const struct acpi_hest_generic_data *gdata, int sec_no)
384{ 384{
385 uuid_le *sec_type = (uuid_le *)gdata->section_type; 385 uuid_le *sec_type = (uuid_le *)gdata->section_type;
386 __u16 severity; 386 __u16 severity;
@@ -426,9 +426,9 @@ err_section_too_small:
426} 426}
427 427
428void cper_estatus_print(const char *pfx, 428void cper_estatus_print(const char *pfx,
429 const struct acpi_generic_status *estatus) 429 const struct acpi_hest_generic_status *estatus)
430{ 430{
431 struct acpi_generic_data *gdata; 431 struct acpi_hest_generic_data *gdata;
432 unsigned int data_len, gedata_len; 432 unsigned int data_len, gedata_len;
433 int sec_no = 0; 433 int sec_no = 0;
434 char newpfx[64]; 434 char newpfx[64];
@@ -441,7 +441,7 @@ void cper_estatus_print(const char *pfx,
441 "and requires no further action"); 441 "and requires no further action");
442 printk("%s""event severity: %s\n", pfx, cper_severity_str(severity)); 442 printk("%s""event severity: %s\n", pfx, cper_severity_str(severity));
443 data_len = estatus->data_length; 443 data_len = estatus->data_length;
444 gdata = (struct acpi_generic_data *)(estatus + 1); 444 gdata = (struct acpi_hest_generic_data *)(estatus + 1);
445 snprintf(newpfx, sizeof(newpfx), "%s%s", pfx, INDENT_SP); 445 snprintf(newpfx, sizeof(newpfx), "%s%s", pfx, INDENT_SP);
446 while (data_len >= sizeof(*gdata)) { 446 while (data_len >= sizeof(*gdata)) {
447 gedata_len = gdata->error_data_length; 447 gedata_len = gdata->error_data_length;
@@ -453,10 +453,10 @@ void cper_estatus_print(const char *pfx,
453} 453}
454EXPORT_SYMBOL_GPL(cper_estatus_print); 454EXPORT_SYMBOL_GPL(cper_estatus_print);
455 455
456int cper_estatus_check_header(const struct acpi_generic_status *estatus) 456int cper_estatus_check_header(const struct acpi_hest_generic_status *estatus)
457{ 457{
458 if (estatus->data_length && 458 if (estatus->data_length &&
459 estatus->data_length < sizeof(struct acpi_generic_data)) 459 estatus->data_length < sizeof(struct acpi_hest_generic_data))
460 return -EINVAL; 460 return -EINVAL;
461 if (estatus->raw_data_length && 461 if (estatus->raw_data_length &&
462 estatus->raw_data_offset < sizeof(*estatus) + estatus->data_length) 462 estatus->raw_data_offset < sizeof(*estatus) + estatus->data_length)
@@ -466,9 +466,9 @@ int cper_estatus_check_header(const struct acpi_generic_status *estatus)
466} 466}
467EXPORT_SYMBOL_GPL(cper_estatus_check_header); 467EXPORT_SYMBOL_GPL(cper_estatus_check_header);
468 468
469int cper_estatus_check(const struct acpi_generic_status *estatus) 469int cper_estatus_check(const struct acpi_hest_generic_status *estatus)
470{ 470{
471 struct acpi_generic_data *gdata; 471 struct acpi_hest_generic_data *gdata;
472 unsigned int data_len, gedata_len; 472 unsigned int data_len, gedata_len;
473 int rc; 473 int rc;
474 474
@@ -476,7 +476,7 @@ int cper_estatus_check(const struct acpi_generic_status *estatus)
476 if (rc) 476 if (rc)
477 return rc; 477 return rc;
478 data_len = estatus->data_length; 478 data_len = estatus->data_length;
479 gdata = (struct acpi_generic_data *)(estatus + 1); 479 gdata = (struct acpi_hest_generic_data *)(estatus + 1);
480 while (data_len >= sizeof(*gdata)) { 480 while (data_len >= sizeof(*gdata)) {
481 gedata_len = gdata->error_data_length; 481 gedata_len = gdata->error_data_length;
482 if (gedata_len > data_len - sizeof(*gdata)) 482 if (gedata_len > data_len - sizeof(*gdata))
diff --git a/drivers/iommu/dmar.c b/drivers/iommu/dmar.c
index 4306885f48b1..60ab474bfff3 100644
--- a/drivers/iommu/dmar.c
+++ b/drivers/iommu/dmar.c
@@ -85,7 +85,7 @@ void *dmar_alloc_dev_scope(void *start, void *end, int *cnt)
85 *cnt = 0; 85 *cnt = 0;
86 while (start < end) { 86 while (start < end) {
87 scope = start; 87 scope = start;
88 if (scope->entry_type == ACPI_DMAR_SCOPE_TYPE_ACPI || 88 if (scope->entry_type == ACPI_DMAR_SCOPE_TYPE_NAMESPACE ||
89 scope->entry_type == ACPI_DMAR_SCOPE_TYPE_ENDPOINT || 89 scope->entry_type == ACPI_DMAR_SCOPE_TYPE_ENDPOINT ||
90 scope->entry_type == ACPI_DMAR_SCOPE_TYPE_BRIDGE) 90 scope->entry_type == ACPI_DMAR_SCOPE_TYPE_BRIDGE)
91 (*cnt)++; 91 (*cnt)++;
@@ -381,7 +381,7 @@ static int __init dmar_parse_one_andd(struct acpi_dmar_header *header)
381 struct acpi_dmar_andd *andd = (void *)header; 381 struct acpi_dmar_andd *andd = (void *)header;
382 382
383 /* Check for NUL termination within the designated length */ 383 /* Check for NUL termination within the designated length */
384 if (strnlen(andd->object_name, header->length - 8) == header->length - 8) { 384 if (strnlen(andd->device_name, header->length - 8) == header->length - 8) {
385 WARN_TAINT(1, TAINT_FIRMWARE_WORKAROUND, 385 WARN_TAINT(1, TAINT_FIRMWARE_WORKAROUND,
386 "Your BIOS is broken; ANDD object name is not NUL-terminated\n" 386 "Your BIOS is broken; ANDD object name is not NUL-terminated\n"
387 "BIOS vendor: %s; Ver: %s; Product Version: %s\n", 387 "BIOS vendor: %s; Ver: %s; Product Version: %s\n",
@@ -391,7 +391,7 @@ static int __init dmar_parse_one_andd(struct acpi_dmar_header *header)
391 return -EINVAL; 391 return -EINVAL;
392 } 392 }
393 pr_info("ANDD device: %x name: %s\n", andd->device_number, 393 pr_info("ANDD device: %x name: %s\n", andd->device_number,
394 andd->object_name); 394 andd->device_name);
395 395
396 return 0; 396 return 0;
397} 397}
@@ -449,17 +449,17 @@ dmar_table_print_dmar_entry(struct acpi_dmar_header *header)
449 (unsigned long long)rmrr->base_address, 449 (unsigned long long)rmrr->base_address,
450 (unsigned long long)rmrr->end_address); 450 (unsigned long long)rmrr->end_address);
451 break; 451 break;
452 case ACPI_DMAR_TYPE_ATSR: 452 case ACPI_DMAR_TYPE_ROOT_ATS:
453 atsr = container_of(header, struct acpi_dmar_atsr, header); 453 atsr = container_of(header, struct acpi_dmar_atsr, header);
454 pr_info("ATSR flags: %#x\n", atsr->flags); 454 pr_info("ATSR flags: %#x\n", atsr->flags);
455 break; 455 break;
456 case ACPI_DMAR_HARDWARE_AFFINITY: 456 case ACPI_DMAR_TYPE_HARDWARE_AFFINITY:
457 rhsa = container_of(header, struct acpi_dmar_rhsa, header); 457 rhsa = container_of(header, struct acpi_dmar_rhsa, header);
458 pr_info("RHSA base: %#016Lx proximity domain: %#x\n", 458 pr_info("RHSA base: %#016Lx proximity domain: %#x\n",
459 (unsigned long long)rhsa->base_address, 459 (unsigned long long)rhsa->base_address,
460 rhsa->proximity_domain); 460 rhsa->proximity_domain);
461 break; 461 break;
462 case ACPI_DMAR_TYPE_ANDD: 462 case ACPI_DMAR_TYPE_NAMESPACE:
463 /* We don't print this here because we need to sanity-check 463 /* We don't print this here because we need to sanity-check
464 it first. So print it in dmar_parse_one_andd() instead. */ 464 it first. So print it in dmar_parse_one_andd() instead. */
465 break; 465 break;
@@ -540,15 +540,15 @@ parse_dmar_table(void)
540 case ACPI_DMAR_TYPE_RESERVED_MEMORY: 540 case ACPI_DMAR_TYPE_RESERVED_MEMORY:
541 ret = dmar_parse_one_rmrr(entry_header); 541 ret = dmar_parse_one_rmrr(entry_header);
542 break; 542 break;
543 case ACPI_DMAR_TYPE_ATSR: 543 case ACPI_DMAR_TYPE_ROOT_ATS:
544 ret = dmar_parse_one_atsr(entry_header); 544 ret = dmar_parse_one_atsr(entry_header);
545 break; 545 break;
546 case ACPI_DMAR_HARDWARE_AFFINITY: 546 case ACPI_DMAR_TYPE_HARDWARE_AFFINITY:
547#ifdef CONFIG_ACPI_NUMA 547#ifdef CONFIG_ACPI_NUMA
548 ret = dmar_parse_one_rhsa(entry_header); 548 ret = dmar_parse_one_rhsa(entry_header);
549#endif 549#endif
550 break; 550 break;
551 case ACPI_DMAR_TYPE_ANDD: 551 case ACPI_DMAR_TYPE_NAMESPACE:
552 ret = dmar_parse_one_andd(entry_header); 552 ret = dmar_parse_one_andd(entry_header);
553 break; 553 break;
554 default: 554 default:
@@ -632,7 +632,7 @@ static void __init dmar_acpi_insert_dev_scope(u8 device_number,
632 for (scope = (void *)(drhd + 1); 632 for (scope = (void *)(drhd + 1);
633 (unsigned long)scope < ((unsigned long)drhd) + drhd->header.length; 633 (unsigned long)scope < ((unsigned long)drhd) + drhd->header.length;
634 scope = ((void *)scope) + scope->length) { 634 scope = ((void *)scope) + scope->length) {
635 if (scope->entry_type != ACPI_DMAR_SCOPE_TYPE_ACPI) 635 if (scope->entry_type != ACPI_DMAR_SCOPE_TYPE_NAMESPACE)
636 continue; 636 continue;
637 if (scope->enumeration_id != device_number) 637 if (scope->enumeration_id != device_number)
638 continue; 638 continue;
@@ -667,21 +667,21 @@ static int __init dmar_acpi_dev_scope_init(void)
667 for (andd = (void *)dmar_tbl + sizeof(struct acpi_table_dmar); 667 for (andd = (void *)dmar_tbl + sizeof(struct acpi_table_dmar);
668 ((unsigned long)andd) < ((unsigned long)dmar_tbl) + dmar_tbl->length; 668 ((unsigned long)andd) < ((unsigned long)dmar_tbl) + dmar_tbl->length;
669 andd = ((void *)andd) + andd->header.length) { 669 andd = ((void *)andd) + andd->header.length) {
670 if (andd->header.type == ACPI_DMAR_TYPE_ANDD) { 670 if (andd->header.type == ACPI_DMAR_TYPE_NAMESPACE) {
671 acpi_handle h; 671 acpi_handle h;
672 struct acpi_device *adev; 672 struct acpi_device *adev;
673 673
674 if (!ACPI_SUCCESS(acpi_get_handle(ACPI_ROOT_OBJECT, 674 if (!ACPI_SUCCESS(acpi_get_handle(ACPI_ROOT_OBJECT,
675 andd->object_name, 675 andd->device_name,
676 &h))) { 676 &h))) {
677 pr_err("Failed to find handle for ACPI object %s\n", 677 pr_err("Failed to find handle for ACPI object %s\n",
678 andd->object_name); 678 andd->device_name);
679 continue; 679 continue;
680 } 680 }
681 acpi_bus_get_device(h, &adev); 681 acpi_bus_get_device(h, &adev);
682 if (!adev) { 682 if (!adev) {
683 pr_err("Failed to get device for ACPI object %s\n", 683 pr_err("Failed to get device for ACPI object %s\n",
684 andd->object_name); 684 andd->device_name);
685 continue; 685 continue;
686 } 686 }
687 dmar_acpi_insert_dev_scope(andd->device_number, adev); 687 dmar_acpi_insert_dev_scope(andd->device_number, adev);
diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c
index 602d153c7055..70741c8c46a0 100644
--- a/drivers/pci/hotplug/acpiphp_glue.c
+++ b/drivers/pci/hotplug/acpiphp_glue.c
@@ -80,8 +80,9 @@ static struct acpiphp_context *acpiphp_init_context(struct acpi_device *adev)
80 return NULL; 80 return NULL;
81 81
82 context->refcount = 1; 82 context->refcount = 1;
83 acpi_set_hp_context(adev, &context->hp, acpiphp_hotplug_notify, NULL, 83 context->hp.notify = acpiphp_hotplug_notify;
84 acpiphp_post_dock_fixup); 84 context->hp.fixup = acpiphp_post_dock_fixup;
85 acpi_set_hp_context(adev, &context->hp);
85 return context; 86 return context;
86} 87}
87 88
@@ -369,20 +370,6 @@ static acpi_status acpiphp_add_context(acpi_handle handle, u32 lvl, void *data,
369 return AE_OK; 370 return AE_OK;
370} 371}
371 372
372static struct acpiphp_bridge *acpiphp_dev_to_bridge(struct acpi_device *adev)
373{
374 struct acpiphp_bridge *bridge = NULL;
375
376 acpi_lock_hp_context();
377 if (adev->hp) {
378 bridge = to_acpiphp_root_context(adev->hp)->root_bridge;
379 if (bridge)
380 get_bridge(bridge);
381 }
382 acpi_unlock_hp_context();
383 return bridge;
384}
385
386static void cleanup_bridge(struct acpiphp_bridge *bridge) 373static void cleanup_bridge(struct acpiphp_bridge *bridge)
387{ 374{
388 struct acpiphp_slot *slot; 375 struct acpiphp_slot *slot;
@@ -753,9 +740,15 @@ static void acpiphp_sanitize_bus(struct pci_bus *bus)
753 740
754void acpiphp_check_host_bridge(struct acpi_device *adev) 741void acpiphp_check_host_bridge(struct acpi_device *adev)
755{ 742{
756 struct acpiphp_bridge *bridge; 743 struct acpiphp_bridge *bridge = NULL;
757 744
758 bridge = acpiphp_dev_to_bridge(adev); 745 acpi_lock_hp_context();
746 if (adev->hp) {
747 bridge = to_acpiphp_root_context(adev->hp)->root_bridge;
748 if (bridge)
749 get_bridge(bridge);
750 }
751 acpi_unlock_hp_context();
759 if (bridge) { 752 if (bridge) {
760 pci_lock_rescan_remove(); 753 pci_lock_rescan_remove();
761 754
@@ -884,7 +877,7 @@ void acpiphp_enumerate_slots(struct pci_bus *bus)
884 goto err; 877 goto err;
885 878
886 root_context->root_bridge = bridge; 879 root_context->root_bridge = bridge;
887 acpi_set_hp_context(adev, &root_context->hp, NULL, NULL, NULL); 880 acpi_set_hp_context(adev, &root_context->hp);
888 } else { 881 } else {
889 struct acpiphp_context *context; 882 struct acpiphp_context *context;
890 883
@@ -927,7 +920,7 @@ void acpiphp_enumerate_slots(struct pci_bus *bus)
927 kfree(bridge); 920 kfree(bridge);
928} 921}
929 922
930void acpiphp_drop_bridge(struct acpiphp_bridge *bridge) 923static void acpiphp_drop_bridge(struct acpiphp_bridge *bridge)
931{ 924{
932 if (pci_is_root_bus(bridge->pci_bus)) { 925 if (pci_is_root_bus(bridge->pci_bus)) {
933 struct acpiphp_root_context *root_context; 926 struct acpiphp_root_context *root_context;
diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c
index ca4927ba8433..37263b0ebfe3 100644
--- a/drivers/pci/pci-acpi.c
+++ b/drivers/pci/pci-acpi.c
@@ -18,31 +18,31 @@
18#include "pci.h" 18#include "pci.h"
19 19
20/** 20/**
21 * pci_acpi_wake_bus - Wake-up notification handler for root buses. 21 * pci_acpi_wake_bus - Root bus wakeup notification fork function.
22 * @handle: ACPI handle of a device the notification is for. 22 * @work: Work item to handle.
23 * @event: Type of the signaled event.
24 * @context: PCI root bus to wake up devices on.
25 */ 23 */
26static void pci_acpi_wake_bus(acpi_handle handle, u32 event, void *context) 24static void pci_acpi_wake_bus(struct work_struct *work)
27{ 25{
28 struct pci_bus *pci_bus = context; 26 struct acpi_device *adev;
27 struct acpi_pci_root *root;
29 28
30 if (event == ACPI_NOTIFY_DEVICE_WAKE && pci_bus) 29 adev = container_of(work, struct acpi_device, wakeup.context.work);
31 pci_pme_wakeup_bus(pci_bus); 30 root = acpi_driver_data(adev);
31 pci_pme_wakeup_bus(root->bus);
32} 32}
33 33
34/** 34/**
35 * pci_acpi_wake_dev - Wake-up notification handler for PCI devices. 35 * pci_acpi_wake_dev - PCI device wakeup notification work function.
36 * @handle: ACPI handle of a device the notification is for. 36 * @handle: ACPI handle of a device the notification is for.
37 * @event: Type of the signaled event. 37 * @work: Work item to handle.
38 * @context: PCI device object to wake up.
39 */ 38 */
40static void pci_acpi_wake_dev(acpi_handle handle, u32 event, void *context) 39static void pci_acpi_wake_dev(struct work_struct *work)
41{ 40{
42 struct pci_dev *pci_dev = context; 41 struct acpi_device_wakeup_context *context;
42 struct pci_dev *pci_dev;
43 43
44 if (event != ACPI_NOTIFY_DEVICE_WAKE || !pci_dev) 44 context = container_of(work, struct acpi_device_wakeup_context, work);
45 return; 45 pci_dev = to_pci_dev(context->dev);
46 46
47 if (pci_dev->pme_poll) 47 if (pci_dev->pme_poll)
48 pci_dev->pme_poll = false; 48 pci_dev->pme_poll = false;
@@ -65,23 +65,12 @@ static void pci_acpi_wake_dev(acpi_handle handle, u32 event, void *context)
65} 65}
66 66
67/** 67/**
68 * pci_acpi_add_bus_pm_notifier - Register PM notifier for given PCI bus. 68 * pci_acpi_add_bus_pm_notifier - Register PM notifier for root PCI bus.
69 * @dev: ACPI device to add the notifier for. 69 * @dev: PCI root bridge ACPI device.
70 * @pci_bus: PCI bus to walk checking for PME status if an event is signaled.
71 */
72acpi_status pci_acpi_add_bus_pm_notifier(struct acpi_device *dev,
73 struct pci_bus *pci_bus)
74{
75 return acpi_add_pm_notifier(dev, pci_acpi_wake_bus, pci_bus);
76}
77
78/**
79 * pci_acpi_remove_bus_pm_notifier - Unregister PCI bus PM notifier.
80 * @dev: ACPI device to remove the notifier from.
81 */ 70 */
82acpi_status pci_acpi_remove_bus_pm_notifier(struct acpi_device *dev) 71acpi_status pci_acpi_add_bus_pm_notifier(struct acpi_device *dev)
83{ 72{
84 return acpi_remove_pm_notifier(dev, pci_acpi_wake_bus); 73 return acpi_add_pm_notifier(dev, NULL, pci_acpi_wake_bus);
85} 74}
86 75
87/** 76/**
@@ -92,16 +81,7 @@ acpi_status pci_acpi_remove_bus_pm_notifier(struct acpi_device *dev)
92acpi_status pci_acpi_add_pm_notifier(struct acpi_device *dev, 81acpi_status pci_acpi_add_pm_notifier(struct acpi_device *dev,
93 struct pci_dev *pci_dev) 82 struct pci_dev *pci_dev)
94{ 83{
95 return acpi_add_pm_notifier(dev, pci_acpi_wake_dev, pci_dev); 84 return acpi_add_pm_notifier(dev, &pci_dev->dev, pci_acpi_wake_dev);
96}
97
98/**
99 * pci_acpi_remove_pm_notifier - Unregister PCI device PM notifier.
100 * @dev: ACPI device to remove the notifier from.
101 */
102acpi_status pci_acpi_remove_pm_notifier(struct acpi_device *dev)
103{
104 return acpi_remove_pm_notifier(dev, pci_acpi_wake_dev);
105} 85}
106 86
107phys_addr_t acpi_pci_root_get_mcfg_addr(acpi_handle handle) 87phys_addr_t acpi_pci_root_get_mcfg_addr(acpi_handle handle)
@@ -170,14 +150,13 @@ static pci_power_t acpi_pci_choose_state(struct pci_dev *pdev)
170 150
171static bool acpi_pci_power_manageable(struct pci_dev *dev) 151static bool acpi_pci_power_manageable(struct pci_dev *dev)
172{ 152{
173 acpi_handle handle = ACPI_HANDLE(&dev->dev); 153 struct acpi_device *adev = ACPI_COMPANION(&dev->dev);
174 154 return adev ? acpi_device_power_manageable(adev) : false;
175 return handle ? acpi_bus_power_manageable(handle) : false;
176} 155}
177 156
178static int acpi_pci_set_power_state(struct pci_dev *dev, pci_power_t state) 157static int acpi_pci_set_power_state(struct pci_dev *dev, pci_power_t state)
179{ 158{
180 acpi_handle handle = ACPI_HANDLE(&dev->dev); 159 struct acpi_device *adev = ACPI_COMPANION(&dev->dev);
181 static const u8 state_conv[] = { 160 static const u8 state_conv[] = {
182 [PCI_D0] = ACPI_STATE_D0, 161 [PCI_D0] = ACPI_STATE_D0,
183 [PCI_D1] = ACPI_STATE_D1, 162 [PCI_D1] = ACPI_STATE_D1,
@@ -188,7 +167,7 @@ static int acpi_pci_set_power_state(struct pci_dev *dev, pci_power_t state)
188 int error = -EINVAL; 167 int error = -EINVAL;
189 168
190 /* If the ACPI device has _EJ0, ignore the device */ 169 /* If the ACPI device has _EJ0, ignore the device */
191 if (!handle || acpi_has_method(handle, "_EJ0")) 170 if (!adev || acpi_has_method(adev->handle, "_EJ0"))
192 return -ENODEV; 171 return -ENODEV;
193 172
194 switch (state) { 173 switch (state) {
@@ -202,7 +181,7 @@ static int acpi_pci_set_power_state(struct pci_dev *dev, pci_power_t state)
202 case PCI_D1: 181 case PCI_D1:
203 case PCI_D2: 182 case PCI_D2:
204 case PCI_D3hot: 183 case PCI_D3hot:
205 error = acpi_bus_set_power(handle, state_conv[state]); 184 error = acpi_device_set_power(adev, state_conv[state]);
206 } 185 }
207 186
208 if (!error) 187 if (!error)
@@ -214,9 +193,8 @@ static int acpi_pci_set_power_state(struct pci_dev *dev, pci_power_t state)
214 193
215static bool acpi_pci_can_wakeup(struct pci_dev *dev) 194static bool acpi_pci_can_wakeup(struct pci_dev *dev)
216{ 195{
217 acpi_handle handle = ACPI_HANDLE(&dev->dev); 196 struct acpi_device *adev = ACPI_COMPANION(&dev->dev);
218 197 return adev ? acpi_device_can_wakeup(adev) : false;
219 return handle ? acpi_bus_can_wakeup(handle) : false;
220} 198}
221 199
222static void acpi_pci_propagate_wakeup_enable(struct pci_bus *bus, bool enable) 200static void acpi_pci_propagate_wakeup_enable(struct pci_bus *bus, bool enable)
diff --git a/drivers/pnp/pnpacpi/core.c b/drivers/pnp/pnpacpi/core.c
index a5c6cb773e5f..d2b780aade89 100644
--- a/drivers/pnp/pnpacpi/core.c
+++ b/drivers/pnp/pnpacpi/core.c
@@ -67,8 +67,8 @@ static int pnpacpi_set_resources(struct pnp_dev *dev)
67 67
68 pnp_dbg(&dev->dev, "set resources\n"); 68 pnp_dbg(&dev->dev, "set resources\n");
69 69
70 handle = ACPI_HANDLE(&dev->dev); 70 acpi_dev = ACPI_COMPANION(&dev->dev);
71 if (!handle || acpi_bus_get_device(handle, &acpi_dev)) { 71 if (!acpi_dev) {
72 dev_dbg(&dev->dev, "ACPI device not found in %s!\n", __func__); 72 dev_dbg(&dev->dev, "ACPI device not found in %s!\n", __func__);
73 return -ENODEV; 73 return -ENODEV;
74 } 74 }
@@ -76,6 +76,7 @@ static int pnpacpi_set_resources(struct pnp_dev *dev)
76 if (WARN_ON_ONCE(acpi_dev != dev->data)) 76 if (WARN_ON_ONCE(acpi_dev != dev->data))
77 dev->data = acpi_dev; 77 dev->data = acpi_dev;
78 78
79 handle = acpi_dev->handle;
79 if (acpi_has_method(handle, METHOD_NAME__SRS)) { 80 if (acpi_has_method(handle, METHOD_NAME__SRS)) {
80 struct acpi_buffer buffer; 81 struct acpi_buffer buffer;
81 82
@@ -93,8 +94,8 @@ static int pnpacpi_set_resources(struct pnp_dev *dev)
93 } 94 }
94 kfree(buffer.pointer); 95 kfree(buffer.pointer);
95 } 96 }
96 if (!ret && acpi_bus_power_manageable(handle)) 97 if (!ret && acpi_device_power_manageable(acpi_dev))
97 ret = acpi_bus_set_power(handle, ACPI_STATE_D0); 98 ret = acpi_device_set_power(acpi_dev, ACPI_STATE_D0);
98 99
99 return ret; 100 return ret;
100} 101}
@@ -102,23 +103,22 @@ static int pnpacpi_set_resources(struct pnp_dev *dev)
102static int pnpacpi_disable_resources(struct pnp_dev *dev) 103static int pnpacpi_disable_resources(struct pnp_dev *dev)
103{ 104{
104 struct acpi_device *acpi_dev; 105 struct acpi_device *acpi_dev;
105 acpi_handle handle;
106 acpi_status status; 106 acpi_status status;
107 107
108 dev_dbg(&dev->dev, "disable resources\n"); 108 dev_dbg(&dev->dev, "disable resources\n");
109 109
110 handle = ACPI_HANDLE(&dev->dev); 110 acpi_dev = ACPI_COMPANION(&dev->dev);
111 if (!handle || acpi_bus_get_device(handle, &acpi_dev)) { 111 if (!acpi_dev) {
112 dev_dbg(&dev->dev, "ACPI device not found in %s!\n", __func__); 112 dev_dbg(&dev->dev, "ACPI device not found in %s!\n", __func__);
113 return 0; 113 return 0;
114 } 114 }
115 115
116 /* acpi_unregister_gsi(pnp_irq(dev, 0)); */ 116 /* acpi_unregister_gsi(pnp_irq(dev, 0)); */
117 if (acpi_bus_power_manageable(handle)) 117 if (acpi_device_power_manageable(acpi_dev))
118 acpi_bus_set_power(handle, ACPI_STATE_D3_COLD); 118 acpi_device_set_power(acpi_dev, ACPI_STATE_D3_COLD);
119 119
120 /* continue even if acpi_bus_set_power() fails */ 120 /* continue even if acpi_device_set_power() fails */
121 status = acpi_evaluate_object(handle, "_DIS", NULL, NULL); 121 status = acpi_evaluate_object(acpi_dev->handle, "_DIS", NULL, NULL);
122 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) 122 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND)
123 return -ENODEV; 123 return -ENODEV;
124 124
@@ -128,26 +128,22 @@ static int pnpacpi_disable_resources(struct pnp_dev *dev)
128#ifdef CONFIG_ACPI_SLEEP 128#ifdef CONFIG_ACPI_SLEEP
129static bool pnpacpi_can_wakeup(struct pnp_dev *dev) 129static bool pnpacpi_can_wakeup(struct pnp_dev *dev)
130{ 130{
131 struct acpi_device *acpi_dev; 131 struct acpi_device *acpi_dev = ACPI_COMPANION(&dev->dev);
132 acpi_handle handle;
133 132
134 handle = ACPI_HANDLE(&dev->dev); 133 if (!acpi_dev) {
135 if (!handle || acpi_bus_get_device(handle, &acpi_dev)) {
136 dev_dbg(&dev->dev, "ACPI device not found in %s!\n", __func__); 134 dev_dbg(&dev->dev, "ACPI device not found in %s!\n", __func__);
137 return false; 135 return false;
138 } 136 }
139 137
140 return acpi_bus_can_wakeup(handle); 138 return acpi_bus_can_wakeup(acpi_dev->handle);
141} 139}
142 140
143static int pnpacpi_suspend(struct pnp_dev *dev, pm_message_t state) 141static int pnpacpi_suspend(struct pnp_dev *dev, pm_message_t state)
144{ 142{
145 struct acpi_device *acpi_dev; 143 struct acpi_device *acpi_dev = ACPI_COMPANION(&dev->dev);
146 acpi_handle handle;
147 int error = 0; 144 int error = 0;
148 145
149 handle = ACPI_HANDLE(&dev->dev); 146 if (!acpi_dev) {
150 if (!handle || acpi_bus_get_device(handle, &acpi_dev)) {
151 dev_dbg(&dev->dev, "ACPI device not found in %s!\n", __func__); 147 dev_dbg(&dev->dev, "ACPI device not found in %s!\n", __func__);
152 return 0; 148 return 0;
153 } 149 }
@@ -159,7 +155,7 @@ static int pnpacpi_suspend(struct pnp_dev *dev, pm_message_t state)
159 return error; 155 return error;
160 } 156 }
161 157
162 if (acpi_bus_power_manageable(handle)) { 158 if (acpi_device_power_manageable(acpi_dev)) {
163 int power_state = acpi_pm_device_sleep_state(&dev->dev, NULL, 159 int power_state = acpi_pm_device_sleep_state(&dev->dev, NULL,
164 ACPI_STATE_D3_COLD); 160 ACPI_STATE_D3_COLD);
165 if (power_state < 0) 161 if (power_state < 0)
@@ -167,12 +163,12 @@ static int pnpacpi_suspend(struct pnp_dev *dev, pm_message_t state)
167 ACPI_STATE_D0 : ACPI_STATE_D3_COLD; 163 ACPI_STATE_D0 : ACPI_STATE_D3_COLD;
168 164
169 /* 165 /*
170 * acpi_bus_set_power() often fails (keyboard port can't be 166 * acpi_device_set_power() can fail (keyboard port can't be
171 * powered-down?), and in any case, our return value is ignored 167 * powered-down?), and in any case, our return value is ignored
172 * by pnp_bus_suspend(). Hence we don't revert the wakeup 168 * by pnp_bus_suspend(). Hence we don't revert the wakeup
173 * setting if the set_power fails. 169 * setting if the set_power fails.
174 */ 170 */
175 error = acpi_bus_set_power(handle, power_state); 171 error = acpi_device_set_power(acpi_dev, power_state);
176 } 172 }
177 173
178 return error; 174 return error;
@@ -180,11 +176,10 @@ static int pnpacpi_suspend(struct pnp_dev *dev, pm_message_t state)
180 176
181static int pnpacpi_resume(struct pnp_dev *dev) 177static int pnpacpi_resume(struct pnp_dev *dev)
182{ 178{
183 struct acpi_device *acpi_dev; 179 struct acpi_device *acpi_dev = ACPI_COMPANION(&dev->dev);
184 acpi_handle handle = ACPI_HANDLE(&dev->dev);
185 int error = 0; 180 int error = 0;
186 181
187 if (!handle || acpi_bus_get_device(handle, &acpi_dev)) { 182 if (!acpi_dev) {
188 dev_dbg(&dev->dev, "ACPI device not found in %s!\n", __func__); 183 dev_dbg(&dev->dev, "ACPI device not found in %s!\n", __func__);
189 return -ENODEV; 184 return -ENODEV;
190 } 185 }
@@ -192,8 +187,8 @@ static int pnpacpi_resume(struct pnp_dev *dev)
192 if (device_may_wakeup(&dev->dev)) 187 if (device_may_wakeup(&dev->dev))
193 acpi_pm_device_sleep_wake(&dev->dev, false); 188 acpi_pm_device_sleep_wake(&dev->dev, false);
194 189
195 if (acpi_bus_power_manageable(handle)) 190 if (acpi_device_power_manageable(acpi_dev))
196 error = acpi_bus_set_power(handle, ACPI_STATE_D0); 191 error = acpi_device_set_power(acpi_dev, ACPI_STATE_D0);
197 192
198 return error; 193 return error;
199} 194}
@@ -295,9 +290,11 @@ static int __init pnpacpi_add_device(struct acpi_device *device)
295 return error; 290 return error;
296 } 291 }
297 292
293 error = acpi_bind_one(&dev->dev, device);
294
298 num++; 295 num++;
299 296
300 return 0; 297 return error;
301} 298}
302 299
303static acpi_status __init pnpacpi_add_device_handler(acpi_handle handle, 300static acpi_status __init pnpacpi_add_device_handler(acpi_handle handle,
@@ -313,40 +310,6 @@ static acpi_status __init pnpacpi_add_device_handler(acpi_handle handle,
313 return AE_OK; 310 return AE_OK;
314} 311}
315 312
316static int __init acpi_pnp_match(struct device *dev, void *_pnp)
317{
318 struct acpi_device *acpi = to_acpi_device(dev);
319 struct pnp_dev *pnp = _pnp;
320
321 /* true means it matched */
322 return pnp->data == acpi;
323}
324
325static struct acpi_device * __init acpi_pnp_find_companion(struct device *dev)
326{
327 dev = bus_find_device(&acpi_bus_type, NULL, to_pnp_dev(dev),
328 acpi_pnp_match);
329 if (!dev)
330 return NULL;
331
332 put_device(dev);
333 return to_acpi_device(dev);
334}
335
336/* complete initialization of a PNPACPI device includes having
337 * pnpdev->dev.archdata.acpi_handle point to its ACPI sibling.
338 */
339static bool acpi_pnp_bus_match(struct device *dev)
340{
341 return dev->bus == &pnp_bus_type;
342}
343
344static struct acpi_bus_type __initdata acpi_pnp_bus = {
345 .name = "PNP",
346 .match = acpi_pnp_bus_match,
347 .find_companion = acpi_pnp_find_companion,
348};
349
350int pnpacpi_disabled __initdata; 313int pnpacpi_disabled __initdata;
351static int __init pnpacpi_init(void) 314static int __init pnpacpi_init(void)
352{ 315{
@@ -356,10 +319,8 @@ static int __init pnpacpi_init(void)
356 } 319 }
357 printk(KERN_INFO "pnp: PnP ACPI init\n"); 320 printk(KERN_INFO "pnp: PnP ACPI init\n");
358 pnp_register_protocol(&pnpacpi_protocol); 321 pnp_register_protocol(&pnpacpi_protocol);
359 register_acpi_bus_type(&acpi_pnp_bus);
360 acpi_get_devices(NULL, pnpacpi_add_device_handler, NULL, NULL); 322 acpi_get_devices(NULL, pnpacpi_add_device_handler, NULL, NULL);
361 printk(KERN_INFO "pnp: PnP ACPI: found %d devices\n", num); 323 printk(KERN_INFO "pnp: PnP ACPI: found %d devices\n", num);
362 unregister_acpi_bus_type(&acpi_pnp_bus);
363 pnp_platform_devices = 1; 324 pnp_platform_devices = 1;
364 return 0; 325 return 0;
365} 326}
diff --git a/include/acpi/acconfig.h b/include/acpi/acconfig.h
index 932a60d6ed82..5a0a3e5daf85 100644
--- a/include/acpi/acconfig.h
+++ b/include/acpi/acconfig.h
@@ -219,6 +219,24 @@
219 219
220/****************************************************************************** 220/******************************************************************************
221 * 221 *
222 * Miscellaneous constants
223 *
224 *****************************************************************************/
225
226/* UUID constants */
227
228#define UUID_BUFFER_LENGTH 16 /* Length of UUID in memory */
229#define UUID_STRING_LENGTH 36 /* Total length of a UUID string */
230
231/* Positions for required hyphens (dashes) in UUID strings */
232
233#define UUID_HYPHEN1_OFFSET 8
234#define UUID_HYPHEN2_OFFSET 13
235#define UUID_HYPHEN3_OFFSET 18
236#define UUID_HYPHEN4_OFFSET 23
237
238/******************************************************************************
239 *
222 * ACPI AML Debugger 240 * ACPI AML Debugger
223 * 241 *
224 *****************************************************************************/ 242 *****************************************************************************/
diff --git a/include/acpi/acnames.h b/include/acpi/acnames.h
index 3dd6e838dc30..c728113374f5 100644
--- a/include/acpi/acnames.h
+++ b/include/acpi/acnames.h
@@ -55,6 +55,7 @@
55#define METHOD_NAME__HID "_HID" 55#define METHOD_NAME__HID "_HID"
56#define METHOD_NAME__INI "_INI" 56#define METHOD_NAME__INI "_INI"
57#define METHOD_NAME__PLD "_PLD" 57#define METHOD_NAME__PLD "_PLD"
58#define METHOD_NAME__DSD "_DSD"
58#define METHOD_NAME__PRS "_PRS" 59#define METHOD_NAME__PRS "_PRS"
59#define METHOD_NAME__PRT "_PRT" 60#define METHOD_NAME__PRT "_PRT"
60#define METHOD_NAME__PRW "_PRW" 61#define METHOD_NAME__PRW "_PRW"
diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
index b5714580801a..bcfd808b1098 100644
--- a/include/acpi/acpi_bus.h
+++ b/include/acpi/acpi_bus.h
@@ -315,12 +315,19 @@ struct acpi_device_wakeup_flags {
315 u8 notifier_present:1; /* Wake-up notify handler has been installed */ 315 u8 notifier_present:1; /* Wake-up notify handler has been installed */
316}; 316};
317 317
318struct acpi_device_wakeup_context {
319 struct work_struct work;
320 struct device *dev;
321};
322
318struct acpi_device_wakeup { 323struct acpi_device_wakeup {
319 acpi_handle gpe_device; 324 acpi_handle gpe_device;
320 u64 gpe_number; 325 u64 gpe_number;
321 u64 sleep_state; 326 u64 sleep_state;
322 struct list_head resources; 327 struct list_head resources;
323 struct acpi_device_wakeup_flags flags; 328 struct acpi_device_wakeup_flags flags;
329 struct acpi_device_wakeup_context context;
330 struct wakeup_source *ws;
324 int prepare_count; 331 int prepare_count;
325}; 332};
326 333
@@ -372,15 +379,9 @@ static inline void acpi_set_device_status(struct acpi_device *adev, u32 sta)
372} 379}
373 380
374static inline void acpi_set_hp_context(struct acpi_device *adev, 381static inline void acpi_set_hp_context(struct acpi_device *adev,
375 struct acpi_hotplug_context *hp, 382 struct acpi_hotplug_context *hp)
376 int (*notify)(struct acpi_device *, u32),
377 void (*uevent)(struct acpi_device *, u32),
378 void (*fixup)(struct acpi_device *))
379{ 383{
380 hp->self = adev; 384 hp->self = adev;
381 hp->notify = notify;
382 hp->uevent = uevent;
383 hp->fixup = fixup;
384 adev->hp = hp; 385 adev->hp = hp;
385} 386}
386 387
@@ -487,6 +488,8 @@ struct acpi_bus_type {
487}; 488};
488int register_acpi_bus_type(struct acpi_bus_type *); 489int register_acpi_bus_type(struct acpi_bus_type *);
489int unregister_acpi_bus_type(struct acpi_bus_type *); 490int unregister_acpi_bus_type(struct acpi_bus_type *);
491int acpi_bind_one(struct device *dev, struct acpi_device *adev);
492int acpi_unbind_one(struct device *dev);
490 493
491struct acpi_pci_root { 494struct acpi_pci_root {
492 struct acpi_device * device; 495 struct acpi_device * device;
@@ -510,20 +513,18 @@ int acpi_enable_wakeup_device_power(struct acpi_device *dev, int state);
510int acpi_disable_wakeup_device_power(struct acpi_device *dev); 513int acpi_disable_wakeup_device_power(struct acpi_device *dev);
511 514
512#ifdef CONFIG_PM 515#ifdef CONFIG_PM
513acpi_status acpi_add_pm_notifier(struct acpi_device *adev, 516acpi_status acpi_add_pm_notifier(struct acpi_device *adev, struct device *dev,
514 acpi_notify_handler handler, void *context); 517 void (*work_func)(struct work_struct *work));
515acpi_status acpi_remove_pm_notifier(struct acpi_device *adev, 518acpi_status acpi_remove_pm_notifier(struct acpi_device *adev);
516 acpi_notify_handler handler);
517int acpi_pm_device_sleep_state(struct device *, int *, int); 519int acpi_pm_device_sleep_state(struct device *, int *, int);
518#else 520#else
519static inline acpi_status acpi_add_pm_notifier(struct acpi_device *adev, 521static inline acpi_status acpi_add_pm_notifier(struct acpi_device *adev,
520 acpi_notify_handler handler, 522 struct device *dev,
521 void *context) 523 void (*work_func)(struct work_struct *work))
522{ 524{
523 return AE_SUPPORT; 525 return AE_SUPPORT;
524} 526}
525static inline acpi_status acpi_remove_pm_notifier(struct acpi_device *adev, 527static inline acpi_status acpi_remove_pm_notifier(struct acpi_device *adev)
526 acpi_notify_handler handler)
527{ 528{
528 return AE_SUPPORT; 529 return AE_SUPPORT;
529} 530}
@@ -538,13 +539,8 @@ static inline int acpi_pm_device_sleep_state(struct device *d, int *p, int m)
538#endif 539#endif
539 540
540#ifdef CONFIG_PM_RUNTIME 541#ifdef CONFIG_PM_RUNTIME
541int __acpi_device_run_wake(struct acpi_device *, bool);
542int acpi_pm_device_run_wake(struct device *, bool); 542int acpi_pm_device_run_wake(struct device *, bool);
543#else 543#else
544static inline int __acpi_device_run_wake(struct acpi_device *adev, bool en)
545{
546 return -ENODEV;
547}
548static inline int acpi_pm_device_run_wake(struct device *dev, bool enable) 544static inline int acpi_pm_device_run_wake(struct device *dev, bool enable)
549{ 545{
550 return -ENODEV; 546 return -ENODEV;
@@ -552,14 +548,8 @@ static inline int acpi_pm_device_run_wake(struct device *dev, bool enable)
552#endif 548#endif
553 549
554#ifdef CONFIG_PM_SLEEP 550#ifdef CONFIG_PM_SLEEP
555int __acpi_device_sleep_wake(struct acpi_device *, u32, bool);
556int acpi_pm_device_sleep_wake(struct device *, bool); 551int acpi_pm_device_sleep_wake(struct device *, bool);
557#else 552#else
558static inline int __acpi_device_sleep_wake(struct acpi_device *adev,
559 u32 target_state, bool enable)
560{
561 return -ENODEV;
562}
563static inline int acpi_pm_device_sleep_wake(struct device *dev, bool enable) 553static inline int acpi_pm_device_sleep_wake(struct device *dev, bool enable)
564{ 554{
565 return -ENODEV; 555 return -ENODEV;
diff --git a/include/acpi/acpiosxf.h b/include/acpi/acpiosxf.h
index f6f5f8af2112..03b3e6d405ff 100644
--- a/include/acpi/acpiosxf.h
+++ b/include/acpi/acpiosxf.h
@@ -399,4 +399,35 @@ char *acpi_os_get_next_filename(void *dir_handle);
399void acpi_os_close_directory(void *dir_handle); 399void acpi_os_close_directory(void *dir_handle);
400#endif 400#endif
401 401
402/*
403 * File I/O and related support
404 */
405#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_open_file
406ACPI_FILE acpi_os_open_file(const char *path, u8 modes);
407#endif
408
409#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_close_file
410void acpi_os_close_file(ACPI_FILE file);
411#endif
412
413#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_read_file
414int
415acpi_os_read_file(ACPI_FILE file,
416 void *buffer, acpi_size size, acpi_size count);
417#endif
418
419#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_write_file
420int
421acpi_os_write_file(ACPI_FILE file,
422 void *buffer, acpi_size size, acpi_size count);
423#endif
424
425#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_get_file_offset
426long acpi_os_get_file_offset(ACPI_FILE file);
427#endif
428
429#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_set_file_offset
430acpi_status acpi_os_set_file_offset(ACPI_FILE file, long offset, u8 from);
431#endif
432
402#endif /* __ACPIOSXF_H__ */ 433#endif /* __ACPIOSXF_H__ */
diff --git a/include/acpi/acpixf.h b/include/acpi/acpixf.h
index 35b525c19711..b7c89d47efbe 100644
--- a/include/acpi/acpixf.h
+++ b/include/acpi/acpixf.h
@@ -46,15 +46,13 @@
46 46
47/* Current ACPICA subsystem version in YYYYMMDD format */ 47/* Current ACPICA subsystem version in YYYYMMDD format */
48 48
49#define ACPI_CA_VERSION 0x20140424 49#define ACPI_CA_VERSION 0x20140724
50 50
51#include <acpi/acconfig.h> 51#include <acpi/acconfig.h>
52#include <acpi/actypes.h> 52#include <acpi/actypes.h>
53#include <acpi/actbl.h> 53#include <acpi/actbl.h>
54#include <acpi/acbuffer.h> 54#include <acpi/acbuffer.h>
55 55
56extern u8 acpi_gbl_permanent_mmap;
57
58/***************************************************************************** 56/*****************************************************************************
59 * 57 *
60 * Macros used for ACPICA globals and configuration 58 * Macros used for ACPICA globals and configuration
@@ -335,6 +333,23 @@ ACPI_GLOBAL(u8, acpi_gbl_system_awake_and_running);
335 333
336#endif /* ACPI_DEBUG_OUTPUT */ 334#endif /* ACPI_DEBUG_OUTPUT */
337 335
336/*
337 * Application prototypes
338 *
339 * All interfaces used by application will be configured
340 * out of the ACPICA build unless the ACPI_APPLICATION
341 * flag is defined.
342 */
343#ifdef ACPI_APPLICATION
344#define ACPI_APP_DEPENDENT_RETURN_VOID(prototype) \
345 prototype;
346
347#else
348#define ACPI_APP_DEPENDENT_RETURN_VOID(prototype) \
349 static ACPI_INLINE prototype {return;}
350
351#endif /* ACPI_APPLICATION */
352
338/***************************************************************************** 353/*****************************************************************************
339 * 354 *
340 * ACPICA public interface prototypes 355 * ACPICA public interface prototypes
@@ -658,6 +673,10 @@ ACPI_HW_DEPENDENT_RETURN_STATUS(acpi_status
658 u32 gpe_number)) 673 u32 gpe_number))
659 674
660ACPI_HW_DEPENDENT_RETURN_STATUS(acpi_status 675ACPI_HW_DEPENDENT_RETURN_STATUS(acpi_status
676 acpi_mark_gpe_for_wake(acpi_handle gpe_device,
677 u32 gpe_number))
678
679ACPI_HW_DEPENDENT_RETURN_STATUS(acpi_status
661 acpi_setup_gpe_for_wake(acpi_handle 680 acpi_setup_gpe_for_wake(acpi_handle
662 parent_device, 681 parent_device,
663 acpi_handle gpe_device, 682 acpi_handle gpe_device,
@@ -861,21 +880,32 @@ ACPI_DBG_DEPENDENT_RETURN_VOID(ACPI_PRINTF_LIKE(6)
861 const char *module_name, 880 const char *module_name,
862 u32 component_id, 881 u32 component_id,
863 const char *format, ...)) 882 const char *format, ...))
883ACPI_APP_DEPENDENT_RETURN_VOID(ACPI_PRINTF_LIKE(1)
884 void ACPI_INTERNAL_VAR_XFACE
885 acpi_log_error(const char *format, ...))
864 886
865/* 887/*
866 * Divergences 888 * Divergences
867 */ 889 */
868acpi_status acpi_get_id(acpi_handle object, acpi_owner_id * out_type); 890ACPI_GLOBAL(u8, acpi_gbl_permanent_mmap);
869 891
870acpi_status acpi_unload_table_id(acpi_owner_id id); 892ACPI_EXTERNAL_RETURN_STATUS(acpi_status
893 acpi_get_id(acpi_handle object,
894 acpi_owner_id * out_type))
871 895
872acpi_status 896ACPI_EXTERNAL_RETURN_STATUS(acpi_status acpi_unload_table_id(acpi_owner_id id))
873acpi_get_table_with_size(acpi_string signature,
874 u32 instance, struct acpi_table_header **out_table,
875 acpi_size *tbl_size);
876 897
877acpi_status 898ACPI_EXTERNAL_RETURN_STATUS(acpi_status
878acpi_get_data_full(acpi_handle object, acpi_object_handler handler, void **data, 899 acpi_get_table_with_size(acpi_string signature,
879 void (*callback)(void *)); 900 u32 instance,
901 struct acpi_table_header
902 **out_table,
903 acpi_size *tbl_size))
904
905ACPI_EXTERNAL_RETURN_STATUS(acpi_status
906 acpi_get_data_full(acpi_handle object,
907 acpi_object_handler handler,
908 void **data,
909 void (*callback)(void *)))
880 910
881#endif /* __ACXFACE_H__ */ 911#endif /* __ACXFACE_H__ */
diff --git a/include/acpi/actbl.h b/include/acpi/actbl.h
index 1cc7ef13c01a..bee19d8170c5 100644
--- a/include/acpi/actbl.h
+++ b/include/acpi/actbl.h
@@ -270,7 +270,8 @@ struct acpi_table_fadt {
270 u32 flags; /* Miscellaneous flag bits (see below for individual flags) */ 270 u32 flags; /* Miscellaneous flag bits (see below for individual flags) */
271 struct acpi_generic_address reset_register; /* 64-bit address of the Reset register */ 271 struct acpi_generic_address reset_register; /* 64-bit address of the Reset register */
272 u8 reset_value; /* Value to write to the reset_register port to reset the system */ 272 u8 reset_value; /* Value to write to the reset_register port to reset the system */
273 u8 reserved4[3]; /* Reserved, must be zero */ 273 u16 arm_boot_flags; /* ARM-Specific Boot Flags (see below for individual flags) (ACPI 5.1) */
274 u8 minor_revision; /* FADT Minor Revision (ACPI 5.1) */
274 u64 Xfacs; /* 64-bit physical address of FACS */ 275 u64 Xfacs; /* 64-bit physical address of FACS */
275 u64 Xdsdt; /* 64-bit physical address of DSDT */ 276 u64 Xdsdt; /* 64-bit physical address of DSDT */
276 struct acpi_generic_address xpm1a_event_block; /* 64-bit Extended Power Mgt 1a Event Reg Blk address */ 277 struct acpi_generic_address xpm1a_event_block; /* 64-bit Extended Power Mgt 1a Event Reg Blk address */
@@ -285,7 +286,7 @@ struct acpi_table_fadt {
285 struct acpi_generic_address sleep_status; /* 64-bit Sleep Status register (ACPI 5.0) */ 286 struct acpi_generic_address sleep_status; /* 64-bit Sleep Status register (ACPI 5.0) */
286}; 287};
287 288
288/* Masks for FADT Boot Architecture Flags (boot_flags) [Vx]=Introduced in this FADT revision */ 289/* Masks for FADT IA-PC Boot Architecture Flags (boot_flags) [Vx]=Introduced in this FADT revision */
289 290
290#define ACPI_FADT_LEGACY_DEVICES (1) /* 00: [V2] System has LPC or ISA bus devices */ 291#define ACPI_FADT_LEGACY_DEVICES (1) /* 00: [V2] System has LPC or ISA bus devices */
291#define ACPI_FADT_8042 (1<<1) /* 01: [V3] System has an 8042 controller on port 60/64 */ 292#define ACPI_FADT_8042 (1<<1) /* 01: [V3] System has an 8042 controller on port 60/64 */
@@ -296,6 +297,11 @@ struct acpi_table_fadt {
296 297
297#define FADT2_REVISION_ID 3 298#define FADT2_REVISION_ID 3
298 299
300/* Masks for FADT ARM Boot Architecture Flags (arm_boot_flags) ACPI 5.1 */
301
302#define ACPI_FADT_PSCI_COMPLIANT (1) /* 00: [V5+] PSCI 0.2+ is implemented */
303#define ACPI_FADT_PSCI_USE_HVC (1<<1) /* 01: [V5+] HVC must be used instead of SMC as the PSCI conduit */
304
299/* Masks for FADT flags */ 305/* Masks for FADT flags */
300 306
301#define ACPI_FADT_WBINVD (1) /* 00: [V1] The WBINVD instruction works properly */ 307#define ACPI_FADT_WBINVD (1) /* 00: [V1] The WBINVD instruction works properly */
@@ -399,7 +405,7 @@ struct acpi_table_desc {
399 * FADT V5 size: 0x10C 405 * FADT V5 size: 0x10C
400 */ 406 */
401#define ACPI_FADT_V1_SIZE (u32) (ACPI_FADT_OFFSET (flags) + 4) 407#define ACPI_FADT_V1_SIZE (u32) (ACPI_FADT_OFFSET (flags) + 4)
402#define ACPI_FADT_V2_SIZE (u32) (ACPI_FADT_OFFSET (reserved4[0]) + 3) 408#define ACPI_FADT_V2_SIZE (u32) (ACPI_FADT_OFFSET (minor_revision) + 1)
403#define ACPI_FADT_V3_SIZE (u32) (ACPI_FADT_OFFSET (sleep_control)) 409#define ACPI_FADT_V3_SIZE (u32) (ACPI_FADT_OFFSET (sleep_control))
404#define ACPI_FADT_V5_SIZE (u32) (sizeof (struct acpi_table_fadt)) 410#define ACPI_FADT_V5_SIZE (u32) (sizeof (struct acpi_table_fadt))
405 411
diff --git a/include/acpi/actbl1.h b/include/acpi/actbl1.h
index 4ad7da805180..7626bfeac2cb 100644
--- a/include/acpi/actbl1.h
+++ b/include/acpi/actbl1.h
@@ -604,7 +604,7 @@ struct acpi_hest_generic {
604 604
605/* Generic Error Status block */ 605/* Generic Error Status block */
606 606
607struct acpi_generic_status { 607struct acpi_hest_generic_status {
608 u32 block_status; 608 u32 block_status;
609 u32 raw_data_offset; 609 u32 raw_data_offset;
610 u32 raw_data_length; 610 u32 raw_data_length;
@@ -614,15 +614,15 @@ struct acpi_generic_status {
614 614
615/* Values for block_status flags above */ 615/* Values for block_status flags above */
616 616
617#define ACPI_GEN_ERR_UC BIT(0) 617#define ACPI_HEST_UNCORRECTABLE (1)
618#define ACPI_GEN_ERR_CE BIT(1) 618#define ACPI_HEST_CORRECTABLE (1<<1)
619#define ACPI_GEN_ERR_MULTI_UC BIT(2) 619#define ACPI_HEST_MULTIPLE_UNCORRECTABLE (1<<2)
620#define ACPI_GEN_ERR_MULTI_CE BIT(3) 620#define ACPI_HEST_MULTIPLE_CORRECTABLE (1<<3)
621#define ACPI_GEN_ERR_COUNT_SHIFT (0xFF<<4) /* 8 bits, error count */ 621#define ACPI_HEST_ERROR_ENTRY_COUNT (0xFF<<4) /* 8 bits, error count */
622 622
623/* Generic Error Data entry */ 623/* Generic Error Data entry */
624 624
625struct acpi_generic_data { 625struct acpi_hest_generic_data {
626 u8 section_type[16]; 626 u8 section_type[16];
627 u32 error_severity; 627 u32 error_severity;
628 u16 revision; 628 u16 revision;
@@ -671,7 +671,9 @@ enum acpi_madt_type {
671 ACPI_MADT_TYPE_LOCAL_X2APIC_NMI = 10, 671 ACPI_MADT_TYPE_LOCAL_X2APIC_NMI = 10,
672 ACPI_MADT_TYPE_GENERIC_INTERRUPT = 11, 672 ACPI_MADT_TYPE_GENERIC_INTERRUPT = 11,
673 ACPI_MADT_TYPE_GENERIC_DISTRIBUTOR = 12, 673 ACPI_MADT_TYPE_GENERIC_DISTRIBUTOR = 12,
674 ACPI_MADT_TYPE_RESERVED = 13 /* 13 and greater are reserved */ 674 ACPI_MADT_TYPE_GENERIC_MSI_FRAME = 13,
675 ACPI_MADT_TYPE_GENERIC_REDISTRIBUTOR = 14,
676 ACPI_MADT_TYPE_RESERVED = 15 /* 15 and greater are reserved */
675}; 677};
676 678
677/* 679/*
@@ -797,15 +799,26 @@ struct acpi_madt_local_x2apic_nmi {
797struct acpi_madt_generic_interrupt { 799struct acpi_madt_generic_interrupt {
798 struct acpi_subtable_header header; 800 struct acpi_subtable_header header;
799 u16 reserved; /* reserved - must be zero */ 801 u16 reserved; /* reserved - must be zero */
800 u32 gic_id; 802 u32 cpu_interface_number;
801 u32 uid; 803 u32 uid;
802 u32 flags; 804 u32 flags;
803 u32 parking_version; 805 u32 parking_version;
804 u32 performance_interrupt; 806 u32 performance_interrupt;
805 u64 parked_address; 807 u64 parked_address;
806 u64 base_address; 808 u64 base_address;
809 u64 gicv_base_address;
810 u64 gich_base_address;
811 u32 vgic_interrupt;
812 u64 gicr_base_address;
813 u64 arm_mpidr;
807}; 814};
808 815
816/* Masks for Flags field above */
817
818/* ACPI_MADT_ENABLED (1) Processor is usable if set */
819#define ACPI_MADT_PERFORMANCE_IRQ_MODE (1<<1) /* 01: Performance Interrupt Mode */
820#define ACPI_MADT_VGIC_IRQ_MODE (1<<2) /* 02: VGIC Maintenance Interrupt mode */
821
809/* 12: Generic Distributor (ACPI 5.0) */ 822/* 12: Generic Distributor (ACPI 5.0) */
810 823
811struct acpi_madt_generic_distributor { 824struct acpi_madt_generic_distributor {
@@ -817,11 +830,36 @@ struct acpi_madt_generic_distributor {
817 u32 reserved2; /* reserved - must be zero */ 830 u32 reserved2; /* reserved - must be zero */
818}; 831};
819 832
833/* 13: Generic MSI Frame (ACPI 5.1) */
834
835struct acpi_madt_generic_msi_frame {
836 struct acpi_subtable_header header;
837 u16 reserved; /* reserved - must be zero */
838 u32 msi_frame_id;
839 u64 base_address;
840 u32 flags;
841 u16 spi_count;
842 u16 spi_base;
843};
844
845/* Masks for Flags field above */
846
847#define ACPI_MADT_OVERRIDE_SPI_VALUES (1)
848
849/* 14: Generic Redistributor (ACPI 5.1) */
850
851struct acpi_madt_generic_redistributor {
852 struct acpi_subtable_header header;
853 u16 reserved; /* reserved - must be zero */
854 u64 base_address;
855 u32 length;
856};
857
820/* 858/*
821 * Common flags fields for MADT subtables 859 * Common flags fields for MADT subtables
822 */ 860 */
823 861
824/* MADT Local APIC flags (lapic_flags) and GIC flags */ 862/* MADT Local APIC flags */
825 863
826#define ACPI_MADT_ENABLED (1) /* 00: Processor is usable if set */ 864#define ACPI_MADT_ENABLED (1) /* 00: Processor is usable if set */
827 865
diff --git a/include/acpi/actbl2.h b/include/acpi/actbl2.h
index 860e5c883eb3..ecff62405f17 100644
--- a/include/acpi/actbl2.h
+++ b/include/acpi/actbl2.h
@@ -396,7 +396,7 @@ struct acpi_table_dbgp {
396 * Version 1 396 * Version 1
397 * 397 *
398 * Conforms to "Intel Virtualization Technology for Directed I/O", 398 * Conforms to "Intel Virtualization Technology for Directed I/O",
399 * Version 1.2, Sept. 2008 399 * Version 2.2, Sept. 2013
400 * 400 *
401 ******************************************************************************/ 401 ******************************************************************************/
402 402
@@ -423,9 +423,9 @@ struct acpi_dmar_header {
423enum acpi_dmar_type { 423enum acpi_dmar_type {
424 ACPI_DMAR_TYPE_HARDWARE_UNIT = 0, 424 ACPI_DMAR_TYPE_HARDWARE_UNIT = 0,
425 ACPI_DMAR_TYPE_RESERVED_MEMORY = 1, 425 ACPI_DMAR_TYPE_RESERVED_MEMORY = 1,
426 ACPI_DMAR_TYPE_ATSR = 2, 426 ACPI_DMAR_TYPE_ROOT_ATS = 2,
427 ACPI_DMAR_HARDWARE_AFFINITY = 3, 427 ACPI_DMAR_TYPE_HARDWARE_AFFINITY = 3,
428 ACPI_DMAR_TYPE_ANDD = 4, 428 ACPI_DMAR_TYPE_NAMESPACE = 4,
429 ACPI_DMAR_TYPE_RESERVED = 5 /* 5 and greater are reserved */ 429 ACPI_DMAR_TYPE_RESERVED = 5 /* 5 and greater are reserved */
430}; 430};
431 431
@@ -439,7 +439,7 @@ struct acpi_dmar_device_scope {
439 u8 bus; 439 u8 bus;
440}; 440};
441 441
442/* Values for entry_type in struct acpi_dmar_device_scope */ 442/* Values for entry_type in struct acpi_dmar_device_scope - device types */
443 443
444enum acpi_dmar_scope_type { 444enum acpi_dmar_scope_type {
445 ACPI_DMAR_SCOPE_TYPE_NOT_USED = 0, 445 ACPI_DMAR_SCOPE_TYPE_NOT_USED = 0,
@@ -447,7 +447,7 @@ enum acpi_dmar_scope_type {
447 ACPI_DMAR_SCOPE_TYPE_BRIDGE = 2, 447 ACPI_DMAR_SCOPE_TYPE_BRIDGE = 2,
448 ACPI_DMAR_SCOPE_TYPE_IOAPIC = 3, 448 ACPI_DMAR_SCOPE_TYPE_IOAPIC = 3,
449 ACPI_DMAR_SCOPE_TYPE_HPET = 4, 449 ACPI_DMAR_SCOPE_TYPE_HPET = 4,
450 ACPI_DMAR_SCOPE_TYPE_ACPI = 5, 450 ACPI_DMAR_SCOPE_TYPE_NAMESPACE = 5,
451 ACPI_DMAR_SCOPE_TYPE_RESERVED = 6 /* 6 and greater are reserved */ 451 ACPI_DMAR_SCOPE_TYPE_RESERVED = 6 /* 6 and greater are reserved */
452}; 452};
453 453
@@ -516,7 +516,7 @@ struct acpi_dmar_andd {
516 struct acpi_dmar_header header; 516 struct acpi_dmar_header header;
517 u8 reserved[3]; 517 u8 reserved[3];
518 u8 device_number; 518 u8 device_number;
519 u8 object_name[]; 519 char device_name[1];
520}; 520};
521 521
522/******************************************************************************* 522/*******************************************************************************
diff --git a/include/acpi/actbl3.h b/include/acpi/actbl3.h
index c2295cc4a5c0..787bcc814463 100644
--- a/include/acpi/actbl3.h
+++ b/include/acpi/actbl3.h
@@ -241,33 +241,96 @@ struct acpi_s3pt_suspend {
241 241
242/******************************************************************************* 242/*******************************************************************************
243 * 243 *
244 * GTDT - Generic Timer Description Table (ACPI 5.0) 244 * GTDT - Generic Timer Description Table (ACPI 5.1)
245 * Version 1 245 * Version 2
246 * 246 *
247 ******************************************************************************/ 247 ******************************************************************************/
248 248
249struct acpi_table_gtdt { 249struct acpi_table_gtdt {
250 struct acpi_table_header header; /* Common ACPI table header */ 250 struct acpi_table_header header; /* Common ACPI table header */
251 u64 address; 251 u64 counter_block_addresss;
252 u32 flags; 252 u32 reserved;
253 u32 secure_pl1_interrupt; 253 u32 secure_el1_interrupt;
254 u32 secure_pl1_flags; 254 u32 secure_el1_flags;
255 u32 non_secure_pl1_interrupt; 255 u32 non_secure_el1_interrupt;
256 u32 non_secure_pl1_flags; 256 u32 non_secure_el1_flags;
257 u32 virtual_timer_interrupt; 257 u32 virtual_timer_interrupt;
258 u32 virtual_timer_flags; 258 u32 virtual_timer_flags;
259 u32 non_secure_pl2_interrupt; 259 u32 non_secure_el2_interrupt;
260 u32 non_secure_pl2_flags; 260 u32 non_secure_el2_flags;
261 u64 counter_read_block_address;
262 u32 platform_timer_count;
263 u32 platform_timer_offset;
261}; 264};
262 265
263/* Values for Flags field above */ 266/* Flag Definitions: Timer Block Physical Timers and Virtual timers */
267
268#define ACPI_GTDT_INTERRUPT_MODE (1)
269#define ACPI_GTDT_INTERRUPT_POLARITY (1<<1)
270#define ACPI_GTDT_ALWAYS_ON (1<<2)
271
272/* Common GTDT subtable header */
273
274struct acpi_gtdt_header {
275 u8 type;
276 u16 length;
277};
264 278
265#define ACPI_GTDT_MAPPED_BLOCK_PRESENT 1 279/* Values for GTDT subtable type above */
266 280
267/* Values for all "TimerFlags" fields above */ 281enum acpi_gtdt_type {
282 ACPI_GTDT_TYPE_TIMER_BLOCK = 0,
283 ACPI_GTDT_TYPE_WATCHDOG = 1,
284 ACPI_GTDT_TYPE_RESERVED = 2 /* 2 and greater are reserved */
285};
286
287/* GTDT Subtables, correspond to Type in struct acpi_gtdt_header */
288
289/* 0: Generic Timer Block */
290
291struct acpi_gtdt_timer_block {
292 struct acpi_gtdt_header header;
293 u8 reserved;
294 u64 block_address;
295 u32 timer_count;
296 u32 timer_offset;
297};
298
299/* Timer Sub-Structure, one per timer */
300
301struct acpi_gtdt_timer_entry {
302 u8 frame_number;
303 u8 reserved[3];
304 u64 base_address;
305 u64 el0_base_address;
306 u32 timer_interrupt;
307 u32 timer_flags;
308 u32 virtual_timer_interrupt;
309 u32 virtual_timer_flags;
310 u32 common_flags;
311};
268 312
269#define ACPI_GTDT_INTERRUPT_MODE 1 313/* Flag Definitions: common_flags above */
270#define ACPI_GTDT_INTERRUPT_POLARITY 2 314
315#define ACPI_GTDT_GT_IS_SECURE_TIMER (1)
316#define ACPI_GTDT_GT_ALWAYS_ON (1<<1)
317
318/* 1: SBSA Generic Watchdog Structure */
319
320struct acpi_gtdt_watchdog {
321 struct acpi_gtdt_header header;
322 u8 reserved;
323 u64 refresh_frame_address;
324 u64 control_frame_address;
325 u32 timer_interrupt;
326 u32 timer_flags;
327};
328
329/* Flag Definitions: timer_flags above */
330
331#define ACPI_GTDT_WATCHDOG_IRQ_MODE (1)
332#define ACPI_GTDT_WATCHDOG_IRQ_POLARITY (1<<1)
333#define ACPI_GTDT_WATCHDOG_SECURE (1<<2)
271 334
272/******************************************************************************* 335/*******************************************************************************
273 * 336 *
@@ -385,7 +448,8 @@ struct acpi_table_pcct {
385 448
386enum acpi_pcct_type { 449enum acpi_pcct_type {
387 ACPI_PCCT_TYPE_GENERIC_SUBSPACE = 0, 450 ACPI_PCCT_TYPE_GENERIC_SUBSPACE = 0,
388 ACPI_PCCT_TYPE_RESERVED = 1 /* 1 and greater are reserved */ 451 ACPI_PCCT_TYPE_HW_REDUCED_SUBSPACE = 1,
452 ACPI_PCCT_TYPE_RESERVED = 2 /* 2 and greater are reserved */
389}; 453};
390 454
391/* 455/*
@@ -407,6 +471,28 @@ struct acpi_pcct_subspace {
407 u16 min_turnaround_time; 471 u16 min_turnaround_time;
408}; 472};
409 473
474/* 1: HW-reduced Communications Subspace (ACPI 5.1) */
475
476struct acpi_pcct_hw_reduced {
477 struct acpi_subtable_header header;
478 u32 doorbell_interrupt;
479 u8 flags;
480 u8 reserved;
481 u64 base_address;
482 u64 length;
483 struct acpi_generic_address doorbell_register;
484 u64 preserve_mask;
485 u64 write_mask;
486 u32 latency;
487 u32 max_access_rate;
488 u16 min_turnaround_time;
489};
490
491/* Values for doorbell flags above */
492
493#define ACPI_PCCT_INTERRUPT_POLARITY (1)
494#define ACPI_PCCT_INTERRUPT_MODE (1<<1)
495
410/* 496/*
411 * PCC memory structures (not part of the ACPI table) 497 * PCC memory structures (not part of the ACPI table)
412 */ 498 */
diff --git a/include/acpi/actypes.h b/include/acpi/actypes.h
index 19b26bb69a70..ac03ec81d342 100644
--- a/include/acpi/actypes.h
+++ b/include/acpi/actypes.h
@@ -126,6 +126,7 @@
126typedef unsigned char u8; 126typedef unsigned char u8;
127typedef unsigned char u8; 127typedef unsigned char u8;
128typedef unsigned short u16; 128typedef unsigned short u16;
129typedef short s16;
129typedef COMPILER_DEPENDENT_UINT64 u64; 130typedef COMPILER_DEPENDENT_UINT64 u64;
130typedef COMPILER_DEPENDENT_INT64 s64; 131typedef COMPILER_DEPENDENT_INT64 s64;
131 132
@@ -516,7 +517,7 @@ typedef u64 acpi_integer;
516 517
517#define ACPI_TO_POINTER(i) ACPI_ADD_PTR (void, (void *) NULL,(acpi_size) i) 518#define ACPI_TO_POINTER(i) ACPI_ADD_PTR (void, (void *) NULL,(acpi_size) i)
518#define ACPI_TO_INTEGER(p) ACPI_PTR_DIFF (p, (void *) NULL) 519#define ACPI_TO_INTEGER(p) ACPI_PTR_DIFF (p, (void *) NULL)
519#define ACPI_OFFSET(d, f) (acpi_size) ACPI_PTR_DIFF (&(((d *)0)->f), (void *) NULL) 520#define ACPI_OFFSET(d, f) ACPI_PTR_DIFF (&(((d *) 0)->f), (void *) NULL)
520#define ACPI_PHYSADDR_TO_PTR(i) ACPI_TO_POINTER(i) 521#define ACPI_PHYSADDR_TO_PTR(i) ACPI_TO_POINTER(i)
521#define ACPI_PTR_TO_PHYSADDR(i) ACPI_TO_INTEGER(i) 522#define ACPI_PTR_TO_PHYSADDR(i) ACPI_TO_INTEGER(i)
522 523
@@ -611,8 +612,9 @@ typedef u64 acpi_integer;
611#define ACPI_NOTIFY_RESERVED (u8) 0x0A 612#define ACPI_NOTIFY_RESERVED (u8) 0x0A
612#define ACPI_NOTIFY_LOCALITY_UPDATE (u8) 0x0B 613#define ACPI_NOTIFY_LOCALITY_UPDATE (u8) 0x0B
613#define ACPI_NOTIFY_SHUTDOWN_REQUEST (u8) 0x0C 614#define ACPI_NOTIFY_SHUTDOWN_REQUEST (u8) 0x0C
615#define ACPI_NOTIFY_AFFINITY_UPDATE (u8) 0x0D
614 616
615#define ACPI_NOTIFY_MAX 0x0C 617#define ACPI_NOTIFY_MAX 0x0D
616 618
617/* 619/*
618 * Types associated with ACPI names and objects. The first group of 620 * Types associated with ACPI names and objects. The first group of
@@ -1244,4 +1246,17 @@ struct acpi_memory_list {
1244#define ACPI_OSI_WIN_7 0x0B 1246#define ACPI_OSI_WIN_7 0x0B
1245#define ACPI_OSI_WIN_8 0x0C 1247#define ACPI_OSI_WIN_8 0x0C
1246 1248
1249/* Definitions of file IO */
1250
1251#define ACPI_FILE_READING 0x01
1252#define ACPI_FILE_WRITING 0x02
1253#define ACPI_FILE_BINARY 0x04
1254
1255#define ACPI_FILE_BEGIN 0x01
1256#define ACPI_FILE_END 0x02
1257
1258/* Definitions of getopt */
1259
1260#define ACPI_OPT_END -1
1261
1247#endif /* __ACTYPES_H__ */ 1262#endif /* __ACTYPES_H__ */
diff --git a/include/acpi/ghes.h b/include/acpi/ghes.h
index dfd60d0bfd27..720446cb243e 100644
--- a/include/acpi/ghes.h
+++ b/include/acpi/ghes.h
@@ -14,7 +14,7 @@
14 14
15struct ghes { 15struct ghes {
16 struct acpi_hest_generic *generic; 16 struct acpi_hest_generic *generic;
17 struct acpi_generic_status *estatus; 17 struct acpi_hest_generic_status *estatus;
18 u64 buffer_paddr; 18 u64 buffer_paddr;
19 unsigned long flags; 19 unsigned long flags;
20 union { 20 union {
diff --git a/include/acpi/platform/acenv.h b/include/acpi/platform/acenv.h
index e863dd5c4e04..5f8cc1fa3278 100644
--- a/include/acpi/platform/acenv.h
+++ b/include/acpi/platform/acenv.h
@@ -87,20 +87,14 @@
87#define ACPI_DBG_TRACK_ALLOCATIONS 87#define ACPI_DBG_TRACK_ALLOCATIONS
88#endif 88#endif
89 89
90/* acpi_names configuration. Single threaded with debugger output enabled. */
91
92#ifdef ACPI_NAMES_APP
93#define ACPI_DEBUGGER
94#define ACPI_APPLICATION
95#define ACPI_SINGLE_THREADED
96#endif
97
98/* 90/*
99 * acpi_bin/acpi_dump/acpi_src/acpi_xtract/Example configuration. All single 91 * acpi_bin/acpi_dump/acpi_help/acpi_names/acpi_src/acpi_xtract/Example configuration.
100 * threaded, with no debug output. 92 * All single threaded.
101 */ 93 */
102#if (defined ACPI_BIN_APP) || \ 94#if (defined ACPI_BIN_APP) || \
103 (defined ACPI_DUMP_APP) || \ 95 (defined ACPI_DUMP_APP) || \
96 (defined ACPI_HELP_APP) || \
97 (defined ACPI_NAMES_APP) || \
104 (defined ACPI_SRC_APP) || \ 98 (defined ACPI_SRC_APP) || \
105 (defined ACPI_XTRACT_APP) || \ 99 (defined ACPI_XTRACT_APP) || \
106 (defined ACPI_EXAMPLE_APP) 100 (defined ACPI_EXAMPLE_APP)
@@ -108,12 +102,40 @@
108#define ACPI_SINGLE_THREADED 102#define ACPI_SINGLE_THREADED
109#endif 103#endif
110 104
105/* acpi_help configuration. Error messages disabled. */
106
111#ifdef ACPI_HELP_APP 107#ifdef ACPI_HELP_APP
112#define ACPI_APPLICATION
113#define ACPI_SINGLE_THREADED
114#define ACPI_NO_ERROR_MESSAGES 108#define ACPI_NO_ERROR_MESSAGES
115#endif 109#endif
116 110
111/* acpi_names configuration. Debug output enabled. */
112
113#ifdef ACPI_NAMES_APP
114#define ACPI_DEBUG_OUTPUT
115#endif
116
117/* acpi_exec/acpi_names/Example configuration. Native RSDP used. */
118
119#if (defined ACPI_EXEC_APP) || \
120 (defined ACPI_EXAMPLE_APP) || \
121 (defined ACPI_NAMES_APP)
122#define ACPI_USE_NATIVE_RSDP_POINTER
123#endif
124
125/* acpi_dump configuration. Native mapping used if provied by OSPMs */
126
127#ifdef ACPI_DUMP_APP
128#define ACPI_USE_NATIVE_MEMORY_MAPPING
129#define USE_NATIVE_ALLOCATE_ZEROED
130#endif
131
132/* acpi_names/Example configuration. Hardware disabled */
133
134#if (defined ACPI_EXAMPLE_APP) || \
135 (defined ACPI_NAMES_APP)
136#define ACPI_REDUCED_HARDWARE 1
137#endif
138
117/* Linkable ACPICA library */ 139/* Linkable ACPICA library */
118 140
119#ifdef ACPI_LIBRARY 141#ifdef ACPI_LIBRARY
@@ -185,6 +207,9 @@
185#elif defined(_AED_EFI) 207#elif defined(_AED_EFI)
186#include "acefi.h" 208#include "acefi.h"
187 209
210#elif defined(_GNU_EFI)
211#include "acefi.h"
212
188#elif defined(__HAIKU__) 213#elif defined(__HAIKU__)
189#include "achaiku.h" 214#include "achaiku.h"
190 215
@@ -399,8 +424,12 @@ typedef char *va_list;
399#ifdef ACPI_APPLICATION 424#ifdef ACPI_APPLICATION
400#include <stdio.h> 425#include <stdio.h>
401#define ACPI_FILE FILE * 426#define ACPI_FILE FILE *
427#define ACPI_FILE_OUT stdout
428#define ACPI_FILE_ERR stderr
402#else 429#else
403#define ACPI_FILE void * 430#define ACPI_FILE void *
431#define ACPI_FILE_OUT NULL
432#define ACPI_FILE_ERR NULL
404#endif /* ACPI_APPLICATION */ 433#endif /* ACPI_APPLICATION */
405#endif /* ACPI_FILE */ 434#endif /* ACPI_FILE */
406 435
diff --git a/include/acpi/platform/aclinux.h b/include/acpi/platform/aclinux.h
index cd1f052d55bb..1ba7c190c2cc 100644
--- a/include/acpi/platform/aclinux.h
+++ b/include/acpi/platform/aclinux.h
@@ -44,6 +44,16 @@
44#ifndef __ACLINUX_H__ 44#ifndef __ACLINUX_H__
45#define __ACLINUX_H__ 45#define __ACLINUX_H__
46 46
47#ifdef __KERNEL__
48
49/* ACPICA external files should not include ACPICA headers directly. */
50
51#if !defined(BUILDING_ACPICA) && !defined(_LINUX_ACPI_H)
52#error "Please don't include <acpi/acpi.h> directly, include <linux/acpi.h> instead."
53#endif
54
55#endif
56
47/* Common (in-kernel/user-space) ACPICA configuration */ 57/* Common (in-kernel/user-space) ACPICA configuration */
48 58
49#define ACPI_USE_SYSTEM_CLIBRARY 59#define ACPI_USE_SYSTEM_CLIBRARY
@@ -70,7 +80,9 @@
70#ifdef EXPORT_ACPI_INTERFACES 80#ifdef EXPORT_ACPI_INTERFACES
71#include <linux/export.h> 81#include <linux/export.h>
72#endif 82#endif
83#ifdef CONFIG_ACPI
73#include <asm/acenv.h> 84#include <asm/acenv.h>
85#endif
74 86
75#ifndef CONFIG_ACPI 87#ifndef CONFIG_ACPI
76 88
diff --git a/include/acpi/platform/aclinuxex.h b/include/acpi/platform/aclinuxex.h
index 191e741cfa0e..568d4b886712 100644
--- a/include/acpi/platform/aclinuxex.h
+++ b/include/acpi/platform/aclinuxex.h
@@ -46,6 +46,28 @@
46 46
47#ifdef __KERNEL__ 47#ifdef __KERNEL__
48 48
49#ifndef ACPI_USE_NATIVE_DIVIDE
50
51#ifndef ACPI_DIV_64_BY_32
52#define ACPI_DIV_64_BY_32(n_hi, n_lo, d32, q32, r32) \
53 do { \
54 u64 (__n) = ((u64) n_hi) << 32 | (n_lo); \
55 (r32) = do_div ((__n), (d32)); \
56 (q32) = (u32) (__n); \
57 } while (0)
58#endif
59
60#ifndef ACPI_SHIFT_RIGHT_64
61#define ACPI_SHIFT_RIGHT_64(n_hi, n_lo) \
62 do { \
63 (n_lo) >>= 1; \
64 (n_lo) |= (((n_hi) & 1) << 31); \
65 (n_hi) >>= 1; \
66 } while (0)
67#endif
68
69#endif
70
49/* 71/*
50 * Overrides for in-kernel ACPICA 72 * Overrides for in-kernel ACPICA
51 */ 73 */
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index 358c01b971db..5320153c311b 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -29,17 +29,17 @@
29#include <linux/ioport.h> /* for struct resource */ 29#include <linux/ioport.h> /* for struct resource */
30#include <linux/device.h> 30#include <linux/device.h>
31 31
32#ifdef CONFIG_ACPI
33
34#ifndef _LINUX 32#ifndef _LINUX
35#define _LINUX 33#define _LINUX
36#endif 34#endif
35#include <acpi/acpi.h>
36
37#ifdef CONFIG_ACPI
37 38
38#include <linux/list.h> 39#include <linux/list.h>
39#include <linux/mod_devicetable.h> 40#include <linux/mod_devicetable.h>
40#include <linux/dynamic_debug.h> 41#include <linux/dynamic_debug.h>
41 42
42#include <acpi/acpi.h>
43#include <acpi/acpi_bus.h> 43#include <acpi/acpi_bus.h>
44#include <acpi/acpi_drivers.h> 44#include <acpi/acpi_drivers.h>
45#include <acpi/acpi_numa.h> 45#include <acpi/acpi_numa.h>
diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
index 8f8ae95c6e27..7d1955afa62c 100644
--- a/include/linux/cpufreq.h
+++ b/include/linux/cpufreq.h
@@ -176,6 +176,7 @@ static inline void disable_cpufreq(void) { }
176 176
177#define CPUFREQ_RELATION_L 0 /* lowest frequency at or above target */ 177#define CPUFREQ_RELATION_L 0 /* lowest frequency at or above target */
178#define CPUFREQ_RELATION_H 1 /* highest frequency below or at target */ 178#define CPUFREQ_RELATION_H 1 /* highest frequency below or at target */
179#define CPUFREQ_RELATION_C 2 /* closest frequency to target */
179 180
180struct freq_attr { 181struct freq_attr {
181 struct attribute attr; 182 struct attribute attr;
diff --git a/include/linux/pci-acpi.h b/include/linux/pci-acpi.h
index 637a608ded0b..64dacb7288a6 100644
--- a/include/linux/pci-acpi.h
+++ b/include/linux/pci-acpi.h
@@ -11,12 +11,17 @@
11#include <linux/acpi.h> 11#include <linux/acpi.h>
12 12
13#ifdef CONFIG_ACPI 13#ifdef CONFIG_ACPI
14extern acpi_status pci_acpi_add_bus_pm_notifier(struct acpi_device *dev, 14extern acpi_status pci_acpi_add_bus_pm_notifier(struct acpi_device *dev);
15 struct pci_bus *pci_bus); 15static inline acpi_status pci_acpi_remove_bus_pm_notifier(struct acpi_device *dev)
16extern acpi_status pci_acpi_remove_bus_pm_notifier(struct acpi_device *dev); 16{
17 return acpi_remove_pm_notifier(dev);
18}
17extern acpi_status pci_acpi_add_pm_notifier(struct acpi_device *dev, 19extern acpi_status pci_acpi_add_pm_notifier(struct acpi_device *dev,
18 struct pci_dev *pci_dev); 20 struct pci_dev *pci_dev);
19extern acpi_status pci_acpi_remove_pm_notifier(struct acpi_device *dev); 21static inline acpi_status pci_acpi_remove_pm_notifier(struct acpi_device *dev)
22{
23 return acpi_remove_pm_notifier(dev);
24}
20extern phys_addr_t acpi_pci_root_get_mcfg_addr(acpi_handle handle); 25extern phys_addr_t acpi_pci_root_get_mcfg_addr(acpi_handle handle);
21 26
22static inline acpi_handle acpi_find_root_bridge_handle(struct pci_dev *pdev) 27static inline acpi_handle acpi_find_root_bridge_handle(struct pci_dev *pdev)
diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
index 43fd6716f662..367f49b9a1c9 100644
--- a/include/linux/pm_runtime.h
+++ b/include/linux/pm_runtime.h
@@ -24,11 +24,20 @@
24#define RPM_AUTO 0x08 /* Use autosuspend_delay */ 24#define RPM_AUTO 0x08 /* Use autosuspend_delay */
25 25
26#ifdef CONFIG_PM 26#ifdef CONFIG_PM
27extern struct workqueue_struct *pm_wq;
28
29static inline bool queue_pm_work(struct work_struct *work)
30{
31 return queue_work(pm_wq, work);
32}
33
27extern int pm_generic_runtime_suspend(struct device *dev); 34extern int pm_generic_runtime_suspend(struct device *dev);
28extern int pm_generic_runtime_resume(struct device *dev); 35extern int pm_generic_runtime_resume(struct device *dev);
29extern int pm_runtime_force_suspend(struct device *dev); 36extern int pm_runtime_force_suspend(struct device *dev);
30extern int pm_runtime_force_resume(struct device *dev); 37extern int pm_runtime_force_resume(struct device *dev);
31#else 38#else
39static inline bool queue_pm_work(struct work_struct *work) { return false; }
40
32static inline int pm_generic_runtime_suspend(struct device *dev) { return 0; } 41static inline int pm_generic_runtime_suspend(struct device *dev) { return 0; }
33static inline int pm_generic_runtime_resume(struct device *dev) { return 0; } 42static inline int pm_generic_runtime_resume(struct device *dev) { return 0; }
34static inline int pm_runtime_force_suspend(struct device *dev) { return 0; } 43static inline int pm_runtime_force_suspend(struct device *dev) { return 0; }
@@ -37,8 +46,6 @@ static inline int pm_runtime_force_resume(struct device *dev) { return 0; }
37 46
38#ifdef CONFIG_PM_RUNTIME 47#ifdef CONFIG_PM_RUNTIME
39 48
40extern struct workqueue_struct *pm_wq;
41
42extern int __pm_runtime_idle(struct device *dev, int rpmflags); 49extern int __pm_runtime_idle(struct device *dev, int rpmflags);
43extern int __pm_runtime_suspend(struct device *dev, int rpmflags); 50extern int __pm_runtime_suspend(struct device *dev, int rpmflags);
44extern int __pm_runtime_resume(struct device *dev, int rpmflags); 51extern int __pm_runtime_resume(struct device *dev, int rpmflags);
diff --git a/include/linux/sfi_acpi.h b/include/linux/sfi_acpi.h
index 4723bbfa1c26..a6e555cbe05c 100644
--- a/include/linux/sfi_acpi.h
+++ b/include/linux/sfi_acpi.h
@@ -63,8 +63,6 @@
63#include <linux/sfi.h> 63#include <linux/sfi.h>
64 64
65#ifdef CONFIG_SFI 65#ifdef CONFIG_SFI
66#include <acpi/acpi.h> /* FIXME: inclusion should be removed */
67
68extern int sfi_acpi_table_parse(char *signature, char *oem_id, 66extern int sfi_acpi_table_parse(char *signature, char *oem_id,
69 char *oem_table_id, 67 char *oem_table_id,
70 int (*handler)(struct acpi_table_header *)); 68 int (*handler)(struct acpi_table_header *));
@@ -78,7 +76,6 @@ static inline int __init acpi_sfi_table_parse(char *signature,
78 return sfi_acpi_table_parse(signature, NULL, NULL, handler); 76 return sfi_acpi_table_parse(signature, NULL, NULL, handler);
79} 77}
80#else /* !CONFIG_SFI */ 78#else /* !CONFIG_SFI */
81
82static inline int sfi_acpi_table_parse(char *signature, char *oem_id, 79static inline int sfi_acpi_table_parse(char *signature, char *oem_id,
83 char *oem_table_id, 80 char *oem_table_id,
84 int (*handler)(struct acpi_table_header *)) 81 int (*handler)(struct acpi_table_header *))
diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
index 9a83d780facd..e4e4121fa327 100644
--- a/kernel/power/Kconfig
+++ b/kernel/power/Kconfig
@@ -253,9 +253,6 @@ config APM_EMULATION
253 anything, try disabling/enabling this option (or disabling/enabling 253 anything, try disabling/enabling this option (or disabling/enabling
254 APM in your BIOS). 254 APM in your BIOS).
255 255
256config ARCH_HAS_OPP
257 bool
258
259config PM_OPP 256config PM_OPP
260 bool 257 bool
261 ---help--- 258 ---help---
diff --git a/kernel/power/main.c b/kernel/power/main.c
index 8e90f330f139..9a59d042ea84 100644
--- a/kernel/power/main.c
+++ b/kernel/power/main.c
@@ -296,8 +296,8 @@ static ssize_t state_show(struct kobject *kobj, struct kobj_attribute *attr,
296 suspend_state_t i; 296 suspend_state_t i;
297 297
298 for (i = PM_SUSPEND_MIN; i < PM_SUSPEND_MAX; i++) 298 for (i = PM_SUSPEND_MIN; i < PM_SUSPEND_MAX; i++)
299 if (pm_states[i].state) 299 if (pm_states[i])
300 s += sprintf(s,"%s ", pm_states[i].label); 300 s += sprintf(s,"%s ", pm_states[i]);
301 301
302#endif 302#endif
303 if (hibernation_available()) 303 if (hibernation_available())
@@ -311,8 +311,7 @@ static ssize_t state_show(struct kobject *kobj, struct kobj_attribute *attr,
311static suspend_state_t decode_state(const char *buf, size_t n) 311static suspend_state_t decode_state(const char *buf, size_t n)
312{ 312{
313#ifdef CONFIG_SUSPEND 313#ifdef CONFIG_SUSPEND
314 suspend_state_t state = PM_SUSPEND_MIN; 314 suspend_state_t state;
315 struct pm_sleep_state *s;
316#endif 315#endif
317 char *p; 316 char *p;
318 int len; 317 int len;
@@ -325,10 +324,12 @@ static suspend_state_t decode_state(const char *buf, size_t n)
325 return PM_SUSPEND_MAX; 324 return PM_SUSPEND_MAX;
326 325
327#ifdef CONFIG_SUSPEND 326#ifdef CONFIG_SUSPEND
328 for (s = &pm_states[state]; state < PM_SUSPEND_MAX; s++, state++) 327 for (state = PM_SUSPEND_MIN; state < PM_SUSPEND_MAX; state++) {
329 if (s->state && len == strlen(s->label) 328 const char *label = pm_states[state];
330 && !strncmp(buf, s->label, len)) 329
331 return s->state; 330 if (label && len == strlen(label) && !strncmp(buf, label, len))
331 return state;
332 }
332#endif 333#endif
333 334
334 return PM_SUSPEND_ON; 335 return PM_SUSPEND_ON;
@@ -446,8 +447,8 @@ static ssize_t autosleep_show(struct kobject *kobj,
446 447
447#ifdef CONFIG_SUSPEND 448#ifdef CONFIG_SUSPEND
448 if (state < PM_SUSPEND_MAX) 449 if (state < PM_SUSPEND_MAX)
449 return sprintf(buf, "%s\n", pm_states[state].state ? 450 return sprintf(buf, "%s\n", pm_states[state] ?
450 pm_states[state].label : "error"); 451 pm_states[state] : "error");
451#endif 452#endif
452#ifdef CONFIG_HIBERNATION 453#ifdef CONFIG_HIBERNATION
453 return sprintf(buf, "disk\n"); 454 return sprintf(buf, "disk\n");
@@ -615,7 +616,6 @@ static struct attribute_group attr_group = {
615 .attrs = g, 616 .attrs = g,
616}; 617};
617 618
618#ifdef CONFIG_PM_RUNTIME
619struct workqueue_struct *pm_wq; 619struct workqueue_struct *pm_wq;
620EXPORT_SYMBOL_GPL(pm_wq); 620EXPORT_SYMBOL_GPL(pm_wq);
621 621
@@ -625,9 +625,6 @@ static int __init pm_start_workqueue(void)
625 625
626 return pm_wq ? 0 : -ENOMEM; 626 return pm_wq ? 0 : -ENOMEM;
627} 627}
628#else
629static inline int pm_start_workqueue(void) { return 0; }
630#endif
631 628
632static int __init pm_init(void) 629static int __init pm_init(void)
633{ 630{
diff --git a/kernel/power/power.h b/kernel/power/power.h
index c60f13b5270a..5d49dcac2537 100644
--- a/kernel/power/power.h
+++ b/kernel/power/power.h
@@ -178,13 +178,8 @@ extern void swsusp_show_speed(struct timeval *, struct timeval *,
178 unsigned int, char *); 178 unsigned int, char *);
179 179
180#ifdef CONFIG_SUSPEND 180#ifdef CONFIG_SUSPEND
181struct pm_sleep_state {
182 const char *label;
183 suspend_state_t state;
184};
185
186/* kernel/power/suspend.c */ 181/* kernel/power/suspend.c */
187extern struct pm_sleep_state pm_states[]; 182extern const char *pm_states[];
188 183
189extern int suspend_devices_and_enter(suspend_state_t state); 184extern int suspend_devices_and_enter(suspend_state_t state);
190#else /* !CONFIG_SUSPEND */ 185#else /* !CONFIG_SUSPEND */
diff --git a/kernel/power/snapshot.c b/kernel/power/snapshot.c
index 1ea328aafdc9..4fc5c32422b3 100644
--- a/kernel/power/snapshot.c
+++ b/kernel/power/snapshot.c
@@ -248,33 +248,61 @@ static void *chain_alloc(struct chain_allocator *ca, unsigned int size)
248 * information is stored (in the form of a block of bitmap) 248 * information is stored (in the form of a block of bitmap)
249 * It also contains the pfns that correspond to the start and end of 249 * It also contains the pfns that correspond to the start and end of
250 * the represented memory area. 250 * the represented memory area.
251 *
252 * The memory bitmap is organized as a radix tree to guarantee fast random
253 * access to the bits. There is one radix tree for each zone (as returned
254 * from create_mem_extents).
255 *
256 * One radix tree is represented by one struct mem_zone_bm_rtree. There are
257 * two linked lists for the nodes of the tree, one for the inner nodes and
258 * one for the leave nodes. The linked leave nodes are used for fast linear
259 * access of the memory bitmap.
260 *
261 * The struct rtree_node represents one node of the radix tree.
251 */ 262 */
252 263
253#define BM_END_OF_MAP (~0UL) 264#define BM_END_OF_MAP (~0UL)
254 265
255#define BM_BITS_PER_BLOCK (PAGE_SIZE * BITS_PER_BYTE) 266#define BM_BITS_PER_BLOCK (PAGE_SIZE * BITS_PER_BYTE)
267#define BM_BLOCK_SHIFT (PAGE_SHIFT + 3)
268#define BM_BLOCK_MASK ((1UL << BM_BLOCK_SHIFT) - 1)
256 269
257struct bm_block { 270/*
258 struct list_head hook; /* hook into a list of bitmap blocks */ 271 * struct rtree_node is a wrapper struct to link the nodes
259 unsigned long start_pfn; /* pfn represented by the first bit */ 272 * of the rtree together for easy linear iteration over
260 unsigned long end_pfn; /* pfn represented by the last bit plus 1 */ 273 * bits and easy freeing
261 unsigned long *data; /* bitmap representing pages */ 274 */
275struct rtree_node {
276 struct list_head list;
277 unsigned long *data;
262}; 278};
263 279
264static inline unsigned long bm_block_bits(struct bm_block *bb) 280/*
265{ 281 * struct mem_zone_bm_rtree represents a bitmap used for one
266 return bb->end_pfn - bb->start_pfn; 282 * populated memory zone.
267} 283 */
284struct mem_zone_bm_rtree {
285 struct list_head list; /* Link Zones together */
286 struct list_head nodes; /* Radix Tree inner nodes */
287 struct list_head leaves; /* Radix Tree leaves */
288 unsigned long start_pfn; /* Zone start page frame */
289 unsigned long end_pfn; /* Zone end page frame + 1 */
290 struct rtree_node *rtree; /* Radix Tree Root */
291 int levels; /* Number of Radix Tree Levels */
292 unsigned int blocks; /* Number of Bitmap Blocks */
293};
268 294
269/* strcut bm_position is used for browsing memory bitmaps */ 295/* strcut bm_position is used for browsing memory bitmaps */
270 296
271struct bm_position { 297struct bm_position {
272 struct bm_block *block; 298 struct mem_zone_bm_rtree *zone;
273 int bit; 299 struct rtree_node *node;
300 unsigned long node_pfn;
301 int node_bit;
274}; 302};
275 303
276struct memory_bitmap { 304struct memory_bitmap {
277 struct list_head blocks; /* list of bitmap blocks */ 305 struct list_head zones;
278 struct linked_page *p_list; /* list of pages used to store zone 306 struct linked_page *p_list; /* list of pages used to store zone
279 * bitmap objects and bitmap block 307 * bitmap objects and bitmap block
280 * objects 308 * objects
@@ -284,38 +312,178 @@ struct memory_bitmap {
284 312
285/* Functions that operate on memory bitmaps */ 313/* Functions that operate on memory bitmaps */
286 314
287static void memory_bm_position_reset(struct memory_bitmap *bm) 315#define BM_ENTRIES_PER_LEVEL (PAGE_SIZE / sizeof(unsigned long))
316#if BITS_PER_LONG == 32
317#define BM_RTREE_LEVEL_SHIFT (PAGE_SHIFT - 2)
318#else
319#define BM_RTREE_LEVEL_SHIFT (PAGE_SHIFT - 3)
320#endif
321#define BM_RTREE_LEVEL_MASK ((1UL << BM_RTREE_LEVEL_SHIFT) - 1)
322
323/*
324 * alloc_rtree_node - Allocate a new node and add it to the radix tree.
325 *
326 * This function is used to allocate inner nodes as well as the
327 * leave nodes of the radix tree. It also adds the node to the
328 * corresponding linked list passed in by the *list parameter.
329 */
330static struct rtree_node *alloc_rtree_node(gfp_t gfp_mask, int safe_needed,
331 struct chain_allocator *ca,
332 struct list_head *list)
288{ 333{
289 bm->cur.block = list_entry(bm->blocks.next, struct bm_block, hook); 334 struct rtree_node *node;
290 bm->cur.bit = 0;
291}
292 335
293static void memory_bm_free(struct memory_bitmap *bm, int clear_nosave_free); 336 node = chain_alloc(ca, sizeof(struct rtree_node));
337 if (!node)
338 return NULL;
294 339
295/** 340 node->data = get_image_page(gfp_mask, safe_needed);
296 * create_bm_block_list - create a list of block bitmap objects 341 if (!node->data)
297 * @pages - number of pages to track 342 return NULL;
298 * @list - list to put the allocated blocks into 343
299 * @ca - chain allocator to be used for allocating memory 344 list_add_tail(&node->list, list);
345
346 return node;
347}
348
349/*
350 * add_rtree_block - Add a new leave node to the radix tree
351 *
352 * The leave nodes need to be allocated in order to keep the leaves
353 * linked list in order. This is guaranteed by the zone->blocks
354 * counter.
300 */ 355 */
301static int create_bm_block_list(unsigned long pages, 356static int add_rtree_block(struct mem_zone_bm_rtree *zone, gfp_t gfp_mask,
302 struct list_head *list, 357 int safe_needed, struct chain_allocator *ca)
303 struct chain_allocator *ca)
304{ 358{
305 unsigned int nr_blocks = DIV_ROUND_UP(pages, BM_BITS_PER_BLOCK); 359 struct rtree_node *node, *block, **dst;
360 unsigned int levels_needed, block_nr;
361 int i;
306 362
307 while (nr_blocks-- > 0) { 363 block_nr = zone->blocks;
308 struct bm_block *bb; 364 levels_needed = 0;
309 365
310 bb = chain_alloc(ca, sizeof(struct bm_block)); 366 /* How many levels do we need for this block nr? */
311 if (!bb) 367 while (block_nr) {
368 levels_needed += 1;
369 block_nr >>= BM_RTREE_LEVEL_SHIFT;
370 }
371
372 /* Make sure the rtree has enough levels */
373 for (i = zone->levels; i < levels_needed; i++) {
374 node = alloc_rtree_node(gfp_mask, safe_needed, ca,
375 &zone->nodes);
376 if (!node)
312 return -ENOMEM; 377 return -ENOMEM;
313 list_add(&bb->hook, list); 378
379 node->data[0] = (unsigned long)zone->rtree;
380 zone->rtree = node;
381 zone->levels += 1;
382 }
383
384 /* Allocate new block */
385 block = alloc_rtree_node(gfp_mask, safe_needed, ca, &zone->leaves);
386 if (!block)
387 return -ENOMEM;
388
389 /* Now walk the rtree to insert the block */
390 node = zone->rtree;
391 dst = &zone->rtree;
392 block_nr = zone->blocks;
393 for (i = zone->levels; i > 0; i--) {
394 int index;
395
396 if (!node) {
397 node = alloc_rtree_node(gfp_mask, safe_needed, ca,
398 &zone->nodes);
399 if (!node)
400 return -ENOMEM;
401 *dst = node;
402 }
403
404 index = block_nr >> ((i - 1) * BM_RTREE_LEVEL_SHIFT);
405 index &= BM_RTREE_LEVEL_MASK;
406 dst = (struct rtree_node **)&((*dst)->data[index]);
407 node = *dst;
314 } 408 }
315 409
410 zone->blocks += 1;
411 *dst = block;
412
316 return 0; 413 return 0;
317} 414}
318 415
416static void free_zone_bm_rtree(struct mem_zone_bm_rtree *zone,
417 int clear_nosave_free);
418
419/*
420 * create_zone_bm_rtree - create a radix tree for one zone
421 *
422 * Allocated the mem_zone_bm_rtree structure and initializes it.
423 * This function also allocated and builds the radix tree for the
424 * zone.
425 */
426static struct mem_zone_bm_rtree *
427create_zone_bm_rtree(gfp_t gfp_mask, int safe_needed,
428 struct chain_allocator *ca,
429 unsigned long start, unsigned long end)
430{
431 struct mem_zone_bm_rtree *zone;
432 unsigned int i, nr_blocks;
433 unsigned long pages;
434
435 pages = end - start;
436 zone = chain_alloc(ca, sizeof(struct mem_zone_bm_rtree));
437 if (!zone)
438 return NULL;
439
440 INIT_LIST_HEAD(&zone->nodes);
441 INIT_LIST_HEAD(&zone->leaves);
442 zone->start_pfn = start;
443 zone->end_pfn = end;
444 nr_blocks = DIV_ROUND_UP(pages, BM_BITS_PER_BLOCK);
445
446 for (i = 0; i < nr_blocks; i++) {
447 if (add_rtree_block(zone, gfp_mask, safe_needed, ca)) {
448 free_zone_bm_rtree(zone, PG_UNSAFE_CLEAR);
449 return NULL;
450 }
451 }
452
453 return zone;
454}
455
456/*
457 * free_zone_bm_rtree - Free the memory of the radix tree
458 *
459 * Free all node pages of the radix tree. The mem_zone_bm_rtree
460 * structure itself is not freed here nor are the rtree_node
461 * structs.
462 */
463static void free_zone_bm_rtree(struct mem_zone_bm_rtree *zone,
464 int clear_nosave_free)
465{
466 struct rtree_node *node;
467
468 list_for_each_entry(node, &zone->nodes, list)
469 free_image_page(node->data, clear_nosave_free);
470
471 list_for_each_entry(node, &zone->leaves, list)
472 free_image_page(node->data, clear_nosave_free);
473}
474
475static void memory_bm_position_reset(struct memory_bitmap *bm)
476{
477 bm->cur.zone = list_entry(bm->zones.next, struct mem_zone_bm_rtree,
478 list);
479 bm->cur.node = list_entry(bm->cur.zone->leaves.next,
480 struct rtree_node, list);
481 bm->cur.node_pfn = 0;
482 bm->cur.node_bit = 0;
483}
484
485static void memory_bm_free(struct memory_bitmap *bm, int clear_nosave_free);
486
319struct mem_extent { 487struct mem_extent {
320 struct list_head hook; 488 struct list_head hook;
321 unsigned long start; 489 unsigned long start;
@@ -407,40 +575,22 @@ memory_bm_create(struct memory_bitmap *bm, gfp_t gfp_mask, int safe_needed)
407 int error; 575 int error;
408 576
409 chain_init(&ca, gfp_mask, safe_needed); 577 chain_init(&ca, gfp_mask, safe_needed);
410 INIT_LIST_HEAD(&bm->blocks); 578 INIT_LIST_HEAD(&bm->zones);
411 579
412 error = create_mem_extents(&mem_extents, gfp_mask); 580 error = create_mem_extents(&mem_extents, gfp_mask);
413 if (error) 581 if (error)
414 return error; 582 return error;
415 583
416 list_for_each_entry(ext, &mem_extents, hook) { 584 list_for_each_entry(ext, &mem_extents, hook) {
417 struct bm_block *bb; 585 struct mem_zone_bm_rtree *zone;
418 unsigned long pfn = ext->start;
419 unsigned long pages = ext->end - ext->start;
420
421 bb = list_entry(bm->blocks.prev, struct bm_block, hook);
422 586
423 error = create_bm_block_list(pages, bm->blocks.prev, &ca); 587 zone = create_zone_bm_rtree(gfp_mask, safe_needed, &ca,
424 if (error) 588 ext->start, ext->end);
589 if (!zone) {
590 error = -ENOMEM;
425 goto Error; 591 goto Error;
426
427 list_for_each_entry_continue(bb, &bm->blocks, hook) {
428 bb->data = get_image_page(gfp_mask, safe_needed);
429 if (!bb->data) {
430 error = -ENOMEM;
431 goto Error;
432 }
433
434 bb->start_pfn = pfn;
435 if (pages >= BM_BITS_PER_BLOCK) {
436 pfn += BM_BITS_PER_BLOCK;
437 pages -= BM_BITS_PER_BLOCK;
438 } else {
439 /* This is executed only once in the loop */
440 pfn += pages;
441 }
442 bb->end_pfn = pfn;
443 } 592 }
593 list_add_tail(&zone->list, &bm->zones);
444 } 594 }
445 595
446 bm->p_list = ca.chain; 596 bm->p_list = ca.chain;
@@ -460,51 +610,83 @@ memory_bm_create(struct memory_bitmap *bm, gfp_t gfp_mask, int safe_needed)
460 */ 610 */
461static void memory_bm_free(struct memory_bitmap *bm, int clear_nosave_free) 611static void memory_bm_free(struct memory_bitmap *bm, int clear_nosave_free)
462{ 612{
463 struct bm_block *bb; 613 struct mem_zone_bm_rtree *zone;
464 614
465 list_for_each_entry(bb, &bm->blocks, hook) 615 list_for_each_entry(zone, &bm->zones, list)
466 if (bb->data) 616 free_zone_bm_rtree(zone, clear_nosave_free);
467 free_image_page(bb->data, clear_nosave_free);
468 617
469 free_list_of_pages(bm->p_list, clear_nosave_free); 618 free_list_of_pages(bm->p_list, clear_nosave_free);
470 619
471 INIT_LIST_HEAD(&bm->blocks); 620 INIT_LIST_HEAD(&bm->zones);
472} 621}
473 622
474/** 623/**
475 * memory_bm_find_bit - find the bit in the bitmap @bm that corresponds 624 * memory_bm_find_bit - Find the bit for pfn in the memory
476 * to given pfn. The cur_zone_bm member of @bm and the cur_block member 625 * bitmap
477 * of @bm->cur_zone_bm are updated. 626 *
627 * Find the bit in the bitmap @bm that corresponds to given pfn.
628 * The cur.zone, cur.block and cur.node_pfn member of @bm are
629 * updated.
630 * It walks the radix tree to find the page which contains the bit for
631 * pfn and returns the bit position in **addr and *bit_nr.
478 */ 632 */
479static int memory_bm_find_bit(struct memory_bitmap *bm, unsigned long pfn, 633static int memory_bm_find_bit(struct memory_bitmap *bm, unsigned long pfn,
480 void **addr, unsigned int *bit_nr) 634 void **addr, unsigned int *bit_nr)
481{ 635{
482 struct bm_block *bb; 636 struct mem_zone_bm_rtree *curr, *zone;
637 struct rtree_node *node;
638 int i, block_nr;
483 639
640 zone = bm->cur.zone;
641
642 if (pfn >= zone->start_pfn && pfn < zone->end_pfn)
643 goto zone_found;
644
645 zone = NULL;
646
647 /* Find the right zone */
648 list_for_each_entry(curr, &bm->zones, list) {
649 if (pfn >= curr->start_pfn && pfn < curr->end_pfn) {
650 zone = curr;
651 break;
652 }
653 }
654
655 if (!zone)
656 return -EFAULT;
657
658zone_found:
484 /* 659 /*
485 * Check if the pfn corresponds to the current bitmap block and find 660 * We have a zone. Now walk the radix tree to find the leave
486 * the block where it fits if this is not the case. 661 * node for our pfn.
487 */ 662 */
488 bb = bm->cur.block;
489 if (pfn < bb->start_pfn)
490 list_for_each_entry_continue_reverse(bb, &bm->blocks, hook)
491 if (pfn >= bb->start_pfn)
492 break;
493 663
494 if (pfn >= bb->end_pfn) 664 node = bm->cur.node;
495 list_for_each_entry_continue(bb, &bm->blocks, hook) 665 if (((pfn - zone->start_pfn) & ~BM_BLOCK_MASK) == bm->cur.node_pfn)
496 if (pfn >= bb->start_pfn && pfn < bb->end_pfn) 666 goto node_found;
497 break;
498 667
499 if (&bb->hook == &bm->blocks) 668 node = zone->rtree;
500 return -EFAULT; 669 block_nr = (pfn - zone->start_pfn) >> BM_BLOCK_SHIFT;
670
671 for (i = zone->levels; i > 0; i--) {
672 int index;
673
674 index = block_nr >> ((i - 1) * BM_RTREE_LEVEL_SHIFT);
675 index &= BM_RTREE_LEVEL_MASK;
676 BUG_ON(node->data[index] == 0);
677 node = (struct rtree_node *)node->data[index];
678 }
679
680node_found:
681 /* Update last position */
682 bm->cur.zone = zone;
683 bm->cur.node = node;
684 bm->cur.node_pfn = (pfn - zone->start_pfn) & ~BM_BLOCK_MASK;
685
686 /* Set return values */
687 *addr = node->data;
688 *bit_nr = (pfn - zone->start_pfn) & BM_BLOCK_MASK;
501 689
502 /* The block has been found */
503 bm->cur.block = bb;
504 pfn -= bb->start_pfn;
505 bm->cur.bit = pfn + 1;
506 *bit_nr = pfn;
507 *addr = bb->data;
508 return 0; 690 return 0;
509} 691}
510 692
@@ -528,6 +710,7 @@ static int mem_bm_set_bit_check(struct memory_bitmap *bm, unsigned long pfn)
528 error = memory_bm_find_bit(bm, pfn, &addr, &bit); 710 error = memory_bm_find_bit(bm, pfn, &addr, &bit);
529 if (!error) 711 if (!error)
530 set_bit(bit, addr); 712 set_bit(bit, addr);
713
531 return error; 714 return error;
532} 715}
533 716
@@ -542,6 +725,14 @@ static void memory_bm_clear_bit(struct memory_bitmap *bm, unsigned long pfn)
542 clear_bit(bit, addr); 725 clear_bit(bit, addr);
543} 726}
544 727
728static void memory_bm_clear_current(struct memory_bitmap *bm)
729{
730 int bit;
731
732 bit = max(bm->cur.node_bit - 1, 0);
733 clear_bit(bit, bm->cur.node->data);
734}
735
545static int memory_bm_test_bit(struct memory_bitmap *bm, unsigned long pfn) 736static int memory_bm_test_bit(struct memory_bitmap *bm, unsigned long pfn)
546{ 737{
547 void *addr; 738 void *addr;
@@ -561,38 +752,70 @@ static bool memory_bm_pfn_present(struct memory_bitmap *bm, unsigned long pfn)
561 return !memory_bm_find_bit(bm, pfn, &addr, &bit); 752 return !memory_bm_find_bit(bm, pfn, &addr, &bit);
562} 753}
563 754
564/** 755/*
565 * memory_bm_next_pfn - find the pfn that corresponds to the next set bit 756 * rtree_next_node - Jumps to the next leave node
566 * in the bitmap @bm. If the pfn cannot be found, BM_END_OF_MAP is 757 *
567 * returned. 758 * Sets the position to the beginning of the next node in the
759 * memory bitmap. This is either the next node in the current
760 * zone's radix tree or the first node in the radix tree of the
761 * next zone.
568 * 762 *
569 * It is required to run memory_bm_position_reset() before the first call to 763 * Returns true if there is a next node, false otherwise.
570 * this function.
571 */ 764 */
765static bool rtree_next_node(struct memory_bitmap *bm)
766{
767 bm->cur.node = list_entry(bm->cur.node->list.next,
768 struct rtree_node, list);
769 if (&bm->cur.node->list != &bm->cur.zone->leaves) {
770 bm->cur.node_pfn += BM_BITS_PER_BLOCK;
771 bm->cur.node_bit = 0;
772 touch_softlockup_watchdog();
773 return true;
774 }
775
776 /* No more nodes, goto next zone */
777 bm->cur.zone = list_entry(bm->cur.zone->list.next,
778 struct mem_zone_bm_rtree, list);
779 if (&bm->cur.zone->list != &bm->zones) {
780 bm->cur.node = list_entry(bm->cur.zone->leaves.next,
781 struct rtree_node, list);
782 bm->cur.node_pfn = 0;
783 bm->cur.node_bit = 0;
784 return true;
785 }
572 786
787 /* No more zones */
788 return false;
789}
790
791/**
792 * memory_bm_rtree_next_pfn - Find the next set bit in the bitmap @bm
793 *
794 * Starting from the last returned position this function searches
795 * for the next set bit in the memory bitmap and returns its
796 * number. If no more bit is set BM_END_OF_MAP is returned.
797 *
798 * It is required to run memory_bm_position_reset() before the
799 * first call to this function.
800 */
573static unsigned long memory_bm_next_pfn(struct memory_bitmap *bm) 801static unsigned long memory_bm_next_pfn(struct memory_bitmap *bm)
574{ 802{
575 struct bm_block *bb; 803 unsigned long bits, pfn, pages;
576 int bit; 804 int bit;
577 805
578 bb = bm->cur.block;
579 do { 806 do {
580 bit = bm->cur.bit; 807 pages = bm->cur.zone->end_pfn - bm->cur.zone->start_pfn;
581 bit = find_next_bit(bb->data, bm_block_bits(bb), bit); 808 bits = min(pages - bm->cur.node_pfn, BM_BITS_PER_BLOCK);
582 if (bit < bm_block_bits(bb)) 809 bit = find_next_bit(bm->cur.node->data, bits,
583 goto Return_pfn; 810 bm->cur.node_bit);
584 811 if (bit < bits) {
585 bb = list_entry(bb->hook.next, struct bm_block, hook); 812 pfn = bm->cur.zone->start_pfn + bm->cur.node_pfn + bit;
586 bm->cur.block = bb; 813 bm->cur.node_bit = bit + 1;
587 bm->cur.bit = 0; 814 return pfn;
588 } while (&bb->hook != &bm->blocks); 815 }
816 } while (rtree_next_node(bm));
589 817
590 memory_bm_position_reset(bm);
591 return BM_END_OF_MAP; 818 return BM_END_OF_MAP;
592
593 Return_pfn:
594 bm->cur.bit = bit + 1;
595 return bb->start_pfn + bit;
596} 819}
597 820
598/** 821/**
@@ -816,12 +1039,17 @@ void free_basic_memory_bitmaps(void)
816 1039
817unsigned int snapshot_additional_pages(struct zone *zone) 1040unsigned int snapshot_additional_pages(struct zone *zone)
818{ 1041{
819 unsigned int res; 1042 unsigned int rtree, nodes;
1043
1044 rtree = nodes = DIV_ROUND_UP(zone->spanned_pages, BM_BITS_PER_BLOCK);
1045 rtree += DIV_ROUND_UP(rtree * sizeof(struct rtree_node),
1046 LINKED_PAGE_DATA_SIZE);
1047 while (nodes > 1) {
1048 nodes = DIV_ROUND_UP(nodes, BM_ENTRIES_PER_LEVEL);
1049 rtree += nodes;
1050 }
820 1051
821 res = DIV_ROUND_UP(zone->spanned_pages, BM_BITS_PER_BLOCK); 1052 return 2 * rtree;
822 res += DIV_ROUND_UP(res * sizeof(struct bm_block),
823 LINKED_PAGE_DATA_SIZE);
824 return 2 * res;
825} 1053}
826 1054
827#ifdef CONFIG_HIGHMEM 1055#ifdef CONFIG_HIGHMEM
@@ -1094,23 +1322,35 @@ static struct memory_bitmap copy_bm;
1094 1322
1095void swsusp_free(void) 1323void swsusp_free(void)
1096{ 1324{
1097 struct zone *zone; 1325 unsigned long fb_pfn, fr_pfn;
1098 unsigned long pfn, max_zone_pfn;
1099 1326
1100 for_each_populated_zone(zone) { 1327 memory_bm_position_reset(forbidden_pages_map);
1101 max_zone_pfn = zone_end_pfn(zone); 1328 memory_bm_position_reset(free_pages_map);
1102 for (pfn = zone->zone_start_pfn; pfn < max_zone_pfn; pfn++) 1329
1103 if (pfn_valid(pfn)) { 1330loop:
1104 struct page *page = pfn_to_page(pfn); 1331 fr_pfn = memory_bm_next_pfn(free_pages_map);
1105 1332 fb_pfn = memory_bm_next_pfn(forbidden_pages_map);
1106 if (swsusp_page_is_forbidden(page) && 1333
1107 swsusp_page_is_free(page)) { 1334 /*
1108 swsusp_unset_page_forbidden(page); 1335 * Find the next bit set in both bitmaps. This is guaranteed to
1109 swsusp_unset_page_free(page); 1336 * terminate when fb_pfn == fr_pfn == BM_END_OF_MAP.
1110 __free_page(page); 1337 */
1111 } 1338 do {
1112 } 1339 if (fb_pfn < fr_pfn)
1340 fb_pfn = memory_bm_next_pfn(forbidden_pages_map);
1341 if (fr_pfn < fb_pfn)
1342 fr_pfn = memory_bm_next_pfn(free_pages_map);
1343 } while (fb_pfn != fr_pfn);
1344
1345 if (fr_pfn != BM_END_OF_MAP && pfn_valid(fr_pfn)) {
1346 struct page *page = pfn_to_page(fr_pfn);
1347
1348 memory_bm_clear_current(forbidden_pages_map);
1349 memory_bm_clear_current(free_pages_map);
1350 __free_page(page);
1351 goto loop;
1113 } 1352 }
1353
1114 nr_copy_pages = 0; 1354 nr_copy_pages = 0;
1115 nr_meta_pages = 0; 1355 nr_meta_pages = 0;
1116 restore_pblist = NULL; 1356 restore_pblist = NULL;
diff --git a/kernel/power/suspend.c b/kernel/power/suspend.c
index 4b736b4dfa96..6dadb25cb0d8 100644
--- a/kernel/power/suspend.c
+++ b/kernel/power/suspend.c
@@ -31,20 +31,11 @@
31 31
32#include "power.h" 32#include "power.h"
33 33
34struct pm_sleep_state pm_states[PM_SUSPEND_MAX] = { 34static const char *pm_labels[] = { "mem", "standby", "freeze", };
35 [PM_SUSPEND_FREEZE] = { .label = "freeze", .state = PM_SUSPEND_FREEZE }, 35const char *pm_states[PM_SUSPEND_MAX];
36 [PM_SUSPEND_STANDBY] = { .label = "standby", },
37 [PM_SUSPEND_MEM] = { .label = "mem", },
38};
39 36
40static const struct platform_suspend_ops *suspend_ops; 37static const struct platform_suspend_ops *suspend_ops;
41static const struct platform_freeze_ops *freeze_ops; 38static const struct platform_freeze_ops *freeze_ops;
42
43static bool need_suspend_ops(suspend_state_t state)
44{
45 return state > PM_SUSPEND_FREEZE;
46}
47
48static DECLARE_WAIT_QUEUE_HEAD(suspend_freeze_wait_head); 39static DECLARE_WAIT_QUEUE_HEAD(suspend_freeze_wait_head);
49static bool suspend_freeze_wake; 40static bool suspend_freeze_wake;
50 41
@@ -97,10 +88,7 @@ static bool relative_states;
97static int __init sleep_states_setup(char *str) 88static int __init sleep_states_setup(char *str)
98{ 89{
99 relative_states = !strncmp(str, "1", 1); 90 relative_states = !strncmp(str, "1", 1);
100 if (relative_states) { 91 pm_states[PM_SUSPEND_FREEZE] = pm_labels[relative_states ? 0 : 2];
101 pm_states[PM_SUSPEND_MEM].state = PM_SUSPEND_FREEZE;
102 pm_states[PM_SUSPEND_FREEZE].state = 0;
103 }
104 return 1; 92 return 1;
105} 93}
106 94
@@ -113,20 +101,20 @@ __setup("relative_sleep_states=", sleep_states_setup);
113void suspend_set_ops(const struct platform_suspend_ops *ops) 101void suspend_set_ops(const struct platform_suspend_ops *ops)
114{ 102{
115 suspend_state_t i; 103 suspend_state_t i;
116 int j = PM_SUSPEND_MAX - 1; 104 int j = 0;
117 105
118 lock_system_sleep(); 106 lock_system_sleep();
119 107
120 suspend_ops = ops; 108 suspend_ops = ops;
121 for (i = PM_SUSPEND_MEM; i >= PM_SUSPEND_STANDBY; i--) 109 for (i = PM_SUSPEND_MEM; i >= PM_SUSPEND_STANDBY; i--)
122 if (valid_state(i)) 110 if (valid_state(i)) {
123 pm_states[j--].state = i; 111 pm_states[i] = pm_labels[j++];
124 else if (!relative_states) 112 } else if (!relative_states) {
125 pm_states[j--].state = 0; 113 pm_states[i] = NULL;
114 j++;
115 }
126 116
127 pm_states[j--].state = PM_SUSPEND_FREEZE; 117 pm_states[PM_SUSPEND_FREEZE] = pm_labels[j];
128 while (j >= PM_SUSPEND_MIN)
129 pm_states[j--].state = 0;
130 118
131 unlock_system_sleep(); 119 unlock_system_sleep();
132} 120}
@@ -145,6 +133,65 @@ int suspend_valid_only_mem(suspend_state_t state)
145} 133}
146EXPORT_SYMBOL_GPL(suspend_valid_only_mem); 134EXPORT_SYMBOL_GPL(suspend_valid_only_mem);
147 135
136static bool sleep_state_supported(suspend_state_t state)
137{
138 return state == PM_SUSPEND_FREEZE || (suspend_ops && suspend_ops->enter);
139}
140
141static int platform_suspend_prepare(suspend_state_t state)
142{
143 return state != PM_SUSPEND_FREEZE && suspend_ops->prepare ?
144 suspend_ops->prepare() : 0;
145}
146
147static int platform_suspend_prepare_late(suspend_state_t state)
148{
149 return state != PM_SUSPEND_FREEZE && suspend_ops->prepare_late ?
150 suspend_ops->prepare_late() : 0;
151}
152
153static void platform_suspend_wake(suspend_state_t state)
154{
155 if (state != PM_SUSPEND_FREEZE && suspend_ops->wake)
156 suspend_ops->wake();
157}
158
159static void platform_suspend_finish(suspend_state_t state)
160{
161 if (state != PM_SUSPEND_FREEZE && suspend_ops->finish)
162 suspend_ops->finish();
163}
164
165static int platform_suspend_begin(suspend_state_t state)
166{
167 if (state == PM_SUSPEND_FREEZE && freeze_ops && freeze_ops->begin)
168 return freeze_ops->begin();
169 else if (suspend_ops->begin)
170 return suspend_ops->begin(state);
171 else
172 return 0;
173}
174
175static void platform_suspend_end(suspend_state_t state)
176{
177 if (state == PM_SUSPEND_FREEZE && freeze_ops && freeze_ops->end)
178 freeze_ops->end();
179 else if (suspend_ops->end)
180 suspend_ops->end();
181}
182
183static void platform_suspend_recover(suspend_state_t state)
184{
185 if (state != PM_SUSPEND_FREEZE && suspend_ops->recover)
186 suspend_ops->recover();
187}
188
189static bool platform_suspend_again(suspend_state_t state)
190{
191 return state != PM_SUSPEND_FREEZE && suspend_ops->suspend_again ?
192 suspend_ops->suspend_again() : false;
193}
194
148static int suspend_test(int level) 195static int suspend_test(int level)
149{ 196{
150#ifdef CONFIG_PM_DEBUG 197#ifdef CONFIG_PM_DEBUG
@@ -168,7 +215,7 @@ static int suspend_prepare(suspend_state_t state)
168{ 215{
169 int error; 216 int error;
170 217
171 if (need_suspend_ops(state) && (!suspend_ops || !suspend_ops->enter)) 218 if (!sleep_state_supported(state))
172 return -EPERM; 219 return -EPERM;
173 220
174 pm_prepare_console(); 221 pm_prepare_console();
@@ -214,23 +261,18 @@ static int suspend_enter(suspend_state_t state, bool *wakeup)
214{ 261{
215 int error; 262 int error;
216 263
217 if (need_suspend_ops(state) && suspend_ops->prepare) { 264 error = platform_suspend_prepare(state);
218 error = suspend_ops->prepare(); 265 if (error)
219 if (error) 266 goto Platform_finish;
220 goto Platform_finish;
221 }
222 267
223 error = dpm_suspend_end(PMSG_SUSPEND); 268 error = dpm_suspend_end(PMSG_SUSPEND);
224 if (error) { 269 if (error) {
225 printk(KERN_ERR "PM: Some devices failed to power down\n"); 270 printk(KERN_ERR "PM: Some devices failed to power down\n");
226 goto Platform_finish; 271 goto Platform_finish;
227 } 272 }
228 273 error = platform_suspend_prepare_late(state);
229 if (need_suspend_ops(state) && suspend_ops->prepare_late) { 274 if (error)
230 error = suspend_ops->prepare_late(); 275 goto Platform_wake;
231 if (error)
232 goto Platform_wake;
233 }
234 276
235 if (suspend_test(TEST_PLATFORM)) 277 if (suspend_test(TEST_PLATFORM))
236 goto Platform_wake; 278 goto Platform_wake;
@@ -276,15 +318,11 @@ static int suspend_enter(suspend_state_t state, bool *wakeup)
276 enable_nonboot_cpus(); 318 enable_nonboot_cpus();
277 319
278 Platform_wake: 320 Platform_wake:
279 if (need_suspend_ops(state) && suspend_ops->wake) 321 platform_suspend_wake(state);
280 suspend_ops->wake();
281
282 dpm_resume_start(PMSG_RESUME); 322 dpm_resume_start(PMSG_RESUME);
283 323
284 Platform_finish: 324 Platform_finish:
285 if (need_suspend_ops(state) && suspend_ops->finish) 325 platform_suspend_finish(state);
286 suspend_ops->finish();
287
288 return error; 326 return error;
289} 327}
290 328
@@ -297,18 +335,13 @@ int suspend_devices_and_enter(suspend_state_t state)
297 int error; 335 int error;
298 bool wakeup = false; 336 bool wakeup = false;
299 337
300 if (need_suspend_ops(state) && !suspend_ops) 338 if (!sleep_state_supported(state))
301 return -ENOSYS; 339 return -ENOSYS;
302 340
303 if (need_suspend_ops(state) && suspend_ops->begin) { 341 error = platform_suspend_begin(state);
304 error = suspend_ops->begin(state); 342 if (error)
305 if (error) 343 goto Close;
306 goto Close; 344
307 } else if (state == PM_SUSPEND_FREEZE && freeze_ops && freeze_ops->begin) {
308 error = freeze_ops->begin();
309 if (error)
310 goto Close;
311 }
312 suspend_console(); 345 suspend_console();
313 suspend_test_start(); 346 suspend_test_start();
314 error = dpm_suspend_start(PMSG_SUSPEND); 347 error = dpm_suspend_start(PMSG_SUSPEND);
@@ -322,25 +355,20 @@ int suspend_devices_and_enter(suspend_state_t state)
322 355
323 do { 356 do {
324 error = suspend_enter(state, &wakeup); 357 error = suspend_enter(state, &wakeup);
325 } while (!error && !wakeup && need_suspend_ops(state) 358 } while (!error && !wakeup && platform_suspend_again(state));
326 && suspend_ops->suspend_again && suspend_ops->suspend_again());
327 359
328 Resume_devices: 360 Resume_devices:
329 suspend_test_start(); 361 suspend_test_start();
330 dpm_resume_end(PMSG_RESUME); 362 dpm_resume_end(PMSG_RESUME);
331 suspend_test_finish("resume devices"); 363 suspend_test_finish("resume devices");
332 resume_console(); 364 resume_console();
333 Close:
334 if (need_suspend_ops(state) && suspend_ops->end)
335 suspend_ops->end();
336 else if (state == PM_SUSPEND_FREEZE && freeze_ops && freeze_ops->end)
337 freeze_ops->end();
338 365
366 Close:
367 platform_suspend_end(state);
339 return error; 368 return error;
340 369
341 Recover_platform: 370 Recover_platform:
342 if (need_suspend_ops(state) && suspend_ops->recover) 371 platform_suspend_recover(state);
343 suspend_ops->recover();
344 goto Resume_devices; 372 goto Resume_devices;
345} 373}
346 374
@@ -393,7 +421,7 @@ static int enter_state(suspend_state_t state)
393 printk("done.\n"); 421 printk("done.\n");
394 trace_suspend_resume(TPS("sync_filesystems"), 0, false); 422 trace_suspend_resume(TPS("sync_filesystems"), 0, false);
395 423
396 pr_debug("PM: Preparing system for %s sleep\n", pm_states[state].label); 424 pr_debug("PM: Preparing system for %s sleep\n", pm_states[state]);
397 error = suspend_prepare(state); 425 error = suspend_prepare(state);
398 if (error) 426 if (error)
399 goto Unlock; 427 goto Unlock;
@@ -402,7 +430,7 @@ static int enter_state(suspend_state_t state)
402 goto Finish; 430 goto Finish;
403 431
404 trace_suspend_resume(TPS("suspend_enter"), state, false); 432 trace_suspend_resume(TPS("suspend_enter"), state, false);
405 pr_debug("PM: Entering %s sleep\n", pm_states[state].label); 433 pr_debug("PM: Entering %s sleep\n", pm_states[state]);
406 pm_restrict_gfp_mask(); 434 pm_restrict_gfp_mask();
407 error = suspend_devices_and_enter(state); 435 error = suspend_devices_and_enter(state);
408 pm_restore_gfp_mask(); 436 pm_restore_gfp_mask();
diff --git a/kernel/power/suspend_test.c b/kernel/power/suspend_test.c
index 269b097e78ea..2f524928b6aa 100644
--- a/kernel/power/suspend_test.c
+++ b/kernel/power/suspend_test.c
@@ -92,13 +92,13 @@ static void __init test_wakealarm(struct rtc_device *rtc, suspend_state_t state)
92 } 92 }
93 93
94 if (state == PM_SUSPEND_MEM) { 94 if (state == PM_SUSPEND_MEM) {
95 printk(info_test, pm_states[state].label); 95 printk(info_test, pm_states[state]);
96 status = pm_suspend(state); 96 status = pm_suspend(state);
97 if (status == -ENODEV) 97 if (status == -ENODEV)
98 state = PM_SUSPEND_STANDBY; 98 state = PM_SUSPEND_STANDBY;
99 } 99 }
100 if (state == PM_SUSPEND_STANDBY) { 100 if (state == PM_SUSPEND_STANDBY) {
101 printk(info_test, pm_states[state].label); 101 printk(info_test, pm_states[state]);
102 status = pm_suspend(state); 102 status = pm_suspend(state);
103 } 103 }
104 if (status < 0) 104 if (status < 0)
@@ -141,8 +141,8 @@ static int __init setup_test_suspend(char *value)
141 /* "=mem" ==> "mem" */ 141 /* "=mem" ==> "mem" */
142 value++; 142 value++;
143 for (i = PM_SUSPEND_MIN; i < PM_SUSPEND_MAX; i++) 143 for (i = PM_SUSPEND_MIN; i < PM_SUSPEND_MAX; i++)
144 if (!strcmp(pm_states[i].label, value)) { 144 if (!strcmp(pm_states[i], value)) {
145 test_state = pm_states[i].state; 145 test_state = i;
146 return 0; 146 return 0;
147 } 147 }
148 148
@@ -162,8 +162,8 @@ static int __init test_suspend(void)
162 /* PM is initialized by now; is that state testable? */ 162 /* PM is initialized by now; is that state testable? */
163 if (test_state == PM_SUSPEND_ON) 163 if (test_state == PM_SUSPEND_ON)
164 goto done; 164 goto done;
165 if (!pm_states[test_state].state) { 165 if (!pm_states[test_state]) {
166 printk(warn_bad_state, pm_states[test_state].label); 166 printk(warn_bad_state, pm_states[test_state]);
167 goto done; 167 goto done;
168 } 168 }
169 169
diff --git a/kernel/sched/idle.c b/kernel/sched/idle.c
index 9f1608f99819..11e7bc434f43 100644
--- a/kernel/sched/idle.c
+++ b/kernel/sched/idle.c
@@ -147,8 +147,6 @@ use_default:
147 clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &dev->cpu)) 147 clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &dev->cpu))
148 goto use_default; 148 goto use_default;
149 149
150 trace_cpu_idle_rcuidle(next_state, dev->cpu);
151
152 /* 150 /*
153 * Enter the idle state previously returned by the governor decision. 151 * Enter the idle state previously returned by the governor decision.
154 * This function will block until an interrupt occurs and will take 152 * This function will block until an interrupt occurs and will take
@@ -156,8 +154,6 @@ use_default:
156 */ 154 */
157 entered_state = cpuidle_enter(drv, dev, next_state); 155 entered_state = cpuidle_enter(drv, dev, next_state);
158 156
159 trace_cpu_idle_rcuidle(PWR_EVENT_EXIT, dev->cpu);
160
161 if (broadcast) 157 if (broadcast)
162 clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &dev->cpu); 158 clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &dev->cpu);
163 159
diff --git a/tools/power/acpi/Makefile b/tools/power/acpi/Makefile
index e5a3c4be2a10..3d1537b93c64 100644
--- a/tools/power/acpi/Makefile
+++ b/tools/power/acpi/Makefile
@@ -108,13 +108,18 @@ DUMP_OBJS = \
108 apmain.o\ 108 apmain.o\
109 osunixdir.o\ 109 osunixdir.o\
110 osunixmap.o\ 110 osunixmap.o\
111 osunixxf.o\
111 tbprint.o\ 112 tbprint.o\
112 tbxfroot.o\ 113 tbxfroot.o\
113 utbuffer.o\ 114 utbuffer.o\
115 utdebug.o\
114 utexcep.o\ 116 utexcep.o\
117 utglobal.o\
115 utmath.o\ 118 utmath.o\
119 utprint.o\
116 utstring.o\ 120 utstring.o\
117 utxferror.o\ 121 utxferror.o\
122 oslibcfs.o\
118 oslinuxtbl.o\ 123 oslinuxtbl.o\
119 cmfsize.o\ 124 cmfsize.o\
120 getopt.o 125 getopt.o
diff --git a/tools/power/acpi/common/cmfsize.c b/tools/power/acpi/common/cmfsize.c
index 5140e5edae1f..f4b953354ff7 100644
--- a/tools/power/acpi/common/cmfsize.c
+++ b/tools/power/acpi/common/cmfsize.c
@@ -58,44 +58,46 @@ ACPI_MODULE_NAME("cmfsize")
58 * RETURN: File Size. On error, -1 (ACPI_UINT32_MAX) 58 * RETURN: File Size. On error, -1 (ACPI_UINT32_MAX)
59 * 59 *
60 * DESCRIPTION: Get the size of a file. Uses seek-to-EOF. File must be open. 60 * DESCRIPTION: Get the size of a file. Uses seek-to-EOF. File must be open.
61 * Does not disturb the current file pointer. Uses perror for 61 * Does not disturb the current file pointer.
62 * error messages.
63 * 62 *
64 ******************************************************************************/ 63 ******************************************************************************/
65u32 cm_get_file_size(FILE * file) 64u32 cm_get_file_size(ACPI_FILE file)
66{ 65{
67 long file_size; 66 long file_size;
68 long current_offset; 67 long current_offset;
68 acpi_status status;
69 69
70 /* Save the current file pointer, seek to EOF to obtain file size */ 70 /* Save the current file pointer, seek to EOF to obtain file size */
71 71
72 current_offset = ftell(file); 72 current_offset = acpi_os_get_file_offset(file);
73 if (current_offset < 0) { 73 if (current_offset < 0) {
74 goto offset_error; 74 goto offset_error;
75 } 75 }
76 76
77 if (fseek(file, 0, SEEK_END)) { 77 status = acpi_os_set_file_offset(file, 0, ACPI_FILE_END);
78 if (ACPI_FAILURE(status)) {
78 goto seek_error; 79 goto seek_error;
79 } 80 }
80 81
81 file_size = ftell(file); 82 file_size = acpi_os_get_file_offset(file);
82 if (file_size < 0) { 83 if (file_size < 0) {
83 goto offset_error; 84 goto offset_error;
84 } 85 }
85 86
86 /* Restore original file pointer */ 87 /* Restore original file pointer */
87 88
88 if (fseek(file, current_offset, SEEK_SET)) { 89 status = acpi_os_set_file_offset(file, current_offset, ACPI_FILE_BEGIN);
90 if (ACPI_FAILURE(status)) {
89 goto seek_error; 91 goto seek_error;
90 } 92 }
91 93
92 return ((u32)file_size); 94 return ((u32)file_size);
93 95
94offset_error: 96offset_error:
95 perror("Could not get file offset"); 97 acpi_log_error("Could not get file offset");
96 return (ACPI_UINT32_MAX); 98 return (ACPI_UINT32_MAX);
97 99
98seek_error: 100seek_error:
99 perror("Could not seek file"); 101 acpi_log_error("Could not set file offset");
100 return (ACPI_UINT32_MAX); 102 return (ACPI_UINT32_MAX);
101} 103}
diff --git a/tools/power/acpi/common/getopt.c b/tools/power/acpi/common/getopt.c
index a302f52e4fd3..2f0f34a36db4 100644
--- a/tools/power/acpi/common/getopt.c
+++ b/tools/power/acpi/common/getopt.c
@@ -51,14 +51,12 @@
51 * "f|" - Option has required single-char sub-options 51 * "f|" - Option has required single-char sub-options
52 */ 52 */
53 53
54#include <stdio.h>
55#include <string.h>
56#include <acpi/acpi.h> 54#include <acpi/acpi.h>
57#include "accommon.h" 55#include "accommon.h"
58#include "acapps.h" 56#include "acapps.h"
59 57
60#define ACPI_OPTION_ERROR(msg, badchar) \ 58#define ACPI_OPTION_ERROR(msg, badchar) \
61 if (acpi_gbl_opterr) {fprintf (stderr, "%s%c\n", msg, badchar);} 59 if (acpi_gbl_opterr) {acpi_log_error ("%s%c\n", msg, badchar);}
62 60
63int acpi_gbl_opterr = 1; 61int acpi_gbl_opterr = 1;
64int acpi_gbl_optind = 1; 62int acpi_gbl_optind = 1;
@@ -113,7 +111,7 @@ int acpi_getopt_argument(int argc, char **argv)
113 * PARAMETERS: argc, argv - from main 111 * PARAMETERS: argc, argv - from main
114 * opts - options info list 112 * opts - options info list
115 * 113 *
116 * RETURN: Option character or EOF 114 * RETURN: Option character or ACPI_OPT_END
117 * 115 *
118 * DESCRIPTION: Get the next option 116 * DESCRIPTION: Get the next option
119 * 117 *
@@ -128,10 +126,10 @@ int acpi_getopt(int argc, char **argv, char *opts)
128 if (acpi_gbl_optind >= argc || 126 if (acpi_gbl_optind >= argc ||
129 argv[acpi_gbl_optind][0] != '-' || 127 argv[acpi_gbl_optind][0] != '-' ||
130 argv[acpi_gbl_optind][1] == '\0') { 128 argv[acpi_gbl_optind][1] == '\0') {
131 return (EOF); 129 return (ACPI_OPT_END);
132 } else if (strcmp(argv[acpi_gbl_optind], "--") == 0) { 130 } else if (ACPI_STRCMP(argv[acpi_gbl_optind], "--") == 0) {
133 acpi_gbl_optind++; 131 acpi_gbl_optind++;
134 return (EOF); 132 return (ACPI_OPT_END);
135 } 133 }
136 } 134 }
137 135
@@ -142,7 +140,7 @@ int acpi_getopt(int argc, char **argv, char *opts)
142 /* Make sure that the option is legal */ 140 /* Make sure that the option is legal */
143 141
144 if (current_char == ':' || 142 if (current_char == ':' ||
145 (opts_ptr = strchr(opts, current_char)) == NULL) { 143 (opts_ptr = ACPI_STRCHR(opts, current_char)) == NULL) {
146 ACPI_OPTION_ERROR("Illegal option: -", current_char); 144 ACPI_OPTION_ERROR("Illegal option: -", current_char);
147 145
148 if (argv[acpi_gbl_optind][++current_char_ptr] == '\0') { 146 if (argv[acpi_gbl_optind][++current_char_ptr] == '\0') {
diff --git a/tools/power/acpi/os_specific/service_layers/oslibcfs.c b/tools/power/acpi/os_specific/service_layers/oslibcfs.c
new file mode 100644
index 000000000000..c13ff9c51d74
--- /dev/null
+++ b/tools/power/acpi/os_specific/service_layers/oslibcfs.c
@@ -0,0 +1,214 @@
1/******************************************************************************
2 *
3 * Module Name: oslibcfs - C library OSL for file I/O
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2014, Intel Corp.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
44#include <acpi/acpi.h>
45#include <stdio.h>
46#include <stdarg.h>
47
48#define _COMPONENT ACPI_OS_SERVICES
49ACPI_MODULE_NAME("oslibcfs")
50
51/*******************************************************************************
52 *
53 * FUNCTION: acpi_os_open_file
54 *
55 * PARAMETERS: path - File path
56 * modes - File operation type
57 *
58 * RETURN: File descriptor.
59 *
60 * DESCRIPTION: Open a file for reading (ACPI_FILE_READING) or/and writing
61 * (ACPI_FILE_WRITING).
62 *
63 ******************************************************************************/
64ACPI_FILE acpi_os_open_file(const char *path, u8 modes)
65{
66 ACPI_FILE file;
67 u32 i = 0;
68 char modes_str[4];
69
70 if (modes & ACPI_FILE_READING) {
71 modes_str[i++] = 'r';
72 }
73 if (modes & ACPI_FILE_WRITING) {
74 modes_str[i++] = 'w';
75 }
76 if (modes & ACPI_FILE_BINARY) {
77 modes_str[i++] = 'b';
78 }
79
80 modes_str[i++] = '\0';
81
82 file = fopen(path, modes_str);
83 if (!file) {
84 perror("Could not open file");
85 }
86
87 return (file);
88}
89
90/*******************************************************************************
91 *
92 * FUNCTION: acpi_os_close_file
93 *
94 * PARAMETERS: file - An open file descriptor
95 *
96 * RETURN: None.
97 *
98 * DESCRIPTION: Close a file opened via acpi_os_open_file.
99 *
100 ******************************************************************************/
101
102void acpi_os_close_file(ACPI_FILE file)
103{
104 fclose(file);
105}
106
107/*******************************************************************************
108 *
109 * FUNCTION: acpi_os_read_file
110 *
111 * PARAMETERS: file - An open file descriptor
112 * buffer - Data buffer
113 * size - Data block size
114 * count - Number of data blocks
115 *
116 * RETURN: Number of bytes actually read.
117 *
118 * DESCRIPTION: Read from a file.
119 *
120 ******************************************************************************/
121
122int
123acpi_os_read_file(ACPI_FILE file, void *buffer, acpi_size size, acpi_size count)
124{
125 int length;
126
127 length = fread(buffer, size, count, file);
128 if (length < 0) {
129 perror("Error reading file");
130 }
131
132 return (length);
133}
134
135/*******************************************************************************
136 *
137 * FUNCTION: acpi_os_write_file
138 *
139 * PARAMETERS: file - An open file descriptor
140 * buffer - Data buffer
141 * size - Data block size
142 * count - Number of data blocks
143 *
144 * RETURN: Number of bytes actually written.
145 *
146 * DESCRIPTION: Write to a file.
147 *
148 ******************************************************************************/
149
150int
151acpi_os_write_file(ACPI_FILE file,
152 void *buffer, acpi_size size, acpi_size count)
153{
154 int length;
155
156 length = fwrite(buffer, size, count, file);
157 if (length < 0) {
158 perror("Error writing file");
159 }
160
161 return (length);
162}
163
164/*******************************************************************************
165 *
166 * FUNCTION: acpi_os_get_file_offset
167 *
168 * PARAMETERS: file - An open file descriptor
169 *
170 * RETURN: Current file pointer position.
171 *
172 * DESCRIPTION: Get current file offset.
173 *
174 ******************************************************************************/
175
176long acpi_os_get_file_offset(ACPI_FILE file)
177{
178 long offset;
179
180 offset = ftell(file);
181 return (offset);
182}
183
184/*******************************************************************************
185 *
186 * FUNCTION: acpi_os_set_file_offset
187 *
188 * PARAMETERS: file - An open file descriptor
189 * offset - New file offset
190 * from - From begin/end of file
191 *
192 * RETURN: Status
193 *
194 * DESCRIPTION: Set current file offset.
195 *
196 ******************************************************************************/
197
198acpi_status acpi_os_set_file_offset(ACPI_FILE file, long offset, u8 from)
199{
200 int ret = 0;
201
202 if (from == ACPI_FILE_BEGIN) {
203 ret = fseek(file, offset, SEEK_SET);
204 }
205 if (from == ACPI_FILE_END) {
206 ret = fseek(file, offset, SEEK_END);
207 }
208
209 if (ret < 0) {
210 return (AE_ERROR);
211 } else {
212 return (AE_OK);
213 }
214}
diff --git a/tools/power/acpi/os_specific/service_layers/oslinuxtbl.c b/tools/power/acpi/os_specific/service_layers/oslinuxtbl.c
index 28c52008e854..0dc2485dedf5 100644
--- a/tools/power/acpi/os_specific/service_layers/oslinuxtbl.c
+++ b/tools/power/acpi/os_specific/service_layers/oslinuxtbl.c
@@ -77,6 +77,9 @@ osl_map_table(acpi_size address,
77 77
78static void osl_unmap_table(struct acpi_table_header *table); 78static void osl_unmap_table(struct acpi_table_header *table);
79 79
80static acpi_physical_address
81osl_find_rsdp_via_efi_by_keyword(FILE * file, const char *keyword);
82
80static acpi_physical_address osl_find_rsdp_via_efi(void); 83static acpi_physical_address osl_find_rsdp_via_efi(void);
81 84
82static acpi_status osl_load_rsdp(void); 85static acpi_status osl_load_rsdp(void);
@@ -417,6 +420,38 @@ acpi_os_get_table_by_index(u32 index,
417 420
418/****************************************************************************** 421/******************************************************************************
419 * 422 *
423 * FUNCTION: osl_find_rsdp_via_efi_by_keyword
424 *
425 * PARAMETERS: keyword - Character string indicating ACPI GUID version
426 * in the EFI table
427 *
428 * RETURN: RSDP address if found
429 *
430 * DESCRIPTION: Find RSDP address via EFI using keyword indicating the ACPI
431 * GUID version.
432 *
433 *****************************************************************************/
434
435static acpi_physical_address
436osl_find_rsdp_via_efi_by_keyword(FILE * file, const char *keyword)
437{
438 char buffer[80];
439 unsigned long long address = 0;
440 char format[32];
441
442 snprintf(format, 32, "%s=%s", keyword, "%llx");
443 fseek(file, 0, SEEK_SET);
444 while (fgets(buffer, 80, file)) {
445 if (sscanf(buffer, format, &address) == 1) {
446 break;
447 }
448 }
449
450 return ((acpi_physical_address) (address));
451}
452
453/******************************************************************************
454 *
420 * FUNCTION: osl_find_rsdp_via_efi 455 * FUNCTION: osl_find_rsdp_via_efi
421 * 456 *
422 * PARAMETERS: None 457 * PARAMETERS: None
@@ -430,20 +465,19 @@ acpi_os_get_table_by_index(u32 index,
430static acpi_physical_address osl_find_rsdp_via_efi(void) 465static acpi_physical_address osl_find_rsdp_via_efi(void)
431{ 466{
432 FILE *file; 467 FILE *file;
433 char buffer[80]; 468 acpi_physical_address address = 0;
434 unsigned long address = 0;
435 469
436 file = fopen(EFI_SYSTAB, "r"); 470 file = fopen(EFI_SYSTAB, "r");
437 if (file) { 471 if (file) {
438 while (fgets(buffer, 80, file)) { 472 address = osl_find_rsdp_via_efi_by_keyword(file, "ACPI20");
439 if (sscanf(buffer, "ACPI20=0x%lx", &address) == 1) { 473 if (!address) {
440 break; 474 address =
441 } 475 osl_find_rsdp_via_efi_by_keyword(file, "ACPI");
442 } 476 }
443 fclose(file); 477 fclose(file);
444 } 478 }
445 479
446 return ((acpi_physical_address) (address)); 480 return (address);
447} 481}
448 482
449/****************************************************************************** 483/******************************************************************************
diff --git a/tools/power/acpi/os_specific/service_layers/osunixxf.c b/tools/power/acpi/os_specific/service_layers/osunixxf.c
new file mode 100644
index 000000000000..60b58cd18410
--- /dev/null
+++ b/tools/power/acpi/os_specific/service_layers/osunixxf.c
@@ -0,0 +1,1311 @@
1/******************************************************************************
2 *
3 * Module Name: osunixxf - UNIX OSL interfaces
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2014, Intel Corp.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
44/*
45 * These interfaces are required in order to compile the ASL compiler and the
46 * various ACPICA tools under Linux or other Unix-like system.
47 */
48#include <acpi/acpi.h>
49#include "accommon.h"
50#include "amlcode.h"
51#include "acparser.h"
52#include "acdebug.h"
53
54#include <stdio.h>
55#include <stdlib.h>
56#include <stdarg.h>
57#include <unistd.h>
58#include <sys/time.h>
59#include <semaphore.h>
60#include <pthread.h>
61#include <errno.h>
62
63#define _COMPONENT ACPI_OS_SERVICES
64ACPI_MODULE_NAME("osunixxf")
65
66u8 acpi_gbl_debug_timeout = FALSE;
67
68/* Upcalls to acpi_exec */
69
70void
71ae_table_override(struct acpi_table_header *existing_table,
72 struct acpi_table_header **new_table);
73
74typedef void *(*PTHREAD_CALLBACK) (void *);
75
76/* Buffer used by acpi_os_vprintf */
77
78#define ACPI_VPRINTF_BUFFER_SIZE 512
79#define _ASCII_NEWLINE '\n'
80
81/* Terminal support for acpi_exec only */
82
83#ifdef ACPI_EXEC_APP
84#include <termios.h>
85
86struct termios original_term_attributes;
87int term_attributes_were_set = 0;
88
89acpi_status acpi_ut_read_line(char *buffer, u32 buffer_length, u32 *bytes_read);
90
91static void os_enter_line_edit_mode(void);
92
93static void os_exit_line_edit_mode(void);
94
95/******************************************************************************
96 *
97 * FUNCTION: os_enter_line_edit_mode, os_exit_line_edit_mode
98 *
99 * PARAMETERS: None
100 *
101 * RETURN: None
102 *
103 * DESCRIPTION: Enter/Exit the raw character input mode for the terminal.
104 *
105 * Interactive line-editing support for the AML debugger. Used with the
106 * common/acgetline module.
107 *
108 * readline() is not used because of non-portability. It is not available
109 * on all systems, and if it is, often the package must be manually installed.
110 *
111 * Therefore, we use the POSIX tcgetattr/tcsetattr and do the minimal line
112 * editing that we need in acpi_os_get_line.
113 *
114 * If the POSIX tcgetattr/tcsetattr interfaces are unavailable, these
115 * calls will also work:
116 * For os_enter_line_edit_mode: system ("stty cbreak -echo")
117 * For os_exit_line_edit_mode: system ("stty cooked echo")
118 *
119 *****************************************************************************/
120
121static void os_enter_line_edit_mode(void)
122{
123 struct termios local_term_attributes;
124
125 /* Get and keep the original attributes */
126
127 if (tcgetattr(STDIN_FILENO, &original_term_attributes)) {
128 fprintf(stderr, "Could not get terminal attributes!\n");
129 return;
130 }
131
132 /* Set the new attributes to enable raw character input */
133
134 memcpy(&local_term_attributes, &original_term_attributes,
135 sizeof(struct termios));
136
137 local_term_attributes.c_lflag &= ~(ICANON | ECHO);
138 local_term_attributes.c_cc[VMIN] = 1;
139 local_term_attributes.c_cc[VTIME] = 0;
140
141 if (tcsetattr(STDIN_FILENO, TCSANOW, &local_term_attributes)) {
142 fprintf(stderr, "Could not set terminal attributes!\n");
143 return;
144 }
145
146 term_attributes_were_set = 1;
147}
148
149static void os_exit_line_edit_mode(void)
150{
151
152 if (!term_attributes_were_set) {
153 return;
154 }
155
156 /* Set terminal attributes back to the original values */
157
158 if (tcsetattr(STDIN_FILENO, TCSANOW, &original_term_attributes)) {
159 fprintf(stderr, "Could not restore terminal attributes!\n");
160 }
161}
162
163#else
164
165/* These functions are not needed for other ACPICA utilities */
166
167#define os_enter_line_edit_mode()
168#define os_exit_line_edit_mode()
169#endif
170
171/******************************************************************************
172 *
173 * FUNCTION: acpi_os_initialize, acpi_os_terminate
174 *
175 * PARAMETERS: None
176 *
177 * RETURN: Status
178 *
179 * DESCRIPTION: Initialize and terminate this module.
180 *
181 *****************************************************************************/
182
183acpi_status acpi_os_initialize(void)
184{
185 acpi_status status;
186
187 acpi_gbl_output_file = stdout;
188
189 os_enter_line_edit_mode();
190
191 status = acpi_os_create_lock(&acpi_gbl_print_lock);
192 if (ACPI_FAILURE(status)) {
193 return (status);
194 }
195
196 return (AE_OK);
197}
198
199acpi_status acpi_os_terminate(void)
200{
201
202 os_exit_line_edit_mode();
203 return (AE_OK);
204}
205
206#ifndef ACPI_USE_NATIVE_RSDP_POINTER
207/******************************************************************************
208 *
209 * FUNCTION: acpi_os_get_root_pointer
210 *
211 * PARAMETERS: None
212 *
213 * RETURN: RSDP physical address
214 *
215 * DESCRIPTION: Gets the ACPI root pointer (RSDP)
216 *
217 *****************************************************************************/
218
219acpi_physical_address acpi_os_get_root_pointer(void)
220{
221
222 return (0);
223}
224#endif
225
226/******************************************************************************
227 *
228 * FUNCTION: acpi_os_predefined_override
229 *
230 * PARAMETERS: init_val - Initial value of the predefined object
231 * new_val - The new value for the object
232 *
233 * RETURN: Status, pointer to value. Null pointer returned if not
234 * overriding.
235 *
236 * DESCRIPTION: Allow the OS to override predefined names
237 *
238 *****************************************************************************/
239
240acpi_status
241acpi_os_predefined_override(const struct acpi_predefined_names * init_val,
242 acpi_string * new_val)
243{
244
245 if (!init_val || !new_val) {
246 return (AE_BAD_PARAMETER);
247 }
248
249 *new_val = NULL;
250 return (AE_OK);
251}
252
253/******************************************************************************
254 *
255 * FUNCTION: acpi_os_table_override
256 *
257 * PARAMETERS: existing_table - Header of current table (probably
258 * firmware)
259 * new_table - Where an entire new table is returned.
260 *
261 * RETURN: Status, pointer to new table. Null pointer returned if no
262 * table is available to override
263 *
264 * DESCRIPTION: Return a different version of a table if one is available
265 *
266 *****************************************************************************/
267
268acpi_status
269acpi_os_table_override(struct acpi_table_header * existing_table,
270 struct acpi_table_header ** new_table)
271{
272
273 if (!existing_table || !new_table) {
274 return (AE_BAD_PARAMETER);
275 }
276
277 *new_table = NULL;
278
279#ifdef ACPI_EXEC_APP
280
281 ae_table_override(existing_table, new_table);
282 return (AE_OK);
283#else
284
285 return (AE_NO_ACPI_TABLES);
286#endif
287}
288
289/******************************************************************************
290 *
291 * FUNCTION: acpi_os_physical_table_override
292 *
293 * PARAMETERS: existing_table - Header of current table (probably firmware)
294 * new_address - Where new table address is returned
295 * (Physical address)
296 * new_table_length - Where new table length is returned
297 *
298 * RETURN: Status, address/length of new table. Null pointer returned
299 * if no table is available to override.
300 *
301 * DESCRIPTION: Returns AE_SUPPORT, function not used in user space.
302 *
303 *****************************************************************************/
304
305acpi_status
306acpi_os_physical_table_override(struct acpi_table_header * existing_table,
307 acpi_physical_address * new_address,
308 u32 *new_table_length)
309{
310
311 return (AE_SUPPORT);
312}
313
314/******************************************************************************
315 *
316 * FUNCTION: acpi_os_redirect_output
317 *
318 * PARAMETERS: destination - An open file handle/pointer
319 *
320 * RETURN: None
321 *
322 * DESCRIPTION: Causes redirect of acpi_os_printf and acpi_os_vprintf
323 *
324 *****************************************************************************/
325
326void acpi_os_redirect_output(void *destination)
327{
328
329 acpi_gbl_output_file = destination;
330}
331
332/******************************************************************************
333 *
334 * FUNCTION: acpi_os_printf
335 *
336 * PARAMETERS: fmt, ... - Standard printf format
337 *
338 * RETURN: None
339 *
340 * DESCRIPTION: Formatted output. Note: very similar to acpi_os_vprintf
341 * (performance), changes should be tracked in both functions.
342 *
343 *****************************************************************************/
344
345void ACPI_INTERNAL_VAR_XFACE acpi_os_printf(const char *fmt, ...)
346{
347 va_list args;
348 u8 flags;
349
350 flags = acpi_gbl_db_output_flags;
351 if (flags & ACPI_DB_REDIRECTABLE_OUTPUT) {
352
353 /* Output is directable to either a file (if open) or the console */
354
355 if (acpi_gbl_debug_file) {
356
357 /* Output file is open, send the output there */
358
359 va_start(args, fmt);
360 vfprintf(acpi_gbl_debug_file, fmt, args);
361 va_end(args);
362 } else {
363 /* No redirection, send output to console (once only!) */
364
365 flags |= ACPI_DB_CONSOLE_OUTPUT;
366 }
367 }
368
369 if (flags & ACPI_DB_CONSOLE_OUTPUT) {
370 va_start(args, fmt);
371 vfprintf(acpi_gbl_output_file, fmt, args);
372 va_end(args);
373 }
374}
375
376/******************************************************************************
377 *
378 * FUNCTION: acpi_os_vprintf
379 *
380 * PARAMETERS: fmt - Standard printf format
381 * args - Argument list
382 *
383 * RETURN: None
384 *
385 * DESCRIPTION: Formatted output with argument list pointer. Note: very
386 * similar to acpi_os_printf, changes should be tracked in both
387 * functions.
388 *
389 *****************************************************************************/
390
391void acpi_os_vprintf(const char *fmt, va_list args)
392{
393 u8 flags;
394 char buffer[ACPI_VPRINTF_BUFFER_SIZE];
395
396 /*
397 * We build the output string in a local buffer because we may be
398 * outputting the buffer twice. Using vfprintf is problematic because
399 * some implementations modify the args pointer/structure during
400 * execution. Thus, we use the local buffer for portability.
401 *
402 * Note: Since this module is intended for use by the various ACPICA
403 * utilities/applications, we can safely declare the buffer on the stack.
404 * Also, This function is used for relatively small error messages only.
405 */
406 vsnprintf(buffer, ACPI_VPRINTF_BUFFER_SIZE, fmt, args);
407
408 flags = acpi_gbl_db_output_flags;
409 if (flags & ACPI_DB_REDIRECTABLE_OUTPUT) {
410
411 /* Output is directable to either a file (if open) or the console */
412
413 if (acpi_gbl_debug_file) {
414
415 /* Output file is open, send the output there */
416
417 fputs(buffer, acpi_gbl_debug_file);
418 } else {
419 /* No redirection, send output to console (once only!) */
420
421 flags |= ACPI_DB_CONSOLE_OUTPUT;
422 }
423 }
424
425 if (flags & ACPI_DB_CONSOLE_OUTPUT) {
426 fputs(buffer, acpi_gbl_output_file);
427 }
428}
429
430#ifndef ACPI_EXEC_APP
431/******************************************************************************
432 *
433 * FUNCTION: acpi_os_get_line
434 *
435 * PARAMETERS: buffer - Where to return the command line
436 * buffer_length - Maximum length of Buffer
437 * bytes_read - Where the actual byte count is returned
438 *
439 * RETURN: Status and actual bytes read
440 *
441 * DESCRIPTION: Get the next input line from the terminal. NOTE: For the
442 * acpi_exec utility, we use the acgetline module instead to
443 * provide line-editing and history support.
444 *
445 *****************************************************************************/
446
447acpi_status acpi_os_get_line(char *buffer, u32 buffer_length, u32 *bytes_read)
448{
449 int input_char;
450 u32 end_of_line;
451
452 /* Standard acpi_os_get_line for all utilities except acpi_exec */
453
454 for (end_of_line = 0;; end_of_line++) {
455 if (end_of_line >= buffer_length) {
456 return (AE_BUFFER_OVERFLOW);
457 }
458
459 if ((input_char = getchar()) == EOF) {
460 return (AE_ERROR);
461 }
462
463 if (!input_char || input_char == _ASCII_NEWLINE) {
464 break;
465 }
466
467 buffer[end_of_line] = (char)input_char;
468 }
469
470 /* Null terminate the buffer */
471
472 buffer[end_of_line] = 0;
473
474 /* Return the number of bytes in the string */
475
476 if (bytes_read) {
477 *bytes_read = end_of_line;
478 }
479
480 return (AE_OK);
481}
482#endif
483
484#ifndef ACPI_USE_NATIVE_MEMORY_MAPPING
485/******************************************************************************
486 *
487 * FUNCTION: acpi_os_map_memory
488 *
489 * PARAMETERS: where - Physical address of memory to be mapped
490 * length - How much memory to map
491 *
492 * RETURN: Pointer to mapped memory. Null on error.
493 *
494 * DESCRIPTION: Map physical memory into caller's address space
495 *
496 *****************************************************************************/
497
498void *acpi_os_map_memory(acpi_physical_address where, acpi_size length)
499{
500
501 return (ACPI_TO_POINTER((acpi_size) where));
502}
503
504/******************************************************************************
505 *
506 * FUNCTION: acpi_os_unmap_memory
507 *
508 * PARAMETERS: where - Logical address of memory to be unmapped
509 * length - How much memory to unmap
510 *
511 * RETURN: None.
512 *
513 * DESCRIPTION: Delete a previously created mapping. Where and Length must
514 * correspond to a previous mapping exactly.
515 *
516 *****************************************************************************/
517
518void acpi_os_unmap_memory(void *where, acpi_size length)
519{
520
521 return;
522}
523#endif
524
525/******************************************************************************
526 *
527 * FUNCTION: acpi_os_allocate
528 *
529 * PARAMETERS: size - Amount to allocate, in bytes
530 *
531 * RETURN: Pointer to the new allocation. Null on error.
532 *
533 * DESCRIPTION: Allocate memory. Algorithm is dependent on the OS.
534 *
535 *****************************************************************************/
536
537void *acpi_os_allocate(acpi_size size)
538{
539 void *mem;
540
541 mem = (void *)malloc((size_t) size);
542 return (mem);
543}
544
545#ifdef USE_NATIVE_ALLOCATE_ZEROED
546/******************************************************************************
547 *
548 * FUNCTION: acpi_os_allocate_zeroed
549 *
550 * PARAMETERS: size - Amount to allocate, in bytes
551 *
552 * RETURN: Pointer to the new allocation. Null on error.
553 *
554 * DESCRIPTION: Allocate and zero memory. Algorithm is dependent on the OS.
555 *
556 *****************************************************************************/
557
558void *acpi_os_allocate_zeroed(acpi_size size)
559{
560 void *mem;
561
562 mem = (void *)calloc(1, (size_t) size);
563 return (mem);
564}
565#endif
566
567/******************************************************************************
568 *
569 * FUNCTION: acpi_os_free
570 *
571 * PARAMETERS: mem - Pointer to previously allocated memory
572 *
573 * RETURN: None.
574 *
575 * DESCRIPTION: Free memory allocated via acpi_os_allocate
576 *
577 *****************************************************************************/
578
579void acpi_os_free(void *mem)
580{
581
582 free(mem);
583}
584
585#ifdef ACPI_SINGLE_THREADED
586/******************************************************************************
587 *
588 * FUNCTION: Semaphore stub functions
589 *
590 * DESCRIPTION: Stub functions used for single-thread applications that do
591 * not require semaphore synchronization. Full implementations
592 * of these functions appear after the stubs.
593 *
594 *****************************************************************************/
595
596acpi_status
597acpi_os_create_semaphore(u32 max_units,
598 u32 initial_units, acpi_handle * out_handle)
599{
600 *out_handle = (acpi_handle) 1;
601 return (AE_OK);
602}
603
604acpi_status acpi_os_delete_semaphore(acpi_handle handle)
605{
606 return (AE_OK);
607}
608
609acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout)
610{
611 return (AE_OK);
612}
613
614acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units)
615{
616 return (AE_OK);
617}
618
619#else
620/******************************************************************************
621 *
622 * FUNCTION: acpi_os_create_semaphore
623 *
624 * PARAMETERS: initial_units - Units to be assigned to the new semaphore
625 * out_handle - Where a handle will be returned
626 *
627 * RETURN: Status
628 *
629 * DESCRIPTION: Create an OS semaphore
630 *
631 *****************************************************************************/
632
633acpi_status
634acpi_os_create_semaphore(u32 max_units,
635 u32 initial_units, acpi_handle * out_handle)
636{
637 sem_t *sem;
638
639 if (!out_handle) {
640 return (AE_BAD_PARAMETER);
641 }
642#ifdef __APPLE__
643 {
644 char *semaphore_name = tmpnam(NULL);
645
646 sem =
647 sem_open(semaphore_name, O_EXCL | O_CREAT, 0755,
648 initial_units);
649 if (!sem) {
650 return (AE_NO_MEMORY);
651 }
652 sem_unlink(semaphore_name); /* This just deletes the name */
653 }
654
655#else
656 sem = acpi_os_allocate(sizeof(sem_t));
657 if (!sem) {
658 return (AE_NO_MEMORY);
659 }
660
661 if (sem_init(sem, 0, initial_units) == -1) {
662 acpi_os_free(sem);
663 return (AE_BAD_PARAMETER);
664 }
665#endif
666
667 *out_handle = (acpi_handle) sem;
668 return (AE_OK);
669}
670
671/******************************************************************************
672 *
673 * FUNCTION: acpi_os_delete_semaphore
674 *
675 * PARAMETERS: handle - Handle returned by acpi_os_create_semaphore
676 *
677 * RETURN: Status
678 *
679 * DESCRIPTION: Delete an OS semaphore
680 *
681 *****************************************************************************/
682
683acpi_status acpi_os_delete_semaphore(acpi_handle handle)
684{
685 sem_t *sem = (sem_t *) handle;
686
687 if (!sem) {
688 return (AE_BAD_PARAMETER);
689 }
690
691 if (sem_destroy(sem) == -1) {
692 return (AE_BAD_PARAMETER);
693 }
694
695 return (AE_OK);
696}
697
698/******************************************************************************
699 *
700 * FUNCTION: acpi_os_wait_semaphore
701 *
702 * PARAMETERS: handle - Handle returned by acpi_os_create_semaphore
703 * units - How many units to wait for
704 * msec_timeout - How long to wait (milliseconds)
705 *
706 * RETURN: Status
707 *
708 * DESCRIPTION: Wait for units
709 *
710 *****************************************************************************/
711
712acpi_status
713acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 msec_timeout)
714{
715 acpi_status status = AE_OK;
716 sem_t *sem = (sem_t *) handle;
717#ifndef ACPI_USE_ALTERNATE_TIMEOUT
718 struct timespec time;
719 int ret_val;
720#endif
721
722 if (!sem) {
723 return (AE_BAD_PARAMETER);
724 }
725
726 switch (msec_timeout) {
727 /*
728 * No Wait:
729 * --------
730 * A zero timeout value indicates that we shouldn't wait - just
731 * acquire the semaphore if available otherwise return AE_TIME
732 * (a.k.a. 'would block').
733 */
734 case 0:
735
736 if (sem_trywait(sem) == -1) {
737 status = (AE_TIME);
738 }
739 break;
740
741 /* Wait Indefinitely */
742
743 case ACPI_WAIT_FOREVER:
744
745 if (sem_wait(sem)) {
746 status = (AE_TIME);
747 }
748 break;
749
750 /* Wait with msec_timeout */
751
752 default:
753
754#ifdef ACPI_USE_ALTERNATE_TIMEOUT
755 /*
756 * Alternate timeout mechanism for environments where
757 * sem_timedwait is not available or does not work properly.
758 */
759 while (msec_timeout) {
760 if (sem_trywait(sem) == 0) {
761
762 /* Got the semaphore */
763 return (AE_OK);
764 }
765
766 if (msec_timeout >= 10) {
767 msec_timeout -= 10;
768 usleep(10 * ACPI_USEC_PER_MSEC); /* ten milliseconds */
769 } else {
770 msec_timeout--;
771 usleep(ACPI_USEC_PER_MSEC); /* one millisecond */
772 }
773 }
774 status = (AE_TIME);
775#else
776 /*
777 * The interface to sem_timedwait is an absolute time, so we need to
778 * get the current time, then add in the millisecond Timeout value.
779 */
780 if (clock_gettime(CLOCK_REALTIME, &time) == -1) {
781 perror("clock_gettime");
782 return (AE_TIME);
783 }
784
785 time.tv_sec += (msec_timeout / ACPI_MSEC_PER_SEC);
786 time.tv_nsec +=
787 ((msec_timeout % ACPI_MSEC_PER_SEC) * ACPI_NSEC_PER_MSEC);
788
789 /* Handle nanosecond overflow (field must be less than one second) */
790
791 if (time.tv_nsec >= ACPI_NSEC_PER_SEC) {
792 time.tv_sec += (time.tv_nsec / ACPI_NSEC_PER_SEC);
793 time.tv_nsec = (time.tv_nsec % ACPI_NSEC_PER_SEC);
794 }
795
796 while (((ret_val = sem_timedwait(sem, &time)) == -1)
797 && (errno == EINTR)) {
798 continue;
799 }
800
801 if (ret_val != 0) {
802 if (errno != ETIMEDOUT) {
803 perror("sem_timedwait");
804 }
805 status = (AE_TIME);
806 }
807#endif
808 break;
809 }
810
811 return (status);
812}
813
814/******************************************************************************
815 *
816 * FUNCTION: acpi_os_signal_semaphore
817 *
818 * PARAMETERS: handle - Handle returned by acpi_os_create_semaphore
819 * units - Number of units to send
820 *
821 * RETURN: Status
822 *
823 * DESCRIPTION: Send units
824 *
825 *****************************************************************************/
826
827acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units)
828{
829 sem_t *sem = (sem_t *) handle;
830
831 if (!sem) {
832 return (AE_BAD_PARAMETER);
833 }
834
835 if (sem_post(sem) == -1) {
836 return (AE_LIMIT);
837 }
838
839 return (AE_OK);
840}
841
842#endif /* ACPI_SINGLE_THREADED */
843
844/******************************************************************************
845 *
846 * FUNCTION: Spinlock interfaces
847 *
848 * DESCRIPTION: Map these interfaces to semaphore interfaces
849 *
850 *****************************************************************************/
851
852acpi_status acpi_os_create_lock(acpi_spinlock * out_handle)
853{
854
855 return (acpi_os_create_semaphore(1, 1, out_handle));
856}
857
858void acpi_os_delete_lock(acpi_spinlock handle)
859{
860 acpi_os_delete_semaphore(handle);
861}
862
863acpi_cpu_flags acpi_os_acquire_lock(acpi_handle handle)
864{
865 acpi_os_wait_semaphore(handle, 1, 0xFFFF);
866 return (0);
867}
868
869void acpi_os_release_lock(acpi_spinlock handle, acpi_cpu_flags flags)
870{
871 acpi_os_signal_semaphore(handle, 1);
872}
873
874/******************************************************************************
875 *
876 * FUNCTION: acpi_os_install_interrupt_handler
877 *
878 * PARAMETERS: interrupt_number - Level handler should respond to.
879 * isr - Address of the ACPI interrupt handler
880 * except_ptr - Where status is returned
881 *
882 * RETURN: Handle to the newly installed handler.
883 *
884 * DESCRIPTION: Install an interrupt handler. Used to install the ACPI
885 * OS-independent handler.
886 *
887 *****************************************************************************/
888
889u32
890acpi_os_install_interrupt_handler(u32 interrupt_number,
891 acpi_osd_handler service_routine,
892 void *context)
893{
894
895 return (AE_OK);
896}
897
898/******************************************************************************
899 *
900 * FUNCTION: acpi_os_remove_interrupt_handler
901 *
902 * PARAMETERS: handle - Returned when handler was installed
903 *
904 * RETURN: Status
905 *
906 * DESCRIPTION: Uninstalls an interrupt handler.
907 *
908 *****************************************************************************/
909
910acpi_status
911acpi_os_remove_interrupt_handler(u32 interrupt_number,
912 acpi_osd_handler service_routine)
913{
914
915 return (AE_OK);
916}
917
918/******************************************************************************
919 *
920 * FUNCTION: acpi_os_stall
921 *
922 * PARAMETERS: microseconds - Time to sleep
923 *
924 * RETURN: Blocks until sleep is completed.
925 *
926 * DESCRIPTION: Sleep at microsecond granularity
927 *
928 *****************************************************************************/
929
930void acpi_os_stall(u32 microseconds)
931{
932
933 if (microseconds) {
934 usleep(microseconds);
935 }
936}
937
938/******************************************************************************
939 *
940 * FUNCTION: acpi_os_sleep
941 *
942 * PARAMETERS: milliseconds - Time to sleep
943 *
944 * RETURN: Blocks until sleep is completed.
945 *
946 * DESCRIPTION: Sleep at millisecond granularity
947 *
948 *****************************************************************************/
949
950void acpi_os_sleep(u64 milliseconds)
951{
952
953 /* Sleep for whole seconds */
954
955 sleep(milliseconds / ACPI_MSEC_PER_SEC);
956
957 /*
958 * Sleep for remaining microseconds.
959 * Arg to usleep() is in usecs and must be less than 1,000,000 (1 second).
960 */
961 usleep((milliseconds % ACPI_MSEC_PER_SEC) * ACPI_USEC_PER_MSEC);
962}
963
964/******************************************************************************
965 *
966 * FUNCTION: acpi_os_get_timer
967 *
968 * PARAMETERS: None
969 *
970 * RETURN: Current time in 100 nanosecond units
971 *
972 * DESCRIPTION: Get the current system time
973 *
974 *****************************************************************************/
975
976u64 acpi_os_get_timer(void)
977{
978 struct timeval time;
979
980 /* This timer has sufficient resolution for user-space application code */
981
982 gettimeofday(&time, NULL);
983
984 /* (Seconds * 10^7 = 100ns(10^-7)) + (Microseconds(10^-6) * 10^1 = 100ns) */
985
986 return (((u64)time.tv_sec * ACPI_100NSEC_PER_SEC) +
987 ((u64)time.tv_usec * ACPI_100NSEC_PER_USEC));
988}
989
990/******************************************************************************
991 *
992 * FUNCTION: acpi_os_read_pci_configuration
993 *
994 * PARAMETERS: pci_id - Seg/Bus/Dev
995 * pci_register - Device Register
996 * value - Buffer where value is placed
997 * width - Number of bits
998 *
999 * RETURN: Status
1000 *
1001 * DESCRIPTION: Read data from PCI configuration space
1002 *
1003 *****************************************************************************/
1004
1005acpi_status
1006acpi_os_read_pci_configuration(struct acpi_pci_id *pci_id,
1007 u32 pci_register, u64 *value, u32 width)
1008{
1009
1010 *value = 0;
1011 return (AE_OK);
1012}
1013
1014/******************************************************************************
1015 *
1016 * FUNCTION: acpi_os_write_pci_configuration
1017 *
1018 * PARAMETERS: pci_id - Seg/Bus/Dev
1019 * pci_register - Device Register
1020 * value - Value to be written
1021 * width - Number of bits
1022 *
1023 * RETURN: Status.
1024 *
1025 * DESCRIPTION: Write data to PCI configuration space
1026 *
1027 *****************************************************************************/
1028
1029acpi_status
1030acpi_os_write_pci_configuration(struct acpi_pci_id * pci_id,
1031 u32 pci_register, u64 value, u32 width)
1032{
1033
1034 return (AE_OK);
1035}
1036
1037/******************************************************************************
1038 *
1039 * FUNCTION: acpi_os_read_port
1040 *
1041 * PARAMETERS: address - Address of I/O port/register to read
1042 * value - Where value is placed
1043 * width - Number of bits
1044 *
1045 * RETURN: Value read from port
1046 *
1047 * DESCRIPTION: Read data from an I/O port or register
1048 *
1049 *****************************************************************************/
1050
1051acpi_status acpi_os_read_port(acpi_io_address address, u32 *value, u32 width)
1052{
1053
1054 switch (width) {
1055 case 8:
1056
1057 *value = 0xFF;
1058 break;
1059
1060 case 16:
1061
1062 *value = 0xFFFF;
1063 break;
1064
1065 case 32:
1066
1067 *value = 0xFFFFFFFF;
1068 break;
1069
1070 default:
1071
1072 return (AE_BAD_PARAMETER);
1073 }
1074
1075 return (AE_OK);
1076}
1077
1078/******************************************************************************
1079 *
1080 * FUNCTION: acpi_os_write_port
1081 *
1082 * PARAMETERS: address - Address of I/O port/register to write
1083 * value - Value to write
1084 * width - Number of bits
1085 *
1086 * RETURN: None
1087 *
1088 * DESCRIPTION: Write data to an I/O port or register
1089 *
1090 *****************************************************************************/
1091
1092acpi_status acpi_os_write_port(acpi_io_address address, u32 value, u32 width)
1093{
1094
1095 return (AE_OK);
1096}
1097
1098/******************************************************************************
1099 *
1100 * FUNCTION: acpi_os_read_memory
1101 *
1102 * PARAMETERS: address - Physical Memory Address to read
1103 * value - Where value is placed
1104 * width - Number of bits (8,16,32, or 64)
1105 *
1106 * RETURN: Value read from physical memory address. Always returned
1107 * as a 64-bit integer, regardless of the read width.
1108 *
1109 * DESCRIPTION: Read data from a physical memory address
1110 *
1111 *****************************************************************************/
1112
1113acpi_status
1114acpi_os_read_memory(acpi_physical_address address, u64 *value, u32 width)
1115{
1116
1117 switch (width) {
1118 case 8:
1119 case 16:
1120 case 32:
1121 case 64:
1122
1123 *value = 0;
1124 break;
1125
1126 default:
1127
1128 return (AE_BAD_PARAMETER);
1129 }
1130 return (AE_OK);
1131}
1132
1133/******************************************************************************
1134 *
1135 * FUNCTION: acpi_os_write_memory
1136 *
1137 * PARAMETERS: address - Physical Memory Address to write
1138 * value - Value to write
1139 * width - Number of bits (8,16,32, or 64)
1140 *
1141 * RETURN: None
1142 *
1143 * DESCRIPTION: Write data to a physical memory address
1144 *
1145 *****************************************************************************/
1146
1147acpi_status
1148acpi_os_write_memory(acpi_physical_address address, u64 value, u32 width)
1149{
1150
1151 return (AE_OK);
1152}
1153
1154/******************************************************************************
1155 *
1156 * FUNCTION: acpi_os_readable
1157 *
1158 * PARAMETERS: pointer - Area to be verified
1159 * length - Size of area
1160 *
1161 * RETURN: TRUE if readable for entire length
1162 *
1163 * DESCRIPTION: Verify that a pointer is valid for reading
1164 *
1165 *****************************************************************************/
1166
1167u8 acpi_os_readable(void *pointer, acpi_size length)
1168{
1169
1170 return (TRUE);
1171}
1172
1173/******************************************************************************
1174 *
1175 * FUNCTION: acpi_os_writable
1176 *
1177 * PARAMETERS: pointer - Area to be verified
1178 * length - Size of area
1179 *
1180 * RETURN: TRUE if writable for entire length
1181 *
1182 * DESCRIPTION: Verify that a pointer is valid for writing
1183 *
1184 *****************************************************************************/
1185
1186u8 acpi_os_writable(void *pointer, acpi_size length)
1187{
1188
1189 return (TRUE);
1190}
1191
1192/******************************************************************************
1193 *
1194 * FUNCTION: acpi_os_signal
1195 *
1196 * PARAMETERS: function - ACPI A signal function code
1197 * info - Pointer to function-dependent structure
1198 *
1199 * RETURN: Status
1200 *
1201 * DESCRIPTION: Miscellaneous functions. Example implementation only.
1202 *
1203 *****************************************************************************/
1204
1205acpi_status acpi_os_signal(u32 function, void *info)
1206{
1207
1208 switch (function) {
1209 case ACPI_SIGNAL_FATAL:
1210
1211 break;
1212
1213 case ACPI_SIGNAL_BREAKPOINT:
1214
1215 break;
1216
1217 default:
1218
1219 break;
1220 }
1221
1222 return (AE_OK);
1223}
1224
1225/* Optional multi-thread support */
1226
1227#ifndef ACPI_SINGLE_THREADED
1228/******************************************************************************
1229 *
1230 * FUNCTION: acpi_os_get_thread_id
1231 *
1232 * PARAMETERS: None
1233 *
1234 * RETURN: Id of the running thread
1235 *
1236 * DESCRIPTION: Get the ID of the current (running) thread
1237 *
1238 *****************************************************************************/
1239
1240acpi_thread_id acpi_os_get_thread_id(void)
1241{
1242 pthread_t thread;
1243
1244 thread = pthread_self();
1245 return (ACPI_CAST_PTHREAD_T(thread));
1246}
1247
1248/******************************************************************************
1249 *
1250 * FUNCTION: acpi_os_execute
1251 *
1252 * PARAMETERS: type - Type of execution
1253 * function - Address of the function to execute
1254 * context - Passed as a parameter to the function
1255 *
1256 * RETURN: Status.
1257 *
1258 * DESCRIPTION: Execute a new thread
1259 *
1260 *****************************************************************************/
1261
1262acpi_status
1263acpi_os_execute(acpi_execute_type type,
1264 acpi_osd_exec_callback function, void *context)
1265{
1266 pthread_t thread;
1267 int ret;
1268
1269 ret =
1270 pthread_create(&thread, NULL, (PTHREAD_CALLBACK) function, context);
1271 if (ret) {
1272 acpi_os_printf("Create thread failed");
1273 }
1274 return (0);
1275}
1276
1277#else /* ACPI_SINGLE_THREADED */
1278acpi_thread_id acpi_os_get_thread_id(void)
1279{
1280 return (1);
1281}
1282
1283acpi_status
1284acpi_os_execute(acpi_execute_type type,
1285 acpi_osd_exec_callback function, void *context)
1286{
1287
1288 function(context);
1289
1290 return (AE_OK);
1291}
1292
1293#endif /* ACPI_SINGLE_THREADED */
1294
1295/******************************************************************************
1296 *
1297 * FUNCTION: acpi_os_wait_events_complete
1298 *
1299 * PARAMETERS: None
1300 *
1301 * RETURN: None
1302 *
1303 * DESCRIPTION: Wait for all asynchronous events to complete. This
1304 * implementation does nothing.
1305 *
1306 *****************************************************************************/
1307
1308void acpi_os_wait_events_complete(void)
1309{
1310 return;
1311}
diff --git a/tools/power/acpi/tools/acpidump/acpidump.h b/tools/power/acpi/tools/acpidump/acpidump.h
index 46f519597fe5..a2d37d610639 100644
--- a/tools/power/acpi/tools/acpidump/acpidump.h
+++ b/tools/power/acpi/tools/acpidump/acpidump.h
@@ -47,7 +47,6 @@
47#ifdef _DECLARE_GLOBALS 47#ifdef _DECLARE_GLOBALS
48#define EXTERN 48#define EXTERN
49#define INIT_GLOBAL(a,b) a=b 49#define INIT_GLOBAL(a,b) a=b
50#define DEFINE_ACPI_GLOBALS 1
51#else 50#else
52#define EXTERN extern 51#define EXTERN extern
53#define INIT_GLOBAL(a,b) a 52#define INIT_GLOBAL(a,b) a
@@ -69,7 +68,7 @@ EXTERN u8 INIT_GLOBAL(gbl_verbose_mode, FALSE);
69EXTERN u8 INIT_GLOBAL(gbl_binary_mode, FALSE); 68EXTERN u8 INIT_GLOBAL(gbl_binary_mode, FALSE);
70EXTERN u8 INIT_GLOBAL(gbl_dump_customized_tables, FALSE); 69EXTERN u8 INIT_GLOBAL(gbl_dump_customized_tables, FALSE);
71EXTERN u8 INIT_GLOBAL(gbl_do_not_dump_xsdt, FALSE); 70EXTERN u8 INIT_GLOBAL(gbl_do_not_dump_xsdt, FALSE);
72EXTERN FILE INIT_GLOBAL(*gbl_output_file, NULL); 71EXTERN ACPI_FILE INIT_GLOBAL(gbl_output_file, NULL);
73EXTERN char INIT_GLOBAL(*gbl_output_filename, NULL); 72EXTERN char INIT_GLOBAL(*gbl_output_filename, NULL);
74EXTERN u64 INIT_GLOBAL(gbl_rsdp_base, 0); 73EXTERN u64 INIT_GLOBAL(gbl_rsdp_base, 0);
75 74
diff --git a/tools/power/acpi/tools/acpidump/apdump.c b/tools/power/acpi/tools/acpidump/apdump.c
index 3cac12378366..53cee781e24e 100644
--- a/tools/power/acpi/tools/acpidump/apdump.c
+++ b/tools/power/acpi/tools/acpidump/apdump.c
@@ -69,17 +69,16 @@ u8 ap_is_valid_header(struct acpi_table_header *table)
69 /* Make sure signature is all ASCII and a valid ACPI name */ 69 /* Make sure signature is all ASCII and a valid ACPI name */
70 70
71 if (!acpi_ut_valid_acpi_name(table->signature)) { 71 if (!acpi_ut_valid_acpi_name(table->signature)) {
72 fprintf(stderr, 72 acpi_log_error("Table signature (0x%8.8X) is invalid\n",
73 "Table signature (0x%8.8X) is invalid\n", 73 *(u32 *)table->signature);
74 *(u32 *)table->signature);
75 return (FALSE); 74 return (FALSE);
76 } 75 }
77 76
78 /* Check for minimum table length */ 77 /* Check for minimum table length */
79 78
80 if (table->length < sizeof(struct acpi_table_header)) { 79 if (table->length < sizeof(struct acpi_table_header)) {
81 fprintf(stderr, "Table length (0x%8.8X) is invalid\n", 80 acpi_log_error("Table length (0x%8.8X) is invalid\n",
82 table->length); 81 table->length);
83 return (FALSE); 82 return (FALSE);
84 } 83 }
85 } 84 }
@@ -116,8 +115,8 @@ u8 ap_is_valid_checksum(struct acpi_table_header *table)
116 } 115 }
117 116
118 if (ACPI_FAILURE(status)) { 117 if (ACPI_FAILURE(status)) {
119 fprintf(stderr, "%4.4s: Warning: wrong checksum in table\n", 118 acpi_log_error("%4.4s: Warning: wrong checksum in table\n",
120 table->signature); 119 table->signature);
121 } 120 }
122 121
123 return (AE_OK); 122 return (AE_OK);
@@ -196,12 +195,13 @@ ap_dump_table_buffer(struct acpi_table_header *table,
196 * Note: simplest to just always emit a 64-bit address. acpi_xtract 195 * Note: simplest to just always emit a 64-bit address. acpi_xtract
197 * utility can handle this. 196 * utility can handle this.
198 */ 197 */
199 printf("%4.4s @ 0x%8.8X%8.8X\n", table->signature, 198 acpi_ut_file_printf(gbl_output_file, "%4.4s @ 0x%8.8X%8.8X\n",
200 ACPI_FORMAT_UINT64(address)); 199 table->signature, ACPI_FORMAT_UINT64(address));
201 200
202 acpi_ut_dump_buffer(ACPI_CAST_PTR(u8, table), table_length, 201 acpi_ut_dump_buffer_to_file(gbl_output_file,
203 DB_BYTE_DISPLAY, 0); 202 ACPI_CAST_PTR(u8, table), table_length,
204 printf("\n"); 203 DB_BYTE_DISPLAY, 0);
204 acpi_ut_file_printf(gbl_output_file, "\n");
205 return (0); 205 return (0);
206} 206}
207 207
@@ -239,20 +239,20 @@ int ap_dump_all_tables(void)
239 if (status == AE_LIMIT) { 239 if (status == AE_LIMIT) {
240 return (0); 240 return (0);
241 } else if (i == 0) { 241 } else if (i == 0) {
242 fprintf(stderr, 242 acpi_log_error
243 "Could not get ACPI tables, %s\n", 243 ("Could not get ACPI tables, %s\n",
244 acpi_format_exception(status)); 244 acpi_format_exception(status));
245 return (-1); 245 return (-1);
246 } else { 246 } else {
247 fprintf(stderr, 247 acpi_log_error
248 "Could not get ACPI table at index %u, %s\n", 248 ("Could not get ACPI table at index %u, %s\n",
249 i, acpi_format_exception(status)); 249 i, acpi_format_exception(status));
250 continue; 250 continue;
251 } 251 }
252 } 252 }
253 253
254 table_status = ap_dump_table_buffer(table, instance, address); 254 table_status = ap_dump_table_buffer(table, instance, address);
255 free(table); 255 ACPI_FREE(table);
256 256
257 if (table_status) { 257 if (table_status) {
258 break; 258 break;
@@ -288,22 +288,22 @@ int ap_dump_table_by_address(char *ascii_address)
288 288
289 status = acpi_ut_strtoul64(ascii_address, 0, &long_address); 289 status = acpi_ut_strtoul64(ascii_address, 0, &long_address);
290 if (ACPI_FAILURE(status)) { 290 if (ACPI_FAILURE(status)) {
291 fprintf(stderr, "%s: Could not convert to a physical address\n", 291 acpi_log_error("%s: Could not convert to a physical address\n",
292 ascii_address); 292 ascii_address);
293 return (-1); 293 return (-1);
294 } 294 }
295 295
296 address = (acpi_physical_address) long_address; 296 address = (acpi_physical_address) long_address;
297 status = acpi_os_get_table_by_address(address, &table); 297 status = acpi_os_get_table_by_address(address, &table);
298 if (ACPI_FAILURE(status)) { 298 if (ACPI_FAILURE(status)) {
299 fprintf(stderr, "Could not get table at 0x%8.8X%8.8X, %s\n", 299 acpi_log_error("Could not get table at 0x%8.8X%8.8X, %s\n",
300 ACPI_FORMAT_UINT64(address), 300 ACPI_FORMAT_UINT64(address),
301 acpi_format_exception(status)); 301 acpi_format_exception(status));
302 return (-1); 302 return (-1);
303 } 303 }
304 304
305 table_status = ap_dump_table_buffer(table, 0, address); 305 table_status = ap_dump_table_buffer(table, 0, address);
306 free(table); 306 ACPI_FREE(table);
307 return (table_status); 307 return (table_status);
308} 308}
309 309
@@ -329,24 +329,24 @@ int ap_dump_table_by_name(char *signature)
329 acpi_status status; 329 acpi_status status;
330 int table_status; 330 int table_status;
331 331
332 if (strlen(signature) != ACPI_NAME_SIZE) { 332 if (ACPI_STRLEN(signature) != ACPI_NAME_SIZE) {
333 fprintf(stderr, 333 acpi_log_error
334 "Invalid table signature [%s]: must be exactly 4 characters\n", 334 ("Invalid table signature [%s]: must be exactly 4 characters\n",
335 signature); 335 signature);
336 return (-1); 336 return (-1);
337 } 337 }
338 338
339 /* Table signatures are expected to be uppercase */ 339 /* Table signatures are expected to be uppercase */
340 340
341 strcpy(local_signature, signature); 341 ACPI_STRCPY(local_signature, signature);
342 acpi_ut_strupr(local_signature); 342 acpi_ut_strupr(local_signature);
343 343
344 /* To be friendly, handle tables whose signatures do not match the name */ 344 /* To be friendly, handle tables whose signatures do not match the name */
345 345
346 if (ACPI_COMPARE_NAME(local_signature, "FADT")) { 346 if (ACPI_COMPARE_NAME(local_signature, "FADT")) {
347 strcpy(local_signature, ACPI_SIG_FADT); 347 ACPI_STRCPY(local_signature, ACPI_SIG_FADT);
348 } else if (ACPI_COMPARE_NAME(local_signature, "MADT")) { 348 } else if (ACPI_COMPARE_NAME(local_signature, "MADT")) {
349 strcpy(local_signature, ACPI_SIG_MADT); 349 ACPI_STRCPY(local_signature, ACPI_SIG_MADT);
350 } 350 }
351 351
352 /* Dump all instances of this signature (to handle multiple SSDTs) */ 352 /* Dump all instances of this signature (to handle multiple SSDTs) */
@@ -362,14 +362,14 @@ int ap_dump_table_by_name(char *signature)
362 return (0); 362 return (0);
363 } 363 }
364 364
365 fprintf(stderr, 365 acpi_log_error
366 "Could not get ACPI table with signature [%s], %s\n", 366 ("Could not get ACPI table with signature [%s], %s\n",
367 local_signature, acpi_format_exception(status)); 367 local_signature, acpi_format_exception(status));
368 return (-1); 368 return (-1);
369 } 369 }
370 370
371 table_status = ap_dump_table_buffer(table, instance, address); 371 table_status = ap_dump_table_buffer(table, instance, address);
372 free(table); 372 ACPI_FREE(table);
373 373
374 if (table_status) { 374 if (table_status) {
375 break; 375 break;
@@ -409,43 +409,21 @@ int ap_dump_table_from_file(char *pathname)
409 /* File must be at least as long as the table length */ 409 /* File must be at least as long as the table length */
410 410
411 if (table->length > file_size) { 411 if (table->length > file_size) {
412 fprintf(stderr, 412 acpi_log_error
413 "Table length (0x%X) is too large for input file (0x%X) %s\n", 413 ("Table length (0x%X) is too large for input file (0x%X) %s\n",
414 table->length, file_size, pathname); 414 table->length, file_size, pathname);
415 goto exit; 415 goto exit;
416 } 416 }
417 417
418 if (gbl_verbose_mode) { 418 if (gbl_verbose_mode) {
419 fprintf(stderr, 419 acpi_log_error
420 "Input file: %s contains table [%4.4s], 0x%X (%u) bytes\n", 420 ("Input file: %s contains table [%4.4s], 0x%X (%u) bytes\n",
421 pathname, table->signature, file_size, file_size); 421 pathname, table->signature, file_size, file_size);
422 } 422 }
423 423
424 table_status = ap_dump_table_buffer(table, 0, 0); 424 table_status = ap_dump_table_buffer(table, 0, 0);
425 425
426exit: 426exit:
427 free(table); 427 ACPI_FREE(table);
428 return (table_status); 428 return (table_status);
429} 429}
430
431/******************************************************************************
432 *
433 * FUNCTION: acpi_os* print functions
434 *
435 * DESCRIPTION: Used for linkage with ACPICA modules
436 *
437 ******************************************************************************/
438
439void ACPI_INTERNAL_VAR_XFACE acpi_os_printf(const char *fmt, ...)
440{
441 va_list args;
442
443 va_start(args, fmt);
444 vfprintf(stdout, fmt, args);
445 va_end(args);
446}
447
448void acpi_os_vprintf(const char *fmt, va_list args)
449{
450 vfprintf(stdout, fmt, args);
451}
diff --git a/tools/power/acpi/tools/acpidump/apfiles.c b/tools/power/acpi/tools/acpidump/apfiles.c
index 4488accc010b..d470046a6d81 100644
--- a/tools/power/acpi/tools/acpidump/apfiles.c
+++ b/tools/power/acpi/tools/acpidump/apfiles.c
@@ -44,6 +44,27 @@
44#include "acpidump.h" 44#include "acpidump.h"
45#include "acapps.h" 45#include "acapps.h"
46 46
47/* Local prototypes */
48
49static int ap_is_existing_file(char *pathname);
50
51static int ap_is_existing_file(char *pathname)
52{
53#ifndef _GNU_EFI
54 struct stat stat_info;
55
56 if (!stat(pathname, &stat_info)) {
57 acpi_log_error("Target path already exists, overwrite? [y|n] ");
58
59 if (getchar() != 'y') {
60 return (-1);
61 }
62 }
63#endif
64
65 return 0;
66}
67
47/****************************************************************************** 68/******************************************************************************
48 * 69 *
49 * FUNCTION: ap_open_output_file 70 * FUNCTION: ap_open_output_file
@@ -59,25 +80,19 @@
59 80
60int ap_open_output_file(char *pathname) 81int ap_open_output_file(char *pathname)
61{ 82{
62 struct stat stat_info; 83 ACPI_FILE file;
63 FILE *file;
64 84
65 /* If file exists, prompt for overwrite */ 85 /* If file exists, prompt for overwrite */
66 86
67 if (!stat(pathname, &stat_info)) { 87 if (ap_is_existing_file(pathname) != 0) {
68 fprintf(stderr, 88 return (-1);
69 "Target path already exists, overwrite? [y|n] ");
70
71 if (getchar() != 'y') {
72 return (-1);
73 }
74 } 89 }
75 90
76 /* Point stdout to the file */ 91 /* Point stdout to the file */
77 92
78 file = freopen(pathname, "w", stdout); 93 file = acpi_os_open_file(pathname, ACPI_FILE_WRITING);
79 if (!file) { 94 if (!file) {
80 perror("Could not open output file"); 95 acpi_log_error("Could not open output file: %s\n", pathname);
81 return (-1); 96 return (-1);
82 } 97 }
83 98
@@ -106,7 +121,7 @@ int ap_write_to_binary_file(struct acpi_table_header *table, u32 instance)
106{ 121{
107 char filename[ACPI_NAME_SIZE + 16]; 122 char filename[ACPI_NAME_SIZE + 16];
108 char instance_str[16]; 123 char instance_str[16];
109 FILE *file; 124 ACPI_FILE file;
110 size_t actual; 125 size_t actual;
111 u32 table_length; 126 u32 table_length;
112 127
@@ -130,35 +145,37 @@ int ap_write_to_binary_file(struct acpi_table_header *table, u32 instance)
130 /* Handle multiple SSDts - create different filenames for each */ 145 /* Handle multiple SSDts - create different filenames for each */
131 146
132 if (instance > 0) { 147 if (instance > 0) {
133 sprintf(instance_str, "%u", instance); 148 acpi_ut_snprintf(instance_str, sizeof(instance_str), "%u",
134 strcat(filename, instance_str); 149 instance);
150 ACPI_STRCAT(filename, instance_str);
135 } 151 }
136 152
137 strcat(filename, ACPI_TABLE_FILE_SUFFIX); 153 ACPI_STRCAT(filename, ACPI_TABLE_FILE_SUFFIX);
138 154
139 if (gbl_verbose_mode) { 155 if (gbl_verbose_mode) {
140 fprintf(stderr, 156 acpi_log_error
141 "Writing [%4.4s] to binary file: %s 0x%X (%u) bytes\n", 157 ("Writing [%4.4s] to binary file: %s 0x%X (%u) bytes\n",
142 table->signature, filename, table->length, 158 table->signature, filename, table->length, table->length);
143 table->length);
144 } 159 }
145 160
146 /* Open the file and dump the entire table in binary mode */ 161 /* Open the file and dump the entire table in binary mode */
147 162
148 file = fopen(filename, "wb"); 163 file = acpi_os_open_file(filename,
164 ACPI_FILE_WRITING | ACPI_FILE_BINARY);
149 if (!file) { 165 if (!file) {
150 perror("Could not open output file"); 166 acpi_log_error("Could not open output file: %s\n", filename);
151 return (-1); 167 return (-1);
152 } 168 }
153 169
154 actual = fwrite(table, 1, table_length, file); 170 actual = acpi_os_write_file(file, table, 1, table_length);
155 if (actual != table_length) { 171 if (actual != table_length) {
156 perror("Error writing binary output file"); 172 acpi_log_error("Error writing binary output file: %s\n",
157 fclose(file); 173 filename);
174 acpi_os_close_file(file);
158 return (-1); 175 return (-1);
159 } 176 }
160 177
161 fclose(file); 178 acpi_os_close_file(file);
162 return (0); 179 return (0);
163} 180}
164 181
@@ -179,15 +196,16 @@ struct acpi_table_header *ap_get_table_from_file(char *pathname,
179 u32 *out_file_size) 196 u32 *out_file_size)
180{ 197{
181 struct acpi_table_header *buffer = NULL; 198 struct acpi_table_header *buffer = NULL;
182 FILE *file; 199 ACPI_FILE file;
183 u32 file_size; 200 u32 file_size;
184 size_t actual; 201 size_t actual;
185 202
186 /* Must use binary mode */ 203 /* Must use binary mode */
187 204
188 file = fopen(pathname, "rb"); 205 file =
206 acpi_os_open_file(pathname, ACPI_FILE_READING | ACPI_FILE_BINARY);
189 if (!file) { 207 if (!file) {
190 perror("Could not open input file"); 208 acpi_log_error("Could not open input file: %s\n", pathname);
191 return (NULL); 209 return (NULL);
192 } 210 }
193 211
@@ -195,27 +213,25 @@ struct acpi_table_header *ap_get_table_from_file(char *pathname,
195 213
196 file_size = cm_get_file_size(file); 214 file_size = cm_get_file_size(file);
197 if (file_size == ACPI_UINT32_MAX) { 215 if (file_size == ACPI_UINT32_MAX) {
198 fprintf(stderr, 216 acpi_log_error("Could not get input file size: %s\n", pathname);
199 "Could not get input file size: %s\n", pathname);
200 goto cleanup; 217 goto cleanup;
201 } 218 }
202 219
203 /* Allocate a buffer for the entire file */ 220 /* Allocate a buffer for the entire file */
204 221
205 buffer = calloc(1, file_size); 222 buffer = ACPI_ALLOCATE_ZEROED(file_size);
206 if (!buffer) { 223 if (!buffer) {
207 fprintf(stderr, 224 acpi_log_error("Could not allocate file buffer of size: %u\n",
208 "Could not allocate file buffer of size: %u\n", 225 file_size);
209 file_size);
210 goto cleanup; 226 goto cleanup;
211 } 227 }
212 228
213 /* Read the entire file */ 229 /* Read the entire file */
214 230
215 actual = fread(buffer, 1, file_size, file); 231 actual = acpi_os_read_file(file, buffer, 1, file_size);
216 if (actual != file_size) { 232 if (actual != file_size) {
217 fprintf(stderr, "Could not read input file: %s\n", pathname); 233 acpi_log_error("Could not read input file: %s\n", pathname);
218 free(buffer); 234 ACPI_FREE(buffer);
219 buffer = NULL; 235 buffer = NULL;
220 goto cleanup; 236 goto cleanup;
221 } 237 }
@@ -223,6 +239,6 @@ struct acpi_table_header *ap_get_table_from_file(char *pathname,
223 *out_file_size = file_size; 239 *out_file_size = file_size;
224 240
225cleanup: 241cleanup:
226 fclose(file); 242 acpi_os_close_file(file);
227 return (buffer); 243 return (buffer);
228} 244}
diff --git a/tools/power/acpi/tools/acpidump/apmain.c b/tools/power/acpi/tools/acpidump/apmain.c
index 51e8d638db18..853b4da22c3e 100644
--- a/tools/power/acpi/tools/acpidump/apmain.c
+++ b/tools/power/acpi/tools/acpidump/apmain.c
@@ -72,7 +72,7 @@ static void ap_display_usage(void);
72 72
73static int ap_do_options(int argc, char **argv); 73static int ap_do_options(int argc, char **argv);
74 74
75static void ap_insert_action(char *argument, u32 to_be_done); 75static int ap_insert_action(char *argument, u32 to_be_done);
76 76
77/* Table for deferred actions from command line options */ 77/* Table for deferred actions from command line options */
78 78
@@ -104,7 +104,7 @@ static void ap_display_usage(void)
104 ACPI_OPTION("-v", "Display version information"); 104 ACPI_OPTION("-v", "Display version information");
105 ACPI_OPTION("-z", "Verbose mode"); 105 ACPI_OPTION("-z", "Verbose mode");
106 106
107 printf("\nTable Options:\n"); 107 ACPI_USAGE_TEXT("\nTable Options:\n");
108 108
109 ACPI_OPTION("-a <Address>", "Get table via a physical address"); 109 ACPI_OPTION("-a <Address>", "Get table via a physical address");
110 ACPI_OPTION("-f <BinaryFile>", "Get table via a binary file"); 110 ACPI_OPTION("-f <BinaryFile>", "Get table via a binary file");
@@ -112,9 +112,9 @@ static void ap_display_usage(void)
112 ACPI_OPTION("-x", "Do not use but dump XSDT"); 112 ACPI_OPTION("-x", "Do not use but dump XSDT");
113 ACPI_OPTION("-x -x", "Do not use or dump XSDT"); 113 ACPI_OPTION("-x -x", "Do not use or dump XSDT");
114 114
115 printf("\n" 115 ACPI_USAGE_TEXT("\n"
116 "Invocation without parameters dumps all available tables\n" 116 "Invocation without parameters dumps all available tables\n"
117 "Multiple mixed instances of -a, -f, and -n are supported\n\n"); 117 "Multiple mixed instances of -a, -f, and -n are supported\n\n");
118} 118}
119 119
120/****************************************************************************** 120/******************************************************************************
@@ -124,13 +124,13 @@ static void ap_display_usage(void)
124 * PARAMETERS: argument - Pointer to the argument for this action 124 * PARAMETERS: argument - Pointer to the argument for this action
125 * to_be_done - What to do to process this action 125 * to_be_done - What to do to process this action
126 * 126 *
127 * RETURN: None. Exits program if action table becomes full. 127 * RETURN: Status
128 * 128 *
129 * DESCRIPTION: Add an action item to the action table 129 * DESCRIPTION: Add an action item to the action table
130 * 130 *
131 ******************************************************************************/ 131 ******************************************************************************/
132 132
133static void ap_insert_action(char *argument, u32 to_be_done) 133static int ap_insert_action(char *argument, u32 to_be_done)
134{ 134{
135 135
136 /* Insert action and check for table overflow */ 136 /* Insert action and check for table overflow */
@@ -140,10 +140,12 @@ static void ap_insert_action(char *argument, u32 to_be_done)
140 140
141 current_action++; 141 current_action++;
142 if (current_action > AP_MAX_ACTIONS) { 142 if (current_action > AP_MAX_ACTIONS) {
143 fprintf(stderr, "Too many table options (max %u)\n", 143 acpi_log_error("Too many table options (max %u)\n",
144 AP_MAX_ACTIONS); 144 AP_MAX_ACTIONS);
145 exit(-1); 145 return (-1);
146 } 146 }
147
148 return (0);
147} 149}
148 150
149/****************************************************************************** 151/******************************************************************************
@@ -166,7 +168,8 @@ static int ap_do_options(int argc, char **argv)
166 168
167 /* Command line options */ 169 /* Command line options */
168 170
169 while ((j = acpi_getopt(argc, argv, AP_SUPPORTED_OPTIONS)) != EOF) 171 while ((j =
172 acpi_getopt(argc, argv, AP_SUPPORTED_OPTIONS)) != ACPI_OPT_END)
170 switch (j) { 173 switch (j) {
171 /* 174 /*
172 * Global options 175 * Global options
@@ -185,12 +188,12 @@ static int ap_do_options(int argc, char **argv)
185 case '?': 188 case '?':
186 189
187 ap_display_usage(); 190 ap_display_usage();
188 exit(0); 191 return (1);
189 192
190 case 'o': /* Redirect output to a single file */ 193 case 'o': /* Redirect output to a single file */
191 194
192 if (ap_open_output_file(acpi_gbl_optarg)) { 195 if (ap_open_output_file(acpi_gbl_optarg)) {
193 exit(-1); 196 return (-1);
194 } 197 }
195 continue; 198 continue;
196 199
@@ -200,10 +203,10 @@ static int ap_do_options(int argc, char **argv)
200 acpi_ut_strtoul64(acpi_gbl_optarg, 0, 203 acpi_ut_strtoul64(acpi_gbl_optarg, 0,
201 &gbl_rsdp_base); 204 &gbl_rsdp_base);
202 if (ACPI_FAILURE(status)) { 205 if (ACPI_FAILURE(status)) {
203 fprintf(stderr, 206 acpi_log_error
204 "%s: Could not convert to a physical address\n", 207 ("%s: Could not convert to a physical address\n",
205 acpi_gbl_optarg); 208 acpi_gbl_optarg);
206 exit(-1); 209 return (-1);
207 } 210 }
208 continue; 211 continue;
209 212
@@ -223,13 +226,13 @@ static int ap_do_options(int argc, char **argv)
223 226
224 case 'v': /* Revision/version */ 227 case 'v': /* Revision/version */
225 228
226 printf(ACPI_COMMON_SIGNON(AP_UTILITY_NAME)); 229 acpi_os_printf(ACPI_COMMON_SIGNON(AP_UTILITY_NAME));
227 exit(0); 230 return (1);
228 231
229 case 'z': /* Verbose mode */ 232 case 'z': /* Verbose mode */
230 233
231 gbl_verbose_mode = TRUE; 234 gbl_verbose_mode = TRUE;
232 fprintf(stderr, ACPI_COMMON_SIGNON(AP_UTILITY_NAME)); 235 acpi_log_error(ACPI_COMMON_SIGNON(AP_UTILITY_NAME));
233 continue; 236 continue;
234 237
235 /* 238 /*
@@ -237,32 +240,40 @@ static int ap_do_options(int argc, char **argv)
237 */ 240 */
238 case 'a': /* Get table by physical address */ 241 case 'a': /* Get table by physical address */
239 242
240 ap_insert_action(acpi_gbl_optarg, 243 if (ap_insert_action
241 AP_DUMP_TABLE_BY_ADDRESS); 244 (acpi_gbl_optarg, AP_DUMP_TABLE_BY_ADDRESS)) {
245 return (-1);
246 }
242 break; 247 break;
243 248
244 case 'f': /* Get table from a file */ 249 case 'f': /* Get table from a file */
245 250
246 ap_insert_action(acpi_gbl_optarg, 251 if (ap_insert_action
247 AP_DUMP_TABLE_BY_FILE); 252 (acpi_gbl_optarg, AP_DUMP_TABLE_BY_FILE)) {
253 return (-1);
254 }
248 break; 255 break;
249 256
250 case 'n': /* Get table by input name (signature) */ 257 case 'n': /* Get table by input name (signature) */
251 258
252 ap_insert_action(acpi_gbl_optarg, 259 if (ap_insert_action
253 AP_DUMP_TABLE_BY_NAME); 260 (acpi_gbl_optarg, AP_DUMP_TABLE_BY_NAME)) {
261 return (-1);
262 }
254 break; 263 break;
255 264
256 default: 265 default:
257 266
258 ap_display_usage(); 267 ap_display_usage();
259 exit(-1); 268 return (-1);
260 } 269 }
261 270
262 /* If there are no actions, this means "get/dump all tables" */ 271 /* If there are no actions, this means "get/dump all tables" */
263 272
264 if (current_action == 0) { 273 if (current_action == 0) {
265 ap_insert_action(NULL, AP_DUMP_ALL_TABLES); 274 if (ap_insert_action(NULL, AP_DUMP_ALL_TABLES)) {
275 return (-1);
276 }
266 } 277 }
267 278
268 return (0); 279 return (0);
@@ -280,7 +291,11 @@ static int ap_do_options(int argc, char **argv)
280 * 291 *
281 ******************************************************************************/ 292 ******************************************************************************/
282 293
294#ifndef _GNU_EFI
283int ACPI_SYSTEM_XFACE main(int argc, char *argv[]) 295int ACPI_SYSTEM_XFACE main(int argc, char *argv[])
296#else
297int ACPI_SYSTEM_XFACE acpi_main(int argc, char *argv[])
298#endif
284{ 299{
285 int status = 0; 300 int status = 0;
286 struct ap_dump_action *action; 301 struct ap_dump_action *action;
@@ -288,11 +303,17 @@ int ACPI_SYSTEM_XFACE main(int argc, char *argv[])
288 u32 i; 303 u32 i;
289 304
290 ACPI_DEBUG_INITIALIZE(); /* For debug version only */ 305 ACPI_DEBUG_INITIALIZE(); /* For debug version only */
306 acpi_os_initialize();
307 gbl_output_file = ACPI_FILE_OUT;
291 308
292 /* Process command line options */ 309 /* Process command line options */
293 310
294 if (ap_do_options(argc, argv)) { 311 status = ap_do_options(argc, argv);
295 return (-1); 312 if (status > 0) {
313 return (0);
314 }
315 if (status < 0) {
316 return (status);
296 } 317 }
297 318
298 /* Get/dump ACPI table(s) as requested */ 319 /* Get/dump ACPI table(s) as requested */
@@ -322,9 +343,8 @@ int ACPI_SYSTEM_XFACE main(int argc, char *argv[])
322 343
323 default: 344 default:
324 345
325 fprintf(stderr, 346 acpi_log_error("Internal error, invalid action: 0x%X\n",
326 "Internal error, invalid action: 0x%X\n", 347 action->to_be_done);
327 action->to_be_done);
328 return (-1); 348 return (-1);
329 } 349 }
330 350
@@ -333,18 +353,18 @@ int ACPI_SYSTEM_XFACE main(int argc, char *argv[])
333 } 353 }
334 } 354 }
335 355
336 if (gbl_output_file) { 356 if (gbl_output_filename) {
337 if (gbl_verbose_mode) { 357 if (gbl_verbose_mode) {
338 358
339 /* Summary for the output file */ 359 /* Summary for the output file */
340 360
341 file_size = cm_get_file_size(gbl_output_file); 361 file_size = cm_get_file_size(gbl_output_file);
342 fprintf(stderr, 362 acpi_log_error
343 "Output file %s contains 0x%X (%u) bytes\n\n", 363 ("Output file %s contains 0x%X (%u) bytes\n\n",
344 gbl_output_filename, file_size, file_size); 364 gbl_output_filename, file_size, file_size);
345 } 365 }
346 366
347 fclose(gbl_output_file); 367 acpi_os_close_file(gbl_output_file);
348 } 368 }
349 369
350 return (status); 370 return (status);
diff --git a/tools/power/cpupower/bench/parse.c b/tools/power/cpupower/bench/parse.c
index 543bba14ae2c..f503fb53824e 100644
--- a/tools/power/cpupower/bench/parse.c
+++ b/tools/power/cpupower/bench/parse.c
@@ -158,14 +158,15 @@ struct config *prepare_default_config()
158int prepare_config(const char *path, struct config *config) 158int prepare_config(const char *path, struct config *config)
159{ 159{
160 size_t len = 0; 160 size_t len = 0;
161 char *opt, *val, *line = NULL; 161 char opt[16], val[32], *line = NULL;
162 FILE *configfile = fopen(path, "r"); 162 FILE *configfile;
163 163
164 if (config == NULL) { 164 if (config == NULL) {
165 fprintf(stderr, "error: config is NULL\n"); 165 fprintf(stderr, "error: config is NULL\n");
166 return 1; 166 return 1;
167 } 167 }
168 168
169 configfile = fopen(path, "r");
169 if (configfile == NULL) { 170 if (configfile == NULL) {
170 perror("fopen"); 171 perror("fopen");
171 fprintf(stderr, "error: unable to read configfile\n"); 172 fprintf(stderr, "error: unable to read configfile\n");
@@ -174,52 +175,54 @@ int prepare_config(const char *path, struct config *config)
174 } 175 }
175 176
176 while (getline(&line, &len, configfile) != -1) { 177 while (getline(&line, &len, configfile) != -1) {
177 if (line[0] == '#' || line[0] == ' ') 178 if (line[0] == '#' || line[0] == ' ' || line[0] == '\n')
178 continue; 179 continue;
179 180
180 sscanf(line, "%as = %as", &opt, &val); 181 if (sscanf(line, "%14s = %30s", opt, val) < 2)
182 continue;
181 183
182 dprintf("parsing: %s -> %s\n", opt, val); 184 dprintf("parsing: %s -> %s\n", opt, val);
183 185
184 if (strncmp("sleep", opt, strlen(opt)) == 0) 186 if (strcmp("sleep", opt) == 0)
185 sscanf(val, "%li", &config->sleep); 187 sscanf(val, "%li", &config->sleep);
186 188
187 else if (strncmp("load", opt, strlen(opt)) == 0) 189 else if (strcmp("load", opt) == 0)
188 sscanf(val, "%li", &config->load); 190 sscanf(val, "%li", &config->load);
189 191
190 else if (strncmp("load_step", opt, strlen(opt)) == 0) 192 else if (strcmp("load_step", opt) == 0)
191 sscanf(val, "%li", &config->load_step); 193 sscanf(val, "%li", &config->load_step);
192 194
193 else if (strncmp("sleep_step", opt, strlen(opt)) == 0) 195 else if (strcmp("sleep_step", opt) == 0)
194 sscanf(val, "%li", &config->sleep_step); 196 sscanf(val, "%li", &config->sleep_step);
195 197
196 else if (strncmp("cycles", opt, strlen(opt)) == 0) 198 else if (strcmp("cycles", opt) == 0)
197 sscanf(val, "%u", &config->cycles); 199 sscanf(val, "%u", &config->cycles);
198 200
199 else if (strncmp("rounds", opt, strlen(opt)) == 0) 201 else if (strcmp("rounds", opt) == 0)
200 sscanf(val, "%u", &config->rounds); 202 sscanf(val, "%u", &config->rounds);
201 203
202 else if (strncmp("verbose", opt, strlen(opt)) == 0) 204 else if (strcmp("verbose", opt) == 0)
203 sscanf(val, "%u", &config->verbose); 205 sscanf(val, "%u", &config->verbose);
204 206
205 else if (strncmp("output", opt, strlen(opt)) == 0) 207 else if (strcmp("output", opt) == 0)
206 config->output = prepare_output(val); 208 config->output = prepare_output(val);
207 209
208 else if (strncmp("cpu", opt, strlen(opt)) == 0) 210 else if (strcmp("cpu", opt) == 0)
209 sscanf(val, "%u", &config->cpu); 211 sscanf(val, "%u", &config->cpu);
210 212
211 else if (strncmp("governor", opt, 14) == 0) 213 else if (strcmp("governor", opt) == 0) {
212 strncpy(config->governor, val, 14); 214 strncpy(config->governor, val,
215 sizeof(config->governor));
216 config->governor[sizeof(config->governor) - 1] = '\0';
217 }
213 218
214 else if (strncmp("priority", opt, strlen(opt)) == 0) { 219 else if (strcmp("priority", opt) == 0) {
215 if (string_to_prio(val) != SCHED_ERR) 220 if (string_to_prio(val) != SCHED_ERR)
216 config->prio = string_to_prio(val); 221 config->prio = string_to_prio(val);
217 } 222 }
218 } 223 }
219 224
220 free(line); 225 free(line);
221 free(opt);
222 free(val);
223 226
224 return 0; 227 return 0;
225} 228}
diff --git a/tools/power/cpupower/utils/cpufreq-set.c b/tools/power/cpupower/utils/cpufreq-set.c
index a416de80c55e..f656e585ed45 100644
--- a/tools/power/cpupower/utils/cpufreq-set.c
+++ b/tools/power/cpupower/utils/cpufreq-set.c
@@ -320,12 +320,11 @@ int cmd_freq_set(int argc, char **argv)
320 320
321 printf(_("Setting cpu: %d\n"), cpu); 321 printf(_("Setting cpu: %d\n"), cpu);
322 ret = do_one_cpu(cpu, &new_pol, freq, policychange); 322 ret = do_one_cpu(cpu, &new_pol, freq, policychange);
323 if (ret) 323 if (ret) {
324 break; 324 print_error();
325 return ret;
326 }
325 } 327 }
326 328
327 if (ret) 329 return 0;
328 print_error();
329
330 return ret;
331} 330}
diff --git a/tools/power/cpupower/utils/helpers/sysfs.c b/tools/power/cpupower/utils/helpers/sysfs.c
index 851c7a16ca49..09afe5d87f2b 100644
--- a/tools/power/cpupower/utils/helpers/sysfs.c
+++ b/tools/power/cpupower/utils/helpers/sysfs.c
@@ -81,7 +81,7 @@ int sysfs_is_cpu_online(unsigned int cpu)
81 close(fd); 81 close(fd);
82 82
83 value = strtoull(linebuf, &endp, 0); 83 value = strtoull(linebuf, &endp, 0);
84 if (value > 1 || value < 0) 84 if (value > 1)
85 return -EINVAL; 85 return -EINVAL;
86 86
87 return value; 87 return value;
diff --git a/tools/power/cpupower/utils/idle_monitor/mperf_monitor.c b/tools/power/cpupower/utils/idle_monitor/mperf_monitor.c
index 5650ab5a2c20..90a8c4f071e7 100644
--- a/tools/power/cpupower/utils/idle_monitor/mperf_monitor.c
+++ b/tools/power/cpupower/utils/idle_monitor/mperf_monitor.c
@@ -237,7 +237,7 @@ static int init_maxfreq_mode(void)
237 unsigned long long hwcr; 237 unsigned long long hwcr;
238 unsigned long min; 238 unsigned long min;
239 239
240 if (!cpupower_cpu_info.caps & CPUPOWER_CAP_INV_TSC) 240 if (!(cpupower_cpu_info.caps & CPUPOWER_CAP_INV_TSC))
241 goto use_sysfs; 241 goto use_sysfs;
242 242
243 if (cpupower_cpu_info.vendor == X86_VENDOR_AMD) { 243 if (cpupower_cpu_info.vendor == X86_VENDOR_AMD) {