aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2013-07-03 17:35:40 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2013-07-03 17:35:40 -0400
commitf991fae5c6d42dfc5029150b05a78cf3f6c18cc9 (patch)
treed140deb437bde0631778b4984eeb72c1f4ee0c1d /drivers
parentd4141531f63a29bb2a980092b6f2828c385e6edd (diff)
parent2c843bd92ec276ecb68504b3b5ffa7066183f032 (diff)
Merge tag 'pm+acpi-3.11-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm
Pull power management and ACPI updates from Rafael Wysocki: "This time the total number of ACPI commits is slightly greater than the number of cpufreq commits, but Viresh Kumar (who works on cpufreq) remains the most active patch submitter. To me, the most significant change is the addition of offline/online device operations to the driver core (with the Greg's blessing) and the related modifications of the ACPI core hotplug code. Next are the freezer updates from Colin Cross that should make the freezing of tasks a bit less heavy weight. We also have a couple of regression fixes, a number of fixes for issues that have not been identified as regressions, two new drivers and a bunch of cleanups all over. Highlights: - Hotplug changes to support graceful hot-removal failures. It sometimes is necessary to fail device hot-removal operations gracefully if they cannot be carried out completely. For example, if memory from a memory module being hot-removed has been allocated for the kernel's own use and cannot be moved elsewhere, it's desirable to fail the hot-removal operation in a graceful way rather than to crash the kernel, but currenty a success or a kernel crash are the only possible outcomes of an attempted memory hot-removal. Needless to say, that is not a very attractive alternative and it had to be addressed. However, in order to make it work for memory, I first had to make it work for CPUs and for this purpose I needed to modify the ACPI processor driver. It's been split into two parts, a resident one handling the low-level initialization/cleanup and a modular one playing the actual driver's role (but it binds to the CPU system device objects rather than to the ACPI device objects representing processors). That's been sort of like a live brain surgery on a patient who's riding a bike. So this is a little scary, but since we found and fixed a couple of regressions it caused to happen during the early linux-next testing (a month ago), nobody has complained. As a bonus we remove some duplicated ACPI hotplug code, because the ACPI-based CPU hotplug is now going to use the common ACPI hotplug code. - Lighter weight freezing of tasks. These changes from Colin Cross and Mandeep Singh Baines are targeted at making the freezing of tasks a bit less heavy weight operation. They reduce the number of tasks woken up every time during the freezing, by using the observation that the freezer simply doesn't need to wake up some of them and wait for them all to call refrigerator(). The time needed for the freezer to decide to report a failure is reduced too. Also reintroduced is the check causing a lockdep warining to trigger when try_to_freeze() is called with locks held (which is generally unsafe and shouldn't happen). - cpufreq updates First off, a commit from Srivatsa S Bhat fixes a resume regression introduced during the 3.10 cycle causing some cpufreq sysfs attributes to return wrong values to user space after resume. The fix is kind of fresh, but also it's pretty obvious once Srivatsa has identified the root cause. Second, we have a new freqdomain_cpus sysfs attribute for the acpi-cpufreq driver to provide information previously available via related_cpus. From Lan Tianyu. Finally, we fix a number of issues, mostly related to the CPUFREQ_POSTCHANGE notifier and cpufreq Kconfig options and clean up some code. The majority of changes from Viresh Kumar with bits from Jacob Shin, Heiko Stübner, Xiaoguang Chen, Ezequiel Garcia, Arnd Bergmann, and Tang Yuantian. - ACPICA update A usual bunch of updates from the ACPICA upstream. During the 3.4 cycle we introduced support for ACPI 5 extended sleep registers, but they are only supposed to be used if the HW-reduced mode bit is set in the FADT flags and the code attempted to use them without checking that bit. That caused suspend/resume regressions to happen on some systems. Fix from Lv Zheng causes those registers to be used only if the HW-reduced mode bit is set. Apart from this some other ACPICA bugs are fixed and code cleanups are made by Bob Moore, Tomasz Nowicki, Lv Zheng, Chao Guan, and Zhang Rui. - cpuidle updates New driver for Xilinx Zynq processors is added by Michal Simek. Multidriver support simplification, addition of some missing kerneldoc comments and Kconfig-related fixes come from Daniel Lezcano. - ACPI power management updates Changes to make suspend/resume work correctly in Xen guests from Konrad Rzeszutek Wilk, sparse warning fix from Fengguang Wu and cleanups and fixes of the ACPI device power state selection routine. - ACPI documentation updates Some previously missing pieces of ACPI documentation are added by Lv Zheng and Aaron Lu (hopefully, that will help people to uderstand how the ACPI subsystem works) and one outdated doc is updated by Hanjun Guo. - Assorted ACPI updates We finally nailed down the IA-64 issue that was the reason for reverting commit 9f29ab11ddbf ("ACPI / scan: do not match drivers against objects having scan handlers"), so we can fix it and move the ACPI scan handler check added to the ACPI video driver back to the core. A mechanism for adding CMOS RTC address space handlers is introduced by Lan Tianyu to allow some EC-related breakage to be fixed on some systems. A spec-compliant implementation of acpi_os_get_timer() is added by Mika Westerberg. The evaluation of _STA is added to do_acpi_find_child() to avoid situations in which a pointer to a disabled device object is returned instead of an enabled one with the same _ADR value. From Jeff Wu. Intel BayTrail PCH (Platform Controller Hub) support is added to the ACPI driver for Intel Low-Power Subsystems (LPSS) and that driver is modified to work around a couple of known BIOS issues. Changes from Mika Westerberg and Heikki Krogerus. The EC driver is fixed by Vasiliy Kulikov to use get_user() and put_user() instead of dereferencing user space pointers blindly. Code cleanups are made by Bjorn Helgaas, Nicholas Mazzuca and Toshi Kani. - Assorted power management updates The "runtime idle" helper routine is changed to take the return values of the callbacks executed by it into account and to call rpm_suspend() if they return 0, which allows us to reduce the overall code bloat a bit (by dropping some code that's not necessary any more after that modification). The runtime PM documentation is updated by Alan Stern (to reflect the "runtime idle" behavior change). New trace points for PM QoS are added by Sahara (<keun-o.park@windriver.com>). PM QoS documentation is updated by Lan Tianyu. Code cleanups are made and minor issues are addressed by Bernie Thompson, Bjorn Helgaas, Julius Werner, and Shuah Khan. - devfreq updates New driver for the Exynos5-bus device from Abhilash Kesavan. Minor cleanups, fixes and MAINTAINERS update from MyungJoo Ham, Abhilash Kesavan, Paul Bolle, Rajagopal Venkat, and Wei Yongjun. - OMAP power management updates Adaptive Voltage Scaling (AVS) SmartReflex voltage control driver updates from Andrii Tseglytskyi and Nishanth Menon." * tag 'pm+acpi-3.11-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm: (162 commits) cpufreq: Fix cpufreq regression after suspend/resume ACPI / PM: Fix possible NULL pointer deref in acpi_pm_device_sleep_state() PM / Sleep: Warn about system time after resume with pm_trace cpufreq: don't leave stale policy pointer in cdbs->cur_policy acpi-cpufreq: Add new sysfs attribute freqdomain_cpus cpufreq: make sure frequency transitions are serialized ACPI: implement acpi_os_get_timer() according the spec ACPI / EC: Add HP Folio 13 to ec_dmi_table in order to skip DSDT scan ACPI: Add CMOS RTC Operation Region handler support ACPI / processor: Drop unused variable from processor_perflib.c cpufreq: tegra: call CPUFREQ_POSTCHANGE notfier in error cases cpufreq: s3c64xx: call CPUFREQ_POSTCHANGE notfier in error cases cpufreq: omap: call CPUFREQ_POSTCHANGE notfier in error cases cpufreq: imx6q: call CPUFREQ_POSTCHANGE notfier in error cases cpufreq: exynos: call CPUFREQ_POSTCHANGE notfier in error cases cpufreq: dbx500: call CPUFREQ_POSTCHANGE notfier in error cases cpufreq: davinci: call CPUFREQ_POSTCHANGE notfier in error cases cpufreq: arm-big-little: call CPUFREQ_POSTCHANGE notfier in error cases cpufreq: powernow-k8: call CPUFREQ_POSTCHANGE notfier in error cases cpufreq: pcc: call CPUFREQ_POSTCHANGE notfier in error cases ...
Diffstat (limited to 'drivers')
-rw-r--r--drivers/acpi/Makefile2
-rw-r--r--drivers/acpi/acpi_cmos_rtc.c92
-rw-r--r--drivers/acpi/acpi_lpss.c125
-rw-r--r--drivers/acpi/acpi_memhotplug.c62
-rw-r--r--drivers/acpi/acpi_processor.c494
-rw-r--r--drivers/acpi/acpica/Makefile4
-rw-r--r--drivers/acpi/acpica/acglobal.h6
-rw-r--r--drivers/acpi/acpica/aclocal.h17
-rw-r--r--drivers/acpi/acpica/acmacros.h10
-rw-r--r--drivers/acpi/acpica/acnamesp.h43
-rw-r--r--drivers/acpi/acpica/acpredef.h4
-rw-r--r--drivers/acpi/acpica/acstruct.h40
-rw-r--r--drivers/acpi/acpica/acutils.h50
-rw-r--r--drivers/acpi/acpica/dscontrol.c4
-rw-r--r--drivers/acpi/acpica/dsfield.c4
-rw-r--r--drivers/acpi/acpica/dsinit.c1
-rw-r--r--drivers/acpi/acpica/dsmthdat.c2
-rw-r--r--drivers/acpi/acpica/dsobject.c3
-rw-r--r--drivers/acpi/acpica/dsopcode.c1
-rw-r--r--drivers/acpi/acpica/dsutils.c5
-rw-r--r--drivers/acpi/acpica/dswexec.c3
-rw-r--r--drivers/acpi/acpica/dswload.c7
-rw-r--r--drivers/acpi/acpica/dswload2.c4
-rw-r--r--drivers/acpi/acpica/evglock.c1
-rw-r--r--drivers/acpi/acpica/evgpe.c7
-rw-r--r--drivers/acpi/acpica/evgpeblk.c2
-rw-r--r--drivers/acpi/acpica/evgpeinit.c3
-rw-r--r--drivers/acpi/acpica/evhandler.c7
-rw-r--r--drivers/acpi/acpica/evmisc.c3
-rw-r--r--drivers/acpi/acpica/evregion.c63
-rw-r--r--drivers/acpi/acpica/evrgnini.c2
-rw-r--r--drivers/acpi/acpica/evxfgpe.c3
-rw-r--r--drivers/acpi/acpica/evxfregn.c1
-rw-r--r--drivers/acpi/acpica/exconfig.c3
-rw-r--r--drivers/acpi/acpica/exconvrt.c13
-rw-r--r--drivers/acpi/acpica/excreate.c3
-rw-r--r--drivers/acpi/acpica/exdebug.c2
-rw-r--r--drivers/acpi/acpica/exdump.c2
-rw-r--r--drivers/acpi/acpica/exfield.c4
-rw-r--r--drivers/acpi/acpica/exfldio.c2
-rw-r--r--drivers/acpi/acpica/exmisc.c12
-rw-r--r--drivers/acpi/acpica/exoparg1.c16
-rw-r--r--drivers/acpi/acpica/exoparg2.c1
-rw-r--r--drivers/acpi/acpica/exoparg3.c1
-rw-r--r--drivers/acpi/acpica/exoparg6.c5
-rw-r--r--drivers/acpi/acpica/exprep.c7
-rw-r--r--drivers/acpi/acpica/exregion.c27
-rw-r--r--drivers/acpi/acpica/exresnte.c1
-rw-r--r--drivers/acpi/acpica/exresolv.c6
-rw-r--r--drivers/acpi/acpica/exresop.c9
-rw-r--r--drivers/acpi/acpica/exstore.c4
-rw-r--r--drivers/acpi/acpica/exstoren.c4
-rw-r--r--drivers/acpi/acpica/hwacpi.c2
-rw-r--r--drivers/acpi/acpica/hwgpe.c3
-rw-r--r--drivers/acpi/acpica/hwregs.c4
-rw-r--r--drivers/acpi/acpica/hwxface.c9
-rw-r--r--drivers/acpi/acpica/hwxfsleep.c12
-rw-r--r--drivers/acpi/acpica/nsaccess.c1
-rw-r--r--drivers/acpi/acpica/nsarguments.c294
-rw-r--r--drivers/acpi/acpica/nsconvert.c3
-rw-r--r--drivers/acpi/acpica/nsdump.c10
-rw-r--r--drivers/acpi/acpica/nseval.c247
-rw-r--r--drivers/acpi/acpica/nsinit.c16
-rw-r--r--drivers/acpi/acpica/nspredef.c216
-rw-r--r--drivers/acpi/acpica/nsprepkg.c81
-rw-r--r--drivers/acpi/acpica/nsrepair.c51
-rw-r--r--drivers/acpi/acpica/nsrepair2.c358
-rw-r--r--drivers/acpi/acpica/nsutils.c3
-rw-r--r--drivers/acpi/acpica/nsxfeval.c163
-rw-r--r--drivers/acpi/acpica/psargs.c4
-rw-r--r--drivers/acpi/acpica/psloop.c2
-rw-r--r--drivers/acpi/acpica/psobject.c1
-rw-r--r--drivers/acpi/acpica/psparse.c3
-rw-r--r--drivers/acpi/acpica/pstree.c2
-rw-r--r--drivers/acpi/acpica/psxface.c14
-rw-r--r--drivers/acpi/acpica/rscalc.c7
-rw-r--r--drivers/acpi/acpica/rscreate.c27
-rw-r--r--drivers/acpi/acpica/rsdump.c10
-rw-r--r--drivers/acpi/acpica/rsmisc.c3
-rw-r--r--drivers/acpi/acpica/rsutils.c7
-rw-r--r--drivers/acpi/acpica/rsxface.c1
-rw-r--r--drivers/acpi/acpica/tbinstal.c7
-rw-r--r--drivers/acpi/acpica/tbprint.c237
-rw-r--r--drivers/acpi/acpica/tbutils.c191
-rw-r--r--drivers/acpi/acpica/tbxfload.c25
-rw-r--r--drivers/acpi/acpica/utbuffer.c201
-rw-r--r--drivers/acpi/acpica/utcopy.c11
-rw-r--r--drivers/acpi/acpica/utdebug.c148
-rw-r--r--drivers/acpi/acpica/utdelete.c3
-rw-r--r--drivers/acpi/acpica/uterror.c289
-rw-r--r--drivers/acpi/acpica/uteval.c9
-rw-r--r--drivers/acpi/acpica/utexcep.c1
-rw-r--r--drivers/acpi/acpica/utids.c3
-rw-r--r--drivers/acpi/acpica/utmisc.c2
-rw-r--r--drivers/acpi/acpica/utobject.c5
-rw-r--r--drivers/acpi/acpica/utpredef.c16
-rw-r--r--drivers/acpi/acpica/utstring.c19
-rw-r--r--drivers/acpi/acpica/uttrack.c8
-rw-r--r--drivers/acpi/acpica/utxferror.c234
-rw-r--r--drivers/acpi/battery.c18
-rw-r--r--drivers/acpi/bus.c17
-rw-r--r--drivers/acpi/device_pm.c170
-rw-r--r--drivers/acpi/ec.c4
-rw-r--r--drivers/acpi/ec_sys.c18
-rw-r--r--drivers/acpi/glue.c12
-rw-r--r--drivers/acpi/internal.h10
-rw-r--r--drivers/acpi/osl.c27
-rw-r--r--drivers/acpi/processor_driver.c818
-rw-r--r--drivers/acpi/processor_idle.c4
-rw-r--r--drivers/acpi/processor_perflib.c4
-rw-r--r--drivers/acpi/scan.c205
-rw-r--r--drivers/acpi/sleep.c2
-rw-r--r--drivers/acpi/sysfs.c31
-rw-r--r--drivers/acpi/video.c3
-rw-r--r--drivers/amba/bus.c2
-rw-r--r--drivers/ata/libata-core.c2
-rw-r--r--drivers/base/core.c130
-rw-r--r--drivers/base/cpu.c101
-rw-r--r--drivers/base/memory.c114
-rw-r--r--drivers/base/platform.c1
-rw-r--r--drivers/base/power/domain.c1
-rw-r--r--drivers/base/power/generic_ops.c23
-rw-r--r--drivers/base/power/opp.c4
-rw-r--r--drivers/base/power/qos.c6
-rw-r--r--drivers/base/power/runtime.c12
-rw-r--r--drivers/base/power/wakeup.c9
-rw-r--r--drivers/clk/x86/clk-lpt.c4
-rw-r--r--drivers/cpufreq/Kconfig.arm17
-rw-r--r--drivers/cpufreq/Kconfig.powerpc37
-rw-r--r--drivers/cpufreq/Kconfig.x861
-rw-r--r--drivers/cpufreq/Makefile8
-rw-r--r--drivers/cpufreq/acpi-cpufreq.c46
-rw-r--r--drivers/cpufreq/arm_big_little.c4
-rw-r--r--drivers/cpufreq/blackfin-cpufreq.c10
-rw-r--r--drivers/cpufreq/cpufreq.c223
-rw-r--r--drivers/cpufreq/cpufreq_governor.c51
-rw-r--r--drivers/cpufreq/cpufreq_governor.h5
-rw-r--r--drivers/cpufreq/cpufreq_performance.c4
-rw-r--r--drivers/cpufreq/cpufreq_powersave.c6
-rw-r--r--drivers/cpufreq/cpufreq_stats.c5
-rw-r--r--drivers/cpufreq/cpufreq_userspace.c112
-rw-r--r--drivers/cpufreq/davinci-cpufreq.c3
-rw-r--r--drivers/cpufreq/dbx500-cpufreq.c4
-rw-r--r--drivers/cpufreq/e_powersaver.c11
-rw-r--r--drivers/cpufreq/exynos-cpufreq.c10
-rw-r--r--drivers/cpufreq/freq_table.c26
-rw-r--r--drivers/cpufreq/ia64-acpi-cpufreq.c2
-rw-r--r--drivers/cpufreq/imx6q-cpufreq.c17
-rw-r--r--drivers/cpufreq/kirkwood-cpufreq.c2
-rw-r--r--drivers/cpufreq/longhaul.c16
-rw-r--r--drivers/cpufreq/loongson2_cpufreq.c2
-rw-r--r--drivers/cpufreq/omap-cpufreq.c6
-rw-r--r--drivers/cpufreq/p4-clockmod.c4
-rw-r--r--drivers/cpufreq/pasemi-cpufreq.c331
-rw-r--r--drivers/cpufreq/pcc-cpufreq.c2
-rw-r--r--drivers/cpufreq/pmac32-cpufreq.c721
-rw-r--r--drivers/cpufreq/pmac64-cpufreq.c746
-rw-r--r--drivers/cpufreq/powernow-k6.c8
-rw-r--r--drivers/cpufreq/powernow-k7.c16
-rw-r--r--drivers/cpufreq/powernow-k8.c24
-rw-r--r--drivers/cpufreq/ppc-corenet-cpufreq.c380
-rw-r--r--drivers/cpufreq/ppc_cbe_cpufreq.c4
-rw-r--r--drivers/cpufreq/pxa2xx-cpufreq.c8
-rw-r--r--drivers/cpufreq/pxa3xx-cpufreq.c4
-rw-r--r--drivers/cpufreq/s3c2416-cpufreq.c6
-rw-r--r--drivers/cpufreq/s3c24xx-cpufreq.c4
-rw-r--r--drivers/cpufreq/s3c64xx-cpufreq.c10
-rw-r--r--drivers/cpufreq/sc520_freq.c2
-rw-r--r--drivers/cpufreq/sparc-us2e-cpufreq.c12
-rw-r--r--drivers/cpufreq/sparc-us3-cpufreq.c8
-rw-r--r--drivers/cpufreq/spear-cpufreq.c4
-rw-r--r--drivers/cpufreq/speedstep-centrino.c8
-rw-r--r--drivers/cpufreq/tegra-cpufreq.c23
-rw-r--r--drivers/cpuidle/Kconfig27
-rw-r--r--drivers/cpuidle/Makefile1
-rw-r--r--drivers/cpuidle/cpuidle-zynq.c83
-rw-r--r--drivers/cpuidle/cpuidle.c4
-rw-r--r--drivers/cpuidle/driver.c324
-rw-r--r--drivers/devfreq/Kconfig12
-rw-r--r--drivers/devfreq/Makefile3
-rw-r--r--drivers/devfreq/devfreq.c25
-rw-r--r--drivers/devfreq/exynos/Makefile3
-rw-r--r--drivers/devfreq/exynos/exynos4_bus.c (renamed from drivers/devfreq/exynos4_bus.c)1
-rw-r--r--drivers/devfreq/exynos/exynos5_bus.c503
-rw-r--r--drivers/devfreq/exynos/exynos_ppmu.c56
-rw-r--r--drivers/devfreq/exynos/exynos_ppmu.h78
-rw-r--r--drivers/dma/intel_mid_dma.c2
-rw-r--r--drivers/gpio/gpio-langwell.c6
-rw-r--r--drivers/i2c/i2c-core.c2
-rw-r--r--drivers/mfd/ab8500-gpadc.c8
-rw-r--r--drivers/mfd/db8500-prcmu.c10
-rw-r--r--drivers/mmc/core/bus.c2
-rw-r--r--drivers/mmc/core/sdio_bus.c2
-rw-r--r--drivers/pci/pci-driver.c14
-rw-r--r--drivers/pnp/manager.c14
-rw-r--r--drivers/power/avs/smartreflex.c154
-rw-r--r--drivers/scsi/scsi_pm.c11
-rw-r--r--drivers/sh/clk/core.c4
-rw-r--r--drivers/sh/pm_runtime.c2
-rw-r--r--drivers/spi/spi.c2
-rw-r--r--drivers/staging/android/binder.c5
-rw-r--r--drivers/tty/serial/mfd.c9
-rw-r--r--drivers/usb/core/driver.c3
-rw-r--r--drivers/usb/core/port.c1
204 files changed, 7276 insertions, 2960 deletions
diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index 536562c626a2..81dbeb83bb45 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -34,6 +34,7 @@ acpi-$(CONFIG_ACPI_SLEEP) += proc.o
34acpi-y += bus.o glue.o 34acpi-y += bus.o glue.o
35acpi-y += scan.o 35acpi-y += scan.o
36acpi-y += resource.o 36acpi-y += resource.o
37acpi-y += acpi_processor.o
37acpi-y += processor_core.o 38acpi-y += processor_core.o
38acpi-y += ec.o 39acpi-y += ec.o
39acpi-$(CONFIG_ACPI_DOCK) += dock.o 40acpi-$(CONFIG_ACPI_DOCK) += dock.o
@@ -43,6 +44,7 @@ acpi-y += acpi_platform.o
43acpi-y += power.o 44acpi-y += power.o
44acpi-y += event.o 45acpi-y += event.o
45acpi-y += sysfs.o 46acpi-y += sysfs.o
47acpi-$(CONFIG_X86) += acpi_cmos_rtc.o
46acpi-$(CONFIG_DEBUG_FS) += debugfs.o 48acpi-$(CONFIG_DEBUG_FS) += debugfs.o
47acpi-$(CONFIG_ACPI_NUMA) += numa.o 49acpi-$(CONFIG_ACPI_NUMA) += numa.o
48acpi-$(CONFIG_ACPI_PROCFS_POWER) += cm_sbs.o 50acpi-$(CONFIG_ACPI_PROCFS_POWER) += cm_sbs.o
diff --git a/drivers/acpi/acpi_cmos_rtc.c b/drivers/acpi/acpi_cmos_rtc.c
new file mode 100644
index 000000000000..84190ed89c04
--- /dev/null
+++ b/drivers/acpi/acpi_cmos_rtc.c
@@ -0,0 +1,92 @@
1/*
2 * ACPI support for CMOS RTC Address Space access
3 *
4 * Copyright (C) 2013, Intel Corporation
5 * Authors: Lan Tianyu <tianyu.lan@intel.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/acpi.h>
13#include <linux/device.h>
14#include <linux/err.h>
15#include <linux/kernel.h>
16#include <linux/module.h>
17#include <asm-generic/rtc.h>
18
19#include "internal.h"
20
21#define PREFIX "ACPI: "
22
23ACPI_MODULE_NAME("cmos rtc");
24
25static const struct acpi_device_id acpi_cmos_rtc_ids[] = {
26 { "PNP0B00" },
27 { "PNP0B01" },
28 { "PNP0B02" },
29 {}
30};
31
32static acpi_status
33acpi_cmos_rtc_space_handler(u32 function, acpi_physical_address address,
34 u32 bits, u64 *value64,
35 void *handler_context, void *region_context)
36{
37 int i;
38 u8 *value = (u8 *)&value64;
39
40 if (address > 0xff || !value64)
41 return AE_BAD_PARAMETER;
42
43 if (function != ACPI_WRITE && function != ACPI_READ)
44 return AE_BAD_PARAMETER;
45
46 spin_lock_irq(&rtc_lock);
47
48 for (i = 0; i < DIV_ROUND_UP(bits, 8); ++i, ++address, ++value)
49 if (function == ACPI_READ)
50 *value = CMOS_READ(address);
51 else
52 CMOS_WRITE(*value, address);
53
54 spin_unlock_irq(&rtc_lock);
55
56 return AE_OK;
57}
58
59static int acpi_install_cmos_rtc_space_handler(struct acpi_device *adev,
60 const struct acpi_device_id *id)
61{
62 acpi_status status;
63
64 status = acpi_install_address_space_handler(adev->handle,
65 ACPI_ADR_SPACE_CMOS,
66 &acpi_cmos_rtc_space_handler,
67 NULL, NULL);
68 if (ACPI_FAILURE(status)) {
69 pr_err(PREFIX "Error installing CMOS-RTC region handler\n");
70 return -ENODEV;
71 }
72
73 return 0;
74}
75
76static void acpi_remove_cmos_rtc_space_handler(struct acpi_device *adev)
77{
78 if (ACPI_FAILURE(acpi_remove_address_space_handler(adev->handle,
79 ACPI_ADR_SPACE_CMOS, &acpi_cmos_rtc_space_handler)))
80 pr_err(PREFIX "Error removing CMOS-RTC region handler\n");
81}
82
83static struct acpi_scan_handler cmos_rtc_handler = {
84 .ids = acpi_cmos_rtc_ids,
85 .attach = acpi_install_cmos_rtc_space_handler,
86 .detach = acpi_remove_cmos_rtc_space_handler,
87};
88
89void __init acpi_cmos_rtc_init(void)
90{
91 acpi_scan_add_handler(&cmos_rtc_handler);
92}
diff --git a/drivers/acpi/acpi_lpss.c b/drivers/acpi/acpi_lpss.c
index cab13f2fc28e..6a382188fa20 100644
--- a/drivers/acpi/acpi_lpss.c
+++ b/drivers/acpi/acpi_lpss.c
@@ -32,12 +32,26 @@ ACPI_MODULE_NAME("acpi_lpss");
32#define LPSS_GENERAL_LTR_MODE_SW BIT(2) 32#define LPSS_GENERAL_LTR_MODE_SW BIT(2)
33#define LPSS_SW_LTR 0x10 33#define LPSS_SW_LTR 0x10
34#define LPSS_AUTO_LTR 0x14 34#define LPSS_AUTO_LTR 0x14
35#define LPSS_TX_INT 0x20
36#define LPSS_TX_INT_MASK BIT(1)
37
38struct lpss_shared_clock {
39 const char *name;
40 unsigned long rate;
41 struct clk *clk;
42};
43
44struct lpss_private_data;
35 45
36struct lpss_device_desc { 46struct lpss_device_desc {
37 bool clk_required; 47 bool clk_required;
38 const char *clkdev_name; 48 const char *clkdev_name;
39 bool ltr_required; 49 bool ltr_required;
40 unsigned int prv_offset; 50 unsigned int prv_offset;
51 size_t prv_size_override;
52 bool clk_gate;
53 struct lpss_shared_clock *shared_clock;
54 void (*setup)(struct lpss_private_data *pdata);
41}; 55};
42 56
43static struct lpss_device_desc lpss_dma_desc = { 57static struct lpss_device_desc lpss_dma_desc = {
@@ -52,17 +66,76 @@ struct lpss_private_data {
52 const struct lpss_device_desc *dev_desc; 66 const struct lpss_device_desc *dev_desc;
53}; 67};
54 68
69static void lpss_uart_setup(struct lpss_private_data *pdata)
70{
71 unsigned int tx_int_offset = pdata->dev_desc->prv_offset + LPSS_TX_INT;
72 u32 reg;
73
74 reg = readl(pdata->mmio_base + tx_int_offset);
75 writel(reg | LPSS_TX_INT_MASK, pdata->mmio_base + tx_int_offset);
76}
77
55static struct lpss_device_desc lpt_dev_desc = { 78static struct lpss_device_desc lpt_dev_desc = {
56 .clk_required = true, 79 .clk_required = true,
57 .prv_offset = 0x800, 80 .prv_offset = 0x800,
58 .ltr_required = true, 81 .ltr_required = true,
82 .clk_gate = true,
83};
84
85static struct lpss_device_desc lpt_uart_dev_desc = {
86 .clk_required = true,
87 .prv_offset = 0x800,
88 .ltr_required = true,
89 .clk_gate = true,
90 .setup = lpss_uart_setup,
59}; 91};
60 92
61static struct lpss_device_desc lpt_sdio_dev_desc = { 93static struct lpss_device_desc lpt_sdio_dev_desc = {
62 .prv_offset = 0x1000, 94 .prv_offset = 0x1000,
95 .prv_size_override = 0x1018,
63 .ltr_required = true, 96 .ltr_required = true,
64}; 97};
65 98
99static struct lpss_shared_clock uart_clock = {
100 .name = "uart_clk",
101 .rate = 44236800,
102};
103
104static struct lpss_device_desc byt_uart_dev_desc = {
105 .clk_required = true,
106 .prv_offset = 0x800,
107 .clk_gate = true,
108 .shared_clock = &uart_clock,
109 .setup = lpss_uart_setup,
110};
111
112static struct lpss_shared_clock spi_clock = {
113 .name = "spi_clk",
114 .rate = 50000000,
115};
116
117static struct lpss_device_desc byt_spi_dev_desc = {
118 .clk_required = true,
119 .prv_offset = 0x400,
120 .clk_gate = true,
121 .shared_clock = &spi_clock,
122};
123
124static struct lpss_device_desc byt_sdio_dev_desc = {
125 .clk_required = true,
126};
127
128static struct lpss_shared_clock i2c_clock = {
129 .name = "i2c_clk",
130 .rate = 100000000,
131};
132
133static struct lpss_device_desc byt_i2c_dev_desc = {
134 .clk_required = true,
135 .prv_offset = 0x800,
136 .shared_clock = &i2c_clock,
137};
138
66static const struct acpi_device_id acpi_lpss_device_ids[] = { 139static const struct acpi_device_id acpi_lpss_device_ids[] = {
67 /* Generic LPSS devices */ 140 /* Generic LPSS devices */
68 { "INTL9C60", (unsigned long)&lpss_dma_desc }, 141 { "INTL9C60", (unsigned long)&lpss_dma_desc },
@@ -72,11 +145,18 @@ static const struct acpi_device_id acpi_lpss_device_ids[] = {
72 { "INT33C1", (unsigned long)&lpt_dev_desc }, 145 { "INT33C1", (unsigned long)&lpt_dev_desc },
73 { "INT33C2", (unsigned long)&lpt_dev_desc }, 146 { "INT33C2", (unsigned long)&lpt_dev_desc },
74 { "INT33C3", (unsigned long)&lpt_dev_desc }, 147 { "INT33C3", (unsigned long)&lpt_dev_desc },
75 { "INT33C4", (unsigned long)&lpt_dev_desc }, 148 { "INT33C4", (unsigned long)&lpt_uart_dev_desc },
76 { "INT33C5", (unsigned long)&lpt_dev_desc }, 149 { "INT33C5", (unsigned long)&lpt_uart_dev_desc },
77 { "INT33C6", (unsigned long)&lpt_sdio_dev_desc }, 150 { "INT33C6", (unsigned long)&lpt_sdio_dev_desc },
78 { "INT33C7", }, 151 { "INT33C7", },
79 152
153 /* BayTrail LPSS devices */
154 { "80860F0A", (unsigned long)&byt_uart_dev_desc },
155 { "80860F0E", (unsigned long)&byt_spi_dev_desc },
156 { "80860F14", (unsigned long)&byt_sdio_dev_desc },
157 { "80860F41", (unsigned long)&byt_i2c_dev_desc },
158 { "INT33B2", },
159
80 { } 160 { }
81}; 161};
82 162
@@ -98,7 +178,10 @@ static int register_device_clock(struct acpi_device *adev,
98 struct lpss_private_data *pdata) 178 struct lpss_private_data *pdata)
99{ 179{
100 const struct lpss_device_desc *dev_desc = pdata->dev_desc; 180 const struct lpss_device_desc *dev_desc = pdata->dev_desc;
181 struct lpss_shared_clock *shared_clock = dev_desc->shared_clock;
182 struct clk *clk = ERR_PTR(-ENODEV);
101 struct lpss_clk_data *clk_data; 183 struct lpss_clk_data *clk_data;
184 const char *parent;
102 185
103 if (!lpss_clk_dev) 186 if (!lpss_clk_dev)
104 lpt_register_clock_device(); 187 lpt_register_clock_device();
@@ -117,14 +200,30 @@ static int register_device_clock(struct acpi_device *adev,
117 || pdata->mmio_size < dev_desc->prv_offset + LPSS_CLK_SIZE) 200 || pdata->mmio_size < dev_desc->prv_offset + LPSS_CLK_SIZE)
118 return -ENODATA; 201 return -ENODATA;
119 202
120 pdata->clk = clk_register_gate(NULL, dev_name(&adev->dev), 203 parent = clk_data->name;
121 clk_data->name, 0, 204
122 pdata->mmio_base + dev_desc->prv_offset, 205 if (shared_clock) {
123 0, 0, NULL); 206 clk = shared_clock->clk;
124 if (IS_ERR(pdata->clk)) 207 if (!clk) {
125 return PTR_ERR(pdata->clk); 208 clk = clk_register_fixed_rate(NULL, shared_clock->name,
209 "lpss_clk", 0,
210 shared_clock->rate);
211 shared_clock->clk = clk;
212 }
213 parent = shared_clock->name;
214 }
215
216 if (dev_desc->clk_gate) {
217 clk = clk_register_gate(NULL, dev_name(&adev->dev), parent, 0,
218 pdata->mmio_base + dev_desc->prv_offset,
219 0, 0, NULL);
220 pdata->clk = clk;
221 }
126 222
127 clk_register_clkdev(pdata->clk, NULL, dev_name(&adev->dev)); 223 if (IS_ERR(clk))
224 return PTR_ERR(clk);
225
226 clk_register_clkdev(clk, NULL, dev_name(&adev->dev));
128 return 0; 227 return 0;
129} 228}
130 229
@@ -152,7 +251,10 @@ static int acpi_lpss_create_device(struct acpi_device *adev,
152 251
153 list_for_each_entry(rentry, &resource_list, node) 252 list_for_each_entry(rentry, &resource_list, node)
154 if (resource_type(&rentry->res) == IORESOURCE_MEM) { 253 if (resource_type(&rentry->res) == IORESOURCE_MEM) {
155 pdata->mmio_size = resource_size(&rentry->res); 254 if (dev_desc->prv_size_override)
255 pdata->mmio_size = dev_desc->prv_size_override;
256 else
257 pdata->mmio_size = resource_size(&rentry->res);
156 pdata->mmio_base = ioremap(rentry->res.start, 258 pdata->mmio_base = ioremap(rentry->res.start,
157 pdata->mmio_size); 259 pdata->mmio_size);
158 pdata->dev_desc = dev_desc; 260 pdata->dev_desc = dev_desc;
@@ -182,6 +284,9 @@ static int acpi_lpss_create_device(struct acpi_device *adev,
182 goto err_out; 284 goto err_out;
183 } 285 }
184 286
287 if (dev_desc->setup)
288 dev_desc->setup(pdata);
289
185 adev->driver_data = pdata; 290 adev->driver_data = pdata;
186 ret = acpi_create_platform_device(adev, id); 291 ret = acpi_create_platform_device(adev, id);
187 if (ret > 0) 292 if (ret > 0)
diff --git a/drivers/acpi/acpi_memhotplug.c b/drivers/acpi/acpi_memhotplug.c
index 5e6301e94920..c711d1144044 100644
--- a/drivers/acpi/acpi_memhotplug.c
+++ b/drivers/acpi/acpi_memhotplug.c
@@ -28,6 +28,7 @@
28 */ 28 */
29 29
30#include <linux/acpi.h> 30#include <linux/acpi.h>
31#include <linux/memory.h>
31#include <linux/memory_hotplug.h> 32#include <linux/memory_hotplug.h>
32 33
33#include "internal.h" 34#include "internal.h"
@@ -166,13 +167,50 @@ static int acpi_memory_check_device(struct acpi_memory_device *mem_device)
166 return 0; 167 return 0;
167} 168}
168 169
170static unsigned long acpi_meminfo_start_pfn(struct acpi_memory_info *info)
171{
172 return PFN_DOWN(info->start_addr);
173}
174
175static unsigned long acpi_meminfo_end_pfn(struct acpi_memory_info *info)
176{
177 return PFN_UP(info->start_addr + info->length-1);
178}
179
180static int acpi_bind_memblk(struct memory_block *mem, void *arg)
181{
182 return acpi_bind_one(&mem->dev, (acpi_handle)arg);
183}
184
185static int acpi_bind_memory_blocks(struct acpi_memory_info *info,
186 acpi_handle handle)
187{
188 return walk_memory_range(acpi_meminfo_start_pfn(info),
189 acpi_meminfo_end_pfn(info), (void *)handle,
190 acpi_bind_memblk);
191}
192
193static int acpi_unbind_memblk(struct memory_block *mem, void *arg)
194{
195 acpi_unbind_one(&mem->dev);
196 return 0;
197}
198
199static void acpi_unbind_memory_blocks(struct acpi_memory_info *info,
200 acpi_handle handle)
201{
202 walk_memory_range(acpi_meminfo_start_pfn(info),
203 acpi_meminfo_end_pfn(info), NULL, acpi_unbind_memblk);
204}
205
169static int acpi_memory_enable_device(struct acpi_memory_device *mem_device) 206static int acpi_memory_enable_device(struct acpi_memory_device *mem_device)
170{ 207{
208 acpi_handle handle = mem_device->device->handle;
171 int result, num_enabled = 0; 209 int result, num_enabled = 0;
172 struct acpi_memory_info *info; 210 struct acpi_memory_info *info;
173 int node; 211 int node;
174 212
175 node = acpi_get_node(mem_device->device->handle); 213 node = acpi_get_node(handle);
176 /* 214 /*
177 * Tell the VM there is more memory here... 215 * Tell the VM there is more memory here...
178 * Note: Assume that this function returns zero on success 216 * Note: Assume that this function returns zero on success
@@ -203,6 +241,12 @@ static int acpi_memory_enable_device(struct acpi_memory_device *mem_device)
203 if (result && result != -EEXIST) 241 if (result && result != -EEXIST)
204 continue; 242 continue;
205 243
244 result = acpi_bind_memory_blocks(info, handle);
245 if (result) {
246 acpi_unbind_memory_blocks(info, handle);
247 return -ENODEV;
248 }
249
206 info->enabled = 1; 250 info->enabled = 1;
207 251
208 /* 252 /*
@@ -227,12 +271,11 @@ static int acpi_memory_enable_device(struct acpi_memory_device *mem_device)
227 return 0; 271 return 0;
228} 272}
229 273
230static int acpi_memory_remove_memory(struct acpi_memory_device *mem_device) 274static void acpi_memory_remove_memory(struct acpi_memory_device *mem_device)
231{ 275{
232 int result = 0, nid; 276 acpi_handle handle = mem_device->device->handle;
233 struct acpi_memory_info *info, *n; 277 struct acpi_memory_info *info, *n;
234 278 int nid = acpi_get_node(handle);
235 nid = acpi_get_node(mem_device->device->handle);
236 279
237 list_for_each_entry_safe(info, n, &mem_device->res_list, list) { 280 list_for_each_entry_safe(info, n, &mem_device->res_list, list) {
238 if (!info->enabled) 281 if (!info->enabled)
@@ -240,15 +283,12 @@ static int acpi_memory_remove_memory(struct acpi_memory_device *mem_device)
240 283
241 if (nid < 0) 284 if (nid < 0)
242 nid = memory_add_physaddr_to_nid(info->start_addr); 285 nid = memory_add_physaddr_to_nid(info->start_addr);
243 result = remove_memory(nid, info->start_addr, info->length);
244 if (result)
245 return result;
246 286
287 acpi_unbind_memory_blocks(info, handle);
288 remove_memory(nid, info->start_addr, info->length);
247 list_del(&info->list); 289 list_del(&info->list);
248 kfree(info); 290 kfree(info);
249 } 291 }
250
251 return result;
252} 292}
253 293
254static void acpi_memory_device_free(struct acpi_memory_device *mem_device) 294static void acpi_memory_device_free(struct acpi_memory_device *mem_device)
@@ -300,7 +340,7 @@ static int acpi_memory_device_add(struct acpi_device *device,
300 if (result) { 340 if (result) {
301 dev_err(&device->dev, "acpi_memory_enable_device() error\n"); 341 dev_err(&device->dev, "acpi_memory_enable_device() error\n");
302 acpi_memory_device_free(mem_device); 342 acpi_memory_device_free(mem_device);
303 return -ENODEV; 343 return result;
304 } 344 }
305 345
306 dev_dbg(&device->dev, "Memory device configured by ACPI\n"); 346 dev_dbg(&device->dev, "Memory device configured by ACPI\n");
diff --git a/drivers/acpi/acpi_processor.c b/drivers/acpi/acpi_processor.c
new file mode 100644
index 000000000000..e9b01e35ac37
--- /dev/null
+++ b/drivers/acpi/acpi_processor.c
@@ -0,0 +1,494 @@
1/*
2 * acpi_processor.c - ACPI processor enumeration support
3 *
4 * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
5 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
6 * Copyright (C) 2004 Dominik Brodowski <linux@brodo.de>
7 * Copyright (C) 2004 Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
8 * Copyright (C) 2013, Intel Corporation
9 * Rafael J. Wysocki <rafael.j.wysocki@intel.com>
10 *
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License version 2 as published
13 * by the Free Software Foundation.
14 */
15
16#include <linux/acpi.h>
17#include <linux/device.h>
18#include <linux/kernel.h>
19#include <linux/module.h>
20#include <linux/pci.h>
21
22#include <acpi/processor.h>
23
24#include <asm/cpu.h>
25
26#include "internal.h"
27
28#define _COMPONENT ACPI_PROCESSOR_COMPONENT
29
30ACPI_MODULE_NAME("processor");
31
32DEFINE_PER_CPU(struct acpi_processor *, processors);
33EXPORT_PER_CPU_SYMBOL(processors);
34
35/* --------------------------------------------------------------------------
36 Errata Handling
37 -------------------------------------------------------------------------- */
38
39struct acpi_processor_errata errata __read_mostly;
40EXPORT_SYMBOL_GPL(errata);
41
42static int acpi_processor_errata_piix4(struct pci_dev *dev)
43{
44 u8 value1 = 0;
45 u8 value2 = 0;
46
47
48 if (!dev)
49 return -EINVAL;
50
51 /*
52 * Note that 'dev' references the PIIX4 ACPI Controller.
53 */
54
55 switch (dev->revision) {
56 case 0:
57 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4 A-step\n"));
58 break;
59 case 1:
60 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4 B-step\n"));
61 break;
62 case 2:
63 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4E\n"));
64 break;
65 case 3:
66 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4M\n"));
67 break;
68 default:
69 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found unknown PIIX4\n"));
70 break;
71 }
72
73 switch (dev->revision) {
74
75 case 0: /* PIIX4 A-step */
76 case 1: /* PIIX4 B-step */
77 /*
78 * See specification changes #13 ("Manual Throttle Duty Cycle")
79 * and #14 ("Enabling and Disabling Manual Throttle"), plus
80 * erratum #5 ("STPCLK# Deassertion Time") from the January
81 * 2002 PIIX4 specification update. Applies to only older
82 * PIIX4 models.
83 */
84 errata.piix4.throttle = 1;
85
86 case 2: /* PIIX4E */
87 case 3: /* PIIX4M */
88 /*
89 * See erratum #18 ("C3 Power State/BMIDE and Type-F DMA
90 * Livelock") from the January 2002 PIIX4 specification update.
91 * Applies to all PIIX4 models.
92 */
93
94 /*
95 * BM-IDE
96 * ------
97 * Find the PIIX4 IDE Controller and get the Bus Master IDE
98 * Status register address. We'll use this later to read
99 * each IDE controller's DMA status to make sure we catch all
100 * DMA activity.
101 */
102 dev = pci_get_subsys(PCI_VENDOR_ID_INTEL,
103 PCI_DEVICE_ID_INTEL_82371AB,
104 PCI_ANY_ID, PCI_ANY_ID, NULL);
105 if (dev) {
106 errata.piix4.bmisx = pci_resource_start(dev, 4);
107 pci_dev_put(dev);
108 }
109
110 /*
111 * Type-F DMA
112 * ----------
113 * Find the PIIX4 ISA Controller and read the Motherboard
114 * DMA controller's status to see if Type-F (Fast) DMA mode
115 * is enabled (bit 7) on either channel. Note that we'll
116 * disable C3 support if this is enabled, as some legacy
117 * devices won't operate well if fast DMA is disabled.
118 */
119 dev = pci_get_subsys(PCI_VENDOR_ID_INTEL,
120 PCI_DEVICE_ID_INTEL_82371AB_0,
121 PCI_ANY_ID, PCI_ANY_ID, NULL);
122 if (dev) {
123 pci_read_config_byte(dev, 0x76, &value1);
124 pci_read_config_byte(dev, 0x77, &value2);
125 if ((value1 & 0x80) || (value2 & 0x80))
126 errata.piix4.fdma = 1;
127 pci_dev_put(dev);
128 }
129
130 break;
131 }
132
133 if (errata.piix4.bmisx)
134 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
135 "Bus master activity detection (BM-IDE) erratum enabled\n"));
136 if (errata.piix4.fdma)
137 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
138 "Type-F DMA livelock erratum (C3 disabled)\n"));
139
140 return 0;
141}
142
143static int acpi_processor_errata(struct acpi_processor *pr)
144{
145 int result = 0;
146 struct pci_dev *dev = NULL;
147
148
149 if (!pr)
150 return -EINVAL;
151
152 /*
153 * PIIX4
154 */
155 dev = pci_get_subsys(PCI_VENDOR_ID_INTEL,
156 PCI_DEVICE_ID_INTEL_82371AB_3, PCI_ANY_ID,
157 PCI_ANY_ID, NULL);
158 if (dev) {
159 result = acpi_processor_errata_piix4(dev);
160 pci_dev_put(dev);
161 }
162
163 return result;
164}
165
166/* --------------------------------------------------------------------------
167 Initialization
168 -------------------------------------------------------------------------- */
169
170#ifdef CONFIG_ACPI_HOTPLUG_CPU
171static int acpi_processor_hotadd_init(struct acpi_processor *pr)
172{
173 unsigned long long sta;
174 acpi_status status;
175 int ret;
176
177 status = acpi_evaluate_integer(pr->handle, "_STA", NULL, &sta);
178 if (ACPI_FAILURE(status) || !(sta & ACPI_STA_DEVICE_PRESENT))
179 return -ENODEV;
180
181 ret = acpi_map_lsapic(pr->handle, &pr->id);
182 if (ret)
183 return ret;
184
185 ret = arch_register_cpu(pr->id);
186 if (ret) {
187 acpi_unmap_lsapic(pr->id);
188 return ret;
189 }
190
191 /*
192 * CPU got hot-added, but cpu_data is not initialized yet. Set a flag
193 * to delay cpu_idle/throttling initialization and do it when the CPU
194 * gets online for the first time.
195 */
196 pr_info("CPU%d has been hot-added\n", pr->id);
197 pr->flags.need_hotplug_init = 1;
198 return 0;
199}
200#else
201static inline int acpi_processor_hotadd_init(struct acpi_processor *pr)
202{
203 return -ENODEV;
204}
205#endif /* CONFIG_ACPI_HOTPLUG_CPU */
206
207static int acpi_processor_get_info(struct acpi_device *device)
208{
209 union acpi_object object = { 0 };
210 struct acpi_buffer buffer = { sizeof(union acpi_object), &object };
211 struct acpi_processor *pr = acpi_driver_data(device);
212 int cpu_index, device_declaration = 0;
213 acpi_status status = AE_OK;
214 static int cpu0_initialized;
215
216 if (num_online_cpus() > 1)
217 errata.smp = TRUE;
218
219 acpi_processor_errata(pr);
220
221 /*
222 * Check to see if we have bus mastering arbitration control. This
223 * is required for proper C3 usage (to maintain cache coherency).
224 */
225 if (acpi_gbl_FADT.pm2_control_block && acpi_gbl_FADT.pm2_control_length) {
226 pr->flags.bm_control = 1;
227 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
228 "Bus mastering arbitration control present\n"));
229 } else
230 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
231 "No bus mastering arbitration control\n"));
232
233 if (!strcmp(acpi_device_hid(device), ACPI_PROCESSOR_OBJECT_HID)) {
234 /* Declared with "Processor" statement; match ProcessorID */
235 status = acpi_evaluate_object(pr->handle, NULL, NULL, &buffer);
236 if (ACPI_FAILURE(status)) {
237 dev_err(&device->dev,
238 "Failed to evaluate processor object (0x%x)\n",
239 status);
240 return -ENODEV;
241 }
242
243 /*
244 * TBD: Synch processor ID (via LAPIC/LSAPIC structures) on SMP.
245 * >>> 'acpi_get_processor_id(acpi_id, &id)' in
246 * arch/xxx/acpi.c
247 */
248 pr->acpi_id = object.processor.proc_id;
249 } else {
250 /*
251 * Declared with "Device" statement; match _UID.
252 * Note that we don't handle string _UIDs yet.
253 */
254 unsigned long long value;
255 status = acpi_evaluate_integer(pr->handle, METHOD_NAME__UID,
256 NULL, &value);
257 if (ACPI_FAILURE(status)) {
258 dev_err(&device->dev,
259 "Failed to evaluate processor _UID (0x%x)\n",
260 status);
261 return -ENODEV;
262 }
263 device_declaration = 1;
264 pr->acpi_id = value;
265 }
266 cpu_index = acpi_get_cpuid(pr->handle, device_declaration, pr->acpi_id);
267
268 /* Handle UP system running SMP kernel, with no LAPIC in MADT */
269 if (!cpu0_initialized && (cpu_index == -1) &&
270 (num_online_cpus() == 1)) {
271 cpu_index = 0;
272 }
273
274 cpu0_initialized = 1;
275
276 pr->id = cpu_index;
277
278 /*
279 * Extra Processor objects may be enumerated on MP systems with
280 * less than the max # of CPUs. They should be ignored _iff
281 * they are physically not present.
282 */
283 if (pr->id == -1) {
284 int ret = acpi_processor_hotadd_init(pr);
285 if (ret)
286 return ret;
287 }
288 /*
289 * On some boxes several processors use the same processor bus id.
290 * But they are located in different scope. For example:
291 * \_SB.SCK0.CPU0
292 * \_SB.SCK1.CPU0
293 * Rename the processor device bus id. And the new bus id will be
294 * generated as the following format:
295 * CPU+CPU ID.
296 */
297 sprintf(acpi_device_bid(device), "CPU%X", pr->id);
298 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Processor [%d:%d]\n", pr->id,
299 pr->acpi_id));
300
301 if (!object.processor.pblk_address)
302 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No PBLK (NULL address)\n"));
303 else if (object.processor.pblk_length != 6)
304 dev_err(&device->dev, "Invalid PBLK length [%d]\n",
305 object.processor.pblk_length);
306 else {
307 pr->throttling.address = object.processor.pblk_address;
308 pr->throttling.duty_offset = acpi_gbl_FADT.duty_offset;
309 pr->throttling.duty_width = acpi_gbl_FADT.duty_width;
310
311 pr->pblk = object.processor.pblk_address;
312
313 /*
314 * We don't care about error returns - we just try to mark
315 * these reserved so that nobody else is confused into thinking
316 * that this region might be unused..
317 *
318 * (In particular, allocating the IO range for Cardbus)
319 */
320 request_region(pr->throttling.address, 6, "ACPI CPU throttle");
321 }
322
323 /*
324 * If ACPI describes a slot number for this CPU, we can use it to
325 * ensure we get the right value in the "physical id" field
326 * of /proc/cpuinfo
327 */
328 status = acpi_evaluate_object(pr->handle, "_SUN", NULL, &buffer);
329 if (ACPI_SUCCESS(status))
330 arch_fix_phys_package_id(pr->id, object.integer.value);
331
332 return 0;
333}
334
335/*
336 * Do not put anything in here which needs the core to be online.
337 * For example MSR access or setting up things which check for cpuinfo_x86
338 * (cpu_data(cpu)) values, like CPU feature flags, family, model, etc.
339 * Such things have to be put in and set up by the processor driver's .probe().
340 */
341static DEFINE_PER_CPU(void *, processor_device_array);
342
343static int __cpuinit acpi_processor_add(struct acpi_device *device,
344 const struct acpi_device_id *id)
345{
346 struct acpi_processor *pr;
347 struct device *dev;
348 int result = 0;
349
350 pr = kzalloc(sizeof(struct acpi_processor), GFP_KERNEL);
351 if (!pr)
352 return -ENOMEM;
353
354 if (!zalloc_cpumask_var(&pr->throttling.shared_cpu_map, GFP_KERNEL)) {
355 result = -ENOMEM;
356 goto err_free_pr;
357 }
358
359 pr->handle = device->handle;
360 strcpy(acpi_device_name(device), ACPI_PROCESSOR_DEVICE_NAME);
361 strcpy(acpi_device_class(device), ACPI_PROCESSOR_CLASS);
362 device->driver_data = pr;
363
364 result = acpi_processor_get_info(device);
365 if (result) /* Processor is not physically present or unavailable */
366 return 0;
367
368#ifdef CONFIG_SMP
369 if (pr->id >= setup_max_cpus && pr->id != 0)
370 return 0;
371#endif
372
373 BUG_ON(pr->id >= nr_cpu_ids);
374
375 /*
376 * Buggy BIOS check.
377 * ACPI id of processors can be reported wrongly by the BIOS.
378 * Don't trust it blindly
379 */
380 if (per_cpu(processor_device_array, pr->id) != NULL &&
381 per_cpu(processor_device_array, pr->id) != device) {
382 dev_warn(&device->dev,
383 "BIOS reported wrong ACPI id %d for the processor\n",
384 pr->id);
385 /* Give up, but do not abort the namespace scan. */
386 goto err;
387 }
388 /*
389 * processor_device_array is not cleared on errors to allow buggy BIOS
390 * checks.
391 */
392 per_cpu(processor_device_array, pr->id) = device;
393 per_cpu(processors, pr->id) = pr;
394
395 dev = get_cpu_device(pr->id);
396 if (!dev) {
397 result = -ENODEV;
398 goto err;
399 }
400
401 result = acpi_bind_one(dev, pr->handle);
402 if (result)
403 goto err;
404
405 pr->dev = dev;
406 dev->offline = pr->flags.need_hotplug_init;
407
408 /* Trigger the processor driver's .probe() if present. */
409 if (device_attach(dev) >= 0)
410 return 1;
411
412 dev_err(dev, "Processor driver could not be attached\n");
413 acpi_unbind_one(dev);
414
415 err:
416 free_cpumask_var(pr->throttling.shared_cpu_map);
417 device->driver_data = NULL;
418 per_cpu(processors, pr->id) = NULL;
419 err_free_pr:
420 kfree(pr);
421 return result;
422}
423
424#ifdef CONFIG_ACPI_HOTPLUG_CPU
425/* --------------------------------------------------------------------------
426 Removal
427 -------------------------------------------------------------------------- */
428
429static void acpi_processor_remove(struct acpi_device *device)
430{
431 struct acpi_processor *pr;
432
433 if (!device || !acpi_driver_data(device))
434 return;
435
436 pr = acpi_driver_data(device);
437 if (pr->id >= nr_cpu_ids)
438 goto out;
439
440 /*
441 * The only reason why we ever get here is CPU hot-removal. The CPU is
442 * already offline and the ACPI device removal locking prevents it from
443 * being put back online at this point.
444 *
445 * Unbind the driver from the processor device and detach it from the
446 * ACPI companion object.
447 */
448 device_release_driver(pr->dev);
449 acpi_unbind_one(pr->dev);
450
451 /* Clean up. */
452 per_cpu(processor_device_array, pr->id) = NULL;
453 per_cpu(processors, pr->id) = NULL;
454 try_offline_node(cpu_to_node(pr->id));
455
456 /* Remove the CPU. */
457 get_online_cpus();
458 arch_unregister_cpu(pr->id);
459 acpi_unmap_lsapic(pr->id);
460 put_online_cpus();
461
462 out:
463 free_cpumask_var(pr->throttling.shared_cpu_map);
464 kfree(pr);
465}
466#endif /* CONFIG_ACPI_HOTPLUG_CPU */
467
468/*
469 * The following ACPI IDs are known to be suitable for representing as
470 * processor devices.
471 */
472static const struct acpi_device_id processor_device_ids[] = {
473
474 { ACPI_PROCESSOR_OBJECT_HID, },
475 { ACPI_PROCESSOR_DEVICE_HID, },
476
477 { }
478};
479
480static struct acpi_scan_handler __refdata processor_handler = {
481 .ids = processor_device_ids,
482 .attach = acpi_processor_add,
483#ifdef CONFIG_ACPI_HOTPLUG_CPU
484 .detach = acpi_processor_remove,
485#endif
486 .hotplug = {
487 .enabled = true,
488 },
489};
490
491void __init acpi_processor_init(void)
492{
493 acpi_scan_add_handler_with_hotplug(&processor_handler, "processor");
494}
diff --git a/drivers/acpi/acpica/Makefile b/drivers/acpi/acpica/Makefile
index 7ddf29eca9f5..438304086ff1 100644
--- a/drivers/acpi/acpica/Makefile
+++ b/drivers/acpi/acpica/Makefile
@@ -83,6 +83,7 @@ acpi-$(ACPI_FUTURE_USAGE) += hwtimer.o
83acpi-y += \ 83acpi-y += \
84 nsaccess.o \ 84 nsaccess.o \
85 nsalloc.o \ 85 nsalloc.o \
86 nsarguments.o \
86 nsconvert.o \ 87 nsconvert.o \
87 nsdump.o \ 88 nsdump.o \
88 nseval.o \ 89 nseval.o \
@@ -137,6 +138,7 @@ acpi-y += \
137 tbfadt.o \ 138 tbfadt.o \
138 tbfind.o \ 139 tbfind.o \
139 tbinstal.o \ 140 tbinstal.o \
141 tbprint.o \
140 tbutils.o \ 142 tbutils.o \
141 tbxface.o \ 143 tbxface.o \
142 tbxfload.o \ 144 tbxfload.o \
@@ -145,11 +147,13 @@ acpi-y += \
145acpi-y += \ 147acpi-y += \
146 utaddress.o \ 148 utaddress.o \
147 utalloc.o \ 149 utalloc.o \
150 utbuffer.o \
148 utcopy.o \ 151 utcopy.o \
149 utexcep.o \ 152 utexcep.o \
150 utdebug.o \ 153 utdebug.o \
151 utdecode.o \ 154 utdecode.o \
152 utdelete.o \ 155 utdelete.o \
156 uterror.o \
153 uteval.o \ 157 uteval.o \
154 utglobal.o \ 158 utglobal.o \
155 utids.o \ 159 utids.o \
diff --git a/drivers/acpi/acpica/acglobal.h b/drivers/acpi/acpica/acglobal.h
index 07160928ca25..b8d38117a20c 100644
--- a/drivers/acpi/acpica/acglobal.h
+++ b/drivers/acpi/acpica/acglobal.h
@@ -132,6 +132,12 @@ u8 ACPI_INIT_GLOBAL(acpi_gbl_truncate_io_addresses, FALSE);
132 */ 132 */
133u8 ACPI_INIT_GLOBAL(acpi_gbl_disable_auto_repair, FALSE); 133u8 ACPI_INIT_GLOBAL(acpi_gbl_disable_auto_repair, FALSE);
134 134
135/*
136 * Optionally do not load any SSDTs from the RSDT/XSDT during initialization.
137 * This can be useful for debugging ACPI problems on some machines.
138 */
139u8 ACPI_INIT_GLOBAL(acpi_gbl_disable_ssdt_table_load, FALSE);
140
135/* acpi_gbl_FADT is a local copy of the FADT, converted to a common format. */ 141/* acpi_gbl_FADT is a local copy of the FADT, converted to a common format. */
136 142
137struct acpi_table_fadt acpi_gbl_FADT; 143struct acpi_table_fadt acpi_gbl_FADT;
diff --git a/drivers/acpi/acpica/aclocal.h b/drivers/acpi/acpica/aclocal.h
index d5bfbd331bfd..dfed26545ba2 100644
--- a/drivers/acpi/acpica/aclocal.h
+++ b/drivers/acpi/acpica/aclocal.h
@@ -362,23 +362,6 @@ union acpi_predefined_info {
362 362
363#pragma pack() 363#pragma pack()
364 364
365/* Data block used during object validation */
366
367struct acpi_predefined_data {
368 char *pathname;
369 const union acpi_predefined_info *predefined;
370 union acpi_operand_object *parent_package;
371 struct acpi_namespace_node *node;
372 u32 flags;
373 u32 return_btype;
374 u8 node_flags;
375};
376
377/* Defines for Flags field above */
378
379#define ACPI_OBJECT_REPAIRED 1
380#define ACPI_OBJECT_WRAPPED 2
381
382/* Return object auto-repair info */ 365/* Return object auto-repair info */
383 366
384typedef acpi_status(*acpi_object_converter) (union acpi_operand_object 367typedef acpi_status(*acpi_object_converter) (union acpi_operand_object
diff --git a/drivers/acpi/acpica/acmacros.h b/drivers/acpi/acpica/acmacros.h
index 53666bd9193d..530a2f8c1252 100644
--- a/drivers/acpi/acpica/acmacros.h
+++ b/drivers/acpi/acpica/acmacros.h
@@ -374,10 +374,11 @@
374 * the plist contains a set of parens to allow variable-length lists. 374 * the plist contains a set of parens to allow variable-length lists.
375 * These macros are used for both the debug and non-debug versions of the code. 375 * These macros are used for both the debug and non-debug versions of the code.
376 */ 376 */
377#define ACPI_ERROR_NAMESPACE(s, e) acpi_ut_namespace_error (AE_INFO, s, e); 377#define ACPI_ERROR_NAMESPACE(s, e) acpi_ut_namespace_error (AE_INFO, s, e);
378#define ACPI_ERROR_METHOD(s, n, p, e) acpi_ut_method_error (AE_INFO, s, n, p, e); 378#define ACPI_ERROR_METHOD(s, n, p, e) acpi_ut_method_error (AE_INFO, s, n, p, e);
379#define ACPI_WARN_PREDEFINED(plist) acpi_ut_predefined_warning plist 379#define ACPI_WARN_PREDEFINED(plist) acpi_ut_predefined_warning plist
380#define ACPI_INFO_PREDEFINED(plist) acpi_ut_predefined_info plist 380#define ACPI_INFO_PREDEFINED(plist) acpi_ut_predefined_info plist
381#define ACPI_BIOS_ERROR_PREDEFINED(plist) acpi_ut_predefined_bios_error plist
381 382
382#else 383#else
383 384
@@ -387,6 +388,7 @@
387#define ACPI_ERROR_METHOD(s, n, p, e) 388#define ACPI_ERROR_METHOD(s, n, p, e)
388#define ACPI_WARN_PREDEFINED(plist) 389#define ACPI_WARN_PREDEFINED(plist)
389#define ACPI_INFO_PREDEFINED(plist) 390#define ACPI_INFO_PREDEFINED(plist)
391#define ACPI_BIOS_ERROR_PREDEFINED(plist)
390 392
391#endif /* ACPI_NO_ERROR_MESSAGES */ 393#endif /* ACPI_NO_ERROR_MESSAGES */
392 394
diff --git a/drivers/acpi/acpica/acnamesp.h b/drivers/acpi/acpica/acnamesp.h
index d2e491876bc0..b83dc32a5ae0 100644
--- a/drivers/acpi/acpica/acnamesp.h
+++ b/drivers/acpi/acpica/acnamesp.h
@@ -223,22 +223,33 @@ acpi_status acpi_ns_evaluate(struct acpi_evaluate_info *info);
223void acpi_ns_exec_module_code_list(void); 223void acpi_ns_exec_module_code_list(void);
224 224
225/* 225/*
226 * nspredef - Support for predefined/reserved names 226 * nsarguments - Argument count/type checking for predefined/reserved names
227 */ 227 */
228acpi_status 228void
229acpi_ns_check_predefined_names(struct acpi_namespace_node *node, 229acpi_ns_check_argument_count(char *pathname,
230 u32 user_param_count, 230 struct acpi_namespace_node *node,
231 acpi_status return_status, 231 u32 user_param_count,
232 union acpi_operand_object **return_object); 232 const union acpi_predefined_info *info);
233 233
234void 234void
235acpi_ns_check_parameter_count(char *pathname, 235acpi_ns_check_acpi_compliance(char *pathname,
236 struct acpi_namespace_node *node, 236 struct acpi_namespace_node *node,
237 u32 user_param_count, 237 const union acpi_predefined_info *predefined);
238 const union acpi_predefined_info *info); 238
239void acpi_ns_check_argument_types(struct acpi_evaluate_info *info);
240
241/*
242 * nspredef - Return value checking for predefined/reserved names
243 */
244acpi_status
245acpi_ns_check_return_value(struct acpi_namespace_node *node,
246 struct acpi_evaluate_info *info,
247 u32 user_param_count,
248 acpi_status return_status,
249 union acpi_operand_object **return_object);
239 250
240acpi_status 251acpi_status
241acpi_ns_check_object_type(struct acpi_predefined_data *data, 252acpi_ns_check_object_type(struct acpi_evaluate_info *info,
242 union acpi_operand_object **return_object_ptr, 253 union acpi_operand_object **return_object_ptr,
243 u32 expected_btypes, u32 package_index); 254 u32 expected_btypes, u32 package_index);
244 255
@@ -246,7 +257,7 @@ acpi_ns_check_object_type(struct acpi_predefined_data *data,
246 * nsprepkg - Validation of predefined name packages 257 * nsprepkg - Validation of predefined name packages
247 */ 258 */
248acpi_status 259acpi_status
249acpi_ns_check_package(struct acpi_predefined_data *data, 260acpi_ns_check_package(struct acpi_evaluate_info *info,
250 union acpi_operand_object **return_object_ptr); 261 union acpi_operand_object **return_object_ptr);
251 262
252/* 263/*
@@ -308,24 +319,24 @@ acpi_ns_get_attached_data(struct acpi_namespace_node *node,
308 * predefined methods/objects 319 * predefined methods/objects
309 */ 320 */
310acpi_status 321acpi_status
311acpi_ns_simple_repair(struct acpi_predefined_data *data, 322acpi_ns_simple_repair(struct acpi_evaluate_info *info,
312 u32 expected_btypes, 323 u32 expected_btypes,
313 u32 package_index, 324 u32 package_index,
314 union acpi_operand_object **return_object_ptr); 325 union acpi_operand_object **return_object_ptr);
315 326
316acpi_status 327acpi_status
317acpi_ns_wrap_with_package(struct acpi_predefined_data *data, 328acpi_ns_wrap_with_package(struct acpi_evaluate_info *info,
318 union acpi_operand_object *original_object, 329 union acpi_operand_object *original_object,
319 union acpi_operand_object **obj_desc_ptr); 330 union acpi_operand_object **obj_desc_ptr);
320 331
321acpi_status 332acpi_status
322acpi_ns_repair_null_element(struct acpi_predefined_data *data, 333acpi_ns_repair_null_element(struct acpi_evaluate_info *info,
323 u32 expected_btypes, 334 u32 expected_btypes,
324 u32 package_index, 335 u32 package_index,
325 union acpi_operand_object **return_object_ptr); 336 union acpi_operand_object **return_object_ptr);
326 337
327void 338void
328acpi_ns_remove_null_elements(struct acpi_predefined_data *data, 339acpi_ns_remove_null_elements(struct acpi_evaluate_info *info,
329 u8 package_type, 340 u8 package_type,
330 union acpi_operand_object *obj_desc); 341 union acpi_operand_object *obj_desc);
331 342
@@ -334,7 +345,7 @@ acpi_ns_remove_null_elements(struct acpi_predefined_data *data,
334 * predefined methods/objects 345 * predefined methods/objects
335 */ 346 */
336acpi_status 347acpi_status
337acpi_ns_complex_repairs(struct acpi_predefined_data *data, 348acpi_ns_complex_repairs(struct acpi_evaluate_info *info,
338 struct acpi_namespace_node *node, 349 struct acpi_namespace_node *node,
339 acpi_status validate_status, 350 acpi_status validate_status,
340 union acpi_operand_object **return_object_ptr); 351 union acpi_operand_object **return_object_ptr);
diff --git a/drivers/acpi/acpica/acpredef.h b/drivers/acpi/acpica/acpredef.h
index b22b70944fd6..f600aded7261 100644
--- a/drivers/acpi/acpica/acpredef.h
+++ b/drivers/acpi/acpica/acpredef.h
@@ -128,8 +128,8 @@ enum acpi_return_package_types {
128#define ARG_COUNT_IS_MINIMUM 0x8000 128#define ARG_COUNT_IS_MINIMUM 0x8000
129#define METHOD_MAX_ARG_TYPE ACPI_TYPE_PACKAGE 129#define METHOD_MAX_ARG_TYPE ACPI_TYPE_PACKAGE
130 130
131#define METHOD_GET_COUNT(arg_list) (arg_list & METHOD_ARG_MASK) 131#define METHOD_GET_ARG_COUNT(arg_list) ((arg_list) & METHOD_ARG_MASK)
132#define METHOD_GET_NEXT_ARG(arg_list) (arg_list >> METHOD_ARG_BIT_WIDTH) 132#define METHOD_GET_NEXT_TYPE(arg_list) (((arg_list) >>= METHOD_ARG_BIT_WIDTH) & METHOD_ARG_MASK)
133 133
134/* Macros used to build the predefined info table */ 134/* Macros used to build the predefined info table */
135 135
diff --git a/drivers/acpi/acpica/acstruct.h b/drivers/acpi/acpica/acstruct.h
index 7896d85876ca..fc83c0a5ca70 100644
--- a/drivers/acpi/acpica/acstruct.h
+++ b/drivers/acpi/acpica/acstruct.h
@@ -178,25 +178,41 @@ union acpi_aml_operands {
178}; 178};
179 179
180/* 180/*
181 * Structure used to pass object evaluation parameters. 181 * Structure used to pass object evaluation information and parameters.
182 * Purpose is to reduce CPU stack use. 182 * Purpose is to reduce CPU stack use.
183 */ 183 */
184struct acpi_evaluate_info { 184struct acpi_evaluate_info {
185 struct acpi_namespace_node *prefix_node; 185 /* The first 3 elements are passed by the caller to acpi_ns_evaluate */
186 char *pathname; 186
187 union acpi_operand_object *obj_desc; 187 struct acpi_namespace_node *prefix_node; /* Input: starting node */
188 union acpi_operand_object **parameters; 188 char *relative_pathname; /* Input: path relative to prefix_node */
189 struct acpi_namespace_node *resolved_node; 189 union acpi_operand_object **parameters; /* Input: argument list */
190 union acpi_operand_object *return_object; 190
191 u8 param_count; 191 struct acpi_namespace_node *node; /* Resolved node (prefix_node:relative_pathname) */
192 u8 pass_number; 192 union acpi_operand_object *obj_desc; /* Object attached to the resolved node */
193 u8 return_object_type; 193 char *full_pathname; /* Full pathname of the resolved node */
194 u8 flags; 194
195 const union acpi_predefined_info *predefined; /* Used if Node is a predefined name */
196 union acpi_operand_object *return_object; /* Object returned from the evaluation */
197 union acpi_operand_object *parent_package; /* Used if return object is a Package */
198
199 u32 return_flags; /* Used for return value analysis */
200 u32 return_btype; /* Bitmapped type of the returned object */
201 u16 param_count; /* Count of the input argument list */
202 u8 pass_number; /* Parser pass number */
203 u8 return_object_type; /* Object type of the returned object */
204 u8 node_flags; /* Same as Node->Flags */
205 u8 flags; /* General flags */
195}; 206};
196 207
197/* Values for Flags above */ 208/* Values for Flags above */
198 209
199#define ACPI_IGNORE_RETURN_VALUE 1 210#define ACPI_IGNORE_RETURN_VALUE 1
211
212/* Defines for return_flags field above */
213
214#define ACPI_OBJECT_REPAIRED 1
215#define ACPI_OBJECT_WRAPPED 2
200 216
201/* Info used by acpi_ns_initialize_devices */ 217/* Info used by acpi_ns_initialize_devices */
202 218
diff --git a/drivers/acpi/acpica/acutils.h b/drivers/acpi/acpica/acutils.h
index 202f4f12d3e2..3c76edea6803 100644
--- a/drivers/acpi/acpica/acutils.h
+++ b/drivers/acpi/acpica/acutils.h
@@ -87,6 +87,48 @@ extern const char *acpi_gbl_fc_decode[];
87extern const char *acpi_gbl_pt_decode[]; 87extern const char *acpi_gbl_pt_decode[];
88#endif 88#endif
89 89
90/*
91 * For the iASL compiler case, the output is redirected to stderr so that
92 * any of the various ACPI errors and warnings do not appear in the output
93 * files, for either the compiler or disassembler portions of the tool.
94 */
95#ifdef ACPI_ASL_COMPILER
96
97#include <stdio.h>
98extern FILE *acpi_gbl_output_file;
99
100#define ACPI_MSG_REDIRECT_BEGIN \
101 FILE *output_file = acpi_gbl_output_file; \
102 acpi_os_redirect_output (stderr);
103
104#define ACPI_MSG_REDIRECT_END \
105 acpi_os_redirect_output (output_file);
106
107#else
108/*
109 * non-iASL case - no redirection, nothing to do
110 */
111#define ACPI_MSG_REDIRECT_BEGIN
112#define ACPI_MSG_REDIRECT_END
113#endif
114
115/*
116 * Common error message prefixes
117 */
118#define ACPI_MSG_ERROR "ACPI Error: "
119#define ACPI_MSG_EXCEPTION "ACPI Exception: "
120#define ACPI_MSG_WARNING "ACPI Warning: "
121#define ACPI_MSG_INFO "ACPI: "
122
123#define ACPI_MSG_BIOS_ERROR "ACPI BIOS Error (bug): "
124#define ACPI_MSG_BIOS_WARNING "ACPI BIOS Warning (bug): "
125
126/*
127 * Common message suffix
128 */
129#define ACPI_MSG_SUFFIX \
130 acpi_os_printf (" (%8.8X/%s-%u)\n", ACPI_CA_VERSION, module_name, line_number)
131
90/* Types for Resource descriptor entries */ 132/* Types for Resource descriptor entries */
91 133
92#define ACPI_INVALID_RESOURCE 0 134#define ACPI_INVALID_RESOURCE 0
@@ -578,7 +620,7 @@ void acpi_ut_print_string(char *string, u8 max_length);
578 620
579void ut_convert_backslashes(char *pathname); 621void ut_convert_backslashes(char *pathname);
580 622
581u8 acpi_ut_valid_acpi_name(u32 name); 623u8 acpi_ut_valid_acpi_name(char *name);
582 624
583u8 acpi_ut_valid_acpi_char(char character, u32 position); 625u8 acpi_ut_valid_acpi_char(char character, u32 position);
584 626
@@ -670,6 +712,12 @@ acpi_ut_predefined_info(const char *module_name,
670 u32 line_number, 712 u32 line_number,
671 char *pathname, u8 node_flags, const char *format, ...); 713 char *pathname, u8 node_flags, const char *format, ...);
672 714
715void ACPI_INTERNAL_VAR_XFACE
716acpi_ut_predefined_bios_error(const char *module_name,
717 u32 line_number,
718 char *pathname,
719 u8 node_flags, const char *format, ...);
720
673void 721void
674acpi_ut_namespace_error(const char *module_name, 722acpi_ut_namespace_error(const char *module_name,
675 u32 line_number, 723 u32 line_number,
diff --git a/drivers/acpi/acpica/dscontrol.c b/drivers/acpi/acpica/dscontrol.c
index 7ea0f162f11c..eb56b66444b5 100644
--- a/drivers/acpi/acpica/dscontrol.c
+++ b/drivers/acpi/acpica/dscontrol.c
@@ -78,7 +78,6 @@ acpi_ds_exec_begin_control_op(struct acpi_walk_state *walk_state,
78 78
79 switch (op->common.aml_opcode) { 79 switch (op->common.aml_opcode) {
80 case AML_WHILE_OP: 80 case AML_WHILE_OP:
81
82 /* 81 /*
83 * If this is an additional iteration of a while loop, continue. 82 * If this is an additional iteration of a while loop, continue.
84 * There is no need to allocate a new control state. 83 * There is no need to allocate a new control state.
@@ -99,7 +98,6 @@ acpi_ds_exec_begin_control_op(struct acpi_walk_state *walk_state,
99 /*lint -fallthrough */ 98 /*lint -fallthrough */
100 99
101 case AML_IF_OP: 100 case AML_IF_OP:
102
103 /* 101 /*
104 * IF/WHILE: Create a new control state to manage these 102 * IF/WHILE: Create a new control state to manage these
105 * constructs. We need to manage these as a stack, in order 103 * constructs. We need to manage these as a stack, in order
@@ -142,6 +140,7 @@ acpi_ds_exec_begin_control_op(struct acpi_walk_state *walk_state,
142 break; 140 break;
143 141
144 default: 142 default:
143
145 break; 144 break;
146 } 145 }
147 146
@@ -344,6 +343,7 @@ acpi_ds_exec_end_control_op(struct acpi_walk_state * walk_state,
344 case AML_NOOP_OP: 343 case AML_NOOP_OP:
345 344
346 /* Just do nothing! */ 345 /* Just do nothing! */
346
347 break; 347 break;
348 348
349 case AML_BREAK_POINT_OP: 349 case AML_BREAK_POINT_OP:
diff --git a/drivers/acpi/acpica/dsfield.c b/drivers/acpi/acpica/dsfield.c
index feadeed1012d..d4bfe7b7f90a 100644
--- a/drivers/acpi/acpica/dsfield.c
+++ b/drivers/acpi/acpica/dsfield.c
@@ -563,21 +563,25 @@ acpi_ds_init_field_objects(union acpi_parse_object *op,
563 */ 563 */
564 switch (walk_state->opcode) { 564 switch (walk_state->opcode) {
565 case AML_FIELD_OP: 565 case AML_FIELD_OP:
566
566 arg = acpi_ps_get_arg(op, 2); 567 arg = acpi_ps_get_arg(op, 2);
567 type = ACPI_TYPE_LOCAL_REGION_FIELD; 568 type = ACPI_TYPE_LOCAL_REGION_FIELD;
568 break; 569 break;
569 570
570 case AML_BANK_FIELD_OP: 571 case AML_BANK_FIELD_OP:
572
571 arg = acpi_ps_get_arg(op, 4); 573 arg = acpi_ps_get_arg(op, 4);
572 type = ACPI_TYPE_LOCAL_BANK_FIELD; 574 type = ACPI_TYPE_LOCAL_BANK_FIELD;
573 break; 575 break;
574 576
575 case AML_INDEX_FIELD_OP: 577 case AML_INDEX_FIELD_OP:
578
576 arg = acpi_ps_get_arg(op, 3); 579 arg = acpi_ps_get_arg(op, 3);
577 type = ACPI_TYPE_LOCAL_INDEX_FIELD; 580 type = ACPI_TYPE_LOCAL_INDEX_FIELD;
578 break; 581 break;
579 582
580 default: 583 default:
584
581 return_ACPI_STATUS(AE_BAD_PARAMETER); 585 return_ACPI_STATUS(AE_BAD_PARAMETER);
582 } 586 }
583 587
diff --git a/drivers/acpi/acpica/dsinit.c b/drivers/acpi/acpica/dsinit.c
index bc8e63f7784b..14424200d246 100644
--- a/drivers/acpi/acpica/dsinit.c
+++ b/drivers/acpi/acpica/dsinit.c
@@ -127,6 +127,7 @@ acpi_ds_init_one_object(acpi_handle obj_handle,
127 break; 127 break;
128 128
129 default: 129 default:
130
130 break; 131 break;
131 } 132 }
132 133
diff --git a/drivers/acpi/acpica/dsmthdat.c b/drivers/acpi/acpica/dsmthdat.c
index 3da80460ce38..c4b0b3657237 100644
--- a/drivers/acpi/acpica/dsmthdat.c
+++ b/drivers/acpi/acpica/dsmthdat.c
@@ -285,6 +285,7 @@ acpi_ds_method_data_get_node(u8 type,
285 break; 285 break;
286 286
287 default: 287 default:
288
288 ACPI_ERROR((AE_INFO, "Type %u is invalid", type)); 289 ACPI_ERROR((AE_INFO, "Type %u is invalid", type));
289 return_ACPI_STATUS(AE_TYPE); 290 return_ACPI_STATUS(AE_TYPE);
290 } 291 }
@@ -428,7 +429,6 @@ acpi_ds_method_data_get_value(u8 type,
428 return_ACPI_STATUS(AE_AML_UNINITIALIZED_ARG); 429 return_ACPI_STATUS(AE_AML_UNINITIALIZED_ARG);
429 430
430 case ACPI_REFCLASS_LOCAL: 431 case ACPI_REFCLASS_LOCAL:
431
432 /* 432 /*
433 * No error message for this case, will be trapped again later to 433 * No error message for this case, will be trapped again later to
434 * detect and ignore cases of Store(local_x,local_x) 434 * detect and ignore cases of Store(local_x,local_x)
diff --git a/drivers/acpi/acpica/dsobject.c b/drivers/acpi/acpica/dsobject.c
index e20e9f84eee8..63f0d220ca3d 100644
--- a/drivers/acpi/acpica/dsobject.c
+++ b/drivers/acpi/acpica/dsobject.c
@@ -648,7 +648,6 @@ acpi_ds_init_object_from_op(struct acpi_walk_state *walk_state,
648 648
649 switch (obj_desc->common.type) { 649 switch (obj_desc->common.type) {
650 case ACPI_TYPE_BUFFER: 650 case ACPI_TYPE_BUFFER:
651
652 /* 651 /*
653 * Defer evaluation of Buffer term_arg operand 652 * Defer evaluation of Buffer term_arg operand
654 */ 653 */
@@ -660,7 +659,6 @@ acpi_ds_init_object_from_op(struct acpi_walk_state *walk_state,
660 break; 659 break;
661 660
662 case ACPI_TYPE_PACKAGE: 661 case ACPI_TYPE_PACKAGE:
663
664 /* 662 /*
665 * Defer evaluation of Package term_arg operand 663 * Defer evaluation of Package term_arg operand
666 */ 664 */
@@ -741,6 +739,7 @@ acpi_ds_init_object_from_op(struct acpi_walk_state *walk_state,
741 break; 739 break;
742 740
743 default: 741 default:
742
744 ACPI_ERROR((AE_INFO, "Unknown Integer type 0x%X", 743 ACPI_ERROR((AE_INFO, "Unknown Integer type 0x%X",
745 op_info->type)); 744 op_info->type));
746 status = AE_AML_OPERAND_TYPE; 745 status = AE_AML_OPERAND_TYPE;
diff --git a/drivers/acpi/acpica/dsopcode.c b/drivers/acpi/acpica/dsopcode.c
index ee6367b8eaf7..1fc1ff114f26 100644
--- a/drivers/acpi/acpica/dsopcode.c
+++ b/drivers/acpi/acpica/dsopcode.c
@@ -636,6 +636,7 @@ acpi_ds_eval_data_object_operands(struct acpi_walk_state *walk_state,
636 break; 636 break;
637 637
638 default: 638 default:
639
639 return_ACPI_STATUS(AE_AML_BAD_OPCODE); 640 return_ACPI_STATUS(AE_AML_BAD_OPCODE);
640 } 641 }
641 642
diff --git a/drivers/acpi/acpica/dsutils.c b/drivers/acpi/acpica/dsutils.c
index 99778997c35a..c666fc014987 100644
--- a/drivers/acpi/acpica/dsutils.c
+++ b/drivers/acpi/acpica/dsutils.c
@@ -240,7 +240,6 @@ acpi_ds_is_result_used(union acpi_parse_object * op,
240 240
241 case AML_IF_OP: 241 case AML_IF_OP:
242 case AML_WHILE_OP: 242 case AML_WHILE_OP:
243
244 /* 243 /*
245 * If we are executing the predicate AND this is the predicate op, 244 * If we are executing the predicate AND this is the predicate op,
246 * we will use the return value 245 * we will use the return value
@@ -254,7 +253,9 @@ acpi_ds_is_result_used(union acpi_parse_object * op,
254 break; 253 break;
255 254
256 default: 255 default:
256
257 /* Ignore other control opcodes */ 257 /* Ignore other control opcodes */
258
258 break; 259 break;
259 } 260 }
260 261
@@ -263,7 +264,6 @@ acpi_ds_is_result_used(union acpi_parse_object * op,
263 goto result_not_used; 264 goto result_not_used;
264 265
265 case AML_CLASS_CREATE: 266 case AML_CLASS_CREATE:
266
267 /* 267 /*
268 * These opcodes allow term_arg(s) as operands and therefore 268 * These opcodes allow term_arg(s) as operands and therefore
269 * the operands can be method calls. The result is used. 269 * the operands can be method calls. The result is used.
@@ -292,7 +292,6 @@ acpi_ds_is_result_used(union acpi_parse_object * op,
292 goto result_not_used; 292 goto result_not_used;
293 293
294 default: 294 default:
295
296 /* 295 /*
297 * In all other cases. the parent will actually use the return 296 * In all other cases. the parent will actually use the return
298 * object, so keep it. 297 * object, so keep it.
diff --git a/drivers/acpi/acpica/dswexec.c b/drivers/acpi/acpica/dswexec.c
index e2199a947470..151d924817e1 100644
--- a/drivers/acpi/acpica/dswexec.c
+++ b/drivers/acpi/acpica/dswexec.c
@@ -327,6 +327,7 @@ acpi_ds_exec_begin_op(struct acpi_walk_state *walk_state,
327 break; 327 break;
328 328
329 default: 329 default:
330
330 break; 331 break;
331 } 332 }
332 333
@@ -488,7 +489,6 @@ acpi_status acpi_ds_exec_end_op(struct acpi_walk_state *walk_state)
488 break; 489 break;
489 490
490 case AML_TYPE_METHOD_CALL: 491 case AML_TYPE_METHOD_CALL:
491
492 /* 492 /*
493 * If the method is referenced from within a package 493 * If the method is referenced from within a package
494 * declaration, it is not a invocation of the method, just 494 * declaration, it is not a invocation of the method, just
@@ -582,7 +582,6 @@ acpi_status acpi_ds_exec_end_op(struct acpi_walk_state *walk_state)
582 582
583 switch (op->common.parent->common.aml_opcode) { 583 switch (op->common.parent->common.aml_opcode) {
584 case AML_NAME_OP: 584 case AML_NAME_OP:
585
586 /* 585 /*
587 * Put the Node on the object stack (Contains the ACPI Name 586 * Put the Node on the object stack (Contains the ACPI Name
588 * of this object) 587 * of this object)
diff --git a/drivers/acpi/acpica/dswload.c b/drivers/acpi/acpica/dswload.c
index 6e17c0e24e63..95e681a36f9c 100644
--- a/drivers/acpi/acpica/dswload.c
+++ b/drivers/acpi/acpica/dswload.c
@@ -74,6 +74,7 @@ acpi_ds_init_callbacks(struct acpi_walk_state *walk_state, u32 pass_number)
74 74
75 switch (pass_number) { 75 switch (pass_number) {
76 case 1: 76 case 1:
77
77 walk_state->parse_flags = ACPI_PARSE_LOAD_PASS1 | 78 walk_state->parse_flags = ACPI_PARSE_LOAD_PASS1 |
78 ACPI_PARSE_DELETE_TREE; 79 ACPI_PARSE_DELETE_TREE;
79 walk_state->descending_callback = acpi_ds_load1_begin_op; 80 walk_state->descending_callback = acpi_ds_load1_begin_op;
@@ -81,6 +82,7 @@ acpi_ds_init_callbacks(struct acpi_walk_state *walk_state, u32 pass_number)
81 break; 82 break;
82 83
83 case 2: 84 case 2:
85
84 walk_state->parse_flags = ACPI_PARSE_LOAD_PASS1 | 86 walk_state->parse_flags = ACPI_PARSE_LOAD_PASS1 |
85 ACPI_PARSE_DELETE_TREE; 87 ACPI_PARSE_DELETE_TREE;
86 walk_state->descending_callback = acpi_ds_load2_begin_op; 88 walk_state->descending_callback = acpi_ds_load2_begin_op;
@@ -88,6 +90,7 @@ acpi_ds_init_callbacks(struct acpi_walk_state *walk_state, u32 pass_number)
88 break; 90 break;
89 91
90 case 3: 92 case 3:
93
91#ifndef ACPI_NO_METHOD_EXECUTION 94#ifndef ACPI_NO_METHOD_EXECUTION
92 walk_state->parse_flags |= ACPI_PARSE_EXECUTE | 95 walk_state->parse_flags |= ACPI_PARSE_EXECUTE |
93 ACPI_PARSE_DELETE_TREE; 96 ACPI_PARSE_DELETE_TREE;
@@ -97,6 +100,7 @@ acpi_ds_init_callbacks(struct acpi_walk_state *walk_state, u32 pass_number)
97 break; 100 break;
98 101
99 default: 102 default:
103
100 return (AE_BAD_PARAMETER); 104 return (AE_BAD_PARAMETER);
101 } 105 }
102 106
@@ -161,7 +165,6 @@ acpi_ds_load1_begin_op(struct acpi_walk_state * walk_state,
161 165
162 switch (walk_state->opcode) { 166 switch (walk_state->opcode) {
163 case AML_SCOPE_OP: 167 case AML_SCOPE_OP:
164
165 /* 168 /*
166 * The target name of the Scope() operator must exist at this point so 169 * The target name of the Scope() operator must exist at this point so
167 * that we can actually open the scope to enter new names underneath it. 170 * that we can actually open the scope to enter new names underneath it.
@@ -210,7 +213,6 @@ acpi_ds_load1_begin_op(struct acpi_walk_state * walk_state,
210 case ACPI_TYPE_INTEGER: 213 case ACPI_TYPE_INTEGER:
211 case ACPI_TYPE_STRING: 214 case ACPI_TYPE_STRING:
212 case ACPI_TYPE_BUFFER: 215 case ACPI_TYPE_BUFFER:
213
214 /* 216 /*
215 * These types we will allow, but we will change the type. 217 * These types we will allow, but we will change the type.
216 * This enables some existing code of the form: 218 * This enables some existing code of the form:
@@ -232,7 +234,6 @@ acpi_ds_load1_begin_op(struct acpi_walk_state * walk_state,
232 break; 234 break;
233 235
234 case ACPI_TYPE_METHOD: 236 case ACPI_TYPE_METHOD:
235
236 /* 237 /*
237 * Allow scope change to root during execution of module-level 238 * Allow scope change to root during execution of module-level
238 * code. Root is typed METHOD during this time. 239 * code. Root is typed METHOD during this time.
diff --git a/drivers/acpi/acpica/dswload2.c b/drivers/acpi/acpica/dswload2.c
index 4407ff2377d5..b1f8f4725c23 100644
--- a/drivers/acpi/acpica/dswload2.c
+++ b/drivers/acpi/acpica/dswload2.c
@@ -509,6 +509,7 @@ acpi_status acpi_ds_load2_end_op(struct acpi_walk_state *walk_state)
509 break; 509 break;
510 510
511 default: 511 default:
512
512 /* All NAMED_FIELD opcodes must be handled above */ 513 /* All NAMED_FIELD opcodes must be handled above */
513 break; 514 break;
514 } 515 }
@@ -548,6 +549,7 @@ acpi_status acpi_ds_load2_end_op(struct acpi_walk_state *walk_state)
548 break; 549 break;
549 550
550 default: 551 default:
552
551 /* Unknown opcode */ 553 /* Unknown opcode */
552 554
553 status = AE_OK; 555 status = AE_OK;
@@ -674,6 +676,7 @@ acpi_status acpi_ds_load2_end_op(struct acpi_walk_state *walk_state)
674#endif /* ACPI_NO_METHOD_EXECUTION */ 676#endif /* ACPI_NO_METHOD_EXECUTION */
675 677
676 default: 678 default:
679
677 /* All NAMED_COMPLEX opcodes must be handled above */ 680 /* All NAMED_COMPLEX opcodes must be handled above */
678 break; 681 break;
679 } 682 }
@@ -721,6 +724,7 @@ acpi_status acpi_ds_load2_end_op(struct acpi_walk_state *walk_state)
721 break; 724 break;
722 725
723 default: 726 default:
727
724 break; 728 break;
725 } 729 }
726 730
diff --git a/drivers/acpi/acpica/evglock.c b/drivers/acpi/acpica/evglock.c
index a621481c6cf2..fdb0a76e40a3 100644
--- a/drivers/acpi/acpica/evglock.c
+++ b/drivers/acpi/acpica/evglock.c
@@ -128,6 +128,7 @@ acpi_status acpi_ev_remove_global_lock_handler(void)
128 status = acpi_remove_fixed_event_handler(ACPI_EVENT_GLOBAL, 128 status = acpi_remove_fixed_event_handler(ACPI_EVENT_GLOBAL,
129 acpi_ev_global_lock_handler); 129 acpi_ev_global_lock_handler);
130 130
131 acpi_os_delete_lock(acpi_gbl_global_lock_pending_lock);
131 return_ACPI_STATUS(status); 132 return_ACPI_STATUS(status);
132} 133}
133 134
diff --git a/drivers/acpi/acpica/evgpe.c b/drivers/acpi/acpica/evgpe.c
index a493b528f8f9..c8a1f7d5931f 100644
--- a/drivers/acpi/acpica/evgpe.c
+++ b/drivers/acpi/acpica/evgpe.c
@@ -529,7 +529,6 @@ static void ACPI_SYSTEM_XFACE acpi_ev_asynch_execute_gpe_method(void *context)
529 529
530 switch (local_gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) { 530 switch (local_gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) {
531 case ACPI_GPE_DISPATCH_NOTIFY: 531 case ACPI_GPE_DISPATCH_NOTIFY:
532
533 /* 532 /*
534 * Implicit notify. 533 * Implicit notify.
535 * Dispatch a DEVICE_WAKE notify to the appropriate handler. 534 * Dispatch a DEVICE_WAKE notify to the appropriate handler.
@@ -579,11 +578,11 @@ static void ACPI_SYSTEM_XFACE acpi_ev_asynch_execute_gpe_method(void *context)
579 (local_gpe_event_info->dispatch. 578 (local_gpe_event_info->dispatch.
580 method_node))); 579 method_node)));
581 } 580 }
582
583 break; 581 break;
584 582
585 default: 583 default:
586 return_VOID; /* Should never happen */ 584
585 return_VOID; /* Should never happen */
587 } 586 }
588 587
589 /* Defer enabling of GPE until all notify handlers are done */ 588 /* Defer enabling of GPE until all notify handlers are done */
@@ -755,7 +754,6 @@ acpi_ev_gpe_dispatch(struct acpi_namespace_node *gpe_device,
755 754
756 case ACPI_GPE_DISPATCH_METHOD: 755 case ACPI_GPE_DISPATCH_METHOD:
757 case ACPI_GPE_DISPATCH_NOTIFY: 756 case ACPI_GPE_DISPATCH_NOTIFY:
758
759 /* 757 /*
760 * Execute the method associated with the GPE 758 * Execute the method associated with the GPE
761 * NOTE: Level-triggered GPEs are cleared after the method completes. 759 * NOTE: Level-triggered GPEs are cleared after the method completes.
@@ -771,7 +769,6 @@ acpi_ev_gpe_dispatch(struct acpi_namespace_node *gpe_device,
771 break; 769 break;
772 770
773 default: 771 default:
774
775 /* 772 /*
776 * No handler or method to run! 773 * No handler or method to run!
777 * 03/2010: This case should no longer be possible. We will not allow 774 * 03/2010: This case should no longer be possible. We will not allow
diff --git a/drivers/acpi/acpica/evgpeblk.c b/drivers/acpi/acpica/evgpeblk.c
index a2d688bbac02..c1aa1eda26c3 100644
--- a/drivers/acpi/acpica/evgpeblk.c
+++ b/drivers/acpi/acpica/evgpeblk.c
@@ -382,6 +382,8 @@ acpi_ev_create_gpe_block(struct acpi_namespace_node *gpe_device,
382 382
383 status = acpi_ev_install_gpe_block(gpe_block, interrupt_number); 383 status = acpi_ev_install_gpe_block(gpe_block, interrupt_number);
384 if (ACPI_FAILURE(status)) { 384 if (ACPI_FAILURE(status)) {
385 ACPI_FREE(gpe_block->register_info);
386 ACPI_FREE(gpe_block->event_info);
385 ACPI_FREE(gpe_block); 387 ACPI_FREE(gpe_block);
386 return_ACPI_STATUS(status); 388 return_ACPI_STATUS(status);
387 } 389 }
diff --git a/drivers/acpi/acpica/evgpeinit.c b/drivers/acpi/acpica/evgpeinit.c
index 72b8f6b3f4ca..9037f17c9608 100644
--- a/drivers/acpi/acpica/evgpeinit.c
+++ b/drivers/acpi/acpica/evgpeinit.c
@@ -363,14 +363,17 @@ acpi_ev_match_gpe_method(acpi_handle obj_handle,
363 */ 363 */
364 switch (name[1]) { 364 switch (name[1]) {
365 case 'L': 365 case 'L':
366
366 type = ACPI_GPE_LEVEL_TRIGGERED; 367 type = ACPI_GPE_LEVEL_TRIGGERED;
367 break; 368 break;
368 369
369 case 'E': 370 case 'E':
371
370 type = ACPI_GPE_EDGE_TRIGGERED; 372 type = ACPI_GPE_EDGE_TRIGGERED;
371 break; 373 break;
372 374
373 default: 375 default:
376
374 /* Unknown method type, just ignore it */ 377 /* Unknown method type, just ignore it */
375 378
376 ACPI_DEBUG_PRINT((ACPI_DB_LOAD, 379 ACPI_DEBUG_PRINT((ACPI_DB_LOAD,
diff --git a/drivers/acpi/acpica/evhandler.c b/drivers/acpi/acpica/evhandler.c
index d4f83112c2e2..068af96134b8 100644
--- a/drivers/acpi/acpica/evhandler.c
+++ b/drivers/acpi/acpica/evhandler.c
@@ -354,36 +354,43 @@ acpi_ev_install_space_handler(struct acpi_namespace_node * node,
354 354
355 switch (space_id) { 355 switch (space_id) {
356 case ACPI_ADR_SPACE_SYSTEM_MEMORY: 356 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
357
357 handler = acpi_ex_system_memory_space_handler; 358 handler = acpi_ex_system_memory_space_handler;
358 setup = acpi_ev_system_memory_region_setup; 359 setup = acpi_ev_system_memory_region_setup;
359 break; 360 break;
360 361
361 case ACPI_ADR_SPACE_SYSTEM_IO: 362 case ACPI_ADR_SPACE_SYSTEM_IO:
363
362 handler = acpi_ex_system_io_space_handler; 364 handler = acpi_ex_system_io_space_handler;
363 setup = acpi_ev_io_space_region_setup; 365 setup = acpi_ev_io_space_region_setup;
364 break; 366 break;
365 367
366 case ACPI_ADR_SPACE_PCI_CONFIG: 368 case ACPI_ADR_SPACE_PCI_CONFIG:
369
367 handler = acpi_ex_pci_config_space_handler; 370 handler = acpi_ex_pci_config_space_handler;
368 setup = acpi_ev_pci_config_region_setup; 371 setup = acpi_ev_pci_config_region_setup;
369 break; 372 break;
370 373
371 case ACPI_ADR_SPACE_CMOS: 374 case ACPI_ADR_SPACE_CMOS:
375
372 handler = acpi_ex_cmos_space_handler; 376 handler = acpi_ex_cmos_space_handler;
373 setup = acpi_ev_cmos_region_setup; 377 setup = acpi_ev_cmos_region_setup;
374 break; 378 break;
375 379
376 case ACPI_ADR_SPACE_PCI_BAR_TARGET: 380 case ACPI_ADR_SPACE_PCI_BAR_TARGET:
381
377 handler = acpi_ex_pci_bar_space_handler; 382 handler = acpi_ex_pci_bar_space_handler;
378 setup = acpi_ev_pci_bar_region_setup; 383 setup = acpi_ev_pci_bar_region_setup;
379 break; 384 break;
380 385
381 case ACPI_ADR_SPACE_DATA_TABLE: 386 case ACPI_ADR_SPACE_DATA_TABLE:
387
382 handler = acpi_ex_data_table_space_handler; 388 handler = acpi_ex_data_table_space_handler;
383 setup = NULL; 389 setup = NULL;
384 break; 390 break;
385 391
386 default: 392 default:
393
387 status = AE_BAD_PARAMETER; 394 status = AE_BAD_PARAMETER;
388 goto unlock_and_exit; 395 goto unlock_and_exit;
389 } 396 }
diff --git a/drivers/acpi/acpica/evmisc.c b/drivers/acpi/acpica/evmisc.c
index c986b2336b81..1b111ef74903 100644
--- a/drivers/acpi/acpica/evmisc.c
+++ b/drivers/acpi/acpica/evmisc.c
@@ -78,6 +78,7 @@ u8 acpi_ev_is_notify_object(struct acpi_namespace_node *node)
78 return (TRUE); 78 return (TRUE);
79 79
80 default: 80 default:
81
81 return (FALSE); 82 return (FALSE);
82 } 83 }
83} 84}
@@ -275,6 +276,8 @@ void acpi_ev_terminate(void)
275 ACPI_ERROR((AE_INFO, 276 ACPI_ERROR((AE_INFO,
276 "Could not remove Global Lock handler")); 277 "Could not remove Global Lock handler"));
277 } 278 }
279
280 acpi_gbl_events_initialized = FALSE;
278 } 281 }
279 282
280 /* Deallocate all handler objects installed within GPE info structs */ 283 /* Deallocate all handler objects installed within GPE info structs */
diff --git a/drivers/acpi/acpica/evregion.c b/drivers/acpi/acpica/evregion.c
index 6555e350fc1f..cea14d6fc76c 100644
--- a/drivers/acpi/acpica/evregion.c
+++ b/drivers/acpi/acpica/evregion.c
@@ -54,7 +54,8 @@ extern u8 acpi_gbl_default_address_spaces[];
54 54
55/* Local prototypes */ 55/* Local prototypes */
56 56
57static void acpi_ev_orphan_ec_reg_method(void); 57static void
58acpi_ev_orphan_ec_reg_method(struct acpi_namespace_node *ec_device_node);
58 59
59static acpi_status 60static acpi_status
60acpi_ev_reg_run(acpi_handle obj_handle, 61acpi_ev_reg_run(acpi_handle obj_handle,
@@ -532,7 +533,7 @@ acpi_ev_execute_reg_method(union acpi_operand_object *region_obj, u32 function)
532 } 533 }
533 534
534 info->prefix_node = region_obj2->extra.method_REG; 535 info->prefix_node = region_obj2->extra.method_REG;
535 info->pathname = NULL; 536 info->relative_pathname = NULL;
536 info->parameters = args; 537 info->parameters = args;
537 info->flags = ACPI_IGNORE_RETURN_VALUE; 538 info->flags = ACPI_IGNORE_RETURN_VALUE;
538 539
@@ -612,7 +613,7 @@ acpi_ev_execute_reg_methods(struct acpi_namespace_node *node,
612 /* Special case for EC: handle "orphan" _REG methods with no region */ 613 /* Special case for EC: handle "orphan" _REG methods with no region */
613 614
614 if (space_id == ACPI_ADR_SPACE_EC) { 615 if (space_id == ACPI_ADR_SPACE_EC) {
615 acpi_ev_orphan_ec_reg_method(); 616 acpi_ev_orphan_ec_reg_method(node);
616 } 617 }
617 618
618 return_ACPI_STATUS(status); 619 return_ACPI_STATUS(status);
@@ -681,7 +682,7 @@ acpi_ev_reg_run(acpi_handle obj_handle,
681 * 682 *
682 * FUNCTION: acpi_ev_orphan_ec_reg_method 683 * FUNCTION: acpi_ev_orphan_ec_reg_method
683 * 684 *
684 * PARAMETERS: None 685 * PARAMETERS: ec_device_node - Namespace node for an EC device
685 * 686 *
686 * RETURN: None 687 * RETURN: None
687 * 688 *
@@ -693,37 +694,27 @@ acpi_ev_reg_run(acpi_handle obj_handle,
693 * detected by providing a _REG method object underneath the 694 * detected by providing a _REG method object underneath the
694 * Embedded Controller device." 695 * Embedded Controller device."
695 * 696 *
696 * To quickly access the EC device, we use the EC_ID that appears 697 * To quickly access the EC device, we use the ec_device_node used
697 * within the ECDT. Otherwise, we would need to perform a time- 698 * during EC handler installation. Otherwise, we would need to
698 * consuming namespace walk, executing _HID methods to find the 699 * perform a time consuming namespace walk, executing _HID
699 * EC device. 700 * methods to find the EC device.
701 *
702 * MUTEX: Assumes the namespace is locked
700 * 703 *
701 ******************************************************************************/ 704 ******************************************************************************/
702 705
703static void acpi_ev_orphan_ec_reg_method(void) 706static void
707acpi_ev_orphan_ec_reg_method(struct acpi_namespace_node *ec_device_node)
704{ 708{
705 struct acpi_table_ecdt *table; 709 acpi_handle reg_method;
710 struct acpi_namespace_node *next_node;
706 acpi_status status; 711 acpi_status status;
707 struct acpi_object_list args; 712 struct acpi_object_list args;
708 union acpi_object objects[2]; 713 union acpi_object objects[2];
709 struct acpi_namespace_node *ec_device_node;
710 struct acpi_namespace_node *reg_method;
711 struct acpi_namespace_node *next_node;
712 714
713 ACPI_FUNCTION_TRACE(ev_orphan_ec_reg_method); 715 ACPI_FUNCTION_TRACE(ev_orphan_ec_reg_method);
714 716
715 /* Get the ECDT (if present in system) */ 717 if (!ec_device_node) {
716
717 status = acpi_get_table(ACPI_SIG_ECDT, 0,
718 ACPI_CAST_INDIRECT_PTR(struct acpi_table_header,
719 &table));
720 if (ACPI_FAILURE(status)) {
721 return_VOID;
722 }
723
724 /* We need a valid EC_ID string */
725
726 if (!(*table->id)) {
727 return_VOID; 718 return_VOID;
728 } 719 }
729 720
@@ -731,22 +722,11 @@ static void acpi_ev_orphan_ec_reg_method(void)
731 722
732 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); 723 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
733 724
734 /* Get a handle to the EC device referenced in the ECDT */
735
736 status = acpi_get_handle(NULL,
737 ACPI_CAST_PTR(char, table->id),
738 ACPI_CAST_PTR(acpi_handle, &ec_device_node));
739 if (ACPI_FAILURE(status)) {
740 goto exit;
741 }
742
743 /* Get a handle to a _REG method immediately under the EC device */ 725 /* Get a handle to a _REG method immediately under the EC device */
744 726
745 status = acpi_get_handle(ec_device_node, 727 status = acpi_get_handle(ec_device_node, METHOD_NAME__REG, &reg_method);
746 METHOD_NAME__REG, ACPI_CAST_PTR(acpi_handle,
747 &reg_method));
748 if (ACPI_FAILURE(status)) { 728 if (ACPI_FAILURE(status)) {
749 goto exit; 729 goto exit; /* There is no _REG method present */
750 } 730 }
751 731
752 /* 732 /*
@@ -754,19 +734,20 @@ static void acpi_ev_orphan_ec_reg_method(void)
754 * this scope with the Embedded Controller space ID. Otherwise, it 734 * this scope with the Embedded Controller space ID. Otherwise, it
755 * will already have been executed. Note, this allows for Regions 735 * will already have been executed. Note, this allows for Regions
756 * with other space IDs to be present; but the code below will then 736 * with other space IDs to be present; but the code below will then
757 * execute the _REG method with the EC space ID argument. 737 * execute the _REG method with the embedded_control space_ID argument.
758 */ 738 */
759 next_node = acpi_ns_get_next_node(ec_device_node, NULL); 739 next_node = acpi_ns_get_next_node(ec_device_node, NULL);
760 while (next_node) { 740 while (next_node) {
761 if ((next_node->type == ACPI_TYPE_REGION) && 741 if ((next_node->type == ACPI_TYPE_REGION) &&
762 (next_node->object) && 742 (next_node->object) &&
763 (next_node->object->region.space_id == ACPI_ADR_SPACE_EC)) { 743 (next_node->object->region.space_id == ACPI_ADR_SPACE_EC)) {
764 goto exit; /* Do not execute _REG */ 744 goto exit; /* Do not execute the _REG */
765 } 745 }
746
766 next_node = acpi_ns_get_next_node(ec_device_node, next_node); 747 next_node = acpi_ns_get_next_node(ec_device_node, next_node);
767 } 748 }
768 749
769 /* Evaluate the _REG(EC,Connect) method */ 750 /* Evaluate the _REG(embedded_control,Connect) method */
770 751
771 args.count = 2; 752 args.count = 2;
772 args.pointer = objects; 753 args.pointer = objects;
diff --git a/drivers/acpi/acpica/evrgnini.c b/drivers/acpi/acpica/evrgnini.c
index 3bb616794b3b..8354c4f7f10c 100644
--- a/drivers/acpi/acpica/evrgnini.c
+++ b/drivers/acpi/acpica/evrgnini.c
@@ -596,7 +596,9 @@ acpi_ev_initialize_region(union acpi_operand_object *region_obj,
596 break; 596 break;
597 597
598 default: 598 default:
599
599 /* Ignore other objects */ 600 /* Ignore other objects */
601
600 break; 602 break;
601 } 603 }
602 604
diff --git a/drivers/acpi/acpica/evxfgpe.c b/drivers/acpi/acpica/evxfgpe.c
index aff4cc261211..7662f1a42ff6 100644
--- a/drivers/acpi/acpica/evxfgpe.c
+++ b/drivers/acpi/acpica/evxfgpe.c
@@ -366,16 +366,19 @@ acpi_set_gpe_wake_mask(acpi_handle gpe_device, u32 gpe_number, u8 action)
366 366
367 switch (action) { 367 switch (action) {
368 case ACPI_GPE_ENABLE: 368 case ACPI_GPE_ENABLE:
369
369 ACPI_SET_BIT(gpe_register_info->enable_for_wake, 370 ACPI_SET_BIT(gpe_register_info->enable_for_wake,
370 (u8)register_bit); 371 (u8)register_bit);
371 break; 372 break;
372 373
373 case ACPI_GPE_DISABLE: 374 case ACPI_GPE_DISABLE:
375
374 ACPI_CLEAR_BIT(gpe_register_info->enable_for_wake, 376 ACPI_CLEAR_BIT(gpe_register_info->enable_for_wake,
375 (u8)register_bit); 377 (u8)register_bit);
376 break; 378 break;
377 379
378 default: 380 default:
381
379 ACPI_ERROR((AE_INFO, "%u, Invalid action", action)); 382 ACPI_ERROR((AE_INFO, "%u, Invalid action", action));
380 status = AE_BAD_PARAMETER; 383 status = AE_BAD_PARAMETER;
381 break; 384 break;
diff --git a/drivers/acpi/acpica/evxfregn.c b/drivers/acpi/acpica/evxfregn.c
index 96c9e5f355ae..80cecf838591 100644
--- a/drivers/acpi/acpica/evxfregn.c
+++ b/drivers/acpi/acpica/evxfregn.c
@@ -139,6 +139,7 @@ acpi_install_address_space_handler(acpi_handle device,
139 break; 139 break;
140 140
141 default: 141 default:
142
142 break; 143 break;
143 } 144 }
144 145
diff --git a/drivers/acpi/acpica/exconfig.c b/drivers/acpi/acpica/exconfig.c
index d93b70be60ad..06d216c8d43a 100644
--- a/drivers/acpi/acpica/exconfig.c
+++ b/drivers/acpi/acpica/exconfig.c
@@ -480,6 +480,7 @@ acpi_ex_load_op(union acpi_operand_object *obj_desc,
480 break; 480 break;
481 481
482 default: 482 default:
483
483 return_ACPI_STATUS(AE_AML_OPERAND_TYPE); 484 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
484 } 485 }
485 486
@@ -588,7 +589,7 @@ acpi_status acpi_ex_unload_table(union acpi_operand_object *ddb_handle)
588 (ACPI_GET_DESCRIPTOR_TYPE(ddb_handle) != ACPI_DESC_TYPE_OPERAND) || 589 (ACPI_GET_DESCRIPTOR_TYPE(ddb_handle) != ACPI_DESC_TYPE_OPERAND) ||
589 (ddb_handle->common.type != ACPI_TYPE_LOCAL_REFERENCE) || 590 (ddb_handle->common.type != ACPI_TYPE_LOCAL_REFERENCE) ||
590 (!(ddb_handle->common.flags & AOPOBJ_DATA_VALID))) { 591 (!(ddb_handle->common.flags & AOPOBJ_DATA_VALID))) {
591 return_ACPI_STATUS(AE_BAD_PARAMETER); 592 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
592 } 593 }
593 594
594 /* Get the table index from the ddb_handle */ 595 /* Get the table index from the ddb_handle */
diff --git a/drivers/acpi/acpica/exconvrt.c b/drivers/acpi/acpica/exconvrt.c
index d2b9613bbf01..69e4a8cc9b71 100644
--- a/drivers/acpi/acpica/exconvrt.c
+++ b/drivers/acpi/acpica/exconvrt.c
@@ -99,6 +99,7 @@ acpi_ex_convert_to_integer(union acpi_operand_object *obj_desc,
99 break; 99 break;
100 100
101 default: 101 default:
102
102 return_ACPI_STATUS(AE_TYPE); 103 return_ACPI_STATUS(AE_TYPE);
103 } 104 }
104 105
@@ -117,7 +118,6 @@ acpi_ex_convert_to_integer(union acpi_operand_object *obj_desc,
117 118
118 switch (obj_desc->common.type) { 119 switch (obj_desc->common.type) {
119 case ACPI_TYPE_STRING: 120 case ACPI_TYPE_STRING:
120
121 /* 121 /*
122 * Convert string to an integer - for most cases, the string must be 122 * Convert string to an integer - for most cases, the string must be
123 * hexadecimal as per the ACPI specification. The only exception (as 123 * hexadecimal as per the ACPI specification. The only exception (as
@@ -161,6 +161,7 @@ acpi_ex_convert_to_integer(union acpi_operand_object *obj_desc,
161 default: 161 default:
162 162
163 /* No other types can get here */ 163 /* No other types can get here */
164
164 break; 165 break;
165 } 166 }
166 167
@@ -213,7 +214,6 @@ acpi_ex_convert_to_buffer(union acpi_operand_object *obj_desc,
213 return_ACPI_STATUS(AE_OK); 214 return_ACPI_STATUS(AE_OK);
214 215
215 case ACPI_TYPE_INTEGER: 216 case ACPI_TYPE_INTEGER:
216
217 /* 217 /*
218 * Create a new Buffer object. 218 * Create a new Buffer object.
219 * Need enough space for one integer 219 * Need enough space for one integer
@@ -233,7 +233,6 @@ acpi_ex_convert_to_buffer(union acpi_operand_object *obj_desc,
233 break; 233 break;
234 234
235 case ACPI_TYPE_STRING: 235 case ACPI_TYPE_STRING:
236
237 /* 236 /*
238 * Create a new Buffer object 237 * Create a new Buffer object
239 * Size will be the string length 238 * Size will be the string length
@@ -258,6 +257,7 @@ acpi_ex_convert_to_buffer(union acpi_operand_object *obj_desc,
258 break; 257 break;
259 258
260 default: 259 default:
260
261 return_ACPI_STATUS(AE_TYPE); 261 return_ACPI_STATUS(AE_TYPE);
262 } 262 }
263 263
@@ -304,15 +304,18 @@ acpi_ex_convert_to_ascii(u64 integer, u16 base, u8 *string, u8 data_width)
304 304
305 switch (data_width) { 305 switch (data_width) {
306 case 1: 306 case 1:
307
307 decimal_length = ACPI_MAX8_DECIMAL_DIGITS; 308 decimal_length = ACPI_MAX8_DECIMAL_DIGITS;
308 break; 309 break;
309 310
310 case 4: 311 case 4:
312
311 decimal_length = ACPI_MAX32_DECIMAL_DIGITS; 313 decimal_length = ACPI_MAX32_DECIMAL_DIGITS;
312 break; 314 break;
313 315
314 case 8: 316 case 8:
315 default: 317 default:
318
316 decimal_length = ACPI_MAX64_DECIMAL_DIGITS; 319 decimal_length = ACPI_MAX64_DECIMAL_DIGITS;
317 break; 320 break;
318 } 321 }
@@ -546,6 +549,7 @@ acpi_ex_convert_to_string(union acpi_operand_object * obj_desc,
546 break; 549 break;
547 550
548 default: 551 default:
552
549 return_ACPI_STATUS(AE_TYPE); 553 return_ACPI_STATUS(AE_TYPE);
550 } 554 }
551 555
@@ -599,6 +603,7 @@ acpi_ex_convert_to_target_type(acpi_object_type destination_type,
599 break; 603 break;
600 604
601 default: 605 default:
606
602 /* No conversion allowed for these types */ 607 /* No conversion allowed for these types */
603 608
604 if (destination_type != source_desc->common.type) { 609 if (destination_type != source_desc->common.type) {
@@ -649,6 +654,7 @@ acpi_ex_convert_to_target_type(acpi_object_type destination_type,
649 break; 654 break;
650 655
651 default: 656 default:
657
652 ACPI_ERROR((AE_INFO, 658 ACPI_ERROR((AE_INFO,
653 "Bad destination type during conversion: 0x%X", 659 "Bad destination type during conversion: 0x%X",
654 destination_type)); 660 destination_type));
@@ -664,6 +670,7 @@ acpi_ex_convert_to_target_type(acpi_object_type destination_type,
664 break; 670 break;
665 671
666 default: 672 default:
673
667 ACPI_ERROR((AE_INFO, 674 ACPI_ERROR((AE_INFO,
668 "Unknown Target type ID 0x%X AmlOpcode 0x%X DestType %s", 675 "Unknown Target type ID 0x%X AmlOpcode 0x%X DestType %s",
669 GET_CURRENT_ARG_TYPE(walk_state->op_info-> 676 GET_CURRENT_ARG_TYPE(walk_state->op_info->
diff --git a/drivers/acpi/acpica/excreate.c b/drivers/acpi/acpica/excreate.c
index 26a13f67977e..269e81d86ef4 100644
--- a/drivers/acpi/acpica/excreate.c
+++ b/drivers/acpi/acpica/excreate.c
@@ -103,7 +103,6 @@ acpi_status acpi_ex_create_alias(struct acpi_walk_state *walk_state)
103 case ACPI_TYPE_BUFFER: 103 case ACPI_TYPE_BUFFER:
104 case ACPI_TYPE_PACKAGE: 104 case ACPI_TYPE_PACKAGE:
105 case ACPI_TYPE_BUFFER_FIELD: 105 case ACPI_TYPE_BUFFER_FIELD:
106
107 /* 106 /*
108 * These types open a new scope, so we need the NS node in order to access 107 * These types open a new scope, so we need the NS node in order to access
109 * any children. 108 * any children.
@@ -113,7 +112,6 @@ acpi_status acpi_ex_create_alias(struct acpi_walk_state *walk_state)
113 case ACPI_TYPE_PROCESSOR: 112 case ACPI_TYPE_PROCESSOR:
114 case ACPI_TYPE_THERMAL: 113 case ACPI_TYPE_THERMAL:
115 case ACPI_TYPE_LOCAL_SCOPE: 114 case ACPI_TYPE_LOCAL_SCOPE:
116
117 /* 115 /*
118 * The new alias has the type ALIAS and points to the original 116 * The new alias has the type ALIAS and points to the original
119 * NS node, not the object itself. 117 * NS node, not the object itself.
@@ -124,7 +122,6 @@ acpi_status acpi_ex_create_alias(struct acpi_walk_state *walk_state)
124 break; 122 break;
125 123
126 case ACPI_TYPE_METHOD: 124 case ACPI_TYPE_METHOD:
127
128 /* 125 /*
129 * Control method aliases need to be differentiated 126 * Control method aliases need to be differentiated
130 */ 127 */
diff --git a/drivers/acpi/acpica/exdebug.c b/drivers/acpi/acpica/exdebug.c
index 7eb853cd279f..81c72a4ecd82 100644
--- a/drivers/acpi/acpica/exdebug.c
+++ b/drivers/acpi/acpica/exdebug.c
@@ -193,6 +193,7 @@ acpi_ex_do_debug_object(union acpi_operand_object *source_desc,
193 return_VOID; 193 return_VOID;
194 194
195 default: 195 default:
196
196 break; 197 break;
197 } 198 }
198 199
@@ -226,6 +227,7 @@ acpi_ex_do_debug_object(union acpi_operand_object *source_desc,
226 break; 227 break;
227 228
228 default: 229 default:
230
229 acpi_ex_do_debug_object((source_desc-> 231 acpi_ex_do_debug_object((source_desc->
230 reference. 232 reference.
231 node)->object, 233 node)->object,
diff --git a/drivers/acpi/acpica/exdump.c b/drivers/acpi/acpica/exdump.c
index e5a3c249f7fa..c740f24e3101 100644
--- a/drivers/acpi/acpica/exdump.c
+++ b/drivers/acpi/acpica/exdump.c
@@ -357,6 +357,7 @@ acpi_ex_dump_object(union acpi_operand_object *obj_desc,
357 357
358 switch (info->opcode) { 358 switch (info->opcode) {
359 case ACPI_EXD_INIT: 359 case ACPI_EXD_INIT:
360
360 break; 361 break;
361 362
362 case ACPI_EXD_TYPE: 363 case ACPI_EXD_TYPE:
@@ -718,6 +719,7 @@ void acpi_ex_dump_operand(union acpi_operand_object *obj_desc, u32 depth)
718 break; 719 break;
719 720
720 default: 721 default:
722
721 /* Unknown Type */ 723 /* Unknown Type */
722 724
723 acpi_os_printf("Unknown Type %X\n", obj_desc->common.type); 725 acpi_os_printf("Unknown Type %X\n", obj_desc->common.type);
diff --git a/drivers/acpi/acpica/exfield.c b/drivers/acpi/acpica/exfield.c
index 7d4bae71e8c6..c2a65aaf29af 100644
--- a/drivers/acpi/acpica/exfield.c
+++ b/drivers/acpi/acpica/exfield.c
@@ -331,21 +331,25 @@ acpi_ex_write_data_to_field(union acpi_operand_object *source_desc,
331 331
332 switch (source_desc->common.type) { 332 switch (source_desc->common.type) {
333 case ACPI_TYPE_INTEGER: 333 case ACPI_TYPE_INTEGER:
334
334 buffer = &source_desc->integer.value; 335 buffer = &source_desc->integer.value;
335 length = sizeof(source_desc->integer.value); 336 length = sizeof(source_desc->integer.value);
336 break; 337 break;
337 338
338 case ACPI_TYPE_BUFFER: 339 case ACPI_TYPE_BUFFER:
340
339 buffer = source_desc->buffer.pointer; 341 buffer = source_desc->buffer.pointer;
340 length = source_desc->buffer.length; 342 length = source_desc->buffer.length;
341 break; 343 break;
342 344
343 case ACPI_TYPE_STRING: 345 case ACPI_TYPE_STRING:
346
344 buffer = source_desc->string.pointer; 347 buffer = source_desc->string.pointer;
345 length = source_desc->string.length; 348 length = source_desc->string.length;
346 break; 349 break;
347 350
348 default: 351 default:
352
349 return_ACPI_STATUS(AE_AML_OPERAND_TYPE); 353 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
350 } 354 }
351 355
diff --git a/drivers/acpi/acpica/exfldio.c b/drivers/acpi/acpica/exfldio.c
index c84ee956fa4c..7e0afe72487e 100644
--- a/drivers/acpi/acpica/exfldio.c
+++ b/drivers/acpi/acpica/exfldio.c
@@ -446,7 +446,6 @@ acpi_ex_field_datum_io(union acpi_operand_object *obj_desc,
446 break; 446 break;
447 447
448 case ACPI_TYPE_LOCAL_BANK_FIELD: 448 case ACPI_TYPE_LOCAL_BANK_FIELD:
449
450 /* 449 /*
451 * Ensure that the bank_value is not beyond the capacity of 450 * Ensure that the bank_value is not beyond the capacity of
452 * the register 451 * the register
@@ -488,7 +487,6 @@ acpi_ex_field_datum_io(union acpi_operand_object *obj_desc,
488 break; 487 break;
489 488
490 case ACPI_TYPE_LOCAL_INDEX_FIELD: 489 case ACPI_TYPE_LOCAL_INDEX_FIELD:
491
492 /* 490 /*
493 * Ensure that the index_value is not beyond the capacity of 491 * Ensure that the index_value is not beyond the capacity of
494 * the register 492 * the register
diff --git a/drivers/acpi/acpica/exmisc.c b/drivers/acpi/acpica/exmisc.c
index 72a2a13b6d36..00bf29877574 100644
--- a/drivers/acpi/acpica/exmisc.c
+++ b/drivers/acpi/acpica/exmisc.c
@@ -105,7 +105,6 @@ acpi_ex_get_object_reference(union acpi_operand_object *obj_desc,
105 break; 105 break;
106 106
107 case ACPI_DESC_TYPE_NAMED: 107 case ACPI_DESC_TYPE_NAMED:
108
109 /* 108 /*
110 * A named reference that has already been resolved to a Node 109 * A named reference that has already been resolved to a Node
111 */ 110 */
@@ -261,20 +260,24 @@ acpi_ex_do_concatenate(union acpi_operand_object *operand0,
261 */ 260 */
262 switch (operand0->common.type) { 261 switch (operand0->common.type) {
263 case ACPI_TYPE_INTEGER: 262 case ACPI_TYPE_INTEGER:
263
264 status = 264 status =
265 acpi_ex_convert_to_integer(operand1, &local_operand1, 16); 265 acpi_ex_convert_to_integer(operand1, &local_operand1, 16);
266 break; 266 break;
267 267
268 case ACPI_TYPE_STRING: 268 case ACPI_TYPE_STRING:
269
269 status = acpi_ex_convert_to_string(operand1, &local_operand1, 270 status = acpi_ex_convert_to_string(operand1, &local_operand1,
270 ACPI_IMPLICIT_CONVERT_HEX); 271 ACPI_IMPLICIT_CONVERT_HEX);
271 break; 272 break;
272 273
273 case ACPI_TYPE_BUFFER: 274 case ACPI_TYPE_BUFFER:
275
274 status = acpi_ex_convert_to_buffer(operand1, &local_operand1); 276 status = acpi_ex_convert_to_buffer(operand1, &local_operand1);
275 break; 277 break;
276 278
277 default: 279 default:
280
278 ACPI_ERROR((AE_INFO, "Invalid object type: 0x%X", 281 ACPI_ERROR((AE_INFO, "Invalid object type: 0x%X",
279 operand0->common.type)); 282 operand0->common.type));
280 status = AE_AML_INTERNAL; 283 status = AE_AML_INTERNAL;
@@ -519,6 +522,7 @@ acpi_ex_do_logical_numeric_op(u16 opcode,
519 break; 522 break;
520 523
521 default: 524 default:
525
522 status = AE_AML_INTERNAL; 526 status = AE_AML_INTERNAL;
523 break; 527 break;
524 } 528 }
@@ -580,20 +584,24 @@ acpi_ex_do_logical_op(u16 opcode,
580 */ 584 */
581 switch (operand0->common.type) { 585 switch (operand0->common.type) {
582 case ACPI_TYPE_INTEGER: 586 case ACPI_TYPE_INTEGER:
587
583 status = 588 status =
584 acpi_ex_convert_to_integer(operand1, &local_operand1, 16); 589 acpi_ex_convert_to_integer(operand1, &local_operand1, 16);
585 break; 590 break;
586 591
587 case ACPI_TYPE_STRING: 592 case ACPI_TYPE_STRING:
593
588 status = acpi_ex_convert_to_string(operand1, &local_operand1, 594 status = acpi_ex_convert_to_string(operand1, &local_operand1,
589 ACPI_IMPLICIT_CONVERT_HEX); 595 ACPI_IMPLICIT_CONVERT_HEX);
590 break; 596 break;
591 597
592 case ACPI_TYPE_BUFFER: 598 case ACPI_TYPE_BUFFER:
599
593 status = acpi_ex_convert_to_buffer(operand1, &local_operand1); 600 status = acpi_ex_convert_to_buffer(operand1, &local_operand1);
594 break; 601 break;
595 602
596 default: 603 default:
604
597 status = AE_AML_INTERNAL; 605 status = AE_AML_INTERNAL;
598 break; 606 break;
599 } 607 }
@@ -636,6 +644,7 @@ acpi_ex_do_logical_op(u16 opcode,
636 break; 644 break;
637 645
638 default: 646 default:
647
639 status = AE_AML_INTERNAL; 648 status = AE_AML_INTERNAL;
640 break; 649 break;
641 } 650 }
@@ -703,6 +712,7 @@ acpi_ex_do_logical_op(u16 opcode,
703 break; 712 break;
704 713
705 default: 714 default:
715
706 status = AE_AML_INTERNAL; 716 status = AE_AML_INTERNAL;
707 break; 717 break;
708 } 718 }
diff --git a/drivers/acpi/acpica/exoparg1.c b/drivers/acpi/acpica/exoparg1.c
index b60c877f5906..814b4a3d656a 100644
--- a/drivers/acpi/acpica/exoparg1.c
+++ b/drivers/acpi/acpica/exoparg1.c
@@ -327,7 +327,6 @@ acpi_status acpi_ex_opcode_1A_1T_1R(struct acpi_walk_state *walk_state)
327 break; 327 break;
328 328
329 case AML_FROM_BCD_OP: /* from_bcd (BCDValue, Result) */ 329 case AML_FROM_BCD_OP: /* from_bcd (BCDValue, Result) */
330
331 /* 330 /*
332 * The 64-bit ACPI integer can hold 16 4-bit BCD characters 331 * The 64-bit ACPI integer can hold 16 4-bit BCD characters
333 * (if table is 32-bit, integer can hold 8 BCD characters) 332 * (if table is 32-bit, integer can hold 8 BCD characters)
@@ -407,7 +406,6 @@ acpi_status acpi_ex_opcode_1A_1T_1R(struct acpi_walk_state *walk_state)
407 break; 406 break;
408 407
409 case AML_COND_REF_OF_OP: /* cond_ref_of (source_object, Result) */ 408 case AML_COND_REF_OF_OP: /* cond_ref_of (source_object, Result) */
410
411 /* 409 /*
412 * This op is a little strange because the internal return value is 410 * This op is a little strange because the internal return value is
413 * different than the return value stored in the result descriptor 411 * different than the return value stored in the result descriptor
@@ -442,13 +440,14 @@ acpi_status acpi_ex_opcode_1A_1T_1R(struct acpi_walk_state *walk_state)
442 goto cleanup; 440 goto cleanup;
443 441
444 default: 442 default:
443
445 /* No other opcodes get here */ 444 /* No other opcodes get here */
445
446 break; 446 break;
447 } 447 }
448 break; 448 break;
449 449
450 case AML_STORE_OP: /* Store (Source, Target) */ 450 case AML_STORE_OP: /* Store (Source, Target) */
451
452 /* 451 /*
453 * A store operand is typically a number, string, buffer or lvalue 452 * A store operand is typically a number, string, buffer or lvalue
454 * Be careful about deleting the source object, 453 * Be careful about deleting the source object,
@@ -615,7 +614,6 @@ acpi_status acpi_ex_opcode_1A_0T_1R(struct acpi_walk_state *walk_state)
615 614
616 case AML_DECREMENT_OP: /* Decrement (Operand) */ 615 case AML_DECREMENT_OP: /* Decrement (Operand) */
617 case AML_INCREMENT_OP: /* Increment (Operand) */ 616 case AML_INCREMENT_OP: /* Increment (Operand) */
618
619 /* 617 /*
620 * Create a new integer. Can't just get the base integer and 618 * Create a new integer. Can't just get the base integer and
621 * increment it because it may be an Arg or Field. 619 * increment it because it may be an Arg or Field.
@@ -682,7 +680,6 @@ acpi_status acpi_ex_opcode_1A_0T_1R(struct acpi_walk_state *walk_state)
682 break; 680 break;
683 681
684 case AML_TYPE_OP: /* object_type (source_object) */ 682 case AML_TYPE_OP: /* object_type (source_object) */
685
686 /* 683 /*
687 * Note: The operand is not resolved at this point because we want to 684 * Note: The operand is not resolved at this point because we want to
688 * get the associated object, not its value. For example, we don't 685 * get the associated object, not its value. For example, we don't
@@ -709,7 +706,6 @@ acpi_status acpi_ex_opcode_1A_0T_1R(struct acpi_walk_state *walk_state)
709 break; 706 break;
710 707
711 case AML_SIZE_OF_OP: /* size_of (source_object) */ 708 case AML_SIZE_OF_OP: /* size_of (source_object) */
712
713 /* 709 /*
714 * Note: The operand is not resolved at this point because we want to 710 * Note: The operand is not resolved at this point because we want to
715 * get the associated object, not its value. 711 * get the associated object, not its value.
@@ -735,10 +731,12 @@ acpi_status acpi_ex_opcode_1A_0T_1R(struct acpi_walk_state *walk_state)
735 */ 731 */
736 switch (type) { 732 switch (type) {
737 case ACPI_TYPE_INTEGER: 733 case ACPI_TYPE_INTEGER:
734
738 value = acpi_gbl_integer_byte_width; 735 value = acpi_gbl_integer_byte_width;
739 break; 736 break;
740 737
741 case ACPI_TYPE_STRING: 738 case ACPI_TYPE_STRING:
739
742 value = temp_desc->string.length; 740 value = temp_desc->string.length;
743 break; 741 break;
744 742
@@ -759,6 +757,7 @@ acpi_status acpi_ex_opcode_1A_0T_1R(struct acpi_walk_state *walk_state)
759 break; 757 break;
760 758
761 default: 759 default:
760
762 ACPI_ERROR((AE_INFO, 761 ACPI_ERROR((AE_INFO,
763 "Operand must be Buffer/Integer/String/Package - found type %s", 762 "Operand must be Buffer/Integer/String/Package - found type %s",
764 acpi_ut_get_type_name(type))); 763 acpi_ut_get_type_name(type)));
@@ -860,9 +859,11 @@ acpi_status acpi_ex_opcode_1A_0T_1R(struct acpi_walk_state *walk_state)
860 break; 859 break;
861 860
862 case ACPI_TYPE_STRING: 861 case ACPI_TYPE_STRING:
862
863 break; 863 break;
864 864
865 default: 865 default:
866
866 status = AE_AML_OPERAND_TYPE; 867 status = AE_AML_OPERAND_TYPE;
867 goto cleanup; 868 goto cleanup;
868 } 869 }
@@ -923,7 +924,6 @@ acpi_status acpi_ex_opcode_1A_0T_1R(struct acpi_walk_state *walk_state)
923 */ 924 */
924 switch (operand[0]->reference.class) { 925 switch (operand[0]->reference.class) {
925 case ACPI_REFCLASS_INDEX: 926 case ACPI_REFCLASS_INDEX:
926
927 /* 927 /*
928 * The target type for the Index operator must be 928 * The target type for the Index operator must be
929 * either a Buffer or a Package 929 * either a Buffer or a Package
@@ -956,7 +956,6 @@ acpi_status acpi_ex_opcode_1A_0T_1R(struct acpi_walk_state *walk_state)
956 break; 956 break;
957 957
958 case ACPI_TYPE_PACKAGE: 958 case ACPI_TYPE_PACKAGE:
959
960 /* 959 /*
961 * Return the referenced element of the package. We must 960 * Return the referenced element of the package. We must
962 * add another reference to the referenced object, however. 961 * add another reference to the referenced object, however.
@@ -999,6 +998,7 @@ acpi_status acpi_ex_opcode_1A_0T_1R(struct acpi_walk_state *walk_state)
999 break; 998 break;
1000 999
1001 default: 1000 default:
1001
1002 ACPI_ERROR((AE_INFO, 1002 ACPI_ERROR((AE_INFO,
1003 "Unknown class in reference(%p) - 0x%2.2X", 1003 "Unknown class in reference(%p) - 0x%2.2X",
1004 operand[0], 1004 operand[0],
diff --git a/drivers/acpi/acpica/exoparg2.c b/drivers/acpi/acpica/exoparg2.c
index b0838a4ea53e..d5088f7030c7 100644
--- a/drivers/acpi/acpica/exoparg2.c
+++ b/drivers/acpi/acpica/exoparg2.c
@@ -304,7 +304,6 @@ acpi_status acpi_ex_opcode_2A_1T_1R(struct acpi_walk_state *walk_state)
304 break; 304 break;
305 305
306 case AML_TO_STRING_OP: /* to_string (Buffer, Length, Result) (ACPI 2.0) */ 306 case AML_TO_STRING_OP: /* to_string (Buffer, Length, Result) (ACPI 2.0) */
307
308 /* 307 /*
309 * Input object is guaranteed to be a buffer at this point (it may have 308 * Input object is guaranteed to be a buffer at this point (it may have
310 * been converted.) Copy the raw buffer data to a new object of 309 * been converted.) Copy the raw buffer data to a new object of
diff --git a/drivers/acpi/acpica/exoparg3.c b/drivers/acpi/acpica/exoparg3.c
index 2d7491f3126e..37656f12f204 100644
--- a/drivers/acpi/acpica/exoparg3.c
+++ b/drivers/acpi/acpica/exoparg3.c
@@ -155,7 +155,6 @@ acpi_status acpi_ex_opcode_3A_1T_1R(struct acpi_walk_state *walk_state)
155 155
156 switch (walk_state->opcode) { 156 switch (walk_state->opcode) {
157 case AML_MID_OP: /* Mid (Source[0], Index[1], Length[2], Result[3]) */ 157 case AML_MID_OP: /* Mid (Source[0], Index[1], Length[2], Result[3]) */
158
159 /* 158 /*
160 * Create the return object. The Source operand is guaranteed to be 159 * Create the return object. The Source operand is guaranteed to be
161 * either a String or a Buffer, so just use its type. 160 * either a String or a Buffer, so just use its type.
diff --git a/drivers/acpi/acpica/exoparg6.c b/drivers/acpi/acpica/exoparg6.c
index b76b97002dff..879b6cd8319c 100644
--- a/drivers/acpi/acpica/exoparg6.c
+++ b/drivers/acpi/acpica/exoparg6.c
@@ -119,7 +119,6 @@ acpi_ex_do_match(u32 match_op,
119 break; 119 break;
120 120
121 case MATCH_MEQ: 121 case MATCH_MEQ:
122
123 /* 122 /*
124 * True if equal: (P[i] == M) 123 * True if equal: (P[i] == M)
125 * Change to: (M == P[i]) 124 * Change to: (M == P[i])
@@ -133,7 +132,6 @@ acpi_ex_do_match(u32 match_op,
133 break; 132 break;
134 133
135 case MATCH_MLE: 134 case MATCH_MLE:
136
137 /* 135 /*
138 * True if less than or equal: (P[i] <= M) (P[i] not_greater than M) 136 * True if less than or equal: (P[i] <= M) (P[i] not_greater than M)
139 * Change to: (M >= P[i]) (M not_less than P[i]) 137 * Change to: (M >= P[i]) (M not_less than P[i])
@@ -148,7 +146,6 @@ acpi_ex_do_match(u32 match_op,
148 break; 146 break;
149 147
150 case MATCH_MLT: 148 case MATCH_MLT:
151
152 /* 149 /*
153 * True if less than: (P[i] < M) 150 * True if less than: (P[i] < M)
154 * Change to: (M > P[i]) 151 * Change to: (M > P[i])
@@ -162,7 +159,6 @@ acpi_ex_do_match(u32 match_op,
162 break; 159 break;
163 160
164 case MATCH_MGE: 161 case MATCH_MGE:
165
166 /* 162 /*
167 * True if greater than or equal: (P[i] >= M) (P[i] not_less than M) 163 * True if greater than or equal: (P[i] >= M) (P[i] not_less than M)
168 * Change to: (M <= P[i]) (M not_greater than P[i]) 164 * Change to: (M <= P[i]) (M not_greater than P[i])
@@ -177,7 +173,6 @@ acpi_ex_do_match(u32 match_op,
177 break; 173 break;
178 174
179 case MATCH_MGT: 175 case MATCH_MGT:
180
181 /* 176 /*
182 * True if greater than: (P[i] > M) 177 * True if greater than: (P[i] > M)
183 * Change to: (M < P[i]) 178 * Change to: (M < P[i])
diff --git a/drivers/acpi/acpica/exprep.c b/drivers/acpi/acpica/exprep.c
index 6b728aef2dca..5a588611ab48 100644
--- a/drivers/acpi/acpica/exprep.c
+++ b/drivers/acpi/acpica/exprep.c
@@ -253,26 +253,31 @@ acpi_ex_decode_field_access(union acpi_operand_object *obj_desc,
253 253
254 case AML_FIELD_ACCESS_BYTE: 254 case AML_FIELD_ACCESS_BYTE:
255 case AML_FIELD_ACCESS_BUFFER: /* ACPI 2.0 (SMBus Buffer) */ 255 case AML_FIELD_ACCESS_BUFFER: /* ACPI 2.0 (SMBus Buffer) */
256
256 byte_alignment = 1; 257 byte_alignment = 1;
257 bit_length = 8; 258 bit_length = 8;
258 break; 259 break;
259 260
260 case AML_FIELD_ACCESS_WORD: 261 case AML_FIELD_ACCESS_WORD:
262
261 byte_alignment = 2; 263 byte_alignment = 2;
262 bit_length = 16; 264 bit_length = 16;
263 break; 265 break;
264 266
265 case AML_FIELD_ACCESS_DWORD: 267 case AML_FIELD_ACCESS_DWORD:
268
266 byte_alignment = 4; 269 byte_alignment = 4;
267 bit_length = 32; 270 bit_length = 32;
268 break; 271 break;
269 272
270 case AML_FIELD_ACCESS_QWORD: /* ACPI 2.0 */ 273 case AML_FIELD_ACCESS_QWORD: /* ACPI 2.0 */
274
271 byte_alignment = 8; 275 byte_alignment = 8;
272 bit_length = 64; 276 bit_length = 64;
273 break; 277 break;
274 278
275 default: 279 default:
280
276 /* Invalid field access type */ 281 /* Invalid field access type */
277 282
278 ACPI_ERROR((AE_INFO, "Unknown field access type 0x%X", access)); 283 ACPI_ERROR((AE_INFO, "Unknown field access type 0x%X", access));
@@ -598,7 +603,9 @@ acpi_status acpi_ex_prep_field_value(struct acpi_create_field_info *info)
598 break; 603 break;
599 604
600 default: 605 default:
606
601 /* No other types should get here */ 607 /* No other types should get here */
608
602 break; 609 break;
603 } 610 }
604 611
diff --git a/drivers/acpi/acpica/exregion.c b/drivers/acpi/acpica/exregion.c
index 182abaf045e1..303429bb4d5d 100644
--- a/drivers/acpi/acpica/exregion.c
+++ b/drivers/acpi/acpica/exregion.c
@@ -88,22 +88,27 @@ acpi_ex_system_memory_space_handler(u32 function,
88 88
89 switch (bit_width) { 89 switch (bit_width) {
90 case 8: 90 case 8:
91
91 length = 1; 92 length = 1;
92 break; 93 break;
93 94
94 case 16: 95 case 16:
96
95 length = 2; 97 length = 2;
96 break; 98 break;
97 99
98 case 32: 100 case 32:
101
99 length = 4; 102 length = 4;
100 break; 103 break;
101 104
102 case 64: 105 case 64:
106
103 length = 8; 107 length = 8;
104 break; 108 break;
105 109
106 default: 110 default:
111
107 ACPI_ERROR((AE_INFO, "Invalid SystemMemory width %u", 112 ACPI_ERROR((AE_INFO, "Invalid SystemMemory width %u",
108 bit_width)); 113 bit_width));
109 return_ACPI_STATUS(AE_AML_OPERAND_VALUE); 114 return_ACPI_STATUS(AE_AML_OPERAND_VALUE);
@@ -214,23 +219,29 @@ acpi_ex_system_memory_space_handler(u32 function,
214 *value = 0; 219 *value = 0;
215 switch (bit_width) { 220 switch (bit_width) {
216 case 8: 221 case 8:
217 *value = (u64) ACPI_GET8(logical_addr_ptr); 222
223 *value = (u64)ACPI_GET8(logical_addr_ptr);
218 break; 224 break;
219 225
220 case 16: 226 case 16:
221 *value = (u64) ACPI_GET16(logical_addr_ptr); 227
228 *value = (u64)ACPI_GET16(logical_addr_ptr);
222 break; 229 break;
223 230
224 case 32: 231 case 32:
225 *value = (u64) ACPI_GET32(logical_addr_ptr); 232
233 *value = (u64)ACPI_GET32(logical_addr_ptr);
226 break; 234 break;
227 235
228 case 64: 236 case 64:
229 *value = (u64) ACPI_GET64(logical_addr_ptr); 237
238 *value = (u64)ACPI_GET64(logical_addr_ptr);
230 break; 239 break;
231 240
232 default: 241 default:
242
233 /* bit_width was already validated */ 243 /* bit_width was already validated */
244
234 break; 245 break;
235 } 246 }
236 break; 247 break;
@@ -239,28 +250,35 @@ acpi_ex_system_memory_space_handler(u32 function,
239 250
240 switch (bit_width) { 251 switch (bit_width) {
241 case 8: 252 case 8:
253
242 ACPI_SET8(logical_addr_ptr, *value); 254 ACPI_SET8(logical_addr_ptr, *value);
243 break; 255 break;
244 256
245 case 16: 257 case 16:
258
246 ACPI_SET16(logical_addr_ptr, *value); 259 ACPI_SET16(logical_addr_ptr, *value);
247 break; 260 break;
248 261
249 case 32: 262 case 32:
263
250 ACPI_SET32(logical_addr_ptr, *value); 264 ACPI_SET32(logical_addr_ptr, *value);
251 break; 265 break;
252 266
253 case 64: 267 case 64:
268
254 ACPI_SET64(logical_addr_ptr, *value); 269 ACPI_SET64(logical_addr_ptr, *value);
255 break; 270 break;
256 271
257 default: 272 default:
273
258 /* bit_width was already validated */ 274 /* bit_width was already validated */
275
259 break; 276 break;
260 } 277 }
261 break; 278 break;
262 279
263 default: 280 default:
281
264 status = AE_BAD_PARAMETER; 282 status = AE_BAD_PARAMETER;
265 break; 283 break;
266 } 284 }
@@ -320,6 +338,7 @@ acpi_ex_system_io_space_handler(u32 function,
320 break; 338 break;
321 339
322 default: 340 default:
341
323 status = AE_BAD_PARAMETER; 342 status = AE_BAD_PARAMETER;
324 break; 343 break;
325 } 344 }
diff --git a/drivers/acpi/acpica/exresnte.c b/drivers/acpi/acpica/exresnte.c
index 8565b6bd12bb..acd34f599313 100644
--- a/drivers/acpi/acpica/exresnte.c
+++ b/drivers/acpi/acpica/exresnte.c
@@ -248,6 +248,7 @@ acpi_ex_resolve_node_to_value(struct acpi_namespace_node **object_ptr,
248 break; 248 break;
249 249
250 default: 250 default:
251
251 /* No named references are allowed here */ 252 /* No named references are allowed here */
252 253
253 ACPI_ERROR((AE_INFO, 254 ACPI_ERROR((AE_INFO,
diff --git a/drivers/acpi/acpica/exresolv.c b/drivers/acpi/acpica/exresolv.c
index e4f9dfbb2a13..ac04278ad28f 100644
--- a/drivers/acpi/acpica/exresolv.c
+++ b/drivers/acpi/acpica/exresolv.c
@@ -156,7 +156,6 @@ acpi_ex_resolve_object_to_value(union acpi_operand_object **stack_ptr,
156 switch (ref_type) { 156 switch (ref_type) {
157 case ACPI_REFCLASS_LOCAL: 157 case ACPI_REFCLASS_LOCAL:
158 case ACPI_REFCLASS_ARG: 158 case ACPI_REFCLASS_ARG:
159
160 /* 159 /*
161 * Get the local from the method's state info 160 * Get the local from the method's state info
162 * Note: this increments the local's object reference count 161 * Note: this increments the local's object reference count
@@ -309,6 +308,7 @@ acpi_ex_resolve_object_to_value(union acpi_operand_object **stack_ptr,
309 break; 308 break;
310 309
311 default: 310 default:
311
312 break; 312 break;
313 } 313 }
314 314
@@ -348,10 +348,12 @@ acpi_ex_resolve_multiple(struct acpi_walk_state *walk_state,
348 348
349 switch (ACPI_GET_DESCRIPTOR_TYPE(obj_desc)) { 349 switch (ACPI_GET_DESCRIPTOR_TYPE(obj_desc)) {
350 case ACPI_DESC_TYPE_OPERAND: 350 case ACPI_DESC_TYPE_OPERAND:
351
351 type = obj_desc->common.type; 352 type = obj_desc->common.type;
352 break; 353 break;
353 354
354 case ACPI_DESC_TYPE_NAMED: 355 case ACPI_DESC_TYPE_NAMED:
356
355 type = ((struct acpi_namespace_node *)obj_desc)->type; 357 type = ((struct acpi_namespace_node *)obj_desc)->type;
356 obj_desc = 358 obj_desc =
357 acpi_ns_get_attached_object((struct acpi_namespace_node *) 359 acpi_ns_get_attached_object((struct acpi_namespace_node *)
@@ -538,7 +540,9 @@ acpi_ex_resolve_multiple(struct acpi_walk_state *walk_state,
538 break; 540 break;
539 541
540 default: 542 default:
543
541 /* No change to Type required */ 544 /* No change to Type required */
545
542 break; 546 break;
543 } 547 }
544 548
diff --git a/drivers/acpi/acpica/exresop.c b/drivers/acpi/acpica/exresop.c
index 9fb9f5e9a4da..00e5af7129c1 100644
--- a/drivers/acpi/acpica/exresop.c
+++ b/drivers/acpi/acpica/exresop.c
@@ -307,7 +307,6 @@ acpi_ex_resolve_operands(u16 opcode,
307 case ARGI_TARGETREF: /* Allows implicit conversion rules before store */ 307 case ARGI_TARGETREF: /* Allows implicit conversion rules before store */
308 case ARGI_FIXED_TARGET: /* No implicit conversion before store to target */ 308 case ARGI_FIXED_TARGET: /* No implicit conversion before store to target */
309 case ARGI_SIMPLE_TARGET: /* Name, Local, or arg - no implicit conversion */ 309 case ARGI_SIMPLE_TARGET: /* Name, Local, or arg - no implicit conversion */
310
311 /* 310 /*
312 * Need an operand of type ACPI_TYPE_LOCAL_REFERENCE 311 * Need an operand of type ACPI_TYPE_LOCAL_REFERENCE
313 * A Namespace Node is OK as-is 312 * A Namespace Node is OK as-is
@@ -326,7 +325,6 @@ acpi_ex_resolve_operands(u16 opcode,
326 goto next_operand; 325 goto next_operand;
327 326
328 case ARGI_DATAREFOBJ: /* Store operator only */ 327 case ARGI_DATAREFOBJ: /* Store operator only */
329
330 /* 328 /*
331 * We don't want to resolve index_op reference objects during 329 * We don't want to resolve index_op reference objects during
332 * a store because this would be an implicit de_ref_of operation. 330 * a store because this would be an implicit de_ref_of operation.
@@ -343,7 +341,9 @@ acpi_ex_resolve_operands(u16 opcode,
343 break; 341 break;
344 342
345 default: 343 default:
344
346 /* All cases covered above */ 345 /* All cases covered above */
346
347 break; 347 break;
348 } 348 }
349 349
@@ -433,7 +433,6 @@ acpi_ex_resolve_operands(u16 opcode,
433 goto next_operand; 433 goto next_operand;
434 434
435 case ARGI_BUFFER: 435 case ARGI_BUFFER:
436
437 /* 436 /*
438 * Need an operand of type ACPI_TYPE_BUFFER, 437 * Need an operand of type ACPI_TYPE_BUFFER,
439 * But we can implicitly convert from a STRING or INTEGER 438 * But we can implicitly convert from a STRING or INTEGER
@@ -459,7 +458,6 @@ acpi_ex_resolve_operands(u16 opcode,
459 goto next_operand; 458 goto next_operand;
460 459
461 case ARGI_STRING: 460 case ARGI_STRING:
462
463 /* 461 /*
464 * Need an operand of type ACPI_TYPE_STRING, 462 * Need an operand of type ACPI_TYPE_STRING,
465 * But we can implicitly convert from a BUFFER or INTEGER 463 * But we can implicitly convert from a BUFFER or INTEGER
@@ -562,6 +560,7 @@ acpi_ex_resolve_operands(u16 opcode,
562 break; 560 break;
563 561
564 default: 562 default:
563
565 ACPI_ERROR((AE_INFO, 564 ACPI_ERROR((AE_INFO,
566 "Needed [Buffer/String/Package/Reference], found [%s] %p", 565 "Needed [Buffer/String/Package/Reference], found [%s] %p",
567 acpi_ut_get_object_type_name 566 acpi_ut_get_object_type_name
@@ -584,6 +583,7 @@ acpi_ex_resolve_operands(u16 opcode,
584 break; 583 break;
585 584
586 default: 585 default:
586
587 ACPI_ERROR((AE_INFO, 587 ACPI_ERROR((AE_INFO,
588 "Needed [Buffer/String/Package], found [%s] %p", 588 "Needed [Buffer/String/Package], found [%s] %p",
589 acpi_ut_get_object_type_name 589 acpi_ut_get_object_type_name
@@ -605,6 +605,7 @@ acpi_ex_resolve_operands(u16 opcode,
605 break; 605 break;
606 606
607 default: 607 default:
608
608 ACPI_ERROR((AE_INFO, 609 ACPI_ERROR((AE_INFO,
609 "Needed [Region/Buffer], found [%s] %p", 610 "Needed [Region/Buffer], found [%s] %p",
610 acpi_ut_get_object_type_name 611 acpi_ut_get_object_type_name
diff --git a/drivers/acpi/acpica/exstore.c b/drivers/acpi/acpica/exstore.c
index 93c6049c2d75..2bdba6f7d762 100644
--- a/drivers/acpi/acpica/exstore.c
+++ b/drivers/acpi/acpica/exstore.c
@@ -114,6 +114,7 @@ acpi_ex_store(union acpi_operand_object *source_desc,
114 114
115 switch (dest_desc->common.type) { 115 switch (dest_desc->common.type) {
116 case ACPI_TYPE_LOCAL_REFERENCE: 116 case ACPI_TYPE_LOCAL_REFERENCE:
117
117 break; 118 break;
118 119
119 case ACPI_TYPE_INTEGER: 120 case ACPI_TYPE_INTEGER:
@@ -178,7 +179,6 @@ acpi_ex_store(union acpi_operand_object *source_desc,
178 break; 179 break;
179 180
180 case ACPI_REFCLASS_DEBUG: 181 case ACPI_REFCLASS_DEBUG:
181
182 /* 182 /*
183 * Storing to the Debug object causes the value stored to be 183 * Storing to the Debug object causes the value stored to be
184 * displayed and otherwise has no effect -- see ACPI Specification 184 * displayed and otherwise has no effect -- see ACPI Specification
@@ -291,7 +291,6 @@ acpi_ex_store_object_to_index(union acpi_operand_object *source_desc,
291 break; 291 break;
292 292
293 case ACPI_TYPE_BUFFER_FIELD: 293 case ACPI_TYPE_BUFFER_FIELD:
294
295 /* 294 /*
296 * Store into a Buffer or String (not actually a real buffer_field) 295 * Store into a Buffer or String (not actually a real buffer_field)
297 * at a location defined by an Index. 296 * at a location defined by an Index.
@@ -447,7 +446,6 @@ acpi_ex_store_object_to_node(union acpi_operand_object *source_desc,
447 case ACPI_TYPE_INTEGER: 446 case ACPI_TYPE_INTEGER:
448 case ACPI_TYPE_STRING: 447 case ACPI_TYPE_STRING:
449 case ACPI_TYPE_BUFFER: 448 case ACPI_TYPE_BUFFER:
450
451 /* 449 /*
452 * These target types are all of type Integer/String/Buffer, and 450 * These target types are all of type Integer/String/Buffer, and
453 * therefore support implicit conversion before the store. 451 * therefore support implicit conversion before the store.
diff --git a/drivers/acpi/acpica/exstoren.c b/drivers/acpi/acpica/exstoren.c
index 1cefe777068e..20d809d90c5b 100644
--- a/drivers/acpi/acpica/exstoren.c
+++ b/drivers/acpi/acpica/exstoren.c
@@ -85,11 +85,9 @@ acpi_ex_resolve_object(union acpi_operand_object **source_desc_ptr,
85 * These cases all require only Integers or values that 85 * These cases all require only Integers or values that
86 * can be converted to Integers (Strings or Buffers) 86 * can be converted to Integers (Strings or Buffers)
87 */ 87 */
88
89 case ACPI_TYPE_INTEGER: 88 case ACPI_TYPE_INTEGER:
90 case ACPI_TYPE_STRING: 89 case ACPI_TYPE_STRING:
91 case ACPI_TYPE_BUFFER: 90 case ACPI_TYPE_BUFFER:
92
93 /* 91 /*
94 * Stores into a Field/Region or into a Integer/Buffer/String 92 * Stores into a Field/Region or into a Integer/Buffer/String
95 * are all essentially the same. This case handles the 93 * are all essentially the same. This case handles the
@@ -133,7 +131,6 @@ acpi_ex_resolve_object(union acpi_operand_object **source_desc_ptr,
133 131
134 case ACPI_TYPE_LOCAL_ALIAS: 132 case ACPI_TYPE_LOCAL_ALIAS:
135 case ACPI_TYPE_LOCAL_METHOD_ALIAS: 133 case ACPI_TYPE_LOCAL_METHOD_ALIAS:
136
137 /* 134 /*
138 * All aliases should have been resolved earlier, during the 135 * All aliases should have been resolved earlier, during the
139 * operand resolution phase. 136 * operand resolution phase.
@@ -144,7 +141,6 @@ acpi_ex_resolve_object(union acpi_operand_object **source_desc_ptr,
144 141
145 case ACPI_TYPE_PACKAGE: 142 case ACPI_TYPE_PACKAGE:
146 default: 143 default:
147
148 /* 144 /*
149 * All other types than Alias and the various Fields come here, 145 * All other types than Alias and the various Fields come here,
150 * including the untyped case - ACPI_TYPE_ANY. 146 * including the untyped case - ACPI_TYPE_ANY.
diff --git a/drivers/acpi/acpica/hwacpi.c b/drivers/acpi/acpica/hwacpi.c
index 579c3a53ac87..3d36df828f52 100644
--- a/drivers/acpi/acpica/hwacpi.c
+++ b/drivers/acpi/acpica/hwacpi.c
@@ -108,7 +108,6 @@ acpi_status acpi_hw_set_mode(u32 mode)
108 break; 108 break;
109 109
110 case ACPI_SYS_MODE_LEGACY: 110 case ACPI_SYS_MODE_LEGACY:
111
112 /* 111 /*
113 * BIOS should clear all fixed status bits and restore fixed event 112 * BIOS should clear all fixed status bits and restore fixed event
114 * enable bits to default 113 * enable bits to default
@@ -120,6 +119,7 @@ acpi_status acpi_hw_set_mode(u32 mode)
120 break; 119 break;
121 120
122 default: 121 default:
122
123 return_ACPI_STATUS(AE_BAD_PARAMETER); 123 return_ACPI_STATUS(AE_BAD_PARAMETER);
124 } 124 }
125 125
diff --git a/drivers/acpi/acpica/hwgpe.c b/drivers/acpi/acpica/hwgpe.c
index 20d02e93c990..96540506058f 100644
--- a/drivers/acpi/acpica/hwgpe.c
+++ b/drivers/acpi/acpica/hwgpe.c
@@ -127,14 +127,17 @@ acpi_hw_low_set_gpe(struct acpi_gpe_event_info *gpe_event_info, u32 action)
127 /*lint -fallthrough */ 127 /*lint -fallthrough */
128 128
129 case ACPI_GPE_ENABLE: 129 case ACPI_GPE_ENABLE:
130
130 ACPI_SET_BIT(enable_mask, register_bit); 131 ACPI_SET_BIT(enable_mask, register_bit);
131 break; 132 break;
132 133
133 case ACPI_GPE_DISABLE: 134 case ACPI_GPE_DISABLE:
135
134 ACPI_CLEAR_BIT(enable_mask, register_bit); 136 ACPI_CLEAR_BIT(enable_mask, register_bit);
135 break; 137 break;
136 138
137 default: 139 default:
140
138 ACPI_ERROR((AE_INFO, "Invalid GPE Action, %u", action)); 141 ACPI_ERROR((AE_INFO, "Invalid GPE Action, %u", action));
139 return (AE_BAD_PARAMETER); 142 return (AE_BAD_PARAMETER);
140 } 143 }
diff --git a/drivers/acpi/acpica/hwregs.c b/drivers/acpi/acpica/hwregs.c
index 083d6551f0e2..8d2e866be15f 100644
--- a/drivers/acpi/acpica/hwregs.c
+++ b/drivers/acpi/acpica/hwregs.c
@@ -419,6 +419,7 @@ acpi_status acpi_hw_register_read(u32 register_id, u32 *return_value)
419 break; 419 break;
420 420
421 default: 421 default:
422
422 ACPI_ERROR((AE_INFO, "Unknown Register ID: 0x%X", register_id)); 423 ACPI_ERROR((AE_INFO, "Unknown Register ID: 0x%X", register_id));
423 status = AE_BAD_PARAMETER; 424 status = AE_BAD_PARAMETER;
424 break; 425 break;
@@ -491,7 +492,6 @@ acpi_status acpi_hw_register_write(u32 register_id, u32 value)
491 break; 492 break;
492 493
493 case ACPI_REGISTER_PM1_CONTROL: /* PM1 A/B: 16-bit access each */ 494 case ACPI_REGISTER_PM1_CONTROL: /* PM1 A/B: 16-bit access each */
494
495 /* 495 /*
496 * Perform a read first to preserve certain bits (per ACPI spec) 496 * Perform a read first to preserve certain bits (per ACPI spec)
497 * Note: This includes SCI_EN, we never want to change this bit 497 * Note: This includes SCI_EN, we never want to change this bit
@@ -520,7 +520,6 @@ acpi_status acpi_hw_register_write(u32 register_id, u32 value)
520 break; 520 break;
521 521
522 case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */ 522 case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */
523
524 /* 523 /*
525 * For control registers, all reserved bits must be preserved, 524 * For control registers, all reserved bits must be preserved,
526 * as per the ACPI spec. 525 * as per the ACPI spec.
@@ -555,6 +554,7 @@ acpi_status acpi_hw_register_write(u32 register_id, u32 value)
555 break; 554 break;
556 555
557 default: 556 default:
557
558 ACPI_ERROR((AE_INFO, "Unknown Register ID: 0x%X", register_id)); 558 ACPI_ERROR((AE_INFO, "Unknown Register ID: 0x%X", register_id));
559 status = AE_BAD_PARAMETER; 559 status = AE_BAD_PARAMETER;
560 break; 560 break;
diff --git a/drivers/acpi/acpica/hwxface.c b/drivers/acpi/acpica/hwxface.c
index 04c2e16f2c0a..5ee7a814cd92 100644
--- a/drivers/acpi/acpica/hwxface.c
+++ b/drivers/acpi/acpica/hwxface.c
@@ -495,7 +495,7 @@ acpi_get_sleep_type_data(u8 sleep_state, u8 *sleep_type_a, u8 *sleep_type_b)
495 * Evaluate the \_Sx namespace object containing the register values 495 * Evaluate the \_Sx namespace object containing the register values
496 * for this state 496 * for this state
497 */ 497 */
498 info->pathname = 498 info->relative_pathname =
499 ACPI_CAST_PTR(char, acpi_gbl_sleep_state_names[sleep_state]); 499 ACPI_CAST_PTR(char, acpi_gbl_sleep_state_names[sleep_state]);
500 status = acpi_ns_evaluate(info); 500 status = acpi_ns_evaluate(info);
501 if (ACPI_FAILURE(status)) { 501 if (ACPI_FAILURE(status)) {
@@ -506,7 +506,7 @@ acpi_get_sleep_type_data(u8 sleep_state, u8 *sleep_type_a, u8 *sleep_type_b)
506 506
507 if (!info->return_object) { 507 if (!info->return_object) {
508 ACPI_ERROR((AE_INFO, "No Sleep State object returned from [%s]", 508 ACPI_ERROR((AE_INFO, "No Sleep State object returned from [%s]",
509 info->pathname)); 509 info->relative_pathname));
510 status = AE_AML_NO_RETURN_VALUE; 510 status = AE_AML_NO_RETURN_VALUE;
511 goto cleanup; 511 goto cleanup;
512 } 512 }
@@ -528,10 +528,12 @@ acpi_get_sleep_type_data(u8 sleep_state, u8 *sleep_type_a, u8 *sleep_type_b)
528 elements = info->return_object->package.elements; 528 elements = info->return_object->package.elements;
529 switch (info->return_object->package.count) { 529 switch (info->return_object->package.count) {
530 case 0: 530 case 0:
531
531 status = AE_AML_PACKAGE_LIMIT; 532 status = AE_AML_PACKAGE_LIMIT;
532 break; 533 break;
533 534
534 case 1: 535 case 1:
536
535 if (elements[0]->common.type != ACPI_TYPE_INTEGER) { 537 if (elements[0]->common.type != ACPI_TYPE_INTEGER) {
536 status = AE_AML_OPERAND_TYPE; 538 status = AE_AML_OPERAND_TYPE;
537 break; 539 break;
@@ -545,6 +547,7 @@ acpi_get_sleep_type_data(u8 sleep_state, u8 *sleep_type_a, u8 *sleep_type_b)
545 547
546 case 2: 548 case 2:
547 default: 549 default:
550
548 if ((elements[0]->common.type != ACPI_TYPE_INTEGER) || 551 if ((elements[0]->common.type != ACPI_TYPE_INTEGER) ||
549 (elements[1]->common.type != ACPI_TYPE_INTEGER)) { 552 (elements[1]->common.type != ACPI_TYPE_INTEGER)) {
550 status = AE_AML_OPERAND_TYPE; 553 status = AE_AML_OPERAND_TYPE;
@@ -565,7 +568,7 @@ acpi_get_sleep_type_data(u8 sleep_state, u8 *sleep_type_a, u8 *sleep_type_b)
565 if (ACPI_FAILURE(status)) { 568 if (ACPI_FAILURE(status)) {
566 ACPI_EXCEPTION((AE_INFO, status, 569 ACPI_EXCEPTION((AE_INFO, status,
567 "While evaluating Sleep State [%s]", 570 "While evaluating Sleep State [%s]",
568 info->pathname)); 571 info->relative_pathname));
569 } 572 }
570 573
571 ACPI_FREE(info); 574 ACPI_FREE(info);
diff --git a/drivers/acpi/acpica/hwxfsleep.c b/drivers/acpi/acpica/hwxfsleep.c
index 35eebdac0f9d..f2e669db8b65 100644
--- a/drivers/acpi/acpica/hwxfsleep.c
+++ b/drivers/acpi/acpica/hwxfsleep.c
@@ -240,12 +240,14 @@ static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id)
240 &acpi_sleep_dispatch[function_id]; 240 &acpi_sleep_dispatch[function_id];
241 241
242#if (!ACPI_REDUCED_HARDWARE) 242#if (!ACPI_REDUCED_HARDWARE)
243
244 /* 243 /*
245 * If the Hardware Reduced flag is set (from the FADT), we must 244 * If the Hardware Reduced flag is set (from the FADT), we must
246 * use the extended sleep registers 245 * use the extended sleep registers (FADT). Note: As per the ACPI
246 * specification, these extended registers are to be used for HW-reduced
247 * platforms only. They are not general-purpose replacements for the
248 * legacy PM register sleep support.
247 */ 249 */
248 if (acpi_gbl_reduced_hardware || acpi_gbl_FADT.sleep_control.address) { 250 if (acpi_gbl_reduced_hardware) {
249 status = sleep_functions->extended_function(sleep_state); 251 status = sleep_functions->extended_function(sleep_state);
250 } else { 252 } else {
251 /* Legacy sleep */ 253 /* Legacy sleep */
@@ -314,20 +316,24 @@ acpi_status acpi_enter_sleep_state_prep(u8 sleep_state)
314 316
315 switch (sleep_state) { 317 switch (sleep_state) {
316 case ACPI_STATE_S0: 318 case ACPI_STATE_S0:
319
317 sst_value = ACPI_SST_WORKING; 320 sst_value = ACPI_SST_WORKING;
318 break; 321 break;
319 322
320 case ACPI_STATE_S1: 323 case ACPI_STATE_S1:
321 case ACPI_STATE_S2: 324 case ACPI_STATE_S2:
322 case ACPI_STATE_S3: 325 case ACPI_STATE_S3:
326
323 sst_value = ACPI_SST_SLEEPING; 327 sst_value = ACPI_SST_SLEEPING;
324 break; 328 break;
325 329
326 case ACPI_STATE_S4: 330 case ACPI_STATE_S4:
331
327 sst_value = ACPI_SST_SLEEP_CONTEXT; 332 sst_value = ACPI_SST_SLEEP_CONTEXT;
328 break; 333 break;
329 334
330 default: 335 default:
336
331 sst_value = ACPI_SST_INDICATOR_OFF; /* Default is off */ 337 sst_value = ACPI_SST_INDICATOR_OFF; /* Default is off */
332 break; 338 break;
333 } 339 }
diff --git a/drivers/acpi/acpica/nsaccess.c b/drivers/acpi/acpica/nsaccess.c
index 8769cf83b044..c5316e5bd4ab 100644
--- a/drivers/acpi/acpica/nsaccess.c
+++ b/drivers/acpi/acpica/nsaccess.c
@@ -151,6 +151,7 @@ acpi_status acpi_ns_root_initialize(void)
151 */ 151 */
152 switch (init_val->type) { 152 switch (init_val->type) {
153 case ACPI_TYPE_METHOD: 153 case ACPI_TYPE_METHOD:
154
154 obj_desc->method.param_count = 155 obj_desc->method.param_count =
155 (u8) ACPI_TO_INTEGER(val); 156 (u8) ACPI_TO_INTEGER(val);
156 obj_desc->common.flags |= AOPOBJ_DATA_VALID; 157 obj_desc->common.flags |= AOPOBJ_DATA_VALID;
diff --git a/drivers/acpi/acpica/nsarguments.c b/drivers/acpi/acpica/nsarguments.c
new file mode 100644
index 000000000000..74b24c82707e
--- /dev/null
+++ b/drivers/acpi/acpica/nsarguments.c
@@ -0,0 +1,294 @@
1/******************************************************************************
2 *
3 * Module Name: nsarguments - Validation of args for ACPI predefined methods
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2013, 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 "acnamesp.h"
47#include "acpredef.h"
48
49#define _COMPONENT ACPI_NAMESPACE
50ACPI_MODULE_NAME("nsarguments")
51
52/*******************************************************************************
53 *
54 * FUNCTION: acpi_ns_check_argument_types
55 *
56 * PARAMETERS: info - Method execution information block
57 *
58 * RETURN: None
59 *
60 * DESCRIPTION: Check the incoming argument count and all argument types
61 * against the argument type list for a predefined name.
62 *
63 ******************************************************************************/
64void acpi_ns_check_argument_types(struct acpi_evaluate_info *info)
65{
66 u16 arg_type_list;
67 u8 arg_count;
68 u8 arg_type;
69 u8 user_arg_type;
70 u32 i;
71
72 /* If not a predefined name, cannot typecheck args */
73
74 if (!info->predefined) {
75 return;
76 }
77
78 arg_type_list = info->predefined->info.argument_list;
79 arg_count = METHOD_GET_ARG_COUNT(arg_type_list);
80
81 /* Typecheck all arguments */
82
83 for (i = 0; ((i < arg_count) && (i < info->param_count)); i++) {
84 arg_type = METHOD_GET_NEXT_TYPE(arg_type_list);
85 user_arg_type = info->parameters[i]->common.type;
86
87 if (user_arg_type != arg_type) {
88 ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname,
89 ACPI_WARN_ALWAYS,
90 "Argument #%u type mismatch - "
91 "Found [%s], ACPI requires [%s]",
92 (i + 1),
93 acpi_ut_get_type_name
94 (user_arg_type),
95 acpi_ut_get_type_name(arg_type)));
96 }
97 }
98}
99
100/*******************************************************************************
101 *
102 * FUNCTION: acpi_ns_check_acpi_compliance
103 *
104 * PARAMETERS: pathname - Full pathname to the node (for error msgs)
105 * node - Namespace node for the method/object
106 * predefined - Pointer to entry in predefined name table
107 *
108 * RETURN: None
109 *
110 * DESCRIPTION: Check that the declared parameter count (in ASL/AML) for a
111 * predefined name is what is expected (matches what is defined in
112 * the ACPI specification for this predefined name.)
113 *
114 ******************************************************************************/
115
116void
117acpi_ns_check_acpi_compliance(char *pathname,
118 struct acpi_namespace_node *node,
119 const union acpi_predefined_info *predefined)
120{
121 u32 aml_param_count;
122 u32 required_param_count;
123
124 if (!predefined) {
125 return;
126 }
127
128 /* Get the ACPI-required arg count from the predefined info table */
129
130 required_param_count =
131 METHOD_GET_ARG_COUNT(predefined->info.argument_list);
132
133 /*
134 * If this object is not a control method, we can check if the ACPI
135 * spec requires that it be a method.
136 */
137 if (node->type != ACPI_TYPE_METHOD) {
138 if (required_param_count > 0) {
139
140 /* Object requires args, must be implemented as a method */
141
142 ACPI_BIOS_ERROR_PREDEFINED((AE_INFO, pathname,
143 ACPI_WARN_ALWAYS,
144 "Object (%s) must be a control method with %u arguments",
145 acpi_ut_get_type_name(node->
146 type),
147 required_param_count));
148 } else if (!required_param_count
149 && !predefined->info.expected_btypes) {
150
151 /* Object requires no args and no return value, must be a method */
152
153 ACPI_BIOS_ERROR_PREDEFINED((AE_INFO, pathname,
154 ACPI_WARN_ALWAYS,
155 "Object (%s) must be a control method "
156 "with no arguments and no return value",
157 acpi_ut_get_type_name(node->
158 type)));
159 }
160
161 return;
162 }
163
164 /*
165 * This is a control method.
166 * Check that the ASL/AML-defined parameter count for this method
167 * matches the ACPI-required parameter count
168 *
169 * Some methods are allowed to have a "minimum" number of args (_SCP)
170 * because their definition in ACPI has changed over time.
171 *
172 * Note: These are BIOS errors in the declaration of the object
173 */
174 aml_param_count = node->object->method.param_count;
175
176 if (aml_param_count < required_param_count) {
177 ACPI_BIOS_ERROR_PREDEFINED((AE_INFO, pathname, ACPI_WARN_ALWAYS,
178 "Insufficient arguments - "
179 "ASL declared %u, ACPI requires %u",
180 aml_param_count,
181 required_param_count));
182 } else if ((aml_param_count > required_param_count)
183 && !(predefined->info.
184 argument_list & ARG_COUNT_IS_MINIMUM)) {
185 ACPI_BIOS_ERROR_PREDEFINED((AE_INFO, pathname, ACPI_WARN_ALWAYS,
186 "Excess arguments - "
187 "ASL declared %u, ACPI requires %u",
188 aml_param_count,
189 required_param_count));
190 }
191}
192
193/*******************************************************************************
194 *
195 * FUNCTION: acpi_ns_check_argument_count
196 *
197 * PARAMETERS: pathname - Full pathname to the node (for error msgs)
198 * node - Namespace node for the method/object
199 * user_param_count - Number of args passed in by the caller
200 * predefined - Pointer to entry in predefined name table
201 *
202 * RETURN: None
203 *
204 * DESCRIPTION: Check that incoming argument count matches the declared
205 * parameter count (in the ASL/AML) for an object.
206 *
207 ******************************************************************************/
208
209void
210acpi_ns_check_argument_count(char *pathname,
211 struct acpi_namespace_node *node,
212 u32 user_param_count,
213 const union acpi_predefined_info *predefined)
214{
215 u32 aml_param_count;
216 u32 required_param_count;
217
218 if (!predefined) {
219 /*
220 * Not a predefined name. Check the incoming user argument count
221 * against the count that is specified in the method/object.
222 */
223 if (node->type != ACPI_TYPE_METHOD) {
224 if (user_param_count) {
225 ACPI_INFO_PREDEFINED((AE_INFO, pathname,
226 ACPI_WARN_ALWAYS,
227 "%u arguments were passed to a non-method ACPI object (%s)",
228 user_param_count,
229 acpi_ut_get_type_name
230 (node->type)));
231 }
232
233 return;
234 }
235
236 /*
237 * This is a control method. Check the parameter count.
238 * We can only check the incoming argument count against the
239 * argument count declared for the method in the ASL/AML.
240 *
241 * Emit a message if too few or too many arguments have been passed
242 * by the caller.
243 *
244 * Note: Too many arguments will not cause the method to
245 * fail. However, the method will fail if there are too few
246 * arguments and the method attempts to use one of the missing ones.
247 */
248 aml_param_count = node->object->method.param_count;
249
250 if (user_param_count < aml_param_count) {
251 ACPI_WARN_PREDEFINED((AE_INFO, pathname,
252 ACPI_WARN_ALWAYS,
253 "Insufficient arguments - "
254 "Caller passed %u, method requires %u",
255 user_param_count,
256 aml_param_count));
257 } else if (user_param_count > aml_param_count) {
258 ACPI_INFO_PREDEFINED((AE_INFO, pathname,
259 ACPI_WARN_ALWAYS,
260 "Excess arguments - "
261 "Caller passed %u, method requires %u",
262 user_param_count,
263 aml_param_count));
264 }
265
266 return;
267 }
268
269 /*
270 * This is a predefined name. Validate the user-supplied parameter
271 * count against the ACPI specification. We don't validate against
272 * the method itself because what is important here is that the
273 * caller is in conformance with the spec. (The arg count for the
274 * method was checked against the ACPI spec earlier.)
275 *
276 * Some methods are allowed to have a "minimum" number of args (_SCP)
277 * because their definition in ACPI has changed over time.
278 */
279 required_param_count =
280 METHOD_GET_ARG_COUNT(predefined->info.argument_list);
281
282 if (user_param_count < required_param_count) {
283 ACPI_WARN_PREDEFINED((AE_INFO, pathname, ACPI_WARN_ALWAYS,
284 "Insufficient arguments - "
285 "Caller passed %u, ACPI requires %u",
286 user_param_count, required_param_count));
287 } else if ((user_param_count > required_param_count) &&
288 !(predefined->info.argument_list & ARG_COUNT_IS_MINIMUM)) {
289 ACPI_INFO_PREDEFINED((AE_INFO, pathname, ACPI_WARN_ALWAYS,
290 "Excess arguments - "
291 "Caller passed %u, ACPI requires %u",
292 user_param_count, required_param_count));
293 }
294}
diff --git a/drivers/acpi/acpica/nsconvert.c b/drivers/acpi/acpica/nsconvert.c
index 8f79a9d2d50e..acd2964c2690 100644
--- a/drivers/acpi/acpica/nsconvert.c
+++ b/drivers/acpi/acpica/nsconvert.c
@@ -103,6 +103,7 @@ acpi_ns_convert_to_integer(union acpi_operand_object *original_object,
103 break; 103 break;
104 104
105 default: 105 default:
106
106 return (AE_AML_OPERAND_TYPE); 107 return (AE_AML_OPERAND_TYPE);
107 } 108 }
108 109
@@ -191,6 +192,7 @@ acpi_ns_convert_to_string(union acpi_operand_object *original_object,
191 break; 192 break;
192 193
193 default: 194 default:
195
194 return (AE_AML_OPERAND_TYPE); 196 return (AE_AML_OPERAND_TYPE);
195 } 197 }
196 198
@@ -294,6 +296,7 @@ acpi_ns_convert_to_buffer(union acpi_operand_object *original_object,
294 break; 296 break;
295 297
296 default: 298 default:
299
297 return (AE_AML_OPERAND_TYPE); 300 return (AE_AML_OPERAND_TYPE);
298 } 301 }
299 302
diff --git a/drivers/acpi/acpica/nsdump.c b/drivers/acpi/acpica/nsdump.c
index ce6e97326205..7418c77fde8c 100644
--- a/drivers/acpi/acpica/nsdump.c
+++ b/drivers/acpi/acpica/nsdump.c
@@ -244,10 +244,12 @@ acpi_ns_dump_one_object(acpi_handle obj_handle,
244 case ACPI_TYPE_BUFFER: 244 case ACPI_TYPE_BUFFER:
245 case ACPI_TYPE_STRING: 245 case ACPI_TYPE_STRING:
246 case ACPI_TYPE_METHOD: 246 case ACPI_TYPE_METHOD:
247
247 acpi_os_printf("<No attached object>"); 248 acpi_os_printf("<No attached object>");
248 break; 249 break;
249 250
250 default: 251 default:
252
251 break; 253 break;
252 } 254 }
253 255
@@ -433,6 +435,7 @@ acpi_ns_dump_one_object(acpi_handle obj_handle,
433 break; 435 break;
434 436
435 default: 437 default:
438
436 break; 439 break;
437 } 440 }
438 break; 441 break;
@@ -567,32 +570,39 @@ acpi_ns_dump_one_object(acpi_handle obj_handle,
567 goto cleanup; 570 goto cleanup;
568 571
569 case ACPI_TYPE_BUFFER_FIELD: 572 case ACPI_TYPE_BUFFER_FIELD:
573
570 obj_desc = 574 obj_desc =
571 (union acpi_operand_object *)obj_desc->buffer_field. 575 (union acpi_operand_object *)obj_desc->buffer_field.
572 buffer_obj; 576 buffer_obj;
573 break; 577 break;
574 578
575 case ACPI_TYPE_PACKAGE: 579 case ACPI_TYPE_PACKAGE:
580
576 obj_desc = (void *)obj_desc->package.elements; 581 obj_desc = (void *)obj_desc->package.elements;
577 break; 582 break;
578 583
579 case ACPI_TYPE_METHOD: 584 case ACPI_TYPE_METHOD:
585
580 obj_desc = (void *)obj_desc->method.aml_start; 586 obj_desc = (void *)obj_desc->method.aml_start;
581 break; 587 break;
582 588
583 case ACPI_TYPE_LOCAL_REGION_FIELD: 589 case ACPI_TYPE_LOCAL_REGION_FIELD:
590
584 obj_desc = (void *)obj_desc->field.region_obj; 591 obj_desc = (void *)obj_desc->field.region_obj;
585 break; 592 break;
586 593
587 case ACPI_TYPE_LOCAL_BANK_FIELD: 594 case ACPI_TYPE_LOCAL_BANK_FIELD:
595
588 obj_desc = (void *)obj_desc->bank_field.region_obj; 596 obj_desc = (void *)obj_desc->bank_field.region_obj;
589 break; 597 break;
590 598
591 case ACPI_TYPE_LOCAL_INDEX_FIELD: 599 case ACPI_TYPE_LOCAL_INDEX_FIELD:
600
592 obj_desc = (void *)obj_desc->index_field.index_obj; 601 obj_desc = (void *)obj_desc->index_field.index_obj;
593 break; 602 break;
594 603
595 default: 604 default:
605
596 goto cleanup; 606 goto cleanup;
597 } 607 }
598 608
diff --git a/drivers/acpi/acpica/nseval.c b/drivers/acpi/acpica/nseval.c
index b61db69d5675..18108bc2e51c 100644
--- a/drivers/acpi/acpica/nseval.c
+++ b/drivers/acpi/acpica/nseval.c
@@ -61,7 +61,7 @@ acpi_ns_exec_module_code(union acpi_operand_object *method_obj,
61 * 61 *
62 * PARAMETERS: info - Evaluation info block, contains: 62 * PARAMETERS: info - Evaluation info block, contains:
63 * prefix_node - Prefix or Method/Object Node to execute 63 * prefix_node - Prefix or Method/Object Node to execute
64 * pathname - Name of method to execute, If NULL, the 64 * relative_path - Name of method to execute, If NULL, the
65 * Node is the object to execute 65 * Node is the object to execute
66 * parameters - List of parameters to pass to the method, 66 * parameters - List of parameters to pass to the method,
67 * terminated by NULL. Params itself may be 67 * terminated by NULL. Params itself may be
@@ -82,10 +82,9 @@ acpi_ns_exec_module_code(union acpi_operand_object *method_obj,
82 * 82 *
83 ******************************************************************************/ 83 ******************************************************************************/
84 84
85acpi_status acpi_ns_evaluate(struct acpi_evaluate_info * info) 85acpi_status acpi_ns_evaluate(struct acpi_evaluate_info *info)
86{ 86{
87 acpi_status status; 87 acpi_status status;
88 struct acpi_namespace_node *node;
89 88
90 ACPI_FUNCTION_TRACE(ns_evaluate); 89 ACPI_FUNCTION_TRACE(ns_evaluate);
91 90
@@ -93,83 +92,138 @@ acpi_status acpi_ns_evaluate(struct acpi_evaluate_info * info)
93 return_ACPI_STATUS(AE_BAD_PARAMETER); 92 return_ACPI_STATUS(AE_BAD_PARAMETER);
94 } 93 }
95 94
96 /* Initialize the return value to an invalid object */ 95 if (!info->node) {
97
98 info->return_object = NULL;
99 info->param_count = 0;
100
101 if (!info->resolved_node) {
102 /* 96 /*
103 * Get the actual namespace node for the target object if we need to. 97 * Get the actual namespace node for the target object if we
104 * Handles these cases: 98 * need to. Handles these cases:
105 * 99 *
106 * 1) Null node, Pathname (absolute path) 100 * 1) Null node, valid pathname from root (absolute path)
107 * 2) Node, Pathname (path relative to Node) 101 * 2) Node and valid pathname (path relative to Node)
108 * 3) Node, Null Pathname 102 * 3) Node, Null pathname
109 */ 103 */
110 status = acpi_ns_get_node(info->prefix_node, info->pathname, 104 status =
111 ACPI_NS_NO_UPSEARCH, 105 acpi_ns_get_node(info->prefix_node, info->relative_pathname,
112 &info->resolved_node); 106 ACPI_NS_NO_UPSEARCH, &info->node);
113 if (ACPI_FAILURE(status)) { 107 if (ACPI_FAILURE(status)) {
114 return_ACPI_STATUS(status); 108 return_ACPI_STATUS(status);
115 } 109 }
116 } 110 }
117 111
118 /* 112 /*
119 * For a method alias, we must grab the actual method node so that proper 113 * For a method alias, we must grab the actual method node so that
120 * scoping context will be established before execution. 114 * proper scoping context will be established before execution.
121 */ 115 */
122 if (acpi_ns_get_type(info->resolved_node) == 116 if (acpi_ns_get_type(info->node) == ACPI_TYPE_LOCAL_METHOD_ALIAS) {
123 ACPI_TYPE_LOCAL_METHOD_ALIAS) { 117 info->node =
124 info->resolved_node =
125 ACPI_CAST_PTR(struct acpi_namespace_node, 118 ACPI_CAST_PTR(struct acpi_namespace_node,
126 info->resolved_node->object); 119 info->node->object);
120 }
121
122 /* Complete the info block initialization */
123
124 info->return_object = NULL;
125 info->node_flags = info->node->flags;
126 info->obj_desc = acpi_ns_get_attached_object(info->node);
127
128 ACPI_DEBUG_PRINT((ACPI_DB_NAMES, "%s [%p] Value %p\n",
129 info->relative_pathname, info->node,
130 acpi_ns_get_attached_object(info->node)));
131
132 /* Get info if we have a predefined name (_HID, etc.) */
133
134 info->predefined =
135 acpi_ut_match_predefined_method(info->node->name.ascii);
136
137 /* Get the full pathname to the object, for use in warning messages */
138
139 info->full_pathname = acpi_ns_get_external_pathname(info->node);
140 if (!info->full_pathname) {
141 return_ACPI_STATUS(AE_NO_MEMORY);
127 } 142 }
128 143
129 ACPI_DEBUG_PRINT((ACPI_DB_NAMES, "%s [%p] Value %p\n", info->pathname, 144 /* Count the number of arguments being passed in */
130 info->resolved_node, 145
131 acpi_ns_get_attached_object(info->resolved_node))); 146 info->param_count = 0;
147 if (info->parameters) {
148 while (info->parameters[info->param_count]) {
149 info->param_count++;
150 }
151
152 /* Warn on impossible argument count */
153
154 if (info->param_count > ACPI_METHOD_NUM_ARGS) {
155 ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname,
156 ACPI_WARN_ALWAYS,
157 "Excess arguments (%u) - using only %u",
158 info->param_count,
159 ACPI_METHOD_NUM_ARGS));
160
161 info->param_count = ACPI_METHOD_NUM_ARGS;
162 }
163 }
164
165 /*
166 * For predefined names: Check that the declared argument count
167 * matches the ACPI spec -- otherwise this is a BIOS error.
168 */
169 acpi_ns_check_acpi_compliance(info->full_pathname, info->node,
170 info->predefined);
171
172 /*
173 * For all names: Check that the incoming argument count for
174 * this method/object matches the actual ASL/AML definition.
175 */
176 acpi_ns_check_argument_count(info->full_pathname, info->node,
177 info->param_count, info->predefined);
132 178
133 node = info->resolved_node; 179 /* For predefined names: Typecheck all incoming arguments */
180
181 acpi_ns_check_argument_types(info);
134 182
135 /* 183 /*
136 * Two major cases here: 184 * Three major evaluation cases:
137 * 185 *
138 * 1) The object is a control method -- execute it 186 * 1) Object types that cannot be evaluated by definition
139 * 2) The object is not a method -- just return it's current value 187 * 2) The object is a control method -- execute it
188 * 3) The object is not a method -- just return it's current value
140 */ 189 */
141 if (acpi_ns_get_type(info->resolved_node) == ACPI_TYPE_METHOD) { 190 switch (acpi_ns_get_type(info->node)) {
191 case ACPI_TYPE_DEVICE:
192 case ACPI_TYPE_EVENT:
193 case ACPI_TYPE_MUTEX:
194 case ACPI_TYPE_REGION:
195 case ACPI_TYPE_THERMAL:
196 case ACPI_TYPE_LOCAL_SCOPE:
197 /*
198 * 1) Disallow evaluation of certain object types. For these,
199 * object evaluation is undefined and not supported.
200 */
201 ACPI_ERROR((AE_INFO,
202 "%s: Evaluation of object type [%s] is not supported",
203 info->full_pathname,
204 acpi_ut_get_type_name(info->node->type)));
205
206 status = AE_TYPE;
207 goto cleanup;
208
209 case ACPI_TYPE_METHOD:
142 /* 210 /*
143 * 1) Object is a control method - execute it 211 * 2) Object is a control method - execute it
144 */ 212 */
145 213
146 /* Verify that there is a method object associated with this node */ 214 /* Verify that there is a method object associated with this node */
147 215
148 info->obj_desc =
149 acpi_ns_get_attached_object(info->resolved_node);
150 if (!info->obj_desc) { 216 if (!info->obj_desc) {
151 ACPI_ERROR((AE_INFO, 217 ACPI_ERROR((AE_INFO,
152 "Control method has no attached sub-object")); 218 "%s: Method has no attached sub-object",
153 return_ACPI_STATUS(AE_NULL_OBJECT); 219 info->full_pathname));
220 status = AE_NULL_OBJECT;
221 goto cleanup;
154 } 222 }
155 223
156 /* Count the number of arguments being passed to the method */
157
158 if (info->parameters) {
159 while (info->parameters[info->param_count]) {
160 if (info->param_count > ACPI_METHOD_MAX_ARG) {
161 return_ACPI_STATUS(AE_LIMIT);
162 }
163 info->param_count++;
164 }
165 }
166
167
168 ACPI_DUMP_PATHNAME(info->resolved_node, "ACPI: Execute Method",
169 ACPI_LV_INFO, _COMPONENT);
170
171 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, 224 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
172 "Method at AML address %p Length %X\n", 225 "**** Execute method [%s] at AML address %p length %X\n",
226 info->full_pathname,
173 info->obj_desc->method.aml_start + 1, 227 info->obj_desc->method.aml_start + 1,
174 info->obj_desc->method.aml_length - 1)); 228 info->obj_desc->method.aml_length - 1));
175 229
@@ -184,81 +238,61 @@ acpi_status acpi_ns_evaluate(struct acpi_evaluate_info * info)
184 acpi_ex_enter_interpreter(); 238 acpi_ex_enter_interpreter();
185 status = acpi_ps_execute_method(info); 239 status = acpi_ps_execute_method(info);
186 acpi_ex_exit_interpreter(); 240 acpi_ex_exit_interpreter();
187 } else { 241 break;
242
243 default:
188 /* 244 /*
189 * 2) Object is not a method, return its current value 245 * 3) All other non-method objects -- get the current object value
190 *
191 * Disallow certain object types. For these, "evaluation" is undefined.
192 */ 246 */
193 switch (info->resolved_node->type) {
194 case ACPI_TYPE_DEVICE:
195 case ACPI_TYPE_EVENT:
196 case ACPI_TYPE_MUTEX:
197 case ACPI_TYPE_REGION:
198 case ACPI_TYPE_THERMAL:
199 case ACPI_TYPE_LOCAL_SCOPE:
200
201 ACPI_ERROR((AE_INFO,
202 "[%4.4s] Evaluation of object type [%s] is not supported",
203 info->resolved_node->name.ascii,
204 acpi_ut_get_type_name(info->resolved_node->
205 type)));
206
207 return_ACPI_STATUS(AE_TYPE);
208
209 default:
210 break;
211 }
212 247
213 /* 248 /*
214 * Objects require additional resolution steps (e.g., the Node may be 249 * Some objects require additional resolution steps (e.g., the Node
215 * a field that must be read, etc.) -- we can't just grab the object 250 * may be a field that must be read, etc.) -- we can't just grab
216 * out of the node. 251 * the object out of the node.
217 * 252 *
218 * Use resolve_node_to_value() to get the associated value. 253 * Use resolve_node_to_value() to get the associated value.
219 * 254 *
220 * NOTE: we can get away with passing in NULL for a walk state because 255 * NOTE: we can get away with passing in NULL for a walk state because
221 * resolved_node is guaranteed to not be a reference to either a method 256 * the Node is guaranteed to not be a reference to either a method
222 * local or a method argument (because this interface is never called 257 * local or a method argument (because this interface is never called
223 * from a running method.) 258 * from a running method.)
224 * 259 *
225 * Even though we do not directly invoke the interpreter for object 260 * Even though we do not directly invoke the interpreter for object
226 * resolution, we must lock it because we could access an opregion. 261 * resolution, we must lock it because we could access an op_region.
227 * The opregion access code assumes that the interpreter is locked. 262 * The op_region access code assumes that the interpreter is locked.
228 */ 263 */
229 acpi_ex_enter_interpreter(); 264 acpi_ex_enter_interpreter();
230 265
231 /* Function has a strange interface */ 266 /* TBD: resolve_node_to_value has a strange interface, fix */
267
268 info->return_object =
269 ACPI_CAST_PTR(union acpi_operand_object, info->node);
232 270
233 status = 271 status =
234 acpi_ex_resolve_node_to_value(&info->resolved_node, NULL); 272 acpi_ex_resolve_node_to_value(ACPI_CAST_INDIRECT_PTR
273 (struct acpi_namespace_node,
274 &info->return_object), NULL);
235 acpi_ex_exit_interpreter(); 275 acpi_ex_exit_interpreter();
236 276
237 /* 277 if (ACPI_FAILURE(status)) {
238 * If acpi_ex_resolve_node_to_value() succeeded, the return value was placed 278 goto cleanup;
239 * in resolved_node.
240 */
241 if (ACPI_SUCCESS(status)) {
242 status = AE_CTRL_RETURN_VALUE;
243 info->return_object =
244 ACPI_CAST_PTR(union acpi_operand_object,
245 info->resolved_node);
246
247 ACPI_DEBUG_PRINT((ACPI_DB_NAMES,
248 "Returning object %p [%s]\n",
249 info->return_object,
250 acpi_ut_get_object_type_name(info->
251 return_object)));
252 } 279 }
280
281 ACPI_DEBUG_PRINT((ACPI_DB_NAMES, "Returned object %p [%s]\n",
282 info->return_object,
283 acpi_ut_get_object_type_name(info->
284 return_object)));
285
286 status = AE_CTRL_RETURN_VALUE; /* Always has a "return value" */
287 break;
253 } 288 }
254 289
255 /* 290 /*
256 * Check input argument count against the ASL-defined count for a method. 291 * For predefined names, check the return value against the ACPI
257 * Also check predefined names: argument count and return value against 292 * specification. Some incorrect return value types are repaired.
258 * the ACPI specification. Some incorrect return value types are repaired.
259 */ 293 */
260 (void)acpi_ns_check_predefined_names(node, info->param_count, 294 (void)acpi_ns_check_return_value(info->node, info, info->param_count,
261 status, &info->return_object); 295 status, &info->return_object);
262 296
263 /* Check if there is a return value that must be dealt with */ 297 /* Check if there is a return value that must be dealt with */
264 298
@@ -278,12 +312,15 @@ acpi_status acpi_ns_evaluate(struct acpi_evaluate_info * info)
278 312
279 ACPI_DEBUG_PRINT((ACPI_DB_NAMES, 313 ACPI_DEBUG_PRINT((ACPI_DB_NAMES,
280 "*** Completed evaluation of object %s ***\n", 314 "*** Completed evaluation of object %s ***\n",
281 info->pathname)); 315 info->relative_pathname));
282 316
317 cleanup:
283 /* 318 /*
284 * Namespace was unlocked by the handling acpi_ns* function, so we 319 * Namespace was unlocked by the handling acpi_ns* function, so we
285 * just return 320 * just free the pathname and return
286 */ 321 */
322 ACPI_FREE(info->full_pathname);
323 info->full_pathname = NULL;
287 return_ACPI_STATUS(status); 324 return_ACPI_STATUS(status);
288} 325}
289 326
diff --git a/drivers/acpi/acpica/nsinit.c b/drivers/acpi/acpica/nsinit.c
index 46f0f83417a1..dd2ceae3f717 100644
--- a/drivers/acpi/acpica/nsinit.c
+++ b/drivers/acpi/acpica/nsinit.c
@@ -176,7 +176,7 @@ acpi_status acpi_ns_initialize_devices(void)
176 * part of the ACPI specification. 176 * part of the ACPI specification.
177 */ 177 */
178 info.evaluate_info->prefix_node = acpi_gbl_root_node; 178 info.evaluate_info->prefix_node = acpi_gbl_root_node;
179 info.evaluate_info->pathname = METHOD_NAME__INI; 179 info.evaluate_info->relative_pathname = METHOD_NAME__INI;
180 info.evaluate_info->parameters = NULL; 180 info.evaluate_info->parameters = NULL;
181 info.evaluate_info->flags = ACPI_IGNORE_RETURN_VALUE; 181 info.evaluate_info->flags = ACPI_IGNORE_RETURN_VALUE;
182 182
@@ -266,28 +266,34 @@ acpi_ns_init_one_object(acpi_handle obj_handle,
266 266
267 switch (type) { 267 switch (type) {
268 case ACPI_TYPE_REGION: 268 case ACPI_TYPE_REGION:
269
269 info->op_region_count++; 270 info->op_region_count++;
270 break; 271 break;
271 272
272 case ACPI_TYPE_BUFFER_FIELD: 273 case ACPI_TYPE_BUFFER_FIELD:
274
273 info->field_count++; 275 info->field_count++;
274 break; 276 break;
275 277
276 case ACPI_TYPE_LOCAL_BANK_FIELD: 278 case ACPI_TYPE_LOCAL_BANK_FIELD:
279
277 info->field_count++; 280 info->field_count++;
278 break; 281 break;
279 282
280 case ACPI_TYPE_BUFFER: 283 case ACPI_TYPE_BUFFER:
284
281 info->buffer_count++; 285 info->buffer_count++;
282 break; 286 break;
283 287
284 case ACPI_TYPE_PACKAGE: 288 case ACPI_TYPE_PACKAGE:
289
285 info->package_count++; 290 info->package_count++;
286 break; 291 break;
287 292
288 default: 293 default:
289 294
290 /* No init required, just exit now */ 295 /* No init required, just exit now */
296
291 return (AE_OK); 297 return (AE_OK);
292 } 298 }
293 299
@@ -337,7 +343,9 @@ acpi_ns_init_one_object(acpi_handle obj_handle,
337 break; 343 break;
338 344
339 default: 345 default:
346
340 /* No other types can get here */ 347 /* No other types can get here */
348
341 break; 349 break;
342 } 350 }
343 351
@@ -416,6 +424,7 @@ acpi_ns_find_ini_methods(acpi_handle obj_handle,
416 break; 424 break;
417 425
418 default: 426 default:
427
419 break; 428 break;
420 } 429 }
421 430
@@ -560,7 +569,7 @@ acpi_ns_init_one_device(acpi_handle obj_handle,
560 569
561 ACPI_MEMSET(info, 0, sizeof(struct acpi_evaluate_info)); 570 ACPI_MEMSET(info, 0, sizeof(struct acpi_evaluate_info));
562 info->prefix_node = device_node; 571 info->prefix_node = device_node;
563 info->pathname = METHOD_NAME__INI; 572 info->relative_pathname = METHOD_NAME__INI;
564 info->parameters = NULL; 573 info->parameters = NULL;
565 info->flags = ACPI_IGNORE_RETURN_VALUE; 574 info->flags = ACPI_IGNORE_RETURN_VALUE;
566 575
@@ -574,8 +583,7 @@ acpi_ns_init_one_device(acpi_handle obj_handle,
574 583
575 /* Ignore error and move on to next device */ 584 /* Ignore error and move on to next device */
576 585
577 char *scope_name = 586 char *scope_name = acpi_ns_get_external_pathname(info->node);
578 acpi_ns_get_external_pathname(info->resolved_node);
579 587
580 ACPI_EXCEPTION((AE_INFO, status, "during %s._INI execution", 588 ACPI_EXCEPTION((AE_INFO, status, "during %s._INI execution",
581 scope_name)); 589 scope_name));
diff --git a/drivers/acpi/acpica/nspredef.c b/drivers/acpi/acpica/nspredef.c
index 8a52916148cb..24b71a01bf93 100644
--- a/drivers/acpi/acpica/nspredef.c
+++ b/drivers/acpi/acpica/nspredef.c
@@ -61,28 +61,29 @@ ACPI_MODULE_NAME("nspredef")
61 * There are several areas that are validated: 61 * There are several areas that are validated:
62 * 62 *
63 * 1) The number of input arguments as defined by the method/object in the 63 * 1) The number of input arguments as defined by the method/object in the
64 * ASL is validated against the ACPI specification. 64 * ASL is validated against the ACPI specification.
65 * 2) The type of the return object (if any) is validated against the ACPI 65 * 2) The type of the return object (if any) is validated against the ACPI
66 * specification. 66 * specification.
67 * 3) For returned package objects, the count of package elements is 67 * 3) For returned package objects, the count of package elements is
68 * validated, as well as the type of each package element. Nested 68 * validated, as well as the type of each package element. Nested
69 * packages are supported. 69 * packages are supported.
70 * 70 *
71 * For any problems found, a warning message is issued. 71 * For any problems found, a warning message is issued.
72 * 72 *
73 ******************************************************************************/ 73 ******************************************************************************/
74/* Local prototypes */ 74/* Local prototypes */
75static acpi_status 75static acpi_status
76acpi_ns_check_reference(struct acpi_predefined_data *data, 76acpi_ns_check_reference(struct acpi_evaluate_info *info,
77 union acpi_operand_object *return_object); 77 union acpi_operand_object *return_object);
78 78
79static u32 acpi_ns_get_bitmapped_type(union acpi_operand_object *return_object); 79static u32 acpi_ns_get_bitmapped_type(union acpi_operand_object *return_object);
80 80
81/******************************************************************************* 81/*******************************************************************************
82 * 82 *
83 * FUNCTION: acpi_ns_check_predefined_names 83 * FUNCTION: acpi_ns_check_return_value
84 * 84 *
85 * PARAMETERS: node - Namespace node for the method/object 85 * PARAMETERS: node - Namespace node for the method/object
86 * info - Method execution information block
86 * user_param_count - Number of parameters actually passed 87 * user_param_count - Number of parameters actually passed
87 * return_status - Status from the object evaluation 88 * return_status - Status from the object evaluation
88 * return_object_ptr - Pointer to the object returned from the 89 * return_object_ptr - Pointer to the object returned from the
@@ -90,44 +91,25 @@ static u32 acpi_ns_get_bitmapped_type(union acpi_operand_object *return_object);
90 * 91 *
91 * RETURN: Status 92 * RETURN: Status
92 * 93 *
93 * DESCRIPTION: Check an ACPI name for a match in the predefined name list. 94 * DESCRIPTION: Check the value returned from a predefined name.
94 * 95 *
95 ******************************************************************************/ 96 ******************************************************************************/
96 97
97acpi_status 98acpi_status
98acpi_ns_check_predefined_names(struct acpi_namespace_node *node, 99acpi_ns_check_return_value(struct acpi_namespace_node *node,
99 u32 user_param_count, 100 struct acpi_evaluate_info *info,
100 acpi_status return_status, 101 u32 user_param_count,
101 union acpi_operand_object **return_object_ptr) 102 acpi_status return_status,
103 union acpi_operand_object **return_object_ptr)
102{ 104{
103 acpi_status status = AE_OK; 105 acpi_status status;
104 const union acpi_predefined_info *predefined; 106 const union acpi_predefined_info *predefined;
105 char *pathname;
106 struct acpi_predefined_data *data;
107
108 /* Match the name for this method/object against the predefined list */
109
110 predefined = acpi_ut_match_predefined_method(node->name.ascii);
111
112 /* Get the full pathname to the object, for use in warning messages */
113
114 pathname = acpi_ns_get_external_pathname(node);
115 if (!pathname) {
116 return (AE_OK); /* Could not get pathname, ignore */
117 }
118
119 /*
120 * Check that the parameter count for this method matches the ASL
121 * definition. For predefined names, ensure that both the caller and
122 * the method itself are in accordance with the ACPI specification.
123 */
124 acpi_ns_check_parameter_count(pathname, node, user_param_count,
125 predefined);
126 107
127 /* If not a predefined name, we cannot validate the return object */ 108 /* If not a predefined name, we cannot validate the return object */
128 109
110 predefined = info->predefined;
129 if (!predefined) { 111 if (!predefined) {
130 goto cleanup; 112 return (AE_OK);
131 } 113 }
132 114
133 /* 115 /*
@@ -135,7 +117,7 @@ acpi_ns_check_predefined_names(struct acpi_namespace_node *node,
135 * validate the return object 117 * validate the return object
136 */ 118 */
137 if ((return_status != AE_OK) && (return_status != AE_CTRL_RETURN_VALUE)) { 119 if ((return_status != AE_OK) && (return_status != AE_CTRL_RETURN_VALUE)) {
138 goto cleanup; 120 return (AE_OK);
139 } 121 }
140 122
141 /* 123 /*
@@ -154,25 +136,14 @@ acpi_ns_check_predefined_names(struct acpi_namespace_node *node,
154 if (acpi_gbl_disable_auto_repair || 136 if (acpi_gbl_disable_auto_repair ||
155 (!predefined->info.expected_btypes) || 137 (!predefined->info.expected_btypes) ||
156 (predefined->info.expected_btypes == ACPI_RTYPE_ALL)) { 138 (predefined->info.expected_btypes == ACPI_RTYPE_ALL)) {
157 goto cleanup; 139 return (AE_OK);
158 }
159
160 /* Create the parameter data block for object validation */
161
162 data = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_predefined_data));
163 if (!data) {
164 goto cleanup;
165 } 140 }
166 data->predefined = predefined;
167 data->node = node;
168 data->node_flags = node->flags;
169 data->pathname = pathname;
170 141
171 /* 142 /*
172 * Check that the type of the main return object is what is expected 143 * Check that the type of the main return object is what is expected
173 * for this predefined name 144 * for this predefined name
174 */ 145 */
175 status = acpi_ns_check_object_type(data, return_object_ptr, 146 status = acpi_ns_check_object_type(info, return_object_ptr,
176 predefined->info.expected_btypes, 147 predefined->info.expected_btypes,
177 ACPI_NOT_PACKAGE_ELEMENT); 148 ACPI_NOT_PACKAGE_ELEMENT);
178 if (ACPI_FAILURE(status)) { 149 if (ACPI_FAILURE(status)) {
@@ -184,10 +155,16 @@ acpi_ns_check_predefined_names(struct acpi_namespace_node *node,
184 * Note: Package may have been newly created by call above. 155 * Note: Package may have been newly created by call above.
185 */ 156 */
186 if ((*return_object_ptr)->common.type == ACPI_TYPE_PACKAGE) { 157 if ((*return_object_ptr)->common.type == ACPI_TYPE_PACKAGE) {
187 data->parent_package = *return_object_ptr; 158 info->parent_package = *return_object_ptr;
188 status = acpi_ns_check_package(data, return_object_ptr); 159 status = acpi_ns_check_package(info, return_object_ptr);
189 if (ACPI_FAILURE(status)) { 160 if (ACPI_FAILURE(status)) {
190 goto exit; 161
162 /* We might be able to fix some errors */
163
164 if ((status != AE_AML_OPERAND_TYPE) &&
165 (status != AE_AML_OPERAND_VALUE)) {
166 goto exit;
167 }
191 } 168 }
192 } 169 }
193 170
@@ -199,7 +176,7 @@ acpi_ns_check_predefined_names(struct acpi_namespace_node *node,
199 * performed on a per-name basis, i.e., the code is specific to 176 * performed on a per-name basis, i.e., the code is specific to
200 * particular predefined names. 177 * particular predefined names.
201 */ 178 */
202 status = acpi_ns_complex_repairs(data, node, status, return_object_ptr); 179 status = acpi_ns_complex_repairs(info, node, status, return_object_ptr);
203 180
204exit: 181exit:
205 /* 182 /*
@@ -207,112 +184,18 @@ exit:
207 * or more objects, mark the parent node to suppress further warning 184 * or more objects, mark the parent node to suppress further warning
208 * messages during the next evaluation of the same method/object. 185 * messages during the next evaluation of the same method/object.
209 */ 186 */
210 if (ACPI_FAILURE(status) || (data->flags & ACPI_OBJECT_REPAIRED)) { 187 if (ACPI_FAILURE(status) || (info->return_flags & ACPI_OBJECT_REPAIRED)) {
211 node->flags |= ANOBJ_EVALUATED; 188 node->flags |= ANOBJ_EVALUATED;
212 } 189 }
213 ACPI_FREE(data);
214 190
215cleanup:
216 ACPI_FREE(pathname);
217 return (status); 191 return (status);
218} 192}
219 193
220/******************************************************************************* 194/*******************************************************************************
221 * 195 *
222 * FUNCTION: acpi_ns_check_parameter_count
223 *
224 * PARAMETERS: pathname - Full pathname to the node (for error msgs)
225 * node - Namespace node for the method/object
226 * user_param_count - Number of args passed in by the caller
227 * predefined - Pointer to entry in predefined name table
228 *
229 * RETURN: None
230 *
231 * DESCRIPTION: Check that the declared (in ASL/AML) parameter count for a
232 * predefined name is what is expected (i.e., what is defined in
233 * the ACPI specification for this predefined name.)
234 *
235 ******************************************************************************/
236
237void
238acpi_ns_check_parameter_count(char *pathname,
239 struct acpi_namespace_node *node,
240 u32 user_param_count,
241 const union acpi_predefined_info *predefined)
242{
243 u32 param_count;
244 u32 required_params_current;
245 u32 required_params_old;
246
247 /* Methods have 0-7 parameters. All other types have zero. */
248
249 param_count = 0;
250 if (node->type == ACPI_TYPE_METHOD) {
251 param_count = node->object->method.param_count;
252 }
253
254 if (!predefined) {
255 /*
256 * Check the parameter count for non-predefined methods/objects.
257 *
258 * Warning if too few or too many arguments have been passed by the
259 * caller. An incorrect number of arguments may not cause the method
260 * to fail. However, the method will fail if there are too few
261 * arguments and the method attempts to use one of the missing ones.
262 */
263 if (user_param_count < param_count) {
264 ACPI_WARN_PREDEFINED((AE_INFO, pathname,
265 ACPI_WARN_ALWAYS,
266 "Insufficient arguments - needs %u, found %u",
267 param_count, user_param_count));
268 } else if (user_param_count > param_count) {
269 ACPI_WARN_PREDEFINED((AE_INFO, pathname,
270 ACPI_WARN_ALWAYS,
271 "Excess arguments - needs %u, found %u",
272 param_count, user_param_count));
273 }
274 return;
275 }
276
277 /*
278 * Validate the user-supplied parameter count.
279 * Allow two different legal argument counts (_SCP, etc.)
280 */
281 required_params_current =
282 predefined->info.argument_list & METHOD_ARG_MASK;
283 required_params_old =
284 predefined->info.argument_list >> METHOD_ARG_BIT_WIDTH;
285
286 if (user_param_count != ACPI_UINT32_MAX) {
287 if ((user_param_count != required_params_current) &&
288 (user_param_count != required_params_old)) {
289 ACPI_WARN_PREDEFINED((AE_INFO, pathname,
290 ACPI_WARN_ALWAYS,
291 "Parameter count mismatch - "
292 "caller passed %u, ACPI requires %u",
293 user_param_count,
294 required_params_current));
295 }
296 }
297
298 /*
299 * Check that the ASL-defined parameter count is what is expected for
300 * this predefined name (parameter count as defined by the ACPI
301 * specification)
302 */
303 if ((param_count != required_params_current) &&
304 (param_count != required_params_old)) {
305 ACPI_WARN_PREDEFINED((AE_INFO, pathname, node->flags,
306 "Parameter count mismatch - ASL declared %u, ACPI requires %u",
307 param_count, required_params_current));
308 }
309}
310
311/*******************************************************************************
312 *
313 * FUNCTION: acpi_ns_check_object_type 196 * FUNCTION: acpi_ns_check_object_type
314 * 197 *
315 * PARAMETERS: data - Pointer to validation data structure 198 * PARAMETERS: info - Method execution information block
316 * return_object_ptr - Pointer to the object returned from the 199 * return_object_ptr - Pointer to the object returned from the
317 * evaluation of a method or object 200 * evaluation of a method or object
318 * expected_btypes - Bitmap of expected return type(s) 201 * expected_btypes - Bitmap of expected return type(s)
@@ -328,7 +211,7 @@ acpi_ns_check_parameter_count(char *pathname,
328 ******************************************************************************/ 211 ******************************************************************************/
329 212
330acpi_status 213acpi_status
331acpi_ns_check_object_type(struct acpi_predefined_data *data, 214acpi_ns_check_object_type(struct acpi_evaluate_info *info,
332 union acpi_operand_object **return_object_ptr, 215 union acpi_operand_object **return_object_ptr,
333 u32 expected_btypes, u32 package_index) 216 u32 expected_btypes, u32 package_index)
334{ 217{
@@ -340,7 +223,8 @@ acpi_ns_check_object_type(struct acpi_predefined_data *data,
340 223
341 if (return_object && 224 if (return_object &&
342 ACPI_GET_DESCRIPTOR_TYPE(return_object) == ACPI_DESC_TYPE_NAMED) { 225 ACPI_GET_DESCRIPTOR_TYPE(return_object) == ACPI_DESC_TYPE_NAMED) {
343 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags, 226 ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname,
227 info->node_flags,
344 "Invalid return type - Found a Namespace node [%4.4s] type %s", 228 "Invalid return type - Found a Namespace node [%4.4s] type %s",
345 return_object->node.name.ascii, 229 return_object->node.name.ascii,
346 acpi_ut_get_type_name(return_object->node. 230 acpi_ut_get_type_name(return_object->node.
@@ -356,8 +240,8 @@ acpi_ns_check_object_type(struct acpi_predefined_data *data,
356 * from all of the predefined names (including elements of returned 240 * from all of the predefined names (including elements of returned
357 * packages) 241 * packages)
358 */ 242 */
359 data->return_btype = acpi_ns_get_bitmapped_type(return_object); 243 info->return_btype = acpi_ns_get_bitmapped_type(return_object);
360 if (data->return_btype == ACPI_RTYPE_ANY) { 244 if (info->return_btype == ACPI_RTYPE_ANY) {
361 245
362 /* Not one of the supported objects, must be incorrect */ 246 /* Not one of the supported objects, must be incorrect */
363 goto type_error_exit; 247 goto type_error_exit;
@@ -365,16 +249,18 @@ acpi_ns_check_object_type(struct acpi_predefined_data *data,
365 249
366 /* For reference objects, check that the reference type is correct */ 250 /* For reference objects, check that the reference type is correct */
367 251
368 if ((data->return_btype & expected_btypes) == ACPI_RTYPE_REFERENCE) { 252 if ((info->return_btype & expected_btypes) == ACPI_RTYPE_REFERENCE) {
369 status = acpi_ns_check_reference(data, return_object); 253 status = acpi_ns_check_reference(info, return_object);
370 return (status); 254 return (status);
371 } 255 }
372 256
373 /* Attempt simple repair of the returned object if necessary */ 257 /* Attempt simple repair of the returned object if necessary */
374 258
375 status = acpi_ns_simple_repair(data, expected_btypes, 259 status = acpi_ns_simple_repair(info, expected_btypes,
376 package_index, return_object_ptr); 260 package_index, return_object_ptr);
377 return (status); 261 if (ACPI_SUCCESS(status)) {
262 return (AE_OK); /* Successful repair */
263 }
378 264
379 type_error_exit: 265 type_error_exit:
380 266
@@ -383,12 +269,14 @@ acpi_ns_check_object_type(struct acpi_predefined_data *data,
383 acpi_ut_get_expected_return_types(type_buffer, expected_btypes); 269 acpi_ut_get_expected_return_types(type_buffer, expected_btypes);
384 270
385 if (package_index == ACPI_NOT_PACKAGE_ELEMENT) { 271 if (package_index == ACPI_NOT_PACKAGE_ELEMENT) {
386 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags, 272 ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname,
273 info->node_flags,
387 "Return type mismatch - found %s, expected %s", 274 "Return type mismatch - found %s, expected %s",
388 acpi_ut_get_object_type_name 275 acpi_ut_get_object_type_name
389 (return_object), type_buffer)); 276 (return_object), type_buffer));
390 } else { 277 } else {
391 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags, 278 ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname,
279 info->node_flags,
392 "Return Package type mismatch at index %u - " 280 "Return Package type mismatch at index %u - "
393 "found %s, expected %s", package_index, 281 "found %s, expected %s", package_index,
394 acpi_ut_get_object_type_name 282 acpi_ut_get_object_type_name
@@ -402,7 +290,7 @@ acpi_ns_check_object_type(struct acpi_predefined_data *data,
402 * 290 *
403 * FUNCTION: acpi_ns_check_reference 291 * FUNCTION: acpi_ns_check_reference
404 * 292 *
405 * PARAMETERS: data - Pointer to validation data structure 293 * PARAMETERS: info - Method execution information block
406 * return_object - Object returned from the evaluation of a 294 * return_object - Object returned from the evaluation of a
407 * method or object 295 * method or object
408 * 296 *
@@ -415,7 +303,7 @@ acpi_ns_check_object_type(struct acpi_predefined_data *data,
415 ******************************************************************************/ 303 ******************************************************************************/
416 304
417static acpi_status 305static acpi_status
418acpi_ns_check_reference(struct acpi_predefined_data *data, 306acpi_ns_check_reference(struct acpi_evaluate_info *info,
419 union acpi_operand_object *return_object) 307 union acpi_operand_object *return_object)
420{ 308{
421 309
@@ -428,7 +316,7 @@ acpi_ns_check_reference(struct acpi_predefined_data *data,
428 return (AE_OK); 316 return (AE_OK);
429 } 317 }
430 318
431 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags, 319 ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname, info->node_flags,
432 "Return type mismatch - unexpected reference object type [%s] %2.2X", 320 "Return type mismatch - unexpected reference object type [%s] %2.2X",
433 acpi_ut_get_reference_name(return_object), 321 acpi_ut_get_reference_name(return_object),
434 return_object->reference.class)); 322 return_object->reference.class));
@@ -462,26 +350,32 @@ static u32 acpi_ns_get_bitmapped_type(union acpi_operand_object *return_object)
462 350
463 switch (return_object->common.type) { 351 switch (return_object->common.type) {
464 case ACPI_TYPE_INTEGER: 352 case ACPI_TYPE_INTEGER:
353
465 return_btype = ACPI_RTYPE_INTEGER; 354 return_btype = ACPI_RTYPE_INTEGER;
466 break; 355 break;
467 356
468 case ACPI_TYPE_BUFFER: 357 case ACPI_TYPE_BUFFER:
358
469 return_btype = ACPI_RTYPE_BUFFER; 359 return_btype = ACPI_RTYPE_BUFFER;
470 break; 360 break;
471 361
472 case ACPI_TYPE_STRING: 362 case ACPI_TYPE_STRING:
363
473 return_btype = ACPI_RTYPE_STRING; 364 return_btype = ACPI_RTYPE_STRING;
474 break; 365 break;
475 366
476 case ACPI_TYPE_PACKAGE: 367 case ACPI_TYPE_PACKAGE:
368
477 return_btype = ACPI_RTYPE_PACKAGE; 369 return_btype = ACPI_RTYPE_PACKAGE;
478 break; 370 break;
479 371
480 case ACPI_TYPE_LOCAL_REFERENCE: 372 case ACPI_TYPE_LOCAL_REFERENCE:
373
481 return_btype = ACPI_RTYPE_REFERENCE; 374 return_btype = ACPI_RTYPE_REFERENCE;
482 break; 375 break;
483 376
484 default: 377 default:
378
485 /* Not one of the supported objects, must be incorrect */ 379 /* Not one of the supported objects, must be incorrect */
486 380
487 return_btype = ACPI_RTYPE_ANY; 381 return_btype = ACPI_RTYPE_ANY;
diff --git a/drivers/acpi/acpica/nsprepkg.c b/drivers/acpi/acpica/nsprepkg.c
index 77cdd539de16..6d55cef7916c 100644
--- a/drivers/acpi/acpica/nsprepkg.c
+++ b/drivers/acpi/acpica/nsprepkg.c
@@ -51,12 +51,12 @@ ACPI_MODULE_NAME("nsprepkg")
51 51
52/* Local prototypes */ 52/* Local prototypes */
53static acpi_status 53static acpi_status
54acpi_ns_check_package_list(struct acpi_predefined_data *data, 54acpi_ns_check_package_list(struct acpi_evaluate_info *info,
55 const union acpi_predefined_info *package, 55 const union acpi_predefined_info *package,
56 union acpi_operand_object **elements, u32 count); 56 union acpi_operand_object **elements, u32 count);
57 57
58static acpi_status 58static acpi_status
59acpi_ns_check_package_elements(struct acpi_predefined_data *data, 59acpi_ns_check_package_elements(struct acpi_evaluate_info *info,
60 union acpi_operand_object **elements, 60 union acpi_operand_object **elements,
61 u8 type1, 61 u8 type1,
62 u32 count1, 62 u32 count1,
@@ -66,7 +66,7 @@ acpi_ns_check_package_elements(struct acpi_predefined_data *data,
66 * 66 *
67 * FUNCTION: acpi_ns_check_package 67 * FUNCTION: acpi_ns_check_package
68 * 68 *
69 * PARAMETERS: data - Pointer to validation data structure 69 * PARAMETERS: info - Method execution information block
70 * return_object_ptr - Pointer to the object returned from the 70 * return_object_ptr - Pointer to the object returned from the
71 * evaluation of a method or object 71 * evaluation of a method or object
72 * 72 *
@@ -78,7 +78,7 @@ acpi_ns_check_package_elements(struct acpi_predefined_data *data,
78 ******************************************************************************/ 78 ******************************************************************************/
79 79
80acpi_status 80acpi_status
81acpi_ns_check_package(struct acpi_predefined_data *data, 81acpi_ns_check_package(struct acpi_evaluate_info *info,
82 union acpi_operand_object **return_object_ptr) 82 union acpi_operand_object **return_object_ptr)
83{ 83{
84 union acpi_operand_object *return_object = *return_object_ptr; 84 union acpi_operand_object *return_object = *return_object_ptr;
@@ -93,18 +93,18 @@ acpi_ns_check_package(struct acpi_predefined_data *data,
93 93
94 /* The package info for this name is in the next table entry */ 94 /* The package info for this name is in the next table entry */
95 95
96 package = data->predefined + 1; 96 package = info->predefined + 1;
97 97
98 ACPI_DEBUG_PRINT((ACPI_DB_NAMES, 98 ACPI_DEBUG_PRINT((ACPI_DB_NAMES,
99 "%s Validating return Package of Type %X, Count %X\n", 99 "%s Validating return Package of Type %X, Count %X\n",
100 data->pathname, package->ret_info.type, 100 info->full_pathname, package->ret_info.type,
101 return_object->package.count)); 101 return_object->package.count));
102 102
103 /* 103 /*
104 * For variable-length Packages, we can safely remove all embedded 104 * For variable-length Packages, we can safely remove all embedded
105 * and trailing NULL package elements 105 * and trailing NULL package elements
106 */ 106 */
107 acpi_ns_remove_null_elements(data, package->ret_info.type, 107 acpi_ns_remove_null_elements(info, package->ret_info.type,
108 return_object); 108 return_object);
109 109
110 /* Extract package count and elements array */ 110 /* Extract package count and elements array */
@@ -121,7 +121,8 @@ acpi_ns_check_package(struct acpi_predefined_data *data,
121 return (AE_OK); 121 return (AE_OK);
122 } 122 }
123 123
124 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags, 124 ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname,
125 info->node_flags,
125 "Return Package has no elements (empty)")); 126 "Return Package has no elements (empty)"));
126 127
127 return (AE_AML_OPERAND_VALUE); 128 return (AE_AML_OPERAND_VALUE);
@@ -135,7 +136,6 @@ acpi_ns_check_package(struct acpi_predefined_data *data,
135 */ 136 */
136 switch (package->ret_info.type) { 137 switch (package->ret_info.type) {
137 case ACPI_PTYPE1_FIXED: 138 case ACPI_PTYPE1_FIXED:
138
139 /* 139 /*
140 * The package count is fixed and there are no sub-packages 140 * The package count is fixed and there are no sub-packages
141 * 141 *
@@ -150,13 +150,13 @@ acpi_ns_check_package(struct acpi_predefined_data *data,
150 ACPI_DEBUG_PRINT((ACPI_DB_REPAIR, 150 ACPI_DEBUG_PRINT((ACPI_DB_REPAIR,
151 "%s: Return Package is larger than needed - " 151 "%s: Return Package is larger than needed - "
152 "found %u, expected %u\n", 152 "found %u, expected %u\n",
153 data->pathname, count, 153 info->full_pathname, count,
154 expected_count)); 154 expected_count));
155 } 155 }
156 156
157 /* Validate all elements of the returned package */ 157 /* Validate all elements of the returned package */
158 158
159 status = acpi_ns_check_package_elements(data, elements, 159 status = acpi_ns_check_package_elements(info, elements,
160 package->ret_info. 160 package->ret_info.
161 object_type1, 161 object_type1,
162 package->ret_info. 162 package->ret_info.
@@ -168,13 +168,12 @@ acpi_ns_check_package(struct acpi_predefined_data *data,
168 break; 168 break;
169 169
170 case ACPI_PTYPE1_VAR: 170 case ACPI_PTYPE1_VAR:
171
172 /* 171 /*
173 * The package count is variable, there are no sub-packages, and all 172 * The package count is variable, there are no sub-packages, and all
174 * elements must be of the same type 173 * elements must be of the same type
175 */ 174 */
176 for (i = 0; i < count; i++) { 175 for (i = 0; i < count; i++) {
177 status = acpi_ns_check_object_type(data, elements, 176 status = acpi_ns_check_object_type(info, elements,
178 package->ret_info. 177 package->ret_info.
179 object_type1, i); 178 object_type1, i);
180 if (ACPI_FAILURE(status)) { 179 if (ACPI_FAILURE(status)) {
@@ -185,7 +184,6 @@ acpi_ns_check_package(struct acpi_predefined_data *data,
185 break; 184 break;
186 185
187 case ACPI_PTYPE1_OPTION: 186 case ACPI_PTYPE1_OPTION:
188
189 /* 187 /*
190 * The package count is variable, there are no sub-packages. There are 188 * The package count is variable, there are no sub-packages. There are
191 * a fixed number of required elements, and a variable number of 189 * a fixed number of required elements, and a variable number of
@@ -206,7 +204,7 @@ acpi_ns_check_package(struct acpi_predefined_data *data,
206 /* These are the required package elements (0, 1, or 2) */ 204 /* These are the required package elements (0, 1, or 2) */
207 205
208 status = 206 status =
209 acpi_ns_check_object_type(data, elements, 207 acpi_ns_check_object_type(info, elements,
210 package-> 208 package->
211 ret_info3. 209 ret_info3.
212 object_type[i], 210 object_type[i],
@@ -218,7 +216,7 @@ acpi_ns_check_package(struct acpi_predefined_data *data,
218 /* These are the optional package elements */ 216 /* These are the optional package elements */
219 217
220 status = 218 status =
221 acpi_ns_check_object_type(data, elements, 219 acpi_ns_check_object_type(info, elements,
222 package-> 220 package->
223 ret_info3. 221 ret_info3.
224 tail_object_type, 222 tail_object_type,
@@ -235,7 +233,7 @@ acpi_ns_check_package(struct acpi_predefined_data *data,
235 233
236 /* First element is the (Integer) revision */ 234 /* First element is the (Integer) revision */
237 235
238 status = acpi_ns_check_object_type(data, elements, 236 status = acpi_ns_check_object_type(info, elements,
239 ACPI_RTYPE_INTEGER, 0); 237 ACPI_RTYPE_INTEGER, 0);
240 if (ACPI_FAILURE(status)) { 238 if (ACPI_FAILURE(status)) {
241 return (status); 239 return (status);
@@ -247,14 +245,14 @@ acpi_ns_check_package(struct acpi_predefined_data *data,
247 /* Examine the sub-packages */ 245 /* Examine the sub-packages */
248 246
249 status = 247 status =
250 acpi_ns_check_package_list(data, package, elements, count); 248 acpi_ns_check_package_list(info, package, elements, count);
251 break; 249 break;
252 250
253 case ACPI_PTYPE2_PKG_COUNT: 251 case ACPI_PTYPE2_PKG_COUNT:
254 252
255 /* First element is the (Integer) count of sub-packages to follow */ 253 /* First element is the (Integer) count of sub-packages to follow */
256 254
257 status = acpi_ns_check_object_type(data, elements, 255 status = acpi_ns_check_object_type(info, elements,
258 ACPI_RTYPE_INTEGER, 0); 256 ACPI_RTYPE_INTEGER, 0);
259 if (ACPI_FAILURE(status)) { 257 if (ACPI_FAILURE(status)) {
260 return (status); 258 return (status);
@@ -275,7 +273,7 @@ acpi_ns_check_package(struct acpi_predefined_data *data,
275 /* Examine the sub-packages */ 273 /* Examine the sub-packages */
276 274
277 status = 275 status =
278 acpi_ns_check_package_list(data, package, elements, count); 276 acpi_ns_check_package_list(info, package, elements, count);
279 break; 277 break;
280 278
281 case ACPI_PTYPE2: 279 case ACPI_PTYPE2:
@@ -283,7 +281,6 @@ acpi_ns_check_package(struct acpi_predefined_data *data,
283 case ACPI_PTYPE2_MIN: 281 case ACPI_PTYPE2_MIN:
284 case ACPI_PTYPE2_COUNT: 282 case ACPI_PTYPE2_COUNT:
285 case ACPI_PTYPE2_FIX_VAR: 283 case ACPI_PTYPE2_FIX_VAR:
286
287 /* 284 /*
288 * These types all return a single Package that consists of a 285 * These types all return a single Package that consists of a
289 * variable number of sub-Packages. 286 * variable number of sub-Packages.
@@ -300,7 +297,7 @@ acpi_ns_check_package(struct acpi_predefined_data *data,
300 /* Create the new outer package and populate it */ 297 /* Create the new outer package and populate it */
301 298
302 status = 299 status =
303 acpi_ns_wrap_with_package(data, return_object, 300 acpi_ns_wrap_with_package(info, return_object,
304 return_object_ptr); 301 return_object_ptr);
305 if (ACPI_FAILURE(status)) { 302 if (ACPI_FAILURE(status)) {
306 return (status); 303 return (status);
@@ -316,14 +313,15 @@ acpi_ns_check_package(struct acpi_predefined_data *data,
316 /* Examine the sub-packages */ 313 /* Examine the sub-packages */
317 314
318 status = 315 status =
319 acpi_ns_check_package_list(data, package, elements, count); 316 acpi_ns_check_package_list(info, package, elements, count);
320 break; 317 break;
321 318
322 default: 319 default:
323 320
324 /* Should not get here if predefined info table is correct */ 321 /* Should not get here if predefined info table is correct */
325 322
326 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags, 323 ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname,
324 info->node_flags,
327 "Invalid internal return type in table entry: %X", 325 "Invalid internal return type in table entry: %X",
328 package->ret_info.type)); 326 package->ret_info.type));
329 327
@@ -336,7 +334,7 @@ acpi_ns_check_package(struct acpi_predefined_data *data,
336 334
337 /* Error exit for the case with an incorrect package count */ 335 /* Error exit for the case with an incorrect package count */
338 336
339 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags, 337 ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname, info->node_flags,
340 "Return Package is too small - found %u elements, expected %u", 338 "Return Package is too small - found %u elements, expected %u",
341 count, expected_count)); 339 count, expected_count));
342 340
@@ -347,7 +345,7 @@ acpi_ns_check_package(struct acpi_predefined_data *data,
347 * 345 *
348 * FUNCTION: acpi_ns_check_package_list 346 * FUNCTION: acpi_ns_check_package_list
349 * 347 *
350 * PARAMETERS: data - Pointer to validation data structure 348 * PARAMETERS: info - Method execution information block
351 * package - Pointer to package-specific info for method 349 * package - Pointer to package-specific info for method
352 * elements - Element list of parent package. All elements 350 * elements - Element list of parent package. All elements
353 * of this list should be of type Package. 351 * of this list should be of type Package.
@@ -360,7 +358,7 @@ acpi_ns_check_package(struct acpi_predefined_data *data,
360 ******************************************************************************/ 358 ******************************************************************************/
361 359
362static acpi_status 360static acpi_status
363acpi_ns_check_package_list(struct acpi_predefined_data *data, 361acpi_ns_check_package_list(struct acpi_evaluate_info *info,
364 const union acpi_predefined_info *package, 362 const union acpi_predefined_info *package,
365 union acpi_operand_object **elements, u32 count) 363 union acpi_operand_object **elements, u32 count)
366{ 364{
@@ -381,11 +379,11 @@ acpi_ns_check_package_list(struct acpi_predefined_data *data,
381 for (i = 0; i < count; i++) { 379 for (i = 0; i < count; i++) {
382 sub_package = *elements; 380 sub_package = *elements;
383 sub_elements = sub_package->package.elements; 381 sub_elements = sub_package->package.elements;
384 data->parent_package = sub_package; 382 info->parent_package = sub_package;
385 383
386 /* Each sub-object must be of type Package */ 384 /* Each sub-object must be of type Package */
387 385
388 status = acpi_ns_check_object_type(data, &sub_package, 386 status = acpi_ns_check_object_type(info, &sub_package,
389 ACPI_RTYPE_PACKAGE, i); 387 ACPI_RTYPE_PACKAGE, i);
390 if (ACPI_FAILURE(status)) { 388 if (ACPI_FAILURE(status)) {
391 return (status); 389 return (status);
@@ -393,7 +391,7 @@ acpi_ns_check_package_list(struct acpi_predefined_data *data,
393 391
394 /* Examine the different types of expected sub-packages */ 392 /* Examine the different types of expected sub-packages */
395 393
396 data->parent_package = sub_package; 394 info->parent_package = sub_package;
397 switch (package->ret_info.type) { 395 switch (package->ret_info.type) {
398 case ACPI_PTYPE2: 396 case ACPI_PTYPE2:
399 case ACPI_PTYPE2_PKG_COUNT: 397 case ACPI_PTYPE2_PKG_COUNT:
@@ -408,7 +406,7 @@ acpi_ns_check_package_list(struct acpi_predefined_data *data,
408 } 406 }
409 407
410 status = 408 status =
411 acpi_ns_check_package_elements(data, sub_elements, 409 acpi_ns_check_package_elements(info, sub_elements,
412 package->ret_info. 410 package->ret_info.
413 object_type1, 411 object_type1,
414 package->ret_info. 412 package->ret_info.
@@ -434,7 +432,7 @@ acpi_ns_check_package_list(struct acpi_predefined_data *data,
434 } 432 }
435 433
436 status = 434 status =
437 acpi_ns_check_package_elements(data, sub_elements, 435 acpi_ns_check_package_elements(info, sub_elements,
438 package->ret_info. 436 package->ret_info.
439 object_type1, 437 object_type1,
440 package->ret_info. 438 package->ret_info.
@@ -463,7 +461,7 @@ acpi_ns_check_package_list(struct acpi_predefined_data *data,
463 461
464 for (j = 0; j < expected_count; j++) { 462 for (j = 0; j < expected_count; j++) {
465 status = 463 status =
466 acpi_ns_check_object_type(data, 464 acpi_ns_check_object_type(info,
467 &sub_elements[j], 465 &sub_elements[j],
468 package-> 466 package->
469 ret_info2. 467 ret_info2.
@@ -487,7 +485,7 @@ acpi_ns_check_package_list(struct acpi_predefined_data *data,
487 /* Check the type of each sub-package element */ 485 /* Check the type of each sub-package element */
488 486
489 status = 487 status =
490 acpi_ns_check_package_elements(data, sub_elements, 488 acpi_ns_check_package_elements(info, sub_elements,
491 package->ret_info. 489 package->ret_info.
492 object_type1, 490 object_type1,
493 sub_package->package. 491 sub_package->package.
@@ -498,12 +496,11 @@ acpi_ns_check_package_list(struct acpi_predefined_data *data,
498 break; 496 break;
499 497
500 case ACPI_PTYPE2_COUNT: 498 case ACPI_PTYPE2_COUNT:
501
502 /* 499 /*
503 * First element is the (Integer) count of elements, including 500 * First element is the (Integer) count of elements, including
504 * the count field (the ACPI name is num_elements) 501 * the count field (the ACPI name is num_elements)
505 */ 502 */
506 status = acpi_ns_check_object_type(data, sub_elements, 503 status = acpi_ns_check_object_type(info, sub_elements,
507 ACPI_RTYPE_INTEGER, 504 ACPI_RTYPE_INTEGER,
508 0); 505 0);
509 if (ACPI_FAILURE(status)) { 506 if (ACPI_FAILURE(status)) {
@@ -537,7 +534,7 @@ acpi_ns_check_package_list(struct acpi_predefined_data *data,
537 /* Check the type of each sub-package element */ 534 /* Check the type of each sub-package element */
538 535
539 status = 536 status =
540 acpi_ns_check_package_elements(data, 537 acpi_ns_check_package_elements(info,
541 (sub_elements + 1), 538 (sub_elements + 1),
542 package->ret_info. 539 package->ret_info.
543 object_type1, 540 object_type1,
@@ -562,7 +559,7 @@ acpi_ns_check_package_list(struct acpi_predefined_data *data,
562 559
563 /* The sub-package count was smaller than required */ 560 /* The sub-package count was smaller than required */
564 561
565 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags, 562 ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname, info->node_flags,
566 "Return Sub-Package[%u] is too small - found %u elements, expected %u", 563 "Return Sub-Package[%u] is too small - found %u elements, expected %u",
567 i, sub_package->package.count, expected_count)); 564 i, sub_package->package.count, expected_count));
568 565
@@ -573,7 +570,7 @@ acpi_ns_check_package_list(struct acpi_predefined_data *data,
573 * 570 *
574 * FUNCTION: acpi_ns_check_package_elements 571 * FUNCTION: acpi_ns_check_package_elements
575 * 572 *
576 * PARAMETERS: data - Pointer to validation data structure 573 * PARAMETERS: info - Method execution information block
577 * elements - Pointer to the package elements array 574 * elements - Pointer to the package elements array
578 * type1 - Object type for first group 575 * type1 - Object type for first group
579 * count1 - Count for first group 576 * count1 - Count for first group
@@ -589,7 +586,7 @@ acpi_ns_check_package_list(struct acpi_predefined_data *data,
589 ******************************************************************************/ 586 ******************************************************************************/
590 587
591static acpi_status 588static acpi_status
592acpi_ns_check_package_elements(struct acpi_predefined_data *data, 589acpi_ns_check_package_elements(struct acpi_evaluate_info *info,
593 union acpi_operand_object **elements, 590 union acpi_operand_object **elements,
594 u8 type1, 591 u8 type1,
595 u32 count1, 592 u32 count1,
@@ -605,7 +602,7 @@ acpi_ns_check_package_elements(struct acpi_predefined_data *data,
605 * The second group can have a count of zero. 602 * The second group can have a count of zero.
606 */ 603 */
607 for (i = 0; i < count1; i++) { 604 for (i = 0; i < count1; i++) {
608 status = acpi_ns_check_object_type(data, this_element, 605 status = acpi_ns_check_object_type(info, this_element,
609 type1, i + start_index); 606 type1, i + start_index);
610 if (ACPI_FAILURE(status)) { 607 if (ACPI_FAILURE(status)) {
611 return (status); 608 return (status);
@@ -614,7 +611,7 @@ acpi_ns_check_package_elements(struct acpi_predefined_data *data,
614 } 611 }
615 612
616 for (i = 0; i < count2; i++) { 613 for (i = 0; i < count2; i++) {
617 status = acpi_ns_check_object_type(data, this_element, 614 status = acpi_ns_check_object_type(info, this_element,
618 type2, 615 type2,
619 (i + count1 + start_index)); 616 (i + count1 + start_index));
620 if (ACPI_FAILURE(status)) { 617 if (ACPI_FAILURE(status)) {
diff --git a/drivers/acpi/acpica/nsrepair.c b/drivers/acpi/acpica/nsrepair.c
index 18f02e4ece01..f8e71ea60319 100644
--- a/drivers/acpi/acpica/nsrepair.c
+++ b/drivers/acpi/acpica/nsrepair.c
@@ -130,7 +130,7 @@ static const struct acpi_simple_repair_info acpi_object_repair_info[] = {
130 * 130 *
131 * FUNCTION: acpi_ns_simple_repair 131 * FUNCTION: acpi_ns_simple_repair
132 * 132 *
133 * PARAMETERS: data - Pointer to validation data structure 133 * PARAMETERS: info - Method execution information block
134 * expected_btypes - Object types expected 134 * expected_btypes - Object types expected
135 * package_index - Index of object within parent package (if 135 * package_index - Index of object within parent package (if
136 * applicable - ACPI_NOT_PACKAGE_ELEMENT 136 * applicable - ACPI_NOT_PACKAGE_ELEMENT
@@ -146,7 +146,7 @@ static const struct acpi_simple_repair_info acpi_object_repair_info[] = {
146 ******************************************************************************/ 146 ******************************************************************************/
147 147
148acpi_status 148acpi_status
149acpi_ns_simple_repair(struct acpi_predefined_data *data, 149acpi_ns_simple_repair(struct acpi_evaluate_info *info,
150 u32 expected_btypes, 150 u32 expected_btypes,
151 u32 package_index, 151 u32 package_index,
152 union acpi_operand_object **return_object_ptr) 152 union acpi_operand_object **return_object_ptr)
@@ -162,12 +162,12 @@ acpi_ns_simple_repair(struct acpi_predefined_data *data,
162 * Special repairs for certain names that are in the repair table. 162 * Special repairs for certain names that are in the repair table.
163 * Check if this name is in the list of repairable names. 163 * Check if this name is in the list of repairable names.
164 */ 164 */
165 predefined = acpi_ns_match_simple_repair(data->node, 165 predefined = acpi_ns_match_simple_repair(info->node,
166 data->return_btype, 166 info->return_btype,
167 package_index); 167 package_index);
168 if (predefined) { 168 if (predefined) {
169 if (!return_object) { 169 if (!return_object) {
170 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, 170 ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname,
171 ACPI_WARN_ALWAYS, 171 ACPI_WARN_ALWAYS,
172 "Missing expected return value")); 172 "Missing expected return value"));
173 } 173 }
@@ -191,7 +191,7 @@ acpi_ns_simple_repair(struct acpi_predefined_data *data,
191 * Do not perform simple object repair unless the return type is not 191 * Do not perform simple object repair unless the return type is not
192 * expected. 192 * expected.
193 */ 193 */
194 if (data->return_btype & expected_btypes) { 194 if (info->return_btype & expected_btypes) {
195 return (AE_OK); 195 return (AE_OK);
196 } 196 }
197 197
@@ -211,7 +211,7 @@ acpi_ns_simple_repair(struct acpi_predefined_data *data,
211 */ 211 */
212 if (!return_object) { 212 if (!return_object) {
213 if (expected_btypes && (!(expected_btypes & ACPI_RTYPE_NONE))) { 213 if (expected_btypes && (!(expected_btypes & ACPI_RTYPE_NONE))) {
214 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, 214 ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname,
215 ACPI_WARN_ALWAYS, 215 ACPI_WARN_ALWAYS,
216 "Missing expected return value")); 216 "Missing expected return value"));
217 217
@@ -247,14 +247,14 @@ acpi_ns_simple_repair(struct acpi_predefined_data *data,
247 * for correct contents (expected object type or types). 247 * for correct contents (expected object type or types).
248 */ 248 */
249 status = 249 status =
250 acpi_ns_wrap_with_package(data, return_object, &new_object); 250 acpi_ns_wrap_with_package(info, return_object, &new_object);
251 if (ACPI_SUCCESS(status)) { 251 if (ACPI_SUCCESS(status)) {
252 /* 252 /*
253 * The original object just had its reference count 253 * The original object just had its reference count
254 * incremented for being inserted into the new package. 254 * incremented for being inserted into the new package.
255 */ 255 */
256 *return_object_ptr = new_object; /* New Package object */ 256 *return_object_ptr = new_object; /* New Package object */
257 data->flags |= ACPI_OBJECT_REPAIRED; 257 info->return_flags |= ACPI_OBJECT_REPAIRED;
258 return (AE_OK); 258 return (AE_OK);
259 } 259 }
260 } 260 }
@@ -277,7 +277,7 @@ acpi_ns_simple_repair(struct acpi_predefined_data *data,
277 * package object as part of the repair, we don't need to 277 * package object as part of the repair, we don't need to
278 * change the reference count. 278 * change the reference count.
279 */ 279 */
280 if (!(data->flags & ACPI_OBJECT_WRAPPED)) { 280 if (!(info->return_flags & ACPI_OBJECT_WRAPPED)) {
281 new_object->common.reference_count = 281 new_object->common.reference_count =
282 return_object->common.reference_count; 282 return_object->common.reference_count;
283 283
@@ -288,14 +288,14 @@ acpi_ns_simple_repair(struct acpi_predefined_data *data,
288 288
289 ACPI_DEBUG_PRINT((ACPI_DB_REPAIR, 289 ACPI_DEBUG_PRINT((ACPI_DB_REPAIR,
290 "%s: Converted %s to expected %s at Package index %u\n", 290 "%s: Converted %s to expected %s at Package index %u\n",
291 data->pathname, 291 info->full_pathname,
292 acpi_ut_get_object_type_name(return_object), 292 acpi_ut_get_object_type_name(return_object),
293 acpi_ut_get_object_type_name(new_object), 293 acpi_ut_get_object_type_name(new_object),
294 package_index)); 294 package_index));
295 } else { 295 } else {
296 ACPI_DEBUG_PRINT((ACPI_DB_REPAIR, 296 ACPI_DEBUG_PRINT((ACPI_DB_REPAIR,
297 "%s: Converted %s to expected %s\n", 297 "%s: Converted %s to expected %s\n",
298 data->pathname, 298 info->full_pathname,
299 acpi_ut_get_object_type_name(return_object), 299 acpi_ut_get_object_type_name(return_object),
300 acpi_ut_get_object_type_name(new_object))); 300 acpi_ut_get_object_type_name(new_object)));
301 } 301 }
@@ -304,7 +304,7 @@ acpi_ns_simple_repair(struct acpi_predefined_data *data,
304 304
305 acpi_ut_remove_reference(return_object); 305 acpi_ut_remove_reference(return_object);
306 *return_object_ptr = new_object; 306 *return_object_ptr = new_object;
307 data->flags |= ACPI_OBJECT_REPAIRED; 307 info->return_flags |= ACPI_OBJECT_REPAIRED;
308 return (AE_OK); 308 return (AE_OK);
309} 309}
310 310
@@ -359,7 +359,7 @@ static const struct acpi_simple_repair_info *acpi_ns_match_simple_repair(struct
359 * 359 *
360 * FUNCTION: acpi_ns_repair_null_element 360 * FUNCTION: acpi_ns_repair_null_element
361 * 361 *
362 * PARAMETERS: data - Pointer to validation data structure 362 * PARAMETERS: info - Method execution information block
363 * expected_btypes - Object types expected 363 * expected_btypes - Object types expected
364 * package_index - Index of object within parent package (if 364 * package_index - Index of object within parent package (if
365 * applicable - ACPI_NOT_PACKAGE_ELEMENT 365 * applicable - ACPI_NOT_PACKAGE_ELEMENT
@@ -374,7 +374,7 @@ static const struct acpi_simple_repair_info *acpi_ns_match_simple_repair(struct
374 ******************************************************************************/ 374 ******************************************************************************/
375 375
376acpi_status 376acpi_status
377acpi_ns_repair_null_element(struct acpi_predefined_data *data, 377acpi_ns_repair_null_element(struct acpi_evaluate_info * info,
378 u32 expected_btypes, 378 u32 expected_btypes,
379 u32 package_index, 379 u32 package_index,
380 union acpi_operand_object **return_object_ptr) 380 union acpi_operand_object **return_object_ptr)
@@ -424,16 +424,16 @@ acpi_ns_repair_null_element(struct acpi_predefined_data *data,
424 /* Set the reference count according to the parent Package object */ 424 /* Set the reference count according to the parent Package object */
425 425
426 new_object->common.reference_count = 426 new_object->common.reference_count =
427 data->parent_package->common.reference_count; 427 info->parent_package->common.reference_count;
428 428
429 ACPI_DEBUG_PRINT((ACPI_DB_REPAIR, 429 ACPI_DEBUG_PRINT((ACPI_DB_REPAIR,
430 "%s: Converted NULL package element to expected %s at index %u\n", 430 "%s: Converted NULL package element to expected %s at index %u\n",
431 data->pathname, 431 info->full_pathname,
432 acpi_ut_get_object_type_name(new_object), 432 acpi_ut_get_object_type_name(new_object),
433 package_index)); 433 package_index));
434 434
435 *return_object_ptr = new_object; 435 *return_object_ptr = new_object;
436 data->flags |= ACPI_OBJECT_REPAIRED; 436 info->return_flags |= ACPI_OBJECT_REPAIRED;
437 return (AE_OK); 437 return (AE_OK);
438} 438}
439 439
@@ -441,7 +441,7 @@ acpi_ns_repair_null_element(struct acpi_predefined_data *data,
441 * 441 *
442 * FUNCTION: acpi_ns_remove_null_elements 442 * FUNCTION: acpi_ns_remove_null_elements
443 * 443 *
444 * PARAMETERS: data - Pointer to validation data structure 444 * PARAMETERS: info - Method execution information block
445 * package_type - An acpi_return_package_types value 445 * package_type - An acpi_return_package_types value
446 * obj_desc - A Package object 446 * obj_desc - A Package object
447 * 447 *
@@ -454,7 +454,7 @@ acpi_ns_repair_null_element(struct acpi_predefined_data *data,
454 *****************************************************************************/ 454 *****************************************************************************/
455 455
456void 456void
457acpi_ns_remove_null_elements(struct acpi_predefined_data *data, 457acpi_ns_remove_null_elements(struct acpi_evaluate_info *info,
458 u8 package_type, 458 u8 package_type,
459 union acpi_operand_object *obj_desc) 459 union acpi_operand_object *obj_desc)
460{ 460{
@@ -480,6 +480,7 @@ acpi_ns_remove_null_elements(struct acpi_predefined_data *data,
480 case ACPI_PTYPE2_MIN: 480 case ACPI_PTYPE2_MIN:
481 case ACPI_PTYPE2_REV_FIXED: 481 case ACPI_PTYPE2_REV_FIXED:
482 case ACPI_PTYPE2_FIX_VAR: 482 case ACPI_PTYPE2_FIX_VAR:
483
483 break; 484 break;
484 485
485 default: 486 default:
@@ -511,7 +512,7 @@ acpi_ns_remove_null_elements(struct acpi_predefined_data *data,
511 if (new_count < count) { 512 if (new_count < count) {
512 ACPI_DEBUG_PRINT((ACPI_DB_REPAIR, 513 ACPI_DEBUG_PRINT((ACPI_DB_REPAIR,
513 "%s: Found and removed %u NULL elements\n", 514 "%s: Found and removed %u NULL elements\n",
514 data->pathname, (count - new_count))); 515 info->full_pathname, (count - new_count)));
515 516
516 /* NULL terminate list and update the package count */ 517 /* NULL terminate list and update the package count */
517 518
@@ -524,7 +525,7 @@ acpi_ns_remove_null_elements(struct acpi_predefined_data *data,
524 * 525 *
525 * FUNCTION: acpi_ns_wrap_with_package 526 * FUNCTION: acpi_ns_wrap_with_package
526 * 527 *
527 * PARAMETERS: data - Pointer to validation data structure 528 * PARAMETERS: info - Method execution information block
528 * original_object - Pointer to the object to repair. 529 * original_object - Pointer to the object to repair.
529 * obj_desc_ptr - The new package object is returned here 530 * obj_desc_ptr - The new package object is returned here
530 * 531 *
@@ -545,7 +546,7 @@ acpi_ns_remove_null_elements(struct acpi_predefined_data *data,
545 ******************************************************************************/ 546 ******************************************************************************/
546 547
547acpi_status 548acpi_status
548acpi_ns_wrap_with_package(struct acpi_predefined_data *data, 549acpi_ns_wrap_with_package(struct acpi_evaluate_info *info,
549 union acpi_operand_object *original_object, 550 union acpi_operand_object *original_object,
550 union acpi_operand_object **obj_desc_ptr) 551 union acpi_operand_object **obj_desc_ptr)
551{ 552{
@@ -566,12 +567,12 @@ acpi_ns_wrap_with_package(struct acpi_predefined_data *data,
566 567
567 ACPI_DEBUG_PRINT((ACPI_DB_REPAIR, 568 ACPI_DEBUG_PRINT((ACPI_DB_REPAIR,
568 "%s: Wrapped %s with expected Package object\n", 569 "%s: Wrapped %s with expected Package object\n",
569 data->pathname, 570 info->full_pathname,
570 acpi_ut_get_object_type_name(original_object))); 571 acpi_ut_get_object_type_name(original_object)));
571 572
572 /* Return the new object in the object pointer */ 573 /* Return the new object in the object pointer */
573 574
574 *obj_desc_ptr = pkg_obj_desc; 575 *obj_desc_ptr = pkg_obj_desc;
575 data->flags |= ACPI_OBJECT_REPAIRED | ACPI_OBJECT_WRAPPED; 576 info->return_flags |= ACPI_OBJECT_REPAIRED | ACPI_OBJECT_WRAPPED;
576 return (AE_OK); 577 return (AE_OK);
577} 578}
diff --git a/drivers/acpi/acpica/nsrepair2.c b/drivers/acpi/acpica/nsrepair2.c
index 149e9b9c2c1b..c84603ee83ae 100644
--- a/drivers/acpi/acpica/nsrepair2.c
+++ b/drivers/acpi/acpica/nsrepair2.c
@@ -54,7 +54,7 @@ ACPI_MODULE_NAME("nsrepair2")
54 * be repaired on a per-name basis. 54 * be repaired on a per-name basis.
55 */ 55 */
56typedef 56typedef
57acpi_status(*acpi_repair_function) (struct acpi_predefined_data *data, 57acpi_status(*acpi_repair_function) (struct acpi_evaluate_info * info,
58 union acpi_operand_object 58 union acpi_operand_object
59 **return_object_ptr); 59 **return_object_ptr);
60 60
@@ -71,45 +71,57 @@ static const struct acpi_repair_info *acpi_ns_match_complex_repair(struct
71 *node); 71 *node);
72 72
73static acpi_status 73static acpi_status
74acpi_ns_repair_ALR(struct acpi_predefined_data *data, 74acpi_ns_repair_ALR(struct acpi_evaluate_info *info,
75 union acpi_operand_object **return_object_ptr); 75 union acpi_operand_object **return_object_ptr);
76 76
77static acpi_status 77static acpi_status
78acpi_ns_repair_CID(struct acpi_predefined_data *data, 78acpi_ns_repair_CID(struct acpi_evaluate_info *info,
79 union acpi_operand_object **return_object_ptr); 79 union acpi_operand_object **return_object_ptr);
80 80
81static acpi_status 81static acpi_status
82acpi_ns_repair_FDE(struct acpi_predefined_data *data, 82acpi_ns_repair_CST(struct acpi_evaluate_info *info,
83 union acpi_operand_object **return_object_ptr); 83 union acpi_operand_object **return_object_ptr);
84 84
85static acpi_status 85static acpi_status
86acpi_ns_repair_HID(struct acpi_predefined_data *data, 86acpi_ns_repair_FDE(struct acpi_evaluate_info *info,
87 union acpi_operand_object **return_object_ptr); 87 union acpi_operand_object **return_object_ptr);
88 88
89static acpi_status 89static acpi_status
90acpi_ns_repair_PSS(struct acpi_predefined_data *data, 90acpi_ns_repair_HID(struct acpi_evaluate_info *info,
91 union acpi_operand_object **return_object_ptr); 91 union acpi_operand_object **return_object_ptr);
92 92
93static acpi_status 93static acpi_status
94acpi_ns_repair_TSS(struct acpi_predefined_data *data, 94acpi_ns_repair_PRT(struct acpi_evaluate_info *info,
95 union acpi_operand_object **return_object_ptr); 95 union acpi_operand_object **return_object_ptr);
96 96
97static acpi_status 97static acpi_status
98acpi_ns_check_sorted_list(struct acpi_predefined_data *data, 98acpi_ns_repair_PSS(struct acpi_evaluate_info *info,
99 union acpi_operand_object **return_object_ptr);
100
101static acpi_status
102acpi_ns_repair_TSS(struct acpi_evaluate_info *info,
103 union acpi_operand_object **return_object_ptr);
104
105static acpi_status
106acpi_ns_check_sorted_list(struct acpi_evaluate_info *info,
99 union acpi_operand_object *return_object, 107 union acpi_operand_object *return_object,
108 u32 start_index,
100 u32 expected_count, 109 u32 expected_count,
101 u32 sort_index, 110 u32 sort_index,
102 u8 sort_direction, char *sort_key_name); 111 u8 sort_direction, char *sort_key_name);
103 112
104static void
105acpi_ns_sort_list(union acpi_operand_object **elements,
106 u32 count, u32 index, u8 sort_direction);
107
108/* Values for sort_direction above */ 113/* Values for sort_direction above */
109 114
110#define ACPI_SORT_ASCENDING 0 115#define ACPI_SORT_ASCENDING 0
111#define ACPI_SORT_DESCENDING 1 116#define ACPI_SORT_DESCENDING 1
112 117
118static void
119acpi_ns_remove_element(union acpi_operand_object *obj_desc, u32 index);
120
121static void
122acpi_ns_sort_list(union acpi_operand_object **elements,
123 u32 count, u32 index, u8 sort_direction);
124
113/* 125/*
114 * This table contains the names of the predefined methods for which we can 126 * This table contains the names of the predefined methods for which we can
115 * perform more complex repairs. 127 * perform more complex repairs.
@@ -118,9 +130,11 @@ acpi_ns_sort_list(union acpi_operand_object **elements,
118 * 130 *
119 * _ALR: Sort the list ascending by ambient_illuminance 131 * _ALR: Sort the list ascending by ambient_illuminance
120 * _CID: Strings: uppercase all, remove any leading asterisk 132 * _CID: Strings: uppercase all, remove any leading asterisk
133 * _CST: Sort the list ascending by C state type
121 * _FDE: Convert Buffer of BYTEs to a Buffer of DWORDs 134 * _FDE: Convert Buffer of BYTEs to a Buffer of DWORDs
122 * _GTM: Convert Buffer of BYTEs to a Buffer of DWORDs 135 * _GTM: Convert Buffer of BYTEs to a Buffer of DWORDs
123 * _HID: Strings: uppercase all, remove any leading asterisk 136 * _HID: Strings: uppercase all, remove any leading asterisk
137 * _PRT: Fix reversed source_name and source_index
124 * _PSS: Sort the list descending by Power 138 * _PSS: Sort the list descending by Power
125 * _TSS: Sort the list descending by Power 139 * _TSS: Sort the list descending by Power
126 * 140 *
@@ -134,9 +148,11 @@ acpi_ns_sort_list(union acpi_operand_object **elements,
134static const struct acpi_repair_info acpi_ns_repairable_names[] = { 148static const struct acpi_repair_info acpi_ns_repairable_names[] = {
135 {"_ALR", acpi_ns_repair_ALR}, 149 {"_ALR", acpi_ns_repair_ALR},
136 {"_CID", acpi_ns_repair_CID}, 150 {"_CID", acpi_ns_repair_CID},
151 {"_CST", acpi_ns_repair_CST},
137 {"_FDE", acpi_ns_repair_FDE}, 152 {"_FDE", acpi_ns_repair_FDE},
138 {"_GTM", acpi_ns_repair_FDE}, /* _GTM has same repair as _FDE */ 153 {"_GTM", acpi_ns_repair_FDE}, /* _GTM has same repair as _FDE */
139 {"_HID", acpi_ns_repair_HID}, 154 {"_HID", acpi_ns_repair_HID},
155 {"_PRT", acpi_ns_repair_PRT},
140 {"_PSS", acpi_ns_repair_PSS}, 156 {"_PSS", acpi_ns_repair_PSS},
141 {"_TSS", acpi_ns_repair_TSS}, 157 {"_TSS", acpi_ns_repair_TSS},
142 {{0, 0, 0, 0}, NULL} /* Table terminator */ 158 {{0, 0, 0, 0}, NULL} /* Table terminator */
@@ -150,7 +166,7 @@ static const struct acpi_repair_info acpi_ns_repairable_names[] = {
150 * 166 *
151 * FUNCTION: acpi_ns_complex_repairs 167 * FUNCTION: acpi_ns_complex_repairs
152 * 168 *
153 * PARAMETERS: data - Pointer to validation data structure 169 * PARAMETERS: info - Method execution information block
154 * node - Namespace node for the method/object 170 * node - Namespace node for the method/object
155 * validate_status - Original status of earlier validation 171 * validate_status - Original status of earlier validation
156 * return_object_ptr - Pointer to the object returned from the 172 * return_object_ptr - Pointer to the object returned from the
@@ -165,7 +181,7 @@ static const struct acpi_repair_info acpi_ns_repairable_names[] = {
165 *****************************************************************************/ 181 *****************************************************************************/
166 182
167acpi_status 183acpi_status
168acpi_ns_complex_repairs(struct acpi_predefined_data *data, 184acpi_ns_complex_repairs(struct acpi_evaluate_info *info,
169 struct acpi_namespace_node *node, 185 struct acpi_namespace_node *node,
170 acpi_status validate_status, 186 acpi_status validate_status,
171 union acpi_operand_object **return_object_ptr) 187 union acpi_operand_object **return_object_ptr)
@@ -180,7 +196,7 @@ acpi_ns_complex_repairs(struct acpi_predefined_data *data,
180 return (validate_status); 196 return (validate_status);
181 } 197 }
182 198
183 status = predefined->repair_function(data, return_object_ptr); 199 status = predefined->repair_function(info, return_object_ptr);
184 return (status); 200 return (status);
185} 201}
186 202
@@ -219,7 +235,7 @@ static const struct acpi_repair_info *acpi_ns_match_complex_repair(struct
219 * 235 *
220 * FUNCTION: acpi_ns_repair_ALR 236 * FUNCTION: acpi_ns_repair_ALR
221 * 237 *
222 * PARAMETERS: data - Pointer to validation data structure 238 * PARAMETERS: info - Method execution information block
223 * return_object_ptr - Pointer to the object returned from the 239 * return_object_ptr - Pointer to the object returned from the
224 * evaluation of a method or object 240 * evaluation of a method or object
225 * 241 *
@@ -231,13 +247,13 @@ static const struct acpi_repair_info *acpi_ns_match_complex_repair(struct
231 *****************************************************************************/ 247 *****************************************************************************/
232 248
233static acpi_status 249static acpi_status
234acpi_ns_repair_ALR(struct acpi_predefined_data *data, 250acpi_ns_repair_ALR(struct acpi_evaluate_info *info,
235 union acpi_operand_object **return_object_ptr) 251 union acpi_operand_object **return_object_ptr)
236{ 252{
237 union acpi_operand_object *return_object = *return_object_ptr; 253 union acpi_operand_object *return_object = *return_object_ptr;
238 acpi_status status; 254 acpi_status status;
239 255
240 status = acpi_ns_check_sorted_list(data, return_object, 2, 1, 256 status = acpi_ns_check_sorted_list(info, return_object, 0, 2, 1,
241 ACPI_SORT_ASCENDING, 257 ACPI_SORT_ASCENDING,
242 "AmbientIlluminance"); 258 "AmbientIlluminance");
243 259
@@ -248,7 +264,7 @@ acpi_ns_repair_ALR(struct acpi_predefined_data *data,
248 * 264 *
249 * FUNCTION: acpi_ns_repair_FDE 265 * FUNCTION: acpi_ns_repair_FDE
250 * 266 *
251 * PARAMETERS: data - Pointer to validation data structure 267 * PARAMETERS: info - Method execution information block
252 * return_object_ptr - Pointer to the object returned from the 268 * return_object_ptr - Pointer to the object returned from the
253 * evaluation of a method or object 269 * evaluation of a method or object
254 * 270 *
@@ -262,7 +278,7 @@ acpi_ns_repair_ALR(struct acpi_predefined_data *data,
262 *****************************************************************************/ 278 *****************************************************************************/
263 279
264static acpi_status 280static acpi_status
265acpi_ns_repair_FDE(struct acpi_predefined_data *data, 281acpi_ns_repair_FDE(struct acpi_evaluate_info *info,
266 union acpi_operand_object **return_object_ptr) 282 union acpi_operand_object **return_object_ptr)
267{ 283{
268 union acpi_operand_object *return_object = *return_object_ptr; 284 union acpi_operand_object *return_object = *return_object_ptr;
@@ -285,8 +301,8 @@ acpi_ns_repair_FDE(struct acpi_predefined_data *data,
285 /* We can only repair if we have exactly 5 BYTEs */ 301 /* We can only repair if we have exactly 5 BYTEs */
286 302
287 if (return_object->buffer.length != ACPI_FDE_BYTE_BUFFER_SIZE) { 303 if (return_object->buffer.length != ACPI_FDE_BYTE_BUFFER_SIZE) {
288 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, 304 ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname,
289 data->node_flags, 305 info->node_flags,
290 "Incorrect return buffer length %u, expected %u", 306 "Incorrect return buffer length %u, expected %u",
291 return_object->buffer.length, 307 return_object->buffer.length,
292 ACPI_FDE_DWORD_BUFFER_SIZE)); 308 ACPI_FDE_DWORD_BUFFER_SIZE));
@@ -316,10 +332,11 @@ acpi_ns_repair_FDE(struct acpi_predefined_data *data,
316 332
317 ACPI_DEBUG_PRINT((ACPI_DB_REPAIR, 333 ACPI_DEBUG_PRINT((ACPI_DB_REPAIR,
318 "%s Expanded Byte Buffer to expected DWord Buffer\n", 334 "%s Expanded Byte Buffer to expected DWord Buffer\n",
319 data->pathname)); 335 info->full_pathname));
320 break; 336 break;
321 337
322 default: 338 default:
339
323 return (AE_AML_OPERAND_TYPE); 340 return (AE_AML_OPERAND_TYPE);
324 } 341 }
325 342
@@ -328,7 +345,7 @@ acpi_ns_repair_FDE(struct acpi_predefined_data *data,
328 acpi_ut_remove_reference(return_object); 345 acpi_ut_remove_reference(return_object);
329 *return_object_ptr = buffer_object; 346 *return_object_ptr = buffer_object;
330 347
331 data->flags |= ACPI_OBJECT_REPAIRED; 348 info->return_flags |= ACPI_OBJECT_REPAIRED;
332 return (AE_OK); 349 return (AE_OK);
333} 350}
334 351
@@ -336,7 +353,7 @@ acpi_ns_repair_FDE(struct acpi_predefined_data *data,
336 * 353 *
337 * FUNCTION: acpi_ns_repair_CID 354 * FUNCTION: acpi_ns_repair_CID
338 * 355 *
339 * PARAMETERS: data - Pointer to validation data structure 356 * PARAMETERS: info - Method execution information block
340 * return_object_ptr - Pointer to the object returned from the 357 * return_object_ptr - Pointer to the object returned from the
341 * evaluation of a method or object 358 * evaluation of a method or object
342 * 359 *
@@ -349,7 +366,7 @@ acpi_ns_repair_FDE(struct acpi_predefined_data *data,
349 *****************************************************************************/ 366 *****************************************************************************/
350 367
351static acpi_status 368static acpi_status
352acpi_ns_repair_CID(struct acpi_predefined_data *data, 369acpi_ns_repair_CID(struct acpi_evaluate_info *info,
353 union acpi_operand_object **return_object_ptr) 370 union acpi_operand_object **return_object_ptr)
354{ 371{
355 acpi_status status; 372 acpi_status status;
@@ -362,7 +379,7 @@ acpi_ns_repair_CID(struct acpi_predefined_data *data,
362 /* Check for _CID as a simple string */ 379 /* Check for _CID as a simple string */
363 380
364 if (return_object->common.type == ACPI_TYPE_STRING) { 381 if (return_object->common.type == ACPI_TYPE_STRING) {
365 status = acpi_ns_repair_HID(data, return_object_ptr); 382 status = acpi_ns_repair_HID(info, return_object_ptr);
366 return (status); 383 return (status);
367 } 384 }
368 385
@@ -379,7 +396,7 @@ acpi_ns_repair_CID(struct acpi_predefined_data *data,
379 original_element = *element_ptr; 396 original_element = *element_ptr;
380 original_ref_count = original_element->common.reference_count; 397 original_ref_count = original_element->common.reference_count;
381 398
382 status = acpi_ns_repair_HID(data, element_ptr); 399 status = acpi_ns_repair_HID(info, element_ptr);
383 if (ACPI_FAILURE(status)) { 400 if (ACPI_FAILURE(status)) {
384 return (status); 401 return (status);
385 } 402 }
@@ -404,9 +421,95 @@ acpi_ns_repair_CID(struct acpi_predefined_data *data,
404 421
405/****************************************************************************** 422/******************************************************************************
406 * 423 *
424 * FUNCTION: acpi_ns_repair_CST
425 *
426 * PARAMETERS: info - Method execution information block
427 * return_object_ptr - Pointer to the object returned from the
428 * evaluation of a method or object
429 *
430 * RETURN: Status. AE_OK if object is OK or was repaired successfully
431 *
432 * DESCRIPTION: Repair for the _CST object:
433 * 1. Sort the list ascending by C state type
434 * 2. Ensure type cannot be zero
435 * 3. A sub-package count of zero means _CST is meaningless
436 * 4. Count must match the number of C state sub-packages
437 *
438 *****************************************************************************/
439
440static acpi_status
441acpi_ns_repair_CST(struct acpi_evaluate_info *info,
442 union acpi_operand_object **return_object_ptr)
443{
444 union acpi_operand_object *return_object = *return_object_ptr;
445 union acpi_operand_object **outer_elements;
446 u32 outer_element_count;
447 union acpi_operand_object *obj_desc;
448 acpi_status status;
449 u8 removing;
450 u32 i;
451
452 ACPI_FUNCTION_NAME(ns_repair_CST);
453
454 /*
455 * Check if the C-state type values are proportional.
456 */
457 outer_element_count = return_object->package.count - 1;
458 i = 0;
459 while (i < outer_element_count) {
460 outer_elements = &return_object->package.elements[i + 1];
461 removing = FALSE;
462
463 if ((*outer_elements)->package.count == 0) {
464 ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname,
465 info->node_flags,
466 "SubPackage[%u] - removing entry due to zero count",
467 i));
468 removing = TRUE;
469 goto remove_element;
470 }
471
472 obj_desc = (*outer_elements)->package.elements[1]; /* Index1 = Type */
473 if ((u32)obj_desc->integer.value == 0) {
474 ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname,
475 info->node_flags,
476 "SubPackage[%u] - removing entry due to invalid Type(0)",
477 i));
478 removing = TRUE;
479 }
480
481 remove_element:
482 if (removing) {
483 acpi_ns_remove_element(return_object, i + 1);
484 outer_element_count--;
485 } else {
486 i++;
487 }
488 }
489
490 /* Update top-level package count, Type "Integer" checked elsewhere */
491
492 obj_desc = return_object->package.elements[0];
493 obj_desc->integer.value = outer_element_count;
494
495 /*
496 * Entries (subpackages) in the _CST Package must be sorted by the
497 * C-state type, in ascending order.
498 */
499 status = acpi_ns_check_sorted_list(info, return_object, 1, 4, 1,
500 ACPI_SORT_ASCENDING, "C-State Type");
501 if (ACPI_FAILURE(status)) {
502 return (status);
503 }
504
505 return (AE_OK);
506}
507
508/******************************************************************************
509 *
407 * FUNCTION: acpi_ns_repair_HID 510 * FUNCTION: acpi_ns_repair_HID
408 * 511 *
409 * PARAMETERS: data - Pointer to validation data structure 512 * PARAMETERS: info - Method execution information block
410 * return_object_ptr - Pointer to the object returned from the 513 * return_object_ptr - Pointer to the object returned from the
411 * evaluation of a method or object 514 * evaluation of a method or object
412 * 515 *
@@ -418,7 +521,7 @@ acpi_ns_repair_CID(struct acpi_predefined_data *data,
418 *****************************************************************************/ 521 *****************************************************************************/
419 522
420static acpi_status 523static acpi_status
421acpi_ns_repair_HID(struct acpi_predefined_data *data, 524acpi_ns_repair_HID(struct acpi_evaluate_info *info,
422 union acpi_operand_object **return_object_ptr) 525 union acpi_operand_object **return_object_ptr)
423{ 526{
424 union acpi_operand_object *return_object = *return_object_ptr; 527 union acpi_operand_object *return_object = *return_object_ptr;
@@ -435,12 +538,13 @@ acpi_ns_repair_HID(struct acpi_predefined_data *data,
435 } 538 }
436 539
437 if (return_object->string.length == 0) { 540 if (return_object->string.length == 0) {
438 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags, 541 ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname,
542 info->node_flags,
439 "Invalid zero-length _HID or _CID string")); 543 "Invalid zero-length _HID or _CID string"));
440 544
441 /* Return AE_OK anyway, let driver handle it */ 545 /* Return AE_OK anyway, let driver handle it */
442 546
443 data->flags |= ACPI_OBJECT_REPAIRED; 547 info->return_flags |= ACPI_OBJECT_REPAIRED;
444 return (AE_OK); 548 return (AE_OK);
445 } 549 }
446 550
@@ -464,7 +568,7 @@ acpi_ns_repair_HID(struct acpi_predefined_data *data,
464 568
465 ACPI_DEBUG_PRINT((ACPI_DB_REPAIR, 569 ACPI_DEBUG_PRINT((ACPI_DB_REPAIR,
466 "%s: Removed invalid leading asterisk\n", 570 "%s: Removed invalid leading asterisk\n",
467 data->pathname)); 571 info->full_pathname));
468 } 572 }
469 573
470 /* 574 /*
@@ -486,53 +590,69 @@ acpi_ns_repair_HID(struct acpi_predefined_data *data,
486 590
487/****************************************************************************** 591/******************************************************************************
488 * 592 *
489 * FUNCTION: acpi_ns_repair_TSS 593 * FUNCTION: acpi_ns_repair_PRT
490 * 594 *
491 * PARAMETERS: data - Pointer to validation data structure 595 * PARAMETERS: info - Method execution information block
492 * return_object_ptr - Pointer to the object returned from the 596 * return_object_ptr - Pointer to the object returned from the
493 * evaluation of a method or object 597 * evaluation of a method or object
494 * 598 *
495 * RETURN: Status. AE_OK if object is OK or was repaired successfully 599 * RETURN: Status. AE_OK if object is OK or was repaired successfully
496 * 600 *
497 * DESCRIPTION: Repair for the _TSS object. If necessary, sort the object list 601 * DESCRIPTION: Repair for the _PRT object. If necessary, fix reversed
498 * descending by the power dissipation values. 602 * source_name and source_index field, a common BIOS bug.
499 * 603 *
500 *****************************************************************************/ 604 *****************************************************************************/
501 605
502static acpi_status 606static acpi_status
503acpi_ns_repair_TSS(struct acpi_predefined_data *data, 607acpi_ns_repair_PRT(struct acpi_evaluate_info *info,
504 union acpi_operand_object **return_object_ptr) 608 union acpi_operand_object **return_object_ptr)
505{ 609{
506 union acpi_operand_object *return_object = *return_object_ptr; 610 union acpi_operand_object *package_object = *return_object_ptr;
507 acpi_status status; 611 union acpi_operand_object **top_object_list;
508 struct acpi_namespace_node *node; 612 union acpi_operand_object **sub_object_list;
613 union acpi_operand_object *obj_desc;
614 u32 element_count;
615 u32 index;
509 616
510 /* 617 /* Each element in the _PRT package is a subpackage */
511 * We can only sort the _TSS return package if there is no _PSS in the
512 * same scope. This is because if _PSS is present, the ACPI specification
513 * dictates that the _TSS Power Dissipation field is to be ignored, and
514 * therefore some BIOSs leave garbage values in the _TSS Power field(s).
515 * In this case, it is best to just return the _TSS package as-is.
516 * (May, 2011)
517 */
518 status =
519 acpi_ns_get_node(data->node, "^_PSS", ACPI_NS_NO_UPSEARCH, &node);
520 if (ACPI_SUCCESS(status)) {
521 return (AE_OK);
522 }
523 618
524 status = acpi_ns_check_sorted_list(data, return_object, 5, 1, 619 top_object_list = package_object->package.elements;
525 ACPI_SORT_DESCENDING, 620 element_count = package_object->package.count;
526 "PowerDissipation");
527 621
528 return (status); 622 for (index = 0; index < element_count; index++) {
623 sub_object_list = (*top_object_list)->package.elements;
624
625 /*
626 * If the BIOS has erroneously reversed the _PRT source_name (index 2)
627 * and the source_index (index 3), fix it. _PRT is important enough to
628 * workaround this BIOS error. This also provides compatibility with
629 * other ACPI implementations.
630 */
631 obj_desc = sub_object_list[3];
632 if (!obj_desc || (obj_desc->common.type != ACPI_TYPE_INTEGER)) {
633 sub_object_list[3] = sub_object_list[2];
634 sub_object_list[2] = obj_desc;
635 info->return_flags |= ACPI_OBJECT_REPAIRED;
636
637 ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname,
638 info->node_flags,
639 "PRT[%X]: Fixed reversed SourceName and SourceIndex",
640 index));
641 }
642
643 /* Point to the next union acpi_operand_object in the top level package */
644
645 top_object_list++;
646 }
647
648 return (AE_OK);
529} 649}
530 650
531/****************************************************************************** 651/******************************************************************************
532 * 652 *
533 * FUNCTION: acpi_ns_repair_PSS 653 * FUNCTION: acpi_ns_repair_PSS
534 * 654 *
535 * PARAMETERS: data - Pointer to validation data structure 655 * PARAMETERS: info - Method execution information block
536 * return_object_ptr - Pointer to the object returned from the 656 * return_object_ptr - Pointer to the object returned from the
537 * evaluation of a method or object 657 * evaluation of a method or object
538 * 658 *
@@ -546,7 +666,7 @@ acpi_ns_repair_TSS(struct acpi_predefined_data *data,
546 *****************************************************************************/ 666 *****************************************************************************/
547 667
548static acpi_status 668static acpi_status
549acpi_ns_repair_PSS(struct acpi_predefined_data *data, 669acpi_ns_repair_PSS(struct acpi_evaluate_info *info,
550 union acpi_operand_object **return_object_ptr) 670 union acpi_operand_object **return_object_ptr)
551{ 671{
552 union acpi_operand_object *return_object = *return_object_ptr; 672 union acpi_operand_object *return_object = *return_object_ptr;
@@ -564,7 +684,7 @@ acpi_ns_repair_PSS(struct acpi_predefined_data *data,
564 * incorrectly sorted, sort it. We sort by cpu_frequency, since this 684 * incorrectly sorted, sort it. We sort by cpu_frequency, since this
565 * should be proportional to the power. 685 * should be proportional to the power.
566 */ 686 */
567 status = acpi_ns_check_sorted_list(data, return_object, 6, 0, 687 status = acpi_ns_check_sorted_list(info, return_object, 0, 6, 0,
568 ACPI_SORT_DESCENDING, 688 ACPI_SORT_DESCENDING,
569 "CpuFrequency"); 689 "CpuFrequency");
570 if (ACPI_FAILURE(status)) { 690 if (ACPI_FAILURE(status)) {
@@ -584,8 +704,8 @@ acpi_ns_repair_PSS(struct acpi_predefined_data *data,
584 obj_desc = elements[1]; /* Index1 = power_dissipation */ 704 obj_desc = elements[1]; /* Index1 = power_dissipation */
585 705
586 if ((u32) obj_desc->integer.value > previous_value) { 706 if ((u32) obj_desc->integer.value > previous_value) {
587 ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, 707 ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname,
588 data->node_flags, 708 info->node_flags,
589 "SubPackage[%u,%u] - suspicious power dissipation values", 709 "SubPackage[%u,%u] - suspicious power dissipation values",
590 i - 1, i)); 710 i - 1, i));
591 } 711 }
@@ -599,10 +719,55 @@ acpi_ns_repair_PSS(struct acpi_predefined_data *data,
599 719
600/****************************************************************************** 720/******************************************************************************
601 * 721 *
722 * FUNCTION: acpi_ns_repair_TSS
723 *
724 * PARAMETERS: info - Method execution information block
725 * return_object_ptr - Pointer to the object returned from the
726 * evaluation of a method or object
727 *
728 * RETURN: Status. AE_OK if object is OK or was repaired successfully
729 *
730 * DESCRIPTION: Repair for the _TSS object. If necessary, sort the object list
731 * descending by the power dissipation values.
732 *
733 *****************************************************************************/
734
735static acpi_status
736acpi_ns_repair_TSS(struct acpi_evaluate_info *info,
737 union acpi_operand_object **return_object_ptr)
738{
739 union acpi_operand_object *return_object = *return_object_ptr;
740 acpi_status status;
741 struct acpi_namespace_node *node;
742
743 /*
744 * We can only sort the _TSS return package if there is no _PSS in the
745 * same scope. This is because if _PSS is present, the ACPI specification
746 * dictates that the _TSS Power Dissipation field is to be ignored, and
747 * therefore some BIOSs leave garbage values in the _TSS Power field(s).
748 * In this case, it is best to just return the _TSS package as-is.
749 * (May, 2011)
750 */
751 status = acpi_ns_get_node(info->node, "^_PSS",
752 ACPI_NS_NO_UPSEARCH, &node);
753 if (ACPI_SUCCESS(status)) {
754 return (AE_OK);
755 }
756
757 status = acpi_ns_check_sorted_list(info, return_object, 0, 5, 1,
758 ACPI_SORT_DESCENDING,
759 "PowerDissipation");
760
761 return (status);
762}
763
764/******************************************************************************
765 *
602 * FUNCTION: acpi_ns_check_sorted_list 766 * FUNCTION: acpi_ns_check_sorted_list
603 * 767 *
604 * PARAMETERS: data - Pointer to validation data structure 768 * PARAMETERS: info - Method execution information block
605 * return_object - Pointer to the top-level returned object 769 * return_object - Pointer to the top-level returned object
770 * start_index - Index of the first sub-package
606 * expected_count - Minimum length of each sub-package 771 * expected_count - Minimum length of each sub-package
607 * sort_index - Sub-package entry to sort on 772 * sort_index - Sub-package entry to sort on
608 * sort_direction - Ascending or descending 773 * sort_direction - Ascending or descending
@@ -617,8 +782,9 @@ acpi_ns_repair_PSS(struct acpi_predefined_data *data,
617 *****************************************************************************/ 782 *****************************************************************************/
618 783
619static acpi_status 784static acpi_status
620acpi_ns_check_sorted_list(struct acpi_predefined_data *data, 785acpi_ns_check_sorted_list(struct acpi_evaluate_info *info,
621 union acpi_operand_object *return_object, 786 union acpi_operand_object *return_object,
787 u32 start_index,
622 u32 expected_count, 788 u32 expected_count,
623 u32 sort_index, 789 u32 sort_index,
624 u8 sort_direction, char *sort_key_name) 790 u8 sort_direction, char *sort_key_name)
@@ -643,12 +809,14 @@ acpi_ns_check_sorted_list(struct acpi_predefined_data *data,
643 * Any NULL elements should have been removed by earlier call 809 * Any NULL elements should have been removed by earlier call
644 * to acpi_ns_remove_null_elements. 810 * to acpi_ns_remove_null_elements.
645 */ 811 */
646 outer_elements = return_object->package.elements;
647 outer_element_count = return_object->package.count; 812 outer_element_count = return_object->package.count;
648 if (!outer_element_count) { 813 if (!outer_element_count || start_index >= outer_element_count) {
649 return (AE_AML_PACKAGE_LIMIT); 814 return (AE_AML_PACKAGE_LIMIT);
650 } 815 }
651 816
817 outer_elements = &return_object->package.elements[start_index];
818 outer_element_count -= start_index;
819
652 previous_value = 0; 820 previous_value = 0;
653 if (sort_direction == ACPI_SORT_DESCENDING) { 821 if (sort_direction == ACPI_SORT_DESCENDING) {
654 previous_value = ACPI_UINT32_MAX; 822 previous_value = ACPI_UINT32_MAX;
@@ -685,15 +853,16 @@ acpi_ns_check_sorted_list(struct acpi_predefined_data *data,
685 (obj_desc->integer.value < previous_value)) || 853 (obj_desc->integer.value < previous_value)) ||
686 ((sort_direction == ACPI_SORT_DESCENDING) && 854 ((sort_direction == ACPI_SORT_DESCENDING) &&
687 (obj_desc->integer.value > previous_value))) { 855 (obj_desc->integer.value > previous_value))) {
688 acpi_ns_sort_list(return_object->package.elements, 856 acpi_ns_sort_list(&return_object->package.
857 elements[start_index],
689 outer_element_count, sort_index, 858 outer_element_count, sort_index,
690 sort_direction); 859 sort_direction);
691 860
692 data->flags |= ACPI_OBJECT_REPAIRED; 861 info->return_flags |= ACPI_OBJECT_REPAIRED;
693 862
694 ACPI_DEBUG_PRINT((ACPI_DB_REPAIR, 863 ACPI_DEBUG_PRINT((ACPI_DB_REPAIR,
695 "%s: Repaired unsorted list - now sorted by %s\n", 864 "%s: Repaired unsorted list - now sorted by %s\n",
696 data->pathname, sort_key_name)); 865 info->full_pathname, sort_key_name));
697 return (AE_OK); 866 return (AE_OK);
698 } 867 }
699 868
@@ -752,3 +921,52 @@ acpi_ns_sort_list(union acpi_operand_object **elements,
752 } 921 }
753 } 922 }
754} 923}
924
925/******************************************************************************
926 *
927 * FUNCTION: acpi_ns_remove_element
928 *
929 * PARAMETERS: obj_desc - Package object element list
930 * index - Index of element to remove
931 *
932 * RETURN: None
933 *
934 * DESCRIPTION: Remove the requested element of a package and delete it.
935 *
936 *****************************************************************************/
937
938static void
939acpi_ns_remove_element(union acpi_operand_object *obj_desc, u32 index)
940{
941 union acpi_operand_object **source;
942 union acpi_operand_object **dest;
943 u32 count;
944 u32 new_count;
945 u32 i;
946
947 ACPI_FUNCTION_NAME(ns_remove_element);
948
949 count = obj_desc->package.count;
950 new_count = count - 1;
951
952 source = obj_desc->package.elements;
953 dest = source;
954
955 /* Examine all elements of the package object, remove matched index */
956
957 for (i = 0; i < count; i++) {
958 if (i == index) {
959 acpi_ut_remove_reference(*source); /* Remove one ref for being in pkg */
960 acpi_ut_remove_reference(*source);
961 } else {
962 *dest = *source;
963 dest++;
964 }
965 source++;
966 }
967
968 /* NULL terminate list and update the package count */
969
970 *dest = NULL;
971 obj_desc->package.count = new_count;
972}
diff --git a/drivers/acpi/acpica/nsutils.c b/drivers/acpi/acpica/nsutils.c
index 2808586fad30..08c0b5beec88 100644
--- a/drivers/acpi/acpica/nsutils.c
+++ b/drivers/acpi/acpica/nsutils.c
@@ -419,10 +419,12 @@ acpi_ns_externalize_name(u32 internal_name_length,
419 419
420 switch (internal_name[0]) { 420 switch (internal_name[0]) {
421 case AML_ROOT_PREFIX: 421 case AML_ROOT_PREFIX:
422
422 prefix_length = 1; 423 prefix_length = 1;
423 break; 424 break;
424 425
425 case AML_PARENT_PREFIX: 426 case AML_PARENT_PREFIX:
427
426 for (i = 0; i < internal_name_length; i++) { 428 for (i = 0; i < internal_name_length; i++) {
427 if (ACPI_IS_PARENT_PREFIX(internal_name[i])) { 429 if (ACPI_IS_PARENT_PREFIX(internal_name[i])) {
428 prefix_length = i + 1; 430 prefix_length = i + 1;
@@ -438,6 +440,7 @@ acpi_ns_externalize_name(u32 internal_name_length,
438 break; 440 break;
439 441
440 default: 442 default:
443
441 break; 444 break;
442 } 445 }
443 446
diff --git a/drivers/acpi/acpica/nsxfeval.c b/drivers/acpi/acpica/nsxfeval.c
index fc69949151bb..f553cfdb71dd 100644
--- a/drivers/acpi/acpica/nsxfeval.c
+++ b/drivers/acpi/acpica/nsxfeval.c
@@ -187,8 +187,6 @@ acpi_evaluate_object(acpi_handle handle,
187 return_ACPI_STATUS(AE_NO_MEMORY); 187 return_ACPI_STATUS(AE_NO_MEMORY);
188 } 188 }
189 189
190 info->pathname = pathname;
191
192 /* Convert and validate the device handle */ 190 /* Convert and validate the device handle */
193 191
194 info->prefix_node = acpi_ns_validate_handle(handle); 192 info->prefix_node = acpi_ns_validate_handle(handle);
@@ -198,17 +196,64 @@ acpi_evaluate_object(acpi_handle handle,
198 } 196 }
199 197
200 /* 198 /*
201 * If there are parameters to be passed to a control method, the external 199 * Get the actual namespace node for the target object.
202 * objects must all be converted to internal objects 200 * Handles these cases:
201 *
202 * 1) Null node, valid pathname from root (absolute path)
203 * 2) Node and valid pathname (path relative to Node)
204 * 3) Node, Null pathname
205 */
206 if ((pathname) && (ACPI_IS_ROOT_PREFIX(pathname[0]))) {
207
208 /* The path is fully qualified, just evaluate by name */
209
210 info->prefix_node = NULL;
211 } else if (!handle) {
212 /*
213 * A handle is optional iff a fully qualified pathname is specified.
214 * Since we've already handled fully qualified names above, this is
215 * an error.
216 */
217 if (!pathname) {
218 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
219 "Both Handle and Pathname are NULL"));
220 } else {
221 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
222 "Null Handle with relative pathname [%s]",
223 pathname));
224 }
225
226 status = AE_BAD_PARAMETER;
227 goto cleanup;
228 }
229
230 info->relative_pathname = pathname;
231
232 /*
233 * Convert all external objects passed as arguments to the
234 * internal version(s).
203 */ 235 */
204 if (external_params && external_params->count) { 236 if (external_params && external_params->count) {
237 info->param_count = (u16)external_params->count;
238
239 /* Warn on impossible argument count */
240
241 if (info->param_count > ACPI_METHOD_NUM_ARGS) {
242 ACPI_WARN_PREDEFINED((AE_INFO, pathname,
243 ACPI_WARN_ALWAYS,
244 "Excess arguments (%u) - using only %u",
245 info->param_count,
246 ACPI_METHOD_NUM_ARGS));
247
248 info->param_count = ACPI_METHOD_NUM_ARGS;
249 }
250
205 /* 251 /*
206 * Allocate a new parameter block for the internal objects 252 * Allocate a new parameter block for the internal objects
207 * Add 1 to count to allow for null terminated internal list 253 * Add 1 to count to allow for null terminated internal list
208 */ 254 */
209 info->parameters = ACPI_ALLOCATE_ZEROED(((acpi_size) 255 info->parameters = ACPI_ALLOCATE_ZEROED(((acpi_size) info->
210 external_params-> 256 param_count +
211 count +
212 1) * sizeof(void *)); 257 1) * sizeof(void *));
213 if (!info->parameters) { 258 if (!info->parameters) {
214 status = AE_NO_MEMORY; 259 status = AE_NO_MEMORY;
@@ -217,7 +262,7 @@ acpi_evaluate_object(acpi_handle handle,
217 262
218 /* Convert each external object in the list to an internal object */ 263 /* Convert each external object in the list to an internal object */
219 264
220 for (i = 0; i < external_params->count; i++) { 265 for (i = 0; i < info->param_count; i++) {
221 status = 266 status =
222 acpi_ut_copy_eobject_to_iobject(&external_params-> 267 acpi_ut_copy_eobject_to_iobject(&external_params->
223 pointer[i], 268 pointer[i],
@@ -227,43 +272,96 @@ acpi_evaluate_object(acpi_handle handle,
227 goto cleanup; 272 goto cleanup;
228 } 273 }
229 } 274 }
230 info->parameters[external_params->count] = NULL; 275
276 info->parameters[info->param_count] = NULL;
231 } 277 }
232 278
279#if 0
280
233 /* 281 /*
234 * Three major cases: 282 * Begin incoming argument count analysis. Check for too few args
235 * 1) Fully qualified pathname 283 * and too many args.
236 * 2) No handle, not fully qualified pathname (error)
237 * 3) Valid handle
238 */ 284 */
239 if ((pathname) && (ACPI_IS_ROOT_PREFIX(pathname[0]))) {
240 285
241 /* The path is fully qualified, just evaluate by name */ 286 switch (acpi_ns_get_type(info->node)) {
287 case ACPI_TYPE_METHOD:
288
289 /* Check incoming argument count against the method definition */
290
291 if (info->obj_desc->method.param_count > info->param_count) {
292 ACPI_ERROR((AE_INFO,
293 "Insufficient arguments (%u) - %u are required",
294 info->param_count,
295 info->obj_desc->method.param_count));
296
297 status = AE_MISSING_ARGUMENTS;
298 goto cleanup;
299 }
300
301 else if (info->obj_desc->method.param_count < info->param_count) {
302 ACPI_WARNING((AE_INFO,
303 "Excess arguments (%u) - only %u are required",
304 info->param_count,
305 info->obj_desc->method.param_count));
306
307 /* Just pass the required number of arguments */
308
309 info->param_count = info->obj_desc->method.param_count;
310 }
242 311
243 info->prefix_node = NULL;
244 status = acpi_ns_evaluate(info);
245 } else if (!handle) {
246 /* 312 /*
247 * A handle is optional iff a fully qualified pathname is specified. 313 * Any incoming external objects to be passed as arguments to the
248 * Since we've already handled fully qualified names above, this is 314 * method must be converted to internal objects
249 * an error
250 */ 315 */
251 if (!pathname) { 316 if (info->param_count) {
252 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 317 /*
253 "Both Handle and Pathname are NULL")); 318 * Allocate a new parameter block for the internal objects
254 } else { 319 * Add 1 to count to allow for null terminated internal list
255 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 320 */
256 "Null Handle with relative pathname [%s]", 321 info->parameters = ACPI_ALLOCATE_ZEROED(((acpi_size)
257 pathname)); 322 info->
323 param_count +
324 1) *
325 sizeof(void *));
326 if (!info->parameters) {
327 status = AE_NO_MEMORY;
328 goto cleanup;
329 }
330
331 /* Convert each external object in the list to an internal object */
332
333 for (i = 0; i < info->param_count; i++) {
334 status =
335 acpi_ut_copy_eobject_to_iobject
336 (&external_params->pointer[i],
337 &info->parameters[i]);
338 if (ACPI_FAILURE(status)) {
339 goto cleanup;
340 }
341 }
342
343 info->parameters[info->param_count] = NULL;
258 } 344 }
345 break;
259 346
260 status = AE_BAD_PARAMETER; 347 default:
261 } else { 348
262 /* We have a namespace a node and a possible relative path */ 349 /* Warn if arguments passed to an object that is not a method */
263 350
264 status = acpi_ns_evaluate(info); 351 if (info->param_count) {
352 ACPI_WARNING((AE_INFO,
353 "%u arguments were passed to a non-method ACPI object",
354 info->param_count));
355 }
356 break;
265 } 357 }
266 358
359#endif
360
361 /* Now we can evaluate the object */
362
363 status = acpi_ns_evaluate(info);
364
267 /* 365 /*
268 * If we are expecting a return value, and all went well above, 366 * If we are expecting a return value, and all went well above,
269 * copy the return value to an external object. 367 * copy the return value to an external object.
@@ -413,6 +511,7 @@ static void acpi_ns_resolve_references(struct acpi_evaluate_info *info)
413 break; 511 break;
414 512
415 default: 513 default:
514
416 return; 515 return;
417 } 516 }
418 517
diff --git a/drivers/acpi/acpica/psargs.c b/drivers/acpi/acpica/psargs.c
index 9f25a3d4e992..91a5a69db80c 100644
--- a/drivers/acpi/acpica/psargs.c
+++ b/drivers/acpi/acpica/psargs.c
@@ -629,24 +629,28 @@ static union acpi_parse_object *acpi_ps_get_next_field(struct acpi_parse_state
629 629
630 switch (opcode) { 630 switch (opcode) {
631 case AML_BYTE_OP: /* AML_BYTEDATA_ARG */ 631 case AML_BYTE_OP: /* AML_BYTEDATA_ARG */
632
632 buffer_length = 633 buffer_length =
633 ACPI_GET8(parser_state->aml); 634 ACPI_GET8(parser_state->aml);
634 parser_state->aml += 1; 635 parser_state->aml += 1;
635 break; 636 break;
636 637
637 case AML_WORD_OP: /* AML_WORDDATA_ARG */ 638 case AML_WORD_OP: /* AML_WORDDATA_ARG */
639
638 buffer_length = 640 buffer_length =
639 ACPI_GET16(parser_state->aml); 641 ACPI_GET16(parser_state->aml);
640 parser_state->aml += 2; 642 parser_state->aml += 2;
641 break; 643 break;
642 644
643 case AML_DWORD_OP: /* AML_DWORDATA_ARG */ 645 case AML_DWORD_OP: /* AML_DWORDATA_ARG */
646
644 buffer_length = 647 buffer_length =
645 ACPI_GET32(parser_state->aml); 648 ACPI_GET32(parser_state->aml);
646 parser_state->aml += 4; 649 parser_state->aml += 4;
647 break; 650 break;
648 651
649 default: 652 default:
653
650 buffer_length = 0; 654 buffer_length = 0;
651 break; 655 break;
652 } 656 }
diff --git a/drivers/acpi/acpica/psloop.c b/drivers/acpi/acpica/psloop.c
index 63c455447481..065b44ae538f 100644
--- a/drivers/acpi/acpica/psloop.c
+++ b/drivers/acpi/acpica/psloop.c
@@ -164,7 +164,6 @@ acpi_ps_get_arguments(struct acpi_walk_state *walk_state,
164 case AML_IF_OP: 164 case AML_IF_OP:
165 case AML_ELSE_OP: 165 case AML_ELSE_OP:
166 case AML_WHILE_OP: 166 case AML_WHILE_OP:
167
168 /* 167 /*
169 * Currently supported module-level opcodes are: 168 * Currently supported module-level opcodes are:
170 * IF/ELSE/WHILE. These appear to be the most common, 169 * IF/ELSE/WHILE. These appear to be the most common,
@@ -289,6 +288,7 @@ acpi_ps_get_arguments(struct acpi_walk_state *walk_state,
289 default: 288 default:
290 289
291 /* No action for all other opcodes */ 290 /* No action for all other opcodes */
291
292 break; 292 break;
293 } 293 }
294 294
diff --git a/drivers/acpi/acpica/psobject.c b/drivers/acpi/acpica/psobject.c
index 12c4028002b1..95dc608a66a8 100644
--- a/drivers/acpi/acpica/psobject.c
+++ b/drivers/acpi/acpica/psobject.c
@@ -402,6 +402,7 @@ acpi_ps_complete_op(struct acpi_walk_state *walk_state,
402 402
403 switch (status) { 403 switch (status) {
404 case AE_OK: 404 case AE_OK:
405
405 break; 406 break;
406 407
407 case AE_CTRL_TRANSFER: 408 case AE_CTRL_TRANSFER:
diff --git a/drivers/acpi/acpica/psparse.c b/drivers/acpi/acpica/psparse.c
index abc4c48b2edd..86198a9139b5 100644
--- a/drivers/acpi/acpica/psparse.c
+++ b/drivers/acpi/acpica/psparse.c
@@ -176,10 +176,10 @@ acpi_ps_complete_this_op(struct acpi_walk_state * walk_state,
176 176
177 switch (parent_info->class) { 177 switch (parent_info->class) {
178 case AML_CLASS_CONTROL: 178 case AML_CLASS_CONTROL:
179
179 break; 180 break;
180 181
181 case AML_CLASS_CREATE: 182 case AML_CLASS_CREATE:
182
183 /* 183 /*
184 * These opcodes contain term_arg operands. The current 184 * These opcodes contain term_arg operands. The current
185 * op must be replaced by a placeholder return op 185 * op must be replaced by a placeholder return op
@@ -192,7 +192,6 @@ acpi_ps_complete_this_op(struct acpi_walk_state * walk_state,
192 break; 192 break;
193 193
194 case AML_CLASS_NAMED_OBJECT: 194 case AML_CLASS_NAMED_OBJECT:
195
196 /* 195 /*
197 * These opcodes contain term_arg operands. The current 196 * These opcodes contain term_arg operands. The current
198 * op must be replaced by a placeholder return op 197 * op must be replaced by a placeholder return op
diff --git a/drivers/acpi/acpica/pstree.c b/drivers/acpi/acpica/pstree.c
index c1934bf04f0a..877dc0de8df3 100644
--- a/drivers/acpi/acpica/pstree.c
+++ b/drivers/acpi/acpica/pstree.c
@@ -308,7 +308,9 @@ union acpi_parse_object *acpi_ps_get_child(union acpi_parse_object *op)
308 break; 308 break;
309 309
310 default: 310 default:
311
311 /* All others have no children */ 312 /* All others have no children */
313
312 break; 314 break;
313 } 315 }
314 316
diff --git a/drivers/acpi/acpica/psxface.c b/drivers/acpi/acpica/psxface.c
index f68254268965..11b99ab20bb3 100644
--- a/drivers/acpi/acpica/psxface.c
+++ b/drivers/acpi/acpica/psxface.c
@@ -125,7 +125,7 @@ static void acpi_ps_start_trace(struct acpi_evaluate_info *info)
125 } 125 }
126 126
127 if ((!acpi_gbl_trace_method_name) || 127 if ((!acpi_gbl_trace_method_name) ||
128 (acpi_gbl_trace_method_name != info->resolved_node->name.integer)) { 128 (acpi_gbl_trace_method_name != info->node->name.integer)) {
129 goto exit; 129 goto exit;
130 } 130 }
131 131
@@ -170,7 +170,7 @@ static void acpi_ps_stop_trace(struct acpi_evaluate_info *info)
170 } 170 }
171 171
172 if ((!acpi_gbl_trace_method_name) || 172 if ((!acpi_gbl_trace_method_name) ||
173 (acpi_gbl_trace_method_name != info->resolved_node->name.integer)) { 173 (acpi_gbl_trace_method_name != info->node->name.integer)) {
174 goto exit; 174 goto exit;
175 } 175 }
176 176
@@ -226,15 +226,14 @@ acpi_status acpi_ps_execute_method(struct acpi_evaluate_info *info)
226 226
227 /* Validate the Info and method Node */ 227 /* Validate the Info and method Node */
228 228
229 if (!info || !info->resolved_node) { 229 if (!info || !info->node) {
230 return_ACPI_STATUS(AE_NULL_ENTRY); 230 return_ACPI_STATUS(AE_NULL_ENTRY);
231 } 231 }
232 232
233 /* Init for new method, wait on concurrency semaphore */ 233 /* Init for new method, wait on concurrency semaphore */
234 234
235 status = 235 status =
236 acpi_ds_begin_method_execution(info->resolved_node, info->obj_desc, 236 acpi_ds_begin_method_execution(info->node, info->obj_desc, NULL);
237 NULL);
238 if (ACPI_FAILURE(status)) { 237 if (ACPI_FAILURE(status)) {
239 return_ACPI_STATUS(status); 238 return_ACPI_STATUS(status);
240 } 239 }
@@ -253,8 +252,7 @@ acpi_status acpi_ps_execute_method(struct acpi_evaluate_info *info)
253 */ 252 */
254 ACPI_DEBUG_PRINT((ACPI_DB_PARSE, 253 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
255 "**** Begin Method Parse/Execute [%4.4s] **** Node=%p Obj=%p\n", 254 "**** Begin Method Parse/Execute [%4.4s] **** Node=%p Obj=%p\n",
256 info->resolved_node->name.ascii, info->resolved_node, 255 info->node->name.ascii, info->node, info->obj_desc));
257 info->obj_desc));
258 256
259 /* Create and init a Root Node */ 257 /* Create and init a Root Node */
260 258
@@ -275,7 +273,7 @@ acpi_status acpi_ps_execute_method(struct acpi_evaluate_info *info)
275 goto cleanup; 273 goto cleanup;
276 } 274 }
277 275
278 status = acpi_ds_init_aml_walk(walk_state, op, info->resolved_node, 276 status = acpi_ds_init_aml_walk(walk_state, op, info->node,
279 info->obj_desc->method.aml_start, 277 info->obj_desc->method.aml_start,
280 info->obj_desc->method.aml_length, info, 278 info->obj_desc->method.aml_length, info,
281 info->pass_number); 279 info->pass_number);
diff --git a/drivers/acpi/acpica/rscalc.c b/drivers/acpi/acpica/rscalc.c
index 72077fa1eea5..b62a0f4f4f9b 100644
--- a/drivers/acpi/acpica/rscalc.c
+++ b/drivers/acpi/acpica/rscalc.c
@@ -352,6 +352,7 @@ acpi_rs_get_aml_length(struct acpi_resource * resource, acpi_size * size_needed)
352 break; 352 break;
353 353
354 default: 354 default:
355
355 break; 356 break;
356 } 357 }
357 358
@@ -539,6 +540,7 @@ acpi_rs_get_list_length(u8 * aml_buffer,
539 break; 540 break;
540 541
541 default: 542 default:
543
542 break; 544 break;
543 } 545 }
544 546
@@ -650,8 +652,9 @@ acpi_rs_get_pci_routing_table_length(union acpi_operand_object *package_object,
650 652
651 name_found = FALSE; 653 name_found = FALSE;
652 654
653 for (table_index = 0; table_index < 4 && !name_found; 655 for (table_index = 0;
654 table_index++) { 656 table_index < package_element->package.count
657 && !name_found; table_index++) {
655 if (*sub_object_list && /* Null object allowed */ 658 if (*sub_object_list && /* Null object allowed */
656 ((ACPI_TYPE_STRING == 659 ((ACPI_TYPE_STRING ==
657 (*sub_object_list)->common.type) || 660 (*sub_object_list)->common.type) ||
diff --git a/drivers/acpi/acpica/rscreate.c b/drivers/acpi/acpica/rscreate.c
index f8b55b426c9d..65f3e1c5b598 100644
--- a/drivers/acpi/acpica/rscreate.c
+++ b/drivers/acpi/acpica/rscreate.c
@@ -273,17 +273,6 @@ acpi_rs_create_pci_routing_table(union acpi_operand_object *package_object,
273 */ 273 */
274 user_prt->length = (sizeof(struct acpi_pci_routing_table) - 4); 274 user_prt->length = (sizeof(struct acpi_pci_routing_table) - 4);
275 275
276 /* Each element of the top-level package must also be a package */
277
278 if ((*top_object_list)->common.type != ACPI_TYPE_PACKAGE) {
279 ACPI_ERROR((AE_INFO,
280 "(PRT[%u]) Need sub-package, found %s",
281 index,
282 acpi_ut_get_object_type_name
283 (*top_object_list)));
284 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
285 }
286
287 /* Each sub-package must be of length 4 */ 276 /* Each sub-package must be of length 4 */
288 277
289 if ((*top_object_list)->package.count != 4) { 278 if ((*top_object_list)->package.count != 4) {
@@ -327,22 +316,6 @@ acpi_rs_create_pci_routing_table(union acpi_operand_object *package_object,
327 user_prt->pin = (u32) obj_desc->integer.value; 316 user_prt->pin = (u32) obj_desc->integer.value;
328 317
329 /* 318 /*
330 * If the BIOS has erroneously reversed the _PRT source_name (index 2)
331 * and the source_index (index 3), fix it. _PRT is important enough to
332 * workaround this BIOS error. This also provides compatibility with
333 * other ACPI implementations.
334 */
335 obj_desc = sub_object_list[3];
336 if (!obj_desc || (obj_desc->common.type != ACPI_TYPE_INTEGER)) {
337 sub_object_list[3] = sub_object_list[2];
338 sub_object_list[2] = obj_desc;
339
340 ACPI_WARNING((AE_INFO,
341 "(PRT[%X].Source) SourceName and SourceIndex are reversed, fixed",
342 index));
343 }
344
345 /*
346 * 3) Third subobject: Dereference the PRT.source_name 319 * 3) Third subobject: Dereference the PRT.source_name
347 * The name may be unresolved (slack mode), so allow a null object 320 * The name may be unresolved (slack mode), so allow a null object
348 */ 321 */
diff --git a/drivers/acpi/acpica/rsdump.c b/drivers/acpi/acpica/rsdump.c
index b5fc0db2e87b..8a2d4986b0aa 100644
--- a/drivers/acpi/acpica/rsdump.c
+++ b/drivers/acpi/acpica/rsdump.c
@@ -120,17 +120,20 @@ acpi_rs_dump_descriptor(void *resource, struct acpi_rsdump_info *table)
120 /* Strings */ 120 /* Strings */
121 121
122 case ACPI_RSD_LITERAL: 122 case ACPI_RSD_LITERAL:
123
123 acpi_rs_out_string(name, 124 acpi_rs_out_string(name,
124 ACPI_CAST_PTR(char, table->pointer)); 125 ACPI_CAST_PTR(char, table->pointer));
125 break; 126 break;
126 127
127 case ACPI_RSD_STRING: 128 case ACPI_RSD_STRING:
129
128 acpi_rs_out_string(name, ACPI_CAST_PTR(char, target)); 130 acpi_rs_out_string(name, ACPI_CAST_PTR(char, target));
129 break; 131 break;
130 132
131 /* Data items, 8/16/32/64 bit */ 133 /* Data items, 8/16/32/64 bit */
132 134
133 case ACPI_RSD_UINT8: 135 case ACPI_RSD_UINT8:
136
134 if (table->pointer) { 137 if (table->pointer) {
135 acpi_rs_out_string(name, ACPI_CAST_PTR(char, 138 acpi_rs_out_string(name, ACPI_CAST_PTR(char,
136 table-> 139 table->
@@ -142,20 +145,24 @@ acpi_rs_dump_descriptor(void *resource, struct acpi_rsdump_info *table)
142 break; 145 break;
143 146
144 case ACPI_RSD_UINT16: 147 case ACPI_RSD_UINT16:
148
145 acpi_rs_out_integer16(name, ACPI_GET16(target)); 149 acpi_rs_out_integer16(name, ACPI_GET16(target));
146 break; 150 break;
147 151
148 case ACPI_RSD_UINT32: 152 case ACPI_RSD_UINT32:
153
149 acpi_rs_out_integer32(name, ACPI_GET32(target)); 154 acpi_rs_out_integer32(name, ACPI_GET32(target));
150 break; 155 break;
151 156
152 case ACPI_RSD_UINT64: 157 case ACPI_RSD_UINT64:
158
153 acpi_rs_out_integer64(name, ACPI_GET64(target)); 159 acpi_rs_out_integer64(name, ACPI_GET64(target));
154 break; 160 break;
155 161
156 /* Flags: 1-bit and 2-bit flags supported */ 162 /* Flags: 1-bit and 2-bit flags supported */
157 163
158 case ACPI_RSD_1BITFLAG: 164 case ACPI_RSD_1BITFLAG:
165
159 acpi_rs_out_string(name, ACPI_CAST_PTR(char, 166 acpi_rs_out_string(name, ACPI_CAST_PTR(char,
160 table-> 167 table->
161 pointer[*target & 168 pointer[*target &
@@ -163,6 +170,7 @@ acpi_rs_dump_descriptor(void *resource, struct acpi_rsdump_info *table)
163 break; 170 break;
164 171
165 case ACPI_RSD_2BITFLAG: 172 case ACPI_RSD_2BITFLAG:
173
166 acpi_rs_out_string(name, ACPI_CAST_PTR(char, 174 acpi_rs_out_string(name, ACPI_CAST_PTR(char,
167 table-> 175 table->
168 pointer[*target & 176 pointer[*target &
@@ -170,6 +178,7 @@ acpi_rs_dump_descriptor(void *resource, struct acpi_rsdump_info *table)
170 break; 178 break;
171 179
172 case ACPI_RSD_3BITFLAG: 180 case ACPI_RSD_3BITFLAG:
181
173 acpi_rs_out_string(name, ACPI_CAST_PTR(char, 182 acpi_rs_out_string(name, ACPI_CAST_PTR(char,
174 table-> 183 table->
175 pointer[*target & 184 pointer[*target &
@@ -258,6 +267,7 @@ acpi_rs_dump_descriptor(void *resource, struct acpi_rsdump_info *table)
258 break; 267 break;
259 268
260 default: 269 default:
270
261 acpi_os_printf("**** Invalid table opcode [%X] ****\n", 271 acpi_os_printf("**** Invalid table opcode [%X] ****\n",
262 table->opcode); 272 table->opcode);
263 return; 273 return;
diff --git a/drivers/acpi/acpica/rsmisc.c b/drivers/acpi/acpica/rsmisc.c
index d5bf05a96096..80d12994e0d0 100644
--- a/drivers/acpi/acpica/rsmisc.c
+++ b/drivers/acpi/acpica/rsmisc.c
@@ -194,7 +194,6 @@ acpi_rs_convert_aml_to_resource(struct acpi_resource *resource,
194 break; 194 break;
195 195
196 case ACPI_RSC_COUNT_GPIO_RES: 196 case ACPI_RSC_COUNT_GPIO_RES:
197
198 /* 197 /*
199 * Vendor data is optional (length/offset may both be zero) 198 * Vendor data is optional (length/offset may both be zero)
200 * Examine vendor data length field first 199 * Examine vendor data length field first
@@ -410,12 +409,14 @@ acpi_rs_convert_aml_to_resource(struct acpi_resource *resource,
410 */ 409 */
411 switch (info->resource_offset) { 410 switch (info->resource_offset) {
412 case ACPI_RSC_COMPARE_AML_LENGTH: 411 case ACPI_RSC_COMPARE_AML_LENGTH:
412
413 if (aml_resource_length != info->value) { 413 if (aml_resource_length != info->value) {
414 goto exit; 414 goto exit;
415 } 415 }
416 break; 416 break;
417 417
418 case ACPI_RSC_COMPARE_VALUE: 418 case ACPI_RSC_COMPARE_VALUE:
419
419 if (ACPI_GET8(source) != info->value) { 420 if (ACPI_GET8(source) != info->value) {
420 goto exit; 421 goto exit;
421 } 422 }
diff --git a/drivers/acpi/acpica/rsutils.c b/drivers/acpi/acpica/rsutils.c
index a44953c6f75d..480b6b40c5ea 100644
--- a/drivers/acpi/acpica/rsutils.c
+++ b/drivers/acpi/acpica/rsutils.c
@@ -147,6 +147,7 @@ acpi_rs_move_data(void *destination, void *source, u16 item_count, u8 move_type)
147 case ACPI_RSC_MOVE_GPIO_RES: 147 case ACPI_RSC_MOVE_GPIO_RES:
148 case ACPI_RSC_MOVE_SERIAL_VEN: 148 case ACPI_RSC_MOVE_SERIAL_VEN:
149 case ACPI_RSC_MOVE_SERIAL_RES: 149 case ACPI_RSC_MOVE_SERIAL_RES:
150
150 ACPI_MEMCPY(destination, source, item_count); 151 ACPI_MEMCPY(destination, source, item_count);
151 return; 152 return;
152 153
@@ -157,21 +158,25 @@ acpi_rs_move_data(void *destination, void *source, u16 item_count, u8 move_type)
157 */ 158 */
158 case ACPI_RSC_MOVE16: 159 case ACPI_RSC_MOVE16:
159 case ACPI_RSC_MOVE_GPIO_PIN: 160 case ACPI_RSC_MOVE_GPIO_PIN:
161
160 ACPI_MOVE_16_TO_16(&ACPI_CAST_PTR(u16, destination)[i], 162 ACPI_MOVE_16_TO_16(&ACPI_CAST_PTR(u16, destination)[i],
161 &ACPI_CAST_PTR(u16, source)[i]); 163 &ACPI_CAST_PTR(u16, source)[i]);
162 break; 164 break;
163 165
164 case ACPI_RSC_MOVE32: 166 case ACPI_RSC_MOVE32:
167
165 ACPI_MOVE_32_TO_32(&ACPI_CAST_PTR(u32, destination)[i], 168 ACPI_MOVE_32_TO_32(&ACPI_CAST_PTR(u32, destination)[i],
166 &ACPI_CAST_PTR(u32, source)[i]); 169 &ACPI_CAST_PTR(u32, source)[i]);
167 break; 170 break;
168 171
169 case ACPI_RSC_MOVE64: 172 case ACPI_RSC_MOVE64:
173
170 ACPI_MOVE_64_TO_64(&ACPI_CAST_PTR(u64, destination)[i], 174 ACPI_MOVE_64_TO_64(&ACPI_CAST_PTR(u64, destination)[i],
171 &ACPI_CAST_PTR(u64, source)[i]); 175 &ACPI_CAST_PTR(u64, source)[i]);
172 break; 176 break;
173 177
174 default: 178 default:
179
175 return; 180 return;
176 } 181 }
177 } 182 }
@@ -736,7 +741,7 @@ acpi_rs_set_srs_method_data(struct acpi_namespace_node *node,
736 } 741 }
737 742
738 info->prefix_node = node; 743 info->prefix_node = node;
739 info->pathname = METHOD_NAME__SRS; 744 info->relative_pathname = METHOD_NAME__SRS;
740 info->parameters = args; 745 info->parameters = args;
741 info->flags = ACPI_IGNORE_RETURN_VALUE; 746 info->flags = ACPI_IGNORE_RETURN_VALUE;
742 747
diff --git a/drivers/acpi/acpica/rsxface.c b/drivers/acpi/acpica/rsxface.c
index c0e5d2d3ce67..94e3517554f9 100644
--- a/drivers/acpi/acpica/rsxface.c
+++ b/drivers/acpi/acpica/rsxface.c
@@ -402,6 +402,7 @@ acpi_resource_to_address64(struct acpi_resource *resource,
402 break; 402 break;
403 403
404 default: 404 default:
405
405 return (AE_BAD_PARAMETER); 406 return (AE_BAD_PARAMETER);
406 } 407 }
407 408
diff --git a/drivers/acpi/acpica/tbinstal.c b/drivers/acpi/acpica/tbinstal.c
index e57cd38004e3..42a13c0d7015 100644
--- a/drivers/acpi/acpica/tbinstal.c
+++ b/drivers/acpi/acpica/tbinstal.c
@@ -141,8 +141,7 @@ acpi_tb_add_table(struct acpi_table_desc *table_desc, u32 *table_index)
141 ACPI_BIOS_ERROR((AE_INFO, 141 ACPI_BIOS_ERROR((AE_INFO,
142 "Table has invalid signature [%4.4s] (0x%8.8X), " 142 "Table has invalid signature [%4.4s] (0x%8.8X), "
143 "must be SSDT or OEMx", 143 "must be SSDT or OEMx",
144 acpi_ut_valid_acpi_name(*(u32 *)table_desc-> 144 acpi_ut_valid_acpi_name(table_desc->pointer->
145 pointer->
146 signature) ? 145 signature) ?
147 table_desc->pointer->signature : "????", 146 table_desc->pointer->signature : "????",
148 *(u32 *)table_desc->pointer->signature)); 147 *(u32 *)table_desc->pointer->signature));
@@ -471,15 +470,19 @@ void acpi_tb_delete_table(struct acpi_table_desc *table_desc)
471 } 470 }
472 switch (table_desc->flags & ACPI_TABLE_ORIGIN_MASK) { 471 switch (table_desc->flags & ACPI_TABLE_ORIGIN_MASK) {
473 case ACPI_TABLE_ORIGIN_MAPPED: 472 case ACPI_TABLE_ORIGIN_MAPPED:
473
474 acpi_os_unmap_memory(table_desc->pointer, table_desc->length); 474 acpi_os_unmap_memory(table_desc->pointer, table_desc->length);
475 break; 475 break;
476
476 case ACPI_TABLE_ORIGIN_ALLOCATED: 477 case ACPI_TABLE_ORIGIN_ALLOCATED:
478
477 ACPI_FREE(table_desc->pointer); 479 ACPI_FREE(table_desc->pointer);
478 break; 480 break;
479 481
480 /* Not mapped or allocated, there is nothing we can do */ 482 /* Not mapped or allocated, there is nothing we can do */
481 483
482 default: 484 default:
485
483 return; 486 return;
484 } 487 }
485 488
diff --git a/drivers/acpi/acpica/tbprint.c b/drivers/acpi/acpica/tbprint.c
new file mode 100644
index 000000000000..dc963f823d2c
--- /dev/null
+++ b/drivers/acpi/acpica/tbprint.c
@@ -0,0 +1,237 @@
1/******************************************************************************
2 *
3 * Module Name: tbprint - Table output utilities
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2013, 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
48#define _COMPONENT ACPI_TABLES
49ACPI_MODULE_NAME("tbprint")
50
51/* Local prototypes */
52static void acpi_tb_fix_string(char *string, acpi_size length);
53
54static void
55acpi_tb_cleanup_table_header(struct acpi_table_header *out_header,
56 struct acpi_table_header *header);
57
58/*******************************************************************************
59 *
60 * FUNCTION: acpi_tb_fix_string
61 *
62 * PARAMETERS: string - String to be repaired
63 * length - Maximum length
64 *
65 * RETURN: None
66 *
67 * DESCRIPTION: Replace every non-printable or non-ascii byte in the string
68 * with a question mark '?'.
69 *
70 ******************************************************************************/
71
72static void acpi_tb_fix_string(char *string, acpi_size length)
73{
74
75 while (length && *string) {
76 if (!ACPI_IS_PRINT(*string)) {
77 *string = '?';
78 }
79 string++;
80 length--;
81 }
82}
83
84/*******************************************************************************
85 *
86 * FUNCTION: acpi_tb_cleanup_table_header
87 *
88 * PARAMETERS: out_header - Where the cleaned header is returned
89 * header - Input ACPI table header
90 *
91 * RETURN: Returns the cleaned header in out_header
92 *
93 * DESCRIPTION: Copy the table header and ensure that all "string" fields in
94 * the header consist of printable characters.
95 *
96 ******************************************************************************/
97
98static void
99acpi_tb_cleanup_table_header(struct acpi_table_header *out_header,
100 struct acpi_table_header *header)
101{
102
103 ACPI_MEMCPY(out_header, header, sizeof(struct acpi_table_header));
104
105 acpi_tb_fix_string(out_header->signature, ACPI_NAME_SIZE);
106 acpi_tb_fix_string(out_header->oem_id, ACPI_OEM_ID_SIZE);
107 acpi_tb_fix_string(out_header->oem_table_id, ACPI_OEM_TABLE_ID_SIZE);
108 acpi_tb_fix_string(out_header->asl_compiler_id, ACPI_NAME_SIZE);
109}
110
111/*******************************************************************************
112 *
113 * FUNCTION: acpi_tb_print_table_header
114 *
115 * PARAMETERS: address - Table physical address
116 * header - Table header
117 *
118 * RETURN: None
119 *
120 * DESCRIPTION: Print an ACPI table header. Special cases for FACS and RSDP.
121 *
122 ******************************************************************************/
123
124void
125acpi_tb_print_table_header(acpi_physical_address address,
126 struct acpi_table_header *header)
127{
128 struct acpi_table_header local_header;
129
130 /*
131 * The reason that the Address is cast to a void pointer is so that we
132 * can use %p which will work properly on both 32-bit and 64-bit hosts.
133 */
134 if (ACPI_COMPARE_NAME(header->signature, ACPI_SIG_FACS)) {
135
136 /* FACS only has signature and length fields */
137
138 ACPI_INFO((AE_INFO, "%4.4s %p %05X",
139 header->signature, ACPI_CAST_PTR(void, address),
140 header->length));
141 } else if (ACPI_COMPARE_NAME(header->signature, ACPI_SIG_RSDP)) {
142
143 /* RSDP has no common fields */
144
145 ACPI_MEMCPY(local_header.oem_id,
146 ACPI_CAST_PTR(struct acpi_table_rsdp,
147 header)->oem_id, ACPI_OEM_ID_SIZE);
148 acpi_tb_fix_string(local_header.oem_id, ACPI_OEM_ID_SIZE);
149
150 ACPI_INFO((AE_INFO, "RSDP %p %05X (v%.2d %6.6s)",
151 ACPI_CAST_PTR(void, address),
152 (ACPI_CAST_PTR(struct acpi_table_rsdp, header)->
153 revision >
154 0) ? ACPI_CAST_PTR(struct acpi_table_rsdp,
155 header)->length : 20,
156 ACPI_CAST_PTR(struct acpi_table_rsdp,
157 header)->revision,
158 local_header.oem_id));
159 } else {
160 /* Standard ACPI table with full common header */
161
162 acpi_tb_cleanup_table_header(&local_header, header);
163
164 ACPI_INFO((AE_INFO,
165 "%4.4s %p %05X (v%.2d %6.6s %8.8s %08X %4.4s %08X)",
166 local_header.signature, ACPI_CAST_PTR(void, address),
167 local_header.length, local_header.revision,
168 local_header.oem_id, local_header.oem_table_id,
169 local_header.oem_revision,
170 local_header.asl_compiler_id,
171 local_header.asl_compiler_revision));
172 }
173}
174
175/*******************************************************************************
176 *
177 * FUNCTION: acpi_tb_validate_checksum
178 *
179 * PARAMETERS: table - ACPI table to verify
180 * length - Length of entire table
181 *
182 * RETURN: Status
183 *
184 * DESCRIPTION: Verifies that the table checksums to zero. Optionally returns
185 * exception on bad checksum.
186 *
187 ******************************************************************************/
188
189acpi_status acpi_tb_verify_checksum(struct acpi_table_header *table, u32 length)
190{
191 u8 checksum;
192
193 /* Compute the checksum on the table */
194
195 checksum = acpi_tb_checksum(ACPI_CAST_PTR(u8, table), length);
196
197 /* Checksum ok? (should be zero) */
198
199 if (checksum) {
200 ACPI_BIOS_WARNING((AE_INFO,
201 "Incorrect checksum in table [%4.4s] - 0x%2.2X, "
202 "should be 0x%2.2X",
203 table->signature, table->checksum,
204 (u8)(table->checksum - checksum)));
205
206#if (ACPI_CHECKSUM_ABORT)
207 return (AE_BAD_CHECKSUM);
208#endif
209 }
210
211 return (AE_OK);
212}
213
214/*******************************************************************************
215 *
216 * FUNCTION: acpi_tb_checksum
217 *
218 * PARAMETERS: buffer - Pointer to memory region to be checked
219 * length - Length of this memory region
220 *
221 * RETURN: Checksum (u8)
222 *
223 * DESCRIPTION: Calculates circular checksum of memory region.
224 *
225 ******************************************************************************/
226
227u8 acpi_tb_checksum(u8 *buffer, u32 length)
228{
229 u8 sum = 0;
230 u8 *end = buffer + length;
231
232 while (buffer < end) {
233 sum = (u8)(sum + *(buffer++));
234 }
235
236 return (sum);
237}
diff --git a/drivers/acpi/acpica/tbutils.c b/drivers/acpi/acpica/tbutils.c
index ce3d5db39a9c..bffdfc7b8322 100644
--- a/drivers/acpi/acpica/tbutils.c
+++ b/drivers/acpi/acpica/tbutils.c
@@ -1,6 +1,6 @@
1/****************************************************************************** 1/******************************************************************************
2 * 2 *
3 * Module Name: tbutils - table utilities 3 * Module Name: tbutils - ACPI Table utilities
4 * 4 *
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
@@ -49,12 +49,6 @@
49ACPI_MODULE_NAME("tbutils") 49ACPI_MODULE_NAME("tbutils")
50 50
51/* Local prototypes */ 51/* Local prototypes */
52static void acpi_tb_fix_string(char *string, acpi_size length);
53
54static void
55acpi_tb_cleanup_table_header(struct acpi_table_header *out_header,
56 struct acpi_table_header *header);
57
58static acpi_physical_address 52static acpi_physical_address
59acpi_tb_get_root_table_entry(u8 *table_entry, u32 table_entry_size); 53acpi_tb_get_root_table_entry(u8 *table_entry, u32 table_entry_size);
60 54
@@ -176,189 +170,6 @@ u8 acpi_tb_tables_loaded(void)
176 170
177/******************************************************************************* 171/*******************************************************************************
178 * 172 *
179 * FUNCTION: acpi_tb_fix_string
180 *
181 * PARAMETERS: string - String to be repaired
182 * length - Maximum length
183 *
184 * RETURN: None
185 *
186 * DESCRIPTION: Replace every non-printable or non-ascii byte in the string
187 * with a question mark '?'.
188 *
189 ******************************************************************************/
190
191static void acpi_tb_fix_string(char *string, acpi_size length)
192{
193
194 while (length && *string) {
195 if (!ACPI_IS_PRINT(*string)) {
196 *string = '?';
197 }
198 string++;
199 length--;
200 }
201}
202
203/*******************************************************************************
204 *
205 * FUNCTION: acpi_tb_cleanup_table_header
206 *
207 * PARAMETERS: out_header - Where the cleaned header is returned
208 * header - Input ACPI table header
209 *
210 * RETURN: Returns the cleaned header in out_header
211 *
212 * DESCRIPTION: Copy the table header and ensure that all "string" fields in
213 * the header consist of printable characters.
214 *
215 ******************************************************************************/
216
217static void
218acpi_tb_cleanup_table_header(struct acpi_table_header *out_header,
219 struct acpi_table_header *header)
220{
221
222 ACPI_MEMCPY(out_header, header, sizeof(struct acpi_table_header));
223
224 acpi_tb_fix_string(out_header->signature, ACPI_NAME_SIZE);
225 acpi_tb_fix_string(out_header->oem_id, ACPI_OEM_ID_SIZE);
226 acpi_tb_fix_string(out_header->oem_table_id, ACPI_OEM_TABLE_ID_SIZE);
227 acpi_tb_fix_string(out_header->asl_compiler_id, ACPI_NAME_SIZE);
228}
229
230/*******************************************************************************
231 *
232 * FUNCTION: acpi_tb_print_table_header
233 *
234 * PARAMETERS: address - Table physical address
235 * header - Table header
236 *
237 * RETURN: None
238 *
239 * DESCRIPTION: Print an ACPI table header. Special cases for FACS and RSDP.
240 *
241 ******************************************************************************/
242
243void
244acpi_tb_print_table_header(acpi_physical_address address,
245 struct acpi_table_header *header)
246{
247 struct acpi_table_header local_header;
248
249 /*
250 * The reason that the Address is cast to a void pointer is so that we
251 * can use %p which will work properly on both 32-bit and 64-bit hosts.
252 */
253 if (ACPI_COMPARE_NAME(header->signature, ACPI_SIG_FACS)) {
254
255 /* FACS only has signature and length fields */
256
257 ACPI_INFO((AE_INFO, "%4.4s %p %05X",
258 header->signature, ACPI_CAST_PTR(void, address),
259 header->length));
260 } else if (ACPI_COMPARE_NAME(header->signature, ACPI_SIG_RSDP)) {
261
262 /* RSDP has no common fields */
263
264 ACPI_MEMCPY(local_header.oem_id,
265 ACPI_CAST_PTR(struct acpi_table_rsdp,
266 header)->oem_id, ACPI_OEM_ID_SIZE);
267 acpi_tb_fix_string(local_header.oem_id, ACPI_OEM_ID_SIZE);
268
269 ACPI_INFO((AE_INFO, "RSDP %p %05X (v%.2d %6.6s)",
270 ACPI_CAST_PTR (void, address),
271 (ACPI_CAST_PTR(struct acpi_table_rsdp, header)->
272 revision >
273 0) ? ACPI_CAST_PTR(struct acpi_table_rsdp,
274 header)->length : 20,
275 ACPI_CAST_PTR(struct acpi_table_rsdp,
276 header)->revision,
277 local_header.oem_id));
278 } else {
279 /* Standard ACPI table with full common header */
280
281 acpi_tb_cleanup_table_header(&local_header, header);
282
283 ACPI_INFO((AE_INFO,
284 "%4.4s %p %05X (v%.2d %6.6s %8.8s %08X %4.4s %08X)",
285 local_header.signature, ACPI_CAST_PTR(void, address),
286 local_header.length, local_header.revision,
287 local_header.oem_id, local_header.oem_table_id,
288 local_header.oem_revision,
289 local_header.asl_compiler_id,
290 local_header.asl_compiler_revision));
291
292 }
293}
294
295/*******************************************************************************
296 *
297 * FUNCTION: acpi_tb_validate_checksum
298 *
299 * PARAMETERS: table - ACPI table to verify
300 * length - Length of entire table
301 *
302 * RETURN: Status
303 *
304 * DESCRIPTION: Verifies that the table checksums to zero. Optionally returns
305 * exception on bad checksum.
306 *
307 ******************************************************************************/
308
309acpi_status acpi_tb_verify_checksum(struct acpi_table_header *table, u32 length)
310{
311 u8 checksum;
312
313 /* Compute the checksum on the table */
314
315 checksum = acpi_tb_checksum(ACPI_CAST_PTR(u8, table), length);
316
317 /* Checksum ok? (should be zero) */
318
319 if (checksum) {
320 ACPI_BIOS_WARNING((AE_INFO,
321 "Incorrect checksum in table [%4.4s] - 0x%2.2X, "
322 "should be 0x%2.2X",
323 table->signature, table->checksum,
324 (u8)(table->checksum - checksum)));
325
326#if (ACPI_CHECKSUM_ABORT)
327
328 return (AE_BAD_CHECKSUM);
329#endif
330 }
331
332 return (AE_OK);
333}
334
335/*******************************************************************************
336 *
337 * FUNCTION: acpi_tb_checksum
338 *
339 * PARAMETERS: buffer - Pointer to memory region to be checked
340 * length - Length of this memory region
341 *
342 * RETURN: Checksum (u8)
343 *
344 * DESCRIPTION: Calculates circular checksum of memory region.
345 *
346 ******************************************************************************/
347
348u8 acpi_tb_checksum(u8 *buffer, u32 length)
349{
350 u8 sum = 0;
351 u8 *end = buffer + length;
352
353 while (buffer < end) {
354 sum = (u8) (sum + *(buffer++));
355 }
356
357 return (sum);
358}
359
360/*******************************************************************************
361 *
362 * FUNCTION: acpi_tb_check_dsdt_header 173 * FUNCTION: acpi_tb_check_dsdt_header
363 * 174 *
364 * PARAMETERS: None 175 * PARAMETERS: None
diff --git a/drivers/acpi/acpica/tbxfload.c b/drivers/acpi/acpica/tbxfload.c
index 67e046ec8f0a..0ba9e328d5d7 100644
--- a/drivers/acpi/acpica/tbxfload.c
+++ b/drivers/acpi/acpica/tbxfload.c
@@ -53,8 +53,6 @@ ACPI_MODULE_NAME("tbxfload")
53/* Local prototypes */ 53/* Local prototypes */
54static acpi_status acpi_tb_load_namespace(void); 54static acpi_status acpi_tb_load_namespace(void);
55 55
56static int no_auto_ssdt;
57
58/******************************************************************************* 56/*******************************************************************************
59 * 57 *
60 * FUNCTION: acpi_load_tables 58 * FUNCTION: acpi_load_tables
@@ -180,8 +178,16 @@ static acpi_status acpi_tb_load_namespace(void)
180 continue; 178 continue;
181 } 179 }
182 180
183 if (no_auto_ssdt) { 181 /*
184 printk(KERN_WARNING "ACPI: SSDT ignored due to \"acpi_no_auto_ssdt\"\n"); 182 * Optionally do not load any SSDTs from the RSDT/XSDT. This can
183 * be useful for debugging ACPI problems on some machines.
184 */
185 if (acpi_gbl_disable_ssdt_table_load) {
186 ACPI_INFO((AE_INFO, "Ignoring %4.4s at %p",
187 acpi_gbl_root_table_list.tables[i].signature.
188 ascii, ACPI_CAST_PTR(void,
189 acpi_gbl_root_table_list.
190 tables[i].address)));
185 continue; 191 continue;
186 } 192 }
187 193
@@ -376,14 +382,3 @@ acpi_status acpi_unload_parent_table(acpi_handle object)
376} 382}
377 383
378ACPI_EXPORT_SYMBOL(acpi_unload_parent_table) 384ACPI_EXPORT_SYMBOL(acpi_unload_parent_table)
379
380static int __init acpi_no_auto_ssdt_setup(char *s) {
381
382 printk(KERN_NOTICE "ACPI: SSDT auto-load disabled\n");
383
384 no_auto_ssdt = 1;
385
386 return 1;
387}
388
389__setup("acpi_no_auto_ssdt", acpi_no_auto_ssdt_setup);
diff --git a/drivers/acpi/acpica/utbuffer.c b/drivers/acpi/acpica/utbuffer.c
new file mode 100644
index 000000000000..11fde93be120
--- /dev/null
+++ b/drivers/acpi/acpica/utbuffer.c
@@ -0,0 +1,201 @@
1/******************************************************************************
2 *
3 * Module Name: utbuffer - Buffer dump routines
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2013, 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("utbuffer")
49
50/*******************************************************************************
51 *
52 * FUNCTION: acpi_ut_dump_buffer
53 *
54 * PARAMETERS: buffer - Buffer to dump
55 * count - Amount to dump, in bytes
56 * display - BYTE, WORD, DWORD, or QWORD display:
57 * DB_BYTE_DISPLAY
58 * DB_WORD_DISPLAY
59 * DB_DWORD_DISPLAY
60 * DB_QWORD_DISPLAY
61 * base_offset - Beginning buffer offset (display only)
62 *
63 * RETURN: None
64 *
65 * DESCRIPTION: Generic dump buffer in both hex and ascii.
66 *
67 ******************************************************************************/
68void acpi_ut_dump_buffer(u8 *buffer, u32 count, u32 display, u32 base_offset)
69{
70 u32 i = 0;
71 u32 j;
72 u32 temp32;
73 u8 buf_char;
74
75 if (!buffer) {
76 acpi_os_printf("Null Buffer Pointer in DumpBuffer!\n");
77 return;
78 }
79
80 if ((count < 4) || (count & 0x01)) {
81 display = DB_BYTE_DISPLAY;
82 }
83
84 /* Nasty little dump buffer routine! */
85
86 while (i < count) {
87
88 /* Print current offset */
89
90 acpi_os_printf("%6.4X: ", (base_offset + i));
91
92 /* Print 16 hex chars */
93
94 for (j = 0; j < 16;) {
95 if (i + j >= count) {
96
97 /* Dump fill spaces */
98
99 acpi_os_printf("%*s", ((display * 2) + 1), " ");
100 j += display;
101 continue;
102 }
103
104 switch (display) {
105 case DB_BYTE_DISPLAY:
106 default: /* Default is BYTE display */
107
108 acpi_os_printf("%02X ",
109 buffer[(acpi_size) i + j]);
110 break;
111
112 case DB_WORD_DISPLAY:
113
114 ACPI_MOVE_16_TO_32(&temp32,
115 &buffer[(acpi_size) i + j]);
116 acpi_os_printf("%04X ", temp32);
117 break;
118
119 case DB_DWORD_DISPLAY:
120
121 ACPI_MOVE_32_TO_32(&temp32,
122 &buffer[(acpi_size) i + j]);
123 acpi_os_printf("%08X ", temp32);
124 break;
125
126 case DB_QWORD_DISPLAY:
127
128 ACPI_MOVE_32_TO_32(&temp32,
129 &buffer[(acpi_size) i + j]);
130 acpi_os_printf("%08X", temp32);
131
132 ACPI_MOVE_32_TO_32(&temp32,
133 &buffer[(acpi_size) i + j +
134 4]);
135 acpi_os_printf("%08X ", temp32);
136 break;
137 }
138
139 j += display;
140 }
141
142 /*
143 * Print the ASCII equivalent characters but watch out for the bad
144 * unprintable ones (printable chars are 0x20 through 0x7E)
145 */
146 acpi_os_printf(" ");
147 for (j = 0; j < 16; j++) {
148 if (i + j >= count) {
149 acpi_os_printf("\n");
150 return;
151 }
152
153 buf_char = buffer[(acpi_size) i + j];
154 if (ACPI_IS_PRINT(buf_char)) {
155 acpi_os_printf("%c", buf_char);
156 } else {
157 acpi_os_printf(".");
158 }
159 }
160
161 /* Done with that line. */
162
163 acpi_os_printf("\n");
164 i += 16;
165 }
166
167 return;
168}
169
170/*******************************************************************************
171 *
172 * FUNCTION: acpi_ut_debug_dump_buffer
173 *
174 * PARAMETERS: buffer - Buffer to dump
175 * count - Amount to dump, in bytes
176 * display - BYTE, WORD, DWORD, or QWORD display:
177 * DB_BYTE_DISPLAY
178 * DB_WORD_DISPLAY
179 * DB_DWORD_DISPLAY
180 * DB_QWORD_DISPLAY
181 * component_ID - Caller's component ID
182 *
183 * RETURN: None
184 *
185 * DESCRIPTION: Generic dump buffer in both hex and ascii.
186 *
187 ******************************************************************************/
188
189void
190acpi_ut_debug_dump_buffer(u8 *buffer, u32 count, u32 display, u32 component_id)
191{
192
193 /* Only dump the buffer if tracing is enabled */
194
195 if (!((ACPI_LV_TABLES & acpi_dbg_level) &&
196 (component_id & acpi_dbg_layer))) {
197 return;
198 }
199
200 acpi_ut_dump_buffer(buffer, count, display, 0);
201}
diff --git a/drivers/acpi/acpica/utcopy.c b/drivers/acpi/acpica/utcopy.c
index e4c9291fc0a3..1731c27c36a6 100644
--- a/drivers/acpi/acpica/utcopy.c
+++ b/drivers/acpi/acpica/utcopy.c
@@ -178,7 +178,6 @@ acpi_ut_copy_isimple_to_esimple(union acpi_operand_object *internal_object,
178 178
179 switch (internal_object->reference.class) { 179 switch (internal_object->reference.class) {
180 case ACPI_REFCLASS_NAME: 180 case ACPI_REFCLASS_NAME:
181
182 /* 181 /*
183 * For namepath, return the object handle ("reference") 182 * For namepath, return the object handle ("reference")
184 * We are referring to the namespace node 183 * We are referring to the namespace node
@@ -264,7 +263,6 @@ acpi_ut_copy_ielement_to_eelement(u8 object_type,
264 263
265 switch (object_type) { 264 switch (object_type) {
266 case ACPI_COPY_TYPE_SIMPLE: 265 case ACPI_COPY_TYPE_SIMPLE:
267
268 /* 266 /*
269 * This is a simple or null object 267 * This is a simple or null object
270 */ 268 */
@@ -278,7 +276,6 @@ acpi_ut_copy_ielement_to_eelement(u8 object_type,
278 break; 276 break;
279 277
280 case ACPI_COPY_TYPE_PACKAGE: 278 case ACPI_COPY_TYPE_PACKAGE:
281
282 /* 279 /*
283 * Build the package object 280 * Build the package object
284 */ 281 */
@@ -304,6 +301,7 @@ acpi_ut_copy_ielement_to_eelement(u8 object_type,
304 break; 301 break;
305 302
306 default: 303 default:
304
307 return (AE_BAD_PARAMETER); 305 return (AE_BAD_PARAMETER);
308 } 306 }
309 307
@@ -481,6 +479,7 @@ acpi_ut_copy_esimple_to_isimple(union acpi_object *external_object,
481 return_ACPI_STATUS(AE_OK); 479 return_ACPI_STATUS(AE_OK);
482 480
483 default: 481 default:
482
484 /* All other types are not supported */ 483 /* All other types are not supported */
485 484
486 ACPI_ERROR((AE_INFO, 485 ACPI_ERROR((AE_INFO,
@@ -544,7 +543,9 @@ acpi_ut_copy_esimple_to_isimple(union acpi_object *external_object,
544 break; 543 break;
545 544
546 default: 545 default:
546
547 /* Other types can't get here */ 547 /* Other types can't get here */
548
548 break; 549 break;
549 } 550 }
550 551
@@ -800,7 +801,9 @@ acpi_ut_copy_simple_object(union acpi_operand_object *source_desc,
800 break; 801 break;
801 802
802 default: 803 default:
804
803 /* Nothing to do for other simple objects */ 805 /* Nothing to do for other simple objects */
806
804 break; 807 break;
805 } 808 }
806 809
@@ -868,7 +871,6 @@ acpi_ut_copy_ielement_to_ielement(u8 object_type,
868 break; 871 break;
869 872
870 case ACPI_COPY_TYPE_PACKAGE: 873 case ACPI_COPY_TYPE_PACKAGE:
871
872 /* 874 /*
873 * This object is a package - go down another nesting level 875 * This object is a package - go down another nesting level
874 * Create and build the package object 876 * Create and build the package object
@@ -891,6 +893,7 @@ acpi_ut_copy_ielement_to_ielement(u8 object_type,
891 break; 893 break;
892 894
893 default: 895 default:
896
894 return (AE_BAD_PARAMETER); 897 return (AE_BAD_PARAMETER);
895 } 898 }
896 899
diff --git a/drivers/acpi/acpica/utdebug.c b/drivers/acpi/acpica/utdebug.c
index c57d9cc07ba9..5796e11a0671 100644
--- a/drivers/acpi/acpica/utdebug.c
+++ b/drivers/acpi/acpica/utdebug.c
@@ -1,6 +1,6 @@
1/****************************************************************************** 1/******************************************************************************
2 * 2 *
3 * Module Name: utdebug - Debug print routines 3 * Module Name: utdebug - Debug print/trace routines
4 * 4 *
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
@@ -543,149 +543,3 @@ acpi_ut_ptr_exit(u32 line_number,
543} 543}
544 544
545#endif 545#endif
546
547/*******************************************************************************
548 *
549 * FUNCTION: acpi_ut_dump_buffer
550 *
551 * PARAMETERS: buffer - Buffer to dump
552 * count - Amount to dump, in bytes
553 * display - BYTE, WORD, DWORD, or QWORD display
554 * offset - Beginning buffer offset (display only)
555 *
556 * RETURN: None
557 *
558 * DESCRIPTION: Generic dump buffer in both hex and ascii.
559 *
560 ******************************************************************************/
561
562void acpi_ut_dump_buffer(u8 *buffer, u32 count, u32 display, u32 base_offset)
563{
564 u32 i = 0;
565 u32 j;
566 u32 temp32;
567 u8 buf_char;
568
569 if (!buffer) {
570 acpi_os_printf("Null Buffer Pointer in DumpBuffer!\n");
571 return;
572 }
573
574 if ((count < 4) || (count & 0x01)) {
575 display = DB_BYTE_DISPLAY;
576 }
577
578 /* Nasty little dump buffer routine! */
579
580 while (i < count) {
581
582 /* Print current offset */
583
584 acpi_os_printf("%6.4X: ", (base_offset + i));
585
586 /* Print 16 hex chars */
587
588 for (j = 0; j < 16;) {
589 if (i + j >= count) {
590
591 /* Dump fill spaces */
592
593 acpi_os_printf("%*s", ((display * 2) + 1), " ");
594 j += display;
595 continue;
596 }
597
598 switch (display) {
599 case DB_BYTE_DISPLAY:
600 default: /* Default is BYTE display */
601
602 acpi_os_printf("%02X ",
603 buffer[(acpi_size) i + j]);
604 break;
605
606 case DB_WORD_DISPLAY:
607
608 ACPI_MOVE_16_TO_32(&temp32,
609 &buffer[(acpi_size) i + j]);
610 acpi_os_printf("%04X ", temp32);
611 break;
612
613 case DB_DWORD_DISPLAY:
614
615 ACPI_MOVE_32_TO_32(&temp32,
616 &buffer[(acpi_size) i + j]);
617 acpi_os_printf("%08X ", temp32);
618 break;
619
620 case DB_QWORD_DISPLAY:
621
622 ACPI_MOVE_32_TO_32(&temp32,
623 &buffer[(acpi_size) i + j]);
624 acpi_os_printf("%08X", temp32);
625
626 ACPI_MOVE_32_TO_32(&temp32,
627 &buffer[(acpi_size) i + j +
628 4]);
629 acpi_os_printf("%08X ", temp32);
630 break;
631 }
632
633 j += display;
634 }
635
636 /*
637 * Print the ASCII equivalent characters but watch out for the bad
638 * unprintable ones (printable chars are 0x20 through 0x7E)
639 */
640 acpi_os_printf(" ");
641 for (j = 0; j < 16; j++) {
642 if (i + j >= count) {
643 acpi_os_printf("\n");
644 return;
645 }
646
647 buf_char = buffer[(acpi_size) i + j];
648 if (ACPI_IS_PRINT(buf_char)) {
649 acpi_os_printf("%c", buf_char);
650 } else {
651 acpi_os_printf(".");
652 }
653 }
654
655 /* Done with that line. */
656
657 acpi_os_printf("\n");
658 i += 16;
659 }
660
661 return;
662}
663
664/*******************************************************************************
665 *
666 * FUNCTION: acpi_ut_debug_dump_buffer
667 *
668 * PARAMETERS: buffer - Buffer to dump
669 * count - Amount to dump, in bytes
670 * display - BYTE, WORD, DWORD, or QWORD display
671 * component_ID - Caller's component ID
672 *
673 * RETURN: None
674 *
675 * DESCRIPTION: Generic dump buffer in both hex and ascii.
676 *
677 ******************************************************************************/
678
679void
680acpi_ut_debug_dump_buffer(u8 *buffer, u32 count, u32 display, u32 component_id)
681{
682
683 /* Only dump the buffer if tracing is enabled */
684
685 if (!((ACPI_LV_TABLES & acpi_dbg_level) &&
686 (component_id & acpi_dbg_layer))) {
687 return;
688 }
689
690 acpi_ut_dump_buffer(buffer, count, display, 0);
691}
diff --git a/drivers/acpi/acpica/utdelete.c b/drivers/acpi/acpica/utdelete.c
index 29b930250b6f..d6b33f29d327 100644
--- a/drivers/acpi/acpica/utdelete.c
+++ b/drivers/acpi/acpica/utdelete.c
@@ -303,6 +303,7 @@ static void acpi_ut_delete_internal_obj(union acpi_operand_object *object)
303 break; 303 break;
304 304
305 default: 305 default:
306
306 break; 307 break;
307 } 308 }
308 309
@@ -508,7 +509,6 @@ acpi_ut_update_object_reference(union acpi_operand_object *object, u16 action)
508 case ACPI_TYPE_PROCESSOR: 509 case ACPI_TYPE_PROCESSOR:
509 case ACPI_TYPE_POWER: 510 case ACPI_TYPE_POWER:
510 case ACPI_TYPE_THERMAL: 511 case ACPI_TYPE_THERMAL:
511
512 /* 512 /*
513 * Update the notify objects for these types (if present) 513 * Update the notify objects for these types (if present)
514 * Two lists, system and device notify handlers. 514 * Two lists, system and device notify handlers.
@@ -623,6 +623,7 @@ acpi_ut_update_object_reference(union acpi_operand_object *object, u16 action)
623 623
624 case ACPI_TYPE_REGION: 624 case ACPI_TYPE_REGION:
625 default: 625 default:
626
626 break; /* No subobjects for all other types */ 627 break; /* No subobjects for all other types */
627 } 628 }
628 629
diff --git a/drivers/acpi/acpica/uterror.c b/drivers/acpi/acpica/uterror.c
new file mode 100644
index 000000000000..154fdcaa5830
--- /dev/null
+++ b/drivers/acpi/acpica/uterror.c
@@ -0,0 +1,289 @@
1/*******************************************************************************
2 *
3 * Module Name: uterror - Various internal error/warning output functions
4 *
5 ******************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2013, 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 "acnamesp.h"
47
48#define _COMPONENT ACPI_UTILITIES
49ACPI_MODULE_NAME("uterror")
50
51/*
52 * This module contains internal error functions that may
53 * be configured out.
54 */
55#if !defined (ACPI_NO_ERROR_MESSAGES)
56/*******************************************************************************
57 *
58 * FUNCTION: acpi_ut_predefined_warning
59 *
60 * PARAMETERS: module_name - Caller's module name (for error output)
61 * line_number - Caller's line number (for error output)
62 * pathname - Full pathname to the node
63 * node_flags - From Namespace node for the method/object
64 * format - Printf format string + additional args
65 *
66 * RETURN: None
67 *
68 * DESCRIPTION: Warnings for the predefined validation module. Messages are
69 * only emitted the first time a problem with a particular
70 * method/object is detected. This prevents a flood of error
71 * messages for methods that are repeatedly evaluated.
72 *
73 ******************************************************************************/
74void ACPI_INTERNAL_VAR_XFACE
75acpi_ut_predefined_warning(const char *module_name,
76 u32 line_number,
77 char *pathname,
78 u8 node_flags, const char *format, ...)
79{
80 va_list arg_list;
81
82 /*
83 * Warning messages for this method/object will be disabled after the
84 * first time a validation fails or an object is successfully repaired.
85 */
86 if (node_flags & ANOBJ_EVALUATED) {
87 return;
88 }
89
90 acpi_os_printf(ACPI_MSG_WARNING "%s: ", pathname);
91
92 va_start(arg_list, format);
93 acpi_os_vprintf(format, arg_list);
94 ACPI_MSG_SUFFIX;
95 va_end(arg_list);
96}
97
98/*******************************************************************************
99 *
100 * FUNCTION: acpi_ut_predefined_info
101 *
102 * PARAMETERS: module_name - Caller's module name (for error output)
103 * line_number - Caller's line number (for error output)
104 * pathname - Full pathname to the node
105 * node_flags - From Namespace node for the method/object
106 * format - Printf format string + additional args
107 *
108 * RETURN: None
109 *
110 * DESCRIPTION: Info messages for the predefined validation module. Messages
111 * are only emitted the first time a problem with a particular
112 * method/object is detected. This prevents a flood of
113 * messages for methods that are repeatedly evaluated.
114 *
115 ******************************************************************************/
116
117void ACPI_INTERNAL_VAR_XFACE
118acpi_ut_predefined_info(const char *module_name,
119 u32 line_number,
120 char *pathname, u8 node_flags, const char *format, ...)
121{
122 va_list arg_list;
123
124 /*
125 * Warning messages for this method/object will be disabled after the
126 * first time a validation fails or an object is successfully repaired.
127 */
128 if (node_flags & ANOBJ_EVALUATED) {
129 return;
130 }
131
132 acpi_os_printf(ACPI_MSG_INFO "%s: ", pathname);
133
134 va_start(arg_list, format);
135 acpi_os_vprintf(format, arg_list);
136 ACPI_MSG_SUFFIX;
137 va_end(arg_list);
138}
139
140/*******************************************************************************
141 *
142 * FUNCTION: acpi_ut_predefined_bios_error
143 *
144 * PARAMETERS: module_name - Caller's module name (for error output)
145 * line_number - Caller's line number (for error output)
146 * pathname - Full pathname to the node
147 * node_flags - From Namespace node for the method/object
148 * format - Printf format string + additional args
149 *
150 * RETURN: None
151 *
152 * DESCRIPTION: BIOS error message for predefined names. Messages
153 * are only emitted the first time a problem with a particular
154 * method/object is detected. This prevents a flood of
155 * messages for methods that are repeatedly evaluated.
156 *
157 ******************************************************************************/
158
159void ACPI_INTERNAL_VAR_XFACE
160acpi_ut_predefined_bios_error(const char *module_name,
161 u32 line_number,
162 char *pathname,
163 u8 node_flags, const char *format, ...)
164{
165 va_list arg_list;
166
167 /*
168 * Warning messages for this method/object will be disabled after the
169 * first time a validation fails or an object is successfully repaired.
170 */
171 if (node_flags & ANOBJ_EVALUATED) {
172 return;
173 }
174
175 acpi_os_printf(ACPI_MSG_BIOS_ERROR "%s: ", pathname);
176
177 va_start(arg_list, format);
178 acpi_os_vprintf(format, arg_list);
179 ACPI_MSG_SUFFIX;
180 va_end(arg_list);
181}
182
183/*******************************************************************************
184 *
185 * FUNCTION: acpi_ut_namespace_error
186 *
187 * PARAMETERS: module_name - Caller's module name (for error output)
188 * line_number - Caller's line number (for error output)
189 * internal_name - Name or path of the namespace node
190 * lookup_status - Exception code from NS lookup
191 *
192 * RETURN: None
193 *
194 * DESCRIPTION: Print error message with the full pathname for the NS node.
195 *
196 ******************************************************************************/
197
198void
199acpi_ut_namespace_error(const char *module_name,
200 u32 line_number,
201 const char *internal_name, acpi_status lookup_status)
202{
203 acpi_status status;
204 u32 bad_name;
205 char *name = NULL;
206
207 ACPI_MSG_REDIRECT_BEGIN;
208 acpi_os_printf(ACPI_MSG_ERROR);
209
210 if (lookup_status == AE_BAD_CHARACTER) {
211
212 /* There is a non-ascii character in the name */
213
214 ACPI_MOVE_32_TO_32(&bad_name,
215 ACPI_CAST_PTR(u32, internal_name));
216 acpi_os_printf("[0x%.8X] (NON-ASCII)", bad_name);
217 } else {
218 /* Convert path to external format */
219
220 status = acpi_ns_externalize_name(ACPI_UINT32_MAX,
221 internal_name, NULL, &name);
222
223 /* Print target name */
224
225 if (ACPI_SUCCESS(status)) {
226 acpi_os_printf("[%s]", name);
227 } else {
228 acpi_os_printf("[COULD NOT EXTERNALIZE NAME]");
229 }
230
231 if (name) {
232 ACPI_FREE(name);
233 }
234 }
235
236 acpi_os_printf(" Namespace lookup failure, %s",
237 acpi_format_exception(lookup_status));
238
239 ACPI_MSG_SUFFIX;
240 ACPI_MSG_REDIRECT_END;
241}
242
243/*******************************************************************************
244 *
245 * FUNCTION: acpi_ut_method_error
246 *
247 * PARAMETERS: module_name - Caller's module name (for error output)
248 * line_number - Caller's line number (for error output)
249 * message - Error message to use on failure
250 * prefix_node - Prefix relative to the path
251 * path - Path to the node (optional)
252 * method_status - Execution status
253 *
254 * RETURN: None
255 *
256 * DESCRIPTION: Print error message with the full pathname for the method.
257 *
258 ******************************************************************************/
259
260void
261acpi_ut_method_error(const char *module_name,
262 u32 line_number,
263 const char *message,
264 struct acpi_namespace_node *prefix_node,
265 const char *path, acpi_status method_status)
266{
267 acpi_status status;
268 struct acpi_namespace_node *node = prefix_node;
269
270 ACPI_MSG_REDIRECT_BEGIN;
271 acpi_os_printf(ACPI_MSG_ERROR);
272
273 if (path) {
274 status =
275 acpi_ns_get_node(prefix_node, path, ACPI_NS_NO_UPSEARCH,
276 &node);
277 if (ACPI_FAILURE(status)) {
278 acpi_os_printf("[Could not get node by pathname]");
279 }
280 }
281
282 acpi_ns_print_node_pathname(node, message);
283 acpi_os_printf(", %s", acpi_format_exception(method_status));
284
285 ACPI_MSG_SUFFIX;
286 ACPI_MSG_REDIRECT_END;
287}
288
289#endif /* ACPI_NO_ERROR_MESSAGES */
diff --git a/drivers/acpi/acpica/uteval.c b/drivers/acpi/acpica/uteval.c
index c3f3a7e7bdc7..ee83adb97b1e 100644
--- a/drivers/acpi/acpica/uteval.c
+++ b/drivers/acpi/acpica/uteval.c
@@ -68,7 +68,7 @@ ACPI_MODULE_NAME("uteval")
68 ******************************************************************************/ 68 ******************************************************************************/
69 69
70acpi_status 70acpi_status
71acpi_ut_evaluate_object(struct acpi_namespace_node * prefix_node, 71acpi_ut_evaluate_object(struct acpi_namespace_node *prefix_node,
72 char *path, 72 char *path,
73 u32 expected_return_btypes, 73 u32 expected_return_btypes,
74 union acpi_operand_object **return_desc) 74 union acpi_operand_object **return_desc)
@@ -87,7 +87,7 @@ acpi_ut_evaluate_object(struct acpi_namespace_node * prefix_node,
87 } 87 }
88 88
89 info->prefix_node = prefix_node; 89 info->prefix_node = prefix_node;
90 info->pathname = path; 90 info->relative_pathname = path;
91 91
92 /* Evaluate the object/method */ 92 /* Evaluate the object/method */
93 93
@@ -123,22 +123,27 @@ acpi_ut_evaluate_object(struct acpi_namespace_node * prefix_node,
123 123
124 switch ((info->return_object)->common.type) { 124 switch ((info->return_object)->common.type) {
125 case ACPI_TYPE_INTEGER: 125 case ACPI_TYPE_INTEGER:
126
126 return_btype = ACPI_BTYPE_INTEGER; 127 return_btype = ACPI_BTYPE_INTEGER;
127 break; 128 break;
128 129
129 case ACPI_TYPE_BUFFER: 130 case ACPI_TYPE_BUFFER:
131
130 return_btype = ACPI_BTYPE_BUFFER; 132 return_btype = ACPI_BTYPE_BUFFER;
131 break; 133 break;
132 134
133 case ACPI_TYPE_STRING: 135 case ACPI_TYPE_STRING:
136
134 return_btype = ACPI_BTYPE_STRING; 137 return_btype = ACPI_BTYPE_STRING;
135 break; 138 break;
136 139
137 case ACPI_TYPE_PACKAGE: 140 case ACPI_TYPE_PACKAGE:
141
138 return_btype = ACPI_BTYPE_PACKAGE; 142 return_btype = ACPI_BTYPE_PACKAGE;
139 break; 143 break;
140 144
141 default: 145 default:
146
142 return_btype = 0; 147 return_btype = 0;
143 break; 148 break;
144 } 149 }
diff --git a/drivers/acpi/acpica/utexcep.c b/drivers/acpi/acpica/utexcep.c
index b543a144941a..ff6d9e8aa842 100644
--- a/drivers/acpi/acpica/utexcep.c
+++ b/drivers/acpi/acpica/utexcep.c
@@ -146,6 +146,7 @@ const struct acpi_exception_info *acpi_ut_validate_exception(acpi_status status)
146 break; 146 break;
147 147
148 default: 148 default:
149
149 break; 150 break;
150 } 151 }
151 152
diff --git a/drivers/acpi/acpica/utids.c b/drivers/acpi/acpica/utids.c
index 43a170a74a61..fa69071db418 100644
--- a/drivers/acpi/acpica/utids.c
+++ b/drivers/acpi/acpica/utids.c
@@ -341,14 +341,17 @@ acpi_ut_execute_CID(struct acpi_namespace_node *device_node,
341 341
342 switch (cid_objects[i]->common.type) { 342 switch (cid_objects[i]->common.type) {
343 case ACPI_TYPE_INTEGER: 343 case ACPI_TYPE_INTEGER:
344
344 string_area_size += ACPI_EISAID_STRING_SIZE; 345 string_area_size += ACPI_EISAID_STRING_SIZE;
345 break; 346 break;
346 347
347 case ACPI_TYPE_STRING: 348 case ACPI_TYPE_STRING:
349
348 string_area_size += cid_objects[i]->string.length + 1; 350 string_area_size += cid_objects[i]->string.length + 1;
349 break; 351 break;
350 352
351 default: 353 default:
354
352 status = AE_TYPE; 355 status = AE_TYPE;
353 goto cleanup; 356 goto cleanup;
354 } 357 }
diff --git a/drivers/acpi/acpica/utmisc.c b/drivers/acpi/acpica/utmisc.c
index 785fdd07ae56..02f9101b65e4 100644
--- a/drivers/acpi/acpica/utmisc.c
+++ b/drivers/acpi/acpica/utmisc.c
@@ -382,10 +382,12 @@ acpi_ut_display_init_pathname(u8 type,
382 382
383 switch (type) { 383 switch (type) {
384 case ACPI_TYPE_METHOD: 384 case ACPI_TYPE_METHOD:
385
385 acpi_os_printf("Executing "); 386 acpi_os_printf("Executing ");
386 break; 387 break;
387 388
388 default: 389 default:
390
389 acpi_os_printf("Initializing "); 391 acpi_os_printf("Initializing ");
390 break; 392 break;
391 } 393 }
diff --git a/drivers/acpi/acpica/utobject.c b/drivers/acpi/acpica/utobject.c
index 1099f5c069f8..aa61f66ee861 100644
--- a/drivers/acpi/acpica/utobject.c
+++ b/drivers/acpi/acpica/utobject.c
@@ -129,6 +129,7 @@ union acpi_operand_object *acpi_ut_create_internal_object_dbg(const char
129 break; 129 break;
130 130
131 default: 131 default:
132
132 /* All others have no secondary object */ 133 /* All others have no secondary object */
133 break; 134 break;
134 } 135 }
@@ -353,6 +354,7 @@ u8 acpi_ut_valid_internal_object(void *object)
353 return (TRUE); 354 return (TRUE);
354 355
355 default: 356 default:
357
356 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, 358 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
357 "%p is not not an ACPI operand obj [%s]\n", 359 "%p is not not an ACPI operand obj [%s]\n",
358 object, acpi_ut_get_descriptor_name(object))); 360 object, acpi_ut_get_descriptor_name(object)));
@@ -509,7 +511,6 @@ acpi_ut_get_simple_object_size(union acpi_operand_object *internal_object,
509 511
510 switch (internal_object->reference.class) { 512 switch (internal_object->reference.class) {
511 case ACPI_REFCLASS_NAME: 513 case ACPI_REFCLASS_NAME:
512
513 /* 514 /*
514 * Get the actual length of the full pathname to this object. 515 * Get the actual length of the full pathname to this object.
515 * The reference will be converted to the pathname to the object 516 * The reference will be converted to the pathname to the object
@@ -525,7 +526,6 @@ acpi_ut_get_simple_object_size(union acpi_operand_object *internal_object,
525 break; 526 break;
526 527
527 default: 528 default:
528
529 /* 529 /*
530 * No other reference opcodes are supported. 530 * No other reference opcodes are supported.
531 * Notably, Locals and Args are not supported, but this may be 531 * Notably, Locals and Args are not supported, but this may be
@@ -585,7 +585,6 @@ acpi_ut_get_element_length(u8 object_type,
585 585
586 switch (object_type) { 586 switch (object_type) {
587 case ACPI_COPY_TYPE_SIMPLE: 587 case ACPI_COPY_TYPE_SIMPLE:
588
589 /* 588 /*
590 * Simple object - just get the size (Null object/entry is handled 589 * Simple object - just get the size (Null object/entry is handled
591 * here also) and sum it into the running package length 590 * here also) and sum it into the running package length
diff --git a/drivers/acpi/acpica/utpredef.c b/drivers/acpi/acpica/utpredef.c
index 29459479148f..2b1ce4cd3207 100644
--- a/drivers/acpi/acpica/utpredef.c
+++ b/drivers/acpi/acpica/utpredef.c
@@ -147,6 +147,11 @@ void acpi_ut_get_expected_return_types(char *buffer, u32 expected_btypes)
147 u32 i; 147 u32 i;
148 u32 j; 148 u32 j;
149 149
150 if (!expected_btypes) {
151 ACPI_STRCPY(buffer, "NONE");
152 return;
153 }
154
150 j = 1; 155 j = 1;
151 buffer[0] = 0; 156 buffer[0] = 0;
152 this_rtype = ACPI_RTYPE_INTEGER; 157 this_rtype = ACPI_RTYPE_INTEGER;
@@ -328,9 +333,7 @@ static u32 acpi_ut_get_argument_types(char *buffer, u16 argument_types)
328 333
329 /* First field in the types list is the count of args to follow */ 334 /* First field in the types list is the count of args to follow */
330 335
331 arg_count = (argument_types & METHOD_ARG_MASK); 336 arg_count = METHOD_GET_ARG_COUNT(argument_types);
332 argument_types >>= METHOD_ARG_BIT_WIDTH;
333
334 if (arg_count > METHOD_PREDEF_ARGS_MAX) { 337 if (arg_count > METHOD_PREDEF_ARGS_MAX) {
335 printf("**** Invalid argument count (%u) " 338 printf("**** Invalid argument count (%u) "
336 "in predefined info structure\n", arg_count); 339 "in predefined info structure\n", arg_count);
@@ -340,7 +343,8 @@ static u32 acpi_ut_get_argument_types(char *buffer, u16 argument_types)
340 /* Get each argument from the list, convert to ascii, store to buffer */ 343 /* Get each argument from the list, convert to ascii, store to buffer */
341 344
342 for (i = 0; i < arg_count; i++) { 345 for (i = 0; i < arg_count; i++) {
343 this_argument_type = (argument_types & METHOD_ARG_MASK); 346 this_argument_type = METHOD_GET_NEXT_TYPE(argument_types);
347
344 if (!this_argument_type 348 if (!this_argument_type
345 || (this_argument_type > METHOD_MAX_ARG_TYPE)) { 349 || (this_argument_type > METHOD_MAX_ARG_TYPE)) {
346 printf("**** Invalid argument type (%u) " 350 printf("**** Invalid argument type (%u) "
@@ -351,10 +355,6 @@ static u32 acpi_ut_get_argument_types(char *buffer, u16 argument_types)
351 355
352 strcat(buffer, 356 strcat(buffer,
353 ut_external_type_names[this_argument_type] + sub_index); 357 ut_external_type_names[this_argument_type] + sub_index);
354
355 /* Shift to next argument type field */
356
357 argument_types >>= METHOD_ARG_BIT_WIDTH;
358 sub_index = 0; 358 sub_index = 0;
359 } 359 }
360 360
diff --git a/drivers/acpi/acpica/utstring.c b/drivers/acpi/acpica/utstring.c
index b3e36a81aa4d..c53759b76a3f 100644
--- a/drivers/acpi/acpica/utstring.c
+++ b/drivers/acpi/acpica/utstring.c
@@ -186,10 +186,13 @@ acpi_status acpi_ut_strtoul64(char *string, u32 base, u64 *ret_integer)
186 switch (base) { 186 switch (base) {
187 case ACPI_ANY_BASE: 187 case ACPI_ANY_BASE:
188 case 16: 188 case 16:
189
189 break; 190 break;
190 191
191 default: 192 default:
193
192 /* Invalid Base */ 194 /* Invalid Base */
195
193 return_ACPI_STATUS(AE_BAD_PARAMETER); 196 return_ACPI_STATUS(AE_BAD_PARAMETER);
194 } 197 }
195 198
@@ -355,36 +358,44 @@ void acpi_ut_print_string(char *string, u8 max_length)
355 358
356 switch (string[i]) { 359 switch (string[i]) {
357 case 0x07: 360 case 0x07:
361
358 acpi_os_printf("\\a"); /* BELL */ 362 acpi_os_printf("\\a"); /* BELL */
359 break; 363 break;
360 364
361 case 0x08: 365 case 0x08:
366
362 acpi_os_printf("\\b"); /* BACKSPACE */ 367 acpi_os_printf("\\b"); /* BACKSPACE */
363 break; 368 break;
364 369
365 case 0x0C: 370 case 0x0C:
371
366 acpi_os_printf("\\f"); /* FORMFEED */ 372 acpi_os_printf("\\f"); /* FORMFEED */
367 break; 373 break;
368 374
369 case 0x0A: 375 case 0x0A:
376
370 acpi_os_printf("\\n"); /* LINEFEED */ 377 acpi_os_printf("\\n"); /* LINEFEED */
371 break; 378 break;
372 379
373 case 0x0D: 380 case 0x0D:
381
374 acpi_os_printf("\\r"); /* CARRIAGE RETURN */ 382 acpi_os_printf("\\r"); /* CARRIAGE RETURN */
375 break; 383 break;
376 384
377 case 0x09: 385 case 0x09:
386
378 acpi_os_printf("\\t"); /* HORIZONTAL TAB */ 387 acpi_os_printf("\\t"); /* HORIZONTAL TAB */
379 break; 388 break;
380 389
381 case 0x0B: 390 case 0x0B:
391
382 acpi_os_printf("\\v"); /* VERTICAL TAB */ 392 acpi_os_printf("\\v"); /* VERTICAL TAB */
383 break; 393 break;
384 394
385 case '\'': /* Single Quote */ 395 case '\'': /* Single Quote */
386 case '\"': /* Double Quote */ 396 case '\"': /* Double Quote */
387 case '\\': /* Backslash */ 397 case '\\': /* Backslash */
398
388 acpi_os_printf("\\%c", (int)string[i]); 399 acpi_os_printf("\\%c", (int)string[i]);
389 break; 400 break;
390 401
@@ -451,7 +462,8 @@ u8 acpi_ut_valid_acpi_char(char character, u32 position)
451 * 462 *
452 * FUNCTION: acpi_ut_valid_acpi_name 463 * FUNCTION: acpi_ut_valid_acpi_name
453 * 464 *
454 * PARAMETERS: name - The name to be examined 465 * PARAMETERS: name - The name to be examined. Does not have to
466 * be NULL terminated string.
455 * 467 *
456 * RETURN: TRUE if the name is valid, FALSE otherwise 468 * RETURN: TRUE if the name is valid, FALSE otherwise
457 * 469 *
@@ -462,15 +474,14 @@ u8 acpi_ut_valid_acpi_char(char character, u32 position)
462 * 474 *
463 ******************************************************************************/ 475 ******************************************************************************/
464 476
465u8 acpi_ut_valid_acpi_name(u32 name) 477u8 acpi_ut_valid_acpi_name(char *name)
466{ 478{
467 u32 i; 479 u32 i;
468 480
469 ACPI_FUNCTION_ENTRY(); 481 ACPI_FUNCTION_ENTRY();
470 482
471 for (i = 0; i < ACPI_NAME_SIZE; i++) { 483 for (i = 0; i < ACPI_NAME_SIZE; i++) {
472 if (!acpi_ut_valid_acpi_char 484 if (!acpi_ut_valid_acpi_char(name[i], i)) {
473 ((ACPI_CAST_PTR(char, &name))[i], i)) {
474 return (FALSE); 485 return (FALSE);
475 } 486 }
476 } 487 }
diff --git a/drivers/acpi/acpica/uttrack.c b/drivers/acpi/acpica/uttrack.c
index 62774c7b76a8..160f13f4aab5 100644
--- a/drivers/acpi/acpica/uttrack.c
+++ b/drivers/acpi/acpica/uttrack.c
@@ -603,6 +603,7 @@ void acpi_ut_dump_allocations(u32 component, const char *module)
603 switch (ACPI_GET_DESCRIPTOR_TYPE 603 switch (ACPI_GET_DESCRIPTOR_TYPE
604 (descriptor)) { 604 (descriptor)) {
605 case ACPI_DESC_TYPE_OPERAND: 605 case ACPI_DESC_TYPE_OPERAND:
606
606 if (element->size == 607 if (element->size ==
607 sizeof(union 608 sizeof(union
608 acpi_operand_object)) 609 acpi_operand_object))
@@ -613,6 +614,7 @@ void acpi_ut_dump_allocations(u32 component, const char *module)
613 break; 614 break;
614 615
615 case ACPI_DESC_TYPE_PARSER: 616 case ACPI_DESC_TYPE_PARSER:
617
616 if (element->size == 618 if (element->size ==
617 sizeof(union 619 sizeof(union
618 acpi_parse_object)) { 620 acpi_parse_object)) {
@@ -622,6 +624,7 @@ void acpi_ut_dump_allocations(u32 component, const char *module)
622 break; 624 break;
623 625
624 case ACPI_DESC_TYPE_NAMED: 626 case ACPI_DESC_TYPE_NAMED:
627
625 if (element->size == 628 if (element->size ==
626 sizeof(struct 629 sizeof(struct
627 acpi_namespace_node)) 630 acpi_namespace_node))
@@ -632,6 +635,7 @@ void acpi_ut_dump_allocations(u32 component, const char *module)
632 break; 635 break;
633 636
634 default: 637 default:
638
635 break; 639 break;
636 } 640 }
637 641
@@ -639,6 +643,7 @@ void acpi_ut_dump_allocations(u32 component, const char *module)
639 643
640 switch (descriptor_type) { 644 switch (descriptor_type) {
641 case ACPI_DESC_TYPE_OPERAND: 645 case ACPI_DESC_TYPE_OPERAND:
646
642 acpi_os_printf 647 acpi_os_printf
643 ("%12.12s RefCount 0x%04X\n", 648 ("%12.12s RefCount 0x%04X\n",
644 acpi_ut_get_type_name 649 acpi_ut_get_type_name
@@ -649,6 +654,7 @@ void acpi_ut_dump_allocations(u32 component, const char *module)
649 break; 654 break;
650 655
651 case ACPI_DESC_TYPE_PARSER: 656 case ACPI_DESC_TYPE_PARSER:
657
652 acpi_os_printf 658 acpi_os_printf
653 ("AmlOpcode 0x%04hX\n", 659 ("AmlOpcode 0x%04hX\n",
654 descriptor->op.asl. 660 descriptor->op.asl.
@@ -656,6 +662,7 @@ void acpi_ut_dump_allocations(u32 component, const char *module)
656 break; 662 break;
657 663
658 case ACPI_DESC_TYPE_NAMED: 664 case ACPI_DESC_TYPE_NAMED:
665
659 acpi_os_printf("%4.4s\n", 666 acpi_os_printf("%4.4s\n",
660 acpi_ut_get_node_name 667 acpi_ut_get_node_name
661 (&descriptor-> 668 (&descriptor->
@@ -663,6 +670,7 @@ void acpi_ut_dump_allocations(u32 component, const char *module)
663 break; 670 break;
664 671
665 default: 672 default:
673
666 acpi_os_printf("\n"); 674 acpi_os_printf("\n");
667 break; 675 break;
668 } 676 }
diff --git a/drivers/acpi/acpica/utxferror.c b/drivers/acpi/acpica/utxferror.c
index 976b6c734fce..e966a2e47b76 100644
--- a/drivers/acpi/acpica/utxferror.c
+++ b/drivers/acpi/acpica/utxferror.c
@@ -44,7 +44,6 @@
44#include <linux/export.h> 44#include <linux/export.h>
45#include <acpi/acpi.h> 45#include <acpi/acpi.h>
46#include "accommon.h" 46#include "accommon.h"
47#include "acnamesp.h"
48 47
49#define _COMPONENT ACPI_UTILITIES 48#define _COMPONENT ACPI_UTILITIES
50ACPI_MODULE_NAME("utxferror") 49ACPI_MODULE_NAME("utxferror")
@@ -52,43 +51,7 @@ ACPI_MODULE_NAME("utxferror")
52/* 51/*
53 * This module is used for the in-kernel ACPICA as well as the ACPICA 52 * This module is used for the in-kernel ACPICA as well as the ACPICA
54 * tools/applications. 53 * tools/applications.
55 *
56 * For the iASL compiler case, the output is redirected to stderr so that
57 * any of the various ACPI errors and warnings do not appear in the output
58 * files, for either the compiler or disassembler portions of the tool.
59 */ 54 */
60#ifdef ACPI_ASL_COMPILER
61#include <stdio.h>
62extern FILE *acpi_gbl_output_file;
63
64#define ACPI_MSG_REDIRECT_BEGIN \
65 FILE *output_file = acpi_gbl_output_file; \
66 acpi_os_redirect_output (stderr);
67
68#define ACPI_MSG_REDIRECT_END \
69 acpi_os_redirect_output (output_file);
70
71#else
72/*
73 * non-iASL case - no redirection, nothing to do
74 */
75#define ACPI_MSG_REDIRECT_BEGIN
76#define ACPI_MSG_REDIRECT_END
77#endif
78/*
79 * Common message prefixes
80 */
81#define ACPI_MSG_ERROR "ACPI Error: "
82#define ACPI_MSG_EXCEPTION "ACPI Exception: "
83#define ACPI_MSG_WARNING "ACPI Warning: "
84#define ACPI_MSG_INFO "ACPI: "
85#define ACPI_MSG_BIOS_ERROR "ACPI BIOS Bug: Error: "
86#define ACPI_MSG_BIOS_WARNING "ACPI BIOS Bug: Warning: "
87/*
88 * Common message suffix
89 */
90#define ACPI_MSG_SUFFIX \
91 acpi_os_printf (" (%8.8X/%s-%u)\n", ACPI_CA_VERSION, module_name, line_number)
92/******************************************************************************* 55/*******************************************************************************
93 * 56 *
94 * FUNCTION: acpi_error 57 * FUNCTION: acpi_error
@@ -285,200 +248,3 @@ acpi_bios_warning(const char *module_name,
285} 248}
286 249
287ACPI_EXPORT_SYMBOL(acpi_bios_warning) 250ACPI_EXPORT_SYMBOL(acpi_bios_warning)
288
289/*
290 * The remainder of this module contains internal error functions that may
291 * be configured out.
292 */
293#if !defined (ACPI_NO_ERROR_MESSAGES) && !defined (ACPI_BIN_APP)
294/*******************************************************************************
295 *
296 * FUNCTION: acpi_ut_predefined_warning
297 *
298 * PARAMETERS: module_name - Caller's module name (for error output)
299 * line_number - Caller's line number (for error output)
300 * pathname - Full pathname to the node
301 * node_flags - From Namespace node for the method/object
302 * format - Printf format string + additional args
303 *
304 * RETURN: None
305 *
306 * DESCRIPTION: Warnings for the predefined validation module. Messages are
307 * only emitted the first time a problem with a particular
308 * method/object is detected. This prevents a flood of error
309 * messages for methods that are repeatedly evaluated.
310 *
311 ******************************************************************************/
312void ACPI_INTERNAL_VAR_XFACE
313acpi_ut_predefined_warning(const char *module_name,
314 u32 line_number,
315 char *pathname,
316 u8 node_flags, const char *format, ...)
317{
318 va_list arg_list;
319
320 /*
321 * Warning messages for this method/object will be disabled after the
322 * first time a validation fails or an object is successfully repaired.
323 */
324 if (node_flags & ANOBJ_EVALUATED) {
325 return;
326 }
327
328 acpi_os_printf(ACPI_MSG_WARNING "For %s: ", pathname);
329
330 va_start(arg_list, format);
331 acpi_os_vprintf(format, arg_list);
332 ACPI_MSG_SUFFIX;
333 va_end(arg_list);
334}
335
336/*******************************************************************************
337 *
338 * FUNCTION: acpi_ut_predefined_info
339 *
340 * PARAMETERS: module_name - Caller's module name (for error output)
341 * line_number - Caller's line number (for error output)
342 * pathname - Full pathname to the node
343 * node_flags - From Namespace node for the method/object
344 * format - Printf format string + additional args
345 *
346 * RETURN: None
347 *
348 * DESCRIPTION: Info messages for the predefined validation module. Messages
349 * are only emitted the first time a problem with a particular
350 * method/object is detected. This prevents a flood of
351 * messages for methods that are repeatedly evaluated.
352 *
353 ******************************************************************************/
354
355void ACPI_INTERNAL_VAR_XFACE
356acpi_ut_predefined_info(const char *module_name,
357 u32 line_number,
358 char *pathname, u8 node_flags, const char *format, ...)
359{
360 va_list arg_list;
361
362 /*
363 * Warning messages for this method/object will be disabled after the
364 * first time a validation fails or an object is successfully repaired.
365 */
366 if (node_flags & ANOBJ_EVALUATED) {
367 return;
368 }
369
370 acpi_os_printf(ACPI_MSG_INFO "For %s: ", pathname);
371
372 va_start(arg_list, format);
373 acpi_os_vprintf(format, arg_list);
374 ACPI_MSG_SUFFIX;
375 va_end(arg_list);
376}
377
378/*******************************************************************************
379 *
380 * FUNCTION: acpi_ut_namespace_error
381 *
382 * PARAMETERS: module_name - Caller's module name (for error output)
383 * line_number - Caller's line number (for error output)
384 * internal_name - Name or path of the namespace node
385 * lookup_status - Exception code from NS lookup
386 *
387 * RETURN: None
388 *
389 * DESCRIPTION: Print error message with the full pathname for the NS node.
390 *
391 ******************************************************************************/
392
393void
394acpi_ut_namespace_error(const char *module_name,
395 u32 line_number,
396 const char *internal_name, acpi_status lookup_status)
397{
398 acpi_status status;
399 u32 bad_name;
400 char *name = NULL;
401
402 ACPI_MSG_REDIRECT_BEGIN;
403 acpi_os_printf(ACPI_MSG_ERROR);
404
405 if (lookup_status == AE_BAD_CHARACTER) {
406
407 /* There is a non-ascii character in the name */
408
409 ACPI_MOVE_32_TO_32(&bad_name,
410 ACPI_CAST_PTR(u32, internal_name));
411 acpi_os_printf("[0x%.8X] (NON-ASCII)", bad_name);
412 } else {
413 /* Convert path to external format */
414
415 status = acpi_ns_externalize_name(ACPI_UINT32_MAX,
416 internal_name, NULL, &name);
417
418 /* Print target name */
419
420 if (ACPI_SUCCESS(status)) {
421 acpi_os_printf("[%s]", name);
422 } else {
423 acpi_os_printf("[COULD NOT EXTERNALIZE NAME]");
424 }
425
426 if (name) {
427 ACPI_FREE(name);
428 }
429 }
430
431 acpi_os_printf(" Namespace lookup failure, %s",
432 acpi_format_exception(lookup_status));
433
434 ACPI_MSG_SUFFIX;
435 ACPI_MSG_REDIRECT_END;
436}
437
438/*******************************************************************************
439 *
440 * FUNCTION: acpi_ut_method_error
441 *
442 * PARAMETERS: module_name - Caller's module name (for error output)
443 * line_number - Caller's line number (for error output)
444 * message - Error message to use on failure
445 * prefix_node - Prefix relative to the path
446 * path - Path to the node (optional)
447 * method_status - Execution status
448 *
449 * RETURN: None
450 *
451 * DESCRIPTION: Print error message with the full pathname for the method.
452 *
453 ******************************************************************************/
454
455void
456acpi_ut_method_error(const char *module_name,
457 u32 line_number,
458 const char *message,
459 struct acpi_namespace_node *prefix_node,
460 const char *path, acpi_status method_status)
461{
462 acpi_status status;
463 struct acpi_namespace_node *node = prefix_node;
464
465 ACPI_MSG_REDIRECT_BEGIN;
466 acpi_os_printf(ACPI_MSG_ERROR);
467
468 if (path) {
469 status =
470 acpi_ns_get_node(prefix_node, path, ACPI_NS_NO_UPSEARCH,
471 &node);
472 if (ACPI_FAILURE(status)) {
473 acpi_os_printf("[Could not get node by pathname]");
474 }
475 }
476
477 acpi_ns_print_node_pathname(node, message);
478 acpi_os_printf(", %s", acpi_format_exception(method_status));
479
480 ACPI_MSG_SUFFIX;
481 ACPI_MSG_REDIRECT_END;
482}
483
484#endif /* ACPI_NO_ERROR_MESSAGES */
diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index e7100459ac4a..082b4dd252a8 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -425,7 +425,7 @@ static int acpi_battery_get_info(struct acpi_battery *battery)
425{ 425{
426 int result = -EFAULT; 426 int result = -EFAULT;
427 acpi_status status = 0; 427 acpi_status status = 0;
428 char *name = test_bit(ACPI_BATTERY_XINFO_PRESENT, &battery->flags)? 428 char *name = test_bit(ACPI_BATTERY_XINFO_PRESENT, &battery->flags) ?
429 "_BIX" : "_BIF"; 429 "_BIX" : "_BIF";
430 430
431 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; 431 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
@@ -661,11 +661,11 @@ static void find_battery(const struct dmi_header *dm, void *private)
661static void acpi_battery_quirks(struct acpi_battery *battery) 661static void acpi_battery_quirks(struct acpi_battery *battery)
662{ 662{
663 if (test_bit(ACPI_BATTERY_QUIRK_PERCENTAGE_CAPACITY, &battery->flags)) 663 if (test_bit(ACPI_BATTERY_QUIRK_PERCENTAGE_CAPACITY, &battery->flags))
664 return ; 664 return;
665 665
666 if (battery->full_charge_capacity == 100 && 666 if (battery->full_charge_capacity == 100 &&
667 battery->rate_now == ACPI_BATTERY_VALUE_UNKNOWN && 667 battery->rate_now == ACPI_BATTERY_VALUE_UNKNOWN &&
668 battery->capacity_now >=0 && battery->capacity_now <= 100) { 668 battery->capacity_now >= 0 && battery->capacity_now <= 100) {
669 set_bit(ACPI_BATTERY_QUIRK_PERCENTAGE_CAPACITY, &battery->flags); 669 set_bit(ACPI_BATTERY_QUIRK_PERCENTAGE_CAPACITY, &battery->flags);
670 battery->full_charge_capacity = battery->design_capacity; 670 battery->full_charge_capacity = battery->design_capacity;
671 battery->capacity_now = (battery->capacity_now * 671 battery->capacity_now = (battery->capacity_now *
@@ -673,7 +673,7 @@ static void acpi_battery_quirks(struct acpi_battery *battery)
673 } 673 }
674 674
675 if (test_bit(ACPI_BATTERY_QUIRK_THINKPAD_MAH, &battery->flags)) 675 if (test_bit(ACPI_BATTERY_QUIRK_THINKPAD_MAH, &battery->flags))
676 return ; 676 return;
677 677
678 if (battery->power_unit && dmi_name_in_vendors("LENOVO")) { 678 if (battery->power_unit && dmi_name_in_vendors("LENOVO")) {
679 const char *s; 679 const char *s;
@@ -761,7 +761,7 @@ static int acpi_battery_print_info(struct seq_file *seq, int result)
761 goto end; 761 goto end;
762 762
763 seq_printf(seq, "present: %s\n", 763 seq_printf(seq, "present: %s\n",
764 acpi_battery_present(battery)?"yes":"no"); 764 acpi_battery_present(battery) ? "yes" : "no");
765 if (!acpi_battery_present(battery)) 765 if (!acpi_battery_present(battery))
766 goto end; 766 goto end;
767 if (battery->design_capacity == ACPI_BATTERY_VALUE_UNKNOWN) 767 if (battery->design_capacity == ACPI_BATTERY_VALUE_UNKNOWN)
@@ -817,12 +817,12 @@ static int acpi_battery_print_state(struct seq_file *seq, int result)
817 goto end; 817 goto end;
818 818
819 seq_printf(seq, "present: %s\n", 819 seq_printf(seq, "present: %s\n",
820 acpi_battery_present(battery)?"yes":"no"); 820 acpi_battery_present(battery) ? "yes" : "no");
821 if (!acpi_battery_present(battery)) 821 if (!acpi_battery_present(battery))
822 goto end; 822 goto end;
823 823
824 seq_printf(seq, "capacity state: %s\n", 824 seq_printf(seq, "capacity state: %s\n",
825 (battery->state & 0x04)?"critical":"ok"); 825 (battery->state & 0x04) ? "critical" : "ok");
826 if ((battery->state & 0x01) && (battery->state & 0x02)) 826 if ((battery->state & 0x01) && (battery->state & 0x02))
827 seq_printf(seq, 827 seq_printf(seq,
828 "charging state: charging/discharging\n"); 828 "charging state: charging/discharging\n");
diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c
index 292de3cab9cc..a5bb33bab448 100644
--- a/drivers/acpi/bus.c
+++ b/drivers/acpi/bus.c
@@ -91,8 +91,7 @@ static struct dmi_system_id dsdt_dmi_table[] __initdata = {
91 91
92int acpi_bus_get_device(acpi_handle handle, struct acpi_device **device) 92int acpi_bus_get_device(acpi_handle handle, struct acpi_device **device)
93{ 93{
94 acpi_status status = AE_OK; 94 acpi_status status;
95
96 95
97 if (!device) 96 if (!device)
98 return -EINVAL; 97 return -EINVAL;
@@ -162,7 +161,7 @@ EXPORT_SYMBOL(acpi_bus_private_data_handler);
162 161
163int acpi_bus_get_private_data(acpi_handle handle, void **data) 162int acpi_bus_get_private_data(acpi_handle handle, void **data)
164{ 163{
165 acpi_status status = AE_OK; 164 acpi_status status;
166 165
167 if (!*data) 166 if (!*data)
168 return -EINVAL; 167 return -EINVAL;
@@ -361,7 +360,7 @@ extern int event_is_open;
361int acpi_bus_generate_proc_event4(const char *device_class, const char *bus_id, u8 type, int data) 360int acpi_bus_generate_proc_event4(const char *device_class, const char *bus_id, u8 type, int data)
362{ 361{
363 struct acpi_bus_event *event; 362 struct acpi_bus_event *event;
364 unsigned long flags = 0; 363 unsigned long flags;
365 364
366 /* drop event on the floor if no one's listening */ 365 /* drop event on the floor if no one's listening */
367 if (!event_is_open) 366 if (!event_is_open)
@@ -400,7 +399,7 @@ EXPORT_SYMBOL(acpi_bus_generate_proc_event);
400 399
401int acpi_bus_receive_event(struct acpi_bus_event *event) 400int acpi_bus_receive_event(struct acpi_bus_event *event)
402{ 401{
403 unsigned long flags = 0; 402 unsigned long flags;
404 struct acpi_bus_event *entry = NULL; 403 struct acpi_bus_event *entry = NULL;
405 404
406 DECLARE_WAITQUEUE(wait, current); 405 DECLARE_WAITQUEUE(wait, current);
@@ -593,7 +592,7 @@ static void acpi_bus_notify(acpi_handle handle, u32 type, void *data)
593 592
594static int __init acpi_bus_init_irq(void) 593static int __init acpi_bus_init_irq(void)
595{ 594{
596 acpi_status status = AE_OK; 595 acpi_status status;
597 union acpi_object arg = { ACPI_TYPE_INTEGER }; 596 union acpi_object arg = { ACPI_TYPE_INTEGER };
598 struct acpi_object_list arg_list = { 1, &arg }; 597 struct acpi_object_list arg_list = { 1, &arg };
599 char *message = NULL; 598 char *message = NULL;
@@ -640,7 +639,7 @@ u8 acpi_gbl_permanent_mmap;
640 639
641void __init acpi_early_init(void) 640void __init acpi_early_init(void)
642{ 641{
643 acpi_status status = AE_OK; 642 acpi_status status;
644 643
645 if (acpi_disabled) 644 if (acpi_disabled)
646 return; 645 return;
@@ -714,8 +713,8 @@ void __init acpi_early_init(void)
714 713
715static int __init acpi_bus_init(void) 714static int __init acpi_bus_init(void)
716{ 715{
717 int result = 0; 716 int result;
718 acpi_status status = AE_OK; 717 acpi_status status;
719 extern acpi_status acpi_os_initialize1(void); 718 extern acpi_status acpi_os_initialize1(void);
720 719
721 acpi_os_initialize1(); 720 acpi_os_initialize1();
diff --git a/drivers/acpi/device_pm.c b/drivers/acpi/device_pm.c
index 31c217a42839..e9e8bb24785b 100644
--- a/drivers/acpi/device_pm.c
+++ b/drivers/acpi/device_pm.c
@@ -419,62 +419,73 @@ bool acpi_bus_can_wakeup(acpi_handle handle)
419EXPORT_SYMBOL(acpi_bus_can_wakeup); 419EXPORT_SYMBOL(acpi_bus_can_wakeup);
420 420
421/** 421/**
422 * acpi_device_power_state - Get preferred power state of ACPI device. 422 * acpi_dev_pm_get_state - Get preferred power state of ACPI device.
423 * @dev: Device whose preferred target power state to return. 423 * @dev: Device whose preferred target power state to return.
424 * @adev: ACPI device node corresponding to @dev. 424 * @adev: ACPI device node corresponding to @dev.
425 * @target_state: System state to match the resultant device state. 425 * @target_state: System state to match the resultant device state.
426 * @d_max_in: Deepest low-power state to take into consideration. 426 * @d_min_p: Location to store the highest power state available to the device.
427 * @d_min_p: Location to store the upper limit of the allowed states range. 427 * @d_max_p: Location to store the lowest power state available to the device.
428 * Return value: Preferred power state of the device on success, -ENODEV
429 * (if there's no 'struct acpi_device' for @dev) or -EINVAL on failure
430 * 428 *
431 * Find the lowest power (highest number) ACPI device power state that the 429 * Find the lowest power (highest number) and highest power (lowest number) ACPI
432 * device can be in while the system is in the state represented by 430 * device power states that the device can be in while the system is in the
433 * @target_state. If @d_min_p is set, the highest power (lowest number) device 431 * state represented by @target_state. Store the integer numbers representing
434 * power state that @dev can be in for the given system sleep state is stored 432 * those stats in the memory locations pointed to by @d_max_p and @d_min_p,
435 * at the location pointed to by it. 433 * respectively.
436 * 434 *
437 * Callers must ensure that @dev and @adev are valid pointers and that @adev 435 * Callers must ensure that @dev and @adev are valid pointers and that @adev
438 * actually corresponds to @dev before using this function. 436 * actually corresponds to @dev before using this function.
437 *
438 * Returns 0 on success or -ENODATA when one of the ACPI methods fails or
439 * returns a value that doesn't make sense. The memory locations pointed to by
440 * @d_max_p and @d_min_p are only modified on success.
439 */ 441 */
440int acpi_device_power_state(struct device *dev, struct acpi_device *adev, 442static int acpi_dev_pm_get_state(struct device *dev, struct acpi_device *adev,
441 u32 target_state, int d_max_in, int *d_min_p) 443 u32 target_state, int *d_min_p, int *d_max_p)
442{ 444{
443 char acpi_method[] = "_SxD"; 445 char method[] = { '_', 'S', '0' + target_state, 'D', '\0' };
444 unsigned long long d_min, d_max; 446 acpi_handle handle = adev->handle;
447 unsigned long long ret;
448 int d_min, d_max;
445 bool wakeup = false; 449 bool wakeup = false;
450 acpi_status status;
446 451
447 if (d_max_in < ACPI_STATE_D0 || d_max_in > ACPI_STATE_D3)
448 return -EINVAL;
449
450 if (d_max_in > ACPI_STATE_D3_HOT) {
451 enum pm_qos_flags_status stat;
452
453 stat = dev_pm_qos_flags(dev, PM_QOS_FLAG_NO_POWER_OFF);
454 if (stat == PM_QOS_FLAGS_ALL)
455 d_max_in = ACPI_STATE_D3_HOT;
456 }
457
458 acpi_method[2] = '0' + target_state;
459 /* 452 /*
460 * If the sleep state is S0, the lowest limit from ACPI is D3, 453 * If the system state is S0, the lowest power state the device can be
461 * but if the device has _S0W, we will use the value from _S0W 454 * in is D3cold, unless the device has _S0W and is supposed to signal
462 * as the lowest limit from ACPI. Finally, we will constrain 455 * wakeup, in which case the return value of _S0W has to be used as the
463 * the lowest limit with the specified one. 456 * lowest power state available to the device.
464 */ 457 */
465 d_min = ACPI_STATE_D0; 458 d_min = ACPI_STATE_D0;
466 d_max = ACPI_STATE_D3; 459 d_max = ACPI_STATE_D3_COLD;
467 460
468 /* 461 /*
469 * If present, _SxD methods return the minimum D-state (highest power 462 * If present, _SxD methods return the minimum D-state (highest power
470 * state) we can use for the corresponding S-states. Otherwise, the 463 * state) we can use for the corresponding S-states. Otherwise, the
471 * minimum D-state is D0 (ACPI 3.x). 464 * minimum D-state is D0 (ACPI 3.x).
472 *
473 * NOTE: We rely on acpi_evaluate_integer() not clobbering the integer
474 * provided -- that's our fault recovery, we ignore retval.
475 */ 465 */
476 if (target_state > ACPI_STATE_S0) { 466 if (target_state > ACPI_STATE_S0) {
477 acpi_evaluate_integer(adev->handle, acpi_method, NULL, &d_min); 467 /*
468 * We rely on acpi_evaluate_integer() not clobbering the integer
469 * provided if AE_NOT_FOUND is returned.
470 */
471 ret = d_min;
472 status = acpi_evaluate_integer(handle, method, NULL, &ret);
473 if ((ACPI_FAILURE(status) && status != AE_NOT_FOUND)
474 || ret > ACPI_STATE_D3_COLD)
475 return -ENODATA;
476
477 /*
478 * We need to handle legacy systems where D3hot and D3cold are
479 * the same and 3 is returned in both cases, so fall back to
480 * D3cold if D3hot is not a valid state.
481 */
482 if (!adev->power.states[ret].flags.valid) {
483 if (ret == ACPI_STATE_D3_HOT)
484 ret = ACPI_STATE_D3_COLD;
485 else
486 return -ENODATA;
487 }
488 d_min = ret;
478 wakeup = device_may_wakeup(dev) && adev->wakeup.flags.valid 489 wakeup = device_may_wakeup(dev) && adev->wakeup.flags.valid
479 && adev->wakeup.sleep_state >= target_state; 490 && adev->wakeup.sleep_state >= target_state;
480 } else if (dev_pm_qos_flags(dev, PM_QOS_FLAG_REMOTE_WAKEUP) != 491 } else if (dev_pm_qos_flags(dev, PM_QOS_FLAG_REMOTE_WAKEUP) !=
@@ -490,38 +501,30 @@ int acpi_device_power_state(struct device *dev, struct acpi_device *adev,
490 * can wake the system. _S0W may be valid, too. 501 * can wake the system. _S0W may be valid, too.
491 */ 502 */
492 if (wakeup) { 503 if (wakeup) {
493 acpi_status status; 504 method[3] = 'W';
494 505 status = acpi_evaluate_integer(handle, method, NULL, &ret);
495 acpi_method[3] = 'W'; 506 if (status == AE_NOT_FOUND) {
496 status = acpi_evaluate_integer(adev->handle, acpi_method, NULL, 507 if (target_state > ACPI_STATE_S0)
497 &d_max);
498 if (ACPI_FAILURE(status)) {
499 if (target_state != ACPI_STATE_S0 ||
500 status != AE_NOT_FOUND)
501 d_max = d_min; 508 d_max = d_min;
502 } else if (d_max < d_min) { 509 } else if (ACPI_SUCCESS(status) && ret <= ACPI_STATE_D3_COLD) {
503 /* Warn the user of the broken DSDT */ 510 /* Fall back to D3cold if ret is not a valid state. */
504 printk(KERN_WARNING "ACPI: Wrong value from %s\n", 511 if (!adev->power.states[ret].flags.valid)
505 acpi_method); 512 ret = ACPI_STATE_D3_COLD;
506 /* Sanitize it */ 513
507 d_min = d_max; 514 d_max = ret > d_min ? ret : d_min;
515 } else {
516 return -ENODATA;
508 } 517 }
509 } 518 }
510 519
511 if (d_max_in < d_min)
512 return -EINVAL;
513 if (d_min_p) 520 if (d_min_p)
514 *d_min_p = d_min; 521 *d_min_p = d_min;
515 /* constrain d_max with specified lowest limit (max number) */ 522
516 if (d_max > d_max_in) { 523 if (d_max_p)
517 for (d_max = d_max_in; d_max > d_min; d_max--) { 524 *d_max_p = d_max;
518 if (adev->power.states[d_max].flags.valid) 525
519 break; 526 return 0;
520 }
521 }
522 return d_max;
523} 527}
524EXPORT_SYMBOL_GPL(acpi_device_power_state);
525 528
526/** 529/**
527 * acpi_pm_device_sleep_state - Get preferred power state of ACPI device. 530 * acpi_pm_device_sleep_state - Get preferred power state of ACPI device.
@@ -529,7 +532,8 @@ EXPORT_SYMBOL_GPL(acpi_device_power_state);
529 * @d_min_p: Location to store the upper limit of the allowed states range. 532 * @d_min_p: Location to store the upper limit of the allowed states range.
530 * @d_max_in: Deepest low-power state to take into consideration. 533 * @d_max_in: Deepest low-power state to take into consideration.
531 * Return value: Preferred power state of the device on success, -ENODEV 534 * Return value: Preferred power state of the device on success, -ENODEV
532 * (if there's no 'struct acpi_device' for @dev) or -EINVAL on failure 535 * if there's no 'struct acpi_device' for @dev, -EINVAL if @d_max_in is
536 * incorrect, or -ENODATA on ACPI method failure.
533 * 537 *
534 * The caller must ensure that @dev is valid before using this function. 538 * The caller must ensure that @dev is valid before using this function.
535 */ 539 */
@@ -537,14 +541,43 @@ int acpi_pm_device_sleep_state(struct device *dev, int *d_min_p, int d_max_in)
537{ 541{
538 acpi_handle handle = DEVICE_ACPI_HANDLE(dev); 542 acpi_handle handle = DEVICE_ACPI_HANDLE(dev);
539 struct acpi_device *adev; 543 struct acpi_device *adev;
544 int ret, d_min, d_max;
545
546 if (d_max_in < ACPI_STATE_D0 || d_max_in > ACPI_STATE_D3_COLD)
547 return -EINVAL;
548
549 if (d_max_in > ACPI_STATE_D3_HOT) {
550 enum pm_qos_flags_status stat;
551
552 stat = dev_pm_qos_flags(dev, PM_QOS_FLAG_NO_POWER_OFF);
553 if (stat == PM_QOS_FLAGS_ALL)
554 d_max_in = ACPI_STATE_D3_HOT;
555 }
540 556
541 if (!handle || acpi_bus_get_device(handle, &adev)) { 557 if (!handle || acpi_bus_get_device(handle, &adev)) {
542 dev_dbg(dev, "ACPI handle without context in %s!\n", __func__); 558 dev_dbg(dev, "ACPI handle without context in %s!\n", __func__);
543 return -ENODEV; 559 return -ENODEV;
544 } 560 }
545 561
546 return acpi_device_power_state(dev, adev, acpi_target_system_state(), 562 ret = acpi_dev_pm_get_state(dev, adev, acpi_target_system_state(),
547 d_max_in, d_min_p); 563 &d_min, &d_max);
564 if (ret)
565 return ret;
566
567 if (d_max_in < d_min)
568 return -EINVAL;
569
570 if (d_max > d_max_in) {
571 for (d_max = d_max_in; d_max > d_min; d_max--) {
572 if (adev->power.states[d_max].flags.valid)
573 break;
574 }
575 }
576
577 if (d_min_p)
578 *d_min_p = d_min;
579
580 return d_max;
548} 581}
549EXPORT_SYMBOL(acpi_pm_device_sleep_state); 582EXPORT_SYMBOL(acpi_pm_device_sleep_state);
550 583
@@ -695,17 +728,13 @@ struct acpi_device *acpi_dev_pm_get_node(struct device *dev)
695static int acpi_dev_pm_low_power(struct device *dev, struct acpi_device *adev, 728static int acpi_dev_pm_low_power(struct device *dev, struct acpi_device *adev,
696 u32 system_state) 729 u32 system_state)
697{ 730{
698 int power_state; 731 int ret, state;
699 732
700 if (!acpi_device_power_manageable(adev)) 733 if (!acpi_device_power_manageable(adev))
701 return 0; 734 return 0;
702 735
703 power_state = acpi_device_power_state(dev, adev, system_state, 736 ret = acpi_dev_pm_get_state(dev, adev, system_state, NULL, &state);
704 ACPI_STATE_D3, NULL); 737 return ret ? ret : acpi_device_set_power(adev, state);
705 if (power_state < ACPI_STATE_D0 || power_state > ACPI_STATE_D3)
706 return -EIO;
707
708 return acpi_device_set_power(adev, power_state);
709} 738}
710 739
711/** 740/**
@@ -908,7 +937,6 @@ static struct dev_pm_domain acpi_general_pm_domain = {
908#ifdef CONFIG_PM_RUNTIME 937#ifdef CONFIG_PM_RUNTIME
909 .runtime_suspend = acpi_subsys_runtime_suspend, 938 .runtime_suspend = acpi_subsys_runtime_suspend,
910 .runtime_resume = acpi_subsys_runtime_resume, 939 .runtime_resume = acpi_subsys_runtime_resume,
911 .runtime_idle = pm_generic_runtime_idle,
912#endif 940#endif
913#ifdef CONFIG_PM_SLEEP 941#ifdef CONFIG_PM_SLEEP
914 .prepare = acpi_subsys_prepare, 942 .prepare = acpi_subsys_prepare,
diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c
index edc00818c803..80403c1a89f8 100644
--- a/drivers/acpi/ec.c
+++ b/drivers/acpi/ec.c
@@ -983,6 +983,10 @@ static struct dmi_system_id __initdata ec_dmi_table[] = {
983 ec_enlarge_storm_threshold, "CLEVO hardware", { 983 ec_enlarge_storm_threshold, "CLEVO hardware", {
984 DMI_MATCH(DMI_SYS_VENDOR, "CLEVO Co."), 984 DMI_MATCH(DMI_SYS_VENDOR, "CLEVO Co."),
985 DMI_MATCH(DMI_PRODUCT_NAME, "M720T/M730T"),}, NULL}, 985 DMI_MATCH(DMI_PRODUCT_NAME, "M720T/M730T"),}, NULL},
986 {
987 ec_skip_dsdt_scan, "HP Folio 13", {
988 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
989 DMI_MATCH(DMI_PRODUCT_NAME, "HP Folio 13"),}, NULL},
986 {}, 990 {},
987}; 991};
988 992
diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
index 7586544fddb4..4e7b798900f2 100644
--- a/drivers/acpi/ec_sys.c
+++ b/drivers/acpi/ec_sys.c
@@ -12,6 +12,7 @@
12#include <linux/acpi.h> 12#include <linux/acpi.h>
13#include <linux/debugfs.h> 13#include <linux/debugfs.h>
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/uaccess.h>
15#include "internal.h" 16#include "internal.h"
16 17
17MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>"); 18MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
@@ -34,7 +35,6 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
34 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private; 35 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
35 */ 36 */
36 unsigned int size = EC_SPACE_SIZE; 37 unsigned int size = EC_SPACE_SIZE;
37 u8 *data = (u8 *) buf;
38 loff_t init_off = *off; 38 loff_t init_off = *off;
39 int err = 0; 39 int err = 0;
40 40
@@ -47,9 +47,15 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
47 size = count; 47 size = count;
48 48
49 while (size) { 49 while (size) {
50 err = ec_read(*off, &data[*off - init_off]); 50 u8 byte_read;
51 err = ec_read(*off, &byte_read);
51 if (err) 52 if (err)
52 return err; 53 return err;
54 if (put_user(byte_read, buf + *off - init_off)) {
55 if (*off - init_off)
56 return *off - init_off; /* partial read */
57 return -EFAULT;
58 }
53 *off += 1; 59 *off += 1;
54 size--; 60 size--;
55 } 61 }
@@ -65,7 +71,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
65 71
66 unsigned int size = count; 72 unsigned int size = count;
67 loff_t init_off = *off; 73 loff_t init_off = *off;
68 u8 *data = (u8 *) buf;
69 int err = 0; 74 int err = 0;
70 75
71 if (*off >= EC_SPACE_SIZE) 76 if (*off >= EC_SPACE_SIZE)
@@ -76,7 +81,12 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
76 } 81 }
77 82
78 while (size) { 83 while (size) {
79 u8 byte_write = data[*off - init_off]; 84 u8 byte_write;
85 if (get_user(byte_write, buf + *off - init_off)) {
86 if (*off - init_off)
87 return *off - init_off; /* partial write */
88 return -EFAULT;
89 }
80 err = ec_write(*off, byte_write); 90 err = ec_write(*off, byte_write);
81 if (err) 91 if (err)
82 return err; 92 return err;
diff --git a/drivers/acpi/glue.c b/drivers/acpi/glue.c
index 40a84cc6740c..f68095756fb7 100644
--- a/drivers/acpi/glue.c
+++ b/drivers/acpi/glue.c
@@ -81,13 +81,15 @@ static struct acpi_bus_type *acpi_get_bus_type(struct device *dev)
81static acpi_status do_acpi_find_child(acpi_handle handle, u32 lvl_not_used, 81static acpi_status do_acpi_find_child(acpi_handle handle, u32 lvl_not_used,
82 void *addr_p, void **ret_p) 82 void *addr_p, void **ret_p)
83{ 83{
84 unsigned long long addr; 84 unsigned long long addr, sta;
85 acpi_status status; 85 acpi_status status;
86 86
87 status = acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL, &addr); 87 status = acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL, &addr);
88 if (ACPI_SUCCESS(status) && addr == *((u64 *)addr_p)) { 88 if (ACPI_SUCCESS(status) && addr == *((u64 *)addr_p)) {
89 *ret_p = handle; 89 *ret_p = handle;
90 return AE_CTRL_TERMINATE; 90 status = acpi_bus_get_status_handle(handle, &sta);
91 if (ACPI_SUCCESS(status) && (sta & ACPI_STA_DEVICE_ENABLED))
92 return AE_CTRL_TERMINATE;
91 } 93 }
92 return AE_OK; 94 return AE_OK;
93} 95}
@@ -105,7 +107,7 @@ acpi_handle acpi_get_child(acpi_handle parent, u64 address)
105} 107}
106EXPORT_SYMBOL(acpi_get_child); 108EXPORT_SYMBOL(acpi_get_child);
107 109
108static int acpi_bind_one(struct device *dev, acpi_handle handle) 110int acpi_bind_one(struct device *dev, acpi_handle handle)
109{ 111{
110 struct acpi_device *acpi_dev; 112 struct acpi_device *acpi_dev;
111 acpi_status status; 113 acpi_status status;
@@ -188,8 +190,9 @@ static int acpi_bind_one(struct device *dev, acpi_handle handle)
188 kfree(physical_node); 190 kfree(physical_node);
189 goto err; 191 goto err;
190} 192}
193EXPORT_SYMBOL_GPL(acpi_bind_one);
191 194
192static int acpi_unbind_one(struct device *dev) 195int acpi_unbind_one(struct device *dev)
193{ 196{
194 struct acpi_device_physical_node *entry; 197 struct acpi_device_physical_node *entry;
195 struct acpi_device *acpi_dev; 198 struct acpi_device *acpi_dev;
@@ -238,6 +241,7 @@ err:
238 dev_err(dev, "Oops, 'acpi_handle' corrupt\n"); 241 dev_err(dev, "Oops, 'acpi_handle' corrupt\n");
239 return -EINVAL; 242 return -EINVAL;
240} 243}
244EXPORT_SYMBOL_GPL(acpi_unbind_one);
241 245
242static int acpi_platform_notify(struct device *dev) 246static int acpi_platform_notify(struct device *dev)
243{ 247{
diff --git a/drivers/acpi/internal.h b/drivers/acpi/internal.h
index c610a76d92c4..3a50a34fe176 100644
--- a/drivers/acpi/internal.h
+++ b/drivers/acpi/internal.h
@@ -33,6 +33,7 @@ static inline void acpi_pci_slot_init(void) { }
33void acpi_pci_root_init(void); 33void acpi_pci_root_init(void);
34void acpi_pci_link_init(void); 34void acpi_pci_link_init(void);
35void acpi_pci_root_hp_init(void); 35void acpi_pci_root_hp_init(void);
36void acpi_processor_init(void);
36void acpi_platform_init(void); 37void acpi_platform_init(void);
37int acpi_sysfs_init(void); 38int acpi_sysfs_init(void);
38#ifdef CONFIG_ACPI_CONTAINER 39#ifdef CONFIG_ACPI_CONTAINER
@@ -50,6 +51,13 @@ void acpi_memory_hotplug_init(void);
50#else 51#else
51static inline void acpi_memory_hotplug_init(void) {} 52static inline void acpi_memory_hotplug_init(void) {}
52#endif 53#endif
54#ifdef CONFIG_X86
55void acpi_cmos_rtc_init(void);
56#else
57static inline void acpi_cmos_rtc_init(void) {}
58#endif
59
60extern bool acpi_force_hot_remove;
53 61
54void acpi_sysfs_add_hotplug_profile(struct acpi_hotplug_profile *hotplug, 62void acpi_sysfs_add_hotplug_profile(struct acpi_hotplug_profile *hotplug,
55 const char *name); 63 const char *name);
@@ -81,6 +89,8 @@ void acpi_init_device_object(struct acpi_device *device, acpi_handle handle,
81 int type, unsigned long long sta); 89 int type, unsigned long long sta);
82void acpi_device_add_finalize(struct acpi_device *device); 90void acpi_device_add_finalize(struct acpi_device *device);
83void acpi_free_pnp_ids(struct acpi_device_pnp *pnp); 91void acpi_free_pnp_ids(struct acpi_device_pnp *pnp);
92int acpi_bind_one(struct device *dev, acpi_handle handle);
93int acpi_unbind_one(struct device *dev);
84 94
85/* -------------------------------------------------------------------------- 95/* --------------------------------------------------------------------------
86 Power Resource 96 Power Resource
diff --git a/drivers/acpi/osl.c b/drivers/acpi/osl.c
index e72186340fec..6ab2c3505520 100644
--- a/drivers/acpi/osl.c
+++ b/drivers/acpi/osl.c
@@ -835,19 +835,9 @@ void acpi_os_stall(u32 us)
835 */ 835 */
836u64 acpi_os_get_timer(void) 836u64 acpi_os_get_timer(void)
837{ 837{
838 static u64 t; 838 u64 time_ns = ktime_to_ns(ktime_get());
839 839 do_div(time_ns, 100);
840#ifdef CONFIG_HPET 840 return time_ns;
841 /* TBD: use HPET if available */
842#endif
843
844#ifdef CONFIG_X86_PM_TIMER
845 /* TBD: default to PM timer if HPET was not available */
846#endif
847 if (!t)
848 printk(KERN_ERR PREFIX "acpi_os_get_timer() TBD\n");
849
850 return ++t;
851} 841}
852 842
853acpi_status acpi_os_read_port(acpi_io_address port, u32 * value, u32 width) 843acpi_status acpi_os_read_port(acpi_io_address port, u32 * value, u32 width)
@@ -1715,6 +1705,17 @@ acpi_status acpi_os_release_object(acpi_cache_t * cache, void *object)
1715} 1705}
1716#endif 1706#endif
1717 1707
1708static int __init acpi_no_auto_ssdt_setup(char *s)
1709{
1710 printk(KERN_NOTICE PREFIX "SSDT auto-load disabled\n");
1711
1712 acpi_gbl_disable_ssdt_table_load = TRUE;
1713
1714 return 1;
1715}
1716
1717__setup("acpi_no_auto_ssdt", acpi_no_auto_ssdt_setup);
1718
1718acpi_status __init acpi_os_initialize(void) 1719acpi_status __init acpi_os_initialize(void)
1719{ 1720{
1720 acpi_os_map_generic_address(&acpi_gbl_FADT.xpm1a_event_block); 1721 acpi_os_map_generic_address(&acpi_gbl_FADT.xpm1a_event_block);
diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
index c266cdc11784..823be116619e 100644
--- a/drivers/acpi/processor_driver.c
+++ b/drivers/acpi/processor_driver.c
@@ -1,11 +1,13 @@
1/* 1/*
2 * acpi_processor.c - ACPI Processor Driver ($Revision: 71 $) 2 * processor_driver.c - ACPI Processor Driver
3 * 3 *
4 * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com> 4 * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
5 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com> 5 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
6 * Copyright (C) 2004 Dominik Brodowski <linux@brodo.de> 6 * Copyright (C) 2004 Dominik Brodowski <linux@brodo.de>
7 * Copyright (C) 2004 Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com> 7 * Copyright (C) 2004 Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
8 * - Added processor hotplug support 8 * - Added processor hotplug support
9 * Copyright (C) 2013, Intel Corporation
10 * Rafael J. Wysocki <rafael.j.wysocki@intel.com>
9 * 11 *
10 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 12 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11 * 13 *
@@ -24,55 +26,26 @@
24 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. 26 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
25 * 27 *
26 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 28 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
27 * TBD:
28 * 1. Make # power states dynamic.
29 * 2. Support duty_cycle values that span bit 4.
30 * 3. Optimize by having scheduler determine business instead of
31 * having us try to calculate it here.
32 * 4. Need C1 timing -- must modify kernel (IRQ handler) to get this.
33 */ 29 */
34 30
35#include <linux/kernel.h> 31#include <linux/kernel.h>
36#include <linux/module.h> 32#include <linux/module.h>
37#include <linux/init.h> 33#include <linux/init.h>
38#include <linux/types.h>
39#include <linux/pci.h>
40#include <linux/pm.h>
41#include <linux/cpufreq.h> 34#include <linux/cpufreq.h>
42#include <linux/cpu.h> 35#include <linux/cpu.h>
43#include <linux/dmi.h>
44#include <linux/moduleparam.h>
45#include <linux/cpuidle.h> 36#include <linux/cpuidle.h>
46#include <linux/slab.h> 37#include <linux/slab.h>
47#include <linux/acpi.h> 38#include <linux/acpi.h>
48#include <linux/memory_hotplug.h> 39
49
50#include <asm/io.h>
51#include <asm/cpu.h>
52#include <asm/delay.h>
53#include <asm/uaccess.h>
54#include <asm/processor.h>
55#include <asm/smp.h>
56#include <asm/acpi.h>
57
58#include <acpi/acpi_bus.h>
59#include <acpi/acpi_drivers.h>
60#include <acpi/processor.h> 40#include <acpi/processor.h>
61 41
42#include "internal.h"
43
62#define PREFIX "ACPI: " 44#define PREFIX "ACPI: "
63 45
64#define ACPI_PROCESSOR_CLASS "processor"
65#define ACPI_PROCESSOR_DEVICE_NAME "Processor"
66#define ACPI_PROCESSOR_FILE_INFO "info"
67#define ACPI_PROCESSOR_FILE_THROTTLING "throttling"
68#define ACPI_PROCESSOR_FILE_LIMIT "limit"
69#define ACPI_PROCESSOR_NOTIFY_PERFORMANCE 0x80 46#define ACPI_PROCESSOR_NOTIFY_PERFORMANCE 0x80
70#define ACPI_PROCESSOR_NOTIFY_POWER 0x81 47#define ACPI_PROCESSOR_NOTIFY_POWER 0x81
71#define ACPI_PROCESSOR_NOTIFY_THROTTLING 0x82 48#define ACPI_PROCESSOR_NOTIFY_THROTTLING 0x82
72#define ACPI_PROCESSOR_DEVICE_HID "ACPI0007"
73
74#define ACPI_PROCESSOR_LIMIT_USER 0
75#define ACPI_PROCESSOR_LIMIT_THERMAL 1
76 49
77#define _COMPONENT ACPI_PROCESSOR_COMPONENT 50#define _COMPONENT ACPI_PROCESSOR_COMPONENT
78ACPI_MODULE_NAME("processor_driver"); 51ACPI_MODULE_NAME("processor_driver");
@@ -81,12 +54,8 @@ MODULE_AUTHOR("Paul Diefenbaugh");
81MODULE_DESCRIPTION("ACPI Processor Driver"); 54MODULE_DESCRIPTION("ACPI Processor Driver");
82MODULE_LICENSE("GPL"); 55MODULE_LICENSE("GPL");
83 56
84static int acpi_processor_add(struct acpi_device *device); 57static int acpi_processor_start(struct device *dev);
85static int acpi_processor_remove(struct acpi_device *device); 58static int acpi_processor_stop(struct device *dev);
86static void acpi_processor_notify(struct acpi_device *device, u32 event);
87static acpi_status acpi_processor_hotadd_init(struct acpi_processor *pr);
88static int acpi_processor_handle_eject(struct acpi_processor *pr);
89static int acpi_processor_start(struct acpi_processor *pr);
90 59
91static const struct acpi_device_id processor_device_ids[] = { 60static const struct acpi_device_id processor_device_ids[] = {
92 {ACPI_PROCESSOR_OBJECT_HID, 0}, 61 {ACPI_PROCESSOR_OBJECT_HID, 0},
@@ -95,295 +64,24 @@ static const struct acpi_device_id processor_device_ids[] = {
95}; 64};
96MODULE_DEVICE_TABLE(acpi, processor_device_ids); 65MODULE_DEVICE_TABLE(acpi, processor_device_ids);
97 66
98static struct acpi_driver acpi_processor_driver = { 67static struct device_driver acpi_processor_driver = {
99 .name = "processor", 68 .name = "processor",
100 .class = ACPI_PROCESSOR_CLASS, 69 .bus = &cpu_subsys,
101 .ids = processor_device_ids, 70 .acpi_match_table = processor_device_ids,
102 .ops = { 71 .probe = acpi_processor_start,
103 .add = acpi_processor_add, 72 .remove = acpi_processor_stop,
104 .remove = acpi_processor_remove,
105 .notify = acpi_processor_notify,
106 },
107}; 73};
108 74
109#define INSTALL_NOTIFY_HANDLER 1 75static void acpi_processor_notify(acpi_handle handle, u32 event, void *data)
110#define UNINSTALL_NOTIFY_HANDLER 2
111
112DEFINE_PER_CPU(struct acpi_processor *, processors);
113EXPORT_PER_CPU_SYMBOL(processors);
114
115struct acpi_processor_errata errata __read_mostly;
116
117/* --------------------------------------------------------------------------
118 Errata Handling
119 -------------------------------------------------------------------------- */
120
121static int acpi_processor_errata_piix4(struct pci_dev *dev)
122{
123 u8 value1 = 0;
124 u8 value2 = 0;
125
126
127 if (!dev)
128 return -EINVAL;
129
130 /*
131 * Note that 'dev' references the PIIX4 ACPI Controller.
132 */
133
134 switch (dev->revision) {
135 case 0:
136 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4 A-step\n"));
137 break;
138 case 1:
139 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4 B-step\n"));
140 break;
141 case 2:
142 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4E\n"));
143 break;
144 case 3:
145 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4M\n"));
146 break;
147 default:
148 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found unknown PIIX4\n"));
149 break;
150 }
151
152 switch (dev->revision) {
153
154 case 0: /* PIIX4 A-step */
155 case 1: /* PIIX4 B-step */
156 /*
157 * See specification changes #13 ("Manual Throttle Duty Cycle")
158 * and #14 ("Enabling and Disabling Manual Throttle"), plus
159 * erratum #5 ("STPCLK# Deassertion Time") from the January
160 * 2002 PIIX4 specification update. Applies to only older
161 * PIIX4 models.
162 */
163 errata.piix4.throttle = 1;
164
165 case 2: /* PIIX4E */
166 case 3: /* PIIX4M */
167 /*
168 * See erratum #18 ("C3 Power State/BMIDE and Type-F DMA
169 * Livelock") from the January 2002 PIIX4 specification update.
170 * Applies to all PIIX4 models.
171 */
172
173 /*
174 * BM-IDE
175 * ------
176 * Find the PIIX4 IDE Controller and get the Bus Master IDE
177 * Status register address. We'll use this later to read
178 * each IDE controller's DMA status to make sure we catch all
179 * DMA activity.
180 */
181 dev = pci_get_subsys(PCI_VENDOR_ID_INTEL,
182 PCI_DEVICE_ID_INTEL_82371AB,
183 PCI_ANY_ID, PCI_ANY_ID, NULL);
184 if (dev) {
185 errata.piix4.bmisx = pci_resource_start(dev, 4);
186 pci_dev_put(dev);
187 }
188
189 /*
190 * Type-F DMA
191 * ----------
192 * Find the PIIX4 ISA Controller and read the Motherboard
193 * DMA controller's status to see if Type-F (Fast) DMA mode
194 * is enabled (bit 7) on either channel. Note that we'll
195 * disable C3 support if this is enabled, as some legacy
196 * devices won't operate well if fast DMA is disabled.
197 */
198 dev = pci_get_subsys(PCI_VENDOR_ID_INTEL,
199 PCI_DEVICE_ID_INTEL_82371AB_0,
200 PCI_ANY_ID, PCI_ANY_ID, NULL);
201 if (dev) {
202 pci_read_config_byte(dev, 0x76, &value1);
203 pci_read_config_byte(dev, 0x77, &value2);
204 if ((value1 & 0x80) || (value2 & 0x80))
205 errata.piix4.fdma = 1;
206 pci_dev_put(dev);
207 }
208
209 break;
210 }
211
212 if (errata.piix4.bmisx)
213 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
214 "Bus master activity detection (BM-IDE) erratum enabled\n"));
215 if (errata.piix4.fdma)
216 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
217 "Type-F DMA livelock erratum (C3 disabled)\n"));
218
219 return 0;
220}
221
222static int acpi_processor_errata(struct acpi_processor *pr)
223{ 76{
224 int result = 0; 77 struct acpi_device *device = data;
225 struct pci_dev *dev = NULL;
226
227
228 if (!pr)
229 return -EINVAL;
230
231 /*
232 * PIIX4
233 */
234 dev = pci_get_subsys(PCI_VENDOR_ID_INTEL,
235 PCI_DEVICE_ID_INTEL_82371AB_3, PCI_ANY_ID,
236 PCI_ANY_ID, NULL);
237 if (dev) {
238 result = acpi_processor_errata_piix4(dev);
239 pci_dev_put(dev);
240 }
241
242 return result;
243}
244
245/* --------------------------------------------------------------------------
246 Driver Interface
247 -------------------------------------------------------------------------- */
248
249static int acpi_processor_get_info(struct acpi_device *device)
250{
251 acpi_status status = 0;
252 union acpi_object object = { 0 };
253 struct acpi_buffer buffer = { sizeof(union acpi_object), &object };
254 struct acpi_processor *pr; 78 struct acpi_processor *pr;
255 int cpu_index, device_declaration = 0;
256 static int cpu0_initialized;
257
258 pr = acpi_driver_data(device);
259 if (!pr)
260 return -EINVAL;
261
262 if (num_online_cpus() > 1)
263 errata.smp = TRUE;
264
265 acpi_processor_errata(pr);
266
267 /*
268 * Check to see if we have bus mastering arbitration control. This
269 * is required for proper C3 usage (to maintain cache coherency).
270 */
271 if (acpi_gbl_FADT.pm2_control_block && acpi_gbl_FADT.pm2_control_length) {
272 pr->flags.bm_control = 1;
273 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
274 "Bus mastering arbitration control present\n"));
275 } else
276 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
277 "No bus mastering arbitration control\n"));
278
279 if (!strcmp(acpi_device_hid(device), ACPI_PROCESSOR_OBJECT_HID)) {
280 /* Declared with "Processor" statement; match ProcessorID */
281 status = acpi_evaluate_object(pr->handle, NULL, NULL, &buffer);
282 if (ACPI_FAILURE(status)) {
283 dev_err(&device->dev,
284 "Failed to evaluate processor object (0x%x)\n",
285 status);
286 return -ENODEV;
287 }
288
289 /*
290 * TBD: Synch processor ID (via LAPIC/LSAPIC structures) on SMP.
291 * >>> 'acpi_get_processor_id(acpi_id, &id)' in
292 * arch/xxx/acpi.c
293 */
294 pr->acpi_id = object.processor.proc_id;
295 } else {
296 /*
297 * Declared with "Device" statement; match _UID.
298 * Note that we don't handle string _UIDs yet.
299 */
300 unsigned long long value;
301 status = acpi_evaluate_integer(pr->handle, METHOD_NAME__UID,
302 NULL, &value);
303 if (ACPI_FAILURE(status)) {
304 dev_err(&device->dev,
305 "Failed to evaluate processor _UID (0x%x)\n",
306 status);
307 return -ENODEV;
308 }
309 device_declaration = 1;
310 pr->acpi_id = value;
311 }
312 cpu_index = acpi_get_cpuid(pr->handle, device_declaration, pr->acpi_id);
313
314 /* Handle UP system running SMP kernel, with no LAPIC in MADT */
315 if (!cpu0_initialized && (cpu_index == -1) &&
316 (num_online_cpus() == 1)) {
317 cpu_index = 0;
318 }
319
320 cpu0_initialized = 1;
321
322 pr->id = cpu_index;
323
324 /*
325 * Extra Processor objects may be enumerated on MP systems with
326 * less than the max # of CPUs. They should be ignored _iff
327 * they are physically not present.
328 */
329 if (pr->id == -1) {
330 if (ACPI_FAILURE(acpi_processor_hotadd_init(pr)))
331 return -ENODEV;
332 }
333 /*
334 * On some boxes several processors use the same processor bus id.
335 * But they are located in different scope. For example:
336 * \_SB.SCK0.CPU0
337 * \_SB.SCK1.CPU0
338 * Rename the processor device bus id. And the new bus id will be
339 * generated as the following format:
340 * CPU+CPU ID.
341 */
342 sprintf(acpi_device_bid(device), "CPU%X", pr->id);
343 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Processor [%d:%d]\n", pr->id,
344 pr->acpi_id));
345
346 if (!object.processor.pblk_address)
347 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No PBLK (NULL address)\n"));
348 else if (object.processor.pblk_length != 6)
349 dev_err(&device->dev, "Invalid PBLK length [%d]\n",
350 object.processor.pblk_length);
351 else {
352 pr->throttling.address = object.processor.pblk_address;
353 pr->throttling.duty_offset = acpi_gbl_FADT.duty_offset;
354 pr->throttling.duty_width = acpi_gbl_FADT.duty_width;
355
356 pr->pblk = object.processor.pblk_address;
357
358 /*
359 * We don't care about error returns - we just try to mark
360 * these reserved so that nobody else is confused into thinking
361 * that this region might be unused..
362 *
363 * (In particular, allocating the IO range for Cardbus)
364 */
365 request_region(pr->throttling.address, 6, "ACPI CPU throttle");
366 }
367
368 /*
369 * If ACPI describes a slot number for this CPU, we can use it
370 * ensure we get the right value in the "physical id" field
371 * of /proc/cpuinfo
372 */
373 status = acpi_evaluate_object(pr->handle, "_SUN", NULL, &buffer);
374 if (ACPI_SUCCESS(status))
375 arch_fix_phys_package_id(pr->id, object.integer.value);
376
377 return 0;
378}
379
380static DEFINE_PER_CPU(void *, processor_device_array);
381
382static void acpi_processor_notify(struct acpi_device *device, u32 event)
383{
384 struct acpi_processor *pr = acpi_driver_data(device);
385 int saved; 79 int saved;
386 80
81 if (device->handle != handle)
82 return;
83
84 pr = acpi_driver_data(device);
387 if (!pr) 85 if (!pr)
388 return; 86 return;
389 87
@@ -420,55 +118,62 @@ static void acpi_processor_notify(struct acpi_device *device, u32 event)
420 return; 118 return;
421} 119}
422 120
423static int acpi_cpu_soft_notify(struct notifier_block *nfb, 121static __cpuinit int __acpi_processor_start(struct acpi_device *device);
424 unsigned long action, void *hcpu) 122
123static int __cpuinit acpi_cpu_soft_notify(struct notifier_block *nfb,
124 unsigned long action, void *hcpu)
425{ 125{
426 unsigned int cpu = (unsigned long)hcpu; 126 unsigned int cpu = (unsigned long)hcpu;
427 struct acpi_processor *pr = per_cpu(processors, cpu); 127 struct acpi_processor *pr = per_cpu(processors, cpu);
128 struct acpi_device *device;
129
130 if (!pr || acpi_bus_get_device(pr->handle, &device))
131 return NOTIFY_DONE;
428 132
429 if (action == CPU_ONLINE && pr) { 133 if (action == CPU_ONLINE) {
430 /* CPU got physically hotplugged and onlined the first time: 134 /*
431 * Initialize missing things 135 * CPU got physically hotplugged and onlined for the first time:
136 * Initialize missing things.
432 */ 137 */
433 if (pr->flags.need_hotplug_init) { 138 if (pr->flags.need_hotplug_init) {
139 int ret;
140
434 pr_info("Will online and init hotplugged CPU: %d\n", 141 pr_info("Will online and init hotplugged CPU: %d\n",
435 pr->id); 142 pr->id);
436 WARN(acpi_processor_start(pr), "Failed to start CPU:"
437 " %d\n", pr->id);
438 pr->flags.need_hotplug_init = 0; 143 pr->flags.need_hotplug_init = 0;
439 /* Normal CPU soft online event */ 144 ret = __acpi_processor_start(device);
145 WARN(ret, "Failed to start CPU: %d\n", pr->id);
440 } else { 146 } else {
147 /* Normal CPU soft online event. */
441 acpi_processor_ppc_has_changed(pr, 0); 148 acpi_processor_ppc_has_changed(pr, 0);
442 acpi_processor_hotplug(pr); 149 acpi_processor_hotplug(pr);
443 acpi_processor_reevaluate_tstate(pr, action); 150 acpi_processor_reevaluate_tstate(pr, action);
444 acpi_processor_tstate_has_changed(pr); 151 acpi_processor_tstate_has_changed(pr);
445 } 152 }
446 } 153 } else if (action == CPU_DEAD) {
447 if (action == CPU_DEAD && pr) { 154 /* Invalidate flag.throttling after the CPU is offline. */
448 /* invalidate the flag.throttling after one CPU is offline */
449 acpi_processor_reevaluate_tstate(pr, action); 155 acpi_processor_reevaluate_tstate(pr, action);
450 } 156 }
451 return NOTIFY_OK; 157 return NOTIFY_OK;
452} 158}
453 159
454static struct notifier_block acpi_cpu_notifier = 160static struct notifier_block __refdata acpi_cpu_notifier =
455{ 161{
456 .notifier_call = acpi_cpu_soft_notify, 162 .notifier_call = acpi_cpu_soft_notify,
457}; 163};
458 164
459/* 165static __cpuinit int __acpi_processor_start(struct acpi_device *device)
460 * acpi_processor_start() is called by the cpu_hotplug_notifier func:
461 * acpi_cpu_soft_notify(). Getting it __cpuinit{data} is difficult, the
462 * root cause seem to be that acpi_processor_uninstall_hotplug_notify()
463 * is in the module_exit (__exit) func. Allowing acpi_processor_start()
464 * to not be in __cpuinit section, but being called from __cpuinit funcs
465 * via __ref looks like the right thing to do here.
466 */
467static __ref int acpi_processor_start(struct acpi_processor *pr)
468{ 166{
469 struct acpi_device *device = per_cpu(processor_device_array, pr->id); 167 struct acpi_processor *pr = acpi_driver_data(device);
168 acpi_status status;
470 int result = 0; 169 int result = 0;
471 170
171 if (!pr)
172 return -ENODEV;
173
174 if (pr->flags.need_hotplug_init)
175 return 0;
176
472#ifdef CONFIG_CPU_FREQ 177#ifdef CONFIG_CPU_FREQ
473 acpi_processor_ppc_has_changed(pr, 0); 178 acpi_processor_ppc_has_changed(pr, 0);
474 acpi_processor_load_module(pr); 179 acpi_processor_load_module(pr);
@@ -506,462 +211,95 @@ static __ref int acpi_processor_start(struct acpi_processor *pr)
506 goto err_remove_sysfs_thermal; 211 goto err_remove_sysfs_thermal;
507 } 212 }
508 213
509 return 0; 214 status = acpi_install_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
215 acpi_processor_notify, device);
216 if (ACPI_SUCCESS(status))
217 return 0;
510 218
511err_remove_sysfs_thermal: 219 sysfs_remove_link(&pr->cdev->device.kobj, "device");
220 err_remove_sysfs_thermal:
512 sysfs_remove_link(&device->dev.kobj, "thermal_cooling"); 221 sysfs_remove_link(&device->dev.kobj, "thermal_cooling");
513err_thermal_unregister: 222 err_thermal_unregister:
514 thermal_cooling_device_unregister(pr->cdev); 223 thermal_cooling_device_unregister(pr->cdev);
515err_power_exit: 224 err_power_exit:
516 acpi_processor_power_exit(pr); 225 acpi_processor_power_exit(pr);
517
518 return result; 226 return result;
519} 227}
520 228
521/* 229static int __cpuinit acpi_processor_start(struct device *dev)
522 * Do not put anything in here which needs the core to be online.
523 * For example MSR access or setting up things which check for cpuinfo_x86
524 * (cpu_data(cpu)) values, like CPU feature flags, family, model, etc.
525 * Such things have to be put in and set up above in acpi_processor_start()
526 */
527static int __cpuinit acpi_processor_add(struct acpi_device *device)
528{ 230{
529 struct acpi_processor *pr = NULL; 231 struct acpi_device *device;
530 int result = 0;
531 struct device *dev;
532
533 pr = kzalloc(sizeof(struct acpi_processor), GFP_KERNEL);
534 if (!pr)
535 return -ENOMEM;
536
537 if (!zalloc_cpumask_var(&pr->throttling.shared_cpu_map, GFP_KERNEL)) {
538 result = -ENOMEM;
539 goto err_free_pr;
540 }
541
542 pr->handle = device->handle;
543 strcpy(acpi_device_name(device), ACPI_PROCESSOR_DEVICE_NAME);
544 strcpy(acpi_device_class(device), ACPI_PROCESSOR_CLASS);
545 device->driver_data = pr;
546
547 result = acpi_processor_get_info(device);
548 if (result) {
549 /* Processor is physically not present */
550 return 0;
551 }
552 232
553#ifdef CONFIG_SMP 233 if (acpi_bus_get_device(ACPI_HANDLE(dev), &device))
554 if (pr->id >= setup_max_cpus && pr->id != 0) 234 return -ENODEV;
555 return 0;
556#endif
557
558 BUG_ON(pr->id >= nr_cpu_ids);
559
560 /*
561 * Buggy BIOS check
562 * ACPI id of processors can be reported wrongly by the BIOS.
563 * Don't trust it blindly
564 */
565 if (per_cpu(processor_device_array, pr->id) != NULL &&
566 per_cpu(processor_device_array, pr->id) != device) {
567 dev_warn(&device->dev,
568 "BIOS reported wrong ACPI id %d for the processor\n",
569 pr->id);
570 result = -ENODEV;
571 goto err_free_cpumask;
572 }
573 per_cpu(processor_device_array, pr->id) = device;
574 235
575 per_cpu(processors, pr->id) = pr; 236 return __acpi_processor_start(device);
576
577 dev = get_cpu_device(pr->id);
578 if (sysfs_create_link(&device->dev.kobj, &dev->kobj, "sysdev")) {
579 result = -EFAULT;
580 goto err_clear_processor;
581 }
582
583 /*
584 * Do not start hotplugged CPUs now, but when they
585 * are onlined the first time
586 */
587 if (pr->flags.need_hotplug_init)
588 return 0;
589
590 result = acpi_processor_start(pr);
591 if (result)
592 goto err_remove_sysfs;
593
594 return 0;
595
596err_remove_sysfs:
597 sysfs_remove_link(&device->dev.kobj, "sysdev");
598err_clear_processor:
599 /*
600 * processor_device_array is not cleared to allow checks for buggy BIOS
601 */
602 per_cpu(processors, pr->id) = NULL;
603err_free_cpumask:
604 free_cpumask_var(pr->throttling.shared_cpu_map);
605err_free_pr:
606 kfree(pr);
607 return result;
608} 237}
609 238
610static int acpi_processor_remove(struct acpi_device *device) 239static int acpi_processor_stop(struct device *dev)
611{ 240{
612 struct acpi_processor *pr = NULL; 241 struct acpi_device *device;
242 struct acpi_processor *pr;
613 243
244 if (acpi_bus_get_device(ACPI_HANDLE(dev), &device))
245 return 0;
614 246
615 if (!device || !acpi_driver_data(device)) 247 acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
616 return -EINVAL; 248 acpi_processor_notify);
617 249
618 pr = acpi_driver_data(device); 250 pr = acpi_driver_data(device);
619 251 if (!pr)
620 if (pr->id >= nr_cpu_ids) 252 return 0;
621 goto free;
622
623 if (device->removal_type == ACPI_BUS_REMOVAL_EJECT) {
624 if (acpi_processor_handle_eject(pr))
625 return -EINVAL;
626 }
627 253
628 acpi_processor_power_exit(pr); 254 acpi_processor_power_exit(pr);
629 255
630 sysfs_remove_link(&device->dev.kobj, "sysdev");
631
632 if (pr->cdev) { 256 if (pr->cdev) {
633 sysfs_remove_link(&device->dev.kobj, "thermal_cooling"); 257 sysfs_remove_link(&device->dev.kobj, "thermal_cooling");
634 sysfs_remove_link(&pr->cdev->device.kobj, "device"); 258 sysfs_remove_link(&pr->cdev->device.kobj, "device");
635 thermal_cooling_device_unregister(pr->cdev); 259 thermal_cooling_device_unregister(pr->cdev);
636 pr->cdev = NULL; 260 pr->cdev = NULL;
637 } 261 }
638
639 per_cpu(processors, pr->id) = NULL;
640 per_cpu(processor_device_array, pr->id) = NULL;
641 try_offline_node(cpu_to_node(pr->id));
642
643free:
644 free_cpumask_var(pr->throttling.shared_cpu_map);
645 kfree(pr);
646
647 return 0; 262 return 0;
648} 263}
649 264
650#ifdef CONFIG_ACPI_HOTPLUG_CPU
651/****************************************************************************
652 * Acpi processor hotplug support *
653 ****************************************************************************/
654
655static int is_processor_present(acpi_handle handle)
656{
657 acpi_status status;
658 unsigned long long sta = 0;
659
660
661 status = acpi_evaluate_integer(handle, "_STA", NULL, &sta);
662
663 if (ACPI_SUCCESS(status) && (sta & ACPI_STA_DEVICE_PRESENT))
664 return 1;
665
666 /*
667 * _STA is mandatory for a processor that supports hot plug
668 */
669 if (status == AE_NOT_FOUND)
670 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
671 "Processor does not support hot plug\n"));
672 else
673 ACPI_EXCEPTION((AE_INFO, status,
674 "Processor Device is not present"));
675 return 0;
676}
677
678static void acpi_processor_hotplug_notify(acpi_handle handle,
679 u32 event, void *data)
680{
681 struct acpi_device *device = NULL;
682 struct acpi_eject_event *ej_event = NULL;
683 u32 ost_code = ACPI_OST_SC_NON_SPECIFIC_FAILURE; /* default */
684 acpi_status status;
685 int result;
686
687 acpi_scan_lock_acquire();
688
689 switch (event) {
690 case ACPI_NOTIFY_BUS_CHECK:
691 case ACPI_NOTIFY_DEVICE_CHECK:
692 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
693 "Processor driver received %s event\n",
694 (event == ACPI_NOTIFY_BUS_CHECK) ?
695 "ACPI_NOTIFY_BUS_CHECK" : "ACPI_NOTIFY_DEVICE_CHECK"));
696
697 if (!is_processor_present(handle))
698 break;
699
700 if (!acpi_bus_get_device(handle, &device))
701 break;
702
703 result = acpi_bus_scan(handle);
704 if (result) {
705 acpi_handle_err(handle, "Unable to add the device\n");
706 break;
707 }
708 result = acpi_bus_get_device(handle, &device);
709 if (result) {
710 acpi_handle_err(handle, "Missing device object\n");
711 break;
712 }
713 ost_code = ACPI_OST_SC_SUCCESS;
714 break;
715
716 case ACPI_NOTIFY_EJECT_REQUEST:
717 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
718 "received ACPI_NOTIFY_EJECT_REQUEST\n"));
719
720 if (acpi_bus_get_device(handle, &device)) {
721 acpi_handle_err(handle,
722 "Device don't exist, dropping EJECT\n");
723 break;
724 }
725 if (!acpi_driver_data(device)) {
726 acpi_handle_err(handle,
727 "Driver data is NULL, dropping EJECT\n");
728 break;
729 }
730
731 ej_event = kmalloc(sizeof(*ej_event), GFP_KERNEL);
732 if (!ej_event) {
733 acpi_handle_err(handle, "No memory, dropping EJECT\n");
734 break;
735 }
736
737 get_device(&device->dev);
738 ej_event->device = device;
739 ej_event->event = ACPI_NOTIFY_EJECT_REQUEST;
740 /* The eject is carried out asynchronously. */
741 status = acpi_os_hotplug_execute(acpi_bus_hot_remove_device,
742 ej_event);
743 if (ACPI_FAILURE(status)) {
744 put_device(&device->dev);
745 kfree(ej_event);
746 break;
747 }
748 goto out;
749
750 default:
751 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
752 "Unsupported event [0x%x]\n", event));
753
754 /* non-hotplug event; possibly handled by other handler */
755 goto out;
756 }
757
758 /* Inform firmware that the hotplug operation has completed */
759 (void) acpi_evaluate_hotplug_ost(handle, event, ost_code, NULL);
760
761 out:
762 acpi_scan_lock_release();
763}
764
765static acpi_status is_processor_device(acpi_handle handle)
766{
767 struct acpi_device_info *info;
768 char *hid;
769 acpi_status status;
770
771 status = acpi_get_object_info(handle, &info);
772 if (ACPI_FAILURE(status))
773 return status;
774
775 if (info->type == ACPI_TYPE_PROCESSOR) {
776 kfree(info);
777 return AE_OK; /* found a processor object */
778 }
779
780 if (!(info->valid & ACPI_VALID_HID)) {
781 kfree(info);
782 return AE_ERROR;
783 }
784
785 hid = info->hardware_id.string;
786 if ((hid == NULL) || strcmp(hid, ACPI_PROCESSOR_DEVICE_HID)) {
787 kfree(info);
788 return AE_ERROR;
789 }
790
791 kfree(info);
792 return AE_OK; /* found a processor device object */
793}
794
795static acpi_status
796processor_walk_namespace_cb(acpi_handle handle,
797 u32 lvl, void *context, void **rv)
798{
799 acpi_status status;
800 int *action = context;
801
802 status = is_processor_device(handle);
803 if (ACPI_FAILURE(status))
804 return AE_OK; /* not a processor; continue to walk */
805
806 switch (*action) {
807 case INSTALL_NOTIFY_HANDLER:
808 acpi_install_notify_handler(handle,
809 ACPI_SYSTEM_NOTIFY,
810 acpi_processor_hotplug_notify,
811 NULL);
812 break;
813 case UNINSTALL_NOTIFY_HANDLER:
814 acpi_remove_notify_handler(handle,
815 ACPI_SYSTEM_NOTIFY,
816 acpi_processor_hotplug_notify);
817 break;
818 default:
819 break;
820 }
821
822 /* found a processor; skip walking underneath */
823 return AE_CTRL_DEPTH;
824}
825
826static acpi_status acpi_processor_hotadd_init(struct acpi_processor *pr)
827{
828 acpi_handle handle = pr->handle;
829
830 if (!is_processor_present(handle)) {
831 return AE_ERROR;
832 }
833
834 if (acpi_map_lsapic(handle, &pr->id))
835 return AE_ERROR;
836
837 if (arch_register_cpu(pr->id)) {
838 acpi_unmap_lsapic(pr->id);
839 return AE_ERROR;
840 }
841
842 /* CPU got hot-plugged, but cpu_data is not initialized yet
843 * Set flag to delay cpu_idle/throttling initialization
844 * in:
845 * acpi_processor_add()
846 * acpi_processor_get_info()
847 * and do it when the CPU gets online the first time
848 * TBD: Cleanup above functions and try to do this more elegant.
849 */
850 pr_info("CPU %d got hotplugged\n", pr->id);
851 pr->flags.need_hotplug_init = 1;
852
853 return AE_OK;
854}
855
856static int acpi_processor_handle_eject(struct acpi_processor *pr)
857{
858 if (cpu_online(pr->id))
859 cpu_down(pr->id);
860
861 get_online_cpus();
862 /*
863 * The cpu might become online again at this point. So we check whether
864 * the cpu has been onlined or not. If the cpu became online, it means
865 * that someone wants to use the cpu. So acpi_processor_handle_eject()
866 * returns -EAGAIN.
867 */
868 if (unlikely(cpu_online(pr->id))) {
869 put_online_cpus();
870 pr_warn("Failed to remove CPU %d, because other task "
871 "brought the CPU back online\n", pr->id);
872 return -EAGAIN;
873 }
874 arch_unregister_cpu(pr->id);
875 acpi_unmap_lsapic(pr->id);
876 put_online_cpus();
877 return (0);
878}
879#else
880static acpi_status acpi_processor_hotadd_init(struct acpi_processor *pr)
881{
882 return AE_ERROR;
883}
884static int acpi_processor_handle_eject(struct acpi_processor *pr)
885{
886 return (-EINVAL);
887}
888#endif
889
890static
891void acpi_processor_install_hotplug_notify(void)
892{
893#ifdef CONFIG_ACPI_HOTPLUG_CPU
894 int action = INSTALL_NOTIFY_HANDLER;
895 acpi_walk_namespace(ACPI_TYPE_ANY,
896 ACPI_ROOT_OBJECT,
897 ACPI_UINT32_MAX,
898 processor_walk_namespace_cb, NULL, &action, NULL);
899#endif
900 register_hotcpu_notifier(&acpi_cpu_notifier);
901}
902
903static
904void acpi_processor_uninstall_hotplug_notify(void)
905{
906#ifdef CONFIG_ACPI_HOTPLUG_CPU
907 int action = UNINSTALL_NOTIFY_HANDLER;
908 acpi_walk_namespace(ACPI_TYPE_ANY,
909 ACPI_ROOT_OBJECT,
910 ACPI_UINT32_MAX,
911 processor_walk_namespace_cb, NULL, &action, NULL);
912#endif
913 unregister_hotcpu_notifier(&acpi_cpu_notifier);
914}
915
916/* 265/*
917 * We keep the driver loaded even when ACPI is not running. 266 * We keep the driver loaded even when ACPI is not running.
918 * This is needed for the powernow-k8 driver, that works even without 267 * This is needed for the powernow-k8 driver, that works even without
919 * ACPI, but needs symbols from this driver 268 * ACPI, but needs symbols from this driver
920 */ 269 */
921 270
922static int __init acpi_processor_init(void) 271static int __init acpi_processor_driver_init(void)
923{ 272{
924 int result = 0; 273 int result = 0;
925 274
926 if (acpi_disabled) 275 if (acpi_disabled)
927 return 0; 276 return 0;
928 277
929 result = acpi_bus_register_driver(&acpi_processor_driver); 278 result = driver_register(&acpi_processor_driver);
930 if (result < 0) 279 if (result < 0)
931 return result; 280 return result;
932 281
933 acpi_processor_syscore_init(); 282 acpi_processor_syscore_init();
934 283 register_hotcpu_notifier(&acpi_cpu_notifier);
935 acpi_processor_install_hotplug_notify();
936
937 acpi_thermal_cpufreq_init(); 284 acpi_thermal_cpufreq_init();
938
939 acpi_processor_ppc_init(); 285 acpi_processor_ppc_init();
940
941 acpi_processor_throttling_init(); 286 acpi_processor_throttling_init();
942
943 return 0; 287 return 0;
944} 288}
945 289
946static void __exit acpi_processor_exit(void) 290static void __exit acpi_processor_driver_exit(void)
947{ 291{
948 if (acpi_disabled) 292 if (acpi_disabled)
949 return; 293 return;
950 294
951 acpi_processor_ppc_exit(); 295 acpi_processor_ppc_exit();
952
953 acpi_thermal_cpufreq_exit(); 296 acpi_thermal_cpufreq_exit();
954 297 unregister_hotcpu_notifier(&acpi_cpu_notifier);
955 acpi_processor_uninstall_hotplug_notify();
956
957 acpi_processor_syscore_exit(); 298 acpi_processor_syscore_exit();
958 299 driver_unregister(&acpi_processor_driver);
959 acpi_bus_unregister_driver(&acpi_processor_driver);
960
961 return;
962} 300}
963 301
964module_init(acpi_processor_init); 302module_init(acpi_processor_driver_init);
965module_exit(acpi_processor_exit); 303module_exit(acpi_processor_driver_exit);
966 304
967MODULE_ALIAS("processor"); 305MODULE_ALIAS("processor");
diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
index eb133c77aadb..0461ccc92c54 100644
--- a/drivers/acpi/processor_idle.c
+++ b/drivers/acpi/processor_idle.c
@@ -214,13 +214,13 @@ static void lapic_timer_state_broadcast(struct acpi_processor *pr,
214#ifdef CONFIG_PM_SLEEP 214#ifdef CONFIG_PM_SLEEP
215static u32 saved_bm_rld; 215static u32 saved_bm_rld;
216 216
217int acpi_processor_suspend(void) 217static int acpi_processor_suspend(void)
218{ 218{
219 acpi_read_bit_register(ACPI_BITREG_BUS_MASTER_RLD, &saved_bm_rld); 219 acpi_read_bit_register(ACPI_BITREG_BUS_MASTER_RLD, &saved_bm_rld);
220 return 0; 220 return 0;
221} 221}
222 222
223void acpi_processor_resume(void) 223static void acpi_processor_resume(void)
224{ 224{
225 u32 resumed_bm_rld; 225 u32 resumed_bm_rld;
226 226
diff --git a/drivers/acpi/processor_perflib.c b/drivers/acpi/processor_perflib.c
index e854582f29a6..1e9732d809bf 100644
--- a/drivers/acpi/processor_perflib.c
+++ b/drivers/acpi/processor_perflib.c
@@ -639,7 +639,7 @@ end:
639int acpi_processor_preregister_performance( 639int acpi_processor_preregister_performance(
640 struct acpi_processor_performance __percpu *performance) 640 struct acpi_processor_performance __percpu *performance)
641{ 641{
642 int count, count_target; 642 int count_target;
643 int retval = 0; 643 int retval = 0;
644 unsigned int i, j; 644 unsigned int i, j;
645 cpumask_var_t covered_cpus; 645 cpumask_var_t covered_cpus;
@@ -711,7 +711,6 @@ int acpi_processor_preregister_performance(
711 711
712 /* Validate the Domain info */ 712 /* Validate the Domain info */
713 count_target = pdomain->num_processors; 713 count_target = pdomain->num_processors;
714 count = 1;
715 if (pdomain->coord_type == DOMAIN_COORD_TYPE_SW_ALL) 714 if (pdomain->coord_type == DOMAIN_COORD_TYPE_SW_ALL)
716 pr->performance->shared_type = CPUFREQ_SHARED_TYPE_ALL; 715 pr->performance->shared_type = CPUFREQ_SHARED_TYPE_ALL;
717 else if (pdomain->coord_type == DOMAIN_COORD_TYPE_HW_ALL) 716 else if (pdomain->coord_type == DOMAIN_COORD_TYPE_HW_ALL)
@@ -745,7 +744,6 @@ int acpi_processor_preregister_performance(
745 744
746 cpumask_set_cpu(j, covered_cpus); 745 cpumask_set_cpu(j, covered_cpus);
747 cpumask_set_cpu(j, pr->performance->shared_cpu_map); 746 cpumask_set_cpu(j, pr->performance->shared_cpu_map);
748 count++;
749 } 747 }
750 748
751 for_each_possible_cpu(j) { 749 for_each_possible_cpu(j) {
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index 27da63061e11..dfe76f17cfc4 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -27,6 +27,12 @@ extern struct acpi_device *acpi_root;
27 27
28#define ACPI_IS_ROOT_DEVICE(device) (!(device)->parent) 28#define ACPI_IS_ROOT_DEVICE(device) (!(device)->parent)
29 29
30/*
31 * If set, devices will be hot-removed even if they cannot be put offline
32 * gracefully (from the kernel's standpoint).
33 */
34bool acpi_force_hot_remove;
35
30static const char *dummy_hid = "device"; 36static const char *dummy_hid = "device";
31 37
32static LIST_HEAD(acpi_device_list); 38static LIST_HEAD(acpi_device_list);
@@ -120,12 +126,78 @@ acpi_device_modalias_show(struct device *dev, struct device_attribute *attr, cha
120} 126}
121static DEVICE_ATTR(modalias, 0444, acpi_device_modalias_show, NULL); 127static DEVICE_ATTR(modalias, 0444, acpi_device_modalias_show, NULL);
122 128
129static acpi_status acpi_bus_offline_companions(acpi_handle handle, u32 lvl,
130 void *data, void **ret_p)
131{
132 struct acpi_device *device = NULL;
133 struct acpi_device_physical_node *pn;
134 bool second_pass = (bool)data;
135 acpi_status status = AE_OK;
136
137 if (acpi_bus_get_device(handle, &device))
138 return AE_OK;
139
140 mutex_lock(&device->physical_node_lock);
141
142 list_for_each_entry(pn, &device->physical_node_list, node) {
143 int ret;
144
145 if (second_pass) {
146 /* Skip devices offlined by the first pass. */
147 if (pn->put_online)
148 continue;
149 } else {
150 pn->put_online = false;
151 }
152 ret = device_offline(pn->dev);
153 if (acpi_force_hot_remove)
154 continue;
155
156 if (ret >= 0) {
157 pn->put_online = !ret;
158 } else {
159 *ret_p = pn->dev;
160 if (second_pass) {
161 status = AE_ERROR;
162 break;
163 }
164 }
165 }
166
167 mutex_unlock(&device->physical_node_lock);
168
169 return status;
170}
171
172static acpi_status acpi_bus_online_companions(acpi_handle handle, u32 lvl,
173 void *data, void **ret_p)
174{
175 struct acpi_device *device = NULL;
176 struct acpi_device_physical_node *pn;
177
178 if (acpi_bus_get_device(handle, &device))
179 return AE_OK;
180
181 mutex_lock(&device->physical_node_lock);
182
183 list_for_each_entry(pn, &device->physical_node_list, node)
184 if (pn->put_online) {
185 device_online(pn->dev);
186 pn->put_online = false;
187 }
188
189 mutex_unlock(&device->physical_node_lock);
190
191 return AE_OK;
192}
193
123static int acpi_scan_hot_remove(struct acpi_device *device) 194static int acpi_scan_hot_remove(struct acpi_device *device)
124{ 195{
125 acpi_handle handle = device->handle; 196 acpi_handle handle = device->handle;
126 acpi_handle not_used; 197 acpi_handle not_used;
127 struct acpi_object_list arg_list; 198 struct acpi_object_list arg_list;
128 union acpi_object arg; 199 union acpi_object arg;
200 struct device *errdev;
129 acpi_status status; 201 acpi_status status;
130 unsigned long long sta; 202 unsigned long long sta;
131 203
@@ -136,10 +208,53 @@ static int acpi_scan_hot_remove(struct acpi_device *device)
136 return -EINVAL; 208 return -EINVAL;
137 } 209 }
138 210
211 lock_device_hotplug();
212
213 /*
214 * Carry out two passes here and ignore errors in the first pass,
215 * because if the devices in question are memory blocks and
216 * CONFIG_MEMCG is set, one of the blocks may hold data structures
217 * that the other blocks depend on, but it is not known in advance which
218 * block holds them.
219 *
220 * If the first pass is successful, the second one isn't needed, though.
221 */
222 errdev = NULL;
223 acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX,
224 NULL, acpi_bus_offline_companions,
225 (void *)false, (void **)&errdev);
226 acpi_bus_offline_companions(handle, 0, (void *)false, (void **)&errdev);
227 if (errdev) {
228 errdev = NULL;
229 acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX,
230 NULL, acpi_bus_offline_companions,
231 (void *)true , (void **)&errdev);
232 if (!errdev || acpi_force_hot_remove)
233 acpi_bus_offline_companions(handle, 0, (void *)true,
234 (void **)&errdev);
235
236 if (errdev && !acpi_force_hot_remove) {
237 dev_warn(errdev, "Offline failed.\n");
238 acpi_bus_online_companions(handle, 0, NULL, NULL);
239 acpi_walk_namespace(ACPI_TYPE_ANY, handle,
240 ACPI_UINT32_MAX,
241 acpi_bus_online_companions, NULL,
242 NULL, NULL);
243
244 unlock_device_hotplug();
245
246 put_device(&device->dev);
247 return -EBUSY;
248 }
249 }
250
139 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 251 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
140 "Hot-removing device %s...\n", dev_name(&device->dev))); 252 "Hot-removing device %s...\n", dev_name(&device->dev)));
141 253
142 acpi_bus_trim(device); 254 acpi_bus_trim(device);
255
256 unlock_device_hotplug();
257
143 /* Device node has been unregistered. */ 258 /* Device node has been unregistered. */
144 put_device(&device->dev); 259 put_device(&device->dev);
145 device = NULL; 260 device = NULL;
@@ -236,6 +351,7 @@ static void acpi_scan_bus_device_check(acpi_handle handle, u32 ost_source)
236 int error; 351 int error;
237 352
238 mutex_lock(&acpi_scan_lock); 353 mutex_lock(&acpi_scan_lock);
354 lock_device_hotplug();
239 355
240 acpi_bus_get_device(handle, &device); 356 acpi_bus_get_device(handle, &device);
241 if (device) { 357 if (device) {
@@ -259,6 +375,7 @@ static void acpi_scan_bus_device_check(acpi_handle handle, u32 ost_source)
259 kobject_uevent(&device->dev.kobj, KOBJ_ONLINE); 375 kobject_uevent(&device->dev.kobj, KOBJ_ONLINE);
260 376
261 out: 377 out:
378 unlock_device_hotplug();
262 acpi_evaluate_hotplug_ost(handle, ost_source, ost_code, NULL); 379 acpi_evaluate_hotplug_ost(handle, ost_source, ost_code, NULL);
263 mutex_unlock(&acpi_scan_lock); 380 mutex_unlock(&acpi_scan_lock);
264} 381}
@@ -816,32 +933,43 @@ static void acpi_device_remove_notify_handler(struct acpi_device *device)
816 acpi_device_notify); 933 acpi_device_notify);
817} 934}
818 935
819static int acpi_bus_driver_init(struct acpi_device *, struct acpi_driver *); 936static int acpi_device_probe(struct device *dev)
820static int acpi_device_probe(struct device * dev)
821{ 937{
822 struct acpi_device *acpi_dev = to_acpi_device(dev); 938 struct acpi_device *acpi_dev = to_acpi_device(dev);
823 struct acpi_driver *acpi_drv = to_acpi_driver(dev->driver); 939 struct acpi_driver *acpi_drv = to_acpi_driver(dev->driver);
824 int ret; 940 int ret;
825 941
826 ret = acpi_bus_driver_init(acpi_dev, acpi_drv); 942 if (acpi_dev->handler)
827 if (!ret) { 943 return -EINVAL;
828 if (acpi_drv->ops.notify) {
829 ret = acpi_device_install_notify_handler(acpi_dev);
830 if (ret) {
831 if (acpi_drv->ops.remove)
832 acpi_drv->ops.remove(acpi_dev);
833 acpi_dev->driver = NULL;
834 acpi_dev->driver_data = NULL;
835 return ret;
836 }
837 }
838 944
839 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 945 if (!acpi_drv->ops.add)
840 "Found driver [%s] for device [%s]\n", 946 return -ENOSYS;
841 acpi_drv->name, acpi_dev->pnp.bus_id)); 947
842 get_device(dev); 948 ret = acpi_drv->ops.add(acpi_dev);
949 if (ret)
950 return ret;
951
952 acpi_dev->driver = acpi_drv;
953 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
954 "Driver [%s] successfully bound to device [%s]\n",
955 acpi_drv->name, acpi_dev->pnp.bus_id));
956
957 if (acpi_drv->ops.notify) {
958 ret = acpi_device_install_notify_handler(acpi_dev);
959 if (ret) {
960 if (acpi_drv->ops.remove)
961 acpi_drv->ops.remove(acpi_dev);
962
963 acpi_dev->driver = NULL;
964 acpi_dev->driver_data = NULL;
965 return ret;
966 }
843 } 967 }
844 return ret; 968
969 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found driver [%s] for device [%s]\n",
970 acpi_drv->name, acpi_dev->pnp.bus_id));
971 get_device(dev);
972 return 0;
845} 973}
846 974
847static int acpi_device_remove(struct device * dev) 975static int acpi_device_remove(struct device * dev)
@@ -952,7 +1080,6 @@ int acpi_device_add(struct acpi_device *device,
952 printk(KERN_ERR PREFIX "Error creating sysfs interface for device %s\n", 1080 printk(KERN_ERR PREFIX "Error creating sysfs interface for device %s\n",
953 dev_name(&device->dev)); 1081 dev_name(&device->dev));
954 1082
955 device->removal_type = ACPI_BUS_REMOVAL_NORMAL;
956 return 0; 1083 return 0;
957 1084
958 err: 1085 err:
@@ -998,41 +1125,6 @@ static void acpi_device_unregister(struct acpi_device *device)
998 Driver Management 1125 Driver Management
999 -------------------------------------------------------------------------- */ 1126 -------------------------------------------------------------------------- */
1000/** 1127/**
1001 * acpi_bus_driver_init - add a device to a driver
1002 * @device: the device to add and initialize
1003 * @driver: driver for the device
1004 *
1005 * Used to initialize a device via its device driver. Called whenever a
1006 * driver is bound to a device. Invokes the driver's add() ops.
1007 */
1008static int
1009acpi_bus_driver_init(struct acpi_device *device, struct acpi_driver *driver)
1010{
1011 int result = 0;
1012
1013 if (!device || !driver)
1014 return -EINVAL;
1015
1016 if (!driver->ops.add)
1017 return -ENOSYS;
1018
1019 result = driver->ops.add(device);
1020 if (result)
1021 return result;
1022
1023 device->driver = driver;
1024
1025 /*
1026 * TBD - Configuration Management: Assign resources to device based
1027 * upon possible configuration and currently allocated resources.
1028 */
1029
1030 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1031 "Driver successfully bound to device\n"));
1032 return 0;
1033}
1034
1035/**
1036 * acpi_bus_register_driver - register a driver with the ACPI bus 1128 * acpi_bus_register_driver - register a driver with the ACPI bus
1037 * @driver: driver being registered 1129 * @driver: driver being registered
1038 * 1130 *
@@ -1939,7 +2031,6 @@ static acpi_status acpi_bus_device_detach(acpi_handle handle, u32 lvl_not_used,
1939 if (!acpi_bus_get_device(handle, &device)) { 2031 if (!acpi_bus_get_device(handle, &device)) {
1940 struct acpi_scan_handler *dev_handler = device->handler; 2032 struct acpi_scan_handler *dev_handler = device->handler;
1941 2033
1942 device->removal_type = ACPI_BUS_REMOVAL_EJECT;
1943 if (dev_handler) { 2034 if (dev_handler) {
1944 if (dev_handler->detach) 2035 if (dev_handler->detach)
1945 dev_handler->detach(device); 2036 dev_handler->detach(device);
@@ -2038,8 +2129,10 @@ int __init acpi_scan_init(void)
2038 2129
2039 acpi_pci_root_init(); 2130 acpi_pci_root_init();
2040 acpi_pci_link_init(); 2131 acpi_pci_link_init();
2132 acpi_processor_init();
2041 acpi_platform_init(); 2133 acpi_platform_init();
2042 acpi_lpss_init(); 2134 acpi_lpss_init();
2135 acpi_cmos_rtc_init();
2043 acpi_container_init(); 2136 acpi_container_init();
2044 acpi_memory_hotplug_init(); 2137 acpi_memory_hotplug_init();
2045 acpi_dock_init(); 2138 acpi_dock_init();
diff --git a/drivers/acpi/sleep.c b/drivers/acpi/sleep.c
index 9c1a435d10e6..187ab61889e6 100644
--- a/drivers/acpi/sleep.c
+++ b/drivers/acpi/sleep.c
@@ -494,6 +494,8 @@ static int acpi_suspend_enter(suspend_state_t pm_state)
494 break; 494 break;
495 495
496 case ACPI_STATE_S3: 496 case ACPI_STATE_S3:
497 if (!acpi_suspend_lowlevel)
498 return -ENOSYS;
497 error = acpi_suspend_lowlevel(); 499 error = acpi_suspend_lowlevel();
498 if (error) 500 if (error)
499 return error; 501 return error;
diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
index fcae5fa2e1b3..5c5d1624fa2c 100644
--- a/drivers/acpi/sysfs.c
+++ b/drivers/acpi/sysfs.c
@@ -780,6 +780,33 @@ void acpi_sysfs_add_hotplug_profile(struct acpi_hotplug_profile *hotplug,
780 pr_err(PREFIX "Unable to add hotplug profile '%s'\n", name); 780 pr_err(PREFIX "Unable to add hotplug profile '%s'\n", name);
781} 781}
782 782
783static ssize_t force_remove_show(struct kobject *kobj,
784 struct kobj_attribute *attr, char *buf)
785{
786 return sprintf(buf, "%d\n", !!acpi_force_hot_remove);
787}
788
789static ssize_t force_remove_store(struct kobject *kobj,
790 struct kobj_attribute *attr,
791 const char *buf, size_t size)
792{
793 bool val;
794 int ret;
795
796 ret = strtobool(buf, &val);
797 if (ret < 0)
798 return ret;
799
800 lock_device_hotplug();
801 acpi_force_hot_remove = val;
802 unlock_device_hotplug();
803 return size;
804}
805
806static const struct kobj_attribute force_remove_attr =
807 __ATTR(force_remove, S_IRUGO | S_IWUSR, force_remove_show,
808 force_remove_store);
809
783int __init acpi_sysfs_init(void) 810int __init acpi_sysfs_init(void)
784{ 811{
785 int result; 812 int result;
@@ -789,6 +816,10 @@ int __init acpi_sysfs_init(void)
789 return result; 816 return result;
790 817
791 hotplug_kobj = kobject_create_and_add("hotplug", acpi_kobj); 818 hotplug_kobj = kobject_create_and_add("hotplug", acpi_kobj);
819 result = sysfs_create_file(hotplug_kobj, &force_remove_attr.attr);
820 if (result)
821 return result;
822
792 result = sysfs_create_file(acpi_kobj, &pm_profile_attr.attr); 823 result = sysfs_create_file(acpi_kobj, &pm_profile_attr.attr);
793 return result; 824 return result;
794} 825}
diff --git a/drivers/acpi/video.c b/drivers/acpi/video.c
index 440eadf2d32c..5d7075d25700 100644
--- a/drivers/acpi/video.c
+++ b/drivers/acpi/video.c
@@ -1722,9 +1722,6 @@ static int acpi_video_bus_add(struct acpi_device *device)
1722 int error; 1722 int error;
1723 acpi_status status; 1723 acpi_status status;
1724 1724
1725 if (device->handler)
1726 return -EINVAL;
1727
1728 status = acpi_walk_namespace(ACPI_TYPE_DEVICE, 1725 status = acpi_walk_namespace(ACPI_TYPE_DEVICE,
1729 device->parent->handle, 1, 1726 device->parent->handle, 1,
1730 acpi_video_bus_match, NULL, 1727 acpi_video_bus_match, NULL,
diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
index cdbad3a454a0..c6707278a6bb 100644
--- a/drivers/amba/bus.c
+++ b/drivers/amba/bus.c
@@ -284,7 +284,7 @@ static const struct dev_pm_ops amba_pm = {
284 SET_RUNTIME_PM_OPS( 284 SET_RUNTIME_PM_OPS(
285 amba_pm_runtime_suspend, 285 amba_pm_runtime_suspend,
286 amba_pm_runtime_resume, 286 amba_pm_runtime_resume,
287 pm_generic_runtime_idle 287 NULL
288 ) 288 )
289}; 289};
290 290
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index adf002a3c584..6e458a40a93b 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -5436,7 +5436,7 @@ static int ata_port_runtime_idle(struct device *dev)
5436 return -EBUSY; 5436 return -EBUSY;
5437 } 5437 }
5438 5438
5439 return pm_runtime_suspend(dev); 5439 return 0;
5440} 5440}
5441 5441
5442static int ata_port_runtime_suspend(struct device *dev) 5442static int ata_port_runtime_suspend(struct device *dev)
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 6fdc53d46fa0..dc3ea237f086 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -403,6 +403,36 @@ static ssize_t store_uevent(struct device *dev, struct device_attribute *attr,
403static struct device_attribute uevent_attr = 403static struct device_attribute uevent_attr =
404 __ATTR(uevent, S_IRUGO | S_IWUSR, show_uevent, store_uevent); 404 __ATTR(uevent, S_IRUGO | S_IWUSR, show_uevent, store_uevent);
405 405
406static ssize_t show_online(struct device *dev, struct device_attribute *attr,
407 char *buf)
408{
409 bool val;
410
411 lock_device_hotplug();
412 val = !dev->offline;
413 unlock_device_hotplug();
414 return sprintf(buf, "%u\n", val);
415}
416
417static ssize_t store_online(struct device *dev, struct device_attribute *attr,
418 const char *buf, size_t count)
419{
420 bool val;
421 int ret;
422
423 ret = strtobool(buf, &val);
424 if (ret < 0)
425 return ret;
426
427 lock_device_hotplug();
428 ret = val ? device_online(dev) : device_offline(dev);
429 unlock_device_hotplug();
430 return ret < 0 ? ret : count;
431}
432
433static struct device_attribute online_attr =
434 __ATTR(online, S_IRUGO | S_IWUSR, show_online, store_online);
435
406static int device_add_attributes(struct device *dev, 436static int device_add_attributes(struct device *dev,
407 struct device_attribute *attrs) 437 struct device_attribute *attrs)
408{ 438{
@@ -516,6 +546,12 @@ static int device_add_attrs(struct device *dev)
516 if (error) 546 if (error)
517 goto err_remove_type_groups; 547 goto err_remove_type_groups;
518 548
549 if (device_supports_offline(dev) && !dev->offline_disabled) {
550 error = device_create_file(dev, &online_attr);
551 if (error)
552 goto err_remove_type_groups;
553 }
554
519 return 0; 555 return 0;
520 556
521 err_remove_type_groups: 557 err_remove_type_groups:
@@ -536,6 +572,7 @@ static void device_remove_attrs(struct device *dev)
536 struct class *class = dev->class; 572 struct class *class = dev->class;
537 const struct device_type *type = dev->type; 573 const struct device_type *type = dev->type;
538 574
575 device_remove_file(dev, &online_attr);
539 device_remove_groups(dev, dev->groups); 576 device_remove_groups(dev, dev->groups);
540 577
541 if (type) 578 if (type)
@@ -1435,6 +1472,99 @@ EXPORT_SYMBOL_GPL(put_device);
1435EXPORT_SYMBOL_GPL(device_create_file); 1472EXPORT_SYMBOL_GPL(device_create_file);
1436EXPORT_SYMBOL_GPL(device_remove_file); 1473EXPORT_SYMBOL_GPL(device_remove_file);
1437 1474
1475static DEFINE_MUTEX(device_hotplug_lock);
1476
1477void lock_device_hotplug(void)
1478{
1479 mutex_lock(&device_hotplug_lock);
1480}
1481
1482void unlock_device_hotplug(void)
1483{
1484 mutex_unlock(&device_hotplug_lock);
1485}
1486
1487static int device_check_offline(struct device *dev, void *not_used)
1488{
1489 int ret;
1490
1491 ret = device_for_each_child(dev, NULL, device_check_offline);
1492 if (ret)
1493 return ret;
1494
1495 return device_supports_offline(dev) && !dev->offline ? -EBUSY : 0;
1496}
1497
1498/**
1499 * device_offline - Prepare the device for hot-removal.
1500 * @dev: Device to be put offline.
1501 *
1502 * Execute the device bus type's .offline() callback, if present, to prepare
1503 * the device for a subsequent hot-removal. If that succeeds, the device must
1504 * not be used until either it is removed or its bus type's .online() callback
1505 * is executed.
1506 *
1507 * Call under device_hotplug_lock.
1508 */
1509int device_offline(struct device *dev)
1510{
1511 int ret;
1512
1513 if (dev->offline_disabled)
1514 return -EPERM;
1515
1516 ret = device_for_each_child(dev, NULL, device_check_offline);
1517 if (ret)
1518 return ret;
1519
1520 device_lock(dev);
1521 if (device_supports_offline(dev)) {
1522 if (dev->offline) {
1523 ret = 1;
1524 } else {
1525 ret = dev->bus->offline(dev);
1526 if (!ret) {
1527 kobject_uevent(&dev->kobj, KOBJ_OFFLINE);
1528 dev->offline = true;
1529 }
1530 }
1531 }
1532 device_unlock(dev);
1533
1534 return ret;
1535}
1536
1537/**
1538 * device_online - Put the device back online after successful device_offline().
1539 * @dev: Device to be put back online.
1540 *
1541 * If device_offline() has been successfully executed for @dev, but the device
1542 * has not been removed subsequently, execute its bus type's .online() callback
1543 * to indicate that the device can be used again.
1544 *
1545 * Call under device_hotplug_lock.
1546 */
1547int device_online(struct device *dev)
1548{
1549 int ret = 0;
1550
1551 device_lock(dev);
1552 if (device_supports_offline(dev)) {
1553 if (dev->offline) {
1554 ret = dev->bus->online(dev);
1555 if (!ret) {
1556 kobject_uevent(&dev->kobj, KOBJ_ONLINE);
1557 dev->offline = false;
1558 }
1559 } else {
1560 ret = 1;
1561 }
1562 }
1563 device_unlock(dev);
1564
1565 return ret;
1566}
1567
1438struct root_device { 1568struct root_device {
1439 struct device dev; 1569 struct device dev;
1440 struct module *owner; 1570 struct module *owner;
diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c
index c377673320ed..a16d20e389f0 100644
--- a/drivers/base/cpu.c
+++ b/drivers/base/cpu.c
@@ -13,17 +13,21 @@
13#include <linux/gfp.h> 13#include <linux/gfp.h>
14#include <linux/slab.h> 14#include <linux/slab.h>
15#include <linux/percpu.h> 15#include <linux/percpu.h>
16#include <linux/acpi.h>
16 17
17#include "base.h" 18#include "base.h"
18 19
19struct bus_type cpu_subsys = {
20 .name = "cpu",
21 .dev_name = "cpu",
22};
23EXPORT_SYMBOL_GPL(cpu_subsys);
24
25static DEFINE_PER_CPU(struct device *, cpu_sys_devices); 20static DEFINE_PER_CPU(struct device *, cpu_sys_devices);
26 21
22static int cpu_subsys_match(struct device *dev, struct device_driver *drv)
23{
24 /* ACPI style match is the only one that may succeed. */
25 if (acpi_driver_match_device(dev, drv))
26 return 1;
27
28 return 0;
29}
30
27#ifdef CONFIG_HOTPLUG_CPU 31#ifdef CONFIG_HOTPLUG_CPU
28static void change_cpu_under_node(struct cpu *cpu, 32static void change_cpu_under_node(struct cpu *cpu,
29 unsigned int from_nid, unsigned int to_nid) 33 unsigned int from_nid, unsigned int to_nid)
@@ -34,65 +38,38 @@ static void change_cpu_under_node(struct cpu *cpu,
34 cpu->node_id = to_nid; 38 cpu->node_id = to_nid;
35} 39}
36 40
37static ssize_t show_online(struct device *dev, 41static int __ref cpu_subsys_online(struct device *dev)
38 struct device_attribute *attr,
39 char *buf)
40{ 42{
41 struct cpu *cpu = container_of(dev, struct cpu, dev); 43 struct cpu *cpu = container_of(dev, struct cpu, dev);
44 int cpuid = dev->id;
45 int from_nid, to_nid;
46 int ret;
47
48 cpu_hotplug_driver_lock();
42 49
43 return sprintf(buf, "%u\n", !!cpu_online(cpu->dev.id)); 50 from_nid = cpu_to_node(cpuid);
51 ret = cpu_up(cpuid);
52 /*
53 * When hot adding memory to memoryless node and enabling a cpu
54 * on the node, node number of the cpu may internally change.
55 */
56 to_nid = cpu_to_node(cpuid);
57 if (from_nid != to_nid)
58 change_cpu_under_node(cpu, from_nid, to_nid);
59
60 cpu_hotplug_driver_unlock();
61 return ret;
44} 62}
45 63
46static ssize_t __ref store_online(struct device *dev, 64static int cpu_subsys_offline(struct device *dev)
47 struct device_attribute *attr,
48 const char *buf, size_t count)
49{ 65{
50 struct cpu *cpu = container_of(dev, struct cpu, dev); 66 int ret;
51 int cpuid = cpu->dev.id;
52 int from_nid, to_nid;
53 ssize_t ret;
54 67
55 cpu_hotplug_driver_lock(); 68 cpu_hotplug_driver_lock();
56 switch (buf[0]) { 69 ret = cpu_down(dev->id);
57 case '0':
58 ret = cpu_down(cpuid);
59 if (!ret)
60 kobject_uevent(&dev->kobj, KOBJ_OFFLINE);
61 break;
62 case '1':
63 from_nid = cpu_to_node(cpuid);
64 ret = cpu_up(cpuid);
65
66 /*
67 * When hot adding memory to memoryless node and enabling a cpu
68 * on the node, node number of the cpu may internally change.
69 */
70 to_nid = cpu_to_node(cpuid);
71 if (from_nid != to_nid)
72 change_cpu_under_node(cpu, from_nid, to_nid);
73
74 if (!ret)
75 kobject_uevent(&dev->kobj, KOBJ_ONLINE);
76 break;
77 default:
78 ret = -EINVAL;
79 }
80 cpu_hotplug_driver_unlock(); 70 cpu_hotplug_driver_unlock();
81
82 if (ret >= 0)
83 ret = count;
84 return ret; 71 return ret;
85} 72}
86static DEVICE_ATTR(online, 0644, show_online, store_online);
87
88static struct attribute *hotplug_cpu_attrs[] = {
89 &dev_attr_online.attr,
90 NULL
91};
92
93static struct attribute_group hotplug_cpu_attr_group = {
94 .attrs = hotplug_cpu_attrs,
95};
96 73
97void unregister_cpu(struct cpu *cpu) 74void unregister_cpu(struct cpu *cpu)
98{ 75{
@@ -127,6 +104,17 @@ static DEVICE_ATTR(release, S_IWUSR, NULL, cpu_release_store);
127#endif /* CONFIG_ARCH_CPU_PROBE_RELEASE */ 104#endif /* CONFIG_ARCH_CPU_PROBE_RELEASE */
128#endif /* CONFIG_HOTPLUG_CPU */ 105#endif /* CONFIG_HOTPLUG_CPU */
129 106
107struct bus_type cpu_subsys = {
108 .name = "cpu",
109 .dev_name = "cpu",
110 .match = cpu_subsys_match,
111#ifdef CONFIG_HOTPLUG_CPU
112 .online = cpu_subsys_online,
113 .offline = cpu_subsys_offline,
114#endif
115};
116EXPORT_SYMBOL_GPL(cpu_subsys);
117
130#ifdef CONFIG_KEXEC 118#ifdef CONFIG_KEXEC
131#include <linux/kexec.h> 119#include <linux/kexec.h>
132 120
@@ -185,9 +173,6 @@ static const struct attribute_group *hotplugable_cpu_attr_groups[] = {
185#ifdef CONFIG_KEXEC 173#ifdef CONFIG_KEXEC
186 &crash_note_cpu_attr_group, 174 &crash_note_cpu_attr_group,
187#endif 175#endif
188#ifdef CONFIG_HOTPLUG_CPU
189 &hotplug_cpu_attr_group,
190#endif
191 NULL 176 NULL
192}; 177};
193 178
@@ -302,6 +287,8 @@ int __cpuinit register_cpu(struct cpu *cpu, int num)
302 cpu->dev.id = num; 287 cpu->dev.id = num;
303 cpu->dev.bus = &cpu_subsys; 288 cpu->dev.bus = &cpu_subsys;
304 cpu->dev.release = cpu_device_release; 289 cpu->dev.release = cpu_device_release;
290 cpu->dev.offline_disabled = !cpu->hotpluggable;
291 cpu->dev.offline = !cpu_online(num);
305#ifdef CONFIG_ARCH_HAS_CPU_AUTOPROBE 292#ifdef CONFIG_ARCH_HAS_CPU_AUTOPROBE
306 cpu->dev.bus->uevent = arch_cpu_uevent; 293 cpu->dev.bus->uevent = arch_cpu_uevent;
307#endif 294#endif
diff --git a/drivers/base/memory.c b/drivers/base/memory.c
index e315051cfeeb..2b7813ec6d02 100644
--- a/drivers/base/memory.c
+++ b/drivers/base/memory.c
@@ -37,9 +37,14 @@ static inline int base_memory_block_id(int section_nr)
37 return section_nr / sections_per_block; 37 return section_nr / sections_per_block;
38} 38}
39 39
40static int memory_subsys_online(struct device *dev);
41static int memory_subsys_offline(struct device *dev);
42
40static struct bus_type memory_subsys = { 43static struct bus_type memory_subsys = {
41 .name = MEMORY_CLASS_NAME, 44 .name = MEMORY_CLASS_NAME,
42 .dev_name = MEMORY_CLASS_NAME, 45 .dev_name = MEMORY_CLASS_NAME,
46 .online = memory_subsys_online,
47 .offline = memory_subsys_offline,
43}; 48};
44 49
45static BLOCKING_NOTIFIER_HEAD(memory_chain); 50static BLOCKING_NOTIFIER_HEAD(memory_chain);
@@ -262,33 +267,64 @@ static int __memory_block_change_state(struct memory_block *mem,
262{ 267{
263 int ret = 0; 268 int ret = 0;
264 269
265 if (mem->state != from_state_req) { 270 if (mem->state != from_state_req)
266 ret = -EINVAL; 271 return -EINVAL;
267 goto out;
268 }
269 272
270 if (to_state == MEM_OFFLINE) 273 if (to_state == MEM_OFFLINE)
271 mem->state = MEM_GOING_OFFLINE; 274 mem->state = MEM_GOING_OFFLINE;
272 275
273 ret = memory_block_action(mem->start_section_nr, to_state, online_type); 276 ret = memory_block_action(mem->start_section_nr, to_state, online_type);
277 mem->state = ret ? from_state_req : to_state;
278 return ret;
279}
274 280
275 if (ret) { 281static int memory_subsys_online(struct device *dev)
276 mem->state = from_state_req; 282{
277 goto out; 283 struct memory_block *mem = container_of(dev, struct memory_block, dev);
278 } 284 int ret;
279 285
280 mem->state = to_state; 286 mutex_lock(&mem->state_mutex);
281 switch (mem->state) { 287
282 case MEM_OFFLINE: 288 ret = mem->state == MEM_ONLINE ? 0 :
283 kobject_uevent(&mem->dev.kobj, KOBJ_OFFLINE); 289 __memory_block_change_state(mem, MEM_ONLINE, MEM_OFFLINE,
284 break; 290 ONLINE_KEEP);
285 case MEM_ONLINE: 291
286 kobject_uevent(&mem->dev.kobj, KOBJ_ONLINE); 292 mutex_unlock(&mem->state_mutex);
287 break; 293 return ret;
288 default: 294}
289 break; 295
296static int memory_subsys_offline(struct device *dev)
297{
298 struct memory_block *mem = container_of(dev, struct memory_block, dev);
299 int ret;
300
301 mutex_lock(&mem->state_mutex);
302
303 ret = mem->state == MEM_OFFLINE ? 0 :
304 __memory_block_change_state(mem, MEM_OFFLINE, MEM_ONLINE, -1);
305
306 mutex_unlock(&mem->state_mutex);
307 return ret;
308}
309
310static int __memory_block_change_state_uevent(struct memory_block *mem,
311 unsigned long to_state, unsigned long from_state_req,
312 int online_type)
313{
314 int ret = __memory_block_change_state(mem, to_state, from_state_req,
315 online_type);
316 if (!ret) {
317 switch (mem->state) {
318 case MEM_OFFLINE:
319 kobject_uevent(&mem->dev.kobj, KOBJ_OFFLINE);
320 break;
321 case MEM_ONLINE:
322 kobject_uevent(&mem->dev.kobj, KOBJ_ONLINE);
323 break;
324 default:
325 break;
326 }
290 } 327 }
291out:
292 return ret; 328 return ret;
293} 329}
294 330
@@ -299,8 +335,8 @@ static int memory_block_change_state(struct memory_block *mem,
299 int ret; 335 int ret;
300 336
301 mutex_lock(&mem->state_mutex); 337 mutex_lock(&mem->state_mutex);
302 ret = __memory_block_change_state(mem, to_state, from_state_req, 338 ret = __memory_block_change_state_uevent(mem, to_state, from_state_req,
303 online_type); 339 online_type);
304 mutex_unlock(&mem->state_mutex); 340 mutex_unlock(&mem->state_mutex);
305 341
306 return ret; 342 return ret;
@@ -310,22 +346,34 @@ store_mem_state(struct device *dev,
310 struct device_attribute *attr, const char *buf, size_t count) 346 struct device_attribute *attr, const char *buf, size_t count)
311{ 347{
312 struct memory_block *mem; 348 struct memory_block *mem;
349 bool offline;
313 int ret = -EINVAL; 350 int ret = -EINVAL;
314 351
315 mem = container_of(dev, struct memory_block, dev); 352 mem = container_of(dev, struct memory_block, dev);
316 353
317 if (!strncmp(buf, "online_kernel", min_t(int, count, 13))) 354 lock_device_hotplug();
355
356 if (!strncmp(buf, "online_kernel", min_t(int, count, 13))) {
357 offline = false;
318 ret = memory_block_change_state(mem, MEM_ONLINE, 358 ret = memory_block_change_state(mem, MEM_ONLINE,
319 MEM_OFFLINE, ONLINE_KERNEL); 359 MEM_OFFLINE, ONLINE_KERNEL);
320 else if (!strncmp(buf, "online_movable", min_t(int, count, 14))) 360 } else if (!strncmp(buf, "online_movable", min_t(int, count, 14))) {
361 offline = false;
321 ret = memory_block_change_state(mem, MEM_ONLINE, 362 ret = memory_block_change_state(mem, MEM_ONLINE,
322 MEM_OFFLINE, ONLINE_MOVABLE); 363 MEM_OFFLINE, ONLINE_MOVABLE);
323 else if (!strncmp(buf, "online", min_t(int, count, 6))) 364 } else if (!strncmp(buf, "online", min_t(int, count, 6))) {
365 offline = false;
324 ret = memory_block_change_state(mem, MEM_ONLINE, 366 ret = memory_block_change_state(mem, MEM_ONLINE,
325 MEM_OFFLINE, ONLINE_KEEP); 367 MEM_OFFLINE, ONLINE_KEEP);
326 else if(!strncmp(buf, "offline", min_t(int, count, 7))) 368 } else if(!strncmp(buf, "offline", min_t(int, count, 7))) {
369 offline = true;
327 ret = memory_block_change_state(mem, MEM_OFFLINE, 370 ret = memory_block_change_state(mem, MEM_OFFLINE,
328 MEM_ONLINE, -1); 371 MEM_ONLINE, -1);
372 }
373 if (!ret)
374 dev->offline = offline;
375
376 unlock_device_hotplug();
329 377
330 if (ret) 378 if (ret)
331 return ret; 379 return ret;
@@ -523,6 +571,7 @@ int register_memory(struct memory_block *memory)
523 memory->dev.id = memory->start_section_nr / sections_per_block; 571 memory->dev.id = memory->start_section_nr / sections_per_block;
524 memory->dev.release = memory_block_release; 572 memory->dev.release = memory_block_release;
525 memory->dev.groups = memory_memblk_attr_groups; 573 memory->dev.groups = memory_memblk_attr_groups;
574 memory->dev.offline = memory->state == MEM_OFFLINE;
526 575
527 error = device_register(&memory->dev); 576 error = device_register(&memory->dev);
528 return error; 577 return error;
@@ -646,21 +695,6 @@ int unregister_memory_section(struct mem_section *section)
646} 695}
647#endif /* CONFIG_MEMORY_HOTREMOVE */ 696#endif /* CONFIG_MEMORY_HOTREMOVE */
648 697
649/*
650 * offline one memory block. If the memory block has been offlined, do nothing.
651 */
652int offline_memory_block(struct memory_block *mem)
653{
654 int ret = 0;
655
656 mutex_lock(&mem->state_mutex);
657 if (mem->state != MEM_OFFLINE)
658 ret = __memory_block_change_state(mem, MEM_OFFLINE, MEM_ONLINE, -1);
659 mutex_unlock(&mem->state_mutex);
660
661 return ret;
662}
663
664/* return true if the memory block is offlined, otherwise, return false */ 698/* return true if the memory block is offlined, otherwise, return false */
665bool is_memblock_offlined(struct memory_block *mem) 699bool is_memblock_offlined(struct memory_block *mem)
666{ 700{
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index ed75cf6ef9c9..6eaa7ab9e4bc 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -890,7 +890,6 @@ int platform_pm_restore(struct device *dev)
890static const struct dev_pm_ops platform_dev_pm_ops = { 890static const struct dev_pm_ops platform_dev_pm_ops = {
891 .runtime_suspend = pm_generic_runtime_suspend, 891 .runtime_suspend = pm_generic_runtime_suspend,
892 .runtime_resume = pm_generic_runtime_resume, 892 .runtime_resume = pm_generic_runtime_resume,
893 .runtime_idle = pm_generic_runtime_idle,
894 USE_PLATFORM_PM_SLEEP_OPS 893 USE_PLATFORM_PM_SLEEP_OPS
895}; 894};
896 895
diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
index 7072404c8b6d..bfb8955c406c 100644
--- a/drivers/base/power/domain.c
+++ b/drivers/base/power/domain.c
@@ -2143,7 +2143,6 @@ void pm_genpd_init(struct generic_pm_domain *genpd,
2143 genpd->max_off_time_changed = true; 2143 genpd->max_off_time_changed = true;
2144 genpd->domain.ops.runtime_suspend = pm_genpd_runtime_suspend; 2144 genpd->domain.ops.runtime_suspend = pm_genpd_runtime_suspend;
2145 genpd->domain.ops.runtime_resume = pm_genpd_runtime_resume; 2145 genpd->domain.ops.runtime_resume = pm_genpd_runtime_resume;
2146 genpd->domain.ops.runtime_idle = pm_generic_runtime_idle;
2147 genpd->domain.ops.prepare = pm_genpd_prepare; 2146 genpd->domain.ops.prepare = pm_genpd_prepare;
2148 genpd->domain.ops.suspend = pm_genpd_suspend; 2147 genpd->domain.ops.suspend = pm_genpd_suspend;
2149 genpd->domain.ops.suspend_late = pm_genpd_suspend_late; 2148 genpd->domain.ops.suspend_late = pm_genpd_suspend_late;
diff --git a/drivers/base/power/generic_ops.c b/drivers/base/power/generic_ops.c
index bfd898b8988e..5ee030a864f9 100644
--- a/drivers/base/power/generic_ops.c
+++ b/drivers/base/power/generic_ops.c
@@ -12,29 +12,6 @@
12 12
13#ifdef CONFIG_PM_RUNTIME 13#ifdef CONFIG_PM_RUNTIME
14/** 14/**
15 * pm_generic_runtime_idle - Generic runtime idle callback for subsystems.
16 * @dev: Device to handle.
17 *
18 * If PM operations are defined for the @dev's driver and they include
19 * ->runtime_idle(), execute it and return its error code, if nonzero.
20 * Otherwise, execute pm_runtime_suspend() for the device and return 0.
21 */
22int pm_generic_runtime_idle(struct device *dev)
23{
24 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
25
26 if (pm && pm->runtime_idle) {
27 int ret = pm->runtime_idle(dev);
28 if (ret)
29 return ret;
30 }
31
32 pm_runtime_suspend(dev);
33 return 0;
34}
35EXPORT_SYMBOL_GPL(pm_generic_runtime_idle);
36
37/**
38 * pm_generic_runtime_suspend - Generic runtime suspend callback for subsystems. 15 * pm_generic_runtime_suspend - Generic runtime suspend callback for subsystems.
39 * @dev: Device to suspend. 16 * @dev: Device to suspend.
40 * 17 *
diff --git a/drivers/base/power/opp.c b/drivers/base/power/opp.c
index f0077cb8e249..c8ec186303db 100644
--- a/drivers/base/power/opp.c
+++ b/drivers/base/power/opp.c
@@ -648,14 +648,14 @@ int opp_init_cpufreq_table(struct device *dev,
648 648
649 list_for_each_entry(opp, &dev_opp->opp_list, node) { 649 list_for_each_entry(opp, &dev_opp->opp_list, node) {
650 if (opp->available) { 650 if (opp->available) {
651 freq_table[i].index = i; 651 freq_table[i].driver_data = i;
652 freq_table[i].frequency = opp->rate / 1000; 652 freq_table[i].frequency = opp->rate / 1000;
653 i++; 653 i++;
654 } 654 }
655 } 655 }
656 mutex_unlock(&dev_opp_list_lock); 656 mutex_unlock(&dev_opp_list_lock);
657 657
658 freq_table[i].index = i; 658 freq_table[i].driver_data = i;
659 freq_table[i].frequency = CPUFREQ_TABLE_END; 659 freq_table[i].frequency = CPUFREQ_TABLE_END;
660 660
661 *table = &freq_table[0]; 661 *table = &freq_table[0];
diff --git a/drivers/base/power/qos.c b/drivers/base/power/qos.c
index 71671c42ef45..5c1361a9e5dd 100644
--- a/drivers/base/power/qos.c
+++ b/drivers/base/power/qos.c
@@ -42,6 +42,7 @@
42#include <linux/export.h> 42#include <linux/export.h>
43#include <linux/pm_runtime.h> 43#include <linux/pm_runtime.h>
44#include <linux/err.h> 44#include <linux/err.h>
45#include <trace/events/power.h>
45 46
46#include "power.h" 47#include "power.h"
47 48
@@ -305,6 +306,7 @@ int dev_pm_qos_add_request(struct device *dev, struct dev_pm_qos_request *req,
305 else if (!dev->power.qos) 306 else if (!dev->power.qos)
306 ret = dev_pm_qos_constraints_allocate(dev); 307 ret = dev_pm_qos_constraints_allocate(dev);
307 308
309 trace_dev_pm_qos_add_request(dev_name(dev), type, value);
308 if (!ret) { 310 if (!ret) {
309 req->dev = dev; 311 req->dev = dev;
310 req->type = type; 312 req->type = type;
@@ -349,6 +351,8 @@ static int __dev_pm_qos_update_request(struct dev_pm_qos_request *req,
349 return -EINVAL; 351 return -EINVAL;
350 } 352 }
351 353
354 trace_dev_pm_qos_update_request(dev_name(req->dev), req->type,
355 new_value);
352 if (curr_value != new_value) 356 if (curr_value != new_value)
353 ret = apply_constraint(req, PM_QOS_UPDATE_REQ, new_value); 357 ret = apply_constraint(req, PM_QOS_UPDATE_REQ, new_value);
354 358
@@ -398,6 +402,8 @@ static int __dev_pm_qos_remove_request(struct dev_pm_qos_request *req)
398 if (IS_ERR_OR_NULL(req->dev->power.qos)) 402 if (IS_ERR_OR_NULL(req->dev->power.qos))
399 return -ENODEV; 403 return -ENODEV;
400 404
405 trace_dev_pm_qos_remove_request(dev_name(req->dev), req->type,
406 PM_QOS_DEFAULT_VALUE);
401 ret = apply_constraint(req, PM_QOS_REMOVE_REQ, PM_QOS_DEFAULT_VALUE); 407 ret = apply_constraint(req, PM_QOS_REMOVE_REQ, PM_QOS_DEFAULT_VALUE);
402 memset(req, 0, sizeof(*req)); 408 memset(req, 0, sizeof(*req));
403 return ret; 409 return ret;
diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
index ef13ad08afb2..268a35097578 100644
--- a/drivers/base/power/runtime.c
+++ b/drivers/base/power/runtime.c
@@ -293,11 +293,8 @@ static int rpm_idle(struct device *dev, int rpmflags)
293 /* Pending requests need to be canceled. */ 293 /* Pending requests need to be canceled. */
294 dev->power.request = RPM_REQ_NONE; 294 dev->power.request = RPM_REQ_NONE;
295 295
296 if (dev->power.no_callbacks) { 296 if (dev->power.no_callbacks)
297 /* Assume ->runtime_idle() callback would have suspended. */
298 retval = rpm_suspend(dev, rpmflags);
299 goto out; 297 goto out;
300 }
301 298
302 /* Carry out an asynchronous or a synchronous idle notification. */ 299 /* Carry out an asynchronous or a synchronous idle notification. */
303 if (rpmflags & RPM_ASYNC) { 300 if (rpmflags & RPM_ASYNC) {
@@ -306,7 +303,8 @@ static int rpm_idle(struct device *dev, int rpmflags)
306 dev->power.request_pending = true; 303 dev->power.request_pending = true;
307 queue_work(pm_wq, &dev->power.work); 304 queue_work(pm_wq, &dev->power.work);
308 } 305 }
309 goto out; 306 trace_rpm_return_int(dev, _THIS_IP_, 0);
307 return 0;
310 } 308 }
311 309
312 dev->power.idle_notification = true; 310 dev->power.idle_notification = true;
@@ -326,14 +324,14 @@ static int rpm_idle(struct device *dev, int rpmflags)
326 callback = dev->driver->pm->runtime_idle; 324 callback = dev->driver->pm->runtime_idle;
327 325
328 if (callback) 326 if (callback)
329 __rpm_callback(callback, dev); 327 retval = __rpm_callback(callback, dev);
330 328
331 dev->power.idle_notification = false; 329 dev->power.idle_notification = false;
332 wake_up_all(&dev->power.wait_queue); 330 wake_up_all(&dev->power.wait_queue);
333 331
334 out: 332 out:
335 trace_rpm_return_int(dev, _THIS_IP_, retval); 333 trace_rpm_return_int(dev, _THIS_IP_, retval);
336 return retval; 334 return retval ? retval : rpm_suspend(dev, rpmflags);
337} 335}
338 336
339/** 337/**
diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
index 79715e7fa43e..2d56f4113ae7 100644
--- a/drivers/base/power/wakeup.c
+++ b/drivers/base/power/wakeup.c
@@ -659,7 +659,7 @@ void pm_wakeup_event(struct device *dev, unsigned int msec)
659} 659}
660EXPORT_SYMBOL_GPL(pm_wakeup_event); 660EXPORT_SYMBOL_GPL(pm_wakeup_event);
661 661
662static void print_active_wakeup_sources(void) 662void pm_print_active_wakeup_sources(void)
663{ 663{
664 struct wakeup_source *ws; 664 struct wakeup_source *ws;
665 int active = 0; 665 int active = 0;
@@ -683,6 +683,7 @@ static void print_active_wakeup_sources(void)
683 last_activity_ws->name); 683 last_activity_ws->name);
684 rcu_read_unlock(); 684 rcu_read_unlock();
685} 685}
686EXPORT_SYMBOL_GPL(pm_print_active_wakeup_sources);
686 687
687/** 688/**
688 * pm_wakeup_pending - Check if power transition in progress should be aborted. 689 * pm_wakeup_pending - Check if power transition in progress should be aborted.
@@ -707,8 +708,10 @@ bool pm_wakeup_pending(void)
707 } 708 }
708 spin_unlock_irqrestore(&events_lock, flags); 709 spin_unlock_irqrestore(&events_lock, flags);
709 710
710 if (ret) 711 if (ret) {
711 print_active_wakeup_sources(); 712 pr_info("PM: Wakeup pending, aborting suspend\n");
713 pm_print_active_wakeup_sources();
714 }
712 715
713 return ret; 716 return ret;
714} 717}
diff --git a/drivers/clk/x86/clk-lpt.c b/drivers/clk/x86/clk-lpt.c
index 4f45eee9e33b..812f83f8b0c6 100644
--- a/drivers/clk/x86/clk-lpt.c
+++ b/drivers/clk/x86/clk-lpt.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Intel Lynxpoint LPSS clocks. 2 * Intel Low Power Subsystem clocks.
3 * 3 *
4 * Copyright (C) 2013, Intel Corporation 4 * Copyright (C) 2013, Intel Corporation
5 * Authors: Mika Westerberg <mika.westerberg@linux.intel.com> 5 * Authors: Mika Westerberg <mika.westerberg@linux.intel.com>
@@ -18,8 +18,6 @@
18#include <linux/platform_data/clk-lpss.h> 18#include <linux/platform_data/clk-lpss.h>
19#include <linux/platform_device.h> 19#include <linux/platform_device.h>
20 20
21#define PRV_CLOCK_PARAMS 0x800
22
23static int lpt_clk_probe(struct platform_device *pdev) 21static int lpt_clk_probe(struct platform_device *pdev)
24{ 22{
25 struct lpss_clk_data *drvdata; 23 struct lpss_clk_data *drvdata;
diff --git a/drivers/cpufreq/Kconfig.arm b/drivers/cpufreq/Kconfig.arm
index a92440896868..de4d5d93c3fd 100644
--- a/drivers/cpufreq/Kconfig.arm
+++ b/drivers/cpufreq/Kconfig.arm
@@ -5,6 +5,7 @@
5config ARM_BIG_LITTLE_CPUFREQ 5config ARM_BIG_LITTLE_CPUFREQ
6 tristate "Generic ARM big LITTLE CPUfreq driver" 6 tristate "Generic ARM big LITTLE CPUfreq driver"
7 depends on ARM_CPU_TOPOLOGY && PM_OPP && HAVE_CLK 7 depends on ARM_CPU_TOPOLOGY && PM_OPP && HAVE_CLK
8 select CPU_FREQ_TABLE
8 help 9 help
9 This enables the Generic CPUfreq driver for ARM big.LITTLE platforms. 10 This enables the Generic CPUfreq driver for ARM big.LITTLE platforms.
10 11
@@ -18,6 +19,7 @@ config ARM_DT_BL_CPUFREQ
18config ARM_EXYNOS_CPUFREQ 19config ARM_EXYNOS_CPUFREQ
19 bool "SAMSUNG EXYNOS SoCs" 20 bool "SAMSUNG EXYNOS SoCs"
20 depends on ARCH_EXYNOS 21 depends on ARCH_EXYNOS
22 select CPU_FREQ_TABLE
21 default y 23 default y
22 help 24 help
23 This adds the CPUFreq driver common part for Samsung 25 This adds the CPUFreq driver common part for Samsung
@@ -46,6 +48,7 @@ config ARM_EXYNOS5250_CPUFREQ
46config ARM_EXYNOS5440_CPUFREQ 48config ARM_EXYNOS5440_CPUFREQ
47 def_bool SOC_EXYNOS5440 49 def_bool SOC_EXYNOS5440
48 depends on HAVE_CLK && PM_OPP && OF 50 depends on HAVE_CLK && PM_OPP && OF
51 select CPU_FREQ_TABLE
49 help 52 help
50 This adds the CPUFreq driver for Samsung EXYNOS5440 53 This adds the CPUFreq driver for Samsung EXYNOS5440
51 SoC. The nature of exynos5440 clock controller is 54 SoC. The nature of exynos5440 clock controller is
@@ -55,7 +58,6 @@ config ARM_EXYNOS5440_CPUFREQ
55config ARM_HIGHBANK_CPUFREQ 58config ARM_HIGHBANK_CPUFREQ
56 tristate "Calxeda Highbank-based" 59 tristate "Calxeda Highbank-based"
57 depends on ARCH_HIGHBANK 60 depends on ARCH_HIGHBANK
58 select CPU_FREQ_TABLE
59 select GENERIC_CPUFREQ_CPU0 61 select GENERIC_CPUFREQ_CPU0
60 select PM_OPP 62 select PM_OPP
61 select REGULATOR 63 select REGULATOR
@@ -71,6 +73,7 @@ config ARM_IMX6Q_CPUFREQ
71 tristate "Freescale i.MX6Q cpufreq support" 73 tristate "Freescale i.MX6Q cpufreq support"
72 depends on SOC_IMX6Q 74 depends on SOC_IMX6Q
73 depends on REGULATOR_ANATOP 75 depends on REGULATOR_ANATOP
76 select CPU_FREQ_TABLE
74 help 77 help
75 This adds cpufreq driver support for Freescale i.MX6Q SOC. 78 This adds cpufreq driver support for Freescale i.MX6Q SOC.
76 79
@@ -86,6 +89,7 @@ config ARM_INTEGRATOR
86 89
87config ARM_KIRKWOOD_CPUFREQ 90config ARM_KIRKWOOD_CPUFREQ
88 def_bool ARCH_KIRKWOOD && OF 91 def_bool ARCH_KIRKWOOD && OF
92 select CPU_FREQ_TABLE
89 help 93 help
90 This adds the CPUFreq driver for Marvell Kirkwood 94 This adds the CPUFreq driver for Marvell Kirkwood
91 SoCs. 95 SoCs.
@@ -149,6 +153,7 @@ config ARM_S3C2412_CPUFREQ
149config ARM_S3C2416_CPUFREQ 153config ARM_S3C2416_CPUFREQ
150 bool "S3C2416 CPU Frequency scaling support" 154 bool "S3C2416 CPU Frequency scaling support"
151 depends on CPU_S3C2416 155 depends on CPU_S3C2416
156 select CPU_FREQ_TABLE
152 help 157 help
153 This adds the CPUFreq driver for the Samsung S3C2416 and 158 This adds the CPUFreq driver for the Samsung S3C2416 and
154 S3C2450 SoC. The S3C2416 supports changing the rate of the 159 S3C2450 SoC. The S3C2416 supports changing the rate of the
@@ -179,6 +184,7 @@ config ARM_S3C2440_CPUFREQ
179config ARM_S3C64XX_CPUFREQ 184config ARM_S3C64XX_CPUFREQ
180 bool "Samsung S3C64XX" 185 bool "Samsung S3C64XX"
181 depends on CPU_S3C6410 186 depends on CPU_S3C6410
187 select CPU_FREQ_TABLE
182 default y 188 default y
183 help 189 help
184 This adds the CPUFreq driver for Samsung S3C6410 SoC. 190 This adds the CPUFreq driver for Samsung S3C6410 SoC.
@@ -205,6 +211,15 @@ config ARM_SA1110_CPUFREQ
205config ARM_SPEAR_CPUFREQ 211config ARM_SPEAR_CPUFREQ
206 bool "SPEAr CPUFreq support" 212 bool "SPEAr CPUFreq support"
207 depends on PLAT_SPEAR 213 depends on PLAT_SPEAR
214 select CPU_FREQ_TABLE
208 default y 215 default y
209 help 216 help
210 This adds the CPUFreq driver support for SPEAr SOCs. 217 This adds the CPUFreq driver support for SPEAr SOCs.
218
219config ARM_TEGRA_CPUFREQ
220 bool "TEGRA CPUFreq support"
221 depends on ARCH_TEGRA
222 select CPU_FREQ_TABLE
223 default y
224 help
225 This adds the CPUFreq driver support for TEGRA SOCs.
diff --git a/drivers/cpufreq/Kconfig.powerpc b/drivers/cpufreq/Kconfig.powerpc
index 9c926ca0d718..25ca9db62e09 100644
--- a/drivers/cpufreq/Kconfig.powerpc
+++ b/drivers/cpufreq/Kconfig.powerpc
@@ -1,6 +1,7 @@
1config CPU_FREQ_CBE 1config CPU_FREQ_CBE
2 tristate "CBE frequency scaling" 2 tristate "CBE frequency scaling"
3 depends on CBE_RAS && PPC_CELL 3 depends on CBE_RAS && PPC_CELL
4 select CPU_FREQ_TABLE
4 default m 5 default m
5 help 6 help
6 This adds the cpufreq driver for Cell BE processors. 7 This adds the cpufreq driver for Cell BE processors.
@@ -23,3 +24,39 @@ config CPU_FREQ_MAPLE
23 help 24 help
24 This adds support for frequency switching on Maple 970FX 25 This adds support for frequency switching on Maple 970FX
25 Evaluation Board and compatible boards (IBM JS2x blades). 26 Evaluation Board and compatible boards (IBM JS2x blades).
27
28config PPC_CORENET_CPUFREQ
29 tristate "CPU frequency scaling driver for Freescale E500MC SoCs"
30 depends on PPC_E500MC && OF && COMMON_CLK
31 select CPU_FREQ_TABLE
32 select CLK_PPC_CORENET
33 help
34 This adds the CPUFreq driver support for Freescale e500mc,
35 e5500 and e6500 series SoCs which are capable of changing
36 the CPU's frequency dynamically.
37
38config CPU_FREQ_PMAC
39 bool "Support for Apple PowerBooks"
40 depends on ADB_PMU && PPC32
41 select CPU_FREQ_TABLE
42 help
43 This adds support for frequency switching on Apple PowerBooks,
44 this currently includes some models of iBook & Titanium
45 PowerBook.
46
47config CPU_FREQ_PMAC64
48 bool "Support for some Apple G5s"
49 depends on PPC_PMAC && PPC64
50 select CPU_FREQ_TABLE
51 help
52 This adds support for frequency switching on Apple iMac G5,
53 and some of the more recent desktop G5 machines as well.
54
55config PPC_PASEMI_CPUFREQ
56 bool "Support for PA Semi PWRficient"
57 depends on PPC_PASEMI
58 select CPU_FREQ_TABLE
59 default y
60 help
61 This adds the support for frequency switching on PA Semi
62 PWRficient processors.
diff --git a/drivers/cpufreq/Kconfig.x86 b/drivers/cpufreq/Kconfig.x86
index 6bd63d63d356..e2b6eabef221 100644
--- a/drivers/cpufreq/Kconfig.x86
+++ b/drivers/cpufreq/Kconfig.x86
@@ -132,6 +132,7 @@ config X86_POWERNOW_K8
132config X86_AMD_FREQ_SENSITIVITY 132config X86_AMD_FREQ_SENSITIVITY
133 tristate "AMD frequency sensitivity feedback powersave bias" 133 tristate "AMD frequency sensitivity feedback powersave bias"
134 depends on CPU_FREQ_GOV_ONDEMAND && X86_ACPI_CPUFREQ && CPU_SUP_AMD 134 depends on CPU_FREQ_GOV_ONDEMAND && X86_ACPI_CPUFREQ && CPU_SUP_AMD
135 select CPU_FREQ_TABLE
135 help 136 help
136 This adds AMD-specific powersave bias function to the ondemand 137 This adds AMD-specific powersave bias function to the ondemand
137 governor, which allows it to make more power-conscious frequency 138 governor, which allows it to make more power-conscious frequency
diff --git a/drivers/cpufreq/Makefile b/drivers/cpufreq/Makefile
index 6ad0b913ca17..d345b5a7aa71 100644
--- a/drivers/cpufreq/Makefile
+++ b/drivers/cpufreq/Makefile
@@ -76,7 +76,7 @@ obj-$(CONFIG_ARM_S5PV210_CPUFREQ) += s5pv210-cpufreq.o
76obj-$(CONFIG_ARM_SA1100_CPUFREQ) += sa1100-cpufreq.o 76obj-$(CONFIG_ARM_SA1100_CPUFREQ) += sa1100-cpufreq.o
77obj-$(CONFIG_ARM_SA1110_CPUFREQ) += sa1110-cpufreq.o 77obj-$(CONFIG_ARM_SA1110_CPUFREQ) += sa1110-cpufreq.o
78obj-$(CONFIG_ARM_SPEAR_CPUFREQ) += spear-cpufreq.o 78obj-$(CONFIG_ARM_SPEAR_CPUFREQ) += spear-cpufreq.o
79obj-$(CONFIG_ARCH_TEGRA) += tegra-cpufreq.o 79obj-$(CONFIG_ARM_TEGRA_CPUFREQ) += tegra-cpufreq.o
80 80
81################################################################################## 81##################################################################################
82# PowerPC platform drivers 82# PowerPC platform drivers
@@ -84,11 +84,15 @@ obj-$(CONFIG_CPU_FREQ_CBE) += ppc-cbe-cpufreq.o
84ppc-cbe-cpufreq-y += ppc_cbe_cpufreq_pervasive.o ppc_cbe_cpufreq.o 84ppc-cbe-cpufreq-y += ppc_cbe_cpufreq_pervasive.o ppc_cbe_cpufreq.o
85obj-$(CONFIG_CPU_FREQ_CBE_PMI) += ppc_cbe_cpufreq_pmi.o 85obj-$(CONFIG_CPU_FREQ_CBE_PMI) += ppc_cbe_cpufreq_pmi.o
86obj-$(CONFIG_CPU_FREQ_MAPLE) += maple-cpufreq.o 86obj-$(CONFIG_CPU_FREQ_MAPLE) += maple-cpufreq.o
87obj-$(CONFIG_PPC_CORENET_CPUFREQ) += ppc-corenet-cpufreq.o
88obj-$(CONFIG_CPU_FREQ_PMAC) += pmac32-cpufreq.o
89obj-$(CONFIG_CPU_FREQ_PMAC64) += pmac64-cpufreq.o
90obj-$(CONFIG_PPC_PASEMI_CPUFREQ) += pasemi-cpufreq.o
87 91
88################################################################################## 92##################################################################################
89# Other platform drivers 93# Other platform drivers
90obj-$(CONFIG_AVR32_AT32AP_CPUFREQ) += at32ap-cpufreq.o 94obj-$(CONFIG_AVR32_AT32AP_CPUFREQ) += at32ap-cpufreq.o
91obj-$(CONFIG_BLACKFIN) += blackfin-cpufreq.o 95obj-$(CONFIG_BFIN_CPU_FREQ) += blackfin-cpufreq.o
92obj-$(CONFIG_CRIS_MACH_ARTPEC3) += cris-artpec3-cpufreq.o 96obj-$(CONFIG_CRIS_MACH_ARTPEC3) += cris-artpec3-cpufreq.o
93obj-$(CONFIG_ETRAXFS) += cris-etraxfs-cpufreq.o 97obj-$(CONFIG_ETRAXFS) += cris-etraxfs-cpufreq.o
94obj-$(CONFIG_IA64_ACPI_CPUFREQ) += ia64-acpi-cpufreq.o 98obj-$(CONFIG_IA64_ACPI_CPUFREQ) += ia64-acpi-cpufreq.o
diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
index edc089e9d0c4..39264020b88a 100644
--- a/drivers/cpufreq/acpi-cpufreq.c
+++ b/drivers/cpufreq/acpi-cpufreq.c
@@ -70,6 +70,7 @@ struct acpi_cpufreq_data {
70 struct cpufreq_frequency_table *freq_table; 70 struct cpufreq_frequency_table *freq_table;
71 unsigned int resume; 71 unsigned int resume;
72 unsigned int cpu_feature; 72 unsigned int cpu_feature;
73 cpumask_var_t freqdomain_cpus;
73}; 74};
74 75
75static DEFINE_PER_CPU(struct acpi_cpufreq_data *, acfreq_data); 76static DEFINE_PER_CPU(struct acpi_cpufreq_data *, acfreq_data);
@@ -176,6 +177,15 @@ static struct global_attr global_boost = __ATTR(boost, 0644,
176 show_global_boost, 177 show_global_boost,
177 store_global_boost); 178 store_global_boost);
178 179
180static ssize_t show_freqdomain_cpus(struct cpufreq_policy *policy, char *buf)
181{
182 struct acpi_cpufreq_data *data = per_cpu(acfreq_data, policy->cpu);
183
184 return cpufreq_show_cpus(data->freqdomain_cpus, buf);
185}
186
187cpufreq_freq_attr_ro(freqdomain_cpus);
188
179#ifdef CONFIG_X86_ACPI_CPUFREQ_CPB 189#ifdef CONFIG_X86_ACPI_CPUFREQ_CPB
180static ssize_t store_cpb(struct cpufreq_policy *policy, const char *buf, 190static ssize_t store_cpb(struct cpufreq_policy *policy, const char *buf,
181 size_t count) 191 size_t count)
@@ -232,7 +242,7 @@ static unsigned extract_msr(u32 msr, struct acpi_cpufreq_data *data)
232 perf = data->acpi_data; 242 perf = data->acpi_data;
233 243
234 for (i = 0; data->freq_table[i].frequency != CPUFREQ_TABLE_END; i++) { 244 for (i = 0; data->freq_table[i].frequency != CPUFREQ_TABLE_END; i++) {
235 if (msr == perf->states[data->freq_table[i].index].status) 245 if (msr == perf->states[data->freq_table[i].driver_data].status)
236 return data->freq_table[i].frequency; 246 return data->freq_table[i].frequency;
237 } 247 }
238 return data->freq_table[0].frequency; 248 return data->freq_table[0].frequency;
@@ -442,7 +452,7 @@ static int acpi_cpufreq_target(struct cpufreq_policy *policy,
442 goto out; 452 goto out;
443 } 453 }
444 454
445 next_perf_state = data->freq_table[next_state].index; 455 next_perf_state = data->freq_table[next_state].driver_data;
446 if (perf->state == next_perf_state) { 456 if (perf->state == next_perf_state) {
447 if (unlikely(data->resume)) { 457 if (unlikely(data->resume)) {
448 pr_debug("Called after resume, resetting to P%d\n", 458 pr_debug("Called after resume, resetting to P%d\n",
@@ -494,12 +504,14 @@ static int acpi_cpufreq_target(struct cpufreq_policy *policy,
494 pr_debug("acpi_cpufreq_target failed (%d)\n", 504 pr_debug("acpi_cpufreq_target failed (%d)\n",
495 policy->cpu); 505 policy->cpu);
496 result = -EAGAIN; 506 result = -EAGAIN;
497 goto out; 507 freqs.new = freqs.old;
498 } 508 }
499 } 509 }
500 510
501 cpufreq_notify_transition(policy, &freqs, CPUFREQ_POSTCHANGE); 511 cpufreq_notify_transition(policy, &freqs, CPUFREQ_POSTCHANGE);
502 perf->state = next_perf_state; 512
513 if (!result)
514 perf->state = next_perf_state;
503 515
504out: 516out:
505 return result; 517 return result;
@@ -702,6 +714,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
702 if (!data) 714 if (!data)
703 return -ENOMEM; 715 return -ENOMEM;
704 716
717 if (!zalloc_cpumask_var(&data->freqdomain_cpus, GFP_KERNEL)) {
718 result = -ENOMEM;
719 goto err_free;
720 }
721
705 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu); 722 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
706 per_cpu(acfreq_data, cpu) = data; 723 per_cpu(acfreq_data, cpu) = data;
707 724
@@ -710,7 +727,7 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
710 727
711 result = acpi_processor_register_performance(data->acpi_data, cpu); 728 result = acpi_processor_register_performance(data->acpi_data, cpu);
712 if (result) 729 if (result)
713 goto err_free; 730 goto err_free_mask;
714 731
715 perf = data->acpi_data; 732 perf = data->acpi_data;
716 policy->shared_type = perf->shared_type; 733 policy->shared_type = perf->shared_type;
@@ -723,6 +740,7 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
723 policy->shared_type == CPUFREQ_SHARED_TYPE_ANY) { 740 policy->shared_type == CPUFREQ_SHARED_TYPE_ANY) {
724 cpumask_copy(policy->cpus, perf->shared_cpu_map); 741 cpumask_copy(policy->cpus, perf->shared_cpu_map);
725 } 742 }
743 cpumask_copy(data->freqdomain_cpus, perf->shared_cpu_map);
726 744
727#ifdef CONFIG_SMP 745#ifdef CONFIG_SMP
728 dmi_check_system(sw_any_bug_dmi_table); 746 dmi_check_system(sw_any_bug_dmi_table);
@@ -734,6 +752,7 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
734 if (check_amd_hwpstate_cpu(cpu) && !acpi_pstate_strict) { 752 if (check_amd_hwpstate_cpu(cpu) && !acpi_pstate_strict) {
735 cpumask_clear(policy->cpus); 753 cpumask_clear(policy->cpus);
736 cpumask_set_cpu(cpu, policy->cpus); 754 cpumask_set_cpu(cpu, policy->cpus);
755 cpumask_copy(data->freqdomain_cpus, cpu_sibling_mask(cpu));
737 policy->shared_type = CPUFREQ_SHARED_TYPE_HW; 756 policy->shared_type = CPUFREQ_SHARED_TYPE_HW;
738 pr_info_once(PFX "overriding BIOS provided _PSD data\n"); 757 pr_info_once(PFX "overriding BIOS provided _PSD data\n");
739 } 758 }
@@ -811,7 +830,7 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
811 data->freq_table[valid_states-1].frequency / 1000) 830 data->freq_table[valid_states-1].frequency / 1000)
812 continue; 831 continue;
813 832
814 data->freq_table[valid_states].index = i; 833 data->freq_table[valid_states].driver_data = i;
815 data->freq_table[valid_states].frequency = 834 data->freq_table[valid_states].frequency =
816 perf->states[i].core_frequency * 1000; 835 perf->states[i].core_frequency * 1000;
817 valid_states++; 836 valid_states++;
@@ -868,6 +887,8 @@ err_freqfree:
868 kfree(data->freq_table); 887 kfree(data->freq_table);
869err_unreg: 888err_unreg:
870 acpi_processor_unregister_performance(perf, cpu); 889 acpi_processor_unregister_performance(perf, cpu);
890err_free_mask:
891 free_cpumask_var(data->freqdomain_cpus);
871err_free: 892err_free:
872 kfree(data); 893 kfree(data);
873 per_cpu(acfreq_data, cpu) = NULL; 894 per_cpu(acfreq_data, cpu) = NULL;
@@ -886,6 +907,7 @@ static int acpi_cpufreq_cpu_exit(struct cpufreq_policy *policy)
886 per_cpu(acfreq_data, policy->cpu) = NULL; 907 per_cpu(acfreq_data, policy->cpu) = NULL;
887 acpi_processor_unregister_performance(data->acpi_data, 908 acpi_processor_unregister_performance(data->acpi_data,
888 policy->cpu); 909 policy->cpu);
910 free_cpumask_var(data->freqdomain_cpus);
889 kfree(data->freq_table); 911 kfree(data->freq_table);
890 kfree(data); 912 kfree(data);
891 } 913 }
@@ -906,6 +928,7 @@ static int acpi_cpufreq_resume(struct cpufreq_policy *policy)
906 928
907static struct freq_attr *acpi_cpufreq_attr[] = { 929static struct freq_attr *acpi_cpufreq_attr[] = {
908 &cpufreq_freq_attr_scaling_available_freqs, 930 &cpufreq_freq_attr_scaling_available_freqs,
931 &freqdomain_cpus,
909 NULL, /* this is a placeholder for cpb, do not remove */ 932 NULL, /* this is a placeholder for cpb, do not remove */
910 NULL, 933 NULL,
911}; 934};
@@ -947,7 +970,7 @@ static void __init acpi_cpufreq_boost_init(void)
947 /* We create the boost file in any case, though for systems without 970 /* We create the boost file in any case, though for systems without
948 * hardware support it will be read-only and hardwired to return 0. 971 * hardware support it will be read-only and hardwired to return 0.
949 */ 972 */
950 if (sysfs_create_file(cpufreq_global_kobject, &(global_boost.attr))) 973 if (cpufreq_sysfs_create_file(&(global_boost.attr)))
951 pr_warn(PFX "could not register global boost sysfs file\n"); 974 pr_warn(PFX "could not register global boost sysfs file\n");
952 else 975 else
953 pr_debug("registered global boost sysfs file\n"); 976 pr_debug("registered global boost sysfs file\n");
@@ -955,7 +978,7 @@ static void __init acpi_cpufreq_boost_init(void)
955 978
956static void __exit acpi_cpufreq_boost_exit(void) 979static void __exit acpi_cpufreq_boost_exit(void)
957{ 980{
958 sysfs_remove_file(cpufreq_global_kobject, &(global_boost.attr)); 981 cpufreq_sysfs_remove_file(&(global_boost.attr));
959 982
960 if (msrs) { 983 if (msrs) {
961 unregister_cpu_notifier(&boost_nb); 984 unregister_cpu_notifier(&boost_nb);
@@ -1034,4 +1057,11 @@ static const struct x86_cpu_id acpi_cpufreq_ids[] = {
1034}; 1057};
1035MODULE_DEVICE_TABLE(x86cpu, acpi_cpufreq_ids); 1058MODULE_DEVICE_TABLE(x86cpu, acpi_cpufreq_ids);
1036 1059
1060static const struct acpi_device_id processor_device_ids[] = {
1061 {ACPI_PROCESSOR_OBJECT_HID, },
1062 {ACPI_PROCESSOR_DEVICE_HID, },
1063 {},
1064};
1065MODULE_DEVICE_TABLE(acpi, processor_device_ids);
1066
1037MODULE_ALIAS("acpi"); 1067MODULE_ALIAS("acpi");
diff --git a/drivers/cpufreq/arm_big_little.c b/drivers/cpufreq/arm_big_little.c
index 5d7f53fcd6f5..3549f0784af1 100644
--- a/drivers/cpufreq/arm_big_little.c
+++ b/drivers/cpufreq/arm_big_little.c
@@ -84,11 +84,9 @@ static int bL_cpufreq_set_target(struct cpufreq_policy *policy,
84 ret = clk_set_rate(clk[cur_cluster], freqs.new * 1000); 84 ret = clk_set_rate(clk[cur_cluster], freqs.new * 1000);
85 if (ret) { 85 if (ret) {
86 pr_err("clk_set_rate failed: %d\n", ret); 86 pr_err("clk_set_rate failed: %d\n", ret);
87 return ret; 87 freqs.new = freqs.old;
88 } 88 }
89 89
90 policy->cur = freqs.new;
91
92 cpufreq_notify_transition(policy, &freqs, CPUFREQ_POSTCHANGE); 90 cpufreq_notify_transition(policy, &freqs, CPUFREQ_POSTCHANGE);
93 91
94 return ret; 92 return ret;
diff --git a/drivers/cpufreq/blackfin-cpufreq.c b/drivers/cpufreq/blackfin-cpufreq.c
index 995511e80bef..9cdbbd278a80 100644
--- a/drivers/cpufreq/blackfin-cpufreq.c
+++ b/drivers/cpufreq/blackfin-cpufreq.c
@@ -20,23 +20,23 @@
20 20
21 21
22/* this is the table of CCLK frequencies, in Hz */ 22/* this is the table of CCLK frequencies, in Hz */
23/* .index is the entry in the auxiliary dpm_state_table[] */ 23/* .driver_data is the entry in the auxiliary dpm_state_table[] */
24static struct cpufreq_frequency_table bfin_freq_table[] = { 24static struct cpufreq_frequency_table bfin_freq_table[] = {
25 { 25 {
26 .frequency = CPUFREQ_TABLE_END, 26 .frequency = CPUFREQ_TABLE_END,
27 .index = 0, 27 .driver_data = 0,
28 }, 28 },
29 { 29 {
30 .frequency = CPUFREQ_TABLE_END, 30 .frequency = CPUFREQ_TABLE_END,
31 .index = 1, 31 .driver_data = 1,
32 }, 32 },
33 { 33 {
34 .frequency = CPUFREQ_TABLE_END, 34 .frequency = CPUFREQ_TABLE_END,
35 .index = 2, 35 .driver_data = 2,
36 }, 36 },
37 { 37 {
38 .frequency = CPUFREQ_TABLE_END, 38 .frequency = CPUFREQ_TABLE_END,
39 .index = 0, 39 .driver_data = 0,
40 }, 40 },
41}; 41};
42 42
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 2d53f47d1747..6a015ada5285 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -3,6 +3,7 @@
3 * 3 *
4 * Copyright (C) 2001 Russell King 4 * Copyright (C) 2001 Russell King
5 * (C) 2002 - 2003 Dominik Brodowski <linux@brodo.de> 5 * (C) 2002 - 2003 Dominik Brodowski <linux@brodo.de>
6 * (C) 2013 Viresh Kumar <viresh.kumar@linaro.org>
6 * 7 *
7 * Oct 2005 - Ashok Raj <ashok.raj@intel.com> 8 * Oct 2005 - Ashok Raj <ashok.raj@intel.com>
8 * Added handling for CPU hotplug 9 * Added handling for CPU hotplug
@@ -12,12 +13,13 @@
12 * This program is free software; you can redistribute it and/or modify 13 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as 14 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation. 15 * published by the Free Software Foundation.
15 *
16 */ 16 */
17 17
18#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 18#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
19 19
20#include <asm/cputime.h>
20#include <linux/kernel.h> 21#include <linux/kernel.h>
22#include <linux/kernel_stat.h>
21#include <linux/module.h> 23#include <linux/module.h>
22#include <linux/init.h> 24#include <linux/init.h>
23#include <linux/notifier.h> 25#include <linux/notifier.h>
@@ -25,6 +27,7 @@
25#include <linux/delay.h> 27#include <linux/delay.h>
26#include <linux/interrupt.h> 28#include <linux/interrupt.h>
27#include <linux/spinlock.h> 29#include <linux/spinlock.h>
30#include <linux/tick.h>
28#include <linux/device.h> 31#include <linux/device.h>
29#include <linux/slab.h> 32#include <linux/slab.h>
30#include <linux/cpu.h> 33#include <linux/cpu.h>
@@ -41,11 +44,13 @@
41 */ 44 */
42static struct cpufreq_driver *cpufreq_driver; 45static struct cpufreq_driver *cpufreq_driver;
43static DEFINE_PER_CPU(struct cpufreq_policy *, cpufreq_cpu_data); 46static DEFINE_PER_CPU(struct cpufreq_policy *, cpufreq_cpu_data);
47static DEFINE_RWLOCK(cpufreq_driver_lock);
48static DEFINE_MUTEX(cpufreq_governor_lock);
49
44#ifdef CONFIG_HOTPLUG_CPU 50#ifdef CONFIG_HOTPLUG_CPU
45/* This one keeps track of the previously set governor of a removed CPU */ 51/* This one keeps track of the previously set governor of a removed CPU */
46static DEFINE_PER_CPU(char[CPUFREQ_NAME_LEN], cpufreq_cpu_governor); 52static DEFINE_PER_CPU(char[CPUFREQ_NAME_LEN], cpufreq_cpu_governor);
47#endif 53#endif
48static DEFINE_RWLOCK(cpufreq_driver_lock);
49 54
50/* 55/*
51 * cpu_policy_rwsem is a per CPU reader-writer semaphore designed to cure 56 * cpu_policy_rwsem is a per CPU reader-writer semaphore designed to cure
@@ -132,6 +137,51 @@ bool have_governor_per_policy(void)
132{ 137{
133 return cpufreq_driver->have_governor_per_policy; 138 return cpufreq_driver->have_governor_per_policy;
134} 139}
140EXPORT_SYMBOL_GPL(have_governor_per_policy);
141
142struct kobject *get_governor_parent_kobj(struct cpufreq_policy *policy)
143{
144 if (have_governor_per_policy())
145 return &policy->kobj;
146 else
147 return cpufreq_global_kobject;
148}
149EXPORT_SYMBOL_GPL(get_governor_parent_kobj);
150
151static inline u64 get_cpu_idle_time_jiffy(unsigned int cpu, u64 *wall)
152{
153 u64 idle_time;
154 u64 cur_wall_time;
155 u64 busy_time;
156
157 cur_wall_time = jiffies64_to_cputime64(get_jiffies_64());
158
159 busy_time = kcpustat_cpu(cpu).cpustat[CPUTIME_USER];
160 busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_SYSTEM];
161 busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_IRQ];
162 busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_SOFTIRQ];
163 busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_STEAL];
164 busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_NICE];
165
166 idle_time = cur_wall_time - busy_time;
167 if (wall)
168 *wall = cputime_to_usecs(cur_wall_time);
169
170 return cputime_to_usecs(idle_time);
171}
172
173u64 get_cpu_idle_time(unsigned int cpu, u64 *wall, int io_busy)
174{
175 u64 idle_time = get_cpu_idle_time_us(cpu, io_busy ? wall : NULL);
176
177 if (idle_time == -1ULL)
178 return get_cpu_idle_time_jiffy(cpu, wall);
179 else if (!io_busy)
180 idle_time += get_cpu_iowait_time_us(cpu, wall);
181
182 return idle_time;
183}
184EXPORT_SYMBOL_GPL(get_cpu_idle_time);
135 185
136static struct cpufreq_policy *__cpufreq_cpu_get(unsigned int cpu, bool sysfs) 186static struct cpufreq_policy *__cpufreq_cpu_get(unsigned int cpu, bool sysfs)
137{ 187{
@@ -150,7 +200,6 @@ static struct cpufreq_policy *__cpufreq_cpu_get(unsigned int cpu, bool sysfs)
150 if (!try_module_get(cpufreq_driver->owner)) 200 if (!try_module_get(cpufreq_driver->owner))
151 goto err_out_unlock; 201 goto err_out_unlock;
152 202
153
154 /* get the CPU */ 203 /* get the CPU */
155 data = per_cpu(cpufreq_cpu_data, cpu); 204 data = per_cpu(cpufreq_cpu_data, cpu);
156 205
@@ -220,7 +269,7 @@ static void cpufreq_cpu_put_sysfs(struct cpufreq_policy *data)
220 */ 269 */
221#ifndef CONFIG_SMP 270#ifndef CONFIG_SMP
222static unsigned long l_p_j_ref; 271static unsigned long l_p_j_ref;
223static unsigned int l_p_j_ref_freq; 272static unsigned int l_p_j_ref_freq;
224 273
225static void adjust_jiffies(unsigned long val, struct cpufreq_freqs *ci) 274static void adjust_jiffies(unsigned long val, struct cpufreq_freqs *ci)
226{ 275{
@@ -233,7 +282,7 @@ static void adjust_jiffies(unsigned long val, struct cpufreq_freqs *ci)
233 pr_debug("saving %lu as reference value for loops_per_jiffy; " 282 pr_debug("saving %lu as reference value for loops_per_jiffy; "
234 "freq is %u kHz\n", l_p_j_ref, l_p_j_ref_freq); 283 "freq is %u kHz\n", l_p_j_ref, l_p_j_ref_freq);
235 } 284 }
236 if ((val == CPUFREQ_POSTCHANGE && ci->old != ci->new) || 285 if ((val == CPUFREQ_POSTCHANGE && ci->old != ci->new) ||
237 (val == CPUFREQ_RESUMECHANGE || val == CPUFREQ_SUSPENDCHANGE)) { 286 (val == CPUFREQ_RESUMECHANGE || val == CPUFREQ_SUSPENDCHANGE)) {
238 loops_per_jiffy = cpufreq_scale(l_p_j_ref, l_p_j_ref_freq, 287 loops_per_jiffy = cpufreq_scale(l_p_j_ref, l_p_j_ref_freq,
239 ci->new); 288 ci->new);
@@ -248,8 +297,7 @@ static inline void adjust_jiffies(unsigned long val, struct cpufreq_freqs *ci)
248} 297}
249#endif 298#endif
250 299
251 300static void __cpufreq_notify_transition(struct cpufreq_policy *policy,
252void __cpufreq_notify_transition(struct cpufreq_policy *policy,
253 struct cpufreq_freqs *freqs, unsigned int state) 301 struct cpufreq_freqs *freqs, unsigned int state)
254{ 302{
255 BUG_ON(irqs_disabled()); 303 BUG_ON(irqs_disabled());
@@ -264,6 +312,12 @@ void __cpufreq_notify_transition(struct cpufreq_policy *policy,
264 switch (state) { 312 switch (state) {
265 313
266 case CPUFREQ_PRECHANGE: 314 case CPUFREQ_PRECHANGE:
315 if (WARN(policy->transition_ongoing,
316 "In middle of another frequency transition\n"))
317 return;
318
319 policy->transition_ongoing = true;
320
267 /* detect if the driver reported a value as "old frequency" 321 /* detect if the driver reported a value as "old frequency"
268 * which is not equal to what the cpufreq core thinks is 322 * which is not equal to what the cpufreq core thinks is
269 * "old frequency". 323 * "old frequency".
@@ -283,6 +337,12 @@ void __cpufreq_notify_transition(struct cpufreq_policy *policy,
283 break; 337 break;
284 338
285 case CPUFREQ_POSTCHANGE: 339 case CPUFREQ_POSTCHANGE:
340 if (WARN(!policy->transition_ongoing,
341 "No frequency transition in progress\n"))
342 return;
343
344 policy->transition_ongoing = false;
345
286 adjust_jiffies(CPUFREQ_POSTCHANGE, freqs); 346 adjust_jiffies(CPUFREQ_POSTCHANGE, freqs);
287 pr_debug("FREQ: %lu - CPU: %lu", (unsigned long)freqs->new, 347 pr_debug("FREQ: %lu - CPU: %lu", (unsigned long)freqs->new,
288 (unsigned long)freqs->cpu); 348 (unsigned long)freqs->cpu);
@@ -294,6 +354,7 @@ void __cpufreq_notify_transition(struct cpufreq_policy *policy,
294 break; 354 break;
295 } 355 }
296} 356}
357
297/** 358/**
298 * cpufreq_notify_transition - call notifier chain and adjust_jiffies 359 * cpufreq_notify_transition - call notifier chain and adjust_jiffies
299 * on frequency transition. 360 * on frequency transition.
@@ -311,7 +372,6 @@ void cpufreq_notify_transition(struct cpufreq_policy *policy,
311EXPORT_SYMBOL_GPL(cpufreq_notify_transition); 372EXPORT_SYMBOL_GPL(cpufreq_notify_transition);
312 373
313 374
314
315/********************************************************************* 375/*********************************************************************
316 * SYSFS INTERFACE * 376 * SYSFS INTERFACE *
317 *********************************************************************/ 377 *********************************************************************/
@@ -376,7 +436,6 @@ out:
376 return err; 436 return err;
377} 437}
378 438
379
380/** 439/**
381 * cpufreq_per_cpu_attr_read() / show_##file_name() - 440 * cpufreq_per_cpu_attr_read() / show_##file_name() -
382 * print out cpufreq information 441 * print out cpufreq information
@@ -441,7 +500,6 @@ static ssize_t show_cpuinfo_cur_freq(struct cpufreq_policy *policy,
441 return sprintf(buf, "%u\n", cur_freq); 500 return sprintf(buf, "%u\n", cur_freq);
442} 501}
443 502
444
445/** 503/**
446 * show_scaling_governor - show the current policy for the specified CPU 504 * show_scaling_governor - show the current policy for the specified CPU
447 */ 505 */
@@ -457,7 +515,6 @@ static ssize_t show_scaling_governor(struct cpufreq_policy *policy, char *buf)
457 return -EINVAL; 515 return -EINVAL;
458} 516}
459 517
460
461/** 518/**
462 * store_scaling_governor - store policy for the specified CPU 519 * store_scaling_governor - store policy for the specified CPU
463 */ 520 */
@@ -480,8 +537,10 @@ static ssize_t store_scaling_governor(struct cpufreq_policy *policy,
480 &new_policy.governor)) 537 &new_policy.governor))
481 return -EINVAL; 538 return -EINVAL;
482 539
483 /* Do not use cpufreq_set_policy here or the user_policy.max 540 /*
484 will be wrongly overridden */ 541 * Do not use cpufreq_set_policy here or the user_policy.max
542 * will be wrongly overridden
543 */
485 ret = __cpufreq_set_policy(policy, &new_policy); 544 ret = __cpufreq_set_policy(policy, &new_policy);
486 545
487 policy->user_policy.policy = policy->policy; 546 policy->user_policy.policy = policy->policy;
@@ -526,7 +585,7 @@ out:
526 return i; 585 return i;
527} 586}
528 587
529static ssize_t show_cpus(const struct cpumask *mask, char *buf) 588ssize_t cpufreq_show_cpus(const struct cpumask *mask, char *buf)
530{ 589{
531 ssize_t i = 0; 590 ssize_t i = 0;
532 unsigned int cpu; 591 unsigned int cpu;
@@ -541,6 +600,7 @@ static ssize_t show_cpus(const struct cpumask *mask, char *buf)
541 i += sprintf(&buf[i], "\n"); 600 i += sprintf(&buf[i], "\n");
542 return i; 601 return i;
543} 602}
603EXPORT_SYMBOL_GPL(cpufreq_show_cpus);
544 604
545/** 605/**
546 * show_related_cpus - show the CPUs affected by each transition even if 606 * show_related_cpus - show the CPUs affected by each transition even if
@@ -548,7 +608,7 @@ static ssize_t show_cpus(const struct cpumask *mask, char *buf)
548 */ 608 */
549static ssize_t show_related_cpus(struct cpufreq_policy *policy, char *buf) 609static ssize_t show_related_cpus(struct cpufreq_policy *policy, char *buf)
550{ 610{
551 return show_cpus(policy->related_cpus, buf); 611 return cpufreq_show_cpus(policy->related_cpus, buf);
552} 612}
553 613
554/** 614/**
@@ -556,7 +616,7 @@ static ssize_t show_related_cpus(struct cpufreq_policy *policy, char *buf)
556 */ 616 */
557static ssize_t show_affected_cpus(struct cpufreq_policy *policy, char *buf) 617static ssize_t show_affected_cpus(struct cpufreq_policy *policy, char *buf)
558{ 618{
559 return show_cpus(policy->cpus, buf); 619 return cpufreq_show_cpus(policy->cpus, buf);
560} 620}
561 621
562static ssize_t store_scaling_setspeed(struct cpufreq_policy *policy, 622static ssize_t store_scaling_setspeed(struct cpufreq_policy *policy,
@@ -630,9 +690,6 @@ static struct attribute *default_attrs[] = {
630 NULL 690 NULL
631}; 691};
632 692
633struct kobject *cpufreq_global_kobject;
634EXPORT_SYMBOL(cpufreq_global_kobject);
635
636#define to_policy(k) container_of(k, struct cpufreq_policy, kobj) 693#define to_policy(k) container_of(k, struct cpufreq_policy, kobj)
637#define to_attr(a) container_of(a, struct freq_attr, attr) 694#define to_attr(a) container_of(a, struct freq_attr, attr)
638 695
@@ -703,6 +760,49 @@ static struct kobj_type ktype_cpufreq = {
703 .release = cpufreq_sysfs_release, 760 .release = cpufreq_sysfs_release,
704}; 761};
705 762
763struct kobject *cpufreq_global_kobject;
764EXPORT_SYMBOL(cpufreq_global_kobject);
765
766static int cpufreq_global_kobject_usage;
767
768int cpufreq_get_global_kobject(void)
769{
770 if (!cpufreq_global_kobject_usage++)
771 return kobject_add(cpufreq_global_kobject,
772 &cpu_subsys.dev_root->kobj, "%s", "cpufreq");
773
774 return 0;
775}
776EXPORT_SYMBOL(cpufreq_get_global_kobject);
777
778void cpufreq_put_global_kobject(void)
779{
780 if (!--cpufreq_global_kobject_usage)
781 kobject_del(cpufreq_global_kobject);
782}
783EXPORT_SYMBOL(cpufreq_put_global_kobject);
784
785int cpufreq_sysfs_create_file(const struct attribute *attr)
786{
787 int ret = cpufreq_get_global_kobject();
788
789 if (!ret) {
790 ret = sysfs_create_file(cpufreq_global_kobject, attr);
791 if (ret)
792 cpufreq_put_global_kobject();
793 }
794
795 return ret;
796}
797EXPORT_SYMBOL(cpufreq_sysfs_create_file);
798
799void cpufreq_sysfs_remove_file(const struct attribute *attr)
800{
801 sysfs_remove_file(cpufreq_global_kobject, attr);
802 cpufreq_put_global_kobject();
803}
804EXPORT_SYMBOL(cpufreq_sysfs_remove_file);
805
706/* symlink affected CPUs */ 806/* symlink affected CPUs */
707static int cpufreq_add_dev_symlink(unsigned int cpu, 807static int cpufreq_add_dev_symlink(unsigned int cpu,
708 struct cpufreq_policy *policy) 808 struct cpufreq_policy *policy)
@@ -1005,7 +1105,8 @@ static void update_policy_cpu(struct cpufreq_policy *policy, unsigned int cpu)
1005 * Caller should already have policy_rwsem in write mode for this CPU. 1105 * Caller should already have policy_rwsem in write mode for this CPU.
1006 * This routine frees the rwsem before returning. 1106 * This routine frees the rwsem before returning.
1007 */ 1107 */
1008static int __cpufreq_remove_dev(struct device *dev, struct subsys_interface *sif) 1108static int __cpufreq_remove_dev(struct device *dev,
1109 struct subsys_interface *sif)
1009{ 1110{
1010 unsigned int cpu = dev->id, ret, cpus; 1111 unsigned int cpu = dev->id, ret, cpus;
1011 unsigned long flags; 1112 unsigned long flags;
@@ -1112,7 +1213,6 @@ static int __cpufreq_remove_dev(struct device *dev, struct subsys_interface *sif
1112 return 0; 1213 return 0;
1113} 1214}
1114 1215
1115
1116static int cpufreq_remove_dev(struct device *dev, struct subsys_interface *sif) 1216static int cpufreq_remove_dev(struct device *dev, struct subsys_interface *sif)
1117{ 1217{
1118 unsigned int cpu = dev->id; 1218 unsigned int cpu = dev->id;
@@ -1125,7 +1225,6 @@ static int cpufreq_remove_dev(struct device *dev, struct subsys_interface *sif)
1125 return retval; 1225 return retval;
1126} 1226}
1127 1227
1128
1129static void handle_update(struct work_struct *work) 1228static void handle_update(struct work_struct *work)
1130{ 1229{
1131 struct cpufreq_policy *policy = 1230 struct cpufreq_policy *policy =
@@ -1136,7 +1235,8 @@ static void handle_update(struct work_struct *work)
1136} 1235}
1137 1236
1138/** 1237/**
1139 * cpufreq_out_of_sync - If actual and saved CPU frequency differs, we're in deep trouble. 1238 * cpufreq_out_of_sync - If actual and saved CPU frequency differs, we're
1239 * in deep trouble.
1140 * @cpu: cpu number 1240 * @cpu: cpu number
1141 * @old_freq: CPU frequency the kernel thinks the CPU runs at 1241 * @old_freq: CPU frequency the kernel thinks the CPU runs at
1142 * @new_freq: CPU frequency the CPU actually runs at 1242 * @new_freq: CPU frequency the CPU actually runs at
@@ -1151,7 +1251,6 @@ static void cpufreq_out_of_sync(unsigned int cpu, unsigned int old_freq,
1151 struct cpufreq_freqs freqs; 1251 struct cpufreq_freqs freqs;
1152 unsigned long flags; 1252 unsigned long flags;
1153 1253
1154
1155 pr_debug("Warning: CPU frequency out of sync: cpufreq and timing " 1254 pr_debug("Warning: CPU frequency out of sync: cpufreq and timing "
1156 "core thinks of %u, is %u kHz.\n", old_freq, new_freq); 1255 "core thinks of %u, is %u kHz.\n", old_freq, new_freq);
1157 1256
@@ -1166,7 +1265,6 @@ static void cpufreq_out_of_sync(unsigned int cpu, unsigned int old_freq,
1166 cpufreq_notify_transition(policy, &freqs, CPUFREQ_POSTCHANGE); 1265 cpufreq_notify_transition(policy, &freqs, CPUFREQ_POSTCHANGE);
1167} 1266}
1168 1267
1169
1170/** 1268/**
1171 * cpufreq_quick_get - get the CPU frequency (in kHz) from policy->cur 1269 * cpufreq_quick_get - get the CPU frequency (in kHz) from policy->cur
1172 * @cpu: CPU number 1270 * @cpu: CPU number
@@ -1212,7 +1310,6 @@ unsigned int cpufreq_quick_get_max(unsigned int cpu)
1212} 1310}
1213EXPORT_SYMBOL(cpufreq_quick_get_max); 1311EXPORT_SYMBOL(cpufreq_quick_get_max);
1214 1312
1215
1216static unsigned int __cpufreq_get(unsigned int cpu) 1313static unsigned int __cpufreq_get(unsigned int cpu)
1217{ 1314{
1218 struct cpufreq_policy *policy = per_cpu(cpufreq_cpu_data, cpu); 1315 struct cpufreq_policy *policy = per_cpu(cpufreq_cpu_data, cpu);
@@ -1271,7 +1368,6 @@ static struct subsys_interface cpufreq_interface = {
1271 .remove_dev = cpufreq_remove_dev, 1368 .remove_dev = cpufreq_remove_dev,
1272}; 1369};
1273 1370
1274
1275/** 1371/**
1276 * cpufreq_bp_suspend - Prepare the boot CPU for system suspend. 1372 * cpufreq_bp_suspend - Prepare the boot CPU for system suspend.
1277 * 1373 *
@@ -1408,11 +1504,10 @@ int cpufreq_register_notifier(struct notifier_block *nb, unsigned int list)
1408} 1504}
1409EXPORT_SYMBOL(cpufreq_register_notifier); 1505EXPORT_SYMBOL(cpufreq_register_notifier);
1410 1506
1411
1412/** 1507/**
1413 * cpufreq_unregister_notifier - unregister a driver with cpufreq 1508 * cpufreq_unregister_notifier - unregister a driver with cpufreq
1414 * @nb: notifier block to be unregistered 1509 * @nb: notifier block to be unregistered
1415 * @list: CPUFREQ_TRANSITION_NOTIFIER or CPUFREQ_POLICY_NOTIFIER 1510 * @list: CPUFREQ_TRANSITION_NOTIFIER or CPUFREQ_POLICY_NOTIFIER
1416 * 1511 *
1417 * Remove a driver from the CPU frequency notifier list. 1512 * Remove a driver from the CPU frequency notifier list.
1418 * 1513 *
@@ -1448,7 +1543,6 @@ EXPORT_SYMBOL(cpufreq_unregister_notifier);
1448 * GOVERNORS * 1543 * GOVERNORS *
1449 *********************************************************************/ 1544 *********************************************************************/
1450 1545
1451
1452int __cpufreq_driver_target(struct cpufreq_policy *policy, 1546int __cpufreq_driver_target(struct cpufreq_policy *policy,
1453 unsigned int target_freq, 1547 unsigned int target_freq,
1454 unsigned int relation) 1548 unsigned int relation)
@@ -1458,6 +1552,8 @@ int __cpufreq_driver_target(struct cpufreq_policy *policy,
1458 1552
1459 if (cpufreq_disabled()) 1553 if (cpufreq_disabled())
1460 return -ENODEV; 1554 return -ENODEV;
1555 if (policy->transition_ongoing)
1556 return -EBUSY;
1461 1557
1462 /* Make sure that target_freq is within supported range */ 1558 /* Make sure that target_freq is within supported range */
1463 if (target_freq > policy->max) 1559 if (target_freq > policy->max)
@@ -1484,10 +1580,6 @@ int cpufreq_driver_target(struct cpufreq_policy *policy,
1484{ 1580{
1485 int ret = -EINVAL; 1581 int ret = -EINVAL;
1486 1582
1487 policy = cpufreq_cpu_get(policy->cpu);
1488 if (!policy)
1489 goto no_policy;
1490
1491 if (unlikely(lock_policy_rwsem_write(policy->cpu))) 1583 if (unlikely(lock_policy_rwsem_write(policy->cpu)))
1492 goto fail; 1584 goto fail;
1493 1585
@@ -1496,30 +1588,19 @@ int cpufreq_driver_target(struct cpufreq_policy *policy,
1496 unlock_policy_rwsem_write(policy->cpu); 1588 unlock_policy_rwsem_write(policy->cpu);
1497 1589
1498fail: 1590fail:
1499 cpufreq_cpu_put(policy);
1500no_policy:
1501 return ret; 1591 return ret;
1502} 1592}
1503EXPORT_SYMBOL_GPL(cpufreq_driver_target); 1593EXPORT_SYMBOL_GPL(cpufreq_driver_target);
1504 1594
1505int __cpufreq_driver_getavg(struct cpufreq_policy *policy, unsigned int cpu) 1595int __cpufreq_driver_getavg(struct cpufreq_policy *policy, unsigned int cpu)
1506{ 1596{
1507 int ret = 0;
1508
1509 if (cpufreq_disabled()) 1597 if (cpufreq_disabled())
1510 return ret; 1598 return 0;
1511 1599
1512 if (!cpufreq_driver->getavg) 1600 if (!cpufreq_driver->getavg)
1513 return 0; 1601 return 0;
1514 1602
1515 policy = cpufreq_cpu_get(policy->cpu); 1603 return cpufreq_driver->getavg(policy, cpu);
1516 if (!policy)
1517 return -EINVAL;
1518
1519 ret = cpufreq_driver->getavg(policy, cpu);
1520
1521 cpufreq_cpu_put(policy);
1522 return ret;
1523} 1604}
1524EXPORT_SYMBOL_GPL(__cpufreq_driver_getavg); 1605EXPORT_SYMBOL_GPL(__cpufreq_driver_getavg);
1525 1606
@@ -1562,6 +1643,21 @@ static int __cpufreq_governor(struct cpufreq_policy *policy,
1562 1643
1563 pr_debug("__cpufreq_governor for CPU %u, event %u\n", 1644 pr_debug("__cpufreq_governor for CPU %u, event %u\n",
1564 policy->cpu, event); 1645 policy->cpu, event);
1646
1647 mutex_lock(&cpufreq_governor_lock);
1648 if ((!policy->governor_enabled && (event == CPUFREQ_GOV_STOP)) ||
1649 (policy->governor_enabled && (event == CPUFREQ_GOV_START))) {
1650 mutex_unlock(&cpufreq_governor_lock);
1651 return -EBUSY;
1652 }
1653
1654 if (event == CPUFREQ_GOV_STOP)
1655 policy->governor_enabled = false;
1656 else if (event == CPUFREQ_GOV_START)
1657 policy->governor_enabled = true;
1658
1659 mutex_unlock(&cpufreq_governor_lock);
1660
1565 ret = policy->governor->governor(policy, event); 1661 ret = policy->governor->governor(policy, event);
1566 1662
1567 if (!ret) { 1663 if (!ret) {
@@ -1569,6 +1665,14 @@ static int __cpufreq_governor(struct cpufreq_policy *policy,
1569 policy->governor->initialized++; 1665 policy->governor->initialized++;
1570 else if (event == CPUFREQ_GOV_POLICY_EXIT) 1666 else if (event == CPUFREQ_GOV_POLICY_EXIT)
1571 policy->governor->initialized--; 1667 policy->governor->initialized--;
1668 } else {
1669 /* Restore original values */
1670 mutex_lock(&cpufreq_governor_lock);
1671 if (event == CPUFREQ_GOV_STOP)
1672 policy->governor_enabled = true;
1673 else if (event == CPUFREQ_GOV_START)
1674 policy->governor_enabled = false;
1675 mutex_unlock(&cpufreq_governor_lock);
1572 } 1676 }
1573 1677
1574 /* we keep one module reference alive for 1678 /* we keep one module reference alive for
@@ -1581,7 +1685,6 @@ static int __cpufreq_governor(struct cpufreq_policy *policy,
1581 return ret; 1685 return ret;
1582} 1686}
1583 1687
1584
1585int cpufreq_register_governor(struct cpufreq_governor *governor) 1688int cpufreq_register_governor(struct cpufreq_governor *governor)
1586{ 1689{
1587 int err; 1690 int err;
@@ -1606,7 +1709,6 @@ int cpufreq_register_governor(struct cpufreq_governor *governor)
1606} 1709}
1607EXPORT_SYMBOL_GPL(cpufreq_register_governor); 1710EXPORT_SYMBOL_GPL(cpufreq_register_governor);
1608 1711
1609
1610void cpufreq_unregister_governor(struct cpufreq_governor *governor) 1712void cpufreq_unregister_governor(struct cpufreq_governor *governor)
1611{ 1713{
1612#ifdef CONFIG_HOTPLUG_CPU 1714#ifdef CONFIG_HOTPLUG_CPU
@@ -1636,7 +1738,6 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor)
1636EXPORT_SYMBOL_GPL(cpufreq_unregister_governor); 1738EXPORT_SYMBOL_GPL(cpufreq_unregister_governor);
1637 1739
1638 1740
1639
1640/********************************************************************* 1741/*********************************************************************
1641 * POLICY INTERFACE * 1742 * POLICY INTERFACE *
1642 *********************************************************************/ 1743 *********************************************************************/
@@ -1665,7 +1766,6 @@ int cpufreq_get_policy(struct cpufreq_policy *policy, unsigned int cpu)
1665} 1766}
1666EXPORT_SYMBOL(cpufreq_get_policy); 1767EXPORT_SYMBOL(cpufreq_get_policy);
1667 1768
1668
1669/* 1769/*
1670 * data : current policy. 1770 * data : current policy.
1671 * policy : policy to be set. 1771 * policy : policy to be set.
@@ -1699,8 +1799,10 @@ static int __cpufreq_set_policy(struct cpufreq_policy *data,
1699 blocking_notifier_call_chain(&cpufreq_policy_notifier_list, 1799 blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
1700 CPUFREQ_INCOMPATIBLE, policy); 1800 CPUFREQ_INCOMPATIBLE, policy);
1701 1801
1702 /* verify the cpu speed can be set within this limit, 1802 /*
1703 which might be different to the first one */ 1803 * verify the cpu speed can be set within this limit, which might be
1804 * different to the first one
1805 */
1704 ret = cpufreq_driver->verify(policy); 1806 ret = cpufreq_driver->verify(policy);
1705 if (ret) 1807 if (ret)
1706 goto error_out; 1808 goto error_out;
@@ -1802,8 +1904,10 @@ int cpufreq_update_policy(unsigned int cpu)
1802 policy.policy = data->user_policy.policy; 1904 policy.policy = data->user_policy.policy;
1803 policy.governor = data->user_policy.governor; 1905 policy.governor = data->user_policy.governor;
1804 1906
1805 /* BIOS might change freq behind our back 1907 /*
1806 -> ask driver for current freq and notify governors about a change */ 1908 * BIOS might change freq behind our back
1909 * -> ask driver for current freq and notify governors about a change
1910 */
1807 if (cpufreq_driver->get) { 1911 if (cpufreq_driver->get) {
1808 policy.cur = cpufreq_driver->get(cpu); 1912 policy.cur = cpufreq_driver->get(cpu);
1809 if (!data->cur) { 1913 if (!data->cur) {
@@ -1852,7 +1956,7 @@ static int __cpuinit cpufreq_cpu_callback(struct notifier_block *nfb,
1852} 1956}
1853 1957
1854static struct notifier_block __refdata cpufreq_cpu_notifier = { 1958static struct notifier_block __refdata cpufreq_cpu_notifier = {
1855 .notifier_call = cpufreq_cpu_callback, 1959 .notifier_call = cpufreq_cpu_callback,
1856}; 1960};
1857 1961
1858/********************************************************************* 1962/*********************************************************************
@@ -1864,7 +1968,7 @@ static struct notifier_block __refdata cpufreq_cpu_notifier = {
1864 * @driver_data: A struct cpufreq_driver containing the values# 1968 * @driver_data: A struct cpufreq_driver containing the values#
1865 * submitted by the CPU Frequency driver. 1969 * submitted by the CPU Frequency driver.
1866 * 1970 *
1867 * Registers a CPU Frequency driver to this core code. This code 1971 * Registers a CPU Frequency driver to this core code. This code
1868 * returns zero on success, -EBUSY when another driver got here first 1972 * returns zero on success, -EBUSY when another driver got here first
1869 * (and isn't unregistered in the meantime). 1973 * (and isn't unregistered in the meantime).
1870 * 1974 *
@@ -1931,11 +2035,10 @@ err_null_driver:
1931} 2035}
1932EXPORT_SYMBOL_GPL(cpufreq_register_driver); 2036EXPORT_SYMBOL_GPL(cpufreq_register_driver);
1933 2037
1934
1935/** 2038/**
1936 * cpufreq_unregister_driver - unregister the current CPUFreq driver 2039 * cpufreq_unregister_driver - unregister the current CPUFreq driver
1937 * 2040 *
1938 * Unregister the current CPUFreq driver. Only call this if you have 2041 * Unregister the current CPUFreq driver. Only call this if you have
1939 * the right to do so, i.e. if you have succeeded in initialising before! 2042 * the right to do so, i.e. if you have succeeded in initialising before!
1940 * Returns zero if successful, and -EINVAL if the cpufreq_driver is 2043 * Returns zero if successful, and -EINVAL if the cpufreq_driver is
1941 * currently not initialised. 2044 * currently not initialised.
@@ -1972,7 +2075,7 @@ static int __init cpufreq_core_init(void)
1972 init_rwsem(&per_cpu(cpu_policy_rwsem, cpu)); 2075 init_rwsem(&per_cpu(cpu_policy_rwsem, cpu));
1973 } 2076 }
1974 2077
1975 cpufreq_global_kobject = kobject_create_and_add("cpufreq", &cpu_subsys.dev_root->kobj); 2078 cpufreq_global_kobject = kobject_create();
1976 BUG_ON(!cpufreq_global_kobject); 2079 BUG_ON(!cpufreq_global_kobject);
1977 register_syscore_ops(&cpufreq_syscore_ops); 2080 register_syscore_ops(&cpufreq_syscore_ops);
1978 2081
diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
index dc9b72e25c1a..464587697561 100644
--- a/drivers/cpufreq/cpufreq_governor.c
+++ b/drivers/cpufreq/cpufreq_governor.c
@@ -23,21 +23,12 @@
23#include <linux/kernel_stat.h> 23#include <linux/kernel_stat.h>
24#include <linux/mutex.h> 24#include <linux/mutex.h>
25#include <linux/slab.h> 25#include <linux/slab.h>
26#include <linux/tick.h>
27#include <linux/types.h> 26#include <linux/types.h>
28#include <linux/workqueue.h> 27#include <linux/workqueue.h>
29#include <linux/cpu.h> 28#include <linux/cpu.h>
30 29
31#include "cpufreq_governor.h" 30#include "cpufreq_governor.h"
32 31
33static struct kobject *get_governor_parent_kobj(struct cpufreq_policy *policy)
34{
35 if (have_governor_per_policy())
36 return &policy->kobj;
37 else
38 return cpufreq_global_kobject;
39}
40
41static struct attribute_group *get_sysfs_attr(struct dbs_data *dbs_data) 32static struct attribute_group *get_sysfs_attr(struct dbs_data *dbs_data)
42{ 33{
43 if (have_governor_per_policy()) 34 if (have_governor_per_policy())
@@ -46,41 +37,6 @@ static struct attribute_group *get_sysfs_attr(struct dbs_data *dbs_data)
46 return dbs_data->cdata->attr_group_gov_sys; 37 return dbs_data->cdata->attr_group_gov_sys;
47} 38}
48 39
49static inline u64 get_cpu_idle_time_jiffy(unsigned int cpu, u64 *wall)
50{
51 u64 idle_time;
52 u64 cur_wall_time;
53 u64 busy_time;
54
55 cur_wall_time = jiffies64_to_cputime64(get_jiffies_64());
56
57 busy_time = kcpustat_cpu(cpu).cpustat[CPUTIME_USER];
58 busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_SYSTEM];
59 busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_IRQ];
60 busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_SOFTIRQ];
61 busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_STEAL];
62 busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_NICE];
63
64 idle_time = cur_wall_time - busy_time;
65 if (wall)
66 *wall = cputime_to_usecs(cur_wall_time);
67
68 return cputime_to_usecs(idle_time);
69}
70
71u64 get_cpu_idle_time(unsigned int cpu, u64 *wall, int io_busy)
72{
73 u64 idle_time = get_cpu_idle_time_us(cpu, io_busy ? wall : NULL);
74
75 if (idle_time == -1ULL)
76 return get_cpu_idle_time_jiffy(cpu, wall);
77 else if (!io_busy)
78 idle_time += get_cpu_iowait_time_us(cpu, wall);
79
80 return idle_time;
81}
82EXPORT_SYMBOL_GPL(get_cpu_idle_time);
83
84void dbs_check_cpu(struct dbs_data *dbs_data, int cpu) 40void dbs_check_cpu(struct dbs_data *dbs_data, int cpu)
85{ 41{
86 struct cpu_dbs_common_info *cdbs = dbs_data->cdata->get_cpu_cdbs(cpu); 42 struct cpu_dbs_common_info *cdbs = dbs_data->cdata->get_cpu_cdbs(cpu);
@@ -278,6 +234,9 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
278 return rc; 234 return rc;
279 } 235 }
280 236
237 if (!have_governor_per_policy())
238 WARN_ON(cpufreq_get_global_kobject());
239
281 rc = sysfs_create_group(get_governor_parent_kobj(policy), 240 rc = sysfs_create_group(get_governor_parent_kobj(policy),
282 get_sysfs_attr(dbs_data)); 241 get_sysfs_attr(dbs_data));
283 if (rc) { 242 if (rc) {
@@ -316,6 +275,9 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
316 sysfs_remove_group(get_governor_parent_kobj(policy), 275 sysfs_remove_group(get_governor_parent_kobj(policy),
317 get_sysfs_attr(dbs_data)); 276 get_sysfs_attr(dbs_data));
318 277
278 if (!have_governor_per_policy())
279 cpufreq_put_global_kobject();
280
319 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) && 281 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
320 (policy->governor->initialized == 1)) { 282 (policy->governor->initialized == 1)) {
321 struct cs_ops *cs_ops = dbs_data->cdata->gov_ops; 283 struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
@@ -404,6 +366,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
404 366
405 mutex_lock(&dbs_data->mutex); 367 mutex_lock(&dbs_data->mutex);
406 mutex_destroy(&cpu_cdbs->timer_mutex); 368 mutex_destroy(&cpu_cdbs->timer_mutex);
369 cpu_cdbs->cur_policy = NULL;
407 370
408 mutex_unlock(&dbs_data->mutex); 371 mutex_unlock(&dbs_data->mutex);
409 372
diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
index e16a96130cb3..6663ec3b3056 100644
--- a/drivers/cpufreq/cpufreq_governor.h
+++ b/drivers/cpufreq/cpufreq_governor.h
@@ -81,7 +81,7 @@ static ssize_t show_##file_name##_gov_sys \
81 return sprintf(buf, "%u\n", tuners->file_name); \ 81 return sprintf(buf, "%u\n", tuners->file_name); \
82} \ 82} \
83 \ 83 \
84static ssize_t show_##file_name##_gov_pol \ 84static ssize_t show_##file_name##_gov_pol \
85(struct cpufreq_policy *policy, char *buf) \ 85(struct cpufreq_policy *policy, char *buf) \
86{ \ 86{ \
87 struct dbs_data *dbs_data = policy->governor_data; \ 87 struct dbs_data *dbs_data = policy->governor_data; \
@@ -91,7 +91,7 @@ static ssize_t show_##file_name##_gov_pol \
91 91
92#define store_one(_gov, file_name) \ 92#define store_one(_gov, file_name) \
93static ssize_t store_##file_name##_gov_sys \ 93static ssize_t store_##file_name##_gov_sys \
94(struct kobject *kobj, struct attribute *attr, const char *buf, size_t count) \ 94(struct kobject *kobj, struct attribute *attr, const char *buf, size_t count) \
95{ \ 95{ \
96 struct dbs_data *dbs_data = _gov##_dbs_cdata.gdbs_data; \ 96 struct dbs_data *dbs_data = _gov##_dbs_cdata.gdbs_data; \
97 return store_##file_name(dbs_data, buf, count); \ 97 return store_##file_name(dbs_data, buf, count); \
@@ -256,7 +256,6 @@ static ssize_t show_sampling_rate_min_gov_pol \
256 return sprintf(buf, "%u\n", dbs_data->min_sampling_rate); \ 256 return sprintf(buf, "%u\n", dbs_data->min_sampling_rate); \
257} 257}
258 258
259u64 get_cpu_idle_time(unsigned int cpu, u64 *wall, int io_busy);
260void dbs_check_cpu(struct dbs_data *dbs_data, int cpu); 259void dbs_check_cpu(struct dbs_data *dbs_data, int cpu);
261bool need_load_eval(struct cpu_dbs_common_info *cdbs, 260bool need_load_eval(struct cpu_dbs_common_info *cdbs,
262 unsigned int sampling_rate); 261 unsigned int sampling_rate);
diff --git a/drivers/cpufreq/cpufreq_performance.c b/drivers/cpufreq/cpufreq_performance.c
index ceee06849b91..9fef7d6e4e6a 100644
--- a/drivers/cpufreq/cpufreq_performance.c
+++ b/drivers/cpufreq/cpufreq_performance.c
@@ -17,7 +17,6 @@
17#include <linux/cpufreq.h> 17#include <linux/cpufreq.h>
18#include <linux/init.h> 18#include <linux/init.h>
19 19
20
21static int cpufreq_governor_performance(struct cpufreq_policy *policy, 20static int cpufreq_governor_performance(struct cpufreq_policy *policy,
22 unsigned int event) 21 unsigned int event)
23{ 22{
@@ -44,19 +43,16 @@ struct cpufreq_governor cpufreq_gov_performance = {
44 .owner = THIS_MODULE, 43 .owner = THIS_MODULE,
45}; 44};
46 45
47
48static int __init cpufreq_gov_performance_init(void) 46static int __init cpufreq_gov_performance_init(void)
49{ 47{
50 return cpufreq_register_governor(&cpufreq_gov_performance); 48 return cpufreq_register_governor(&cpufreq_gov_performance);
51} 49}
52 50
53
54static void __exit cpufreq_gov_performance_exit(void) 51static void __exit cpufreq_gov_performance_exit(void)
55{ 52{
56 cpufreq_unregister_governor(&cpufreq_gov_performance); 53 cpufreq_unregister_governor(&cpufreq_gov_performance);
57} 54}
58 55
59
60MODULE_AUTHOR("Dominik Brodowski <linux@brodo.de>"); 56MODULE_AUTHOR("Dominik Brodowski <linux@brodo.de>");
61MODULE_DESCRIPTION("CPUfreq policy governor 'performance'"); 57MODULE_DESCRIPTION("CPUfreq policy governor 'performance'");
62MODULE_LICENSE("GPL"); 58MODULE_LICENSE("GPL");
diff --git a/drivers/cpufreq/cpufreq_powersave.c b/drivers/cpufreq/cpufreq_powersave.c
index 2d948a171155..32109a14f5dc 100644
--- a/drivers/cpufreq/cpufreq_powersave.c
+++ b/drivers/cpufreq/cpufreq_powersave.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * linux/drivers/cpufreq/cpufreq_powersave.c 2 * linux/drivers/cpufreq/cpufreq_powersave.c
3 * 3 *
4 * Copyright (C) 2002 - 2003 Dominik Brodowski <linux@brodo.de> 4 * Copyright (C) 2002 - 2003 Dominik Brodowski <linux@brodo.de>
5 * 5 *
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
@@ -48,13 +48,11 @@ static int __init cpufreq_gov_powersave_init(void)
48 return cpufreq_register_governor(&cpufreq_gov_powersave); 48 return cpufreq_register_governor(&cpufreq_gov_powersave);
49} 49}
50 50
51
52static void __exit cpufreq_gov_powersave_exit(void) 51static void __exit cpufreq_gov_powersave_exit(void)
53{ 52{
54 cpufreq_unregister_governor(&cpufreq_gov_powersave); 53 cpufreq_unregister_governor(&cpufreq_gov_powersave);
55} 54}
56 55
57
58MODULE_AUTHOR("Dominik Brodowski <linux@brodo.de>"); 56MODULE_AUTHOR("Dominik Brodowski <linux@brodo.de>");
59MODULE_DESCRIPTION("CPUfreq policy governor 'powersave'"); 57MODULE_DESCRIPTION("CPUfreq policy governor 'powersave'");
60MODULE_LICENSE("GPL"); 58MODULE_LICENSE("GPL");
diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
index fb65decffa28..cd9e81713a71 100644
--- a/drivers/cpufreq/cpufreq_stats.c
+++ b/drivers/cpufreq/cpufreq_stats.c
@@ -27,7 +27,7 @@ static spinlock_t cpufreq_stats_lock;
27struct cpufreq_stats { 27struct cpufreq_stats {
28 unsigned int cpu; 28 unsigned int cpu;
29 unsigned int total_trans; 29 unsigned int total_trans;
30 unsigned long long last_time; 30 unsigned long long last_time;
31 unsigned int max_state; 31 unsigned int max_state;
32 unsigned int state_num; 32 unsigned int state_num;
33 unsigned int last_index; 33 unsigned int last_index;
@@ -116,7 +116,7 @@ static ssize_t show_trans_table(struct cpufreq_policy *policy, char *buf)
116 len += snprintf(buf + len, PAGE_SIZE - len, "%9u: ", 116 len += snprintf(buf + len, PAGE_SIZE - len, "%9u: ",
117 stat->freq_table[i]); 117 stat->freq_table[i]);
118 118
119 for (j = 0; j < stat->state_num; j++) { 119 for (j = 0; j < stat->state_num; j++) {
120 if (len >= PAGE_SIZE) 120 if (len >= PAGE_SIZE)
121 break; 121 break;
122 len += snprintf(buf + len, PAGE_SIZE - len, "%9u ", 122 len += snprintf(buf + len, PAGE_SIZE - len, "%9u ",
@@ -349,6 +349,7 @@ static int __cpuinit cpufreq_stat_cpu_callback(struct notifier_block *nfb,
349 349
350 switch (action) { 350 switch (action) {
351 case CPU_ONLINE: 351 case CPU_ONLINE:
352 case CPU_ONLINE_FROZEN:
352 cpufreq_update_policy(cpu); 353 cpufreq_update_policy(cpu);
353 break; 354 break;
354 case CPU_DOWN_PREPARE: 355 case CPU_DOWN_PREPARE:
diff --git a/drivers/cpufreq/cpufreq_userspace.c b/drivers/cpufreq/cpufreq_userspace.c
index bbeb9c0720a6..03078090b5f7 100644
--- a/drivers/cpufreq/cpufreq_userspace.c
+++ b/drivers/cpufreq/cpufreq_userspace.c
@@ -13,55 +13,13 @@
13 13
14#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 14#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
15 15
16#include <linux/kernel.h>
17#include <linux/module.h>
18#include <linux/smp.h>
19#include <linux/init.h>
20#include <linux/spinlock.h>
21#include <linux/interrupt.h>
22#include <linux/cpufreq.h> 16#include <linux/cpufreq.h>
23#include <linux/cpu.h> 17#include <linux/init.h>
24#include <linux/types.h> 18#include <linux/module.h>
25#include <linux/fs.h>
26#include <linux/sysfs.h>
27#include <linux/mutex.h> 19#include <linux/mutex.h>
28 20
29/**
30 * A few values needed by the userspace governor
31 */
32static DEFINE_PER_CPU(unsigned int, cpu_max_freq);
33static DEFINE_PER_CPU(unsigned int, cpu_min_freq);
34static DEFINE_PER_CPU(unsigned int, cpu_cur_freq); /* current CPU freq */
35static DEFINE_PER_CPU(unsigned int, cpu_set_freq); /* CPU freq desired by
36 userspace */
37static DEFINE_PER_CPU(unsigned int, cpu_is_managed); 21static DEFINE_PER_CPU(unsigned int, cpu_is_managed);
38
39static DEFINE_MUTEX(userspace_mutex); 22static DEFINE_MUTEX(userspace_mutex);
40static int cpus_using_userspace_governor;
41
42/* keep track of frequency transitions */
43static int
44userspace_cpufreq_notifier(struct notifier_block *nb, unsigned long val,
45 void *data)
46{
47 struct cpufreq_freqs *freq = data;
48
49 if (!per_cpu(cpu_is_managed, freq->cpu))
50 return 0;
51
52 if (val == CPUFREQ_POSTCHANGE) {
53 pr_debug("saving cpu_cur_freq of cpu %u to be %u kHz\n",
54 freq->cpu, freq->new);
55 per_cpu(cpu_cur_freq, freq->cpu) = freq->new;
56 }
57
58 return 0;
59}
60
61static struct notifier_block userspace_cpufreq_notifier_block = {
62 .notifier_call = userspace_cpufreq_notifier
63};
64
65 23
66/** 24/**
67 * cpufreq_set - set the CPU frequency 25 * cpufreq_set - set the CPU frequency
@@ -80,13 +38,6 @@ static int cpufreq_set(struct cpufreq_policy *policy, unsigned int freq)
80 if (!per_cpu(cpu_is_managed, policy->cpu)) 38 if (!per_cpu(cpu_is_managed, policy->cpu))
81 goto err; 39 goto err;
82 40
83 per_cpu(cpu_set_freq, policy->cpu) = freq;
84
85 if (freq < per_cpu(cpu_min_freq, policy->cpu))
86 freq = per_cpu(cpu_min_freq, policy->cpu);
87 if (freq > per_cpu(cpu_max_freq, policy->cpu))
88 freq = per_cpu(cpu_max_freq, policy->cpu);
89
90 /* 41 /*
91 * We're safe from concurrent calls to ->target() here 42 * We're safe from concurrent calls to ->target() here
92 * as we hold the userspace_mutex lock. If we were calling 43 * as we hold the userspace_mutex lock. If we were calling
@@ -104,10 +55,9 @@ static int cpufreq_set(struct cpufreq_policy *policy, unsigned int freq)
104 return ret; 55 return ret;
105} 56}
106 57
107
108static ssize_t show_speed(struct cpufreq_policy *policy, char *buf) 58static ssize_t show_speed(struct cpufreq_policy *policy, char *buf)
109{ 59{
110 return sprintf(buf, "%u\n", per_cpu(cpu_cur_freq, policy->cpu)); 60 return sprintf(buf, "%u\n", policy->cur);
111} 61}
112 62
113static int cpufreq_governor_userspace(struct cpufreq_policy *policy, 63static int cpufreq_governor_userspace(struct cpufreq_policy *policy,
@@ -119,73 +69,37 @@ static int cpufreq_governor_userspace(struct cpufreq_policy *policy,
119 switch (event) { 69 switch (event) {
120 case CPUFREQ_GOV_START: 70 case CPUFREQ_GOV_START:
121 BUG_ON(!policy->cur); 71 BUG_ON(!policy->cur);
122 mutex_lock(&userspace_mutex); 72 pr_debug("started managing cpu %u\n", cpu);
123
124 if (cpus_using_userspace_governor == 0) {
125 cpufreq_register_notifier(
126 &userspace_cpufreq_notifier_block,
127 CPUFREQ_TRANSITION_NOTIFIER);
128 }
129 cpus_using_userspace_governor++;
130 73
74 mutex_lock(&userspace_mutex);
131 per_cpu(cpu_is_managed, cpu) = 1; 75 per_cpu(cpu_is_managed, cpu) = 1;
132 per_cpu(cpu_min_freq, cpu) = policy->min;
133 per_cpu(cpu_max_freq, cpu) = policy->max;
134 per_cpu(cpu_cur_freq, cpu) = policy->cur;
135 per_cpu(cpu_set_freq, cpu) = policy->cur;
136 pr_debug("managing cpu %u started "
137 "(%u - %u kHz, currently %u kHz)\n",
138 cpu,
139 per_cpu(cpu_min_freq, cpu),
140 per_cpu(cpu_max_freq, cpu),
141 per_cpu(cpu_cur_freq, cpu));
142
143 mutex_unlock(&userspace_mutex); 76 mutex_unlock(&userspace_mutex);
144 break; 77 break;
145 case CPUFREQ_GOV_STOP: 78 case CPUFREQ_GOV_STOP:
146 mutex_lock(&userspace_mutex); 79 pr_debug("managing cpu %u stopped\n", cpu);
147 cpus_using_userspace_governor--;
148 if (cpus_using_userspace_governor == 0) {
149 cpufreq_unregister_notifier(
150 &userspace_cpufreq_notifier_block,
151 CPUFREQ_TRANSITION_NOTIFIER);
152 }
153 80
81 mutex_lock(&userspace_mutex);
154 per_cpu(cpu_is_managed, cpu) = 0; 82 per_cpu(cpu_is_managed, cpu) = 0;
155 per_cpu(cpu_min_freq, cpu) = 0;
156 per_cpu(cpu_max_freq, cpu) = 0;
157 per_cpu(cpu_set_freq, cpu) = 0;
158 pr_debug("managing cpu %u stopped\n", cpu);
159 mutex_unlock(&userspace_mutex); 83 mutex_unlock(&userspace_mutex);
160 break; 84 break;
161 case CPUFREQ_GOV_LIMITS: 85 case CPUFREQ_GOV_LIMITS:
162 mutex_lock(&userspace_mutex); 86 mutex_lock(&userspace_mutex);
163 pr_debug("limit event for cpu %u: %u - %u kHz, " 87 pr_debug("limit event for cpu %u: %u - %u kHz, currently %u kHz\n",
164 "currently %u kHz, last set to %u kHz\n",
165 cpu, policy->min, policy->max, 88 cpu, policy->min, policy->max,
166 per_cpu(cpu_cur_freq, cpu), 89 policy->cur);
167 per_cpu(cpu_set_freq, cpu)); 90
168 if (policy->max < per_cpu(cpu_set_freq, cpu)) { 91 if (policy->max < policy->cur)
169 __cpufreq_driver_target(policy, policy->max, 92 __cpufreq_driver_target(policy, policy->max,
170 CPUFREQ_RELATION_H); 93 CPUFREQ_RELATION_H);
171 } else if (policy->min > per_cpu(cpu_set_freq, cpu)) { 94 else if (policy->min > policy->cur)
172 __cpufreq_driver_target(policy, policy->min, 95 __cpufreq_driver_target(policy, policy->min,
173 CPUFREQ_RELATION_L); 96 CPUFREQ_RELATION_L);
174 } else {
175 __cpufreq_driver_target(policy,
176 per_cpu(cpu_set_freq, cpu),
177 CPUFREQ_RELATION_L);
178 }
179 per_cpu(cpu_min_freq, cpu) = policy->min;
180 per_cpu(cpu_max_freq, cpu) = policy->max;
181 per_cpu(cpu_cur_freq, cpu) = policy->cur;
182 mutex_unlock(&userspace_mutex); 97 mutex_unlock(&userspace_mutex);
183 break; 98 break;
184 } 99 }
185 return rc; 100 return rc;
186} 101}
187 102
188
189#ifndef CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE 103#ifndef CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE
190static 104static
191#endif 105#endif
@@ -202,13 +116,11 @@ static int __init cpufreq_gov_userspace_init(void)
202 return cpufreq_register_governor(&cpufreq_gov_userspace); 116 return cpufreq_register_governor(&cpufreq_gov_userspace);
203} 117}
204 118
205
206static void __exit cpufreq_gov_userspace_exit(void) 119static void __exit cpufreq_gov_userspace_exit(void)
207{ 120{
208 cpufreq_unregister_governor(&cpufreq_gov_userspace); 121 cpufreq_unregister_governor(&cpufreq_gov_userspace);
209} 122}
210 123
211
212MODULE_AUTHOR("Dominik Brodowski <linux@brodo.de>, " 124MODULE_AUTHOR("Dominik Brodowski <linux@brodo.de>, "
213 "Russell King <rmk@arm.linux.org.uk>"); 125 "Russell King <rmk@arm.linux.org.uk>");
214MODULE_DESCRIPTION("CPUfreq policy governor 'userspace'"); 126MODULE_DESCRIPTION("CPUfreq policy governor 'userspace'");
diff --git a/drivers/cpufreq/davinci-cpufreq.c b/drivers/cpufreq/davinci-cpufreq.c
index c33c76c360fa..551dd655c6f2 100644
--- a/drivers/cpufreq/davinci-cpufreq.c
+++ b/drivers/cpufreq/davinci-cpufreq.c
@@ -114,6 +114,9 @@ static int davinci_target(struct cpufreq_policy *policy,
114 pdata->set_voltage(idx); 114 pdata->set_voltage(idx);
115 115
116out: 116out:
117 if (ret)
118 freqs.new = freqs.old;
119
117 cpufreq_notify_transition(policy, &freqs, CPUFREQ_POSTCHANGE); 120 cpufreq_notify_transition(policy, &freqs, CPUFREQ_POSTCHANGE);
118 121
119 return ret; 122 return ret;
diff --git a/drivers/cpufreq/dbx500-cpufreq.c b/drivers/cpufreq/dbx500-cpufreq.c
index 6ec6539ae041..1fdb02b9f1ec 100644
--- a/drivers/cpufreq/dbx500-cpufreq.c
+++ b/drivers/cpufreq/dbx500-cpufreq.c
@@ -57,13 +57,13 @@ static int dbx500_cpufreq_target(struct cpufreq_policy *policy,
57 if (ret) { 57 if (ret) {
58 pr_err("dbx500-cpufreq: Failed to set armss_clk to %d Hz: error %d\n", 58 pr_err("dbx500-cpufreq: Failed to set armss_clk to %d Hz: error %d\n",
59 freqs.new * 1000, ret); 59 freqs.new * 1000, ret);
60 return ret; 60 freqs.new = freqs.old;
61 } 61 }
62 62
63 /* post change notification */ 63 /* post change notification */
64 cpufreq_notify_transition(policy, &freqs, CPUFREQ_POSTCHANGE); 64 cpufreq_notify_transition(policy, &freqs, CPUFREQ_POSTCHANGE);
65 65
66 return 0; 66 return ret;
67} 67}
68 68
69static unsigned int dbx500_cpufreq_getspeed(unsigned int cpu) 69static unsigned int dbx500_cpufreq_getspeed(unsigned int cpu)
diff --git a/drivers/cpufreq/e_powersaver.c b/drivers/cpufreq/e_powersaver.c
index 37380fb92621..a60efaeb4cf8 100644
--- a/drivers/cpufreq/e_powersaver.c
+++ b/drivers/cpufreq/e_powersaver.c
@@ -161,6 +161,9 @@ postchange:
161 current_multiplier); 161 current_multiplier);
162 } 162 }
163#endif 163#endif
164 if (err)
165 freqs.new = freqs.old;
166
164 cpufreq_notify_transition(policy, &freqs, CPUFREQ_POSTCHANGE); 167 cpufreq_notify_transition(policy, &freqs, CPUFREQ_POSTCHANGE);
165 return err; 168 return err;
166} 169}
@@ -188,7 +191,7 @@ static int eps_target(struct cpufreq_policy *policy,
188 } 191 }
189 192
190 /* Make frequency transition */ 193 /* Make frequency transition */
191 dest_state = centaur->freq_table[newstate].index & 0xffff; 194 dest_state = centaur->freq_table[newstate].driver_data & 0xffff;
192 ret = eps_set_state(centaur, policy, dest_state); 195 ret = eps_set_state(centaur, policy, dest_state);
193 if (ret) 196 if (ret)
194 printk(KERN_ERR "eps: Timeout!\n"); 197 printk(KERN_ERR "eps: Timeout!\n");
@@ -380,9 +383,9 @@ static int eps_cpu_init(struct cpufreq_policy *policy)
380 f_table = &centaur->freq_table[0]; 383 f_table = &centaur->freq_table[0];
381 if (brand != EPS_BRAND_C7M) { 384 if (brand != EPS_BRAND_C7M) {
382 f_table[0].frequency = fsb * min_multiplier; 385 f_table[0].frequency = fsb * min_multiplier;
383 f_table[0].index = (min_multiplier << 8) | min_voltage; 386 f_table[0].driver_data = (min_multiplier << 8) | min_voltage;
384 f_table[1].frequency = fsb * max_multiplier; 387 f_table[1].frequency = fsb * max_multiplier;
385 f_table[1].index = (max_multiplier << 8) | max_voltage; 388 f_table[1].driver_data = (max_multiplier << 8) | max_voltage;
386 f_table[2].frequency = CPUFREQ_TABLE_END; 389 f_table[2].frequency = CPUFREQ_TABLE_END;
387 } else { 390 } else {
388 k = 0; 391 k = 0;
@@ -391,7 +394,7 @@ static int eps_cpu_init(struct cpufreq_policy *policy)
391 for (i = min_multiplier; i <= max_multiplier; i++) { 394 for (i = min_multiplier; i <= max_multiplier; i++) {
392 voltage = (k * step) / 256 + min_voltage; 395 voltage = (k * step) / 256 + min_voltage;
393 f_table[k].frequency = fsb * i; 396 f_table[k].frequency = fsb * i;
394 f_table[k].index = (i << 8) | voltage; 397 f_table[k].driver_data = (i << 8) | voltage;
395 k++; 398 k++;
396 } 399 }
397 f_table[k].frequency = CPUFREQ_TABLE_END; 400 f_table[k].frequency = CPUFREQ_TABLE_END;
diff --git a/drivers/cpufreq/exynos-cpufreq.c b/drivers/cpufreq/exynos-cpufreq.c
index 475b4f607f0d..0d32f02ef4d6 100644
--- a/drivers/cpufreq/exynos-cpufreq.c
+++ b/drivers/cpufreq/exynos-cpufreq.c
@@ -113,7 +113,8 @@ static int exynos_cpufreq_scale(unsigned int target_freq)
113 if (ret) { 113 if (ret) {
114 pr_err("%s: failed to set cpu voltage to %d\n", 114 pr_err("%s: failed to set cpu voltage to %d\n",
115 __func__, arm_volt); 115 __func__, arm_volt);
116 goto out; 116 freqs.new = freqs.old;
117 goto post_notify;
117 } 118 }
118 } 119 }
119 120
@@ -123,14 +124,19 @@ static int exynos_cpufreq_scale(unsigned int target_freq)
123 if (ret) { 124 if (ret) {
124 pr_err("%s: failed to set cpu voltage to %d\n", 125 pr_err("%s: failed to set cpu voltage to %d\n",
125 __func__, safe_arm_volt); 126 __func__, safe_arm_volt);
126 goto out; 127 freqs.new = freqs.old;
128 goto post_notify;
127 } 129 }
128 } 130 }
129 131
130 exynos_info->set_freq(old_index, index); 132 exynos_info->set_freq(old_index, index);
131 133
134post_notify:
132 cpufreq_notify_transition(policy, &freqs, CPUFREQ_POSTCHANGE); 135 cpufreq_notify_transition(policy, &freqs, CPUFREQ_POSTCHANGE);
133 136
137 if (ret)
138 goto out;
139
134 /* When the new frequency is lower than current frequency */ 140 /* When the new frequency is lower than current frequency */
135 if ((freqs.new < freqs.old) || 141 if ((freqs.new < freqs.old) ||
136 ((freqs.new > freqs.old) && safe_arm_volt)) { 142 ((freqs.new > freqs.old) && safe_arm_volt)) {
diff --git a/drivers/cpufreq/freq_table.c b/drivers/cpufreq/freq_table.c
index d7a79662e24c..f0d87412cc91 100644
--- a/drivers/cpufreq/freq_table.c
+++ b/drivers/cpufreq/freq_table.c
@@ -34,8 +34,8 @@ int cpufreq_frequency_table_cpuinfo(struct cpufreq_policy *policy,
34 34
35 continue; 35 continue;
36 } 36 }
37 pr_debug("table entry %u: %u kHz, %u index\n", 37 pr_debug("table entry %u: %u kHz, %u driver_data\n",
38 i, freq, table[i].index); 38 i, freq, table[i].driver_data);
39 if (freq < min_freq) 39 if (freq < min_freq)
40 min_freq = freq; 40 min_freq = freq;
41 if (freq > max_freq) 41 if (freq > max_freq)
@@ -97,11 +97,11 @@ int cpufreq_frequency_table_target(struct cpufreq_policy *policy,
97 unsigned int *index) 97 unsigned int *index)
98{ 98{
99 struct cpufreq_frequency_table optimal = { 99 struct cpufreq_frequency_table optimal = {
100 .index = ~0, 100 .driver_data = ~0,
101 .frequency = 0, 101 .frequency = 0,
102 }; 102 };
103 struct cpufreq_frequency_table suboptimal = { 103 struct cpufreq_frequency_table suboptimal = {
104 .index = ~0, 104 .driver_data = ~0,
105 .frequency = 0, 105 .frequency = 0,
106 }; 106 };
107 unsigned int i; 107 unsigned int i;
@@ -129,12 +129,12 @@ int cpufreq_frequency_table_target(struct cpufreq_policy *policy,
129 if (freq <= target_freq) { 129 if (freq <= target_freq) {
130 if (freq >= optimal.frequency) { 130 if (freq >= optimal.frequency) {
131 optimal.frequency = freq; 131 optimal.frequency = freq;
132 optimal.index = i; 132 optimal.driver_data = i;
133 } 133 }
134 } else { 134 } else {
135 if (freq <= suboptimal.frequency) { 135 if (freq <= suboptimal.frequency) {
136 suboptimal.frequency = freq; 136 suboptimal.frequency = freq;
137 suboptimal.index = i; 137 suboptimal.driver_data = i;
138 } 138 }
139 } 139 }
140 break; 140 break;
@@ -142,26 +142,26 @@ int cpufreq_frequency_table_target(struct cpufreq_policy *policy,
142 if (freq >= target_freq) { 142 if (freq >= target_freq) {
143 if (freq <= optimal.frequency) { 143 if (freq <= optimal.frequency) {
144 optimal.frequency = freq; 144 optimal.frequency = freq;
145 optimal.index = i; 145 optimal.driver_data = i;
146 } 146 }
147 } else { 147 } else {
148 if (freq >= suboptimal.frequency) { 148 if (freq >= suboptimal.frequency) {
149 suboptimal.frequency = freq; 149 suboptimal.frequency = freq;
150 suboptimal.index = i; 150 suboptimal.driver_data = i;
151 } 151 }
152 } 152 }
153 break; 153 break;
154 } 154 }
155 } 155 }
156 if (optimal.index > i) { 156 if (optimal.driver_data > i) {
157 if (suboptimal.index > i) 157 if (suboptimal.driver_data > i)
158 return -EINVAL; 158 return -EINVAL;
159 *index = suboptimal.index; 159 *index = suboptimal.driver_data;
160 } else 160 } else
161 *index = optimal.index; 161 *index = optimal.driver_data;
162 162
163 pr_debug("target is %u (%u kHz, %u)\n", *index, table[*index].frequency, 163 pr_debug("target is %u (%u kHz, %u)\n", *index, table[*index].frequency,
164 table[*index].index); 164 table[*index].driver_data);
165 165
166 return 0; 166 return 0;
167} 167}
diff --git a/drivers/cpufreq/ia64-acpi-cpufreq.c b/drivers/cpufreq/ia64-acpi-cpufreq.c
index c0075dbaa633..573c14ea802d 100644
--- a/drivers/cpufreq/ia64-acpi-cpufreq.c
+++ b/drivers/cpufreq/ia64-acpi-cpufreq.c
@@ -326,7 +326,7 @@ acpi_cpufreq_cpu_init (
326 /* table init */ 326 /* table init */
327 for (i = 0; i <= data->acpi_data.state_count; i++) 327 for (i = 0; i <= data->acpi_data.state_count; i++)
328 { 328 {
329 data->freq_table[i].index = i; 329 data->freq_table[i].driver_data = i;
330 if (i < data->acpi_data.state_count) { 330 if (i < data->acpi_data.state_count) {
331 data->freq_table[i].frequency = 331 data->freq_table[i].frequency =
332 data->acpi_data.states[i].core_frequency * 1000; 332 data->acpi_data.states[i].core_frequency * 1000;
diff --git a/drivers/cpufreq/imx6q-cpufreq.c b/drivers/cpufreq/imx6q-cpufreq.c
index b78bc35973ba..e37cdaedbb5b 100644
--- a/drivers/cpufreq/imx6q-cpufreq.c
+++ b/drivers/cpufreq/imx6q-cpufreq.c
@@ -68,8 +68,6 @@ static int imx6q_set_target(struct cpufreq_policy *policy,
68 if (freqs.old == freqs.new) 68 if (freqs.old == freqs.new)
69 return 0; 69 return 0;
70 70
71 cpufreq_notify_transition(policy, &freqs, CPUFREQ_PRECHANGE);
72
73 rcu_read_lock(); 71 rcu_read_lock();
74 opp = opp_find_freq_ceil(cpu_dev, &freq_hz); 72 opp = opp_find_freq_ceil(cpu_dev, &freq_hz);
75 if (IS_ERR(opp)) { 73 if (IS_ERR(opp)) {
@@ -86,13 +84,16 @@ static int imx6q_set_target(struct cpufreq_policy *policy,
86 freqs.old / 1000, volt_old / 1000, 84 freqs.old / 1000, volt_old / 1000,
87 freqs.new / 1000, volt / 1000); 85 freqs.new / 1000, volt / 1000);
88 86
87 cpufreq_notify_transition(policy, &freqs, CPUFREQ_PRECHANGE);
88
89 /* scaling up? scale voltage before frequency */ 89 /* scaling up? scale voltage before frequency */
90 if (freqs.new > freqs.old) { 90 if (freqs.new > freqs.old) {
91 ret = regulator_set_voltage_tol(arm_reg, volt, 0); 91 ret = regulator_set_voltage_tol(arm_reg, volt, 0);
92 if (ret) { 92 if (ret) {
93 dev_err(cpu_dev, 93 dev_err(cpu_dev,
94 "failed to scale vddarm up: %d\n", ret); 94 "failed to scale vddarm up: %d\n", ret);
95 return ret; 95 freqs.new = freqs.old;
96 goto post_notify;
96 } 97 }
97 98
98 /* 99 /*
@@ -145,15 +146,18 @@ static int imx6q_set_target(struct cpufreq_policy *policy,
145 if (ret) { 146 if (ret) {
146 dev_err(cpu_dev, "failed to set clock rate: %d\n", ret); 147 dev_err(cpu_dev, "failed to set clock rate: %d\n", ret);
147 regulator_set_voltage_tol(arm_reg, volt_old, 0); 148 regulator_set_voltage_tol(arm_reg, volt_old, 0);
148 return ret; 149 freqs.new = freqs.old;
150 goto post_notify;
149 } 151 }
150 152
151 /* scaling down? scale voltage after frequency */ 153 /* scaling down? scale voltage after frequency */
152 if (freqs.new < freqs.old) { 154 if (freqs.new < freqs.old) {
153 ret = regulator_set_voltage_tol(arm_reg, volt, 0); 155 ret = regulator_set_voltage_tol(arm_reg, volt, 0);
154 if (ret) 156 if (ret) {
155 dev_warn(cpu_dev, 157 dev_warn(cpu_dev,
156 "failed to scale vddarm down: %d\n", ret); 158 "failed to scale vddarm down: %d\n", ret);
159 ret = 0;
160 }
157 161
158 if (freqs.old == FREQ_1P2_GHZ / 1000) { 162 if (freqs.old == FREQ_1P2_GHZ / 1000) {
159 regulator_set_voltage_tol(pu_reg, 163 regulator_set_voltage_tol(pu_reg,
@@ -163,9 +167,10 @@ static int imx6q_set_target(struct cpufreq_policy *policy,
163 } 167 }
164 } 168 }
165 169
170post_notify:
166 cpufreq_notify_transition(policy, &freqs, CPUFREQ_POSTCHANGE); 171 cpufreq_notify_transition(policy, &freqs, CPUFREQ_POSTCHANGE);
167 172
168 return 0; 173 return ret;
169} 174}
170 175
171static int imx6q_cpufreq_init(struct cpufreq_policy *policy) 176static int imx6q_cpufreq_init(struct cpufreq_policy *policy)
diff --git a/drivers/cpufreq/kirkwood-cpufreq.c b/drivers/cpufreq/kirkwood-cpufreq.c
index b2644af985ec..c233ea617366 100644
--- a/drivers/cpufreq/kirkwood-cpufreq.c
+++ b/drivers/cpufreq/kirkwood-cpufreq.c
@@ -59,7 +59,7 @@ static void kirkwood_cpufreq_set_cpu_state(struct cpufreq_policy *policy,
59 unsigned int index) 59 unsigned int index)
60{ 60{
61 struct cpufreq_freqs freqs; 61 struct cpufreq_freqs freqs;
62 unsigned int state = kirkwood_freq_table[index].index; 62 unsigned int state = kirkwood_freq_table[index].driver_data;
63 unsigned long reg; 63 unsigned long reg;
64 64
65 freqs.old = kirkwood_cpufreq_get_cpu_frequency(0); 65 freqs.old = kirkwood_cpufreq_get_cpu_frequency(0);
diff --git a/drivers/cpufreq/longhaul.c b/drivers/cpufreq/longhaul.c
index b448638e34de..b6a0a7a406b0 100644
--- a/drivers/cpufreq/longhaul.c
+++ b/drivers/cpufreq/longhaul.c
@@ -254,7 +254,7 @@ static void longhaul_setstate(struct cpufreq_policy *policy,
254 u32 bm_timeout = 1000; 254 u32 bm_timeout = 1000;
255 unsigned int dir = 0; 255 unsigned int dir = 0;
256 256
257 mults_index = longhaul_table[table_index].index; 257 mults_index = longhaul_table[table_index].driver_data;
258 /* Safety precautions */ 258 /* Safety precautions */
259 mult = mults[mults_index & 0x1f]; 259 mult = mults[mults_index & 0x1f];
260 if (mult == -1) 260 if (mult == -1)
@@ -487,7 +487,7 @@ static int __cpuinit longhaul_get_ranges(void)
487 if (ratio > maxmult || ratio < minmult) 487 if (ratio > maxmult || ratio < minmult)
488 continue; 488 continue;
489 longhaul_table[k].frequency = calc_speed(ratio); 489 longhaul_table[k].frequency = calc_speed(ratio);
490 longhaul_table[k].index = j; 490 longhaul_table[k].driver_data = j;
491 k++; 491 k++;
492 } 492 }
493 if (k <= 1) { 493 if (k <= 1) {
@@ -508,8 +508,8 @@ static int __cpuinit longhaul_get_ranges(void)
508 if (min_i != j) { 508 if (min_i != j) {
509 swap(longhaul_table[j].frequency, 509 swap(longhaul_table[j].frequency,
510 longhaul_table[min_i].frequency); 510 longhaul_table[min_i].frequency);
511 swap(longhaul_table[j].index, 511 swap(longhaul_table[j].driver_data,
512 longhaul_table[min_i].index); 512 longhaul_table[min_i].driver_data);
513 } 513 }
514 } 514 }
515 515
@@ -517,7 +517,7 @@ static int __cpuinit longhaul_get_ranges(void)
517 517
518 /* Find index we are running on */ 518 /* Find index we are running on */
519 for (j = 0; j < k; j++) { 519 for (j = 0; j < k; j++) {
520 if (mults[longhaul_table[j].index & 0x1f] == mult) { 520 if (mults[longhaul_table[j].driver_data & 0x1f] == mult) {
521 longhaul_index = j; 521 longhaul_index = j;
522 break; 522 break;
523 } 523 }
@@ -613,7 +613,7 @@ static void __cpuinit longhaul_setup_voltagescaling(void)
613 pos = (speed - min_vid_speed) / kHz_step + minvid.pos; 613 pos = (speed - min_vid_speed) / kHz_step + minvid.pos;
614 else 614 else
615 pos = minvid.pos; 615 pos = minvid.pos;
616 longhaul_table[j].index |= mV_vrm_table[pos] << 8; 616 longhaul_table[j].driver_data |= mV_vrm_table[pos] << 8;
617 vid = vrm_mV_table[mV_vrm_table[pos]]; 617 vid = vrm_mV_table[mV_vrm_table[pos]];
618 printk(KERN_INFO PFX "f: %d kHz, index: %d, vid: %d mV\n", 618 printk(KERN_INFO PFX "f: %d kHz, index: %d, vid: %d mV\n",
619 speed, j, vid.mV); 619 speed, j, vid.mV);
@@ -656,12 +656,12 @@ static int longhaul_target(struct cpufreq_policy *policy,
656 * this in hardware, C3 is old and we need to do this 656 * this in hardware, C3 is old and we need to do this
657 * in software. */ 657 * in software. */
658 i = longhaul_index; 658 i = longhaul_index;
659 current_vid = (longhaul_table[longhaul_index].index >> 8); 659 current_vid = (longhaul_table[longhaul_index].driver_data >> 8);
660 current_vid &= 0x1f; 660 current_vid &= 0x1f;
661 if (table_index > longhaul_index) 661 if (table_index > longhaul_index)
662 dir = 1; 662 dir = 1;
663 while (i != table_index) { 663 while (i != table_index) {
664 vid = (longhaul_table[i].index >> 8) & 0x1f; 664 vid = (longhaul_table[i].driver_data >> 8) & 0x1f;
665 if (vid != current_vid) { 665 if (vid != current_vid) {
666 longhaul_setstate(policy, i); 666 longhaul_setstate(policy, i);
667 current_vid = vid; 667 current_vid = vid;
diff --git a/drivers/cpufreq/loongson2_cpufreq.c b/drivers/cpufreq/loongson2_cpufreq.c
index d53912768946..bb838b985077 100644
--- a/drivers/cpufreq/loongson2_cpufreq.c
+++ b/drivers/cpufreq/loongson2_cpufreq.c
@@ -72,7 +72,7 @@ static int loongson2_cpufreq_target(struct cpufreq_policy *policy,
72 72
73 freq = 73 freq =
74 ((cpu_clock_freq / 1000) * 74 ((cpu_clock_freq / 1000) *
75 loongson2_clockmod_table[newstate].index) / 8; 75 loongson2_clockmod_table[newstate].driver_data) / 8;
76 if (freq < policy->min || freq > policy->max) 76 if (freq < policy->min || freq > policy->max)
77 return -EINVAL; 77 return -EINVAL;
78 78
diff --git a/drivers/cpufreq/omap-cpufreq.c b/drivers/cpufreq/omap-cpufreq.c
index 0279d18a57f9..29468a522ee9 100644
--- a/drivers/cpufreq/omap-cpufreq.c
+++ b/drivers/cpufreq/omap-cpufreq.c
@@ -93,9 +93,6 @@ static int omap_target(struct cpufreq_policy *policy,
93 if (freqs.old == freqs.new && policy->cur == freqs.new) 93 if (freqs.old == freqs.new && policy->cur == freqs.new)
94 return ret; 94 return ret;
95 95
96 /* notifiers */
97 cpufreq_notify_transition(policy, &freqs, CPUFREQ_PRECHANGE);
98
99 freq = freqs.new * 1000; 96 freq = freqs.new * 1000;
100 ret = clk_round_rate(mpu_clk, freq); 97 ret = clk_round_rate(mpu_clk, freq);
101 if (IS_ERR_VALUE(ret)) { 98 if (IS_ERR_VALUE(ret)) {
@@ -125,6 +122,9 @@ static int omap_target(struct cpufreq_policy *policy,
125 freqs.old / 1000, volt_old ? volt_old / 1000 : -1, 122 freqs.old / 1000, volt_old ? volt_old / 1000 : -1,
126 freqs.new / 1000, volt ? volt / 1000 : -1); 123 freqs.new / 1000, volt ? volt / 1000 : -1);
127 124
125 /* notifiers */
126 cpufreq_notify_transition(policy, &freqs, CPUFREQ_PRECHANGE);
127
128 /* scaling up? scale voltage before frequency */ 128 /* scaling up? scale voltage before frequency */
129 if (mpu_reg && (freqs.new > freqs.old)) { 129 if (mpu_reg && (freqs.new > freqs.old)) {
130 r = regulator_set_voltage(mpu_reg, volt - tol, volt + tol); 130 r = regulator_set_voltage(mpu_reg, volt - tol, volt + tol);
diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
index 421ef37d0bb3..9ee78170ff86 100644
--- a/drivers/cpufreq/p4-clockmod.c
+++ b/drivers/cpufreq/p4-clockmod.c
@@ -118,7 +118,7 @@ static int cpufreq_p4_target(struct cpufreq_policy *policy,
118 return -EINVAL; 118 return -EINVAL;
119 119
120 freqs.old = cpufreq_p4_get(policy->cpu); 120 freqs.old = cpufreq_p4_get(policy->cpu);
121 freqs.new = stock_freq * p4clockmod_table[newstate].index / 8; 121 freqs.new = stock_freq * p4clockmod_table[newstate].driver_data / 8;
122 122
123 if (freqs.new == freqs.old) 123 if (freqs.new == freqs.old)
124 return 0; 124 return 0;
@@ -131,7 +131,7 @@ static int cpufreq_p4_target(struct cpufreq_policy *policy,
131 * Developer's Manual, Volume 3 131 * Developer's Manual, Volume 3
132 */ 132 */
133 for_each_cpu(i, policy->cpus) 133 for_each_cpu(i, policy->cpus)
134 cpufreq_p4_setdc(i, p4clockmod_table[newstate].index); 134 cpufreq_p4_setdc(i, p4clockmod_table[newstate].driver_data);
135 135
136 /* notifiers */ 136 /* notifiers */
137 cpufreq_notify_transition(policy, &freqs, CPUFREQ_POSTCHANGE); 137 cpufreq_notify_transition(policy, &freqs, CPUFREQ_POSTCHANGE);
diff --git a/drivers/cpufreq/pasemi-cpufreq.c b/drivers/cpufreq/pasemi-cpufreq.c
new file mode 100644
index 000000000000..b704da404067
--- /dev/null
+++ b/drivers/cpufreq/pasemi-cpufreq.c
@@ -0,0 +1,331 @@
1/*
2 * Copyright (C) 2007 PA Semi, Inc
3 *
4 * Authors: Egor Martovetsky <egor@pasemi.com>
5 * Olof Johansson <olof@lixom.net>
6 *
7 * Maintained by: Olof Johansson <olof@lixom.net>
8 *
9 * Based on arch/powerpc/platforms/cell/cbe_cpufreq.c:
10 * (C) Copyright IBM Deutschland Entwicklung GmbH 2005
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2, or (at your option)
15 * any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 *
26 */
27
28#include <linux/cpufreq.h>
29#include <linux/timer.h>
30#include <linux/module.h>
31
32#include <asm/hw_irq.h>
33#include <asm/io.h>
34#include <asm/prom.h>
35#include <asm/time.h>
36#include <asm/smp.h>
37
38#define SDCASR_REG 0x0100
39#define SDCASR_REG_STRIDE 0x1000
40#define SDCPWR_CFGA0_REG 0x0100
41#define SDCPWR_PWST0_REG 0x0000
42#define SDCPWR_GIZTIME_REG 0x0440
43
44/* SDCPWR_GIZTIME_REG fields */
45#define SDCPWR_GIZTIME_GR 0x80000000
46#define SDCPWR_GIZTIME_LONGLOCK 0x000000ff
47
48/* Offset of ASR registers from SDC base */
49#define SDCASR_OFFSET 0x120000
50
51static void __iomem *sdcpwr_mapbase;
52static void __iomem *sdcasr_mapbase;
53
54static DEFINE_MUTEX(pas_switch_mutex);
55
56/* Current astate, is used when waking up from power savings on
57 * one core, in case the other core has switched states during
58 * the idle time.
59 */
60static int current_astate;
61
62/* We support 5(A0-A4) power states excluding turbo(A5-A6) modes */
63static struct cpufreq_frequency_table pas_freqs[] = {
64 {0, 0},
65 {1, 0},
66 {2, 0},
67 {3, 0},
68 {4, 0},
69 {0, CPUFREQ_TABLE_END},
70};
71
72static struct freq_attr *pas_cpu_freqs_attr[] = {
73 &cpufreq_freq_attr_scaling_available_freqs,
74 NULL,
75};
76
77/*
78 * hardware specific functions
79 */
80
81static int get_astate_freq(int astate)
82{
83 u32 ret;
84 ret = in_le32(sdcpwr_mapbase + SDCPWR_CFGA0_REG + (astate * 0x10));
85
86 return ret & 0x3f;
87}
88
89static int get_cur_astate(int cpu)
90{
91 u32 ret;
92
93 ret = in_le32(sdcpwr_mapbase + SDCPWR_PWST0_REG);
94 ret = (ret >> (cpu * 4)) & 0x7;
95
96 return ret;
97}
98
99static int get_gizmo_latency(void)
100{
101 u32 giztime, ret;
102
103 giztime = in_le32(sdcpwr_mapbase + SDCPWR_GIZTIME_REG);
104
105 /* just provide the upper bound */
106 if (giztime & SDCPWR_GIZTIME_GR)
107 ret = (giztime & SDCPWR_GIZTIME_LONGLOCK) * 128000;
108 else
109 ret = (giztime & SDCPWR_GIZTIME_LONGLOCK) * 1000;
110
111 return ret;
112}
113
114static void set_astate(int cpu, unsigned int astate)
115{
116 unsigned long flags;
117
118 /* Return if called before init has run */
119 if (unlikely(!sdcasr_mapbase))
120 return;
121
122 local_irq_save(flags);
123
124 out_le32(sdcasr_mapbase + SDCASR_REG + SDCASR_REG_STRIDE*cpu, astate);
125
126 local_irq_restore(flags);
127}
128
129int check_astate(void)
130{
131 return get_cur_astate(hard_smp_processor_id());
132}
133
134void restore_astate(int cpu)
135{
136 set_astate(cpu, current_astate);
137}
138
139/*
140 * cpufreq functions
141 */
142
143static int pas_cpufreq_cpu_init(struct cpufreq_policy *policy)
144{
145 const u32 *max_freqp;
146 u32 max_freq;
147 int i, cur_astate;
148 struct resource res;
149 struct device_node *cpu, *dn;
150 int err = -ENODEV;
151
152 cpu = of_get_cpu_node(policy->cpu, NULL);
153
154 if (!cpu)
155 goto out;
156
157 dn = of_find_compatible_node(NULL, NULL, "1682m-sdc");
158 if (!dn)
159 dn = of_find_compatible_node(NULL, NULL,
160 "pasemi,pwrficient-sdc");
161 if (!dn)
162 goto out;
163 err = of_address_to_resource(dn, 0, &res);
164 of_node_put(dn);
165 if (err)
166 goto out;
167 sdcasr_mapbase = ioremap(res.start + SDCASR_OFFSET, 0x2000);
168 if (!sdcasr_mapbase) {
169 err = -EINVAL;
170 goto out;
171 }
172
173 dn = of_find_compatible_node(NULL, NULL, "1682m-gizmo");
174 if (!dn)
175 dn = of_find_compatible_node(NULL, NULL,
176 "pasemi,pwrficient-gizmo");
177 if (!dn) {
178 err = -ENODEV;
179 goto out_unmap_sdcasr;
180 }
181 err = of_address_to_resource(dn, 0, &res);
182 of_node_put(dn);
183 if (err)
184 goto out_unmap_sdcasr;
185 sdcpwr_mapbase = ioremap(res.start, 0x1000);
186 if (!sdcpwr_mapbase) {
187 err = -EINVAL;
188 goto out_unmap_sdcasr;
189 }
190
191 pr_debug("init cpufreq on CPU %d\n", policy->cpu);
192
193 max_freqp = of_get_property(cpu, "clock-frequency", NULL);
194 if (!max_freqp) {
195 err = -EINVAL;
196 goto out_unmap_sdcpwr;
197 }
198
199 /* we need the freq in kHz */
200 max_freq = *max_freqp / 1000;
201
202 pr_debug("max clock-frequency is at %u kHz\n", max_freq);
203 pr_debug("initializing frequency table\n");
204
205 /* initialize frequency table */
206 for (i=0; pas_freqs[i].frequency!=CPUFREQ_TABLE_END; i++) {
207 pas_freqs[i].frequency =
208 get_astate_freq(pas_freqs[i].driver_data) * 100000;
209 pr_debug("%d: %d\n", i, pas_freqs[i].frequency);
210 }
211
212 policy->cpuinfo.transition_latency = get_gizmo_latency();
213
214 cur_astate = get_cur_astate(policy->cpu);
215 pr_debug("current astate is at %d\n",cur_astate);
216
217 policy->cur = pas_freqs[cur_astate].frequency;
218 cpumask_copy(policy->cpus, cpu_online_mask);
219
220 ppc_proc_freq = policy->cur * 1000ul;
221
222 cpufreq_frequency_table_get_attr(pas_freqs, policy->cpu);
223
224 /* this ensures that policy->cpuinfo_min and policy->cpuinfo_max
225 * are set correctly
226 */
227 return cpufreq_frequency_table_cpuinfo(policy, pas_freqs);
228
229out_unmap_sdcpwr:
230 iounmap(sdcpwr_mapbase);
231
232out_unmap_sdcasr:
233 iounmap(sdcasr_mapbase);
234out:
235 return err;
236}
237
238static int pas_cpufreq_cpu_exit(struct cpufreq_policy *policy)
239{
240 /*
241 * We don't support CPU hotplug. Don't unmap after the system
242 * has already made it to a running state.
243 */
244 if (system_state != SYSTEM_BOOTING)
245 return 0;
246
247 if (sdcasr_mapbase)
248 iounmap(sdcasr_mapbase);
249 if (sdcpwr_mapbase)
250 iounmap(sdcpwr_mapbase);
251
252 cpufreq_frequency_table_put_attr(policy->cpu);
253 return 0;
254}
255
256static int pas_cpufreq_verify(struct cpufreq_policy *policy)
257{
258 return cpufreq_frequency_table_verify(policy, pas_freqs);
259}
260
261static int pas_cpufreq_target(struct cpufreq_policy *policy,
262 unsigned int target_freq,
263 unsigned int relation)
264{
265 struct cpufreq_freqs freqs;
266 int pas_astate_new;
267 int i;
268
269 cpufreq_frequency_table_target(policy,
270 pas_freqs,
271 target_freq,
272 relation,
273 &pas_astate_new);
274
275 freqs.old = policy->cur;
276 freqs.new = pas_freqs[pas_astate_new].frequency;
277
278 mutex_lock(&pas_switch_mutex);
279 cpufreq_notify_transition(policy, &freqs, CPUFREQ_PRECHANGE);
280
281 pr_debug("setting frequency for cpu %d to %d kHz, 1/%d of max frequency\n",
282 policy->cpu,
283 pas_freqs[pas_astate_new].frequency,
284 pas_freqs[pas_astate_new].driver_data);
285
286 current_astate = pas_astate_new;
287
288 for_each_online_cpu(i)
289 set_astate(i, pas_astate_new);
290
291 cpufreq_notify_transition(policy, &freqs, CPUFREQ_POSTCHANGE);
292 mutex_unlock(&pas_switch_mutex);
293
294 ppc_proc_freq = freqs.new * 1000ul;
295 return 0;
296}
297
298static struct cpufreq_driver pas_cpufreq_driver = {
299 .name = "pas-cpufreq",
300 .owner = THIS_MODULE,
301 .flags = CPUFREQ_CONST_LOOPS,
302 .init = pas_cpufreq_cpu_init,
303 .exit = pas_cpufreq_cpu_exit,
304 .verify = pas_cpufreq_verify,
305 .target = pas_cpufreq_target,
306 .attr = pas_cpu_freqs_attr,
307};
308
309/*
310 * module init and destoy
311 */
312
313static int __init pas_cpufreq_init(void)
314{
315 if (!of_machine_is_compatible("PA6T-1682M") &&
316 !of_machine_is_compatible("pasemi,pwrficient"))
317 return -ENODEV;
318
319 return cpufreq_register_driver(&pas_cpufreq_driver);
320}
321
322static void __exit pas_cpufreq_exit(void)
323{
324 cpufreq_unregister_driver(&pas_cpufreq_driver);
325}
326
327module_init(pas_cpufreq_init);
328module_exit(pas_cpufreq_exit);
329
330MODULE_LICENSE("GPL");
331MODULE_AUTHOR("Egor Martovetsky <egor@pasemi.com>, Olof Johansson <olof@lixom.net>");
diff --git a/drivers/cpufreq/pcc-cpufreq.c b/drivers/cpufreq/pcc-cpufreq.c
index 0de00081a81e..1581fcc4cf4a 100644
--- a/drivers/cpufreq/pcc-cpufreq.c
+++ b/drivers/cpufreq/pcc-cpufreq.c
@@ -243,6 +243,8 @@ static int pcc_cpufreq_target(struct cpufreq_policy *policy,
243 return 0; 243 return 0;
244 244
245cmd_incomplete: 245cmd_incomplete:
246 freqs.new = freqs.old;
247 cpufreq_notify_transition(policy, &freqs, CPUFREQ_POSTCHANGE);
246 iowrite16(0, &pcch_hdr->status); 248 iowrite16(0, &pcch_hdr->status);
247 spin_unlock(&pcc_lock); 249 spin_unlock(&pcc_lock);
248 return -EINVAL; 250 return -EINVAL;
diff --git a/drivers/cpufreq/pmac32-cpufreq.c b/drivers/cpufreq/pmac32-cpufreq.c
new file mode 100644
index 000000000000..3104fad82480
--- /dev/null
+++ b/drivers/cpufreq/pmac32-cpufreq.c
@@ -0,0 +1,721 @@
1/*
2 * Copyright (C) 2002 - 2005 Benjamin Herrenschmidt <benh@kernel.crashing.org>
3 * Copyright (C) 2004 John Steele Scott <toojays@toojays.net>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 *
9 * TODO: Need a big cleanup here. Basically, we need to have different
10 * cpufreq_driver structures for the different type of HW instead of the
11 * current mess. We also need to better deal with the detection of the
12 * type of machine.
13 *
14 */
15
16#include <linux/module.h>
17#include <linux/types.h>
18#include <linux/errno.h>
19#include <linux/kernel.h>
20#include <linux/delay.h>
21#include <linux/sched.h>
22#include <linux/adb.h>
23#include <linux/pmu.h>
24#include <linux/cpufreq.h>
25#include <linux/init.h>
26#include <linux/device.h>
27#include <linux/hardirq.h>
28#include <asm/prom.h>
29#include <asm/machdep.h>
30#include <asm/irq.h>
31#include <asm/pmac_feature.h>
32#include <asm/mmu_context.h>
33#include <asm/sections.h>
34#include <asm/cputable.h>
35#include <asm/time.h>
36#include <asm/mpic.h>
37#include <asm/keylargo.h>
38#include <asm/switch_to.h>
39
40/* WARNING !!! This will cause calibrate_delay() to be called,
41 * but this is an __init function ! So you MUST go edit
42 * init/main.c to make it non-init before enabling DEBUG_FREQ
43 */
44#undef DEBUG_FREQ
45
46extern void low_choose_7447a_dfs(int dfs);
47extern void low_choose_750fx_pll(int pll);
48extern void low_sleep_handler(void);
49
50/*
51 * Currently, PowerMac cpufreq supports only high & low frequencies
52 * that are set by the firmware
53 */
54static unsigned int low_freq;
55static unsigned int hi_freq;
56static unsigned int cur_freq;
57static unsigned int sleep_freq;
58static unsigned long transition_latency;
59
60/*
61 * Different models uses different mechanisms to switch the frequency
62 */
63static int (*set_speed_proc)(int low_speed);
64static unsigned int (*get_speed_proc)(void);
65
66/*
67 * Some definitions used by the various speedprocs
68 */
69static u32 voltage_gpio;
70static u32 frequency_gpio;
71static u32 slew_done_gpio;
72static int no_schedule;
73static int has_cpu_l2lve;
74static int is_pmu_based;
75
76/* There are only two frequency states for each processor. Values
77 * are in kHz for the time being.
78 */
79#define CPUFREQ_HIGH 0
80#define CPUFREQ_LOW 1
81
82static struct cpufreq_frequency_table pmac_cpu_freqs[] = {
83 {CPUFREQ_HIGH, 0},
84 {CPUFREQ_LOW, 0},
85 {0, CPUFREQ_TABLE_END},
86};
87
88static struct freq_attr* pmac_cpu_freqs_attr[] = {
89 &cpufreq_freq_attr_scaling_available_freqs,
90 NULL,
91};
92
93static inline void local_delay(unsigned long ms)
94{
95 if (no_schedule)
96 mdelay(ms);
97 else
98 msleep(ms);
99}
100
101#ifdef DEBUG_FREQ
102static inline void debug_calc_bogomips(void)
103{
104 /* This will cause a recalc of bogomips and display the
105 * result. We backup/restore the value to avoid affecting the
106 * core cpufreq framework's own calculation.
107 */
108 unsigned long save_lpj = loops_per_jiffy;
109 calibrate_delay();
110 loops_per_jiffy = save_lpj;
111}
112#endif /* DEBUG_FREQ */
113
114/* Switch CPU speed under 750FX CPU control
115 */
116static int cpu_750fx_cpu_speed(int low_speed)
117{
118 u32 hid2;
119
120 if (low_speed == 0) {
121 /* ramping up, set voltage first */
122 pmac_call_feature(PMAC_FTR_WRITE_GPIO, NULL, voltage_gpio, 0x05);
123 /* Make sure we sleep for at least 1ms */
124 local_delay(10);
125
126 /* tweak L2 for high voltage */
127 if (has_cpu_l2lve) {
128 hid2 = mfspr(SPRN_HID2);
129 hid2 &= ~0x2000;
130 mtspr(SPRN_HID2, hid2);
131 }
132 }
133#ifdef CONFIG_6xx
134 low_choose_750fx_pll(low_speed);
135#endif
136 if (low_speed == 1) {
137 /* tweak L2 for low voltage */
138 if (has_cpu_l2lve) {
139 hid2 = mfspr(SPRN_HID2);
140 hid2 |= 0x2000;
141 mtspr(SPRN_HID2, hid2);
142 }
143
144 /* ramping down, set voltage last */
145 pmac_call_feature(PMAC_FTR_WRITE_GPIO, NULL, voltage_gpio, 0x04);
146 local_delay(10);
147 }
148
149 return 0;
150}
151
152static unsigned int cpu_750fx_get_cpu_speed(void)
153{
154 if (mfspr(SPRN_HID1) & HID1_PS)
155 return low_freq;
156 else
157 return hi_freq;
158}
159
160/* Switch CPU speed using DFS */
161static int dfs_set_cpu_speed(int low_speed)
162{
163 if (low_speed == 0) {
164 /* ramping up, set voltage first */
165 pmac_call_feature(PMAC_FTR_WRITE_GPIO, NULL, voltage_gpio, 0x05);
166 /* Make sure we sleep for at least 1ms */
167 local_delay(1);
168 }
169
170 /* set frequency */
171#ifdef CONFIG_6xx
172 low_choose_7447a_dfs(low_speed);
173#endif
174 udelay(100);
175
176 if (low_speed == 1) {
177 /* ramping down, set voltage last */
178 pmac_call_feature(PMAC_FTR_WRITE_GPIO, NULL, voltage_gpio, 0x04);
179 local_delay(1);
180 }
181
182 return 0;
183}
184
185static unsigned int dfs_get_cpu_speed(void)
186{
187 if (mfspr(SPRN_HID1) & HID1_DFS)
188 return low_freq;
189 else
190 return hi_freq;
191}
192
193
194/* Switch CPU speed using slewing GPIOs
195 */
196static int gpios_set_cpu_speed(int low_speed)
197{
198 int gpio, timeout = 0;
199
200 /* If ramping up, set voltage first */
201 if (low_speed == 0) {
202 pmac_call_feature(PMAC_FTR_WRITE_GPIO, NULL, voltage_gpio, 0x05);
203 /* Delay is way too big but it's ok, we schedule */
204 local_delay(10);
205 }
206
207 /* Set frequency */
208 gpio = pmac_call_feature(PMAC_FTR_READ_GPIO, NULL, frequency_gpio, 0);
209 if (low_speed == ((gpio & 0x01) == 0))
210 goto skip;
211
212 pmac_call_feature(PMAC_FTR_WRITE_GPIO, NULL, frequency_gpio,
213 low_speed ? 0x04 : 0x05);
214 udelay(200);
215 do {
216 if (++timeout > 100)
217 break;
218 local_delay(1);
219 gpio = pmac_call_feature(PMAC_FTR_READ_GPIO, NULL, slew_done_gpio, 0);
220 } while((gpio & 0x02) == 0);
221 skip:
222 /* If ramping down, set voltage last */
223 if (low_speed == 1) {
224 pmac_call_feature(PMAC_FTR_WRITE_GPIO, NULL, voltage_gpio, 0x04);
225 /* Delay is way too big but it's ok, we schedule */
226 local_delay(10);
227 }
228
229#ifdef DEBUG_FREQ
230 debug_calc_bogomips();
231#endif
232
233 return 0;
234}
235
236/* Switch CPU speed under PMU control
237 */
238static int pmu_set_cpu_speed(int low_speed)
239{
240 struct adb_request req;
241 unsigned long save_l2cr;
242 unsigned long save_l3cr;
243 unsigned int pic_prio;
244 unsigned long flags;
245
246 preempt_disable();
247
248#ifdef DEBUG_FREQ
249 printk(KERN_DEBUG "HID1, before: %x\n", mfspr(SPRN_HID1));
250#endif
251 pmu_suspend();
252
253 /* Disable all interrupt sources on openpic */
254 pic_prio = mpic_cpu_get_priority();
255 mpic_cpu_set_priority(0xf);
256
257 /* Make sure the decrementer won't interrupt us */
258 asm volatile("mtdec %0" : : "r" (0x7fffffff));
259 /* Make sure any pending DEC interrupt occurring while we did
260 * the above didn't re-enable the DEC */
261 mb();
262 asm volatile("mtdec %0" : : "r" (0x7fffffff));
263
264 /* We can now disable MSR_EE */
265 local_irq_save(flags);
266
267 /* Giveup the FPU & vec */
268 enable_kernel_fp();
269
270#ifdef CONFIG_ALTIVEC
271 if (cpu_has_feature(CPU_FTR_ALTIVEC))
272 enable_kernel_altivec();
273#endif /* CONFIG_ALTIVEC */
274
275 /* Save & disable L2 and L3 caches */
276 save_l3cr = _get_L3CR(); /* (returns -1 if not available) */
277 save_l2cr = _get_L2CR(); /* (returns -1 if not available) */
278
279 /* Send the new speed command. My assumption is that this command
280 * will cause PLL_CFG[0..3] to be changed next time CPU goes to sleep
281 */
282 pmu_request(&req, NULL, 6, PMU_CPU_SPEED, 'W', 'O', 'O', 'F', low_speed);
283 while (!req.complete)
284 pmu_poll();
285
286 /* Prepare the northbridge for the speed transition */
287 pmac_call_feature(PMAC_FTR_SLEEP_STATE,NULL,1,1);
288
289 /* Call low level code to backup CPU state and recover from
290 * hardware reset
291 */
292 low_sleep_handler();
293
294 /* Restore the northbridge */
295 pmac_call_feature(PMAC_FTR_SLEEP_STATE,NULL,1,0);
296
297 /* Restore L2 cache */
298 if (save_l2cr != 0xffffffff && (save_l2cr & L2CR_L2E) != 0)
299 _set_L2CR(save_l2cr);
300 /* Restore L3 cache */
301 if (save_l3cr != 0xffffffff && (save_l3cr & L3CR_L3E) != 0)
302 _set_L3CR(save_l3cr);
303
304 /* Restore userland MMU context */
305 switch_mmu_context(NULL, current->active_mm);
306
307#ifdef DEBUG_FREQ
308 printk(KERN_DEBUG "HID1, after: %x\n", mfspr(SPRN_HID1));
309#endif
310
311 /* Restore low level PMU operations */
312 pmu_unlock();
313
314 /*
315 * Restore decrementer; we'll take a decrementer interrupt
316 * as soon as interrupts are re-enabled and the generic
317 * clockevents code will reprogram it with the right value.
318 */
319 set_dec(1);
320
321 /* Restore interrupts */
322 mpic_cpu_set_priority(pic_prio);
323
324 /* Let interrupts flow again ... */
325 local_irq_restore(flags);
326
327#ifdef DEBUG_FREQ
328 debug_calc_bogomips();
329#endif
330
331 pmu_resume();
332
333 preempt_enable();
334
335 return 0;
336}
337
338static int do_set_cpu_speed(struct cpufreq_policy *policy, int speed_mode,
339 int notify)
340{
341 struct cpufreq_freqs freqs;
342 unsigned long l3cr;
343 static unsigned long prev_l3cr;
344
345 freqs.old = cur_freq;
346 freqs.new = (speed_mode == CPUFREQ_HIGH) ? hi_freq : low_freq;
347
348 if (freqs.old == freqs.new)
349 return 0;
350
351 if (notify)
352 cpufreq_notify_transition(policy, &freqs, CPUFREQ_PRECHANGE);
353 if (speed_mode == CPUFREQ_LOW &&
354 cpu_has_feature(CPU_FTR_L3CR)) {
355 l3cr = _get_L3CR();
356 if (l3cr & L3CR_L3E) {
357 prev_l3cr = l3cr;
358 _set_L3CR(0);
359 }
360 }
361 set_speed_proc(speed_mode == CPUFREQ_LOW);
362 if (speed_mode == CPUFREQ_HIGH &&
363 cpu_has_feature(CPU_FTR_L3CR)) {
364 l3cr = _get_L3CR();
365 if ((prev_l3cr & L3CR_L3E) && l3cr != prev_l3cr)
366 _set_L3CR(prev_l3cr);
367 }
368 if (notify)
369 cpufreq_notify_transition(policy, &freqs, CPUFREQ_POSTCHANGE);
370 cur_freq = (speed_mode == CPUFREQ_HIGH) ? hi_freq : low_freq;
371
372 return 0;
373}
374
375static unsigned int pmac_cpufreq_get_speed(unsigned int cpu)
376{
377 return cur_freq;
378}
379
380static int pmac_cpufreq_verify(struct cpufreq_policy *policy)
381{
382 return cpufreq_frequency_table_verify(policy, pmac_cpu_freqs);
383}
384
385static int pmac_cpufreq_target( struct cpufreq_policy *policy,
386 unsigned int target_freq,
387 unsigned int relation)
388{
389 unsigned int newstate = 0;
390 int rc;
391
392 if (cpufreq_frequency_table_target(policy, pmac_cpu_freqs,
393 target_freq, relation, &newstate))
394 return -EINVAL;
395
396 rc = do_set_cpu_speed(policy, newstate, 1);
397
398 ppc_proc_freq = cur_freq * 1000ul;
399 return rc;
400}
401
402static int pmac_cpufreq_cpu_init(struct cpufreq_policy *policy)
403{
404 if (policy->cpu != 0)
405 return -ENODEV;
406
407 policy->cpuinfo.transition_latency = transition_latency;
408 policy->cur = cur_freq;
409
410 cpufreq_frequency_table_get_attr(pmac_cpu_freqs, policy->cpu);
411 return cpufreq_frequency_table_cpuinfo(policy, pmac_cpu_freqs);
412}
413
414static u32 read_gpio(struct device_node *np)
415{
416 const u32 *reg = of_get_property(np, "reg", NULL);
417 u32 offset;
418
419 if (reg == NULL)
420 return 0;
421 /* That works for all keylargos but shall be fixed properly
422 * some day... The problem is that it seems we can't rely
423 * on the "reg" property of the GPIO nodes, they are either
424 * relative to the base of KeyLargo or to the base of the
425 * GPIO space, and the device-tree doesn't help.
426 */
427 offset = *reg;
428 if (offset < KEYLARGO_GPIO_LEVELS0)
429 offset += KEYLARGO_GPIO_LEVELS0;
430 return offset;
431}
432
433static int pmac_cpufreq_suspend(struct cpufreq_policy *policy)
434{
435 /* Ok, this could be made a bit smarter, but let's be robust for now. We
436 * always force a speed change to high speed before sleep, to make sure
437 * we have appropriate voltage and/or bus speed for the wakeup process,
438 * and to make sure our loops_per_jiffies are "good enough", that is will
439 * not cause too short delays if we sleep in low speed and wake in high
440 * speed..
441 */
442 no_schedule = 1;
443 sleep_freq = cur_freq;
444 if (cur_freq == low_freq && !is_pmu_based)
445 do_set_cpu_speed(policy, CPUFREQ_HIGH, 0);
446 return 0;
447}
448
449static int pmac_cpufreq_resume(struct cpufreq_policy *policy)
450{
451 /* If we resume, first check if we have a get() function */
452 if (get_speed_proc)
453 cur_freq = get_speed_proc();
454 else
455 cur_freq = 0;
456
457 /* We don't, hrm... we don't really know our speed here, best
458 * is that we force a switch to whatever it was, which is
459 * probably high speed due to our suspend() routine
460 */
461 do_set_cpu_speed(policy, sleep_freq == low_freq ?
462 CPUFREQ_LOW : CPUFREQ_HIGH, 0);
463
464 ppc_proc_freq = cur_freq * 1000ul;
465
466 no_schedule = 0;
467 return 0;
468}
469
470static struct cpufreq_driver pmac_cpufreq_driver = {
471 .verify = pmac_cpufreq_verify,
472 .target = pmac_cpufreq_target,
473 .get = pmac_cpufreq_get_speed,
474 .init = pmac_cpufreq_cpu_init,
475 .suspend = pmac_cpufreq_suspend,
476 .resume = pmac_cpufreq_resume,
477 .flags = CPUFREQ_PM_NO_WARN,
478 .attr = pmac_cpu_freqs_attr,
479 .name = "powermac",
480 .owner = THIS_MODULE,
481};
482
483
484static int pmac_cpufreq_init_MacRISC3(struct device_node *cpunode)
485{
486 struct device_node *volt_gpio_np = of_find_node_by_name(NULL,
487 "voltage-gpio");
488 struct device_node *freq_gpio_np = of_find_node_by_name(NULL,
489 "frequency-gpio");
490 struct device_node *slew_done_gpio_np = of_find_node_by_name(NULL,
491 "slewing-done");
492 const u32 *value;
493
494 /*
495 * Check to see if it's GPIO driven or PMU only
496 *
497 * The way we extract the GPIO address is slightly hackish, but it
498 * works well enough for now. We need to abstract the whole GPIO
499 * stuff sooner or later anyway
500 */
501
502 if (volt_gpio_np)
503 voltage_gpio = read_gpio(volt_gpio_np);
504 if (freq_gpio_np)
505 frequency_gpio = read_gpio(freq_gpio_np);
506 if (slew_done_gpio_np)
507 slew_done_gpio = read_gpio(slew_done_gpio_np);
508
509 /* If we use the frequency GPIOs, calculate the min/max speeds based
510 * on the bus frequencies
511 */
512 if (frequency_gpio && slew_done_gpio) {
513 int lenp, rc;
514 const u32 *freqs, *ratio;
515
516 freqs = of_get_property(cpunode, "bus-frequencies", &lenp);
517 lenp /= sizeof(u32);
518 if (freqs == NULL || lenp != 2) {
519 printk(KERN_ERR "cpufreq: bus-frequencies incorrect or missing\n");
520 return 1;
521 }
522 ratio = of_get_property(cpunode, "processor-to-bus-ratio*2",
523 NULL);
524 if (ratio == NULL) {
525 printk(KERN_ERR "cpufreq: processor-to-bus-ratio*2 missing\n");
526 return 1;
527 }
528
529 /* Get the min/max bus frequencies */
530 low_freq = min(freqs[0], freqs[1]);
531 hi_freq = max(freqs[0], freqs[1]);
532
533 /* Grrrr.. It _seems_ that the device-tree is lying on the low bus
534 * frequency, it claims it to be around 84Mhz on some models while
535 * it appears to be approx. 101Mhz on all. Let's hack around here...
536 * fortunately, we don't need to be too precise
537 */
538 if (low_freq < 98000000)
539 low_freq = 101000000;
540
541 /* Convert those to CPU core clocks */
542 low_freq = (low_freq * (*ratio)) / 2000;
543 hi_freq = (hi_freq * (*ratio)) / 2000;
544
545 /* Now we get the frequencies, we read the GPIO to see what is out current
546 * speed
547 */
548 rc = pmac_call_feature(PMAC_FTR_READ_GPIO, NULL, frequency_gpio, 0);
549 cur_freq = (rc & 0x01) ? hi_freq : low_freq;
550
551 set_speed_proc = gpios_set_cpu_speed;
552 return 1;
553 }
554
555 /* If we use the PMU, look for the min & max frequencies in the
556 * device-tree
557 */
558 value = of_get_property(cpunode, "min-clock-frequency", NULL);
559 if (!value)
560 return 1;
561 low_freq = (*value) / 1000;
562 /* The PowerBook G4 12" (PowerBook6,1) has an error in the device-tree
563 * here */
564 if (low_freq < 100000)
565 low_freq *= 10;
566
567 value = of_get_property(cpunode, "max-clock-frequency", NULL);
568 if (!value)
569 return 1;
570 hi_freq = (*value) / 1000;
571 set_speed_proc = pmu_set_cpu_speed;
572 is_pmu_based = 1;
573
574 return 0;
575}
576
577static int pmac_cpufreq_init_7447A(struct device_node *cpunode)
578{
579 struct device_node *volt_gpio_np;
580
581 if (of_get_property(cpunode, "dynamic-power-step", NULL) == NULL)
582 return 1;
583
584 volt_gpio_np = of_find_node_by_name(NULL, "cpu-vcore-select");
585 if (volt_gpio_np)
586 voltage_gpio = read_gpio(volt_gpio_np);
587 if (!voltage_gpio){
588 printk(KERN_ERR "cpufreq: missing cpu-vcore-select gpio\n");
589 return 1;
590 }
591
592 /* OF only reports the high frequency */
593 hi_freq = cur_freq;
594 low_freq = cur_freq/2;
595
596 /* Read actual frequency from CPU */
597 cur_freq = dfs_get_cpu_speed();
598 set_speed_proc = dfs_set_cpu_speed;
599 get_speed_proc = dfs_get_cpu_speed;
600
601 return 0;
602}
603
604static int pmac_cpufreq_init_750FX(struct device_node *cpunode)
605{
606 struct device_node *volt_gpio_np;
607 u32 pvr;
608 const u32 *value;
609
610 if (of_get_property(cpunode, "dynamic-power-step", NULL) == NULL)
611 return 1;
612
613 hi_freq = cur_freq;
614 value = of_get_property(cpunode, "reduced-clock-frequency", NULL);
615 if (!value)
616 return 1;
617 low_freq = (*value) / 1000;
618
619 volt_gpio_np = of_find_node_by_name(NULL, "cpu-vcore-select");
620 if (volt_gpio_np)
621 voltage_gpio = read_gpio(volt_gpio_np);
622
623 pvr = mfspr(SPRN_PVR);
624 has_cpu_l2lve = !((pvr & 0xf00) == 0x100);
625
626 set_speed_proc = cpu_750fx_cpu_speed;
627 get_speed_proc = cpu_750fx_get_cpu_speed;
628 cur_freq = cpu_750fx_get_cpu_speed();
629
630 return 0;
631}
632
633/* Currently, we support the following machines:
634 *
635 * - Titanium PowerBook 1Ghz (PMU based, 667Mhz & 1Ghz)
636 * - Titanium PowerBook 800 (PMU based, 667Mhz & 800Mhz)
637 * - Titanium PowerBook 400 (PMU based, 300Mhz & 400Mhz)
638 * - Titanium PowerBook 500 (PMU based, 300Mhz & 500Mhz)
639 * - iBook2 500/600 (PMU based, 400Mhz & 500/600Mhz)
640 * - iBook2 700 (CPU based, 400Mhz & 700Mhz, support low voltage)
641 * - Recent MacRISC3 laptops
642 * - All new machines with 7447A CPUs
643 */
644static int __init pmac_cpufreq_setup(void)
645{
646 struct device_node *cpunode;
647 const u32 *value;
648
649 if (strstr(cmd_line, "nocpufreq"))
650 return 0;
651
652 /* Assume only one CPU */
653 cpunode = of_find_node_by_type(NULL, "cpu");
654 if (!cpunode)
655 goto out;
656
657 /* Get current cpu clock freq */
658 value = of_get_property(cpunode, "clock-frequency", NULL);
659 if (!value)
660 goto out;
661 cur_freq = (*value) / 1000;
662 transition_latency = CPUFREQ_ETERNAL;
663
664 /* Check for 7447A based MacRISC3 */
665 if (of_machine_is_compatible("MacRISC3") &&
666 of_get_property(cpunode, "dynamic-power-step", NULL) &&
667 PVR_VER(mfspr(SPRN_PVR)) == 0x8003) {
668 pmac_cpufreq_init_7447A(cpunode);
669 transition_latency = 8000000;
670 /* Check for other MacRISC3 machines */
671 } else if (of_machine_is_compatible("PowerBook3,4") ||
672 of_machine_is_compatible("PowerBook3,5") ||
673 of_machine_is_compatible("MacRISC3")) {
674 pmac_cpufreq_init_MacRISC3(cpunode);
675 /* Else check for iBook2 500/600 */
676 } else if (of_machine_is_compatible("PowerBook4,1")) {
677 hi_freq = cur_freq;
678 low_freq = 400000;
679 set_speed_proc = pmu_set_cpu_speed;
680 is_pmu_based = 1;
681 }
682 /* Else check for TiPb 550 */
683 else if (of_machine_is_compatible("PowerBook3,3") && cur_freq == 550000) {
684 hi_freq = cur_freq;
685 low_freq = 500000;
686 set_speed_proc = pmu_set_cpu_speed;
687 is_pmu_based = 1;
688 }
689 /* Else check for TiPb 400 & 500 */
690 else if (of_machine_is_compatible("PowerBook3,2")) {
691 /* We only know about the 400 MHz and the 500Mhz model
692 * they both have 300 MHz as low frequency
693 */
694 if (cur_freq < 350000 || cur_freq > 550000)
695 goto out;
696 hi_freq = cur_freq;
697 low_freq = 300000;
698 set_speed_proc = pmu_set_cpu_speed;
699 is_pmu_based = 1;
700 }
701 /* Else check for 750FX */
702 else if (PVR_VER(mfspr(SPRN_PVR)) == 0x7000)
703 pmac_cpufreq_init_750FX(cpunode);
704out:
705 of_node_put(cpunode);
706 if (set_speed_proc == NULL)
707 return -ENODEV;
708
709 pmac_cpu_freqs[CPUFREQ_LOW].frequency = low_freq;
710 pmac_cpu_freqs[CPUFREQ_HIGH].frequency = hi_freq;
711 ppc_proc_freq = cur_freq * 1000ul;
712
713 printk(KERN_INFO "Registering PowerMac CPU frequency driver\n");
714 printk(KERN_INFO "Low: %d Mhz, High: %d Mhz, Boot: %d Mhz\n",
715 low_freq/1000, hi_freq/1000, cur_freq/1000);
716
717 return cpufreq_register_driver(&pmac_cpufreq_driver);
718}
719
720module_init(pmac_cpufreq_setup);
721
diff --git a/drivers/cpufreq/pmac64-cpufreq.c b/drivers/cpufreq/pmac64-cpufreq.c
new file mode 100644
index 000000000000..7ba423431cfe
--- /dev/null
+++ b/drivers/cpufreq/pmac64-cpufreq.c
@@ -0,0 +1,746 @@
1/*
2 * Copyright (C) 2002 - 2005 Benjamin Herrenschmidt <benh@kernel.crashing.org>
3 * and Markus Demleitner <msdemlei@cl.uni-heidelberg.de>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 *
9 * This driver adds basic cpufreq support for SMU & 970FX based G5 Macs,
10 * that is iMac G5 and latest single CPU desktop.
11 */
12
13#undef DEBUG
14
15#include <linux/module.h>
16#include <linux/types.h>
17#include <linux/errno.h>
18#include <linux/kernel.h>
19#include <linux/delay.h>
20#include <linux/sched.h>
21#include <linux/cpufreq.h>
22#include <linux/init.h>
23#include <linux/completion.h>
24#include <linux/mutex.h>
25#include <asm/prom.h>
26#include <asm/machdep.h>
27#include <asm/irq.h>
28#include <asm/sections.h>
29#include <asm/cputable.h>
30#include <asm/time.h>
31#include <asm/smu.h>
32#include <asm/pmac_pfunc.h>
33
34#define DBG(fmt...) pr_debug(fmt)
35
36/* see 970FX user manual */
37
38#define SCOM_PCR 0x0aa001 /* PCR scom addr */
39
40#define PCR_HILO_SELECT 0x80000000U /* 1 = PCR, 0 = PCRH */
41#define PCR_SPEED_FULL 0x00000000U /* 1:1 speed value */
42#define PCR_SPEED_HALF 0x00020000U /* 1:2 speed value */
43#define PCR_SPEED_QUARTER 0x00040000U /* 1:4 speed value */
44#define PCR_SPEED_MASK 0x000e0000U /* speed mask */
45#define PCR_SPEED_SHIFT 17
46#define PCR_FREQ_REQ_VALID 0x00010000U /* freq request valid */
47#define PCR_VOLT_REQ_VALID 0x00008000U /* volt request valid */
48#define PCR_TARGET_TIME_MASK 0x00006000U /* target time */
49#define PCR_STATLAT_MASK 0x00001f00U /* STATLAT value */
50#define PCR_SNOOPLAT_MASK 0x000000f0U /* SNOOPLAT value */
51#define PCR_SNOOPACC_MASK 0x0000000fU /* SNOOPACC value */
52
53#define SCOM_PSR 0x408001 /* PSR scom addr */
54/* warning: PSR is a 64 bits register */
55#define PSR_CMD_RECEIVED 0x2000000000000000U /* command received */
56#define PSR_CMD_COMPLETED 0x1000000000000000U /* command completed */
57#define PSR_CUR_SPEED_MASK 0x0300000000000000U /* current speed */
58#define PSR_CUR_SPEED_SHIFT (56)
59
60/*
61 * The G5 only supports two frequencies (Quarter speed is not supported)
62 */
63#define CPUFREQ_HIGH 0
64#define CPUFREQ_LOW 1
65
66static struct cpufreq_frequency_table g5_cpu_freqs[] = {
67 {CPUFREQ_HIGH, 0},
68 {CPUFREQ_LOW, 0},
69 {0, CPUFREQ_TABLE_END},
70};
71
72static struct freq_attr* g5_cpu_freqs_attr[] = {
73 &cpufreq_freq_attr_scaling_available_freqs,
74 NULL,
75};
76
77/* Power mode data is an array of the 32 bits PCR values to use for
78 * the various frequencies, retrieved from the device-tree
79 */
80static int g5_pmode_cur;
81
82static void (*g5_switch_volt)(int speed_mode);
83static int (*g5_switch_freq)(int speed_mode);
84static int (*g5_query_freq)(void);
85
86static DEFINE_MUTEX(g5_switch_mutex);
87
88static unsigned long transition_latency;
89
90#ifdef CONFIG_PMAC_SMU
91
92static const u32 *g5_pmode_data;
93static int g5_pmode_max;
94
95static struct smu_sdbp_fvt *g5_fvt_table; /* table of op. points */
96static int g5_fvt_count; /* number of op. points */
97static int g5_fvt_cur; /* current op. point */
98
99/*
100 * SMU based voltage switching for Neo2 platforms
101 */
102
103static void g5_smu_switch_volt(int speed_mode)
104{
105 struct smu_simple_cmd cmd;
106
107 DECLARE_COMPLETION_ONSTACK(comp);
108 smu_queue_simple(&cmd, SMU_CMD_POWER_COMMAND, 8, smu_done_complete,
109 &comp, 'V', 'S', 'L', 'E', 'W',
110 0xff, g5_fvt_cur+1, speed_mode);
111 wait_for_completion(&comp);
112}
113
114/*
115 * Platform function based voltage/vdnap switching for Neo2
116 */
117
118static struct pmf_function *pfunc_set_vdnap0;
119static struct pmf_function *pfunc_vdnap0_complete;
120
121static void g5_vdnap_switch_volt(int speed_mode)
122{
123 struct pmf_args args;
124 u32 slew, done = 0;
125 unsigned long timeout;
126
127 slew = (speed_mode == CPUFREQ_LOW) ? 1 : 0;
128 args.count = 1;
129 args.u[0].p = &slew;
130
131 pmf_call_one(pfunc_set_vdnap0, &args);
132
133 /* It's an irq GPIO so we should be able to just block here,
134 * I'll do that later after I've properly tested the IRQ code for
135 * platform functions
136 */
137 timeout = jiffies + HZ/10;
138 while(!time_after(jiffies, timeout)) {
139 args.count = 1;
140 args.u[0].p = &done;
141 pmf_call_one(pfunc_vdnap0_complete, &args);
142 if (done)
143 break;
144 msleep(1);
145 }
146 if (done == 0)
147 printk(KERN_WARNING "cpufreq: Timeout in clock slewing !\n");
148}
149
150
151/*
152 * SCOM based frequency switching for 970FX rev3
153 */
154static int g5_scom_switch_freq(int speed_mode)
155{
156 unsigned long flags;
157 int to;
158
159 /* If frequency is going up, first ramp up the voltage */
160 if (speed_mode < g5_pmode_cur)
161 g5_switch_volt(speed_mode);
162
163 local_irq_save(flags);
164
165 /* Clear PCR high */
166 scom970_write(SCOM_PCR, 0);
167 /* Clear PCR low */
168 scom970_write(SCOM_PCR, PCR_HILO_SELECT | 0);
169 /* Set PCR low */
170 scom970_write(SCOM_PCR, PCR_HILO_SELECT |
171 g5_pmode_data[speed_mode]);
172
173 /* Wait for completion */
174 for (to = 0; to < 10; to++) {
175 unsigned long psr = scom970_read(SCOM_PSR);
176
177 if ((psr & PSR_CMD_RECEIVED) == 0 &&
178 (((psr >> PSR_CUR_SPEED_SHIFT) ^
179 (g5_pmode_data[speed_mode] >> PCR_SPEED_SHIFT)) & 0x3)
180 == 0)
181 break;
182 if (psr & PSR_CMD_COMPLETED)
183 break;
184 udelay(100);
185 }
186
187 local_irq_restore(flags);
188
189 /* If frequency is going down, last ramp the voltage */
190 if (speed_mode > g5_pmode_cur)
191 g5_switch_volt(speed_mode);
192
193 g5_pmode_cur = speed_mode;
194 ppc_proc_freq = g5_cpu_freqs[speed_mode].frequency * 1000ul;
195
196 return 0;
197}
198
199static int g5_scom_query_freq(void)
200{
201 unsigned long psr = scom970_read(SCOM_PSR);
202 int i;
203
204 for (i = 0; i <= g5_pmode_max; i++)
205 if ((((psr >> PSR_CUR_SPEED_SHIFT) ^
206 (g5_pmode_data[i] >> PCR_SPEED_SHIFT)) & 0x3) == 0)
207 break;
208 return i;
209}
210
211/*
212 * Fake voltage switching for platforms with missing support
213 */
214
215static void g5_dummy_switch_volt(int speed_mode)
216{
217}
218
219#endif /* CONFIG_PMAC_SMU */
220
221/*
222 * Platform function based voltage switching for PowerMac7,2 & 7,3
223 */
224
225static struct pmf_function *pfunc_cpu0_volt_high;
226static struct pmf_function *pfunc_cpu0_volt_low;
227static struct pmf_function *pfunc_cpu1_volt_high;
228static struct pmf_function *pfunc_cpu1_volt_low;
229
230static void g5_pfunc_switch_volt(int speed_mode)
231{
232 if (speed_mode == CPUFREQ_HIGH) {
233 if (pfunc_cpu0_volt_high)
234 pmf_call_one(pfunc_cpu0_volt_high, NULL);
235 if (pfunc_cpu1_volt_high)
236 pmf_call_one(pfunc_cpu1_volt_high, NULL);
237 } else {
238 if (pfunc_cpu0_volt_low)
239 pmf_call_one(pfunc_cpu0_volt_low, NULL);
240 if (pfunc_cpu1_volt_low)
241 pmf_call_one(pfunc_cpu1_volt_low, NULL);
242 }
243 msleep(10); /* should be faster , to fix */
244}
245
246/*
247 * Platform function based frequency switching for PowerMac7,2 & 7,3
248 */
249
250static struct pmf_function *pfunc_cpu_setfreq_high;
251static struct pmf_function *pfunc_cpu_setfreq_low;
252static struct pmf_function *pfunc_cpu_getfreq;
253static struct pmf_function *pfunc_slewing_done;
254
255static int g5_pfunc_switch_freq(int speed_mode)
256{
257 struct pmf_args args;
258 u32 done = 0;
259 unsigned long timeout;
260 int rc;
261
262 DBG("g5_pfunc_switch_freq(%d)\n", speed_mode);
263
264 /* If frequency is going up, first ramp up the voltage */
265 if (speed_mode < g5_pmode_cur)
266 g5_switch_volt(speed_mode);
267
268 /* Do it */
269 if (speed_mode == CPUFREQ_HIGH)
270 rc = pmf_call_one(pfunc_cpu_setfreq_high, NULL);
271 else
272 rc = pmf_call_one(pfunc_cpu_setfreq_low, NULL);
273
274 if (rc)
275 printk(KERN_WARNING "cpufreq: pfunc switch error %d\n", rc);
276
277 /* It's an irq GPIO so we should be able to just block here,
278 * I'll do that later after I've properly tested the IRQ code for
279 * platform functions
280 */
281 timeout = jiffies + HZ/10;
282 while(!time_after(jiffies, timeout)) {
283 args.count = 1;
284 args.u[0].p = &done;
285 pmf_call_one(pfunc_slewing_done, &args);
286 if (done)
287 break;
288 msleep(1);
289 }
290 if (done == 0)
291 printk(KERN_WARNING "cpufreq: Timeout in clock slewing !\n");
292
293 /* If frequency is going down, last ramp the voltage */
294 if (speed_mode > g5_pmode_cur)
295 g5_switch_volt(speed_mode);
296
297 g5_pmode_cur = speed_mode;
298 ppc_proc_freq = g5_cpu_freqs[speed_mode].frequency * 1000ul;
299
300 return 0;
301}
302
303static int g5_pfunc_query_freq(void)
304{
305 struct pmf_args args;
306 u32 val = 0;
307
308 args.count = 1;
309 args.u[0].p = &val;
310 pmf_call_one(pfunc_cpu_getfreq, &args);
311 return val ? CPUFREQ_HIGH : CPUFREQ_LOW;
312}
313
314
315/*
316 * Common interface to the cpufreq core
317 */
318
319static int g5_cpufreq_verify(struct cpufreq_policy *policy)
320{
321 return cpufreq_frequency_table_verify(policy, g5_cpu_freqs);
322}
323
324static int g5_cpufreq_target(struct cpufreq_policy *policy,
325 unsigned int target_freq, unsigned int relation)
326{
327 unsigned int newstate = 0;
328 struct cpufreq_freqs freqs;
329 int rc;
330
331 if (cpufreq_frequency_table_target(policy, g5_cpu_freqs,
332 target_freq, relation, &newstate))
333 return -EINVAL;
334
335 if (g5_pmode_cur == newstate)
336 return 0;
337
338 mutex_lock(&g5_switch_mutex);
339
340 freqs.old = g5_cpu_freqs[g5_pmode_cur].frequency;
341 freqs.new = g5_cpu_freqs[newstate].frequency;
342
343 cpufreq_notify_transition(policy, &freqs, CPUFREQ_PRECHANGE);
344 rc = g5_switch_freq(newstate);
345 cpufreq_notify_transition(policy, &freqs, CPUFREQ_POSTCHANGE);
346
347 mutex_unlock(&g5_switch_mutex);
348
349 return rc;
350}
351
352static unsigned int g5_cpufreq_get_speed(unsigned int cpu)
353{
354 return g5_cpu_freqs[g5_pmode_cur].frequency;
355}
356
357static int g5_cpufreq_cpu_init(struct cpufreq_policy *policy)
358{
359 policy->cpuinfo.transition_latency = transition_latency;
360 policy->cur = g5_cpu_freqs[g5_query_freq()].frequency;
361 /* secondary CPUs are tied to the primary one by the
362 * cpufreq core if in the secondary policy we tell it that
363 * it actually must be one policy together with all others. */
364 cpumask_copy(policy->cpus, cpu_online_mask);
365 cpufreq_frequency_table_get_attr(g5_cpu_freqs, policy->cpu);
366
367 return cpufreq_frequency_table_cpuinfo(policy,
368 g5_cpu_freqs);
369}
370
371
372static struct cpufreq_driver g5_cpufreq_driver = {
373 .name = "powermac",
374 .owner = THIS_MODULE,
375 .flags = CPUFREQ_CONST_LOOPS,
376 .init = g5_cpufreq_cpu_init,
377 .verify = g5_cpufreq_verify,
378 .target = g5_cpufreq_target,
379 .get = g5_cpufreq_get_speed,
380 .attr = g5_cpu_freqs_attr,
381};
382
383
384#ifdef CONFIG_PMAC_SMU
385
386static int __init g5_neo2_cpufreq_init(struct device_node *cpus)
387{
388 struct device_node *cpunode;
389 unsigned int psize, ssize;
390 unsigned long max_freq;
391 char *freq_method, *volt_method;
392 const u32 *valp;
393 u32 pvr_hi;
394 int use_volts_vdnap = 0;
395 int use_volts_smu = 0;
396 int rc = -ENODEV;
397
398 /* Check supported platforms */
399 if (of_machine_is_compatible("PowerMac8,1") ||
400 of_machine_is_compatible("PowerMac8,2") ||
401 of_machine_is_compatible("PowerMac9,1"))
402 use_volts_smu = 1;
403 else if (of_machine_is_compatible("PowerMac11,2"))
404 use_volts_vdnap = 1;
405 else
406 return -ENODEV;
407
408 /* Get first CPU node */
409 for (cpunode = NULL;
410 (cpunode = of_get_next_child(cpus, cpunode)) != NULL;) {
411 const u32 *reg = of_get_property(cpunode, "reg", NULL);
412 if (reg == NULL || (*reg) != 0)
413 continue;
414 if (!strcmp(cpunode->type, "cpu"))
415 break;
416 }
417 if (cpunode == NULL) {
418 printk(KERN_ERR "cpufreq: Can't find any CPU 0 node\n");
419 return -ENODEV;
420 }
421
422 /* Check 970FX for now */
423 valp = of_get_property(cpunode, "cpu-version", NULL);
424 if (!valp) {
425 DBG("No cpu-version property !\n");
426 goto bail_noprops;
427 }
428 pvr_hi = (*valp) >> 16;
429 if (pvr_hi != 0x3c && pvr_hi != 0x44) {
430 printk(KERN_ERR "cpufreq: Unsupported CPU version\n");
431 goto bail_noprops;
432 }
433
434 /* Look for the powertune data in the device-tree */
435 g5_pmode_data = of_get_property(cpunode, "power-mode-data",&psize);
436 if (!g5_pmode_data) {
437 DBG("No power-mode-data !\n");
438 goto bail_noprops;
439 }
440 g5_pmode_max = psize / sizeof(u32) - 1;
441
442 if (use_volts_smu) {
443 const struct smu_sdbp_header *shdr;
444
445 /* Look for the FVT table */
446 shdr = smu_get_sdb_partition(SMU_SDB_FVT_ID, NULL);
447 if (!shdr)
448 goto bail_noprops;
449 g5_fvt_table = (struct smu_sdbp_fvt *)&shdr[1];
450 ssize = (shdr->len * sizeof(u32)) -
451 sizeof(struct smu_sdbp_header);
452 g5_fvt_count = ssize / sizeof(struct smu_sdbp_fvt);
453 g5_fvt_cur = 0;
454
455 /* Sanity checking */
456 if (g5_fvt_count < 1 || g5_pmode_max < 1)
457 goto bail_noprops;
458
459 g5_switch_volt = g5_smu_switch_volt;
460 volt_method = "SMU";
461 } else if (use_volts_vdnap) {
462 struct device_node *root;
463
464 root = of_find_node_by_path("/");
465 if (root == NULL) {
466 printk(KERN_ERR "cpufreq: Can't find root of "
467 "device tree\n");
468 goto bail_noprops;
469 }
470 pfunc_set_vdnap0 = pmf_find_function(root, "set-vdnap0");
471 pfunc_vdnap0_complete =
472 pmf_find_function(root, "slewing-done");
473 if (pfunc_set_vdnap0 == NULL ||
474 pfunc_vdnap0_complete == NULL) {
475 printk(KERN_ERR "cpufreq: Can't find required "
476 "platform function\n");
477 goto bail_noprops;
478 }
479
480 g5_switch_volt = g5_vdnap_switch_volt;
481 volt_method = "GPIO";
482 } else {
483 g5_switch_volt = g5_dummy_switch_volt;
484 volt_method = "none";
485 }
486
487 /*
488 * From what I see, clock-frequency is always the maximal frequency.
489 * The current driver can not slew sysclk yet, so we really only deal
490 * with powertune steps for now. We also only implement full freq and
491 * half freq in this version. So far, I haven't yet seen a machine
492 * supporting anything else.
493 */
494 valp = of_get_property(cpunode, "clock-frequency", NULL);
495 if (!valp)
496 return -ENODEV;
497 max_freq = (*valp)/1000;
498 g5_cpu_freqs[0].frequency = max_freq;
499 g5_cpu_freqs[1].frequency = max_freq/2;
500
501 /* Set callbacks */
502 transition_latency = 12000;
503 g5_switch_freq = g5_scom_switch_freq;
504 g5_query_freq = g5_scom_query_freq;
505 freq_method = "SCOM";
506
507 /* Force apply current frequency to make sure everything is in
508 * sync (voltage is right for example). Firmware may leave us with
509 * a strange setting ...
510 */
511 g5_switch_volt(CPUFREQ_HIGH);
512 msleep(10);
513 g5_pmode_cur = -1;
514 g5_switch_freq(g5_query_freq());
515
516 printk(KERN_INFO "Registering G5 CPU frequency driver\n");
517 printk(KERN_INFO "Frequency method: %s, Voltage method: %s\n",
518 freq_method, volt_method);
519 printk(KERN_INFO "Low: %d Mhz, High: %d Mhz, Cur: %d MHz\n",
520 g5_cpu_freqs[1].frequency/1000,
521 g5_cpu_freqs[0].frequency/1000,
522 g5_cpu_freqs[g5_pmode_cur].frequency/1000);
523
524 rc = cpufreq_register_driver(&g5_cpufreq_driver);
525
526 /* We keep the CPU node on hold... hopefully, Apple G5 don't have
527 * hotplug CPU with a dynamic device-tree ...
528 */
529 return rc;
530
531 bail_noprops:
532 of_node_put(cpunode);
533
534 return rc;
535}
536
537#endif /* CONFIG_PMAC_SMU */
538
539
540static int __init g5_pm72_cpufreq_init(struct device_node *cpus)
541{
542 struct device_node *cpuid = NULL, *hwclock = NULL, *cpunode = NULL;
543 const u8 *eeprom = NULL;
544 const u32 *valp;
545 u64 max_freq, min_freq, ih, il;
546 int has_volt = 1, rc = 0;
547
548 DBG("cpufreq: Initializing for PowerMac7,2, PowerMac7,3 and"
549 " RackMac3,1...\n");
550
551 /* Get first CPU node */
552 for (cpunode = NULL;
553 (cpunode = of_get_next_child(cpus, cpunode)) != NULL;) {
554 if (!strcmp(cpunode->type, "cpu"))
555 break;
556 }
557 if (cpunode == NULL) {
558 printk(KERN_ERR "cpufreq: Can't find any CPU node\n");
559 return -ENODEV;
560 }
561
562 /* Lookup the cpuid eeprom node */
563 cpuid = of_find_node_by_path("/u3@0,f8000000/i2c@f8001000/cpuid@a0");
564 if (cpuid != NULL)
565 eeprom = of_get_property(cpuid, "cpuid", NULL);
566 if (eeprom == NULL) {
567 printk(KERN_ERR "cpufreq: Can't find cpuid EEPROM !\n");
568 rc = -ENODEV;
569 goto bail;
570 }
571
572 /* Lookup the i2c hwclock */
573 for (hwclock = NULL;
574 (hwclock = of_find_node_by_name(hwclock, "i2c-hwclock")) != NULL;){
575 const char *loc = of_get_property(hwclock,
576 "hwctrl-location", NULL);
577 if (loc == NULL)
578 continue;
579 if (strcmp(loc, "CPU CLOCK"))
580 continue;
581 if (!of_get_property(hwclock, "platform-get-frequency", NULL))
582 continue;
583 break;
584 }
585 if (hwclock == NULL) {
586 printk(KERN_ERR "cpufreq: Can't find i2c clock chip !\n");
587 rc = -ENODEV;
588 goto bail;
589 }
590
591 DBG("cpufreq: i2c clock chip found: %s\n", hwclock->full_name);
592
593 /* Now get all the platform functions */
594 pfunc_cpu_getfreq =
595 pmf_find_function(hwclock, "get-frequency");
596 pfunc_cpu_setfreq_high =
597 pmf_find_function(hwclock, "set-frequency-high");
598 pfunc_cpu_setfreq_low =
599 pmf_find_function(hwclock, "set-frequency-low");
600 pfunc_slewing_done =
601 pmf_find_function(hwclock, "slewing-done");
602 pfunc_cpu0_volt_high =
603 pmf_find_function(hwclock, "set-voltage-high-0");
604 pfunc_cpu0_volt_low =
605 pmf_find_function(hwclock, "set-voltage-low-0");
606 pfunc_cpu1_volt_high =
607 pmf_find_function(hwclock, "set-voltage-high-1");
608 pfunc_cpu1_volt_low =
609 pmf_find_function(hwclock, "set-voltage-low-1");
610
611 /* Check we have minimum requirements */
612 if (pfunc_cpu_getfreq == NULL || pfunc_cpu_setfreq_high == NULL ||
613 pfunc_cpu_setfreq_low == NULL || pfunc_slewing_done == NULL) {
614 printk(KERN_ERR "cpufreq: Can't find platform functions !\n");
615 rc = -ENODEV;
616 goto bail;
617 }
618
619 /* Check that we have complete sets */
620 if (pfunc_cpu0_volt_high == NULL || pfunc_cpu0_volt_low == NULL) {
621 pmf_put_function(pfunc_cpu0_volt_high);
622 pmf_put_function(pfunc_cpu0_volt_low);
623 pfunc_cpu0_volt_high = pfunc_cpu0_volt_low = NULL;
624 has_volt = 0;
625 }
626 if (!has_volt ||
627 pfunc_cpu1_volt_high == NULL || pfunc_cpu1_volt_low == NULL) {
628 pmf_put_function(pfunc_cpu1_volt_high);
629 pmf_put_function(pfunc_cpu1_volt_low);
630 pfunc_cpu1_volt_high = pfunc_cpu1_volt_low = NULL;
631 }
632
633 /* Note: The device tree also contains a "platform-set-values"
634 * function for which I haven't quite figured out the usage. It
635 * might have to be called on init and/or wakeup, I'm not too sure
636 * but things seem to work fine without it so far ...
637 */
638
639 /* Get max frequency from device-tree */
640 valp = of_get_property(cpunode, "clock-frequency", NULL);
641 if (!valp) {
642 printk(KERN_ERR "cpufreq: Can't find CPU frequency !\n");
643 rc = -ENODEV;
644 goto bail;
645 }
646
647 max_freq = (*valp)/1000;
648
649 /* Now calculate reduced frequency by using the cpuid input freq
650 * ratio. This requires 64 bits math unless we are willing to lose
651 * some precision
652 */
653 ih = *((u32 *)(eeprom + 0x10));
654 il = *((u32 *)(eeprom + 0x20));
655
656 /* Check for machines with no useful settings */
657 if (il == ih) {
658 printk(KERN_WARNING "cpufreq: No low frequency mode available"
659 " on this model !\n");
660 rc = -ENODEV;
661 goto bail;
662 }
663
664 min_freq = 0;
665 if (ih != 0 && il != 0)
666 min_freq = (max_freq * il) / ih;
667
668 /* Sanity check */
669 if (min_freq >= max_freq || min_freq < 1000) {
670 printk(KERN_ERR "cpufreq: Can't calculate low frequency !\n");
671 rc = -ENXIO;
672 goto bail;
673 }
674 g5_cpu_freqs[0].frequency = max_freq;
675 g5_cpu_freqs[1].frequency = min_freq;
676
677 /* Set callbacks */
678 transition_latency = CPUFREQ_ETERNAL;
679 g5_switch_volt = g5_pfunc_switch_volt;
680 g5_switch_freq = g5_pfunc_switch_freq;
681 g5_query_freq = g5_pfunc_query_freq;
682
683 /* Force apply current frequency to make sure everything is in
684 * sync (voltage is right for example). Firmware may leave us with
685 * a strange setting ...
686 */
687 g5_switch_volt(CPUFREQ_HIGH);
688 msleep(10);
689 g5_pmode_cur = -1;
690 g5_switch_freq(g5_query_freq());
691
692 printk(KERN_INFO "Registering G5 CPU frequency driver\n");
693 printk(KERN_INFO "Frequency method: i2c/pfunc, "
694 "Voltage method: %s\n", has_volt ? "i2c/pfunc" : "none");
695 printk(KERN_INFO "Low: %d Mhz, High: %d Mhz, Cur: %d MHz\n",
696 g5_cpu_freqs[1].frequency/1000,
697 g5_cpu_freqs[0].frequency/1000,
698 g5_cpu_freqs[g5_pmode_cur].frequency/1000);
699
700 rc = cpufreq_register_driver(&g5_cpufreq_driver);
701 bail:
702 if (rc != 0) {
703 pmf_put_function(pfunc_cpu_getfreq);
704 pmf_put_function(pfunc_cpu_setfreq_high);
705 pmf_put_function(pfunc_cpu_setfreq_low);
706 pmf_put_function(pfunc_slewing_done);
707 pmf_put_function(pfunc_cpu0_volt_high);
708 pmf_put_function(pfunc_cpu0_volt_low);
709 pmf_put_function(pfunc_cpu1_volt_high);
710 pmf_put_function(pfunc_cpu1_volt_low);
711 }
712 of_node_put(hwclock);
713 of_node_put(cpuid);
714 of_node_put(cpunode);
715
716 return rc;
717}
718
719static int __init g5_cpufreq_init(void)
720{
721 struct device_node *cpus;
722 int rc = 0;
723
724 cpus = of_find_node_by_path("/cpus");
725 if (cpus == NULL) {
726 DBG("No /cpus node !\n");
727 return -ENODEV;
728 }
729
730 if (of_machine_is_compatible("PowerMac7,2") ||
731 of_machine_is_compatible("PowerMac7,3") ||
732 of_machine_is_compatible("RackMac3,1"))
733 rc = g5_pm72_cpufreq_init(cpus);
734#ifdef CONFIG_PMAC_SMU
735 else
736 rc = g5_neo2_cpufreq_init(cpus);
737#endif /* CONFIG_PMAC_SMU */
738
739 of_node_put(cpus);
740 return rc;
741}
742
743module_init(g5_cpufreq_init);
744
745
746MODULE_LICENSE("GPL");
diff --git a/drivers/cpufreq/powernow-k6.c b/drivers/cpufreq/powernow-k6.c
index ea0222a45b7b..ea8e10382ec5 100644
--- a/drivers/cpufreq/powernow-k6.c
+++ b/drivers/cpufreq/powernow-k6.c
@@ -58,7 +58,7 @@ static int powernow_k6_get_cpu_multiplier(void)
58 msrval = POWERNOW_IOPORT + 0x0; 58 msrval = POWERNOW_IOPORT + 0x0;
59 wrmsr(MSR_K6_EPMR, msrval, 0); /* disable it again */ 59 wrmsr(MSR_K6_EPMR, msrval, 0); /* disable it again */
60 60
61 return clock_ratio[(invalue >> 5)&7].index; 61 return clock_ratio[(invalue >> 5)&7].driver_data;
62} 62}
63 63
64 64
@@ -75,13 +75,13 @@ static void powernow_k6_set_state(struct cpufreq_policy *policy,
75 unsigned long msrval; 75 unsigned long msrval;
76 struct cpufreq_freqs freqs; 76 struct cpufreq_freqs freqs;
77 77
78 if (clock_ratio[best_i].index > max_multiplier) { 78 if (clock_ratio[best_i].driver_data > max_multiplier) {
79 printk(KERN_ERR PFX "invalid target frequency\n"); 79 printk(KERN_ERR PFX "invalid target frequency\n");
80 return; 80 return;
81 } 81 }
82 82
83 freqs.old = busfreq * powernow_k6_get_cpu_multiplier(); 83 freqs.old = busfreq * powernow_k6_get_cpu_multiplier();
84 freqs.new = busfreq * clock_ratio[best_i].index; 84 freqs.new = busfreq * clock_ratio[best_i].driver_data;
85 85
86 cpufreq_notify_transition(policy, &freqs, CPUFREQ_PRECHANGE); 86 cpufreq_notify_transition(policy, &freqs, CPUFREQ_PRECHANGE);
87 87
@@ -156,7 +156,7 @@ static int powernow_k6_cpu_init(struct cpufreq_policy *policy)
156 156
157 /* table init */ 157 /* table init */
158 for (i = 0; (clock_ratio[i].frequency != CPUFREQ_TABLE_END); i++) { 158 for (i = 0; (clock_ratio[i].frequency != CPUFREQ_TABLE_END); i++) {
159 f = clock_ratio[i].index; 159 f = clock_ratio[i].driver_data;
160 if (f > max_multiplier) 160 if (f > max_multiplier)
161 clock_ratio[i].frequency = CPUFREQ_ENTRY_INVALID; 161 clock_ratio[i].frequency = CPUFREQ_ENTRY_INVALID;
162 else 162 else
diff --git a/drivers/cpufreq/powernow-k7.c b/drivers/cpufreq/powernow-k7.c
index 53888dacbe58..b9f80b713fda 100644
--- a/drivers/cpufreq/powernow-k7.c
+++ b/drivers/cpufreq/powernow-k7.c
@@ -186,7 +186,7 @@ static int get_ranges(unsigned char *pst)
186 fid = *pst++; 186 fid = *pst++;
187 187
188 powernow_table[j].frequency = (fsb * fid_codes[fid]) / 10; 188 powernow_table[j].frequency = (fsb * fid_codes[fid]) / 10;
189 powernow_table[j].index = fid; /* lower 8 bits */ 189 powernow_table[j].driver_data = fid; /* lower 8 bits */
190 190
191 speed = powernow_table[j].frequency; 191 speed = powernow_table[j].frequency;
192 192
@@ -203,7 +203,7 @@ static int get_ranges(unsigned char *pst)
203 maximum_speed = speed; 203 maximum_speed = speed;
204 204
205 vid = *pst++; 205 vid = *pst++;
206 powernow_table[j].index |= (vid << 8); /* upper 8 bits */ 206 powernow_table[j].driver_data |= (vid << 8); /* upper 8 bits */
207 207
208 pr_debug(" FID: 0x%x (%d.%dx [%dMHz]) " 208 pr_debug(" FID: 0x%x (%d.%dx [%dMHz]) "
209 "VID: 0x%x (%d.%03dV)\n", fid, fid_codes[fid] / 10, 209 "VID: 0x%x (%d.%03dV)\n", fid, fid_codes[fid] / 10,
@@ -212,7 +212,7 @@ static int get_ranges(unsigned char *pst)
212 mobile_vid_table[vid]%1000); 212 mobile_vid_table[vid]%1000);
213 } 213 }
214 powernow_table[number_scales].frequency = CPUFREQ_TABLE_END; 214 powernow_table[number_scales].frequency = CPUFREQ_TABLE_END;
215 powernow_table[number_scales].index = 0; 215 powernow_table[number_scales].driver_data = 0;
216 216
217 return 0; 217 return 0;
218} 218}
@@ -260,8 +260,8 @@ static void change_speed(struct cpufreq_policy *policy, unsigned int index)
260 * vid are the upper 8 bits. 260 * vid are the upper 8 bits.
261 */ 261 */
262 262
263 fid = powernow_table[index].index & 0xFF; 263 fid = powernow_table[index].driver_data & 0xFF;
264 vid = (powernow_table[index].index & 0xFF00) >> 8; 264 vid = (powernow_table[index].driver_data & 0xFF00) >> 8;
265 265
266 rdmsrl(MSR_K7_FID_VID_STATUS, fidvidstatus.val); 266 rdmsrl(MSR_K7_FID_VID_STATUS, fidvidstatus.val);
267 cfid = fidvidstatus.bits.CFID; 267 cfid = fidvidstatus.bits.CFID;
@@ -373,8 +373,8 @@ static int powernow_acpi_init(void)
373 fid = pc.bits.fid; 373 fid = pc.bits.fid;
374 374
375 powernow_table[i].frequency = fsb * fid_codes[fid] / 10; 375 powernow_table[i].frequency = fsb * fid_codes[fid] / 10;
376 powernow_table[i].index = fid; /* lower 8 bits */ 376 powernow_table[i].driver_data = fid; /* lower 8 bits */
377 powernow_table[i].index |= (vid << 8); /* upper 8 bits */ 377 powernow_table[i].driver_data |= (vid << 8); /* upper 8 bits */
378 378
379 speed = powernow_table[i].frequency; 379 speed = powernow_table[i].frequency;
380 speed_mhz = speed / 1000; 380 speed_mhz = speed / 1000;
@@ -417,7 +417,7 @@ static int powernow_acpi_init(void)
417 } 417 }
418 418
419 powernow_table[i].frequency = CPUFREQ_TABLE_END; 419 powernow_table[i].frequency = CPUFREQ_TABLE_END;
420 powernow_table[i].index = 0; 420 powernow_table[i].driver_data = 0;
421 421
422 /* notify BIOS that we exist */ 422 /* notify BIOS that we exist */
423 acpi_processor_notify_smm(THIS_MODULE); 423 acpi_processor_notify_smm(THIS_MODULE);
diff --git a/drivers/cpufreq/powernow-k8.c b/drivers/cpufreq/powernow-k8.c
index b828efe4b2f8..78f018f2a5de 100644
--- a/drivers/cpufreq/powernow-k8.c
+++ b/drivers/cpufreq/powernow-k8.c
@@ -584,9 +584,9 @@ static void print_basics(struct powernow_k8_data *data)
584 CPUFREQ_ENTRY_INVALID) { 584 CPUFREQ_ENTRY_INVALID) {
585 printk(KERN_INFO PFX 585 printk(KERN_INFO PFX
586 "fid 0x%x (%d MHz), vid 0x%x\n", 586 "fid 0x%x (%d MHz), vid 0x%x\n",
587 data->powernow_table[j].index & 0xff, 587 data->powernow_table[j].driver_data & 0xff,
588 data->powernow_table[j].frequency/1000, 588 data->powernow_table[j].frequency/1000,
589 data->powernow_table[j].index >> 8); 589 data->powernow_table[j].driver_data >> 8);
590 } 590 }
591 } 591 }
592 if (data->batps) 592 if (data->batps)
@@ -632,13 +632,13 @@ static int fill_powernow_table(struct powernow_k8_data *data,
632 632
633 for (j = 0; j < data->numps; j++) { 633 for (j = 0; j < data->numps; j++) {
634 int freq; 634 int freq;
635 powernow_table[j].index = pst[j].fid; /* lower 8 bits */ 635 powernow_table[j].driver_data = pst[j].fid; /* lower 8 bits */
636 powernow_table[j].index |= (pst[j].vid << 8); /* upper 8 bits */ 636 powernow_table[j].driver_data |= (pst[j].vid << 8); /* upper 8 bits */
637 freq = find_khz_freq_from_fid(pst[j].fid); 637 freq = find_khz_freq_from_fid(pst[j].fid);
638 powernow_table[j].frequency = freq; 638 powernow_table[j].frequency = freq;
639 } 639 }
640 powernow_table[data->numps].frequency = CPUFREQ_TABLE_END; 640 powernow_table[data->numps].frequency = CPUFREQ_TABLE_END;
641 powernow_table[data->numps].index = 0; 641 powernow_table[data->numps].driver_data = 0;
642 642
643 if (query_current_values_with_pending_wait(data)) { 643 if (query_current_values_with_pending_wait(data)) {
644 kfree(powernow_table); 644 kfree(powernow_table);
@@ -810,7 +810,7 @@ static int powernow_k8_cpu_init_acpi(struct powernow_k8_data *data)
810 810
811 powernow_table[data->acpi_data.state_count].frequency = 811 powernow_table[data->acpi_data.state_count].frequency =
812 CPUFREQ_TABLE_END; 812 CPUFREQ_TABLE_END;
813 powernow_table[data->acpi_data.state_count].index = 0; 813 powernow_table[data->acpi_data.state_count].driver_data = 0;
814 data->powernow_table = powernow_table; 814 data->powernow_table = powernow_table;
815 815
816 if (cpumask_first(cpu_core_mask(data->cpu)) == data->cpu) 816 if (cpumask_first(cpu_core_mask(data->cpu)) == data->cpu)
@@ -865,7 +865,7 @@ static int fill_powernow_table_fidvid(struct powernow_k8_data *data,
865 pr_debug(" %d : fid 0x%x, vid 0x%x\n", i, fid, vid); 865 pr_debug(" %d : fid 0x%x, vid 0x%x\n", i, fid, vid);
866 866
867 index = fid | (vid<<8); 867 index = fid | (vid<<8);
868 powernow_table[i].index = index; 868 powernow_table[i].driver_data = index;
869 869
870 freq = find_khz_freq_from_fid(fid); 870 freq = find_khz_freq_from_fid(fid);
871 powernow_table[i].frequency = freq; 871 powernow_table[i].frequency = freq;
@@ -941,8 +941,8 @@ static int transition_frequency_fidvid(struct powernow_k8_data *data,
941 * the cpufreq frequency table in find_psb_table, vid 941 * the cpufreq frequency table in find_psb_table, vid
942 * are the upper 8 bits. 942 * are the upper 8 bits.
943 */ 943 */
944 fid = data->powernow_table[index].index & 0xFF; 944 fid = data->powernow_table[index].driver_data & 0xFF;
945 vid = (data->powernow_table[index].index & 0xFF00) >> 8; 945 vid = (data->powernow_table[index].driver_data & 0xFF00) >> 8;
946 946
947 pr_debug("table matched fid 0x%x, giving vid 0x%x\n", fid, vid); 947 pr_debug("table matched fid 0x%x, giving vid 0x%x\n", fid, vid);
948 948
@@ -967,9 +967,9 @@ static int transition_frequency_fidvid(struct powernow_k8_data *data,
967 967
968 res = transition_fid_vid(data, fid, vid); 968 res = transition_fid_vid(data, fid, vid);
969 if (res) 969 if (res)
970 return res; 970 freqs.new = freqs.old;
971 971 else
972 freqs.new = find_khz_freq_from_fid(data->currfid); 972 freqs.new = find_khz_freq_from_fid(data->currfid);
973 973
974 cpufreq_notify_transition(policy, &freqs, CPUFREQ_POSTCHANGE); 974 cpufreq_notify_transition(policy, &freqs, CPUFREQ_POSTCHANGE);
975 return res; 975 return res;
diff --git a/drivers/cpufreq/ppc-corenet-cpufreq.c b/drivers/cpufreq/ppc-corenet-cpufreq.c
new file mode 100644
index 000000000000..3cae4529f959
--- /dev/null
+++ b/drivers/cpufreq/ppc-corenet-cpufreq.c
@@ -0,0 +1,380 @@
1/*
2 * Copyright 2013 Freescale Semiconductor, Inc.
3 *
4 * CPU Frequency Scaling driver for Freescale PowerPC corenet SoCs.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
12
13#include <linux/clk.h>
14#include <linux/cpufreq.h>
15#include <linux/errno.h>
16#include <sysdev/fsl_soc.h>
17#include <linux/init.h>
18#include <linux/kernel.h>
19#include <linux/module.h>
20#include <linux/mutex.h>
21#include <linux/of.h>
22#include <linux/slab.h>
23#include <linux/smp.h>
24
25/**
26 * struct cpu_data - per CPU data struct
27 * @clk: the clk of CPU
28 * @parent: the parent node of cpu clock
29 * @table: frequency table
30 */
31struct cpu_data {
32 struct clk *clk;
33 struct device_node *parent;
34 struct cpufreq_frequency_table *table;
35};
36
37/**
38 * struct soc_data - SoC specific data
39 * @freq_mask: mask the disallowed frequencies
40 * @flag: unique flags
41 */
42struct soc_data {
43 u32 freq_mask[4];
44 u32 flag;
45};
46
47#define FREQ_MASK 1
48/* see hardware specification for the allowed frqeuencies */
49static const struct soc_data sdata[] = {
50 { /* used by p2041 and p3041 */
51 .freq_mask = {0x8, 0x8, 0x2, 0x2},
52 .flag = FREQ_MASK,
53 },
54 { /* used by p5020 */
55 .freq_mask = {0x8, 0x2},
56 .flag = FREQ_MASK,
57 },
58 { /* used by p4080, p5040 */
59 .freq_mask = {0},
60 .flag = 0,
61 },
62};
63
64/*
65 * the minimum allowed core frequency, in Hz
66 * for chassis v1.0, >= platform frequency
67 * for chassis v2.0, >= platform frequency / 2
68 */
69static u32 min_cpufreq;
70static const u32 *fmask;
71
72/* serialize frequency changes */
73static DEFINE_MUTEX(cpufreq_lock);
74static DEFINE_PER_CPU(struct cpu_data *, cpu_data);
75
76/* cpumask in a cluster */
77static DEFINE_PER_CPU(cpumask_var_t, cpu_mask);
78
79#ifndef CONFIG_SMP
80static inline const struct cpumask *cpu_core_mask(int cpu)
81{
82 return cpumask_of(0);
83}
84#endif
85
86static unsigned int corenet_cpufreq_get_speed(unsigned int cpu)
87{
88 struct cpu_data *data = per_cpu(cpu_data, cpu);
89
90 return clk_get_rate(data->clk) / 1000;
91}
92
93/* reduce the duplicated frequencies in frequency table */
94static void freq_table_redup(struct cpufreq_frequency_table *freq_table,
95 int count)
96{
97 int i, j;
98
99 for (i = 1; i < count; i++) {
100 for (j = 0; j < i; j++) {
101 if (freq_table[j].frequency == CPUFREQ_ENTRY_INVALID ||
102 freq_table[j].frequency !=
103 freq_table[i].frequency)
104 continue;
105
106 freq_table[i].frequency = CPUFREQ_ENTRY_INVALID;
107 break;
108 }
109 }
110}
111
112/* sort the frequencies in frequency table in descenting order */
113static void freq_table_sort(struct cpufreq_frequency_table *freq_table,
114 int count)
115{
116 int i, j, ind;
117 unsigned int freq, max_freq;
118 struct cpufreq_frequency_table table;
119 for (i = 0; i < count - 1; i++) {
120 max_freq = freq_table[i].frequency;
121 ind = i;
122 for (j = i + 1; j < count; j++) {
123 freq = freq_table[j].frequency;
124 if (freq == CPUFREQ_ENTRY_INVALID ||
125 freq <= max_freq)
126 continue;
127 ind = j;
128 max_freq = freq;
129 }
130
131 if (ind != i) {
132 /* exchange the frequencies */
133 table.driver_data = freq_table[i].driver_data;
134 table.frequency = freq_table[i].frequency;
135 freq_table[i].driver_data = freq_table[ind].driver_data;
136 freq_table[i].frequency = freq_table[ind].frequency;
137 freq_table[ind].driver_data = table.driver_data;
138 freq_table[ind].frequency = table.frequency;
139 }
140 }
141}
142
143static int corenet_cpufreq_cpu_init(struct cpufreq_policy *policy)
144{
145 struct device_node *np;
146 int i, count, ret;
147 u32 freq, mask;
148 struct clk *clk;
149 struct cpufreq_frequency_table *table;
150 struct cpu_data *data;
151 unsigned int cpu = policy->cpu;
152
153 np = of_get_cpu_node(cpu, NULL);
154 if (!np)
155 return -ENODEV;
156
157 data = kzalloc(sizeof(*data), GFP_KERNEL);
158 if (!data) {
159 pr_err("%s: no memory\n", __func__);
160 goto err_np;
161 }
162
163 data->clk = of_clk_get(np, 0);
164 if (IS_ERR(data->clk)) {
165 pr_err("%s: no clock information\n", __func__);
166 goto err_nomem2;
167 }
168
169 data->parent = of_parse_phandle(np, "clocks", 0);
170 if (!data->parent) {
171 pr_err("%s: could not get clock information\n", __func__);
172 goto err_nomem2;
173 }
174
175 count = of_property_count_strings(data->parent, "clock-names");
176 table = kcalloc(count + 1, sizeof(*table), GFP_KERNEL);
177 if (!table) {
178 pr_err("%s: no memory\n", __func__);
179 goto err_node;
180 }
181
182 if (fmask)
183 mask = fmask[get_hard_smp_processor_id(cpu)];
184 else
185 mask = 0x0;
186
187 for (i = 0; i < count; i++) {
188 clk = of_clk_get(data->parent, i);
189 freq = clk_get_rate(clk);
190 /*
191 * the clock is valid if its frequency is not masked
192 * and large than minimum allowed frequency.
193 */
194 if (freq < min_cpufreq || (mask & (1 << i)))
195 table[i].frequency = CPUFREQ_ENTRY_INVALID;
196 else
197 table[i].frequency = freq / 1000;
198 table[i].driver_data = i;
199 }
200 freq_table_redup(table, count);
201 freq_table_sort(table, count);
202 table[i].frequency = CPUFREQ_TABLE_END;
203
204 /* set the min and max frequency properly */
205 ret = cpufreq_frequency_table_cpuinfo(policy, table);
206 if (ret) {
207 pr_err("invalid frequency table: %d\n", ret);
208 goto err_nomem1;
209 }
210
211 data->table = table;
212 per_cpu(cpu_data, cpu) = data;
213
214 /* update ->cpus if we have cluster, no harm if not */
215 cpumask_copy(policy->cpus, per_cpu(cpu_mask, cpu));
216 for_each_cpu(i, per_cpu(cpu_mask, cpu))
217 per_cpu(cpu_data, i) = data;
218
219 policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL;
220 policy->cur = corenet_cpufreq_get_speed(policy->cpu);
221
222 cpufreq_frequency_table_get_attr(table, cpu);
223 of_node_put(np);
224
225 return 0;
226
227err_nomem1:
228 kfree(table);
229err_node:
230 of_node_put(data->parent);
231err_nomem2:
232 per_cpu(cpu_data, cpu) = NULL;
233 kfree(data);
234err_np:
235 of_node_put(np);
236
237 return -ENODEV;
238}
239
240static int __exit corenet_cpufreq_cpu_exit(struct cpufreq_policy *policy)
241{
242 struct cpu_data *data = per_cpu(cpu_data, policy->cpu);
243 unsigned int cpu;
244
245 cpufreq_frequency_table_put_attr(policy->cpu);
246 of_node_put(data->parent);
247 kfree(data->table);
248 kfree(data);
249
250 for_each_cpu(cpu, per_cpu(cpu_mask, policy->cpu))
251 per_cpu(cpu_data, cpu) = NULL;
252
253 return 0;
254}
255
256static int corenet_cpufreq_verify(struct cpufreq_policy *policy)
257{
258 struct cpufreq_frequency_table *table =
259 per_cpu(cpu_data, policy->cpu)->table;
260
261 return cpufreq_frequency_table_verify(policy, table);
262}
263
264static int corenet_cpufreq_target(struct cpufreq_policy *policy,
265 unsigned int target_freq, unsigned int relation)
266{
267 struct cpufreq_freqs freqs;
268 unsigned int new;
269 struct clk *parent;
270 int ret;
271 struct cpu_data *data = per_cpu(cpu_data, policy->cpu);
272
273 cpufreq_frequency_table_target(policy, data->table,
274 target_freq, relation, &new);
275
276 if (policy->cur == data->table[new].frequency)
277 return 0;
278
279 freqs.old = policy->cur;
280 freqs.new = data->table[new].frequency;
281
282 mutex_lock(&cpufreq_lock);
283 cpufreq_notify_transition(policy, &freqs, CPUFREQ_PRECHANGE);
284
285 parent = of_clk_get(data->parent, data->table[new].driver_data);
286 ret = clk_set_parent(data->clk, parent);
287 if (ret)
288 freqs.new = freqs.old;
289
290 cpufreq_notify_transition(policy, &freqs, CPUFREQ_POSTCHANGE);
291 mutex_unlock(&cpufreq_lock);
292
293 return ret;
294}
295
296static struct freq_attr *corenet_cpufreq_attr[] = {
297 &cpufreq_freq_attr_scaling_available_freqs,
298 NULL,
299};
300
301static struct cpufreq_driver ppc_corenet_cpufreq_driver = {
302 .name = "ppc_cpufreq",
303 .owner = THIS_MODULE,
304 .flags = CPUFREQ_CONST_LOOPS,
305 .init = corenet_cpufreq_cpu_init,
306 .exit = __exit_p(corenet_cpufreq_cpu_exit),
307 .verify = corenet_cpufreq_verify,
308 .target = corenet_cpufreq_target,
309 .get = corenet_cpufreq_get_speed,
310 .attr = corenet_cpufreq_attr,
311};
312
313static const struct of_device_id node_matches[] __initdata = {
314 { .compatible = "fsl,p2041-clockgen", .data = &sdata[0], },
315 { .compatible = "fsl,p3041-clockgen", .data = &sdata[0], },
316 { .compatible = "fsl,p5020-clockgen", .data = &sdata[1], },
317 { .compatible = "fsl,p4080-clockgen", .data = &sdata[2], },
318 { .compatible = "fsl,p5040-clockgen", .data = &sdata[2], },
319 { .compatible = "fsl,qoriq-clockgen-2.0", },
320 {}
321};
322
323static int __init ppc_corenet_cpufreq_init(void)
324{
325 int ret;
326 struct device_node *np;
327 const struct of_device_id *match;
328 const struct soc_data *data;
329 unsigned int cpu;
330
331 np = of_find_matching_node(NULL, node_matches);
332 if (!np)
333 return -ENODEV;
334
335 for_each_possible_cpu(cpu) {
336 if (!alloc_cpumask_var(&per_cpu(cpu_mask, cpu), GFP_KERNEL))
337 goto err_mask;
338 cpumask_copy(per_cpu(cpu_mask, cpu), cpu_core_mask(cpu));
339 }
340
341 match = of_match_node(node_matches, np);
342 data = match->data;
343 if (data) {
344 if (data->flag)
345 fmask = data->freq_mask;
346 min_cpufreq = fsl_get_sys_freq();
347 } else {
348 min_cpufreq = fsl_get_sys_freq() / 2;
349 }
350
351 of_node_put(np);
352
353 ret = cpufreq_register_driver(&ppc_corenet_cpufreq_driver);
354 if (!ret)
355 pr_info("Freescale PowerPC corenet CPU frequency scaling driver\n");
356
357 return ret;
358
359err_mask:
360 for_each_possible_cpu(cpu)
361 free_cpumask_var(per_cpu(cpu_mask, cpu));
362
363 return -ENOMEM;
364}
365module_init(ppc_corenet_cpufreq_init);
366
367static void __exit ppc_corenet_cpufreq_exit(void)
368{
369 unsigned int cpu;
370
371 for_each_possible_cpu(cpu)
372 free_cpumask_var(per_cpu(cpu_mask, cpu));
373
374 cpufreq_unregister_driver(&ppc_corenet_cpufreq_driver);
375}
376module_exit(ppc_corenet_cpufreq_exit);
377
378MODULE_LICENSE("GPL");
379MODULE_AUTHOR("Tang Yuantian <Yuantian.Tang@freescale.com>");
380MODULE_DESCRIPTION("cpufreq driver for Freescale e500mc series SoCs");
diff --git a/drivers/cpufreq/ppc_cbe_cpufreq.c b/drivers/cpufreq/ppc_cbe_cpufreq.c
index e577a1dbbfcd..5936f8d6f2cc 100644
--- a/drivers/cpufreq/ppc_cbe_cpufreq.c
+++ b/drivers/cpufreq/ppc_cbe_cpufreq.c
@@ -106,7 +106,7 @@ static int cbe_cpufreq_cpu_init(struct cpufreq_policy *policy)
106 106
107 /* initialize frequency table */ 107 /* initialize frequency table */
108 for (i=0; cbe_freqs[i].frequency!=CPUFREQ_TABLE_END; i++) { 108 for (i=0; cbe_freqs[i].frequency!=CPUFREQ_TABLE_END; i++) {
109 cbe_freqs[i].frequency = max_freq / cbe_freqs[i].index; 109 cbe_freqs[i].frequency = max_freq / cbe_freqs[i].driver_data;
110 pr_debug("%d: %d\n", i, cbe_freqs[i].frequency); 110 pr_debug("%d: %d\n", i, cbe_freqs[i].frequency);
111 } 111 }
112 112
@@ -165,7 +165,7 @@ static int cbe_cpufreq_target(struct cpufreq_policy *policy,
165 "1/%d of max frequency\n", 165 "1/%d of max frequency\n",
166 policy->cpu, 166 policy->cpu,
167 cbe_freqs[cbe_pmode_new].frequency, 167 cbe_freqs[cbe_pmode_new].frequency,
168 cbe_freqs[cbe_pmode_new].index); 168 cbe_freqs[cbe_pmode_new].driver_data);
169 169
170 rc = set_pmode(policy->cpu, cbe_pmode_new); 170 rc = set_pmode(policy->cpu, cbe_pmode_new);
171 171
diff --git a/drivers/cpufreq/pxa2xx-cpufreq.c b/drivers/cpufreq/pxa2xx-cpufreq.c
index 9e5bc8e388a0..fb3981ac829f 100644
--- a/drivers/cpufreq/pxa2xx-cpufreq.c
+++ b/drivers/cpufreq/pxa2xx-cpufreq.c
@@ -420,7 +420,7 @@ static int pxa_cpufreq_init(struct cpufreq_policy *policy)
420 /* Generate pxa25x the run cpufreq_frequency_table struct */ 420 /* Generate pxa25x the run cpufreq_frequency_table struct */
421 for (i = 0; i < NUM_PXA25x_RUN_FREQS; i++) { 421 for (i = 0; i < NUM_PXA25x_RUN_FREQS; i++) {
422 pxa255_run_freq_table[i].frequency = pxa255_run_freqs[i].khz; 422 pxa255_run_freq_table[i].frequency = pxa255_run_freqs[i].khz;
423 pxa255_run_freq_table[i].index = i; 423 pxa255_run_freq_table[i].driver_data = i;
424 } 424 }
425 pxa255_run_freq_table[i].frequency = CPUFREQ_TABLE_END; 425 pxa255_run_freq_table[i].frequency = CPUFREQ_TABLE_END;
426 426
@@ -428,7 +428,7 @@ static int pxa_cpufreq_init(struct cpufreq_policy *policy)
428 for (i = 0; i < NUM_PXA25x_TURBO_FREQS; i++) { 428 for (i = 0; i < NUM_PXA25x_TURBO_FREQS; i++) {
429 pxa255_turbo_freq_table[i].frequency = 429 pxa255_turbo_freq_table[i].frequency =
430 pxa255_turbo_freqs[i].khz; 430 pxa255_turbo_freqs[i].khz;
431 pxa255_turbo_freq_table[i].index = i; 431 pxa255_turbo_freq_table[i].driver_data = i;
432 } 432 }
433 pxa255_turbo_freq_table[i].frequency = CPUFREQ_TABLE_END; 433 pxa255_turbo_freq_table[i].frequency = CPUFREQ_TABLE_END;
434 434
@@ -440,9 +440,9 @@ static int pxa_cpufreq_init(struct cpufreq_policy *policy)
440 if (freq > pxa27x_maxfreq) 440 if (freq > pxa27x_maxfreq)
441 break; 441 break;
442 pxa27x_freq_table[i].frequency = freq; 442 pxa27x_freq_table[i].frequency = freq;
443 pxa27x_freq_table[i].index = i; 443 pxa27x_freq_table[i].driver_data = i;
444 } 444 }
445 pxa27x_freq_table[i].index = i; 445 pxa27x_freq_table[i].driver_data = i;
446 pxa27x_freq_table[i].frequency = CPUFREQ_TABLE_END; 446 pxa27x_freq_table[i].frequency = CPUFREQ_TABLE_END;
447 447
448 /* 448 /*
diff --git a/drivers/cpufreq/pxa3xx-cpufreq.c b/drivers/cpufreq/pxa3xx-cpufreq.c
index 15d60f857ad5..9c92ef032a9e 100644
--- a/drivers/cpufreq/pxa3xx-cpufreq.c
+++ b/drivers/cpufreq/pxa3xx-cpufreq.c
@@ -98,10 +98,10 @@ static int setup_freqs_table(struct cpufreq_policy *policy,
98 return -ENOMEM; 98 return -ENOMEM;
99 99
100 for (i = 0; i < num; i++) { 100 for (i = 0; i < num; i++) {
101 table[i].index = i; 101 table[i].driver_data = i;
102 table[i].frequency = freqs[i].cpufreq_mhz * 1000; 102 table[i].frequency = freqs[i].cpufreq_mhz * 1000;
103 } 103 }
104 table[num].index = i; 104 table[num].driver_data = i;
105 table[num].frequency = CPUFREQ_TABLE_END; 105 table[num].frequency = CPUFREQ_TABLE_END;
106 106
107 pxa3xx_freqs = freqs; 107 pxa3xx_freqs = freqs;
diff --git a/drivers/cpufreq/s3c2416-cpufreq.c b/drivers/cpufreq/s3c2416-cpufreq.c
index 4f1881eee3f1..e35865af96e2 100644
--- a/drivers/cpufreq/s3c2416-cpufreq.c
+++ b/drivers/cpufreq/s3c2416-cpufreq.c
@@ -244,7 +244,7 @@ static int s3c2416_cpufreq_set_target(struct cpufreq_policy *policy,
244 if (ret != 0) 244 if (ret != 0)
245 goto out; 245 goto out;
246 246
247 idx = s3c_freq->freq_table[i].index; 247 idx = s3c_freq->freq_table[i].driver_data;
248 248
249 if (idx == SOURCE_HCLK) 249 if (idx == SOURCE_HCLK)
250 to_dvs = 1; 250 to_dvs = 1;
@@ -312,7 +312,7 @@ static void __init s3c2416_cpufreq_cfg_regulator(struct s3c2416_data *s3c_freq)
312 if (freq->frequency == CPUFREQ_ENTRY_INVALID) 312 if (freq->frequency == CPUFREQ_ENTRY_INVALID)
313 continue; 313 continue;
314 314
315 dvfs = &s3c2416_dvfs_table[freq->index]; 315 dvfs = &s3c2416_dvfs_table[freq->driver_data];
316 found = 0; 316 found = 0;
317 317
318 /* Check only the min-voltage, more is always ok on S3C2416 */ 318 /* Check only the min-voltage, more is always ok on S3C2416 */
@@ -462,7 +462,7 @@ static int __init s3c2416_cpufreq_driver_init(struct cpufreq_policy *policy)
462 freq = s3c_freq->freq_table; 462 freq = s3c_freq->freq_table;
463 while (freq->frequency != CPUFREQ_TABLE_END) { 463 while (freq->frequency != CPUFREQ_TABLE_END) {
464 /* special handling for dvs mode */ 464 /* special handling for dvs mode */
465 if (freq->index == 0) { 465 if (freq->driver_data == 0) {
466 if (!s3c_freq->hclk) { 466 if (!s3c_freq->hclk) {
467 pr_debug("cpufreq: %dkHz unsupported as it would need unavailable dvs mode\n", 467 pr_debug("cpufreq: %dkHz unsupported as it would need unavailable dvs mode\n",
468 freq->frequency); 468 freq->frequency);
diff --git a/drivers/cpufreq/s3c24xx-cpufreq.c b/drivers/cpufreq/s3c24xx-cpufreq.c
index 3c0e78ede0da..3513e7477160 100644
--- a/drivers/cpufreq/s3c24xx-cpufreq.c
+++ b/drivers/cpufreq/s3c24xx-cpufreq.c
@@ -70,7 +70,7 @@ static void s3c_cpufreq_getcur(struct s3c_cpufreq_config *cfg)
70 cfg->freq.pclk = pclk = clk_get_rate(clk_pclk); 70 cfg->freq.pclk = pclk = clk_get_rate(clk_pclk);
71 cfg->freq.armclk = armclk = clk_get_rate(clk_arm); 71 cfg->freq.armclk = armclk = clk_get_rate(clk_arm);
72 72
73 cfg->pll.index = __raw_readl(S3C2410_MPLLCON); 73 cfg->pll.driver_data = __raw_readl(S3C2410_MPLLCON);
74 cfg->pll.frequency = fclk; 74 cfg->pll.frequency = fclk;
75 75
76 cfg->freq.hclk_tns = 1000000000 / (cfg->freq.hclk / 10); 76 cfg->freq.hclk_tns = 1000000000 / (cfg->freq.hclk / 10);
@@ -431,7 +431,7 @@ static unsigned int suspend_freq;
431static int s3c_cpufreq_suspend(struct cpufreq_policy *policy) 431static int s3c_cpufreq_suspend(struct cpufreq_policy *policy)
432{ 432{
433 suspend_pll.frequency = clk_get_rate(_clk_mpll); 433 suspend_pll.frequency = clk_get_rate(_clk_mpll);
434 suspend_pll.index = __raw_readl(S3C2410_MPLLCON); 434 suspend_pll.driver_data = __raw_readl(S3C2410_MPLLCON);
435 suspend_freq = s3c_cpufreq_get(0) * 1000; 435 suspend_freq = s3c_cpufreq_get(0) * 1000;
436 436
437 return 0; 437 return 0;
diff --git a/drivers/cpufreq/s3c64xx-cpufreq.c b/drivers/cpufreq/s3c64xx-cpufreq.c
index 27cacb524796..13bb4bae64ee 100644
--- a/drivers/cpufreq/s3c64xx-cpufreq.c
+++ b/drivers/cpufreq/s3c64xx-cpufreq.c
@@ -87,7 +87,7 @@ static int s3c64xx_cpufreq_set_target(struct cpufreq_policy *policy,
87 freqs.old = clk_get_rate(armclk) / 1000; 87 freqs.old = clk_get_rate(armclk) / 1000;
88 freqs.new = s3c64xx_freq_table[i].frequency; 88 freqs.new = s3c64xx_freq_table[i].frequency;
89 freqs.flags = 0; 89 freqs.flags = 0;
90 dvfs = &s3c64xx_dvfs_table[s3c64xx_freq_table[i].index]; 90 dvfs = &s3c64xx_dvfs_table[s3c64xx_freq_table[i].driver_data];
91 91
92 if (freqs.old == freqs.new) 92 if (freqs.old == freqs.new)
93 return 0; 93 return 0;
@@ -104,7 +104,8 @@ static int s3c64xx_cpufreq_set_target(struct cpufreq_policy *policy,
104 if (ret != 0) { 104 if (ret != 0) {
105 pr_err("Failed to set VDDARM for %dkHz: %d\n", 105 pr_err("Failed to set VDDARM for %dkHz: %d\n",
106 freqs.new, ret); 106 freqs.new, ret);
107 goto err; 107 freqs.new = freqs.old;
108 goto post_notify;
108 } 109 }
109 } 110 }
110#endif 111#endif
@@ -113,10 +114,13 @@ static int s3c64xx_cpufreq_set_target(struct cpufreq_policy *policy,
113 if (ret < 0) { 114 if (ret < 0) {
114 pr_err("Failed to set rate %dkHz: %d\n", 115 pr_err("Failed to set rate %dkHz: %d\n",
115 freqs.new, ret); 116 freqs.new, ret);
116 goto err; 117 freqs.new = freqs.old;
117 } 118 }
118 119
120post_notify:
119 cpufreq_notify_transition(policy, &freqs, CPUFREQ_POSTCHANGE); 121 cpufreq_notify_transition(policy, &freqs, CPUFREQ_POSTCHANGE);
122 if (ret)
123 goto err;
120 124
121#ifdef CONFIG_REGULATOR 125#ifdef CONFIG_REGULATOR
122 if (vddarm && freqs.new < freqs.old) { 126 if (vddarm && freqs.new < freqs.old) {
diff --git a/drivers/cpufreq/sc520_freq.c b/drivers/cpufreq/sc520_freq.c
index f740b134d27b..77a210975fc4 100644
--- a/drivers/cpufreq/sc520_freq.c
+++ b/drivers/cpufreq/sc520_freq.c
@@ -71,7 +71,7 @@ static void sc520_freq_set_cpu_state(struct cpufreq_policy *policy,
71 local_irq_disable(); 71 local_irq_disable();
72 72
73 clockspeed_reg = *cpuctl & ~0x03; 73 clockspeed_reg = *cpuctl & ~0x03;
74 *cpuctl = clockspeed_reg | sc520_freq_table[state].index; 74 *cpuctl = clockspeed_reg | sc520_freq_table[state].driver_data;
75 75
76 local_irq_enable(); 76 local_irq_enable();
77 77
diff --git a/drivers/cpufreq/sparc-us2e-cpufreq.c b/drivers/cpufreq/sparc-us2e-cpufreq.c
index 306ae462bba6..93061a408773 100644
--- a/drivers/cpufreq/sparc-us2e-cpufreq.c
+++ b/drivers/cpufreq/sparc-us2e-cpufreq.c
@@ -308,17 +308,17 @@ static int __init us2e_freq_cpu_init(struct cpufreq_policy *policy)
308 struct cpufreq_frequency_table *table = 308 struct cpufreq_frequency_table *table =
309 &us2e_freq_table[cpu].table[0]; 309 &us2e_freq_table[cpu].table[0];
310 310
311 table[0].index = 0; 311 table[0].driver_data = 0;
312 table[0].frequency = clock_tick / 1; 312 table[0].frequency = clock_tick / 1;
313 table[1].index = 1; 313 table[1].driver_data = 1;
314 table[1].frequency = clock_tick / 2; 314 table[1].frequency = clock_tick / 2;
315 table[2].index = 2; 315 table[2].driver_data = 2;
316 table[2].frequency = clock_tick / 4; 316 table[2].frequency = clock_tick / 4;
317 table[2].index = 3; 317 table[2].driver_data = 3;
318 table[2].frequency = clock_tick / 6; 318 table[2].frequency = clock_tick / 6;
319 table[2].index = 4; 319 table[2].driver_data = 4;
320 table[2].frequency = clock_tick / 8; 320 table[2].frequency = clock_tick / 8;
321 table[2].index = 5; 321 table[2].driver_data = 5;
322 table[3].frequency = CPUFREQ_TABLE_END; 322 table[3].frequency = CPUFREQ_TABLE_END;
323 323
324 policy->cpuinfo.transition_latency = 0; 324 policy->cpuinfo.transition_latency = 0;
diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
index c71ee142347a..880ee293d61e 100644
--- a/drivers/cpufreq/sparc-us3-cpufreq.c
+++ b/drivers/cpufreq/sparc-us3-cpufreq.c
@@ -169,13 +169,13 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
169 struct cpufreq_frequency_table *table = 169 struct cpufreq_frequency_table *table =
170 &us3_freq_table[cpu].table[0]; 170 &us3_freq_table[cpu].table[0];
171 171
172 table[0].index = 0; 172 table[0].driver_data = 0;
173 table[0].frequency = clock_tick / 1; 173 table[0].frequency = clock_tick / 1;
174 table[1].index = 1; 174 table[1].driver_data = 1;
175 table[1].frequency = clock_tick / 2; 175 table[1].frequency = clock_tick / 2;
176 table[2].index = 2; 176 table[2].driver_data = 2;
177 table[2].frequency = clock_tick / 32; 177 table[2].frequency = clock_tick / 32;
178 table[3].index = 0; 178 table[3].driver_data = 0;
179 table[3].frequency = CPUFREQ_TABLE_END; 179 table[3].frequency = CPUFREQ_TABLE_END;
180 180
181 policy->cpuinfo.transition_latency = 0; 181 policy->cpuinfo.transition_latency = 0;
diff --git a/drivers/cpufreq/spear-cpufreq.c b/drivers/cpufreq/spear-cpufreq.c
index 156829f4576d..c3efa7f2a908 100644
--- a/drivers/cpufreq/spear-cpufreq.c
+++ b/drivers/cpufreq/spear-cpufreq.c
@@ -250,11 +250,11 @@ static int spear_cpufreq_driver_init(void)
250 } 250 }
251 251
252 for (i = 0; i < cnt; i++) { 252 for (i = 0; i < cnt; i++) {
253 freq_tbl[i].index = i; 253 freq_tbl[i].driver_data = i;
254 freq_tbl[i].frequency = be32_to_cpup(val++); 254 freq_tbl[i].frequency = be32_to_cpup(val++);
255 } 255 }
256 256
257 freq_tbl[i].index = i; 257 freq_tbl[i].driver_data = i;
258 freq_tbl[i].frequency = CPUFREQ_TABLE_END; 258 freq_tbl[i].frequency = CPUFREQ_TABLE_END;
259 259
260 spear_cpufreq.freq_tbl = freq_tbl; 260 spear_cpufreq.freq_tbl = freq_tbl;
diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
index 618e6f417b1c..0915e712fbdc 100644
--- a/drivers/cpufreq/speedstep-centrino.c
+++ b/drivers/cpufreq/speedstep-centrino.c
@@ -79,11 +79,11 @@ static struct cpufreq_driver centrino_driver;
79 79
80/* Computes the correct form for IA32_PERF_CTL MSR for a particular 80/* Computes the correct form for IA32_PERF_CTL MSR for a particular
81 frequency/voltage operating point; frequency in MHz, volts in mV. 81 frequency/voltage operating point; frequency in MHz, volts in mV.
82 This is stored as "index" in the structure. */ 82 This is stored as "driver_data" in the structure. */
83#define OP(mhz, mv) \ 83#define OP(mhz, mv) \
84 { \ 84 { \
85 .frequency = (mhz) * 1000, \ 85 .frequency = (mhz) * 1000, \
86 .index = (((mhz)/100) << 8) | ((mv - 700) / 16) \ 86 .driver_data = (((mhz)/100) << 8) | ((mv - 700) / 16) \
87 } 87 }
88 88
89/* 89/*
@@ -307,7 +307,7 @@ static unsigned extract_clock(unsigned msr, unsigned int cpu, int failsafe)
307 per_cpu(centrino_model, cpu)->op_points[i].frequency 307 per_cpu(centrino_model, cpu)->op_points[i].frequency
308 != CPUFREQ_TABLE_END; 308 != CPUFREQ_TABLE_END;
309 i++) { 309 i++) {
310 if (msr == per_cpu(centrino_model, cpu)->op_points[i].index) 310 if (msr == per_cpu(centrino_model, cpu)->op_points[i].driver_data)
311 return per_cpu(centrino_model, cpu)-> 311 return per_cpu(centrino_model, cpu)->
312 op_points[i].frequency; 312 op_points[i].frequency;
313 } 313 }
@@ -501,7 +501,7 @@ static int centrino_target (struct cpufreq_policy *policy,
501 break; 501 break;
502 } 502 }
503 503
504 msr = per_cpu(centrino_model, cpu)->op_points[newstate].index; 504 msr = per_cpu(centrino_model, cpu)->op_points[newstate].driver_data;
505 505
506 if (first_cpu) { 506 if (first_cpu) {
507 rdmsr_on_cpu(good_cpu, MSR_IA32_PERF_CTL, &oldmsr, &h); 507 rdmsr_on_cpu(good_cpu, MSR_IA32_PERF_CTL, &oldmsr, &h);
diff --git a/drivers/cpufreq/tegra-cpufreq.c b/drivers/cpufreq/tegra-cpufreq.c
index c74c0e130ef4..cd66b85d927c 100644
--- a/drivers/cpufreq/tegra-cpufreq.c
+++ b/drivers/cpufreq/tegra-cpufreq.c
@@ -28,17 +28,16 @@
28#include <linux/io.h> 28#include <linux/io.h>
29#include <linux/suspend.h> 29#include <linux/suspend.h>
30 30
31/* Frequency table index must be sequential starting at 0 */
32static struct cpufreq_frequency_table freq_table[] = { 31static struct cpufreq_frequency_table freq_table[] = {
33 { 0, 216000 }, 32 { .frequency = 216000 },
34 { 1, 312000 }, 33 { .frequency = 312000 },
35 { 2, 456000 }, 34 { .frequency = 456000 },
36 { 3, 608000 }, 35 { .frequency = 608000 },
37 { 4, 760000 }, 36 { .frequency = 760000 },
38 { 5, 816000 }, 37 { .frequency = 816000 },
39 { 6, 912000 }, 38 { .frequency = 912000 },
40 { 7, 1000000 }, 39 { .frequency = 1000000 },
41 { 8, CPUFREQ_TABLE_END }, 40 { .frequency = CPUFREQ_TABLE_END },
42}; 41};
43 42
44#define NUM_CPUS 2 43#define NUM_CPUS 2
@@ -138,12 +137,12 @@ static int tegra_update_cpu_speed(struct cpufreq_policy *policy,
138 if (ret) { 137 if (ret) {
139 pr_err("cpu-tegra: Failed to set cpu frequency to %d kHz\n", 138 pr_err("cpu-tegra: Failed to set cpu frequency to %d kHz\n",
140 freqs.new); 139 freqs.new);
141 return ret; 140 freqs.new = freqs.old;
142 } 141 }
143 142
144 cpufreq_notify_transition(policy, &freqs, CPUFREQ_POSTCHANGE); 143 cpufreq_notify_transition(policy, &freqs, CPUFREQ_POSTCHANGE);
145 144
146 return 0; 145 return ret;
147} 146}
148 147
149static unsigned long tegra_cpu_highest_speed(void) 148static unsigned long tegra_cpu_highest_speed(void)
diff --git a/drivers/cpuidle/Kconfig b/drivers/cpuidle/Kconfig
index e21cdfa4002a..0e2cd5cab4d0 100644
--- a/drivers/cpuidle/Kconfig
+++ b/drivers/cpuidle/Kconfig
@@ -1,7 +1,9 @@
1 1
2config CPU_IDLE 2menuconfig CPU_IDLE
3 bool "CPU idle PM support" 3 bool "CPU idle PM support"
4 default y if ACPI || PPC_PSERIES 4 default y if ACPI || PPC_PSERIES
5 select CPU_IDLE_GOV_LADDER if (!NO_HZ && !NO_HZ_IDLE)
6 select CPU_IDLE_GOV_MENU if (NO_HZ || NO_HZ_IDLE)
5 help 7 help
6 CPU idle is a generic framework for supporting software-controlled 8 CPU idle is a generic framework for supporting software-controlled
7 idle processor power management. It includes modular cross-platform 9 idle processor power management. It includes modular cross-platform
@@ -9,9 +11,10 @@ config CPU_IDLE
9 11
10 If you're using an ACPI-enabled platform, you should say Y here. 12 If you're using an ACPI-enabled platform, you should say Y here.
11 13
14if CPU_IDLE
15
12config CPU_IDLE_MULTIPLE_DRIVERS 16config CPU_IDLE_MULTIPLE_DRIVERS
13 bool "Support multiple cpuidle drivers" 17 bool "Support multiple cpuidle drivers"
14 depends on CPU_IDLE
15 default n 18 default n
16 help 19 help
17 Allows the cpuidle framework to use different drivers for each CPU. 20 Allows the cpuidle framework to use different drivers for each CPU.
@@ -19,20 +22,13 @@ config CPU_IDLE_MULTIPLE_DRIVERS
19 states. If unsure say N. 22 states. If unsure say N.
20 23
21config CPU_IDLE_GOV_LADDER 24config CPU_IDLE_GOV_LADDER
22 bool 25 bool "Ladder governor (for periodic timer tick)"
23 depends on CPU_IDLE
24 default y 26 default y
25 27
26config CPU_IDLE_GOV_MENU 28config CPU_IDLE_GOV_MENU
27 bool 29 bool "Menu governor (for tickless system)"
28 depends on CPU_IDLE && NO_HZ
29 default y 30 default y
30 31
31config ARCH_NEEDS_CPU_IDLE_COUPLED
32 def_bool n
33
34if CPU_IDLE
35
36config CPU_IDLE_CALXEDA 32config CPU_IDLE_CALXEDA
37 bool "CPU Idle Driver for Calxeda processors" 33 bool "CPU Idle Driver for Calxeda processors"
38 depends on ARCH_HIGHBANK 34 depends on ARCH_HIGHBANK
@@ -40,4 +36,13 @@ config CPU_IDLE_CALXEDA
40 help 36 help
41 Select this to enable cpuidle on Calxeda processors. 37 Select this to enable cpuidle on Calxeda processors.
42 38
39config CPU_IDLE_ZYNQ
40 bool "CPU Idle Driver for Xilinx Zynq processors"
41 depends on ARCH_ZYNQ
42 help
43 Select this to enable cpuidle on Xilinx Zynq processors.
44
43endif 45endif
46
47config ARCH_NEEDS_CPU_IDLE_COUPLED
48 def_bool n
diff --git a/drivers/cpuidle/Makefile b/drivers/cpuidle/Makefile
index 0d8bd55e776f..8767a7b3eb91 100644
--- a/drivers/cpuidle/Makefile
+++ b/drivers/cpuidle/Makefile
@@ -7,3 +7,4 @@ obj-$(CONFIG_ARCH_NEEDS_CPU_IDLE_COUPLED) += coupled.o
7 7
8obj-$(CONFIG_CPU_IDLE_CALXEDA) += cpuidle-calxeda.o 8obj-$(CONFIG_CPU_IDLE_CALXEDA) += cpuidle-calxeda.o
9obj-$(CONFIG_ARCH_KIRKWOOD) += cpuidle-kirkwood.o 9obj-$(CONFIG_ARCH_KIRKWOOD) += cpuidle-kirkwood.o
10obj-$(CONFIG_CPU_IDLE_ZYNQ) += cpuidle-zynq.o
diff --git a/drivers/cpuidle/cpuidle-zynq.c b/drivers/cpuidle/cpuidle-zynq.c
new file mode 100644
index 000000000000..38e03a183591
--- /dev/null
+++ b/drivers/cpuidle/cpuidle-zynq.c
@@ -0,0 +1,83 @@
1/*
2 * Copyright (C) 2012-2013 Xilinx
3 *
4 * CPU idle support for Xilinx Zynq
5 *
6 * based on arch/arm/mach-at91/cpuidle.c
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms and conditions of the GNU General Public License,
10 * version 2, as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * The cpu idle uses wait-for-interrupt and RAM self refresh in order
21 * to implement two idle states -
22 * #1 wait-for-interrupt
23 * #2 wait-for-interrupt and RAM self refresh
24 *
25 * Maintainer: Michal Simek <michal.simek@xilinx.com>
26 */
27
28#include <linux/init.h>
29#include <linux/cpu_pm.h>
30#include <linux/cpuidle.h>
31#include <linux/of.h>
32#include <asm/proc-fns.h>
33#include <asm/cpuidle.h>
34
35#define ZYNQ_MAX_STATES 2
36
37/* Actual code that puts the SoC in different idle states */
38static int zynq_enter_idle(struct cpuidle_device *dev,
39 struct cpuidle_driver *drv, int index)
40{
41 /* Devices must be stopped here */
42 cpu_pm_enter();
43
44 /* Add code for DDR self refresh start */
45 cpu_do_idle();
46
47 /* Add code for DDR self refresh stop */
48 cpu_pm_exit();
49
50 return index;
51}
52
53static struct cpuidle_driver zynq_idle_driver = {
54 .name = "zynq_idle",
55 .owner = THIS_MODULE,
56 .states = {
57 ARM_CPUIDLE_WFI_STATE,
58 {
59 .enter = zynq_enter_idle,
60 .exit_latency = 10,
61 .target_residency = 10000,
62 .flags = CPUIDLE_FLAG_TIME_VALID |
63 CPUIDLE_FLAG_TIMER_STOP,
64 .name = "RAM_SR",
65 .desc = "WFI and RAM Self Refresh",
66 },
67 },
68 .safe_state_index = 0,
69 .state_count = ZYNQ_MAX_STATES,
70};
71
72/* Initialize CPU idle by registering the idle states */
73static int __init zynq_cpuidle_init(void)
74{
75 if (!of_machine_is_compatible("xlnx,zynq-7000"))
76 return -ENODEV;
77
78 pr_info("Xilinx Zynq CpuIdle Driver started\n");
79
80 return cpuidle_register(&zynq_idle_driver, NULL);
81}
82
83device_initcall(zynq_cpuidle_init);
diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
index c3a93fece819..fdc432f18022 100644
--- a/drivers/cpuidle/cpuidle.c
+++ b/drivers/cpuidle/cpuidle.c
@@ -466,7 +466,7 @@ void cpuidle_unregister(struct cpuidle_driver *drv)
466 int cpu; 466 int cpu;
467 struct cpuidle_device *device; 467 struct cpuidle_device *device;
468 468
469 for_each_possible_cpu(cpu) { 469 for_each_cpu(cpu, drv->cpumask) {
470 device = &per_cpu(cpuidle_dev, cpu); 470 device = &per_cpu(cpuidle_dev, cpu);
471 cpuidle_unregister_device(device); 471 cpuidle_unregister_device(device);
472 } 472 }
@@ -498,7 +498,7 @@ int cpuidle_register(struct cpuidle_driver *drv,
498 return ret; 498 return ret;
499 } 499 }
500 500
501 for_each_possible_cpu(cpu) { 501 for_each_cpu(cpu, drv->cpumask) {
502 device = &per_cpu(cpuidle_dev, cpu); 502 device = &per_cpu(cpuidle_dev, cpu);
503 device->cpu = cpu; 503 device->cpu = cpu;
504 504
diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
index 8dfaaae94444..3ac499d5a207 100644
--- a/drivers/cpuidle/driver.c
+++ b/drivers/cpuidle/driver.c
@@ -18,182 +18,249 @@
18 18
19DEFINE_SPINLOCK(cpuidle_driver_lock); 19DEFINE_SPINLOCK(cpuidle_driver_lock);
20 20
21static void __cpuidle_set_cpu_driver(struct cpuidle_driver *drv, int cpu); 21#ifdef CONFIG_CPU_IDLE_MULTIPLE_DRIVERS
22static struct cpuidle_driver * __cpuidle_get_cpu_driver(int cpu);
23 22
24static void cpuidle_setup_broadcast_timer(void *arg) 23static DEFINE_PER_CPU(struct cpuidle_driver *, cpuidle_drivers);
24
25/**
26 * __cpuidle_get_cpu_driver - return the cpuidle driver tied to a CPU.
27 * @cpu: the CPU handled by the driver
28 *
29 * Returns a pointer to struct cpuidle_driver or NULL if no driver has been
30 * registered for @cpu.
31 */
32static struct cpuidle_driver *__cpuidle_get_cpu_driver(int cpu)
25{ 33{
26 int cpu = smp_processor_id(); 34 return per_cpu(cpuidle_drivers, cpu);
27 clockevents_notify((long)(arg), &cpu);
28} 35}
29 36
30static void __cpuidle_driver_init(struct cpuidle_driver *drv, int cpu) 37/**
38 * __cpuidle_unset_driver - unset per CPU driver variables.
39 * @drv: a valid pointer to a struct cpuidle_driver
40 *
41 * For each CPU in the driver's CPU mask, unset the registered driver per CPU
42 * variable. If @drv is different from the registered driver, the corresponding
43 * variable is not cleared.
44 */
45static inline void __cpuidle_unset_driver(struct cpuidle_driver *drv)
31{ 46{
32 int i; 47 int cpu;
33
34 drv->refcnt = 0;
35 48
36 for (i = drv->state_count - 1; i >= 0 ; i--) { 49 for_each_cpu(cpu, drv->cpumask) {
37 50
38 if (!(drv->states[i].flags & CPUIDLE_FLAG_TIMER_STOP)) 51 if (drv != __cpuidle_get_cpu_driver(cpu))
39 continue; 52 continue;
40 53
41 drv->bctimer = 1; 54 per_cpu(cpuidle_drivers, cpu) = NULL;
42 on_each_cpu_mask(get_cpu_mask(cpu), cpuidle_setup_broadcast_timer,
43 (void *)CLOCK_EVT_NOTIFY_BROADCAST_ON, 1);
44 break;
45 } 55 }
46} 56}
47 57
48static int __cpuidle_register_driver(struct cpuidle_driver *drv, int cpu) 58/**
59 * __cpuidle_set_driver - set per CPU driver variables the the given driver.
60 * @drv: a valid pointer to a struct cpuidle_driver
61 *
62 * For each CPU in the driver's cpumask, unset the registered driver per CPU
63 * to @drv.
64 *
65 * Returns 0 on success, -EBUSY if the CPUs have driver(s) already.
66 */
67static inline int __cpuidle_set_driver(struct cpuidle_driver *drv)
49{ 68{
50 if (!drv || !drv->state_count) 69 int cpu;
51 return -EINVAL;
52
53 if (cpuidle_disabled())
54 return -ENODEV;
55 70
56 if (__cpuidle_get_cpu_driver(cpu)) 71 for_each_cpu(cpu, drv->cpumask) {
57 return -EBUSY;
58 72
59 __cpuidle_driver_init(drv, cpu); 73 if (__cpuidle_get_cpu_driver(cpu)) {
74 __cpuidle_unset_driver(drv);
75 return -EBUSY;
76 }
60 77
61 __cpuidle_set_cpu_driver(drv, cpu); 78 per_cpu(cpuidle_drivers, cpu) = drv;
79 }
62 80
63 return 0; 81 return 0;
64} 82}
65 83
66static void __cpuidle_unregister_driver(struct cpuidle_driver *drv, int cpu) 84#else
67{
68 if (drv != __cpuidle_get_cpu_driver(cpu))
69 return;
70 85
71 if (!WARN_ON(drv->refcnt > 0)) 86static struct cpuidle_driver *cpuidle_curr_driver;
72 __cpuidle_set_cpu_driver(NULL, cpu);
73 87
74 if (drv->bctimer) { 88/**
75 drv->bctimer = 0; 89 * __cpuidle_get_cpu_driver - return the global cpuidle driver pointer.
76 on_each_cpu_mask(get_cpu_mask(cpu), cpuidle_setup_broadcast_timer, 90 * @cpu: ignored without the multiple driver support
77 (void *)CLOCK_EVT_NOTIFY_BROADCAST_OFF, 1); 91 *
78 } 92 * Return a pointer to a struct cpuidle_driver object or NULL if no driver was
93 * previously registered.
94 */
95static inline struct cpuidle_driver *__cpuidle_get_cpu_driver(int cpu)
96{
97 return cpuidle_curr_driver;
79} 98}
80 99
81#ifdef CONFIG_CPU_IDLE_MULTIPLE_DRIVERS 100/**
101 * __cpuidle_set_driver - assign the global cpuidle driver variable.
102 * @drv: pointer to a struct cpuidle_driver object
103 *
104 * Returns 0 on success, -EBUSY if the driver is already registered.
105 */
106static inline int __cpuidle_set_driver(struct cpuidle_driver *drv)
107{
108 if (cpuidle_curr_driver)
109 return -EBUSY;
82 110
83static DEFINE_PER_CPU(struct cpuidle_driver *, cpuidle_drivers); 111 cpuidle_curr_driver = drv;
84 112
85static void __cpuidle_set_cpu_driver(struct cpuidle_driver *drv, int cpu) 113 return 0;
86{
87 per_cpu(cpuidle_drivers, cpu) = drv;
88} 114}
89 115
90static struct cpuidle_driver *__cpuidle_get_cpu_driver(int cpu) 116/**
117 * __cpuidle_unset_driver - unset the global cpuidle driver variable.
118 * @drv: a pointer to a struct cpuidle_driver
119 *
120 * Reset the global cpuidle variable to NULL. If @drv does not match the
121 * registered driver, do nothing.
122 */
123static inline void __cpuidle_unset_driver(struct cpuidle_driver *drv)
91{ 124{
92 return per_cpu(cpuidle_drivers, cpu); 125 if (drv == cpuidle_curr_driver)
126 cpuidle_curr_driver = NULL;
93} 127}
94 128
95static void __cpuidle_unregister_all_cpu_driver(struct cpuidle_driver *drv) 129#endif
130
131/**
132 * cpuidle_setup_broadcast_timer - enable/disable the broadcast timer
133 * @arg: a void pointer used to match the SMP cross call API
134 *
135 * @arg is used as a value of type 'long' with on of the two values:
136 * - CLOCK_EVT_NOTIFY_BROADCAST_ON
137 * - CLOCK_EVT_NOTIFY_BROADCAST_OFF
138 *
139 * Set the broadcast timer notification for the current CPU. This function
140 * is executed per CPU by an SMP cross call. It not supposed to be called
141 * directly.
142 */
143static void cpuidle_setup_broadcast_timer(void *arg)
96{ 144{
97 int cpu; 145 int cpu = smp_processor_id();
98 for_each_present_cpu(cpu) 146 clockevents_notify((long)(arg), &cpu);
99 __cpuidle_unregister_driver(drv, cpu);
100} 147}
101 148
102static int __cpuidle_register_all_cpu_driver(struct cpuidle_driver *drv) 149/**
150 * __cpuidle_driver_init - initialize the driver's internal data
151 * @drv: a valid pointer to a struct cpuidle_driver
152 *
153 * Returns 0 on success, a negative error code otherwise.
154 */
155static int __cpuidle_driver_init(struct cpuidle_driver *drv)
103{ 156{
104 int ret = 0; 157 int i;
105 int i, cpu;
106 158
107 for_each_present_cpu(cpu) { 159 drv->refcnt = 0;
108 ret = __cpuidle_register_driver(drv, cpu);
109 if (ret)
110 break;
111 }
112 160
113 if (ret) 161 /*
114 for_each_present_cpu(i) { 162 * Use all possible CPUs as the default, because if the kernel boots
115 if (i == cpu) 163 * with some CPUs offline and then we online one of them, the CPU
116 break; 164 * notifier has to know which driver to assign.
117 __cpuidle_unregister_driver(drv, i); 165 */
118 } 166 if (!drv->cpumask)
167 drv->cpumask = (struct cpumask *)cpu_possible_mask;
168
169 /*
170 * Look for the timer stop flag in the different states, so that we know
171 * if the broadcast timer has to be set up. The loop is in the reverse
172 * order, because usually on of the the deeper states has this flag set.
173 */
174 for (i = drv->state_count - 1; i >= 0 ; i--) {
119 175
176 if (!(drv->states[i].flags & CPUIDLE_FLAG_TIMER_STOP))
177 continue;
120 178
121 return ret; 179 drv->bctimer = 1;
180 break;
181 }
182
183 return 0;
122} 184}
123 185
124int cpuidle_register_cpu_driver(struct cpuidle_driver *drv, int cpu) 186/**
187 * __cpuidle_register_driver: register the driver
188 * @drv: a valid pointer to a struct cpuidle_driver
189 *
190 * Do some sanity checks, initialize the driver, assign the driver to the
191 * global cpuidle driver variable(s) and set up the broadcast timer if the
192 * cpuidle driver has some states that shut down the local timer.
193 *
194 * Returns 0 on success, a negative error code otherwise:
195 * * -EINVAL if the driver pointer is NULL or no idle states are available
196 * * -ENODEV if the cpuidle framework is disabled
197 * * -EBUSY if the driver is already assigned to the global variable(s)
198 */
199static int __cpuidle_register_driver(struct cpuidle_driver *drv)
125{ 200{
126 int ret; 201 int ret;
127 202
128 spin_lock(&cpuidle_driver_lock); 203 if (!drv || !drv->state_count)
129 ret = __cpuidle_register_driver(drv, cpu); 204 return -EINVAL;
130 spin_unlock(&cpuidle_driver_lock);
131 205
132 return ret; 206 if (cpuidle_disabled())
133} 207 return -ENODEV;
134 208
135void cpuidle_unregister_cpu_driver(struct cpuidle_driver *drv, int cpu) 209 ret = __cpuidle_driver_init(drv);
136{ 210 if (ret)
137 spin_lock(&cpuidle_driver_lock); 211 return ret;
138 __cpuidle_unregister_driver(drv, cpu);
139 spin_unlock(&cpuidle_driver_lock);
140}
141 212
142/** 213 ret = __cpuidle_set_driver(drv);
143 * cpuidle_register_driver - registers a driver 214 if (ret)
144 * @drv: the driver 215 return ret;
145 */
146int cpuidle_register_driver(struct cpuidle_driver *drv)
147{
148 int ret;
149 216
150 spin_lock(&cpuidle_driver_lock); 217 if (drv->bctimer)
151 ret = __cpuidle_register_all_cpu_driver(drv); 218 on_each_cpu_mask(drv->cpumask, cpuidle_setup_broadcast_timer,
152 spin_unlock(&cpuidle_driver_lock); 219 (void *)CLOCK_EVT_NOTIFY_BROADCAST_ON, 1);
153 220
154 return ret; 221 return 0;
155} 222}
156EXPORT_SYMBOL_GPL(cpuidle_register_driver);
157 223
158/** 224/**
159 * cpuidle_unregister_driver - unregisters a driver 225 * __cpuidle_unregister_driver - unregister the driver
160 * @drv: the driver 226 * @drv: a valid pointer to a struct cpuidle_driver
227 *
228 * Check if the driver is no longer in use, reset the global cpuidle driver
229 * variable(s) and disable the timer broadcast notification mechanism if it was
230 * in use.
231 *
161 */ 232 */
162void cpuidle_unregister_driver(struct cpuidle_driver *drv) 233static void __cpuidle_unregister_driver(struct cpuidle_driver *drv)
163{ 234{
164 spin_lock(&cpuidle_driver_lock); 235 if (WARN_ON(drv->refcnt > 0))
165 __cpuidle_unregister_all_cpu_driver(drv); 236 return;
166 spin_unlock(&cpuidle_driver_lock);
167}
168EXPORT_SYMBOL_GPL(cpuidle_unregister_driver);
169
170#else
171
172static struct cpuidle_driver *cpuidle_curr_driver;
173 237
174static inline void __cpuidle_set_cpu_driver(struct cpuidle_driver *drv, int cpu) 238 if (drv->bctimer) {
175{ 239 drv->bctimer = 0;
176 cpuidle_curr_driver = drv; 240 on_each_cpu_mask(drv->cpumask, cpuidle_setup_broadcast_timer,
177} 241 (void *)CLOCK_EVT_NOTIFY_BROADCAST_OFF, 1);
242 }
178 243
179static inline struct cpuidle_driver *__cpuidle_get_cpu_driver(int cpu) 244 __cpuidle_unset_driver(drv);
180{
181 return cpuidle_curr_driver;
182} 245}
183 246
184/** 247/**
185 * cpuidle_register_driver - registers a driver 248 * cpuidle_register_driver - registers a driver
186 * @drv: the driver 249 * @drv: a pointer to a valid struct cpuidle_driver
250 *
251 * Register the driver under a lock to prevent concurrent attempts to
252 * [un]register the driver from occuring at the same time.
253 *
254 * Returns 0 on success, a negative error code (returned by
255 * __cpuidle_register_driver()) otherwise.
187 */ 256 */
188int cpuidle_register_driver(struct cpuidle_driver *drv) 257int cpuidle_register_driver(struct cpuidle_driver *drv)
189{ 258{
190 int ret, cpu; 259 int ret;
191 260
192 cpu = get_cpu();
193 spin_lock(&cpuidle_driver_lock); 261 spin_lock(&cpuidle_driver_lock);
194 ret = __cpuidle_register_driver(drv, cpu); 262 ret = __cpuidle_register_driver(drv);
195 spin_unlock(&cpuidle_driver_lock); 263 spin_unlock(&cpuidle_driver_lock);
196 put_cpu();
197 264
198 return ret; 265 return ret;
199} 266}
@@ -201,23 +268,24 @@ EXPORT_SYMBOL_GPL(cpuidle_register_driver);
201 268
202/** 269/**
203 * cpuidle_unregister_driver - unregisters a driver 270 * cpuidle_unregister_driver - unregisters a driver
204 * @drv: the driver 271 * @drv: a pointer to a valid struct cpuidle_driver
272 *
273 * Unregisters the cpuidle driver under a lock to prevent concurrent attempts
274 * to [un]register the driver from occuring at the same time. @drv has to
275 * match the currently registered driver.
205 */ 276 */
206void cpuidle_unregister_driver(struct cpuidle_driver *drv) 277void cpuidle_unregister_driver(struct cpuidle_driver *drv)
207{ 278{
208 int cpu;
209
210 cpu = get_cpu();
211 spin_lock(&cpuidle_driver_lock); 279 spin_lock(&cpuidle_driver_lock);
212 __cpuidle_unregister_driver(drv, cpu); 280 __cpuidle_unregister_driver(drv);
213 spin_unlock(&cpuidle_driver_lock); 281 spin_unlock(&cpuidle_driver_lock);
214 put_cpu();
215} 282}
216EXPORT_SYMBOL_GPL(cpuidle_unregister_driver); 283EXPORT_SYMBOL_GPL(cpuidle_unregister_driver);
217#endif
218 284
219/** 285/**
220 * cpuidle_get_driver - return the current driver 286 * cpuidle_get_driver - return the driver tied to the current CPU.
287 *
288 * Returns a struct cpuidle_driver pointer, or NULL if no driver is registered.
221 */ 289 */
222struct cpuidle_driver *cpuidle_get_driver(void) 290struct cpuidle_driver *cpuidle_get_driver(void)
223{ 291{
@@ -233,7 +301,11 @@ struct cpuidle_driver *cpuidle_get_driver(void)
233EXPORT_SYMBOL_GPL(cpuidle_get_driver); 301EXPORT_SYMBOL_GPL(cpuidle_get_driver);
234 302
235/** 303/**
236 * cpuidle_get_cpu_driver - return the driver tied with a cpu 304 * cpuidle_get_cpu_driver - return the driver registered for a CPU.
305 * @dev: a valid pointer to a struct cpuidle_device
306 *
307 * Returns a struct cpuidle_driver pointer, or NULL if no driver is registered
308 * for the CPU associated with @dev.
237 */ 309 */
238struct cpuidle_driver *cpuidle_get_cpu_driver(struct cpuidle_device *dev) 310struct cpuidle_driver *cpuidle_get_cpu_driver(struct cpuidle_device *dev)
239{ 311{
@@ -244,6 +316,14 @@ struct cpuidle_driver *cpuidle_get_cpu_driver(struct cpuidle_device *dev)
244} 316}
245EXPORT_SYMBOL_GPL(cpuidle_get_cpu_driver); 317EXPORT_SYMBOL_GPL(cpuidle_get_cpu_driver);
246 318
319/**
320 * cpuidle_driver_ref - get a reference to the driver.
321 *
322 * Increment the reference counter of the cpuidle driver associated with
323 * the current CPU.
324 *
325 * Returns a pointer to the driver, or NULL if the current CPU has no driver.
326 */
247struct cpuidle_driver *cpuidle_driver_ref(void) 327struct cpuidle_driver *cpuidle_driver_ref(void)
248{ 328{
249 struct cpuidle_driver *drv; 329 struct cpuidle_driver *drv;
@@ -257,6 +337,12 @@ struct cpuidle_driver *cpuidle_driver_ref(void)
257 return drv; 337 return drv;
258} 338}
259 339
340/**
341 * cpuidle_driver_unref - puts down the refcount for the driver
342 *
343 * Decrement the reference counter of the cpuidle driver associated with
344 * the current CPU.
345 */
260void cpuidle_driver_unref(void) 346void cpuidle_driver_unref(void)
261{ 347{
262 struct cpuidle_driver *drv = cpuidle_get_driver(); 348 struct cpuidle_driver *drv = cpuidle_get_driver();
diff --git a/drivers/devfreq/Kconfig b/drivers/devfreq/Kconfig
index 0f079be13305..31f3adba4cf3 100644
--- a/drivers/devfreq/Kconfig
+++ b/drivers/devfreq/Kconfig
@@ -67,7 +67,7 @@ comment "DEVFREQ Drivers"
67 67
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 || CPU_EXYNOS4212 || CPU_EXYNOS4412 70 depends on CPU_EXYNOS4210 || SOC_EXYNOS4212 || SOC_EXYNOS4412
71 select ARCH_HAS_OPP 71 select ARCH_HAS_OPP
72 select DEVFREQ_GOV_SIMPLE_ONDEMAND 72 select DEVFREQ_GOV_SIMPLE_ONDEMAND
73 help 73 help
@@ -78,4 +78,14 @@ config ARM_EXYNOS4_BUS_DEVFREQ
78 To operate with optimal voltages, ASV support is required 78 To operate with optimal voltages, ASV support is required
79 (CONFIG_EXYNOS_ASV). 79 (CONFIG_EXYNOS_ASV).
80 80
81config ARM_EXYNOS5_BUS_DEVFREQ
82 bool "ARM Exynos5250 Bus DEVFREQ Driver"
83 depends on SOC_EXYNOS5250
84 select ARCH_HAS_OPP
85 select DEVFREQ_GOV_SIMPLE_ONDEMAND
86 help
87 This adds the DEVFREQ driver for Exynos5250 bus interface (vdd_int).
88 It reads PPMU counters of memory controllers and adjusts the
89 operating frequencies and voltages with OPP support.
90
81endif # PM_DEVFREQ 91endif # PM_DEVFREQ
diff --git a/drivers/devfreq/Makefile b/drivers/devfreq/Makefile
index 8c464234f7e7..16138c9e0d58 100644
--- a/drivers/devfreq/Makefile
+++ b/drivers/devfreq/Makefile
@@ -5,4 +5,5 @@ obj-$(CONFIG_DEVFREQ_GOV_POWERSAVE) += governor_powersave.o
5obj-$(CONFIG_DEVFREQ_GOV_USERSPACE) += governor_userspace.o 5obj-$(CONFIG_DEVFREQ_GOV_USERSPACE) += governor_userspace.o
6 6
7# DEVFREQ Drivers 7# DEVFREQ Drivers
8obj-$(CONFIG_ARM_EXYNOS4_BUS_DEVFREQ) += exynos4_bus.o 8obj-$(CONFIG_ARM_EXYNOS4_BUS_DEVFREQ) += exynos/
9obj-$(CONFIG_ARM_EXYNOS5_BUS_DEVFREQ) += exynos/
diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
index 3b367973a802..44c407986f64 100644
--- a/drivers/devfreq/devfreq.c
+++ b/drivers/devfreq/devfreq.c
@@ -271,6 +271,7 @@ void devfreq_monitor_suspend(struct devfreq *devfreq)
271 return; 271 return;
272 } 272 }
273 273
274 devfreq_update_status(devfreq, devfreq->previous_freq);
274 devfreq->stop_polling = true; 275 devfreq->stop_polling = true;
275 mutex_unlock(&devfreq->lock); 276 mutex_unlock(&devfreq->lock);
276 cancel_delayed_work_sync(&devfreq->work); 277 cancel_delayed_work_sync(&devfreq->work);
@@ -287,6 +288,8 @@ EXPORT_SYMBOL(devfreq_monitor_suspend);
287 */ 288 */
288void devfreq_monitor_resume(struct devfreq *devfreq) 289void devfreq_monitor_resume(struct devfreq *devfreq)
289{ 290{
291 unsigned long freq;
292
290 mutex_lock(&devfreq->lock); 293 mutex_lock(&devfreq->lock);
291 if (!devfreq->stop_polling) 294 if (!devfreq->stop_polling)
292 goto out; 295 goto out;
@@ -295,8 +298,14 @@ void devfreq_monitor_resume(struct devfreq *devfreq)
295 devfreq->profile->polling_ms) 298 devfreq->profile->polling_ms)
296 queue_delayed_work(devfreq_wq, &devfreq->work, 299 queue_delayed_work(devfreq_wq, &devfreq->work,
297 msecs_to_jiffies(devfreq->profile->polling_ms)); 300 msecs_to_jiffies(devfreq->profile->polling_ms));
301
302 devfreq->last_stat_updated = jiffies;
298 devfreq->stop_polling = false; 303 devfreq->stop_polling = false;
299 304
305 if (devfreq->profile->get_cur_freq &&
306 !devfreq->profile->get_cur_freq(devfreq->dev.parent, &freq))
307 devfreq->previous_freq = freq;
308
300out: 309out:
301 mutex_unlock(&devfreq->lock); 310 mutex_unlock(&devfreq->lock);
302} 311}
@@ -518,6 +527,8 @@ EXPORT_SYMBOL(devfreq_add_device);
518/** 527/**
519 * devfreq_remove_device() - Remove devfreq feature from a device. 528 * devfreq_remove_device() - Remove devfreq feature from a device.
520 * @devfreq: the devfreq instance to be removed 529 * @devfreq: the devfreq instance to be removed
530 *
531 * The opposite of devfreq_add_device().
521 */ 532 */
522int devfreq_remove_device(struct devfreq *devfreq) 533int devfreq_remove_device(struct devfreq *devfreq)
523{ 534{
@@ -533,6 +544,10 @@ EXPORT_SYMBOL(devfreq_remove_device);
533/** 544/**
534 * devfreq_suspend_device() - Suspend devfreq of a device. 545 * devfreq_suspend_device() - Suspend devfreq of a device.
535 * @devfreq: the devfreq instance to be suspended 546 * @devfreq: the devfreq instance to be suspended
547 *
548 * This function is intended to be called by the pm callbacks
549 * (e.g., runtime_suspend, suspend) of the device driver that
550 * holds the devfreq.
536 */ 551 */
537int devfreq_suspend_device(struct devfreq *devfreq) 552int devfreq_suspend_device(struct devfreq *devfreq)
538{ 553{
@@ -550,6 +565,10 @@ EXPORT_SYMBOL(devfreq_suspend_device);
550/** 565/**
551 * devfreq_resume_device() - Resume devfreq of a device. 566 * devfreq_resume_device() - Resume devfreq of a device.
552 * @devfreq: the devfreq instance to be resumed 567 * @devfreq: the devfreq instance to be resumed
568 *
569 * This function is intended to be called by the pm callbacks
570 * (e.g., runtime_resume, resume) of the device driver that
571 * holds the devfreq.
553 */ 572 */
554int devfreq_resume_device(struct devfreq *devfreq) 573int devfreq_resume_device(struct devfreq *devfreq)
555{ 574{
@@ -905,11 +924,11 @@ static ssize_t show_trans_table(struct device *dev, struct device_attribute *att
905{ 924{
906 struct devfreq *devfreq = to_devfreq(dev); 925 struct devfreq *devfreq = to_devfreq(dev);
907 ssize_t len; 926 ssize_t len;
908 int i, j, err; 927 int i, j;
909 unsigned int max_state = devfreq->profile->max_state; 928 unsigned int max_state = devfreq->profile->max_state;
910 929
911 err = devfreq_update_status(devfreq, devfreq->previous_freq); 930 if (!devfreq->stop_polling &&
912 if (err) 931 devfreq_update_status(devfreq, devfreq->previous_freq))
913 return 0; 932 return 0;
914 933
915 len = sprintf(buf, " From : To\n"); 934 len = sprintf(buf, " From : To\n");
diff --git a/drivers/devfreq/exynos/Makefile b/drivers/devfreq/exynos/Makefile
new file mode 100644
index 000000000000..bfaaf5b0d61d
--- /dev/null
+++ b/drivers/devfreq/exynos/Makefile
@@ -0,0 +1,3 @@
1# Exynos DEVFREQ Drivers
2obj-$(CONFIG_ARM_EXYNOS4_BUS_DEVFREQ) += exynos4_bus.o
3obj-$(CONFIG_ARM_EXYNOS5_BUS_DEVFREQ) += exynos_ppmu.o exynos5_bus.o
diff --git a/drivers/devfreq/exynos4_bus.c b/drivers/devfreq/exynos/exynos4_bus.c
index 3f37f3b3f268..c5f86d8caca3 100644
--- a/drivers/devfreq/exynos4_bus.c
+++ b/drivers/devfreq/exynos/exynos4_bus.c
@@ -974,6 +974,7 @@ static int exynos4_busfreq_pm_notifier_event(struct notifier_block *this,
974 rcu_read_unlock(); 974 rcu_read_unlock();
975 dev_err(data->dev, "%s: unable to find a min freq\n", 975 dev_err(data->dev, "%s: unable to find a min freq\n",
976 __func__); 976 __func__);
977 mutex_unlock(&data->lock);
977 return PTR_ERR(opp); 978 return PTR_ERR(opp);
978 } 979 }
979 new_oppinfo.rate = opp_get_freq(opp); 980 new_oppinfo.rate = opp_get_freq(opp);
diff --git a/drivers/devfreq/exynos/exynos5_bus.c b/drivers/devfreq/exynos/exynos5_bus.c
new file mode 100644
index 000000000000..574b16b59be5
--- /dev/null
+++ b/drivers/devfreq/exynos/exynos5_bus.c
@@ -0,0 +1,503 @@
1/*
2 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 * http://www.samsung.com/
4 *
5 * EXYNOS5 INT clock frequency scaling support using DEVFREQ framework
6 * Based on work done by Jonghwan Choi <jhbird.choi@samsung.com>
7 * Support for only EXYNOS5250 is present.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 *
13 */
14
15#include <linux/module.h>
16#include <linux/devfreq.h>
17#include <linux/io.h>
18#include <linux/opp.h>
19#include <linux/slab.h>
20#include <linux/suspend.h>
21#include <linux/opp.h>
22#include <linux/clk.h>
23#include <linux/delay.h>
24#include <linux/platform_device.h>
25#include <linux/pm_qos.h>
26#include <linux/regulator/consumer.h>
27#include <linux/of_address.h>
28#include <linux/of_platform.h>
29
30#include "exynos_ppmu.h"
31
32#define MAX_SAFEVOLT 1100000 /* 1.10V */
33/* Assume that the bus is saturated if the utilization is 25% */
34#define INT_BUS_SATURATION_RATIO 25
35
36enum int_level_idx {
37 LV_0,
38 LV_1,
39 LV_2,
40 LV_3,
41 LV_4,
42 _LV_END
43};
44
45enum exynos_ppmu_list {
46 PPMU_RIGHT,
47 PPMU_END,
48};
49
50struct busfreq_data_int {
51 struct device *dev;
52 struct devfreq *devfreq;
53 struct regulator *vdd_int;
54 struct exynos_ppmu ppmu[PPMU_END];
55 unsigned long curr_freq;
56 bool disabled;
57
58 struct notifier_block pm_notifier;
59 struct mutex lock;
60 struct pm_qos_request int_req;
61 struct clk *int_clk;
62};
63
64struct int_bus_opp_table {
65 unsigned int idx;
66 unsigned long clk;
67 unsigned long volt;
68};
69
70static struct int_bus_opp_table exynos5_int_opp_table[] = {
71 {LV_0, 266000, 1025000},
72 {LV_1, 200000, 1025000},
73 {LV_2, 160000, 1025000},
74 {LV_3, 133000, 1025000},
75 {LV_4, 100000, 1025000},
76 {0, 0, 0},
77};
78
79static void busfreq_mon_reset(struct busfreq_data_int *data)
80{
81 unsigned int i;
82
83 for (i = PPMU_RIGHT; i < PPMU_END; i++) {
84 void __iomem *ppmu_base = data->ppmu[i].hw_base;
85
86 /* Reset the performance and cycle counters */
87 exynos_ppmu_reset(ppmu_base);
88
89 /* Setup count registers to monitor read/write transactions */
90 data->ppmu[i].event[PPMU_PMNCNT3] = RDWR_DATA_COUNT;
91 exynos_ppmu_setevent(ppmu_base, PPMU_PMNCNT3,
92 data->ppmu[i].event[PPMU_PMNCNT3]);
93
94 exynos_ppmu_start(ppmu_base);
95 }
96}
97
98static void exynos5_read_ppmu(struct busfreq_data_int *data)
99{
100 int i, j;
101
102 for (i = PPMU_RIGHT; i < PPMU_END; i++) {
103 void __iomem *ppmu_base = data->ppmu[i].hw_base;
104
105 exynos_ppmu_stop(ppmu_base);
106
107 /* Update local data from PPMU */
108 data->ppmu[i].ccnt = __raw_readl(ppmu_base + PPMU_CCNT);
109
110 for (j = PPMU_PMNCNT0; j < PPMU_PMNCNT_MAX; j++) {
111 if (data->ppmu[i].event[j] == 0)
112 data->ppmu[i].count[j] = 0;
113 else
114 data->ppmu[i].count[j] =
115 exynos_ppmu_read(ppmu_base, j);
116 }
117 }
118
119 busfreq_mon_reset(data);
120}
121
122static int exynos5_int_setvolt(struct busfreq_data_int *data,
123 unsigned long volt)
124{
125 return regulator_set_voltage(data->vdd_int, volt, MAX_SAFEVOLT);
126}
127
128static int exynos5_busfreq_int_target(struct device *dev, unsigned long *_freq,
129 u32 flags)
130{
131 int err = 0;
132 struct platform_device *pdev = container_of(dev, struct platform_device,
133 dev);
134 struct busfreq_data_int *data = platform_get_drvdata(pdev);
135 struct opp *opp;
136 unsigned long old_freq, freq;
137 unsigned long volt;
138
139 rcu_read_lock();
140 opp = devfreq_recommended_opp(dev, _freq, flags);
141 if (IS_ERR(opp)) {
142 rcu_read_unlock();
143 dev_err(dev, "%s: Invalid OPP.\n", __func__);
144 return PTR_ERR(opp);
145 }
146
147 freq = opp_get_freq(opp);
148 volt = opp_get_voltage(opp);
149 rcu_read_unlock();
150
151 old_freq = data->curr_freq;
152
153 if (old_freq == freq)
154 return 0;
155
156 dev_dbg(dev, "targetting %lukHz %luuV\n", freq, volt);
157
158 mutex_lock(&data->lock);
159
160 if (data->disabled)
161 goto out;
162
163 if (freq > exynos5_int_opp_table[0].clk)
164 pm_qos_update_request(&data->int_req, freq * 16 / 1000);
165 else
166 pm_qos_update_request(&data->int_req, -1);
167
168 if (old_freq < freq)
169 err = exynos5_int_setvolt(data, volt);
170 if (err)
171 goto out;
172
173 err = clk_set_rate(data->int_clk, freq * 1000);
174
175 if (err)
176 goto out;
177
178 if (old_freq > freq)
179 err = exynos5_int_setvolt(data, volt);
180 if (err)
181 goto out;
182
183 data->curr_freq = freq;
184out:
185 mutex_unlock(&data->lock);
186 return err;
187}
188
189static int exynos5_get_busier_dmc(struct busfreq_data_int *data)
190{
191 int i, j;
192 int busy = 0;
193 unsigned int temp = 0;
194
195 for (i = PPMU_RIGHT; i < PPMU_END; i++) {
196 for (j = PPMU_PMNCNT0; j < PPMU_PMNCNT_MAX; j++) {
197 if (data->ppmu[i].count[j] > temp) {
198 temp = data->ppmu[i].count[j];
199 busy = i;
200 }
201 }
202 }
203
204 return busy;
205}
206
207static int exynos5_int_get_dev_status(struct device *dev,
208 struct devfreq_dev_status *stat)
209{
210 struct platform_device *pdev = container_of(dev, struct platform_device,
211 dev);
212 struct busfreq_data_int *data = platform_get_drvdata(pdev);
213 int busier_dmc;
214
215 exynos5_read_ppmu(data);
216 busier_dmc = exynos5_get_busier_dmc(data);
217
218 stat->current_frequency = data->curr_freq;
219
220 /* Number of cycles spent on memory access */
221 stat->busy_time = data->ppmu[busier_dmc].count[PPMU_PMNCNT3];
222 stat->busy_time *= 100 / INT_BUS_SATURATION_RATIO;
223 stat->total_time = data->ppmu[busier_dmc].ccnt;
224
225 return 0;
226}
227static void exynos5_int_exit(struct device *dev)
228{
229 struct platform_device *pdev = container_of(dev, struct platform_device,
230 dev);
231 struct busfreq_data_int *data = platform_get_drvdata(pdev);
232
233 devfreq_unregister_opp_notifier(dev, data->devfreq);
234}
235
236static struct devfreq_dev_profile exynos5_devfreq_int_profile = {
237 .initial_freq = 160000,
238 .polling_ms = 100,
239 .target = exynos5_busfreq_int_target,
240 .get_dev_status = exynos5_int_get_dev_status,
241 .exit = exynos5_int_exit,
242};
243
244static int exynos5250_init_int_tables(struct busfreq_data_int *data)
245{
246 int i, err = 0;
247
248 for (i = LV_0; i < _LV_END; i++) {
249 err = opp_add(data->dev, exynos5_int_opp_table[i].clk,
250 exynos5_int_opp_table[i].volt);
251 if (err) {
252 dev_err(data->dev, "Cannot add opp entries.\n");
253 return err;
254 }
255 }
256
257 return 0;
258}
259
260static int exynos5_busfreq_int_pm_notifier_event(struct notifier_block *this,
261 unsigned long event, void *ptr)
262{
263 struct busfreq_data_int *data = container_of(this,
264 struct busfreq_data_int, pm_notifier);
265 struct opp *opp;
266 unsigned long maxfreq = ULONG_MAX;
267 unsigned long freq;
268 unsigned long volt;
269 int err = 0;
270
271 switch (event) {
272 case PM_SUSPEND_PREPARE:
273 /* Set Fastest and Deactivate DVFS */
274 mutex_lock(&data->lock);
275
276 data->disabled = true;
277
278 rcu_read_lock();
279 opp = opp_find_freq_floor(data->dev, &maxfreq);
280 if (IS_ERR(opp)) {
281 rcu_read_unlock();
282 err = PTR_ERR(opp);
283 goto unlock;
284 }
285 freq = opp_get_freq(opp);
286 volt = opp_get_voltage(opp);
287 rcu_read_unlock();
288
289 err = exynos5_int_setvolt(data, volt);
290 if (err)
291 goto unlock;
292
293 err = clk_set_rate(data->int_clk, freq * 1000);
294
295 if (err)
296 goto unlock;
297
298 data->curr_freq = freq;
299unlock:
300 mutex_unlock(&data->lock);
301 if (err)
302 return NOTIFY_BAD;
303 return NOTIFY_OK;
304 case PM_POST_RESTORE:
305 case PM_POST_SUSPEND:
306 /* Reactivate */
307 mutex_lock(&data->lock);
308 data->disabled = false;
309 mutex_unlock(&data->lock);
310 return NOTIFY_OK;
311 }
312
313 return NOTIFY_DONE;
314}
315
316static int exynos5_busfreq_int_probe(struct platform_device *pdev)
317{
318 struct busfreq_data_int *data;
319 struct opp *opp;
320 struct device *dev = &pdev->dev;
321 struct device_node *np;
322 unsigned long initial_freq;
323 unsigned long initial_volt;
324 int err = 0;
325 int i;
326
327 data = devm_kzalloc(&pdev->dev, sizeof(struct busfreq_data_int),
328 GFP_KERNEL);
329 if (data == NULL) {
330 dev_err(dev, "Cannot allocate memory.\n");
331 return -ENOMEM;
332 }
333
334 np = of_find_compatible_node(NULL, NULL, "samsung,exynos5250-ppmu");
335 if (np == NULL) {
336 pr_err("Unable to find PPMU node\n");
337 return -ENOENT;
338 }
339
340 for (i = PPMU_RIGHT; i < PPMU_END; i++) {
341 /* map PPMU memory region */
342 data->ppmu[i].hw_base = of_iomap(np, i);
343 if (data->ppmu[i].hw_base == NULL) {
344 dev_err(&pdev->dev, "failed to map memory region\n");
345 return -ENOMEM;
346 }
347 }
348 data->pm_notifier.notifier_call = exynos5_busfreq_int_pm_notifier_event;
349 data->dev = dev;
350 mutex_init(&data->lock);
351
352 err = exynos5250_init_int_tables(data);
353 if (err)
354 goto err_regulator;
355
356 data->vdd_int = regulator_get(dev, "vdd_int");
357 if (IS_ERR(data->vdd_int)) {
358 dev_err(dev, "Cannot get the regulator \"vdd_int\"\n");
359 err = PTR_ERR(data->vdd_int);
360 goto err_regulator;
361 }
362
363 data->int_clk = clk_get(dev, "int_clk");
364 if (IS_ERR(data->int_clk)) {
365 dev_err(dev, "Cannot get clock \"int_clk\"\n");
366 err = PTR_ERR(data->int_clk);
367 goto err_clock;
368 }
369
370 rcu_read_lock();
371 opp = opp_find_freq_floor(dev,
372 &exynos5_devfreq_int_profile.initial_freq);
373 if (IS_ERR(opp)) {
374 rcu_read_unlock();
375 dev_err(dev, "Invalid initial frequency %lu kHz.\n",
376 exynos5_devfreq_int_profile.initial_freq);
377 err = PTR_ERR(opp);
378 goto err_opp_add;
379 }
380 initial_freq = opp_get_freq(opp);
381 initial_volt = opp_get_voltage(opp);
382 rcu_read_unlock();
383 data->curr_freq = initial_freq;
384
385 err = clk_set_rate(data->int_clk, initial_freq * 1000);
386 if (err) {
387 dev_err(dev, "Failed to set initial frequency\n");
388 goto err_opp_add;
389 }
390
391 err = exynos5_int_setvolt(data, initial_volt);
392 if (err)
393 goto err_opp_add;
394
395 platform_set_drvdata(pdev, data);
396
397 busfreq_mon_reset(data);
398
399 data->devfreq = devfreq_add_device(dev, &exynos5_devfreq_int_profile,
400 "simple_ondemand", NULL);
401
402 if (IS_ERR(data->devfreq)) {
403 err = PTR_ERR(data->devfreq);
404 goto err_devfreq_add;
405 }
406
407 devfreq_register_opp_notifier(dev, data->devfreq);
408
409 err = register_pm_notifier(&data->pm_notifier);
410 if (err) {
411 dev_err(dev, "Failed to setup pm notifier\n");
412 goto err_devfreq_add;
413 }
414
415 /* TODO: Add a new QOS class for int/mif bus */
416 pm_qos_add_request(&data->int_req, PM_QOS_NETWORK_THROUGHPUT, -1);
417
418 return 0;
419
420err_devfreq_add:
421 devfreq_remove_device(data->devfreq);
422 platform_set_drvdata(pdev, NULL);
423err_opp_add:
424 clk_put(data->int_clk);
425err_clock:
426 regulator_put(data->vdd_int);
427err_regulator:
428 return err;
429}
430
431static int exynos5_busfreq_int_remove(struct platform_device *pdev)
432{
433 struct busfreq_data_int *data = platform_get_drvdata(pdev);
434
435 pm_qos_remove_request(&data->int_req);
436 unregister_pm_notifier(&data->pm_notifier);
437 devfreq_remove_device(data->devfreq);
438 regulator_put(data->vdd_int);
439 clk_put(data->int_clk);
440 platform_set_drvdata(pdev, NULL);
441
442 return 0;
443}
444
445static int exynos5_busfreq_int_resume(struct device *dev)
446{
447 struct platform_device *pdev = container_of(dev, struct platform_device,
448 dev);
449 struct busfreq_data_int *data = platform_get_drvdata(pdev);
450
451 busfreq_mon_reset(data);
452 return 0;
453}
454
455static const struct dev_pm_ops exynos5_busfreq_int_pm = {
456 .resume = exynos5_busfreq_int_resume,
457};
458
459/* platform device pointer for exynos5 devfreq device. */
460static struct platform_device *exynos5_devfreq_pdev;
461
462static struct platform_driver exynos5_busfreq_int_driver = {
463 .probe = exynos5_busfreq_int_probe,
464 .remove = exynos5_busfreq_int_remove,
465 .driver = {
466 .name = "exynos5-bus-int",
467 .owner = THIS_MODULE,
468 .pm = &exynos5_busfreq_int_pm,
469 },
470};
471
472static int __init exynos5_busfreq_int_init(void)
473{
474 int ret;
475
476 ret = platform_driver_register(&exynos5_busfreq_int_driver);
477 if (ret < 0)
478 goto out;
479
480 exynos5_devfreq_pdev =
481 platform_device_register_simple("exynos5-bus-int", -1, NULL, 0);
482 if (IS_ERR_OR_NULL(exynos5_devfreq_pdev)) {
483 ret = PTR_ERR(exynos5_devfreq_pdev);
484 goto out1;
485 }
486
487 return 0;
488out1:
489 platform_driver_unregister(&exynos5_busfreq_int_driver);
490out:
491 return ret;
492}
493late_initcall(exynos5_busfreq_int_init);
494
495static void __exit exynos5_busfreq_int_exit(void)
496{
497 platform_device_unregister(exynos5_devfreq_pdev);
498 platform_driver_unregister(&exynos5_busfreq_int_driver);
499}
500module_exit(exynos5_busfreq_int_exit);
501
502MODULE_LICENSE("GPL");
503MODULE_DESCRIPTION("EXYNOS5 busfreq driver with devfreq framework");
diff --git a/drivers/devfreq/exynos/exynos_ppmu.c b/drivers/devfreq/exynos/exynos_ppmu.c
new file mode 100644
index 000000000000..85fc5ac1036a
--- /dev/null
+++ b/drivers/devfreq/exynos/exynos_ppmu.c
@@ -0,0 +1,56 @@
1/*
2 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 * http://www.samsung.com/
4 *
5 * EXYNOS - PPMU support
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/kernel.h>
13#include <linux/types.h>
14#include <linux/io.h>
15
16#include "exynos_ppmu.h"
17
18void exynos_ppmu_reset(void __iomem *ppmu_base)
19{
20 __raw_writel(PPMU_CYCLE_RESET | PPMU_COUNTER_RESET, ppmu_base);
21 __raw_writel(PPMU_ENABLE_CYCLE |
22 PPMU_ENABLE_COUNT0 |
23 PPMU_ENABLE_COUNT1 |
24 PPMU_ENABLE_COUNT2 |
25 PPMU_ENABLE_COUNT3,
26 ppmu_base + PPMU_CNTENS);
27}
28
29void exynos_ppmu_setevent(void __iomem *ppmu_base, unsigned int ch,
30 unsigned int evt)
31{
32 __raw_writel(evt, ppmu_base + PPMU_BEVTSEL(ch));
33}
34
35void exynos_ppmu_start(void __iomem *ppmu_base)
36{
37 __raw_writel(PPMU_ENABLE, ppmu_base);
38}
39
40void exynos_ppmu_stop(void __iomem *ppmu_base)
41{
42 __raw_writel(PPMU_DISABLE, ppmu_base);
43}
44
45unsigned int exynos_ppmu_read(void __iomem *ppmu_base, unsigned int ch)
46{
47 unsigned int total;
48
49 if (ch == PPMU_PMNCNT3)
50 total = ((__raw_readl(ppmu_base + PMCNT_OFFSET(ch)) << 8) |
51 __raw_readl(ppmu_base + PMCNT_OFFSET(ch + 1)));
52 else
53 total = __raw_readl(ppmu_base + PMCNT_OFFSET(ch));
54
55 return total;
56}
diff --git a/drivers/devfreq/exynos/exynos_ppmu.h b/drivers/devfreq/exynos/exynos_ppmu.h
new file mode 100644
index 000000000000..7dfb221eaccd
--- /dev/null
+++ b/drivers/devfreq/exynos/exynos_ppmu.h
@@ -0,0 +1,78 @@
1/*
2 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 * http://www.samsung.com/
4 *
5 * EXYNOS PPMU header
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10*/
11
12#ifndef __DEVFREQ_EXYNOS_PPMU_H
13#define __DEVFREQ_EXYNOS_PPMU_H __FILE__
14
15#include <linux/ktime.h>
16
17/* For PPMU Control */
18#define PPMU_ENABLE BIT(0)
19#define PPMU_DISABLE 0x0
20#define PPMU_CYCLE_RESET BIT(1)
21#define PPMU_COUNTER_RESET BIT(2)
22
23#define PPMU_ENABLE_COUNT0 BIT(0)
24#define PPMU_ENABLE_COUNT1 BIT(1)
25#define PPMU_ENABLE_COUNT2 BIT(2)
26#define PPMU_ENABLE_COUNT3 BIT(3)
27#define PPMU_ENABLE_CYCLE BIT(31)
28
29#define PPMU_CNTENS 0x10
30#define PPMU_FLAG 0x50
31#define PPMU_CCNT_OVERFLOW BIT(31)
32#define PPMU_CCNT 0x100
33
34#define PPMU_PMCNT0 0x110
35#define PPMU_PMCNT_OFFSET 0x10
36#define PMCNT_OFFSET(x) (PPMU_PMCNT0 + (PPMU_PMCNT_OFFSET * x))
37
38#define PPMU_BEVT0SEL 0x1000
39#define PPMU_BEVTSEL_OFFSET 0x100
40#define PPMU_BEVTSEL(x) (PPMU_BEVT0SEL + (ch * PPMU_BEVTSEL_OFFSET))
41
42/* For Event Selection */
43#define RD_DATA_COUNT 0x5
44#define WR_DATA_COUNT 0x6
45#define RDWR_DATA_COUNT 0x7
46
47enum ppmu_counter {
48 PPMU_PMNCNT0,
49 PPMU_PMCCNT1,
50 PPMU_PMNCNT2,
51 PPMU_PMNCNT3,
52 PPMU_PMNCNT_MAX,
53};
54
55struct bus_opp_table {
56 unsigned int idx;
57 unsigned long clk;
58 unsigned long volt;
59};
60
61struct exynos_ppmu {
62 void __iomem *hw_base;
63 unsigned int ccnt;
64 unsigned int event[PPMU_PMNCNT_MAX];
65 unsigned int count[PPMU_PMNCNT_MAX];
66 unsigned long long ns;
67 ktime_t reset_time;
68 bool ccnt_overflow;
69 bool count_overflow[PPMU_PMNCNT_MAX];
70};
71
72void exynos_ppmu_reset(void __iomem *ppmu_base);
73void exynos_ppmu_setevent(void __iomem *ppmu_base, unsigned int ch,
74 unsigned int evt);
75void exynos_ppmu_start(void __iomem *ppmu_base);
76void exynos_ppmu_stop(void __iomem *ppmu_base);
77unsigned int exynos_ppmu_read(void __iomem *ppmu_base, unsigned int ch);
78#endif /* __DEVFREQ_EXYNOS_PPMU_H */
diff --git a/drivers/dma/intel_mid_dma.c b/drivers/dma/intel_mid_dma.c
index a0de82e21a7c..a975ebebea8a 100644
--- a/drivers/dma/intel_mid_dma.c
+++ b/drivers/dma/intel_mid_dma.c
@@ -1405,7 +1405,7 @@ static int dma_runtime_idle(struct device *dev)
1405 return -EAGAIN; 1405 return -EAGAIN;
1406 } 1406 }
1407 1407
1408 return pm_schedule_suspend(dev, 0); 1408 return 0;
1409} 1409}
1410 1410
1411/****************************************************************************** 1411/******************************************************************************
diff --git a/drivers/gpio/gpio-langwell.c b/drivers/gpio/gpio-langwell.c
index f4b72456faaf..bfa1af1b519f 100644
--- a/drivers/gpio/gpio-langwell.c
+++ b/drivers/gpio/gpio-langwell.c
@@ -300,11 +300,7 @@ static const struct irq_domain_ops lnw_gpio_irq_ops = {
300 300
301static int lnw_gpio_runtime_idle(struct device *dev) 301static int lnw_gpio_runtime_idle(struct device *dev)
302{ 302{
303 int err = pm_schedule_suspend(dev, 500); 303 pm_schedule_suspend(dev, 500);
304
305 if (!err)
306 return 0;
307
308 return -EBUSY; 304 return -EBUSY;
309} 305}
310 306
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 48e31ed69dbf..f32ca293ae0e 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -435,7 +435,7 @@ static const struct dev_pm_ops i2c_device_pm_ops = {
435 SET_RUNTIME_PM_OPS( 435 SET_RUNTIME_PM_OPS(
436 pm_generic_runtime_suspend, 436 pm_generic_runtime_suspend,
437 pm_generic_runtime_resume, 437 pm_generic_runtime_resume,
438 pm_generic_runtime_idle 438 NULL
439 ) 439 )
440}; 440};
441 441
diff --git a/drivers/mfd/ab8500-gpadc.c b/drivers/mfd/ab8500-gpadc.c
index 13f7866de46e..3598b0ecf8c7 100644
--- a/drivers/mfd/ab8500-gpadc.c
+++ b/drivers/mfd/ab8500-gpadc.c
@@ -886,12 +886,6 @@ static int ab8500_gpadc_runtime_resume(struct device *dev)
886 return ret; 886 return ret;
887} 887}
888 888
889static int ab8500_gpadc_runtime_idle(struct device *dev)
890{
891 pm_runtime_suspend(dev);
892 return 0;
893}
894
895static int ab8500_gpadc_suspend(struct device *dev) 889static int ab8500_gpadc_suspend(struct device *dev)
896{ 890{
897 struct ab8500_gpadc *gpadc = dev_get_drvdata(dev); 891 struct ab8500_gpadc *gpadc = dev_get_drvdata(dev);
@@ -1039,7 +1033,7 @@ static int ab8500_gpadc_remove(struct platform_device *pdev)
1039static const struct dev_pm_ops ab8500_gpadc_pm_ops = { 1033static const struct dev_pm_ops ab8500_gpadc_pm_ops = {
1040 SET_RUNTIME_PM_OPS(ab8500_gpadc_runtime_suspend, 1034 SET_RUNTIME_PM_OPS(ab8500_gpadc_runtime_suspend,
1041 ab8500_gpadc_runtime_resume, 1035 ab8500_gpadc_runtime_resume,
1042 ab8500_gpadc_runtime_idle) 1036 NULL)
1043 SET_SYSTEM_SLEEP_PM_OPS(ab8500_gpadc_suspend, 1037 SET_SYSTEM_SLEEP_PM_OPS(ab8500_gpadc_suspend,
1044 ab8500_gpadc_resume) 1038 ab8500_gpadc_resume)
1045 1039
diff --git a/drivers/mfd/db8500-prcmu.c b/drivers/mfd/db8500-prcmu.c
index a292a1deff9a..3c157faee645 100644
--- a/drivers/mfd/db8500-prcmu.c
+++ b/drivers/mfd/db8500-prcmu.c
@@ -1725,9 +1725,9 @@ static long round_clock_rate(u8 clock, unsigned long rate)
1725 1725
1726/* CPU FREQ table, may be changed due to if MAX_OPP is supported. */ 1726/* CPU FREQ table, may be changed due to if MAX_OPP is supported. */
1727static struct cpufreq_frequency_table db8500_cpufreq_table[] = { 1727static struct cpufreq_frequency_table db8500_cpufreq_table[] = {
1728 { .frequency = 200000, .index = ARM_EXTCLK,}, 1728 { .frequency = 200000, .driver_data = ARM_EXTCLK,},
1729 { .frequency = 400000, .index = ARM_50_OPP,}, 1729 { .frequency = 400000, .driver_data = ARM_50_OPP,},
1730 { .frequency = 800000, .index = ARM_100_OPP,}, 1730 { .frequency = 800000, .driver_data = ARM_100_OPP,},
1731 { .frequency = CPUFREQ_TABLE_END,}, /* To be used for MAX_OPP. */ 1731 { .frequency = CPUFREQ_TABLE_END,}, /* To be used for MAX_OPP. */
1732 { .frequency = CPUFREQ_TABLE_END,}, 1732 { .frequency = CPUFREQ_TABLE_END,},
1733}; 1733};
@@ -1902,7 +1902,7 @@ static int set_armss_rate(unsigned long rate)
1902 return -EINVAL; 1902 return -EINVAL;
1903 1903
1904 /* Set the new arm opp. */ 1904 /* Set the new arm opp. */
1905 return db8500_prcmu_set_arm_opp(db8500_cpufreq_table[i].index); 1905 return db8500_prcmu_set_arm_opp(db8500_cpufreq_table[i].driver_data);
1906} 1906}
1907 1907
1908static int set_plldsi_rate(unsigned long rate) 1908static int set_plldsi_rate(unsigned long rate)
@@ -3106,7 +3106,7 @@ static void db8500_prcmu_update_cpufreq(void)
3106{ 3106{
3107 if (prcmu_has_arm_maxopp()) { 3107 if (prcmu_has_arm_maxopp()) {
3108 db8500_cpufreq_table[3].frequency = 1000000; 3108 db8500_cpufreq_table[3].frequency = 1000000;
3109 db8500_cpufreq_table[3].index = ARM_MAX_OPP; 3109 db8500_cpufreq_table[3].driver_data = ARM_MAX_OPP;
3110 } 3110 }
3111} 3111}
3112 3112
diff --git a/drivers/mmc/core/bus.c b/drivers/mmc/core/bus.c
index e219c97a02a4..9d5c71125576 100644
--- a/drivers/mmc/core/bus.c
+++ b/drivers/mmc/core/bus.c
@@ -164,7 +164,7 @@ static int mmc_runtime_resume(struct device *dev)
164 164
165static int mmc_runtime_idle(struct device *dev) 165static int mmc_runtime_idle(struct device *dev)
166{ 166{
167 return pm_runtime_suspend(dev); 167 return 0;
168} 168}
169 169
170#endif /* !CONFIG_PM_RUNTIME */ 170#endif /* !CONFIG_PM_RUNTIME */
diff --git a/drivers/mmc/core/sdio_bus.c b/drivers/mmc/core/sdio_bus.c
index 546c67c2bbbf..6d67492a9247 100644
--- a/drivers/mmc/core/sdio_bus.c
+++ b/drivers/mmc/core/sdio_bus.c
@@ -211,7 +211,7 @@ static const struct dev_pm_ops sdio_bus_pm_ops = {
211 SET_RUNTIME_PM_OPS( 211 SET_RUNTIME_PM_OPS(
212 pm_generic_runtime_suspend, 212 pm_generic_runtime_suspend,
213 pm_generic_runtime_resume, 213 pm_generic_runtime_resume,
214 pm_generic_runtime_idle 214 NULL
215 ) 215 )
216}; 216};
217 217
diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index 79277fb36c6b..e6515e21afa3 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -1050,26 +1050,22 @@ static int pci_pm_runtime_idle(struct device *dev)
1050{ 1050{
1051 struct pci_dev *pci_dev = to_pci_dev(dev); 1051 struct pci_dev *pci_dev = to_pci_dev(dev);
1052 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; 1052 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
1053 int ret = 0;
1053 1054
1054 /* 1055 /*
1055 * If pci_dev->driver is not set (unbound), the device should 1056 * If pci_dev->driver is not set (unbound), the device should
1056 * always remain in D0 regardless of the runtime PM status 1057 * always remain in D0 regardless of the runtime PM status
1057 */ 1058 */
1058 if (!pci_dev->driver) 1059 if (!pci_dev->driver)
1059 goto out; 1060 return 0;
1060 1061
1061 if (!pm) 1062 if (!pm)
1062 return -ENOSYS; 1063 return -ENOSYS;
1063 1064
1064 if (pm->runtime_idle) { 1065 if (pm->runtime_idle)
1065 int ret = pm->runtime_idle(dev); 1066 ret = pm->runtime_idle(dev);
1066 if (ret)
1067 return ret;
1068 }
1069 1067
1070out: 1068 return ret;
1071 pm_runtime_suspend(dev);
1072 return 0;
1073} 1069}
1074 1070
1075#else /* !CONFIG_PM_RUNTIME */ 1071#else /* !CONFIG_PM_RUNTIME */
diff --git a/drivers/pnp/manager.c b/drivers/pnp/manager.c
index 95cebf0185de..9357aa779048 100644
--- a/drivers/pnp/manager.c
+++ b/drivers/pnp/manager.c
@@ -211,6 +211,12 @@ static int pnp_assign_dma(struct pnp_dev *dev, struct pnp_dma *rule, int idx)
211 res->start = -1; 211 res->start = -1;
212 res->end = -1; 212 res->end = -1;
213 213
214 if (!rule->map) {
215 res->flags |= IORESOURCE_DISABLED;
216 pnp_dbg(&dev->dev, " dma %d disabled\n", idx);
217 goto __add;
218 }
219
214 for (i = 0; i < 8; i++) { 220 for (i = 0; i < 8; i++) {
215 if (rule->map & (1 << xtab[i])) { 221 if (rule->map & (1 << xtab[i])) {
216 res->start = res->end = xtab[i]; 222 res->start = res->end = xtab[i];
@@ -218,11 +224,9 @@ static int pnp_assign_dma(struct pnp_dev *dev, struct pnp_dma *rule, int idx)
218 goto __add; 224 goto __add;
219 } 225 }
220 } 226 }
221#ifdef MAX_DMA_CHANNELS 227
222 res->start = res->end = MAX_DMA_CHANNELS; 228 pnp_dbg(&dev->dev, " couldn't assign dma %d\n", idx);
223#endif 229 return -EBUSY;
224 res->flags |= IORESOURCE_DISABLED;
225 pnp_dbg(&dev->dev, " disable dma %d\n", idx);
226 230
227__add: 231__add:
228 pnp_add_dma_resource(dev, res->start, res->flags); 232 pnp_add_dma_resource(dev, res->start, res->flags);
diff --git a/drivers/power/avs/smartreflex.c b/drivers/power/avs/smartreflex.c
index 6b2238bb6a81..db9973bb53f1 100644
--- a/drivers/power/avs/smartreflex.c
+++ b/drivers/power/avs/smartreflex.c
@@ -27,7 +27,8 @@
27#include <linux/pm_runtime.h> 27#include <linux/pm_runtime.h>
28#include <linux/power/smartreflex.h> 28#include <linux/power/smartreflex.h>
29 29
30#define SMARTREFLEX_NAME_LEN 16 30#define DRIVER_NAME "smartreflex"
31#define SMARTREFLEX_NAME_LEN 32
31#define NVALUE_NAME_LEN 40 32#define NVALUE_NAME_LEN 40
32#define SR_DISABLE_TIMEOUT 200 33#define SR_DISABLE_TIMEOUT 200
33 34
@@ -207,12 +208,11 @@ static void sr_stop_vddautocomp(struct omap_sr *sr)
207static int sr_late_init(struct omap_sr *sr_info) 208static int sr_late_init(struct omap_sr *sr_info)
208{ 209{
209 struct omap_sr_data *pdata = sr_info->pdev->dev.platform_data; 210 struct omap_sr_data *pdata = sr_info->pdev->dev.platform_data;
210 struct resource *mem;
211 int ret = 0; 211 int ret = 0;
212 212
213 if (sr_class->notify && sr_class->notify_flags && sr_info->irq) { 213 if (sr_class->notify && sr_class->notify_flags && sr_info->irq) {
214 ret = request_irq(sr_info->irq, sr_interrupt, 214 ret = devm_request_irq(&sr_info->pdev->dev, sr_info->irq,
215 0, sr_info->name, sr_info); 215 sr_interrupt, 0, sr_info->name, sr_info);
216 if (ret) 216 if (ret)
217 goto error; 217 goto error;
218 disable_irq(sr_info->irq); 218 disable_irq(sr_info->irq);
@@ -224,14 +224,10 @@ static int sr_late_init(struct omap_sr *sr_info)
224 return ret; 224 return ret;
225 225
226error: 226error:
227 iounmap(sr_info->base);
228 mem = platform_get_resource(sr_info->pdev, IORESOURCE_MEM, 0);
229 release_mem_region(mem->start, resource_size(mem));
230 list_del(&sr_info->node); 227 list_del(&sr_info->node);
231 dev_err(&sr_info->pdev->dev, "%s: ERROR in registering" 228 dev_err(&sr_info->pdev->dev, "%s: ERROR in registering"
232 "interrupt handler. Smartreflex will" 229 "interrupt handler. Smartreflex will"
233 "not function as desired\n", __func__); 230 "not function as desired\n", __func__);
234 kfree(sr_info);
235 231
236 return ret; 232 return ret;
237} 233}
@@ -341,9 +337,9 @@ static struct omap_sr_nvalue_table *sr_retrieve_nvalue_row(
341/* Public Functions */ 337/* Public Functions */
342 338
343/** 339/**
344 * sr_configure_errgen() - Configures the smrtreflex to perform AVS using the 340 * sr_configure_errgen() - Configures the SmartReflex to perform AVS using the
345 * error generator module. 341 * error generator module.
346 * @voltdm: VDD pointer to which the SR module to be configured belongs to. 342 * @sr: SR module to be configured.
347 * 343 *
348 * This API is to be called from the smartreflex class driver to 344 * This API is to be called from the smartreflex class driver to
349 * configure the error generator module inside the smartreflex module. 345 * configure the error generator module inside the smartreflex module.
@@ -352,17 +348,17 @@ static struct omap_sr_nvalue_table *sr_retrieve_nvalue_row(
352 * SR CLASS 2 can choose between ERROR module and MINMAXAVG 348 * SR CLASS 2 can choose between ERROR module and MINMAXAVG
353 * module. Returns 0 on success and error value in case of failure. 349 * module. Returns 0 on success and error value in case of failure.
354 */ 350 */
355int sr_configure_errgen(struct voltagedomain *voltdm) 351int sr_configure_errgen(struct omap_sr *sr)
356{ 352{
357 u32 sr_config, sr_errconfig, errconfig_offs; 353 u32 sr_config, sr_errconfig, errconfig_offs;
358 u32 vpboundint_en, vpboundint_st; 354 u32 vpboundint_en, vpboundint_st;
359 u32 senp_en = 0, senn_en = 0; 355 u32 senp_en = 0, senn_en = 0;
360 u8 senp_shift, senn_shift; 356 u8 senp_shift, senn_shift;
361 struct omap_sr *sr = _sr_lookup(voltdm);
362 357
363 if (IS_ERR(sr)) { 358 if (!sr) {
364 pr_warning("%s: omap_sr struct for voltdm not found\n", __func__); 359 pr_warn("%s: NULL omap_sr from %pF\n", __func__,
365 return PTR_ERR(sr); 360 (void *)_RET_IP_);
361 return -EINVAL;
366 } 362 }
367 363
368 if (!sr->clk_length) 364 if (!sr->clk_length)
@@ -414,22 +410,22 @@ int sr_configure_errgen(struct voltagedomain *voltdm)
414 410
415/** 411/**
416 * sr_disable_errgen() - Disables SmartReflex AVS module's errgen component 412 * sr_disable_errgen() - Disables SmartReflex AVS module's errgen component
417 * @voltdm: VDD pointer to which the SR module to be configured belongs to. 413 * @sr: SR module to be configured.
418 * 414 *
419 * This API is to be called from the smartreflex class driver to 415 * This API is to be called from the smartreflex class driver to
420 * disable the error generator module inside the smartreflex module. 416 * disable the error generator module inside the smartreflex module.
421 * 417 *
422 * Returns 0 on success and error value in case of failure. 418 * Returns 0 on success and error value in case of failure.
423 */ 419 */
424int sr_disable_errgen(struct voltagedomain *voltdm) 420int sr_disable_errgen(struct omap_sr *sr)
425{ 421{
426 u32 errconfig_offs; 422 u32 errconfig_offs;
427 u32 vpboundint_en, vpboundint_st; 423 u32 vpboundint_en, vpboundint_st;
428 struct omap_sr *sr = _sr_lookup(voltdm);
429 424
430 if (IS_ERR(sr)) { 425 if (!sr) {
431 pr_warning("%s: omap_sr struct for voltdm not found\n", __func__); 426 pr_warn("%s: NULL omap_sr from %pF\n", __func__,
432 return PTR_ERR(sr); 427 (void *)_RET_IP_);
428 return -EINVAL;
433 } 429 }
434 430
435 switch (sr->ip_type) { 431 switch (sr->ip_type) {
@@ -449,19 +445,24 @@ int sr_disable_errgen(struct voltagedomain *voltdm)
449 return -EINVAL; 445 return -EINVAL;
450 } 446 }
451 447
452 /* Disable the interrupts of ERROR module */
453 sr_modify_reg(sr, errconfig_offs, vpboundint_en | vpboundint_st, 0);
454
455 /* Disable the Sensor and errorgen */ 448 /* Disable the Sensor and errorgen */
456 sr_modify_reg(sr, SRCONFIG, SRCONFIG_SENENABLE | SRCONFIG_ERRGEN_EN, 0); 449 sr_modify_reg(sr, SRCONFIG, SRCONFIG_SENENABLE | SRCONFIG_ERRGEN_EN, 0);
457 450
451 /*
452 * Disable the interrupts of ERROR module
453 * NOTE: modify is a read, modify,write - an implicit OCP barrier
454 * which is required is present here - sequencing is critical
455 * at this point (after errgen is disabled, vpboundint disable)
456 */
457 sr_modify_reg(sr, errconfig_offs, vpboundint_en | vpboundint_st, 0);
458
458 return 0; 459 return 0;
459} 460}
460 461
461/** 462/**
462 * sr_configure_minmax() - Configures the smrtreflex to perform AVS using the 463 * sr_configure_minmax() - Configures the SmartReflex to perform AVS using the
463 * minmaxavg module. 464 * minmaxavg module.
464 * @voltdm: VDD pointer to which the SR module to be configured belongs to. 465 * @sr: SR module to be configured.
465 * 466 *
466 * This API is to be called from the smartreflex class driver to 467 * This API is to be called from the smartreflex class driver to
467 * configure the minmaxavg module inside the smartreflex module. 468 * configure the minmaxavg module inside the smartreflex module.
@@ -470,16 +471,16 @@ int sr_disable_errgen(struct voltagedomain *voltdm)
470 * SR CLASS 2 can choose between ERROR module and MINMAXAVG 471 * SR CLASS 2 can choose between ERROR module and MINMAXAVG
471 * module. Returns 0 on success and error value in case of failure. 472 * module. Returns 0 on success and error value in case of failure.
472 */ 473 */
473int sr_configure_minmax(struct voltagedomain *voltdm) 474int sr_configure_minmax(struct omap_sr *sr)
474{ 475{
475 u32 sr_config, sr_avgwt; 476 u32 sr_config, sr_avgwt;
476 u32 senp_en = 0, senn_en = 0; 477 u32 senp_en = 0, senn_en = 0;
477 u8 senp_shift, senn_shift; 478 u8 senp_shift, senn_shift;
478 struct omap_sr *sr = _sr_lookup(voltdm);
479 479
480 if (IS_ERR(sr)) { 480 if (!sr) {
481 pr_warning("%s: omap_sr struct for voltdm not found\n", __func__); 481 pr_warn("%s: NULL omap_sr from %pF\n", __func__,
482 return PTR_ERR(sr); 482 (void *)_RET_IP_);
483 return -EINVAL;
483 } 484 }
484 485
485 if (!sr->clk_length) 486 if (!sr->clk_length)
@@ -546,7 +547,7 @@ int sr_configure_minmax(struct voltagedomain *voltdm)
546 547
547/** 548/**
548 * sr_enable() - Enables the smartreflex module. 549 * sr_enable() - Enables the smartreflex module.
549 * @voltdm: VDD pointer to which the SR module to be configured belongs to. 550 * @sr: pointer to which the SR module to be configured belongs to.
550 * @volt: The voltage at which the Voltage domain associated with 551 * @volt: The voltage at which the Voltage domain associated with
551 * the smartreflex module is operating at. 552 * the smartreflex module is operating at.
552 * This is required only to program the correct Ntarget value. 553 * This is required only to program the correct Ntarget value.
@@ -555,16 +556,16 @@ int sr_configure_minmax(struct voltagedomain *voltdm)
555 * enable a smartreflex module. Returns 0 on success. Returns error 556 * enable a smartreflex module. Returns 0 on success. Returns error
556 * value if the voltage passed is wrong or if ntarget value is wrong. 557 * value if the voltage passed is wrong or if ntarget value is wrong.
557 */ 558 */
558int sr_enable(struct voltagedomain *voltdm, unsigned long volt) 559int sr_enable(struct omap_sr *sr, unsigned long volt)
559{ 560{
560 struct omap_volt_data *volt_data; 561 struct omap_volt_data *volt_data;
561 struct omap_sr *sr = _sr_lookup(voltdm);
562 struct omap_sr_nvalue_table *nvalue_row; 562 struct omap_sr_nvalue_table *nvalue_row;
563 int ret; 563 int ret;
564 564
565 if (IS_ERR(sr)) { 565 if (!sr) {
566 pr_warning("%s: omap_sr struct for voltdm not found\n", __func__); 566 pr_warn("%s: NULL omap_sr from %pF\n", __func__,
567 return PTR_ERR(sr); 567 (void *)_RET_IP_);
568 return -EINVAL;
568 } 569 }
569 570
570 volt_data = omap_voltage_get_voltdata(sr->voltdm, volt); 571 volt_data = omap_voltage_get_voltdata(sr->voltdm, volt);
@@ -606,17 +607,16 @@ int sr_enable(struct voltagedomain *voltdm, unsigned long volt)
606 607
607/** 608/**
608 * sr_disable() - Disables the smartreflex module. 609 * sr_disable() - Disables the smartreflex module.
609 * @voltdm: VDD pointer to which the SR module to be configured belongs to. 610 * @sr: pointer to which the SR module to be configured belongs to.
610 * 611 *
611 * This API is to be called from the smartreflex class driver to 612 * This API is to be called from the smartreflex class driver to
612 * disable a smartreflex module. 613 * disable a smartreflex module.
613 */ 614 */
614void sr_disable(struct voltagedomain *voltdm) 615void sr_disable(struct omap_sr *sr)
615{ 616{
616 struct omap_sr *sr = _sr_lookup(voltdm); 617 if (!sr) {
617 618 pr_warn("%s: NULL omap_sr from %pF\n", __func__,
618 if (IS_ERR(sr)) { 619 (void *)_RET_IP_);
619 pr_warning("%s: omap_sr struct for voltdm not found\n", __func__);
620 return; 620 return;
621 } 621 }
622 622
@@ -847,34 +847,33 @@ static int __init omap_sr_probe(struct platform_device *pdev)
847 struct dentry *nvalue_dir; 847 struct dentry *nvalue_dir;
848 int i, ret = 0; 848 int i, ret = 0;
849 849
850 sr_info = kzalloc(sizeof(struct omap_sr), GFP_KERNEL); 850 sr_info = devm_kzalloc(&pdev->dev, sizeof(struct omap_sr), GFP_KERNEL);
851 if (!sr_info) { 851 if (!sr_info) {
852 dev_err(&pdev->dev, "%s: unable to allocate sr_info\n", 852 dev_err(&pdev->dev, "%s: unable to allocate sr_info\n",
853 __func__); 853 __func__);
854 return -ENOMEM; 854 return -ENOMEM;
855 } 855 }
856 856
857 sr_info->name = devm_kzalloc(&pdev->dev,
858 SMARTREFLEX_NAME_LEN, GFP_KERNEL);
859 if (!sr_info->name) {
860 dev_err(&pdev->dev, "%s: unable to allocate SR instance name\n",
861 __func__);
862 return -ENOMEM;
863 }
864
857 platform_set_drvdata(pdev, sr_info); 865 platform_set_drvdata(pdev, sr_info);
858 866
859 if (!pdata) { 867 if (!pdata) {
860 dev_err(&pdev->dev, "%s: platform data missing\n", __func__); 868 dev_err(&pdev->dev, "%s: platform data missing\n", __func__);
861 ret = -EINVAL; 869 return -EINVAL;
862 goto err_free_devinfo;
863 } 870 }
864 871
865 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 872 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
866 if (!mem) { 873 sr_info->base = devm_ioremap_resource(&pdev->dev, mem);
867 dev_err(&pdev->dev, "%s: no mem resource\n", __func__); 874 if (IS_ERR(sr_info->base)) {
868 ret = -ENODEV; 875 dev_err(&pdev->dev, "%s: ioremap fail\n", __func__);
869 goto err_free_devinfo; 876 return PTR_ERR(sr_info->base);
870 }
871
872 mem = request_mem_region(mem->start, resource_size(mem),
873 dev_name(&pdev->dev));
874 if (!mem) {
875 dev_err(&pdev->dev, "%s: no mem region\n", __func__);
876 ret = -EBUSY;
877 goto err_free_devinfo;
878 } 877 }
879 878
880 irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 879 irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
@@ -882,13 +881,7 @@ static int __init omap_sr_probe(struct platform_device *pdev)
882 pm_runtime_enable(&pdev->dev); 881 pm_runtime_enable(&pdev->dev);
883 pm_runtime_irq_safe(&pdev->dev); 882 pm_runtime_irq_safe(&pdev->dev);
884 883
885 sr_info->name = kasprintf(GFP_KERNEL, "%s", pdata->name); 884 snprintf(sr_info->name, SMARTREFLEX_NAME_LEN, "%s", pdata->name);
886 if (!sr_info->name) {
887 dev_err(&pdev->dev, "%s: Unable to alloc SR instance name\n",
888 __func__);
889 ret = -ENOMEM;
890 goto err_release_region;
891 }
892 885
893 sr_info->pdev = pdev; 886 sr_info->pdev = pdev;
894 sr_info->srid = pdev->id; 887 sr_info->srid = pdev->id;
@@ -905,13 +898,6 @@ static int __init omap_sr_probe(struct platform_device *pdev)
905 sr_info->autocomp_active = false; 898 sr_info->autocomp_active = false;
906 sr_info->ip_type = pdata->ip_type; 899 sr_info->ip_type = pdata->ip_type;
907 900
908 sr_info->base = ioremap(mem->start, resource_size(mem));
909 if (!sr_info->base) {
910 dev_err(&pdev->dev, "%s: ioremap fail\n", __func__);
911 ret = -ENOMEM;
912 goto err_free_name;
913 }
914
915 if (irq) 901 if (irq)
916 sr_info->irq = irq->start; 902 sr_info->irq = irq->start;
917 903
@@ -927,7 +913,7 @@ static int __init omap_sr_probe(struct platform_device *pdev)
927 ret = sr_late_init(sr_info); 913 ret = sr_late_init(sr_info);
928 if (ret) { 914 if (ret) {
929 pr_warning("%s: Error in SR late init\n", __func__); 915 pr_warning("%s: Error in SR late init\n", __func__);
930 goto err_iounmap; 916 goto err_list_del;
931 } 917 }
932 } 918 }
933 919
@@ -938,7 +924,7 @@ static int __init omap_sr_probe(struct platform_device *pdev)
938 ret = PTR_ERR(sr_dbg_dir); 924 ret = PTR_ERR(sr_dbg_dir);
939 pr_err("%s:sr debugfs dir creation failed(%d)\n", 925 pr_err("%s:sr debugfs dir creation failed(%d)\n",
940 __func__, ret); 926 __func__, ret);
941 goto err_iounmap; 927 goto err_list_del;
942 } 928 }
943 } 929 }
944 930
@@ -991,16 +977,8 @@ static int __init omap_sr_probe(struct platform_device *pdev)
991 977
992err_debugfs: 978err_debugfs:
993 debugfs_remove_recursive(sr_info->dbg_dir); 979 debugfs_remove_recursive(sr_info->dbg_dir);
994err_iounmap: 980err_list_del:
995 list_del(&sr_info->node); 981 list_del(&sr_info->node);
996 iounmap(sr_info->base);
997err_free_name:
998 kfree(sr_info->name);
999err_release_region:
1000 release_mem_region(mem->start, resource_size(mem));
1001err_free_devinfo:
1002 kfree(sr_info);
1003
1004 return ret; 982 return ret;
1005} 983}
1006 984
@@ -1008,7 +986,6 @@ static int omap_sr_remove(struct platform_device *pdev)
1008{ 986{
1009 struct omap_sr_data *pdata = pdev->dev.platform_data; 987 struct omap_sr_data *pdata = pdev->dev.platform_data;
1010 struct omap_sr *sr_info; 988 struct omap_sr *sr_info;
1011 struct resource *mem;
1012 989
1013 if (!pdata) { 990 if (!pdata) {
1014 dev_err(&pdev->dev, "%s: platform data missing\n", __func__); 991 dev_err(&pdev->dev, "%s: platform data missing\n", __func__);
@@ -1027,13 +1004,8 @@ static int omap_sr_remove(struct platform_device *pdev)
1027 if (sr_info->dbg_dir) 1004 if (sr_info->dbg_dir)
1028 debugfs_remove_recursive(sr_info->dbg_dir); 1005 debugfs_remove_recursive(sr_info->dbg_dir);
1029 1006
1007 pm_runtime_disable(&pdev->dev);
1030 list_del(&sr_info->node); 1008 list_del(&sr_info->node);
1031 iounmap(sr_info->base);
1032 kfree(sr_info->name);
1033 kfree(sr_info);
1034 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1035 release_mem_region(mem->start, resource_size(mem));
1036
1037 return 0; 1009 return 0;
1038} 1010}
1039 1011
@@ -1064,7 +1036,7 @@ static struct platform_driver smartreflex_driver = {
1064 .remove = omap_sr_remove, 1036 .remove = omap_sr_remove,
1065 .shutdown = omap_sr_shutdown, 1037 .shutdown = omap_sr_shutdown,
1066 .driver = { 1038 .driver = {
1067 .name = "smartreflex", 1039 .name = DRIVER_NAME,
1068 }, 1040 },
1069}; 1041};
1070 1042
diff --git a/drivers/scsi/scsi_pm.c b/drivers/scsi/scsi_pm.c
index 42539ee2cb11..4c5aabe21755 100644
--- a/drivers/scsi/scsi_pm.c
+++ b/drivers/scsi/scsi_pm.c
@@ -229,8 +229,6 @@ static int scsi_runtime_resume(struct device *dev)
229 229
230static int scsi_runtime_idle(struct device *dev) 230static int scsi_runtime_idle(struct device *dev)
231{ 231{
232 int err;
233
234 dev_dbg(dev, "scsi_runtime_idle\n"); 232 dev_dbg(dev, "scsi_runtime_idle\n");
235 233
236 /* Insert hooks here for targets, hosts, and transport classes */ 234 /* Insert hooks here for targets, hosts, and transport classes */
@@ -240,14 +238,11 @@ static int scsi_runtime_idle(struct device *dev)
240 238
241 if (sdev->request_queue->dev) { 239 if (sdev->request_queue->dev) {
242 pm_runtime_mark_last_busy(dev); 240 pm_runtime_mark_last_busy(dev);
243 err = pm_runtime_autosuspend(dev); 241 pm_runtime_autosuspend(dev);
244 } else { 242 return -EBUSY;
245 err = pm_runtime_suspend(dev);
246 } 243 }
247 } else {
248 err = pm_runtime_suspend(dev);
249 } 244 }
250 return err; 245 return 0;
251} 246}
252 247
253int scsi_autopm_get_device(struct scsi_device *sdev) 248int scsi_autopm_get_device(struct scsi_device *sdev)
diff --git a/drivers/sh/clk/core.c b/drivers/sh/clk/core.c
index 7715de2629c1..74727851820d 100644
--- a/drivers/sh/clk/core.c
+++ b/drivers/sh/clk/core.c
@@ -63,12 +63,12 @@ void clk_rate_table_build(struct clk *clk,
63 else 63 else
64 freq = clk->parent->rate * mult / div; 64 freq = clk->parent->rate * mult / div;
65 65
66 freq_table[i].index = i; 66 freq_table[i].driver_data = i;
67 freq_table[i].frequency = freq; 67 freq_table[i].frequency = freq;
68 } 68 }
69 69
70 /* Termination entry */ 70 /* Termination entry */
71 freq_table[i].index = i; 71 freq_table[i].driver_data = i;
72 freq_table[i].frequency = CPUFREQ_TABLE_END; 72 freq_table[i].frequency = CPUFREQ_TABLE_END;
73} 73}
74 74
diff --git a/drivers/sh/pm_runtime.c b/drivers/sh/pm_runtime.c
index afe9282629b9..8afa5a4589f2 100644
--- a/drivers/sh/pm_runtime.c
+++ b/drivers/sh/pm_runtime.c
@@ -25,7 +25,7 @@
25static int default_platform_runtime_idle(struct device *dev) 25static int default_platform_runtime_idle(struct device *dev)
26{ 26{
27 /* suspend synchronously to disable clocks immediately */ 27 /* suspend synchronously to disable clocks immediately */
28 return pm_runtime_suspend(dev); 28 return 0;
29} 29}
30 30
31static struct dev_pm_domain default_pm_domain = { 31static struct dev_pm_domain default_pm_domain = {
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 32b7bb111eb6..095cfaded1c0 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -223,7 +223,7 @@ static const struct dev_pm_ops spi_pm = {
223 SET_RUNTIME_PM_OPS( 223 SET_RUNTIME_PM_OPS(
224 pm_generic_runtime_suspend, 224 pm_generic_runtime_suspend,
225 pm_generic_runtime_resume, 225 pm_generic_runtime_resume,
226 pm_generic_runtime_idle 226 NULL
227 ) 227 )
228}; 228};
229 229
diff --git a/drivers/staging/android/binder.c b/drivers/staging/android/binder.c
index c6dc1846943f..119d486a5cf7 100644
--- a/drivers/staging/android/binder.c
+++ b/drivers/staging/android/binder.c
@@ -20,6 +20,7 @@
20#include <asm/cacheflush.h> 20#include <asm/cacheflush.h>
21#include <linux/fdtable.h> 21#include <linux/fdtable.h>
22#include <linux/file.h> 22#include <linux/file.h>
23#include <linux/freezer.h>
23#include <linux/fs.h> 24#include <linux/fs.h>
24#include <linux/list.h> 25#include <linux/list.h>
25#include <linux/miscdevice.h> 26#include <linux/miscdevice.h>
@@ -2140,13 +2141,13 @@ retry:
2140 if (!binder_has_proc_work(proc, thread)) 2141 if (!binder_has_proc_work(proc, thread))
2141 ret = -EAGAIN; 2142 ret = -EAGAIN;
2142 } else 2143 } else
2143 ret = wait_event_interruptible_exclusive(proc->wait, binder_has_proc_work(proc, thread)); 2144 ret = wait_event_freezable_exclusive(proc->wait, binder_has_proc_work(proc, thread));
2144 } else { 2145 } else {
2145 if (non_block) { 2146 if (non_block) {
2146 if (!binder_has_thread_work(thread)) 2147 if (!binder_has_thread_work(thread))
2147 ret = -EAGAIN; 2148 ret = -EAGAIN;
2148 } else 2149 } else
2149 ret = wait_event_interruptible(thread->wait, binder_has_thread_work(thread)); 2150 ret = wait_event_freezable(thread->wait, binder_has_thread_work(thread));
2150 } 2151 }
2151 2152
2152 binder_lock(__func__); 2153 binder_lock(__func__);
diff --git a/drivers/tty/serial/mfd.c b/drivers/tty/serial/mfd.c
index e266eca0ec76..4a82267af83f 100644
--- a/drivers/tty/serial/mfd.c
+++ b/drivers/tty/serial/mfd.c
@@ -1252,13 +1252,8 @@ static int serial_hsu_resume(struct pci_dev *pdev)
1252#ifdef CONFIG_PM_RUNTIME 1252#ifdef CONFIG_PM_RUNTIME
1253static int serial_hsu_runtime_idle(struct device *dev) 1253static int serial_hsu_runtime_idle(struct device *dev)
1254{ 1254{
1255 int err; 1255 pm_schedule_suspend(dev, 500);
1256 1256 return -EBUSY;
1257 err = pm_schedule_suspend(dev, 500);
1258 if (err)
1259 return -EBUSY;
1260
1261 return 0;
1262} 1257}
1263 1258
1264static int serial_hsu_runtime_suspend(struct device *dev) 1259static int serial_hsu_runtime_suspend(struct device *dev)
diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
index 6eab440e1542..7609ac4aed1c 100644
--- a/drivers/usb/core/driver.c
+++ b/drivers/usb/core/driver.c
@@ -1765,7 +1765,8 @@ int usb_runtime_idle(struct device *dev)
1765 */ 1765 */
1766 if (autosuspend_check(udev) == 0) 1766 if (autosuspend_check(udev) == 0)
1767 pm_runtime_autosuspend(dev); 1767 pm_runtime_autosuspend(dev);
1768 return 0; 1768 /* Tell the core not to suspend it, though. */
1769 return -EBUSY;
1769} 1770}
1770 1771
1771int usb_set_usb2_hardware_lpm(struct usb_device *udev, int enable) 1772int usb_set_usb2_hardware_lpm(struct usb_device *udev, int enable)
diff --git a/drivers/usb/core/port.c b/drivers/usb/core/port.c
index 5fd3fee58f8b..d6b0fadf53e9 100644
--- a/drivers/usb/core/port.c
+++ b/drivers/usb/core/port.c
@@ -141,7 +141,6 @@ static const struct dev_pm_ops usb_port_pm_ops = {
141#ifdef CONFIG_PM_RUNTIME 141#ifdef CONFIG_PM_RUNTIME
142 .runtime_suspend = usb_port_runtime_suspend, 142 .runtime_suspend = usb_port_runtime_suspend,
143 .runtime_resume = usb_port_runtime_resume, 143 .runtime_resume = usb_port_runtime_resume,
144 .runtime_idle = pm_generic_runtime_idle,
145#endif 144#endif
146}; 145};
147 146