aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2008-07-16 17:52:12 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-07-16 17:52:12 -0400
commit4314652bb41df08ad65bd25176ba1dfd24b14a51 (patch)
tree1632ae5936422bb36f2c43948bf079b7ca17e76f
parentd442cc44c0db56e84ef6aa244a88427d2efe06cd (diff)
parent01a5bba576b9364b33f61f0cd9fa70c2cf5535e2 (diff)
Merge branch 'release-2.6.27' of git://git.kernel.org/pub/scm/linux/kernel/git/ak/linux-acpi-merge-2.6
* 'release-2.6.27' of git://git.kernel.org/pub/scm/linux/kernel/git/ak/linux-acpi-merge-2.6: (87 commits) Fix FADT parsing Add the ability to reset the machine using the RESET_REG in ACPI's FADT table. ACPI: use dev_printk when possible PNPACPI: add support for HP vendor-specific CCSR descriptors PNP: avoid legacy IDE IRQs PNP: convert resource options to single linked list ISAPNP: handle independent options following dependent ones PNP: remove extra 0x100 bit from option priority PNP: support optional IRQ resources PNP: rename pnp_register_*_resource() local variables PNPACPI: ignore _PRS interrupt numbers larger than PNP_IRQ_NR PNP: centralize resource option allocations PNP: remove redundant pnp_can_configure() check PNP: make resource assignment functions return 0 (success) or -EBUSY (failure) PNP: in debug resource dump, make empty list obvious PNP: improve resource assignment debug PNP: increase I/O port & memory option address sizes PNP: introduce pnp_irq_mask_t typedef PNP: make resource option structures private to PNP subsystem PNP: define PNP-specific IORESOURCE_IO_* flags alongside IRQ, DMA, MEM ...
-rw-r--r--Documentation/ABI/testing/sysfs-firmware-acpi127
-rw-r--r--Documentation/kernel-parameters.txt5
-rw-r--r--Documentation/laptops/acer-wmi.txt2
-rw-r--r--MAINTAINERS25
-rw-r--r--arch/ia64/kernel/process.c4
-rw-r--r--arch/x86/kernel/acpi/processor.c6
-rw-r--r--arch/x86/kernel/process.c28
-rw-r--r--arch/x86/mm/srat_32.c3
-rw-r--r--drivers/acpi/Makefile2
-rw-r--r--drivers/acpi/bay.c3
-rw-r--r--drivers/acpi/bus.c2
-rw-r--r--drivers/acpi/dispatcher/dsinit.c2
-rw-r--r--drivers/acpi/dispatcher/dsmethod.c1
-rw-r--r--drivers/acpi/dispatcher/dsopcode.c22
-rw-r--r--drivers/acpi/dispatcher/dswexec.c8
-rw-r--r--drivers/acpi/dispatcher/dswstate.c20
-rw-r--r--drivers/acpi/dock.c3
-rw-r--r--drivers/acpi/events/evevent.c6
-rw-r--r--drivers/acpi/events/evgpe.c36
-rw-r--r--drivers/acpi/events/evgpeblk.c18
-rw-r--r--drivers/acpi/events/evmisc.c4
-rw-r--r--drivers/acpi/events/evregion.c5
-rw-r--r--drivers/acpi/events/evrgnini.c2
-rw-r--r--drivers/acpi/events/evxfevnt.c18
-rw-r--r--drivers/acpi/executer/exconfig.c17
-rw-r--r--drivers/acpi/executer/exconvrt.c12
-rw-r--r--drivers/acpi/executer/excreate.c2
-rw-r--r--drivers/acpi/executer/exdump.c67
-rw-r--r--drivers/acpi/executer/exfldio.c9
-rw-r--r--drivers/acpi/executer/exmisc.c8
-rw-r--r--drivers/acpi/executer/exprep.c8
-rw-r--r--drivers/acpi/executer/exregion.c2
-rw-r--r--drivers/acpi/executer/exresop.c4
-rw-r--r--drivers/acpi/executer/exstore.c6
-rw-r--r--drivers/acpi/fan.c8
-rw-r--r--drivers/acpi/glue.c3
-rw-r--r--drivers/acpi/hardware/hwgpe.c52
-rw-r--r--drivers/acpi/namespace/nsdump.c6
-rw-r--r--drivers/acpi/namespace/nseval.c35
-rw-r--r--drivers/acpi/namespace/nsinit.c1
-rw-r--r--drivers/acpi/namespace/nsload.c3
-rw-r--r--drivers/acpi/namespace/nsparse.c15
-rw-r--r--drivers/acpi/namespace/nsutils.c50
-rw-r--r--drivers/acpi/namespace/nsxfeval.c3
-rw-r--r--drivers/acpi/numa.c4
-rw-r--r--drivers/acpi/parser/psargs.c4
-rw-r--r--drivers/acpi/parser/psxface.c4
-rw-r--r--drivers/acpi/pci_irq.c38
-rw-r--r--drivers/acpi/processor_core.c75
-rw-r--r--drivers/acpi/processor_idle.c34
-rw-r--r--drivers/acpi/processor_perflib.c18
-rw-r--r--drivers/acpi/processor_throttling.c38
-rw-r--r--drivers/acpi/reboot.c50
-rw-r--r--drivers/acpi/resources/rscalc.c4
-rw-r--r--drivers/acpi/resources/rscreate.c41
-rw-r--r--drivers/acpi/resources/rsmisc.c2
-rw-r--r--drivers/acpi/resources/rsutils.c13
-rw-r--r--drivers/acpi/scan.c62
-rw-r--r--drivers/acpi/sleep/main.c39
-rw-r--r--drivers/acpi/system.c169
-rw-r--r--drivers/acpi/tables/tbfadt.c23
-rw-r--r--drivers/acpi/tables/tbfind.c5
-rw-r--r--drivers/acpi/tables/tbinstal.c30
-rw-r--r--drivers/acpi/tables/tbutils.c15
-rw-r--r--drivers/acpi/tables/tbxface.c28
-rw-r--r--drivers/acpi/tables/tbxfroot.c4
-rw-r--r--drivers/acpi/utilities/utalloc.c5
-rw-r--r--drivers/acpi/utilities/utcopy.c4
-rw-r--r--drivers/acpi/utilities/utdebug.c54
-rw-r--r--drivers/acpi/utilities/utdelete.c2
-rw-r--r--drivers/acpi/utilities/uteval.c5
-rw-r--r--drivers/acpi/utilities/utmisc.c39
-rw-r--r--drivers/acpi/utilities/utmutex.c4
-rw-r--r--drivers/acpi/utilities/utobject.c9
-rw-r--r--drivers/acpi/video.c123
-rw-r--r--drivers/char/apm-emulation.c346
-rw-r--r--drivers/misc/Kconfig31
-rw-r--r--drivers/misc/Makefile5
-rw-r--r--drivers/misc/acer-wmi.c145
-rw-r--r--drivers/misc/compal-laptop.c404
-rw-r--r--drivers/misc/eeepc-laptop.c4
-rw-r--r--drivers/misc/fujitsu-laptop.c825
-rw-r--r--drivers/pci/pci-acpi.c6
-rw-r--r--drivers/pci/pci.c4
-rw-r--r--drivers/pci/pci.h3
-rw-r--r--drivers/pnp/base.h148
-rw-r--r--drivers/pnp/core.c29
-rw-r--r--drivers/pnp/interface.c207
-rw-r--r--drivers/pnp/isapnp/core.c253
-rw-r--r--drivers/pnp/manager.c414
-rw-r--r--drivers/pnp/pnpacpi/core.c4
-rw-r--r--drivers/pnp/pnpacpi/rsparser.c492
-rw-r--r--drivers/pnp/pnpbios/rsparser.c274
-rw-r--r--drivers/pnp/quirks.c307
-rw-r--r--drivers/pnp/resource.c454
-rw-r--r--drivers/pnp/support.c171
-rw-r--r--drivers/pnp/system.c4
-rw-r--r--drivers/serial/8250_pnp.c24
-rw-r--r--include/acpi/acconfig.h2
-rw-r--r--include/acpi/acdisasm.h1
-rw-r--r--include/acpi/acdispat.h2
-rw-r--r--include/acpi/acexcep.h10
-rw-r--r--include/acpi/acglobal.h2
-rw-r--r--include/acpi/achware.h4
-rw-r--r--include/acpi/acinterp.h5
-rw-r--r--include/acpi/aclocal.h6
-rw-r--r--include/acpi/acmacros.h38
-rw-r--r--include/acpi/acnamesp.h30
-rw-r--r--include/acpi/acpi_bus.h4
-rw-r--r--include/acpi/acpiosxf.h2
-rw-r--r--include/acpi/acpixf.h12
-rw-r--r--include/acpi/acstruct.h10
-rw-r--r--include/acpi/actables.h27
-rw-r--r--include/acpi/actbl1.h23
-rw-r--r--include/acpi/actypes.h16
-rw-r--r--include/acpi/acutils.h70
-rw-r--r--include/acpi/processor.h2
-rw-r--r--include/acpi/reboot.h14
-rw-r--r--include/asm-ia64/processor.h2
-rw-r--r--include/asm-x86/processor.h2
-rw-r--r--include/linux/freezer.h10
-rw-r--r--include/linux/ioport.h5
-rw-r--r--include/linux/pnp.h146
-rw-r--r--include/linux/sched.h1
-rw-r--r--kernel/cpu.c1
-rw-r--r--kernel/kthread.c2
-rw-r--r--kernel/power/process.c97
-rw-r--r--kernel/power/user.c71
128 files changed, 4330 insertions, 2449 deletions
diff --git a/Documentation/ABI/testing/sysfs-firmware-acpi b/Documentation/ABI/testing/sysfs-firmware-acpi
index 9470ed9afcc0..f27be7d1a49f 100644
--- a/Documentation/ABI/testing/sysfs-firmware-acpi
+++ b/Documentation/ABI/testing/sysfs-firmware-acpi
@@ -29,46 +29,46 @@ Description:
29 29
30 $ cd /sys/firmware/acpi/interrupts 30 $ cd /sys/firmware/acpi/interrupts
31 $ grep . * 31 $ grep . *
32 error:0 32 error: 0
33 ff_gbl_lock:0 33 ff_gbl_lock: 0 enable
34 ff_pmtimer:0 34 ff_pmtimer: 0 invalid
35 ff_pwr_btn:0 35 ff_pwr_btn: 0 enable
36 ff_rt_clk:0 36 ff_rt_clk: 2 disable
37 ff_slp_btn:0 37 ff_slp_btn: 0 invalid
38 gpe00:0 38 gpe00: 0 invalid
39 gpe01:0 39 gpe01: 0 enable
40 gpe02:0 40 gpe02: 108 enable
41 gpe03:0 41 gpe03: 0 invalid
42 gpe04:0 42 gpe04: 0 invalid
43 gpe05:0 43 gpe05: 0 invalid
44 gpe06:0 44 gpe06: 0 enable
45 gpe07:0 45 gpe07: 0 enable
46 gpe08:0 46 gpe08: 0 invalid
47 gpe09:174 47 gpe09: 0 invalid
48 gpe0A:0 48 gpe0A: 0 invalid
49 gpe0B:0 49 gpe0B: 0 invalid
50 gpe0C:0 50 gpe0C: 0 invalid
51 gpe0D:0 51 gpe0D: 0 invalid
52 gpe0E:0 52 gpe0E: 0 invalid
53 gpe0F:0 53 gpe0F: 0 invalid
54 gpe10:0 54 gpe10: 0 invalid
55 gpe11:60 55 gpe11: 0 invalid
56 gpe12:0 56 gpe12: 0 invalid
57 gpe13:0 57 gpe13: 0 invalid
58 gpe14:0 58 gpe14: 0 invalid
59 gpe15:0 59 gpe15: 0 invalid
60 gpe16:0 60 gpe16: 0 invalid
61 gpe17:0 61 gpe17: 1084 enable
62 gpe18:0 62 gpe18: 0 enable
63 gpe19:7 63 gpe19: 0 invalid
64 gpe1A:0 64 gpe1A: 0 invalid
65 gpe1B:0 65 gpe1B: 0 invalid
66 gpe1C:0 66 gpe1C: 0 invalid
67 gpe1D:0 67 gpe1D: 0 invalid
68 gpe1E:0 68 gpe1E: 0 invalid
69 gpe1F:0 69 gpe1F: 0 invalid
70 gpe_all:241 70 gpe_all: 1192
71 sci:241 71 sci: 1194
72 72
73 sci - The total number of times the ACPI SCI 73 sci - The total number of times the ACPI SCI
74 has claimed an interrupt. 74 has claimed an interrupt.
@@ -89,6 +89,13 @@ Description:
89 89
90 error - an interrupt that can't be accounted for above. 90 error - an interrupt that can't be accounted for above.
91 91
92 invalid: it's either a wakeup GPE or a GPE/Fixed Event that
93 doesn't have an event handler.
94
95 disable: the GPE/Fixed Event is valid but disabled.
96
97 enable: the GPE/Fixed Event is valid and enabled.
98
92 Root has permission to clear any of these counters. Eg. 99 Root has permission to clear any of these counters. Eg.
93 # echo 0 > gpe11 100 # echo 0 > gpe11
94 101
@@ -97,3 +104,43 @@ Description:
97 104
98 None of these counters has an effect on the function 105 None of these counters has an effect on the function
99 of the system, they are simply statistics. 106 of the system, they are simply statistics.
107
108 Besides this, user can also write specific strings to these files
109 to enable/disable/clear ACPI interrupts in user space, which can be
110 used to debug some ACPI interrupt storm issues.
111
112 Note that only writting to VALID GPE/Fixed Event is allowed,
113 i.e. user can only change the status of runtime GPE and
114 Fixed Event with event handler installed.
115
116 Let's take power button fixed event for example, please kill acpid
117 and other user space applications so that the machine won't shutdown
118 when pressing the power button.
119 # cat ff_pwr_btn
120 0
121 # press the power button for 3 times;
122 # cat ff_pwr_btn
123 3
124 # echo disable > ff_pwr_btn
125 # cat ff_pwr_btn
126 disable
127 # press the power button for 3 times;
128 # cat ff_pwr_btn
129 disable
130 # echo enable > ff_pwr_btn
131 # cat ff_pwr_btn
132 4
133 /*
134 * this is because the status bit is set even if the enable bit is cleared,
135 * and it triggers an ACPI fixed event when the enable bit is set again
136 */
137 # press the power button for 3 times;
138 # cat ff_pwr_btn
139 7
140 # echo disable > ff_pwr_btn
141 # press the power button for 3 times;
142 # echo clear > ff_pwr_btn /* clear the status bit */
143 # echo disable > ff_pwr_btn
144 # cat ff_pwr_btn
145 7
146
diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
index 312fe77764a4..5e497d16fb51 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -818,7 +818,7 @@ and is between 256 and 4096 characters. It is defined in the file
818 See Documentation/ide/ide.txt. 818 See Documentation/ide/ide.txt.
819 819
820 idle= [X86] 820 idle= [X86]
821 Format: idle=poll or idle=mwait 821 Format: idle=poll or idle=mwait, idle=halt, idle=nomwait
822 Poll forces a polling idle loop that can slightly improves the performance 822 Poll forces a polling idle loop that can slightly improves the performance
823 of waking up a idle CPU, but will use a lot of power and make the system 823 of waking up a idle CPU, but will use a lot of power and make the system
824 run hot. Not recommended. 824 run hot. Not recommended.
@@ -826,6 +826,9 @@ and is between 256 and 4096 characters. It is defined in the file
826 to not use it because it doesn't save as much power as a normal idle 826 to not use it because it doesn't save as much power as a normal idle
827 loop use the MONITOR/MWAIT idle loop anyways. Performance should be the same 827 loop use the MONITOR/MWAIT idle loop anyways. Performance should be the same
828 as idle=poll. 828 as idle=poll.
829 idle=halt. Halt is forced to be used for CPU idle.
830 In such case C2/C3 won't be used again.
831 idle=nomwait. Disable mwait for CPU C-states
829 832
830 ide-pci-generic.all-generic-ide [HW] (E)IDE subsystem 833 ide-pci-generic.all-generic-ide [HW] (E)IDE subsystem
831 Claim all unknown PCI IDE storage controllers. 834 Claim all unknown PCI IDE storage controllers.
diff --git a/Documentation/laptops/acer-wmi.txt b/Documentation/laptops/acer-wmi.txt
index 79b7dbd22141..69b5dd4e5a59 100644
--- a/Documentation/laptops/acer-wmi.txt
+++ b/Documentation/laptops/acer-wmi.txt
@@ -174,8 +174,6 @@ The LED is exposed through the LED subsystem, and can be found in:
174The mail LED is autodetected, so if you don't have one, the LED device won't 174The mail LED is autodetected, so if you don't have one, the LED device won't
175be registered. 175be registered.
176 176
177If you have a mail LED that is not green, please report this to me.
178
179Backlight 177Backlight
180********* 178*********
181 179
diff --git a/MAINTAINERS b/MAINTAINERS
index ee1c56a20750..633bda666e45 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -216,8 +216,8 @@ W: http://code.google.com/p/aceracpi
216S: Maintained 216S: Maintained
217 217
218ACPI 218ACPI
219P: Len Brown 219P: Andi Kleen
220M: len.brown@intel.com 220M: ak@linux.intel.com
221M: lenb@kernel.org 221M: lenb@kernel.org
222L: linux-acpi@vger.kernel.org 222L: linux-acpi@vger.kernel.org
223W: http://www.lesswatts.org/projects/acpi/ 223W: http://www.lesswatts.org/projects/acpi/
@@ -239,8 +239,8 @@ W: http://www.lesswatts.org/projects/acpi/
239S: Supported 239S: Supported
240 240
241ACPI FAN DRIVER 241ACPI FAN DRIVER
242P: Len Brown 242P: Zhang Rui
243M: len.brown@intel.com 243M: rui.zhang@intel.com
244L: linux-acpi@vger.kernel.org 244L: linux-acpi@vger.kernel.org
245W: http://www.lesswatts.org/projects/acpi/ 245W: http://www.lesswatts.org/projects/acpi/
246S: Supported 246S: Supported
@@ -252,14 +252,14 @@ L: pcihpd-discuss@lists.sourceforge.net
252S: Supported 252S: Supported
253 253
254ACPI THERMAL DRIVER 254ACPI THERMAL DRIVER
255P: Len Brown 255P: Zhang Rui
256M: len.brown@intel.com 256M: rui.zhang@intel.com
257L: linux-acpi@vger.kernel.org 257L: linux-acpi@vger.kernel.org
258W: http://www.lesswatts.org/projects/acpi/ 258W: http://www.lesswatts.org/projects/acpi/
259S: Supported 259S: Supported
260 260
261ACPI VIDEO DRIVER 261ACPI VIDEO DRIVER
262P: Rui Zhang 262P: Zhang Rui
263M: rui.zhang@intel.com 263M: rui.zhang@intel.com
264L: linux-acpi@vger.kernel.org 264L: linux-acpi@vger.kernel.org
265W: http://www.lesswatts.org/projects/acpi/ 265W: http://www.lesswatts.org/projects/acpi/
@@ -1160,6 +1160,11 @@ M: scott@spiteful.org
1160L: pcihpd-discuss@lists.sourceforge.net 1160L: pcihpd-discuss@lists.sourceforge.net
1161S: Supported 1161S: Supported
1162 1162
1163COMPAL LAPTOP SUPPORT
1164P: Cezary Jackiewicz
1165M: cezary.jackiewicz@gmail.com
1166S: Maintained
1167
1163COMPUTONE INTELLIPORT MULTIPORT CARD 1168COMPUTONE INTELLIPORT MULTIPORT CARD
1164P: Michael H. Warfield 1169P: Michael H. Warfield
1165M: mhw@wittsend.com 1170M: mhw@wittsend.com
@@ -1787,6 +1792,12 @@ P: David Howells
1787M: dhowells@redhat.com 1792M: dhowells@redhat.com
1788S: Maintained 1793S: Maintained
1789 1794
1795FUJITSU LAPTOP EXTRAS
1796P: Jonathan Woithe
1797M: jwoithe@physics.adelaide.edu.au
1798L: linux-acpi@vger.kernel.org
1799S: Maintained
1800
1790FUSE: FILESYSTEM IN USERSPACE 1801FUSE: FILESYSTEM IN USERSPACE
1791P: Miklos Szeredi 1802P: Miklos Szeredi
1792M: miklos@szeredi.hu 1803M: miklos@szeredi.hu
diff --git a/arch/ia64/kernel/process.c b/arch/ia64/kernel/process.c
index fabaf08d9a69..3ab8373103ec 100644
--- a/arch/ia64/kernel/process.c
+++ b/arch/ia64/kernel/process.c
@@ -55,6 +55,10 @@ void (*ia64_mark_idle)(int);
55 55
56unsigned long boot_option_idle_override = 0; 56unsigned long boot_option_idle_override = 0;
57EXPORT_SYMBOL(boot_option_idle_override); 57EXPORT_SYMBOL(boot_option_idle_override);
58unsigned long idle_halt;
59EXPORT_SYMBOL(idle_halt);
60unsigned long idle_nomwait;
61EXPORT_SYMBOL(idle_nomwait);
58 62
59void 63void
60ia64_do_show_stack (struct unw_frame_info *info, void *arg) 64ia64_do_show_stack (struct unw_frame_info *info, void *arg)
diff --git a/arch/x86/kernel/acpi/processor.c b/arch/x86/kernel/acpi/processor.c
index de2d2e4ebad9..7c074eec39fb 100644
--- a/arch/x86/kernel/acpi/processor.c
+++ b/arch/x86/kernel/acpi/processor.c
@@ -56,6 +56,12 @@ static void init_intel_pdc(struct acpi_processor *pr, struct cpuinfo_x86 *c)
56 if (cpu_has(c, X86_FEATURE_ACPI)) 56 if (cpu_has(c, X86_FEATURE_ACPI))
57 buf[2] |= ACPI_PDC_T_FFH; 57 buf[2] |= ACPI_PDC_T_FFH;
58 58
59 /*
60 * If mwait/monitor is unsupported, C2/C3_FFH will be disabled
61 */
62 if (!cpu_has(c, X86_FEATURE_MWAIT))
63 buf[2] &= ~(ACPI_PDC_C_C2C3_FFH);
64
59 obj->type = ACPI_TYPE_BUFFER; 65 obj->type = ACPI_TYPE_BUFFER;
60 obj->buffer.length = 12; 66 obj->buffer.length = 12;
61 obj->buffer.pointer = (u8 *) buf; 67 obj->buffer.pointer = (u8 *) buf;
diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
index 7dceea947232..4d629c62f4f8 100644
--- a/arch/x86/kernel/process.c
+++ b/arch/x86/kernel/process.c
@@ -7,6 +7,12 @@
7#include <linux/module.h> 7#include <linux/module.h>
8#include <linux/pm.h> 8#include <linux/pm.h>
9#include <linux/clockchips.h> 9#include <linux/clockchips.h>
10#include <asm/system.h>
11
12unsigned long idle_halt;
13EXPORT_SYMBOL(idle_halt);
14unsigned long idle_nomwait;
15EXPORT_SYMBOL(idle_nomwait);
10 16
11struct kmem_cache *task_xstate_cachep; 17struct kmem_cache *task_xstate_cachep;
12 18
@@ -325,7 +331,27 @@ static int __init idle_setup(char *str)
325 pm_idle = poll_idle; 331 pm_idle = poll_idle;
326 } else if (!strcmp(str, "mwait")) 332 } else if (!strcmp(str, "mwait"))
327 force_mwait = 1; 333 force_mwait = 1;
328 else 334 else if (!strcmp(str, "halt")) {
335 /*
336 * When the boot option of idle=halt is added, halt is
337 * forced to be used for CPU idle. In such case CPU C2/C3
338 * won't be used again.
339 * To continue to load the CPU idle driver, don't touch
340 * the boot_option_idle_override.
341 */
342 pm_idle = default_idle;
343 idle_halt = 1;
344 return 0;
345 } else if (!strcmp(str, "nomwait")) {
346 /*
347 * If the boot option of "idle=nomwait" is added,
348 * it means that mwait will be disabled for CPU C2/C3
349 * states. In such case it won't touch the variable
350 * of boot_option_idle_override.
351 */
352 idle_nomwait = 1;
353 return 0;
354 } else
329 return -1; 355 return -1;
330 356
331 boot_option_idle_override = 1; 357 boot_option_idle_override = 1;
diff --git a/arch/x86/mm/srat_32.c b/arch/x86/mm/srat_32.c
index f41d67f8f831..1eb2973a301c 100644
--- a/arch/x86/mm/srat_32.c
+++ b/arch/x86/mm/srat_32.c
@@ -156,10 +156,9 @@ acpi_numa_memory_affinity_init(struct acpi_srat_mem_affinity *memory_affinity)
156 156
157 num_memory_chunks++; 157 num_memory_chunks++;
158 158
159 printk(KERN_DEBUG "Memory range %08lx to %08lx (type %x)" 159 printk(KERN_DEBUG "Memory range %08lx to %08lx"
160 " in proximity domain %02x %s\n", 160 " in proximity domain %02x %s\n",
161 start_pfn, end_pfn, 161 start_pfn, end_pfn,
162 memory_affinity->memory_type,
163 pxm, 162 pxm,
164 ((memory_affinity->flags & ACPI_SRAT_MEM_HOT_PLUGGABLE) ? 163 ((memory_affinity->flags & ACPI_SRAT_MEM_HOT_PLUGGABLE) ?
165 "enabled and removable" : "enabled" ) ); 164 "enabled and removable" : "enabled" ) );
diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index 40b0fcae4c78..4efbe598c817 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -21,7 +21,7 @@ obj-$(CONFIG_X86) += blacklist.o
21# 21#
22# ACPI Core Subsystem (Interpreter) 22# ACPI Core Subsystem (Interpreter)
23# 23#
24obj-y += osl.o utils.o \ 24obj-y += osl.o utils.o reboot.o\
25 dispatcher/ events/ executer/ hardware/ \ 25 dispatcher/ events/ executer/ hardware/ \
26 namespace/ parser/ resources/ tables/ \ 26 namespace/ parser/ resources/ tables/ \
27 utilities/ 27 utilities/
diff --git a/drivers/acpi/bay.c b/drivers/acpi/bay.c
index 61b6c5beb2d3..e6caf5d42e0e 100644
--- a/drivers/acpi/bay.c
+++ b/drivers/acpi/bay.c
@@ -380,6 +380,9 @@ static int __init bay_init(void)
380 if (acpi_disabled) 380 if (acpi_disabled)
381 return -ENODEV; 381 return -ENODEV;
382 382
383 if (acpi_disabled)
384 return -ENODEV;
385
383 /* look for dockable drive bays */ 386 /* look for dockable drive bays */
384 acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, 387 acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
385 ACPI_UINT32_MAX, find_bay, &bays, NULL); 388 ACPI_UINT32_MAX, find_bay, &bays, NULL);
diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c
index a6dbcf4d9ef5..afb34387d5f2 100644
--- a/drivers/acpi/bus.c
+++ b/drivers/acpi/bus.c
@@ -612,7 +612,7 @@ static int __init acpi_bus_init_irq(void)
612 return 0; 612 return 0;
613} 613}
614 614
615acpi_native_uint acpi_gbl_permanent_mmap; 615u8 acpi_gbl_permanent_mmap;
616 616
617 617
618void __init acpi_early_init(void) 618void __init acpi_early_init(void)
diff --git a/drivers/acpi/dispatcher/dsinit.c b/drivers/acpi/dispatcher/dsinit.c
index 610b1ee102b0..949f7c75029e 100644
--- a/drivers/acpi/dispatcher/dsinit.c
+++ b/drivers/acpi/dispatcher/dsinit.c
@@ -151,7 +151,7 @@ acpi_ds_init_one_object(acpi_handle obj_handle,
151 ******************************************************************************/ 151 ******************************************************************************/
152 152
153acpi_status 153acpi_status
154acpi_ds_initialize_objects(acpi_native_uint table_index, 154acpi_ds_initialize_objects(u32 table_index,
155 struct acpi_namespace_node * start_node) 155 struct acpi_namespace_node * start_node)
156{ 156{
157 acpi_status status; 157 acpi_status status;
diff --git a/drivers/acpi/dispatcher/dsmethod.c b/drivers/acpi/dispatcher/dsmethod.c
index 2509809a36cf..4613b9ca5792 100644
--- a/drivers/acpi/dispatcher/dsmethod.c
+++ b/drivers/acpi/dispatcher/dsmethod.c
@@ -377,7 +377,6 @@ acpi_ds_call_control_method(struct acpi_thread_state *thread,
377 } 377 }
378 378
379 info->parameters = &this_walk_state->operands[0]; 379 info->parameters = &this_walk_state->operands[0];
380 info->parameter_type = ACPI_PARAM_ARGS;
381 380
382 status = acpi_ds_init_aml_walk(next_walk_state, NULL, method_node, 381 status = acpi_ds_init_aml_walk(next_walk_state, NULL, method_node,
383 obj_desc->method.aml_start, 382 obj_desc->method.aml_start,
diff --git a/drivers/acpi/dispatcher/dsopcode.c b/drivers/acpi/dispatcher/dsopcode.c
index a818e0ddb996..6a81c4400edf 100644
--- a/drivers/acpi/dispatcher/dsopcode.c
+++ b/drivers/acpi/dispatcher/dsopcode.c
@@ -691,12 +691,6 @@ acpi_ds_eval_buffer_field_operands(struct acpi_walk_state *walk_state,
691 691
692 status = acpi_ex_resolve_operands(op->common.aml_opcode, 692 status = acpi_ex_resolve_operands(op->common.aml_opcode,
693 ACPI_WALK_OPERANDS, walk_state); 693 ACPI_WALK_OPERANDS, walk_state);
694
695 ACPI_DUMP_OPERANDS(ACPI_WALK_OPERANDS, ACPI_IMODE_EXECUTE,
696 acpi_ps_get_opcode_name(op->common.aml_opcode),
697 walk_state->num_operands,
698 "after AcpiExResolveOperands");
699
700 if (ACPI_FAILURE(status)) { 694 if (ACPI_FAILURE(status)) {
701 ACPI_ERROR((AE_INFO, "(%s) bad operand(s) (%X)", 695 ACPI_ERROR((AE_INFO, "(%s) bad operand(s) (%X)",
702 acpi_ps_get_opcode_name(op->common.aml_opcode), 696 acpi_ps_get_opcode_name(op->common.aml_opcode),
@@ -785,10 +779,6 @@ acpi_ds_eval_region_operands(struct acpi_walk_state *walk_state,
785 return_ACPI_STATUS(status); 779 return_ACPI_STATUS(status);
786 } 780 }
787 781
788 ACPI_DUMP_OPERANDS(ACPI_WALK_OPERANDS, ACPI_IMODE_EXECUTE,
789 acpi_ps_get_opcode_name(op->common.aml_opcode),
790 1, "after AcpiExResolveOperands");
791
792 obj_desc = acpi_ns_get_attached_object(node); 782 obj_desc = acpi_ns_get_attached_object(node);
793 if (!obj_desc) { 783 if (!obj_desc) {
794 return_ACPI_STATUS(AE_NOT_EXIST); 784 return_ACPI_STATUS(AE_NOT_EXIST);
@@ -848,7 +838,7 @@ acpi_ds_eval_table_region_operands(struct acpi_walk_state *walk_state,
848 union acpi_operand_object **operand; 838 union acpi_operand_object **operand;
849 struct acpi_namespace_node *node; 839 struct acpi_namespace_node *node;
850 union acpi_parse_object *next_op; 840 union acpi_parse_object *next_op;
851 acpi_native_uint table_index; 841 u32 table_index;
852 struct acpi_table_header *table; 842 struct acpi_table_header *table;
853 843
854 ACPI_FUNCTION_TRACE_PTR(ds_eval_table_region_operands, op); 844 ACPI_FUNCTION_TRACE_PTR(ds_eval_table_region_operands, op);
@@ -882,10 +872,6 @@ acpi_ds_eval_table_region_operands(struct acpi_walk_state *walk_state,
882 return_ACPI_STATUS(status); 872 return_ACPI_STATUS(status);
883 } 873 }
884 874
885 ACPI_DUMP_OPERANDS(ACPI_WALK_OPERANDS, ACPI_IMODE_EXECUTE,
886 acpi_ps_get_opcode_name(op->common.aml_opcode),
887 1, "after AcpiExResolveOperands");
888
889 operand = &walk_state->operands[0]; 875 operand = &walk_state->operands[0];
890 876
891 /* Find the ACPI table */ 877 /* Find the ACPI table */
@@ -1091,10 +1077,8 @@ acpi_ds_eval_bank_field_operands(struct acpi_walk_state *walk_state,
1091 return_ACPI_STATUS(status); 1077 return_ACPI_STATUS(status);
1092 } 1078 }
1093 1079
1094 ACPI_DUMP_OPERANDS(ACPI_WALK_OPERANDS, ACPI_IMODE_EXECUTE, 1080 ACPI_DUMP_OPERANDS(ACPI_WALK_OPERANDS,
1095 acpi_ps_get_opcode_name(op->common.aml_opcode), 1081 acpi_ps_get_opcode_name(op->common.aml_opcode), 1);
1096 1, "after AcpiExResolveOperands");
1097
1098 /* 1082 /*
1099 * Get the bank_value operand and save it 1083 * Get the bank_value operand and save it
1100 * (at Top of stack) 1084 * (at Top of stack)
diff --git a/drivers/acpi/dispatcher/dswexec.c b/drivers/acpi/dispatcher/dswexec.c
index b246b9657ead..b5072fa9c920 100644
--- a/drivers/acpi/dispatcher/dswexec.c
+++ b/drivers/acpi/dispatcher/dswexec.c
@@ -408,14 +408,6 @@ acpi_status acpi_ds_exec_end_op(struct acpi_walk_state *walk_state)
408 [walk_state-> 408 [walk_state->
409 num_operands - 1]), 409 num_operands - 1]),
410 walk_state); 410 walk_state);
411 if (ACPI_SUCCESS(status)) {
412 ACPI_DUMP_OPERANDS(ACPI_WALK_OPERANDS,
413 ACPI_IMODE_EXECUTE,
414 acpi_ps_get_opcode_name
415 (walk_state->opcode),
416 walk_state->num_operands,
417 "after ExResolveOperands");
418 }
419 } 411 }
420 412
421 if (ACPI_SUCCESS(status)) { 413 if (ACPI_SUCCESS(status)) {
diff --git a/drivers/acpi/dispatcher/dswstate.c b/drivers/acpi/dispatcher/dswstate.c
index 1386ced332ec..b00d4af791aa 100644
--- a/drivers/acpi/dispatcher/dswstate.c
+++ b/drivers/acpi/dispatcher/dswstate.c
@@ -70,7 +70,7 @@ acpi_status
70acpi_ds_result_pop(union acpi_operand_object **object, 70acpi_ds_result_pop(union acpi_operand_object **object,
71 struct acpi_walk_state *walk_state) 71 struct acpi_walk_state *walk_state)
72{ 72{
73 acpi_native_uint index; 73 u32 index;
74 union acpi_generic_state *state; 74 union acpi_generic_state *state;
75 acpi_status status; 75 acpi_status status;
76 76
@@ -122,7 +122,7 @@ acpi_ds_result_pop(union acpi_operand_object **object,
122 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, 122 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
123 "Obj=%p [%s] Index=%X State=%p Num=%X\n", *object, 123 "Obj=%p [%s] Index=%X State=%p Num=%X\n", *object,
124 acpi_ut_get_object_type_name(*object), 124 acpi_ut_get_object_type_name(*object),
125 (u32) index, walk_state, walk_state->result_count)); 125 index, walk_state, walk_state->result_count));
126 126
127 return (AE_OK); 127 return (AE_OK);
128} 128}
@@ -146,7 +146,7 @@ acpi_ds_result_push(union acpi_operand_object * object,
146{ 146{
147 union acpi_generic_state *state; 147 union acpi_generic_state *state;
148 acpi_status status; 148 acpi_status status;
149 acpi_native_uint index; 149 u32 index;
150 150
151 ACPI_FUNCTION_NAME(ds_result_push); 151 ACPI_FUNCTION_NAME(ds_result_push);
152 152
@@ -400,7 +400,7 @@ void
400acpi_ds_obj_stack_pop_and_delete(u32 pop_count, 400acpi_ds_obj_stack_pop_and_delete(u32 pop_count,
401 struct acpi_walk_state *walk_state) 401 struct acpi_walk_state *walk_state)
402{ 402{
403 acpi_native_int i; 403 s32 i;
404 union acpi_operand_object *obj_desc; 404 union acpi_operand_object *obj_desc;
405 405
406 ACPI_FUNCTION_NAME(ds_obj_stack_pop_and_delete); 406 ACPI_FUNCTION_NAME(ds_obj_stack_pop_and_delete);
@@ -409,7 +409,7 @@ acpi_ds_obj_stack_pop_and_delete(u32 pop_count,
409 return; 409 return;
410 } 410 }
411 411
412 for (i = (acpi_native_int) (pop_count - 1); i >= 0; i--) { 412 for (i = (s32) pop_count - 1; i >= 0; i--) {
413 if (walk_state->num_operands == 0) { 413 if (walk_state->num_operands == 0) {
414 return; 414 return;
415 } 415 }
@@ -615,14 +615,8 @@ acpi_ds_init_aml_walk(struct acpi_walk_state *walk_state,
615 walk_state->pass_number = pass_number; 615 walk_state->pass_number = pass_number;
616 616
617 if (info) { 617 if (info) {
618 if (info->parameter_type == ACPI_PARAM_GPE) { 618 walk_state->params = info->parameters;
619 walk_state->gpe_event_info = 619 walk_state->caller_return_desc = &info->return_object;
620 ACPI_CAST_PTR(struct acpi_gpe_event_info,
621 info->parameters);
622 } else {
623 walk_state->params = info->parameters;
624 walk_state->caller_return_desc = &info->return_object;
625 }
626 } 620 }
627 621
628 status = acpi_ps_init_scope(&walk_state->parser_state, op); 622 status = acpi_ps_init_scope(&walk_state->parser_state, op);
diff --git a/drivers/acpi/dock.c b/drivers/acpi/dock.c
index bb7c51f712bd..1e872e79db33 100644
--- a/drivers/acpi/dock.c
+++ b/drivers/acpi/dock.c
@@ -920,6 +920,9 @@ static int __init dock_init(void)
920 if (acpi_disabled) 920 if (acpi_disabled)
921 return 0; 921 return 0;
922 922
923 if (acpi_disabled)
924 return 0;
925
923 /* look for a dock station */ 926 /* look for a dock station */
924 acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, 927 acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
925 ACPI_UINT32_MAX, find_dock, &num, NULL); 928 ACPI_UINT32_MAX, find_dock, &num, NULL);
diff --git a/drivers/acpi/events/evevent.c b/drivers/acpi/events/evevent.c
index 5d30e5be1b1c..c56c5c6ea77b 100644
--- a/drivers/acpi/events/evevent.c
+++ b/drivers/acpi/events/evevent.c
@@ -188,7 +188,7 @@ acpi_status acpi_ev_install_xrupt_handlers(void)
188 188
189static acpi_status acpi_ev_fixed_event_initialize(void) 189static acpi_status acpi_ev_fixed_event_initialize(void)
190{ 190{
191 acpi_native_uint i; 191 u32 i;
192 acpi_status status; 192 acpi_status status;
193 193
194 /* 194 /*
@@ -231,7 +231,7 @@ u32 acpi_ev_fixed_event_detect(void)
231 u32 int_status = ACPI_INTERRUPT_NOT_HANDLED; 231 u32 int_status = ACPI_INTERRUPT_NOT_HANDLED;
232 u32 fixed_status; 232 u32 fixed_status;
233 u32 fixed_enable; 233 u32 fixed_enable;
234 acpi_native_uint i; 234 u32 i;
235 235
236 ACPI_FUNCTION_NAME(ev_fixed_event_detect); 236 ACPI_FUNCTION_NAME(ev_fixed_event_detect);
237 237
@@ -260,7 +260,7 @@ u32 acpi_ev_fixed_event_detect(void)
260 260
261 /* Found an active (signalled) event */ 261 /* Found an active (signalled) event */
262 acpi_os_fixed_event_count(i); 262 acpi_os_fixed_event_count(i);
263 int_status |= acpi_ev_fixed_event_dispatch((u32) i); 263 int_status |= acpi_ev_fixed_event_dispatch(i);
264 } 264 }
265 } 265 }
266 266
diff --git a/drivers/acpi/events/evgpe.c b/drivers/acpi/events/evgpe.c
index 5354be44f876..c5e53aae86f7 100644
--- a/drivers/acpi/events/evgpe.c
+++ b/drivers/acpi/events/evgpe.c
@@ -256,7 +256,7 @@ acpi_status acpi_ev_disable_gpe(struct acpi_gpe_event_info *gpe_event_info)
256 return_ACPI_STATUS(status); 256 return_ACPI_STATUS(status);
257 } 257 }
258 258
259 /* Mark wake-disabled or HW disable, or both */ 259 /* Clear the appropriate enabled flags for this GPE */
260 260
261 switch (gpe_event_info->flags & ACPI_GPE_TYPE_MASK) { 261 switch (gpe_event_info->flags & ACPI_GPE_TYPE_MASK) {
262 case ACPI_GPE_TYPE_WAKE: 262 case ACPI_GPE_TYPE_WAKE:
@@ -273,13 +273,23 @@ acpi_status acpi_ev_disable_gpe(struct acpi_gpe_event_info *gpe_event_info)
273 /* Disable the requested runtime GPE */ 273 /* Disable the requested runtime GPE */
274 274
275 ACPI_CLEAR_BIT(gpe_event_info->flags, ACPI_GPE_RUN_ENABLED); 275 ACPI_CLEAR_BIT(gpe_event_info->flags, ACPI_GPE_RUN_ENABLED);
276 276 break;
277 /* fallthrough */
278 277
279 default: 278 default:
280 acpi_hw_write_gpe_enable_reg(gpe_event_info); 279 break;
281 } 280 }
282 281
282 /*
283 * Even if we don't know the GPE type, make sure that we always
284 * disable it. low_disable_gpe will just clear the enable bit for this
285 * GPE and write it. It will not write out the current GPE enable mask,
286 * since this may inadvertently enable GPEs too early, if a rogue GPE has
287 * come in during ACPICA initialization - possibly as a result of AML or
288 * other code that has enabled the GPE.
289 */
290 status = acpi_hw_low_disable_gpe(gpe_event_info);
291 return_ACPI_STATUS(status);
292
283 return_ACPI_STATUS(AE_OK); 293 return_ACPI_STATUS(AE_OK);
284} 294}
285 295
@@ -305,7 +315,7 @@ struct acpi_gpe_event_info *acpi_ev_get_gpe_event_info(acpi_handle gpe_device,
305{ 315{
306 union acpi_operand_object *obj_desc; 316 union acpi_operand_object *obj_desc;
307 struct acpi_gpe_block_info *gpe_block; 317 struct acpi_gpe_block_info *gpe_block;
308 acpi_native_uint i; 318 u32 i;
309 319
310 ACPI_FUNCTION_ENTRY(); 320 ACPI_FUNCTION_ENTRY();
311 321
@@ -379,8 +389,8 @@ u32 acpi_ev_gpe_detect(struct acpi_gpe_xrupt_info * gpe_xrupt_list)
379 u32 status_reg; 389 u32 status_reg;
380 u32 enable_reg; 390 u32 enable_reg;
381 acpi_cpu_flags flags; 391 acpi_cpu_flags flags;
382 acpi_native_uint i; 392 u32 i;
383 acpi_native_uint j; 393 u32 j;
384 394
385 ACPI_FUNCTION_NAME(ev_gpe_detect); 395 ACPI_FUNCTION_NAME(ev_gpe_detect);
386 396
@@ -462,13 +472,7 @@ u32 acpi_ev_gpe_detect(struct acpi_gpe_xrupt_info * gpe_xrupt_list)
462 */ 472 */
463 int_status |= 473 int_status |=
464 acpi_ev_gpe_dispatch(&gpe_block-> 474 acpi_ev_gpe_dispatch(&gpe_block->
465 event_info[(i * 475 event_info[((acpi_size) i * ACPI_GPE_REGISTER_WIDTH) + j], j + gpe_register_info->base_gpe_number);
466 ACPI_GPE_REGISTER_WIDTH)
467 +
468 j],
469 (u32) j +
470 gpe_register_info->
471 base_gpe_number);
472 } 476 }
473 } 477 }
474 } 478 }
@@ -555,10 +559,6 @@ static void ACPI_SYSTEM_XFACE acpi_ev_asynch_execute_gpe_method(void *context)
555 */ 559 */
556 info->prefix_node = 560 info->prefix_node =
557 local_gpe_event_info.dispatch.method_node; 561 local_gpe_event_info.dispatch.method_node;
558 info->parameters =
559 ACPI_CAST_PTR(union acpi_operand_object *,
560 gpe_event_info);
561 info->parameter_type = ACPI_PARAM_GPE;
562 info->flags = ACPI_IGNORE_RETURN_VALUE; 562 info->flags = ACPI_IGNORE_RETURN_VALUE;
563 563
564 status = acpi_ns_evaluate(info); 564 status = acpi_ns_evaluate(info);
diff --git a/drivers/acpi/events/evgpeblk.c b/drivers/acpi/events/evgpeblk.c
index e6c4d4c49e79..73c058e2f5c2 100644
--- a/drivers/acpi/events/evgpeblk.c
+++ b/drivers/acpi/events/evgpeblk.c
@@ -189,8 +189,8 @@ acpi_ev_delete_gpe_handlers(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
189 struct acpi_gpe_block_info *gpe_block) 189 struct acpi_gpe_block_info *gpe_block)
190{ 190{
191 struct acpi_gpe_event_info *gpe_event_info; 191 struct acpi_gpe_event_info *gpe_event_info;
192 acpi_native_uint i; 192 u32 i;
193 acpi_native_uint j; 193 u32 j;
194 194
195 ACPI_FUNCTION_TRACE(ev_delete_gpe_handlers); 195 ACPI_FUNCTION_TRACE(ev_delete_gpe_handlers);
196 196
@@ -203,7 +203,8 @@ acpi_ev_delete_gpe_handlers(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
203 for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) { 203 for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) {
204 gpe_event_info = 204 gpe_event_info =
205 &gpe_block-> 205 &gpe_block->
206 event_info[(i * ACPI_GPE_REGISTER_WIDTH) + j]; 206 event_info[((acpi_size) i *
207 ACPI_GPE_REGISTER_WIDTH) + j];
207 208
208 if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) == 209 if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) ==
209 ACPI_GPE_DISPATCH_HANDLER) { 210 ACPI_GPE_DISPATCH_HANDLER) {
@@ -744,8 +745,8 @@ acpi_ev_create_gpe_info_blocks(struct acpi_gpe_block_info *gpe_block)
744 struct acpi_gpe_event_info *gpe_event_info = NULL; 745 struct acpi_gpe_event_info *gpe_event_info = NULL;
745 struct acpi_gpe_event_info *this_event; 746 struct acpi_gpe_event_info *this_event;
746 struct acpi_gpe_register_info *this_register; 747 struct acpi_gpe_register_info *this_register;
747 acpi_native_uint i; 748 u32 i;
748 acpi_native_uint j; 749 u32 j;
749 acpi_status status; 750 acpi_status status;
750 751
751 ACPI_FUNCTION_TRACE(ev_create_gpe_info_blocks); 752 ACPI_FUNCTION_TRACE(ev_create_gpe_info_blocks);
@@ -983,8 +984,8 @@ acpi_ev_initialize_gpe_block(struct acpi_namespace_node *gpe_device,
983 struct acpi_gpe_walk_info gpe_info; 984 struct acpi_gpe_walk_info gpe_info;
984 u32 wake_gpe_count; 985 u32 wake_gpe_count;
985 u32 gpe_enabled_count; 986 u32 gpe_enabled_count;
986 acpi_native_uint i; 987 u32 i;
987 acpi_native_uint j; 988 u32 j;
988 989
989 ACPI_FUNCTION_TRACE(ev_initialize_gpe_block); 990 ACPI_FUNCTION_TRACE(ev_initialize_gpe_block);
990 991
@@ -1033,7 +1034,8 @@ acpi_ev_initialize_gpe_block(struct acpi_namespace_node *gpe_device,
1033 1034
1034 gpe_event_info = 1035 gpe_event_info =
1035 &gpe_block-> 1036 &gpe_block->
1036 event_info[(i * ACPI_GPE_REGISTER_WIDTH) + j]; 1037 event_info[((acpi_size) i *
1038 ACPI_GPE_REGISTER_WIDTH) + j];
1037 1039
1038 if (((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) == 1040 if (((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) ==
1039 ACPI_GPE_DISPATCH_METHOD) 1041 ACPI_GPE_DISPATCH_METHOD)
diff --git a/drivers/acpi/events/evmisc.c b/drivers/acpi/events/evmisc.c
index 2113e58e2221..1d5670be729a 100644
--- a/drivers/acpi/events/evmisc.c
+++ b/drivers/acpi/events/evmisc.c
@@ -575,7 +575,7 @@ acpi_status acpi_ev_release_global_lock(void)
575 575
576void acpi_ev_terminate(void) 576void acpi_ev_terminate(void)
577{ 577{
578 acpi_native_uint i; 578 u32 i;
579 acpi_status status; 579 acpi_status status;
580 580
581 ACPI_FUNCTION_TRACE(ev_terminate); 581 ACPI_FUNCTION_TRACE(ev_terminate);
@@ -589,7 +589,7 @@ void acpi_ev_terminate(void)
589 /* Disable all fixed events */ 589 /* Disable all fixed events */
590 590
591 for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++) { 591 for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++) {
592 status = acpi_disable_event((u32) i, 0); 592 status = acpi_disable_event(i, 0);
593 if (ACPI_FAILURE(status)) { 593 if (ACPI_FAILURE(status)) {
594 ACPI_ERROR((AE_INFO, 594 ACPI_ERROR((AE_INFO,
595 "Could not disable fixed event %d", 595 "Could not disable fixed event %d",
diff --git a/drivers/acpi/events/evregion.c b/drivers/acpi/events/evregion.c
index 1628f5934752..236fbd1ca438 100644
--- a/drivers/acpi/events/evregion.c
+++ b/drivers/acpi/events/evregion.c
@@ -81,7 +81,7 @@ acpi_ev_install_handler(acpi_handle obj_handle,
81acpi_status acpi_ev_install_region_handlers(void) 81acpi_status acpi_ev_install_region_handlers(void)
82{ 82{
83 acpi_status status; 83 acpi_status status;
84 acpi_native_uint i; 84 u32 i;
85 85
86 ACPI_FUNCTION_TRACE(ev_install_region_handlers); 86 ACPI_FUNCTION_TRACE(ev_install_region_handlers);
87 87
@@ -151,7 +151,7 @@ acpi_status acpi_ev_install_region_handlers(void)
151acpi_status acpi_ev_initialize_op_regions(void) 151acpi_status acpi_ev_initialize_op_regions(void)
152{ 152{
153 acpi_status status; 153 acpi_status status;
154 acpi_native_uint i; 154 u32 i;
155 155
156 ACPI_FUNCTION_TRACE(ev_initialize_op_regions); 156 ACPI_FUNCTION_TRACE(ev_initialize_op_regions);
157 157
@@ -219,7 +219,6 @@ acpi_ev_execute_reg_method(union acpi_operand_object *region_obj, u32 function)
219 info->prefix_node = region_obj2->extra.method_REG; 219 info->prefix_node = region_obj2->extra.method_REG;
220 info->pathname = NULL; 220 info->pathname = NULL;
221 info->parameters = args; 221 info->parameters = args;
222 info->parameter_type = ACPI_PARAM_ARGS;
223 info->flags = ACPI_IGNORE_RETURN_VALUE; 222 info->flags = ACPI_IGNORE_RETURN_VALUE;
224 223
225 /* 224 /*
diff --git a/drivers/acpi/events/evrgnini.c b/drivers/acpi/events/evrgnini.c
index 2e3d2c5e4f4d..6b94b38df07d 100644
--- a/drivers/acpi/events/evrgnini.c
+++ b/drivers/acpi/events/evrgnini.c
@@ -380,7 +380,7 @@ static u8 acpi_ev_is_pci_root_bridge(struct acpi_namespace_node *node)
380 acpi_status status; 380 acpi_status status;
381 struct acpica_device_id hid; 381 struct acpica_device_id hid;
382 struct acpi_compatible_id_list *cid; 382 struct acpi_compatible_id_list *cid;
383 acpi_native_uint i; 383 u32 i;
384 384
385 /* 385 /*
386 * Get the _HID and check for a PCI Root Bridge 386 * Get the _HID and check for a PCI Root Bridge
diff --git a/drivers/acpi/events/evxfevnt.c b/drivers/acpi/events/evxfevnt.c
index 99a7502e6a87..73bfd6bf962f 100644
--- a/drivers/acpi/events/evxfevnt.c
+++ b/drivers/acpi/events/evxfevnt.c
@@ -472,7 +472,6 @@ acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number, u32 flags)
472} 472}
473 473
474ACPI_EXPORT_SYMBOL(acpi_clear_gpe) 474ACPI_EXPORT_SYMBOL(acpi_clear_gpe)
475#ifdef ACPI_FUTURE_USAGE
476/******************************************************************************* 475/*******************************************************************************
477 * 476 *
478 * FUNCTION: acpi_get_event_status 477 * FUNCTION: acpi_get_event_status
@@ -489,6 +488,7 @@ ACPI_EXPORT_SYMBOL(acpi_clear_gpe)
489acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status) 488acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status)
490{ 489{
491 acpi_status status = AE_OK; 490 acpi_status status = AE_OK;
491 u32 value;
492 492
493 ACPI_FUNCTION_TRACE(acpi_get_event_status); 493 ACPI_FUNCTION_TRACE(acpi_get_event_status);
494 494
@@ -506,7 +506,20 @@ acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status)
506 506
507 status = 507 status =
508 acpi_get_register(acpi_gbl_fixed_event_info[event]. 508 acpi_get_register(acpi_gbl_fixed_event_info[event].
509 status_register_id, event_status); 509 enable_register_id, &value);
510 if (ACPI_FAILURE(status))
511 return_ACPI_STATUS(status);
512
513 *event_status = value;
514
515 status =
516 acpi_get_register(acpi_gbl_fixed_event_info[event].
517 status_register_id, &value);
518 if (ACPI_FAILURE(status))
519 return_ACPI_STATUS(status);
520
521 if (value)
522 *event_status |= ACPI_EVENT_FLAG_SET;
510 523
511 return_ACPI_STATUS(status); 524 return_ACPI_STATUS(status);
512} 525}
@@ -566,7 +579,6 @@ acpi_get_gpe_status(acpi_handle gpe_device,
566} 579}
567 580
568ACPI_EXPORT_SYMBOL(acpi_get_gpe_status) 581ACPI_EXPORT_SYMBOL(acpi_get_gpe_status)
569#endif /* ACPI_FUTURE_USAGE */
570/******************************************************************************* 582/*******************************************************************************
571 * 583 *
572 * FUNCTION: acpi_install_gpe_block 584 * FUNCTION: acpi_install_gpe_block
diff --git a/drivers/acpi/executer/exconfig.c b/drivers/acpi/executer/exconfig.c
index 39d742190584..2a32c843cb4a 100644
--- a/drivers/acpi/executer/exconfig.c
+++ b/drivers/acpi/executer/exconfig.c
@@ -53,7 +53,7 @@ ACPI_MODULE_NAME("exconfig")
53 53
54/* Local prototypes */ 54/* Local prototypes */
55static acpi_status 55static acpi_status
56acpi_ex_add_table(acpi_native_uint table_index, 56acpi_ex_add_table(u32 table_index,
57 struct acpi_namespace_node *parent_node, 57 struct acpi_namespace_node *parent_node,
58 union acpi_operand_object **ddb_handle); 58 union acpi_operand_object **ddb_handle);
59 59
@@ -73,7 +73,7 @@ acpi_ex_add_table(acpi_native_uint table_index,
73 ******************************************************************************/ 73 ******************************************************************************/
74 74
75static acpi_status 75static acpi_status
76acpi_ex_add_table(acpi_native_uint table_index, 76acpi_ex_add_table(u32 table_index,
77 struct acpi_namespace_node *parent_node, 77 struct acpi_namespace_node *parent_node,
78 union acpi_operand_object **ddb_handle) 78 union acpi_operand_object **ddb_handle)
79{ 79{
@@ -96,7 +96,8 @@ acpi_ex_add_table(acpi_native_uint table_index,
96 96
97 /* Install the new table into the local data structures */ 97 /* Install the new table into the local data structures */
98 98
99 obj_desc->reference.object = ACPI_CAST_PTR(void, table_index); 99 obj_desc->reference.object = ACPI_CAST_PTR(void,
100 (unsigned long)table_index);
100 101
101 /* Add the table to the namespace */ 102 /* Add the table to the namespace */
102 103
@@ -128,12 +129,12 @@ acpi_ex_load_table_op(struct acpi_walk_state *walk_state,
128{ 129{
129 acpi_status status; 130 acpi_status status;
130 union acpi_operand_object **operand = &walk_state->operands[0]; 131 union acpi_operand_object **operand = &walk_state->operands[0];
131 acpi_native_uint table_index;
132 struct acpi_namespace_node *parent_node; 132 struct acpi_namespace_node *parent_node;
133 struct acpi_namespace_node *start_node; 133 struct acpi_namespace_node *start_node;
134 struct acpi_namespace_node *parameter_node = NULL; 134 struct acpi_namespace_node *parameter_node = NULL;
135 union acpi_operand_object *ddb_handle; 135 union acpi_operand_object *ddb_handle;
136 struct acpi_table_header *table; 136 struct acpi_table_header *table;
137 u32 table_index;
137 138
138 ACPI_FUNCTION_TRACE(ex_load_table_op); 139 ACPI_FUNCTION_TRACE(ex_load_table_op);
139 140
@@ -280,7 +281,7 @@ acpi_ex_load_op(union acpi_operand_object *obj_desc,
280{ 281{
281 union acpi_operand_object *ddb_handle; 282 union acpi_operand_object *ddb_handle;
282 struct acpi_table_desc table_desc; 283 struct acpi_table_desc table_desc;
283 acpi_native_uint table_index; 284 u32 table_index;
284 acpi_status status; 285 acpi_status status;
285 u32 length; 286 u32 length;
286 287
@@ -437,7 +438,7 @@ acpi_status acpi_ex_unload_table(union acpi_operand_object *ddb_handle)
437{ 438{
438 acpi_status status = AE_OK; 439 acpi_status status = AE_OK;
439 union acpi_operand_object *table_desc = ddb_handle; 440 union acpi_operand_object *table_desc = ddb_handle;
440 acpi_native_uint table_index; 441 u32 table_index;
441 struct acpi_table_header *table; 442 struct acpi_table_header *table;
442 443
443 ACPI_FUNCTION_TRACE(ex_unload_table); 444 ACPI_FUNCTION_TRACE(ex_unload_table);
@@ -454,9 +455,9 @@ acpi_status acpi_ex_unload_table(union acpi_operand_object *ddb_handle)
454 return_ACPI_STATUS(AE_BAD_PARAMETER); 455 return_ACPI_STATUS(AE_BAD_PARAMETER);
455 } 456 }
456 457
457 /* Get the table index from the ddb_handle */ 458 /* Get the table index from the ddb_handle (acpi_size for 64-bit case) */
458 459
459 table_index = (acpi_native_uint) table_desc->reference.object; 460 table_index = (u32) (acpi_size) table_desc->reference.object;
460 461
461 /* Invoke table handler if present */ 462 /* Invoke table handler if present */
462 463
diff --git a/drivers/acpi/executer/exconvrt.c b/drivers/acpi/executer/exconvrt.c
index fd954b4ed83d..261d97516d9b 100644
--- a/drivers/acpi/executer/exconvrt.c
+++ b/drivers/acpi/executer/exconvrt.c
@@ -288,11 +288,11 @@ acpi_ex_convert_to_ascii(acpi_integer integer,
288 u16 base, u8 * string, u8 data_width) 288 u16 base, u8 * string, u8 data_width)
289{ 289{
290 acpi_integer digit; 290 acpi_integer digit;
291 acpi_native_uint i; 291 u32 i;
292 acpi_native_uint j; 292 u32 j;
293 acpi_native_uint k = 0; 293 u32 k = 0;
294 acpi_native_uint hex_length; 294 u32 hex_length;
295 acpi_native_uint decimal_length; 295 u32 decimal_length;
296 u32 remainder; 296 u32 remainder;
297 u8 supress_zeros; 297 u8 supress_zeros;
298 298
@@ -348,7 +348,7 @@ acpi_ex_convert_to_ascii(acpi_integer integer,
348 348
349 /* hex_length: 2 ascii hex chars per data byte */ 349 /* hex_length: 2 ascii hex chars per data byte */
350 350
351 hex_length = (acpi_native_uint) ACPI_MUL_2(data_width); 351 hex_length = ACPI_MUL_2(data_width);
352 for (i = 0, j = (hex_length - 1); i < hex_length; i++, j--) { 352 for (i = 0, j = (hex_length - 1); i < hex_length; i++, j--) {
353 353
354 /* Get one hex digit, most significant digits first */ 354 /* Get one hex digit, most significant digits first */
diff --git a/drivers/acpi/executer/excreate.c b/drivers/acpi/executer/excreate.c
index 60e62c4f0577..ad09696d5069 100644
--- a/drivers/acpi/executer/excreate.c
+++ b/drivers/acpi/executer/excreate.c
@@ -45,8 +45,6 @@
45#include <acpi/acinterp.h> 45#include <acpi/acinterp.h>
46#include <acpi/amlcode.h> 46#include <acpi/amlcode.h>
47#include <acpi/acnamesp.h> 47#include <acpi/acnamesp.h>
48#include <acpi/acevents.h>
49#include <acpi/actables.h>
50 48
51#define _COMPONENT ACPI_EXECUTER 49#define _COMPONENT ACPI_EXECUTER
52ACPI_MODULE_NAME("excreate") 50ACPI_MODULE_NAME("excreate")
diff --git a/drivers/acpi/executer/exdump.c b/drivers/acpi/executer/exdump.c
index 74f1b22601b3..2be2e2bf95bf 100644
--- a/drivers/acpi/executer/exdump.c
+++ b/drivers/acpi/executer/exdump.c
@@ -580,25 +580,22 @@ void acpi_ex_dump_operand(union acpi_operand_object *obj_desc, u32 depth)
580 580
581 case ACPI_TYPE_BUFFER: 581 case ACPI_TYPE_BUFFER:
582 582
583 acpi_os_printf("Buffer len %X @ %p\n", 583 acpi_os_printf("Buffer length %.2X @ %p\n",
584 obj_desc->buffer.length, 584 obj_desc->buffer.length,
585 obj_desc->buffer.pointer); 585 obj_desc->buffer.pointer);
586 586
587 length = obj_desc->buffer.length;
588 if (length > 64) {
589 length = 64;
590 }
591
592 /* Debug only -- dump the buffer contents */ 587 /* Debug only -- dump the buffer contents */
593 588
594 if (obj_desc->buffer.pointer) { 589 if (obj_desc->buffer.pointer) {
595 acpi_os_printf("Buffer Contents: "); 590 length = obj_desc->buffer.length;
596 591 if (length > 128) {
597 for (index = 0; index < length; index++) { 592 length = 128;
598 acpi_os_printf(" %02x",
599 obj_desc->buffer.pointer[index]);
600 } 593 }
601 acpi_os_printf("\n"); 594
595 acpi_os_printf
596 ("Buffer Contents: (displaying length 0x%.2X)\n",
597 length);
598 ACPI_DUMP_BUFFER(obj_desc->buffer.pointer, length);
602 } 599 }
603 break; 600 break;
604 601
@@ -756,54 +753,42 @@ void acpi_ex_dump_operand(union acpi_operand_object *obj_desc, u32 depth)
756 * 753 *
757 * FUNCTION: acpi_ex_dump_operands 754 * FUNCTION: acpi_ex_dump_operands
758 * 755 *
759 * PARAMETERS: Operands - Operand list 756 * PARAMETERS: Operands - A list of Operand objects
760 * interpreter_mode - Load or Exec 757 * opcode_name - AML opcode name
761 * Ident - Identification 758 * num_operands - Operand count for this opcode
762 * num_levels - # of stack entries to dump above line
763 * Note - Output notation
764 * module_name - Caller's module name
765 * line_number - Caller's invocation line number
766 * 759 *
767 * DESCRIPTION: Dump the object stack 760 * DESCRIPTION: Dump the operands associated with the opcode
768 * 761 *
769 ******************************************************************************/ 762 ******************************************************************************/
770 763
771void 764void
772acpi_ex_dump_operands(union acpi_operand_object **operands, 765acpi_ex_dump_operands(union acpi_operand_object **operands,
773 acpi_interpreter_mode interpreter_mode, 766 const char *opcode_name, u32 num_operands)
774 char *ident,
775 u32 num_levels,
776 char *note, char *module_name, u32 line_number)
777{ 767{
778 acpi_native_uint i;
779
780 ACPI_FUNCTION_NAME(ex_dump_operands); 768 ACPI_FUNCTION_NAME(ex_dump_operands);
781 769
782 if (!ident) { 770 if (!opcode_name) {
783 ident = "?"; 771 opcode_name = "UNKNOWN";
784 }
785
786 if (!note) {
787 note = "?";
788 } 772 }
789 773
790 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, 774 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
791 "************* Operand Stack Contents (Opcode [%s], %d Operands)\n", 775 "**** Start operand dump for opcode [%s], %d operands\n",
792 ident, num_levels)); 776 opcode_name, num_operands));
793 777
794 if (num_levels == 0) { 778 if (num_operands == 0) {
795 num_levels = 1; 779 num_operands = 1;
796 } 780 }
797 781
798 /* Dump the operand stack starting at the top */ 782 /* Dump the individual operands */
799 783
800 for (i = 0; num_levels > 0; i--, num_levels--) { 784 while (num_operands) {
801 acpi_ex_dump_operand(operands[i], 0); 785 acpi_ex_dump_operand(*operands, 0);
786 operands++;
787 num_operands--;
802 } 788 }
803 789
804 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, 790 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
805 "************* Operand Stack dump from %s(%d), %s\n", 791 "**** End operand dump for [%s]\n", opcode_name));
806 module_name, line_number, note));
807 return; 792 return;
808} 793}
809 794
diff --git a/drivers/acpi/executer/exfldio.c b/drivers/acpi/executer/exfldio.c
index e336b5dc7a50..9ff9d1f4615d 100644
--- a/drivers/acpi/executer/exfldio.c
+++ b/drivers/acpi/executer/exfldio.c
@@ -153,14 +153,15 @@ acpi_ex_setup_region(union acpi_operand_object *obj_desc,
153 /* 153 /*
154 * Slack mode only: We will go ahead and allow access to this 154 * Slack mode only: We will go ahead and allow access to this
155 * field if it is within the region length rounded up to the next 155 * field if it is within the region length rounded up to the next
156 * access width boundary. 156 * access width boundary. acpi_size cast for 64-bit compile.
157 */ 157 */
158 if (ACPI_ROUND_UP(rgn_desc->region.length, 158 if (ACPI_ROUND_UP(rgn_desc->region.length,
159 obj_desc->common_field. 159 obj_desc->common_field.
160 access_byte_width) >= 160 access_byte_width) >=
161 (obj_desc->common_field.base_byte_offset + 161 ((acpi_size) obj_desc->common_field.
162 (acpi_native_uint) obj_desc->common_field. 162 base_byte_offset +
163 access_byte_width + field_datum_byte_offset)) { 163 obj_desc->common_field.access_byte_width +
164 field_datum_byte_offset)) {
164 return_ACPI_STATUS(AE_OK); 165 return_ACPI_STATUS(AE_OK);
165 } 166 }
166 } 167 }
diff --git a/drivers/acpi/executer/exmisc.c b/drivers/acpi/executer/exmisc.c
index cc956a5b5267..731414a581a6 100644
--- a/drivers/acpi/executer/exmisc.c
+++ b/drivers/acpi/executer/exmisc.c
@@ -329,8 +329,8 @@ acpi_ex_do_concatenate(union acpi_operand_object *operand0,
329 329
330 /* Result of two Strings is a String */ 330 /* Result of two Strings is a String */
331 331
332 return_desc = acpi_ut_create_string_object((acpi_size) 332 return_desc = acpi_ut_create_string_object(((acpi_size)
333 (operand0->string. 333 operand0->string.
334 length + 334 length +
335 local_operand1-> 335 local_operand1->
336 string.length)); 336 string.length));
@@ -352,8 +352,8 @@ acpi_ex_do_concatenate(union acpi_operand_object *operand0,
352 352
353 /* Result of two Buffers is a Buffer */ 353 /* Result of two Buffers is a Buffer */
354 354
355 return_desc = acpi_ut_create_buffer_object((acpi_size) 355 return_desc = acpi_ut_create_buffer_object(((acpi_size)
356 (operand0->buffer. 356 operand0->buffer.
357 length + 357 length +
358 local_operand1-> 358 local_operand1->
359 buffer.length)); 359 buffer.length));
diff --git a/drivers/acpi/executer/exprep.c b/drivers/acpi/executer/exprep.c
index 3a2f8cd4c62a..5d438c32989d 100644
--- a/drivers/acpi/executer/exprep.c
+++ b/drivers/acpi/executer/exprep.c
@@ -503,11 +503,11 @@ acpi_status acpi_ex_prep_field_value(struct acpi_create_field_info *info)
503 */ 503 */
504 second_desc = obj_desc->common.next_object; 504 second_desc = obj_desc->common.next_object;
505 second_desc->extra.aml_start = 505 second_desc->extra.aml_start =
506 ((union acpi_parse_object *)(info->data_register_node))-> 506 ACPI_CAST_PTR(union acpi_parse_object,
507 named.data; 507 info->data_register_node)->named.data;
508 second_desc->extra.aml_length = 508 second_desc->extra.aml_length =
509 ((union acpi_parse_object *)(info->data_register_node))-> 509 ACPI_CAST_PTR(union acpi_parse_object,
510 named.length; 510 info->data_register_node)->named.length;
511 511
512 break; 512 break;
513 513
diff --git a/drivers/acpi/executer/exregion.c b/drivers/acpi/executer/exregion.c
index 7cd8bb54fa01..7a41c409ae4d 100644
--- a/drivers/acpi/executer/exregion.c
+++ b/drivers/acpi/executer/exregion.c
@@ -156,7 +156,7 @@ acpi_ex_system_memory_space_handler(u32 function,
156 /* Create a new mapping starting at the address given */ 156 /* Create a new mapping starting at the address given */
157 157
158 mem_info->mapped_logical_address = 158 mem_info->mapped_logical_address =
159 acpi_os_map_memory((acpi_native_uint) address, window_size); 159 acpi_os_map_memory((acpi_physical_address) address, window_size);
160 if (!mem_info->mapped_logical_address) { 160 if (!mem_info->mapped_logical_address) {
161 ACPI_ERROR((AE_INFO, 161 ACPI_ERROR((AE_INFO,
162 "Could not map memory at %8.8X%8.8X, size %X", 162 "Could not map memory at %8.8X%8.8X, size %X",
diff --git a/drivers/acpi/executer/exresop.c b/drivers/acpi/executer/exresop.c
index 73e29e566a70..54085f16ec28 100644
--- a/drivers/acpi/executer/exresop.c
+++ b/drivers/acpi/executer/exresop.c
@@ -698,5 +698,9 @@ acpi_ex_resolve_operands(u16 opcode,
698 } 698 }
699 } 699 }
700 700
701 ACPI_DUMP_OPERANDS(walk_state->operands,
702 acpi_ps_get_opcode_name(opcode),
703 walk_state->num_operands);
704
701 return_ACPI_STATUS(status); 705 return_ACPI_STATUS(status);
702} 706}
diff --git a/drivers/acpi/executer/exstore.c b/drivers/acpi/executer/exstore.c
index 76c875bc3154..38b55e352495 100644
--- a/drivers/acpi/executer/exstore.c
+++ b/drivers/acpi/executer/exstore.c
@@ -343,12 +343,6 @@ acpi_ex_store(union acpi_operand_object *source_desc,
343 acpi_ut_get_object_type_name(dest_desc), 343 acpi_ut_get_object_type_name(dest_desc),
344 dest_desc)); 344 dest_desc));
345 345
346 ACPI_DUMP_STACK_ENTRY(source_desc);
347 ACPI_DUMP_STACK_ENTRY(dest_desc);
348 ACPI_DUMP_OPERANDS(&dest_desc, ACPI_IMODE_EXECUTE, "ExStore",
349 2,
350 "Target is not a Reference or Constant object");
351
352 return_ACPI_STATUS(AE_AML_OPERAND_TYPE); 346 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
353 } 347 }
354 348
diff --git a/drivers/acpi/fan.c b/drivers/acpi/fan.c
index 6cf10cbc1eee..55c17afbe669 100644
--- a/drivers/acpi/fan.c
+++ b/drivers/acpi/fan.c
@@ -148,7 +148,7 @@ acpi_fan_write_state(struct file *file, const char __user * buffer,
148 int result = 0; 148 int result = 0;
149 struct seq_file *m = file->private_data; 149 struct seq_file *m = file->private_data;
150 struct acpi_device *device = m->private; 150 struct acpi_device *device = m->private;
151 char state_string[12] = { '\0' }; 151 char state_string[3] = { '\0' };
152 152
153 if (count > sizeof(state_string) - 1) 153 if (count > sizeof(state_string) - 1)
154 return -EINVAL; 154 return -EINVAL;
@@ -157,6 +157,12 @@ acpi_fan_write_state(struct file *file, const char __user * buffer,
157 return -EFAULT; 157 return -EFAULT;
158 158
159 state_string[count] = '\0'; 159 state_string[count] = '\0';
160 if ((state_string[0] < '0') || (state_string[0] > '3'))
161 return -EINVAL;
162 if (state_string[1] == '\n')
163 state_string[1] = '\0';
164 if (state_string[1] != '\0')
165 return -EINVAL;
160 166
161 result = acpi_bus_set_power(device->handle, 167 result = acpi_bus_set_power(device->handle,
162 simple_strtoul(state_string, NULL, 0)); 168 simple_strtoul(state_string, NULL, 0));
diff --git a/drivers/acpi/glue.c b/drivers/acpi/glue.c
index 9b227d4dc9c9..6d18ca34b6aa 100644
--- a/drivers/acpi/glue.c
+++ b/drivers/acpi/glue.c
@@ -336,6 +336,9 @@ static int __init acpi_rtc_init(void)
336 if (acpi_disabled) 336 if (acpi_disabled)
337 return 0; 337 return 0;
338 338
339 if (acpi_disabled)
340 return 0;
341
339 if (dev) { 342 if (dev) {
340 rtc_wake_setup(); 343 rtc_wake_setup();
341 rtc_info.wake_on = rtc_wake_on; 344 rtc_info.wake_on = rtc_wake_on;
diff --git a/drivers/acpi/hardware/hwgpe.c b/drivers/acpi/hardware/hwgpe.c
index 14bc4f456ae8..0b80db9d9197 100644
--- a/drivers/acpi/hardware/hwgpe.c
+++ b/drivers/acpi/hardware/hwgpe.c
@@ -55,6 +55,54 @@ acpi_hw_enable_wakeup_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
55 55
56/****************************************************************************** 56/******************************************************************************
57 * 57 *
58 * FUNCTION: acpi_hw_low_disable_gpe
59 *
60 * PARAMETERS: gpe_event_info - Info block for the GPE to be disabled
61 *
62 * RETURN: Status
63 *
64 * DESCRIPTION: Disable a single GPE in the enable register.
65 *
66 ******************************************************************************/
67
68acpi_status acpi_hw_low_disable_gpe(struct acpi_gpe_event_info *gpe_event_info)
69{
70 struct acpi_gpe_register_info *gpe_register_info;
71 acpi_status status;
72 u32 enable_mask;
73
74 /* Get the info block for the entire GPE register */
75
76 gpe_register_info = gpe_event_info->register_info;
77 if (!gpe_register_info) {
78 return (AE_NOT_EXIST);
79 }
80
81 /* Get current value of the enable register that contains this GPE */
82
83 status = acpi_hw_low_level_read(ACPI_GPE_REGISTER_WIDTH, &enable_mask,
84 &gpe_register_info->enable_address);
85 if (ACPI_FAILURE(status)) {
86 return (status);
87 }
88
89 /* Clear just the bit that corresponds to this GPE */
90
91 ACPI_CLEAR_BIT(enable_mask,
92 ((u32) 1 <<
93 (gpe_event_info->gpe_number -
94 gpe_register_info->base_gpe_number)));
95
96 /* Write the updated enable mask */
97
98 status = acpi_hw_low_level_write(ACPI_GPE_REGISTER_WIDTH, enable_mask,
99 &gpe_register_info->enable_address);
100
101 return (status);
102}
103
104/******************************************************************************
105 *
58 * FUNCTION: acpi_hw_write_gpe_enable_reg 106 * FUNCTION: acpi_hw_write_gpe_enable_reg
59 * 107 *
60 * PARAMETERS: gpe_event_info - Info block for the GPE to be enabled 108 * PARAMETERS: gpe_event_info - Info block for the GPE to be enabled
@@ -68,7 +116,7 @@ acpi_hw_enable_wakeup_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
68 ******************************************************************************/ 116 ******************************************************************************/
69 117
70acpi_status 118acpi_status
71acpi_hw_write_gpe_enable_reg(struct acpi_gpe_event_info *gpe_event_info) 119acpi_hw_write_gpe_enable_reg(struct acpi_gpe_event_info * gpe_event_info)
72{ 120{
73 struct acpi_gpe_register_info *gpe_register_info; 121 struct acpi_gpe_register_info *gpe_register_info;
74 acpi_status status; 122 acpi_status status;
@@ -138,7 +186,6 @@ acpi_status acpi_hw_clear_gpe(struct acpi_gpe_event_info * gpe_event_info)
138 * 186 *
139 ******************************************************************************/ 187 ******************************************************************************/
140 188
141#ifdef ACPI_FUTURE_USAGE
142acpi_status 189acpi_status
143acpi_hw_get_gpe_status(struct acpi_gpe_event_info * gpe_event_info, 190acpi_hw_get_gpe_status(struct acpi_gpe_event_info * gpe_event_info,
144 acpi_event_status * event_status) 191 acpi_event_status * event_status)
@@ -198,7 +245,6 @@ acpi_hw_get_gpe_status(struct acpi_gpe_event_info * gpe_event_info,
198 unlock_and_exit: 245 unlock_and_exit:
199 return (status); 246 return (status);
200} 247}
201#endif /* ACPI_FUTURE_USAGE */
202 248
203/****************************************************************************** 249/******************************************************************************
204 * 250 *
diff --git a/drivers/acpi/namespace/nsdump.c b/drivers/acpi/namespace/nsdump.c
index 5445751b8a3e..0ab22004728a 100644
--- a/drivers/acpi/namespace/nsdump.c
+++ b/drivers/acpi/namespace/nsdump.c
@@ -73,7 +73,7 @@ acpi_ns_dump_one_device(acpi_handle obj_handle,
73 73
74void acpi_ns_print_pathname(u32 num_segments, char *pathname) 74void acpi_ns_print_pathname(u32 num_segments, char *pathname)
75{ 75{
76 acpi_native_uint i; 76 u32 i;
77 77
78 ACPI_FUNCTION_NAME(ns_print_pathname); 78 ACPI_FUNCTION_NAME(ns_print_pathname);
79 79
@@ -515,12 +515,12 @@ acpi_ns_dump_one_object(acpi_handle obj_handle,
515 515
516 if (obj_type > ACPI_TYPE_LOCAL_MAX) { 516 if (obj_type > ACPI_TYPE_LOCAL_MAX) {
517 acpi_os_printf 517 acpi_os_printf
518 ("(Ptr to ACPI Object type %X [UNKNOWN])\n", 518 ("(Pointer to ACPI Object type %.2X [UNKNOWN])\n",
519 obj_type); 519 obj_type);
520 bytes_to_dump = 32; 520 bytes_to_dump = 32;
521 } else { 521 } else {
522 acpi_os_printf 522 acpi_os_printf
523 ("(Ptr to ACPI Object type %X [%s])\n", 523 ("(Pointer to ACPI Object type %.2X [%s])\n",
524 obj_type, acpi_ut_get_type_name(obj_type)); 524 obj_type, acpi_ut_get_type_name(obj_type));
525 bytes_to_dump = 525 bytes_to_dump =
526 sizeof(union acpi_operand_object); 526 sizeof(union acpi_operand_object);
diff --git a/drivers/acpi/namespace/nseval.c b/drivers/acpi/namespace/nseval.c
index 14bdfa92bea0..d369164e00b0 100644
--- a/drivers/acpi/namespace/nseval.c
+++ b/drivers/acpi/namespace/nseval.c
@@ -138,6 +138,41 @@ acpi_status acpi_ns_evaluate(struct acpi_evaluate_info * info)
138 return_ACPI_STATUS(AE_NULL_OBJECT); 138 return_ACPI_STATUS(AE_NULL_OBJECT);
139 } 139 }
140 140
141 /*
142 * Calculate the number of arguments being passed to the method
143 */
144
145 info->param_count = 0;
146 if (info->parameters) {
147 while (info->parameters[info->param_count])
148 info->param_count++;
149 }
150
151 /* Error if too few arguments were passed in */
152
153 if (info->param_count < info->obj_desc->method.param_count) {
154 ACPI_ERROR((AE_INFO,
155 "Insufficient arguments - "
156 "method [%4.4s] needs %d, found %d",
157 acpi_ut_get_node_name(info->resolved_node),
158 info->obj_desc->method.param_count,
159 info->param_count));
160 return_ACPI_STATUS(AE_MISSING_ARGUMENTS);
161 }
162
163 /* Just a warning if too many arguments */
164
165 else if (info->param_count >
166 info->obj_desc->method.param_count) {
167 ACPI_WARNING((AE_INFO,
168 "Excess arguments - "
169 "method [%4.4s] needs %d, found %d",
170 acpi_ut_get_node_name(info->
171 resolved_node),
172 info->obj_desc->method.param_count,
173 info->param_count));
174 }
175
141 ACPI_DUMP_PATHNAME(info->resolved_node, "Execute Method:", 176 ACPI_DUMP_PATHNAME(info->resolved_node, "Execute Method:",
142 ACPI_LV_INFO, _COMPONENT); 177 ACPI_LV_INFO, _COMPONENT);
143 178
diff --git a/drivers/acpi/namespace/nsinit.c b/drivers/acpi/namespace/nsinit.c
index 6d6d930c8e18..e4c57510d798 100644
--- a/drivers/acpi/namespace/nsinit.c
+++ b/drivers/acpi/namespace/nsinit.c
@@ -542,7 +542,6 @@ acpi_ns_init_one_device(acpi_handle obj_handle,
542 info->prefix_node = device_node; 542 info->prefix_node = device_node;
543 info->pathname = METHOD_NAME__INI; 543 info->pathname = METHOD_NAME__INI;
544 info->parameters = NULL; 544 info->parameters = NULL;
545 info->parameter_type = ACPI_PARAM_ARGS;
546 info->flags = ACPI_IGNORE_RETURN_VALUE; 545 info->flags = ACPI_IGNORE_RETURN_VALUE;
547 546
548 /* 547 /*
diff --git a/drivers/acpi/namespace/nsload.c b/drivers/acpi/namespace/nsload.c
index 2c92f6cf5ce1..a4a412b7c029 100644
--- a/drivers/acpi/namespace/nsload.c
+++ b/drivers/acpi/namespace/nsload.c
@@ -71,8 +71,7 @@ static acpi_status acpi_ns_delete_subtree(acpi_handle start_handle);
71 ******************************************************************************/ 71 ******************************************************************************/
72 72
73acpi_status 73acpi_status
74acpi_ns_load_table(acpi_native_uint table_index, 74acpi_ns_load_table(u32 table_index, struct acpi_namespace_node *node)
75 struct acpi_namespace_node *node)
76{ 75{
77 acpi_status status; 76 acpi_status status;
78 77
diff --git a/drivers/acpi/namespace/nsparse.c b/drivers/acpi/namespace/nsparse.c
index 46a79b0103b6..a82271a9dbb3 100644
--- a/drivers/acpi/namespace/nsparse.c
+++ b/drivers/acpi/namespace/nsparse.c
@@ -63,13 +63,13 @@ ACPI_MODULE_NAME("nsparse")
63 * 63 *
64 ******************************************************************************/ 64 ******************************************************************************/
65acpi_status 65acpi_status
66acpi_ns_one_complete_parse(acpi_native_uint pass_number, 66acpi_ns_one_complete_parse(u32 pass_number,
67 acpi_native_uint table_index, 67 u32 table_index,
68 struct acpi_namespace_node * start_node) 68 struct acpi_namespace_node *start_node)
69{ 69{
70 union acpi_parse_object *parse_root; 70 union acpi_parse_object *parse_root;
71 acpi_status status; 71 acpi_status status;
72 acpi_native_uint aml_length; 72 u32 aml_length;
73 u8 *aml_start; 73 u8 *aml_start;
74 struct acpi_walk_state *walk_state; 74 struct acpi_walk_state *walk_state;
75 struct acpi_table_header *table; 75 struct acpi_table_header *table;
@@ -112,8 +112,8 @@ acpi_ns_one_complete_parse(acpi_native_uint pass_number,
112 aml_start = (u8 *) table + sizeof(struct acpi_table_header); 112 aml_start = (u8 *) table + sizeof(struct acpi_table_header);
113 aml_length = table->length - sizeof(struct acpi_table_header); 113 aml_length = table->length - sizeof(struct acpi_table_header);
114 status = acpi_ds_init_aml_walk(walk_state, parse_root, NULL, 114 status = acpi_ds_init_aml_walk(walk_state, parse_root, NULL,
115 aml_start, (u32) aml_length, 115 aml_start, aml_length, NULL,
116 NULL, (u8) pass_number); 116 (u8) pass_number);
117 } 117 }
118 118
119 if (ACPI_FAILURE(status)) { 119 if (ACPI_FAILURE(status)) {
@@ -158,8 +158,7 @@ acpi_ns_one_complete_parse(acpi_native_uint pass_number,
158 ******************************************************************************/ 158 ******************************************************************************/
159 159
160acpi_status 160acpi_status
161acpi_ns_parse_table(acpi_native_uint table_index, 161acpi_ns_parse_table(u32 table_index, struct acpi_namespace_node *start_node)
162 struct acpi_namespace_node *start_node)
163{ 162{
164 acpi_status status; 163 acpi_status status;
165 164
diff --git a/drivers/acpi/namespace/nsutils.c b/drivers/acpi/namespace/nsutils.c
index 64c039843ed2..b0817e1127b1 100644
--- a/drivers/acpi/namespace/nsutils.c
+++ b/drivers/acpi/namespace/nsutils.c
@@ -73,9 +73,9 @@ acpi_name acpi_ns_find_parent_name(struct acpi_namespace_node *node_to_search);
73 ******************************************************************************/ 73 ******************************************************************************/
74 74
75void 75void
76acpi_ns_report_error(char *module_name, 76acpi_ns_report_error(const char *module_name,
77 u32 line_number, 77 u32 line_number,
78 char *internal_name, acpi_status lookup_status) 78 const char *internal_name, acpi_status lookup_status)
79{ 79{
80 acpi_status status; 80 acpi_status status;
81 u32 bad_name; 81 u32 bad_name;
@@ -130,11 +130,11 @@ acpi_ns_report_error(char *module_name,
130 ******************************************************************************/ 130 ******************************************************************************/
131 131
132void 132void
133acpi_ns_report_method_error(char *module_name, 133acpi_ns_report_method_error(const char *module_name,
134 u32 line_number, 134 u32 line_number,
135 char *message, 135 const char *message,
136 struct acpi_namespace_node *prefix_node, 136 struct acpi_namespace_node *prefix_node,
137 char *path, acpi_status method_status) 137 const char *path, acpi_status method_status)
138{ 138{
139 acpi_status status; 139 acpi_status status;
140 struct acpi_namespace_node *node = prefix_node; 140 struct acpi_namespace_node *node = prefix_node;
@@ -167,7 +167,8 @@ acpi_ns_report_method_error(char *module_name,
167 ******************************************************************************/ 167 ******************************************************************************/
168 168
169void 169void
170acpi_ns_print_node_pathname(struct acpi_namespace_node *node, char *message) 170acpi_ns_print_node_pathname(struct acpi_namespace_node *node,
171 const char *message)
171{ 172{
172 struct acpi_buffer buffer; 173 struct acpi_buffer buffer;
173 acpi_status status; 174 acpi_status status;
@@ -296,7 +297,7 @@ u32 acpi_ns_local(acpi_object_type type)
296 297
297void acpi_ns_get_internal_name_length(struct acpi_namestring_info *info) 298void acpi_ns_get_internal_name_length(struct acpi_namestring_info *info)
298{ 299{
299 char *next_external_char; 300 const char *next_external_char;
300 u32 i; 301 u32 i;
301 302
302 ACPI_FUNCTION_ENTRY(); 303 ACPI_FUNCTION_ENTRY();
@@ -363,9 +364,9 @@ acpi_status acpi_ns_build_internal_name(struct acpi_namestring_info *info)
363{ 364{
364 u32 num_segments = info->num_segments; 365 u32 num_segments = info->num_segments;
365 char *internal_name = info->internal_name; 366 char *internal_name = info->internal_name;
366 char *external_name = info->next_external_char; 367 const char *external_name = info->next_external_char;
367 char *result = NULL; 368 char *result = NULL;
368 acpi_native_uint i; 369 u32 i;
369 370
370 ACPI_FUNCTION_TRACE(ns_build_internal_name); 371 ACPI_FUNCTION_TRACE(ns_build_internal_name);
371 372
@@ -400,12 +401,11 @@ acpi_status acpi_ns_build_internal_name(struct acpi_namestring_info *info)
400 result = &internal_name[i]; 401 result = &internal_name[i];
401 } else if (num_segments == 2) { 402 } else if (num_segments == 2) {
402 internal_name[i] = AML_DUAL_NAME_PREFIX; 403 internal_name[i] = AML_DUAL_NAME_PREFIX;
403 result = &internal_name[(acpi_native_uint) (i + 1)]; 404 result = &internal_name[(acpi_size) i + 1];
404 } else { 405 } else {
405 internal_name[i] = AML_MULTI_NAME_PREFIX_OP; 406 internal_name[i] = AML_MULTI_NAME_PREFIX_OP;
406 internal_name[(acpi_native_uint) (i + 1)] = 407 internal_name[(acpi_size) i + 1] = (char)num_segments;
407 (char)num_segments; 408 result = &internal_name[(acpi_size) i + 2];
408 result = &internal_name[(acpi_native_uint) (i + 2)];
409 } 409 }
410 } 410 }
411 411
@@ -472,7 +472,8 @@ acpi_status acpi_ns_build_internal_name(struct acpi_namestring_info *info)
472 * 472 *
473 *******************************************************************************/ 473 *******************************************************************************/
474 474
475acpi_status acpi_ns_internalize_name(char *external_name, char **converted_name) 475acpi_status
476acpi_ns_internalize_name(const char *external_name, char **converted_name)
476{ 477{
477 char *internal_name; 478 char *internal_name;
478 struct acpi_namestring_info info; 479 struct acpi_namestring_info info;
@@ -528,15 +529,15 @@ acpi_status acpi_ns_internalize_name(char *external_name, char **converted_name)
528 529
529acpi_status 530acpi_status
530acpi_ns_externalize_name(u32 internal_name_length, 531acpi_ns_externalize_name(u32 internal_name_length,
531 char *internal_name, 532 const char *internal_name,
532 u32 * converted_name_length, char **converted_name) 533 u32 * converted_name_length, char **converted_name)
533{ 534{
534 acpi_native_uint names_index = 0; 535 u32 names_index = 0;
535 acpi_native_uint num_segments = 0; 536 u32 num_segments = 0;
536 acpi_native_uint required_length; 537 u32 required_length;
537 acpi_native_uint prefix_length = 0; 538 u32 prefix_length = 0;
538 acpi_native_uint i = 0; 539 u32 i = 0;
539 acpi_native_uint j = 0; 540 u32 j = 0;
540 541
541 ACPI_FUNCTION_TRACE(ns_externalize_name); 542 ACPI_FUNCTION_TRACE(ns_externalize_name);
542 543
@@ -582,9 +583,8 @@ acpi_ns_externalize_name(u32 internal_name_length,
582 /* <count> 4-byte names */ 583 /* <count> 4-byte names */
583 584
584 names_index = prefix_length + 2; 585 names_index = prefix_length + 2;
585 num_segments = (acpi_native_uint) (u8) 586 num_segments = (u8)
586 internal_name[(acpi_native_uint) 587 internal_name[(acpi_size) prefix_length + 1];
587 (prefix_length + 1)];
588 break; 588 break;
589 589
590 case AML_DUAL_NAME_PREFIX: 590 case AML_DUAL_NAME_PREFIX:
@@ -823,7 +823,7 @@ u32 acpi_ns_opens_scope(acpi_object_type type)
823 823
824acpi_status 824acpi_status
825acpi_ns_get_node(struct acpi_namespace_node *prefix_node, 825acpi_ns_get_node(struct acpi_namespace_node *prefix_node,
826 char *pathname, 826 const char *pathname,
827 u32 flags, struct acpi_namespace_node **return_node) 827 u32 flags, struct acpi_namespace_node **return_node)
828{ 828{
829 union acpi_generic_state scope_info; 829 union acpi_generic_state scope_info;
diff --git a/drivers/acpi/namespace/nsxfeval.c b/drivers/acpi/namespace/nsxfeval.c
index a8d549187c84..38be5865d95d 100644
--- a/drivers/acpi/namespace/nsxfeval.c
+++ b/drivers/acpi/namespace/nsxfeval.c
@@ -182,7 +182,6 @@ acpi_evaluate_object(acpi_handle handle,
182 } 182 }
183 183
184 info->pathname = pathname; 184 info->pathname = pathname;
185 info->parameter_type = ACPI_PARAM_ARGS;
186 185
187 /* Convert and validate the device handle */ 186 /* Convert and validate the device handle */
188 187
@@ -442,7 +441,7 @@ acpi_ns_get_device_callback(acpi_handle obj_handle,
442 u32 flags; 441 u32 flags;
443 struct acpica_device_id hid; 442 struct acpica_device_id hid;
444 struct acpi_compatible_id_list *cid; 443 struct acpi_compatible_id_list *cid;
445 acpi_native_uint i; 444 u32 i;
446 int found; 445 int found;
447 446
448 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); 447 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
diff --git a/drivers/acpi/numa.c b/drivers/acpi/numa.c
index 658e5f3abae0..cb9864e39bae 100644
--- a/drivers/acpi/numa.c
+++ b/drivers/acpi/numa.c
@@ -120,10 +120,10 @@ acpi_table_print_srat_entry(struct acpi_subtable_header *header)
120 struct acpi_srat_mem_affinity *p = 120 struct acpi_srat_mem_affinity *p =
121 (struct acpi_srat_mem_affinity *)header; 121 (struct acpi_srat_mem_affinity *)header;
122 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 122 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
123 "SRAT Memory (0x%lx length 0x%lx type 0x%x) in proximity domain %d %s%s\n", 123 "SRAT Memory (0x%lx length 0x%lx) in proximity domain %d %s%s\n",
124 (unsigned long)p->base_address, 124 (unsigned long)p->base_address,
125 (unsigned long)p->length, 125 (unsigned long)p->length,
126 p->memory_type, p->proximity_domain, 126 p->proximity_domain,
127 (p->flags & ACPI_SRAT_MEM_ENABLED)? 127 (p->flags & ACPI_SRAT_MEM_ENABLED)?
128 "enabled" : "disabled", 128 "enabled" : "disabled",
129 (p->flags & ACPI_SRAT_MEM_HOT_PLUGGABLE)? 129 (p->flags & ACPI_SRAT_MEM_HOT_PLUGGABLE)?
diff --git a/drivers/acpi/parser/psargs.c b/drivers/acpi/parser/psargs.c
index e94463778845..d830b29b85b1 100644
--- a/drivers/acpi/parser/psargs.c
+++ b/drivers/acpi/parser/psargs.c
@@ -76,7 +76,7 @@ acpi_ps_get_next_package_length(struct acpi_parse_state *parser_state)
76{ 76{
77 u8 *aml = parser_state->aml; 77 u8 *aml = parser_state->aml;
78 u32 package_length = 0; 78 u32 package_length = 0;
79 acpi_native_uint byte_count; 79 u32 byte_count;
80 u8 byte_zero_mask = 0x3F; /* Default [0:5] */ 80 u8 byte_zero_mask = 0x3F; /* Default [0:5] */
81 81
82 ACPI_FUNCTION_TRACE(ps_get_next_package_length); 82 ACPI_FUNCTION_TRACE(ps_get_next_package_length);
@@ -86,7 +86,7 @@ acpi_ps_get_next_package_length(struct acpi_parse_state *parser_state)
86 * used to encode the package length, either 0,1,2, or 3 86 * used to encode the package length, either 0,1,2, or 3
87 */ 87 */
88 byte_count = (aml[0] >> 6); 88 byte_count = (aml[0] >> 6);
89 parser_state->aml += (byte_count + 1); 89 parser_state->aml += ((acpi_size) byte_count + 1);
90 90
91 /* Get bytes 3, 2, 1 as needed */ 91 /* Get bytes 3, 2, 1 as needed */
92 92
diff --git a/drivers/acpi/parser/psxface.c b/drivers/acpi/parser/psxface.c
index 52581454c47c..270469aae842 100644
--- a/drivers/acpi/parser/psxface.c
+++ b/drivers/acpi/parser/psxface.c
@@ -333,9 +333,9 @@ acpi_status acpi_ps_execute_method(struct acpi_evaluate_info *info)
333static void 333static void
334acpi_ps_update_parameter_list(struct acpi_evaluate_info *info, u16 action) 334acpi_ps_update_parameter_list(struct acpi_evaluate_info *info, u16 action)
335{ 335{
336 acpi_native_uint i; 336 u32 i;
337 337
338 if ((info->parameter_type == ACPI_PARAM_ARGS) && (info->parameters)) { 338 if (info->parameters) {
339 339
340 /* Update reference count for each parameter */ 340 /* Update reference count for each parameter */
341 341
diff --git a/drivers/acpi/pci_irq.c b/drivers/acpi/pci_irq.c
index 89022a74faee..11acaee14d66 100644
--- a/drivers/acpi/pci_irq.c
+++ b/drivers/acpi/pci_irq.c
@@ -162,7 +162,7 @@ do_prt_fixups(struct acpi_prt_entry *entry, struct acpi_pci_routing_table *prt)
162 !strcmp(prt->source, quirk->source) && 162 !strcmp(prt->source, quirk->source) &&
163 strlen(prt->source) >= strlen(quirk->actual_source)) { 163 strlen(prt->source) >= strlen(quirk->actual_source)) {
164 printk(KERN_WARNING PREFIX "firmware reports " 164 printk(KERN_WARNING PREFIX "firmware reports "
165 "%04x:%02x:%02x[%c] connected to %s; " 165 "%04x:%02x:%02x PCI INT %c connected to %s; "
166 "changing to %s\n", 166 "changing to %s\n",
167 entry->id.segment, entry->id.bus, 167 entry->id.segment, entry->id.bus,
168 entry->id.device, 'A' + entry->pin, 168 entry->id.device, 'A' + entry->pin,
@@ -429,7 +429,7 @@ acpi_pci_irq_derive(struct pci_dev *dev,
429{ 429{
430 struct pci_dev *bridge = dev; 430 struct pci_dev *bridge = dev;
431 int irq = -1; 431 int irq = -1;
432 u8 bridge_pin = 0; 432 u8 bridge_pin = 0, orig_pin = pin;
433 433
434 434
435 if (!dev) 435 if (!dev)
@@ -463,8 +463,8 @@ acpi_pci_irq_derive(struct pci_dev *dev,
463 } 463 }
464 464
465 if (irq < 0) { 465 if (irq < 0) {
466 printk(KERN_WARNING PREFIX "Unable to derive IRQ for device %s\n", 466 dev_warn(&dev->dev, "can't derive routing for PCI INT %c\n",
467 pci_name(dev)); 467 'A' + orig_pin);
468 return -1; 468 return -1;
469 } 469 }
470 470
@@ -487,6 +487,7 @@ int acpi_pci_irq_enable(struct pci_dev *dev)
487 int triggering = ACPI_LEVEL_SENSITIVE; 487 int triggering = ACPI_LEVEL_SENSITIVE;
488 int polarity = ACPI_ACTIVE_LOW; 488 int polarity = ACPI_ACTIVE_LOW;
489 char *link = NULL; 489 char *link = NULL;
490 char link_desc[16];
490 int rc; 491 int rc;
491 492
492 493
@@ -503,7 +504,7 @@ int acpi_pci_irq_enable(struct pci_dev *dev)
503 pin--; 504 pin--;
504 505
505 if (!dev->bus) { 506 if (!dev->bus) {
506 printk(KERN_ERR PREFIX "Invalid (NULL) 'bus' field\n"); 507 dev_err(&dev->dev, "invalid (NULL) 'bus' field\n");
507 return -ENODEV; 508 return -ENODEV;
508 } 509 }
509 510
@@ -538,8 +539,7 @@ int acpi_pci_irq_enable(struct pci_dev *dev)
538 * driver reported one, then use it. Exit in any case. 539 * driver reported one, then use it. Exit in any case.
539 */ 540 */
540 if (irq < 0) { 541 if (irq < 0) {
541 printk(KERN_WARNING PREFIX "PCI Interrupt %s[%c]: no GSI", 542 dev_warn(&dev->dev, "PCI INT %c: no GSI", 'A' + pin);
542 pci_name(dev), ('A' + pin));
543 /* Interrupt Line values above 0xF are forbidden */ 543 /* Interrupt Line values above 0xF are forbidden */
544 if (dev->irq > 0 && (dev->irq <= 0xF)) { 544 if (dev->irq > 0 && (dev->irq <= 0xF)) {
545 printk(" - using IRQ %d\n", dev->irq); 545 printk(" - using IRQ %d\n", dev->irq);
@@ -554,21 +554,21 @@ int acpi_pci_irq_enable(struct pci_dev *dev)
554 554
555 rc = acpi_register_gsi(irq, triggering, polarity); 555 rc = acpi_register_gsi(irq, triggering, polarity);
556 if (rc < 0) { 556 if (rc < 0) {
557 printk(KERN_WARNING PREFIX "PCI Interrupt %s[%c]: failed " 557 dev_warn(&dev->dev, "PCI INT %c: failed to register GSI\n",
558 "to register GSI\n", pci_name(dev), ('A' + pin)); 558 'A' + pin);
559 return rc; 559 return rc;
560 } 560 }
561 dev->irq = rc; 561 dev->irq = rc;
562 562
563 printk(KERN_INFO PREFIX "PCI Interrupt %s[%c] -> ",
564 pci_name(dev), 'A' + pin);
565
566 if (link) 563 if (link)
567 printk("Link [%s] -> ", link); 564 snprintf(link_desc, sizeof(link_desc), " -> Link[%s]", link);
565 else
566 link_desc[0] = '\0';
568 567
569 printk("GSI %u (%s, %s) -> IRQ %d\n", irq, 568 dev_info(&dev->dev, "PCI INT %c%s -> GSI %u (%s, %s) -> IRQ %d\n",
570 (triggering == ACPI_LEVEL_SENSITIVE) ? "level" : "edge", 569 'A' + pin, link_desc, irq,
571 (polarity == ACPI_ACTIVE_LOW) ? "low" : "high", dev->irq); 570 (triggering == ACPI_LEVEL_SENSITIVE) ? "level" : "edge",
571 (polarity == ACPI_ACTIVE_LOW) ? "low" : "high", dev->irq);
572 572
573 return 0; 573 return 0;
574} 574}
@@ -616,10 +616,6 @@ void acpi_pci_irq_disable(struct pci_dev *dev)
616 * (e.g. PCI_UNDEFINED_IRQ). 616 * (e.g. PCI_UNDEFINED_IRQ).
617 */ 617 */
618 618
619 printk(KERN_INFO PREFIX "PCI interrupt for device %s disabled\n", 619 dev_info(&dev->dev, "PCI INT %c disabled\n", 'A' + pin);
620 pci_name(dev));
621
622 acpi_unregister_gsi(gsi); 620 acpi_unregister_gsi(gsi);
623
624 return;
625} 621}
diff --git a/drivers/acpi/processor_core.c b/drivers/acpi/processor_core.c
index 9dd0fa93b9e1..ec0f2d581ece 100644
--- a/drivers/acpi/processor_core.c
+++ b/drivers/acpi/processor_core.c
@@ -118,8 +118,31 @@ static const struct file_operations acpi_processor_info_fops = {
118 .release = single_release, 118 .release = single_release,
119}; 119};
120 120
121struct acpi_processor *processors[NR_CPUS]; 121DEFINE_PER_CPU(struct acpi_processor *, processors);
122struct acpi_processor_errata errata __read_mostly; 122struct acpi_processor_errata errata __read_mostly;
123static int set_no_mwait(const struct dmi_system_id *id)
124{
125 printk(KERN_NOTICE PREFIX "%s detected - "
126 "disable mwait for CPU C-stetes\n", id->ident);
127 idle_nomwait = 1;
128 return 0;
129}
130
131static struct dmi_system_id __cpuinitdata processor_idle_dmi_table[] = {
132 {
133 set_no_mwait, "IFL91 board", {
134 DMI_MATCH(DMI_BIOS_VENDOR, "COMPAL"),
135 DMI_MATCH(DMI_SYS_VENDOR, "ZEPTO"),
136 DMI_MATCH(DMI_PRODUCT_VERSION, "3215W"),
137 DMI_MATCH(DMI_BOARD_NAME, "IFL91") }, NULL},
138 {
139 set_no_mwait, "Extensa 5220", {
140 DMI_MATCH(DMI_BIOS_VENDOR, "Phoenix Technologies LTD"),
141 DMI_MATCH(DMI_SYS_VENDOR, "ACER"),
142 DMI_MATCH(DMI_PRODUCT_VERSION, "0100"),
143 DMI_MATCH(DMI_BOARD_NAME, "Columbia") }, NULL},
144 {},
145};
123 146
124/* -------------------------------------------------------------------------- 147/* --------------------------------------------------------------------------
125 Errata Handling 148 Errata Handling
@@ -265,7 +288,20 @@ static int acpi_processor_set_pdc(struct acpi_processor *pr)
265 288
266 if (!pdc_in) 289 if (!pdc_in)
267 return status; 290 return status;
291 if (idle_nomwait) {
292 /*
293 * If mwait is disabled for CPU C-states, the C2C3_FFH access
294 * mode will be disabled in the parameter of _PDC object.
295 * Of course C1_FFH access mode will also be disabled.
296 */
297 union acpi_object *obj;
298 u32 *buffer = NULL;
268 299
300 obj = pdc_in->pointer;
301 buffer = (u32 *)(obj->buffer.pointer);
302 buffer[2] &= ~(ACPI_PDC_C_C2C3_FFH | ACPI_PDC_C_C1_FFH);
303
304 }
269 status = acpi_evaluate_object(pr->handle, "_PDC", pdc_in, NULL); 305 status = acpi_evaluate_object(pr->handle, "_PDC", pdc_in, NULL);
270 306
271 if (ACPI_FAILURE(status)) 307 if (ACPI_FAILURE(status))
@@ -614,14 +650,14 @@ static int acpi_processor_get_info(struct acpi_processor *pr, unsigned has_uid)
614 return 0; 650 return 0;
615} 651}
616 652
617static void *processor_device_array[NR_CPUS]; 653static DEFINE_PER_CPU(void *, processor_device_array);
618 654
619static int __cpuinit acpi_processor_start(struct acpi_device *device) 655static int __cpuinit acpi_processor_start(struct acpi_device *device)
620{ 656{
621 int result = 0; 657 int result = 0;
622 acpi_status status = AE_OK; 658 acpi_status status = AE_OK;
623 struct acpi_processor *pr; 659 struct acpi_processor *pr;
624 660 struct sys_device *sysdev;
625 661
626 pr = acpi_driver_data(device); 662 pr = acpi_driver_data(device);
627 663
@@ -638,20 +674,24 @@ static int __cpuinit acpi_processor_start(struct acpi_device *device)
638 * ACPI id of processors can be reported wrongly by the BIOS. 674 * ACPI id of processors can be reported wrongly by the BIOS.
639 * Don't trust it blindly 675 * Don't trust it blindly
640 */ 676 */
641 if (processor_device_array[pr->id] != NULL && 677 if (per_cpu(processor_device_array, pr->id) != NULL &&
642 processor_device_array[pr->id] != device) { 678 per_cpu(processor_device_array, pr->id) != device) {
643 printk(KERN_WARNING "BIOS reported wrong ACPI id " 679 printk(KERN_WARNING "BIOS reported wrong ACPI id "
644 "for the processor\n"); 680 "for the processor\n");
645 return -ENODEV; 681 return -ENODEV;
646 } 682 }
647 processor_device_array[pr->id] = device; 683 per_cpu(processor_device_array, pr->id) = device;
648 684
649 processors[pr->id] = pr; 685 per_cpu(processors, pr->id) = pr;
650 686
651 result = acpi_processor_add_fs(device); 687 result = acpi_processor_add_fs(device);
652 if (result) 688 if (result)
653 goto end; 689 goto end;
654 690
691 sysdev = get_cpu_sysdev(pr->id);
692 if (sysfs_create_link(&device->dev.kobj, &sysdev->kobj, "sysdev"))
693 return -EFAULT;
694
655 status = acpi_install_notify_handler(pr->handle, ACPI_DEVICE_NOTIFY, 695 status = acpi_install_notify_handler(pr->handle, ACPI_DEVICE_NOTIFY,
656 acpi_processor_notify, pr); 696 acpi_processor_notify, pr);
657 697
@@ -749,7 +789,7 @@ static int acpi_cpu_soft_notify(struct notifier_block *nfb,
749 unsigned long action, void *hcpu) 789 unsigned long action, void *hcpu)
750{ 790{
751 unsigned int cpu = (unsigned long)hcpu; 791 unsigned int cpu = (unsigned long)hcpu;
752 struct acpi_processor *pr = processors[cpu]; 792 struct acpi_processor *pr = per_cpu(processors, cpu);
753 793
754 if (action == CPU_ONLINE && pr) { 794 if (action == CPU_ONLINE && pr) {
755 acpi_processor_ppc_has_changed(pr); 795 acpi_processor_ppc_has_changed(pr);
@@ -810,6 +850,8 @@ static int acpi_processor_remove(struct acpi_device *device, int type)
810 status = acpi_remove_notify_handler(pr->handle, ACPI_DEVICE_NOTIFY, 850 status = acpi_remove_notify_handler(pr->handle, ACPI_DEVICE_NOTIFY,
811 acpi_processor_notify); 851 acpi_processor_notify);
812 852
853 sysfs_remove_link(&device->dev.kobj, "sysdev");
854
813 acpi_processor_remove_fs(device); 855 acpi_processor_remove_fs(device);
814 856
815 if (pr->cdev) { 857 if (pr->cdev) {
@@ -819,8 +861,8 @@ static int acpi_processor_remove(struct acpi_device *device, int type)
819 pr->cdev = NULL; 861 pr->cdev = NULL;
820 } 862 }
821 863
822 processors[pr->id] = NULL; 864 per_cpu(processors, pr->id) = NULL;
823 processor_device_array[pr->id] = NULL; 865 per_cpu(processor_device_array, pr->id) = NULL;
824 kfree(pr); 866 kfree(pr);
825 867
826 return 0; 868 return 0;
@@ -1014,9 +1056,9 @@ static acpi_status acpi_processor_hotadd_init(acpi_handle handle, int *p_cpu)
1014 1056
1015static int acpi_processor_handle_eject(struct acpi_processor *pr) 1057static int acpi_processor_handle_eject(struct acpi_processor *pr)
1016{ 1058{
1017 if (cpu_online(pr->id)) { 1059 if (cpu_online(pr->id))
1018 return (-EINVAL); 1060 cpu_down(pr->id);
1019 } 1061
1020 arch_unregister_cpu(pr->id); 1062 arch_unregister_cpu(pr->id);
1021 acpi_unmap_lsapic(pr->id); 1063 acpi_unmap_lsapic(pr->id);
1022 return (0); 1064 return (0);
@@ -1068,8 +1110,6 @@ static int __init acpi_processor_init(void)
1068{ 1110{
1069 int result = 0; 1111 int result = 0;
1070 1112
1071
1072 memset(&processors, 0, sizeof(processors));
1073 memset(&errata, 0, sizeof(errata)); 1113 memset(&errata, 0, sizeof(errata));
1074 1114
1075#ifdef CONFIG_SMP 1115#ifdef CONFIG_SMP
@@ -1083,6 +1123,11 @@ static int __init acpi_processor_init(void)
1083 return -ENOMEM; 1123 return -ENOMEM;
1084 acpi_processor_dir->owner = THIS_MODULE; 1124 acpi_processor_dir->owner = THIS_MODULE;
1085 1125
1126 /*
1127 * Check whether the system is DMI table. If yes, OSPM
1128 * should not use mwait for CPU-states.
1129 */
1130 dmi_check_system(processor_idle_dmi_table);
1086 result = cpuidle_register_driver(&acpi_idle_driver); 1131 result = cpuidle_register_driver(&acpi_idle_driver);
1087 if (result < 0) 1132 if (result < 0)
1088 goto out_proc; 1133 goto out_proc;
diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
index 4976e5db2b3f..d592dbb1d12a 100644
--- a/drivers/acpi/processor_idle.c
+++ b/drivers/acpi/processor_idle.c
@@ -41,6 +41,7 @@
41#include <linux/pm_qos_params.h> 41#include <linux/pm_qos_params.h>
42#include <linux/clockchips.h> 42#include <linux/clockchips.h>
43#include <linux/cpuidle.h> 43#include <linux/cpuidle.h>
44#include <linux/cpuidle.h>
44 45
45/* 46/*
46 * Include the apic definitions for x86 to have the APIC timer related defines 47 * Include the apic definitions for x86 to have the APIC timer related defines
@@ -57,6 +58,7 @@
57 58
58#include <acpi/acpi_bus.h> 59#include <acpi/acpi_bus.h>
59#include <acpi/processor.h> 60#include <acpi/processor.h>
61#include <asm/processor.h>
60 62
61#define ACPI_PROCESSOR_COMPONENT 0x01000000 63#define ACPI_PROCESSOR_COMPONENT 0x01000000
62#define ACPI_PROCESSOR_CLASS "processor" 64#define ACPI_PROCESSOR_CLASS "processor"
@@ -401,7 +403,7 @@ static void acpi_processor_idle(void)
401 */ 403 */
402 local_irq_disable(); 404 local_irq_disable();
403 405
404 pr = processors[smp_processor_id()]; 406 pr = __get_cpu_var(processors);
405 if (!pr) { 407 if (!pr) {
406 local_irq_enable(); 408 local_irq_enable();
407 return; 409 return;
@@ -955,6 +957,21 @@ static int acpi_processor_get_power_info_cst(struct acpi_processor *pr)
955 } else { 957 } else {
956 continue; 958 continue;
957 } 959 }
960 if (cx.type == ACPI_STATE_C1 &&
961 (idle_halt || idle_nomwait)) {
962 /*
963 * In most cases the C1 space_id obtained from
964 * _CST object is FIXED_HARDWARE access mode.
965 * But when the option of idle=halt is added,
966 * the entry_method type should be changed from
967 * CSTATE_FFH to CSTATE_HALT.
968 * When the option of idle=nomwait is added,
969 * the C1 entry_method type should be
970 * CSTATE_HALT.
971 */
972 cx.entry_method = ACPI_CSTATE_HALT;
973 snprintf(cx.desc, ACPI_CX_DESC_LEN, "ACPI HLT");
974 }
958 } else { 975 } else {
959 snprintf(cx.desc, ACPI_CX_DESC_LEN, "ACPI IOPORT 0x%x", 976 snprintf(cx.desc, ACPI_CX_DESC_LEN, "ACPI IOPORT 0x%x",
960 cx.address); 977 cx.address);
@@ -1431,7 +1448,7 @@ static int acpi_idle_enter_c1(struct cpuidle_device *dev,
1431 struct acpi_processor *pr; 1448 struct acpi_processor *pr;
1432 struct acpi_processor_cx *cx = cpuidle_get_statedata(state); 1449 struct acpi_processor_cx *cx = cpuidle_get_statedata(state);
1433 1450
1434 pr = processors[smp_processor_id()]; 1451 pr = __get_cpu_var(processors);
1435 1452
1436 if (unlikely(!pr)) 1453 if (unlikely(!pr))
1437 return 0; 1454 return 0;
@@ -1471,7 +1488,7 @@ static int acpi_idle_enter_simple(struct cpuidle_device *dev,
1471 u32 t1, t2; 1488 u32 t1, t2;
1472 int sleep_ticks = 0; 1489 int sleep_ticks = 0;
1473 1490
1474 pr = processors[smp_processor_id()]; 1491 pr = __get_cpu_var(processors);
1475 1492
1476 if (unlikely(!pr)) 1493 if (unlikely(!pr))
1477 return 0; 1494 return 0;
@@ -1549,7 +1566,7 @@ static int acpi_idle_enter_bm(struct cpuidle_device *dev,
1549 u32 t1, t2; 1566 u32 t1, t2;
1550 int sleep_ticks = 0; 1567 int sleep_ticks = 0;
1551 1568
1552 pr = processors[smp_processor_id()]; 1569 pr = __get_cpu_var(processors);
1553 1570
1554 if (unlikely(!pr)) 1571 if (unlikely(!pr))
1555 return 0; 1572 return 0;
@@ -1780,6 +1797,15 @@ int __cpuinit acpi_processor_power_init(struct acpi_processor *pr,
1780 return 0; 1797 return 0;
1781 1798
1782 if (!first_run) { 1799 if (!first_run) {
1800 if (idle_halt) {
1801 /*
1802 * When the boot option of "idle=halt" is added, halt
1803 * is used for CPU IDLE.
1804 * In such case C2/C3 is meaningless. So the max_cstate
1805 * is set to one.
1806 */
1807 max_cstate = 1;
1808 }
1783 dmi_check_system(processor_power_dmi_table); 1809 dmi_check_system(processor_power_dmi_table);
1784 max_cstate = acpi_processor_cstate_check(max_cstate); 1810 max_cstate = acpi_processor_cstate_check(max_cstate);
1785 if (max_cstate < ACPI_C_STATES_MAX) 1811 if (max_cstate < ACPI_C_STATES_MAX)
diff --git a/drivers/acpi/processor_perflib.c b/drivers/acpi/processor_perflib.c
index d80b2d1441af..b4749969c6b4 100644
--- a/drivers/acpi/processor_perflib.c
+++ b/drivers/acpi/processor_perflib.c
@@ -89,7 +89,7 @@ static int acpi_processor_ppc_notifier(struct notifier_block *nb,
89 if (event != CPUFREQ_INCOMPATIBLE) 89 if (event != CPUFREQ_INCOMPATIBLE)
90 goto out; 90 goto out;
91 91
92 pr = processors[policy->cpu]; 92 pr = per_cpu(processors, policy->cpu);
93 if (!pr || !pr->performance) 93 if (!pr || !pr->performance)
94 goto out; 94 goto out;
95 95
@@ -572,7 +572,7 @@ int acpi_processor_preregister_performance(
572 572
573 /* Call _PSD for all CPUs */ 573 /* Call _PSD for all CPUs */
574 for_each_possible_cpu(i) { 574 for_each_possible_cpu(i) {
575 pr = processors[i]; 575 pr = per_cpu(processors, i);
576 if (!pr) { 576 if (!pr) {
577 /* Look only at processors in ACPI namespace */ 577 /* Look only at processors in ACPI namespace */
578 continue; 578 continue;
@@ -603,7 +603,7 @@ int acpi_processor_preregister_performance(
603 * domain info. 603 * domain info.
604 */ 604 */
605 for_each_possible_cpu(i) { 605 for_each_possible_cpu(i) {
606 pr = processors[i]; 606 pr = per_cpu(processors, i);
607 if (!pr) 607 if (!pr)
608 continue; 608 continue;
609 609
@@ -624,7 +624,7 @@ int acpi_processor_preregister_performance(
624 624
625 cpus_clear(covered_cpus); 625 cpus_clear(covered_cpus);
626 for_each_possible_cpu(i) { 626 for_each_possible_cpu(i) {
627 pr = processors[i]; 627 pr = per_cpu(processors, i);
628 if (!pr) 628 if (!pr)
629 continue; 629 continue;
630 630
@@ -651,7 +651,7 @@ int acpi_processor_preregister_performance(
651 if (i == j) 651 if (i == j)
652 continue; 652 continue;
653 653
654 match_pr = processors[j]; 654 match_pr = per_cpu(processors, j);
655 if (!match_pr) 655 if (!match_pr)
656 continue; 656 continue;
657 657
@@ -680,7 +680,7 @@ int acpi_processor_preregister_performance(
680 if (i == j) 680 if (i == j)
681 continue; 681 continue;
682 682
683 match_pr = processors[j]; 683 match_pr = per_cpu(processors, j);
684 if (!match_pr) 684 if (!match_pr)
685 continue; 685 continue;
686 686
@@ -697,7 +697,7 @@ int acpi_processor_preregister_performance(
697 697
698err_ret: 698err_ret:
699 for_each_possible_cpu(i) { 699 for_each_possible_cpu(i) {
700 pr = processors[i]; 700 pr = per_cpu(processors, i);
701 if (!pr || !pr->performance) 701 if (!pr || !pr->performance)
702 continue; 702 continue;
703 703
@@ -728,7 +728,7 @@ acpi_processor_register_performance(struct acpi_processor_performance
728 728
729 mutex_lock(&performance_mutex); 729 mutex_lock(&performance_mutex);
730 730
731 pr = processors[cpu]; 731 pr = per_cpu(processors, cpu);
732 if (!pr) { 732 if (!pr) {
733 mutex_unlock(&performance_mutex); 733 mutex_unlock(&performance_mutex);
734 return -ENODEV; 734 return -ENODEV;
@@ -766,7 +766,7 @@ acpi_processor_unregister_performance(struct acpi_processor_performance
766 766
767 mutex_lock(&performance_mutex); 767 mutex_lock(&performance_mutex);
768 768
769 pr = processors[cpu]; 769 pr = per_cpu(processors, cpu);
770 if (!pr) { 770 if (!pr) {
771 mutex_unlock(&performance_mutex); 771 mutex_unlock(&performance_mutex);
772 return; 772 return;
diff --git a/drivers/acpi/processor_throttling.c b/drivers/acpi/processor_throttling.c
index bb06738860c4..0622ace05220 100644
--- a/drivers/acpi/processor_throttling.c
+++ b/drivers/acpi/processor_throttling.c
@@ -71,7 +71,7 @@ static int acpi_processor_update_tsd_coord(void)
71 * coordination between all CPUs. 71 * coordination between all CPUs.
72 */ 72 */
73 for_each_possible_cpu(i) { 73 for_each_possible_cpu(i) {
74 pr = processors[i]; 74 pr = per_cpu(processors, i);
75 if (!pr) 75 if (!pr)
76 continue; 76 continue;
77 77
@@ -93,7 +93,7 @@ static int acpi_processor_update_tsd_coord(void)
93 93
94 cpus_clear(covered_cpus); 94 cpus_clear(covered_cpus);
95 for_each_possible_cpu(i) { 95 for_each_possible_cpu(i) {
96 pr = processors[i]; 96 pr = per_cpu(processors, i);
97 if (!pr) 97 if (!pr)
98 continue; 98 continue;
99 99
@@ -119,7 +119,7 @@ static int acpi_processor_update_tsd_coord(void)
119 if (i == j) 119 if (i == j)
120 continue; 120 continue;
121 121
122 match_pr = processors[j]; 122 match_pr = per_cpu(processors, j);
123 if (!match_pr) 123 if (!match_pr)
124 continue; 124 continue;
125 125
@@ -152,7 +152,7 @@ static int acpi_processor_update_tsd_coord(void)
152 if (i == j) 152 if (i == j)
153 continue; 153 continue;
154 154
155 match_pr = processors[j]; 155 match_pr = per_cpu(processors, j);
156 if (!match_pr) 156 if (!match_pr)
157 continue; 157 continue;
158 158
@@ -172,7 +172,7 @@ static int acpi_processor_update_tsd_coord(void)
172 172
173err_ret: 173err_ret:
174 for_each_possible_cpu(i) { 174 for_each_possible_cpu(i) {
175 pr = processors[i]; 175 pr = per_cpu(processors, i);
176 if (!pr) 176 if (!pr)
177 continue; 177 continue;
178 178
@@ -214,7 +214,7 @@ static int acpi_processor_throttling_notifier(unsigned long event, void *data)
214 struct acpi_processor_throttling *p_throttling; 214 struct acpi_processor_throttling *p_throttling;
215 215
216 cpu = p_tstate->cpu; 216 cpu = p_tstate->cpu;
217 pr = processors[cpu]; 217 pr = per_cpu(processors, cpu);
218 if (!pr) { 218 if (!pr) {
219 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Invalid pr pointer\n")); 219 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Invalid pr pointer\n"));
220 return 0; 220 return 0;
@@ -1035,7 +1035,7 @@ int acpi_processor_set_throttling(struct acpi_processor *pr, int state)
1035 * cpus. 1035 * cpus.
1036 */ 1036 */
1037 for_each_cpu_mask(i, online_throttling_cpus) { 1037 for_each_cpu_mask(i, online_throttling_cpus) {
1038 match_pr = processors[i]; 1038 match_pr = per_cpu(processors, i);
1039 /* 1039 /*
1040 * If the pointer is invalid, we will report the 1040 * If the pointer is invalid, we will report the
1041 * error message and continue. 1041 * error message and continue.
@@ -1232,7 +1232,10 @@ static ssize_t acpi_processor_write_throttling(struct file *file,
1232 int result = 0; 1232 int result = 0;
1233 struct seq_file *m = file->private_data; 1233 struct seq_file *m = file->private_data;
1234 struct acpi_processor *pr = m->private; 1234 struct acpi_processor *pr = m->private;
1235 char state_string[12] = { '\0' }; 1235 char state_string[5] = "";
1236 char *charp = NULL;
1237 size_t state_val = 0;
1238 char tmpbuf[5] = "";
1236 1239
1237 if (!pr || (count > sizeof(state_string) - 1)) 1240 if (!pr || (count > sizeof(state_string) - 1))
1238 return -EINVAL; 1241 return -EINVAL;
@@ -1241,10 +1244,23 @@ static ssize_t acpi_processor_write_throttling(struct file *file,
1241 return -EFAULT; 1244 return -EFAULT;
1242 1245
1243 state_string[count] = '\0'; 1246 state_string[count] = '\0';
1247 if ((count > 0) && (state_string[count-1] == '\n'))
1248 state_string[count-1] = '\0';
1244 1249
1245 result = acpi_processor_set_throttling(pr, 1250 charp = state_string;
1246 simple_strtoul(state_string, 1251 if ((state_string[0] == 't') || (state_string[0] == 'T'))
1247 NULL, 0)); 1252 charp++;
1253
1254 state_val = simple_strtoul(charp, NULL, 0);
1255 if (state_val >= pr->throttling.state_count)
1256 return -EINVAL;
1257
1258 snprintf(tmpbuf, 5, "%zu", state_val);
1259
1260 if (strcmp(tmpbuf, charp) != 0)
1261 return -EINVAL;
1262
1263 result = acpi_processor_set_throttling(pr, state_val);
1248 if (result) 1264 if (result)
1249 return result; 1265 return result;
1250 1266
diff --git a/drivers/acpi/reboot.c b/drivers/acpi/reboot.c
new file mode 100644
index 000000000000..a6b662c00b67
--- /dev/null
+++ b/drivers/acpi/reboot.c
@@ -0,0 +1,50 @@
1
2#include <linux/pci.h>
3#include <linux/acpi.h>
4#include <acpi/reboot.h>
5
6void acpi_reboot(void)
7{
8 struct acpi_generic_address *rr;
9 struct pci_bus *bus0;
10 u8 reset_value;
11 unsigned int devfn;
12
13 if (acpi_disabled)
14 return;
15
16 rr = &acpi_gbl_FADT.reset_register;
17
18 /* Is the reset register supported? */
19 if (!(acpi_gbl_FADT.flags & ACPI_FADT_RESET_REGISTER) ||
20 rr->bit_width != 8 || rr->bit_offset != 0)
21 return;
22
23 reset_value = acpi_gbl_FADT.reset_value;
24
25 /* The reset register can only exist in I/O, Memory or PCI config space
26 * on a device on bus 0. */
27 switch (rr->space_id) {
28 case ACPI_ADR_SPACE_PCI_CONFIG:
29 /* The reset register can only live on bus 0. */
30 bus0 = pci_find_bus(0, 0);
31 if (!bus0)
32 return;
33 /* Form PCI device/function pair. */
34 devfn = PCI_DEVFN((rr->address >> 32) & 0xffff,
35 (rr->address >> 16) & 0xffff);
36 printk(KERN_DEBUG "Resetting with ACPI PCI RESET_REG.");
37 /* Write the value that resets us. */
38 pci_bus_write_config_byte(bus0, devfn,
39 (rr->address & 0xffff), reset_value);
40 break;
41
42 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
43 case ACPI_ADR_SPACE_SYSTEM_IO:
44 printk(KERN_DEBUG "ACPI MEMORY or I/O RESET_REG.\n");
45 acpi_hw_low_level_write(8, reset_value, rr);
46 break;
47 }
48 /* Wait ten seconds */
49 acpi_os_stall(10000000);
50}
diff --git a/drivers/acpi/resources/rscalc.c b/drivers/acpi/resources/rscalc.c
index 8a112d11d491..f61ebc679e66 100644
--- a/drivers/acpi/resources/rscalc.c
+++ b/drivers/acpi/resources/rscalc.c
@@ -73,7 +73,7 @@ acpi_rs_stream_option_length(u32 resource_length, u32 minimum_total_length);
73 73
74static u8 acpi_rs_count_set_bits(u16 bit_field) 74static u8 acpi_rs_count_set_bits(u16 bit_field)
75{ 75{
76 acpi_native_uint bits_set; 76 u8 bits_set;
77 77
78 ACPI_FUNCTION_ENTRY(); 78 ACPI_FUNCTION_ENTRY();
79 79
@@ -84,7 +84,7 @@ static u8 acpi_rs_count_set_bits(u16 bit_field)
84 bit_field &= (u16) (bit_field - 1); 84 bit_field &= (u16) (bit_field - 1);
85 } 85 }
86 86
87 return ((u8) bits_set); 87 return bits_set;
88} 88}
89 89
90/******************************************************************************* 90/*******************************************************************************
diff --git a/drivers/acpi/resources/rscreate.c b/drivers/acpi/resources/rscreate.c
index faddaee1bc07..7804a8c40e7a 100644
--- a/drivers/acpi/resources/rscreate.c
+++ b/drivers/acpi/resources/rscreate.c
@@ -181,9 +181,9 @@ acpi_rs_create_pci_routing_table(union acpi_operand_object *package_object,
181 } 181 }
182 182
183 /* 183 /*
184 * Loop through the ACPI_INTERNAL_OBJECTS - Each object 184 * Loop through the ACPI_INTERNAL_OBJECTS - Each object should be a
185 * should be a package that in turn contains an 185 * package that in turn contains an acpi_integer Address, a u8 Pin,
186 * acpi_integer Address, a u8 Pin, a Name and a u8 source_index. 186 * a Name, and a u8 source_index.
187 */ 187 */
188 top_object_list = package_object->package.elements; 188 top_object_list = package_object->package.elements;
189 number_of_elements = package_object->package.count; 189 number_of_elements = package_object->package.count;
@@ -240,9 +240,7 @@ acpi_rs_create_pci_routing_table(union acpi_operand_object *package_object,
240 /* 1) First subobject: Dereference the PRT.Address */ 240 /* 1) First subobject: Dereference the PRT.Address */
241 241
242 obj_desc = sub_object_list[0]; 242 obj_desc = sub_object_list[0];
243 if (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_INTEGER) { 243 if (ACPI_GET_OBJECT_TYPE(obj_desc) != ACPI_TYPE_INTEGER) {
244 user_prt->address = obj_desc->integer.value;
245 } else {
246 ACPI_ERROR((AE_INFO, 244 ACPI_ERROR((AE_INFO,
247 "(PRT[%X].Address) Need Integer, found %s", 245 "(PRT[%X].Address) Need Integer, found %s",
248 index, 246 index,
@@ -250,12 +248,12 @@ acpi_rs_create_pci_routing_table(union acpi_operand_object *package_object,
250 return_ACPI_STATUS(AE_BAD_DATA); 248 return_ACPI_STATUS(AE_BAD_DATA);
251 } 249 }
252 250
251 user_prt->address = obj_desc->integer.value;
252
253 /* 2) Second subobject: Dereference the PRT.Pin */ 253 /* 2) Second subobject: Dereference the PRT.Pin */
254 254
255 obj_desc = sub_object_list[1]; 255 obj_desc = sub_object_list[1];
256 if (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_INTEGER) { 256 if (ACPI_GET_OBJECT_TYPE(obj_desc) != ACPI_TYPE_INTEGER) {
257 user_prt->pin = (u32) obj_desc->integer.value;
258 } else {
259 ACPI_ERROR((AE_INFO, 257 ACPI_ERROR((AE_INFO,
260 "(PRT[%X].Pin) Need Integer, found %s", 258 "(PRT[%X].Pin) Need Integer, found %s",
261 index, 259 index,
@@ -284,6 +282,25 @@ acpi_rs_create_pci_routing_table(union acpi_operand_object *package_object,
284 } 282 }
285 } 283 }
286 284
285 user_prt->pin = (u32) obj_desc->integer.value;
286
287 /*
288 * If the BIOS has erroneously reversed the _PRT source_name (index 2)
289 * and the source_index (index 3), fix it. _PRT is important enough to
290 * workaround this BIOS error. This also provides compatibility with
291 * other ACPI implementations.
292 */
293 obj_desc = sub_object_list[3];
294 if (!obj_desc
295 || (ACPI_GET_OBJECT_TYPE(obj_desc) != ACPI_TYPE_INTEGER)) {
296 sub_object_list[3] = sub_object_list[2];
297 sub_object_list[2] = obj_desc;
298
299 ACPI_WARNING((AE_INFO,
300 "(PRT[%X].Source) SourceName and SourceIndex are reversed, fixed",
301 index));
302 }
303
287 /* 304 /*
288 * 3) Third subobject: Dereference the PRT.source_name 305 * 3) Third subobject: Dereference the PRT.source_name
289 * The name may be unresolved (slack mode), so allow a null object 306 * The name may be unresolved (slack mode), so allow a null object
@@ -364,9 +381,7 @@ acpi_rs_create_pci_routing_table(union acpi_operand_object *package_object,
364 /* 4) Fourth subobject: Dereference the PRT.source_index */ 381 /* 4) Fourth subobject: Dereference the PRT.source_index */
365 382
366 obj_desc = sub_object_list[source_index_index]; 383 obj_desc = sub_object_list[source_index_index];
367 if (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_INTEGER) { 384 if (ACPI_GET_OBJECT_TYPE(obj_desc) != ACPI_TYPE_INTEGER) {
368 user_prt->source_index = (u32) obj_desc->integer.value;
369 } else {
370 ACPI_ERROR((AE_INFO, 385 ACPI_ERROR((AE_INFO,
371 "(PRT[%X].SourceIndex) Need Integer, found %s", 386 "(PRT[%X].SourceIndex) Need Integer, found %s",
372 index, 387 index,
@@ -374,6 +389,8 @@ acpi_rs_create_pci_routing_table(union acpi_operand_object *package_object,
374 return_ACPI_STATUS(AE_BAD_DATA); 389 return_ACPI_STATUS(AE_BAD_DATA);
375 } 390 }
376 391
392 user_prt->source_index = (u32) obj_desc->integer.value;
393
377 /* Point to the next union acpi_operand_object in the top level package */ 394 /* Point to the next union acpi_operand_object in the top level package */
378 395
379 top_object_list++; 396 top_object_list++;
diff --git a/drivers/acpi/resources/rsmisc.c b/drivers/acpi/resources/rsmisc.c
index de1ac3881b22..96a6c0353255 100644
--- a/drivers/acpi/resources/rsmisc.c
+++ b/drivers/acpi/resources/rsmisc.c
@@ -82,7 +82,7 @@ acpi_rs_convert_aml_to_resource(struct acpi_resource *resource,
82 82
83 ACPI_FUNCTION_TRACE(rs_convert_aml_to_resource); 83 ACPI_FUNCTION_TRACE(rs_convert_aml_to_resource);
84 84
85 if (((acpi_native_uint) resource) & 0x3) { 85 if (((acpi_size) resource) & 0x3) {
86 86
87 /* Each internal resource struct is expected to be 32-bit aligned */ 87 /* Each internal resource struct is expected to be 32-bit aligned */
88 88
diff --git a/drivers/acpi/resources/rsutils.c b/drivers/acpi/resources/rsutils.c
index befe2302f41b..f7b3bcd59ba7 100644
--- a/drivers/acpi/resources/rsutils.c
+++ b/drivers/acpi/resources/rsutils.c
@@ -62,7 +62,7 @@ ACPI_MODULE_NAME("rsutils")
62 ******************************************************************************/ 62 ******************************************************************************/
63u8 acpi_rs_decode_bitmask(u16 mask, u8 * list) 63u8 acpi_rs_decode_bitmask(u16 mask, u8 * list)
64{ 64{
65 acpi_native_uint i; 65 u8 i;
66 u8 bit_count; 66 u8 bit_count;
67 67
68 ACPI_FUNCTION_ENTRY(); 68 ACPI_FUNCTION_ENTRY();
@@ -71,7 +71,7 @@ u8 acpi_rs_decode_bitmask(u16 mask, u8 * list)
71 71
72 for (i = 0, bit_count = 0; mask; i++) { 72 for (i = 0, bit_count = 0; mask; i++) {
73 if (mask & 0x0001) { 73 if (mask & 0x0001) {
74 list[bit_count] = (u8) i; 74 list[bit_count] = i;
75 bit_count++; 75 bit_count++;
76 } 76 }
77 77
@@ -96,8 +96,8 @@ u8 acpi_rs_decode_bitmask(u16 mask, u8 * list)
96 96
97u16 acpi_rs_encode_bitmask(u8 * list, u8 count) 97u16 acpi_rs_encode_bitmask(u8 * list, u8 count)
98{ 98{
99 acpi_native_uint i; 99 u32 i;
100 acpi_native_uint mask; 100 u16 mask;
101 101
102 ACPI_FUNCTION_ENTRY(); 102 ACPI_FUNCTION_ENTRY();
103 103
@@ -107,7 +107,7 @@ u16 acpi_rs_encode_bitmask(u8 * list, u8 count)
107 mask |= (0x1 << list[i]); 107 mask |= (0x1 << list[i]);
108 } 108 }
109 109
110 return ((u16) mask); 110 return mask;
111} 111}
112 112
113/******************************************************************************* 113/*******************************************************************************
@@ -130,7 +130,7 @@ u16 acpi_rs_encode_bitmask(u8 * list, u8 count)
130void 130void
131acpi_rs_move_data(void *destination, void *source, u16 item_count, u8 move_type) 131acpi_rs_move_data(void *destination, void *source, u16 item_count, u8 move_type)
132{ 132{
133 acpi_native_uint i; 133 u32 i;
134 134
135 ACPI_FUNCTION_ENTRY(); 135 ACPI_FUNCTION_ENTRY();
136 136
@@ -679,7 +679,6 @@ acpi_rs_set_srs_method_data(struct acpi_namespace_node *node,
679 info->prefix_node = node; 679 info->prefix_node = node;
680 info->pathname = METHOD_NAME__SRS; 680 info->pathname = METHOD_NAME__SRS;
681 info->parameters = args; 681 info->parameters = args;
682 info->parameter_type = ACPI_PARAM_ARGS;
683 info->flags = ACPI_IGNORE_RETURN_VALUE; 682 info->flags = ACPI_IGNORE_RETURN_VALUE;
684 683
685 /* 684 /*
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index 6d85289f1c12..5b049cd79553 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -6,6 +6,8 @@
6#include <linux/init.h> 6#include <linux/init.h>
7#include <linux/kernel.h> 7#include <linux/kernel.h>
8#include <linux/acpi.h> 8#include <linux/acpi.h>
9#include <linux/signal.h>
10#include <linux/kthread.h>
9 11
10#include <acpi/acpi_drivers.h> 12#include <acpi/acpi_drivers.h>
11#include <acpi/acinterp.h> /* for acpi_ex_eisa_id_to_string() */ 13#include <acpi/acinterp.h> /* for acpi_ex_eisa_id_to_string() */
@@ -92,17 +94,37 @@ acpi_device_modalias_show(struct device *dev, struct device_attribute *attr, cha
92} 94}
93static DEVICE_ATTR(modalias, 0444, acpi_device_modalias_show, NULL); 95static DEVICE_ATTR(modalias, 0444, acpi_device_modalias_show, NULL);
94 96
95static int acpi_eject_operation(acpi_handle handle, int lockable) 97static int acpi_bus_hot_remove_device(void *context)
96{ 98{
99 struct acpi_device *device;
100 acpi_handle handle = context;
97 struct acpi_object_list arg_list; 101 struct acpi_object_list arg_list;
98 union acpi_object arg; 102 union acpi_object arg;
99 acpi_status status = AE_OK; 103 acpi_status status = AE_OK;
100 104
101 /* 105 if (acpi_bus_get_device(handle, &device))
102 * TBD: evaluate _PS3? 106 return 0;
103 */
104 107
105 if (lockable) { 108 if (!device)
109 return 0;
110
111 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
112 "Hot-removing device %s...\n", device->dev.bus_id));
113
114
115 if (acpi_bus_trim(device, 1)) {
116 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
117 "Removing device failed\n"));
118 return -1;
119 }
120
121 /* power off device */
122 status = acpi_evaluate_object(handle, "_PS3", NULL, NULL);
123 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND)
124 ACPI_DEBUG_PRINT((ACPI_DB_WARN,
125 "Power-off device failed\n"));
126
127 if (device->flags.lockable) {
106 arg_list.count = 1; 128 arg_list.count = 1;
107 arg_list.pointer = &arg; 129 arg_list.pointer = &arg;
108 arg.type = ACPI_TYPE_INTEGER; 130 arg.type = ACPI_TYPE_INTEGER;
@@ -118,26 +140,22 @@ static int acpi_eject_operation(acpi_handle handle, int lockable)
118 /* 140 /*
119 * TBD: _EJD support. 141 * TBD: _EJD support.
120 */ 142 */
121
122 status = acpi_evaluate_object(handle, "_EJ0", &arg_list, NULL); 143 status = acpi_evaluate_object(handle, "_EJ0", &arg_list, NULL);
123 if (ACPI_FAILURE(status)) { 144 if (ACPI_FAILURE(status))
124 return (-ENODEV); 145 return -ENODEV;
125 }
126 146
127 return (0); 147 return 0;
128} 148}
129 149
130static ssize_t 150static ssize_t
131acpi_eject_store(struct device *d, struct device_attribute *attr, 151acpi_eject_store(struct device *d, struct device_attribute *attr,
132 const char *buf, size_t count) 152 const char *buf, size_t count)
133{ 153{
134 int result;
135 int ret = count; 154 int ret = count;
136 int islockable;
137 acpi_status status; 155 acpi_status status;
138 acpi_handle handle;
139 acpi_object_type type = 0; 156 acpi_object_type type = 0;
140 struct acpi_device *acpi_device = to_acpi_device(d); 157 struct acpi_device *acpi_device = to_acpi_device(d);
158 struct task_struct *task;
141 159
142 if ((!count) || (buf[0] != '1')) { 160 if ((!count) || (buf[0] != '1')) {
143 return -EINVAL; 161 return -EINVAL;
@@ -154,18 +172,12 @@ acpi_eject_store(struct device *d, struct device_attribute *attr,
154 goto err; 172 goto err;
155 } 173 }
156 174
157 islockable = acpi_device->flags.lockable; 175 /* remove the device in another thread to fix the deadlock issue */
158 handle = acpi_device->handle; 176 task = kthread_run(acpi_bus_hot_remove_device,
159 177 acpi_device->handle, "acpi_hot_remove_device");
160 result = acpi_bus_trim(acpi_device, 1); 178 if (IS_ERR(task))
161 179 ret = PTR_ERR(task);
162 if (!result) 180err:
163 result = acpi_eject_operation(handle, islockable);
164
165 if (result) {
166 ret = -EBUSY;
167 }
168 err:
169 return ret; 181 return ret;
170} 182}
171 183
diff --git a/drivers/acpi/sleep/main.c b/drivers/acpi/sleep/main.c
index 495c63a3e0af..244e352f7661 100644
--- a/drivers/acpi/sleep/main.c
+++ b/drivers/acpi/sleep/main.c
@@ -61,8 +61,6 @@ static u32 acpi_suspend_states[] = {
61 [PM_SUSPEND_MAX] = ACPI_STATE_S5 61 [PM_SUSPEND_MAX] = ACPI_STATE_S5
62}; 62};
63 63
64static int init_8259A_after_S1;
65
66/** 64/**
67 * acpi_suspend_begin - Set the target system sleep state to the state 65 * acpi_suspend_begin - Set the target system sleep state to the state
68 * associated with given @pm_state, if supported. 66 * associated with given @pm_state, if supported.
@@ -185,13 +183,6 @@ static void acpi_suspend_finish(void)
185 acpi_set_firmware_waking_vector((acpi_physical_address) 0); 183 acpi_set_firmware_waking_vector((acpi_physical_address) 0);
186 184
187 acpi_target_sleep_state = ACPI_STATE_S0; 185 acpi_target_sleep_state = ACPI_STATE_S0;
188
189#ifdef CONFIG_X86
190 if (init_8259A_after_S1) {
191 printk("Broken toshiba laptop -> kicking interrupts\n");
192 init_8259A(0);
193 }
194#endif
195} 186}
196 187
197/** 188/**
@@ -231,26 +222,6 @@ static struct platform_suspend_ops acpi_suspend_ops = {
231 .finish = acpi_suspend_finish, 222 .finish = acpi_suspend_finish,
232 .end = acpi_suspend_end, 223 .end = acpi_suspend_end,
233}; 224};
234
235/*
236 * Toshiba fails to preserve interrupts over S1, reinitialization
237 * of 8259 is needed after S1 resume.
238 */
239static int __init init_ints_after_s1(const struct dmi_system_id *d)
240{
241 printk(KERN_WARNING "%s with broken S1 detected.\n", d->ident);
242 init_8259A_after_S1 = 1;
243 return 0;
244}
245
246static struct dmi_system_id __initdata acpisleep_dmi_table[] = {
247 {
248 .callback = init_ints_after_s1,
249 .ident = "Toshiba Satellite 4030cdt",
250 .matches = {DMI_MATCH(DMI_PRODUCT_NAME, "S4030CDT/4.3"),},
251 },
252 {},
253};
254#endif /* CONFIG_SUSPEND */ 225#endif /* CONFIG_SUSPEND */
255 226
256#ifdef CONFIG_HIBERNATION 227#ifdef CONFIG_HIBERNATION
@@ -368,8 +339,8 @@ int acpi_suspend(u32 acpi_state)
368/** 339/**
369 * acpi_pm_device_sleep_state - return preferred power state of ACPI device 340 * acpi_pm_device_sleep_state - return preferred power state of ACPI device
370 * in the system sleep state given by %acpi_target_sleep_state 341 * in the system sleep state given by %acpi_target_sleep_state
371 * @dev: device to examine 342 * @dev: device to examine; its driver model wakeup flags control
372 * @wake: if set, the device should be able to wake up the system 343 * whether it should be able to wake up the system
373 * @d_min_p: used to store the upper limit of allowed states range 344 * @d_min_p: used to store the upper limit of allowed states range
374 * Return value: preferred power state of the device on success, -ENODEV on 345 * Return value: preferred power state of the device on success, -ENODEV on
375 * failure (ie. if there's no 'struct acpi_device' for @dev) 346 * failure (ie. if there's no 'struct acpi_device' for @dev)
@@ -387,7 +358,7 @@ int acpi_suspend(u32 acpi_state)
387 * via @wake. 358 * via @wake.
388 */ 359 */
389 360
390int acpi_pm_device_sleep_state(struct device *dev, int wake, int *d_min_p) 361int acpi_pm_device_sleep_state(struct device *dev, int *d_min_p)
391{ 362{
392 acpi_handle handle = DEVICE_ACPI_HANDLE(dev); 363 acpi_handle handle = DEVICE_ACPI_HANDLE(dev);
393 struct acpi_device *adev; 364 struct acpi_device *adev;
@@ -426,7 +397,7 @@ int acpi_pm_device_sleep_state(struct device *dev, int wake, int *d_min_p)
426 * can wake the system. _S0W may be valid, too. 397 * can wake the system. _S0W may be valid, too.
427 */ 398 */
428 if (acpi_target_sleep_state == ACPI_STATE_S0 || 399 if (acpi_target_sleep_state == ACPI_STATE_S0 ||
429 (wake && adev->wakeup.state.enabled && 400 (device_may_wakeup(dev) && adev->wakeup.state.enabled &&
430 adev->wakeup.sleep_state <= acpi_target_sleep_state)) { 401 adev->wakeup.sleep_state <= acpi_target_sleep_state)) {
431 acpi_status status; 402 acpi_status status;
432 403
@@ -472,8 +443,6 @@ int __init acpi_sleep_init(void)
472 u8 type_a, type_b; 443 u8 type_a, type_b;
473#ifdef CONFIG_SUSPEND 444#ifdef CONFIG_SUSPEND
474 int i = 0; 445 int i = 0;
475
476 dmi_check_system(acpisleep_dmi_table);
477#endif 446#endif
478 447
479 if (acpi_disabled) 448 if (acpi_disabled)
diff --git a/drivers/acpi/system.c b/drivers/acpi/system.c
index 5bd2dec9a7ac..d8e3f153b295 100644
--- a/drivers/acpi/system.c
+++ b/drivers/acpi/system.c
@@ -167,7 +167,13 @@ static int acpi_system_sysfs_init(void)
167#define COUNT_ERROR 2 /* other */ 167#define COUNT_ERROR 2 /* other */
168#define NUM_COUNTERS_EXTRA 3 168#define NUM_COUNTERS_EXTRA 3
169 169
170static u32 *all_counters; 170#define ACPI_EVENT_VALID 0x01
171struct event_counter {
172 u32 count;
173 u32 flags;
174};
175
176static struct event_counter *all_counters;
171static u32 num_gpes; 177static u32 num_gpes;
172static u32 num_counters; 178static u32 num_counters;
173static struct attribute **all_attrs; 179static struct attribute **all_attrs;
@@ -202,9 +208,44 @@ static int count_num_gpes(void)
202 return count; 208 return count;
203} 209}
204 210
211static int get_gpe_device(int index, acpi_handle *handle)
212{
213 struct acpi_gpe_xrupt_info *gpe_xrupt_info;
214 struct acpi_gpe_block_info *gpe_block;
215 acpi_cpu_flags flags;
216 struct acpi_namespace_node *node;
217
218 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
219
220 gpe_xrupt_info = acpi_gbl_gpe_xrupt_list_head;
221 while (gpe_xrupt_info) {
222 gpe_block = gpe_xrupt_info->gpe_block_list_head;
223 node = gpe_block->node;
224 while (gpe_block) {
225 index -= gpe_block->register_count *
226 ACPI_GPE_REGISTER_WIDTH;
227 if (index < 0) {
228 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
229 /* return NULL if it's FADT GPE */
230 if (node->type != ACPI_TYPE_DEVICE)
231 *handle = NULL;
232 else
233 *handle = node;
234 return 0;
235 }
236 node = gpe_block->node;
237 gpe_block = gpe_block->next;
238 }
239 gpe_xrupt_info = gpe_xrupt_info->next;
240 }
241 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
242
243 return -ENODEV;
244}
245
205static void delete_gpe_attr_array(void) 246static void delete_gpe_attr_array(void)
206{ 247{
207 u32 *tmp = all_counters; 248 struct event_counter *tmp = all_counters;
208 249
209 all_counters = NULL; 250 all_counters = NULL;
210 kfree(tmp); 251 kfree(tmp);
@@ -230,9 +271,10 @@ void acpi_os_gpe_count(u32 gpe_number)
230 return; 271 return;
231 272
232 if (gpe_number < num_gpes) 273 if (gpe_number < num_gpes)
233 all_counters[gpe_number]++; 274 all_counters[gpe_number].count++;
234 else 275 else
235 all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_ERROR]++; 276 all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_ERROR].
277 count++;
236 278
237 return; 279 return;
238} 280}
@@ -243,44 +285,144 @@ void acpi_os_fixed_event_count(u32 event_number)
243 return; 285 return;
244 286
245 if (event_number < ACPI_NUM_FIXED_EVENTS) 287 if (event_number < ACPI_NUM_FIXED_EVENTS)
246 all_counters[num_gpes + event_number]++; 288 all_counters[num_gpes + event_number].count++;
247 else 289 else
248 all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_ERROR]++; 290 all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_ERROR].
291 count++;
249 292
250 return; 293 return;
251} 294}
252 295
296static int get_status(u32 index, acpi_event_status *status, acpi_handle *handle)
297{
298 int result = 0;
299
300 if (index >= num_gpes + ACPI_NUM_FIXED_EVENTS)
301 goto end;
302
303 if (index < num_gpes) {
304 result = get_gpe_device(index, handle);
305 if (result) {
306 ACPI_EXCEPTION((AE_INFO, AE_NOT_FOUND,
307 "Invalid GPE 0x%x\n", index));
308 goto end;
309 }
310 result = acpi_get_gpe_status(*handle, index,
311 ACPI_NOT_ISR, status);
312 } else if (index < (num_gpes + ACPI_NUM_FIXED_EVENTS))
313 result = acpi_get_event_status(index - num_gpes, status);
314
315 /*
316 * sleep/power button GPE/Fixed Event is enabled after acpi_system_init,
317 * check the status at runtime and mark it as valid once it's enabled
318 */
319 if (!result && (*status & ACPI_EVENT_FLAG_ENABLED))
320 all_counters[index].flags |= ACPI_EVENT_VALID;
321end:
322 return result;
323}
324
253static ssize_t counter_show(struct kobject *kobj, 325static ssize_t counter_show(struct kobject *kobj,
254 struct kobj_attribute *attr, char *buf) 326 struct kobj_attribute *attr, char *buf)
255{ 327{
256 all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI] = 328 int index = attr - counter_attrs;
329 int size;
330 acpi_handle handle;
331 acpi_event_status status;
332 int result = 0;
333
334 all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI].count =
257 acpi_irq_handled; 335 acpi_irq_handled;
258 all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_GPE] = 336 all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_GPE].count =
259 acpi_gpe_count; 337 acpi_gpe_count;
260 338
261 return sprintf(buf, "%d\n", all_counters[attr - counter_attrs]); 339 size = sprintf(buf, "%8d", all_counters[index].count);
340
341 /* "gpe_all" or "sci" */
342 if (index >= num_gpes + ACPI_NUM_FIXED_EVENTS)
343 goto end;
344
345 result = get_status(index, &status, &handle);
346 if (result)
347 goto end;
348
349 if (!(all_counters[index].flags & ACPI_EVENT_VALID))
350 size += sprintf(buf + size, " invalid");
351 else if (status & ACPI_EVENT_FLAG_ENABLED)
352 size += sprintf(buf + size, " enable");
353 else
354 size += sprintf(buf + size, " disable");
355
356end:
357 size += sprintf(buf + size, "\n");
358 return result ? result : size;
262} 359}
263 360
264/* 361/*
265 * counter_set() sets the specified counter. 362 * counter_set() sets the specified counter.
266 * setting the total "sci" file to any value clears all counters. 363 * setting the total "sci" file to any value clears all counters.
364 * enable/disable/clear a gpe/fixed event in user space.
267 */ 365 */
268static ssize_t counter_set(struct kobject *kobj, 366static ssize_t counter_set(struct kobject *kobj,
269 struct kobj_attribute *attr, const char *buf, size_t size) 367 struct kobj_attribute *attr, const char *buf, size_t size)
270{ 368{
271 int index = attr - counter_attrs; 369 int index = attr - counter_attrs;
370 acpi_event_status status;
371 acpi_handle handle;
372 int result = 0;
272 373
273 if (index == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI) { 374 if (index == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI) {
274 int i; 375 int i;
275 for (i = 0; i < num_counters; ++i) 376 for (i = 0; i < num_counters; ++i)
276 all_counters[i] = 0; 377 all_counters[i].count = 0;
277 acpi_gpe_count = 0; 378 acpi_gpe_count = 0;
278 acpi_irq_handled = 0; 379 acpi_irq_handled = 0;
380 goto end;
381 }
279 382
383 /* show the event status for both GPEs and Fixed Events */
384 result = get_status(index, &status, &handle);
385 if (result)
386 goto end;
387
388 if (!(all_counters[index].flags & ACPI_EVENT_VALID)) {
389 ACPI_DEBUG_PRINT((ACPI_DB_WARN,
390 "Can not change Invalid GPE/Fixed Event status\n"));
391 return -EINVAL;
392 }
393
394 if (index < num_gpes) {
395 if (!strcmp(buf, "disable\n") &&
396 (status & ACPI_EVENT_FLAG_ENABLED))
397 result = acpi_disable_gpe(handle, index, ACPI_NOT_ISR);
398 else if (!strcmp(buf, "enable\n") &&
399 !(status & ACPI_EVENT_FLAG_ENABLED))
400 result = acpi_enable_gpe(handle, index, ACPI_NOT_ISR);
401 else if (!strcmp(buf, "clear\n") &&
402 (status & ACPI_EVENT_FLAG_SET))
403 result = acpi_clear_gpe(handle, index, ACPI_NOT_ISR);
404 else
405 all_counters[index].count = strtoul(buf, NULL, 0);
406 } else if (index < num_gpes + ACPI_NUM_FIXED_EVENTS) {
407 int event = index - num_gpes;
408 if (!strcmp(buf, "disable\n") &&
409 (status & ACPI_EVENT_FLAG_ENABLED))
410 result = acpi_disable_event(event, ACPI_NOT_ISR);
411 else if (!strcmp(buf, "enable\n") &&
412 !(status & ACPI_EVENT_FLAG_ENABLED))
413 result = acpi_enable_event(event, ACPI_NOT_ISR);
414 else if (!strcmp(buf, "clear\n") &&
415 (status & ACPI_EVENT_FLAG_SET))
416 result = acpi_clear_event(event);
417 else
418 all_counters[index].count = strtoul(buf, NULL, 0);
280 } else 419 } else
281 all_counters[index] = strtoul(buf, NULL, 0); 420 all_counters[index].count = strtoul(buf, NULL, 0);
282 421
283 return size; 422 if (ACPI_FAILURE(result))
423 result = -EINVAL;
424end:
425 return result ? result : size;
284} 426}
285 427
286void acpi_irq_stats_init(void) 428void acpi_irq_stats_init(void)
@@ -298,7 +440,8 @@ void acpi_irq_stats_init(void)
298 if (all_attrs == NULL) 440 if (all_attrs == NULL)
299 return; 441 return;
300 442
301 all_counters = kzalloc(sizeof(u32) * (num_counters), GFP_KERNEL); 443 all_counters = kzalloc(sizeof(struct event_counter) * (num_counters),
444 GFP_KERNEL);
302 if (all_counters == NULL) 445 if (all_counters == NULL)
303 goto fail; 446 goto fail;
304 447
diff --git a/drivers/acpi/tables/tbfadt.c b/drivers/acpi/tables/tbfadt.c
index 949d4114eb9f..ccb5b64bbef3 100644
--- a/drivers/acpi/tables/tbfadt.c
+++ b/drivers/acpi/tables/tbfadt.c
@@ -124,7 +124,7 @@ static struct acpi_fadt_info fadt_info_table[] = {
124 124
125static void inline 125static void inline
126acpi_tb_init_generic_address(struct acpi_generic_address *generic_address, 126acpi_tb_init_generic_address(struct acpi_generic_address *generic_address,
127 u8 bit_width, u64 address) 127 u8 byte_width, u64 address)
128{ 128{
129 129
130 /* 130 /*
@@ -136,7 +136,7 @@ acpi_tb_init_generic_address(struct acpi_generic_address *generic_address,
136 /* All other fields are byte-wide */ 136 /* All other fields are byte-wide */
137 137
138 generic_address->space_id = ACPI_ADR_SPACE_SYSTEM_IO; 138 generic_address->space_id = ACPI_ADR_SPACE_SYSTEM_IO;
139 generic_address->bit_width = bit_width; 139 generic_address->bit_width = byte_width << 3;
140 generic_address->bit_offset = 0; 140 generic_address->bit_offset = 0;
141 generic_address->access_width = 0; 141 generic_address->access_width = 0;
142} 142}
@@ -155,7 +155,7 @@ acpi_tb_init_generic_address(struct acpi_generic_address *generic_address,
155 * 155 *
156 ******************************************************************************/ 156 ******************************************************************************/
157 157
158void acpi_tb_parse_fadt(acpi_native_uint table_index, u8 flags) 158void acpi_tb_parse_fadt(u32 table_index, u8 flags)
159{ 159{
160 u32 length; 160 u32 length;
161 struct acpi_table_header *table; 161 struct acpi_table_header *table;
@@ -280,7 +280,7 @@ static void acpi_tb_convert_fadt(void)
280{ 280{
281 u8 pm1_register_length; 281 u8 pm1_register_length;
282 struct acpi_generic_address *target; 282 struct acpi_generic_address *target;
283 acpi_native_uint i; 283 u32 i;
284 284
285 /* Update the local FADT table header length */ 285 /* Update the local FADT table header length */
286 286
@@ -343,9 +343,11 @@ static void acpi_tb_convert_fadt(void)
343 * 343 *
344 * The PM event blocks are split into two register blocks, first is the 344 * The PM event blocks are split into two register blocks, first is the
345 * PM Status Register block, followed immediately by the PM Enable Register 345 * PM Status Register block, followed immediately by the PM Enable Register
346 * block. Each is of length (pm1_event_length/2) 346 * block. Each is of length (xpm1x_event_block.bit_width/2)
347 */ 347 */
348 pm1_register_length = (u8) ACPI_DIV_2(acpi_gbl_FADT.pm1_event_length); 348 WARN_ON(ACPI_MOD_16(acpi_gbl_FADT.xpm1a_event_block.bit_width));
349 pm1_register_length = (u8) ACPI_DIV_16(acpi_gbl_FADT
350 .xpm1a_event_block.bit_width);
349 351
350 /* The PM1A register block is required */ 352 /* The PM1A register block is required */
351 353
@@ -360,14 +362,17 @@ static void acpi_tb_convert_fadt(void)
360 /* The PM1B register block is optional, ignore if not present */ 362 /* The PM1B register block is optional, ignore if not present */
361 363
362 if (acpi_gbl_FADT.xpm1b_event_block.address) { 364 if (acpi_gbl_FADT.xpm1b_event_block.address) {
365 WARN_ON(ACPI_MOD_16(acpi_gbl_FADT.xpm1b_event_block.bit_width));
366 pm1_register_length = (u8) ACPI_DIV_16(acpi_gbl_FADT
367 .xpm1b_event_block
368 .bit_width);
363 acpi_tb_init_generic_address(&acpi_gbl_xpm1b_enable, 369 acpi_tb_init_generic_address(&acpi_gbl_xpm1b_enable,
364 pm1_register_length, 370 pm1_register_length,
365 (acpi_gbl_FADT.xpm1b_event_block. 371 (acpi_gbl_FADT.xpm1b_event_block.
366 address + pm1_register_length)); 372 address + pm1_register_length));
367 /* Don't forget to copy space_id of the GAS */ 373 /* Don't forget to copy space_id of the GAS */
368 acpi_gbl_xpm1b_enable.space_id = 374 acpi_gbl_xpm1b_enable.space_id =
369 acpi_gbl_FADT.xpm1a_event_block.space_id; 375 acpi_gbl_FADT.xpm1b_event_block.space_id;
370
371 } 376 }
372} 377}
373 378
@@ -396,7 +401,7 @@ static void acpi_tb_validate_fadt(void)
396 u32 *address32; 401 u32 *address32;
397 struct acpi_generic_address *address64; 402 struct acpi_generic_address *address64;
398 u8 length; 403 u8 length;
399 acpi_native_uint i; 404 u32 i;
400 405
401 /* Examine all of the 64-bit extended address fields (X fields) */ 406 /* Examine all of the 64-bit extended address fields (X fields) */
402 407
diff --git a/drivers/acpi/tables/tbfind.c b/drivers/acpi/tables/tbfind.c
index 9ca3afc98c80..531584defbb8 100644
--- a/drivers/acpi/tables/tbfind.c
+++ b/drivers/acpi/tables/tbfind.c
@@ -65,10 +65,9 @@ ACPI_MODULE_NAME("tbfind")
65 ******************************************************************************/ 65 ******************************************************************************/
66acpi_status 66acpi_status
67acpi_tb_find_table(char *signature, 67acpi_tb_find_table(char *signature,
68 char *oem_id, 68 char *oem_id, char *oem_table_id, u32 *table_index)
69 char *oem_table_id, acpi_native_uint * table_index)
70{ 69{
71 acpi_native_uint i; 70 u32 i;
72 acpi_status status; 71 acpi_status status;
73 struct acpi_table_header header; 72 struct acpi_table_header header;
74 73
diff --git a/drivers/acpi/tables/tbinstal.c b/drivers/acpi/tables/tbinstal.c
index 5336ce88f89f..b22185f55a16 100644
--- a/drivers/acpi/tables/tbinstal.c
+++ b/drivers/acpi/tables/tbinstal.c
@@ -107,11 +107,10 @@ acpi_status acpi_tb_verify_table(struct acpi_table_desc *table_desc)
107 ******************************************************************************/ 107 ******************************************************************************/
108 108
109acpi_status 109acpi_status
110acpi_tb_add_table(struct acpi_table_desc *table_desc, 110acpi_tb_add_table(struct acpi_table_desc *table_desc, u32 *table_index)
111 acpi_native_uint * table_index)
112{ 111{
113 acpi_native_uint i; 112 u32 i;
114 acpi_native_uint length; 113 u32 length;
115 acpi_status status = AE_OK; 114 acpi_status status = AE_OK;
116 115
117 ACPI_FUNCTION_TRACE(tb_add_table); 116 ACPI_FUNCTION_TRACE(tb_add_table);
@@ -207,8 +206,8 @@ acpi_status acpi_tb_resize_root_table_list(void)
207 206
208 /* Increase the Table Array size */ 207 /* Increase the Table Array size */
209 208
210 tables = ACPI_ALLOCATE_ZEROED((acpi_gbl_root_table_list.size + 209 tables = ACPI_ALLOCATE_ZEROED(((acpi_size) acpi_gbl_root_table_list.
211 ACPI_ROOT_TABLE_SIZE_INCREMENT) 210 size + ACPI_ROOT_TABLE_SIZE_INCREMENT)
212 * sizeof(struct acpi_table_desc)); 211 * sizeof(struct acpi_table_desc));
213 if (!tables) { 212 if (!tables) {
214 ACPI_ERROR((AE_INFO, 213 ACPI_ERROR((AE_INFO,
@@ -220,7 +219,7 @@ acpi_status acpi_tb_resize_root_table_list(void)
220 219
221 if (acpi_gbl_root_table_list.tables) { 220 if (acpi_gbl_root_table_list.tables) {
222 ACPI_MEMCPY(tables, acpi_gbl_root_table_list.tables, 221 ACPI_MEMCPY(tables, acpi_gbl_root_table_list.tables,
223 acpi_gbl_root_table_list.size * 222 (acpi_size) acpi_gbl_root_table_list.size *
224 sizeof(struct acpi_table_desc)); 223 sizeof(struct acpi_table_desc));
225 224
226 if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) { 225 if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
@@ -253,7 +252,7 @@ acpi_status acpi_tb_resize_root_table_list(void)
253acpi_status 252acpi_status
254acpi_tb_store_table(acpi_physical_address address, 253acpi_tb_store_table(acpi_physical_address address,
255 struct acpi_table_header *table, 254 struct acpi_table_header *table,
256 u32 length, u8 flags, acpi_native_uint * table_index) 255 u32 length, u8 flags, u32 *table_index)
257{ 256{
258 acpi_status status = AE_OK; 257 acpi_status status = AE_OK;
259 258
@@ -334,7 +333,7 @@ void acpi_tb_delete_table(struct acpi_table_desc *table_desc)
334 333
335void acpi_tb_terminate(void) 334void acpi_tb_terminate(void)
336{ 335{
337 acpi_native_uint i; 336 u32 i;
338 337
339 ACPI_FUNCTION_TRACE(tb_terminate); 338 ACPI_FUNCTION_TRACE(tb_terminate);
340 339
@@ -374,7 +373,7 @@ void acpi_tb_terminate(void)
374 * 373 *
375 ******************************************************************************/ 374 ******************************************************************************/
376 375
377void acpi_tb_delete_namespace_by_owner(acpi_native_uint table_index) 376void acpi_tb_delete_namespace_by_owner(u32 table_index)
378{ 377{
379 acpi_owner_id owner_id; 378 acpi_owner_id owner_id;
380 379
@@ -403,7 +402,7 @@ void acpi_tb_delete_namespace_by_owner(acpi_native_uint table_index)
403 * 402 *
404 ******************************************************************************/ 403 ******************************************************************************/
405 404
406acpi_status acpi_tb_allocate_owner_id(acpi_native_uint table_index) 405acpi_status acpi_tb_allocate_owner_id(u32 table_index)
407{ 406{
408 acpi_status status = AE_BAD_PARAMETER; 407 acpi_status status = AE_BAD_PARAMETER;
409 408
@@ -431,7 +430,7 @@ acpi_status acpi_tb_allocate_owner_id(acpi_native_uint table_index)
431 * 430 *
432 ******************************************************************************/ 431 ******************************************************************************/
433 432
434acpi_status acpi_tb_release_owner_id(acpi_native_uint table_index) 433acpi_status acpi_tb_release_owner_id(u32 table_index)
435{ 434{
436 acpi_status status = AE_BAD_PARAMETER; 435 acpi_status status = AE_BAD_PARAMETER;
437 436
@@ -462,8 +461,7 @@ acpi_status acpi_tb_release_owner_id(acpi_native_uint table_index)
462 * 461 *
463 ******************************************************************************/ 462 ******************************************************************************/
464 463
465acpi_status 464acpi_status acpi_tb_get_owner_id(u32 table_index, acpi_owner_id *owner_id)
466acpi_tb_get_owner_id(acpi_native_uint table_index, acpi_owner_id * owner_id)
467{ 465{
468 acpi_status status = AE_BAD_PARAMETER; 466 acpi_status status = AE_BAD_PARAMETER;
469 467
@@ -490,7 +488,7 @@ acpi_tb_get_owner_id(acpi_native_uint table_index, acpi_owner_id * owner_id)
490 * 488 *
491 ******************************************************************************/ 489 ******************************************************************************/
492 490
493u8 acpi_tb_is_table_loaded(acpi_native_uint table_index) 491u8 acpi_tb_is_table_loaded(u32 table_index)
494{ 492{
495 u8 is_loaded = FALSE; 493 u8 is_loaded = FALSE;
496 494
@@ -518,7 +516,7 @@ u8 acpi_tb_is_table_loaded(acpi_native_uint table_index)
518 * 516 *
519 ******************************************************************************/ 517 ******************************************************************************/
520 518
521void acpi_tb_set_table_loaded_flag(acpi_native_uint table_index, u8 is_loaded) 519void acpi_tb_set_table_loaded_flag(u32 table_index, u8 is_loaded)
522{ 520{
523 521
524 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); 522 (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
diff --git a/drivers/acpi/tables/tbutils.c b/drivers/acpi/tables/tbutils.c
index bc019b9b6a68..0cc92ef5236f 100644
--- a/drivers/acpi/tables/tbutils.c
+++ b/drivers/acpi/tables/tbutils.c
@@ -49,8 +49,8 @@ ACPI_MODULE_NAME("tbutils")
49 49
50/* Local prototypes */ 50/* Local prototypes */
51static acpi_physical_address 51static acpi_physical_address
52acpi_tb_get_root_table_entry(u8 * table_entry, 52acpi_tb_get_root_table_entry(u8 *table_entry, u32 table_entry_size);
53 acpi_native_uint table_entry_size); 53
54/******************************************************************************* 54/*******************************************************************************
55 * 55 *
56 * FUNCTION: acpi_tb_check_xsdt 56 * FUNCTION: acpi_tb_check_xsdt
@@ -238,7 +238,7 @@ acpi_status acpi_tb_verify_checksum(struct acpi_table_header *table, u32 length)
238 * 238 *
239 ******************************************************************************/ 239 ******************************************************************************/
240 240
241u8 acpi_tb_checksum(u8 * buffer, acpi_native_uint length) 241u8 acpi_tb_checksum(u8 *buffer, u32 length)
242{ 242{
243 u8 sum = 0; 243 u8 sum = 0;
244 u8 *end = buffer + length; 244 u8 *end = buffer + length;
@@ -268,7 +268,7 @@ u8 acpi_tb_checksum(u8 * buffer, acpi_native_uint length)
268 268
269void 269void
270acpi_tb_install_table(acpi_physical_address address, 270acpi_tb_install_table(acpi_physical_address address,
271 u8 flags, char *signature, acpi_native_uint table_index) 271 u8 flags, char *signature, u32 table_index)
272{ 272{
273 struct acpi_table_header *table; 273 struct acpi_table_header *table;
274 274
@@ -336,8 +336,7 @@ acpi_tb_install_table(acpi_physical_address address,
336 ******************************************************************************/ 336 ******************************************************************************/
337 337
338static acpi_physical_address 338static acpi_physical_address
339acpi_tb_get_root_table_entry(u8 * table_entry, 339acpi_tb_get_root_table_entry(u8 *table_entry, u32 table_entry_size)
340 acpi_native_uint table_entry_size)
341{ 340{
342 u64 address64; 341 u64 address64;
343 342
@@ -395,8 +394,8 @@ acpi_status __init
395acpi_tb_parse_root_table(acpi_physical_address rsdp_address, u8 flags) 394acpi_tb_parse_root_table(acpi_physical_address rsdp_address, u8 flags)
396{ 395{
397 struct acpi_table_rsdp *rsdp; 396 struct acpi_table_rsdp *rsdp;
398 acpi_native_uint table_entry_size; 397 u32 table_entry_size;
399 acpi_native_uint i; 398 u32 i;
400 u32 table_count; 399 u32 table_count;
401 struct acpi_table_header *table; 400 struct acpi_table_header *table;
402 acpi_physical_address address; 401 acpi_physical_address address;
diff --git a/drivers/acpi/tables/tbxface.c b/drivers/acpi/tables/tbxface.c
index 0e319604d3e7..fd7770aa1061 100644
--- a/drivers/acpi/tables/tbxface.c
+++ b/drivers/acpi/tables/tbxface.c
@@ -125,7 +125,7 @@ acpi_initialize_tables(struct acpi_table_desc * initial_table_array,
125 /* Root Table Array has been statically allocated by the host */ 125 /* Root Table Array has been statically allocated by the host */
126 126
127 ACPI_MEMSET(initial_table_array, 0, 127 ACPI_MEMSET(initial_table_array, 0,
128 initial_table_count * 128 (acpi_size) initial_table_count *
129 sizeof(struct acpi_table_desc)); 129 sizeof(struct acpi_table_desc));
130 130
131 acpi_gbl_root_table_list.tables = initial_table_array; 131 acpi_gbl_root_table_list.tables = initial_table_array;
@@ -183,9 +183,9 @@ acpi_status acpi_reallocate_root_table(void)
183 return_ACPI_STATUS(AE_SUPPORT); 183 return_ACPI_STATUS(AE_SUPPORT);
184 } 184 }
185 185
186 new_size = 186 new_size = ((acpi_size) acpi_gbl_root_table_list.count +
187 (acpi_gbl_root_table_list.count + 187 ACPI_ROOT_TABLE_SIZE_INCREMENT) *
188 ACPI_ROOT_TABLE_SIZE_INCREMENT) * sizeof(struct acpi_table_desc); 188 sizeof(struct acpi_table_desc);
189 189
190 /* Create new array and copy the old array */ 190 /* Create new array and copy the old array */
191 191
@@ -222,7 +222,7 @@ acpi_status acpi_reallocate_root_table(void)
222acpi_status acpi_load_table(struct acpi_table_header *table_ptr) 222acpi_status acpi_load_table(struct acpi_table_header *table_ptr)
223{ 223{
224 acpi_status status; 224 acpi_status status;
225 acpi_native_uint table_index; 225 u32 table_index;
226 struct acpi_table_desc table_desc; 226 struct acpi_table_desc table_desc;
227 227
228 if (!table_ptr) 228 if (!table_ptr)
@@ -264,11 +264,10 @@ ACPI_EXPORT_SYMBOL(acpi_load_table)
264 *****************************************************************************/ 264 *****************************************************************************/
265acpi_status 265acpi_status
266acpi_get_table_header(char *signature, 266acpi_get_table_header(char *signature,
267 acpi_native_uint instance, 267 u32 instance, struct acpi_table_header *out_table_header)
268 struct acpi_table_header * out_table_header)
269{ 268{
270 acpi_native_uint i; 269 u32 i;
271 acpi_native_uint j; 270 u32 j;
272 struct acpi_table_header *header; 271 struct acpi_table_header *header;
273 272
274 /* Parameter validation */ 273 /* Parameter validation */
@@ -378,10 +377,10 @@ ACPI_EXPORT_SYMBOL(acpi_unload_table_id)
378 *****************************************************************************/ 377 *****************************************************************************/
379acpi_status 378acpi_status
380acpi_get_table(char *signature, 379acpi_get_table(char *signature,
381 acpi_native_uint instance, struct acpi_table_header **out_table) 380 u32 instance, struct acpi_table_header **out_table)
382{ 381{
383 acpi_native_uint i; 382 u32 i;
384 acpi_native_uint j; 383 u32 j;
385 acpi_status status; 384 acpi_status status;
386 385
387 /* Parameter validation */ 386 /* Parameter validation */
@@ -435,8 +434,7 @@ ACPI_EXPORT_SYMBOL(acpi_get_table)
435 * 434 *
436 ******************************************************************************/ 435 ******************************************************************************/
437acpi_status 436acpi_status
438acpi_get_table_by_index(acpi_native_uint table_index, 437acpi_get_table_by_index(u32 table_index, struct acpi_table_header **table)
439 struct acpi_table_header ** table)
440{ 438{
441 acpi_status status; 439 acpi_status status;
442 440
@@ -493,7 +491,7 @@ static acpi_status acpi_tb_load_namespace(void)
493{ 491{
494 acpi_status status; 492 acpi_status status;
495 struct acpi_table_header *table; 493 struct acpi_table_header *table;
496 acpi_native_uint i; 494 u32 i;
497 495
498 ACPI_FUNCTION_TRACE(tb_load_namespace); 496 ACPI_FUNCTION_TRACE(tb_load_namespace);
499 497
diff --git a/drivers/acpi/tables/tbxfroot.c b/drivers/acpi/tables/tbxfroot.c
index b8c0dfa084f6..2d157e0f98d2 100644
--- a/drivers/acpi/tables/tbxfroot.c
+++ b/drivers/acpi/tables/tbxfroot.c
@@ -118,7 +118,7 @@ static acpi_status acpi_tb_validate_rsdp(struct acpi_table_rsdp *rsdp)
118 * 118 *
119 ******************************************************************************/ 119 ******************************************************************************/
120 120
121acpi_status acpi_find_root_pointer(acpi_native_uint * table_address) 121acpi_status acpi_find_root_pointer(acpi_size *table_address)
122{ 122{
123 u8 *table_ptr; 123 u8 *table_ptr;
124 u8 *mem_rover; 124 u8 *mem_rover;
@@ -153,7 +153,7 @@ acpi_status acpi_find_root_pointer(acpi_native_uint * table_address)
153 * 1b) Search EBDA paragraphs (EBDA is required to be a 153 * 1b) Search EBDA paragraphs (EBDA is required to be a
154 * minimum of 1_k length) 154 * minimum of 1_k length)
155 */ 155 */
156 table_ptr = acpi_os_map_memory((acpi_native_uint) 156 table_ptr = acpi_os_map_memory((acpi_physical_address)
157 physical_address, 157 physical_address,
158 ACPI_EBDA_WINDOW_SIZE); 158 ACPI_EBDA_WINDOW_SIZE);
159 if (!table_ptr) { 159 if (!table_ptr) {
diff --git a/drivers/acpi/utilities/utalloc.c b/drivers/acpi/utilities/utalloc.c
index ede084829a70..3dfb8a442b26 100644
--- a/drivers/acpi/utilities/utalloc.c
+++ b/drivers/acpi/utilities/utalloc.c
@@ -309,7 +309,8 @@ acpi_ut_initialize_buffer(struct acpi_buffer * buffer,
309 * 309 *
310 ******************************************************************************/ 310 ******************************************************************************/
311 311
312void *acpi_ut_allocate(acpi_size size, u32 component, char *module, u32 line) 312void *acpi_ut_allocate(acpi_size size,
313 u32 component, const char *module, u32 line)
313{ 314{
314 void *allocation; 315 void *allocation;
315 316
@@ -353,7 +354,7 @@ void *acpi_ut_allocate(acpi_size size, u32 component, char *module, u32 line)
353 ******************************************************************************/ 354 ******************************************************************************/
354 355
355void *acpi_ut_allocate_zeroed(acpi_size size, 356void *acpi_ut_allocate_zeroed(acpi_size size,
356 u32 component, char *module, u32 line) 357 u32 component, const char *module, u32 line)
357{ 358{
358 void *allocation; 359 void *allocation;
359 360
diff --git a/drivers/acpi/utilities/utcopy.c b/drivers/acpi/utilities/utcopy.c
index 655c290aca7b..53499ac90988 100644
--- a/drivers/acpi/utilities/utcopy.c
+++ b/drivers/acpi/utilities/utcopy.c
@@ -572,7 +572,7 @@ acpi_ut_copy_epackage_to_ipackage(union acpi_object *external_object,
572 acpi_status status = AE_OK; 572 acpi_status status = AE_OK;
573 union acpi_operand_object *package_object; 573 union acpi_operand_object *package_object;
574 union acpi_operand_object **package_elements; 574 union acpi_operand_object **package_elements;
575 acpi_native_uint i; 575 u32 i;
576 576
577 ACPI_FUNCTION_TRACE(ut_copy_epackage_to_ipackage); 577 ACPI_FUNCTION_TRACE(ut_copy_epackage_to_ipackage);
578 578
@@ -599,7 +599,7 @@ acpi_ut_copy_epackage_to_ipackage(union acpi_object *external_object,
599 599
600 /* Truncate package and delete it */ 600 /* Truncate package and delete it */
601 601
602 package_object->package.count = (u32) i; 602 package_object->package.count = i;
603 package_elements[i] = NULL; 603 package_elements[i] = NULL;
604 acpi_ut_remove_reference(package_object); 604 acpi_ut_remove_reference(package_object);
605 return_ACPI_STATUS(status); 605 return_ACPI_STATUS(status);
diff --git a/drivers/acpi/utilities/utdebug.c b/drivers/acpi/utilities/utdebug.c
index f938f465efa4..fd66ecb6741e 100644
--- a/drivers/acpi/utilities/utdebug.c
+++ b/drivers/acpi/utilities/utdebug.c
@@ -157,7 +157,8 @@ void ACPI_INTERNAL_VAR_XFACE
157acpi_ut_debug_print(u32 requested_debug_level, 157acpi_ut_debug_print(u32 requested_debug_level,
158 u32 line_number, 158 u32 line_number,
159 const char *function_name, 159 const char *function_name,
160 char *module_name, u32 component_id, char *format, ...) 160 const char *module_name,
161 u32 component_id, const char *format, ...)
161{ 162{
162 acpi_thread_id thread_id; 163 acpi_thread_id thread_id;
163 va_list args; 164 va_list args;
@@ -228,7 +229,8 @@ void ACPI_INTERNAL_VAR_XFACE
228acpi_ut_debug_print_raw(u32 requested_debug_level, 229acpi_ut_debug_print_raw(u32 requested_debug_level,
229 u32 line_number, 230 u32 line_number,
230 const char *function_name, 231 const char *function_name,
231 char *module_name, u32 component_id, char *format, ...) 232 const char *module_name,
233 u32 component_id, const char *format, ...)
232{ 234{
233 va_list args; 235 va_list args;
234 236
@@ -261,7 +263,8 @@ ACPI_EXPORT_SYMBOL(acpi_ut_debug_print_raw)
261 ******************************************************************************/ 263 ******************************************************************************/
262void 264void
263acpi_ut_trace(u32 line_number, 265acpi_ut_trace(u32 line_number,
264 const char *function_name, char *module_name, u32 component_id) 266 const char *function_name,
267 const char *module_name, u32 component_id)
265{ 268{
266 269
267 acpi_gbl_nesting_level++; 270 acpi_gbl_nesting_level++;
@@ -293,7 +296,7 @@ ACPI_EXPORT_SYMBOL(acpi_ut_trace)
293void 296void
294acpi_ut_trace_ptr(u32 line_number, 297acpi_ut_trace_ptr(u32 line_number,
295 const char *function_name, 298 const char *function_name,
296 char *module_name, u32 component_id, void *pointer) 299 const char *module_name, u32 component_id, void *pointer)
297{ 300{
298 acpi_gbl_nesting_level++; 301 acpi_gbl_nesting_level++;
299 acpi_ut_track_stack_ptr(); 302 acpi_ut_track_stack_ptr();
@@ -324,7 +327,7 @@ acpi_ut_trace_ptr(u32 line_number,
324void 327void
325acpi_ut_trace_str(u32 line_number, 328acpi_ut_trace_str(u32 line_number,
326 const char *function_name, 329 const char *function_name,
327 char *module_name, u32 component_id, char *string) 330 const char *module_name, u32 component_id, char *string)
328{ 331{
329 332
330 acpi_gbl_nesting_level++; 333 acpi_gbl_nesting_level++;
@@ -356,7 +359,7 @@ acpi_ut_trace_str(u32 line_number,
356void 359void
357acpi_ut_trace_u32(u32 line_number, 360acpi_ut_trace_u32(u32 line_number,
358 const char *function_name, 361 const char *function_name,
359 char *module_name, u32 component_id, u32 integer) 362 const char *module_name, u32 component_id, u32 integer)
360{ 363{
361 364
362 acpi_gbl_nesting_level++; 365 acpi_gbl_nesting_level++;
@@ -386,7 +389,8 @@ acpi_ut_trace_u32(u32 line_number,
386 389
387void 390void
388acpi_ut_exit(u32 line_number, 391acpi_ut_exit(u32 line_number,
389 const char *function_name, char *module_name, u32 component_id) 392 const char *function_name,
393 const char *module_name, u32 component_id)
390{ 394{
391 395
392 acpi_ut_debug_print(ACPI_LV_FUNCTIONS, 396 acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
@@ -417,7 +421,8 @@ ACPI_EXPORT_SYMBOL(acpi_ut_exit)
417void 421void
418acpi_ut_status_exit(u32 line_number, 422acpi_ut_status_exit(u32 line_number,
419 const char *function_name, 423 const char *function_name,
420 char *module_name, u32 component_id, acpi_status status) 424 const char *module_name,
425 u32 component_id, acpi_status status)
421{ 426{
422 427
423 if (ACPI_SUCCESS(status)) { 428 if (ACPI_SUCCESS(status)) {
@@ -458,7 +463,8 @@ ACPI_EXPORT_SYMBOL(acpi_ut_status_exit)
458void 463void
459acpi_ut_value_exit(u32 line_number, 464acpi_ut_value_exit(u32 line_number,
460 const char *function_name, 465 const char *function_name,
461 char *module_name, u32 component_id, acpi_integer value) 466 const char *module_name,
467 u32 component_id, acpi_integer value)
462{ 468{
463 469
464 acpi_ut_debug_print(ACPI_LV_FUNCTIONS, 470 acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
@@ -490,7 +496,7 @@ ACPI_EXPORT_SYMBOL(acpi_ut_value_exit)
490void 496void
491acpi_ut_ptr_exit(u32 line_number, 497acpi_ut_ptr_exit(u32 line_number,
492 const char *function_name, 498 const char *function_name,
493 char *module_name, u32 component_id, u8 * ptr) 499 const char *module_name, u32 component_id, u8 *ptr)
494{ 500{
495 501
496 acpi_ut_debug_print(ACPI_LV_FUNCTIONS, 502 acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
@@ -519,8 +525,8 @@ acpi_ut_ptr_exit(u32 line_number,
519 525
520void acpi_ut_dump_buffer2(u8 * buffer, u32 count, u32 display) 526void acpi_ut_dump_buffer2(u8 * buffer, u32 count, u32 display)
521{ 527{
522 acpi_native_uint i = 0; 528 u32 i = 0;
523 acpi_native_uint j; 529 u32 j;
524 u32 temp32; 530 u32 temp32;
525 u8 buf_char; 531 u8 buf_char;
526 532
@@ -539,7 +545,7 @@ void acpi_ut_dump_buffer2(u8 * buffer, u32 count, u32 display)
539 545
540 /* Print current offset */ 546 /* Print current offset */
541 547
542 acpi_os_printf("%6.4X: ", (u32) i); 548 acpi_os_printf("%6.4X: ", i);
543 549
544 /* Print 16 hex chars */ 550 /* Print 16 hex chars */
545 551
@@ -549,7 +555,7 @@ void acpi_ut_dump_buffer2(u8 * buffer, u32 count, u32 display)
549 /* Dump fill spaces */ 555 /* Dump fill spaces */
550 556
551 acpi_os_printf("%*s", ((display * 2) + 1), " "); 557 acpi_os_printf("%*s", ((display * 2) + 1), " ");
552 j += (acpi_native_uint) display; 558 j += display;
553 continue; 559 continue;
554 } 560 }
555 561
@@ -557,32 +563,38 @@ void acpi_ut_dump_buffer2(u8 * buffer, u32 count, u32 display)
557 case DB_BYTE_DISPLAY: 563 case DB_BYTE_DISPLAY:
558 default: /* Default is BYTE display */ 564 default: /* Default is BYTE display */
559 565
560 acpi_os_printf("%02X ", buffer[i + j]); 566 acpi_os_printf("%02X ",
567 buffer[(acpi_size) i + j]);
561 break; 568 break;
562 569
563 case DB_WORD_DISPLAY: 570 case DB_WORD_DISPLAY:
564 571
565 ACPI_MOVE_16_TO_32(&temp32, &buffer[i + j]); 572 ACPI_MOVE_16_TO_32(&temp32,
573 &buffer[(acpi_size) i + j]);
566 acpi_os_printf("%04X ", temp32); 574 acpi_os_printf("%04X ", temp32);
567 break; 575 break;
568 576
569 case DB_DWORD_DISPLAY: 577 case DB_DWORD_DISPLAY:
570 578
571 ACPI_MOVE_32_TO_32(&temp32, &buffer[i + j]); 579 ACPI_MOVE_32_TO_32(&temp32,
580 &buffer[(acpi_size) i + j]);
572 acpi_os_printf("%08X ", temp32); 581 acpi_os_printf("%08X ", temp32);
573 break; 582 break;
574 583
575 case DB_QWORD_DISPLAY: 584 case DB_QWORD_DISPLAY:
576 585
577 ACPI_MOVE_32_TO_32(&temp32, &buffer[i + j]); 586 ACPI_MOVE_32_TO_32(&temp32,
587 &buffer[(acpi_size) i + j]);
578 acpi_os_printf("%08X", temp32); 588 acpi_os_printf("%08X", temp32);
579 589
580 ACPI_MOVE_32_TO_32(&temp32, &buffer[i + j + 4]); 590 ACPI_MOVE_32_TO_32(&temp32,
591 &buffer[(acpi_size) i + j +
592 4]);
581 acpi_os_printf("%08X ", temp32); 593 acpi_os_printf("%08X ", temp32);
582 break; 594 break;
583 } 595 }
584 596
585 j += (acpi_native_uint) display; 597 j += display;
586 } 598 }
587 599
588 /* 600 /*
@@ -596,7 +608,7 @@ void acpi_ut_dump_buffer2(u8 * buffer, u32 count, u32 display)
596 return; 608 return;
597 } 609 }
598 610
599 buf_char = buffer[i + j]; 611 buf_char = buffer[(acpi_size) i + j];
600 if (ACPI_IS_PRINT(buf_char)) { 612 if (ACPI_IS_PRINT(buf_char)) {
601 acpi_os_printf("%c", buf_char); 613 acpi_os_printf("%c", buf_char);
602 } else { 614 } else {
diff --git a/drivers/acpi/utilities/utdelete.c b/drivers/acpi/utilities/utdelete.c
index 1fbc35139e84..c5c791a575c9 100644
--- a/drivers/acpi/utilities/utdelete.c
+++ b/drivers/acpi/utilities/utdelete.c
@@ -442,7 +442,7 @@ acpi_ut_update_object_reference(union acpi_operand_object *object, u16 action)
442 union acpi_generic_state *state_list = NULL; 442 union acpi_generic_state *state_list = NULL;
443 union acpi_operand_object *next_object = NULL; 443 union acpi_operand_object *next_object = NULL;
444 union acpi_generic_state *state; 444 union acpi_generic_state *state;
445 acpi_native_uint i; 445 u32 i;
446 446
447 ACPI_FUNCTION_TRACE_PTR(ut_update_object_reference, object); 447 ACPI_FUNCTION_TRACE_PTR(ut_update_object_reference, object);
448 448
diff --git a/drivers/acpi/utilities/uteval.c b/drivers/acpi/utilities/uteval.c
index 05e61be267d5..352747e49c7a 100644
--- a/drivers/acpi/utilities/uteval.c
+++ b/drivers/acpi/utilities/uteval.c
@@ -97,7 +97,7 @@ acpi_status acpi_ut_osi_implementation(struct acpi_walk_state *walk_state)
97 acpi_status status; 97 acpi_status status;
98 union acpi_operand_object *string_desc; 98 union acpi_operand_object *string_desc;
99 union acpi_operand_object *return_desc; 99 union acpi_operand_object *return_desc;
100 acpi_native_uint i; 100 u32 i;
101 101
102 ACPI_FUNCTION_TRACE(ut_osi_implementation); 102 ACPI_FUNCTION_TRACE(ut_osi_implementation);
103 103
@@ -217,7 +217,6 @@ acpi_ut_evaluate_object(struct acpi_namespace_node *prefix_node,
217 217
218 info->prefix_node = prefix_node; 218 info->prefix_node = prefix_node;
219 info->pathname = path; 219 info->pathname = path;
220 info->parameter_type = ACPI_PARAM_ARGS;
221 220
222 /* Evaluate the object/method */ 221 /* Evaluate the object/method */
223 222
@@ -514,7 +513,7 @@ acpi_ut_execute_CID(struct acpi_namespace_node * device_node,
514 u32 count; 513 u32 count;
515 u32 size; 514 u32 size;
516 struct acpi_compatible_id_list *cid_list; 515 struct acpi_compatible_id_list *cid_list;
517 acpi_native_uint i; 516 u32 i;
518 517
519 ACPI_FUNCTION_TRACE(ut_execute_CID); 518 ACPI_FUNCTION_TRACE(ut_execute_CID);
520 519
diff --git a/drivers/acpi/utilities/utmisc.c b/drivers/acpi/utilities/utmisc.c
index 1f057b71db1a..f34be6773556 100644
--- a/drivers/acpi/utilities/utmisc.c
+++ b/drivers/acpi/utilities/utmisc.c
@@ -64,7 +64,7 @@ ACPI_MODULE_NAME("utmisc")
64 ******************************************************************************/ 64 ******************************************************************************/
65const char *acpi_ut_validate_exception(acpi_status status) 65const char *acpi_ut_validate_exception(acpi_status status)
66{ 66{
67 acpi_status sub_status; 67 u32 sub_status;
68 const char *exception = NULL; 68 const char *exception = NULL;
69 69
70 ACPI_FUNCTION_ENTRY(); 70 ACPI_FUNCTION_ENTRY();
@@ -85,32 +85,28 @@ const char *acpi_ut_validate_exception(acpi_status status)
85 case AE_CODE_PROGRAMMER: 85 case AE_CODE_PROGRAMMER:
86 86
87 if (sub_status <= AE_CODE_PGM_MAX) { 87 if (sub_status <= AE_CODE_PGM_MAX) {
88 exception = 88 exception = acpi_gbl_exception_names_pgm[sub_status];
89 acpi_gbl_exception_names_pgm[sub_status - 1];
90 } 89 }
91 break; 90 break;
92 91
93 case AE_CODE_ACPI_TABLES: 92 case AE_CODE_ACPI_TABLES:
94 93
95 if (sub_status <= AE_CODE_TBL_MAX) { 94 if (sub_status <= AE_CODE_TBL_MAX) {
96 exception = 95 exception = acpi_gbl_exception_names_tbl[sub_status];
97 acpi_gbl_exception_names_tbl[sub_status - 1];
98 } 96 }
99 break; 97 break;
100 98
101 case AE_CODE_AML: 99 case AE_CODE_AML:
102 100
103 if (sub_status <= AE_CODE_AML_MAX) { 101 if (sub_status <= AE_CODE_AML_MAX) {
104 exception = 102 exception = acpi_gbl_exception_names_aml[sub_status];
105 acpi_gbl_exception_names_aml[sub_status - 1];
106 } 103 }
107 break; 104 break;
108 105
109 case AE_CODE_CONTROL: 106 case AE_CODE_CONTROL:
110 107
111 if (sub_status <= AE_CODE_CTRL_MAX) { 108 if (sub_status <= AE_CODE_CTRL_MAX) {
112 exception = 109 exception = acpi_gbl_exception_names_ctrl[sub_status];
113 acpi_gbl_exception_names_ctrl[sub_status - 1];
114 } 110 }
115 break; 111 break;
116 112
@@ -165,9 +161,9 @@ u8 acpi_ut_is_aml_table(struct acpi_table_header *table)
165 161
166acpi_status acpi_ut_allocate_owner_id(acpi_owner_id * owner_id) 162acpi_status acpi_ut_allocate_owner_id(acpi_owner_id * owner_id)
167{ 163{
168 acpi_native_uint i; 164 u32 i;
169 acpi_native_uint j; 165 u32 j;
170 acpi_native_uint k; 166 u32 k;
171 acpi_status status; 167 acpi_status status;
172 168
173 ACPI_FUNCTION_TRACE(ut_allocate_owner_id); 169 ACPI_FUNCTION_TRACE(ut_allocate_owner_id);
@@ -273,7 +269,7 @@ void acpi_ut_release_owner_id(acpi_owner_id * owner_id_ptr)
273{ 269{
274 acpi_owner_id owner_id = *owner_id_ptr; 270 acpi_owner_id owner_id = *owner_id_ptr;
275 acpi_status status; 271 acpi_status status;
276 acpi_native_uint index; 272 u32 index;
277 u32 bit; 273 u32 bit;
278 274
279 ACPI_FUNCTION_TRACE_U32(ut_release_owner_id, owner_id); 275 ACPI_FUNCTION_TRACE_U32(ut_release_owner_id, owner_id);
@@ -593,7 +589,7 @@ acpi_ut_display_init_pathname(u8 type,
593 * 589 *
594 ******************************************************************************/ 590 ******************************************************************************/
595 591
596u8 acpi_ut_valid_acpi_char(char character, acpi_native_uint position) 592u8 acpi_ut_valid_acpi_char(char character, u32 position)
597{ 593{
598 594
599 if (!((character >= 'A' && character <= 'Z') || 595 if (!((character >= 'A' && character <= 'Z') ||
@@ -628,7 +624,7 @@ u8 acpi_ut_valid_acpi_char(char character, acpi_native_uint position)
628 624
629u8 acpi_ut_valid_acpi_name(u32 name) 625u8 acpi_ut_valid_acpi_name(u32 name)
630{ 626{
631 acpi_native_uint i; 627 u32 i;
632 628
633 ACPI_FUNCTION_ENTRY(); 629 ACPI_FUNCTION_ENTRY();
634 630
@@ -657,7 +653,7 @@ u8 acpi_ut_valid_acpi_name(u32 name)
657 653
658acpi_name acpi_ut_repair_name(char *name) 654acpi_name acpi_ut_repair_name(char *name)
659{ 655{
660 acpi_native_uint i; 656 u32 i;
661 char new_name[ACPI_NAME_SIZE]; 657 char new_name[ACPI_NAME_SIZE];
662 658
663 for (i = 0; i < ACPI_NAME_SIZE; i++) { 659 for (i = 0; i < ACPI_NAME_SIZE; i++) {
@@ -1024,7 +1020,7 @@ acpi_ut_walk_package_tree(union acpi_operand_object * source_object,
1024 ******************************************************************************/ 1020 ******************************************************************************/
1025 1021
1026void ACPI_INTERNAL_VAR_XFACE 1022void ACPI_INTERNAL_VAR_XFACE
1027acpi_ut_error(char *module_name, u32 line_number, char *format, ...) 1023acpi_ut_error(const char *module_name, u32 line_number, const char *format, ...)
1028{ 1024{
1029 va_list args; 1025 va_list args;
1030 1026
@@ -1037,8 +1033,8 @@ acpi_ut_error(char *module_name, u32 line_number, char *format, ...)
1037} 1033}
1038 1034
1039void ACPI_INTERNAL_VAR_XFACE 1035void ACPI_INTERNAL_VAR_XFACE
1040acpi_ut_exception(char *module_name, 1036acpi_ut_exception(const char *module_name,
1041 u32 line_number, acpi_status status, char *format, ...) 1037 u32 line_number, acpi_status status, const char *format, ...)
1042{ 1038{
1043 va_list args; 1039 va_list args;
1044 1040
@@ -1054,7 +1050,8 @@ acpi_ut_exception(char *module_name,
1054EXPORT_SYMBOL(acpi_ut_exception); 1050EXPORT_SYMBOL(acpi_ut_exception);
1055 1051
1056void ACPI_INTERNAL_VAR_XFACE 1052void ACPI_INTERNAL_VAR_XFACE
1057acpi_ut_warning(char *module_name, u32 line_number, char *format, ...) 1053acpi_ut_warning(const char *module_name,
1054 u32 line_number, const char *format, ...)
1058{ 1055{
1059 va_list args; 1056 va_list args;
1060 1057
@@ -1067,7 +1064,7 @@ acpi_ut_warning(char *module_name, u32 line_number, char *format, ...)
1067} 1064}
1068 1065
1069void ACPI_INTERNAL_VAR_XFACE 1066void ACPI_INTERNAL_VAR_XFACE
1070acpi_ut_info(char *module_name, u32 line_number, char *format, ...) 1067acpi_ut_info(const char *module_name, u32 line_number, const char *format, ...)
1071{ 1068{
1072 va_list args; 1069 va_list args;
1073 1070
diff --git a/drivers/acpi/utilities/utmutex.c b/drivers/acpi/utilities/utmutex.c
index f7d602b1a894..7331dde9e1b3 100644
--- a/drivers/acpi/utilities/utmutex.c
+++ b/drivers/acpi/utilities/utmutex.c
@@ -218,7 +218,7 @@ acpi_status acpi_ut_acquire_mutex(acpi_mutex_handle mutex_id)
218 * the mutex ordering rule. This indicates a coding error somewhere in 218 * the mutex ordering rule. This indicates a coding error somewhere in
219 * the ACPI subsystem code. 219 * the ACPI subsystem code.
220 */ 220 */
221 for (i = mutex_id; i < ACPI_MAX_MUTEX; i++) { 221 for (i = mutex_id; i < ACPI_NUM_MUTEX; i++) {
222 if (acpi_gbl_mutex_info[i].thread_id == this_thread_id) { 222 if (acpi_gbl_mutex_info[i].thread_id == this_thread_id) {
223 if (i == mutex_id) { 223 if (i == mutex_id) {
224 ACPI_ERROR((AE_INFO, 224 ACPI_ERROR((AE_INFO,
@@ -315,7 +315,7 @@ acpi_status acpi_ut_release_mutex(acpi_mutex_handle mutex_id)
315 * ordering rule. This indicates a coding error somewhere in 315 * ordering rule. This indicates a coding error somewhere in
316 * the ACPI subsystem code. 316 * the ACPI subsystem code.
317 */ 317 */
318 for (i = mutex_id; i < ACPI_MAX_MUTEX; i++) { 318 for (i = mutex_id; i < ACPI_NUM_MUTEX; i++) {
319 if (acpi_gbl_mutex_info[i].thread_id == this_thread_id) { 319 if (acpi_gbl_mutex_info[i].thread_id == this_thread_id) {
320 if (i == mutex_id) { 320 if (i == mutex_id) {
321 continue; 321 continue;
diff --git a/drivers/acpi/utilities/utobject.c b/drivers/acpi/utilities/utobject.c
index e68466de8044..e25484495e65 100644
--- a/drivers/acpi/utilities/utobject.c
+++ b/drivers/acpi/utilities/utobject.c
@@ -83,7 +83,8 @@ acpi_ut_get_element_length(u8 object_type,
83 * 83 *
84 ******************************************************************************/ 84 ******************************************************************************/
85 85
86union acpi_operand_object *acpi_ut_create_internal_object_dbg(char *module_name, 86union acpi_operand_object *acpi_ut_create_internal_object_dbg(const char
87 *module_name,
87 u32 line_number, 88 u32 line_number,
88 u32 component_id, 89 u32 component_id,
89 acpi_object_type 90 acpi_object_type
@@ -175,8 +176,8 @@ union acpi_operand_object *acpi_ut_create_package_object(u32 count)
175 * Create the element array. Count+1 allows the array to be null 176 * Create the element array. Count+1 allows the array to be null
176 * terminated. 177 * terminated.
177 */ 178 */
178 package_elements = ACPI_ALLOCATE_ZEROED((acpi_size) 179 package_elements = ACPI_ALLOCATE_ZEROED(((acpi_size) count +
179 (count + 1) * sizeof(void *)); 180 1) * sizeof(void *));
180 if (!package_elements) { 181 if (!package_elements) {
181 acpi_ut_remove_reference(package_desc); 182 acpi_ut_remove_reference(package_desc);
182 return_PTR(NULL); 183 return_PTR(NULL);
@@ -347,7 +348,7 @@ u8 acpi_ut_valid_internal_object(void *object)
347 * 348 *
348 ******************************************************************************/ 349 ******************************************************************************/
349 350
350void *acpi_ut_allocate_object_desc_dbg(char *module_name, 351void *acpi_ut_allocate_object_desc_dbg(const char *module_name,
351 u32 line_number, u32 component_id) 352 u32 line_number, u32 component_id)
352{ 353{
353 union acpi_operand_object *object; 354 union acpi_operand_object *object;
diff --git a/drivers/acpi/video.c b/drivers/acpi/video.c
index d089c4519d45..64c889331f3b 100644
--- a/drivers/acpi/video.c
+++ b/drivers/acpi/video.c
@@ -631,6 +631,76 @@ acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
631 * device : video output device (LCD, CRT, ..) 631 * device : video output device (LCD, CRT, ..)
632 * 632 *
633 * Return Value: 633 * Return Value:
634 * Maximum brightness level
635 *
636 * Allocate and initialize device->brightness.
637 */
638
639static int
640acpi_video_init_brightness(struct acpi_video_device *device)
641{
642 union acpi_object *obj = NULL;
643 int i, max_level = 0, count = 0;
644 union acpi_object *o;
645 struct acpi_video_device_brightness *br = NULL;
646
647 if (!ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) {
648 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available "
649 "LCD brightness level\n"));
650 goto out;
651 }
652
653 if (obj->package.count < 2)
654 goto out;
655
656 br = kzalloc(sizeof(*br), GFP_KERNEL);
657 if (!br) {
658 printk(KERN_ERR "can't allocate memory\n");
659 goto out;
660 }
661
662 br->levels = kmalloc(obj->package.count * sizeof *(br->levels),
663 GFP_KERNEL);
664 if (!br->levels)
665 goto out_free;
666
667 for (i = 0; i < obj->package.count; i++) {
668 o = (union acpi_object *)&obj->package.elements[i];
669 if (o->type != ACPI_TYPE_INTEGER) {
670 printk(KERN_ERR PREFIX "Invalid data\n");
671 continue;
672 }
673 br->levels[count] = (u32) o->integer.value;
674
675 if (br->levels[count] > max_level)
676 max_level = br->levels[count];
677 count++;
678 }
679
680 if (count < 2)
681 goto out_free_levels;
682
683 br->count = count;
684 device->brightness = br;
685 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "found %d brightness levels\n", count));
686 kfree(obj);
687 return max_level;
688
689out_free_levels:
690 kfree(br->levels);
691out_free:
692 kfree(br);
693out:
694 device->brightness = NULL;
695 kfree(obj);
696 return 0;
697}
698
699/*
700 * Arg:
701 * device : video output device (LCD, CRT, ..)
702 *
703 * Return Value:
634 * None 704 * None
635 * 705 *
636 * Find out all required AML methods defined under the output 706 * Find out all required AML methods defined under the output
@@ -640,10 +710,7 @@ acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
640static void acpi_video_device_find_cap(struct acpi_video_device *device) 710static void acpi_video_device_find_cap(struct acpi_video_device *device)
641{ 711{
642 acpi_handle h_dummy1; 712 acpi_handle h_dummy1;
643 int i;
644 u32 max_level = 0; 713 u32 max_level = 0;
645 union acpi_object *obj = NULL;
646 struct acpi_video_device_brightness *br = NULL;
647 714
648 715
649 memset(&device->cap, 0, sizeof(device->cap)); 716 memset(&device->cap, 0, sizeof(device->cap));
@@ -672,53 +739,7 @@ static void acpi_video_device_find_cap(struct acpi_video_device *device)
672 device->cap._DSS = 1; 739 device->cap._DSS = 1;
673 } 740 }
674 741
675 if (ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) { 742 max_level = acpi_video_init_brightness(device);
676
677 if (obj->package.count >= 2) {
678 int count = 0;
679 union acpi_object *o;
680
681 br = kzalloc(sizeof(*br), GFP_KERNEL);
682 if (!br) {
683 printk(KERN_ERR "can't allocate memory\n");
684 } else {
685 br->levels = kmalloc(obj->package.count *
686 sizeof *(br->levels), GFP_KERNEL);
687 if (!br->levels)
688 goto out;
689
690 for (i = 0; i < obj->package.count; i++) {
691 o = (union acpi_object *)&obj->package.
692 elements[i];
693 if (o->type != ACPI_TYPE_INTEGER) {
694 printk(KERN_ERR PREFIX "Invalid data\n");
695 continue;
696 }
697 br->levels[count] = (u32) o->integer.value;
698
699 if (br->levels[count] > max_level)
700 max_level = br->levels[count];
701 count++;
702 }
703 out:
704 if (count < 2) {
705 kfree(br->levels);
706 kfree(br);
707 } else {
708 br->count = count;
709 device->brightness = br;
710 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
711 "found %d brightness levels\n",
712 count));
713 }
714 }
715 }
716
717 } else {
718 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available LCD brightness level\n"));
719 }
720
721 kfree(obj);
722 743
723 if (device->cap._BCL && device->cap._BCM && device->cap._BQC && max_level > 0){ 744 if (device->cap._BCL && device->cap._BCM && device->cap._BQC && max_level > 0){
724 int result; 745 int result;
@@ -1695,6 +1716,8 @@ static void
1695acpi_video_switch_brightness(struct acpi_video_device *device, int event) 1716acpi_video_switch_brightness(struct acpi_video_device *device, int event)
1696{ 1717{
1697 unsigned long level_current, level_next; 1718 unsigned long level_current, level_next;
1719 if (!device->brightness)
1720 return;
1698 acpi_video_device_lcd_get_level_current(device, &level_current); 1721 acpi_video_device_lcd_get_level_current(device, &level_current);
1699 level_next = acpi_video_get_next_level(device, level_current, event); 1722 level_next = acpi_video_get_next_level(device, level_current, event);
1700 acpi_video_device_lcd_set_level(device, level_next); 1723 acpi_video_device_lcd_set_level(device, level_next);
diff --git a/drivers/char/apm-emulation.c b/drivers/char/apm-emulation.c
index da8a1658a273..aaca40283be9 100644
--- a/drivers/char/apm-emulation.c
+++ b/drivers/char/apm-emulation.c
@@ -59,6 +59,55 @@ struct apm_queue {
59}; 59};
60 60
61/* 61/*
62 * thread states (for threads using a writable /dev/apm_bios fd):
63 *
64 * SUSPEND_NONE: nothing happening
65 * SUSPEND_PENDING: suspend event queued for thread and pending to be read
66 * SUSPEND_READ: suspend event read, pending acknowledgement
67 * SUSPEND_ACKED: acknowledgement received from thread (via ioctl),
68 * waiting for resume
69 * SUSPEND_ACKTO: acknowledgement timeout
70 * SUSPEND_DONE: thread had acked suspend and is now notified of
71 * resume
72 *
73 * SUSPEND_WAIT: this thread invoked suspend and is waiting for resume
74 *
75 * A thread migrates in one of three paths:
76 * NONE -1-> PENDING -2-> READ -3-> ACKED -4-> DONE -5-> NONE
77 * -6-> ACKTO -7-> NONE
78 * NONE -8-> WAIT -9-> NONE
79 *
80 * While in PENDING or READ, the thread is accounted for in the
81 * suspend_acks_pending counter.
82 *
83 * The transitions are invoked as follows:
84 * 1: suspend event is signalled from the core PM code
85 * 2: the suspend event is read from the fd by the userspace thread
86 * 3: userspace thread issues the APM_IOC_SUSPEND ioctl (as ack)
87 * 4: core PM code signals that we have resumed
88 * 5: APM_IOC_SUSPEND ioctl returns
89 *
90 * 6: the notifier invoked from the core PM code timed out waiting
91 * for all relevant threds to enter ACKED state and puts those
92 * that haven't into ACKTO
93 * 7: those threads issue APM_IOC_SUSPEND ioctl too late,
94 * get an error
95 *
96 * 8: userspace thread issues the APM_IOC_SUSPEND ioctl (to suspend),
97 * ioctl code invokes pm_suspend()
98 * 9: pm_suspend() returns indicating resume
99 */
100enum apm_suspend_state {
101 SUSPEND_NONE,
102 SUSPEND_PENDING,
103 SUSPEND_READ,
104 SUSPEND_ACKED,
105 SUSPEND_ACKTO,
106 SUSPEND_WAIT,
107 SUSPEND_DONE,
108};
109
110/*
62 * The per-file APM data 111 * The per-file APM data
63 */ 112 */
64struct apm_user { 113struct apm_user {
@@ -69,13 +118,7 @@ struct apm_user {
69 unsigned int reader: 1; 118 unsigned int reader: 1;
70 119
71 int suspend_result; 120 int suspend_result;
72 unsigned int suspend_state; 121 enum apm_suspend_state suspend_state;
73#define SUSPEND_NONE 0 /* no suspend pending */
74#define SUSPEND_PENDING 1 /* suspend pending read */
75#define SUSPEND_READ 2 /* suspend read, pending ack */
76#define SUSPEND_ACKED 3 /* suspend acked */
77#define SUSPEND_WAIT 4 /* waiting for suspend */
78#define SUSPEND_DONE 5 /* suspend completed */
79 122
80 struct apm_queue queue; 123 struct apm_queue queue;
81}; 124};
@@ -83,7 +126,8 @@ struct apm_user {
83/* 126/*
84 * Local variables 127 * Local variables
85 */ 128 */
86static int suspends_pending; 129static atomic_t suspend_acks_pending = ATOMIC_INIT(0);
130static atomic_t userspace_notification_inhibit = ATOMIC_INIT(0);
87static int apm_disabled; 131static int apm_disabled;
88static struct task_struct *kapmd_tsk; 132static struct task_struct *kapmd_tsk;
89 133
@@ -166,78 +210,6 @@ static void queue_event(apm_event_t event)
166 wake_up_interruptible(&apm_waitqueue); 210 wake_up_interruptible(&apm_waitqueue);
167} 211}
168 212
169/*
170 * queue_suspend_event - queue an APM suspend event.
171 *
172 * Check that we're in a state where we can suspend. If not,
173 * return -EBUSY. Otherwise, queue an event to all "writer"
174 * users. If there are no "writer" users, return '1' to
175 * indicate that we can immediately suspend.
176 */
177static int queue_suspend_event(apm_event_t event, struct apm_user *sender)
178{
179 struct apm_user *as;
180 int ret = 1;
181
182 mutex_lock(&state_lock);
183 down_read(&user_list_lock);
184
185 /*
186 * If a thread is still processing, we can't suspend, so reject
187 * the request.
188 */
189 list_for_each_entry(as, &apm_user_list, list) {
190 if (as != sender && as->reader && as->writer && as->suser &&
191 as->suspend_state != SUSPEND_NONE) {
192 ret = -EBUSY;
193 goto out;
194 }
195 }
196
197 list_for_each_entry(as, &apm_user_list, list) {
198 if (as != sender && as->reader && as->writer && as->suser) {
199 as->suspend_state = SUSPEND_PENDING;
200 suspends_pending++;
201 queue_add_event(&as->queue, event);
202 ret = 0;
203 }
204 }
205 out:
206 up_read(&user_list_lock);
207 mutex_unlock(&state_lock);
208 wake_up_interruptible(&apm_waitqueue);
209 return ret;
210}
211
212static void apm_suspend(void)
213{
214 struct apm_user *as;
215 int err = pm_suspend(PM_SUSPEND_MEM);
216
217 /*
218 * Anyone on the APM queues will think we're still suspended.
219 * Send a message so everyone knows we're now awake again.
220 */
221 queue_event(APM_NORMAL_RESUME);
222
223 /*
224 * Finally, wake up anyone who is sleeping on the suspend.
225 */
226 mutex_lock(&state_lock);
227 down_read(&user_list_lock);
228 list_for_each_entry(as, &apm_user_list, list) {
229 if (as->suspend_state == SUSPEND_WAIT ||
230 as->suspend_state == SUSPEND_ACKED) {
231 as->suspend_result = err;
232 as->suspend_state = SUSPEND_DONE;
233 }
234 }
235 up_read(&user_list_lock);
236 mutex_unlock(&state_lock);
237
238 wake_up(&apm_suspend_waitqueue);
239}
240
241static ssize_t apm_read(struct file *fp, char __user *buf, size_t count, loff_t *ppos) 213static ssize_t apm_read(struct file *fp, char __user *buf, size_t count, loff_t *ppos)
242{ 214{
243 struct apm_user *as = fp->private_data; 215 struct apm_user *as = fp->private_data;
@@ -308,25 +280,22 @@ apm_ioctl(struct inode * inode, struct file *filp, u_int cmd, u_long arg)
308 280
309 as->suspend_result = -EINTR; 281 as->suspend_result = -EINTR;
310 282
311 if (as->suspend_state == SUSPEND_READ) { 283 switch (as->suspend_state) {
312 int pending; 284 case SUSPEND_READ:
313
314 /* 285 /*
315 * If we read a suspend command from /dev/apm_bios, 286 * If we read a suspend command from /dev/apm_bios,
316 * then the corresponding APM_IOC_SUSPEND ioctl is 287 * then the corresponding APM_IOC_SUSPEND ioctl is
317 * interpreted as an acknowledge. 288 * interpreted as an acknowledge.
318 */ 289 */
319 as->suspend_state = SUSPEND_ACKED; 290 as->suspend_state = SUSPEND_ACKED;
320 suspends_pending--; 291 atomic_dec(&suspend_acks_pending);
321 pending = suspends_pending == 0;
322 mutex_unlock(&state_lock); 292 mutex_unlock(&state_lock);
323 293
324 /* 294 /*
325 * If there are no further acknowledges required, 295 * suspend_acks_pending changed, the notifier needs to
326 * suspend the system. 296 * be woken up for this
327 */ 297 */
328 if (pending) 298 wake_up(&apm_suspend_waitqueue);
329 apm_suspend();
330 299
331 /* 300 /*
332 * Wait for the suspend/resume to complete. If there 301 * Wait for the suspend/resume to complete. If there
@@ -342,35 +311,21 @@ apm_ioctl(struct inode * inode, struct file *filp, u_int cmd, u_long arg)
342 * try_to_freeze() in freezer_count() will not trigger 311 * try_to_freeze() in freezer_count() will not trigger
343 */ 312 */
344 freezer_count(); 313 freezer_count();
345 } else { 314 break;
315 case SUSPEND_ACKTO:
316 as->suspend_result = -ETIMEDOUT;
317 mutex_unlock(&state_lock);
318 break;
319 default:
346 as->suspend_state = SUSPEND_WAIT; 320 as->suspend_state = SUSPEND_WAIT;
347 mutex_unlock(&state_lock); 321 mutex_unlock(&state_lock);
348 322
349 /* 323 /*
350 * Otherwise it is a request to suspend the system. 324 * Otherwise it is a request to suspend the system.
351 * Queue an event for all readers, and expect an 325 * Just invoke pm_suspend(), we'll handle it from
352 * acknowledge from all writers who haven't already 326 * there via the notifier.
353 * acknowledged.
354 */
355 err = queue_suspend_event(APM_USER_SUSPEND, as);
356 if (err < 0) {
357 /*
358 * Avoid taking the lock here - this
359 * should be fine.
360 */
361 as->suspend_state = SUSPEND_NONE;
362 break;
363 }
364
365 if (err > 0)
366 apm_suspend();
367
368 /*
369 * Wait for the suspend/resume to complete. If there
370 * are pending acknowledges, we wait here for them.
371 */ 327 */
372 wait_event_freezable(apm_suspend_waitqueue, 328 as->suspend_result = pm_suspend(PM_SUSPEND_MEM);
373 as->suspend_state == SUSPEND_DONE);
374 } 329 }
375 330
376 mutex_lock(&state_lock); 331 mutex_lock(&state_lock);
@@ -386,7 +341,6 @@ apm_ioctl(struct inode * inode, struct file *filp, u_int cmd, u_long arg)
386static int apm_release(struct inode * inode, struct file * filp) 341static int apm_release(struct inode * inode, struct file * filp)
387{ 342{
388 struct apm_user *as = filp->private_data; 343 struct apm_user *as = filp->private_data;
389 int pending = 0;
390 344
391 filp->private_data = NULL; 345 filp->private_data = NULL;
392 346
@@ -396,18 +350,15 @@ static int apm_release(struct inode * inode, struct file * filp)
396 350
397 /* 351 /*
398 * We are now unhooked from the chain. As far as new 352 * We are now unhooked from the chain. As far as new
399 * events are concerned, we no longer exist. However, we 353 * events are concerned, we no longer exist.
400 * need to balance suspends_pending, which means the
401 * possibility of sleeping.
402 */ 354 */
403 mutex_lock(&state_lock); 355 mutex_lock(&state_lock);
404 if (as->suspend_state != SUSPEND_NONE) { 356 if (as->suspend_state == SUSPEND_PENDING ||
405 suspends_pending -= 1; 357 as->suspend_state == SUSPEND_READ)
406 pending = suspends_pending == 0; 358 atomic_dec(&suspend_acks_pending);
407 }
408 mutex_unlock(&state_lock); 359 mutex_unlock(&state_lock);
409 if (pending) 360
410 apm_suspend(); 361 wake_up(&apm_suspend_waitqueue);
411 362
412 kfree(as); 363 kfree(as);
413 return 0; 364 return 0;
@@ -545,7 +496,6 @@ static int kapmd(void *arg)
545{ 496{
546 do { 497 do {
547 apm_event_t event; 498 apm_event_t event;
548 int ret;
549 499
550 wait_event_interruptible(kapmd_wait, 500 wait_event_interruptible(kapmd_wait,
551 !queue_empty(&kapmd_queue) || kthread_should_stop()); 501 !queue_empty(&kapmd_queue) || kthread_should_stop());
@@ -570,20 +520,13 @@ static int kapmd(void *arg)
570 520
571 case APM_USER_SUSPEND: 521 case APM_USER_SUSPEND:
572 case APM_SYS_SUSPEND: 522 case APM_SYS_SUSPEND:
573 ret = queue_suspend_event(event, NULL); 523 pm_suspend(PM_SUSPEND_MEM);
574 if (ret < 0) {
575 /*
576 * We were busy. Try again in 50ms.
577 */
578 queue_add_event(&kapmd_queue, event);
579 msleep(50);
580 }
581 if (ret > 0)
582 apm_suspend();
583 break; 524 break;
584 525
585 case APM_CRITICAL_SUSPEND: 526 case APM_CRITICAL_SUSPEND:
586 apm_suspend(); 527 atomic_inc(&userspace_notification_inhibit);
528 pm_suspend(PM_SUSPEND_MEM);
529 atomic_dec(&userspace_notification_inhibit);
587 break; 530 break;
588 } 531 }
589 } while (1); 532 } while (1);
@@ -591,6 +534,120 @@ static int kapmd(void *arg)
591 return 0; 534 return 0;
592} 535}
593 536
537static int apm_suspend_notifier(struct notifier_block *nb,
538 unsigned long event,
539 void *dummy)
540{
541 struct apm_user *as;
542 int err;
543
544 /* short-cut emergency suspends */
545 if (atomic_read(&userspace_notification_inhibit))
546 return NOTIFY_DONE;
547
548 switch (event) {
549 case PM_SUSPEND_PREPARE:
550 /*
551 * Queue an event to all "writer" users that we want
552 * to suspend and need their ack.
553 */
554 mutex_lock(&state_lock);
555 down_read(&user_list_lock);
556
557 list_for_each_entry(as, &apm_user_list, list) {
558 if (as->suspend_state != SUSPEND_WAIT && as->reader &&
559 as->writer && as->suser) {
560 as->suspend_state = SUSPEND_PENDING;
561 atomic_inc(&suspend_acks_pending);
562 queue_add_event(&as->queue, APM_USER_SUSPEND);
563 }
564 }
565
566 up_read(&user_list_lock);
567 mutex_unlock(&state_lock);
568 wake_up_interruptible(&apm_waitqueue);
569
570 /*
571 * Wait for the the suspend_acks_pending variable to drop to
572 * zero, meaning everybody acked the suspend event (or the
573 * process was killed.)
574 *
575 * If the app won't answer within a short while we assume it
576 * locked up and ignore it.
577 */
578 err = wait_event_interruptible_timeout(
579 apm_suspend_waitqueue,
580 atomic_read(&suspend_acks_pending) == 0,
581 5*HZ);
582
583 /* timed out */
584 if (err == 0) {
585 /*
586 * Move anybody who timed out to "ack timeout" state.
587 *
588 * We could time out and the userspace does the ACK
589 * right after we time out but before we enter the
590 * locked section here, but that's fine.
591 */
592 mutex_lock(&state_lock);
593 down_read(&user_list_lock);
594 list_for_each_entry(as, &apm_user_list, list) {
595 if (as->suspend_state == SUSPEND_PENDING ||
596 as->suspend_state == SUSPEND_READ) {
597 as->suspend_state = SUSPEND_ACKTO;
598 atomic_dec(&suspend_acks_pending);
599 }
600 }
601 up_read(&user_list_lock);
602 mutex_unlock(&state_lock);
603 }
604
605 /* let suspend proceed */
606 if (err >= 0)
607 return NOTIFY_OK;
608
609 /* interrupted by signal */
610 return NOTIFY_BAD;
611
612 case PM_POST_SUSPEND:
613 /*
614 * Anyone on the APM queues will think we're still suspended.
615 * Send a message so everyone knows we're now awake again.
616 */
617 queue_event(APM_NORMAL_RESUME);
618
619 /*
620 * Finally, wake up anyone who is sleeping on the suspend.
621 */
622 mutex_lock(&state_lock);
623 down_read(&user_list_lock);
624 list_for_each_entry(as, &apm_user_list, list) {
625 if (as->suspend_state == SUSPEND_ACKED) {
626 /*
627 * TODO: maybe grab error code, needs core
628 * changes to push the error to the notifier
629 * chain (could use the second parameter if
630 * implemented)
631 */
632 as->suspend_result = 0;
633 as->suspend_state = SUSPEND_DONE;
634 }
635 }
636 up_read(&user_list_lock);
637 mutex_unlock(&state_lock);
638
639 wake_up(&apm_suspend_waitqueue);
640 return NOTIFY_OK;
641
642 default:
643 return NOTIFY_DONE;
644 }
645}
646
647static struct notifier_block apm_notif_block = {
648 .notifier_call = apm_suspend_notifier,
649};
650
594static int __init apm_init(void) 651static int __init apm_init(void)
595{ 652{
596 int ret; 653 int ret;
@@ -604,7 +661,7 @@ static int __init apm_init(void)
604 if (IS_ERR(kapmd_tsk)) { 661 if (IS_ERR(kapmd_tsk)) {
605 ret = PTR_ERR(kapmd_tsk); 662 ret = PTR_ERR(kapmd_tsk);
606 kapmd_tsk = NULL; 663 kapmd_tsk = NULL;
607 return ret; 664 goto out;
608 } 665 }
609 wake_up_process(kapmd_tsk); 666 wake_up_process(kapmd_tsk);
610 667
@@ -613,16 +670,27 @@ static int __init apm_init(void)
613#endif 670#endif
614 671
615 ret = misc_register(&apm_device); 672 ret = misc_register(&apm_device);
616 if (ret != 0) { 673 if (ret)
617 remove_proc_entry("apm", NULL); 674 goto out_stop;
618 kthread_stop(kapmd_tsk);
619 }
620 675
676 ret = register_pm_notifier(&apm_notif_block);
677 if (ret)
678 goto out_unregister;
679
680 return 0;
681
682 out_unregister:
683 misc_deregister(&apm_device);
684 out_stop:
685 remove_proc_entry("apm", NULL);
686 kthread_stop(kapmd_tsk);
687 out:
621 return ret; 688 return ret;
622} 689}
623 690
624static void __exit apm_exit(void) 691static void __exit apm_exit(void)
625{ 692{
693 unregister_pm_notifier(&apm_notif_block);
626 misc_deregister(&apm_device); 694 misc_deregister(&apm_device);
627 remove_proc_entry("apm", NULL); 695 remove_proc_entry("apm", NULL);
628 696
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index 636af2862308..1921b8dbb242 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -179,17 +179,29 @@ config FUJITSU_LAPTOP
179 tristate "Fujitsu Laptop Extras" 179 tristate "Fujitsu Laptop Extras"
180 depends on X86 180 depends on X86
181 depends on ACPI 181 depends on ACPI
182 depends on INPUT
182 depends on BACKLIGHT_CLASS_DEVICE 183 depends on BACKLIGHT_CLASS_DEVICE
183 ---help--- 184 ---help---
184 This is a driver for laptops built by Fujitsu: 185 This is a driver for laptops built by Fujitsu:
185 186
186 * P2xxx/P5xxx/S6xxx/S7xxx series Lifebooks 187 * P2xxx/P5xxx/S6xxx/S7xxx series Lifebooks
187 * Possibly other Fujitsu laptop models 188 * Possibly other Fujitsu laptop models
189 * Tested with S6410 and S7020
188 190
189 It adds support for LCD brightness control. 191 It adds support for LCD brightness control and some hotkeys.
190 192
191 If you have a Fujitsu laptop, say Y or M here. 193 If you have a Fujitsu laptop, say Y or M here.
192 194
195config FUJITSU_LAPTOP_DEBUG
196 bool "Verbose debug mode for Fujitsu Laptop Extras"
197 depends on FUJITSU_LAPTOP
198 default n
199 ---help---
200 Enables extra debug output from the fujitsu extras driver, at the
201 expense of a slight increase in driver size.
202
203 If you are not sure, say N here.
204
193config TC1100_WMI 205config TC1100_WMI
194 tristate "HP Compaq TC1100 Tablet WMI Extras (EXPERIMENTAL)" 206 tristate "HP Compaq TC1100 Tablet WMI Extras (EXPERIMENTAL)"
195 depends on X86 && !X86_64 207 depends on X86 && !X86_64
@@ -219,6 +231,23 @@ config MSI_LAPTOP
219 231
220 If you have an MSI S270 laptop, say Y or M here. 232 If you have an MSI S270 laptop, say Y or M here.
221 233
234config COMPAL_LAPTOP
235 tristate "Compal Laptop Extras"
236 depends on X86
237 depends on ACPI_EC
238 depends on BACKLIGHT_CLASS_DEVICE
239 ---help---
240 This is a driver for laptops built by Compal:
241
242 Compal FL90/IFL90
243 Compal FL91/IFL91
244 Compal FL92/JFL92
245 Compal FT00/IFT00
246
247 It adds support for Bluetooth, WLAN and LCD brightness control.
248
249 If you have an Compal FL9x/IFL9x/FT00 laptop, say Y or M here.
250
222config SONY_LAPTOP 251config SONY_LAPTOP
223 tristate "Sony Laptop Extras" 252 tristate "Sony Laptop Extras"
224 depends on X86 && ACPI 253 depends on X86 && ACPI
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index 1952875a272e..a6dac6a2e7e5 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -5,10 +5,11 @@ obj- := misc.o # Dummy rule to force built-in.o to be made
5 5
6obj-$(CONFIG_IBM_ASM) += ibmasm/ 6obj-$(CONFIG_IBM_ASM) += ibmasm/
7obj-$(CONFIG_HDPU_FEATURES) += hdpuftrs/ 7obj-$(CONFIG_HDPU_FEATURES) += hdpuftrs/
8obj-$(CONFIG_MSI_LAPTOP) += msi-laptop.o
9obj-$(CONFIG_ACER_WMI) += acer-wmi.o
10obj-$(CONFIG_ASUS_LAPTOP) += asus-laptop.o 8obj-$(CONFIG_ASUS_LAPTOP) += asus-laptop.o
11obj-$(CONFIG_EEEPC_LAPTOP) += eeepc-laptop.o 9obj-$(CONFIG_EEEPC_LAPTOP) += eeepc-laptop.o
10obj-$(CONFIG_MSI_LAPTOP) += msi-laptop.o
11obj-$(CONFIG_COMPAL_LAPTOP) += compal-laptop.o
12obj-$(CONFIG_ACER_WMI) += acer-wmi.o
12obj-$(CONFIG_ATMEL_PWM) += atmel_pwm.o 13obj-$(CONFIG_ATMEL_PWM) += atmel_pwm.o
13obj-$(CONFIG_ATMEL_SSC) += atmel-ssc.o 14obj-$(CONFIG_ATMEL_SSC) += atmel-ssc.o
14obj-$(CONFIG_ATMEL_TCLIB) += atmel_tclib.o 15obj-$(CONFIG_ATMEL_TCLIB) += atmel_tclib.o
diff --git a/drivers/misc/acer-wmi.c b/drivers/misc/acer-wmi.c
index dd13a3749927..e7a3fe508dff 100644
--- a/drivers/misc/acer-wmi.c
+++ b/drivers/misc/acer-wmi.c
@@ -22,18 +22,18 @@
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */ 23 */
24 24
25#define ACER_WMI_VERSION "0.1"
26
27#include <linux/kernel.h> 25#include <linux/kernel.h>
28#include <linux/module.h> 26#include <linux/module.h>
29#include <linux/init.h> 27#include <linux/init.h>
30#include <linux/types.h> 28#include <linux/types.h>
31#include <linux/dmi.h> 29#include <linux/dmi.h>
30#include <linux/fb.h>
32#include <linux/backlight.h> 31#include <linux/backlight.h>
33#include <linux/leds.h> 32#include <linux/leds.h>
34#include <linux/platform_device.h> 33#include <linux/platform_device.h>
35#include <linux/acpi.h> 34#include <linux/acpi.h>
36#include <linux/i8042.h> 35#include <linux/i8042.h>
36#include <linux/debugfs.h>
37 37
38#include <acpi/acpi_drivers.h> 38#include <acpi/acpi_drivers.h>
39 39
@@ -87,6 +87,7 @@ struct acer_quirks {
87 * Acer ACPI method GUIDs 87 * Acer ACPI method GUIDs
88 */ 88 */
89#define AMW0_GUID1 "67C3371D-95A3-4C37-BB61-DD47B491DAAB" 89#define AMW0_GUID1 "67C3371D-95A3-4C37-BB61-DD47B491DAAB"
90#define AMW0_GUID2 "431F16ED-0C2B-444C-B267-27DEB140CF9C"
90#define WMID_GUID1 "6AF4F258-B401-42fd-BE91-3D4AC2D7C0D3" 91#define WMID_GUID1 "6AF4F258-B401-42fd-BE91-3D4AC2D7C0D3"
91#define WMID_GUID2 "95764E09-FB56-4e83-B31A-37761F60994A" 92#define WMID_GUID2 "95764E09-FB56-4e83-B31A-37761F60994A"
92 93
@@ -150,6 +151,12 @@ struct acer_data {
150 int brightness; 151 int brightness;
151}; 152};
152 153
154struct acer_debug {
155 struct dentry *root;
156 struct dentry *devices;
157 u32 wmid_devices;
158};
159
153/* Each low-level interface must define at least some of the following */ 160/* Each low-level interface must define at least some of the following */
154struct wmi_interface { 161struct wmi_interface {
155 /* The WMI device type */ 162 /* The WMI device type */
@@ -160,6 +167,9 @@ struct wmi_interface {
160 167
161 /* Private data for the current interface */ 168 /* Private data for the current interface */
162 struct acer_data data; 169 struct acer_data data;
170
171 /* debugfs entries associated with this interface */
172 struct acer_debug debug;
163}; 173};
164 174
165/* The static interface pointer, points to the currently detected interface */ 175/* The static interface pointer, points to the currently detected interface */
@@ -174,7 +184,7 @@ static struct wmi_interface *interface;
174struct quirk_entry { 184struct quirk_entry {
175 u8 wireless; 185 u8 wireless;
176 u8 mailled; 186 u8 mailled;
177 u8 brightness; 187 s8 brightness;
178 u8 bluetooth; 188 u8 bluetooth;
179}; 189};
180 190
@@ -198,6 +208,10 @@ static int dmi_matched(const struct dmi_system_id *dmi)
198static struct quirk_entry quirk_unknown = { 208static struct quirk_entry quirk_unknown = {
199}; 209};
200 210
211static struct quirk_entry quirk_acer_aspire_1520 = {
212 .brightness = -1,
213};
214
201static struct quirk_entry quirk_acer_travelmate_2490 = { 215static struct quirk_entry quirk_acer_travelmate_2490 = {
202 .mailled = 1, 216 .mailled = 1,
203}; 217};
@@ -207,9 +221,31 @@ static struct quirk_entry quirk_medion_md_98300 = {
207 .wireless = 1, 221 .wireless = 1,
208}; 222};
209 223
224static struct quirk_entry quirk_fujitsu_amilo_li_1718 = {
225 .wireless = 2,
226};
227
210static struct dmi_system_id acer_quirks[] = { 228static struct dmi_system_id acer_quirks[] = {
211 { 229 {
212 .callback = dmi_matched, 230 .callback = dmi_matched,
231 .ident = "Acer Aspire 1360",
232 .matches = {
233 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
234 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1360"),
235 },
236 .driver_data = &quirk_acer_aspire_1520,
237 },
238 {
239 .callback = dmi_matched,
240 .ident = "Acer Aspire 1520",
241 .matches = {
242 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
243 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1520"),
244 },
245 .driver_data = &quirk_acer_aspire_1520,
246 },
247 {
248 .callback = dmi_matched,
213 .ident = "Acer Aspire 3100", 249 .ident = "Acer Aspire 3100",
214 .matches = { 250 .matches = {
215 DMI_MATCH(DMI_SYS_VENDOR, "Acer"), 251 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
@@ -300,6 +336,15 @@ static struct dmi_system_id acer_quirks[] = {
300 }, 336 },
301 { 337 {
302 .callback = dmi_matched, 338 .callback = dmi_matched,
339 .ident = "Fujitsu Siemens Amilo Li 1718",
340 .matches = {
341 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
342 DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Li 1718"),
343 },
344 .driver_data = &quirk_fujitsu_amilo_li_1718,
345 },
346 {
347 .callback = dmi_matched,
303 .ident = "Medion MD 98300", 348 .ident = "Medion MD 98300",
304 .matches = { 349 .matches = {
305 DMI_MATCH(DMI_SYS_VENDOR, "MEDION"), 350 DMI_MATCH(DMI_SYS_VENDOR, "MEDION"),
@@ -393,6 +438,12 @@ struct wmi_interface *iface)
393 return AE_ERROR; 438 return AE_ERROR;
394 *value = result & 0x1; 439 *value = result & 0x1;
395 return AE_OK; 440 return AE_OK;
441 case 2:
442 err = ec_read(0x71, &result);
443 if (err)
444 return AE_ERROR;
445 *value = result & 0x1;
446 return AE_OK;
396 default: 447 default:
397 err = ec_read(0xA, &result); 448 err = ec_read(0xA, &result);
398 if (err) 449 if (err)
@@ -506,6 +557,15 @@ static acpi_status AMW0_set_capabilities(void)
506 struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL }; 557 struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
507 union acpi_object *obj; 558 union acpi_object *obj;
508 559
560 /*
561 * On laptops with this strange GUID (non Acer), normal probing doesn't
562 * work.
563 */
564 if (wmi_has_guid(AMW0_GUID2)) {
565 interface->capability |= ACER_CAP_WIRELESS;
566 return AE_OK;
567 }
568
509 args.eax = ACER_AMW0_WRITE; 569 args.eax = ACER_AMW0_WRITE;
510 args.ecx = args.edx = 0; 570 args.ecx = args.edx = 0;
511 571
@@ -552,7 +612,8 @@ static acpi_status AMW0_set_capabilities(void)
552 * appear to use the same EC register for brightness, even if they 612 * appear to use the same EC register for brightness, even if they
553 * differ for wireless, etc 613 * differ for wireless, etc
554 */ 614 */
555 interface->capability |= ACER_CAP_BRIGHTNESS; 615 if (quirks->brightness >= 0)
616 interface->capability |= ACER_CAP_BRIGHTNESS;
556 617
557 return AE_OK; 618 return AE_OK;
558} 619}
@@ -807,7 +868,15 @@ static int read_brightness(struct backlight_device *bd)
807 868
808static int update_bl_status(struct backlight_device *bd) 869static int update_bl_status(struct backlight_device *bd)
809{ 870{
810 set_u32(bd->props.brightness, ACER_CAP_BRIGHTNESS); 871 int intensity = bd->props.brightness;
872
873 if (bd->props.power != FB_BLANK_UNBLANK)
874 intensity = 0;
875 if (bd->props.fb_blank != FB_BLANK_UNBLANK)
876 intensity = 0;
877
878 set_u32(intensity, ACER_CAP_BRIGHTNESS);
879
811 return 0; 880 return 0;
812} 881}
813 882
@@ -829,8 +898,9 @@ static int __devinit acer_backlight_init(struct device *dev)
829 898
830 acer_backlight_device = bd; 899 acer_backlight_device = bd;
831 900
901 bd->props.power = FB_BLANK_UNBLANK;
902 bd->props.brightness = max_brightness;
832 bd->props.max_brightness = max_brightness; 903 bd->props.max_brightness = max_brightness;
833 bd->props.brightness = read_brightness(NULL);
834 backlight_update_status(bd); 904 backlight_update_status(bd);
835 return 0; 905 return 0;
836} 906}
@@ -894,6 +964,28 @@ static DEVICE_ATTR(interface, S_IWUGO | S_IRUGO | S_IWUSR,
894 show_interface, NULL); 964 show_interface, NULL);
895 965
896/* 966/*
967 * debugfs functions
968 */
969static u32 get_wmid_devices(void)
970{
971 struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
972 union acpi_object *obj;
973 acpi_status status;
974
975 status = wmi_query_block(WMID_GUID2, 1, &out);
976 if (ACPI_FAILURE(status))
977 return 0;
978
979 obj = (union acpi_object *) out.pointer;
980 if (obj && obj->type == ACPI_TYPE_BUFFER &&
981 obj->buffer.length == sizeof(u32)) {
982 return *((u32 *) obj->buffer.pointer);
983 } else {
984 return 0;
985 }
986}
987
988/*
897 * Platform device 989 * Platform device
898 */ 990 */
899static int __devinit acer_platform_probe(struct platform_device *device) 991static int __devinit acer_platform_probe(struct platform_device *device)
@@ -1052,12 +1144,40 @@ error_sysfs:
1052 return retval; 1144 return retval;
1053} 1145}
1054 1146
1147static void remove_debugfs(void)
1148{
1149 debugfs_remove(interface->debug.devices);
1150 debugfs_remove(interface->debug.root);
1151}
1152
1153static int create_debugfs(void)
1154{
1155 interface->debug.root = debugfs_create_dir("acer-wmi", NULL);
1156 if (!interface->debug.root) {
1157 printk(ACER_ERR "Failed to create debugfs directory");
1158 return -ENOMEM;
1159 }
1160
1161 interface->debug.devices = debugfs_create_u32("devices", S_IRUGO,
1162 interface->debug.root,
1163 &interface->debug.wmid_devices);
1164 if (!interface->debug.devices)
1165 goto error_debugfs;
1166
1167 return 0;
1168
1169error_debugfs:
1170 remove_debugfs();
1171 return -ENOMEM;
1172}
1173
1055static int __init acer_wmi_init(void) 1174static int __init acer_wmi_init(void)
1056{ 1175{
1057 int err; 1176 int err;
1058 1177
1059 printk(ACER_INFO "Acer Laptop ACPI-WMI Extras version %s\n", 1178 printk(ACER_INFO "Acer Laptop ACPI-WMI Extras\n");
1060 ACER_WMI_VERSION); 1179
1180 find_quirks();
1061 1181
1062 /* 1182 /*
1063 * Detect which ACPI-WMI interface we're using. 1183 * Detect which ACPI-WMI interface we're using.
@@ -1092,8 +1212,6 @@ static int __init acer_wmi_init(void)
1092 if (wmi_has_guid(AMW0_GUID1)) 1212 if (wmi_has_guid(AMW0_GUID1))
1093 AMW0_find_mailled(); 1213 AMW0_find_mailled();
1094 1214
1095 find_quirks();
1096
1097 if (!interface) { 1215 if (!interface) {
1098 printk(ACER_ERR "No or unsupported WMI interface, unable to " 1216 printk(ACER_ERR "No or unsupported WMI interface, unable to "
1099 "load\n"); 1217 "load\n");
@@ -1111,6 +1229,13 @@ static int __init acer_wmi_init(void)
1111 if (err) 1229 if (err)
1112 return err; 1230 return err;
1113 1231
1232 if (wmi_has_guid(WMID_GUID2)) {
1233 interface->debug.wmid_devices = get_wmid_devices();
1234 err = create_debugfs();
1235 if (err)
1236 return err;
1237 }
1238
1114 /* Override any initial settings with values from the commandline */ 1239 /* Override any initial settings with values from the commandline */
1115 acer_commandline_init(); 1240 acer_commandline_init();
1116 1241
diff --git a/drivers/misc/compal-laptop.c b/drivers/misc/compal-laptop.c
new file mode 100644
index 000000000000..344b790a6253
--- /dev/null
+++ b/drivers/misc/compal-laptop.c
@@ -0,0 +1,404 @@
1/*-*-linux-c-*-*/
2
3/*
4 Copyright (C) 2008 Cezary Jackiewicz <cezary.jackiewicz (at) gmail.com>
5
6 based on MSI driver
7
8 Copyright (C) 2006 Lennart Poettering <mzxreary (at) 0pointer (dot) de>
9
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 02110-1301, USA.
24 */
25
26/*
27 * comapl-laptop.c - Compal laptop support.
28 *
29 * This driver exports a few files in /sys/devices/platform/compal-laptop/:
30 *
31 * wlan - wlan subsystem state: contains 0 or 1 (rw)
32 *
33 * bluetooth - Bluetooth subsystem state: contains 0 or 1 (rw)
34 *
35 * raw - raw value taken from embedded controller register (ro)
36 *
37 * In addition to these platform device attributes the driver
38 * registers itself in the Linux backlight control subsystem and is
39 * available to userspace under /sys/class/backlight/compal-laptop/.
40 *
41 * This driver might work on other laptops produced by Compal. If you
42 * want to try it you can pass force=1 as argument to the module which
43 * will force it to load even when the DMI data doesn't identify the
44 * laptop as FL9x.
45 */
46
47#include <linux/module.h>
48#include <linux/kernel.h>
49#include <linux/init.h>
50#include <linux/acpi.h>
51#include <linux/dmi.h>
52#include <linux/backlight.h>
53#include <linux/platform_device.h>
54#include <linux/autoconf.h>
55
56#define COMPAL_DRIVER_VERSION "0.2.6"
57
58#define COMPAL_LCD_LEVEL_MAX 8
59
60#define COMPAL_EC_COMMAND_WIRELESS 0xBB
61#define COMPAL_EC_COMMAND_LCD_LEVEL 0xB9
62
63#define KILLSWITCH_MASK 0x10
64#define WLAN_MASK 0x01
65#define BT_MASK 0x02
66
67static int force;
68module_param(force, bool, 0);
69MODULE_PARM_DESC(force, "Force driver load, ignore DMI data");
70
71/* Hardware access */
72
73static int set_lcd_level(int level)
74{
75 if (level < 0 || level >= COMPAL_LCD_LEVEL_MAX)
76 return -EINVAL;
77
78 ec_write(COMPAL_EC_COMMAND_LCD_LEVEL, level);
79
80 return 0;
81}
82
83static int get_lcd_level(void)
84{
85 u8 result;
86
87 ec_read(COMPAL_EC_COMMAND_LCD_LEVEL, &result);
88
89 return (int) result;
90}
91
92static int set_wlan_state(int state)
93{
94 u8 result, value;
95
96 ec_read(COMPAL_EC_COMMAND_WIRELESS, &result);
97
98 if ((result & KILLSWITCH_MASK) == 0)
99 return -EINVAL;
100 else {
101 if (state)
102 value = (u8) (result | WLAN_MASK);
103 else
104 value = (u8) (result & ~WLAN_MASK);
105 ec_write(COMPAL_EC_COMMAND_WIRELESS, value);
106 }
107
108 return 0;
109}
110
111static int set_bluetooth_state(int state)
112{
113 u8 result, value;
114
115 ec_read(COMPAL_EC_COMMAND_WIRELESS, &result);
116
117 if ((result & KILLSWITCH_MASK) == 0)
118 return -EINVAL;
119 else {
120 if (state)
121 value = (u8) (result | BT_MASK);
122 else
123 value = (u8) (result & ~BT_MASK);
124 ec_write(COMPAL_EC_COMMAND_WIRELESS, value);
125 }
126
127 return 0;
128}
129
130static int get_wireless_state(int *wlan, int *bluetooth)
131{
132 u8 result;
133
134 ec_read(COMPAL_EC_COMMAND_WIRELESS, &result);
135
136 if (wlan) {
137 if ((result & KILLSWITCH_MASK) == 0)
138 *wlan = 0;
139 else
140 *wlan = result & WLAN_MASK;
141 }
142
143 if (bluetooth) {
144 if ((result & KILLSWITCH_MASK) == 0)
145 *bluetooth = 0;
146 else
147 *bluetooth = (result & BT_MASK) >> 1;
148 }
149
150 return 0;
151}
152
153/* Backlight device stuff */
154
155static int bl_get_brightness(struct backlight_device *b)
156{
157 return get_lcd_level();
158}
159
160
161static int bl_update_status(struct backlight_device *b)
162{
163 return set_lcd_level(b->props.brightness);
164}
165
166static struct backlight_ops compalbl_ops = {
167 .get_brightness = bl_get_brightness,
168 .update_status = bl_update_status,
169};
170
171static struct backlight_device *compalbl_device;
172
173/* Platform device */
174
175static ssize_t show_wlan(struct device *dev,
176 struct device_attribute *attr, char *buf)
177{
178 int ret, enabled;
179
180 ret = get_wireless_state(&enabled, NULL);
181 if (ret < 0)
182 return ret;
183
184 return sprintf(buf, "%i\n", enabled);
185}
186
187static ssize_t show_raw(struct device *dev,
188 struct device_attribute *attr, char *buf)
189{
190 u8 result;
191
192 ec_read(COMPAL_EC_COMMAND_WIRELESS, &result);
193
194 return sprintf(buf, "%i\n", result);
195}
196
197static ssize_t show_bluetooth(struct device *dev,
198 struct device_attribute *attr, char *buf)
199{
200 int ret, enabled;
201
202 ret = get_wireless_state(NULL, &enabled);
203 if (ret < 0)
204 return ret;
205
206 return sprintf(buf, "%i\n", enabled);
207}
208
209static ssize_t store_wlan_state(struct device *dev,
210 struct device_attribute *attr, const char *buf, size_t count)
211{
212 int state, ret;
213
214 if (sscanf(buf, "%i", &state) != 1 || (state < 0 || state > 1))
215 return -EINVAL;
216
217 ret = set_wlan_state(state);
218 if (ret < 0)
219 return ret;
220
221 return count;
222}
223
224static ssize_t store_bluetooth_state(struct device *dev,
225 struct device_attribute *attr, const char *buf, size_t count)
226{
227 int state, ret;
228
229 if (sscanf(buf, "%i", &state) != 1 || (state < 0 || state > 1))
230 return -EINVAL;
231
232 ret = set_bluetooth_state(state);
233 if (ret < 0)
234 return ret;
235
236 return count;
237}
238
239static DEVICE_ATTR(bluetooth, 0644, show_bluetooth, store_bluetooth_state);
240static DEVICE_ATTR(wlan, 0644, show_wlan, store_wlan_state);
241static DEVICE_ATTR(raw, 0444, show_raw, NULL);
242
243static struct attribute *compal_attributes[] = {
244 &dev_attr_bluetooth.attr,
245 &dev_attr_wlan.attr,
246 &dev_attr_raw.attr,
247 NULL
248};
249
250static struct attribute_group compal_attribute_group = {
251 .attrs = compal_attributes
252};
253
254static struct platform_driver compal_driver = {
255 .driver = {
256 .name = "compal-laptop",
257 .owner = THIS_MODULE,
258 }
259};
260
261static struct platform_device *compal_device;
262
263/* Initialization */
264
265static int dmi_check_cb(const struct dmi_system_id *id)
266{
267 printk(KERN_INFO "compal-laptop: Identified laptop model '%s'.\n",
268 id->ident);
269
270 return 0;
271}
272
273static struct dmi_system_id __initdata compal_dmi_table[] = {
274 {
275 .ident = "FL90/IFL90",
276 .matches = {
277 DMI_MATCH(DMI_BOARD_NAME, "IFL90"),
278 DMI_MATCH(DMI_BOARD_VERSION, "IFT00"),
279 },
280 .callback = dmi_check_cb
281 },
282 {
283 .ident = "FL90/IFL90",
284 .matches = {
285 DMI_MATCH(DMI_BOARD_NAME, "IFL90"),
286 DMI_MATCH(DMI_BOARD_VERSION, "REFERENCE"),
287 },
288 .callback = dmi_check_cb
289 },
290 {
291 .ident = "FL91/IFL91",
292 .matches = {
293 DMI_MATCH(DMI_BOARD_NAME, "IFL91"),
294 DMI_MATCH(DMI_BOARD_VERSION, "IFT00"),
295 },
296 .callback = dmi_check_cb
297 },
298 {
299 .ident = "FL92/JFL92",
300 .matches = {
301 DMI_MATCH(DMI_BOARD_NAME, "JFL92"),
302 DMI_MATCH(DMI_BOARD_VERSION, "IFT00"),
303 },
304 .callback = dmi_check_cb
305 },
306 {
307 .ident = "FT00/IFT00",
308 .matches = {
309 DMI_MATCH(DMI_BOARD_NAME, "IFT00"),
310 DMI_MATCH(DMI_BOARD_VERSION, "IFT00"),
311 },
312 .callback = dmi_check_cb
313 },
314 { }
315};
316
317static int __init compal_init(void)
318{
319 int ret;
320
321 if (acpi_disabled)
322 return -ENODEV;
323
324 if (!force && !dmi_check_system(compal_dmi_table))
325 return -ENODEV;
326
327 /* Register backlight stuff */
328
329 compalbl_device = backlight_device_register("compal-laptop", NULL, NULL,
330 &compalbl_ops);
331 if (IS_ERR(compalbl_device))
332 return PTR_ERR(compalbl_device);
333
334 compalbl_device->props.max_brightness = COMPAL_LCD_LEVEL_MAX-1;
335
336 ret = platform_driver_register(&compal_driver);
337 if (ret)
338 goto fail_backlight;
339
340 /* Register platform stuff */
341
342 compal_device = platform_device_alloc("compal-laptop", -1);
343 if (!compal_device) {
344 ret = -ENOMEM;
345 goto fail_platform_driver;
346 }
347
348 ret = platform_device_add(compal_device);
349 if (ret)
350 goto fail_platform_device1;
351
352 ret = sysfs_create_group(&compal_device->dev.kobj,
353 &compal_attribute_group);
354 if (ret)
355 goto fail_platform_device2;
356
357 printk(KERN_INFO "compal-laptop: driver "COMPAL_DRIVER_VERSION
358 " successfully loaded.\n");
359
360 return 0;
361
362fail_platform_device2:
363
364 platform_device_del(compal_device);
365
366fail_platform_device1:
367
368 platform_device_put(compal_device);
369
370fail_platform_driver:
371
372 platform_driver_unregister(&compal_driver);
373
374fail_backlight:
375
376 backlight_device_unregister(compalbl_device);
377
378 return ret;
379}
380
381static void __exit compal_cleanup(void)
382{
383
384 sysfs_remove_group(&compal_device->dev.kobj, &compal_attribute_group);
385 platform_device_unregister(compal_device);
386 platform_driver_unregister(&compal_driver);
387 backlight_device_unregister(compalbl_device);
388
389 printk(KERN_INFO "compal-laptop: driver unloaded.\n");
390}
391
392module_init(compal_init);
393module_exit(compal_cleanup);
394
395MODULE_AUTHOR("Cezary Jackiewicz");
396MODULE_DESCRIPTION("Compal Laptop Support");
397MODULE_VERSION(COMPAL_DRIVER_VERSION);
398MODULE_LICENSE("GPL");
399
400MODULE_ALIAS("dmi:*:rnIFL90:rvrIFT00:*");
401MODULE_ALIAS("dmi:*:rnIFL90:rvrREFERENCE:*");
402MODULE_ALIAS("dmi:*:rnIFL91:rvrIFT00:*");
403MODULE_ALIAS("dmi:*:rnJFL92:rvrIFT00:*");
404MODULE_ALIAS("dmi:*:rnIFT00:rvrIFT00:*");
diff --git a/drivers/misc/eeepc-laptop.c b/drivers/misc/eeepc-laptop.c
index 6d727609097f..9e8d79e7e9f4 100644
--- a/drivers/misc/eeepc-laptop.c
+++ b/drivers/misc/eeepc-laptop.c
@@ -87,7 +87,7 @@ enum {
87 CM_ASL_LID 87 CM_ASL_LID
88}; 88};
89 89
90const char *cm_getv[] = { 90static const char *cm_getv[] = {
91 "WLDG", NULL, NULL, NULL, 91 "WLDG", NULL, NULL, NULL,
92 "CAMG", NULL, NULL, NULL, 92 "CAMG", NULL, NULL, NULL,
93 NULL, "PBLG", NULL, NULL, 93 NULL, "PBLG", NULL, NULL,
@@ -96,7 +96,7 @@ const char *cm_getv[] = {
96 "CRDG", "LIDG" 96 "CRDG", "LIDG"
97}; 97};
98 98
99const char *cm_setv[] = { 99static const char *cm_setv[] = {
100 "WLDS", NULL, NULL, NULL, 100 "WLDS", NULL, NULL, NULL,
101 "CAMS", NULL, NULL, NULL, 101 "CAMS", NULL, NULL, NULL,
102 "SDSP", "PBLS", "HDPS", NULL, 102 "SDSP", "PBLS", "HDPS", NULL,
diff --git a/drivers/misc/fujitsu-laptop.c b/drivers/misc/fujitsu-laptop.c
index 6d14e8fe1537..7a1ef6c262de 100644
--- a/drivers/misc/fujitsu-laptop.c
+++ b/drivers/misc/fujitsu-laptop.c
@@ -1,12 +1,14 @@
1/*-*-linux-c-*-*/ 1/*-*-linux-c-*-*/
2 2
3/* 3/*
4 Copyright (C) 2007 Jonathan Woithe <jwoithe@physics.adelaide.edu.au> 4 Copyright (C) 2007,2008 Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
5 Copyright (C) 2008 Peter Gruber <nokos@gmx.net>
5 Based on earlier work: 6 Based on earlier work:
6 Copyright (C) 2003 Shane Spencer <shane@bogomip.com> 7 Copyright (C) 2003 Shane Spencer <shane@bogomip.com>
7 Adrian Yee <brewt-fujitsu@brewt.org> 8 Adrian Yee <brewt-fujitsu@brewt.org>
8 9
9 Templated from msi-laptop.c which is copyright by its respective authors. 10 Templated from msi-laptop.c and thinkpad_acpi.c which is copyright
11 by its respective authors.
10 12
11 This program is free software; you can redistribute it and/or modify 13 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by 14 it under the terms of the GNU General Public License as published by
@@ -39,8 +41,17 @@
39 * registers itself in the Linux backlight control subsystem and is 41 * registers itself in the Linux backlight control subsystem and is
40 * available to userspace under /sys/class/backlight/fujitsu-laptop/. 42 * available to userspace under /sys/class/backlight/fujitsu-laptop/.
41 * 43 *
42 * This driver has been tested on a Fujitsu Lifebook S7020. It should 44 * Hotkeys present on certain Fujitsu laptops (eg: the S6xxx series) are
43 * work on most P-series and S-series Lifebooks, but YMMV. 45 * also supported by this driver.
46 *
47 * This driver has been tested on a Fujitsu Lifebook S6410 and S7020. It
48 * should work on most P-series and S-series Lifebooks, but YMMV.
49 *
50 * The module parameter use_alt_lcd_levels switches between different ACPI
51 * brightness controls which are used by different Fujitsu laptops. In most
52 * cases the correct method is automatically detected. "use_alt_lcd_levels=1"
53 * is applicable for a Fujitsu Lifebook S6410 if autodetection fails.
54 *
44 */ 55 */
45 56
46#include <linux/module.h> 57#include <linux/module.h>
@@ -49,30 +60,105 @@
49#include <linux/acpi.h> 60#include <linux/acpi.h>
50#include <linux/dmi.h> 61#include <linux/dmi.h>
51#include <linux/backlight.h> 62#include <linux/backlight.h>
63#include <linux/input.h>
64#include <linux/kfifo.h>
65#include <linux/video_output.h>
52#include <linux/platform_device.h> 66#include <linux/platform_device.h>
53 67
54#define FUJITSU_DRIVER_VERSION "0.3" 68#define FUJITSU_DRIVER_VERSION "0.4.2"
55 69
56#define FUJITSU_LCD_N_LEVELS 8 70#define FUJITSU_LCD_N_LEVELS 8
57 71
58#define ACPI_FUJITSU_CLASS "fujitsu" 72#define ACPI_FUJITSU_CLASS "fujitsu"
59#define ACPI_FUJITSU_HID "FUJ02B1" 73#define ACPI_FUJITSU_HID "FUJ02B1"
60#define ACPI_FUJITSU_DRIVER_NAME "Fujitsu laptop FUJ02B1 ACPI extras driver" 74#define ACPI_FUJITSU_DRIVER_NAME "Fujitsu laptop FUJ02B1 ACPI brightness driver"
61#define ACPI_FUJITSU_DEVICE_NAME "Fujitsu FUJ02B1" 75#define ACPI_FUJITSU_DEVICE_NAME "Fujitsu FUJ02B1"
62 76#define ACPI_FUJITSU_HOTKEY_HID "FUJ02E3"
77#define ACPI_FUJITSU_HOTKEY_DRIVER_NAME "Fujitsu laptop FUJ02E3 ACPI hotkeys driver"
78#define ACPI_FUJITSU_HOTKEY_DEVICE_NAME "Fujitsu FUJ02E3"
79
80#define ACPI_FUJITSU_NOTIFY_CODE1 0x80
81
82#define ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS 0x86
83#define ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS 0x87
84
85/* Hotkey details */
86#define LOCK_KEY 0x410 /* codes for the keys in the GIRB register */
87#define DISPLAY_KEY 0x411 /* keys are mapped to KEY_SCREENLOCK (the key with the key symbol) */
88#define ENERGY_KEY 0x412 /* KEY_MEDIA (the key with the laptop symbol, KEY_EMAIL (E key)) */
89#define REST_KEY 0x413 /* KEY_SUSPEND (R key) */
90
91#define MAX_HOTKEY_RINGBUFFER_SIZE 100
92#define RINGBUFFERSIZE 40
93
94/* Debugging */
95#define FUJLAPTOP_LOG ACPI_FUJITSU_HID ": "
96#define FUJLAPTOP_ERR KERN_ERR FUJLAPTOP_LOG
97#define FUJLAPTOP_NOTICE KERN_NOTICE FUJLAPTOP_LOG
98#define FUJLAPTOP_INFO KERN_INFO FUJLAPTOP_LOG
99#define FUJLAPTOP_DEBUG KERN_DEBUG FUJLAPTOP_LOG
100
101#define FUJLAPTOP_DBG_ALL 0xffff
102#define FUJLAPTOP_DBG_ERROR 0x0001
103#define FUJLAPTOP_DBG_WARN 0x0002
104#define FUJLAPTOP_DBG_INFO 0x0004
105#define FUJLAPTOP_DBG_TRACE 0x0008
106
107#define dbg_printk(a_dbg_level, format, arg...) \
108 do { if (dbg_level & a_dbg_level) \
109 printk(FUJLAPTOP_DEBUG "%s: " format, __func__ , ## arg); \
110 } while (0)
111#ifdef CONFIG_FUJITSU_LAPTOP_DEBUG
112#define vdbg_printk(a_dbg_level, format, arg...) \
113 dbg_printk(a_dbg_level, format, ## arg)
114#else
115#define vdbg_printk(a_dbg_level, format, arg...)
116#endif
117
118/* Device controlling the backlight and associated keys */
63struct fujitsu_t { 119struct fujitsu_t {
64 acpi_handle acpi_handle; 120 acpi_handle acpi_handle;
121 struct acpi_device *dev;
122 struct input_dev *input;
123 char phys[32];
65 struct backlight_device *bl_device; 124 struct backlight_device *bl_device;
66 struct platform_device *pf_device; 125 struct platform_device *pf_device;
67 126
68 unsigned long fuj02b1_state; 127 unsigned int max_brightness;
69 unsigned int brightness_changed; 128 unsigned int brightness_changed;
70 unsigned int brightness_level; 129 unsigned int brightness_level;
71}; 130};
72 131
73static struct fujitsu_t *fujitsu; 132static struct fujitsu_t *fujitsu;
133static int use_alt_lcd_levels = -1;
134static int disable_brightness_keys = -1;
135static int disable_brightness_adjust = -1;
136
137/* Device used to access other hotkeys on the laptop */
138struct fujitsu_hotkey_t {
139 acpi_handle acpi_handle;
140 struct acpi_device *dev;
141 struct input_dev *input;
142 char phys[32];
143 struct platform_device *pf_device;
144 struct kfifo *fifo;
145 spinlock_t fifo_lock;
146
147 unsigned int irb; /* info about the pressed buttons */
148};
74 149
75/* Hardware access */ 150static struct fujitsu_hotkey_t *fujitsu_hotkey;
151
152static void acpi_fujitsu_hotkey_notify(acpi_handle handle, u32 event,
153 void *data);
154
155#ifdef CONFIG_FUJITSU_LAPTOP_DEBUG
156static u32 dbg_level = 0x03;
157#endif
158
159static void acpi_fujitsu_notify(acpi_handle handle, u32 event, void *data);
160
161/* Hardware access for LCD brightness control */
76 162
77static int set_lcd_level(int level) 163static int set_lcd_level(int level)
78{ 164{
@@ -81,7 +167,10 @@ static int set_lcd_level(int level)
81 struct acpi_object_list arg_list = { 1, &arg0 }; 167 struct acpi_object_list arg_list = { 1, &arg0 };
82 acpi_handle handle = NULL; 168 acpi_handle handle = NULL;
83 169
84 if (level < 0 || level >= FUJITSU_LCD_N_LEVELS) 170 vdbg_printk(FUJLAPTOP_DBG_TRACE, "set lcd level via SBLL [%d]\n",
171 level);
172
173 if (level < 0 || level >= fujitsu->max_brightness)
85 return -EINVAL; 174 return -EINVAL;
86 175
87 if (!fujitsu) 176 if (!fujitsu)
@@ -89,7 +178,38 @@ static int set_lcd_level(int level)
89 178
90 status = acpi_get_handle(fujitsu->acpi_handle, "SBLL", &handle); 179 status = acpi_get_handle(fujitsu->acpi_handle, "SBLL", &handle);
91 if (ACPI_FAILURE(status)) { 180 if (ACPI_FAILURE(status)) {
92 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "SBLL not present\n")); 181 vdbg_printk(FUJLAPTOP_DBG_ERROR, "SBLL not present\n");
182 return -ENODEV;
183 }
184
185 arg0.integer.value = level;
186
187 status = acpi_evaluate_object(handle, NULL, &arg_list, NULL);
188 if (ACPI_FAILURE(status))
189 return -ENODEV;
190
191 return 0;
192}
193
194static int set_lcd_level_alt(int level)
195{
196 acpi_status status = AE_OK;
197 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
198 struct acpi_object_list arg_list = { 1, &arg0 };
199 acpi_handle handle = NULL;
200
201 vdbg_printk(FUJLAPTOP_DBG_TRACE, "set lcd level via SBL2 [%d]\n",
202 level);
203
204 if (level < 0 || level >= fujitsu->max_brightness)
205 return -EINVAL;
206
207 if (!fujitsu)
208 return -EINVAL;
209
210 status = acpi_get_handle(fujitsu->acpi_handle, "SBL2", &handle);
211 if (ACPI_FAILURE(status)) {
212 vdbg_printk(FUJLAPTOP_DBG_ERROR, "SBL2 not present\n");
93 return -ENODEV; 213 return -ENODEV;
94 } 214 }
95 215
@@ -107,13 +227,52 @@ static int get_lcd_level(void)
107 unsigned long state = 0; 227 unsigned long state = 0;
108 acpi_status status = AE_OK; 228 acpi_status status = AE_OK;
109 229
110 // Get the Brightness 230 vdbg_printk(FUJLAPTOP_DBG_TRACE, "get lcd level via GBLL\n");
231
111 status = 232 status =
112 acpi_evaluate_integer(fujitsu->acpi_handle, "GBLL", NULL, &state); 233 acpi_evaluate_integer(fujitsu->acpi_handle, "GBLL", NULL, &state);
113 if (status < 0) 234 if (status < 0)
114 return status; 235 return status;
115 236
116 fujitsu->fuj02b1_state = state; 237 fujitsu->brightness_level = state & 0x0fffffff;
238
239 if (state & 0x80000000)
240 fujitsu->brightness_changed = 1;
241 else
242 fujitsu->brightness_changed = 0;
243
244 return fujitsu->brightness_level;
245}
246
247static int get_max_brightness(void)
248{
249 unsigned long state = 0;
250 acpi_status status = AE_OK;
251
252 vdbg_printk(FUJLAPTOP_DBG_TRACE, "get max lcd level via RBLL\n");
253
254 status =
255 acpi_evaluate_integer(fujitsu->acpi_handle, "RBLL", NULL, &state);
256 if (status < 0)
257 return status;
258
259 fujitsu->max_brightness = state;
260
261 return fujitsu->max_brightness;
262}
263
264static int get_lcd_level_alt(void)
265{
266 unsigned long state = 0;
267 acpi_status status = AE_OK;
268
269 vdbg_printk(FUJLAPTOP_DBG_TRACE, "get lcd level via GBLS\n");
270
271 status =
272 acpi_evaluate_integer(fujitsu->acpi_handle, "GBLS", NULL, &state);
273 if (status < 0)
274 return status;
275
117 fujitsu->brightness_level = state & 0x0fffffff; 276 fujitsu->brightness_level = state & 0x0fffffff;
118 277
119 if (state & 0x80000000) 278 if (state & 0x80000000)
@@ -128,12 +287,18 @@ static int get_lcd_level(void)
128 287
129static int bl_get_brightness(struct backlight_device *b) 288static int bl_get_brightness(struct backlight_device *b)
130{ 289{
131 return get_lcd_level(); 290 if (use_alt_lcd_levels)
291 return get_lcd_level_alt();
292 else
293 return get_lcd_level();
132} 294}
133 295
134static int bl_update_status(struct backlight_device *b) 296static int bl_update_status(struct backlight_device *b)
135{ 297{
136 return set_lcd_level(b->props.brightness); 298 if (use_alt_lcd_levels)
299 return set_lcd_level_alt(b->props.brightness);
300 else
301 return set_lcd_level(b->props.brightness);
137} 302}
138 303
139static struct backlight_ops fujitsubl_ops = { 304static struct backlight_ops fujitsubl_ops = {
@@ -141,7 +306,35 @@ static struct backlight_ops fujitsubl_ops = {
141 .update_status = bl_update_status, 306 .update_status = bl_update_status,
142}; 307};
143 308
144/* Platform device */ 309/* Platform LCD brightness device */
310
311static ssize_t
312show_max_brightness(struct device *dev,
313 struct device_attribute *attr, char *buf)
314{
315
316 int ret;
317
318 ret = get_max_brightness();
319 if (ret < 0)
320 return ret;
321
322 return sprintf(buf, "%i\n", ret);
323}
324
325static ssize_t
326show_brightness_changed(struct device *dev,
327 struct device_attribute *attr, char *buf)
328{
329
330 int ret;
331
332 ret = fujitsu->brightness_changed;
333 if (ret < 0)
334 return ret;
335
336 return sprintf(buf, "%i\n", ret);
337}
145 338
146static ssize_t show_lcd_level(struct device *dev, 339static ssize_t show_lcd_level(struct device *dev,
147 struct device_attribute *attr, char *buf) 340 struct device_attribute *attr, char *buf)
@@ -149,7 +342,10 @@ static ssize_t show_lcd_level(struct device *dev,
149 342
150 int ret; 343 int ret;
151 344
152 ret = get_lcd_level(); 345 if (use_alt_lcd_levels)
346 ret = get_lcd_level_alt();
347 else
348 ret = get_lcd_level();
153 if (ret < 0) 349 if (ret < 0)
154 return ret; 350 return ret;
155 351
@@ -164,19 +360,61 @@ static ssize_t store_lcd_level(struct device *dev,
164 int level, ret; 360 int level, ret;
165 361
166 if (sscanf(buf, "%i", &level) != 1 362 if (sscanf(buf, "%i", &level) != 1
167 || (level < 0 || level >= FUJITSU_LCD_N_LEVELS)) 363 || (level < 0 || level >= fujitsu->max_brightness))
168 return -EINVAL; 364 return -EINVAL;
169 365
170 ret = set_lcd_level(level); 366 if (use_alt_lcd_levels)
367 ret = set_lcd_level_alt(level);
368 else
369 ret = set_lcd_level(level);
370 if (ret < 0)
371 return ret;
372
373 if (use_alt_lcd_levels)
374 ret = get_lcd_level_alt();
375 else
376 ret = get_lcd_level();
171 if (ret < 0) 377 if (ret < 0)
172 return ret; 378 return ret;
173 379
174 return count; 380 return count;
175} 381}
176 382
383/* Hardware access for hotkey device */
384
385static int get_irb(void)
386{
387 unsigned long state = 0;
388 acpi_status status = AE_OK;
389
390 vdbg_printk(FUJLAPTOP_DBG_TRACE, "Get irb\n");
391
392 status =
393 acpi_evaluate_integer(fujitsu_hotkey->acpi_handle, "GIRB", NULL,
394 &state);
395 if (status < 0)
396 return status;
397
398 fujitsu_hotkey->irb = state;
399
400 return fujitsu_hotkey->irb;
401}
402
403static ssize_t
404ignore_store(struct device *dev,
405 struct device_attribute *attr, const char *buf, size_t count)
406{
407 return count;
408}
409
410static DEVICE_ATTR(max_brightness, 0444, show_max_brightness, ignore_store);
411static DEVICE_ATTR(brightness_changed, 0444, show_brightness_changed,
412 ignore_store);
177static DEVICE_ATTR(lcd_level, 0644, show_lcd_level, store_lcd_level); 413static DEVICE_ATTR(lcd_level, 0644, show_lcd_level, store_lcd_level);
178 414
179static struct attribute *fujitsupf_attributes[] = { 415static struct attribute *fujitsupf_attributes[] = {
416 &dev_attr_brightness_changed.attr,
417 &dev_attr_max_brightness.attr,
180 &dev_attr_lcd_level.attr, 418 &dev_attr_lcd_level.attr,
181 NULL 419 NULL
182}; 420};
@@ -192,14 +430,52 @@ static struct platform_driver fujitsupf_driver = {
192 } 430 }
193}; 431};
194 432
195/* ACPI device */ 433static int dmi_check_cb_s6410(const struct dmi_system_id *id)
434{
435 acpi_handle handle;
436 int have_blnf;
437 printk(KERN_INFO "fujitsu-laptop: Identified laptop model '%s'.\n",
438 id->ident);
439 have_blnf = ACPI_SUCCESS
440 (acpi_get_handle(NULL, "\\_SB.PCI0.GFX0.LCD.BLNF", &handle));
441 if (use_alt_lcd_levels == -1) {
442 vdbg_printk(FUJLAPTOP_DBG_TRACE, "auto-detecting usealt\n");
443 use_alt_lcd_levels = 1;
444 }
445 if (disable_brightness_keys == -1) {
446 vdbg_printk(FUJLAPTOP_DBG_TRACE,
447 "auto-detecting disable_keys\n");
448 disable_brightness_keys = have_blnf ? 1 : 0;
449 }
450 if (disable_brightness_adjust == -1) {
451 vdbg_printk(FUJLAPTOP_DBG_TRACE,
452 "auto-detecting disable_adjust\n");
453 disable_brightness_adjust = have_blnf ? 0 : 1;
454 }
455 return 0;
456}
457
458static struct dmi_system_id __initdata fujitsu_dmi_table[] = {
459 {
460 .ident = "Fujitsu Siemens",
461 .matches = {
462 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
463 DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK S6410"),
464 },
465 .callback = dmi_check_cb_s6410},
466 {}
467};
468
469/* ACPI device for LCD brightness control */
196 470
197static int acpi_fujitsu_add(struct acpi_device *device) 471static int acpi_fujitsu_add(struct acpi_device *device)
198{ 472{
473 acpi_status status;
474 acpi_handle handle;
199 int result = 0; 475 int result = 0;
200 int state = 0; 476 int state = 0;
201 477 struct input_dev *input;
202 ACPI_FUNCTION_TRACE("acpi_fujitsu_add"); 478 int error;
203 479
204 if (!device) 480 if (!device)
205 return -EINVAL; 481 return -EINVAL;
@@ -209,10 +485,42 @@ static int acpi_fujitsu_add(struct acpi_device *device)
209 sprintf(acpi_device_class(device), "%s", ACPI_FUJITSU_CLASS); 485 sprintf(acpi_device_class(device), "%s", ACPI_FUJITSU_CLASS);
210 acpi_driver_data(device) = fujitsu; 486 acpi_driver_data(device) = fujitsu;
211 487
488 status = acpi_install_notify_handler(device->handle,
489 ACPI_DEVICE_NOTIFY,
490 acpi_fujitsu_notify, fujitsu);
491
492 if (ACPI_FAILURE(status)) {
493 printk(KERN_ERR "Error installing notify handler\n");
494 error = -ENODEV;
495 goto err_stop;
496 }
497
498 fujitsu->input = input = input_allocate_device();
499 if (!input) {
500 error = -ENOMEM;
501 goto err_uninstall_notify;
502 }
503
504 snprintf(fujitsu->phys, sizeof(fujitsu->phys),
505 "%s/video/input0", acpi_device_hid(device));
506
507 input->name = acpi_device_name(device);
508 input->phys = fujitsu->phys;
509 input->id.bustype = BUS_HOST;
510 input->id.product = 0x06;
511 input->dev.parent = &device->dev;
512 input->evbit[0] = BIT(EV_KEY);
513 set_bit(KEY_BRIGHTNESSUP, input->keybit);
514 set_bit(KEY_BRIGHTNESSDOWN, input->keybit);
515 set_bit(KEY_UNKNOWN, input->keybit);
516
517 error = input_register_device(input);
518 if (error)
519 goto err_free_input_dev;
520
212 result = acpi_bus_get_power(fujitsu->acpi_handle, &state); 521 result = acpi_bus_get_power(fujitsu->acpi_handle, &state);
213 if (result) { 522 if (result) {
214 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 523 printk(KERN_ERR "Error reading power state\n");
215 "Error reading power state\n"));
216 goto end; 524 goto end;
217 } 525 }
218 526
@@ -220,22 +528,373 @@ static int acpi_fujitsu_add(struct acpi_device *device)
220 acpi_device_name(device), acpi_device_bid(device), 528 acpi_device_name(device), acpi_device_bid(device),
221 !device->power.state ? "on" : "off"); 529 !device->power.state ? "on" : "off");
222 530
223 end: 531 fujitsu->dev = device;
532
533 if (ACPI_SUCCESS
534 (acpi_get_handle(device->handle, METHOD_NAME__INI, &handle))) {
535 vdbg_printk(FUJLAPTOP_DBG_INFO, "Invoking _INI\n");
536 if (ACPI_FAILURE
537 (acpi_evaluate_object
538 (device->handle, METHOD_NAME__INI, NULL, NULL)))
539 printk(KERN_ERR "_INI Method failed\n");
540 }
541
542 /* do config (detect defaults) */
543 dmi_check_system(fujitsu_dmi_table);
544 use_alt_lcd_levels = use_alt_lcd_levels == 1 ? 1 : 0;
545 disable_brightness_keys = disable_brightness_keys == 1 ? 1 : 0;
546 disable_brightness_adjust = disable_brightness_adjust == 1 ? 1 : 0;
547 vdbg_printk(FUJLAPTOP_DBG_INFO,
548 "config: [alt interface: %d], [key disable: %d], [adjust disable: %d]\n",
549 use_alt_lcd_levels, disable_brightness_keys,
550 disable_brightness_adjust);
551
552 if (get_max_brightness() <= 0)
553 fujitsu->max_brightness = FUJITSU_LCD_N_LEVELS;
554 if (use_alt_lcd_levels)
555 get_lcd_level_alt();
556 else
557 get_lcd_level();
558
559 return result;
560
561end:
562err_free_input_dev:
563 input_free_device(input);
564err_uninstall_notify:
565 acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
566 acpi_fujitsu_notify);
567err_stop:
224 568
225 return result; 569 return result;
226} 570}
227 571
228static int acpi_fujitsu_remove(struct acpi_device *device, int type) 572static int acpi_fujitsu_remove(struct acpi_device *device, int type)
229{ 573{
230 ACPI_FUNCTION_TRACE("acpi_fujitsu_remove"); 574 acpi_status status;
575 struct fujitsu_t *fujitsu = NULL;
231 576
232 if (!device || !acpi_driver_data(device)) 577 if (!device || !acpi_driver_data(device))
233 return -EINVAL; 578 return -EINVAL;
579
580 fujitsu = acpi_driver_data(device);
581
582 status = acpi_remove_notify_handler(fujitsu->acpi_handle,
583 ACPI_DEVICE_NOTIFY,
584 acpi_fujitsu_notify);
585
586 if (!device || !acpi_driver_data(device))
587 return -EINVAL;
588
234 fujitsu->acpi_handle = NULL; 589 fujitsu->acpi_handle = NULL;
235 590
236 return 0; 591 return 0;
237} 592}
238 593
594/* Brightness notify */
595
596static void acpi_fujitsu_notify(acpi_handle handle, u32 event, void *data)
597{
598 struct input_dev *input;
599 int keycode;
600 int oldb, newb;
601
602 input = fujitsu->input;
603
604 switch (event) {
605 case ACPI_FUJITSU_NOTIFY_CODE1:
606 keycode = 0;
607 oldb = fujitsu->brightness_level;
608 get_lcd_level(); /* the alt version always yields changed */
609 newb = fujitsu->brightness_level;
610
611 vdbg_printk(FUJLAPTOP_DBG_TRACE,
612 "brightness button event [%i -> %i (%i)]\n",
613 oldb, newb, fujitsu->brightness_changed);
614
615 if (oldb == newb && fujitsu->brightness_changed) {
616 keycode = 0;
617 if (disable_brightness_keys != 1) {
618 if (oldb == 0) {
619 acpi_bus_generate_proc_event(fujitsu->
620 dev,
621 ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS,
622 0);
623 keycode = KEY_BRIGHTNESSDOWN;
624 } else if (oldb ==
625 (fujitsu->max_brightness) - 1) {
626 acpi_bus_generate_proc_event(fujitsu->
627 dev,
628 ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS,
629 0);
630 keycode = KEY_BRIGHTNESSUP;
631 }
632 }
633 } else if (oldb < newb) {
634 if (disable_brightness_adjust != 1) {
635 if (use_alt_lcd_levels)
636 set_lcd_level_alt(newb);
637 else
638 set_lcd_level(newb);
639 }
640 if (disable_brightness_keys != 1) {
641 acpi_bus_generate_proc_event(fujitsu->dev,
642 ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS,
643 0);
644 keycode = KEY_BRIGHTNESSUP;
645 }
646 } else if (oldb > newb) {
647 if (disable_brightness_adjust != 1) {
648 if (use_alt_lcd_levels)
649 set_lcd_level_alt(newb);
650 else
651 set_lcd_level(newb);
652 }
653 if (disable_brightness_keys != 1) {
654 acpi_bus_generate_proc_event(fujitsu->dev,
655 ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS,
656 0);
657 keycode = KEY_BRIGHTNESSDOWN;
658 }
659 } else {
660 keycode = KEY_UNKNOWN;
661 }
662 break;
663 default:
664 keycode = KEY_UNKNOWN;
665 vdbg_printk(FUJLAPTOP_DBG_WARN,
666 "unsupported event [0x%x]\n", event);
667 break;
668 }
669
670 if (keycode != 0) {
671 input_report_key(input, keycode, 1);
672 input_sync(input);
673 input_report_key(input, keycode, 0);
674 input_sync(input);
675 }
676
677 return;
678}
679
680/* ACPI device for hotkey handling */
681
682static int acpi_fujitsu_hotkey_add(struct acpi_device *device)
683{
684 acpi_status status;
685 acpi_handle handle;
686 int result = 0;
687 int state = 0;
688 struct input_dev *input;
689 int error;
690 int i;
691
692 if (!device)
693 return -EINVAL;
694
695 fujitsu_hotkey->acpi_handle = device->handle;
696 sprintf(acpi_device_name(device), "%s",
697 ACPI_FUJITSU_HOTKEY_DEVICE_NAME);
698 sprintf(acpi_device_class(device), "%s", ACPI_FUJITSU_CLASS);
699 acpi_driver_data(device) = fujitsu_hotkey;
700
701 status = acpi_install_notify_handler(device->handle,
702 ACPI_DEVICE_NOTIFY,
703 acpi_fujitsu_hotkey_notify,
704 fujitsu_hotkey);
705
706 if (ACPI_FAILURE(status)) {
707 printk(KERN_ERR "Error installing notify handler\n");
708 error = -ENODEV;
709 goto err_stop;
710 }
711
712 /* kfifo */
713 spin_lock_init(&fujitsu_hotkey->fifo_lock);
714 fujitsu_hotkey->fifo =
715 kfifo_alloc(RINGBUFFERSIZE * sizeof(int), GFP_KERNEL,
716 &fujitsu_hotkey->fifo_lock);
717 if (IS_ERR(fujitsu_hotkey->fifo)) {
718 printk(KERN_ERR "kfifo_alloc failed\n");
719 error = PTR_ERR(fujitsu_hotkey->fifo);
720 goto err_stop;
721 }
722
723 fujitsu_hotkey->input = input = input_allocate_device();
724 if (!input) {
725 error = -ENOMEM;
726 goto err_uninstall_notify;
727 }
728
729 snprintf(fujitsu_hotkey->phys, sizeof(fujitsu_hotkey->phys),
730 "%s/video/input0", acpi_device_hid(device));
731
732 input->name = acpi_device_name(device);
733 input->phys = fujitsu_hotkey->phys;
734 input->id.bustype = BUS_HOST;
735 input->id.product = 0x06;
736 input->dev.parent = &device->dev;
737 input->evbit[0] = BIT(EV_KEY);
738 set_bit(KEY_SCREENLOCK, input->keybit);
739 set_bit(KEY_MEDIA, input->keybit);
740 set_bit(KEY_EMAIL, input->keybit);
741 set_bit(KEY_SUSPEND, input->keybit);
742 set_bit(KEY_UNKNOWN, input->keybit);
743
744 error = input_register_device(input);
745 if (error)
746 goto err_free_input_dev;
747
748 result = acpi_bus_get_power(fujitsu_hotkey->acpi_handle, &state);
749 if (result) {
750 printk(KERN_ERR "Error reading power state\n");
751 goto end;
752 }
753
754 printk(KERN_INFO PREFIX "%s [%s] (%s)\n",
755 acpi_device_name(device), acpi_device_bid(device),
756 !device->power.state ? "on" : "off");
757
758 fujitsu_hotkey->dev = device;
759
760 if (ACPI_SUCCESS
761 (acpi_get_handle(device->handle, METHOD_NAME__INI, &handle))) {
762 vdbg_printk(FUJLAPTOP_DBG_INFO, "Invoking _INI\n");
763 if (ACPI_FAILURE
764 (acpi_evaluate_object
765 (device->handle, METHOD_NAME__INI, NULL, NULL)))
766 printk(KERN_ERR "_INI Method failed\n");
767 }
768
769 i = 0; /* Discard hotkey ringbuffer */
770 while (get_irb() != 0 && (i++) < MAX_HOTKEY_RINGBUFFER_SIZE) ;
771 vdbg_printk(FUJLAPTOP_DBG_INFO, "Discarded %i ringbuffer entries\n", i);
772
773 return result;
774
775end:
776err_free_input_dev:
777 input_free_device(input);
778err_uninstall_notify:
779 acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
780 acpi_fujitsu_hotkey_notify);
781 kfifo_free(fujitsu_hotkey->fifo);
782err_stop:
783
784 return result;
785}
786
787static int acpi_fujitsu_hotkey_remove(struct acpi_device *device, int type)
788{
789 acpi_status status;
790 struct fujitsu_hotkey_t *fujitsu_hotkey = NULL;
791
792 if (!device || !acpi_driver_data(device))
793 return -EINVAL;
794
795 fujitsu_hotkey = acpi_driver_data(device);
796
797 status = acpi_remove_notify_handler(fujitsu_hotkey->acpi_handle,
798 ACPI_DEVICE_NOTIFY,
799 acpi_fujitsu_hotkey_notify);
800
801 fujitsu_hotkey->acpi_handle = NULL;
802
803 kfifo_free(fujitsu_hotkey->fifo);
804
805 return 0;
806}
807
808static void acpi_fujitsu_hotkey_notify(acpi_handle handle, u32 event,
809 void *data)
810{
811 struct input_dev *input;
812 int keycode, keycode_r;
813 unsigned int irb = 1;
814 int i, status;
815
816 input = fujitsu_hotkey->input;
817
818 vdbg_printk(FUJLAPTOP_DBG_TRACE, "Hotkey event\n");
819
820 switch (event) {
821 case ACPI_FUJITSU_NOTIFY_CODE1:
822 i = 0;
823 while ((irb = get_irb()) != 0
824 && (i++) < MAX_HOTKEY_RINGBUFFER_SIZE) {
825 vdbg_printk(FUJLAPTOP_DBG_TRACE, "GIRB result [%x]\n",
826 irb);
827
828 switch (irb & 0x4ff) {
829 case LOCK_KEY:
830 keycode = KEY_SCREENLOCK;
831 break;
832 case DISPLAY_KEY:
833 keycode = KEY_MEDIA;
834 break;
835 case ENERGY_KEY:
836 keycode = KEY_EMAIL;
837 break;
838 case REST_KEY:
839 keycode = KEY_SUSPEND;
840 break;
841 case 0:
842 keycode = 0;
843 break;
844 default:
845 vdbg_printk(FUJLAPTOP_DBG_WARN,
846 "Unknown GIRB result [%x]\n", irb);
847 keycode = -1;
848 break;
849 }
850 if (keycode > 0) {
851 vdbg_printk(FUJLAPTOP_DBG_TRACE,
852 "Push keycode into ringbuffer [%d]\n",
853 keycode);
854 status = kfifo_put(fujitsu_hotkey->fifo,
855 (unsigned char *)&keycode,
856 sizeof(keycode));
857 if (status != sizeof(keycode)) {
858 vdbg_printk(FUJLAPTOP_DBG_WARN,
859 "Could not push keycode [0x%x]\n",
860 keycode);
861 } else {
862 input_report_key(input, keycode, 1);
863 input_sync(input);
864 }
865 } else if (keycode == 0) {
866 while ((status =
867 kfifo_get
868 (fujitsu_hotkey->fifo, (unsigned char *)
869 &keycode_r,
870 sizeof
871 (keycode_r))) == sizeof(keycode_r)) {
872 input_report_key(input, keycode_r, 0);
873 input_sync(input);
874 vdbg_printk(FUJLAPTOP_DBG_TRACE,
875 "Pop keycode from ringbuffer [%d]\n",
876 keycode_r);
877 }
878 }
879 }
880
881 break;
882 default:
883 keycode = KEY_UNKNOWN;
884 vdbg_printk(FUJLAPTOP_DBG_WARN,
885 "Unsupported event [0x%x]\n", event);
886 input_report_key(input, keycode, 1);
887 input_sync(input);
888 input_report_key(input, keycode, 0);
889 input_sync(input);
890 break;
891 }
892
893 return;
894}
895
896/* Initialization */
897
239static const struct acpi_device_id fujitsu_device_ids[] = { 898static const struct acpi_device_id fujitsu_device_ids[] = {
240 {ACPI_FUJITSU_HID, 0}, 899 {ACPI_FUJITSU_HID, 0},
241 {"", 0}, 900 {"", 0},
@@ -251,11 +910,24 @@ static struct acpi_driver acpi_fujitsu_driver = {
251 }, 910 },
252}; 911};
253 912
254/* Initialization */ 913static const struct acpi_device_id fujitsu_hotkey_device_ids[] = {
914 {ACPI_FUJITSU_HOTKEY_HID, 0},
915 {"", 0},
916};
917
918static struct acpi_driver acpi_fujitsu_hotkey_driver = {
919 .name = ACPI_FUJITSU_HOTKEY_DRIVER_NAME,
920 .class = ACPI_FUJITSU_CLASS,
921 .ids = fujitsu_hotkey_device_ids,
922 .ops = {
923 .add = acpi_fujitsu_hotkey_add,
924 .remove = acpi_fujitsu_hotkey_remove,
925 },
926};
255 927
256static int __init fujitsu_init(void) 928static int __init fujitsu_init(void)
257{ 929{
258 int ret, result; 930 int ret, result, max_brightness;
259 931
260 if (acpi_disabled) 932 if (acpi_disabled)
261 return -ENODEV; 933 return -ENODEV;
@@ -271,19 +943,6 @@ static int __init fujitsu_init(void)
271 goto fail_acpi; 943 goto fail_acpi;
272 } 944 }
273 945
274 /* Register backlight stuff */
275
276 fujitsu->bl_device =
277 backlight_device_register("fujitsu-laptop", NULL, NULL,
278 &fujitsubl_ops);
279 if (IS_ERR(fujitsu->bl_device))
280 return PTR_ERR(fujitsu->bl_device);
281
282 fujitsu->bl_device->props.max_brightness = FUJITSU_LCD_N_LEVELS - 1;
283 ret = platform_driver_register(&fujitsupf_driver);
284 if (ret)
285 goto fail_backlight;
286
287 /* Register platform stuff */ 946 /* Register platform stuff */
288 947
289 fujitsu->pf_device = platform_device_alloc("fujitsu-laptop", -1); 948 fujitsu->pf_device = platform_device_alloc("fujitsu-laptop", -1);
@@ -302,28 +961,68 @@ static int __init fujitsu_init(void)
302 if (ret) 961 if (ret)
303 goto fail_platform_device2; 962 goto fail_platform_device2;
304 963
964 /* Register backlight stuff */
965
966 fujitsu->bl_device =
967 backlight_device_register("fujitsu-laptop", NULL, NULL,
968 &fujitsubl_ops);
969 if (IS_ERR(fujitsu->bl_device))
970 return PTR_ERR(fujitsu->bl_device);
971
972 max_brightness = fujitsu->max_brightness;
973
974 fujitsu->bl_device->props.max_brightness = max_brightness - 1;
975 fujitsu->bl_device->props.brightness = fujitsu->brightness_level;
976
977 ret = platform_driver_register(&fujitsupf_driver);
978 if (ret)
979 goto fail_backlight;
980
981 /* Register hotkey driver */
982
983 fujitsu_hotkey = kmalloc(sizeof(struct fujitsu_hotkey_t), GFP_KERNEL);
984 if (!fujitsu_hotkey) {
985 ret = -ENOMEM;
986 goto fail_hotkey;
987 }
988 memset(fujitsu_hotkey, 0, sizeof(struct fujitsu_hotkey_t));
989
990 result = acpi_bus_register_driver(&acpi_fujitsu_hotkey_driver);
991 if (result < 0) {
992 ret = -ENODEV;
993 goto fail_hotkey1;
994 }
995
305 printk(KERN_INFO "fujitsu-laptop: driver " FUJITSU_DRIVER_VERSION 996 printk(KERN_INFO "fujitsu-laptop: driver " FUJITSU_DRIVER_VERSION
306 " successfully loaded.\n"); 997 " successfully loaded.\n");
307 998
308 return 0; 999 return 0;
309 1000
310 fail_platform_device2: 1001fail_hotkey1:
311 1002
312 platform_device_del(fujitsu->pf_device); 1003 kfree(fujitsu_hotkey);
313
314 fail_platform_device1:
315
316 platform_device_put(fujitsu->pf_device);
317 1004
318 fail_platform_driver: 1005fail_hotkey:
319 1006
320 platform_driver_unregister(&fujitsupf_driver); 1007 platform_driver_unregister(&fujitsupf_driver);
321 1008
322 fail_backlight: 1009fail_backlight:
323 1010
324 backlight_device_unregister(fujitsu->bl_device); 1011 backlight_device_unregister(fujitsu->bl_device);
325 1012
326 fail_acpi: 1013fail_platform_device2:
1014
1015 platform_device_del(fujitsu->pf_device);
1016
1017fail_platform_device1:
1018
1019 platform_device_put(fujitsu->pf_device);
1020
1021fail_platform_driver:
1022
1023 acpi_bus_unregister_driver(&acpi_fujitsu_driver);
1024
1025fail_acpi:
327 1026
328 kfree(fujitsu); 1027 kfree(fujitsu);
329 1028
@@ -342,19 +1041,43 @@ static void __exit fujitsu_cleanup(void)
342 1041
343 kfree(fujitsu); 1042 kfree(fujitsu);
344 1043
1044 acpi_bus_unregister_driver(&acpi_fujitsu_hotkey_driver);
1045
1046 kfree(fujitsu_hotkey);
1047
345 printk(KERN_INFO "fujitsu-laptop: driver unloaded.\n"); 1048 printk(KERN_INFO "fujitsu-laptop: driver unloaded.\n");
346} 1049}
347 1050
348module_init(fujitsu_init); 1051module_init(fujitsu_init);
349module_exit(fujitsu_cleanup); 1052module_exit(fujitsu_cleanup);
350 1053
351MODULE_AUTHOR("Jonathan Woithe"); 1054module_param(use_alt_lcd_levels, uint, 0644);
1055MODULE_PARM_DESC(use_alt_lcd_levels,
1056 "Use alternative interface for lcd_levels (needed for Lifebook s6410).");
1057module_param(disable_brightness_keys, uint, 0644);
1058MODULE_PARM_DESC(disable_brightness_keys,
1059 "Disable brightness keys (eg. if they are already handled by the generic ACPI_VIDEO device).");
1060module_param(disable_brightness_adjust, uint, 0644);
1061MODULE_PARM_DESC(disable_brightness_adjust, "Disable brightness adjustment .");
1062#ifdef CONFIG_FUJITSU_LAPTOP_DEBUG
1063module_param_named(debug, dbg_level, uint, 0644);
1064MODULE_PARM_DESC(debug, "Sets debug level bit-mask");
1065#endif
1066
1067MODULE_AUTHOR("Jonathan Woithe, Peter Gruber");
352MODULE_DESCRIPTION("Fujitsu laptop extras support"); 1068MODULE_DESCRIPTION("Fujitsu laptop extras support");
353MODULE_VERSION(FUJITSU_DRIVER_VERSION); 1069MODULE_VERSION(FUJITSU_DRIVER_VERSION);
354MODULE_LICENSE("GPL"); 1070MODULE_LICENSE("GPL");
355 1071
1072MODULE_ALIAS
1073 ("dmi:*:svnFUJITSUSIEMENS:*:pvr:rvnFUJITSU:rnFJNB1D3:*:cvrS6410:*");
1074MODULE_ALIAS
1075 ("dmi:*:svnFUJITSU:*:pvr:rvnFUJITSU:rnFJNB19C:*:cvrS7020:*");
1076
356static struct pnp_device_id pnp_ids[] = { 1077static struct pnp_device_id pnp_ids[] = {
357 { .id = "FUJ02bf" }, 1078 { .id = "FUJ02bf" },
1079 { .id = "FUJ02B1" },
1080 { .id = "FUJ02E3" },
358 { .id = "" } 1081 { .id = "" }
359}; 1082};
360MODULE_DEVICE_TABLE(pnp, pnp_ids); 1083MODULE_DEVICE_TABLE(pnp, pnp_ids);
diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c
index 9d6fc8e6285d..dab9d471914c 100644
--- a/drivers/pci/pci-acpi.c
+++ b/drivers/pci/pci-acpi.c
@@ -293,13 +293,11 @@ EXPORT_SYMBOL(pci_osc_control_set);
293 * choose highest power _SxD or any lower power 293 * choose highest power _SxD or any lower power
294 */ 294 */
295 295
296static pci_power_t acpi_pci_choose_state(struct pci_dev *pdev, 296static pci_power_t acpi_pci_choose_state(struct pci_dev *pdev)
297 pm_message_t state)
298{ 297{
299 int acpi_state; 298 int acpi_state;
300 299
301 acpi_state = acpi_pm_device_sleep_state(&pdev->dev, 300 acpi_state = acpi_pm_device_sleep_state(&pdev->dev, NULL);
302 device_may_wakeup(&pdev->dev), NULL);
303 if (acpi_state < 0) 301 if (acpi_state < 0)
304 return PCI_POWER_ERROR; 302 return PCI_POWER_ERROR;
305 303
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index e4548ab2a93c..75c60239cadd 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -508,7 +508,7 @@ pci_set_power_state(struct pci_dev *dev, pci_power_t state)
508 return 0; 508 return 0;
509} 509}
510 510
511pci_power_t (*platform_pci_choose_state)(struct pci_dev *dev, pm_message_t state); 511pci_power_t (*platform_pci_choose_state)(struct pci_dev *dev);
512 512
513/** 513/**
514 * pci_choose_state - Choose the power state of a PCI device 514 * pci_choose_state - Choose the power state of a PCI device
@@ -528,7 +528,7 @@ pci_power_t pci_choose_state(struct pci_dev *dev, pm_message_t state)
528 return PCI_D0; 528 return PCI_D0;
529 529
530 if (platform_pci_choose_state) { 530 if (platform_pci_choose_state) {
531 ret = platform_pci_choose_state(dev, state); 531 ret = platform_pci_choose_state(dev);
532 if (ret != PCI_POWER_ERROR) 532 if (ret != PCI_POWER_ERROR)
533 return ret; 533 return ret;
534 } 534 }
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index 00408c97e5fc..312daff834b6 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -6,8 +6,7 @@ extern void pci_remove_sysfs_dev_files(struct pci_dev *pdev);
6extern void pci_cleanup_rom(struct pci_dev *dev); 6extern void pci_cleanup_rom(struct pci_dev *dev);
7 7
8/* Firmware callbacks */ 8/* Firmware callbacks */
9extern pci_power_t (*platform_pci_choose_state)(struct pci_dev *dev, 9extern pci_power_t (*platform_pci_choose_state)(struct pci_dev *dev);
10 pm_message_t state);
11extern int (*platform_pci_set_power_state)(struct pci_dev *dev, 10extern int (*platform_pci_set_power_state)(struct pci_dev *dev,
12 pci_power_t state); 11 pci_power_t state);
13 12
diff --git a/drivers/pnp/base.h b/drivers/pnp/base.h
index 886dac823ed6..e3fa9a2d9a3d 100644
--- a/drivers/pnp/base.h
+++ b/drivers/pnp/base.h
@@ -1,3 +1,8 @@
1/*
2 * Copyright (C) 2008 Hewlett-Packard Development Company, L.P.
3 * Bjorn Helgaas <bjorn.helgaas@hp.com>
4 */
5
1extern spinlock_t pnp_lock; 6extern spinlock_t pnp_lock;
2void *pnp_alloc(long size); 7void *pnp_alloc(long size);
3 8
@@ -19,22 +24,118 @@ void pnp_remove_card(struct pnp_card *card);
19int pnp_add_card_device(struct pnp_card *card, struct pnp_dev *dev); 24int pnp_add_card_device(struct pnp_card *card, struct pnp_dev *dev);
20void pnp_remove_card_device(struct pnp_dev *dev); 25void pnp_remove_card_device(struct pnp_dev *dev);
21 26
22struct pnp_option *pnp_build_option(int priority); 27struct pnp_port {
23struct pnp_option *pnp_register_independent_option(struct pnp_dev *dev); 28 resource_size_t min; /* min base number */
24struct pnp_option *pnp_register_dependent_option(struct pnp_dev *dev, 29 resource_size_t max; /* max base number */
25 int priority); 30 resource_size_t align; /* align boundary */
26int pnp_register_irq_resource(struct pnp_dev *dev, struct pnp_option *option, 31 resource_size_t size; /* size of range */
27 struct pnp_irq *data); 32 unsigned char flags; /* port flags */
28int pnp_register_dma_resource(struct pnp_dev *dev, struct pnp_option *option, 33};
29 struct pnp_dma *data); 34
30int pnp_register_port_resource(struct pnp_dev *dev, struct pnp_option *option, 35#define PNP_IRQ_NR 256
31 struct pnp_port *data); 36typedef struct { DECLARE_BITMAP(bits, PNP_IRQ_NR); } pnp_irq_mask_t;
32int pnp_register_mem_resource(struct pnp_dev *dev, struct pnp_option *option, 37
33 struct pnp_mem *data); 38struct pnp_irq {
39 pnp_irq_mask_t map; /* bitmap for IRQ lines */
40 unsigned char flags; /* IRQ flags */
41};
42
43struct pnp_dma {
44 unsigned char map; /* bitmask for DMA channels */
45 unsigned char flags; /* DMA flags */
46};
47
48struct pnp_mem {
49 resource_size_t min; /* min base number */
50 resource_size_t max; /* max base number */
51 resource_size_t align; /* align boundary */
52 resource_size_t size; /* size of range */
53 unsigned char flags; /* memory flags */
54};
55
56#define PNP_OPTION_DEPENDENT 0x80000000
57#define PNP_OPTION_SET_MASK 0xffff
58#define PNP_OPTION_SET_SHIFT 12
59#define PNP_OPTION_PRIORITY_MASK 0xfff
60#define PNP_OPTION_PRIORITY_SHIFT 0
61
62#define PNP_RES_PRIORITY_PREFERRED 0
63#define PNP_RES_PRIORITY_ACCEPTABLE 1
64#define PNP_RES_PRIORITY_FUNCTIONAL 2
65#define PNP_RES_PRIORITY_INVALID PNP_OPTION_PRIORITY_MASK
66
67struct pnp_option {
68 struct list_head list;
69 unsigned int flags; /* independent/dependent, set, priority */
70
71 unsigned long type; /* IORESOURCE_{IO,MEM,IRQ,DMA} */
72 union {
73 struct pnp_port port;
74 struct pnp_irq irq;
75 struct pnp_dma dma;
76 struct pnp_mem mem;
77 } u;
78};
79
80int pnp_register_irq_resource(struct pnp_dev *dev, unsigned int option_flags,
81 pnp_irq_mask_t *map, unsigned char flags);
82int pnp_register_dma_resource(struct pnp_dev *dev, unsigned int option_flags,
83 unsigned char map, unsigned char flags);
84int pnp_register_port_resource(struct pnp_dev *dev, unsigned int option_flags,
85 resource_size_t min, resource_size_t max,
86 resource_size_t align, resource_size_t size,
87 unsigned char flags);
88int pnp_register_mem_resource(struct pnp_dev *dev, unsigned int option_flags,
89 resource_size_t min, resource_size_t max,
90 resource_size_t align, resource_size_t size,
91 unsigned char flags);
92
93static inline int pnp_option_is_dependent(struct pnp_option *option)
94{
95 return option->flags & PNP_OPTION_DEPENDENT ? 1 : 0;
96}
97
98static inline unsigned int pnp_option_set(struct pnp_option *option)
99{
100 return (option->flags >> PNP_OPTION_SET_SHIFT) & PNP_OPTION_SET_MASK;
101}
102
103static inline unsigned int pnp_option_priority(struct pnp_option *option)
104{
105 return (option->flags >> PNP_OPTION_PRIORITY_SHIFT) &
106 PNP_OPTION_PRIORITY_MASK;
107}
108
109static inline unsigned int pnp_new_dependent_set(struct pnp_dev *dev,
110 int priority)
111{
112 unsigned int flags;
113
114 if (priority > PNP_RES_PRIORITY_FUNCTIONAL) {
115 dev_warn(&dev->dev, "invalid dependent option priority %d "
116 "clipped to %d", priority,
117 PNP_RES_PRIORITY_INVALID);
118 priority = PNP_RES_PRIORITY_INVALID;
119 }
120
121 flags = PNP_OPTION_DEPENDENT |
122 ((dev->num_dependent_sets & PNP_OPTION_SET_MASK) <<
123 PNP_OPTION_SET_SHIFT) |
124 ((priority & PNP_OPTION_PRIORITY_MASK) <<
125 PNP_OPTION_PRIORITY_SHIFT);
126
127 dev->num_dependent_sets++;
128
129 return flags;
130}
131
132char *pnp_option_priority_name(struct pnp_option *option);
133void dbg_pnp_show_option(struct pnp_dev *dev, struct pnp_option *option);
134
34void pnp_init_resources(struct pnp_dev *dev); 135void pnp_init_resources(struct pnp_dev *dev);
35 136
36void pnp_fixup_device(struct pnp_dev *dev); 137void pnp_fixup_device(struct pnp_dev *dev);
37void pnp_free_option(struct pnp_option *option); 138void pnp_free_options(struct pnp_dev *dev);
38int __pnp_add_device(struct pnp_dev *dev); 139int __pnp_add_device(struct pnp_dev *dev);
39void __pnp_remove_device(struct pnp_dev *dev); 140void __pnp_remove_device(struct pnp_dev *dev);
40 141
@@ -43,29 +144,18 @@ int pnp_check_mem(struct pnp_dev *dev, struct resource *res);
43int pnp_check_irq(struct pnp_dev *dev, struct resource *res); 144int pnp_check_irq(struct pnp_dev *dev, struct resource *res);
44int pnp_check_dma(struct pnp_dev *dev, struct resource *res); 145int pnp_check_dma(struct pnp_dev *dev, struct resource *res);
45 146
147char *pnp_resource_type_name(struct resource *res);
46void dbg_pnp_show_resources(struct pnp_dev *dev, char *desc); 148void dbg_pnp_show_resources(struct pnp_dev *dev, char *desc);
47 149
48void pnp_init_resource(struct resource *res); 150void pnp_free_resources(struct pnp_dev *dev);
49 151int pnp_resource_type(struct resource *res);
50struct pnp_resource *pnp_get_pnp_resource(struct pnp_dev *dev,
51 unsigned int type, unsigned int num);
52
53#define PNP_MAX_PORT 40
54#define PNP_MAX_MEM 24
55#define PNP_MAX_IRQ 2
56#define PNP_MAX_DMA 2
57 152
58struct pnp_resource { 153struct pnp_resource {
154 struct list_head list;
59 struct resource res; 155 struct resource res;
60 unsigned int index; /* ISAPNP config register index */
61}; 156};
62 157
63struct pnp_resource_table { 158void pnp_free_resource(struct pnp_resource *pnp_res);
64 struct pnp_resource port[PNP_MAX_PORT];
65 struct pnp_resource mem[PNP_MAX_MEM];
66 struct pnp_resource dma[PNP_MAX_DMA];
67 struct pnp_resource irq[PNP_MAX_IRQ];
68};
69 159
70struct pnp_resource *pnp_add_irq_resource(struct pnp_dev *dev, int irq, 160struct pnp_resource *pnp_add_irq_resource(struct pnp_dev *dev, int irq,
71 int flags); 161 int flags);
diff --git a/drivers/pnp/core.c b/drivers/pnp/core.c
index 20771b7d4482..a411582bcd72 100644
--- a/drivers/pnp/core.c
+++ b/drivers/pnp/core.c
@@ -99,14 +99,28 @@ static void pnp_free_ids(struct pnp_dev *dev)
99 } 99 }
100} 100}
101 101
102void pnp_free_resource(struct pnp_resource *pnp_res)
103{
104 list_del(&pnp_res->list);
105 kfree(pnp_res);
106}
107
108void pnp_free_resources(struct pnp_dev *dev)
109{
110 struct pnp_resource *pnp_res, *tmp;
111
112 list_for_each_entry_safe(pnp_res, tmp, &dev->resources, list) {
113 pnp_free_resource(pnp_res);
114 }
115}
116
102static void pnp_release_device(struct device *dmdev) 117static void pnp_release_device(struct device *dmdev)
103{ 118{
104 struct pnp_dev *dev = to_pnp_dev(dmdev); 119 struct pnp_dev *dev = to_pnp_dev(dmdev);
105 120
106 pnp_free_option(dev->independent);
107 pnp_free_option(dev->dependent);
108 pnp_free_ids(dev); 121 pnp_free_ids(dev);
109 kfree(dev->res); 122 pnp_free_resources(dev);
123 pnp_free_options(dev);
110 kfree(dev); 124 kfree(dev);
111} 125}
112 126
@@ -119,12 +133,8 @@ struct pnp_dev *pnp_alloc_dev(struct pnp_protocol *protocol, int id, char *pnpid
119 if (!dev) 133 if (!dev)
120 return NULL; 134 return NULL;
121 135
122 dev->res = kzalloc(sizeof(struct pnp_resource_table), GFP_KERNEL); 136 INIT_LIST_HEAD(&dev->resources);
123 if (!dev->res) { 137 INIT_LIST_HEAD(&dev->options);
124 kfree(dev);
125 return NULL;
126 }
127
128 dev->protocol = protocol; 138 dev->protocol = protocol;
129 dev->number = id; 139 dev->number = id;
130 dev->dma_mask = DMA_24BIT_MASK; 140 dev->dma_mask = DMA_24BIT_MASK;
@@ -140,7 +150,6 @@ struct pnp_dev *pnp_alloc_dev(struct pnp_protocol *protocol, int id, char *pnpid
140 150
141 dev_id = pnp_add_id(dev, pnpid); 151 dev_id = pnp_add_id(dev, pnpid);
142 if (!dev_id) { 152 if (!dev_id) {
143 kfree(dev->res);
144 kfree(dev); 153 kfree(dev);
145 return NULL; 154 return NULL;
146 } 155 }
diff --git a/drivers/pnp/interface.c b/drivers/pnp/interface.c
index 5695a79f3a52..a876ecf7028c 100644
--- a/drivers/pnp/interface.c
+++ b/drivers/pnp/interface.c
@@ -3,6 +3,8 @@
3 * 3 *
4 * Some code, especially possible resource dumping is based on isapnp_proc.c (c) Jaroslav Kysela <perex@perex.cz> 4 * Some code, especially possible resource dumping is based on isapnp_proc.c (c) Jaroslav Kysela <perex@perex.cz>
5 * Copyright 2002 Adam Belay <ambx1@neo.rr.com> 5 * Copyright 2002 Adam Belay <ambx1@neo.rr.com>
6 * Copyright (C) 2008 Hewlett-Packard Development Company, L.P.
7 * Bjorn Helgaas <bjorn.helgaas@hp.com>
6 */ 8 */
7 9
8#include <linux/pnp.h> 10#include <linux/pnp.h>
@@ -53,11 +55,13 @@ static int pnp_printf(pnp_info_buffer_t * buffer, char *fmt, ...)
53static void pnp_print_port(pnp_info_buffer_t * buffer, char *space, 55static void pnp_print_port(pnp_info_buffer_t * buffer, char *space,
54 struct pnp_port *port) 56 struct pnp_port *port)
55{ 57{
56 pnp_printf(buffer, 58 pnp_printf(buffer, "%sport %#llx-%#llx, align %#llx, size %#llx, "
57 "%sport 0x%x-0x%x, align 0x%x, size 0x%x, %i-bit address decoding\n", 59 "%i-bit address decoding\n", space,
58 space, port->min, port->max, 60 (unsigned long long) port->min,
59 port->align ? (port->align - 1) : 0, port->size, 61 (unsigned long long) port->max,
60 port->flags & PNP_PORT_FLAG_16BITADDR ? 16 : 10); 62 port->align ? ((unsigned long long) port->align - 1) : 0,
63 (unsigned long long) port->size,
64 port->flags & IORESOURCE_IO_16BIT_ADDR ? 16 : 10);
61} 65}
62 66
63static void pnp_print_irq(pnp_info_buffer_t * buffer, char *space, 67static void pnp_print_irq(pnp_info_buffer_t * buffer, char *space,
@@ -67,7 +71,7 @@ static void pnp_print_irq(pnp_info_buffer_t * buffer, char *space,
67 71
68 pnp_printf(buffer, "%sirq ", space); 72 pnp_printf(buffer, "%sirq ", space);
69 for (i = 0; i < PNP_IRQ_NR; i++) 73 for (i = 0; i < PNP_IRQ_NR; i++)
70 if (test_bit(i, irq->map)) { 74 if (test_bit(i, irq->map.bits)) {
71 if (!first) { 75 if (!first) {
72 pnp_printf(buffer, ","); 76 pnp_printf(buffer, ",");
73 } else { 77 } else {
@@ -78,7 +82,7 @@ static void pnp_print_irq(pnp_info_buffer_t * buffer, char *space,
78 else 82 else
79 pnp_printf(buffer, "%i", i); 83 pnp_printf(buffer, "%i", i);
80 } 84 }
81 if (bitmap_empty(irq->map, PNP_IRQ_NR)) 85 if (bitmap_empty(irq->map.bits, PNP_IRQ_NR))
82 pnp_printf(buffer, "<none>"); 86 pnp_printf(buffer, "<none>");
83 if (irq->flags & IORESOURCE_IRQ_HIGHEDGE) 87 if (irq->flags & IORESOURCE_IRQ_HIGHEDGE)
84 pnp_printf(buffer, " High-Edge"); 88 pnp_printf(buffer, " High-Edge");
@@ -88,6 +92,8 @@ static void pnp_print_irq(pnp_info_buffer_t * buffer, char *space,
88 pnp_printf(buffer, " High-Level"); 92 pnp_printf(buffer, " High-Level");
89 if (irq->flags & IORESOURCE_IRQ_LOWLEVEL) 93 if (irq->flags & IORESOURCE_IRQ_LOWLEVEL)
90 pnp_printf(buffer, " Low-Level"); 94 pnp_printf(buffer, " Low-Level");
95 if (irq->flags & IORESOURCE_IRQ_OPTIONAL)
96 pnp_printf(buffer, " (optional)");
91 pnp_printf(buffer, "\n"); 97 pnp_printf(buffer, "\n");
92} 98}
93 99
@@ -148,8 +154,11 @@ static void pnp_print_mem(pnp_info_buffer_t * buffer, char *space,
148{ 154{
149 char *s; 155 char *s;
150 156
151 pnp_printf(buffer, "%sMemory 0x%x-0x%x, align 0x%x, size 0x%x", 157 pnp_printf(buffer, "%sMemory %#llx-%#llx, align %#llx, size %#llx",
152 space, mem->min, mem->max, mem->align, mem->size); 158 space, (unsigned long long) mem->min,
159 (unsigned long long) mem->max,
160 (unsigned long long) mem->align,
161 (unsigned long long) mem->size);
153 if (mem->flags & IORESOURCE_MEM_WRITEABLE) 162 if (mem->flags & IORESOURCE_MEM_WRITEABLE)
154 pnp_printf(buffer, ", writeable"); 163 pnp_printf(buffer, ", writeable");
155 if (mem->flags & IORESOURCE_MEM_CACHEABLE) 164 if (mem->flags & IORESOURCE_MEM_CACHEABLE)
@@ -177,65 +186,58 @@ static void pnp_print_mem(pnp_info_buffer_t * buffer, char *space,
177} 186}
178 187
179static void pnp_print_option(pnp_info_buffer_t * buffer, char *space, 188static void pnp_print_option(pnp_info_buffer_t * buffer, char *space,
180 struct pnp_option *option, int dep) 189 struct pnp_option *option)
181{ 190{
182 char *s; 191 switch (option->type) {
183 struct pnp_port *port; 192 case IORESOURCE_IO:
184 struct pnp_irq *irq; 193 pnp_print_port(buffer, space, &option->u.port);
185 struct pnp_dma *dma; 194 break;
186 struct pnp_mem *mem; 195 case IORESOURCE_MEM:
187 196 pnp_print_mem(buffer, space, &option->u.mem);
188 if (dep) { 197 break;
189 switch (option->priority) { 198 case IORESOURCE_IRQ:
190 case PNP_RES_PRIORITY_PREFERRED: 199 pnp_print_irq(buffer, space, &option->u.irq);
191 s = "preferred"; 200 break;
192 break; 201 case IORESOURCE_DMA:
193 case PNP_RES_PRIORITY_ACCEPTABLE: 202 pnp_print_dma(buffer, space, &option->u.dma);
194 s = "acceptable"; 203 break;
195 break;
196 case PNP_RES_PRIORITY_FUNCTIONAL:
197 s = "functional";
198 break;
199 default:
200 s = "invalid";
201 }
202 pnp_printf(buffer, "Dependent: %02i - Priority %s\n", dep, s);
203 } 204 }
204
205 for (port = option->port; port; port = port->next)
206 pnp_print_port(buffer, space, port);
207 for (irq = option->irq; irq; irq = irq->next)
208 pnp_print_irq(buffer, space, irq);
209 for (dma = option->dma; dma; dma = dma->next)
210 pnp_print_dma(buffer, space, dma);
211 for (mem = option->mem; mem; mem = mem->next)
212 pnp_print_mem(buffer, space, mem);
213} 205}
214 206
215static ssize_t pnp_show_options(struct device *dmdev, 207static ssize_t pnp_show_options(struct device *dmdev,
216 struct device_attribute *attr, char *buf) 208 struct device_attribute *attr, char *buf)
217{ 209{
218 struct pnp_dev *dev = to_pnp_dev(dmdev); 210 struct pnp_dev *dev = to_pnp_dev(dmdev);
219 struct pnp_option *independent = dev->independent; 211 pnp_info_buffer_t *buffer;
220 struct pnp_option *dependent = dev->dependent; 212 struct pnp_option *option;
221 int ret, dep = 1; 213 int ret, dep = 0, set = 0;
214 char *indent;
222 215
223 pnp_info_buffer_t *buffer = (pnp_info_buffer_t *) 216 buffer = pnp_alloc(sizeof(pnp_info_buffer_t));
224 pnp_alloc(sizeof(pnp_info_buffer_t));
225 if (!buffer) 217 if (!buffer)
226 return -ENOMEM; 218 return -ENOMEM;
227 219
228 buffer->len = PAGE_SIZE; 220 buffer->len = PAGE_SIZE;
229 buffer->buffer = buf; 221 buffer->buffer = buf;
230 buffer->curr = buffer->buffer; 222 buffer->curr = buffer->buffer;
231 if (independent)
232 pnp_print_option(buffer, "", independent, 0);
233 223
234 while (dependent) { 224 list_for_each_entry(option, &dev->options, list) {
235 pnp_print_option(buffer, " ", dependent, dep); 225 if (pnp_option_is_dependent(option)) {
236 dependent = dependent->next; 226 indent = " ";
237 dep++; 227 if (!dep || pnp_option_set(option) != set) {
228 set = pnp_option_set(option);
229 dep = 1;
230 pnp_printf(buffer, "Dependent: %02i - "
231 "Priority %s\n", set,
232 pnp_option_priority_name(option));
233 }
234 } else {
235 dep = 0;
236 indent = "";
237 }
238 pnp_print_option(buffer, indent, option);
238 } 239 }
240
239 ret = (buffer->curr - buf); 241 ret = (buffer->curr - buf);
240 kfree(buffer); 242 kfree(buffer);
241 return ret; 243 return ret;
@@ -248,79 +250,59 @@ static ssize_t pnp_show_current_resources(struct device *dmdev,
248 char *buf) 250 char *buf)
249{ 251{
250 struct pnp_dev *dev = to_pnp_dev(dmdev); 252 struct pnp_dev *dev = to_pnp_dev(dmdev);
251 struct resource *res;
252 int i, ret;
253 pnp_info_buffer_t *buffer; 253 pnp_info_buffer_t *buffer;
254 struct pnp_resource *pnp_res;
255 struct resource *res;
256 int ret;
254 257
255 if (!dev) 258 if (!dev)
256 return -EINVAL; 259 return -EINVAL;
257 260
258 buffer = (pnp_info_buffer_t *) pnp_alloc(sizeof(pnp_info_buffer_t)); 261 buffer = pnp_alloc(sizeof(pnp_info_buffer_t));
259 if (!buffer) 262 if (!buffer)
260 return -ENOMEM; 263 return -ENOMEM;
264
261 buffer->len = PAGE_SIZE; 265 buffer->len = PAGE_SIZE;
262 buffer->buffer = buf; 266 buffer->buffer = buf;
263 buffer->curr = buffer->buffer; 267 buffer->curr = buffer->buffer;
264 268
265 pnp_printf(buffer, "state = "); 269 pnp_printf(buffer, "state = %s\n", dev->active ? "active" : "disabled");
266 if (dev->active) 270
267 pnp_printf(buffer, "active\n"); 271 list_for_each_entry(pnp_res, &dev->resources, list) {
268 else 272 res = &pnp_res->res;
269 pnp_printf(buffer, "disabled\n"); 273
270 274 pnp_printf(buffer, pnp_resource_type_name(res));
271 for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_IO, i)); i++) { 275
272 if (pnp_resource_valid(res)) { 276 if (res->flags & IORESOURCE_DISABLED) {
273 pnp_printf(buffer, "io"); 277 pnp_printf(buffer, " disabled\n");
274 if (res->flags & IORESOURCE_DISABLED) 278 continue;
275 pnp_printf(buffer, " disabled\n");
276 else
277 pnp_printf(buffer, " 0x%llx-0x%llx\n",
278 (unsigned long long) res->start,
279 (unsigned long long) res->end);
280 }
281 }
282 for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_MEM, i)); i++) {
283 if (pnp_resource_valid(res)) {
284 pnp_printf(buffer, "mem");
285 if (res->flags & IORESOURCE_DISABLED)
286 pnp_printf(buffer, " disabled\n");
287 else
288 pnp_printf(buffer, " 0x%llx-0x%llx\n",
289 (unsigned long long) res->start,
290 (unsigned long long) res->end);
291 }
292 }
293 for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_IRQ, i)); i++) {
294 if (pnp_resource_valid(res)) {
295 pnp_printf(buffer, "irq");
296 if (res->flags & IORESOURCE_DISABLED)
297 pnp_printf(buffer, " disabled\n");
298 else
299 pnp_printf(buffer, " %lld\n",
300 (unsigned long long) res->start);
301 } 279 }
302 } 280
303 for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_DMA, i)); i++) { 281 switch (pnp_resource_type(res)) {
304 if (pnp_resource_valid(res)) { 282 case IORESOURCE_IO:
305 pnp_printf(buffer, "dma"); 283 case IORESOURCE_MEM:
306 if (res->flags & IORESOURCE_DISABLED) 284 pnp_printf(buffer, " %#llx-%#llx\n",
307 pnp_printf(buffer, " disabled\n"); 285 (unsigned long long) res->start,
308 else 286 (unsigned long long) res->end);
309 pnp_printf(buffer, " %lld\n", 287 break;
310 (unsigned long long) res->start); 288 case IORESOURCE_IRQ:
289 case IORESOURCE_DMA:
290 pnp_printf(buffer, " %lld\n",
291 (unsigned long long) res->start);
292 break;
311 } 293 }
312 } 294 }
295
313 ret = (buffer->curr - buf); 296 ret = (buffer->curr - buf);
314 kfree(buffer); 297 kfree(buffer);
315 return ret; 298 return ret;
316} 299}
317 300
318static ssize_t 301static ssize_t pnp_set_current_resources(struct device *dmdev,
319pnp_set_current_resources(struct device *dmdev, struct device_attribute *attr, 302 struct device_attribute *attr,
320 const char *ubuf, size_t count) 303 const char *ubuf, size_t count)
321{ 304{
322 struct pnp_dev *dev = to_pnp_dev(dmdev); 305 struct pnp_dev *dev = to_pnp_dev(dmdev);
323 struct pnp_resource *pnp_res;
324 char *buf = (void *)ubuf; 306 char *buf = (void *)ubuf;
325 int retval = 0; 307 int retval = 0;
326 resource_size_t start, end; 308 resource_size_t start, end;
@@ -368,7 +350,6 @@ pnp_set_current_resources(struct device *dmdev, struct device_attribute *attr,
368 goto done; 350 goto done;
369 } 351 }
370 if (!strnicmp(buf, "set", 3)) { 352 if (!strnicmp(buf, "set", 3)) {
371 int nport = 0, nmem = 0, nirq = 0, ndma = 0;
372 if (dev->active) 353 if (dev->active)
373 goto done; 354 goto done;
374 buf += 3; 355 buf += 3;
@@ -391,10 +372,7 @@ pnp_set_current_resources(struct device *dmdev, struct device_attribute *attr,
391 end = simple_strtoul(buf, &buf, 0); 372 end = simple_strtoul(buf, &buf, 0);
392 } else 373 } else
393 end = start; 374 end = start;
394 pnp_res = pnp_add_io_resource(dev, start, end, 375 pnp_add_io_resource(dev, start, end, 0);
395 0);
396 if (pnp_res)
397 pnp_res->index = nport++;
398 continue; 376 continue;
399 } 377 }
400 if (!strnicmp(buf, "mem", 3)) { 378 if (!strnicmp(buf, "mem", 3)) {
@@ -411,10 +389,7 @@ pnp_set_current_resources(struct device *dmdev, struct device_attribute *attr,
411 end = simple_strtoul(buf, &buf, 0); 389 end = simple_strtoul(buf, &buf, 0);
412 } else 390 } else
413 end = start; 391 end = start;
414 pnp_res = pnp_add_mem_resource(dev, start, end, 392 pnp_add_mem_resource(dev, start, end, 0);
415 0);
416 if (pnp_res)
417 pnp_res->index = nmem++;
418 continue; 393 continue;
419 } 394 }
420 if (!strnicmp(buf, "irq", 3)) { 395 if (!strnicmp(buf, "irq", 3)) {
@@ -422,9 +397,7 @@ pnp_set_current_resources(struct device *dmdev, struct device_attribute *attr,
422 while (isspace(*buf)) 397 while (isspace(*buf))
423 ++buf; 398 ++buf;
424 start = simple_strtoul(buf, &buf, 0); 399 start = simple_strtoul(buf, &buf, 0);
425 pnp_res = pnp_add_irq_resource(dev, start, 0); 400 pnp_add_irq_resource(dev, start, 0);
426 if (pnp_res)
427 pnp_res->index = nirq++;
428 continue; 401 continue;
429 } 402 }
430 if (!strnicmp(buf, "dma", 3)) { 403 if (!strnicmp(buf, "dma", 3)) {
@@ -432,9 +405,7 @@ pnp_set_current_resources(struct device *dmdev, struct device_attribute *attr,
432 while (isspace(*buf)) 405 while (isspace(*buf))
433 ++buf; 406 ++buf;
434 start = simple_strtoul(buf, &buf, 0); 407 start = simple_strtoul(buf, &buf, 0);
435 pnp_res = pnp_add_dma_resource(dev, start, 0); 408 pnp_add_dma_resource(dev, start, 0);
436 if (pnp_res)
437 pnp_res->index = ndma++;
438 continue; 409 continue;
439 } 410 }
440 break; 411 break;
diff --git a/drivers/pnp/isapnp/core.c b/drivers/pnp/isapnp/core.c
index f1bccdbdeb08..101a835e8759 100644
--- a/drivers/pnp/isapnp/core.c
+++ b/drivers/pnp/isapnp/core.c
@@ -429,154 +429,135 @@ static struct pnp_dev *__init isapnp_parse_device(struct pnp_card *card,
429 * Add IRQ resource to resources list. 429 * Add IRQ resource to resources list.
430 */ 430 */
431static void __init isapnp_parse_irq_resource(struct pnp_dev *dev, 431static void __init isapnp_parse_irq_resource(struct pnp_dev *dev,
432 struct pnp_option *option, 432 unsigned int option_flags,
433 int size) 433 int size)
434{ 434{
435 unsigned char tmp[3]; 435 unsigned char tmp[3];
436 struct pnp_irq *irq;
437 unsigned long bits; 436 unsigned long bits;
437 pnp_irq_mask_t map;
438 unsigned char flags = IORESOURCE_IRQ_HIGHEDGE;
438 439
439 isapnp_peek(tmp, size); 440 isapnp_peek(tmp, size);
440 irq = kzalloc(sizeof(struct pnp_irq), GFP_KERNEL);
441 if (!irq)
442 return;
443 bits = (tmp[1] << 8) | tmp[0]; 441 bits = (tmp[1] << 8) | tmp[0];
444 bitmap_copy(irq->map, &bits, 16); 442
443 bitmap_zero(map.bits, PNP_IRQ_NR);
444 bitmap_copy(map.bits, &bits, 16);
445
445 if (size > 2) 446 if (size > 2)
446 irq->flags = tmp[2]; 447 flags = tmp[2];
447 else 448
448 irq->flags = IORESOURCE_IRQ_HIGHEDGE; 449 pnp_register_irq_resource(dev, option_flags, &map, flags);
449 pnp_register_irq_resource(dev, option, irq);
450} 450}
451 451
452/* 452/*
453 * Add DMA resource to resources list. 453 * Add DMA resource to resources list.
454 */ 454 */
455static void __init isapnp_parse_dma_resource(struct pnp_dev *dev, 455static void __init isapnp_parse_dma_resource(struct pnp_dev *dev,
456 struct pnp_option *option, 456 unsigned int option_flags,
457 int size) 457 int size)
458{ 458{
459 unsigned char tmp[2]; 459 unsigned char tmp[2];
460 struct pnp_dma *dma;
461 460
462 isapnp_peek(tmp, size); 461 isapnp_peek(tmp, size);
463 dma = kzalloc(sizeof(struct pnp_dma), GFP_KERNEL); 462 pnp_register_dma_resource(dev, option_flags, tmp[0], tmp[1]);
464 if (!dma)
465 return;
466 dma->map = tmp[0];
467 dma->flags = tmp[1];
468 pnp_register_dma_resource(dev, option, dma);
469} 463}
470 464
471/* 465/*
472 * Add port resource to resources list. 466 * Add port resource to resources list.
473 */ 467 */
474static void __init isapnp_parse_port_resource(struct pnp_dev *dev, 468static void __init isapnp_parse_port_resource(struct pnp_dev *dev,
475 struct pnp_option *option, 469 unsigned int option_flags,
476 int size) 470 int size)
477{ 471{
478 unsigned char tmp[7]; 472 unsigned char tmp[7];
479 struct pnp_port *port; 473 resource_size_t min, max, align, len;
474 unsigned char flags;
480 475
481 isapnp_peek(tmp, size); 476 isapnp_peek(tmp, size);
482 port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL); 477 min = (tmp[2] << 8) | tmp[1];
483 if (!port) 478 max = (tmp[4] << 8) | tmp[3];
484 return; 479 align = tmp[5];
485 port->min = (tmp[2] << 8) | tmp[1]; 480 len = tmp[6];
486 port->max = (tmp[4] << 8) | tmp[3]; 481 flags = tmp[0] ? IORESOURCE_IO_16BIT_ADDR : 0;
487 port->align = tmp[5]; 482 pnp_register_port_resource(dev, option_flags,
488 port->size = tmp[6]; 483 min, max, align, len, flags);
489 port->flags = tmp[0] ? PNP_PORT_FLAG_16BITADDR : 0;
490 pnp_register_port_resource(dev, option, port);
491} 484}
492 485
493/* 486/*
494 * Add fixed port resource to resources list. 487 * Add fixed port resource to resources list.
495 */ 488 */
496static void __init isapnp_parse_fixed_port_resource(struct pnp_dev *dev, 489static void __init isapnp_parse_fixed_port_resource(struct pnp_dev *dev,
497 struct pnp_option *option, 490 unsigned int option_flags,
498 int size) 491 int size)
499{ 492{
500 unsigned char tmp[3]; 493 unsigned char tmp[3];
501 struct pnp_port *port; 494 resource_size_t base, len;
502 495
503 isapnp_peek(tmp, size); 496 isapnp_peek(tmp, size);
504 port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL); 497 base = (tmp[1] << 8) | tmp[0];
505 if (!port) 498 len = tmp[2];
506 return; 499 pnp_register_port_resource(dev, option_flags, base, base, 0, len,
507 port->min = port->max = (tmp[1] << 8) | tmp[0]; 500 IORESOURCE_IO_FIXED);
508 port->size = tmp[2];
509 port->align = 0;
510 port->flags = PNP_PORT_FLAG_FIXED;
511 pnp_register_port_resource(dev, option, port);
512} 501}
513 502
514/* 503/*
515 * Add memory resource to resources list. 504 * Add memory resource to resources list.
516 */ 505 */
517static void __init isapnp_parse_mem_resource(struct pnp_dev *dev, 506static void __init isapnp_parse_mem_resource(struct pnp_dev *dev,
518 struct pnp_option *option, 507 unsigned int option_flags,
519 int size) 508 int size)
520{ 509{
521 unsigned char tmp[9]; 510 unsigned char tmp[9];
522 struct pnp_mem *mem; 511 resource_size_t min, max, align, len;
512 unsigned char flags;
523 513
524 isapnp_peek(tmp, size); 514 isapnp_peek(tmp, size);
525 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL); 515 min = ((tmp[2] << 8) | tmp[1]) << 8;
526 if (!mem) 516 max = ((tmp[4] << 8) | tmp[3]) << 8;
527 return; 517 align = (tmp[6] << 8) | tmp[5];
528 mem->min = ((tmp[2] << 8) | tmp[1]) << 8; 518 len = ((tmp[8] << 8) | tmp[7]) << 8;
529 mem->max = ((tmp[4] << 8) | tmp[3]) << 8; 519 flags = tmp[0];
530 mem->align = (tmp[6] << 8) | tmp[5]; 520 pnp_register_mem_resource(dev, option_flags,
531 mem->size = ((tmp[8] << 8) | tmp[7]) << 8; 521 min, max, align, len, flags);
532 mem->flags = tmp[0];
533 pnp_register_mem_resource(dev, option, mem);
534} 522}
535 523
536/* 524/*
537 * Add 32-bit memory resource to resources list. 525 * Add 32-bit memory resource to resources list.
538 */ 526 */
539static void __init isapnp_parse_mem32_resource(struct pnp_dev *dev, 527static void __init isapnp_parse_mem32_resource(struct pnp_dev *dev,
540 struct pnp_option *option, 528 unsigned int option_flags,
541 int size) 529 int size)
542{ 530{
543 unsigned char tmp[17]; 531 unsigned char tmp[17];
544 struct pnp_mem *mem; 532 resource_size_t min, max, align, len;
533 unsigned char flags;
545 534
546 isapnp_peek(tmp, size); 535 isapnp_peek(tmp, size);
547 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL); 536 min = (tmp[4] << 24) | (tmp[3] << 16) | (tmp[2] << 8) | tmp[1];
548 if (!mem) 537 max = (tmp[8] << 24) | (tmp[7] << 16) | (tmp[6] << 8) | tmp[5];
549 return; 538 align = (tmp[12] << 24) | (tmp[11] << 16) | (tmp[10] << 8) | tmp[9];
550 mem->min = (tmp[4] << 24) | (tmp[3] << 16) | (tmp[2] << 8) | tmp[1]; 539 len = (tmp[16] << 24) | (tmp[15] << 16) | (tmp[14] << 8) | tmp[13];
551 mem->max = (tmp[8] << 24) | (tmp[7] << 16) | (tmp[6] << 8) | tmp[5]; 540 flags = tmp[0];
552 mem->align = 541 pnp_register_mem_resource(dev, option_flags,
553 (tmp[12] << 24) | (tmp[11] << 16) | (tmp[10] << 8) | tmp[9]; 542 min, max, align, len, flags);
554 mem->size =
555 (tmp[16] << 24) | (tmp[15] << 16) | (tmp[14] << 8) | tmp[13];
556 mem->flags = tmp[0];
557 pnp_register_mem_resource(dev, option, mem);
558} 543}
559 544
560/* 545/*
561 * Add 32-bit fixed memory resource to resources list. 546 * Add 32-bit fixed memory resource to resources list.
562 */ 547 */
563static void __init isapnp_parse_fixed_mem32_resource(struct pnp_dev *dev, 548static void __init isapnp_parse_fixed_mem32_resource(struct pnp_dev *dev,
564 struct pnp_option *option, 549 unsigned int option_flags,
565 int size) 550 int size)
566{ 551{
567 unsigned char tmp[9]; 552 unsigned char tmp[9];
568 struct pnp_mem *mem; 553 resource_size_t base, len;
554 unsigned char flags;
569 555
570 isapnp_peek(tmp, size); 556 isapnp_peek(tmp, size);
571 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL); 557 base = (tmp[4] << 24) | (tmp[3] << 16) | (tmp[2] << 8) | tmp[1];
572 if (!mem) 558 len = (tmp[8] << 24) | (tmp[7] << 16) | (tmp[6] << 8) | tmp[5];
573 return; 559 flags = tmp[0];
574 mem->min = mem->max = 560 pnp_register_mem_resource(dev, option_flags, base, base, 0, len, flags);
575 (tmp[4] << 24) | (tmp[3] << 16) | (tmp[2] << 8) | tmp[1];
576 mem->size = (tmp[8] << 24) | (tmp[7] << 16) | (tmp[6] << 8) | tmp[5];
577 mem->align = 0;
578 mem->flags = tmp[0];
579 pnp_register_mem_resource(dev, option, mem);
580} 561}
581 562
582/* 563/*
@@ -604,20 +585,16 @@ isapnp_parse_name(char *name, unsigned int name_max, unsigned short *size)
604static int __init isapnp_create_device(struct pnp_card *card, 585static int __init isapnp_create_device(struct pnp_card *card,
605 unsigned short size) 586 unsigned short size)
606{ 587{
607 int number = 0, skip = 0, priority = 0, compat = 0; 588 int number = 0, skip = 0, priority, compat = 0;
608 unsigned char type, tmp[17]; 589 unsigned char type, tmp[17];
609 struct pnp_option *option; 590 unsigned int option_flags;
610 struct pnp_dev *dev; 591 struct pnp_dev *dev;
611 u32 eisa_id; 592 u32 eisa_id;
612 char id[8]; 593 char id[8];
613 594
614 if ((dev = isapnp_parse_device(card, size, number++)) == NULL) 595 if ((dev = isapnp_parse_device(card, size, number++)) == NULL)
615 return 1; 596 return 1;
616 option = pnp_register_independent_option(dev); 597 option_flags = 0;
617 if (!option) {
618 kfree(dev);
619 return 1;
620 }
621 pnp_add_card_device(card, dev); 598 pnp_add_card_device(card, dev);
622 599
623 while (1) { 600 while (1) {
@@ -634,16 +611,11 @@ static int __init isapnp_create_device(struct pnp_card *card,
634 return 1; 611 return 1;
635 size = 0; 612 size = 0;
636 skip = 0; 613 skip = 0;
637 option = pnp_register_independent_option(dev); 614 option_flags = 0;
638 if (!option) {
639 kfree(dev);
640 return 1;
641 }
642 pnp_add_card_device(card, dev); 615 pnp_add_card_device(card, dev);
643 } else { 616 } else {
644 skip = 1; 617 skip = 1;
645 } 618 }
646 priority = 0;
647 compat = 0; 619 compat = 0;
648 break; 620 break;
649 case _STAG_COMPATDEVID: 621 case _STAG_COMPATDEVID:
@@ -660,44 +632,42 @@ static int __init isapnp_create_device(struct pnp_card *card,
660 case _STAG_IRQ: 632 case _STAG_IRQ:
661 if (size < 2 || size > 3) 633 if (size < 2 || size > 3)
662 goto __skip; 634 goto __skip;
663 isapnp_parse_irq_resource(dev, option, size); 635 isapnp_parse_irq_resource(dev, option_flags, size);
664 size = 0; 636 size = 0;
665 break; 637 break;
666 case _STAG_DMA: 638 case _STAG_DMA:
667 if (size != 2) 639 if (size != 2)
668 goto __skip; 640 goto __skip;
669 isapnp_parse_dma_resource(dev, option, size); 641 isapnp_parse_dma_resource(dev, option_flags, size);
670 size = 0; 642 size = 0;
671 break; 643 break;
672 case _STAG_STARTDEP: 644 case _STAG_STARTDEP:
673 if (size > 1) 645 if (size > 1)
674 goto __skip; 646 goto __skip;
675 priority = 0x100 | PNP_RES_PRIORITY_ACCEPTABLE; 647 priority = PNP_RES_PRIORITY_ACCEPTABLE;
676 if (size > 0) { 648 if (size > 0) {
677 isapnp_peek(tmp, size); 649 isapnp_peek(tmp, size);
678 priority = 0x100 | tmp[0]; 650 priority = tmp[0];
679 size = 0; 651 size = 0;
680 } 652 }
681 option = pnp_register_dependent_option(dev, priority); 653 option_flags = pnp_new_dependent_set(dev, priority);
682 if (!option)
683 return 1;
684 break; 654 break;
685 case _STAG_ENDDEP: 655 case _STAG_ENDDEP:
686 if (size != 0) 656 if (size != 0)
687 goto __skip; 657 goto __skip;
688 priority = 0; 658 option_flags = 0;
689 dev_dbg(&dev->dev, "end dependent options\n");
690 break; 659 break;
691 case _STAG_IOPORT: 660 case _STAG_IOPORT:
692 if (size != 7) 661 if (size != 7)
693 goto __skip; 662 goto __skip;
694 isapnp_parse_port_resource(dev, option, size); 663 isapnp_parse_port_resource(dev, option_flags, size);
695 size = 0; 664 size = 0;
696 break; 665 break;
697 case _STAG_FIXEDIO: 666 case _STAG_FIXEDIO:
698 if (size != 3) 667 if (size != 3)
699 goto __skip; 668 goto __skip;
700 isapnp_parse_fixed_port_resource(dev, option, size); 669 isapnp_parse_fixed_port_resource(dev, option_flags,
670 size);
701 size = 0; 671 size = 0;
702 break; 672 break;
703 case _STAG_VENDOR: 673 case _STAG_VENDOR:
@@ -705,7 +675,7 @@ static int __init isapnp_create_device(struct pnp_card *card,
705 case _LTAG_MEMRANGE: 675 case _LTAG_MEMRANGE:
706 if (size != 9) 676 if (size != 9)
707 goto __skip; 677 goto __skip;
708 isapnp_parse_mem_resource(dev, option, size); 678 isapnp_parse_mem_resource(dev, option_flags, size);
709 size = 0; 679 size = 0;
710 break; 680 break;
711 case _LTAG_ANSISTR: 681 case _LTAG_ANSISTR:
@@ -720,13 +690,14 @@ static int __init isapnp_create_device(struct pnp_card *card,
720 case _LTAG_MEM32RANGE: 690 case _LTAG_MEM32RANGE:
721 if (size != 17) 691 if (size != 17)
722 goto __skip; 692 goto __skip;
723 isapnp_parse_mem32_resource(dev, option, size); 693 isapnp_parse_mem32_resource(dev, option_flags, size);
724 size = 0; 694 size = 0;
725 break; 695 break;
726 case _LTAG_FIXEDMEM32RANGE: 696 case _LTAG_FIXEDMEM32RANGE:
727 if (size != 9) 697 if (size != 9)
728 goto __skip; 698 goto __skip;
729 isapnp_parse_fixed_mem32_resource(dev, option, size); 699 isapnp_parse_fixed_mem32_resource(dev, option_flags,
700 size);
730 size = 0; 701 size = 0;
731 break; 702 break;
732 case _STAG_END: 703 case _STAG_END:
@@ -928,7 +899,6 @@ EXPORT_SYMBOL(isapnp_write_byte);
928 899
929static int isapnp_get_resources(struct pnp_dev *dev) 900static int isapnp_get_resources(struct pnp_dev *dev)
930{ 901{
931 struct pnp_resource *pnp_res;
932 int i, ret; 902 int i, ret;
933 903
934 dev_dbg(&dev->dev, "get resources\n"); 904 dev_dbg(&dev->dev, "get resources\n");
@@ -940,35 +910,23 @@ static int isapnp_get_resources(struct pnp_dev *dev)
940 910
941 for (i = 0; i < ISAPNP_MAX_PORT; i++) { 911 for (i = 0; i < ISAPNP_MAX_PORT; i++) {
942 ret = isapnp_read_word(ISAPNP_CFG_PORT + (i << 1)); 912 ret = isapnp_read_word(ISAPNP_CFG_PORT + (i << 1));
943 if (ret) { 913 pnp_add_io_resource(dev, ret, ret,
944 pnp_res = pnp_add_io_resource(dev, ret, ret, 0); 914 ret == 0 ? IORESOURCE_DISABLED : 0);
945 if (pnp_res)
946 pnp_res->index = i;
947 }
948 } 915 }
949 for (i = 0; i < ISAPNP_MAX_MEM; i++) { 916 for (i = 0; i < ISAPNP_MAX_MEM; i++) {
950 ret = isapnp_read_word(ISAPNP_CFG_MEM + (i << 3)) << 8; 917 ret = isapnp_read_word(ISAPNP_CFG_MEM + (i << 3)) << 8;
951 if (ret) { 918 pnp_add_mem_resource(dev, ret, ret,
952 pnp_res = pnp_add_mem_resource(dev, ret, ret, 0); 919 ret == 0 ? IORESOURCE_DISABLED : 0);
953 if (pnp_res)
954 pnp_res->index = i;
955 }
956 } 920 }
957 for (i = 0; i < ISAPNP_MAX_IRQ; i++) { 921 for (i = 0; i < ISAPNP_MAX_IRQ; i++) {
958 ret = isapnp_read_word(ISAPNP_CFG_IRQ + (i << 1)) >> 8; 922 ret = isapnp_read_word(ISAPNP_CFG_IRQ + (i << 1)) >> 8;
959 if (ret) { 923 pnp_add_irq_resource(dev, ret,
960 pnp_res = pnp_add_irq_resource(dev, ret, 0); 924 ret == 0 ? IORESOURCE_DISABLED : 0);
961 if (pnp_res)
962 pnp_res->index = i;
963 }
964 } 925 }
965 for (i = 0; i < ISAPNP_MAX_DMA; i++) { 926 for (i = 0; i < ISAPNP_MAX_DMA; i++) {
966 ret = isapnp_read_byte(ISAPNP_CFG_DMA + i); 927 ret = isapnp_read_byte(ISAPNP_CFG_DMA + i);
967 if (ret != 4) { 928 pnp_add_dma_resource(dev, ret,
968 pnp_res = pnp_add_dma_resource(dev, ret, 0); 929 ret == 4 ? IORESOURCE_DISABLED : 0);
969 if (pnp_res)
970 pnp_res->index = i;
971 }
972 } 930 }
973 931
974__end: 932__end:
@@ -978,62 +936,45 @@ __end:
978 936
979static int isapnp_set_resources(struct pnp_dev *dev) 937static int isapnp_set_resources(struct pnp_dev *dev)
980{ 938{
981 struct pnp_resource *pnp_res;
982 struct resource *res; 939 struct resource *res;
983 int tmp, index; 940 int tmp;
984 941
985 dev_dbg(&dev->dev, "set resources\n"); 942 dev_dbg(&dev->dev, "set resources\n");
986 isapnp_cfg_begin(dev->card->number, dev->number); 943 isapnp_cfg_begin(dev->card->number, dev->number);
987 dev->active = 1; 944 dev->active = 1;
988 for (tmp = 0; tmp < ISAPNP_MAX_PORT; tmp++) { 945 for (tmp = 0; tmp < ISAPNP_MAX_PORT; tmp++) {
989 pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_IO, tmp); 946 res = pnp_get_resource(dev, IORESOURCE_IO, tmp);
990 if (!pnp_res) 947 if (pnp_resource_enabled(res)) {
991 continue;
992 res = &pnp_res->res;
993 if (pnp_resource_valid(res)) {
994 index = pnp_res->index;
995 dev_dbg(&dev->dev, " set io %d to %#llx\n", 948 dev_dbg(&dev->dev, " set io %d to %#llx\n",
996 index, (unsigned long long) res->start); 949 tmp, (unsigned long long) res->start);
997 isapnp_write_word(ISAPNP_CFG_PORT + (index << 1), 950 isapnp_write_word(ISAPNP_CFG_PORT + (tmp << 1),
998 res->start); 951 res->start);
999 } 952 }
1000 } 953 }
1001 for (tmp = 0; tmp < ISAPNP_MAX_IRQ; tmp++) { 954 for (tmp = 0; tmp < ISAPNP_MAX_IRQ; tmp++) {
1002 pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_IRQ, tmp); 955 res = pnp_get_resource(dev, IORESOURCE_IRQ, tmp);
1003 if (!pnp_res) 956 if (pnp_resource_enabled(res)) {
1004 continue;
1005 res = &pnp_res->res;
1006 if (pnp_resource_valid(res)) {
1007 int irq = res->start; 957 int irq = res->start;
1008 if (irq == 2) 958 if (irq == 2)
1009 irq = 9; 959 irq = 9;
1010 index = pnp_res->index; 960 dev_dbg(&dev->dev, " set irq %d to %d\n", tmp, irq);
1011 dev_dbg(&dev->dev, " set irq %d to %d\n", index, irq); 961 isapnp_write_byte(ISAPNP_CFG_IRQ + (tmp << 1), irq);
1012 isapnp_write_byte(ISAPNP_CFG_IRQ + (index << 1), irq);
1013 } 962 }
1014 } 963 }
1015 for (tmp = 0; tmp < ISAPNP_MAX_DMA; tmp++) { 964 for (tmp = 0; tmp < ISAPNP_MAX_DMA; tmp++) {
1016 pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_DMA, tmp); 965 res = pnp_get_resource(dev, IORESOURCE_DMA, tmp);
1017 if (!pnp_res) 966 if (pnp_resource_enabled(res)) {
1018 continue;
1019 res = &pnp_res->res;
1020 if (pnp_resource_valid(res)) {
1021 index = pnp_res->index;
1022 dev_dbg(&dev->dev, " set dma %d to %lld\n", 967 dev_dbg(&dev->dev, " set dma %d to %lld\n",
1023 index, (unsigned long long) res->start); 968 tmp, (unsigned long long) res->start);
1024 isapnp_write_byte(ISAPNP_CFG_DMA + index, res->start); 969 isapnp_write_byte(ISAPNP_CFG_DMA + tmp, res->start);
1025 } 970 }
1026 } 971 }
1027 for (tmp = 0; tmp < ISAPNP_MAX_MEM; tmp++) { 972 for (tmp = 0; tmp < ISAPNP_MAX_MEM; tmp++) {
1028 pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_MEM, tmp); 973 res = pnp_get_resource(dev, IORESOURCE_MEM, tmp);
1029 if (!pnp_res) 974 if (pnp_resource_enabled(res)) {
1030 continue;
1031 res = &pnp_res->res;
1032 if (pnp_resource_valid(res)) {
1033 index = pnp_res->index;
1034 dev_dbg(&dev->dev, " set mem %d to %#llx\n", 975 dev_dbg(&dev->dev, " set mem %d to %#llx\n",
1035 index, (unsigned long long) res->start); 976 tmp, (unsigned long long) res->start);
1036 isapnp_write_word(ISAPNP_CFG_MEM + (index << 3), 977 isapnp_write_word(ISAPNP_CFG_MEM + (tmp << 3),
1037 (res->start >> 8) & 0xffff); 978 (res->start >> 8) & 0xffff);
1038 } 979 }
1039 } 980 }
diff --git a/drivers/pnp/manager.c b/drivers/pnp/manager.c
index bea0914ff947..b526eaad3f6c 100644
--- a/drivers/pnp/manager.c
+++ b/drivers/pnp/manager.c
@@ -3,6 +3,8 @@
3 * 3 *
4 * based on isapnp.c resource management (c) Jaroslav Kysela <perex@perex.cz> 4 * based on isapnp.c resource management (c) Jaroslav Kysela <perex@perex.cz>
5 * Copyright 2003 Adam Belay <ambx1@neo.rr.com> 5 * Copyright 2003 Adam Belay <ambx1@neo.rr.com>
6 * Copyright (C) 2008 Hewlett-Packard Development Company, L.P.
7 * Bjorn Helgaas <bjorn.helgaas@hp.com>
6 */ 8 */
7 9
8#include <linux/errno.h> 10#include <linux/errno.h>
@@ -19,82 +21,64 @@ DEFINE_MUTEX(pnp_res_mutex);
19 21
20static int pnp_assign_port(struct pnp_dev *dev, struct pnp_port *rule, int idx) 22static int pnp_assign_port(struct pnp_dev *dev, struct pnp_port *rule, int idx)
21{ 23{
22 struct pnp_resource *pnp_res; 24 struct resource *res, local_res;
23 struct resource *res;
24
25 pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_IO, idx);
26 if (!pnp_res) {
27 dev_err(&dev->dev, "too many I/O port resources\n");
28 /* pretend we were successful so at least the manager won't try again */
29 return 1;
30 }
31
32 res = &pnp_res->res;
33 25
34 /* check if this resource has been manually set, if so skip */ 26 res = pnp_get_resource(dev, IORESOURCE_IO, idx);
35 if (!(res->flags & IORESOURCE_AUTO)) { 27 if (res) {
36 dev_dbg(&dev->dev, " io %d already set to %#llx-%#llx " 28 dev_dbg(&dev->dev, " io %d already set to %#llx-%#llx "
37 "flags %#lx\n", idx, (unsigned long long) res->start, 29 "flags %#lx\n", idx, (unsigned long long) res->start,
38 (unsigned long long) res->end, res->flags); 30 (unsigned long long) res->end, res->flags);
39 return 1; 31 return 0;
40 } 32 }
41 33
42 /* set the initial values */ 34 res = &local_res;
43 pnp_res->index = idx; 35 res->flags = rule->flags | IORESOURCE_AUTO;
44 res->flags |= rule->flags | IORESOURCE_IO; 36 res->start = 0;
45 res->flags &= ~IORESOURCE_UNSET; 37 res->end = 0;
46 38
47 if (!rule->size) { 39 if (!rule->size) {
48 res->flags |= IORESOURCE_DISABLED; 40 res->flags |= IORESOURCE_DISABLED;
49 dev_dbg(&dev->dev, " io %d disabled\n", idx); 41 dev_dbg(&dev->dev, " io %d disabled\n", idx);
50 return 1; /* skip disabled resource requests */ 42 goto __add;
51 } 43 }
52 44
53 res->start = rule->min; 45 res->start = rule->min;
54 res->end = res->start + rule->size - 1; 46 res->end = res->start + rule->size - 1;
55 47
56 /* run through until pnp_check_port is happy */
57 while (!pnp_check_port(dev, res)) { 48 while (!pnp_check_port(dev, res)) {
58 res->start += rule->align; 49 res->start += rule->align;
59 res->end = res->start + rule->size - 1; 50 res->end = res->start + rule->size - 1;
60 if (res->start > rule->max || !rule->align) { 51 if (res->start > rule->max || !rule->align) {
61 dev_dbg(&dev->dev, " couldn't assign io %d\n", idx); 52 dev_dbg(&dev->dev, " couldn't assign io %d "
62 return 0; 53 "(min %#llx max %#llx)\n", idx,
54 (unsigned long long) rule->min,
55 (unsigned long long) rule->max);
56 return -EBUSY;
63 } 57 }
64 } 58 }
65 dev_dbg(&dev->dev, " assign io %d %#llx-%#llx\n", idx, 59
66 (unsigned long long) res->start, (unsigned long long) res->end); 60__add:
67 return 1; 61 pnp_add_io_resource(dev, res->start, res->end, res->flags);
62 return 0;
68} 63}
69 64
70static int pnp_assign_mem(struct pnp_dev *dev, struct pnp_mem *rule, int idx) 65static int pnp_assign_mem(struct pnp_dev *dev, struct pnp_mem *rule, int idx)
71{ 66{
72 struct pnp_resource *pnp_res; 67 struct resource *res, local_res;
73 struct resource *res;
74
75 pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_MEM, idx);
76 if (!pnp_res) {
77 dev_err(&dev->dev, "too many memory resources\n");
78 /* pretend we were successful so at least the manager won't try again */
79 return 1;
80 }
81 68
82 res = &pnp_res->res; 69 res = pnp_get_resource(dev, IORESOURCE_MEM, idx);
83 70 if (res) {
84 /* check if this resource has been manually set, if so skip */
85 if (!(res->flags & IORESOURCE_AUTO)) {
86 dev_dbg(&dev->dev, " mem %d already set to %#llx-%#llx " 71 dev_dbg(&dev->dev, " mem %d already set to %#llx-%#llx "
87 "flags %#lx\n", idx, (unsigned long long) res->start, 72 "flags %#lx\n", idx, (unsigned long long) res->start,
88 (unsigned long long) res->end, res->flags); 73 (unsigned long long) res->end, res->flags);
89 return 1; 74 return 0;
90 } 75 }
91 76
92 /* set the initial values */ 77 res = &local_res;
93 pnp_res->index = idx; 78 res->flags = rule->flags | IORESOURCE_AUTO;
94 res->flags |= rule->flags | IORESOURCE_MEM; 79 res->start = 0;
95 res->flags &= ~IORESOURCE_UNSET; 80 res->end = 0;
96 81
97 /* convert pnp flags to standard Linux flags */
98 if (!(rule->flags & IORESOURCE_MEM_WRITEABLE)) 82 if (!(rule->flags & IORESOURCE_MEM_WRITEABLE))
99 res->flags |= IORESOURCE_READONLY; 83 res->flags |= IORESOURCE_READONLY;
100 if (rule->flags & IORESOURCE_MEM_CACHEABLE) 84 if (rule->flags & IORESOURCE_MEM_CACHEABLE)
@@ -107,30 +91,32 @@ static int pnp_assign_mem(struct pnp_dev *dev, struct pnp_mem *rule, int idx)
107 if (!rule->size) { 91 if (!rule->size) {
108 res->flags |= IORESOURCE_DISABLED; 92 res->flags |= IORESOURCE_DISABLED;
109 dev_dbg(&dev->dev, " mem %d disabled\n", idx); 93 dev_dbg(&dev->dev, " mem %d disabled\n", idx);
110 return 1; /* skip disabled resource requests */ 94 goto __add;
111 } 95 }
112 96
113 res->start = rule->min; 97 res->start = rule->min;
114 res->end = res->start + rule->size - 1; 98 res->end = res->start + rule->size - 1;
115 99
116 /* run through until pnp_check_mem is happy */
117 while (!pnp_check_mem(dev, res)) { 100 while (!pnp_check_mem(dev, res)) {
118 res->start += rule->align; 101 res->start += rule->align;
119 res->end = res->start + rule->size - 1; 102 res->end = res->start + rule->size - 1;
120 if (res->start > rule->max || !rule->align) { 103 if (res->start > rule->max || !rule->align) {
121 dev_dbg(&dev->dev, " couldn't assign mem %d\n", idx); 104 dev_dbg(&dev->dev, " couldn't assign mem %d "
122 return 0; 105 "(min %#llx max %#llx)\n", idx,
106 (unsigned long long) rule->min,
107 (unsigned long long) rule->max);
108 return -EBUSY;
123 } 109 }
124 } 110 }
125 dev_dbg(&dev->dev, " assign mem %d %#llx-%#llx\n", idx, 111
126 (unsigned long long) res->start, (unsigned long long) res->end); 112__add:
127 return 1; 113 pnp_add_mem_resource(dev, res->start, res->end, res->flags);
114 return 0;
128} 115}
129 116
130static int pnp_assign_irq(struct pnp_dev *dev, struct pnp_irq *rule, int idx) 117static int pnp_assign_irq(struct pnp_dev *dev, struct pnp_irq *rule, int idx)
131{ 118{
132 struct pnp_resource *pnp_res; 119 struct resource *res, local_res;
133 struct resource *res;
134 int i; 120 int i;
135 121
136 /* IRQ priority: this table is good for i386 */ 122 /* IRQ priority: this table is good for i386 */
@@ -138,59 +124,57 @@ static int pnp_assign_irq(struct pnp_dev *dev, struct pnp_irq *rule, int idx)
138 5, 10, 11, 12, 9, 14, 15, 7, 3, 4, 13, 0, 1, 6, 8, 2 124 5, 10, 11, 12, 9, 14, 15, 7, 3, 4, 13, 0, 1, 6, 8, 2
139 }; 125 };
140 126
141 pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_IRQ, idx); 127 res = pnp_get_resource(dev, IORESOURCE_IRQ, idx);
142 if (!pnp_res) { 128 if (res) {
143 dev_err(&dev->dev, "too many IRQ resources\n");
144 /* pretend we were successful so at least the manager won't try again */
145 return 1;
146 }
147
148 res = &pnp_res->res;
149
150 /* check if this resource has been manually set, if so skip */
151 if (!(res->flags & IORESOURCE_AUTO)) {
152 dev_dbg(&dev->dev, " irq %d already set to %d flags %#lx\n", 129 dev_dbg(&dev->dev, " irq %d already set to %d flags %#lx\n",
153 idx, (int) res->start, res->flags); 130 idx, (int) res->start, res->flags);
154 return 1; 131 return 0;
155 } 132 }
156 133
157 /* set the initial values */ 134 res = &local_res;
158 pnp_res->index = idx; 135 res->flags = rule->flags | IORESOURCE_AUTO;
159 res->flags |= rule->flags | IORESOURCE_IRQ; 136 res->start = -1;
160 res->flags &= ~IORESOURCE_UNSET; 137 res->end = -1;
161 138
162 if (bitmap_empty(rule->map, PNP_IRQ_NR)) { 139 if (bitmap_empty(rule->map.bits, PNP_IRQ_NR)) {
163 res->flags |= IORESOURCE_DISABLED; 140 res->flags |= IORESOURCE_DISABLED;
164 dev_dbg(&dev->dev, " irq %d disabled\n", idx); 141 dev_dbg(&dev->dev, " irq %d disabled\n", idx);
165 return 1; /* skip disabled resource requests */ 142 goto __add;
166 } 143 }
167 144
168 /* TBD: need check for >16 IRQ */ 145 /* TBD: need check for >16 IRQ */
169 res->start = find_next_bit(rule->map, PNP_IRQ_NR, 16); 146 res->start = find_next_bit(rule->map.bits, PNP_IRQ_NR, 16);
170 if (res->start < PNP_IRQ_NR) { 147 if (res->start < PNP_IRQ_NR) {
171 res->end = res->start; 148 res->end = res->start;
172 dev_dbg(&dev->dev, " assign irq %d %d\n", idx, 149 goto __add;
173 (int) res->start);
174 return 1;
175 } 150 }
176 for (i = 0; i < 16; i++) { 151 for (i = 0; i < 16; i++) {
177 if (test_bit(xtab[i], rule->map)) { 152 if (test_bit(xtab[i], rule->map.bits)) {
178 res->start = res->end = xtab[i]; 153 res->start = res->end = xtab[i];
179 if (pnp_check_irq(dev, res)) { 154 if (pnp_check_irq(dev, res))
180 dev_dbg(&dev->dev, " assign irq %d %d\n", idx, 155 goto __add;
181 (int) res->start);
182 return 1;
183 }
184 } 156 }
185 } 157 }
158
159 if (rule->flags & IORESOURCE_IRQ_OPTIONAL) {
160 res->start = -1;
161 res->end = -1;
162 res->flags |= IORESOURCE_DISABLED;
163 dev_dbg(&dev->dev, " irq %d disabled (optional)\n", idx);
164 goto __add;
165 }
166
186 dev_dbg(&dev->dev, " couldn't assign irq %d\n", idx); 167 dev_dbg(&dev->dev, " couldn't assign irq %d\n", idx);
168 return -EBUSY;
169
170__add:
171 pnp_add_irq_resource(dev, res->start, res->flags);
187 return 0; 172 return 0;
188} 173}
189 174
190static void pnp_assign_dma(struct pnp_dev *dev, struct pnp_dma *rule, int idx) 175static int pnp_assign_dma(struct pnp_dev *dev, struct pnp_dma *rule, int idx)
191{ 176{
192 struct pnp_resource *pnp_res; 177 struct resource *res, local_res;
193 struct resource *res;
194 int i; 178 int i;
195 179
196 /* DMA priority: this table is good for i386 */ 180 /* DMA priority: this table is good for i386 */
@@ -198,231 +182,99 @@ static void pnp_assign_dma(struct pnp_dev *dev, struct pnp_dma *rule, int idx)
198 1, 3, 5, 6, 7, 0, 2, 4 182 1, 3, 5, 6, 7, 0, 2, 4
199 }; 183 };
200 184
201 pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_DMA, idx); 185 res = pnp_get_resource(dev, IORESOURCE_DMA, idx);
202 if (!pnp_res) { 186 if (res) {
203 dev_err(&dev->dev, "too many DMA resources\n");
204 return;
205 }
206
207 res = &pnp_res->res;
208
209 /* check if this resource has been manually set, if so skip */
210 if (!(res->flags & IORESOURCE_AUTO)) {
211 dev_dbg(&dev->dev, " dma %d already set to %d flags %#lx\n", 187 dev_dbg(&dev->dev, " dma %d already set to %d flags %#lx\n",
212 idx, (int) res->start, res->flags); 188 idx, (int) res->start, res->flags);
213 return; 189 return 0;
214 } 190 }
215 191
216 /* set the initial values */ 192 res = &local_res;
217 pnp_res->index = idx; 193 res->flags = rule->flags | IORESOURCE_AUTO;
218 res->flags |= rule->flags | IORESOURCE_DMA; 194 res->start = -1;
219 res->flags &= ~IORESOURCE_UNSET; 195 res->end = -1;
220 196
221 for (i = 0; i < 8; i++) { 197 for (i = 0; i < 8; i++) {
222 if (rule->map & (1 << xtab[i])) { 198 if (rule->map & (1 << xtab[i])) {
223 res->start = res->end = xtab[i]; 199 res->start = res->end = xtab[i];
224 if (pnp_check_dma(dev, res)) { 200 if (pnp_check_dma(dev, res))
225 dev_dbg(&dev->dev, " assign dma %d %d\n", idx, 201 goto __add;
226 (int) res->start);
227 return;
228 }
229 } 202 }
230 } 203 }
231#ifdef MAX_DMA_CHANNELS 204#ifdef MAX_DMA_CHANNELS
232 res->start = res->end = MAX_DMA_CHANNELS; 205 res->start = res->end = MAX_DMA_CHANNELS;
233#endif 206#endif
234 res->flags |= IORESOURCE_UNSET | IORESOURCE_DISABLED; 207 res->flags |= IORESOURCE_DISABLED;
235 dev_dbg(&dev->dev, " disable dma %d\n", idx); 208 dev_dbg(&dev->dev, " disable dma %d\n", idx);
236}
237
238void pnp_init_resource(struct resource *res)
239{
240 unsigned long type;
241
242 type = res->flags & (IORESOURCE_IO | IORESOURCE_MEM |
243 IORESOURCE_IRQ | IORESOURCE_DMA);
244 209
245 res->name = NULL; 210__add:
246 res->flags = type | IORESOURCE_AUTO | IORESOURCE_UNSET; 211 pnp_add_dma_resource(dev, res->start, res->flags);
247 if (type == IORESOURCE_IRQ || type == IORESOURCE_DMA) { 212 return 0;
248 res->start = -1;
249 res->end = -1;
250 } else {
251 res->start = 0;
252 res->end = 0;
253 }
254} 213}
255 214
256/**
257 * pnp_init_resources - Resets a resource table to default values.
258 * @table: pointer to the desired resource table
259 */
260void pnp_init_resources(struct pnp_dev *dev) 215void pnp_init_resources(struct pnp_dev *dev)
261{ 216{
262 struct resource *res; 217 pnp_free_resources(dev);
263 int idx;
264
265 for (idx = 0; idx < PNP_MAX_IRQ; idx++) {
266 res = &dev->res->irq[idx].res;
267 res->flags = IORESOURCE_IRQ;
268 pnp_init_resource(res);
269 }
270 for (idx = 0; idx < PNP_MAX_DMA; idx++) {
271 res = &dev->res->dma[idx].res;
272 res->flags = IORESOURCE_DMA;
273 pnp_init_resource(res);
274 }
275 for (idx = 0; idx < PNP_MAX_PORT; idx++) {
276 res = &dev->res->port[idx].res;
277 res->flags = IORESOURCE_IO;
278 pnp_init_resource(res);
279 }
280 for (idx = 0; idx < PNP_MAX_MEM; idx++) {
281 res = &dev->res->mem[idx].res;
282 res->flags = IORESOURCE_MEM;
283 pnp_init_resource(res);
284 }
285} 218}
286 219
287/**
288 * pnp_clean_resources - clears resources that were not manually set
289 * @res: the resources to clean
290 */
291static void pnp_clean_resource_table(struct pnp_dev *dev) 220static void pnp_clean_resource_table(struct pnp_dev *dev)
292{ 221{
293 struct resource *res; 222 struct pnp_resource *pnp_res, *tmp;
294 int idx; 223
295 224 list_for_each_entry_safe(pnp_res, tmp, &dev->resources, list) {
296 for (idx = 0; idx < PNP_MAX_IRQ; idx++) { 225 if (pnp_res->res.flags & IORESOURCE_AUTO)
297 res = &dev->res->irq[idx].res; 226 pnp_free_resource(pnp_res);
298 if (res->flags & IORESOURCE_AUTO) {
299 res->flags = IORESOURCE_IRQ;
300 pnp_init_resource(res);
301 }
302 }
303 for (idx = 0; idx < PNP_MAX_DMA; idx++) {
304 res = &dev->res->dma[idx].res;
305 if (res->flags & IORESOURCE_AUTO) {
306 res->flags = IORESOURCE_DMA;
307 pnp_init_resource(res);
308 }
309 }
310 for (idx = 0; idx < PNP_MAX_PORT; idx++) {
311 res = &dev->res->port[idx].res;
312 if (res->flags & IORESOURCE_AUTO) {
313 res->flags = IORESOURCE_IO;
314 pnp_init_resource(res);
315 }
316 }
317 for (idx = 0; idx < PNP_MAX_MEM; idx++) {
318 res = &dev->res->mem[idx].res;
319 if (res->flags & IORESOURCE_AUTO) {
320 res->flags = IORESOURCE_MEM;
321 pnp_init_resource(res);
322 }
323 } 227 }
324} 228}
325 229
326/** 230/**
327 * pnp_assign_resources - assigns resources to the device based on the specified dependent number 231 * pnp_assign_resources - assigns resources to the device based on the specified dependent number
328 * @dev: pointer to the desired device 232 * @dev: pointer to the desired device
329 * @depnum: the dependent function number 233 * @set: the dependent function number
330 *
331 * Only set depnum to 0 if the device does not have dependent options.
332 */ 234 */
333static int pnp_assign_resources(struct pnp_dev *dev, int depnum) 235static int pnp_assign_resources(struct pnp_dev *dev, int set)
334{ 236{
335 struct pnp_port *port; 237 struct pnp_option *option;
336 struct pnp_mem *mem;
337 struct pnp_irq *irq;
338 struct pnp_dma *dma;
339 int nport = 0, nmem = 0, nirq = 0, ndma = 0; 238 int nport = 0, nmem = 0, nirq = 0, ndma = 0;
239 int ret = 0;
340 240
341 if (!pnp_can_configure(dev)) 241 dev_dbg(&dev->dev, "pnp_assign_resources, try dependent set %d\n", set);
342 return -ENODEV;
343
344 dbg_pnp_show_resources(dev, "before pnp_assign_resources");
345 mutex_lock(&pnp_res_mutex); 242 mutex_lock(&pnp_res_mutex);
346 pnp_clean_resource_table(dev); 243 pnp_clean_resource_table(dev);
347 if (dev->independent) {
348 dev_dbg(&dev->dev, "assigning independent options\n");
349 port = dev->independent->port;
350 mem = dev->independent->mem;
351 irq = dev->independent->irq;
352 dma = dev->independent->dma;
353 while (port) {
354 if (!pnp_assign_port(dev, port, nport))
355 goto fail;
356 nport++;
357 port = port->next;
358 }
359 while (mem) {
360 if (!pnp_assign_mem(dev, mem, nmem))
361 goto fail;
362 nmem++;
363 mem = mem->next;
364 }
365 while (irq) {
366 if (!pnp_assign_irq(dev, irq, nirq))
367 goto fail;
368 nirq++;
369 irq = irq->next;
370 }
371 while (dma) {
372 pnp_assign_dma(dev, dma, ndma);
373 ndma++;
374 dma = dma->next;
375 }
376 }
377 244
378 if (depnum) { 245 list_for_each_entry(option, &dev->options, list) {
379 struct pnp_option *dep; 246 if (pnp_option_is_dependent(option) &&
380 int i; 247 pnp_option_set(option) != set)
381 248 continue;
382 dev_dbg(&dev->dev, "assigning dependent option %d\n", depnum); 249
383 for (i = 1, dep = dev->dependent; i < depnum; 250 switch (option->type) {
384 i++, dep = dep->next) 251 case IORESOURCE_IO:
385 if (!dep) 252 ret = pnp_assign_port(dev, &option->u.port, nport++);
386 goto fail; 253 break;
387 port = dep->port; 254 case IORESOURCE_MEM:
388 mem = dep->mem; 255 ret = pnp_assign_mem(dev, &option->u.mem, nmem++);
389 irq = dep->irq; 256 break;
390 dma = dep->dma; 257 case IORESOURCE_IRQ:
391 while (port) { 258 ret = pnp_assign_irq(dev, &option->u.irq, nirq++);
392 if (!pnp_assign_port(dev, port, nport)) 259 break;
393 goto fail; 260 case IORESOURCE_DMA:
394 nport++; 261 ret = pnp_assign_dma(dev, &option->u.dma, ndma++);
395 port = port->next; 262 break;
396 } 263 default:
397 while (mem) { 264 ret = -EINVAL;
398 if (!pnp_assign_mem(dev, mem, nmem)) 265 break;
399 goto fail;
400 nmem++;
401 mem = mem->next;
402 }
403 while (irq) {
404 if (!pnp_assign_irq(dev, irq, nirq))
405 goto fail;
406 nirq++;
407 irq = irq->next;
408 } 266 }
409 while (dma) { 267 if (ret < 0)
410 pnp_assign_dma(dev, dma, ndma); 268 break;
411 ndma++; 269 }
412 dma = dma->next;
413 }
414 } else if (dev->dependent)
415 goto fail;
416
417 mutex_unlock(&pnp_res_mutex);
418 dbg_pnp_show_resources(dev, "after pnp_assign_resources");
419 return 1;
420 270
421fail:
422 pnp_clean_resource_table(dev);
423 mutex_unlock(&pnp_res_mutex); 271 mutex_unlock(&pnp_res_mutex);
424 dbg_pnp_show_resources(dev, "after pnp_assign_resources (failed)"); 272 if (ret < 0) {
425 return 0; 273 dev_dbg(&dev->dev, "pnp_assign_resources failed (%d)\n", ret);
274 pnp_clean_resource_table(dev);
275 } else
276 dbg_pnp_show_resources(dev, "pnp_assign_resources succeeded");
277 return ret;
426} 278}
427 279
428/** 280/**
@@ -431,29 +283,25 @@ fail:
431 */ 283 */
432int pnp_auto_config_dev(struct pnp_dev *dev) 284int pnp_auto_config_dev(struct pnp_dev *dev)
433{ 285{
434 struct pnp_option *dep; 286 int i, ret;
435 int i = 1;
436 287
437 if (!pnp_can_configure(dev)) { 288 if (!pnp_can_configure(dev)) {
438 dev_dbg(&dev->dev, "configuration not supported\n"); 289 dev_dbg(&dev->dev, "configuration not supported\n");
439 return -ENODEV; 290 return -ENODEV;
440 } 291 }
441 292
442 if (!dev->dependent) { 293 ret = pnp_assign_resources(dev, 0);
443 if (pnp_assign_resources(dev, 0)) 294 if (ret == 0)
295 return 0;
296
297 for (i = 1; i < dev->num_dependent_sets; i++) {
298 ret = pnp_assign_resources(dev, i);
299 if (ret == 0)
444 return 0; 300 return 0;
445 } else {
446 dep = dev->dependent;
447 do {
448 if (pnp_assign_resources(dev, i))
449 return 0;
450 dep = dep->next;
451 i++;
452 } while (dep);
453 } 301 }
454 302
455 dev_err(&dev->dev, "unable to assign resources\n"); 303 dev_err(&dev->dev, "unable to assign resources\n");
456 return -EBUSY; 304 return ret;
457} 305}
458 306
459/** 307/**
diff --git a/drivers/pnp/pnpacpi/core.c b/drivers/pnp/pnpacpi/core.c
index 50902773beaf..c1b9ea34977b 100644
--- a/drivers/pnp/pnpacpi/core.c
+++ b/drivers/pnp/pnpacpi/core.c
@@ -117,9 +117,7 @@ static int pnpacpi_suspend(struct pnp_dev *dev, pm_message_t state)
117{ 117{
118 int power_state; 118 int power_state;
119 119
120 power_state = acpi_pm_device_sleep_state(&dev->dev, 120 power_state = acpi_pm_device_sleep_state(&dev->dev, NULL);
121 device_may_wakeup(&dev->dev),
122 NULL);
123 if (power_state < 0) 121 if (power_state < 0)
124 power_state = (state.event == PM_EVENT_ON) ? 122 power_state = (state.event == PM_EVENT_ON) ?
125 ACPI_STATE_D0 : ACPI_STATE_D3; 123 ACPI_STATE_D0 : ACPI_STATE_D3;
diff --git a/drivers/pnp/pnpacpi/rsparser.c b/drivers/pnp/pnpacpi/rsparser.c
index 46c791adb894..d7e9f2152df0 100644
--- a/drivers/pnp/pnpacpi/rsparser.c
+++ b/drivers/pnp/pnpacpi/rsparser.c
@@ -3,6 +3,8 @@
3 * 3 *
4 * Copyright (c) 2004 Matthieu Castet <castet.matthieu@free.fr> 4 * Copyright (c) 2004 Matthieu Castet <castet.matthieu@free.fr>
5 * Copyright (c) 2004 Li Shaohua <shaohua.li@intel.com> 5 * Copyright (c) 2004 Li Shaohua <shaohua.li@intel.com>
6 * Copyright (C) 2008 Hewlett-Packard Development Company, L.P.
7 * Bjorn Helgaas <bjorn.helgaas@hp.com>
6 * 8 *
7 * This program is free software; you can redistribute it and/or modify it 9 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the 10 * under the terms of the GNU General Public License as published by the
@@ -98,8 +100,10 @@ static void pnpacpi_parse_allocated_irqresource(struct pnp_dev *dev,
98 int irq, flags; 100 int irq, flags;
99 int p, t; 101 int p, t;
100 102
101 if (!valid_IRQ(gsi)) 103 if (!valid_IRQ(gsi)) {
104 pnp_add_irq_resource(dev, gsi, IORESOURCE_DISABLED);
102 return; 105 return;
106 }
103 107
104 /* 108 /*
105 * in IO-APIC mode, use overrided attribute. Two reasons: 109 * in IO-APIC mode, use overrided attribute. Two reasons:
@@ -178,13 +182,68 @@ static void pnpacpi_parse_allocated_ioresource(struct pnp_dev *dev, u64 start,
178 u64 end = start + len - 1; 182 u64 end = start + len - 1;
179 183
180 if (io_decode == ACPI_DECODE_16) 184 if (io_decode == ACPI_DECODE_16)
181 flags |= PNP_PORT_FLAG_16BITADDR; 185 flags |= IORESOURCE_IO_16BIT_ADDR;
182 if (len == 0 || end >= 0x10003) 186 if (len == 0 || end >= 0x10003)
183 flags |= IORESOURCE_DISABLED; 187 flags |= IORESOURCE_DISABLED;
184 188
185 pnp_add_io_resource(dev, start, end, flags); 189 pnp_add_io_resource(dev, start, end, flags);
186} 190}
187 191
192/*
193 * Device CSRs that do not appear in PCI config space should be described
194 * via ACPI. This would normally be done with Address Space Descriptors
195 * marked as "consumer-only," but old versions of Windows and Linux ignore
196 * the producer/consumer flag, so HP invented a vendor-defined resource to
197 * describe the location and size of CSR space.
198 */
199static struct acpi_vendor_uuid hp_ccsr_uuid = {
200 .subtype = 2,
201 .data = { 0xf9, 0xad, 0xe9, 0x69, 0x4f, 0x92, 0x5f, 0xab, 0xf6, 0x4a,
202 0x24, 0xd2, 0x01, 0x37, 0x0e, 0xad },
203};
204
205static int vendor_resource_matches(struct pnp_dev *dev,
206 struct acpi_resource_vendor_typed *vendor,
207 struct acpi_vendor_uuid *match,
208 int expected_len)
209{
210 int uuid_len = sizeof(vendor->uuid);
211 u8 uuid_subtype = vendor->uuid_subtype;
212 u8 *uuid = vendor->uuid;
213 int actual_len;
214
215 /* byte_length includes uuid_subtype and uuid */
216 actual_len = vendor->byte_length - uuid_len - 1;
217
218 if (uuid_subtype == match->subtype &&
219 uuid_len == sizeof(match->data) &&
220 memcmp(uuid, match->data, uuid_len) == 0) {
221 if (expected_len && expected_len != actual_len) {
222 dev_err(&dev->dev, "wrong vendor descriptor size; "
223 "expected %d, found %d bytes\n",
224 expected_len, actual_len);
225 return 0;
226 }
227
228 return 1;
229 }
230
231 return 0;
232}
233
234static void pnpacpi_parse_allocated_vendor(struct pnp_dev *dev,
235 struct acpi_resource_vendor_typed *vendor)
236{
237 if (vendor_resource_matches(dev, vendor, &hp_ccsr_uuid, 16)) {
238 u64 start, length;
239
240 memcpy(&start, vendor->byte_data, sizeof(start));
241 memcpy(&length, vendor->byte_data + 8, sizeof(length));
242
243 pnp_add_mem_resource(dev, start, start + length - 1, 0);
244 }
245}
246
188static void pnpacpi_parse_allocated_memresource(struct pnp_dev *dev, 247static void pnpacpi_parse_allocated_memresource(struct pnp_dev *dev,
189 u64 start, u64 len, 248 u64 start, u64 len,
190 int write_protect) 249 int write_protect)
@@ -235,6 +294,7 @@ static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
235 struct acpi_resource_dma *dma; 294 struct acpi_resource_dma *dma;
236 struct acpi_resource_io *io; 295 struct acpi_resource_io *io;
237 struct acpi_resource_fixed_io *fixed_io; 296 struct acpi_resource_fixed_io *fixed_io;
297 struct acpi_resource_vendor_typed *vendor_typed;
238 struct acpi_resource_memory24 *memory24; 298 struct acpi_resource_memory24 *memory24;
239 struct acpi_resource_memory32 *memory32; 299 struct acpi_resource_memory32 *memory32;
240 struct acpi_resource_fixed_memory32 *fixed_memory32; 300 struct acpi_resource_fixed_memory32 *fixed_memory32;
@@ -248,24 +308,39 @@ static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
248 * _CRS, but some firmware violates this, so parse them all. 308 * _CRS, but some firmware violates this, so parse them all.
249 */ 309 */
250 irq = &res->data.irq; 310 irq = &res->data.irq;
251 for (i = 0; i < irq->interrupt_count; i++) { 311 if (irq->interrupt_count == 0)
252 pnpacpi_parse_allocated_irqresource(dev, 312 pnp_add_irq_resource(dev, 0, IORESOURCE_DISABLED);
253 irq->interrupts[i], 313 else {
254 irq->triggering, 314 for (i = 0; i < irq->interrupt_count; i++) {
255 irq->polarity, 315 pnpacpi_parse_allocated_irqresource(dev,
256 irq->sharable); 316 irq->interrupts[i],
317 irq->triggering,
318 irq->polarity,
319 irq->sharable);
320 }
321
322 /*
323 * The IRQ encoder puts a single interrupt in each
324 * descriptor, so if a _CRS descriptor has more than
325 * one interrupt, we won't be able to re-encode it.
326 */
327 if (pnp_can_write(dev) && irq->interrupt_count > 1) {
328 dev_warn(&dev->dev, "multiple interrupts in "
329 "_CRS descriptor; configuration can't "
330 "be changed\n");
331 dev->capabilities &= ~PNP_WRITE;
332 }
257 } 333 }
258 break; 334 break;
259 335
260 case ACPI_RESOURCE_TYPE_DMA: 336 case ACPI_RESOURCE_TYPE_DMA:
261 dma = &res->data.dma; 337 dma = &res->data.dma;
262 if (dma->channel_count > 0) { 338 if (dma->channel_count > 0 && dma->channels[0] != (u8) -1)
263 flags = dma_flags(dma->type, dma->bus_master, 339 flags = dma_flags(dma->type, dma->bus_master,
264 dma->transfer); 340 dma->transfer);
265 if (dma->channels[0] == (u8) -1) 341 else
266 flags |= IORESOURCE_DISABLED; 342 flags = IORESOURCE_DISABLED;
267 pnp_add_dma_resource(dev, dma->channels[0], flags); 343 pnp_add_dma_resource(dev, dma->channels[0], flags);
268 }
269 break; 344 break;
270 345
271 case ACPI_RESOURCE_TYPE_IO: 346 case ACPI_RESOURCE_TYPE_IO:
@@ -289,6 +364,8 @@ static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
289 break; 364 break;
290 365
291 case ACPI_RESOURCE_TYPE_VENDOR: 366 case ACPI_RESOURCE_TYPE_VENDOR:
367 vendor_typed = &res->data.vendor_typed;
368 pnpacpi_parse_allocated_vendor(dev, vendor_typed);
292 break; 369 break;
293 370
294 case ACPI_RESOURCE_TYPE_END_TAG: 371 case ACPI_RESOURCE_TYPE_END_TAG:
@@ -331,12 +408,29 @@ static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
331 if (extended_irq->producer_consumer == ACPI_PRODUCER) 408 if (extended_irq->producer_consumer == ACPI_PRODUCER)
332 return AE_OK; 409 return AE_OK;
333 410
334 for (i = 0; i < extended_irq->interrupt_count; i++) { 411 if (extended_irq->interrupt_count == 0)
335 pnpacpi_parse_allocated_irqresource(dev, 412 pnp_add_irq_resource(dev, 0, IORESOURCE_DISABLED);
336 extended_irq->interrupts[i], 413 else {
337 extended_irq->triggering, 414 for (i = 0; i < extended_irq->interrupt_count; i++) {
338 extended_irq->polarity, 415 pnpacpi_parse_allocated_irqresource(dev,
339 extended_irq->sharable); 416 extended_irq->interrupts[i],
417 extended_irq->triggering,
418 extended_irq->polarity,
419 extended_irq->sharable);
420 }
421
422 /*
423 * The IRQ encoder puts a single interrupt in each
424 * descriptor, so if a _CRS descriptor has more than
425 * one interrupt, we won't be able to re-encode it.
426 */
427 if (pnp_can_write(dev) &&
428 extended_irq->interrupt_count > 1) {
429 dev_warn(&dev->dev, "multiple interrupts in "
430 "_CRS descriptor; configuration can't "
431 "be changed\n");
432 dev->capabilities &= ~PNP_WRITE;
433 }
340 } 434 }
341 break; 435 break;
342 436
@@ -373,179 +467,147 @@ int pnpacpi_parse_allocated_resource(struct pnp_dev *dev)
373} 467}
374 468
375static __init void pnpacpi_parse_dma_option(struct pnp_dev *dev, 469static __init void pnpacpi_parse_dma_option(struct pnp_dev *dev,
376 struct pnp_option *option, 470 unsigned int option_flags,
377 struct acpi_resource_dma *p) 471 struct acpi_resource_dma *p)
378{ 472{
379 int i; 473 int i;
380 struct pnp_dma *dma; 474 unsigned char map = 0, flags;
381 475
382 if (p->channel_count == 0) 476 if (p->channel_count == 0)
383 return; 477 return;
384 dma = kzalloc(sizeof(struct pnp_dma), GFP_KERNEL);
385 if (!dma)
386 return;
387 478
388 for (i = 0; i < p->channel_count; i++) 479 for (i = 0; i < p->channel_count; i++)
389 dma->map |= 1 << p->channels[i]; 480 map |= 1 << p->channels[i];
390
391 dma->flags = dma_flags(p->type, p->bus_master, p->transfer);
392 481
393 pnp_register_dma_resource(dev, option, dma); 482 flags = dma_flags(p->type, p->bus_master, p->transfer);
483 pnp_register_dma_resource(dev, option_flags, map, flags);
394} 484}
395 485
396static __init void pnpacpi_parse_irq_option(struct pnp_dev *dev, 486static __init void pnpacpi_parse_irq_option(struct pnp_dev *dev,
397 struct pnp_option *option, 487 unsigned int option_flags,
398 struct acpi_resource_irq *p) 488 struct acpi_resource_irq *p)
399{ 489{
400 int i; 490 int i;
401 struct pnp_irq *irq; 491 pnp_irq_mask_t map;
492 unsigned char flags;
402 493
403 if (p->interrupt_count == 0) 494 if (p->interrupt_count == 0)
404 return; 495 return;
405 irq = kzalloc(sizeof(struct pnp_irq), GFP_KERNEL);
406 if (!irq)
407 return;
408 496
497 bitmap_zero(map.bits, PNP_IRQ_NR);
409 for (i = 0; i < p->interrupt_count; i++) 498 for (i = 0; i < p->interrupt_count; i++)
410 if (p->interrupts[i]) 499 if (p->interrupts[i])
411 __set_bit(p->interrupts[i], irq->map); 500 __set_bit(p->interrupts[i], map.bits);
412 irq->flags = irq_flags(p->triggering, p->polarity, p->sharable);
413 501
414 pnp_register_irq_resource(dev, option, irq); 502 flags = irq_flags(p->triggering, p->polarity, p->sharable);
503 pnp_register_irq_resource(dev, option_flags, &map, flags);
415} 504}
416 505
417static __init void pnpacpi_parse_ext_irq_option(struct pnp_dev *dev, 506static __init void pnpacpi_parse_ext_irq_option(struct pnp_dev *dev,
418 struct pnp_option *option, 507 unsigned int option_flags,
419 struct acpi_resource_extended_irq *p) 508 struct acpi_resource_extended_irq *p)
420{ 509{
421 int i; 510 int i;
422 struct pnp_irq *irq; 511 pnp_irq_mask_t map;
512 unsigned char flags;
423 513
424 if (p->interrupt_count == 0) 514 if (p->interrupt_count == 0)
425 return; 515 return;
426 irq = kzalloc(sizeof(struct pnp_irq), GFP_KERNEL);
427 if (!irq)
428 return;
429 516
430 for (i = 0; i < p->interrupt_count; i++) 517 bitmap_zero(map.bits, PNP_IRQ_NR);
431 if (p->interrupts[i]) 518 for (i = 0; i < p->interrupt_count; i++) {
432 __set_bit(p->interrupts[i], irq->map); 519 if (p->interrupts[i]) {
433 irq->flags = irq_flags(p->triggering, p->polarity, p->sharable); 520 if (p->interrupts[i] < PNP_IRQ_NR)
521 __set_bit(p->interrupts[i], map.bits);
522 else
523 dev_err(&dev->dev, "ignoring IRQ %d option "
524 "(too large for %d entry bitmap)\n",
525 p->interrupts[i], PNP_IRQ_NR);
526 }
527 }
434 528
435 pnp_register_irq_resource(dev, option, irq); 529 flags = irq_flags(p->triggering, p->polarity, p->sharable);
530 pnp_register_irq_resource(dev, option_flags, &map, flags);
436} 531}
437 532
438static __init void pnpacpi_parse_port_option(struct pnp_dev *dev, 533static __init void pnpacpi_parse_port_option(struct pnp_dev *dev,
439 struct pnp_option *option, 534 unsigned int option_flags,
440 struct acpi_resource_io *io) 535 struct acpi_resource_io *io)
441{ 536{
442 struct pnp_port *port; 537 unsigned char flags = 0;
443 538
444 if (io->address_length == 0) 539 if (io->address_length == 0)
445 return; 540 return;
446 port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL); 541
447 if (!port) 542 if (io->io_decode == ACPI_DECODE_16)
448 return; 543 flags = IORESOURCE_IO_16BIT_ADDR;
449 port->min = io->minimum; 544 pnp_register_port_resource(dev, option_flags, io->minimum, io->maximum,
450 port->max = io->maximum; 545 io->alignment, io->address_length, flags);
451 port->align = io->alignment;
452 port->size = io->address_length;
453 port->flags = ACPI_DECODE_16 == io->io_decode ?
454 PNP_PORT_FLAG_16BITADDR : 0;
455 pnp_register_port_resource(dev, option, port);
456} 546}
457 547
458static __init void pnpacpi_parse_fixed_port_option(struct pnp_dev *dev, 548static __init void pnpacpi_parse_fixed_port_option(struct pnp_dev *dev,
459 struct pnp_option *option, 549 unsigned int option_flags,
460 struct acpi_resource_fixed_io *io) 550 struct acpi_resource_fixed_io *io)
461{ 551{
462 struct pnp_port *port;
463
464 if (io->address_length == 0) 552 if (io->address_length == 0)
465 return; 553 return;
466 port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL); 554
467 if (!port) 555 pnp_register_port_resource(dev, option_flags, io->address, io->address,
468 return; 556 0, io->address_length, IORESOURCE_IO_FIXED);
469 port->min = port->max = io->address;
470 port->size = io->address_length;
471 port->align = 0;
472 port->flags = PNP_PORT_FLAG_FIXED;
473 pnp_register_port_resource(dev, option, port);
474} 557}
475 558
476static __init void pnpacpi_parse_mem24_option(struct pnp_dev *dev, 559static __init void pnpacpi_parse_mem24_option(struct pnp_dev *dev,
477 struct pnp_option *option, 560 unsigned int option_flags,
478 struct acpi_resource_memory24 *p) 561 struct acpi_resource_memory24 *p)
479{ 562{
480 struct pnp_mem *mem; 563 unsigned char flags = 0;
481 564
482 if (p->address_length == 0) 565 if (p->address_length == 0)
483 return; 566 return;
484 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
485 if (!mem)
486 return;
487 mem->min = p->minimum;
488 mem->max = p->maximum;
489 mem->align = p->alignment;
490 mem->size = p->address_length;
491
492 mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ?
493 IORESOURCE_MEM_WRITEABLE : 0;
494 567
495 pnp_register_mem_resource(dev, option, mem); 568 if (p->write_protect == ACPI_READ_WRITE_MEMORY)
569 flags = IORESOURCE_MEM_WRITEABLE;
570 pnp_register_mem_resource(dev, option_flags, p->minimum, p->maximum,
571 p->alignment, p->address_length, flags);
496} 572}
497 573
498static __init void pnpacpi_parse_mem32_option(struct pnp_dev *dev, 574static __init void pnpacpi_parse_mem32_option(struct pnp_dev *dev,
499 struct pnp_option *option, 575 unsigned int option_flags,
500 struct acpi_resource_memory32 *p) 576 struct acpi_resource_memory32 *p)
501{ 577{
502 struct pnp_mem *mem; 578 unsigned char flags = 0;
503 579
504 if (p->address_length == 0) 580 if (p->address_length == 0)
505 return; 581 return;
506 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
507 if (!mem)
508 return;
509 mem->min = p->minimum;
510 mem->max = p->maximum;
511 mem->align = p->alignment;
512 mem->size = p->address_length;
513
514 mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ?
515 IORESOURCE_MEM_WRITEABLE : 0;
516 582
517 pnp_register_mem_resource(dev, option, mem); 583 if (p->write_protect == ACPI_READ_WRITE_MEMORY)
584 flags = IORESOURCE_MEM_WRITEABLE;
585 pnp_register_mem_resource(dev, option_flags, p->minimum, p->maximum,
586 p->alignment, p->address_length, flags);
518} 587}
519 588
520static __init void pnpacpi_parse_fixed_mem32_option(struct pnp_dev *dev, 589static __init void pnpacpi_parse_fixed_mem32_option(struct pnp_dev *dev,
521 struct pnp_option *option, 590 unsigned int option_flags,
522 struct acpi_resource_fixed_memory32 *p) 591 struct acpi_resource_fixed_memory32 *p)
523{ 592{
524 struct pnp_mem *mem; 593 unsigned char flags = 0;
525 594
526 if (p->address_length == 0) 595 if (p->address_length == 0)
527 return; 596 return;
528 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
529 if (!mem)
530 return;
531 mem->min = mem->max = p->address;
532 mem->size = p->address_length;
533 mem->align = 0;
534
535 mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ?
536 IORESOURCE_MEM_WRITEABLE : 0;
537 597
538 pnp_register_mem_resource(dev, option, mem); 598 if (p->write_protect == ACPI_READ_WRITE_MEMORY)
599 flags = IORESOURCE_MEM_WRITEABLE;
600 pnp_register_mem_resource(dev, option_flags, p->address, p->address,
601 0, p->address_length, flags);
539} 602}
540 603
541static __init void pnpacpi_parse_address_option(struct pnp_dev *dev, 604static __init void pnpacpi_parse_address_option(struct pnp_dev *dev,
542 struct pnp_option *option, 605 unsigned int option_flags,
543 struct acpi_resource *r) 606 struct acpi_resource *r)
544{ 607{
545 struct acpi_resource_address64 addr, *p = &addr; 608 struct acpi_resource_address64 addr, *p = &addr;
546 acpi_status status; 609 acpi_status status;
547 struct pnp_mem *mem; 610 unsigned char flags = 0;
548 struct pnp_port *port;
549 611
550 status = acpi_resource_to_address64(r, p); 612 status = acpi_resource_to_address64(r, p);
551 if (!ACPI_SUCCESS(status)) { 613 if (!ACPI_SUCCESS(status)) {
@@ -558,49 +620,37 @@ static __init void pnpacpi_parse_address_option(struct pnp_dev *dev,
558 return; 620 return;
559 621
560 if (p->resource_type == ACPI_MEMORY_RANGE) { 622 if (p->resource_type == ACPI_MEMORY_RANGE) {
561 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL); 623 if (p->info.mem.write_protect == ACPI_READ_WRITE_MEMORY)
562 if (!mem) 624 flags = IORESOURCE_MEM_WRITEABLE;
563 return; 625 pnp_register_mem_resource(dev, option_flags, p->minimum,
564 mem->min = mem->max = p->minimum; 626 p->minimum, 0, p->address_length,
565 mem->size = p->address_length; 627 flags);
566 mem->align = 0; 628 } else if (p->resource_type == ACPI_IO_RANGE)
567 mem->flags = (p->info.mem.write_protect == 629 pnp_register_port_resource(dev, option_flags, p->minimum,
568 ACPI_READ_WRITE_MEMORY) ? IORESOURCE_MEM_WRITEABLE 630 p->minimum, 0, p->address_length,
569 : 0; 631 IORESOURCE_IO_FIXED);
570 pnp_register_mem_resource(dev, option, mem);
571 } else if (p->resource_type == ACPI_IO_RANGE) {
572 port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL);
573 if (!port)
574 return;
575 port->min = port->max = p->minimum;
576 port->size = p->address_length;
577 port->align = 0;
578 port->flags = PNP_PORT_FLAG_FIXED;
579 pnp_register_port_resource(dev, option, port);
580 }
581} 632}
582 633
583struct acpipnp_parse_option_s { 634struct acpipnp_parse_option_s {
584 struct pnp_option *option;
585 struct pnp_option *option_independent;
586 struct pnp_dev *dev; 635 struct pnp_dev *dev;
636 unsigned int option_flags;
587}; 637};
588 638
589static __init acpi_status pnpacpi_option_resource(struct acpi_resource *res, 639static __init acpi_status pnpacpi_option_resource(struct acpi_resource *res,
590 void *data) 640 void *data)
591{ 641{
592 int priority = 0; 642 int priority;
593 struct acpipnp_parse_option_s *parse_data = data; 643 struct acpipnp_parse_option_s *parse_data = data;
594 struct pnp_dev *dev = parse_data->dev; 644 struct pnp_dev *dev = parse_data->dev;
595 struct pnp_option *option = parse_data->option; 645 unsigned int option_flags = parse_data->option_flags;
596 646
597 switch (res->type) { 647 switch (res->type) {
598 case ACPI_RESOURCE_TYPE_IRQ: 648 case ACPI_RESOURCE_TYPE_IRQ:
599 pnpacpi_parse_irq_option(dev, option, &res->data.irq); 649 pnpacpi_parse_irq_option(dev, option_flags, &res->data.irq);
600 break; 650 break;
601 651
602 case ACPI_RESOURCE_TYPE_DMA: 652 case ACPI_RESOURCE_TYPE_DMA:
603 pnpacpi_parse_dma_option(dev, option, &res->data.dma); 653 pnpacpi_parse_dma_option(dev, option_flags, &res->data.dma);
604 break; 654 break;
605 655
606 case ACPI_RESOURCE_TYPE_START_DEPENDENT: 656 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
@@ -620,31 +670,19 @@ static __init acpi_status pnpacpi_option_resource(struct acpi_resource *res,
620 priority = PNP_RES_PRIORITY_INVALID; 670 priority = PNP_RES_PRIORITY_INVALID;
621 break; 671 break;
622 } 672 }
623 /* TBD: Consider performance/robustness bits */ 673 parse_data->option_flags = pnp_new_dependent_set(dev, priority);
624 option = pnp_register_dependent_option(dev, priority);
625 if (!option)
626 return AE_ERROR;
627 parse_data->option = option;
628 break; 674 break;
629 675
630 case ACPI_RESOURCE_TYPE_END_DEPENDENT: 676 case ACPI_RESOURCE_TYPE_END_DEPENDENT:
631 /*only one EndDependentFn is allowed */ 677 parse_data->option_flags = 0;
632 if (!parse_data->option_independent) {
633 dev_warn(&dev->dev, "more than one EndDependentFn "
634 "in _PRS\n");
635 return AE_ERROR;
636 }
637 parse_data->option = parse_data->option_independent;
638 parse_data->option_independent = NULL;
639 dev_dbg(&dev->dev, "end dependent options\n");
640 break; 678 break;
641 679
642 case ACPI_RESOURCE_TYPE_IO: 680 case ACPI_RESOURCE_TYPE_IO:
643 pnpacpi_parse_port_option(dev, option, &res->data.io); 681 pnpacpi_parse_port_option(dev, option_flags, &res->data.io);
644 break; 682 break;
645 683
646 case ACPI_RESOURCE_TYPE_FIXED_IO: 684 case ACPI_RESOURCE_TYPE_FIXED_IO:
647 pnpacpi_parse_fixed_port_option(dev, option, 685 pnpacpi_parse_fixed_port_option(dev, option_flags,
648 &res->data.fixed_io); 686 &res->data.fixed_io);
649 break; 687 break;
650 688
@@ -653,29 +691,31 @@ static __init acpi_status pnpacpi_option_resource(struct acpi_resource *res,
653 break; 691 break;
654 692
655 case ACPI_RESOURCE_TYPE_MEMORY24: 693 case ACPI_RESOURCE_TYPE_MEMORY24:
656 pnpacpi_parse_mem24_option(dev, option, &res->data.memory24); 694 pnpacpi_parse_mem24_option(dev, option_flags,
695 &res->data.memory24);
657 break; 696 break;
658 697
659 case ACPI_RESOURCE_TYPE_MEMORY32: 698 case ACPI_RESOURCE_TYPE_MEMORY32:
660 pnpacpi_parse_mem32_option(dev, option, &res->data.memory32); 699 pnpacpi_parse_mem32_option(dev, option_flags,
700 &res->data.memory32);
661 break; 701 break;
662 702
663 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32: 703 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
664 pnpacpi_parse_fixed_mem32_option(dev, option, 704 pnpacpi_parse_fixed_mem32_option(dev, option_flags,
665 &res->data.fixed_memory32); 705 &res->data.fixed_memory32);
666 break; 706 break;
667 707
668 case ACPI_RESOURCE_TYPE_ADDRESS16: 708 case ACPI_RESOURCE_TYPE_ADDRESS16:
669 case ACPI_RESOURCE_TYPE_ADDRESS32: 709 case ACPI_RESOURCE_TYPE_ADDRESS32:
670 case ACPI_RESOURCE_TYPE_ADDRESS64: 710 case ACPI_RESOURCE_TYPE_ADDRESS64:
671 pnpacpi_parse_address_option(dev, option, res); 711 pnpacpi_parse_address_option(dev, option_flags, res);
672 break; 712 break;
673 713
674 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64: 714 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
675 break; 715 break;
676 716
677 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ: 717 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
678 pnpacpi_parse_ext_irq_option(dev, option, 718 pnpacpi_parse_ext_irq_option(dev, option_flags,
679 &res->data.extended_irq); 719 &res->data.extended_irq);
680 break; 720 break;
681 721
@@ -699,12 +739,9 @@ int __init pnpacpi_parse_resource_option_data(struct pnp_dev *dev)
699 739
700 dev_dbg(&dev->dev, "parse resource options\n"); 740 dev_dbg(&dev->dev, "parse resource options\n");
701 741
702 parse_data.option = pnp_register_independent_option(dev);
703 if (!parse_data.option)
704 return -ENOMEM;
705
706 parse_data.option_independent = parse_data.option;
707 parse_data.dev = dev; 742 parse_data.dev = dev;
743 parse_data.option_flags = 0;
744
708 status = acpi_walk_resources(handle, METHOD_NAME__PRS, 745 status = acpi_walk_resources(handle, METHOD_NAME__PRS,
709 pnpacpi_option_resource, &parse_data); 746 pnpacpi_option_resource, &parse_data);
710 747
@@ -806,6 +843,13 @@ static void pnpacpi_encode_irq(struct pnp_dev *dev,
806 struct acpi_resource_irq *irq = &resource->data.irq; 843 struct acpi_resource_irq *irq = &resource->data.irq;
807 int triggering, polarity, shareable; 844 int triggering, polarity, shareable;
808 845
846 if (!pnp_resource_enabled(p)) {
847 irq->interrupt_count = 0;
848 dev_dbg(&dev->dev, " encode irq (%s)\n",
849 p ? "disabled" : "missing");
850 return;
851 }
852
809 decode_irq_flags(dev, p->flags, &triggering, &polarity, &shareable); 853 decode_irq_flags(dev, p->flags, &triggering, &polarity, &shareable);
810 irq->triggering = triggering; 854 irq->triggering = triggering;
811 irq->polarity = polarity; 855 irq->polarity = polarity;
@@ -828,6 +872,13 @@ static void pnpacpi_encode_ext_irq(struct pnp_dev *dev,
828 struct acpi_resource_extended_irq *extended_irq = &resource->data.extended_irq; 872 struct acpi_resource_extended_irq *extended_irq = &resource->data.extended_irq;
829 int triggering, polarity, shareable; 873 int triggering, polarity, shareable;
830 874
875 if (!pnp_resource_enabled(p)) {
876 extended_irq->interrupt_count = 0;
877 dev_dbg(&dev->dev, " encode extended irq (%s)\n",
878 p ? "disabled" : "missing");
879 return;
880 }
881
831 decode_irq_flags(dev, p->flags, &triggering, &polarity, &shareable); 882 decode_irq_flags(dev, p->flags, &triggering, &polarity, &shareable);
832 extended_irq->producer_consumer = ACPI_CONSUMER; 883 extended_irq->producer_consumer = ACPI_CONSUMER;
833 extended_irq->triggering = triggering; 884 extended_irq->triggering = triggering;
@@ -848,6 +899,13 @@ static void pnpacpi_encode_dma(struct pnp_dev *dev,
848{ 899{
849 struct acpi_resource_dma *dma = &resource->data.dma; 900 struct acpi_resource_dma *dma = &resource->data.dma;
850 901
902 if (!pnp_resource_enabled(p)) {
903 dma->channel_count = 0;
904 dev_dbg(&dev->dev, " encode dma (%s)\n",
905 p ? "disabled" : "missing");
906 return;
907 }
908
851 /* Note: pnp_assign_dma will copy pnp_dma->flags into p->flags */ 909 /* Note: pnp_assign_dma will copy pnp_dma->flags into p->flags */
852 switch (p->flags & IORESOURCE_DMA_SPEED_MASK) { 910 switch (p->flags & IORESOURCE_DMA_SPEED_MASK) {
853 case IORESOURCE_DMA_TYPEA: 911 case IORESOURCE_DMA_TYPEA:
@@ -889,17 +947,21 @@ static void pnpacpi_encode_io(struct pnp_dev *dev,
889{ 947{
890 struct acpi_resource_io *io = &resource->data.io; 948 struct acpi_resource_io *io = &resource->data.io;
891 949
892 /* Note: pnp_assign_port will copy pnp_port->flags into p->flags */ 950 if (pnp_resource_enabled(p)) {
893 io->io_decode = (p->flags & PNP_PORT_FLAG_16BITADDR) ? 951 /* Note: pnp_assign_port copies pnp_port->flags into p->flags */
894 ACPI_DECODE_16 : ACPI_DECODE_10; 952 io->io_decode = (p->flags & IORESOURCE_IO_16BIT_ADDR) ?
895 io->minimum = p->start; 953 ACPI_DECODE_16 : ACPI_DECODE_10;
896 io->maximum = p->end; 954 io->minimum = p->start;
897 io->alignment = 0; /* Correct? */ 955 io->maximum = p->end;
898 io->address_length = p->end - p->start + 1; 956 io->alignment = 0; /* Correct? */
899 957 io->address_length = p->end - p->start + 1;
900 dev_dbg(&dev->dev, " encode io %#llx-%#llx decode %#x\n", 958 } else {
901 (unsigned long long) p->start, (unsigned long long) p->end, 959 io->minimum = 0;
902 io->io_decode); 960 io->address_length = 0;
961 }
962
963 dev_dbg(&dev->dev, " encode io %#x-%#x decode %#x\n", io->minimum,
964 io->minimum + io->address_length - 1, io->io_decode);
903} 965}
904 966
905static void pnpacpi_encode_fixed_io(struct pnp_dev *dev, 967static void pnpacpi_encode_fixed_io(struct pnp_dev *dev,
@@ -908,11 +970,16 @@ static void pnpacpi_encode_fixed_io(struct pnp_dev *dev,
908{ 970{
909 struct acpi_resource_fixed_io *fixed_io = &resource->data.fixed_io; 971 struct acpi_resource_fixed_io *fixed_io = &resource->data.fixed_io;
910 972
911 fixed_io->address = p->start; 973 if (pnp_resource_enabled(p)) {
912 fixed_io->address_length = p->end - p->start + 1; 974 fixed_io->address = p->start;
975 fixed_io->address_length = p->end - p->start + 1;
976 } else {
977 fixed_io->address = 0;
978 fixed_io->address_length = 0;
979 }
913 980
914 dev_dbg(&dev->dev, " encode fixed_io %#llx-%#llx\n", 981 dev_dbg(&dev->dev, " encode fixed_io %#x-%#x\n", fixed_io->address,
915 (unsigned long long) p->start, (unsigned long long) p->end); 982 fixed_io->address + fixed_io->address_length - 1);
916} 983}
917 984
918static void pnpacpi_encode_mem24(struct pnp_dev *dev, 985static void pnpacpi_encode_mem24(struct pnp_dev *dev,
@@ -921,17 +988,22 @@ static void pnpacpi_encode_mem24(struct pnp_dev *dev,
921{ 988{
922 struct acpi_resource_memory24 *memory24 = &resource->data.memory24; 989 struct acpi_resource_memory24 *memory24 = &resource->data.memory24;
923 990
924 /* Note: pnp_assign_mem will copy pnp_mem->flags into p->flags */ 991 if (pnp_resource_enabled(p)) {
925 memory24->write_protect = 992 /* Note: pnp_assign_mem copies pnp_mem->flags into p->flags */
926 (p->flags & IORESOURCE_MEM_WRITEABLE) ? 993 memory24->write_protect = p->flags & IORESOURCE_MEM_WRITEABLE ?
927 ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY; 994 ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
928 memory24->minimum = p->start; 995 memory24->minimum = p->start;
929 memory24->maximum = p->end; 996 memory24->maximum = p->end;
930 memory24->alignment = 0; 997 memory24->alignment = 0;
931 memory24->address_length = p->end - p->start + 1; 998 memory24->address_length = p->end - p->start + 1;
932 999 } else {
933 dev_dbg(&dev->dev, " encode mem24 %#llx-%#llx write_protect %#x\n", 1000 memory24->minimum = 0;
934 (unsigned long long) p->start, (unsigned long long) p->end, 1001 memory24->address_length = 0;
1002 }
1003
1004 dev_dbg(&dev->dev, " encode mem24 %#x-%#x write_protect %#x\n",
1005 memory24->minimum,
1006 memory24->minimum + memory24->address_length - 1,
935 memory24->write_protect); 1007 memory24->write_protect);
936} 1008}
937 1009
@@ -941,16 +1013,21 @@ static void pnpacpi_encode_mem32(struct pnp_dev *dev,
941{ 1013{
942 struct acpi_resource_memory32 *memory32 = &resource->data.memory32; 1014 struct acpi_resource_memory32 *memory32 = &resource->data.memory32;
943 1015
944 memory32->write_protect = 1016 if (pnp_resource_enabled(p)) {
945 (p->flags & IORESOURCE_MEM_WRITEABLE) ? 1017 memory32->write_protect = p->flags & IORESOURCE_MEM_WRITEABLE ?
946 ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY; 1018 ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
947 memory32->minimum = p->start; 1019 memory32->minimum = p->start;
948 memory32->maximum = p->end; 1020 memory32->maximum = p->end;
949 memory32->alignment = 0; 1021 memory32->alignment = 0;
950 memory32->address_length = p->end - p->start + 1; 1022 memory32->address_length = p->end - p->start + 1;
1023 } else {
1024 memory32->minimum = 0;
1025 memory32->alignment = 0;
1026 }
951 1027
952 dev_dbg(&dev->dev, " encode mem32 %#llx-%#llx write_protect %#x\n", 1028 dev_dbg(&dev->dev, " encode mem32 %#x-%#x write_protect %#x\n",
953 (unsigned long long) p->start, (unsigned long long) p->end, 1029 memory32->minimum,
1030 memory32->minimum + memory32->address_length - 1,
954 memory32->write_protect); 1031 memory32->write_protect);
955} 1032}
956 1033
@@ -960,15 +1037,20 @@ static void pnpacpi_encode_fixed_mem32(struct pnp_dev *dev,
960{ 1037{
961 struct acpi_resource_fixed_memory32 *fixed_memory32 = &resource->data.fixed_memory32; 1038 struct acpi_resource_fixed_memory32 *fixed_memory32 = &resource->data.fixed_memory32;
962 1039
963 fixed_memory32->write_protect = 1040 if (pnp_resource_enabled(p)) {
964 (p->flags & IORESOURCE_MEM_WRITEABLE) ? 1041 fixed_memory32->write_protect =
965 ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY; 1042 p->flags & IORESOURCE_MEM_WRITEABLE ?
966 fixed_memory32->address = p->start; 1043 ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
967 fixed_memory32->address_length = p->end - p->start + 1; 1044 fixed_memory32->address = p->start;
1045 fixed_memory32->address_length = p->end - p->start + 1;
1046 } else {
1047 fixed_memory32->address = 0;
1048 fixed_memory32->address_length = 0;
1049 }
968 1050
969 dev_dbg(&dev->dev, " encode fixed_mem32 %#llx-%#llx " 1051 dev_dbg(&dev->dev, " encode fixed_mem32 %#x-%#x write_protect %#x\n",
970 "write_protect %#x\n", 1052 fixed_memory32->address,
971 (unsigned long long) p->start, (unsigned long long) p->end, 1053 fixed_memory32->address + fixed_memory32->address_length - 1,
972 fixed_memory32->write_protect); 1054 fixed_memory32->write_protect);
973} 1055}
974 1056
diff --git a/drivers/pnp/pnpbios/rsparser.c b/drivers/pnp/pnpbios/rsparser.c
index 5ff9a4c0447e..ca567671379e 100644
--- a/drivers/pnp/pnpbios/rsparser.c
+++ b/drivers/pnp/pnpbios/rsparser.c
@@ -216,137 +216,116 @@ len_err:
216 216
217static __init void pnpbios_parse_mem_option(struct pnp_dev *dev, 217static __init void pnpbios_parse_mem_option(struct pnp_dev *dev,
218 unsigned char *p, int size, 218 unsigned char *p, int size,
219 struct pnp_option *option) 219 unsigned int option_flags)
220{ 220{
221 struct pnp_mem *mem; 221 resource_size_t min, max, align, len;
222 222 unsigned char flags;
223 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL); 223
224 if (!mem) 224 min = ((p[5] << 8) | p[4]) << 8;
225 return; 225 max = ((p[7] << 8) | p[6]) << 8;
226 mem->min = ((p[5] << 8) | p[4]) << 8; 226 align = (p[9] << 8) | p[8];
227 mem->max = ((p[7] << 8) | p[6]) << 8; 227 len = ((p[11] << 8) | p[10]) << 8;
228 mem->align = (p[9] << 8) | p[8]; 228 flags = p[3];
229 mem->size = ((p[11] << 8) | p[10]) << 8; 229 pnp_register_mem_resource(dev, option_flags, min, max, align, len,
230 mem->flags = p[3]; 230 flags);
231 pnp_register_mem_resource(dev, option, mem);
232} 231}
233 232
234static __init void pnpbios_parse_mem32_option(struct pnp_dev *dev, 233static __init void pnpbios_parse_mem32_option(struct pnp_dev *dev,
235 unsigned char *p, int size, 234 unsigned char *p, int size,
236 struct pnp_option *option) 235 unsigned int option_flags)
237{ 236{
238 struct pnp_mem *mem; 237 resource_size_t min, max, align, len;
239 238 unsigned char flags;
240 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL); 239
241 if (!mem) 240 min = (p[7] << 24) | (p[6] << 16) | (p[5] << 8) | p[4];
242 return; 241 max = (p[11] << 24) | (p[10] << 16) | (p[9] << 8) | p[8];
243 mem->min = (p[7] << 24) | (p[6] << 16) | (p[5] << 8) | p[4]; 242 align = (p[15] << 24) | (p[14] << 16) | (p[13] << 8) | p[12];
244 mem->max = (p[11] << 24) | (p[10] << 16) | (p[9] << 8) | p[8]; 243 len = (p[19] << 24) | (p[18] << 16) | (p[17] << 8) | p[16];
245 mem->align = (p[15] << 24) | (p[14] << 16) | (p[13] << 8) | p[12]; 244 flags = p[3];
246 mem->size = (p[19] << 24) | (p[18] << 16) | (p[17] << 8) | p[16]; 245 pnp_register_mem_resource(dev, option_flags, min, max, align, len,
247 mem->flags = p[3]; 246 flags);
248 pnp_register_mem_resource(dev, option, mem);
249} 247}
250 248
251static __init void pnpbios_parse_fixed_mem32_option(struct pnp_dev *dev, 249static __init void pnpbios_parse_fixed_mem32_option(struct pnp_dev *dev,
252 unsigned char *p, int size, 250 unsigned char *p, int size,
253 struct pnp_option *option) 251 unsigned int option_flags)
254{ 252{
255 struct pnp_mem *mem; 253 resource_size_t base, len;
256 254 unsigned char flags;
257 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL); 255
258 if (!mem) 256 base = (p[7] << 24) | (p[6] << 16) | (p[5] << 8) | p[4];
259 return; 257 len = (p[11] << 24) | (p[10] << 16) | (p[9] << 8) | p[8];
260 mem->min = mem->max = (p[7] << 24) | (p[6] << 16) | (p[5] << 8) | p[4]; 258 flags = p[3];
261 mem->size = (p[11] << 24) | (p[10] << 16) | (p[9] << 8) | p[8]; 259 pnp_register_mem_resource(dev, option_flags, base, base, 0, len, flags);
262 mem->align = 0;
263 mem->flags = p[3];
264 pnp_register_mem_resource(dev, option, mem);
265} 260}
266 261
267static __init void pnpbios_parse_irq_option(struct pnp_dev *dev, 262static __init void pnpbios_parse_irq_option(struct pnp_dev *dev,
268 unsigned char *p, int size, 263 unsigned char *p, int size,
269 struct pnp_option *option) 264 unsigned int option_flags)
270{ 265{
271 struct pnp_irq *irq;
272 unsigned long bits; 266 unsigned long bits;
267 pnp_irq_mask_t map;
268 unsigned char flags = IORESOURCE_IRQ_HIGHEDGE;
273 269
274 irq = kzalloc(sizeof(struct pnp_irq), GFP_KERNEL);
275 if (!irq)
276 return;
277 bits = (p[2] << 8) | p[1]; 270 bits = (p[2] << 8) | p[1];
278 bitmap_copy(irq->map, &bits, 16); 271
272 bitmap_zero(map.bits, PNP_IRQ_NR);
273 bitmap_copy(map.bits, &bits, 16);
274
279 if (size > 2) 275 if (size > 2)
280 irq->flags = p[3]; 276 flags = p[3];
281 else 277
282 irq->flags = IORESOURCE_IRQ_HIGHEDGE; 278 pnp_register_irq_resource(dev, option_flags, &map, flags);
283 pnp_register_irq_resource(dev, option, irq);
284} 279}
285 280
286static __init void pnpbios_parse_dma_option(struct pnp_dev *dev, 281static __init void pnpbios_parse_dma_option(struct pnp_dev *dev,
287 unsigned char *p, int size, 282 unsigned char *p, int size,
288 struct pnp_option *option) 283 unsigned int option_flags)
289{ 284{
290 struct pnp_dma *dma; 285 pnp_register_dma_resource(dev, option_flags, p[1], p[2]);
291
292 dma = kzalloc(sizeof(struct pnp_dma), GFP_KERNEL);
293 if (!dma)
294 return;
295 dma->map = p[1];
296 dma->flags = p[2];
297 pnp_register_dma_resource(dev, option, dma);
298} 286}
299 287
300static __init void pnpbios_parse_port_option(struct pnp_dev *dev, 288static __init void pnpbios_parse_port_option(struct pnp_dev *dev,
301 unsigned char *p, int size, 289 unsigned char *p, int size,
302 struct pnp_option *option) 290 unsigned int option_flags)
303{ 291{
304 struct pnp_port *port; 292 resource_size_t min, max, align, len;
305 293 unsigned char flags;
306 port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL); 294
307 if (!port) 295 min = (p[3] << 8) | p[2];
308 return; 296 max = (p[5] << 8) | p[4];
309 port->min = (p[3] << 8) | p[2]; 297 align = p[6];
310 port->max = (p[5] << 8) | p[4]; 298 len = p[7];
311 port->align = p[6]; 299 flags = p[1] ? IORESOURCE_IO_16BIT_ADDR : 0;
312 port->size = p[7]; 300 pnp_register_port_resource(dev, option_flags, min, max, align, len,
313 port->flags = p[1] ? PNP_PORT_FLAG_16BITADDR : 0; 301 flags);
314 pnp_register_port_resource(dev, option, port);
315} 302}
316 303
317static __init void pnpbios_parse_fixed_port_option(struct pnp_dev *dev, 304static __init void pnpbios_parse_fixed_port_option(struct pnp_dev *dev,
318 unsigned char *p, int size, 305 unsigned char *p, int size,
319 struct pnp_option *option) 306 unsigned int option_flags)
320{ 307{
321 struct pnp_port *port; 308 resource_size_t base, len;
322 309
323 port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL); 310 base = (p[2] << 8) | p[1];
324 if (!port) 311 len = p[3];
325 return; 312 pnp_register_port_resource(dev, option_flags, base, base, 0, len,
326 port->min = port->max = (p[2] << 8) | p[1]; 313 IORESOURCE_IO_FIXED);
327 port->size = p[3];
328 port->align = 0;
329 port->flags = PNP_PORT_FLAG_FIXED;
330 pnp_register_port_resource(dev, option, port);
331} 314}
332 315
333static __init unsigned char * 316static __init unsigned char *
334pnpbios_parse_resource_option_data(unsigned char *p, unsigned char *end, 317pnpbios_parse_resource_option_data(unsigned char *p, unsigned char *end,
335 struct pnp_dev *dev) 318 struct pnp_dev *dev)
336{ 319{
337 unsigned int len, tag; 320 unsigned int len, tag;
338 int priority = 0; 321 int priority;
339 struct pnp_option *option, *option_independent; 322 unsigned int option_flags;
340 323
341 if (!p) 324 if (!p)
342 return NULL; 325 return NULL;
343 326
344 dev_dbg(&dev->dev, "parse resource options\n"); 327 dev_dbg(&dev->dev, "parse resource options\n");
345 328 option_flags = 0;
346 option_independent = option = pnp_register_independent_option(dev);
347 if (!option)
348 return NULL;
349
350 while ((char *)p < (char *)end) { 329 while ((char *)p < (char *)end) {
351 330
352 /* determine the type of tag */ 331 /* determine the type of tag */
@@ -363,37 +342,38 @@ pnpbios_parse_resource_option_data(unsigned char *p, unsigned char *end,
363 case LARGE_TAG_MEM: 342 case LARGE_TAG_MEM:
364 if (len != 9) 343 if (len != 9)
365 goto len_err; 344 goto len_err;
366 pnpbios_parse_mem_option(dev, p, len, option); 345 pnpbios_parse_mem_option(dev, p, len, option_flags);
367 break; 346 break;
368 347
369 case LARGE_TAG_MEM32: 348 case LARGE_TAG_MEM32:
370 if (len != 17) 349 if (len != 17)
371 goto len_err; 350 goto len_err;
372 pnpbios_parse_mem32_option(dev, p, len, option); 351 pnpbios_parse_mem32_option(dev, p, len, option_flags);
373 break; 352 break;
374 353
375 case LARGE_TAG_FIXEDMEM32: 354 case LARGE_TAG_FIXEDMEM32:
376 if (len != 9) 355 if (len != 9)
377 goto len_err; 356 goto len_err;
378 pnpbios_parse_fixed_mem32_option(dev, p, len, option); 357 pnpbios_parse_fixed_mem32_option(dev, p, len,
358 option_flags);
379 break; 359 break;
380 360
381 case SMALL_TAG_IRQ: 361 case SMALL_TAG_IRQ:
382 if (len < 2 || len > 3) 362 if (len < 2 || len > 3)
383 goto len_err; 363 goto len_err;
384 pnpbios_parse_irq_option(dev, p, len, option); 364 pnpbios_parse_irq_option(dev, p, len, option_flags);
385 break; 365 break;
386 366
387 case SMALL_TAG_DMA: 367 case SMALL_TAG_DMA:
388 if (len != 2) 368 if (len != 2)
389 goto len_err; 369 goto len_err;
390 pnpbios_parse_dma_option(dev, p, len, option); 370 pnpbios_parse_dma_option(dev, p, len, option_flags);
391 break; 371 break;
392 372
393 case SMALL_TAG_PORT: 373 case SMALL_TAG_PORT:
394 if (len != 7) 374 if (len != 7)
395 goto len_err; 375 goto len_err;
396 pnpbios_parse_port_option(dev, p, len, option); 376 pnpbios_parse_port_option(dev, p, len, option_flags);
397 break; 377 break;
398 378
399 case SMALL_TAG_VENDOR: 379 case SMALL_TAG_VENDOR:
@@ -403,28 +383,23 @@ pnpbios_parse_resource_option_data(unsigned char *p, unsigned char *end,
403 case SMALL_TAG_FIXEDPORT: 383 case SMALL_TAG_FIXEDPORT:
404 if (len != 3) 384 if (len != 3)
405 goto len_err; 385 goto len_err;
406 pnpbios_parse_fixed_port_option(dev, p, len, option); 386 pnpbios_parse_fixed_port_option(dev, p, len,
387 option_flags);
407 break; 388 break;
408 389
409 case SMALL_TAG_STARTDEP: 390 case SMALL_TAG_STARTDEP:
410 if (len > 1) 391 if (len > 1)
411 goto len_err; 392 goto len_err;
412 priority = 0x100 | PNP_RES_PRIORITY_ACCEPTABLE; 393 priority = PNP_RES_PRIORITY_ACCEPTABLE;
413 if (len > 0) 394 if (len > 0)
414 priority = 0x100 | p[1]; 395 priority = p[1];
415 option = pnp_register_dependent_option(dev, priority); 396 option_flags = pnp_new_dependent_set(dev, priority);
416 if (!option)
417 return NULL;
418 break; 397 break;
419 398
420 case SMALL_TAG_ENDDEP: 399 case SMALL_TAG_ENDDEP:
421 if (len != 0) 400 if (len != 0)
422 goto len_err; 401 goto len_err;
423 if (option_independent == option) 402 option_flags = 0;
424 dev_warn(&dev->dev, "missing "
425 "SMALL_TAG_STARTDEP tag\n");
426 option = option_independent;
427 dev_dbg(&dev->dev, "end dependent options\n");
428 break; 403 break;
429 404
430 case SMALL_TAG_END: 405 case SMALL_TAG_END:
@@ -526,8 +501,16 @@ len_err:
526static void pnpbios_encode_mem(struct pnp_dev *dev, unsigned char *p, 501static void pnpbios_encode_mem(struct pnp_dev *dev, unsigned char *p,
527 struct resource *res) 502 struct resource *res)
528{ 503{
529 unsigned long base = res->start; 504 unsigned long base;
530 unsigned long len = res->end - res->start + 1; 505 unsigned long len;
506
507 if (pnp_resource_enabled(res)) {
508 base = res->start;
509 len = res->end - res->start + 1;
510 } else {
511 base = 0;
512 len = 0;
513 }
531 514
532 p[4] = (base >> 8) & 0xff; 515 p[4] = (base >> 8) & 0xff;
533 p[5] = ((base >> 8) >> 8) & 0xff; 516 p[5] = ((base >> 8) >> 8) & 0xff;
@@ -536,15 +519,22 @@ static void pnpbios_encode_mem(struct pnp_dev *dev, unsigned char *p,
536 p[10] = (len >> 8) & 0xff; 519 p[10] = (len >> 8) & 0xff;
537 p[11] = ((len >> 8) >> 8) & 0xff; 520 p[11] = ((len >> 8) >> 8) & 0xff;
538 521
539 dev_dbg(&dev->dev, " encode mem %#llx-%#llx\n", 522 dev_dbg(&dev->dev, " encode mem %#lx-%#lx\n", base, base + len - 1);
540 (unsigned long long) res->start, (unsigned long long) res->end);
541} 523}
542 524
543static void pnpbios_encode_mem32(struct pnp_dev *dev, unsigned char *p, 525static void pnpbios_encode_mem32(struct pnp_dev *dev, unsigned char *p,
544 struct resource *res) 526 struct resource *res)
545{ 527{
546 unsigned long base = res->start; 528 unsigned long base;
547 unsigned long len = res->end - res->start + 1; 529 unsigned long len;
530
531 if (pnp_resource_enabled(res)) {
532 base = res->start;
533 len = res->end - res->start + 1;
534 } else {
535 base = 0;
536 len = 0;
537 }
548 538
549 p[4] = base & 0xff; 539 p[4] = base & 0xff;
550 p[5] = (base >> 8) & 0xff; 540 p[5] = (base >> 8) & 0xff;
@@ -559,15 +549,22 @@ static void pnpbios_encode_mem32(struct pnp_dev *dev, unsigned char *p,
559 p[18] = (len >> 16) & 0xff; 549 p[18] = (len >> 16) & 0xff;
560 p[19] = (len >> 24) & 0xff; 550 p[19] = (len >> 24) & 0xff;
561 551
562 dev_dbg(&dev->dev, " encode mem32 %#llx-%#llx\n", 552 dev_dbg(&dev->dev, " encode mem32 %#lx-%#lx\n", base, base + len - 1);
563 (unsigned long long) res->start, (unsigned long long) res->end);
564} 553}
565 554
566static void pnpbios_encode_fixed_mem32(struct pnp_dev *dev, unsigned char *p, 555static void pnpbios_encode_fixed_mem32(struct pnp_dev *dev, unsigned char *p,
567 struct resource *res) 556 struct resource *res)
568{ 557{
569 unsigned long base = res->start; 558 unsigned long base;
570 unsigned long len = res->end - res->start + 1; 559 unsigned long len;
560
561 if (pnp_resource_enabled(res)) {
562 base = res->start;
563 len = res->end - res->start + 1;
564 } else {
565 base = 0;
566 len = 0;
567 }
571 568
572 p[4] = base & 0xff; 569 p[4] = base & 0xff;
573 p[5] = (base >> 8) & 0xff; 570 p[5] = (base >> 8) & 0xff;
@@ -578,40 +575,54 @@ static void pnpbios_encode_fixed_mem32(struct pnp_dev *dev, unsigned char *p,
578 p[10] = (len >> 16) & 0xff; 575 p[10] = (len >> 16) & 0xff;
579 p[11] = (len >> 24) & 0xff; 576 p[11] = (len >> 24) & 0xff;
580 577
581 dev_dbg(&dev->dev, " encode fixed_mem32 %#llx-%#llx\n", 578 dev_dbg(&dev->dev, " encode fixed_mem32 %#lx-%#lx\n", base,
582 (unsigned long long) res->start, (unsigned long long) res->end); 579 base + len - 1);
583} 580}
584 581
585static void pnpbios_encode_irq(struct pnp_dev *dev, unsigned char *p, 582static void pnpbios_encode_irq(struct pnp_dev *dev, unsigned char *p,
586 struct resource *res) 583 struct resource *res)
587{ 584{
588 unsigned long map = 0; 585 unsigned long map;
586
587 if (pnp_resource_enabled(res))
588 map = 1 << res->start;
589 else
590 map = 0;
589 591
590 map = 1 << res->start;
591 p[1] = map & 0xff; 592 p[1] = map & 0xff;
592 p[2] = (map >> 8) & 0xff; 593 p[2] = (map >> 8) & 0xff;
593 594
594 dev_dbg(&dev->dev, " encode irq %llu\n", 595 dev_dbg(&dev->dev, " encode irq mask %#lx\n", map);
595 (unsigned long long)res->start);
596} 596}
597 597
598static void pnpbios_encode_dma(struct pnp_dev *dev, unsigned char *p, 598static void pnpbios_encode_dma(struct pnp_dev *dev, unsigned char *p,
599 struct resource *res) 599 struct resource *res)
600{ 600{
601 unsigned long map = 0; 601 unsigned long map;
602
603 if (pnp_resource_enabled(res))
604 map = 1 << res->start;
605 else
606 map = 0;
602 607
603 map = 1 << res->start;
604 p[1] = map & 0xff; 608 p[1] = map & 0xff;
605 609
606 dev_dbg(&dev->dev, " encode dma %llu\n", 610 dev_dbg(&dev->dev, " encode dma mask %#lx\n", map);
607 (unsigned long long)res->start);
608} 611}
609 612
610static void pnpbios_encode_port(struct pnp_dev *dev, unsigned char *p, 613static void pnpbios_encode_port(struct pnp_dev *dev, unsigned char *p,
611 struct resource *res) 614 struct resource *res)
612{ 615{
613 unsigned long base = res->start; 616 unsigned long base;
614 unsigned long len = res->end - res->start + 1; 617 unsigned long len;
618
619 if (pnp_resource_enabled(res)) {
620 base = res->start;
621 len = res->end - res->start + 1;
622 } else {
623 base = 0;
624 len = 0;
625 }
615 626
616 p[2] = base & 0xff; 627 p[2] = base & 0xff;
617 p[3] = (base >> 8) & 0xff; 628 p[3] = (base >> 8) & 0xff;
@@ -619,8 +630,7 @@ static void pnpbios_encode_port(struct pnp_dev *dev, unsigned char *p,
619 p[5] = (base >> 8) & 0xff; 630 p[5] = (base >> 8) & 0xff;
620 p[7] = len & 0xff; 631 p[7] = len & 0xff;
621 632
622 dev_dbg(&dev->dev, " encode io %#llx-%#llx\n", 633 dev_dbg(&dev->dev, " encode io %#lx-%#lx\n", base, base + len - 1);
623 (unsigned long long) res->start, (unsigned long long) res->end);
624} 634}
625 635
626static void pnpbios_encode_fixed_port(struct pnp_dev *dev, unsigned char *p, 636static void pnpbios_encode_fixed_port(struct pnp_dev *dev, unsigned char *p,
@@ -629,12 +639,20 @@ static void pnpbios_encode_fixed_port(struct pnp_dev *dev, unsigned char *p,
629 unsigned long base = res->start; 639 unsigned long base = res->start;
630 unsigned long len = res->end - res->start + 1; 640 unsigned long len = res->end - res->start + 1;
631 641
642 if (pnp_resource_enabled(res)) {
643 base = res->start;
644 len = res->end - res->start + 1;
645 } else {
646 base = 0;
647 len = 0;
648 }
649
632 p[1] = base & 0xff; 650 p[1] = base & 0xff;
633 p[2] = (base >> 8) & 0xff; 651 p[2] = (base >> 8) & 0xff;
634 p[3] = len & 0xff; 652 p[3] = len & 0xff;
635 653
636 dev_dbg(&dev->dev, " encode fixed_io %#llx-%#llx\n", 654 dev_dbg(&dev->dev, " encode fixed_io %#lx-%#lx\n", base,
637 (unsigned long long) res->start, (unsigned long long) res->end); 655 base + len - 1);
638} 656}
639 657
640static unsigned char *pnpbios_encode_allocated_resource_data(struct pnp_dev 658static unsigned char *pnpbios_encode_allocated_resource_data(struct pnp_dev
diff --git a/drivers/pnp/quirks.c b/drivers/pnp/quirks.c
index 1ff3bb585ab2..55f55ed72dc7 100644
--- a/drivers/pnp/quirks.c
+++ b/drivers/pnp/quirks.c
@@ -5,6 +5,8 @@
5 * when building up the resource structure for the first time. 5 * when building up the resource structure for the first time.
6 * 6 *
7 * Copyright (c) 2000 Peter Denison <peterd@pnd-pc.demon.co.uk> 7 * Copyright (c) 2000 Peter Denison <peterd@pnd-pc.demon.co.uk>
8 * Copyright (C) 2008 Hewlett-Packard Development Company, L.P.
9 * Bjorn Helgaas <bjorn.helgaas@hp.com>
8 * 10 *
9 * Heavily based on PCI quirks handling which is 11 * Heavily based on PCI quirks handling which is
10 * 12 *
@@ -20,203 +22,207 @@
20#include <linux/kallsyms.h> 22#include <linux/kallsyms.h>
21#include "base.h" 23#include "base.h"
22 24
25static void quirk_awe32_add_ports(struct pnp_dev *dev,
26 struct pnp_option *option,
27 unsigned int offset)
28{
29 struct pnp_option *new_option;
30
31 new_option = kmalloc(sizeof(struct pnp_option), GFP_KERNEL);
32 if (!new_option) {
33 dev_err(&dev->dev, "couldn't add ioport region to option set "
34 "%d\n", pnp_option_set(option));
35 return;
36 }
37
38 *new_option = *option;
39 new_option->u.port.min += offset;
40 new_option->u.port.max += offset;
41 list_add(&new_option->list, &option->list);
42
43 dev_info(&dev->dev, "added ioport region %#llx-%#llx to set %d\n",
44 (unsigned long long) new_option->u.port.min,
45 (unsigned long long) new_option->u.port.max,
46 pnp_option_set(option));
47}
48
23static void quirk_awe32_resources(struct pnp_dev *dev) 49static void quirk_awe32_resources(struct pnp_dev *dev)
24{ 50{
25 struct pnp_port *port, *port2, *port3; 51 struct pnp_option *option;
26 struct pnp_option *res = dev->dependent; 52 unsigned int set = ~0;
27 53
28 /* 54 /*
29 * Unfortunately the isapnp_add_port_resource is too tightly bound 55 * Add two extra ioport regions (at offset 0x400 and 0x800 from the
30 * into the PnP discovery sequence, and cannot be used. Link in the 56 * one given) to every dependent option set.
31 * two extra ports (at offset 0x400 and 0x800 from the one given) by
32 * hand.
33 */ 57 */
34 for (; res; res = res->next) { 58 list_for_each_entry(option, &dev->options, list) {
35 port2 = pnp_alloc(sizeof(struct pnp_port)); 59 if (pnp_option_is_dependent(option) &&
36 if (!port2) 60 pnp_option_set(option) != set) {
37 return; 61 set = pnp_option_set(option);
38 port3 = pnp_alloc(sizeof(struct pnp_port)); 62 quirk_awe32_add_ports(dev, option, 0x800);
39 if (!port3) { 63 quirk_awe32_add_ports(dev, option, 0x400);
40 kfree(port2);
41 return;
42 } 64 }
43 port = res->port;
44 memcpy(port2, port, sizeof(struct pnp_port));
45 memcpy(port3, port, sizeof(struct pnp_port));
46 port->next = port2;
47 port2->next = port3;
48 port2->min += 0x400;
49 port2->max += 0x400;
50 port3->min += 0x800;
51 port3->max += 0x800;
52 dev_info(&dev->dev,
53 "AWE32 quirk - added ioports 0x%lx and 0x%lx\n",
54 (unsigned long)port2->min,
55 (unsigned long)port3->min);
56 } 65 }
57} 66}
58 67
59static void quirk_cmi8330_resources(struct pnp_dev *dev) 68static void quirk_cmi8330_resources(struct pnp_dev *dev)
60{ 69{
61 struct pnp_option *res = dev->dependent; 70 struct pnp_option *option;
62 unsigned long tmp; 71 struct pnp_irq *irq;
63 72 struct pnp_dma *dma;
64 for (; res; res = res->next) {
65
66 struct pnp_irq *irq;
67 struct pnp_dma *dma;
68 73
69 for (irq = res->irq; irq; irq = irq->next) { // Valid irqs are 5, 7, 10 74 list_for_each_entry(option, &dev->options, list) {
70 tmp = 0x04A0; 75 if (!pnp_option_is_dependent(option))
71 bitmap_copy(irq->map, &tmp, 16); // 0000 0100 1010 0000 76 continue;
72 }
73 77
74 for (dma = res->dma; dma; dma = dma->next) // Valid 8bit dma channels are 1,3 78 if (option->type == IORESOURCE_IRQ) {
79 irq = &option->u.irq;
80 bitmap_zero(irq->map.bits, PNP_IRQ_NR);
81 __set_bit(5, irq->map.bits);
82 __set_bit(7, irq->map.bits);
83 __set_bit(10, irq->map.bits);
84 dev_info(&dev->dev, "set possible IRQs in "
85 "option set %d to 5, 7, 10\n",
86 pnp_option_set(option));
87 } else if (option->type == IORESOURCE_DMA) {
88 dma = &option->u.dma;
75 if ((dma->flags & IORESOURCE_DMA_TYPE_MASK) == 89 if ((dma->flags & IORESOURCE_DMA_TYPE_MASK) ==
76 IORESOURCE_DMA_8BIT) 90 IORESOURCE_DMA_8BIT &&
77 dma->map = 0x000A; 91 dma->map != 0x0A) {
92 dev_info(&dev->dev, "changing possible "
93 "DMA channel mask in option set %d "
94 "from %#02x to 0x0A (1, 3)\n",
95 pnp_option_set(option), dma->map);
96 dma->map = 0x0A;
97 }
98 }
78 } 99 }
79 dev_info(&dev->dev, "CMI8330 quirk - forced possible IRQs to 5, 7, 10 "
80 "and DMA channels to 1, 3\n");
81} 100}
82 101
83static void quirk_sb16audio_resources(struct pnp_dev *dev) 102static void quirk_sb16audio_resources(struct pnp_dev *dev)
84{ 103{
104 struct pnp_option *option;
105 unsigned int prev_option_flags = ~0, n = 0;
85 struct pnp_port *port; 106 struct pnp_port *port;
86 struct pnp_option *res = dev->dependent;
87 int changed = 0;
88 107
89 /* 108 /*
90 * The default range on the mpu port for these devices is 0x388-0x388. 109 * The default range on the OPL port for these devices is 0x388-0x388.
91 * Here we increase that range so that two such cards can be 110 * Here we increase that range so that two such cards can be
92 * auto-configured. 111 * auto-configured.
93 */ 112 */
113 list_for_each_entry(option, &dev->options, list) {
114 if (prev_option_flags != option->flags) {
115 prev_option_flags = option->flags;
116 n = 0;
117 }
94 118
95 for (; res; res = res->next) { 119 if (pnp_option_is_dependent(option) &&
96 port = res->port; 120 option->type == IORESOURCE_IO) {
97 if (!port) 121 n++;
98 continue; 122 port = &option->u.port;
99 port = port->next; 123 if (n == 3 && port->min == port->max) {
100 if (!port) 124 port->max += 0x70;
101 continue; 125 dev_info(&dev->dev, "increased option port "
102 port = port->next; 126 "range from %#llx-%#llx to "
103 if (!port) 127 "%#llx-%#llx\n",
104 continue; 128 (unsigned long long) port->min,
105 if (port->min != port->max) 129 (unsigned long long) port->min,
106 continue; 130 (unsigned long long) port->min,
107 port->max += 0x70; 131 (unsigned long long) port->max);
108 changed = 1; 132 }
133 }
109 } 134 }
110 if (changed)
111 dev_info(&dev->dev, "SB audio device quirk - increased port range\n");
112} 135}
113 136
114static struct pnp_option *quirk_isapnp_mpu_options(struct pnp_dev *dev) 137static struct pnp_option *pnp_clone_dependent_set(struct pnp_dev *dev,
138 unsigned int set)
115{ 139{
116 struct pnp_option *head = NULL; 140 struct pnp_option *tail = NULL, *first_new_option = NULL;
117 struct pnp_option *prev = NULL; 141 struct pnp_option *option, *new_option;
118 struct pnp_option *res; 142 unsigned int flags;
119
120 /*
121 * Build a functional IRQ-less variant of each MPU option.
122 */
123
124 for (res = dev->dependent; res; res = res->next) {
125 struct pnp_option *curr;
126 struct pnp_port *port;
127 struct pnp_port *copy;
128 143
129 port = res->port; 144 list_for_each_entry(option, &dev->options, list) {
130 if (!port || !res->irq) 145 if (pnp_option_is_dependent(option))
131 continue; 146 tail = option;
147 }
148 if (!tail) {
149 dev_err(&dev->dev, "no dependent option sets\n");
150 return NULL;
151 }
132 152
133 copy = pnp_alloc(sizeof *copy); 153 flags = pnp_new_dependent_set(dev, PNP_RES_PRIORITY_FUNCTIONAL);
134 if (!copy) 154 list_for_each_entry(option, &dev->options, list) {
135 break; 155 if (pnp_option_is_dependent(option) &&
156 pnp_option_set(option) == set) {
157 new_option = kmalloc(sizeof(struct pnp_option),
158 GFP_KERNEL);
159 if (!new_option) {
160 dev_err(&dev->dev, "couldn't clone dependent "
161 "set %d\n", set);
162 return NULL;
163 }
136 164
137 copy->min = port->min; 165 *new_option = *option;
138 copy->max = port->max; 166 new_option->flags = flags;
139 copy->align = port->align; 167 if (!first_new_option)
140 copy->size = port->size; 168 first_new_option = new_option;
141 copy->flags = port->flags;
142 169
143 curr = pnp_build_option(PNP_RES_PRIORITY_FUNCTIONAL); 170 list_add(&new_option->list, &tail->list);
144 if (!curr) { 171 tail = new_option;
145 kfree(copy);
146 break;
147 } 172 }
148 curr->port = copy;
149
150 if (prev)
151 prev->next = curr;
152 else
153 head = curr;
154 prev = curr;
155 } 173 }
156 if (head)
157 dev_info(&dev->dev, "adding IRQ-less MPU options\n");
158 174
159 return head; 175 return first_new_option;
160} 176}
161 177
162static void quirk_ad1815_mpu_resources(struct pnp_dev *dev) 178
179static void quirk_add_irq_optional_dependent_sets(struct pnp_dev *dev)
163{ 180{
164 struct pnp_option *res; 181 struct pnp_option *new_option;
182 unsigned int num_sets, i, set;
165 struct pnp_irq *irq; 183 struct pnp_irq *irq;
166 184
167 /* 185 num_sets = dev->num_dependent_sets;
168 * Distribute the independent IRQ over the dependent options 186 for (i = 0; i < num_sets; i++) {
169 */ 187 new_option = pnp_clone_dependent_set(dev, i);
170 188 if (!new_option)
171 res = dev->independent; 189 return;
172 if (!res)
173 return;
174
175 irq = res->irq;
176 if (!irq || irq->next)
177 return;
178
179 res = dev->dependent;
180 if (!res)
181 return;
182
183 while (1) {
184 struct pnp_irq *copy;
185
186 copy = pnp_alloc(sizeof *copy);
187 if (!copy)
188 break;
189
190 memcpy(copy->map, irq->map, sizeof copy->map);
191 copy->flags = irq->flags;
192 190
193 copy->next = res->irq; /* Yes, this is NULL */ 191 set = pnp_option_set(new_option);
194 res->irq = copy; 192 while (new_option && pnp_option_set(new_option) == set) {
193 if (new_option->type == IORESOURCE_IRQ) {
194 irq = &new_option->u.irq;
195 irq->flags |= IORESOURCE_IRQ_OPTIONAL;
196 }
197 dbg_pnp_show_option(dev, new_option);
198 new_option = list_entry(new_option->list.next,
199 struct pnp_option, list);
200 }
195 201
196 if (!res->next) 202 dev_info(&dev->dev, "added dependent option set %d (same as "
197 break; 203 "set %d except IRQ optional)\n", set, i);
198 res = res->next;
199 } 204 }
200 kfree(irq);
201
202 res->next = quirk_isapnp_mpu_options(dev);
203
204 res = dev->independent;
205 res->irq = NULL;
206} 205}
207 206
208static void quirk_isapnp_mpu_resources(struct pnp_dev *dev) 207static void quirk_ad1815_mpu_resources(struct pnp_dev *dev)
209{ 208{
210 struct pnp_option *res; 209 struct pnp_option *option;
210 struct pnp_irq *irq = NULL;
211 unsigned int independent_irqs = 0;
212
213 list_for_each_entry(option, &dev->options, list) {
214 if (option->type == IORESOURCE_IRQ &&
215 !pnp_option_is_dependent(option)) {
216 independent_irqs++;
217 irq = &option->u.irq;
218 }
219 }
211 220
212 res = dev->dependent; 221 if (independent_irqs != 1)
213 if (!res)
214 return; 222 return;
215 223
216 while (res->next) 224 irq->flags |= IORESOURCE_IRQ_OPTIONAL;
217 res = res->next; 225 dev_info(&dev->dev, "made independent IRQ optional\n");
218
219 res->next = quirk_isapnp_mpu_options(dev);
220} 226}
221 227
222#include <linux/pci.h> 228#include <linux/pci.h>
@@ -248,8 +254,7 @@ static void quirk_system_pci_resources(struct pnp_dev *dev)
248 for (j = 0; 254 for (j = 0;
249 (res = pnp_get_resource(dev, IORESOURCE_MEM, j)); 255 (res = pnp_get_resource(dev, IORESOURCE_MEM, j));
250 j++) { 256 j++) {
251 if (res->flags & IORESOURCE_UNSET || 257 if (res->start == 0 && res->end == 0)
252 (res->start == 0 && res->end == 0))
253 continue; 258 continue;
254 259
255 pnp_start = res->start; 260 pnp_start = res->start;
@@ -312,10 +317,10 @@ static struct pnp_fixup pnp_fixups[] = {
312 {"CTL0043", quirk_sb16audio_resources}, 317 {"CTL0043", quirk_sb16audio_resources},
313 {"CTL0044", quirk_sb16audio_resources}, 318 {"CTL0044", quirk_sb16audio_resources},
314 {"CTL0045", quirk_sb16audio_resources}, 319 {"CTL0045", quirk_sb16audio_resources},
315 /* Add IRQ-less MPU options */ 320 /* Add IRQ-optional MPU options */
316 {"ADS7151", quirk_ad1815_mpu_resources}, 321 {"ADS7151", quirk_ad1815_mpu_resources},
317 {"ADS7181", quirk_isapnp_mpu_resources}, 322 {"ADS7181", quirk_add_irq_optional_dependent_sets},
318 {"AZT0002", quirk_isapnp_mpu_resources}, 323 {"AZT0002", quirk_add_irq_optional_dependent_sets},
319 /* PnP resources that might overlap PCI BARs */ 324 /* PnP resources that might overlap PCI BARs */
320 {"PNP0c01", quirk_system_pci_resources}, 325 {"PNP0c01", quirk_system_pci_resources},
321 {"PNP0c02", quirk_system_pci_resources}, 326 {"PNP0c02", quirk_system_pci_resources},
diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
index 390b50096e30..4cfe3a1efdfb 100644
--- a/drivers/pnp/resource.c
+++ b/drivers/pnp/resource.c
@@ -3,6 +3,8 @@
3 * 3 *
4 * based on isapnp.c resource management (c) Jaroslav Kysela <perex@perex.cz> 4 * based on isapnp.c resource management (c) Jaroslav Kysela <perex@perex.cz>
5 * Copyright 2003 Adam Belay <ambx1@neo.rr.com> 5 * Copyright 2003 Adam Belay <ambx1@neo.rr.com>
6 * Copyright (C) 2008 Hewlett-Packard Development Company, L.P.
7 * Bjorn Helgaas <bjorn.helgaas@hp.com>
6 */ 8 */
7 9
8#include <linux/module.h> 10#include <linux/module.h>
@@ -28,201 +30,121 @@ static int pnp_reserve_mem[16] = {[0 ... 15] = -1 }; /* reserve (don't use) some
28 * option registration 30 * option registration
29 */ 31 */
30 32
31struct pnp_option *pnp_build_option(int priority) 33struct pnp_option *pnp_build_option(struct pnp_dev *dev, unsigned long type,
34 unsigned int option_flags)
32{ 35{
33 struct pnp_option *option = pnp_alloc(sizeof(struct pnp_option)); 36 struct pnp_option *option;
34 37
38 option = kzalloc(sizeof(struct pnp_option), GFP_KERNEL);
35 if (!option) 39 if (!option)
36 return NULL; 40 return NULL;
37 41
38 option->priority = priority & 0xff; 42 option->flags = option_flags;
39 /* make sure the priority is valid */ 43 option->type = type;
40 if (option->priority > PNP_RES_PRIORITY_FUNCTIONAL)
41 option->priority = PNP_RES_PRIORITY_INVALID;
42
43 return option;
44}
45
46struct pnp_option *pnp_register_independent_option(struct pnp_dev *dev)
47{
48 struct pnp_option *option;
49
50 option = pnp_build_option(PNP_RES_PRIORITY_PREFERRED);
51
52 /* this should never happen but if it does we'll try to continue */
53 if (dev->independent)
54 dev_err(&dev->dev, "independent resource already registered\n");
55 dev->independent = option;
56 44
57 dev_dbg(&dev->dev, "new independent option\n"); 45 list_add_tail(&option->list, &dev->options);
58 return option; 46 return option;
59} 47}
60 48
61struct pnp_option *pnp_register_dependent_option(struct pnp_dev *dev, 49int pnp_register_irq_resource(struct pnp_dev *dev, unsigned int option_flags,
62 int priority) 50 pnp_irq_mask_t *map, unsigned char flags)
63{ 51{
64 struct pnp_option *option; 52 struct pnp_option *option;
53 struct pnp_irq *irq;
65 54
66 option = pnp_build_option(priority); 55 option = pnp_build_option(dev, IORESOURCE_IRQ, option_flags);
67 56 if (!option)
68 if (dev->dependent) { 57 return -ENOMEM;
69 struct pnp_option *parent = dev->dependent;
70 while (parent->next)
71 parent = parent->next;
72 parent->next = option;
73 } else
74 dev->dependent = option;
75
76 dev_dbg(&dev->dev, "new dependent option (priority %#x)\n", priority);
77 return option;
78}
79
80int pnp_register_irq_resource(struct pnp_dev *dev, struct pnp_option *option,
81 struct pnp_irq *data)
82{
83 struct pnp_irq *ptr;
84#ifdef DEBUG
85 char buf[PNP_IRQ_NR]; /* hex-encoded, so this is overkill but safe */
86#endif
87 58
88 ptr = option->irq; 59 irq = &option->u.irq;
89 while (ptr && ptr->next) 60 irq->map = *map;
90 ptr = ptr->next; 61 irq->flags = flags;
91 if (ptr)
92 ptr->next = data;
93 else
94 option->irq = data;
95 62
96#ifdef CONFIG_PCI 63#ifdef CONFIG_PCI
97 { 64 {
98 int i; 65 int i;
99 66
100 for (i = 0; i < 16; i++) 67 for (i = 0; i < 16; i++)
101 if (test_bit(i, data->map)) 68 if (test_bit(i, irq->map.bits))
102 pcibios_penalize_isa_irq(i, 0); 69 pcibios_penalize_isa_irq(i, 0);
103 } 70 }
104#endif 71#endif
105 72
106#ifdef DEBUG 73 dbg_pnp_show_option(dev, option);
107 bitmap_scnprintf(buf, sizeof(buf), data->map, PNP_IRQ_NR);
108 dev_dbg(&dev->dev, " irq bitmask %s flags %#x\n", buf,
109 data->flags);
110#endif
111 return 0; 74 return 0;
112} 75}
113 76
114int pnp_register_dma_resource(struct pnp_dev *dev, struct pnp_option *option, 77int pnp_register_dma_resource(struct pnp_dev *dev, unsigned int option_flags,
115 struct pnp_dma *data) 78 unsigned char map, unsigned char flags)
116{ 79{
117 struct pnp_dma *ptr; 80 struct pnp_option *option;
118 81 struct pnp_dma *dma;
119 ptr = option->dma;
120 while (ptr && ptr->next)
121 ptr = ptr->next;
122 if (ptr)
123 ptr->next = data;
124 else
125 option->dma = data;
126
127 dev_dbg(&dev->dev, " dma bitmask %#x flags %#x\n", data->map,
128 data->flags);
129 return 0;
130}
131 82
132int pnp_register_port_resource(struct pnp_dev *dev, struct pnp_option *option, 83 option = pnp_build_option(dev, IORESOURCE_DMA, option_flags);
133 struct pnp_port *data) 84 if (!option)
134{ 85 return -ENOMEM;
135 struct pnp_port *ptr;
136
137 ptr = option->port;
138 while (ptr && ptr->next)
139 ptr = ptr->next;
140 if (ptr)
141 ptr->next = data;
142 else
143 option->port = data;
144
145 dev_dbg(&dev->dev, " io "
146 "min %#x max %#x align %d size %d flags %#x\n",
147 data->min, data->max, data->align, data->size, data->flags);
148 return 0;
149}
150 86
151int pnp_register_mem_resource(struct pnp_dev *dev, struct pnp_option *option, 87 dma = &option->u.dma;
152 struct pnp_mem *data) 88 dma->map = map;
153{ 89 dma->flags = flags;
154 struct pnp_mem *ptr; 90
155 91 dbg_pnp_show_option(dev, option);
156 ptr = option->mem;
157 while (ptr && ptr->next)
158 ptr = ptr->next;
159 if (ptr)
160 ptr->next = data;
161 else
162 option->mem = data;
163
164 dev_dbg(&dev->dev, " mem "
165 "min %#x max %#x align %d size %d flags %#x\n",
166 data->min, data->max, data->align, data->size, data->flags);
167 return 0; 92 return 0;
168} 93}
169 94
170static void pnp_free_port(struct pnp_port *port) 95int pnp_register_port_resource(struct pnp_dev *dev, unsigned int option_flags,
96 resource_size_t min, resource_size_t max,
97 resource_size_t align, resource_size_t size,
98 unsigned char flags)
171{ 99{
172 struct pnp_port *next; 100 struct pnp_option *option;
101 struct pnp_port *port;
173 102
174 while (port) { 103 option = pnp_build_option(dev, IORESOURCE_IO, option_flags);
175 next = port->next; 104 if (!option)
176 kfree(port); 105 return -ENOMEM;
177 port = next;
178 }
179}
180 106
181static void pnp_free_irq(struct pnp_irq *irq) 107 port = &option->u.port;
182{ 108 port->min = min;
183 struct pnp_irq *next; 109 port->max = max;
110 port->align = align;
111 port->size = size;
112 port->flags = flags;
184 113
185 while (irq) { 114 dbg_pnp_show_option(dev, option);
186 next = irq->next; 115 return 0;
187 kfree(irq);
188 irq = next;
189 }
190} 116}
191 117
192static void pnp_free_dma(struct pnp_dma *dma) 118int pnp_register_mem_resource(struct pnp_dev *dev, unsigned int option_flags,
119 resource_size_t min, resource_size_t max,
120 resource_size_t align, resource_size_t size,
121 unsigned char flags)
193{ 122{
194 struct pnp_dma *next; 123 struct pnp_option *option;
124 struct pnp_mem *mem;
195 125
196 while (dma) { 126 option = pnp_build_option(dev, IORESOURCE_MEM, option_flags);
197 next = dma->next; 127 if (!option)
198 kfree(dma); 128 return -ENOMEM;
199 dma = next;
200 }
201}
202 129
203static void pnp_free_mem(struct pnp_mem *mem) 130 mem = &option->u.mem;
204{ 131 mem->min = min;
205 struct pnp_mem *next; 132 mem->max = max;
133 mem->align = align;
134 mem->size = size;
135 mem->flags = flags;
206 136
207 while (mem) { 137 dbg_pnp_show_option(dev, option);
208 next = mem->next; 138 return 0;
209 kfree(mem);
210 mem = next;
211 }
212} 139}
213 140
214void pnp_free_option(struct pnp_option *option) 141void pnp_free_options(struct pnp_dev *dev)
215{ 142{
216 struct pnp_option *next; 143 struct pnp_option *option, *tmp;
217 144
218 while (option) { 145 list_for_each_entry_safe(option, tmp, &dev->options, list) {
219 next = option->next; 146 list_del(&option->list);
220 pnp_free_port(option->port);
221 pnp_free_irq(option->irq);
222 pnp_free_dma(option->dma);
223 pnp_free_mem(option->mem);
224 kfree(option); 147 kfree(option);
225 option = next;
226 } 148 }
227} 149}
228 150
@@ -237,7 +159,7 @@ void pnp_free_option(struct pnp_option *option)
237 !((*(enda) < *(startb)) || (*(endb) < *(starta))) 159 !((*(enda) < *(startb)) || (*(endb) < *(starta)))
238 160
239#define cannot_compare(flags) \ 161#define cannot_compare(flags) \
240((flags) & (IORESOURCE_UNSET | IORESOURCE_DISABLED)) 162((flags) & IORESOURCE_DISABLED)
241 163
242int pnp_check_port(struct pnp_dev *dev, struct resource *res) 164int pnp_check_port(struct pnp_dev *dev, struct resource *res)
243{ 165{
@@ -364,6 +286,61 @@ static irqreturn_t pnp_test_handler(int irq, void *dev_id)
364 return IRQ_HANDLED; 286 return IRQ_HANDLED;
365} 287}
366 288
289#ifdef CONFIG_PCI
290static int pci_dev_uses_irq(struct pnp_dev *pnp, struct pci_dev *pci,
291 unsigned int irq)
292{
293 u32 class;
294 u8 progif;
295
296 if (pci->irq == irq) {
297 dev_dbg(&pnp->dev, "device %s using irq %d\n",
298 pci_name(pci), irq);
299 return 1;
300 }
301
302 /*
303 * See pci_setup_device() and ata_pci_sff_activate_host() for
304 * similar IDE legacy detection.
305 */
306 pci_read_config_dword(pci, PCI_CLASS_REVISION, &class);
307 class >>= 8; /* discard revision ID */
308 progif = class & 0xff;
309 class >>= 8;
310
311 if (class == PCI_CLASS_STORAGE_IDE) {
312 /*
313 * Unless both channels are native-PCI mode only,
314 * treat the compatibility IRQs as busy.
315 */
316 if ((progif & 0x5) != 0x5)
317 if (pci_get_legacy_ide_irq(pci, 0) == irq ||
318 pci_get_legacy_ide_irq(pci, 1) == irq) {
319 dev_dbg(&pnp->dev, "legacy IDE device %s "
320 "using irq %d\n", pci_name(pci), irq);
321 return 1;
322 }
323 }
324
325 return 0;
326}
327#endif
328
329static int pci_uses_irq(struct pnp_dev *pnp, unsigned int irq)
330{
331#ifdef CONFIG_PCI
332 struct pci_dev *pci = NULL;
333
334 for_each_pci_dev(pci) {
335 if (pci_dev_uses_irq(pnp, pci, irq)) {
336 pci_dev_put(pci);
337 return 1;
338 }
339 }
340#endif
341 return 0;
342}
343
367int pnp_check_irq(struct pnp_dev *dev, struct resource *res) 344int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
368{ 345{
369 int i; 346 int i;
@@ -395,18 +372,9 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
395 } 372 }
396 } 373 }
397 374
398#ifdef CONFIG_PCI
399 /* check if the resource is being used by a pci device */ 375 /* check if the resource is being used by a pci device */
400 { 376 if (pci_uses_irq(dev, *irq))
401 struct pci_dev *pci = NULL; 377 return 0;
402 for_each_pci_dev(pci) {
403 if (pci->irq == *irq) {
404 pci_dev_put(pci);
405 return 0;
406 }
407 }
408 }
409#endif
410 378
411 /* check if the resource is already in use, skip if the 379 /* check if the resource is already in use, skip if the
412 * device is active because it itself may be in use */ 380 * device is active because it itself may be in use */
@@ -499,81 +467,37 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
499#endif 467#endif
500} 468}
501 469
502struct pnp_resource *pnp_get_pnp_resource(struct pnp_dev *dev, 470int pnp_resource_type(struct resource *res)
503 unsigned int type, unsigned int num)
504{ 471{
505 struct pnp_resource_table *res = dev->res; 472 return res->flags & (IORESOURCE_IO | IORESOURCE_MEM |
506 473 IORESOURCE_IRQ | IORESOURCE_DMA);
507 switch (type) {
508 case IORESOURCE_IO:
509 if (num >= PNP_MAX_PORT)
510 return NULL;
511 return &res->port[num];
512 case IORESOURCE_MEM:
513 if (num >= PNP_MAX_MEM)
514 return NULL;
515 return &res->mem[num];
516 case IORESOURCE_IRQ:
517 if (num >= PNP_MAX_IRQ)
518 return NULL;
519 return &res->irq[num];
520 case IORESOURCE_DMA:
521 if (num >= PNP_MAX_DMA)
522 return NULL;
523 return &res->dma[num];
524 }
525 return NULL;
526} 474}
527 475
528struct resource *pnp_get_resource(struct pnp_dev *dev, 476struct resource *pnp_get_resource(struct pnp_dev *dev,
529 unsigned int type, unsigned int num) 477 unsigned int type, unsigned int num)
530{ 478{
531 struct pnp_resource *pnp_res; 479 struct pnp_resource *pnp_res;
480 struct resource *res;
532 481
533 pnp_res = pnp_get_pnp_resource(dev, type, num); 482 list_for_each_entry(pnp_res, &dev->resources, list) {
534 if (pnp_res) 483 res = &pnp_res->res;
535 return &pnp_res->res; 484 if (pnp_resource_type(res) == type && num-- == 0)
536 485 return res;
486 }
537 return NULL; 487 return NULL;
538} 488}
539EXPORT_SYMBOL(pnp_get_resource); 489EXPORT_SYMBOL(pnp_get_resource);
540 490
541static struct pnp_resource *pnp_new_resource(struct pnp_dev *dev, int type) 491static struct pnp_resource *pnp_new_resource(struct pnp_dev *dev)
542{ 492{
543 struct pnp_resource *pnp_res; 493 struct pnp_resource *pnp_res;
544 int i;
545 494
546 switch (type) { 495 pnp_res = kzalloc(sizeof(struct pnp_resource), GFP_KERNEL);
547 case IORESOURCE_IO: 496 if (!pnp_res)
548 for (i = 0; i < PNP_MAX_PORT; i++) { 497 return NULL;
549 pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_IO, i); 498
550 if (pnp_res && !pnp_resource_valid(&pnp_res->res)) 499 list_add_tail(&pnp_res->list, &dev->resources);
551 return pnp_res; 500 return pnp_res;
552 }
553 break;
554 case IORESOURCE_MEM:
555 for (i = 0; i < PNP_MAX_MEM; i++) {
556 pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_MEM, i);
557 if (pnp_res && !pnp_resource_valid(&pnp_res->res))
558 return pnp_res;
559 }
560 break;
561 case IORESOURCE_IRQ:
562 for (i = 0; i < PNP_MAX_IRQ; i++) {
563 pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_IRQ, i);
564 if (pnp_res && !pnp_resource_valid(&pnp_res->res))
565 return pnp_res;
566 }
567 break;
568 case IORESOURCE_DMA:
569 for (i = 0; i < PNP_MAX_DMA; i++) {
570 pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_DMA, i);
571 if (pnp_res && !pnp_resource_valid(&pnp_res->res))
572 return pnp_res;
573 }
574 break;
575 }
576 return NULL;
577} 501}
578 502
579struct pnp_resource *pnp_add_irq_resource(struct pnp_dev *dev, int irq, 503struct pnp_resource *pnp_add_irq_resource(struct pnp_dev *dev, int irq,
@@ -581,15 +505,10 @@ struct pnp_resource *pnp_add_irq_resource(struct pnp_dev *dev, int irq,
581{ 505{
582 struct pnp_resource *pnp_res; 506 struct pnp_resource *pnp_res;
583 struct resource *res; 507 struct resource *res;
584 static unsigned char warned;
585 508
586 pnp_res = pnp_new_resource(dev, IORESOURCE_IRQ); 509 pnp_res = pnp_new_resource(dev);
587 if (!pnp_res) { 510 if (!pnp_res) {
588 if (!warned) { 511 dev_err(&dev->dev, "can't add resource for IRQ %d\n", irq);
589 dev_err(&dev->dev, "can't add resource for IRQ %d\n",
590 irq);
591 warned = 1;
592 }
593 return NULL; 512 return NULL;
594 } 513 }
595 514
@@ -607,15 +526,10 @@ struct pnp_resource *pnp_add_dma_resource(struct pnp_dev *dev, int dma,
607{ 526{
608 struct pnp_resource *pnp_res; 527 struct pnp_resource *pnp_res;
609 struct resource *res; 528 struct resource *res;
610 static unsigned char warned;
611 529
612 pnp_res = pnp_new_resource(dev, IORESOURCE_DMA); 530 pnp_res = pnp_new_resource(dev);
613 if (!pnp_res) { 531 if (!pnp_res) {
614 if (!warned) { 532 dev_err(&dev->dev, "can't add resource for DMA %d\n", dma);
615 dev_err(&dev->dev, "can't add resource for DMA %d\n",
616 dma);
617 warned = 1;
618 }
619 return NULL; 533 return NULL;
620 } 534 }
621 535
@@ -634,16 +548,12 @@ struct pnp_resource *pnp_add_io_resource(struct pnp_dev *dev,
634{ 548{
635 struct pnp_resource *pnp_res; 549 struct pnp_resource *pnp_res;
636 struct resource *res; 550 struct resource *res;
637 static unsigned char warned;
638 551
639 pnp_res = pnp_new_resource(dev, IORESOURCE_IO); 552 pnp_res = pnp_new_resource(dev);
640 if (!pnp_res) { 553 if (!pnp_res) {
641 if (!warned) { 554 dev_err(&dev->dev, "can't add resource for IO %#llx-%#llx\n",
642 dev_err(&dev->dev, "can't add resource for IO " 555 (unsigned long long) start,
643 "%#llx-%#llx\n",(unsigned long long) start, 556 (unsigned long long) end);
644 (unsigned long long) end);
645 warned = 1;
646 }
647 return NULL; 557 return NULL;
648 } 558 }
649 559
@@ -663,16 +573,12 @@ struct pnp_resource *pnp_add_mem_resource(struct pnp_dev *dev,
663{ 573{
664 struct pnp_resource *pnp_res; 574 struct pnp_resource *pnp_res;
665 struct resource *res; 575 struct resource *res;
666 static unsigned char warned;
667 576
668 pnp_res = pnp_new_resource(dev, IORESOURCE_MEM); 577 pnp_res = pnp_new_resource(dev);
669 if (!pnp_res) { 578 if (!pnp_res) {
670 if (!warned) { 579 dev_err(&dev->dev, "can't add resource for MEM %#llx-%#llx\n",
671 dev_err(&dev->dev, "can't add resource for MEM " 580 (unsigned long long) start,
672 "%#llx-%#llx\n",(unsigned long long) start, 581 (unsigned long long) end);
673 (unsigned long long) end);
674 warned = 1;
675 }
676 return NULL; 582 return NULL;
677 } 583 }
678 584
@@ -686,6 +592,52 @@ struct pnp_resource *pnp_add_mem_resource(struct pnp_dev *dev,
686 return pnp_res; 592 return pnp_res;
687} 593}
688 594
595/*
596 * Determine whether the specified resource is a possible configuration
597 * for this device.
598 */
599int pnp_possible_config(struct pnp_dev *dev, int type, resource_size_t start,
600 resource_size_t size)
601{
602 struct pnp_option *option;
603 struct pnp_port *port;
604 struct pnp_mem *mem;
605 struct pnp_irq *irq;
606 struct pnp_dma *dma;
607
608 list_for_each_entry(option, &dev->options, list) {
609 if (option->type != type)
610 continue;
611
612 switch (option->type) {
613 case IORESOURCE_IO:
614 port = &option->u.port;
615 if (port->min == start && port->size == size)
616 return 1;
617 break;
618 case IORESOURCE_MEM:
619 mem = &option->u.mem;
620 if (mem->min == start && mem->size == size)
621 return 1;
622 break;
623 case IORESOURCE_IRQ:
624 irq = &option->u.irq;
625 if (start < PNP_IRQ_NR &&
626 test_bit(start, irq->map.bits))
627 return 1;
628 break;
629 case IORESOURCE_DMA:
630 dma = &option->u.dma;
631 if (dma->map & (1 << start))
632 return 1;
633 break;
634 }
635 }
636
637 return 0;
638}
639EXPORT_SYMBOL(pnp_possible_config);
640
689/* format is: pnp_reserve_irq=irq1[,irq2] .... */ 641/* format is: pnp_reserve_irq=irq1[,irq2] .... */
690static int __init pnp_setup_reserve_irq(char *str) 642static int __init pnp_setup_reserve_irq(char *str)
691{ 643{
diff --git a/drivers/pnp/support.c b/drivers/pnp/support.c
index 95b076c18c07..bbf78ef4ba02 100644
--- a/drivers/pnp/support.c
+++ b/drivers/pnp/support.c
@@ -2,6 +2,8 @@
2 * support.c - standard functions for the use of pnp protocol drivers 2 * support.c - standard functions for the use of pnp protocol drivers
3 * 3 *
4 * Copyright 2003 Adam Belay <ambx1@neo.rr.com> 4 * Copyright 2003 Adam Belay <ambx1@neo.rr.com>
5 * Copyright (C) 2008 Hewlett-Packard Development Company, L.P.
6 * Bjorn Helgaas <bjorn.helgaas@hp.com>
5 */ 7 */
6 8
7#include <linux/module.h> 9#include <linux/module.h>
@@ -16,6 +18,10 @@
16 */ 18 */
17int pnp_is_active(struct pnp_dev *dev) 19int pnp_is_active(struct pnp_dev *dev)
18{ 20{
21 /*
22 * I don't think this is very reliable because pnp_disable_dev()
23 * only clears out auto-assigned resources.
24 */
19 if (!pnp_port_start(dev, 0) && pnp_port_len(dev, 0) <= 1 && 25 if (!pnp_port_start(dev, 0) && pnp_port_len(dev, 0) <= 1 &&
20 !pnp_mem_start(dev, 0) && pnp_mem_len(dev, 0) <= 1 && 26 !pnp_mem_start(dev, 0) && pnp_mem_len(dev, 0) <= 1 &&
21 pnp_irq(dev, 0) == -1 && pnp_dma(dev, 0) == -1) 27 pnp_irq(dev, 0) == -1 && pnp_dma(dev, 0) == -1)
@@ -52,39 +58,154 @@ void pnp_eisa_id_to_string(u32 id, char *str)
52 str[7] = '\0'; 58 str[7] = '\0';
53} 59}
54 60
61char *pnp_resource_type_name(struct resource *res)
62{
63 switch (pnp_resource_type(res)) {
64 case IORESOURCE_IO:
65 return "io";
66 case IORESOURCE_MEM:
67 return "mem";
68 case IORESOURCE_IRQ:
69 return "irq";
70 case IORESOURCE_DMA:
71 return "dma";
72 }
73 return NULL;
74}
75
55void dbg_pnp_show_resources(struct pnp_dev *dev, char *desc) 76void dbg_pnp_show_resources(struct pnp_dev *dev, char *desc)
56{ 77{
57#ifdef DEBUG 78#ifdef DEBUG
79 char buf[128];
80 int len = 0;
81 struct pnp_resource *pnp_res;
58 struct resource *res; 82 struct resource *res;
59 int i;
60 83
61 dev_dbg(&dev->dev, "current resources: %s\n", desc); 84 if (list_empty(&dev->resources)) {
62 85 dev_dbg(&dev->dev, "%s: no current resources\n", desc);
63 for (i = 0; i < PNP_MAX_IRQ; i++) { 86 return;
64 res = pnp_get_resource(dev, IORESOURCE_IRQ, i);
65 if (res && !(res->flags & IORESOURCE_UNSET))
66 dev_dbg(&dev->dev, " irq %lld flags %#lx\n",
67 (unsigned long long) res->start, res->flags);
68 } 87 }
69 for (i = 0; i < PNP_MAX_DMA; i++) { 88
70 res = pnp_get_resource(dev, IORESOURCE_DMA, i); 89 dev_dbg(&dev->dev, "%s: current resources:\n", desc);
71 if (res && !(res->flags & IORESOURCE_UNSET)) 90 list_for_each_entry(pnp_res, &dev->resources, list) {
72 dev_dbg(&dev->dev, " dma %lld flags %#lx\n", 91 res = &pnp_res->res;
73 (unsigned long long) res->start, res->flags); 92
93 len += snprintf(buf + len, sizeof(buf) - len, " %-3s ",
94 pnp_resource_type_name(res));
95
96 if (res->flags & IORESOURCE_DISABLED) {
97 dev_dbg(&dev->dev, "%sdisabled\n", buf);
98 continue;
99 }
100
101 switch (pnp_resource_type(res)) {
102 case IORESOURCE_IO:
103 case IORESOURCE_MEM:
104 len += snprintf(buf + len, sizeof(buf) - len,
105 "%#llx-%#llx flags %#lx",
106 (unsigned long long) res->start,
107 (unsigned long long) res->end,
108 res->flags);
109 break;
110 case IORESOURCE_IRQ:
111 case IORESOURCE_DMA:
112 len += snprintf(buf + len, sizeof(buf) - len,
113 "%lld flags %#lx",
114 (unsigned long long) res->start,
115 res->flags);
116 break;
117 }
118 dev_dbg(&dev->dev, "%s\n", buf);
74 } 119 }
75 for (i = 0; i < PNP_MAX_PORT; i++) { 120#endif
76 res = pnp_get_resource(dev, IORESOURCE_IO, i); 121}
77 if (res && !(res->flags & IORESOURCE_UNSET)) 122
78 dev_dbg(&dev->dev, " io %#llx-%#llx flags %#lx\n", 123char *pnp_option_priority_name(struct pnp_option *option)
79 (unsigned long long) res->start, 124{
80 (unsigned long long) res->end, res->flags); 125 switch (pnp_option_priority(option)) {
126 case PNP_RES_PRIORITY_PREFERRED:
127 return "preferred";
128 case PNP_RES_PRIORITY_ACCEPTABLE:
129 return "acceptable";
130 case PNP_RES_PRIORITY_FUNCTIONAL:
131 return "functional";
81 } 132 }
82 for (i = 0; i < PNP_MAX_MEM; i++) { 133 return "invalid";
83 res = pnp_get_resource(dev, IORESOURCE_MEM, i); 134}
84 if (res && !(res->flags & IORESOURCE_UNSET)) 135
85 dev_dbg(&dev->dev, " mem %#llx-%#llx flags %#lx\n", 136void dbg_pnp_show_option(struct pnp_dev *dev, struct pnp_option *option)
86 (unsigned long long) res->start, 137{
87 (unsigned long long) res->end, res->flags); 138#ifdef DEBUG
139 char buf[128];
140 int len = 0, i;
141 struct pnp_port *port;
142 struct pnp_mem *mem;
143 struct pnp_irq *irq;
144 struct pnp_dma *dma;
145
146 if (pnp_option_is_dependent(option))
147 len += snprintf(buf + len, sizeof(buf) - len,
148 " dependent set %d (%s) ",
149 pnp_option_set(option),
150 pnp_option_priority_name(option));
151 else
152 len += snprintf(buf + len, sizeof(buf) - len, " independent ");
153
154 switch (option->type) {
155 case IORESOURCE_IO:
156 port = &option->u.port;
157 len += snprintf(buf + len, sizeof(buf) - len, "io min %#llx "
158 "max %#llx align %lld size %lld flags %#x",
159 (unsigned long long) port->min,
160 (unsigned long long) port->max,
161 (unsigned long long) port->align,
162 (unsigned long long) port->size, port->flags);
163 break;
164 case IORESOURCE_MEM:
165 mem = &option->u.mem;
166 len += snprintf(buf + len, sizeof(buf) - len, "mem min %#llx "
167 "max %#llx align %lld size %lld flags %#x",
168 (unsigned long long) mem->min,
169 (unsigned long long) mem->max,
170 (unsigned long long) mem->align,
171 (unsigned long long) mem->size, mem->flags);
172 break;
173 case IORESOURCE_IRQ:
174 irq = &option->u.irq;
175 len += snprintf(buf + len, sizeof(buf) - len, "irq");
176 if (bitmap_empty(irq->map.bits, PNP_IRQ_NR))
177 len += snprintf(buf + len, sizeof(buf) - len,
178 " <none>");
179 else {
180 for (i = 0; i < PNP_IRQ_NR; i++)
181 if (test_bit(i, irq->map.bits))
182 len += snprintf(buf + len,
183 sizeof(buf) - len,
184 " %d", i);
185 }
186 len += snprintf(buf + len, sizeof(buf) - len, " flags %#x",
187 irq->flags);
188 if (irq->flags & IORESOURCE_IRQ_OPTIONAL)
189 len += snprintf(buf + len, sizeof(buf) - len,
190 " (optional)");
191 break;
192 case IORESOURCE_DMA:
193 dma = &option->u.dma;
194 len += snprintf(buf + len, sizeof(buf) - len, "dma");
195 if (!dma->map)
196 len += snprintf(buf + len, sizeof(buf) - len,
197 " <none>");
198 else {
199 for (i = 0; i < 8; i++)
200 if (dma->map & (1 << i))
201 len += snprintf(buf + len,
202 sizeof(buf) - len,
203 " %d", i);
204 }
205 len += snprintf(buf + len, sizeof(buf) - len, " (bitmask %#x) "
206 "flags %#x", dma->map, dma->flags);
207 break;
88 } 208 }
209 dev_dbg(&dev->dev, "%s\n", buf);
89#endif 210#endif
90} 211}
diff --git a/drivers/pnp/system.c b/drivers/pnp/system.c
index cf4e07b01d48..764f3a310685 100644
--- a/drivers/pnp/system.c
+++ b/drivers/pnp/system.c
@@ -60,7 +60,7 @@ static void reserve_resources_of_dev(struct pnp_dev *dev)
60 int i; 60 int i;
61 61
62 for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_IO, i)); i++) { 62 for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_IO, i)); i++) {
63 if (res->flags & IORESOURCE_UNSET) 63 if (res->flags & IORESOURCE_DISABLED)
64 continue; 64 continue;
65 if (res->start == 0) 65 if (res->start == 0)
66 continue; /* disabled */ 66 continue; /* disabled */
@@ -81,7 +81,7 @@ static void reserve_resources_of_dev(struct pnp_dev *dev)
81 } 81 }
82 82
83 for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_MEM, i)); i++) { 83 for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_MEM, i)); i++) {
84 if (res->flags & (IORESOURCE_UNSET | IORESOURCE_DISABLED)) 84 if (res->flags & IORESOURCE_DISABLED)
85 continue; 85 continue;
86 86
87 reserve_range(dev, res->start, res->end, 0); 87 reserve_range(dev, res->start, res->end, 0);
diff --git a/drivers/serial/8250_pnp.c b/drivers/serial/8250_pnp.c
index 97c68d021d28..638b68649e79 100644
--- a/drivers/serial/8250_pnp.c
+++ b/drivers/serial/8250_pnp.c
@@ -383,21 +383,14 @@ static int __devinit check_name(char *name)
383 return 0; 383 return 0;
384} 384}
385 385
386static int __devinit check_resources(struct pnp_option *option) 386static int __devinit check_resources(struct pnp_dev *dev)
387{ 387{
388 struct pnp_option *tmp; 388 resource_size_t base[] = {0x2f8, 0x3f8, 0x2e8, 0x3e8};
389 if (!option) 389 int i;
390 return 0;
391 390
392 for (tmp = option; tmp; tmp = tmp->next) { 391 for (i = 0; i < ARRAY_SIZE(base); i++) {
393 struct pnp_port *port; 392 if (pnp_possible_config(dev, IORESOURCE_IO, base[i], 8))
394 for (port = tmp->port; port; port = port->next) 393 return 1;
395 if ((port->size == 8) &&
396 ((port->min == 0x2f8) ||
397 (port->min == 0x3f8) ||
398 (port->min == 0x2e8) ||
399 (port->min == 0x3e8)))
400 return 1;
401 } 394 }
402 395
403 return 0; 396 return 0;
@@ -420,10 +413,7 @@ static int __devinit serial_pnp_guess_board(struct pnp_dev *dev, int *flags)
420 (dev->card && check_name(dev->card->name)))) 413 (dev->card && check_name(dev->card->name))))
421 return -ENODEV; 414 return -ENODEV;
422 415
423 if (check_resources(dev->independent)) 416 if (check_resources(dev))
424 return 0;
425
426 if (check_resources(dev->dependent))
427 return 0; 417 return 0;
428 418
429 return -ENODEV; 419 return -ENODEV;
diff --git a/include/acpi/acconfig.h b/include/acpi/acconfig.h
index 28fe8bae1037..4eb75a88795a 100644
--- a/include/acpi/acconfig.h
+++ b/include/acpi/acconfig.h
@@ -63,7 +63,7 @@
63 63
64/* Current ACPICA subsystem version in YYYYMMDD format */ 64/* Current ACPICA subsystem version in YYYYMMDD format */
65 65
66#define ACPI_CA_VERSION 0x20080321 66#define ACPI_CA_VERSION 0x20080609
67 67
68/* 68/*
69 * OS name, used for the _OS object. The _OS object is essentially obsolete, 69 * OS name, used for the _OS object. The _OS object is essentially obsolete,
diff --git a/include/acpi/acdisasm.h b/include/acpi/acdisasm.h
index 788f88782012..f53faca8ec80 100644
--- a/include/acpi/acdisasm.h
+++ b/include/acpi/acdisasm.h
@@ -162,6 +162,7 @@ extern struct acpi_dmtable_info acpi_dm_table_info_dmar_hdr[];
162extern struct acpi_dmtable_info acpi_dm_table_info_dmar_scope[]; 162extern struct acpi_dmtable_info acpi_dm_table_info_dmar_scope[];
163extern struct acpi_dmtable_info acpi_dm_table_info_dmar0[]; 163extern struct acpi_dmtable_info acpi_dm_table_info_dmar0[];
164extern struct acpi_dmtable_info acpi_dm_table_info_dmar1[]; 164extern struct acpi_dmtable_info acpi_dm_table_info_dmar1[];
165extern struct acpi_dmtable_info acpi_dm_table_info_dmar2[];
165extern struct acpi_dmtable_info acpi_dm_table_info_ecdt[]; 166extern struct acpi_dmtable_info acpi_dm_table_info_ecdt[];
166extern struct acpi_dmtable_info acpi_dm_table_info_einj[]; 167extern struct acpi_dmtable_info acpi_dm_table_info_einj[];
167extern struct acpi_dmtable_info acpi_dm_table_info_einj0[]; 168extern struct acpi_dmtable_info acpi_dm_table_info_einj0[];
diff --git a/include/acpi/acdispat.h b/include/acpi/acdispat.h
index 910f018d92c7..21a73a105d0a 100644
--- a/include/acpi/acdispat.h
+++ b/include/acpi/acdispat.h
@@ -221,7 +221,7 @@ acpi_ds_method_error(acpi_status status, struct acpi_walk_state *walk_state);
221 * dsinit 221 * dsinit
222 */ 222 */
223acpi_status 223acpi_status
224acpi_ds_initialize_objects(acpi_native_uint table_index, 224acpi_ds_initialize_objects(u32 table_index,
225 struct acpi_namespace_node *start_node); 225 struct acpi_namespace_node *start_node);
226 226
227/* 227/*
diff --git a/include/acpi/acexcep.h b/include/acpi/acexcep.h
index 1f591171bf31..e5a890ffeb02 100644
--- a/include/acpi/acexcep.h
+++ b/include/acpi/acexcep.h
@@ -108,8 +108,9 @@
108#define AE_BAD_HEX_CONSTANT (acpi_status) (0x0007 | AE_CODE_PROGRAMMER) 108#define AE_BAD_HEX_CONSTANT (acpi_status) (0x0007 | AE_CODE_PROGRAMMER)
109#define AE_BAD_OCTAL_CONSTANT (acpi_status) (0x0008 | AE_CODE_PROGRAMMER) 109#define AE_BAD_OCTAL_CONSTANT (acpi_status) (0x0008 | AE_CODE_PROGRAMMER)
110#define AE_BAD_DECIMAL_CONSTANT (acpi_status) (0x0009 | AE_CODE_PROGRAMMER) 110#define AE_BAD_DECIMAL_CONSTANT (acpi_status) (0x0009 | AE_CODE_PROGRAMMER)
111#define AE_MISSING_ARGUMENTS (acpi_status) (0x000A | AE_CODE_PROGRAMMER)
111 112
112#define AE_CODE_PGM_MAX 0x0009 113#define AE_CODE_PGM_MAX 0x000A
113 114
114/* 115/*
115 * Acpi table exceptions 116 * Acpi table exceptions
@@ -225,6 +226,7 @@ char const *acpi_gbl_exception_names_env[] = {
225}; 226};
226 227
227char const *acpi_gbl_exception_names_pgm[] = { 228char const *acpi_gbl_exception_names_pgm[] = {
229 NULL,
228 "AE_BAD_PARAMETER", 230 "AE_BAD_PARAMETER",
229 "AE_BAD_CHARACTER", 231 "AE_BAD_CHARACTER",
230 "AE_BAD_PATHNAME", 232 "AE_BAD_PATHNAME",
@@ -233,10 +235,12 @@ char const *acpi_gbl_exception_names_pgm[] = {
233 "AE_ALIGNMENT", 235 "AE_ALIGNMENT",
234 "AE_BAD_HEX_CONSTANT", 236 "AE_BAD_HEX_CONSTANT",
235 "AE_BAD_OCTAL_CONSTANT", 237 "AE_BAD_OCTAL_CONSTANT",
236 "AE_BAD_DECIMAL_CONSTANT" 238 "AE_BAD_DECIMAL_CONSTANT",
239 "AE_MISSING_ARGUMENTS"
237}; 240};
238 241
239char const *acpi_gbl_exception_names_tbl[] = { 242char const *acpi_gbl_exception_names_tbl[] = {
243 NULL,
240 "AE_BAD_SIGNATURE", 244 "AE_BAD_SIGNATURE",
241 "AE_BAD_HEADER", 245 "AE_BAD_HEADER",
242 "AE_BAD_CHECKSUM", 246 "AE_BAD_CHECKSUM",
@@ -246,6 +250,7 @@ char const *acpi_gbl_exception_names_tbl[] = {
246}; 250};
247 251
248char const *acpi_gbl_exception_names_aml[] = { 252char const *acpi_gbl_exception_names_aml[] = {
253 NULL,
249 "AE_AML_ERROR", 254 "AE_AML_ERROR",
250 "AE_AML_PARSE", 255 "AE_AML_PARSE",
251 "AE_AML_BAD_OPCODE", 256 "AE_AML_BAD_OPCODE",
@@ -283,6 +288,7 @@ char const *acpi_gbl_exception_names_aml[] = {
283}; 288};
284 289
285char const *acpi_gbl_exception_names_ctrl[] = { 290char const *acpi_gbl_exception_names_ctrl[] = {
291 NULL,
286 "AE_CTRL_RETURN_VALUE", 292 "AE_CTRL_RETURN_VALUE",
287 "AE_CTRL_PENDING", 293 "AE_CTRL_PENDING",
288 "AE_CTRL_TERMINATE", 294 "AE_CTRL_TERMINATE",
diff --git a/include/acpi/acglobal.h b/include/acpi/acglobal.h
index 74ad971241db..15dda46b70d1 100644
--- a/include/acpi/acglobal.h
+++ b/include/acpi/acglobal.h
@@ -140,7 +140,7 @@ ACPI_EXTERN u32 acpi_gbl_trace_flags;
140 */ 140 */
141ACPI_EXTERN struct acpi_internal_rsdt acpi_gbl_root_table_list; 141ACPI_EXTERN struct acpi_internal_rsdt acpi_gbl_root_table_list;
142ACPI_EXTERN struct acpi_table_fadt acpi_gbl_FADT; 142ACPI_EXTERN struct acpi_table_fadt acpi_gbl_FADT;
143extern acpi_native_uint acpi_gbl_permanent_mmap; 143extern u8 acpi_gbl_permanent_mmap;
144 144
145/* These addresses are calculated from FADT address values */ 145/* These addresses are calculated from FADT address values */
146 146
diff --git a/include/acpi/achware.h b/include/acpi/achware.h
index d4fb9bbc903c..97a72b193276 100644
--- a/include/acpi/achware.h
+++ b/include/acpi/achware.h
@@ -87,6 +87,8 @@ acpi_status acpi_hw_clear_acpi_status(void);
87/* 87/*
88 * hwgpe - GPE support 88 * hwgpe - GPE support
89 */ 89 */
90acpi_status acpi_hw_low_disable_gpe(struct acpi_gpe_event_info *gpe_event_info);
91
90acpi_status 92acpi_status
91acpi_hw_write_gpe_enable_reg(struct acpi_gpe_event_info *gpe_event_info); 93acpi_hw_write_gpe_enable_reg(struct acpi_gpe_event_info *gpe_event_info);
92 94
@@ -100,11 +102,9 @@ acpi_status
100acpi_hw_clear_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info, 102acpi_hw_clear_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
101 struct acpi_gpe_block_info *gpe_block); 103 struct acpi_gpe_block_info *gpe_block);
102 104
103#ifdef ACPI_FUTURE_USAGE
104acpi_status 105acpi_status
105acpi_hw_get_gpe_status(struct acpi_gpe_event_info *gpe_event_info, 106acpi_hw_get_gpe_status(struct acpi_gpe_event_info *gpe_event_info,
106 acpi_event_status * event_status); 107 acpi_event_status * event_status);
107#endif /* ACPI_FUTURE_USAGE */
108 108
109acpi_status acpi_hw_disable_all_gpes(void); 109acpi_status acpi_hw_disable_all_gpes(void);
110 110
diff --git a/include/acpi/acinterp.h b/include/acpi/acinterp.h
index e249ce5d3300..e8db7a3143a5 100644
--- a/include/acpi/acinterp.h
+++ b/include/acpi/acinterp.h
@@ -366,10 +366,7 @@ void acpi_ex_dump_operand(union acpi_operand_object *obj_desc, u32 depth);
366 366
367void 367void
368acpi_ex_dump_operands(union acpi_operand_object **operands, 368acpi_ex_dump_operands(union acpi_operand_object **operands,
369 acpi_interpreter_mode interpreter_mode, 369 const char *opcode_name, u32 num_opcodes);
370 char *ident,
371 u32 num_levels,
372 char *note, char *module_name, u32 line_number);
373 370
374#ifdef ACPI_FUTURE_USAGE 371#ifdef ACPI_FUTURE_USAGE
375void 372void
diff --git a/include/acpi/aclocal.h b/include/acpi/aclocal.h
index c5cdc32ac2f8..b221c8583ddd 100644
--- a/include/acpi/aclocal.h
+++ b/include/acpi/aclocal.h
@@ -98,8 +98,8 @@ union acpi_parse_object;
98 98
99static char *acpi_gbl_mutex_names[ACPI_NUM_MUTEX] = { 99static char *acpi_gbl_mutex_names[ACPI_NUM_MUTEX] = {
100 "ACPI_MTX_Interpreter", 100 "ACPI_MTX_Interpreter",
101 "ACPI_MTX_Tables",
102 "ACPI_MTX_Namespace", 101 "ACPI_MTX_Namespace",
102 "ACPI_MTX_Tables",
103 "ACPI_MTX_Events", 103 "ACPI_MTX_Events",
104 "ACPI_MTX_Caches", 104 "ACPI_MTX_Caches",
105 "ACPI_MTX_Memory", 105 "ACPI_MTX_Memory",
@@ -282,8 +282,8 @@ struct acpi_predefined_names {
282/* Info structure used to convert external<->internal namestrings */ 282/* Info structure used to convert external<->internal namestrings */
283 283
284struct acpi_namestring_info { 284struct acpi_namestring_info {
285 char *external_name; 285 const char *external_name;
286 char *next_external_char; 286 const char *next_external_char;
287 char *internal_name; 287 char *internal_name;
288 u32 length; 288 u32 length;
289 u32 num_segments; 289 u32 num_segments;
diff --git a/include/acpi/acmacros.h b/include/acpi/acmacros.h
index fb41a3b802fc..57ab9e9d7593 100644
--- a/include/acpi/acmacros.h
+++ b/include/acpi/acmacros.h
@@ -80,12 +80,12 @@
80 */ 80 */
81#define ACPI_CAST_PTR(t, p) ((t *) (acpi_uintptr_t) (p)) 81#define ACPI_CAST_PTR(t, p) ((t *) (acpi_uintptr_t) (p))
82#define ACPI_CAST_INDIRECT_PTR(t, p) ((t **) (acpi_uintptr_t) (p)) 82#define ACPI_CAST_INDIRECT_PTR(t, p) ((t **) (acpi_uintptr_t) (p))
83#define ACPI_ADD_PTR(t,a,b) ACPI_CAST_PTR (t, (ACPI_CAST_PTR (u8,(a)) + (acpi_native_uint)(b))) 83#define ACPI_ADD_PTR(t, a, b) ACPI_CAST_PTR (t, (ACPI_CAST_PTR (u8,(a)) + (acpi_size)(b)))
84#define ACPI_PTR_DIFF(a,b) (acpi_native_uint) (ACPI_CAST_PTR (u8,(a)) - ACPI_CAST_PTR (u8,(b))) 84#define ACPI_PTR_DIFF(a, b) (acpi_size) (ACPI_CAST_PTR (u8,(a)) - ACPI_CAST_PTR (u8,(b)))
85 85
86/* Pointer/Integer type conversions */ 86/* Pointer/Integer type conversions */
87 87
88#define ACPI_TO_POINTER(i) ACPI_ADD_PTR (void,(void *) NULL,(acpi_native_uint) i) 88#define ACPI_TO_POINTER(i) ACPI_ADD_PTR (void, (void *) NULL, (acpi_size) i)
89#define ACPI_TO_INTEGER(p) ACPI_PTR_DIFF (p,(void *) NULL) 89#define ACPI_TO_INTEGER(p) ACPI_PTR_DIFF (p,(void *) NULL)
90#define ACPI_OFFSET(d,f) (acpi_size) ACPI_PTR_DIFF (&(((d *)0)->f),(void *) NULL) 90#define ACPI_OFFSET(d,f) (acpi_size) ACPI_PTR_DIFF (&(((d *)0)->f),(void *) NULL)
91#define ACPI_PHYSADDR_TO_PTR(i) ACPI_TO_POINTER(i) 91#define ACPI_PHYSADDR_TO_PTR(i) ACPI_TO_POINTER(i)
@@ -296,22 +296,22 @@ struct acpi_integer_overlay {
296/* 296/*
297 * Rounding macros (Power of two boundaries only) 297 * Rounding macros (Power of two boundaries only)
298 */ 298 */
299#define ACPI_ROUND_DOWN(value,boundary) (((acpi_native_uint)(value)) & \ 299#define ACPI_ROUND_DOWN(value, boundary) (((acpi_size)(value)) & \
300 (~(((acpi_native_uint) boundary)-1))) 300 (~(((acpi_size) boundary)-1)))
301 301
302#define ACPI_ROUND_UP(value,boundary) ((((acpi_native_uint)(value)) + \ 302#define ACPI_ROUND_UP(value, boundary) ((((acpi_size)(value)) + \
303 (((acpi_native_uint) boundary)-1)) & \ 303 (((acpi_size) boundary)-1)) & \
304 (~(((acpi_native_uint) boundary)-1))) 304 (~(((acpi_size) boundary)-1)))
305 305
306/* Note: sizeof(acpi_native_uint) evaluates to either 2, 4, or 8 */ 306/* Note: sizeof(acpi_size) evaluates to either 4 or 8 (32- vs 64-bit mode) */
307 307
308#define ACPI_ROUND_DOWN_TO_32BIT(a) ACPI_ROUND_DOWN(a,4) 308#define ACPI_ROUND_DOWN_TO_32BIT(a) ACPI_ROUND_DOWN(a,4)
309#define ACPI_ROUND_DOWN_TO_64BIT(a) ACPI_ROUND_DOWN(a,8) 309#define ACPI_ROUND_DOWN_TO_64BIT(a) ACPI_ROUND_DOWN(a,8)
310#define ACPI_ROUND_DOWN_TO_NATIVE_WORD(a) ACPI_ROUND_DOWN(a,sizeof(acpi_native_uint)) 310#define ACPI_ROUND_DOWN_TO_NATIVE_WORD(a) ACPI_ROUND_DOWN(a,sizeof(acpi_size))
311 311
312#define ACPI_ROUND_UP_TO_32BIT(a) ACPI_ROUND_UP(a,4) 312#define ACPI_ROUND_UP_TO_32BIT(a) ACPI_ROUND_UP(a,4)
313#define ACPI_ROUND_UP_TO_64BIT(a) ACPI_ROUND_UP(a,8) 313#define ACPI_ROUND_UP_TO_64BIT(a) ACPI_ROUND_UP(a,8)
314#define ACPI_ROUND_UP_TO_NATIVE_WORD(a) ACPI_ROUND_UP(a,sizeof(acpi_native_uint)) 314#define ACPI_ROUND_UP_TO_NATIVE_WORD(a) ACPI_ROUND_UP(a,sizeof(acpi_size))
315 315
316#define ACPI_ROUND_BITS_UP_TO_BYTES(a) ACPI_DIV_8((a) + 7) 316#define ACPI_ROUND_BITS_UP_TO_BYTES(a) ACPI_DIV_8((a) + 7)
317#define ACPI_ROUND_BITS_DOWN_TO_BYTES(a) ACPI_DIV_8((a)) 317#define ACPI_ROUND_BITS_DOWN_TO_BYTES(a) ACPI_DIV_8((a))
@@ -322,7 +322,7 @@ struct acpi_integer_overlay {
322 322
323#define ACPI_ROUND_UP_TO(value,boundary) (((value) + ((boundary)-1)) / (boundary)) 323#define ACPI_ROUND_UP_TO(value,boundary) (((value) + ((boundary)-1)) / (boundary))
324 324
325#define ACPI_IS_MISALIGNED(value) (((acpi_native_uint)value) & (sizeof(acpi_native_uint)-1)) 325#define ACPI_IS_MISALIGNED(value) (((acpi_size)value) & (sizeof(acpi_size)-1))
326 326
327/* 327/*
328 * Bitmask creation 328 * Bitmask creation
@@ -414,7 +414,7 @@ struct acpi_integer_overlay {
414 * error messages. The __FILE__ macro is not very useful for this, because it 414 * error messages. The __FILE__ macro is not very useful for this, because it
415 * often includes the entire pathname to the module 415 * often includes the entire pathname to the module
416 */ 416 */
417#define ACPI_MODULE_NAME(name) static char ACPI_UNUSED_VAR *_acpi_module_name = name; 417#define ACPI_MODULE_NAME(name) static const char ACPI_UNUSED_VAR _acpi_module_name[] = name;
418#else 418#else
419#define ACPI_MODULE_NAME(name) 419#define ACPI_MODULE_NAME(name)
420#endif 420#endif
@@ -467,19 +467,17 @@ struct acpi_integer_overlay {
467/* 467/*
468 * If ACPI_GET_FUNCTION_NAME was not defined in the compiler-dependent header, 468 * If ACPI_GET_FUNCTION_NAME was not defined in the compiler-dependent header,
469 * define it now. This is the case where there the compiler does not support 469 * define it now. This is the case where there the compiler does not support
470 * a __FUNCTION__ macro or equivalent. We save the function name on the 470 * a __FUNCTION__ macro or equivalent.
471 * local stack.
472 */ 471 */
473#ifndef ACPI_GET_FUNCTION_NAME 472#ifndef ACPI_GET_FUNCTION_NAME
474#define ACPI_GET_FUNCTION_NAME _acpi_function_name 473#define ACPI_GET_FUNCTION_NAME _acpi_function_name
475/* 474/*
476 * The Name parameter should be the procedure name as a quoted string. 475 * The Name parameter should be the procedure name as a quoted string.
477 * This is declared as a local string ("MyFunctionName") so that it can 476 * The function name is also used by the function exit macros below.
478 * be also used by the function exit macros below.
479 * Note: (const char) is used to be compatible with the debug interfaces 477 * Note: (const char) is used to be compatible with the debug interfaces
480 * and macros such as __FUNCTION__. 478 * and macros such as __FUNCTION__.
481 */ 479 */
482#define ACPI_FUNCTION_NAME(name) const char *_acpi_function_name = #name; 480#define ACPI_FUNCTION_NAME(name) static const char _acpi_function_name[] = #name;
483 481
484#else 482#else
485/* Compiler supports __FUNCTION__ (or equivalent) -- Ignore this macro */ 483/* Compiler supports __FUNCTION__ (or equivalent) -- Ignore this macro */
@@ -599,7 +597,7 @@ struct acpi_integer_overlay {
599/* Stack and buffer dumping */ 597/* Stack and buffer dumping */
600 598
601#define ACPI_DUMP_STACK_ENTRY(a) acpi_ex_dump_operand((a),0) 599#define ACPI_DUMP_STACK_ENTRY(a) acpi_ex_dump_operand((a),0)
602#define ACPI_DUMP_OPERANDS(a,b,c,d,e) acpi_ex_dump_operands(a,b,c,d,e,_acpi_module_name,__LINE__) 600#define ACPI_DUMP_OPERANDS(a,b,c) acpi_ex_dump_operands(a,b,c)
603 601
604#define ACPI_DUMP_ENTRY(a,b) acpi_ns_dump_entry (a,b) 602#define ACPI_DUMP_ENTRY(a,b) acpi_ns_dump_entry (a,b)
605#define ACPI_DUMP_PATHNAME(a,b,c,d) acpi_ns_dump_pathname(a,b,c,d) 603#define ACPI_DUMP_PATHNAME(a,b,c,d) acpi_ns_dump_pathname(a,b,c,d)
@@ -635,7 +633,7 @@ struct acpi_integer_overlay {
635#define ACPI_FUNCTION_VALUE_EXIT(s) do { } while(0) 633#define ACPI_FUNCTION_VALUE_EXIT(s) do { } while(0)
636#define ACPI_FUNCTION_ENTRY() do { } while(0) 634#define ACPI_FUNCTION_ENTRY() do { } while(0)
637#define ACPI_DUMP_STACK_ENTRY(a) do { } while(0) 635#define ACPI_DUMP_STACK_ENTRY(a) do { } while(0)
638#define ACPI_DUMP_OPERANDS(a,b,c,d,e) do { } while(0) 636#define ACPI_DUMP_OPERANDS(a,b,c) do { } while(0)
639#define ACPI_DUMP_ENTRY(a,b) do { } while(0) 637#define ACPI_DUMP_ENTRY(a,b) do { } while(0)
640#define ACPI_DUMP_TABLES(a,b) do { } while(0) 638#define ACPI_DUMP_TABLES(a,b) do { } while(0)
641#define ACPI_DUMP_PATHNAME(a,b,c,d) do { } while(0) 639#define ACPI_DUMP_PATHNAME(a,b,c,d) do { } while(0)
diff --git a/include/acpi/acnamesp.h b/include/acpi/acnamesp.h
index 713b30903fe5..9ed70a050580 100644
--- a/include/acpi/acnamesp.h
+++ b/include/acpi/acnamesp.h
@@ -86,8 +86,7 @@ acpi_status acpi_ns_initialize_devices(void);
86acpi_status acpi_ns_load_namespace(void); 86acpi_status acpi_ns_load_namespace(void);
87 87
88acpi_status 88acpi_status
89acpi_ns_load_table(acpi_native_uint table_index, 89acpi_ns_load_table(u32 table_index, struct acpi_namespace_node *node);
90 struct acpi_namespace_node *node);
91 90
92/* 91/*
93 * nswalk - walk the namespace 92 * nswalk - walk the namespace
@@ -108,12 +107,11 @@ struct acpi_namespace_node *acpi_ns_get_next_node(acpi_object_type type, struct
108 * nsparse - table parsing 107 * nsparse - table parsing
109 */ 108 */
110acpi_status 109acpi_status
111acpi_ns_parse_table(acpi_native_uint table_index, 110acpi_ns_parse_table(u32 table_index, struct acpi_namespace_node *start_node);
112 struct acpi_namespace_node *start_node);
113 111
114acpi_status 112acpi_status
115acpi_ns_one_complete_parse(acpi_native_uint pass_number, 113acpi_ns_one_complete_parse(u32 pass_number,
116 acpi_native_uint table_index, 114 u32 table_index,
117 struct acpi_namespace_node *start_node); 115 struct acpi_namespace_node *start_node);
118 116
119/* 117/*
@@ -201,7 +199,7 @@ acpi_ns_pattern_match(struct acpi_namespace_node *obj_node, char *search_for);
201 199
202acpi_status 200acpi_status
203acpi_ns_get_node(struct acpi_namespace_node *prefix_node, 201acpi_ns_get_node(struct acpi_namespace_node *prefix_node,
204 char *external_pathname, 202 const char *external_pathname,
205 u32 flags, struct acpi_namespace_node **out_node); 203 u32 flags, struct acpi_namespace_node **out_node);
206 204
207acpi_size acpi_ns_get_pathname_length(struct acpi_namespace_node *node); 205acpi_size acpi_ns_get_pathname_length(struct acpi_namespace_node *node);
@@ -265,28 +263,30 @@ acpi_object_type acpi_ns_get_type(struct acpi_namespace_node *node);
265u32 acpi_ns_local(acpi_object_type type); 263u32 acpi_ns_local(acpi_object_type type);
266 264
267void 265void
268acpi_ns_report_error(char *module_name, 266acpi_ns_report_error(const char *module_name,
269 u32 line_number, 267 u32 line_number,
270 char *internal_name, acpi_status lookup_status); 268 const char *internal_name, acpi_status lookup_status);
271 269
272void 270void
273acpi_ns_report_method_error(char *module_name, 271acpi_ns_report_method_error(const char *module_name,
274 u32 line_number, 272 u32 line_number,
275 char *message, 273 const char *message,
276 struct acpi_namespace_node *node, 274 struct acpi_namespace_node *node,
277 char *path, acpi_status lookup_status); 275 const char *path, acpi_status lookup_status);
278 276
279void acpi_ns_print_node_pathname(struct acpi_namespace_node *node, char *msg); 277void
278acpi_ns_print_node_pathname(struct acpi_namespace_node *node, const char *msg);
280 279
281acpi_status acpi_ns_build_internal_name(struct acpi_namestring_info *info); 280acpi_status acpi_ns_build_internal_name(struct acpi_namestring_info *info);
282 281
283void acpi_ns_get_internal_name_length(struct acpi_namestring_info *info); 282void acpi_ns_get_internal_name_length(struct acpi_namestring_info *info);
284 283
285acpi_status acpi_ns_internalize_name(char *dotted_name, char **converted_name); 284acpi_status
285acpi_ns_internalize_name(const char *dotted_name, char **converted_name);
286 286
287acpi_status 287acpi_status
288acpi_ns_externalize_name(u32 internal_name_length, 288acpi_ns_externalize_name(u32 internal_name_length,
289 char *internal_name, 289 const char *internal_name,
290 u32 * converted_name_length, char **converted_name); 290 u32 * converted_name_length, char **converted_name);
291 291
292struct acpi_namespace_node *acpi_ns_map_handle_to_node(acpi_handle handle); 292struct acpi_namespace_node *acpi_ns_map_handle_to_node(acpi_handle handle);
diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
index 2f1c68c7a727..db90a74f8714 100644
--- a/include/acpi/acpi_bus.h
+++ b/include/acpi/acpi_bus.h
@@ -376,9 +376,9 @@ acpi_handle acpi_get_pci_rootbridge_handle(unsigned int, unsigned int);
376#define DEVICE_ACPI_HANDLE(dev) ((acpi_handle)((dev)->archdata.acpi_handle)) 376#define DEVICE_ACPI_HANDLE(dev) ((acpi_handle)((dev)->archdata.acpi_handle))
377 377
378#ifdef CONFIG_PM_SLEEP 378#ifdef CONFIG_PM_SLEEP
379int acpi_pm_device_sleep_state(struct device *, int, int *); 379int acpi_pm_device_sleep_state(struct device *, int *);
380#else /* !CONFIG_PM_SLEEP */ 380#else /* !CONFIG_PM_SLEEP */
381static inline int acpi_pm_device_sleep_state(struct device *d, int w, int *p) 381static inline int acpi_pm_device_sleep_state(struct device *d, int *p)
382{ 382{
383 if (p) 383 if (p)
384 *p = ACPI_STATE_D0; 384 *p = ACPI_STATE_D0;
diff --git a/include/acpi/acpiosxf.h b/include/acpi/acpiosxf.h
index d4a560d2deb6..3f93a6b4e17f 100644
--- a/include/acpi/acpiosxf.h
+++ b/include/acpi/acpiosxf.h
@@ -144,7 +144,7 @@ void acpi_os_release_mutex(acpi_mutex handle);
144void *acpi_os_allocate(acpi_size size); 144void *acpi_os_allocate(acpi_size size);
145 145
146void __iomem *acpi_os_map_memory(acpi_physical_address where, 146void __iomem *acpi_os_map_memory(acpi_physical_address where,
147 acpi_native_uint length); 147 acpi_size length);
148 148
149void acpi_os_unmap_memory(void __iomem * logical_address, acpi_size size); 149void acpi_os_unmap_memory(void __iomem * logical_address, acpi_size size);
150 150
diff --git a/include/acpi/acpixf.h b/include/acpi/acpixf.h
index 2c3806e6546f..94d94e126e9f 100644
--- a/include/acpi/acpixf.h
+++ b/include/acpi/acpixf.h
@@ -98,7 +98,7 @@ void acpi_free(void *address);
98 */ 98 */
99acpi_status acpi_reallocate_root_table(void); 99acpi_status acpi_reallocate_root_table(void);
100 100
101acpi_status acpi_find_root_pointer(acpi_native_uint * rsdp_address); 101acpi_status acpi_find_root_pointer(acpi_size *rsdp_address);
102 102
103acpi_status acpi_load_tables(void); 103acpi_status acpi_load_tables(void);
104 104
@@ -108,15 +108,15 @@ acpi_status acpi_unload_table_id(acpi_owner_id id);
108 108
109acpi_status 109acpi_status
110acpi_get_table_header(acpi_string signature, 110acpi_get_table_header(acpi_string signature,
111 acpi_native_uint instance, 111 u32 instance,
112 struct acpi_table_header *out_table_header); 112 struct acpi_table_header *out_table_header);
113 113
114acpi_status 114acpi_status
115acpi_get_table(acpi_string signature, 115acpi_get_table(acpi_string signature,
116 acpi_native_uint instance, struct acpi_table_header **out_table); 116 u32 instance, struct acpi_table_header **out_table);
117 117
118acpi_status 118acpi_status
119acpi_get_table_by_index(acpi_native_uint table_index, 119acpi_get_table_by_index(u32 table_index,
120 struct acpi_table_header **out_table); 120 struct acpi_table_header **out_table);
121 121
122acpi_status 122acpi_status
@@ -248,9 +248,7 @@ acpi_status acpi_disable_event(u32 event, u32 flags);
248 248
249acpi_status acpi_clear_event(u32 event); 249acpi_status acpi_clear_event(u32 event);
250 250
251#ifdef ACPI_FUTURE_USAGE
252acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status); 251acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status);
253#endif /* ACPI_FUTURE_USAGE */
254 252
255acpi_status acpi_set_gpe_type(acpi_handle gpe_device, u32 gpe_number, u8 type); 253acpi_status acpi_set_gpe_type(acpi_handle gpe_device, u32 gpe_number, u8 type);
256 254
@@ -260,12 +258,10 @@ acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number, u32 flags);
260 258
261acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number, u32 flags); 259acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number, u32 flags);
262 260
263#ifdef ACPI_FUTURE_USAGE
264acpi_status 261acpi_status
265acpi_get_gpe_status(acpi_handle gpe_device, 262acpi_get_gpe_status(acpi_handle gpe_device,
266 u32 gpe_number, 263 u32 gpe_number,
267 u32 flags, acpi_event_status * event_status); 264 u32 flags, acpi_event_status * event_status);
268#endif /* ACPI_FUTURE_USAGE */
269 265
270acpi_status 266acpi_status
271acpi_install_gpe_block(acpi_handle gpe_device, 267acpi_install_gpe_block(acpi_handle gpe_device,
diff --git a/include/acpi/acstruct.h b/include/acpi/acstruct.h
index a907c67d651e..7980a26bad35 100644
--- a/include/acpi/acstruct.h
+++ b/include/acpi/acstruct.h
@@ -108,7 +108,6 @@ struct acpi_walk_state {
108 union acpi_operand_object **caller_return_desc; 108 union acpi_operand_object **caller_return_desc;
109 union acpi_generic_state *control_state; /* List of control states (nested IFs) */ 109 union acpi_generic_state *control_state; /* List of control states (nested IFs) */
110 struct acpi_namespace_node *deferred_node; /* Used when executing deferred opcodes */ 110 struct acpi_namespace_node *deferred_node; /* Used when executing deferred opcodes */
111 struct acpi_gpe_event_info *gpe_event_info; /* Info for GPE (_Lxx/_Exx methods only */
112 union acpi_operand_object *implicit_return_obj; 111 union acpi_operand_object *implicit_return_obj;
113 struct acpi_namespace_node *method_call_node; /* Called method Node */ 112 struct acpi_namespace_node *method_call_node; /* Called method Node */
114 union acpi_parse_object *method_call_op; /* method_call Op if running a method */ 113 union acpi_parse_object *method_call_op; /* method_call Op if running a method */
@@ -143,7 +142,7 @@ struct acpi_init_walk_info {
143 u16 package_init; 142 u16 package_init;
144 u16 object_count; 143 u16 object_count;
145 acpi_owner_id owner_id; 144 acpi_owner_id owner_id;
146 acpi_native_uint table_index; 145 u32 table_index;
147}; 146};
148 147
149struct acpi_get_devices_info { 148struct acpi_get_devices_info {
@@ -189,17 +188,12 @@ struct acpi_evaluate_info {
189 union acpi_operand_object **parameters; 188 union acpi_operand_object **parameters;
190 struct acpi_namespace_node *resolved_node; 189 struct acpi_namespace_node *resolved_node;
191 union acpi_operand_object *return_object; 190 union acpi_operand_object *return_object;
191 u8 param_count;
192 u8 pass_number; 192 u8 pass_number;
193 u8 parameter_type;
194 u8 return_object_type; 193 u8 return_object_type;
195 u8 flags; 194 u8 flags;
196}; 195};
197 196
198/* Types for parameter_type above */
199
200#define ACPI_PARAM_ARGS 0
201#define ACPI_PARAM_GPE 1
202
203/* Values for Flags above */ 197/* Values for Flags above */
204 198
205#define ACPI_IGNORE_RETURN_VALUE 1 199#define ACPI_IGNORE_RETURN_VALUE 1
diff --git a/include/acpi/actables.h b/include/acpi/actables.h
index 4b36a55b0b3b..0cbe1b9ab522 100644
--- a/include/acpi/actables.h
+++ b/include/acpi/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(acpi_native_uint table_index, u8 flags); 52void acpi_tb_parse_fadt(u32 table_index, u8 flags);
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
@@ -58,8 +58,7 @@ void acpi_tb_create_local_fadt(struct acpi_table_header *table, u32 length);
58 */ 58 */
59acpi_status 59acpi_status
60acpi_tb_find_table(char *signature, 60acpi_tb_find_table(char *signature,
61 char *oem_id, 61 char *oem_id, char *oem_table_id, u32 *table_index);
62 char *oem_table_id, acpi_native_uint * table_index);
63 62
64/* 63/*
65 * tbinstal - Table removal and deletion 64 * tbinstal - Table removal and deletion
@@ -69,30 +68,28 @@ acpi_status acpi_tb_resize_root_table_list(void);
69acpi_status acpi_tb_verify_table(struct acpi_table_desc *table_desc); 68acpi_status acpi_tb_verify_table(struct acpi_table_desc *table_desc);
70 69
71acpi_status 70acpi_status
72acpi_tb_add_table(struct acpi_table_desc *table_desc, 71acpi_tb_add_table(struct acpi_table_desc *table_desc, u32 *table_index);
73 acpi_native_uint * table_index);
74 72
75acpi_status 73acpi_status
76acpi_tb_store_table(acpi_physical_address address, 74acpi_tb_store_table(acpi_physical_address address,
77 struct acpi_table_header *table, 75 struct acpi_table_header *table,
78 u32 length, u8 flags, acpi_native_uint * table_index); 76 u32 length, u8 flags, u32 *table_index);
79 77
80void acpi_tb_delete_table(struct acpi_table_desc *table_desc); 78void acpi_tb_delete_table(struct acpi_table_desc *table_desc);
81 79
82void acpi_tb_terminate(void); 80void acpi_tb_terminate(void);
83 81
84void acpi_tb_delete_namespace_by_owner(acpi_native_uint table_index); 82void acpi_tb_delete_namespace_by_owner(u32 table_index);
85 83
86acpi_status acpi_tb_allocate_owner_id(acpi_native_uint table_index); 84acpi_status acpi_tb_allocate_owner_id(u32 table_index);
87 85
88acpi_status acpi_tb_release_owner_id(acpi_native_uint table_index); 86acpi_status acpi_tb_release_owner_id(u32 table_index);
89 87
90acpi_status 88acpi_status acpi_tb_get_owner_id(u32 table_index, acpi_owner_id *owner_id);
91acpi_tb_get_owner_id(acpi_native_uint table_index, acpi_owner_id * owner_id);
92 89
93u8 acpi_tb_is_table_loaded(acpi_native_uint table_index); 90u8 acpi_tb_is_table_loaded(u32 table_index);
94 91
95void acpi_tb_set_table_loaded_flag(acpi_native_uint table_index, u8 is_loaded); 92void acpi_tb_set_table_loaded_flag(u32 table_index, u8 is_loaded);
96 93
97/* 94/*
98 * tbutils - table manager utilities 95 * tbutils - table manager utilities
@@ -103,14 +100,14 @@ void
103acpi_tb_print_table_header(acpi_physical_address address, 100acpi_tb_print_table_header(acpi_physical_address address,
104 struct acpi_table_header *header); 101 struct acpi_table_header *header);
105 102
106u8 acpi_tb_checksum(u8 * buffer, acpi_native_uint length); 103u8 acpi_tb_checksum(u8 *buffer, u32 length);
107 104
108acpi_status 105acpi_status
109acpi_tb_verify_checksum(struct acpi_table_header *table, u32 length); 106acpi_tb_verify_checksum(struct acpi_table_header *table, u32 length);
110 107
111void 108void
112acpi_tb_install_table(acpi_physical_address address, 109acpi_tb_install_table(acpi_physical_address address,
113 u8 flags, char *signature, acpi_native_uint table_index); 110 u8 flags, char *signature, u32 table_index);
114 111
115acpi_status 112acpi_status
116acpi_tb_parse_root_table(acpi_physical_address rsdp_address, u8 flags); 113acpi_tb_parse_root_table(acpi_physical_address rsdp_address, u8 flags);
diff --git a/include/acpi/actbl1.h b/include/acpi/actbl1.h
index 9af239bd1153..d38f9be2f6ee 100644
--- a/include/acpi/actbl1.h
+++ b/include/acpi/actbl1.h
@@ -300,6 +300,7 @@ struct acpi_table_dbgp {
300/******************************************************************************* 300/*******************************************************************************
301 * 301 *
302 * DMAR - DMA Remapping table 302 * DMAR - DMA Remapping table
303 * From "Intel Virtualization Technology for Directed I/O", Sept. 2007
303 * 304 *
304 ******************************************************************************/ 305 ******************************************************************************/
305 306
@@ -310,6 +311,10 @@ struct acpi_table_dmar {
310 u8 reserved[10]; 311 u8 reserved[10];
311}; 312};
312 313
314/* Flags */
315
316#define ACPI_DMAR_INTR_REMAP (1)
317
313/* DMAR subtable header */ 318/* DMAR subtable header */
314 319
315struct acpi_dmar_header { 320struct acpi_dmar_header {
@@ -382,6 +387,20 @@ struct acpi_dmar_reserved_memory {
382 387
383#define ACPI_DMAR_ALLOW_ALL (1) 388#define ACPI_DMAR_ALLOW_ALL (1)
384 389
390
391/* 2: Root Port ATS Capability Reporting Structure */
392
393struct acpi_dmar_atsr {
394 struct acpi_dmar_header header;
395 u8 flags;
396 u8 reserved;
397 u16 segment;
398};
399
400/* Flags */
401
402#define ACPI_DMAR_ALL_PORTS (1)
403
385/******************************************************************************* 404/*******************************************************************************
386 * 405 *
387 * ECDT - Embedded Controller Boot Resources Table 406 * ECDT - Embedded Controller Boot Resources Table
@@ -1156,9 +1175,9 @@ struct acpi_srat_mem_affinity {
1156 u16 reserved; /* Reserved, must be zero */ 1175 u16 reserved; /* Reserved, must be zero */
1157 u64 base_address; 1176 u64 base_address;
1158 u64 length; 1177 u64 length;
1159 u32 memory_type; /* See acpi_address_range_id */ 1178 u32 reserved1;
1160 u32 flags; 1179 u32 flags;
1161 u64 reserved1; /* Reserved, must be zero */ 1180 u64 reserved2; /* Reserved, must be zero */
1162}; 1181};
1163 1182
1164/* Flags */ 1183/* Flags */
diff --git a/include/acpi/actypes.h b/include/acpi/actypes.h
index dfea2d440488..4ea4f40bf894 100644
--- a/include/acpi/actypes.h
+++ b/include/acpi/actypes.h
@@ -110,10 +110,10 @@
110 * usually used for memory allocation, efficient loop counters, and array 110 * usually used for memory allocation, efficient loop counters, and array
111 * indexes. The types are similar to the size_t type in the C library and are 111 * indexes. The types are similar to the size_t type in the C library and are
112 * required because there is no C type that consistently represents the native 112 * required because there is no C type that consistently represents the native
113 * data width. 113 * data width. ACPI_SIZE is needed because there is no guarantee that a
114 * kernel-level C library is present.
114 * 115 *
115 * ACPI_SIZE 16/32/64-bit unsigned value 116 * ACPI_SIZE 16/32/64-bit unsigned value
116 * ACPI_NATIVE_UINT 16/32/64-bit unsigned value
117 * ACPI_NATIVE_INT 16/32/64-bit signed value 117 * ACPI_NATIVE_INT 16/32/64-bit signed value
118 * 118 *
119 */ 119 */
@@ -147,9 +147,9 @@ typedef int INT32;
147 147
148/*! [End] no source code translation !*/ 148/*! [End] no source code translation !*/
149 149
150typedef u64 acpi_native_uint;
151typedef s64 acpi_native_int; 150typedef s64 acpi_native_int;
152 151
152typedef u64 acpi_size;
153typedef u64 acpi_io_address; 153typedef u64 acpi_io_address;
154typedef u64 acpi_physical_address; 154typedef u64 acpi_physical_address;
155 155
@@ -186,9 +186,9 @@ typedef int INT32;
186 186
187/*! [End] no source code translation !*/ 187/*! [End] no source code translation !*/
188 188
189typedef u32 acpi_native_uint;
190typedef s32 acpi_native_int; 189typedef s32 acpi_native_int;
191 190
191typedef u32 acpi_size;
192typedef u32 acpi_io_address; 192typedef u32 acpi_io_address;
193typedef u32 acpi_physical_address; 193typedef u32 acpi_physical_address;
194 194
@@ -202,10 +202,6 @@ typedef u32 acpi_physical_address;
202#error unknown ACPI_MACHINE_WIDTH 202#error unknown ACPI_MACHINE_WIDTH
203#endif 203#endif
204 204
205/* Variable-width type, used instead of clib size_t */
206
207typedef acpi_native_uint acpi_size;
208
209/******************************************************************************* 205/*******************************************************************************
210 * 206 *
211 * OS-dependent and compiler-dependent types 207 * OS-dependent and compiler-dependent types
@@ -219,7 +215,7 @@ typedef acpi_native_uint acpi_size;
219/* Value returned by acpi_os_get_thread_id */ 215/* Value returned by acpi_os_get_thread_id */
220 216
221#ifndef acpi_thread_id 217#ifndef acpi_thread_id
222#define acpi_thread_id acpi_native_uint 218#define acpi_thread_id acpi_size
223#endif 219#endif
224 220
225/* Object returned from acpi_os_create_lock */ 221/* Object returned from acpi_os_create_lock */
@@ -231,7 +227,7 @@ typedef acpi_native_uint acpi_size;
231/* Flags for acpi_os_acquire_lock/acpi_os_release_lock */ 227/* Flags for acpi_os_acquire_lock/acpi_os_release_lock */
232 228
233#ifndef acpi_cpu_flags 229#ifndef acpi_cpu_flags
234#define acpi_cpu_flags acpi_native_uint 230#define acpi_cpu_flags acpi_size
235#endif 231#endif
236 232
237/* Object returned from acpi_os_create_cache */ 233/* Object returned from acpi_os_create_cache */
diff --git a/include/acpi/acutils.h b/include/acpi/acutils.h
index b42cadf07302..69f8888771ff 100644
--- a/include/acpi/acutils.h
+++ b/include/acpi/acutils.h
@@ -172,7 +172,7 @@ char *acpi_ut_strstr(char *string1, char *string2);
172 172
173void *acpi_ut_memcpy(void *dest, const void *src, acpi_size count); 173void *acpi_ut_memcpy(void *dest, const void *src, acpi_size count);
174 174
175void *acpi_ut_memset(void *dest, acpi_native_uint value, acpi_size count); 175void *acpi_ut_memset(void *dest, u8 value, acpi_size count);
176 176
177int acpi_ut_to_upper(int c); 177int acpi_ut_to_upper(int c);
178 178
@@ -245,41 +245,45 @@ void acpi_ut_track_stack_ptr(void);
245 245
246void 246void
247acpi_ut_trace(u32 line_number, 247acpi_ut_trace(u32 line_number,
248 const char *function_name, char *module_name, u32 component_id); 248 const char *function_name,
249 const char *module_name, u32 component_id);
249 250
250void 251void
251acpi_ut_trace_ptr(u32 line_number, 252acpi_ut_trace_ptr(u32 line_number,
252 const char *function_name, 253 const char *function_name,
253 char *module_name, u32 component_id, void *pointer); 254 const char *module_name, u32 component_id, void *pointer);
254 255
255void 256void
256acpi_ut_trace_u32(u32 line_number, 257acpi_ut_trace_u32(u32 line_number,
257 const char *function_name, 258 const char *function_name,
258 char *module_name, u32 component_id, u32 integer); 259 const char *module_name, u32 component_id, u32 integer);
259 260
260void 261void
261acpi_ut_trace_str(u32 line_number, 262acpi_ut_trace_str(u32 line_number,
262 const char *function_name, 263 const char *function_name,
263 char *module_name, u32 component_id, char *string); 264 const char *module_name, u32 component_id, char *string);
264 265
265void 266void
266acpi_ut_exit(u32 line_number, 267acpi_ut_exit(u32 line_number,
267 const char *function_name, char *module_name, u32 component_id); 268 const char *function_name,
269 const char *module_name, u32 component_id);
268 270
269void 271void
270acpi_ut_status_exit(u32 line_number, 272acpi_ut_status_exit(u32 line_number,
271 const char *function_name, 273 const char *function_name,
272 char *module_name, u32 component_id, acpi_status status); 274 const char *module_name,
275 u32 component_id, acpi_status status);
273 276
274void 277void
275acpi_ut_value_exit(u32 line_number, 278acpi_ut_value_exit(u32 line_number,
276 const char *function_name, 279 const char *function_name,
277 char *module_name, u32 component_id, acpi_integer value); 280 const char *module_name,
281 u32 component_id, acpi_integer value);
278 282
279void 283void
280acpi_ut_ptr_exit(u32 line_number, 284acpi_ut_ptr_exit(u32 line_number,
281 const char *function_name, 285 const char *function_name,
282 char *module_name, u32 component_id, u8 * ptr); 286 const char *module_name, u32 component_id, u8 *ptr);
283 287
284void acpi_ut_dump_buffer(u8 * buffer, u32 count, u32 display, u32 component_id); 288void acpi_ut_dump_buffer(u8 * buffer, u32 count, u32 display, u32 component_id);
285 289
@@ -297,33 +301,35 @@ void ACPI_INTERNAL_VAR_XFACE
297acpi_ut_debug_print(u32 requested_debug_level, 301acpi_ut_debug_print(u32 requested_debug_level,
298 u32 line_number, 302 u32 line_number,
299 const char *function_name, 303 const char *function_name,
300 char *module_name, 304 const char *module_name,
301 u32 component_id, char *format, ...) ACPI_PRINTF_LIKE(6); 305 u32 component_id,
306 const char *format, ...) ACPI_PRINTF_LIKE(6);
302 307
303void ACPI_INTERNAL_VAR_XFACE 308void ACPI_INTERNAL_VAR_XFACE
304acpi_ut_debug_print_raw(u32 requested_debug_level, 309acpi_ut_debug_print_raw(u32 requested_debug_level,
305 u32 line_number, 310 u32 line_number,
306 const char *function_name, 311 const char *function_name,
307 char *module_name, 312 const char *module_name,
308 u32 component_id, 313 u32 component_id,
309 char *format, ...) ACPI_PRINTF_LIKE(6); 314 const char *format, ...) ACPI_PRINTF_LIKE(6);
310 315
311void ACPI_INTERNAL_VAR_XFACE 316void ACPI_INTERNAL_VAR_XFACE
312acpi_ut_error(char *module_name, 317acpi_ut_error(const char *module_name,
313 u32 line_number, char *format, ...) ACPI_PRINTF_LIKE(3); 318 u32 line_number, const char *format, ...) ACPI_PRINTF_LIKE(3);
314 319
315void ACPI_INTERNAL_VAR_XFACE 320void ACPI_INTERNAL_VAR_XFACE
316acpi_ut_exception(char *module_name, 321acpi_ut_exception(const char *module_name,
317 u32 line_number, 322 u32 line_number,
318 acpi_status status, char *format, ...) ACPI_PRINTF_LIKE(4); 323 acpi_status status,
324 const char *format, ...) ACPI_PRINTF_LIKE(4);
319 325
320void ACPI_INTERNAL_VAR_XFACE 326void ACPI_INTERNAL_VAR_XFACE
321acpi_ut_warning(char *module_name, 327acpi_ut_warning(const char *module_name,
322 u32 line_number, char *format, ...) ACPI_PRINTF_LIKE(3); 328 u32 line_number, const char *format, ...) ACPI_PRINTF_LIKE(3);
323 329
324void ACPI_INTERNAL_VAR_XFACE 330void ACPI_INTERNAL_VAR_XFACE
325acpi_ut_info(char *module_name, 331acpi_ut_info(const char *module_name,
326 u32 line_number, char *format, ...) ACPI_PRINTF_LIKE(3); 332 u32 line_number, const char *format, ...) ACPI_PRINTF_LIKE(3);
327 333
328/* 334/*
329 * utdelete - Object deletion and reference counts 335 * utdelete - Object deletion and reference counts
@@ -376,13 +382,14 @@ acpi_ut_execute_sxds(struct acpi_namespace_node *device_node, u8 * highest);
376/* 382/*
377 * utobject - internal object create/delete/cache routines 383 * utobject - internal object create/delete/cache routines
378 */ 384 */
379union acpi_operand_object *acpi_ut_create_internal_object_dbg(char *module_name, 385union acpi_operand_object *acpi_ut_create_internal_object_dbg(const char
386 *module_name,
380 u32 line_number, 387 u32 line_number,
381 u32 component_id, 388 u32 component_id,
382 acpi_object_type 389 acpi_object_type
383 type); 390 type);
384 391
385void *acpi_ut_allocate_object_desc_dbg(char *module_name, 392void *acpi_ut_allocate_object_desc_dbg(const char *module_name,
386 u32 line_number, u32 component_id); 393 u32 line_number, u32 component_id);
387 394
388#define acpi_ut_create_internal_object(t) acpi_ut_create_internal_object_dbg (_acpi_module_name,__LINE__,_COMPONENT,t) 395#define acpi_ut_create_internal_object(t) acpi_ut_create_internal_object_dbg (_acpi_module_name,__LINE__,_COMPONENT,t)
@@ -476,7 +483,7 @@ u8 acpi_ut_valid_acpi_name(u32 name);
476 483
477acpi_name acpi_ut_repair_name(char *name); 484acpi_name acpi_ut_repair_name(char *name);
478 485
479u8 acpi_ut_valid_acpi_char(char character, acpi_native_uint position); 486u8 acpi_ut_valid_acpi_char(char character, u32 position);
480 487
481acpi_status 488acpi_status
482acpi_ut_strtoul64(char *string, u32 base, acpi_integer * ret_integer); 489acpi_ut_strtoul64(char *string, u32 base, acpi_integer * ret_integer);
@@ -543,26 +550,29 @@ acpi_status
543acpi_ut_initialize_buffer(struct acpi_buffer *buffer, 550acpi_ut_initialize_buffer(struct acpi_buffer *buffer,
544 acpi_size required_length); 551 acpi_size required_length);
545 552
546void *acpi_ut_allocate(acpi_size size, u32 component, char *module, u32 line); 553void *acpi_ut_allocate(acpi_size size,
554 u32 component, const char *module, u32 line);
547 555
548void *acpi_ut_allocate_zeroed(acpi_size size, 556void *acpi_ut_allocate_zeroed(acpi_size size,
549 u32 component, char *module, u32 line); 557 u32 component, const char *module, u32 line);
550 558
551#ifdef ACPI_DBG_TRACK_ALLOCATIONS 559#ifdef ACPI_DBG_TRACK_ALLOCATIONS
552void *acpi_ut_allocate_and_track(acpi_size size, 560void *acpi_ut_allocate_and_track(acpi_size size,
553 u32 component, char *module, u32 line); 561 u32 component, const char *module, u32 line);
554 562
555void *acpi_ut_allocate_zeroed_and_track(acpi_size size, 563void *acpi_ut_allocate_zeroed_and_track(acpi_size size,
556 u32 component, char *module, u32 line); 564 u32 component,
565 const char *module, u32 line);
557 566
558void 567void
559acpi_ut_free_and_track(void *address, u32 component, char *module, u32 line); 568acpi_ut_free_and_track(void *address,
569 u32 component, const char *module, u32 line);
560 570
561#ifdef ACPI_FUTURE_USAGE 571#ifdef ACPI_FUTURE_USAGE
562void acpi_ut_dump_allocation_info(void); 572void acpi_ut_dump_allocation_info(void);
563#endif /* ACPI_FUTURE_USAGE */ 573#endif /* ACPI_FUTURE_USAGE */
564 574
565void acpi_ut_dump_allocations(u32 component, char *module); 575void acpi_ut_dump_allocations(u32 component, const char *module);
566 576
567acpi_status 577acpi_status
568acpi_ut_create_list(char *list_name, 578acpi_ut_create_list(char *list_name,
diff --git a/include/acpi/processor.h b/include/acpi/processor.h
index 06ebb6ef72aa..3795590e152a 100644
--- a/include/acpi/processor.h
+++ b/include/acpi/processor.h
@@ -255,7 +255,7 @@ extern void acpi_processor_unregister_performance(struct
255int acpi_processor_notify_smm(struct module *calling_module); 255int acpi_processor_notify_smm(struct module *calling_module);
256 256
257/* for communication between multiple parts of the processor kernel module */ 257/* for communication between multiple parts of the processor kernel module */
258extern struct acpi_processor *processors[NR_CPUS]; 258DECLARE_PER_CPU(struct acpi_processor *, processors);
259extern struct acpi_processor_errata errata; 259extern struct acpi_processor_errata errata;
260 260
261void arch_acpi_processor_init_pdc(struct acpi_processor *pr); 261void arch_acpi_processor_init_pdc(struct acpi_processor *pr);
diff --git a/include/acpi/reboot.h b/include/acpi/reboot.h
index 8857f57e0b78..0419184ce886 100644
--- a/include/acpi/reboot.h
+++ b/include/acpi/reboot.h
@@ -1,9 +1,11 @@
1#ifndef __ACPI_REBOOT_H
2#define __ACPI_REBOOT_H
3
4#ifdef CONFIG_ACPI
5extern void acpi_reboot(void);
6#else
7static inline void acpi_reboot(void) { }
8#endif
1 9
2/*
3 * Dummy placeholder to make the EFI patches apply to the x86 tree.
4 * Andrew/Len, please just kill this file if you encounter it.
5 */
6#ifndef acpi_reboot
7# define acpi_reboot() do { } while (0)
8#endif 10#endif
9 11
diff --git a/include/asm-ia64/processor.h b/include/asm-ia64/processor.h
index 6aff126fc07e..f88fa054d01d 100644
--- a/include/asm-ia64/processor.h
+++ b/include/asm-ia64/processor.h
@@ -763,6 +763,8 @@ prefetchw (const void *x)
763#define spin_lock_prefetch(x) prefetchw(x) 763#define spin_lock_prefetch(x) prefetchw(x)
764 764
765extern unsigned long boot_option_idle_override; 765extern unsigned long boot_option_idle_override;
766extern unsigned long idle_halt;
767extern unsigned long idle_nomwait;
766 768
767#endif /* !__ASSEMBLY__ */ 769#endif /* !__ASSEMBLY__ */
768 770
diff --git a/include/asm-x86/processor.h b/include/asm-x86/processor.h
index 7f7382704592..55402d2ab938 100644
--- a/include/asm-x86/processor.h
+++ b/include/asm-x86/processor.h
@@ -727,6 +727,8 @@ extern int force_mwait;
727extern void select_idle_routine(const struct cpuinfo_x86 *c); 727extern void select_idle_routine(const struct cpuinfo_x86 *c);
728 728
729extern unsigned long boot_option_idle_override; 729extern unsigned long boot_option_idle_override;
730extern unsigned long idle_halt;
731extern unsigned long idle_nomwait;
730 732
731extern void enable_sep_cpu(void); 733extern void enable_sep_cpu(void);
732extern int sysenter_setup(void); 734extern int sysenter_setup(void);
diff --git a/include/linux/freezer.h b/include/linux/freezer.h
index 08934995c7ab..deddeedf3257 100644
--- a/include/linux/freezer.h
+++ b/include/linux/freezer.h
@@ -128,6 +128,15 @@ static inline void set_freezable(void)
128} 128}
129 129
130/* 130/*
131 * Tell the freezer that the current task should be frozen by it and that it
132 * should send a fake signal to the task to freeze it.
133 */
134static inline void set_freezable_with_signal(void)
135{
136 current->flags &= ~(PF_NOFREEZE | PF_FREEZER_NOSIG);
137}
138
139/*
131 * Freezer-friendly wrappers around wait_event_interruptible() and 140 * Freezer-friendly wrappers around wait_event_interruptible() and
132 * wait_event_interruptible_timeout(), originally defined in <linux/wait.h> 141 * wait_event_interruptible_timeout(), originally defined in <linux/wait.h>
133 */ 142 */
@@ -174,6 +183,7 @@ static inline void freezer_do_not_count(void) {}
174static inline void freezer_count(void) {} 183static inline void freezer_count(void) {}
175static inline int freezer_should_skip(struct task_struct *p) { return 0; } 184static inline int freezer_should_skip(struct task_struct *p) { return 0; }
176static inline void set_freezable(void) {} 185static inline void set_freezable(void) {}
186static inline void set_freezable_with_signal(void) {}
177 187
178#define wait_event_freezable(wq, condition) \ 188#define wait_event_freezable(wq, condition) \
179 wait_event_interruptible(wq, condition) 189 wait_event_interruptible(wq, condition)
diff --git a/include/linux/ioport.h b/include/linux/ioport.h
index c6801bffe76d..2cd07cc29687 100644
--- a/include/linux/ioport.h
+++ b/include/linux/ioport.h
@@ -59,6 +59,7 @@ struct resource_list {
59#define IORESOURCE_IRQ_HIGHLEVEL (1<<2) 59#define IORESOURCE_IRQ_HIGHLEVEL (1<<2)
60#define IORESOURCE_IRQ_LOWLEVEL (1<<3) 60#define IORESOURCE_IRQ_LOWLEVEL (1<<3)
61#define IORESOURCE_IRQ_SHAREABLE (1<<4) 61#define IORESOURCE_IRQ_SHAREABLE (1<<4)
62#define IORESOURCE_IRQ_OPTIONAL (1<<5)
62 63
63/* PnP DMA specific bits (IORESOURCE_BITS) */ 64/* PnP DMA specific bits (IORESOURCE_BITS) */
64#define IORESOURCE_DMA_TYPE_MASK (3<<0) 65#define IORESOURCE_DMA_TYPE_MASK (3<<0)
@@ -88,6 +89,10 @@ struct resource_list {
88#define IORESOURCE_MEM_SHADOWABLE (1<<5) /* dup: IORESOURCE_SHADOWABLE */ 89#define IORESOURCE_MEM_SHADOWABLE (1<<5) /* dup: IORESOURCE_SHADOWABLE */
89#define IORESOURCE_MEM_EXPANSIONROM (1<<6) 90#define IORESOURCE_MEM_EXPANSIONROM (1<<6)
90 91
92/* PnP I/O specific bits (IORESOURCE_BITS) */
93#define IORESOURCE_IO_16BIT_ADDR (1<<0)
94#define IORESOURCE_IO_FIXED (1<<1)
95
91/* PCI ROM control bits (IORESOURCE_BITS) */ 96/* PCI ROM control bits (IORESOURCE_BITS) */
92#define IORESOURCE_ROM_ENABLE (1<<0) /* ROM is enabled, same as PCI_ROM_ADDRESS_ENABLE */ 97#define IORESOURCE_ROM_ENABLE (1<<0) /* ROM is enabled, same as PCI_ROM_ADDRESS_ENABLE */
93#define IORESOURCE_ROM_SHADOW (1<<1) /* ROM is copy at C000:0 */ 98#define IORESOURCE_ROM_SHADOW (1<<1) /* ROM is copy at C000:0 */
diff --git a/include/linux/pnp.h b/include/linux/pnp.h
index 63b128d512fb..1ce54b63085d 100644
--- a/include/linux/pnp.h
+++ b/include/linux/pnp.h
@@ -1,6 +1,8 @@
1/* 1/*
2 * Linux Plug and Play Support 2 * Linux Plug and Play Support
3 * Copyright by Adam Belay <ambx1@neo.rr.com> 3 * Copyright by Adam Belay <ambx1@neo.rr.com>
4 * Copyright (C) 2008 Hewlett-Packard Development Company, L.P.
5 * Bjorn Helgaas <bjorn.helgaas@hp.com>
4 */ 6 */
5 7
6#ifndef _LINUX_PNP_H 8#ifndef _LINUX_PNP_H
@@ -15,7 +17,6 @@
15 17
16struct pnp_protocol; 18struct pnp_protocol;
17struct pnp_dev; 19struct pnp_dev;
18struct pnp_resource_table;
19 20
20/* 21/*
21 * Resource Management 22 * Resource Management
@@ -24,7 +25,14 @@ struct resource *pnp_get_resource(struct pnp_dev *, unsigned int, unsigned int);
24 25
25static inline int pnp_resource_valid(struct resource *res) 26static inline int pnp_resource_valid(struct resource *res)
26{ 27{
27 if (res && !(res->flags & IORESOURCE_UNSET)) 28 if (res)
29 return 1;
30 return 0;
31}
32
33static inline int pnp_resource_enabled(struct resource *res)
34{
35 if (res && !(res->flags & IORESOURCE_DISABLED))
28 return 1; 36 return 1;
29 return 0; 37 return 0;
30} 38}
@@ -40,19 +48,31 @@ static inline resource_size_t pnp_resource_len(struct resource *res)
40static inline resource_size_t pnp_port_start(struct pnp_dev *dev, 48static inline resource_size_t pnp_port_start(struct pnp_dev *dev,
41 unsigned int bar) 49 unsigned int bar)
42{ 50{
43 return pnp_get_resource(dev, IORESOURCE_IO, bar)->start; 51 struct resource *res = pnp_get_resource(dev, IORESOURCE_IO, bar);
52
53 if (pnp_resource_valid(res))
54 return res->start;
55 return 0;
44} 56}
45 57
46static inline resource_size_t pnp_port_end(struct pnp_dev *dev, 58static inline resource_size_t pnp_port_end(struct pnp_dev *dev,
47 unsigned int bar) 59 unsigned int bar)
48{ 60{
49 return pnp_get_resource(dev, IORESOURCE_IO, bar)->end; 61 struct resource *res = pnp_get_resource(dev, IORESOURCE_IO, bar);
62
63 if (pnp_resource_valid(res))
64 return res->end;
65 return 0;
50} 66}
51 67
52static inline unsigned long pnp_port_flags(struct pnp_dev *dev, 68static inline unsigned long pnp_port_flags(struct pnp_dev *dev,
53 unsigned int bar) 69 unsigned int bar)
54{ 70{
55 return pnp_get_resource(dev, IORESOURCE_IO, bar)->flags; 71 struct resource *res = pnp_get_resource(dev, IORESOURCE_IO, bar);
72
73 if (pnp_resource_valid(res))
74 return res->flags;
75 return IORESOURCE_IO | IORESOURCE_AUTO;
56} 76}
57 77
58static inline int pnp_port_valid(struct pnp_dev *dev, unsigned int bar) 78static inline int pnp_port_valid(struct pnp_dev *dev, unsigned int bar)
@@ -63,25 +83,41 @@ static inline int pnp_port_valid(struct pnp_dev *dev, unsigned int bar)
63static inline resource_size_t pnp_port_len(struct pnp_dev *dev, 83static inline resource_size_t pnp_port_len(struct pnp_dev *dev,
64 unsigned int bar) 84 unsigned int bar)
65{ 85{
66 return pnp_resource_len(pnp_get_resource(dev, IORESOURCE_IO, bar)); 86 struct resource *res = pnp_get_resource(dev, IORESOURCE_IO, bar);
87
88 if (pnp_resource_valid(res))
89 return pnp_resource_len(res);
90 return 0;
67} 91}
68 92
69 93
70static inline resource_size_t pnp_mem_start(struct pnp_dev *dev, 94static inline resource_size_t pnp_mem_start(struct pnp_dev *dev,
71 unsigned int bar) 95 unsigned int bar)
72{ 96{
73 return pnp_get_resource(dev, IORESOURCE_MEM, bar)->start; 97 struct resource *res = pnp_get_resource(dev, IORESOURCE_MEM, bar);
98
99 if (pnp_resource_valid(res))
100 return res->start;
101 return 0;
74} 102}
75 103
76static inline resource_size_t pnp_mem_end(struct pnp_dev *dev, 104static inline resource_size_t pnp_mem_end(struct pnp_dev *dev,
77 unsigned int bar) 105 unsigned int bar)
78{ 106{
79 return pnp_get_resource(dev, IORESOURCE_MEM, bar)->end; 107 struct resource *res = pnp_get_resource(dev, IORESOURCE_MEM, bar);
108
109 if (pnp_resource_valid(res))
110 return res->end;
111 return 0;
80} 112}
81 113
82static inline unsigned long pnp_mem_flags(struct pnp_dev *dev, unsigned int bar) 114static inline unsigned long pnp_mem_flags(struct pnp_dev *dev, unsigned int bar)
83{ 115{
84 return pnp_get_resource(dev, IORESOURCE_MEM, bar)->flags; 116 struct resource *res = pnp_get_resource(dev, IORESOURCE_MEM, bar);
117
118 if (pnp_resource_valid(res))
119 return res->flags;
120 return IORESOURCE_MEM | IORESOURCE_AUTO;
85} 121}
86 122
87static inline int pnp_mem_valid(struct pnp_dev *dev, unsigned int bar) 123static inline int pnp_mem_valid(struct pnp_dev *dev, unsigned int bar)
@@ -92,18 +128,30 @@ static inline int pnp_mem_valid(struct pnp_dev *dev, unsigned int bar)
92static inline resource_size_t pnp_mem_len(struct pnp_dev *dev, 128static inline resource_size_t pnp_mem_len(struct pnp_dev *dev,
93 unsigned int bar) 129 unsigned int bar)
94{ 130{
95 return pnp_resource_len(pnp_get_resource(dev, IORESOURCE_MEM, bar)); 131 struct resource *res = pnp_get_resource(dev, IORESOURCE_MEM, bar);
132
133 if (pnp_resource_valid(res))
134 return pnp_resource_len(res);
135 return 0;
96} 136}
97 137
98 138
99static inline resource_size_t pnp_irq(struct pnp_dev *dev, unsigned int bar) 139static inline resource_size_t pnp_irq(struct pnp_dev *dev, unsigned int bar)
100{ 140{
101 return pnp_get_resource(dev, IORESOURCE_IRQ, bar)->start; 141 struct resource *res = pnp_get_resource(dev, IORESOURCE_IRQ, bar);
142
143 if (pnp_resource_valid(res))
144 return res->start;
145 return -1;
102} 146}
103 147
104static inline unsigned long pnp_irq_flags(struct pnp_dev *dev, unsigned int bar) 148static inline unsigned long pnp_irq_flags(struct pnp_dev *dev, unsigned int bar)
105{ 149{
106 return pnp_get_resource(dev, IORESOURCE_IRQ, bar)->flags; 150 struct resource *res = pnp_get_resource(dev, IORESOURCE_IRQ, bar);
151
152 if (pnp_resource_valid(res))
153 return res->flags;
154 return IORESOURCE_IRQ | IORESOURCE_AUTO;
107} 155}
108 156
109static inline int pnp_irq_valid(struct pnp_dev *dev, unsigned int bar) 157static inline int pnp_irq_valid(struct pnp_dev *dev, unsigned int bar)
@@ -114,12 +162,20 @@ static inline int pnp_irq_valid(struct pnp_dev *dev, unsigned int bar)
114 162
115static inline resource_size_t pnp_dma(struct pnp_dev *dev, unsigned int bar) 163static inline resource_size_t pnp_dma(struct pnp_dev *dev, unsigned int bar)
116{ 164{
117 return pnp_get_resource(dev, IORESOURCE_DMA, bar)->start; 165 struct resource *res = pnp_get_resource(dev, IORESOURCE_DMA, bar);
166
167 if (pnp_resource_valid(res))
168 return res->start;
169 return -1;
118} 170}
119 171
120static inline unsigned long pnp_dma_flags(struct pnp_dev *dev, unsigned int bar) 172static inline unsigned long pnp_dma_flags(struct pnp_dev *dev, unsigned int bar)
121{ 173{
122 return pnp_get_resource(dev, IORESOURCE_DMA, bar)->flags; 174 struct resource *res = pnp_get_resource(dev, IORESOURCE_DMA, bar);
175
176 if (pnp_resource_valid(res))
177 return res->flags;
178 return IORESOURCE_DMA | IORESOURCE_AUTO;
123} 179}
124 180
125static inline int pnp_dma_valid(struct pnp_dev *dev, unsigned int bar) 181static inline int pnp_dma_valid(struct pnp_dev *dev, unsigned int bar)
@@ -128,57 +184,6 @@ static inline int pnp_dma_valid(struct pnp_dev *dev, unsigned int bar)
128} 184}
129 185
130 186
131#define PNP_PORT_FLAG_16BITADDR (1<<0)
132#define PNP_PORT_FLAG_FIXED (1<<1)
133
134struct pnp_port {
135 unsigned short min; /* min base number */
136 unsigned short max; /* max base number */
137 unsigned char align; /* align boundary */
138 unsigned char size; /* size of range */
139 unsigned char flags; /* port flags */
140 unsigned char pad; /* pad */
141 struct pnp_port *next; /* next port */
142};
143
144#define PNP_IRQ_NR 256
145struct pnp_irq {
146 DECLARE_BITMAP(map, PNP_IRQ_NR); /* bitmask for IRQ lines */
147 unsigned char flags; /* IRQ flags */
148 unsigned char pad; /* pad */
149 struct pnp_irq *next; /* next IRQ */
150};
151
152struct pnp_dma {
153 unsigned char map; /* bitmask for DMA channels */
154 unsigned char flags; /* DMA flags */
155 struct pnp_dma *next; /* next port */
156};
157
158struct pnp_mem {
159 unsigned int min; /* min base number */
160 unsigned int max; /* max base number */
161 unsigned int align; /* align boundary */
162 unsigned int size; /* size of range */
163 unsigned char flags; /* memory flags */
164 unsigned char pad; /* pad */
165 struct pnp_mem *next; /* next memory resource */
166};
167
168#define PNP_RES_PRIORITY_PREFERRED 0
169#define PNP_RES_PRIORITY_ACCEPTABLE 1
170#define PNP_RES_PRIORITY_FUNCTIONAL 2
171#define PNP_RES_PRIORITY_INVALID 65535
172
173struct pnp_option {
174 unsigned short priority; /* priority */
175 struct pnp_port *port; /* first port */
176 struct pnp_irq *irq; /* first IRQ */
177 struct pnp_dma *dma; /* first DMA */
178 struct pnp_mem *mem; /* first memory resource */
179 struct pnp_option *next; /* used to chain dependent resources */
180};
181
182/* 187/*
183 * Device Management 188 * Device Management
184 */ 189 */
@@ -246,9 +251,9 @@ struct pnp_dev {
246 251
247 int active; 252 int active;
248 int capabilities; 253 int capabilities;
249 struct pnp_option *independent; 254 unsigned int num_dependent_sets;
250 struct pnp_option *dependent; 255 struct list_head resources;
251 struct pnp_resource_table *res; 256 struct list_head options;
252 257
253 char name[PNP_NAME_LEN]; /* contains a human-readable name */ 258 char name[PNP_NAME_LEN]; /* contains a human-readable name */
254 int flags; /* used by protocols */ 259 int flags; /* used by protocols */
@@ -425,6 +430,8 @@ void pnp_unregister_card_driver(struct pnp_card_driver *drv);
425extern struct list_head pnp_cards; 430extern struct list_head pnp_cards;
426 431
427/* resource management */ 432/* resource management */
433int pnp_possible_config(struct pnp_dev *dev, int type, resource_size_t base,
434 resource_size_t size);
428int pnp_auto_config_dev(struct pnp_dev *dev); 435int pnp_auto_config_dev(struct pnp_dev *dev);
429int pnp_start_dev(struct pnp_dev *dev); 436int pnp_start_dev(struct pnp_dev *dev);
430int pnp_stop_dev(struct pnp_dev *dev); 437int pnp_stop_dev(struct pnp_dev *dev);
@@ -452,6 +459,9 @@ static inline int pnp_register_card_driver(struct pnp_card_driver *drv) { return
452static inline void pnp_unregister_card_driver(struct pnp_card_driver *drv) { } 459static inline void pnp_unregister_card_driver(struct pnp_card_driver *drv) { }
453 460
454/* resource management */ 461/* resource management */
462static inline int pnp_possible_config(struct pnp_dev *dev, int type,
463 resource_size_t base,
464 resource_size_t size) { return 0; }
455static inline int pnp_auto_config_dev(struct pnp_dev *dev) { return -ENODEV; } 465static inline int pnp_auto_config_dev(struct pnp_dev *dev) { return -ENODEV; }
456static inline int pnp_start_dev(struct pnp_dev *dev) { return -ENODEV; } 466static inline int pnp_start_dev(struct pnp_dev *dev) { return -ENODEV; }
457static inline int pnp_stop_dev(struct pnp_dev *dev) { return -ENODEV; } 467static inline int pnp_stop_dev(struct pnp_dev *dev) { return -ENODEV; }
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 21349173d148..ba2f859c6e4f 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1494,6 +1494,7 @@ static inline void put_task_struct(struct task_struct *t)
1494#define PF_MEMPOLICY 0x10000000 /* Non-default NUMA mempolicy */ 1494#define PF_MEMPOLICY 0x10000000 /* Non-default NUMA mempolicy */
1495#define PF_MUTEX_TESTER 0x20000000 /* Thread belongs to the rt mutex tester */ 1495#define PF_MUTEX_TESTER 0x20000000 /* Thread belongs to the rt mutex tester */
1496#define PF_FREEZER_SKIP 0x40000000 /* Freezer should not count it as freezeable */ 1496#define PF_FREEZER_SKIP 0x40000000 /* Freezer should not count it as freezeable */
1497#define PF_FREEZER_NOSIG 0x80000000 /* Freezer won't send signals to it */
1497 1498
1498/* 1499/*
1499 * Only the _current_ task can read/write to tsk->flags, but other 1500 * Only the _current_ task can read/write to tsk->flags, but other
diff --git a/kernel/cpu.c b/kernel/cpu.c
index b11f06dc149a..cfb1d43ab801 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -299,6 +299,7 @@ int __ref cpu_down(unsigned int cpu)
299 cpu_maps_update_done(); 299 cpu_maps_update_done();
300 return err; 300 return err;
301} 301}
302EXPORT_SYMBOL(cpu_down);
302#endif /*CONFIG_HOTPLUG_CPU*/ 303#endif /*CONFIG_HOTPLUG_CPU*/
303 304
304/* Requires cpu_add_remove_lock to be held */ 305/* Requires cpu_add_remove_lock to be held */
diff --git a/kernel/kthread.c b/kernel/kthread.c
index 97747cdd37c9..ac3fb7326641 100644
--- a/kernel/kthread.c
+++ b/kernel/kthread.c
@@ -235,7 +235,7 @@ int kthreadd(void *unused)
235 set_user_nice(tsk, KTHREAD_NICE_LEVEL); 235 set_user_nice(tsk, KTHREAD_NICE_LEVEL);
236 set_cpus_allowed(tsk, CPU_MASK_ALL); 236 set_cpus_allowed(tsk, CPU_MASK_ALL);
237 237
238 current->flags |= PF_NOFREEZE; 238 current->flags |= PF_NOFREEZE | PF_FREEZER_NOSIG;
239 239
240 for (;;) { 240 for (;;) {
241 set_current_state(TASK_INTERRUPTIBLE); 241 set_current_state(TASK_INTERRUPTIBLE);
diff --git a/kernel/power/process.c b/kernel/power/process.c
index f1d0b345c9ba..5fb87652f214 100644
--- a/kernel/power/process.c
+++ b/kernel/power/process.c
@@ -19,9 +19,6 @@
19 */ 19 */
20#define TIMEOUT (20 * HZ) 20#define TIMEOUT (20 * HZ)
21 21
22#define FREEZER_KERNEL_THREADS 0
23#define FREEZER_USER_SPACE 1
24
25static inline int freezeable(struct task_struct * p) 22static inline int freezeable(struct task_struct * p)
26{ 23{
27 if ((p == current) || 24 if ((p == current) ||
@@ -84,63 +81,53 @@ static void fake_signal_wake_up(struct task_struct *p)
84 spin_unlock_irqrestore(&p->sighand->siglock, flags); 81 spin_unlock_irqrestore(&p->sighand->siglock, flags);
85} 82}
86 83
87static int has_mm(struct task_struct *p) 84static inline bool should_send_signal(struct task_struct *p)
88{ 85{
89 return (p->mm && !(p->flags & PF_BORROWED_MM)); 86 return !(p->flags & PF_FREEZER_NOSIG);
90} 87}
91 88
92/** 89/**
93 * freeze_task - send a freeze request to given task 90 * freeze_task - send a freeze request to given task
94 * @p: task to send the request to 91 * @p: task to send the request to
95 * @with_mm_only: if set, the request will only be sent if the task has its 92 * @sig_only: if set, the request will only be sent if the task has the
96 * own mm 93 * PF_FREEZER_NOSIG flag unset
97 * Return value: 0, if @with_mm_only is set and the task has no mm of its 94 * Return value: 'false', if @sig_only is set and the task has
98 * own or the task is frozen, 1, otherwise 95 * PF_FREEZER_NOSIG set or the task is frozen, 'true', otherwise
99 * 96 *
100 * The freeze request is sent by seting the tasks's TIF_FREEZE flag and 97 * The freeze request is sent by setting the tasks's TIF_FREEZE flag and
101 * either sending a fake signal to it or waking it up, depending on whether 98 * either sending a fake signal to it or waking it up, depending on whether
102 * or not it has its own mm (ie. it is a user land task). If @with_mm_only 99 * or not it has PF_FREEZER_NOSIG set. If @sig_only is set and the task
103 * is set and the task has no mm of its own (ie. it is a kernel thread), 100 * has PF_FREEZER_NOSIG set (ie. it is a typical kernel thread), its
104 * its TIF_FREEZE flag should not be set. 101 * TIF_FREEZE flag will not be set.
105 *
106 * The task_lock() is necessary to prevent races with exit_mm() or
107 * use_mm()/unuse_mm() from occuring.
108 */ 102 */
109static int freeze_task(struct task_struct *p, int with_mm_only) 103static bool freeze_task(struct task_struct *p, bool sig_only)
110{ 104{
111 int ret = 1; 105 /*
106 * We first check if the task is freezing and next if it has already
107 * been frozen to avoid the race with frozen_process() which first marks
108 * the task as frozen and next clears its TIF_FREEZE.
109 */
110 if (!freezing(p)) {
111 rmb();
112 if (frozen(p))
113 return false;
112 114
113 task_lock(p); 115 if (!sig_only || should_send_signal(p))
114 if (freezing(p)) { 116 set_freeze_flag(p);
115 if (has_mm(p)) { 117 else
116 if (!signal_pending(p)) 118 return false;
117 fake_signal_wake_up(p); 119 }
118 } else { 120
119 if (with_mm_only) 121 if (should_send_signal(p)) {
120 ret = 0; 122 if (!signal_pending(p))
121 else 123 fake_signal_wake_up(p);
122 wake_up_state(p, TASK_INTERRUPTIBLE); 124 } else if (sig_only) {
123 } 125 return false;
124 } else { 126 } else {
125 rmb(); 127 wake_up_state(p, TASK_INTERRUPTIBLE);
126 if (frozen(p)) {
127 ret = 0;
128 } else {
129 if (has_mm(p)) {
130 set_freeze_flag(p);
131 fake_signal_wake_up(p);
132 } else {
133 if (with_mm_only) {
134 ret = 0;
135 } else {
136 set_freeze_flag(p);
137 wake_up_state(p, TASK_INTERRUPTIBLE);
138 }
139 }
140 }
141 } 128 }
142 task_unlock(p); 129
143 return ret; 130 return true;
144} 131}
145 132
146static void cancel_freezing(struct task_struct *p) 133static void cancel_freezing(struct task_struct *p)
@@ -156,7 +143,7 @@ static void cancel_freezing(struct task_struct *p)
156 } 143 }
157} 144}
158 145
159static int try_to_freeze_tasks(int freeze_user_space) 146static int try_to_freeze_tasks(bool sig_only)
160{ 147{
161 struct task_struct *g, *p; 148 struct task_struct *g, *p;
162 unsigned long end_time; 149 unsigned long end_time;
@@ -175,7 +162,7 @@ static int try_to_freeze_tasks(int freeze_user_space)
175 if (frozen(p) || !freezeable(p)) 162 if (frozen(p) || !freezeable(p))
176 continue; 163 continue;
177 164
178 if (!freeze_task(p, freeze_user_space)) 165 if (!freeze_task(p, sig_only))
179 continue; 166 continue;
180 167
181 /* 168 /*
@@ -235,13 +222,13 @@ int freeze_processes(void)
235 int error; 222 int error;
236 223
237 printk("Freezing user space processes ... "); 224 printk("Freezing user space processes ... ");
238 error = try_to_freeze_tasks(FREEZER_USER_SPACE); 225 error = try_to_freeze_tasks(true);
239 if (error) 226 if (error)
240 goto Exit; 227 goto Exit;
241 printk("done.\n"); 228 printk("done.\n");
242 229
243 printk("Freezing remaining freezable tasks ... "); 230 printk("Freezing remaining freezable tasks ... ");
244 error = try_to_freeze_tasks(FREEZER_KERNEL_THREADS); 231 error = try_to_freeze_tasks(false);
245 if (error) 232 if (error)
246 goto Exit; 233 goto Exit;
247 printk("done."); 234 printk("done.");
@@ -251,7 +238,7 @@ int freeze_processes(void)
251 return error; 238 return error;
252} 239}
253 240
254static void thaw_tasks(int thaw_user_space) 241static void thaw_tasks(bool nosig_only)
255{ 242{
256 struct task_struct *g, *p; 243 struct task_struct *g, *p;
257 244
@@ -260,7 +247,7 @@ static void thaw_tasks(int thaw_user_space)
260 if (!freezeable(p)) 247 if (!freezeable(p))
261 continue; 248 continue;
262 249
263 if (!p->mm == thaw_user_space) 250 if (nosig_only && should_send_signal(p))
264 continue; 251 continue;
265 252
266 thaw_process(p); 253 thaw_process(p);
@@ -271,8 +258,8 @@ static void thaw_tasks(int thaw_user_space)
271void thaw_processes(void) 258void thaw_processes(void)
272{ 259{
273 printk("Restarting tasks ... "); 260 printk("Restarting tasks ... ");
274 thaw_tasks(FREEZER_KERNEL_THREADS); 261 thaw_tasks(true);
275 thaw_tasks(FREEZER_USER_SPACE); 262 thaw_tasks(false);
276 schedule(); 263 schedule();
277 printk("done.\n"); 264 printk("done.\n");
278} 265}
diff --git a/kernel/power/user.c b/kernel/power/user.c
index f5512cb3aa86..a6332a313262 100644
--- a/kernel/power/user.c
+++ b/kernel/power/user.c
@@ -23,6 +23,7 @@
23#include <linux/console.h> 23#include <linux/console.h>
24#include <linux/cpu.h> 24#include <linux/cpu.h>
25#include <linux/freezer.h> 25#include <linux/freezer.h>
26#include <linux/smp_lock.h>
26 27
27#include <asm/uaccess.h> 28#include <asm/uaccess.h>
28 29
@@ -69,16 +70,22 @@ static int snapshot_open(struct inode *inode, struct file *filp)
69 struct snapshot_data *data; 70 struct snapshot_data *data;
70 int error; 71 int error;
71 72
72 if (!atomic_add_unless(&snapshot_device_available, -1, 0)) 73 mutex_lock(&pm_mutex);
73 return -EBUSY; 74
75 if (!atomic_add_unless(&snapshot_device_available, -1, 0)) {
76 error = -EBUSY;
77 goto Unlock;
78 }
74 79
75 if ((filp->f_flags & O_ACCMODE) == O_RDWR) { 80 if ((filp->f_flags & O_ACCMODE) == O_RDWR) {
76 atomic_inc(&snapshot_device_available); 81 atomic_inc(&snapshot_device_available);
77 return -ENOSYS; 82 error = -ENOSYS;
83 goto Unlock;
78 } 84 }
79 if(create_basic_memory_bitmaps()) { 85 if(create_basic_memory_bitmaps()) {
80 atomic_inc(&snapshot_device_available); 86 atomic_inc(&snapshot_device_available);
81 return -ENOMEM; 87 error = -ENOMEM;
88 goto Unlock;
82 } 89 }
83 nonseekable_open(inode, filp); 90 nonseekable_open(inode, filp);
84 data = &snapshot_state; 91 data = &snapshot_state;
@@ -98,33 +105,36 @@ static int snapshot_open(struct inode *inode, struct file *filp)
98 if (error) 105 if (error)
99 pm_notifier_call_chain(PM_POST_HIBERNATION); 106 pm_notifier_call_chain(PM_POST_HIBERNATION);
100 } 107 }
101 if (error) { 108 if (error)
102 atomic_inc(&snapshot_device_available); 109 atomic_inc(&snapshot_device_available);
103 return error;
104 }
105 data->frozen = 0; 110 data->frozen = 0;
106 data->ready = 0; 111 data->ready = 0;
107 data->platform_support = 0; 112 data->platform_support = 0;
108 113
109 return 0; 114 Unlock:
115 mutex_unlock(&pm_mutex);
116
117 return error;
110} 118}
111 119
112static int snapshot_release(struct inode *inode, struct file *filp) 120static int snapshot_release(struct inode *inode, struct file *filp)
113{ 121{
114 struct snapshot_data *data; 122 struct snapshot_data *data;
115 123
124 mutex_lock(&pm_mutex);
125
116 swsusp_free(); 126 swsusp_free();
117 free_basic_memory_bitmaps(); 127 free_basic_memory_bitmaps();
118 data = filp->private_data; 128 data = filp->private_data;
119 free_all_swap_pages(data->swap); 129 free_all_swap_pages(data->swap);
120 if (data->frozen) { 130 if (data->frozen)
121 mutex_lock(&pm_mutex);
122 thaw_processes(); 131 thaw_processes();
123 mutex_unlock(&pm_mutex);
124 }
125 pm_notifier_call_chain(data->mode == O_WRONLY ? 132 pm_notifier_call_chain(data->mode == O_WRONLY ?
126 PM_POST_HIBERNATION : PM_POST_RESTORE); 133 PM_POST_HIBERNATION : PM_POST_RESTORE);
127 atomic_inc(&snapshot_device_available); 134 atomic_inc(&snapshot_device_available);
135
136 mutex_unlock(&pm_mutex);
137
128 return 0; 138 return 0;
129} 139}
130 140
@@ -134,9 +144,13 @@ static ssize_t snapshot_read(struct file *filp, char __user *buf,
134 struct snapshot_data *data; 144 struct snapshot_data *data;
135 ssize_t res; 145 ssize_t res;
136 146
147 mutex_lock(&pm_mutex);
148
137 data = filp->private_data; 149 data = filp->private_data;
138 if (!data->ready) 150 if (!data->ready) {
139 return -ENODATA; 151 res = -ENODATA;
152 goto Unlock;
153 }
140 res = snapshot_read_next(&data->handle, count); 154 res = snapshot_read_next(&data->handle, count);
141 if (res > 0) { 155 if (res > 0) {
142 if (copy_to_user(buf, data_of(data->handle), res)) 156 if (copy_to_user(buf, data_of(data->handle), res))
@@ -144,6 +158,10 @@ static ssize_t snapshot_read(struct file *filp, char __user *buf,
144 else 158 else
145 *offp = data->handle.offset; 159 *offp = data->handle.offset;
146 } 160 }
161
162 Unlock:
163 mutex_unlock(&pm_mutex);
164
147 return res; 165 return res;
148} 166}
149 167
@@ -153,6 +171,8 @@ static ssize_t snapshot_write(struct file *filp, const char __user *buf,
153 struct snapshot_data *data; 171 struct snapshot_data *data;
154 ssize_t res; 172 ssize_t res;
155 173
174 mutex_lock(&pm_mutex);
175
156 data = filp->private_data; 176 data = filp->private_data;
157 res = snapshot_write_next(&data->handle, count); 177 res = snapshot_write_next(&data->handle, count);
158 if (res > 0) { 178 if (res > 0) {
@@ -161,11 +181,14 @@ static ssize_t snapshot_write(struct file *filp, const char __user *buf,
161 else 181 else
162 *offp = data->handle.offset; 182 *offp = data->handle.offset;
163 } 183 }
184
185 mutex_unlock(&pm_mutex);
186
164 return res; 187 return res;
165} 188}
166 189
167static int snapshot_ioctl(struct inode *inode, struct file *filp, 190static long snapshot_ioctl(struct file *filp, unsigned int cmd,
168 unsigned int cmd, unsigned long arg) 191 unsigned long arg)
169{ 192{
170 int error = 0; 193 int error = 0;
171 struct snapshot_data *data; 194 struct snapshot_data *data;
@@ -179,6 +202,9 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp,
179 if (!capable(CAP_SYS_ADMIN)) 202 if (!capable(CAP_SYS_ADMIN))
180 return -EPERM; 203 return -EPERM;
181 204
205 if (!mutex_trylock(&pm_mutex))
206 return -EBUSY;
207
182 data = filp->private_data; 208 data = filp->private_data;
183 209
184 switch (cmd) { 210 switch (cmd) {
@@ -186,7 +212,6 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp,
186 case SNAPSHOT_FREEZE: 212 case SNAPSHOT_FREEZE:
187 if (data->frozen) 213 if (data->frozen)
188 break; 214 break;
189 mutex_lock(&pm_mutex);
190 printk("Syncing filesystems ... "); 215 printk("Syncing filesystems ... ");
191 sys_sync(); 216 sys_sync();
192 printk("done.\n"); 217 printk("done.\n");
@@ -194,7 +219,6 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp,
194 error = freeze_processes(); 219 error = freeze_processes();
195 if (error) 220 if (error)
196 thaw_processes(); 221 thaw_processes();
197 mutex_unlock(&pm_mutex);
198 if (!error) 222 if (!error)
199 data->frozen = 1; 223 data->frozen = 1;
200 break; 224 break;
@@ -202,9 +226,7 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp,
202 case SNAPSHOT_UNFREEZE: 226 case SNAPSHOT_UNFREEZE:
203 if (!data->frozen || data->ready) 227 if (!data->frozen || data->ready)
204 break; 228 break;
205 mutex_lock(&pm_mutex);
206 thaw_processes(); 229 thaw_processes();
207 mutex_unlock(&pm_mutex);
208 data->frozen = 0; 230 data->frozen = 0;
209 break; 231 break;
210 232
@@ -307,16 +329,11 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp,
307 error = -EPERM; 329 error = -EPERM;
308 break; 330 break;
309 } 331 }
310 if (!mutex_trylock(&pm_mutex)) {
311 error = -EBUSY;
312 break;
313 }
314 /* 332 /*
315 * Tasks are frozen and the notifiers have been called with 333 * Tasks are frozen and the notifiers have been called with
316 * PM_HIBERNATION_PREPARE 334 * PM_HIBERNATION_PREPARE
317 */ 335 */
318 error = suspend_devices_and_enter(PM_SUSPEND_MEM); 336 error = suspend_devices_and_enter(PM_SUSPEND_MEM);
319 mutex_unlock(&pm_mutex);
320 break; 337 break;
321 338
322 case SNAPSHOT_PLATFORM_SUPPORT: 339 case SNAPSHOT_PLATFORM_SUPPORT:
@@ -390,6 +407,8 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp,
390 407
391 } 408 }
392 409
410 mutex_unlock(&pm_mutex);
411
393 return error; 412 return error;
394} 413}
395 414
@@ -399,7 +418,7 @@ static const struct file_operations snapshot_fops = {
399 .read = snapshot_read, 418 .read = snapshot_read,
400 .write = snapshot_write, 419 .write = snapshot_write,
401 .llseek = no_llseek, 420 .llseek = no_llseek,
402 .ioctl = snapshot_ioctl, 421 .unlocked_ioctl = snapshot_ioctl,
403}; 422};
404 423
405static struct miscdevice snapshot_device = { 424static struct miscdevice snapshot_device = {