aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2013-11-13 23:41:48 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2013-11-13 23:41:48 -0500
commitf9300eaaac1ca300083ad41937923a90cc3a2394 (patch)
tree724b72ad729a8b85c09d2d54f8ca7d8ba22d774f /drivers/acpi
parent7f2dc5c4bcbff035b0d03f7aa78a182664b21e47 (diff)
parentfaddf2f5d278f1656e9444961bdd8d9db4deb5bf (diff)
Merge tag 'pm+acpi-3.13-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm
Pull ACPI and power management updates from Rafael J Wysocki: - New power capping framework and the the Intel Running Average Power Limit (RAPL) driver using it from Srinivas Pandruvada and Jacob Pan. - Addition of the in-kernel switching feature to the arm_big_little cpufreq driver from Viresh Kumar and Nicolas Pitre. - cpufreq support for iMac G5 from Aaro Koskinen. - Baytrail processors support for intel_pstate from Dirk Brandewie. - cpufreq support for Midway/ECX-2000 from Mark Langsdorf. - ARM vexpress/TC2 cpufreq support from Sudeep KarkadaNagesha. - ACPI power management support for the I2C and SPI bus types from Mika Westerberg and Lv Zheng. - cpufreq core fixes and cleanups from Viresh Kumar, Srivatsa S Bhat, Stratos Karafotis, Xiaoguang Chen, Lan Tianyu. - cpufreq drivers updates (mostly fixes and cleanups) from Viresh Kumar, Aaro Koskinen, Jungseok Lee, Sudeep KarkadaNagesha, Lukasz Majewski, Manish Badarkhe, Hans-Christian Egtvedt, Evgeny Kapaev. - intel_pstate updates from Dirk Brandewie and Adrian Huang. - ACPICA update to version 20130927 includig fixes and cleanups and some reduction of divergences between the ACPICA code in the kernel and ACPICA upstream in order to improve the automatic ACPICA patch generation process. From Bob Moore, Lv Zheng, Tomasz Nowicki, Naresh Bhat, Bjorn Helgaas, David E Box. - ACPI IPMI driver fixes and cleanups from Lv Zheng. - ACPI hotplug fixes and cleanups from Bjorn Helgaas, Toshi Kani, Zhang Yanfei, Rafael J Wysocki. - Conversion of the ACPI AC driver to the platform bus type and multiple driver fixes and cleanups related to ACPI from Zhang Rui. - ACPI processor driver fixes and cleanups from Hanjun Guo, Jiang Liu, Bartlomiej Zolnierkiewicz, Mathieu Rhéaume, Rafael J Wysocki. - Fixes and cleanups and new blacklist entries related to the ACPI video support from Aaron Lu, Felipe Contreras, Lennart Poettering, Kirill Tkhai. - cpuidle core cleanups from Viresh Kumar and Lorenzo Pieralisi. - cpuidle drivers fixes and cleanups from Daniel Lezcano, Jingoo Han, Bartlomiej Zolnierkiewicz, Prarit Bhargava. - devfreq updates from Sachin Kamat, Dan Carpenter, Manish Badarkhe. - Operation Performance Points (OPP) core updates from Nishanth Menon. - Runtime power management core fix from Rafael J Wysocki and update from Ulf Hansson. - Hibernation fixes from Aaron Lu and Rafael J Wysocki. - Device suspend/resume lockup detection mechanism from Benoit Goby. - Removal of unused proc directories created for various ACPI drivers from Lan Tianyu. - ACPI LPSS driver fix and new device IDs for the ACPI platform scan handler from Heikki Krogerus and Jarkko Nikula. - New ACPI _OSI blacklist entry for Toshiba NB100 from Levente Kurusa. - Assorted fixes and cleanups related to ACPI from Andy Shevchenko, Al Stone, Bartlomiej Zolnierkiewicz, Colin Ian King, Dan Carpenter, Felipe Contreras, Jianguo Wu, Lan Tianyu, Yinghai Lu, Mathias Krause, Liu Chuansheng. - Assorted PM fixes and cleanups from Andy Shevchenko, Thierry Reding, Jean-Christophe Plagniol-Villard. * tag 'pm+acpi-3.13-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm: (386 commits) cpufreq: conservative: fix requested_freq reduction issue ACPI / hotplug: Consolidate deferred execution of ACPI hotplug routines PM / runtime: Use pm_runtime_put_sync() in __device_release_driver() ACPI / event: remove unneeded NULL pointer check Revert "ACPI / video: Ignore BIOS initial backlight value for HP 250 G1" ACPI / video: Quirk initial backlight level 0 ACPI / video: Fix initial level validity test intel_pstate: skip the driver if ACPI has power mgmt option PM / hibernate: Avoid overflow in hibernate_preallocate_memory() ACPI / hotplug: Do not execute "insert in progress" _OST ACPI / hotplug: Carry out PCI root eject directly ACPI / hotplug: Merge device hot-removal routines ACPI / hotplug: Make acpi_bus_hot_remove_device() internal ACPI / hotplug: Simplify device ejection routines ACPI / hotplug: Fix handle_root_bridge_removal() ACPI / hotplug: Refuse to hot-remove all objects with disabled hotplug ACPI / scan: Start matching drivers after trying scan handlers ACPI: Remove acpi_pci_slot_init() headers from internal.h ACPI / blacklist: fix name of ThinkPad Edge E530 PowerCap: Fix build error with option -Werror=format-security ... Conflicts: arch/arm/mach-omap2/opp.c drivers/Kconfig drivers/spi/spi.c
Diffstat (limited to 'drivers/acpi')
-rw-r--r--drivers/acpi/Kconfig20
-rw-r--r--drivers/acpi/Makefile1
-rw-r--r--drivers/acpi/ac.c256
-rw-r--r--drivers/acpi/acpi_ipmi.c580
-rw-r--r--drivers/acpi/acpi_lpss.c12
-rw-r--r--drivers/acpi/acpi_memhotplug.c7
-rw-r--r--drivers/acpi/acpi_platform.c7
-rw-r--r--drivers/acpi/acpi_processor.c28
-rw-r--r--drivers/acpi/acpica/acdebug.h8
-rw-r--r--drivers/acpi/acpica/acevents.h9
-rw-r--r--drivers/acpi/acpica/acglobal.h20
-rw-r--r--drivers/acpi/acpica/aclocal.h11
-rw-r--r--drivers/acpi/acpica/acmacros.h31
-rw-r--r--drivers/acpi/acpica/acnamesp.h6
-rw-r--r--drivers/acpi/acpica/acutils.h17
-rw-r--r--drivers/acpi/acpica/dsargs.c2
-rw-r--r--drivers/acpi/acpica/dsfield.c2
-rw-r--r--drivers/acpi/acpica/dsmethod.c5
-rw-r--r--drivers/acpi/acpica/dsobject.c2
-rw-r--r--drivers/acpi/acpica/dsopcode.c2
-rw-r--r--drivers/acpi/acpica/dsutils.c10
-rw-r--r--drivers/acpi/acpica/dswexec.c6
-rw-r--r--drivers/acpi/acpica/dswload2.c2
-rw-r--r--drivers/acpi/acpica/evglock.c2
-rw-r--r--drivers/acpi/acpica/evgpe.c3
-rw-r--r--drivers/acpi/acpica/evgpeblk.c6
-rw-r--r--drivers/acpi/acpica/evgpeinit.c2
-rw-r--r--drivers/acpi/acpica/evgpeutil.c4
-rw-r--r--drivers/acpi/acpica/evhandler.c4
-rw-r--r--drivers/acpi/acpica/evmisc.c14
-rw-r--r--drivers/acpi/acpica/evregion.c29
-rw-r--r--drivers/acpi/acpica/evsci.c79
-rw-r--r--drivers/acpi/acpica/evxface.c148
-rw-r--r--drivers/acpi/acpica/evxfevnt.c3
-rw-r--r--drivers/acpi/acpica/evxfgpe.c9
-rw-r--r--drivers/acpi/acpica/evxfregn.c7
-rw-r--r--drivers/acpi/acpica/excreate.c8
-rw-r--r--drivers/acpi/acpica/exfield.c2
-rw-r--r--drivers/acpi/acpica/exfldio.c8
-rw-r--r--drivers/acpi/acpica/exmisc.c4
-rw-r--r--drivers/acpi/acpica/exoparg1.c8
-rw-r--r--drivers/acpi/acpica/exoparg2.c10
-rw-r--r--drivers/acpi/acpica/exoparg3.c4
-rw-r--r--drivers/acpi/acpica/exoparg6.c2
-rw-r--r--drivers/acpi/acpica/exregion.c1
-rw-r--r--drivers/acpi/acpica/exresolv.c2
-rw-r--r--drivers/acpi/acpica/exresop.c2
-rw-r--r--drivers/acpi/acpica/hwregs.c2
-rw-r--r--drivers/acpi/acpica/hwtimer.c3
-rw-r--r--drivers/acpi/acpica/hwxface.c43
-rw-r--r--drivers/acpi/acpica/hwxfsleep.c7
-rw-r--r--drivers/acpi/acpica/nsaccess.c7
-rw-r--r--drivers/acpi/acpica/nsdump.c143
-rw-r--r--drivers/acpi/acpica/nsdumpdv.c7
-rw-r--r--drivers/acpi/acpica/nseval.c4
-rw-r--r--drivers/acpi/acpica/nsinit.c2
-rw-r--r--drivers/acpi/acpica/nsload.c2
-rw-r--r--drivers/acpi/acpica/nsparse.c2
-rw-r--r--drivers/acpi/acpica/nspredef.c2
-rw-r--r--drivers/acpi/acpica/nsprepkg.c4
-rw-r--r--drivers/acpi/acpica/nsrepair.c2
-rw-r--r--drivers/acpi/acpica/nsrepair2.c2
-rw-r--r--drivers/acpi/acpica/nssearch.c3
-rw-r--r--drivers/acpi/acpica/nsutils.c2
-rw-r--r--drivers/acpi/acpica/nsxfeval.c23
-rw-r--r--drivers/acpi/acpica/nsxfname.c7
-rw-r--r--drivers/acpi/acpica/nsxfobj.c7
-rw-r--r--drivers/acpi/acpica/psparse.c2
-rw-r--r--drivers/acpi/acpica/psxface.c6
-rw-r--r--drivers/acpi/acpica/rsmisc.c4
-rw-r--r--drivers/acpi/acpica/rsutils.c2
-rw-r--r--drivers/acpi/acpica/rsxface.c3
-rw-r--r--drivers/acpi/acpica/tbinstal.c18
-rw-r--r--drivers/acpi/acpica/tbprint.c18
-rw-r--r--drivers/acpi/acpica/tbutils.c5
-rw-r--r--drivers/acpi/acpica/tbxface.c16
-rw-r--r--drivers/acpi/acpica/tbxfload.c11
-rw-r--r--drivers/acpi/acpica/tbxfroot.c5
-rw-r--r--drivers/acpi/acpica/utalloc.c117
-rw-r--r--drivers/acpi/acpica/utcache.c2
-rw-r--r--drivers/acpi/acpica/utcopy.c4
-rw-r--r--drivers/acpi/acpica/utdebug.c5
-rw-r--r--drivers/acpi/acpica/utdecode.c1
-rw-r--r--drivers/acpi/acpica/utdelete.c2
-rw-r--r--drivers/acpi/acpica/uteval.c2
-rw-r--r--drivers/acpi/acpica/utexcep.c3
-rw-r--r--drivers/acpi/acpica/utglobal.c20
-rw-r--r--drivers/acpi/acpica/utids.c2
-rw-r--r--drivers/acpi/acpica/utobject.c26
-rw-r--r--drivers/acpi/acpica/utownerid.c2
-rw-r--r--drivers/acpi/acpica/utresrc.c4
-rw-r--r--drivers/acpi/acpica/utstate.c1
-rw-r--r--drivers/acpi/acpica/utstring.c66
-rw-r--r--drivers/acpi/acpica/uttrack.c31
-rw-r--r--drivers/acpi/acpica/utxface.c45
-rw-r--r--drivers/acpi/acpica/utxferror.c3
-rw-r--r--drivers/acpi/acpica/utxfinit.c18
-rw-r--r--drivers/acpi/battery.c328
-rw-r--r--drivers/acpi/blacklist.c63
-rw-r--r--drivers/acpi/button.c9
-rw-r--r--drivers/acpi/cm_sbs.c105
-rw-r--r--drivers/acpi/device_pm.c8
-rw-r--r--drivers/acpi/dock.c31
-rw-r--r--drivers/acpi/ec.c49
-rw-r--r--drivers/acpi/event.c5
-rw-r--r--drivers/acpi/fan.c2
-rw-r--r--drivers/acpi/internal.h10
-rw-r--r--drivers/acpi/numa.c4
-rw-r--r--drivers/acpi/osl.c144
-rw-r--r--drivers/acpi/pci_root.c51
-rw-r--r--drivers/acpi/proc.c305
-rw-r--r--drivers/acpi/processor_core.c26
-rw-r--r--drivers/acpi/processor_driver.c4
-rw-r--r--drivers/acpi/processor_idle.c15
-rw-r--r--drivers/acpi/processor_perflib.c22
-rw-r--r--drivers/acpi/sbs.c325
-rw-r--r--drivers/acpi/scan.c176
-rw-r--r--drivers/acpi/sysfs.c18
-rw-r--r--drivers/acpi/thermal.c43
-rw-r--r--drivers/acpi/utils.c21
-rw-r--r--drivers/acpi/video.c461
-rw-r--r--drivers/acpi/video_detect.c12
122 files changed, 1921 insertions, 2439 deletions
diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig
index e11faae81ed9..c95df0b8c880 100644
--- a/drivers/acpi/Kconfig
+++ b/drivers/acpi/Kconfig
@@ -56,23 +56,6 @@ config ACPI_PROCFS
56 56
57 Say N to delete /proc/acpi/ files that have moved to /sys/ 57 Say N to delete /proc/acpi/ files that have moved to /sys/
58 58
59config ACPI_PROCFS_POWER
60 bool "Deprecated power /proc/acpi directories"
61 depends on PROC_FS
62 help
63 For backwards compatibility, this option allows
64 deprecated power /proc/acpi/ directories to exist, even when
65 they have been replaced by functions in /sys.
66 The deprecated directories (and their replacements) include:
67 /proc/acpi/battery/* (/sys/class/power_supply/*)
68 /proc/acpi/ac_adapter/* (sys/class/power_supply/*)
69 This option has no effect on /proc/acpi/ directories
70 and functions, which do not yet exist in /sys
71 This option, together with the proc directories, will be
72 deleted in 2.6.39.
73
74 Say N to delete power /proc/acpi/ directories that have moved to /sys/
75
76config ACPI_EC_DEBUGFS 59config ACPI_EC_DEBUGFS
77 tristate "EC read/write access through /sys/kernel/debug/ec" 60 tristate "EC read/write access through /sys/kernel/debug/ec"
78 default n 61 default n
@@ -175,9 +158,10 @@ config ACPI_PROCESSOR
175 158
176 To compile this driver as a module, choose M here: 159 To compile this driver as a module, choose M here:
177 the module will be called processor. 160 the module will be called processor.
161
178config ACPI_IPMI 162config ACPI_IPMI
179 tristate "IPMI" 163 tristate "IPMI"
180 depends on IPMI_SI && IPMI_HANDLER 164 depends on IPMI_SI
181 default n 165 default n
182 help 166 help
183 This driver enables the ACPI to access the BMC controller. And it 167 This driver enables the ACPI to access the BMC controller. And it
diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index bce34afadcd0..0331f91d56e6 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -47,7 +47,6 @@ acpi-y += sysfs.o
47acpi-$(CONFIG_X86) += acpi_cmos_rtc.o 47acpi-$(CONFIG_X86) += acpi_cmos_rtc.o
48acpi-$(CONFIG_DEBUG_FS) += debugfs.o 48acpi-$(CONFIG_DEBUG_FS) += debugfs.o
49acpi-$(CONFIG_ACPI_NUMA) += numa.o 49acpi-$(CONFIG_ACPI_NUMA) += numa.o
50acpi-$(CONFIG_ACPI_PROCFS_POWER) += cm_sbs.o
51ifdef CONFIG_ACPI_VIDEO 50ifdef CONFIG_ACPI_VIDEO
52acpi-y += video_detect.o 51acpi-y += video_detect.o
53endif 52endif
diff --git a/drivers/acpi/ac.c b/drivers/acpi/ac.c
index f37beaa32750..b9f0d5f4bba5 100644
--- a/drivers/acpi/ac.c
+++ b/drivers/acpi/ac.c
@@ -30,10 +30,7 @@
30#include <linux/types.h> 30#include <linux/types.h>
31#include <linux/dmi.h> 31#include <linux/dmi.h>
32#include <linux/delay.h> 32#include <linux/delay.h>
33#ifdef CONFIG_ACPI_PROCFS_POWER 33#include <linux/platform_device.h>
34#include <linux/proc_fs.h>
35#include <linux/seq_file.h>
36#endif
37#include <linux/power_supply.h> 34#include <linux/power_supply.h>
38#include <acpi/acpi_bus.h> 35#include <acpi/acpi_bus.h>
39#include <acpi/acpi_drivers.h> 36#include <acpi/acpi_drivers.h>
@@ -55,75 +52,30 @@ MODULE_AUTHOR("Paul Diefenbaugh");
55MODULE_DESCRIPTION("ACPI AC Adapter Driver"); 52MODULE_DESCRIPTION("ACPI AC Adapter Driver");
56MODULE_LICENSE("GPL"); 53MODULE_LICENSE("GPL");
57 54
58#ifdef CONFIG_ACPI_PROCFS_POWER
59extern struct proc_dir_entry *acpi_lock_ac_dir(void);
60extern void *acpi_unlock_ac_dir(struct proc_dir_entry *acpi_ac_dir);
61static int acpi_ac_open_fs(struct inode *inode, struct file *file);
62#endif
63
64static int acpi_ac_add(struct acpi_device *device);
65static int acpi_ac_remove(struct acpi_device *device);
66static void acpi_ac_notify(struct acpi_device *device, u32 event);
67
68static const struct acpi_device_id ac_device_ids[] = {
69 {"ACPI0003", 0},
70 {"", 0},
71};
72MODULE_DEVICE_TABLE(acpi, ac_device_ids);
73
74#ifdef CONFIG_PM_SLEEP
75static int acpi_ac_resume(struct device *dev);
76#endif
77static SIMPLE_DEV_PM_OPS(acpi_ac_pm, NULL, acpi_ac_resume);
78
79static int ac_sleep_before_get_state_ms; 55static int ac_sleep_before_get_state_ms;
80 56
81static struct acpi_driver acpi_ac_driver = {
82 .name = "ac",
83 .class = ACPI_AC_CLASS,
84 .ids = ac_device_ids,
85 .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
86 .ops = {
87 .add = acpi_ac_add,
88 .remove = acpi_ac_remove,
89 .notify = acpi_ac_notify,
90 },
91 .drv.pm = &acpi_ac_pm,
92};
93
94struct acpi_ac { 57struct acpi_ac {
95 struct power_supply charger; 58 struct power_supply charger;
96 struct acpi_device * device; 59 struct acpi_device *adev;
60 struct platform_device *pdev;
97 unsigned long long state; 61 unsigned long long state;
98}; 62};
99 63
100#define to_acpi_ac(x) container_of(x, struct acpi_ac, charger) 64#define to_acpi_ac(x) container_of(x, struct acpi_ac, charger)
101 65
102#ifdef CONFIG_ACPI_PROCFS_POWER
103static const struct file_operations acpi_ac_fops = {
104 .owner = THIS_MODULE,
105 .open = acpi_ac_open_fs,
106 .read = seq_read,
107 .llseek = seq_lseek,
108 .release = single_release,
109};
110#endif
111
112/* -------------------------------------------------------------------------- 66/* --------------------------------------------------------------------------
113 AC Adapter Management 67 AC Adapter Management
114 -------------------------------------------------------------------------- */ 68 -------------------------------------------------------------------------- */
115 69
116static int acpi_ac_get_state(struct acpi_ac *ac) 70static int acpi_ac_get_state(struct acpi_ac *ac)
117{ 71{
118 acpi_status status = AE_OK; 72 acpi_status status;
119
120
121 if (!ac)
122 return -EINVAL;
123 73
124 status = acpi_evaluate_integer(ac->device->handle, "_PSR", NULL, &ac->state); 74 status = acpi_evaluate_integer(ac->adev->handle, "_PSR", NULL,
75 &ac->state);
125 if (ACPI_FAILURE(status)) { 76 if (ACPI_FAILURE(status)) {
126 ACPI_EXCEPTION((AE_INFO, status, "Error reading AC Adapter state")); 77 ACPI_EXCEPTION((AE_INFO, status,
78 "Error reading AC Adapter state"));
127 ac->state = ACPI_AC_STATUS_UNKNOWN; 79 ac->state = ACPI_AC_STATUS_UNKNOWN;
128 return -ENODEV; 80 return -ENODEV;
129 } 81 }
@@ -160,91 +112,13 @@ static enum power_supply_property ac_props[] = {
160 POWER_SUPPLY_PROP_ONLINE, 112 POWER_SUPPLY_PROP_ONLINE,
161}; 113};
162 114
163#ifdef CONFIG_ACPI_PROCFS_POWER
164/* --------------------------------------------------------------------------
165 FS Interface (/proc)
166 -------------------------------------------------------------------------- */
167
168static struct proc_dir_entry *acpi_ac_dir;
169
170static int acpi_ac_seq_show(struct seq_file *seq, void *offset)
171{
172 struct acpi_ac *ac = seq->private;
173
174
175 if (!ac)
176 return 0;
177
178 if (acpi_ac_get_state(ac)) {
179 seq_puts(seq, "ERROR: Unable to read AC Adapter state\n");
180 return 0;
181 }
182
183 seq_puts(seq, "state: ");
184 switch (ac->state) {
185 case ACPI_AC_STATUS_OFFLINE:
186 seq_puts(seq, "off-line\n");
187 break;
188 case ACPI_AC_STATUS_ONLINE:
189 seq_puts(seq, "on-line\n");
190 break;
191 default:
192 seq_puts(seq, "unknown\n");
193 break;
194 }
195
196 return 0;
197}
198
199static int acpi_ac_open_fs(struct inode *inode, struct file *file)
200{
201 return single_open(file, acpi_ac_seq_show, PDE_DATA(inode));
202}
203
204static int acpi_ac_add_fs(struct acpi_device *device)
205{
206 struct proc_dir_entry *entry = NULL;
207
208 printk(KERN_WARNING PREFIX "Deprecated procfs I/F for AC is loaded,"
209 " please retry with CONFIG_ACPI_PROCFS_POWER cleared\n");
210 if (!acpi_device_dir(device)) {
211 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
212 acpi_ac_dir);
213 if (!acpi_device_dir(device))
214 return -ENODEV;
215 }
216
217 /* 'state' [R] */
218 entry = proc_create_data(ACPI_AC_FILE_STATE,
219 S_IRUGO, acpi_device_dir(device),
220 &acpi_ac_fops, acpi_driver_data(device));
221 if (!entry)
222 return -ENODEV;
223 return 0;
224}
225
226static int acpi_ac_remove_fs(struct acpi_device *device)
227{
228
229 if (acpi_device_dir(device)) {
230 remove_proc_entry(ACPI_AC_FILE_STATE, acpi_device_dir(device));
231
232 remove_proc_entry(acpi_device_bid(device), acpi_ac_dir);
233 acpi_device_dir(device) = NULL;
234 }
235
236 return 0;
237}
238#endif
239
240/* -------------------------------------------------------------------------- 115/* --------------------------------------------------------------------------
241 Driver Model 116 Driver Model
242 -------------------------------------------------------------------------- */ 117 -------------------------------------------------------------------------- */
243 118
244static void acpi_ac_notify(struct acpi_device *device, u32 event) 119static void acpi_ac_notify_handler(acpi_handle handle, u32 event, void *data)
245{ 120{
246 struct acpi_ac *ac = acpi_driver_data(device); 121 struct acpi_ac *ac = data;
247
248 122
249 if (!ac) 123 if (!ac)
250 return; 124 return;
@@ -267,10 +141,10 @@ static void acpi_ac_notify(struct acpi_device *device, u32 event)
267 msleep(ac_sleep_before_get_state_ms); 141 msleep(ac_sleep_before_get_state_ms);
268 142
269 acpi_ac_get_state(ac); 143 acpi_ac_get_state(ac);
270 acpi_bus_generate_netlink_event(device->pnp.device_class, 144 acpi_bus_generate_netlink_event(ac->adev->pnp.device_class,
271 dev_name(&device->dev), event, 145 dev_name(&ac->pdev->dev),
272 (u32) ac->state); 146 event, (u32) ac->state);
273 acpi_notifier_call_chain(device, event, (u32) ac->state); 147 acpi_notifier_call_chain(ac->adev, event, (u32) ac->state);
274 kobject_uevent(&ac->charger.dev->kobj, KOBJ_CHANGE); 148 kobject_uevent(&ac->charger.dev->kobj, KOBJ_CHANGE);
275 } 149 }
276 150
@@ -295,53 +169,55 @@ static struct dmi_system_id ac_dmi_table[] = {
295 {}, 169 {},
296}; 170};
297 171
298static int acpi_ac_add(struct acpi_device *device) 172static int acpi_ac_probe(struct platform_device *pdev)
299{ 173{
300 int result = 0; 174 int result = 0;
301 struct acpi_ac *ac = NULL; 175 struct acpi_ac *ac = NULL;
176 struct acpi_device *adev;
302 177
303 178 if (!pdev)
304 if (!device)
305 return -EINVAL; 179 return -EINVAL;
306 180
181 result = acpi_bus_get_device(ACPI_HANDLE(&pdev->dev), &adev);
182 if (result)
183 return -ENODEV;
184
307 ac = kzalloc(sizeof(struct acpi_ac), GFP_KERNEL); 185 ac = kzalloc(sizeof(struct acpi_ac), GFP_KERNEL);
308 if (!ac) 186 if (!ac)
309 return -ENOMEM; 187 return -ENOMEM;
310 188
311 ac->device = device; 189 strcpy(acpi_device_name(adev), ACPI_AC_DEVICE_NAME);
312 strcpy(acpi_device_name(device), ACPI_AC_DEVICE_NAME); 190 strcpy(acpi_device_class(adev), ACPI_AC_CLASS);
313 strcpy(acpi_device_class(device), ACPI_AC_CLASS); 191 ac->adev = adev;
314 device->driver_data = ac; 192 ac->pdev = pdev;
193 platform_set_drvdata(pdev, ac);
315 194
316 result = acpi_ac_get_state(ac); 195 result = acpi_ac_get_state(ac);
317 if (result) 196 if (result)
318 goto end; 197 goto end;
319 198
320#ifdef CONFIG_ACPI_PROCFS_POWER 199 ac->charger.name = acpi_device_bid(adev);
321 result = acpi_ac_add_fs(device);
322#endif
323 if (result)
324 goto end;
325 ac->charger.name = acpi_device_bid(device);
326 ac->charger.type = POWER_SUPPLY_TYPE_MAINS; 200 ac->charger.type = POWER_SUPPLY_TYPE_MAINS;
327 ac->charger.properties = ac_props; 201 ac->charger.properties = ac_props;
328 ac->charger.num_properties = ARRAY_SIZE(ac_props); 202 ac->charger.num_properties = ARRAY_SIZE(ac_props);
329 ac->charger.get_property = get_ac_property; 203 ac->charger.get_property = get_ac_property;
330 result = power_supply_register(&ac->device->dev, &ac->charger); 204 result = power_supply_register(&pdev->dev, &ac->charger);
331 if (result) 205 if (result)
332 goto end; 206 goto end;
333 207
208 result = acpi_install_notify_handler(ACPI_HANDLE(&pdev->dev),
209 ACPI_DEVICE_NOTIFY, acpi_ac_notify_handler, ac);
210 if (result) {
211 power_supply_unregister(&ac->charger);
212 goto end;
213 }
334 printk(KERN_INFO PREFIX "%s [%s] (%s)\n", 214 printk(KERN_INFO PREFIX "%s [%s] (%s)\n",
335 acpi_device_name(device), acpi_device_bid(device), 215 acpi_device_name(adev), acpi_device_bid(adev),
336 ac->state ? "on-line" : "off-line"); 216 ac->state ? "on-line" : "off-line");
337 217
338 end: 218end:
339 if (result) { 219 if (result)
340#ifdef CONFIG_ACPI_PROCFS_POWER
341 acpi_ac_remove_fs(device);
342#endif
343 kfree(ac); 220 kfree(ac);
344 }
345 221
346 dmi_check_system(ac_dmi_table); 222 dmi_check_system(ac_dmi_table);
347 return result; 223 return result;
@@ -356,7 +232,7 @@ static int acpi_ac_resume(struct device *dev)
356 if (!dev) 232 if (!dev)
357 return -EINVAL; 233 return -EINVAL;
358 234
359 ac = acpi_driver_data(to_acpi_device(dev)); 235 ac = platform_get_drvdata(to_platform_device(dev));
360 if (!ac) 236 if (!ac)
361 return -EINVAL; 237 return -EINVAL;
362 238
@@ -368,28 +244,44 @@ static int acpi_ac_resume(struct device *dev)
368 return 0; 244 return 0;
369} 245}
370#endif 246#endif
247static SIMPLE_DEV_PM_OPS(acpi_ac_pm_ops, NULL, acpi_ac_resume);
371 248
372static int acpi_ac_remove(struct acpi_device *device) 249static int acpi_ac_remove(struct platform_device *pdev)
373{ 250{
374 struct acpi_ac *ac = NULL; 251 struct acpi_ac *ac;
375
376 252
377 if (!device || !acpi_driver_data(device)) 253 if (!pdev)
378 return -EINVAL; 254 return -EINVAL;
379 255
380 ac = acpi_driver_data(device); 256 acpi_remove_notify_handler(ACPI_HANDLE(&pdev->dev),
257 ACPI_DEVICE_NOTIFY, acpi_ac_notify_handler);
381 258
259 ac = platform_get_drvdata(pdev);
382 if (ac->charger.dev) 260 if (ac->charger.dev)
383 power_supply_unregister(&ac->charger); 261 power_supply_unregister(&ac->charger);
384#ifdef CONFIG_ACPI_PROCFS_POWER
385 acpi_ac_remove_fs(device);
386#endif
387 262
388 kfree(ac); 263 kfree(ac);
389 264
390 return 0; 265 return 0;
391} 266}
392 267
268static const struct acpi_device_id acpi_ac_match[] = {
269 { "ACPI0003", 0 },
270 { }
271};
272MODULE_DEVICE_TABLE(acpi, acpi_ac_match);
273
274static struct platform_driver acpi_ac_driver = {
275 .probe = acpi_ac_probe,
276 .remove = acpi_ac_remove,
277 .driver = {
278 .name = "acpi-ac",
279 .owner = THIS_MODULE,
280 .pm = &acpi_ac_pm_ops,
281 .acpi_match_table = ACPI_PTR(acpi_ac_match),
282 },
283};
284
393static int __init acpi_ac_init(void) 285static int __init acpi_ac_init(void)
394{ 286{
395 int result; 287 int result;
@@ -397,34 +289,16 @@ static int __init acpi_ac_init(void)
397 if (acpi_disabled) 289 if (acpi_disabled)
398 return -ENODEV; 290 return -ENODEV;
399 291
400#ifdef CONFIG_ACPI_PROCFS_POWER 292 result = platform_driver_register(&acpi_ac_driver);
401 acpi_ac_dir = acpi_lock_ac_dir(); 293 if (result < 0)
402 if (!acpi_ac_dir)
403 return -ENODEV; 294 return -ENODEV;
404#endif
405
406 result = acpi_bus_register_driver(&acpi_ac_driver);
407 if (result < 0) {
408#ifdef CONFIG_ACPI_PROCFS_POWER
409 acpi_unlock_ac_dir(acpi_ac_dir);
410#endif
411 return -ENODEV;
412 }
413 295
414 return 0; 296 return 0;
415} 297}
416 298
417static void __exit acpi_ac_exit(void) 299static void __exit acpi_ac_exit(void)
418{ 300{
419 301 platform_driver_unregister(&acpi_ac_driver);
420 acpi_bus_unregister_driver(&acpi_ac_driver);
421
422#ifdef CONFIG_ACPI_PROCFS_POWER
423 acpi_unlock_ac_dir(acpi_ac_dir);
424#endif
425
426 return;
427} 302}
428
429module_init(acpi_ac_init); 303module_init(acpi_ac_init);
430module_exit(acpi_ac_exit); 304module_exit(acpi_ac_exit);
diff --git a/drivers/acpi/acpi_ipmi.c b/drivers/acpi/acpi_ipmi.c
index a6977e12d574..ac0f52f6df2b 100644
--- a/drivers/acpi/acpi_ipmi.c
+++ b/drivers/acpi/acpi_ipmi.c
@@ -1,8 +1,9 @@
1/* 1/*
2 * acpi_ipmi.c - ACPI IPMI opregion 2 * acpi_ipmi.c - ACPI IPMI opregion
3 * 3 *
4 * Copyright (C) 2010 Intel Corporation 4 * Copyright (C) 2010, 2013 Intel Corporation
5 * Copyright (C) 2010 Zhao Yakui <yakui.zhao@intel.com> 5 * Author: Zhao Yakui <yakui.zhao@intel.com>
6 * Lv Zheng <lv.zheng@intel.com>
6 * 7 *
7 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 8 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8 * 9 *
@@ -23,60 +24,58 @@
23 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 24 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
24 */ 25 */
25 26
26#include <linux/kernel.h>
27#include <linux/module.h> 27#include <linux/module.h>
28#include <linux/init.h> 28#include <linux/acpi.h>
29#include <linux/types.h>
30#include <linux/delay.h>
31#include <linux/proc_fs.h>
32#include <linux/seq_file.h>
33#include <linux/interrupt.h>
34#include <linux/list.h>
35#include <linux/spinlock.h>
36#include <linux/io.h>
37#include <acpi/acpi_bus.h>
38#include <acpi/acpi_drivers.h>
39#include <linux/ipmi.h> 29#include <linux/ipmi.h>
40#include <linux/device.h>
41#include <linux/pnp.h>
42#include <linux/spinlock.h> 30#include <linux/spinlock.h>
43 31
44MODULE_AUTHOR("Zhao Yakui"); 32MODULE_AUTHOR("Zhao Yakui");
45MODULE_DESCRIPTION("ACPI IPMI Opregion driver"); 33MODULE_DESCRIPTION("ACPI IPMI Opregion driver");
46MODULE_LICENSE("GPL"); 34MODULE_LICENSE("GPL");
47 35
48#define IPMI_FLAGS_HANDLER_INSTALL 0
49
50#define ACPI_IPMI_OK 0 36#define ACPI_IPMI_OK 0
51#define ACPI_IPMI_TIMEOUT 0x10 37#define ACPI_IPMI_TIMEOUT 0x10
52#define ACPI_IPMI_UNKNOWN 0x07 38#define ACPI_IPMI_UNKNOWN 0x07
53/* the IPMI timeout is 5s */ 39/* the IPMI timeout is 5s */
54#define IPMI_TIMEOUT (5 * HZ) 40#define IPMI_TIMEOUT (5000)
41#define ACPI_IPMI_MAX_MSG_LENGTH 64
55 42
56struct acpi_ipmi_device { 43struct acpi_ipmi_device {
57 /* the device list attached to driver_data.ipmi_devices */ 44 /* the device list attached to driver_data.ipmi_devices */
58 struct list_head head; 45 struct list_head head;
46
59 /* the IPMI request message list */ 47 /* the IPMI request message list */
60 struct list_head tx_msg_list; 48 struct list_head tx_msg_list;
61 spinlock_t tx_msg_lock; 49
50 spinlock_t tx_msg_lock;
62 acpi_handle handle; 51 acpi_handle handle;
63 struct pnp_dev *pnp_dev; 52 struct device *dev;
64 ipmi_user_t user_interface; 53 ipmi_user_t user_interface;
65 int ipmi_ifnum; /* IPMI interface number */ 54 int ipmi_ifnum; /* IPMI interface number */
66 long curr_msgid; 55 long curr_msgid;
67 unsigned long flags; 56 bool dead;
68 struct ipmi_smi_info smi_data; 57 struct kref kref;
69}; 58};
70 59
71struct ipmi_driver_data { 60struct ipmi_driver_data {
72 struct list_head ipmi_devices; 61 struct list_head ipmi_devices;
73 struct ipmi_smi_watcher bmc_events; 62 struct ipmi_smi_watcher bmc_events;
74 struct ipmi_user_hndl ipmi_hndlrs; 63 struct ipmi_user_hndl ipmi_hndlrs;
75 struct mutex ipmi_lock; 64 struct mutex ipmi_lock;
65
66 /*
67 * NOTE: IPMI System Interface Selection
68 * There is no system interface specified by the IPMI operation
69 * region access. We try to select one system interface with ACPI
70 * handle set. IPMI messages passed from the ACPI codes are sent
71 * to this selected global IPMI system interface.
72 */
73 struct acpi_ipmi_device *selected_smi;
76}; 74};
77 75
78struct acpi_ipmi_msg { 76struct acpi_ipmi_msg {
79 struct list_head head; 77 struct list_head head;
78
80 /* 79 /*
81 * General speaking the addr type should be SI_ADDR_TYPE. And 80 * General speaking the addr type should be SI_ADDR_TYPE. And
82 * the addr channel should be BMC. 81 * the addr channel should be BMC.
@@ -86,30 +85,31 @@ struct acpi_ipmi_msg {
86 */ 85 */
87 struct ipmi_addr addr; 86 struct ipmi_addr addr;
88 long tx_msgid; 87 long tx_msgid;
88
89 /* it is used to track whether the IPMI message is finished */ 89 /* it is used to track whether the IPMI message is finished */
90 struct completion tx_complete; 90 struct completion tx_complete;
91
91 struct kernel_ipmi_msg tx_message; 92 struct kernel_ipmi_msg tx_message;
92 int msg_done; 93 int msg_done;
93 /* tx data . And copy it from ACPI object buffer */ 94
94 u8 tx_data[64]; 95 /* tx/rx data . And copy it from/to ACPI object buffer */
95 int tx_len; 96 u8 data[ACPI_IPMI_MAX_MSG_LENGTH];
96 u8 rx_data[64]; 97 u8 rx_len;
97 int rx_len; 98
98 struct acpi_ipmi_device *device; 99 struct acpi_ipmi_device *device;
100 struct kref kref;
99}; 101};
100 102
101/* IPMI request/response buffer per ACPI 4.0, sec 5.5.2.4.3.2 */ 103/* IPMI request/response buffer per ACPI 4.0, sec 5.5.2.4.3.2 */
102struct acpi_ipmi_buffer { 104struct acpi_ipmi_buffer {
103 u8 status; 105 u8 status;
104 u8 length; 106 u8 length;
105 u8 data[64]; 107 u8 data[ACPI_IPMI_MAX_MSG_LENGTH];
106}; 108};
107 109
108static void ipmi_register_bmc(int iface, struct device *dev); 110static void ipmi_register_bmc(int iface, struct device *dev);
109static void ipmi_bmc_gone(int iface); 111static void ipmi_bmc_gone(int iface);
110static void ipmi_msg_handler(struct ipmi_recv_msg *msg, void *user_msg_data); 112static void ipmi_msg_handler(struct ipmi_recv_msg *msg, void *user_msg_data);
111static void acpi_add_ipmi_device(struct acpi_ipmi_device *ipmi_device);
112static void acpi_remove_ipmi_device(struct acpi_ipmi_device *ipmi_device);
113 113
114static struct ipmi_driver_data driver_data = { 114static struct ipmi_driver_data driver_data = {
115 .ipmi_devices = LIST_HEAD_INIT(driver_data.ipmi_devices), 115 .ipmi_devices = LIST_HEAD_INIT(driver_data.ipmi_devices),
@@ -121,29 +121,142 @@ static struct ipmi_driver_data driver_data = {
121 .ipmi_hndlrs = { 121 .ipmi_hndlrs = {
122 .ipmi_recv_hndl = ipmi_msg_handler, 122 .ipmi_recv_hndl = ipmi_msg_handler,
123 }, 123 },
124 .ipmi_lock = __MUTEX_INITIALIZER(driver_data.ipmi_lock)
124}; 125};
125 126
126static struct acpi_ipmi_msg *acpi_alloc_ipmi_msg(struct acpi_ipmi_device *ipmi) 127static struct acpi_ipmi_device *
128ipmi_dev_alloc(int iface, struct device *dev, acpi_handle handle)
129{
130 struct acpi_ipmi_device *ipmi_device;
131 int err;
132 ipmi_user_t user;
133
134 ipmi_device = kzalloc(sizeof(*ipmi_device), GFP_KERNEL);
135 if (!ipmi_device)
136 return NULL;
137
138 kref_init(&ipmi_device->kref);
139 INIT_LIST_HEAD(&ipmi_device->head);
140 INIT_LIST_HEAD(&ipmi_device->tx_msg_list);
141 spin_lock_init(&ipmi_device->tx_msg_lock);
142 ipmi_device->handle = handle;
143 ipmi_device->dev = get_device(dev);
144 ipmi_device->ipmi_ifnum = iface;
145
146 err = ipmi_create_user(iface, &driver_data.ipmi_hndlrs,
147 ipmi_device, &user);
148 if (err) {
149 put_device(dev);
150 kfree(ipmi_device);
151 return NULL;
152 }
153 ipmi_device->user_interface = user;
154
155 return ipmi_device;
156}
157
158static void ipmi_dev_release(struct acpi_ipmi_device *ipmi_device)
159{
160 ipmi_destroy_user(ipmi_device->user_interface);
161 put_device(ipmi_device->dev);
162 kfree(ipmi_device);
163}
164
165static void ipmi_dev_release_kref(struct kref *kref)
166{
167 struct acpi_ipmi_device *ipmi =
168 container_of(kref, struct acpi_ipmi_device, kref);
169
170 ipmi_dev_release(ipmi);
171}
172
173static void __ipmi_dev_kill(struct acpi_ipmi_device *ipmi_device)
174{
175 list_del(&ipmi_device->head);
176 if (driver_data.selected_smi == ipmi_device)
177 driver_data.selected_smi = NULL;
178
179 /*
180 * Always setting dead flag after deleting from the list or
181 * list_for_each_entry() codes must get changed.
182 */
183 ipmi_device->dead = true;
184}
185
186static struct acpi_ipmi_device *acpi_ipmi_dev_get(void)
187{
188 struct acpi_ipmi_device *ipmi_device = NULL;
189
190 mutex_lock(&driver_data.ipmi_lock);
191 if (driver_data.selected_smi) {
192 ipmi_device = driver_data.selected_smi;
193 kref_get(&ipmi_device->kref);
194 }
195 mutex_unlock(&driver_data.ipmi_lock);
196
197 return ipmi_device;
198}
199
200static void acpi_ipmi_dev_put(struct acpi_ipmi_device *ipmi_device)
201{
202 kref_put(&ipmi_device->kref, ipmi_dev_release_kref);
203}
204
205static struct acpi_ipmi_msg *ipmi_msg_alloc(void)
127{ 206{
207 struct acpi_ipmi_device *ipmi;
128 struct acpi_ipmi_msg *ipmi_msg; 208 struct acpi_ipmi_msg *ipmi_msg;
129 struct pnp_dev *pnp_dev = ipmi->pnp_dev; 209
210 ipmi = acpi_ipmi_dev_get();
211 if (!ipmi)
212 return NULL;
130 213
131 ipmi_msg = kzalloc(sizeof(struct acpi_ipmi_msg), GFP_KERNEL); 214 ipmi_msg = kzalloc(sizeof(struct acpi_ipmi_msg), GFP_KERNEL);
132 if (!ipmi_msg) { 215 if (!ipmi_msg) {
133 dev_warn(&pnp_dev->dev, "Can't allocate memory for ipmi_msg\n"); 216 acpi_ipmi_dev_put(ipmi);
134 return NULL; 217 return NULL;
135 } 218 }
219
220 kref_init(&ipmi_msg->kref);
136 init_completion(&ipmi_msg->tx_complete); 221 init_completion(&ipmi_msg->tx_complete);
137 INIT_LIST_HEAD(&ipmi_msg->head); 222 INIT_LIST_HEAD(&ipmi_msg->head);
138 ipmi_msg->device = ipmi; 223 ipmi_msg->device = ipmi;
224 ipmi_msg->msg_done = ACPI_IPMI_UNKNOWN;
225
139 return ipmi_msg; 226 return ipmi_msg;
140} 227}
141 228
142#define IPMI_OP_RGN_NETFN(offset) ((offset >> 8) & 0xff) 229static void ipmi_msg_release(struct acpi_ipmi_msg *tx_msg)
143#define IPMI_OP_RGN_CMD(offset) (offset & 0xff) 230{
144static void acpi_format_ipmi_msg(struct acpi_ipmi_msg *tx_msg, 231 acpi_ipmi_dev_put(tx_msg->device);
145 acpi_physical_address address, 232 kfree(tx_msg);
146 acpi_integer *value) 233}
234
235static void ipmi_msg_release_kref(struct kref *kref)
236{
237 struct acpi_ipmi_msg *tx_msg =
238 container_of(kref, struct acpi_ipmi_msg, kref);
239
240 ipmi_msg_release(tx_msg);
241}
242
243static struct acpi_ipmi_msg *acpi_ipmi_msg_get(struct acpi_ipmi_msg *tx_msg)
244{
245 kref_get(&tx_msg->kref);
246
247 return tx_msg;
248}
249
250static void acpi_ipmi_msg_put(struct acpi_ipmi_msg *tx_msg)
251{
252 kref_put(&tx_msg->kref, ipmi_msg_release_kref);
253}
254
255#define IPMI_OP_RGN_NETFN(offset) ((offset >> 8) & 0xff)
256#define IPMI_OP_RGN_CMD(offset) (offset & 0xff)
257static int acpi_format_ipmi_request(struct acpi_ipmi_msg *tx_msg,
258 acpi_physical_address address,
259 acpi_integer *value)
147{ 260{
148 struct kernel_ipmi_msg *msg; 261 struct kernel_ipmi_msg *msg;
149 struct acpi_ipmi_buffer *buffer; 262 struct acpi_ipmi_buffer *buffer;
@@ -151,21 +264,31 @@ static void acpi_format_ipmi_msg(struct acpi_ipmi_msg *tx_msg,
151 unsigned long flags; 264 unsigned long flags;
152 265
153 msg = &tx_msg->tx_message; 266 msg = &tx_msg->tx_message;
267
154 /* 268 /*
155 * IPMI network function and command are encoded in the address 269 * IPMI network function and command are encoded in the address
156 * within the IPMI OpRegion; see ACPI 4.0, sec 5.5.2.4.3. 270 * within the IPMI OpRegion; see ACPI 4.0, sec 5.5.2.4.3.
157 */ 271 */
158 msg->netfn = IPMI_OP_RGN_NETFN(address); 272 msg->netfn = IPMI_OP_RGN_NETFN(address);
159 msg->cmd = IPMI_OP_RGN_CMD(address); 273 msg->cmd = IPMI_OP_RGN_CMD(address);
160 msg->data = tx_msg->tx_data; 274 msg->data = tx_msg->data;
275
161 /* 276 /*
162 * value is the parameter passed by the IPMI opregion space handler. 277 * value is the parameter passed by the IPMI opregion space handler.
163 * It points to the IPMI request message buffer 278 * It points to the IPMI request message buffer
164 */ 279 */
165 buffer = (struct acpi_ipmi_buffer *)value; 280 buffer = (struct acpi_ipmi_buffer *)value;
281
166 /* copy the tx message data */ 282 /* copy the tx message data */
283 if (buffer->length > ACPI_IPMI_MAX_MSG_LENGTH) {
284 dev_WARN_ONCE(tx_msg->device->dev, true,
285 "Unexpected request (msg len %d).\n",
286 buffer->length);
287 return -EINVAL;
288 }
167 msg->data_len = buffer->length; 289 msg->data_len = buffer->length;
168 memcpy(tx_msg->tx_data, buffer->data, msg->data_len); 290 memcpy(tx_msg->data, buffer->data, msg->data_len);
291
169 /* 292 /*
170 * now the default type is SYSTEM_INTERFACE and channel type is BMC. 293 * now the default type is SYSTEM_INTERFACE and channel type is BMC.
171 * If the netfn is APP_REQUEST and the cmd is SEND_MESSAGE, 294 * If the netfn is APP_REQUEST and the cmd is SEND_MESSAGE,
@@ -179,14 +302,17 @@ static void acpi_format_ipmi_msg(struct acpi_ipmi_msg *tx_msg,
179 302
180 /* Get the msgid */ 303 /* Get the msgid */
181 device = tx_msg->device; 304 device = tx_msg->device;
305
182 spin_lock_irqsave(&device->tx_msg_lock, flags); 306 spin_lock_irqsave(&device->tx_msg_lock, flags);
183 device->curr_msgid++; 307 device->curr_msgid++;
184 tx_msg->tx_msgid = device->curr_msgid; 308 tx_msg->tx_msgid = device->curr_msgid;
185 spin_unlock_irqrestore(&device->tx_msg_lock, flags); 309 spin_unlock_irqrestore(&device->tx_msg_lock, flags);
310
311 return 0;
186} 312}
187 313
188static void acpi_format_ipmi_response(struct acpi_ipmi_msg *msg, 314static void acpi_format_ipmi_response(struct acpi_ipmi_msg *msg,
189 acpi_integer *value, int rem_time) 315 acpi_integer *value)
190{ 316{
191 struct acpi_ipmi_buffer *buffer; 317 struct acpi_ipmi_buffer *buffer;
192 318
@@ -195,110 +321,158 @@ static void acpi_format_ipmi_response(struct acpi_ipmi_msg *msg,
195 * IPMI message returned by IPMI command. 321 * IPMI message returned by IPMI command.
196 */ 322 */
197 buffer = (struct acpi_ipmi_buffer *)value; 323 buffer = (struct acpi_ipmi_buffer *)value;
198 if (!rem_time && !msg->msg_done) { 324
199 buffer->status = ACPI_IPMI_TIMEOUT;
200 return;
201 }
202 /* 325 /*
203 * If the flag of msg_done is not set or the recv length is zero, it 326 * If the flag of msg_done is not set, it means that the IPMI command is
204 * means that the IPMI command is not executed correctly. 327 * not executed correctly.
205 * The status code will be ACPI_IPMI_UNKNOWN.
206 */ 328 */
207 if (!msg->msg_done || !msg->rx_len) { 329 buffer->status = msg->msg_done;
208 buffer->status = ACPI_IPMI_UNKNOWN; 330 if (msg->msg_done != ACPI_IPMI_OK)
209 return; 331 return;
210 } 332
211 /* 333 /*
212 * If the IPMI response message is obtained correctly, the status code 334 * If the IPMI response message is obtained correctly, the status code
213 * will be ACPI_IPMI_OK 335 * will be ACPI_IPMI_OK
214 */ 336 */
215 buffer->status = ACPI_IPMI_OK;
216 buffer->length = msg->rx_len; 337 buffer->length = msg->rx_len;
217 memcpy(buffer->data, msg->rx_data, msg->rx_len); 338 memcpy(buffer->data, msg->data, msg->rx_len);
218} 339}
219 340
220static void ipmi_flush_tx_msg(struct acpi_ipmi_device *ipmi) 341static void ipmi_flush_tx_msg(struct acpi_ipmi_device *ipmi)
221{ 342{
222 struct acpi_ipmi_msg *tx_msg, *temp; 343 struct acpi_ipmi_msg *tx_msg;
223 int count = HZ / 10; 344 unsigned long flags;
224 struct pnp_dev *pnp_dev = ipmi->pnp_dev; 345
346 /*
347 * NOTE: On-going ipmi_recv_msg
348 * ipmi_msg_handler() may still be invoked by ipmi_si after
349 * flushing. But it is safe to do a fast flushing on module_exit()
350 * without waiting for all ipmi_recv_msg(s) to complete from
351 * ipmi_msg_handler() as it is ensured by ipmi_si that all
352 * ipmi_recv_msg(s) are freed after invoking ipmi_destroy_user().
353 */
354 spin_lock_irqsave(&ipmi->tx_msg_lock, flags);
355 while (!list_empty(&ipmi->tx_msg_list)) {
356 tx_msg = list_first_entry(&ipmi->tx_msg_list,
357 struct acpi_ipmi_msg,
358 head);
359 list_del(&tx_msg->head);
360 spin_unlock_irqrestore(&ipmi->tx_msg_lock, flags);
225 361
226 list_for_each_entry_safe(tx_msg, temp, &ipmi->tx_msg_list, head) {
227 /* wake up the sleep thread on the Tx msg */ 362 /* wake up the sleep thread on the Tx msg */
228 complete(&tx_msg->tx_complete); 363 complete(&tx_msg->tx_complete);
364 acpi_ipmi_msg_put(tx_msg);
365 spin_lock_irqsave(&ipmi->tx_msg_lock, flags);
229 } 366 }
367 spin_unlock_irqrestore(&ipmi->tx_msg_lock, flags);
368}
369
370static void ipmi_cancel_tx_msg(struct acpi_ipmi_device *ipmi,
371 struct acpi_ipmi_msg *msg)
372{
373 struct acpi_ipmi_msg *tx_msg, *temp;
374 bool msg_found = false;
375 unsigned long flags;
230 376
231 /* wait for about 100ms to flush the tx message list */ 377 spin_lock_irqsave(&ipmi->tx_msg_lock, flags);
232 while (count--) { 378 list_for_each_entry_safe(tx_msg, temp, &ipmi->tx_msg_list, head) {
233 if (list_empty(&ipmi->tx_msg_list)) 379 if (msg == tx_msg) {
380 msg_found = true;
381 list_del(&tx_msg->head);
234 break; 382 break;
235 schedule_timeout(1); 383 }
236 } 384 }
237 if (!list_empty(&ipmi->tx_msg_list)) 385 spin_unlock_irqrestore(&ipmi->tx_msg_lock, flags);
238 dev_warn(&pnp_dev->dev, "tx msg list is not NULL\n"); 386
387 if (msg_found)
388 acpi_ipmi_msg_put(tx_msg);
239} 389}
240 390
241static void ipmi_msg_handler(struct ipmi_recv_msg *msg, void *user_msg_data) 391static void ipmi_msg_handler(struct ipmi_recv_msg *msg, void *user_msg_data)
242{ 392{
243 struct acpi_ipmi_device *ipmi_device = user_msg_data; 393 struct acpi_ipmi_device *ipmi_device = user_msg_data;
244 int msg_found = 0; 394 bool msg_found = false;
245 struct acpi_ipmi_msg *tx_msg; 395 struct acpi_ipmi_msg *tx_msg, *temp;
246 struct pnp_dev *pnp_dev = ipmi_device->pnp_dev; 396 struct device *dev = ipmi_device->dev;
247 unsigned long flags; 397 unsigned long flags;
248 398
249 if (msg->user != ipmi_device->user_interface) { 399 if (msg->user != ipmi_device->user_interface) {
250 dev_warn(&pnp_dev->dev, "Unexpected response is returned. " 400 dev_warn(dev,
251 "returned user %p, expected user %p\n", 401 "Unexpected response is returned. returned user %p, expected user %p\n",
252 msg->user, ipmi_device->user_interface); 402 msg->user, ipmi_device->user_interface);
253 ipmi_free_recv_msg(msg); 403 goto out_msg;
254 return;
255 } 404 }
405
256 spin_lock_irqsave(&ipmi_device->tx_msg_lock, flags); 406 spin_lock_irqsave(&ipmi_device->tx_msg_lock, flags);
257 list_for_each_entry(tx_msg, &ipmi_device->tx_msg_list, head) { 407 list_for_each_entry_safe(tx_msg, temp, &ipmi_device->tx_msg_list, head) {
258 if (msg->msgid == tx_msg->tx_msgid) { 408 if (msg->msgid == tx_msg->tx_msgid) {
259 msg_found = 1; 409 msg_found = true;
410 list_del(&tx_msg->head);
260 break; 411 break;
261 } 412 }
262 } 413 }
263
264 spin_unlock_irqrestore(&ipmi_device->tx_msg_lock, flags); 414 spin_unlock_irqrestore(&ipmi_device->tx_msg_lock, flags);
415
265 if (!msg_found) { 416 if (!msg_found) {
266 dev_warn(&pnp_dev->dev, "Unexpected response (msg id %ld) is " 417 dev_warn(dev,
267 "returned.\n", msg->msgid); 418 "Unexpected response (msg id %ld) is returned.\n",
268 ipmi_free_recv_msg(msg); 419 msg->msgid);
269 return; 420 goto out_msg;
270 } 421 }
271 422
272 if (msg->msg.data_len) { 423 /* copy the response data to Rx_data buffer */
273 /* copy the response data to Rx_data buffer */ 424 if (msg->msg.data_len > ACPI_IPMI_MAX_MSG_LENGTH) {
274 memcpy(tx_msg->rx_data, msg->msg_data, msg->msg.data_len); 425 dev_WARN_ONCE(dev, true,
275 tx_msg->rx_len = msg->msg.data_len; 426 "Unexpected response (msg len %d).\n",
276 tx_msg->msg_done = 1; 427 msg->msg.data_len);
428 goto out_comp;
277 } 429 }
430
431 /* response msg is an error msg */
432 msg->recv_type = IPMI_RESPONSE_RECV_TYPE;
433 if (msg->recv_type == IPMI_RESPONSE_RECV_TYPE &&
434 msg->msg.data_len == 1) {
435 if (msg->msg.data[0] == IPMI_TIMEOUT_COMPLETION_CODE) {
436 dev_WARN_ONCE(dev, true,
437 "Unexpected response (timeout).\n");
438 tx_msg->msg_done = ACPI_IPMI_TIMEOUT;
439 }
440 goto out_comp;
441 }
442
443 tx_msg->rx_len = msg->msg.data_len;
444 memcpy(tx_msg->data, msg->msg.data, tx_msg->rx_len);
445 tx_msg->msg_done = ACPI_IPMI_OK;
446
447out_comp:
278 complete(&tx_msg->tx_complete); 448 complete(&tx_msg->tx_complete);
449 acpi_ipmi_msg_put(tx_msg);
450out_msg:
279 ipmi_free_recv_msg(msg); 451 ipmi_free_recv_msg(msg);
280}; 452}
281 453
282static void ipmi_register_bmc(int iface, struct device *dev) 454static void ipmi_register_bmc(int iface, struct device *dev)
283{ 455{
284 struct acpi_ipmi_device *ipmi_device, *temp; 456 struct acpi_ipmi_device *ipmi_device, *temp;
285 struct pnp_dev *pnp_dev;
286 ipmi_user_t user;
287 int err; 457 int err;
288 struct ipmi_smi_info smi_data; 458 struct ipmi_smi_info smi_data;
289 acpi_handle handle; 459 acpi_handle handle;
290 460
291 err = ipmi_get_smi_info(iface, &smi_data); 461 err = ipmi_get_smi_info(iface, &smi_data);
292
293 if (err) 462 if (err)
294 return; 463 return;
295 464
296 if (smi_data.addr_src != SI_ACPI) { 465 if (smi_data.addr_src != SI_ACPI)
297 put_device(smi_data.dev); 466 goto err_ref;
298 return;
299 }
300
301 handle = smi_data.addr_info.acpi_info.acpi_handle; 467 handle = smi_data.addr_info.acpi_info.acpi_handle;
468 if (!handle)
469 goto err_ref;
470
471 ipmi_device = ipmi_dev_alloc(iface, smi_data.dev, handle);
472 if (!ipmi_device) {
473 dev_warn(smi_data.dev, "Can't create IPMI user interface\n");
474 goto err_ref;
475 }
302 476
303 mutex_lock(&driver_data.ipmi_lock); 477 mutex_lock(&driver_data.ipmi_lock);
304 list_for_each_entry(temp, &driver_data.ipmi_devices, head) { 478 list_for_each_entry(temp, &driver_data.ipmi_devices, head) {
@@ -307,34 +481,20 @@ static void ipmi_register_bmc(int iface, struct device *dev)
307 * to the device list, don't add it again. 481 * to the device list, don't add it again.
308 */ 482 */
309 if (temp->handle == handle) 483 if (temp->handle == handle)
310 goto out; 484 goto err_lock;
311 } 485 }
312 486 if (!driver_data.selected_smi)
313 ipmi_device = kzalloc(sizeof(*ipmi_device), GFP_KERNEL); 487 driver_data.selected_smi = ipmi_device;
314 488 list_add_tail(&ipmi_device->head, &driver_data.ipmi_devices);
315 if (!ipmi_device)
316 goto out;
317
318 pnp_dev = to_pnp_dev(smi_data.dev);
319 ipmi_device->handle = handle;
320 ipmi_device->pnp_dev = pnp_dev;
321
322 err = ipmi_create_user(iface, &driver_data.ipmi_hndlrs,
323 ipmi_device, &user);
324 if (err) {
325 dev_warn(&pnp_dev->dev, "Can't create IPMI user interface\n");
326 kfree(ipmi_device);
327 goto out;
328 }
329 acpi_add_ipmi_device(ipmi_device);
330 ipmi_device->user_interface = user;
331 ipmi_device->ipmi_ifnum = iface;
332 mutex_unlock(&driver_data.ipmi_lock); 489 mutex_unlock(&driver_data.ipmi_lock);
333 memcpy(&ipmi_device->smi_data, &smi_data, sizeof(struct ipmi_smi_info)); 490
491 put_device(smi_data.dev);
334 return; 492 return;
335 493
336out: 494err_lock:
337 mutex_unlock(&driver_data.ipmi_lock); 495 mutex_unlock(&driver_data.ipmi_lock);
496 ipmi_dev_release(ipmi_device);
497err_ref:
338 put_device(smi_data.dev); 498 put_device(smi_data.dev);
339 return; 499 return;
340} 500}
@@ -342,23 +502,29 @@ out:
342static void ipmi_bmc_gone(int iface) 502static void ipmi_bmc_gone(int iface)
343{ 503{
344 struct acpi_ipmi_device *ipmi_device, *temp; 504 struct acpi_ipmi_device *ipmi_device, *temp;
505 bool dev_found = false;
345 506
346 mutex_lock(&driver_data.ipmi_lock); 507 mutex_lock(&driver_data.ipmi_lock);
347 list_for_each_entry_safe(ipmi_device, temp, 508 list_for_each_entry_safe(ipmi_device, temp,
348 &driver_data.ipmi_devices, head) { 509 &driver_data.ipmi_devices, head) {
349 if (ipmi_device->ipmi_ifnum != iface) 510 if (ipmi_device->ipmi_ifnum != iface) {
350 continue; 511 dev_found = true;
351 512 __ipmi_dev_kill(ipmi_device);
352 acpi_remove_ipmi_device(ipmi_device); 513 break;
353 put_device(ipmi_device->smi_data.dev); 514 }
354 kfree(ipmi_device);
355 break;
356 } 515 }
516 if (!driver_data.selected_smi)
517 driver_data.selected_smi = list_first_entry_or_null(
518 &driver_data.ipmi_devices,
519 struct acpi_ipmi_device, head);
357 mutex_unlock(&driver_data.ipmi_lock); 520 mutex_unlock(&driver_data.ipmi_lock);
521
522 if (dev_found) {
523 ipmi_flush_tx_msg(ipmi_device);
524 acpi_ipmi_dev_put(ipmi_device);
525 }
358} 526}
359/* -------------------------------------------------------------------------- 527
360 * Address Space Management
361 * -------------------------------------------------------------------------- */
362/* 528/*
363 * This is the IPMI opregion space handler. 529 * This is the IPMI opregion space handler.
364 * @function: indicates the read/write. In fact as the IPMI message is driven 530 * @function: indicates the read/write. In fact as the IPMI message is driven
@@ -371,17 +537,17 @@ static void ipmi_bmc_gone(int iface)
371 * the response IPMI message returned by IPMI command. 537 * the response IPMI message returned by IPMI command.
372 * @handler_context: IPMI device context. 538 * @handler_context: IPMI device context.
373 */ 539 */
374
375static acpi_status 540static acpi_status
376acpi_ipmi_space_handler(u32 function, acpi_physical_address address, 541acpi_ipmi_space_handler(u32 function, acpi_physical_address address,
377 u32 bits, acpi_integer *value, 542 u32 bits, acpi_integer *value,
378 void *handler_context, void *region_context) 543 void *handler_context, void *region_context)
379{ 544{
380 struct acpi_ipmi_msg *tx_msg; 545 struct acpi_ipmi_msg *tx_msg;
381 struct acpi_ipmi_device *ipmi_device = handler_context; 546 struct acpi_ipmi_device *ipmi_device;
382 int err, rem_time; 547 int err;
383 acpi_status status; 548 acpi_status status;
384 unsigned long flags; 549 unsigned long flags;
550
385 /* 551 /*
386 * IPMI opregion message. 552 * IPMI opregion message.
387 * IPMI message is firstly written to the BMC and system software 553 * IPMI message is firstly written to the BMC and system software
@@ -391,118 +557,75 @@ acpi_ipmi_space_handler(u32 function, acpi_physical_address address,
391 if ((function & ACPI_IO_MASK) == ACPI_READ) 557 if ((function & ACPI_IO_MASK) == ACPI_READ)
392 return AE_TYPE; 558 return AE_TYPE;
393 559
394 if (!ipmi_device->user_interface) 560 tx_msg = ipmi_msg_alloc();
561 if (!tx_msg)
395 return AE_NOT_EXIST; 562 return AE_NOT_EXIST;
563 ipmi_device = tx_msg->device;
396 564
397 tx_msg = acpi_alloc_ipmi_msg(ipmi_device); 565 if (acpi_format_ipmi_request(tx_msg, address, value) != 0) {
398 if (!tx_msg) 566 ipmi_msg_release(tx_msg);
399 return AE_NO_MEMORY; 567 return AE_TYPE;
568 }
400 569
401 acpi_format_ipmi_msg(tx_msg, address, value); 570 acpi_ipmi_msg_get(tx_msg);
571 mutex_lock(&driver_data.ipmi_lock);
572 /* Do not add a tx_msg that can not be flushed. */
573 if (ipmi_device->dead) {
574 mutex_unlock(&driver_data.ipmi_lock);
575 ipmi_msg_release(tx_msg);
576 return AE_NOT_EXIST;
577 }
402 spin_lock_irqsave(&ipmi_device->tx_msg_lock, flags); 578 spin_lock_irqsave(&ipmi_device->tx_msg_lock, flags);
403 list_add_tail(&tx_msg->head, &ipmi_device->tx_msg_list); 579 list_add_tail(&tx_msg->head, &ipmi_device->tx_msg_list);
404 spin_unlock_irqrestore(&ipmi_device->tx_msg_lock, flags); 580 spin_unlock_irqrestore(&ipmi_device->tx_msg_lock, flags);
581 mutex_unlock(&driver_data.ipmi_lock);
582
405 err = ipmi_request_settime(ipmi_device->user_interface, 583 err = ipmi_request_settime(ipmi_device->user_interface,
406 &tx_msg->addr, 584 &tx_msg->addr,
407 tx_msg->tx_msgid, 585 tx_msg->tx_msgid,
408 &tx_msg->tx_message, 586 &tx_msg->tx_message,
409 NULL, 0, 0, 0); 587 NULL, 0, 0, IPMI_TIMEOUT);
410 if (err) { 588 if (err) {
411 status = AE_ERROR; 589 status = AE_ERROR;
412 goto end_label; 590 goto out_msg;
413 } 591 }
414 rem_time = wait_for_completion_timeout(&tx_msg->tx_complete, 592 wait_for_completion(&tx_msg->tx_complete);
415 IPMI_TIMEOUT); 593
416 acpi_format_ipmi_response(tx_msg, value, rem_time); 594 acpi_format_ipmi_response(tx_msg, value);
417 status = AE_OK; 595 status = AE_OK;
418 596
419end_label: 597out_msg:
420 spin_lock_irqsave(&ipmi_device->tx_msg_lock, flags); 598 ipmi_cancel_tx_msg(ipmi_device, tx_msg);
421 list_del(&tx_msg->head); 599 acpi_ipmi_msg_put(tx_msg);
422 spin_unlock_irqrestore(&ipmi_device->tx_msg_lock, flags);
423 kfree(tx_msg);
424 return status; 600 return status;
425} 601}
426 602
427static void ipmi_remove_space_handler(struct acpi_ipmi_device *ipmi) 603static int __init acpi_ipmi_init(void)
428{
429 if (!test_bit(IPMI_FLAGS_HANDLER_INSTALL, &ipmi->flags))
430 return;
431
432 acpi_remove_address_space_handler(ipmi->handle,
433 ACPI_ADR_SPACE_IPMI, &acpi_ipmi_space_handler);
434
435 clear_bit(IPMI_FLAGS_HANDLER_INSTALL, &ipmi->flags);
436}
437
438static int ipmi_install_space_handler(struct acpi_ipmi_device *ipmi)
439{ 604{
605 int result;
440 acpi_status status; 606 acpi_status status;
441 607
442 if (test_bit(IPMI_FLAGS_HANDLER_INSTALL, &ipmi->flags)) 608 if (acpi_disabled)
443 return 0; 609 return 0;
444 610
445 status = acpi_install_address_space_handler(ipmi->handle, 611 status = acpi_install_address_space_handler(ACPI_ROOT_OBJECT,
446 ACPI_ADR_SPACE_IPMI, 612 ACPI_ADR_SPACE_IPMI,
447 &acpi_ipmi_space_handler, 613 &acpi_ipmi_space_handler,
448 NULL, ipmi); 614 NULL, NULL);
449 if (ACPI_FAILURE(status)) { 615 if (ACPI_FAILURE(status)) {
450 struct pnp_dev *pnp_dev = ipmi->pnp_dev; 616 pr_warn("Can't register IPMI opregion space handle\n");
451 dev_warn(&pnp_dev->dev, "Can't register IPMI opregion space "
452 "handle\n");
453 return -EINVAL; 617 return -EINVAL;
454 } 618 }
455 set_bit(IPMI_FLAGS_HANDLER_INSTALL, &ipmi->flags);
456 return 0;
457}
458
459static void acpi_add_ipmi_device(struct acpi_ipmi_device *ipmi_device)
460{
461
462 INIT_LIST_HEAD(&ipmi_device->head);
463
464 spin_lock_init(&ipmi_device->tx_msg_lock);
465 INIT_LIST_HEAD(&ipmi_device->tx_msg_list);
466 ipmi_install_space_handler(ipmi_device);
467
468 list_add_tail(&ipmi_device->head, &driver_data.ipmi_devices);
469}
470
471static void acpi_remove_ipmi_device(struct acpi_ipmi_device *ipmi_device)
472{
473 /*
474 * If the IPMI user interface is created, it should be
475 * destroyed.
476 */
477 if (ipmi_device->user_interface) {
478 ipmi_destroy_user(ipmi_device->user_interface);
479 ipmi_device->user_interface = NULL;
480 }
481 /* flush the Tx_msg list */
482 if (!list_empty(&ipmi_device->tx_msg_list))
483 ipmi_flush_tx_msg(ipmi_device);
484
485 list_del(&ipmi_device->head);
486 ipmi_remove_space_handler(ipmi_device);
487}
488
489static int __init acpi_ipmi_init(void)
490{
491 int result = 0;
492
493 if (acpi_disabled)
494 return result;
495
496 mutex_init(&driver_data.ipmi_lock);
497
498 result = ipmi_smi_watcher_register(&driver_data.bmc_events); 619 result = ipmi_smi_watcher_register(&driver_data.bmc_events);
620 if (result)
621 pr_err("Can't register IPMI system interface watcher\n");
499 622
500 return result; 623 return result;
501} 624}
502 625
503static void __exit acpi_ipmi_exit(void) 626static void __exit acpi_ipmi_exit(void)
504{ 627{
505 struct acpi_ipmi_device *ipmi_device, *temp; 628 struct acpi_ipmi_device *ipmi_device;
506 629
507 if (acpi_disabled) 630 if (acpi_disabled)
508 return; 631 return;
@@ -516,13 +639,22 @@ static void __exit acpi_ipmi_exit(void)
516 * handler and free it. 639 * handler and free it.
517 */ 640 */
518 mutex_lock(&driver_data.ipmi_lock); 641 mutex_lock(&driver_data.ipmi_lock);
519 list_for_each_entry_safe(ipmi_device, temp, 642 while (!list_empty(&driver_data.ipmi_devices)) {
520 &driver_data.ipmi_devices, head) { 643 ipmi_device = list_first_entry(&driver_data.ipmi_devices,
521 acpi_remove_ipmi_device(ipmi_device); 644 struct acpi_ipmi_device,
522 put_device(ipmi_device->smi_data.dev); 645 head);
523 kfree(ipmi_device); 646 __ipmi_dev_kill(ipmi_device);
647 mutex_unlock(&driver_data.ipmi_lock);
648
649 ipmi_flush_tx_msg(ipmi_device);
650 acpi_ipmi_dev_put(ipmi_device);
651
652 mutex_lock(&driver_data.ipmi_lock);
524 } 653 }
525 mutex_unlock(&driver_data.ipmi_lock); 654 mutex_unlock(&driver_data.ipmi_lock);
655 acpi_remove_address_space_handler(ACPI_ROOT_OBJECT,
656 ACPI_ADR_SPACE_IPMI,
657 &acpi_ipmi_space_handler);
526} 658}
527 659
528module_init(acpi_ipmi_init); 660module_init(acpi_ipmi_init);
diff --git a/drivers/acpi/acpi_lpss.c b/drivers/acpi/acpi_lpss.c
index fb78bb9ad8f6..d3961014aad7 100644
--- a/drivers/acpi/acpi_lpss.c
+++ b/drivers/acpi/acpi_lpss.c
@@ -30,6 +30,7 @@ ACPI_MODULE_NAME("acpi_lpss");
30/* Offsets relative to LPSS_PRIVATE_OFFSET */ 30/* Offsets relative to LPSS_PRIVATE_OFFSET */
31#define LPSS_GENERAL 0x08 31#define LPSS_GENERAL 0x08
32#define LPSS_GENERAL_LTR_MODE_SW BIT(2) 32#define LPSS_GENERAL_LTR_MODE_SW BIT(2)
33#define LPSS_GENERAL_UART_RTS_OVRD BIT(3)
33#define LPSS_SW_LTR 0x10 34#define LPSS_SW_LTR 0x10
34#define LPSS_AUTO_LTR 0x14 35#define LPSS_AUTO_LTR 0x14
35#define LPSS_TX_INT 0x20 36#define LPSS_TX_INT 0x20
@@ -68,11 +69,16 @@ struct lpss_private_data {
68 69
69static void lpss_uart_setup(struct lpss_private_data *pdata) 70static void lpss_uart_setup(struct lpss_private_data *pdata)
70{ 71{
71 unsigned int tx_int_offset = pdata->dev_desc->prv_offset + LPSS_TX_INT; 72 unsigned int offset;
72 u32 reg; 73 u32 reg;
73 74
74 reg = readl(pdata->mmio_base + tx_int_offset); 75 offset = pdata->dev_desc->prv_offset + LPSS_TX_INT;
75 writel(reg | LPSS_TX_INT_MASK, pdata->mmio_base + tx_int_offset); 76 reg = readl(pdata->mmio_base + offset);
77 writel(reg | LPSS_TX_INT_MASK, pdata->mmio_base + offset);
78
79 offset = pdata->dev_desc->prv_offset + LPSS_GENERAL;
80 reg = readl(pdata->mmio_base + offset);
81 writel(reg | LPSS_GENERAL_UART_RTS_OVRD, pdata->mmio_base + offset);
76} 82}
77 83
78static struct lpss_device_desc lpt_dev_desc = { 84static struct lpss_device_desc lpt_dev_desc = {
diff --git a/drivers/acpi/acpi_memhotplug.c b/drivers/acpi/acpi_memhotplug.c
index 999adb5499c7..551dad712ffe 100644
--- a/drivers/acpi/acpi_memhotplug.c
+++ b/drivers/acpi/acpi_memhotplug.c
@@ -152,8 +152,9 @@ static int acpi_memory_check_device(struct acpi_memory_device *mem_device)
152 unsigned long long current_status; 152 unsigned long long current_status;
153 153
154 /* Get device present/absent information from the _STA */ 154 /* Get device present/absent information from the _STA */
155 if (ACPI_FAILURE(acpi_evaluate_integer(mem_device->device->handle, "_STA", 155 if (ACPI_FAILURE(acpi_evaluate_integer(mem_device->device->handle,
156 NULL, &current_status))) 156 METHOD_NAME__STA, NULL,
157 &current_status)))
157 return -ENODEV; 158 return -ENODEV;
158 /* 159 /*
159 * Check for device status. Device should be 160 * Check for device status. Device should be
@@ -281,7 +282,7 @@ static void acpi_memory_remove_memory(struct acpi_memory_device *mem_device)
281 if (!info->enabled) 282 if (!info->enabled)
282 continue; 283 continue;
283 284
284 if (nid < 0) 285 if (nid == NUMA_NO_NODE)
285 nid = memory_add_physaddr_to_nid(info->start_addr); 286 nid = memory_add_physaddr_to_nid(info->start_addr);
286 287
287 acpi_unbind_memory_blocks(info, handle); 288 acpi_unbind_memory_blocks(info, handle);
diff --git a/drivers/acpi/acpi_platform.c b/drivers/acpi/acpi_platform.c
index 1bde12708f9e..8a4cfc7e71f0 100644
--- a/drivers/acpi/acpi_platform.c
+++ b/drivers/acpi/acpi_platform.c
@@ -29,6 +29,13 @@ ACPI_MODULE_NAME("platform");
29static const struct acpi_device_id acpi_platform_device_ids[] = { 29static const struct acpi_device_id acpi_platform_device_ids[] = {
30 30
31 { "PNP0D40" }, 31 { "PNP0D40" },
32 { "ACPI0003" },
33 { "VPC2004" },
34 { "BCM4752" },
35
36 /* Intel Smart Sound Technology */
37 { "INT33C8" },
38 { "80860F28" },
32 39
33 { } 40 { }
34}; 41};
diff --git a/drivers/acpi/acpi_processor.c b/drivers/acpi/acpi_processor.c
index f29e06efa479..3c1d6b0c09a4 100644
--- a/drivers/acpi/acpi_processor.c
+++ b/drivers/acpi/acpi_processor.c
@@ -140,15 +140,11 @@ static int acpi_processor_errata_piix4(struct pci_dev *dev)
140 return 0; 140 return 0;
141} 141}
142 142
143static int acpi_processor_errata(struct acpi_processor *pr) 143static int acpi_processor_errata(void)
144{ 144{
145 int result = 0; 145 int result = 0;
146 struct pci_dev *dev = NULL; 146 struct pci_dev *dev = NULL;
147 147
148
149 if (!pr)
150 return -EINVAL;
151
152 /* 148 /*
153 * PIIX4 149 * PIIX4
154 */ 150 */
@@ -181,7 +177,7 @@ static int acpi_processor_hotadd_init(struct acpi_processor *pr)
181 cpu_maps_update_begin(); 177 cpu_maps_update_begin();
182 cpu_hotplug_begin(); 178 cpu_hotplug_begin();
183 179
184 ret = acpi_map_lsapic(pr->handle, &pr->id); 180 ret = acpi_map_lsapic(pr->handle, pr->apic_id, &pr->id);
185 if (ret) 181 if (ret)
186 goto out; 182 goto out;
187 183
@@ -219,11 +215,9 @@ static int acpi_processor_get_info(struct acpi_device *device)
219 int cpu_index, device_declaration = 0; 215 int cpu_index, device_declaration = 0;
220 acpi_status status = AE_OK; 216 acpi_status status = AE_OK;
221 static int cpu0_initialized; 217 static int cpu0_initialized;
218 unsigned long long value;
222 219
223 if (num_online_cpus() > 1) 220 acpi_processor_errata();
224 errata.smp = TRUE;
225
226 acpi_processor_errata(pr);
227 221
228 /* 222 /*
229 * Check to see if we have bus mastering arbitration control. This 223 * Check to see if we have bus mastering arbitration control. This
@@ -247,18 +241,12 @@ static int acpi_processor_get_info(struct acpi_device *device)
247 return -ENODEV; 241 return -ENODEV;
248 } 242 }
249 243
250 /*
251 * TBD: Synch processor ID (via LAPIC/LSAPIC structures) on SMP.
252 * >>> 'acpi_get_processor_id(acpi_id, &id)' in
253 * arch/xxx/acpi.c
254 */
255 pr->acpi_id = object.processor.proc_id; 244 pr->acpi_id = object.processor.proc_id;
256 } else { 245 } else {
257 /* 246 /*
258 * Declared with "Device" statement; match _UID. 247 * Declared with "Device" statement; match _UID.
259 * Note that we don't handle string _UIDs yet. 248 * Note that we don't handle string _UIDs yet.
260 */ 249 */
261 unsigned long long value;
262 status = acpi_evaluate_integer(pr->handle, METHOD_NAME__UID, 250 status = acpi_evaluate_integer(pr->handle, METHOD_NAME__UID,
263 NULL, &value); 251 NULL, &value);
264 if (ACPI_FAILURE(status)) { 252 if (ACPI_FAILURE(status)) {
@@ -270,7 +258,9 @@ static int acpi_processor_get_info(struct acpi_device *device)
270 device_declaration = 1; 258 device_declaration = 1;
271 pr->acpi_id = value; 259 pr->acpi_id = value;
272 } 260 }
273 cpu_index = acpi_get_cpuid(pr->handle, device_declaration, pr->acpi_id); 261 pr->apic_id = acpi_get_apicid(pr->handle, device_declaration,
262 pr->acpi_id);
263 cpu_index = acpi_map_cpuid(pr->apic_id, pr->acpi_id);
274 264
275 /* Handle UP system running SMP kernel, with no LAPIC in MADT */ 265 /* Handle UP system running SMP kernel, with no LAPIC in MADT */
276 if (!cpu0_initialized && (cpu_index == -1) && 266 if (!cpu0_initialized && (cpu_index == -1) &&
@@ -332,9 +322,9 @@ static int acpi_processor_get_info(struct acpi_device *device)
332 * ensure we get the right value in the "physical id" field 322 * ensure we get the right value in the "physical id" field
333 * of /proc/cpuinfo 323 * of /proc/cpuinfo
334 */ 324 */
335 status = acpi_evaluate_object(pr->handle, "_SUN", NULL, &buffer); 325 status = acpi_evaluate_integer(pr->handle, "_SUN", NULL, &value);
336 if (ACPI_SUCCESS(status)) 326 if (ACPI_SUCCESS(status))
337 arch_fix_phys_package_id(pr->id, object.integer.value); 327 arch_fix_phys_package_id(pr->id, value);
338 328
339 return 0; 329 return 0;
340} 330}
diff --git a/drivers/acpi/acpica/acdebug.h b/drivers/acpi/acpica/acdebug.h
index 9feba08c29fe..a9fd0b872062 100644
--- a/drivers/acpi/acpica/acdebug.h
+++ b/drivers/acpi/acpica/acdebug.h
@@ -114,10 +114,12 @@ ACPI_HW_DEPENDENT_RETURN_VOID(void
114 acpi_db_generate_gpe(char *gpe_arg, 114 acpi_db_generate_gpe(char *gpe_arg,
115 char *block_arg)) 115 char *block_arg))
116 116
117ACPI_HW_DEPENDENT_RETURN_VOID(void acpi_db_generate_sci(void))
118
117/* 119/*
118 * dbconvert - miscellaneous conversion routines 120 * dbconvert - miscellaneous conversion routines
119 */ 121 */
120 acpi_status acpi_db_hex_char_to_value(int hex_char, u8 *return_value); 122acpi_status acpi_db_hex_char_to_value(int hex_char, u8 *return_value);
121 123
122acpi_status acpi_db_convert_to_package(char *string, union acpi_object *object); 124acpi_status acpi_db_convert_to_package(char *string, union acpi_object *object);
123 125
@@ -154,6 +156,8 @@ void acpi_db_set_scope(char *name);
154 156
155void acpi_db_dump_namespace(char *start_arg, char *depth_arg); 157void acpi_db_dump_namespace(char *start_arg, char *depth_arg);
156 158
159void acpi_db_dump_namespace_paths(void);
160
157void acpi_db_dump_namespace_by_owner(char *owner_arg, char *depth_arg); 161void acpi_db_dump_namespace_by_owner(char *owner_arg, char *depth_arg);
158 162
159acpi_status acpi_db_find_name_in_namespace(char *name_arg); 163acpi_status acpi_db_find_name_in_namespace(char *name_arg);
@@ -240,6 +244,8 @@ void acpi_db_display_history(void);
240 244
241char *acpi_db_get_from_history(char *command_num_arg); 245char *acpi_db_get_from_history(char *command_num_arg);
242 246
247char *acpi_db_get_history_by_index(u32 commandd_num);
248
243/* 249/*
244 * dbinput - user front-end to the AML debugger 250 * dbinput - user front-end to the AML debugger
245 */ 251 */
diff --git a/drivers/acpi/acpica/acevents.h b/drivers/acpi/acpica/acevents.h
index ab0e97710381..41abe552c7a3 100644
--- a/drivers/acpi/acpica/acevents.h
+++ b/drivers/acpi/acpica/acevents.h
@@ -71,7 +71,8 @@ acpi_status acpi_ev_init_global_lock_handler(void);
71 71
72ACPI_HW_DEPENDENT_RETURN_OK(acpi_status 72ACPI_HW_DEPENDENT_RETURN_OK(acpi_status
73 acpi_ev_acquire_global_lock(u16 timeout)) 73 acpi_ev_acquire_global_lock(u16 timeout))
74 ACPI_HW_DEPENDENT_RETURN_OK(acpi_status acpi_ev_release_global_lock(void)) 74
75ACPI_HW_DEPENDENT_RETURN_OK(acpi_status acpi_ev_release_global_lock(void))
75 acpi_status acpi_ev_remove_global_lock_handler(void); 76 acpi_status acpi_ev_remove_global_lock_handler(void);
76 77
77/* 78/*
@@ -242,11 +243,11 @@ acpi_ev_initialize_region(union acpi_operand_object *region_obj,
242 */ 243 */
243u32 ACPI_SYSTEM_XFACE acpi_ev_gpe_xrupt_handler(void *context); 244u32 ACPI_SYSTEM_XFACE acpi_ev_gpe_xrupt_handler(void *context);
244 245
245u32 acpi_ev_install_sci_handler(void); 246u32 acpi_ev_sci_dispatch(void);
246 247
247acpi_status acpi_ev_remove_sci_handler(void); 248u32 acpi_ev_install_sci_handler(void);
248 249
249u32 acpi_ev_initialize_SCI(u32 program_SCI); 250acpi_status acpi_ev_remove_all_sci_handlers(void);
250 251
251ACPI_HW_DEPENDENT_RETURN_VOID(void acpi_ev_terminate(void)) 252ACPI_HW_DEPENDENT_RETURN_VOID(void acpi_ev_terminate(void))
252#endif /* __ACEVENTS_H__ */ 253#endif /* __ACEVENTS_H__ */
diff --git a/drivers/acpi/acpica/acglobal.h b/drivers/acpi/acpica/acglobal.h
index 90e846f985fa..e9f1fc7f99c7 100644
--- a/drivers/acpi/acpica/acglobal.h
+++ b/drivers/acpi/acpica/acglobal.h
@@ -269,6 +269,7 @@ ACPI_EXTERN acpi_table_handler acpi_gbl_table_handler;
269ACPI_EXTERN void *acpi_gbl_table_handler_context; 269ACPI_EXTERN void *acpi_gbl_table_handler_context;
270ACPI_EXTERN struct acpi_walk_state *acpi_gbl_breakpoint_walk; 270ACPI_EXTERN struct acpi_walk_state *acpi_gbl_breakpoint_walk;
271ACPI_EXTERN acpi_interface_handler acpi_gbl_interface_handler; 271ACPI_EXTERN acpi_interface_handler acpi_gbl_interface_handler;
272ACPI_EXTERN struct acpi_sci_handler_info *acpi_gbl_sci_handler_list;
272 273
273/* Owner ID support */ 274/* Owner ID support */
274 275
@@ -405,7 +406,9 @@ extern u32 acpi_gbl_nesting_level;
405 406
406/* Event counters */ 407/* Event counters */
407 408
409ACPI_EXTERN u32 acpi_method_count;
408ACPI_EXTERN u32 acpi_gpe_count; 410ACPI_EXTERN u32 acpi_gpe_count;
411ACPI_EXTERN u32 acpi_sci_count;
409ACPI_EXTERN u32 acpi_fixed_event_count[ACPI_NUM_FIXED_EVENTS]; 412ACPI_EXTERN u32 acpi_fixed_event_count[ACPI_NUM_FIXED_EVENTS];
410 413
411/* Support for dynamic control method tracing mechanism */ 414/* Support for dynamic control method tracing mechanism */
@@ -445,13 +448,6 @@ ACPI_EXTERN u8 acpi_gbl_db_opt_tables;
445ACPI_EXTERN u8 acpi_gbl_db_opt_stats; 448ACPI_EXTERN u8 acpi_gbl_db_opt_stats;
446ACPI_EXTERN u8 acpi_gbl_db_opt_ini_methods; 449ACPI_EXTERN u8 acpi_gbl_db_opt_ini_methods;
447ACPI_EXTERN u8 acpi_gbl_db_opt_no_region_support; 450ACPI_EXTERN u8 acpi_gbl_db_opt_no_region_support;
448
449ACPI_EXTERN char *acpi_gbl_db_args[ACPI_DEBUGGER_MAX_ARGS];
450ACPI_EXTERN acpi_object_type acpi_gbl_db_arg_types[ACPI_DEBUGGER_MAX_ARGS];
451ACPI_EXTERN char acpi_gbl_db_line_buf[ACPI_DB_LINE_BUFFER_SIZE];
452ACPI_EXTERN char acpi_gbl_db_parsed_buf[ACPI_DB_LINE_BUFFER_SIZE];
453ACPI_EXTERN char acpi_gbl_db_scope_buf[80];
454ACPI_EXTERN char acpi_gbl_db_debug_filename[80];
455ACPI_EXTERN u8 acpi_gbl_db_output_to_file; 451ACPI_EXTERN u8 acpi_gbl_db_output_to_file;
456ACPI_EXTERN char *acpi_gbl_db_buffer; 452ACPI_EXTERN char *acpi_gbl_db_buffer;
457ACPI_EXTERN char *acpi_gbl_db_filename; 453ACPI_EXTERN char *acpi_gbl_db_filename;
@@ -459,6 +455,16 @@ ACPI_EXTERN u32 acpi_gbl_db_debug_level;
459ACPI_EXTERN u32 acpi_gbl_db_console_debug_level; 455ACPI_EXTERN u32 acpi_gbl_db_console_debug_level;
460ACPI_EXTERN struct acpi_namespace_node *acpi_gbl_db_scope_node; 456ACPI_EXTERN struct acpi_namespace_node *acpi_gbl_db_scope_node;
461 457
458ACPI_EXTERN char *acpi_gbl_db_args[ACPI_DEBUGGER_MAX_ARGS];
459ACPI_EXTERN acpi_object_type acpi_gbl_db_arg_types[ACPI_DEBUGGER_MAX_ARGS];
460
461/* These buffers should all be the same size */
462
463ACPI_EXTERN char acpi_gbl_db_line_buf[ACPI_DB_LINE_BUFFER_SIZE];
464ACPI_EXTERN char acpi_gbl_db_parsed_buf[ACPI_DB_LINE_BUFFER_SIZE];
465ACPI_EXTERN char acpi_gbl_db_scope_buf[ACPI_DB_LINE_BUFFER_SIZE];
466ACPI_EXTERN char acpi_gbl_db_debug_filename[ACPI_DB_LINE_BUFFER_SIZE];
467
462/* 468/*
463 * Statistic globals 469 * Statistic globals
464 */ 470 */
diff --git a/drivers/acpi/acpica/aclocal.h b/drivers/acpi/acpica/aclocal.h
index 0ed00669cd21..53ed1a8ba4f0 100644
--- a/drivers/acpi/acpica/aclocal.h
+++ b/drivers/acpi/acpica/aclocal.h
@@ -398,6 +398,14 @@ struct acpi_simple_repair_info {
398 * 398 *
399 ****************************************************************************/ 399 ****************************************************************************/
400 400
401/* Dispatch info for each host-installed SCI handler */
402
403struct acpi_sci_handler_info {
404 struct acpi_sci_handler_info *next;
405 acpi_sci_handler address; /* Address of handler */
406 void *context; /* Context to be passed to handler */
407};
408
401/* Dispatch info for each GPE -- either a method or handler, cannot be both */ 409/* Dispatch info for each GPE -- either a method or handler, cannot be both */
402 410
403struct acpi_gpe_handler_info { 411struct acpi_gpe_handler_info {
@@ -1064,7 +1072,7 @@ struct acpi_db_method_info {
1064 char *name; 1072 char *name;
1065 u32 flags; 1073 u32 flags;
1066 u32 num_loops; 1074 u32 num_loops;
1067 char pathname[128]; 1075 char pathname[ACPI_DB_LINE_BUFFER_SIZE];
1068 char **args; 1076 char **args;
1069 acpi_object_type *types; 1077 acpi_object_type *types;
1070 1078
@@ -1086,6 +1094,7 @@ struct acpi_integrity_info {
1086 u32 objects; 1094 u32 objects;
1087}; 1095};
1088 1096
1097#define ACPI_DB_DISABLE_OUTPUT 0x00
1089#define ACPI_DB_REDIRECTABLE_OUTPUT 0x01 1098#define ACPI_DB_REDIRECTABLE_OUTPUT 0x01
1090#define ACPI_DB_CONSOLE_OUTPUT 0x02 1099#define ACPI_DB_CONSOLE_OUTPUT 0x02
1091#define ACPI_DB_DUPLICATE_OUTPUT 0x03 1100#define ACPI_DB_DUPLICATE_OUTPUT 0x03
diff --git a/drivers/acpi/acpica/acmacros.h b/drivers/acpi/acpica/acmacros.h
index 530a2f8c1252..2a86c65d873b 100644
--- a/drivers/acpi/acpica/acmacros.h
+++ b/drivers/acpi/acpica/acmacros.h
@@ -410,37 +410,6 @@
410#endif 410#endif
411 411
412/* 412/*
413 * Memory allocation tracking (DEBUG ONLY)
414 */
415#define ACPI_MEM_PARAMETERS _COMPONENT, _acpi_module_name, __LINE__
416
417#ifndef ACPI_DBG_TRACK_ALLOCATIONS
418
419/* Memory allocation */
420
421#ifndef ACPI_ALLOCATE
422#define ACPI_ALLOCATE(a) acpi_ut_allocate((acpi_size) (a), ACPI_MEM_PARAMETERS)
423#endif
424#ifndef ACPI_ALLOCATE_ZEROED
425#define ACPI_ALLOCATE_ZEROED(a) acpi_ut_allocate_zeroed((acpi_size) (a), ACPI_MEM_PARAMETERS)
426#endif
427#ifndef ACPI_FREE
428#define ACPI_FREE(a) acpi_os_free(a)
429#endif
430#define ACPI_MEM_TRACKING(a)
431
432#else
433
434/* Memory allocation */
435
436#define ACPI_ALLOCATE(a) acpi_ut_allocate_and_track((acpi_size) (a), ACPI_MEM_PARAMETERS)
437#define ACPI_ALLOCATE_ZEROED(a) acpi_ut_allocate_zeroed_and_track((acpi_size) (a), ACPI_MEM_PARAMETERS)
438#define ACPI_FREE(a) acpi_ut_free_and_track(a, ACPI_MEM_PARAMETERS)
439#define ACPI_MEM_TRACKING(a) a
440
441#endif /* ACPI_DBG_TRACK_ALLOCATIONS */
442
443/*
444 * Macros used for ACPICA utilities only 413 * Macros used for ACPICA utilities only
445 */ 414 */
446 415
diff --git a/drivers/acpi/acpica/acnamesp.h b/drivers/acpi/acpica/acnamesp.h
index 40b04bd5579e..e6138ac4a160 100644
--- a/drivers/acpi/acpica/acnamesp.h
+++ b/drivers/acpi/acpica/acnamesp.h
@@ -213,6 +213,12 @@ acpi_ns_dump_objects(acpi_object_type type,
213 u8 display_type, 213 u8 display_type,
214 u32 max_depth, 214 u32 max_depth,
215 acpi_owner_id owner_id, acpi_handle start_handle); 215 acpi_owner_id owner_id, acpi_handle start_handle);
216
217void
218acpi_ns_dump_object_paths(acpi_object_type type,
219 u8 display_type,
220 u32 max_depth,
221 acpi_owner_id owner_id, acpi_handle start_handle);
216#endif /* ACPI_FUTURE_USAGE */ 222#endif /* ACPI_FUTURE_USAGE */
217 223
218/* 224/*
diff --git a/drivers/acpi/acpica/acutils.h b/drivers/acpi/acpica/acutils.h
index d5a62a6182bb..be8180c17d7e 100644
--- a/drivers/acpi/acpica/acutils.h
+++ b/drivers/acpi/acpica/acutils.h
@@ -628,6 +628,17 @@ u8 acpi_ut_valid_acpi_char(char character, u32 position);
628 628
629void acpi_ut_repair_name(char *name); 629void acpi_ut_repair_name(char *name);
630 630
631#if defined (ACPI_DEBUGGER) || defined (ACPI_APPLICATION)
632u8 acpi_ut_safe_strcpy(char *dest, acpi_size dest_size, char *source);
633
634u8 acpi_ut_safe_strcat(char *dest, acpi_size dest_size, char *source);
635
636u8
637acpi_ut_safe_strncat(char *dest,
638 acpi_size dest_size,
639 char *source, acpi_size max_transfer_length);
640#endif
641
631/* 642/*
632 * utmutex - mutex support 643 * utmutex - mutex support
633 */ 644 */
@@ -652,12 +663,6 @@ acpi_status
652acpi_ut_initialize_buffer(struct acpi_buffer *buffer, 663acpi_ut_initialize_buffer(struct acpi_buffer *buffer,
653 acpi_size required_length); 664 acpi_size required_length);
654 665
655void *acpi_ut_allocate(acpi_size size,
656 u32 component, const char *module, u32 line);
657
658void *acpi_ut_allocate_zeroed(acpi_size size,
659 u32 component, const char *module, u32 line);
660
661#ifdef ACPI_DBG_TRACK_ALLOCATIONS 666#ifdef ACPI_DBG_TRACK_ALLOCATIONS
662void *acpi_ut_allocate_and_track(acpi_size size, 667void *acpi_ut_allocate_and_track(acpi_size size,
663 u32 component, const char *module, u32 line); 668 u32 component, const char *module, u32 line);
diff --git a/drivers/acpi/acpica/dsargs.c b/drivers/acpi/acpica/dsargs.c
index fb09b08d7080..afdc6df17abf 100644
--- a/drivers/acpi/acpica/dsargs.c
+++ b/drivers/acpi/acpica/dsargs.c
@@ -158,7 +158,7 @@ acpi_ds_execute_arguments(struct acpi_namespace_node *node,
158 walk_state->deferred_node = node; 158 walk_state->deferred_node = node;
159 status = acpi_ps_parse_aml(walk_state); 159 status = acpi_ps_parse_aml(walk_state);
160 160
161 cleanup: 161cleanup:
162 acpi_ps_delete_parse_tree(op); 162 acpi_ps_delete_parse_tree(op);
163 return_ACPI_STATUS(status); 163 return_ACPI_STATUS(status);
164} 164}
diff --git a/drivers/acpi/acpica/dsfield.c b/drivers/acpi/acpica/dsfield.c
index d4bfe7b7f90a..2d4c07322576 100644
--- a/drivers/acpi/acpica/dsfield.c
+++ b/drivers/acpi/acpica/dsfield.c
@@ -259,7 +259,7 @@ acpi_ds_create_buffer_field(union acpi_parse_object *op,
259 goto cleanup; 259 goto cleanup;
260 } 260 }
261 261
262 cleanup: 262cleanup:
263 263
264 /* Remove local reference to the object */ 264 /* Remove local reference to the object */
265 265
diff --git a/drivers/acpi/acpica/dsmethod.c b/drivers/acpi/acpica/dsmethod.c
index a9ffd44c18fe..81a78ba84311 100644
--- a/drivers/acpi/acpica/dsmethod.c
+++ b/drivers/acpi/acpica/dsmethod.c
@@ -292,9 +292,10 @@ acpi_ds_begin_method_execution(struct acpi_namespace_node *method_node,
292 * reentered one more time (even if it is the same thread) 292 * reentered one more time (even if it is the same thread)
293 */ 293 */
294 obj_desc->method.thread_count++; 294 obj_desc->method.thread_count++;
295 acpi_method_count++;
295 return_ACPI_STATUS(status); 296 return_ACPI_STATUS(status);
296 297
297 cleanup: 298cleanup:
298 /* On error, must release the method mutex (if present) */ 299 /* On error, must release the method mutex (if present) */
299 300
300 if (obj_desc->method.mutex) { 301 if (obj_desc->method.mutex) {
@@ -424,7 +425,7 @@ acpi_ds_call_control_method(struct acpi_thread_state *thread,
424 425
425 return_ACPI_STATUS(status); 426 return_ACPI_STATUS(status);
426 427
427 cleanup: 428cleanup:
428 429
429 /* On error, we must terminate the method properly */ 430 /* On error, we must terminate the method properly */
430 431
diff --git a/drivers/acpi/acpica/dsobject.c b/drivers/acpi/acpica/dsobject.c
index 63f0d220ca3d..b1746a68dad1 100644
--- a/drivers/acpi/acpica/dsobject.c
+++ b/drivers/acpi/acpica/dsobject.c
@@ -240,7 +240,7 @@ acpi_ds_build_internal_object(struct acpi_walk_state *walk_state,
240 return_ACPI_STATUS(status); 240 return_ACPI_STATUS(status);
241 } 241 }
242 242
243 exit: 243exit:
244 *obj_desc_ptr = obj_desc; 244 *obj_desc_ptr = obj_desc;
245 return_ACPI_STATUS(status); 245 return_ACPI_STATUS(status);
246} 246}
diff --git a/drivers/acpi/acpica/dsopcode.c b/drivers/acpi/acpica/dsopcode.c
index 1fc1ff114f26..5205edcf2c01 100644
--- a/drivers/acpi/acpica/dsopcode.c
+++ b/drivers/acpi/acpica/dsopcode.c
@@ -257,7 +257,7 @@ acpi_ds_init_buffer_field(u16 aml_opcode,
257 (buffer_desc->common.reference_count + 257 (buffer_desc->common.reference_count +
258 obj_desc->common.reference_count); 258 obj_desc->common.reference_count);
259 259
260 cleanup: 260cleanup:
261 261
262 /* Always delete the operands */ 262 /* Always delete the operands */
263 263
diff --git a/drivers/acpi/acpica/dsutils.c b/drivers/acpi/acpica/dsutils.c
index c666fc014987..ade44e49deb4 100644
--- a/drivers/acpi/acpica/dsutils.c
+++ b/drivers/acpi/acpica/dsutils.c
@@ -299,7 +299,7 @@ acpi_ds_is_result_used(union acpi_parse_object * op,
299 goto result_used; 299 goto result_used;
300 } 300 }
301 301
302 result_used: 302result_used:
303 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, 303 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
304 "Result of [%s] used by Parent [%s] Op=%p\n", 304 "Result of [%s] used by Parent [%s] Op=%p\n",
305 acpi_ps_get_opcode_name(op->common.aml_opcode), 305 acpi_ps_get_opcode_name(op->common.aml_opcode),
@@ -308,7 +308,7 @@ acpi_ds_is_result_used(union acpi_parse_object * op,
308 308
309 return_UINT8(TRUE); 309 return_UINT8(TRUE);
310 310
311 result_not_used: 311result_not_used:
312 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, 312 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
313 "Result of [%s] not used by Parent [%s] Op=%p\n", 313 "Result of [%s] not used by Parent [%s] Op=%p\n",
314 acpi_ps_get_opcode_name(op->common.aml_opcode), 314 acpi_ps_get_opcode_name(op->common.aml_opcode),
@@ -752,7 +752,7 @@ acpi_ds_create_operands(struct acpi_walk_state *walk_state,
752 752
753 return_ACPI_STATUS(status); 753 return_ACPI_STATUS(status);
754 754
755 cleanup: 755cleanup:
756 /* 756 /*
757 * We must undo everything done above; meaning that we must 757 * We must undo everything done above; meaning that we must
758 * pop everything off of the operand stack and delete those 758 * pop everything off of the operand stack and delete those
@@ -851,7 +851,7 @@ acpi_status acpi_ds_evaluate_name_path(struct acpi_walk_state *walk_state)
851 goto exit; 851 goto exit;
852 } 852 }
853 853
854 push_result: 854push_result:
855 855
856 walk_state->result_obj = new_obj_desc; 856 walk_state->result_obj = new_obj_desc;
857 857
@@ -863,7 +863,7 @@ acpi_status acpi_ds_evaluate_name_path(struct acpi_walk_state *walk_state)
863 op->common.flags |= ACPI_PARSEOP_IN_STACK; 863 op->common.flags |= ACPI_PARSEOP_IN_STACK;
864 } 864 }
865 865
866 exit: 866exit:
867 867
868 return_ACPI_STATUS(status); 868 return_ACPI_STATUS(status);
869} 869}
diff --git a/drivers/acpi/acpica/dswexec.c b/drivers/acpi/acpica/dswexec.c
index 151d924817e1..1bbb22fd6fa0 100644
--- a/drivers/acpi/acpica/dswexec.c
+++ b/drivers/acpi/acpica/dswexec.c
@@ -170,7 +170,7 @@ acpi_ds_get_predicate_value(struct acpi_walk_state *walk_state,
170 170
171 (void)acpi_ds_do_implicit_return(local_obj_desc, walk_state, TRUE); 171 (void)acpi_ds_do_implicit_return(local_obj_desc, walk_state, TRUE);
172 172
173 cleanup: 173cleanup:
174 174
175 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Completed a predicate eval=%X Op=%p\n", 175 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Completed a predicate eval=%X Op=%p\n",
176 walk_state->control_state->common.value, 176 walk_state->control_state->common.value,
@@ -335,7 +335,7 @@ acpi_ds_exec_begin_op(struct acpi_walk_state *walk_state,
335 335
336 return_ACPI_STATUS(status); 336 return_ACPI_STATUS(status);
337 337
338 error_exit: 338error_exit:
339 status = acpi_ds_method_error(status, walk_state); 339 status = acpi_ds_method_error(status, walk_state);
340 return_ACPI_STATUS(status); 340 return_ACPI_STATUS(status);
341} 341}
@@ -722,7 +722,7 @@ acpi_status acpi_ds_exec_end_op(struct acpi_walk_state *walk_state)
722 walk_state->result_obj = NULL; 722 walk_state->result_obj = NULL;
723 } 723 }
724 724
725 cleanup: 725cleanup:
726 726
727 if (walk_state->result_obj) { 727 if (walk_state->result_obj) {
728 728
diff --git a/drivers/acpi/acpica/dswload2.c b/drivers/acpi/acpica/dswload2.c
index b1f8f4725c23..7f569d573027 100644
--- a/drivers/acpi/acpica/dswload2.c
+++ b/drivers/acpi/acpica/dswload2.c
@@ -728,7 +728,7 @@ acpi_status acpi_ds_load2_end_op(struct acpi_walk_state *walk_state)
728 break; 728 break;
729 } 729 }
730 730
731 cleanup: 731cleanup:
732 732
733 /* Remove the Node pushed at the very beginning */ 733 /* Remove the Node pushed at the very beginning */
734 734
diff --git a/drivers/acpi/acpica/evglock.c b/drivers/acpi/acpica/evglock.c
index fdb0a76e40a3..4c67193a9fa7 100644
--- a/drivers/acpi/acpica/evglock.c
+++ b/drivers/acpi/acpica/evglock.c
@@ -173,7 +173,7 @@ static u32 acpi_ev_global_lock_handler(void *context)
173 173
174 acpi_gbl_global_lock_pending = FALSE; 174 acpi_gbl_global_lock_pending = FALSE;
175 175
176 cleanup_and_exit: 176cleanup_and_exit:
177 177
178 acpi_os_release_lock(acpi_gbl_global_lock_pending_lock, flags); 178 acpi_os_release_lock(acpi_gbl_global_lock_pending_lock, flags);
179 return (ACPI_INTERRUPT_HANDLED); 179 return (ACPI_INTERRUPT_HANDLED);
diff --git a/drivers/acpi/acpica/evgpe.c b/drivers/acpi/acpica/evgpe.c
index c8a1f7d5931f..a9cb4a1a4bb8 100644
--- a/drivers/acpi/acpica/evgpe.c
+++ b/drivers/acpi/acpica/evgpe.c
@@ -458,7 +458,7 @@ u32 acpi_ev_gpe_detect(struct acpi_gpe_xrupt_info * gpe_xrupt_list)
458 gpe_block = gpe_block->next; 458 gpe_block = gpe_block->next;
459 } 459 }
460 460
461 unlock_and_exit: 461unlock_and_exit:
462 462
463 acpi_os_release_lock(acpi_gbl_gpe_lock, flags); 463 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
464 return (int_status); 464 return (int_status);
@@ -522,6 +522,7 @@ static void ACPI_SYSTEM_XFACE acpi_ev_asynch_execute_gpe_method(void *context)
522 522
523 status = acpi_ut_release_mutex(ACPI_MTX_EVENTS); 523 status = acpi_ut_release_mutex(ACPI_MTX_EVENTS);
524 if (ACPI_FAILURE(status)) { 524 if (ACPI_FAILURE(status)) {
525 ACPI_FREE(local_gpe_event_info);
525 return_VOID; 526 return_VOID;
526 } 527 }
527 528
diff --git a/drivers/acpi/acpica/evgpeblk.c b/drivers/acpi/acpica/evgpeblk.c
index c1aa1eda26c3..a9e76bc4ad97 100644
--- a/drivers/acpi/acpica/evgpeblk.c
+++ b/drivers/acpi/acpica/evgpeblk.c
@@ -111,7 +111,7 @@ acpi_ev_install_gpe_block(struct acpi_gpe_block_info *gpe_block,
111 gpe_block->xrupt_block = gpe_xrupt_block; 111 gpe_block->xrupt_block = gpe_xrupt_block;
112 acpi_os_release_lock(acpi_gbl_gpe_lock, flags); 112 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
113 113
114 unlock_and_exit: 114unlock_and_exit:
115 status = acpi_ut_release_mutex(ACPI_MTX_EVENTS); 115 status = acpi_ut_release_mutex(ACPI_MTX_EVENTS);
116 return_ACPI_STATUS(status); 116 return_ACPI_STATUS(status);
117} 117}
@@ -178,7 +178,7 @@ acpi_status acpi_ev_delete_gpe_block(struct acpi_gpe_block_info *gpe_block)
178 ACPI_FREE(gpe_block->event_info); 178 ACPI_FREE(gpe_block->event_info);
179 ACPI_FREE(gpe_block); 179 ACPI_FREE(gpe_block);
180 180
181 unlock_and_exit: 181unlock_and_exit:
182 status = acpi_ut_release_mutex(ACPI_MTX_EVENTS); 182 status = acpi_ut_release_mutex(ACPI_MTX_EVENTS);
183 return_ACPI_STATUS(status); 183 return_ACPI_STATUS(status);
184} 184}
@@ -302,7 +302,7 @@ acpi_ev_create_gpe_info_blocks(struct acpi_gpe_block_info *gpe_block)
302 302
303 return_ACPI_STATUS(AE_OK); 303 return_ACPI_STATUS(AE_OK);
304 304
305 error_exit: 305error_exit:
306 if (gpe_register_info) { 306 if (gpe_register_info) {
307 ACPI_FREE(gpe_register_info); 307 ACPI_FREE(gpe_register_info);
308 } 308 }
diff --git a/drivers/acpi/acpica/evgpeinit.c b/drivers/acpi/acpica/evgpeinit.c
index 7842700346a4..a3e2f38aadf6 100644
--- a/drivers/acpi/acpica/evgpeinit.c
+++ b/drivers/acpi/acpica/evgpeinit.c
@@ -203,7 +203,7 @@ acpi_status acpi_ev_gpe_initialize(void)
203 goto cleanup; 203 goto cleanup;
204 } 204 }
205 205
206 cleanup: 206cleanup:
207 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); 207 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
208 return_ACPI_STATUS(AE_OK); 208 return_ACPI_STATUS(AE_OK);
209} 209}
diff --git a/drivers/acpi/acpica/evgpeutil.c b/drivers/acpi/acpica/evgpeutil.c
index b24dbb80fab8..d3f5e1e2a2b1 100644
--- a/drivers/acpi/acpica/evgpeutil.c
+++ b/drivers/acpi/acpica/evgpeutil.c
@@ -101,7 +101,7 @@ acpi_ev_walk_gpe_list(acpi_gpe_callback gpe_walk_callback, void *context)
101 gpe_xrupt_info = gpe_xrupt_info->next; 101 gpe_xrupt_info = gpe_xrupt_info->next;
102 } 102 }
103 103
104 unlock_and_exit: 104unlock_and_exit:
105 acpi_os_release_lock(acpi_gbl_gpe_lock, flags); 105 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
106 return_ACPI_STATUS(status); 106 return_ACPI_STATUS(status);
107} 107}
@@ -196,7 +196,7 @@ acpi_ev_get_gpe_device(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
196 * 196 *
197 * FUNCTION: acpi_ev_get_gpe_xrupt_block 197 * FUNCTION: acpi_ev_get_gpe_xrupt_block
198 * 198 *
199 * PARAMETERS: interrupt_number - Interrupt for a GPE block 199 * PARAMETERS: interrupt_number - Interrupt for a GPE block
200 * 200 *
201 * RETURN: A GPE interrupt block 201 * RETURN: A GPE interrupt block
202 * 202 *
diff --git a/drivers/acpi/acpica/evhandler.c b/drivers/acpi/acpica/evhandler.c
index 068af96134b8..e3157313eb27 100644
--- a/drivers/acpi/acpica/evhandler.c
+++ b/drivers/acpi/acpica/evhandler.c
@@ -129,7 +129,7 @@ acpi_status acpi_ev_install_region_handlers(void)
129 } 129 }
130 } 130 }
131 131
132 unlock_and_exit: 132unlock_and_exit:
133 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); 133 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
134 return_ACPI_STATUS(status); 134 return_ACPI_STATUS(status);
135} 135}
@@ -531,6 +531,6 @@ acpi_ev_install_space_handler(struct acpi_namespace_node * node,
531 acpi_ev_install_handler, NULL, 531 acpi_ev_install_handler, NULL,
532 handler_obj, NULL); 532 handler_obj, NULL);
533 533
534 unlock_and_exit: 534unlock_and_exit:
535 return_ACPI_STATUS(status); 535 return_ACPI_STATUS(status);
536} 536}
diff --git a/drivers/acpi/acpica/evmisc.c b/drivers/acpi/acpica/evmisc.c
index 1b111ef74903..a5687540e9a6 100644
--- a/drivers/acpi/acpica/evmisc.c
+++ b/drivers/acpi/acpica/evmisc.c
@@ -264,13 +264,6 @@ void acpi_ev_terminate(void)
264 264
265 status = acpi_ev_walk_gpe_list(acpi_hw_disable_gpe_block, NULL); 265 status = acpi_ev_walk_gpe_list(acpi_hw_disable_gpe_block, NULL);
266 266
267 /* Remove SCI handler */
268
269 status = acpi_ev_remove_sci_handler();
270 if (ACPI_FAILURE(status)) {
271 ACPI_ERROR((AE_INFO, "Could not remove SCI handler"));
272 }
273
274 status = acpi_ev_remove_global_lock_handler(); 267 status = acpi_ev_remove_global_lock_handler();
275 if (ACPI_FAILURE(status)) { 268 if (ACPI_FAILURE(status)) {
276 ACPI_ERROR((AE_INFO, 269 ACPI_ERROR((AE_INFO,
@@ -280,6 +273,13 @@ void acpi_ev_terminate(void)
280 acpi_gbl_events_initialized = FALSE; 273 acpi_gbl_events_initialized = FALSE;
281 } 274 }
282 275
276 /* Remove SCI handlers */
277
278 status = acpi_ev_remove_all_sci_handlers();
279 if (ACPI_FAILURE(status)) {
280 ACPI_ERROR((AE_INFO, "Could not remove SCI handler"));
281 }
282
283 /* Deallocate all handler objects installed within GPE info structs */ 283 /* Deallocate all handler objects installed within GPE info structs */
284 284
285 status = acpi_ev_walk_gpe_list(acpi_ev_delete_gpe_handlers, NULL); 285 status = acpi_ev_walk_gpe_list(acpi_ev_delete_gpe_handlers, NULL);
diff --git a/drivers/acpi/acpica/evregion.c b/drivers/acpi/acpica/evregion.c
index cea14d6fc76c..144cbb9b73bc 100644
--- a/drivers/acpi/acpica/evregion.c
+++ b/drivers/acpi/acpica/evregion.c
@@ -217,16 +217,11 @@ acpi_ev_address_space_dispatch(union acpi_operand_object *region_obj,
217 if (!(region_obj->region.flags & AOPOBJ_SETUP_COMPLETE)) { 217 if (!(region_obj->region.flags & AOPOBJ_SETUP_COMPLETE)) {
218 region_obj->region.flags |= AOPOBJ_SETUP_COMPLETE; 218 region_obj->region.flags |= AOPOBJ_SETUP_COMPLETE;
219 219
220 if (region_obj2->extra.region_context) { 220 /*
221 221 * Save the returned context for use in all accesses to
222 /* The handler for this region was already installed */ 222 * the handler for this particular region
223 223 */
224 ACPI_FREE(region_context); 224 if (!(region_obj2->extra.region_context)) {
225 } else {
226 /*
227 * Save the returned context for use in all accesses to
228 * this particular region
229 */
230 region_obj2->extra.region_context = 225 region_obj2->extra.region_context =
231 region_context; 226 region_context;
232 } 227 }
@@ -402,6 +397,14 @@ acpi_ev_detach_region(union acpi_operand_object *region_obj,
402 handler_obj->address_space. 397 handler_obj->address_space.
403 context, region_context); 398 context, region_context);
404 399
400 /*
401 * region_context should have been released by the deactivate
402 * operation. We don't need access to it anymore here.
403 */
404 if (region_context) {
405 *region_context = NULL;
406 }
407
405 /* Init routine may fail, Just ignore errors */ 408 /* Init routine may fail, Just ignore errors */
406 409
407 if (ACPI_FAILURE(status)) { 410 if (ACPI_FAILURE(status)) {
@@ -570,10 +573,10 @@ acpi_ev_execute_reg_method(union acpi_operand_object *region_obj, u32 function)
570 status = acpi_ns_evaluate(info); 573 status = acpi_ns_evaluate(info);
571 acpi_ut_remove_reference(args[1]); 574 acpi_ut_remove_reference(args[1]);
572 575
573 cleanup2: 576cleanup2:
574 acpi_ut_remove_reference(args[0]); 577 acpi_ut_remove_reference(args[0]);
575 578
576 cleanup1: 579cleanup1:
577 ACPI_FREE(info); 580 ACPI_FREE(info);
578 return_ACPI_STATUS(status); 581 return_ACPI_STATUS(status);
579} 582}
@@ -758,7 +761,7 @@ acpi_ev_orphan_ec_reg_method(struct acpi_namespace_node *ec_device_node)
758 761
759 status = acpi_evaluate_object(reg_method, NULL, &args, NULL); 762 status = acpi_evaluate_object(reg_method, NULL, &args, NULL);
760 763
761 exit: 764exit:
762 /* We ignore all errors from above, don't care */ 765 /* We ignore all errors from above, don't care */
763 766
764 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); 767 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
diff --git a/drivers/acpi/acpica/evsci.c b/drivers/acpi/acpica/evsci.c
index b905acf7aacd..9e9e3454d893 100644
--- a/drivers/acpi/acpica/evsci.c
+++ b/drivers/acpi/acpica/evsci.c
@@ -54,6 +54,50 @@ static u32 ACPI_SYSTEM_XFACE acpi_ev_sci_xrupt_handler(void *context);
54 54
55/******************************************************************************* 55/*******************************************************************************
56 * 56 *
57 * FUNCTION: acpi_ev_sci_dispatch
58 *
59 * PARAMETERS: None
60 *
61 * RETURN: Status code indicates whether interrupt was handled.
62 *
63 * DESCRIPTION: Dispatch the SCI to all host-installed SCI handlers.
64 *
65 ******************************************************************************/
66
67u32 acpi_ev_sci_dispatch(void)
68{
69 struct acpi_sci_handler_info *sci_handler;
70 acpi_cpu_flags flags;
71 u32 int_status = ACPI_INTERRUPT_NOT_HANDLED;
72
73 ACPI_FUNCTION_NAME(ev_sci_dispatch);
74
75 /* Are there any host-installed SCI handlers? */
76
77 if (!acpi_gbl_sci_handler_list) {
78 return (int_status);
79 }
80
81 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
82
83 /* Invoke all host-installed SCI handlers */
84
85 sci_handler = acpi_gbl_sci_handler_list;
86 while (sci_handler) {
87
88 /* Invoke the installed handler (at interrupt level) */
89
90 int_status |= sci_handler->address(sci_handler->context);
91
92 sci_handler = sci_handler->next;
93 }
94
95 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
96 return (int_status);
97}
98
99/*******************************************************************************
100 *
57 * FUNCTION: acpi_ev_sci_xrupt_handler 101 * FUNCTION: acpi_ev_sci_xrupt_handler
58 * 102 *
59 * PARAMETERS: context - Calling Context 103 * PARAMETERS: context - Calling Context
@@ -89,6 +133,11 @@ static u32 ACPI_SYSTEM_XFACE acpi_ev_sci_xrupt_handler(void *context)
89 */ 133 */
90 interrupt_handled |= acpi_ev_gpe_detect(gpe_xrupt_list); 134 interrupt_handled |= acpi_ev_gpe_detect(gpe_xrupt_list);
91 135
136 /* Invoke all host-installed SCI handlers */
137
138 interrupt_handled |= acpi_ev_sci_dispatch();
139
140 acpi_sci_count++;
92 return_UINT32(interrupt_handled); 141 return_UINT32(interrupt_handled);
93} 142}
94 143
@@ -112,14 +161,13 @@ u32 ACPI_SYSTEM_XFACE acpi_ev_gpe_xrupt_handler(void *context)
112 ACPI_FUNCTION_TRACE(ev_gpe_xrupt_handler); 161 ACPI_FUNCTION_TRACE(ev_gpe_xrupt_handler);
113 162
114 /* 163 /*
115 * We are guaranteed by the ACPI CA initialization/shutdown code that 164 * We are guaranteed by the ACPICA initialization/shutdown code that
116 * if this interrupt handler is installed, ACPI is enabled. 165 * if this interrupt handler is installed, ACPI is enabled.
117 */ 166 */
118 167
119 /* GPEs: Check for and dispatch any GPEs that have occurred */ 168 /* GPEs: Check for and dispatch any GPEs that have occurred */
120 169
121 interrupt_handled |= acpi_ev_gpe_detect(gpe_xrupt_list); 170 interrupt_handled |= acpi_ev_gpe_detect(gpe_xrupt_list);
122
123 return_UINT32(interrupt_handled); 171 return_UINT32(interrupt_handled);
124} 172}
125 173
@@ -150,15 +198,15 @@ u32 acpi_ev_install_sci_handler(void)
150 198
151/****************************************************************************** 199/******************************************************************************
152 * 200 *
153 * FUNCTION: acpi_ev_remove_sci_handler 201 * FUNCTION: acpi_ev_remove_all_sci_handlers
154 * 202 *
155 * PARAMETERS: none 203 * PARAMETERS: none
156 * 204 *
157 * RETURN: E_OK if handler uninstalled OK, E_ERROR if handler was not 205 * RETURN: AE_OK if handler uninstalled, AE_ERROR if handler was not
158 * installed to begin with 206 * installed to begin with
159 * 207 *
160 * DESCRIPTION: Remove the SCI interrupt handler. No further SCIs will be 208 * DESCRIPTION: Remove the SCI interrupt handler. No further SCIs will be
161 * taken. 209 * taken. Remove all host-installed SCI handlers.
162 * 210 *
163 * Note: It doesn't seem important to disable all events or set the event 211 * Note: It doesn't seem important to disable all events or set the event
164 * enable registers to their original values. The OS should disable 212 * enable registers to their original values. The OS should disable
@@ -167,11 +215,13 @@ u32 acpi_ev_install_sci_handler(void)
167 * 215 *
168 ******************************************************************************/ 216 ******************************************************************************/
169 217
170acpi_status acpi_ev_remove_sci_handler(void) 218acpi_status acpi_ev_remove_all_sci_handlers(void)
171{ 219{
220 struct acpi_sci_handler_info *sci_handler;
221 acpi_cpu_flags flags;
172 acpi_status status; 222 acpi_status status;
173 223
174 ACPI_FUNCTION_TRACE(ev_remove_sci_handler); 224 ACPI_FUNCTION_TRACE(ev_remove_all_sci_handlers);
175 225
176 /* Just let the OS remove the handler and disable the level */ 226 /* Just let the OS remove the handler and disable the level */
177 227
@@ -179,6 +229,21 @@ acpi_status acpi_ev_remove_sci_handler(void)
179 acpi_os_remove_interrupt_handler((u32) acpi_gbl_FADT.sci_interrupt, 229 acpi_os_remove_interrupt_handler((u32) acpi_gbl_FADT.sci_interrupt,
180 acpi_ev_sci_xrupt_handler); 230 acpi_ev_sci_xrupt_handler);
181 231
232 if (!acpi_gbl_sci_handler_list) {
233 return (status);
234 }
235
236 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
237
238 /* Free all host-installed SCI handlers */
239
240 while (acpi_gbl_sci_handler_list) {
241 sci_handler = acpi_gbl_sci_handler_list;
242 acpi_gbl_sci_handler_list = sci_handler->next;
243 ACPI_FREE(sci_handler);
244 }
245
246 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
182 return_ACPI_STATUS(status); 247 return_ACPI_STATUS(status);
183} 248}
184 249
diff --git a/drivers/acpi/acpica/evxface.c b/drivers/acpi/acpica/evxface.c
index ca5fba99c33b..23a7fadca412 100644
--- a/drivers/acpi/acpica/evxface.c
+++ b/drivers/acpi/acpica/evxface.c
@@ -41,7 +41,8 @@
41 * POSSIBILITY OF SUCH DAMAGES. 41 * POSSIBILITY OF SUCH DAMAGES.
42 */ 42 */
43 43
44#include <linux/export.h> 44#define EXPORT_ACPI_INTERFACES
45
45#include <acpi/acpi.h> 46#include <acpi/acpi.h>
46#include "accommon.h" 47#include "accommon.h"
47#include "acnamesp.h" 48#include "acnamesp.h"
@@ -374,7 +375,7 @@ acpi_status acpi_install_exception_handler(acpi_exception_handler handler)
374 375
375 acpi_gbl_exception_handler = handler; 376 acpi_gbl_exception_handler = handler;
376 377
377 cleanup: 378cleanup:
378 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); 379 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
379 return_ACPI_STATUS(status); 380 return_ACPI_STATUS(status);
380} 381}
@@ -385,6 +386,144 @@ ACPI_EXPORT_SYMBOL(acpi_install_exception_handler)
385#if (!ACPI_REDUCED_HARDWARE) 386#if (!ACPI_REDUCED_HARDWARE)
386/******************************************************************************* 387/*******************************************************************************
387 * 388 *
389 * FUNCTION: acpi_install_sci_handler
390 *
391 * PARAMETERS: address - Address of the handler
392 * context - Value passed to the handler on each SCI
393 *
394 * RETURN: Status
395 *
396 * DESCRIPTION: Install a handler for a System Control Interrupt.
397 *
398 ******************************************************************************/
399acpi_status acpi_install_sci_handler(acpi_sci_handler address, void *context)
400{
401 struct acpi_sci_handler_info *new_sci_handler;
402 struct acpi_sci_handler_info *sci_handler;
403 acpi_cpu_flags flags;
404 acpi_status status;
405
406 ACPI_FUNCTION_TRACE(acpi_install_sci_handler);
407
408 if (!address) {
409 return_ACPI_STATUS(AE_BAD_PARAMETER);
410 }
411
412 /* Allocate and init a handler object */
413
414 new_sci_handler = ACPI_ALLOCATE(sizeof(struct acpi_sci_handler_info));
415 if (!new_sci_handler) {
416 return_ACPI_STATUS(AE_NO_MEMORY);
417 }
418
419 new_sci_handler->address = address;
420 new_sci_handler->context = context;
421
422 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
423 if (ACPI_FAILURE(status)) {
424 goto exit;
425 }
426
427 /* Lock list during installation */
428
429 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
430 sci_handler = acpi_gbl_sci_handler_list;
431
432 /* Ensure handler does not already exist */
433
434 while (sci_handler) {
435 if (address == sci_handler->address) {
436 status = AE_ALREADY_EXISTS;
437 goto unlock_and_exit;
438 }
439
440 sci_handler = sci_handler->next;
441 }
442
443 /* Install the new handler into the global list (at head) */
444
445 new_sci_handler->next = acpi_gbl_sci_handler_list;
446 acpi_gbl_sci_handler_list = new_sci_handler;
447
448unlock_and_exit:
449
450 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
451 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
452
453exit:
454 if (ACPI_FAILURE(status)) {
455 ACPI_FREE(new_sci_handler);
456 }
457 return_ACPI_STATUS(status);
458}
459
460/*******************************************************************************
461 *
462 * FUNCTION: acpi_remove_sci_handler
463 *
464 * PARAMETERS: address - Address of the handler
465 *
466 * RETURN: Status
467 *
468 * DESCRIPTION: Remove a handler for a System Control Interrupt.
469 *
470 ******************************************************************************/
471
472acpi_status acpi_remove_sci_handler(acpi_sci_handler address)
473{
474 struct acpi_sci_handler_info *prev_sci_handler;
475 struct acpi_sci_handler_info *next_sci_handler;
476 acpi_cpu_flags flags;
477 acpi_status status;
478
479 ACPI_FUNCTION_TRACE(acpi_remove_sci_handler);
480
481 if (!address) {
482 return_ACPI_STATUS(AE_BAD_PARAMETER);
483 }
484
485 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
486 if (ACPI_FAILURE(status)) {
487 return_ACPI_STATUS(status);
488 }
489
490 /* Remove the SCI handler with lock */
491
492 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
493
494 prev_sci_handler = NULL;
495 next_sci_handler = acpi_gbl_sci_handler_list;
496 while (next_sci_handler) {
497 if (next_sci_handler->address == address) {
498
499 /* Unlink and free the SCI handler info block */
500
501 if (prev_sci_handler) {
502 prev_sci_handler->next = next_sci_handler->next;
503 } else {
504 acpi_gbl_sci_handler_list =
505 next_sci_handler->next;
506 }
507
508 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
509 ACPI_FREE(next_sci_handler);
510 goto unlock_and_exit;
511 }
512
513 prev_sci_handler = next_sci_handler;
514 next_sci_handler = next_sci_handler->next;
515 }
516
517 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
518 status = AE_NOT_EXIST;
519
520unlock_and_exit:
521 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
522 return_ACPI_STATUS(status);
523}
524
525/*******************************************************************************
526 *
388 * FUNCTION: acpi_install_global_event_handler 527 * FUNCTION: acpi_install_global_event_handler
389 * 528 *
390 * PARAMETERS: handler - Pointer to the global event handler function 529 * PARAMETERS: handler - Pointer to the global event handler function
@@ -398,6 +537,7 @@ ACPI_EXPORT_SYMBOL(acpi_install_exception_handler)
398 * Can be used to update event counters, etc. 537 * Can be used to update event counters, etc.
399 * 538 *
400 ******************************************************************************/ 539 ******************************************************************************/
540
401acpi_status 541acpi_status
402acpi_install_global_event_handler(acpi_gbl_event_handler handler, void *context) 542acpi_install_global_event_handler(acpi_gbl_event_handler handler, void *context)
403{ 543{
@@ -426,7 +566,7 @@ acpi_install_global_event_handler(acpi_gbl_event_handler handler, void *context)
426 acpi_gbl_global_event_handler = handler; 566 acpi_gbl_global_event_handler = handler;
427 acpi_gbl_global_event_handler_context = context; 567 acpi_gbl_global_event_handler_context = context;
428 568
429 cleanup: 569cleanup:
430 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); 570 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
431 return_ACPI_STATUS(status); 571 return_ACPI_STATUS(status);
432} 572}
@@ -498,7 +638,7 @@ acpi_install_fixed_event_handler(u32 event,
498 handler)); 638 handler));
499 } 639 }
500 640
501 cleanup: 641cleanup:
502 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); 642 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
503 return_ACPI_STATUS(status); 643 return_ACPI_STATUS(status);
504} 644}
diff --git a/drivers/acpi/acpica/evxfevnt.c b/drivers/acpi/acpica/evxfevnt.c
index 7039606a0ba8..39d06af5e347 100644
--- a/drivers/acpi/acpica/evxfevnt.c
+++ b/drivers/acpi/acpica/evxfevnt.c
@@ -41,7 +41,8 @@
41 * POSSIBILITY OF SUCH DAMAGES. 41 * POSSIBILITY OF SUCH DAMAGES.
42 */ 42 */
43 43
44#include <linux/export.h> 44#define EXPORT_ACPI_INTERFACES
45
45#include <acpi/acpi.h> 46#include <acpi/acpi.h>
46#include "accommon.h" 47#include "accommon.h"
47#include "actables.h" 48#include "actables.h"
diff --git a/drivers/acpi/acpica/evxfgpe.c b/drivers/acpi/acpica/evxfgpe.c
index 7662f1a42ff6..5713da77c665 100644
--- a/drivers/acpi/acpica/evxfgpe.c
+++ b/drivers/acpi/acpica/evxfgpe.c
@@ -41,7 +41,8 @@
41 * POSSIBILITY OF SUCH DAMAGES. 41 * POSSIBILITY OF SUCH DAMAGES.
42 */ 42 */
43 43
44#include <linux/export.h> 44#define EXPORT_ACPI_INTERFACES
45
45#include <acpi/acpi.h> 46#include <acpi/acpi.h>
46#include "accommon.h" 47#include "accommon.h"
47#include "acevents.h" 48#include "acevents.h"
@@ -471,7 +472,7 @@ acpi_get_gpe_status(acpi_handle gpe_device,
471 if (gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) 472 if (gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK)
472 *event_status |= ACPI_EVENT_FLAG_HANDLE; 473 *event_status |= ACPI_EVENT_FLAG_HANDLE;
473 474
474 unlock_and_exit: 475unlock_and_exit:
475 acpi_os_release_lock(acpi_gbl_gpe_lock, flags); 476 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
476 return_ACPI_STATUS(status); 477 return_ACPI_STATUS(status);
477} 478}
@@ -624,7 +625,7 @@ acpi_install_gpe_block(acpi_handle gpe_device,
624 625
625 obj_desc->device.gpe_block = gpe_block; 626 obj_desc->device.gpe_block = gpe_block;
626 627
627 unlock_and_exit: 628unlock_and_exit:
628 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); 629 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
629 return_ACPI_STATUS(status); 630 return_ACPI_STATUS(status);
630} 631}
@@ -679,7 +680,7 @@ acpi_status acpi_remove_gpe_block(acpi_handle gpe_device)
679 obj_desc->device.gpe_block = NULL; 680 obj_desc->device.gpe_block = NULL;
680 } 681 }
681 682
682 unlock_and_exit: 683unlock_and_exit:
683 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); 684 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
684 return_ACPI_STATUS(status); 685 return_ACPI_STATUS(status);
685} 686}
diff --git a/drivers/acpi/acpica/evxfregn.c b/drivers/acpi/acpica/evxfregn.c
index 80cecf838591..02ed75ac56cd 100644
--- a/drivers/acpi/acpica/evxfregn.c
+++ b/drivers/acpi/acpica/evxfregn.c
@@ -42,7 +42,8 @@
42 * POSSIBILITY OF SUCH DAMAGES. 42 * POSSIBILITY OF SUCH DAMAGES.
43 */ 43 */
44 44
45#include <linux/export.h> 45#define EXPORT_ACPI_INTERFACES
46
46#include <acpi/acpi.h> 47#include <acpi/acpi.h>
47#include "accommon.h" 48#include "accommon.h"
48#include "acnamesp.h" 49#include "acnamesp.h"
@@ -147,7 +148,7 @@ acpi_install_address_space_handler(acpi_handle device,
147 148
148 status = acpi_ev_execute_reg_methods(node, space_id); 149 status = acpi_ev_execute_reg_methods(node, space_id);
149 150
150 unlock_and_exit: 151unlock_and_exit:
151 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); 152 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
152 return_ACPI_STATUS(status); 153 return_ACPI_STATUS(status);
153} 154}
@@ -286,7 +287,7 @@ acpi_remove_address_space_handler(acpi_handle device,
286 287
287 status = AE_NOT_EXIST; 288 status = AE_NOT_EXIST;
288 289
289 unlock_and_exit: 290unlock_and_exit:
290 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); 291 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
291 return_ACPI_STATUS(status); 292 return_ACPI_STATUS(status);
292} 293}
diff --git a/drivers/acpi/acpica/excreate.c b/drivers/acpi/acpica/excreate.c
index 269e81d86ef4..3c2e6dcdad3e 100644
--- a/drivers/acpi/acpica/excreate.c
+++ b/drivers/acpi/acpica/excreate.c
@@ -193,7 +193,7 @@ acpi_status acpi_ex_create_event(struct acpi_walk_state *walk_state)
193 acpi_ns_attach_object((struct acpi_namespace_node *)walk_state-> 193 acpi_ns_attach_object((struct acpi_namespace_node *)walk_state->
194 operands[0], obj_desc, ACPI_TYPE_EVENT); 194 operands[0], obj_desc, ACPI_TYPE_EVENT);
195 195
196 cleanup: 196cleanup:
197 /* 197 /*
198 * Remove local reference to the object (on error, will cause deletion 198 * Remove local reference to the object (on error, will cause deletion
199 * of both object and semaphore if present.) 199 * of both object and semaphore if present.)
@@ -248,7 +248,7 @@ acpi_status acpi_ex_create_mutex(struct acpi_walk_state *walk_state)
248 acpi_ns_attach_object(obj_desc->mutex.node, obj_desc, 248 acpi_ns_attach_object(obj_desc->mutex.node, obj_desc,
249 ACPI_TYPE_MUTEX); 249 ACPI_TYPE_MUTEX);
250 250
251 cleanup: 251cleanup:
252 /* 252 /*
253 * Remove local reference to the object (on error, will cause deletion 253 * Remove local reference to the object (on error, will cause deletion
254 * of both object and semaphore if present.) 254 * of both object and semaphore if present.)
@@ -347,7 +347,7 @@ acpi_ex_create_region(u8 * aml_start,
347 347
348 status = acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_REGION); 348 status = acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_REGION);
349 349
350 cleanup: 350cleanup:
351 351
352 /* Remove local reference to the object */ 352 /* Remove local reference to the object */
353 353
@@ -520,7 +520,7 @@ acpi_ex_create_method(u8 * aml_start,
520 520
521 acpi_ut_remove_reference(obj_desc); 521 acpi_ut_remove_reference(obj_desc);
522 522
523 exit: 523exit:
524 /* Remove a reference to the operand */ 524 /* Remove a reference to the operand */
525 525
526 acpi_ut_remove_reference(operand[1]); 526 acpi_ut_remove_reference(operand[1]);
diff --git a/drivers/acpi/acpica/exfield.c b/drivers/acpi/acpica/exfield.c
index c2a65aaf29af..cfd875243421 100644
--- a/drivers/acpi/acpica/exfield.c
+++ b/drivers/acpi/acpica/exfield.c
@@ -197,7 +197,7 @@ acpi_ex_read_data_from_field(struct acpi_walk_state *walk_state,
197 status = acpi_ex_extract_from_field(obj_desc, buffer, (u32) length); 197 status = acpi_ex_extract_from_field(obj_desc, buffer, (u32) length);
198 acpi_ex_release_global_lock(obj_desc->common_field.field_flags); 198 acpi_ex_release_global_lock(obj_desc->common_field.field_flags);
199 199
200 exit: 200exit:
201 if (ACPI_FAILURE(status)) { 201 if (ACPI_FAILURE(status)) {
202 acpi_ut_remove_reference(buffer_desc); 202 acpi_ut_remove_reference(buffer_desc);
203 } else { 203 } else {
diff --git a/drivers/acpi/acpica/exfldio.c b/drivers/acpi/acpica/exfldio.c
index 7e0afe72487e..49fb742d61b9 100644
--- a/drivers/acpi/acpica/exfldio.c
+++ b/drivers/acpi/acpica/exfldio.c
@@ -123,12 +123,6 @@ acpi_ex_setup_region(union acpi_operand_object *obj_desc,
123 } 123 }
124 } 124 }
125 125
126 /* Exit if Address/Length have been disallowed by the host OS */
127
128 if (rgn_desc->common.flags & AOPOBJ_INVALID) {
129 return_ACPI_STATUS(AE_AML_ILLEGAL_ADDRESS);
130 }
131
132 /* 126 /*
133 * Exit now for SMBus, GSBus or IPMI address space, it has a non-linear 127 * Exit now for SMBus, GSBus or IPMI address space, it has a non-linear
134 * address space and the request cannot be directly validated 128 * address space and the request cannot be directly validated
@@ -1002,7 +996,7 @@ acpi_ex_insert_into_field(union acpi_operand_object *obj_desc,
1002 mask, merged_datum, 996 mask, merged_datum,
1003 field_offset); 997 field_offset);
1004 998
1005 exit: 999exit:
1006 /* Free temporary buffer if we used one */ 1000 /* Free temporary buffer if we used one */
1007 1001
1008 if (new_buffer) { 1002 if (new_buffer) {
diff --git a/drivers/acpi/acpica/exmisc.c b/drivers/acpi/acpica/exmisc.c
index 00bf29877574..65d93607f368 100644
--- a/drivers/acpi/acpica/exmisc.c
+++ b/drivers/acpi/acpica/exmisc.c
@@ -388,7 +388,7 @@ acpi_ex_do_concatenate(union acpi_operand_object *operand0,
388 388
389 *actual_return_desc = return_desc; 389 *actual_return_desc = return_desc;
390 390
391 cleanup: 391cleanup:
392 if (local_operand1 != operand1) { 392 if (local_operand1 != operand1) {
393 acpi_ut_remove_reference(local_operand1); 393 acpi_ut_remove_reference(local_operand1);
394 } 394 }
@@ -718,7 +718,7 @@ acpi_ex_do_logical_op(u16 opcode,
718 } 718 }
719 } 719 }
720 720
721 cleanup: 721cleanup:
722 722
723 /* New object was created if implicit conversion performed - delete */ 723 /* New object was created if implicit conversion performed - delete */
724 724
diff --git a/drivers/acpi/acpica/exoparg1.c b/drivers/acpi/acpica/exoparg1.c
index 2cdd41d8ade6..d74cea416ca0 100644
--- a/drivers/acpi/acpica/exoparg1.c
+++ b/drivers/acpi/acpica/exoparg1.c
@@ -115,7 +115,7 @@ acpi_status acpi_ex_opcode_0A_0T_1R(struct acpi_walk_state *walk_state)
115 break; 115 break;
116 } 116 }
117 117
118 cleanup: 118cleanup:
119 119
120 /* Delete return object on error */ 120 /* Delete return object on error */
121 121
@@ -234,7 +234,7 @@ acpi_status acpi_ex_opcode_1A_1T_0R(struct acpi_walk_state *walk_state)
234 goto cleanup; 234 goto cleanup;
235 } 235 }
236 236
237 cleanup: 237cleanup:
238 238
239 return_ACPI_STATUS(status); 239 return_ACPI_STATUS(status);
240} 240}
@@ -551,7 +551,7 @@ acpi_status acpi_ex_opcode_1A_1T_1R(struct acpi_walk_state *walk_state)
551 status = acpi_ex_store(return_desc, operand[1], walk_state); 551 status = acpi_ex_store(return_desc, operand[1], walk_state);
552 } 552 }
553 553
554 cleanup: 554cleanup:
555 555
556 /* Delete return object on error */ 556 /* Delete return object on error */
557 557
@@ -1054,7 +1054,7 @@ acpi_status acpi_ex_opcode_1A_0T_1R(struct acpi_walk_state *walk_state)
1054 goto cleanup; 1054 goto cleanup;
1055 } 1055 }
1056 1056
1057 cleanup: 1057cleanup:
1058 1058
1059 /* Delete return object on error */ 1059 /* Delete return object on error */
1060 1060
diff --git a/drivers/acpi/acpica/exoparg2.c b/drivers/acpi/acpica/exoparg2.c
index d5088f7030c7..d6fa0fce1fc9 100644
--- a/drivers/acpi/acpica/exoparg2.c
+++ b/drivers/acpi/acpica/exoparg2.c
@@ -215,7 +215,7 @@ acpi_status acpi_ex_opcode_2A_2T_1R(struct acpi_walk_state *walk_state)
215 goto cleanup; 215 goto cleanup;
216 } 216 }
217 217
218 cleanup: 218cleanup:
219 /* 219 /*
220 * Since the remainder is not returned indirectly, remove a reference to 220 * Since the remainder is not returned indirectly, remove a reference to
221 * it. Only the quotient is returned indirectly. 221 * it. Only the quotient is returned indirectly.
@@ -445,7 +445,7 @@ acpi_status acpi_ex_opcode_2A_1T_1R(struct acpi_walk_state *walk_state)
445 break; 445 break;
446 } 446 }
447 447
448 store_result_to_target: 448store_result_to_target:
449 449
450 if (ACPI_SUCCESS(status)) { 450 if (ACPI_SUCCESS(status)) {
451 /* 451 /*
@@ -462,7 +462,7 @@ acpi_status acpi_ex_opcode_2A_1T_1R(struct acpi_walk_state *walk_state)
462 } 462 }
463 } 463 }
464 464
465 cleanup: 465cleanup:
466 466
467 /* Delete return object on error */ 467 /* Delete return object on error */
468 468
@@ -553,7 +553,7 @@ acpi_status acpi_ex_opcode_2A_0T_1R(struct acpi_walk_state *walk_state)
553 goto cleanup; 553 goto cleanup;
554 } 554 }
555 555
556 store_logical_result: 556store_logical_result:
557 /* 557 /*
558 * Set return value to according to logical_result. logical TRUE (all ones) 558 * Set return value to according to logical_result. logical TRUE (all ones)
559 * Default is FALSE (zero) 559 * Default is FALSE (zero)
@@ -562,7 +562,7 @@ acpi_status acpi_ex_opcode_2A_0T_1R(struct acpi_walk_state *walk_state)
562 return_desc->integer.value = ACPI_UINT64_MAX; 562 return_desc->integer.value = ACPI_UINT64_MAX;
563 } 563 }
564 564
565 cleanup: 565cleanup:
566 566
567 /* Delete return object on error */ 567 /* Delete return object on error */
568 568
diff --git a/drivers/acpi/acpica/exoparg3.c b/drivers/acpi/acpica/exoparg3.c
index 37656f12f204..bc042adf8804 100644
--- a/drivers/acpi/acpica/exoparg3.c
+++ b/drivers/acpi/acpica/exoparg3.c
@@ -124,7 +124,7 @@ acpi_status acpi_ex_opcode_3A_0T_0R(struct acpi_walk_state *walk_state)
124 goto cleanup; 124 goto cleanup;
125 } 125 }
126 126
127 cleanup: 127cleanup:
128 128
129 return_ACPI_STATUS(status); 129 return_ACPI_STATUS(status);
130} 130}
@@ -252,7 +252,7 @@ acpi_status acpi_ex_opcode_3A_1T_1R(struct acpi_walk_state *walk_state)
252 252
253 status = acpi_ex_store(return_desc, operand[3], walk_state); 253 status = acpi_ex_store(return_desc, operand[3], walk_state);
254 254
255 cleanup: 255cleanup:
256 256
257 /* Delete return object on error */ 257 /* Delete return object on error */
258 258
diff --git a/drivers/acpi/acpica/exoparg6.c b/drivers/acpi/acpica/exoparg6.c
index 879b6cd8319c..4459e32c683d 100644
--- a/drivers/acpi/acpica/exoparg6.c
+++ b/drivers/acpi/acpica/exoparg6.c
@@ -314,7 +314,7 @@ acpi_status acpi_ex_opcode_6A_0T_1R(struct acpi_walk_state * walk_state)
314 goto cleanup; 314 goto cleanup;
315 } 315 }
316 316
317 cleanup: 317cleanup:
318 318
319 /* Delete return object on error */ 319 /* Delete return object on error */
320 320
diff --git a/drivers/acpi/acpica/exregion.c b/drivers/acpi/acpica/exregion.c
index 303429bb4d5d..9d28867e60dc 100644
--- a/drivers/acpi/acpica/exregion.c
+++ b/drivers/acpi/acpica/exregion.c
@@ -400,6 +400,7 @@ acpi_ex_pci_config_space_handler(u32 function,
400 switch (function) { 400 switch (function) {
401 case ACPI_READ: 401 case ACPI_READ:
402 402
403 *value = 0;
403 status = acpi_os_read_pci_configuration(pci_id, pci_register, 404 status = acpi_os_read_pci_configuration(pci_id, pci_register,
404 value, bit_width); 405 value, bit_width);
405 break; 406 break;
diff --git a/drivers/acpi/acpica/exresolv.c b/drivers/acpi/acpica/exresolv.c
index ac04278ad28f..1606524312e3 100644
--- a/drivers/acpi/acpica/exresolv.c
+++ b/drivers/acpi/acpica/exresolv.c
@@ -521,7 +521,7 @@ acpi_ex_resolve_multiple(struct acpi_walk_state *walk_state,
521 */ 521 */
522 type = obj_desc->common.type; 522 type = obj_desc->common.type;
523 523
524 exit: 524exit:
525 /* Convert internal types to external types */ 525 /* Convert internal types to external types */
526 526
527 switch (type) { 527 switch (type) {
diff --git a/drivers/acpi/acpica/exresop.c b/drivers/acpi/acpica/exresop.c
index 00e5af7129c1..be3f66973ee8 100644
--- a/drivers/acpi/acpica/exresop.c
+++ b/drivers/acpi/acpica/exresop.c
@@ -683,7 +683,7 @@ acpi_ex_resolve_operands(u16 opcode,
683 return_ACPI_STATUS(status); 683 return_ACPI_STATUS(status);
684 } 684 }
685 685
686 next_operand: 686next_operand:
687 /* 687 /*
688 * If more operands needed, decrement stack_ptr to point 688 * If more operands needed, decrement stack_ptr to point
689 * to next operand on stack 689 * to next operand on stack
diff --git a/drivers/acpi/acpica/hwregs.c b/drivers/acpi/acpica/hwregs.c
index 8d2e866be15f..12e6cff54f78 100644
--- a/drivers/acpi/acpica/hwregs.c
+++ b/drivers/acpi/acpica/hwregs.c
@@ -560,7 +560,7 @@ acpi_status acpi_hw_register_write(u32 register_id, u32 value)
560 break; 560 break;
561 } 561 }
562 562
563 exit: 563exit:
564 return_ACPI_STATUS(status); 564 return_ACPI_STATUS(status);
565} 565}
566 566
diff --git a/drivers/acpi/acpica/hwtimer.c b/drivers/acpi/acpica/hwtimer.c
index 2d7d22ebc782..3c498dc1636e 100644
--- a/drivers/acpi/acpica/hwtimer.c
+++ b/drivers/acpi/acpica/hwtimer.c
@@ -41,7 +41,8 @@
41 * POSSIBILITY OF SUCH DAMAGES. 41 * POSSIBILITY OF SUCH DAMAGES.
42 */ 42 */
43 43
44#include <linux/export.h> 44#define EXPORT_ACPI_INTERFACES
45
45#include <acpi/acpi.h> 46#include <acpi/acpi.h>
46#include "accommon.h" 47#include "accommon.h"
47 48
diff --git a/drivers/acpi/acpica/hwxface.c b/drivers/acpi/acpica/hwxface.c
index 5ee7a814cd92..b4b47db2dee2 100644
--- a/drivers/acpi/acpica/hwxface.c
+++ b/drivers/acpi/acpica/hwxface.c
@@ -41,7 +41,8 @@
41 * POSSIBILITY OF SUCH DAMAGES. 41 * POSSIBILITY OF SUCH DAMAGES.
42 */ 42 */
43 43
44#include <linux/export.h> 44#define EXPORT_ACPI_INTERFACES
45
45#include <acpi/acpi.h> 46#include <acpi/acpi.h>
46#include "accommon.h" 47#include "accommon.h"
47#include "acnamesp.h" 48#include "acnamesp.h"
@@ -83,11 +84,17 @@ acpi_status acpi_reset(void)
83 * For I/O space, write directly to the OSL. This bypasses the port 84 * For I/O space, write directly to the OSL. This bypasses the port
84 * validation mechanism, which may block a valid write to the reset 85 * validation mechanism, which may block a valid write to the reset
85 * register. 86 * register.
86 * Spec section 4.7.3.6 requires register width to be 8. 87 *
88 * NOTE:
89 * The ACPI spec requires the reset register width to be 8, so we
90 * hardcode it here and ignore the FADT value. This maintains
91 * compatibility with other ACPI implementations that have allowed
92 * BIOS code with bad register width values to go unnoticed.
87 */ 93 */
88 status = 94 status =
89 acpi_os_write_port((acpi_io_address) reset_reg->address, 95 acpi_os_write_port((acpi_io_address) reset_reg->address,
90 acpi_gbl_FADT.reset_value, 8); 96 acpi_gbl_FADT.reset_value,
97 ACPI_RESET_REGISTER_WIDTH);
91 } else { 98 } else {
92 /* Write the reset value to the reset register */ 99 /* Write the reset value to the reset register */
93 100
@@ -119,7 +126,8 @@ ACPI_EXPORT_SYMBOL(acpi_reset)
119 ******************************************************************************/ 126 ******************************************************************************/
120acpi_status acpi_read(u64 *return_value, struct acpi_generic_address *reg) 127acpi_status acpi_read(u64 *return_value, struct acpi_generic_address *reg)
121{ 128{
122 u32 value; 129 u32 value_lo;
130 u32 value_hi;
123 u32 width; 131 u32 width;
124 u64 address; 132 u64 address;
125 acpi_status status; 133 acpi_status status;
@@ -137,13 +145,8 @@ acpi_status acpi_read(u64 *return_value, struct acpi_generic_address *reg)
137 return (status); 145 return (status);
138 } 146 }
139 147
140 /* Initialize entire 64-bit return value to zero */
141
142 *return_value = 0;
143 value = 0;
144
145 /* 148 /*
146 * Two address spaces supported: Memory or IO. PCI_Config is 149 * Two address spaces supported: Memory or I/O. PCI_Config is
147 * not supported here because the GAS structure is insufficient 150 * not supported here because the GAS structure is insufficient
148 */ 151 */
149 if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) { 152 if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) {
@@ -155,29 +158,35 @@ acpi_status acpi_read(u64 *return_value, struct acpi_generic_address *reg)
155 } 158 }
156 } else { /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */ 159 } else { /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */
157 160
161 value_lo = 0;
162 value_hi = 0;
163
158 width = reg->bit_width; 164 width = reg->bit_width;
159 if (width == 64) { 165 if (width == 64) {
160 width = 32; /* Break into two 32-bit transfers */ 166 width = 32; /* Break into two 32-bit transfers */
161 } 167 }
162 168
163 status = acpi_hw_read_port((acpi_io_address) 169 status = acpi_hw_read_port((acpi_io_address)
164 address, &value, width); 170 address, &value_lo, width);
165 if (ACPI_FAILURE(status)) { 171 if (ACPI_FAILURE(status)) {
166 return (status); 172 return (status);
167 } 173 }
168 *return_value = value;
169 174
170 if (reg->bit_width == 64) { 175 if (reg->bit_width == 64) {
171 176
172 /* Read the top 32 bits */ 177 /* Read the top 32 bits */
173 178
174 status = acpi_hw_read_port((acpi_io_address) 179 status = acpi_hw_read_port((acpi_io_address)
175 (address + 4), &value, 32); 180 (address + 4), &value_hi,
181 32);
176 if (ACPI_FAILURE(status)) { 182 if (ACPI_FAILURE(status)) {
177 return (status); 183 return (status);
178 } 184 }
179 *return_value |= ((u64)value << 32);
180 } 185 }
186
187 /* Set the return value only if status is AE_OK */
188
189 *return_value = (value_lo | ((u64)value_hi << 32));
181 } 190 }
182 191
183 ACPI_DEBUG_PRINT((ACPI_DB_IO, 192 ACPI_DEBUG_PRINT((ACPI_DB_IO,
@@ -186,7 +195,7 @@ acpi_status acpi_read(u64 *return_value, struct acpi_generic_address *reg)
186 ACPI_FORMAT_UINT64(address), 195 ACPI_FORMAT_UINT64(address),
187 acpi_ut_get_region_name(reg->space_id))); 196 acpi_ut_get_region_name(reg->space_id)));
188 197
189 return (status); 198 return (AE_OK);
190} 199}
191 200
192ACPI_EXPORT_SYMBOL(acpi_read) 201ACPI_EXPORT_SYMBOL(acpi_read)
@@ -561,10 +570,10 @@ acpi_get_sleep_type_data(u8 sleep_state, u8 *sleep_type_a, u8 *sleep_type_b)
561 break; 570 break;
562 } 571 }
563 572
564 cleanup1: 573cleanup1:
565 acpi_ut_remove_reference(info->return_object); 574 acpi_ut_remove_reference(info->return_object);
566 575
567 cleanup: 576cleanup:
568 if (ACPI_FAILURE(status)) { 577 if (ACPI_FAILURE(status)) {
569 ACPI_EXCEPTION((AE_INFO, status, 578 ACPI_EXCEPTION((AE_INFO, status,
570 "While evaluating Sleep State [%s]", 579 "While evaluating Sleep State [%s]",
diff --git a/drivers/acpi/acpica/hwxfsleep.c b/drivers/acpi/acpica/hwxfsleep.c
index f2e669db8b65..15dddc10fc9b 100644
--- a/drivers/acpi/acpica/hwxfsleep.c
+++ b/drivers/acpi/acpica/hwxfsleep.c
@@ -41,7 +41,8 @@
41 * POSSIBILITY OF SUCH DAMAGES. 41 * POSSIBILITY OF SUCH DAMAGES.
42 */ 42 */
43 43
44#include <linux/export.h> 44#define EXPORT_ACPI_INTERFACES
45
45#include <acpi/acpi.h> 46#include <acpi/acpi.h>
46#include "accommon.h" 47#include "accommon.h"
47 48
@@ -166,7 +167,7 @@ ACPI_EXPORT_SYMBOL(acpi_set_firmware_waking_vector64)
166 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED 167 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED
167 * 168 *
168 ******************************************************************************/ 169 ******************************************************************************/
169acpi_status asmlinkage acpi_enter_sleep_state_s4bios(void) 170acpi_status acpi_enter_sleep_state_s4bios(void)
170{ 171{
171 u32 in_value; 172 u32 in_value;
172 acpi_status status; 173 acpi_status status;
@@ -360,7 +361,7 @@ ACPI_EXPORT_SYMBOL(acpi_enter_sleep_state_prep)
360 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED 361 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED
361 * 362 *
362 ******************************************************************************/ 363 ******************************************************************************/
363acpi_status asmlinkage acpi_enter_sleep_state(u8 sleep_state) 364acpi_status acpi_enter_sleep_state(u8 sleep_state)
364{ 365{
365 acpi_status status; 366 acpi_status status;
366 367
diff --git a/drivers/acpi/acpica/nsaccess.c b/drivers/acpi/acpica/nsaccess.c
index c5316e5bd4ab..14f65f6345b9 100644
--- a/drivers/acpi/acpica/nsaccess.c
+++ b/drivers/acpi/acpica/nsaccess.c
@@ -240,7 +240,7 @@ acpi_status acpi_ns_root_initialize(void)
240 } 240 }
241 } 241 }
242 242
243 unlock_and_exit: 243unlock_and_exit:
244 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); 244 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
245 245
246 /* Save a handle to "_GPE", it is always present */ 246 /* Save a handle to "_GPE", it is always present */
@@ -424,8 +424,9 @@ acpi_ns_lookup(union acpi_generic_state *scope_info,
424 /* Current scope has no parent scope */ 424 /* Current scope has no parent scope */
425 425
426 ACPI_ERROR((AE_INFO, 426 ACPI_ERROR((AE_INFO,
427 "ACPI path has too many parent prefixes (^) " 427 "%s: Path has too many parent prefixes (^) "
428 "- reached beyond root node")); 428 "- reached beyond root node",
429 pathname));
429 return_ACPI_STATUS(AE_NOT_FOUND); 430 return_ACPI_STATUS(AE_NOT_FOUND);
430 } 431 }
431 } 432 }
diff --git a/drivers/acpi/acpica/nsdump.c b/drivers/acpi/acpica/nsdump.c
index 7418c77fde8c..48b9c6f12643 100644
--- a/drivers/acpi/acpica/nsdump.c
+++ b/drivers/acpi/acpica/nsdump.c
@@ -59,6 +59,17 @@ acpi_ns_dump_one_device(acpi_handle obj_handle,
59#endif 59#endif
60 60
61#if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER) 61#if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER)
62
63#ifdef ACPI_FUTURE_USAGE
64static acpi_status
65acpi_ns_dump_one_object_path(acpi_handle obj_handle,
66 u32 level, void *context, void **return_value);
67
68static acpi_status
69acpi_ns_get_max_depth(acpi_handle obj_handle,
70 u32 level, void *context, void **return_value);
71#endif /* ACPI_FUTURE_USAGE */
72
62/******************************************************************************* 73/*******************************************************************************
63 * 74 *
64 * FUNCTION: acpi_ns_print_pathname 75 * FUNCTION: acpi_ns_print_pathname
@@ -609,7 +620,7 @@ acpi_ns_dump_one_object(acpi_handle obj_handle,
609 obj_type = ACPI_TYPE_INVALID; /* Terminate loop after next pass */ 620 obj_type = ACPI_TYPE_INVALID; /* Terminate loop after next pass */
610 } 621 }
611 622
612 cleanup: 623cleanup:
613 acpi_os_printf("\n"); 624 acpi_os_printf("\n");
614 return (AE_OK); 625 return (AE_OK);
615} 626}
@@ -671,6 +682,136 @@ acpi_ns_dump_objects(acpi_object_type type,
671} 682}
672#endif /* ACPI_FUTURE_USAGE */ 683#endif /* ACPI_FUTURE_USAGE */
673 684
685#ifdef ACPI_FUTURE_USAGE
686/*******************************************************************************
687 *
688 * FUNCTION: acpi_ns_dump_one_object_path, acpi_ns_get_max_depth
689 *
690 * PARAMETERS: obj_handle - Node to be dumped
691 * level - Nesting level of the handle
692 * context - Passed into walk_namespace
693 * return_value - Not used
694 *
695 * RETURN: Status
696 *
697 * DESCRIPTION: Dump the full pathname to a namespace object. acp_ns_get_max_depth
698 * computes the maximum nesting depth in the namespace tree, in
699 * order to simplify formatting in acpi_ns_dump_one_object_path.
700 * These procedures are user_functions called by acpi_ns_walk_namespace.
701 *
702 ******************************************************************************/
703
704static acpi_status
705acpi_ns_dump_one_object_path(acpi_handle obj_handle,
706 u32 level, void *context, void **return_value)
707{
708 u32 max_level = *((u32 *)context);
709 char *pathname;
710 struct acpi_namespace_node *node;
711 int path_indent;
712
713 if (!obj_handle) {
714 return (AE_OK);
715 }
716
717 node = acpi_ns_validate_handle(obj_handle);
718 if (!node) {
719
720 /* Ignore bad node during namespace walk */
721
722 return (AE_OK);
723 }
724
725 pathname = acpi_ns_get_external_pathname(node);
726
727 path_indent = 1;
728 if (level <= max_level) {
729 path_indent = max_level - level + 1;
730 }
731
732 acpi_os_printf("%2d%*s%-12s%*s",
733 level, level, " ", acpi_ut_get_type_name(node->type),
734 path_indent, " ");
735
736 acpi_os_printf("%s\n", &pathname[1]);
737 ACPI_FREE(pathname);
738 return (AE_OK);
739}
740
741static acpi_status
742acpi_ns_get_max_depth(acpi_handle obj_handle,
743 u32 level, void *context, void **return_value)
744{
745 u32 *max_level = (u32 *)context;
746
747 if (level > *max_level) {
748 *max_level = level;
749 }
750 return (AE_OK);
751}
752
753/*******************************************************************************
754 *
755 * FUNCTION: acpi_ns_dump_object_paths
756 *
757 * PARAMETERS: type - Object type to be dumped
758 * display_type - 0 or ACPI_DISPLAY_SUMMARY
759 * max_depth - Maximum depth of dump. Use ACPI_UINT32_MAX
760 * for an effectively unlimited depth.
761 * owner_id - Dump only objects owned by this ID. Use
762 * ACPI_UINT32_MAX to match all owners.
763 * start_handle - Where in namespace to start/end search
764 *
765 * RETURN: None
766 *
767 * DESCRIPTION: Dump full object pathnames within the loaded namespace. Uses
768 * acpi_ns_walk_namespace in conjunction with acpi_ns_dump_one_object_path.
769 *
770 ******************************************************************************/
771
772void
773acpi_ns_dump_object_paths(acpi_object_type type,
774 u8 display_type,
775 u32 max_depth,
776 acpi_owner_id owner_id, acpi_handle start_handle)
777{
778 acpi_status status;
779 u32 max_level = 0;
780
781 ACPI_FUNCTION_ENTRY();
782
783 /*
784 * Just lock the entire namespace for the duration of the dump.
785 * We don't want any changes to the namespace during this time,
786 * especially the temporary nodes since we are going to display
787 * them also.
788 */
789 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
790 if (ACPI_FAILURE(status)) {
791 acpi_os_printf("Could not acquire namespace mutex\n");
792 return;
793 }
794
795 /* Get the max depth of the namespace tree, for formatting later */
796
797 (void)acpi_ns_walk_namespace(type, start_handle, max_depth,
798 ACPI_NS_WALK_NO_UNLOCK |
799 ACPI_NS_WALK_TEMP_NODES,
800 acpi_ns_get_max_depth, NULL,
801 (void *)&max_level, NULL);
802
803 /* Now dump the entire namespace */
804
805 (void)acpi_ns_walk_namespace(type, start_handle, max_depth,
806 ACPI_NS_WALK_NO_UNLOCK |
807 ACPI_NS_WALK_TEMP_NODES,
808 acpi_ns_dump_one_object_path, NULL,
809 (void *)&max_level, NULL);
810
811 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
812}
813#endif /* ACPI_FUTURE_USAGE */
814
674/******************************************************************************* 815/*******************************************************************************
675 * 816 *
676 * FUNCTION: acpi_ns_dump_entry 817 * FUNCTION: acpi_ns_dump_entry
diff --git a/drivers/acpi/acpica/nsdumpdv.c b/drivers/acpi/acpica/nsdumpdv.c
index 409ae80824d1..283762511b73 100644
--- a/drivers/acpi/acpica/nsdumpdv.c
+++ b/drivers/acpi/acpica/nsdumpdv.c
@@ -69,6 +69,7 @@ static acpi_status
69acpi_ns_dump_one_device(acpi_handle obj_handle, 69acpi_ns_dump_one_device(acpi_handle obj_handle,
70 u32 level, void *context, void **return_value) 70 u32 level, void *context, void **return_value)
71{ 71{
72 struct acpi_buffer buffer;
72 struct acpi_device_info *info; 73 struct acpi_device_info *info;
73 acpi_status status; 74 acpi_status status;
74 u32 i; 75 u32 i;
@@ -78,15 +79,17 @@ acpi_ns_dump_one_device(acpi_handle obj_handle,
78 status = 79 status =
79 acpi_ns_dump_one_object(obj_handle, level, context, return_value); 80 acpi_ns_dump_one_object(obj_handle, level, context, return_value);
80 81
81 status = acpi_get_object_info(obj_handle, &info); 82 buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER;
83 status = acpi_get_object_info(obj_handle, &buffer);
82 if (ACPI_SUCCESS(status)) { 84 if (ACPI_SUCCESS(status)) {
85 info = buffer.pointer;
83 for (i = 0; i < level; i++) { 86 for (i = 0; i < level; i++) {
84 ACPI_DEBUG_PRINT_RAW((ACPI_DB_TABLES, " ")); 87 ACPI_DEBUG_PRINT_RAW((ACPI_DB_TABLES, " "));
85 } 88 }
86 89
87 ACPI_DEBUG_PRINT_RAW((ACPI_DB_TABLES, 90 ACPI_DEBUG_PRINT_RAW((ACPI_DB_TABLES,
88 " HID: %s, ADR: %8.8X%8.8X, Status: %X\n", 91 " HID: %s, ADR: %8.8X%8.8X, Status: %X\n",
89 info->hardware_id.string, 92 info->hardware_id.value,
90 ACPI_FORMAT_UINT64(info->address), 93 ACPI_FORMAT_UINT64(info->address),
91 info->current_status)); 94 info->current_status));
92 ACPI_FREE(info); 95 ACPI_FREE(info);
diff --git a/drivers/acpi/acpica/nseval.c b/drivers/acpi/acpica/nseval.c
index 18108bc2e51c..963ceef063f8 100644
--- a/drivers/acpi/acpica/nseval.c
+++ b/drivers/acpi/acpica/nseval.c
@@ -314,7 +314,7 @@ acpi_status acpi_ns_evaluate(struct acpi_evaluate_info *info)
314 "*** Completed evaluation of object %s ***\n", 314 "*** Completed evaluation of object %s ***\n",
315 info->relative_pathname)); 315 info->relative_pathname));
316 316
317 cleanup: 317cleanup:
318 /* 318 /*
319 * Namespace was unlocked by the handling acpi_ns* function, so we 319 * Namespace was unlocked by the handling acpi_ns* function, so we
320 * just free the pathname and return 320 * just free the pathname and return
@@ -486,7 +486,7 @@ acpi_ns_exec_module_code(union acpi_operand_object *method_obj,
486 parent_node->type = (u8)type; 486 parent_node->type = (u8)type;
487 } 487 }
488 488
489 exit: 489exit:
490 if (parent_obj) { 490 if (parent_obj) {
491 acpi_ut_remove_reference(parent_obj); 491 acpi_ut_remove_reference(parent_obj);
492 } 492 }
diff --git a/drivers/acpi/acpica/nsinit.c b/drivers/acpi/acpica/nsinit.c
index dd2ceae3f717..3a0423af968c 100644
--- a/drivers/acpi/acpica/nsinit.c
+++ b/drivers/acpi/acpica/nsinit.c
@@ -213,7 +213,7 @@ acpi_status acpi_ns_initialize_devices(void)
213 213
214 return_ACPI_STATUS(status); 214 return_ACPI_STATUS(status);
215 215
216 error_exit: 216error_exit:
217 ACPI_EXCEPTION((AE_INFO, status, "During device initialization")); 217 ACPI_EXCEPTION((AE_INFO, status, "During device initialization"));
218 return_ACPI_STATUS(status); 218 return_ACPI_STATUS(status);
219} 219}
diff --git a/drivers/acpi/acpica/nsload.c b/drivers/acpi/acpica/nsload.c
index 0a7badc3179f..89ec645e7730 100644
--- a/drivers/acpi/acpica/nsload.c
+++ b/drivers/acpi/acpica/nsload.c
@@ -114,7 +114,7 @@ acpi_ns_load_table(u32 table_index, struct acpi_namespace_node *node)
114 (void)acpi_tb_release_owner_id(table_index); 114 (void)acpi_tb_release_owner_id(table_index);
115 } 115 }
116 116
117 unlock: 117unlock:
118 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); 118 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
119 119
120 if (ACPI_FAILURE(status)) { 120 if (ACPI_FAILURE(status)) {
diff --git a/drivers/acpi/acpica/nsparse.c b/drivers/acpi/acpica/nsparse.c
index 35dde8151c0d..177857340271 100644
--- a/drivers/acpi/acpica/nsparse.c
+++ b/drivers/acpi/acpica/nsparse.c
@@ -140,7 +140,7 @@ acpi_ns_one_complete_parse(u32 pass_number,
140 pass_number)); 140 pass_number));
141 status = acpi_ps_parse_aml(walk_state); 141 status = acpi_ps_parse_aml(walk_state);
142 142
143 cleanup: 143cleanup:
144 acpi_ps_delete_parse_tree(parse_root); 144 acpi_ps_delete_parse_tree(parse_root);
145 return_ACPI_STATUS(status); 145 return_ACPI_STATUS(status);
146} 146}
diff --git a/drivers/acpi/acpica/nspredef.c b/drivers/acpi/acpica/nspredef.c
index 098e7666cbc9..d2855d9857c4 100644
--- a/drivers/acpi/acpica/nspredef.c
+++ b/drivers/acpi/acpica/nspredef.c
@@ -271,7 +271,7 @@ acpi_ns_check_object_type(struct acpi_evaluate_info *info,
271 return (AE_OK); /* Successful repair */ 271 return (AE_OK); /* Successful repair */
272 } 272 }
273 273
274 type_error_exit: 274type_error_exit:
275 275
276 /* Create a string with all expected types for this predefined object */ 276 /* Create a string with all expected types for this predefined object */
277 277
diff --git a/drivers/acpi/acpica/nsprepkg.c b/drivers/acpi/acpica/nsprepkg.c
index 6d55cef7916c..3d5391f9bcb5 100644
--- a/drivers/acpi/acpica/nsprepkg.c
+++ b/drivers/acpi/acpica/nsprepkg.c
@@ -330,7 +330,7 @@ acpi_ns_check_package(struct acpi_evaluate_info *info,
330 330
331 return (status); 331 return (status);
332 332
333 package_too_small: 333package_too_small:
334 334
335 /* Error exit for the case with an incorrect package count */ 335 /* Error exit for the case with an incorrect package count */
336 336
@@ -555,7 +555,7 @@ acpi_ns_check_package_list(struct acpi_evaluate_info *info,
555 555
556 return (AE_OK); 556 return (AE_OK);
557 557
558 package_too_small: 558package_too_small:
559 559
560 /* The sub-package count was smaller than required */ 560 /* The sub-package count was smaller than required */
561 561
diff --git a/drivers/acpi/acpica/nsrepair.c b/drivers/acpi/acpica/nsrepair.c
index f8e71ea60319..a05afff50eb9 100644
--- a/drivers/acpi/acpica/nsrepair.c
+++ b/drivers/acpi/acpica/nsrepair.c
@@ -263,7 +263,7 @@ acpi_ns_simple_repair(struct acpi_evaluate_info *info,
263 263
264 return (AE_AML_OPERAND_TYPE); 264 return (AE_AML_OPERAND_TYPE);
265 265
266 object_repaired: 266object_repaired:
267 267
268 /* Object was successfully repaired */ 268 /* Object was successfully repaired */
269 269
diff --git a/drivers/acpi/acpica/nsrepair2.c b/drivers/acpi/acpica/nsrepair2.c
index c84603ee83ae..6a25d320b169 100644
--- a/drivers/acpi/acpica/nsrepair2.c
+++ b/drivers/acpi/acpica/nsrepair2.c
@@ -478,7 +478,7 @@ acpi_ns_repair_CST(struct acpi_evaluate_info *info,
478 removing = TRUE; 478 removing = TRUE;
479 } 479 }
480 480
481 remove_element: 481remove_element:
482 if (removing) { 482 if (removing) {
483 acpi_ns_remove_element(return_object, i + 1); 483 acpi_ns_remove_element(return_object, i + 1);
484 outer_element_count--; 484 outer_element_count--;
diff --git a/drivers/acpi/acpica/nssearch.c b/drivers/acpi/acpica/nssearch.c
index 5d43efc53a61..47420faef073 100644
--- a/drivers/acpi/acpica/nssearch.c
+++ b/drivers/acpi/acpica/nssearch.c
@@ -381,7 +381,8 @@ acpi_ns_search_and_enter(u32 target_name,
381 381
382 /* Node is an object defined by an External() statement */ 382 /* Node is an object defined by an External() statement */
383 383
384 if (flags & ACPI_NS_EXTERNAL) { 384 if (flags & ACPI_NS_EXTERNAL ||
385 (walk_state && walk_state->opcode == AML_SCOPE_OP)) {
385 new_node->flags |= ANOBJ_IS_EXTERNAL; 386 new_node->flags |= ANOBJ_IS_EXTERNAL;
386 } 387 }
387#endif 388#endif
diff --git a/drivers/acpi/acpica/nsutils.c b/drivers/acpi/acpica/nsutils.c
index 08c0b5beec88..cc2fea94c5f0 100644
--- a/drivers/acpi/acpica/nsutils.c
+++ b/drivers/acpi/acpica/nsutils.c
@@ -722,7 +722,7 @@ acpi_ns_get_node(struct acpi_namespace_node *prefix_node,
722 722
723 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); 723 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
724 724
725 cleanup: 725cleanup:
726 ACPI_FREE(internal_path); 726 ACPI_FREE(internal_path);
727 return_ACPI_STATUS(status); 727 return_ACPI_STATUS(status);
728} 728}
diff --git a/drivers/acpi/acpica/nsxfeval.c b/drivers/acpi/acpica/nsxfeval.c
index b38b4b07f86e..e973e311f856 100644
--- a/drivers/acpi/acpica/nsxfeval.c
+++ b/drivers/acpi/acpica/nsxfeval.c
@@ -42,7 +42,8 @@
42 * POSSIBILITY OF SUCH DAMAGES. 42 * POSSIBILITY OF SUCH DAMAGES.
43 */ 43 */
44 44
45#include <linux/export.h> 45#define EXPORT_ACPI_INTERFACES
46
46#include <acpi/acpi.h> 47#include <acpi/acpi.h>
47#include "accommon.h" 48#include "accommon.h"
48#include "acnamesp.h" 49#include "acnamesp.h"
@@ -138,7 +139,7 @@ acpi_evaluate_object_typed(acpi_handle handle,
138 139
139 /* Caller used ACPI_ALLOCATE_BUFFER, free the return buffer */ 140 /* Caller used ACPI_ALLOCATE_BUFFER, free the return buffer */
140 141
141 ACPI_FREE(return_buffer->pointer); 142 ACPI_FREE_BUFFER(*return_buffer);
142 return_buffer->pointer = NULL; 143 return_buffer->pointer = NULL;
143 } 144 }
144 145
@@ -441,7 +442,7 @@ acpi_evaluate_object(acpi_handle handle,
441 acpi_ex_exit_interpreter(); 442 acpi_ex_exit_interpreter();
442 } 443 }
443 444
444 cleanup: 445cleanup:
445 446
446 /* Free the input parameter list (if we created one) */ 447 /* Free the input parameter list (if we created one) */
447 448
@@ -605,14 +606,22 @@ acpi_walk_namespace(acpi_object_type type,
605 goto unlock_and_exit; 606 goto unlock_and_exit;
606 } 607 }
607 608
609 /* Now we can validate the starting node */
610
611 if (!acpi_ns_validate_handle(start_object)) {
612 status = AE_BAD_PARAMETER;
613 goto unlock_and_exit2;
614 }
615
608 status = acpi_ns_walk_namespace(type, start_object, max_depth, 616 status = acpi_ns_walk_namespace(type, start_object, max_depth,
609 ACPI_NS_WALK_UNLOCK, 617 ACPI_NS_WALK_UNLOCK,
610 descending_callback, ascending_callback, 618 descending_callback, ascending_callback,
611 context, return_value); 619 context, return_value);
612 620
621unlock_and_exit2:
613 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); 622 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
614 623
615 unlock_and_exit: 624unlock_and_exit:
616 (void)acpi_ut_release_read_lock(&acpi_gbl_namespace_rw_lock); 625 (void)acpi_ut_release_read_lock(&acpi_gbl_namespace_rw_lock);
617 return_ACPI_STATUS(status); 626 return_ACPI_STATUS(status);
618} 627}
@@ -856,7 +865,7 @@ acpi_attach_data(acpi_handle obj_handle,
856 865
857 status = acpi_ns_attach_data(node, handler, data); 866 status = acpi_ns_attach_data(node, handler, data);
858 867
859 unlock_and_exit: 868unlock_and_exit:
860 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); 869 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
861 return (status); 870 return (status);
862} 871}
@@ -902,7 +911,7 @@ acpi_detach_data(acpi_handle obj_handle, acpi_object_handler handler)
902 911
903 status = acpi_ns_detach_data(node, handler); 912 status = acpi_ns_detach_data(node, handler);
904 913
905 unlock_and_exit: 914unlock_and_exit:
906 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); 915 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
907 return (status); 916 return (status);
908} 917}
@@ -949,7 +958,7 @@ acpi_get_data(acpi_handle obj_handle, acpi_object_handler handler, void **data)
949 958
950 status = acpi_ns_get_attached_data(node, handler, data); 959 status = acpi_ns_get_attached_data(node, handler, data);
951 960
952 unlock_and_exit: 961unlock_and_exit:
953 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); 962 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
954 return (status); 963 return (status);
955} 964}
diff --git a/drivers/acpi/acpica/nsxfname.c b/drivers/acpi/acpica/nsxfname.c
index 83c164434580..3a4bd3ff49a3 100644
--- a/drivers/acpi/acpica/nsxfname.c
+++ b/drivers/acpi/acpica/nsxfname.c
@@ -42,7 +42,8 @@
42 * POSSIBILITY OF SUCH DAMAGES. 42 * POSSIBILITY OF SUCH DAMAGES.
43 */ 43 */
44 44
45#include <linux/export.h> 45#define EXPORT_ACPI_INTERFACES
46
46#include <acpi/acpi.h> 47#include <acpi/acpi.h>
47#include "accommon.h" 48#include "accommon.h"
48#include "acnamesp.h" 49#include "acnamesp.h"
@@ -208,7 +209,7 @@ acpi_get_name(acpi_handle handle, u32 name_type, struct acpi_buffer * buffer)
208 ((char *)buffer->pointer)[ACPI_NAME_SIZE] = 0; 209 ((char *)buffer->pointer)[ACPI_NAME_SIZE] = 0;
209 status = AE_OK; 210 status = AE_OK;
210 211
211 unlock_and_exit: 212unlock_and_exit:
212 213
213 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); 214 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
214 return (status); 215 return (status);
@@ -496,7 +497,7 @@ acpi_get_object_info(acpi_handle handle,
496 *return_buffer = info; 497 *return_buffer = info;
497 status = AE_OK; 498 status = AE_OK;
498 499
499 cleanup: 500cleanup:
500 if (hid) { 501 if (hid) {
501 ACPI_FREE(hid); 502 ACPI_FREE(hid);
502 } 503 }
diff --git a/drivers/acpi/acpica/nsxfobj.c b/drivers/acpi/acpica/nsxfobj.c
index c0853ef294e4..0e6d79e462d4 100644
--- a/drivers/acpi/acpica/nsxfobj.c
+++ b/drivers/acpi/acpica/nsxfobj.c
@@ -42,7 +42,8 @@
42 * POSSIBILITY OF SUCH DAMAGES. 42 * POSSIBILITY OF SUCH DAMAGES.
43 */ 43 */
44 44
45#include <linux/export.h> 45#define EXPORT_ACPI_INTERFACES
46
46#include <acpi/acpi.h> 47#include <acpi/acpi.h>
47#include "accommon.h" 48#include "accommon.h"
48#include "acnamesp.h" 49#include "acnamesp.h"
@@ -200,7 +201,7 @@ acpi_status acpi_get_parent(acpi_handle handle, acpi_handle * ret_handle)
200 status = AE_NULL_ENTRY; 201 status = AE_NULL_ENTRY;
201 } 202 }
202 203
203 unlock_and_exit: 204unlock_and_exit:
204 205
205 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); 206 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
206 return (status); 207 return (status);
@@ -280,7 +281,7 @@ acpi_get_next_object(acpi_object_type type,
280 *ret_handle = ACPI_CAST_PTR(acpi_handle, node); 281 *ret_handle = ACPI_CAST_PTR(acpi_handle, node);
281 } 282 }
282 283
283 unlock_and_exit: 284unlock_and_exit:
284 285
285 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); 286 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
286 return (status); 287 return (status);
diff --git a/drivers/acpi/acpica/psparse.c b/drivers/acpi/acpica/psparse.c
index 86198a9139b5..79d9a28dedef 100644
--- a/drivers/acpi/acpica/psparse.c
+++ b/drivers/acpi/acpica/psparse.c
@@ -297,7 +297,7 @@ acpi_ps_complete_this_op(struct acpi_walk_state * walk_state,
297 } 297 }
298 } 298 }
299 299
300 cleanup: 300cleanup:
301 301
302 /* Now we can actually delete the subtree rooted at Op */ 302 /* Now we can actually delete the subtree rooted at Op */
303 303
diff --git a/drivers/acpi/acpica/psxface.c b/drivers/acpi/acpica/psxface.c
index 11b99ab20bb3..fcb7a840e996 100644
--- a/drivers/acpi/acpica/psxface.c
+++ b/drivers/acpi/acpica/psxface.c
@@ -142,7 +142,7 @@ static void acpi_ps_start_trace(struct acpi_evaluate_info *info)
142 acpi_dbg_layer = acpi_gbl_trace_dbg_layer; 142 acpi_dbg_layer = acpi_gbl_trace_dbg_layer;
143 } 143 }
144 144
145 exit: 145exit:
146 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); 146 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
147} 147}
148 148
@@ -185,7 +185,7 @@ static void acpi_ps_stop_trace(struct acpi_evaluate_info *info)
185 acpi_dbg_level = acpi_gbl_original_dbg_level; 185 acpi_dbg_level = acpi_gbl_original_dbg_level;
186 acpi_dbg_layer = acpi_gbl_original_dbg_layer; 186 acpi_dbg_layer = acpi_gbl_original_dbg_layer;
187 187
188 exit: 188exit:
189 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); 189 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
190} 190}
191 191
@@ -323,7 +323,7 @@ acpi_status acpi_ps_execute_method(struct acpi_evaluate_info *info)
323 323
324 /* walk_state was deleted by parse_aml */ 324 /* walk_state was deleted by parse_aml */
325 325
326 cleanup: 326cleanup:
327 acpi_ps_delete_parse_tree(op); 327 acpi_ps_delete_parse_tree(op);
328 328
329 /* End optional tracing */ 329 /* End optional tracing */
diff --git a/drivers/acpi/acpica/rsmisc.c b/drivers/acpi/acpica/rsmisc.c
index 80d12994e0d0..c99cec9cefde 100644
--- a/drivers/acpi/acpica/rsmisc.c
+++ b/drivers/acpi/acpica/rsmisc.c
@@ -440,7 +440,7 @@ acpi_rs_convert_aml_to_resource(struct acpi_resource *resource,
440 info++; 440 info++;
441 } 441 }
442 442
443 exit: 443exit:
444 if (!flags_mode) { 444 if (!flags_mode) {
445 445
446 /* Round the resource struct length up to the next boundary (32 or 64) */ 446 /* Round the resource struct length up to the next boundary (32 or 64) */
@@ -783,7 +783,7 @@ acpi_rs_convert_resource_to_aml(struct acpi_resource *resource,
783 info++; 783 info++;
784 } 784 }
785 785
786 exit: 786exit:
787 return_ACPI_STATUS(AE_OK); 787 return_ACPI_STATUS(AE_OK);
788} 788}
789 789
diff --git a/drivers/acpi/acpica/rsutils.c b/drivers/acpi/acpica/rsutils.c
index 480b6b40c5ea..aef303d56d86 100644
--- a/drivers/acpi/acpica/rsutils.c
+++ b/drivers/acpi/acpica/rsutils.c
@@ -784,7 +784,7 @@ acpi_rs_set_srs_method_data(struct acpi_namespace_node *node,
784 784
785 acpi_ut_remove_reference(args[0]); 785 acpi_ut_remove_reference(args[0]);
786 786
787 cleanup: 787cleanup:
788 ACPI_FREE(info); 788 ACPI_FREE(info);
789 return_ACPI_STATUS(status); 789 return_ACPI_STATUS(status);
790} 790}
diff --git a/drivers/acpi/acpica/rsxface.c b/drivers/acpi/acpica/rsxface.c
index 94e3517554f9..01e476988aae 100644
--- a/drivers/acpi/acpica/rsxface.c
+++ b/drivers/acpi/acpica/rsxface.c
@@ -41,7 +41,8 @@
41 * POSSIBILITY OF SUCH DAMAGES. 41 * POSSIBILITY OF SUCH DAMAGES.
42 */ 42 */
43 43
44#include <linux/export.h> 44#define EXPORT_ACPI_INTERFACES
45
45#include <acpi/acpi.h> 46#include <acpi/acpi.h>
46#include "accommon.h" 47#include "accommon.h"
47#include "acresrc.h" 48#include "acresrc.h"
diff --git a/drivers/acpi/acpica/tbinstal.c b/drivers/acpi/acpica/tbinstal.c
index 42a13c0d7015..634357d51fe9 100644
--- a/drivers/acpi/acpica/tbinstal.c
+++ b/drivers/acpi/acpica/tbinstal.c
@@ -80,16 +80,10 @@ acpi_status acpi_tb_verify_table(struct acpi_table_desc *table_desc)
80 } 80 }
81 } 81 }
82 82
83 /* FACS is the odd table, has no standard ACPI header and no checksum */ 83 /* Always calculate checksum, ignore bad checksum if requested */
84 84
85 if (!ACPI_COMPARE_NAME(&table_desc->signature, ACPI_SIG_FACS)) { 85 status =
86 86 acpi_tb_verify_checksum(table_desc->pointer, table_desc->length);
87 /* Always calculate checksum, ignore bad checksum if requested */
88
89 status =
90 acpi_tb_verify_checksum(table_desc->pointer,
91 table_desc->length);
92 }
93 87
94 return_ACPI_STATUS(status); 88 return_ACPI_STATUS(status);
95} 89}
@@ -237,10 +231,10 @@ acpi_tb_add_table(struct acpi_table_desc *table_desc, u32 *table_index)
237 goto release; 231 goto release;
238 } 232 }
239 233
240 print_header: 234print_header:
241 acpi_tb_print_table_header(table_desc->address, table_desc->pointer); 235 acpi_tb_print_table_header(table_desc->address, table_desc->pointer);
242 236
243 release: 237release:
244 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); 238 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
245 return_ACPI_STATUS(status); 239 return_ACPI_STATUS(status);
246} 240}
@@ -312,7 +306,7 @@ struct acpi_table_header *acpi_tb_table_override(struct acpi_table_header
312 306
313 return (NULL); /* There was no override */ 307 return (NULL); /* There was no override */
314 308
315 finish_override: 309finish_override:
316 310
317 ACPI_INFO((AE_INFO, 311 ACPI_INFO((AE_INFO,
318 "%4.4s %p %s table override, new table: %p", 312 "%4.4s %p %s table override, new table: %p",
diff --git a/drivers/acpi/acpica/tbprint.c b/drivers/acpi/acpica/tbprint.c
index dc963f823d2c..6866e767ba90 100644
--- a/drivers/acpi/acpica/tbprint.c
+++ b/drivers/acpi/acpica/tbprint.c
@@ -135,10 +135,10 @@ acpi_tb_print_table_header(acpi_physical_address address,
135 135
136 /* FACS only has signature and length fields */ 136 /* FACS only has signature and length fields */
137 137
138 ACPI_INFO((AE_INFO, "%4.4s %p %05X", 138 ACPI_INFO((AE_INFO, "%4.4s %p %06X",
139 header->signature, ACPI_CAST_PTR(void, address), 139 header->signature, ACPI_CAST_PTR(void, address),
140 header->length)); 140 header->length));
141 } else if (ACPI_COMPARE_NAME(header->signature, ACPI_SIG_RSDP)) { 141 } else if (ACPI_VALIDATE_RSDP_SIG(header->signature)) {
142 142
143 /* RSDP has no common fields */ 143 /* RSDP has no common fields */
144 144
@@ -147,7 +147,7 @@ acpi_tb_print_table_header(acpi_physical_address address,
147 header)->oem_id, ACPI_OEM_ID_SIZE); 147 header)->oem_id, ACPI_OEM_ID_SIZE);
148 acpi_tb_fix_string(local_header.oem_id, ACPI_OEM_ID_SIZE); 148 acpi_tb_fix_string(local_header.oem_id, ACPI_OEM_ID_SIZE);
149 149
150 ACPI_INFO((AE_INFO, "RSDP %p %05X (v%.2d %6.6s)", 150 ACPI_INFO((AE_INFO, "RSDP %p %06X (v%.2d %6.6s)",
151 ACPI_CAST_PTR(void, address), 151 ACPI_CAST_PTR(void, address),
152 (ACPI_CAST_PTR(struct acpi_table_rsdp, header)-> 152 (ACPI_CAST_PTR(struct acpi_table_rsdp, header)->
153 revision > 153 revision >
@@ -162,7 +162,7 @@ acpi_tb_print_table_header(acpi_physical_address address,
162 acpi_tb_cleanup_table_header(&local_header, header); 162 acpi_tb_cleanup_table_header(&local_header, header);
163 163
164 ACPI_INFO((AE_INFO, 164 ACPI_INFO((AE_INFO,
165 "%4.4s %p %05X (v%.2d %6.6s %8.8s %08X %4.4s %08X)", 165 "%4.4s %p %06X (v%.2d %6.6s %8.8s %08X %4.4s %08X)",
166 local_header.signature, ACPI_CAST_PTR(void, address), 166 local_header.signature, ACPI_CAST_PTR(void, address),
167 local_header.length, local_header.revision, 167 local_header.length, local_header.revision,
168 local_header.oem_id, local_header.oem_table_id, 168 local_header.oem_id, local_header.oem_table_id,
@@ -190,6 +190,16 @@ acpi_status acpi_tb_verify_checksum(struct acpi_table_header *table, u32 length)
190{ 190{
191 u8 checksum; 191 u8 checksum;
192 192
193 /*
194 * FACS/S3PT:
195 * They are the odd tables, have no standard ACPI header and no checksum
196 */
197
198 if (ACPI_COMPARE_NAME(table->signature, ACPI_SIG_S3PT) ||
199 ACPI_COMPARE_NAME(table->signature, ACPI_SIG_FACS)) {
200 return (AE_OK);
201 }
202
193 /* Compute the checksum on the table */ 203 /* Compute the checksum on the table */
194 204
195 checksum = acpi_tb_checksum(ACPI_CAST_PTR(u8, table), length); 205 checksum = acpi_tb_checksum(ACPI_CAST_PTR(u8, table), length);
diff --git a/drivers/acpi/acpica/tbutils.c b/drivers/acpi/acpica/tbutils.c
index bffdfc7b8322..3d6bb83aa7e7 100644
--- a/drivers/acpi/acpica/tbutils.c
+++ b/drivers/acpi/acpica/tbutils.c
@@ -350,7 +350,7 @@ acpi_tb_install_table(acpi_physical_address address,
350 acpi_tb_delete_table(table_desc); 350 acpi_tb_delete_table(table_desc);
351 } 351 }
352 352
353 unmap_and_exit: 353unmap_and_exit:
354 354
355 /* Always unmap the table header that we mapped above */ 355 /* Always unmap the table header that we mapped above */
356 356
@@ -430,8 +430,7 @@ acpi_tb_get_root_table_entry(u8 *table_entry, u32 table_entry_size)
430 * 430 *
431 ******************************************************************************/ 431 ******************************************************************************/
432 432
433acpi_status __init 433acpi_status __init acpi_tb_parse_root_table(acpi_physical_address rsdp_address)
434acpi_tb_parse_root_table(acpi_physical_address rsdp_address)
435{ 434{
436 struct acpi_table_rsdp *rsdp; 435 struct acpi_table_rsdp *rsdp;
437 u32 table_entry_size; 436 u32 table_entry_size;
diff --git a/drivers/acpi/acpica/tbxface.c b/drivers/acpi/acpica/tbxface.c
index ad11162482ff..db826eaadd1c 100644
--- a/drivers/acpi/acpica/tbxface.c
+++ b/drivers/acpi/acpica/tbxface.c
@@ -41,7 +41,8 @@
41 * POSSIBILITY OF SUCH DAMAGES. 41 * POSSIBILITY OF SUCH DAMAGES.
42 */ 42 */
43 43
44#include <linux/export.h> 44#define EXPORT_ACPI_INTERFACES
45
45#include <acpi/acpi.h> 46#include <acpi/acpi.h>
46#include "accommon.h" 47#include "accommon.h"
47#include "actables.h" 48#include "actables.h"
@@ -147,6 +148,8 @@ acpi_initialize_tables(struct acpi_table_desc * initial_table_array,
147 return_ACPI_STATUS(status); 148 return_ACPI_STATUS(status);
148} 149}
149 150
151ACPI_EXPORT_SYMBOL_INIT(acpi_initialize_tables)
152
150/******************************************************************************* 153/*******************************************************************************
151 * 154 *
152 * FUNCTION: acpi_reallocate_root_table 155 * FUNCTION: acpi_reallocate_root_table
@@ -161,7 +164,7 @@ acpi_initialize_tables(struct acpi_table_desc * initial_table_array,
161 * kernel. 164 * kernel.
162 * 165 *
163 ******************************************************************************/ 166 ******************************************************************************/
164acpi_status acpi_reallocate_root_table(void) 167acpi_status __init acpi_reallocate_root_table(void)
165{ 168{
166 acpi_status status; 169 acpi_status status;
167 170
@@ -181,6 +184,8 @@ acpi_status acpi_reallocate_root_table(void)
181 return_ACPI_STATUS(status); 184 return_ACPI_STATUS(status);
182} 185}
183 186
187ACPI_EXPORT_SYMBOL_INIT(acpi_reallocate_root_table)
188
184/******************************************************************************* 189/*******************************************************************************
185 * 190 *
186 * FUNCTION: acpi_get_table_header 191 * FUNCTION: acpi_get_table_header
@@ -356,6 +361,7 @@ acpi_get_table_with_size(char *signature,
356 361
357 return (AE_NOT_FOUND); 362 return (AE_NOT_FOUND);
358} 363}
364
359ACPI_EXPORT_SYMBOL(acpi_get_table_with_size) 365ACPI_EXPORT_SYMBOL(acpi_get_table_with_size)
360 366
361acpi_status 367acpi_status
@@ -367,6 +373,7 @@ acpi_get_table(char *signature,
367 return acpi_get_table_with_size(signature, 373 return acpi_get_table_with_size(signature,
368 instance, out_table, &tbl_size); 374 instance, out_table, &tbl_size);
369} 375}
376
370ACPI_EXPORT_SYMBOL(acpi_get_table) 377ACPI_EXPORT_SYMBOL(acpi_get_table)
371 378
372/******************************************************************************* 379/*******************************************************************************
@@ -424,7 +431,6 @@ acpi_get_table_by_index(u32 table_index, struct acpi_table_header **table)
424 431
425ACPI_EXPORT_SYMBOL(acpi_get_table_by_index) 432ACPI_EXPORT_SYMBOL(acpi_get_table_by_index)
426 433
427
428/******************************************************************************* 434/*******************************************************************************
429 * 435 *
430 * FUNCTION: acpi_install_table_handler 436 * FUNCTION: acpi_install_table_handler
@@ -465,7 +471,7 @@ acpi_install_table_handler(acpi_table_handler handler, void *context)
465 acpi_gbl_table_handler = handler; 471 acpi_gbl_table_handler = handler;
466 acpi_gbl_table_handler_context = context; 472 acpi_gbl_table_handler_context = context;
467 473
468 cleanup: 474cleanup:
469 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); 475 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
470 return_ACPI_STATUS(status); 476 return_ACPI_STATUS(status);
471} 477}
@@ -506,7 +512,7 @@ acpi_status acpi_remove_table_handler(acpi_table_handler handler)
506 512
507 acpi_gbl_table_handler = NULL; 513 acpi_gbl_table_handler = NULL;
508 514
509 cleanup: 515cleanup:
510 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); 516 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
511 return_ACPI_STATUS(status); 517 return_ACPI_STATUS(status);
512} 518}
diff --git a/drivers/acpi/acpica/tbxfload.c b/drivers/acpi/acpica/tbxfload.c
index 0ba9e328d5d7..60b5a871833c 100644
--- a/drivers/acpi/acpica/tbxfload.c
+++ b/drivers/acpi/acpica/tbxfload.c
@@ -41,7 +41,8 @@
41 * POSSIBILITY OF SUCH DAMAGES. 41 * POSSIBILITY OF SUCH DAMAGES.
42 */ 42 */
43 43
44#include <linux/export.h> 44#define EXPORT_ACPI_INTERFACES
45
45#include <acpi/acpi.h> 46#include <acpi/acpi.h>
46#include "accommon.h" 47#include "accommon.h"
47#include "acnamesp.h" 48#include "acnamesp.h"
@@ -65,7 +66,7 @@ static acpi_status acpi_tb_load_namespace(void);
65 * 66 *
66 ******************************************************************************/ 67 ******************************************************************************/
67 68
68acpi_status acpi_load_tables(void) 69acpi_status __init acpi_load_tables(void)
69{ 70{
70 acpi_status status; 71 acpi_status status;
71 72
@@ -82,7 +83,7 @@ acpi_status acpi_load_tables(void)
82 return_ACPI_STATUS(status); 83 return_ACPI_STATUS(status);
83} 84}
84 85
85ACPI_EXPORT_SYMBOL(acpi_load_tables) 86ACPI_EXPORT_SYMBOL_INIT(acpi_load_tables)
86 87
87/******************************************************************************* 88/*******************************************************************************
88 * 89 *
@@ -200,7 +201,7 @@ static acpi_status acpi_tb_load_namespace(void)
200 201
201 ACPI_INFO((AE_INFO, "All ACPI Tables successfully acquired")); 202 ACPI_INFO((AE_INFO, "All ACPI Tables successfully acquired"));
202 203
203 unlock_and_exit: 204unlock_and_exit:
204 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); 205 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
205 return_ACPI_STATUS(status); 206 return_ACPI_STATUS(status);
206} 207}
@@ -268,7 +269,7 @@ acpi_status acpi_load_table(struct acpi_table_header *table)
268 acpi_gbl_table_handler_context); 269 acpi_gbl_table_handler_context);
269 } 270 }
270 271
271 unlock_and_exit: 272unlock_and_exit:
272 (void)acpi_ut_release_mutex(ACPI_MTX_INTERPRETER); 273 (void)acpi_ut_release_mutex(ACPI_MTX_INTERPRETER);
273 return_ACPI_STATUS(status); 274 return_ACPI_STATUS(status);
274} 275}
diff --git a/drivers/acpi/acpica/tbxfroot.c b/drivers/acpi/acpica/tbxfroot.c
index 948c95e80d44..e4e1468877c3 100644
--- a/drivers/acpi/acpica/tbxfroot.c
+++ b/drivers/acpi/acpica/tbxfroot.c
@@ -68,8 +68,7 @@ acpi_status acpi_tb_validate_rsdp(struct acpi_table_rsdp *rsdp)
68 * Note: Sometimes there exists more than one RSDP in memory; the valid 68 * Note: Sometimes there exists more than one RSDP in memory; the valid
69 * RSDP has a valid checksum, all others have an invalid checksum. 69 * RSDP has a valid checksum, all others have an invalid checksum.
70 */ 70 */
71 if (ACPI_STRNCMP((char *)rsdp->signature, ACPI_SIG_RSDP, 71 if (!ACPI_VALIDATE_RSDP_SIG(rsdp->signature)) {
72 sizeof(ACPI_SIG_RSDP) - 1) != 0) {
73 72
74 /* Nope, BAD Signature */ 73 /* Nope, BAD Signature */
75 74
@@ -112,7 +111,7 @@ acpi_status acpi_tb_validate_rsdp(struct acpi_table_rsdp *rsdp)
112 * 111 *
113 ******************************************************************************/ 112 ******************************************************************************/
114 113
115acpi_status acpi_find_root_pointer(acpi_size *table_address) 114acpi_status __init acpi_find_root_pointer(acpi_size *table_address)
116{ 115{
117 u8 *table_ptr; 116 u8 *table_ptr;
118 u8 *mem_rover; 117 u8 *mem_rover;
diff --git a/drivers/acpi/acpica/utalloc.c b/drivers/acpi/acpica/utalloc.c
index e0ffb580f4b0..814267f52715 100644
--- a/drivers/acpi/acpica/utalloc.c
+++ b/drivers/acpi/acpica/utalloc.c
@@ -48,6 +48,39 @@
48#define _COMPONENT ACPI_UTILITIES 48#define _COMPONENT ACPI_UTILITIES
49ACPI_MODULE_NAME("utalloc") 49ACPI_MODULE_NAME("utalloc")
50 50
51#if !defined (USE_NATIVE_ALLOCATE_ZEROED)
52/*******************************************************************************
53 *
54 * FUNCTION: acpi_os_allocate_zeroed
55 *
56 * PARAMETERS: size - Size of the allocation
57 *
58 * RETURN: Address of the allocated memory on success, NULL on failure.
59 *
60 * DESCRIPTION: Subsystem equivalent of calloc. Allocate and zero memory.
61 * This is the default implementation. Can be overridden via the
62 * USE_NATIVE_ALLOCATE_ZEROED flag.
63 *
64 ******************************************************************************/
65void *acpi_os_allocate_zeroed(acpi_size size)
66{
67 void *allocation;
68
69 ACPI_FUNCTION_ENTRY();
70
71 allocation = acpi_os_allocate(size);
72 if (allocation) {
73
74 /* Clear the memory block */
75
76 ACPI_MEMSET(allocation, 0, size);
77 }
78
79 return (allocation);
80}
81
82#endif /* !USE_NATIVE_ALLOCATE_ZEROED */
83
51/******************************************************************************* 84/*******************************************************************************
52 * 85 *
53 * FUNCTION: acpi_ut_create_caches 86 * FUNCTION: acpi_ut_create_caches
@@ -59,6 +92,7 @@ ACPI_MODULE_NAME("utalloc")
59 * DESCRIPTION: Create all local caches 92 * DESCRIPTION: Create all local caches
60 * 93 *
61 ******************************************************************************/ 94 ******************************************************************************/
95
62acpi_status acpi_ut_create_caches(void) 96acpi_status acpi_ut_create_caches(void)
63{ 97{
64 acpi_status status; 98 acpi_status status;
@@ -175,10 +209,10 @@ acpi_status acpi_ut_delete_caches(void)
175 209
176 /* Free memory lists */ 210 /* Free memory lists */
177 211
178 ACPI_FREE(acpi_gbl_global_list); 212 acpi_os_free(acpi_gbl_global_list);
179 acpi_gbl_global_list = NULL; 213 acpi_gbl_global_list = NULL;
180 214
181 ACPI_FREE(acpi_gbl_ns_node_list); 215 acpi_os_free(acpi_gbl_ns_node_list);
182 acpi_gbl_ns_node_list = NULL; 216 acpi_gbl_ns_node_list = NULL;
183#endif 217#endif
184 218
@@ -302,82 +336,3 @@ acpi_ut_initialize_buffer(struct acpi_buffer * buffer,
302 ACPI_MEMSET(buffer->pointer, 0, required_length); 336 ACPI_MEMSET(buffer->pointer, 0, required_length);
303 return (AE_OK); 337 return (AE_OK);
304} 338}
305
306#ifdef NOT_USED_BY_LINUX
307/*******************************************************************************
308 *
309 * FUNCTION: acpi_ut_allocate
310 *
311 * PARAMETERS: size - Size of the allocation
312 * component - Component type of caller
313 * module - Source file name of caller
314 * line - Line number of caller
315 *
316 * RETURN: Address of the allocated memory on success, NULL on failure.
317 *
318 * DESCRIPTION: Subsystem equivalent of malloc.
319 *
320 ******************************************************************************/
321
322void *acpi_ut_allocate(acpi_size size,
323 u32 component, const char *module, u32 line)
324{
325 void *allocation;
326
327 ACPI_FUNCTION_TRACE_U32(ut_allocate, size);
328
329 /* Check for an inadvertent size of zero bytes */
330
331 if (!size) {
332 ACPI_WARNING((module, line,
333 "Attempt to allocate zero bytes, allocating 1 byte"));
334 size = 1;
335 }
336
337 allocation = acpi_os_allocate(size);
338 if (!allocation) {
339
340 /* Report allocation error */
341
342 ACPI_WARNING((module, line,
343 "Could not allocate size %u", (u32) size));
344
345 return_PTR(NULL);
346 }
347
348 return_PTR(allocation);
349}
350
351/*******************************************************************************
352 *
353 * FUNCTION: acpi_ut_allocate_zeroed
354 *
355 * PARAMETERS: size - Size of the allocation
356 * component - Component type of caller
357 * module - Source file name of caller
358 * line - Line number of caller
359 *
360 * RETURN: Address of the allocated memory on success, NULL on failure.
361 *
362 * DESCRIPTION: Subsystem equivalent of calloc. Allocate and zero memory.
363 *
364 ******************************************************************************/
365
366void *acpi_ut_allocate_zeroed(acpi_size size,
367 u32 component, const char *module, u32 line)
368{
369 void *allocation;
370
371 ACPI_FUNCTION_ENTRY();
372
373 allocation = acpi_ut_allocate(size, component, module, line);
374 if (allocation) {
375
376 /* Clear the memory block */
377
378 ACPI_MEMSET(allocation, 0, size);
379 }
380
381 return (allocation);
382}
383#endif
diff --git a/drivers/acpi/acpica/utcache.c b/drivers/acpi/acpica/utcache.c
index a877a9647fd9..366bfec4b770 100644
--- a/drivers/acpi/acpica/utcache.c
+++ b/drivers/acpi/acpica/utcache.c
@@ -65,7 +65,7 @@ ACPI_MODULE_NAME("utcache")
65acpi_status 65acpi_status
66acpi_os_create_cache(char *cache_name, 66acpi_os_create_cache(char *cache_name,
67 u16 object_size, 67 u16 object_size,
68 u16 max_depth, struct acpi_memory_list ** return_cache) 68 u16 max_depth, struct acpi_memory_list **return_cache)
69{ 69{
70 struct acpi_memory_list *cache; 70 struct acpi_memory_list *cache;
71 71
diff --git a/drivers/acpi/acpica/utcopy.c b/drivers/acpi/acpica/utcopy.c
index 1731c27c36a6..edff4e653d9a 100644
--- a/drivers/acpi/acpica/utcopy.c
+++ b/drivers/acpi/acpica/utcopy.c
@@ -552,7 +552,7 @@ acpi_ut_copy_esimple_to_isimple(union acpi_object *external_object,
552 *ret_internal_object = internal_object; 552 *ret_internal_object = internal_object;
553 return_ACPI_STATUS(AE_OK); 553 return_ACPI_STATUS(AE_OK);
554 554
555 error_exit: 555error_exit:
556 acpi_ut_remove_reference(internal_object); 556 acpi_ut_remove_reference(internal_object);
557 return_ACPI_STATUS(AE_NO_MEMORY); 557 return_ACPI_STATUS(AE_NO_MEMORY);
558} 558}
@@ -899,7 +899,7 @@ acpi_ut_copy_ielement_to_ielement(u8 object_type,
899 899
900 return (status); 900 return (status);
901 901
902 error_exit: 902error_exit:
903 acpi_ut_remove_reference(target_object); 903 acpi_ut_remove_reference(target_object);
904 return (status); 904 return (status);
905} 905}
diff --git a/drivers/acpi/acpica/utdebug.c b/drivers/acpi/acpica/utdebug.c
index 5796e11a0671..1a67b3944b3b 100644
--- a/drivers/acpi/acpica/utdebug.c
+++ b/drivers/acpi/acpica/utdebug.c
@@ -41,7 +41,8 @@
41 * POSSIBILITY OF SUCH DAMAGES. 41 * POSSIBILITY OF SUCH DAMAGES.
42 */ 42 */
43 43
44#include <linux/export.h> 44#define EXPORT_ACPI_INTERFACES
45
45#include <acpi/acpi.h> 46#include <acpi/acpi.h>
46#include "accommon.h" 47#include "accommon.h"
47 48
@@ -190,7 +191,7 @@ acpi_debug_print(u32 requested_debug_level,
190 * Display the module name, current line number, thread ID (if requested), 191 * Display the module name, current line number, thread ID (if requested),
191 * current procedure nesting level, and the current procedure name 192 * current procedure nesting level, and the current procedure name
192 */ 193 */
193 acpi_os_printf("%8s-%04ld ", module_name, line_number); 194 acpi_os_printf("%9s-%04ld ", module_name, line_number);
194 195
195 if (ACPI_LV_THREADS & acpi_dbg_level) { 196 if (ACPI_LV_THREADS & acpi_dbg_level) {
196 acpi_os_printf("[%u] ", (u32)thread_id); 197 acpi_os_printf("[%u] ", (u32)thread_id);
diff --git a/drivers/acpi/acpica/utdecode.c b/drivers/acpi/acpica/utdecode.c
index 11e2e02e1618..b3f31dd89a45 100644
--- a/drivers/acpi/acpica/utdecode.c
+++ b/drivers/acpi/acpica/utdecode.c
@@ -41,7 +41,6 @@
41 * POSSIBILITY OF SUCH DAMAGES. 41 * POSSIBILITY OF SUCH DAMAGES.
42 */ 42 */
43 43
44#include <linux/export.h>
45#include <acpi/acpi.h> 44#include <acpi/acpi.h>
46#include "accommon.h" 45#include "accommon.h"
47#include "acnamesp.h" 46#include "acnamesp.h"
diff --git a/drivers/acpi/acpica/utdelete.c b/drivers/acpi/acpica/utdelete.c
index d6b33f29d327..c07d2227ea42 100644
--- a/drivers/acpi/acpica/utdelete.c
+++ b/drivers/acpi/acpica/utdelete.c
@@ -649,7 +649,7 @@ acpi_ut_update_object_reference(union acpi_operand_object *object, u16 action)
649 649
650 return (AE_OK); 650 return (AE_OK);
651 651
652 error_exit: 652error_exit:
653 653
654 ACPI_EXCEPTION((AE_INFO, status, 654 ACPI_EXCEPTION((AE_INFO, status,
655 "Could not update object reference count")); 655 "Could not update object reference count"));
diff --git a/drivers/acpi/acpica/uteval.c b/drivers/acpi/acpica/uteval.c
index 4fd68971019b..16fb90506db7 100644
--- a/drivers/acpi/acpica/uteval.c
+++ b/drivers/acpi/acpica/uteval.c
@@ -181,7 +181,7 @@ acpi_ut_evaluate_object(struct acpi_namespace_node *prefix_node,
181 181
182 *return_desc = info->return_object; 182 *return_desc = info->return_object;
183 183
184 cleanup: 184cleanup:
185 ACPI_FREE(info); 185 ACPI_FREE(info);
186 return_ACPI_STATUS(status); 186 return_ACPI_STATUS(status);
187} 187}
diff --git a/drivers/acpi/acpica/utexcep.c b/drivers/acpi/acpica/utexcep.c
index ff6d9e8aa842..3cf7b597edb9 100644
--- a/drivers/acpi/acpica/utexcep.c
+++ b/drivers/acpi/acpica/utexcep.c
@@ -41,8 +41,9 @@
41 * POSSIBILITY OF SUCH DAMAGES. 41 * POSSIBILITY OF SUCH DAMAGES.
42 */ 42 */
43 43
44#define EXPORT_ACPI_INTERFACES
45
44#define ACPI_DEFINE_EXCEPTION_TABLE 46#define ACPI_DEFINE_EXCEPTION_TABLE
45#include <linux/export.h>
46#include <acpi/acpi.h> 47#include <acpi/acpi.h>
47#include "accommon.h" 48#include "accommon.h"
48 49
diff --git a/drivers/acpi/acpica/utglobal.c b/drivers/acpi/acpica/utglobal.c
index d6f26bf8a062..81f9a9584451 100644
--- a/drivers/acpi/acpica/utglobal.c
+++ b/drivers/acpi/acpica/utglobal.c
@@ -41,9 +41,9 @@
41 * POSSIBILITY OF SUCH DAMAGES. 41 * POSSIBILITY OF SUCH DAMAGES.
42 */ 42 */
43 43
44#define EXPORT_ACPI_INTERFACES
44#define DEFINE_ACPI_GLOBALS 45#define DEFINE_ACPI_GLOBALS
45 46
46#include <linux/export.h>
47#include <acpi/acpi.h> 47#include <acpi/acpi.h>
48#include "accommon.h" 48#include "accommon.h"
49 49
@@ -289,9 +289,19 @@ acpi_status acpi_ut_init_globals(void)
289 289
290 acpi_gbl_owner_id_mask[ACPI_NUM_OWNERID_MASKS - 1] = 0x80000000; 290 acpi_gbl_owner_id_mask[ACPI_NUM_OWNERID_MASKS - 1] = 0x80000000;
291 291
292 /* Event counters */
293
294 acpi_method_count = 0;
295 acpi_sci_count = 0;
296 acpi_gpe_count = 0;
297
298 for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++) {
299 acpi_fixed_event_count[i] = 0;
300 }
301
292#if (!ACPI_REDUCED_HARDWARE) 302#if (!ACPI_REDUCED_HARDWARE)
293 303
294 /* GPE support */ 304 /* GPE/SCI support */
295 305
296 acpi_gbl_all_gpes_initialized = FALSE; 306 acpi_gbl_all_gpes_initialized = FALSE;
297 acpi_gbl_gpe_xrupt_list_head = NULL; 307 acpi_gbl_gpe_xrupt_list_head = NULL;
@@ -300,6 +310,7 @@ acpi_status acpi_ut_init_globals(void)
300 acpi_current_gpe_count = 0; 310 acpi_current_gpe_count = 0;
301 311
302 acpi_gbl_global_event_handler = NULL; 312 acpi_gbl_global_event_handler = NULL;
313 acpi_gbl_sci_handler_list = NULL;
303 314
304#endif /* !ACPI_REDUCED_HARDWARE */ 315#endif /* !ACPI_REDUCED_HARDWARE */
305 316
@@ -377,6 +388,11 @@ acpi_status acpi_ut_init_globals(void)
377/* Public globals */ 388/* Public globals */
378 389
379ACPI_EXPORT_SYMBOL(acpi_gbl_FADT) 390ACPI_EXPORT_SYMBOL(acpi_gbl_FADT)
391
380ACPI_EXPORT_SYMBOL(acpi_dbg_level) 392ACPI_EXPORT_SYMBOL(acpi_dbg_level)
393
381ACPI_EXPORT_SYMBOL(acpi_dbg_layer) 394ACPI_EXPORT_SYMBOL(acpi_dbg_layer)
395
396ACPI_EXPORT_SYMBOL(acpi_gpe_count)
397
382ACPI_EXPORT_SYMBOL(acpi_current_gpe_count) 398ACPI_EXPORT_SYMBOL(acpi_current_gpe_count)
diff --git a/drivers/acpi/acpica/utids.c b/drivers/acpi/acpica/utids.c
index fa69071db418..bfca7b4b6731 100644
--- a/drivers/acpi/acpica/utids.c
+++ b/drivers/acpi/acpica/utids.c
@@ -184,7 +184,7 @@ acpi_ut_execute_SUB(struct acpi_namespace_node *device_node,
184 sub->length = length; 184 sub->length = length;
185 *return_id = sub; 185 *return_id = sub;
186 186
187 cleanup: 187cleanup:
188 188
189 /* On exit, we must delete the return object */ 189 /* On exit, we must delete the return object */
190 190
diff --git a/drivers/acpi/acpica/utobject.c b/drivers/acpi/acpica/utobject.c
index aa61f66ee861..13e045025c33 100644
--- a/drivers/acpi/acpica/utobject.c
+++ b/drivers/acpi/acpica/utobject.c
@@ -180,7 +180,7 @@ union acpi_operand_object *acpi_ut_create_package_object(u32 count)
180 package_elements = ACPI_ALLOCATE_ZEROED(((acpi_size) count + 180 package_elements = ACPI_ALLOCATE_ZEROED(((acpi_size) count +
181 1) * sizeof(void *)); 181 1) * sizeof(void *));
182 if (!package_elements) { 182 if (!package_elements) {
183 acpi_ut_remove_reference(package_desc); 183 ACPI_FREE(package_desc);
184 return_PTR(NULL); 184 return_PTR(NULL);
185 } 185 }
186 186
@@ -396,7 +396,6 @@ void *acpi_ut_allocate_object_desc_dbg(const char *module_name,
396 396
397 /* Mark the descriptor type */ 397 /* Mark the descriptor type */
398 398
399 memset(object, 0, sizeof(union acpi_operand_object));
400 ACPI_SET_DESCRIPTOR_TYPE(object, ACPI_DESC_TYPE_OPERAND); 399 ACPI_SET_DESCRIPTOR_TYPE(object, ACPI_DESC_TYPE_OPERAND);
401 400
402 ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS, "%p Size %X\n", 401 ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS, "%p Size %X\n",
@@ -461,25 +460,28 @@ acpi_ut_get_simple_object_size(union acpi_operand_object *internal_object,
461 460
462 ACPI_FUNCTION_TRACE_PTR(ut_get_simple_object_size, internal_object); 461 ACPI_FUNCTION_TRACE_PTR(ut_get_simple_object_size, internal_object);
463 462
463 /* Start with the length of the (external) Acpi object */
464
465 length = sizeof(union acpi_object);
466
467 /* A NULL object is allowed, can be a legal uninitialized package element */
468
469 if (!internal_object) {
464 /* 470 /*
465 * Handle a null object (Could be a uninitialized package 471 * Object is NULL, just return the length of union acpi_object
466 * element -- which is legal) 472 * (A NULL union acpi_object is an object of all zeroes.)
467 */ 473 */
468 if (!internal_object) { 474 *obj_length = ACPI_ROUND_UP_TO_NATIVE_WORD(length);
469 *obj_length = sizeof(union acpi_object);
470 return_ACPI_STATUS(AE_OK); 475 return_ACPI_STATUS(AE_OK);
471 } 476 }
472 477
473 /* Start with the length of the Acpi object */ 478 /* A Namespace Node should never appear here */
474
475 length = sizeof(union acpi_object);
476 479
477 if (ACPI_GET_DESCRIPTOR_TYPE(internal_object) == ACPI_DESC_TYPE_NAMED) { 480 if (ACPI_GET_DESCRIPTOR_TYPE(internal_object) == ACPI_DESC_TYPE_NAMED) {
478 481
479 /* Object is a named object (reference), just return the length */ 482 /* A namespace node should never get here */
480 483
481 *obj_length = ACPI_ROUND_UP_TO_NATIVE_WORD(length); 484 return_ACPI_STATUS(AE_AML_INTERNAL);
482 return_ACPI_STATUS(status);
483 } 485 }
484 486
485 /* 487 /*
diff --git a/drivers/acpi/acpica/utownerid.c b/drivers/acpi/acpica/utownerid.c
index 835340b26d37..eb3aca761369 100644
--- a/drivers/acpi/acpica/utownerid.c
+++ b/drivers/acpi/acpica/utownerid.c
@@ -148,7 +148,7 @@ acpi_status acpi_ut_allocate_owner_id(acpi_owner_id * owner_id)
148 ACPI_ERROR((AE_INFO, 148 ACPI_ERROR((AE_INFO,
149 "Could not allocate new OwnerId (255 max), AE_OWNER_ID_LIMIT")); 149 "Could not allocate new OwnerId (255 max), AE_OWNER_ID_LIMIT"));
150 150
151 exit: 151exit:
152 (void)acpi_ut_release_mutex(ACPI_MTX_CACHES); 152 (void)acpi_ut_release_mutex(ACPI_MTX_CACHES);
153 return_ACPI_STATUS(status); 153 return_ACPI_STATUS(status);
154} 154}
diff --git a/drivers/acpi/acpica/utresrc.c b/drivers/acpi/acpica/utresrc.c
index cb7fa491decf..2c2accb9e534 100644
--- a/drivers/acpi/acpica/utresrc.c
+++ b/drivers/acpi/acpica/utresrc.c
@@ -643,7 +643,7 @@ acpi_ut_validate_resource(struct acpi_walk_state *walk_state,
643 643
644 return (AE_OK); 644 return (AE_OK);
645 645
646 invalid_resource: 646invalid_resource:
647 647
648 if (walk_state) { 648 if (walk_state) {
649 ACPI_ERROR((AE_INFO, 649 ACPI_ERROR((AE_INFO,
@@ -652,7 +652,7 @@ acpi_ut_validate_resource(struct acpi_walk_state *walk_state,
652 } 652 }
653 return (AE_AML_INVALID_RESOURCE_TYPE); 653 return (AE_AML_INVALID_RESOURCE_TYPE);
654 654
655 bad_resource_length: 655bad_resource_length:
656 656
657 if (walk_state) { 657 if (walk_state) {
658 ACPI_ERROR((AE_INFO, 658 ACPI_ERROR((AE_INFO,
diff --git a/drivers/acpi/acpica/utstate.c b/drivers/acpi/acpica/utstate.c
index a6b729d4c1dc..03c4c2febd84 100644
--- a/drivers/acpi/acpica/utstate.c
+++ b/drivers/acpi/acpica/utstate.c
@@ -161,7 +161,6 @@ union acpi_generic_state *acpi_ut_create_generic_state(void)
161 if (state) { 161 if (state) {
162 162
163 /* Initialize */ 163 /* Initialize */
164 memset(state, 0, sizeof(union acpi_generic_state));
165 state->common.descriptor_type = ACPI_DESC_TYPE_STATE; 164 state->common.descriptor_type = ACPI_DESC_TYPE_STATE;
166 } 165 }
167 166
diff --git a/drivers/acpi/acpica/utstring.c b/drivers/acpi/acpica/utstring.c
index cb1e9cc32d5f..45c0eb26b33d 100644
--- a/drivers/acpi/acpica/utstring.c
+++ b/drivers/acpi/acpica/utstring.c
@@ -310,7 +310,7 @@ acpi_status acpi_ut_strtoul64(char *string, u32 base, u64 *ret_integer)
310 310
311 /* All done, normal exit */ 311 /* All done, normal exit */
312 312
313 all_done: 313all_done:
314 314
315 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Converted value: %8.8X%8.8X\n", 315 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Converted value: %8.8X%8.8X\n",
316 ACPI_FORMAT_UINT64(return_value))); 316 ACPI_FORMAT_UINT64(return_value)));
@@ -318,7 +318,7 @@ acpi_status acpi_ut_strtoul64(char *string, u32 base, u64 *ret_integer)
318 *ret_integer = return_value; 318 *ret_integer = return_value;
319 return_ACPI_STATUS(AE_OK); 319 return_ACPI_STATUS(AE_OK);
320 320
321 error_exit: 321error_exit:
322 /* Base was set/validated above */ 322 /* Base was set/validated above */
323 323
324 if (base == 10) { 324 if (base == 10) {
@@ -584,3 +584,65 @@ void ut_convert_backslashes(char *pathname)
584 } 584 }
585} 585}
586#endif 586#endif
587
588#if defined (ACPI_DEBUGGER) || defined (ACPI_APPLICATION)
589/*******************************************************************************
590 *
591 * FUNCTION: acpi_ut_safe_strcpy, acpi_ut_safe_strcat, acpi_ut_safe_strncat
592 *
593 * PARAMETERS: Adds a "DestSize" parameter to each of the standard string
594 * functions. This is the size of the Destination buffer.
595 *
596 * RETURN: TRUE if the operation would overflow the destination buffer.
597 *
598 * DESCRIPTION: Safe versions of standard Clib string functions. Ensure that
599 * the result of the operation will not overflow the output string
600 * buffer.
601 *
602 * NOTE: These functions are typically only helpful for processing
603 * user input and command lines. For most ACPICA code, the
604 * required buffer length is precisely calculated before buffer
605 * allocation, so the use of these functions is unnecessary.
606 *
607 ******************************************************************************/
608
609u8 acpi_ut_safe_strcpy(char *dest, acpi_size dest_size, char *source)
610{
611
612 if (ACPI_STRLEN(source) >= dest_size) {
613 return (TRUE);
614 }
615
616 ACPI_STRCPY(dest, source);
617 return (FALSE);
618}
619
620u8 acpi_ut_safe_strcat(char *dest, acpi_size dest_size, char *source)
621{
622
623 if ((ACPI_STRLEN(dest) + ACPI_STRLEN(source)) >= dest_size) {
624 return (TRUE);
625 }
626
627 ACPI_STRCAT(dest, source);
628 return (FALSE);
629}
630
631u8
632acpi_ut_safe_strncat(char *dest,
633 acpi_size dest_size,
634 char *source, acpi_size max_transfer_length)
635{
636 acpi_size actual_transfer_length;
637
638 actual_transfer_length =
639 ACPI_MIN(max_transfer_length, ACPI_STRLEN(source));
640
641 if ((ACPI_STRLEN(dest) + actual_transfer_length) >= dest_size) {
642 return (TRUE);
643 }
644
645 ACPI_STRNCAT(dest, source, max_transfer_length);
646 return (FALSE);
647}
648#endif
diff --git a/drivers/acpi/acpica/uttrack.c b/drivers/acpi/acpica/uttrack.c
index 160f13f4aab5..c0027773cccb 100644
--- a/drivers/acpi/acpica/uttrack.c
+++ b/drivers/acpi/acpica/uttrack.c
@@ -130,10 +130,23 @@ void *acpi_ut_allocate_and_track(acpi_size size,
130 struct acpi_debug_mem_block *allocation; 130 struct acpi_debug_mem_block *allocation;
131 acpi_status status; 131 acpi_status status;
132 132
133 /* Check for an inadvertent size of zero bytes */
134
135 if (!size) {
136 ACPI_WARNING((module, line,
137 "Attempt to allocate zero bytes, allocating 1 byte"));
138 size = 1;
139 }
140
133 allocation = 141 allocation =
134 acpi_ut_allocate(size + sizeof(struct acpi_debug_mem_header), 142 acpi_os_allocate(size + sizeof(struct acpi_debug_mem_header));
135 component, module, line);
136 if (!allocation) { 143 if (!allocation) {
144
145 /* Report allocation error */
146
147 ACPI_WARNING((module, line,
148 "Could not allocate size %u", (u32)size));
149
137 return (NULL); 150 return (NULL);
138 } 151 }
139 152
@@ -179,9 +192,17 @@ void *acpi_ut_allocate_zeroed_and_track(acpi_size size,
179 struct acpi_debug_mem_block *allocation; 192 struct acpi_debug_mem_block *allocation;
180 acpi_status status; 193 acpi_status status;
181 194
195 /* Check for an inadvertent size of zero bytes */
196
197 if (!size) {
198 ACPI_WARNING((module, line,
199 "Attempt to allocate zero bytes, allocating 1 byte"));
200 size = 1;
201 }
202
182 allocation = 203 allocation =
183 acpi_ut_allocate_zeroed(size + sizeof(struct acpi_debug_mem_header), 204 acpi_os_allocate_zeroed(size +
184 component, module, line); 205 sizeof(struct acpi_debug_mem_header));
185 if (!allocation) { 206 if (!allocation) {
186 207
187 /* Report allocation error */ 208 /* Report allocation error */
@@ -409,7 +430,7 @@ acpi_ut_track_allocation(struct acpi_debug_mem_block *allocation,
409 element->next = allocation; 430 element->next = allocation;
410 } 431 }
411 432
412 unlock_and_exit: 433unlock_and_exit:
413 status = acpi_ut_release_mutex(ACPI_MTX_MEMORY); 434 status = acpi_ut_release_mutex(ACPI_MTX_MEMORY);
414 return_ACPI_STATUS(status); 435 return_ACPI_STATUS(status);
415} 436}
diff --git a/drivers/acpi/acpica/utxface.c b/drivers/acpi/acpica/utxface.c
index 03a211e6e26a..be322c83643a 100644
--- a/drivers/acpi/acpica/utxface.c
+++ b/drivers/acpi/acpica/utxface.c
@@ -41,7 +41,8 @@
41 * POSSIBILITY OF SUCH DAMAGES. 41 * POSSIBILITY OF SUCH DAMAGES.
42 */ 42 */
43 43
44#include <linux/export.h> 44#define EXPORT_ACPI_INTERFACES
45
45#include <acpi/acpi.h> 46#include <acpi/acpi.h>
46#include "accommon.h" 47#include "accommon.h"
47#include "acdebug.h" 48#include "acdebug.h"
@@ -60,7 +61,7 @@ ACPI_MODULE_NAME("utxface")
60 * DESCRIPTION: Shutdown the ACPICA subsystem and release all resources. 61 * DESCRIPTION: Shutdown the ACPICA subsystem and release all resources.
61 * 62 *
62 ******************************************************************************/ 63 ******************************************************************************/
63acpi_status acpi_terminate(void) 64acpi_status __init acpi_terminate(void)
64{ 65{
65 acpi_status status; 66 acpi_status status;
66 67
@@ -104,7 +105,7 @@ acpi_status acpi_terminate(void)
104 return_ACPI_STATUS(status); 105 return_ACPI_STATUS(status);
105} 106}
106 107
107ACPI_EXPORT_SYMBOL(acpi_terminate) 108ACPI_EXPORT_SYMBOL_INIT(acpi_terminate)
108 109
109#ifndef ACPI_ASL_COMPILER 110#ifndef ACPI_ASL_COMPILER
110#ifdef ACPI_FUTURE_USAGE 111#ifdef ACPI_FUTURE_USAGE
@@ -207,6 +208,44 @@ acpi_status acpi_get_system_info(struct acpi_buffer * out_buffer)
207 208
208ACPI_EXPORT_SYMBOL(acpi_get_system_info) 209ACPI_EXPORT_SYMBOL(acpi_get_system_info)
209 210
211/*******************************************************************************
212 *
213 * FUNCTION: acpi_get_statistics
214 *
215 * PARAMETERS: stats - Where the statistics are returned
216 *
217 * RETURN: status - the status of the call
218 *
219 * DESCRIPTION: Get the contents of the various system counters
220 *
221 ******************************************************************************/
222acpi_status acpi_get_statistics(struct acpi_statistics *stats)
223{
224 ACPI_FUNCTION_TRACE(acpi_get_statistics);
225
226 /* Parameter validation */
227
228 if (!stats) {
229 return_ACPI_STATUS(AE_BAD_PARAMETER);
230 }
231
232 /* Various interrupt-based event counters */
233
234 stats->sci_count = acpi_sci_count;
235 stats->gpe_count = acpi_gpe_count;
236
237 ACPI_MEMCPY(stats->fixed_event_count, acpi_fixed_event_count,
238 sizeof(acpi_fixed_event_count));
239
240 /* Other counters */
241
242 stats->method_count = acpi_method_count;
243
244 return_ACPI_STATUS(AE_OK);
245}
246
247ACPI_EXPORT_SYMBOL(acpi_get_statistics)
248
210/***************************************************************************** 249/*****************************************************************************
211 * 250 *
212 * FUNCTION: acpi_install_initialization_handler 251 * FUNCTION: acpi_install_initialization_handler
diff --git a/drivers/acpi/acpica/utxferror.c b/drivers/acpi/acpica/utxferror.c
index e966a2e47b76..f7edb88f6054 100644
--- a/drivers/acpi/acpica/utxferror.c
+++ b/drivers/acpi/acpica/utxferror.c
@@ -41,7 +41,8 @@
41 * POSSIBILITY OF SUCH DAMAGES. 41 * POSSIBILITY OF SUCH DAMAGES.
42 */ 42 */
43 43
44#include <linux/export.h> 44#define EXPORT_ACPI_INTERFACES
45
45#include <acpi/acpi.h> 46#include <acpi/acpi.h>
46#include "accommon.h" 47#include "accommon.h"
47 48
diff --git a/drivers/acpi/acpica/utxfinit.c b/drivers/acpi/acpica/utxfinit.c
index 41ebaaf8bb1a..75efea0539c1 100644
--- a/drivers/acpi/acpica/utxfinit.c
+++ b/drivers/acpi/acpica/utxfinit.c
@@ -41,7 +41,8 @@
41 * POSSIBILITY OF SUCH DAMAGES. 41 * POSSIBILITY OF SUCH DAMAGES.
42 */ 42 */
43 43
44#include <linux/export.h> 44#define EXPORT_ACPI_INTERFACES
45
45#include <acpi/acpi.h> 46#include <acpi/acpi.h>
46#include "accommon.h" 47#include "accommon.h"
47#include "acevents.h" 48#include "acevents.h"
@@ -64,7 +65,7 @@ ACPI_MODULE_NAME("utxfinit")
64 * called, so any early initialization belongs here. 65 * called, so any early initialization belongs here.
65 * 66 *
66 ******************************************************************************/ 67 ******************************************************************************/
67acpi_status acpi_initialize_subsystem(void) 68acpi_status __init acpi_initialize_subsystem(void)
68{ 69{
69 acpi_status status; 70 acpi_status status;
70 71
@@ -124,7 +125,8 @@ acpi_status acpi_initialize_subsystem(void)
124 ACPI_DEBUGGER_EXEC(status = acpi_db_initialize()); 125 ACPI_DEBUGGER_EXEC(status = acpi_db_initialize());
125 return_ACPI_STATUS(status); 126 return_ACPI_STATUS(status);
126} 127}
127ACPI_EXPORT_SYMBOL(acpi_initialize_subsystem) 128
129ACPI_EXPORT_SYMBOL_INIT(acpi_initialize_subsystem)
128 130
129/******************************************************************************* 131/*******************************************************************************
130 * 132 *
@@ -138,7 +140,7 @@ ACPI_EXPORT_SYMBOL(acpi_initialize_subsystem)
138 * Puts system into ACPI mode if it isn't already. 140 * Puts system into ACPI mode if it isn't already.
139 * 141 *
140 ******************************************************************************/ 142 ******************************************************************************/
141acpi_status acpi_enable_subsystem(u32 flags) 143acpi_status __init acpi_enable_subsystem(u32 flags)
142{ 144{
143 acpi_status status = AE_OK; 145 acpi_status status = AE_OK;
144 146
@@ -228,7 +230,8 @@ acpi_status acpi_enable_subsystem(u32 flags)
228 230
229 return_ACPI_STATUS(status); 231 return_ACPI_STATUS(status);
230} 232}
231ACPI_EXPORT_SYMBOL(acpi_enable_subsystem) 233
234ACPI_EXPORT_SYMBOL_INIT(acpi_enable_subsystem)
232 235
233/******************************************************************************* 236/*******************************************************************************
234 * 237 *
@@ -242,7 +245,7 @@ ACPI_EXPORT_SYMBOL(acpi_enable_subsystem)
242 * objects and executing AML code for Regions, buffers, etc. 245 * objects and executing AML code for Regions, buffers, etc.
243 * 246 *
244 ******************************************************************************/ 247 ******************************************************************************/
245acpi_status acpi_initialize_objects(u32 flags) 248acpi_status __init acpi_initialize_objects(u32 flags)
246{ 249{
247 acpi_status status = AE_OK; 250 acpi_status status = AE_OK;
248 251
@@ -314,4 +317,5 @@ acpi_status acpi_initialize_objects(u32 flags)
314 acpi_gbl_startup_flags |= ACPI_INITIALIZED_OK; 317 acpi_gbl_startup_flags |= ACPI_INITIALIZED_OK;
315 return_ACPI_STATUS(status); 318 return_ACPI_STATUS(status);
316} 319}
317ACPI_EXPORT_SYMBOL(acpi_initialize_objects) 320
321ACPI_EXPORT_SYMBOL_INIT(acpi_initialize_objects)
diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index 2c9958cd7a43..fbf1aceda8b8 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -36,12 +36,6 @@
36#include <linux/suspend.h> 36#include <linux/suspend.h>
37#include <asm/unaligned.h> 37#include <asm/unaligned.h>
38 38
39#ifdef CONFIG_ACPI_PROCFS_POWER
40#include <linux/proc_fs.h>
41#include <linux/seq_file.h>
42#include <asm/uaccess.h>
43#endif
44
45#include <acpi/acpi_bus.h> 39#include <acpi/acpi_bus.h>
46#include <acpi/acpi_drivers.h> 40#include <acpi/acpi_drivers.h>
47#include <linux/power_supply.h> 41#include <linux/power_supply.h>
@@ -72,19 +66,6 @@ static unsigned int cache_time = 1000;
72module_param(cache_time, uint, 0644); 66module_param(cache_time, uint, 0644);
73MODULE_PARM_DESC(cache_time, "cache time in milliseconds"); 67MODULE_PARM_DESC(cache_time, "cache time in milliseconds");
74 68
75#ifdef CONFIG_ACPI_PROCFS_POWER
76extern struct proc_dir_entry *acpi_lock_battery_dir(void);
77extern void *acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir);
78
79enum acpi_battery_files {
80 info_tag = 0,
81 state_tag,
82 alarm_tag,
83 ACPI_BATTERY_NUMFILES,
84};
85
86#endif
87
88static const struct acpi_device_id battery_device_ids[] = { 69static const struct acpi_device_id battery_device_ids[] = {
89 {"PNP0C0A", 0}, 70 {"PNP0C0A", 0},
90 {"", 0}, 71 {"", 0},
@@ -320,14 +301,6 @@ static enum power_supply_property energy_battery_props[] = {
320 POWER_SUPPLY_PROP_SERIAL_NUMBER, 301 POWER_SUPPLY_PROP_SERIAL_NUMBER,
321}; 302};
322 303
323#ifdef CONFIG_ACPI_PROCFS_POWER
324inline char *acpi_battery_units(struct acpi_battery *battery)
325{
326 return (battery->power_unit == ACPI_BATTERY_POWER_UNIT_MA) ?
327 "mA" : "mW";
328}
329#endif
330
331/* -------------------------------------------------------------------------- 304/* --------------------------------------------------------------------------
332 Battery Management 305 Battery Management
333 -------------------------------------------------------------------------- */ 306 -------------------------------------------------------------------------- */
@@ -741,279 +714,6 @@ static void acpi_battery_refresh(struct acpi_battery *battery)
741} 714}
742 715
743/* -------------------------------------------------------------------------- 716/* --------------------------------------------------------------------------
744 FS Interface (/proc)
745 -------------------------------------------------------------------------- */
746
747#ifdef CONFIG_ACPI_PROCFS_POWER
748static struct proc_dir_entry *acpi_battery_dir;
749
750static int acpi_battery_print_info(struct seq_file *seq, int result)
751{
752 struct acpi_battery *battery = seq->private;
753
754 if (result)
755 goto end;
756
757 seq_printf(seq, "present: %s\n",
758 acpi_battery_present(battery) ? "yes" : "no");
759 if (!acpi_battery_present(battery))
760 goto end;
761 if (battery->design_capacity == ACPI_BATTERY_VALUE_UNKNOWN)
762 seq_printf(seq, "design capacity: unknown\n");
763 else
764 seq_printf(seq, "design capacity: %d %sh\n",
765 battery->design_capacity,
766 acpi_battery_units(battery));
767
768 if (battery->full_charge_capacity == ACPI_BATTERY_VALUE_UNKNOWN)
769 seq_printf(seq, "last full capacity: unknown\n");
770 else
771 seq_printf(seq, "last full capacity: %d %sh\n",
772 battery->full_charge_capacity,
773 acpi_battery_units(battery));
774
775 seq_printf(seq, "battery technology: %srechargeable\n",
776 (!battery->technology)?"non-":"");
777
778 if (battery->design_voltage == ACPI_BATTERY_VALUE_UNKNOWN)
779 seq_printf(seq, "design voltage: unknown\n");
780 else
781 seq_printf(seq, "design voltage: %d mV\n",
782 battery->design_voltage);
783 seq_printf(seq, "design capacity warning: %d %sh\n",
784 battery->design_capacity_warning,
785 acpi_battery_units(battery));
786 seq_printf(seq, "design capacity low: %d %sh\n",
787 battery->design_capacity_low,
788 acpi_battery_units(battery));
789 seq_printf(seq, "cycle count: %i\n", battery->cycle_count);
790 seq_printf(seq, "capacity granularity 1: %d %sh\n",
791 battery->capacity_granularity_1,
792 acpi_battery_units(battery));
793 seq_printf(seq, "capacity granularity 2: %d %sh\n",
794 battery->capacity_granularity_2,
795 acpi_battery_units(battery));
796 seq_printf(seq, "model number: %s\n", battery->model_number);
797 seq_printf(seq, "serial number: %s\n", battery->serial_number);
798 seq_printf(seq, "battery type: %s\n", battery->type);
799 seq_printf(seq, "OEM info: %s\n", battery->oem_info);
800 end:
801 if (result)
802 seq_printf(seq, "ERROR: Unable to read battery info\n");
803 return result;
804}
805
806static int acpi_battery_print_state(struct seq_file *seq, int result)
807{
808 struct acpi_battery *battery = seq->private;
809
810 if (result)
811 goto end;
812
813 seq_printf(seq, "present: %s\n",
814 acpi_battery_present(battery) ? "yes" : "no");
815 if (!acpi_battery_present(battery))
816 goto end;
817
818 seq_printf(seq, "capacity state: %s\n",
819 (battery->state & 0x04) ? "critical" : "ok");
820 if ((battery->state & 0x01) && (battery->state & 0x02))
821 seq_printf(seq,
822 "charging state: charging/discharging\n");
823 else if (battery->state & 0x01)
824 seq_printf(seq, "charging state: discharging\n");
825 else if (battery->state & 0x02)
826 seq_printf(seq, "charging state: charging\n");
827 else
828 seq_printf(seq, "charging state: charged\n");
829
830 if (battery->rate_now == ACPI_BATTERY_VALUE_UNKNOWN)
831 seq_printf(seq, "present rate: unknown\n");
832 else
833 seq_printf(seq, "present rate: %d %s\n",
834 battery->rate_now, acpi_battery_units(battery));
835
836 if (battery->capacity_now == ACPI_BATTERY_VALUE_UNKNOWN)
837 seq_printf(seq, "remaining capacity: unknown\n");
838 else
839 seq_printf(seq, "remaining capacity: %d %sh\n",
840 battery->capacity_now, acpi_battery_units(battery));
841 if (battery->voltage_now == ACPI_BATTERY_VALUE_UNKNOWN)
842 seq_printf(seq, "present voltage: unknown\n");
843 else
844 seq_printf(seq, "present voltage: %d mV\n",
845 battery->voltage_now);
846 end:
847 if (result)
848 seq_printf(seq, "ERROR: Unable to read battery state\n");
849
850 return result;
851}
852
853static int acpi_battery_print_alarm(struct seq_file *seq, int result)
854{
855 struct acpi_battery *battery = seq->private;
856
857 if (result)
858 goto end;
859
860 if (!acpi_battery_present(battery)) {
861 seq_printf(seq, "present: no\n");
862 goto end;
863 }
864 seq_printf(seq, "alarm: ");
865 if (!battery->alarm)
866 seq_printf(seq, "unsupported\n");
867 else
868 seq_printf(seq, "%u %sh\n", battery->alarm,
869 acpi_battery_units(battery));
870 end:
871 if (result)
872 seq_printf(seq, "ERROR: Unable to read battery alarm\n");
873 return result;
874}
875
876static ssize_t acpi_battery_write_alarm(struct file *file,
877 const char __user * buffer,
878 size_t count, loff_t * ppos)
879{
880 int result = 0;
881 char alarm_string[12] = { '\0' };
882 struct seq_file *m = file->private_data;
883 struct acpi_battery *battery = m->private;
884
885 if (!battery || (count > sizeof(alarm_string) - 1))
886 return -EINVAL;
887 if (!acpi_battery_present(battery)) {
888 result = -ENODEV;
889 goto end;
890 }
891 if (copy_from_user(alarm_string, buffer, count)) {
892 result = -EFAULT;
893 goto end;
894 }
895 alarm_string[count] = '\0';
896 battery->alarm = simple_strtol(alarm_string, NULL, 0);
897 result = acpi_battery_set_alarm(battery);
898 end:
899 if (!result)
900 return count;
901 return result;
902}
903
904typedef int(*print_func)(struct seq_file *seq, int result);
905
906static print_func acpi_print_funcs[ACPI_BATTERY_NUMFILES] = {
907 acpi_battery_print_info,
908 acpi_battery_print_state,
909 acpi_battery_print_alarm,
910};
911
912static int acpi_battery_read(int fid, struct seq_file *seq)
913{
914 struct acpi_battery *battery = seq->private;
915 int result = acpi_battery_update(battery);
916 return acpi_print_funcs[fid](seq, result);
917}
918
919#define DECLARE_FILE_FUNCTIONS(_name) \
920static int acpi_battery_read_##_name(struct seq_file *seq, void *offset) \
921{ \
922 return acpi_battery_read(_name##_tag, seq); \
923} \
924static int acpi_battery_##_name##_open_fs(struct inode *inode, struct file *file) \
925{ \
926 return single_open(file, acpi_battery_read_##_name, PDE_DATA(inode)); \
927}
928
929DECLARE_FILE_FUNCTIONS(info);
930DECLARE_FILE_FUNCTIONS(state);
931DECLARE_FILE_FUNCTIONS(alarm);
932
933#undef DECLARE_FILE_FUNCTIONS
934
935#define FILE_DESCRIPTION_RO(_name) \
936 { \
937 .name = __stringify(_name), \
938 .mode = S_IRUGO, \
939 .ops = { \
940 .open = acpi_battery_##_name##_open_fs, \
941 .read = seq_read, \
942 .llseek = seq_lseek, \
943 .release = single_release, \
944 .owner = THIS_MODULE, \
945 }, \
946 }
947
948#define FILE_DESCRIPTION_RW(_name) \
949 { \
950 .name = __stringify(_name), \
951 .mode = S_IFREG | S_IRUGO | S_IWUSR, \
952 .ops = { \
953 .open = acpi_battery_##_name##_open_fs, \
954 .read = seq_read, \
955 .llseek = seq_lseek, \
956 .write = acpi_battery_write_##_name, \
957 .release = single_release, \
958 .owner = THIS_MODULE, \
959 }, \
960 }
961
962static const struct battery_file {
963 struct file_operations ops;
964 umode_t mode;
965 const char *name;
966} acpi_battery_file[] = {
967 FILE_DESCRIPTION_RO(info),
968 FILE_DESCRIPTION_RO(state),
969 FILE_DESCRIPTION_RW(alarm),
970};
971
972#undef FILE_DESCRIPTION_RO
973#undef FILE_DESCRIPTION_RW
974
975static int acpi_battery_add_fs(struct acpi_device *device)
976{
977 struct proc_dir_entry *entry = NULL;
978 int i;
979
980 printk(KERN_WARNING PREFIX "Deprecated procfs I/F for battery is loaded,"
981 " please retry with CONFIG_ACPI_PROCFS_POWER cleared\n");
982 if (!acpi_device_dir(device)) {
983 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
984 acpi_battery_dir);
985 if (!acpi_device_dir(device))
986 return -ENODEV;
987 }
988
989 for (i = 0; i < ACPI_BATTERY_NUMFILES; ++i) {
990 entry = proc_create_data(acpi_battery_file[i].name,
991 acpi_battery_file[i].mode,
992 acpi_device_dir(device),
993 &acpi_battery_file[i].ops,
994 acpi_driver_data(device));
995 if (!entry)
996 return -ENODEV;
997 }
998 return 0;
999}
1000
1001static void acpi_battery_remove_fs(struct acpi_device *device)
1002{
1003 int i;
1004 if (!acpi_device_dir(device))
1005 return;
1006 for (i = 0; i < ACPI_BATTERY_NUMFILES; ++i)
1007 remove_proc_entry(acpi_battery_file[i].name,
1008 acpi_device_dir(device));
1009
1010 remove_proc_entry(acpi_device_bid(device), acpi_battery_dir);
1011 acpi_device_dir(device) = NULL;
1012}
1013
1014#endif
1015
1016/* --------------------------------------------------------------------------
1017 Driver Interface 717 Driver Interface
1018 -------------------------------------------------------------------------- */ 718 -------------------------------------------------------------------------- */
1019 719
@@ -1075,15 +775,6 @@ static int acpi_battery_add(struct acpi_device *device)
1075 result = acpi_battery_update(battery); 775 result = acpi_battery_update(battery);
1076 if (result) 776 if (result)
1077 goto fail; 777 goto fail;
1078#ifdef CONFIG_ACPI_PROCFS_POWER
1079 result = acpi_battery_add_fs(device);
1080#endif
1081 if (result) {
1082#ifdef CONFIG_ACPI_PROCFS_POWER
1083 acpi_battery_remove_fs(device);
1084#endif
1085 goto fail;
1086 }
1087 778
1088 printk(KERN_INFO PREFIX "%s Slot [%s] (battery %s)\n", 779 printk(KERN_INFO PREFIX "%s Slot [%s] (battery %s)\n",
1089 ACPI_BATTERY_DEVICE_NAME, acpi_device_bid(device), 780 ACPI_BATTERY_DEVICE_NAME, acpi_device_bid(device),
@@ -1110,9 +801,6 @@ static int acpi_battery_remove(struct acpi_device *device)
1110 return -EINVAL; 801 return -EINVAL;
1111 battery = acpi_driver_data(device); 802 battery = acpi_driver_data(device);
1112 unregister_pm_notifier(&battery->pm_nb); 803 unregister_pm_notifier(&battery->pm_nb);
1113#ifdef CONFIG_ACPI_PROCFS_POWER
1114 acpi_battery_remove_fs(device);
1115#endif
1116 sysfs_remove_battery(battery); 804 sysfs_remove_battery(battery);
1117 mutex_destroy(&battery->lock); 805 mutex_destroy(&battery->lock);
1118 mutex_destroy(&battery->sysfs_lock); 806 mutex_destroy(&battery->sysfs_lock);
@@ -1158,18 +846,7 @@ static void __init acpi_battery_init_async(void *unused, async_cookie_t cookie)
1158{ 846{
1159 if (acpi_disabled) 847 if (acpi_disabled)
1160 return; 848 return;
1161#ifdef CONFIG_ACPI_PROCFS_POWER 849 acpi_bus_register_driver(&acpi_battery_driver);
1162 acpi_battery_dir = acpi_lock_battery_dir();
1163 if (!acpi_battery_dir)
1164 return;
1165#endif
1166 if (acpi_bus_register_driver(&acpi_battery_driver) < 0) {
1167#ifdef CONFIG_ACPI_PROCFS_POWER
1168 acpi_unlock_battery_dir(acpi_battery_dir);
1169#endif
1170 return;
1171 }
1172 return;
1173} 850}
1174 851
1175static int __init acpi_battery_init(void) 852static int __init acpi_battery_init(void)
@@ -1181,9 +858,6 @@ static int __init acpi_battery_init(void)
1181static void __exit acpi_battery_exit(void) 858static void __exit acpi_battery_exit(void)
1182{ 859{
1183 acpi_bus_unregister_driver(&acpi_battery_driver); 860 acpi_bus_unregister_driver(&acpi_battery_driver);
1184#ifdef CONFIG_ACPI_PROCFS_POWER
1185 acpi_unlock_battery_dir(acpi_battery_dir);
1186#endif
1187} 861}
1188 862
1189module_init(acpi_battery_init); 863module_init(acpi_battery_init);
diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
index 9515f18898b2..fb848378d582 100644
--- a/drivers/acpi/blacklist.c
+++ b/drivers/acpi/blacklist.c
@@ -274,6 +274,19 @@ static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
274 }, 274 },
275 }, 275 },
276 { 276 {
277 .callback = dmi_disable_osi_vista,
278 .ident = "Toshiba NB100",
279 .matches = {
280 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
281 DMI_MATCH(DMI_PRODUCT_NAME, "NB100"),
282 },
283 },
284
285 /*
286 * The following machines have broken backlight support when reporting
287 * the Windows 2012 OSI, so disable it until their support is fixed.
288 */
289 {
277 .callback = dmi_disable_osi_win8, 290 .callback = dmi_disable_osi_win8,
278 .ident = "ASUS Zenbook Prime UX31A", 291 .ident = "ASUS Zenbook Prime UX31A",
279 .matches = { 292 .matches = {
@@ -291,12 +304,60 @@ static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
291 }, 304 },
292 { 305 {
293 .callback = dmi_disable_osi_win8, 306 .callback = dmi_disable_osi_win8,
294 .ident = "Lenovo ThinkPad Edge E530", 307 .ident = "ThinkPad Edge E530",
295 .matches = { 308 .matches = {
296 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), 309 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
297 DMI_MATCH(DMI_PRODUCT_VERSION, "3259A2G"), 310 DMI_MATCH(DMI_PRODUCT_VERSION, "3259A2G"),
298 }, 311 },
299 }, 312 },
313 {
314 .callback = dmi_disable_osi_win8,
315 .ident = "ThinkPad Edge E530",
316 .matches = {
317 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
318 DMI_MATCH(DMI_PRODUCT_VERSION, "3259CTO"),
319 },
320 },
321 {
322 .callback = dmi_disable_osi_win8,
323 .ident = "ThinkPad Edge E530",
324 .matches = {
325 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
326 DMI_MATCH(DMI_PRODUCT_VERSION, "3259HJG"),
327 },
328 },
329 {
330 .callback = dmi_disable_osi_win8,
331 .ident = "Acer Aspire V5-573G",
332 .matches = {
333 DMI_MATCH(DMI_SYS_VENDOR, "Acer Aspire"),
334 DMI_MATCH(DMI_PRODUCT_VERSION, "V5-573G/Dazzle_HW"),
335 },
336 },
337 {
338 .callback = dmi_disable_osi_win8,
339 .ident = "Acer Aspire V5-572G",
340 .matches = {
341 DMI_MATCH(DMI_SYS_VENDOR, "Acer Aspire"),
342 DMI_MATCH(DMI_PRODUCT_VERSION, "V5-572G/Dazzle_CX"),
343 },
344 },
345 {
346 .callback = dmi_disable_osi_win8,
347 .ident = "ThinkPad T431s",
348 .matches = {
349 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
350 DMI_MATCH(DMI_PRODUCT_VERSION, "20AACTO1WW"),
351 },
352 },
353 {
354 .callback = dmi_disable_osi_win8,
355 .ident = "ThinkPad T430",
356 .matches = {
357 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
358 DMI_MATCH(DMI_PRODUCT_VERSION, "2349D15"),
359 },
360 },
300 361
301 /* 362 /*
302 * BIOS invocation of _OSI(Linux) is almost always a BIOS bug. 363 * BIOS invocation of _OSI(Linux) is almost always a BIOS bug.
diff --git a/drivers/acpi/button.c b/drivers/acpi/button.c
index a55773801c5f..c971929d75c2 100644
--- a/drivers/acpi/button.c
+++ b/drivers/acpi/button.c
@@ -383,18 +383,15 @@ static int acpi_button_add(struct acpi_device *device)
383 383
384 switch (button->type) { 384 switch (button->type) {
385 case ACPI_BUTTON_TYPE_POWER: 385 case ACPI_BUTTON_TYPE_POWER:
386 input->evbit[0] = BIT_MASK(EV_KEY); 386 input_set_capability(input, EV_KEY, KEY_POWER);
387 set_bit(KEY_POWER, input->keybit);
388 break; 387 break;
389 388
390 case ACPI_BUTTON_TYPE_SLEEP: 389 case ACPI_BUTTON_TYPE_SLEEP:
391 input->evbit[0] = BIT_MASK(EV_KEY); 390 input_set_capability(input, EV_KEY, KEY_SLEEP);
392 set_bit(KEY_SLEEP, input->keybit);
393 break; 391 break;
394 392
395 case ACPI_BUTTON_TYPE_LID: 393 case ACPI_BUTTON_TYPE_LID:
396 input->evbit[0] = BIT_MASK(EV_SW); 394 input_set_capability(input, EV_SW, SW_LID);
397 set_bit(SW_LID, input->swbit);
398 break; 395 break;
399 } 396 }
400 397
diff --git a/drivers/acpi/cm_sbs.c b/drivers/acpi/cm_sbs.c
deleted file mode 100644
index 6c9ee68e46fb..000000000000
--- a/drivers/acpi/cm_sbs.c
+++ /dev/null
@@ -1,105 +0,0 @@
1/*
2 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or (at
7 * your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17 *
18 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
19 */
20
21#include <linux/kernel.h>
22#include <linux/module.h>
23#include <linux/init.h>
24#include <linux/acpi.h>
25#include <linux/types.h>
26#include <linux/proc_fs.h>
27#include <linux/seq_file.h>
28#include <acpi/acpi_bus.h>
29#include <acpi/acpi_drivers.h>
30
31#define PREFIX "ACPI: "
32
33ACPI_MODULE_NAME("cm_sbs");
34#define ACPI_AC_CLASS "ac_adapter"
35#define ACPI_BATTERY_CLASS "battery"
36#define _COMPONENT ACPI_SBS_COMPONENT
37static struct proc_dir_entry *acpi_ac_dir;
38static struct proc_dir_entry *acpi_battery_dir;
39
40static DEFINE_MUTEX(cm_sbs_mutex);
41
42static int lock_ac_dir_cnt;
43static int lock_battery_dir_cnt;
44
45struct proc_dir_entry *acpi_lock_ac_dir(void)
46{
47 mutex_lock(&cm_sbs_mutex);
48 if (!acpi_ac_dir)
49 acpi_ac_dir = proc_mkdir(ACPI_AC_CLASS, acpi_root_dir);
50 if (acpi_ac_dir) {
51 lock_ac_dir_cnt++;
52 } else {
53 printk(KERN_ERR PREFIX
54 "Cannot create %s\n", ACPI_AC_CLASS);
55 }
56 mutex_unlock(&cm_sbs_mutex);
57 return acpi_ac_dir;
58}
59EXPORT_SYMBOL(acpi_lock_ac_dir);
60
61void acpi_unlock_ac_dir(struct proc_dir_entry *acpi_ac_dir_param)
62{
63 mutex_lock(&cm_sbs_mutex);
64 if (acpi_ac_dir_param)
65 lock_ac_dir_cnt--;
66 if (lock_ac_dir_cnt == 0 && acpi_ac_dir_param && acpi_ac_dir) {
67 remove_proc_entry(ACPI_AC_CLASS, acpi_root_dir);
68 acpi_ac_dir = NULL;
69 }
70 mutex_unlock(&cm_sbs_mutex);
71}
72EXPORT_SYMBOL(acpi_unlock_ac_dir);
73
74struct proc_dir_entry *acpi_lock_battery_dir(void)
75{
76 mutex_lock(&cm_sbs_mutex);
77 if (!acpi_battery_dir) {
78 acpi_battery_dir =
79 proc_mkdir(ACPI_BATTERY_CLASS, acpi_root_dir);
80 }
81 if (acpi_battery_dir) {
82 lock_battery_dir_cnt++;
83 } else {
84 printk(KERN_ERR PREFIX
85 "Cannot create %s\n", ACPI_BATTERY_CLASS);
86 }
87 mutex_unlock(&cm_sbs_mutex);
88 return acpi_battery_dir;
89}
90EXPORT_SYMBOL(acpi_lock_battery_dir);
91
92void acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir_param)
93{
94 mutex_lock(&cm_sbs_mutex);
95 if (acpi_battery_dir_param)
96 lock_battery_dir_cnt--;
97 if (lock_battery_dir_cnt == 0 && acpi_battery_dir_param
98 && acpi_battery_dir) {
99 remove_proc_entry(ACPI_BATTERY_CLASS, acpi_root_dir);
100 acpi_battery_dir = NULL;
101 }
102 mutex_unlock(&cm_sbs_mutex);
103 return;
104}
105EXPORT_SYMBOL(acpi_unlock_battery_dir);
diff --git a/drivers/acpi/device_pm.c b/drivers/acpi/device_pm.c
index a94383d1f350..d42b2fb5a7e9 100644
--- a/drivers/acpi/device_pm.c
+++ b/drivers/acpi/device_pm.c
@@ -118,9 +118,10 @@ int acpi_device_get_power(struct acpi_device *device, int *state)
118 /* 118 /*
119 * If we were unsure about the device parent's power state up to this 119 * If we were unsure about the device parent's power state up to this
120 * point, the fact that the device is in D0 implies that the parent has 120 * point, the fact that the device is in D0 implies that the parent has
121 * to be in D0 too. 121 * to be in D0 too, except if ignore_parent is set.
122 */ 122 */
123 if (device->parent && device->parent->power.state == ACPI_STATE_UNKNOWN 123 if (!device->power.flags.ignore_parent && device->parent
124 && device->parent->power.state == ACPI_STATE_UNKNOWN
124 && result == ACPI_STATE_D0) 125 && result == ACPI_STATE_D0)
125 device->parent->power.state = ACPI_STATE_D0; 126 device->parent->power.state = ACPI_STATE_D0;
126 127
@@ -177,7 +178,8 @@ int acpi_device_set_power(struct acpi_device *device, int state)
177 acpi_power_state_string(state)); 178 acpi_power_state_string(state));
178 return -ENODEV; 179 return -ENODEV;
179 } 180 }
180 if (device->parent && (state < device->parent->power.state)) { 181 if (!device->power.flags.ignore_parent &&
182 device->parent && (state < device->parent->power.state)) {
181 dev_warn(&device->dev, 183 dev_warn(&device->dev,
182 "Cannot transition to power state %s for parent in %s\n", 184 "Cannot transition to power state %s for parent in %s\n",
183 acpi_power_state_string(state), 185 acpi_power_state_string(state),
diff --git a/drivers/acpi/dock.c b/drivers/acpi/dock.c
index 05ea4be01a83..dcd73ccb514c 100644
--- a/drivers/acpi/dock.c
+++ b/drivers/acpi/dock.c
@@ -441,7 +441,7 @@ static void handle_dock(struct dock_station *ds, int dock)
441 acpi_status status; 441 acpi_status status;
442 struct acpi_object_list arg_list; 442 struct acpi_object_list arg_list;
443 union acpi_object arg; 443 union acpi_object arg;
444 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; 444 unsigned long long value;
445 445
446 acpi_handle_info(ds->handle, "%s\n", dock ? "docking" : "undocking"); 446 acpi_handle_info(ds->handle, "%s\n", dock ? "docking" : "undocking");
447 447
@@ -450,12 +450,10 @@ static void handle_dock(struct dock_station *ds, int dock)
450 arg_list.pointer = &arg; 450 arg_list.pointer = &arg;
451 arg.type = ACPI_TYPE_INTEGER; 451 arg.type = ACPI_TYPE_INTEGER;
452 arg.integer.value = dock; 452 arg.integer.value = dock;
453 status = acpi_evaluate_object(ds->handle, "_DCK", &arg_list, &buffer); 453 status = acpi_evaluate_integer(ds->handle, "_DCK", &arg_list, &value);
454 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) 454 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND)
455 acpi_handle_err(ds->handle, "Failed to execute _DCK (0x%x)\n", 455 acpi_handle_err(ds->handle, "Failed to execute _DCK (0x%x)\n",
456 status); 456 status);
457
458 kfree(buffer.pointer);
459} 457}
460 458
461static inline void dock(struct dock_station *ds) 459static inline void dock(struct dock_station *ds)
@@ -671,39 +669,20 @@ static void dock_notify(struct dock_station *ds, u32 event)
671 } 669 }
672} 670}
673 671
674struct dock_data { 672static void acpi_dock_deferred_cb(void *data, u32 event)
675 struct dock_station *ds;
676 u32 event;
677};
678
679static void acpi_dock_deferred_cb(void *context)
680{ 673{
681 struct dock_data *data = context;
682
683 acpi_scan_lock_acquire(); 674 acpi_scan_lock_acquire();
684 dock_notify(data->ds, data->event); 675 dock_notify(data, event);
685 acpi_scan_lock_release(); 676 acpi_scan_lock_release();
686 kfree(data);
687} 677}
688 678
689static void dock_notify_handler(acpi_handle handle, u32 event, void *data) 679static void dock_notify_handler(acpi_handle handle, u32 event, void *data)
690{ 680{
691 struct dock_data *dd;
692
693 if (event != ACPI_NOTIFY_BUS_CHECK && event != ACPI_NOTIFY_DEVICE_CHECK 681 if (event != ACPI_NOTIFY_BUS_CHECK && event != ACPI_NOTIFY_DEVICE_CHECK
694 && event != ACPI_NOTIFY_EJECT_REQUEST) 682 && event != ACPI_NOTIFY_EJECT_REQUEST)
695 return; 683 return;
696 684
697 dd = kmalloc(sizeof(*dd), GFP_KERNEL); 685 acpi_hotplug_execute(acpi_dock_deferred_cb, data, event);
698 if (dd) {
699 acpi_status status;
700
701 dd->ds = data;
702 dd->event = event;
703 status = acpi_os_hotplug_execute(acpi_dock_deferred_cb, dd);
704 if (ACPI_FAILURE(status))
705 kfree(dd);
706 }
707} 686}
708 687
709/** 688/**
diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c
index a06d98374705..d5309fd49458 100644
--- a/drivers/acpi/ec.c
+++ b/drivers/acpi/ec.c
@@ -28,6 +28,7 @@
28 28
29/* Uncomment next line to get verbose printout */ 29/* Uncomment next line to get verbose printout */
30/* #define DEBUG */ 30/* #define DEBUG */
31#define pr_fmt(fmt) "ACPI : EC: " fmt
31 32
32#include <linux/kernel.h> 33#include <linux/kernel.h>
33#include <linux/module.h> 34#include <linux/module.h>
@@ -49,9 +50,6 @@
49#define ACPI_EC_DEVICE_NAME "Embedded Controller" 50#define ACPI_EC_DEVICE_NAME "Embedded Controller"
50#define ACPI_EC_FILE_INFO "info" 51#define ACPI_EC_FILE_INFO "info"
51 52
52#undef PREFIX
53#define PREFIX "ACPI: EC: "
54
55/* EC status register */ 53/* EC status register */
56#define ACPI_EC_FLAG_OBF 0x01 /* Output buffer full */ 54#define ACPI_EC_FLAG_OBF 0x01 /* Output buffer full */
57#define ACPI_EC_FLAG_IBF 0x02 /* Input buffer full */ 55#define ACPI_EC_FLAG_IBF 0x02 /* Input buffer full */
@@ -131,26 +129,26 @@ static int EC_FLAGS_SKIP_DSDT_SCAN; /* Not all BIOS survive early DSDT scan */
131static inline u8 acpi_ec_read_status(struct acpi_ec *ec) 129static inline u8 acpi_ec_read_status(struct acpi_ec *ec)
132{ 130{
133 u8 x = inb(ec->command_addr); 131 u8 x = inb(ec->command_addr);
134 pr_debug(PREFIX "---> status = 0x%2.2x\n", x); 132 pr_debug("---> status = 0x%2.2x\n", x);
135 return x; 133 return x;
136} 134}
137 135
138static inline u8 acpi_ec_read_data(struct acpi_ec *ec) 136static inline u8 acpi_ec_read_data(struct acpi_ec *ec)
139{ 137{
140 u8 x = inb(ec->data_addr); 138 u8 x = inb(ec->data_addr);
141 pr_debug(PREFIX "---> data = 0x%2.2x\n", x); 139 pr_debug("---> data = 0x%2.2x\n", x);
142 return x; 140 return x;
143} 141}
144 142
145static inline void acpi_ec_write_cmd(struct acpi_ec *ec, u8 command) 143static inline void acpi_ec_write_cmd(struct acpi_ec *ec, u8 command)
146{ 144{
147 pr_debug(PREFIX "<--- command = 0x%2.2x\n", command); 145 pr_debug("<--- command = 0x%2.2x\n", command);
148 outb(command, ec->command_addr); 146 outb(command, ec->command_addr);
149} 147}
150 148
151static inline void acpi_ec_write_data(struct acpi_ec *ec, u8 data) 149static inline void acpi_ec_write_data(struct acpi_ec *ec, u8 data)
152{ 150{
153 pr_debug(PREFIX "<--- data = 0x%2.2x\n", data); 151 pr_debug("<--- data = 0x%2.2x\n", data);
154 outb(data, ec->data_addr); 152 outb(data, ec->data_addr);
155} 153}
156 154
@@ -241,7 +239,7 @@ static int ec_poll(struct acpi_ec *ec)
241 } 239 }
242 advance_transaction(ec, acpi_ec_read_status(ec)); 240 advance_transaction(ec, acpi_ec_read_status(ec));
243 } while (time_before(jiffies, delay)); 241 } while (time_before(jiffies, delay));
244 pr_debug(PREFIX "controller reset, restart transaction\n"); 242 pr_debug("controller reset, restart transaction\n");
245 spin_lock_irqsave(&ec->lock, flags); 243 spin_lock_irqsave(&ec->lock, flags);
246 start_transaction(ec); 244 start_transaction(ec);
247 spin_unlock_irqrestore(&ec->lock, flags); 245 spin_unlock_irqrestore(&ec->lock, flags);
@@ -309,12 +307,12 @@ static int acpi_ec_transaction(struct acpi_ec *ec, struct transaction *t)
309 } 307 }
310 } 308 }
311 if (ec_wait_ibf0(ec)) { 309 if (ec_wait_ibf0(ec)) {
312 pr_err(PREFIX "input buffer is not empty, " 310 pr_err("input buffer is not empty, "
313 "aborting transaction\n"); 311 "aborting transaction\n");
314 status = -ETIME; 312 status = -ETIME;
315 goto end; 313 goto end;
316 } 314 }
317 pr_debug(PREFIX "transaction start (cmd=0x%02x, addr=0x%02x)\n", 315 pr_debug("transaction start (cmd=0x%02x, addr=0x%02x)\n",
318 t->command, t->wdata ? t->wdata[0] : 0); 316 t->command, t->wdata ? t->wdata[0] : 0);
319 /* disable GPE during transaction if storm is detected */ 317 /* disable GPE during transaction if storm is detected */
320 if (test_bit(EC_FLAGS_GPE_STORM, &ec->flags)) { 318 if (test_bit(EC_FLAGS_GPE_STORM, &ec->flags)) {
@@ -331,12 +329,12 @@ static int acpi_ec_transaction(struct acpi_ec *ec, struct transaction *t)
331 /* It is safe to enable the GPE outside of the transaction. */ 329 /* It is safe to enable the GPE outside of the transaction. */
332 acpi_enable_gpe(NULL, ec->gpe); 330 acpi_enable_gpe(NULL, ec->gpe);
333 } else if (t->irq_count > ec_storm_threshold) { 331 } else if (t->irq_count > ec_storm_threshold) {
334 pr_info(PREFIX "GPE storm detected(%d GPEs), " 332 pr_info("GPE storm detected(%d GPEs), "
335 "transactions will use polling mode\n", 333 "transactions will use polling mode\n",
336 t->irq_count); 334 t->irq_count);
337 set_bit(EC_FLAGS_GPE_STORM, &ec->flags); 335 set_bit(EC_FLAGS_GPE_STORM, &ec->flags);
338 } 336 }
339 pr_debug(PREFIX "transaction end\n"); 337 pr_debug("transaction end\n");
340end: 338end:
341 if (ec->global_lock) 339 if (ec->global_lock)
342 acpi_release_global_lock(glk); 340 acpi_release_global_lock(glk);
@@ -570,12 +568,12 @@ static void acpi_ec_run(void *cxt)
570 struct acpi_ec_query_handler *handler = cxt; 568 struct acpi_ec_query_handler *handler = cxt;
571 if (!handler) 569 if (!handler)
572 return; 570 return;
573 pr_debug(PREFIX "start query execution\n"); 571 pr_debug("start query execution\n");
574 if (handler->func) 572 if (handler->func)
575 handler->func(handler->data); 573 handler->func(handler->data);
576 else if (handler->handle) 574 else if (handler->handle)
577 acpi_evaluate_object(handler->handle, NULL, NULL, NULL); 575 acpi_evaluate_object(handler->handle, NULL, NULL, NULL);
578 pr_debug(PREFIX "stop query execution\n"); 576 pr_debug("stop query execution\n");
579 kfree(handler); 577 kfree(handler);
580} 578}
581 579
@@ -593,7 +591,8 @@ static int acpi_ec_sync_query(struct acpi_ec *ec)
593 if (!copy) 591 if (!copy)
594 return -ENOMEM; 592 return -ENOMEM;
595 memcpy(copy, handler, sizeof(*copy)); 593 memcpy(copy, handler, sizeof(*copy));
596 pr_debug(PREFIX "push query execution (0x%2x) on queue\n", value); 594 pr_debug("push query execution (0x%2x) on queue\n",
595 value);
597 return acpi_os_execute((copy->func) ? 596 return acpi_os_execute((copy->func) ?
598 OSL_NOTIFY_HANDLER : OSL_GPE_HANDLER, 597 OSL_NOTIFY_HANDLER : OSL_GPE_HANDLER,
599 acpi_ec_run, copy); 598 acpi_ec_run, copy);
@@ -616,7 +615,7 @@ static int ec_check_sci(struct acpi_ec *ec, u8 state)
616{ 615{
617 if (state & ACPI_EC_FLAG_SCI) { 616 if (state & ACPI_EC_FLAG_SCI) {
618 if (!test_and_set_bit(EC_FLAGS_QUERY_PENDING, &ec->flags)) { 617 if (!test_and_set_bit(EC_FLAGS_QUERY_PENDING, &ec->flags)) {
619 pr_debug(PREFIX "push gpe query to the queue\n"); 618 pr_debug("push gpe query to the queue\n");
620 return acpi_os_execute(OSL_NOTIFY_HANDLER, 619 return acpi_os_execute(OSL_NOTIFY_HANDLER,
621 acpi_ec_gpe_query, ec); 620 acpi_ec_gpe_query, ec);
622 } 621 }
@@ -630,7 +629,7 @@ static u32 acpi_ec_gpe_handler(acpi_handle gpe_device,
630 struct acpi_ec *ec = data; 629 struct acpi_ec *ec = data;
631 u8 status = acpi_ec_read_status(ec); 630 u8 status = acpi_ec_read_status(ec);
632 631
633 pr_debug(PREFIX "~~~> interrupt, status:0x%02x\n", status); 632 pr_debug("~~~> interrupt, status:0x%02x\n", status);
634 633
635 advance_transaction(ec, status); 634 advance_transaction(ec, status);
636 if (ec_transaction_done(ec) && 635 if (ec_transaction_done(ec) &&
@@ -776,7 +775,7 @@ static int ec_install_handlers(struct acpi_ec *ec)
776 * The AE_NOT_FOUND error will be ignored and OS 775 * The AE_NOT_FOUND error will be ignored and OS
777 * continue to initialize EC. 776 * continue to initialize EC.
778 */ 777 */
779 printk(KERN_ERR "Fail in evaluating the _REG object" 778 pr_err("Fail in evaluating the _REG object"
780 " of EC device. Broken bios is suspected.\n"); 779 " of EC device. Broken bios is suspected.\n");
781 } else { 780 } else {
782 acpi_remove_gpe_handler(NULL, ec->gpe, 781 acpi_remove_gpe_handler(NULL, ec->gpe,
@@ -795,10 +794,10 @@ static void ec_remove_handlers(struct acpi_ec *ec)
795 acpi_disable_gpe(NULL, ec->gpe); 794 acpi_disable_gpe(NULL, ec->gpe);
796 if (ACPI_FAILURE(acpi_remove_address_space_handler(ec->handle, 795 if (ACPI_FAILURE(acpi_remove_address_space_handler(ec->handle,
797 ACPI_ADR_SPACE_EC, &acpi_ec_space_handler))) 796 ACPI_ADR_SPACE_EC, &acpi_ec_space_handler)))
798 pr_err(PREFIX "failed to remove space handler\n"); 797 pr_err("failed to remove space handler\n");
799 if (ACPI_FAILURE(acpi_remove_gpe_handler(NULL, ec->gpe, 798 if (ACPI_FAILURE(acpi_remove_gpe_handler(NULL, ec->gpe,
800 &acpi_ec_gpe_handler))) 799 &acpi_ec_gpe_handler)))
801 pr_err(PREFIX "failed to remove gpe handler\n"); 800 pr_err("failed to remove gpe handler\n");
802 clear_bit(EC_FLAGS_HANDLERS_INSTALLED, &ec->flags); 801 clear_bit(EC_FLAGS_HANDLERS_INSTALLED, &ec->flags);
803} 802}
804 803
@@ -840,7 +839,7 @@ static int acpi_ec_add(struct acpi_device *device)
840 ret = !!request_region(ec->command_addr, 1, "EC cmd"); 839 ret = !!request_region(ec->command_addr, 1, "EC cmd");
841 WARN(!ret, "Could not request EC cmd io port 0x%lx", ec->command_addr); 840 WARN(!ret, "Could not request EC cmd io port 0x%lx", ec->command_addr);
842 841
843 pr_info(PREFIX "GPE = 0x%lx, I/O: command/status = 0x%lx, data = 0x%lx\n", 842 pr_info("GPE = 0x%lx, I/O: command/status = 0x%lx, data = 0x%lx\n",
844 ec->gpe, ec->command_addr, ec->data_addr); 843 ec->gpe, ec->command_addr, ec->data_addr);
845 844
846 ret = ec_install_handlers(ec); 845 ret = ec_install_handlers(ec);
@@ -931,7 +930,7 @@ static int ec_validate_ecdt(const struct dmi_system_id *id)
931/* MSI EC needs special treatment, enable it */ 930/* MSI EC needs special treatment, enable it */
932static int ec_flag_msi(const struct dmi_system_id *id) 931static int ec_flag_msi(const struct dmi_system_id *id)
933{ 932{
934 printk(KERN_DEBUG PREFIX "Detected MSI hardware, enabling workarounds.\n"); 933 pr_debug("Detected MSI hardware, enabling workarounds.\n");
935 EC_FLAGS_MSI = 1; 934 EC_FLAGS_MSI = 1;
936 EC_FLAGS_VALIDATE_ECDT = 1; 935 EC_FLAGS_VALIDATE_ECDT = 1;
937 return 0; 936 return 0;
@@ -1010,7 +1009,7 @@ int __init acpi_ec_ecdt_probe(void)
1010 status = acpi_get_table(ACPI_SIG_ECDT, 1, 1009 status = acpi_get_table(ACPI_SIG_ECDT, 1,
1011 (struct acpi_table_header **)&ecdt_ptr); 1010 (struct acpi_table_header **)&ecdt_ptr);
1012 if (ACPI_SUCCESS(status)) { 1011 if (ACPI_SUCCESS(status)) {
1013 pr_info(PREFIX "EC description table is found, configuring boot EC\n"); 1012 pr_info("EC description table is found, configuring boot EC\n");
1014 boot_ec->command_addr = ecdt_ptr->control.address; 1013 boot_ec->command_addr = ecdt_ptr->control.address;
1015 boot_ec->data_addr = ecdt_ptr->data.address; 1014 boot_ec->data_addr = ecdt_ptr->data.address;
1016 boot_ec->gpe = ecdt_ptr->gpe; 1015 boot_ec->gpe = ecdt_ptr->gpe;
@@ -1030,7 +1029,7 @@ int __init acpi_ec_ecdt_probe(void)
1030 1029
1031 /* This workaround is needed only on some broken machines, 1030 /* This workaround is needed only on some broken machines,
1032 * which require early EC, but fail to provide ECDT */ 1031 * which require early EC, but fail to provide ECDT */
1033 printk(KERN_DEBUG PREFIX "Look up EC in DSDT\n"); 1032 pr_debug("Look up EC in DSDT\n");
1034 status = acpi_get_devices(ec_device_ids[0].id, ec_parse_device, 1033 status = acpi_get_devices(ec_device_ids[0].id, ec_parse_device,
1035 boot_ec, NULL); 1034 boot_ec, NULL);
1036 /* Check that acpi_get_devices actually find something */ 1035 /* Check that acpi_get_devices actually find something */
@@ -1042,7 +1041,7 @@ int __init acpi_ec_ecdt_probe(void)
1042 saved_ec->data_addr != boot_ec->data_addr || 1041 saved_ec->data_addr != boot_ec->data_addr ||
1043 saved_ec->gpe != boot_ec->gpe || 1042 saved_ec->gpe != boot_ec->gpe ||
1044 saved_ec->handle != boot_ec->handle) 1043 saved_ec->handle != boot_ec->handle)
1045 pr_info(PREFIX "ASUSTek keeps feeding us with broken " 1044 pr_info("ASUSTek keeps feeding us with broken "
1046 "ECDT tables, which are very hard to workaround. " 1045 "ECDT tables, which are very hard to workaround. "
1047 "Trying to use DSDT EC info instead. Please send " 1046 "Trying to use DSDT EC info instead. Please send "
1048 "output of acpidump to linux-acpi@vger.kernel.org\n"); 1047 "output of acpidump to linux-acpi@vger.kernel.org\n");
diff --git a/drivers/acpi/event.c b/drivers/acpi/event.c
index 8247fcdde079..fdef416c0ff6 100644
--- a/drivers/acpi/event.c
+++ b/drivers/acpi/event.c
@@ -127,11 +127,6 @@ int acpi_bus_generate_netlink_event(const char *device_class,
127 } 127 }
128 128
129 event = nla_data(attr); 129 event = nla_data(attr);
130 if (!event) {
131 nlmsg_free(skb);
132 return -EINVAL;
133 }
134
135 memset(event, 0, sizeof(struct acpi_genl_event)); 130 memset(event, 0, sizeof(struct acpi_genl_event));
136 131
137 strcpy(event->device_class, device_class); 132 strcpy(event->device_class, device_class);
diff --git a/drivers/acpi/fan.c b/drivers/acpi/fan.c
index 41ade6570bc0..ba3da88cee45 100644
--- a/drivers/acpi/fan.c
+++ b/drivers/acpi/fan.c
@@ -168,7 +168,7 @@ static int acpi_fan_add(struct acpi_device *device)
168 acpi_device_name(device), acpi_device_bid(device), 168 acpi_device_name(device), acpi_device_bid(device),
169 !device->power.state ? "on" : "off"); 169 !device->power.state ? "on" : "off");
170 170
171 end: 171end:
172 return result; 172 return result;
173} 173}
174 174
diff --git a/drivers/acpi/internal.h b/drivers/acpi/internal.h
index 20f423337e1f..a29739c0ba79 100644
--- a/drivers/acpi/internal.h
+++ b/drivers/acpi/internal.h
@@ -26,11 +26,6 @@
26acpi_status acpi_os_initialize1(void); 26acpi_status acpi_os_initialize1(void);
27int init_acpi_device_notify(void); 27int init_acpi_device_notify(void);
28int acpi_scan_init(void); 28int acpi_scan_init(void);
29#ifdef CONFIG_ACPI_PCI_SLOT
30void acpi_pci_slot_init(void);
31#else
32static inline void acpi_pci_slot_init(void) { }
33#endif
34void acpi_pci_root_init(void); 29void acpi_pci_root_init(void);
35void acpi_pci_link_init(void); 30void acpi_pci_link_init(void);
36void acpi_pci_root_hp_init(void); 31void acpi_pci_root_hp_init(void);
@@ -92,6 +87,7 @@ void acpi_device_add_finalize(struct acpi_device *device);
92void acpi_free_pnp_ids(struct acpi_device_pnp *pnp); 87void acpi_free_pnp_ids(struct acpi_device_pnp *pnp);
93int acpi_bind_one(struct device *dev, acpi_handle handle); 88int acpi_bind_one(struct device *dev, acpi_handle handle);
94int acpi_unbind_one(struct device *dev); 89int acpi_unbind_one(struct device *dev);
90void acpi_bus_device_eject(void *data, u32 ost_src);
95 91
96/* -------------------------------------------------------------------------- 92/* --------------------------------------------------------------------------
97 Power Resource 93 Power Resource
@@ -169,9 +165,7 @@ int acpi_create_platform_device(struct acpi_device *adev,
169 Video 165 Video
170 -------------------------------------------------------------------------- */ 166 -------------------------------------------------------------------------- */
171#if defined(CONFIG_ACPI_VIDEO) || defined(CONFIG_ACPI_VIDEO_MODULE) 167#if defined(CONFIG_ACPI_VIDEO) || defined(CONFIG_ACPI_VIDEO_MODULE)
172bool acpi_video_backlight_quirks(void); 168bool acpi_osi_is_win8(void);
173#else
174static inline bool acpi_video_backlight_quirks(void) { return false; }
175#endif 169#endif
176 170
177#endif /* _ACPI_INTERNAL_H_ */ 171#endif /* _ACPI_INTERNAL_H_ */
diff --git a/drivers/acpi/numa.c b/drivers/acpi/numa.c
index 2e82e5d76930..a2343a1d9e0b 100644
--- a/drivers/acpi/numa.c
+++ b/drivers/acpi/numa.c
@@ -73,7 +73,7 @@ int acpi_map_pxm_to_node(int pxm)
73{ 73{
74 int node = pxm_to_node_map[pxm]; 74 int node = pxm_to_node_map[pxm];
75 75
76 if (node < 0) { 76 if (node == NUMA_NO_NODE) {
77 if (nodes_weight(nodes_found_map) >= MAX_NUMNODES) 77 if (nodes_weight(nodes_found_map) >= MAX_NUMNODES)
78 return NUMA_NO_NODE; 78 return NUMA_NO_NODE;
79 node = first_unset_node(nodes_found_map); 79 node = first_unset_node(nodes_found_map);
@@ -334,7 +334,7 @@ int acpi_get_pxm(acpi_handle h)
334 334
335int acpi_get_node(acpi_handle *handle) 335int acpi_get_node(acpi_handle *handle)
336{ 336{
337 int pxm, node = -1; 337 int pxm, node = NUMA_NO_NODE;
338 338
339 pxm = acpi_get_pxm(handle); 339 pxm = acpi_get_pxm(handle);
340 if (pxm >= 0 && pxm < MAX_PXM_DOMAINS) 340 if (pxm >= 0 && pxm < MAX_PXM_DOMAINS)
diff --git a/drivers/acpi/osl.c b/drivers/acpi/osl.c
index e5f416c7f66e..54a20ff4b864 100644
--- a/drivers/acpi/osl.c
+++ b/drivers/acpi/osl.c
@@ -61,7 +61,6 @@ struct acpi_os_dpc {
61 acpi_osd_exec_callback function; 61 acpi_osd_exec_callback function;
62 void *context; 62 void *context;
63 struct work_struct work; 63 struct work_struct work;
64 int wait;
65}; 64};
66 65
67#ifdef CONFIG_ACPI_CUSTOM_DSDT 66#ifdef CONFIG_ACPI_CUSTOM_DSDT
@@ -569,8 +568,10 @@ static const char * const table_sigs[] = {
569 568
570#define ACPI_HEADER_SIZE sizeof(struct acpi_table_header) 569#define ACPI_HEADER_SIZE sizeof(struct acpi_table_header)
571 570
572/* Must not increase 10 or needs code modification below */ 571#define ACPI_OVERRIDE_TABLES 64
573#define ACPI_OVERRIDE_TABLES 10 572static struct cpio_data __initdata acpi_initrd_files[ACPI_OVERRIDE_TABLES];
573
574#define MAP_CHUNK_SIZE (NR_FIX_BTMAPS << PAGE_SHIFT)
574 575
575void __init acpi_initrd_override(void *data, size_t size) 576void __init acpi_initrd_override(void *data, size_t size)
576{ 577{
@@ -579,8 +580,6 @@ void __init acpi_initrd_override(void *data, size_t size)
579 struct acpi_table_header *table; 580 struct acpi_table_header *table;
580 char cpio_path[32] = "kernel/firmware/acpi/"; 581 char cpio_path[32] = "kernel/firmware/acpi/";
581 struct cpio_data file; 582 struct cpio_data file;
582 struct cpio_data early_initrd_files[ACPI_OVERRIDE_TABLES];
583 char *p;
584 583
585 if (data == NULL || size == 0) 584 if (data == NULL || size == 0)
586 return; 585 return;
@@ -625,8 +624,8 @@ void __init acpi_initrd_override(void *data, size_t size)
625 table->signature, cpio_path, file.name, table->length); 624 table->signature, cpio_path, file.name, table->length);
626 625
627 all_tables_size += table->length; 626 all_tables_size += table->length;
628 early_initrd_files[table_nr].data = file.data; 627 acpi_initrd_files[table_nr].data = file.data;
629 early_initrd_files[table_nr].size = file.size; 628 acpi_initrd_files[table_nr].size = file.size;
630 table_nr++; 629 table_nr++;
631 } 630 }
632 if (table_nr == 0) 631 if (table_nr == 0)
@@ -652,14 +651,34 @@ void __init acpi_initrd_override(void *data, size_t size)
652 memblock_reserve(acpi_tables_addr, all_tables_size); 651 memblock_reserve(acpi_tables_addr, all_tables_size);
653 arch_reserve_mem_area(acpi_tables_addr, all_tables_size); 652 arch_reserve_mem_area(acpi_tables_addr, all_tables_size);
654 653
655 p = early_ioremap(acpi_tables_addr, all_tables_size); 654 /*
656 655 * early_ioremap only can remap 256k one time. If we map all
656 * tables one time, we will hit the limit. Need to map chunks
657 * one by one during copying the same as that in relocate_initrd().
658 */
657 for (no = 0; no < table_nr; no++) { 659 for (no = 0; no < table_nr; no++) {
658 memcpy(p + total_offset, early_initrd_files[no].data, 660 unsigned char *src_p = acpi_initrd_files[no].data;
659 early_initrd_files[no].size); 661 phys_addr_t size = acpi_initrd_files[no].size;
660 total_offset += early_initrd_files[no].size; 662 phys_addr_t dest_addr = acpi_tables_addr + total_offset;
663 phys_addr_t slop, clen;
664 char *dest_p;
665
666 total_offset += size;
667
668 while (size) {
669 slop = dest_addr & ~PAGE_MASK;
670 clen = size;
671 if (clen > MAP_CHUNK_SIZE - slop)
672 clen = MAP_CHUNK_SIZE - slop;
673 dest_p = early_ioremap(dest_addr & PAGE_MASK,
674 clen + slop);
675 memcpy(dest_p + slop, src_p, clen);
676 early_iounmap(dest_p, clen + slop);
677 src_p += clen;
678 dest_addr += clen;
679 size -= clen;
680 }
661 } 681 }
662 early_iounmap(p, all_tables_size);
663} 682}
664#endif /* CONFIG_ACPI_INITRD_TABLE_OVERRIDE */ 683#endif /* CONFIG_ACPI_INITRD_TABLE_OVERRIDE */
665 684
@@ -820,7 +839,7 @@ acpi_status acpi_os_remove_interrupt_handler(u32 irq, acpi_osd_handler handler)
820 839
821void acpi_os_sleep(u64 ms) 840void acpi_os_sleep(u64 ms)
822{ 841{
823 schedule_timeout_interruptible(msecs_to_jiffies(ms)); 842 msleep(ms);
824} 843}
825 844
826void acpi_os_stall(u32 us) 845void acpi_os_stall(u32 us)
@@ -1067,9 +1086,6 @@ static void acpi_os_execute_deferred(struct work_struct *work)
1067{ 1086{
1068 struct acpi_os_dpc *dpc = container_of(work, struct acpi_os_dpc, work); 1087 struct acpi_os_dpc *dpc = container_of(work, struct acpi_os_dpc, work);
1069 1088
1070 if (dpc->wait)
1071 acpi_os_wait_events_complete();
1072
1073 dpc->function(dpc->context); 1089 dpc->function(dpc->context);
1074 kfree(dpc); 1090 kfree(dpc);
1075} 1091}
@@ -1089,8 +1105,8 @@ static void acpi_os_execute_deferred(struct work_struct *work)
1089 * 1105 *
1090 ******************************************************************************/ 1106 ******************************************************************************/
1091 1107
1092static acpi_status __acpi_os_execute(acpi_execute_type type, 1108acpi_status acpi_os_execute(acpi_execute_type type,
1093 acpi_osd_exec_callback function, void *context, int hp) 1109 acpi_osd_exec_callback function, void *context)
1094{ 1110{
1095 acpi_status status = AE_OK; 1111 acpi_status status = AE_OK;
1096 struct acpi_os_dpc *dpc; 1112 struct acpi_os_dpc *dpc;
@@ -1117,20 +1133,11 @@ static acpi_status __acpi_os_execute(acpi_execute_type type,
1117 dpc->context = context; 1133 dpc->context = context;
1118 1134
1119 /* 1135 /*
1120 * We can't run hotplug code in keventd_wq/kacpid_wq/kacpid_notify_wq
1121 * because the hotplug code may call driver .remove() functions,
1122 * which invoke flush_scheduled_work/acpi_os_wait_events_complete
1123 * to flush these workqueues.
1124 *
1125 * To prevent lockdep from complaining unnecessarily, make sure that 1136 * To prevent lockdep from complaining unnecessarily, make sure that
1126 * there is a different static lockdep key for each workqueue by using 1137 * there is a different static lockdep key for each workqueue by using
1127 * INIT_WORK() for each of them separately. 1138 * INIT_WORK() for each of them separately.
1128 */ 1139 */
1129 if (hp) { 1140 if (type == OSL_NOTIFY_HANDLER) {
1130 queue = kacpi_hotplug_wq;
1131 dpc->wait = 1;
1132 INIT_WORK(&dpc->work, acpi_os_execute_deferred);
1133 } else if (type == OSL_NOTIFY_HANDLER) {
1134 queue = kacpi_notify_wq; 1141 queue = kacpi_notify_wq;
1135 INIT_WORK(&dpc->work, acpi_os_execute_deferred); 1142 INIT_WORK(&dpc->work, acpi_os_execute_deferred);
1136 } else { 1143 } else {
@@ -1155,28 +1162,59 @@ static acpi_status __acpi_os_execute(acpi_execute_type type,
1155 } 1162 }
1156 return status; 1163 return status;
1157} 1164}
1165EXPORT_SYMBOL(acpi_os_execute);
1158 1166
1159acpi_status acpi_os_execute(acpi_execute_type type, 1167void acpi_os_wait_events_complete(void)
1160 acpi_osd_exec_callback function, void *context)
1161{ 1168{
1162 return __acpi_os_execute(type, function, context, 0); 1169 flush_workqueue(kacpid_wq);
1170 flush_workqueue(kacpi_notify_wq);
1163} 1171}
1164EXPORT_SYMBOL(acpi_os_execute);
1165 1172
1166acpi_status acpi_os_hotplug_execute(acpi_osd_exec_callback function, 1173struct acpi_hp_work {
1167 void *context) 1174 struct work_struct work;
1175 acpi_hp_callback func;
1176 void *data;
1177 u32 src;
1178};
1179
1180static void acpi_hotplug_work_fn(struct work_struct *work)
1168{ 1181{
1169 return __acpi_os_execute(0, function, context, 1); 1182 struct acpi_hp_work *hpw = container_of(work, struct acpi_hp_work, work);
1183
1184 acpi_os_wait_events_complete();
1185 hpw->func(hpw->data, hpw->src);
1186 kfree(hpw);
1170} 1187}
1171EXPORT_SYMBOL(acpi_os_hotplug_execute);
1172 1188
1173void acpi_os_wait_events_complete(void) 1189acpi_status acpi_hotplug_execute(acpi_hp_callback func, void *data, u32 src)
1174{ 1190{
1175 flush_workqueue(kacpid_wq); 1191 struct acpi_hp_work *hpw;
1176 flush_workqueue(kacpi_notify_wq); 1192
1193 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
1194 "Scheduling function [%p(%p, %u)] for deferred execution.\n",
1195 func, data, src));
1196
1197 hpw = kmalloc(sizeof(*hpw), GFP_KERNEL);
1198 if (!hpw)
1199 return AE_NO_MEMORY;
1200
1201 INIT_WORK(&hpw->work, acpi_hotplug_work_fn);
1202 hpw->func = func;
1203 hpw->data = data;
1204 hpw->src = src;
1205 /*
1206 * We can't run hotplug code in kacpid_wq/kacpid_notify_wq etc., because
1207 * the hotplug code may call driver .remove() functions, which may
1208 * invoke flush_scheduled_work()/acpi_os_wait_events_complete() to flush
1209 * these workqueues.
1210 */
1211 if (!queue_work(kacpi_hotplug_wq, &hpw->work)) {
1212 kfree(hpw);
1213 return AE_ERROR;
1214 }
1215 return AE_OK;
1177} 1216}
1178 1217
1179EXPORT_SYMBOL(acpi_os_wait_events_complete);
1180 1218
1181acpi_status 1219acpi_status
1182acpi_os_create_semaphore(u32 max_units, u32 initial_units, acpi_handle * handle) 1220acpi_os_create_semaphore(u32 max_units, u32 initial_units, acpi_handle * handle)
@@ -1335,7 +1373,7 @@ static int __init acpi_os_name_setup(char *str)
1335 if (!str || !*str) 1373 if (!str || !*str)
1336 return 0; 1374 return 0;
1337 1375
1338 for (; count-- && str && *str; str++) { 1376 for (; count-- && *str; str++) {
1339 if (isalnum(*str) || *str == ' ' || *str == ':') 1377 if (isalnum(*str) || *str == ' ' || *str == ':')
1340 *p++ = *str; 1378 *p++ = *str;
1341 else if (*str == '\'' || *str == '"') 1379 else if (*str == '\'' || *str == '"')
@@ -1825,25 +1863,3 @@ void acpi_os_set_prepare_extended_sleep(int (*func)(u8 sleep_state,
1825{ 1863{
1826 __acpi_os_prepare_extended_sleep = func; 1864 __acpi_os_prepare_extended_sleep = func;
1827} 1865}
1828
1829
1830void alloc_acpi_hp_work(acpi_handle handle, u32 type, void *context,
1831 void (*func)(struct work_struct *work))
1832{
1833 struct acpi_hp_work *hp_work;
1834 int ret;
1835
1836 hp_work = kmalloc(sizeof(*hp_work), GFP_KERNEL);
1837 if (!hp_work)
1838 return;
1839
1840 hp_work->handle = handle;
1841 hp_work->type = type;
1842 hp_work->context = context;
1843
1844 INIT_WORK(&hp_work->work, func);
1845 ret = queue_work(kacpi_hotplug_wq, &hp_work->work);
1846 if (!ret)
1847 kfree(hp_work);
1848}
1849EXPORT_SYMBOL_GPL(alloc_acpi_hp_work);
diff --git a/drivers/acpi/pci_root.c b/drivers/acpi/pci_root.c
index d3874f425653..417876bce854 100644
--- a/drivers/acpi/pci_root.c
+++ b/drivers/acpi/pci_root.c
@@ -39,6 +39,8 @@
39#include <acpi/acpi_drivers.h> 39#include <acpi/acpi_drivers.h>
40#include <acpi/apei.h> 40#include <acpi/apei.h>
41 41
42#include "internal.h"
43
42#define PREFIX "ACPI: " 44#define PREFIX "ACPI: "
43 45
44#define _COMPONENT ACPI_PCI_COMPONENT 46#define _COMPONENT ACPI_PCI_COMPONENT
@@ -590,39 +592,10 @@ static void handle_root_bridge_insertion(acpi_handle handle)
590 acpi_handle_err(handle, "cannot add bridge to acpi list\n"); 592 acpi_handle_err(handle, "cannot add bridge to acpi list\n");
591} 593}
592 594
593static void handle_root_bridge_removal(struct acpi_device *device) 595static void hotplug_event_root(void *data, u32 type)
594{
595 acpi_status status;
596 struct acpi_eject_event *ej_event;
597
598 ej_event = kmalloc(sizeof(*ej_event), GFP_KERNEL);
599 if (!ej_event) {
600 /* Inform firmware the hot-remove operation has error */
601 (void) acpi_evaluate_hotplug_ost(device->handle,
602 ACPI_NOTIFY_EJECT_REQUEST,
603 ACPI_OST_SC_NON_SPECIFIC_FAILURE,
604 NULL);
605 return;
606 }
607
608 ej_event->device = device;
609 ej_event->event = ACPI_NOTIFY_EJECT_REQUEST;
610
611 status = acpi_os_hotplug_execute(acpi_bus_hot_remove_device, ej_event);
612 if (ACPI_FAILURE(status))
613 kfree(ej_event);
614}
615
616static void _handle_hotplug_event_root(struct work_struct *work)
617{ 596{
597 acpi_handle handle = data;
618 struct acpi_pci_root *root; 598 struct acpi_pci_root *root;
619 struct acpi_hp_work *hp_work;
620 acpi_handle handle;
621 u32 type;
622
623 hp_work = container_of(work, struct acpi_hp_work, work);
624 handle = hp_work->handle;
625 type = hp_work->type;
626 599
627 acpi_scan_lock_acquire(); 600 acpi_scan_lock_acquire();
628 601
@@ -652,9 +625,15 @@ static void _handle_hotplug_event_root(struct work_struct *work)
652 /* request device eject */ 625 /* request device eject */
653 acpi_handle_printk(KERN_DEBUG, handle, 626 acpi_handle_printk(KERN_DEBUG, handle,
654 "Device eject notify on %s\n", __func__); 627 "Device eject notify on %s\n", __func__);
655 if (root) 628 if (!root)
656 handle_root_bridge_removal(root->device); 629 break;
657 break; 630
631 get_device(&root->device->dev);
632
633 acpi_scan_lock_release();
634
635 acpi_bus_device_eject(root->device, ACPI_NOTIFY_EJECT_REQUEST);
636 return;
658 default: 637 default:
659 acpi_handle_warn(handle, 638 acpi_handle_warn(handle,
660 "notify_handler: unknown event type 0x%x\n", 639 "notify_handler: unknown event type 0x%x\n",
@@ -663,14 +642,12 @@ static void _handle_hotplug_event_root(struct work_struct *work)
663 } 642 }
664 643
665 acpi_scan_lock_release(); 644 acpi_scan_lock_release();
666 kfree(hp_work); /* allocated in handle_hotplug_event_bridge */
667} 645}
668 646
669static void handle_hotplug_event_root(acpi_handle handle, u32 type, 647static void handle_hotplug_event_root(acpi_handle handle, u32 type,
670 void *context) 648 void *context)
671{ 649{
672 alloc_acpi_hp_work(handle, type, context, 650 acpi_hotplug_execute(hotplug_event_root, handle, type);
673 _handle_hotplug_event_root);
674} 651}
675 652
676static acpi_status __init 653static acpi_status __init
diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
index 04a13784dd20..6a5b152ad4d0 100644
--- a/drivers/acpi/proc.c
+++ b/drivers/acpi/proc.c
@@ -8,289 +8,17 @@
8#include <acpi/acpi_bus.h> 8#include <acpi/acpi_bus.h>
9#include <acpi/acpi_drivers.h> 9#include <acpi/acpi_drivers.h>
10 10
11#ifdef CONFIG_X86
12#include <linux/mc146818rtc.h>
13#endif
14
15#include "sleep.h" 11#include "sleep.h"
16 12
17#define _COMPONENT ACPI_SYSTEM_COMPONENT 13#define _COMPONENT ACPI_SYSTEM_COMPONENT
18 14
19/* 15/*
20 * this file provides support for: 16 * this file provides support for:
21 * /proc/acpi/alarm
22 * /proc/acpi/wakeup 17 * /proc/acpi/wakeup
23 */ 18 */
24 19
25ACPI_MODULE_NAME("sleep") 20ACPI_MODULE_NAME("sleep")
26 21
27#if defined(CONFIG_RTC_DRV_CMOS) || defined(CONFIG_RTC_DRV_CMOS_MODULE) || !defined(CONFIG_X86)
28/* use /sys/class/rtc/rtcX/wakealarm instead; it's not ACPI-specific */
29#else
30#define HAVE_ACPI_LEGACY_ALARM
31#endif
32
33#ifdef HAVE_ACPI_LEGACY_ALARM
34
35static u32 cmos_bcd_read(int offset, int rtc_control);
36
37static int acpi_system_alarm_seq_show(struct seq_file *seq, void *offset)
38{
39 u32 sec, min, hr;
40 u32 day, mo, yr, cent = 0;
41 u32 today = 0;
42 unsigned char rtc_control = 0;
43 unsigned long flags;
44
45 spin_lock_irqsave(&rtc_lock, flags);
46
47 rtc_control = CMOS_READ(RTC_CONTROL);
48 sec = cmos_bcd_read(RTC_SECONDS_ALARM, rtc_control);
49 min = cmos_bcd_read(RTC_MINUTES_ALARM, rtc_control);
50 hr = cmos_bcd_read(RTC_HOURS_ALARM, rtc_control);
51
52 /* If we ever get an FACP with proper values... */
53 if (acpi_gbl_FADT.day_alarm) {
54 /* ACPI spec: only low 6 its should be cared */
55 day = CMOS_READ(acpi_gbl_FADT.day_alarm) & 0x3F;
56 if (!(rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD)
57 day = bcd2bin(day);
58 } else
59 day = cmos_bcd_read(RTC_DAY_OF_MONTH, rtc_control);
60 if (acpi_gbl_FADT.month_alarm)
61 mo = cmos_bcd_read(acpi_gbl_FADT.month_alarm, rtc_control);
62 else {
63 mo = cmos_bcd_read(RTC_MONTH, rtc_control);
64 today = cmos_bcd_read(RTC_DAY_OF_MONTH, rtc_control);
65 }
66 if (acpi_gbl_FADT.century)
67 cent = cmos_bcd_read(acpi_gbl_FADT.century, rtc_control);
68
69 yr = cmos_bcd_read(RTC_YEAR, rtc_control);
70
71 spin_unlock_irqrestore(&rtc_lock, flags);
72
73 /* we're trusting the FADT (see above) */
74 if (!acpi_gbl_FADT.century)
75 /* If we're not trusting the FADT, we should at least make it
76 * right for _this_ century... ehm, what is _this_ century?
77 *
78 * TBD:
79 * ASAP: find piece of code in the kernel, e.g. star tracker driver,
80 * which we can trust to determine the century correctly. Atom
81 * watch driver would be nice, too...
82 *
83 * if that has not happened, change for first release in 2050:
84 * if (yr<50)
85 * yr += 2100;
86 * else
87 * yr += 2000; // current line of code
88 *
89 * if that has not happened either, please do on 2099/12/31:23:59:59
90 * s/2000/2100
91 *
92 */
93 yr += 2000;
94 else
95 yr += cent * 100;
96
97 /*
98 * Show correct dates for alarms up to a month into the future.
99 * This solves issues for nearly all situations with the common
100 * 30-day alarm clocks in PC hardware.
101 */
102 if (day < today) {
103 if (mo < 12) {
104 mo += 1;
105 } else {
106 mo = 1;
107 yr += 1;
108 }
109 }
110
111 seq_printf(seq, "%4.4u-", yr);
112 (mo > 12) ? seq_puts(seq, "**-") : seq_printf(seq, "%2.2u-", mo);
113 (day > 31) ? seq_puts(seq, "** ") : seq_printf(seq, "%2.2u ", day);
114 (hr > 23) ? seq_puts(seq, "**:") : seq_printf(seq, "%2.2u:", hr);
115 (min > 59) ? seq_puts(seq, "**:") : seq_printf(seq, "%2.2u:", min);
116 (sec > 59) ? seq_puts(seq, "**\n") : seq_printf(seq, "%2.2u\n", sec);
117
118 return 0;
119}
120
121static int acpi_system_alarm_open_fs(struct inode *inode, struct file *file)
122{
123 return single_open(file, acpi_system_alarm_seq_show, PDE_DATA(inode));
124}
125
126static int get_date_field(char **p, u32 * value)
127{
128 char *next = NULL;
129 char *string_end = NULL;
130 int result = -EINVAL;
131
132 /*
133 * Try to find delimeter, only to insert null. The end of the
134 * string won't have one, but is still valid.
135 */
136 if (*p == NULL)
137 return result;
138
139 next = strpbrk(*p, "- :");
140 if (next)
141 *next++ = '\0';
142
143 *value = simple_strtoul(*p, &string_end, 10);
144
145 /* Signal success if we got a good digit */
146 if (string_end != *p)
147 result = 0;
148
149 if (next)
150 *p = next;
151 else
152 *p = NULL;
153
154 return result;
155}
156
157/* Read a possibly BCD register, always return binary */
158static u32 cmos_bcd_read(int offset, int rtc_control)
159{
160 u32 val = CMOS_READ(offset);
161 if (!(rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD)
162 val = bcd2bin(val);
163 return val;
164}
165
166/* Write binary value into possibly BCD register */
167static void cmos_bcd_write(u32 val, int offset, int rtc_control)
168{
169 if (!(rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD)
170 val = bin2bcd(val);
171 CMOS_WRITE(val, offset);
172}
173
174static ssize_t
175acpi_system_write_alarm(struct file *file,
176 const char __user * buffer, size_t count, loff_t * ppos)
177{
178 int result = 0;
179 char alarm_string[30] = { '\0' };
180 char *p = alarm_string;
181 u32 sec, min, hr, day, mo, yr;
182 int adjust = 0;
183 unsigned char rtc_control = 0;
184
185 if (count > sizeof(alarm_string) - 1)
186 return -EINVAL;
187
188 if (copy_from_user(alarm_string, buffer, count))
189 return -EFAULT;
190
191 alarm_string[count] = '\0';
192
193 /* check for time adjustment */
194 if (alarm_string[0] == '+') {
195 p++;
196 adjust = 1;
197 }
198
199 if ((result = get_date_field(&p, &yr)))
200 goto end;
201 if ((result = get_date_field(&p, &mo)))
202 goto end;
203 if ((result = get_date_field(&p, &day)))
204 goto end;
205 if ((result = get_date_field(&p, &hr)))
206 goto end;
207 if ((result = get_date_field(&p, &min)))
208 goto end;
209 if ((result = get_date_field(&p, &sec)))
210 goto end;
211
212 spin_lock_irq(&rtc_lock);
213
214 rtc_control = CMOS_READ(RTC_CONTROL);
215
216 if (adjust) {
217 yr += cmos_bcd_read(RTC_YEAR, rtc_control);
218 mo += cmos_bcd_read(RTC_MONTH, rtc_control);
219 day += cmos_bcd_read(RTC_DAY_OF_MONTH, rtc_control);
220 hr += cmos_bcd_read(RTC_HOURS, rtc_control);
221 min += cmos_bcd_read(RTC_MINUTES, rtc_control);
222 sec += cmos_bcd_read(RTC_SECONDS, rtc_control);
223 }
224
225 spin_unlock_irq(&rtc_lock);
226
227 if (sec > 59) {
228 min += sec/60;
229 sec = sec%60;
230 }
231 if (min > 59) {
232 hr += min/60;
233 min = min%60;
234 }
235 if (hr > 23) {
236 day += hr/24;
237 hr = hr%24;
238 }
239 if (day > 31) {
240 mo += day/32;
241 day = day%32;
242 }
243 if (mo > 12) {
244 yr += mo/13;
245 mo = mo%13;
246 }
247
248 spin_lock_irq(&rtc_lock);
249 /*
250 * Disable alarm interrupt before setting alarm timer or else
251 * when ACPI_EVENT_RTC is enabled, a spurious ACPI interrupt occurs
252 */
253 rtc_control &= ~RTC_AIE;
254 CMOS_WRITE(rtc_control, RTC_CONTROL);
255 CMOS_READ(RTC_INTR_FLAGS);
256
257 /* write the fields the rtc knows about */
258 cmos_bcd_write(hr, RTC_HOURS_ALARM, rtc_control);
259 cmos_bcd_write(min, RTC_MINUTES_ALARM, rtc_control);
260 cmos_bcd_write(sec, RTC_SECONDS_ALARM, rtc_control);
261
262 /*
263 * If the system supports an enhanced alarm it will have non-zero
264 * offsets into the CMOS RAM here -- which for some reason are pointing
265 * to the RTC area of memory.
266 */
267 if (acpi_gbl_FADT.day_alarm)
268 cmos_bcd_write(day, acpi_gbl_FADT.day_alarm, rtc_control);
269 if (acpi_gbl_FADT.month_alarm)
270 cmos_bcd_write(mo, acpi_gbl_FADT.month_alarm, rtc_control);
271 if (acpi_gbl_FADT.century) {
272 if (adjust)
273 yr += cmos_bcd_read(acpi_gbl_FADT.century, rtc_control) * 100;
274 cmos_bcd_write(yr / 100, acpi_gbl_FADT.century, rtc_control);
275 }
276 /* enable the rtc alarm interrupt */
277 rtc_control |= RTC_AIE;
278 CMOS_WRITE(rtc_control, RTC_CONTROL);
279 CMOS_READ(RTC_INTR_FLAGS);
280
281 spin_unlock_irq(&rtc_lock);
282
283 acpi_clear_event(ACPI_EVENT_RTC);
284 acpi_enable_event(ACPI_EVENT_RTC, 0);
285
286 *ppos += count;
287
288 result = 0;
289 end:
290 return result ? result : count;
291}
292#endif /* HAVE_ACPI_LEGACY_ALARM */
293
294static int 22static int
295acpi_system_wakeup_device_seq_show(struct seq_file *seq, void *offset) 23acpi_system_wakeup_device_seq_show(struct seq_file *seq, void *offset)
296{ 24{
@@ -417,41 +145,8 @@ static const struct file_operations acpi_system_wakeup_device_fops = {
417 .release = single_release, 145 .release = single_release,
418}; 146};
419 147
420#ifdef HAVE_ACPI_LEGACY_ALARM
421static const struct file_operations acpi_system_alarm_fops = {
422 .owner = THIS_MODULE,
423 .open = acpi_system_alarm_open_fs,
424 .read = seq_read,
425 .write = acpi_system_write_alarm,
426 .llseek = seq_lseek,
427 .release = single_release,
428};
429
430static u32 rtc_handler(void *context)
431{
432 acpi_clear_event(ACPI_EVENT_RTC);
433 acpi_disable_event(ACPI_EVENT_RTC, 0);
434
435 return ACPI_INTERRUPT_HANDLED;
436}
437#endif /* HAVE_ACPI_LEGACY_ALARM */
438
439int __init acpi_sleep_proc_init(void) 148int __init acpi_sleep_proc_init(void)
440{ 149{
441#ifdef HAVE_ACPI_LEGACY_ALARM
442 /* 'alarm' [R/W] */
443 proc_create("alarm", S_IFREG | S_IRUGO | S_IWUSR,
444 acpi_root_dir, &acpi_system_alarm_fops);
445
446 acpi_install_fixed_event_handler(ACPI_EVENT_RTC, rtc_handler, NULL);
447 /*
448 * Disable the RTC event after installing RTC handler.
449 * Only when RTC alarm is set will it be enabled.
450 */
451 acpi_clear_event(ACPI_EVENT_RTC);
452 acpi_disable_event(ACPI_EVENT_RTC, 0);
453#endif /* HAVE_ACPI_LEGACY_ALARM */
454
455 /* 'wakeup device' [R/W] */ 150 /* 'wakeup device' [R/W] */
456 proc_create("wakeup", S_IFREG | S_IRUGO | S_IWUSR, 151 proc_create("wakeup", S_IFREG | S_IRUGO | S_IWUSR,
457 acpi_root_dir, &acpi_system_wakeup_device_fops); 152 acpi_root_dir, &acpi_system_wakeup_device_fops);
diff --git a/drivers/acpi/processor_core.c b/drivers/acpi/processor_core.c
index cf34d903f4fb..b3171f30b319 100644
--- a/drivers/acpi/processor_core.c
+++ b/drivers/acpi/processor_core.c
@@ -162,16 +162,23 @@ exit:
162 return apic_id; 162 return apic_id;
163} 163}
164 164
165int acpi_get_cpuid(acpi_handle handle, int type, u32 acpi_id) 165int acpi_get_apicid(acpi_handle handle, int type, u32 acpi_id)
166{ 166{
167#ifdef CONFIG_SMP 167 int apic_id;
168 int i;
169#endif
170 int apic_id = -1;
171 168
172 apic_id = map_mat_entry(handle, type, acpi_id); 169 apic_id = map_mat_entry(handle, type, acpi_id);
173 if (apic_id == -1) 170 if (apic_id == -1)
174 apic_id = map_madt_entry(type, acpi_id); 171 apic_id = map_madt_entry(type, acpi_id);
172
173 return apic_id;
174}
175
176int acpi_map_cpuid(int apic_id, u32 acpi_id)
177{
178#ifdef CONFIG_SMP
179 int i;
180#endif
181
175 if (apic_id == -1) { 182 if (apic_id == -1) {
176 /* 183 /*
177 * On UP processor, there is no _MAT or MADT table. 184 * On UP processor, there is no _MAT or MADT table.
@@ -211,6 +218,15 @@ int acpi_get_cpuid(acpi_handle handle, int type, u32 acpi_id)
211#endif 218#endif
212 return -1; 219 return -1;
213} 220}
221
222int acpi_get_cpuid(acpi_handle handle, int type, u32 acpi_id)
223{
224 int apic_id;
225
226 apic_id = acpi_get_apicid(handle, type, acpi_id);
227
228 return acpi_map_cpuid(apic_id, acpi_id);
229}
214EXPORT_SYMBOL_GPL(acpi_get_cpuid); 230EXPORT_SYMBOL_GPL(acpi_get_cpuid);
215 231
216static bool __init processor_physically_present(acpi_handle handle) 232static bool __init processor_physically_present(acpi_handle handle)
diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
index e534ba66d5b8..146ab7e2b81d 100644
--- a/drivers/acpi/processor_driver.c
+++ b/drivers/acpi/processor_driver.c
@@ -153,8 +153,7 @@ static int acpi_cpu_soft_notify(struct notifier_block *nfb,
153 return NOTIFY_OK; 153 return NOTIFY_OK;
154} 154}
155 155
156static struct notifier_block __refdata acpi_cpu_notifier = 156static struct notifier_block __refdata acpi_cpu_notifier = {
157{
158 .notifier_call = acpi_cpu_soft_notify, 157 .notifier_call = acpi_cpu_soft_notify,
159}; 158};
160 159
@@ -172,7 +171,6 @@ static int __acpi_processor_start(struct acpi_device *device)
172 171
173#ifdef CONFIG_CPU_FREQ 172#ifdef CONFIG_CPU_FREQ
174 acpi_processor_ppc_has_changed(pr, 0); 173 acpi_processor_ppc_has_changed(pr, 0);
175 acpi_processor_load_module(pr);
176#endif 174#endif
177 acpi_processor_get_throttling_info(pr); 175 acpi_processor_get_throttling_info(pr);
178 176
diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
index c7414a545a4f..644516d9bde6 100644
--- a/drivers/acpi/processor_idle.c
+++ b/drivers/acpi/processor_idle.c
@@ -265,9 +265,6 @@ static void tsc_check_state(int state) { return; }
265static int acpi_processor_get_power_info_fadt(struct acpi_processor *pr) 265static int acpi_processor_get_power_info_fadt(struct acpi_processor *pr)
266{ 266{
267 267
268 if (!pr)
269 return -EINVAL;
270
271 if (!pr->pblk) 268 if (!pr->pblk)
272 return -ENODEV; 269 return -ENODEV;
273 270
@@ -1050,12 +1047,8 @@ int acpi_processor_hotplug(struct acpi_processor *pr)
1050 if (disabled_by_idle_boot_param()) 1047 if (disabled_by_idle_boot_param())
1051 return 0; 1048 return 0;
1052 1049
1053 if (!pr) 1050 if (nocst)
1054 return -EINVAL;
1055
1056 if (nocst) {
1057 return -ENODEV; 1051 return -ENODEV;
1058 }
1059 1052
1060 if (!pr->flags.power_setup_done) 1053 if (!pr->flags.power_setup_done)
1061 return -ENODEV; 1054 return -ENODEV;
@@ -1082,9 +1075,6 @@ int acpi_processor_cst_has_changed(struct acpi_processor *pr)
1082 if (disabled_by_idle_boot_param()) 1075 if (disabled_by_idle_boot_param())
1083 return 0; 1076 return 0;
1084 1077
1085 if (!pr)
1086 return -EINVAL;
1087
1088 if (nocst) 1078 if (nocst)
1089 return -ENODEV; 1079 return -ENODEV;
1090 1080
@@ -1157,9 +1147,6 @@ int acpi_processor_power_init(struct acpi_processor *pr)
1157 first_run++; 1147 first_run++;
1158 } 1148 }
1159 1149
1160 if (!pr)
1161 return -EINVAL;
1162
1163 if (acpi_gbl_FADT.cst_control && !nocst) { 1150 if (acpi_gbl_FADT.cst_control && !nocst) {
1164 status = 1151 status =
1165 acpi_os_write_port(acpi_gbl_FADT.smi_command, acpi_gbl_FADT.cst_control, 8); 1152 acpi_os_write_port(acpi_gbl_FADT.smi_command, acpi_gbl_FADT.cst_control, 8);
diff --git a/drivers/acpi/processor_perflib.c b/drivers/acpi/processor_perflib.c
index 51d7948611da..60a7c28fc167 100644
--- a/drivers/acpi/processor_perflib.c
+++ b/drivers/acpi/processor_perflib.c
@@ -235,28 +235,6 @@ void acpi_processor_ppc_exit(void)
235 acpi_processor_ppc_status &= ~PPC_REGISTERED; 235 acpi_processor_ppc_status &= ~PPC_REGISTERED;
236} 236}
237 237
238/*
239 * Do a quick check if the systems looks like it should use ACPI
240 * cpufreq. We look at a _PCT method being available, but don't
241 * do a whole lot of sanity checks.
242 */
243void acpi_processor_load_module(struct acpi_processor *pr)
244{
245 static int requested;
246 acpi_status status = 0;
247 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
248
249 if (!arch_has_acpi_pdc() || requested)
250 return;
251 status = acpi_evaluate_object(pr->handle, "_PCT", NULL, &buffer);
252 if (!ACPI_FAILURE(status)) {
253 printk(KERN_INFO PREFIX "Requesting acpi_cpufreq\n");
254 request_module_nowait("acpi_cpufreq");
255 requested = 1;
256 }
257 kfree(buffer.pointer);
258}
259
260static int acpi_processor_get_performance_control(struct acpi_processor *pr) 238static int acpi_processor_get_performance_control(struct acpi_processor *pr)
261{ 239{
262 int result = 0; 240 int result = 0;
diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c
index aef7e1cd1e5d..d465ae6cdd00 100644
--- a/drivers/acpi/sbs.c
+++ b/drivers/acpi/sbs.c
@@ -30,12 +30,6 @@
30#include <linux/moduleparam.h> 30#include <linux/moduleparam.h>
31#include <linux/kernel.h> 31#include <linux/kernel.h>
32 32
33#ifdef CONFIG_ACPI_PROCFS_POWER
34#include <linux/proc_fs.h>
35#include <linux/seq_file.h>
36#include <asm/uaccess.h>
37#endif
38
39#include <linux/acpi.h> 33#include <linux/acpi.h>
40#include <linux/timer.h> 34#include <linux/timer.h>
41#include <linux/jiffies.h> 35#include <linux/jiffies.h>
@@ -67,11 +61,6 @@ static unsigned int cache_time = 1000;
67module_param(cache_time, uint, 0644); 61module_param(cache_time, uint, 0644);
68MODULE_PARM_DESC(cache_time, "cache time in milliseconds"); 62MODULE_PARM_DESC(cache_time, "cache time in milliseconds");
69 63
70extern struct proc_dir_entry *acpi_lock_ac_dir(void);
71extern struct proc_dir_entry *acpi_lock_battery_dir(void);
72extern void acpi_unlock_ac_dir(struct proc_dir_entry *acpi_ac_dir);
73extern void acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir);
74
75#define MAX_SBS_BAT 4 64#define MAX_SBS_BAT 4
76#define ACPI_SBS_BLOCK_MAX 32 65#define ACPI_SBS_BLOCK_MAX 32
77 66
@@ -84,9 +73,6 @@ MODULE_DEVICE_TABLE(acpi, sbs_device_ids);
84struct acpi_battery { 73struct acpi_battery {
85 struct power_supply bat; 74 struct power_supply bat;
86 struct acpi_sbs *sbs; 75 struct acpi_sbs *sbs;
87#ifdef CONFIG_ACPI_PROCFS_POWER
88 struct proc_dir_entry *proc_entry;
89#endif
90 unsigned long update_time; 76 unsigned long update_time;
91 char name[8]; 77 char name[8];
92 char manufacturer_name[ACPI_SBS_BLOCK_MAX]; 78 char manufacturer_name[ACPI_SBS_BLOCK_MAX];
@@ -119,9 +105,6 @@ struct acpi_sbs {
119 struct acpi_device *device; 105 struct acpi_device *device;
120 struct acpi_smb_hc *hc; 106 struct acpi_smb_hc *hc;
121 struct mutex lock; 107 struct mutex lock;
122#ifdef CONFIG_ACPI_PROCFS_POWER
123 struct proc_dir_entry *charger_entry;
124#endif
125 struct acpi_battery battery[MAX_SBS_BAT]; 108 struct acpi_battery battery[MAX_SBS_BAT];
126 u8 batteries_supported:4; 109 u8 batteries_supported:4;
127 u8 manager_present:1; 110 u8 manager_present:1;
@@ -482,261 +465,6 @@ static struct device_attribute alarm_attr = {
482}; 465};
483 466
484/* -------------------------------------------------------------------------- 467/* --------------------------------------------------------------------------
485 FS Interface (/proc/acpi)
486 -------------------------------------------------------------------------- */
487
488#ifdef CONFIG_ACPI_PROCFS_POWER
489/* Generic Routines */
490static int
491acpi_sbs_add_fs(struct proc_dir_entry **dir,
492 struct proc_dir_entry *parent_dir,
493 char *dir_name,
494 const struct file_operations *info_fops,
495 const struct file_operations *state_fops,
496 const struct file_operations *alarm_fops, void *data)
497{
498 printk(KERN_WARNING PREFIX "Deprecated procfs I/F for SBS is loaded,"
499 " please retry with CONFIG_ACPI_PROCFS_POWER cleared\n");
500 if (!*dir) {
501 *dir = proc_mkdir(dir_name, parent_dir);
502 if (!*dir) {
503 return -ENODEV;
504 }
505 }
506
507 /* 'info' [R] */
508 if (info_fops)
509 proc_create_data(ACPI_SBS_FILE_INFO, S_IRUGO, *dir,
510 info_fops, data);
511
512 /* 'state' [R] */
513 if (state_fops)
514 proc_create_data(ACPI_SBS_FILE_STATE, S_IRUGO, *dir,
515 state_fops, data);
516
517 /* 'alarm' [R/W] */
518 if (alarm_fops)
519 proc_create_data(ACPI_SBS_FILE_ALARM, S_IRUGO, *dir,
520 alarm_fops, data);
521 return 0;
522}
523
524/* Smart Battery Interface */
525static struct proc_dir_entry *acpi_battery_dir = NULL;
526
527static inline char *acpi_battery_units(struct acpi_battery *battery)
528{
529 return acpi_battery_mode(battery) ? " mW" : " mA";
530}
531
532
533static int acpi_battery_read_info(struct seq_file *seq, void *offset)
534{
535 struct acpi_battery *battery = seq->private;
536 struct acpi_sbs *sbs = battery->sbs;
537 int result = 0;
538
539 mutex_lock(&sbs->lock);
540
541 seq_printf(seq, "present: %s\n",
542 (battery->present) ? "yes" : "no");
543 if (!battery->present)
544 goto end;
545
546 seq_printf(seq, "design capacity: %i%sh\n",
547 battery->design_capacity * acpi_battery_scale(battery),
548 acpi_battery_units(battery));
549 seq_printf(seq, "last full capacity: %i%sh\n",
550 battery->full_charge_capacity * acpi_battery_scale(battery),
551 acpi_battery_units(battery));
552 seq_printf(seq, "battery technology: rechargeable\n");
553 seq_printf(seq, "design voltage: %i mV\n",
554 battery->design_voltage * acpi_battery_vscale(battery));
555 seq_printf(seq, "design capacity warning: unknown\n");
556 seq_printf(seq, "design capacity low: unknown\n");
557 seq_printf(seq, "cycle count: %i\n", battery->cycle_count);
558 seq_printf(seq, "capacity granularity 1: unknown\n");
559 seq_printf(seq, "capacity granularity 2: unknown\n");
560 seq_printf(seq, "model number: %s\n", battery->device_name);
561 seq_printf(seq, "serial number: %i\n",
562 battery->serial_number);
563 seq_printf(seq, "battery type: %s\n",
564 battery->device_chemistry);
565 seq_printf(seq, "OEM info: %s\n",
566 battery->manufacturer_name);
567 end:
568 mutex_unlock(&sbs->lock);
569 return result;
570}
571
572static int acpi_battery_info_open_fs(struct inode *inode, struct file *file)
573{
574 return single_open(file, acpi_battery_read_info, PDE_DATA(inode));
575}
576
577static int acpi_battery_read_state(struct seq_file *seq, void *offset)
578{
579 struct acpi_battery *battery = seq->private;
580 struct acpi_sbs *sbs = battery->sbs;
581 int rate;
582
583 mutex_lock(&sbs->lock);
584 seq_printf(seq, "present: %s\n",
585 (battery->present) ? "yes" : "no");
586 if (!battery->present)
587 goto end;
588
589 acpi_battery_get_state(battery);
590 seq_printf(seq, "capacity state: %s\n",
591 (battery->state & 0x0010) ? "critical" : "ok");
592 seq_printf(seq, "charging state: %s\n",
593 (battery->rate_now < 0) ? "discharging" :
594 ((battery->rate_now > 0) ? "charging" : "charged"));
595 rate = abs(battery->rate_now) * acpi_battery_ipscale(battery);
596 rate *= (acpi_battery_mode(battery))?(battery->voltage_now *
597 acpi_battery_vscale(battery)/1000):1;
598 seq_printf(seq, "present rate: %d%s\n", rate,
599 acpi_battery_units(battery));
600 seq_printf(seq, "remaining capacity: %i%sh\n",
601 battery->capacity_now * acpi_battery_scale(battery),
602 acpi_battery_units(battery));
603 seq_printf(seq, "present voltage: %i mV\n",
604 battery->voltage_now * acpi_battery_vscale(battery));
605
606 end:
607 mutex_unlock(&sbs->lock);
608 return 0;
609}
610
611static int acpi_battery_state_open_fs(struct inode *inode, struct file *file)
612{
613 return single_open(file, acpi_battery_read_state, PDE_DATA(inode));
614}
615
616static int acpi_battery_read_alarm(struct seq_file *seq, void *offset)
617{
618 struct acpi_battery *battery = seq->private;
619 struct acpi_sbs *sbs = battery->sbs;
620 int result = 0;
621
622 mutex_lock(&sbs->lock);
623
624 if (!battery->present) {
625 seq_printf(seq, "present: no\n");
626 goto end;
627 }
628
629 acpi_battery_get_alarm(battery);
630 seq_printf(seq, "alarm: ");
631 if (battery->alarm_capacity)
632 seq_printf(seq, "%i%sh\n",
633 battery->alarm_capacity *
634 acpi_battery_scale(battery),
635 acpi_battery_units(battery));
636 else
637 seq_printf(seq, "disabled\n");
638 end:
639 mutex_unlock(&sbs->lock);
640 return result;
641}
642
643static ssize_t
644acpi_battery_write_alarm(struct file *file, const char __user * buffer,
645 size_t count, loff_t * ppos)
646{
647 struct seq_file *seq = file->private_data;
648 struct acpi_battery *battery = seq->private;
649 struct acpi_sbs *sbs = battery->sbs;
650 char alarm_string[12] = { '\0' };
651 int result = 0;
652 mutex_lock(&sbs->lock);
653 if (!battery->present) {
654 result = -ENODEV;
655 goto end;
656 }
657 if (count > sizeof(alarm_string) - 1) {
658 result = -EINVAL;
659 goto end;
660 }
661 if (copy_from_user(alarm_string, buffer, count)) {
662 result = -EFAULT;
663 goto end;
664 }
665 alarm_string[count] = 0;
666 battery->alarm_capacity = simple_strtoul(alarm_string, NULL, 0) /
667 acpi_battery_scale(battery);
668 acpi_battery_set_alarm(battery);
669 end:
670 mutex_unlock(&sbs->lock);
671 if (result)
672 return result;
673 return count;
674}
675
676static int acpi_battery_alarm_open_fs(struct inode *inode, struct file *file)
677{
678 return single_open(file, acpi_battery_read_alarm, PDE_DATA(inode));
679}
680
681static const struct file_operations acpi_battery_info_fops = {
682 .open = acpi_battery_info_open_fs,
683 .read = seq_read,
684 .llseek = seq_lseek,
685 .release = single_release,
686 .owner = THIS_MODULE,
687};
688
689static const struct file_operations acpi_battery_state_fops = {
690 .open = acpi_battery_state_open_fs,
691 .read = seq_read,
692 .llseek = seq_lseek,
693 .release = single_release,
694 .owner = THIS_MODULE,
695};
696
697static const struct file_operations acpi_battery_alarm_fops = {
698 .open = acpi_battery_alarm_open_fs,
699 .read = seq_read,
700 .write = acpi_battery_write_alarm,
701 .llseek = seq_lseek,
702 .release = single_release,
703 .owner = THIS_MODULE,
704};
705
706/* Legacy AC Adapter Interface */
707
708static struct proc_dir_entry *acpi_ac_dir = NULL;
709
710static int acpi_ac_read_state(struct seq_file *seq, void *offset)
711{
712
713 struct acpi_sbs *sbs = seq->private;
714
715 mutex_lock(&sbs->lock);
716
717 seq_printf(seq, "state: %s\n",
718 sbs->charger_present ? "on-line" : "off-line");
719
720 mutex_unlock(&sbs->lock);
721 return 0;
722}
723
724static int acpi_ac_state_open_fs(struct inode *inode, struct file *file)
725{
726 return single_open(file, acpi_ac_read_state, PDE_DATA(inode));
727}
728
729static const struct file_operations acpi_ac_state_fops = {
730 .open = acpi_ac_state_open_fs,
731 .read = seq_read,
732 .llseek = seq_lseek,
733 .release = single_release,
734 .owner = THIS_MODULE,
735};
736
737#endif
738
739/* --------------------------------------------------------------------------
740 Driver Interface 468 Driver Interface
741 -------------------------------------------------------------------------- */ 469 -------------------------------------------------------------------------- */
742static int acpi_battery_read(struct acpi_battery *battery) 470static int acpi_battery_read(struct acpi_battery *battery)
@@ -781,12 +509,6 @@ static int acpi_battery_add(struct acpi_sbs *sbs, int id)
781 return result; 509 return result;
782 510
783 sprintf(battery->name, ACPI_BATTERY_DIR_NAME, id); 511 sprintf(battery->name, ACPI_BATTERY_DIR_NAME, id);
784#ifdef CONFIG_ACPI_PROCFS_POWER
785 acpi_sbs_add_fs(&battery->proc_entry, acpi_battery_dir,
786 battery->name, &acpi_battery_info_fops,
787 &acpi_battery_state_fops, &acpi_battery_alarm_fops,
788 battery);
789#endif
790 battery->bat.name = battery->name; 512 battery->bat.name = battery->name;
791 battery->bat.type = POWER_SUPPLY_TYPE_BATTERY; 513 battery->bat.type = POWER_SUPPLY_TYPE_BATTERY;
792 if (!acpi_battery_mode(battery)) { 514 if (!acpi_battery_mode(battery)) {
@@ -822,10 +544,6 @@ static void acpi_battery_remove(struct acpi_sbs *sbs, int id)
822 device_remove_file(battery->bat.dev, &alarm_attr); 544 device_remove_file(battery->bat.dev, &alarm_attr);
823 power_supply_unregister(&battery->bat); 545 power_supply_unregister(&battery->bat);
824 } 546 }
825#ifdef CONFIG_ACPI_PROCFS_POWER
826 proc_remove(battery->proc_entry);
827 battery->proc_entry = NULL;
828#endif
829} 547}
830 548
831static int acpi_charger_add(struct acpi_sbs *sbs) 549static int acpi_charger_add(struct acpi_sbs *sbs)
@@ -835,13 +553,7 @@ static int acpi_charger_add(struct acpi_sbs *sbs)
835 result = acpi_ac_get_present(sbs); 553 result = acpi_ac_get_present(sbs);
836 if (result) 554 if (result)
837 goto end; 555 goto end;
838#ifdef CONFIG_ACPI_PROCFS_POWER 556
839 result = acpi_sbs_add_fs(&sbs->charger_entry, acpi_ac_dir,
840 ACPI_AC_DIR_NAME, NULL,
841 &acpi_ac_state_fops, NULL, sbs);
842 if (result)
843 goto end;
844#endif
845 sbs->charger.name = "sbs-charger"; 557 sbs->charger.name = "sbs-charger";
846 sbs->charger.type = POWER_SUPPLY_TYPE_MAINS; 558 sbs->charger.type = POWER_SUPPLY_TYPE_MAINS;
847 sbs->charger.properties = sbs_ac_props; 559 sbs->charger.properties = sbs_ac_props;
@@ -859,10 +571,6 @@ static void acpi_charger_remove(struct acpi_sbs *sbs)
859{ 571{
860 if (sbs->charger.dev) 572 if (sbs->charger.dev)
861 power_supply_unregister(&sbs->charger); 573 power_supply_unregister(&sbs->charger);
862#ifdef CONFIG_ACPI_PROCFS_POWER
863 proc_remove(sbs->charger_entry);
864 sbs->charger_entry = NULL;
865#endif
866} 574}
867 575
868static void acpi_sbs_callback(void *context) 576static void acpi_sbs_callback(void *context)
@@ -950,20 +658,6 @@ static int acpi_sbs_remove(struct acpi_device *device)
950 return 0; 658 return 0;
951} 659}
952 660
953static void acpi_sbs_rmdirs(void)
954{
955#ifdef CONFIG_ACPI_PROCFS_POWER
956 if (acpi_ac_dir) {
957 acpi_unlock_ac_dir(acpi_ac_dir);
958 acpi_ac_dir = NULL;
959 }
960 if (acpi_battery_dir) {
961 acpi_unlock_battery_dir(acpi_battery_dir);
962 acpi_battery_dir = NULL;
963 }
964#endif
965}
966
967#ifdef CONFIG_PM_SLEEP 661#ifdef CONFIG_PM_SLEEP
968static int acpi_sbs_resume(struct device *dev) 662static int acpi_sbs_resume(struct device *dev)
969{ 663{
@@ -995,28 +689,17 @@ static int __init acpi_sbs_init(void)
995 689
996 if (acpi_disabled) 690 if (acpi_disabled)
997 return -ENODEV; 691 return -ENODEV;
998#ifdef CONFIG_ACPI_PROCFS_POWER 692
999 acpi_ac_dir = acpi_lock_ac_dir();
1000 if (!acpi_ac_dir)
1001 return -ENODEV;
1002 acpi_battery_dir = acpi_lock_battery_dir();
1003 if (!acpi_battery_dir) {
1004 acpi_sbs_rmdirs();
1005 return -ENODEV;
1006 }
1007#endif
1008 result = acpi_bus_register_driver(&acpi_sbs_driver); 693 result = acpi_bus_register_driver(&acpi_sbs_driver);
1009 if (result < 0) { 694 if (result < 0)
1010 acpi_sbs_rmdirs();
1011 return -ENODEV; 695 return -ENODEV;
1012 } 696
1013 return 0; 697 return 0;
1014} 698}
1015 699
1016static void __exit acpi_sbs_exit(void) 700static void __exit acpi_sbs_exit(void)
1017{ 701{
1018 acpi_bus_unregister_driver(&acpi_sbs_driver); 702 acpi_bus_unregister_driver(&acpi_sbs_driver);
1019 acpi_sbs_rmdirs();
1020 return; 703 return;
1021} 704}
1022 705
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index fee8a297c7d9..55f9dedbbf9f 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -125,8 +125,8 @@ acpi_device_modalias_show(struct device *dev, struct device_attribute *attr, cha
125} 125}
126static DEVICE_ATTR(modalias, 0444, acpi_device_modalias_show, NULL); 126static DEVICE_ATTR(modalias, 0444, acpi_device_modalias_show, NULL);
127 127
128static acpi_status acpi_bus_offline_companions(acpi_handle handle, u32 lvl, 128static acpi_status acpi_bus_offline(acpi_handle handle, u32 lvl, void *data,
129 void *data, void **ret_p) 129 void **ret_p)
130{ 130{
131 struct acpi_device *device = NULL; 131 struct acpi_device *device = NULL;
132 struct acpi_device_physical_node *pn; 132 struct acpi_device_physical_node *pn;
@@ -136,6 +136,11 @@ static acpi_status acpi_bus_offline_companions(acpi_handle handle, u32 lvl,
136 if (acpi_bus_get_device(handle, &device)) 136 if (acpi_bus_get_device(handle, &device))
137 return AE_OK; 137 return AE_OK;
138 138
139 if (device->handler && !device->handler->hotplug.enabled) {
140 *ret_p = &device->dev;
141 return AE_SUPPORT;
142 }
143
139 mutex_lock(&device->physical_node_lock); 144 mutex_lock(&device->physical_node_lock);
140 145
141 list_for_each_entry(pn, &device->physical_node_list, node) { 146 list_for_each_entry(pn, &device->physical_node_list, node) {
@@ -168,8 +173,8 @@ static acpi_status acpi_bus_offline_companions(acpi_handle handle, u32 lvl,
168 return status; 173 return status;
169} 174}
170 175
171static acpi_status acpi_bus_online_companions(acpi_handle handle, u32 lvl, 176static acpi_status acpi_bus_online(acpi_handle handle, u32 lvl, void *data,
172 void *data, void **ret_p) 177 void **ret_p)
173{ 178{
174 struct acpi_device *device = NULL; 179 struct acpi_device *device = NULL;
175 struct acpi_device_physical_node *pn; 180 struct acpi_device_physical_node *pn;
@@ -214,26 +219,32 @@ static int acpi_scan_hot_remove(struct acpi_device *device)
214 * If the first pass is successful, the second one isn't needed, though. 219 * If the first pass is successful, the second one isn't needed, though.
215 */ 220 */
216 errdev = NULL; 221 errdev = NULL;
217 acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX, 222 status = acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX,
218 NULL, acpi_bus_offline_companions, 223 NULL, acpi_bus_offline, (void *)false,
219 (void *)false, (void **)&errdev); 224 (void **)&errdev);
220 acpi_bus_offline_companions(handle, 0, (void *)false, (void **)&errdev); 225 if (status == AE_SUPPORT) {
226 dev_warn(errdev, "Offline disabled.\n");
227 acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX,
228 acpi_bus_online, NULL, NULL, NULL);
229 put_device(&device->dev);
230 return -EPERM;
231 }
232 acpi_bus_offline(handle, 0, (void *)false, (void **)&errdev);
221 if (errdev) { 233 if (errdev) {
222 errdev = NULL; 234 errdev = NULL;
223 acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX, 235 acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX,
224 NULL, acpi_bus_offline_companions, 236 NULL, acpi_bus_offline, (void *)true,
225 (void *)true , (void **)&errdev); 237 (void **)&errdev);
226 if (!errdev || acpi_force_hot_remove) 238 if (!errdev || acpi_force_hot_remove)
227 acpi_bus_offline_companions(handle, 0, (void *)true, 239 acpi_bus_offline(handle, 0, (void *)true,
228 (void **)&errdev); 240 (void **)&errdev);
229 241
230 if (errdev && !acpi_force_hot_remove) { 242 if (errdev && !acpi_force_hot_remove) {
231 dev_warn(errdev, "Offline failed.\n"); 243 dev_warn(errdev, "Offline failed.\n");
232 acpi_bus_online_companions(handle, 0, NULL, NULL); 244 acpi_bus_online(handle, 0, NULL, NULL);
233 acpi_walk_namespace(ACPI_TYPE_ANY, handle, 245 acpi_walk_namespace(ACPI_TYPE_ANY, handle,
234 ACPI_UINT32_MAX, 246 ACPI_UINT32_MAX, acpi_bus_online,
235 acpi_bus_online_companions, NULL, 247 NULL, NULL, NULL);
236 NULL, NULL);
237 put_device(&device->dev); 248 put_device(&device->dev);
238 return -EBUSY; 249 return -EBUSY;
239 } 250 }
@@ -274,10 +285,10 @@ static int acpi_scan_hot_remove(struct acpi_device *device)
274 return 0; 285 return 0;
275} 286}
276 287
277static void acpi_bus_device_eject(void *context) 288void acpi_bus_device_eject(void *data, u32 ost_src)
278{ 289{
279 acpi_handle handle = context; 290 struct acpi_device *device = data;
280 struct acpi_device *device = NULL; 291 acpi_handle handle = device->handle;
281 struct acpi_scan_handler *handler; 292 struct acpi_scan_handler *handler;
282 u32 ost_code = ACPI_OST_SC_NON_SPECIFIC_FAILURE; 293 u32 ost_code = ACPI_OST_SC_NON_SPECIFIC_FAILURE;
283 int error; 294 int error;
@@ -285,38 +296,41 @@ static void acpi_bus_device_eject(void *context)
285 lock_device_hotplug(); 296 lock_device_hotplug();
286 mutex_lock(&acpi_scan_lock); 297 mutex_lock(&acpi_scan_lock);
287 298
288 acpi_bus_get_device(handle, &device);
289 if (!device)
290 goto err_out;
291
292 handler = device->handler; 299 handler = device->handler;
293 if (!handler || !handler->hotplug.enabled) { 300 if (!handler || !handler->hotplug.enabled) {
294 ost_code = ACPI_OST_SC_EJECT_NOT_SUPPORTED; 301 put_device(&device->dev);
295 goto err_out; 302 goto err_support;
296 } 303 }
297 acpi_evaluate_hotplug_ost(handle, ACPI_NOTIFY_EJECT_REQUEST, 304
298 ACPI_OST_SC_EJECT_IN_PROGRESS, NULL); 305 if (ost_src == ACPI_NOTIFY_EJECT_REQUEST)
306 acpi_evaluate_hotplug_ost(handle, ACPI_NOTIFY_EJECT_REQUEST,
307 ACPI_OST_SC_EJECT_IN_PROGRESS, NULL);
308
299 if (handler->hotplug.mode == AHM_CONTAINER) 309 if (handler->hotplug.mode == AHM_CONTAINER)
300 kobject_uevent(&device->dev.kobj, KOBJ_OFFLINE); 310 kobject_uevent(&device->dev.kobj, KOBJ_OFFLINE);
301 311
302 get_device(&device->dev);
303 error = acpi_scan_hot_remove(device); 312 error = acpi_scan_hot_remove(device);
304 if (error) 313 if (error == -EPERM) {
314 goto err_support;
315 } else if (error) {
305 goto err_out; 316 goto err_out;
317 }
306 318
307 out: 319 out:
308 mutex_unlock(&acpi_scan_lock); 320 mutex_unlock(&acpi_scan_lock);
309 unlock_device_hotplug(); 321 unlock_device_hotplug();
310 return; 322 return;
311 323
324 err_support:
325 ost_code = ACPI_OST_SC_EJECT_NOT_SUPPORTED;
312 err_out: 326 err_out:
313 acpi_evaluate_hotplug_ost(handle, ACPI_NOTIFY_EJECT_REQUEST, ost_code, 327 acpi_evaluate_hotplug_ost(handle, ost_src, ost_code, NULL);
314 NULL);
315 goto out; 328 goto out;
316} 329}
317 330
318static void acpi_scan_bus_device_check(acpi_handle handle, u32 ost_source) 331static void acpi_scan_bus_device_check(void *data, u32 ost_source)
319{ 332{
333 acpi_handle handle = data;
320 struct acpi_device *device = NULL; 334 struct acpi_device *device = NULL;
321 u32 ost_code = ACPI_OST_SC_NON_SPECIFIC_FAILURE; 335 u32 ost_code = ACPI_OST_SC_NON_SPECIFIC_FAILURE;
322 int error; 336 int error;
@@ -331,8 +345,6 @@ static void acpi_scan_bus_device_check(acpi_handle handle, u32 ost_source)
331 goto out; 345 goto out;
332 } 346 }
333 } 347 }
334 acpi_evaluate_hotplug_ost(handle, ost_source,
335 ACPI_OST_SC_INSERT_IN_PROGRESS, NULL);
336 error = acpi_bus_scan(handle); 348 error = acpi_bus_scan(handle);
337 if (error) { 349 if (error) {
338 acpi_handle_warn(handle, "Namespace scan failure\n"); 350 acpi_handle_warn(handle, "Namespace scan failure\n");
@@ -353,18 +365,6 @@ static void acpi_scan_bus_device_check(acpi_handle handle, u32 ost_source)
353 unlock_device_hotplug(); 365 unlock_device_hotplug();
354} 366}
355 367
356static void acpi_scan_bus_check(void *context)
357{
358 acpi_scan_bus_device_check((acpi_handle)context,
359 ACPI_NOTIFY_BUS_CHECK);
360}
361
362static void acpi_scan_device_check(void *context)
363{
364 acpi_scan_bus_device_check((acpi_handle)context,
365 ACPI_NOTIFY_DEVICE_CHECK);
366}
367
368static void acpi_hotplug_unsupported(acpi_handle handle, u32 type) 368static void acpi_hotplug_unsupported(acpi_handle handle, u32 type)
369{ 369{
370 u32 ost_status; 370 u32 ost_status;
@@ -395,8 +395,8 @@ static void acpi_hotplug_unsupported(acpi_handle handle, u32 type)
395 395
396static void acpi_hotplug_notify_cb(acpi_handle handle, u32 type, void *data) 396static void acpi_hotplug_notify_cb(acpi_handle handle, u32 type, void *data)
397{ 397{
398 acpi_osd_exec_callback callback;
399 struct acpi_scan_handler *handler = data; 398 struct acpi_scan_handler *handler = data;
399 struct acpi_device *adev;
400 acpi_status status; 400 acpi_status status;
401 401
402 if (!handler->hotplug.enabled) 402 if (!handler->hotplug.enabled)
@@ -405,56 +405,35 @@ static void acpi_hotplug_notify_cb(acpi_handle handle, u32 type, void *data)
405 switch (type) { 405 switch (type) {
406 case ACPI_NOTIFY_BUS_CHECK: 406 case ACPI_NOTIFY_BUS_CHECK:
407 acpi_handle_debug(handle, "ACPI_NOTIFY_BUS_CHECK event\n"); 407 acpi_handle_debug(handle, "ACPI_NOTIFY_BUS_CHECK event\n");
408 callback = acpi_scan_bus_check;
409 break; 408 break;
410 case ACPI_NOTIFY_DEVICE_CHECK: 409 case ACPI_NOTIFY_DEVICE_CHECK:
411 acpi_handle_debug(handle, "ACPI_NOTIFY_DEVICE_CHECK event\n"); 410 acpi_handle_debug(handle, "ACPI_NOTIFY_DEVICE_CHECK event\n");
412 callback = acpi_scan_device_check;
413 break; 411 break;
414 case ACPI_NOTIFY_EJECT_REQUEST: 412 case ACPI_NOTIFY_EJECT_REQUEST:
415 acpi_handle_debug(handle, "ACPI_NOTIFY_EJECT_REQUEST event\n"); 413 acpi_handle_debug(handle, "ACPI_NOTIFY_EJECT_REQUEST event\n");
416 callback = acpi_bus_device_eject; 414 status = acpi_bus_get_device(handle, &adev);
417 break; 415 if (ACPI_FAILURE(status))
416 goto err_out;
417
418 get_device(&adev->dev);
419 status = acpi_hotplug_execute(acpi_bus_device_eject, adev, type);
420 if (ACPI_SUCCESS(status))
421 return;
422
423 put_device(&adev->dev);
424 goto err_out;
418 default: 425 default:
419 /* non-hotplug event; possibly handled by other handler */ 426 /* non-hotplug event; possibly handled by other handler */
420 return; 427 return;
421 } 428 }
422 status = acpi_os_hotplug_execute(callback, handle); 429 status = acpi_hotplug_execute(acpi_scan_bus_device_check, handle, type);
423 if (ACPI_FAILURE(status)) 430 if (ACPI_SUCCESS(status))
424 acpi_evaluate_hotplug_ost(handle, type, 431 return;
425 ACPI_OST_SC_NON_SPECIFIC_FAILURE,
426 NULL);
427}
428
429/**
430 * acpi_bus_hot_remove_device: hot-remove a device and its children
431 * @context: struct acpi_eject_event pointer (freed in this func)
432 *
433 * Hot-remove a device and its children. This function frees up the
434 * memory space passed by arg context, so that the caller may call
435 * this function asynchronously through acpi_os_hotplug_execute().
436 */
437void acpi_bus_hot_remove_device(void *context)
438{
439 struct acpi_eject_event *ej_event = context;
440 struct acpi_device *device = ej_event->device;
441 acpi_handle handle = device->handle;
442 int error;
443
444 lock_device_hotplug();
445 mutex_lock(&acpi_scan_lock);
446
447 error = acpi_scan_hot_remove(device);
448 if (error && handle)
449 acpi_evaluate_hotplug_ost(handle, ej_event->event,
450 ACPI_OST_SC_NON_SPECIFIC_FAILURE,
451 NULL);
452 432
453 mutex_unlock(&acpi_scan_lock); 433 err_out:
454 unlock_device_hotplug(); 434 acpi_evaluate_hotplug_ost(handle, type,
455 kfree(context); 435 ACPI_OST_SC_NON_SPECIFIC_FAILURE, NULL);
456} 436}
457EXPORT_SYMBOL(acpi_bus_hot_remove_device);
458 437
459static ssize_t real_power_state_show(struct device *dev, 438static ssize_t real_power_state_show(struct device *dev,
460 struct device_attribute *attr, char *buf) 439 struct device_attribute *attr, char *buf)
@@ -487,10 +466,8 @@ acpi_eject_store(struct device *d, struct device_attribute *attr,
487 const char *buf, size_t count) 466 const char *buf, size_t count)
488{ 467{
489 struct acpi_device *acpi_device = to_acpi_device(d); 468 struct acpi_device *acpi_device = to_acpi_device(d);
490 struct acpi_eject_event *ej_event;
491 acpi_object_type not_used; 469 acpi_object_type not_used;
492 acpi_status status; 470 acpi_status status;
493 int ret;
494 471
495 if (!count || buf[0] != '1') 472 if (!count || buf[0] != '1')
496 return -EINVAL; 473 return -EINVAL;
@@ -503,28 +480,18 @@ acpi_eject_store(struct device *d, struct device_attribute *attr,
503 if (ACPI_FAILURE(status) || !acpi_device->flags.ejectable) 480 if (ACPI_FAILURE(status) || !acpi_device->flags.ejectable)
504 return -ENODEV; 481 return -ENODEV;
505 482
506 ej_event = kmalloc(sizeof(*ej_event), GFP_KERNEL);
507 if (!ej_event) {
508 ret = -ENOMEM;
509 goto err_out;
510 }
511 acpi_evaluate_hotplug_ost(acpi_device->handle, ACPI_OST_EC_OSPM_EJECT, 483 acpi_evaluate_hotplug_ost(acpi_device->handle, ACPI_OST_EC_OSPM_EJECT,
512 ACPI_OST_SC_EJECT_IN_PROGRESS, NULL); 484 ACPI_OST_SC_EJECT_IN_PROGRESS, NULL);
513 ej_event->device = acpi_device;
514 ej_event->event = ACPI_OST_EC_OSPM_EJECT;
515 get_device(&acpi_device->dev); 485 get_device(&acpi_device->dev);
516 status = acpi_os_hotplug_execute(acpi_bus_hot_remove_device, ej_event); 486 status = acpi_hotplug_execute(acpi_bus_device_eject, acpi_device,
487 ACPI_OST_EC_OSPM_EJECT);
517 if (ACPI_SUCCESS(status)) 488 if (ACPI_SUCCESS(status))
518 return count; 489 return count;
519 490
520 put_device(&acpi_device->dev); 491 put_device(&acpi_device->dev);
521 kfree(ej_event);
522 ret = status == AE_NO_MEMORY ? -ENOMEM : -EAGAIN;
523
524 err_out:
525 acpi_evaluate_hotplug_ost(acpi_device->handle, ACPI_OST_EC_OSPM_EJECT, 492 acpi_evaluate_hotplug_ost(acpi_device->handle, ACPI_OST_EC_OSPM_EJECT,
526 ACPI_OST_SC_NON_SPECIFIC_FAILURE, NULL); 493 ACPI_OST_SC_NON_SPECIFIC_FAILURE, NULL);
527 return ret; 494 return status == AE_NO_MEMORY ? -ENOMEM : -EAGAIN;
528} 495}
529 496
530static DEVICE_ATTR(eject, 0200, NULL, acpi_eject_store); 497static DEVICE_ATTR(eject, 0200, NULL, acpi_eject_store);
@@ -1676,7 +1643,6 @@ void acpi_init_device_object(struct acpi_device *device, acpi_handle handle,
1676 1643
1677void acpi_device_add_finalize(struct acpi_device *device) 1644void acpi_device_add_finalize(struct acpi_device *device)
1678{ 1645{
1679 device->flags.match_driver = true;
1680 dev_set_uevent_suppress(&device->dev, false); 1646 dev_set_uevent_suppress(&device->dev, false);
1681 kobject_uevent(&device->dev.kobj, KOBJ_ADD); 1647 kobject_uevent(&device->dev.kobj, KOBJ_ADD);
1682} 1648}
@@ -1915,8 +1881,12 @@ static acpi_status acpi_bus_device_attach(acpi_handle handle, u32 lvl_not_used,
1915 return AE_OK; 1881 return AE_OK;
1916 1882
1917 ret = acpi_scan_attach_handler(device); 1883 ret = acpi_scan_attach_handler(device);
1918 if (ret) 1884 if (ret < 0)
1919 return ret > 0 ? AE_OK : AE_CTRL_DEPTH; 1885 return AE_CTRL_DEPTH;
1886
1887 device->flags.match_driver = true;
1888 if (ret > 0)
1889 return AE_OK;
1920 1890
1921 ret = device_attach(&device->dev); 1891 ret = device_attach(&device->dev);
1922 return ret >= 0 ? AE_OK : AE_CTRL_DEPTH; 1892 return ret >= 0 ? AE_OK : AE_CTRL_DEPTH;
diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
index 05306a59aedc..db5293650f62 100644
--- a/drivers/acpi/sysfs.c
+++ b/drivers/acpi/sysfs.c
@@ -564,6 +564,7 @@ static ssize_t counter_set(struct kobject *kobj,
564 acpi_event_status status; 564 acpi_event_status status;
565 acpi_handle handle; 565 acpi_handle handle;
566 int result = 0; 566 int result = 0;
567 unsigned long tmp;
567 568
568 if (index == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI) { 569 if (index == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI) {
569 int i; 570 int i;
@@ -596,8 +597,10 @@ static ssize_t counter_set(struct kobject *kobj,
596 else if (!strcmp(buf, "clear\n") && 597 else if (!strcmp(buf, "clear\n") &&
597 (status & ACPI_EVENT_FLAG_SET)) 598 (status & ACPI_EVENT_FLAG_SET))
598 result = acpi_clear_gpe(handle, index); 599 result = acpi_clear_gpe(handle, index);
600 else if (!kstrtoul(buf, 0, &tmp))
601 all_counters[index].count = tmp;
599 else 602 else
600 all_counters[index].count = strtoul(buf, NULL, 0); 603 result = -EINVAL;
601 } else if (index < num_gpes + ACPI_NUM_FIXED_EVENTS) { 604 } else if (index < num_gpes + ACPI_NUM_FIXED_EVENTS) {
602 int event = index - num_gpes; 605 int event = index - num_gpes;
603 if (!strcmp(buf, "disable\n") && 606 if (!strcmp(buf, "disable\n") &&
@@ -609,8 +612,10 @@ static ssize_t counter_set(struct kobject *kobj,
609 else if (!strcmp(buf, "clear\n") && 612 else if (!strcmp(buf, "clear\n") &&
610 (status & ACPI_EVENT_FLAG_SET)) 613 (status & ACPI_EVENT_FLAG_SET))
611 result = acpi_clear_event(event); 614 result = acpi_clear_event(event);
615 else if (!kstrtoul(buf, 0, &tmp))
616 all_counters[index].count = tmp;
612 else 617 else
613 all_counters[index].count = strtoul(buf, NULL, 0); 618 result = -EINVAL;
614 } else 619 } else
615 all_counters[index].count = strtoul(buf, NULL, 0); 620 all_counters[index].count = strtoul(buf, NULL, 0);
616 621
@@ -762,13 +767,8 @@ void acpi_sysfs_add_hotplug_profile(struct acpi_hotplug_profile *hotplug,
762 if (!hotplug_kobj) 767 if (!hotplug_kobj)
763 goto err_out; 768 goto err_out;
764 769
765 kobject_init(&hotplug->kobj, &acpi_hotplug_profile_ktype); 770 error = kobject_init_and_add(&hotplug->kobj,
766 error = kobject_set_name(&hotplug->kobj, "%s", name); 771 &acpi_hotplug_profile_ktype, hotplug_kobj, "%s", name);
767 if (error)
768 goto err_out;
769
770 hotplug->kobj.parent = hotplug_kobj;
771 error = kobject_add(&hotplug->kobj, hotplug_kobj, NULL);
772 if (error) 772 if (error)
773 goto err_out; 773 goto err_out;
774 774
diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c
index 6a0329340b42..e600b5dbfcb6 100644
--- a/drivers/acpi/thermal.c
+++ b/drivers/acpi/thermal.c
@@ -299,8 +299,8 @@ static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag)
299 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 299 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
300 "No critical threshold\n")); 300 "No critical threshold\n"));
301 } else if (tmp <= 2732) { 301 } else if (tmp <= 2732) {
302 printk(KERN_WARNING FW_BUG "Invalid critical threshold " 302 pr_warn(FW_BUG "Invalid critical threshold (%llu)\n",
303 "(%llu)\n", tmp); 303 tmp);
304 tz->trips.critical.flags.valid = 0; 304 tz->trips.critical.flags.valid = 0;
305 } else { 305 } else {
306 tz->trips.critical.flags.valid = 1; 306 tz->trips.critical.flags.valid = 1;
@@ -317,8 +317,8 @@ static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag)
317 * Allow override critical threshold 317 * Allow override critical threshold
318 */ 318 */
319 if (crt_k > tz->trips.critical.temperature) 319 if (crt_k > tz->trips.critical.temperature)
320 printk(KERN_WARNING PREFIX 320 pr_warn(PREFIX "Critical threshold %d C\n",
321 "Critical threshold %d C\n", crt); 321 crt);
322 tz->trips.critical.temperature = crt_k; 322 tz->trips.critical.temperature = crt_k;
323 } 323 }
324 } 324 }
@@ -390,8 +390,7 @@ static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag)
390 status = acpi_evaluate_reference(tz->device->handle, "_PSL", 390 status = acpi_evaluate_reference(tz->device->handle, "_PSL",
391 NULL, &devices); 391 NULL, &devices);
392 if (ACPI_FAILURE(status)) { 392 if (ACPI_FAILURE(status)) {
393 printk(KERN_WARNING PREFIX 393 pr_warn(PREFIX "Invalid passive threshold\n");
394 "Invalid passive threshold\n");
395 tz->trips.passive.flags.valid = 0; 394 tz->trips.passive.flags.valid = 0;
396 } 395 }
397 else 396 else
@@ -453,8 +452,8 @@ static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag)
453 status = acpi_evaluate_reference(tz->device->handle, 452 status = acpi_evaluate_reference(tz->device->handle,
454 name, NULL, &devices); 453 name, NULL, &devices);
455 if (ACPI_FAILURE(status)) { 454 if (ACPI_FAILURE(status)) {
456 printk(KERN_WARNING PREFIX 455 pr_warn(PREFIX "Invalid active%d threshold\n",
457 "Invalid active%d threshold\n", i); 456 i);
458 tz->trips.active[i].flags.valid = 0; 457 tz->trips.active[i].flags.valid = 0;
459 } 458 }
460 else 459 else
@@ -505,7 +504,7 @@ static int acpi_thermal_get_trip_points(struct acpi_thermal *tz)
505 valid |= tz->trips.active[i].flags.valid; 504 valid |= tz->trips.active[i].flags.valid;
506 505
507 if (!valid) { 506 if (!valid) {
508 printk(KERN_WARNING FW_BUG "No valid trip found\n"); 507 pr_warn(FW_BUG "No valid trip found\n");
509 return -ENODEV; 508 return -ENODEV;
510 } 509 }
511 return 0; 510 return 0;
@@ -923,8 +922,7 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz)
923 acpi_bus_private_data_handler, 922 acpi_bus_private_data_handler,
924 tz->thermal_zone); 923 tz->thermal_zone);
925 if (ACPI_FAILURE(status)) { 924 if (ACPI_FAILURE(status)) {
926 printk(KERN_ERR PREFIX 925 pr_err(PREFIX "Error attaching device data\n");
927 "Error attaching device data\n");
928 return -ENODEV; 926 return -ENODEV;
929 } 927 }
930 928
@@ -1094,9 +1092,8 @@ static int acpi_thermal_add(struct acpi_device *device)
1094 if (result) 1092 if (result)
1095 goto free_memory; 1093 goto free_memory;
1096 1094
1097 printk(KERN_INFO PREFIX "%s [%s] (%ld C)\n", 1095 pr_info(PREFIX "%s [%s] (%ld C)\n", acpi_device_name(device),
1098 acpi_device_name(device), acpi_device_bid(device), 1096 acpi_device_bid(device), KELVIN_TO_CELSIUS(tz->temperature));
1099 KELVIN_TO_CELSIUS(tz->temperature));
1100 goto end; 1097 goto end;
1101 1098
1102free_memory: 1099free_memory:
@@ -1159,24 +1156,24 @@ static int acpi_thermal_resume(struct device *dev)
1159static int thermal_act(const struct dmi_system_id *d) { 1156static int thermal_act(const struct dmi_system_id *d) {
1160 1157
1161 if (act == 0) { 1158 if (act == 0) {
1162 printk(KERN_NOTICE "ACPI: %s detected: " 1159 pr_notice(PREFIX "%s detected: "
1163 "disabling all active thermal trip points\n", d->ident); 1160 "disabling all active thermal trip points\n", d->ident);
1164 act = -1; 1161 act = -1;
1165 } 1162 }
1166 return 0; 1163 return 0;
1167} 1164}
1168static int thermal_nocrt(const struct dmi_system_id *d) { 1165static int thermal_nocrt(const struct dmi_system_id *d) {
1169 1166
1170 printk(KERN_NOTICE "ACPI: %s detected: " 1167 pr_notice(PREFIX "%s detected: "
1171 "disabling all critical thermal trip point actions.\n", d->ident); 1168 "disabling all critical thermal trip point actions.\n", d->ident);
1172 nocrt = 1; 1169 nocrt = 1;
1173 return 0; 1170 return 0;
1174} 1171}
1175static int thermal_tzp(const struct dmi_system_id *d) { 1172static int thermal_tzp(const struct dmi_system_id *d) {
1176 1173
1177 if (tzp == 0) { 1174 if (tzp == 0) {
1178 printk(KERN_NOTICE "ACPI: %s detected: " 1175 pr_notice(PREFIX "%s detected: "
1179 "enabling thermal zone polling\n", d->ident); 1176 "enabling thermal zone polling\n", d->ident);
1180 tzp = 300; /* 300 dS = 30 Seconds */ 1177 tzp = 300; /* 300 dS = 30 Seconds */
1181 } 1178 }
1182 return 0; 1179 return 0;
@@ -1184,8 +1181,8 @@ static int thermal_tzp(const struct dmi_system_id *d) {
1184static int thermal_psv(const struct dmi_system_id *d) { 1181static int thermal_psv(const struct dmi_system_id *d) {
1185 1182
1186 if (psv == 0) { 1183 if (psv == 0) {
1187 printk(KERN_NOTICE "ACPI: %s detected: " 1184 pr_notice(PREFIX "%s detected: "
1188 "disabling all passive thermal trip points\n", d->ident); 1185 "disabling all passive thermal trip points\n", d->ident);
1189 psv = -1; 1186 psv = -1;
1190 } 1187 }
1191 return 0; 1188 return 0;
@@ -1238,7 +1235,7 @@ static int __init acpi_thermal_init(void)
1238 dmi_check_system(thermal_dmi_table); 1235 dmi_check_system(thermal_dmi_table);
1239 1236
1240 if (off) { 1237 if (off) {
1241 printk(KERN_NOTICE "ACPI: thermal control disabled\n"); 1238 pr_notice(PREFIX "thermal control disabled\n");
1242 return -ENODEV; 1239 return -ENODEV;
1243 } 1240 }
1244 1241
diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c
index 552248b0005b..6d408bfbbb1d 100644
--- a/drivers/acpi/utils.c
+++ b/drivers/acpi/utils.c
@@ -121,7 +121,7 @@ acpi_extract_package(union acpi_object *package,
121 break; 121 break;
122 default: 122 default:
123 printk(KERN_WARNING PREFIX "Invalid package element" 123 printk(KERN_WARNING PREFIX "Invalid package element"
124 " [%d]: got number, expecing" 124 " [%d]: got number, expecting"
125 " [%c]\n", 125 " [%c]\n",
126 i, format_string[i]); 126 i, format_string[i]);
127 return AE_BAD_DATA; 127 return AE_BAD_DATA;
@@ -148,7 +148,7 @@ acpi_extract_package(union acpi_object *package,
148 default: 148 default:
149 printk(KERN_WARNING PREFIX "Invalid package element" 149 printk(KERN_WARNING PREFIX "Invalid package element"
150 " [%d] got string/buffer," 150 " [%d] got string/buffer,"
151 " expecing [%c]\n", 151 " expecting [%c]\n",
152 i, format_string[i]); 152 i, format_string[i]);
153 return AE_BAD_DATA; 153 return AE_BAD_DATA;
154 break; 154 break;
@@ -169,11 +169,20 @@ acpi_extract_package(union acpi_object *package,
169 /* 169 /*
170 * Validate output buffer. 170 * Validate output buffer.
171 */ 171 */
172 if (buffer->length < size_required) { 172 if (buffer->length == ACPI_ALLOCATE_BUFFER) {
173 buffer->pointer = ACPI_ALLOCATE(size_required);
174 if (!buffer->pointer)
175 return AE_NO_MEMORY;
173 buffer->length = size_required; 176 buffer->length = size_required;
174 return AE_BUFFER_OVERFLOW; 177 memset(buffer->pointer, 0, size_required);
175 } else if (buffer->length != size_required || !buffer->pointer) { 178 } else {
176 return AE_BAD_PARAMETER; 179 if (buffer->length < size_required) {
180 buffer->length = size_required;
181 return AE_BUFFER_OVERFLOW;
182 } else if (buffer->length != size_required ||
183 !buffer->pointer) {
184 return AE_BAD_PARAMETER;
185 }
177 } 186 }
178 187
179 head = buffer->pointer; 188 head = buffer->pointer;
diff --git a/drivers/acpi/video.c b/drivers/acpi/video.c
index aebcf6355df4..18dbdff4656e 100644
--- a/drivers/acpi/video.c
+++ b/drivers/acpi/video.c
@@ -88,7 +88,16 @@ module_param(allow_duplicates, bool, 0644);
88static bool use_bios_initial_backlight = 1; 88static bool use_bios_initial_backlight = 1;
89module_param(use_bios_initial_backlight, bool, 0644); 89module_param(use_bios_initial_backlight, bool, 0644);
90 90
91/*
92 * For Windows 8 systems: if set ture and the GPU driver has
93 * registered a backlight interface, skip registering ACPI video's.
94 */
95static bool use_native_backlight = false;
96module_param(use_native_backlight, bool, 0644);
97
91static int register_count; 98static int register_count;
99static struct mutex video_list_lock;
100static struct list_head video_bus_head;
92static int acpi_video_bus_add(struct acpi_device *device); 101static int acpi_video_bus_add(struct acpi_device *device);
93static int acpi_video_bus_remove(struct acpi_device *device); 102static int acpi_video_bus_remove(struct acpi_device *device);
94static void acpi_video_bus_notify(struct acpi_device *device, u32 event); 103static void acpi_video_bus_notify(struct acpi_device *device, u32 event);
@@ -157,6 +166,7 @@ struct acpi_video_bus {
157 struct acpi_video_bus_flags flags; 166 struct acpi_video_bus_flags flags;
158 struct list_head video_device_list; 167 struct list_head video_device_list;
159 struct mutex device_list_lock; /* protects video_device_list */ 168 struct mutex device_list_lock; /* protects video_device_list */
169 struct list_head entry;
160 struct input_dev *input; 170 struct input_dev *input;
161 char phys[32]; /* for input device */ 171 char phys[32]; /* for input device */
162 struct notifier_block pm_nb; 172 struct notifier_block pm_nb;
@@ -229,6 +239,14 @@ static int acpi_video_get_next_level(struct acpi_video_device *device,
229static int acpi_video_switch_brightness(struct acpi_video_device *device, 239static int acpi_video_switch_brightness(struct acpi_video_device *device,
230 int event); 240 int event);
231 241
242static bool acpi_video_verify_backlight_support(void)
243{
244 if (acpi_osi_is_win8() && use_native_backlight &&
245 backlight_device_registered(BACKLIGHT_RAW))
246 return false;
247 return acpi_video_backlight_support();
248}
249
232/* backlight device sysfs support */ 250/* backlight device sysfs support */
233static int acpi_video_get_brightness(struct backlight_device *bd) 251static int acpi_video_get_brightness(struct backlight_device *bd)
234{ 252{
@@ -830,9 +848,9 @@ acpi_video_init_brightness(struct acpi_video_device *device)
830 * or an index). Set the backlight to max_level in this case. 848 * or an index). Set the backlight to max_level in this case.
831 */ 849 */
832 for (i = 2; i < br->count; i++) 850 for (i = 2; i < br->count; i++)
833 if (level_old == br->levels[i]) 851 if (level == br->levels[i])
834 break; 852 break;
835 if (i == br->count) 853 if (i == br->count || !level)
836 level = max_level; 854 level = max_level;
837 } 855 }
838 856
@@ -884,79 +902,6 @@ static void acpi_video_device_find_cap(struct acpi_video_device *device)
884 902
885 if (acpi_has_method(device->dev->handle, "_DDC")) 903 if (acpi_has_method(device->dev->handle, "_DDC"))
886 device->cap._DDC = 1; 904 device->cap._DDC = 1;
887
888 if (acpi_video_backlight_support()) {
889 struct backlight_properties props;
890 struct pci_dev *pdev;
891 acpi_handle acpi_parent;
892 struct device *parent = NULL;
893 int result;
894 static int count;
895 char *name;
896
897 result = acpi_video_init_brightness(device);
898 if (result)
899 return;
900 name = kasprintf(GFP_KERNEL, "acpi_video%d", count);
901 if (!name)
902 return;
903 count++;
904
905 acpi_get_parent(device->dev->handle, &acpi_parent);
906
907 pdev = acpi_get_pci_dev(acpi_parent);
908 if (pdev) {
909 parent = &pdev->dev;
910 pci_dev_put(pdev);
911 }
912
913 memset(&props, 0, sizeof(struct backlight_properties));
914 props.type = BACKLIGHT_FIRMWARE;
915 props.max_brightness = device->brightness->count - 3;
916 device->backlight = backlight_device_register(name,
917 parent,
918 device,
919 &acpi_backlight_ops,
920 &props);
921 kfree(name);
922 if (IS_ERR(device->backlight))
923 return;
924
925 /*
926 * Save current brightness level in case we have to restore it
927 * before acpi_video_device_lcd_set_level() is called next time.
928 */
929 device->backlight->props.brightness =
930 acpi_video_get_brightness(device->backlight);
931
932 device->cooling_dev = thermal_cooling_device_register("LCD",
933 device->dev, &video_cooling_ops);
934 if (IS_ERR(device->cooling_dev)) {
935 /*
936 * Set cooling_dev to NULL so we don't crash trying to
937 * free it.
938 * Also, why the hell we are returning early and
939 * not attempt to register video output if cooling
940 * device registration failed?
941 * -- dtor
942 */
943 device->cooling_dev = NULL;
944 return;
945 }
946
947 dev_info(&device->dev->dev, "registered as cooling_device%d\n",
948 device->cooling_dev->id);
949 result = sysfs_create_link(&device->dev->dev.kobj,
950 &device->cooling_dev->device.kobj,
951 "thermal_cooling");
952 if (result)
953 printk(KERN_ERR PREFIX "Create sysfs link\n");
954 result = sysfs_create_link(&device->cooling_dev->device.kobj,
955 &device->dev->dev.kobj, "device");
956 if (result)
957 printk(KERN_ERR PREFIX "Create sysfs link\n");
958
959 }
960} 905}
961 906
962/* 907/*
@@ -1143,13 +1088,6 @@ acpi_video_bus_get_one_device(struct acpi_device *device,
1143 acpi_video_device_bind(video, data); 1088 acpi_video_device_bind(video, data);
1144 acpi_video_device_find_cap(data); 1089 acpi_video_device_find_cap(data);
1145 1090
1146 status = acpi_install_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
1147 acpi_video_device_notify, data);
1148 if (ACPI_FAILURE(status))
1149 dev_err(&device->dev, "Error installing notify handler\n");
1150 else
1151 data->flags.notify = 1;
1152
1153 mutex_lock(&video->device_list_lock); 1091 mutex_lock(&video->device_list_lock);
1154 list_add_tail(&data->entry, &video->video_device_list); 1092 list_add_tail(&data->entry, &video->video_device_list);
1155 mutex_unlock(&video->device_list_lock); 1093 mutex_unlock(&video->device_list_lock);
@@ -1333,8 +1271,8 @@ acpi_video_switch_brightness(struct acpi_video_device *device, int event)
1333 unsigned long long level_current, level_next; 1271 unsigned long long level_current, level_next;
1334 int result = -EINVAL; 1272 int result = -EINVAL;
1335 1273
1336 /* no warning message if acpi_backlight=vendor is used */ 1274 /* no warning message if acpi_backlight=vendor or a quirk is used */
1337 if (!acpi_video_backlight_support()) 1275 if (!acpi_video_verify_backlight_support())
1338 return 0; 1276 return 0;
1339 1277
1340 if (!device->brightness) 1278 if (!device->brightness)
@@ -1454,64 +1392,6 @@ acpi_video_bus_get_devices(struct acpi_video_bus *video,
1454 return status; 1392 return status;
1455} 1393}
1456 1394
1457static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
1458{
1459 acpi_status status;
1460
1461 if (!device || !device->video)
1462 return -ENOENT;
1463
1464 if (device->flags.notify) {
1465 status = acpi_remove_notify_handler(device->dev->handle,
1466 ACPI_DEVICE_NOTIFY, acpi_video_device_notify);
1467 if (ACPI_FAILURE(status))
1468 dev_err(&device->dev->dev,
1469 "Can't remove video notify handler\n");
1470 }
1471
1472 if (device->backlight) {
1473 backlight_device_unregister(device->backlight);
1474 device->backlight = NULL;
1475 }
1476 if (device->cooling_dev) {
1477 sysfs_remove_link(&device->dev->dev.kobj,
1478 "thermal_cooling");
1479 sysfs_remove_link(&device->cooling_dev->device.kobj,
1480 "device");
1481 thermal_cooling_device_unregister(device->cooling_dev);
1482 device->cooling_dev = NULL;
1483 }
1484
1485 return 0;
1486}
1487
1488static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
1489{
1490 int status;
1491 struct acpi_video_device *dev, *next;
1492
1493 mutex_lock(&video->device_list_lock);
1494
1495 list_for_each_entry_safe(dev, next, &video->video_device_list, entry) {
1496
1497 status = acpi_video_bus_put_one_device(dev);
1498 if (ACPI_FAILURE(status))
1499 printk(KERN_WARNING PREFIX
1500 "hhuuhhuu bug in acpi video driver.\n");
1501
1502 if (dev->brightness) {
1503 kfree(dev->brightness->levels);
1504 kfree(dev->brightness);
1505 }
1506 list_del(&dev->entry);
1507 kfree(dev);
1508 }
1509
1510 mutex_unlock(&video->device_list_lock);
1511
1512 return 0;
1513}
1514
1515/* acpi_video interface */ 1395/* acpi_video interface */
1516 1396
1517/* 1397/*
@@ -1521,13 +1401,13 @@ static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
1521static int acpi_video_bus_start_devices(struct acpi_video_bus *video) 1401static int acpi_video_bus_start_devices(struct acpi_video_bus *video)
1522{ 1402{
1523 return acpi_video_bus_DOS(video, 0, 1403 return acpi_video_bus_DOS(video, 0,
1524 acpi_video_backlight_quirks() ? 1 : 0); 1404 acpi_osi_is_win8() ? 1 : 0);
1525} 1405}
1526 1406
1527static int acpi_video_bus_stop_devices(struct acpi_video_bus *video) 1407static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
1528{ 1408{
1529 return acpi_video_bus_DOS(video, 0, 1409 return acpi_video_bus_DOS(video, 0,
1530 acpi_video_backlight_quirks() ? 0 : 1); 1410 acpi_osi_is_win8() ? 0 : 1);
1531} 1411}
1532 1412
1533static void acpi_video_bus_notify(struct acpi_device *device, u32 event) 1413static void acpi_video_bus_notify(struct acpi_device *device, u32 event)
@@ -1536,7 +1416,7 @@ static void acpi_video_bus_notify(struct acpi_device *device, u32 event)
1536 struct input_dev *input; 1416 struct input_dev *input;
1537 int keycode = 0; 1417 int keycode = 0;
1538 1418
1539 if (!video) 1419 if (!video || !video->input)
1540 return; 1420 return;
1541 1421
1542 input = video->input; 1422 input = video->input;
@@ -1691,12 +1571,236 @@ acpi_video_bus_match(acpi_handle handle, u32 level, void *context,
1691 return AE_OK; 1571 return AE_OK;
1692} 1572}
1693 1573
1574static void acpi_video_dev_register_backlight(struct acpi_video_device *device)
1575{
1576 if (acpi_video_verify_backlight_support()) {
1577 struct backlight_properties props;
1578 struct pci_dev *pdev;
1579 acpi_handle acpi_parent;
1580 struct device *parent = NULL;
1581 int result;
1582 static int count;
1583 char *name;
1584
1585 result = acpi_video_init_brightness(device);
1586 if (result)
1587 return;
1588 name = kasprintf(GFP_KERNEL, "acpi_video%d", count);
1589 if (!name)
1590 return;
1591 count++;
1592
1593 acpi_get_parent(device->dev->handle, &acpi_parent);
1594
1595 pdev = acpi_get_pci_dev(acpi_parent);
1596 if (pdev) {
1597 parent = &pdev->dev;
1598 pci_dev_put(pdev);
1599 }
1600
1601 memset(&props, 0, sizeof(struct backlight_properties));
1602 props.type = BACKLIGHT_FIRMWARE;
1603 props.max_brightness = device->brightness->count - 3;
1604 device->backlight = backlight_device_register(name,
1605 parent,
1606 device,
1607 &acpi_backlight_ops,
1608 &props);
1609 kfree(name);
1610 if (IS_ERR(device->backlight))
1611 return;
1612
1613 /*
1614 * Save current brightness level in case we have to restore it
1615 * before acpi_video_device_lcd_set_level() is called next time.
1616 */
1617 device->backlight->props.brightness =
1618 acpi_video_get_brightness(device->backlight);
1619
1620 device->cooling_dev = thermal_cooling_device_register("LCD",
1621 device->dev, &video_cooling_ops);
1622 if (IS_ERR(device->cooling_dev)) {
1623 /*
1624 * Set cooling_dev to NULL so we don't crash trying to
1625 * free it.
1626 * Also, why the hell we are returning early and
1627 * not attempt to register video output if cooling
1628 * device registration failed?
1629 * -- dtor
1630 */
1631 device->cooling_dev = NULL;
1632 return;
1633 }
1634
1635 dev_info(&device->dev->dev, "registered as cooling_device%d\n",
1636 device->cooling_dev->id);
1637 result = sysfs_create_link(&device->dev->dev.kobj,
1638 &device->cooling_dev->device.kobj,
1639 "thermal_cooling");
1640 if (result)
1641 printk(KERN_ERR PREFIX "Create sysfs link\n");
1642 result = sysfs_create_link(&device->cooling_dev->device.kobj,
1643 &device->dev->dev.kobj, "device");
1644 if (result)
1645 printk(KERN_ERR PREFIX "Create sysfs link\n");
1646 }
1647}
1648
1649static int acpi_video_bus_register_backlight(struct acpi_video_bus *video)
1650{
1651 struct acpi_video_device *dev;
1652
1653 mutex_lock(&video->device_list_lock);
1654 list_for_each_entry(dev, &video->video_device_list, entry)
1655 acpi_video_dev_register_backlight(dev);
1656 mutex_unlock(&video->device_list_lock);
1657
1658 video->pm_nb.notifier_call = acpi_video_resume;
1659 video->pm_nb.priority = 0;
1660 return register_pm_notifier(&video->pm_nb);
1661}
1662
1663static void acpi_video_dev_unregister_backlight(struct acpi_video_device *device)
1664{
1665 if (device->backlight) {
1666 backlight_device_unregister(device->backlight);
1667 device->backlight = NULL;
1668 }
1669 if (device->brightness) {
1670 kfree(device->brightness->levels);
1671 kfree(device->brightness);
1672 device->brightness = NULL;
1673 }
1674 if (device->cooling_dev) {
1675 sysfs_remove_link(&device->dev->dev.kobj, "thermal_cooling");
1676 sysfs_remove_link(&device->cooling_dev->device.kobj, "device");
1677 thermal_cooling_device_unregister(device->cooling_dev);
1678 device->cooling_dev = NULL;
1679 }
1680}
1681
1682static int acpi_video_bus_unregister_backlight(struct acpi_video_bus *video)
1683{
1684 struct acpi_video_device *dev;
1685 int error = unregister_pm_notifier(&video->pm_nb);
1686
1687 mutex_lock(&video->device_list_lock);
1688 list_for_each_entry(dev, &video->video_device_list, entry)
1689 acpi_video_dev_unregister_backlight(dev);
1690 mutex_unlock(&video->device_list_lock);
1691
1692 return error;
1693}
1694
1695static void acpi_video_dev_add_notify_handler(struct acpi_video_device *device)
1696{
1697 acpi_status status;
1698 struct acpi_device *adev = device->dev;
1699
1700 status = acpi_install_notify_handler(adev->handle, ACPI_DEVICE_NOTIFY,
1701 acpi_video_device_notify, device);
1702 if (ACPI_FAILURE(status))
1703 dev_err(&adev->dev, "Error installing notify handler\n");
1704 else
1705 device->flags.notify = 1;
1706}
1707
1708static int acpi_video_bus_add_notify_handler(struct acpi_video_bus *video)
1709{
1710 struct input_dev *input;
1711 struct acpi_video_device *dev;
1712 int error;
1713
1714 video->input = input = input_allocate_device();
1715 if (!input) {
1716 error = -ENOMEM;
1717 goto out;
1718 }
1719
1720 error = acpi_video_bus_start_devices(video);
1721 if (error)
1722 goto err_free_input;
1723
1724 snprintf(video->phys, sizeof(video->phys),
1725 "%s/video/input0", acpi_device_hid(video->device));
1726
1727 input->name = acpi_device_name(video->device);
1728 input->phys = video->phys;
1729 input->id.bustype = BUS_HOST;
1730 input->id.product = 0x06;
1731 input->dev.parent = &video->device->dev;
1732 input->evbit[0] = BIT(EV_KEY);
1733 set_bit(KEY_SWITCHVIDEOMODE, input->keybit);
1734 set_bit(KEY_VIDEO_NEXT, input->keybit);
1735 set_bit(KEY_VIDEO_PREV, input->keybit);
1736 set_bit(KEY_BRIGHTNESS_CYCLE, input->keybit);
1737 set_bit(KEY_BRIGHTNESSUP, input->keybit);
1738 set_bit(KEY_BRIGHTNESSDOWN, input->keybit);
1739 set_bit(KEY_BRIGHTNESS_ZERO, input->keybit);
1740 set_bit(KEY_DISPLAY_OFF, input->keybit);
1741
1742 error = input_register_device(input);
1743 if (error)
1744 goto err_stop_dev;
1745
1746 mutex_lock(&video->device_list_lock);
1747 list_for_each_entry(dev, &video->video_device_list, entry)
1748 acpi_video_dev_add_notify_handler(dev);
1749 mutex_unlock(&video->device_list_lock);
1750
1751 return 0;
1752
1753err_stop_dev:
1754 acpi_video_bus_stop_devices(video);
1755err_free_input:
1756 input_free_device(input);
1757 video->input = NULL;
1758out:
1759 return error;
1760}
1761
1762static void acpi_video_dev_remove_notify_handler(struct acpi_video_device *dev)
1763{
1764 if (dev->flags.notify) {
1765 acpi_remove_notify_handler(dev->dev->handle, ACPI_DEVICE_NOTIFY,
1766 acpi_video_device_notify);
1767 dev->flags.notify = 0;
1768 }
1769}
1770
1771static void acpi_video_bus_remove_notify_handler(struct acpi_video_bus *video)
1772{
1773 struct acpi_video_device *dev;
1774
1775 mutex_lock(&video->device_list_lock);
1776 list_for_each_entry(dev, &video->video_device_list, entry)
1777 acpi_video_dev_remove_notify_handler(dev);
1778 mutex_unlock(&video->device_list_lock);
1779
1780 acpi_video_bus_stop_devices(video);
1781 input_unregister_device(video->input);
1782 video->input = NULL;
1783}
1784
1785static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
1786{
1787 struct acpi_video_device *dev, *next;
1788
1789 mutex_lock(&video->device_list_lock);
1790 list_for_each_entry_safe(dev, next, &video->video_device_list, entry) {
1791 list_del(&dev->entry);
1792 kfree(dev);
1793 }
1794 mutex_unlock(&video->device_list_lock);
1795
1796 return 0;
1797}
1798
1694static int instance; 1799static int instance;
1695 1800
1696static int acpi_video_bus_add(struct acpi_device *device) 1801static int acpi_video_bus_add(struct acpi_device *device)
1697{ 1802{
1698 struct acpi_video_bus *video; 1803 struct acpi_video_bus *video;
1699 struct input_dev *input;
1700 int error; 1804 int error;
1701 acpi_status status; 1805 acpi_status status;
1702 1806
@@ -1748,62 +1852,24 @@ static int acpi_video_bus_add(struct acpi_device *device)
1748 if (error) 1852 if (error)
1749 goto err_put_video; 1853 goto err_put_video;
1750 1854
1751 video->input = input = input_allocate_device();
1752 if (!input) {
1753 error = -ENOMEM;
1754 goto err_put_video;
1755 }
1756
1757 error = acpi_video_bus_start_devices(video);
1758 if (error)
1759 goto err_free_input_dev;
1760
1761 snprintf(video->phys, sizeof(video->phys),
1762 "%s/video/input0", acpi_device_hid(video->device));
1763
1764 input->name = acpi_device_name(video->device);
1765 input->phys = video->phys;
1766 input->id.bustype = BUS_HOST;
1767 input->id.product = 0x06;
1768 input->dev.parent = &device->dev;
1769 input->evbit[0] = BIT(EV_KEY);
1770 set_bit(KEY_SWITCHVIDEOMODE, input->keybit);
1771 set_bit(KEY_VIDEO_NEXT, input->keybit);
1772 set_bit(KEY_VIDEO_PREV, input->keybit);
1773 set_bit(KEY_BRIGHTNESS_CYCLE, input->keybit);
1774 set_bit(KEY_BRIGHTNESSUP, input->keybit);
1775 set_bit(KEY_BRIGHTNESSDOWN, input->keybit);
1776 set_bit(KEY_BRIGHTNESS_ZERO, input->keybit);
1777 set_bit(KEY_DISPLAY_OFF, input->keybit);
1778
1779 printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n", 1855 printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n",
1780 ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device), 1856 ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
1781 video->flags.multihead ? "yes" : "no", 1857 video->flags.multihead ? "yes" : "no",
1782 video->flags.rom ? "yes" : "no", 1858 video->flags.rom ? "yes" : "no",
1783 video->flags.post ? "yes" : "no"); 1859 video->flags.post ? "yes" : "no");
1860 mutex_lock(&video_list_lock);
1861 list_add_tail(&video->entry, &video_bus_head);
1862 mutex_unlock(&video_list_lock);
1784 1863
1785 video->pm_nb.notifier_call = acpi_video_resume; 1864 acpi_video_bus_register_backlight(video);
1786 video->pm_nb.priority = 0; 1865 acpi_video_bus_add_notify_handler(video);
1787 error = register_pm_notifier(&video->pm_nb);
1788 if (error)
1789 goto err_stop_video;
1790
1791 error = input_register_device(input);
1792 if (error)
1793 goto err_unregister_pm_notifier;
1794 1866
1795 return 0; 1867 return 0;
1796 1868
1797 err_unregister_pm_notifier: 1869err_put_video:
1798 unregister_pm_notifier(&video->pm_nb);
1799 err_stop_video:
1800 acpi_video_bus_stop_devices(video);
1801 err_free_input_dev:
1802 input_free_device(input);
1803 err_put_video:
1804 acpi_video_bus_put_devices(video); 1870 acpi_video_bus_put_devices(video);
1805 kfree(video->attached_array); 1871 kfree(video->attached_array);
1806 err_free_video: 1872err_free_video:
1807 kfree(video); 1873 kfree(video);
1808 device->driver_data = NULL; 1874 device->driver_data = NULL;
1809 1875
@@ -1820,12 +1886,14 @@ static int acpi_video_bus_remove(struct acpi_device *device)
1820 1886
1821 video = acpi_driver_data(device); 1887 video = acpi_driver_data(device);
1822 1888
1823 unregister_pm_notifier(&video->pm_nb); 1889 acpi_video_bus_remove_notify_handler(video);
1824 1890 acpi_video_bus_unregister_backlight(video);
1825 acpi_video_bus_stop_devices(video);
1826 acpi_video_bus_put_devices(video); 1891 acpi_video_bus_put_devices(video);
1827 1892
1828 input_unregister_device(video->input); 1893 mutex_lock(&video_list_lock);
1894 list_del(&video->entry);
1895 mutex_unlock(&video_list_lock);
1896
1829 kfree(video->attached_array); 1897 kfree(video->attached_array);
1830 kfree(video); 1898 kfree(video);
1831 1899
@@ -1874,6 +1942,9 @@ int acpi_video_register(void)
1874 return 0; 1942 return 0;
1875 } 1943 }
1876 1944
1945 mutex_init(&video_list_lock);
1946 INIT_LIST_HEAD(&video_bus_head);
1947
1877 result = acpi_bus_register_driver(&acpi_video_bus); 1948 result = acpi_bus_register_driver(&acpi_video_bus);
1878 if (result < 0) 1949 if (result < 0)
1879 return -ENODEV; 1950 return -ENODEV;
diff --git a/drivers/acpi/video_detect.c b/drivers/acpi/video_detect.c
index 940edbf2fe8f..84875fd4c74f 100644
--- a/drivers/acpi/video_detect.c
+++ b/drivers/acpi/video_detect.c
@@ -168,6 +168,14 @@ static struct dmi_system_id video_detect_dmi_table[] = {
168 DMI_MATCH(DMI_PRODUCT_NAME, "UL30A"), 168 DMI_MATCH(DMI_PRODUCT_NAME, "UL30A"),
169 }, 169 },
170 }, 170 },
171 {
172 .callback = video_detect_force_vendor,
173 .ident = "Lenovo Yoga 13",
174 .matches = {
175 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
176 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo IdeaPad Yoga 13"),
177 },
178 },
171 { }, 179 { },
172}; 180};
173 181
@@ -233,11 +241,11 @@ static void acpi_video_caps_check(void)
233 acpi_video_get_capabilities(NULL); 241 acpi_video_get_capabilities(NULL);
234} 242}
235 243
236bool acpi_video_backlight_quirks(void) 244bool acpi_osi_is_win8(void)
237{ 245{
238 return acpi_gbl_osi_data >= ACPI_OSI_WIN_8; 246 return acpi_gbl_osi_data >= ACPI_OSI_WIN_8;
239} 247}
240EXPORT_SYMBOL(acpi_video_backlight_quirks); 248EXPORT_SYMBOL(acpi_osi_is_win8);
241 249
242/* Promote the vendor interface instead of the generic video module. 250/* Promote the vendor interface instead of the generic video module.
243 * This function allow DMI blacklists to be implemented by externals 251 * This function allow DMI blacklists to be implemented by externals