aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/acpi')
-rw-r--r--drivers/acpi/Kconfig156
-rw-r--r--drivers/acpi/Makefile52
-rw-r--r--drivers/acpi/ac.c1
-rw-r--r--drivers/acpi/acpica/Makefile4
-rw-r--r--drivers/acpi/acpica/acglobal.h11
-rw-r--r--drivers/acpi/acpica/achware.h12
-rw-r--r--drivers/acpi/acpica/aclocal.h60
-rw-r--r--drivers/acpi/acpica/acmacros.h4
-rw-r--r--drivers/acpi/acpica/acobject.h1
-rw-r--r--drivers/acpi/acpica/acpredef.h41
-rw-r--r--drivers/acpi/acpica/actables.h9
-rw-r--r--drivers/acpi/acpica/acutils.h15
-rw-r--r--drivers/acpi/acpica/dsinit.c16
-rw-r--r--drivers/acpi/acpica/dsmthdat.c2
-rw-r--r--drivers/acpi/acpica/dsobject.c6
-rw-r--r--drivers/acpi/acpica/dsopcode.c32
-rw-r--r--drivers/acpi/acpica/dsutils.c2
-rw-r--r--drivers/acpi/acpica/dswexec.c5
-rw-r--r--drivers/acpi/acpica/evevent.c18
-rw-r--r--drivers/acpi/acpica/evgpe.c7
-rw-r--r--drivers/acpi/acpica/evgpeblk.c70
-rw-r--r--drivers/acpi/acpica/evmisc.c16
-rw-r--r--drivers/acpi/acpica/evregion.c5
-rw-r--r--drivers/acpi/acpica/evrgnini.c22
-rw-r--r--drivers/acpi/acpica/evxface.c3
-rw-r--r--drivers/acpi/acpica/evxfevnt.c24
-rw-r--r--drivers/acpi/acpica/evxfregn.c3
-rw-r--r--drivers/acpi/acpica/exconfig.c17
-rw-r--r--drivers/acpi/acpica/exconvrt.c11
-rw-r--r--drivers/acpi/acpica/exdump.c59
-rw-r--r--drivers/acpi/acpica/exfield.c29
-rw-r--r--drivers/acpi/acpica/exfldio.c14
-rw-r--r--drivers/acpi/acpica/exmisc.c14
-rw-r--r--drivers/acpi/acpica/exoparg1.c13
-rw-r--r--drivers/acpi/acpica/exoparg2.c2
-rw-r--r--drivers/acpi/acpica/exoparg3.c7
-rw-r--r--drivers/acpi/acpica/exprep.c2
-rw-r--r--drivers/acpi/acpica/exregion.c4
-rw-r--r--drivers/acpi/acpica/exresnte.c8
-rw-r--r--drivers/acpi/acpica/exresolv.c9
-rw-r--r--drivers/acpi/acpica/exresop.c23
-rw-r--r--drivers/acpi/acpica/exstore.c18
-rw-r--r--drivers/acpi/acpica/exstoren.c29
-rw-r--r--drivers/acpi/acpica/exutils.c2
-rw-r--r--drivers/acpi/acpica/hwacpi.c9
-rw-r--r--drivers/acpi/acpica/hwgpe.c21
-rw-r--r--drivers/acpi/acpica/hwregs.c322
-rw-r--r--drivers/acpi/acpica/hwsleep.c173
-rw-r--r--drivers/acpi/acpica/hwvalid.c315
-rw-r--r--drivers/acpi/acpica/hwxface.c279
-rw-r--r--drivers/acpi/acpica/nsaccess.c54
-rw-r--r--drivers/acpi/acpica/nsalloc.c24
-rw-r--r--drivers/acpi/acpica/nsdump.c24
-rw-r--r--drivers/acpi/acpica/nseval.c2
-rw-r--r--drivers/acpi/acpica/nsinit.c19
-rw-r--r--drivers/acpi/acpica/nsload.c4
-rw-r--r--drivers/acpi/acpica/nsobject.c18
-rw-r--r--drivers/acpi/acpica/nsparse.c10
-rw-r--r--drivers/acpi/acpica/nspredef.c38
-rw-r--r--drivers/acpi/acpica/nssearch.c14
-rw-r--r--drivers/acpi/acpica/nsutils.c27
-rw-r--r--drivers/acpi/acpica/nswalk.c12
-rw-r--r--drivers/acpi/acpica/nsxfeval.c39
-rw-r--r--drivers/acpi/acpica/rscalc.c7
-rw-r--r--drivers/acpi/acpica/rscreate.c40
-rw-r--r--drivers/acpi/acpica/tbfadt.c363
-rw-r--r--drivers/acpi/acpica/tbinstal.c82
-rw-r--r--drivers/acpi/acpica/tbutils.c113
-rw-r--r--drivers/acpi/acpica/tbxface.c88
-rw-r--r--drivers/acpi/acpica/tbxfroot.c4
-rw-r--r--drivers/acpi/acpica/utcopy.c30
-rw-r--r--drivers/acpi/acpica/utdelete.c6
-rw-r--r--drivers/acpi/acpica/uteval.c93
-rw-r--r--drivers/acpi/acpica/utglobal.c17
-rw-r--r--drivers/acpi/acpica/utlock.c175
-rw-r--r--drivers/acpi/acpica/utmisc.c3
-rw-r--r--drivers/acpi/acpica/utmutex.c23
-rw-r--r--drivers/acpi/acpica/utobject.c11
-rw-r--r--drivers/acpi/battery.c55
-rw-r--r--drivers/acpi/bus.c24
-rw-r--r--drivers/acpi/button.c220
-rw-r--r--drivers/acpi/container.c5
-rw-r--r--drivers/acpi/debug.c19
-rw-r--r--drivers/acpi/dock.c19
-rw-r--r--drivers/acpi/ec.c116
-rw-r--r--drivers/acpi/event.c6
-rw-r--r--drivers/acpi/fan.c22
-rw-r--r--drivers/acpi/glue.c14
-rw-r--r--drivers/acpi/internal.h43
-rw-r--r--drivers/acpi/numa.c48
-rw-r--r--drivers/acpi/osl.c27
-rw-r--r--drivers/acpi/pci_irq.c18
-rw-r--r--drivers/acpi/pci_link.c149
-rw-r--r--drivers/acpi/pci_root.c180
-rw-r--r--drivers/acpi/pci_slot.c5
-rw-r--r--drivers/acpi/power.c12
-rw-r--r--drivers/acpi/proc.c20
-rw-r--r--drivers/acpi/processor_core.c47
-rw-r--r--drivers/acpi/processor_idle.c812
-rw-r--r--drivers/acpi/processor_perflib.c155
-rw-r--r--drivers/acpi/processor_thermal.c22
-rw-r--r--drivers/acpi/processor_throttling.c8
-rw-r--r--drivers/acpi/sbs.c42
-rw-r--r--drivers/acpi/scan.c125
-rw-r--r--drivers/acpi/sleep.c (renamed from drivers/acpi/main.c)117
-rw-r--r--drivers/acpi/sleep.h3
-rw-r--r--drivers/acpi/system.c75
-rw-r--r--drivers/acpi/tables.c57
-rw-r--r--drivers/acpi/thermal.c617
-rw-r--r--drivers/acpi/video.c388
-rw-r--r--drivers/acpi/video_detect.c3
-rw-r--r--drivers/acpi/wakeup.c39
112 files changed, 3438 insertions, 3391 deletions
diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig
index d7f9839ba264..431f8b439553 100644
--- a/drivers/acpi/Kconfig
+++ b/drivers/acpi/Kconfig
@@ -9,10 +9,11 @@ menuconfig ACPI
9 depends on PCI 9 depends on PCI
10 depends on PM 10 depends on PM
11 select PNP 11 select PNP
12 select CPU_IDLE
12 default y 13 default y
13 ---help--- 14 help
14 Advanced Configuration and Power Interface (ACPI) support for 15 Advanced Configuration and Power Interface (ACPI) support for
15 Linux requires an ACPI compliant platform (hardware/firmware), 16 Linux requires an ACPI-compliant platform (hardware/firmware),
16 and assumes the presence of OS-directed configuration and power 17 and assumes the presence of OS-directed configuration and power
17 management (OSPM) software. This option will enlarge your 18 management (OSPM) software. This option will enlarge your
18 kernel by about 70K. 19 kernel by about 70K.
@@ -22,20 +23,19 @@ menuconfig ACPI
22 the Plug-and-Play BIOS specification (PnP BIOS), the 23 the Plug-and-Play BIOS specification (PnP BIOS), the
23 MultiProcessor Specification (MPS), and the Advanced Power 24 MultiProcessor Specification (MPS), and the Advanced Power
24 Management (APM) specification. If both ACPI and APM support 25 Management (APM) specification. If both ACPI and APM support
25 are configured, whichever is loaded first shall be used. 26 are configured, ACPI is used.
26 27
27 The ACPI SourceForge project contains the latest source code, 28 The project home page for the Linux ACPI subsystem is here:
28 documentation, tools, mailing list subscription, and other 29 <http://www.lesswatts.org/projects/acpi/>
29 information. This project is available at:
30 <http://sourceforge.net/projects/acpi>
31 30
32 Linux support for ACPI is based on Intel Corporation's ACPI 31 Linux support for ACPI is based on Intel Corporation's ACPI
33 Component Architecture (ACPI CA). For more information see: 32 Component Architecture (ACPI CA). For more information on the
34 <http://developer.intel.com/technology/iapc/acpi> 33 ACPI CA, see:
34 <http://acpica.org/>
35 35
36 ACPI is an open industry specification co-developed by Compaq, 36 ACPI is an open industry specification co-developed by
37 Intel, Microsoft, Phoenix, and Toshiba. The specification is 37 Hewlett-Packard, Intel, Microsoft, Phoenix, and Toshiba.
38 available at: 38 The specification is available at:
39 <http://www.acpi.info> 39 <http://www.acpi.info>
40 40
41if ACPI 41if ACPI
@@ -48,14 +48,14 @@ config ACPI_SLEEP
48config ACPI_PROCFS 48config ACPI_PROCFS
49 bool "Deprecated /proc/acpi files" 49 bool "Deprecated /proc/acpi files"
50 depends on PROC_FS 50 depends on PROC_FS
51 ---help--- 51 help
52 For backwards compatibility, this option allows 52 For backwards compatibility, this option allows
53 deprecated /proc/acpi/ files to exist, even when 53 deprecated /proc/acpi/ files to exist, even when
54 they have been replaced by functions in /sys. 54 they have been replaced by functions in /sys.
55 The deprecated files (and their replacements) include: 55 The deprecated files (and their replacements) include:
56 56
57 /proc/acpi/sleep (/sys/power/state) 57 /proc/acpi/sleep (/sys/power/state)
58 /proc/acpi/info (/sys/modules/acpi/parameters/acpica_version) 58 /proc/acpi/info (/sys/module/acpi/parameters/acpica_version)
59 /proc/acpi/dsdt (/sys/firmware/acpi/tables/DSDT) 59 /proc/acpi/dsdt (/sys/firmware/acpi/tables/DSDT)
60 /proc/acpi/fadt (/sys/firmware/acpi/tables/FACP) 60 /proc/acpi/fadt (/sys/firmware/acpi/tables/FACP)
61 /proc/acpi/debug_layer (/sys/module/acpi/parameters/debug_layer) 61 /proc/acpi/debug_layer (/sys/module/acpi/parameters/debug_layer)
@@ -65,11 +65,12 @@ config ACPI_PROCFS
65 and functions which do not yet exist in /sys. 65 and functions which do not yet exist in /sys.
66 66
67 Say N to delete /proc/acpi/ files that have moved to /sys/ 67 Say N to delete /proc/acpi/ files that have moved to /sys/
68
68config ACPI_PROCFS_POWER 69config ACPI_PROCFS_POWER
69 bool "Deprecated power /proc/acpi directories" 70 bool "Deprecated power /proc/acpi directories"
70 depends on PROC_FS 71 depends on PROC_FS
71 default y 72 default y
72 ---help--- 73 help
73 For backwards compatibility, this option allows 74 For backwards compatibility, this option allows
74 deprecated power /proc/acpi/ directories to exist, even when 75 deprecated power /proc/acpi/ directories to exist, even when
75 they have been replaced by functions in /sys. 76 they have been replaced by functions in /sys.
@@ -85,19 +86,19 @@ config ACPI_SYSFS_POWER
85 bool "Future power /sys interface" 86 bool "Future power /sys interface"
86 select POWER_SUPPLY 87 select POWER_SUPPLY
87 default y 88 default y
88 ---help--- 89 help
89 Say N to disable power /sys interface 90 Say N to disable power /sys interface
90 91
91config ACPI_PROC_EVENT 92config ACPI_PROC_EVENT
92 bool "Deprecated /proc/acpi/event support" 93 bool "Deprecated /proc/acpi/event support"
93 depends on PROC_FS 94 depends on PROC_FS
94 default y 95 default y
95 ---help--- 96 help
96 A user-space daemon, acpi, typically read /proc/acpi/event 97 A user-space daemon, acpid, typically reads /proc/acpi/event
97 and handled all ACPI sub-system generated events. 98 and handles all ACPI-generated events.
98 99
99 These events are now delivered to user-space via 100 These events are now delivered to user-space either
100 either the input layer, or as netlink events. 101 via the input layer or as netlink events.
101 102
102 This build option enables the old code for legacy 103 This build option enables the old code for legacy
103 user-space implementation. After some time, this will 104 user-space implementation. After some time, this will
@@ -111,10 +112,13 @@ config ACPI_AC
111 depends on X86 112 depends on X86
112 default y 113 default y
113 help 114 help
114 This driver adds support for the AC Adapter object, which indicates 115 This driver supports the AC Adapter object, which indicates
115 whether a system is on AC, or not. If you have a system that can 116 whether a system is on AC or not. If you have a system that can
116 switch between A/C and battery, say Y. 117 switch between A/C and battery, say Y.
117 118
119 To compile this driver as a module, choose M here:
120 the module will be called ac.
121
118config ACPI_BATTERY 122config ACPI_BATTERY
119 tristate "Battery" 123 tristate "Battery"
120 depends on X86 124 depends on X86
@@ -124,15 +128,21 @@ config ACPI_BATTERY
124 /proc/acpi/battery. If you have a mobile system with a battery, 128 /proc/acpi/battery. If you have a mobile system with a battery,
125 say Y. 129 say Y.
126 130
131 To compile this driver as a module, choose M here:
132 the module will be called battery.
133
127config ACPI_BUTTON 134config ACPI_BUTTON
128 tristate "Button" 135 tristate "Button"
129 depends on INPUT 136 depends on INPUT
130 default y 137 default y
131 help 138 help
132 This driver handles events on the power, sleep and lid buttons. 139 This driver handles events on the power, sleep, and lid buttons.
133 A daemon reads /proc/acpi/event and perform user-defined actions 140 A daemon reads /proc/acpi/event and perform user-defined actions
134 such as shutting down the system. This is necessary for 141 such as shutting down the system. This is necessary for
135 software controlled poweroff. 142 software-controlled poweroff.
143
144 To compile this driver as a module, choose M here:
145 the module will be called button.
136 146
137config ACPI_VIDEO 147config ACPI_VIDEO
138 tristate "Video" 148 tristate "Video"
@@ -140,38 +150,45 @@ config ACPI_VIDEO
140 depends on INPUT 150 depends on INPUT
141 select THERMAL 151 select THERMAL
142 help 152 help
143 This driver implement the ACPI Extensions For Display Adapters 153 This driver implements the ACPI Extensions For Display Adapters
144 for integrated graphics devices on motherboard, as specified in 154 for integrated graphics devices on motherboard, as specified in
145 ACPI 2.0 Specification, Appendix B, allowing to perform some basic 155 ACPI 2.0 Specification, Appendix B. This supports basic operations
146 control like defining the video POST device, retrieving EDID information 156 such as defining the video POST device, retrieving EDID information,
147 or to setup a video output, etc. 157 and setting up a video output.
148 Note that this is an ref. implementation only. It may or may not work 158
149 for your integrated video device. 159 To compile this driver as a module, choose M here:
160 the module will be called video.
150 161
151config ACPI_FAN 162config ACPI_FAN
152 tristate "Fan" 163 tristate "Fan"
153 select THERMAL 164 select THERMAL
154 default y 165 default y
155 help 166 help
156 This driver adds support for ACPI fan devices, allowing user-mode 167 This driver supports ACPI fan devices, allowing user-mode
157 applications to perform basic fan control (on, off, status). 168 applications to perform basic fan control (on, off, status).
158 169
170 To compile this driver as a module, choose M here:
171 the module will be called fan.
172
159config ACPI_DOCK 173config ACPI_DOCK
160 bool "Dock" 174 bool "Dock"
161 depends on EXPERIMENTAL 175 depends on EXPERIMENTAL
162 help 176 help
163 This driver adds support for ACPI controlled docking stations and removable 177 This driver supports ACPI-controlled docking stations and removable
164 drive bays such as the IBM ultrabay or the Dell Module Bay. 178 drive bays such as the IBM Ultrabay and the Dell Module Bay.
165 179
166config ACPI_PROCESSOR 180config ACPI_PROCESSOR
167 tristate "Processor" 181 tristate "Processor"
168 select THERMAL 182 select THERMAL
169 default y 183 default y
170 help 184 help
171 This driver installs ACPI as the idle handler for Linux, and uses 185 This driver installs ACPI as the idle handler for Linux and uses
172 ACPI C2 and C3 processor states to save power, on systems that 186 ACPI C2 and C3 processor states to save power on systems that
173 support it. It is required by several flavors of cpufreq 187 support it. It is required by several flavors of cpufreq
174 Performance-state drivers. 188 performance-state drivers.
189
190 To compile this driver as a module, choose M here:
191 the module will be called processor.
175 192
176config ACPI_HOTPLUG_CPU 193config ACPI_HOTPLUG_CPU
177 bool 194 bool
@@ -185,11 +202,14 @@ config ACPI_THERMAL
185 select THERMAL 202 select THERMAL
186 default y 203 default y
187 help 204 help
188 This driver adds support for ACPI thermal zones. Most mobile and 205 This driver supports ACPI thermal zones. Most mobile and
189 some desktop systems support ACPI thermal zones. It is HIGHLY 206 some desktop systems support ACPI thermal zones. It is HIGHLY
190 recommended that this option be enabled, as your processor(s) 207 recommended that this option be enabled, as your processor(s)
191 may be damaged without it. 208 may be damaged without it.
192 209
210 To compile this driver as a module, choose M here:
211 the module will be called thermal.
212
193config ACPI_NUMA 213config ACPI_NUMA
194 bool "NUMA support" 214 bool "NUMA support"
195 depends on NUMA 215 depends on NUMA
@@ -217,7 +237,7 @@ config ACPI_BLACKLIST_YEAR
217 int "Disable ACPI for systems before Jan 1st this year" if X86_32 237 int "Disable ACPI for systems before Jan 1st this year" if X86_32
218 default 0 238 default 0
219 help 239 help
220 enter a 4-digit year, eg. 2001 to disable ACPI by default 240 Enter a 4-digit year, e.g., 2001, to disable ACPI by default
221 on platforms with DMI BIOS date before January 1st that year. 241 on platforms with DMI BIOS date before January 1st that year.
222 "acpi=force" can be used to override this mechanism. 242 "acpi=force" can be used to override this mechanism.
223 243
@@ -248,17 +268,13 @@ config ACPI_PCI_SLOT
248 tristate "PCI slot detection driver" 268 tristate "PCI slot detection driver"
249 default n 269 default n
250 help 270 help
251 This driver will attempt to discover all PCI slots in your system, 271 This driver creates entries in /sys/bus/pci/slots/ for all PCI
252 and creates entries in /sys/bus/pci/slots/. This feature can 272 slots in the system. This can help correlate PCI bus addresses,
253 help you correlate PCI bus addresses with the physical geography 273 i.e., segment/bus/device/function tuples, with physical slots in
254 of your slots. If you are unsure, say N. 274 the system. If you are unsure, say N.
255 275
256config ACPI_SYSTEM 276 To compile this driver as a module, choose M here:
257 bool 277 the module will be called pci_slot.
258 default y
259 help
260 This driver will enable your system to shut down using ACPI, and
261 dump your ACPI DSDT table using /proc/acpi/dsdt.
262 278
263config X86_PM_TIMER 279config X86_PM_TIMER
264 bool "Power Management Timer Support" if EMBEDDED 280 bool "Power Management Timer Support" if EMBEDDED
@@ -277,43 +293,43 @@ config X86_PM_TIMER
277 systems require this timer. 293 systems require this timer.
278 294
279config ACPI_CONTAINER 295config ACPI_CONTAINER
280 tristate "ACPI0004,PNP0A05 and PNP0A06 Container Driver (EXPERIMENTAL)" 296 tristate "Container and Module Devices (EXPERIMENTAL)"
281 depends on EXPERIMENTAL 297 depends on EXPERIMENTAL
282 default (ACPI_HOTPLUG_MEMORY || ACPI_HOTPLUG_CPU || ACPI_HOTPLUG_IO) 298 default (ACPI_HOTPLUG_MEMORY || ACPI_HOTPLUG_CPU || ACPI_HOTPLUG_IO)
283 ---help--- 299 help
284 This allows _physical_ insertion and removal of CPUs and memory. 300 This driver supports ACPI Container and Module devices (IDs
285 This can be useful, for example, on NUMA machines that support 301 ACPI0004, PNP0A05, and PNP0A06).
286 ACPI based physical hotplug of nodes, or non-NUMA machines that
287 support physical cpu/memory hot-plug.
288 302
289 If one selects "m", this driver can be loaded with 303 This helps support hotplug of nodes, CPUs, and memory.
290 "modprobe acpi_container". 304
305 To compile this driver as a module, choose M here:
306 the module will be called container.
291 307
292config ACPI_HOTPLUG_MEMORY 308config ACPI_HOTPLUG_MEMORY
293 tristate "Memory Hotplug" 309 tristate "Memory Hotplug"
294 depends on MEMORY_HOTPLUG 310 depends on MEMORY_HOTPLUG
295 default n 311 default n
296 help 312 help
297 This driver adds supports for ACPI Memory Hotplug. This driver 313 This driver supports ACPI memory hotplug. The driver
298 provides support for fielding notifications on ACPI memory 314 fields notifications on ACPI memory devices (PNP0C80),
299 devices (PNP0C80) which represent memory ranges that may be 315 which represent memory ranges that may be onlined or
300 onlined or offlined during runtime. 316 offlined during runtime.
301 317
302 Enabling this driver assumes that your platform hardware 318 If your hardware and firmware do not support adding or
303 and firmware have support for hot-plugging physical memory. If 319 removing memory devices at runtime, you need not enable
304 your system does not support physically adding or ripping out 320 this driver.
305 memory DIMMs at some platform defined granularity (individually
306 or as a bank) at runtime, then you need not enable this driver.
307 321
308 If one selects "m," this driver can be loaded using the following 322 To compile this driver as a module, choose M here:
309 command: 323 the module will be called acpi_memhotplug.
310 $>modprobe acpi_memhotplug
311 324
312config ACPI_SBS 325config ACPI_SBS
313 tristate "Smart Battery System" 326 tristate "Smart Battery System"
314 depends on X86 327 depends on X86
315 help 328 help
316 This driver adds support for the Smart Battery System, another 329 This driver supports the Smart Battery System, another
317 type of access to battery information, found on some laptops. 330 type of access to battery information, found on some laptops.
318 331
332 To compile this driver as a module, choose M here:
333 the modules will be called sbs and sbshc.
334
319endif # ACPI 335endif # ACPI
diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index d80f4cc2e0da..03a985be3fe3 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -14,48 +14,50 @@ obj-$(CONFIG_X86) += blacklist.o
14# 14#
15# ACPI Core Subsystem (Interpreter) 15# ACPI Core Subsystem (Interpreter)
16# 16#
17obj-y += osl.o utils.o reboot.o\ 17obj-y += acpi.o \
18 acpica/ 18 acpica/
19 19
20# All the builtin files are in the "acpi." module_param namespace.
21acpi-y += osl.o utils.o reboot.o
22
20# sleep related files 23# sleep related files
21obj-y += wakeup.o 24acpi-y += wakeup.o
22obj-y += main.o 25acpi-y += sleep.o
23obj-$(CONFIG_ACPI_SLEEP) += proc.o 26acpi-$(CONFIG_ACPI_SLEEP) += proc.o
24 27
25 28
26# 29#
27# ACPI Bus and Device Drivers 30# ACPI Bus and Device Drivers
28# 31#
29processor-objs += processor_core.o processor_throttling.o \ 32acpi-y += bus.o glue.o
30 processor_idle.o processor_thermal.o 33acpi-y += scan.o
31ifdef CONFIG_CPU_FREQ 34acpi-y += ec.o
32processor-objs += processor_perflib.o 35acpi-$(CONFIG_ACPI_DOCK) += dock.o
36acpi-y += pci_root.o pci_link.o pci_irq.o pci_bind.o
37acpi-y += power.o
38acpi-y += system.o event.o
39acpi-$(CONFIG_ACPI_DEBUG) += debug.o
40acpi-$(CONFIG_ACPI_NUMA) += numa.o
41acpi-$(CONFIG_ACPI_PROCFS_POWER) += cm_sbs.o
42ifdef CONFIG_ACPI_VIDEO
43acpi-y += video_detect.o
33endif 44endif
34 45
35obj-y += bus.o glue.o 46# These are (potentially) separate modules
36obj-y += scan.o
37# Keep EC driver first. Initialization of others depend on it.
38obj-y += ec.o
39obj-$(CONFIG_ACPI_AC) += ac.o 47obj-$(CONFIG_ACPI_AC) += ac.o
40obj-$(CONFIG_ACPI_BATTERY) += battery.o
41obj-$(CONFIG_ACPI_BUTTON) += button.o 48obj-$(CONFIG_ACPI_BUTTON) += button.o
42obj-$(CONFIG_ACPI_FAN) += fan.o 49obj-$(CONFIG_ACPI_FAN) += fan.o
43obj-$(CONFIG_ACPI_DOCK) += dock.o
44obj-$(CONFIG_ACPI_VIDEO) += video.o 50obj-$(CONFIG_ACPI_VIDEO) += video.o
45ifdef CONFIG_ACPI_VIDEO
46obj-y += video_detect.o
47endif
48
49obj-y += pci_root.o pci_link.o pci_irq.o pci_bind.o
50obj-$(CONFIG_ACPI_PCI_SLOT) += pci_slot.o 51obj-$(CONFIG_ACPI_PCI_SLOT) += pci_slot.o
51obj-$(CONFIG_ACPI_PROCESSOR) += processor.o 52obj-$(CONFIG_ACPI_PROCESSOR) += processor.o
52obj-$(CONFIG_ACPI_CONTAINER) += container.o 53obj-$(CONFIG_ACPI_CONTAINER) += container.o
53obj-$(CONFIG_ACPI_THERMAL) += thermal.o 54obj-$(CONFIG_ACPI_THERMAL) += thermal.o
54obj-y += power.o 55obj-$(CONFIG_ACPI_HOTPLUG_MEMORY) += acpi_memhotplug.o
55obj-$(CONFIG_ACPI_SYSTEM) += system.o event.o 56obj-$(CONFIG_ACPI_BATTERY) += battery.o
56obj-$(CONFIG_ACPI_DEBUG) += debug.o
57obj-$(CONFIG_ACPI_NUMA) += numa.o
58obj-$(CONFIG_ACPI_HOTPLUG_MEMORY) += acpi_memhotplug.o
59obj-$(CONFIG_ACPI_PROCFS_POWER) += cm_sbs.o
60obj-$(CONFIG_ACPI_SBS) += sbshc.o 57obj-$(CONFIG_ACPI_SBS) += sbshc.o
61obj-$(CONFIG_ACPI_SBS) += sbs.o 58obj-$(CONFIG_ACPI_SBS) += sbs.o
59
60# processor has its own "processor." module_param namespace
61processor-y := processor_core.o processor_throttling.o
62processor-y += processor_idle.o processor_thermal.o
63processor-$(CONFIG_CPU_FREQ) += processor_perflib.o
diff --git a/drivers/acpi/ac.c b/drivers/acpi/ac.c
index 9b917dac7732..88e42abf5d88 100644
--- a/drivers/acpi/ac.c
+++ b/drivers/acpi/ac.c
@@ -191,7 +191,6 @@ static int acpi_ac_add_fs(struct acpi_device *device)
191 acpi_ac_dir); 191 acpi_ac_dir);
192 if (!acpi_device_dir(device)) 192 if (!acpi_device_dir(device))
193 return -ENODEV; 193 return -ENODEV;
194 acpi_device_dir(device)->owner = THIS_MODULE;
195 } 194 }
196 195
197 /* 'state' [R] */ 196 /* 'state' [R] */
diff --git a/drivers/acpi/acpica/Makefile b/drivers/acpi/acpica/Makefile
index 3f23298ee3fd..17e50824a6f1 100644
--- a/drivers/acpi/acpica/Makefile
+++ b/drivers/acpi/acpica/Makefile
@@ -18,7 +18,7 @@ obj-y += exconfig.o exfield.o exnames.o exoparg6.o exresolv.o exstorob.o\
18 excreate.o exmisc.o exoparg2.o exregion.o exstore.o exutils.o \ 18 excreate.o exmisc.o exoparg2.o exregion.o exstore.o exutils.o \
19 exdump.o exmutex.o exoparg3.o exresnte.o exstoren.o 19 exdump.o exmutex.o exoparg3.o exresnte.o exstoren.o
20 20
21obj-y += hwacpi.o hwgpe.o hwregs.o hwsleep.o hwxface.o 21obj-y += hwacpi.o hwgpe.o hwregs.o hwsleep.o hwxface.o hwvalid.o
22 22
23obj-$(ACPI_FUTURE_USAGE) += hwtimer.o 23obj-$(ACPI_FUTURE_USAGE) += hwtimer.o
24 24
@@ -41,4 +41,4 @@ obj-y += tbxface.o tbinstal.o tbutils.o tbfind.o tbfadt.o tbxfroot.o
41 41
42obj-y += utalloc.o utdebug.o uteval.o utinit.o utmisc.o utxface.o \ 42obj-y += utalloc.o utdebug.o uteval.o utinit.o utmisc.o utxface.o \
43 utcopy.o utdelete.o utglobal.o utmath.o utobject.o \ 43 utcopy.o utdelete.o utglobal.o utmath.o utobject.o \
44 utstate.o utmutex.o utobject.o utresrc.o 44 utstate.o utmutex.o utobject.o utresrc.o utlock.o
diff --git a/drivers/acpi/acpica/acglobal.h b/drivers/acpi/acpica/acglobal.h
index ddb40f5c68fc..16e5210ae936 100644
--- a/drivers/acpi/acpica/acglobal.h
+++ b/drivers/acpi/acpica/acglobal.h
@@ -148,9 +148,12 @@ ACPI_EXTERN struct acpi_internal_rsdt acpi_gbl_root_table_list;
148ACPI_EXTERN struct acpi_table_fadt acpi_gbl_FADT; 148ACPI_EXTERN struct acpi_table_fadt acpi_gbl_FADT;
149ACPI_EXTERN struct acpi_table_facs *acpi_gbl_FACS; 149ACPI_EXTERN struct acpi_table_facs *acpi_gbl_FACS;
150 150
151/* These addresses are calculated from FADT address values */ 151/* These addresses are calculated from the FADT Event Block addresses */
152 152
153ACPI_EXTERN struct acpi_generic_address acpi_gbl_xpm1a_status;
153ACPI_EXTERN struct acpi_generic_address acpi_gbl_xpm1a_enable; 154ACPI_EXTERN struct acpi_generic_address acpi_gbl_xpm1a_enable;
155
156ACPI_EXTERN struct acpi_generic_address acpi_gbl_xpm1b_status;
154ACPI_EXTERN struct acpi_generic_address acpi_gbl_xpm1b_enable; 157ACPI_EXTERN struct acpi_generic_address acpi_gbl_xpm1b_enable;
155 158
156/* 159/*
@@ -162,6 +165,10 @@ ACPI_EXTERN u8 acpi_gbl_integer_bit_width;
162ACPI_EXTERN u8 acpi_gbl_integer_byte_width; 165ACPI_EXTERN u8 acpi_gbl_integer_byte_width;
163ACPI_EXTERN u8 acpi_gbl_integer_nybble_width; 166ACPI_EXTERN u8 acpi_gbl_integer_nybble_width;
164 167
168/* Reader/Writer lock is used for namespace walk and dynamic table unload */
169
170ACPI_EXTERN struct acpi_rw_lock acpi_gbl_namespace_rw_lock;
171
165/***************************************************************************** 172/*****************************************************************************
166 * 173 *
167 * Mutual exlusion within ACPICA subsystem 174 * Mutual exlusion within ACPICA subsystem
@@ -245,6 +252,7 @@ ACPI_EXTERN u8 acpi_gbl_step_to_next_call;
245ACPI_EXTERN u8 acpi_gbl_acpi_hardware_present; 252ACPI_EXTERN u8 acpi_gbl_acpi_hardware_present;
246ACPI_EXTERN u8 acpi_gbl_events_initialized; 253ACPI_EXTERN u8 acpi_gbl_events_initialized;
247ACPI_EXTERN u8 acpi_gbl_system_awake_and_running; 254ACPI_EXTERN u8 acpi_gbl_system_awake_and_running;
255ACPI_EXTERN u8 acpi_gbl_osi_data;
248 256
249#ifndef DEFINE_ACPI_GLOBALS 257#ifndef DEFINE_ACPI_GLOBALS
250 258
@@ -371,7 +379,6 @@ ACPI_EXTERN char *acpi_gbl_db_buffer;
371ACPI_EXTERN char *acpi_gbl_db_filename; 379ACPI_EXTERN char *acpi_gbl_db_filename;
372ACPI_EXTERN u32 acpi_gbl_db_debug_level; 380ACPI_EXTERN u32 acpi_gbl_db_debug_level;
373ACPI_EXTERN u32 acpi_gbl_db_console_debug_level; 381ACPI_EXTERN u32 acpi_gbl_db_console_debug_level;
374ACPI_EXTERN struct acpi_table_header *acpi_gbl_db_table_ptr;
375ACPI_EXTERN struct acpi_namespace_node *acpi_gbl_db_scope_node; 382ACPI_EXTERN struct acpi_namespace_node *acpi_gbl_db_scope_node;
376 383
377/* 384/*
diff --git a/drivers/acpi/acpica/achware.h b/drivers/acpi/acpica/achware.h
index 58c69dc49ab4..4afa3d8e0efb 100644
--- a/drivers/acpi/acpica/achware.h
+++ b/drivers/acpi/acpica/achware.h
@@ -64,14 +64,22 @@ u32 acpi_hw_get_mode(void);
64 */ 64 */
65struct acpi_bit_register_info *acpi_hw_get_bit_register_info(u32 register_id); 65struct acpi_bit_register_info *acpi_hw_get_bit_register_info(u32 register_id);
66 66
67acpi_status 67acpi_status acpi_hw_write_pm1_control(u32 pm1a_control, u32 pm1b_control);
68acpi_hw_register_read(u32 register_id, u32 * return_value); 68
69acpi_status acpi_hw_register_read(u32 register_id, u32 *return_value);
69 70
70acpi_status acpi_hw_register_write(u32 register_id, u32 value); 71acpi_status acpi_hw_register_write(u32 register_id, u32 value);
71 72
72acpi_status acpi_hw_clear_acpi_status(void); 73acpi_status acpi_hw_clear_acpi_status(void);
73 74
74/* 75/*
76 * hwvalid - Port I/O with validation
77 */
78acpi_status acpi_hw_read_port(acpi_io_address address, u32 *value, u32 width);
79
80acpi_status acpi_hw_write_port(acpi_io_address address, u32 value, u32 width);
81
82/*
75 * hwgpe - GPE support 83 * hwgpe - GPE support
76 */ 84 */
77acpi_status acpi_hw_low_disable_gpe(struct acpi_gpe_event_info *gpe_event_info); 85acpi_status acpi_hw_low_disable_gpe(struct acpi_gpe_event_info *gpe_event_info);
diff --git a/drivers/acpi/acpica/aclocal.h b/drivers/acpi/acpica/aclocal.h
index 492d02761bb7..772ee5c4ccca 100644
--- a/drivers/acpi/acpica/aclocal.h
+++ b/drivers/acpi/acpica/aclocal.h
@@ -108,6 +108,14 @@ static char *acpi_gbl_mutex_names[ACPI_NUM_MUTEX] = {
108#endif 108#endif
109#endif 109#endif
110 110
111/* Lock structure for reader/writer interfaces */
112
113struct acpi_rw_lock {
114 acpi_mutex writer_mutex;
115 acpi_mutex reader_mutex;
116 u32 num_readers;
117};
118
111/* 119/*
112 * Predefined handles for spinlocks used within the subsystem. 120 * Predefined handles for spinlocks used within the subsystem.
113 * These spinlocks are created by acpi_ut_mutex_initialize 121 * These spinlocks are created by acpi_ut_mutex_initialize
@@ -772,7 +780,19 @@ struct acpi_bit_register_info {
772 * must be preserved. 780 * must be preserved.
773 */ 781 */
774#define ACPI_PM1_STATUS_PRESERVED_BITS 0x0800 /* Bit 11 */ 782#define ACPI_PM1_STATUS_PRESERVED_BITS 0x0800 /* Bit 11 */
775#define ACPI_PM1_CONTROL_PRESERVED_BITS 0x0200 /* Bit 9 (whatever) */ 783
784/* Write-only bits must be zeroed by software */
785
786#define ACPI_PM1_CONTROL_WRITEONLY_BITS 0x2004 /* Bits 13, 2 */
787
788/* For control registers, both ignored and reserved bits must be preserved */
789
790#define ACPI_PM1_CONTROL_IGNORED_BITS 0x0201 /* Bits 9, 0(SCI_EN) */
791#define ACPI_PM1_CONTROL_RESERVED_BITS 0xC1F8 /* Bits 14-15, 3-8 */
792#define ACPI_PM1_CONTROL_PRESERVED_BITS \
793 (ACPI_PM1_CONTROL_IGNORED_BITS | ACPI_PM1_CONTROL_RESERVED_BITS)
794
795#define ACPI_PM2_CONTROL_PRESERVED_BITS 0xFFFFFFFE /* All except bit 0 */
776 796
777/* 797/*
778 * Register IDs 798 * Register IDs
@@ -781,12 +801,10 @@ struct acpi_bit_register_info {
781#define ACPI_REGISTER_PM1_STATUS 0x01 801#define ACPI_REGISTER_PM1_STATUS 0x01
782#define ACPI_REGISTER_PM1_ENABLE 0x02 802#define ACPI_REGISTER_PM1_ENABLE 0x02
783#define ACPI_REGISTER_PM1_CONTROL 0x03 803#define ACPI_REGISTER_PM1_CONTROL 0x03
784#define ACPI_REGISTER_PM1A_CONTROL 0x04 804#define ACPI_REGISTER_PM2_CONTROL 0x04
785#define ACPI_REGISTER_PM1B_CONTROL 0x05 805#define ACPI_REGISTER_PM_TIMER 0x05
786#define ACPI_REGISTER_PM2_CONTROL 0x06 806#define ACPI_REGISTER_PROCESSOR_BLOCK 0x06
787#define ACPI_REGISTER_PM_TIMER 0x07 807#define ACPI_REGISTER_SMI_COMMAND_BLOCK 0x07
788#define ACPI_REGISTER_PROCESSOR_BLOCK 0x08
789#define ACPI_REGISTER_SMI_COMMAND_BLOCK 0x09
790 808
791/* Masks used to access the bit_registers */ 809/* Masks used to access the bit_registers */
792 810
@@ -818,7 +836,7 @@ struct acpi_bit_register_info {
818#define ACPI_BITMASK_SCI_ENABLE 0x0001 836#define ACPI_BITMASK_SCI_ENABLE 0x0001
819#define ACPI_BITMASK_BUS_MASTER_RLD 0x0002 837#define ACPI_BITMASK_BUS_MASTER_RLD 0x0002
820#define ACPI_BITMASK_GLOBAL_LOCK_RELEASE 0x0004 838#define ACPI_BITMASK_GLOBAL_LOCK_RELEASE 0x0004
821#define ACPI_BITMASK_SLEEP_TYPE_X 0x1C00 839#define ACPI_BITMASK_SLEEP_TYPE 0x1C00
822#define ACPI_BITMASK_SLEEP_ENABLE 0x2000 840#define ACPI_BITMASK_SLEEP_ENABLE 0x2000
823 841
824#define ACPI_BITMASK_ARB_DISABLE 0x0001 842#define ACPI_BITMASK_ARB_DISABLE 0x0001
@@ -844,11 +862,35 @@ struct acpi_bit_register_info {
844#define ACPI_BITPOSITION_SCI_ENABLE 0x00 862#define ACPI_BITPOSITION_SCI_ENABLE 0x00
845#define ACPI_BITPOSITION_BUS_MASTER_RLD 0x01 863#define ACPI_BITPOSITION_BUS_MASTER_RLD 0x01
846#define ACPI_BITPOSITION_GLOBAL_LOCK_RELEASE 0x02 864#define ACPI_BITPOSITION_GLOBAL_LOCK_RELEASE 0x02
847#define ACPI_BITPOSITION_SLEEP_TYPE_X 0x0A 865#define ACPI_BITPOSITION_SLEEP_TYPE 0x0A
848#define ACPI_BITPOSITION_SLEEP_ENABLE 0x0D 866#define ACPI_BITPOSITION_SLEEP_ENABLE 0x0D
849 867
850#define ACPI_BITPOSITION_ARB_DISABLE 0x00 868#define ACPI_BITPOSITION_ARB_DISABLE 0x00
851 869
870/* Structs and definitions for _OSI support and I/O port validation */
871
872#define ACPI_OSI_WIN_2000 0x01
873#define ACPI_OSI_WIN_XP 0x02
874#define ACPI_OSI_WIN_XP_SP1 0x03
875#define ACPI_OSI_WINSRV_2003 0x04
876#define ACPI_OSI_WIN_XP_SP2 0x05
877#define ACPI_OSI_WINSRV_2003_SP1 0x06
878#define ACPI_OSI_WIN_VISTA 0x07
879
880#define ACPI_ALWAYS_ILLEGAL 0x00
881
882struct acpi_interface_info {
883 char *name;
884 u8 value;
885};
886
887struct acpi_port_info {
888 char *name;
889 u16 start;
890 u16 end;
891 u8 osi_dependency;
892};
893
852/***************************************************************************** 894/*****************************************************************************
853 * 895 *
854 * Resource descriptors 896 * Resource descriptors
diff --git a/drivers/acpi/acpica/acmacros.h b/drivers/acpi/acpica/acmacros.h
index 9c127e8e2d6d..91ac7d7b4402 100644
--- a/drivers/acpi/acpica/acmacros.h
+++ b/drivers/acpi/acpica/acmacros.h
@@ -292,10 +292,6 @@
292#define ACPI_GET_DESCRIPTOR_TYPE(d) (((union acpi_descriptor *)(void *)(d))->common.descriptor_type) 292#define ACPI_GET_DESCRIPTOR_TYPE(d) (((union acpi_descriptor *)(void *)(d))->common.descriptor_type)
293#define ACPI_SET_DESCRIPTOR_TYPE(d, t) (((union acpi_descriptor *)(void *)(d))->common.descriptor_type = t) 293#define ACPI_SET_DESCRIPTOR_TYPE(d, t) (((union acpi_descriptor *)(void *)(d))->common.descriptor_type = t)
294 294
295/* Macro to test the object type */
296
297#define ACPI_GET_OBJECT_TYPE(d) (((union acpi_operand_object *)(void *)(d))->common.type)
298
299/* 295/*
300 * Macros for the master AML opcode table 296 * Macros for the master AML opcode table
301 */ 297 */
diff --git a/drivers/acpi/acpica/acobject.h b/drivers/acpi/acpica/acobject.h
index eb6f038b03d9..544dcf834922 100644
--- a/drivers/acpi/acpica/acobject.h
+++ b/drivers/acpi/acpica/acobject.h
@@ -97,7 +97,6 @@
97#define AOPOBJ_OBJECT_INITIALIZED 0x08 97#define AOPOBJ_OBJECT_INITIALIZED 0x08
98#define AOPOBJ_SETUP_COMPLETE 0x10 98#define AOPOBJ_SETUP_COMPLETE 0x10
99#define AOPOBJ_SINGLE_DATUM 0x20 99#define AOPOBJ_SINGLE_DATUM 0x20
100#define AOPOBJ_INVALID 0x40 /* Used if host OS won't allow an op_region address */
101 100
102/****************************************************************************** 101/******************************************************************************
103 * 102 *
diff --git a/drivers/acpi/acpica/acpredef.h b/drivers/acpi/acpica/acpredef.h
index 16a9ca9a66e4..63f656ae3604 100644
--- a/drivers/acpi/acpica/acpredef.h
+++ b/drivers/acpi/acpica/acpredef.h
@@ -52,41 +52,44 @@
52 * 1) PTYPE1 packages do not contain sub-packages. 52 * 1) PTYPE1 packages do not contain sub-packages.
53 * 53 *
54 * ACPI_PTYPE1_FIXED: Fixed length, 1 or 2 object types: 54 * ACPI_PTYPE1_FIXED: Fixed length, 1 or 2 object types:
55 * object type 55 * object type
56 * count 56 * count
57 * object type 57 * object type
58 * count 58 * count
59 * 59 *
60 * ACPI_PTYPE1_VAR: Variable length: 60 * ACPI_PTYPE1_VAR: Variable length:
61 * object type (Int/Buf/Ref) 61 * object type (Int/Buf/Ref)
62 * 62 *
63 * ACPI_PTYPE1_OPTION: Package has some required and some optional elements: 63 * ACPI_PTYPE1_OPTION: Package has some required and some optional elements
64 * Used for _PRW 64 * (Used for _PRW)
65 * 65 *
66 * 66 *
67 * 2) PTYPE2 packages contain a variable number of sub-packages. Each of the 67 * 2) PTYPE2 packages contain a variable number of sub-packages. Each of the
68 * different types describe the contents of each of the sub-packages. 68 * different types describe the contents of each of the sub-packages.
69 * 69 *
70 * ACPI_PTYPE2: Each subpackage contains 1 or 2 object types: 70 * ACPI_PTYPE2: Each subpackage contains 1 or 2 object types:
71 * object type 71 * object type
72 * count 72 * count
73 * object type 73 * object type
74 * count 74 * count
75 * (Used for _ALR,_MLS,_PSS,_TRT,_TSS)
75 * 76 *
76 * ACPI_PTYPE2_COUNT: Each subpackage has a count as first element: 77 * ACPI_PTYPE2_COUNT: Each subpackage has a count as first element:
77 * object type 78 * object type
79 * (Used for _CSD,_PSD,_TSD)
78 * 80 *
79 * ACPI_PTYPE2_PKG_COUNT: Count of subpackages at start, 1 or 2 object types: 81 * ACPI_PTYPE2_PKG_COUNT: Count of subpackages at start, 1 or 2 object types:
80 * object type 82 * object type
81 * count 83 * count
82 * object type 84 * object type
83 * count 85 * count
86 * (Used for _CST)
84 * 87 *
85 * ACPI_PTYPE2_FIXED: Each subpackage is of fixed length: 88 * ACPI_PTYPE2_FIXED: Each subpackage is of fixed length
86 * Used for _PRT 89 * (Used for _PRT)
87 * 90 *
88 * ACPI_PTYPE2_MIN: Each subpackage has a variable but minimum length 91 * ACPI_PTYPE2_MIN: Each subpackage has a variable but minimum length
89 * Used for _HPX 92 * (Used for _HPX)
90 * 93 *
91 *****************************************************************************/ 94 *****************************************************************************/
92 95
diff --git a/drivers/acpi/acpica/actables.h b/drivers/acpi/acpica/actables.h
index 7ce6e33c7f78..01c76b8ea7ba 100644
--- a/drivers/acpi/acpica/actables.h
+++ b/drivers/acpi/acpica/actables.h
@@ -49,7 +49,7 @@ acpi_status acpi_allocate_root_table(u32 initial_table_count);
49/* 49/*
50 * tbfadt - FADT parse/convert/validate 50 * tbfadt - FADT parse/convert/validate
51 */ 51 */
52void acpi_tb_parse_fadt(u32 table_index, u8 flags); 52void acpi_tb_parse_fadt(u32 table_index);
53 53
54void acpi_tb_create_local_fadt(struct acpi_table_header *table, u32 length); 54void acpi_tb_create_local_fadt(struct acpi_table_header *table, u32 length);
55 55
@@ -79,7 +79,7 @@ void acpi_tb_delete_table(struct acpi_table_desc *table_desc);
79 79
80void acpi_tb_terminate(void); 80void acpi_tb_terminate(void);
81 81
82void acpi_tb_delete_namespace_by_owner(u32 table_index); 82acpi_status acpi_tb_delete_namespace_by_owner(u32 table_index);
83 83
84acpi_status acpi_tb_allocate_owner_id(u32 table_index); 84acpi_status acpi_tb_allocate_owner_id(u32 table_index);
85 85
@@ -109,9 +109,8 @@ acpi_tb_verify_checksum(struct acpi_table_header *table, u32 length);
109 109
110void 110void
111acpi_tb_install_table(acpi_physical_address address, 111acpi_tb_install_table(acpi_physical_address address,
112 u8 flags, char *signature, u32 table_index); 112 char *signature, u32 table_index);
113 113
114acpi_status 114acpi_status acpi_tb_parse_root_table(acpi_physical_address rsdp_address);
115acpi_tb_parse_root_table(acpi_physical_address rsdp_address, u8 flags);
116 115
117#endif /* __ACTABLES_H__ */ 116#endif /* __ACTABLES_H__ */
diff --git a/drivers/acpi/acpica/acutils.h b/drivers/acpi/acpica/acutils.h
index 80d8813484fe..897810ba0ccc 100644
--- a/drivers/acpi/acpica/acutils.h
+++ b/drivers/acpi/acpica/acutils.h
@@ -346,6 +346,21 @@ acpi_status
346acpi_ut_execute_sxds(struct acpi_namespace_node *device_node, u8 * highest); 346acpi_ut_execute_sxds(struct acpi_namespace_node *device_node, u8 * highest);
347 347
348/* 348/*
349 * utlock - reader/writer locks
350 */
351acpi_status acpi_ut_create_rw_lock(struct acpi_rw_lock *lock);
352
353void acpi_ut_delete_rw_lock(struct acpi_rw_lock *lock);
354
355acpi_status acpi_ut_acquire_read_lock(struct acpi_rw_lock *lock);
356
357acpi_status acpi_ut_release_read_lock(struct acpi_rw_lock *lock);
358
359acpi_status acpi_ut_acquire_write_lock(struct acpi_rw_lock *lock);
360
361void acpi_ut_release_write_lock(struct acpi_rw_lock *lock);
362
363/*
349 * utobject - internal object create/delete/cache routines 364 * utobject - internal object create/delete/cache routines
350 */ 365 */
351union acpi_operand_object *acpi_ut_create_internal_object_dbg(const char 366union acpi_operand_object *acpi_ut_create_internal_object_dbg(const char
diff --git a/drivers/acpi/acpica/dsinit.c b/drivers/acpi/acpica/dsinit.c
index eb144b13d8fa..3aae13f30c5e 100644
--- a/drivers/acpi/acpica/dsinit.c
+++ b/drivers/acpi/acpica/dsinit.c
@@ -180,11 +180,23 @@ acpi_ds_initialize_objects(u32 table_index,
180 180
181 /* Walk entire namespace from the supplied root */ 181 /* Walk entire namespace from the supplied root */
182 182
183 status = acpi_walk_namespace(ACPI_TYPE_ANY, start_node, ACPI_UINT32_MAX, 183 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
184 acpi_ds_init_one_object, &info, NULL); 184 if (ACPI_FAILURE(status)) {
185 return_ACPI_STATUS(status);
186 }
187
188 /*
189 * We don't use acpi_walk_namespace since we do not want to acquire
190 * the namespace reader lock.
191 */
192 status =
193 acpi_ns_walk_namespace(ACPI_TYPE_ANY, start_node, ACPI_UINT32_MAX,
194 ACPI_NS_WALK_UNLOCK, acpi_ds_init_one_object,
195 &info, NULL);
185 if (ACPI_FAILURE(status)) { 196 if (ACPI_FAILURE(status)) {
186 ACPI_EXCEPTION((AE_INFO, status, "During WalkNamespace")); 197 ACPI_EXCEPTION((AE_INFO, status, "During WalkNamespace"));
187 } 198 }
199 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
188 200
189 status = acpi_get_table_by_index(table_index, &table); 201 status = acpi_get_table_by_index(table_index, &table);
190 if (ACPI_FAILURE(status)) { 202 if (ACPI_FAILURE(status)) {
diff --git a/drivers/acpi/acpica/dsmthdat.c b/drivers/acpi/acpica/dsmthdat.c
index da0f5468184c..22b1a3ce2c94 100644
--- a/drivers/acpi/acpica/dsmthdat.c
+++ b/drivers/acpi/acpica/dsmthdat.c
@@ -713,6 +713,6 @@ acpi_ds_method_data_get_type(u16 opcode,
713 713
714 /* Get the object type */ 714 /* Get the object type */
715 715
716 return_VALUE(ACPI_GET_OBJECT_TYPE(object)); 716 return_VALUE(object->type);
717} 717}
718#endif 718#endif
diff --git a/drivers/acpi/acpica/dsobject.c b/drivers/acpi/acpica/dsobject.c
index 15c628e6aa00..dab3f48f0b42 100644
--- a/drivers/acpi/acpica/dsobject.c
+++ b/drivers/acpi/acpica/dsobject.c
@@ -565,7 +565,7 @@ acpi_ds_create_node(struct acpi_walk_state *walk_state,
565 565
566 /* Re-type the object according to its argument */ 566 /* Re-type the object according to its argument */
567 567
568 node->type = ACPI_GET_OBJECT_TYPE(obj_desc); 568 node->type = obj_desc->common.type;
569 569
570 /* Attach obj to node */ 570 /* Attach obj to node */
571 571
@@ -619,7 +619,7 @@ acpi_ds_init_object_from_op(struct acpi_walk_state *walk_state,
619 619
620 /* Perform per-object initialization */ 620 /* Perform per-object initialization */
621 621
622 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) { 622 switch (obj_desc->common.type) {
623 case ACPI_TYPE_BUFFER: 623 case ACPI_TYPE_BUFFER:
624 624
625 /* 625 /*
@@ -803,7 +803,7 @@ acpi_ds_init_object_from_op(struct acpi_walk_state *walk_state,
803 default: 803 default:
804 804
805 ACPI_ERROR((AE_INFO, "Unimplemented data type: %X", 805 ACPI_ERROR((AE_INFO, "Unimplemented data type: %X",
806 ACPI_GET_OBJECT_TYPE(obj_desc))); 806 obj_desc->common.type));
807 807
808 status = AE_AML_OPERAND_TYPE; 808 status = AE_AML_OPERAND_TYPE;
809 break; 809 break;
diff --git a/drivers/acpi/acpica/dsopcode.c b/drivers/acpi/acpica/dsopcode.c
index 0c3b4dd60e8a..b4c87b5053e6 100644
--- a/drivers/acpi/acpica/dsopcode.c
+++ b/drivers/acpi/acpica/dsopcode.c
@@ -397,30 +397,6 @@ acpi_status acpi_ds_get_region_arguments(union acpi_operand_object *obj_desc)
397 status = acpi_ds_execute_arguments(node, acpi_ns_get_parent_node(node), 397 status = acpi_ds_execute_arguments(node, acpi_ns_get_parent_node(node),
398 extra_desc->extra.aml_length, 398 extra_desc->extra.aml_length,
399 extra_desc->extra.aml_start); 399 extra_desc->extra.aml_start);
400 if (ACPI_FAILURE(status)) {
401 return_ACPI_STATUS(status);
402 }
403
404 /* Validate the region address/length via the host OS */
405
406 status = acpi_os_validate_address(obj_desc->region.space_id,
407 obj_desc->region.address,
408 (acpi_size) obj_desc->region.length,
409 acpi_ut_get_node_name(node));
410
411 if (ACPI_FAILURE(status)) {
412 /*
413 * Invalid address/length. We will emit an error message and mark
414 * the region as invalid, so that it will cause an additional error if
415 * it is ever used. Then return AE_OK.
416 */
417 ACPI_EXCEPTION((AE_INFO, status,
418 "During address validation of OpRegion [%4.4s]",
419 node->name.ascii));
420 obj_desc->common.flags |= AOPOBJ_INVALID;
421 status = AE_OK;
422 }
423
424 return_ACPI_STATUS(status); 400 return_ACPI_STATUS(status);
425} 401}
426 402
@@ -484,7 +460,7 @@ acpi_ds_init_buffer_field(u16 aml_opcode,
484 460
485 /* Host object must be a Buffer */ 461 /* Host object must be a Buffer */
486 462
487 if (ACPI_GET_OBJECT_TYPE(buffer_desc) != ACPI_TYPE_BUFFER) { 463 if (buffer_desc->common.type != ACPI_TYPE_BUFFER) {
488 ACPI_ERROR((AE_INFO, 464 ACPI_ERROR((AE_INFO,
489 "Target of Create Field is not a Buffer object - %s", 465 "Target of Create Field is not a Buffer object - %s",
490 acpi_ut_get_object_type_name(buffer_desc))); 466 acpi_ut_get_object_type_name(buffer_desc)));
@@ -1365,10 +1341,8 @@ acpi_ds_exec_end_control_op(struct acpi_walk_state * walk_state,
1365 if ((ACPI_GET_DESCRIPTOR_TYPE 1341 if ((ACPI_GET_DESCRIPTOR_TYPE
1366 (walk_state->results->results.obj_desc[0]) == 1342 (walk_state->results->results.obj_desc[0]) ==
1367 ACPI_DESC_TYPE_OPERAND) 1343 ACPI_DESC_TYPE_OPERAND)
1368 && 1344 && ((walk_state->results->results.obj_desc[0])->
1369 (ACPI_GET_OBJECT_TYPE 1345 common.type == ACPI_TYPE_LOCAL_REFERENCE)
1370 (walk_state->results->results.obj_desc[0]) ==
1371 ACPI_TYPE_LOCAL_REFERENCE)
1372 && ((walk_state->results->results.obj_desc[0])-> 1346 && ((walk_state->results->results.obj_desc[0])->
1373 reference.class != ACPI_REFCLASS_INDEX)) { 1347 reference.class != ACPI_REFCLASS_INDEX)) {
1374 status = 1348 status =
diff --git a/drivers/acpi/acpica/dsutils.c b/drivers/acpi/acpica/dsutils.c
index dabc23a46176..dfa104102926 100644
--- a/drivers/acpi/acpica/dsutils.c
+++ b/drivers/acpi/acpica/dsutils.c
@@ -816,7 +816,7 @@ acpi_status acpi_ds_evaluate_name_path(struct acpi_walk_state *walk_state)
816 goto push_result; 816 goto push_result;
817 } 817 }
818 818
819 type = ACPI_GET_OBJECT_TYPE(*operand); 819 type = (*operand)->common.type;
820 820
821 status = acpi_ex_resolve_to_value(operand, walk_state); 821 status = acpi_ex_resolve_to_value(operand, walk_state);
822 if (ACPI_FAILURE(status)) { 822 if (ACPI_FAILURE(status)) {
diff --git a/drivers/acpi/acpica/dswexec.c b/drivers/acpi/acpica/dswexec.c
index 350e6656bc89..f0280856dc0e 100644
--- a/drivers/acpi/acpica/dswexec.c
+++ b/drivers/acpi/acpica/dswexec.c
@@ -138,11 +138,10 @@ acpi_ds_get_predicate_value(struct acpi_walk_state *walk_state,
138 goto cleanup; 138 goto cleanup;
139 } 139 }
140 140
141 if (ACPI_GET_OBJECT_TYPE(local_obj_desc) != ACPI_TYPE_INTEGER) { 141 if (local_obj_desc->common.type != ACPI_TYPE_INTEGER) {
142 ACPI_ERROR((AE_INFO, 142 ACPI_ERROR((AE_INFO,
143 "Bad predicate (not an integer) ObjDesc=%p State=%p Type=%X", 143 "Bad predicate (not an integer) ObjDesc=%p State=%p Type=%X",
144 obj_desc, walk_state, 144 obj_desc, walk_state, obj_desc->common.type));
145 ACPI_GET_OBJECT_TYPE(obj_desc)));
146 145
147 status = AE_AML_OPERAND_TYPE; 146 status = AE_AML_OPERAND_TYPE;
148 goto cleanup; 147 goto cleanup;
diff --git a/drivers/acpi/acpica/evevent.c b/drivers/acpi/acpica/evevent.c
index 803edd9e3f6a..cd55c774e882 100644
--- a/drivers/acpi/acpica/evevent.c
+++ b/drivers/acpi/acpica/evevent.c
@@ -183,7 +183,7 @@ acpi_status acpi_ev_install_xrupt_handlers(void)
183 * 183 *
184 * RETURN: Status 184 * RETURN: Status
185 * 185 *
186 * DESCRIPTION: Install the fixed event handlers and enable the fixed events. 186 * DESCRIPTION: Install the fixed event handlers and disable all fixed events.
187 * 187 *
188 ******************************************************************************/ 188 ******************************************************************************/
189 189
@@ -200,12 +200,13 @@ static acpi_status acpi_ev_fixed_event_initialize(void)
200 acpi_gbl_fixed_event_handlers[i].handler = NULL; 200 acpi_gbl_fixed_event_handlers[i].handler = NULL;
201 acpi_gbl_fixed_event_handlers[i].context = NULL; 201 acpi_gbl_fixed_event_handlers[i].context = NULL;
202 202
203 /* Enable the fixed event */ 203 /* Disable the fixed event */
204 204
205 if (acpi_gbl_fixed_event_info[i].enable_register_id != 0xFF) { 205 if (acpi_gbl_fixed_event_info[i].enable_register_id != 0xFF) {
206 status = 206 status =
207 acpi_set_register(acpi_gbl_fixed_event_info[i]. 207 acpi_write_bit_register(acpi_gbl_fixed_event_info
208 enable_register_id, 0); 208 [i].enable_register_id,
209 ACPI_DISABLE_EVENT);
209 if (ACPI_FAILURE(status)) { 210 if (ACPI_FAILURE(status)) {
210 return (status); 211 return (status);
211 } 212 }
@@ -288,16 +289,17 @@ static u32 acpi_ev_fixed_event_dispatch(u32 event)
288 289
289 /* Clear the status bit */ 290 /* Clear the status bit */
290 291
291 (void)acpi_set_register(acpi_gbl_fixed_event_info[event]. 292 (void)acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
292 status_register_id, 1); 293 status_register_id, ACPI_CLEAR_STATUS);
293 294
294 /* 295 /*
295 * Make sure we've got a handler. If not, report an error. The event is 296 * Make sure we've got a handler. If not, report an error. The event is
296 * disabled to prevent further interrupts. 297 * disabled to prevent further interrupts.
297 */ 298 */
298 if (NULL == acpi_gbl_fixed_event_handlers[event].handler) { 299 if (NULL == acpi_gbl_fixed_event_handlers[event].handler) {
299 (void)acpi_set_register(acpi_gbl_fixed_event_info[event]. 300 (void)acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
300 enable_register_id, 0); 301 enable_register_id,
302 ACPI_DISABLE_EVENT);
301 303
302 ACPI_ERROR((AE_INFO, 304 ACPI_ERROR((AE_INFO,
303 "No installed handler for fixed event [%08X]", 305 "No installed handler for fixed event [%08X]",
diff --git a/drivers/acpi/acpica/evgpe.c b/drivers/acpi/acpica/evgpe.c
index f345ced36477..b9d8ee69ca6c 100644
--- a/drivers/acpi/acpica/evgpe.c
+++ b/drivers/acpi/acpica/evgpe.c
@@ -88,10 +88,10 @@ acpi_ev_set_gpe_type(struct acpi_gpe_event_info *gpe_event_info, u8 type)
88 88
89 status = acpi_ev_disable_gpe(gpe_event_info); 89 status = acpi_ev_disable_gpe(gpe_event_info);
90 90
91 /* Type was validated above */ 91 /* Clear the type bits and insert the new Type */
92 92
93 gpe_event_info->flags &= ~ACPI_GPE_TYPE_MASK; /* Clear type bits */ 93 gpe_event_info->flags &= ~ACPI_GPE_TYPE_MASK;
94 gpe_event_info->flags |= type; /* Insert type */ 94 gpe_event_info->flags |= type;
95 return_ACPI_STATUS(status); 95 return_ACPI_STATUS(status);
96} 96}
97 97
@@ -122,6 +122,7 @@ acpi_ev_update_gpe_enable_masks(struct acpi_gpe_event_info *gpe_event_info,
122 if (!gpe_register_info) { 122 if (!gpe_register_info) {
123 return_ACPI_STATUS(AE_NOT_EXIST); 123 return_ACPI_STATUS(AE_NOT_EXIST);
124 } 124 }
125
125 register_bit = (u8) 126 register_bit = (u8)
126 (1 << 127 (1 <<
127 (gpe_event_info->gpe_number - gpe_register_info->base_gpe_number)); 128 (gpe_event_info->gpe_number - gpe_register_info->base_gpe_number));
diff --git a/drivers/acpi/acpica/evgpeblk.c b/drivers/acpi/acpica/evgpeblk.c
index 484cc0565d5b..7b3463639422 100644
--- a/drivers/acpi/acpica/evgpeblk.c
+++ b/drivers/acpi/acpica/evgpeblk.c
@@ -104,9 +104,9 @@ u8 acpi_ev_valid_gpe_event(struct acpi_gpe_event_info *gpe_event_info)
104 104
105 while (gpe_block) { 105 while (gpe_block) {
106 if ((&gpe_block->event_info[0] <= gpe_event_info) && 106 if ((&gpe_block->event_info[0] <= gpe_event_info) &&
107 (&gpe_block-> 107 (&gpe_block->event_info[((acpi_size)
108 event_info[((acpi_size) gpe_block-> 108 gpe_block->
109 register_count) * 8] > 109 register_count) * 8] >
110 gpe_event_info)) { 110 gpe_event_info)) {
111 return (TRUE); 111 return (TRUE);
112 } 112 }
@@ -210,10 +210,9 @@ acpi_ev_delete_gpe_handlers(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
210 /* Now look at the individual GPEs in this byte register */ 210 /* Now look at the individual GPEs in this byte register */
211 211
212 for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) { 212 for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) {
213 gpe_event_info = 213 gpe_event_info = &gpe_block->event_info[((acpi_size) i *
214 &gpe_block-> 214 ACPI_GPE_REGISTER_WIDTH)
215 event_info[((acpi_size) i * 215 + j];
216 ACPI_GPE_REGISTER_WIDTH) + j];
217 216
218 if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) == 217 if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) ==
219 ACPI_GPE_DISPATCH_HANDLER) { 218 ACPI_GPE_DISPATCH_HANDLER) {
@@ -293,8 +292,8 @@ acpi_ev_save_method_info(acpi_handle obj_handle,
293 /* Unknown method type, just ignore it! */ 292 /* Unknown method type, just ignore it! */
294 293
295 ACPI_DEBUG_PRINT((ACPI_DB_LOAD, 294 ACPI_DEBUG_PRINT((ACPI_DB_LOAD,
296 "Ignoring unknown GPE method type: %s (name not of form _Lxx or _Exx)", 295 "Ignoring unknown GPE method type: %s "
297 name)); 296 "(name not of form _Lxx or _Exx)", name));
298 return_ACPI_STATUS(AE_OK); 297 return_ACPI_STATUS(AE_OK);
299 } 298 }
300 299
@@ -306,17 +305,16 @@ acpi_ev_save_method_info(acpi_handle obj_handle,
306 /* Conversion failed; invalid method, just ignore it */ 305 /* Conversion failed; invalid method, just ignore it */
307 306
308 ACPI_DEBUG_PRINT((ACPI_DB_LOAD, 307 ACPI_DEBUG_PRINT((ACPI_DB_LOAD,
309 "Could not extract GPE number from name: %s (name is not of form _Lxx or _Exx)", 308 "Could not extract GPE number from name: %s "
310 name)); 309 "(name is not of form _Lxx or _Exx)", name));
311 return_ACPI_STATUS(AE_OK); 310 return_ACPI_STATUS(AE_OK);
312 } 311 }
313 312
314 /* Ensure that we have a valid GPE number for this GPE block */ 313 /* Ensure that we have a valid GPE number for this GPE block */
315 314
316 if ((gpe_number < gpe_block->block_base_number) || 315 if ((gpe_number < gpe_block->block_base_number) ||
317 (gpe_number >= 316 (gpe_number >= (gpe_block->block_base_number +
318 (gpe_block->block_base_number + 317 (gpe_block->register_count * 8)))) {
319 (gpe_block->register_count * 8)))) {
320 /* 318 /*
321 * Not valid for this GPE block, just ignore it. However, it may be 319 * Not valid for this GPE block, just ignore it. However, it may be
322 * valid for a different GPE block, since GPE0 and GPE1 methods both 320 * valid for a different GPE block, since GPE0 and GPE1 methods both
@@ -408,7 +406,7 @@ acpi_ev_match_prw_and_gpe(acpi_handle obj_handle,
408 */ 406 */
409 obj_desc = pkg_desc->package.elements[0]; 407 obj_desc = pkg_desc->package.elements[0];
410 408
411 if (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_INTEGER) { 409 if (obj_desc->common.type == ACPI_TYPE_INTEGER) {
412 410
413 /* Use FADT-defined GPE device (from definition of _PRW) */ 411 /* Use FADT-defined GPE device (from definition of _PRW) */
414 412
@@ -417,15 +415,15 @@ acpi_ev_match_prw_and_gpe(acpi_handle obj_handle,
417 /* Integer is the GPE number in the FADT described GPE blocks */ 415 /* Integer is the GPE number in the FADT described GPE blocks */
418 416
419 gpe_number = (u32) obj_desc->integer.value; 417 gpe_number = (u32) obj_desc->integer.value;
420 } else if (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_PACKAGE) { 418 } else if (obj_desc->common.type == ACPI_TYPE_PACKAGE) {
421 419
422 /* Package contains a GPE reference and GPE number within a GPE block */ 420 /* Package contains a GPE reference and GPE number within a GPE block */
423 421
424 if ((obj_desc->package.count < 2) || 422 if ((obj_desc->package.count < 2) ||
425 (ACPI_GET_OBJECT_TYPE(obj_desc->package.elements[0]) != 423 ((obj_desc->package.elements[0])->common.type !=
426 ACPI_TYPE_LOCAL_REFERENCE) 424 ACPI_TYPE_LOCAL_REFERENCE) ||
427 || (ACPI_GET_OBJECT_TYPE(obj_desc->package.elements[1]) != 425 ((obj_desc->package.elements[1])->common.type !=
428 ACPI_TYPE_INTEGER)) { 426 ACPI_TYPE_INTEGER)) {
429 goto cleanup; 427 goto cleanup;
430 } 428 }
431 429
@@ -450,11 +448,11 @@ acpi_ev_match_prw_and_gpe(acpi_handle obj_handle,
450 */ 448 */
451 if ((gpe_device == target_gpe_device) && 449 if ((gpe_device == target_gpe_device) &&
452 (gpe_number >= gpe_block->block_base_number) && 450 (gpe_number >= gpe_block->block_base_number) &&
453 (gpe_number < 451 (gpe_number < gpe_block->block_base_number +
454 gpe_block->block_base_number + (gpe_block->register_count * 8))) { 452 (gpe_block->register_count * 8))) {
455 gpe_event_info = 453 gpe_event_info = &gpe_block->event_info[gpe_number -
456 &gpe_block->event_info[gpe_number - 454 gpe_block->
457 gpe_block->block_base_number]; 455 block_base_number];
458 456
459 /* Mark GPE for WAKE-ONLY but WAKE_DISABLED */ 457 /* Mark GPE for WAKE-ONLY but WAKE_DISABLED */
460 458
@@ -1033,8 +1031,8 @@ acpi_ev_initialize_gpe_block(struct acpi_namespace_node *gpe_device,
1033 * 1) are "runtime" or "run/wake" GPEs, and 1031 * 1) are "runtime" or "run/wake" GPEs, and
1034 * 2) have a corresponding _Lxx or _Exx method 1032 * 2) have a corresponding _Lxx or _Exx method
1035 * 1033 *
1036 * Any other GPEs within this block must be enabled via the acpi_enable_gpe() 1034 * Any other GPEs within this block must be enabled via the
1037 * external interface. 1035 * acpi_enable_gpe() external interface.
1038 */ 1036 */
1039 wake_gpe_count = 0; 1037 wake_gpe_count = 0;
1040 gpe_enabled_count = 0; 1038 gpe_enabled_count = 0;
@@ -1044,14 +1042,13 @@ acpi_ev_initialize_gpe_block(struct acpi_namespace_node *gpe_device,
1044 1042
1045 /* Get the info block for this particular GPE */ 1043 /* Get the info block for this particular GPE */
1046 1044
1047 gpe_event_info = 1045 gpe_event_info = &gpe_block->event_info[((acpi_size) i *
1048 &gpe_block-> 1046 ACPI_GPE_REGISTER_WIDTH)
1049 event_info[((acpi_size) i * 1047 + j];
1050 ACPI_GPE_REGISTER_WIDTH) + j];
1051 1048
1052 if (((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) == 1049 if (((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) ==
1053 ACPI_GPE_DISPATCH_METHOD) 1050 ACPI_GPE_DISPATCH_METHOD) &&
1054 && (gpe_event_info->flags & ACPI_GPE_TYPE_RUNTIME)) { 1051 (gpe_event_info->flags & ACPI_GPE_TYPE_RUNTIME)) {
1055 gpe_enabled_count++; 1052 gpe_enabled_count++;
1056 } 1053 }
1057 1054
@@ -1105,8 +1102,8 @@ acpi_status acpi_ev_gpe_initialize(void)
1105 /* 1102 /*
1106 * Initialize the GPE Block(s) defined in the FADT 1103 * Initialize the GPE Block(s) defined in the FADT
1107 * 1104 *
1108 * Why the GPE register block lengths are divided by 2: From the ACPI Spec, 1105 * Why the GPE register block lengths are divided by 2: From the ACPI
1109 * section "General-Purpose Event Registers", we have: 1106 * Spec, section "General-Purpose Event Registers", we have:
1110 * 1107 *
1111 * "Each register block contains two registers of equal length 1108 * "Each register block contains two registers of equal length
1112 * GPEx_STS and GPEx_EN (where x is 0 or 1). The length of the 1109 * GPEx_STS and GPEx_EN (where x is 0 or 1). The length of the
@@ -1163,7 +1160,8 @@ acpi_status acpi_ev_gpe_initialize(void)
1163 if ((register_count0) && 1160 if ((register_count0) &&
1164 (gpe_number_max >= acpi_gbl_FADT.gpe1_base)) { 1161 (gpe_number_max >= acpi_gbl_FADT.gpe1_base)) {
1165 ACPI_ERROR((AE_INFO, 1162 ACPI_ERROR((AE_INFO,
1166 "GPE0 block (GPE 0 to %d) overlaps the GPE1 block (GPE %d to %d) - Ignoring GPE1", 1163 "GPE0 block (GPE 0 to %d) overlaps the GPE1 block "
1164 "(GPE %d to %d) - Ignoring GPE1",
1167 gpe_number_max, acpi_gbl_FADT.gpe1_base, 1165 gpe_number_max, acpi_gbl_FADT.gpe1_base,
1168 acpi_gbl_FADT.gpe1_base + 1166 acpi_gbl_FADT.gpe1_base +
1169 ((register_count1 * 1167 ((register_count1 *
diff --git a/drivers/acpi/acpica/evmisc.c b/drivers/acpi/acpica/evmisc.c
index 5f893057bcc6..ce224e1eaa89 100644
--- a/drivers/acpi/acpica/evmisc.c
+++ b/drivers/acpi/acpica/evmisc.c
@@ -163,10 +163,10 @@ acpi_ev_queue_notify_request(struct acpi_namespace_node * node,
163 * 2) Global device notify handler 163 * 2) Global device notify handler
164 * 3) Per-device notify handler 164 * 3) Per-device notify handler
165 */ 165 */
166 if ((acpi_gbl_system_notify.handler 166 if ((acpi_gbl_system_notify.handler &&
167 && (notify_value <= ACPI_MAX_SYS_NOTIFY)) 167 (notify_value <= ACPI_MAX_SYS_NOTIFY)) ||
168 || (acpi_gbl_device_notify.handler 168 (acpi_gbl_device_notify.handler &&
169 && (notify_value > ACPI_MAX_SYS_NOTIFY)) || handler_obj) { 169 (notify_value > ACPI_MAX_SYS_NOTIFY)) || handler_obj) {
170 notify_info = acpi_ut_create_generic_state(); 170 notify_info = acpi_ut_create_generic_state();
171 if (!notify_info) { 171 if (!notify_info) {
172 return (AE_NO_MEMORY); 172 return (AE_NO_MEMORY);
@@ -174,7 +174,8 @@ acpi_ev_queue_notify_request(struct acpi_namespace_node * node,
174 174
175 if (!handler_obj) { 175 if (!handler_obj) {
176 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 176 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
177 "Executing system notify handler for Notify (%4.4s, %X) node %p\n", 177 "Executing system notify handler for Notify (%4.4s, %X) "
178 "node %p\n",
178 acpi_ut_get_node_name(node), 179 acpi_ut_get_node_name(node),
179 notify_value, node)); 180 notify_value, node));
180 } 181 }
@@ -534,8 +535,9 @@ acpi_status acpi_ev_release_global_lock(void)
534 */ 535 */
535 if (pending) { 536 if (pending) {
536 status = 537 status =
537 acpi_set_register(ACPI_BITREG_GLOBAL_LOCK_RELEASE, 538 acpi_write_bit_register
538 1); 539 (ACPI_BITREG_GLOBAL_LOCK_RELEASE,
540 ACPI_ENABLE_EVENT);
539 } 541 }
540 542
541 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, 543 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
diff --git a/drivers/acpi/acpica/evregion.c b/drivers/acpi/acpica/evregion.c
index 665c0887ab4d..538d63264555 100644
--- a/drivers/acpi/acpica/evregion.c
+++ b/drivers/acpi/acpica/evregion.c
@@ -691,7 +691,7 @@ acpi_ev_install_handler(acpi_handle obj_handle,
691 691
692 /* Devices are handled different than regions */ 692 /* Devices are handled different than regions */
693 693
694 if (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_DEVICE) { 694 if (obj_desc->common.type == ACPI_TYPE_DEVICE) {
695 695
696 /* Check if this Device already has a handler for this address space */ 696 /* Check if this Device already has a handler for this address space */
697 697
@@ -703,7 +703,8 @@ acpi_ev_install_handler(acpi_handle obj_handle,
703 if (next_handler_obj->address_space.space_id == 703 if (next_handler_obj->address_space.space_id ==
704 handler_obj->address_space.space_id) { 704 handler_obj->address_space.space_id) {
705 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION, 705 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
706 "Found handler for region [%s] in device %p(%p) handler %p\n", 706 "Found handler for region [%s] in device %p(%p) "
707 "handler %p\n",
707 acpi_ut_get_region_name 708 acpi_ut_get_region_name
708 (handler_obj->address_space. 709 (handler_obj->address_space.
709 space_id), obj_desc, 710 space_id), obj_desc,
diff --git a/drivers/acpi/acpica/evrgnini.c b/drivers/acpi/acpica/evrgnini.c
index f3f1fb45c3dc..284a7becbe96 100644
--- a/drivers/acpi/acpica/evrgnini.c
+++ b/drivers/acpi/acpica/evrgnini.c
@@ -241,7 +241,8 @@ acpi_ev_pci_config_region_setup(acpi_handle handle,
241 status = AE_OK; 241 status = AE_OK;
242 } else { 242 } else {
243 ACPI_EXCEPTION((AE_INFO, status, 243 ACPI_EXCEPTION((AE_INFO, status,
244 "Could not install PciConfig handler for Root Bridge %4.4s", 244 "Could not install PciConfig handler "
245 "for Root Bridge %4.4s",
245 acpi_ut_get_node_name 246 acpi_ut_get_node_name
246 (pci_root_node))); 247 (pci_root_node)));
247 } 248 }
@@ -293,9 +294,8 @@ acpi_ev_pci_config_region_setup(acpi_handle handle,
293 * Get the PCI device and function numbers from the _ADR object contained 294 * Get the PCI device and function numbers from the _ADR object contained
294 * in the parent's scope. 295 * in the parent's scope.
295 */ 296 */
296 status = 297 status = acpi_ut_evaluate_numeric_object(METHOD_NAME__ADR,
297 acpi_ut_evaluate_numeric_object(METHOD_NAME__ADR, pci_device_node, 298 pci_device_node, &pci_value);
298 &pci_value);
299 299
300 /* 300 /*
301 * The default is zero, and since the allocation above zeroed the data, 301 * The default is zero, and since the allocation above zeroed the data,
@@ -308,18 +308,16 @@ acpi_ev_pci_config_region_setup(acpi_handle handle,
308 308
309 /* The PCI segment number comes from the _SEG method */ 309 /* The PCI segment number comes from the _SEG method */
310 310
311 status = 311 status = acpi_ut_evaluate_numeric_object(METHOD_NAME__SEG,
312 acpi_ut_evaluate_numeric_object(METHOD_NAME__SEG, pci_root_node, 312 pci_root_node, &pci_value);
313 &pci_value);
314 if (ACPI_SUCCESS(status)) { 313 if (ACPI_SUCCESS(status)) {
315 pci_id->segment = ACPI_LOWORD(pci_value); 314 pci_id->segment = ACPI_LOWORD(pci_value);
316 } 315 }
317 316
318 /* The PCI bus number comes from the _BBN method */ 317 /* The PCI bus number comes from the _BBN method */
319 318
320 status = 319 status = acpi_ut_evaluate_numeric_object(METHOD_NAME__BBN,
321 acpi_ut_evaluate_numeric_object(METHOD_NAME__BBN, pci_root_node, 320 pci_root_node, &pci_value);
322 &pci_value);
323 if (ACPI_SUCCESS(status)) { 321 if (ACPI_SUCCESS(status)) {
324 pci_id->bus = ACPI_LOWORD(pci_value); 322 pci_id->bus = ACPI_LOWORD(pci_value);
325 } 323 }
@@ -632,8 +630,8 @@ acpi_ev_initialize_region(union acpi_operand_object *region_obj,
632 acpi_ns_locked); 630 acpi_ns_locked);
633 631
634 /* 632 /*
635 * Tell all users that this region is usable by running the _REG 633 * Tell all users that this region is usable by
636 * method 634 * running the _REG method
637 */ 635 */
638 if (acpi_ns_locked) { 636 if (acpi_ns_locked) {
639 status = 637 status =
diff --git a/drivers/acpi/acpica/evxface.c b/drivers/acpi/acpica/evxface.c
index 3aca9010a11e..10b8543dd466 100644
--- a/drivers/acpi/acpica/evxface.c
+++ b/drivers/acpi/acpica/evxface.c
@@ -631,7 +631,8 @@ acpi_install_gpe_handler(acpi_handle gpe_device,
631 631
632 /* Setup up dispatch flags to indicate handler (vs. method) */ 632 /* Setup up dispatch flags to indicate handler (vs. method) */
633 633
634 gpe_event_info->flags &= ~(ACPI_GPE_XRUPT_TYPE_MASK | ACPI_GPE_DISPATCH_MASK); /* Clear bits */ 634 gpe_event_info->flags &=
635 ~(ACPI_GPE_XRUPT_TYPE_MASK | ACPI_GPE_DISPATCH_MASK);
635 gpe_event_info->flags |= (u8) (type | ACPI_GPE_DISPATCH_HANDLER); 636 gpe_event_info->flags |= (u8) (type | ACPI_GPE_DISPATCH_HANDLER);
636 637
637 acpi_os_release_lock(acpi_gbl_gpe_lock, flags); 638 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
diff --git a/drivers/acpi/acpica/evxfevnt.c b/drivers/acpi/acpica/evxfevnt.c
index 35485e4b60a6..d0a080747ec3 100644
--- a/drivers/acpi/acpica/evxfevnt.c
+++ b/drivers/acpi/acpica/evxfevnt.c
@@ -172,8 +172,8 @@ acpi_status acpi_enable_event(u32 event, u32 flags)
172 * register bit) 172 * register bit)
173 */ 173 */
174 status = 174 status =
175 acpi_set_register(acpi_gbl_fixed_event_info[event]. 175 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
176 enable_register_id, 1); 176 enable_register_id, ACPI_ENABLE_EVENT);
177 if (ACPI_FAILURE(status)) { 177 if (ACPI_FAILURE(status)) {
178 return_ACPI_STATUS(status); 178 return_ACPI_STATUS(status);
179 } 179 }
@@ -181,8 +181,8 @@ acpi_status acpi_enable_event(u32 event, u32 flags)
181 /* Make sure that the hardware responded */ 181 /* Make sure that the hardware responded */
182 182
183 status = 183 status =
184 acpi_get_register(acpi_gbl_fixed_event_info[event]. 184 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
185 enable_register_id, &value); 185 enable_register_id, &value);
186 if (ACPI_FAILURE(status)) { 186 if (ACPI_FAILURE(status)) {
187 return_ACPI_STATUS(status); 187 return_ACPI_STATUS(status);
188 } 188 }
@@ -354,15 +354,15 @@ acpi_status acpi_disable_event(u32 event, u32 flags)
354 * register bit) 354 * register bit)
355 */ 355 */
356 status = 356 status =
357 acpi_set_register(acpi_gbl_fixed_event_info[event]. 357 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
358 enable_register_id, 0); 358 enable_register_id, ACPI_DISABLE_EVENT);
359 if (ACPI_FAILURE(status)) { 359 if (ACPI_FAILURE(status)) {
360 return_ACPI_STATUS(status); 360 return_ACPI_STATUS(status);
361 } 361 }
362 362
363 status = 363 status =
364 acpi_get_register(acpi_gbl_fixed_event_info[event]. 364 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
365 enable_register_id, &value); 365 enable_register_id, &value);
366 if (ACPI_FAILURE(status)) { 366 if (ACPI_FAILURE(status)) {
367 return_ACPI_STATUS(status); 367 return_ACPI_STATUS(status);
368 } 368 }
@@ -407,8 +407,8 @@ acpi_status acpi_clear_event(u32 event)
407 * register bit) 407 * register bit)
408 */ 408 */
409 status = 409 status =
410 acpi_set_register(acpi_gbl_fixed_event_info[event]. 410 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
411 status_register_id, 1); 411 status_register_id, ACPI_CLEAR_STATUS);
412 412
413 return_ACPI_STATUS(status); 413 return_ACPI_STATUS(status);
414} 414}
@@ -495,7 +495,7 @@ acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status)
495 /* Get the status of the requested fixed event */ 495 /* Get the status of the requested fixed event */
496 496
497 status = 497 status =
498 acpi_get_register(acpi_gbl_fixed_event_info[event]. 498 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
499 enable_register_id, &value); 499 enable_register_id, &value);
500 if (ACPI_FAILURE(status)) 500 if (ACPI_FAILURE(status))
501 return_ACPI_STATUS(status); 501 return_ACPI_STATUS(status);
@@ -503,7 +503,7 @@ acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status)
503 *event_status = value; 503 *event_status = value;
504 504
505 status = 505 status =
506 acpi_get_register(acpi_gbl_fixed_event_info[event]. 506 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
507 status_register_id, &value); 507 status_register_id, &value);
508 if (ACPI_FAILURE(status)) 508 if (ACPI_FAILURE(status))
509 return_ACPI_STATUS(status); 509 return_ACPI_STATUS(status);
diff --git a/drivers/acpi/acpica/evxfregn.c b/drivers/acpi/acpica/evxfregn.c
index 479e7a3721be..7c3d2d356ffb 100644
--- a/drivers/acpi/acpica/evxfregn.c
+++ b/drivers/acpi/acpica/evxfregn.c
@@ -193,7 +193,8 @@ acpi_remove_address_space_handler(acpi_handle device,
193 /* Matched space_id, first dereference this in the Regions */ 193 /* Matched space_id, first dereference this in the Regions */
194 194
195 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION, 195 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
196 "Removing address handler %p(%p) for region %s on Device %p(%p)\n", 196 "Removing address handler %p(%p) for region %s "
197 "on Device %p(%p)\n",
197 handler_obj, handler, 198 handler_obj, handler,
198 acpi_ut_get_region_name(space_id), 199 acpi_ut_get_region_name(space_id),
199 node, obj_desc)); 200 node, obj_desc));
diff --git a/drivers/acpi/acpica/exconfig.c b/drivers/acpi/acpica/exconfig.c
index 932bbc26aa04..3deb20a126b2 100644
--- a/drivers/acpi/acpica/exconfig.c
+++ b/drivers/acpi/acpica/exconfig.c
@@ -291,7 +291,7 @@ acpi_ex_load_op(union acpi_operand_object *obj_desc,
291 291
292 /* Source Object can be either an op_region or a Buffer/Field */ 292 /* Source Object can be either an op_region or a Buffer/Field */
293 293
294 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) { 294 switch (obj_desc->common.type) {
295 case ACPI_TYPE_REGION: 295 case ACPI_TYPE_REGION:
296 296
297 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, 297 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
@@ -501,7 +501,7 @@ acpi_status acpi_ex_unload_table(union acpi_operand_object *ddb_handle)
501 */ 501 */
502 if ((!ddb_handle) || 502 if ((!ddb_handle) ||
503 (ACPI_GET_DESCRIPTOR_TYPE(ddb_handle) != ACPI_DESC_TYPE_OPERAND) || 503 (ACPI_GET_DESCRIPTOR_TYPE(ddb_handle) != ACPI_DESC_TYPE_OPERAND) ||
504 (ACPI_GET_OBJECT_TYPE(ddb_handle) != ACPI_TYPE_LOCAL_REFERENCE)) { 504 (ddb_handle->common.type != ACPI_TYPE_LOCAL_REFERENCE)) {
505 return_ACPI_STATUS(AE_BAD_PARAMETER); 505 return_ACPI_STATUS(AE_BAD_PARAMETER);
506 } 506 }
507 507
@@ -520,13 +520,14 @@ acpi_status acpi_ex_unload_table(union acpi_operand_object *ddb_handle)
520 } 520 }
521 } 521 }
522 522
523 /* 523 /* Delete the portion of the namespace owned by this table */
524 * Delete the entire namespace under this table Node 524
525 * (Offset contains the table_id) 525 status = acpi_tb_delete_namespace_by_owner(table_index);
526 */ 526 if (ACPI_FAILURE(status)) {
527 acpi_tb_delete_namespace_by_owner(table_index); 527 return_ACPI_STATUS(status);
528 (void)acpi_tb_release_owner_id(table_index); 528 }
529 529
530 (void)acpi_tb_release_owner_id(table_index);
530 acpi_tb_set_table_loaded_flag(table_index, FALSE); 531 acpi_tb_set_table_loaded_flag(table_index, FALSE);
531 532
532 /* Table unloaded, remove a reference to the ddb_handle object */ 533 /* Table unloaded, remove a reference to the ddb_handle object */
diff --git a/drivers/acpi/acpica/exconvrt.c b/drivers/acpi/acpica/exconvrt.c
index 0be10188316e..37d0d39e60a6 100644
--- a/drivers/acpi/acpica/exconvrt.c
+++ b/drivers/acpi/acpica/exconvrt.c
@@ -82,7 +82,7 @@ acpi_ex_convert_to_integer(union acpi_operand_object *obj_desc,
82 82
83 ACPI_FUNCTION_TRACE_PTR(ex_convert_to_integer, obj_desc); 83 ACPI_FUNCTION_TRACE_PTR(ex_convert_to_integer, obj_desc);
84 84
85 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) { 85 switch (obj_desc->common.type) {
86 case ACPI_TYPE_INTEGER: 86 case ACPI_TYPE_INTEGER:
87 87
88 /* No conversion necessary */ 88 /* No conversion necessary */
@@ -116,7 +116,7 @@ acpi_ex_convert_to_integer(union acpi_operand_object *obj_desc,
116 116
117 /* String conversion is different than Buffer conversion */ 117 /* String conversion is different than Buffer conversion */
118 118
119 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) { 119 switch (obj_desc->common.type) {
120 case ACPI_TYPE_STRING: 120 case ACPI_TYPE_STRING:
121 121
122 /* 122 /*
@@ -206,7 +206,7 @@ acpi_ex_convert_to_buffer(union acpi_operand_object *obj_desc,
206 206
207 ACPI_FUNCTION_TRACE_PTR(ex_convert_to_buffer, obj_desc); 207 ACPI_FUNCTION_TRACE_PTR(ex_convert_to_buffer, obj_desc);
208 208
209 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) { 209 switch (obj_desc->common.type) {
210 case ACPI_TYPE_BUFFER: 210 case ACPI_TYPE_BUFFER:
211 211
212 /* No conversion necessary */ 212 /* No conversion necessary */
@@ -409,7 +409,7 @@ acpi_ex_convert_to_string(union acpi_operand_object * obj_desc,
409 409
410 ACPI_FUNCTION_TRACE_PTR(ex_convert_to_string, obj_desc); 410 ACPI_FUNCTION_TRACE_PTR(ex_convert_to_string, obj_desc);
411 411
412 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) { 412 switch (obj_desc->common.type) {
413 case ACPI_TYPE_STRING: 413 case ACPI_TYPE_STRING:
414 414
415 /* No conversion necessary */ 415 /* No conversion necessary */
@@ -605,8 +605,7 @@ acpi_ex_convert_to_target_type(acpi_object_type destination_type,
605 default: 605 default:
606 /* No conversion allowed for these types */ 606 /* No conversion allowed for these types */
607 607
608 if (destination_type != 608 if (destination_type != source_desc->common.type) {
609 ACPI_GET_OBJECT_TYPE(source_desc)) {
610 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 609 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
611 "Explicit operator, will store (%s) over existing type (%s)\n", 610 "Explicit operator, will store (%s) over existing type (%s)\n",
612 acpi_ut_get_object_type_name 611 acpi_ut_get_object_type_name
diff --git a/drivers/acpi/acpica/exdump.c b/drivers/acpi/acpica/exdump.c
index aa313574b0df..89d141fdae0b 100644
--- a/drivers/acpi/acpica/exdump.c
+++ b/drivers/acpi/acpica/exdump.c
@@ -350,6 +350,7 @@ acpi_ex_dump_object(union acpi_operand_object *obj_desc,
350 break; 350 break;
351 351
352 case ACPI_EXD_TYPE: 352 case ACPI_EXD_TYPE:
353
353 acpi_ex_out_string("Type", 354 acpi_ex_out_string("Type",
354 acpi_ut_get_object_type_name 355 acpi_ut_get_object_type_name
355 (obj_desc)); 356 (obj_desc));
@@ -422,6 +423,7 @@ acpi_ex_dump_object(union acpi_operand_object *obj_desc,
422 break; 423 break;
423 424
424 default: 425 default:
426
425 acpi_os_printf("**** Invalid table opcode [%X] ****\n", 427 acpi_os_printf("**** Invalid table opcode [%X] ****\n",
426 info->opcode); 428 info->opcode);
427 return; 429 return;
@@ -492,7 +494,7 @@ void acpi_ex_dump_operand(union acpi_operand_object *obj_desc, u32 depth)
492 494
493 /* Decode object type */ 495 /* Decode object type */
494 496
495 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) { 497 switch (obj_desc->common.type) {
496 case ACPI_TYPE_LOCAL_REFERENCE: 498 case ACPI_TYPE_LOCAL_REFERENCE:
497 499
498 acpi_os_printf("Reference: [%s] ", 500 acpi_os_printf("Reference: [%s] ",
@@ -527,44 +529,16 @@ void acpi_ex_dump_operand(union acpi_operand_object *obj_desc, u32 depth)
527 type)); 529 type));
528 break; 530 break;
529 531
530 case ACPI_REFCLASS_ARG: 532 case ACPI_REFCLASS_NAME:
531
532 acpi_os_printf("%X", obj_desc->reference.value);
533
534 if (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_INTEGER) {
535
536 /* Value is an Integer */
537
538 acpi_os_printf(" value is [%8.8X%8.8x]",
539 ACPI_FORMAT_UINT64(obj_desc->
540 integer.
541 value));
542 }
543 533
544 acpi_os_printf("\n"); 534 acpi_os_printf("- [%4.4s]\n",
535 obj_desc->reference.node->name.ascii);
545 break; 536 break;
546 537
538 case ACPI_REFCLASS_ARG:
547 case ACPI_REFCLASS_LOCAL: 539 case ACPI_REFCLASS_LOCAL:
548 540
549 acpi_os_printf("%X", obj_desc->reference.value); 541 acpi_os_printf("%X\n", obj_desc->reference.value);
550
551 if (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_INTEGER) {
552
553 /* Value is an Integer */
554
555 acpi_os_printf(" value is [%8.8X%8.8x]",
556 ACPI_FORMAT_UINT64(obj_desc->
557 integer.
558 value));
559 }
560
561 acpi_os_printf("\n");
562 break;
563
564 case ACPI_REFCLASS_NAME:
565
566 acpi_os_printf("- [%4.4s]\n",
567 obj_desc->reference.node->name.ascii);
568 break; 542 break;
569 543
570 default: /* Unknown reference class */ 544 default: /* Unknown reference class */
@@ -661,8 +635,8 @@ void acpi_ex_dump_operand(union acpi_operand_object *obj_desc, u32 depth)
661 case ACPI_TYPE_LOCAL_REGION_FIELD: 635 case ACPI_TYPE_LOCAL_REGION_FIELD:
662 636
663 acpi_os_printf 637 acpi_os_printf
664 ("RegionField: Bits=%X AccWidth=%X Lock=%X Update=%X at byte=%X bit=%X of below:\n", 638 ("RegionField: Bits=%X AccWidth=%X Lock=%X Update=%X at "
665 obj_desc->field.bit_length, 639 "byte=%X bit=%X of below:\n", obj_desc->field.bit_length,
666 obj_desc->field.access_byte_width, 640 obj_desc->field.access_byte_width,
667 obj_desc->field.field_flags & AML_FIELD_LOCK_RULE_MASK, 641 obj_desc->field.field_flags & AML_FIELD_LOCK_RULE_MASK,
668 obj_desc->field.field_flags & AML_FIELD_UPDATE_RULE_MASK, 642 obj_desc->field.field_flags & AML_FIELD_UPDATE_RULE_MASK,
@@ -686,9 +660,8 @@ void acpi_ex_dump_operand(union acpi_operand_object *obj_desc, u32 depth)
686 660
687 if (!obj_desc->buffer_field.buffer_obj) { 661 if (!obj_desc->buffer_field.buffer_obj) {
688 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "*NULL*\n")); 662 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "*NULL*\n"));
689 } else 663 } else if ((obj_desc->buffer_field.buffer_obj)->common.type !=
690 if (ACPI_GET_OBJECT_TYPE(obj_desc->buffer_field.buffer_obj) 664 ACPI_TYPE_BUFFER) {
691 != ACPI_TYPE_BUFFER) {
692 acpi_os_printf("*not a Buffer*\n"); 665 acpi_os_printf("*not a Buffer*\n");
693 } else { 666 } else {
694 acpi_ex_dump_operand(obj_desc->buffer_field.buffer_obj, 667 acpi_ex_dump_operand(obj_desc->buffer_field.buffer_obj,
@@ -737,8 +710,7 @@ void acpi_ex_dump_operand(union acpi_operand_object *obj_desc, u32 depth)
737 default: 710 default:
738 /* Unknown Type */ 711 /* Unknown Type */
739 712
740 acpi_os_printf("Unknown Type %X\n", 713 acpi_os_printf("Unknown Type %X\n", obj_desc->common.type);
741 ACPI_GET_OBJECT_TYPE(obj_desc));
742 break; 714 break;
743 } 715 }
744 716
@@ -939,7 +911,7 @@ acpi_ex_dump_package_obj(union acpi_operand_object *obj_desc,
939 911
940 /* Packages may only contain a few object types */ 912 /* Packages may only contain a few object types */
941 913
942 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) { 914 switch (obj_desc->common.type) {
943 case ACPI_TYPE_INTEGER: 915 case ACPI_TYPE_INTEGER:
944 916
945 acpi_os_printf("[Integer] = %8.8X%8.8X\n", 917 acpi_os_printf("[Integer] = %8.8X%8.8X\n",
@@ -990,8 +962,7 @@ acpi_ex_dump_package_obj(union acpi_operand_object *obj_desc,
990 962
991 default: 963 default:
992 964
993 acpi_os_printf("[Unknown Type] %X\n", 965 acpi_os_printf("[Unknown Type] %X\n", obj_desc->common.type);
994 ACPI_GET_OBJECT_TYPE(obj_desc));
995 break; 966 break;
996 } 967 }
997} 968}
diff --git a/drivers/acpi/acpica/exfield.c b/drivers/acpi/acpica/exfield.c
index a352d0233857..546dcdd86785 100644
--- a/drivers/acpi/acpica/exfield.c
+++ b/drivers/acpi/acpica/exfield.c
@@ -84,7 +84,7 @@ acpi_ex_read_data_from_field(struct acpi_walk_state *walk_state,
84 return_ACPI_STATUS(AE_BAD_PARAMETER); 84 return_ACPI_STATUS(AE_BAD_PARAMETER);
85 } 85 }
86 86
87 if (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_BUFFER_FIELD) { 87 if (obj_desc->common.type == ACPI_TYPE_BUFFER_FIELD) {
88 /* 88 /*
89 * If the buffer_field arguments have not been previously evaluated, 89 * If the buffer_field arguments have not been previously evaluated,
90 * evaluate them now and save the results. 90 * evaluate them now and save the results.
@@ -95,9 +95,8 @@ acpi_ex_read_data_from_field(struct acpi_walk_state *walk_state,
95 return_ACPI_STATUS(status); 95 return_ACPI_STATUS(status);
96 } 96 }
97 } 97 }
98 } else 98 } else if ((obj_desc->common.type == ACPI_TYPE_LOCAL_REGION_FIELD) &&
99 if ((ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_LOCAL_REGION_FIELD) 99 (obj_desc->field.region_obj->region.space_id ==
100 && (obj_desc->field.region_obj->region.space_id ==
101 ACPI_ADR_SPACE_SMBUS)) { 100 ACPI_ADR_SPACE_SMBUS)) {
102 /* 101 /*
103 * This is an SMBus read. We must create a buffer to hold the data 102 * This is an SMBus read. We must create a buffer to hold the data
@@ -163,7 +162,7 @@ acpi_ex_read_data_from_field(struct acpi_walk_state *walk_state,
163 162
164 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, 163 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD,
165 "FieldRead [TO]: Obj %p, Type %X, Buf %p, ByteLen %X\n", 164 "FieldRead [TO]: Obj %p, Type %X, Buf %p, ByteLen %X\n",
166 obj_desc, ACPI_GET_OBJECT_TYPE(obj_desc), buffer, 165 obj_desc, obj_desc->common.type, buffer,
167 (u32) length)); 166 (u32) length));
168 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, 167 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD,
169 "FieldRead [FROM]: BitLen %X, BitOff %X, ByteOff %X\n", 168 "FieldRead [FROM]: BitLen %X, BitOff %X, ByteOff %X\n",
@@ -222,7 +221,7 @@ acpi_ex_write_data_to_field(union acpi_operand_object *source_desc,
222 return_ACPI_STATUS(AE_AML_NO_OPERAND); 221 return_ACPI_STATUS(AE_AML_NO_OPERAND);
223 } 222 }
224 223
225 if (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_BUFFER_FIELD) { 224 if (obj_desc->common.type == ACPI_TYPE_BUFFER_FIELD) {
226 /* 225 /*
227 * If the buffer_field arguments have not been previously evaluated, 226 * If the buffer_field arguments have not been previously evaluated,
228 * evaluate them now and save the results. 227 * evaluate them now and save the results.
@@ -233,9 +232,8 @@ acpi_ex_write_data_to_field(union acpi_operand_object *source_desc,
233 return_ACPI_STATUS(status); 232 return_ACPI_STATUS(status);
234 } 233 }
235 } 234 }
236 } else 235 } else if ((obj_desc->common.type == ACPI_TYPE_LOCAL_REGION_FIELD) &&
237 if ((ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_LOCAL_REGION_FIELD) 236 (obj_desc->field.region_obj->region.space_id ==
238 && (obj_desc->field.region_obj->region.space_id ==
239 ACPI_ADR_SPACE_SMBUS)) { 237 ACPI_ADR_SPACE_SMBUS)) {
240 /* 238 /*
241 * This is an SMBus write. We will bypass the entire field mechanism 239 * This is an SMBus write. We will bypass the entire field mechanism
@@ -243,7 +241,7 @@ acpi_ex_write_data_to_field(union acpi_operand_object *source_desc,
243 * 241 *
244 * Source must be a buffer of sufficient size (ACPI_SMBUS_BUFFER_SIZE). 242 * Source must be a buffer of sufficient size (ACPI_SMBUS_BUFFER_SIZE).
245 */ 243 */
246 if (ACPI_GET_OBJECT_TYPE(source_desc) != ACPI_TYPE_BUFFER) { 244 if (source_desc->common.type != ACPI_TYPE_BUFFER) {
247 ACPI_ERROR((AE_INFO, 245 ACPI_ERROR((AE_INFO,
248 "SMBus write requires Buffer, found type %s", 246 "SMBus write requires Buffer, found type %s",
249 acpi_ut_get_object_type_name(source_desc))); 247 acpi_ut_get_object_type_name(source_desc)));
@@ -291,7 +289,7 @@ acpi_ex_write_data_to_field(union acpi_operand_object *source_desc,
291 289
292 /* Get a pointer to the data to be written */ 290 /* Get a pointer to the data to be written */
293 291
294 switch (ACPI_GET_OBJECT_TYPE(source_desc)) { 292 switch (source_desc->common.type) {
295 case ACPI_TYPE_INTEGER: 293 case ACPI_TYPE_INTEGER:
296 buffer = &source_desc->integer.value; 294 buffer = &source_desc->integer.value;
297 length = sizeof(source_desc->integer.value); 295 length = sizeof(source_desc->integer.value);
@@ -314,15 +312,14 @@ acpi_ex_write_data_to_field(union acpi_operand_object *source_desc,
314 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, 312 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD,
315 "FieldWrite [FROM]: Obj %p (%s:%X), Buf %p, ByteLen %X\n", 313 "FieldWrite [FROM]: Obj %p (%s:%X), Buf %p, ByteLen %X\n",
316 source_desc, 314 source_desc,
317 acpi_ut_get_type_name(ACPI_GET_OBJECT_TYPE 315 acpi_ut_get_type_name(source_desc->common.type),
318 (source_desc)), 316 source_desc->common.type, buffer, length));
319 ACPI_GET_OBJECT_TYPE(source_desc), buffer, length));
320 317
321 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, 318 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD,
322 "FieldWrite [TO]: Obj %p (%s:%X), BitLen %X, BitOff %X, ByteOff %X\n", 319 "FieldWrite [TO]: Obj %p (%s:%X), BitLen %X, BitOff %X, ByteOff %X\n",
323 obj_desc, 320 obj_desc,
324 acpi_ut_get_type_name(ACPI_GET_OBJECT_TYPE(obj_desc)), 321 acpi_ut_get_type_name(obj_desc->common.type),
325 ACPI_GET_OBJECT_TYPE(obj_desc), 322 obj_desc->common.type,
326 obj_desc->common_field.bit_length, 323 obj_desc->common_field.bit_length,
327 obj_desc->common_field.start_field_bit_offset, 324 obj_desc->common_field.start_field_bit_offset,
328 obj_desc->common_field.base_byte_offset)); 325 obj_desc->common_field.base_byte_offset));
diff --git a/drivers/acpi/acpica/exfldio.c b/drivers/acpi/acpica/exfldio.c
index ef58ac4e687b..99cee61e655d 100644
--- a/drivers/acpi/acpica/exfldio.c
+++ b/drivers/acpi/acpica/exfldio.c
@@ -94,9 +94,9 @@ acpi_ex_setup_region(union acpi_operand_object *obj_desc,
94 94
95 /* We must have a valid region */ 95 /* We must have a valid region */
96 96
97 if (ACPI_GET_OBJECT_TYPE(rgn_desc) != ACPI_TYPE_REGION) { 97 if (rgn_desc->common.type != ACPI_TYPE_REGION) {
98 ACPI_ERROR((AE_INFO, "Needed Region, found type %X (%s)", 98 ACPI_ERROR((AE_INFO, "Needed Region, found type %X (%s)",
99 ACPI_GET_OBJECT_TYPE(rgn_desc), 99 rgn_desc->common.type,
100 acpi_ut_get_object_type_name(rgn_desc))); 100 acpi_ut_get_object_type_name(rgn_desc)));
101 101
102 return_ACPI_STATUS(AE_AML_OPERAND_TYPE); 102 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
@@ -113,12 +113,6 @@ acpi_ex_setup_region(union acpi_operand_object *obj_desc,
113 } 113 }
114 } 114 }
115 115
116 /* Exit if Address/Length have been disallowed by the host OS */
117
118 if (rgn_desc->common.flags & AOPOBJ_INVALID) {
119 return_ACPI_STATUS(AE_AML_ILLEGAL_ADDRESS);
120 }
121
122 /* 116 /*
123 * Exit now for SMBus address space, it has a non-linear address space 117 * Exit now for SMBus address space, it has a non-linear address space
124 * and the request cannot be directly validated 118 * and the request cannot be directly validated
@@ -390,7 +384,7 @@ acpi_ex_field_datum_io(union acpi_operand_object *obj_desc,
390 * index_field - Write to an Index Register, then read/write from/to a 384 * index_field - Write to an Index Register, then read/write from/to a
391 * Data Register 385 * Data Register
392 */ 386 */
393 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) { 387 switch (obj_desc->common.type) {
394 case ACPI_TYPE_BUFFER_FIELD: 388 case ACPI_TYPE_BUFFER_FIELD:
395 /* 389 /*
396 * If the buffer_field arguments have not been previously evaluated, 390 * If the buffer_field arguments have not been previously evaluated,
@@ -527,7 +521,7 @@ acpi_ex_field_datum_io(union acpi_operand_object *obj_desc,
527 default: 521 default:
528 522
529 ACPI_ERROR((AE_INFO, "Wrong object type in field I/O %X", 523 ACPI_ERROR((AE_INFO, "Wrong object type in field I/O %X",
530 ACPI_GET_OBJECT_TYPE(obj_desc))); 524 obj_desc->common.type));
531 status = AE_AML_INTERNAL; 525 status = AE_AML_INTERNAL;
532 break; 526 break;
533 } 527 }
diff --git a/drivers/acpi/acpica/exmisc.c b/drivers/acpi/acpica/exmisc.c
index 6b0747ac683b..998eac329937 100644
--- a/drivers/acpi/acpica/exmisc.c
+++ b/drivers/acpi/acpica/exmisc.c
@@ -80,7 +80,7 @@ acpi_ex_get_object_reference(union acpi_operand_object *obj_desc,
80 switch (ACPI_GET_DESCRIPTOR_TYPE(obj_desc)) { 80 switch (ACPI_GET_DESCRIPTOR_TYPE(obj_desc)) {
81 case ACPI_DESC_TYPE_OPERAND: 81 case ACPI_DESC_TYPE_OPERAND:
82 82
83 if (ACPI_GET_OBJECT_TYPE(obj_desc) != ACPI_TYPE_LOCAL_REFERENCE) { 83 if (obj_desc->common.type != ACPI_TYPE_LOCAL_REFERENCE) {
84 return_ACPI_STATUS(AE_AML_OPERAND_TYPE); 84 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
85 } 85 }
86 86
@@ -260,7 +260,7 @@ acpi_ex_do_concatenate(union acpi_operand_object *operand0,
260 * guaranteed to be either Integer/String/Buffer by the operand 260 * guaranteed to be either Integer/String/Buffer by the operand
261 * resolution mechanism. 261 * resolution mechanism.
262 */ 262 */
263 switch (ACPI_GET_OBJECT_TYPE(operand0)) { 263 switch (operand0->common.type) {
264 case ACPI_TYPE_INTEGER: 264 case ACPI_TYPE_INTEGER:
265 status = 265 status =
266 acpi_ex_convert_to_integer(operand1, &local_operand1, 16); 266 acpi_ex_convert_to_integer(operand1, &local_operand1, 16);
@@ -277,7 +277,7 @@ acpi_ex_do_concatenate(union acpi_operand_object *operand0,
277 277
278 default: 278 default:
279 ACPI_ERROR((AE_INFO, "Invalid object type: %X", 279 ACPI_ERROR((AE_INFO, "Invalid object type: %X",
280 ACPI_GET_OBJECT_TYPE(operand0))); 280 operand0->common.type));
281 status = AE_AML_INTERNAL; 281 status = AE_AML_INTERNAL;
282 } 282 }
283 283
@@ -298,7 +298,7 @@ acpi_ex_do_concatenate(union acpi_operand_object *operand0,
298 * 2) Two Strings concatenated to produce a new String 298 * 2) Two Strings concatenated to produce a new String
299 * 3) Two Buffers concatenated to produce a new Buffer 299 * 3) Two Buffers concatenated to produce a new Buffer
300 */ 300 */
301 switch (ACPI_GET_OBJECT_TYPE(operand0)) { 301 switch (operand0->common.type) {
302 case ACPI_TYPE_INTEGER: 302 case ACPI_TYPE_INTEGER:
303 303
304 /* Result of two Integers is a Buffer */ 304 /* Result of two Integers is a Buffer */
@@ -379,7 +379,7 @@ acpi_ex_do_concatenate(union acpi_operand_object *operand0,
379 /* Invalid object type, should not happen here */ 379 /* Invalid object type, should not happen here */
380 380
381 ACPI_ERROR((AE_INFO, "Invalid object type: %X", 381 ACPI_ERROR((AE_INFO, "Invalid object type: %X",
382 ACPI_GET_OBJECT_TYPE(operand0))); 382 operand0->common.type));
383 status = AE_AML_INTERNAL; 383 status = AE_AML_INTERNAL;
384 goto cleanup; 384 goto cleanup;
385 } 385 }
@@ -581,7 +581,7 @@ acpi_ex_do_logical_op(u16 opcode,
581 * guaranteed to be either Integer/String/Buffer by the operand 581 * guaranteed to be either Integer/String/Buffer by the operand
582 * resolution mechanism. 582 * resolution mechanism.
583 */ 583 */
584 switch (ACPI_GET_OBJECT_TYPE(operand0)) { 584 switch (operand0->common.type) {
585 case ACPI_TYPE_INTEGER: 585 case ACPI_TYPE_INTEGER:
586 status = 586 status =
587 acpi_ex_convert_to_integer(operand1, &local_operand1, 16); 587 acpi_ex_convert_to_integer(operand1, &local_operand1, 16);
@@ -608,7 +608,7 @@ acpi_ex_do_logical_op(u16 opcode,
608 /* 608 /*
609 * Two cases: 1) Both Integers, 2) Both Strings or Buffers 609 * Two cases: 1) Both Integers, 2) Both Strings or Buffers
610 */ 610 */
611 if (ACPI_GET_OBJECT_TYPE(operand0) == ACPI_TYPE_INTEGER) { 611 if (operand0->common.type == ACPI_TYPE_INTEGER) {
612 /* 612 /*
613 * 1) Both operands are of type integer 613 * 1) Both operands are of type integer
614 * Note: local_operand1 may have changed above 614 * Note: local_operand1 may have changed above
diff --git a/drivers/acpi/acpica/exoparg1.c b/drivers/acpi/acpica/exoparg1.c
index b530480cc7d5..9635d21e568d 100644
--- a/drivers/acpi/acpica/exoparg1.c
+++ b/drivers/acpi/acpica/exoparg1.c
@@ -807,11 +807,9 @@ acpi_status acpi_ex_opcode_1A_0T_1R(struct acpi_walk_state *walk_state)
807 acpi_namespace_node *) 807 acpi_namespace_node *)
808 operand[0]); 808 operand[0]);
809 if (temp_desc 809 if (temp_desc
810 && 810 && ((temp_desc->common.type == ACPI_TYPE_STRING)
811 ((ACPI_GET_OBJECT_TYPE(temp_desc) == 811 || (temp_desc->common.type ==
812 ACPI_TYPE_STRING) 812 ACPI_TYPE_LOCAL_REFERENCE))) {
813 || (ACPI_GET_OBJECT_TYPE(temp_desc) ==
814 ACPI_TYPE_LOCAL_REFERENCE))) {
815 operand[0] = temp_desc; 813 operand[0] = temp_desc;
816 acpi_ut_add_reference(temp_desc); 814 acpi_ut_add_reference(temp_desc);
817 } else { 815 } else {
@@ -819,7 +817,7 @@ acpi_status acpi_ex_opcode_1A_0T_1R(struct acpi_walk_state *walk_state)
819 goto cleanup; 817 goto cleanup;
820 } 818 }
821 } else { 819 } else {
822 switch (ACPI_GET_OBJECT_TYPE(operand[0])) { 820 switch ((operand[0])->common.type) {
823 case ACPI_TYPE_LOCAL_REFERENCE: 821 case ACPI_TYPE_LOCAL_REFERENCE:
824 /* 822 /*
825 * This is a deref_of (local_x | arg_x) 823 * This is a deref_of (local_x | arg_x)
@@ -877,8 +875,7 @@ acpi_status acpi_ex_opcode_1A_0T_1R(struct acpi_walk_state *walk_state)
877 875
878 if (ACPI_GET_DESCRIPTOR_TYPE(operand[0]) != 876 if (ACPI_GET_DESCRIPTOR_TYPE(operand[0]) !=
879 ACPI_DESC_TYPE_NAMED) { 877 ACPI_DESC_TYPE_NAMED) {
880 if (ACPI_GET_OBJECT_TYPE(operand[0]) == 878 if ((operand[0])->common.type == ACPI_TYPE_STRING) {
881 ACPI_TYPE_STRING) {
882 /* 879 /*
883 * This is a deref_of (String). The string is a reference 880 * This is a deref_of (String). The string is a reference
884 * to a named ACPI object. 881 * to a named ACPI object.
diff --git a/drivers/acpi/acpica/exoparg2.c b/drivers/acpi/acpica/exoparg2.c
index 0b4f513ca885..85d95c92dfd3 100644
--- a/drivers/acpi/acpica/exoparg2.c
+++ b/drivers/acpi/acpica/exoparg2.c
@@ -399,7 +399,7 @@ acpi_status acpi_ex_opcode_2A_1T_1R(struct acpi_walk_state *walk_state)
399 * At this point, the Source operand is a String, Buffer, or Package. 399 * At this point, the Source operand is a String, Buffer, or Package.
400 * Verify that the index is within range. 400 * Verify that the index is within range.
401 */ 401 */
402 switch (ACPI_GET_OBJECT_TYPE(operand[0])) { 402 switch ((operand[0])->common.type) {
403 case ACPI_TYPE_STRING: 403 case ACPI_TYPE_STRING:
404 404
405 if (index >= operand[0]->string.length) { 405 if (index >= operand[0]->string.length) {
diff --git a/drivers/acpi/acpica/exoparg3.c b/drivers/acpi/acpica/exoparg3.c
index c6520bbf882b..253f9e122584 100644
--- a/drivers/acpi/acpica/exoparg3.c
+++ b/drivers/acpi/acpica/exoparg3.c
@@ -161,9 +161,8 @@ acpi_status acpi_ex_opcode_3A_1T_1R(struct acpi_walk_state *walk_state)
161 * Create the return object. The Source operand is guaranteed to be 161 * Create the return object. The Source operand is guaranteed to be
162 * either a String or a Buffer, so just use its type. 162 * either a String or a Buffer, so just use its type.
163 */ 163 */
164 return_desc = 164 return_desc = acpi_ut_create_internal_object((operand[0])->
165 acpi_ut_create_internal_object(ACPI_GET_OBJECT_TYPE 165 common.type);
166 (operand[0]));
167 if (!return_desc) { 166 if (!return_desc) {
168 status = AE_NO_MEMORY; 167 status = AE_NO_MEMORY;
169 goto cleanup; 168 goto cleanup;
@@ -191,7 +190,7 @@ acpi_status acpi_ex_opcode_3A_1T_1R(struct acpi_walk_state *walk_state)
191 190
192 /* Strings always have a sub-pointer, not so for buffers */ 191 /* Strings always have a sub-pointer, not so for buffers */
193 192
194 switch (ACPI_GET_OBJECT_TYPE(operand[0])) { 193 switch ((operand[0])->common.type) {
195 case ACPI_TYPE_STRING: 194 case ACPI_TYPE_STRING:
196 195
197 /* Always allocate a new buffer for the String */ 196 /* Always allocate a new buffer for the String */
diff --git a/drivers/acpi/acpica/exprep.c b/drivers/acpi/acpica/exprep.c
index a226f74d4a5c..52fec07064f0 100644
--- a/drivers/acpi/acpica/exprep.c
+++ b/drivers/acpi/acpica/exprep.c
@@ -279,7 +279,7 @@ acpi_ex_decode_field_access(union acpi_operand_object *obj_desc,
279 return_UINT32(0); 279 return_UINT32(0);
280 } 280 }
281 281
282 if (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_BUFFER_FIELD) { 282 if (obj_desc->common.type == ACPI_TYPE_BUFFER_FIELD) {
283 /* 283 /*
284 * buffer_field access can be on any byte boundary, so the 284 * buffer_field access can be on any byte boundary, so the
285 * byte_alignment is always 1 byte -- regardless of any byte_alignment 285 * byte_alignment is always 1 byte -- regardless of any byte_alignment
diff --git a/drivers/acpi/acpica/exregion.c b/drivers/acpi/acpica/exregion.c
index 76ec8ff903b8..3a54b737d2da 100644
--- a/drivers/acpi/acpica/exregion.c
+++ b/drivers/acpi/acpica/exregion.c
@@ -294,14 +294,14 @@ acpi_ex_system_io_space_handler(u32 function,
294 switch (function) { 294 switch (function) {
295 case ACPI_READ: 295 case ACPI_READ:
296 296
297 status = acpi_os_read_port((acpi_io_address) address, 297 status = acpi_hw_read_port((acpi_io_address) address,
298 &value32, bit_width); 298 &value32, bit_width);
299 *value = value32; 299 *value = value32;
300 break; 300 break;
301 301
302 case ACPI_WRITE: 302 case ACPI_WRITE:
303 303
304 status = acpi_os_write_port((acpi_io_address) address, 304 status = acpi_hw_write_port((acpi_io_address) address,
305 (u32) * value, bit_width); 305 (u32) * value, bit_width);
306 break; 306 break;
307 307
diff --git a/drivers/acpi/acpica/exresnte.c b/drivers/acpi/acpica/exresnte.c
index a063a74006f6..607958ff467c 100644
--- a/drivers/acpi/acpica/exresnte.c
+++ b/drivers/acpi/acpica/exresnte.c
@@ -136,7 +136,7 @@ acpi_ex_resolve_node_to_value(struct acpi_namespace_node **object_ptr,
136 switch (entry_type) { 136 switch (entry_type) {
137 case ACPI_TYPE_PACKAGE: 137 case ACPI_TYPE_PACKAGE:
138 138
139 if (ACPI_GET_OBJECT_TYPE(source_desc) != ACPI_TYPE_PACKAGE) { 139 if (source_desc->common.type != ACPI_TYPE_PACKAGE) {
140 ACPI_ERROR((AE_INFO, "Object not a Package, type %s", 140 ACPI_ERROR((AE_INFO, "Object not a Package, type %s",
141 acpi_ut_get_object_type_name(source_desc))); 141 acpi_ut_get_object_type_name(source_desc)));
142 return_ACPI_STATUS(AE_AML_OPERAND_TYPE); 142 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
@@ -154,7 +154,7 @@ acpi_ex_resolve_node_to_value(struct acpi_namespace_node **object_ptr,
154 154
155 case ACPI_TYPE_BUFFER: 155 case ACPI_TYPE_BUFFER:
156 156
157 if (ACPI_GET_OBJECT_TYPE(source_desc) != ACPI_TYPE_BUFFER) { 157 if (source_desc->common.type != ACPI_TYPE_BUFFER) {
158 ACPI_ERROR((AE_INFO, "Object not a Buffer, type %s", 158 ACPI_ERROR((AE_INFO, "Object not a Buffer, type %s",
159 acpi_ut_get_object_type_name(source_desc))); 159 acpi_ut_get_object_type_name(source_desc)));
160 return_ACPI_STATUS(AE_AML_OPERAND_TYPE); 160 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
@@ -172,7 +172,7 @@ acpi_ex_resolve_node_to_value(struct acpi_namespace_node **object_ptr,
172 172
173 case ACPI_TYPE_STRING: 173 case ACPI_TYPE_STRING:
174 174
175 if (ACPI_GET_OBJECT_TYPE(source_desc) != ACPI_TYPE_STRING) { 175 if (source_desc->common.type != ACPI_TYPE_STRING) {
176 ACPI_ERROR((AE_INFO, "Object not a String, type %s", 176 ACPI_ERROR((AE_INFO, "Object not a String, type %s",
177 acpi_ut_get_object_type_name(source_desc))); 177 acpi_ut_get_object_type_name(source_desc)));
178 return_ACPI_STATUS(AE_AML_OPERAND_TYPE); 178 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
@@ -186,7 +186,7 @@ acpi_ex_resolve_node_to_value(struct acpi_namespace_node **object_ptr,
186 186
187 case ACPI_TYPE_INTEGER: 187 case ACPI_TYPE_INTEGER:
188 188
189 if (ACPI_GET_OBJECT_TYPE(source_desc) != ACPI_TYPE_INTEGER) { 189 if (source_desc->common.type != ACPI_TYPE_INTEGER) {
190 ACPI_ERROR((AE_INFO, "Object not a Integer, type %s", 190 ACPI_ERROR((AE_INFO, "Object not a Integer, type %s",
191 acpi_ut_get_object_type_name(source_desc))); 191 acpi_ut_get_object_type_name(source_desc)));
192 return_ACPI_STATUS(AE_AML_OPERAND_TYPE); 192 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
diff --git a/drivers/acpi/acpica/exresolv.c b/drivers/acpi/acpica/exresolv.c
index f6105a6d6126..c93b54ce7f78 100644
--- a/drivers/acpi/acpica/exresolv.c
+++ b/drivers/acpi/acpica/exresolv.c
@@ -149,7 +149,7 @@ acpi_ex_resolve_object_to_value(union acpi_operand_object **stack_ptr,
149 149
150 /* This is a union acpi_operand_object */ 150 /* This is a union acpi_operand_object */
151 151
152 switch (ACPI_GET_OBJECT_TYPE(stack_desc)) { 152 switch (stack_desc->common.type) {
153 case ACPI_TYPE_LOCAL_REFERENCE: 153 case ACPI_TYPE_LOCAL_REFERENCE:
154 154
155 ref_type = stack_desc->reference.class; 155 ref_type = stack_desc->reference.class;
@@ -297,8 +297,7 @@ acpi_ex_resolve_object_to_value(union acpi_operand_object **stack_ptr,
297 297
298 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, 298 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
299 "FieldRead SourceDesc=%p Type=%X\n", 299 "FieldRead SourceDesc=%p Type=%X\n",
300 stack_desc, 300 stack_desc, stack_desc->common.type));
301 ACPI_GET_OBJECT_TYPE(stack_desc)));
302 301
303 status = 302 status =
304 acpi_ex_read_data_from_field(walk_state, stack_desc, 303 acpi_ex_read_data_from_field(walk_state, stack_desc,
@@ -386,7 +385,7 @@ acpi_ex_resolve_multiple(struct acpi_walk_state *walk_state,
386 * specification of the object_type and size_of operators). This means 385 * specification of the object_type and size_of operators). This means
387 * traversing the list of possibly many nested references. 386 * traversing the list of possibly many nested references.
388 */ 387 */
389 while (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_LOCAL_REFERENCE) { 388 while (obj_desc->common.type == ACPI_TYPE_LOCAL_REFERENCE) {
390 switch (obj_desc->reference.class) { 389 switch (obj_desc->reference.class) {
391 case ACPI_REFCLASS_REFOF: 390 case ACPI_REFCLASS_REFOF:
392 case ACPI_REFCLASS_NAME: 391 case ACPI_REFCLASS_NAME:
@@ -518,7 +517,7 @@ acpi_ex_resolve_multiple(struct acpi_walk_state *walk_state,
518 * Now we are guaranteed to have an object that has not been created 517 * Now we are guaranteed to have an object that has not been created
519 * via the ref_of or Index operators. 518 * via the ref_of or Index operators.
520 */ 519 */
521 type = ACPI_GET_OBJECT_TYPE(obj_desc); 520 type = obj_desc->common.type;
522 521
523 exit: 522 exit:
524 /* Convert internal types to external types */ 523 /* Convert internal types to external types */
diff --git a/drivers/acpi/acpica/exresop.c b/drivers/acpi/acpica/exresop.c
index 3c3802764bfb..5c729a9e9131 100644
--- a/drivers/acpi/acpica/exresop.c
+++ b/drivers/acpi/acpica/exresop.c
@@ -212,7 +212,7 @@ acpi_ex_resolve_operands(u16 opcode,
212 212
213 /* ACPI internal object */ 213 /* ACPI internal object */
214 214
215 object_type = ACPI_GET_OBJECT_TYPE(obj_desc); 215 object_type = obj_desc->common.type;
216 216
217 /* Check for bad acpi_object_type */ 217 /* Check for bad acpi_object_type */
218 218
@@ -287,8 +287,7 @@ acpi_ex_resolve_operands(u16 opcode,
287 287
288 if ((ACPI_GET_DESCRIPTOR_TYPE(obj_desc) == 288 if ((ACPI_GET_DESCRIPTOR_TYPE(obj_desc) ==
289 ACPI_DESC_TYPE_OPERAND) 289 ACPI_DESC_TYPE_OPERAND)
290 && (ACPI_GET_OBJECT_TYPE(obj_desc) == 290 && (obj_desc->common.type == ACPI_TYPE_STRING)) {
291 ACPI_TYPE_STRING)) {
292 /* 291 /*
293 * String found - the string references a named object and 292 * String found - the string references a named object and
294 * must be resolved to a node 293 * must be resolved to a node
@@ -336,7 +335,7 @@ acpi_ex_resolve_operands(u16 opcode,
336 * -- All others must be resolved below. 335 * -- All others must be resolved below.
337 */ 336 */
338 if ((opcode == AML_STORE_OP) && 337 if ((opcode == AML_STORE_OP) &&
339 (ACPI_GET_OBJECT_TYPE(*stack_ptr) == 338 ((*stack_ptr)->common.type ==
340 ACPI_TYPE_LOCAL_REFERENCE) 339 ACPI_TYPE_LOCAL_REFERENCE)
341 && ((*stack_ptr)->reference.class == ACPI_REFCLASS_INDEX)) { 340 && ((*stack_ptr)->reference.class == ACPI_REFCLASS_INDEX)) {
342 goto next_operand; 341 goto next_operand;
@@ -490,7 +489,7 @@ acpi_ex_resolve_operands(u16 opcode,
490 489
491 /* Need an operand of type INTEGER, STRING or BUFFER */ 490 /* Need an operand of type INTEGER, STRING or BUFFER */
492 491
493 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) { 492 switch (obj_desc->common.type) {
494 case ACPI_TYPE_INTEGER: 493 case ACPI_TYPE_INTEGER:
495 case ACPI_TYPE_STRING: 494 case ACPI_TYPE_STRING:
496 case ACPI_TYPE_BUFFER: 495 case ACPI_TYPE_BUFFER:
@@ -512,7 +511,7 @@ acpi_ex_resolve_operands(u16 opcode,
512 511
513 /* Need an operand of type STRING or BUFFER */ 512 /* Need an operand of type STRING or BUFFER */
514 513
515 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) { 514 switch (obj_desc->common.type) {
516 case ACPI_TYPE_STRING: 515 case ACPI_TYPE_STRING:
517 case ACPI_TYPE_BUFFER: 516 case ACPI_TYPE_BUFFER:
518 517
@@ -553,7 +552,7 @@ acpi_ex_resolve_operands(u16 opcode,
553 * The only reference allowed here is a direct reference to 552 * The only reference allowed here is a direct reference to
554 * a namespace node. 553 * a namespace node.
555 */ 554 */
556 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) { 555 switch (obj_desc->common.type) {
557 case ACPI_TYPE_PACKAGE: 556 case ACPI_TYPE_PACKAGE:
558 case ACPI_TYPE_STRING: 557 case ACPI_TYPE_STRING:
559 case ACPI_TYPE_BUFFER: 558 case ACPI_TYPE_BUFFER:
@@ -576,7 +575,7 @@ acpi_ex_resolve_operands(u16 opcode,
576 575
577 /* Need a buffer or package or (ACPI 2.0) String */ 576 /* Need a buffer or package or (ACPI 2.0) String */
578 577
579 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) { 578 switch (obj_desc->common.type) {
580 case ACPI_TYPE_PACKAGE: 579 case ACPI_TYPE_PACKAGE:
581 case ACPI_TYPE_STRING: 580 case ACPI_TYPE_STRING:
582 case ACPI_TYPE_BUFFER: 581 case ACPI_TYPE_BUFFER:
@@ -598,7 +597,7 @@ acpi_ex_resolve_operands(u16 opcode,
598 597
599 /* Need an operand of type REGION or a BUFFER (which could be a resolved region field) */ 598 /* Need an operand of type REGION or a BUFFER (which could be a resolved region field) */
600 599
601 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) { 600 switch (obj_desc->common.type) {
602 case ACPI_TYPE_BUFFER: 601 case ACPI_TYPE_BUFFER:
603 case ACPI_TYPE_REGION: 602 case ACPI_TYPE_REGION:
604 603
@@ -619,7 +618,7 @@ acpi_ex_resolve_operands(u16 opcode,
619 618
620 /* Used by the Store() operator only */ 619 /* Used by the Store() operator only */
621 620
622 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) { 621 switch (obj_desc->common.type) {
623 case ACPI_TYPE_INTEGER: 622 case ACPI_TYPE_INTEGER:
624 case ACPI_TYPE_PACKAGE: 623 case ACPI_TYPE_PACKAGE:
625 case ACPI_TYPE_STRING: 624 case ACPI_TYPE_STRING:
@@ -677,8 +676,8 @@ acpi_ex_resolve_operands(u16 opcode,
677 * required object type (Simple cases only). 676 * required object type (Simple cases only).
678 */ 677 */
679 status = acpi_ex_check_object_type(type_needed, 678 status = acpi_ex_check_object_type(type_needed,
680 ACPI_GET_OBJECT_TYPE 679 (*stack_ptr)->common.type,
681 (*stack_ptr), *stack_ptr); 680 *stack_ptr);
682 if (ACPI_FAILURE(status)) { 681 if (ACPI_FAILURE(status)) {
683 return_ACPI_STATUS(status); 682 return_ACPI_STATUS(status);
684 } 683 }
diff --git a/drivers/acpi/acpica/exstore.c b/drivers/acpi/acpica/exstore.c
index e35e9b4f6a4e..90d606196c99 100644
--- a/drivers/acpi/acpica/exstore.c
+++ b/drivers/acpi/acpica/exstore.c
@@ -129,7 +129,7 @@ acpi_ex_do_debug_object(union acpi_operand_object *source_desc,
129 129
130 /* source_desc is of type ACPI_DESC_TYPE_OPERAND */ 130 /* source_desc is of type ACPI_DESC_TYPE_OPERAND */
131 131
132 switch (ACPI_GET_OBJECT_TYPE(source_desc)) { 132 switch (source_desc->common.type) {
133 case ACPI_TYPE_INTEGER: 133 case ACPI_TYPE_INTEGER:
134 134
135 /* Output correct integer width */ 135 /* Output correct integer width */
@@ -324,7 +324,7 @@ acpi_ex_store(union acpi_operand_object *source_desc,
324 324
325 /* Destination object must be a Reference or a Constant object */ 325 /* Destination object must be a Reference or a Constant object */
326 326
327 switch (ACPI_GET_OBJECT_TYPE(dest_desc)) { 327 switch (dest_desc->common.type) {
328 case ACPI_TYPE_LOCAL_REFERENCE: 328 case ACPI_TYPE_LOCAL_REFERENCE:
329 break; 329 break;
330 330
@@ -460,9 +460,8 @@ acpi_ex_store_object_to_index(union acpi_operand_object *source_desc,
460 */ 460 */
461 obj_desc = *(index_desc->reference.where); 461 obj_desc = *(index_desc->reference.where);
462 462
463 if (ACPI_GET_OBJECT_TYPE(source_desc) == 463 if (source_desc->common.type == ACPI_TYPE_LOCAL_REFERENCE &&
464 ACPI_TYPE_LOCAL_REFERENCE 464 source_desc->reference.class == ACPI_REFCLASS_TABLE) {
465 && source_desc->reference.class == ACPI_REFCLASS_TABLE) {
466 465
467 /* This is a DDBHandle, just add a reference to it */ 466 /* This is a DDBHandle, just add a reference to it */
468 467
@@ -520,8 +519,8 @@ acpi_ex_store_object_to_index(union acpi_operand_object *source_desc,
520 * by the INDEX_OP code. 519 * by the INDEX_OP code.
521 */ 520 */
522 obj_desc = index_desc->reference.object; 521 obj_desc = index_desc->reference.object;
523 if ((ACPI_GET_OBJECT_TYPE(obj_desc) != ACPI_TYPE_BUFFER) && 522 if ((obj_desc->common.type != ACPI_TYPE_BUFFER) &&
524 (ACPI_GET_OBJECT_TYPE(obj_desc) != ACPI_TYPE_STRING)) { 523 (obj_desc->common.type != ACPI_TYPE_STRING)) {
525 return_ACPI_STATUS(AE_AML_OPERAND_TYPE); 524 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
526 } 525 }
527 526
@@ -529,7 +528,7 @@ acpi_ex_store_object_to_index(union acpi_operand_object *source_desc,
529 * The assignment of the individual elements will be slightly 528 * The assignment of the individual elements will be slightly
530 * different for each source type. 529 * different for each source type.
531 */ 530 */
532 switch (ACPI_GET_OBJECT_TYPE(source_desc)) { 531 switch (source_desc->common.type) {
533 case ACPI_TYPE_INTEGER: 532 case ACPI_TYPE_INTEGER:
534 533
535 /* Use the least-significant byte of the integer */ 534 /* Use the least-significant byte of the integer */
@@ -707,8 +706,7 @@ acpi_ex_store_object_to_node(union acpi_operand_object *source_desc,
707 /* No conversions for all other types. Just attach the source object */ 706 /* No conversions for all other types. Just attach the source object */
708 707
709 status = acpi_ns_attach_object(node, source_desc, 708 status = acpi_ns_attach_object(node, source_desc,
710 ACPI_GET_OBJECT_TYPE 709 source_desc->common.type);
711 (source_desc));
712 break; 710 break;
713 } 711 }
714 712
diff --git a/drivers/acpi/acpica/exstoren.c b/drivers/acpi/acpica/exstoren.c
index 145d15305f70..608e838d537e 100644
--- a/drivers/acpi/acpica/exstoren.c
+++ b/drivers/acpi/acpica/exstoren.c
@@ -96,8 +96,7 @@ acpi_ex_resolve_object(union acpi_operand_object **source_desc_ptr,
96 * are all essentially the same. This case handles the 96 * are all essentially the same. This case handles the
97 * "interchangeable" types Integer, String, and Buffer. 97 * "interchangeable" types Integer, String, and Buffer.
98 */ 98 */
99 if (ACPI_GET_OBJECT_TYPE(source_desc) == 99 if (source_desc->common.type == ACPI_TYPE_LOCAL_REFERENCE) {
100 ACPI_TYPE_LOCAL_REFERENCE) {
101 100
102 /* Resolve a reference object first */ 101 /* Resolve a reference object first */
103 102
@@ -117,13 +116,11 @@ acpi_ex_resolve_object(union acpi_operand_object **source_desc_ptr,
117 116
118 /* Must have a Integer, Buffer, or String */ 117 /* Must have a Integer, Buffer, or String */
119 118
120 if ((ACPI_GET_OBJECT_TYPE(source_desc) != ACPI_TYPE_INTEGER) && 119 if ((source_desc->common.type != ACPI_TYPE_INTEGER) &&
121 (ACPI_GET_OBJECT_TYPE(source_desc) != ACPI_TYPE_BUFFER) && 120 (source_desc->common.type != ACPI_TYPE_BUFFER) &&
122 (ACPI_GET_OBJECT_TYPE(source_desc) != ACPI_TYPE_STRING) && 121 (source_desc->common.type != ACPI_TYPE_STRING) &&
123 !((ACPI_GET_OBJECT_TYPE(source_desc) == 122 !((source_desc->common.type == ACPI_TYPE_LOCAL_REFERENCE) &&
124 ACPI_TYPE_LOCAL_REFERENCE) 123 (source_desc->reference.class == ACPI_REFCLASS_TABLE))) {
125 && (source_desc->reference.class ==
126 ACPI_REFCLASS_TABLE))) {
127 124
128 /* Conversion successful but still not a valid type */ 125 /* Conversion successful but still not a valid type */
129 126
@@ -218,8 +215,7 @@ acpi_ex_store_object_to_object(union acpi_operand_object *source_desc,
218 return_ACPI_STATUS(status); 215 return_ACPI_STATUS(status);
219 } 216 }
220 217
221 if (ACPI_GET_OBJECT_TYPE(source_desc) != 218 if (source_desc->common.type != dest_desc->common.type) {
222 ACPI_GET_OBJECT_TYPE(dest_desc)) {
223 /* 219 /*
224 * The source type does not match the type of the destination. 220 * The source type does not match the type of the destination.
225 * Perform the "implicit conversion" of the source to the current type 221 * Perform the "implicit conversion" of the source to the current type
@@ -229,11 +225,10 @@ acpi_ex_store_object_to_object(union acpi_operand_object *source_desc,
229 * Otherwise, actual_src_desc is a temporary object to hold the 225 * Otherwise, actual_src_desc is a temporary object to hold the
230 * converted object. 226 * converted object.
231 */ 227 */
232 status = 228 status = acpi_ex_convert_to_target_type(dest_desc->common.type,
233 acpi_ex_convert_to_target_type(ACPI_GET_OBJECT_TYPE 229 source_desc,
234 (dest_desc), source_desc, 230 &actual_src_desc,
235 &actual_src_desc, 231 walk_state);
236 walk_state);
237 if (ACPI_FAILURE(status)) { 232 if (ACPI_FAILURE(status)) {
238 return_ACPI_STATUS(status); 233 return_ACPI_STATUS(status);
239 } 234 }
@@ -252,7 +247,7 @@ acpi_ex_store_object_to_object(union acpi_operand_object *source_desc,
252 * We now have two objects of identical types, and we can perform a 247 * We now have two objects of identical types, and we can perform a
253 * copy of the *value* of the source object. 248 * copy of the *value* of the source object.
254 */ 249 */
255 switch (ACPI_GET_OBJECT_TYPE(dest_desc)) { 250 switch (dest_desc->common.type) {
256 case ACPI_TYPE_INTEGER: 251 case ACPI_TYPE_INTEGER:
257 252
258 dest_desc->integer.value = actual_src_desc->integer.value; 253 dest_desc->integer.value = actual_src_desc->integer.value;
diff --git a/drivers/acpi/acpica/exutils.c b/drivers/acpi/acpica/exutils.c
index 32b85d68e756..87730e944132 100644
--- a/drivers/acpi/acpica/exutils.c
+++ b/drivers/acpi/acpica/exutils.c
@@ -221,7 +221,7 @@ void acpi_ex_truncate_for32bit_table(union acpi_operand_object *obj_desc)
221 */ 221 */
222 if ((!obj_desc) || 222 if ((!obj_desc) ||
223 (ACPI_GET_DESCRIPTOR_TYPE(obj_desc) != ACPI_DESC_TYPE_OPERAND) || 223 (ACPI_GET_DESCRIPTOR_TYPE(obj_desc) != ACPI_DESC_TYPE_OPERAND) ||
224 (ACPI_GET_OBJECT_TYPE(obj_desc) != ACPI_TYPE_INTEGER)) { 224 (obj_desc->common.type != ACPI_TYPE_INTEGER)) {
225 return; 225 return;
226 } 226 }
227 227
diff --git a/drivers/acpi/acpica/hwacpi.c b/drivers/acpi/acpica/hwacpi.c
index a9d4fea4167f..9af361a191e7 100644
--- a/drivers/acpi/acpica/hwacpi.c
+++ b/drivers/acpi/acpica/hwacpi.c
@@ -86,7 +86,8 @@ acpi_status acpi_hw_set_mode(u32 mode)
86 */ 86 */
87 if (!acpi_gbl_FADT.acpi_enable && !acpi_gbl_FADT.acpi_disable) { 87 if (!acpi_gbl_FADT.acpi_enable && !acpi_gbl_FADT.acpi_disable) {
88 ACPI_ERROR((AE_INFO, 88 ACPI_ERROR((AE_INFO,
89 "No ACPI mode transition supported in this system (enable/disable both zero)")); 89 "No ACPI mode transition supported in this system "
90 "(enable/disable both zero)"));
90 return_ACPI_STATUS(AE_OK); 91 return_ACPI_STATUS(AE_OK);
91 } 92 }
92 93
@@ -95,7 +96,7 @@ acpi_status acpi_hw_set_mode(u32 mode)
95 96
96 /* BIOS should have disabled ALL fixed and GP events */ 97 /* BIOS should have disabled ALL fixed and GP events */
97 98
98 status = acpi_os_write_port(acpi_gbl_FADT.smi_command, 99 status = acpi_hw_write_port(acpi_gbl_FADT.smi_command,
99 (u32) acpi_gbl_FADT.acpi_enable, 8); 100 (u32) acpi_gbl_FADT.acpi_enable, 8);
100 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 101 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
101 "Attempting to enable ACPI mode\n")); 102 "Attempting to enable ACPI mode\n"));
@@ -107,7 +108,7 @@ acpi_status acpi_hw_set_mode(u32 mode)
107 * BIOS should clear all fixed status bits and restore fixed event 108 * BIOS should clear all fixed status bits and restore fixed event
108 * enable bits to default 109 * enable bits to default
109 */ 110 */
110 status = acpi_os_write_port(acpi_gbl_FADT.smi_command, 111 status = acpi_hw_write_port(acpi_gbl_FADT.smi_command,
111 (u32) acpi_gbl_FADT.acpi_disable, 112 (u32) acpi_gbl_FADT.acpi_disable,
112 8); 113 8);
113 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 114 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
@@ -172,7 +173,7 @@ u32 acpi_hw_get_mode(void)
172 return_UINT32(ACPI_SYS_MODE_ACPI); 173 return_UINT32(ACPI_SYS_MODE_ACPI);
173 } 174 }
174 175
175 status = acpi_get_register(ACPI_BITREG_SCI_ENABLE, &value); 176 status = acpi_read_bit_register(ACPI_BITREG_SCI_ENABLE, &value);
176 if (ACPI_FAILURE(status)) { 177 if (ACPI_FAILURE(status)) {
177 return_UINT32(ACPI_SYS_MODE_LEGACY); 178 return_UINT32(ACPI_SYS_MODE_LEGACY);
178 } 179 }
diff --git a/drivers/acpi/acpica/hwgpe.c b/drivers/acpi/acpica/hwgpe.c
index 2013b66745d2..d3b7e37c9eed 100644
--- a/drivers/acpi/acpica/hwgpe.c
+++ b/drivers/acpi/acpica/hwgpe.c
@@ -89,10 +89,9 @@ acpi_status acpi_hw_low_disable_gpe(struct acpi_gpe_event_info *gpe_event_info)
89 89
90 /* Clear just the bit that corresponds to this GPE */ 90 /* Clear just the bit that corresponds to this GPE */
91 91
92 ACPI_CLEAR_BIT(enable_mask, 92 ACPI_CLEAR_BIT(enable_mask, ((u32)1 <<
93 ((u32) 1 << 93 (gpe_event_info->gpe_number -
94 (gpe_event_info->gpe_number - 94 gpe_register_info->base_gpe_number)));
95 gpe_register_info->base_gpe_number)));
96 95
97 /* Write the updated enable mask */ 96 /* Write the updated enable mask */
98 97
@@ -156,10 +155,9 @@ acpi_status acpi_hw_clear_gpe(struct acpi_gpe_event_info * gpe_event_info)
156 155
157 ACPI_FUNCTION_ENTRY(); 156 ACPI_FUNCTION_ENTRY();
158 157
159 register_bit = (u8) 158 register_bit = (u8)(1 <<
160 (1 << 159 (gpe_event_info->gpe_number -
161 (gpe_event_info->gpe_number - 160 gpe_event_info->register_info->base_gpe_number));
162 gpe_event_info->register_info->base_gpe_number));
163 161
164 /* 162 /*
165 * Write a one to the appropriate bit in the status register to 163 * Write a one to the appropriate bit in the status register to
@@ -206,10 +204,9 @@ acpi_hw_get_gpe_status(struct acpi_gpe_event_info * gpe_event_info,
206 204
207 /* Get the register bitmask for this GPE */ 205 /* Get the register bitmask for this GPE */
208 206
209 register_bit = (u8) 207 register_bit = (u8)(1 <<
210 (1 << 208 (gpe_event_info->gpe_number -
211 (gpe_event_info->gpe_number - 209 gpe_event_info->register_info->base_gpe_number));
212 gpe_event_info->register_info->base_gpe_number));
213 210
214 /* GPE currently enabled? (enabled for runtime?) */ 211 /* GPE currently enabled? (enabled for runtime?) */
215 212
diff --git a/drivers/acpi/acpica/hwregs.c b/drivers/acpi/acpica/hwregs.c
index 4dc43b018517..7b2fb602b5cb 100644
--- a/drivers/acpi/acpica/hwregs.c
+++ b/drivers/acpi/acpica/hwregs.c
@@ -51,6 +51,17 @@
51#define _COMPONENT ACPI_HARDWARE 51#define _COMPONENT ACPI_HARDWARE
52ACPI_MODULE_NAME("hwregs") 52ACPI_MODULE_NAME("hwregs")
53 53
54/* Local Prototypes */
55static acpi_status
56acpi_hw_read_multiple(u32 *value,
57 struct acpi_generic_address *register_a,
58 struct acpi_generic_address *register_b);
59
60static acpi_status
61acpi_hw_write_multiple(u32 value,
62 struct acpi_generic_address *register_a,
63 struct acpi_generic_address *register_b);
64
54/******************************************************************************* 65/*******************************************************************************
55 * 66 *
56 * FUNCTION: acpi_hw_clear_acpi_status 67 * FUNCTION: acpi_hw_clear_acpi_status
@@ -60,9 +71,9 @@ ACPI_MODULE_NAME("hwregs")
60 * RETURN: Status 71 * RETURN: Status
61 * 72 *
62 * DESCRIPTION: Clears all fixed and general purpose status bits 73 * DESCRIPTION: Clears all fixed and general purpose status bits
63 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED
64 * 74 *
65 ******************************************************************************/ 75 ******************************************************************************/
76
66acpi_status acpi_hw_clear_acpi_status(void) 77acpi_status acpi_hw_clear_acpi_status(void)
67{ 78{
68 acpi_status status; 79 acpi_status status;
@@ -70,28 +81,20 @@ acpi_status acpi_hw_clear_acpi_status(void)
70 81
71 ACPI_FUNCTION_TRACE(hw_clear_acpi_status); 82 ACPI_FUNCTION_TRACE(hw_clear_acpi_status);
72 83
73 ACPI_DEBUG_PRINT((ACPI_DB_IO, "About to write %04X to %04X\n", 84 ACPI_DEBUG_PRINT((ACPI_DB_IO, "About to write %04X to %0llX\n",
74 ACPI_BITMASK_ALL_FIXED_STATUS, 85 ACPI_BITMASK_ALL_FIXED_STATUS,
75 (u16) acpi_gbl_FADT.xpm1a_event_block.address)); 86 acpi_gbl_xpm1a_status.address));
76 87
77 lock_flags = acpi_os_acquire_lock(acpi_gbl_hardware_lock); 88 lock_flags = acpi_os_acquire_lock(acpi_gbl_hardware_lock);
78 89
90 /* Clear the fixed events in PM1 A/B */
91
79 status = acpi_hw_register_write(ACPI_REGISTER_PM1_STATUS, 92 status = acpi_hw_register_write(ACPI_REGISTER_PM1_STATUS,
80 ACPI_BITMASK_ALL_FIXED_STATUS); 93 ACPI_BITMASK_ALL_FIXED_STATUS);
81 if (ACPI_FAILURE(status)) { 94 if (ACPI_FAILURE(status)) {
82 goto unlock_and_exit; 95 goto unlock_and_exit;
83 } 96 }
84 97
85 /* Clear the fixed events */
86
87 if (acpi_gbl_FADT.xpm1b_event_block.address) {
88 status = acpi_write(ACPI_BITMASK_ALL_FIXED_STATUS,
89 &acpi_gbl_FADT.xpm1b_event_block);
90 if (ACPI_FAILURE(status)) {
91 goto unlock_and_exit;
92 }
93 }
94
95 /* Clear the GPE Bits in all GPE registers in all GPE blocks */ 98 /* Clear the GPE Bits in all GPE registers in all GPE blocks */
96 99
97 status = acpi_ev_walk_gpe_list(acpi_hw_clear_gpe_block, NULL); 100 status = acpi_ev_walk_gpe_list(acpi_hw_clear_gpe_block, NULL);
@@ -128,6 +131,42 @@ struct acpi_bit_register_info *acpi_hw_get_bit_register_info(u32 register_id)
128 131
129/****************************************************************************** 132/******************************************************************************
130 * 133 *
134 * FUNCTION: acpi_hw_write_pm1_control
135 *
136 * PARAMETERS: pm1a_control - Value to be written to PM1A control
137 * pm1b_control - Value to be written to PM1B control
138 *
139 * RETURN: Status
140 *
141 * DESCRIPTION: Write the PM1 A/B control registers. These registers are
142 * different than than the PM1 A/B status and enable registers
143 * in that different values can be written to the A/B registers.
144 * Most notably, the SLP_TYP bits can be different, as per the
145 * values returned from the _Sx predefined methods.
146 *
147 ******************************************************************************/
148
149acpi_status acpi_hw_write_pm1_control(u32 pm1a_control, u32 pm1b_control)
150{
151 acpi_status status;
152
153 ACPI_FUNCTION_TRACE(hw_write_pm1_control);
154
155 status = acpi_write(pm1a_control, &acpi_gbl_FADT.xpm1a_control_block);
156 if (ACPI_FAILURE(status)) {
157 return_ACPI_STATUS(status);
158 }
159
160 if (acpi_gbl_FADT.xpm1b_control_block.address) {
161 status =
162 acpi_write(pm1b_control,
163 &acpi_gbl_FADT.xpm1b_control_block);
164 }
165 return_ACPI_STATUS(status);
166}
167
168/******************************************************************************
169 *
131 * FUNCTION: acpi_hw_register_read 170 * FUNCTION: acpi_hw_register_read
132 * 171 *
133 * PARAMETERS: register_id - ACPI Register ID 172 * PARAMETERS: register_id - ACPI Register ID
@@ -141,64 +180,56 @@ struct acpi_bit_register_info *acpi_hw_get_bit_register_info(u32 register_id)
141acpi_status 180acpi_status
142acpi_hw_register_read(u32 register_id, u32 * return_value) 181acpi_hw_register_read(u32 register_id, u32 * return_value)
143{ 182{
144 u32 value1 = 0; 183 u32 value = 0;
145 u32 value2 = 0;
146 acpi_status status; 184 acpi_status status;
147 185
148 ACPI_FUNCTION_TRACE(hw_register_read); 186 ACPI_FUNCTION_TRACE(hw_register_read);
149 187
150 switch (register_id) { 188 switch (register_id) {
151 case ACPI_REGISTER_PM1_STATUS: /* 16-bit access */ 189 case ACPI_REGISTER_PM1_STATUS: /* PM1 A/B: 16-bit access each */
152
153 status = acpi_read(&value1, &acpi_gbl_FADT.xpm1a_event_block);
154 if (ACPI_FAILURE(status)) {
155 goto exit;
156 }
157
158 /* PM1B is optional */
159 190
160 status = acpi_read(&value2, &acpi_gbl_FADT.xpm1b_event_block); 191 status = acpi_hw_read_multiple(&value,
161 value1 |= value2; 192 &acpi_gbl_xpm1a_status,
193 &acpi_gbl_xpm1b_status);
162 break; 194 break;
163 195
164 case ACPI_REGISTER_PM1_ENABLE: /* 16-bit access */ 196 case ACPI_REGISTER_PM1_ENABLE: /* PM1 A/B: 16-bit access each */
165 197
166 status = acpi_read(&value1, &acpi_gbl_xpm1a_enable); 198 status = acpi_hw_read_multiple(&value,
167 if (ACPI_FAILURE(status)) { 199 &acpi_gbl_xpm1a_enable,
168 goto exit; 200 &acpi_gbl_xpm1b_enable);
169 }
170
171 /* PM1B is optional */
172
173 status = acpi_read(&value2, &acpi_gbl_xpm1b_enable);
174 value1 |= value2;
175 break; 201 break;
176 202
177 case ACPI_REGISTER_PM1_CONTROL: /* 16-bit access */ 203 case ACPI_REGISTER_PM1_CONTROL: /* PM1 A/B: 16-bit access each */
178 204
179 status = acpi_read(&value1, &acpi_gbl_FADT.xpm1a_control_block); 205 status = acpi_hw_read_multiple(&value,
180 if (ACPI_FAILURE(status)) { 206 &acpi_gbl_FADT.
181 goto exit; 207 xpm1a_control_block,
182 } 208 &acpi_gbl_FADT.
209 xpm1b_control_block);
183 210
184 status = acpi_read(&value2, &acpi_gbl_FADT.xpm1b_control_block); 211 /*
185 value1 |= value2; 212 * Zero the write-only bits. From the ACPI specification, "Hardware
213 * Write-Only Bits": "Upon reads to registers with write-only bits,
214 * software masks out all write-only bits."
215 */
216 value &= ~ACPI_PM1_CONTROL_WRITEONLY_BITS;
186 break; 217 break;
187 218
188 case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */ 219 case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */
189 220
190 status = acpi_read(&value1, &acpi_gbl_FADT.xpm2_control_block); 221 status = acpi_read(&value, &acpi_gbl_FADT.xpm2_control_block);
191 break; 222 break;
192 223
193 case ACPI_REGISTER_PM_TIMER: /* 32-bit access */ 224 case ACPI_REGISTER_PM_TIMER: /* 32-bit access */
194 225
195 status = acpi_read(&value1, &acpi_gbl_FADT.xpm_timer_block); 226 status = acpi_read(&value, &acpi_gbl_FADT.xpm_timer_block);
196 break; 227 break;
197 228
198 case ACPI_REGISTER_SMI_COMMAND_BLOCK: /* 8-bit access */ 229 case ACPI_REGISTER_SMI_COMMAND_BLOCK: /* 8-bit access */
199 230
200 status = 231 status =
201 acpi_os_read_port(acpi_gbl_FADT.smi_command, &value1, 8); 232 acpi_hw_read_port(acpi_gbl_FADT.smi_command, &value, 8);
202 break; 233 break;
203 234
204 default: 235 default:
@@ -207,10 +238,8 @@ acpi_hw_register_read(u32 register_id, u32 * return_value)
207 break; 238 break;
208 } 239 }
209 240
210 exit:
211
212 if (ACPI_SUCCESS(status)) { 241 if (ACPI_SUCCESS(status)) {
213 *return_value = value1; 242 *return_value = value;
214 } 243 }
215 244
216 return_ACPI_STATUS(status); 245 return_ACPI_STATUS(status);
@@ -250,52 +279,42 @@ acpi_status acpi_hw_register_write(u32 register_id, u32 value)
250 ACPI_FUNCTION_TRACE(hw_register_write); 279 ACPI_FUNCTION_TRACE(hw_register_write);
251 280
252 switch (register_id) { 281 switch (register_id) {
253 case ACPI_REGISTER_PM1_STATUS: /* 16-bit access */ 282 case ACPI_REGISTER_PM1_STATUS: /* PM1 A/B: 16-bit access each */
254 283 /*
255 /* Perform a read first to preserve certain bits (per ACPI spec) */ 284 * Handle the "ignored" bit in PM1 Status. According to the ACPI
256 285 * specification, ignored bits are to be preserved when writing.
257 status = acpi_hw_register_read(ACPI_REGISTER_PM1_STATUS, 286 * Normally, this would mean a read/modify/write sequence. However,
258 &read_value); 287 * preserving a bit in the status register is different. Writing a
259 if (ACPI_FAILURE(status)) { 288 * one clears the status, and writing a zero preserves the status.
260 goto exit; 289 * Therefore, we must always write zero to the ignored bit.
261 } 290 *
262 291 * This behavior is clarified in the ACPI 4.0 specification.
263 /* Insert the bits to be preserved */ 292 */
264 293 value &= ~ACPI_PM1_STATUS_PRESERVED_BITS;
265 ACPI_INSERT_BITS(value, ACPI_PM1_STATUS_PRESERVED_BITS,
266 read_value);
267
268 /* Now we can write the data */
269
270 status = acpi_write(value, &acpi_gbl_FADT.xpm1a_event_block);
271 if (ACPI_FAILURE(status)) {
272 goto exit;
273 }
274
275 /* PM1B is optional */
276 294
277 status = acpi_write(value, &acpi_gbl_FADT.xpm1b_event_block); 295 status = acpi_hw_write_multiple(value,
296 &acpi_gbl_xpm1a_status,
297 &acpi_gbl_xpm1b_status);
278 break; 298 break;
279 299
280 case ACPI_REGISTER_PM1_ENABLE: /* 16-bit access */ 300 case ACPI_REGISTER_PM1_ENABLE: /* PM1 A/B: 16-bit access */
281 301
282 status = acpi_write(value, &acpi_gbl_xpm1a_enable); 302 status = acpi_hw_write_multiple(value,
283 if (ACPI_FAILURE(status)) { 303 &acpi_gbl_xpm1a_enable,
284 goto exit; 304 &acpi_gbl_xpm1b_enable);
285 }
286
287 /* PM1B is optional */
288
289 status = acpi_write(value, &acpi_gbl_xpm1b_enable);
290 break; 305 break;
291 306
292 case ACPI_REGISTER_PM1_CONTROL: /* 16-bit access */ 307 case ACPI_REGISTER_PM1_CONTROL: /* PM1 A/B: 16-bit access each */
293 308
294 /* 309 /*
295 * Perform a read first to preserve certain bits (per ACPI spec) 310 * Perform a read first to preserve certain bits (per ACPI spec)
311 * Note: This includes SCI_EN, we never want to change this bit
296 */ 312 */
297 status = acpi_hw_register_read(ACPI_REGISTER_PM1_CONTROL, 313 status = acpi_hw_read_multiple(&read_value,
298 &read_value); 314 &acpi_gbl_FADT.
315 xpm1a_control_block,
316 &acpi_gbl_FADT.
317 xpm1b_control_block);
299 if (ACPI_FAILURE(status)) { 318 if (ACPI_FAILURE(status)) {
300 goto exit; 319 goto exit;
301 } 320 }
@@ -307,25 +326,29 @@ acpi_status acpi_hw_register_write(u32 register_id, u32 value)
307 326
308 /* Now we can write the data */ 327 /* Now we can write the data */
309 328
310 status = acpi_write(value, &acpi_gbl_FADT.xpm1a_control_block); 329 status = acpi_hw_write_multiple(value,
311 if (ACPI_FAILURE(status)) { 330 &acpi_gbl_FADT.
312 goto exit; 331 xpm1a_control_block,
313 } 332 &acpi_gbl_FADT.
314 333 xpm1b_control_block);
315 status = acpi_write(value, &acpi_gbl_FADT.xpm1b_control_block);
316 break; 334 break;
317 335
318 case ACPI_REGISTER_PM1A_CONTROL: /* 16-bit access */ 336 case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */
319
320 status = acpi_write(value, &acpi_gbl_FADT.xpm1a_control_block);
321 break;
322 337
323 case ACPI_REGISTER_PM1B_CONTROL: /* 16-bit access */ 338 /*
339 * For control registers, all reserved bits must be preserved,
340 * as per the ACPI spec.
341 */
342 status =
343 acpi_read(&read_value, &acpi_gbl_FADT.xpm2_control_block);
344 if (ACPI_FAILURE(status)) {
345 goto exit;
346 }
324 347
325 status = acpi_write(value, &acpi_gbl_FADT.xpm1b_control_block); 348 /* Insert the bits to be preserved */
326 break;
327 349
328 case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */ 350 ACPI_INSERT_BITS(value, ACPI_PM2_CONTROL_PRESERVED_BITS,
351 read_value);
329 352
330 status = acpi_write(value, &acpi_gbl_FADT.xpm2_control_block); 353 status = acpi_write(value, &acpi_gbl_FADT.xpm2_control_block);
331 break; 354 break;
@@ -340,10 +363,11 @@ acpi_status acpi_hw_register_write(u32 register_id, u32 value)
340 /* SMI_CMD is currently always in IO space */ 363 /* SMI_CMD is currently always in IO space */
341 364
342 status = 365 status =
343 acpi_os_write_port(acpi_gbl_FADT.smi_command, value, 8); 366 acpi_hw_write_port(acpi_gbl_FADT.smi_command, value, 8);
344 break; 367 break;
345 368
346 default: 369 default:
370 ACPI_ERROR((AE_INFO, "Unknown Register ID: %X", register_id));
347 status = AE_BAD_PARAMETER; 371 status = AE_BAD_PARAMETER;
348 break; 372 break;
349 } 373 }
@@ -351,3 +375,103 @@ acpi_status acpi_hw_register_write(u32 register_id, u32 value)
351 exit: 375 exit:
352 return_ACPI_STATUS(status); 376 return_ACPI_STATUS(status);
353} 377}
378
379/******************************************************************************
380 *
381 * FUNCTION: acpi_hw_read_multiple
382 *
383 * PARAMETERS: Value - Where the register value is returned
384 * register_a - First ACPI register (required)
385 * register_b - Second ACPI register (optional)
386 *
387 * RETURN: Status
388 *
389 * DESCRIPTION: Read from the specified two-part ACPI register (such as PM1 A/B)
390 *
391 ******************************************************************************/
392
393static acpi_status
394acpi_hw_read_multiple(u32 *value,
395 struct acpi_generic_address *register_a,
396 struct acpi_generic_address *register_b)
397{
398 u32 value_a = 0;
399 u32 value_b = 0;
400 acpi_status status;
401
402 /* The first register is always required */
403
404 status = acpi_read(&value_a, register_a);
405 if (ACPI_FAILURE(status)) {
406 return (status);
407 }
408
409 /* Second register is optional */
410
411 if (register_b->address) {
412 status = acpi_read(&value_b, register_b);
413 if (ACPI_FAILURE(status)) {
414 return (status);
415 }
416 }
417
418 /*
419 * OR the two return values together. No shifting or masking is necessary,
420 * because of how the PM1 registers are defined in the ACPI specification:
421 *
422 * "Although the bits can be split between the two register blocks (each
423 * register block has a unique pointer within the FADT), the bit positions
424 * are maintained. The register block with unimplemented bits (that is,
425 * those implemented in the other register block) always returns zeros,
426 * and writes have no side effects"
427 */
428 *value = (value_a | value_b);
429 return (AE_OK);
430}
431
432/******************************************************************************
433 *
434 * FUNCTION: acpi_hw_write_multiple
435 *
436 * PARAMETERS: Value - The value to write
437 * register_a - First ACPI register (required)
438 * register_b - Second ACPI register (optional)
439 *
440 * RETURN: Status
441 *
442 * DESCRIPTION: Write to the specified two-part ACPI register (such as PM1 A/B)
443 *
444 ******************************************************************************/
445
446static acpi_status
447acpi_hw_write_multiple(u32 value,
448 struct acpi_generic_address *register_a,
449 struct acpi_generic_address *register_b)
450{
451 acpi_status status;
452
453 /* The first register is always required */
454
455 status = acpi_write(value, register_a);
456 if (ACPI_FAILURE(status)) {
457 return (status);
458 }
459
460 /*
461 * Second register is optional
462 *
463 * No bit shifting or clearing is necessary, because of how the PM1
464 * registers are defined in the ACPI specification:
465 *
466 * "Although the bits can be split between the two register blocks (each
467 * register block has a unique pointer within the FADT), the bit positions
468 * are maintained. The register block with unimplemented bits (that is,
469 * those implemented in the other register block) always returns zeros,
470 * and writes have no side effects"
471 */
472 if (register_b->address) {
473 status = acpi_write(value, register_b);
474 }
475
476 return (status);
477}
diff --git a/drivers/acpi/acpica/hwsleep.c b/drivers/acpi/acpica/hwsleep.c
index a2af2a4f2f26..db307a356f08 100644
--- a/drivers/acpi/acpica/hwsleep.c
+++ b/drivers/acpi/acpica/hwsleep.c
@@ -90,6 +90,7 @@ acpi_set_firmware_waking_vector(u32 physical_address)
90 90
91ACPI_EXPORT_SYMBOL(acpi_set_firmware_waking_vector) 91ACPI_EXPORT_SYMBOL(acpi_set_firmware_waking_vector)
92 92
93#if ACPI_MACHINE_WIDTH == 64
93/******************************************************************************* 94/*******************************************************************************
94 * 95 *
95 * FUNCTION: acpi_set_firmware_waking_vector64 96 * FUNCTION: acpi_set_firmware_waking_vector64
@@ -100,7 +101,8 @@ ACPI_EXPORT_SYMBOL(acpi_set_firmware_waking_vector)
100 * RETURN: Status 101 * RETURN: Status
101 * 102 *
102 * DESCRIPTION: Sets the 64-bit X_firmware_waking_vector field of the FACS, if 103 * DESCRIPTION: Sets the 64-bit X_firmware_waking_vector field of the FACS, if
103 * it exists in the table. 104 * it exists in the table. This function is intended for use with
105 * 64-bit host operating systems.
104 * 106 *
105 ******************************************************************************/ 107 ******************************************************************************/
106acpi_status 108acpi_status
@@ -124,6 +126,7 @@ acpi_set_firmware_waking_vector64(u64 physical_address)
124} 126}
125 127
126ACPI_EXPORT_SYMBOL(acpi_set_firmware_waking_vector64) 128ACPI_EXPORT_SYMBOL(acpi_set_firmware_waking_vector64)
129#endif
127 130
128/******************************************************************************* 131/*******************************************************************************
129 * 132 *
@@ -147,9 +150,8 @@ acpi_status acpi_enter_sleep_state_prep(u8 sleep_state)
147 150
148 ACPI_FUNCTION_TRACE(acpi_enter_sleep_state_prep); 151 ACPI_FUNCTION_TRACE(acpi_enter_sleep_state_prep);
149 152
150 /* 153 /* _PSW methods could be run here to enable wake-on keyboard, LAN, etc. */
151 * _PSW methods could be run here to enable wake-on keyboard, LAN, etc. 154
152 */
153 status = acpi_get_sleep_type_data(sleep_state, 155 status = acpi_get_sleep_type_data(sleep_state,
154 &acpi_gbl_sleep_type_a, 156 &acpi_gbl_sleep_type_a,
155 &acpi_gbl_sleep_type_b); 157 &acpi_gbl_sleep_type_b);
@@ -209,6 +211,12 @@ acpi_status acpi_enter_sleep_state_prep(u8 sleep_state)
209 211
210ACPI_EXPORT_SYMBOL(acpi_enter_sleep_state_prep) 212ACPI_EXPORT_SYMBOL(acpi_enter_sleep_state_prep)
211 213
214static unsigned int gts, bfs;
215module_param(gts, uint, 0644);
216module_param(bfs, uint, 0644);
217MODULE_PARM_DESC(gts, "Enable evaluation of _GTS on suspend.");
218MODULE_PARM_DESC(bfs, "Enable evaluation of _BFS on resume".);
219
212/******************************************************************************* 220/*******************************************************************************
213 * 221 *
214 * FUNCTION: acpi_enter_sleep_state 222 * FUNCTION: acpi_enter_sleep_state
@@ -223,8 +231,8 @@ ACPI_EXPORT_SYMBOL(acpi_enter_sleep_state_prep)
223 ******************************************************************************/ 231 ******************************************************************************/
224acpi_status asmlinkage acpi_enter_sleep_state(u8 sleep_state) 232acpi_status asmlinkage acpi_enter_sleep_state(u8 sleep_state)
225{ 233{
226 u32 PM1Acontrol; 234 u32 pm1a_control;
227 u32 PM1Bcontrol; 235 u32 pm1b_control;
228 struct acpi_bit_register_info *sleep_type_reg_info; 236 struct acpi_bit_register_info *sleep_type_reg_info;
229 struct acpi_bit_register_info *sleep_enable_reg_info; 237 struct acpi_bit_register_info *sleep_enable_reg_info;
230 u32 in_value; 238 u32 in_value;
@@ -242,13 +250,14 @@ acpi_status asmlinkage acpi_enter_sleep_state(u8 sleep_state)
242 } 250 }
243 251
244 sleep_type_reg_info = 252 sleep_type_reg_info =
245 acpi_hw_get_bit_register_info(ACPI_BITREG_SLEEP_TYPE_A); 253 acpi_hw_get_bit_register_info(ACPI_BITREG_SLEEP_TYPE);
246 sleep_enable_reg_info = 254 sleep_enable_reg_info =
247 acpi_hw_get_bit_register_info(ACPI_BITREG_SLEEP_ENABLE); 255 acpi_hw_get_bit_register_info(ACPI_BITREG_SLEEP_ENABLE);
248 256
249 /* Clear wake status */ 257 /* Clear wake status */
250 258
251 status = acpi_set_register(ACPI_BITREG_WAKE_STATUS, 1); 259 status =
260 acpi_write_bit_register(ACPI_BITREG_WAKE_STATUS, ACPI_CLEAR_STATUS);
252 if (ACPI_FAILURE(status)) { 261 if (ACPI_FAILURE(status)) {
253 return_ACPI_STATUS(status); 262 return_ACPI_STATUS(status);
254 } 263 }
@@ -275,38 +284,41 @@ acpi_status asmlinkage acpi_enter_sleep_state(u8 sleep_state)
275 return_ACPI_STATUS(status); 284 return_ACPI_STATUS(status);
276 } 285 }
277 286
278 /* Execute the _GTS method */ 287 if (gts) {
288 /* Execute the _GTS method */
279 289
280 arg_list.count = 1; 290 arg_list.count = 1;
281 arg_list.pointer = &arg; 291 arg_list.pointer = &arg;
282 arg.type = ACPI_TYPE_INTEGER; 292 arg.type = ACPI_TYPE_INTEGER;
283 arg.integer.value = sleep_state; 293 arg.integer.value = sleep_state;
284 294
285 status = acpi_evaluate_object(NULL, METHOD_NAME__GTS, &arg_list, NULL); 295 status = acpi_evaluate_object(NULL, METHOD_NAME__GTS, &arg_list, NULL);
286 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { 296 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
287 return_ACPI_STATUS(status); 297 return_ACPI_STATUS(status);
298 }
288 } 299 }
289 300
290 /* Get current value of PM1A control */ 301 /* Get current value of PM1A control */
291 302
292 status = acpi_hw_register_read(ACPI_REGISTER_PM1_CONTROL, &PM1Acontrol); 303 status = acpi_hw_register_read(ACPI_REGISTER_PM1_CONTROL,
304 &pm1a_control);
293 if (ACPI_FAILURE(status)) { 305 if (ACPI_FAILURE(status)) {
294 return_ACPI_STATUS(status); 306 return_ACPI_STATUS(status);
295 } 307 }
296 ACPI_DEBUG_PRINT((ACPI_DB_INIT, 308 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
297 "Entering sleep state [S%d]\n", sleep_state)); 309 "Entering sleep state [S%d]\n", sleep_state));
298 310
299 /* Clear SLP_EN and SLP_TYP fields */ 311 /* Clear the SLP_EN and SLP_TYP fields */
300 312
301 PM1Acontrol &= ~(sleep_type_reg_info->access_bit_mask | 313 pm1a_control &= ~(sleep_type_reg_info->access_bit_mask |
302 sleep_enable_reg_info->access_bit_mask); 314 sleep_enable_reg_info->access_bit_mask);
303 PM1Bcontrol = PM1Acontrol; 315 pm1b_control = pm1a_control;
304 316
305 /* Insert SLP_TYP bits */ 317 /* Insert the SLP_TYP bits */
306 318
307 PM1Acontrol |= 319 pm1a_control |=
308 (acpi_gbl_sleep_type_a << sleep_type_reg_info->bit_position); 320 (acpi_gbl_sleep_type_a << sleep_type_reg_info->bit_position);
309 PM1Bcontrol |= 321 pm1b_control |=
310 (acpi_gbl_sleep_type_b << sleep_type_reg_info->bit_position); 322 (acpi_gbl_sleep_type_b << sleep_type_reg_info->bit_position);
311 323
312 /* 324 /*
@@ -314,37 +326,25 @@ acpi_status asmlinkage acpi_enter_sleep_state(u8 sleep_state)
314 * poorly implemented hardware. 326 * poorly implemented hardware.
315 */ 327 */
316 328
317 /* Write #1: fill in SLP_TYP data */ 329 /* Write #1: write the SLP_TYP data to the PM1 Control registers */
318 330
319 status = acpi_hw_register_write(ACPI_REGISTER_PM1A_CONTROL, 331 status = acpi_hw_write_pm1_control(pm1a_control, pm1b_control);
320 PM1Acontrol);
321 if (ACPI_FAILURE(status)) { 332 if (ACPI_FAILURE(status)) {
322 return_ACPI_STATUS(status); 333 return_ACPI_STATUS(status);
323 } 334 }
324 335
325 status = acpi_hw_register_write(ACPI_REGISTER_PM1B_CONTROL, 336 /* Insert the sleep enable (SLP_EN) bit */
326 PM1Bcontrol);
327 if (ACPI_FAILURE(status)) {
328 return_ACPI_STATUS(status);
329 }
330
331 /* Insert SLP_ENABLE bit */
332 337
333 PM1Acontrol |= sleep_enable_reg_info->access_bit_mask; 338 pm1a_control |= sleep_enable_reg_info->access_bit_mask;
334 PM1Bcontrol |= sleep_enable_reg_info->access_bit_mask; 339 pm1b_control |= sleep_enable_reg_info->access_bit_mask;
335 340
336 /* Write #2: SLP_TYP + SLP_EN */ 341 /* Flush caches, as per ACPI specification */
337 342
338 ACPI_FLUSH_CPU_CACHE(); 343 ACPI_FLUSH_CPU_CACHE();
339 344
340 status = acpi_hw_register_write(ACPI_REGISTER_PM1A_CONTROL, 345 /* Write #2: Write both SLP_TYP + SLP_EN */
341 PM1Acontrol);
342 if (ACPI_FAILURE(status)) {
343 return_ACPI_STATUS(status);
344 }
345 346
346 status = acpi_hw_register_write(ACPI_REGISTER_PM1B_CONTROL, 347 status = acpi_hw_write_pm1_control(pm1a_control, pm1b_control);
347 PM1Bcontrol);
348 if (ACPI_FAILURE(status)) { 348 if (ACPI_FAILURE(status)) {
349 return_ACPI_STATUS(status); 349 return_ACPI_STATUS(status);
350 } 350 }
@@ -357,8 +357,8 @@ acpi_status asmlinkage acpi_enter_sleep_state(u8 sleep_state)
357 * Wait ten seconds, then try again. This is to get S4/S5 to work on 357 * Wait ten seconds, then try again. This is to get S4/S5 to work on
358 * all machines. 358 * all machines.
359 * 359 *
360 * We wait so long to allow chipsets that poll this reg very slowly to 360 * We wait so long to allow chipsets that poll this reg very slowly
361 * still read the right value. Ideally, this block would go 361 * to still read the right value. Ideally, this block would go
362 * away entirely. 362 * away entirely.
363 */ 363 */
364 acpi_os_stall(10000000); 364 acpi_os_stall(10000000);
@@ -374,7 +374,7 @@ acpi_status asmlinkage acpi_enter_sleep_state(u8 sleep_state)
374 /* Wait until we enter sleep state */ 374 /* Wait until we enter sleep state */
375 375
376 do { 376 do {
377 status = acpi_get_register_unlocked(ACPI_BITREG_WAKE_STATUS, 377 status = acpi_read_bit_register(ACPI_BITREG_WAKE_STATUS,
378 &in_value); 378 &in_value);
379 if (ACPI_FAILURE(status)) { 379 if (ACPI_FAILURE(status)) {
380 return_ACPI_STATUS(status); 380 return_ACPI_STATUS(status);
@@ -408,7 +408,10 @@ acpi_status asmlinkage acpi_enter_sleep_state_s4bios(void)
408 408
409 ACPI_FUNCTION_TRACE(acpi_enter_sleep_state_s4bios); 409 ACPI_FUNCTION_TRACE(acpi_enter_sleep_state_s4bios);
410 410
411 status = acpi_set_register(ACPI_BITREG_WAKE_STATUS, 1); 411 /* Clear the wake status bit (PM1) */
412
413 status =
414 acpi_write_bit_register(ACPI_BITREG_WAKE_STATUS, ACPI_CLEAR_STATUS);
412 if (ACPI_FAILURE(status)) { 415 if (ACPI_FAILURE(status)) {
413 return_ACPI_STATUS(status); 416 return_ACPI_STATUS(status);
414 } 417 }
@@ -435,12 +438,13 @@ acpi_status asmlinkage acpi_enter_sleep_state_s4bios(void)
435 438
436 ACPI_FLUSH_CPU_CACHE(); 439 ACPI_FLUSH_CPU_CACHE();
437 440
438 status = acpi_os_write_port(acpi_gbl_FADT.smi_command, 441 status = acpi_hw_write_port(acpi_gbl_FADT.smi_command,
439 (u32) acpi_gbl_FADT.S4bios_request, 8); 442 (u32) acpi_gbl_FADT.S4bios_request, 8);
440 443
441 do { 444 do {
442 acpi_os_stall(1000); 445 acpi_os_stall(1000);
443 status = acpi_get_register(ACPI_BITREG_WAKE_STATUS, &in_value); 446 status =
447 acpi_read_bit_register(ACPI_BITREG_WAKE_STATUS, &in_value);
444 if (ACPI_FAILURE(status)) { 448 if (ACPI_FAILURE(status)) {
445 return_ACPI_STATUS(status); 449 return_ACPI_STATUS(status);
446 } 450 }
@@ -471,8 +475,8 @@ acpi_status acpi_leave_sleep_state_prep(u8 sleep_state)
471 acpi_status status; 475 acpi_status status;
472 struct acpi_bit_register_info *sleep_type_reg_info; 476 struct acpi_bit_register_info *sleep_type_reg_info;
473 struct acpi_bit_register_info *sleep_enable_reg_info; 477 struct acpi_bit_register_info *sleep_enable_reg_info;
474 u32 PM1Acontrol; 478 u32 pm1a_control;
475 u32 PM1Bcontrol; 479 u32 pm1b_control;
476 480
477 ACPI_FUNCTION_TRACE(acpi_leave_sleep_state_prep); 481 ACPI_FUNCTION_TRACE(acpi_leave_sleep_state_prep);
478 482
@@ -486,53 +490,50 @@ acpi_status acpi_leave_sleep_state_prep(u8 sleep_state)
486 &acpi_gbl_sleep_type_b); 490 &acpi_gbl_sleep_type_b);
487 if (ACPI_SUCCESS(status)) { 491 if (ACPI_SUCCESS(status)) {
488 sleep_type_reg_info = 492 sleep_type_reg_info =
489 acpi_hw_get_bit_register_info(ACPI_BITREG_SLEEP_TYPE_A); 493 acpi_hw_get_bit_register_info(ACPI_BITREG_SLEEP_TYPE);
490 sleep_enable_reg_info = 494 sleep_enable_reg_info =
491 acpi_hw_get_bit_register_info(ACPI_BITREG_SLEEP_ENABLE); 495 acpi_hw_get_bit_register_info(ACPI_BITREG_SLEEP_ENABLE);
492 496
493 /* Get current value of PM1A control */ 497 /* Get current value of PM1A control */
494 498
495 status = acpi_hw_register_read(ACPI_REGISTER_PM1_CONTROL, 499 status = acpi_hw_register_read(ACPI_REGISTER_PM1_CONTROL,
496 &PM1Acontrol); 500 &pm1a_control);
497 if (ACPI_SUCCESS(status)) { 501 if (ACPI_SUCCESS(status)) {
498 502
499 /* Clear SLP_EN and SLP_TYP fields */ 503 /* Clear the SLP_EN and SLP_TYP fields */
500 504
501 PM1Acontrol &= ~(sleep_type_reg_info->access_bit_mask | 505 pm1a_control &= ~(sleep_type_reg_info->access_bit_mask |
502 sleep_enable_reg_info-> 506 sleep_enable_reg_info->
503 access_bit_mask); 507 access_bit_mask);
504 PM1Bcontrol = PM1Acontrol; 508 pm1b_control = pm1a_control;
505 509
506 /* Insert SLP_TYP bits */ 510 /* Insert the SLP_TYP bits */
507 511
508 PM1Acontrol |= 512 pm1a_control |= (acpi_gbl_sleep_type_a <<
509 (acpi_gbl_sleep_type_a << sleep_type_reg_info-> 513 sleep_type_reg_info->bit_position);
510 bit_position); 514 pm1b_control |= (acpi_gbl_sleep_type_b <<
511 PM1Bcontrol |= 515 sleep_type_reg_info->bit_position);
512 (acpi_gbl_sleep_type_b << sleep_type_reg_info->
513 bit_position);
514 516
515 /* Just ignore any errors */ 517 /* Write the control registers and ignore any errors */
516 518
517 (void)acpi_hw_register_write(ACPI_REGISTER_PM1A_CONTROL, 519 (void)acpi_hw_write_pm1_control(pm1a_control,
518 PM1Acontrol); 520 pm1b_control);
519 (void)acpi_hw_register_write(ACPI_REGISTER_PM1B_CONTROL,
520 PM1Bcontrol);
521 } 521 }
522 } 522 }
523 523
524 /* Execute the _BFS method */ 524 if (bfs) {
525 /* Execute the _BFS method */
525 526
526 arg_list.count = 1; 527 arg_list.count = 1;
527 arg_list.pointer = &arg; 528 arg_list.pointer = &arg;
528 arg.type = ACPI_TYPE_INTEGER; 529 arg.type = ACPI_TYPE_INTEGER;
529 arg.integer.value = sleep_state; 530 arg.integer.value = sleep_state;
530 531
531 status = acpi_evaluate_object(NULL, METHOD_NAME__BFS, &arg_list, NULL); 532 status = acpi_evaluate_object(NULL, METHOD_NAME__BFS, &arg_list, NULL);
532 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { 533 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
533 ACPI_EXCEPTION((AE_INFO, status, "During Method _BFS")); 534 ACPI_EXCEPTION((AE_INFO, status, "During Method _BFS"));
535 }
534 } 536 }
535
536 return_ACPI_STATUS(status); 537 return_ACPI_STATUS(status);
537} 538}
538 539
@@ -603,19 +604,21 @@ acpi_status acpi_leave_sleep_state(u8 sleep_state)
603 * it to determine whether the system is rebooting or resuming. Clear 604 * it to determine whether the system is rebooting or resuming. Clear
604 * it for compatibility. 605 * it for compatibility.
605 */ 606 */
606 acpi_set_register(ACPI_BITREG_WAKE_STATUS, 1); 607 acpi_write_bit_register(ACPI_BITREG_WAKE_STATUS, 1);
607 608
608 acpi_gbl_system_awake_and_running = TRUE; 609 acpi_gbl_system_awake_and_running = TRUE;
609 610
610 /* Enable power button */ 611 /* Enable power button */
611 612
612 (void) 613 (void)
613 acpi_set_register(acpi_gbl_fixed_event_info 614 acpi_write_bit_register(acpi_gbl_fixed_event_info
614 [ACPI_EVENT_POWER_BUTTON].enable_register_id, 1); 615 [ACPI_EVENT_POWER_BUTTON].
616 enable_register_id, ACPI_ENABLE_EVENT);
615 617
616 (void) 618 (void)
617 acpi_set_register(acpi_gbl_fixed_event_info 619 acpi_write_bit_register(acpi_gbl_fixed_event_info
618 [ACPI_EVENT_POWER_BUTTON].status_register_id, 1); 620 [ACPI_EVENT_POWER_BUTTON].
621 status_register_id, ACPI_CLEAR_STATUS);
619 622
620 arg.integer.value = ACPI_SST_WORKING; 623 arg.integer.value = ACPI_SST_WORKING;
621 status = acpi_evaluate_object(NULL, METHOD_NAME__SST, &arg_list, NULL); 624 status = acpi_evaluate_object(NULL, METHOD_NAME__SST, &arg_list, NULL);
diff --git a/drivers/acpi/acpica/hwvalid.c b/drivers/acpi/acpica/hwvalid.c
new file mode 100644
index 000000000000..ec33f270c5b7
--- /dev/null
+++ b/drivers/acpi/acpica/hwvalid.c
@@ -0,0 +1,315 @@
1
2/******************************************************************************
3 *
4 * Module Name: hwvalid - I/O request validation
5 *
6 *****************************************************************************/
7
8/*
9 * Copyright (C) 2000 - 2009, Intel Corp.
10 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
23 * 3. Neither the names of the above-listed copyright holders nor the names
24 * of any contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL") version 2 as published by the Free
29 * Software Foundation.
30 *
31 * NO WARRANTY
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGES.
43 */
44
45#include <acpi/acpi.h>
46#include "accommon.h"
47
48#define _COMPONENT ACPI_HARDWARE
49ACPI_MODULE_NAME("hwvalid")
50
51/* Local prototypes */
52static acpi_status
53acpi_hw_validate_io_request(acpi_io_address address, u32 bit_width);
54
55/*
56 * Protected I/O ports. Some ports are always illegal, and some are
57 * conditionally illegal. This table must remain ordered by port address.
58 *
59 * The table is used to implement the Microsoft port access rules that
60 * first appeared in Windows XP. Some ports are always illegal, and some
61 * ports are only illegal if the BIOS calls _OSI with a win_xP string or
62 * later (meaning that the BIOS itelf is post-XP.)
63 *
64 * This provides ACPICA with the desired port protections and
65 * Microsoft compatibility.
66 *
67 * Description of port entries:
68 * DMA: DMA controller
69 * PIC0: Programmable Interrupt Controller (8259_a)
70 * PIT1: System Timer 1
71 * PIT2: System Timer 2 failsafe
72 * RTC: Real-time clock
73 * CMOS: Extended CMOS
74 * DMA1: DMA 1 page registers
75 * DMA1L: DMA 1 Ch 0 low page
76 * DMA2: DMA 2 page registers
77 * DMA2L: DMA 2 low page refresh
78 * ARBC: Arbitration control
79 * SETUP: Reserved system board setup
80 * POS: POS channel select
81 * PIC1: Cascaded PIC
82 * IDMA: ISA DMA
83 * ELCR: PIC edge/level registers
84 * PCI: PCI configuration space
85 */
86static const struct acpi_port_info acpi_protected_ports[] = {
87 {"DMA", 0x0000, 0x000F, ACPI_OSI_WIN_XP},
88 {"PIC0", 0x0020, 0x0021, ACPI_ALWAYS_ILLEGAL},
89 {"PIT1", 0x0040, 0x0043, ACPI_OSI_WIN_XP},
90 {"PIT2", 0x0048, 0x004B, ACPI_OSI_WIN_XP},
91 {"RTC", 0x0070, 0x0071, ACPI_OSI_WIN_XP},
92 {"CMOS", 0x0074, 0x0076, ACPI_OSI_WIN_XP},
93 {"DMA1", 0x0081, 0x0083, ACPI_OSI_WIN_XP},
94 {"DMA1L", 0x0087, 0x0087, ACPI_OSI_WIN_XP},
95 {"DMA2", 0x0089, 0x008B, ACPI_OSI_WIN_XP},
96 {"DMA2L", 0x008F, 0x008F, ACPI_OSI_WIN_XP},
97 {"ARBC", 0x0090, 0x0091, ACPI_OSI_WIN_XP},
98 {"SETUP", 0x0093, 0x0094, ACPI_OSI_WIN_XP},
99 {"POS", 0x0096, 0x0097, ACPI_OSI_WIN_XP},
100 {"PIC1", 0x00A0, 0x00A1, ACPI_ALWAYS_ILLEGAL},
101 {"IDMA", 0x00C0, 0x00DF, ACPI_OSI_WIN_XP},
102 {"ELCR", 0x04D0, 0x04D1, ACPI_ALWAYS_ILLEGAL},
103 {"PCI", 0x0CF8, 0x0CFF, ACPI_OSI_WIN_XP}
104};
105
106#define ACPI_PORT_INFO_ENTRIES ACPI_ARRAY_LENGTH (acpi_protected_ports)
107
108/******************************************************************************
109 *
110 * FUNCTION: acpi_hw_validate_io_request
111 *
112 * PARAMETERS: Address Address of I/O port/register
113 * bit_width Number of bits (8,16,32)
114 *
115 * RETURN: Status
116 *
117 * DESCRIPTION: Validates an I/O request (address/length). Certain ports are
118 * always illegal and some ports are only illegal depending on
119 * the requests the BIOS AML code makes to the predefined
120 * _OSI method.
121 *
122 ******************************************************************************/
123
124static acpi_status
125acpi_hw_validate_io_request(acpi_io_address address, u32 bit_width)
126{
127 u32 i;
128 u32 byte_width;
129 acpi_io_address last_address;
130 const struct acpi_port_info *port_info;
131
132 ACPI_FUNCTION_TRACE(hw_validate_io_request);
133
134 /* Supported widths are 8/16/32 */
135
136 if ((bit_width != 8) && (bit_width != 16) && (bit_width != 32)) {
137 return AE_BAD_PARAMETER;
138 }
139
140 port_info = acpi_protected_ports;
141 byte_width = ACPI_DIV_8(bit_width);
142 last_address = address + byte_width - 1;
143
144 ACPI_DEBUG_PRINT((ACPI_DB_IO, "Address %p LastAddress %p Length %X",
145 ACPI_CAST_PTR(void, address), ACPI_CAST_PTR(void,
146 last_address),
147 byte_width));
148
149 /* Maximum 16-bit address in I/O space */
150
151 if (last_address > ACPI_UINT16_MAX) {
152 ACPI_ERROR((AE_INFO,
153 "Illegal I/O port address/length above 64K: 0x%p/%X",
154 ACPI_CAST_PTR(void, address), byte_width));
155 return_ACPI_STATUS(AE_LIMIT);
156 }
157
158 /* Exit if requested address is not within the protected port table */
159
160 if (address > acpi_protected_ports[ACPI_PORT_INFO_ENTRIES - 1].end) {
161 return_ACPI_STATUS(AE_OK);
162 }
163
164 /* Check request against the list of protected I/O ports */
165
166 for (i = 0; i < ACPI_PORT_INFO_ENTRIES; i++, port_info++) {
167 /*
168 * Check if the requested address range will write to a reserved
169 * port. Four cases to consider:
170 *
171 * 1) Address range is contained completely in the port address range
172 * 2) Address range overlaps port range at the port range start
173 * 3) Address range overlaps port range at the port range end
174 * 4) Address range completely encompasses the port range
175 */
176 if ((address <= port_info->end)
177 && (last_address >= port_info->start)) {
178
179 /* Port illegality may depend on the _OSI calls made by the BIOS */
180
181 if (acpi_gbl_osi_data >= port_info->osi_dependency) {
182 ACPI_DEBUG_PRINT((ACPI_DB_IO,
183 "Denied AML access to port 0x%p/%X (%s 0x%.4X-0x%.4X)",
184 ACPI_CAST_PTR(void, address),
185 byte_width, port_info->name,
186 port_info->start,
187 port_info->end));
188
189 return_ACPI_STATUS(AE_AML_ILLEGAL_ADDRESS);
190 }
191 }
192
193 /* Finished if address range ends before the end of this port */
194
195 if (last_address <= port_info->end) {
196 break;
197 }
198 }
199
200 return_ACPI_STATUS(AE_OK);
201}
202
203/******************************************************************************
204 *
205 * FUNCTION: acpi_hw_read_port
206 *
207 * PARAMETERS: Address Address of I/O port/register to read
208 * Value Where value is placed
209 * Width Number of bits
210 *
211 * RETURN: Status and value read from port
212 *
213 * DESCRIPTION: Read data from an I/O port or register. This is a front-end
214 * to acpi_os_read_port that performs validation on both the port
215 * address and the length.
216 *
217 *****************************************************************************/
218
219acpi_status acpi_hw_read_port(acpi_io_address address, u32 *value, u32 width)
220{
221 acpi_status status;
222 u32 one_byte;
223 u32 i;
224
225 /* Validate the entire request and perform the I/O */
226
227 status = acpi_hw_validate_io_request(address, width);
228 if (ACPI_SUCCESS(status)) {
229 status = acpi_os_read_port(address, value, width);
230 return status;
231 }
232
233 if (status != AE_AML_ILLEGAL_ADDRESS) {
234 return status;
235 }
236
237 /*
238 * There has been a protection violation within the request. Fall
239 * back to byte granularity port I/O and ignore the failing bytes.
240 * This provides Windows compatibility.
241 */
242 for (i = 0, *value = 0; i < width; i += 8) {
243
244 /* Validate and read one byte */
245
246 if (acpi_hw_validate_io_request(address, 8) == AE_OK) {
247 status = acpi_os_read_port(address, &one_byte, 8);
248 if (ACPI_FAILURE(status)) {
249 return status;
250 }
251
252 *value |= (one_byte << i);
253 }
254
255 address++;
256 }
257
258 return AE_OK;
259}
260
261/******************************************************************************
262 *
263 * FUNCTION: acpi_hw_write_port
264 *
265 * PARAMETERS: Address Address of I/O port/register to write
266 * Value Value to write
267 * Width Number of bits
268 *
269 * RETURN: Status
270 *
271 * DESCRIPTION: Write data to an I/O port or register. This is a front-end
272 * to acpi_os_write_port that performs validation on both the port
273 * address and the length.
274 *
275 *****************************************************************************/
276
277acpi_status acpi_hw_write_port(acpi_io_address address, u32 value, u32 width)
278{
279 acpi_status status;
280 u32 i;
281
282 /* Validate the entire request and perform the I/O */
283
284 status = acpi_hw_validate_io_request(address, width);
285 if (ACPI_SUCCESS(status)) {
286 status = acpi_os_write_port(address, value, width);
287 return status;
288 }
289
290 if (status != AE_AML_ILLEGAL_ADDRESS) {
291 return status;
292 }
293
294 /*
295 * There has been a protection violation within the request. Fall
296 * back to byte granularity port I/O and ignore the failing bytes.
297 * This provides Windows compatibility.
298 */
299 for (i = 0; i < width; i += 8) {
300
301 /* Validate and write one byte */
302
303 if (acpi_hw_validate_io_request(address, 8) == AE_OK) {
304 status =
305 acpi_os_write_port(address, (value >> i) & 0xFF, 8);
306 if (ACPI_FAILURE(status)) {
307 return status;
308 }
309 }
310
311 address++;
312 }
313
314 return AE_OK;
315}
diff --git a/drivers/acpi/acpica/hwxface.c b/drivers/acpi/acpica/hwxface.c
index ae597c0ab53f..9829979f2bdd 100644
--- a/drivers/acpi/acpica/hwxface.c
+++ b/drivers/acpi/acpica/hwxface.c
@@ -107,19 +107,18 @@ acpi_status acpi_read(u32 *value, struct acpi_generic_address *reg)
107 ACPI_FUNCTION_NAME(acpi_read); 107 ACPI_FUNCTION_NAME(acpi_read);
108 108
109 /* 109 /*
110 * Must have a valid pointer to a GAS structure, and 110 * Must have a valid pointer to a GAS structure, and a non-zero address
111 * a non-zero address within. However, don't return an error 111 * within.
112 * because the PM1A/B code must not fail if B isn't present.
113 */ 112 */
114 if (!reg) { 113 if (!reg) {
115 return (AE_OK); 114 return (AE_BAD_PARAMETER);
116 } 115 }
117 116
118 /* Get a local copy of the address. Handles possible alignment issues */ 117 /* Get a local copy of the address. Handles possible alignment issues */
119 118
120 ACPI_MOVE_64_TO_64(&address, &reg->address); 119 ACPI_MOVE_64_TO_64(&address, &reg->address);
121 if (!address) { 120 if (!address) {
122 return (AE_OK); 121 return (AE_BAD_ADDRESS);
123 } 122 }
124 123
125 /* Supported widths are 8/16/32 */ 124 /* Supported widths are 8/16/32 */
@@ -134,8 +133,8 @@ acpi_status acpi_read(u32 *value, struct acpi_generic_address *reg)
134 *value = 0; 133 *value = 0;
135 134
136 /* 135 /*
137 * Two address spaces supported: Memory or IO. 136 * Two address spaces supported: Memory or IO. PCI_Config is
138 * PCI_Config is not supported here because the GAS struct is insufficient 137 * not supported here because the GAS structure is insufficient
139 */ 138 */
140 switch (reg->space_id) { 139 switch (reg->space_id) {
141 case ACPI_ADR_SPACE_SYSTEM_MEMORY: 140 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
@@ -147,7 +146,7 @@ acpi_status acpi_read(u32 *value, struct acpi_generic_address *reg)
147 case ACPI_ADR_SPACE_SYSTEM_IO: 146 case ACPI_ADR_SPACE_SYSTEM_IO:
148 147
149 status = 148 status =
150 acpi_os_read_port((acpi_io_address) address, value, width); 149 acpi_hw_read_port((acpi_io_address) address, value, width);
151 break; 150 break;
152 151
153 default: 152 default:
@@ -187,19 +186,18 @@ acpi_status acpi_write(u32 value, struct acpi_generic_address *reg)
187 ACPI_FUNCTION_NAME(acpi_write); 186 ACPI_FUNCTION_NAME(acpi_write);
188 187
189 /* 188 /*
190 * Must have a valid pointer to a GAS structure, and 189 * Must have a valid pointer to a GAS structure, and a non-zero address
191 * a non-zero address within. However, don't return an error 190 * within.
192 * because the PM1A/B code must not fail if B isn't present.
193 */ 191 */
194 if (!reg) { 192 if (!reg) {
195 return (AE_OK); 193 return (AE_BAD_PARAMETER);
196 } 194 }
197 195
198 /* Get a local copy of the address. Handles possible alignment issues */ 196 /* Get a local copy of the address. Handles possible alignment issues */
199 197
200 ACPI_MOVE_64_TO_64(&address, &reg->address); 198 ACPI_MOVE_64_TO_64(&address, &reg->address);
201 if (!address) { 199 if (!address) {
202 return (AE_OK); 200 return (AE_BAD_ADDRESS);
203 } 201 }
204 202
205 /* Supported widths are 8/16/32 */ 203 /* Supported widths are 8/16/32 */
@@ -222,7 +220,7 @@ acpi_status acpi_write(u32 value, struct acpi_generic_address *reg)
222 220
223 case ACPI_ADR_SPACE_SYSTEM_IO: 221 case ACPI_ADR_SPACE_SYSTEM_IO:
224 222
225 status = acpi_os_write_port((acpi_io_address) address, value, 223 status = acpi_hw_write_port((acpi_io_address) address, value,
226 width); 224 width);
227 break; 225 break;
228 226
@@ -244,24 +242,36 @@ ACPI_EXPORT_SYMBOL(acpi_write)
244 242
245/******************************************************************************* 243/*******************************************************************************
246 * 244 *
247 * FUNCTION: acpi_get_register_unlocked 245 * FUNCTION: acpi_read_bit_register
248 * 246 *
249 * PARAMETERS: register_id - ID of ACPI bit_register to access 247 * PARAMETERS: register_id - ID of ACPI Bit Register to access
250 * return_value - Value that was read from the register 248 * return_value - Value that was read from the register,
249 * normalized to bit position zero.
251 * 250 *
252 * RETURN: Status and the value read from specified Register. Value 251 * RETURN: Status and the value read from the specified Register. Value
253 * returned is normalized to bit0 (is shifted all the way right) 252 * returned is normalized to bit0 (is shifted all the way right)
254 * 253 *
255 * DESCRIPTION: ACPI bit_register read function. Does not acquire the HW lock. 254 * DESCRIPTION: ACPI bit_register read function. Does not acquire the HW lock.
256 * 255 *
256 * SUPPORTS: Bit fields in PM1 Status, PM1 Enable, PM1 Control, and
257 * PM2 Control.
258 *
259 * Note: The hardware lock is not required when reading the ACPI bit registers
260 * since almost all of them are single bit and it does not matter that
261 * the parent hardware register can be split across two physical
262 * registers. The only multi-bit field is SLP_TYP in the PM1 control
263 * register, but this field does not cross an 8-bit boundary (nor does
264 * it make much sense to actually read this field.)
265 *
257 ******************************************************************************/ 266 ******************************************************************************/
258acpi_status acpi_get_register_unlocked(u32 register_id, u32 *return_value) 267acpi_status acpi_read_bit_register(u32 register_id, u32 *return_value)
259{ 268{
260 u32 register_value = 0;
261 struct acpi_bit_register_info *bit_reg_info; 269 struct acpi_bit_register_info *bit_reg_info;
270 u32 register_value;
271 u32 value;
262 acpi_status status; 272 acpi_status status;
263 273
264 ACPI_FUNCTION_TRACE(acpi_get_register_unlocked); 274 ACPI_FUNCTION_TRACE_U32(acpi_read_bit_register, register_id);
265 275
266 /* Get the info structure corresponding to the requested ACPI Register */ 276 /* Get the info structure corresponding to the requested ACPI Register */
267 277
@@ -270,209 +280,133 @@ acpi_status acpi_get_register_unlocked(u32 register_id, u32 *return_value)
270 return_ACPI_STATUS(AE_BAD_PARAMETER); 280 return_ACPI_STATUS(AE_BAD_PARAMETER);
271 } 281 }
272 282
273 /* Read from the register */ 283 /* Read the entire parent register */
274 284
275 status = acpi_hw_register_read(bit_reg_info->parent_register, 285 status = acpi_hw_register_read(bit_reg_info->parent_register,
276 &register_value); 286 &register_value);
277 287 if (ACPI_FAILURE(status)) {
278 if (ACPI_SUCCESS(status)) { 288 return_ACPI_STATUS(status);
279
280 /* Normalize the value that was read */
281
282 register_value =
283 ((register_value & bit_reg_info->access_bit_mask)
284 >> bit_reg_info->bit_position);
285
286 *return_value = register_value;
287
288 ACPI_DEBUG_PRINT((ACPI_DB_IO, "Read value %8.8X register %X\n",
289 register_value,
290 bit_reg_info->parent_register));
291 } 289 }
292 290
293 return_ACPI_STATUS(status); 291 /* Normalize the value that was read, mask off other bits */
294}
295 292
296ACPI_EXPORT_SYMBOL(acpi_get_register_unlocked) 293 value = ((register_value & bit_reg_info->access_bit_mask)
294 >> bit_reg_info->bit_position);
297 295
298/******************************************************************************* 296 ACPI_DEBUG_PRINT((ACPI_DB_IO,
299 * 297 "BitReg %X, ParentReg %X, Actual %8.8X, ReturnValue %8.8X\n",
300 * FUNCTION: acpi_get_register 298 register_id, bit_reg_info->parent_register,
301 * 299 register_value, value));
302 * PARAMETERS: register_id - ID of ACPI bit_register to access
303 * return_value - Value that was read from the register
304 *
305 * RETURN: Status and the value read from specified Register. Value
306 * returned is normalized to bit0 (is shifted all the way right)
307 *
308 * DESCRIPTION: ACPI bit_register read function.
309 *
310 ******************************************************************************/
311acpi_status acpi_get_register(u32 register_id, u32 *return_value)
312{
313 acpi_status status;
314 acpi_cpu_flags flags;
315
316 flags = acpi_os_acquire_lock(acpi_gbl_hardware_lock);
317 status = acpi_get_register_unlocked(register_id, return_value);
318 acpi_os_release_lock(acpi_gbl_hardware_lock, flags);
319 300
320 return (status); 301 *return_value = value;
302 return_ACPI_STATUS(AE_OK);
321} 303}
322 304
323ACPI_EXPORT_SYMBOL(acpi_get_register) 305ACPI_EXPORT_SYMBOL(acpi_read_bit_register)
324 306
325/******************************************************************************* 307/*******************************************************************************
326 * 308 *
327 * FUNCTION: acpi_set_register 309 * FUNCTION: acpi_write_bit_register
328 * 310 *
329 * PARAMETERS: register_id - ID of ACPI bit_register to access 311 * PARAMETERS: register_id - ID of ACPI Bit Register to access
330 * Value - (only used on write) value to write to the 312 * Value - Value to write to the register, in bit
331 * Register, NOT pre-normalized to the bit pos 313 * position zero. The bit is automaticallly
314 * shifted to the correct position.
332 * 315 *
333 * RETURN: Status 316 * RETURN: Status
334 * 317 *
335 * DESCRIPTION: ACPI Bit Register write function. 318 * DESCRIPTION: ACPI Bit Register write function. Acquires the hardware lock
319 * since most operations require a read/modify/write sequence.
320 *
321 * SUPPORTS: Bit fields in PM1 Status, PM1 Enable, PM1 Control, and
322 * PM2 Control.
323 *
324 * Note that at this level, the fact that there may be actually two
325 * hardware registers (A and B - and B may not exist) is abstracted.
336 * 326 *
337 ******************************************************************************/ 327 ******************************************************************************/
338acpi_status acpi_set_register(u32 register_id, u32 value) 328acpi_status acpi_write_bit_register(u32 register_id, u32 value)
339{ 329{
340 u32 register_value = 0;
341 struct acpi_bit_register_info *bit_reg_info; 330 struct acpi_bit_register_info *bit_reg_info;
342 acpi_status status;
343 acpi_cpu_flags lock_flags; 331 acpi_cpu_flags lock_flags;
332 u32 register_value;
333 acpi_status status = AE_OK;
344 334
345 ACPI_FUNCTION_TRACE_U32(acpi_set_register, register_id); 335 ACPI_FUNCTION_TRACE_U32(acpi_write_bit_register, register_id);
346 336
347 /* Get the info structure corresponding to the requested ACPI Register */ 337 /* Get the info structure corresponding to the requested ACPI Register */
348 338
349 bit_reg_info = acpi_hw_get_bit_register_info(register_id); 339 bit_reg_info = acpi_hw_get_bit_register_info(register_id);
350 if (!bit_reg_info) { 340 if (!bit_reg_info) {
351 ACPI_ERROR((AE_INFO, "Bad ACPI HW RegisterId: %X",
352 register_id));
353 return_ACPI_STATUS(AE_BAD_PARAMETER); 341 return_ACPI_STATUS(AE_BAD_PARAMETER);
354 } 342 }
355 343
356 lock_flags = acpi_os_acquire_lock(acpi_gbl_hardware_lock); 344 lock_flags = acpi_os_acquire_lock(acpi_gbl_hardware_lock);
357 345
358 /* Always do a register read first so we can insert the new bits */
359
360 status = acpi_hw_register_read(bit_reg_info->parent_register,
361 &register_value);
362 if (ACPI_FAILURE(status)) {
363 goto unlock_and_exit;
364 }
365
366 /* 346 /*
367 * Decode the Register ID 347 * At this point, we know that the parent register is one of the
368 * Register ID = [Register block ID] | [bit ID] 348 * following: PM1 Status, PM1 Enable, PM1 Control, or PM2 Control
369 *
370 * Check bit ID to fine locate Register offset.
371 * Check Mask to determine Register offset, and then read-write.
372 */ 349 */
373 switch (bit_reg_info->parent_register) { 350 if (bit_reg_info->parent_register != ACPI_REGISTER_PM1_STATUS) {
374 case ACPI_REGISTER_PM1_STATUS:
375
376 /* 351 /*
377 * Status Registers are different from the rest. Clear by 352 * 1) Case for PM1 Enable, PM1 Control, and PM2 Control
378 * writing 1, and writing 0 has no effect. So, the only relevant 353 *
379 * information is the single bit we're interested in, all others should 354 * Perform a register read to preserve the bits that we are not
380 * be written as 0 so they will be left unchanged. 355 * interested in
381 */ 356 */
382 value = ACPI_REGISTER_PREPARE_BITS(value, 357 status = acpi_hw_register_read(bit_reg_info->parent_register,
383 bit_reg_info->bit_position,
384 bit_reg_info->
385 access_bit_mask);
386 if (value) {
387 status =
388 acpi_hw_register_write(ACPI_REGISTER_PM1_STATUS,
389 (u16) value);
390 register_value = 0;
391 }
392 break;
393
394 case ACPI_REGISTER_PM1_ENABLE:
395
396 ACPI_REGISTER_INSERT_VALUE(register_value,
397 bit_reg_info->bit_position,
398 bit_reg_info->access_bit_mask,
399 value);
400
401 status = acpi_hw_register_write(ACPI_REGISTER_PM1_ENABLE,
402 (u16) register_value);
403 break;
404
405 case ACPI_REGISTER_PM1_CONTROL:
406
407 /*
408 * Write the PM1 Control register.
409 * Note that at this level, the fact that there are actually TWO
410 * registers (A and B - and B may not exist) is abstracted.
411 */
412 ACPI_DEBUG_PRINT((ACPI_DB_IO, "PM1 control: Read %X\n",
413 register_value));
414
415 ACPI_REGISTER_INSERT_VALUE(register_value,
416 bit_reg_info->bit_position,
417 bit_reg_info->access_bit_mask,
418 value);
419
420 status = acpi_hw_register_write(ACPI_REGISTER_PM1_CONTROL,
421 (u16) register_value);
422 break;
423
424 case ACPI_REGISTER_PM2_CONTROL:
425
426 status = acpi_hw_register_read(ACPI_REGISTER_PM2_CONTROL,
427 &register_value); 358 &register_value);
428 if (ACPI_FAILURE(status)) { 359 if (ACPI_FAILURE(status)) {
429 goto unlock_and_exit; 360 goto unlock_and_exit;
430 } 361 }
431 362
432 ACPI_DEBUG_PRINT((ACPI_DB_IO, 363 /*
433 "PM2 control: Read %X from %8.8X%8.8X\n", 364 * Insert the input bit into the value that was just read
434 register_value, 365 * and write the register
435 ACPI_FORMAT_UINT64(acpi_gbl_FADT. 366 */
436 xpm2_control_block.
437 address)));
438
439 ACPI_REGISTER_INSERT_VALUE(register_value, 367 ACPI_REGISTER_INSERT_VALUE(register_value,
440 bit_reg_info->bit_position, 368 bit_reg_info->bit_position,
441 bit_reg_info->access_bit_mask, 369 bit_reg_info->access_bit_mask,
442 value); 370 value);
443 371
444 ACPI_DEBUG_PRINT((ACPI_DB_IO, 372 status = acpi_hw_register_write(bit_reg_info->parent_register,
445 "About to write %4.4X to %8.8X%8.8X\n", 373 register_value);
446 register_value, 374 } else {
447 ACPI_FORMAT_UINT64(acpi_gbl_FADT. 375 /*
448 xpm2_control_block. 376 * 2) Case for PM1 Status
449 address))); 377 *
378 * The Status register is different from the rest. Clear an event
379 * by writing 1, writing 0 has no effect. So, the only relevant
380 * information is the single bit we're interested in, all others
381 * should be written as 0 so they will be left unchanged.
382 */
383 register_value = ACPI_REGISTER_PREPARE_BITS(value,
384 bit_reg_info->
385 bit_position,
386 bit_reg_info->
387 access_bit_mask);
450 388
451 status = acpi_hw_register_write(ACPI_REGISTER_PM2_CONTROL, 389 /* No need to write the register if value is all zeros */
452 (u8) (register_value));
453 break;
454 390
455 default: 391 if (register_value) {
456 break; 392 status =
393 acpi_hw_register_write(ACPI_REGISTER_PM1_STATUS,
394 register_value);
395 }
457 } 396 }
458 397
459 unlock_and_exit: 398 ACPI_DEBUG_PRINT((ACPI_DB_IO,
460 399 "BitReg %X, ParentReg %X, Value %8.8X, Actual %8.8X\n",
461 acpi_os_release_lock(acpi_gbl_hardware_lock, lock_flags); 400 register_id, bit_reg_info->parent_register, value,
462 401 register_value));
463 /* Normalize the value that was read */
464 402
465 ACPI_DEBUG_EXEC(register_value = 403unlock_and_exit:
466 ((register_value & bit_reg_info->access_bit_mask) >>
467 bit_reg_info->bit_position));
468 404
469 ACPI_DEBUG_PRINT((ACPI_DB_IO, 405 acpi_os_release_lock(acpi_gbl_hardware_lock, lock_flags);
470 "Set bits: %8.8X actual %8.8X register %X\n", value,
471 register_value, bit_reg_info->parent_register));
472 return_ACPI_STATUS(status); 406 return_ACPI_STATUS(status);
473} 407}
474 408
475ACPI_EXPORT_SYMBOL(acpi_set_register) 409ACPI_EXPORT_SYMBOL(acpi_write_bit_register)
476 410
477/******************************************************************************* 411/*******************************************************************************
478 * 412 *
@@ -534,7 +468,7 @@ acpi_get_sleep_type_data(u8 sleep_state, u8 *sleep_type_a, u8 *sleep_type_b)
534 468
535 /* It must be of type Package */ 469 /* It must be of type Package */
536 470
537 else if (ACPI_GET_OBJECT_TYPE(info->return_object) != ACPI_TYPE_PACKAGE) { 471 else if (info->return_object->common.type != ACPI_TYPE_PACKAGE) {
538 ACPI_ERROR((AE_INFO, 472 ACPI_ERROR((AE_INFO,
539 "Sleep State return object is not a Package")); 473 "Sleep State return object is not a Package"));
540 status = AE_AML_OPERAND_TYPE; 474 status = AE_AML_OPERAND_TYPE;
@@ -555,12 +489,13 @@ acpi_get_sleep_type_data(u8 sleep_state, u8 *sleep_type_a, u8 *sleep_type_b)
555 489
556 /* The first two elements must both be of type Integer */ 490 /* The first two elements must both be of type Integer */
557 491
558 else if ((ACPI_GET_OBJECT_TYPE(info->return_object->package.elements[0]) 492 else if (((info->return_object->package.elements[0])->common.type
559 != ACPI_TYPE_INTEGER) || 493 != ACPI_TYPE_INTEGER) ||
560 (ACPI_GET_OBJECT_TYPE(info->return_object->package.elements[1]) 494 ((info->return_object->package.elements[1])->common.type
561 != ACPI_TYPE_INTEGER)) { 495 != ACPI_TYPE_INTEGER)) {
562 ACPI_ERROR((AE_INFO, 496 ACPI_ERROR((AE_INFO,
563 "Sleep State return package elements are not both Integers (%s, %s)", 497 "Sleep State return package elements are not both Integers "
498 "(%s, %s)",
564 acpi_ut_get_object_type_name(info->return_object-> 499 acpi_ut_get_object_type_name(info->return_object->
565 package.elements[0]), 500 package.elements[0]),
566 acpi_ut_get_object_type_name(info->return_object-> 501 acpi_ut_get_object_type_name(info->return_object->
diff --git a/drivers/acpi/acpica/nsaccess.c b/drivers/acpi/acpica/nsaccess.c
index 88303ebe924c..9c3cdbe2d82a 100644
--- a/drivers/acpi/acpica/nsaccess.c
+++ b/drivers/acpi/acpica/nsaccess.c
@@ -118,9 +118,8 @@ acpi_status acpi_ns_root_initialize(void)
118 } 118 }
119 119
120 /* 120 /*
121 * Name entered successfully. 121 * Name entered successfully. If entry in pre_defined_names[] specifies
122 * If entry in pre_defined_names[] specifies an 122 * an initial value, create the initial value.
123 * initial value, create the initial value.
124 */ 123 */
125 if (init_val->val) { 124 if (init_val->val) {
126 status = acpi_os_predefined_override(init_val, &val); 125 status = acpi_os_predefined_override(init_val, &val);
@@ -178,9 +177,8 @@ acpi_status acpi_ns_root_initialize(void)
178 177
179 case ACPI_TYPE_STRING: 178 case ACPI_TYPE_STRING:
180 179
181 /* 180 /* Build an object around the static string */
182 * Build an object around the static string 181
183 */
184 obj_desc->string.length = 182 obj_desc->string.length =
185 (u32) ACPI_STRLEN(val); 183 (u32) ACPI_STRLEN(val);
186 obj_desc->string.pointer = val; 184 obj_desc->string.pointer = val;
@@ -234,8 +232,7 @@ acpi_status acpi_ns_root_initialize(void)
234 /* Store pointer to value descriptor in the Node */ 232 /* Store pointer to value descriptor in the Node */
235 233
236 status = acpi_ns_attach_object(new_node, obj_desc, 234 status = acpi_ns_attach_object(new_node, obj_desc,
237 ACPI_GET_OBJECT_TYPE 235 obj_desc->common.type);
238 (obj_desc));
239 236
240 /* Remove local reference to the object */ 237 /* Remove local reference to the object */
241 238
@@ -315,10 +312,8 @@ acpi_ns_lookup(union acpi_generic_state *scope_info,
315 return_ACPI_STATUS(AE_NO_NAMESPACE); 312 return_ACPI_STATUS(AE_NO_NAMESPACE);
316 } 313 }
317 314
318 /* 315 /* Get the prefix scope. A null scope means use the root scope */
319 * Get the prefix scope. 316
320 * A null scope means use the root scope
321 */
322 if ((!scope_info) || (!scope_info->scope.node)) { 317 if ((!scope_info) || (!scope_info->scope.node)) {
323 ACPI_DEBUG_PRINT((ACPI_DB_NAMES, 318 ACPI_DEBUG_PRINT((ACPI_DB_NAMES,
324 "Null scope prefix, using root node (%p)\n", 319 "Null scope prefix, using root node (%p)\n",
@@ -338,8 +333,8 @@ acpi_ns_lookup(union acpi_generic_state *scope_info,
338 if (!(flags & ACPI_NS_PREFIX_IS_SCOPE)) { 333 if (!(flags & ACPI_NS_PREFIX_IS_SCOPE)) {
339 /* 334 /*
340 * This node might not be a actual "scope" node (such as a 335 * This node might not be a actual "scope" node (such as a
341 * Device/Method, etc.) It could be a Package or other object node. 336 * Device/Method, etc.) It could be a Package or other object
342 * Backup up the tree to find the containing scope node. 337 * node. Backup up the tree to find the containing scope node.
343 */ 338 */
344 while (!acpi_ns_opens_scope(prefix_node->type) && 339 while (!acpi_ns_opens_scope(prefix_node->type) &&
345 prefix_node->type != ACPI_TYPE_ANY) { 340 prefix_node->type != ACPI_TYPE_ANY) {
@@ -349,7 +344,7 @@ acpi_ns_lookup(union acpi_generic_state *scope_info,
349 } 344 }
350 } 345 }
351 346
352 /* Save type TBD: may be no longer necessary */ 347 /* Save type. TBD: may be no longer necessary */
353 348
354 type_to_check_for = type; 349 type_to_check_for = type;
355 350
@@ -414,6 +409,7 @@ acpi_ns_lookup(union acpi_generic_state *scope_info,
414 /* Name is fully qualified, no search rules apply */ 409 /* Name is fully qualified, no search rules apply */
415 410
416 search_parent_flag = ACPI_NS_NO_UPSEARCH; 411 search_parent_flag = ACPI_NS_NO_UPSEARCH;
412
417 /* 413 /*
418 * Point past this prefix to the name segment 414 * Point past this prefix to the name segment
419 * part or the next Parent Prefix 415 * part or the next Parent Prefix
@@ -429,7 +425,8 @@ acpi_ns_lookup(union acpi_generic_state *scope_info,
429 /* Current scope has no parent scope */ 425 /* Current scope has no parent scope */
430 426
431 ACPI_ERROR((AE_INFO, 427 ACPI_ERROR((AE_INFO,
432 "ACPI path has too many parent prefixes (^) - reached beyond root node")); 428 "ACPI path has too many parent prefixes (^) "
429 "- reached beyond root node"));
433 return_ACPI_STATUS(AE_NOT_FOUND); 430 return_ACPI_STATUS(AE_NOT_FOUND);
434 } 431 }
435 } 432 }
@@ -531,9 +528,9 @@ acpi_ns_lookup(union acpi_generic_state *scope_info,
531 while (num_segments && current_node) { 528 while (num_segments && current_node) {
532 num_segments--; 529 num_segments--;
533 if (!num_segments) { 530 if (!num_segments) {
534 /* 531
535 * This is the last segment, enable typechecking 532 /* This is the last segment, enable typechecking */
536 */ 533
537 this_search_type = type; 534 this_search_type = type;
538 535
539 /* 536 /*
@@ -584,9 +581,9 @@ acpi_ns_lookup(union acpi_generic_state *scope_info,
584 if (num_segments > 0) { 581 if (num_segments > 0) {
585 /* 582 /*
586 * If we have an alias to an object that opens a scope (such as a 583 * If we have an alias to an object that opens a scope (such as a
587 * device or processor), we need to dereference the alias here so that 584 * device or processor), we need to dereference the alias here so
588 * we can access any children of the original node (via the remaining 585 * that we can access any children of the original node (via the
589 * segments). 586 * remaining segments).
590 */ 587 */
591 if (this_node->type == ACPI_TYPE_LOCAL_ALIAS) { 588 if (this_node->type == ACPI_TYPE_LOCAL_ALIAS) {
592 if (!this_node->object) { 589 if (!this_node->object) {
@@ -594,8 +591,8 @@ acpi_ns_lookup(union acpi_generic_state *scope_info,
594 } 591 }
595 592
596 if (acpi_ns_opens_scope 593 if (acpi_ns_opens_scope
597 (((struct acpi_namespace_node *)this_node-> 594 (((struct acpi_namespace_node *)
598 object)->type)) { 595 this_node->object)->type)) {
599 this_node = 596 this_node =
600 (struct acpi_namespace_node *) 597 (struct acpi_namespace_node *)
601 this_node->object; 598 this_node->object;
@@ -639,8 +636,8 @@ acpi_ns_lookup(union acpi_generic_state *scope_info,
639 636
640 /* 637 /*
641 * If this is the last name segment and we are not looking for a 638 * If this is the last name segment and we are not looking for a
642 * specific type, but the type of found object is known, use that type 639 * specific type, but the type of found object is known, use that
643 * to (later) see if it opens a scope. 640 * type to (later) see if it opens a scope.
644 */ 641 */
645 if (type == ACPI_TYPE_ANY) { 642 if (type == ACPI_TYPE_ANY) {
646 type = this_node->type; 643 type = this_node->type;
@@ -653,9 +650,8 @@ acpi_ns_lookup(union acpi_generic_state *scope_info,
653 current_node = this_node; 650 current_node = this_node;
654 } 651 }
655 652
656 /* 653 /* Always check if we need to open a new scope */
657 * Always check if we need to open a new scope 654
658 */
659 if (!(flags & ACPI_NS_DONT_OPEN_SCOPE) && (walk_state)) { 655 if (!(flags & ACPI_NS_DONT_OPEN_SCOPE) && (walk_state)) {
660 /* 656 /*
661 * If entry is a type which opens a scope, push the new scope on the 657 * If entry is a type which opens a scope, push the new scope on the
diff --git a/drivers/acpi/acpica/nsalloc.c b/drivers/acpi/acpica/nsalloc.c
index f976d848fe82..aceb93111967 100644
--- a/drivers/acpi/acpica/nsalloc.c
+++ b/drivers/acpi/acpica/nsalloc.c
@@ -76,8 +76,7 @@ struct acpi_namespace_node *acpi_ns_create_node(u32 name)
76 ACPI_MEM_TRACKING(acpi_gbl_ns_node_list->total_allocated++); 76 ACPI_MEM_TRACKING(acpi_gbl_ns_node_list->total_allocated++);
77 77
78#ifdef ACPI_DBG_TRACK_ALLOCATIONS 78#ifdef ACPI_DBG_TRACK_ALLOCATIONS
79 temp = 79 temp = acpi_gbl_ns_node_list->total_allocated -
80 acpi_gbl_ns_node_list->total_allocated -
81 acpi_gbl_ns_node_list->total_freed; 80 acpi_gbl_ns_node_list->total_freed;
82 if (temp > acpi_gbl_ns_node_list->max_occupied) { 81 if (temp > acpi_gbl_ns_node_list->max_occupied) {
83 acpi_gbl_ns_node_list->max_occupied = temp; 82 acpi_gbl_ns_node_list->max_occupied = temp;
@@ -145,9 +144,8 @@ void acpi_ns_delete_node(struct acpi_namespace_node *node)
145 144
146 ACPI_MEM_TRACKING(acpi_gbl_ns_node_list->total_freed++); 145 ACPI_MEM_TRACKING(acpi_gbl_ns_node_list->total_freed++);
147 146
148 /* 147 /* Detach an object if there is one, then delete the node */
149 * Detach an object if there is one, then delete the node 148
150 */
151 acpi_ns_detach_object(node); 149 acpi_ns_detach_object(node);
152 (void)acpi_os_release_object(acpi_gbl_namespace_cache, node); 150 (void)acpi_os_release_object(acpi_gbl_namespace_cache, node);
153 return_VOID; 151 return_VOID;
@@ -183,9 +181,8 @@ void acpi_ns_install_node(struct acpi_walk_state *walk_state, struct acpi_namesp
183 ACPI_FUNCTION_TRACE(ns_install_node); 181 ACPI_FUNCTION_TRACE(ns_install_node);
184 182
185 /* 183 /*
186 * Get the owner ID from the Walk state 184 * Get the owner ID from the Walk state. The owner ID is used to track
187 * The owner ID is used to track table deletion and 185 * table deletion and deletion of objects created by methods.
188 * deletion of objects created by methods
189 */ 186 */
190 if (walk_state) { 187 if (walk_state) {
191 owner_id = walk_state->owner_id; 188 owner_id = walk_state->owner_id;
@@ -260,9 +257,8 @@ void acpi_ns_delete_children(struct acpi_namespace_node *parent_node)
260 return_VOID; 257 return_VOID;
261 } 258 }
262 259
263 /* 260 /* Deallocate all children at this level */
264 * Deallocate all children at this level 261
265 */
266 do { 262 do {
267 263
268 /* Get the things we need */ 264 /* Get the things we need */
@@ -285,9 +281,8 @@ void acpi_ns_delete_children(struct acpi_namespace_node *parent_node)
285 "Object %p, Remaining %X\n", child_node, 281 "Object %p, Remaining %X\n", child_node,
286 acpi_gbl_current_node_count)); 282 acpi_gbl_current_node_count));
287 283
288 /* 284 /* Detach an object if there is one, then free the child node */
289 * Detach an object if there is one, then free the child node 285
290 */
291 acpi_ns_detach_object(child_node); 286 acpi_ns_detach_object(child_node);
292 287
293 /* Now we can delete the node */ 288 /* Now we can delete the node */
@@ -304,7 +299,6 @@ void acpi_ns_delete_children(struct acpi_namespace_node *parent_node)
304 /* Clear the parent's child pointer */ 299 /* Clear the parent's child pointer */
305 300
306 parent_node->child = NULL; 301 parent_node->child = NULL;
307
308 return_VOID; 302 return_VOID;
309} 303}
310 304
diff --git a/drivers/acpi/acpica/nsdump.c b/drivers/acpi/acpica/nsdump.c
index 0da33c8e9ba2..2bad613db73a 100644
--- a/drivers/acpi/acpica/nsdump.c
+++ b/drivers/acpi/acpica/nsdump.c
@@ -181,6 +181,12 @@ acpi_ns_dump_one_object(acpi_handle obj_handle,
181 } 181 }
182 182
183 this_node = acpi_ns_map_handle_to_node(obj_handle); 183 this_node = acpi_ns_map_handle_to_node(obj_handle);
184 if (!this_node) {
185 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Invalid object handle %p\n",
186 obj_handle));
187 return (AE_OK);
188 }
189
184 type = this_node->type; 190 type = this_node->type;
185 191
186 /* Check if the owner matches */ 192 /* Check if the owner matches */
@@ -214,9 +220,8 @@ acpi_ns_dump_one_object(acpi_handle obj_handle,
214 acpi_os_printf("%4.4s", acpi_ut_get_node_name(this_node)); 220 acpi_os_printf("%4.4s", acpi_ut_get_node_name(this_node));
215 } 221 }
216 222
217 /* 223 /* Now we can print out the pertinent information */
218 * Now we can print out the pertinent information 224
219 */
220 acpi_os_printf(" %-12s %p %2.2X ", 225 acpi_os_printf(" %-12s %p %2.2X ",
221 acpi_ut_get_type_name(type), this_node, 226 acpi_ut_get_type_name(type), this_node,
222 this_node->owner_id); 227 this_node->owner_id);
@@ -509,7 +514,7 @@ acpi_ns_dump_one_object(acpi_handle obj_handle,
509 514
510 case ACPI_DESC_TYPE_OPERAND: 515 case ACPI_DESC_TYPE_OPERAND:
511 516
512 obj_type = ACPI_GET_OBJECT_TYPE(obj_desc); 517 obj_type = obj_desc->common.type;
513 518
514 if (obj_type > ACPI_TYPE_LOCAL_MAX) { 519 if (obj_type > ACPI_TYPE_LOCAL_MAX) {
515 acpi_os_printf 520 acpi_os_printf
@@ -539,9 +544,8 @@ acpi_ns_dump_one_object(acpi_handle obj_handle,
539 goto cleanup; 544 goto cleanup;
540 } 545 }
541 546
542 /* 547 /* Valid object, get the pointer to next level, if any */
543 * Valid object, get the pointer to next level, if any 548
544 */
545 switch (obj_type) { 549 switch (obj_type) {
546 case ACPI_TYPE_BUFFER: 550 case ACPI_TYPE_BUFFER:
547 case ACPI_TYPE_STRING: 551 case ACPI_TYPE_STRING:
@@ -602,14 +606,14 @@ acpi_ns_dump_one_object(acpi_handle obj_handle,
602 * display_type - 0 or ACPI_DISPLAY_SUMMARY 606 * display_type - 0 or ACPI_DISPLAY_SUMMARY
603 * max_depth - Maximum depth of dump. Use ACPI_UINT32_MAX 607 * max_depth - Maximum depth of dump. Use ACPI_UINT32_MAX
604 * for an effectively unlimited depth. 608 * for an effectively unlimited depth.
605 * owner_id - Dump only objects owned by this ID. Use 609 * owner_id - Dump only objects owned by this ID. Use
606 * ACPI_UINT32_MAX to match all owners. 610 * ACPI_UINT32_MAX to match all owners.
607 * start_handle - Where in namespace to start/end search 611 * start_handle - Where in namespace to start/end search
608 * 612 *
609 * RETURN: None 613 * RETURN: None
610 * 614 *
611 * DESCRIPTION: Dump typed objects within the loaded namespace. 615 * DESCRIPTION: Dump typed objects within the loaded namespace. Uses
612 * Uses acpi_ns_walk_namespace in conjunction with acpi_ns_dump_one_object. 616 * acpi_ns_walk_namespace in conjunction with acpi_ns_dump_one_object.
613 * 617 *
614 ******************************************************************************/ 618 ******************************************************************************/
615 619
diff --git a/drivers/acpi/acpica/nseval.c b/drivers/acpi/acpica/nseval.c
index 0f3d5f9b5966..8e7dec1176c9 100644
--- a/drivers/acpi/acpica/nseval.c
+++ b/drivers/acpi/acpica/nseval.c
@@ -155,7 +155,7 @@ acpi_status acpi_ns_evaluate(struct acpi_evaluate_info * info)
155 } 155 }
156 156
157 157
158 ACPI_DUMP_PATHNAME(info->resolved_node, "Execute Method:", 158 ACPI_DUMP_PATHNAME(info->resolved_node, "ACPI: Execute Method",
159 ACPI_LV_INFO, _COMPONENT); 159 ACPI_LV_INFO, _COMPONENT);
160 160
161 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, 161 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
diff --git a/drivers/acpi/acpica/nsinit.c b/drivers/acpi/acpica/nsinit.c
index 13501cb81863..2adfcf329e15 100644
--- a/drivers/acpi/acpica/nsinit.c
+++ b/drivers/acpi/acpica/nsinit.c
@@ -103,7 +103,8 @@ acpi_status acpi_ns_initialize_objects(void)
103 } 103 }
104 104
105 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT, 105 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT,
106 "\nInitialized %hd/%hd Regions %hd/%hd Fields %hd/%hd Buffers %hd/%hd Packages (%hd nodes)\n", 106 "\nInitialized %hd/%hd Regions %hd/%hd Fields %hd/%hd "
107 "Buffers %hd/%hd Packages (%hd nodes)\n",
107 info.op_region_init, info.op_region_count, 108 info.op_region_init, info.op_region_count,
108 info.field_init, info.field_count, 109 info.field_init, info.field_count,
109 info.buffer_init, info.buffer_count, 110 info.buffer_init, info.buffer_count,
@@ -148,7 +149,8 @@ acpi_status acpi_ns_initialize_devices(void)
148 info.num_INI = 0; 149 info.num_INI = 0;
149 150
150 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT, 151 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT,
151 "Initializing Device/Processor/Thermal objects by executing _INI methods:")); 152 "Initializing Device/Processor/Thermal objects "
153 "by executing _INI methods:"));
152 154
153 /* Tree analysis: find all subtrees that contain _INI methods */ 155 /* Tree analysis: find all subtrees that contain _INI methods */
154 156
@@ -180,7 +182,8 @@ acpi_status acpi_ns_initialize_devices(void)
180 } 182 }
181 183
182 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT, 184 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT,
183 "\nExecuted %hd _INI methods requiring %hd _STA executions (examined %hd objects)\n", 185 "\nExecuted %hd _INI methods requiring %hd _STA executions "
186 "(examined %hd objects)\n",
184 info.num_INI, info.num_STA, info.device_count)); 187 info.num_INI, info.num_STA, info.device_count));
185 188
186 return_ACPI_STATUS(status); 189 return_ACPI_STATUS(status);
@@ -263,16 +266,14 @@ acpi_ns_init_one_object(acpi_handle obj_handle,
263 return (AE_OK); 266 return (AE_OK);
264 } 267 }
265 268
266 /* 269 /* If the object is already initialized, nothing else to do */
267 * If the object is already initialized, nothing else to do 270
268 */
269 if (obj_desc->common.flags & AOPOBJ_DATA_VALID) { 271 if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
270 return (AE_OK); 272 return (AE_OK);
271 } 273 }
272 274
273 /* 275 /* Must lock the interpreter before executing AML code */
274 * Must lock the interpreter before executing AML code 276
275 */
276 acpi_ex_enter_interpreter(); 277 acpi_ex_enter_interpreter();
277 278
278 /* 279 /*
diff --git a/drivers/acpi/acpica/nsload.c b/drivers/acpi/acpica/nsload.c
index a0ba9e12379e..dcd7a6adbbbc 100644
--- a/drivers/acpi/acpica/nsload.c
+++ b/drivers/acpi/acpica/nsload.c
@@ -128,12 +128,12 @@ acpi_ns_load_table(u32 table_index, struct acpi_namespace_node *node)
128 * parse trees. 128 * parse trees.
129 */ 129 */
130 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 130 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
131 "**** Begin Table Method Parsing and Object Initialization ****\n")); 131 "**** Begin Table Method Parsing and Object Initialization\n"));
132 132
133 status = acpi_ds_initialize_objects(table_index, node); 133 status = acpi_ds_initialize_objects(table_index, node);
134 134
135 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 135 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
136 "**** Completed Table Method Parsing and Object Initialization ****\n")); 136 "**** Completed Table Method Parsing and Object Initialization\n"));
137 137
138 return_ACPI_STATUS(status); 138 return_ACPI_STATUS(status);
139} 139}
diff --git a/drivers/acpi/acpica/nsobject.c b/drivers/acpi/acpica/nsobject.c
index 08a97a57f8f9..3eb20bfda9d8 100644
--- a/drivers/acpi/acpica/nsobject.c
+++ b/drivers/acpi/acpica/nsobject.c
@@ -209,8 +209,7 @@ void acpi_ns_detach_object(struct acpi_namespace_node *node)
209 209
210 obj_desc = node->object; 210 obj_desc = node->object;
211 211
212 if (!obj_desc || 212 if (!obj_desc || (obj_desc->common.type == ACPI_TYPE_LOCAL_DATA)) {
213 (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_LOCAL_DATA)) {
214 return_VOID; 213 return_VOID;
215 } 214 }
216 215
@@ -220,8 +219,7 @@ void acpi_ns_detach_object(struct acpi_namespace_node *node)
220 if (ACPI_GET_DESCRIPTOR_TYPE(obj_desc) == ACPI_DESC_TYPE_OPERAND) { 219 if (ACPI_GET_DESCRIPTOR_TYPE(obj_desc) == ACPI_DESC_TYPE_OPERAND) {
221 node->object = obj_desc->common.next_object; 220 node->object = obj_desc->common.next_object;
222 if (node->object && 221 if (node->object &&
223 (ACPI_GET_OBJECT_TYPE(node->object) != 222 ((node->object)->common.type != ACPI_TYPE_LOCAL_DATA)) {
224 ACPI_TYPE_LOCAL_DATA)) {
225 node->object = node->object->common.next_object; 223 node->object = node->object->common.next_object;
226 } 224 }
227 } 225 }
@@ -267,7 +265,7 @@ union acpi_operand_object *acpi_ns_get_attached_object(struct
267 ((ACPI_GET_DESCRIPTOR_TYPE(node->object) != ACPI_DESC_TYPE_OPERAND) 265 ((ACPI_GET_DESCRIPTOR_TYPE(node->object) != ACPI_DESC_TYPE_OPERAND)
268 && (ACPI_GET_DESCRIPTOR_TYPE(node->object) != 266 && (ACPI_GET_DESCRIPTOR_TYPE(node->object) !=
269 ACPI_DESC_TYPE_NAMED)) 267 ACPI_DESC_TYPE_NAMED))
270 || (ACPI_GET_OBJECT_TYPE(node->object) == ACPI_TYPE_LOCAL_DATA)) { 268 || ((node->object)->common.type == ACPI_TYPE_LOCAL_DATA)) {
271 return_PTR(NULL); 269 return_PTR(NULL);
272 } 270 }
273 271
@@ -294,9 +292,9 @@ union acpi_operand_object *acpi_ns_get_secondary_object(union
294 ACPI_FUNCTION_TRACE_PTR(ns_get_secondary_object, obj_desc); 292 ACPI_FUNCTION_TRACE_PTR(ns_get_secondary_object, obj_desc);
295 293
296 if ((!obj_desc) || 294 if ((!obj_desc) ||
297 (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_LOCAL_DATA) || 295 (obj_desc->common.type == ACPI_TYPE_LOCAL_DATA) ||
298 (!obj_desc->common.next_object) || 296 (!obj_desc->common.next_object) ||
299 (ACPI_GET_OBJECT_TYPE(obj_desc->common.next_object) == 297 ((obj_desc->common.next_object)->common.type ==
300 ACPI_TYPE_LOCAL_DATA)) { 298 ACPI_TYPE_LOCAL_DATA)) {
301 return_PTR(NULL); 299 return_PTR(NULL);
302 } 300 }
@@ -331,7 +329,7 @@ acpi_ns_attach_data(struct acpi_namespace_node *node,
331 prev_obj_desc = NULL; 329 prev_obj_desc = NULL;
332 obj_desc = node->object; 330 obj_desc = node->object;
333 while (obj_desc) { 331 while (obj_desc) {
334 if ((ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_LOCAL_DATA) && 332 if ((obj_desc->common.type == ACPI_TYPE_LOCAL_DATA) &&
335 (obj_desc->data.handler == handler)) { 333 (obj_desc->data.handler == handler)) {
336 return (AE_ALREADY_EXISTS); 334 return (AE_ALREADY_EXISTS);
337 } 335 }
@@ -385,7 +383,7 @@ acpi_ns_detach_data(struct acpi_namespace_node * node,
385 prev_obj_desc = NULL; 383 prev_obj_desc = NULL;
386 obj_desc = node->object; 384 obj_desc = node->object;
387 while (obj_desc) { 385 while (obj_desc) {
388 if ((ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_LOCAL_DATA) && 386 if ((obj_desc->common.type == ACPI_TYPE_LOCAL_DATA) &&
389 (obj_desc->data.handler == handler)) { 387 (obj_desc->data.handler == handler)) {
390 if (prev_obj_desc) { 388 if (prev_obj_desc) {
391 prev_obj_desc->common.next_object = 389 prev_obj_desc->common.next_object =
@@ -428,7 +426,7 @@ acpi_ns_get_attached_data(struct acpi_namespace_node * node,
428 426
429 obj_desc = node->object; 427 obj_desc = node->object;
430 while (obj_desc) { 428 while (obj_desc) {
431 if ((ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_LOCAL_DATA) && 429 if ((obj_desc->common.type == ACPI_TYPE_LOCAL_DATA) &&
432 (obj_desc->data.handler == handler)) { 430 (obj_desc->data.handler == handler)) {
433 *data = obj_desc->data.pointer; 431 *data = obj_desc->data.pointer;
434 return (AE_OK); 432 return (AE_OK);
diff --git a/drivers/acpi/acpica/nsparse.c b/drivers/acpi/acpica/nsparse.c
index b9e8d0070b6f..662a4bd5b621 100644
--- a/drivers/acpi/acpica/nsparse.c
+++ b/drivers/acpi/acpica/nsparse.c
@@ -176,9 +176,8 @@ acpi_ns_parse_table(u32 table_index, struct acpi_namespace_node *start_node)
176 * performs another complete parse of the AML. 176 * performs another complete parse of the AML.
177 */ 177 */
178 ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "**** Start pass 1\n")); 178 ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "**** Start pass 1\n"));
179 status = 179 status = acpi_ns_one_complete_parse(ACPI_IMODE_LOAD_PASS1,
180 acpi_ns_one_complete_parse(ACPI_IMODE_LOAD_PASS1, table_index, 180 table_index, start_node);
181 start_node);
182 if (ACPI_FAILURE(status)) { 181 if (ACPI_FAILURE(status)) {
183 return_ACPI_STATUS(status); 182 return_ACPI_STATUS(status);
184 } 183 }
@@ -193,9 +192,8 @@ acpi_ns_parse_table(u32 table_index, struct acpi_namespace_node *start_node)
193 * parse objects are all cached. 192 * parse objects are all cached.
194 */ 193 */
195 ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "**** Start pass 2\n")); 194 ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "**** Start pass 2\n"));
196 status = 195 status = acpi_ns_one_complete_parse(ACPI_IMODE_LOAD_PASS2,
197 acpi_ns_one_complete_parse(ACPI_IMODE_LOAD_PASS2, table_index, 196 table_index, start_node);
198 start_node);
199 if (ACPI_FAILURE(status)) { 197 if (ACPI_FAILURE(status)) {
200 return_ACPI_STATUS(status); 198 return_ACPI_STATUS(status);
201 } 199 }
diff --git a/drivers/acpi/acpica/nspredef.c b/drivers/acpi/acpica/nspredef.c
index 452703290d35..d9e8cbc6e679 100644
--- a/drivers/acpi/acpica/nspredef.c
+++ b/drivers/acpi/acpica/nspredef.c
@@ -79,7 +79,9 @@ acpi_ns_check_package(char *pathname,
79static acpi_status 79static acpi_status
80acpi_ns_check_package_elements(char *pathname, 80acpi_ns_check_package_elements(char *pathname,
81 union acpi_operand_object **elements, 81 union acpi_operand_object **elements,
82 u8 type1, u32 count1, u8 type2, u32 count2); 82 u8 type1,
83 u32 count1,
84 u8 type2, u32 count2, u32 start_index);
83 85
84static acpi_status 86static acpi_status
85acpi_ns_check_object_type(char *pathname, 87acpi_ns_check_object_type(char *pathname,
@@ -221,7 +223,7 @@ acpi_ns_check_predefined_names(struct acpi_namespace_node *node,
221 223
222 /* For returned Package objects, check the type of all sub-objects */ 224 /* For returned Package objects, check the type of all sub-objects */
223 225
224 if (ACPI_GET_OBJECT_TYPE(return_object) == ACPI_TYPE_PACKAGE) { 226 if (return_object->common.type == ACPI_TYPE_PACKAGE) {
225 status = 227 status =
226 acpi_ns_check_package(pathname, return_object_ptr, 228 acpi_ns_check_package(pathname, return_object_ptr,
227 predefined); 229 predefined);
@@ -302,7 +304,8 @@ acpi_ns_check_parameter_count(char *pathname,
302 if ((user_param_count != required_params_current) && 304 if ((user_param_count != required_params_current) &&
303 (user_param_count != required_params_old)) { 305 (user_param_count != required_params_old)) {
304 ACPI_WARNING((AE_INFO, 306 ACPI_WARNING((AE_INFO,
305 "%s: Parameter count mismatch - caller passed %d, ACPI requires %d", 307 "%s: Parameter count mismatch - "
308 "caller passed %d, ACPI requires %d",
306 pathname, user_param_count, 309 pathname, user_param_count,
307 required_params_current)); 310 required_params_current));
308 } 311 }
@@ -472,7 +475,7 @@ acpi_ns_check_package(char *pathname,
472 package->ret_info. 475 package->ret_info.
473 object_type2, 476 object_type2,
474 package->ret_info. 477 package->ret_info.
475 count2); 478 count2, 0);
476 if (ACPI_FAILURE(status)) { 479 if (ACPI_FAILURE(status)) {
477 return (status); 480 return (status);
478 } 481 }
@@ -623,7 +626,7 @@ acpi_ns_check_package(char *pathname,
623 object_type2, 626 object_type2,
624 package-> 627 package->
625 ret_info. 628 ret_info.
626 count2); 629 count2, 0);
627 if (ACPI_FAILURE(status)) { 630 if (ACPI_FAILURE(status)) {
628 return (status); 631 return (status);
629 } 632 }
@@ -672,7 +675,8 @@ acpi_ns_check_package(char *pathname,
672 object_type1, 675 object_type1,
673 sub_package-> 676 sub_package->
674 package. 677 package.
675 count, 0, 0); 678 count, 0, 0,
679 0);
676 if (ACPI_FAILURE(status)) { 680 if (ACPI_FAILURE(status)) {
677 return (status); 681 return (status);
678 } 682 }
@@ -710,7 +714,8 @@ acpi_ns_check_package(char *pathname,
710 ret_info. 714 ret_info.
711 object_type1, 715 object_type1,
712 (expected_count 716 (expected_count
713 - 1), 0, 0); 717 - 1), 0, 0,
718 1);
714 if (ACPI_FAILURE(status)) { 719 if (ACPI_FAILURE(status)) {
715 return (status); 720 return (status);
716 } 721 }
@@ -758,6 +763,7 @@ acpi_ns_check_package(char *pathname,
758 * Count1 - Count for first group 763 * Count1 - Count for first group
759 * Type2 - Object type for second group 764 * Type2 - Object type for second group
760 * Count2 - Count for second group 765 * Count2 - Count for second group
766 * start_index - Start of the first group of elements
761 * 767 *
762 * RETURN: Status 768 * RETURN: Status
763 * 769 *
@@ -769,7 +775,9 @@ acpi_ns_check_package(char *pathname,
769static acpi_status 775static acpi_status
770acpi_ns_check_package_elements(char *pathname, 776acpi_ns_check_package_elements(char *pathname,
771 union acpi_operand_object **elements, 777 union acpi_operand_object **elements,
772 u8 type1, u32 count1, u8 type2, u32 count2) 778 u8 type1,
779 u32 count1,
780 u8 type2, u32 count2, u32 start_index)
773{ 781{
774 union acpi_operand_object **this_element = elements; 782 union acpi_operand_object **this_element = elements;
775 acpi_status status; 783 acpi_status status;
@@ -782,7 +790,7 @@ acpi_ns_check_package_elements(char *pathname,
782 */ 790 */
783 for (i = 0; i < count1; i++) { 791 for (i = 0; i < count1; i++) {
784 status = acpi_ns_check_object_type(pathname, this_element, 792 status = acpi_ns_check_object_type(pathname, this_element,
785 type1, i); 793 type1, i + start_index);
786 if (ACPI_FAILURE(status)) { 794 if (ACPI_FAILURE(status)) {
787 return (status); 795 return (status);
788 } 796 }
@@ -791,7 +799,8 @@ acpi_ns_check_package_elements(char *pathname,
791 799
792 for (i = 0; i < count2; i++) { 800 for (i = 0; i < count2; i++) {
793 status = acpi_ns_check_object_type(pathname, this_element, 801 status = acpi_ns_check_object_type(pathname, this_element,
794 type2, (i + count1)); 802 type2,
803 (i + count1 + start_index));
795 if (ACPI_FAILURE(status)) { 804 if (ACPI_FAILURE(status)) {
796 return (status); 805 return (status);
797 } 806 }
@@ -858,7 +867,7 @@ acpi_ns_check_object_type(char *pathname,
858 * from all of the predefined names (including elements of returned 867 * from all of the predefined names (including elements of returned
859 * packages) 868 * packages)
860 */ 869 */
861 switch (ACPI_GET_OBJECT_TYPE(return_object)) { 870 switch (return_object->common.type) {
862 case ACPI_TYPE_INTEGER: 871 case ACPI_TYPE_INTEGER:
863 return_btype = ACPI_RTYPE_INTEGER; 872 return_btype = ACPI_RTYPE_INTEGER;
864 break; 873 break;
@@ -901,7 +910,7 @@ acpi_ns_check_object_type(char *pathname,
901 910
902 /* For reference objects, check that the reference type is correct */ 911 /* For reference objects, check that the reference type is correct */
903 912
904 if (ACPI_GET_OBJECT_TYPE(return_object) == ACPI_TYPE_LOCAL_REFERENCE) { 913 if (return_object->common.type == ACPI_TYPE_LOCAL_REFERENCE) {
905 status = acpi_ns_check_reference(pathname, return_object); 914 status = acpi_ns_check_reference(pathname, return_object);
906 } 915 }
907 916
@@ -974,7 +983,8 @@ acpi_ns_check_reference(char *pathname,
974 } 983 }
975 984
976 ACPI_WARNING((AE_INFO, 985 ACPI_WARNING((AE_INFO,
977 "%s: Return type mismatch - unexpected reference object type [%s] %2.2X", 986 "%s: Return type mismatch - "
987 "unexpected reference object type [%s] %2.2X",
978 pathname, acpi_ut_get_reference_name(return_object), 988 pathname, acpi_ut_get_reference_name(return_object),
979 return_object->reference.class)); 989 return_object->reference.class));
980 990
@@ -1006,7 +1016,7 @@ acpi_ns_repair_object(u32 expected_btypes,
1006 union acpi_operand_object *new_object; 1016 union acpi_operand_object *new_object;
1007 acpi_size length; 1017 acpi_size length;
1008 1018
1009 switch (ACPI_GET_OBJECT_TYPE(return_object)) { 1019 switch (return_object->common.type) {
1010 case ACPI_TYPE_BUFFER: 1020 case ACPI_TYPE_BUFFER:
1011 1021
1012 if (!(expected_btypes & ACPI_RTYPE_STRING)) { 1022 if (!(expected_btypes & ACPI_RTYPE_STRING)) {
diff --git a/drivers/acpi/acpica/nssearch.c b/drivers/acpi/acpica/nssearch.c
index 6fea13f3f52d..f9b4f51bf8f2 100644
--- a/drivers/acpi/acpica/nssearch.c
+++ b/drivers/acpi/acpica/nssearch.c
@@ -167,7 +167,8 @@ acpi_ns_search_one_scope(u32 target_name,
167 /* Searched entire namespace level, not found */ 167 /* Searched entire namespace level, not found */
168 168
169 ACPI_DEBUG_PRINT((ACPI_DB_NAMES, 169 ACPI_DEBUG_PRINT((ACPI_DB_NAMES,
170 "Name [%4.4s] (%s) not found in search in scope [%4.4s] %p first child %p\n", 170 "Name [%4.4s] (%s) not found in search in scope [%4.4s] "
171 "%p first child %p\n",
171 ACPI_CAST_PTR(char, &target_name), 172 ACPI_CAST_PTR(char, &target_name),
172 acpi_ut_get_type_name(type), 173 acpi_ut_get_type_name(type),
173 acpi_ut_get_node_name(parent_node), parent_node, 174 acpi_ut_get_node_name(parent_node), parent_node,
@@ -239,9 +240,8 @@ acpi_ns_search_parent_tree(u32 target_name,
239 acpi_ut_get_node_name(parent_node), 240 acpi_ut_get_node_name(parent_node),
240 ACPI_CAST_PTR(char, &target_name))); 241 ACPI_CAST_PTR(char, &target_name)));
241 242
242 /* 243 /* Search parents until target is found or we have backed up to the root */
243 * Search parents until target is found or we have backed up to the root 244
244 */
245 while (parent_node) { 245 while (parent_node) {
246 /* 246 /*
247 * Search parent scope. Use TYPE_ANY because we don't care about the 247 * Search parent scope. Use TYPE_ANY because we don't care about the
@@ -395,9 +395,9 @@ acpi_ns_search_and_enter(u32 target_name,
395 return_ACPI_STATUS(AE_NO_MEMORY); 395 return_ACPI_STATUS(AE_NO_MEMORY);
396 } 396 }
397#ifdef ACPI_ASL_COMPILER 397#ifdef ACPI_ASL_COMPILER
398 /* 398
399 * Node is an object defined by an External() statement 399 /* Node is an object defined by an External() statement */
400 */ 400
401 if (flags & ACPI_NS_EXTERNAL) { 401 if (flags & ACPI_NS_EXTERNAL) {
402 new_node->flags |= ANOBJ_IS_EXTERNAL; 402 new_node->flags |= ANOBJ_IS_EXTERNAL;
403 } 403 }
diff --git a/drivers/acpi/acpica/nsutils.c b/drivers/acpi/acpica/nsutils.c
index 3e1149bf4aa5..78277ed08339 100644
--- a/drivers/acpi/acpica/nsutils.c
+++ b/drivers/acpi/acpica/nsutils.c
@@ -325,9 +325,8 @@ void acpi_ns_get_internal_name_length(struct acpi_namestring_info *info)
325 next_external_char++; 325 next_external_char++;
326 } 326 }
327 } else { 327 } else {
328 /* 328 /* Handle Carat prefixes */
329 * Handle Carat prefixes 329
330 */
331 while (*next_external_char == '^') { 330 while (*next_external_char == '^') {
332 info->num_carats++; 331 info->num_carats++;
333 next_external_char++; 332 next_external_char++;
@@ -552,9 +551,8 @@ acpi_ns_externalize_name(u32 internal_name_length,
552 return_ACPI_STATUS(AE_BAD_PARAMETER); 551 return_ACPI_STATUS(AE_BAD_PARAMETER);
553 } 552 }
554 553
555 /* 554 /* Check for a prefix (one '\' | one or more '^') */
556 * Check for a prefix (one '\' | one or more '^'). 555
557 */
558 switch (internal_name[0]) { 556 switch (internal_name[0]) {
559 case '\\': 557 case '\\':
560 prefix_length = 1; 558 prefix_length = 1;
@@ -580,7 +578,7 @@ acpi_ns_externalize_name(u32 internal_name_length,
580 } 578 }
581 579
582 /* 580 /*
583 * Check for object names. Note that there could be 0-255 of these 581 * Check for object names. Note that there could be 0-255 of these
584 * 4-byte elements. 582 * 4-byte elements.
585 */ 583 */
586 if (prefix_length < internal_name_length) { 584 if (prefix_length < internal_name_length) {
@@ -637,9 +635,8 @@ acpi_ns_externalize_name(u32 internal_name_length,
637 return_ACPI_STATUS(AE_BAD_PATHNAME); 635 return_ACPI_STATUS(AE_BAD_PATHNAME);
638 } 636 }
639 637
640 /* 638 /* Build the converted_name */
641 * Build converted_name 639
642 */
643 *converted_name = ACPI_ALLOCATE_ZEROED(required_length); 640 *converted_name = ACPI_ALLOCATE_ZEROED(required_length);
644 if (!(*converted_name)) { 641 if (!(*converted_name)) {
645 return_ACPI_STATUS(AE_NO_MEMORY); 642 return_ACPI_STATUS(AE_NO_MEMORY);
@@ -685,6 +682,9 @@ acpi_ns_externalize_name(u32 internal_name_length,
685 * and keep all pointers within this subsystem - however this introduces 682 * and keep all pointers within this subsystem - however this introduces
686 * more (and perhaps unnecessary) overhead. 683 * more (and perhaps unnecessary) overhead.
687 * 684 *
685 * The current implemenation is basically a placeholder until such time comes
686 * that it is needed.
687 *
688 ******************************************************************************/ 688 ******************************************************************************/
689 689
690struct acpi_namespace_node *acpi_ns_map_handle_to_node(acpi_handle handle) 690struct acpi_namespace_node *acpi_ns_map_handle_to_node(acpi_handle handle)
@@ -692,9 +692,8 @@ struct acpi_namespace_node *acpi_ns_map_handle_to_node(acpi_handle handle)
692 692
693 ACPI_FUNCTION_ENTRY(); 693 ACPI_FUNCTION_ENTRY();
694 694
695 /* 695 /* Parameter validation */
696 * Simple implementation 696
697 */
698 if ((!handle) || (handle == ACPI_ROOT_OBJECT)) { 697 if ((!handle) || (handle == ACPI_ROOT_OBJECT)) {
699 return (acpi_gbl_root_node); 698 return (acpi_gbl_root_node);
700 } 699 }
@@ -872,7 +871,7 @@ acpi_ns_get_node(struct acpi_namespace_node *prefix_node,
872 (flags | ACPI_NS_DONT_OPEN_SCOPE), NULL, 871 (flags | ACPI_NS_DONT_OPEN_SCOPE), NULL,
873 return_node); 872 return_node);
874 if (ACPI_FAILURE(status)) { 873 if (ACPI_FAILURE(status)) {
875 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s, %s\n", 874 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "%s, %s\n",
876 pathname, acpi_format_exception(status))); 875 pathname, acpi_format_exception(status)));
877 } 876 }
878 877
diff --git a/drivers/acpi/acpica/nswalk.c b/drivers/acpi/acpica/nswalk.c
index 200895fa2728..83e3aa6d4b9b 100644
--- a/drivers/acpi/acpica/nswalk.c
+++ b/drivers/acpi/acpica/nswalk.c
@@ -135,8 +135,8 @@ struct acpi_namespace_node *acpi_ns_get_next_node(acpi_object_type type, struct
135 * starting (and ending) at the node specified by start_handle. 135 * starting (and ending) at the node specified by start_handle.
136 * The user_function is called whenever a node that matches 136 * The user_function is called whenever a node that matches
137 * the type parameter is found. If the user function returns 137 * the type parameter is found. If the user function returns
138 * a non-zero value, the search is terminated immediately and this 138 * a non-zero value, the search is terminated immediately and
139 * value is returned to the caller. 139 * this value is returned to the caller.
140 * 140 *
141 * The point of this procedure is to provide a generic namespace 141 * The point of this procedure is to provide a generic namespace
142 * walk routine that can be called from multiple places to 142 * walk routine that can be called from multiple places to
@@ -200,10 +200,10 @@ acpi_ns_walk_namespace(acpi_object_type type,
200 /* 200 /*
201 * Ignore all temporary namespace nodes (created during control 201 * Ignore all temporary namespace nodes (created during control
202 * method execution) unless told otherwise. These temporary nodes 202 * method execution) unless told otherwise. These temporary nodes
203 * can cause a race condition because they can be deleted during the 203 * can cause a race condition because they can be deleted during
204 * execution of the user function (if the namespace is unlocked before 204 * the execution of the user function (if the namespace is
205 * invocation of the user function.) Only the debugger namespace dump 205 * unlocked before invocation of the user function.) Only the
206 * will examine the temporary nodes. 206 * debugger namespace dump will examine the temporary nodes.
207 */ 207 */
208 if ((child_node->flags & ANOBJ_TEMPORARY) && 208 if ((child_node->flags & ANOBJ_TEMPORARY) &&
209 !(flags & ACPI_NS_WALK_TEMP_NODES)) { 209 !(flags & ACPI_NS_WALK_TEMP_NODES)) {
diff --git a/drivers/acpi/acpica/nsxfeval.c b/drivers/acpi/acpica/nsxfeval.c
index 22a7171ac1ed..daf4ad37896d 100644
--- a/drivers/acpi/acpica/nsxfeval.c
+++ b/drivers/acpi/acpica/nsxfeval.c
@@ -53,7 +53,6 @@ ACPI_MODULE_NAME("nsxfeval")
53/* Local prototypes */ 53/* Local prototypes */
54static void acpi_ns_resolve_references(struct acpi_evaluate_info *info); 54static void acpi_ns_resolve_references(struct acpi_evaluate_info *info);
55 55
56#ifdef ACPI_FUTURE_USAGE
57/******************************************************************************* 56/*******************************************************************************
58 * 57 *
59 * FUNCTION: acpi_evaluate_object_typed 58 * FUNCTION: acpi_evaluate_object_typed
@@ -147,7 +146,7 @@ acpi_evaluate_object_typed(acpi_handle handle,
147} 146}
148 147
149ACPI_EXPORT_SYMBOL(acpi_evaluate_object_typed) 148ACPI_EXPORT_SYMBOL(acpi_evaluate_object_typed)
150#endif /* ACPI_FUTURE_USAGE */ 149
151/******************************************************************************* 150/*******************************************************************************
152 * 151 *
153 * FUNCTION: acpi_evaluate_object 152 * FUNCTION: acpi_evaluate_object
@@ -387,8 +386,7 @@ static void acpi_ns_resolve_references(struct acpi_evaluate_info *info)
387 386
388 /* We are interested in reference objects only */ 387 /* We are interested in reference objects only */
389 388
390 if (ACPI_GET_OBJECT_TYPE(info->return_object) != 389 if ((info->return_object)->common.type != ACPI_TYPE_LOCAL_REFERENCE) {
391 ACPI_TYPE_LOCAL_REFERENCE) {
392 return; 390 return;
393 } 391 }
394 392
@@ -476,21 +474,40 @@ acpi_walk_namespace(acpi_object_type type,
476 } 474 }
477 475
478 /* 476 /*
479 * Lock the namespace around the walk. 477 * Need to acquire the namespace reader lock to prevent interference
480 * The namespace will be unlocked/locked around each call 478 * with any concurrent table unloads (which causes the deletion of
481 * to the user function - since this function 479 * namespace objects). We cannot allow the deletion of a namespace node
482 * must be allowed to make Acpi calls itself. 480 * while the user function is using it. The exception to this are the
481 * nodes created and deleted during control method execution -- these
482 * nodes are marked as temporary nodes and are ignored by the namespace
483 * walk. Thus, control methods can be executed while holding the
484 * namespace deletion lock (and the user function can execute control
485 * methods.)
486 */
487 status = acpi_ut_acquire_read_lock(&acpi_gbl_namespace_rw_lock);
488 if (ACPI_FAILURE(status)) {
489 return status;
490 }
491
492 /*
493 * Lock the namespace around the walk. The namespace will be
494 * unlocked/locked around each call to the user function - since the user
495 * function must be allowed to make ACPICA calls itself (for example, it
496 * will typically execute control methods during device enumeration.)
483 */ 497 */
484 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); 498 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
485 if (ACPI_FAILURE(status)) { 499 if (ACPI_FAILURE(status)) {
486 return_ACPI_STATUS(status); 500 goto unlock_and_exit;
487 } 501 }
488 502
489 status = acpi_ns_walk_namespace(type, start_object, max_depth, 503 status = acpi_ns_walk_namespace(type, start_object, max_depth,
490 ACPI_NS_WALK_UNLOCK, 504 ACPI_NS_WALK_UNLOCK, user_function,
491 user_function, context, return_value); 505 context, return_value);
492 506
493 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); 507 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
508
509 unlock_and_exit:
510 (void)acpi_ut_release_read_lock(&acpi_gbl_namespace_rw_lock);
494 return_ACPI_STATUS(status); 511 return_ACPI_STATUS(status);
495} 512}
496 513
diff --git a/drivers/acpi/acpica/rscalc.c b/drivers/acpi/acpica/rscalc.c
index 52865ee6bc77..b6667ff059e5 100644
--- a/drivers/acpi/acpica/rscalc.c
+++ b/drivers/acpi/acpica/rscalc.c
@@ -557,9 +557,9 @@ acpi_rs_get_pci_routing_table_length(union acpi_operand_object *package_object,
557 table_index++) { 557 table_index++) {
558 if (*sub_object_list && /* Null object allowed */ 558 if (*sub_object_list && /* Null object allowed */
559 ((ACPI_TYPE_STRING == 559 ((ACPI_TYPE_STRING ==
560 ACPI_GET_OBJECT_TYPE(*sub_object_list)) || 560 (*sub_object_list)->common.type) ||
561 ((ACPI_TYPE_LOCAL_REFERENCE == 561 ((ACPI_TYPE_LOCAL_REFERENCE ==
562 ACPI_GET_OBJECT_TYPE(*sub_object_list)) && 562 (*sub_object_list)->common.type) &&
563 ((*sub_object_list)->reference.class == 563 ((*sub_object_list)->reference.class ==
564 ACPI_REFCLASS_NAME)))) { 564 ACPI_REFCLASS_NAME)))) {
565 name_found = TRUE; 565 name_found = TRUE;
@@ -575,8 +575,7 @@ acpi_rs_get_pci_routing_table_length(union acpi_operand_object *package_object,
575 /* Was a String type found? */ 575 /* Was a String type found? */
576 576
577 if (name_found) { 577 if (name_found) {
578 if (ACPI_GET_OBJECT_TYPE(*sub_object_list) == 578 if ((*sub_object_list)->common.type == ACPI_TYPE_STRING) {
579 ACPI_TYPE_STRING) {
580 /* 579 /*
581 * The length String.Length field does not include the 580 * The length String.Length field does not include the
582 * terminating NULL, add 1 581 * terminating NULL, add 1
diff --git a/drivers/acpi/acpica/rscreate.c b/drivers/acpi/acpica/rscreate.c
index 61566b1a0616..a3c23d686d5f 100644
--- a/drivers/acpi/acpica/rscreate.c
+++ b/drivers/acpi/acpica/rscreate.c
@@ -191,8 +191,6 @@ acpi_rs_create_pci_routing_table(union acpi_operand_object *package_object,
191 user_prt = ACPI_CAST_PTR(struct acpi_pci_routing_table, buffer); 191 user_prt = ACPI_CAST_PTR(struct acpi_pci_routing_table, buffer);
192 192
193 for (index = 0; index < number_of_elements; index++) { 193 for (index = 0; index < number_of_elements; index++) {
194 int source_name_index = 2;
195 int source_index_index = 3;
196 194
197 /* 195 /*
198 * Point user_prt past this current structure 196 * Point user_prt past this current structure
@@ -212,7 +210,7 @@ acpi_rs_create_pci_routing_table(union acpi_operand_object *package_object,
212 210
213 /* Each element of the top-level package must also be a package */ 211 /* Each element of the top-level package must also be a package */
214 212
215 if (ACPI_GET_OBJECT_TYPE(*top_object_list) != ACPI_TYPE_PACKAGE) { 213 if ((*top_object_list)->common.type != ACPI_TYPE_PACKAGE) {
216 ACPI_ERROR((AE_INFO, 214 ACPI_ERROR((AE_INFO,
217 "(PRT[%X]) Need sub-package, found %s", 215 "(PRT[%X]) Need sub-package, found %s",
218 index, 216 index,
@@ -240,7 +238,7 @@ acpi_rs_create_pci_routing_table(union acpi_operand_object *package_object,
240 /* 1) First subobject: Dereference the PRT.Address */ 238 /* 1) First subobject: Dereference the PRT.Address */
241 239
242 obj_desc = sub_object_list[0]; 240 obj_desc = sub_object_list[0];
243 if (ACPI_GET_OBJECT_TYPE(obj_desc) != ACPI_TYPE_INTEGER) { 241 if (obj_desc->common.type != ACPI_TYPE_INTEGER) {
244 ACPI_ERROR((AE_INFO, 242 ACPI_ERROR((AE_INFO,
245 "(PRT[%X].Address) Need Integer, found %s", 243 "(PRT[%X].Address) Need Integer, found %s",
246 index, 244 index,
@@ -253,7 +251,7 @@ acpi_rs_create_pci_routing_table(union acpi_operand_object *package_object,
253 /* 2) Second subobject: Dereference the PRT.Pin */ 251 /* 2) Second subobject: Dereference the PRT.Pin */
254 252
255 obj_desc = sub_object_list[1]; 253 obj_desc = sub_object_list[1];
256 if (ACPI_GET_OBJECT_TYPE(obj_desc) != ACPI_TYPE_INTEGER) { 254 if (obj_desc->common.type != ACPI_TYPE_INTEGER) {
257 ACPI_ERROR((AE_INFO, 255 ACPI_ERROR((AE_INFO,
258 "(PRT[%X].Pin) Need Integer, found %s", 256 "(PRT[%X].Pin) Need Integer, found %s",
259 index, 257 index,
@@ -261,27 +259,6 @@ acpi_rs_create_pci_routing_table(union acpi_operand_object *package_object,
261 return_ACPI_STATUS(AE_BAD_DATA); 259 return_ACPI_STATUS(AE_BAD_DATA);
262 } 260 }
263 261
264 /*
265 * If BIOS erroneously reversed the _PRT source_name and source_index,
266 * then reverse them back.
267 */
268 if (ACPI_GET_OBJECT_TYPE(sub_object_list[3]) !=
269 ACPI_TYPE_INTEGER) {
270 if (acpi_gbl_enable_interpreter_slack) {
271 source_name_index = 3;
272 source_index_index = 2;
273 printk(KERN_WARNING
274 "ACPI: Handling Garbled _PRT entry\n");
275 } else {
276 ACPI_ERROR((AE_INFO,
277 "(PRT[%X].source_index) Need Integer, found %s",
278 index,
279 acpi_ut_get_object_type_name
280 (sub_object_list[3])));
281 return_ACPI_STATUS(AE_BAD_DATA);
282 }
283 }
284
285 user_prt->pin = (u32) obj_desc->integer.value; 262 user_prt->pin = (u32) obj_desc->integer.value;
286 263
287 /* 264 /*
@@ -291,8 +268,7 @@ acpi_rs_create_pci_routing_table(union acpi_operand_object *package_object,
291 * other ACPI implementations. 268 * other ACPI implementations.
292 */ 269 */
293 obj_desc = sub_object_list[3]; 270 obj_desc = sub_object_list[3];
294 if (!obj_desc 271 if (!obj_desc || (obj_desc->common.type != ACPI_TYPE_INTEGER)) {
295 || (ACPI_GET_OBJECT_TYPE(obj_desc) != ACPI_TYPE_INTEGER)) {
296 sub_object_list[3] = sub_object_list[2]; 272 sub_object_list[3] = sub_object_list[2];
297 sub_object_list[2] = obj_desc; 273 sub_object_list[2] = obj_desc;
298 274
@@ -305,9 +281,9 @@ acpi_rs_create_pci_routing_table(union acpi_operand_object *package_object,
305 * 3) Third subobject: Dereference the PRT.source_name 281 * 3) Third subobject: Dereference the PRT.source_name
306 * The name may be unresolved (slack mode), so allow a null object 282 * The name may be unresolved (slack mode), so allow a null object
307 */ 283 */
308 obj_desc = sub_object_list[source_name_index]; 284 obj_desc = sub_object_list[2];
309 if (obj_desc) { 285 if (obj_desc) {
310 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) { 286 switch (obj_desc->common.type) {
311 case ACPI_TYPE_LOCAL_REFERENCE: 287 case ACPI_TYPE_LOCAL_REFERENCE:
312 288
313 if (obj_desc->reference.class != 289 if (obj_desc->reference.class !=
@@ -379,8 +355,8 @@ acpi_rs_create_pci_routing_table(union acpi_operand_object *package_object,
379 355
380 /* 4) Fourth subobject: Dereference the PRT.source_index */ 356 /* 4) Fourth subobject: Dereference the PRT.source_index */
381 357
382 obj_desc = sub_object_list[source_index_index]; 358 obj_desc = sub_object_list[3];
383 if (ACPI_GET_OBJECT_TYPE(obj_desc) != ACPI_TYPE_INTEGER) { 359 if (obj_desc->common.type != ACPI_TYPE_INTEGER) {
384 ACPI_ERROR((AE_INFO, 360 ACPI_ERROR((AE_INFO,
385 "(PRT[%X].SourceIndex) Need Integer, found %s", 361 "(PRT[%X].SourceIndex) Need Integer, found %s",
386 index, 362 index,
diff --git a/drivers/acpi/acpica/tbfadt.c b/drivers/acpi/acpica/tbfadt.c
index 3636e4f8fb73..71e655d14cb0 100644
--- a/drivers/acpi/acpica/tbfadt.c
+++ b/drivers/acpi/acpica/tbfadt.c
@@ -57,6 +57,8 @@ static void acpi_tb_convert_fadt(void);
57 57
58static void acpi_tb_validate_fadt(void); 58static void acpi_tb_validate_fadt(void);
59 59
60static void acpi_tb_setup_fadt_registers(void);
61
60/* Table for conversion of FADT to common internal format and FADT validation */ 62/* Table for conversion of FADT to common internal format and FADT validation */
61 63
62typedef struct acpi_fadt_info { 64typedef struct acpi_fadt_info {
@@ -130,7 +132,38 @@ static struct acpi_fadt_info fadt_info_table[] = {
130 ACPI_FADT_SEPARATE_LENGTH} 132 ACPI_FADT_SEPARATE_LENGTH}
131}; 133};
132 134
133#define ACPI_FADT_INFO_ENTRIES (sizeof (fadt_info_table) / sizeof (struct acpi_fadt_info)) 135#define ACPI_FADT_INFO_ENTRIES \
136 (sizeof (fadt_info_table) / sizeof (struct acpi_fadt_info))
137
138/* Table used to split Event Blocks into separate status/enable registers */
139
140typedef struct acpi_fadt_pm_info {
141 struct acpi_generic_address *target;
142 u8 source;
143 u8 register_num;
144
145} acpi_fadt_pm_info;
146
147static struct acpi_fadt_pm_info fadt_pm_info_table[] = {
148 {&acpi_gbl_xpm1a_status,
149 ACPI_FADT_OFFSET(xpm1a_event_block),
150 0},
151
152 {&acpi_gbl_xpm1a_enable,
153 ACPI_FADT_OFFSET(xpm1a_event_block),
154 1},
155
156 {&acpi_gbl_xpm1b_status,
157 ACPI_FADT_OFFSET(xpm1b_event_block),
158 0},
159
160 {&acpi_gbl_xpm1b_enable,
161 ACPI_FADT_OFFSET(xpm1b_event_block),
162 1}
163};
164
165#define ACPI_FADT_PM_INFO_ENTRIES \
166 (sizeof (fadt_pm_info_table) / sizeof (struct acpi_fadt_pm_info))
134 167
135/******************************************************************************* 168/*******************************************************************************
136 * 169 *
@@ -172,7 +205,6 @@ acpi_tb_init_generic_address(struct acpi_generic_address *generic_address,
172 * FUNCTION: acpi_tb_parse_fadt 205 * FUNCTION: acpi_tb_parse_fadt
173 * 206 *
174 * PARAMETERS: table_index - Index for the FADT 207 * PARAMETERS: table_index - Index for the FADT
175 * Flags - Flags
176 * 208 *
177 * RETURN: None 209 * RETURN: None
178 * 210 *
@@ -181,7 +213,7 @@ acpi_tb_init_generic_address(struct acpi_generic_address *generic_address,
181 * 213 *
182 ******************************************************************************/ 214 ******************************************************************************/
183 215
184void acpi_tb_parse_fadt(u32 table_index, u8 flags) 216void acpi_tb_parse_fadt(u32 table_index)
185{ 217{
186 u32 length; 218 u32 length;
187 struct acpi_table_header *table; 219 struct acpi_table_header *table;
@@ -208,7 +240,7 @@ void acpi_tb_parse_fadt(u32 table_index, u8 flags)
208 */ 240 */
209 (void)acpi_tb_verify_checksum(table, length); 241 (void)acpi_tb_verify_checksum(table, length);
210 242
211 /* Obtain a local copy of the FADT in common ACPI 2.0+ format */ 243 /* Create a local copy of the FADT in common ACPI 2.0+ format */
212 244
213 acpi_tb_create_local_fadt(table, length); 245 acpi_tb_create_local_fadt(table, length);
214 246
@@ -219,10 +251,10 @@ void acpi_tb_parse_fadt(u32 table_index, u8 flags)
219 /* Obtain the DSDT and FACS tables via their addresses within the FADT */ 251 /* Obtain the DSDT and FACS tables via their addresses within the FADT */
220 252
221 acpi_tb_install_table((acpi_physical_address) acpi_gbl_FADT.Xdsdt, 253 acpi_tb_install_table((acpi_physical_address) acpi_gbl_FADT.Xdsdt,
222 flags, ACPI_SIG_DSDT, ACPI_TABLE_INDEX_DSDT); 254 ACPI_SIG_DSDT, ACPI_TABLE_INDEX_DSDT);
223 255
224 acpi_tb_install_table((acpi_physical_address) acpi_gbl_FADT.Xfacs, 256 acpi_tb_install_table((acpi_physical_address) acpi_gbl_FADT.Xfacs,
225 flags, ACPI_SIG_FACS, ACPI_TABLE_INDEX_FACS); 257 ACPI_SIG_FACS, ACPI_TABLE_INDEX_FACS);
226} 258}
227 259
228/******************************************************************************* 260/*******************************************************************************
@@ -266,11 +298,17 @@ void acpi_tb_create_local_fadt(struct acpi_table_header *table, u32 length)
266 ACPI_MEMCPY(&acpi_gbl_FADT, table, 298 ACPI_MEMCPY(&acpi_gbl_FADT, table,
267 ACPI_MIN(length, sizeof(struct acpi_table_fadt))); 299 ACPI_MIN(length, sizeof(struct acpi_table_fadt)));
268 300
269 /* 301 /* Convert the local copy of the FADT to the common internal format */
270 * 1) Convert the local copy of the FADT to the common internal format 302
271 * 2) Validate some of the important values within the FADT
272 */
273 acpi_tb_convert_fadt(); 303 acpi_tb_convert_fadt();
304
305 /* Validate FADT values now, before we make any changes */
306
307 acpi_tb_validate_fadt();
308
309 /* Initialize the global ACPI register structures */
310
311 acpi_tb_setup_fadt_registers();
274} 312}
275 313
276/******************************************************************************* 314/*******************************************************************************
@@ -282,31 +320,35 @@ void acpi_tb_create_local_fadt(struct acpi_table_header *table, u32 length)
282 * RETURN: None 320 * RETURN: None
283 * 321 *
284 * DESCRIPTION: Converts all versions of the FADT to a common internal format. 322 * DESCRIPTION: Converts all versions of the FADT to a common internal format.
285 * Expand all 32-bit addresses to 64-bit. 323 * Expand 32-bit addresses to 64-bit as necessary.
286 * 324 *
287 * NOTE: acpi_gbl_FADT must be of size (struct acpi_table_fadt), 325 * NOTE: acpi_gbl_FADT must be of size (struct acpi_table_fadt),
288 * and must contain a copy of the actual FADT. 326 * and must contain a copy of the actual FADT.
289 * 327 *
290 * ACPICA will use the "X" fields of the FADT for all addresses. 328 * Notes on 64-bit register addresses:
329 *
330 * After this FADT conversion, later ACPICA code will only use the 64-bit "X"
331 * fields of the FADT for all ACPI register addresses.
291 * 332 *
292 * "X" fields are optional extensions to the original V1.0 fields. Even if 333 * The 64-bit "X" fields are optional extensions to the original 32-bit FADT
293 * they are present in the structure, they can be optionally not used by 334 * V1.0 fields. Even if they are present in the FADT, they are optional and
294 * setting them to zero. Therefore, we must selectively expand V1.0 fields 335 * are unused if the BIOS sets them to zero. Therefore, we must copy/expand
295 * if the corresponding X field is zero. 336 * 32-bit V1.0 fields if the corresponding X field is zero.
296 * 337 *
297 * For ACPI 1.0 FADTs, all address fields are expanded to the corresponding 338 * For ACPI 1.0 FADTs, all 32-bit address fields are expanded to the
298 * "X" fields. 339 * corresponding "X" fields in the internal FADT.
299 * 340 *
300 * For ACPI 2.0 FADTs, any "X" fields that are NULL are filled in by 341 * For ACPI 2.0+ FADTs, all valid (non-zero) 32-bit address fields are expanded
301 * expanding the corresponding ACPI 1.0 field. 342 * to the corresponding 64-bit X fields. For compatibility with other ACPI
343 * implementations, we ignore the 64-bit field if the 32-bit field is valid,
344 * regardless of whether the host OS is 32-bit or 64-bit.
302 * 345 *
303 ******************************************************************************/ 346 ******************************************************************************/
304 347
305static void acpi_tb_convert_fadt(void) 348static void acpi_tb_convert_fadt(void)
306{ 349{
307 u8 pm1_register_bit_width; 350 struct acpi_generic_address *address64;
308 u8 pm1_register_byte_width; 351 u32 address32;
309 struct acpi_generic_address *target64;
310 u32 i; 352 u32 i;
311 353
312 /* Update the local FADT table header length */ 354 /* Update the local FADT table header length */
@@ -355,140 +397,56 @@ static void acpi_tb_convert_fadt(void)
355 * Expand the ACPI 1.0 32-bit addresses to the ACPI 2.0 64-bit "X" 397 * Expand the ACPI 1.0 32-bit addresses to the ACPI 2.0 64-bit "X"
356 * generic address structures as necessary. Later code will always use 398 * generic address structures as necessary. Later code will always use
357 * the 64-bit address structures. 399 * the 64-bit address structures.
400 *
401 * March 2009:
402 * We now always use the 32-bit address if it is valid (non-null). This
403 * is not in accordance with the ACPI specification which states that
404 * the 64-bit address supersedes the 32-bit version, but we do this for
405 * compatibility with other ACPI implementations. Most notably, in the
406 * case where both the 32 and 64 versions are non-null, we use the 32-bit
407 * version. This is the only address that is guaranteed to have been
408 * tested by the BIOS manufacturer.
358 */ 409 */
359 for (i = 0; i < ACPI_FADT_INFO_ENTRIES; i++) { 410 for (i = 0; i < ACPI_FADT_INFO_ENTRIES; i++) {
360 target64 = 411 address32 = *ACPI_ADD_PTR(u32,
361 ACPI_ADD_PTR(struct acpi_generic_address, &acpi_gbl_FADT, 412 &acpi_gbl_FADT,
362 fadt_info_table[i].address64); 413 fadt_info_table[i].address32);
363 414
364 /* Expand only if the 64-bit X target is null */ 415 address64 = ACPI_ADD_PTR(struct acpi_generic_address,
416 &acpi_gbl_FADT,
417 fadt_info_table[i].address64);
365 418
366 if (!target64->address) { 419 /*
420 * If both 32- and 64-bit addresses are valid (non-zero),
421 * they must match.
422 */
423 if (address64->address && address32 &&
424 (address64->address != (u64) address32)) {
425 ACPI_ERROR((AE_INFO,
426 "32/64X address mismatch in %s: %8.8X/%8.8X%8.8X, using 32",
427 fadt_info_table[i].name, address32,
428 ACPI_FORMAT_UINT64(address64->address)));
429 }
367 430
368 /* The space_id is always I/O for the 32-bit legacy address fields */ 431 /* Always use 32-bit address if it is valid (non-null) */
369 432
370 acpi_tb_init_generic_address(target64, 433 if (address32) {
434 /*
435 * Copy the 32-bit address to the 64-bit GAS structure. The
436 * Space ID is always I/O for 32-bit legacy address fields
437 */
438 acpi_tb_init_generic_address(address64,
371 ACPI_ADR_SPACE_SYSTEM_IO, 439 ACPI_ADR_SPACE_SYSTEM_IO,
372 *ACPI_ADD_PTR(u8, 440 *ACPI_ADD_PTR(u8,
373 &acpi_gbl_FADT, 441 &acpi_gbl_FADT,
374 fadt_info_table 442 fadt_info_table
375 [i].length), 443 [i].length),
376 (u64) * ACPI_ADD_PTR(u32, 444 address32);
377 &acpi_gbl_FADT,
378 fadt_info_table
379 [i].
380 address32));
381 }
382 }
383
384 /* Validate FADT values now, before we make any changes */
385
386 acpi_tb_validate_fadt();
387
388 /*
389 * Optionally check all register lengths against the default values and
390 * update them if they are incorrect.
391 */
392 if (acpi_gbl_use_default_register_widths) {
393 for (i = 0; i < ACPI_FADT_INFO_ENTRIES; i++) {
394 target64 =
395 ACPI_ADD_PTR(struct acpi_generic_address,
396 &acpi_gbl_FADT,
397 fadt_info_table[i].address64);
398
399 /*
400 * If a valid register (Address != 0) and the (default_length > 0)
401 * (Not a GPE register), then check the width against the default.
402 */
403 if ((target64->address) &&
404 (fadt_info_table[i].default_length > 0) &&
405 (fadt_info_table[i].default_length !=
406 target64->bit_width)) {
407 ACPI_WARNING((AE_INFO,
408 "Invalid length for %s: %d, using default %d",
409 fadt_info_table[i].name,
410 target64->bit_width,
411 fadt_info_table[i].
412 default_length));
413
414 /* Incorrect size, set width to the default */
415
416 target64->bit_width =
417 fadt_info_table[i].default_length;
418 }
419 } 445 }
420 } 446 }
421
422 /*
423 * Get the length of the individual PM1 registers (enable and status).
424 * Each register is defined to be (event block length / 2).
425 */
426 pm1_register_bit_width =
427 (u8)ACPI_DIV_2(acpi_gbl_FADT.xpm1a_event_block.bit_width);
428 pm1_register_byte_width = (u8)ACPI_DIV_8(pm1_register_bit_width);
429
430 /*
431 * Adjust the lengths of the PM1 Event Blocks so that they can be used to
432 * access the PM1 status register(s). Use (width / 2)
433 */
434 acpi_gbl_FADT.xpm1a_event_block.bit_width = pm1_register_bit_width;
435 acpi_gbl_FADT.xpm1b_event_block.bit_width = pm1_register_bit_width;
436
437 /*
438 * Calculate separate GAS structs for the PM1 Enable registers.
439 * These addresses do not appear (directly) in the FADT, so it is
440 * useful to calculate them once, here.
441 *
442 * The PM event blocks are split into two register blocks, first is the
443 * PM Status Register block, followed immediately by the PM Enable
444 * Register block. Each is of length (xpm1x_event_block.bit_width/2).
445 *
446 * On various systems the v2 fields (and particularly the bit widths)
447 * cannot be relied upon, though. Hence resort to using the v1 length
448 * here (and warn about the inconsistency).
449 */
450 if (acpi_gbl_FADT.xpm1a_event_block.bit_width
451 != acpi_gbl_FADT.pm1_event_length * 8)
452 printk(KERN_WARNING "FADT: "
453 "X_PM1a_EVT_BLK.bit_width (%u) does not match"
454 " PM1_EVT_LEN (%u)\n",
455 acpi_gbl_FADT.xpm1a_event_block.bit_width,
456 acpi_gbl_FADT.pm1_event_length);
457
458 /* The PM1A register block is required */
459
460 acpi_tb_init_generic_address(&acpi_gbl_xpm1a_enable,
461 acpi_gbl_FADT.xpm1a_event_block.space_id,
462 pm1_register_byte_width,
463 (acpi_gbl_FADT.xpm1a_event_block.address +
464 pm1_register_byte_width));
465 /* Don't forget to copy space_id of the GAS */
466 acpi_gbl_xpm1a_enable.space_id =
467 acpi_gbl_FADT.xpm1a_event_block.space_id;
468
469 /* The PM1B register block is optional, ignore if not present */
470
471 if (acpi_gbl_FADT.xpm1b_event_block.address) {
472 if (acpi_gbl_FADT.xpm1b_event_block.bit_width
473 != acpi_gbl_FADT.pm1_event_length * 8)
474 printk(KERN_WARNING "FADT: "
475 "X_PM1b_EVT_BLK.bit_width (%u) does not match"
476 " PM1_EVT_LEN (%u)\n",
477 acpi_gbl_FADT.xpm1b_event_block.bit_width,
478 acpi_gbl_FADT.pm1_event_length);
479 acpi_tb_init_generic_address(&acpi_gbl_xpm1b_enable,
480 acpi_gbl_FADT.xpm1b_event_block.space_id,
481 pm1_register_byte_width,
482 (acpi_gbl_FADT.xpm1b_event_block.
483 address + pm1_register_byte_width));
484 /* Don't forget to copy space_id of the GAS */
485 acpi_gbl_xpm1b_enable.space_id =
486 acpi_gbl_FADT.xpm1b_event_block.space_id;
487
488 }
489} 447}
490 448
491/****************************************************************************** 449/*******************************************************************************
492 * 450 *
493 * FUNCTION: acpi_tb_validate_fadt 451 * FUNCTION: acpi_tb_validate_fadt
494 * 452 *
@@ -525,18 +483,22 @@ static void acpi_tb_validate_fadt(void)
525 (acpi_gbl_FADT.Xfacs != (u64) acpi_gbl_FADT.facs)) { 483 (acpi_gbl_FADT.Xfacs != (u64) acpi_gbl_FADT.facs)) {
526 ACPI_WARNING((AE_INFO, 484 ACPI_WARNING((AE_INFO,
527 "32/64X FACS address mismatch in FADT - " 485 "32/64X FACS address mismatch in FADT - "
528 "two FACS tables! %8.8X/%8.8X%8.8X", 486 "%8.8X/%8.8X%8.8X, using 32",
529 acpi_gbl_FADT.facs, 487 acpi_gbl_FADT.facs,
530 ACPI_FORMAT_UINT64(acpi_gbl_FADT.Xfacs))); 488 ACPI_FORMAT_UINT64(acpi_gbl_FADT.Xfacs)));
489
490 acpi_gbl_FADT.Xfacs = (u64) acpi_gbl_FADT.facs;
531 } 491 }
532 492
533 if (acpi_gbl_FADT.dsdt && 493 if (acpi_gbl_FADT.dsdt &&
534 (acpi_gbl_FADT.Xdsdt != (u64) acpi_gbl_FADT.dsdt)) { 494 (acpi_gbl_FADT.Xdsdt != (u64) acpi_gbl_FADT.dsdt)) {
535 ACPI_WARNING((AE_INFO, 495 ACPI_WARNING((AE_INFO,
536 "32/64X DSDT address mismatch in FADT - " 496 "32/64X DSDT address mismatch in FADT - "
537 "two DSDT tables! %8.8X/%8.8X%8.8X", 497 "%8.8X/%8.8X%8.8X, using 32",
538 acpi_gbl_FADT.dsdt, 498 acpi_gbl_FADT.dsdt,
539 ACPI_FORMAT_UINT64(acpi_gbl_FADT.Xdsdt))); 499 ACPI_FORMAT_UINT64(acpi_gbl_FADT.Xdsdt)));
500
501 acpi_gbl_FADT.Xdsdt = (u64) acpi_gbl_FADT.dsdt;
540 } 502 }
541 503
542 /* Examine all of the 64-bit extended address fields (X fields) */ 504 /* Examine all of the 64-bit extended address fields (X fields) */
@@ -561,7 +523,8 @@ static void acpi_tb_validate_fadt(void)
561 * For each extended field, check for length mismatch between the 523 * For each extended field, check for length mismatch between the
562 * legacy length field and the corresponding 64-bit X length field. 524 * legacy length field and the corresponding 64-bit X length field.
563 */ 525 */
564 if (address64 && (address64->bit_width != ACPI_MUL_8(length))) { 526 if (address64->address &&
527 (address64->bit_width != ACPI_MUL_8(length))) {
565 ACPI_WARNING((AE_INFO, 528 ACPI_WARNING((AE_INFO,
566 "32/64X length mismatch in %s: %d/%d", 529 "32/64X length mismatch in %s: %d/%d",
567 name, ACPI_MUL_8(length), 530 name, ACPI_MUL_8(length),
@@ -575,7 +538,8 @@ static void acpi_tb_validate_fadt(void)
575 */ 538 */
576 if (!address64->address || !length) { 539 if (!address64->address || !length) {
577 ACPI_ERROR((AE_INFO, 540 ACPI_ERROR((AE_INFO,
578 "Required field %s has zero address and/or length: %8.8X%8.8X/%X", 541 "Required field %s has zero address and/or length:"
542 " %8.8X%8.8X/%X",
579 name, 543 name,
580 ACPI_FORMAT_UINT64(address64-> 544 ACPI_FORMAT_UINT64(address64->
581 address), 545 address),
@@ -584,27 +548,112 @@ static void acpi_tb_validate_fadt(void)
584 } else if (fadt_info_table[i].type & ACPI_FADT_SEPARATE_LENGTH) { 548 } else if (fadt_info_table[i].type & ACPI_FADT_SEPARATE_LENGTH) {
585 /* 549 /*
586 * Field is optional (PM2Control, GPE0, GPE1) AND has its own 550 * Field is optional (PM2Control, GPE0, GPE1) AND has its own
587 * length field. If present, both the address and length must be valid. 551 * length field. If present, both the address and length must
552 * be valid.
588 */ 553 */
589 if ((address64->address && !length) 554 if ((address64->address && !length) ||
590 || (!address64->address && length)) { 555 (!address64->address && length)) {
591 ACPI_WARNING((AE_INFO, 556 ACPI_WARNING((AE_INFO,
592 "Optional field %s has zero address or length: %8.8X%8.8X/%X", 557 "Optional field %s has zero address or length: "
558 "%8.8X%8.8X/%X",
593 name, 559 name,
594 ACPI_FORMAT_UINT64(address64-> 560 ACPI_FORMAT_UINT64(address64->
595 address), 561 address),
596 length)); 562 length));
597 } 563 }
598 } 564 }
565 }
566}
599 567
600 /* If both 32- and 64-bit addresses are valid (non-zero), they must match */ 568/*******************************************************************************
569 *
570 * FUNCTION: acpi_tb_setup_fadt_registers
571 *
572 * PARAMETERS: None, uses acpi_gbl_FADT.
573 *
574 * RETURN: None
575 *
576 * DESCRIPTION: Initialize global ACPI PM1 register definitions. Optionally,
577 * force FADT register definitions to their default lengths.
578 *
579 ******************************************************************************/
601 580
602 if (address64->address && *address32 && 581static void acpi_tb_setup_fadt_registers(void)
603 (address64->address != (u64) * address32)) { 582{
604 ACPI_ERROR((AE_INFO, 583 struct acpi_generic_address *target64;
605 "32/64X address mismatch in %s: %8.8X/%8.8X%8.8X, using 64X", 584 struct acpi_generic_address *source64;
606 name, *address32, 585 u8 pm1_register_byte_width;
607 ACPI_FORMAT_UINT64(address64->address))); 586 u32 i;
587
588 /*
589 * Optionally check all register lengths against the default values and
590 * update them if they are incorrect.
591 */
592 if (acpi_gbl_use_default_register_widths) {
593 for (i = 0; i < ACPI_FADT_INFO_ENTRIES; i++) {
594 target64 =
595 ACPI_ADD_PTR(struct acpi_generic_address,
596 &acpi_gbl_FADT,
597 fadt_info_table[i].address64);
598
599 /*
600 * If a valid register (Address != 0) and the (default_length > 0)
601 * (Not a GPE register), then check the width against the default.
602 */
603 if ((target64->address) &&
604 (fadt_info_table[i].default_length > 0) &&
605 (fadt_info_table[i].default_length !=
606 target64->bit_width)) {
607 ACPI_WARNING((AE_INFO,
608 "Invalid length for %s: %d, using default %d",
609 fadt_info_table[i].name,
610 target64->bit_width,
611 fadt_info_table[i].
612 default_length));
613
614 /* Incorrect size, set width to the default */
615
616 target64->bit_width =
617 fadt_info_table[i].default_length;
618 }
619 }
620 }
621
622 /*
623 * Get the length of the individual PM1 registers (enable and status).
624 * Each register is defined to be (event block length / 2). Extra divide
625 * by 8 converts bits to bytes.
626 */
627 pm1_register_byte_width = (u8)
628 ACPI_DIV_16(acpi_gbl_FADT.xpm1a_event_block.bit_width);
629
630 /*
631 * Calculate separate GAS structs for the PM1x (A/B) Status and Enable
632 * registers. These addresses do not appear (directly) in the FADT, so it
633 * is useful to pre-calculate them from the PM1 Event Block definitions.
634 *
635 * The PM event blocks are split into two register blocks, first is the
636 * PM Status Register block, followed immediately by the PM Enable
637 * Register block. Each is of length (pm1_event_length/2)
638 *
639 * Note: The PM1A event block is required by the ACPI specification.
640 * However, the PM1B event block is optional and is rarely, if ever,
641 * used.
642 */
643
644 for (i = 0; i < ACPI_FADT_PM_INFO_ENTRIES; i++) {
645 source64 =
646 ACPI_ADD_PTR(struct acpi_generic_address, &acpi_gbl_FADT,
647 fadt_pm_info_table[i].source);
648
649 if (source64->address) {
650 acpi_tb_init_generic_address(fadt_pm_info_table[i].
651 target, source64->space_id,
652 pm1_register_byte_width,
653 source64->address +
654 (fadt_pm_info_table[i].
655 register_num *
656 pm1_register_byte_width));
608 } 657 }
609 } 658 }
610} 659}
diff --git a/drivers/acpi/acpica/tbinstal.c b/drivers/acpi/acpica/tbinstal.c
index 37374b21969d..f865d5a096de 100644
--- a/drivers/acpi/acpica/tbinstal.c
+++ b/drivers/acpi/acpica/tbinstal.c
@@ -103,7 +103,9 @@ acpi_status acpi_tb_verify_table(struct acpi_table_desc *table_desc)
103 * 103 *
104 * RETURN: Status 104 * RETURN: Status
105 * 105 *
106 * DESCRIPTION: This function is called to add the ACPI table 106 * DESCRIPTION: This function is called to add an ACPI table. It is used to
107 * dynamically load tables via the Load and load_table AML
108 * operators.
107 * 109 *
108 ******************************************************************************/ 110 ******************************************************************************/
109 111
@@ -112,6 +114,7 @@ acpi_tb_add_table(struct acpi_table_desc *table_desc, u32 *table_index)
112{ 114{
113 u32 i; 115 u32 i;
114 acpi_status status = AE_OK; 116 acpi_status status = AE_OK;
117 struct acpi_table_header *override_table = NULL;
115 118
116 ACPI_FUNCTION_TRACE(tb_add_table); 119 ACPI_FUNCTION_TRACE(tb_add_table);
117 120
@@ -201,6 +204,29 @@ acpi_tb_add_table(struct acpi_table_desc *table_desc, u32 *table_index)
201 } 204 }
202 } 205 }
203 206
207 /*
208 * ACPI Table Override:
209 * Allow the host to override dynamically loaded tables.
210 */
211 status = acpi_os_table_override(table_desc->pointer, &override_table);
212 if (ACPI_SUCCESS(status) && override_table) {
213 ACPI_INFO((AE_INFO,
214 "%4.4s @ 0x%p Table override, replaced with:",
215 table_desc->pointer->signature,
216 ACPI_CAST_PTR(void, table_desc->address)));
217
218 /* We can delete the table that was passed as a parameter */
219
220 acpi_tb_delete_table(table_desc);
221
222 /* Setup descriptor for the new table */
223
224 table_desc->address = ACPI_PTR_TO_PHYSADDR(override_table);
225 table_desc->pointer = override_table;
226 table_desc->length = override_table->length;
227 table_desc->flags = ACPI_TABLE_ORIGIN_OVERRIDE;
228 }
229
204 /* Add the table to the global root table list */ 230 /* Add the table to the global root table list */
205 231
206 status = acpi_tb_store_table(table_desc->address, table_desc->pointer, 232 status = acpi_tb_store_table(table_desc->address, table_desc->pointer,
@@ -247,8 +273,9 @@ acpi_status acpi_tb_resize_root_table_list(void)
247 /* Increase the Table Array size */ 273 /* Increase the Table Array size */
248 274
249 tables = ACPI_ALLOCATE_ZEROED(((acpi_size) acpi_gbl_root_table_list. 275 tables = ACPI_ALLOCATE_ZEROED(((acpi_size) acpi_gbl_root_table_list.
250 size + ACPI_ROOT_TABLE_SIZE_INCREMENT) 276 size +
251 * sizeof(struct acpi_table_desc)); 277 ACPI_ROOT_TABLE_SIZE_INCREMENT) *
278 sizeof(struct acpi_table_desc));
252 if (!tables) { 279 if (!tables) {
253 ACPI_ERROR((AE_INFO, 280 ACPI_ERROR((AE_INFO,
254 "Could not allocate new root table array")); 281 "Could not allocate new root table array"));
@@ -407,27 +434,56 @@ void acpi_tb_terminate(void)
407 * 434 *
408 * PARAMETERS: table_index - Table index 435 * PARAMETERS: table_index - Table index
409 * 436 *
410 * RETURN: None 437 * RETURN: Status
411 * 438 *
412 * DESCRIPTION: Delete all namespace objects created when this table was loaded. 439 * DESCRIPTION: Delete all namespace objects created when this table was loaded.
413 * 440 *
414 ******************************************************************************/ 441 ******************************************************************************/
415 442
416void acpi_tb_delete_namespace_by_owner(u32 table_index) 443acpi_status acpi_tb_delete_namespace_by_owner(u32 table_index)
417{ 444{
418 acpi_owner_id owner_id; 445 acpi_owner_id owner_id;
446 acpi_status status;
447
448 ACPI_FUNCTION_TRACE(tb_delete_namespace_by_owner);
449
450 status = acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
451 if (ACPI_FAILURE(status)) {
452 return_ACPI_STATUS(status);
453 }
454
455 if (table_index >= acpi_gbl_root_table_list.count) {
456
457 /* The table index does not exist */
419 458
420 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
421 if (table_index < acpi_gbl_root_table_list.count) {
422 owner_id =
423 acpi_gbl_root_table_list.tables[table_index].owner_id;
424 } else {
425 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); 459 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
426 return; 460 return_ACPI_STATUS(AE_NOT_EXIST);
427 } 461 }
428 462
463 /* Get the owner ID for this table, used to delete namespace nodes */
464
465 owner_id = acpi_gbl_root_table_list.tables[table_index].owner_id;
429 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); 466 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
467
468 /*
469 * Need to acquire the namespace writer lock to prevent interference
470 * with any concurrent namespace walks. The interpreter must be
471 * released during the deletion since the acquisition of the deletion
472 * lock may block, and also since the execution of a namespace walk
473 * must be allowed to use the interpreter.
474 */
475 acpi_ut_release_mutex(ACPI_MTX_INTERPRETER);
476 status = acpi_ut_acquire_write_lock(&acpi_gbl_namespace_rw_lock);
477
430 acpi_ns_delete_namespace_by_owner(owner_id); 478 acpi_ns_delete_namespace_by_owner(owner_id);
479 if (ACPI_FAILURE(status)) {
480 return_ACPI_STATUS(status);
481 }
482
483 acpi_ut_release_write_lock(&acpi_gbl_namespace_rw_lock);
484
485 status = acpi_ut_acquire_mutex(ACPI_MTX_INTERPRETER);
486 return_ACPI_STATUS(status);
431} 487}
432 488
433/******************************************************************************* 489/*******************************************************************************
@@ -535,8 +591,8 @@ u8 acpi_tb_is_table_loaded(u32 table_index)
535 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); 591 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
536 if (table_index < acpi_gbl_root_table_list.count) { 592 if (table_index < acpi_gbl_root_table_list.count) {
537 is_loaded = (u8) 593 is_loaded = (u8)
538 (acpi_gbl_root_table_list.tables[table_index]. 594 (acpi_gbl_root_table_list.tables[table_index].flags &
539 flags & ACPI_TABLE_IS_LOADED); 595 ACPI_TABLE_IS_LOADED);
540 } 596 }
541 597
542 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); 598 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
diff --git a/drivers/acpi/acpica/tbutils.c b/drivers/acpi/acpica/tbutils.c
index 9684cc827930..ef7d2c2d8f0b 100644
--- a/drivers/acpi/acpica/tbutils.c
+++ b/drivers/acpi/acpica/tbutils.c
@@ -177,19 +177,23 @@ acpi_tb_print_table_header(acpi_physical_address address,
177 struct acpi_table_header *header) 177 struct acpi_table_header *header)
178{ 178{
179 179
180 /*
181 * The reason that the Address is cast to a void pointer is so that we
182 * can use %p which will work properly on both 32-bit and 64-bit hosts.
183 */
180 if (ACPI_COMPARE_NAME(header->signature, ACPI_SIG_FACS)) { 184 if (ACPI_COMPARE_NAME(header->signature, ACPI_SIG_FACS)) {
181 185
182 /* FACS only has signature and length fields of common table header */ 186 /* FACS only has signature and length fields */
183 187
184 ACPI_INFO((AE_INFO, "%4.4s %08lX, %04X", 188 ACPI_INFO((AE_INFO, "%4.4s %p %05X",
185 header->signature, (unsigned long)address, 189 header->signature, ACPI_CAST_PTR(void, address),
186 header->length)); 190 header->length));
187 } else if (ACPI_COMPARE_NAME(header->signature, ACPI_SIG_RSDP)) { 191 } else if (ACPI_COMPARE_NAME(header->signature, ACPI_SIG_RSDP)) {
188 192
189 /* RSDP has no common fields */ 193 /* RSDP has no common fields */
190 194
191 ACPI_INFO((AE_INFO, "RSDP %08lX, %04X (r%d %6.6s)", 195 ACPI_INFO((AE_INFO, "RSDP %p %05X (v%.2d %6.6s)",
192 (unsigned long)address, 196 ACPI_CAST_PTR (void, address),
193 (ACPI_CAST_PTR(struct acpi_table_rsdp, header)-> 197 (ACPI_CAST_PTR(struct acpi_table_rsdp, header)->
194 revision > 198 revision >
195 0) ? ACPI_CAST_PTR(struct acpi_table_rsdp, 199 0) ? ACPI_CAST_PTR(struct acpi_table_rsdp,
@@ -202,8 +206,8 @@ acpi_tb_print_table_header(acpi_physical_address address,
202 /* Standard ACPI table with full common header */ 206 /* Standard ACPI table with full common header */
203 207
204 ACPI_INFO((AE_INFO, 208 ACPI_INFO((AE_INFO,
205 "%4.4s %08lX, %04X (r%d %6.6s %8.8s %8X %4.4s %8X)", 209 "%4.4s %p %05X (v%.2d %6.6s %8.8s %08X %4.4s %08X)",
206 header->signature, (unsigned long)address, 210 header->signature, ACPI_CAST_PTR (void, address),
207 header->length, header->revision, header->oem_id, 211 header->length, header->revision, header->oem_id,
208 header->oem_table_id, header->oem_revision, 212 header->oem_table_id, header->oem_revision,
209 header->asl_compiler_id, 213 header->asl_compiler_id,
@@ -280,22 +284,28 @@ u8 acpi_tb_checksum(u8 *buffer, u32 length)
280 * FUNCTION: acpi_tb_install_table 284 * FUNCTION: acpi_tb_install_table
281 * 285 *
282 * PARAMETERS: Address - Physical address of DSDT or FACS 286 * PARAMETERS: Address - Physical address of DSDT or FACS
283 * Flags - Flags
284 * Signature - Table signature, NULL if no need to 287 * Signature - Table signature, NULL if no need to
285 * match 288 * match
286 * table_index - Index into root table array 289 * table_index - Index into root table array
287 * 290 *
288 * RETURN: None 291 * RETURN: None
289 * 292 *
290 * DESCRIPTION: Install an ACPI table into the global data structure. 293 * DESCRIPTION: Install an ACPI table into the global data structure. The
294 * table override mechanism is implemented here to allow the host
295 * OS to replace any table before it is installed in the root
296 * table array.
291 * 297 *
292 ******************************************************************************/ 298 ******************************************************************************/
293 299
294void 300void
295acpi_tb_install_table(acpi_physical_address address, 301acpi_tb_install_table(acpi_physical_address address,
296 u8 flags, char *signature, u32 table_index) 302 char *signature, u32 table_index)
297{ 303{
298 struct acpi_table_header *table; 304 u8 flags;
305 acpi_status status;
306 struct acpi_table_header *table_to_install;
307 struct acpi_table_header *mapped_table;
308 struct acpi_table_header *override_table = NULL;
299 309
300 if (!address) { 310 if (!address) {
301 ACPI_ERROR((AE_INFO, 311 ACPI_ERROR((AE_INFO,
@@ -306,41 +316,69 @@ acpi_tb_install_table(acpi_physical_address address,
306 316
307 /* Map just the table header */ 317 /* Map just the table header */
308 318
309 table = acpi_os_map_memory(address, sizeof(struct acpi_table_header)); 319 mapped_table =
310 if (!table) { 320 acpi_os_map_memory(address, sizeof(struct acpi_table_header));
321 if (!mapped_table) {
311 return; 322 return;
312 } 323 }
313 324
314 /* If a particular signature is expected, signature must match */ 325 /* If a particular signature is expected (DSDT/FACS), it must match */
315 326
316 if (signature && !ACPI_COMPARE_NAME(table->signature, signature)) { 327 if (signature && !ACPI_COMPARE_NAME(mapped_table->signature, signature)) {
317 ACPI_ERROR((AE_INFO, 328 ACPI_ERROR((AE_INFO,
318 "Invalid signature 0x%X for ACPI table [%s]", 329 "Invalid signature 0x%X for ACPI table, expected [%s]",
319 *ACPI_CAST_PTR(u32, table->signature), signature)); 330 *ACPI_CAST_PTR(u32, mapped_table->signature),
331 signature));
320 goto unmap_and_exit; 332 goto unmap_and_exit;
321 } 333 }
322 334
335 /*
336 * ACPI Table Override:
337 *
338 * Before we install the table, let the host OS override it with a new
339 * one if desired. Any table within the RSDT/XSDT can be replaced,
340 * including the DSDT which is pointed to by the FADT.
341 */
342 status = acpi_os_table_override(mapped_table, &override_table);
343 if (ACPI_SUCCESS(status) && override_table) {
344 ACPI_INFO((AE_INFO,
345 "%4.4s @ 0x%p Table override, replaced with:",
346 mapped_table->signature, ACPI_CAST_PTR(void,
347 address)));
348
349 acpi_gbl_root_table_list.tables[table_index].pointer =
350 override_table;
351 address = ACPI_PTR_TO_PHYSADDR(override_table);
352
353 table_to_install = override_table;
354 flags = ACPI_TABLE_ORIGIN_OVERRIDE;
355 } else {
356 table_to_install = mapped_table;
357 flags = ACPI_TABLE_ORIGIN_MAPPED;
358 }
359
323 /* Initialize the table entry */ 360 /* Initialize the table entry */
324 361
325 acpi_gbl_root_table_list.tables[table_index].address = address; 362 acpi_gbl_root_table_list.tables[table_index].address = address;
326 acpi_gbl_root_table_list.tables[table_index].length = table->length; 363 acpi_gbl_root_table_list.tables[table_index].length =
364 table_to_install->length;
327 acpi_gbl_root_table_list.tables[table_index].flags = flags; 365 acpi_gbl_root_table_list.tables[table_index].flags = flags;
328 366
329 ACPI_MOVE_32_TO_32(& 367 ACPI_MOVE_32_TO_32(&
330 (acpi_gbl_root_table_list.tables[table_index]. 368 (acpi_gbl_root_table_list.tables[table_index].
331 signature), table->signature); 369 signature), table_to_install->signature);
332 370
333 acpi_tb_print_table_header(address, table); 371 acpi_tb_print_table_header(address, table_to_install);
334 372
335 if (table_index == ACPI_TABLE_INDEX_DSDT) { 373 if (table_index == ACPI_TABLE_INDEX_DSDT) {
336 374
337 /* Global integer width is based upon revision of the DSDT */ 375 /* Global integer width is based upon revision of the DSDT */
338 376
339 acpi_ut_set_integer_width(table->revision); 377 acpi_ut_set_integer_width(table_to_install->revision);
340 } 378 }
341 379
342 unmap_and_exit: 380 unmap_and_exit:
343 acpi_os_unmap_memory(table, sizeof(struct acpi_table_header)); 381 acpi_os_unmap_memory(mapped_table, sizeof(struct acpi_table_header));
344} 382}
345 383
346/******************************************************************************* 384/*******************************************************************************
@@ -379,7 +417,8 @@ acpi_tb_get_root_table_entry(u8 *table_entry, u32 table_entry_size)
379 } else { 417 } else {
380 /* 418 /*
381 * 32-bit platform, XSDT: Truncate 64-bit to 32-bit and return 419 * 32-bit platform, XSDT: Truncate 64-bit to 32-bit and return
382 * 64-bit platform, XSDT: Move (unaligned) 64-bit to local, return 64-bit 420 * 64-bit platform, XSDT: Move (unaligned) 64-bit to local,
421 * return 64-bit
383 */ 422 */
384 ACPI_MOVE_64_TO_64(&address64, table_entry); 423 ACPI_MOVE_64_TO_64(&address64, table_entry);
385 424
@@ -389,7 +428,8 @@ acpi_tb_get_root_table_entry(u8 *table_entry, u32 table_entry_size)
389 /* Will truncate 64-bit address to 32 bits, issue warning */ 428 /* Will truncate 64-bit address to 32 bits, issue warning */
390 429
391 ACPI_WARNING((AE_INFO, 430 ACPI_WARNING((AE_INFO,
392 "64-bit Physical Address in XSDT is too large (%8.8X%8.8X), truncating", 431 "64-bit Physical Address in XSDT is too large (%8.8X%8.8X),"
432 " truncating",
393 ACPI_FORMAT_UINT64(address64))); 433 ACPI_FORMAT_UINT64(address64)));
394 } 434 }
395#endif 435#endif
@@ -402,7 +442,6 @@ acpi_tb_get_root_table_entry(u8 *table_entry, u32 table_entry_size)
402 * FUNCTION: acpi_tb_parse_root_table 442 * FUNCTION: acpi_tb_parse_root_table
403 * 443 *
404 * PARAMETERS: Rsdp - Pointer to the RSDP 444 * PARAMETERS: Rsdp - Pointer to the RSDP
405 * Flags - Flags
406 * 445 *
407 * RETURN: Status 446 * RETURN: Status
408 * 447 *
@@ -416,7 +455,7 @@ acpi_tb_get_root_table_entry(u8 *table_entry, u32 table_entry_size)
416 ******************************************************************************/ 455 ******************************************************************************/
417 456
418acpi_status __init 457acpi_status __init
419acpi_tb_parse_root_table(acpi_physical_address rsdp_address, u8 flags) 458acpi_tb_parse_root_table(acpi_physical_address rsdp_address)
420{ 459{
421 struct acpi_table_rsdp *rsdp; 460 struct acpi_table_rsdp *rsdp;
422 u32 table_entry_size; 461 u32 table_entry_size;
@@ -513,13 +552,12 @@ acpi_tb_parse_root_table(acpi_physical_address rsdp_address, u8 flags)
513 552
514 /* Calculate the number of tables described in the root table */ 553 /* Calculate the number of tables described in the root table */
515 554
516 table_count = 555 table_count = (u32)((table->length - sizeof(struct acpi_table_header)) /
517 (u32) ((table->length - 556 table_entry_size);
518 sizeof(struct acpi_table_header)) / table_entry_size);
519
520 /* 557 /*
521 * First two entries in the table array are reserved for the DSDT and FACS, 558 * First two entries in the table array are reserved for the DSDT
522 * which are not actually present in the RSDT/XSDT - they come from the FADT 559 * and FACS, which are not actually present in the RSDT/XSDT - they
560 * come from the FADT
523 */ 561 */
524 table_entry = 562 table_entry =
525 ACPI_CAST_PTR(u8, table) + sizeof(struct acpi_table_header); 563 ACPI_CAST_PTR(u8, table) + sizeof(struct acpi_table_header);
@@ -538,10 +576,9 @@ acpi_tb_parse_root_table(acpi_physical_address rsdp_address, u8 flags)
538 if (ACPI_FAILURE(status)) { 576 if (ACPI_FAILURE(status)) {
539 ACPI_WARNING((AE_INFO, 577 ACPI_WARNING((AE_INFO,
540 "Truncating %u table entries!", 578 "Truncating %u table entries!",
541 (unsigned) 579 (unsigned) (table_count -
542 (acpi_gbl_root_table_list.size - 580 (acpi_gbl_root_table_list.
543 acpi_gbl_root_table_list. 581 count - 2))));
544 count)));
545 break; 582 break;
546 } 583 }
547 } 584 }
@@ -568,14 +605,14 @@ acpi_tb_parse_root_table(acpi_physical_address rsdp_address, u8 flags)
568 */ 605 */
569 for (i = 2; i < acpi_gbl_root_table_list.count; i++) { 606 for (i = 2; i < acpi_gbl_root_table_list.count; i++) {
570 acpi_tb_install_table(acpi_gbl_root_table_list.tables[i]. 607 acpi_tb_install_table(acpi_gbl_root_table_list.tables[i].
571 address, flags, NULL, i); 608 address, NULL, i);
572 609
573 /* Special case for FADT - get the DSDT and FACS */ 610 /* Special case for FADT - get the DSDT and FACS */
574 611
575 if (ACPI_COMPARE_NAME 612 if (ACPI_COMPARE_NAME
576 (&acpi_gbl_root_table_list.tables[i].signature, 613 (&acpi_gbl_root_table_list.tables[i].signature,
577 ACPI_SIG_FADT)) { 614 ACPI_SIG_FADT)) {
578 acpi_tb_parse_fadt(i, flags); 615 acpi_tb_parse_fadt(i);
579 } 616 }
580 } 617 }
581 618
diff --git a/drivers/acpi/acpica/tbxface.c b/drivers/acpi/acpica/tbxface.c
index c3e841f3cde9..a88f02bd6c94 100644
--- a/drivers/acpi/acpica/tbxface.c
+++ b/drivers/acpi/acpica/tbxface.c
@@ -150,8 +150,7 @@ acpi_initialize_tables(struct acpi_table_desc * initial_table_array,
150 * Root Table Array. This array contains the information of the RSDT/XSDT 150 * Root Table Array. This array contains the information of the RSDT/XSDT
151 * in a common, more useable format. 151 * in a common, more useable format.
152 */ 152 */
153 status = 153 status = acpi_tb_parse_root_table(rsdp_address);
154 acpi_tb_parse_root_table(rsdp_address, ACPI_TABLE_ORIGIN_MAPPED);
155 return_ACPI_STATUS(status); 154 return_ACPI_STATUS(status);
156} 155}
157 156
@@ -247,7 +246,7 @@ acpi_status acpi_load_table(struct acpi_table_header *table_ptr)
247 246
248ACPI_EXPORT_SYMBOL(acpi_load_table) 247ACPI_EXPORT_SYMBOL(acpi_load_table)
249 248
250/****************************************************************************** 249/*******************************************************************************
251 * 250 *
252 * FUNCTION: acpi_get_table_header 251 * FUNCTION: acpi_get_table_header
253 * 252 *
@@ -262,7 +261,7 @@ ACPI_EXPORT_SYMBOL(acpi_load_table)
262 * NOTE: Caller is responsible in unmapping the header with 261 * NOTE: Caller is responsible in unmapping the header with
263 * acpi_os_unmap_memory 262 * acpi_os_unmap_memory
264 * 263 *
265 *****************************************************************************/ 264 ******************************************************************************/
266acpi_status 265acpi_status
267acpi_get_table_header(char *signature, 266acpi_get_table_header(char *signature,
268 u32 instance, struct acpi_table_header *out_table_header) 267 u32 instance, struct acpi_table_header *out_table_header)
@@ -277,9 +276,8 @@ acpi_get_table_header(char *signature,
277 return (AE_BAD_PARAMETER); 276 return (AE_BAD_PARAMETER);
278 } 277 }
279 278
280 /* 279 /* Walk the root table list */
281 * Walk the root table list 280
282 */
283 for (i = 0, j = 0; i < acpi_gbl_root_table_list.count; i++) { 281 for (i = 0, j = 0; i < acpi_gbl_root_table_list.count; i++) {
284 if (!ACPI_COMPARE_NAME 282 if (!ACPI_COMPARE_NAME
285 (&(acpi_gbl_root_table_list.tables[i].signature), 283 (&(acpi_gbl_root_table_list.tables[i].signature),
@@ -292,8 +290,8 @@ acpi_get_table_header(char *signature,
292 } 290 }
293 291
294 if (!acpi_gbl_root_table_list.tables[i].pointer) { 292 if (!acpi_gbl_root_table_list.tables[i].pointer) {
295 if ((acpi_gbl_root_table_list.tables[i]. 293 if ((acpi_gbl_root_table_list.tables[i].flags &
296 flags & ACPI_TABLE_ORIGIN_MASK) == 294 ACPI_TABLE_ORIGIN_MASK) ==
297 ACPI_TABLE_ORIGIN_MAPPED) { 295 ACPI_TABLE_ORIGIN_MAPPED) {
298 header = 296 header =
299 acpi_os_map_memory(acpi_gbl_root_table_list. 297 acpi_os_map_memory(acpi_gbl_root_table_list.
@@ -324,7 +322,7 @@ acpi_get_table_header(char *signature,
324 322
325ACPI_EXPORT_SYMBOL(acpi_get_table_header) 323ACPI_EXPORT_SYMBOL(acpi_get_table_header)
326 324
327/****************************************************************************** 325/*******************************************************************************
328 * 326 *
329 * FUNCTION: acpi_unload_table_id 327 * FUNCTION: acpi_unload_table_id
330 * 328 *
@@ -365,7 +363,7 @@ ACPI_EXPORT_SYMBOL(acpi_unload_table_id)
365 363
366/******************************************************************************* 364/*******************************************************************************
367 * 365 *
368 * FUNCTION: acpi_get_table 366 * FUNCTION: acpi_get_table_with_size
369 * 367 *
370 * PARAMETERS: Signature - ACPI signature of needed table 368 * PARAMETERS: Signature - ACPI signature of needed table
371 * Instance - Which instance (for SSDTs) 369 * Instance - Which instance (for SSDTs)
@@ -375,10 +373,11 @@ ACPI_EXPORT_SYMBOL(acpi_unload_table_id)
375 * 373 *
376 * DESCRIPTION: Finds and verifies an ACPI table. 374 * DESCRIPTION: Finds and verifies an ACPI table.
377 * 375 *
378 *****************************************************************************/ 376 ******************************************************************************/
379acpi_status 377acpi_status
380acpi_get_table(char *signature, 378acpi_get_table_with_size(char *signature,
381 u32 instance, struct acpi_table_header **out_table) 379 u32 instance, struct acpi_table_header **out_table,
380 acpi_size *tbl_size)
382{ 381{
383 u32 i; 382 u32 i;
384 u32 j; 383 u32 j;
@@ -390,9 +389,8 @@ acpi_get_table(char *signature,
390 return (AE_BAD_PARAMETER); 389 return (AE_BAD_PARAMETER);
391 } 390 }
392 391
393 /* 392 /* Walk the root table list */
394 * Walk the root table list 393
395 */
396 for (i = 0, j = 0; i < acpi_gbl_root_table_list.count; i++) { 394 for (i = 0, j = 0; i < acpi_gbl_root_table_list.count; i++) {
397 if (!ACPI_COMPARE_NAME 395 if (!ACPI_COMPARE_NAME
398 (&(acpi_gbl_root_table_list.tables[i].signature), 396 (&(acpi_gbl_root_table_list.tables[i].signature),
@@ -408,6 +406,7 @@ acpi_get_table(char *signature,
408 acpi_tb_verify_table(&acpi_gbl_root_table_list.tables[i]); 406 acpi_tb_verify_table(&acpi_gbl_root_table_list.tables[i]);
409 if (ACPI_SUCCESS(status)) { 407 if (ACPI_SUCCESS(status)) {
410 *out_table = acpi_gbl_root_table_list.tables[i].pointer; 408 *out_table = acpi_gbl_root_table_list.tables[i].pointer;
409 *tbl_size = acpi_gbl_root_table_list.tables[i].length;
411 } 410 }
412 411
413 if (!acpi_gbl_permanent_mmap) { 412 if (!acpi_gbl_permanent_mmap) {
@@ -420,6 +419,15 @@ acpi_get_table(char *signature,
420 return (AE_NOT_FOUND); 419 return (AE_NOT_FOUND);
421} 420}
422 421
422acpi_status
423acpi_get_table(char *signature,
424 u32 instance, struct acpi_table_header **out_table)
425{
426 acpi_size tbl_size;
427
428 return acpi_get_table_with_size(signature,
429 instance, out_table, &tbl_size);
430}
423ACPI_EXPORT_SYMBOL(acpi_get_table) 431ACPI_EXPORT_SYMBOL(acpi_get_table)
424 432
425/******************************************************************************* 433/*******************************************************************************
@@ -491,7 +499,6 @@ ACPI_EXPORT_SYMBOL(acpi_get_table_by_index)
491static acpi_status acpi_tb_load_namespace(void) 499static acpi_status acpi_tb_load_namespace(void)
492{ 500{
493 acpi_status status; 501 acpi_status status;
494 struct acpi_table_header *table;
495 u32 i; 502 u32 i;
496 503
497 ACPI_FUNCTION_TRACE(tb_load_namespace); 504 ACPI_FUNCTION_TRACE(tb_load_namespace);
@@ -515,58 +522,28 @@ static acpi_status acpi_tb_load_namespace(void)
515 goto unlock_and_exit; 522 goto unlock_and_exit;
516 } 523 }
517 524
518 /* 525 /* A valid DSDT is required */
519 * Find DSDT table
520 */
521 status =
522 acpi_os_table_override(acpi_gbl_root_table_list.
523 tables[ACPI_TABLE_INDEX_DSDT].pointer,
524 &table);
525 if (ACPI_SUCCESS(status) && table) {
526 /*
527 * DSDT table has been found
528 */
529 acpi_tb_delete_table(&acpi_gbl_root_table_list.
530 tables[ACPI_TABLE_INDEX_DSDT]);
531 acpi_gbl_root_table_list.tables[ACPI_TABLE_INDEX_DSDT].pointer =
532 table;
533 acpi_gbl_root_table_list.tables[ACPI_TABLE_INDEX_DSDT].length =
534 table->length;
535 acpi_gbl_root_table_list.tables[ACPI_TABLE_INDEX_DSDT].flags =
536 ACPI_TABLE_ORIGIN_UNKNOWN;
537
538 ACPI_INFO((AE_INFO, "Table DSDT replaced by host OS"));
539 acpi_tb_print_table_header(0, table);
540
541 if (no_auto_ssdt == 0) {
542 printk(KERN_WARNING "ACPI: DSDT override uses original SSDTs unless \"acpi_no_auto_ssdt\"\n");
543 }
544 }
545 526
546 status = 527 status =
547 acpi_tb_verify_table(&acpi_gbl_root_table_list. 528 acpi_tb_verify_table(&acpi_gbl_root_table_list.
548 tables[ACPI_TABLE_INDEX_DSDT]); 529 tables[ACPI_TABLE_INDEX_DSDT]);
549 if (ACPI_FAILURE(status)) { 530 if (ACPI_FAILURE(status)) {
550 531
551 /* A valid DSDT is required */
552
553 status = AE_NO_ACPI_TABLES; 532 status = AE_NO_ACPI_TABLES;
554 goto unlock_and_exit; 533 goto unlock_and_exit;
555 } 534 }
556 535
557 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES); 536 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
558 537
559 /* 538 /* Load and parse tables */
560 * Load and parse tables. 539
561 */
562 status = acpi_ns_load_table(ACPI_TABLE_INDEX_DSDT, acpi_gbl_root_node); 540 status = acpi_ns_load_table(ACPI_TABLE_INDEX_DSDT, acpi_gbl_root_node);
563 if (ACPI_FAILURE(status)) { 541 if (ACPI_FAILURE(status)) {
564 return_ACPI_STATUS(status); 542 return_ACPI_STATUS(status);
565 } 543 }
566 544
567 /* 545 /* Load any SSDT or PSDT tables. Note: Loop leaves tables locked */
568 * Load any SSDT or PSDT tables. Note: Loop leaves tables locked 546
569 */
570 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); 547 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
571 for (i = 0; i < acpi_gbl_root_table_list.count; ++i) { 548 for (i = 0; i < acpi_gbl_root_table_list.count; ++i) {
572 if ((!ACPI_COMPARE_NAME 549 if ((!ACPI_COMPARE_NAME
@@ -619,9 +596,8 @@ acpi_status acpi_load_tables(void)
619 596
620 ACPI_FUNCTION_TRACE(acpi_load_tables); 597 ACPI_FUNCTION_TRACE(acpi_load_tables);
621 598
622 /* 599 /* Load the namespace from the tables */
623 * Load the namespace from the tables 600
624 */
625 status = acpi_tb_load_namespace(); 601 status = acpi_tb_load_namespace();
626 if (ACPI_FAILURE(status)) { 602 if (ACPI_FAILURE(status)) {
627 ACPI_EXCEPTION((AE_INFO, status, 603 ACPI_EXCEPTION((AE_INFO, status,
diff --git a/drivers/acpi/acpica/tbxfroot.c b/drivers/acpi/acpica/tbxfroot.c
index b7fc8dd43341..85ea834199e2 100644
--- a/drivers/acpi/acpica/tbxfroot.c
+++ b/drivers/acpi/acpica/tbxfroot.c
@@ -75,8 +75,8 @@ static acpi_status acpi_tb_validate_rsdp(struct acpi_table_rsdp *rsdp)
75 * Note: Sometimes there exists more than one RSDP in memory; the valid 75 * Note: Sometimes there exists more than one RSDP in memory; the valid
76 * RSDP has a valid checksum, all others have an invalid checksum. 76 * RSDP has a valid checksum, all others have an invalid checksum.
77 */ 77 */
78 if (ACPI_STRNCMP((char *)rsdp, ACPI_SIG_RSDP, sizeof(ACPI_SIG_RSDP) - 1) 78 if (ACPI_STRNCMP((char *)rsdp, ACPI_SIG_RSDP,
79 != 0) { 79 sizeof(ACPI_SIG_RSDP) - 1) != 0) {
80 80
81 /* Nope, BAD Signature */ 81 /* Nope, BAD Signature */
82 82
diff --git a/drivers/acpi/acpica/utcopy.c b/drivers/acpi/acpica/utcopy.c
index b0dcfd3c872a..919624f123d5 100644
--- a/drivers/acpi/acpica/utcopy.c
+++ b/drivers/acpi/acpica/utcopy.c
@@ -135,11 +135,11 @@ acpi_ut_copy_isimple_to_esimple(union acpi_operand_object *internal_object,
135 * In general, the external object will be the same type as 135 * In general, the external object will be the same type as
136 * the internal object 136 * the internal object
137 */ 137 */
138 external_object->type = ACPI_GET_OBJECT_TYPE(internal_object); 138 external_object->type = internal_object->common.type;
139 139
140 /* However, only a limited number of external types are supported */ 140 /* However, only a limited number of external types are supported */
141 141
142 switch (ACPI_GET_OBJECT_TYPE(internal_object)) { 142 switch (internal_object->common.type) {
143 case ACPI_TYPE_STRING: 143 case ACPI_TYPE_STRING:
144 144
145 external_object->string.pointer = (char *)data_space; 145 external_object->string.pointer = (char *)data_space;
@@ -222,8 +222,8 @@ acpi_ut_copy_isimple_to_esimple(union acpi_operand_object *internal_object,
222 */ 222 */
223 ACPI_ERROR((AE_INFO, 223 ACPI_ERROR((AE_INFO,
224 "Unsupported object type, cannot convert to external object: %s", 224 "Unsupported object type, cannot convert to external object: %s",
225 acpi_ut_get_type_name(ACPI_GET_OBJECT_TYPE 225 acpi_ut_get_type_name(internal_object->common.
226 (internal_object)))); 226 type)));
227 227
228 return_ACPI_STATUS(AE_SUPPORT); 228 return_ACPI_STATUS(AE_SUPPORT);
229 } 229 }
@@ -355,7 +355,7 @@ acpi_ut_copy_ipackage_to_epackage(union acpi_operand_object *internal_object,
355 info.object_space = 0; 355 info.object_space = 0;
356 info.num_packages = 1; 356 info.num_packages = 1;
357 357
358 external_object->type = ACPI_GET_OBJECT_TYPE(internal_object); 358 external_object->type = internal_object->common.type;
359 external_object->package.count = internal_object->package.count; 359 external_object->package.count = internal_object->package.count;
360 external_object->package.elements = ACPI_CAST_PTR(union acpi_object, 360 external_object->package.elements = ACPI_CAST_PTR(union acpi_object,
361 info.free_space); 361 info.free_space);
@@ -399,7 +399,7 @@ acpi_ut_copy_iobject_to_eobject(union acpi_operand_object *internal_object,
399 399
400 ACPI_FUNCTION_TRACE(ut_copy_iobject_to_eobject); 400 ACPI_FUNCTION_TRACE(ut_copy_iobject_to_eobject);
401 401
402 if (ACPI_GET_OBJECT_TYPE(internal_object) == ACPI_TYPE_PACKAGE) { 402 if (internal_object->common.type == ACPI_TYPE_PACKAGE) {
403 /* 403 /*
404 * Package object: Copy all subobjects (including 404 * Package object: Copy all subobjects (including
405 * nested packages) 405 * nested packages)
@@ -496,8 +496,9 @@ acpi_ut_copy_esimple_to_isimple(union acpi_object *external_object,
496 case ACPI_TYPE_STRING: 496 case ACPI_TYPE_STRING:
497 497
498 internal_object->string.pointer = 498 internal_object->string.pointer =
499 ACPI_ALLOCATE_ZEROED((acpi_size) external_object->string. 499 ACPI_ALLOCATE_ZEROED((acpi_size)
500 length + 1); 500 external_object->string.length + 1);
501
501 if (!internal_object->string.pointer) { 502 if (!internal_object->string.pointer) {
502 goto error_exit; 503 goto error_exit;
503 } 504 }
@@ -697,7 +698,7 @@ acpi_ut_copy_simple_object(union acpi_operand_object *source_desc,
697 698
698 /* Handle the objects with extra data */ 699 /* Handle the objects with extra data */
699 700
700 switch (ACPI_GET_OBJECT_TYPE(dest_desc)) { 701 switch (dest_desc->common.type) {
701 case ACPI_TYPE_BUFFER: 702 case ACPI_TYPE_BUFFER:
702 /* 703 /*
703 * Allocate and copy the actual buffer if and only if: 704 * Allocate and copy the actual buffer if and only if:
@@ -814,8 +815,8 @@ acpi_ut_copy_ielement_to_ielement(u8 object_type,
814 * This is a simple object, just copy it 815 * This is a simple object, just copy it
815 */ 816 */
816 target_object = 817 target_object =
817 acpi_ut_create_internal_object(ACPI_GET_OBJECT_TYPE 818 acpi_ut_create_internal_object(source_object->
818 (source_object)); 819 common.type);
819 if (!target_object) { 820 if (!target_object) {
820 return (AE_NO_MEMORY); 821 return (AE_NO_MEMORY);
821 } 822 }
@@ -892,7 +893,7 @@ acpi_ut_copy_ipackage_to_ipackage(union acpi_operand_object *source_obj,
892 893
893 ACPI_FUNCTION_TRACE(ut_copy_ipackage_to_ipackage); 894 ACPI_FUNCTION_TRACE(ut_copy_ipackage_to_ipackage);
894 895
895 dest_obj->common.type = ACPI_GET_OBJECT_TYPE(source_obj); 896 dest_obj->common.type = source_obj->common.type;
896 dest_obj->common.flags = source_obj->common.flags; 897 dest_obj->common.flags = source_obj->common.flags;
897 dest_obj->package.count = source_obj->package.count; 898 dest_obj->package.count = source_obj->package.count;
898 899
@@ -950,15 +951,14 @@ acpi_ut_copy_iobject_to_iobject(union acpi_operand_object *source_desc,
950 951
951 /* Create the top level object */ 952 /* Create the top level object */
952 953
953 *dest_desc = 954 *dest_desc = acpi_ut_create_internal_object(source_desc->common.type);
954 acpi_ut_create_internal_object(ACPI_GET_OBJECT_TYPE(source_desc));
955 if (!*dest_desc) { 955 if (!*dest_desc) {
956 return_ACPI_STATUS(AE_NO_MEMORY); 956 return_ACPI_STATUS(AE_NO_MEMORY);
957 } 957 }
958 958
959 /* Copy the object and possible subobjects */ 959 /* Copy the object and possible subobjects */
960 960
961 if (ACPI_GET_OBJECT_TYPE(source_desc) == ACPI_TYPE_PACKAGE) { 961 if (source_desc->common.type == ACPI_TYPE_PACKAGE) {
962 status = 962 status =
963 acpi_ut_copy_ipackage_to_ipackage(source_desc, *dest_desc, 963 acpi_ut_copy_ipackage_to_ipackage(source_desc, *dest_desc,
964 walk_state); 964 walk_state);
diff --git a/drivers/acpi/acpica/utdelete.c b/drivers/acpi/acpica/utdelete.c
index a0be9e39531e..a5ee23bc4f55 100644
--- a/drivers/acpi/acpica/utdelete.c
+++ b/drivers/acpi/acpica/utdelete.c
@@ -86,7 +86,7 @@ static void acpi_ut_delete_internal_obj(union acpi_operand_object *object)
86 * Must delete or free any pointers within the object that are not 86 * Must delete or free any pointers within the object that are not
87 * actual ACPI objects (for example, a raw buffer pointer). 87 * actual ACPI objects (for example, a raw buffer pointer).
88 */ 88 */
89 switch (ACPI_GET_OBJECT_TYPE(object)) { 89 switch (object->common.type) {
90 case ACPI_TYPE_STRING: 90 case ACPI_TYPE_STRING:
91 91
92 ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS, 92 ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS,
@@ -382,7 +382,7 @@ acpi_ut_update_ref_count(union acpi_operand_object *object, u32 action)
382 object, new_count)); 382 object, new_count));
383 } 383 }
384 384
385 if (ACPI_GET_OBJECT_TYPE(object) == ACPI_TYPE_METHOD) { 385 if (object->common.type == ACPI_TYPE_METHOD) {
386 ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS, 386 ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS,
387 "Method Obj %p Refs=%X, [Decremented]\n", 387 "Method Obj %p Refs=%X, [Decremented]\n",
388 object, new_count)); 388 object, new_count));
@@ -469,7 +469,7 @@ acpi_ut_update_object_reference(union acpi_operand_object *object, u16 action)
469 * All sub-objects must have their reference count incremented also. 469 * All sub-objects must have their reference count incremented also.
470 * Different object types have different subobjects. 470 * Different object types have different subobjects.
471 */ 471 */
472 switch (ACPI_GET_OBJECT_TYPE(object)) { 472 switch (object->common.type) {
473 case ACPI_TYPE_DEVICE: 473 case ACPI_TYPE_DEVICE:
474 case ACPI_TYPE_PROCESSOR: 474 case ACPI_TYPE_PROCESSOR:
475 case ACPI_TYPE_POWER: 475 case ACPI_TYPE_POWER:
diff --git a/drivers/acpi/acpica/uteval.c b/drivers/acpi/acpica/uteval.c
index da9450bc60f7..006b16c26017 100644
--- a/drivers/acpi/acpica/uteval.c
+++ b/drivers/acpi/acpica/uteval.c
@@ -59,26 +59,35 @@ acpi_ut_translate_one_cid(union acpi_operand_object *obj_desc,
59 59
60/* 60/*
61 * Strings supported by the _OSI predefined (internal) method. 61 * Strings supported by the _OSI predefined (internal) method.
62 *
63 * March 2009: Removed "Linux" as this host no longer wants to respond true
64 * for this string. Basically, the only safe OS strings are windows-related
65 * and in many or most cases represent the only test path within the
66 * BIOS-provided ASL code.
67 *
68 * The second element of each entry is used to track the newest version of
69 * Windows that the BIOS has requested.
62 */ 70 */
63static char *acpi_interfaces_supported[] = { 71static struct acpi_interface_info acpi_interfaces_supported[] = {
64 /* Operating System Vendor Strings */ 72 /* Operating System Vendor Strings */
65 73
66 "Windows 2000", /* Windows 2000 */ 74 {"Windows 2000", ACPI_OSI_WIN_2000}, /* Windows 2000 */
67 "Windows 2001", /* Windows XP */ 75 {"Windows 2001", ACPI_OSI_WIN_XP}, /* Windows XP */
68 "Windows 2001 SP1", /* Windows XP SP1 */ 76 {"Windows 2001 SP1", ACPI_OSI_WIN_XP_SP1}, /* Windows XP SP1 */
69 "Windows 2001 SP2", /* Windows XP SP2 */ 77 {"Windows 2001.1", ACPI_OSI_WINSRV_2003}, /* Windows Server 2003 */
70 "Windows 2001.1", /* Windows Server 2003 */ 78 {"Windows 2001 SP2", ACPI_OSI_WIN_XP_SP2}, /* Windows XP SP2 */
71 "Windows 2001.1 SP1", /* Windows Server 2003 SP1 - Added 03/2006 */ 79 {"Windows 2001.1 SP1", ACPI_OSI_WINSRV_2003_SP1}, /* Windows Server 2003 SP1 - Added 03/2006 */
72 "Windows 2006", /* Windows Vista - Added 03/2006 */ 80 {"Windows 2006", ACPI_OSI_WIN_VISTA}, /* Windows Vista - Added 03/2006 */
73 81
74 /* Feature Group Strings */ 82 /* Feature Group Strings */
75 83
76 "Extended Address Space Descriptor" 84 {"Extended Address Space Descriptor", 0}
77 /* 85
78 * All "optional" feature group strings (features that are implemented 86 /*
79 * by the host) should be implemented in the host version of 87 * All "optional" feature group strings (features that are implemented
80 * acpi_os_validate_interface and should not be added here. 88 * by the host) should be implemented in the host version of
81 */ 89 * acpi_os_validate_interface and should not be added here.
90 */
82}; 91};
83 92
84/******************************************************************************* 93/*******************************************************************************
@@ -98,6 +107,7 @@ acpi_status acpi_ut_osi_implementation(struct acpi_walk_state *walk_state)
98 acpi_status status; 107 acpi_status status;
99 union acpi_operand_object *string_desc; 108 union acpi_operand_object *string_desc;
100 union acpi_operand_object *return_desc; 109 union acpi_operand_object *return_desc;
110 u32 return_value;
101 u32 i; 111 u32 i;
102 112
103 ACPI_FUNCTION_TRACE(ut_osi_implementation); 113 ACPI_FUNCTION_TRACE(ut_osi_implementation);
@@ -116,21 +126,28 @@ acpi_status acpi_ut_osi_implementation(struct acpi_walk_state *walk_state)
116 return_ACPI_STATUS(AE_NO_MEMORY); 126 return_ACPI_STATUS(AE_NO_MEMORY);
117 } 127 }
118 128
119 /* Default return value is SUPPORTED */ 129 /* Default return value is 0, NOT SUPPORTED */
120 130
121 return_desc->integer.value = ACPI_UINT32_MAX; 131 return_value = 0;
122 walk_state->return_desc = return_desc;
123 132
124 /* Compare input string to static table of supported interfaces */ 133 /* Compare input string to static table of supported interfaces */
125 134
126 for (i = 0; i < ACPI_ARRAY_LENGTH(acpi_interfaces_supported); i++) { 135 for (i = 0; i < ACPI_ARRAY_LENGTH(acpi_interfaces_supported); i++) {
127 if (!ACPI_STRCMP 136 if (!ACPI_STRCMP(string_desc->string.pointer,
128 (string_desc->string.pointer, 137 acpi_interfaces_supported[i].name)) {
129 acpi_interfaces_supported[i])) { 138 /*
130 139 * The interface is supported.
131 /* The interface is supported */ 140 * Update the osi_data if necessary. We keep track of the latest
141 * version of Windows that has been requested by the BIOS.
142 */
143 if (acpi_interfaces_supported[i].value >
144 acpi_gbl_osi_data) {
145 acpi_gbl_osi_data =
146 acpi_interfaces_supported[i].value;
147 }
132 148
133 return_ACPI_STATUS(AE_OK); 149 return_value = ACPI_UINT32_MAX;
150 goto exit;
134 } 151 }
135 } 152 }
136 153
@@ -144,13 +161,19 @@ acpi_status acpi_ut_osi_implementation(struct acpi_walk_state *walk_state)
144 161
145 /* The interface is supported */ 162 /* The interface is supported */
146 163
147 return_ACPI_STATUS(AE_OK); 164 return_value = ACPI_UINT32_MAX;
148 } 165 }
149 166
150 /* The interface is not supported */ 167exit:
168 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO,
169 "ACPI: BIOS _OSI(%s) is %ssupported\n",
170 string_desc->string.pointer, return_value == 0 ? "not " : ""));
151 171
152 return_desc->integer.value = 0; 172 /* Complete the return value */
153 return_ACPI_STATUS(AE_OK); 173
174 return_desc->integer.value = return_value;
175 walk_state->return_desc = return_desc;
176 return_ACPI_STATUS (AE_OK);
154} 177}
155 178
156/******************************************************************************* 179/*******************************************************************************
@@ -170,8 +193,8 @@ acpi_status acpi_osi_invalidate(char *interface)
170 int i; 193 int i;
171 194
172 for (i = 0; i < ACPI_ARRAY_LENGTH(acpi_interfaces_supported); i++) { 195 for (i = 0; i < ACPI_ARRAY_LENGTH(acpi_interfaces_supported); i++) {
173 if (!ACPI_STRCMP(interface, acpi_interfaces_supported[i])) { 196 if (!ACPI_STRCMP(interface, acpi_interfaces_supported[i].name)) {
174 *acpi_interfaces_supported[i] = '\0'; 197 *acpi_interfaces_supported[i].name = '\0';
175 return AE_OK; 198 return AE_OK;
176 } 199 }
177 } 200 }
@@ -251,7 +274,7 @@ acpi_ut_evaluate_object(struct acpi_namespace_node *prefix_node,
251 274
252 /* Map the return object type to the bitmapped type */ 275 /* Map the return object type to the bitmapped type */
253 276
254 switch (ACPI_GET_OBJECT_TYPE(info->return_object)) { 277 switch ((info->return_object)->common.type) {
255 case ACPI_TYPE_INTEGER: 278 case ACPI_TYPE_INTEGER:
256 return_btype = ACPI_BTYPE_INTEGER; 279 return_btype = ACPI_BTYPE_INTEGER;
257 break; 280 break;
@@ -421,7 +444,7 @@ acpi_ut_execute_HID(struct acpi_namespace_node *device_node,
421 return_ACPI_STATUS(status); 444 return_ACPI_STATUS(status);
422 } 445 }
423 446
424 if (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_INTEGER) { 447 if (obj_desc->common.type == ACPI_TYPE_INTEGER) {
425 448
426 /* Convert the Numeric HID to string */ 449 /* Convert the Numeric HID to string */
427 450
@@ -462,7 +485,7 @@ acpi_ut_translate_one_cid(union acpi_operand_object *obj_desc,
462 struct acpi_compatible_id *one_cid) 485 struct acpi_compatible_id *one_cid)
463{ 486{
464 487
465 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) { 488 switch (obj_desc->common.type) {
466 case ACPI_TYPE_INTEGER: 489 case ACPI_TYPE_INTEGER:
467 490
468 /* Convert the Numeric CID to string */ 491 /* Convert the Numeric CID to string */
@@ -530,7 +553,7 @@ acpi_ut_execute_CID(struct acpi_namespace_node * device_node,
530 /* Get the number of _CIDs returned */ 553 /* Get the number of _CIDs returned */
531 554
532 count = 1; 555 count = 1;
533 if (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_PACKAGE) { 556 if (obj_desc->common.type == ACPI_TYPE_PACKAGE) {
534 count = obj_desc->package.count; 557 count = obj_desc->package.count;
535 } 558 }
536 559
@@ -558,7 +581,7 @@ acpi_ut_execute_CID(struct acpi_namespace_node * device_node,
558 581
559 /* The _CID object can be either a single CID or a package (list) of CIDs */ 582 /* The _CID object can be either a single CID or a package (list) of CIDs */
560 583
561 if (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_PACKAGE) { 584 if (obj_desc->common.type == ACPI_TYPE_PACKAGE) {
562 585
563 /* Translate each package element */ 586 /* Translate each package element */
564 587
@@ -623,7 +646,7 @@ acpi_ut_execute_UID(struct acpi_namespace_node *device_node,
623 return_ACPI_STATUS(status); 646 return_ACPI_STATUS(status);
624 } 647 }
625 648
626 if (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_INTEGER) { 649 if (obj_desc->common.type == ACPI_TYPE_INTEGER) {
627 650
628 /* Convert the Numeric UID to string */ 651 /* Convert the Numeric UID to string */
629 652
diff --git a/drivers/acpi/acpica/utglobal.c b/drivers/acpi/acpica/utglobal.c
index a3ab9d9da299..59e46f257c02 100644
--- a/drivers/acpi/acpica/utglobal.c
+++ b/drivers/acpi/acpica/utglobal.c
@@ -294,12 +294,9 @@ struct acpi_bit_register_info acpi_gbl_bit_register_info[ACPI_NUM_BITREG] = {
294 /* ACPI_BITREG_GLOBAL_LOCK_RELEASE */ {ACPI_REGISTER_PM1_CONTROL, 294 /* ACPI_BITREG_GLOBAL_LOCK_RELEASE */ {ACPI_REGISTER_PM1_CONTROL,
295 ACPI_BITPOSITION_GLOBAL_LOCK_RELEASE, 295 ACPI_BITPOSITION_GLOBAL_LOCK_RELEASE,
296 ACPI_BITMASK_GLOBAL_LOCK_RELEASE}, 296 ACPI_BITMASK_GLOBAL_LOCK_RELEASE},
297 /* ACPI_BITREG_SLEEP_TYPE_A */ {ACPI_REGISTER_PM1_CONTROL, 297 /* ACPI_BITREG_SLEEP_TYPE */ {ACPI_REGISTER_PM1_CONTROL,
298 ACPI_BITPOSITION_SLEEP_TYPE_X, 298 ACPI_BITPOSITION_SLEEP_TYPE,
299 ACPI_BITMASK_SLEEP_TYPE_X}, 299 ACPI_BITMASK_SLEEP_TYPE},
300 /* ACPI_BITREG_SLEEP_TYPE_B */ {ACPI_REGISTER_PM1_CONTROL,
301 ACPI_BITPOSITION_SLEEP_TYPE_X,
302 ACPI_BITMASK_SLEEP_TYPE_X},
303 /* ACPI_BITREG_SLEEP_ENABLE */ {ACPI_REGISTER_PM1_CONTROL, 300 /* ACPI_BITREG_SLEEP_ENABLE */ {ACPI_REGISTER_PM1_CONTROL,
304 ACPI_BITPOSITION_SLEEP_ENABLE, 301 ACPI_BITPOSITION_SLEEP_ENABLE,
305 ACPI_BITMASK_SLEEP_ENABLE}, 302 ACPI_BITMASK_SLEEP_ENABLE},
@@ -476,7 +473,7 @@ char *acpi_ut_get_object_type_name(union acpi_operand_object *obj_desc)
476 return ("[NULL Object Descriptor]"); 473 return ("[NULL Object Descriptor]");
477 } 474 }
478 475
479 return (acpi_ut_get_type_name(ACPI_GET_OBJECT_TYPE(obj_desc))); 476 return (acpi_ut_get_type_name(obj_desc->common.type));
480} 477}
481 478
482/******************************************************************************* 479/*******************************************************************************
@@ -749,7 +746,10 @@ acpi_status acpi_ut_init_globals(void)
749 for (i = 0; i < ACPI_NUM_OWNERID_MASKS; i++) { 746 for (i = 0; i < ACPI_NUM_OWNERID_MASKS; i++) {
750 acpi_gbl_owner_id_mask[i] = 0; 747 acpi_gbl_owner_id_mask[i] = 0;
751 } 748 }
752 acpi_gbl_owner_id_mask[ACPI_NUM_OWNERID_MASKS - 1] = 0x80000000; /* Last ID is never valid */ 749
750 /* Last owner_iD is never valid */
751
752 acpi_gbl_owner_id_mask[ACPI_NUM_OWNERID_MASKS - 1] = 0x80000000;
753 753
754 /* GPE support */ 754 /* GPE support */
755 755
@@ -789,6 +789,7 @@ acpi_status acpi_ut_init_globals(void)
789 acpi_gbl_trace_dbg_layer = 0; 789 acpi_gbl_trace_dbg_layer = 0;
790 acpi_gbl_debugger_configuration = DEBUGGER_THREADING; 790 acpi_gbl_debugger_configuration = DEBUGGER_THREADING;
791 acpi_gbl_db_output_flags = ACPI_DB_CONSOLE_OUTPUT; 791 acpi_gbl_db_output_flags = ACPI_DB_CONSOLE_OUTPUT;
792 acpi_gbl_osi_data = 0;
792 793
793 /* Hardware oriented */ 794 /* Hardware oriented */
794 795
diff --git a/drivers/acpi/acpica/utlock.c b/drivers/acpi/acpica/utlock.c
new file mode 100644
index 000000000000..25e03120686d
--- /dev/null
+++ b/drivers/acpi/acpica/utlock.c
@@ -0,0 +1,175 @@
1/******************************************************************************
2 *
3 * Module Name: utlock - Reader/Writer lock interfaces
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2009, Intel Corp.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
44#include <acpi/acpi.h>
45#include "accommon.h"
46
47#define _COMPONENT ACPI_UTILITIES
48ACPI_MODULE_NAME("utlock")
49
50/*******************************************************************************
51 *
52 * FUNCTION: acpi_ut_create_rw_lock
53 * acpi_ut_delete_rw_lock
54 *
55 * PARAMETERS: Lock - Pointer to a valid RW lock
56 *
57 * RETURN: Status
58 *
59 * DESCRIPTION: Reader/writer lock creation and deletion interfaces.
60 *
61 ******************************************************************************/
62acpi_status acpi_ut_create_rw_lock(struct acpi_rw_lock *lock)
63{
64 acpi_status status;
65
66 lock->num_readers = 0;
67 status = acpi_os_create_mutex(&lock->reader_mutex);
68 if (ACPI_FAILURE(status)) {
69 return status;
70 }
71
72 status = acpi_os_create_mutex(&lock->writer_mutex);
73 return status;
74}
75
76void acpi_ut_delete_rw_lock(struct acpi_rw_lock *lock)
77{
78
79 acpi_os_delete_mutex(lock->reader_mutex);
80 acpi_os_delete_mutex(lock->writer_mutex);
81
82 lock->num_readers = 0;
83 lock->reader_mutex = NULL;
84 lock->writer_mutex = NULL;
85}
86
87/*******************************************************************************
88 *
89 * FUNCTION: acpi_ut_acquire_read_lock
90 * acpi_ut_release_read_lock
91 *
92 * PARAMETERS: Lock - Pointer to a valid RW lock
93 *
94 * RETURN: Status
95 *
96 * DESCRIPTION: Reader interfaces for reader/writer locks. On acquisition,
97 * only the first reader acquires the write mutex. On release,
98 * only the last reader releases the write mutex. Although this
99 * algorithm can in theory starve writers, this should not be a
100 * problem with ACPICA since the subsystem is infrequently used
101 * in comparison to (for example) an I/O system.
102 *
103 ******************************************************************************/
104
105acpi_status acpi_ut_acquire_read_lock(struct acpi_rw_lock *lock)
106{
107 acpi_status status;
108
109 status = acpi_os_acquire_mutex(lock->reader_mutex, ACPI_WAIT_FOREVER);
110 if (ACPI_FAILURE(status)) {
111 return status;
112 }
113
114 /* Acquire the write lock only for the first reader */
115
116 lock->num_readers++;
117 if (lock->num_readers == 1) {
118 status =
119 acpi_os_acquire_mutex(lock->writer_mutex,
120 ACPI_WAIT_FOREVER);
121 }
122
123 acpi_os_release_mutex(lock->reader_mutex);
124 return status;
125}
126
127acpi_status acpi_ut_release_read_lock(struct acpi_rw_lock *lock)
128{
129 acpi_status status;
130
131 status = acpi_os_acquire_mutex(lock->reader_mutex, ACPI_WAIT_FOREVER);
132 if (ACPI_FAILURE(status)) {
133 return status;
134 }
135
136 /* Release the write lock only for the very last reader */
137
138 lock->num_readers--;
139 if (lock->num_readers == 0) {
140 acpi_os_release_mutex(lock->writer_mutex);
141 }
142
143 acpi_os_release_mutex(lock->reader_mutex);
144 return status;
145}
146
147/*******************************************************************************
148 *
149 * FUNCTION: acpi_ut_acquire_write_lock
150 * acpi_ut_release_write_lock
151 *
152 * PARAMETERS: Lock - Pointer to a valid RW lock
153 *
154 * RETURN: Status
155 *
156 * DESCRIPTION: Writer interfaces for reader/writer locks. Simply acquire or
157 * release the writer mutex associated with the lock. Acquisition
158 * of the lock is fully exclusive and will block all readers and
159 * writers until it is released.
160 *
161 ******************************************************************************/
162
163acpi_status acpi_ut_acquire_write_lock(struct acpi_rw_lock *lock)
164{
165 acpi_status status;
166
167 status = acpi_os_acquire_mutex(lock->writer_mutex, ACPI_WAIT_FOREVER);
168 return status;
169}
170
171void acpi_ut_release_write_lock(struct acpi_rw_lock *lock)
172{
173
174 acpi_os_release_mutex(lock->writer_mutex);
175}
diff --git a/drivers/acpi/acpica/utmisc.c b/drivers/acpi/acpica/utmisc.c
index c1f7f4e1a72d..1c9e250caefb 100644
--- a/drivers/acpi/acpica/utmisc.c
+++ b/drivers/acpi/acpica/utmisc.c
@@ -938,8 +938,7 @@ acpi_ut_walk_package_tree(union acpi_operand_object * source_object,
938 if ((!this_source_obj) || 938 if ((!this_source_obj) ||
939 (ACPI_GET_DESCRIPTOR_TYPE(this_source_obj) != 939 (ACPI_GET_DESCRIPTOR_TYPE(this_source_obj) !=
940 ACPI_DESC_TYPE_OPERAND) 940 ACPI_DESC_TYPE_OPERAND)
941 || (ACPI_GET_OBJECT_TYPE(this_source_obj) != 941 || (this_source_obj->common.type != ACPI_TYPE_PACKAGE)) {
942 ACPI_TYPE_PACKAGE)) {
943 status = 942 status =
944 walk_callback(ACPI_COPY_TYPE_SIMPLE, 943 walk_callback(ACPI_COPY_TYPE_SIMPLE,
945 this_source_obj, state, context); 944 this_source_obj, state, context);
diff --git a/drivers/acpi/acpica/utmutex.c b/drivers/acpi/acpica/utmutex.c
index 14eb52c4d647..26c93a748e64 100644
--- a/drivers/acpi/acpica/utmutex.c
+++ b/drivers/acpi/acpica/utmutex.c
@@ -60,7 +60,8 @@ static acpi_status acpi_ut_delete_mutex(acpi_mutex_handle mutex_id);
60 * 60 *
61 * RETURN: Status 61 * RETURN: Status
62 * 62 *
63 * DESCRIPTION: Create the system mutex objects. 63 * DESCRIPTION: Create the system mutex objects. This includes mutexes,
64 * spin locks, and reader/writer locks.
64 * 65 *
65 ******************************************************************************/ 66 ******************************************************************************/
66 67
@@ -71,9 +72,8 @@ acpi_status acpi_ut_mutex_initialize(void)
71 72
72 ACPI_FUNCTION_TRACE(ut_mutex_initialize); 73 ACPI_FUNCTION_TRACE(ut_mutex_initialize);
73 74
74 /* 75 /* Create each of the predefined mutex objects */
75 * Create each of the predefined mutex objects 76
76 */
77 for (i = 0; i < ACPI_NUM_MUTEX; i++) { 77 for (i = 0; i < ACPI_NUM_MUTEX; i++) {
78 status = acpi_ut_create_mutex(i); 78 status = acpi_ut_create_mutex(i);
79 if (ACPI_FAILURE(status)) { 79 if (ACPI_FAILURE(status)) {
@@ -86,6 +86,9 @@ acpi_status acpi_ut_mutex_initialize(void)
86 spin_lock_init(acpi_gbl_gpe_lock); 86 spin_lock_init(acpi_gbl_gpe_lock);
87 spin_lock_init(acpi_gbl_hardware_lock); 87 spin_lock_init(acpi_gbl_hardware_lock);
88 88
89 /* Create the reader/writer lock for namespace access */
90
91 status = acpi_ut_create_rw_lock(&acpi_gbl_namespace_rw_lock);
89 return_ACPI_STATUS(status); 92 return_ACPI_STATUS(status);
90} 93}
91 94
@@ -97,7 +100,8 @@ acpi_status acpi_ut_mutex_initialize(void)
97 * 100 *
98 * RETURN: None. 101 * RETURN: None.
99 * 102 *
100 * DESCRIPTION: Delete all of the system mutex objects. 103 * DESCRIPTION: Delete all of the system mutex objects. This includes mutexes,
104 * spin locks, and reader/writer locks.
101 * 105 *
102 ******************************************************************************/ 106 ******************************************************************************/
103 107
@@ -107,9 +111,8 @@ void acpi_ut_mutex_terminate(void)
107 111
108 ACPI_FUNCTION_TRACE(ut_mutex_terminate); 112 ACPI_FUNCTION_TRACE(ut_mutex_terminate);
109 113
110 /* 114 /* Delete each predefined mutex object */
111 * Delete each predefined mutex object 115
112 */
113 for (i = 0; i < ACPI_NUM_MUTEX; i++) { 116 for (i = 0; i < ACPI_NUM_MUTEX; i++) {
114 (void)acpi_ut_delete_mutex(i); 117 (void)acpi_ut_delete_mutex(i);
115 } 118 }
@@ -118,6 +121,10 @@ void acpi_ut_mutex_terminate(void)
118 121
119 acpi_os_delete_lock(acpi_gbl_gpe_lock); 122 acpi_os_delete_lock(acpi_gbl_gpe_lock);
120 acpi_os_delete_lock(acpi_gbl_hardware_lock); 123 acpi_os_delete_lock(acpi_gbl_hardware_lock);
124
125 /* Delete the reader/writer lock */
126
127 acpi_ut_delete_rw_lock(&acpi_gbl_namespace_rw_lock);
121 return_VOID; 128 return_VOID;
122} 129}
123 130
diff --git a/drivers/acpi/acpica/utobject.c b/drivers/acpi/acpica/utobject.c
index fd5ea7543e5b..0207b625274a 100644
--- a/drivers/acpi/acpica/utobject.c
+++ b/drivers/acpi/acpica/utobject.c
@@ -310,7 +310,7 @@ u8 acpi_ut_valid_internal_object(void *object)
310 /* Check for a null pointer */ 310 /* Check for a null pointer */
311 311
312 if (!object) { 312 if (!object) {
313 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "**** Null Object Ptr\n")); 313 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "**** Null Object Ptr\n"));
314 return (FALSE); 314 return (FALSE);
315 } 315 }
316 316
@@ -324,7 +324,7 @@ u8 acpi_ut_valid_internal_object(void *object)
324 return (TRUE); 324 return (TRUE);
325 325
326 default: 326 default:
327 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 327 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
328 "%p is not not an ACPI operand obj [%s]\n", 328 "%p is not not an ACPI operand obj [%s]\n",
329 object, acpi_ut_get_descriptor_name(object))); 329 object, acpi_ut_get_descriptor_name(object)));
330 break; 330 break;
@@ -457,7 +457,7 @@ acpi_ut_get_simple_object_size(union acpi_operand_object *internal_object,
457 * must be accessed bytewise or there may be alignment problems on 457 * must be accessed bytewise or there may be alignment problems on
458 * certain processors 458 * certain processors
459 */ 459 */
460 switch (ACPI_GET_OBJECT_TYPE(internal_object)) { 460 switch (internal_object->common.type) {
461 case ACPI_TYPE_STRING: 461 case ACPI_TYPE_STRING:
462 462
463 length += (acpi_size) internal_object->string.length + 1; 463 length += (acpi_size) internal_object->string.length + 1;
@@ -518,8 +518,7 @@ acpi_ut_get_simple_object_size(union acpi_operand_object *internal_object,
518 ACPI_ERROR((AE_INFO, "Cannot convert to external object - " 518 ACPI_ERROR((AE_INFO, "Cannot convert to external object - "
519 "unsupported type [%s] %X in object %p", 519 "unsupported type [%s] %X in object %p",
520 acpi_ut_get_object_type_name(internal_object), 520 acpi_ut_get_object_type_name(internal_object),
521 ACPI_GET_OBJECT_TYPE(internal_object), 521 internal_object->common.type, internal_object));
522 internal_object));
523 status = AE_TYPE; 522 status = AE_TYPE;
524 break; 523 break;
525 } 524 }
@@ -664,7 +663,7 @@ acpi_ut_get_object_size(union acpi_operand_object *internal_object,
664 663
665 if ((ACPI_GET_DESCRIPTOR_TYPE(internal_object) == 664 if ((ACPI_GET_DESCRIPTOR_TYPE(internal_object) ==
666 ACPI_DESC_TYPE_OPERAND) 665 ACPI_DESC_TYPE_OPERAND)
667 && (ACPI_GET_OBJECT_TYPE(internal_object) == ACPI_TYPE_PACKAGE)) { 666 && (internal_object->common.type == ACPI_TYPE_PACKAGE)) {
668 status = 667 status =
669 acpi_ut_get_package_object_size(internal_object, 668 acpi_ut_get_package_object_size(internal_object,
670 obj_length); 669 obj_length);
diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index 65132f920459..b0de6312919a 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -30,6 +30,7 @@
30#include <linux/init.h> 30#include <linux/init.h>
31#include <linux/types.h> 31#include <linux/types.h>
32#include <linux/jiffies.h> 32#include <linux/jiffies.h>
33#include <linux/async.h>
33 34
34#ifdef CONFIG_ACPI_PROCFS_POWER 35#ifdef CONFIG_ACPI_PROCFS_POWER
35#include <linux/proc_fs.h> 36#include <linux/proc_fs.h>
@@ -92,7 +93,7 @@ struct acpi_battery {
92#endif 93#endif
93 struct acpi_device *device; 94 struct acpi_device *device;
94 unsigned long update_time; 95 unsigned long update_time;
95 int current_now; 96 int rate_now;
96 int capacity_now; 97 int capacity_now;
97 int voltage_now; 98 int voltage_now;
98 int design_capacity; 99 int design_capacity;
@@ -138,6 +139,29 @@ static int acpi_battery_technology(struct acpi_battery *battery)
138 139
139static int acpi_battery_get_state(struct acpi_battery *battery); 140static int acpi_battery_get_state(struct acpi_battery *battery);
140 141
142static int acpi_battery_is_charged(struct acpi_battery *battery)
143{
144 /* either charging or discharging */
145 if (battery->state != 0)
146 return 0;
147
148 /* battery not reporting charge */
149 if (battery->capacity_now == ACPI_BATTERY_VALUE_UNKNOWN ||
150 battery->capacity_now == 0)
151 return 0;
152
153 /* good batteries update full_charge as the batteries degrade */
154 if (battery->full_charge_capacity == battery->capacity_now)
155 return 1;
156
157 /* fallback to using design values for broken batteries */
158 if (battery->design_capacity == battery->capacity_now)
159 return 1;
160
161 /* we don't do any sort of metric based on percentages */
162 return 0;
163}
164
141static int acpi_battery_get_property(struct power_supply *psy, 165static int acpi_battery_get_property(struct power_supply *psy,
142 enum power_supply_property psp, 166 enum power_supply_property psp,
143 union power_supply_propval *val) 167 union power_supply_propval *val)
@@ -155,7 +179,7 @@ static int acpi_battery_get_property(struct power_supply *psy,
155 val->intval = POWER_SUPPLY_STATUS_DISCHARGING; 179 val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
156 else if (battery->state & 0x02) 180 else if (battery->state & 0x02)
157 val->intval = POWER_SUPPLY_STATUS_CHARGING; 181 val->intval = POWER_SUPPLY_STATUS_CHARGING;
158 else if (battery->state == 0) 182 else if (acpi_battery_is_charged(battery))
159 val->intval = POWER_SUPPLY_STATUS_FULL; 183 val->intval = POWER_SUPPLY_STATUS_FULL;
160 else 184 else
161 val->intval = POWER_SUPPLY_STATUS_UNKNOWN; 185 val->intval = POWER_SUPPLY_STATUS_UNKNOWN;
@@ -173,7 +197,8 @@ static int acpi_battery_get_property(struct power_supply *psy,
173 val->intval = battery->voltage_now * 1000; 197 val->intval = battery->voltage_now * 1000;
174 break; 198 break;
175 case POWER_SUPPLY_PROP_CURRENT_NOW: 199 case POWER_SUPPLY_PROP_CURRENT_NOW:
176 val->intval = battery->current_now * 1000; 200 case POWER_SUPPLY_PROP_POWER_NOW:
201 val->intval = battery->rate_now * 1000;
177 break; 202 break;
178 case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN: 203 case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN:
179 case POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN: 204 case POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN:
@@ -224,6 +249,7 @@ static enum power_supply_property energy_battery_props[] = {
224 POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN, 249 POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN,
225 POWER_SUPPLY_PROP_VOLTAGE_NOW, 250 POWER_SUPPLY_PROP_VOLTAGE_NOW,
226 POWER_SUPPLY_PROP_CURRENT_NOW, 251 POWER_SUPPLY_PROP_CURRENT_NOW,
252 POWER_SUPPLY_PROP_POWER_NOW,
227 POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN, 253 POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN,
228 POWER_SUPPLY_PROP_ENERGY_FULL, 254 POWER_SUPPLY_PROP_ENERGY_FULL,
229 POWER_SUPPLY_PROP_ENERGY_NOW, 255 POWER_SUPPLY_PROP_ENERGY_NOW,
@@ -250,7 +276,7 @@ struct acpi_offsets {
250 276
251static struct acpi_offsets state_offsets[] = { 277static struct acpi_offsets state_offsets[] = {
252 {offsetof(struct acpi_battery, state), 0}, 278 {offsetof(struct acpi_battery, state), 0},
253 {offsetof(struct acpi_battery, current_now), 0}, 279 {offsetof(struct acpi_battery, rate_now), 0},
254 {offsetof(struct acpi_battery, capacity_now), 0}, 280 {offsetof(struct acpi_battery, capacity_now), 0},
255 {offsetof(struct acpi_battery, voltage_now), 0}, 281 {offsetof(struct acpi_battery, voltage_now), 0},
256}; 282};
@@ -582,11 +608,11 @@ static int acpi_battery_print_state(struct seq_file *seq, int result)
582 else 608 else
583 seq_printf(seq, "charging state: charged\n"); 609 seq_printf(seq, "charging state: charged\n");
584 610
585 if (battery->current_now == ACPI_BATTERY_VALUE_UNKNOWN) 611 if (battery->rate_now == ACPI_BATTERY_VALUE_UNKNOWN)
586 seq_printf(seq, "present rate: unknown\n"); 612 seq_printf(seq, "present rate: unknown\n");
587 else 613 else
588 seq_printf(seq, "present rate: %d %s\n", 614 seq_printf(seq, "present rate: %d %s\n",
589 battery->current_now, acpi_battery_units(battery)); 615 battery->rate_now, acpi_battery_units(battery));
590 616
591 if (battery->capacity_now == ACPI_BATTERY_VALUE_UNKNOWN) 617 if (battery->capacity_now == ACPI_BATTERY_VALUE_UNKNOWN)
592 seq_printf(seq, "remaining capacity: unknown\n"); 618 seq_printf(seq, "remaining capacity: unknown\n");
@@ -717,7 +743,7 @@ DECLARE_FILE_FUNCTIONS(alarm);
717static struct battery_file { 743static struct battery_file {
718 struct file_operations ops; 744 struct file_operations ops;
719 mode_t mode; 745 mode_t mode;
720 char *name; 746 const char *name;
721} acpi_battery_file[] = { 747} acpi_battery_file[] = {
722 FILE_DESCRIPTION_RO(info), 748 FILE_DESCRIPTION_RO(info),
723 FILE_DESCRIPTION_RO(state), 749 FILE_DESCRIPTION_RO(state),
@@ -737,7 +763,6 @@ static int acpi_battery_add_fs(struct acpi_device *device)
737 acpi_battery_dir); 763 acpi_battery_dir);
738 if (!acpi_device_dir(device)) 764 if (!acpi_device_dir(device))
739 return -ENODEV; 765 return -ENODEV;
740 acpi_device_dir(device)->owner = THIS_MODULE;
741 } 766 }
742 767
743 for (i = 0; i < ACPI_BATTERY_NUMFILES; ++i) { 768 for (i = 0; i < ACPI_BATTERY_NUMFILES; ++i) {
@@ -878,21 +903,27 @@ static struct acpi_driver acpi_battery_driver = {
878 }, 903 },
879}; 904};
880 905
881static int __init acpi_battery_init(void) 906static void __init acpi_battery_init_async(void *unused, async_cookie_t cookie)
882{ 907{
883 if (acpi_disabled) 908 if (acpi_disabled)
884 return -ENODEV; 909 return;
885#ifdef CONFIG_ACPI_PROCFS_POWER 910#ifdef CONFIG_ACPI_PROCFS_POWER
886 acpi_battery_dir = acpi_lock_battery_dir(); 911 acpi_battery_dir = acpi_lock_battery_dir();
887 if (!acpi_battery_dir) 912 if (!acpi_battery_dir)
888 return -ENODEV; 913 return;
889#endif 914#endif
890 if (acpi_bus_register_driver(&acpi_battery_driver) < 0) { 915 if (acpi_bus_register_driver(&acpi_battery_driver) < 0) {
891#ifdef CONFIG_ACPI_PROCFS_POWER 916#ifdef CONFIG_ACPI_PROCFS_POWER
892 acpi_unlock_battery_dir(acpi_battery_dir); 917 acpi_unlock_battery_dir(acpi_battery_dir);
893#endif 918#endif
894 return -ENODEV; 919 return;
895 } 920 }
921 return;
922}
923
924static int __init acpi_battery_init(void)
925{
926 async_schedule(acpi_battery_init_async, NULL);
896 return 0; 927 return 0;
897} 928}
898 929
diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c
index 765fd1c56cd6..e8f7b64e92da 100644
--- a/drivers/acpi/bus.c
+++ b/drivers/acpi/bus.c
@@ -39,6 +39,8 @@
39#include <acpi/acpi_bus.h> 39#include <acpi/acpi_bus.h>
40#include <acpi/acpi_drivers.h> 40#include <acpi/acpi_drivers.h>
41 41
42#include "internal.h"
43
42#define _COMPONENT ACPI_BUS_COMPONENT 44#define _COMPONENT ACPI_BUS_COMPONENT
43ACPI_MODULE_NAME("bus"); 45ACPI_MODULE_NAME("bus");
44 46
@@ -758,8 +760,7 @@ static int __init acpi_bus_init(void)
758 acpi_status status = AE_OK; 760 acpi_status status = AE_OK;
759 extern acpi_status acpi_os_initialize1(void); 761 extern acpi_status acpi_os_initialize1(void);
760 762
761 763 acpi_os_initialize1();
762 status = acpi_os_initialize1();
763 764
764 status = 765 status =
765 acpi_enable_subsystem(ACPI_NO_HARDWARE_INIT | ACPI_NO_ACPI_ENABLE); 766 acpi_enable_subsystem(ACPI_NO_HARDWARE_INIT | ACPI_NO_ACPI_ENABLE);
@@ -769,12 +770,6 @@ static int __init acpi_bus_init(void)
769 goto error1; 770 goto error1;
770 } 771 }
771 772
772 if (ACPI_FAILURE(status)) {
773 printk(KERN_ERR PREFIX
774 "Unable to initialize ACPI OS objects\n");
775 goto error1;
776 }
777
778 /* 773 /*
779 * ACPI 2.0 requires the EC driver to be loaded and work before 774 * ACPI 2.0 requires the EC driver to be loaded and work before
780 * the EC device is found in the namespace (i.e. before acpi_initialize_objects() 775 * the EC device is found in the namespace (i.e. before acpi_initialize_objects()
@@ -853,6 +848,7 @@ static int __init acpi_init(void)
853 acpi_kobj = NULL; 848 acpi_kobj = NULL;
854 } 849 }
855 850
851 init_acpi_device_notify();
856 result = acpi_bus_init(); 852 result = acpi_bus_init();
857 853
858 if (!result) { 854 if (!result) {
@@ -867,11 +863,23 @@ static int __init acpi_init(void)
867 } 863 }
868 } else 864 } else
869 disable_acpi(); 865 disable_acpi();
866
867 if (acpi_disabled)
868 return result;
869
870 /* 870 /*
871 * If the laptop falls into the DMI check table, the power state check 871 * If the laptop falls into the DMI check table, the power state check
872 * will be disabled in the course of device power transistion. 872 * will be disabled in the course of device power transistion.
873 */ 873 */
874 dmi_check_system(power_nocheck_dmi_table); 874 dmi_check_system(power_nocheck_dmi_table);
875
876 acpi_scan_init();
877 acpi_ec_init();
878 acpi_power_init();
879 acpi_system_init();
880 acpi_debug_init();
881 acpi_sleep_proc_init();
882 acpi_wakeup_device_init();
875 return result; 883 return result;
876} 884}
877 885
diff --git a/drivers/acpi/button.c b/drivers/acpi/button.c
index 171fd914f435..9195deba9d94 100644
--- a/drivers/acpi/button.c
+++ b/drivers/acpi/button.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * acpi_button.c - ACPI Button Driver ($Revision: 30 $) 2 * button.c - ACPI Button Driver
3 * 3 *
4 * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com> 4 * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
5 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com> 5 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
@@ -41,17 +41,13 @@
41 41
42#define ACPI_BUTTON_SUBCLASS_POWER "power" 42#define ACPI_BUTTON_SUBCLASS_POWER "power"
43#define ACPI_BUTTON_HID_POWER "PNP0C0C" 43#define ACPI_BUTTON_HID_POWER "PNP0C0C"
44#define ACPI_BUTTON_DEVICE_NAME_POWER "Power Button (CM)" 44#define ACPI_BUTTON_DEVICE_NAME_POWER "Power Button"
45#define ACPI_BUTTON_DEVICE_NAME_POWERF "Power Button (FF)"
46#define ACPI_BUTTON_TYPE_POWER 0x01 45#define ACPI_BUTTON_TYPE_POWER 0x01
47#define ACPI_BUTTON_TYPE_POWERF 0x02
48 46
49#define ACPI_BUTTON_SUBCLASS_SLEEP "sleep" 47#define ACPI_BUTTON_SUBCLASS_SLEEP "sleep"
50#define ACPI_BUTTON_HID_SLEEP "PNP0C0E" 48#define ACPI_BUTTON_HID_SLEEP "PNP0C0E"
51#define ACPI_BUTTON_DEVICE_NAME_SLEEP "Sleep Button (CM)" 49#define ACPI_BUTTON_DEVICE_NAME_SLEEP "Sleep Button"
52#define ACPI_BUTTON_DEVICE_NAME_SLEEPF "Sleep Button (FF)"
53#define ACPI_BUTTON_TYPE_SLEEP 0x03 50#define ACPI_BUTTON_TYPE_SLEEP 0x03
54#define ACPI_BUTTON_TYPE_SLEEPF 0x04
55 51
56#define ACPI_BUTTON_SUBCLASS_LID "lid" 52#define ACPI_BUTTON_SUBCLASS_LID "lid"
57#define ACPI_BUTTON_HID_LID "PNP0C0D" 53#define ACPI_BUTTON_HID_LID "PNP0C0D"
@@ -78,6 +74,7 @@ MODULE_DEVICE_TABLE(acpi, button_device_ids);
78static int acpi_button_add(struct acpi_device *device); 74static int acpi_button_add(struct acpi_device *device);
79static int acpi_button_remove(struct acpi_device *device, int type); 75static int acpi_button_remove(struct acpi_device *device, int type);
80static int acpi_button_resume(struct acpi_device *device); 76static int acpi_button_resume(struct acpi_device *device);
77static void acpi_button_notify(struct acpi_device *device, u32 event);
81static int acpi_button_info_open_fs(struct inode *inode, struct file *file); 78static int acpi_button_info_open_fs(struct inode *inode, struct file *file);
82static int acpi_button_state_open_fs(struct inode *inode, struct file *file); 79static int acpi_button_state_open_fs(struct inode *inode, struct file *file);
83 80
@@ -89,11 +86,11 @@ static struct acpi_driver acpi_button_driver = {
89 .add = acpi_button_add, 86 .add = acpi_button_add,
90 .resume = acpi_button_resume, 87 .resume = acpi_button_resume,
91 .remove = acpi_button_remove, 88 .remove = acpi_button_remove,
89 .notify = acpi_button_notify,
92 }, 90 },
93}; 91};
94 92
95struct acpi_button { 93struct acpi_button {
96 struct acpi_device *device; /* Fixed button kludge */
97 unsigned int type; 94 unsigned int type;
98 struct input_dev *input; 95 struct input_dev *input;
99 char phys[32]; /* for input device */ 96 char phys[32]; /* for input device */
@@ -124,14 +121,10 @@ static struct proc_dir_entry *acpi_button_dir;
124 121
125static int acpi_button_info_seq_show(struct seq_file *seq, void *offset) 122static int acpi_button_info_seq_show(struct seq_file *seq, void *offset)
126{ 123{
127 struct acpi_button *button = seq->private; 124 struct acpi_device *device = seq->private;
128
129 if (!button || !button->device)
130 return 0;
131 125
132 seq_printf(seq, "type: %s\n", 126 seq_printf(seq, "type: %s\n",
133 acpi_device_name(button->device)); 127 acpi_device_name(device));
134
135 return 0; 128 return 0;
136} 129}
137 130
@@ -142,14 +135,11 @@ static int acpi_button_info_open_fs(struct inode *inode, struct file *file)
142 135
143static int acpi_button_state_seq_show(struct seq_file *seq, void *offset) 136static int acpi_button_state_seq_show(struct seq_file *seq, void *offset)
144{ 137{
145 struct acpi_button *button = seq->private; 138 struct acpi_device *device = seq->private;
146 acpi_status status; 139 acpi_status status;
147 unsigned long long state; 140 unsigned long long state;
148 141
149 if (!button || !button->device) 142 status = acpi_evaluate_integer(device->handle, "_LID", NULL, &state);
150 return 0;
151
152 status = acpi_evaluate_integer(button->device->handle, "_LID", NULL, &state);
153 seq_printf(seq, "state: %s\n", 143 seq_printf(seq, "state: %s\n",
154 ACPI_FAILURE(status) ? "unsupported" : 144 ACPI_FAILURE(status) ? "unsupported" :
155 (state ? "open" : "closed")); 145 (state ? "open" : "closed"));
@@ -167,24 +157,17 @@ static struct proc_dir_entry *acpi_lid_dir;
167 157
168static int acpi_button_add_fs(struct acpi_device *device) 158static int acpi_button_add_fs(struct acpi_device *device)
169{ 159{
160 struct acpi_button *button = acpi_driver_data(device);
170 struct proc_dir_entry *entry = NULL; 161 struct proc_dir_entry *entry = NULL;
171 struct acpi_button *button;
172
173 if (!device || !acpi_driver_data(device))
174 return -EINVAL;
175
176 button = acpi_driver_data(device);
177 162
178 switch (button->type) { 163 switch (button->type) {
179 case ACPI_BUTTON_TYPE_POWER: 164 case ACPI_BUTTON_TYPE_POWER:
180 case ACPI_BUTTON_TYPE_POWERF:
181 if (!acpi_power_dir) 165 if (!acpi_power_dir)
182 acpi_power_dir = proc_mkdir(ACPI_BUTTON_SUBCLASS_POWER, 166 acpi_power_dir = proc_mkdir(ACPI_BUTTON_SUBCLASS_POWER,
183 acpi_button_dir); 167 acpi_button_dir);
184 entry = acpi_power_dir; 168 entry = acpi_power_dir;
185 break; 169 break;
186 case ACPI_BUTTON_TYPE_SLEEP: 170 case ACPI_BUTTON_TYPE_SLEEP:
187 case ACPI_BUTTON_TYPE_SLEEPF:
188 if (!acpi_sleep_dir) 171 if (!acpi_sleep_dir)
189 acpi_sleep_dir = proc_mkdir(ACPI_BUTTON_SUBCLASS_SLEEP, 172 acpi_sleep_dir = proc_mkdir(ACPI_BUTTON_SUBCLASS_SLEEP,
190 acpi_button_dir); 173 acpi_button_dir);
@@ -200,18 +183,15 @@ static int acpi_button_add_fs(struct acpi_device *device)
200 183
201 if (!entry) 184 if (!entry)
202 return -ENODEV; 185 return -ENODEV;
203 entry->owner = THIS_MODULE;
204 186
205 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), entry); 187 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), entry);
206 if (!acpi_device_dir(device)) 188 if (!acpi_device_dir(device))
207 return -ENODEV; 189 return -ENODEV;
208 acpi_device_dir(device)->owner = THIS_MODULE;
209 190
210 /* 'info' [R] */ 191 /* 'info' [R] */
211 entry = proc_create_data(ACPI_BUTTON_FILE_INFO, 192 entry = proc_create_data(ACPI_BUTTON_FILE_INFO,
212 S_IRUGO, acpi_device_dir(device), 193 S_IRUGO, acpi_device_dir(device),
213 &acpi_button_info_fops, 194 &acpi_button_info_fops, device);
214 acpi_driver_data(device));
215 if (!entry) 195 if (!entry)
216 return -ENODEV; 196 return -ENODEV;
217 197
@@ -219,8 +199,7 @@ static int acpi_button_add_fs(struct acpi_device *device)
219 if (button->type == ACPI_BUTTON_TYPE_LID) { 199 if (button->type == ACPI_BUTTON_TYPE_LID) {
220 entry = proc_create_data(ACPI_BUTTON_FILE_STATE, 200 entry = proc_create_data(ACPI_BUTTON_FILE_STATE,
221 S_IRUGO, acpi_device_dir(device), 201 S_IRUGO, acpi_device_dir(device),
222 &acpi_button_state_fops, 202 &acpi_button_state_fops, device);
223 acpi_driver_data(device));
224 if (!entry) 203 if (!entry)
225 return -ENODEV; 204 return -ENODEV;
226 } 205 }
@@ -250,34 +229,35 @@ static int acpi_button_remove_fs(struct acpi_device *device)
250/* -------------------------------------------------------------------------- 229/* --------------------------------------------------------------------------
251 Driver Interface 230 Driver Interface
252 -------------------------------------------------------------------------- */ 231 -------------------------------------------------------------------------- */
253static int acpi_lid_send_state(struct acpi_button *button) 232static int acpi_lid_send_state(struct acpi_device *device)
254{ 233{
234 struct acpi_button *button = acpi_driver_data(device);
255 unsigned long long state; 235 unsigned long long state;
256 acpi_status status; 236 acpi_status status;
257 237
258 status = acpi_evaluate_integer(button->device->handle, "_LID", NULL, 238 status = acpi_evaluate_integer(device->handle, "_LID", NULL, &state);
259 &state);
260 if (ACPI_FAILURE(status)) 239 if (ACPI_FAILURE(status))
261 return -ENODEV; 240 return -ENODEV;
241
262 /* input layer checks if event is redundant */ 242 /* input layer checks if event is redundant */
263 input_report_switch(button->input, SW_LID, !state); 243 input_report_switch(button->input, SW_LID, !state);
264 input_sync(button->input); 244 input_sync(button->input);
265 return 0; 245 return 0;
266} 246}
267 247
268static void acpi_button_notify(acpi_handle handle, u32 event, void *data) 248static void acpi_button_notify(struct acpi_device *device, u32 event)
269{ 249{
270 struct acpi_button *button = data; 250 struct acpi_button *button = acpi_driver_data(device);
271 struct input_dev *input; 251 struct input_dev *input;
272 252
273 if (!button || !button->device)
274 return;
275
276 switch (event) { 253 switch (event) {
254 case ACPI_FIXED_HARDWARE_EVENT:
255 event = ACPI_BUTTON_NOTIFY_STATUS;
256 /* fall through */
277 case ACPI_BUTTON_NOTIFY_STATUS: 257 case ACPI_BUTTON_NOTIFY_STATUS:
278 input = button->input; 258 input = button->input;
279 if (button->type == ACPI_BUTTON_TYPE_LID) { 259 if (button->type == ACPI_BUTTON_TYPE_LID) {
280 acpi_lid_send_state(button); 260 acpi_lid_send_state(device);
281 } else { 261 } else {
282 int keycode = test_bit(KEY_SLEEP, input->keybit) ? 262 int keycode = test_bit(KEY_SLEEP, input->keybit) ?
283 KEY_SLEEP : KEY_POWER; 263 KEY_SLEEP : KEY_POWER;
@@ -288,102 +268,35 @@ static void acpi_button_notify(acpi_handle handle, u32 event, void *data)
288 input_sync(input); 268 input_sync(input);
289 } 269 }
290 270
291 acpi_bus_generate_proc_event(button->device, event, 271 acpi_bus_generate_proc_event(device, event, ++button->pushed);
292 ++button->pushed);
293 break; 272 break;
294 default: 273 default:
295 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 274 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
296 "Unsupported event [0x%x]\n", event)); 275 "Unsupported event [0x%x]\n", event));
297 break; 276 break;
298 } 277 }
299
300 return;
301}
302
303static acpi_status acpi_button_notify_fixed(void *data)
304{
305 struct acpi_button *button = data;
306
307 if (!button)
308 return AE_BAD_PARAMETER;
309
310 acpi_button_notify(button->device->handle, ACPI_BUTTON_NOTIFY_STATUS, button);
311
312 return AE_OK;
313}
314
315static int acpi_button_install_notify_handlers(struct acpi_button *button)
316{
317 acpi_status status;
318
319 switch (button->type) {
320 case ACPI_BUTTON_TYPE_POWERF:
321 status =
322 acpi_install_fixed_event_handler(ACPI_EVENT_POWER_BUTTON,
323 acpi_button_notify_fixed,
324 button);
325 break;
326 case ACPI_BUTTON_TYPE_SLEEPF:
327 status =
328 acpi_install_fixed_event_handler(ACPI_EVENT_SLEEP_BUTTON,
329 acpi_button_notify_fixed,
330 button);
331 break;
332 default:
333 status = acpi_install_notify_handler(button->device->handle,
334 ACPI_DEVICE_NOTIFY,
335 acpi_button_notify,
336 button);
337 break;
338 }
339
340 return ACPI_FAILURE(status) ? -ENODEV : 0;
341} 278}
342 279
343static int acpi_button_resume(struct acpi_device *device) 280static int acpi_button_resume(struct acpi_device *device)
344{ 281{
345 struct acpi_button *button; 282 struct acpi_button *button = acpi_driver_data(device);
346 if (!device)
347 return -EINVAL;
348 button = acpi_driver_data(device);
349 if (button && button->type == ACPI_BUTTON_TYPE_LID)
350 return acpi_lid_send_state(button);
351 return 0;
352}
353 283
354static void acpi_button_remove_notify_handlers(struct acpi_button *button) 284 if (button->type == ACPI_BUTTON_TYPE_LID)
355{ 285 return acpi_lid_send_state(device);
356 switch (button->type) { 286 return 0;
357 case ACPI_BUTTON_TYPE_POWERF:
358 acpi_remove_fixed_event_handler(ACPI_EVENT_POWER_BUTTON,
359 acpi_button_notify_fixed);
360 break;
361 case ACPI_BUTTON_TYPE_SLEEPF:
362 acpi_remove_fixed_event_handler(ACPI_EVENT_SLEEP_BUTTON,
363 acpi_button_notify_fixed);
364 break;
365 default:
366 acpi_remove_notify_handler(button->device->handle,
367 ACPI_DEVICE_NOTIFY,
368 acpi_button_notify);
369 break;
370 }
371} 287}
372 288
373static int acpi_button_add(struct acpi_device *device) 289static int acpi_button_add(struct acpi_device *device)
374{ 290{
375 int error;
376 struct acpi_button *button; 291 struct acpi_button *button;
377 struct input_dev *input; 292 struct input_dev *input;
378 293 char *hid, *name, *class;
379 if (!device) 294 int error;
380 return -EINVAL;
381 295
382 button = kzalloc(sizeof(struct acpi_button), GFP_KERNEL); 296 button = kzalloc(sizeof(struct acpi_button), GFP_KERNEL);
383 if (!button) 297 if (!button)
384 return -ENOMEM; 298 return -ENOMEM;
385 299
386 button->device = device;
387 device->driver_data = button; 300 device->driver_data = button;
388 301
389 button->input = input = input_allocate_device(); 302 button->input = input = input_allocate_device();
@@ -392,40 +305,29 @@ static int acpi_button_add(struct acpi_device *device)
392 goto err_free_button; 305 goto err_free_button;
393 } 306 }
394 307
395 /* 308 hid = acpi_device_hid(device);
396 * Determine the button type (via hid), as fixed-feature buttons 309 name = acpi_device_name(device);
397 * need to be handled a bit differently than generic-space. 310 class = acpi_device_class(device);
398 */ 311
399 if (!strcmp(acpi_device_hid(device), ACPI_BUTTON_HID_POWER)) { 312 if (!strcmp(hid, ACPI_BUTTON_HID_POWER) ||
313 !strcmp(hid, ACPI_BUTTON_HID_POWERF)) {
400 button->type = ACPI_BUTTON_TYPE_POWER; 314 button->type = ACPI_BUTTON_TYPE_POWER;
401 strcpy(acpi_device_name(device), ACPI_BUTTON_DEVICE_NAME_POWER); 315 strcpy(name, ACPI_BUTTON_DEVICE_NAME_POWER);
402 sprintf(acpi_device_class(device), "%s/%s", 316 sprintf(class, "%s/%s",
403 ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_POWER); 317 ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_POWER);
404 } else if (!strcmp(acpi_device_hid(device), ACPI_BUTTON_HID_POWERF)) { 318 } else if (!strcmp(hid, ACPI_BUTTON_HID_SLEEP) ||
405 button->type = ACPI_BUTTON_TYPE_POWERF; 319 !strcmp(hid, ACPI_BUTTON_HID_SLEEPF)) {
406 strcpy(acpi_device_name(device),
407 ACPI_BUTTON_DEVICE_NAME_POWERF);
408 sprintf(acpi_device_class(device), "%s/%s",
409 ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_POWER);
410 } else if (!strcmp(acpi_device_hid(device), ACPI_BUTTON_HID_SLEEP)) {
411 button->type = ACPI_BUTTON_TYPE_SLEEP; 320 button->type = ACPI_BUTTON_TYPE_SLEEP;
412 strcpy(acpi_device_name(device), ACPI_BUTTON_DEVICE_NAME_SLEEP); 321 strcpy(name, ACPI_BUTTON_DEVICE_NAME_SLEEP);
413 sprintf(acpi_device_class(device), "%s/%s", 322 sprintf(class, "%s/%s",
414 ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_SLEEP);
415 } else if (!strcmp(acpi_device_hid(device), ACPI_BUTTON_HID_SLEEPF)) {
416 button->type = ACPI_BUTTON_TYPE_SLEEPF;
417 strcpy(acpi_device_name(device),
418 ACPI_BUTTON_DEVICE_NAME_SLEEPF);
419 sprintf(acpi_device_class(device), "%s/%s",
420 ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_SLEEP); 323 ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_SLEEP);
421 } else if (!strcmp(acpi_device_hid(device), ACPI_BUTTON_HID_LID)) { 324 } else if (!strcmp(hid, ACPI_BUTTON_HID_LID)) {
422 button->type = ACPI_BUTTON_TYPE_LID; 325 button->type = ACPI_BUTTON_TYPE_LID;
423 strcpy(acpi_device_name(device), ACPI_BUTTON_DEVICE_NAME_LID); 326 strcpy(name, ACPI_BUTTON_DEVICE_NAME_LID);
424 sprintf(acpi_device_class(device), "%s/%s", 327 sprintf(class, "%s/%s",
425 ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_LID); 328 ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_LID);
426 } else { 329 } else {
427 printk(KERN_ERR PREFIX "Unsupported hid [%s]\n", 330 printk(KERN_ERR PREFIX "Unsupported hid [%s]\n", hid);
428 acpi_device_hid(device));
429 error = -ENODEV; 331 error = -ENODEV;
430 goto err_free_input; 332 goto err_free_input;
431 } 333 }
@@ -434,14 +336,9 @@ static int acpi_button_add(struct acpi_device *device)
434 if (error) 336 if (error)
435 goto err_free_input; 337 goto err_free_input;
436 338
437 error = acpi_button_install_notify_handlers(button); 339 snprintf(button->phys, sizeof(button->phys), "%s/button/input0", hid);
438 if (error)
439 goto err_remove_fs;
440 340
441 snprintf(button->phys, sizeof(button->phys), 341 input->name = name;
442 "%s/button/input0", acpi_device_hid(device));
443
444 input->name = acpi_device_name(device);
445 input->phys = button->phys; 342 input->phys = button->phys;
446 input->id.bustype = BUS_HOST; 343 input->id.bustype = BUS_HOST;
447 input->id.product = button->type; 344 input->id.product = button->type;
@@ -449,13 +346,11 @@ static int acpi_button_add(struct acpi_device *device)
449 346
450 switch (button->type) { 347 switch (button->type) {
451 case ACPI_BUTTON_TYPE_POWER: 348 case ACPI_BUTTON_TYPE_POWER:
452 case ACPI_BUTTON_TYPE_POWERF:
453 input->evbit[0] = BIT_MASK(EV_KEY); 349 input->evbit[0] = BIT_MASK(EV_KEY);
454 set_bit(KEY_POWER, input->keybit); 350 set_bit(KEY_POWER, input->keybit);
455 break; 351 break;
456 352
457 case ACPI_BUTTON_TYPE_SLEEP: 353 case ACPI_BUTTON_TYPE_SLEEP:
458 case ACPI_BUTTON_TYPE_SLEEPF:
459 input->evbit[0] = BIT_MASK(EV_KEY); 354 input->evbit[0] = BIT_MASK(EV_KEY);
460 set_bit(KEY_SLEEP, input->keybit); 355 set_bit(KEY_SLEEP, input->keybit);
461 break; 356 break;
@@ -468,9 +363,9 @@ static int acpi_button_add(struct acpi_device *device)
468 363
469 error = input_register_device(input); 364 error = input_register_device(input);
470 if (error) 365 if (error)
471 goto err_remove_handlers; 366 goto err_remove_fs;
472 if (button->type == ACPI_BUTTON_TYPE_LID) 367 if (button->type == ACPI_BUTTON_TYPE_LID)
473 acpi_lid_send_state(button); 368 acpi_lid_send_state(device);
474 369
475 if (device->wakeup.flags.valid) { 370 if (device->wakeup.flags.valid) {
476 /* Button's GPE is run-wake GPE */ 371 /* Button's GPE is run-wake GPE */
@@ -482,13 +377,9 @@ static int acpi_button_add(struct acpi_device *device)
482 device->wakeup.state.enabled = 1; 377 device->wakeup.state.enabled = 1;
483 } 378 }
484 379
485 printk(KERN_INFO PREFIX "%s [%s]\n", 380 printk(KERN_INFO PREFIX "%s [%s]\n", name, acpi_device_bid(device));
486 acpi_device_name(device), acpi_device_bid(device));
487
488 return 0; 381 return 0;
489 382
490 err_remove_handlers:
491 acpi_button_remove_notify_handlers(button);
492 err_remove_fs: 383 err_remove_fs:
493 acpi_button_remove_fs(device); 384 acpi_button_remove_fs(device);
494 err_free_input: 385 err_free_input:
@@ -500,18 +391,11 @@ static int acpi_button_add(struct acpi_device *device)
500 391
501static int acpi_button_remove(struct acpi_device *device, int type) 392static int acpi_button_remove(struct acpi_device *device, int type)
502{ 393{
503 struct acpi_button *button; 394 struct acpi_button *button = acpi_driver_data(device);
504
505 if (!device || !acpi_driver_data(device))
506 return -EINVAL;
507
508 button = acpi_driver_data(device);
509 395
510 acpi_button_remove_notify_handlers(button);
511 acpi_button_remove_fs(device); 396 acpi_button_remove_fs(device);
512 input_unregister_device(button->input); 397 input_unregister_device(button->input);
513 kfree(button); 398 kfree(button);
514
515 return 0; 399 return 0;
516} 400}
517 401
@@ -522,7 +406,7 @@ static int __init acpi_button_init(void)
522 acpi_button_dir = proc_mkdir(ACPI_BUTTON_CLASS, acpi_root_dir); 406 acpi_button_dir = proc_mkdir(ACPI_BUTTON_CLASS, acpi_root_dir);
523 if (!acpi_button_dir) 407 if (!acpi_button_dir)
524 return -ENODEV; 408 return -ENODEV;
525 acpi_button_dir->owner = THIS_MODULE; 409
526 result = acpi_bus_register_driver(&acpi_button_driver); 410 result = acpi_bus_register_driver(&acpi_button_driver);
527 if (result < 0) { 411 if (result < 0) {
528 remove_proc_entry(ACPI_BUTTON_CLASS, acpi_root_dir); 412 remove_proc_entry(ACPI_BUTTON_CLASS, acpi_root_dir);
diff --git a/drivers/acpi/container.c b/drivers/acpi/container.c
index 17020c12623c..fe0cdf83641a 100644
--- a/drivers/acpi/container.c
+++ b/drivers/acpi/container.c
@@ -163,7 +163,7 @@ static void container_notify_cb(acpi_handle handle, u32 type, void *context)
163 case ACPI_NOTIFY_BUS_CHECK: 163 case ACPI_NOTIFY_BUS_CHECK:
164 /* Fall through */ 164 /* Fall through */
165 case ACPI_NOTIFY_DEVICE_CHECK: 165 case ACPI_NOTIFY_DEVICE_CHECK:
166 printk("Container driver received %s event\n", 166 printk(KERN_WARNING "Container driver received %s event\n",
167 (type == ACPI_NOTIFY_BUS_CHECK) ? 167 (type == ACPI_NOTIFY_BUS_CHECK) ?
168 "ACPI_NOTIFY_BUS_CHECK" : "ACPI_NOTIFY_DEVICE_CHECK"); 168 "ACPI_NOTIFY_BUS_CHECK" : "ACPI_NOTIFY_DEVICE_CHECK");
169 status = acpi_bus_get_device(handle, &device); 169 status = acpi_bus_get_device(handle, &device);
@@ -174,7 +174,8 @@ static void container_notify_cb(acpi_handle handle, u32 type, void *context)
174 kobject_uevent(&device->dev.kobj, 174 kobject_uevent(&device->dev.kobj,
175 KOBJ_ONLINE); 175 KOBJ_ONLINE);
176 else 176 else
177 printk("Failed to add container\n"); 177 printk(KERN_WARNING
178 "Failed to add container\n");
178 } 179 }
179 } else { 180 } else {
180 if (ACPI_SUCCESS(status)) { 181 if (ACPI_SUCCESS(status)) {
diff --git a/drivers/acpi/debug.c b/drivers/acpi/debug.c
index 20223cbd0d1c..a8287be0870e 100644
--- a/drivers/acpi/debug.c
+++ b/drivers/acpi/debug.c
@@ -13,11 +13,6 @@
13#define _COMPONENT ACPI_SYSTEM_COMPONENT 13#define _COMPONENT ACPI_SYSTEM_COMPONENT
14ACPI_MODULE_NAME("debug"); 14ACPI_MODULE_NAME("debug");
15 15
16#ifdef MODULE_PARAM_PREFIX
17#undef MODULE_PARAM_PREFIX
18#endif
19#define MODULE_PARAM_PREFIX "acpi."
20
21struct acpi_dlayer { 16struct acpi_dlayer {
22 const char *name; 17 const char *name;
23 unsigned long value; 18 unsigned long value;
@@ -297,17 +292,15 @@ acpi_system_write_debug(struct file *file,
297 292
298 return count; 293 return count;
299} 294}
295#endif
300 296
301static int __init acpi_debug_init(void) 297int __init acpi_debug_init(void)
302{ 298{
299#ifdef CONFIG_ACPI_PROCFS
303 struct proc_dir_entry *entry; 300 struct proc_dir_entry *entry;
304 int error = 0; 301 int error = 0;
305 char *name; 302 char *name;
306 303
307
308 if (acpi_disabled)
309 return 0;
310
311 /* 'debug_layer' [R/W] */ 304 /* 'debug_layer' [R/W] */
312 name = ACPI_SYSTEM_FILE_DEBUG_LAYER; 305 name = ACPI_SYSTEM_FILE_DEBUG_LAYER;
313 entry = 306 entry =
@@ -338,7 +331,7 @@ static int __init acpi_debug_init(void)
338 remove_proc_entry(ACPI_SYSTEM_FILE_DEBUG_LAYER, acpi_root_dir); 331 remove_proc_entry(ACPI_SYSTEM_FILE_DEBUG_LAYER, acpi_root_dir);
339 error = -ENODEV; 332 error = -ENODEV;
340 goto Done; 333 goto Done;
341} 334#else
342 335 return 0;
343subsys_initcall(acpi_debug_init);
344#endif 336#endif
337}
diff --git a/drivers/acpi/dock.c b/drivers/acpi/dock.c
index 5b30b8d91d71..efb959d6c8a9 100644
--- a/drivers/acpi/dock.c
+++ b/drivers/acpi/dock.c
@@ -855,10 +855,14 @@ fdd_out:
855static ssize_t show_docked(struct device *dev, 855static ssize_t show_docked(struct device *dev,
856 struct device_attribute *attr, char *buf) 856 struct device_attribute *attr, char *buf)
857{ 857{
858 struct acpi_device *tmp;
859
858 struct dock_station *dock_station = *((struct dock_station **) 860 struct dock_station *dock_station = *((struct dock_station **)
859 dev->platform_data); 861 dev->platform_data);
860 return snprintf(buf, PAGE_SIZE, "%d\n", dock_present(dock_station));
861 862
863 if (ACPI_SUCCESS(acpi_bus_get_device(dock_station->handle, &tmp)))
864 return snprintf(buf, PAGE_SIZE, "1\n");
865 return snprintf(buf, PAGE_SIZE, "0\n");
862} 866}
863static DEVICE_ATTR(docked, S_IRUGO, show_docked, NULL); 867static DEVICE_ATTR(docked, S_IRUGO, show_docked, NULL);
864 868
@@ -973,7 +977,7 @@ static int dock_add(acpi_handle handle)
973 sizeof(struct dock_station *)); 977 sizeof(struct dock_station *));
974 978
975 /* we want the dock device to send uevents */ 979 /* we want the dock device to send uevents */
976 dock_device->dev.uevent_suppress = 0; 980 dev_set_uevent_suppress(&dock_device->dev, 0);
977 981
978 if (is_dock(handle)) 982 if (is_dock(handle))
979 dock_station->flags |= DOCK_IS_DOCK; 983 dock_station->flags |= DOCK_IS_DOCK;
@@ -984,7 +988,7 @@ static int dock_add(acpi_handle handle)
984 988
985 ret = device_create_file(&dock_device->dev, &dev_attr_docked); 989 ret = device_create_file(&dock_device->dev, &dev_attr_docked);
986 if (ret) { 990 if (ret) {
987 printk("Error %d adding sysfs file\n", ret); 991 printk(KERN_ERR "Error %d adding sysfs file\n", ret);
988 platform_device_unregister(dock_device); 992 platform_device_unregister(dock_device);
989 kfree(dock_station); 993 kfree(dock_station);
990 dock_station = NULL; 994 dock_station = NULL;
@@ -992,7 +996,7 @@ static int dock_add(acpi_handle handle)
992 } 996 }
993 ret = device_create_file(&dock_device->dev, &dev_attr_undock); 997 ret = device_create_file(&dock_device->dev, &dev_attr_undock);
994 if (ret) { 998 if (ret) {
995 printk("Error %d adding sysfs file\n", ret); 999 printk(KERN_ERR "Error %d adding sysfs file\n", ret);
996 device_remove_file(&dock_device->dev, &dev_attr_docked); 1000 device_remove_file(&dock_device->dev, &dev_attr_docked);
997 platform_device_unregister(dock_device); 1001 platform_device_unregister(dock_device);
998 kfree(dock_station); 1002 kfree(dock_station);
@@ -1001,7 +1005,7 @@ static int dock_add(acpi_handle handle)
1001 } 1005 }
1002 ret = device_create_file(&dock_device->dev, &dev_attr_uid); 1006 ret = device_create_file(&dock_device->dev, &dev_attr_uid);
1003 if (ret) { 1007 if (ret) {
1004 printk("Error %d adding sysfs file\n", ret); 1008 printk(KERN_ERR "Error %d adding sysfs file\n", ret);
1005 device_remove_file(&dock_device->dev, &dev_attr_docked); 1009 device_remove_file(&dock_device->dev, &dev_attr_docked);
1006 device_remove_file(&dock_device->dev, &dev_attr_undock); 1010 device_remove_file(&dock_device->dev, &dev_attr_undock);
1007 platform_device_unregister(dock_device); 1011 platform_device_unregister(dock_device);
@@ -1011,7 +1015,7 @@ static int dock_add(acpi_handle handle)
1011 } 1015 }
1012 ret = device_create_file(&dock_device->dev, &dev_attr_flags); 1016 ret = device_create_file(&dock_device->dev, &dev_attr_flags);
1013 if (ret) { 1017 if (ret) {
1014 printk("Error %d adding sysfs file\n", ret); 1018 printk(KERN_ERR "Error %d adding sysfs file\n", ret);
1015 device_remove_file(&dock_device->dev, &dev_attr_docked); 1019 device_remove_file(&dock_device->dev, &dev_attr_docked);
1016 device_remove_file(&dock_device->dev, &dev_attr_undock); 1020 device_remove_file(&dock_device->dev, &dev_attr_undock);
1017 device_remove_file(&dock_device->dev, &dev_attr_uid); 1021 device_remove_file(&dock_device->dev, &dev_attr_uid);
@@ -1142,9 +1146,10 @@ static int __init dock_init(void)
1142static void __exit dock_exit(void) 1146static void __exit dock_exit(void)
1143{ 1147{
1144 struct dock_station *dock_station; 1148 struct dock_station *dock_station;
1149 struct dock_station *tmp;
1145 1150
1146 unregister_acpi_bus_notifier(&dock_acpi_notifier); 1151 unregister_acpi_bus_notifier(&dock_acpi_notifier);
1147 list_for_each_entry(dock_station, &dock_stations, sibiling) 1152 list_for_each_entry_safe(dock_station, tmp, &dock_stations, sibiling)
1148 dock_remove(dock_station); 1153 dock_remove(dock_station);
1149} 1154}
1150 1155
diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c
index 8dfcbb8aff73..391f331674c7 100644
--- a/drivers/acpi/ec.c
+++ b/drivers/acpi/ec.c
@@ -67,7 +67,7 @@ enum ec_command {
67 67
68#define ACPI_EC_DELAY 500 /* Wait 500ms max. during EC ops */ 68#define ACPI_EC_DELAY 500 /* Wait 500ms max. during EC ops */
69#define ACPI_EC_UDELAY_GLK 1000 /* Wait 1ms max. to get global lock */ 69#define ACPI_EC_UDELAY_GLK 1000 /* Wait 1ms max. to get global lock */
70#define ACPI_EC_UDELAY 100 /* Wait 100us before polling EC again */ 70#define ACPI_EC_CDELAY 10 /* Wait 10us before polling EC */
71 71
72#define ACPI_EC_STORM_THRESHOLD 8 /* number of false interrupts 72#define ACPI_EC_STORM_THRESHOLD 8 /* number of false interrupts
73 per one transaction */ 73 per one transaction */
@@ -120,30 +120,7 @@ static struct acpi_ec {
120 spinlock_t curr_lock; 120 spinlock_t curr_lock;
121} *boot_ec, *first_ec; 121} *boot_ec, *first_ec;
122 122
123/* 123static int EC_FLAGS_MSI; /* Out-of-spec MSI controller */
124 * Some Asus system have exchanged ECDT data/command IO addresses.
125 */
126static int print_ecdt_error(const struct dmi_system_id *id)
127{
128 printk(KERN_NOTICE PREFIX "%s detected - "
129 "ECDT has exchanged control/data I/O address\n",
130 id->ident);
131 return 0;
132}
133
134static struct dmi_system_id __cpuinitdata ec_dmi_table[] = {
135 {
136 print_ecdt_error, "Asus L4R", {
137 DMI_MATCH(DMI_BIOS_VERSION, "1008.006"),
138 DMI_MATCH(DMI_PRODUCT_NAME, "L4R"),
139 DMI_MATCH(DMI_BOARD_NAME, "L4R") }, NULL},
140 {
141 print_ecdt_error, "Asus M6R", {
142 DMI_MATCH(DMI_BIOS_VERSION, "0207"),
143 DMI_MATCH(DMI_PRODUCT_NAME, "M6R"),
144 DMI_MATCH(DMI_BOARD_NAME, "M6R") }, NULL},
145 {},
146};
147 124
148/* -------------------------------------------------------------------------- 125/* --------------------------------------------------------------------------
149 Transaction Management 126 Transaction Management
@@ -259,13 +236,23 @@ static int ec_check_sci(struct acpi_ec *ec, u8 state)
259 return 0; 236 return 0;
260} 237}
261 238
239static void ec_delay(void)
240{
241 /* EC in MSI notebooks don't tolerate delays other than 550 usec */
242 if (EC_FLAGS_MSI)
243 udelay(ACPI_EC_DELAY);
244 else
245 /* Use shortest sleep available */
246 msleep(1);
247}
248
262static int ec_poll(struct acpi_ec *ec) 249static int ec_poll(struct acpi_ec *ec)
263{ 250{
264 unsigned long delay = jiffies + msecs_to_jiffies(ACPI_EC_DELAY); 251 unsigned long delay = jiffies + msecs_to_jiffies(ACPI_EC_DELAY);
265 udelay(ACPI_EC_UDELAY); 252 udelay(ACPI_EC_CDELAY);
266 while (time_before(jiffies, delay)) { 253 while (time_before(jiffies, delay)) {
267 gpe_transaction(ec, acpi_ec_read_status(ec)); 254 gpe_transaction(ec, acpi_ec_read_status(ec));
268 udelay(ACPI_EC_UDELAY); 255 ec_delay();
269 if (ec_transaction_done(ec)) 256 if (ec_transaction_done(ec))
270 return 0; 257 return 0;
271 } 258 }
@@ -284,6 +271,8 @@ static int acpi_ec_transaction_unlocked(struct acpi_ec *ec,
284 clear_bit(EC_FLAGS_GPE_MODE, &ec->flags); 271 clear_bit(EC_FLAGS_GPE_MODE, &ec->flags);
285 acpi_disable_gpe(NULL, ec->gpe); 272 acpi_disable_gpe(NULL, ec->gpe);
286 } 273 }
274 if (EC_FLAGS_MSI)
275 udelay(ACPI_EC_DELAY);
287 /* start transaction */ 276 /* start transaction */
288 spin_lock_irqsave(&ec->curr_lock, tmp); 277 spin_lock_irqsave(&ec->curr_lock, tmp);
289 /* following two actions should be kept atomic */ 278 /* following two actions should be kept atomic */
@@ -693,7 +682,7 @@ static int acpi_ec_info_open_fs(struct inode *inode, struct file *file)
693 return single_open(file, acpi_ec_read_info, PDE(inode)->data); 682 return single_open(file, acpi_ec_read_info, PDE(inode)->data);
694} 683}
695 684
696static struct file_operations acpi_ec_info_ops = { 685static const struct file_operations acpi_ec_info_ops = {
697 .open = acpi_ec_info_open_fs, 686 .open = acpi_ec_info_open_fs,
698 .read = seq_read, 687 .read = seq_read,
699 .llseek = seq_lseek, 688 .llseek = seq_lseek,
@@ -776,6 +765,10 @@ ec_parse_device(acpi_handle handle, u32 Level, void *context, void **retval)
776 unsigned long long tmp = 0; 765 unsigned long long tmp = 0;
777 766
778 struct acpi_ec *ec = context; 767 struct acpi_ec *ec = context;
768
769 /* clear addr values, ec_parse_io_ports depend on it */
770 ec->command_addr = ec->data_addr = 0;
771
779 status = acpi_walk_resources(handle, METHOD_NAME__CRS, 772 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
780 ec_parse_io_ports, ec); 773 ec_parse_io_ports, ec);
781 if (ACPI_FAILURE(status)) 774 if (ACPI_FAILURE(status))
@@ -825,11 +818,11 @@ static int acpi_ec_add(struct acpi_device *device)
825 ec = make_acpi_ec(); 818 ec = make_acpi_ec();
826 if (!ec) 819 if (!ec)
827 return -ENOMEM; 820 return -ENOMEM;
828 if (ec_parse_device(device->handle, 0, ec, NULL) != 821 }
829 AE_CTRL_TERMINATE) { 822 if (ec_parse_device(device->handle, 0, ec, NULL) !=
823 AE_CTRL_TERMINATE) {
830 kfree(ec); 824 kfree(ec);
831 return -EINVAL; 825 return -EINVAL;
832 }
833 } 826 }
834 827
835 ec->handle = device->handle; 828 ec->handle = device->handle;
@@ -983,8 +976,8 @@ static const struct acpi_device_id ec_device_ids[] = {
983int __init acpi_ec_ecdt_probe(void) 976int __init acpi_ec_ecdt_probe(void)
984{ 977{
985 acpi_status status; 978 acpi_status status;
979 struct acpi_ec *saved_ec = NULL;
986 struct acpi_table_ecdt *ecdt_ptr; 980 struct acpi_table_ecdt *ecdt_ptr;
987 acpi_handle dummy;
988 981
989 boot_ec = make_acpi_ec(); 982 boot_ec = make_acpi_ec();
990 if (!boot_ec) 983 if (!boot_ec)
@@ -992,27 +985,27 @@ int __init acpi_ec_ecdt_probe(void)
992 /* 985 /*
993 * Generate a boot ec context 986 * Generate a boot ec context
994 */ 987 */
988 if (dmi_name_in_vendors("Micro-Star") ||
989 dmi_name_in_vendors("Notebook")) {
990 pr_info(PREFIX "Enabling special treatment for EC from MSI.\n");
991 EC_FLAGS_MSI = 1;
992 }
995 status = acpi_get_table(ACPI_SIG_ECDT, 1, 993 status = acpi_get_table(ACPI_SIG_ECDT, 1,
996 (struct acpi_table_header **)&ecdt_ptr); 994 (struct acpi_table_header **)&ecdt_ptr);
997 if (ACPI_SUCCESS(status)) { 995 if (ACPI_SUCCESS(status)) {
998 pr_info(PREFIX "EC description table is found, configuring boot EC\n"); 996 pr_info(PREFIX "EC description table is found, configuring boot EC\n");
999 boot_ec->command_addr = ecdt_ptr->control.address; 997 boot_ec->command_addr = ecdt_ptr->control.address;
1000 boot_ec->data_addr = ecdt_ptr->data.address; 998 boot_ec->data_addr = ecdt_ptr->data.address;
1001 if (dmi_check_system(ec_dmi_table)) {
1002 /*
1003 * If the board falls into ec_dmi_table, it means
1004 * that ECDT table gives the incorrect command/status
1005 * & data I/O address. Just fix it.
1006 */
1007 boot_ec->data_addr = ecdt_ptr->control.address;
1008 boot_ec->command_addr = ecdt_ptr->data.address;
1009 }
1010 boot_ec->gpe = ecdt_ptr->gpe; 999 boot_ec->gpe = ecdt_ptr->gpe;
1011 boot_ec->handle = ACPI_ROOT_OBJECT; 1000 boot_ec->handle = ACPI_ROOT_OBJECT;
1012 acpi_get_handle(ACPI_ROOT_OBJECT, ecdt_ptr->id, &boot_ec->handle); 1001 acpi_get_handle(ACPI_ROOT_OBJECT, ecdt_ptr->id, &boot_ec->handle);
1013 /* Add some basic check against completely broken table */ 1002 /* Don't trust ECDT, which comes from ASUSTek */
1014 if (boot_ec->data_addr != boot_ec->command_addr) 1003 if (!dmi_name_in_vendors("ASUS") && EC_FLAGS_MSI == 0)
1015 goto install; 1004 goto install;
1005 saved_ec = kmalloc(sizeof(struct acpi_ec), GFP_KERNEL);
1006 if (!saved_ec)
1007 return -ENOMEM;
1008 memcpy(saved_ec, boot_ec, sizeof(struct acpi_ec));
1016 /* fall through */ 1009 /* fall through */
1017 } 1010 }
1018 /* This workaround is needed only on some broken machines, 1011 /* This workaround is needed only on some broken machines,
@@ -1023,12 +1016,29 @@ int __init acpi_ec_ecdt_probe(void)
1023 /* Check that acpi_get_devices actually find something */ 1016 /* Check that acpi_get_devices actually find something */
1024 if (ACPI_FAILURE(status) || !boot_ec->handle) 1017 if (ACPI_FAILURE(status) || !boot_ec->handle)
1025 goto error; 1018 goto error;
1026 /* We really need to limit this workaround, the only ASUS, 1019 if (saved_ec) {
1027 * which needs it, has fake EC._INI method, so use it as flag. 1020 /* try to find good ECDT from ASUSTek */
1028 * Keep boot_ec struct as it will be needed soon. 1021 if (saved_ec->command_addr != boot_ec->command_addr ||
1029 */ 1022 saved_ec->data_addr != boot_ec->data_addr ||
1030 if (ACPI_FAILURE(acpi_get_handle(boot_ec->handle, "_INI", &dummy))) 1023 saved_ec->gpe != boot_ec->gpe ||
1031 return -ENODEV; 1024 saved_ec->handle != boot_ec->handle)
1025 pr_info(PREFIX "ASUSTek keeps feeding us with broken "
1026 "ECDT tables, which are very hard to workaround. "
1027 "Trying to use DSDT EC info instead. Please send "
1028 "output of acpidump to linux-acpi@vger.kernel.org\n");
1029 kfree(saved_ec);
1030 saved_ec = NULL;
1031 } else {
1032 /* We really need to limit this workaround, the only ASUS,
1033 * which needs it, has fake EC._INI method, so use it as flag.
1034 * Keep boot_ec struct as it will be needed soon.
1035 */
1036 acpi_handle dummy;
1037 if (!dmi_name_in_vendors("ASUS") ||
1038 ACPI_FAILURE(acpi_get_handle(boot_ec->handle, "_INI",
1039 &dummy)))
1040 return -ENODEV;
1041 }
1032install: 1042install:
1033 if (!ec_install_handlers(boot_ec)) { 1043 if (!ec_install_handlers(boot_ec)) {
1034 first_ec = boot_ec; 1044 first_ec = boot_ec;
@@ -1055,6 +1065,7 @@ static int acpi_ec_resume(struct acpi_device *device)
1055 struct acpi_ec *ec = acpi_driver_data(device); 1065 struct acpi_ec *ec = acpi_driver_data(device);
1056 /* Enable use of GPE back */ 1066 /* Enable use of GPE back */
1057 clear_bit(EC_FLAGS_NO_GPE, &ec->flags); 1067 clear_bit(EC_FLAGS_NO_GPE, &ec->flags);
1068 set_bit(EC_FLAGS_GPE_MODE, &ec->flags);
1058 acpi_enable_gpe(NULL, ec->gpe); 1069 acpi_enable_gpe(NULL, ec->gpe);
1059 return 0; 1070 return 0;
1060} 1071}
@@ -1073,13 +1084,10 @@ static struct acpi_driver acpi_ec_driver = {
1073 }, 1084 },
1074}; 1085};
1075 1086
1076static int __init acpi_ec_init(void) 1087int __init acpi_ec_init(void)
1077{ 1088{
1078 int result = 0; 1089 int result = 0;
1079 1090
1080 if (acpi_disabled)
1081 return 0;
1082
1083 acpi_ec_dir = proc_mkdir(ACPI_EC_CLASS, acpi_root_dir); 1091 acpi_ec_dir = proc_mkdir(ACPI_EC_CLASS, acpi_root_dir);
1084 if (!acpi_ec_dir) 1092 if (!acpi_ec_dir)
1085 return -ENODEV; 1093 return -ENODEV;
@@ -1094,8 +1102,6 @@ static int __init acpi_ec_init(void)
1094 return result; 1102 return result;
1095} 1103}
1096 1104
1097subsys_initcall(acpi_ec_init);
1098
1099/* EC driver currently not unloadable */ 1105/* EC driver currently not unloadable */
1100#if 0 1106#if 0
1101static void __exit acpi_ec_exit(void) 1107static void __exit acpi_ec_exit(void)
diff --git a/drivers/acpi/event.c b/drivers/acpi/event.c
index 0c24bd4d6562..aeb7e5fb4a04 100644
--- a/drivers/acpi/event.c
+++ b/drivers/acpi/event.c
@@ -235,11 +235,7 @@ int acpi_bus_generate_netlink_event(const char *device_class,
235 return result; 235 return result;
236 } 236 }
237 237
238 result = 238 genlmsg_multicast(skb, 0, acpi_event_mcgrp.id, GFP_ATOMIC);
239 genlmsg_multicast(skb, 0, acpi_event_mcgrp.id, GFP_ATOMIC);
240 if (result)
241 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
242 "Failed to send a Genetlink message!\n"));
243 return 0; 239 return 0;
244} 240}
245 241
diff --git a/drivers/acpi/fan.c b/drivers/acpi/fan.c
index eaaee1660bdf..53698ea08371 100644
--- a/drivers/acpi/fan.c
+++ b/drivers/acpi/fan.c
@@ -68,31 +68,35 @@ static struct acpi_driver acpi_fan_driver = {
68}; 68};
69 69
70/* thermal cooling device callbacks */ 70/* thermal cooling device callbacks */
71static int fan_get_max_state(struct thermal_cooling_device *cdev, char *buf) 71static int fan_get_max_state(struct thermal_cooling_device *cdev, unsigned long
72 *state)
72{ 73{
73 /* ACPI fan device only support two states: ON/OFF */ 74 /* ACPI fan device only support two states: ON/OFF */
74 return sprintf(buf, "1\n"); 75 *state = 1;
76 return 0;
75} 77}
76 78
77static int fan_get_cur_state(struct thermal_cooling_device *cdev, char *buf) 79static int fan_get_cur_state(struct thermal_cooling_device *cdev, unsigned long
80 *state)
78{ 81{
79 struct acpi_device *device = cdev->devdata; 82 struct acpi_device *device = cdev->devdata;
80 int state;
81 int result; 83 int result;
84 int acpi_state;
82 85
83 if (!device) 86 if (!device)
84 return -EINVAL; 87 return -EINVAL;
85 88
86 result = acpi_bus_get_power(device->handle, &state); 89 result = acpi_bus_get_power(device->handle, &acpi_state);
87 if (result) 90 if (result)
88 return result; 91 return result;
89 92
90 return sprintf(buf, "%s\n", state == ACPI_STATE_D3 ? "0" : 93 *state = (acpi_state == ACPI_STATE_D3 ? 0 :
91 (state == ACPI_STATE_D0 ? "1" : "unknown")); 94 (acpi_state == ACPI_STATE_D0 ? 1 : -1));
95 return 0;
92} 96}
93 97
94static int 98static int
95fan_set_cur_state(struct thermal_cooling_device *cdev, unsigned int state) 99fan_set_cur_state(struct thermal_cooling_device *cdev, unsigned long state)
96{ 100{
97 struct acpi_device *device = cdev->devdata; 101 struct acpi_device *device = cdev->devdata;
98 int result; 102 int result;
@@ -193,7 +197,6 @@ static int acpi_fan_add_fs(struct acpi_device *device)
193 acpi_fan_dir); 197 acpi_fan_dir);
194 if (!acpi_device_dir(device)) 198 if (!acpi_device_dir(device))
195 return -ENODEV; 199 return -ENODEV;
196 acpi_device_dir(device)->owner = THIS_MODULE;
197 } 200 }
198 201
199 /* 'status' [R/W] */ 202 /* 'status' [R/W] */
@@ -347,7 +350,6 @@ static int __init acpi_fan_init(void)
347 acpi_fan_dir = proc_mkdir(ACPI_FAN_CLASS, acpi_root_dir); 350 acpi_fan_dir = proc_mkdir(ACPI_FAN_CLASS, acpi_root_dir);
348 if (!acpi_fan_dir) 351 if (!acpi_fan_dir)
349 return -ENODEV; 352 return -ENODEV;
350 acpi_fan_dir->owner = THIS_MODULE;
351#endif 353#endif
352 354
353 result = acpi_bus_register_driver(&acpi_fan_driver); 355 result = acpi_bus_register_driver(&acpi_fan_driver);
diff --git a/drivers/acpi/glue.c b/drivers/acpi/glue.c
index adec3d15810a..8bd2c2a6884d 100644
--- a/drivers/acpi/glue.c
+++ b/drivers/acpi/glue.c
@@ -255,12 +255,12 @@ static int acpi_platform_notify(struct device *dev)
255 } 255 }
256 type = acpi_get_bus_type(dev->bus); 256 type = acpi_get_bus_type(dev->bus);
257 if (!type) { 257 if (!type) {
258 DBG("No ACPI bus support for %s\n", dev->bus_id); 258 DBG("No ACPI bus support for %s\n", dev_name(dev));
259 ret = -EINVAL; 259 ret = -EINVAL;
260 goto end; 260 goto end;
261 } 261 }
262 if ((ret = type->find_device(dev, &handle)) != 0) 262 if ((ret = type->find_device(dev, &handle)) != 0)
263 DBG("Can't get handler for %s\n", dev->bus_id); 263 DBG("Can't get handler for %s\n", dev_name(dev));
264 end: 264 end:
265 if (!ret) 265 if (!ret)
266 acpi_bind_one(dev, handle); 266 acpi_bind_one(dev, handle);
@@ -271,10 +271,10 @@ static int acpi_platform_notify(struct device *dev)
271 271
272 acpi_get_name(dev->archdata.acpi_handle, 272 acpi_get_name(dev->archdata.acpi_handle,
273 ACPI_FULL_PATHNAME, &buffer); 273 ACPI_FULL_PATHNAME, &buffer);
274 DBG("Device %s -> %s\n", dev->bus_id, (char *)buffer.pointer); 274 DBG("Device %s -> %s\n", dev_name(dev), (char *)buffer.pointer);
275 kfree(buffer.pointer); 275 kfree(buffer.pointer);
276 } else 276 } else
277 DBG("Device %s -> No ACPI support\n", dev->bus_id); 277 DBG("Device %s -> No ACPI support\n", dev_name(dev));
278#endif 278#endif
279 279
280 return ret; 280 return ret;
@@ -286,10 +286,8 @@ static int acpi_platform_notify_remove(struct device *dev)
286 return 0; 286 return 0;
287} 287}
288 288
289static int __init init_acpi_device_notify(void) 289int __init init_acpi_device_notify(void)
290{ 290{
291 if (acpi_disabled)
292 return 0;
293 if (platform_notify || platform_notify_remove) { 291 if (platform_notify || platform_notify_remove) {
294 printk(KERN_ERR PREFIX "Can't use platform_notify\n"); 292 printk(KERN_ERR PREFIX "Can't use platform_notify\n");
295 return 0; 293 return 0;
@@ -298,5 +296,3 @@ static int __init init_acpi_device_notify(void)
298 platform_notify_remove = acpi_platform_notify_remove; 296 platform_notify_remove = acpi_platform_notify_remove;
299 return 0; 297 return 0;
300} 298}
301
302arch_initcall(init_acpi_device_notify);
diff --git a/drivers/acpi/internal.h b/drivers/acpi/internal.h
new file mode 100644
index 000000000000..11a69b53004e
--- /dev/null
+++ b/drivers/acpi/internal.h
@@ -0,0 +1,43 @@
1/* For use by Linux/ACPI infrastructure, not drivers */
2
3int init_acpi_device_notify(void);
4int acpi_scan_init(void);
5int acpi_system_init(void);
6
7#ifdef CONFIG_ACPI_DEBUG
8int acpi_debug_init(void);
9#else
10static inline int acpi_debug_init(void) { return 0; }
11#endif
12
13/* --------------------------------------------------------------------------
14 Power Resource
15 -------------------------------------------------------------------------- */
16int acpi_power_init(void);
17int acpi_device_sleep_wake(struct acpi_device *dev,
18 int enable, int sleep_state, int dev_state);
19int acpi_enable_wakeup_device_power(struct acpi_device *dev, int sleep_state);
20int acpi_disable_wakeup_device_power(struct acpi_device *dev);
21int acpi_power_get_inferred_state(struct acpi_device *device);
22int acpi_power_transition(struct acpi_device *device, int state);
23extern int acpi_power_nocheck;
24
25int acpi_wakeup_device_init(void);
26
27/* --------------------------------------------------------------------------
28 Embedded Controller
29 -------------------------------------------------------------------------- */
30int acpi_ec_init(void);
31int acpi_ec_ecdt_probe(void);
32int acpi_boot_ec_enable(void);
33
34/*--------------------------------------------------------------------------
35 Suspend/Resume
36 -------------------------------------------------------------------------- */
37extern int acpi_sleep_init(void);
38
39#ifdef CONFIG_ACPI_SLEEP
40int acpi_sleep_proc_init(void);
41#else
42static inline int acpi_sleep_proc_init(void) { return 0; }
43#endif
diff --git a/drivers/acpi/numa.c b/drivers/acpi/numa.c
index c5e292aab0e3..d440ccd27d91 100644
--- a/drivers/acpi/numa.c
+++ b/drivers/acpi/numa.c
@@ -131,6 +131,21 @@ acpi_table_print_srat_entry(struct acpi_subtable_header *header)
131#endif /* ACPI_DEBUG_OUTPUT */ 131#endif /* ACPI_DEBUG_OUTPUT */
132 break; 132 break;
133 133
134 case ACPI_SRAT_TYPE_X2APIC_CPU_AFFINITY:
135#ifdef ACPI_DEBUG_OUTPUT
136 {
137 struct acpi_srat_x2apic_cpu_affinity *p =
138 (struct acpi_srat_x2apic_cpu_affinity *)header;
139 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
140 "SRAT Processor (x2apicid[0x%08x]) in"
141 " proximity domain %d %s\n",
142 p->apic_id,
143 p->proximity_domain,
144 (p->flags & ACPI_SRAT_CPU_ENABLED) ?
145 "enabled" : "disabled"));
146 }
147#endif /* ACPI_DEBUG_OUTPUT */
148 break;
134 default: 149 default:
135 printk(KERN_WARNING PREFIX 150 printk(KERN_WARNING PREFIX
136 "Found unsupported SRAT entry (type = 0x%x)\n", 151 "Found unsupported SRAT entry (type = 0x%x)\n",
@@ -180,8 +195,35 @@ static int __init acpi_parse_slit(struct acpi_table_header *table)
180 return 0; 195 return 0;
181} 196}
182 197
198void __init __attribute__ ((weak))
199acpi_numa_x2apic_affinity_init(struct acpi_srat_x2apic_cpu_affinity *pa)
200{
201 printk(KERN_WARNING PREFIX
202 "Found unsupported x2apic [0x%08x] SRAT entry\n", pa->apic_id);
203 return;
204}
205
206
207static int __init
208acpi_parse_x2apic_affinity(struct acpi_subtable_header *header,
209 const unsigned long end)
210{
211 struct acpi_srat_x2apic_cpu_affinity *processor_affinity;
212
213 processor_affinity = (struct acpi_srat_x2apic_cpu_affinity *)header;
214 if (!processor_affinity)
215 return -EINVAL;
216
217 acpi_table_print_srat_entry(header);
218
219 /* let architecture-dependent part to do it */
220 acpi_numa_x2apic_affinity_init(processor_affinity);
221
222 return 0;
223}
224
183static int __init 225static int __init
184acpi_parse_processor_affinity(struct acpi_subtable_header * header, 226acpi_parse_processor_affinity(struct acpi_subtable_header *header,
185 const unsigned long end) 227 const unsigned long end)
186{ 228{
187 struct acpi_srat_cpu_affinity *processor_affinity; 229 struct acpi_srat_cpu_affinity *processor_affinity;
@@ -241,6 +283,8 @@ int __init acpi_numa_init(void)
241{ 283{
242 /* SRAT: Static Resource Affinity Table */ 284 /* SRAT: Static Resource Affinity Table */
243 if (!acpi_table_parse(ACPI_SIG_SRAT, acpi_parse_srat)) { 285 if (!acpi_table_parse(ACPI_SIG_SRAT, acpi_parse_srat)) {
286 acpi_table_parse_srat(ACPI_SRAT_TYPE_X2APIC_CPU_AFFINITY,
287 acpi_parse_x2apic_affinity, NR_CPUS);
244 acpi_table_parse_srat(ACPI_SRAT_TYPE_CPU_AFFINITY, 288 acpi_table_parse_srat(ACPI_SRAT_TYPE_CPU_AFFINITY,
245 acpi_parse_processor_affinity, NR_CPUS); 289 acpi_parse_processor_affinity, NR_CPUS);
246 acpi_table_parse_srat(ACPI_SRAT_TYPE_MEMORY_AFFINITY, 290 acpi_table_parse_srat(ACPI_SRAT_TYPE_MEMORY_AFFINITY,
@@ -277,7 +321,7 @@ int acpi_get_node(acpi_handle *handle)
277 int pxm, node = -1; 321 int pxm, node = -1;
278 322
279 pxm = acpi_get_pxm(handle); 323 pxm = acpi_get_pxm(handle);
280 if (pxm >= 0) 324 if (pxm >= 0 && pxm < MAX_PXM_DOMAINS)
281 node = acpi_map_pxm_to_node(pxm); 325 node = acpi_map_pxm_to_node(pxm);
282 326
283 return node; 327 return node;
diff --git a/drivers/acpi/osl.c b/drivers/acpi/osl.c
index 6729a4992f2b..d916bea729f1 100644
--- a/drivers/acpi/osl.c
+++ b/drivers/acpi/osl.c
@@ -228,10 +228,10 @@ void acpi_os_vprintf(const char *fmt, va_list args)
228 if (acpi_in_debugger) { 228 if (acpi_in_debugger) {
229 kdb_printf("%s", buffer); 229 kdb_printf("%s", buffer);
230 } else { 230 } else {
231 printk("%s", buffer); 231 printk(KERN_CONT "%s", buffer);
232 } 232 }
233#else 233#else
234 printk("%s", buffer); 234 printk(KERN_CONT "%s", buffer);
235#endif 235#endif
236} 236}
237 237
@@ -272,14 +272,21 @@ acpi_os_map_memory(acpi_physical_address phys, acpi_size size)
272} 272}
273EXPORT_SYMBOL_GPL(acpi_os_map_memory); 273EXPORT_SYMBOL_GPL(acpi_os_map_memory);
274 274
275void acpi_os_unmap_memory(void __iomem * virt, acpi_size size) 275void __ref acpi_os_unmap_memory(void __iomem *virt, acpi_size size)
276{ 276{
277 if (acpi_gbl_permanent_mmap) { 277 if (acpi_gbl_permanent_mmap)
278 iounmap(virt); 278 iounmap(virt);
279 } 279 else
280 __acpi_unmap_table(virt, size);
280} 281}
281EXPORT_SYMBOL_GPL(acpi_os_unmap_memory); 282EXPORT_SYMBOL_GPL(acpi_os_unmap_memory);
282 283
284void __init early_acpi_os_unmap_memory(void __iomem *virt, acpi_size size)
285{
286 if (!acpi_gbl_permanent_mmap)
287 __acpi_unmap_table(virt, size);
288}
289
283#ifdef ACPI_FUTURE_USAGE 290#ifdef ACPI_FUTURE_USAGE
284acpi_status 291acpi_status
285acpi_os_get_physical_address(void *virt, acpi_physical_address * phys) 292acpi_os_get_physical_address(void *virt, acpi_physical_address * phys)
@@ -346,8 +353,10 @@ static irqreturn_t acpi_irq(int irq, void *dev_id)
346 if (handled) { 353 if (handled) {
347 acpi_irq_handled++; 354 acpi_irq_handled++;
348 return IRQ_HANDLED; 355 return IRQ_HANDLED;
349 } else 356 } else {
357 acpi_irq_not_handled++;
350 return IRQ_NONE; 358 return IRQ_NONE;
359 }
351} 360}
352 361
353acpi_status 362acpi_status
@@ -1063,9 +1072,9 @@ __setup("acpi_wake_gpes_always_on", acpi_wake_gpes_always_on_setup);
1063 * in arbitrary AML code and can interfere with legacy drivers. 1072 * in arbitrary AML code and can interfere with legacy drivers.
1064 * acpi_enforce_resources= can be set to: 1073 * acpi_enforce_resources= can be set to:
1065 * 1074 *
1066 * - strict (2) 1075 * - strict (default) (2)
1067 * -> further driver trying to access the resources will not load 1076 * -> further driver trying to access the resources will not load
1068 * - lax (default) (1) 1077 * - lax (1)
1069 * -> further driver trying to access the resources will load, but you 1078 * -> further driver trying to access the resources will load, but you
1070 * get a system message that something might go wrong... 1079 * get a system message that something might go wrong...
1071 * 1080 *
@@ -1077,7 +1086,7 @@ __setup("acpi_wake_gpes_always_on", acpi_wake_gpes_always_on_setup);
1077#define ENFORCE_RESOURCES_LAX 1 1086#define ENFORCE_RESOURCES_LAX 1
1078#define ENFORCE_RESOURCES_NO 0 1087#define ENFORCE_RESOURCES_NO 0
1079 1088
1080static unsigned int acpi_enforce_resources = ENFORCE_RESOURCES_LAX; 1089static unsigned int acpi_enforce_resources = ENFORCE_RESOURCES_STRICT;
1081 1090
1082static int __init acpi_enforce_resources_setup(char *str) 1091static int __init acpi_enforce_resources_setup(char *str)
1083{ 1092{
diff --git a/drivers/acpi/pci_irq.c b/drivers/acpi/pci_irq.c
index 891bdf6679f3..51b9f8280f88 100644
--- a/drivers/acpi/pci_irq.c
+++ b/drivers/acpi/pci_irq.c
@@ -86,7 +86,7 @@ static struct acpi_prt_entry *acpi_pci_irq_find_prt_entry(struct pci_dev *dev,
86} 86}
87 87
88/* http://bugzilla.kernel.org/show_bug.cgi?id=4773 */ 88/* http://bugzilla.kernel.org/show_bug.cgi?id=4773 */
89static struct dmi_system_id medion_md9580[] = { 89static const struct dmi_system_id medion_md9580[] = {
90 { 90 {
91 .ident = "Medion MD9580-F laptop", 91 .ident = "Medion MD9580-F laptop",
92 .matches = { 92 .matches = {
@@ -98,7 +98,7 @@ static struct dmi_system_id medion_md9580[] = {
98}; 98};
99 99
100/* http://bugzilla.kernel.org/show_bug.cgi?id=5044 */ 100/* http://bugzilla.kernel.org/show_bug.cgi?id=5044 */
101static struct dmi_system_id dell_optiplex[] = { 101static const struct dmi_system_id dell_optiplex[] = {
102 { 102 {
103 .ident = "Dell Optiplex GX1", 103 .ident = "Dell Optiplex GX1",
104 .matches = { 104 .matches = {
@@ -110,7 +110,7 @@ static struct dmi_system_id dell_optiplex[] = {
110}; 110};
111 111
112/* http://bugzilla.kernel.org/show_bug.cgi?id=10138 */ 112/* http://bugzilla.kernel.org/show_bug.cgi?id=10138 */
113static struct dmi_system_id hp_t5710[] = { 113static const struct dmi_system_id hp_t5710[] = {
114 { 114 {
115 .ident = "HP t5710", 115 .ident = "HP t5710",
116 .matches = { 116 .matches = {
@@ -123,13 +123,13 @@ static struct dmi_system_id hp_t5710[] = {
123}; 123};
124 124
125struct prt_quirk { 125struct prt_quirk {
126 struct dmi_system_id *system; 126 const struct dmi_system_id *system;
127 unsigned int segment; 127 unsigned int segment;
128 unsigned int bus; 128 unsigned int bus;
129 unsigned int device; 129 unsigned int device;
130 unsigned char pin; 130 unsigned char pin;
131 char *source; /* according to BIOS */ 131 const char *source; /* according to BIOS */
132 char *actual_source; 132 const char *actual_source;
133}; 133};
134 134
135#define PCI_INTX_PIN(c) (c - 'A' + 1) 135#define PCI_INTX_PIN(c) (c - 'A' + 1)
@@ -139,7 +139,7 @@ struct prt_quirk {
139 * interrupt at the listed segment/bus/device/pin is connected to the first 139 * interrupt at the listed segment/bus/device/pin is connected to the first
140 * link device, but it is actually connected to the second. 140 * link device, but it is actually connected to the second.
141 */ 141 */
142static struct prt_quirk prt_quirks[] = { 142static const struct prt_quirk prt_quirks[] = {
143 { medion_md9580, 0, 0, 9, PCI_INTX_PIN('A'), 143 { medion_md9580, 0, 0, 9, PCI_INTX_PIN('A'),
144 "\\_SB_.PCI0.ISA_.LNKA", 144 "\\_SB_.PCI0.ISA_.LNKA",
145 "\\_SB_.PCI0.ISA_.LNKB"}, 145 "\\_SB_.PCI0.ISA_.LNKB"},
@@ -155,7 +155,7 @@ static void do_prt_fixups(struct acpi_prt_entry *entry,
155 struct acpi_pci_routing_table *prt) 155 struct acpi_pci_routing_table *prt)
156{ 156{
157 int i; 157 int i;
158 struct prt_quirk *quirk; 158 const struct prt_quirk *quirk;
159 159
160 for (i = 0; i < ARRAY_SIZE(prt_quirks); i++) { 160 for (i = 0; i < ARRAY_SIZE(prt_quirks); i++) {
161 quirk = &prt_quirks[i]; 161 quirk = &prt_quirks[i];
@@ -319,7 +319,7 @@ static struct acpi_prt_entry *acpi_pci_irq_lookup(struct pci_dev *dev, int pin)
319 */ 319 */
320 bridge = dev->bus->self; 320 bridge = dev->bus->self;
321 while (bridge) { 321 while (bridge) {
322 pin = (((pin - 1) + PCI_SLOT(dev->devfn)) % 4) + 1; 322 pin = pci_swizzle_interrupt_pin(dev, pin);
323 323
324 if ((bridge->class >> 8) == PCI_CLASS_BRIDGE_CARDBUS) { 324 if ((bridge->class >> 8) == PCI_CLASS_BRIDGE_CARDBUS) {
325 /* PC card has the same IRQ as its cardbridge */ 325 /* PC card has the same IRQ as its cardbridge */
diff --git a/drivers/acpi/pci_link.c b/drivers/acpi/pci_link.c
index 1c6e73c7865e..16e0f9d3d17c 100644
--- a/drivers/acpi/pci_link.c
+++ b/drivers/acpi/pci_link.c
@@ -43,13 +43,14 @@
43#include <acpi/acpi_bus.h> 43#include <acpi/acpi_bus.h>
44#include <acpi/acpi_drivers.h> 44#include <acpi/acpi_drivers.h>
45 45
46#define _COMPONENT ACPI_PCI_COMPONENT 46#define _COMPONENT ACPI_PCI_COMPONENT
47ACPI_MODULE_NAME("pci_link"); 47ACPI_MODULE_NAME("pci_link");
48#define ACPI_PCI_LINK_CLASS "pci_irq_routing" 48#define ACPI_PCI_LINK_CLASS "pci_irq_routing"
49#define ACPI_PCI_LINK_DEVICE_NAME "PCI Interrupt Link" 49#define ACPI_PCI_LINK_DEVICE_NAME "PCI Interrupt Link"
50#define ACPI_PCI_LINK_FILE_INFO "info" 50#define ACPI_PCI_LINK_FILE_INFO "info"
51#define ACPI_PCI_LINK_FILE_STATUS "state" 51#define ACPI_PCI_LINK_FILE_STATUS "state"
52#define ACPI_PCI_LINK_MAX_POSSIBLE 16 52#define ACPI_PCI_LINK_MAX_POSSIBLE 16
53
53static int acpi_pci_link_add(struct acpi_device *device); 54static int acpi_pci_link_add(struct acpi_device *device);
54static int acpi_pci_link_remove(struct acpi_device *device, int type); 55static int acpi_pci_link_remove(struct acpi_device *device, int type);
55 56
@@ -66,7 +67,7 @@ static struct acpi_driver acpi_pci_link_driver = {
66 .ops = { 67 .ops = {
67 .add = acpi_pci_link_add, 68 .add = acpi_pci_link_add,
68 .remove = acpi_pci_link_remove, 69 .remove = acpi_pci_link_remove,
69 }, 70 },
70}; 71};
71 72
72/* 73/*
@@ -76,7 +77,7 @@ static struct acpi_driver acpi_pci_link_driver = {
76struct acpi_pci_link_irq { 77struct acpi_pci_link_irq {
77 u8 active; /* Current IRQ */ 78 u8 active; /* Current IRQ */
78 u8 triggering; /* All IRQs */ 79 u8 triggering; /* All IRQs */
79 u8 polarity; /* All IRQs */ 80 u8 polarity; /* All IRQs */
80 u8 resource_type; 81 u8 resource_type;
81 u8 possible_count; 82 u8 possible_count;
82 u8 possible[ACPI_PCI_LINK_MAX_POSSIBLE]; 83 u8 possible[ACPI_PCI_LINK_MAX_POSSIBLE];
@@ -85,16 +86,13 @@ struct acpi_pci_link_irq {
85}; 86};
86 87
87struct acpi_pci_link { 88struct acpi_pci_link {
88 struct list_head node; 89 struct list_head list;
89 struct acpi_device *device; 90 struct acpi_device *device;
90 struct acpi_pci_link_irq irq; 91 struct acpi_pci_link_irq irq;
91 int refcnt; 92 int refcnt;
92}; 93};
93 94
94static struct { 95static LIST_HEAD(acpi_link_list);
95 int count;
96 struct list_head entries;
97} acpi_link;
98static DEFINE_MUTEX(acpi_link_lock); 96static DEFINE_MUTEX(acpi_link_lock);
99 97
100/* -------------------------------------------------------------------------- 98/* --------------------------------------------------------------------------
@@ -104,12 +102,11 @@ static DEFINE_MUTEX(acpi_link_lock);
104/* 102/*
105 * set context (link) possible list from resource list 103 * set context (link) possible list from resource list
106 */ 104 */
107static acpi_status 105static acpi_status acpi_pci_link_check_possible(struct acpi_resource *resource,
108acpi_pci_link_check_possible(struct acpi_resource *resource, void *context) 106 void *context)
109{ 107{
110 struct acpi_pci_link *link = context; 108 struct acpi_pci_link *link = context;
111 u32 i = 0; 109 u32 i;
112
113 110
114 switch (resource->type) { 111 switch (resource->type) {
115 case ACPI_RESOURCE_TYPE_START_DEPENDENT: 112 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
@@ -179,10 +176,6 @@ static int acpi_pci_link_get_possible(struct acpi_pci_link *link)
179{ 176{
180 acpi_status status; 177 acpi_status status;
181 178
182
183 if (!link)
184 return -EINVAL;
185
186 status = acpi_walk_resources(link->device->handle, METHOD_NAME__PRS, 179 status = acpi_walk_resources(link->device->handle, METHOD_NAME__PRS,
187 acpi_pci_link_check_possible, link); 180 acpi_pci_link_check_possible, link);
188 if (ACPI_FAILURE(status)) { 181 if (ACPI_FAILURE(status)) {
@@ -197,11 +190,10 @@ static int acpi_pci_link_get_possible(struct acpi_pci_link *link)
197 return 0; 190 return 0;
198} 191}
199 192
200static acpi_status 193static acpi_status acpi_pci_link_check_current(struct acpi_resource *resource,
201acpi_pci_link_check_current(struct acpi_resource *resource, void *context) 194 void *context)
202{ 195{
203 int *irq = (int *)context; 196 int *irq = context;
204
205 197
206 switch (resource->type) { 198 switch (resource->type) {
207 case ACPI_RESOURCE_TYPE_START_DEPENDENT: 199 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
@@ -258,12 +250,9 @@ acpi_pci_link_check_current(struct acpi_resource *resource, void *context)
258static int acpi_pci_link_get_current(struct acpi_pci_link *link) 250static int acpi_pci_link_get_current(struct acpi_pci_link *link)
259{ 251{
260 int result = 0; 252 int result = 0;
261 acpi_status status = AE_OK; 253 acpi_status status;
262 int irq = 0; 254 int irq = 0;
263 255
264 if (!link)
265 return -EINVAL;
266
267 link->irq.active = 0; 256 link->irq.active = 0;
268 257
269 /* in practice, status disabled is meaningless, ignore it */ 258 /* in practice, status disabled is meaningless, ignore it */
@@ -308,16 +297,15 @@ static int acpi_pci_link_get_current(struct acpi_pci_link *link)
308 297
309static int acpi_pci_link_set(struct acpi_pci_link *link, int irq) 298static int acpi_pci_link_set(struct acpi_pci_link *link, int irq)
310{ 299{
311 int result = 0; 300 int result;
312 acpi_status status = AE_OK; 301 acpi_status status;
313 struct { 302 struct {
314 struct acpi_resource res; 303 struct acpi_resource res;
315 struct acpi_resource end; 304 struct acpi_resource end;
316 } *resource; 305 } *resource;
317 struct acpi_buffer buffer = { 0, NULL }; 306 struct acpi_buffer buffer = { 0, NULL };
318 307
319 308 if (!irq)
320 if (!link || !irq)
321 return -EINVAL; 309 return -EINVAL;
322 310
323 resource = kzalloc(sizeof(*resource) + 1, irqs_disabled() ? GFP_ATOMIC: GFP_KERNEL); 311 resource = kzalloc(sizeof(*resource) + 1, irqs_disabled() ? GFP_ATOMIC: GFP_KERNEL);
@@ -479,30 +467,22 @@ static int acpi_irq_penalty[ACPI_MAX_IRQS] = {
479 PIRQ_PENALTY_PCI_AVAILABLE, /* IRQ9 PCI, often acpi */ 467 PIRQ_PENALTY_PCI_AVAILABLE, /* IRQ9 PCI, often acpi */
480 PIRQ_PENALTY_PCI_AVAILABLE, /* IRQ10 PCI */ 468 PIRQ_PENALTY_PCI_AVAILABLE, /* IRQ10 PCI */
481 PIRQ_PENALTY_PCI_AVAILABLE, /* IRQ11 PCI */ 469 PIRQ_PENALTY_PCI_AVAILABLE, /* IRQ11 PCI */
482 PIRQ_PENALTY_ISA_USED, /* IRQ12 mouse */ 470 PIRQ_PENALTY_ISA_USED, /* IRQ12 mouse */
483 PIRQ_PENALTY_ISA_USED, /* IRQ13 fpe, sometimes */ 471 PIRQ_PENALTY_ISA_USED, /* IRQ13 fpe, sometimes */
484 PIRQ_PENALTY_ISA_USED, /* IRQ14 ide0 */ 472 PIRQ_PENALTY_ISA_USED, /* IRQ14 ide0 */
485 PIRQ_PENALTY_ISA_USED, /* IRQ15 ide1 */ 473 PIRQ_PENALTY_ISA_USED, /* IRQ15 ide1 */
486 /* >IRQ15 */ 474 /* >IRQ15 */
487}; 475};
488 476
489int __init acpi_irq_penalty_init(void) 477int __init acpi_irq_penalty_init(void)
490{ 478{
491 struct list_head *node = NULL; 479 struct acpi_pci_link *link;
492 struct acpi_pci_link *link = NULL; 480 int i;
493 int i = 0;
494
495 481
496 /* 482 /*
497 * Update penalties to facilitate IRQ balancing. 483 * Update penalties to facilitate IRQ balancing.
498 */ 484 */
499 list_for_each(node, &acpi_link.entries) { 485 list_for_each_entry(link, &acpi_link_list, list) {
500
501 link = list_entry(node, struct acpi_pci_link, node);
502 if (!link) {
503 printk(KERN_ERR PREFIX "Invalid link context\n");
504 continue;
505 }
506 486
507 /* 487 /*
508 * reflect the possible and active irqs in the penalty table -- 488 * reflect the possible and active irqs in the penalty table --
@@ -527,7 +507,6 @@ int __init acpi_irq_penalty_init(void)
527 } 507 }
528 /* Add a penalty for the SCI */ 508 /* Add a penalty for the SCI */
529 acpi_irq_penalty[acpi_gbl_FADT.sci_interrupt] += PIRQ_PENALTY_PCI_USING; 509 acpi_irq_penalty[acpi_gbl_FADT.sci_interrupt] += PIRQ_PENALTY_PCI_USING;
530
531 return 0; 510 return 0;
532} 511}
533 512
@@ -538,7 +517,6 @@ static int acpi_pci_link_allocate(struct acpi_pci_link *link)
538 int irq; 517 int irq;
539 int i; 518 int i;
540 519
541
542 if (link->irq.initialized) { 520 if (link->irq.initialized) {
543 if (link->refcnt == 0) 521 if (link->refcnt == 0)
544 /* This means the link is disabled but initialized */ 522 /* This means the link is disabled but initialized */
@@ -566,11 +544,10 @@ static int acpi_pci_link_allocate(struct acpi_pci_link *link)
566 /* 544 /*
567 * if active found, use it; else pick entry from end of possible list. 545 * if active found, use it; else pick entry from end of possible list.
568 */ 546 */
569 if (link->irq.active) { 547 if (link->irq.active)
570 irq = link->irq.active; 548 irq = link->irq.active;
571 } else { 549 else
572 irq = link->irq.possible[link->irq.possible_count - 1]; 550 irq = link->irq.possible[link->irq.possible_count - 1];
573 }
574 551
575 if (acpi_irq_balance || !link->irq.active) { 552 if (acpi_irq_balance || !link->irq.active) {
576 /* 553 /*
@@ -593,13 +570,12 @@ static int acpi_pci_link_allocate(struct acpi_pci_link *link)
593 return -ENODEV; 570 return -ENODEV;
594 } else { 571 } else {
595 acpi_irq_penalty[link->irq.active] += PIRQ_PENALTY_PCI_USING; 572 acpi_irq_penalty[link->irq.active] += PIRQ_PENALTY_PCI_USING;
596 printk(PREFIX "%s [%s] enabled at IRQ %d\n", 573 printk(KERN_WARNING PREFIX "%s [%s] enabled at IRQ %d\n",
597 acpi_device_name(link->device), 574 acpi_device_name(link->device),
598 acpi_device_bid(link->device), link->irq.active); 575 acpi_device_bid(link->device), link->irq.active);
599 } 576 }
600 577
601 link->irq.initialized = 1; 578 link->irq.initialized = 1;
602
603 return 0; 579 return 0;
604} 580}
605 581
@@ -608,16 +584,12 @@ static int acpi_pci_link_allocate(struct acpi_pci_link *link)
608 * success: return IRQ >= 0 584 * success: return IRQ >= 0
609 * failure: return -1 585 * failure: return -1
610 */ 586 */
611 587int acpi_pci_link_allocate_irq(acpi_handle handle, int index, int *triggering,
612int 588 int *polarity, char **name)
613acpi_pci_link_allocate_irq(acpi_handle handle,
614 int index,
615 int *triggering, int *polarity, char **name)
616{ 589{
617 int result = 0; 590 int result;
618 struct acpi_device *device = NULL; 591 struct acpi_device *device;
619 struct acpi_pci_link *link = NULL; 592 struct acpi_pci_link *link;
620
621 593
622 result = acpi_bus_get_device(handle, &device); 594 result = acpi_bus_get_device(handle, &device);
623 if (result) { 595 if (result) {
@@ -669,11 +641,10 @@ acpi_pci_link_allocate_irq(acpi_handle handle,
669 */ 641 */
670int acpi_pci_link_free_irq(acpi_handle handle) 642int acpi_pci_link_free_irq(acpi_handle handle)
671{ 643{
672 struct acpi_device *device = NULL; 644 struct acpi_device *device;
673 struct acpi_pci_link *link = NULL; 645 struct acpi_pci_link *link;
674 acpi_status result; 646 acpi_status result;
675 647
676
677 result = acpi_bus_get_device(handle, &device); 648 result = acpi_bus_get_device(handle, &device);
678 if (result) { 649 if (result) {
679 printk(KERN_ERR PREFIX "Invalid link device\n"); 650 printk(KERN_ERR PREFIX "Invalid link device\n");
@@ -708,9 +679,9 @@ int acpi_pci_link_free_irq(acpi_handle handle)
708 "Link %s is dereferenced\n", 679 "Link %s is dereferenced\n",
709 acpi_device_bid(link->device))); 680 acpi_device_bid(link->device)));
710 681
711 if (link->refcnt == 0) { 682 if (link->refcnt == 0)
712 acpi_evaluate_object(link->device->handle, "_DIS", NULL, NULL); 683 acpi_evaluate_object(link->device->handle, "_DIS", NULL, NULL);
713 } 684
714 mutex_unlock(&acpi_link_lock); 685 mutex_unlock(&acpi_link_lock);
715 return (link->irq.active); 686 return (link->irq.active);
716} 687}
@@ -721,15 +692,11 @@ int acpi_pci_link_free_irq(acpi_handle handle)
721 692
722static int acpi_pci_link_add(struct acpi_device *device) 693static int acpi_pci_link_add(struct acpi_device *device)
723{ 694{
724 int result = 0; 695 int result;
725 struct acpi_pci_link *link = NULL; 696 struct acpi_pci_link *link;
726 int i = 0; 697 int i;
727 int found = 0; 698 int found = 0;
728 699
729
730 if (!device)
731 return -EINVAL;
732
733 link = kzalloc(sizeof(struct acpi_pci_link), GFP_KERNEL); 700 link = kzalloc(sizeof(struct acpi_pci_link), GFP_KERNEL);
734 if (!link) 701 if (!link)
735 return -ENOMEM; 702 return -ENOMEM;
@@ -767,9 +734,7 @@ static int acpi_pci_link_add(struct acpi_device *device)
767 734
768 printk("\n"); 735 printk("\n");
769 736
770 /* TBD: Acquire/release lock */ 737 list_add_tail(&link->list, &acpi_link_list);
771 list_add_tail(&link->node, &acpi_link.entries);
772 acpi_link.count++;
773 738
774 end: 739 end:
775 /* disable all links -- to be activated on use */ 740 /* disable all links -- to be activated on use */
@@ -784,24 +749,17 @@ static int acpi_pci_link_add(struct acpi_device *device)
784 749
785static int acpi_pci_link_resume(struct acpi_pci_link *link) 750static int acpi_pci_link_resume(struct acpi_pci_link *link)
786{ 751{
787
788 if (link->refcnt && link->irq.active && link->irq.initialized) 752 if (link->refcnt && link->irq.active && link->irq.initialized)
789 return (acpi_pci_link_set(link, link->irq.active)); 753 return (acpi_pci_link_set(link, link->irq.active));
790 else 754
791 return 0; 755 return 0;
792} 756}
793 757
794static int irqrouter_resume(struct sys_device *dev) 758static int irqrouter_resume(struct sys_device *dev)
795{ 759{
796 struct list_head *node = NULL; 760 struct acpi_pci_link *link;
797 struct acpi_pci_link *link = NULL;
798 761
799 list_for_each(node, &acpi_link.entries) { 762 list_for_each_entry(link, &acpi_link_list, list) {
800 link = list_entry(node, struct acpi_pci_link, node);
801 if (!link) {
802 printk(KERN_ERR PREFIX "Invalid link context\n");
803 continue;
804 }
805 acpi_pci_link_resume(link); 763 acpi_pci_link_resume(link);
806 } 764 }
807 return 0; 765 return 0;
@@ -809,20 +767,15 @@ static int irqrouter_resume(struct sys_device *dev)
809 767
810static int acpi_pci_link_remove(struct acpi_device *device, int type) 768static int acpi_pci_link_remove(struct acpi_device *device, int type)
811{ 769{
812 struct acpi_pci_link *link = NULL; 770 struct acpi_pci_link *link;
813
814
815 if (!device || !acpi_driver_data(device))
816 return -EINVAL;
817 771
818 link = acpi_driver_data(device); 772 link = acpi_driver_data(device);
819 773
820 mutex_lock(&acpi_link_lock); 774 mutex_lock(&acpi_link_lock);
821 list_del(&link->node); 775 list_del(&link->list);
822 mutex_unlock(&acpi_link_lock); 776 mutex_unlock(&acpi_link_lock);
823 777
824 kfree(link); 778 kfree(link);
825
826 return 0; 779 return 0;
827} 780}
828 781
@@ -931,7 +884,6 @@ static int __init irqrouter_init_sysfs(void)
931{ 884{
932 int error; 885 int error;
933 886
934
935 if (acpi_disabled || acpi_noirq) 887 if (acpi_disabled || acpi_noirq)
936 return 0; 888 return 0;
937 889
@@ -957,9 +909,6 @@ static int __init acpi_pci_link_init(void)
957 acpi_irq_balance = 0; 909 acpi_irq_balance = 0;
958 } 910 }
959 911
960 acpi_link.count = 0;
961 INIT_LIST_HEAD(&acpi_link.entries);
962
963 if (acpi_bus_register_driver(&acpi_pci_link_driver) < 0) 912 if (acpi_bus_register_driver(&acpi_pci_link_driver) < 0)
964 return -ENODEV; 913 return -ENODEV;
965 914
diff --git a/drivers/acpi/pci_root.c b/drivers/acpi/pci_root.c
index 5b38a026d122..196f97d00956 100644
--- a/drivers/acpi/pci_root.c
+++ b/drivers/acpi/pci_root.c
@@ -66,11 +66,18 @@ struct acpi_pci_root {
66 struct acpi_device * device; 66 struct acpi_device * device;
67 struct acpi_pci_id id; 67 struct acpi_pci_id id;
68 struct pci_bus *bus; 68 struct pci_bus *bus;
69
70 u32 osc_support_set; /* _OSC state of support bits */
71 u32 osc_control_set; /* _OSC state of control bits */
72 u32 osc_control_qry; /* the latest _OSC query result */
73
74 u32 osc_queried:1; /* has _OSC control been queried? */
69}; 75};
70 76
71static LIST_HEAD(acpi_pci_roots); 77static LIST_HEAD(acpi_pci_roots);
72 78
73static struct acpi_pci_driver *sub_driver; 79static struct acpi_pci_driver *sub_driver;
80static DEFINE_MUTEX(osc_lock);
74 81
75int acpi_pci_register_driver(struct acpi_pci_driver *driver) 82int acpi_pci_register_driver(struct acpi_pci_driver *driver)
76{ 83{
@@ -185,6 +192,175 @@ static void acpi_pci_bridge_scan(struct acpi_device *device)
185 } 192 }
186} 193}
187 194
195static u8 OSC_UUID[16] = {0x5B, 0x4D, 0xDB, 0x33, 0xF7, 0x1F, 0x1C, 0x40,
196 0x96, 0x57, 0x74, 0x41, 0xC0, 0x3D, 0xD7, 0x66};
197
198static acpi_status acpi_pci_run_osc(acpi_handle handle,
199 const u32 *capbuf, u32 *retval)
200{
201 acpi_status status;
202 struct acpi_object_list input;
203 union acpi_object in_params[4];
204 struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL};
205 union acpi_object *out_obj;
206 u32 errors;
207
208 /* Setting up input parameters */
209 input.count = 4;
210 input.pointer = in_params;
211 in_params[0].type = ACPI_TYPE_BUFFER;
212 in_params[0].buffer.length = 16;
213 in_params[0].buffer.pointer = OSC_UUID;
214 in_params[1].type = ACPI_TYPE_INTEGER;
215 in_params[1].integer.value = 1;
216 in_params[2].type = ACPI_TYPE_INTEGER;
217 in_params[2].integer.value = 3;
218 in_params[3].type = ACPI_TYPE_BUFFER;
219 in_params[3].buffer.length = 12;
220 in_params[3].buffer.pointer = (u8 *)capbuf;
221
222 status = acpi_evaluate_object(handle, "_OSC", &input, &output);
223 if (ACPI_FAILURE(status))
224 return status;
225
226 if (!output.length)
227 return AE_NULL_OBJECT;
228
229 out_obj = output.pointer;
230 if (out_obj->type != ACPI_TYPE_BUFFER) {
231 printk(KERN_DEBUG "_OSC evaluation returned wrong type\n");
232 status = AE_TYPE;
233 goto out_kfree;
234 }
235 /* Need to ignore the bit0 in result code */
236 errors = *((u32 *)out_obj->buffer.pointer) & ~(1 << 0);
237 if (errors) {
238 if (errors & OSC_REQUEST_ERROR)
239 printk(KERN_DEBUG "_OSC request failed\n");
240 if (errors & OSC_INVALID_UUID_ERROR)
241 printk(KERN_DEBUG "_OSC invalid UUID\n");
242 if (errors & OSC_INVALID_REVISION_ERROR)
243 printk(KERN_DEBUG "_OSC invalid revision\n");
244 if (errors & OSC_CAPABILITIES_MASK_ERROR) {
245 if (capbuf[OSC_QUERY_TYPE] & OSC_QUERY_ENABLE)
246 goto out_success;
247 printk(KERN_DEBUG
248 "Firmware did not grant requested _OSC control\n");
249 status = AE_SUPPORT;
250 goto out_kfree;
251 }
252 status = AE_ERROR;
253 goto out_kfree;
254 }
255out_success:
256 *retval = *((u32 *)(out_obj->buffer.pointer + 8));
257 status = AE_OK;
258
259out_kfree:
260 kfree(output.pointer);
261 return status;
262}
263
264static acpi_status acpi_pci_query_osc(struct acpi_pci_root *root, u32 flags)
265{
266 acpi_status status;
267 u32 support_set, result, capbuf[3];
268
269 /* do _OSC query for all possible controls */
270 support_set = root->osc_support_set | (flags & OSC_SUPPORT_MASKS);
271 capbuf[OSC_QUERY_TYPE] = OSC_QUERY_ENABLE;
272 capbuf[OSC_SUPPORT_TYPE] = support_set;
273 capbuf[OSC_CONTROL_TYPE] = OSC_CONTROL_MASKS;
274
275 status = acpi_pci_run_osc(root->device->handle, capbuf, &result);
276 if (ACPI_SUCCESS(status)) {
277 root->osc_support_set = support_set;
278 root->osc_control_qry = result;
279 root->osc_queried = 1;
280 }
281 return status;
282}
283
284static acpi_status acpi_pci_osc_support(struct acpi_pci_root *root, u32 flags)
285{
286 acpi_status status;
287 acpi_handle tmp;
288
289 status = acpi_get_handle(root->device->handle, "_OSC", &tmp);
290 if (ACPI_FAILURE(status))
291 return status;
292 mutex_lock(&osc_lock);
293 status = acpi_pci_query_osc(root, flags);
294 mutex_unlock(&osc_lock);
295 return status;
296}
297
298static struct acpi_pci_root *acpi_pci_find_root(acpi_handle handle)
299{
300 struct acpi_pci_root *root;
301 list_for_each_entry(root, &acpi_pci_roots, node) {
302 if (root->device->handle == handle)
303 return root;
304 }
305 return NULL;
306}
307
308/**
309 * acpi_pci_osc_control_set - commit requested control to Firmware
310 * @handle: acpi_handle for the target ACPI object
311 * @flags: driver's requested control bits
312 *
313 * Attempt to take control from Firmware on requested control bits.
314 **/
315acpi_status acpi_pci_osc_control_set(acpi_handle handle, u32 flags)
316{
317 acpi_status status;
318 u32 control_req, result, capbuf[3];
319 acpi_handle tmp;
320 struct acpi_pci_root *root;
321
322 status = acpi_get_handle(handle, "_OSC", &tmp);
323 if (ACPI_FAILURE(status))
324 return status;
325
326 control_req = (flags & OSC_CONTROL_MASKS);
327 if (!control_req)
328 return AE_TYPE;
329
330 root = acpi_pci_find_root(handle);
331 if (!root)
332 return AE_NOT_EXIST;
333
334 mutex_lock(&osc_lock);
335 /* No need to evaluate _OSC if the control was already granted. */
336 if ((root->osc_control_set & control_req) == control_req)
337 goto out;
338
339 /* Need to query controls first before requesting them */
340 if (!root->osc_queried) {
341 status = acpi_pci_query_osc(root, root->osc_support_set);
342 if (ACPI_FAILURE(status))
343 goto out;
344 }
345 if ((root->osc_control_qry & control_req) != control_req) {
346 printk(KERN_DEBUG
347 "Firmware did not grant requested _OSC control\n");
348 status = AE_SUPPORT;
349 goto out;
350 }
351
352 capbuf[OSC_QUERY_TYPE] = 0;
353 capbuf[OSC_SUPPORT_TYPE] = root->osc_support_set;
354 capbuf[OSC_CONTROL_TYPE] = root->osc_control_set | control_req;
355 status = acpi_pci_run_osc(handle, capbuf, &result);
356 if (ACPI_SUCCESS(status))
357 root->osc_control_set = result;
358out:
359 mutex_unlock(&osc_lock);
360 return status;
361}
362EXPORT_SYMBOL(acpi_pci_osc_control_set);
363
188static int __devinit acpi_pci_root_add(struct acpi_device *device) 364static int __devinit acpi_pci_root_add(struct acpi_device *device)
189{ 365{
190 int result = 0; 366 int result = 0;
@@ -217,7 +393,7 @@ static int __devinit acpi_pci_root_add(struct acpi_device *device)
217 * PCI domains, so we indicate this in _OSC support capabilities. 393 * PCI domains, so we indicate this in _OSC support capabilities.
218 */ 394 */
219 flags = base_flags = OSC_PCI_SEGMENT_GROUPS_SUPPORT; 395 flags = base_flags = OSC_PCI_SEGMENT_GROUPS_SUPPORT;
220 pci_acpi_osc_support(device->handle, flags); 396 acpi_pci_osc_support(root, flags);
221 397
222 /* 398 /*
223 * Segment 399 * Segment
@@ -353,7 +529,7 @@ static int __devinit acpi_pci_root_add(struct acpi_device *device)
353 if (pci_msi_enabled()) 529 if (pci_msi_enabled())
354 flags |= OSC_MSI_SUPPORT; 530 flags |= OSC_MSI_SUPPORT;
355 if (flags != base_flags) 531 if (flags != base_flags)
356 pci_acpi_osc_support(device->handle, flags); 532 acpi_pci_osc_support(root, flags);
357 533
358 end: 534 end:
359 if (result) { 535 if (result) {
diff --git a/drivers/acpi/pci_slot.c b/drivers/acpi/pci_slot.c
index cd1f4467be7b..12158e0d009b 100644
--- a/drivers/acpi/pci_slot.c
+++ b/drivers/acpi/pci_slot.c
@@ -164,6 +164,8 @@ register_slot(acpi_handle handle, u32 lvl, void *context, void **rv)
164 list_add(&slot->list, &slot_list); 164 list_add(&slot->list, &slot_list);
165 mutex_unlock(&slot_list_lock); 165 mutex_unlock(&slot_list_lock);
166 166
167 get_device(&pci_bus->dev);
168
167 dbg("pci_slot: %p, pci_bus: %x, device: %d, name: %s\n", 169 dbg("pci_slot: %p, pci_bus: %x, device: %d, name: %s\n",
168 pci_slot, pci_bus->number, device, name); 170 pci_slot, pci_bus->number, device, name);
169 171
@@ -310,12 +312,15 @@ static void
310acpi_pci_slot_remove(acpi_handle handle) 312acpi_pci_slot_remove(acpi_handle handle)
311{ 313{
312 struct acpi_pci_slot *slot, *tmp; 314 struct acpi_pci_slot *slot, *tmp;
315 struct pci_bus *pbus;
313 316
314 mutex_lock(&slot_list_lock); 317 mutex_lock(&slot_list_lock);
315 list_for_each_entry_safe(slot, tmp, &slot_list, list) { 318 list_for_each_entry_safe(slot, tmp, &slot_list, list) {
316 if (slot->root_handle == handle) { 319 if (slot->root_handle == handle) {
317 list_del(&slot->list); 320 list_del(&slot->list);
321 pbus = slot->pci_slot->bus;
318 pci_destroy_slot(slot->pci_slot); 322 pci_destroy_slot(slot->pci_slot);
323 put_device(&pbus->dev);
319 kfree(slot); 324 kfree(slot);
320 } 325 }
321 } 326 }
diff --git a/drivers/acpi/power.c b/drivers/acpi/power.c
index c926e7d4a0d6..56665a63bf19 100644
--- a/drivers/acpi/power.c
+++ b/drivers/acpi/power.c
@@ -54,10 +54,6 @@ ACPI_MODULE_NAME("power");
54#define ACPI_POWER_RESOURCE_STATE_ON 0x01 54#define ACPI_POWER_RESOURCE_STATE_ON 0x01
55#define ACPI_POWER_RESOURCE_STATE_UNKNOWN 0xFF 55#define ACPI_POWER_RESOURCE_STATE_UNKNOWN 0xFF
56 56
57#ifdef MODULE_PARAM_PREFIX
58#undef MODULE_PARAM_PREFIX
59#endif
60#define MODULE_PARAM_PREFIX "acpi."
61int acpi_power_nocheck; 57int acpi_power_nocheck;
62module_param_named(power_nocheck, acpi_power_nocheck, bool, 000); 58module_param_named(power_nocheck, acpi_power_nocheck, bool, 000);
63 59
@@ -773,14 +769,10 @@ static int acpi_power_resume(struct acpi_device *device)
773 return 0; 769 return 0;
774} 770}
775 771
776static int __init acpi_power_init(void) 772int __init acpi_power_init(void)
777{ 773{
778 int result = 0; 774 int result = 0;
779 775
780
781 if (acpi_disabled)
782 return 0;
783
784 INIT_LIST_HEAD(&acpi_power_resource_list); 776 INIT_LIST_HEAD(&acpi_power_resource_list);
785 777
786 acpi_power_dir = proc_mkdir(ACPI_POWER_CLASS, acpi_root_dir); 778 acpi_power_dir = proc_mkdir(ACPI_POWER_CLASS, acpi_root_dir);
@@ -795,5 +787,3 @@ static int __init acpi_power_init(void)
795 787
796 return 0; 788 return 0;
797} 789}
798
799subsys_initcall(acpi_power_init);
diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
index 428c911dba08..d0d550d22a6d 100644
--- a/drivers/acpi/proc.c
+++ b/drivers/acpi/proc.c
@@ -343,9 +343,6 @@ acpi_system_write_alarm(struct file *file,
343} 343}
344#endif /* HAVE_ACPI_LEGACY_ALARM */ 344#endif /* HAVE_ACPI_LEGACY_ALARM */
345 345
346extern struct list_head acpi_wakeup_device_list;
347extern spinlock_t acpi_device_lock;
348
349static int 346static int
350acpi_system_wakeup_device_seq_show(struct seq_file *seq, void *offset) 347acpi_system_wakeup_device_seq_show(struct seq_file *seq, void *offset)
351{ 348{
@@ -353,7 +350,7 @@ acpi_system_wakeup_device_seq_show(struct seq_file *seq, void *offset)
353 350
354 seq_printf(seq, "Device\tS-state\t Status Sysfs node\n"); 351 seq_printf(seq, "Device\tS-state\t Status Sysfs node\n");
355 352
356 spin_lock(&acpi_device_lock); 353 mutex_lock(&acpi_device_lock);
357 list_for_each_safe(node, next, &acpi_wakeup_device_list) { 354 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
358 struct acpi_device *dev = 355 struct acpi_device *dev =
359 container_of(node, struct acpi_device, wakeup_list); 356 container_of(node, struct acpi_device, wakeup_list);
@@ -361,7 +358,6 @@ acpi_system_wakeup_device_seq_show(struct seq_file *seq, void *offset)
361 358
362 if (!dev->wakeup.flags.valid) 359 if (!dev->wakeup.flags.valid)
363 continue; 360 continue;
364 spin_unlock(&acpi_device_lock);
365 361
366 ldev = acpi_get_physical_device(dev->handle); 362 ldev = acpi_get_physical_device(dev->handle);
367 seq_printf(seq, "%s\t S%d\t%c%-8s ", 363 seq_printf(seq, "%s\t S%d\t%c%-8s ",
@@ -376,9 +372,8 @@ acpi_system_wakeup_device_seq_show(struct seq_file *seq, void *offset)
376 seq_printf(seq, "\n"); 372 seq_printf(seq, "\n");
377 put_device(ldev); 373 put_device(ldev);
378 374
379 spin_lock(&acpi_device_lock);
380 } 375 }
381 spin_unlock(&acpi_device_lock); 376 mutex_unlock(&acpi_device_lock);
382 return 0; 377 return 0;
383} 378}
384 379
@@ -409,7 +404,7 @@ acpi_system_write_wakeup_device(struct file *file,
409 strbuf[len] = '\0'; 404 strbuf[len] = '\0';
410 sscanf(strbuf, "%s", str); 405 sscanf(strbuf, "%s", str);
411 406
412 spin_lock(&acpi_device_lock); 407 mutex_lock(&acpi_device_lock);
413 list_for_each_safe(node, next, &acpi_wakeup_device_list) { 408 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
414 struct acpi_device *dev = 409 struct acpi_device *dev =
415 container_of(node, struct acpi_device, wakeup_list); 410 container_of(node, struct acpi_device, wakeup_list);
@@ -446,7 +441,7 @@ acpi_system_write_wakeup_device(struct file *file,
446 } 441 }
447 } 442 }
448 } 443 }
449 spin_unlock(&acpi_device_lock); 444 mutex_unlock(&acpi_device_lock);
450 return count; 445 return count;
451} 446}
452 447
@@ -496,11 +491,8 @@ static u32 rtc_handler(void *context)
496} 491}
497#endif /* HAVE_ACPI_LEGACY_ALARM */ 492#endif /* HAVE_ACPI_LEGACY_ALARM */
498 493
499static int __init acpi_sleep_proc_init(void) 494int __init acpi_sleep_proc_init(void)
500{ 495{
501 if (acpi_disabled)
502 return 0;
503
504#ifdef CONFIG_ACPI_PROCFS 496#ifdef CONFIG_ACPI_PROCFS
505 /* 'sleep' [R/W] */ 497 /* 'sleep' [R/W] */
506 proc_create("sleep", S_IFREG | S_IRUGO | S_IWUSR, 498 proc_create("sleep", S_IFREG | S_IRUGO | S_IWUSR,
@@ -527,5 +519,3 @@ static int __init acpi_sleep_proc_init(void)
527 519
528 return 0; 520 return 0;
529} 521}
530
531late_initcall(acpi_sleep_proc_init);
diff --git a/drivers/acpi/processor_core.c b/drivers/acpi/processor_core.c
index 0cc2fd31e376..45ad3288c5ff 100644
--- a/drivers/acpi/processor_core.c
+++ b/drivers/acpi/processor_core.c
@@ -82,7 +82,7 @@ static int acpi_processor_add(struct acpi_device *device);
82static int acpi_processor_start(struct acpi_device *device); 82static int acpi_processor_start(struct acpi_device *device);
83static int acpi_processor_remove(struct acpi_device *device, int type); 83static int acpi_processor_remove(struct acpi_device *device, int type);
84static int acpi_processor_info_open_fs(struct inode *inode, struct file *file); 84static int acpi_processor_info_open_fs(struct inode *inode, struct file *file);
85static void acpi_processor_notify(acpi_handle handle, u32 event, void *data); 85static void acpi_processor_notify(struct acpi_device *device, u32 event);
86static acpi_status acpi_processor_hotadd_init(acpi_handle handle, int *p_cpu); 86static acpi_status acpi_processor_hotadd_init(acpi_handle handle, int *p_cpu);
87static int acpi_processor_handle_eject(struct acpi_processor *pr); 87static int acpi_processor_handle_eject(struct acpi_processor *pr);
88 88
@@ -104,6 +104,7 @@ static struct acpi_driver acpi_processor_driver = {
104 .start = acpi_processor_start, 104 .start = acpi_processor_start,
105 .suspend = acpi_processor_suspend, 105 .suspend = acpi_processor_suspend,
106 .resume = acpi_processor_resume, 106 .resume = acpi_processor_resume,
107 .notify = acpi_processor_notify,
107 }, 108 },
108}; 109};
109 110
@@ -359,7 +360,6 @@ static int acpi_processor_add_fs(struct acpi_device *device)
359 if (!acpi_device_dir(device)) 360 if (!acpi_device_dir(device))
360 return -ENODEV; 361 return -ENODEV;
361 } 362 }
362 acpi_device_dir(device)->owner = THIS_MODULE;
363 363
364 /* 'info' [R] */ 364 /* 'info' [R] */
365 entry = proc_create_data(ACPI_PROCESSOR_FILE_INFO, 365 entry = proc_create_data(ACPI_PROCESSOR_FILE_INFO,
@@ -427,6 +427,29 @@ static int map_lapic_id(struct acpi_subtable_header *entry,
427 return 0; 427 return 0;
428} 428}
429 429
430static int map_x2apic_id(struct acpi_subtable_header *entry,
431 int device_declaration, u32 acpi_id, int *apic_id)
432{
433 struct acpi_madt_local_x2apic *apic =
434 (struct acpi_madt_local_x2apic *)entry;
435 u32 tmp = apic->local_apic_id;
436
437 /* Only check enabled APICs*/
438 if (!(apic->lapic_flags & ACPI_MADT_ENABLED))
439 return 0;
440
441 /* Device statement declaration type */
442 if (device_declaration) {
443 if (apic->uid == acpi_id)
444 goto found;
445 }
446
447 return 0;
448found:
449 *apic_id = tmp;
450 return 1;
451}
452
430static int map_lsapic_id(struct acpi_subtable_header *entry, 453static int map_lsapic_id(struct acpi_subtable_header *entry,
431 int device_declaration, u32 acpi_id, int *apic_id) 454 int device_declaration, u32 acpi_id, int *apic_id)
432{ 455{
@@ -476,6 +499,9 @@ static int map_madt_entry(int type, u32 acpi_id)
476 if (header->type == ACPI_MADT_TYPE_LOCAL_APIC) { 499 if (header->type == ACPI_MADT_TYPE_LOCAL_APIC) {
477 if (map_lapic_id(header, acpi_id, &apic_id)) 500 if (map_lapic_id(header, acpi_id, &apic_id))
478 break; 501 break;
502 } else if (header->type == ACPI_MADT_TYPE_LOCAL_X2APIC) {
503 if (map_x2apic_id(header, type, acpi_id, &apic_id))
504 break;
479 } else if (header->type == ACPI_MADT_TYPE_LOCAL_SAPIC) { 505 } else if (header->type == ACPI_MADT_TYPE_LOCAL_SAPIC) {
480 if (map_lsapic_id(header, type, acpi_id, &apic_id)) 506 if (map_lsapic_id(header, type, acpi_id, &apic_id))
481 break; 507 break;
@@ -666,7 +692,6 @@ static DEFINE_PER_CPU(void *, processor_device_array);
666static int __cpuinit acpi_processor_start(struct acpi_device *device) 692static int __cpuinit acpi_processor_start(struct acpi_device *device)
667{ 693{
668 int result = 0; 694 int result = 0;
669 acpi_status status = AE_OK;
670 struct acpi_processor *pr; 695 struct acpi_processor *pr;
671 struct sys_device *sysdev; 696 struct sys_device *sysdev;
672 697
@@ -703,9 +728,6 @@ static int __cpuinit acpi_processor_start(struct acpi_device *device)
703 if (sysfs_create_link(&device->dev.kobj, &sysdev->kobj, "sysdev")) 728 if (sysfs_create_link(&device->dev.kobj, &sysdev->kobj, "sysdev"))
704 return -EFAULT; 729 return -EFAULT;
705 730
706 status = acpi_install_notify_handler(pr->handle, ACPI_DEVICE_NOTIFY,
707 acpi_processor_notify, pr);
708
709 /* _PDC call should be done before doing anything else (if reqd.). */ 731 /* _PDC call should be done before doing anything else (if reqd.). */
710 arch_acpi_processor_init_pdc(pr); 732 arch_acpi_processor_init_pdc(pr);
711 acpi_processor_set_pdc(pr); 733 acpi_processor_set_pdc(pr);
@@ -751,18 +773,14 @@ static int __cpuinit acpi_processor_start(struct acpi_device *device)
751 return result; 773 return result;
752} 774}
753 775
754static void acpi_processor_notify(acpi_handle handle, u32 event, void *data) 776static void acpi_processor_notify(struct acpi_device *device, u32 event)
755{ 777{
756 struct acpi_processor *pr = data; 778 struct acpi_processor *pr = acpi_driver_data(device);
757 struct acpi_device *device = NULL;
758 int saved; 779 int saved;
759 780
760 if (!pr) 781 if (!pr)
761 return; 782 return;
762 783
763 if (acpi_bus_get_device(pr->handle, &device))
764 return;
765
766 switch (event) { 784 switch (event) {
767 case ACPI_PROCESSOR_NOTIFY_PERFORMANCE: 785 case ACPI_PROCESSOR_NOTIFY_PERFORMANCE:
768 saved = pr->performance_platform_limit; 786 saved = pr->performance_platform_limit;
@@ -841,7 +859,6 @@ static int acpi_processor_add(struct acpi_device *device)
841 859
842static int acpi_processor_remove(struct acpi_device *device, int type) 860static int acpi_processor_remove(struct acpi_device *device, int type)
843{ 861{
844 acpi_status status = AE_OK;
845 struct acpi_processor *pr = NULL; 862 struct acpi_processor *pr = NULL;
846 863
847 864
@@ -860,9 +877,6 @@ static int acpi_processor_remove(struct acpi_device *device, int type)
860 877
861 acpi_processor_power_exit(pr, device); 878 acpi_processor_power_exit(pr, device);
862 879
863 status = acpi_remove_notify_handler(pr->handle, ACPI_DEVICE_NOTIFY,
864 acpi_processor_notify);
865
866 sysfs_remove_link(&device->dev.kobj, "sysdev"); 880 sysfs_remove_link(&device->dev.kobj, "sysdev");
867 881
868 acpi_processor_remove_fs(device); 882 acpi_processor_remove_fs(device);
@@ -1137,7 +1151,6 @@ static int __init acpi_processor_init(void)
1137 acpi_processor_dir = proc_mkdir(ACPI_PROCESSOR_CLASS, acpi_root_dir); 1151 acpi_processor_dir = proc_mkdir(ACPI_PROCESSOR_CLASS, acpi_root_dir);
1138 if (!acpi_processor_dir) 1152 if (!acpi_processor_dir)
1139 return -ENOMEM; 1153 return -ENOMEM;
1140 acpi_processor_dir->owner = THIS_MODULE;
1141 1154
1142 /* 1155 /*
1143 * Check whether the system is DMI table. If yes, OSPM 1156 * Check whether the system is DMI table. If yes, OSPM
diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
index 66a9d8145562..f7ca8c55956b 100644
--- a/drivers/acpi/processor_idle.c
+++ b/drivers/acpi/processor_idle.c
@@ -64,46 +64,23 @@
64#define _COMPONENT ACPI_PROCESSOR_COMPONENT 64#define _COMPONENT ACPI_PROCESSOR_COMPONENT
65ACPI_MODULE_NAME("processor_idle"); 65ACPI_MODULE_NAME("processor_idle");
66#define ACPI_PROCESSOR_FILE_POWER "power" 66#define ACPI_PROCESSOR_FILE_POWER "power"
67#define US_TO_PM_TIMER_TICKS(t) ((t * (PM_TIMER_FREQUENCY/1000)) / 1000)
68#define PM_TIMER_TICK_NS (1000000000ULL/PM_TIMER_FREQUENCY) 67#define PM_TIMER_TICK_NS (1000000000ULL/PM_TIMER_FREQUENCY)
69#ifndef CONFIG_CPU_IDLE
70#define C2_OVERHEAD 4 /* 1us (3.579 ticks per us) */
71#define C3_OVERHEAD 4 /* 1us (3.579 ticks per us) */
72static void (*pm_idle_save) (void) __read_mostly;
73#else
74#define C2_OVERHEAD 1 /* 1us */ 68#define C2_OVERHEAD 1 /* 1us */
75#define C3_OVERHEAD 1 /* 1us */ 69#define C3_OVERHEAD 1 /* 1us */
76#endif
77#define PM_TIMER_TICKS_TO_US(p) (((p) * 1000)/(PM_TIMER_FREQUENCY/1000)) 70#define PM_TIMER_TICKS_TO_US(p) (((p) * 1000)/(PM_TIMER_FREQUENCY/1000))
78 71
79static unsigned int max_cstate __read_mostly = ACPI_PROCESSOR_MAX_POWER; 72static unsigned int max_cstate __read_mostly = ACPI_PROCESSOR_MAX_POWER;
80#ifdef CONFIG_CPU_IDLE
81module_param(max_cstate, uint, 0000); 73module_param(max_cstate, uint, 0000);
82#else
83module_param(max_cstate, uint, 0644);
84#endif
85static unsigned int nocst __read_mostly; 74static unsigned int nocst __read_mostly;
86module_param(nocst, uint, 0000); 75module_param(nocst, uint, 0000);
87 76
88#ifndef CONFIG_CPU_IDLE
89/*
90 * bm_history -- bit-mask with a bit per jiffy of bus-master activity
91 * 1000 HZ: 0xFFFFFFFF: 32 jiffies = 32ms
92 * 800 HZ: 0xFFFFFFFF: 32 jiffies = 40ms
93 * 100 HZ: 0x0000000F: 4 jiffies = 40ms
94 * reduce history for more aggressive entry into C3
95 */
96static unsigned int bm_history __read_mostly =
97 (HZ >= 800 ? 0xFFFFFFFF : ((1U << (HZ / 25)) - 1));
98module_param(bm_history, uint, 0644);
99
100static int acpi_processor_set_power_policy(struct acpi_processor *pr);
101
102#else /* CONFIG_CPU_IDLE */
103static unsigned int latency_factor __read_mostly = 2; 77static unsigned int latency_factor __read_mostly = 2;
104module_param(latency_factor, uint, 0644); 78module_param(latency_factor, uint, 0644);
105#endif
106 79
80static s64 us_to_pm_timer_ticks(s64 t)
81{
82 return div64_u64(t * PM_TIMER_FREQUENCY, 1000000);
83}
107/* 84/*
108 * IBM ThinkPad R40e crashes mysteriously when going into C2 or C3. 85 * IBM ThinkPad R40e crashes mysteriously when going into C2 or C3.
109 * For now disable this. Probably a bug somewhere else. 86 * For now disable this. Probably a bug somewhere else.
@@ -127,57 +104,6 @@ static int set_max_cstate(const struct dmi_system_id *id)
127/* Actually this shouldn't be __cpuinitdata, would be better to fix the 104/* Actually this shouldn't be __cpuinitdata, would be better to fix the
128 callers to only run once -AK */ 105 callers to only run once -AK */
129static struct dmi_system_id __cpuinitdata processor_power_dmi_table[] = { 106static struct dmi_system_id __cpuinitdata processor_power_dmi_table[] = {
130 { set_max_cstate, "IBM ThinkPad R40e", {
131 DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
132 DMI_MATCH(DMI_BIOS_VERSION,"1SET70WW")}, (void *)1},
133 { set_max_cstate, "IBM ThinkPad R40e", {
134 DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
135 DMI_MATCH(DMI_BIOS_VERSION,"1SET60WW")}, (void *)1},
136 { set_max_cstate, "IBM ThinkPad R40e", {
137 DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
138 DMI_MATCH(DMI_BIOS_VERSION,"1SET43WW") }, (void*)1},
139 { set_max_cstate, "IBM ThinkPad R40e", {
140 DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
141 DMI_MATCH(DMI_BIOS_VERSION,"1SET45WW") }, (void*)1},
142 { set_max_cstate, "IBM ThinkPad R40e", {
143 DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
144 DMI_MATCH(DMI_BIOS_VERSION,"1SET47WW") }, (void*)1},
145 { set_max_cstate, "IBM ThinkPad R40e", {
146 DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
147 DMI_MATCH(DMI_BIOS_VERSION,"1SET50WW") }, (void*)1},
148 { set_max_cstate, "IBM ThinkPad R40e", {
149 DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
150 DMI_MATCH(DMI_BIOS_VERSION,"1SET52WW") }, (void*)1},
151 { set_max_cstate, "IBM ThinkPad R40e", {
152 DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
153 DMI_MATCH(DMI_BIOS_VERSION,"1SET55WW") }, (void*)1},
154 { set_max_cstate, "IBM ThinkPad R40e", {
155 DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
156 DMI_MATCH(DMI_BIOS_VERSION,"1SET56WW") }, (void*)1},
157 { set_max_cstate, "IBM ThinkPad R40e", {
158 DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
159 DMI_MATCH(DMI_BIOS_VERSION,"1SET59WW") }, (void*)1},
160 { set_max_cstate, "IBM ThinkPad R40e", {
161 DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
162 DMI_MATCH(DMI_BIOS_VERSION,"1SET60WW") }, (void*)1},
163 { set_max_cstate, "IBM ThinkPad R40e", {
164 DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
165 DMI_MATCH(DMI_BIOS_VERSION,"1SET61WW") }, (void*)1},
166 { set_max_cstate, "IBM ThinkPad R40e", {
167 DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
168 DMI_MATCH(DMI_BIOS_VERSION,"1SET62WW") }, (void*)1},
169 { set_max_cstate, "IBM ThinkPad R40e", {
170 DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
171 DMI_MATCH(DMI_BIOS_VERSION,"1SET64WW") }, (void*)1},
172 { set_max_cstate, "IBM ThinkPad R40e", {
173 DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
174 DMI_MATCH(DMI_BIOS_VERSION,"1SET65WW") }, (void*)1},
175 { set_max_cstate, "IBM ThinkPad R40e", {
176 DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
177 DMI_MATCH(DMI_BIOS_VERSION,"1SET68WW") }, (void*)1},
178 { set_max_cstate, "Medion 41700", {
179 DMI_MATCH(DMI_BIOS_VENDOR,"Phoenix Technologies LTD"),
180 DMI_MATCH(DMI_BIOS_VERSION,"R01-A1J")}, (void *)1},
181 { set_max_cstate, "Clevo 5600D", { 107 { set_max_cstate, "Clevo 5600D", {
182 DMI_MATCH(DMI_BIOS_VENDOR,"Phoenix Technologies LTD"), 108 DMI_MATCH(DMI_BIOS_VENDOR,"Phoenix Technologies LTD"),
183 DMI_MATCH(DMI_BIOS_VERSION,"SHE845M0.86C.0013.D.0302131307")}, 109 DMI_MATCH(DMI_BIOS_VERSION,"SHE845M0.86C.0013.D.0302131307")},
@@ -185,25 +111,6 @@ static struct dmi_system_id __cpuinitdata processor_power_dmi_table[] = {
185 {}, 111 {},
186}; 112};
187 113
188static inline u32 ticks_elapsed(u32 t1, u32 t2)
189{
190 if (t2 >= t1)
191 return (t2 - t1);
192 else if (!(acpi_gbl_FADT.flags & ACPI_FADT_32BIT_TIMER))
193 return (((0x00FFFFFF - t1) + t2) & 0x00FFFFFF);
194 else
195 return ((0xFFFFFFFF - t1) + t2);
196}
197
198static inline u32 ticks_elapsed_in_us(u32 t1, u32 t2)
199{
200 if (t2 >= t1)
201 return PM_TIMER_TICKS_TO_US(t2 - t1);
202 else if (!(acpi_gbl_FADT.flags & ACPI_FADT_32BIT_TIMER))
203 return PM_TIMER_TICKS_TO_US(((0x00FFFFFF - t1) + t2) & 0x00FFFFFF);
204 else
205 return PM_TIMER_TICKS_TO_US((0xFFFFFFFF - t1) + t2);
206}
207 114
208/* 115/*
209 * Callers should disable interrupts before the call and enable 116 * Callers should disable interrupts before the call and enable
@@ -224,71 +131,6 @@ static void acpi_safe_halt(void)
224 current_thread_info()->status |= TS_POLLING; 131 current_thread_info()->status |= TS_POLLING;
225} 132}
226 133
227#ifndef CONFIG_CPU_IDLE
228
229static void
230acpi_processor_power_activate(struct acpi_processor *pr,
231 struct acpi_processor_cx *new)
232{
233 struct acpi_processor_cx *old;
234
235 if (!pr || !new)
236 return;
237
238 old = pr->power.state;
239
240 if (old)
241 old->promotion.count = 0;
242 new->demotion.count = 0;
243
244 /* Cleanup from old state. */
245 if (old) {
246 switch (old->type) {
247 case ACPI_STATE_C3:
248 /* Disable bus master reload */
249 if (new->type != ACPI_STATE_C3 && pr->flags.bm_check)
250 acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD, 0);
251 break;
252 }
253 }
254
255 /* Prepare to use new state. */
256 switch (new->type) {
257 case ACPI_STATE_C3:
258 /* Enable bus master reload */
259 if (old->type != ACPI_STATE_C3 && pr->flags.bm_check)
260 acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD, 1);
261 break;
262 }
263
264 pr->power.state = new;
265
266 return;
267}
268
269static atomic_t c3_cpu_count;
270
271/* Common C-state entry for C2, C3, .. */
272static void acpi_cstate_enter(struct acpi_processor_cx *cstate)
273{
274 /* Don't trace irqs off for idle */
275 stop_critical_timings();
276 if (cstate->entry_method == ACPI_CSTATE_FFH) {
277 /* Call into architectural FFH based C-state */
278 acpi_processor_ffh_cstate_enter(cstate);
279 } else {
280 int unused;
281 /* IO port based C-state */
282 inb(cstate->address);
283 /* Dummy wait op - must do something useless after P_LVL2 read
284 because chipsets cannot guarantee that STPCLK# signal
285 gets asserted in time to freeze execution properly. */
286 unused = inl(acpi_gbl_FADT.xpm_timer_block.address);
287 }
288 start_critical_timings();
289}
290#endif /* !CONFIG_CPU_IDLE */
291
292#ifdef ARCH_APICTIMER_STOPS_ON_C3 134#ifdef ARCH_APICTIMER_STOPS_ON_C3
293 135
294/* 136/*
@@ -303,6 +145,9 @@ static void acpi_timer_check_state(int state, struct acpi_processor *pr,
303 struct acpi_processor_power *pwr = &pr->power; 145 struct acpi_processor_power *pwr = &pr->power;
304 u8 type = local_apic_timer_c2_ok ? ACPI_STATE_C3 : ACPI_STATE_C2; 146 u8 type = local_apic_timer_c2_ok ? ACPI_STATE_C3 : ACPI_STATE_C2;
305 147
148 if (cpu_has(&cpu_data(pr->id), X86_FEATURE_ARAT))
149 return;
150
306 /* 151 /*
307 * Check, if one of the previous states already marked the lapic 152 * Check, if one of the previous states already marked the lapic
308 * unstable 153 * unstable
@@ -390,421 +235,6 @@ static int tsc_halts_in_c(int state)
390} 235}
391#endif 236#endif
392 237
393#ifndef CONFIG_CPU_IDLE
394static void acpi_processor_idle(void)
395{
396 struct acpi_processor *pr = NULL;
397 struct acpi_processor_cx *cx = NULL;
398 struct acpi_processor_cx *next_state = NULL;
399 int sleep_ticks = 0;
400 u32 t1, t2 = 0;
401
402 /*
403 * Interrupts must be disabled during bus mastering calculations and
404 * for C2/C3 transitions.
405 */
406 local_irq_disable();
407
408 pr = __get_cpu_var(processors);
409 if (!pr) {
410 local_irq_enable();
411 return;
412 }
413
414 /*
415 * Check whether we truly need to go idle, or should
416 * reschedule:
417 */
418 if (unlikely(need_resched())) {
419 local_irq_enable();
420 return;
421 }
422
423 cx = pr->power.state;
424 if (!cx || acpi_idle_suspend) {
425 if (pm_idle_save) {
426 pm_idle_save(); /* enables IRQs */
427 } else {
428 acpi_safe_halt();
429 local_irq_enable();
430 }
431
432 return;
433 }
434
435 /*
436 * Check BM Activity
437 * -----------------
438 * Check for bus mastering activity (if required), record, and check
439 * for demotion.
440 */
441 if (pr->flags.bm_check) {
442 u32 bm_status = 0;
443 unsigned long diff = jiffies - pr->power.bm_check_timestamp;
444
445 if (diff > 31)
446 diff = 31;
447
448 pr->power.bm_activity <<= diff;
449
450 acpi_get_register(ACPI_BITREG_BUS_MASTER_STATUS, &bm_status);
451 if (bm_status) {
452 pr->power.bm_activity |= 0x1;
453 acpi_set_register(ACPI_BITREG_BUS_MASTER_STATUS, 1);
454 }
455 /*
456 * PIIX4 Erratum #18: Note that BM_STS doesn't always reflect
457 * the true state of bus mastering activity; forcing us to
458 * manually check the BMIDEA bit of each IDE channel.
459 */
460 else if (errata.piix4.bmisx) {
461 if ((inb_p(errata.piix4.bmisx + 0x02) & 0x01)
462 || (inb_p(errata.piix4.bmisx + 0x0A) & 0x01))
463 pr->power.bm_activity |= 0x1;
464 }
465
466 pr->power.bm_check_timestamp = jiffies;
467
468 /*
469 * If bus mastering is or was active this jiffy, demote
470 * to avoid a faulty transition. Note that the processor
471 * won't enter a low-power state during this call (to this
472 * function) but should upon the next.
473 *
474 * TBD: A better policy might be to fallback to the demotion
475 * state (use it for this quantum only) istead of
476 * demoting -- and rely on duration as our sole demotion
477 * qualification. This may, however, introduce DMA
478 * issues (e.g. floppy DMA transfer overrun/underrun).
479 */
480 if ((pr->power.bm_activity & 0x1) &&
481 cx->demotion.threshold.bm) {
482 local_irq_enable();
483 next_state = cx->demotion.state;
484 goto end;
485 }
486 }
487
488#ifdef CONFIG_HOTPLUG_CPU
489 /*
490 * Check for P_LVL2_UP flag before entering C2 and above on
491 * an SMP system. We do it here instead of doing it at _CST/P_LVL
492 * detection phase, to work cleanly with logical CPU hotplug.
493 */
494 if ((cx->type != ACPI_STATE_C1) && (num_online_cpus() > 1) &&
495 !pr->flags.has_cst && !(acpi_gbl_FADT.flags & ACPI_FADT_C2_MP_SUPPORTED))
496 cx = &pr->power.states[ACPI_STATE_C1];
497#endif
498
499 /*
500 * Sleep:
501 * ------
502 * Invoke the current Cx state to put the processor to sleep.
503 */
504 if (cx->type == ACPI_STATE_C2 || cx->type == ACPI_STATE_C3) {
505 current_thread_info()->status &= ~TS_POLLING;
506 /*
507 * TS_POLLING-cleared state must be visible before we
508 * test NEED_RESCHED:
509 */
510 smp_mb();
511 if (need_resched()) {
512 current_thread_info()->status |= TS_POLLING;
513 local_irq_enable();
514 return;
515 }
516 }
517
518 switch (cx->type) {
519
520 case ACPI_STATE_C1:
521 /*
522 * Invoke C1.
523 * Use the appropriate idle routine, the one that would
524 * be used without acpi C-states.
525 */
526 if (pm_idle_save) {
527 pm_idle_save(); /* enables IRQs */
528 } else {
529 acpi_safe_halt();
530 local_irq_enable();
531 }
532
533 /*
534 * TBD: Can't get time duration while in C1, as resumes
535 * go to an ISR rather than here. Need to instrument
536 * base interrupt handler.
537 *
538 * Note: the TSC better not stop in C1, sched_clock() will
539 * skew otherwise.
540 */
541 sleep_ticks = 0xFFFFFFFF;
542
543 break;
544
545 case ACPI_STATE_C2:
546 /* Get start time (ticks) */
547 t1 = inl(acpi_gbl_FADT.xpm_timer_block.address);
548 /* Tell the scheduler that we are going deep-idle: */
549 sched_clock_idle_sleep_event();
550 /* Invoke C2 */
551 acpi_state_timer_broadcast(pr, cx, 1);
552 acpi_cstate_enter(cx);
553 /* Get end time (ticks) */
554 t2 = inl(acpi_gbl_FADT.xpm_timer_block.address);
555
556#if defined (CONFIG_GENERIC_TIME) && defined (CONFIG_X86)
557 /* TSC halts in C2, so notify users */
558 if (tsc_halts_in_c(ACPI_STATE_C2))
559 mark_tsc_unstable("possible TSC halt in C2");
560#endif
561 /* Compute time (ticks) that we were actually asleep */
562 sleep_ticks = ticks_elapsed(t1, t2);
563
564 /* Tell the scheduler how much we idled: */
565 sched_clock_idle_wakeup_event(sleep_ticks*PM_TIMER_TICK_NS);
566
567 /* Re-enable interrupts */
568 local_irq_enable();
569 /* Do not account our idle-switching overhead: */
570 sleep_ticks -= cx->latency_ticks + C2_OVERHEAD;
571
572 current_thread_info()->status |= TS_POLLING;
573 acpi_state_timer_broadcast(pr, cx, 0);
574 break;
575
576 case ACPI_STATE_C3:
577 acpi_unlazy_tlb(smp_processor_id());
578 /*
579 * Must be done before busmaster disable as we might
580 * need to access HPET !
581 */
582 acpi_state_timer_broadcast(pr, cx, 1);
583 /*
584 * disable bus master
585 * bm_check implies we need ARB_DIS
586 * !bm_check implies we need cache flush
587 * bm_control implies whether we can do ARB_DIS
588 *
589 * That leaves a case where bm_check is set and bm_control is
590 * not set. In that case we cannot do much, we enter C3
591 * without doing anything.
592 */
593 if (pr->flags.bm_check && pr->flags.bm_control) {
594 if (atomic_inc_return(&c3_cpu_count) ==
595 num_online_cpus()) {
596 /*
597 * All CPUs are trying to go to C3
598 * Disable bus master arbitration
599 */
600 acpi_set_register(ACPI_BITREG_ARB_DISABLE, 1);
601 }
602 } else if (!pr->flags.bm_check) {
603 /* SMP with no shared cache... Invalidate cache */
604 ACPI_FLUSH_CPU_CACHE();
605 }
606
607 /* Get start time (ticks) */
608 t1 = inl(acpi_gbl_FADT.xpm_timer_block.address);
609 /* Invoke C3 */
610 /* Tell the scheduler that we are going deep-idle: */
611 sched_clock_idle_sleep_event();
612 acpi_cstate_enter(cx);
613 /* Get end time (ticks) */
614 t2 = inl(acpi_gbl_FADT.xpm_timer_block.address);
615 if (pr->flags.bm_check && pr->flags.bm_control) {
616 /* Enable bus master arbitration */
617 atomic_dec(&c3_cpu_count);
618 acpi_set_register(ACPI_BITREG_ARB_DISABLE, 0);
619 }
620
621#if defined (CONFIG_GENERIC_TIME) && defined (CONFIG_X86)
622 /* TSC halts in C3, so notify users */
623 if (tsc_halts_in_c(ACPI_STATE_C3))
624 mark_tsc_unstable("TSC halts in C3");
625#endif
626 /* Compute time (ticks) that we were actually asleep */
627 sleep_ticks = ticks_elapsed(t1, t2);
628 /* Tell the scheduler how much we idled: */
629 sched_clock_idle_wakeup_event(sleep_ticks*PM_TIMER_TICK_NS);
630
631 /* Re-enable interrupts */
632 local_irq_enable();
633 /* Do not account our idle-switching overhead: */
634 sleep_ticks -= cx->latency_ticks + C3_OVERHEAD;
635
636 current_thread_info()->status |= TS_POLLING;
637 acpi_state_timer_broadcast(pr, cx, 0);
638 break;
639
640 default:
641 local_irq_enable();
642 return;
643 }
644 cx->usage++;
645 if ((cx->type != ACPI_STATE_C1) && (sleep_ticks > 0))
646 cx->time += sleep_ticks;
647
648 next_state = pr->power.state;
649
650#ifdef CONFIG_HOTPLUG_CPU
651 /* Don't do promotion/demotion */
652 if ((cx->type == ACPI_STATE_C1) && (num_online_cpus() > 1) &&
653 !pr->flags.has_cst && !(acpi_gbl_FADT.flags & ACPI_FADT_C2_MP_SUPPORTED)) {
654 next_state = cx;
655 goto end;
656 }
657#endif
658
659 /*
660 * Promotion?
661 * ----------
662 * Track the number of longs (time asleep is greater than threshold)
663 * and promote when the count threshold is reached. Note that bus
664 * mastering activity may prevent promotions.
665 * Do not promote above max_cstate.
666 */
667 if (cx->promotion.state &&
668 ((cx->promotion.state - pr->power.states) <= max_cstate)) {
669 if (sleep_ticks > cx->promotion.threshold.ticks &&
670 cx->promotion.state->latency <=
671 pm_qos_requirement(PM_QOS_CPU_DMA_LATENCY)) {
672 cx->promotion.count++;
673 cx->demotion.count = 0;
674 if (cx->promotion.count >=
675 cx->promotion.threshold.count) {
676 if (pr->flags.bm_check) {
677 if (!
678 (pr->power.bm_activity & cx->
679 promotion.threshold.bm)) {
680 next_state =
681 cx->promotion.state;
682 goto end;
683 }
684 } else {
685 next_state = cx->promotion.state;
686 goto end;
687 }
688 }
689 }
690 }
691
692 /*
693 * Demotion?
694 * ---------
695 * Track the number of shorts (time asleep is less than time threshold)
696 * and demote when the usage threshold is reached.
697 */
698 if (cx->demotion.state) {
699 if (sleep_ticks < cx->demotion.threshold.ticks) {
700 cx->demotion.count++;
701 cx->promotion.count = 0;
702 if (cx->demotion.count >= cx->demotion.threshold.count) {
703 next_state = cx->demotion.state;
704 goto end;
705 }
706 }
707 }
708
709 end:
710 /*
711 * Demote if current state exceeds max_cstate
712 * or if the latency of the current state is unacceptable
713 */
714 if ((pr->power.state - pr->power.states) > max_cstate ||
715 pr->power.state->latency >
716 pm_qos_requirement(PM_QOS_CPU_DMA_LATENCY)) {
717 if (cx->demotion.state)
718 next_state = cx->demotion.state;
719 }
720
721 /*
722 * New Cx State?
723 * -------------
724 * If we're going to start using a new Cx state we must clean up
725 * from the previous and prepare to use the new.
726 */
727 if (next_state != pr->power.state)
728 acpi_processor_power_activate(pr, next_state);
729}
730
731static int acpi_processor_set_power_policy(struct acpi_processor *pr)
732{
733 unsigned int i;
734 unsigned int state_is_set = 0;
735 struct acpi_processor_cx *lower = NULL;
736 struct acpi_processor_cx *higher = NULL;
737 struct acpi_processor_cx *cx;
738
739
740 if (!pr)
741 return -EINVAL;
742
743 /*
744 * This function sets the default Cx state policy (OS idle handler).
745 * Our scheme is to promote quickly to C2 but more conservatively
746 * to C3. We're favoring C2 for its characteristics of low latency
747 * (quick response), good power savings, and ability to allow bus
748 * mastering activity. Note that the Cx state policy is completely
749 * customizable and can be altered dynamically.
750 */
751
752 /* startup state */
753 for (i = 1; i < ACPI_PROCESSOR_MAX_POWER; i++) {
754 cx = &pr->power.states[i];
755 if (!cx->valid)
756 continue;
757
758 if (!state_is_set)
759 pr->power.state = cx;
760 state_is_set++;
761 break;
762 }
763
764 if (!state_is_set)
765 return -ENODEV;
766
767 /* demotion */
768 for (i = 1; i < ACPI_PROCESSOR_MAX_POWER; i++) {
769 cx = &pr->power.states[i];
770 if (!cx->valid)
771 continue;
772
773 if (lower) {
774 cx->demotion.state = lower;
775 cx->demotion.threshold.ticks = cx->latency_ticks;
776 cx->demotion.threshold.count = 1;
777 if (cx->type == ACPI_STATE_C3)
778 cx->demotion.threshold.bm = bm_history;
779 }
780
781 lower = cx;
782 }
783
784 /* promotion */
785 for (i = (ACPI_PROCESSOR_MAX_POWER - 1); i > 0; i--) {
786 cx = &pr->power.states[i];
787 if (!cx->valid)
788 continue;
789
790 if (higher) {
791 cx->promotion.state = higher;
792 cx->promotion.threshold.ticks = cx->latency_ticks;
793 if (cx->type >= ACPI_STATE_C2)
794 cx->promotion.threshold.count = 4;
795 else
796 cx->promotion.threshold.count = 10;
797 if (higher->type == ACPI_STATE_C3)
798 cx->promotion.threshold.bm = bm_history;
799 }
800
801 higher = cx;
802 }
803
804 return 0;
805}
806#endif /* !CONFIG_CPU_IDLE */
807
808static int acpi_processor_get_power_info_fadt(struct acpi_processor *pr) 238static int acpi_processor_get_power_info_fadt(struct acpi_processor *pr)
809{ 239{
810 240
@@ -1047,11 +477,7 @@ static void acpi_processor_power_verify_c2(struct acpi_processor_cx *cx)
1047 */ 477 */
1048 cx->valid = 1; 478 cx->valid = 1;
1049 479
1050#ifndef CONFIG_CPU_IDLE
1051 cx->latency_ticks = US_TO_PM_TIMER_TICKS(cx->latency);
1052#else
1053 cx->latency_ticks = cx->latency; 480 cx->latency_ticks = cx->latency;
1054#endif
1055 481
1056 return; 482 return;
1057} 483}
@@ -1121,7 +547,6 @@ static void acpi_processor_power_verify_c3(struct acpi_processor *pr,
1121 " for C3 to be enabled on SMP systems\n")); 547 " for C3 to be enabled on SMP systems\n"));
1122 return; 548 return;
1123 } 549 }
1124 acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD, 0);
1125 } 550 }
1126 551
1127 /* 552 /*
@@ -1132,11 +557,16 @@ static void acpi_processor_power_verify_c3(struct acpi_processor *pr,
1132 */ 557 */
1133 cx->valid = 1; 558 cx->valid = 1;
1134 559
1135#ifndef CONFIG_CPU_IDLE
1136 cx->latency_ticks = US_TO_PM_TIMER_TICKS(cx->latency);
1137#else
1138 cx->latency_ticks = cx->latency; 560 cx->latency_ticks = cx->latency;
1139#endif 561 /*
562 * On older chipsets, BM_RLD needs to be set
563 * in order for Bus Master activity to wake the
564 * system from C3. Newer chipsets handle DMA
565 * during C3 automatically and BM_RLD is a NOP.
566 * In either case, the proper way to
567 * handle BM_RLD is to set it and leave it set.
568 */
569 acpi_write_bit_register(ACPI_BITREG_BUS_MASTER_RLD, 1);
1140 570
1141 return; 571 return;
1142} 572}
@@ -1151,6 +581,11 @@ static int acpi_processor_power_verify(struct acpi_processor *pr)
1151 for (i = 1; i < ACPI_PROCESSOR_MAX_POWER; i++) { 581 for (i = 1; i < ACPI_PROCESSOR_MAX_POWER; i++) {
1152 struct acpi_processor_cx *cx = &pr->power.states[i]; 582 struct acpi_processor_cx *cx = &pr->power.states[i];
1153 583
584#if defined (CONFIG_GENERIC_TIME) && defined (CONFIG_X86)
585 /* TSC could halt in idle, so notify users */
586 if (tsc_halts_in_c(cx->type))
587 mark_tsc_unstable("TSC halts in idle");;
588#endif
1154 switch (cx->type) { 589 switch (cx->type) {
1155 case ACPI_STATE_C1: 590 case ACPI_STATE_C1:
1156 cx->valid = 1; 591 cx->valid = 1;
@@ -1201,20 +636,6 @@ static int acpi_processor_get_power_info(struct acpi_processor *pr)
1201 636
1202 pr->power.count = acpi_processor_power_verify(pr); 637 pr->power.count = acpi_processor_power_verify(pr);
1203 638
1204#ifndef CONFIG_CPU_IDLE
1205 /*
1206 * Set Default Policy
1207 * ------------------
1208 * Now that we know which states are supported, set the default
1209 * policy. Note that this policy can be changed dynamically
1210 * (e.g. encourage deeper sleeps to conserve battery life when
1211 * not on AC).
1212 */
1213 result = acpi_processor_set_power_policy(pr);
1214 if (result)
1215 return result;
1216#endif
1217
1218 /* 639 /*
1219 * if one state of type C2 or C3 is available, mark this 640 * if one state of type C2 or C3 is available, mark this
1220 * CPU as being "idle manageable" 641 * CPU as being "idle manageable"
@@ -1241,11 +662,9 @@ static int acpi_processor_power_seq_show(struct seq_file *seq, void *offset)
1241 662
1242 seq_printf(seq, "active state: C%zd\n" 663 seq_printf(seq, "active state: C%zd\n"
1243 "max_cstate: C%d\n" 664 "max_cstate: C%d\n"
1244 "bus master activity: %08x\n"
1245 "maximum allowed latency: %d usec\n", 665 "maximum allowed latency: %d usec\n",
1246 pr->power.state ? pr->power.state - pr->power.states : 0, 666 pr->power.state ? pr->power.state - pr->power.states : 0,
1247 max_cstate, (unsigned)pr->power.bm_activity, 667 max_cstate, pm_qos_requirement(PM_QOS_CPU_DMA_LATENCY));
1248 pm_qos_requirement(PM_QOS_CPU_DMA_LATENCY));
1249 668
1250 seq_puts(seq, "states:\n"); 669 seq_puts(seq, "states:\n");
1251 670
@@ -1312,69 +731,6 @@ static const struct file_operations acpi_processor_power_fops = {
1312 .release = single_release, 731 .release = single_release,
1313}; 732};
1314 733
1315#ifndef CONFIG_CPU_IDLE
1316
1317int acpi_processor_cst_has_changed(struct acpi_processor *pr)
1318{
1319 int result = 0;
1320
1321 if (boot_option_idle_override)
1322 return 0;
1323
1324 if (!pr)
1325 return -EINVAL;
1326
1327 if (nocst) {
1328 return -ENODEV;
1329 }
1330
1331 if (!pr->flags.power_setup_done)
1332 return -ENODEV;
1333
1334 /*
1335 * Fall back to the default idle loop, when pm_idle_save had
1336 * been initialized.
1337 */
1338 if (pm_idle_save) {
1339 pm_idle = pm_idle_save;
1340 /* Relies on interrupts forcing exit from idle. */
1341 synchronize_sched();
1342 }
1343
1344 pr->flags.power = 0;
1345 result = acpi_processor_get_power_info(pr);
1346 if ((pr->flags.power == 1) && (pr->flags.power_setup_done))
1347 pm_idle = acpi_processor_idle;
1348
1349 return result;
1350}
1351
1352#ifdef CONFIG_SMP
1353static void smp_callback(void *v)
1354{
1355 /* we already woke the CPU up, nothing more to do */
1356}
1357
1358/*
1359 * This function gets called when a part of the kernel has a new latency
1360 * requirement. This means we need to get all processors out of their C-state,
1361 * and then recalculate a new suitable C-state. Just do a cross-cpu IPI; that
1362 * wakes them all right up.
1363 */
1364static int acpi_processor_latency_notify(struct notifier_block *b,
1365 unsigned long l, void *v)
1366{
1367 smp_call_function(smp_callback, NULL, 1);
1368 return NOTIFY_OK;
1369}
1370
1371static struct notifier_block acpi_processor_latency_notifier = {
1372 .notifier_call = acpi_processor_latency_notify,
1373};
1374
1375#endif
1376
1377#else /* CONFIG_CPU_IDLE */
1378 734
1379/** 735/**
1380 * acpi_idle_bm_check - checks if bus master activity was detected 736 * acpi_idle_bm_check - checks if bus master activity was detected
@@ -1383,9 +739,9 @@ static int acpi_idle_bm_check(void)
1383{ 739{
1384 u32 bm_status = 0; 740 u32 bm_status = 0;
1385 741
1386 acpi_get_register(ACPI_BITREG_BUS_MASTER_STATUS, &bm_status); 742 acpi_read_bit_register(ACPI_BITREG_BUS_MASTER_STATUS, &bm_status);
1387 if (bm_status) 743 if (bm_status)
1388 acpi_set_register(ACPI_BITREG_BUS_MASTER_STATUS, 1); 744 acpi_write_bit_register(ACPI_BITREG_BUS_MASTER_STATUS, 1);
1389 /* 745 /*
1390 * PIIX4 Erratum #18: Note that BM_STS doesn't always reflect 746 * PIIX4 Erratum #18: Note that BM_STS doesn't always reflect
1391 * the true state of bus mastering activity; forcing us to 747 * the true state of bus mastering activity; forcing us to
@@ -1400,25 +756,6 @@ static int acpi_idle_bm_check(void)
1400} 756}
1401 757
1402/** 758/**
1403 * acpi_idle_update_bm_rld - updates the BM_RLD bit depending on target state
1404 * @pr: the processor
1405 * @target: the new target state
1406 */
1407static inline void acpi_idle_update_bm_rld(struct acpi_processor *pr,
1408 struct acpi_processor_cx *target)
1409{
1410 if (pr->flags.bm_rld_set && target->type != ACPI_STATE_C3) {
1411 acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD, 0);
1412 pr->flags.bm_rld_set = 0;
1413 }
1414
1415 if (!pr->flags.bm_rld_set && target->type == ACPI_STATE_C3) {
1416 acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD, 1);
1417 pr->flags.bm_rld_set = 1;
1418 }
1419}
1420
1421/**
1422 * acpi_idle_do_entry - a helper function that does C2 and C3 type entry 759 * acpi_idle_do_entry - a helper function that does C2 and C3 type entry
1423 * @cx: cstate data 760 * @cx: cstate data
1424 * 761 *
@@ -1455,7 +792,8 @@ static inline void acpi_idle_do_entry(struct acpi_processor_cx *cx)
1455static int acpi_idle_enter_c1(struct cpuidle_device *dev, 792static int acpi_idle_enter_c1(struct cpuidle_device *dev,
1456 struct cpuidle_state *state) 793 struct cpuidle_state *state)
1457{ 794{
1458 u32 t1, t2; 795 ktime_t kt1, kt2;
796 s64 idle_time;
1459 struct acpi_processor *pr; 797 struct acpi_processor *pr;
1460 struct acpi_processor_cx *cx = cpuidle_get_statedata(state); 798 struct acpi_processor_cx *cx = cpuidle_get_statedata(state);
1461 799
@@ -1473,17 +811,15 @@ static int acpi_idle_enter_c1(struct cpuidle_device *dev,
1473 return 0; 811 return 0;
1474 } 812 }
1475 813
1476 if (pr->flags.bm_check) 814 kt1 = ktime_get_real();
1477 acpi_idle_update_bm_rld(pr, cx);
1478
1479 t1 = inl(acpi_gbl_FADT.xpm_timer_block.address);
1480 acpi_idle_do_entry(cx); 815 acpi_idle_do_entry(cx);
1481 t2 = inl(acpi_gbl_FADT.xpm_timer_block.address); 816 kt2 = ktime_get_real();
817 idle_time = ktime_to_us(ktime_sub(kt2, kt1));
1482 818
1483 local_irq_enable(); 819 local_irq_enable();
1484 cx->usage++; 820 cx->usage++;
1485 821
1486 return ticks_elapsed_in_us(t1, t2); 822 return idle_time;
1487} 823}
1488 824
1489/** 825/**
@@ -1496,8 +832,9 @@ static int acpi_idle_enter_simple(struct cpuidle_device *dev,
1496{ 832{
1497 struct acpi_processor *pr; 833 struct acpi_processor *pr;
1498 struct acpi_processor_cx *cx = cpuidle_get_statedata(state); 834 struct acpi_processor_cx *cx = cpuidle_get_statedata(state);
1499 u32 t1, t2; 835 ktime_t kt1, kt2;
1500 int sleep_ticks = 0; 836 s64 idle_time;
837 s64 sleep_ticks = 0;
1501 838
1502 pr = __get_cpu_var(processors); 839 pr = __get_cpu_var(processors);
1503 840
@@ -1527,24 +864,17 @@ static int acpi_idle_enter_simple(struct cpuidle_device *dev,
1527 */ 864 */
1528 acpi_state_timer_broadcast(pr, cx, 1); 865 acpi_state_timer_broadcast(pr, cx, 1);
1529 866
1530 if (pr->flags.bm_check)
1531 acpi_idle_update_bm_rld(pr, cx);
1532
1533 if (cx->type == ACPI_STATE_C3) 867 if (cx->type == ACPI_STATE_C3)
1534 ACPI_FLUSH_CPU_CACHE(); 868 ACPI_FLUSH_CPU_CACHE();
1535 869
1536 t1 = inl(acpi_gbl_FADT.xpm_timer_block.address); 870 kt1 = ktime_get_real();
1537 /* Tell the scheduler that we are going deep-idle: */ 871 /* Tell the scheduler that we are going deep-idle: */
1538 sched_clock_idle_sleep_event(); 872 sched_clock_idle_sleep_event();
1539 acpi_idle_do_entry(cx); 873 acpi_idle_do_entry(cx);
1540 t2 = inl(acpi_gbl_FADT.xpm_timer_block.address); 874 kt2 = ktime_get_real();
875 idle_time = ktime_to_us(ktime_sub(kt2, kt1));
1541 876
1542#if defined (CONFIG_GENERIC_TIME) && defined (CONFIG_X86) 877 sleep_ticks = us_to_pm_timer_ticks(idle_time);
1543 /* TSC could halt in idle, so notify users */
1544 if (tsc_halts_in_c(cx->type))
1545 mark_tsc_unstable("TSC halts in idle");;
1546#endif
1547 sleep_ticks = ticks_elapsed(t1, t2);
1548 878
1549 /* Tell the scheduler how much we idled: */ 879 /* Tell the scheduler how much we idled: */
1550 sched_clock_idle_wakeup_event(sleep_ticks*PM_TIMER_TICK_NS); 880 sched_clock_idle_wakeup_event(sleep_ticks*PM_TIMER_TICK_NS);
@@ -1556,7 +886,7 @@ static int acpi_idle_enter_simple(struct cpuidle_device *dev,
1556 886
1557 acpi_state_timer_broadcast(pr, cx, 0); 887 acpi_state_timer_broadcast(pr, cx, 0);
1558 cx->time += sleep_ticks; 888 cx->time += sleep_ticks;
1559 return ticks_elapsed_in_us(t1, t2); 889 return idle_time;
1560} 890}
1561 891
1562static int c3_cpu_count; 892static int c3_cpu_count;
@@ -1574,8 +904,10 @@ static int acpi_idle_enter_bm(struct cpuidle_device *dev,
1574{ 904{
1575 struct acpi_processor *pr; 905 struct acpi_processor *pr;
1576 struct acpi_processor_cx *cx = cpuidle_get_statedata(state); 906 struct acpi_processor_cx *cx = cpuidle_get_statedata(state);
1577 u32 t1, t2; 907 ktime_t kt1, kt2;
1578 int sleep_ticks = 0; 908 s64 idle_time;
909 s64 sleep_ticks = 0;
910
1579 911
1580 pr = __get_cpu_var(processors); 912 pr = __get_cpu_var(processors);
1581 913
@@ -1621,8 +953,7 @@ static int acpi_idle_enter_bm(struct cpuidle_device *dev,
1621 */ 953 */
1622 acpi_state_timer_broadcast(pr, cx, 1); 954 acpi_state_timer_broadcast(pr, cx, 1);
1623 955
1624 acpi_idle_update_bm_rld(pr, cx); 956 kt1 = ktime_get_real();
1625
1626 /* 957 /*
1627 * disable bus master 958 * disable bus master
1628 * bm_check implies we need ARB_DIS 959 * bm_check implies we need ARB_DIS
@@ -1638,30 +969,25 @@ static int acpi_idle_enter_bm(struct cpuidle_device *dev,
1638 c3_cpu_count++; 969 c3_cpu_count++;
1639 /* Disable bus master arbitration when all CPUs are in C3 */ 970 /* Disable bus master arbitration when all CPUs are in C3 */
1640 if (c3_cpu_count == num_online_cpus()) 971 if (c3_cpu_count == num_online_cpus())
1641 acpi_set_register(ACPI_BITREG_ARB_DISABLE, 1); 972 acpi_write_bit_register(ACPI_BITREG_ARB_DISABLE, 1);
1642 spin_unlock(&c3_lock); 973 spin_unlock(&c3_lock);
1643 } else if (!pr->flags.bm_check) { 974 } else if (!pr->flags.bm_check) {
1644 ACPI_FLUSH_CPU_CACHE(); 975 ACPI_FLUSH_CPU_CACHE();
1645 } 976 }
1646 977
1647 t1 = inl(acpi_gbl_FADT.xpm_timer_block.address);
1648 acpi_idle_do_entry(cx); 978 acpi_idle_do_entry(cx);
1649 t2 = inl(acpi_gbl_FADT.xpm_timer_block.address);
1650 979
1651 /* Re-enable bus master arbitration */ 980 /* Re-enable bus master arbitration */
1652 if (pr->flags.bm_check && pr->flags.bm_control) { 981 if (pr->flags.bm_check && pr->flags.bm_control) {
1653 spin_lock(&c3_lock); 982 spin_lock(&c3_lock);
1654 acpi_set_register(ACPI_BITREG_ARB_DISABLE, 0); 983 acpi_write_bit_register(ACPI_BITREG_ARB_DISABLE, 0);
1655 c3_cpu_count--; 984 c3_cpu_count--;
1656 spin_unlock(&c3_lock); 985 spin_unlock(&c3_lock);
1657 } 986 }
987 kt2 = ktime_get_real();
988 idle_time = ktime_to_us(ktime_sub(kt2, kt1));
1658 989
1659#if defined (CONFIG_GENERIC_TIME) && defined (CONFIG_X86) 990 sleep_ticks = us_to_pm_timer_ticks(idle_time);
1660 /* TSC could halt in idle, so notify users */
1661 if (tsc_halts_in_c(ACPI_STATE_C3))
1662 mark_tsc_unstable("TSC halts in idle");
1663#endif
1664 sleep_ticks = ticks_elapsed(t1, t2);
1665 /* Tell the scheduler how much we idled: */ 991 /* Tell the scheduler how much we idled: */
1666 sched_clock_idle_wakeup_event(sleep_ticks*PM_TIMER_TICK_NS); 992 sched_clock_idle_wakeup_event(sleep_ticks*PM_TIMER_TICK_NS);
1667 993
@@ -1672,7 +998,7 @@ static int acpi_idle_enter_bm(struct cpuidle_device *dev,
1672 998
1673 acpi_state_timer_broadcast(pr, cx, 0); 999 acpi_state_timer_broadcast(pr, cx, 0);
1674 cx->time += sleep_ticks; 1000 cx->time += sleep_ticks;
1675 return ticks_elapsed_in_us(t1, t2); 1001 return idle_time;
1676} 1002}
1677 1003
1678struct cpuidle_driver acpi_idle_driver = { 1004struct cpuidle_driver acpi_idle_driver = {
@@ -1704,6 +1030,9 @@ static int acpi_processor_setup_cpuidle(struct acpi_processor *pr)
1704 dev->states[i].desc[0] = '\0'; 1030 dev->states[i].desc[0] = '\0';
1705 } 1031 }
1706 1032
1033 if (max_cstate == 0)
1034 max_cstate = 1;
1035
1707 for (i = 1; i < ACPI_PROCESSOR_MAX_POWER && i <= max_cstate; i++) { 1036 for (i = 1; i < ACPI_PROCESSOR_MAX_POWER && i <= max_cstate; i++) {
1708 cx = &pr->power.states[i]; 1037 cx = &pr->power.states[i];
1709 state = &dev->states[count]; 1038 state = &dev->states[count];
@@ -1795,8 +1124,6 @@ int acpi_processor_cst_has_changed(struct acpi_processor *pr)
1795 return ret; 1124 return ret;
1796} 1125}
1797 1126
1798#endif /* CONFIG_CPU_IDLE */
1799
1800int __cpuinit acpi_processor_power_init(struct acpi_processor *pr, 1127int __cpuinit acpi_processor_power_init(struct acpi_processor *pr,
1801 struct acpi_device *device) 1128 struct acpi_device *device)
1802{ 1129{
@@ -1825,10 +1152,6 @@ int __cpuinit acpi_processor_power_init(struct acpi_processor *pr,
1825 "ACPI: processor limited to max C-state %d\n", 1152 "ACPI: processor limited to max C-state %d\n",
1826 max_cstate); 1153 max_cstate);
1827 first_run++; 1154 first_run++;
1828#if !defined(CONFIG_CPU_IDLE) && defined(CONFIG_SMP)
1829 pm_qos_add_notifier(PM_QOS_CPU_DMA_LATENCY,
1830 &acpi_processor_latency_notifier);
1831#endif
1832 } 1155 }
1833 1156
1834 if (!pr) 1157 if (!pr)
@@ -1852,11 +1175,9 @@ int __cpuinit acpi_processor_power_init(struct acpi_processor *pr,
1852 * platforms that only support C1. 1175 * platforms that only support C1.
1853 */ 1176 */
1854 if (pr->flags.power) { 1177 if (pr->flags.power) {
1855#ifdef CONFIG_CPU_IDLE
1856 acpi_processor_setup_cpuidle(pr); 1178 acpi_processor_setup_cpuidle(pr);
1857 if (cpuidle_register_device(&pr->power.dev)) 1179 if (cpuidle_register_device(&pr->power.dev))
1858 return -EIO; 1180 return -EIO;
1859#endif
1860 1181
1861 printk(KERN_INFO PREFIX "CPU%d (power states:", pr->id); 1182 printk(KERN_INFO PREFIX "CPU%d (power states:", pr->id);
1862 for (i = 1; i <= pr->power.count; i++) 1183 for (i = 1; i <= pr->power.count; i++)
@@ -1864,13 +1185,6 @@ int __cpuinit acpi_processor_power_init(struct acpi_processor *pr,
1864 printk(" C%d[C%d]", i, 1185 printk(" C%d[C%d]", i,
1865 pr->power.states[i].type); 1186 pr->power.states[i].type);
1866 printk(")\n"); 1187 printk(")\n");
1867
1868#ifndef CONFIG_CPU_IDLE
1869 if (pr->id == 0) {
1870 pm_idle_save = pm_idle;
1871 pm_idle = acpi_processor_idle;
1872 }
1873#endif
1874 } 1188 }
1875 1189
1876 /* 'power' [R] */ 1190 /* 'power' [R] */
@@ -1889,34 +1203,12 @@ int acpi_processor_power_exit(struct acpi_processor *pr,
1889 if (boot_option_idle_override) 1203 if (boot_option_idle_override)
1890 return 0; 1204 return 0;
1891 1205
1892#ifdef CONFIG_CPU_IDLE
1893 cpuidle_unregister_device(&pr->power.dev); 1206 cpuidle_unregister_device(&pr->power.dev);
1894#endif
1895 pr->flags.power_setup_done = 0; 1207 pr->flags.power_setup_done = 0;
1896 1208
1897 if (acpi_device_dir(device)) 1209 if (acpi_device_dir(device))
1898 remove_proc_entry(ACPI_PROCESSOR_FILE_POWER, 1210 remove_proc_entry(ACPI_PROCESSOR_FILE_POWER,
1899 acpi_device_dir(device)); 1211 acpi_device_dir(device));
1900 1212
1901#ifndef CONFIG_CPU_IDLE
1902
1903 /* Unregister the idle handler when processor #0 is removed. */
1904 if (pr->id == 0) {
1905 if (pm_idle_save)
1906 pm_idle = pm_idle_save;
1907
1908 /*
1909 * We are about to unload the current idle thread pm callback
1910 * (pm_idle), Wait for all processors to update cached/local
1911 * copies of pm_idle before proceeding.
1912 */
1913 cpu_idle_wait();
1914#ifdef CONFIG_SMP
1915 pm_qos_remove_notifier(PM_QOS_CPU_DMA_LATENCY,
1916 &acpi_processor_latency_notifier);
1917#endif
1918 }
1919#endif
1920
1921 return 0; 1213 return 0;
1922} 1214}
diff --git a/drivers/acpi/processor_perflib.c b/drivers/acpi/processor_perflib.c
index 846e227592d4..cafb41000f6b 100644
--- a/drivers/acpi/processor_perflib.c
+++ b/drivers/acpi/processor_perflib.c
@@ -31,14 +31,6 @@
31#include <linux/init.h> 31#include <linux/init.h>
32#include <linux/cpufreq.h> 32#include <linux/cpufreq.h>
33 33
34#ifdef CONFIG_X86_ACPI_CPUFREQ_PROC_INTF
35#include <linux/proc_fs.h>
36#include <linux/seq_file.h>
37#include <linux/mutex.h>
38
39#include <asm/uaccess.h>
40#endif
41
42#ifdef CONFIG_X86 34#ifdef CONFIG_X86
43#include <asm/cpufeature.h> 35#include <asm/cpufeature.h>
44#endif 36#endif
@@ -434,96 +426,6 @@ int acpi_processor_notify_smm(struct module *calling_module)
434 426
435EXPORT_SYMBOL(acpi_processor_notify_smm); 427EXPORT_SYMBOL(acpi_processor_notify_smm);
436 428
437#ifdef CONFIG_X86_ACPI_CPUFREQ_PROC_INTF
438/* /proc/acpi/processor/../performance interface (DEPRECATED) */
439
440static int acpi_processor_perf_open_fs(struct inode *inode, struct file *file);
441static struct file_operations acpi_processor_perf_fops = {
442 .owner = THIS_MODULE,
443 .open = acpi_processor_perf_open_fs,
444 .read = seq_read,
445 .llseek = seq_lseek,
446 .release = single_release,
447};
448
449static int acpi_processor_perf_seq_show(struct seq_file *seq, void *offset)
450{
451 struct acpi_processor *pr = seq->private;
452 int i;
453
454
455 if (!pr)
456 goto end;
457
458 if (!pr->performance) {
459 seq_puts(seq, "<not supported>\n");
460 goto end;
461 }
462
463 seq_printf(seq, "state count: %d\n"
464 "active state: P%d\n",
465 pr->performance->state_count, pr->performance->state);
466
467 seq_puts(seq, "states:\n");
468 for (i = 0; i < pr->performance->state_count; i++)
469 seq_printf(seq,
470 " %cP%d: %d MHz, %d mW, %d uS\n",
471 (i == pr->performance->state ? '*' : ' '), i,
472 (u32) pr->performance->states[i].core_frequency,
473 (u32) pr->performance->states[i].power,
474 (u32) pr->performance->states[i].transition_latency);
475
476 end:
477 return 0;
478}
479
480static int acpi_processor_perf_open_fs(struct inode *inode, struct file *file)
481{
482 return single_open(file, acpi_processor_perf_seq_show,
483 PDE(inode)->data);
484}
485
486static void acpi_cpufreq_add_file(struct acpi_processor *pr)
487{
488 struct acpi_device *device = NULL;
489
490
491 if (acpi_bus_get_device(pr->handle, &device))
492 return;
493
494 /* add file 'performance' [R/W] */
495 proc_create_data(ACPI_PROCESSOR_FILE_PERFORMANCE, S_IFREG | S_IRUGO,
496 acpi_device_dir(device),
497 &acpi_processor_perf_fops, acpi_driver_data(device));
498 return;
499}
500
501static void acpi_cpufreq_remove_file(struct acpi_processor *pr)
502{
503 struct acpi_device *device = NULL;
504
505
506 if (acpi_bus_get_device(pr->handle, &device))
507 return;
508
509 /* remove file 'performance' */
510 remove_proc_entry(ACPI_PROCESSOR_FILE_PERFORMANCE,
511 acpi_device_dir(device));
512
513 return;
514}
515
516#else
517static void acpi_cpufreq_add_file(struct acpi_processor *pr)
518{
519 return;
520}
521static void acpi_cpufreq_remove_file(struct acpi_processor *pr)
522{
523 return;
524}
525#endif /* CONFIG_X86_ACPI_CPUFREQ_PROC_INTF */
526
527static int acpi_processor_get_psd(struct acpi_processor *pr) 429static int acpi_processor_get_psd(struct acpi_processor *pr)
528{ 430{
529 int result = 0; 431 int result = 0;
@@ -577,6 +479,13 @@ static int acpi_processor_get_psd(struct acpi_processor *pr)
577 goto end; 479 goto end;
578 } 480 }
579 481
482 if (pdomain->coord_type != DOMAIN_COORD_TYPE_SW_ALL &&
483 pdomain->coord_type != DOMAIN_COORD_TYPE_SW_ANY &&
484 pdomain->coord_type != DOMAIN_COORD_TYPE_HW_ALL) {
485 printk(KERN_ERR PREFIX "Invalid _PSD:coord_type\n");
486 result = -EFAULT;
487 goto end;
488 }
580end: 489end:
581 kfree(buffer.pointer); 490 kfree(buffer.pointer);
582 return result; 491 return result;
@@ -599,9 +508,10 @@ int acpi_processor_preregister_performance(
599 508
600 mutex_lock(&performance_mutex); 509 mutex_lock(&performance_mutex);
601 510
602 retval = 0; 511 /*
603 512 * Check if another driver has already registered, and abort before
604 /* Call _PSD for all CPUs */ 513 * changing pr->performance if it has. Check input data as well.
514 */
605 for_each_possible_cpu(i) { 515 for_each_possible_cpu(i) {
606 pr = per_cpu(processors, i); 516 pr = per_cpu(processors, i);
607 if (!pr) { 517 if (!pr) {
@@ -611,15 +521,22 @@ int acpi_processor_preregister_performance(
611 521
612 if (pr->performance) { 522 if (pr->performance) {
613 retval = -EBUSY; 523 retval = -EBUSY;
614 continue; 524 goto err_out;
615 } 525 }
616 526
617 if (!performance || !percpu_ptr(performance, i)) { 527 if (!performance || !per_cpu_ptr(performance, i)) {
618 retval = -EINVAL; 528 retval = -EINVAL;
619 continue; 529 goto err_out;
620 } 530 }
531 }
621 532
622 pr->performance = percpu_ptr(performance, i); 533 /* Call _PSD for all CPUs */
534 for_each_possible_cpu(i) {
535 pr = per_cpu(processors, i);
536 if (!pr)
537 continue;
538
539 pr->performance = per_cpu_ptr(performance, i);
623 cpumask_set_cpu(i, pr->performance->shared_cpu_map); 540 cpumask_set_cpu(i, pr->performance->shared_cpu_map);
624 if (acpi_processor_get_psd(pr)) { 541 if (acpi_processor_get_psd(pr)) {
625 retval = -EINVAL; 542 retval = -EINVAL;
@@ -633,26 +550,6 @@ int acpi_processor_preregister_performance(
633 * Now that we have _PSD data from all CPUs, lets setup P-state 550 * Now that we have _PSD data from all CPUs, lets setup P-state
634 * domain info. 551 * domain info.
635 */ 552 */
636 for_each_possible_cpu(i) {
637 pr = per_cpu(processors, i);
638 if (!pr)
639 continue;
640
641 /* Basic validity check for domain info */
642 pdomain = &(pr->performance->domain_info);
643 if ((pdomain->revision != ACPI_PSD_REV0_REVISION) ||
644 (pdomain->num_entries != ACPI_PSD_REV0_ENTRIES)) {
645 retval = -EINVAL;
646 goto err_ret;
647 }
648 if (pdomain->coord_type != DOMAIN_COORD_TYPE_SW_ALL &&
649 pdomain->coord_type != DOMAIN_COORD_TYPE_SW_ANY &&
650 pdomain->coord_type != DOMAIN_COORD_TYPE_HW_ALL) {
651 retval = -EINVAL;
652 goto err_ret;
653 }
654 }
655
656 cpumask_clear(covered_cpus); 553 cpumask_clear(covered_cpus);
657 for_each_possible_cpu(i) { 554 for_each_possible_cpu(i) {
658 pr = per_cpu(processors, i); 555 pr = per_cpu(processors, i);
@@ -741,20 +638,19 @@ err_ret:
741 pr->performance = NULL; /* Will be set for real in register */ 638 pr->performance = NULL; /* Will be set for real in register */
742 } 639 }
743 640
641err_out:
744 mutex_unlock(&performance_mutex); 642 mutex_unlock(&performance_mutex);
745 free_cpumask_var(covered_cpus); 643 free_cpumask_var(covered_cpus);
746 return retval; 644 return retval;
747} 645}
748EXPORT_SYMBOL(acpi_processor_preregister_performance); 646EXPORT_SYMBOL(acpi_processor_preregister_performance);
749 647
750
751int 648int
752acpi_processor_register_performance(struct acpi_processor_performance 649acpi_processor_register_performance(struct acpi_processor_performance
753 *performance, unsigned int cpu) 650 *performance, unsigned int cpu)
754{ 651{
755 struct acpi_processor *pr; 652 struct acpi_processor *pr;
756 653
757
758 if (!(acpi_processor_ppc_status & PPC_REGISTERED)) 654 if (!(acpi_processor_ppc_status & PPC_REGISTERED))
759 return -EINVAL; 655 return -EINVAL;
760 656
@@ -781,8 +677,6 @@ acpi_processor_register_performance(struct acpi_processor_performance
781 return -EIO; 677 return -EIO;
782 } 678 }
783 679
784 acpi_cpufreq_add_file(pr);
785
786 mutex_unlock(&performance_mutex); 680 mutex_unlock(&performance_mutex);
787 return 0; 681 return 0;
788} 682}
@@ -795,7 +689,6 @@ acpi_processor_unregister_performance(struct acpi_processor_performance
795{ 689{
796 struct acpi_processor *pr; 690 struct acpi_processor *pr;
797 691
798
799 mutex_lock(&performance_mutex); 692 mutex_lock(&performance_mutex);
800 693
801 pr = per_cpu(processors, cpu); 694 pr = per_cpu(processors, cpu);
@@ -808,8 +701,6 @@ acpi_processor_unregister_performance(struct acpi_processor_performance
808 kfree(pr->performance->states); 701 kfree(pr->performance->states);
809 pr->performance = NULL; 702 pr->performance = NULL;
810 703
811 acpi_cpufreq_remove_file(pr);
812
813 mutex_unlock(&performance_mutex); 704 mutex_unlock(&performance_mutex);
814 705
815 return; 706 return;
diff --git a/drivers/acpi/processor_thermal.c b/drivers/acpi/processor_thermal.c
index b1eb376fae45..39838c666032 100644
--- a/drivers/acpi/processor_thermal.c
+++ b/drivers/acpi/processor_thermal.c
@@ -373,7 +373,8 @@ static int acpi_processor_max_state(struct acpi_processor *pr)
373 return max_state; 373 return max_state;
374} 374}
375static int 375static int
376processor_get_max_state(struct thermal_cooling_device *cdev, char *buf) 376processor_get_max_state(struct thermal_cooling_device *cdev,
377 unsigned long *state)
377{ 378{
378 struct acpi_device *device = cdev->devdata; 379 struct acpi_device *device = cdev->devdata;
379 struct acpi_processor *pr = acpi_driver_data(device); 380 struct acpi_processor *pr = acpi_driver_data(device);
@@ -381,28 +382,29 @@ processor_get_max_state(struct thermal_cooling_device *cdev, char *buf)
381 if (!device || !pr) 382 if (!device || !pr)
382 return -EINVAL; 383 return -EINVAL;
383 384
384 return sprintf(buf, "%d\n", acpi_processor_max_state(pr)); 385 *state = acpi_processor_max_state(pr);
386 return 0;
385} 387}
386 388
387static int 389static int
388processor_get_cur_state(struct thermal_cooling_device *cdev, char *buf) 390processor_get_cur_state(struct thermal_cooling_device *cdev,
391 unsigned long *cur_state)
389{ 392{
390 struct acpi_device *device = cdev->devdata; 393 struct acpi_device *device = cdev->devdata;
391 struct acpi_processor *pr = acpi_driver_data(device); 394 struct acpi_processor *pr = acpi_driver_data(device);
392 int cur_state;
393 395
394 if (!device || !pr) 396 if (!device || !pr)
395 return -EINVAL; 397 return -EINVAL;
396 398
397 cur_state = cpufreq_get_cur_state(pr->id); 399 *cur_state = cpufreq_get_cur_state(pr->id);
398 if (pr->flags.throttling) 400 if (pr->flags.throttling)
399 cur_state += pr->throttling.state; 401 *cur_state += pr->throttling.state;
400 402 return 0;
401 return sprintf(buf, "%d\n", cur_state);
402} 403}
403 404
404static int 405static int
405processor_set_cur_state(struct thermal_cooling_device *cdev, unsigned int state) 406processor_set_cur_state(struct thermal_cooling_device *cdev,
407 unsigned long state)
406{ 408{
407 struct acpi_device *device = cdev->devdata; 409 struct acpi_device *device = cdev->devdata;
408 struct acpi_processor *pr = acpi_driver_data(device); 410 struct acpi_processor *pr = acpi_driver_data(device);
@@ -507,7 +509,7 @@ static ssize_t acpi_processor_write_limit(struct file * file,
507 return count; 509 return count;
508} 510}
509 511
510struct file_operations acpi_processor_limit_fops = { 512const struct file_operations acpi_processor_limit_fops = {
511 .owner = THIS_MODULE, 513 .owner = THIS_MODULE,
512 .open = acpi_processor_limit_open_fs, 514 .open = acpi_processor_limit_open_fs,
513 .read = seq_read, 515 .read = seq_read,
diff --git a/drivers/acpi/processor_throttling.c b/drivers/acpi/processor_throttling.c
index d27838171f4a..d0d1f4d50434 100644
--- a/drivers/acpi/processor_throttling.c
+++ b/drivers/acpi/processor_throttling.c
@@ -783,11 +783,9 @@ static int acpi_get_throttling_state(struct acpi_processor *pr,
783 (struct acpi_processor_tx_tss *)&(pr->throttling. 783 (struct acpi_processor_tx_tss *)&(pr->throttling.
784 states_tss[i]); 784 states_tss[i]);
785 if (tx->control == value) 785 if (tx->control == value)
786 break; 786 return i;
787 } 787 }
788 if (i > pr->throttling.state_count) 788 return -1;
789 i = -1;
790 return i;
791} 789}
792 790
793static int acpi_get_throttling_value(struct acpi_processor *pr, 791static int acpi_get_throttling_value(struct acpi_processor *pr,
@@ -1291,7 +1289,7 @@ static ssize_t acpi_processor_write_throttling(struct file *file,
1291 return count; 1289 return count;
1292} 1290}
1293 1291
1294struct file_operations acpi_processor_throttling_fops = { 1292const struct file_operations acpi_processor_throttling_fops = {
1295 .owner = THIS_MODULE, 1293 .owner = THIS_MODULE,
1296 .open = acpi_processor_throttling_open_fs, 1294 .open = acpi_processor_throttling_open_fs,
1297 .read = seq_read, 1295 .read = seq_read,
diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c
index 6050ce481873..4b214b74ebaa 100644
--- a/drivers/acpi/sbs.c
+++ b/drivers/acpi/sbs.c
@@ -102,8 +102,8 @@ struct acpi_battery {
102 u16 cycle_count; 102 u16 cycle_count;
103 u16 temp_now; 103 u16 temp_now;
104 u16 voltage_now; 104 u16 voltage_now;
105 s16 current_now; 105 s16 rate_now;
106 s16 current_avg; 106 s16 rate_avg;
107 u16 capacity_now; 107 u16 capacity_now;
108 u16 state_of_charge; 108 u16 state_of_charge;
109 u16 state; 109 u16 state;
@@ -202,9 +202,9 @@ static int acpi_sbs_battery_get_property(struct power_supply *psy,
202 return -ENODEV; 202 return -ENODEV;
203 switch (psp) { 203 switch (psp) {
204 case POWER_SUPPLY_PROP_STATUS: 204 case POWER_SUPPLY_PROP_STATUS:
205 if (battery->current_now < 0) 205 if (battery->rate_now < 0)
206 val->intval = POWER_SUPPLY_STATUS_DISCHARGING; 206 val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
207 else if (battery->current_now > 0) 207 else if (battery->rate_now > 0)
208 val->intval = POWER_SUPPLY_STATUS_CHARGING; 208 val->intval = POWER_SUPPLY_STATUS_CHARGING;
209 else 209 else
210 val->intval = POWER_SUPPLY_STATUS_FULL; 210 val->intval = POWER_SUPPLY_STATUS_FULL;
@@ -224,11 +224,13 @@ static int acpi_sbs_battery_get_property(struct power_supply *psy,
224 acpi_battery_vscale(battery) * 1000; 224 acpi_battery_vscale(battery) * 1000;
225 break; 225 break;
226 case POWER_SUPPLY_PROP_CURRENT_NOW: 226 case POWER_SUPPLY_PROP_CURRENT_NOW:
227 val->intval = abs(battery->current_now) * 227 case POWER_SUPPLY_PROP_POWER_NOW:
228 val->intval = abs(battery->rate_now) *
228 acpi_battery_ipscale(battery) * 1000; 229 acpi_battery_ipscale(battery) * 1000;
229 break; 230 break;
230 case POWER_SUPPLY_PROP_CURRENT_AVG: 231 case POWER_SUPPLY_PROP_CURRENT_AVG:
231 val->intval = abs(battery->current_avg) * 232 case POWER_SUPPLY_PROP_POWER_AVG:
233 val->intval = abs(battery->rate_avg) *
232 acpi_battery_ipscale(battery) * 1000; 234 acpi_battery_ipscale(battery) * 1000;
233 break; 235 break;
234 case POWER_SUPPLY_PROP_CAPACITY: 236 case POWER_SUPPLY_PROP_CAPACITY:
@@ -293,6 +295,8 @@ static enum power_supply_property sbs_energy_battery_props[] = {
293 POWER_SUPPLY_PROP_VOLTAGE_NOW, 295 POWER_SUPPLY_PROP_VOLTAGE_NOW,
294 POWER_SUPPLY_PROP_CURRENT_NOW, 296 POWER_SUPPLY_PROP_CURRENT_NOW,
295 POWER_SUPPLY_PROP_CURRENT_AVG, 297 POWER_SUPPLY_PROP_CURRENT_AVG,
298 POWER_SUPPLY_PROP_POWER_NOW,
299 POWER_SUPPLY_PROP_POWER_AVG,
296 POWER_SUPPLY_PROP_CAPACITY, 300 POWER_SUPPLY_PROP_CAPACITY,
297 POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN, 301 POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN,
298 POWER_SUPPLY_PROP_ENERGY_FULL, 302 POWER_SUPPLY_PROP_ENERGY_FULL,
@@ -301,6 +305,7 @@ static enum power_supply_property sbs_energy_battery_props[] = {
301 POWER_SUPPLY_PROP_MODEL_NAME, 305 POWER_SUPPLY_PROP_MODEL_NAME,
302 POWER_SUPPLY_PROP_MANUFACTURER, 306 POWER_SUPPLY_PROP_MANUFACTURER,
303}; 307};
308
304#endif 309#endif
305 310
306/* -------------------------------------------------------------------------- 311/* --------------------------------------------------------------------------
@@ -330,8 +335,8 @@ static struct acpi_battery_reader info_readers[] = {
330static struct acpi_battery_reader state_readers[] = { 335static struct acpi_battery_reader state_readers[] = {
331 {0x08, SMBUS_READ_WORD, offsetof(struct acpi_battery, temp_now)}, 336 {0x08, SMBUS_READ_WORD, offsetof(struct acpi_battery, temp_now)},
332 {0x09, SMBUS_READ_WORD, offsetof(struct acpi_battery, voltage_now)}, 337 {0x09, SMBUS_READ_WORD, offsetof(struct acpi_battery, voltage_now)},
333 {0x0a, SMBUS_READ_WORD, offsetof(struct acpi_battery, current_now)}, 338 {0x0a, SMBUS_READ_WORD, offsetof(struct acpi_battery, rate_now)},
334 {0x0b, SMBUS_READ_WORD, offsetof(struct acpi_battery, current_avg)}, 339 {0x0b, SMBUS_READ_WORD, offsetof(struct acpi_battery, rate_avg)},
335 {0x0f, SMBUS_READ_WORD, offsetof(struct acpi_battery, capacity_now)}, 340 {0x0f, SMBUS_READ_WORD, offsetof(struct acpi_battery, capacity_now)},
336 {0x0e, SMBUS_READ_WORD, offsetof(struct acpi_battery, state_of_charge)}, 341 {0x0e, SMBUS_READ_WORD, offsetof(struct acpi_battery, state_of_charge)},
337 {0x16, SMBUS_READ_WORD, offsetof(struct acpi_battery, state)}, 342 {0x16, SMBUS_READ_WORD, offsetof(struct acpi_battery, state)},
@@ -479,16 +484,15 @@ static int
479acpi_sbs_add_fs(struct proc_dir_entry **dir, 484acpi_sbs_add_fs(struct proc_dir_entry **dir,
480 struct proc_dir_entry *parent_dir, 485 struct proc_dir_entry *parent_dir,
481 char *dir_name, 486 char *dir_name,
482 struct file_operations *info_fops, 487 const struct file_operations *info_fops,
483 struct file_operations *state_fops, 488 const struct file_operations *state_fops,
484 struct file_operations *alarm_fops, void *data) 489 const struct file_operations *alarm_fops, void *data)
485{ 490{
486 if (!*dir) { 491 if (!*dir) {
487 *dir = proc_mkdir(dir_name, parent_dir); 492 *dir = proc_mkdir(dir_name, parent_dir);
488 if (!*dir) { 493 if (!*dir) {
489 return -ENODEV; 494 return -ENODEV;
490 } 495 }
491 (*dir)->owner = THIS_MODULE;
492 } 496 }
493 497
494 /* 'info' [R] */ 498 /* 'info' [R] */
@@ -589,9 +593,9 @@ static int acpi_battery_read_state(struct seq_file *seq, void *offset)
589 seq_printf(seq, "capacity state: %s\n", 593 seq_printf(seq, "capacity state: %s\n",
590 (battery->state & 0x0010) ? "critical" : "ok"); 594 (battery->state & 0x0010) ? "critical" : "ok");
591 seq_printf(seq, "charging state: %s\n", 595 seq_printf(seq, "charging state: %s\n",
592 (battery->current_now < 0) ? "discharging" : 596 (battery->rate_now < 0) ? "discharging" :
593 ((battery->current_now > 0) ? "charging" : "charged")); 597 ((battery->rate_now > 0) ? "charging" : "charged"));
594 rate = abs(battery->current_now) * acpi_battery_ipscale(battery); 598 rate = abs(battery->rate_now) * acpi_battery_ipscale(battery);
595 rate *= (acpi_battery_mode(battery))?(battery->voltage_now * 599 rate *= (acpi_battery_mode(battery))?(battery->voltage_now *
596 acpi_battery_vscale(battery)/1000):1; 600 acpi_battery_vscale(battery)/1000):1;
597 seq_printf(seq, "present rate: %d%s\n", rate, 601 seq_printf(seq, "present rate: %d%s\n", rate,
@@ -677,7 +681,7 @@ static int acpi_battery_alarm_open_fs(struct inode *inode, struct file *file)
677 return single_open(file, acpi_battery_read_alarm, PDE(inode)->data); 681 return single_open(file, acpi_battery_read_alarm, PDE(inode)->data);
678} 682}
679 683
680static struct file_operations acpi_battery_info_fops = { 684static const struct file_operations acpi_battery_info_fops = {
681 .open = acpi_battery_info_open_fs, 685 .open = acpi_battery_info_open_fs,
682 .read = seq_read, 686 .read = seq_read,
683 .llseek = seq_lseek, 687 .llseek = seq_lseek,
@@ -685,7 +689,7 @@ static struct file_operations acpi_battery_info_fops = {
685 .owner = THIS_MODULE, 689 .owner = THIS_MODULE,
686}; 690};
687 691
688static struct file_operations acpi_battery_state_fops = { 692static const struct file_operations acpi_battery_state_fops = {
689 .open = acpi_battery_state_open_fs, 693 .open = acpi_battery_state_open_fs,
690 .read = seq_read, 694 .read = seq_read,
691 .llseek = seq_lseek, 695 .llseek = seq_lseek,
@@ -693,7 +697,7 @@ static struct file_operations acpi_battery_state_fops = {
693 .owner = THIS_MODULE, 697 .owner = THIS_MODULE,
694}; 698};
695 699
696static struct file_operations acpi_battery_alarm_fops = { 700static const struct file_operations acpi_battery_alarm_fops = {
697 .open = acpi_battery_alarm_open_fs, 701 .open = acpi_battery_alarm_open_fs,
698 .read = seq_read, 702 .read = seq_read,
699 .write = acpi_battery_write_alarm, 703 .write = acpi_battery_write_alarm,
@@ -725,7 +729,7 @@ static int acpi_ac_state_open_fs(struct inode *inode, struct file *file)
725 return single_open(file, acpi_ac_read_state, PDE(inode)->data); 729 return single_open(file, acpi_ac_read_state, PDE(inode)->data);
726} 730}
727 731
728static struct file_operations acpi_ac_state_fops = { 732static const struct file_operations acpi_ac_state_fops = {
729 .open = acpi_ac_state_open_fs, 733 .open = acpi_ac_state_open_fs,
730 .read = seq_read, 734 .read = seq_read,
731 .llseek = seq_lseek, 735 .llseek = seq_lseek,
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index c54d7b6c4066..8ff510b91d88 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -11,6 +11,8 @@
11 11
12#include <acpi/acpi_drivers.h> 12#include <acpi/acpi_drivers.h>
13 13
14#include "internal.h"
15
14#define _COMPONENT ACPI_BUS_COMPONENT 16#define _COMPONENT ACPI_BUS_COMPONENT
15ACPI_MODULE_NAME("scan"); 17ACPI_MODULE_NAME("scan");
16#define STRUCT_TO_INT(s) (*((int*)&s)) 18#define STRUCT_TO_INT(s) (*((int*)&s))
@@ -22,7 +24,7 @@ extern struct acpi_device *acpi_root;
22 24
23static LIST_HEAD(acpi_device_list); 25static LIST_HEAD(acpi_device_list);
24static LIST_HEAD(acpi_bus_id_list); 26static LIST_HEAD(acpi_bus_id_list);
25DEFINE_SPINLOCK(acpi_device_lock); 27DEFINE_MUTEX(acpi_device_lock);
26LIST_HEAD(acpi_wakeup_device_list); 28LIST_HEAD(acpi_wakeup_device_list);
27 29
28struct acpi_device_bus_id{ 30struct acpi_device_bus_id{
@@ -357,6 +359,61 @@ static int acpi_device_uevent(struct device *dev, struct kobj_uevent_env *env)
357 return 0; 359 return 0;
358} 360}
359 361
362static void acpi_device_notify(acpi_handle handle, u32 event, void *data)
363{
364 struct acpi_device *device = data;
365
366 device->driver->ops.notify(device, event);
367}
368
369static acpi_status acpi_device_notify_fixed(void *data)
370{
371 struct acpi_device *device = data;
372
373 acpi_device_notify(device->handle, ACPI_FIXED_HARDWARE_EVENT, device);
374 return AE_OK;
375}
376
377static int acpi_device_install_notify_handler(struct acpi_device *device)
378{
379 acpi_status status;
380 char *hid;
381
382 hid = acpi_device_hid(device);
383 if (!strcmp(hid, ACPI_BUTTON_HID_POWERF))
384 status =
385 acpi_install_fixed_event_handler(ACPI_EVENT_POWER_BUTTON,
386 acpi_device_notify_fixed,
387 device);
388 else if (!strcmp(hid, ACPI_BUTTON_HID_SLEEPF))
389 status =
390 acpi_install_fixed_event_handler(ACPI_EVENT_SLEEP_BUTTON,
391 acpi_device_notify_fixed,
392 device);
393 else
394 status = acpi_install_notify_handler(device->handle,
395 ACPI_DEVICE_NOTIFY,
396 acpi_device_notify,
397 device);
398
399 if (ACPI_FAILURE(status))
400 return -EINVAL;
401 return 0;
402}
403
404static void acpi_device_remove_notify_handler(struct acpi_device *device)
405{
406 if (!strcmp(acpi_device_hid(device), ACPI_BUTTON_HID_POWERF))
407 acpi_remove_fixed_event_handler(ACPI_EVENT_POWER_BUTTON,
408 acpi_device_notify_fixed);
409 else if (!strcmp(acpi_device_hid(device), ACPI_BUTTON_HID_SLEEPF))
410 acpi_remove_fixed_event_handler(ACPI_EVENT_SLEEP_BUTTON,
411 acpi_device_notify_fixed);
412 else
413 acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
414 acpi_device_notify);
415}
416
360static int acpi_bus_driver_init(struct acpi_device *, struct acpi_driver *); 417static int acpi_bus_driver_init(struct acpi_device *, struct acpi_driver *);
361static int acpi_start_single_object(struct acpi_device *); 418static int acpi_start_single_object(struct acpi_device *);
362static int acpi_device_probe(struct device * dev) 419static int acpi_device_probe(struct device * dev)
@@ -369,6 +426,20 @@ static int acpi_device_probe(struct device * dev)
369 if (!ret) { 426 if (!ret) {
370 if (acpi_dev->bus_ops.acpi_op_start) 427 if (acpi_dev->bus_ops.acpi_op_start)
371 acpi_start_single_object(acpi_dev); 428 acpi_start_single_object(acpi_dev);
429
430 if (acpi_drv->ops.notify) {
431 ret = acpi_device_install_notify_handler(acpi_dev);
432 if (ret) {
433 if (acpi_drv->ops.stop)
434 acpi_drv->ops.stop(acpi_dev,
435 acpi_dev->removal_type);
436 if (acpi_drv->ops.remove)
437 acpi_drv->ops.remove(acpi_dev,
438 acpi_dev->removal_type);
439 return ret;
440 }
441 }
442
372 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 443 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
373 "Found driver [%s] for device [%s]\n", 444 "Found driver [%s] for device [%s]\n",
374 acpi_drv->name, acpi_dev->pnp.bus_id)); 445 acpi_drv->name, acpi_dev->pnp.bus_id));
@@ -383,6 +454,8 @@ static int acpi_device_remove(struct device * dev)
383 struct acpi_driver *acpi_drv = acpi_dev->driver; 454 struct acpi_driver *acpi_drv = acpi_dev->driver;
384 455
385 if (acpi_drv) { 456 if (acpi_drv) {
457 if (acpi_drv->ops.notify)
458 acpi_device_remove_notify_handler(acpi_dev);
386 if (acpi_drv->ops.stop) 459 if (acpi_drv->ops.stop)
387 acpi_drv->ops.stop(acpi_dev, acpi_dev->removal_type); 460 acpi_drv->ops.stop(acpi_dev, acpi_dev->removal_type);
388 if (acpi_drv->ops.remove) 461 if (acpi_drv->ops.remove)
@@ -395,22 +468,10 @@ static int acpi_device_remove(struct device * dev)
395 return 0; 468 return 0;
396} 469}
397 470
398static void acpi_device_shutdown(struct device *dev)
399{
400 struct acpi_device *acpi_dev = to_acpi_device(dev);
401 struct acpi_driver *acpi_drv = acpi_dev->driver;
402
403 if (acpi_drv && acpi_drv->ops.shutdown)
404 acpi_drv->ops.shutdown(acpi_dev);
405
406 return ;
407}
408
409struct bus_type acpi_bus_type = { 471struct bus_type acpi_bus_type = {
410 .name = "acpi", 472 .name = "acpi",
411 .suspend = acpi_device_suspend, 473 .suspend = acpi_device_suspend,
412 .resume = acpi_device_resume, 474 .resume = acpi_device_resume,
413 .shutdown = acpi_device_shutdown,
414 .match = acpi_bus_match, 475 .match = acpi_bus_match,
415 .probe = acpi_device_probe, 476 .probe = acpi_device_probe,
416 .remove = acpi_device_remove, 477 .remove = acpi_device_remove,
@@ -430,7 +491,6 @@ static int acpi_device_register(struct acpi_device *device,
430 */ 491 */
431 INIT_LIST_HEAD(&device->children); 492 INIT_LIST_HEAD(&device->children);
432 INIT_LIST_HEAD(&device->node); 493 INIT_LIST_HEAD(&device->node);
433 INIT_LIST_HEAD(&device->g_list);
434 INIT_LIST_HEAD(&device->wakeup_list); 494 INIT_LIST_HEAD(&device->wakeup_list);
435 495
436 new_bus_id = kzalloc(sizeof(struct acpi_device_bus_id), GFP_KERNEL); 496 new_bus_id = kzalloc(sizeof(struct acpi_device_bus_id), GFP_KERNEL);
@@ -439,7 +499,7 @@ static int acpi_device_register(struct acpi_device *device,
439 return -ENOMEM; 499 return -ENOMEM;
440 } 500 }
441 501
442 spin_lock(&acpi_device_lock); 502 mutex_lock(&acpi_device_lock);
443 /* 503 /*
444 * Find suitable bus_id and instance number in acpi_bus_id_list 504 * Find suitable bus_id and instance number in acpi_bus_id_list
445 * If failed, create one and link it into acpi_bus_id_list 505 * If failed, create one and link it into acpi_bus_id_list
@@ -460,14 +520,12 @@ static int acpi_device_register(struct acpi_device *device,
460 } 520 }
461 dev_set_name(&device->dev, "%s:%02x", acpi_device_bus_id->bus_id, acpi_device_bus_id->instance_no); 521 dev_set_name(&device->dev, "%s:%02x", acpi_device_bus_id->bus_id, acpi_device_bus_id->instance_no);
462 522
463 if (device->parent) { 523 if (device->parent)
464 list_add_tail(&device->node, &device->parent->children); 524 list_add_tail(&device->node, &device->parent->children);
465 list_add_tail(&device->g_list, &device->parent->g_list); 525
466 } else
467 list_add_tail(&device->g_list, &acpi_device_list);
468 if (device->wakeup.flags.valid) 526 if (device->wakeup.flags.valid)
469 list_add_tail(&device->wakeup_list, &acpi_wakeup_device_list); 527 list_add_tail(&device->wakeup_list, &acpi_wakeup_device_list);
470 spin_unlock(&acpi_device_lock); 528 mutex_unlock(&acpi_device_lock);
471 529
472 if (device->parent) 530 if (device->parent)
473 device->dev.parent = &parent->dev; 531 device->dev.parent = &parent->dev;
@@ -488,28 +546,22 @@ static int acpi_device_register(struct acpi_device *device,
488 device->removal_type = ACPI_BUS_REMOVAL_NORMAL; 546 device->removal_type = ACPI_BUS_REMOVAL_NORMAL;
489 return 0; 547 return 0;
490 end: 548 end:
491 spin_lock(&acpi_device_lock); 549 mutex_lock(&acpi_device_lock);
492 if (device->parent) { 550 if (device->parent)
493 list_del(&device->node); 551 list_del(&device->node);
494 list_del(&device->g_list);
495 } else
496 list_del(&device->g_list);
497 list_del(&device->wakeup_list); 552 list_del(&device->wakeup_list);
498 spin_unlock(&acpi_device_lock); 553 mutex_unlock(&acpi_device_lock);
499 return result; 554 return result;
500} 555}
501 556
502static void acpi_device_unregister(struct acpi_device *device, int type) 557static void acpi_device_unregister(struct acpi_device *device, int type)
503{ 558{
504 spin_lock(&acpi_device_lock); 559 mutex_lock(&acpi_device_lock);
505 if (device->parent) { 560 if (device->parent)
506 list_del(&device->node); 561 list_del(&device->node);
507 list_del(&device->g_list);
508 } else
509 list_del(&device->g_list);
510 562
511 list_del(&device->wakeup_list); 563 list_del(&device->wakeup_list);
512 spin_unlock(&acpi_device_lock); 564 mutex_unlock(&acpi_device_lock);
513 565
514 acpi_detach_data(device->handle, acpi_bus_data_handler); 566 acpi_detach_data(device->handle, acpi_bus_data_handler);
515 567
@@ -1524,16 +1576,11 @@ static int acpi_bus_scan_fixed(struct acpi_device *root)
1524 return result; 1576 return result;
1525} 1577}
1526 1578
1527 1579int __init acpi_scan_init(void)
1528static int __init acpi_scan_init(void)
1529{ 1580{
1530 int result; 1581 int result;
1531 struct acpi_bus_ops ops; 1582 struct acpi_bus_ops ops;
1532 1583
1533
1534 if (acpi_disabled)
1535 return 0;
1536
1537 memset(&ops, 0, sizeof(ops)); 1584 memset(&ops, 0, sizeof(ops));
1538 ops.acpi_op_add = 1; 1585 ops.acpi_op_add = 1;
1539 ops.acpi_op_start = 1; 1586 ops.acpi_op_start = 1;
@@ -1566,5 +1613,3 @@ static int __init acpi_scan_init(void)
1566 Done: 1613 Done:
1567 return result; 1614 return result;
1568} 1615}
1569
1570subsys_initcall(acpi_scan_init);
diff --git a/drivers/acpi/main.c b/drivers/acpi/sleep.c
index 7e3c609cbef2..01574a066534 100644
--- a/drivers/acpi/main.c
+++ b/drivers/acpi/sleep.c
@@ -21,6 +21,8 @@
21 21
22#include <acpi/acpi_bus.h> 22#include <acpi/acpi_bus.h>
23#include <acpi/acpi_drivers.h> 23#include <acpi/acpi_drivers.h>
24
25#include "internal.h"
24#include "sleep.h" 26#include "sleep.h"
25 27
26u8 sleep_states[ACPI_S_STATE_COUNT]; 28u8 sleep_states[ACPI_S_STATE_COUNT];
@@ -90,31 +92,6 @@ void __init acpi_old_suspend_ordering(void)
90 old_suspend_ordering = true; 92 old_suspend_ordering = true;
91} 93}
92 94
93/*
94 * According to the ACPI specification the BIOS should make sure that ACPI is
95 * enabled and SCI_EN bit is set on wake-up from S1 - S3 sleep states. Still,
96 * some BIOSes don't do that and therefore we use acpi_enable() to enable ACPI
97 * on such systems during resume. Unfortunately that doesn't help in
98 * particularly pathological cases in which SCI_EN has to be set directly on
99 * resume, although the specification states very clearly that this flag is
100 * owned by the hardware. The set_sci_en_on_resume variable will be set in such
101 * cases.
102 */
103static bool set_sci_en_on_resume;
104/*
105 * The ACPI specification wants us to save NVS memory regions during hibernation
106 * and to restore them during the subsequent resume. However, it is not certain
107 * if this mechanism is going to work on all machines, so we allow the user to
108 * disable this mechanism using the 'acpi_sleep=s4_nonvs' kernel command line
109 * option.
110 */
111static bool s4_no_nvs;
112
113void __init acpi_s4_no_nvs(void)
114{
115 s4_no_nvs = true;
116}
117
118/** 95/**
119 * acpi_pm_disable_gpes - Disable the GPEs. 96 * acpi_pm_disable_gpes - Disable the GPEs.
120 */ 97 */
@@ -193,6 +170,18 @@ static void acpi_pm_end(void)
193#endif /* CONFIG_ACPI_SLEEP */ 170#endif /* CONFIG_ACPI_SLEEP */
194 171
195#ifdef CONFIG_SUSPEND 172#ifdef CONFIG_SUSPEND
173/*
174 * According to the ACPI specification the BIOS should make sure that ACPI is
175 * enabled and SCI_EN bit is set on wake-up from S1 - S3 sleep states. Still,
176 * some BIOSes don't do that and therefore we use acpi_enable() to enable ACPI
177 * on such systems during resume. Unfortunately that doesn't help in
178 * particularly pathological cases in which SCI_EN has to be set directly on
179 * resume, although the specification states very clearly that this flag is
180 * owned by the hardware. The set_sci_en_on_resume variable will be set in such
181 * cases.
182 */
183static bool set_sci_en_on_resume;
184
196extern void do_suspend_lowlevel(void); 185extern void do_suspend_lowlevel(void);
197 186
198static u32 acpi_suspend_states[] = { 187static u32 acpi_suspend_states[] = {
@@ -261,7 +250,7 @@ static int acpi_suspend_enter(suspend_state_t pm_state)
261 250
262 /* If ACPI is not enabled by the BIOS, we need to enable it here. */ 251 /* If ACPI is not enabled by the BIOS, we need to enable it here. */
263 if (set_sci_en_on_resume) 252 if (set_sci_en_on_resume)
264 acpi_set_register(ACPI_BITREG_SCI_ENABLE, 1); 253 acpi_write_bit_register(ACPI_BITREG_SCI_ENABLE, 1);
265 else 254 else
266 acpi_enable(); 255 acpi_enable();
267 256
@@ -311,9 +300,9 @@ static int acpi_suspend_state_valid(suspend_state_t pm_state)
311static struct platform_suspend_ops acpi_suspend_ops = { 300static struct platform_suspend_ops acpi_suspend_ops = {
312 .valid = acpi_suspend_state_valid, 301 .valid = acpi_suspend_state_valid,
313 .begin = acpi_suspend_begin, 302 .begin = acpi_suspend_begin,
314 .prepare = acpi_pm_prepare, 303 .prepare_late = acpi_pm_prepare,
315 .enter = acpi_suspend_enter, 304 .enter = acpi_suspend_enter,
316 .finish = acpi_pm_finish, 305 .wake = acpi_pm_finish,
317 .end = acpi_pm_end, 306 .end = acpi_pm_end,
318}; 307};
319 308
@@ -339,9 +328,9 @@ static int acpi_suspend_begin_old(suspend_state_t pm_state)
339static struct platform_suspend_ops acpi_suspend_ops_old = { 328static struct platform_suspend_ops acpi_suspend_ops_old = {
340 .valid = acpi_suspend_state_valid, 329 .valid = acpi_suspend_state_valid,
341 .begin = acpi_suspend_begin_old, 330 .begin = acpi_suspend_begin_old,
342 .prepare = acpi_pm_disable_gpes, 331 .prepare_late = acpi_pm_disable_gpes,
343 .enter = acpi_suspend_enter, 332 .enter = acpi_suspend_enter,
344 .finish = acpi_pm_finish, 333 .wake = acpi_pm_finish,
345 .end = acpi_pm_end, 334 .end = acpi_pm_end,
346 .recover = acpi_pm_finish, 335 .recover = acpi_pm_finish,
347}; 336};
@@ -391,11 +380,50 @@ static struct dmi_system_id __initdata acpisleep_dmi_table[] = {
391 DMI_MATCH(DMI_PRODUCT_NAME, "Macmini1,1"), 380 DMI_MATCH(DMI_PRODUCT_NAME, "Macmini1,1"),
392 }, 381 },
393 }, 382 },
383 {
384 .callback = init_old_suspend_ordering,
385 .ident = "Asus Pundit P1-AH2 (M2N8L motherboard)",
386 .matches = {
387 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTek Computer INC."),
388 DMI_MATCH(DMI_BOARD_NAME, "M2N8L"),
389 },
390 },
391 {
392 .callback = init_set_sci_en_on_resume,
393 .ident = "Toshiba Satellite L300",
394 .matches = {
395 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
396 DMI_MATCH(DMI_PRODUCT_NAME, "Satellite L300"),
397 },
398 },
399 {
400 .callback = init_old_suspend_ordering,
401 .ident = "Panasonic CF51-2L",
402 .matches = {
403 DMI_MATCH(DMI_BOARD_VENDOR,
404 "Matsushita Electric Industrial Co.,Ltd."),
405 DMI_MATCH(DMI_BOARD_NAME, "CF51-2L"),
406 },
407 },
394 {}, 408 {},
395}; 409};
396#endif /* CONFIG_SUSPEND */ 410#endif /* CONFIG_SUSPEND */
397 411
398#ifdef CONFIG_HIBERNATION 412#ifdef CONFIG_HIBERNATION
413/*
414 * The ACPI specification wants us to save NVS memory regions during hibernation
415 * and to restore them during the subsequent resume. However, it is not certain
416 * if this mechanism is going to work on all machines, so we allow the user to
417 * disable this mechanism using the 'acpi_sleep=s4_nonvs' kernel command line
418 * option.
419 */
420static bool s4_no_nvs;
421
422void __init acpi_s4_no_nvs(void)
423{
424 s4_no_nvs = true;
425}
426
399static unsigned long s4_hardware_signature; 427static unsigned long s4_hardware_signature;
400static struct acpi_table_facs *facs; 428static struct acpi_table_facs *facs;
401static bool nosigcheck; 429static bool nosigcheck;
@@ -679,12 +707,38 @@ static void acpi_power_off_prepare(void)
679static void acpi_power_off(void) 707static void acpi_power_off(void)
680{ 708{
681 /* acpi_sleep_prepare(ACPI_STATE_S5) should have already been called */ 709 /* acpi_sleep_prepare(ACPI_STATE_S5) should have already been called */
682 printk("%s called\n", __func__); 710 printk(KERN_DEBUG "%s called\n", __func__);
683 local_irq_disable(); 711 local_irq_disable();
684 acpi_enable_wakeup_device(ACPI_STATE_S5); 712 acpi_enable_wakeup_device(ACPI_STATE_S5);
685 acpi_enter_sleep_state(ACPI_STATE_S5); 713 acpi_enter_sleep_state(ACPI_STATE_S5);
686} 714}
687 715
716/*
717 * ACPI 2.0 created the optional _GTS and _BFS,
718 * but industry adoption has been neither rapid nor broad.
719 *
720 * Linux gets into trouble when it executes poorly validated
721 * paths through the BIOS, so disable _GTS and _BFS by default,
722 * but do speak up and offer the option to enable them.
723 */
724void __init acpi_gts_bfs_check(void)
725{
726 acpi_handle dummy;
727
728 if (ACPI_SUCCESS(acpi_get_handle(ACPI_ROOT_OBJECT, METHOD_NAME__GTS, &dummy)))
729 {
730 printk(KERN_NOTICE PREFIX "BIOS offers _GTS\n");
731 printk(KERN_NOTICE PREFIX "If \"acpi.gts=1\" improves suspend, "
732 "please notify linux-acpi@vger.kernel.org\n");
733 }
734 if (ACPI_SUCCESS(acpi_get_handle(ACPI_ROOT_OBJECT, METHOD_NAME__BFS, &dummy)))
735 {
736 printk(KERN_NOTICE PREFIX "BIOS offers _BFS\n");
737 printk(KERN_NOTICE PREFIX "If \"acpi.bfs=1\" improves resume, "
738 "please notify linux-acpi@vger.kernel.org\n");
739 }
740}
741
688int __init acpi_sleep_init(void) 742int __init acpi_sleep_init(void)
689{ 743{
690 acpi_status status; 744 acpi_status status;
@@ -743,5 +797,6 @@ int __init acpi_sleep_init(void)
743 * object can also be evaluated when the system enters S5. 797 * object can also be evaluated when the system enters S5.
744 */ 798 */
745 register_reboot_notifier(&tts_notifier); 799 register_reboot_notifier(&tts_notifier);
800 acpi_gts_bfs_check();
746 return 0; 801 return 0;
747} 802}
diff --git a/drivers/acpi/sleep.h b/drivers/acpi/sleep.h
index cfaf8f5b0a14..8a8f3b3382a6 100644
--- a/drivers/acpi/sleep.h
+++ b/drivers/acpi/sleep.h
@@ -5,3 +5,6 @@ extern int acpi_suspend (u32 state);
5extern void acpi_enable_wakeup_device_prep(u8 sleep_state); 5extern void acpi_enable_wakeup_device_prep(u8 sleep_state);
6extern void acpi_enable_wakeup_device(u8 sleep_state); 6extern void acpi_enable_wakeup_device(u8 sleep_state);
7extern void acpi_disable_wakeup_device(u8 sleep_state); 7extern void acpi_disable_wakeup_device(u8 sleep_state);
8
9extern struct list_head acpi_wakeup_device_list;
10extern struct mutex acpi_device_lock;
diff --git a/drivers/acpi/system.c b/drivers/acpi/system.c
index 391d0358a592..0944daec064f 100644
--- a/drivers/acpi/system.c
+++ b/drivers/acpi/system.c
@@ -33,15 +33,12 @@
33 33
34#define _COMPONENT ACPI_SYSTEM_COMPONENT 34#define _COMPONENT ACPI_SYSTEM_COMPONENT
35ACPI_MODULE_NAME("system"); 35ACPI_MODULE_NAME("system");
36#ifdef MODULE_PARAM_PREFIX
37#undef MODULE_PARAM_PREFIX
38#endif
39#define MODULE_PARAM_PREFIX "acpi."
40 36
41#define ACPI_SYSTEM_CLASS "system" 37#define ACPI_SYSTEM_CLASS "system"
42#define ACPI_SYSTEM_DEVICE_NAME "System" 38#define ACPI_SYSTEM_DEVICE_NAME "System"
43 39
44u32 acpi_irq_handled; 40u32 acpi_irq_handled;
41u32 acpi_irq_not_handled;
45 42
46/* 43/*
47 * Make ACPICA version work as module param 44 * Make ACPICA version work as module param
@@ -62,6 +59,7 @@ module_param_call(acpica_version, NULL, param_get_acpica_version, NULL, 0444);
62 -------------------------------------------------------------------------- */ 59 -------------------------------------------------------------------------- */
63static LIST_HEAD(acpi_table_attr_list); 60static LIST_HEAD(acpi_table_attr_list);
64static struct kobject *tables_kobj; 61static struct kobject *tables_kobj;
62static struct kobject *dynamic_tables_kobj;
65 63
66struct acpi_table_attr { 64struct acpi_table_attr {
67 struct bin_attribute attr; 65 struct bin_attribute attr;
@@ -128,6 +126,40 @@ static void acpi_table_attr_init(struct acpi_table_attr *table_attr,
128 return; 126 return;
129} 127}
130 128
129static acpi_status
130acpi_sysfs_table_handler(u32 event, void *table, void *context)
131{
132 struct acpi_table_attr *table_attr;
133
134 switch (event) {
135 case ACPI_TABLE_EVENT_LOAD:
136 table_attr =
137 kzalloc(sizeof(struct acpi_table_attr), GFP_KERNEL);
138 if (!table_attr)
139 return AE_NO_MEMORY;
140
141 acpi_table_attr_init(table_attr, table);
142 if (sysfs_create_bin_file(dynamic_tables_kobj,
143 &table_attr->attr)) {
144 kfree(table_attr);
145 return AE_ERROR;
146 } else
147 list_add_tail(&table_attr->node,
148 &acpi_table_attr_list);
149 break;
150 case ACPI_TABLE_EVENT_UNLOAD:
151 /*
152 * we do not need to do anything right now
153 * because the table is not deleted from the
154 * global table list when unloading it.
155 */
156 break;
157 default:
158 return AE_BAD_PARAMETER;
159 }
160 return AE_OK;
161}
162
131static int acpi_system_sysfs_init(void) 163static int acpi_system_sysfs_init(void)
132{ 164{
133 struct acpi_table_attr *table_attr; 165 struct acpi_table_attr *table_attr;
@@ -137,7 +169,11 @@ static int acpi_system_sysfs_init(void)
137 169
138 tables_kobj = kobject_create_and_add("tables", acpi_kobj); 170 tables_kobj = kobject_create_and_add("tables", acpi_kobj);
139 if (!tables_kobj) 171 if (!tables_kobj)
140 return -ENOMEM; 172 goto err;
173
174 dynamic_tables_kobj = kobject_create_and_add("dynamic", tables_kobj);
175 if (!dynamic_tables_kobj)
176 goto err_dynamic_tables;
141 177
142 do { 178 do {
143 result = acpi_get_table_by_index(table_index, &table_header); 179 result = acpi_get_table_by_index(table_index, &table_header);
@@ -162,8 +198,14 @@ static int acpi_system_sysfs_init(void)
162 } 198 }
163 } while (!result); 199 } while (!result);
164 kobject_uevent(tables_kobj, KOBJ_ADD); 200 kobject_uevent(tables_kobj, KOBJ_ADD);
165 201 kobject_uevent(dynamic_tables_kobj, KOBJ_ADD);
166 return 0; 202 result = acpi_install_table_handler(acpi_sysfs_table_handler, NULL);
203
204 return result == AE_OK ? 0 : -EINVAL;
205err_dynamic_tables:
206 kobject_put(tables_kobj);
207err:
208 return -ENOMEM;
167} 209}
168 210
169/* 211/*
@@ -173,8 +215,9 @@ static int acpi_system_sysfs_init(void)
173 215
174#define COUNT_GPE 0 216#define COUNT_GPE 0
175#define COUNT_SCI 1 /* acpi_irq_handled */ 217#define COUNT_SCI 1 /* acpi_irq_handled */
176#define COUNT_ERROR 2 /* other */ 218#define COUNT_SCI_NOT 2 /* acpi_irq_not_handled */
177#define NUM_COUNTERS_EXTRA 3 219#define COUNT_ERROR 3 /* other */
220#define NUM_COUNTERS_EXTRA 4
178 221
179struct event_counter { 222struct event_counter {
180 u32 count; 223 u32 count;
@@ -276,6 +319,8 @@ static ssize_t counter_show(struct kobject *kobj,
276 319
277 all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI].count = 320 all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI].count =
278 acpi_irq_handled; 321 acpi_irq_handled;
322 all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI_NOT].count =
323 acpi_irq_not_handled;
279 all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_GPE].count = 324 all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_GPE].count =
280 acpi_gpe_count; 325 acpi_gpe_count;
281 326
@@ -322,6 +367,7 @@ static ssize_t counter_set(struct kobject *kobj,
322 all_counters[i].count = 0; 367 all_counters[i].count = 0;
323 acpi_gpe_count = 0; 368 acpi_gpe_count = 0;
324 acpi_irq_handled = 0; 369 acpi_irq_handled = 0;
370 acpi_irq_not_handled = 0;
325 goto end; 371 goto end;
326 } 372 }
327 373
@@ -415,6 +461,8 @@ void acpi_irq_stats_init(void)
415 sprintf(buffer, "gpe_all"); 461 sprintf(buffer, "gpe_all");
416 else if (i == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI) 462 else if (i == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI)
417 sprintf(buffer, "sci"); 463 sprintf(buffer, "sci");
464 else if (i == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI_NOT)
465 sprintf(buffer, "sci_not");
418 else if (i == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_ERROR) 466 else if (i == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_ERROR)
419 sprintf(buffer, "error"); 467 sprintf(buffer, "error");
420 else 468 else
@@ -571,12 +619,9 @@ static int acpi_system_procfs_init(void)
571} 619}
572#endif 620#endif
573 621
574static int __init acpi_system_init(void) 622int __init acpi_system_init(void)
575{ 623{
576 int result = 0; 624 int result;
577
578 if (acpi_disabled)
579 return 0;
580 625
581 result = acpi_system_procfs_init(); 626 result = acpi_system_procfs_init();
582 if (result) 627 if (result)
@@ -586,5 +631,3 @@ static int __init acpi_system_init(void)
586 631
587 return result; 632 return result;
588} 633}
589
590subsys_initcall(acpi_system_init);
diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c
index 775c97a282bd..646d39c031ca 100644
--- a/drivers/acpi/tables.c
+++ b/drivers/acpi/tables.c
@@ -62,6 +62,18 @@ void acpi_table_print_madt_entry(struct acpi_subtable_header *header)
62 } 62 }
63 break; 63 break;
64 64
65 case ACPI_MADT_TYPE_LOCAL_X2APIC:
66 {
67 struct acpi_madt_local_x2apic *p =
68 (struct acpi_madt_local_x2apic *)header;
69 printk(KERN_INFO PREFIX
70 "X2APIC (apic_id[0x%02x] uid[0x%02x] %s)\n",
71 p->local_apic_id, p->uid,
72 (p->lapic_flags & ACPI_MADT_ENABLED) ?
73 "enabled" : "disabled");
74 }
75 break;
76
65 case ACPI_MADT_TYPE_IO_APIC: 77 case ACPI_MADT_TYPE_IO_APIC:
66 { 78 {
67 struct acpi_madt_io_apic *p = 79 struct acpi_madt_io_apic *p =
@@ -116,6 +128,24 @@ void acpi_table_print_madt_entry(struct acpi_subtable_header *header)
116 } 128 }
117 break; 129 break;
118 130
131 case ACPI_MADT_TYPE_LOCAL_X2APIC_NMI:
132 {
133 u16 polarity, trigger;
134 struct acpi_madt_local_x2apic_nmi *p =
135 (struct acpi_madt_local_x2apic_nmi *)header;
136
137 polarity = p->inti_flags & ACPI_MADT_POLARITY_MASK;
138 trigger = (p->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2;
139
140 printk(KERN_INFO PREFIX
141 "X2APIC_NMI (uid[0x%02x] %s %s lint[0x%x])\n",
142 p->uid,
143 mps_inti_flags_polarity[polarity],
144 mps_inti_flags_trigger[trigger],
145 p->lint);
146 }
147 break;
148
119 case ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE: 149 case ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE:
120 { 150 {
121 struct acpi_madt_local_apic_override *p = 151 struct acpi_madt_local_apic_override *p =
@@ -181,14 +211,15 @@ acpi_table_parse_entries(char *id,
181 struct acpi_subtable_header *entry; 211 struct acpi_subtable_header *entry;
182 unsigned int count = 0; 212 unsigned int count = 0;
183 unsigned long table_end; 213 unsigned long table_end;
214 acpi_size tbl_size;
184 215
185 if (!handler) 216 if (!handler)
186 return -EINVAL; 217 return -EINVAL;
187 218
188 if (strncmp(id, ACPI_SIG_MADT, 4) == 0) 219 if (strncmp(id, ACPI_SIG_MADT, 4) == 0)
189 acpi_get_table(id, acpi_apic_instance, &table_header); 220 acpi_get_table_with_size(id, acpi_apic_instance, &table_header, &tbl_size);
190 else 221 else
191 acpi_get_table(id, 0, &table_header); 222 acpi_get_table_with_size(id, 0, &table_header, &tbl_size);
192 223
193 if (!table_header) { 224 if (!table_header) {
194 printk(KERN_WARNING PREFIX "%4.4s not present\n", id); 225 printk(KERN_WARNING PREFIX "%4.4s not present\n", id);
@@ -206,8 +237,10 @@ acpi_table_parse_entries(char *id,
206 table_end) { 237 table_end) {
207 if (entry->type == entry_id 238 if (entry->type == entry_id
208 && (!max_entries || count++ < max_entries)) 239 && (!max_entries || count++ < max_entries))
209 if (handler(entry, table_end)) 240 if (handler(entry, table_end)) {
241 early_acpi_os_unmap_memory((char *)table_header, tbl_size);
210 return -EINVAL; 242 return -EINVAL;
243 }
211 244
212 entry = (struct acpi_subtable_header *) 245 entry = (struct acpi_subtable_header *)
213 ((unsigned long)entry + entry->length); 246 ((unsigned long)entry + entry->length);
@@ -217,6 +250,7 @@ acpi_table_parse_entries(char *id,
217 "%i found\n", id, entry_id, count - max_entries, count); 250 "%i found\n", id, entry_id, count - max_entries, count);
218 } 251 }
219 252
253 early_acpi_os_unmap_memory((char *)table_header, tbl_size);
220 return count; 254 return count;
221} 255}
222 256
@@ -241,17 +275,19 @@ acpi_table_parse_madt(enum acpi_madt_type id,
241int __init acpi_table_parse(char *id, acpi_table_handler handler) 275int __init acpi_table_parse(char *id, acpi_table_handler handler)
242{ 276{
243 struct acpi_table_header *table = NULL; 277 struct acpi_table_header *table = NULL;
278 acpi_size tbl_size;
244 279
245 if (!handler) 280 if (!handler)
246 return -EINVAL; 281 return -EINVAL;
247 282
248 if (strncmp(id, ACPI_SIG_MADT, 4) == 0) 283 if (strncmp(id, ACPI_SIG_MADT, 4) == 0)
249 acpi_get_table(id, acpi_apic_instance, &table); 284 acpi_get_table_with_size(id, acpi_apic_instance, &table, &tbl_size);
250 else 285 else
251 acpi_get_table(id, 0, &table); 286 acpi_get_table_with_size(id, 0, &table, &tbl_size);
252 287
253 if (table) { 288 if (table) {
254 handler(table); 289 handler(table);
290 early_acpi_os_unmap_memory(table, tbl_size);
255 return 0; 291 return 0;
256 } else 292 } else
257 return 1; 293 return 1;
@@ -265,8 +301,9 @@ int __init acpi_table_parse(char *id, acpi_table_handler handler)
265static void __init check_multiple_madt(void) 301static void __init check_multiple_madt(void)
266{ 302{
267 struct acpi_table_header *table = NULL; 303 struct acpi_table_header *table = NULL;
304 acpi_size tbl_size;
268 305
269 acpi_get_table(ACPI_SIG_MADT, 2, &table); 306 acpi_get_table_with_size(ACPI_SIG_MADT, 2, &table, &tbl_size);
270 if (table) { 307 if (table) {
271 printk(KERN_WARNING PREFIX 308 printk(KERN_WARNING PREFIX
272 "BIOS bug: multiple APIC/MADT found," 309 "BIOS bug: multiple APIC/MADT found,"
@@ -275,6 +312,7 @@ static void __init check_multiple_madt(void)
275 "If \"acpi_apic_instance=%d\" works better, " 312 "If \"acpi_apic_instance=%d\" works better, "
276 "notify linux-acpi@vger.kernel.org\n", 313 "notify linux-acpi@vger.kernel.org\n",
277 acpi_apic_instance ? 0 : 2); 314 acpi_apic_instance ? 0 : 2);
315 early_acpi_os_unmap_memory(table, tbl_size);
278 316
279 } else 317 } else
280 acpi_apic_instance = 0; 318 acpi_apic_instance = 0;
@@ -293,7 +331,12 @@ static void __init check_multiple_madt(void)
293 331
294int __init acpi_table_init(void) 332int __init acpi_table_init(void)
295{ 333{
296 acpi_initialize_tables(initial_tables, ACPI_MAX_TABLES, 0); 334 acpi_status status;
335
336 status = acpi_initialize_tables(initial_tables, ACPI_MAX_TABLES, 0);
337 if (ACPI_FAILURE(status))
338 return 1;
339
297 check_multiple_madt(); 340 check_multiple_madt();
298 return 0; 341 return 0;
299} 342}
diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c
index 073ff09218a9..564ea1424288 100644
--- a/drivers/acpi/thermal.c
+++ b/drivers/acpi/thermal.c
@@ -37,11 +37,11 @@
37#include <linux/init.h> 37#include <linux/init.h>
38#include <linux/types.h> 38#include <linux/types.h>
39#include <linux/proc_fs.h> 39#include <linux/proc_fs.h>
40#include <linux/timer.h>
41#include <linux/jiffies.h> 40#include <linux/jiffies.h>
42#include <linux/kmod.h> 41#include <linux/kmod.h>
43#include <linux/seq_file.h> 42#include <linux/seq_file.h>
44#include <linux/reboot.h> 43#include <linux/reboot.h>
44#include <linux/device.h>
45#include <asm/uaccess.h> 45#include <asm/uaccess.h>
46#include <linux/thermal.h> 46#include <linux/thermal.h>
47#include <acpi/acpi_bus.h> 47#include <acpi/acpi_bus.h>
@@ -98,6 +98,7 @@ MODULE_PARM_DESC(psv, "Disable or override all passive trip points.");
98static int acpi_thermal_add(struct acpi_device *device); 98static int acpi_thermal_add(struct acpi_device *device);
99static int acpi_thermal_remove(struct acpi_device *device, int type); 99static int acpi_thermal_remove(struct acpi_device *device, int type);
100static int acpi_thermal_resume(struct acpi_device *device); 100static int acpi_thermal_resume(struct acpi_device *device);
101static void acpi_thermal_notify(struct acpi_device *device, u32 event);
101static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file); 102static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file);
102static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file); 103static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file);
103static int acpi_thermal_trip_open_fs(struct inode *inode, struct file *file); 104static int acpi_thermal_trip_open_fs(struct inode *inode, struct file *file);
@@ -123,6 +124,7 @@ static struct acpi_driver acpi_thermal_driver = {
123 .add = acpi_thermal_add, 124 .add = acpi_thermal_add,
124 .remove = acpi_thermal_remove, 125 .remove = acpi_thermal_remove,
125 .resume = acpi_thermal_resume, 126 .resume = acpi_thermal_resume,
127 .notify = acpi_thermal_notify,
126 }, 128 },
127}; 129};
128 130
@@ -190,9 +192,9 @@ struct acpi_thermal {
190 struct acpi_thermal_state state; 192 struct acpi_thermal_state state;
191 struct acpi_thermal_trips trips; 193 struct acpi_thermal_trips trips;
192 struct acpi_handle_list devices; 194 struct acpi_handle_list devices;
193 struct timer_list timer;
194 struct thermal_zone_device *thermal_zone; 195 struct thermal_zone_device *thermal_zone;
195 int tz_enabled; 196 int tz_enabled;
197 int kelvin_offset;
196 struct mutex lock; 198 struct mutex lock;
197}; 199};
198 200
@@ -290,6 +292,11 @@ static int acpi_thermal_set_polling(struct acpi_thermal *tz, int seconds)
290 292
291 tz->polling_frequency = seconds * 10; /* Convert value to deci-seconds */ 293 tz->polling_frequency = seconds * 10; /* Convert value to deci-seconds */
292 294
295 tz->thermal_zone->polling_delay = seconds * 1000;
296
297 if (tz->tz_enabled)
298 thermal_zone_device_update(tz->thermal_zone);
299
293 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 300 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
294 "Polling frequency set to %lu seconds\n", 301 "Polling frequency set to %lu seconds\n",
295 tz->polling_frequency/10)); 302 tz->polling_frequency/10));
@@ -367,7 +374,7 @@ static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag)
367 /* 374 /*
368 * Treat freezing temperatures as invalid as well; some 375 * Treat freezing temperatures as invalid as well; some
369 * BIOSes return really low values and cause reboots at startup. 376 * BIOSes return really low values and cause reboots at startup.
370 * Below zero (Celcius) values clearly aren't right for sure.. 377 * Below zero (Celsius) values clearly aren't right for sure..
371 * ... so lets discard those as invalid. 378 * ... so lets discard those as invalid.
372 */ 379 */
373 if (ACPI_FAILURE(status) || 380 if (ACPI_FAILURE(status) ||
@@ -416,7 +423,8 @@ static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag)
416 } 423 }
417 424
418 /* Passive (optional) */ 425 /* Passive (optional) */
419 if (flag & ACPI_TRIPS_PASSIVE) { 426 if (((flag & ACPI_TRIPS_PASSIVE) && tz->trips.passive.flags.valid) ||
427 (flag == ACPI_TRIPS_INIT)) {
420 valid = tz->trips.passive.flags.valid; 428 valid = tz->trips.passive.flags.valid;
421 if (psv == -1) { 429 if (psv == -1) {
422 status = AE_SUPPORT; 430 status = AE_SUPPORT;
@@ -462,8 +470,11 @@ static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag)
462 memset(&devices, 0, sizeof(struct acpi_handle_list)); 470 memset(&devices, 0, sizeof(struct acpi_handle_list));
463 status = acpi_evaluate_reference(tz->device->handle, "_PSL", 471 status = acpi_evaluate_reference(tz->device->handle, "_PSL",
464 NULL, &devices); 472 NULL, &devices);
465 if (ACPI_FAILURE(status)) 473 if (ACPI_FAILURE(status)) {
474 printk(KERN_WARNING PREFIX
475 "Invalid passive threshold\n");
466 tz->trips.passive.flags.valid = 0; 476 tz->trips.passive.flags.valid = 0;
477 }
467 else 478 else
468 tz->trips.passive.flags.valid = 1; 479 tz->trips.passive.flags.valid = 1;
469 480
@@ -487,7 +498,8 @@ static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag)
487 if (act == -1) 498 if (act == -1)
488 break; /* disable all active trip points */ 499 break; /* disable all active trip points */
489 500
490 if (flag & ACPI_TRIPS_ACTIVE) { 501 if ((flag == ACPI_TRIPS_INIT) || ((flag & ACPI_TRIPS_ACTIVE) &&
502 tz->trips.active[i].flags.valid)) {
491 status = acpi_evaluate_integer(tz->device->handle, 503 status = acpi_evaluate_integer(tz->device->handle,
492 name, NULL, &tmp); 504 name, NULL, &tmp);
493 if (ACPI_FAILURE(status)) { 505 if (ACPI_FAILURE(status)) {
@@ -521,8 +533,11 @@ static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag)
521 memset(&devices, 0, sizeof(struct acpi_handle_list)); 533 memset(&devices, 0, sizeof(struct acpi_handle_list));
522 status = acpi_evaluate_reference(tz->device->handle, 534 status = acpi_evaluate_reference(tz->device->handle,
523 name, NULL, &devices); 535 name, NULL, &devices);
524 if (ACPI_FAILURE(status)) 536 if (ACPI_FAILURE(status)) {
537 printk(KERN_WARNING PREFIX
538 "Invalid active%d threshold\n", i);
525 tz->trips.active[i].flags.valid = 0; 539 tz->trips.active[i].flags.valid = 0;
540 }
526 else 541 else
527 tz->trips.active[i].flags.valid = 1; 542 tz->trips.active[i].flags.valid = 1;
528 543
@@ -561,392 +576,18 @@ static int acpi_thermal_get_trip_points(struct acpi_thermal *tz)
561 return acpi_thermal_trips_update(tz, ACPI_TRIPS_INIT); 576 return acpi_thermal_trips_update(tz, ACPI_TRIPS_INIT);
562} 577}
563 578
564static int acpi_thermal_critical(struct acpi_thermal *tz)
565{
566 if (!tz || !tz->trips.critical.flags.valid)
567 return -EINVAL;
568
569 if (tz->temperature >= tz->trips.critical.temperature) {
570 printk(KERN_WARNING PREFIX "Critical trip point\n");
571 tz->trips.critical.flags.enabled = 1;
572 } else if (tz->trips.critical.flags.enabled)
573 tz->trips.critical.flags.enabled = 0;
574
575 acpi_bus_generate_proc_event(tz->device, ACPI_THERMAL_NOTIFY_CRITICAL,
576 tz->trips.critical.flags.enabled);
577 acpi_bus_generate_netlink_event(tz->device->pnp.device_class,
578 dev_name(&tz->device->dev),
579 ACPI_THERMAL_NOTIFY_CRITICAL,
580 tz->trips.critical.flags.enabled);
581
582 /* take no action if nocrt is set */
583 if(!nocrt) {
584 printk(KERN_EMERG
585 "Critical temperature reached (%ld C), shutting down.\n",
586 KELVIN_TO_CELSIUS(tz->temperature));
587 orderly_poweroff(true);
588 }
589
590 return 0;
591}
592
593static int acpi_thermal_hot(struct acpi_thermal *tz)
594{
595 if (!tz || !tz->trips.hot.flags.valid)
596 return -EINVAL;
597
598 if (tz->temperature >= tz->trips.hot.temperature) {
599 printk(KERN_WARNING PREFIX "Hot trip point\n");
600 tz->trips.hot.flags.enabled = 1;
601 } else if (tz->trips.hot.flags.enabled)
602 tz->trips.hot.flags.enabled = 0;
603
604 acpi_bus_generate_proc_event(tz->device, ACPI_THERMAL_NOTIFY_HOT,
605 tz->trips.hot.flags.enabled);
606 acpi_bus_generate_netlink_event(tz->device->pnp.device_class,
607 dev_name(&tz->device->dev),
608 ACPI_THERMAL_NOTIFY_HOT,
609 tz->trips.hot.flags.enabled);
610
611 /* TBD: Call user-mode "sleep(S4)" function if nocrt is cleared */
612
613 return 0;
614}
615
616static void acpi_thermal_passive(struct acpi_thermal *tz)
617{
618 int result = 1;
619 struct acpi_thermal_passive *passive = NULL;
620 int trend = 0;
621 int i = 0;
622
623
624 if (!tz || !tz->trips.passive.flags.valid)
625 return;
626
627 passive = &(tz->trips.passive);
628
629 /*
630 * Above Trip?
631 * -----------
632 * Calculate the thermal trend (using the passive cooling equation)
633 * and modify the performance limit for all passive cooling devices
634 * accordingly. Note that we assume symmetry.
635 */
636 if (tz->temperature >= passive->temperature) {
637 trend =
638 (passive->tc1 * (tz->temperature - tz->last_temperature)) +
639 (passive->tc2 * (tz->temperature - passive->temperature));
640 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
641 "trend[%d]=(tc1[%lu]*(tmp[%lu]-last[%lu]))+(tc2[%lu]*(tmp[%lu]-psv[%lu]))\n",
642 trend, passive->tc1, tz->temperature,
643 tz->last_temperature, passive->tc2,
644 tz->temperature, passive->temperature));
645 passive->flags.enabled = 1;
646 /* Heating up? */
647 if (trend > 0)
648 for (i = 0; i < passive->devices.count; i++)
649 acpi_processor_set_thermal_limit(passive->
650 devices.
651 handles[i],
652 ACPI_PROCESSOR_LIMIT_INCREMENT);
653 /* Cooling off? */
654 else if (trend < 0) {
655 for (i = 0; i < passive->devices.count; i++)
656 /*
657 * assume that we are on highest
658 * freq/lowest thrott and can leave
659 * passive mode, even in error case
660 */
661 if (!acpi_processor_set_thermal_limit
662 (passive->devices.handles[i],
663 ACPI_PROCESSOR_LIMIT_DECREMENT))
664 result = 0;
665 /*
666 * Leave cooling mode, even if the temp might
667 * higher than trip point This is because some
668 * machines might have long thermal polling
669 * frequencies (tsp) defined. We will fall back
670 * into passive mode in next cycle (probably quicker)
671 */
672 if (result) {
673 passive->flags.enabled = 0;
674 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
675 "Disabling passive cooling, still above threshold,"
676 " but we are cooling down\n"));
677 }
678 }
679 return;
680 }
681
682 /*
683 * Below Trip?
684 * -----------
685 * Implement passive cooling hysteresis to slowly increase performance
686 * and avoid thrashing around the passive trip point. Note that we
687 * assume symmetry.
688 */
689 if (!passive->flags.enabled)
690 return;
691 for (i = 0; i < passive->devices.count; i++)
692 if (!acpi_processor_set_thermal_limit
693 (passive->devices.handles[i],
694 ACPI_PROCESSOR_LIMIT_DECREMENT))
695 result = 0;
696 if (result) {
697 passive->flags.enabled = 0;
698 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
699 "Disabling passive cooling (zone is cool)\n"));
700 }
701}
702
703static void acpi_thermal_active(struct acpi_thermal *tz)
704{
705 int result = 0;
706 struct acpi_thermal_active *active = NULL;
707 int i = 0;
708 int j = 0;
709 unsigned long maxtemp = 0;
710
711
712 if (!tz)
713 return;
714
715 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
716 active = &(tz->trips.active[i]);
717 if (!active || !active->flags.valid)
718 break;
719 if (tz->temperature >= active->temperature) {
720 /*
721 * Above Threshold?
722 * ----------------
723 * If not already enabled, turn ON all cooling devices
724 * associated with this active threshold.
725 */
726 if (active->temperature > maxtemp)
727 tz->state.active_index = i;
728 maxtemp = active->temperature;
729 if (active->flags.enabled)
730 continue;
731 for (j = 0; j < active->devices.count; j++) {
732 result =
733 acpi_bus_set_power(active->devices.
734 handles[j],
735 ACPI_STATE_D0);
736 if (result) {
737 printk(KERN_WARNING PREFIX
738 "Unable to turn cooling device [%p] 'on'\n",
739 active->devices.
740 handles[j]);
741 continue;
742 }
743 active->flags.enabled = 1;
744 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
745 "Cooling device [%p] now 'on'\n",
746 active->devices.handles[j]));
747 }
748 continue;
749 }
750 if (!active->flags.enabled)
751 continue;
752 /*
753 * Below Threshold?
754 * ----------------
755 * Turn OFF all cooling devices associated with this
756 * threshold.
757 */
758 for (j = 0; j < active->devices.count; j++) {
759 result = acpi_bus_set_power(active->devices.handles[j],
760 ACPI_STATE_D3);
761 if (result) {
762 printk(KERN_WARNING PREFIX
763 "Unable to turn cooling device [%p] 'off'\n",
764 active->devices.handles[j]);
765 continue;
766 }
767 active->flags.enabled = 0;
768 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
769 "Cooling device [%p] now 'off'\n",
770 active->devices.handles[j]));
771 }
772 }
773}
774
775static void acpi_thermal_check(void *context);
776
777static void acpi_thermal_run(unsigned long data)
778{
779 struct acpi_thermal *tz = (struct acpi_thermal *)data;
780 if (!tz->zombie)
781 acpi_os_execute(OSL_GPE_HANDLER, acpi_thermal_check, (void *)data);
782}
783
784static void acpi_thermal_active_off(void *data)
785{
786 int result = 0;
787 struct acpi_thermal *tz = data;
788 int i = 0;
789 int j = 0;
790 struct acpi_thermal_active *active = NULL;
791
792 if (!tz) {
793 printk(KERN_ERR PREFIX "Invalid (NULL) context\n");
794 return;
795 }
796
797 result = acpi_thermal_get_temperature(tz);
798 if (result)
799 return;
800
801 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
802 active = &(tz->trips.active[i]);
803 if (!active || !active->flags.valid)
804 break;
805 if (tz->temperature >= active->temperature) {
806 /*
807 * If the thermal temperature is greater than the
808 * active threshod, unnecessary to turn off the
809 * the active cooling device.
810 */
811 continue;
812 }
813 /*
814 * Below Threshold?
815 * ----------------
816 * Turn OFF all cooling devices associated with this
817 * threshold.
818 */
819 for (j = 0; j < active->devices.count; j++)
820 result = acpi_bus_set_power(active->devices.handles[j],
821 ACPI_STATE_D3);
822 }
823}
824
825static void acpi_thermal_check(void *data) 579static void acpi_thermal_check(void *data)
826{ 580{
827 int result = 0;
828 struct acpi_thermal *tz = data; 581 struct acpi_thermal *tz = data;
829 unsigned long sleep_time = 0;
830 unsigned long timeout_jiffies = 0;
831 int i = 0;
832 struct acpi_thermal_state state;
833
834
835 if (!tz) {
836 printk(KERN_ERR PREFIX "Invalid (NULL) context\n");
837 return;
838 }
839
840 /* Check if someone else is already running */
841 if (!mutex_trylock(&tz->lock))
842 return;
843
844 state = tz->state;
845
846 result = acpi_thermal_get_temperature(tz);
847 if (result)
848 goto unlock;
849
850 if (!tz->tz_enabled)
851 goto unlock;
852
853 memset(&tz->state, 0, sizeof(tz->state));
854
855 /*
856 * Check Trip Points
857 * -----------------
858 * Compare the current temperature to the trip point values to see
859 * if we've entered one of the thermal policy states. Note that
860 * this function determines when a state is entered, but the
861 * individual policy decides when it is exited (e.g. hysteresis).
862 */
863 if (tz->trips.critical.flags.valid)
864 state.critical |=
865 (tz->temperature >= tz->trips.critical.temperature);
866 if (tz->trips.hot.flags.valid)
867 state.hot |= (tz->temperature >= tz->trips.hot.temperature);
868 if (tz->trips.passive.flags.valid)
869 state.passive |=
870 (tz->temperature >= tz->trips.passive.temperature);
871 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++)
872 if (tz->trips.active[i].flags.valid)
873 state.active |=
874 (tz->temperature >=
875 tz->trips.active[i].temperature);
876
877 /*
878 * Invoke Policy
879 * -------------
880 * Separated from the above check to allow individual policy to
881 * determine when to exit a given state.
882 */
883 if (state.critical)
884 acpi_thermal_critical(tz);
885 if (state.hot)
886 acpi_thermal_hot(tz);
887 if (state.passive)
888 acpi_thermal_passive(tz);
889 if (state.active)
890 acpi_thermal_active(tz);
891
892 /*
893 * Calculate State
894 * ---------------
895 * Again, separated from the above two to allow independent policy
896 * decisions.
897 */
898 tz->state.critical = tz->trips.critical.flags.enabled;
899 tz->state.hot = tz->trips.hot.flags.enabled;
900 tz->state.passive = tz->trips.passive.flags.enabled;
901 tz->state.active = 0;
902 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++)
903 tz->state.active |= tz->trips.active[i].flags.enabled;
904
905 /*
906 * Calculate Sleep Time
907 * --------------------
908 * If we're in the passive state, use _TSP's value. Otherwise
909 * use the default polling frequency (e.g. _TZP). If no polling
910 * frequency is specified then we'll wait forever (at least until
911 * a thermal event occurs). Note that _TSP and _TZD values are
912 * given in 1/10th seconds (we must covert to milliseconds).
913 */
914 if (tz->state.passive) {
915 sleep_time = tz->trips.passive.tsp * 100;
916 timeout_jiffies = jiffies + (HZ * sleep_time) / 1000;
917 } else if (tz->polling_frequency > 0) {
918 sleep_time = tz->polling_frequency * 100;
919 timeout_jiffies = round_jiffies(jiffies + (HZ * sleep_time) / 1000);
920 }
921
922 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s: temperature[%lu] sleep[%lu]\n",
923 tz->name, tz->temperature, sleep_time));
924 582
925 /* 583 thermal_zone_device_update(tz->thermal_zone);
926 * Schedule Next Poll
927 * ------------------
928 */
929 if (!sleep_time) {
930 if (timer_pending(&(tz->timer)))
931 del_timer(&(tz->timer));
932 } else {
933 if (timer_pending(&(tz->timer)))
934 mod_timer(&(tz->timer), timeout_jiffies);
935 else {
936 tz->timer.data = (unsigned long)tz;
937 tz->timer.function = acpi_thermal_run;
938 tz->timer.expires = timeout_jiffies;
939 add_timer(&(tz->timer));
940 }
941 }
942 unlock:
943 mutex_unlock(&tz->lock);
944} 584}
945 585
946/* sys I/F for generic thermal sysfs support */ 586/* sys I/F for generic thermal sysfs support */
947#define KELVIN_TO_MILLICELSIUS(t) (t * 100 - 273200) 587#define KELVIN_TO_MILLICELSIUS(t, off) (((t) - (off)) * 100)
948 588
949static int thermal_get_temp(struct thermal_zone_device *thermal, char *buf) 589static int thermal_get_temp(struct thermal_zone_device *thermal,
590 unsigned long *temp)
950{ 591{
951 struct acpi_thermal *tz = thermal->devdata; 592 struct acpi_thermal *tz = thermal->devdata;
952 int result; 593 int result;
@@ -958,25 +599,28 @@ static int thermal_get_temp(struct thermal_zone_device *thermal, char *buf)
958 if (result) 599 if (result)
959 return result; 600 return result;
960 601
961 return sprintf(buf, "%ld\n", KELVIN_TO_MILLICELSIUS(tz->temperature)); 602 *temp = KELVIN_TO_MILLICELSIUS(tz->temperature, tz->kelvin_offset);
603 return 0;
962} 604}
963 605
964static const char enabled[] = "kernel"; 606static const char enabled[] = "kernel";
965static const char disabled[] = "user"; 607static const char disabled[] = "user";
966static int thermal_get_mode(struct thermal_zone_device *thermal, 608static int thermal_get_mode(struct thermal_zone_device *thermal,
967 char *buf) 609 enum thermal_device_mode *mode)
968{ 610{
969 struct acpi_thermal *tz = thermal->devdata; 611 struct acpi_thermal *tz = thermal->devdata;
970 612
971 if (!tz) 613 if (!tz)
972 return -EINVAL; 614 return -EINVAL;
973 615
974 return sprintf(buf, "%s\n", tz->tz_enabled ? 616 *mode = tz->tz_enabled ? THERMAL_DEVICE_ENABLED :
975 enabled : disabled); 617 THERMAL_DEVICE_DISABLED;
618
619 return 0;
976} 620}
977 621
978static int thermal_set_mode(struct thermal_zone_device *thermal, 622static int thermal_set_mode(struct thermal_zone_device *thermal,
979 const char *buf) 623 enum thermal_device_mode mode)
980{ 624{
981 struct acpi_thermal *tz = thermal->devdata; 625 struct acpi_thermal *tz = thermal->devdata;
982 int enable; 626 int enable;
@@ -987,9 +631,9 @@ static int thermal_set_mode(struct thermal_zone_device *thermal,
987 /* 631 /*
988 * enable/disable thermal management from ACPI thermal driver 632 * enable/disable thermal management from ACPI thermal driver
989 */ 633 */
990 if (!strncmp(buf, enabled, sizeof enabled - 1)) 634 if (mode == THERMAL_DEVICE_ENABLED)
991 enable = 1; 635 enable = 1;
992 else if (!strncmp(buf, disabled, sizeof disabled - 1)) 636 else if (mode == THERMAL_DEVICE_DISABLED)
993 enable = 0; 637 enable = 0;
994 else 638 else
995 return -EINVAL; 639 return -EINVAL;
@@ -1005,7 +649,7 @@ static int thermal_set_mode(struct thermal_zone_device *thermal,
1005} 649}
1006 650
1007static int thermal_get_trip_type(struct thermal_zone_device *thermal, 651static int thermal_get_trip_type(struct thermal_zone_device *thermal,
1008 int trip, char *buf) 652 int trip, enum thermal_trip_type *type)
1009{ 653{
1010 struct acpi_thermal *tz = thermal->devdata; 654 struct acpi_thermal *tz = thermal->devdata;
1011 int i; 655 int i;
@@ -1014,27 +658,35 @@ static int thermal_get_trip_type(struct thermal_zone_device *thermal,
1014 return -EINVAL; 658 return -EINVAL;
1015 659
1016 if (tz->trips.critical.flags.valid) { 660 if (tz->trips.critical.flags.valid) {
1017 if (!trip) 661 if (!trip) {
1018 return sprintf(buf, "critical\n"); 662 *type = THERMAL_TRIP_CRITICAL;
663 return 0;
664 }
1019 trip--; 665 trip--;
1020 } 666 }
1021 667
1022 if (tz->trips.hot.flags.valid) { 668 if (tz->trips.hot.flags.valid) {
1023 if (!trip) 669 if (!trip) {
1024 return sprintf(buf, "hot\n"); 670 *type = THERMAL_TRIP_HOT;
671 return 0;
672 }
1025 trip--; 673 trip--;
1026 } 674 }
1027 675
1028 if (tz->trips.passive.flags.valid) { 676 if (tz->trips.passive.flags.valid) {
1029 if (!trip) 677 if (!trip) {
1030 return sprintf(buf, "passive\n"); 678 *type = THERMAL_TRIP_PASSIVE;
679 return 0;
680 }
1031 trip--; 681 trip--;
1032 } 682 }
1033 683
1034 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && 684 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE &&
1035 tz->trips.active[i].flags.valid; i++) { 685 tz->trips.active[i].flags.valid; i++) {
1036 if (!trip) 686 if (!trip) {
1037 return sprintf(buf, "active%d\n", i); 687 *type = THERMAL_TRIP_ACTIVE;
688 return 0;
689 }
1038 trip--; 690 trip--;
1039 } 691 }
1040 692
@@ -1042,7 +694,7 @@ static int thermal_get_trip_type(struct thermal_zone_device *thermal,
1042} 694}
1043 695
1044static int thermal_get_trip_temp(struct thermal_zone_device *thermal, 696static int thermal_get_trip_temp(struct thermal_zone_device *thermal,
1045 int trip, char *buf) 697 int trip, unsigned long *temp)
1046{ 698{
1047 struct acpi_thermal *tz = thermal->devdata; 699 struct acpi_thermal *tz = thermal->devdata;
1048 int i; 700 int i;
@@ -1051,31 +703,43 @@ static int thermal_get_trip_temp(struct thermal_zone_device *thermal,
1051 return -EINVAL; 703 return -EINVAL;
1052 704
1053 if (tz->trips.critical.flags.valid) { 705 if (tz->trips.critical.flags.valid) {
1054 if (!trip) 706 if (!trip) {
1055 return sprintf(buf, "%ld\n", KELVIN_TO_MILLICELSIUS( 707 *temp = KELVIN_TO_MILLICELSIUS(
1056 tz->trips.critical.temperature)); 708 tz->trips.critical.temperature,
709 tz->kelvin_offset);
710 return 0;
711 }
1057 trip--; 712 trip--;
1058 } 713 }
1059 714
1060 if (tz->trips.hot.flags.valid) { 715 if (tz->trips.hot.flags.valid) {
1061 if (!trip) 716 if (!trip) {
1062 return sprintf(buf, "%ld\n", KELVIN_TO_MILLICELSIUS( 717 *temp = KELVIN_TO_MILLICELSIUS(
1063 tz->trips.hot.temperature)); 718 tz->trips.hot.temperature,
719 tz->kelvin_offset);
720 return 0;
721 }
1064 trip--; 722 trip--;
1065 } 723 }
1066 724
1067 if (tz->trips.passive.flags.valid) { 725 if (tz->trips.passive.flags.valid) {
1068 if (!trip) 726 if (!trip) {
1069 return sprintf(buf, "%ld\n", KELVIN_TO_MILLICELSIUS( 727 *temp = KELVIN_TO_MILLICELSIUS(
1070 tz->trips.passive.temperature)); 728 tz->trips.passive.temperature,
729 tz->kelvin_offset);
730 return 0;
731 }
1071 trip--; 732 trip--;
1072 } 733 }
1073 734
1074 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && 735 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE &&
1075 tz->trips.active[i].flags.valid; i++) { 736 tz->trips.active[i].flags.valid; i++) {
1076 if (!trip) 737 if (!trip) {
1077 return sprintf(buf, "%ld\n", KELVIN_TO_MILLICELSIUS( 738 *temp = KELVIN_TO_MILLICELSIUS(
1078 tz->trips.active[i].temperature)); 739 tz->trips.active[i].temperature,
740 tz->kelvin_offset);
741 return 0;
742 }
1079 trip--; 743 trip--;
1080 } 744 }
1081 745
@@ -1088,12 +752,36 @@ static int thermal_get_crit_temp(struct thermal_zone_device *thermal,
1088 752
1089 if (tz->trips.critical.flags.valid) { 753 if (tz->trips.critical.flags.valid) {
1090 *temperature = KELVIN_TO_MILLICELSIUS( 754 *temperature = KELVIN_TO_MILLICELSIUS(
1091 tz->trips.critical.temperature); 755 tz->trips.critical.temperature,
756 tz->kelvin_offset);
1092 return 0; 757 return 0;
1093 } else 758 } else
1094 return -EINVAL; 759 return -EINVAL;
1095} 760}
1096 761
762static int thermal_notify(struct thermal_zone_device *thermal, int trip,
763 enum thermal_trip_type trip_type)
764{
765 u8 type = 0;
766 struct acpi_thermal *tz = thermal->devdata;
767
768 if (trip_type == THERMAL_TRIP_CRITICAL)
769 type = ACPI_THERMAL_NOTIFY_CRITICAL;
770 else if (trip_type == THERMAL_TRIP_HOT)
771 type = ACPI_THERMAL_NOTIFY_HOT;
772 else
773 return 0;
774
775 acpi_bus_generate_proc_event(tz->device, type, 1);
776 acpi_bus_generate_netlink_event(tz->device->pnp.device_class,
777 dev_name(&tz->device->dev), type, 1);
778
779 if (trip_type == THERMAL_TRIP_CRITICAL && nocrt)
780 return 1;
781
782 return 0;
783}
784
1097typedef int (*cb)(struct thermal_zone_device *, int, 785typedef int (*cb)(struct thermal_zone_device *, int,
1098 struct thermal_cooling_device *); 786 struct thermal_cooling_device *);
1099static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal, 787static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal,
@@ -1186,6 +874,7 @@ static struct thermal_zone_device_ops acpi_thermal_zone_ops = {
1186 .get_trip_type = thermal_get_trip_type, 874 .get_trip_type = thermal_get_trip_type,
1187 .get_trip_temp = thermal_get_trip_temp, 875 .get_trip_temp = thermal_get_trip_temp,
1188 .get_crit_temp = thermal_get_crit_temp, 876 .get_crit_temp = thermal_get_crit_temp,
877 .notify = thermal_notify,
1189}; 878};
1190 879
1191static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) 880static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz)
@@ -1206,8 +895,21 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz)
1206 895
1207 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && 896 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE &&
1208 tz->trips.active[i].flags.valid; i++, trips++); 897 tz->trips.active[i].flags.valid; i++, trips++);
1209 tz->thermal_zone = thermal_zone_device_register("acpitz", 898
1210 trips, tz, &acpi_thermal_zone_ops); 899 if (tz->trips.passive.flags.valid)
900 tz->thermal_zone =
901 thermal_zone_device_register("acpitz", trips, tz,
902 &acpi_thermal_zone_ops,
903 tz->trips.passive.tc1,
904 tz->trips.passive.tc2,
905 tz->trips.passive.tsp*100,
906 tz->polling_frequency*100);
907 else
908 tz->thermal_zone =
909 thermal_zone_device_register("acpitz", trips, tz,
910 &acpi_thermal_zone_ops,
911 0, 0, 0,
912 tz->polling_frequency*100);
1211 if (IS_ERR(tz->thermal_zone)) 913 if (IS_ERR(tz->thermal_zone))
1212 return -ENODEV; 914 return -ENODEV;
1213 915
@@ -1439,13 +1141,13 @@ static int acpi_thermal_polling_seq_show(struct seq_file *seq, void *offset)
1439 if (!tz) 1141 if (!tz)
1440 goto end; 1142 goto end;
1441 1143
1442 if (!tz->polling_frequency) { 1144 if (!tz->thermal_zone->polling_delay) {
1443 seq_puts(seq, "<polling disabled>\n"); 1145 seq_puts(seq, "<polling disabled>\n");
1444 goto end; 1146 goto end;
1445 } 1147 }
1446 1148
1447 seq_printf(seq, "polling frequency: %lu seconds\n", 1149 seq_printf(seq, "polling frequency: %d seconds\n",
1448 (tz->polling_frequency / 10)); 1150 (tz->thermal_zone->polling_delay / 1000));
1449 1151
1450 end: 1152 end:
1451 return 0; 1153 return 0;
@@ -1498,7 +1200,6 @@ static int acpi_thermal_add_fs(struct acpi_device *device)
1498 acpi_thermal_dir); 1200 acpi_thermal_dir);
1499 if (!acpi_device_dir(device)) 1201 if (!acpi_device_dir(device))
1500 return -ENODEV; 1202 return -ENODEV;
1501 acpi_device_dir(device)->owner = THIS_MODULE;
1502 } 1203 }
1503 1204
1504 /* 'state' [R] */ 1205 /* 'state' [R] */
@@ -1571,17 +1272,14 @@ static int acpi_thermal_remove_fs(struct acpi_device *device)
1571 Driver Interface 1272 Driver Interface
1572 -------------------------------------------------------------------------- */ 1273 -------------------------------------------------------------------------- */
1573 1274
1574static void acpi_thermal_notify(acpi_handle handle, u32 event, void *data) 1275static void acpi_thermal_notify(struct acpi_device *device, u32 event)
1575{ 1276{
1576 struct acpi_thermal *tz = data; 1277 struct acpi_thermal *tz = acpi_driver_data(device);
1577 struct acpi_device *device = NULL;
1578 1278
1579 1279
1580 if (!tz) 1280 if (!tz)
1581 return; 1281 return;
1582 1282
1583 device = tz->device;
1584
1585 switch (event) { 1283 switch (event) {
1586 case ACPI_THERMAL_NOTIFY_TEMPERATURE: 1284 case ACPI_THERMAL_NOTIFY_TEMPERATURE:
1587 acpi_thermal_check(tz); 1285 acpi_thermal_check(tz);
@@ -1605,8 +1303,6 @@ static void acpi_thermal_notify(acpi_handle handle, u32 event, void *data)
1605 "Unsupported event [0x%x]\n", event)); 1303 "Unsupported event [0x%x]\n", event));
1606 break; 1304 break;
1607 } 1305 }
1608
1609 return;
1610} 1306}
1611 1307
1612static int acpi_thermal_get_info(struct acpi_thermal *tz) 1308static int acpi_thermal_get_info(struct acpi_thermal *tz)
@@ -1641,10 +1337,28 @@ static int acpi_thermal_get_info(struct acpi_thermal *tz)
1641 return 0; 1337 return 0;
1642} 1338}
1643 1339
1340/*
1341 * The exact offset between Kelvin and degree Celsius is 273.15. However ACPI
1342 * handles temperature values with a single decimal place. As a consequence,
1343 * some implementations use an offset of 273.1 and others use an offset of
1344 * 273.2. Try to find out which one is being used, to present the most
1345 * accurate and visually appealing number.
1346 *
1347 * The heuristic below should work for all ACPI thermal zones which have a
1348 * critical trip point with a value being a multiple of 0.5 degree Celsius.
1349 */
1350static void acpi_thermal_guess_offset(struct acpi_thermal *tz)
1351{
1352 if (tz->trips.critical.flags.valid &&
1353 (tz->trips.critical.temperature % 5) == 1)
1354 tz->kelvin_offset = 2731;
1355 else
1356 tz->kelvin_offset = 2732;
1357}
1358
1644static int acpi_thermal_add(struct acpi_device *device) 1359static int acpi_thermal_add(struct acpi_device *device)
1645{ 1360{
1646 int result = 0; 1361 int result = 0;
1647 acpi_status status = AE_OK;
1648 struct acpi_thermal *tz = NULL; 1362 struct acpi_thermal *tz = NULL;
1649 1363
1650 1364
@@ -1667,6 +1381,8 @@ static int acpi_thermal_add(struct acpi_device *device)
1667 if (result) 1381 if (result)
1668 goto free_memory; 1382 goto free_memory;
1669 1383
1384 acpi_thermal_guess_offset(tz);
1385
1670 result = acpi_thermal_register_thermal_zone(tz); 1386 result = acpi_thermal_register_thermal_zone(tz);
1671 if (result) 1387 if (result)
1672 goto free_memory; 1388 goto free_memory;
@@ -1675,27 +1391,11 @@ static int acpi_thermal_add(struct acpi_device *device)
1675 if (result) 1391 if (result)
1676 goto unregister_thermal_zone; 1392 goto unregister_thermal_zone;
1677 1393
1678 init_timer(&tz->timer);
1679
1680 acpi_thermal_active_off(tz);
1681
1682 acpi_thermal_check(tz);
1683
1684 status = acpi_install_notify_handler(device->handle,
1685 ACPI_DEVICE_NOTIFY,
1686 acpi_thermal_notify, tz);
1687 if (ACPI_FAILURE(status)) {
1688 result = -ENODEV;
1689 goto remove_fs;
1690 }
1691
1692 printk(KERN_INFO PREFIX "%s [%s] (%ld C)\n", 1394 printk(KERN_INFO PREFIX "%s [%s] (%ld C)\n",
1693 acpi_device_name(device), acpi_device_bid(device), 1395 acpi_device_name(device), acpi_device_bid(device),
1694 KELVIN_TO_CELSIUS(tz->temperature)); 1396 KELVIN_TO_CELSIUS(tz->temperature));
1695 goto end; 1397 goto end;
1696 1398
1697remove_fs:
1698 acpi_thermal_remove_fs(device);
1699unregister_thermal_zone: 1399unregister_thermal_zone:
1700 thermal_zone_device_unregister(tz->thermal_zone); 1400 thermal_zone_device_unregister(tz->thermal_zone);
1701free_memory: 1401free_memory:
@@ -1706,39 +1406,13 @@ end:
1706 1406
1707static int acpi_thermal_remove(struct acpi_device *device, int type) 1407static int acpi_thermal_remove(struct acpi_device *device, int type)
1708{ 1408{
1709 acpi_status status = AE_OK;
1710 struct acpi_thermal *tz = NULL; 1409 struct acpi_thermal *tz = NULL;
1711 1410
1712
1713 if (!device || !acpi_driver_data(device)) 1411 if (!device || !acpi_driver_data(device))
1714 return -EINVAL; 1412 return -EINVAL;
1715 1413
1716 tz = acpi_driver_data(device); 1414 tz = acpi_driver_data(device);
1717 1415
1718 /* avoid timer adding new defer task */
1719 tz->zombie = 1;
1720 /* wait for running timer (on other CPUs) finish */
1721 del_timer_sync(&(tz->timer));
1722 /* synchronize deferred task */
1723 acpi_os_wait_events_complete(NULL);
1724 /* deferred task may reinsert timer */
1725 del_timer_sync(&(tz->timer));
1726
1727 status = acpi_remove_notify_handler(device->handle,
1728 ACPI_DEVICE_NOTIFY,
1729 acpi_thermal_notify);
1730
1731 /* Terminate policy */
1732 if (tz->trips.passive.flags.valid && tz->trips.passive.flags.enabled) {
1733 tz->trips.passive.flags.enabled = 0;
1734 acpi_thermal_passive(tz);
1735 }
1736 if (tz->trips.active[0].flags.valid
1737 && tz->trips.active[0].flags.enabled) {
1738 tz->trips.active[0].flags.enabled = 0;
1739 acpi_thermal_active(tz);
1740 }
1741
1742 acpi_thermal_remove_fs(device); 1416 acpi_thermal_remove_fs(device);
1743 acpi_thermal_unregister_thermal_zone(tz); 1417 acpi_thermal_unregister_thermal_zone(tz);
1744 mutex_destroy(&tz->lock); 1418 mutex_destroy(&tz->lock);
@@ -1867,7 +1541,6 @@ static int __init acpi_thermal_init(void)
1867 acpi_thermal_dir = proc_mkdir(ACPI_THERMAL_CLASS, acpi_root_dir); 1541 acpi_thermal_dir = proc_mkdir(ACPI_THERMAL_CLASS, acpi_root_dir);
1868 if (!acpi_thermal_dir) 1542 if (!acpi_thermal_dir)
1869 return -ENODEV; 1543 return -ENODEV;
1870 acpi_thermal_dir->owner = THIS_MODULE;
1871 1544
1872 result = acpi_bus_register_driver(&acpi_thermal_driver); 1545 result = acpi_bus_register_driver(&acpi_thermal_driver);
1873 if (result < 0) { 1546 if (result < 0) {
diff --git a/drivers/acpi/video.c b/drivers/acpi/video.c
index f261737636da..1705d947ea09 100644
--- a/drivers/acpi/video.c
+++ b/drivers/acpi/video.c
@@ -37,6 +37,8 @@
37#include <linux/thermal.h> 37#include <linux/thermal.h>
38#include <linux/video_output.h> 38#include <linux/video_output.h>
39#include <linux/sort.h> 39#include <linux/sort.h>
40#include <linux/pci.h>
41#include <linux/pci_ids.h>
40#include <asm/uaccess.h> 42#include <asm/uaccess.h>
41 43
42#include <acpi/acpi_bus.h> 44#include <acpi/acpi_bus.h>
@@ -77,6 +79,7 @@ module_param(brightness_switch_enabled, bool, 0644);
77static int acpi_video_bus_add(struct acpi_device *device); 79static int acpi_video_bus_add(struct acpi_device *device);
78static int acpi_video_bus_remove(struct acpi_device *device, int type); 80static int acpi_video_bus_remove(struct acpi_device *device, int type);
79static int acpi_video_resume(struct acpi_device *device); 81static int acpi_video_resume(struct acpi_device *device);
82static void acpi_video_bus_notify(struct acpi_device *device, u32 event);
80 83
81static const struct acpi_device_id video_device_ids[] = { 84static const struct acpi_device_id video_device_ids[] = {
82 {ACPI_VIDEO_HID, 0}, 85 {ACPI_VIDEO_HID, 0},
@@ -92,6 +95,7 @@ static struct acpi_driver acpi_video_bus = {
92 .add = acpi_video_bus_add, 95 .add = acpi_video_bus_add,
93 .remove = acpi_video_bus_remove, 96 .remove = acpi_video_bus_remove,
94 .resume = acpi_video_resume, 97 .resume = acpi_video_resume,
98 .notify = acpi_video_bus_notify,
95 }, 99 },
96}; 100};
97 101
@@ -162,16 +166,26 @@ struct acpi_video_device_cap {
162 u8 _BCL:1; /*Query list of brightness control levels supported */ 166 u8 _BCL:1; /*Query list of brightness control levels supported */
163 u8 _BCM:1; /*Set the brightness level */ 167 u8 _BCM:1; /*Set the brightness level */
164 u8 _BQC:1; /* Get current brightness level */ 168 u8 _BQC:1; /* Get current brightness level */
169 u8 _BCQ:1; /* Some buggy BIOS uses _BCQ instead of _BQC */
165 u8 _DDC:1; /*Return the EDID for this device */ 170 u8 _DDC:1; /*Return the EDID for this device */
166 u8 _DCS:1; /*Return status of output device */ 171 u8 _DCS:1; /*Return status of output device */
167 u8 _DGS:1; /*Query graphics state */ 172 u8 _DGS:1; /*Query graphics state */
168 u8 _DSS:1; /*Device state set */ 173 u8 _DSS:1; /*Device state set */
169}; 174};
170 175
176struct acpi_video_brightness_flags {
177 u8 _BCL_no_ac_battery_levels:1; /* no AC/Battery levels in _BCL */
178 u8 _BCL_reversed:1; /* _BCL package is in a reversed order*/
179 u8 _BCL_use_index:1; /* levels in _BCL are index values */
180 u8 _BCM_use_index:1; /* input of _BCM is an index value */
181 u8 _BQC_use_index:1; /* _BQC returns an index value */
182};
183
171struct acpi_video_device_brightness { 184struct acpi_video_device_brightness {
172 int curr; 185 int curr;
173 int count; 186 int count;
174 int *levels; 187 int *levels;
188 struct acpi_video_brightness_flags flags;
175}; 189};
176 190
177struct acpi_video_device { 191struct acpi_video_device {
@@ -189,7 +203,7 @@ struct acpi_video_device {
189 203
190/* bus */ 204/* bus */
191static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file); 205static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file);
192static struct file_operations acpi_video_bus_info_fops = { 206static const struct file_operations acpi_video_bus_info_fops = {
193 .owner = THIS_MODULE, 207 .owner = THIS_MODULE,
194 .open = acpi_video_bus_info_open_fs, 208 .open = acpi_video_bus_info_open_fs,
195 .read = seq_read, 209 .read = seq_read,
@@ -198,7 +212,7 @@ static struct file_operations acpi_video_bus_info_fops = {
198}; 212};
199 213
200static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file); 214static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file);
201static struct file_operations acpi_video_bus_ROM_fops = { 215static const struct file_operations acpi_video_bus_ROM_fops = {
202 .owner = THIS_MODULE, 216 .owner = THIS_MODULE,
203 .open = acpi_video_bus_ROM_open_fs, 217 .open = acpi_video_bus_ROM_open_fs,
204 .read = seq_read, 218 .read = seq_read,
@@ -208,7 +222,7 @@ static struct file_operations acpi_video_bus_ROM_fops = {
208 222
209static int acpi_video_bus_POST_info_open_fs(struct inode *inode, 223static int acpi_video_bus_POST_info_open_fs(struct inode *inode,
210 struct file *file); 224 struct file *file);
211static struct file_operations acpi_video_bus_POST_info_fops = { 225static const struct file_operations acpi_video_bus_POST_info_fops = {
212 .owner = THIS_MODULE, 226 .owner = THIS_MODULE,
213 .open = acpi_video_bus_POST_info_open_fs, 227 .open = acpi_video_bus_POST_info_open_fs,
214 .read = seq_read, 228 .read = seq_read,
@@ -217,19 +231,25 @@ static struct file_operations acpi_video_bus_POST_info_fops = {
217}; 231};
218 232
219static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file); 233static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file);
220static struct file_operations acpi_video_bus_POST_fops = { 234static ssize_t acpi_video_bus_write_POST(struct file *file,
235 const char __user *buffer, size_t count, loff_t *data);
236static const struct file_operations acpi_video_bus_POST_fops = {
221 .owner = THIS_MODULE, 237 .owner = THIS_MODULE,
222 .open = acpi_video_bus_POST_open_fs, 238 .open = acpi_video_bus_POST_open_fs,
223 .read = seq_read, 239 .read = seq_read,
240 .write = acpi_video_bus_write_POST,
224 .llseek = seq_lseek, 241 .llseek = seq_lseek,
225 .release = single_release, 242 .release = single_release,
226}; 243};
227 244
228static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file); 245static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file);
229static struct file_operations acpi_video_bus_DOS_fops = { 246static ssize_t acpi_video_bus_write_DOS(struct file *file,
247 const char __user *buffer, size_t count, loff_t *data);
248static const struct file_operations acpi_video_bus_DOS_fops = {
230 .owner = THIS_MODULE, 249 .owner = THIS_MODULE,
231 .open = acpi_video_bus_DOS_open_fs, 250 .open = acpi_video_bus_DOS_open_fs,
232 .read = seq_read, 251 .read = seq_read,
252 .write = acpi_video_bus_write_DOS,
233 .llseek = seq_lseek, 253 .llseek = seq_lseek,
234 .release = single_release, 254 .release = single_release,
235}; 255};
@@ -237,7 +257,7 @@ static struct file_operations acpi_video_bus_DOS_fops = {
237/* device */ 257/* device */
238static int acpi_video_device_info_open_fs(struct inode *inode, 258static int acpi_video_device_info_open_fs(struct inode *inode,
239 struct file *file); 259 struct file *file);
240static struct file_operations acpi_video_device_info_fops = { 260static const struct file_operations acpi_video_device_info_fops = {
241 .owner = THIS_MODULE, 261 .owner = THIS_MODULE,
242 .open = acpi_video_device_info_open_fs, 262 .open = acpi_video_device_info_open_fs,
243 .read = seq_read, 263 .read = seq_read,
@@ -247,27 +267,33 @@ static struct file_operations acpi_video_device_info_fops = {
247 267
248static int acpi_video_device_state_open_fs(struct inode *inode, 268static int acpi_video_device_state_open_fs(struct inode *inode,
249 struct file *file); 269 struct file *file);
250static struct file_operations acpi_video_device_state_fops = { 270static ssize_t acpi_video_device_write_state(struct file *file,
271 const char __user *buffer, size_t count, loff_t *data);
272static const struct file_operations acpi_video_device_state_fops = {
251 .owner = THIS_MODULE, 273 .owner = THIS_MODULE,
252 .open = acpi_video_device_state_open_fs, 274 .open = acpi_video_device_state_open_fs,
253 .read = seq_read, 275 .read = seq_read,
276 .write = acpi_video_device_write_state,
254 .llseek = seq_lseek, 277 .llseek = seq_lseek,
255 .release = single_release, 278 .release = single_release,
256}; 279};
257 280
258static int acpi_video_device_brightness_open_fs(struct inode *inode, 281static int acpi_video_device_brightness_open_fs(struct inode *inode,
259 struct file *file); 282 struct file *file);
283static ssize_t acpi_video_device_write_brightness(struct file *file,
284 const char __user *buffer, size_t count, loff_t *data);
260static struct file_operations acpi_video_device_brightness_fops = { 285static struct file_operations acpi_video_device_brightness_fops = {
261 .owner = THIS_MODULE, 286 .owner = THIS_MODULE,
262 .open = acpi_video_device_brightness_open_fs, 287 .open = acpi_video_device_brightness_open_fs,
263 .read = seq_read, 288 .read = seq_read,
289 .write = acpi_video_device_write_brightness,
264 .llseek = seq_lseek, 290 .llseek = seq_lseek,
265 .release = single_release, 291 .release = single_release,
266}; 292};
267 293
268static int acpi_video_device_EDID_open_fs(struct inode *inode, 294static int acpi_video_device_EDID_open_fs(struct inode *inode,
269 struct file *file); 295 struct file *file);
270static struct file_operations acpi_video_device_EDID_fops = { 296static const struct file_operations acpi_video_device_EDID_fops = {
271 .owner = THIS_MODULE, 297 .owner = THIS_MODULE,
272 .open = acpi_video_device_EDID_open_fs, 298 .open = acpi_video_device_EDID_open_fs,
273 .read = seq_read, 299 .read = seq_read,
@@ -275,7 +301,7 @@ static struct file_operations acpi_video_device_EDID_fops = {
275 .release = single_release, 301 .release = single_release,
276}; 302};
277 303
278static char device_decode[][30] = { 304static const char device_decode[][30] = {
279 "motherboard VGA device", 305 "motherboard VGA device",
280 "PCI VGA device", 306 "PCI VGA device",
281 "AGP VGA device", 307 "AGP VGA device",
@@ -294,7 +320,7 @@ static int acpi_video_device_lcd_get_level_current(
294 unsigned long long *level); 320 unsigned long long *level);
295static int acpi_video_get_next_level(struct acpi_video_device *device, 321static int acpi_video_get_next_level(struct acpi_video_device *device,
296 u32 level_current, u32 event); 322 u32 level_current, u32 event);
297static void acpi_video_switch_brightness(struct acpi_video_device *device, 323static int acpi_video_switch_brightness(struct acpi_video_device *device,
298 int event); 324 int event);
299static int acpi_video_device_get_state(struct acpi_video_device *device, 325static int acpi_video_device_get_state(struct acpi_video_device *device,
300 unsigned long long *state); 326 unsigned long long *state);
@@ -308,7 +334,9 @@ static int acpi_video_get_brightness(struct backlight_device *bd)
308 int i; 334 int i;
309 struct acpi_video_device *vd = 335 struct acpi_video_device *vd =
310 (struct acpi_video_device *)bl_get_data(bd); 336 (struct acpi_video_device *)bl_get_data(bd);
311 acpi_video_device_lcd_get_level_current(vd, &cur_level); 337
338 if (acpi_video_device_lcd_get_level_current(vd, &cur_level))
339 return -EINVAL;
312 for (i = 2; i < vd->brightness->count; i++) { 340 for (i = 2; i < vd->brightness->count; i++) {
313 if (vd->brightness->levels[i] == cur_level) 341 if (vd->brightness->levels[i] == cur_level)
314 /* The first two entries are special - see page 575 342 /* The first two entries are special - see page 575
@@ -320,12 +348,12 @@ static int acpi_video_get_brightness(struct backlight_device *bd)
320 348
321static int acpi_video_set_brightness(struct backlight_device *bd) 349static int acpi_video_set_brightness(struct backlight_device *bd)
322{ 350{
323 int request_level = bd->props.brightness+2; 351 int request_level = bd->props.brightness + 2;
324 struct acpi_video_device *vd = 352 struct acpi_video_device *vd =
325 (struct acpi_video_device *)bl_get_data(bd); 353 (struct acpi_video_device *)bl_get_data(bd);
326 acpi_video_device_lcd_set_level(vd, 354
327 vd->brightness->levels[request_level]); 355 return acpi_video_device_lcd_set_level(vd,
328 return 0; 356 vd->brightness->levels[request_level]);
329} 357}
330 358
331static struct backlight_ops acpi_backlight_ops = { 359static struct backlight_ops acpi_backlight_ops = {
@@ -358,32 +386,37 @@ static struct output_properties acpi_output_properties = {
358 386
359 387
360/* thermal cooling device callbacks */ 388/* thermal cooling device callbacks */
361static int video_get_max_state(struct thermal_cooling_device *cdev, char *buf) 389static int video_get_max_state(struct thermal_cooling_device *cdev, unsigned
390 long *state)
362{ 391{
363 struct acpi_device *device = cdev->devdata; 392 struct acpi_device *device = cdev->devdata;
364 struct acpi_video_device *video = acpi_driver_data(device); 393 struct acpi_video_device *video = acpi_driver_data(device);
365 394
366 return sprintf(buf, "%d\n", video->brightness->count - 3); 395 *state = video->brightness->count - 3;
396 return 0;
367} 397}
368 398
369static int video_get_cur_state(struct thermal_cooling_device *cdev, char *buf) 399static int video_get_cur_state(struct thermal_cooling_device *cdev, unsigned
400 long *state)
370{ 401{
371 struct acpi_device *device = cdev->devdata; 402 struct acpi_device *device = cdev->devdata;
372 struct acpi_video_device *video = acpi_driver_data(device); 403 struct acpi_video_device *video = acpi_driver_data(device);
373 unsigned long long level; 404 unsigned long long level;
374 int state; 405 int offset;
375 406
376 acpi_video_device_lcd_get_level_current(video, &level); 407 if (acpi_video_device_lcd_get_level_current(video, &level))
377 for (state = 2; state < video->brightness->count; state++) 408 return -EINVAL;
378 if (level == video->brightness->levels[state]) 409 for (offset = 2; offset < video->brightness->count; offset++)
379 return sprintf(buf, "%d\n", 410 if (level == video->brightness->levels[offset]) {
380 video->brightness->count - state - 1); 411 *state = video->brightness->count - offset - 1;
412 return 0;
413 }
381 414
382 return -EINVAL; 415 return -EINVAL;
383} 416}
384 417
385static int 418static int
386video_set_cur_state(struct thermal_cooling_device *cdev, unsigned int state) 419video_set_cur_state(struct thermal_cooling_device *cdev, unsigned long state)
387{ 420{
388 struct acpi_device *device = cdev->devdata; 421 struct acpi_device *device = cdev->devdata;
389 struct acpi_video_device *video = acpi_driver_data(device); 422 struct acpi_video_device *video = acpi_driver_data(device);
@@ -479,34 +512,68 @@ acpi_video_device_lcd_query_levels(struct acpi_video_device *device,
479static int 512static int
480acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level) 513acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level)
481{ 514{
482 int status = AE_OK; 515 int status;
483 union acpi_object arg0 = { ACPI_TYPE_INTEGER }; 516 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
484 struct acpi_object_list args = { 1, &arg0 }; 517 struct acpi_object_list args = { 1, &arg0 };
485 int state; 518 int state;
486 519
487
488 arg0.integer.value = level; 520 arg0.integer.value = level;
489 521
490 if (device->cap._BCM) 522 status = acpi_evaluate_object(device->dev->handle, "_BCM",
491 status = acpi_evaluate_object(device->dev->handle, "_BCM", 523 &args, NULL);
492 &args, NULL); 524 if (ACPI_FAILURE(status)) {
525 ACPI_ERROR((AE_INFO, "Evaluating _BCM failed"));
526 return -EIO;
527 }
528
493 device->brightness->curr = level; 529 device->brightness->curr = level;
494 for (state = 2; state < device->brightness->count; state++) 530 for (state = 2; state < device->brightness->count; state++)
495 if (level == device->brightness->levels[state]) 531 if (level == device->brightness->levels[state]) {
496 device->backlight->props.brightness = state - 2; 532 if (device->backlight)
533 device->backlight->props.brightness = state - 2;
534 return 0;
535 }
497 536
498 return status; 537 ACPI_ERROR((AE_INFO, "Current brightness invalid"));
538 return -EINVAL;
499} 539}
500 540
501static int 541static int
502acpi_video_device_lcd_get_level_current(struct acpi_video_device *device, 542acpi_video_device_lcd_get_level_current(struct acpi_video_device *device,
503 unsigned long long *level) 543 unsigned long long *level)
504{ 544{
505 if (device->cap._BQC) 545 acpi_status status = AE_OK;
506 return acpi_evaluate_integer(device->dev->handle, "_BQC", NULL, 546
507 level); 547 if (device->cap._BQC || device->cap._BCQ) {
548 char *buf = device->cap._BQC ? "_BQC" : "_BCQ";
549
550 status = acpi_evaluate_integer(device->dev->handle, buf,
551 NULL, level);
552 if (ACPI_SUCCESS(status)) {
553 if (device->brightness->flags._BQC_use_index) {
554 if (device->brightness->flags._BCL_reversed)
555 *level = device->brightness->count
556 - 3 - (*level);
557 *level = device->brightness->levels[*level + 2];
558
559 }
560 device->brightness->curr = *level;
561 return 0;
562 } else {
563 /* Fixme:
564 * should we return an error or ignore this failure?
565 * dev->brightness->curr is a cached value which stores
566 * the correct current backlight level in most cases.
567 * ACPI video backlight still works w/ buggy _BQC.
568 * http://bugzilla.kernel.org/show_bug.cgi?id=12233
569 */
570 ACPI_WARNING((AE_INFO, "Evaluating %s failed", buf));
571 device->cap._BQC = device->cap._BCQ = 0;
572 }
573 }
574
508 *level = device->brightness->curr; 575 *level = device->brightness->curr;
509 return AE_OK; 576 return 0;
510} 577}
511 578
512static int 579static int
@@ -655,9 +722,11 @@ static int
655acpi_video_init_brightness(struct acpi_video_device *device) 722acpi_video_init_brightness(struct acpi_video_device *device)
656{ 723{
657 union acpi_object *obj = NULL; 724 union acpi_object *obj = NULL;
658 int i, max_level = 0, count = 0; 725 int i, max_level = 0, count = 0, level_ac_battery = 0;
726 unsigned long long level, level_old;
659 union acpi_object *o; 727 union acpi_object *o;
660 struct acpi_video_device_brightness *br = NULL; 728 struct acpi_video_device_brightness *br = NULL;
729 int result = -EINVAL;
661 730
662 if (!ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) { 731 if (!ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) {
663 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available " 732 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available "
@@ -671,13 +740,16 @@ acpi_video_init_brightness(struct acpi_video_device *device)
671 br = kzalloc(sizeof(*br), GFP_KERNEL); 740 br = kzalloc(sizeof(*br), GFP_KERNEL);
672 if (!br) { 741 if (!br) {
673 printk(KERN_ERR "can't allocate memory\n"); 742 printk(KERN_ERR "can't allocate memory\n");
743 result = -ENOMEM;
674 goto out; 744 goto out;
675 } 745 }
676 746
677 br->levels = kmalloc(obj->package.count * sizeof *(br->levels), 747 br->levels = kmalloc((obj->package.count + 2) * sizeof *(br->levels),
678 GFP_KERNEL); 748 GFP_KERNEL);
679 if (!br->levels) 749 if (!br->levels) {
750 result = -ENOMEM;
680 goto out_free; 751 goto out_free;
752 }
681 753
682 for (i = 0; i < obj->package.count; i++) { 754 for (i = 0; i < obj->package.count; i++) {
683 o = (union acpi_object *)&obj->package.elements[i]; 755 o = (union acpi_object *)&obj->package.elements[i];
@@ -692,18 +764,89 @@ acpi_video_init_brightness(struct acpi_video_device *device)
692 count++; 764 count++;
693 } 765 }
694 766
695 /* don't sort the first two brightness levels */ 767 /*
696 sort(&br->levels[2], count - 2, sizeof(br->levels[2]), 768 * some buggy BIOS don't export the levels
697 acpi_video_cmp_level, NULL); 769 * when machine is on AC/Battery in _BCL package.
770 * In this case, the first two elements in _BCL packages
771 * are also supported brightness levels that OS should take care of.
772 */
773 for (i = 2; i < count; i++) {
774 if (br->levels[i] == br->levels[0])
775 level_ac_battery++;
776 if (br->levels[i] == br->levels[1])
777 level_ac_battery++;
778 }
698 779
699 if (count < 2) 780 if (level_ac_battery < 2) {
700 goto out_free_levels; 781 level_ac_battery = 2 - level_ac_battery;
782 br->flags._BCL_no_ac_battery_levels = 1;
783 for (i = (count - 1 + level_ac_battery); i >= 2; i--)
784 br->levels[i] = br->levels[i - level_ac_battery];
785 count += level_ac_battery;
786 } else if (level_ac_battery > 2)
787 ACPI_ERROR((AE_INFO, "Too many duplicates in _BCL package\n"));
788
789 /* Check if the _BCL package is in a reversed order */
790 if (max_level == br->levels[2]) {
791 br->flags._BCL_reversed = 1;
792 sort(&br->levels[2], count - 2, sizeof(br->levels[2]),
793 acpi_video_cmp_level, NULL);
794 } else if (max_level != br->levels[count - 1])
795 ACPI_ERROR((AE_INFO,
796 "Found unordered _BCL package\n"));
701 797
702 br->count = count; 798 br->count = count;
703 device->brightness = br; 799 device->brightness = br;
704 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "found %d brightness levels\n", count)); 800
801 /* Check the input/output of _BQC/_BCL/_BCM */
802 if ((max_level < 100) && (max_level <= (count - 2)))
803 br->flags._BCL_use_index = 1;
804
805 /*
806 * _BCM is always consistent with _BCL,
807 * at least for all the laptops we have ever seen.
808 */
809 br->flags._BCM_use_index = br->flags._BCL_use_index;
810
811 /* _BQC uses INDEX while _BCL uses VALUE in some laptops */
812 br->curr = level_old = max_level;
813
814 if (!device->cap._BQC)
815 goto set_level;
816
817 result = acpi_video_device_lcd_get_level_current(device, &level_old);
818 if (result)
819 goto out_free_levels;
820
821 /*
822 * Set the level to maximum and check if _BQC uses indexed value
823 */
824 result = acpi_video_device_lcd_set_level(device, max_level);
825 if (result)
826 goto out_free_levels;
827
828 result = acpi_video_device_lcd_get_level_current(device, &level);
829 if (result)
830 goto out_free_levels;
831
832 br->flags._BQC_use_index = (level == max_level ? 0 : 1);
833
834 if (!br->flags._BQC_use_index)
835 goto set_level;
836
837 if (br->flags._BCL_reversed)
838 level_old = (br->count - 1) - level_old;
839 level_old = br->levels[level_old];
840
841set_level:
842 result = acpi_video_device_lcd_set_level(device, level_old);
843 if (result)
844 goto out_free_levels;
845
846 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
847 "found %d brightness levels\n", count - 2));
705 kfree(obj); 848 kfree(obj);
706 return max_level; 849 return result;
707 850
708out_free_levels: 851out_free_levels:
709 kfree(br->levels); 852 kfree(br->levels);
@@ -712,7 +855,7 @@ out_free:
712out: 855out:
713 device->brightness = NULL; 856 device->brightness = NULL;
714 kfree(obj); 857 kfree(obj);
715 return 0; 858 return result;
716} 859}
717 860
718/* 861/*
@@ -729,7 +872,6 @@ out:
729static void acpi_video_device_find_cap(struct acpi_video_device *device) 872static void acpi_video_device_find_cap(struct acpi_video_device *device)
730{ 873{
731 acpi_handle h_dummy1; 874 acpi_handle h_dummy1;
732 u32 max_level = 0;
733 875
734 876
735 memset(&device->cap, 0, sizeof(device->cap)); 877 memset(&device->cap, 0, sizeof(device->cap));
@@ -745,6 +887,12 @@ static void acpi_video_device_find_cap(struct acpi_video_device *device)
745 } 887 }
746 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle,"_BQC",&h_dummy1))) 888 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle,"_BQC",&h_dummy1)))
747 device->cap._BQC = 1; 889 device->cap._BQC = 1;
890 else if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCQ",
891 &h_dummy1))) {
892 printk(KERN_WARNING FW_BUG "_BCQ is used instead of _BQC\n");
893 device->cap._BCQ = 1;
894 }
895
748 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DDC", &h_dummy1))) { 896 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DDC", &h_dummy1))) {
749 device->cap._DDC = 1; 897 device->cap._DDC = 1;
750 } 898 }
@@ -758,13 +906,14 @@ static void acpi_video_device_find_cap(struct acpi_video_device *device)
758 device->cap._DSS = 1; 906 device->cap._DSS = 1;
759 } 907 }
760 908
761 if (acpi_video_backlight_support()) 909 if (acpi_video_backlight_support()) {
762 max_level = acpi_video_init_brightness(device);
763
764 if (device->cap._BCL && device->cap._BCM && max_level > 0) {
765 int result; 910 int result;
766 static int count = 0; 911 static int count = 0;
767 char *name; 912 char *name;
913
914 result = acpi_video_init_brightness(device);
915 if (result)
916 return;
768 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL); 917 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
769 if (!name) 918 if (!name)
770 return; 919 return;
@@ -773,18 +922,6 @@ static void acpi_video_device_find_cap(struct acpi_video_device *device)
773 device->backlight = backlight_device_register(name, 922 device->backlight = backlight_device_register(name,
774 NULL, device, &acpi_backlight_ops); 923 NULL, device, &acpi_backlight_ops);
775 device->backlight->props.max_brightness = device->brightness->count-3; 924 device->backlight->props.max_brightness = device->brightness->count-3;
776 /*
777 * If there exists the _BQC object, the _BQC object will be
778 * called to get the current backlight brightness. Otherwise
779 * the brightness will be set to the maximum.
780 */
781 if (device->cap._BQC)
782 device->backlight->props.brightness =
783 acpi_video_get_brightness(device->backlight);
784 else
785 device->backlight->props.brightness =
786 device->backlight->props.max_brightness;
787 backlight_update_status(device->backlight);
788 kfree(name); 925 kfree(name);
789 926
790 device->cdev = thermal_cooling_device_register("LCD", 927 device->cdev = thermal_cooling_device_register("LCD",
@@ -1020,7 +1157,7 @@ acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset)
1020 } 1157 }
1021 1158
1022 seq_printf(seq, "levels: "); 1159 seq_printf(seq, "levels: ");
1023 for (i = 0; i < dev->brightness->count; i++) 1160 for (i = 2; i < dev->brightness->count; i++)
1024 seq_printf(seq, " %d", dev->brightness->levels[i]); 1161 seq_printf(seq, " %d", dev->brightness->levels[i]);
1025 seq_printf(seq, "\ncurrent: %d\n", dev->brightness->curr); 1162 seq_printf(seq, "\ncurrent: %d\n", dev->brightness->curr);
1026 1163
@@ -1059,15 +1196,14 @@ acpi_video_device_write_brightness(struct file *file,
1059 return -EFAULT; 1196 return -EFAULT;
1060 1197
1061 /* validate through the list of available levels */ 1198 /* validate through the list of available levels */
1062 for (i = 0; i < dev->brightness->count; i++) 1199 for (i = 2; i < dev->brightness->count; i++)
1063 if (level == dev->brightness->levels[i]) { 1200 if (level == dev->brightness->levels[i]) {
1064 if (ACPI_SUCCESS 1201 if (!acpi_video_device_lcd_set_level(dev, level))
1065 (acpi_video_device_lcd_set_level(dev, level))) 1202 return count;
1066 dev->brightness->curr = level;
1067 break; 1203 break;
1068 } 1204 }
1069 1205
1070 return count; 1206 return -EINVAL;
1071} 1207}
1072 1208
1073static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset) 1209static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset)
@@ -1125,8 +1261,6 @@ static int acpi_video_device_add_fs(struct acpi_device *device)
1125 if (!device_dir) 1261 if (!device_dir)
1126 return -ENOMEM; 1262 return -ENOMEM;
1127 1263
1128 device_dir->owner = THIS_MODULE;
1129
1130 /* 'info' [R] */ 1264 /* 'info' [R] */
1131 entry = proc_create_data("info", S_IRUGO, device_dir, 1265 entry = proc_create_data("info", S_IRUGO, device_dir,
1132 &acpi_video_device_info_fops, acpi_driver_data(device)); 1266 &acpi_video_device_info_fops, acpi_driver_data(device));
@@ -1134,7 +1268,6 @@ static int acpi_video_device_add_fs(struct acpi_device *device)
1134 goto err_remove_dir; 1268 goto err_remove_dir;
1135 1269
1136 /* 'state' [R/W] */ 1270 /* 'state' [R/W] */
1137 acpi_video_device_state_fops.write = acpi_video_device_write_state;
1138 entry = proc_create_data("state", S_IFREG | S_IRUGO | S_IWUSR, 1271 entry = proc_create_data("state", S_IFREG | S_IRUGO | S_IWUSR,
1139 device_dir, 1272 device_dir,
1140 &acpi_video_device_state_fops, 1273 &acpi_video_device_state_fops,
@@ -1143,8 +1276,6 @@ static int acpi_video_device_add_fs(struct acpi_device *device)
1143 goto err_remove_info; 1276 goto err_remove_info;
1144 1277
1145 /* 'brightness' [R/W] */ 1278 /* 'brightness' [R/W] */
1146 acpi_video_device_brightness_fops.write =
1147 acpi_video_device_write_brightness;
1148 entry = proc_create_data("brightness", S_IFREG | S_IRUGO | S_IWUSR, 1279 entry = proc_create_data("brightness", S_IFREG | S_IRUGO | S_IWUSR,
1149 device_dir, 1280 device_dir,
1150 &acpi_video_device_brightness_fops, 1281 &acpi_video_device_brightness_fops,
@@ -1260,7 +1391,7 @@ static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset)
1260 printk(KERN_WARNING PREFIX 1391 printk(KERN_WARNING PREFIX
1261 "This indicates a BIOS bug. Please contact the manufacturer.\n"); 1392 "This indicates a BIOS bug. Please contact the manufacturer.\n");
1262 } 1393 }
1263 printk("%llx\n", options); 1394 printk(KERN_WARNING "%llx\n", options);
1264 seq_printf(seq, "can POST: <integrated video>"); 1395 seq_printf(seq, "can POST: <integrated video>");
1265 if (options & 2) 1396 if (options & 2)
1266 seq_printf(seq, " <PCI video>"); 1397 seq_printf(seq, " <PCI video>");
@@ -1403,8 +1534,6 @@ static int acpi_video_bus_add_fs(struct acpi_device *device)
1403 if (!device_dir) 1534 if (!device_dir)
1404 return -ENOMEM; 1535 return -ENOMEM;
1405 1536
1406 device_dir->owner = THIS_MODULE;
1407
1408 /* 'info' [R] */ 1537 /* 'info' [R] */
1409 entry = proc_create_data("info", S_IRUGO, device_dir, 1538 entry = proc_create_data("info", S_IRUGO, device_dir,
1410 &acpi_video_bus_info_fops, 1539 &acpi_video_bus_info_fops,
@@ -1427,7 +1556,6 @@ static int acpi_video_bus_add_fs(struct acpi_device *device)
1427 goto err_remove_rom; 1556 goto err_remove_rom;
1428 1557
1429 /* 'POST' [R/W] */ 1558 /* 'POST' [R/W] */
1430 acpi_video_bus_POST_fops.write = acpi_video_bus_write_POST;
1431 entry = proc_create_data("POST", S_IFREG | S_IRUGO | S_IWUSR, 1559 entry = proc_create_data("POST", S_IFREG | S_IRUGO | S_IWUSR,
1432 device_dir, 1560 device_dir,
1433 &acpi_video_bus_POST_fops, 1561 &acpi_video_bus_POST_fops,
@@ -1436,7 +1564,6 @@ static int acpi_video_bus_add_fs(struct acpi_device *device)
1436 goto err_remove_post_info; 1564 goto err_remove_post_info;
1437 1565
1438 /* 'DOS' [R/W] */ 1566 /* 'DOS' [R/W] */
1439 acpi_video_bus_DOS_fops.write = acpi_video_bus_write_DOS;
1440 entry = proc_create_data("DOS", S_IFREG | S_IRUGO | S_IWUSR, 1567 entry = proc_create_data("DOS", S_IFREG | S_IRUGO | S_IWUSR,
1441 device_dir, 1568 device_dir,
1442 &acpi_video_bus_DOS_fops, 1569 &acpi_video_bus_DOS_fops,
@@ -1712,7 +1839,7 @@ acpi_video_get_next_level(struct acpi_video_device *device,
1712 max = max_below = 0; 1839 max = max_below = 0;
1713 min = min_above = 255; 1840 min = min_above = 255;
1714 /* Find closest level to level_current */ 1841 /* Find closest level to level_current */
1715 for (i = 0; i < device->brightness->count; i++) { 1842 for (i = 2; i < device->brightness->count; i++) {
1716 l = device->brightness->levels[i]; 1843 l = device->brightness->levels[i];
1717 if (abs(l - level_current) < abs(delta)) { 1844 if (abs(l - level_current) < abs(delta)) {
1718 delta = l - level_current; 1845 delta = l - level_current;
@@ -1722,7 +1849,7 @@ acpi_video_get_next_level(struct acpi_video_device *device,
1722 } 1849 }
1723 /* Ajust level_current to closest available level */ 1850 /* Ajust level_current to closest available level */
1724 level_current += delta; 1851 level_current += delta;
1725 for (i = 0; i < device->brightness->count; i++) { 1852 for (i = 2; i < device->brightness->count; i++) {
1726 l = device->brightness->levels[i]; 1853 l = device->brightness->levels[i];
1727 if (l < min) 1854 if (l < min)
1728 min = l; 1855 min = l;
@@ -1749,15 +1876,29 @@ acpi_video_get_next_level(struct acpi_video_device *device,
1749 } 1876 }
1750} 1877}
1751 1878
1752static void 1879static int
1753acpi_video_switch_brightness(struct acpi_video_device *device, int event) 1880acpi_video_switch_brightness(struct acpi_video_device *device, int event)
1754{ 1881{
1755 unsigned long long level_current, level_next; 1882 unsigned long long level_current, level_next;
1883 int result = -EINVAL;
1884
1756 if (!device->brightness) 1885 if (!device->brightness)
1757 return; 1886 goto out;
1758 acpi_video_device_lcd_get_level_current(device, &level_current); 1887
1888 result = acpi_video_device_lcd_get_level_current(device,
1889 &level_current);
1890 if (result)
1891 goto out;
1892
1759 level_next = acpi_video_get_next_level(device, level_current, event); 1893 level_next = acpi_video_get_next_level(device, level_current, event);
1760 acpi_video_device_lcd_set_level(device, level_next); 1894
1895 result = acpi_video_device_lcd_set_level(device, level_next);
1896
1897out:
1898 if (result)
1899 printk(KERN_ERR PREFIX "Failed to switch the brightness\n");
1900
1901 return result;
1761} 1902}
1762 1903
1763static int 1904static int
@@ -1850,17 +1991,15 @@ static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
1850 return acpi_video_bus_DOS(video, 0, 1); 1991 return acpi_video_bus_DOS(video, 0, 1);
1851} 1992}
1852 1993
1853static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data) 1994static void acpi_video_bus_notify(struct acpi_device *device, u32 event)
1854{ 1995{
1855 struct acpi_video_bus *video = data; 1996 struct acpi_video_bus *video = acpi_driver_data(device);
1856 struct acpi_device *device = NULL;
1857 struct input_dev *input; 1997 struct input_dev *input;
1858 int keycode; 1998 int keycode;
1859 1999
1860 if (!video) 2000 if (!video)
1861 return; 2001 return;
1862 2002
1863 device = video->device;
1864 input = video->input; 2003 input = video->input;
1865 2004
1866 switch (event) { 2005 switch (event) {
@@ -1991,7 +2130,6 @@ static int acpi_video_resume(struct acpi_device *device)
1991 2130
1992static int acpi_video_bus_add(struct acpi_device *device) 2131static int acpi_video_bus_add(struct acpi_device *device)
1993{ 2132{
1994 acpi_status status;
1995 struct acpi_video_bus *video; 2133 struct acpi_video_bus *video;
1996 struct input_dev *input; 2134 struct input_dev *input;
1997 int error; 2135 int error;
@@ -2006,6 +2144,12 @@ static int acpi_video_bus_add(struct acpi_device *device)
2006 device->pnp.bus_id[3] = '0' + instance; 2144 device->pnp.bus_id[3] = '0' + instance;
2007 instance ++; 2145 instance ++;
2008 } 2146 }
2147 /* a hack to fix the duplicate name "VGA" problem on Pa 3553 */
2148 if (!strcmp(device->pnp.bus_id, "VGA")) {
2149 if (instance)
2150 device->pnp.bus_id[3] = '0' + instance;
2151 instance++;
2152 }
2009 2153
2010 video->device = device; 2154 video->device = device;
2011 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME); 2155 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
@@ -2027,20 +2171,10 @@ static int acpi_video_bus_add(struct acpi_device *device)
2027 acpi_video_bus_get_devices(video, device); 2171 acpi_video_bus_get_devices(video, device);
2028 acpi_video_bus_start_devices(video); 2172 acpi_video_bus_start_devices(video);
2029 2173
2030 status = acpi_install_notify_handler(device->handle,
2031 ACPI_DEVICE_NOTIFY,
2032 acpi_video_bus_notify, video);
2033 if (ACPI_FAILURE(status)) {
2034 printk(KERN_ERR PREFIX
2035 "Error installing notify handler\n");
2036 error = -ENODEV;
2037 goto err_stop_video;
2038 }
2039
2040 video->input = input = input_allocate_device(); 2174 video->input = input = input_allocate_device();
2041 if (!input) { 2175 if (!input) {
2042 error = -ENOMEM; 2176 error = -ENOMEM;
2043 goto err_uninstall_notify; 2177 goto err_stop_video;
2044 } 2178 }
2045 2179
2046 snprintf(video->phys, sizeof(video->phys), 2180 snprintf(video->phys, sizeof(video->phys),
@@ -2076,9 +2210,6 @@ static int acpi_video_bus_add(struct acpi_device *device)
2076 2210
2077 err_free_input_dev: 2211 err_free_input_dev:
2078 input_free_device(input); 2212 input_free_device(input);
2079 err_uninstall_notify:
2080 acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
2081 acpi_video_bus_notify);
2082 err_stop_video: 2213 err_stop_video:
2083 acpi_video_bus_stop_devices(video); 2214 acpi_video_bus_stop_devices(video);
2084 acpi_video_bus_put_devices(video); 2215 acpi_video_bus_put_devices(video);
@@ -2093,7 +2224,6 @@ static int acpi_video_bus_add(struct acpi_device *device)
2093 2224
2094static int acpi_video_bus_remove(struct acpi_device *device, int type) 2225static int acpi_video_bus_remove(struct acpi_device *device, int type)
2095{ 2226{
2096 acpi_status status = 0;
2097 struct acpi_video_bus *video = NULL; 2227 struct acpi_video_bus *video = NULL;
2098 2228
2099 2229
@@ -2103,11 +2233,6 @@ static int acpi_video_bus_remove(struct acpi_device *device, int type)
2103 video = acpi_driver_data(device); 2233 video = acpi_driver_data(device);
2104 2234
2105 acpi_video_bus_stop_devices(video); 2235 acpi_video_bus_stop_devices(video);
2106
2107 status = acpi_remove_notify_handler(video->device->handle,
2108 ACPI_DEVICE_NOTIFY,
2109 acpi_video_bus_notify);
2110
2111 acpi_video_bus_put_devices(video); 2236 acpi_video_bus_put_devices(video);
2112 acpi_video_bus_remove_fs(device); 2237 acpi_video_bus_remove_fs(device);
2113 2238
@@ -2118,14 +2243,33 @@ static int acpi_video_bus_remove(struct acpi_device *device, int type)
2118 return 0; 2243 return 0;
2119} 2244}
2120 2245
2121static int __init acpi_video_init(void) 2246static int __init intel_opregion_present(void)
2247{
2248#if defined(CONFIG_DRM_I915) || defined(CONFIG_DRM_I915_MODULE)
2249 struct pci_dev *dev = NULL;
2250 u32 address;
2251
2252 for_each_pci_dev(dev) {
2253 if ((dev->class >> 8) != PCI_CLASS_DISPLAY_VGA)
2254 continue;
2255 if (dev->vendor != PCI_VENDOR_ID_INTEL)
2256 continue;
2257 pci_read_config_dword(dev, 0xfc, &address);
2258 if (!address)
2259 continue;
2260 return 1;
2261 }
2262#endif
2263 return 0;
2264}
2265
2266int acpi_video_register(void)
2122{ 2267{
2123 int result = 0; 2268 int result = 0;
2124 2269
2125 acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir); 2270 acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir);
2126 if (!acpi_video_dir) 2271 if (!acpi_video_dir)
2127 return -ENODEV; 2272 return -ENODEV;
2128 acpi_video_dir->owner = THIS_MODULE;
2129 2273
2130 result = acpi_bus_register_driver(&acpi_video_bus); 2274 result = acpi_bus_register_driver(&acpi_video_bus);
2131 if (result < 0) { 2275 if (result < 0) {
@@ -2135,6 +2279,22 @@ static int __init acpi_video_init(void)
2135 2279
2136 return 0; 2280 return 0;
2137} 2281}
2282EXPORT_SYMBOL(acpi_video_register);
2283
2284/*
2285 * This is kind of nasty. Hardware using Intel chipsets may require
2286 * the video opregion code to be run first in order to initialise
2287 * state before any ACPI video calls are made. To handle this we defer
2288 * registration of the video class until the opregion code has run.
2289 */
2290
2291static int __init acpi_video_init(void)
2292{
2293 if (intel_opregion_present())
2294 return 0;
2295
2296 return acpi_video_register();
2297}
2138 2298
2139static void __exit acpi_video_exit(void) 2299static void __exit acpi_video_exit(void)
2140{ 2300{
diff --git a/drivers/acpi/video_detect.c b/drivers/acpi/video_detect.c
index 50e3d2dbf3af..09737275e25f 100644
--- a/drivers/acpi/video_detect.c
+++ b/drivers/acpi/video_detect.c
@@ -55,6 +55,9 @@ acpi_backlight_cap_match(acpi_handle handle, u32 level, void *context,
55 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found generic backlight " 55 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found generic backlight "
56 "support\n")); 56 "support\n"));
57 *cap |= ACPI_VIDEO_BACKLIGHT; 57 *cap |= ACPI_VIDEO_BACKLIGHT;
58 if (ACPI_FAILURE(acpi_get_handle(handle, "_BQC", &h_dummy)))
59 printk(KERN_WARNING FW_BUG PREFIX "ACPI brightness "
60 "control misses _BQC function\n");
58 /* We have backlight support, no need to scan further */ 61 /* We have backlight support, no need to scan further */
59 return AE_CTRL_TERMINATE; 62 return AE_CTRL_TERMINATE;
60 } 63 }
diff --git a/drivers/acpi/wakeup.c b/drivers/acpi/wakeup.c
index 2d34806d45dd..88725dcdf8bc 100644
--- a/drivers/acpi/wakeup.c
+++ b/drivers/acpi/wakeup.c
@@ -8,14 +8,18 @@
8#include <acpi/acpi_drivers.h> 8#include <acpi/acpi_drivers.h>
9#include <linux/kernel.h> 9#include <linux/kernel.h>
10#include <linux/types.h> 10#include <linux/types.h>
11
12#include "internal.h"
11#include "sleep.h" 13#include "sleep.h"
12 14
15/*
16 * We didn't lock acpi_device_lock in the file, because it invokes oops in
17 * suspend/resume and isn't really required as this is called in S-state. At
18 * that time, there is no device hotplug
19 **/
13#define _COMPONENT ACPI_SYSTEM_COMPONENT 20#define _COMPONENT ACPI_SYSTEM_COMPONENT
14ACPI_MODULE_NAME("wakeup_devices") 21ACPI_MODULE_NAME("wakeup_devices")
15 22
16extern struct list_head acpi_wakeup_device_list;
17extern spinlock_t acpi_device_lock;
18
19/** 23/**
20 * acpi_enable_wakeup_device_prep - prepare wakeup devices 24 * acpi_enable_wakeup_device_prep - prepare wakeup devices
21 * @sleep_state: ACPI state 25 * @sleep_state: ACPI state
@@ -27,7 +31,6 @@ void acpi_enable_wakeup_device_prep(u8 sleep_state)
27{ 31{
28 struct list_head *node, *next; 32 struct list_head *node, *next;
29 33
30 spin_lock(&acpi_device_lock);
31 list_for_each_safe(node, next, &acpi_wakeup_device_list) { 34 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
32 struct acpi_device *dev = container_of(node, 35 struct acpi_device *dev = container_of(node,
33 struct acpi_device, 36 struct acpi_device,
@@ -38,11 +41,8 @@ void acpi_enable_wakeup_device_prep(u8 sleep_state)
38 (sleep_state > (u32) dev->wakeup.sleep_state)) 41 (sleep_state > (u32) dev->wakeup.sleep_state))
39 continue; 42 continue;
40 43
41 spin_unlock(&acpi_device_lock);
42 acpi_enable_wakeup_device_power(dev, sleep_state); 44 acpi_enable_wakeup_device_power(dev, sleep_state);
43 spin_lock(&acpi_device_lock);
44 } 45 }
45 spin_unlock(&acpi_device_lock);
46} 46}
47 47
48/** 48/**
@@ -58,7 +58,6 @@ void acpi_enable_wakeup_device(u8 sleep_state)
58 * Caution: this routine must be invoked when interrupt is disabled 58 * Caution: this routine must be invoked when interrupt is disabled
59 * Refer ACPI2.0: P212 59 * Refer ACPI2.0: P212
60 */ 60 */
61 spin_lock(&acpi_device_lock);
62 list_for_each_safe(node, next, &acpi_wakeup_device_list) { 61 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
63 struct acpi_device *dev = 62 struct acpi_device *dev =
64 container_of(node, struct acpi_device, wakeup_list); 63 container_of(node, struct acpi_device, wakeup_list);
@@ -72,22 +71,17 @@ void acpi_enable_wakeup_device(u8 sleep_state)
72 if ((!dev->wakeup.state.enabled && !dev->wakeup.flags.prepared) 71 if ((!dev->wakeup.state.enabled && !dev->wakeup.flags.prepared)
73 || sleep_state > (u32) dev->wakeup.sleep_state) { 72 || sleep_state > (u32) dev->wakeup.sleep_state) {
74 if (dev->wakeup.flags.run_wake) { 73 if (dev->wakeup.flags.run_wake) {
75 spin_unlock(&acpi_device_lock);
76 /* set_gpe_type will disable GPE, leave it like that */ 74 /* set_gpe_type will disable GPE, leave it like that */
77 acpi_set_gpe_type(dev->wakeup.gpe_device, 75 acpi_set_gpe_type(dev->wakeup.gpe_device,
78 dev->wakeup.gpe_number, 76 dev->wakeup.gpe_number,
79 ACPI_GPE_TYPE_RUNTIME); 77 ACPI_GPE_TYPE_RUNTIME);
80 spin_lock(&acpi_device_lock);
81 } 78 }
82 continue; 79 continue;
83 } 80 }
84 spin_unlock(&acpi_device_lock);
85 if (!dev->wakeup.flags.run_wake) 81 if (!dev->wakeup.flags.run_wake)
86 acpi_enable_gpe(dev->wakeup.gpe_device, 82 acpi_enable_gpe(dev->wakeup.gpe_device,
87 dev->wakeup.gpe_number); 83 dev->wakeup.gpe_number);
88 spin_lock(&acpi_device_lock);
89 } 84 }
90 spin_unlock(&acpi_device_lock);
91} 85}
92 86
93/** 87/**
@@ -99,7 +93,6 @@ void acpi_disable_wakeup_device(u8 sleep_state)
99{ 93{
100 struct list_head *node, *next; 94 struct list_head *node, *next;
101 95
102 spin_lock(&acpi_device_lock);
103 list_for_each_safe(node, next, &acpi_wakeup_device_list) { 96 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
104 struct acpi_device *dev = 97 struct acpi_device *dev =
105 container_of(node, struct acpi_device, wakeup_list); 98 container_of(node, struct acpi_device, wakeup_list);
@@ -110,19 +103,16 @@ void acpi_disable_wakeup_device(u8 sleep_state)
110 if ((!dev->wakeup.state.enabled && !dev->wakeup.flags.prepared) 103 if ((!dev->wakeup.state.enabled && !dev->wakeup.flags.prepared)
111 || sleep_state > (u32) dev->wakeup.sleep_state) { 104 || sleep_state > (u32) dev->wakeup.sleep_state) {
112 if (dev->wakeup.flags.run_wake) { 105 if (dev->wakeup.flags.run_wake) {
113 spin_unlock(&acpi_device_lock);
114 acpi_set_gpe_type(dev->wakeup.gpe_device, 106 acpi_set_gpe_type(dev->wakeup.gpe_device,
115 dev->wakeup.gpe_number, 107 dev->wakeup.gpe_number,
116 ACPI_GPE_TYPE_WAKE_RUN); 108 ACPI_GPE_TYPE_WAKE_RUN);
117 /* Re-enable it, since set_gpe_type will disable it */ 109 /* Re-enable it, since set_gpe_type will disable it */
118 acpi_enable_gpe(dev->wakeup.gpe_device, 110 acpi_enable_gpe(dev->wakeup.gpe_device,
119 dev->wakeup.gpe_number); 111 dev->wakeup.gpe_number);
120 spin_lock(&acpi_device_lock);
121 } 112 }
122 continue; 113 continue;
123 } 114 }
124 115
125 spin_unlock(&acpi_device_lock);
126 acpi_disable_wakeup_device_power(dev); 116 acpi_disable_wakeup_device_power(dev);
127 /* Never disable run-wake GPE */ 117 /* Never disable run-wake GPE */
128 if (!dev->wakeup.flags.run_wake) { 118 if (!dev->wakeup.flags.run_wake) {
@@ -131,19 +121,14 @@ void acpi_disable_wakeup_device(u8 sleep_state)
131 acpi_clear_gpe(dev->wakeup.gpe_device, 121 acpi_clear_gpe(dev->wakeup.gpe_device,
132 dev->wakeup.gpe_number, ACPI_NOT_ISR); 122 dev->wakeup.gpe_number, ACPI_NOT_ISR);
133 } 123 }
134 spin_lock(&acpi_device_lock);
135 } 124 }
136 spin_unlock(&acpi_device_lock);
137} 125}
138 126
139static int __init acpi_wakeup_device_init(void) 127int __init acpi_wakeup_device_init(void)
140{ 128{
141 struct list_head *node, *next; 129 struct list_head *node, *next;
142 130
143 if (acpi_disabled) 131 mutex_lock(&acpi_device_lock);
144 return 0;
145
146 spin_lock(&acpi_device_lock);
147 list_for_each_safe(node, next, &acpi_wakeup_device_list) { 132 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
148 struct acpi_device *dev = container_of(node, 133 struct acpi_device *dev = container_of(node,
149 struct acpi_device, 134 struct acpi_device,
@@ -151,17 +136,13 @@ static int __init acpi_wakeup_device_init(void)
151 /* In case user doesn't load button driver */ 136 /* In case user doesn't load button driver */
152 if (!dev->wakeup.flags.run_wake || dev->wakeup.state.enabled) 137 if (!dev->wakeup.flags.run_wake || dev->wakeup.state.enabled)
153 continue; 138 continue;
154 spin_unlock(&acpi_device_lock);
155 acpi_set_gpe_type(dev->wakeup.gpe_device, 139 acpi_set_gpe_type(dev->wakeup.gpe_device,
156 dev->wakeup.gpe_number, 140 dev->wakeup.gpe_number,
157 ACPI_GPE_TYPE_WAKE_RUN); 141 ACPI_GPE_TYPE_WAKE_RUN);
158 acpi_enable_gpe(dev->wakeup.gpe_device, 142 acpi_enable_gpe(dev->wakeup.gpe_device,
159 dev->wakeup.gpe_number); 143 dev->wakeup.gpe_number);
160 dev->wakeup.state.enabled = 1; 144 dev->wakeup.state.enabled = 1;
161 spin_lock(&acpi_device_lock);
162 } 145 }
163 spin_unlock(&acpi_device_lock); 146 mutex_unlock(&acpi_device_lock);
164 return 0; 147 return 0;
165} 148}
166
167late_initcall(acpi_wakeup_device_init);