aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/acpi')
-rw-r--r--drivers/acpi/Kconfig21
-rw-r--r--drivers/acpi/Makefile3
-rw-r--r--drivers/acpi/ac.c97
-rw-r--r--drivers/acpi/acpi_memhotplug.c278
-rw-r--r--drivers/acpi/asus_acpi.c337
-rw-r--r--drivers/acpi/battery.c171
-rw-r--r--drivers/acpi/bus.c133
-rw-r--r--drivers/acpi/button.c86
-rw-r--r--drivers/acpi/cm_sbs.c113
-rw-r--r--drivers/acpi/container.c38
-rw-r--r--drivers/acpi/debug.c19
-rw-r--r--drivers/acpi/dispatcher/dsinit.c40
-rw-r--r--drivers/acpi/dispatcher/dsmethod.c349
-rw-r--r--drivers/acpi/dispatcher/dswexec.c8
-rw-r--r--drivers/acpi/dispatcher/dswload.c49
-rw-r--r--drivers/acpi/dock.c739
-rw-r--r--drivers/acpi/ec.c170
-rw-r--r--drivers/acpi/event.c21
-rw-r--r--drivers/acpi/events/evgpe.c14
-rw-r--r--drivers/acpi/events/evregion.c44
-rw-r--r--drivers/acpi/events/evxface.c39
-rw-r--r--drivers/acpi/events/evxfregn.c13
-rw-r--r--drivers/acpi/executer/exconfig.c9
-rw-r--r--drivers/acpi/executer/exconvrt.c3
-rw-r--r--drivers/acpi/executer/excreate.c27
-rw-r--r--drivers/acpi/executer/exdump.c8
-rw-r--r--drivers/acpi/executer/exfldio.c71
-rw-r--r--drivers/acpi/executer/exmutex.c16
-rw-r--r--drivers/acpi/executer/exsystem.c84
-rw-r--r--drivers/acpi/fan.c63
-rw-r--r--drivers/acpi/glue.c8
-rw-r--r--drivers/acpi/hardware/hwregs.c77
-rw-r--r--drivers/acpi/hotkey.c417
-rw-r--r--drivers/acpi/i2c_ec.c406
-rw-r--r--drivers/acpi/i2c_ec.h23
-rw-r--r--drivers/acpi/motherboard.c5
-rw-r--r--drivers/acpi/namespace/nsaccess.c27
-rw-r--r--drivers/acpi/namespace/nsalloc.c13
-rw-r--r--drivers/acpi/namespace/nsxfeval.c2
-rw-r--r--drivers/acpi/numa.c14
-rw-r--r--drivers/acpi/osl.c184
-rw-r--r--drivers/acpi/parser/psparse.c18
-rw-r--r--drivers/acpi/parser/psutils.c2
-rw-r--r--drivers/acpi/pci_bind.c87
-rw-r--r--drivers/acpi/pci_irq.c92
-rw-r--r--drivers/acpi/pci_link.c211
-rw-r--r--drivers/acpi/pci_root.c59
-rw-r--r--drivers/acpi/power.c165
-rw-r--r--drivers/acpi/processor_core.c163
-rw-r--r--drivers/acpi/processor_idle.c154
-rw-r--r--drivers/acpi/processor_perflib.c138
-rw-r--r--drivers/acpi/processor_thermal.c48
-rw-r--r--drivers/acpi/processor_throttling.c45
-rw-r--r--drivers/acpi/sbs.c1769
-rw-r--r--drivers/acpi/scan.c125
-rw-r--r--drivers/acpi/sleep/proc.c6
-rw-r--r--drivers/acpi/system.c31
-rw-r--r--drivers/acpi/tables.c1
-rw-r--r--drivers/acpi/tables/tbget.c12
-rw-r--r--drivers/acpi/tables/tbinstal.c21
-rw-r--r--drivers/acpi/tables/tbrsdt.c27
-rw-r--r--drivers/acpi/tables/tbxface.c32
-rw-r--r--drivers/acpi/thermal.c296
-rw-r--r--drivers/acpi/utilities/utalloc.c6
-rw-r--r--drivers/acpi/utilities/utcache.c2
-rw-r--r--drivers/acpi/utilities/utdebug.c4
-rw-r--r--drivers/acpi/utilities/utdelete.c49
-rw-r--r--drivers/acpi/utilities/utglobal.c1
-rw-r--r--drivers/acpi/utilities/utmisc.c28
-rw-r--r--drivers/acpi/utilities/utmutex.c47
-rw-r--r--drivers/acpi/utilities/utstate.c7
-rw-r--r--drivers/acpi/utils.c110
-rw-r--r--drivers/acpi/video.c342
73 files changed, 5596 insertions, 2741 deletions
diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig
index 94b8d820c512..56c5ba874623 100644
--- a/drivers/acpi/Kconfig
+++ b/drivers/acpi/Kconfig
@@ -107,7 +107,6 @@ config ACPI_BUTTON
107config ACPI_VIDEO 107config ACPI_VIDEO
108 tristate "Video" 108 tristate "Video"
109 depends on X86 109 depends on X86
110 default y
111 help 110 help
112 This driver implement the ACPI Extensions For Display Adapters 111 This driver implement the ACPI Extensions For Display Adapters
113 for integrated graphics devices on motherboard, as specified in 112 for integrated graphics devices on motherboard, as specified in
@@ -133,6 +132,12 @@ config ACPI_FAN
133 This driver adds support for ACPI fan devices, allowing user-mode 132 This driver adds support for ACPI fan devices, allowing user-mode
134 applications to perform basic fan control (on, off, status). 133 applications to perform basic fan control (on, off, status).
135 134
135config ACPI_DOCK
136 tristate "Dock"
137 depends on EXPERIMENTAL
138 help
139 This driver adds support for ACPI controlled docking stations
140
136config ACPI_PROCESSOR 141config ACPI_PROCESSOR
137 tristate "Processor" 142 tristate "Processor"
138 default y 143 default y
@@ -207,6 +212,7 @@ config ACPI_IBM
207config ACPI_IBM_DOCK 212config ACPI_IBM_DOCK
208 bool "Legacy Docking Station Support" 213 bool "Legacy Docking Station Support"
209 depends on ACPI_IBM 214 depends on ACPI_IBM
215 depends on ACPI_DOCK=n
210 default n 216 default n
211 ---help--- 217 ---help---
212 Allows the ibm_acpi driver to handle docking station events. 218 Allows the ibm_acpi driver to handle docking station events.
@@ -328,7 +334,7 @@ config ACPI_CONTAINER
328config ACPI_HOTPLUG_MEMORY 334config ACPI_HOTPLUG_MEMORY
329 tristate "Memory Hotplug" 335 tristate "Memory Hotplug"
330 depends on ACPI 336 depends on ACPI
331 depends on MEMORY_HOTPLUG || X86_64 337 depends on MEMORY_HOTPLUG
332 default n 338 default n
333 help 339 help
334 This driver adds supports for ACPI Memory Hotplug. This driver 340 This driver adds supports for ACPI Memory Hotplug. This driver
@@ -345,6 +351,17 @@ config ACPI_HOTPLUG_MEMORY
345 If one selects "m," this driver can be loaded using the following 351 If one selects "m," this driver can be loaded using the following
346 command: 352 command:
347 $>modprobe acpi_memhotplug 353 $>modprobe acpi_memhotplug
354
355config ACPI_SBS
356 tristate "Smart Battery System (EXPERIMENTAL)"
357 depends on X86 && I2C
358 depends on EXPERIMENTAL
359 help
360 This driver adds support for the Smart Battery System.
361 Depends on I2C (Device Drivers ---> I2C support)
362 A "Smart Battery" is quite old and quite rare compared
363 to today's ACPI "Control Method" battery.
364
348endif # ACPI 365endif # ACPI
349 366
350endmenu 367endmenu
diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index 5984b4f6715a..bce7ca27b429 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -42,6 +42,7 @@ obj-$(CONFIG_ACPI_BATTERY) += battery.o
42obj-$(CONFIG_ACPI_BUTTON) += button.o 42obj-$(CONFIG_ACPI_BUTTON) += button.o
43obj-$(CONFIG_ACPI_EC) += ec.o 43obj-$(CONFIG_ACPI_EC) += ec.o
44obj-$(CONFIG_ACPI_FAN) += fan.o 44obj-$(CONFIG_ACPI_FAN) += fan.o
45obj-$(CONFIG_ACPI_DOCK) += dock.o
45obj-$(CONFIG_ACPI_VIDEO) += video.o 46obj-$(CONFIG_ACPI_VIDEO) += video.o
46obj-$(CONFIG_ACPI_HOTKEY) += hotkey.o 47obj-$(CONFIG_ACPI_HOTKEY) += hotkey.o
47obj-y += pci_root.o pci_link.o pci_irq.o pci_bind.o 48obj-y += pci_root.o pci_link.o pci_irq.o pci_bind.o
@@ -57,3 +58,5 @@ obj-$(CONFIG_ACPI_IBM) += ibm_acpi.o
57obj-$(CONFIG_ACPI_TOSHIBA) += toshiba_acpi.o 58obj-$(CONFIG_ACPI_TOSHIBA) += toshiba_acpi.o
58obj-y += scan.o motherboard.o 59obj-y += scan.o motherboard.o
59obj-$(CONFIG_ACPI_HOTPLUG_MEMORY) += acpi_memhotplug.o 60obj-$(CONFIG_ACPI_HOTPLUG_MEMORY) += acpi_memhotplug.o
61obj-y += cm_sbs.o
62obj-$(CONFIG_ACPI_SBS) += i2c_ec.o sbs.o
diff --git a/drivers/acpi/ac.c b/drivers/acpi/ac.c
index 7839b831df94..11abc7bf777e 100644
--- a/drivers/acpi/ac.c
+++ b/drivers/acpi/ac.c
@@ -50,6 +50,9 @@ ACPI_MODULE_NAME("acpi_ac")
50MODULE_DESCRIPTION(ACPI_AC_DRIVER_NAME); 50MODULE_DESCRIPTION(ACPI_AC_DRIVER_NAME);
51MODULE_LICENSE("GPL"); 51MODULE_LICENSE("GPL");
52 52
53extern struct proc_dir_entry *acpi_lock_ac_dir(void);
54extern void *acpi_unlock_ac_dir(struct proc_dir_entry *acpi_ac_dir);
55
53static int acpi_ac_add(struct acpi_device *device); 56static int acpi_ac_add(struct acpi_device *device);
54static int acpi_ac_remove(struct acpi_device *device, int type); 57static int acpi_ac_remove(struct acpi_device *device, int type);
55static int acpi_ac_open_fs(struct inode *inode, struct file *file); 58static int acpi_ac_open_fs(struct inode *inode, struct file *file);
@@ -65,11 +68,11 @@ static struct acpi_driver acpi_ac_driver = {
65}; 68};
66 69
67struct acpi_ac { 70struct acpi_ac {
68 acpi_handle handle; 71 struct acpi_device * device;
69 unsigned long state; 72 unsigned long state;
70}; 73};
71 74
72static struct file_operations acpi_ac_fops = { 75static const struct file_operations acpi_ac_fops = {
73 .open = acpi_ac_open_fs, 76 .open = acpi_ac_open_fs,
74 .read = seq_read, 77 .read = seq_read,
75 .llseek = seq_lseek, 78 .llseek = seq_lseek,
@@ -84,20 +87,18 @@ static int acpi_ac_get_state(struct acpi_ac *ac)
84{ 87{
85 acpi_status status = AE_OK; 88 acpi_status status = AE_OK;
86 89
87 ACPI_FUNCTION_TRACE("acpi_ac_get_state");
88 90
89 if (!ac) 91 if (!ac)
90 return_VALUE(-EINVAL); 92 return -EINVAL;
91 93
92 status = acpi_evaluate_integer(ac->handle, "_PSR", NULL, &ac->state); 94 status = acpi_evaluate_integer(ac->device->handle, "_PSR", NULL, &ac->state);
93 if (ACPI_FAILURE(status)) { 95 if (ACPI_FAILURE(status)) {
94 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 96 ACPI_EXCEPTION((AE_INFO, status, "Error reading AC Adapter state"));
95 "Error reading AC Adapter state\n"));
96 ac->state = ACPI_AC_STATUS_UNKNOWN; 97 ac->state = ACPI_AC_STATUS_UNKNOWN;
97 return_VALUE(-ENODEV); 98 return -ENODEV;
98 } 99 }
99 100
100 return_VALUE(0); 101 return 0;
101} 102}
102 103
103/* -------------------------------------------------------------------------- 104/* --------------------------------------------------------------------------
@@ -110,14 +111,13 @@ static int acpi_ac_seq_show(struct seq_file *seq, void *offset)
110{ 111{
111 struct acpi_ac *ac = (struct acpi_ac *)seq->private; 112 struct acpi_ac *ac = (struct acpi_ac *)seq->private;
112 113
113 ACPI_FUNCTION_TRACE("acpi_ac_seq_show");
114 114
115 if (!ac) 115 if (!ac)
116 return_VALUE(0); 116 return 0;
117 117
118 if (acpi_ac_get_state(ac)) { 118 if (acpi_ac_get_state(ac)) {
119 seq_puts(seq, "ERROR: Unable to read AC Adapter state\n"); 119 seq_puts(seq, "ERROR: Unable to read AC Adapter state\n");
120 return_VALUE(0); 120 return 0;
121 } 121 }
122 122
123 seq_puts(seq, "state: "); 123 seq_puts(seq, "state: ");
@@ -133,7 +133,7 @@ static int acpi_ac_seq_show(struct seq_file *seq, void *offset)
133 break; 133 break;
134 } 134 }
135 135
136 return_VALUE(0); 136 return 0;
137} 137}
138 138
139static int acpi_ac_open_fs(struct inode *inode, struct file *file) 139static int acpi_ac_open_fs(struct inode *inode, struct file *file)
@@ -145,13 +145,12 @@ static int acpi_ac_add_fs(struct acpi_device *device)
145{ 145{
146 struct proc_dir_entry *entry = NULL; 146 struct proc_dir_entry *entry = NULL;
147 147
148 ACPI_FUNCTION_TRACE("acpi_ac_add_fs");
149 148
150 if (!acpi_device_dir(device)) { 149 if (!acpi_device_dir(device)) {
151 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), 150 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
152 acpi_ac_dir); 151 acpi_ac_dir);
153 if (!acpi_device_dir(device)) 152 if (!acpi_device_dir(device))
154 return_VALUE(-ENODEV); 153 return -ENODEV;
155 acpi_device_dir(device)->owner = THIS_MODULE; 154 acpi_device_dir(device)->owner = THIS_MODULE;
156 } 155 }
157 156
@@ -159,21 +158,18 @@ static int acpi_ac_add_fs(struct acpi_device *device)
159 entry = create_proc_entry(ACPI_AC_FILE_STATE, 158 entry = create_proc_entry(ACPI_AC_FILE_STATE,
160 S_IRUGO, acpi_device_dir(device)); 159 S_IRUGO, acpi_device_dir(device));
161 if (!entry) 160 if (!entry)
162 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 161 return -ENODEV;
163 "Unable to create '%s' fs entry\n",
164 ACPI_AC_FILE_STATE));
165 else { 162 else {
166 entry->proc_fops = &acpi_ac_fops; 163 entry->proc_fops = &acpi_ac_fops;
167 entry->data = acpi_driver_data(device); 164 entry->data = acpi_driver_data(device);
168 entry->owner = THIS_MODULE; 165 entry->owner = THIS_MODULE;
169 } 166 }
170 167
171 return_VALUE(0); 168 return 0;
172} 169}
173 170
174static int acpi_ac_remove_fs(struct acpi_device *device) 171static int acpi_ac_remove_fs(struct acpi_device *device)
175{ 172{
176 ACPI_FUNCTION_TRACE("acpi_ac_remove_fs");
177 173
178 if (acpi_device_dir(device)) { 174 if (acpi_device_dir(device)) {
179 remove_proc_entry(ACPI_AC_FILE_STATE, acpi_device_dir(device)); 175 remove_proc_entry(ACPI_AC_FILE_STATE, acpi_device_dir(device));
@@ -182,7 +178,7 @@ static int acpi_ac_remove_fs(struct acpi_device *device)
182 acpi_device_dir(device) = NULL; 178 acpi_device_dir(device) = NULL;
183 } 179 }
184 180
185 return_VALUE(0); 181 return 0;
186} 182}
187 183
188/* -------------------------------------------------------------------------- 184/* --------------------------------------------------------------------------
@@ -194,16 +190,15 @@ static void acpi_ac_notify(acpi_handle handle, u32 event, void *data)
194 struct acpi_ac *ac = (struct acpi_ac *)data; 190 struct acpi_ac *ac = (struct acpi_ac *)data;
195 struct acpi_device *device = NULL; 191 struct acpi_device *device = NULL;
196 192
197 ACPI_FUNCTION_TRACE("acpi_ac_notify");
198 193
199 if (!ac) 194 if (!ac)
200 return_VOID; 195 return;
201
202 if (acpi_bus_get_device(ac->handle, &device))
203 return_VOID;
204 196
197 device = ac->device;
205 switch (event) { 198 switch (event) {
206 case ACPI_AC_NOTIFY_STATUS: 199 case ACPI_AC_NOTIFY_STATUS:
200 case ACPI_NOTIFY_BUS_CHECK:
201 case ACPI_NOTIFY_DEVICE_CHECK:
207 acpi_ac_get_state(ac); 202 acpi_ac_get_state(ac);
208 acpi_bus_generate_event(device, event, (u32) ac->state); 203 acpi_bus_generate_event(device, event, (u32) ac->state);
209 break; 204 break;
@@ -213,7 +208,7 @@ static void acpi_ac_notify(acpi_handle handle, u32 event, void *data)
213 break; 208 break;
214 } 209 }
215 210
216 return_VOID; 211 return;
217} 212}
218 213
219static int acpi_ac_add(struct acpi_device *device) 214static int acpi_ac_add(struct acpi_device *device)
@@ -222,17 +217,16 @@ static int acpi_ac_add(struct acpi_device *device)
222 acpi_status status = AE_OK; 217 acpi_status status = AE_OK;
223 struct acpi_ac *ac = NULL; 218 struct acpi_ac *ac = NULL;
224 219
225 ACPI_FUNCTION_TRACE("acpi_ac_add");
226 220
227 if (!device) 221 if (!device)
228 return_VALUE(-EINVAL); 222 return -EINVAL;
229 223
230 ac = kmalloc(sizeof(struct acpi_ac), GFP_KERNEL); 224 ac = kmalloc(sizeof(struct acpi_ac), GFP_KERNEL);
231 if (!ac) 225 if (!ac)
232 return_VALUE(-ENOMEM); 226 return -ENOMEM;
233 memset(ac, 0, sizeof(struct acpi_ac)); 227 memset(ac, 0, sizeof(struct acpi_ac));
234 228
235 ac->handle = device->handle; 229 ac->device = device;
236 strcpy(acpi_device_name(device), ACPI_AC_DEVICE_NAME); 230 strcpy(acpi_device_name(device), ACPI_AC_DEVICE_NAME);
237 strcpy(acpi_device_class(device), ACPI_AC_CLASS); 231 strcpy(acpi_device_class(device), ACPI_AC_CLASS);
238 acpi_driver_data(device) = ac; 232 acpi_driver_data(device) = ac;
@@ -245,12 +239,10 @@ static int acpi_ac_add(struct acpi_device *device)
245 if (result) 239 if (result)
246 goto end; 240 goto end;
247 241
248 status = acpi_install_notify_handler(ac->handle, 242 status = acpi_install_notify_handler(device->handle,
249 ACPI_DEVICE_NOTIFY, acpi_ac_notify, 243 ACPI_ALL_NOTIFY, acpi_ac_notify,
250 ac); 244 ac);
251 if (ACPI_FAILURE(status)) { 245 if (ACPI_FAILURE(status)) {
252 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
253 "Error installing notify handler\n"));
254 result = -ENODEV; 246 result = -ENODEV;
255 goto end; 247 goto end;
256 } 248 }
@@ -265,7 +257,7 @@ static int acpi_ac_add(struct acpi_device *device)
265 kfree(ac); 257 kfree(ac);
266 } 258 }
267 259
268 return_VALUE(result); 260 return result;
269} 261}
270 262
271static int acpi_ac_remove(struct acpi_device *device, int type) 263static int acpi_ac_remove(struct acpi_device *device, int type)
@@ -273,55 +265,50 @@ static int acpi_ac_remove(struct acpi_device *device, int type)
273 acpi_status status = AE_OK; 265 acpi_status status = AE_OK;
274 struct acpi_ac *ac = NULL; 266 struct acpi_ac *ac = NULL;
275 267
276 ACPI_FUNCTION_TRACE("acpi_ac_remove");
277 268
278 if (!device || !acpi_driver_data(device)) 269 if (!device || !acpi_driver_data(device))
279 return_VALUE(-EINVAL); 270 return -EINVAL;
280 271
281 ac = (struct acpi_ac *)acpi_driver_data(device); 272 ac = (struct acpi_ac *)acpi_driver_data(device);
282 273
283 status = acpi_remove_notify_handler(ac->handle, 274 status = acpi_remove_notify_handler(device->handle,
284 ACPI_DEVICE_NOTIFY, acpi_ac_notify); 275 ACPI_ALL_NOTIFY, acpi_ac_notify);
285 if (ACPI_FAILURE(status))
286 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
287 "Error removing notify handler\n"));
288 276
289 acpi_ac_remove_fs(device); 277 acpi_ac_remove_fs(device);
290 278
291 kfree(ac); 279 kfree(ac);
292 280
293 return_VALUE(0); 281 return 0;
294} 282}
295 283
296static int __init acpi_ac_init(void) 284static int __init acpi_ac_init(void)
297{ 285{
298 int result = 0; 286 int result;
299 287
300 ACPI_FUNCTION_TRACE("acpi_ac_init"); 288 if (acpi_disabled)
289 return -ENODEV;
301 290
302 acpi_ac_dir = proc_mkdir(ACPI_AC_CLASS, acpi_root_dir); 291 acpi_ac_dir = acpi_lock_ac_dir();
303 if (!acpi_ac_dir) 292 if (!acpi_ac_dir)
304 return_VALUE(-ENODEV); 293 return -ENODEV;
305 acpi_ac_dir->owner = THIS_MODULE;
306 294
307 result = acpi_bus_register_driver(&acpi_ac_driver); 295 result = acpi_bus_register_driver(&acpi_ac_driver);
308 if (result < 0) { 296 if (result < 0) {
309 remove_proc_entry(ACPI_AC_CLASS, acpi_root_dir); 297 acpi_unlock_ac_dir(acpi_ac_dir);
310 return_VALUE(-ENODEV); 298 return -ENODEV;
311 } 299 }
312 300
313 return_VALUE(0); 301 return 0;
314} 302}
315 303
316static void __exit acpi_ac_exit(void) 304static void __exit acpi_ac_exit(void)
317{ 305{
318 ACPI_FUNCTION_TRACE("acpi_ac_exit");
319 306
320 acpi_bus_unregister_driver(&acpi_ac_driver); 307 acpi_bus_unregister_driver(&acpi_ac_driver);
321 308
322 remove_proc_entry(ACPI_AC_CLASS, acpi_root_dir); 309 acpi_unlock_ac_dir(acpi_ac_dir);
323 310
324 return_VOID; 311 return;
325} 312}
326 313
327module_init(acpi_ac_init); 314module_init(acpi_ac_init);
diff --git a/drivers/acpi/acpi_memhotplug.c b/drivers/acpi/acpi_memhotplug.c
index e0a95ba72371..1dda370f402b 100644
--- a/drivers/acpi/acpi_memhotplug.c
+++ b/drivers/acpi/acpi_memhotplug.c
@@ -57,6 +57,7 @@ MODULE_LICENSE("GPL");
57 57
58static int acpi_memory_device_add(struct acpi_device *device); 58static int acpi_memory_device_add(struct acpi_device *device);
59static int acpi_memory_device_remove(struct acpi_device *device, int type); 59static int acpi_memory_device_remove(struct acpi_device *device, int type);
60static int acpi_memory_device_start(struct acpi_device *device);
60 61
61static struct acpi_driver acpi_memory_device_driver = { 62static struct acpi_driver acpi_memory_device_driver = {
62 .name = ACPI_MEMORY_DEVICE_DRIVER_NAME, 63 .name = ACPI_MEMORY_DEVICE_DRIVER_NAME,
@@ -65,48 +66,82 @@ static struct acpi_driver acpi_memory_device_driver = {
65 .ops = { 66 .ops = {
66 .add = acpi_memory_device_add, 67 .add = acpi_memory_device_add,
67 .remove = acpi_memory_device_remove, 68 .remove = acpi_memory_device_remove,
69 .start = acpi_memory_device_start,
68 }, 70 },
69}; 71};
70 72
71struct acpi_memory_device { 73struct acpi_memory_info {
72 acpi_handle handle; 74 struct list_head list;
73 unsigned int state; /* State of the memory device */
74 unsigned short caching; /* memory cache attribute */
75 unsigned short write_protect; /* memory read/write attribute */
76 u64 start_addr; /* Memory Range start physical addr */ 75 u64 start_addr; /* Memory Range start physical addr */
77 u64 length; /* Memory Range length */ 76 u64 length; /* Memory Range length */
77 unsigned short caching; /* memory cache attribute */
78 unsigned short write_protect; /* memory read/write attribute */
79 unsigned int enabled:1;
78}; 80};
79 81
82struct acpi_memory_device {
83 struct acpi_device * device;
84 unsigned int state; /* State of the memory device */
85 struct list_head res_list;
86};
87
88static acpi_status
89acpi_memory_get_resource(struct acpi_resource *resource, void *context)
90{
91 struct acpi_memory_device *mem_device = context;
92 struct acpi_resource_address64 address64;
93 struct acpi_memory_info *info, *new;
94 acpi_status status;
95
96 status = acpi_resource_to_address64(resource, &address64);
97 if (ACPI_FAILURE(status) ||
98 (address64.resource_type != ACPI_MEMORY_RANGE))
99 return AE_OK;
100
101 list_for_each_entry(info, &mem_device->res_list, list) {
102 /* Can we combine the resource range information? */
103 if ((info->caching == address64.info.mem.caching) &&
104 (info->write_protect == address64.info.mem.write_protect) &&
105 (info->start_addr + info->length == address64.minimum)) {
106 info->length += address64.address_length;
107 return AE_OK;
108 }
109 }
110
111 new = kzalloc(sizeof(struct acpi_memory_info), GFP_KERNEL);
112 if (!new)
113 return AE_ERROR;
114
115 INIT_LIST_HEAD(&new->list);
116 new->caching = address64.info.mem.caching;
117 new->write_protect = address64.info.mem.write_protect;
118 new->start_addr = address64.minimum;
119 new->length = address64.address_length;
120 list_add_tail(&new->list, &mem_device->res_list);
121
122 return AE_OK;
123}
124
80static int 125static int
81acpi_memory_get_device_resources(struct acpi_memory_device *mem_device) 126acpi_memory_get_device_resources(struct acpi_memory_device *mem_device)
82{ 127{
83 acpi_status status; 128 acpi_status status;
84 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; 129 struct acpi_memory_info *info, *n;
85 struct acpi_resource *resource = NULL;
86 struct acpi_resource_address64 address64;
87 130
88 ACPI_FUNCTION_TRACE("acpi_memory_get_device_resources");
89 131
90 /* Get the range from the _CRS */ 132 if (!list_empty(&mem_device->res_list))
91 status = acpi_get_current_resources(mem_device->handle, &buffer); 133 return 0;
92 if (ACPI_FAILURE(status))
93 return_VALUE(-EINVAL);
94 134
95 resource = (struct acpi_resource *)buffer.pointer; 135 status = acpi_walk_resources(mem_device->device->handle, METHOD_NAME__CRS,
96 status = acpi_resource_to_address64(resource, &address64); 136 acpi_memory_get_resource, mem_device);
97 if (ACPI_SUCCESS(status)) { 137 if (ACPI_FAILURE(status)) {
98 if (address64.resource_type == ACPI_MEMORY_RANGE) { 138 list_for_each_entry_safe(info, n, &mem_device->res_list, list)
99 /* Populate the structure */ 139 kfree(info);
100 mem_device->caching = address64.info.mem.caching; 140 INIT_LIST_HEAD(&mem_device->res_list);
101 mem_device->write_protect = 141 return -EINVAL;
102 address64.info.mem.write_protect;
103 mem_device->start_addr = address64.minimum;
104 mem_device->length = address64.address_length;
105 }
106 } 142 }
107 143
108 acpi_os_free(buffer.pointer); 144 return 0;
109 return_VALUE(0);
110} 145}
111 146
112static int 147static int
@@ -118,23 +153,21 @@ acpi_memory_get_device(acpi_handle handle,
118 struct acpi_device *device = NULL; 153 struct acpi_device *device = NULL;
119 struct acpi_device *pdevice = NULL; 154 struct acpi_device *pdevice = NULL;
120 155
121 ACPI_FUNCTION_TRACE("acpi_memory_get_device");
122 156
123 if (!acpi_bus_get_device(handle, &device) && device) 157 if (!acpi_bus_get_device(handle, &device) && device)
124 goto end; 158 goto end;
125 159
126 status = acpi_get_parent(handle, &phandle); 160 status = acpi_get_parent(handle, &phandle);
127 if (ACPI_FAILURE(status)) { 161 if (ACPI_FAILURE(status)) {
128 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error in acpi_get_parent\n")); 162 ACPI_EXCEPTION((AE_INFO, status, "Cannot find acpi parent"));
129 return_VALUE(-EINVAL); 163 return -EINVAL;
130 } 164 }
131 165
132 /* Get the parent device */ 166 /* Get the parent device */
133 status = acpi_bus_get_device(phandle, &pdevice); 167 status = acpi_bus_get_device(phandle, &pdevice);
134 if (ACPI_FAILURE(status)) { 168 if (ACPI_FAILURE(status)) {
135 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 169 ACPI_EXCEPTION((AE_INFO, status, "Cannot get acpi bus device"));
136 "Error in acpi_bus_get_device\n")); 170 return -EINVAL;
137 return_VALUE(-EINVAL);
138 } 171 }
139 172
140 /* 173 /*
@@ -143,30 +176,29 @@ acpi_memory_get_device(acpi_handle handle,
143 */ 176 */
144 status = acpi_bus_add(&device, pdevice, handle, ACPI_BUS_TYPE_DEVICE); 177 status = acpi_bus_add(&device, pdevice, handle, ACPI_BUS_TYPE_DEVICE);
145 if (ACPI_FAILURE(status)) { 178 if (ACPI_FAILURE(status)) {
146 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error in acpi_bus_add\n")); 179 ACPI_EXCEPTION((AE_INFO, status, "Cannot add acpi bus"));
147 return_VALUE(-EINVAL); 180 return -EINVAL;
148 } 181 }
149 182
150 end: 183 end:
151 *mem_device = acpi_driver_data(device); 184 *mem_device = acpi_driver_data(device);
152 if (!(*mem_device)) { 185 if (!(*mem_device)) {
153 printk(KERN_ERR "\n driver data not found"); 186 printk(KERN_ERR "\n driver data not found");
154 return_VALUE(-ENODEV); 187 return -ENODEV;
155 } 188 }
156 189
157 return_VALUE(0); 190 return 0;
158} 191}
159 192
160static int acpi_memory_check_device(struct acpi_memory_device *mem_device) 193static int acpi_memory_check_device(struct acpi_memory_device *mem_device)
161{ 194{
162 unsigned long current_status; 195 unsigned long current_status;
163 196
164 ACPI_FUNCTION_TRACE("acpi_memory_check_device");
165 197
166 /* Get device present/absent information from the _STA */ 198 /* Get device present/absent information from the _STA */
167 if (ACPI_FAILURE(acpi_evaluate_integer(mem_device->handle, "_STA", 199 if (ACPI_FAILURE(acpi_evaluate_integer(mem_device->device->handle, "_STA",
168 NULL, &current_status))) 200 NULL, &current_status)))
169 return_VALUE(-ENODEV); 201 return -ENODEV;
170 /* 202 /*
171 * Check for device status. Device should be 203 * Check for device status. Device should be
172 * present/enabled/functioning. 204 * present/enabled/functioning.
@@ -174,35 +206,48 @@ static int acpi_memory_check_device(struct acpi_memory_device *mem_device)
174 if (!((current_status & ACPI_MEMORY_STA_PRESENT) 206 if (!((current_status & ACPI_MEMORY_STA_PRESENT)
175 && (current_status & ACPI_MEMORY_STA_ENABLED) 207 && (current_status & ACPI_MEMORY_STA_ENABLED)
176 && (current_status & ACPI_MEMORY_STA_FUNCTIONAL))) 208 && (current_status & ACPI_MEMORY_STA_FUNCTIONAL)))
177 return_VALUE(-ENODEV); 209 return -ENODEV;
178 210
179 return_VALUE(0); 211 return 0;
180} 212}
181 213
182static int acpi_memory_enable_device(struct acpi_memory_device *mem_device) 214static int acpi_memory_enable_device(struct acpi_memory_device *mem_device)
183{ 215{
184 int result; 216 int result, num_enabled = 0;
217 struct acpi_memory_info *info;
218 int node;
185 219
186 ACPI_FUNCTION_TRACE("acpi_memory_enable_device");
187 220
188 /* Get the range from the _CRS */ 221 /* Get the range from the _CRS */
189 result = acpi_memory_get_device_resources(mem_device); 222 result = acpi_memory_get_device_resources(mem_device);
190 if (result) { 223 if (result) {
191 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 224 printk(KERN_ERR PREFIX "get_device_resources failed\n");
192 "\nget_device_resources failed\n"));
193 mem_device->state = MEMORY_INVALID_STATE; 225 mem_device->state = MEMORY_INVALID_STATE;
194 return result; 226 return result;
195 } 227 }
196 228
229 node = acpi_get_node(mem_device->device->handle);
197 /* 230 /*
198 * Tell the VM there is more memory here... 231 * Tell the VM there is more memory here...
199 * Note: Assume that this function returns zero on success 232 * Note: Assume that this function returns zero on success
233 * We don't have memory-hot-add rollback function,now.
234 * (i.e. memory-hot-remove function)
200 */ 235 */
201 result = add_memory(mem_device->start_addr, mem_device->length); 236 list_for_each_entry(info, &mem_device->res_list, list) {
202 if (result) { 237 if (info->enabled) { /* just sanity check...*/
203 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "\nadd_memory failed\n")); 238 num_enabled++;
239 continue;
240 }
241 result = add_memory(node, info->start_addr, info->length);
242 if (result)
243 continue;
244 info->enabled = 1;
245 num_enabled++;
246 }
247 if (!num_enabled) {
248 printk(KERN_ERR PREFIX "add_memory failed\n");
204 mem_device->state = MEMORY_INVALID_STATE; 249 mem_device->state = MEMORY_INVALID_STATE;
205 return result; 250 return -EINVAL;
206 } 251 }
207 252
208 return result; 253 return result;
@@ -215,57 +260,55 @@ static int acpi_memory_powerdown_device(struct acpi_memory_device *mem_device)
215 union acpi_object arg; 260 union acpi_object arg;
216 unsigned long current_status; 261 unsigned long current_status;
217 262
218 ACPI_FUNCTION_TRACE("acpi_memory_powerdown_device");
219 263
220 /* Issue the _EJ0 command */ 264 /* Issue the _EJ0 command */
221 arg_list.count = 1; 265 arg_list.count = 1;
222 arg_list.pointer = &arg; 266 arg_list.pointer = &arg;
223 arg.type = ACPI_TYPE_INTEGER; 267 arg.type = ACPI_TYPE_INTEGER;
224 arg.integer.value = 1; 268 arg.integer.value = 1;
225 status = acpi_evaluate_object(mem_device->handle, 269 status = acpi_evaluate_object(mem_device->device->handle,
226 "_EJ0", &arg_list, NULL); 270 "_EJ0", &arg_list, NULL);
227 /* Return on _EJ0 failure */ 271 /* Return on _EJ0 failure */
228 if (ACPI_FAILURE(status)) { 272 if (ACPI_FAILURE(status)) {
229 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "_EJ0 failed.\n")); 273 ACPI_EXCEPTION((AE_INFO, status, "_EJ0 failed"));
230 return_VALUE(-ENODEV); 274 return -ENODEV;
231 } 275 }
232 276
233 /* Evalute _STA to check if the device is disabled */ 277 /* Evalute _STA to check if the device is disabled */
234 status = acpi_evaluate_integer(mem_device->handle, "_STA", 278 status = acpi_evaluate_integer(mem_device->device->handle, "_STA",
235 NULL, &current_status); 279 NULL, &current_status);
236 if (ACPI_FAILURE(status)) 280 if (ACPI_FAILURE(status))
237 return_VALUE(-ENODEV); 281 return -ENODEV;
238 282
239 /* Check for device status. Device should be disabled */ 283 /* Check for device status. Device should be disabled */
240 if (current_status & ACPI_MEMORY_STA_ENABLED) 284 if (current_status & ACPI_MEMORY_STA_ENABLED)
241 return_VALUE(-EINVAL); 285 return -EINVAL;
242 286
243 return_VALUE(0); 287 return 0;
244} 288}
245 289
246static int acpi_memory_disable_device(struct acpi_memory_device *mem_device) 290static int acpi_memory_disable_device(struct acpi_memory_device *mem_device)
247{ 291{
248 int result; 292 int result;
249 u64 start = mem_device->start_addr; 293 struct acpi_memory_info *info, *n;
250 u64 len = mem_device->length;
251 294
252 ACPI_FUNCTION_TRACE("acpi_memory_disable_device");
253 295
254 /* 296 /*
255 * Ask the VM to offline this memory range. 297 * Ask the VM to offline this memory range.
256 * Note: Assume that this function returns zero on success 298 * Note: Assume that this function returns zero on success
257 */ 299 */
258 result = remove_memory(start, len); 300 list_for_each_entry_safe(info, n, &mem_device->res_list, list) {
259 if (result) { 301 if (info->enabled) {
260 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Hot-Remove failed.\n")); 302 result = remove_memory(info->start_addr, info->length);
261 return_VALUE(result); 303 if (result)
304 return result;
305 }
306 kfree(info);
262 } 307 }
263 308
264 /* Power-off and eject the device */ 309 /* Power-off and eject the device */
265 result = acpi_memory_powerdown_device(mem_device); 310 result = acpi_memory_powerdown_device(mem_device);
266 if (result) { 311 if (result) {
267 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
268 "Device Power Down failed.\n"));
269 /* Set the status of the device to invalid */ 312 /* Set the status of the device to invalid */
270 mem_device->state = MEMORY_INVALID_STATE; 313 mem_device->state = MEMORY_INVALID_STATE;
271 return result; 314 return result;
@@ -280,7 +323,6 @@ static void acpi_memory_device_notify(acpi_handle handle, u32 event, void *data)
280 struct acpi_memory_device *mem_device; 323 struct acpi_memory_device *mem_device;
281 struct acpi_device *device; 324 struct acpi_device *device;
282 325
283 ACPI_FUNCTION_TRACE("acpi_memory_device_notify");
284 326
285 switch (event) { 327 switch (event) {
286 case ACPI_NOTIFY_BUS_CHECK: 328 case ACPI_NOTIFY_BUS_CHECK:
@@ -292,15 +334,14 @@ static void acpi_memory_device_notify(acpi_handle handle, u32 event, void *data)
292 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 334 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
293 "\nReceived DEVICE CHECK notification for device\n")); 335 "\nReceived DEVICE CHECK notification for device\n"));
294 if (acpi_memory_get_device(handle, &mem_device)) { 336 if (acpi_memory_get_device(handle, &mem_device)) {
295 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 337 printk(KERN_ERR PREFIX "Cannot find driver data\n");
296 "Error in finding driver data\n")); 338 return;
297 return_VOID;
298 } 339 }
299 340
300 if (!acpi_memory_check_device(mem_device)) { 341 if (!acpi_memory_check_device(mem_device)) {
301 if (acpi_memory_enable_device(mem_device)) 342 if (acpi_memory_enable_device(mem_device))
302 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 343 printk(KERN_ERR PREFIX
303 "Error in acpi_memory_enable_device\n")); 344 "Cannot enable memory device\n");
304 } 345 }
305 break; 346 break;
306 case ACPI_NOTIFY_EJECT_REQUEST: 347 case ACPI_NOTIFY_EJECT_REQUEST:
@@ -308,14 +349,12 @@ static void acpi_memory_device_notify(acpi_handle handle, u32 event, void *data)
308 "\nReceived EJECT REQUEST notification for device\n")); 349 "\nReceived EJECT REQUEST notification for device\n"));
309 350
310 if (acpi_bus_get_device(handle, &device)) { 351 if (acpi_bus_get_device(handle, &device)) {
311 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 352 printk(KERN_ERR PREFIX "Device doesn't exist\n");
312 "Device doesn't exist\n"));
313 break; 353 break;
314 } 354 }
315 mem_device = acpi_driver_data(device); 355 mem_device = acpi_driver_data(device);
316 if (!mem_device) { 356 if (!mem_device) {
317 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 357 printk(KERN_ERR PREFIX "Driver Data is NULL\n");
318 "Driver Data is NULL\n"));
319 break; 358 break;
320 } 359 }
321 360
@@ -326,8 +365,8 @@ static void acpi_memory_device_notify(acpi_handle handle, u32 event, void *data)
326 * with generic sysfs driver 365 * with generic sysfs driver
327 */ 366 */
328 if (acpi_memory_disable_device(mem_device)) 367 if (acpi_memory_disable_device(mem_device))
329 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 368 printk(KERN_ERR PREFIX
330 "Error in acpi_memory_disable_device\n")); 369 "Disable memory device\n");
331 /* 370 /*
332 * TBD: Invoke acpi_bus_remove to cleanup data structures 371 * TBD: Invoke acpi_bus_remove to cleanup data structures
333 */ 372 */
@@ -338,7 +377,7 @@ static void acpi_memory_device_notify(acpi_handle handle, u32 event, void *data)
338 break; 377 break;
339 } 378 }
340 379
341 return_VOID; 380 return;
342} 381}
343 382
344static int acpi_memory_device_add(struct acpi_device *device) 383static int acpi_memory_device_add(struct acpi_device *device)
@@ -346,17 +385,17 @@ static int acpi_memory_device_add(struct acpi_device *device)
346 int result; 385 int result;
347 struct acpi_memory_device *mem_device = NULL; 386 struct acpi_memory_device *mem_device = NULL;
348 387
349 ACPI_FUNCTION_TRACE("acpi_memory_device_add");
350 388
351 if (!device) 389 if (!device)
352 return_VALUE(-EINVAL); 390 return -EINVAL;
353 391
354 mem_device = kmalloc(sizeof(struct acpi_memory_device), GFP_KERNEL); 392 mem_device = kmalloc(sizeof(struct acpi_memory_device), GFP_KERNEL);
355 if (!mem_device) 393 if (!mem_device)
356 return_VALUE(-ENOMEM); 394 return -ENOMEM;
357 memset(mem_device, 0, sizeof(struct acpi_memory_device)); 395 memset(mem_device, 0, sizeof(struct acpi_memory_device));
358 396
359 mem_device->handle = device->handle; 397 INIT_LIST_HEAD(&mem_device->res_list);
398 mem_device->device = device;
360 sprintf(acpi_device_name(device), "%s", ACPI_MEMORY_DEVICE_NAME); 399 sprintf(acpi_device_name(device), "%s", ACPI_MEMORY_DEVICE_NAME);
361 sprintf(acpi_device_class(device), "%s", ACPI_MEMORY_DEVICE_CLASS); 400 sprintf(acpi_device_class(device), "%s", ACPI_MEMORY_DEVICE_CLASS);
362 acpi_driver_data(device) = mem_device; 401 acpi_driver_data(device) = mem_device;
@@ -365,7 +404,7 @@ static int acpi_memory_device_add(struct acpi_device *device)
365 result = acpi_memory_get_device_resources(mem_device); 404 result = acpi_memory_get_device_resources(mem_device);
366 if (result) { 405 if (result) {
367 kfree(mem_device); 406 kfree(mem_device);
368 return_VALUE(result); 407 return result;
369 } 408 }
370 409
371 /* Set the device state */ 410 /* Set the device state */
@@ -373,22 +412,38 @@ static int acpi_memory_device_add(struct acpi_device *device)
373 412
374 printk(KERN_INFO "%s \n", acpi_device_name(device)); 413 printk(KERN_INFO "%s \n", acpi_device_name(device));
375 414
376 return_VALUE(result); 415 return result;
377} 416}
378 417
379static int acpi_memory_device_remove(struct acpi_device *device, int type) 418static int acpi_memory_device_remove(struct acpi_device *device, int type)
380{ 419{
381 struct acpi_memory_device *mem_device = NULL; 420 struct acpi_memory_device *mem_device = NULL;
382 421
383 ACPI_FUNCTION_TRACE("acpi_memory_device_remove");
384 422
385 if (!device || !acpi_driver_data(device)) 423 if (!device || !acpi_driver_data(device))
386 return_VALUE(-EINVAL); 424 return -EINVAL;
387 425
388 mem_device = (struct acpi_memory_device *)acpi_driver_data(device); 426 mem_device = (struct acpi_memory_device *)acpi_driver_data(device);
389 kfree(mem_device); 427 kfree(mem_device);
390 428
391 return_VALUE(0); 429 return 0;
430}
431
432static int acpi_memory_device_start (struct acpi_device *device)
433{
434 struct acpi_memory_device *mem_device;
435 int result = 0;
436
437 mem_device = acpi_driver_data(device);
438
439 if (!acpi_memory_check_device(mem_device)) {
440 /* call add_memory func */
441 result = acpi_memory_enable_device(mem_device);
442 if (result)
443 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
444 "Error in acpi_memory_enable_device\n"));
445 }
446 return result;
392} 447}
393 448
394/* 449/*
@@ -401,16 +456,15 @@ static acpi_status is_memory_device(acpi_handle handle)
401 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; 456 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
402 struct acpi_device_info *info; 457 struct acpi_device_info *info;
403 458
404 ACPI_FUNCTION_TRACE("is_memory_device");
405 459
406 status = acpi_get_object_info(handle, &buffer); 460 status = acpi_get_object_info(handle, &buffer);
407 if (ACPI_FAILURE(status)) 461 if (ACPI_FAILURE(status))
408 return_ACPI_STATUS(AE_ERROR); 462 return status;
409 463
410 info = buffer.pointer; 464 info = buffer.pointer;
411 if (!(info->valid & ACPI_VALID_HID)) { 465 if (!(info->valid & ACPI_VALID_HID)) {
412 acpi_os_free(buffer.pointer); 466 kfree(buffer.pointer);
413 return_ACPI_STATUS(AE_ERROR); 467 return AE_ERROR;
414 } 468 }
415 469
416 hardware_id = info->hardware_id.value; 470 hardware_id = info->hardware_id.value;
@@ -418,8 +472,8 @@ static acpi_status is_memory_device(acpi_handle handle)
418 (strcmp(hardware_id, ACPI_MEMORY_DEVICE_HID))) 472 (strcmp(hardware_id, ACPI_MEMORY_DEVICE_HID)))
419 status = AE_ERROR; 473 status = AE_ERROR;
420 474
421 acpi_os_free(buffer.pointer); 475 kfree(buffer.pointer);
422 return_ACPI_STATUS(status); 476 return status;
423} 477}
424 478
425static acpi_status 479static acpi_status
@@ -428,21 +482,15 @@ acpi_memory_register_notify_handler(acpi_handle handle,
428{ 482{
429 acpi_status status; 483 acpi_status status;
430 484
431 ACPI_FUNCTION_TRACE("acpi_memory_register_notify_handler");
432 485
433 status = is_memory_device(handle); 486 status = is_memory_device(handle);
434 if (ACPI_FAILURE(status)) 487 if (ACPI_FAILURE(status))
435 return_ACPI_STATUS(AE_OK); /* continue */ 488 return AE_OK; /* continue */
436 489
437 status = acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY, 490 status = acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY,
438 acpi_memory_device_notify, NULL); 491 acpi_memory_device_notify, NULL);
439 if (ACPI_FAILURE(status)) { 492 /* continue */
440 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 493 return AE_OK;
441 "Error installing notify handler\n"));
442 return_ACPI_STATUS(AE_OK); /* continue */
443 }
444
445 return_ACPI_STATUS(status);
446} 494}
447 495
448static acpi_status 496static acpi_status
@@ -451,22 +499,16 @@ acpi_memory_deregister_notify_handler(acpi_handle handle,
451{ 499{
452 acpi_status status; 500 acpi_status status;
453 501
454 ACPI_FUNCTION_TRACE("acpi_memory_deregister_notify_handler");
455 502
456 status = is_memory_device(handle); 503 status = is_memory_device(handle);
457 if (ACPI_FAILURE(status)) 504 if (ACPI_FAILURE(status))
458 return_ACPI_STATUS(AE_OK); /* continue */ 505 return AE_OK; /* continue */
459 506
460 status = acpi_remove_notify_handler(handle, 507 status = acpi_remove_notify_handler(handle,
461 ACPI_SYSTEM_NOTIFY, 508 ACPI_SYSTEM_NOTIFY,
462 acpi_memory_device_notify); 509 acpi_memory_device_notify);
463 if (ACPI_FAILURE(status)) {
464 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
465 "Error removing notify handler\n"));
466 return_ACPI_STATUS(AE_OK); /* continue */
467 }
468 510
469 return_ACPI_STATUS(status); 511 return AE_OK; /* continue */
470} 512}
471 513
472static int __init acpi_memory_device_init(void) 514static int __init acpi_memory_device_init(void)
@@ -474,12 +516,11 @@ static int __init acpi_memory_device_init(void)
474 int result; 516 int result;
475 acpi_status status; 517 acpi_status status;
476 518
477 ACPI_FUNCTION_TRACE("acpi_memory_device_init");
478 519
479 result = acpi_bus_register_driver(&acpi_memory_device_driver); 520 result = acpi_bus_register_driver(&acpi_memory_device_driver);
480 521
481 if (result < 0) 522 if (result < 0)
482 return_VALUE(-ENODEV); 523 return -ENODEV;
483 524
484 status = acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, 525 status = acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
485 ACPI_UINT32_MAX, 526 ACPI_UINT32_MAX,
@@ -487,19 +528,18 @@ static int __init acpi_memory_device_init(void)
487 NULL, NULL); 528 NULL, NULL);
488 529
489 if (ACPI_FAILURE(status)) { 530 if (ACPI_FAILURE(status)) {
490 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "walk_namespace failed\n")); 531 ACPI_EXCEPTION((AE_INFO, status, "walk_namespace failed"));
491 acpi_bus_unregister_driver(&acpi_memory_device_driver); 532 acpi_bus_unregister_driver(&acpi_memory_device_driver);
492 return_VALUE(-ENODEV); 533 return -ENODEV;
493 } 534 }
494 535
495 return_VALUE(0); 536 return 0;
496} 537}
497 538
498static void __exit acpi_memory_device_exit(void) 539static void __exit acpi_memory_device_exit(void)
499{ 540{
500 acpi_status status; 541 acpi_status status;
501 542
502 ACPI_FUNCTION_TRACE("acpi_memory_device_exit");
503 543
504 /* 544 /*
505 * Adding this to un-install notification handlers for all the device 545 * Adding this to un-install notification handlers for all the device
@@ -511,11 +551,11 @@ static void __exit acpi_memory_device_exit(void)
511 NULL, NULL); 551 NULL, NULL);
512 552
513 if (ACPI_FAILURE(status)) 553 if (ACPI_FAILURE(status))
514 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "walk_namespace failed\n")); 554 ACPI_EXCEPTION((AE_INFO, status, "walk_namespace failed"));
515 555
516 acpi_bus_unregister_driver(&acpi_memory_device_driver); 556 acpi_bus_unregister_driver(&acpi_memory_device_driver);
517 557
518 return_VOID; 558 return;
519} 559}
520 560
521module_init(acpi_memory_device_init); 561module_init(acpi_memory_device_init);
diff --git a/drivers/acpi/asus_acpi.c b/drivers/acpi/asus_acpi.c
index 839f423d738d..e9ee4c52a5f6 100644
--- a/drivers/acpi/asus_acpi.c
+++ b/drivers/acpi/asus_acpi.c
@@ -2,7 +2,7 @@
2 * asus_acpi.c - Asus Laptop ACPI Extras 2 * asus_acpi.c - Asus Laptop ACPI Extras
3 * 3 *
4 * 4 *
5 * Copyright (C) 2002, 2003, 2004 Julien Lerouge, Karol Kozimor 5 * Copyright (C) 2002-2005 Julien Lerouge, 2003-2006 Karol Kozimor
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by 8 * it under the terms of the GNU General Public License as published by
@@ -26,11 +26,8 @@
26 * Pontus Fuchs - Helper functions, cleanup 26 * Pontus Fuchs - Helper functions, cleanup
27 * Johann Wiesner - Small compile fixes 27 * Johann Wiesner - Small compile fixes
28 * John Belmonte - ACPI code for Toshiba laptop was a good starting point. 28 * John Belmonte - ACPI code for Toshiba laptop was a good starting point.
29 * Éric Burghard - LED display support for W1N
29 * 30 *
30 * TODO:
31 * add Fn key status
32 * Add mode selection on module loading (parameter) -> still necessary?
33 * Complete display switching -- may require dirty hacks or calling _DOS?
34 */ 31 */
35 32
36#include <linux/kernel.h> 33#include <linux/kernel.h>
@@ -42,12 +39,14 @@
42#include <acpi/acpi_bus.h> 39#include <acpi/acpi_bus.h>
43#include <asm/uaccess.h> 40#include <asm/uaccess.h>
44 41
45#define ASUS_ACPI_VERSION "0.29" 42#define ASUS_ACPI_VERSION "0.30"
46 43
47#define PROC_ASUS "asus" //the directory 44#define PROC_ASUS "asus" //the directory
48#define PROC_MLED "mled" 45#define PROC_MLED "mled"
49#define PROC_WLED "wled" 46#define PROC_WLED "wled"
50#define PROC_TLED "tled" 47#define PROC_TLED "tled"
48#define PROC_BT "bluetooth"
49#define PROC_LEDD "ledd"
51#define PROC_INFO "info" 50#define PROC_INFO "info"
52#define PROC_LCD "lcd" 51#define PROC_LCD "lcd"
53#define PROC_BRN "brn" 52#define PROC_BRN "brn"
@@ -67,9 +66,10 @@
67/* 66/*
68 * Flags for hotk status 67 * Flags for hotk status
69 */ 68 */
70#define MLED_ON 0x01 //is MLED ON ? 69#define MLED_ON 0x01 //mail LED
71#define WLED_ON 0x02 70#define WLED_ON 0x02 //wireless LED
72#define TLED_ON 0x04 71#define TLED_ON 0x04 //touchpad LED
72#define BT_ON 0x08 //internal Bluetooth
73 73
74MODULE_AUTHOR("Julien Lerouge, Karol Kozimor"); 74MODULE_AUTHOR("Julien Lerouge, Karol Kozimor");
75MODULE_DESCRIPTION(ACPI_HOTK_NAME); 75MODULE_DESCRIPTION(ACPI_HOTK_NAME);
@@ -92,7 +92,10 @@ struct model_data {
92 char *wled_status; //node to handle wled reading_______A 92 char *wled_status; //node to handle wled reading_______A
93 char *mt_tled; //method to handle tled_____________R 93 char *mt_tled; //method to handle tled_____________R
94 char *tled_status; //node to handle tled reading_______A 94 char *tled_status; //node to handle tled reading_______A
95 char *mt_lcd_switch; //method to turn LCD ON/OFF_________A 95 char *mt_ledd; //method to handle LED display______R
96 char *mt_bt_switch; //method to switch Bluetooth on/off_R
97 char *bt_status; //no model currently supports this__?
98 char *mt_lcd_switch; //method to turn LCD on/off_________A
96 char *lcd_status; //node to read LCD panel state______A 99 char *lcd_status; //node to read LCD panel state______A
97 char *brightness_up; //method to set brightness up_______A 100 char *brightness_up; //method to set brightness up_______A
98 char *brightness_down; //guess what ?______________________A 101 char *brightness_down; //guess what ?______________________A
@@ -111,27 +114,31 @@ struct asus_hotk {
111 struct acpi_device *device; //the device we are in 114 struct acpi_device *device; //the device we are in
112 acpi_handle handle; //the handle of the hotk device 115 acpi_handle handle; //the handle of the hotk device
113 char status; //status of the hotk, for LEDs, ... 116 char status; //status of the hotk, for LEDs, ...
117 u32 ledd_status; //status of the LED display
114 struct model_data *methods; //methods available on the laptop 118 struct model_data *methods; //methods available on the laptop
115 u8 brightness; //brightness level 119 u8 brightness; //brightness level
116 enum { 120 enum {
117 A1x = 0, //A1340D, A1300F 121 A1x = 0, //A1340D, A1300F
118 A2x, //A2500H 122 A2x, //A2500H
123 A4G, //A4700G
119 D1x, //D1 124 D1x, //D1
120 L2D, //L2000D 125 L2D, //L2000D
121 L3C, //L3800C 126 L3C, //L3800C
122 L3D, //L3400D 127 L3D, //L3400D
123 L3H, //L3H, but also L2000E 128 L3H, //L3H, L2000E, L5D
124 L4R, //L4500R 129 L4R, //L4500R
125 L5x, //L5800C 130 L5x, //L5800C
126 L8L, //L8400L 131 L8L, //L8400L
127 M1A, //M1300A 132 M1A, //M1300A
128 M2E, //M2400E, L4400L 133 M2E, //M2400E, L4400L
129 M6N, //M6800N 134 M6N, //M6800N, W3400N
130 M6R, //M6700R 135 M6R, //M6700R, A3000G
131 P30, //Samsung P30 136 P30, //Samsung P30
132 S1x, //S1300A, but also L1400B and M2400A (L84F) 137 S1x, //S1300A, but also L1400B and M2400A (L84F)
133 S2x, //S200 (J1 reported), Victor MP-XP7210 138 S2x, //S200 (J1 reported), Victor MP-XP7210
134 xxN, //M2400N, M3700N, M5200N, S1300N, S5200N, W1OOON 139 W1N, //W1000N
140 W5A, //W5A
141 xxN, //M2400N, M3700N, M5200N, M6800N, S1300N, S5200N
135 //(Centrino) 142 //(Centrino)
136 END_MODEL 143 END_MODEL
137 } model; //Models currently supported 144 } model; //Models currently supported
@@ -149,17 +156,8 @@ struct asus_hotk {
149 156
150static struct model_data model_conf[END_MODEL] = { 157static struct model_data model_conf[END_MODEL] = {
151 /* 158 /*
152 * Those pathnames are relative to the HOTK / ATKD device :
153 * - mt_mled
154 * - mt_wled
155 * - brightness_set
156 * - brightness_get
157 * - display_set
158 * - display_get
159 *
160 * TODO I have seen a SWBX and AIBX method on some models, like L1400B, 159 * TODO I have seen a SWBX and AIBX method on some models, like L1400B,
161 * it seems to be a kind of switch, but what for ? 160 * it seems to be a kind of switch, but what for ?
162 *
163 */ 161 */
164 162
165 { 163 {
@@ -184,6 +182,16 @@ static struct model_data model_conf[END_MODEL] = {
184 .display_get = "\\INFB"}, 182 .display_get = "\\INFB"},
185 183
186 { 184 {
185 .name = "A4G",
186 .mt_mled = "MLED",
187/* WLED present, but not controlled by ACPI */
188 .mt_lcd_switch = xxN_PREFIX "_Q10",
189 .brightness_set = "SPLV",
190 .brightness_get = "GPLV",
191 .display_set = "SDSP",
192 .display_get = "\\ADVG"},
193
194 {
187 .name = "D1x", 195 .name = "D1x",
188 .mt_mled = "MLED", 196 .mt_mled = "MLED",
189 .mt_lcd_switch = "\\Q0D", 197 .mt_lcd_switch = "\\Q0D",
@@ -302,7 +310,8 @@ static struct model_data model_conf[END_MODEL] = {
302 .brightness_set = "SPLV", 310 .brightness_set = "SPLV",
303 .brightness_get = "GPLV", 311 .brightness_get = "GPLV",
304 .display_set = "SDSP", 312 .display_set = "SDSP",
305 .display_get = "\\_SB.PCI0.P0P1.VGA.GETD"}, 313 .display_get = "\\SSTE"},
314
306 { 315 {
307 .name = "M6R", 316 .name = "M6R",
308 .mt_mled = "MLED", 317 .mt_mled = "MLED",
@@ -312,7 +321,7 @@ static struct model_data model_conf[END_MODEL] = {
312 .brightness_set = "SPLV", 321 .brightness_set = "SPLV",
313 .brightness_get = "GPLV", 322 .brightness_get = "GPLV",
314 .display_set = "SDSP", 323 .display_set = "SDSP",
315 .display_get = "\\SSTE"}, 324 .display_get = "\\_SB.PCI0.P0P1.VGA.GETD"},
316 325
317 { 326 {
318 .name = "P30", 327 .name = "P30",
@@ -345,6 +354,28 @@ static struct model_data model_conf[END_MODEL] = {
345 .brightness_down = S2x_PREFIX "_Q0A"}, 354 .brightness_down = S2x_PREFIX "_Q0A"},
346 355
347 { 356 {
357 .name = "W1N",
358 .mt_mled = "MLED",
359 .mt_wled = "WLED",
360 .mt_ledd = "SLCM",
361 .mt_lcd_switch = xxN_PREFIX "_Q10",
362 .lcd_status = "\\BKLT",
363 .brightness_set = "SPLV",
364 .brightness_get = "GPLV",
365 .display_set = "SDSP",
366 .display_get = "\\ADVG"},
367
368 {
369 .name = "W5A",
370 .mt_bt_switch = "BLED",
371 .mt_wled = "WLED",
372 .mt_lcd_switch = xxN_PREFIX "_Q10",
373 .brightness_set = "SPLV",
374 .brightness_get = "GPLV",
375 .display_set = "SDSP",
376 .display_get = "\\ADVG"},
377
378 {
348 .name = "xxN", 379 .name = "xxN",
349 .mt_mled = "MLED", 380 .mt_mled = "MLED",
350/* WLED present, but not controlled by ACPI */ 381/* WLED present, but not controlled by ACPI */
@@ -563,6 +594,36 @@ proc_write_mled(struct file *file, const char __user * buffer,
563} 594}
564 595
565/* 596/*
597 * Proc handlers for LED display
598 */
599static int
600proc_read_ledd(char *page, char **start, off_t off, int count, int *eof,
601 void *data)
602{
603 return sprintf(page, "0x%08x\n", hotk->ledd_status);
604}
605
606static int
607proc_write_ledd(struct file *file, const char __user * buffer,
608 unsigned long count, void *data)
609{
610 int value;
611
612 count = parse_arg(buffer, count, &value);
613 if (count > 0) {
614 if (!write_acpi_int
615 (hotk->handle, hotk->methods->mt_ledd, value, NULL))
616 printk(KERN_WARNING
617 "Asus ACPI: LED display write failed\n");
618 else
619 hotk->ledd_status = (u32) value;
620 } else if (count < 0)
621 printk(KERN_WARNING "Asus ACPI: Error reading user input\n");
622
623 return count;
624}
625
626/*
566 * Proc handlers for WLED 627 * Proc handlers for WLED
567 */ 628 */
568static int 629static int
@@ -581,6 +642,25 @@ proc_write_wled(struct file *file, const char __user * buffer,
581} 642}
582 643
583/* 644/*
645 * Proc handlers for Bluetooth
646 */
647static int
648proc_read_bluetooth(char *page, char **start, off_t off, int count, int *eof,
649 void *data)
650{
651 return sprintf(page, "%d\n", read_led(hotk->methods->bt_status, BT_ON));
652}
653
654static int
655proc_write_bluetooth(struct file *file, const char __user * buffer,
656 unsigned long count, void *data)
657{
658 /* Note: mt_bt_switch controls both internal Bluetooth adapter's
659 presence and its LED */
660 return write_led(buffer, count, hotk->methods->mt_bt_switch, BT_ON, 0);
661}
662
663/*
584 * Proc handlers for TLED 664 * Proc handlers for TLED
585 */ 665 */
586static int 666static int
@@ -876,6 +956,11 @@ static int asus_hotk_add_fs(struct acpi_device *device)
876 mode, device); 956 mode, device);
877 } 957 }
878 958
959 if (hotk->methods->mt_ledd) {
960 asus_proc_add(PROC_LEDD, &proc_write_ledd, &proc_read_ledd,
961 mode, device);
962 }
963
879 if (hotk->methods->mt_mled) { 964 if (hotk->methods->mt_mled) {
880 asus_proc_add(PROC_MLED, &proc_write_mled, &proc_read_mled, 965 asus_proc_add(PROC_MLED, &proc_write_mled, &proc_read_mled,
881 mode, device); 966 mode, device);
@@ -886,6 +971,11 @@ static int asus_hotk_add_fs(struct acpi_device *device)
886 mode, device); 971 mode, device);
887 } 972 }
888 973
974 if (hotk->methods->mt_bt_switch) {
975 asus_proc_add(PROC_BT, &proc_write_bluetooth,
976 &proc_read_bluetooth, mode, device);
977 }
978
889 /* 979 /*
890 * We need both read node and write method as LCD switch is also accessible 980 * We need both read node and write method as LCD switch is also accessible
891 * from keyboard 981 * from keyboard
@@ -919,6 +1009,10 @@ static int asus_hotk_remove_fs(struct acpi_device *device)
919 remove_proc_entry(PROC_MLED, acpi_device_dir(device)); 1009 remove_proc_entry(PROC_MLED, acpi_device_dir(device));
920 if (hotk->methods->mt_tled) 1010 if (hotk->methods->mt_tled)
921 remove_proc_entry(PROC_TLED, acpi_device_dir(device)); 1011 remove_proc_entry(PROC_TLED, acpi_device_dir(device));
1012 if (hotk->methods->mt_ledd)
1013 remove_proc_entry(PROC_LEDD, acpi_device_dir(device));
1014 if (hotk->methods->mt_bt_switch)
1015 remove_proc_entry(PROC_BT, acpi_device_dir(device));
922 if (hotk->methods->mt_lcd_switch && hotk->methods->lcd_status) 1016 if (hotk->methods->mt_lcd_switch && hotk->methods->lcd_status)
923 remove_proc_entry(PROC_LCD, acpi_device_dir(device)); 1017 remove_proc_entry(PROC_LCD, acpi_device_dir(device));
924 if ((hotk->methods->brightness_up 1018 if ((hotk->methods->brightness_up
@@ -951,6 +1045,65 @@ static void asus_hotk_notify(acpi_handle handle, u32 event, void *data)
951} 1045}
952 1046
953/* 1047/*
1048 * Match the model string to the list of supported models. Return END_MODEL if
1049 * no match or model is NULL.
1050 */
1051static int asus_model_match(char *model)
1052{
1053 if (model == NULL)
1054 return END_MODEL;
1055
1056 if (strncmp(model, "L3D", 3) == 0)
1057 return L3D;
1058 else if (strncmp(model, "L2E", 3) == 0 ||
1059 strncmp(model, "L3H", 3) == 0 || strncmp(model, "L5D", 3) == 0)
1060 return L3H;
1061 else if (strncmp(model, "L3", 2) == 0 || strncmp(model, "L2B", 3) == 0)
1062 return L3C;
1063 else if (strncmp(model, "L8L", 3) == 0)
1064 return L8L;
1065 else if (strncmp(model, "L4R", 3) == 0)
1066 return L4R;
1067 else if (strncmp(model, "M6N", 3) == 0 || strncmp(model, "W3N", 3) == 0)
1068 return M6N;
1069 else if (strncmp(model, "M6R", 3) == 0 || strncmp(model, "A3G", 3) == 0)
1070 return M6R;
1071 else if (strncmp(model, "M2N", 3) == 0 ||
1072 strncmp(model, "M3N", 3) == 0 ||
1073 strncmp(model, "M5N", 3) == 0 ||
1074 strncmp(model, "M6N", 3) == 0 ||
1075 strncmp(model, "S1N", 3) == 0 ||
1076 strncmp(model, "S5N", 3) == 0 || strncmp(model, "W1N", 3) == 0)
1077 return xxN;
1078 else if (strncmp(model, "M1", 2) == 0)
1079 return M1A;
1080 else if (strncmp(model, "M2", 2) == 0 || strncmp(model, "L4E", 3) == 0)
1081 return M2E;
1082 else if (strncmp(model, "L2", 2) == 0)
1083 return L2D;
1084 else if (strncmp(model, "L8", 2) == 0)
1085 return S1x;
1086 else if (strncmp(model, "D1", 2) == 0)
1087 return D1x;
1088 else if (strncmp(model, "A1", 2) == 0)
1089 return A1x;
1090 else if (strncmp(model, "A2", 2) == 0)
1091 return A2x;
1092 else if (strncmp(model, "J1", 2) == 0)
1093 return S2x;
1094 else if (strncmp(model, "L5", 2) == 0)
1095 return L5x;
1096 else if (strncmp(model, "A4G", 3) == 0)
1097 return A4G;
1098 else if (strncmp(model, "W1N", 3) == 0)
1099 return W1N;
1100 else if (strncmp(model, "W5A", 3) == 0)
1101 return W5A;
1102 else
1103 return END_MODEL;
1104}
1105
1106/*
954 * This function is used to initialize the hotk with right values. In this 1107 * This function is used to initialize the hotk with right values. In this
955 * method, we can make all the detection we want, and modify the hotk struct 1108 * method, we can make all the detection we want, and modify the hotk struct
956 */ 1109 */
@@ -960,6 +1113,7 @@ static int asus_hotk_get_info(void)
960 struct acpi_buffer dsdt = { ACPI_ALLOCATE_BUFFER, NULL }; 1113 struct acpi_buffer dsdt = { ACPI_ALLOCATE_BUFFER, NULL };
961 union acpi_object *model = NULL; 1114 union acpi_object *model = NULL;
962 int bsts_result; 1115 int bsts_result;
1116 char *string = NULL;
963 acpi_status status; 1117 acpi_status status;
964 1118
965 /* 1119 /*
@@ -989,114 +1143,73 @@ static int asus_hotk_get_info(void)
989 printk(KERN_NOTICE " BSTS called, 0x%02x returned\n", 1143 printk(KERN_NOTICE " BSTS called, 0x%02x returned\n",
990 bsts_result); 1144 bsts_result);
991 1145
992 /* This is unlikely with implicit return */
993 if (buffer.pointer == NULL)
994 return -EINVAL;
995
996 model = (union acpi_object *) buffer.pointer;
997 /* 1146 /*
998 * Samsung P30 has a device with a valid _HID whose INIT does not 1147 * Try to match the object returned by INIT to the specific model.
999 * return anything. It used to be possible to catch this exception, 1148 * Handle every possible object (or the lack of thereof) the DSDT
1000 * but the implicit return code will now happily confuse the 1149 * writers might throw at us. When in trouble, we pass NULL to
1001 * driver. We assume that every ACPI_TYPE_STRING is a valid model 1150 * asus_model_match() and try something completely different.
1002 * identifier but it's still possible to get completely bogus data.
1003 */ 1151 */
1004 if (model->type == ACPI_TYPE_STRING) { 1152 if (buffer.pointer) {
1005 printk(KERN_NOTICE " %s model detected, ", model->string.pointer); 1153 model = (union acpi_object *)buffer.pointer;
1006 } else { 1154 switch (model->type) {
1007 if (asus_info && /* Samsung P30 */ 1155 case ACPI_TYPE_STRING:
1156 string = model->string.pointer;
1157 break;
1158 case ACPI_TYPE_BUFFER:
1159 string = model->buffer.pointer;
1160 break;
1161 default:
1162 kfree(model);
1163 break;
1164 }
1165 }
1166 hotk->model = asus_model_match(string);
1167 if (hotk->model == END_MODEL) { /* match failed */
1168 if (asus_info &&
1008 strncmp(asus_info->oem_table_id, "ODEM", 4) == 0) { 1169 strncmp(asus_info->oem_table_id, "ODEM", 4) == 0) {
1009 hotk->model = P30; 1170 hotk->model = P30;
1010 printk(KERN_NOTICE 1171 printk(KERN_NOTICE
1011 " Samsung P30 detected, supported\n"); 1172 " Samsung P30 detected, supported\n");
1012 } else { 1173 } else {
1013 hotk->model = M2E; 1174 hotk->model = M2E;
1014 printk(KERN_WARNING " no string returned by INIT\n"); 1175 printk(KERN_NOTICE " unsupported model %s, trying "
1015 printk(KERN_WARNING " trying default values, supply " 1176 "default values\n", string);
1016 "the developers with your DSDT\n"); 1177 printk(KERN_NOTICE
1178 " send /proc/acpi/dsdt to the developers\n");
1017 } 1179 }
1018 hotk->methods = &model_conf[hotk->model]; 1180 hotk->methods = &model_conf[hotk->model];
1019
1020 acpi_os_free(model);
1021
1022 return AE_OK; 1181 return AE_OK;
1023 } 1182 }
1024
1025 hotk->model = END_MODEL;
1026 if (strncmp(model->string.pointer, "L3D", 3) == 0)
1027 hotk->model = L3D;
1028 else if (strncmp(model->string.pointer, "L3H", 3) == 0 ||
1029 strncmp(model->string.pointer, "L2E", 3) == 0)
1030 hotk->model = L3H;
1031 else if (strncmp(model->string.pointer, "L3", 2) == 0 ||
1032 strncmp(model->string.pointer, "L2B", 3) == 0)
1033 hotk->model = L3C;
1034 else if (strncmp(model->string.pointer, "L8L", 3) == 0)
1035 hotk->model = L8L;
1036 else if (strncmp(model->string.pointer, "L4R", 3) == 0)
1037 hotk->model = L4R;
1038 else if (strncmp(model->string.pointer, "M6N", 3) == 0)
1039 hotk->model = M6N;
1040 else if (strncmp(model->string.pointer, "M6R", 3) == 0)
1041 hotk->model = M6R;
1042 else if (strncmp(model->string.pointer, "M2N", 3) == 0 ||
1043 strncmp(model->string.pointer, "M3N", 3) == 0 ||
1044 strncmp(model->string.pointer, "M5N", 3) == 0 ||
1045 strncmp(model->string.pointer, "M6N", 3) == 0 ||
1046 strncmp(model->string.pointer, "S1N", 3) == 0 ||
1047 strncmp(model->string.pointer, "S5N", 3) == 0 ||
1048 strncmp(model->string.pointer, "W1N", 3) == 0)
1049 hotk->model = xxN;
1050 else if (strncmp(model->string.pointer, "M1", 2) == 0)
1051 hotk->model = M1A;
1052 else if (strncmp(model->string.pointer, "M2", 2) == 0 ||
1053 strncmp(model->string.pointer, "L4E", 3) == 0)
1054 hotk->model = M2E;
1055 else if (strncmp(model->string.pointer, "L2", 2) == 0)
1056 hotk->model = L2D;
1057 else if (strncmp(model->string.pointer, "L8", 2) == 0)
1058 hotk->model = S1x;
1059 else if (strncmp(model->string.pointer, "D1", 2) == 0)
1060 hotk->model = D1x;
1061 else if (strncmp(model->string.pointer, "A1", 2) == 0)
1062 hotk->model = A1x;
1063 else if (strncmp(model->string.pointer, "A2", 2) == 0)
1064 hotk->model = A2x;
1065 else if (strncmp(model->string.pointer, "J1", 2) == 0)
1066 hotk->model = S2x;
1067 else if (strncmp(model->string.pointer, "L5", 2) == 0)
1068 hotk->model = L5x;
1069
1070 if (hotk->model == END_MODEL) {
1071 printk("unsupported, trying default values, supply the "
1072 "developers with your DSDT\n");
1073 hotk->model = M2E;
1074 } else {
1075 printk("supported\n");
1076 }
1077
1078 hotk->methods = &model_conf[hotk->model]; 1183 hotk->methods = &model_conf[hotk->model];
1184 printk(KERN_NOTICE " %s model detected, supported\n", string);
1079 1185
1080 /* Sort of per-model blacklist */ 1186 /* Sort of per-model blacklist */
1081 if (strncmp(model->string.pointer, "L2B", 3) == 0) 1187 if (strncmp(string, "L2B", 3) == 0)
1082 hotk->methods->lcd_status = NULL; 1188 hotk->methods->lcd_status = NULL;
1083 /* L2B is similar enough to L3C to use its settings, with this only 1189 /* L2B is similar enough to L3C to use its settings, with this only
1084 exception */ 1190 exception */
1085 else if (strncmp(model->string.pointer, "S5N", 3) == 0 || 1191 else if (strncmp(string, "A3G", 3) == 0)
1086 strncmp(model->string.pointer, "M5N", 3) == 0) 1192 hotk->methods->lcd_status = "\\BLFG";
1193 /* A3G is like M6R */
1194 else if (strncmp(string, "S5N", 3) == 0 ||
1195 strncmp(string, "M5N", 3) == 0 ||
1196 strncmp(string, "W3N", 3) == 0)
1087 hotk->methods->mt_mled = NULL; 1197 hotk->methods->mt_mled = NULL;
1088 /* S5N and M5N have no MLED */ 1198 /* S5N, M5N and W3N have no MLED */
1089 else if (strncmp(model->string.pointer, "M2N", 3) == 0 || 1199 else if (strncmp(string, "L5D", 3) == 0)
1090 strncmp(model->string.pointer, "W1N", 3) == 0) 1200 hotk->methods->mt_wled = NULL;
1201 /* L5D's WLED is not controlled by ACPI */
1202 else if (strncmp(string, "M2N", 3) == 0 ||
1203 strncmp(string, "S1N", 3) == 0)
1091 hotk->methods->mt_wled = "WLED"; 1204 hotk->methods->mt_wled = "WLED";
1092 /* M2N and W1N have a usable WLED */ 1205 /* M2N and S1N have a usable WLED */
1093 else if (asus_info) { 1206 else if (asus_info) {
1094 if (strncmp(asus_info->oem_table_id, "L1", 2) == 0) 1207 if (strncmp(asus_info->oem_table_id, "L1", 2) == 0)
1095 hotk->methods->mled_status = NULL; 1208 hotk->methods->mled_status = NULL;
1096 /* S1300A reports L84F, but L1400B too, account for that */ 1209 /* S1300A reports L84F, but L1400B too, account for that */
1097 } 1210 }
1098 1211
1099 acpi_os_free(model); 1212 kfree(model);
1100 1213
1101 return AE_OK; 1214 return AE_OK;
1102} 1215}
@@ -1164,8 +1277,7 @@ static int asus_hotk_add(struct acpi_device *device)
1164 /* For laptops without GPLV: init the hotk->brightness value */ 1277 /* For laptops without GPLV: init the hotk->brightness value */
1165 if ((!hotk->methods->brightness_get) 1278 if ((!hotk->methods->brightness_get)
1166 && (!hotk->methods->brightness_status) 1279 && (!hotk->methods->brightness_status)
1167 && (hotk->methods->brightness_up 1280 && (hotk->methods->brightness_up && hotk->methods->brightness_down)) {
1168 && hotk->methods->brightness_down)) {
1169 status = 1281 status =
1170 acpi_evaluate_object(NULL, hotk->methods->brightness_down, 1282 acpi_evaluate_object(NULL, hotk->methods->brightness_down,
1171 NULL, NULL); 1283 NULL, NULL);
@@ -1184,6 +1296,9 @@ static int asus_hotk_add(struct acpi_device *device)
1184 1296
1185 asus_hotk_found = 1; 1297 asus_hotk_found = 1;
1186 1298
1299 /* LED display is off by default */
1300 hotk->ledd_status = 0xFFF;
1301
1187 end: 1302 end:
1188 if (result) { 1303 if (result) {
1189 kfree(hotk); 1304 kfree(hotk);
@@ -1232,7 +1347,7 @@ static int __init asus_acpi_init(void)
1232 result = acpi_bus_register_driver(&asus_hotk_driver); 1347 result = acpi_bus_register_driver(&asus_hotk_driver);
1233 if (result < 0) { 1348 if (result < 0) {
1234 remove_proc_entry(PROC_ASUS, acpi_root_dir); 1349 remove_proc_entry(PROC_ASUS, acpi_root_dir);
1235 return -ENODEV; 1350 return result;
1236 } 1351 }
1237 1352
1238 /* 1353 /*
@@ -1256,7 +1371,7 @@ static void __exit asus_acpi_exit(void)
1256 acpi_bus_unregister_driver(&asus_hotk_driver); 1371 acpi_bus_unregister_driver(&asus_hotk_driver);
1257 remove_proc_entry(PROC_ASUS, acpi_root_dir); 1372 remove_proc_entry(PROC_ASUS, acpi_root_dir);
1258 1373
1259 acpi_os_free(asus_info); 1374 kfree(asus_info);
1260 1375
1261 return; 1376 return;
1262} 1377}
diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index 702e857e98c5..9810e2a55d0a 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -59,6 +59,9 @@ ACPI_MODULE_NAME("acpi_battery")
59MODULE_DESCRIPTION(ACPI_BATTERY_DRIVER_NAME); 59MODULE_DESCRIPTION(ACPI_BATTERY_DRIVER_NAME);
60MODULE_LICENSE("GPL"); 60MODULE_LICENSE("GPL");
61 61
62extern struct proc_dir_entry *acpi_lock_battery_dir(void);
63extern void *acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir);
64
62static int acpi_battery_add(struct acpi_device *device); 65static int acpi_battery_add(struct acpi_device *device);
63static int acpi_battery_remove(struct acpi_device *device, int type); 66static int acpi_battery_remove(struct acpi_device *device, int type);
64 67
@@ -108,7 +111,7 @@ struct acpi_battery_trips {
108}; 111};
109 112
110struct acpi_battery { 113struct acpi_battery {
111 acpi_handle handle; 114 struct acpi_device * device;
112 struct acpi_battery_flags flags; 115 struct acpi_battery_flags flags;
113 struct acpi_battery_trips trips; 116 struct acpi_battery_trips trips;
114 unsigned long alarm; 117 unsigned long alarm;
@@ -132,17 +135,16 @@ acpi_battery_get_info(struct acpi_battery *battery,
132 struct acpi_buffer data = { 0, NULL }; 135 struct acpi_buffer data = { 0, NULL };
133 union acpi_object *package = NULL; 136 union acpi_object *package = NULL;
134 137
135 ACPI_FUNCTION_TRACE("acpi_battery_get_info");
136 138
137 if (!battery || !bif) 139 if (!battery || !bif)
138 return_VALUE(-EINVAL); 140 return -EINVAL;
139 141
140 /* Evalute _BIF */ 142 /* Evalute _BIF */
141 143
142 status = acpi_evaluate_object(battery->handle, "_BIF", NULL, &buffer); 144 status = acpi_evaluate_object(battery->device->handle, "_BIF", NULL, &buffer);
143 if (ACPI_FAILURE(status)) { 145 if (ACPI_FAILURE(status)) {
144 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error evaluating _BIF\n")); 146 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _BIF"));
145 return_VALUE(-ENODEV); 147 return -ENODEV;
146 } 148 }
147 149
148 package = (union acpi_object *)buffer.pointer; 150 package = (union acpi_object *)buffer.pointer;
@@ -151,7 +153,7 @@ acpi_battery_get_info(struct acpi_battery *battery,
151 153
152 status = acpi_extract_package(package, &format, &data); 154 status = acpi_extract_package(package, &format, &data);
153 if (status != AE_BUFFER_OVERFLOW) { 155 if (status != AE_BUFFER_OVERFLOW) {
154 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error extracting _BIF\n")); 156 ACPI_EXCEPTION((AE_INFO, status, "Extracting _BIF"));
155 result = -ENODEV; 157 result = -ENODEV;
156 goto end; 158 goto end;
157 } 159 }
@@ -165,19 +167,19 @@ acpi_battery_get_info(struct acpi_battery *battery,
165 167
166 status = acpi_extract_package(package, &format, &data); 168 status = acpi_extract_package(package, &format, &data);
167 if (ACPI_FAILURE(status)) { 169 if (ACPI_FAILURE(status)) {
168 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error extracting _BIF\n")); 170 ACPI_EXCEPTION((AE_INFO, status, "Extracting _BIF"));
169 kfree(data.pointer); 171 kfree(data.pointer);
170 result = -ENODEV; 172 result = -ENODEV;
171 goto end; 173 goto end;
172 } 174 }
173 175
174 end: 176 end:
175 acpi_os_free(buffer.pointer); 177 kfree(buffer.pointer);
176 178
177 if (!result) 179 if (!result)
178 (*bif) = (struct acpi_battery_info *)data.pointer; 180 (*bif) = (struct acpi_battery_info *)data.pointer;
179 181
180 return_VALUE(result); 182 return result;
181} 183}
182 184
183static int 185static int
@@ -193,17 +195,16 @@ acpi_battery_get_status(struct acpi_battery *battery,
193 struct acpi_buffer data = { 0, NULL }; 195 struct acpi_buffer data = { 0, NULL };
194 union acpi_object *package = NULL; 196 union acpi_object *package = NULL;
195 197
196 ACPI_FUNCTION_TRACE("acpi_battery_get_status");
197 198
198 if (!battery || !bst) 199 if (!battery || !bst)
199 return_VALUE(-EINVAL); 200 return -EINVAL;
200 201
201 /* Evalute _BST */ 202 /* Evalute _BST */
202 203
203 status = acpi_evaluate_object(battery->handle, "_BST", NULL, &buffer); 204 status = acpi_evaluate_object(battery->device->handle, "_BST", NULL, &buffer);
204 if (ACPI_FAILURE(status)) { 205 if (ACPI_FAILURE(status)) {
205 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error evaluating _BST\n")); 206 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _BST"));
206 return_VALUE(-ENODEV); 207 return -ENODEV;
207 } 208 }
208 209
209 package = (union acpi_object *)buffer.pointer; 210 package = (union acpi_object *)buffer.pointer;
@@ -212,7 +213,7 @@ acpi_battery_get_status(struct acpi_battery *battery,
212 213
213 status = acpi_extract_package(package, &format, &data); 214 status = acpi_extract_package(package, &format, &data);
214 if (status != AE_BUFFER_OVERFLOW) { 215 if (status != AE_BUFFER_OVERFLOW) {
215 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error extracting _BST\n")); 216 ACPI_EXCEPTION((AE_INFO, status, "Extracting _BST"));
216 result = -ENODEV; 217 result = -ENODEV;
217 goto end; 218 goto end;
218 } 219 }
@@ -226,19 +227,19 @@ acpi_battery_get_status(struct acpi_battery *battery,
226 227
227 status = acpi_extract_package(package, &format, &data); 228 status = acpi_extract_package(package, &format, &data);
228 if (ACPI_FAILURE(status)) { 229 if (ACPI_FAILURE(status)) {
229 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error extracting _BST\n")); 230 ACPI_EXCEPTION((AE_INFO, status, "Extracting _BST"));
230 kfree(data.pointer); 231 kfree(data.pointer);
231 result = -ENODEV; 232 result = -ENODEV;
232 goto end; 233 goto end;
233 } 234 }
234 235
235 end: 236 end:
236 acpi_os_free(buffer.pointer); 237 kfree(buffer.pointer);
237 238
238 if (!result) 239 if (!result)
239 (*bst) = (struct acpi_battery_status *)data.pointer; 240 (*bst) = (struct acpi_battery_status *)data.pointer;
240 241
241 return_VALUE(result); 242 return result;
242} 243}
243 244
244static int 245static int
@@ -248,25 +249,24 @@ acpi_battery_set_alarm(struct acpi_battery *battery, unsigned long alarm)
248 union acpi_object arg0 = { ACPI_TYPE_INTEGER }; 249 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
249 struct acpi_object_list arg_list = { 1, &arg0 }; 250 struct acpi_object_list arg_list = { 1, &arg0 };
250 251
251 ACPI_FUNCTION_TRACE("acpi_battery_set_alarm");
252 252
253 if (!battery) 253 if (!battery)
254 return_VALUE(-EINVAL); 254 return -EINVAL;
255 255
256 if (!battery->flags.alarm) 256 if (!battery->flags.alarm)
257 return_VALUE(-ENODEV); 257 return -ENODEV;
258 258
259 arg0.integer.value = alarm; 259 arg0.integer.value = alarm;
260 260
261 status = acpi_evaluate_object(battery->handle, "_BTP", &arg_list, NULL); 261 status = acpi_evaluate_object(battery->device->handle, "_BTP", &arg_list, NULL);
262 if (ACPI_FAILURE(status)) 262 if (ACPI_FAILURE(status))
263 return_VALUE(-ENODEV); 263 return -ENODEV;
264 264
265 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Alarm set to %d\n", (u32) alarm)); 265 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Alarm set to %d\n", (u32) alarm));
266 266
267 battery->alarm = alarm; 267 battery->alarm = alarm;
268 268
269 return_VALUE(0); 269 return 0;
270} 270}
271 271
272static int acpi_battery_check(struct acpi_battery *battery) 272static int acpi_battery_check(struct acpi_battery *battery)
@@ -277,18 +277,15 @@ static int acpi_battery_check(struct acpi_battery *battery)
277 struct acpi_device *device = NULL; 277 struct acpi_device *device = NULL;
278 struct acpi_battery_info *bif = NULL; 278 struct acpi_battery_info *bif = NULL;
279 279
280 ACPI_FUNCTION_TRACE("acpi_battery_check");
281 280
282 if (!battery) 281 if (!battery)
283 return_VALUE(-EINVAL); 282 return -EINVAL;
284 283
285 result = acpi_bus_get_device(battery->handle, &device); 284 device = battery->device;
286 if (result)
287 return_VALUE(result);
288 285
289 result = acpi_bus_get_status(device); 286 result = acpi_bus_get_status(device);
290 if (result) 287 if (result)
291 return_VALUE(result); 288 return result;
292 289
293 /* Insertion? */ 290 /* Insertion? */
294 291
@@ -300,7 +297,7 @@ static int acpi_battery_check(struct acpi_battery *battery)
300 297
301 result = acpi_battery_get_info(battery, &bif); 298 result = acpi_battery_get_info(battery, &bif);
302 if (result) 299 if (result)
303 return_VALUE(result); 300 return result;
304 301
305 battery->flags.power_unit = bif->power_unit; 302 battery->flags.power_unit = bif->power_unit;
306 battery->trips.warning = bif->design_capacity_warning; 303 battery->trips.warning = bif->design_capacity_warning;
@@ -309,7 +306,7 @@ static int acpi_battery_check(struct acpi_battery *battery)
309 306
310 /* See if alarms are supported, and if so, set default */ 307 /* See if alarms are supported, and if so, set default */
311 308
312 status = acpi_get_handle(battery->handle, "_BTP", &handle); 309 status = acpi_get_handle(battery->device->handle, "_BTP", &handle);
313 if (ACPI_SUCCESS(status)) { 310 if (ACPI_SUCCESS(status)) {
314 battery->flags.alarm = 1; 311 battery->flags.alarm = 1;
315 acpi_battery_set_alarm(battery, battery->trips.warning); 312 acpi_battery_set_alarm(battery, battery->trips.warning);
@@ -324,7 +321,7 @@ static int acpi_battery_check(struct acpi_battery *battery)
324 321
325 battery->flags.present = device->status.battery_present; 322 battery->flags.present = device->status.battery_present;
326 323
327 return_VALUE(result); 324 return result;
328} 325}
329 326
330/* -------------------------------------------------------------------------- 327/* --------------------------------------------------------------------------
@@ -339,7 +336,6 @@ static int acpi_battery_read_info(struct seq_file *seq, void *offset)
339 struct acpi_battery_info *bif = NULL; 336 struct acpi_battery_info *bif = NULL;
340 char *units = "?"; 337 char *units = "?";
341 338
342 ACPI_FUNCTION_TRACE("acpi_battery_read_info");
343 339
344 if (!battery) 340 if (!battery)
345 goto end; 341 goto end;
@@ -409,7 +405,7 @@ static int acpi_battery_read_info(struct seq_file *seq, void *offset)
409 end: 405 end:
410 kfree(bif); 406 kfree(bif);
411 407
412 return_VALUE(0); 408 return 0;
413} 409}
414 410
415static int acpi_battery_info_open_fs(struct inode *inode, struct file *file) 411static int acpi_battery_info_open_fs(struct inode *inode, struct file *file)
@@ -424,7 +420,6 @@ static int acpi_battery_read_state(struct seq_file *seq, void *offset)
424 struct acpi_battery_status *bst = NULL; 420 struct acpi_battery_status *bst = NULL;
425 char *units = "?"; 421 char *units = "?";
426 422
427 ACPI_FUNCTION_TRACE("acpi_battery_read_state");
428 423
429 if (!battery) 424 if (!battery)
430 goto end; 425 goto end;
@@ -458,8 +453,6 @@ static int acpi_battery_read_state(struct seq_file *seq, void *offset)
458 if ((bst->state & 0x01) && (bst->state & 0x02)) { 453 if ((bst->state & 0x01) && (bst->state & 0x02)) {
459 seq_printf(seq, 454 seq_printf(seq,
460 "charging state: charging/discharging\n"); 455 "charging state: charging/discharging\n");
461 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
462 "Battery Charging and Discharging?\n"));
463 } else if (bst->state & 0x01) 456 } else if (bst->state & 0x01)
464 seq_printf(seq, "charging state: discharging\n"); 457 seq_printf(seq, "charging state: discharging\n");
465 else if (bst->state & 0x02) 458 else if (bst->state & 0x02)
@@ -489,7 +482,7 @@ static int acpi_battery_read_state(struct seq_file *seq, void *offset)
489 end: 482 end:
490 kfree(bst); 483 kfree(bst);
491 484
492 return_VALUE(0); 485 return 0;
493} 486}
494 487
495static int acpi_battery_state_open_fs(struct inode *inode, struct file *file) 488static int acpi_battery_state_open_fs(struct inode *inode, struct file *file)
@@ -502,7 +495,6 @@ static int acpi_battery_read_alarm(struct seq_file *seq, void *offset)
502 struct acpi_battery *battery = (struct acpi_battery *)seq->private; 495 struct acpi_battery *battery = (struct acpi_battery *)seq->private;
503 char *units = "?"; 496 char *units = "?";
504 497
505 ACPI_FUNCTION_TRACE("acpi_battery_read_alarm");
506 498
507 if (!battery) 499 if (!battery)
508 goto end; 500 goto end;
@@ -527,7 +519,7 @@ static int acpi_battery_read_alarm(struct seq_file *seq, void *offset)
527 seq_printf(seq, "%d %sh\n", (u32) battery->alarm, units); 519 seq_printf(seq, "%d %sh\n", (u32) battery->alarm, units);
528 520
529 end: 521 end:
530 return_VALUE(0); 522 return 0;
531} 523}
532 524
533static ssize_t 525static ssize_t
@@ -540,25 +532,24 @@ acpi_battery_write_alarm(struct file *file,
540 struct seq_file *m = (struct seq_file *)file->private_data; 532 struct seq_file *m = (struct seq_file *)file->private_data;
541 struct acpi_battery *battery = (struct acpi_battery *)m->private; 533 struct acpi_battery *battery = (struct acpi_battery *)m->private;
542 534
543 ACPI_FUNCTION_TRACE("acpi_battery_write_alarm");
544 535
545 if (!battery || (count > sizeof(alarm_string) - 1)) 536 if (!battery || (count > sizeof(alarm_string) - 1))
546 return_VALUE(-EINVAL); 537 return -EINVAL;
547 538
548 if (!battery->flags.present) 539 if (!battery->flags.present)
549 return_VALUE(-ENODEV); 540 return -ENODEV;
550 541
551 if (copy_from_user(alarm_string, buffer, count)) 542 if (copy_from_user(alarm_string, buffer, count))
552 return_VALUE(-EFAULT); 543 return -EFAULT;
553 544
554 alarm_string[count] = '\0'; 545 alarm_string[count] = '\0';
555 546
556 result = acpi_battery_set_alarm(battery, 547 result = acpi_battery_set_alarm(battery,
557 simple_strtoul(alarm_string, NULL, 0)); 548 simple_strtoul(alarm_string, NULL, 0));
558 if (result) 549 if (result)
559 return_VALUE(result); 550 return result;
560 551
561 return_VALUE(count); 552 return count;
562} 553}
563 554
564static int acpi_battery_alarm_open_fs(struct inode *inode, struct file *file) 555static int acpi_battery_alarm_open_fs(struct inode *inode, struct file *file)
@@ -566,7 +557,7 @@ static int acpi_battery_alarm_open_fs(struct inode *inode, struct file *file)
566 return single_open(file, acpi_battery_read_alarm, PDE(inode)->data); 557 return single_open(file, acpi_battery_read_alarm, PDE(inode)->data);
567} 558}
568 559
569static struct file_operations acpi_battery_info_ops = { 560static const struct file_operations acpi_battery_info_ops = {
570 .open = acpi_battery_info_open_fs, 561 .open = acpi_battery_info_open_fs,
571 .read = seq_read, 562 .read = seq_read,
572 .llseek = seq_lseek, 563 .llseek = seq_lseek,
@@ -574,7 +565,7 @@ static struct file_operations acpi_battery_info_ops = {
574 .owner = THIS_MODULE, 565 .owner = THIS_MODULE,
575}; 566};
576 567
577static struct file_operations acpi_battery_state_ops = { 568static const struct file_operations acpi_battery_state_ops = {
578 .open = acpi_battery_state_open_fs, 569 .open = acpi_battery_state_open_fs,
579 .read = seq_read, 570 .read = seq_read,
580 .llseek = seq_lseek, 571 .llseek = seq_lseek,
@@ -582,7 +573,7 @@ static struct file_operations acpi_battery_state_ops = {
582 .owner = THIS_MODULE, 573 .owner = THIS_MODULE,
583}; 574};
584 575
585static struct file_operations acpi_battery_alarm_ops = { 576static const struct file_operations acpi_battery_alarm_ops = {
586 .open = acpi_battery_alarm_open_fs, 577 .open = acpi_battery_alarm_open_fs,
587 .read = seq_read, 578 .read = seq_read,
588 .write = acpi_battery_write_alarm, 579 .write = acpi_battery_write_alarm,
@@ -595,13 +586,12 @@ static int acpi_battery_add_fs(struct acpi_device *device)
595{ 586{
596 struct proc_dir_entry *entry = NULL; 587 struct proc_dir_entry *entry = NULL;
597 588
598 ACPI_FUNCTION_TRACE("acpi_battery_add_fs");
599 589
600 if (!acpi_device_dir(device)) { 590 if (!acpi_device_dir(device)) {
601 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), 591 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
602 acpi_battery_dir); 592 acpi_battery_dir);
603 if (!acpi_device_dir(device)) 593 if (!acpi_device_dir(device))
604 return_VALUE(-ENODEV); 594 return -ENODEV;
605 acpi_device_dir(device)->owner = THIS_MODULE; 595 acpi_device_dir(device)->owner = THIS_MODULE;
606 } 596 }
607 597
@@ -609,9 +599,7 @@ static int acpi_battery_add_fs(struct acpi_device *device)
609 entry = create_proc_entry(ACPI_BATTERY_FILE_INFO, 599 entry = create_proc_entry(ACPI_BATTERY_FILE_INFO,
610 S_IRUGO, acpi_device_dir(device)); 600 S_IRUGO, acpi_device_dir(device));
611 if (!entry) 601 if (!entry)
612 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 602 return -ENODEV;
613 "Unable to create '%s' fs entry\n",
614 ACPI_BATTERY_FILE_INFO));
615 else { 603 else {
616 entry->proc_fops = &acpi_battery_info_ops; 604 entry->proc_fops = &acpi_battery_info_ops;
617 entry->data = acpi_driver_data(device); 605 entry->data = acpi_driver_data(device);
@@ -622,9 +610,7 @@ static int acpi_battery_add_fs(struct acpi_device *device)
622 entry = create_proc_entry(ACPI_BATTERY_FILE_STATUS, 610 entry = create_proc_entry(ACPI_BATTERY_FILE_STATUS,
623 S_IRUGO, acpi_device_dir(device)); 611 S_IRUGO, acpi_device_dir(device));
624 if (!entry) 612 if (!entry)
625 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 613 return -ENODEV;
626 "Unable to create '%s' fs entry\n",
627 ACPI_BATTERY_FILE_STATUS));
628 else { 614 else {
629 entry->proc_fops = &acpi_battery_state_ops; 615 entry->proc_fops = &acpi_battery_state_ops;
630 entry->data = acpi_driver_data(device); 616 entry->data = acpi_driver_data(device);
@@ -636,21 +622,18 @@ static int acpi_battery_add_fs(struct acpi_device *device)
636 S_IFREG | S_IRUGO | S_IWUSR, 622 S_IFREG | S_IRUGO | S_IWUSR,
637 acpi_device_dir(device)); 623 acpi_device_dir(device));
638 if (!entry) 624 if (!entry)
639 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 625 return -ENODEV;
640 "Unable to create '%s' fs entry\n",
641 ACPI_BATTERY_FILE_ALARM));
642 else { 626 else {
643 entry->proc_fops = &acpi_battery_alarm_ops; 627 entry->proc_fops = &acpi_battery_alarm_ops;
644 entry->data = acpi_driver_data(device); 628 entry->data = acpi_driver_data(device);
645 entry->owner = THIS_MODULE; 629 entry->owner = THIS_MODULE;
646 } 630 }
647 631
648 return_VALUE(0); 632 return 0;
649} 633}
650 634
651static int acpi_battery_remove_fs(struct acpi_device *device) 635static int acpi_battery_remove_fs(struct acpi_device *device)
652{ 636{
653 ACPI_FUNCTION_TRACE("acpi_battery_remove_fs");
654 637
655 if (acpi_device_dir(device)) { 638 if (acpi_device_dir(device)) {
656 remove_proc_entry(ACPI_BATTERY_FILE_ALARM, 639 remove_proc_entry(ACPI_BATTERY_FILE_ALARM,
@@ -664,7 +647,7 @@ static int acpi_battery_remove_fs(struct acpi_device *device)
664 acpi_device_dir(device) = NULL; 647 acpi_device_dir(device) = NULL;
665 } 648 }
666 649
667 return_VALUE(0); 650 return 0;
668} 651}
669 652
670/* -------------------------------------------------------------------------- 653/* --------------------------------------------------------------------------
@@ -676,17 +659,17 @@ static void acpi_battery_notify(acpi_handle handle, u32 event, void *data)
676 struct acpi_battery *battery = (struct acpi_battery *)data; 659 struct acpi_battery *battery = (struct acpi_battery *)data;
677 struct acpi_device *device = NULL; 660 struct acpi_device *device = NULL;
678 661
679 ACPI_FUNCTION_TRACE("acpi_battery_notify");
680 662
681 if (!battery) 663 if (!battery)
682 return_VOID; 664 return;
683 665
684 if (acpi_bus_get_device(handle, &device)) 666 device = battery->device;
685 return_VOID;
686 667
687 switch (event) { 668 switch (event) {
688 case ACPI_BATTERY_NOTIFY_STATUS: 669 case ACPI_BATTERY_NOTIFY_STATUS:
689 case ACPI_BATTERY_NOTIFY_INFO: 670 case ACPI_BATTERY_NOTIFY_INFO:
671 case ACPI_NOTIFY_BUS_CHECK:
672 case ACPI_NOTIFY_DEVICE_CHECK:
690 acpi_battery_check(battery); 673 acpi_battery_check(battery);
691 acpi_bus_generate_event(device, event, battery->flags.present); 674 acpi_bus_generate_event(device, event, battery->flags.present);
692 break; 675 break;
@@ -696,7 +679,7 @@ static void acpi_battery_notify(acpi_handle handle, u32 event, void *data)
696 break; 679 break;
697 } 680 }
698 681
699 return_VOID; 682 return;
700} 683}
701 684
702static int acpi_battery_add(struct acpi_device *device) 685static int acpi_battery_add(struct acpi_device *device)
@@ -705,17 +688,16 @@ static int acpi_battery_add(struct acpi_device *device)
705 acpi_status status = 0; 688 acpi_status status = 0;
706 struct acpi_battery *battery = NULL; 689 struct acpi_battery *battery = NULL;
707 690
708 ACPI_FUNCTION_TRACE("acpi_battery_add");
709 691
710 if (!device) 692 if (!device)
711 return_VALUE(-EINVAL); 693 return -EINVAL;
712 694
713 battery = kmalloc(sizeof(struct acpi_battery), GFP_KERNEL); 695 battery = kmalloc(sizeof(struct acpi_battery), GFP_KERNEL);
714 if (!battery) 696 if (!battery)
715 return_VALUE(-ENOMEM); 697 return -ENOMEM;
716 memset(battery, 0, sizeof(struct acpi_battery)); 698 memset(battery, 0, sizeof(struct acpi_battery));
717 699
718 battery->handle = device->handle; 700 battery->device = device;
719 strcpy(acpi_device_name(device), ACPI_BATTERY_DEVICE_NAME); 701 strcpy(acpi_device_name(device), ACPI_BATTERY_DEVICE_NAME);
720 strcpy(acpi_device_class(device), ACPI_BATTERY_CLASS); 702 strcpy(acpi_device_class(device), ACPI_BATTERY_CLASS);
721 acpi_driver_data(device) = battery; 703 acpi_driver_data(device) = battery;
@@ -728,12 +710,10 @@ static int acpi_battery_add(struct acpi_device *device)
728 if (result) 710 if (result)
729 goto end; 711 goto end;
730 712
731 status = acpi_install_notify_handler(battery->handle, 713 status = acpi_install_notify_handler(device->handle,
732 ACPI_DEVICE_NOTIFY, 714 ACPI_ALL_NOTIFY,
733 acpi_battery_notify, battery); 715 acpi_battery_notify, battery);
734 if (ACPI_FAILURE(status)) { 716 if (ACPI_FAILURE(status)) {
735 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
736 "Error installing notify handler\n"));
737 result = -ENODEV; 717 result = -ENODEV;
738 goto end; 718 goto end;
739 } 719 }
@@ -748,7 +728,7 @@ static int acpi_battery_add(struct acpi_device *device)
748 kfree(battery); 728 kfree(battery);
749 } 729 }
750 730
751 return_VALUE(result); 731 return result;
752} 732}
753 733
754static int acpi_battery_remove(struct acpi_device *device, int type) 734static int acpi_battery_remove(struct acpi_device *device, int type)
@@ -756,56 +736,51 @@ static int acpi_battery_remove(struct acpi_device *device, int type)
756 acpi_status status = 0; 736 acpi_status status = 0;
757 struct acpi_battery *battery = NULL; 737 struct acpi_battery *battery = NULL;
758 738
759 ACPI_FUNCTION_TRACE("acpi_battery_remove");
760 739
761 if (!device || !acpi_driver_data(device)) 740 if (!device || !acpi_driver_data(device))
762 return_VALUE(-EINVAL); 741 return -EINVAL;
763 742
764 battery = (struct acpi_battery *)acpi_driver_data(device); 743 battery = (struct acpi_battery *)acpi_driver_data(device);
765 744
766 status = acpi_remove_notify_handler(battery->handle, 745 status = acpi_remove_notify_handler(device->handle,
767 ACPI_DEVICE_NOTIFY, 746 ACPI_ALL_NOTIFY,
768 acpi_battery_notify); 747 acpi_battery_notify);
769 if (ACPI_FAILURE(status))
770 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
771 "Error removing notify handler\n"));
772 748
773 acpi_battery_remove_fs(device); 749 acpi_battery_remove_fs(device);
774 750
775 kfree(battery); 751 kfree(battery);
776 752
777 return_VALUE(0); 753 return 0;
778} 754}
779 755
780static int __init acpi_battery_init(void) 756static int __init acpi_battery_init(void)
781{ 757{
782 int result = 0; 758 int result;
783 759
784 ACPI_FUNCTION_TRACE("acpi_battery_init"); 760 if (acpi_disabled)
761 return -ENODEV;
785 762
786 acpi_battery_dir = proc_mkdir(ACPI_BATTERY_CLASS, acpi_root_dir); 763 acpi_battery_dir = acpi_lock_battery_dir();
787 if (!acpi_battery_dir) 764 if (!acpi_battery_dir)
788 return_VALUE(-ENODEV); 765 return -ENODEV;
789 acpi_battery_dir->owner = THIS_MODULE;
790 766
791 result = acpi_bus_register_driver(&acpi_battery_driver); 767 result = acpi_bus_register_driver(&acpi_battery_driver);
792 if (result < 0) { 768 if (result < 0) {
793 remove_proc_entry(ACPI_BATTERY_CLASS, acpi_root_dir); 769 acpi_unlock_battery_dir(acpi_battery_dir);
794 return_VALUE(-ENODEV); 770 return -ENODEV;
795 } 771 }
796 772
797 return_VALUE(0); 773 return 0;
798} 774}
799 775
800static void __exit acpi_battery_exit(void) 776static void __exit acpi_battery_exit(void)
801{ 777{
802 ACPI_FUNCTION_TRACE("acpi_battery_exit");
803 778
804 acpi_bus_unregister_driver(&acpi_battery_driver); 779 acpi_bus_unregister_driver(&acpi_battery_driver);
805 780
806 remove_proc_entry(ACPI_BATTERY_CLASS, acpi_root_dir); 781 acpi_unlock_battery_dir(acpi_battery_dir);
807 782
808 return_VOID; 783 return;
809} 784}
810 785
811module_init(acpi_battery_init); 786module_init(acpi_battery_init);
diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c
index dd3983cece92..279c4bac92e5 100644
--- a/drivers/acpi/bus.c
+++ b/drivers/acpi/bus.c
@@ -25,6 +25,7 @@
25#include <linux/module.h> 25#include <linux/module.h>
26#include <linux/init.h> 26#include <linux/init.h>
27#include <linux/ioport.h> 27#include <linux/ioport.h>
28#include <linux/kernel.h>
28#include <linux/list.h> 29#include <linux/list.h>
29#include <linux/sched.h> 30#include <linux/sched.h>
30#include <linux/pm.h> 31#include <linux/pm.h>
@@ -60,21 +61,20 @@ int acpi_bus_get_device(acpi_handle handle, struct acpi_device **device)
60{ 61{
61 acpi_status status = AE_OK; 62 acpi_status status = AE_OK;
62 63
63 ACPI_FUNCTION_TRACE("acpi_bus_get_device");
64 64
65 if (!device) 65 if (!device)
66 return_VALUE(-EINVAL); 66 return -EINVAL;
67 67
68 /* TBD: Support fixed-feature devices */ 68 /* TBD: Support fixed-feature devices */
69 69
70 status = acpi_get_data(handle, acpi_bus_data_handler, (void **)device); 70 status = acpi_get_data(handle, acpi_bus_data_handler, (void **)device);
71 if (ACPI_FAILURE(status) || !*device) { 71 if (ACPI_FAILURE(status) || !*device) {
72 ACPI_DEBUG_PRINT((ACPI_DB_WARN, "No context for object [%p]\n", 72 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No context for object [%p]\n",
73 handle)); 73 handle));
74 return_VALUE(-ENODEV); 74 return -ENODEV;
75 } 75 }
76 76
77 return_VALUE(0); 77 return 0;
78} 78}
79 79
80EXPORT_SYMBOL(acpi_bus_get_device); 80EXPORT_SYMBOL(acpi_bus_get_device);
@@ -84,10 +84,9 @@ int acpi_bus_get_status(struct acpi_device *device)
84 acpi_status status = AE_OK; 84 acpi_status status = AE_OK;
85 unsigned long sta = 0; 85 unsigned long sta = 0;
86 86
87 ACPI_FUNCTION_TRACE("acpi_bus_get_status");
88 87
89 if (!device) 88 if (!device)
90 return_VALUE(-EINVAL); 89 return -EINVAL;
91 90
92 /* 91 /*
93 * Evaluate _STA if present. 92 * Evaluate _STA if present.
@@ -96,7 +95,7 @@ int acpi_bus_get_status(struct acpi_device *device)
96 status = 95 status =
97 acpi_evaluate_integer(device->handle, "_STA", NULL, &sta); 96 acpi_evaluate_integer(device->handle, "_STA", NULL, &sta);
98 if (ACPI_FAILURE(status)) 97 if (ACPI_FAILURE(status))
99 return_VALUE(-ENODEV); 98 return -ENODEV;
100 STRUCT_TO_INT(device->status) = (int)sta; 99 STRUCT_TO_INT(device->status) = (int)sta;
101 } 100 }
102 101
@@ -120,7 +119,7 @@ int acpi_bus_get_status(struct acpi_device *device)
120 device->pnp.bus_id, 119 device->pnp.bus_id,
121 (u32) STRUCT_TO_INT(device->status))); 120 (u32) STRUCT_TO_INT(device->status)));
122 121
123 return_VALUE(0); 122 return 0;
124} 123}
125 124
126EXPORT_SYMBOL(acpi_bus_get_status); 125EXPORT_SYMBOL(acpi_bus_get_status);
@@ -136,11 +135,10 @@ int acpi_bus_get_power(acpi_handle handle, int *state)
136 struct acpi_device *device = NULL; 135 struct acpi_device *device = NULL;
137 unsigned long psc = 0; 136 unsigned long psc = 0;
138 137
139 ACPI_FUNCTION_TRACE("acpi_bus_get_power");
140 138
141 result = acpi_bus_get_device(handle, &device); 139 result = acpi_bus_get_device(handle, &device);
142 if (result) 140 if (result)
143 return_VALUE(result); 141 return result;
144 142
145 *state = ACPI_STATE_UNKNOWN; 143 *state = ACPI_STATE_UNKNOWN;
146 144
@@ -159,12 +157,12 @@ int acpi_bus_get_power(acpi_handle handle, int *state)
159 status = acpi_evaluate_integer(device->handle, "_PSC", 157 status = acpi_evaluate_integer(device->handle, "_PSC",
160 NULL, &psc); 158 NULL, &psc);
161 if (ACPI_FAILURE(status)) 159 if (ACPI_FAILURE(status))
162 return_VALUE(-ENODEV); 160 return -ENODEV;
163 device->power.state = (int)psc; 161 device->power.state = (int)psc;
164 } else if (device->power.flags.power_resources) { 162 } else if (device->power.flags.power_resources) {
165 result = acpi_power_get_inferred_state(device); 163 result = acpi_power_get_inferred_state(device);
166 if (result) 164 if (result)
167 return_VALUE(result); 165 return result;
168 } 166 }
169 167
170 *state = device->power.state; 168 *state = device->power.state;
@@ -173,7 +171,7 @@ int acpi_bus_get_power(acpi_handle handle, int *state)
173 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] power state is D%d\n", 171 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] power state is D%d\n",
174 device->pnp.bus_id, device->power.state)); 172 device->pnp.bus_id, device->power.state));
175 173
176 return_VALUE(0); 174 return 0;
177} 175}
178 176
179EXPORT_SYMBOL(acpi_bus_get_power); 177EXPORT_SYMBOL(acpi_bus_get_power);
@@ -185,21 +183,20 @@ int acpi_bus_set_power(acpi_handle handle, int state)
185 struct acpi_device *device = NULL; 183 struct acpi_device *device = NULL;
186 char object_name[5] = { '_', 'P', 'S', '0' + state, '\0' }; 184 char object_name[5] = { '_', 'P', 'S', '0' + state, '\0' };
187 185
188 ACPI_FUNCTION_TRACE("acpi_bus_set_power");
189 186
190 result = acpi_bus_get_device(handle, &device); 187 result = acpi_bus_get_device(handle, &device);
191 if (result) 188 if (result)
192 return_VALUE(result); 189 return result;
193 190
194 if ((state < ACPI_STATE_D0) || (state > ACPI_STATE_D3)) 191 if ((state < ACPI_STATE_D0) || (state > ACPI_STATE_D3))
195 return_VALUE(-EINVAL); 192 return -EINVAL;
196 193
197 /* Make sure this is a valid target state */ 194 /* Make sure this is a valid target state */
198 195
199 if (!device->flags.power_manageable) { 196 if (!device->flags.power_manageable) {
200 ACPI_DEBUG_PRINT((ACPI_DB_WARN, 197 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device `[%s]' is not power manageable\n",
201 "Device is not power manageable\n")); 198 device->kobj.name));
202 return_VALUE(-ENODEV); 199 return -ENODEV;
203 } 200 }
204 /* 201 /*
205 * Get device's current power state if it's unknown 202 * Get device's current power state if it's unknown
@@ -211,18 +208,18 @@ int acpi_bus_set_power(acpi_handle handle, int state)
211 if (state == device->power.state) { 208 if (state == device->power.state) {
212 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device is already at D%d\n", 209 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device is already at D%d\n",
213 state)); 210 state));
214 return_VALUE(0); 211 return 0;
215 } 212 }
216 } 213 }
217 if (!device->power.states[state].flags.valid) { 214 if (!device->power.states[state].flags.valid) {
218 ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Device does not support D%d\n", 215 printk(KERN_WARNING PREFIX "Device does not support D%d\n", state);
219 state)); 216 return -ENODEV;
220 return_VALUE(-ENODEV);
221 } 217 }
222 if (device->parent && (state < device->parent->power.state)) { 218 if (device->parent && (state < device->parent->power.state)) {
223 ACPI_DEBUG_PRINT((ACPI_DB_WARN, 219 printk(KERN_WARNING PREFIX
224 "Cannot set device to a higher-powered state than parent\n")); 220 "Cannot set device to a higher-powered"
225 return_VALUE(-ENODEV); 221 " state than parent\n");
222 return -ENODEV;
226 } 223 }
227 224
228 /* 225 /*
@@ -264,15 +261,15 @@ int acpi_bus_set_power(acpi_handle handle, int state)
264 261
265 end: 262 end:
266 if (result) 263 if (result)
267 ACPI_DEBUG_PRINT((ACPI_DB_WARN, 264 printk(KERN_WARNING PREFIX
268 "Error transitioning device [%s] to D%d\n", 265 "Transitioning device [%s] to D%d\n",
269 device->pnp.bus_id, state)); 266 device->pnp.bus_id, state);
270 else 267 else
271 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 268 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
272 "Device [%s] transitioned to D%d\n", 269 "Device [%s] transitioned to D%d\n",
273 device->pnp.bus_id, state)); 270 device->pnp.bus_id, state));
274 271
275 return_VALUE(result); 272 return result;
276} 273}
277 274
278EXPORT_SYMBOL(acpi_bus_set_power); 275EXPORT_SYMBOL(acpi_bus_set_power);
@@ -293,18 +290,17 @@ int acpi_bus_generate_event(struct acpi_device *device, u8 type, int data)
293 struct acpi_bus_event *event = NULL; 290 struct acpi_bus_event *event = NULL;
294 unsigned long flags = 0; 291 unsigned long flags = 0;
295 292
296 ACPI_FUNCTION_TRACE("acpi_bus_generate_event");
297 293
298 if (!device) 294 if (!device)
299 return_VALUE(-EINVAL); 295 return -EINVAL;
300 296
301 /* drop event on the floor if no one's listening */ 297 /* drop event on the floor if no one's listening */
302 if (!event_is_open) 298 if (!event_is_open)
303 return_VALUE(0); 299 return 0;
304 300
305 event = kmalloc(sizeof(struct acpi_bus_event), GFP_ATOMIC); 301 event = kmalloc(sizeof(struct acpi_bus_event), GFP_ATOMIC);
306 if (!event) 302 if (!event)
307 return_VALUE(-ENOMEM); 303 return -ENOMEM;
308 304
309 strcpy(event->device_class, device->pnp.device_class); 305 strcpy(event->device_class, device->pnp.device_class);
310 strcpy(event->bus_id, device->pnp.bus_id); 306 strcpy(event->bus_id, device->pnp.bus_id);
@@ -317,7 +313,7 @@ int acpi_bus_generate_event(struct acpi_device *device, u8 type, int data)
317 313
318 wake_up_interruptible(&acpi_bus_event_queue); 314 wake_up_interruptible(&acpi_bus_event_queue);
319 315
320 return_VALUE(0); 316 return 0;
321} 317}
322 318
323EXPORT_SYMBOL(acpi_bus_generate_event); 319EXPORT_SYMBOL(acpi_bus_generate_event);
@@ -329,10 +325,9 @@ int acpi_bus_receive_event(struct acpi_bus_event *event)
329 325
330 DECLARE_WAITQUEUE(wait, current); 326 DECLARE_WAITQUEUE(wait, current);
331 327
332 ACPI_FUNCTION_TRACE("acpi_bus_receive_event");
333 328
334 if (!event) 329 if (!event)
335 return_VALUE(-EINVAL); 330 return -EINVAL;
336 331
337 if (list_empty(&acpi_bus_event_list)) { 332 if (list_empty(&acpi_bus_event_list)) {
338 333
@@ -346,7 +341,7 @@ int acpi_bus_receive_event(struct acpi_bus_event *event)
346 set_current_state(TASK_RUNNING); 341 set_current_state(TASK_RUNNING);
347 342
348 if (signal_pending(current)) 343 if (signal_pending(current))
349 return_VALUE(-ERESTARTSYS); 344 return -ERESTARTSYS;
350 } 345 }
351 346
352 spin_lock_irqsave(&acpi_bus_event_lock, flags); 347 spin_lock_irqsave(&acpi_bus_event_lock, flags);
@@ -357,13 +352,13 @@ int acpi_bus_receive_event(struct acpi_bus_event *event)
357 spin_unlock_irqrestore(&acpi_bus_event_lock, flags); 352 spin_unlock_irqrestore(&acpi_bus_event_lock, flags);
358 353
359 if (!entry) 354 if (!entry)
360 return_VALUE(-ENODEV); 355 return -ENODEV;
361 356
362 memcpy(event, entry, sizeof(struct acpi_bus_event)); 357 memcpy(event, entry, sizeof(struct acpi_bus_event));
363 358
364 kfree(entry); 359 kfree(entry);
365 360
366 return_VALUE(0); 361 return 0;
367} 362}
368 363
369EXPORT_SYMBOL(acpi_bus_receive_event); 364EXPORT_SYMBOL(acpi_bus_receive_event);
@@ -378,10 +373,9 @@ acpi_bus_check_device(struct acpi_device *device, int *status_changed)
378 acpi_status status = 0; 373 acpi_status status = 0;
379 struct acpi_device_status old_status; 374 struct acpi_device_status old_status;
380 375
381 ACPI_FUNCTION_TRACE("acpi_bus_check_device");
382 376
383 if (!device) 377 if (!device)
384 return_VALUE(-EINVAL); 378 return -EINVAL;
385 379
386 if (status_changed) 380 if (status_changed)
387 *status_changed = 0; 381 *status_changed = 0;
@@ -398,15 +392,15 @@ acpi_bus_check_device(struct acpi_device *device, int *status_changed)
398 if (status_changed) 392 if (status_changed)
399 *status_changed = 1; 393 *status_changed = 1;
400 } 394 }
401 return_VALUE(0); 395 return 0;
402 } 396 }
403 397
404 status = acpi_bus_get_status(device); 398 status = acpi_bus_get_status(device);
405 if (ACPI_FAILURE(status)) 399 if (ACPI_FAILURE(status))
406 return_VALUE(-ENODEV); 400 return -ENODEV;
407 401
408 if (STRUCT_TO_INT(old_status) == STRUCT_TO_INT(device->status)) 402 if (STRUCT_TO_INT(old_status) == STRUCT_TO_INT(device->status))
409 return_VALUE(0); 403 return 0;
410 404
411 if (status_changed) 405 if (status_changed)
412 *status_changed = 1; 406 *status_changed = 1;
@@ -422,7 +416,7 @@ acpi_bus_check_device(struct acpi_device *device, int *status_changed)
422 /* TBD: Handle device removal */ 416 /* TBD: Handle device removal */
423 } 417 }
424 418
425 return_VALUE(0); 419 return 0;
426} 420}
427 421
428static int acpi_bus_check_scope(struct acpi_device *device) 422static int acpi_bus_check_scope(struct acpi_device *device)
@@ -430,25 +424,24 @@ static int acpi_bus_check_scope(struct acpi_device *device)
430 int result = 0; 424 int result = 0;
431 int status_changed = 0; 425 int status_changed = 0;
432 426
433 ACPI_FUNCTION_TRACE("acpi_bus_check_scope");
434 427
435 if (!device) 428 if (!device)
436 return_VALUE(-EINVAL); 429 return -EINVAL;
437 430
438 /* Status Change? */ 431 /* Status Change? */
439 result = acpi_bus_check_device(device, &status_changed); 432 result = acpi_bus_check_device(device, &status_changed);
440 if (result) 433 if (result)
441 return_VALUE(result); 434 return result;
442 435
443 if (!status_changed) 436 if (!status_changed)
444 return_VALUE(0); 437 return 0;
445 438
446 /* 439 /*
447 * TBD: Enumerate child devices within this device's scope and 440 * TBD: Enumerate child devices within this device's scope and
448 * run acpi_bus_check_device()'s on them. 441 * run acpi_bus_check_device()'s on them.
449 */ 442 */
450 443
451 return_VALUE(0); 444 return 0;
452} 445}
453 446
454/** 447/**
@@ -461,10 +454,9 @@ static void acpi_bus_notify(acpi_handle handle, u32 type, void *data)
461 int result = 0; 454 int result = 0;
462 struct acpi_device *device = NULL; 455 struct acpi_device *device = NULL;
463 456
464 ACPI_FUNCTION_TRACE("acpi_bus_notify");
465 457
466 if (acpi_bus_get_device(handle, &device)) 458 if (acpi_bus_get_device(handle, &device))
467 return_VOID; 459 return;
468 460
469 switch (type) { 461 switch (type) {
470 462
@@ -539,7 +531,7 @@ static void acpi_bus_notify(acpi_handle handle, u32 type, void *data)
539 break; 531 break;
540 } 532 }
541 533
542 return_VOID; 534 return;
543} 535}
544 536
545/* -------------------------------------------------------------------------- 537/* --------------------------------------------------------------------------
@@ -553,7 +545,6 @@ static int __init acpi_bus_init_irq(void)
553 struct acpi_object_list arg_list = { 1, &arg }; 545 struct acpi_object_list arg_list = { 1, &arg };
554 char *message = NULL; 546 char *message = NULL;
555 547
556 ACPI_FUNCTION_TRACE("acpi_bus_init_irq");
557 548
558 /* 549 /*
559 * Let the system know what interrupt model we are using by 550 * Let the system know what interrupt model we are using by
@@ -572,7 +563,7 @@ static int __init acpi_bus_init_irq(void)
572 break; 563 break;
573 default: 564 default:
574 printk(KERN_WARNING PREFIX "Unknown interrupt routing model\n"); 565 printk(KERN_WARNING PREFIX "Unknown interrupt routing model\n");
575 return_VALUE(-ENODEV); 566 return -ENODEV;
576 } 567 }
577 568
578 printk(KERN_INFO PREFIX "Using %s for interrupt routing\n", message); 569 printk(KERN_INFO PREFIX "Using %s for interrupt routing\n", message);
@@ -581,11 +572,11 @@ static int __init acpi_bus_init_irq(void)
581 572
582 status = acpi_evaluate_object(NULL, "\\_PIC", &arg_list, NULL); 573 status = acpi_evaluate_object(NULL, "\\_PIC", &arg_list, NULL);
583 if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) { 574 if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) {
584 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error evaluating _PIC\n")); 575 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PIC"));
585 return_VALUE(-ENODEV); 576 return -ENODEV;
586 } 577 }
587 578
588 return_VALUE(0); 579 return 0;
589} 580}
590 581
591void __init acpi_early_init(void) 582void __init acpi_early_init(void)
@@ -593,10 +584,9 @@ void __init acpi_early_init(void)
593 acpi_status status = AE_OK; 584 acpi_status status = AE_OK;
594 struct acpi_buffer buffer = { sizeof(acpi_fadt), &acpi_fadt }; 585 struct acpi_buffer buffer = { sizeof(acpi_fadt), &acpi_fadt };
595 586
596 ACPI_FUNCTION_TRACE("acpi_early_init");
597 587
598 if (acpi_disabled) 588 if (acpi_disabled)
599 return_VOID; 589 return;
600 590
601 printk(KERN_INFO PREFIX "Core revision %08x\n", ACPI_CA_VERSION); 591 printk(KERN_INFO PREFIX "Core revision %08x\n", ACPI_CA_VERSION);
602 592
@@ -656,11 +646,11 @@ void __init acpi_early_init(void)
656 goto error0; 646 goto error0;
657 } 647 }
658 648
659 return_VOID; 649 return;
660 650
661 error0: 651 error0:
662 disable_acpi(); 652 disable_acpi();
663 return_VOID; 653 return;
664} 654}
665 655
666static int __init acpi_bus_init(void) 656static int __init acpi_bus_init(void)
@@ -669,7 +659,6 @@ static int __init acpi_bus_init(void)
669 acpi_status status = AE_OK; 659 acpi_status status = AE_OK;
670 extern acpi_status acpi_os_initialize1(void); 660 extern acpi_status acpi_os_initialize1(void);
671 661
672 ACPI_FUNCTION_TRACE("acpi_bus_init");
673 662
674 status = acpi_os_initialize1(); 663 status = acpi_os_initialize1();
675 664
@@ -731,12 +720,12 @@ static int __init acpi_bus_init(void)
731 */ 720 */
732 acpi_root_dir = proc_mkdir(ACPI_BUS_FILE_ROOT, NULL); 721 acpi_root_dir = proc_mkdir(ACPI_BUS_FILE_ROOT, NULL);
733 722
734 return_VALUE(0); 723 return 0;
735 724
736 /* Mimic structured exception handling */ 725 /* Mimic structured exception handling */
737 error1: 726 error1:
738 acpi_terminate(); 727 acpi_terminate();
739 return_VALUE(-ENODEV); 728 return -ENODEV;
740} 729}
741 730
742decl_subsys(acpi, NULL, NULL); 731decl_subsys(acpi, NULL, NULL);
@@ -745,14 +734,16 @@ static int __init acpi_init(void)
745{ 734{
746 int result = 0; 735 int result = 0;
747 736
748 ACPI_FUNCTION_TRACE("acpi_init");
749 737
750 if (acpi_disabled) { 738 if (acpi_disabled) {
751 printk(KERN_INFO PREFIX "Interpreter disabled.\n"); 739 printk(KERN_INFO PREFIX "Interpreter disabled.\n");
752 return_VALUE(-ENODEV); 740 return -ENODEV;
753 } 741 }
754 742
755 firmware_register(&acpi_subsys); 743 result = firmware_register(&acpi_subsys);
744 if (result < 0)
745 printk(KERN_WARNING "%s: firmware_register error: %d\n",
746 __FUNCTION__, result);
756 747
757 result = acpi_bus_init(); 748 result = acpi_bus_init();
758 749
@@ -770,7 +761,7 @@ static int __init acpi_init(void)
770 } else 761 } else
771 disable_acpi(); 762 disable_acpi();
772 763
773 return_VALUE(result); 764 return result;
774} 765}
775 766
776subsys_initcall(acpi_init); 767subsys_initcall(acpi_init);
diff --git a/drivers/acpi/button.c b/drivers/acpi/button.c
index 4b6d9f0096a1..5ef885e82c78 100644
--- a/drivers/acpi/button.c
+++ b/drivers/acpi/button.c
@@ -82,20 +82,19 @@ static struct acpi_driver acpi_button_driver = {
82}; 82};
83 83
84struct acpi_button { 84struct acpi_button {
85 acpi_handle handle;
86 struct acpi_device *device; /* Fixed button kludge */ 85 struct acpi_device *device; /* Fixed button kludge */
87 u8 type; 86 u8 type;
88 unsigned long pushed; 87 unsigned long pushed;
89}; 88};
90 89
91static struct file_operations acpi_button_info_fops = { 90static const struct file_operations acpi_button_info_fops = {
92 .open = acpi_button_info_open_fs, 91 .open = acpi_button_info_open_fs,
93 .read = seq_read, 92 .read = seq_read,
94 .llseek = seq_lseek, 93 .llseek = seq_lseek,
95 .release = single_release, 94 .release = single_release,
96}; 95};
97 96
98static struct file_operations acpi_button_state_fops = { 97static const struct file_operations acpi_button_state_fops = {
99 .open = acpi_button_state_open_fs, 98 .open = acpi_button_state_open_fs,
100 .read = seq_read, 99 .read = seq_read,
101 .llseek = seq_lseek, 100 .llseek = seq_lseek,
@@ -112,15 +111,14 @@ static int acpi_button_info_seq_show(struct seq_file *seq, void *offset)
112{ 111{
113 struct acpi_button *button = (struct acpi_button *)seq->private; 112 struct acpi_button *button = (struct acpi_button *)seq->private;
114 113
115 ACPI_FUNCTION_TRACE("acpi_button_info_seq_show");
116 114
117 if (!button || !button->device) 115 if (!button || !button->device)
118 return_VALUE(0); 116 return 0;
119 117
120 seq_printf(seq, "type: %s\n", 118 seq_printf(seq, "type: %s\n",
121 acpi_device_name(button->device)); 119 acpi_device_name(button->device));
122 120
123 return_VALUE(0); 121 return 0;
124} 122}
125 123
126static int acpi_button_info_open_fs(struct inode *inode, struct file *file) 124static int acpi_button_info_open_fs(struct inode *inode, struct file *file)
@@ -134,12 +132,11 @@ static int acpi_button_state_seq_show(struct seq_file *seq, void *offset)
134 acpi_status status; 132 acpi_status status;
135 unsigned long state; 133 unsigned long state;
136 134
137 ACPI_FUNCTION_TRACE("acpi_button_state_seq_show");
138 135
139 if (!button || !button->device) 136 if (!button || !button->device)
140 return_VALUE(0); 137 return 0;
141 138
142 status = acpi_evaluate_integer(button->handle, "_LID", NULL, &state); 139 status = acpi_evaluate_integer(button->device->handle, "_LID", NULL, &state);
143 if (ACPI_FAILURE(status)) { 140 if (ACPI_FAILURE(status)) {
144 seq_printf(seq, "state: unsupported\n"); 141 seq_printf(seq, "state: unsupported\n");
145 } else { 142 } else {
@@ -147,7 +144,7 @@ static int acpi_button_state_seq_show(struct seq_file *seq, void *offset)
147 (state ? "open" : "closed")); 144 (state ? "open" : "closed"));
148 } 145 }
149 146
150 return_VALUE(0); 147 return 0;
151} 148}
152 149
153static int acpi_button_state_open_fs(struct inode *inode, struct file *file) 150static int acpi_button_state_open_fs(struct inode *inode, struct file *file)
@@ -164,10 +161,9 @@ static int acpi_button_add_fs(struct acpi_device *device)
164 struct proc_dir_entry *entry = NULL; 161 struct proc_dir_entry *entry = NULL;
165 struct acpi_button *button = NULL; 162 struct acpi_button *button = NULL;
166 163
167 ACPI_FUNCTION_TRACE("acpi_button_add_fs");
168 164
169 if (!device || !acpi_driver_data(device)) 165 if (!device || !acpi_driver_data(device))
170 return_VALUE(-EINVAL); 166 return -EINVAL;
171 167
172 button = acpi_driver_data(device); 168 button = acpi_driver_data(device);
173 169
@@ -195,21 +191,19 @@ static int acpi_button_add_fs(struct acpi_device *device)
195 } 191 }
196 192
197 if (!entry) 193 if (!entry)
198 return_VALUE(-ENODEV); 194 return -ENODEV;
199 entry->owner = THIS_MODULE; 195 entry->owner = THIS_MODULE;
200 196
201 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), entry); 197 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), entry);
202 if (!acpi_device_dir(device)) 198 if (!acpi_device_dir(device))
203 return_VALUE(-ENODEV); 199 return -ENODEV;
204 acpi_device_dir(device)->owner = THIS_MODULE; 200 acpi_device_dir(device)->owner = THIS_MODULE;
205 201
206 /* 'info' [R] */ 202 /* 'info' [R] */
207 entry = create_proc_entry(ACPI_BUTTON_FILE_INFO, 203 entry = create_proc_entry(ACPI_BUTTON_FILE_INFO,
208 S_IRUGO, acpi_device_dir(device)); 204 S_IRUGO, acpi_device_dir(device));
209 if (!entry) 205 if (!entry)
210 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 206 return -ENODEV;
211 "Unable to create '%s' fs entry\n",
212 ACPI_BUTTON_FILE_INFO));
213 else { 207 else {
214 entry->proc_fops = &acpi_button_info_fops; 208 entry->proc_fops = &acpi_button_info_fops;
215 entry->data = acpi_driver_data(device); 209 entry->data = acpi_driver_data(device);
@@ -221,9 +215,7 @@ static int acpi_button_add_fs(struct acpi_device *device)
221 entry = create_proc_entry(ACPI_BUTTON_FILE_STATE, 215 entry = create_proc_entry(ACPI_BUTTON_FILE_STATE,
222 S_IRUGO, acpi_device_dir(device)); 216 S_IRUGO, acpi_device_dir(device));
223 if (!entry) 217 if (!entry)
224 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 218 return -ENODEV;
225 "Unable to create '%s' fs entry\n",
226 ACPI_BUTTON_FILE_INFO));
227 else { 219 else {
228 entry->proc_fops = &acpi_button_state_fops; 220 entry->proc_fops = &acpi_button_state_fops;
229 entry->data = acpi_driver_data(device); 221 entry->data = acpi_driver_data(device);
@@ -231,14 +223,13 @@ static int acpi_button_add_fs(struct acpi_device *device)
231 } 223 }
232 } 224 }
233 225
234 return_VALUE(0); 226 return 0;
235} 227}
236 228
237static int acpi_button_remove_fs(struct acpi_device *device) 229static int acpi_button_remove_fs(struct acpi_device *device)
238{ 230{
239 struct acpi_button *button = NULL; 231 struct acpi_button *button = NULL;
240 232
241 ACPI_FUNCTION_TRACE("acpi_button_remove_fs");
242 233
243 button = acpi_driver_data(device); 234 button = acpi_driver_data(device);
244 if (acpi_device_dir(device)) { 235 if (acpi_device_dir(device)) {
@@ -253,7 +244,7 @@ static int acpi_button_remove_fs(struct acpi_device *device)
253 acpi_device_dir(device) = NULL; 244 acpi_device_dir(device) = NULL;
254 } 245 }
255 246
256 return_VALUE(0); 247 return 0;
257} 248}
258 249
259/* -------------------------------------------------------------------------- 250/* --------------------------------------------------------------------------
@@ -264,10 +255,9 @@ static void acpi_button_notify(acpi_handle handle, u32 event, void *data)
264{ 255{
265 struct acpi_button *button = (struct acpi_button *)data; 256 struct acpi_button *button = (struct acpi_button *)data;
266 257
267 ACPI_FUNCTION_TRACE("acpi_button_notify");
268 258
269 if (!button || !button->device) 259 if (!button || !button->device)
270 return_VOID; 260 return;
271 261
272 switch (event) { 262 switch (event) {
273 case ACPI_BUTTON_NOTIFY_STATUS: 263 case ACPI_BUTTON_NOTIFY_STATUS:
@@ -280,21 +270,20 @@ static void acpi_button_notify(acpi_handle handle, u32 event, void *data)
280 break; 270 break;
281 } 271 }
282 272
283 return_VOID; 273 return;
284} 274}
285 275
286static acpi_status acpi_button_notify_fixed(void *data) 276static acpi_status acpi_button_notify_fixed(void *data)
287{ 277{
288 struct acpi_button *button = (struct acpi_button *)data; 278 struct acpi_button *button = (struct acpi_button *)data;
289 279
290 ACPI_FUNCTION_TRACE("acpi_button_notify_fixed");
291 280
292 if (!button) 281 if (!button)
293 return_ACPI_STATUS(AE_BAD_PARAMETER); 282 return AE_BAD_PARAMETER;
294 283
295 acpi_button_notify(button->handle, ACPI_BUTTON_NOTIFY_STATUS, button); 284 acpi_button_notify(button->device->handle, ACPI_BUTTON_NOTIFY_STATUS, button);
296 285
297 return_ACPI_STATUS(AE_OK); 286 return AE_OK;
298} 287}
299 288
300static int acpi_button_add(struct acpi_device *device) 289static int acpi_button_add(struct acpi_device *device)
@@ -303,18 +292,16 @@ static int acpi_button_add(struct acpi_device *device)
303 acpi_status status = AE_OK; 292 acpi_status status = AE_OK;
304 struct acpi_button *button = NULL; 293 struct acpi_button *button = NULL;
305 294
306 ACPI_FUNCTION_TRACE("acpi_button_add");
307 295
308 if (!device) 296 if (!device)
309 return_VALUE(-EINVAL); 297 return -EINVAL;
310 298
311 button = kmalloc(sizeof(struct acpi_button), GFP_KERNEL); 299 button = kmalloc(sizeof(struct acpi_button), GFP_KERNEL);
312 if (!button) 300 if (!button)
313 return_VALUE(-ENOMEM); 301 return -ENOMEM;
314 memset(button, 0, sizeof(struct acpi_button)); 302 memset(button, 0, sizeof(struct acpi_button));
315 303
316 button->device = device; 304 button->device = device;
317 button->handle = device->handle;
318 acpi_driver_data(device) = button; 305 acpi_driver_data(device) = button;
319 306
320 /* 307 /*
@@ -349,8 +336,8 @@ static int acpi_button_add(struct acpi_device *device)
349 sprintf(acpi_device_class(device), "%s/%s", 336 sprintf(acpi_device_class(device), "%s/%s",
350 ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_LID); 337 ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_LID);
351 } else { 338 } else {
352 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Unsupported hid [%s]\n", 339 printk(KERN_ERR PREFIX "Unsupported hid [%s]\n",
353 acpi_device_hid(device))); 340 acpi_device_hid(device));
354 result = -ENODEV; 341 result = -ENODEV;
355 goto end; 342 goto end;
356 } 343 }
@@ -373,7 +360,7 @@ static int acpi_button_add(struct acpi_device *device)
373 button); 360 button);
374 break; 361 break;
375 default: 362 default:
376 status = acpi_install_notify_handler(button->handle, 363 status = acpi_install_notify_handler(device->handle,
377 ACPI_DEVICE_NOTIFY, 364 ACPI_DEVICE_NOTIFY,
378 acpi_button_notify, 365 acpi_button_notify,
379 button); 366 button);
@@ -381,8 +368,6 @@ static int acpi_button_add(struct acpi_device *device)
381 } 368 }
382 369
383 if (ACPI_FAILURE(status)) { 370 if (ACPI_FAILURE(status)) {
384 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
385 "Error installing notify handler\n"));
386 result = -ENODEV; 371 result = -ENODEV;
387 goto end; 372 goto end;
388 } 373 }
@@ -406,7 +391,7 @@ static int acpi_button_add(struct acpi_device *device)
406 kfree(button); 391 kfree(button);
407 } 392 }
408 393
409 return_VALUE(result); 394 return result;
410} 395}
411 396
412static int acpi_button_remove(struct acpi_device *device, int type) 397static int acpi_button_remove(struct acpi_device *device, int type)
@@ -414,10 +399,9 @@ static int acpi_button_remove(struct acpi_device *device, int type)
414 acpi_status status = 0; 399 acpi_status status = 0;
415 struct acpi_button *button = NULL; 400 struct acpi_button *button = NULL;
416 401
417 ACPI_FUNCTION_TRACE("acpi_button_remove");
418 402
419 if (!device || !acpi_driver_data(device)) 403 if (!device || !acpi_driver_data(device))
420 return_VALUE(-EINVAL); 404 return -EINVAL;
421 405
422 button = acpi_driver_data(device); 406 button = acpi_driver_data(device);
423 407
@@ -434,45 +418,39 @@ static int acpi_button_remove(struct acpi_device *device, int type)
434 acpi_button_notify_fixed); 418 acpi_button_notify_fixed);
435 break; 419 break;
436 default: 420 default:
437 status = acpi_remove_notify_handler(button->handle, 421 status = acpi_remove_notify_handler(device->handle,
438 ACPI_DEVICE_NOTIFY, 422 ACPI_DEVICE_NOTIFY,
439 acpi_button_notify); 423 acpi_button_notify);
440 break; 424 break;
441 } 425 }
442 426
443 if (ACPI_FAILURE(status))
444 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
445 "Error removing notify handler\n"));
446
447 acpi_button_remove_fs(device); 427 acpi_button_remove_fs(device);
448 428
449 kfree(button); 429 kfree(button);
450 430
451 return_VALUE(0); 431 return 0;
452} 432}
453 433
454static int __init acpi_button_init(void) 434static int __init acpi_button_init(void)
455{ 435{
456 int result = 0; 436 int result = 0;
457 437
458 ACPI_FUNCTION_TRACE("acpi_button_init");
459 438
460 acpi_button_dir = proc_mkdir(ACPI_BUTTON_CLASS, acpi_root_dir); 439 acpi_button_dir = proc_mkdir(ACPI_BUTTON_CLASS, acpi_root_dir);
461 if (!acpi_button_dir) 440 if (!acpi_button_dir)
462 return_VALUE(-ENODEV); 441 return -ENODEV;
463 acpi_button_dir->owner = THIS_MODULE; 442 acpi_button_dir->owner = THIS_MODULE;
464 result = acpi_bus_register_driver(&acpi_button_driver); 443 result = acpi_bus_register_driver(&acpi_button_driver);
465 if (result < 0) { 444 if (result < 0) {
466 remove_proc_entry(ACPI_BUTTON_CLASS, acpi_root_dir); 445 remove_proc_entry(ACPI_BUTTON_CLASS, acpi_root_dir);
467 return_VALUE(-ENODEV); 446 return -ENODEV;
468 } 447 }
469 448
470 return_VALUE(0); 449 return 0;
471} 450}
472 451
473static void __exit acpi_button_exit(void) 452static void __exit acpi_button_exit(void)
474{ 453{
475 ACPI_FUNCTION_TRACE("acpi_button_exit");
476 454
477 acpi_bus_unregister_driver(&acpi_button_driver); 455 acpi_bus_unregister_driver(&acpi_button_driver);
478 456
@@ -484,7 +462,7 @@ static void __exit acpi_button_exit(void)
484 remove_proc_entry(ACPI_BUTTON_SUBCLASS_LID, acpi_button_dir); 462 remove_proc_entry(ACPI_BUTTON_SUBCLASS_LID, acpi_button_dir);
485 remove_proc_entry(ACPI_BUTTON_CLASS, acpi_root_dir); 463 remove_proc_entry(ACPI_BUTTON_CLASS, acpi_root_dir);
486 464
487 return_VOID; 465 return;
488} 466}
489 467
490module_init(acpi_button_init); 468module_init(acpi_button_init);
diff --git a/drivers/acpi/cm_sbs.c b/drivers/acpi/cm_sbs.c
new file mode 100644
index 000000000000..a01ce6700bfe
--- /dev/null
+++ b/drivers/acpi/cm_sbs.c
@@ -0,0 +1,113 @@
1/*
2 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or (at
7 * your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17 *
18 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
19 */
20
21#include <linux/kernel.h>
22#include <linux/module.h>
23#include <linux/init.h>
24#include <linux/acpi.h>
25#include <linux/types.h>
26#include <linux/proc_fs.h>
27#include <linux/seq_file.h>
28#include <acpi/acpi_bus.h>
29#include <acpi/acpi_drivers.h>
30#include <acpi/acmacros.h>
31#include <acpi/actypes.h>
32#include <acpi/acutils.h>
33
34ACPI_MODULE_NAME("cm_sbs")
35#define ACPI_AC_CLASS "ac_adapter"
36#define ACPI_BATTERY_CLASS "battery"
37#define ACPI_SBS_COMPONENT 0x00080000
38#define _COMPONENT ACPI_SBS_COMPONENT
39static struct proc_dir_entry *acpi_ac_dir;
40static struct proc_dir_entry *acpi_battery_dir;
41
42static DEFINE_MUTEX(cm_sbs_mutex);
43
44static int lock_ac_dir_cnt;
45static int lock_battery_dir_cnt;
46
47struct proc_dir_entry *acpi_lock_ac_dir(void)
48{
49 mutex_lock(&cm_sbs_mutex);
50 if (!acpi_ac_dir)
51 acpi_ac_dir = proc_mkdir(ACPI_AC_CLASS, acpi_root_dir);
52 if (acpi_ac_dir) {
53 lock_ac_dir_cnt++;
54 } else {
55 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
56 "Cannot create %s\n", ACPI_AC_CLASS));
57 }
58 mutex_unlock(&cm_sbs_mutex);
59 return acpi_ac_dir;
60}
61EXPORT_SYMBOL(acpi_lock_ac_dir);
62
63void acpi_unlock_ac_dir(struct proc_dir_entry *acpi_ac_dir_param)
64{
65 mutex_lock(&cm_sbs_mutex);
66 if (acpi_ac_dir_param)
67 lock_ac_dir_cnt--;
68 if (lock_ac_dir_cnt == 0 && acpi_ac_dir_param && acpi_ac_dir) {
69 remove_proc_entry(ACPI_AC_CLASS, acpi_root_dir);
70 acpi_ac_dir = 0;
71 }
72 mutex_unlock(&cm_sbs_mutex);
73}
74EXPORT_SYMBOL(acpi_unlock_ac_dir);
75
76struct proc_dir_entry *acpi_lock_battery_dir(void)
77{
78 mutex_lock(&cm_sbs_mutex);
79 if (!acpi_battery_dir) {
80 acpi_battery_dir =
81 proc_mkdir(ACPI_BATTERY_CLASS, acpi_root_dir);
82 }
83 if (acpi_battery_dir) {
84 lock_battery_dir_cnt++;
85 } else {
86 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
87 "Cannot create %s\n", ACPI_BATTERY_CLASS));
88 }
89 mutex_unlock(&cm_sbs_mutex);
90 return acpi_battery_dir;
91}
92EXPORT_SYMBOL(acpi_lock_battery_dir);
93
94void acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir_param)
95{
96 mutex_lock(&cm_sbs_mutex);
97 if (acpi_battery_dir_param)
98 lock_battery_dir_cnt--;
99 if (lock_battery_dir_cnt == 0 && acpi_battery_dir_param
100 && acpi_battery_dir) {
101 remove_proc_entry(ACPI_BATTERY_CLASS, acpi_root_dir);
102 acpi_battery_dir = 0;
103 }
104 mutex_unlock(&cm_sbs_mutex);
105 return;
106}
107EXPORT_SYMBOL(acpi_unlock_battery_dir);
108
109static int __init acpi_cm_sbs_init(void)
110{
111 return 0;
112}
113subsys_initcall(acpi_cm_sbs_init);
diff --git a/drivers/acpi/container.c b/drivers/acpi/container.c
index b69a8cad82b7..871aa520ece7 100644
--- a/drivers/acpi/container.c
+++ b/drivers/acpi/container.c
@@ -73,17 +73,16 @@ static int is_device_present(acpi_handle handle)
73 acpi_status status; 73 acpi_status status;
74 unsigned long sta; 74 unsigned long sta;
75 75
76 ACPI_FUNCTION_TRACE("is_device_present");
77 76
78 status = acpi_get_handle(handle, "_STA", &temp); 77 status = acpi_get_handle(handle, "_STA", &temp);
79 if (ACPI_FAILURE(status)) 78 if (ACPI_FAILURE(status))
80 return_VALUE(1); /* _STA not found, assmue device present */ 79 return 1; /* _STA not found, assmue device present */
81 80
82 status = acpi_evaluate_integer(handle, "_STA", NULL, &sta); 81 status = acpi_evaluate_integer(handle, "_STA", NULL, &sta);
83 if (ACPI_FAILURE(status)) 82 if (ACPI_FAILURE(status))
84 return_VALUE(0); /* Firmware error */ 83 return 0; /* Firmware error */
85 84
86 return_VALUE((sta & ACPI_STA_PRESENT) == ACPI_STA_PRESENT); 85 return ((sta & ACPI_STA_PRESENT) == ACPI_STA_PRESENT);
87} 86}
88 87
89/*******************************************************************/ 88/*******************************************************************/
@@ -91,16 +90,15 @@ static int acpi_container_add(struct acpi_device *device)
91{ 90{
92 struct acpi_container *container; 91 struct acpi_container *container;
93 92
94 ACPI_FUNCTION_TRACE("acpi_container_add");
95 93
96 if (!device) { 94 if (!device) {
97 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "device is NULL\n")); 95 printk(KERN_ERR PREFIX "device is NULL\n");
98 return_VALUE(-EINVAL); 96 return -EINVAL;
99 } 97 }
100 98
101 container = kmalloc(sizeof(struct acpi_container), GFP_KERNEL); 99 container = kmalloc(sizeof(struct acpi_container), GFP_KERNEL);
102 if (!container) 100 if (!container)
103 return_VALUE(-ENOMEM); 101 return -ENOMEM;
104 102
105 memset(container, 0, sizeof(struct acpi_container)); 103 memset(container, 0, sizeof(struct acpi_container));
106 container->handle = device->handle; 104 container->handle = device->handle;
@@ -111,7 +109,7 @@ static int acpi_container_add(struct acpi_device *device)
111 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device <%s> bid <%s>\n", 109 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device <%s> bid <%s>\n",
112 acpi_device_name(device), acpi_device_bid(device))); 110 acpi_device_name(device), acpi_device_bid(device)));
113 111
114 return_VALUE(0); 112 return 0;
115} 113}
116 114
117static int acpi_container_remove(struct acpi_device *device, int type) 115static int acpi_container_remove(struct acpi_device *device, int type)
@@ -130,23 +128,22 @@ static int container_device_add(struct acpi_device **device, acpi_handle handle)
130 struct acpi_device *pdev; 128 struct acpi_device *pdev;
131 int result; 129 int result;
132 130
133 ACPI_FUNCTION_TRACE("container_device_add");
134 131
135 if (acpi_get_parent(handle, &phandle)) { 132 if (acpi_get_parent(handle, &phandle)) {
136 return_VALUE(-ENODEV); 133 return -ENODEV;
137 } 134 }
138 135
139 if (acpi_bus_get_device(phandle, &pdev)) { 136 if (acpi_bus_get_device(phandle, &pdev)) {
140 return_VALUE(-ENODEV); 137 return -ENODEV;
141 } 138 }
142 139
143 if (acpi_bus_add(device, pdev, handle, ACPI_BUS_TYPE_DEVICE)) { 140 if (acpi_bus_add(device, pdev, handle, ACPI_BUS_TYPE_DEVICE)) {
144 return_VALUE(-ENODEV); 141 return -ENODEV;
145 } 142 }
146 143
147 result = acpi_bus_start(*device); 144 result = acpi_bus_start(*device);
148 145
149 return_VALUE(result); 146 return result;
150} 147}
151 148
152static void container_notify_cb(acpi_handle handle, u32 type, void *context) 149static void container_notify_cb(acpi_handle handle, u32 type, void *context)
@@ -156,7 +153,6 @@ static void container_notify_cb(acpi_handle handle, u32 type, void *context)
156 int present; 153 int present;
157 acpi_status status; 154 acpi_status status;
158 155
159 ACPI_FUNCTION_TRACE("container_notify_cb");
160 156
161 present = is_device_present(handle); 157 present = is_device_present(handle);
162 158
@@ -192,7 +188,7 @@ static void container_notify_cb(acpi_handle handle, u32 type, void *context)
192 default: 188 default:
193 break; 189 break;
194 } 190 }
195 return_VOID; 191 return;
196} 192}
197 193
198static acpi_status 194static acpi_status
@@ -205,11 +201,10 @@ container_walk_namespace_cb(acpi_handle handle,
205 acpi_status status; 201 acpi_status status;
206 int *action = context; 202 int *action = context;
207 203
208 ACPI_FUNCTION_TRACE("container_walk_namespace_cb");
209 204
210 status = acpi_get_object_info(handle, &buffer); 205 status = acpi_get_object_info(handle, &buffer);
211 if (ACPI_FAILURE(status) || !buffer.pointer) { 206 if (ACPI_FAILURE(status) || !buffer.pointer) {
212 return_ACPI_STATUS(AE_OK); 207 return AE_OK;
213 } 208 }
214 209
215 info = buffer.pointer; 210 info = buffer.pointer;
@@ -241,9 +236,9 @@ container_walk_namespace_cb(acpi_handle handle,
241 } 236 }
242 237
243 end: 238 end:
244 acpi_os_free(buffer.pointer); 239 kfree(buffer.pointer);
245 240
246 return_ACPI_STATUS(AE_OK); 241 return AE_OK;
247} 242}
248 243
249static int __init acpi_container_init(void) 244static int __init acpi_container_init(void)
@@ -269,7 +264,6 @@ static void __exit acpi_container_exit(void)
269{ 264{
270 int action = UNINSTALL_NOTIFY_HANDLER; 265 int action = UNINSTALL_NOTIFY_HANDLER;
271 266
272 ACPI_FUNCTION_TRACE("acpi_container_exit");
273 267
274 acpi_walk_namespace(ACPI_TYPE_DEVICE, 268 acpi_walk_namespace(ACPI_TYPE_DEVICE,
275 ACPI_ROOT_OBJECT, 269 ACPI_ROOT_OBJECT,
@@ -278,7 +272,7 @@ static void __exit acpi_container_exit(void)
278 272
279 acpi_bus_unregister_driver(&acpi_container_driver); 273 acpi_bus_unregister_driver(&acpi_container_driver);
280 274
281 return_VOID; 275 return;
282} 276}
283 277
284module_init(acpi_container_init); 278module_init(acpi_container_init);
diff --git a/drivers/acpi/debug.c b/drivers/acpi/debug.c
index 263322b7d113..35c6af8a83cd 100644
--- a/drivers/acpi/debug.c
+++ b/drivers/acpi/debug.c
@@ -155,13 +155,12 @@ acpi_system_write_debug(struct file *file,
155{ 155{
156 char debug_string[12] = { '\0' }; 156 char debug_string[12] = { '\0' };
157 157
158 ACPI_FUNCTION_TRACE("acpi_system_write_debug");
159 158
160 if (count > sizeof(debug_string) - 1) 159 if (count > sizeof(debug_string) - 1)
161 return_VALUE(-EINVAL); 160 return -EINVAL;
162 161
163 if (copy_from_user(debug_string, buffer, count)) 162 if (copy_from_user(debug_string, buffer, count))
164 return_VALUE(-EFAULT); 163 return -EFAULT;
165 164
166 debug_string[count] = '\0'; 165 debug_string[count] = '\0';
167 166
@@ -173,10 +172,10 @@ acpi_system_write_debug(struct file *file,
173 acpi_dbg_level = simple_strtoul(debug_string, NULL, 0); 172 acpi_dbg_level = simple_strtoul(debug_string, NULL, 0);
174 break; 173 break;
175 default: 174 default:
176 return_VALUE(-EINVAL); 175 return -EINVAL;
177 } 176 }
178 177
179 return_VALUE(count); 178 return count;
180} 179}
181 180
182static int __init acpi_debug_init(void) 181static int __init acpi_debug_init(void)
@@ -185,10 +184,9 @@ static int __init acpi_debug_init(void)
185 int error = 0; 184 int error = 0;
186 char *name; 185 char *name;
187 186
188 ACPI_FUNCTION_TRACE("acpi_debug_init");
189 187
190 if (acpi_disabled) 188 if (acpi_disabled)
191 return_VALUE(0); 189 return 0;
192 190
193 /* 'debug_layer' [R/W] */ 191 /* 'debug_layer' [R/W] */
194 name = ACPI_SYSTEM_FILE_DEBUG_LAYER; 192 name = ACPI_SYSTEM_FILE_DEBUG_LAYER;
@@ -213,15 +211,12 @@ static int __init acpi_debug_init(void)
213 goto Error; 211 goto Error;
214 212
215 Done: 213 Done:
216 return_VALUE(error); 214 return error;
217 215
218 Error: 216 Error:
219 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
220 "Unable to create '%s' proc fs entry\n", name));
221
222 remove_proc_entry(ACPI_SYSTEM_FILE_DEBUG_LEVEL, acpi_root_dir); 217 remove_proc_entry(ACPI_SYSTEM_FILE_DEBUG_LEVEL, acpi_root_dir);
223 remove_proc_entry(ACPI_SYSTEM_FILE_DEBUG_LAYER, acpi_root_dir); 218 remove_proc_entry(ACPI_SYSTEM_FILE_DEBUG_LAYER, acpi_root_dir);
224 error = -EFAULT; 219 error = -ENODEV;
225 goto Done; 220 goto Done;
226} 221}
227 222
diff --git a/drivers/acpi/dispatcher/dsinit.c b/drivers/acpi/dispatcher/dsinit.c
index bbdf990e9f65..1888c055d10f 100644
--- a/drivers/acpi/dispatcher/dsinit.c
+++ b/drivers/acpi/dispatcher/dsinit.c
@@ -116,46 +116,6 @@ acpi_ds_init_one_object(acpi_handle obj_handle,
116 116
117 case ACPI_TYPE_METHOD: 117 case ACPI_TYPE_METHOD:
118 118
119 /*
120 * Set the execution data width (32 or 64) based upon the
121 * revision number of the parent ACPI table.
122 * TBD: This is really for possible future support of integer width
123 * on a per-table basis. Currently, we just use a global for the width.
124 */
125 if (info->table_desc->pointer->revision == 1) {
126 node->flags |= ANOBJ_DATA_WIDTH_32;
127 }
128#ifdef ACPI_INIT_PARSE_METHODS
129 /*
130 * Note 11/2005: Removed this code to parse all methods during table
131 * load because it causes problems if there are any errors during the
132 * parse. Also, it seems like overkill and we probably don't want to
133 * abort a table load because of an issue with a single method.
134 */
135
136 /*
137 * Print a dot for each method unless we are going to print
138 * the entire pathname
139 */
140 if (!(acpi_dbg_level & ACPI_LV_INIT_NAMES)) {
141 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT, "."));
142 }
143
144 /*
145 * Always parse methods to detect errors, we will delete
146 * the parse tree below
147 */
148 status = acpi_ds_parse_method(obj_handle);
149 if (ACPI_FAILURE(status)) {
150 ACPI_ERROR((AE_INFO,
151 "Method %p [%4.4s] - parse failure, %s",
152 obj_handle,
153 acpi_ut_get_node_name(obj_handle),
154 acpi_format_exception(status)));
155
156 /* This parse failed, but we will continue parsing more methods */
157 }
158#endif
159 info->method_count++; 119 info->method_count++;
160 break; 120 break;
161 121
diff --git a/drivers/acpi/dispatcher/dsmethod.c b/drivers/acpi/dispatcher/dsmethod.c
index bc9aca4e7401..cf888add3191 100644
--- a/drivers/acpi/dispatcher/dsmethod.c
+++ b/drivers/acpi/dispatcher/dsmethod.c
@@ -52,6 +52,10 @@
52#define _COMPONENT ACPI_DISPATCHER 52#define _COMPONENT ACPI_DISPATCHER
53ACPI_MODULE_NAME("dsmethod") 53ACPI_MODULE_NAME("dsmethod")
54 54
55/* Local prototypes */
56static acpi_status
57acpi_ds_create_method_mutex(union acpi_operand_object *method_desc);
58
55/******************************************************************************* 59/*******************************************************************************
56 * 60 *
57 * FUNCTION: acpi_ds_method_error 61 * FUNCTION: acpi_ds_method_error
@@ -67,6 +71,7 @@ ACPI_MODULE_NAME("dsmethod")
67 * Note: Allows the exception handler to change the status code 71 * Note: Allows the exception handler to change the status code
68 * 72 *
69 ******************************************************************************/ 73 ******************************************************************************/
74
70acpi_status 75acpi_status
71acpi_ds_method_error(acpi_status status, struct acpi_walk_state *walk_state) 76acpi_ds_method_error(acpi_status status, struct acpi_walk_state *walk_state)
72{ 77{
@@ -113,11 +118,51 @@ acpi_ds_method_error(acpi_status status, struct acpi_walk_state *walk_state)
113 118
114/******************************************************************************* 119/*******************************************************************************
115 * 120 *
121 * FUNCTION: acpi_ds_create_method_mutex
122 *
123 * PARAMETERS: obj_desc - The method object
124 *
125 * RETURN: Status
126 *
127 * DESCRIPTION: Create a mutex object for a serialized control method
128 *
129 ******************************************************************************/
130
131static acpi_status
132acpi_ds_create_method_mutex(union acpi_operand_object *method_desc)
133{
134 union acpi_operand_object *mutex_desc;
135 acpi_status status;
136
137 ACPI_FUNCTION_TRACE(ds_create_method_mutex);
138
139 /* Create the new mutex object */
140
141 mutex_desc = acpi_ut_create_internal_object(ACPI_TYPE_MUTEX);
142 if (!mutex_desc) {
143 return_ACPI_STATUS(AE_NO_MEMORY);
144 }
145
146 /* Create the actual OS Mutex */
147
148 status = acpi_os_create_mutex(&mutex_desc->mutex.os_mutex);
149 if (ACPI_FAILURE(status)) {
150 return_ACPI_STATUS(status);
151 }
152
153 mutex_desc->mutex.sync_level = method_desc->method.sync_level;
154 method_desc->method.mutex = mutex_desc;
155 return_ACPI_STATUS(AE_OK);
156}
157
158/*******************************************************************************
159 *
116 * FUNCTION: acpi_ds_begin_method_execution 160 * FUNCTION: acpi_ds_begin_method_execution
117 * 161 *
118 * PARAMETERS: method_node - Node of the method 162 * PARAMETERS: method_node - Node of the method
119 * obj_desc - The method object 163 * obj_desc - The method object
120 * calling_method_node - Caller of this method (if non-null) 164 * walk_state - current state, NULL if not yet executing
165 * a method.
121 * 166 *
122 * RETURN: Status 167 * RETURN: Status
123 * 168 *
@@ -128,9 +173,9 @@ acpi_ds_method_error(acpi_status status, struct acpi_walk_state *walk_state)
128 ******************************************************************************/ 173 ******************************************************************************/
129 174
130acpi_status 175acpi_status
131acpi_ds_begin_method_execution(struct acpi_namespace_node * method_node, 176acpi_ds_begin_method_execution(struct acpi_namespace_node *method_node,
132 union acpi_operand_object * obj_desc, 177 union acpi_operand_object *obj_desc,
133 struct acpi_namespace_node * calling_method_node) 178 struct acpi_walk_state *walk_state)
134{ 179{
135 acpi_status status = AE_OK; 180 acpi_status status = AE_OK;
136 181
@@ -149,35 +194,80 @@ acpi_ds_begin_method_execution(struct acpi_namespace_node * method_node,
149 } 194 }
150 195
151 /* 196 /*
152 * If there is a concurrency limit on this method, we need to 197 * If this method is serialized, we need to acquire the method mutex.
153 * obtain a unit from the method semaphore.
154 */ 198 */
155 if (obj_desc->method.semaphore) { 199 if (obj_desc->method.method_flags & AML_METHOD_SERIALIZED) {
156 /* 200 /*
157 * Allow recursive method calls, up to the reentrancy/concurrency 201 * Create a mutex for the method if it is defined to be Serialized
158 * limit imposed by the SERIALIZED rule and the sync_level method 202 * and a mutex has not already been created. We defer the mutex creation
159 * parameter. 203 * until a method is actually executed, to minimize the object count
160 *
161 * The point of this code is to avoid permanently blocking a
162 * thread that is making recursive method calls.
163 */ 204 */
164 if (method_node == calling_method_node) { 205 if (!obj_desc->method.mutex) {
165 if (obj_desc->method.thread_count >= 206 status = acpi_ds_create_method_mutex(obj_desc);
166 obj_desc->method.concurrency) { 207 if (ACPI_FAILURE(status)) {
167 return_ACPI_STATUS(AE_AML_METHOD_LIMIT); 208 return_ACPI_STATUS(status);
168 } 209 }
169 } 210 }
170 211
171 /* 212 /*
172 * Get a unit from the method semaphore. This releases the 213 * The current_sync_level (per-thread) must be less than or equal to
173 * interpreter if we block (then reacquires it) 214 * the sync level of the method. This mechanism provides some
215 * deadlock prevention
216 *
217 * Top-level method invocation has no walk state at this point
174 */ 218 */
175 status = 219 if (walk_state &&
176 acpi_ex_system_wait_semaphore(obj_desc->method.semaphore, 220 (walk_state->thread->current_sync_level >
177 ACPI_WAIT_FOREVER); 221 obj_desc->method.mutex->mutex.sync_level)) {
178 if (ACPI_FAILURE(status)) { 222 ACPI_ERROR((AE_INFO,
179 return_ACPI_STATUS(status); 223 "Cannot acquire Mutex for method [%4.4s], current SyncLevel is too large (%d)",
224 acpi_ut_get_node_name(method_node),
225 walk_state->thread->current_sync_level));
226
227 return_ACPI_STATUS(AE_AML_MUTEX_ORDER);
180 } 228 }
229
230 /*
231 * Obtain the method mutex if necessary. Do not acquire mutex for a
232 * recursive call.
233 */
234 if (!walk_state ||
235 !obj_desc->method.mutex->mutex.owner_thread ||
236 (walk_state->thread !=
237 obj_desc->method.mutex->mutex.owner_thread)) {
238 /*
239 * Acquire the method mutex. This releases the interpreter if we
240 * block (and reacquires it before it returns)
241 */
242 status =
243 acpi_ex_system_wait_mutex(obj_desc->method.mutex->
244 mutex.os_mutex,
245 ACPI_WAIT_FOREVER);
246 if (ACPI_FAILURE(status)) {
247 return_ACPI_STATUS(status);
248 }
249
250 /* Update the mutex and walk info and save the original sync_level */
251
252 if (walk_state) {
253 obj_desc->method.mutex->mutex.
254 original_sync_level =
255 walk_state->thread->current_sync_level;
256
257 obj_desc->method.mutex->mutex.owner_thread =
258 walk_state->thread;
259 walk_state->thread->current_sync_level =
260 obj_desc->method.sync_level;
261 } else {
262 obj_desc->method.mutex->mutex.
263 original_sync_level =
264 obj_desc->method.mutex->mutex.sync_level;
265 }
266 }
267
268 /* Always increase acquisition depth */
269
270 obj_desc->method.mutex->mutex.acquisition_depth++;
181 } 271 }
182 272
183 /* 273 /*
@@ -200,10 +290,10 @@ acpi_ds_begin_method_execution(struct acpi_namespace_node * method_node,
200 return_ACPI_STATUS(status); 290 return_ACPI_STATUS(status);
201 291
202 cleanup: 292 cleanup:
203 /* On error, must signal the method semaphore if present */ 293 /* On error, must release the method mutex (if present) */
204 294
205 if (obj_desc->method.semaphore) { 295 if (obj_desc->method.mutex) {
206 (void)acpi_os_signal_semaphore(obj_desc->method.semaphore, 1); 296 acpi_os_release_mutex(obj_desc->method.mutex->mutex.os_mutex);
207 } 297 }
208 return_ACPI_STATUS(status); 298 return_ACPI_STATUS(status);
209} 299}
@@ -253,10 +343,10 @@ acpi_ds_call_control_method(struct acpi_thread_state *thread,
253 return_ACPI_STATUS(AE_NULL_OBJECT); 343 return_ACPI_STATUS(AE_NULL_OBJECT);
254 } 344 }
255 345
256 /* Init for new method, possibly wait on concurrency semaphore */ 346 /* Init for new method, possibly wait on method mutex */
257 347
258 status = acpi_ds_begin_method_execution(method_node, obj_desc, 348 status = acpi_ds_begin_method_execution(method_node, obj_desc,
259 this_walk_state->method_node); 349 this_walk_state);
260 if (ACPI_FAILURE(status)) { 350 if (ACPI_FAILURE(status)) {
261 return_ACPI_STATUS(status); 351 return_ACPI_STATUS(status);
262 } 352 }
@@ -403,7 +493,7 @@ acpi_ds_restart_control_method(struct acpi_walk_state *walk_state,
403 493
404 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, 494 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
405 "****Restart [%4.4s] Op %p ReturnValueFromCallee %p\n", 495 "****Restart [%4.4s] Op %p ReturnValueFromCallee %p\n",
406 (char *)&walk_state->method_node->name, 496 acpi_ut_get_node_name(walk_state->method_node),
407 walk_state->method_call_op, return_desc)); 497 walk_state->method_call_op, return_desc));
408 498
409 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, 499 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
@@ -478,6 +568,8 @@ acpi_ds_restart_control_method(struct acpi_walk_state *walk_state,
478 * created, delete all locals and arguments, and delete the parse 568 * created, delete all locals and arguments, and delete the parse
479 * tree if requested. 569 * tree if requested.
480 * 570 *
571 * MUTEX: Interpreter is locked
572 *
481 ******************************************************************************/ 573 ******************************************************************************/
482 574
483void 575void
@@ -503,26 +595,22 @@ acpi_ds_terminate_control_method(union acpi_operand_object *method_desc,
503 } 595 }
504 596
505 /* 597 /*
506 * Lock the parser while we terminate this method. 598 * If method is serialized, release the mutex and restore the
507 * If this is the last thread executing the method, 599 * current sync level for this thread
508 * we have additional cleanup to perform
509 */ 600 */
510 status = acpi_ut_acquire_mutex(ACPI_MTX_CONTROL_METHOD); 601 if (method_desc->method.mutex) {
511 if (ACPI_FAILURE(status)) {
512 return_VOID;
513 }
514
515 /* Signal completion of the execution of this method if necessary */
516 602
517 if (method_desc->method.semaphore) { 603 /* Acquisition Depth handles recursive calls */
518 status =
519 acpi_os_signal_semaphore(method_desc->method.semaphore, 1);
520 if (ACPI_FAILURE(status)) {
521 604
522 /* Ignore error and continue */ 605 method_desc->method.mutex->mutex.acquisition_depth--;
606 if (!method_desc->method.mutex->mutex.acquisition_depth) {
607 walk_state->thread->current_sync_level =
608 method_desc->method.mutex->mutex.
609 original_sync_level;
523 610
524 ACPI_EXCEPTION((AE_INFO, status, 611 acpi_os_release_mutex(method_desc->method.mutex->mutex.
525 "Could not signal method semaphore")); 612 os_mutex);
613 method_desc->method.mutex->mutex.owner_thread = NULL;
526 } 614 }
527 } 615 }
528 616
@@ -533,27 +621,11 @@ acpi_ds_terminate_control_method(union acpi_operand_object *method_desc,
533 */ 621 */
534 method_node = walk_state->method_node; 622 method_node = walk_state->method_node;
535 623
536 /* Lock namespace for possible update */
537
538 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
539 if (ACPI_FAILURE(status)) {
540 goto exit;
541 }
542
543 /*
544 * Delete any namespace entries created immediately underneath
545 * the method
546 */
547 if (method_node && method_node->child) {
548 acpi_ns_delete_namespace_subtree(method_node);
549 }
550
551 /* 624 /*
552 * Delete any namespace entries created anywhere else within 625 * Delete any namespace objects created anywhere within
553 * the namespace by the execution of this method 626 * the namespace by the execution of this method
554 */ 627 */
555 acpi_ns_delete_namespace_by_owner(method_desc->method.owner_id); 628 acpi_ns_delete_namespace_by_owner(method_desc->method.owner_id);
556 status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
557 } 629 }
558 630
559 /* Decrement the thread count on the method */ 631 /* Decrement the thread count on the method */
@@ -580,18 +652,16 @@ acpi_ds_terminate_control_method(union acpi_operand_object *method_desc,
580 /* 652 /*
581 * Support to dynamically change a method from not_serialized to 653 * Support to dynamically change a method from not_serialized to
582 * Serialized if it appears that the method is incorrectly written and 654 * Serialized if it appears that the method is incorrectly written and
583 * does not support multiple thread execution. The best example of this 655 * does not support multiple thread execution. The best example of this
584 * is if such a method creates namespace objects and blocks. A second 656 * is if such a method creates namespace objects and blocks. A second
585 * thread will fail with an AE_ALREADY_EXISTS exception 657 * thread will fail with an AE_ALREADY_EXISTS exception
586 * 658 *
587 * This code is here because we must wait until the last thread exits 659 * This code is here because we must wait until the last thread exits
588 * before creating the synchronization semaphore. 660 * before creating the synchronization semaphore.
589 */ 661 */
590 if ((method_desc->method.concurrency == 1) && 662 if ((method_desc->method.method_flags & AML_METHOD_SERIALIZED)
591 (!method_desc->method.semaphore)) { 663 && (!method_desc->method.mutex)) {
592 status = acpi_os_create_semaphore(1, 1, 664 status = acpi_ds_create_method_mutex(method_desc);
593 &method_desc->method.
594 semaphore);
595 } 665 }
596 666
597 /* No more threads, we can free the owner_id */ 667 /* No more threads, we can free the owner_id */
@@ -599,144 +669,5 @@ acpi_ds_terminate_control_method(union acpi_operand_object *method_desc,
599 acpi_ut_release_owner_id(&method_desc->method.owner_id); 669 acpi_ut_release_owner_id(&method_desc->method.owner_id);
600 } 670 }
601 671
602 exit:
603 (void)acpi_ut_release_mutex(ACPI_MTX_CONTROL_METHOD);
604 return_VOID; 672 return_VOID;
605} 673}
606
607#ifdef ACPI_INIT_PARSE_METHODS
608 /*
609 * Note 11/2005: Removed this code to parse all methods during table
610 * load because it causes problems if there are any errors during the
611 * parse. Also, it seems like overkill and we probably don't want to
612 * abort a table load because of an issue with a single method.
613 */
614
615/*******************************************************************************
616 *
617 * FUNCTION: acpi_ds_parse_method
618 *
619 * PARAMETERS: Node - Method node
620 *
621 * RETURN: Status
622 *
623 * DESCRIPTION: Parse the AML that is associated with the method.
624 *
625 * MUTEX: Assumes parser is locked
626 *
627 ******************************************************************************/
628
629acpi_status acpi_ds_parse_method(struct acpi_namespace_node *node)
630{
631 acpi_status status;
632 union acpi_operand_object *obj_desc;
633 union acpi_parse_object *op;
634 struct acpi_walk_state *walk_state;
635
636 ACPI_FUNCTION_TRACE_PTR(ds_parse_method, node);
637
638 /* Parameter Validation */
639
640 if (!node) {
641 return_ACPI_STATUS(AE_NULL_ENTRY);
642 }
643
644 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
645 "**** Parsing [%4.4s] **** NamedObj=%p\n",
646 acpi_ut_get_node_name(node), node));
647
648 /* Extract the method object from the method Node */
649
650 obj_desc = acpi_ns_get_attached_object(node);
651 if (!obj_desc) {
652 return_ACPI_STATUS(AE_NULL_OBJECT);
653 }
654
655 /* Create a mutex for the method if there is a concurrency limit */
656
657 if ((obj_desc->method.concurrency != ACPI_INFINITE_CONCURRENCY) &&
658 (!obj_desc->method.semaphore)) {
659 status = acpi_os_create_semaphore(obj_desc->method.concurrency,
660 obj_desc->method.concurrency,
661 &obj_desc->method.semaphore);
662 if (ACPI_FAILURE(status)) {
663 return_ACPI_STATUS(status);
664 }
665 }
666
667 /*
668 * Allocate a new parser op to be the root of the parsed
669 * method tree
670 */
671 op = acpi_ps_alloc_op(AML_METHOD_OP);
672 if (!op) {
673 return_ACPI_STATUS(AE_NO_MEMORY);
674 }
675
676 /* Init new op with the method name and pointer back to the Node */
677
678 acpi_ps_set_name(op, node->name.integer);
679 op->common.node = node;
680
681 /*
682 * Get a new owner_id for objects created by this method. Namespace
683 * objects (such as Operation Regions) can be created during the
684 * first pass parse.
685 */
686 status = acpi_ut_allocate_owner_id(&obj_desc->method.owner_id);
687 if (ACPI_FAILURE(status)) {
688 goto cleanup;
689 }
690
691 /* Create and initialize a new walk state */
692
693 walk_state =
694 acpi_ds_create_walk_state(obj_desc->method.owner_id, NULL, NULL,
695 NULL);
696 if (!walk_state) {
697 status = AE_NO_MEMORY;
698 goto cleanup2;
699 }
700
701 status = acpi_ds_init_aml_walk(walk_state, op, node,
702 obj_desc->method.aml_start,
703 obj_desc->method.aml_length, NULL, 1);
704 if (ACPI_FAILURE(status)) {
705 acpi_ds_delete_walk_state(walk_state);
706 goto cleanup2;
707 }
708
709 /*
710 * Parse the method, first pass
711 *
712 * The first pass load is where newly declared named objects are added into
713 * the namespace. Actual evaluation of the named objects (what would be
714 * called a "second pass") happens during the actual execution of the
715 * method so that operands to the named objects can take on dynamic
716 * run-time values.
717 */
718 status = acpi_ps_parse_aml(walk_state);
719 if (ACPI_FAILURE(status)) {
720 goto cleanup2;
721 }
722
723 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
724 "**** [%4.4s] Parsed **** NamedObj=%p Op=%p\n",
725 acpi_ut_get_node_name(node), node, op));
726
727 /*
728 * Delete the parse tree. We simply re-parse the method for every
729 * execution since there isn't much overhead (compared to keeping lots
730 * of parse trees around)
731 */
732 acpi_ns_delete_namespace_subtree(node);
733 acpi_ns_delete_namespace_by_owner(obj_desc->method.owner_id);
734
735 cleanup2:
736 acpi_ut_release_owner_id(&obj_desc->method.owner_id);
737
738 cleanup:
739 acpi_ps_delete_parse_tree(op);
740 return_ACPI_STATUS(status);
741}
742#endif
diff --git a/drivers/acpi/dispatcher/dswexec.c b/drivers/acpi/dispatcher/dswexec.c
index 3acbd9145d72..d7a616c3104e 100644
--- a/drivers/acpi/dispatcher/dswexec.c
+++ b/drivers/acpi/dispatcher/dswexec.c
@@ -313,10 +313,10 @@ acpi_ds_exec_begin_op(struct acpi_walk_state *walk_state,
313 case AML_CLASS_EXECUTE: 313 case AML_CLASS_EXECUTE:
314 case AML_CLASS_CREATE: 314 case AML_CLASS_CREATE:
315 /* 315 /*
316 * Most operators with arguments. 316 * Most operators with arguments (except create_xxx_field operators)
317 * Start a new result/operand state 317 * Start a new result/operand state
318 */ 318 */
319 if (walk_state->opcode != AML_CREATE_FIELD_OP) { 319 if (walk_state->op_info->object_type != ACPI_TYPE_BUFFER_FIELD) {
320 status = acpi_ds_result_stack_push(walk_state); 320 status = acpi_ds_result_stack_push(walk_state);
321 } 321 }
322 break; 322 break;
@@ -472,7 +472,6 @@ acpi_status acpi_ds_exec_end_op(struct acpi_walk_state *walk_state)
472 acpi_ds_result_push(walk_state->result_obj, 472 acpi_ds_result_push(walk_state->result_obj,
473 walk_state); 473 walk_state);
474 } 474 }
475
476 break; 475 break;
477 476
478 default: 477 default:
@@ -510,6 +509,7 @@ acpi_status acpi_ds_exec_end_op(struct acpi_walk_state *walk_state)
510 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, 509 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
511 "Method Reference in a Package, Op=%p\n", 510 "Method Reference in a Package, Op=%p\n",
512 op)); 511 op));
512
513 op->common.node = 513 op->common.node =
514 (struct acpi_namespace_node *)op->asl.value. 514 (struct acpi_namespace_node *)op->asl.value.
515 arg->asl.node->object; 515 arg->asl.node->object;
@@ -670,7 +670,6 @@ acpi_status acpi_ds_exec_end_op(struct acpi_walk_state *walk_state)
670 670
671 status = acpi_ds_result_stack_pop(walk_state); 671 status = acpi_ds_result_stack_pop(walk_state);
672 } 672 }
673
674 break; 673 break;
675 674
676 case AML_TYPE_UNDEFINED: 675 case AML_TYPE_UNDEFINED:
@@ -708,7 +707,6 @@ acpi_status acpi_ds_exec_end_op(struct acpi_walk_state *walk_state)
708 * Check if we just completed the evaluation of a 707 * Check if we just completed the evaluation of a
709 * conditional predicate 708 * conditional predicate
710 */ 709 */
711
712 if ((ACPI_SUCCESS(status)) && 710 if ((ACPI_SUCCESS(status)) &&
713 (walk_state->control_state) && 711 (walk_state->control_state) &&
714 (walk_state->control_state->common.state == 712 (walk_state->control_state->common.state ==
diff --git a/drivers/acpi/dispatcher/dswload.c b/drivers/acpi/dispatcher/dswload.c
index 35074399c617..e3ca7f6539c1 100644
--- a/drivers/acpi/dispatcher/dswload.c
+++ b/drivers/acpi/dispatcher/dswload.c
@@ -175,7 +175,7 @@ acpi_ds_load1_begin_op(struct acpi_walk_state * walk_state,
175 if (status == AE_NOT_FOUND) { 175 if (status == AE_NOT_FOUND) {
176 /* 176 /*
177 * Table disassembly: 177 * Table disassembly:
178 * Target of Scope() not found. Generate an External for it, and 178 * Target of Scope() not found. Generate an External for it, and
179 * insert the name into the namespace. 179 * insert the name into the namespace.
180 */ 180 */
181 acpi_dm_add_to_external_list(path, ACPI_TYPE_DEVICE, 0); 181 acpi_dm_add_to_external_list(path, ACPI_TYPE_DEVICE, 0);
@@ -210,16 +210,15 @@ acpi_ds_load1_begin_op(struct acpi_walk_state * walk_state,
210 case ACPI_TYPE_BUFFER: 210 case ACPI_TYPE_BUFFER:
211 211
212 /* 212 /*
213 * These types we will allow, but we will change the type. This 213 * These types we will allow, but we will change the type. This
214 * enables some existing code of the form: 214 * enables some existing code of the form:
215 * 215 *
216 * Name (DEB, 0) 216 * Name (DEB, 0)
217 * Scope (DEB) { ... } 217 * Scope (DEB) { ... }
218 * 218 *
219 * Note: silently change the type here. On the second pass, we will report 219 * Note: silently change the type here. On the second pass, we will report
220 * a warning 220 * a warning
221 */ 221 */
222
223 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 222 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
224 "Type override - [%4.4s] had invalid type (%s) for Scope operator, changed to (Scope)\n", 223 "Type override - [%4.4s] had invalid type (%s) for Scope operator, changed to (Scope)\n",
225 path, 224 path,
@@ -242,7 +241,6 @@ acpi_ds_load1_begin_op(struct acpi_walk_state * walk_state,
242 break; 241 break;
243 242
244 default: 243 default:
245
246 /* 244 /*
247 * For all other named opcodes, we will enter the name into 245 * For all other named opcodes, we will enter the name into
248 * the namespace. 246 * the namespace.
@@ -259,7 +257,6 @@ acpi_ds_load1_begin_op(struct acpi_walk_state * walk_state,
259 * buffer_field, or Package), the name of the object is already 257 * buffer_field, or Package), the name of the object is already
260 * in the namespace. 258 * in the namespace.
261 */ 259 */
262
263 if (walk_state->deferred_node) { 260 if (walk_state->deferred_node) {
264 261
265 /* This name is already in the namespace, get the node */ 262 /* This name is already in the namespace, get the node */
@@ -293,8 +290,8 @@ acpi_ds_load1_begin_op(struct acpi_walk_state * walk_state,
293 } 290 }
294 291
295 /* 292 /*
296 * Enter the named type into the internal namespace. We enter the name 293 * Enter the named type into the internal namespace. We enter the name
297 * as we go downward in the parse tree. Any necessary subobjects that 294 * as we go downward in the parse tree. Any necessary subobjects that
298 * involve arguments to the opcode must be created as we go back up the 295 * involve arguments to the opcode must be created as we go back up the
299 * parse tree later. 296 * parse tree later.
300 */ 297 */
@@ -327,12 +324,12 @@ acpi_ds_load1_begin_op(struct acpi_walk_state * walk_state,
327 (status); 324 (status);
328 } 325 }
329 } 326 }
327
330 status = AE_OK; 328 status = AE_OK;
331 } 329 }
332 } 330 }
333 331
334 if (ACPI_FAILURE(status)) { 332 if (ACPI_FAILURE(status)) {
335
336 ACPI_ERROR_NAMESPACE(path, status); 333 ACPI_ERROR_NAMESPACE(path, status);
337 return_ACPI_STATUS(status); 334 return_ACPI_STATUS(status);
338 } 335 }
@@ -434,9 +431,13 @@ acpi_status acpi_ds_load1_end_op(struct acpi_walk_state *walk_state)
434 status = 431 status =
435 acpi_ex_create_region(op->named.data, 432 acpi_ex_create_region(op->named.data,
436 op->named.length, 433 op->named.length,
437 (acpi_adr_space_type) 434 (acpi_adr_space_type) ((op->
438 ((op->common.value.arg)-> 435 common.
439 common.value.integer), 436 value.
437 arg)->
438 common.
439 value.
440 integer),
440 walk_state); 441 walk_state);
441 if (ACPI_FAILURE(status)) { 442 if (ACPI_FAILURE(status)) {
442 return_ACPI_STATUS(status); 443 return_ACPI_STATUS(status);
@@ -474,7 +475,7 @@ acpi_status acpi_ds_load1_end_op(struct acpi_walk_state *walk_state)
474 * method_op pkg_length name_string method_flags term_list 475 * method_op pkg_length name_string method_flags term_list
475 * 476 *
476 * Note: We must create the method node/object pair as soon as we 477 * Note: We must create the method node/object pair as soon as we
477 * see the method declaration. This allows later pass1 parsing 478 * see the method declaration. This allows later pass1 parsing
478 * of invocations of the method (need to know the number of 479 * of invocations of the method (need to know the number of
479 * arguments.) 480 * arguments.)
480 */ 481 */
@@ -499,6 +500,7 @@ acpi_status acpi_ds_load1_end_op(struct acpi_walk_state *walk_state)
499 length, 500 length,
500 walk_state); 501 walk_state);
501 } 502 }
503
502 walk_state->operands[0] = NULL; 504 walk_state->operands[0] = NULL;
503 walk_state->num_operands = 0; 505 walk_state->num_operands = 0;
504 506
@@ -570,7 +572,6 @@ acpi_ds_load2_begin_op(struct acpi_walk_state *walk_state,
570#ifdef ACPI_ENABLE_MODULE_LEVEL_CODE 572#ifdef ACPI_ENABLE_MODULE_LEVEL_CODE
571 if ((walk_state->op_info->class == AML_CLASS_EXECUTE) || 573 if ((walk_state->op_info->class == AML_CLASS_EXECUTE) ||
572 (walk_state->op_info->class == AML_CLASS_CONTROL)) { 574 (walk_state->op_info->class == AML_CLASS_CONTROL)) {
573
574 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, 575 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
575 "Begin/EXEC: %s (fl %8.8X)\n", 576 "Begin/EXEC: %s (fl %8.8X)\n",
576 walk_state->op_info->name, 577 walk_state->op_info->name,
@@ -602,7 +603,7 @@ acpi_ds_load2_begin_op(struct acpi_walk_state *walk_state,
602 } else { 603 } else {
603 /* Get name from the op */ 604 /* Get name from the op */
604 605
605 buffer_ptr = (char *)&op->named.name; 606 buffer_ptr = ACPI_CAST_PTR(char, &op->named.name);
606 } 607 }
607 } else { 608 } else {
608 /* Get the namestring from the raw AML */ 609 /* Get the namestring from the raw AML */
@@ -629,7 +630,6 @@ acpi_ds_load2_begin_op(struct acpi_walk_state *walk_state,
629 break; 630 break;
630 631
631 case AML_INT_NAMEPATH_OP: 632 case AML_INT_NAMEPATH_OP:
632
633 /* 633 /*
634 * The name_path is an object reference to an existing object. 634 * The name_path is an object reference to an existing object.
635 * Don't enter the name into the namespace, but look it up 635 * Don't enter the name into the namespace, but look it up
@@ -642,7 +642,6 @@ acpi_ds_load2_begin_op(struct acpi_walk_state *walk_state,
642 break; 642 break;
643 643
644 case AML_SCOPE_OP: 644 case AML_SCOPE_OP:
645
646 /* 645 /*
647 * The Path is an object reference to an existing object. 646 * The Path is an object reference to an existing object.
648 * Don't enter the name into the namespace, but look it up 647 * Don't enter the name into the namespace, but look it up
@@ -664,6 +663,7 @@ acpi_ds_load2_begin_op(struct acpi_walk_state *walk_state,
664#endif 663#endif
665 return_ACPI_STATUS(status); 664 return_ACPI_STATUS(status);
666 } 665 }
666
667 /* 667 /*
668 * We must check to make sure that the target is 668 * We must check to make sure that the target is
669 * one of the opcodes that actually opens a scope 669 * one of the opcodes that actually opens a scope
@@ -683,13 +683,12 @@ acpi_ds_load2_begin_op(struct acpi_walk_state *walk_state,
683 case ACPI_TYPE_BUFFER: 683 case ACPI_TYPE_BUFFER:
684 684
685 /* 685 /*
686 * These types we will allow, but we will change the type. This 686 * These types we will allow, but we will change the type. This
687 * enables some existing code of the form: 687 * enables some existing code of the form:
688 * 688 *
689 * Name (DEB, 0) 689 * Name (DEB, 0)
690 * Scope (DEB) { ... } 690 * Scope (DEB) { ... }
691 */ 691 */
692
693 ACPI_WARNING((AE_INFO, 692 ACPI_WARNING((AE_INFO,
694 "Type override - [%4.4s] had invalid type (%s) for Scope operator, changed to (Scope)", 693 "Type override - [%4.4s] had invalid type (%s) for Scope operator, changed to (Scope)",
695 buffer_ptr, 694 buffer_ptr,
@@ -729,14 +728,14 @@ acpi_ds_load2_begin_op(struct acpi_walk_state *walk_state,
729 if (ACPI_FAILURE(status)) { 728 if (ACPI_FAILURE(status)) {
730 return_ACPI_STATUS(status); 729 return_ACPI_STATUS(status);
731 } 730 }
732
733 } 731 }
732
734 return_ACPI_STATUS(AE_OK); 733 return_ACPI_STATUS(AE_OK);
735 } 734 }
736 735
737 /* 736 /*
738 * Enter the named type into the internal namespace. We enter the name 737 * Enter the named type into the internal namespace. We enter the name
739 * as we go downward in the parse tree. Any necessary subobjects that 738 * as we go downward in the parse tree. Any necessary subobjects that
740 * involve arguments to the opcode must be created as we go back up the 739 * involve arguments to the opcode must be created as we go back up the
741 * parse tree later. 740 * parse tree later.
742 * 741 *
@@ -787,7 +786,6 @@ acpi_ds_load2_begin_op(struct acpi_walk_state *walk_state,
787 * can get it again quickly when this scope is closed 786 * can get it again quickly when this scope is closed
788 */ 787 */
789 op->common.node = node; 788 op->common.node = node;
790
791 return_ACPI_STATUS(status); 789 return_ACPI_STATUS(status);
792} 790}
793 791
@@ -922,7 +920,6 @@ acpi_status acpi_ds_load2_end_op(struct acpi_walk_state *walk_state)
922#ifndef ACPI_NO_METHOD_EXECUTION 920#ifndef ACPI_NO_METHOD_EXECUTION
923 921
924 case AML_TYPE_CREATE_FIELD: 922 case AML_TYPE_CREATE_FIELD:
925
926 /* 923 /*
927 * Create the field object, but the field buffer and index must 924 * Create the field object, but the field buffer and index must
928 * be evaluated later during the execution phase 925 * be evaluated later during the execution phase
@@ -931,7 +928,6 @@ acpi_status acpi_ds_load2_end_op(struct acpi_walk_state *walk_state)
931 break; 928 break;
932 929
933 case AML_TYPE_NAMED_FIELD: 930 case AML_TYPE_NAMED_FIELD:
934
935 /* 931 /*
936 * If we are executing a method, initialize the field 932 * If we are executing a method, initialize the field
937 */ 933 */
@@ -1051,6 +1047,7 @@ acpi_status acpi_ds_load2_end_op(struct acpi_walk_state *walk_state)
1051 * argument is the space_id. (We must save the address of the 1047 * argument is the space_id. (We must save the address of the
1052 * AML of the address and length operands) 1048 * AML of the address and length operands)
1053 */ 1049 */
1050
1054 /* 1051 /*
1055 * If we have a valid region, initialize it 1052 * If we have a valid region, initialize it
1056 * Namespace is NOT locked at this point. 1053 * Namespace is NOT locked at this point.
@@ -1080,7 +1077,7 @@ acpi_status acpi_ds_load2_end_op(struct acpi_walk_state *walk_state)
1080 * method_op pkg_length name_string method_flags term_list 1077 * method_op pkg_length name_string method_flags term_list
1081 * 1078 *
1082 * Note: We must create the method node/object pair as soon as we 1079 * Note: We must create the method node/object pair as soon as we
1083 * see the method declaration. This allows later pass1 parsing 1080 * see the method declaration. This allows later pass1 parsing
1084 * of invocations of the method (need to know the number of 1081 * of invocations of the method (need to know the number of
1085 * arguments.) 1082 * arguments.)
1086 */ 1083 */
diff --git a/drivers/acpi/dock.c b/drivers/acpi/dock.c
new file mode 100644
index 000000000000..578b99b71d9c
--- /dev/null
+++ b/drivers/acpi/dock.c
@@ -0,0 +1,739 @@
1/*
2 * dock.c - ACPI dock station driver
3 *
4 * Copyright (C) 2006 Kristen Carlson Accardi <kristen.c.accardi@intel.com>
5 *
6 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or (at
11 * your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 *
22 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
23 */
24
25#include <linux/kernel.h>
26#include <linux/module.h>
27#include <linux/init.h>
28#include <linux/types.h>
29#include <linux/notifier.h>
30#include <acpi/acpi_bus.h>
31#include <acpi/acpi_drivers.h>
32
33#define ACPI_DOCK_DRIVER_NAME "ACPI Dock Station Driver"
34
35ACPI_MODULE_NAME("dock")
36MODULE_AUTHOR("Kristen Carlson Accardi");
37MODULE_DESCRIPTION(ACPI_DOCK_DRIVER_NAME);
38MODULE_LICENSE("GPL");
39
40static struct atomic_notifier_head dock_notifier_list;
41
42struct dock_station {
43 acpi_handle handle;
44 unsigned long last_dock_time;
45 u32 flags;
46 spinlock_t dd_lock;
47 spinlock_t hp_lock;
48 struct list_head dependent_devices;
49 struct list_head hotplug_devices;
50};
51
52struct dock_dependent_device {
53 struct list_head list;
54 struct list_head hotplug_list;
55 acpi_handle handle;
56 acpi_notify_handler handler;
57 void *context;
58};
59
60#define DOCK_DOCKING 0x00000001
61#define DOCK_EVENT 3
62#define UNDOCK_EVENT 2
63
64static struct dock_station *dock_station;
65
66/*****************************************************************************
67 * Dock Dependent device functions *
68 *****************************************************************************/
69/**
70 * alloc_dock_dependent_device - allocate and init a dependent device
71 * @handle: the acpi_handle of the dependent device
72 *
73 * Allocate memory for a dependent device structure for a device referenced
74 * by the acpi handle
75 */
76static struct dock_dependent_device *
77alloc_dock_dependent_device(acpi_handle handle)
78{
79 struct dock_dependent_device *dd;
80
81 dd = kzalloc(sizeof(*dd), GFP_KERNEL);
82 if (dd) {
83 dd->handle = handle;
84 INIT_LIST_HEAD(&dd->list);
85 INIT_LIST_HEAD(&dd->hotplug_list);
86 }
87 return dd;
88}
89
90/**
91 * add_dock_dependent_device - associate a device with the dock station
92 * @ds: The dock station
93 * @dd: The dependent device
94 *
95 * Add the dependent device to the dock's dependent device list.
96 */
97static void
98add_dock_dependent_device(struct dock_station *ds,
99 struct dock_dependent_device *dd)
100{
101 spin_lock(&ds->dd_lock);
102 list_add_tail(&dd->list, &ds->dependent_devices);
103 spin_unlock(&ds->dd_lock);
104}
105
106/**
107 * dock_add_hotplug_device - associate a hotplug handler with the dock station
108 * @ds: The dock station
109 * @dd: The dependent device struct
110 *
111 * Add the dependent device to the dock's hotplug device list
112 */
113static void
114dock_add_hotplug_device(struct dock_station *ds,
115 struct dock_dependent_device *dd)
116{
117 spin_lock(&ds->hp_lock);
118 list_add_tail(&dd->hotplug_list, &ds->hotplug_devices);
119 spin_unlock(&ds->hp_lock);
120}
121
122/**
123 * dock_del_hotplug_device - remove a hotplug handler from the dock station
124 * @ds: The dock station
125 * @dd: the dependent device struct
126 *
127 * Delete the dependent device from the dock's hotplug device list
128 */
129static void
130dock_del_hotplug_device(struct dock_station *ds,
131 struct dock_dependent_device *dd)
132{
133 spin_lock(&ds->hp_lock);
134 list_del(&dd->hotplug_list);
135 spin_unlock(&ds->hp_lock);
136}
137
138/**
139 * find_dock_dependent_device - get a device dependent on this dock
140 * @ds: the dock station
141 * @handle: the acpi_handle of the device we want
142 *
143 * iterate over the dependent device list for this dock. If the
144 * dependent device matches the handle, return.
145 */
146static struct dock_dependent_device *
147find_dock_dependent_device(struct dock_station *ds, acpi_handle handle)
148{
149 struct dock_dependent_device *dd;
150
151 spin_lock(&ds->dd_lock);
152 list_for_each_entry(dd, &ds->dependent_devices, list) {
153 if (handle == dd->handle) {
154 spin_unlock(&ds->dd_lock);
155 return dd;
156 }
157 }
158 spin_unlock(&ds->dd_lock);
159 return NULL;
160}
161
162/*****************************************************************************
163 * Dock functions *
164 *****************************************************************************/
165/**
166 * is_dock - see if a device is a dock station
167 * @handle: acpi handle of the device
168 *
169 * If an acpi object has a _DCK method, then it is by definition a dock
170 * station, so return true.
171 */
172static int is_dock(acpi_handle handle)
173{
174 acpi_status status;
175 acpi_handle tmp;
176
177 status = acpi_get_handle(handle, "_DCK", &tmp);
178 if (ACPI_FAILURE(status))
179 return 0;
180 return 1;
181}
182
183/**
184 * is_dock_device - see if a device is on a dock station
185 * @handle: acpi handle of the device
186 *
187 * If this device is either the dock station itself,
188 * or is a device dependent on the dock station, then it
189 * is a dock device
190 */
191int is_dock_device(acpi_handle handle)
192{
193 if (!dock_station)
194 return 0;
195
196 if (is_dock(handle) || find_dock_dependent_device(dock_station, handle))
197 return 1;
198
199 return 0;
200}
201
202EXPORT_SYMBOL_GPL(is_dock_device);
203
204/**
205 * dock_present - see if the dock station is present.
206 * @ds: the dock station
207 *
208 * execute the _STA method. note that present does not
209 * imply that we are docked.
210 */
211static int dock_present(struct dock_station *ds)
212{
213 unsigned long sta;
214 acpi_status status;
215
216 if (ds) {
217 status = acpi_evaluate_integer(ds->handle, "_STA", NULL, &sta);
218 if (ACPI_SUCCESS(status) && sta)
219 return 1;
220 }
221 return 0;
222}
223
224
225
226/**
227 * dock_create_acpi_device - add new devices to acpi
228 * @handle - handle of the device to add
229 *
230 * This function will create a new acpi_device for the given
231 * handle if one does not exist already. This should cause
232 * acpi to scan for drivers for the given devices, and call
233 * matching driver's add routine.
234 *
235 * Returns a pointer to the acpi_device corresponding to the handle.
236 */
237static struct acpi_device * dock_create_acpi_device(acpi_handle handle)
238{
239 struct acpi_device *device = NULL;
240 struct acpi_device *parent_device;
241 acpi_handle parent;
242 int ret;
243
244 if (acpi_bus_get_device(handle, &device)) {
245 /*
246 * no device created for this object,
247 * so we should create one.
248 */
249 acpi_get_parent(handle, &parent);
250 if (acpi_bus_get_device(parent, &parent_device))
251 parent_device = NULL;
252
253 ret = acpi_bus_add(&device, parent_device, handle,
254 ACPI_BUS_TYPE_DEVICE);
255 if (ret) {
256 pr_debug("error adding bus, %x\n",
257 -ret);
258 return NULL;
259 }
260 }
261 return device;
262}
263
264/**
265 * dock_remove_acpi_device - remove the acpi_device struct from acpi
266 * @handle - the handle of the device to remove
267 *
268 * Tell acpi to remove the acpi_device. This should cause any loaded
269 * driver to have it's remove routine called.
270 */
271static void dock_remove_acpi_device(acpi_handle handle)
272{
273 struct acpi_device *device;
274 int ret;
275
276 if (!acpi_bus_get_device(handle, &device)) {
277 ret = acpi_bus_trim(device, 1);
278 if (ret)
279 pr_debug("error removing bus, %x\n", -ret);
280 }
281}
282
283
284/**
285 * hotplug_dock_devices - insert or remove devices on the dock station
286 * @ds: the dock station
287 * @event: either bus check or eject request
288 *
289 * Some devices on the dock station need to have drivers called
290 * to perform hotplug operations after a dock event has occurred.
291 * Traverse the list of dock devices that have registered a
292 * hotplug handler, and call the handler.
293 */
294static void hotplug_dock_devices(struct dock_station *ds, u32 event)
295{
296 struct dock_dependent_device *dd;
297
298 spin_lock(&ds->hp_lock);
299
300 /*
301 * First call driver specific hotplug functions
302 */
303 list_for_each_entry(dd, &ds->hotplug_devices, hotplug_list) {
304 if (dd->handler)
305 dd->handler(dd->handle, event, dd->context);
306 }
307
308 /*
309 * Now make sure that an acpi_device is created for each
310 * dependent device, or removed if this is an eject request.
311 * This will cause acpi_drivers to be stopped/started if they
312 * exist
313 */
314 list_for_each_entry(dd, &ds->dependent_devices, list) {
315 if (event == ACPI_NOTIFY_EJECT_REQUEST)
316 dock_remove_acpi_device(dd->handle);
317 else
318 dock_create_acpi_device(dd->handle);
319 }
320 spin_unlock(&ds->hp_lock);
321}
322
323static void dock_event(struct dock_station *ds, u32 event, int num)
324{
325 /*
326 * we don't do events until someone tells me that
327 * they would like to have them.
328 */
329}
330
331/**
332 * eject_dock - respond to a dock eject request
333 * @ds: the dock station
334 *
335 * This is called after _DCK is called, to execute the dock station's
336 * _EJ0 method.
337 */
338static void eject_dock(struct dock_station *ds)
339{
340 struct acpi_object_list arg_list;
341 union acpi_object arg;
342 acpi_status status;
343 acpi_handle tmp;
344
345 /* all dock devices should have _EJ0, but check anyway */
346 status = acpi_get_handle(ds->handle, "_EJ0", &tmp);
347 if (ACPI_FAILURE(status)) {
348 pr_debug("No _EJ0 support for dock device\n");
349 return;
350 }
351
352 arg_list.count = 1;
353 arg_list.pointer = &arg;
354 arg.type = ACPI_TYPE_INTEGER;
355 arg.integer.value = 1;
356
357 if (ACPI_FAILURE(acpi_evaluate_object(ds->handle, "_EJ0",
358 &arg_list, NULL)))
359 pr_debug("Failed to evaluate _EJ0!\n");
360}
361
362/**
363 * handle_dock - handle a dock event
364 * @ds: the dock station
365 * @dock: to dock, or undock - that is the question
366 *
367 * Execute the _DCK method in response to an acpi event
368 */
369static void handle_dock(struct dock_station *ds, int dock)
370{
371 acpi_status status;
372 struct acpi_object_list arg_list;
373 union acpi_object arg;
374 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
375 struct acpi_buffer name_buffer = { ACPI_ALLOCATE_BUFFER, NULL };
376 union acpi_object *obj;
377
378 acpi_get_name(ds->handle, ACPI_FULL_PATHNAME, &name_buffer);
379 obj = name_buffer.pointer;
380
381 printk(KERN_INFO PREFIX "%s\n", dock ? "docking" : "undocking");
382
383 /* _DCK method has one argument */
384 arg_list.count = 1;
385 arg_list.pointer = &arg;
386 arg.type = ACPI_TYPE_INTEGER;
387 arg.integer.value = dock;
388 status = acpi_evaluate_object(ds->handle, "_DCK", &arg_list, &buffer);
389 if (ACPI_FAILURE(status))
390 pr_debug("%s: failed to execute _DCK\n", obj->string.pointer);
391 kfree(buffer.pointer);
392 kfree(name_buffer.pointer);
393}
394
395static inline void dock(struct dock_station *ds)
396{
397 handle_dock(ds, 1);
398}
399
400static inline void undock(struct dock_station *ds)
401{
402 handle_dock(ds, 0);
403}
404
405static inline void begin_dock(struct dock_station *ds)
406{
407 ds->flags |= DOCK_DOCKING;
408}
409
410static inline void complete_dock(struct dock_station *ds)
411{
412 ds->flags &= ~(DOCK_DOCKING);
413 ds->last_dock_time = jiffies;
414}
415
416/**
417 * dock_in_progress - see if we are in the middle of handling a dock event
418 * @ds: the dock station
419 *
420 * Sometimes while docking, false dock events can be sent to the driver
421 * because good connections aren't made or some other reason. Ignore these
422 * if we are in the middle of doing something.
423 */
424static int dock_in_progress(struct dock_station *ds)
425{
426 if ((ds->flags & DOCK_DOCKING) ||
427 time_before(jiffies, (ds->last_dock_time + HZ)))
428 return 1;
429 return 0;
430}
431
432/**
433 * register_dock_notifier - add yourself to the dock notifier list
434 * @nb: the callers notifier block
435 *
436 * If a driver wishes to be notified about dock events, they can
437 * use this function to put a notifier block on the dock notifier list.
438 * this notifier call chain will be called after a dock event, but
439 * before hotplugging any new devices.
440 */
441int register_dock_notifier(struct notifier_block *nb)
442{
443 return atomic_notifier_chain_register(&dock_notifier_list, nb);
444}
445
446EXPORT_SYMBOL_GPL(register_dock_notifier);
447
448/**
449 * unregister_dock_notifier - remove yourself from the dock notifier list
450 * @nb: the callers notifier block
451 */
452void unregister_dock_notifier(struct notifier_block *nb)
453{
454 atomic_notifier_chain_unregister(&dock_notifier_list, nb);
455}
456
457EXPORT_SYMBOL_GPL(unregister_dock_notifier);
458
459/**
460 * register_hotplug_dock_device - register a hotplug function
461 * @handle: the handle of the device
462 * @handler: the acpi_notifier_handler to call after docking
463 * @context: device specific data
464 *
465 * If a driver would like to perform a hotplug operation after a dock
466 * event, they can register an acpi_notifiy_handler to be called by
467 * the dock driver after _DCK is executed.
468 */
469int
470register_hotplug_dock_device(acpi_handle handle, acpi_notify_handler handler,
471 void *context)
472{
473 struct dock_dependent_device *dd;
474
475 if (!dock_station)
476 return -ENODEV;
477
478 /*
479 * make sure this handle is for a device dependent on the dock,
480 * this would include the dock station itself
481 */
482 dd = find_dock_dependent_device(dock_station, handle);
483 if (dd) {
484 dd->handler = handler;
485 dd->context = context;
486 dock_add_hotplug_device(dock_station, dd);
487 return 0;
488 }
489
490 return -EINVAL;
491}
492
493EXPORT_SYMBOL_GPL(register_hotplug_dock_device);
494
495/**
496 * unregister_hotplug_dock_device - remove yourself from the hotplug list
497 * @handle: the acpi handle of the device
498 */
499void unregister_hotplug_dock_device(acpi_handle handle)
500{
501 struct dock_dependent_device *dd;
502
503 if (!dock_station)
504 return;
505
506 dd = find_dock_dependent_device(dock_station, handle);
507 if (dd)
508 dock_del_hotplug_device(dock_station, dd);
509}
510
511EXPORT_SYMBOL_GPL(unregister_hotplug_dock_device);
512
513/**
514 * dock_notify - act upon an acpi dock notification
515 * @handle: the dock station handle
516 * @event: the acpi event
517 * @data: our driver data struct
518 *
519 * If we are notified to dock, then check to see if the dock is
520 * present and then dock. Notify all drivers of the dock event,
521 * and then hotplug and devices that may need hotplugging. For undock
522 * check to make sure the dock device is still present, then undock
523 * and hotremove all the devices that may need removing.
524 */
525static void dock_notify(acpi_handle handle, u32 event, void *data)
526{
527 struct dock_station *ds = (struct dock_station *)data;
528
529 switch (event) {
530 case ACPI_NOTIFY_BUS_CHECK:
531 if (!dock_in_progress(ds) && dock_present(ds)) {
532 begin_dock(ds);
533 dock(ds);
534 if (!dock_present(ds)) {
535 printk(KERN_ERR PREFIX "Unable to dock!\n");
536 break;
537 }
538 atomic_notifier_call_chain(&dock_notifier_list,
539 event, NULL);
540 hotplug_dock_devices(ds, event);
541 complete_dock(ds);
542 dock_event(ds, event, DOCK_EVENT);
543 }
544 break;
545 case ACPI_NOTIFY_DEVICE_CHECK:
546 /*
547 * According to acpi spec 3.0a, if a DEVICE_CHECK notification
548 * is sent and _DCK is present, it is assumed to mean an
549 * undock request. This notify routine will only be called
550 * for objects defining _DCK, so we will fall through to eject
551 * request here. However, we will pass an eject request through
552 * to the driver who wish to hotplug.
553 */
554 case ACPI_NOTIFY_EJECT_REQUEST:
555 if (!dock_in_progress(ds) && dock_present(ds)) {
556 /*
557 * here we need to generate the undock
558 * event prior to actually doing the undock
559 * so that the device struct still exists.
560 */
561 dock_event(ds, event, UNDOCK_EVENT);
562 hotplug_dock_devices(ds, ACPI_NOTIFY_EJECT_REQUEST);
563 undock(ds);
564 eject_dock(ds);
565 if (dock_present(ds))
566 printk(KERN_ERR PREFIX "Unable to undock!\n");
567 }
568 break;
569 default:
570 printk(KERN_ERR PREFIX "Unknown dock event %d\n", event);
571 }
572}
573
574/**
575 * find_dock_devices - find devices on the dock station
576 * @handle: the handle of the device we are examining
577 * @lvl: unused
578 * @context: the dock station private data
579 * @rv: unused
580 *
581 * This function is called by acpi_walk_namespace. It will
582 * check to see if an object has an _EJD method. If it does, then it
583 * will see if it is dependent on the dock station.
584 */
585static acpi_status
586find_dock_devices(acpi_handle handle, u32 lvl, void *context, void **rv)
587{
588 acpi_status status;
589 acpi_handle tmp;
590 struct dock_station *ds = (struct dock_station *)context;
591 struct dock_dependent_device *dd;
592
593 status = acpi_bus_get_ejd(handle, &tmp);
594 if (ACPI_FAILURE(status))
595 return AE_OK;
596
597 if (tmp == ds->handle) {
598 dd = alloc_dock_dependent_device(handle);
599 if (dd)
600 add_dock_dependent_device(ds, dd);
601 }
602
603 return AE_OK;
604}
605
606/**
607 * dock_add - add a new dock station
608 * @handle: the dock station handle
609 *
610 * allocated and initialize a new dock station device. Find all devices
611 * that are on the dock station, and register for dock event notifications.
612 */
613static int dock_add(acpi_handle handle)
614{
615 int ret;
616 acpi_status status;
617 struct dock_dependent_device *dd;
618
619 /* allocate & initialize the dock_station private data */
620 dock_station = kzalloc(sizeof(*dock_station), GFP_KERNEL);
621 if (!dock_station)
622 return -ENOMEM;
623 dock_station->handle = handle;
624 dock_station->last_dock_time = jiffies - HZ;
625 INIT_LIST_HEAD(&dock_station->dependent_devices);
626 INIT_LIST_HEAD(&dock_station->hotplug_devices);
627 spin_lock_init(&dock_station->dd_lock);
628 spin_lock_init(&dock_station->hp_lock);
629 ATOMIC_INIT_NOTIFIER_HEAD(&dock_notifier_list);
630
631 /* Find dependent devices */
632 acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
633 ACPI_UINT32_MAX, find_dock_devices, dock_station,
634 NULL);
635
636 /* add the dock station as a device dependent on itself */
637 dd = alloc_dock_dependent_device(handle);
638 if (!dd) {
639 kfree(dock_station);
640 return -ENOMEM;
641 }
642 add_dock_dependent_device(dock_station, dd);
643
644 /* register for dock events */
645 status = acpi_install_notify_handler(dock_station->handle,
646 ACPI_SYSTEM_NOTIFY,
647 dock_notify, dock_station);
648
649 if (ACPI_FAILURE(status)) {
650 printk(KERN_ERR PREFIX "Error installing notify handler\n");
651 ret = -ENODEV;
652 goto dock_add_err;
653 }
654
655 printk(KERN_INFO PREFIX "%s \n", ACPI_DOCK_DRIVER_NAME);
656
657 return 0;
658
659dock_add_err:
660 kfree(dock_station);
661 kfree(dd);
662 return ret;
663}
664
665/**
666 * dock_remove - free up resources related to the dock station
667 */
668static int dock_remove(void)
669{
670 struct dock_dependent_device *dd, *tmp;
671 acpi_status status;
672
673 if (!dock_station)
674 return 0;
675
676 /* remove dependent devices */
677 list_for_each_entry_safe(dd, tmp, &dock_station->dependent_devices,
678 list)
679 kfree(dd);
680
681 /* remove dock notify handler */
682 status = acpi_remove_notify_handler(dock_station->handle,
683 ACPI_SYSTEM_NOTIFY,
684 dock_notify);
685 if (ACPI_FAILURE(status))
686 printk(KERN_ERR "Error removing notify handler\n");
687
688 /* free dock station memory */
689 kfree(dock_station);
690 return 0;
691}
692
693/**
694 * find_dock - look for a dock station
695 * @handle: acpi handle of a device
696 * @lvl: unused
697 * @context: counter of dock stations found
698 * @rv: unused
699 *
700 * This is called by acpi_walk_namespace to look for dock stations.
701 */
702static acpi_status
703find_dock(acpi_handle handle, u32 lvl, void *context, void **rv)
704{
705 int *count = (int *)context;
706 acpi_status status = AE_OK;
707
708 if (is_dock(handle)) {
709 if (dock_add(handle) >= 0) {
710 (*count)++;
711 status = AE_CTRL_TERMINATE;
712 }
713 }
714 return status;
715}
716
717static int __init dock_init(void)
718{
719 int num = 0;
720
721 dock_station = NULL;
722
723 /* look for a dock station */
724 acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
725 ACPI_UINT32_MAX, find_dock, &num, NULL);
726
727 if (!num)
728 return -ENODEV;
729
730 return 0;
731}
732
733static void __exit dock_exit(void)
734{
735 dock_remove();
736}
737
738postcore_initcall(dock_init);
739module_exit(dock_exit);
diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c
index 18b3ea9dace2..e5d796362854 100644
--- a/drivers/acpi/ec.c
+++ b/drivers/acpi/ec.c
@@ -207,16 +207,15 @@ static int acpi_ec_intr_wait(union acpi_ec *ec, unsigned int event)
207{ 207{
208 int result = 0; 208 int result = 0;
209 209
210 ACPI_FUNCTION_TRACE("acpi_ec_wait");
211 210
212 ec->intr.expect_event = event; 211 ec->intr.expect_event = event;
213 smp_mb(); 212 smp_mb();
214 213
215 switch (event) { 214 switch (event) {
216 case ACPI_EC_EVENT_IBE: 215 case ACPI_EC_EVENT_IBE:
217 if (~acpi_ec_read_status(ec) & event) { 216 if (~acpi_ec_read_status(ec) & ACPI_EC_FLAG_IBF) {
218 ec->intr.expect_event = 0; 217 ec->intr.expect_event = 0;
219 return_VALUE(0); 218 return 0;
220 } 219 }
221 break; 220 break;
222 default: 221 default:
@@ -238,16 +237,16 @@ static int acpi_ec_intr_wait(union acpi_ec *ec, unsigned int event)
238 switch (event) { 237 switch (event) {
239 case ACPI_EC_EVENT_OBF: 238 case ACPI_EC_EVENT_OBF:
240 if (acpi_ec_read_status(ec) & ACPI_EC_FLAG_OBF) 239 if (acpi_ec_read_status(ec) & ACPI_EC_FLAG_OBF)
241 return_VALUE(0); 240 return 0;
242 break; 241 break;
243 242
244 case ACPI_EC_EVENT_IBE: 243 case ACPI_EC_EVENT_IBE:
245 if (~acpi_ec_read_status(ec) & ACPI_EC_FLAG_IBF) 244 if (~acpi_ec_read_status(ec) & ACPI_EC_FLAG_IBF)
246 return_VALUE(0); 245 return 0;
247 break; 246 break;
248 } 247 }
249 248
250 return_VALUE(-ETIME); 249 return -ETIME;
251} 250}
252 251
253#ifdef ACPI_FUTURE_USAGE 252#ifdef ACPI_FUTURE_USAGE
@@ -260,7 +259,6 @@ int acpi_ec_enter_burst_mode(union acpi_ec *ec)
260 u32 tmp = 0; 259 u32 tmp = 0;
261 int status = 0; 260 int status = 0;
262 261
263 ACPI_FUNCTION_TRACE("acpi_ec_enter_burst_mode");
264 262
265 status = acpi_ec_read_status(ec); 263 status = acpi_ec_read_status(ec);
266 if (status != -EINVAL && !(status & ACPI_EC_FLAG_BURST)) { 264 if (status != -EINVAL && !(status & ACPI_EC_FLAG_BURST)) {
@@ -272,22 +270,21 @@ int acpi_ec_enter_burst_mode(union acpi_ec *ec)
272 status = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF); 270 status = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF);
273 acpi_hw_low_level_read(8, &tmp, &ec->common.data_addr); 271 acpi_hw_low_level_read(8, &tmp, &ec->common.data_addr);
274 if (tmp != 0x90) { /* Burst ACK byte */ 272 if (tmp != 0x90) { /* Burst ACK byte */
275 return_VALUE(-EINVAL); 273 return -EINVAL;
276 } 274 }
277 } 275 }
278 276
279 atomic_set(&ec->intr.leaving_burst, 0); 277 atomic_set(&ec->intr.leaving_burst, 0);
280 return_VALUE(0); 278 return 0;
281 end: 279 end:
282 printk(KERN_WARNING PREFIX "Error in acpi_ec_wait\n"); 280 ACPI_EXCEPTION ((AE_INFO, status, "EC wait, burst mode");
283 return_VALUE(-1); 281 return -1;
284} 282}
285 283
286int acpi_ec_leave_burst_mode(union acpi_ec *ec) 284int acpi_ec_leave_burst_mode(union acpi_ec *ec)
287{ 285{
288 int status = 0; 286 int status = 0;
289 287
290 ACPI_FUNCTION_TRACE("acpi_ec_leave_burst_mode");
291 288
292 status = acpi_ec_read_status(ec); 289 status = acpi_ec_read_status(ec);
293 if (status != -EINVAL && (status & ACPI_EC_FLAG_BURST)){ 290 if (status != -EINVAL && (status & ACPI_EC_FLAG_BURST)){
@@ -298,10 +295,10 @@ int acpi_ec_leave_burst_mode(union acpi_ec *ec)
298 acpi_ec_wait(ec, ACPI_EC_FLAG_IBF); 295 acpi_ec_wait(ec, ACPI_EC_FLAG_IBF);
299 } 296 }
300 atomic_set(&ec->intr.leaving_burst, 1); 297 atomic_set(&ec->intr.leaving_burst, 1);
301 return_VALUE(0); 298 return 0;
302end: 299end:
303 printk(KERN_WARNING PREFIX "leave burst_mode:error\n"); 300 ACPI_EXCEPTION((AE_INFO, status, "EC leave burst mode");
304 return_VALUE(-1); 301 return -1;
305} 302}
306#endif /* ACPI_FUTURE_USAGE */ 303#endif /* ACPI_FUTURE_USAGE */
307 304
@@ -325,17 +322,16 @@ static int acpi_ec_poll_read(union acpi_ec *ec, u8 address, u32 * data)
325 int result = 0; 322 int result = 0;
326 u32 glk = 0; 323 u32 glk = 0;
327 324
328 ACPI_FUNCTION_TRACE("acpi_ec_read");
329 325
330 if (!ec || !data) 326 if (!ec || !data)
331 return_VALUE(-EINVAL); 327 return -EINVAL;
332 328
333 *data = 0; 329 *data = 0;
334 330
335 if (ec->common.global_lock) { 331 if (ec->common.global_lock) {
336 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk); 332 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk);
337 if (ACPI_FAILURE(status)) 333 if (ACPI_FAILURE(status))
338 return_VALUE(-ENODEV); 334 return -ENODEV;
339 } 335 }
340 336
341 if (down_interruptible(&ec->poll.sem)) { 337 if (down_interruptible(&ec->poll.sem)) {
@@ -365,7 +361,7 @@ end_nosem:
365 if (ec->common.global_lock) 361 if (ec->common.global_lock)
366 acpi_release_global_lock(glk); 362 acpi_release_global_lock(glk);
367 363
368 return_VALUE(result); 364 return result;
369} 365}
370 366
371static int acpi_ec_poll_write(union acpi_ec *ec, u8 address, u8 data) 367static int acpi_ec_poll_write(union acpi_ec *ec, u8 address, u8 data)
@@ -374,15 +370,14 @@ static int acpi_ec_poll_write(union acpi_ec *ec, u8 address, u8 data)
374 acpi_status status = AE_OK; 370 acpi_status status = AE_OK;
375 u32 glk = 0; 371 u32 glk = 0;
376 372
377 ACPI_FUNCTION_TRACE("acpi_ec_write");
378 373
379 if (!ec) 374 if (!ec)
380 return_VALUE(-EINVAL); 375 return -EINVAL;
381 376
382 if (ec->common.global_lock) { 377 if (ec->common.global_lock) {
383 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk); 378 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk);
384 if (ACPI_FAILURE(status)) 379 if (ACPI_FAILURE(status))
385 return_VALUE(-ENODEV); 380 return -ENODEV;
386 } 381 }
387 382
388 if (down_interruptible(&ec->poll.sem)) { 383 if (down_interruptible(&ec->poll.sem)) {
@@ -415,7 +410,7 @@ end_nosem:
415 if (ec->common.global_lock) 410 if (ec->common.global_lock)
416 acpi_release_global_lock(glk); 411 acpi_release_global_lock(glk);
417 412
418 return_VALUE(result); 413 return result;
419} 414}
420 415
421static int acpi_ec_intr_read(union acpi_ec *ec, u8 address, u32 * data) 416static int acpi_ec_intr_read(union acpi_ec *ec, u8 address, u32 * data)
@@ -423,17 +418,16 @@ static int acpi_ec_intr_read(union acpi_ec *ec, u8 address, u32 * data)
423 int status = 0; 418 int status = 0;
424 u32 glk; 419 u32 glk;
425 420
426 ACPI_FUNCTION_TRACE("acpi_ec_read");
427 421
428 if (!ec || !data) 422 if (!ec || !data)
429 return_VALUE(-EINVAL); 423 return -EINVAL;
430 424
431 *data = 0; 425 *data = 0;
432 426
433 if (ec->common.global_lock) { 427 if (ec->common.global_lock) {
434 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk); 428 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk);
435 if (ACPI_FAILURE(status)) 429 if (ACPI_FAILURE(status))
436 return_VALUE(-ENODEV); 430 return -ENODEV;
437 } 431 }
438 432
439 WARN_ON(in_interrupt()); 433 WARN_ON(in_interrupt());
@@ -467,7 +461,7 @@ static int acpi_ec_intr_read(union acpi_ec *ec, u8 address, u32 * data)
467 if (ec->common.global_lock) 461 if (ec->common.global_lock)
468 acpi_release_global_lock(glk); 462 acpi_release_global_lock(glk);
469 463
470 return_VALUE(status); 464 return status;
471} 465}
472 466
473static int acpi_ec_intr_write(union acpi_ec *ec, u8 address, u8 data) 467static int acpi_ec_intr_write(union acpi_ec *ec, u8 address, u8 data)
@@ -475,15 +469,14 @@ static int acpi_ec_intr_write(union acpi_ec *ec, u8 address, u8 data)
475 int status = 0; 469 int status = 0;
476 u32 glk; 470 u32 glk;
477 471
478 ACPI_FUNCTION_TRACE("acpi_ec_write");
479 472
480 if (!ec) 473 if (!ec)
481 return_VALUE(-EINVAL); 474 return -EINVAL;
482 475
483 if (ec->common.global_lock) { 476 if (ec->common.global_lock) {
484 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk); 477 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk);
485 if (ACPI_FAILURE(status)) 478 if (ACPI_FAILURE(status))
486 return_VALUE(-ENODEV); 479 return -ENODEV;
487 } 480 }
488 481
489 WARN_ON(in_interrupt()); 482 WARN_ON(in_interrupt());
@@ -516,7 +509,7 @@ static int acpi_ec_intr_write(union acpi_ec *ec, u8 address, u8 data)
516 if (ec->common.global_lock) 509 if (ec->common.global_lock)
517 acpi_release_global_lock(glk); 510 acpi_release_global_lock(glk);
518 511
519 return_VALUE(status); 512 return status;
520} 513}
521 514
522/* 515/*
@@ -574,17 +567,16 @@ static int acpi_ec_poll_query(union acpi_ec *ec, u32 * data)
574 acpi_status status = AE_OK; 567 acpi_status status = AE_OK;
575 u32 glk = 0; 568 u32 glk = 0;
576 569
577 ACPI_FUNCTION_TRACE("acpi_ec_query");
578 570
579 if (!ec || !data) 571 if (!ec || !data)
580 return_VALUE(-EINVAL); 572 return -EINVAL;
581 573
582 *data = 0; 574 *data = 0;
583 575
584 if (ec->common.global_lock) { 576 if (ec->common.global_lock) {
585 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk); 577 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk);
586 if (ACPI_FAILURE(status)) 578 if (ACPI_FAILURE(status))
587 return_VALUE(-ENODEV); 579 return -ENODEV;
588 } 580 }
589 581
590 /* 582 /*
@@ -613,23 +605,22 @@ end_nosem:
613 if (ec->common.global_lock) 605 if (ec->common.global_lock)
614 acpi_release_global_lock(glk); 606 acpi_release_global_lock(glk);
615 607
616 return_VALUE(result); 608 return result;
617} 609}
618static int acpi_ec_intr_query(union acpi_ec *ec, u32 * data) 610static int acpi_ec_intr_query(union acpi_ec *ec, u32 * data)
619{ 611{
620 int status = 0; 612 int status = 0;
621 u32 glk; 613 u32 glk;
622 614
623 ACPI_FUNCTION_TRACE("acpi_ec_query");
624 615
625 if (!ec || !data) 616 if (!ec || !data)
626 return_VALUE(-EINVAL); 617 return -EINVAL;
627 *data = 0; 618 *data = 0;
628 619
629 if (ec->common.global_lock) { 620 if (ec->common.global_lock) {
630 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk); 621 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk);
631 if (ACPI_FAILURE(status)) 622 if (ACPI_FAILURE(status))
632 return_VALUE(-ENODEV); 623 return -ENODEV;
633 } 624 }
634 625
635 down(&ec->intr.sem); 626 down(&ec->intr.sem);
@@ -662,7 +653,7 @@ static int acpi_ec_intr_query(union acpi_ec *ec, u32 * data)
662 if (ec->common.global_lock) 653 if (ec->common.global_lock)
663 acpi_release_global_lock(glk); 654 acpi_release_global_lock(glk);
664 655
665 return_VALUE(status); 656 return status;
666} 657}
667 658
668/* -------------------------------------------------------------------------- 659/* --------------------------------------------------------------------------
@@ -691,13 +682,12 @@ static void acpi_ec_gpe_poll_query(void *ec_cxt)
691 '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' 682 '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
692 }; 683 };
693 684
694 ACPI_FUNCTION_TRACE("acpi_ec_gpe_query");
695 685
696 if (!ec_cxt) 686 if (!ec_cxt)
697 goto end; 687 goto end;
698 688
699 if (down_interruptible (&ec->poll.sem)) { 689 if (down_interruptible (&ec->poll.sem)) {
700 return_VOID; 690 return;
701 } 691 }
702 acpi_hw_low_level_read(8, &value, &ec->common.command_addr); 692 acpi_hw_low_level_read(8, &value, &ec->common.command_addr);
703 up(&ec->poll.sem); 693 up(&ec->poll.sem);
@@ -734,7 +724,6 @@ static void acpi_ec_gpe_intr_query(void *ec_cxt)
734 '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' 724 '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
735 }; 725 };
736 726
737 ACPI_FUNCTION_TRACE("acpi_ec_gpe_query");
738 727
739 if (acpi_ec_read_status(ec) & ACPI_EC_FLAG_SCI) 728 if (acpi_ec_read_status(ec) & ACPI_EC_FLAG_SCI)
740 result = acpi_ec_query(ec, &value); 729 result = acpi_ec_query(ec, &value);
@@ -793,12 +782,15 @@ static u32 acpi_ec_gpe_intr_handler(void *data)
793 case ACPI_EC_EVENT_OBF: 782 case ACPI_EC_EVENT_OBF:
794 if (!(value & ACPI_EC_FLAG_OBF)) 783 if (!(value & ACPI_EC_FLAG_OBF))
795 break; 784 break;
785 ec->intr.expect_event = 0;
786 wake_up(&ec->intr.wait);
787 break;
796 case ACPI_EC_EVENT_IBE: 788 case ACPI_EC_EVENT_IBE:
797 if ((value & ACPI_EC_FLAG_IBF)) 789 if ((value & ACPI_EC_FLAG_IBF))
798 break; 790 break;
799 ec->intr.expect_event = 0; 791 ec->intr.expect_event = 0;
800 wake_up(&ec->intr.wait); 792 wake_up(&ec->intr.wait);
801 return ACPI_INTERRUPT_HANDLED; 793 break;
802 default: 794 default:
803 break; 795 break;
804 } 796 }
@@ -846,15 +838,14 @@ acpi_ec_space_handler(u32 function,
846 acpi_integer f_v = 0; 838 acpi_integer f_v = 0;
847 int i = 0; 839 int i = 0;
848 840
849 ACPI_FUNCTION_TRACE("acpi_ec_space_handler");
850 841
851 if ((address > 0xFF) || !value || !handler_context) 842 if ((address > 0xFF) || !value || !handler_context)
852 return_VALUE(AE_BAD_PARAMETER); 843 return AE_BAD_PARAMETER;
853 844
854 if (bit_width != 8 && acpi_strict) { 845 if (bit_width != 8 && acpi_strict) {
855 printk(KERN_WARNING PREFIX 846 printk(KERN_WARNING PREFIX
856 "acpi_ec_space_handler: bit_width should be 8\n"); 847 "acpi_ec_space_handler: bit_width should be 8\n");
857 return_VALUE(AE_BAD_PARAMETER); 848 return AE_BAD_PARAMETER;
858 } 849 }
859 850
860 ec = (union acpi_ec *)handler_context; 851 ec = (union acpi_ec *)handler_context;
@@ -893,16 +884,16 @@ acpi_ec_space_handler(u32 function,
893 out: 884 out:
894 switch (result) { 885 switch (result) {
895 case -EINVAL: 886 case -EINVAL:
896 return_VALUE(AE_BAD_PARAMETER); 887 return AE_BAD_PARAMETER;
897 break; 888 break;
898 case -ENODEV: 889 case -ENODEV:
899 return_VALUE(AE_NOT_FOUND); 890 return AE_NOT_FOUND;
900 break; 891 break;
901 case -ETIME: 892 case -ETIME:
902 return_VALUE(AE_TIME); 893 return AE_TIME;
903 break; 894 break;
904 default: 895 default:
905 return_VALUE(AE_OK); 896 return AE_OK;
906 } 897 }
907} 898}
908 899
@@ -916,7 +907,6 @@ static int acpi_ec_read_info(struct seq_file *seq, void *offset)
916{ 907{
917 union acpi_ec *ec = (union acpi_ec *)seq->private; 908 union acpi_ec *ec = (union acpi_ec *)seq->private;
918 909
919 ACPI_FUNCTION_TRACE("acpi_ec_read_info");
920 910
921 if (!ec) 911 if (!ec)
922 goto end; 912 goto end;
@@ -931,7 +921,7 @@ static int acpi_ec_read_info(struct seq_file *seq, void *offset)
931 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR); 921 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR);
932 922
933 end: 923 end:
934 return_VALUE(0); 924 return 0;
935} 925}
936 926
937static int acpi_ec_info_open_fs(struct inode *inode, struct file *file) 927static int acpi_ec_info_open_fs(struct inode *inode, struct file *file)
@@ -939,7 +929,7 @@ static int acpi_ec_info_open_fs(struct inode *inode, struct file *file)
939 return single_open(file, acpi_ec_read_info, PDE(inode)->data); 929 return single_open(file, acpi_ec_read_info, PDE(inode)->data);
940} 930}
941 931
942static struct file_operations acpi_ec_info_ops = { 932static const struct file_operations acpi_ec_info_ops = {
943 .open = acpi_ec_info_open_fs, 933 .open = acpi_ec_info_open_fs,
944 .read = seq_read, 934 .read = seq_read,
945 .llseek = seq_lseek, 935 .llseek = seq_lseek,
@@ -951,33 +941,29 @@ static int acpi_ec_add_fs(struct acpi_device *device)
951{ 941{
952 struct proc_dir_entry *entry = NULL; 942 struct proc_dir_entry *entry = NULL;
953 943
954 ACPI_FUNCTION_TRACE("acpi_ec_add_fs");
955 944
956 if (!acpi_device_dir(device)) { 945 if (!acpi_device_dir(device)) {
957 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), 946 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
958 acpi_ec_dir); 947 acpi_ec_dir);
959 if (!acpi_device_dir(device)) 948 if (!acpi_device_dir(device))
960 return_VALUE(-ENODEV); 949 return -ENODEV;
961 } 950 }
962 951
963 entry = create_proc_entry(ACPI_EC_FILE_INFO, S_IRUGO, 952 entry = create_proc_entry(ACPI_EC_FILE_INFO, S_IRUGO,
964 acpi_device_dir(device)); 953 acpi_device_dir(device));
965 if (!entry) 954 if (!entry)
966 ACPI_DEBUG_PRINT((ACPI_DB_WARN, 955 return -ENODEV;
967 "Unable to create '%s' fs entry\n",
968 ACPI_EC_FILE_INFO));
969 else { 956 else {
970 entry->proc_fops = &acpi_ec_info_ops; 957 entry->proc_fops = &acpi_ec_info_ops;
971 entry->data = acpi_driver_data(device); 958 entry->data = acpi_driver_data(device);
972 entry->owner = THIS_MODULE; 959 entry->owner = THIS_MODULE;
973 } 960 }
974 961
975 return_VALUE(0); 962 return 0;
976} 963}
977 964
978static int acpi_ec_remove_fs(struct acpi_device *device) 965static int acpi_ec_remove_fs(struct acpi_device *device)
979{ 966{
980 ACPI_FUNCTION_TRACE("acpi_ec_remove_fs");
981 967
982 if (acpi_device_dir(device)) { 968 if (acpi_device_dir(device)) {
983 remove_proc_entry(ACPI_EC_FILE_INFO, acpi_device_dir(device)); 969 remove_proc_entry(ACPI_EC_FILE_INFO, acpi_device_dir(device));
@@ -985,7 +971,7 @@ static int acpi_ec_remove_fs(struct acpi_device *device)
985 acpi_device_dir(device) = NULL; 971 acpi_device_dir(device) = NULL;
986 } 972 }
987 973
988 return_VALUE(0); 974 return 0;
989} 975}
990 976
991/* -------------------------------------------------------------------------- 977/* --------------------------------------------------------------------------
@@ -998,14 +984,13 @@ static int acpi_ec_poll_add(struct acpi_device *device)
998 acpi_status status = AE_OK; 984 acpi_status status = AE_OK;
999 union acpi_ec *ec = NULL; 985 union acpi_ec *ec = NULL;
1000 986
1001 ACPI_FUNCTION_TRACE("acpi_ec_add");
1002 987
1003 if (!device) 988 if (!device)
1004 return_VALUE(-EINVAL); 989 return -EINVAL;
1005 990
1006 ec = kmalloc(sizeof(union acpi_ec), GFP_KERNEL); 991 ec = kmalloc(sizeof(union acpi_ec), GFP_KERNEL);
1007 if (!ec) 992 if (!ec)
1008 return_VALUE(-ENOMEM); 993 return -ENOMEM;
1009 memset(ec, 0, sizeof(union acpi_ec)); 994 memset(ec, 0, sizeof(union acpi_ec));
1010 995
1011 ec->common.handle = device->handle; 996 ec->common.handle = device->handle;
@@ -1038,8 +1023,7 @@ static int acpi_ec_poll_add(struct acpi_device *device)
1038 acpi_evaluate_integer(ec->common.handle, "_GPE", NULL, 1023 acpi_evaluate_integer(ec->common.handle, "_GPE", NULL,
1039 &ec->common.gpe_bit); 1024 &ec->common.gpe_bit);
1040 if (ACPI_FAILURE(status)) { 1025 if (ACPI_FAILURE(status)) {
1041 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1026 ACPI_EXCEPTION((AE_INFO, status, "Obtaining GPE bit"));
1042 "Error obtaining GPE bit assignment\n"));
1043 result = -ENODEV; 1027 result = -ENODEV;
1044 goto end; 1028 goto end;
1045 } 1029 }
@@ -1059,7 +1043,7 @@ static int acpi_ec_poll_add(struct acpi_device *device)
1059 if (result) 1043 if (result)
1060 kfree(ec); 1044 kfree(ec);
1061 1045
1062 return_VALUE(result); 1046 return result;
1063} 1047}
1064static int acpi_ec_intr_add(struct acpi_device *device) 1048static int acpi_ec_intr_add(struct acpi_device *device)
1065{ 1049{
@@ -1067,14 +1051,13 @@ static int acpi_ec_intr_add(struct acpi_device *device)
1067 acpi_status status = AE_OK; 1051 acpi_status status = AE_OK;
1068 union acpi_ec *ec = NULL; 1052 union acpi_ec *ec = NULL;
1069 1053
1070 ACPI_FUNCTION_TRACE("acpi_ec_add");
1071 1054
1072 if (!device) 1055 if (!device)
1073 return_VALUE(-EINVAL); 1056 return -EINVAL;
1074 1057
1075 ec = kmalloc(sizeof(union acpi_ec), GFP_KERNEL); 1058 ec = kmalloc(sizeof(union acpi_ec), GFP_KERNEL);
1076 if (!ec) 1059 if (!ec)
1077 return_VALUE(-ENOMEM); 1060 return -ENOMEM;
1078 memset(ec, 0, sizeof(union acpi_ec)); 1061 memset(ec, 0, sizeof(union acpi_ec));
1079 1062
1080 ec->common.handle = device->handle; 1063 ec->common.handle = device->handle;
@@ -1110,8 +1093,7 @@ static int acpi_ec_intr_add(struct acpi_device *device)
1110 acpi_evaluate_integer(ec->common.handle, "_GPE", NULL, 1093 acpi_evaluate_integer(ec->common.handle, "_GPE", NULL,
1111 &ec->common.gpe_bit); 1094 &ec->common.gpe_bit);
1112 if (ACPI_FAILURE(status)) { 1095 if (ACPI_FAILURE(status)) {
1113 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1096 printk(KERN_ERR PREFIX "Obtaining GPE bit assignment\n");
1114 "Error obtaining GPE bit assignment\n"));
1115 result = -ENODEV; 1097 result = -ENODEV;
1116 goto end; 1098 goto end;
1117 } 1099 }
@@ -1131,17 +1113,16 @@ static int acpi_ec_intr_add(struct acpi_device *device)
1131 if (result) 1113 if (result)
1132 kfree(ec); 1114 kfree(ec);
1133 1115
1134 return_VALUE(result); 1116 return result;
1135} 1117}
1136 1118
1137static int acpi_ec_remove(struct acpi_device *device, int type) 1119static int acpi_ec_remove(struct acpi_device *device, int type)
1138{ 1120{
1139 union acpi_ec *ec = NULL; 1121 union acpi_ec *ec = NULL;
1140 1122
1141 ACPI_FUNCTION_TRACE("acpi_ec_remove");
1142 1123
1143 if (!device) 1124 if (!device)
1144 return_VALUE(-EINVAL); 1125 return -EINVAL;
1145 1126
1146 ec = acpi_driver_data(device); 1127 ec = acpi_driver_data(device);
1147 1128
@@ -1149,7 +1130,7 @@ static int acpi_ec_remove(struct acpi_device *device, int type)
1149 1130
1150 kfree(ec); 1131 kfree(ec);
1151 1132
1152 return_VALUE(0); 1133 return 0;
1153} 1134}
1154 1135
1155static acpi_status 1136static acpi_status
@@ -1188,15 +1169,14 @@ static int acpi_ec_start(struct acpi_device *device)
1188 acpi_status status = AE_OK; 1169 acpi_status status = AE_OK;
1189 union acpi_ec *ec = NULL; 1170 union acpi_ec *ec = NULL;
1190 1171
1191 ACPI_FUNCTION_TRACE("acpi_ec_start");
1192 1172
1193 if (!device) 1173 if (!device)
1194 return_VALUE(-EINVAL); 1174 return -EINVAL;
1195 1175
1196 ec = acpi_driver_data(device); 1176 ec = acpi_driver_data(device);
1197 1177
1198 if (!ec) 1178 if (!ec)
1199 return_VALUE(-EINVAL); 1179 return -EINVAL;
1200 1180
1201 /* 1181 /*
1202 * Get I/O port addresses. Convert to GAS format. 1182 * Get I/O port addresses. Convert to GAS format.
@@ -1205,9 +1185,8 @@ static int acpi_ec_start(struct acpi_device *device)
1205 acpi_ec_io_ports, ec); 1185 acpi_ec_io_ports, ec);
1206 if (ACPI_FAILURE(status) 1186 if (ACPI_FAILURE(status)
1207 || ec->common.command_addr.register_bit_width == 0) { 1187 || ec->common.command_addr.register_bit_width == 0) {
1208 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1188 printk(KERN_ERR PREFIX "Error getting I/O port addresses\n");
1209 "Error getting I/O port addresses")); 1189 return -ENODEV;
1210 return_VALUE(-ENODEV);
1211 } 1190 }
1212 1191
1213 ec->common.status_addr = ec->common.command_addr; 1192 ec->common.status_addr = ec->common.command_addr;
@@ -1224,7 +1203,7 @@ static int acpi_ec_start(struct acpi_device *device)
1224 ACPI_GPE_EDGE_TRIGGERED, 1203 ACPI_GPE_EDGE_TRIGGERED,
1225 &acpi_ec_gpe_handler, ec); 1204 &acpi_ec_gpe_handler, ec);
1226 if (ACPI_FAILURE(status)) { 1205 if (ACPI_FAILURE(status)) {
1227 return_VALUE(-ENODEV); 1206 return -ENODEV;
1228 } 1207 }
1229 acpi_set_gpe_type(NULL, ec->common.gpe_bit, ACPI_GPE_TYPE_RUNTIME); 1208 acpi_set_gpe_type(NULL, ec->common.gpe_bit, ACPI_GPE_TYPE_RUNTIME);
1230 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR); 1209 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR);
@@ -1236,10 +1215,10 @@ static int acpi_ec_start(struct acpi_device *device)
1236 if (ACPI_FAILURE(status)) { 1215 if (ACPI_FAILURE(status)) {
1237 acpi_remove_gpe_handler(NULL, ec->common.gpe_bit, 1216 acpi_remove_gpe_handler(NULL, ec->common.gpe_bit,
1238 &acpi_ec_gpe_handler); 1217 &acpi_ec_gpe_handler);
1239 return_VALUE(-ENODEV); 1218 return -ENODEV;
1240 } 1219 }
1241 1220
1242 return_VALUE(AE_OK); 1221 return AE_OK;
1243} 1222}
1244 1223
1245static int acpi_ec_stop(struct acpi_device *device, int type) 1224static int acpi_ec_stop(struct acpi_device *device, int type)
@@ -1247,10 +1226,9 @@ static int acpi_ec_stop(struct acpi_device *device, int type)
1247 acpi_status status = AE_OK; 1226 acpi_status status = AE_OK;
1248 union acpi_ec *ec = NULL; 1227 union acpi_ec *ec = NULL;
1249 1228
1250 ACPI_FUNCTION_TRACE("acpi_ec_stop");
1251 1229
1252 if (!device) 1230 if (!device)
1253 return_VALUE(-EINVAL); 1231 return -EINVAL;
1254 1232
1255 ec = acpi_driver_data(device); 1233 ec = acpi_driver_data(device);
1256 1234
@@ -1258,15 +1236,15 @@ static int acpi_ec_stop(struct acpi_device *device, int type)
1258 ACPI_ADR_SPACE_EC, 1236 ACPI_ADR_SPACE_EC,
1259 &acpi_ec_space_handler); 1237 &acpi_ec_space_handler);
1260 if (ACPI_FAILURE(status)) 1238 if (ACPI_FAILURE(status))
1261 return_VALUE(-ENODEV); 1239 return -ENODEV;
1262 1240
1263 status = 1241 status =
1264 acpi_remove_gpe_handler(NULL, ec->common.gpe_bit, 1242 acpi_remove_gpe_handler(NULL, ec->common.gpe_bit,
1265 &acpi_ec_gpe_handler); 1243 &acpi_ec_gpe_handler);
1266 if (ACPI_FAILURE(status)) 1244 if (ACPI_FAILURE(status))
1267 return_VALUE(-ENODEV); 1245 return -ENODEV;
1268 1246
1269 return_VALUE(0); 1247 return 0;
1270} 1248}
1271 1249
1272static acpi_status __init 1250static acpi_status __init
@@ -1536,23 +1514,22 @@ static int __init acpi_ec_init(void)
1536{ 1514{
1537 int result = 0; 1515 int result = 0;
1538 1516
1539 ACPI_FUNCTION_TRACE("acpi_ec_init");
1540 1517
1541 if (acpi_disabled) 1518 if (acpi_disabled)
1542 return_VALUE(0); 1519 return 0;
1543 1520
1544 acpi_ec_dir = proc_mkdir(ACPI_EC_CLASS, acpi_root_dir); 1521 acpi_ec_dir = proc_mkdir(ACPI_EC_CLASS, acpi_root_dir);
1545 if (!acpi_ec_dir) 1522 if (!acpi_ec_dir)
1546 return_VALUE(-ENODEV); 1523 return -ENODEV;
1547 1524
1548 /* Now register the driver for the EC */ 1525 /* Now register the driver for the EC */
1549 result = acpi_bus_register_driver(&acpi_ec_driver); 1526 result = acpi_bus_register_driver(&acpi_ec_driver);
1550 if (result < 0) { 1527 if (result < 0) {
1551 remove_proc_entry(ACPI_EC_CLASS, acpi_root_dir); 1528 remove_proc_entry(ACPI_EC_CLASS, acpi_root_dir);
1552 return_VALUE(-ENODEV); 1529 return -ENODEV;
1553 } 1530 }
1554 1531
1555 return_VALUE(result); 1532 return result;
1556} 1533}
1557 1534
1558subsys_initcall(acpi_ec_init); 1535subsys_initcall(acpi_ec_init);
@@ -1561,13 +1538,12 @@ subsys_initcall(acpi_ec_init);
1561#if 0 1538#if 0
1562static void __exit acpi_ec_exit(void) 1539static void __exit acpi_ec_exit(void)
1563{ 1540{
1564 ACPI_FUNCTION_TRACE("acpi_ec_exit");
1565 1541
1566 acpi_bus_unregister_driver(&acpi_ec_driver); 1542 acpi_bus_unregister_driver(&acpi_ec_driver);
1567 1543
1568 remove_proc_entry(ACPI_EC_CLASS, acpi_root_dir); 1544 remove_proc_entry(ACPI_EC_CLASS, acpi_root_dir);
1569 1545
1570 return_VOID; 1546 return;
1571} 1547}
1572#endif /* 0 */ 1548#endif /* 0 */
1573 1549
diff --git a/drivers/acpi/event.c b/drivers/acpi/event.c
index 2dbb1b0f11d5..959a893c8d1f 100644
--- a/drivers/acpi/event.c
+++ b/drivers/acpi/event.c
@@ -48,18 +48,17 @@ acpi_system_read_event(struct file *file, char __user * buffer, size_t count,
48 static int chars_remaining = 0; 48 static int chars_remaining = 0;
49 static char *ptr; 49 static char *ptr;
50 50
51 ACPI_FUNCTION_TRACE("acpi_system_read_event");
52 51
53 if (!chars_remaining) { 52 if (!chars_remaining) {
54 memset(&event, 0, sizeof(struct acpi_bus_event)); 53 memset(&event, 0, sizeof(struct acpi_bus_event));
55 54
56 if ((file->f_flags & O_NONBLOCK) 55 if ((file->f_flags & O_NONBLOCK)
57 && (list_empty(&acpi_bus_event_list))) 56 && (list_empty(&acpi_bus_event_list)))
58 return_VALUE(-EAGAIN); 57 return -EAGAIN;
59 58
60 result = acpi_bus_receive_event(&event); 59 result = acpi_bus_receive_event(&event);
61 if (result) 60 if (result)
62 return_VALUE(result); 61 return result;
63 62
64 chars_remaining = sprintf(str, "%s %s %08x %08x\n", 63 chars_remaining = sprintf(str, "%s %s %08x %08x\n",
65 event.device_class ? event. 64 event.device_class ? event.
@@ -75,13 +74,13 @@ acpi_system_read_event(struct file *file, char __user * buffer, size_t count,
75 } 74 }
76 75
77 if (copy_to_user(buffer, ptr, count)) 76 if (copy_to_user(buffer, ptr, count))
78 return_VALUE(-EFAULT); 77 return -EFAULT;
79 78
80 *ppos += count; 79 *ppos += count;
81 chars_remaining -= count; 80 chars_remaining -= count;
82 ptr += count; 81 ptr += count;
83 82
84 return_VALUE(count); 83 return count;
85} 84}
86 85
87static int acpi_system_close_event(struct inode *inode, struct file *file) 86static int acpi_system_close_event(struct inode *inode, struct file *file)
@@ -100,7 +99,7 @@ static unsigned int acpi_system_poll_event(struct file *file, poll_table * wait)
100 return 0; 99 return 0;
101} 100}
102 101
103static struct file_operations acpi_system_event_ops = { 102static const struct file_operations acpi_system_event_ops = {
104 .open = acpi_system_open_event, 103 .open = acpi_system_open_event,
105 .read = acpi_system_read_event, 104 .read = acpi_system_read_event,
106 .release = acpi_system_close_event, 105 .release = acpi_system_close_event,
@@ -112,22 +111,18 @@ static int __init acpi_event_init(void)
112 struct proc_dir_entry *entry; 111 struct proc_dir_entry *entry;
113 int error = 0; 112 int error = 0;
114 113
115 ACPI_FUNCTION_TRACE("acpi_event_init");
116 114
117 if (acpi_disabled) 115 if (acpi_disabled)
118 return_VALUE(0); 116 return 0;
119 117
120 /* 'event' [R] */ 118 /* 'event' [R] */
121 entry = create_proc_entry("event", S_IRUSR, acpi_root_dir); 119 entry = create_proc_entry("event", S_IRUSR, acpi_root_dir);
122 if (entry) 120 if (entry)
123 entry->proc_fops = &acpi_system_event_ops; 121 entry->proc_fops = &acpi_system_event_ops;
124 else { 122 else {
125 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 123 error = -ENODEV;
126 "Unable to create '%s' proc fs entry\n",
127 "event"));
128 error = -EFAULT;
129 } 124 }
130 return_VALUE(error); 125 return error;
131} 126}
132 127
133subsys_initcall(acpi_event_init); 128subsys_initcall(acpi_event_init);
diff --git a/drivers/acpi/events/evgpe.c b/drivers/acpi/events/evgpe.c
index f01d339407f8..c76c0583ca6a 100644
--- a/drivers/acpi/events/evgpe.c
+++ b/drivers/acpi/events/evgpe.c
@@ -382,7 +382,6 @@ u32 acpi_ev_gpe_detect(struct acpi_gpe_xrupt_info * gpe_xrupt_list)
382 u32 status_reg; 382 u32 status_reg;
383 u32 enable_reg; 383 u32 enable_reg;
384 acpi_cpu_flags flags; 384 acpi_cpu_flags flags;
385 acpi_cpu_flags hw_flags;
386 acpi_native_uint i; 385 acpi_native_uint i;
387 acpi_native_uint j; 386 acpi_native_uint j;
388 387
@@ -394,8 +393,11 @@ u32 acpi_ev_gpe_detect(struct acpi_gpe_xrupt_info * gpe_xrupt_list)
394 return (int_status); 393 return (int_status);
395 } 394 }
396 395
397 /* We need to hold the GPE lock now, hardware lock in the loop */ 396 /*
398 397 * We need to obtain the GPE lock for both the data structs and registers
398 * Note: Not necessary to obtain the hardware lock, since the GPE registers
399 * are owned by the gpe_lock.
400 */
399 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); 401 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
400 402
401 /* Examine all GPE blocks attached to this interrupt level */ 403 /* Examine all GPE blocks attached to this interrupt level */
@@ -413,8 +415,6 @@ u32 acpi_ev_gpe_detect(struct acpi_gpe_xrupt_info * gpe_xrupt_list)
413 415
414 gpe_register_info = &gpe_block->register_info[i]; 416 gpe_register_info = &gpe_block->register_info[i];
415 417
416 hw_flags = acpi_os_acquire_lock(acpi_gbl_hardware_lock);
417
418 /* Read the Status Register */ 418 /* Read the Status Register */
419 419
420 status = 420 status =
@@ -423,8 +423,6 @@ u32 acpi_ev_gpe_detect(struct acpi_gpe_xrupt_info * gpe_xrupt_list)
423 &gpe_register_info-> 423 &gpe_register_info->
424 status_address); 424 status_address);
425 if (ACPI_FAILURE(status)) { 425 if (ACPI_FAILURE(status)) {
426 acpi_os_release_lock(acpi_gbl_hardware_lock,
427 hw_flags);
428 goto unlock_and_exit; 426 goto unlock_and_exit;
429 } 427 }
430 428
@@ -435,8 +433,6 @@ u32 acpi_ev_gpe_detect(struct acpi_gpe_xrupt_info * gpe_xrupt_list)
435 &enable_reg, 433 &enable_reg,
436 &gpe_register_info-> 434 &gpe_register_info->
437 enable_address); 435 enable_address);
438 acpi_os_release_lock(acpi_gbl_hardware_lock, hw_flags);
439
440 if (ACPI_FAILURE(status)) { 436 if (ACPI_FAILURE(status)) {
441 goto unlock_and_exit; 437 goto unlock_and_exit;
442 } 438 }
diff --git a/drivers/acpi/events/evregion.c b/drivers/acpi/events/evregion.c
index 094a17e4c86d..21caae04fe85 100644
--- a/drivers/acpi/events/evregion.c
+++ b/drivers/acpi/events/evregion.c
@@ -528,34 +528,40 @@ acpi_ev_detach_region(union acpi_operand_object *region_obj,
528 } 528 }
529 } 529 }
530 530
531 /* Call the setup handler with the deactivate notification */ 531 /*
532 * If the region has been activated, call the setup handler
533 * with the deactivate notification
534 */
535 if (region_obj->region.flags & AOPOBJ_SETUP_COMPLETE) {
536 region_setup = handler_obj->address_space.setup;
537 status =
538 region_setup(region_obj,
539 ACPI_REGION_DEACTIVATE,
540 handler_obj->address_space.
541 context, region_context);
532 542
533 region_setup = handler_obj->address_space.setup; 543 /* Init routine may fail, Just ignore errors */
534 status =
535 region_setup(region_obj, ACPI_REGION_DEACTIVATE,
536 handler_obj->address_space.context,
537 region_context);
538 544
539 /* Init routine may fail, Just ignore errors */ 545 if (ACPI_FAILURE(status)) {
546 ACPI_EXCEPTION((AE_INFO, status,
547 "from region handler - deactivate, [%s]",
548 acpi_ut_get_region_name
549 (region_obj->region.
550 space_id)));
551 }
540 552
541 if (ACPI_FAILURE(status)) { 553 region_obj->region.flags &=
542 ACPI_EXCEPTION((AE_INFO, status, 554 ~(AOPOBJ_SETUP_COMPLETE);
543 "from region init, [%s]",
544 acpi_ut_get_region_name
545 (region_obj->region.space_id)));
546 } 555 }
547 556
548 region_obj->region.flags &= ~(AOPOBJ_SETUP_COMPLETE);
549
550 /* 557 /*
551 * Remove handler reference in the region 558 * Remove handler reference in the region
552 * 559 *
553 * NOTE: this doesn't mean that the region goes away 560 * NOTE: this doesn't mean that the region goes away, the region
554 * The region is just inaccessible as indicated to 561 * is just inaccessible as indicated to the _REG method
555 * the _REG method
556 * 562 *
557 * If the region is on the handler's list 563 * If the region is on the handler's list, this must be the
558 * this better be the region's handler 564 * region's handler
559 */ 565 */
560 region_obj->region.handler = NULL; 566 region_obj->region.handler = NULL;
561 acpi_ut_remove_reference(handler_obj); 567 acpi_ut_remove_reference(handler_obj);
diff --git a/drivers/acpi/events/evxface.c b/drivers/acpi/events/evxface.c
index 76c34a66e0e0..923fd2b46955 100644
--- a/drivers/acpi/events/evxface.c
+++ b/drivers/acpi/events/evxface.c
@@ -414,12 +414,13 @@ acpi_remove_notify_handler(acpi_handle device,
414 414
415 if ((!device) || 415 if ((!device) ||
416 (!handler) || (handler_type > ACPI_MAX_NOTIFY_HANDLER_TYPE)) { 416 (!handler) || (handler_type > ACPI_MAX_NOTIFY_HANDLER_TYPE)) {
417 return_ACPI_STATUS(AE_BAD_PARAMETER); 417 status = AE_BAD_PARAMETER;
418 goto exit;
418 } 419 }
419 420
420 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); 421 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
421 if (ACPI_FAILURE(status)) { 422 if (ACPI_FAILURE(status)) {
422 return_ACPI_STATUS(status); 423 goto exit;
423 } 424 }
424 425
425 /* Convert and validate the device handle */ 426 /* Convert and validate the device handle */
@@ -450,7 +451,7 @@ acpi_remove_notify_handler(acpi_handle device,
450 acpi_os_wait_events_complete(NULL); 451 acpi_os_wait_events_complete(NULL);
451 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); 452 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
452 if (ACPI_FAILURE(status)) { 453 if (ACPI_FAILURE(status)) {
453 return_ACPI_STATUS(status); 454 goto exit;
454 } 455 }
455 456
456 if (handler_type & ACPI_SYSTEM_NOTIFY) { 457 if (handler_type & ACPI_SYSTEM_NOTIFY) {
@@ -488,8 +489,12 @@ acpi_remove_notify_handler(acpi_handle device,
488 489
489 if (handler_type & ACPI_SYSTEM_NOTIFY) { 490 if (handler_type & ACPI_SYSTEM_NOTIFY) {
490 notify_obj = obj_desc->common_notify.system_notify; 491 notify_obj = obj_desc->common_notify.system_notify;
491 if ((!notify_obj) || 492 if (!notify_obj) {
492 (notify_obj->notify.handler != handler)) { 493 status = AE_NOT_EXIST;
494 goto unlock_and_exit;
495 }
496
497 if (notify_obj->notify.handler != handler) {
493 status = AE_BAD_PARAMETER; 498 status = AE_BAD_PARAMETER;
494 goto unlock_and_exit; 499 goto unlock_and_exit;
495 } 500 }
@@ -499,7 +504,7 @@ acpi_remove_notify_handler(acpi_handle device,
499 acpi_os_wait_events_complete(NULL); 504 acpi_os_wait_events_complete(NULL);
500 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); 505 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
501 if (ACPI_FAILURE(status)) { 506 if (ACPI_FAILURE(status)) {
502 return_ACPI_STATUS(status); 507 goto exit;
503 } 508 }
504 509
505 /* Remove the handler */ 510 /* Remove the handler */
@@ -509,8 +514,12 @@ acpi_remove_notify_handler(acpi_handle device,
509 514
510 if (handler_type & ACPI_DEVICE_NOTIFY) { 515 if (handler_type & ACPI_DEVICE_NOTIFY) {
511 notify_obj = obj_desc->common_notify.device_notify; 516 notify_obj = obj_desc->common_notify.device_notify;
512 if ((!notify_obj) || 517 if (!notify_obj) {
513 (notify_obj->notify.handler != handler)) { 518 status = AE_NOT_EXIST;
519 goto unlock_and_exit;
520 }
521
522 if (notify_obj->notify.handler != handler) {
514 status = AE_BAD_PARAMETER; 523 status = AE_BAD_PARAMETER;
515 goto unlock_and_exit; 524 goto unlock_and_exit;
516 } 525 }
@@ -520,7 +529,7 @@ acpi_remove_notify_handler(acpi_handle device,
520 acpi_os_wait_events_complete(NULL); 529 acpi_os_wait_events_complete(NULL);
521 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); 530 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
522 if (ACPI_FAILURE(status)) { 531 if (ACPI_FAILURE(status)) {
523 return_ACPI_STATUS(status); 532 goto exit;
524 } 533 }
525 534
526 /* Remove the handler */ 535 /* Remove the handler */
@@ -531,6 +540,9 @@ acpi_remove_notify_handler(acpi_handle device,
531 540
532 unlock_and_exit: 541 unlock_and_exit:
533 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); 542 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
543 exit:
544 if (ACPI_FAILURE(status))
545 ACPI_EXCEPTION((AE_INFO, status, "Removing notify handler"));
534 return_ACPI_STATUS(status); 546 return_ACPI_STATUS(status);
535} 547}
536 548
@@ -568,12 +580,13 @@ acpi_install_gpe_handler(acpi_handle gpe_device,
568 /* Parameter validation */ 580 /* Parameter validation */
569 581
570 if ((!address) || (type > ACPI_GPE_XRUPT_TYPE_MASK)) { 582 if ((!address) || (type > ACPI_GPE_XRUPT_TYPE_MASK)) {
571 return_ACPI_STATUS(AE_BAD_PARAMETER); 583 status = AE_BAD_PARAMETER;
584 goto exit;
572 } 585 }
573 586
574 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); 587 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
575 if (ACPI_FAILURE(status)) { 588 if (ACPI_FAILURE(status)) {
576 return_ACPI_STATUS(status); 589 goto exit;
577 } 590 }
578 591
579 /* Ensure that we have a valid GPE number */ 592 /* Ensure that we have a valid GPE number */
@@ -625,6 +638,10 @@ acpi_install_gpe_handler(acpi_handle gpe_device,
625 638
626 unlock_and_exit: 639 unlock_and_exit:
627 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); 640 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
641 exit:
642 if (ACPI_FAILURE(status))
643 ACPI_EXCEPTION((AE_INFO, status,
644 "Installing notify handler failed"));
628 return_ACPI_STATUS(status); 645 return_ACPI_STATUS(status);
629} 646}
630 647
diff --git a/drivers/acpi/events/evxfregn.c b/drivers/acpi/events/evxfregn.c
index e8b86a0baad0..83b12a9afa32 100644
--- a/drivers/acpi/events/evxfregn.c
+++ b/drivers/acpi/events/evxfregn.c
@@ -155,7 +155,11 @@ acpi_remove_address_space_handler(acpi_handle device,
155 /* Convert and validate the device handle */ 155 /* Convert and validate the device handle */
156 156
157 node = acpi_ns_map_handle_to_node(device); 157 node = acpi_ns_map_handle_to_node(device);
158 if (!node) { 158 if (!node ||
159 ((node->type != ACPI_TYPE_DEVICE) &&
160 (node->type != ACPI_TYPE_PROCESSOR) &&
161 (node->type != ACPI_TYPE_THERMAL) &&
162 (node != acpi_gbl_root_node))) {
159 status = AE_BAD_PARAMETER; 163 status = AE_BAD_PARAMETER;
160 goto unlock_and_exit; 164 goto unlock_and_exit;
161 } 165 }
@@ -178,6 +182,13 @@ acpi_remove_address_space_handler(acpi_handle device,
178 182
179 if (handler_obj->address_space.space_id == space_id) { 183 if (handler_obj->address_space.space_id == space_id) {
180 184
185 /* Handler must be the same as the installed handler */
186
187 if (handler_obj->address_space.handler != handler) {
188 status = AE_BAD_PARAMETER;
189 goto unlock_and_exit;
190 }
191
181 /* Matched space_id, first dereference this in the Regions */ 192 /* Matched space_id, first dereference this in the Regions */
182 193
183 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION, 194 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
diff --git a/drivers/acpi/executer/exconfig.c b/drivers/acpi/executer/exconfig.c
index 823352435e08..c8341fa5fe01 100644
--- a/drivers/acpi/executer/exconfig.c
+++ b/drivers/acpi/executer/exconfig.c
@@ -266,6 +266,10 @@ acpi_ex_load_table_op(struct acpi_walk_state *walk_state,
266 } 266 }
267 } 267 }
268 268
269 ACPI_INFO((AE_INFO,
270 "Dynamic OEM Table Load - [%4.4s] OemId [%6.6s] OemTableId [%8.8s]",
271 table->signature, table->oem_id, table->oem_table_id));
272
269 *return_desc = ddb_handle; 273 *return_desc = ddb_handle;
270 return_ACPI_STATUS(status); 274 return_ACPI_STATUS(status);
271} 275}
@@ -446,6 +450,10 @@ acpi_ex_load_op(union acpi_operand_object *obj_desc,
446 return_ACPI_STATUS(status); 450 return_ACPI_STATUS(status);
447 } 451 }
448 452
453 ACPI_INFO((AE_INFO,
454 "Dynamic SSDT Load - OemId [%6.6s] OemTableId [%8.8s]",
455 table_ptr->oem_id, table_ptr->oem_table_id));
456
449 cleanup: 457 cleanup:
450 if (ACPI_FAILURE(status)) { 458 if (ACPI_FAILURE(status)) {
451 ACPI_FREE(table_ptr); 459 ACPI_FREE(table_ptr);
@@ -494,7 +502,6 @@ acpi_status acpi_ex_unload_table(union acpi_operand_object *ddb_handle)
494 * (Offset contains the table_id) 502 * (Offset contains the table_id)
495 */ 503 */
496 acpi_ns_delete_namespace_by_owner(table_info->owner_id); 504 acpi_ns_delete_namespace_by_owner(table_info->owner_id);
497 acpi_ut_release_owner_id(&table_info->owner_id);
498 505
499 /* Delete the table itself */ 506 /* Delete the table itself */
500 507
diff --git a/drivers/acpi/executer/exconvrt.c b/drivers/acpi/executer/exconvrt.c
index b732e399b1ef..544e81a6a438 100644
--- a/drivers/acpi/executer/exconvrt.c
+++ b/drivers/acpi/executer/exconvrt.c
@@ -170,6 +170,9 @@ acpi_ex_convert_to_integer(union acpi_operand_object *obj_desc,
170 return_ACPI_STATUS(AE_NO_MEMORY); 170 return_ACPI_STATUS(AE_NO_MEMORY);
171 } 171 }
172 172
173 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Converted value: %8.8X%8.8X\n",
174 ACPI_FORMAT_UINT64(result)));
175
173 /* Save the Result */ 176 /* Save the Result */
174 177
175 return_desc->integer.value = result; 178 return_desc->integer.value = result;
diff --git a/drivers/acpi/executer/excreate.c b/drivers/acpi/executer/excreate.c
index 106dc7219df7..34eec82c1b1e 100644
--- a/drivers/acpi/executer/excreate.c
+++ b/drivers/acpi/executer/excreate.c
@@ -177,7 +177,7 @@ acpi_status acpi_ex_create_event(struct acpi_walk_state *walk_state)
177 * that the event is created in an unsignalled state 177 * that the event is created in an unsignalled state
178 */ 178 */
179 status = acpi_os_create_semaphore(ACPI_NO_UNIT_LIMIT, 0, 179 status = acpi_os_create_semaphore(ACPI_NO_UNIT_LIMIT, 0,
180 &obj_desc->event.semaphore); 180 &obj_desc->event.os_semaphore);
181 if (ACPI_FAILURE(status)) { 181 if (ACPI_FAILURE(status)) {
182 goto cleanup; 182 goto cleanup;
183 } 183 }
@@ -226,12 +226,9 @@ acpi_status acpi_ex_create_mutex(struct acpi_walk_state *walk_state)
226 goto cleanup; 226 goto cleanup;
227 } 227 }
228 228
229 /* 229 /* Create the actual OS Mutex */
230 * Create the actual OS semaphore. 230
231 * One unit max to make it a mutex, with one initial unit to allow 231 status = acpi_os_create_mutex(&obj_desc->mutex.os_mutex);
232 * the mutex to be acquired.
233 */
234 status = acpi_os_create_semaphore(1, 1, &obj_desc->mutex.semaphore);
235 if (ACPI_FAILURE(status)) { 232 if (ACPI_FAILURE(status)) {
236 goto cleanup; 233 goto cleanup;
237 } 234 }
@@ -565,7 +562,7 @@ acpi_ex_create_method(u8 * aml_start,
565 obj_desc->method.aml_length = aml_length; 562 obj_desc->method.aml_length = aml_length;
566 563
567 /* 564 /*
568 * Disassemble the method flags. Split off the Arg Count 565 * Disassemble the method flags. Split off the Arg Count
569 * for efficiency 566 * for efficiency
570 */ 567 */
571 method_flags = (u8) operand[1]->integer.value; 568 method_flags = (u8) operand[1]->integer.value;
@@ -576,21 +573,19 @@ acpi_ex_create_method(u8 * aml_start,
576 (u8) (method_flags & AML_METHOD_ARG_COUNT); 573 (u8) (method_flags & AML_METHOD_ARG_COUNT);
577 574
578 /* 575 /*
579 * Get the concurrency count. If required, a semaphore will be 576 * Get the sync_level. If method is serialized, a mutex will be
580 * created for this method when it is parsed. 577 * created for this method when it is parsed.
581 */ 578 */
582 if (acpi_gbl_all_methods_serialized) { 579 if (acpi_gbl_all_methods_serialized) {
583 obj_desc->method.concurrency = 1; 580 obj_desc->method.sync_level = 0;
584 obj_desc->method.method_flags |= AML_METHOD_SERIALIZED; 581 obj_desc->method.method_flags |= AML_METHOD_SERIALIZED;
585 } else if (method_flags & AML_METHOD_SERIALIZED) { 582 } else if (method_flags & AML_METHOD_SERIALIZED) {
586 /* 583 /*
587 * ACPI 1.0: Concurrency = 1 584 * ACPI 1.0: sync_level = 0
588 * ACPI 2.0: Concurrency = (sync_level (in method declaration) + 1) 585 * ACPI 2.0: sync_level = sync_level in method declaration
589 */ 586 */
590 obj_desc->method.concurrency = (u8) 587 obj_desc->method.sync_level = (u8)
591 (((method_flags & AML_METHOD_SYNCH_LEVEL) >> 4) + 1); 588 ((method_flags & AML_METHOD_SYNCH_LEVEL) >> 4);
592 } else {
593 obj_desc->method.concurrency = ACPI_INFINITE_CONCURRENCY;
594 } 589 }
595 590
596 /* Attach the new object to the method Node */ 591 /* Attach the new object to the method Node */
diff --git a/drivers/acpi/executer/exdump.c b/drivers/acpi/executer/exdump.c
index 7b9718e976bf..2450943add33 100644
--- a/drivers/acpi/executer/exdump.c
+++ b/drivers/acpi/executer/exdump.c
@@ -118,14 +118,14 @@ static struct acpi_exdump_info acpi_ex_dump_device[4] = {
118 118
119static struct acpi_exdump_info acpi_ex_dump_event[2] = { 119static struct acpi_exdump_info acpi_ex_dump_event[2] = {
120 {ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_event), NULL}, 120 {ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_event), NULL},
121 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(event.semaphore), "Semaphore"} 121 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(event.os_semaphore), "OsSemaphore"}
122}; 122};
123 123
124static struct acpi_exdump_info acpi_ex_dump_method[8] = { 124static struct acpi_exdump_info acpi_ex_dump_method[8] = {
125 {ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_method), NULL}, 125 {ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_method), NULL},
126 {ACPI_EXD_UINT8, ACPI_EXD_OFFSET(method.param_count), "ParamCount"}, 126 {ACPI_EXD_UINT8, ACPI_EXD_OFFSET(method.param_count), "ParamCount"},
127 {ACPI_EXD_UINT8, ACPI_EXD_OFFSET(method.concurrency), "Concurrency"}, 127 {ACPI_EXD_UINT8, ACPI_EXD_OFFSET(method.sync_level), "Sync Level"},
128 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(method.semaphore), "Semaphore"}, 128 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(method.mutex), "Mutex"},
129 {ACPI_EXD_UINT8, ACPI_EXD_OFFSET(method.owner_id), "Owner Id"}, 129 {ACPI_EXD_UINT8, ACPI_EXD_OFFSET(method.owner_id), "Owner Id"},
130 {ACPI_EXD_UINT8, ACPI_EXD_OFFSET(method.thread_count), "Thread Count"}, 130 {ACPI_EXD_UINT8, ACPI_EXD_OFFSET(method.thread_count), "Thread Count"},
131 {ACPI_EXD_UINT32, ACPI_EXD_OFFSET(method.aml_length), "Aml Length"}, 131 {ACPI_EXD_UINT32, ACPI_EXD_OFFSET(method.aml_length), "Aml Length"},
@@ -138,7 +138,7 @@ static struct acpi_exdump_info acpi_ex_dump_mutex[5] = {
138 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(mutex.owner_thread), "Owner Thread"}, 138 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(mutex.owner_thread), "Owner Thread"},
139 {ACPI_EXD_UINT16, ACPI_EXD_OFFSET(mutex.acquisition_depth), 139 {ACPI_EXD_UINT16, ACPI_EXD_OFFSET(mutex.acquisition_depth),
140 "Acquire Depth"}, 140 "Acquire Depth"},
141 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(mutex.semaphore), "Semaphore"} 141 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(mutex.os_mutex), "OsMutex"}
142}; 142};
143 143
144static struct acpi_exdump_info acpi_ex_dump_region[7] = { 144static struct acpi_exdump_info acpi_ex_dump_region[7] = {
diff --git a/drivers/acpi/executer/exfldio.c b/drivers/acpi/executer/exfldio.c
index 051053f7cccb..40f0bee6faa5 100644
--- a/drivers/acpi/executer/exfldio.c
+++ b/drivers/acpi/executer/exfldio.c
@@ -727,11 +727,23 @@ acpi_ex_extract_from_field(union acpi_operand_object *obj_desc,
727 return_ACPI_STATUS(status); 727 return_ACPI_STATUS(status);
728 } 728 }
729 729
730 /* Merge with previous datum if necessary */ 730 /*
731 731 * Merge with previous datum if necessary.
732 merged_datum |= raw_datum << 732 *
733 (obj_desc->common_field.access_bit_width - 733 * Note: Before the shift, check if the shift value will be larger than
734 obj_desc->common_field.start_field_bit_offset); 734 * the integer size. If so, there is no need to perform the operation.
735 * This avoids the differences in behavior between different compilers
736 * concerning shift values larger than the target data width.
737 */
738 if ((obj_desc->common_field.access_bit_width -
739 obj_desc->common_field.start_field_bit_offset) <
740 ACPI_INTEGER_BIT_SIZE) {
741 merged_datum |=
742 raw_datum << (obj_desc->common_field.
743 access_bit_width -
744 obj_desc->common_field.
745 start_field_bit_offset);
746 }
735 747
736 if (i == datum_count) { 748 if (i == datum_count) {
737 break; 749 break;
@@ -808,13 +820,23 @@ acpi_ex_insert_into_field(union acpi_operand_object *obj_desc,
808 return_ACPI_STATUS(AE_BUFFER_OVERFLOW); 820 return_ACPI_STATUS(AE_BUFFER_OVERFLOW);
809 } 821 }
810 822
811 /* Compute the number of datums (access width data items) */ 823 /*
824 * Create the bitmasks used for bit insertion.
825 * Note: This if/else is used to bypass compiler differences with the
826 * shift operator
827 */
828 if (obj_desc->common_field.access_bit_width == ACPI_INTEGER_BIT_SIZE) {
829 width_mask = ACPI_INTEGER_MAX;
830 } else {
831 width_mask =
832 ACPI_MASK_BITS_ABOVE(obj_desc->common_field.
833 access_bit_width);
834 }
812 835
813 width_mask = 836 mask = width_mask &
814 ACPI_MASK_BITS_ABOVE(obj_desc->common_field.access_bit_width); 837 ACPI_MASK_BITS_BELOW(obj_desc->common_field.start_field_bit_offset);
815 mask = 838
816 width_mask & ACPI_MASK_BITS_BELOW(obj_desc->common_field. 839 /* Compute the number of datums (access width data items) */
817 start_field_bit_offset);
818 840
819 datum_count = ACPI_ROUND_UP_TO(obj_desc->common_field.bit_length, 841 datum_count = ACPI_ROUND_UP_TO(obj_desc->common_field.bit_length,
820 obj_desc->common_field.access_bit_width); 842 obj_desc->common_field.access_bit_width);
@@ -848,12 +870,29 @@ acpi_ex_insert_into_field(union acpi_operand_object *obj_desc,
848 return_ACPI_STATUS(status); 870 return_ACPI_STATUS(status);
849 } 871 }
850 872
851 /* Start new output datum by merging with previous input datum */
852
853 field_offset += obj_desc->common_field.access_byte_width; 873 field_offset += obj_desc->common_field.access_byte_width;
854 merged_datum = raw_datum >> 874
855 (obj_desc->common_field.access_bit_width - 875 /*
856 obj_desc->common_field.start_field_bit_offset); 876 * Start new output datum by merging with previous input datum
877 * if necessary.
878 *
879 * Note: Before the shift, check if the shift value will be larger than
880 * the integer size. If so, there is no need to perform the operation.
881 * This avoids the differences in behavior between different compilers
882 * concerning shift values larger than the target data width.
883 */
884 if ((obj_desc->common_field.access_bit_width -
885 obj_desc->common_field.start_field_bit_offset) <
886 ACPI_INTEGER_BIT_SIZE) {
887 merged_datum =
888 raw_datum >> (obj_desc->common_field.
889 access_bit_width -
890 obj_desc->common_field.
891 start_field_bit_offset);
892 } else {
893 merged_datum = 0;
894 }
895
857 mask = width_mask; 896 mask = width_mask;
858 897
859 if (i == datum_count) { 898 if (i == datum_count) {
diff --git a/drivers/acpi/executer/exmutex.c b/drivers/acpi/executer/exmutex.c
index 93098d68cadf..3a39c2e8e104 100644
--- a/drivers/acpi/executer/exmutex.c
+++ b/drivers/acpi/executer/exmutex.c
@@ -161,12 +161,13 @@ acpi_ex_acquire_mutex(union acpi_operand_object *time_desc,
161 161
162 /* 162 /*
163 * Current Sync must be less than or equal to the sync level of the 163 * Current Sync must be less than or equal to the sync level of the
164 * mutex. This mechanism provides some deadlock prevention 164 * mutex. This mechanism provides some deadlock prevention
165 */ 165 */
166 if (walk_state->thread->current_sync_level > obj_desc->mutex.sync_level) { 166 if (walk_state->thread->current_sync_level > obj_desc->mutex.sync_level) {
167 ACPI_ERROR((AE_INFO, 167 ACPI_ERROR((AE_INFO,
168 "Cannot acquire Mutex [%4.4s], incorrect SyncLevel", 168 "Cannot acquire Mutex [%4.4s], current SyncLevel is too large (%d)",
169 acpi_ut_get_node_name(obj_desc->mutex.node))); 169 acpi_ut_get_node_name(obj_desc->mutex.node),
170 walk_state->thread->current_sync_level));
170 return_ACPI_STATUS(AE_AML_MUTEX_ORDER); 171 return_ACPI_STATUS(AE_AML_MUTEX_ORDER);
171 } 172 }
172 173
@@ -178,8 +179,7 @@ acpi_ex_acquire_mutex(union acpi_operand_object *time_desc,
178 179
179 if ((obj_desc->mutex.owner_thread->thread_id == 180 if ((obj_desc->mutex.owner_thread->thread_id ==
180 walk_state->thread->thread_id) || 181 walk_state->thread->thread_id) ||
181 (obj_desc->mutex.semaphore == 182 (obj_desc->mutex.os_mutex == ACPI_GLOBAL_LOCK)) {
182 acpi_gbl_global_lock_semaphore)) {
183 /* 183 /*
184 * The mutex is already owned by this thread, 184 * The mutex is already owned by this thread,
185 * just increment the acquisition depth 185 * just increment the acquisition depth
@@ -264,12 +264,12 @@ acpi_ex_release_mutex(union acpi_operand_object *obj_desc,
264 */ 264 */
265 if ((obj_desc->mutex.owner_thread->thread_id != 265 if ((obj_desc->mutex.owner_thread->thread_id !=
266 walk_state->thread->thread_id) 266 walk_state->thread->thread_id)
267 && (obj_desc->mutex.semaphore != acpi_gbl_global_lock_semaphore)) { 267 && (obj_desc->mutex.os_mutex != ACPI_GLOBAL_LOCK)) {
268 ACPI_ERROR((AE_INFO, 268 ACPI_ERROR((AE_INFO,
269 "Thread %X cannot release Mutex [%4.4s] acquired by thread %X", 269 "Thread %X cannot release Mutex [%4.4s] acquired by thread %X",
270 walk_state->thread->thread_id, 270 (u32) walk_state->thread->thread_id,
271 acpi_ut_get_node_name(obj_desc->mutex.node), 271 acpi_ut_get_node_name(obj_desc->mutex.node),
272 obj_desc->mutex.owner_thread->thread_id)); 272 (u32) obj_desc->mutex.owner_thread->thread_id));
273 return_ACPI_STATUS(AE_AML_NOT_OWNER); 273 return_ACPI_STATUS(AE_AML_NOT_OWNER);
274 } 274 }
275 275
diff --git a/drivers/acpi/executer/exsystem.c b/drivers/acpi/executer/exsystem.c
index 52beee3674a0..28aef3e69ecc 100644
--- a/drivers/acpi/executer/exsystem.c
+++ b/drivers/acpi/executer/exsystem.c
@@ -60,17 +60,17 @@ ACPI_MODULE_NAME("exsystem")
60 * 60 *
61 * DESCRIPTION: Implements a semaphore wait with a check to see if the 61 * DESCRIPTION: Implements a semaphore wait with a check to see if the
62 * semaphore is available immediately. If it is not, the 62 * semaphore is available immediately. If it is not, the
63 * interpreter is released. 63 * interpreter is released before waiting.
64 * 64 *
65 ******************************************************************************/ 65 ******************************************************************************/
66acpi_status acpi_ex_system_wait_semaphore(acpi_handle semaphore, u16 timeout) 66acpi_status acpi_ex_system_wait_semaphore(acpi_semaphore semaphore, u16 timeout)
67{ 67{
68 acpi_status status; 68 acpi_status status;
69 acpi_status status2; 69 acpi_status status2;
70 70
71 ACPI_FUNCTION_TRACE(ex_system_wait_semaphore); 71 ACPI_FUNCTION_TRACE(ex_system_wait_semaphore);
72 72
73 status = acpi_os_wait_semaphore(semaphore, 1, 0); 73 status = acpi_os_wait_semaphore(semaphore, 1, ACPI_DO_NOT_WAIT);
74 if (ACPI_SUCCESS(status)) { 74 if (ACPI_SUCCESS(status)) {
75 return_ACPI_STATUS(status); 75 return_ACPI_STATUS(status);
76 } 76 }
@@ -103,6 +103,59 @@ acpi_status acpi_ex_system_wait_semaphore(acpi_handle semaphore, u16 timeout)
103 103
104/******************************************************************************* 104/*******************************************************************************
105 * 105 *
106 * FUNCTION: acpi_ex_system_wait_mutex
107 *
108 * PARAMETERS: Mutex - Mutex to wait on
109 * Timeout - Max time to wait
110 *
111 * RETURN: Status
112 *
113 * DESCRIPTION: Implements a mutex wait with a check to see if the
114 * mutex is available immediately. If it is not, the
115 * interpreter is released before waiting.
116 *
117 ******************************************************************************/
118
119acpi_status acpi_ex_system_wait_mutex(acpi_mutex mutex, u16 timeout)
120{
121 acpi_status status;
122 acpi_status status2;
123
124 ACPI_FUNCTION_TRACE(ex_system_wait_mutex);
125
126 status = acpi_os_acquire_mutex(mutex, ACPI_DO_NOT_WAIT);
127 if (ACPI_SUCCESS(status)) {
128 return_ACPI_STATUS(status);
129 }
130
131 if (status == AE_TIME) {
132
133 /* We must wait, so unlock the interpreter */
134
135 acpi_ex_exit_interpreter();
136
137 status = acpi_os_acquire_mutex(mutex, timeout);
138
139 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
140 "*** Thread awake after blocking, %s\n",
141 acpi_format_exception(status)));
142
143 /* Reacquire the interpreter */
144
145 status2 = acpi_ex_enter_interpreter();
146 if (ACPI_FAILURE(status2)) {
147
148 /* Report fatal error, could not acquire interpreter */
149
150 return_ACPI_STATUS(status2);
151 }
152 }
153
154 return_ACPI_STATUS(status);
155}
156
157/*******************************************************************************
158 *
106 * FUNCTION: acpi_ex_system_do_stall 159 * FUNCTION: acpi_ex_system_do_stall
107 * 160 *
108 * PARAMETERS: how_long - The amount of time to stall, 161 * PARAMETERS: how_long - The amount of time to stall,
@@ -176,7 +229,7 @@ acpi_status acpi_ex_system_do_suspend(acpi_integer how_long)
176 * 229 *
177 * FUNCTION: acpi_ex_system_acquire_mutex 230 * FUNCTION: acpi_ex_system_acquire_mutex
178 * 231 *
179 * PARAMETERS: time_desc - The 'time to delay' object descriptor 232 * PARAMETERS: time_desc - Maximum time to wait for the mutex
180 * obj_desc - The object descriptor for this op 233 * obj_desc - The object descriptor for this op
181 * 234 *
182 * RETURN: Status 235 * RETURN: Status
@@ -201,14 +254,14 @@ acpi_ex_system_acquire_mutex(union acpi_operand_object * time_desc,
201 254
202 /* Support for the _GL_ Mutex object -- go get the global lock */ 255 /* Support for the _GL_ Mutex object -- go get the global lock */
203 256
204 if (obj_desc->mutex.semaphore == acpi_gbl_global_lock_semaphore) { 257 if (obj_desc->mutex.os_mutex == ACPI_GLOBAL_LOCK) {
205 status = 258 status =
206 acpi_ev_acquire_global_lock((u16) time_desc->integer.value); 259 acpi_ev_acquire_global_lock((u16) time_desc->integer.value);
207 return_ACPI_STATUS(status); 260 return_ACPI_STATUS(status);
208 } 261 }
209 262
210 status = acpi_ex_system_wait_semaphore(obj_desc->mutex.semaphore, 263 status = acpi_ex_system_wait_mutex(obj_desc->mutex.os_mutex,
211 (u16) time_desc->integer.value); 264 (u16) time_desc->integer.value);
212 return_ACPI_STATUS(status); 265 return_ACPI_STATUS(status);
213} 266}
214 267
@@ -239,13 +292,13 @@ acpi_status acpi_ex_system_release_mutex(union acpi_operand_object *obj_desc)
239 292
240 /* Support for the _GL_ Mutex object -- release the global lock */ 293 /* Support for the _GL_ Mutex object -- release the global lock */
241 294
242 if (obj_desc->mutex.semaphore == acpi_gbl_global_lock_semaphore) { 295 if (obj_desc->mutex.os_mutex == ACPI_GLOBAL_LOCK) {
243 status = acpi_ev_release_global_lock(); 296 status = acpi_ev_release_global_lock();
244 return_ACPI_STATUS(status); 297 return_ACPI_STATUS(status);
245 } 298 }
246 299
247 status = acpi_os_signal_semaphore(obj_desc->mutex.semaphore, 1); 300 acpi_os_release_mutex(obj_desc->mutex.os_mutex);
248 return_ACPI_STATUS(status); 301 return_ACPI_STATUS(AE_OK);
249} 302}
250 303
251/******************************************************************************* 304/*******************************************************************************
@@ -268,7 +321,8 @@ acpi_status acpi_ex_system_signal_event(union acpi_operand_object *obj_desc)
268 ACPI_FUNCTION_TRACE(ex_system_signal_event); 321 ACPI_FUNCTION_TRACE(ex_system_signal_event);
269 322
270 if (obj_desc) { 323 if (obj_desc) {
271 status = acpi_os_signal_semaphore(obj_desc->event.semaphore, 1); 324 status =
325 acpi_os_signal_semaphore(obj_desc->event.os_semaphore, 1);
272 } 326 }
273 327
274 return_ACPI_STATUS(status); 328 return_ACPI_STATUS(status);
@@ -299,7 +353,7 @@ acpi_ex_system_wait_event(union acpi_operand_object *time_desc,
299 353
300 if (obj_desc) { 354 if (obj_desc) {
301 status = 355 status =
302 acpi_ex_system_wait_semaphore(obj_desc->event.semaphore, 356 acpi_ex_system_wait_semaphore(obj_desc->event.os_semaphore,
303 (u16) time_desc->integer. 357 (u16) time_desc->integer.
304 value); 358 value);
305 } 359 }
@@ -322,7 +376,7 @@ acpi_ex_system_wait_event(union acpi_operand_object *time_desc,
322acpi_status acpi_ex_system_reset_event(union acpi_operand_object *obj_desc) 376acpi_status acpi_ex_system_reset_event(union acpi_operand_object *obj_desc)
323{ 377{
324 acpi_status status = AE_OK; 378 acpi_status status = AE_OK;
325 void *temp_semaphore; 379 acpi_semaphore temp_semaphore;
326 380
327 ACPI_FUNCTION_ENTRY(); 381 ACPI_FUNCTION_ENTRY();
328 382
@@ -333,8 +387,8 @@ acpi_status acpi_ex_system_reset_event(union acpi_operand_object *obj_desc)
333 status = 387 status =
334 acpi_os_create_semaphore(ACPI_NO_UNIT_LIMIT, 0, &temp_semaphore); 388 acpi_os_create_semaphore(ACPI_NO_UNIT_LIMIT, 0, &temp_semaphore);
335 if (ACPI_SUCCESS(status)) { 389 if (ACPI_SUCCESS(status)) {
336 (void)acpi_os_delete_semaphore(obj_desc->event.semaphore); 390 (void)acpi_os_delete_semaphore(obj_desc->event.os_semaphore);
337 obj_desc->event.semaphore = temp_semaphore; 391 obj_desc->event.os_semaphore = temp_semaphore;
338 } 392 }
339 393
340 return (status); 394 return (status);
diff --git a/drivers/acpi/fan.c b/drivers/acpi/fan.c
index 1cd25784b7a4..045c89477e59 100644
--- a/drivers/acpi/fan.c
+++ b/drivers/acpi/fan.c
@@ -64,7 +64,7 @@ static struct acpi_driver acpi_fan_driver = {
64}; 64};
65 65
66struct acpi_fan { 66struct acpi_fan {
67 acpi_handle handle; 67 struct acpi_device * device;
68}; 68};
69 69
70/* -------------------------------------------------------------------------- 70/* --------------------------------------------------------------------------
@@ -78,16 +78,15 @@ static int acpi_fan_read_state(struct seq_file *seq, void *offset)
78 struct acpi_fan *fan = seq->private; 78 struct acpi_fan *fan = seq->private;
79 int state = 0; 79 int state = 0;
80 80
81 ACPI_FUNCTION_TRACE("acpi_fan_read_state");
82 81
83 if (fan) { 82 if (fan) {
84 if (acpi_bus_get_power(fan->handle, &state)) 83 if (acpi_bus_get_power(fan->device->handle, &state))
85 seq_printf(seq, "status: ERROR\n"); 84 seq_printf(seq, "status: ERROR\n");
86 else 85 else
87 seq_printf(seq, "status: %s\n", 86 seq_printf(seq, "status: %s\n",
88 !state ? "on" : "off"); 87 !state ? "on" : "off");
89 } 88 }
90 return_VALUE(0); 89 return 0;
91} 90}
92 91
93static int acpi_fan_state_open_fs(struct inode *inode, struct file *file) 92static int acpi_fan_state_open_fs(struct inode *inode, struct file *file)
@@ -104,25 +103,24 @@ acpi_fan_write_state(struct file *file, const char __user * buffer,
104 struct acpi_fan *fan = (struct acpi_fan *)m->private; 103 struct acpi_fan *fan = (struct acpi_fan *)m->private;
105 char state_string[12] = { '\0' }; 104 char state_string[12] = { '\0' };
106 105
107 ACPI_FUNCTION_TRACE("acpi_fan_write_state");
108 106
109 if (!fan || (count > sizeof(state_string) - 1)) 107 if (!fan || (count > sizeof(state_string) - 1))
110 return_VALUE(-EINVAL); 108 return -EINVAL;
111 109
112 if (copy_from_user(state_string, buffer, count)) 110 if (copy_from_user(state_string, buffer, count))
113 return_VALUE(-EFAULT); 111 return -EFAULT;
114 112
115 state_string[count] = '\0'; 113 state_string[count] = '\0';
116 114
117 result = acpi_bus_set_power(fan->handle, 115 result = acpi_bus_set_power(fan->device->handle,
118 simple_strtoul(state_string, NULL, 0)); 116 simple_strtoul(state_string, NULL, 0));
119 if (result) 117 if (result)
120 return_VALUE(result); 118 return result;
121 119
122 return_VALUE(count); 120 return count;
123} 121}
124 122
125static struct file_operations acpi_fan_state_ops = { 123static const struct file_operations acpi_fan_state_ops = {
126 .open = acpi_fan_state_open_fs, 124 .open = acpi_fan_state_open_fs,
127 .read = seq_read, 125 .read = seq_read,
128 .write = acpi_fan_write_state, 126 .write = acpi_fan_write_state,
@@ -135,16 +133,15 @@ static int acpi_fan_add_fs(struct acpi_device *device)
135{ 133{
136 struct proc_dir_entry *entry = NULL; 134 struct proc_dir_entry *entry = NULL;
137 135
138 ACPI_FUNCTION_TRACE("acpi_fan_add_fs");
139 136
140 if (!device) 137 if (!device)
141 return_VALUE(-EINVAL); 138 return -EINVAL;
142 139
143 if (!acpi_device_dir(device)) { 140 if (!acpi_device_dir(device)) {
144 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), 141 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
145 acpi_fan_dir); 142 acpi_fan_dir);
146 if (!acpi_device_dir(device)) 143 if (!acpi_device_dir(device))
147 return_VALUE(-ENODEV); 144 return -ENODEV;
148 acpi_device_dir(device)->owner = THIS_MODULE; 145 acpi_device_dir(device)->owner = THIS_MODULE;
149 } 146 }
150 147
@@ -153,21 +150,18 @@ static int acpi_fan_add_fs(struct acpi_device *device)
153 S_IFREG | S_IRUGO | S_IWUSR, 150 S_IFREG | S_IRUGO | S_IWUSR,
154 acpi_device_dir(device)); 151 acpi_device_dir(device));
155 if (!entry) 152 if (!entry)
156 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 153 return -ENODEV;
157 "Unable to create '%s' fs entry\n",
158 ACPI_FAN_FILE_STATE));
159 else { 154 else {
160 entry->proc_fops = &acpi_fan_state_ops; 155 entry->proc_fops = &acpi_fan_state_ops;
161 entry->data = acpi_driver_data(device); 156 entry->data = acpi_driver_data(device);
162 entry->owner = THIS_MODULE; 157 entry->owner = THIS_MODULE;
163 } 158 }
164 159
165 return_VALUE(0); 160 return 0;
166} 161}
167 162
168static int acpi_fan_remove_fs(struct acpi_device *device) 163static int acpi_fan_remove_fs(struct acpi_device *device)
169{ 164{
170 ACPI_FUNCTION_TRACE("acpi_fan_remove_fs");
171 165
172 if (acpi_device_dir(device)) { 166 if (acpi_device_dir(device)) {
173 remove_proc_entry(ACPI_FAN_FILE_STATE, acpi_device_dir(device)); 167 remove_proc_entry(ACPI_FAN_FILE_STATE, acpi_device_dir(device));
@@ -175,7 +169,7 @@ static int acpi_fan_remove_fs(struct acpi_device *device)
175 acpi_device_dir(device) = NULL; 169 acpi_device_dir(device) = NULL;
176 } 170 }
177 171
178 return_VALUE(0); 172 return 0;
179} 173}
180 174
181/* -------------------------------------------------------------------------- 175/* --------------------------------------------------------------------------
@@ -188,25 +182,23 @@ static int acpi_fan_add(struct acpi_device *device)
188 struct acpi_fan *fan = NULL; 182 struct acpi_fan *fan = NULL;
189 int state = 0; 183 int state = 0;
190 184
191 ACPI_FUNCTION_TRACE("acpi_fan_add");
192 185
193 if (!device) 186 if (!device)
194 return_VALUE(-EINVAL); 187 return -EINVAL;
195 188
196 fan = kmalloc(sizeof(struct acpi_fan), GFP_KERNEL); 189 fan = kmalloc(sizeof(struct acpi_fan), GFP_KERNEL);
197 if (!fan) 190 if (!fan)
198 return_VALUE(-ENOMEM); 191 return -ENOMEM;
199 memset(fan, 0, sizeof(struct acpi_fan)); 192 memset(fan, 0, sizeof(struct acpi_fan));
200 193
201 fan->handle = device->handle; 194 fan->device = device;
202 strcpy(acpi_device_name(device), "Fan"); 195 strcpy(acpi_device_name(device), "Fan");
203 strcpy(acpi_device_class(device), ACPI_FAN_CLASS); 196 strcpy(acpi_device_class(device), ACPI_FAN_CLASS);
204 acpi_driver_data(device) = fan; 197 acpi_driver_data(device) = fan;
205 198
206 result = acpi_bus_get_power(fan->handle, &state); 199 result = acpi_bus_get_power(device->handle, &state);
207 if (result) { 200 if (result) {
208 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 201 printk(KERN_ERR PREFIX "Reading power state\n");
209 "Error reading power state\n"));
210 goto end; 202 goto end;
211 } 203 }
212 204
@@ -226,17 +218,16 @@ static int acpi_fan_add(struct acpi_device *device)
226 if (result) 218 if (result)
227 kfree(fan); 219 kfree(fan);
228 220
229 return_VALUE(result); 221 return result;
230} 222}
231 223
232static int acpi_fan_remove(struct acpi_device *device, int type) 224static int acpi_fan_remove(struct acpi_device *device, int type)
233{ 225{
234 struct acpi_fan *fan = NULL; 226 struct acpi_fan *fan = NULL;
235 227
236 ACPI_FUNCTION_TRACE("acpi_fan_remove");
237 228
238 if (!device || !acpi_driver_data(device)) 229 if (!device || !acpi_driver_data(device))
239 return_VALUE(-EINVAL); 230 return -EINVAL;
240 231
241 fan = (struct acpi_fan *)acpi_driver_data(device); 232 fan = (struct acpi_fan *)acpi_driver_data(device);
242 233
@@ -244,7 +235,7 @@ static int acpi_fan_remove(struct acpi_device *device, int type)
244 235
245 kfree(fan); 236 kfree(fan);
246 237
247 return_VALUE(0); 238 return 0;
248} 239}
249 240
250static int acpi_fan_suspend(struct acpi_device *device, int state) 241static int acpi_fan_suspend(struct acpi_device *device, int state)
@@ -283,31 +274,29 @@ static int __init acpi_fan_init(void)
283{ 274{
284 int result = 0; 275 int result = 0;
285 276
286 ACPI_FUNCTION_TRACE("acpi_fan_init");
287 277
288 acpi_fan_dir = proc_mkdir(ACPI_FAN_CLASS, acpi_root_dir); 278 acpi_fan_dir = proc_mkdir(ACPI_FAN_CLASS, acpi_root_dir);
289 if (!acpi_fan_dir) 279 if (!acpi_fan_dir)
290 return_VALUE(-ENODEV); 280 return -ENODEV;
291 acpi_fan_dir->owner = THIS_MODULE; 281 acpi_fan_dir->owner = THIS_MODULE;
292 282
293 result = acpi_bus_register_driver(&acpi_fan_driver); 283 result = acpi_bus_register_driver(&acpi_fan_driver);
294 if (result < 0) { 284 if (result < 0) {
295 remove_proc_entry(ACPI_FAN_CLASS, acpi_root_dir); 285 remove_proc_entry(ACPI_FAN_CLASS, acpi_root_dir);
296 return_VALUE(-ENODEV); 286 return -ENODEV;
297 } 287 }
298 288
299 return_VALUE(0); 289 return 0;
300} 290}
301 291
302static void __exit acpi_fan_exit(void) 292static void __exit acpi_fan_exit(void)
303{ 293{
304 ACPI_FUNCTION_TRACE("acpi_fan_exit");
305 294
306 acpi_bus_unregister_driver(&acpi_fan_driver); 295 acpi_bus_unregister_driver(&acpi_fan_driver);
307 296
308 remove_proc_entry(ACPI_FAN_CLASS, acpi_root_dir); 297 remove_proc_entry(ACPI_FAN_CLASS, acpi_root_dir);
309 298
310 return_VOID; 299 return;
311} 300}
312 301
313module_init(acpi_fan_init); 302module_init(acpi_fan_init);
diff --git a/drivers/acpi/glue.c b/drivers/acpi/glue.c
index 8daef57b994c..10f160dc75b1 100644
--- a/drivers/acpi/glue.c
+++ b/drivers/acpi/glue.c
@@ -152,7 +152,7 @@ static int get_root_bridge_busnr(acpi_handle handle)
152 bbn = bus; 152 bbn = bus;
153 } 153 }
154 exit: 154 exit:
155 acpi_os_free(buffer.pointer); 155 kfree(buffer.pointer);
156 return (int)bbn; 156 return (int)bbn;
157} 157}
158 158
@@ -192,7 +192,7 @@ find_pci_rootbridge(acpi_handle handle, u32 lvl, void *context, void **rv)
192 find->handle = handle; 192 find->handle = handle;
193 status = AE_OK; 193 status = AE_OK;
194 exit: 194 exit:
195 acpi_os_free(buffer.pointer); 195 kfree(buffer.pointer);
196 return status; 196 return status;
197} 197}
198 198
@@ -224,7 +224,7 @@ do_acpi_find_child(acpi_handle handle, u32 lvl, void *context, void **rv)
224 info = buffer.pointer; 224 info = buffer.pointer;
225 if (info->address == find->address) 225 if (info->address == find->address)
226 find->handle = handle; 226 find->handle = handle;
227 acpi_os_free(buffer.pointer); 227 kfree(buffer.pointer);
228 } 228 }
229 return AE_OK; 229 return AE_OK;
230} 230}
@@ -330,7 +330,7 @@ static int acpi_platform_notify(struct device *dev)
330 330
331 acpi_get_name(dev->firmware_data, ACPI_FULL_PATHNAME, &buffer); 331 acpi_get_name(dev->firmware_data, ACPI_FULL_PATHNAME, &buffer);
332 DBG("Device %s -> %s\n", dev->bus_id, (char *)buffer.pointer); 332 DBG("Device %s -> %s\n", dev->bus_id, (char *)buffer.pointer);
333 acpi_os_free(buffer.pointer); 333 kfree(buffer.pointer);
334 } else 334 } else
335 DBG("Device %s -> No ACPI support\n", dev->bus_id); 335 DBG("Device %s -> No ACPI support\n", dev->bus_id);
336#endif 336#endif
diff --git a/drivers/acpi/hardware/hwregs.c b/drivers/acpi/hardware/hwregs.c
index ae142de19507..3143f36fcec9 100644
--- a/drivers/acpi/hardware/hwregs.c
+++ b/drivers/acpi/hardware/hwregs.c
@@ -172,9 +172,9 @@ acpi_get_sleep_type_data(u8 sleep_state, u8 * sleep_type_a, u8 * sleep_type_b)
172 } 172 }
173 173
174 /* 174 /*
175 * The package must have at least two elements. NOTE (March 2005): This 175 * The package must have at least two elements. NOTE (March 2005): This
176 * goes against the current ACPI spec which defines this object as a 176 * goes against the current ACPI spec which defines this object as a
177 * package with one encoded DWORD element. However, existing practice 177 * package with one encoded DWORD element. However, existing practice
178 * by BIOS vendors seems to be to have 2 or more elements, at least 178 * by BIOS vendors seems to be to have 2 or more elements, at least
179 * one per sleep type (A/B). 179 * one per sleep type (A/B).
180 */ 180 */
@@ -255,7 +255,7 @@ struct acpi_bit_register_info *acpi_hw_get_bit_register_info(u32 register_id)
255 * return_value - Value that was read from the register 255 * return_value - Value that was read from the register
256 * Flags - Lock the hardware or not 256 * Flags - Lock the hardware or not
257 * 257 *
258 * RETURN: Status and the value read from specified Register. Value 258 * RETURN: Status and the value read from specified Register. Value
259 * returned is normalized to bit0 (is shifted all the way right) 259 * returned is normalized to bit0 (is shifted all the way right)
260 * 260 *
261 * DESCRIPTION: ACPI bit_register read function. 261 * DESCRIPTION: ACPI bit_register read function.
@@ -361,8 +361,8 @@ acpi_status acpi_set_register(u32 register_id, u32 value, u32 flags)
361 case ACPI_REGISTER_PM1_STATUS: 361 case ACPI_REGISTER_PM1_STATUS:
362 362
363 /* 363 /*
364 * Status Registers are different from the rest. Clear by 364 * Status Registers are different from the rest. Clear by
365 * writing 1, and writing 0 has no effect. So, the only relevant 365 * writing 1, and writing 0 has no effect. So, the only relevant
366 * information is the single bit we're interested in, all others should 366 * information is the single bit we're interested in, all others should
367 * be written as 0 so they will be left unchanged. 367 * be written as 0 so they will be left unchanged.
368 */ 368 */
@@ -467,14 +467,13 @@ ACPI_EXPORT_SYMBOL(acpi_set_register)
467 * 467 *
468 * FUNCTION: acpi_hw_register_read 468 * FUNCTION: acpi_hw_register_read
469 * 469 *
470 * PARAMETERS: use_lock - Mutex hw access 470 * PARAMETERS: use_lock - Lock hardware? True/False
471 * register_id - register_iD + Offset 471 * register_id - ACPI Register ID
472 * return_value - Where the register value is returned 472 * return_value - Where the register value is returned
473 * 473 *
474 * RETURN: Status and the value read. 474 * RETURN: Status and the value read.
475 * 475 *
476 * DESCRIPTION: Acpi register read function. Registers are read at the 476 * DESCRIPTION: Read from the specified ACPI register
477 * given offset.
478 * 477 *
479 ******************************************************************************/ 478 ******************************************************************************/
480acpi_status 479acpi_status
@@ -580,14 +579,26 @@ acpi_hw_register_read(u8 use_lock, u32 register_id, u32 * return_value)
580 * 579 *
581 * FUNCTION: acpi_hw_register_write 580 * FUNCTION: acpi_hw_register_write
582 * 581 *
583 * PARAMETERS: use_lock - Mutex hw access 582 * PARAMETERS: use_lock - Lock hardware? True/False
584 * register_id - register_iD + Offset 583 * register_id - ACPI Register ID
585 * Value - The value to write 584 * Value - The value to write
586 * 585 *
587 * RETURN: Status 586 * RETURN: Status
588 * 587 *
589 * DESCRIPTION: Acpi register Write function. Registers are written at the 588 * DESCRIPTION: Write to the specified ACPI register
590 * given offset. 589 *
590 * NOTE: In accordance with the ACPI specification, this function automatically
591 * preserves the value of the following bits, meaning that these bits cannot be
592 * changed via this interface:
593 *
594 * PM1_CONTROL[0] = SCI_EN
595 * PM1_CONTROL[9]
596 * PM1_STATUS[11]
597 *
598 * ACPI References:
599 * 1) Hardware Ignored Bits: When software writes to a register with ignored
600 * bit fields, it preserves the ignored bit fields
601 * 2) SCI_EN: OSPM always preserves this bit position
591 * 602 *
592 ******************************************************************************/ 603 ******************************************************************************/
593 604
@@ -595,6 +606,7 @@ acpi_status acpi_hw_register_write(u8 use_lock, u32 register_id, u32 value)
595{ 606{
596 acpi_status status; 607 acpi_status status;
597 acpi_cpu_flags lock_flags = 0; 608 acpi_cpu_flags lock_flags = 0;
609 u32 read_value;
598 610
599 ACPI_FUNCTION_TRACE(hw_register_write); 611 ACPI_FUNCTION_TRACE(hw_register_write);
600 612
@@ -605,6 +617,22 @@ acpi_status acpi_hw_register_write(u8 use_lock, u32 register_id, u32 value)
605 switch (register_id) { 617 switch (register_id) {
606 case ACPI_REGISTER_PM1_STATUS: /* 16-bit access */ 618 case ACPI_REGISTER_PM1_STATUS: /* 16-bit access */
607 619
620 /* Perform a read first to preserve certain bits (per ACPI spec) */
621
622 status = acpi_hw_register_read(ACPI_MTX_DO_NOT_LOCK,
623 ACPI_REGISTER_PM1_STATUS,
624 &read_value);
625 if (ACPI_FAILURE(status)) {
626 goto unlock_and_exit;
627 }
628
629 /* Insert the bits to be preserved */
630
631 ACPI_INSERT_BITS(value, ACPI_PM1_STATUS_PRESERVED_BITS,
632 read_value);
633
634 /* Now we can write the data */
635
608 status = 636 status =
609 acpi_hw_low_level_write(16, value, 637 acpi_hw_low_level_write(16, value,
610 &acpi_gbl_FADT->xpm1a_evt_blk); 638 &acpi_gbl_FADT->xpm1a_evt_blk);
@@ -635,6 +663,25 @@ acpi_status acpi_hw_register_write(u8 use_lock, u32 register_id, u32 value)
635 663
636 case ACPI_REGISTER_PM1_CONTROL: /* 16-bit access */ 664 case ACPI_REGISTER_PM1_CONTROL: /* 16-bit access */
637 665
666 /*
667 * Perform a read first to preserve certain bits (per ACPI spec)
668 *
669 * Note: This includes SCI_EN, we never want to change this bit
670 */
671 status = acpi_hw_register_read(ACPI_MTX_DO_NOT_LOCK,
672 ACPI_REGISTER_PM1_CONTROL,
673 &read_value);
674 if (ACPI_FAILURE(status)) {
675 goto unlock_and_exit;
676 }
677
678 /* Insert the bits to be preserved */
679
680 ACPI_INSERT_BITS(value, ACPI_PM1_CONTROL_PRESERVED_BITS,
681 read_value);
682
683 /* Now we can write the data */
684
638 status = 685 status =
639 acpi_hw_low_level_write(16, value, 686 acpi_hw_low_level_write(16, value,
640 &acpi_gbl_FADT->xpm1a_cnt_blk); 687 &acpi_gbl_FADT->xpm1a_cnt_blk);
@@ -726,7 +773,7 @@ acpi_hw_low_level_read(u32 width, u32 * value, struct acpi_generic_address *reg)
726 return (AE_OK); 773 return (AE_OK);
727 } 774 }
728 775
729 /* Get a local copy of the address. Handles possible alignment issues */ 776 /* Get a local copy of the address. Handles possible alignment issues */
730 777
731 ACPI_MOVE_64_TO_64(&address, &reg->address); 778 ACPI_MOVE_64_TO_64(&address, &reg->address);
732 if (!address) { 779 if (!address) {
@@ -798,7 +845,7 @@ acpi_hw_low_level_write(u32 width, u32 value, struct acpi_generic_address * reg)
798 return (AE_OK); 845 return (AE_OK);
799 } 846 }
800 847
801 /* Get a local copy of the address. Handles possible alignment issues */ 848 /* Get a local copy of the address. Handles possible alignment issues */
802 849
803 ACPI_MOVE_64_TO_64(&address, &reg->address); 850 ACPI_MOVE_64_TO_64(&address, &reg->address);
804 if (!address) { 851 if (!address) {
diff --git a/drivers/acpi/hotkey.c b/drivers/acpi/hotkey.c
index c25b2b92edcf..1ba2db671865 100644
--- a/drivers/acpi/hotkey.c
+++ b/drivers/acpi/hotkey.c
@@ -91,6 +91,14 @@ enum {
91 HK_EVENT_ENTERRING_S5, 91 HK_EVENT_ENTERRING_S5,
92}; 92};
93 93
94enum conf_entry_enum {
95 bus_handle = 0,
96 bus_method = 1,
97 action_handle = 2,
98 method = 3,
99 LAST_CONF_ENTRY
100};
101
94/* procdir we use */ 102/* procdir we use */
95static struct proc_dir_entry *hotkey_proc_dir; 103static struct proc_dir_entry *hotkey_proc_dir;
96static struct proc_dir_entry *hotkey_config; 104static struct proc_dir_entry *hotkey_config;
@@ -184,7 +192,7 @@ static union acpi_hotkey *get_hotkey_by_event(struct
184 *hotkey_list, int event); 192 *hotkey_list, int event);
185 193
186/* event based config */ 194/* event based config */
187static struct file_operations hotkey_config_fops = { 195static const struct file_operations hotkey_config_fops = {
188 .open = hotkey_open_config, 196 .open = hotkey_open_config,
189 .read = seq_read, 197 .read = seq_read,
190 .write = hotkey_write_config, 198 .write = hotkey_write_config,
@@ -193,7 +201,7 @@ static struct file_operations hotkey_config_fops = {
193}; 201};
194 202
195/* polling based config */ 203/* polling based config */
196static struct file_operations hotkey_poll_config_fops = { 204static const struct file_operations hotkey_poll_config_fops = {
197 .open = hotkey_poll_open_config, 205 .open = hotkey_poll_open_config,
198 .read = seq_read, 206 .read = seq_read,
199 .write = hotkey_write_config, 207 .write = hotkey_write_config,
@@ -202,7 +210,7 @@ static struct file_operations hotkey_poll_config_fops = {
202}; 210};
203 211
204/* hotkey driver info */ 212/* hotkey driver info */
205static struct file_operations hotkey_info_fops = { 213static const struct file_operations hotkey_info_fops = {
206 .open = hotkey_info_open_fs, 214 .open = hotkey_info_open_fs,
207 .read = seq_read, 215 .read = seq_read,
208 .llseek = seq_lseek, 216 .llseek = seq_lseek,
@@ -210,7 +218,7 @@ static struct file_operations hotkey_info_fops = {
210}; 218};
211 219
212/* action */ 220/* action */
213static struct file_operations hotkey_action_fops = { 221static const struct file_operations hotkey_action_fops = {
214 .open = hotkey_action_open_fs, 222 .open = hotkey_action_open_fs,
215 .read = seq_read, 223 .read = seq_read,
216 .write = hotkey_execute_aml_method, 224 .write = hotkey_execute_aml_method,
@@ -219,7 +227,7 @@ static struct file_operations hotkey_action_fops = {
219}; 227};
220 228
221/* polling results */ 229/* polling results */
222static struct file_operations hotkey_polling_fops = { 230static const struct file_operations hotkey_polling_fops = {
223 .open = hotkey_polling_open_fs, 231 .open = hotkey_polling_open_fs,
224 .read = seq_read, 232 .read = seq_read,
225 .llseek = seq_lseek, 233 .llseek = seq_lseek,
@@ -231,11 +239,10 @@ struct list_head hotkey_entries; /* head of the list of hotkey_list */
231 239
232static int hotkey_info_seq_show(struct seq_file *seq, void *offset) 240static int hotkey_info_seq_show(struct seq_file *seq, void *offset)
233{ 241{
234 ACPI_FUNCTION_TRACE("hotkey_info_seq_show");
235 242
236 seq_printf(seq, "Hotkey generic driver ver: %s\n", HOTKEY_ACPI_VERSION); 243 seq_printf(seq, "Hotkey generic driver ver: %s\n", HOTKEY_ACPI_VERSION);
237 244
238 return_VALUE(0); 245 return 0;
239} 246}
240 247
241static int hotkey_info_open_fs(struct inode *inode, struct file *file) 248static int hotkey_info_open_fs(struct inode *inode, struct file *file)
@@ -245,19 +252,15 @@ static int hotkey_info_open_fs(struct inode *inode, struct file *file)
245 252
246static char *format_result(union acpi_object *object) 253static char *format_result(union acpi_object *object)
247{ 254{
248 char *buf = NULL; 255 char *buf;
249
250 buf = (char *)kmalloc(RESULT_STR_LEN, GFP_KERNEL);
251 if (buf)
252 memset(buf, 0, RESULT_STR_LEN);
253 else
254 goto do_fail;
255 256
257 buf = kzalloc(RESULT_STR_LEN, GFP_KERNEL);
258 if (!buf)
259 return NULL;
256 /* Now, just support integer type */ 260 /* Now, just support integer type */
257 if (object->type == ACPI_TYPE_INTEGER) 261 if (object->type == ACPI_TYPE_INTEGER)
258 sprintf(buf, "%d\n", (u32) object->integer.value); 262 sprintf(buf, "%d\n", (u32) object->integer.value);
259 do_fail: 263 return buf;
260 return (buf);
261} 264}
262 265
263static int hotkey_polling_seq_show(struct seq_file *seq, void *offset) 266static int hotkey_polling_seq_show(struct seq_file *seq, void *offset)
@@ -266,7 +269,6 @@ static int hotkey_polling_seq_show(struct seq_file *seq, void *offset)
266 (struct acpi_polling_hotkey *)seq->private; 269 (struct acpi_polling_hotkey *)seq->private;
267 char *buf; 270 char *buf;
268 271
269 ACPI_FUNCTION_TRACE("hotkey_polling_seq_show");
270 272
271 if (poll_hotkey->poll_result) { 273 if (poll_hotkey->poll_result) {
272 buf = format_result(poll_hotkey->poll_result); 274 buf = format_result(poll_hotkey->poll_result);
@@ -274,7 +276,7 @@ static int hotkey_polling_seq_show(struct seq_file *seq, void *offset)
274 seq_printf(seq, "%s", buf); 276 seq_printf(seq, "%s", buf);
275 kfree(buf); 277 kfree(buf);
276 } 278 }
277 return_VALUE(0); 279 return 0;
278} 280}
279 281
280static int hotkey_polling_open_fs(struct inode *inode, struct file *file) 282static int hotkey_polling_open_fs(struct inode *inode, struct file *file)
@@ -293,7 +295,6 @@ static int hotkey_get_internal_event(int event, struct acpi_hotkey_list *list)
293 struct list_head *entries; 295 struct list_head *entries;
294 int val = -1; 296 int val = -1;
295 297
296 ACPI_FUNCTION_TRACE("hotkey_get_internal_event");
297 298
298 list_for_each(entries, list->entries) { 299 list_for_each(entries, list->entries) {
299 union acpi_hotkey *key = 300 union acpi_hotkey *key =
@@ -305,7 +306,7 @@ static int hotkey_get_internal_event(int event, struct acpi_hotkey_list *list)
305 } 306 }
306 } 307 }
307 308
308 return_VALUE(val); 309 return val;
309} 310}
310 311
311static void 312static void
@@ -314,15 +315,14 @@ acpi_hotkey_notify_handler(acpi_handle handle, u32 event, void *data)
314 struct acpi_device *device = NULL; 315 struct acpi_device *device = NULL;
315 u32 internal_event; 316 u32 internal_event;
316 317
317 ACPI_FUNCTION_TRACE("acpi_hotkey_notify_handler");
318 318
319 if (acpi_bus_get_device(handle, &device)) 319 if (acpi_bus_get_device(handle, &device))
320 return_VOID; 320 return;
321 321
322 internal_event = hotkey_get_internal_event(event, &global_hotkey_list); 322 internal_event = hotkey_get_internal_event(event, &global_hotkey_list);
323 acpi_bus_generate_event(device, internal_event, 0); 323 acpi_bus_generate_event(device, internal_event, 0);
324 324
325 return_VOID; 325 return;
326} 326}
327 327
328/* Need to invent automatically hotkey add method */ 328/* Need to invent automatically hotkey add method */
@@ -346,7 +346,6 @@ static int create_polling_proc(union acpi_hotkey *device)
346 char proc_name[80]; 346 char proc_name[80];
347 mode_t mode; 347 mode_t mode;
348 348
349 ACPI_FUNCTION_TRACE("create_polling_proc");
350 mode = S_IFREG | S_IRUGO | S_IWUGO; 349 mode = S_IFREG | S_IRUGO | S_IWUGO;
351 350
352 sprintf(proc_name, "%d", device->link.hotkey_standard_num); 351 sprintf(proc_name, "%d", device->link.hotkey_standard_num);
@@ -356,10 +355,7 @@ static int create_polling_proc(union acpi_hotkey *device)
356 proc = create_proc_entry(proc_name, mode, hotkey_proc_dir); 355 proc = create_proc_entry(proc_name, mode, hotkey_proc_dir);
357 356
358 if (!proc) { 357 if (!proc) {
359 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 358 return -ENODEV;
360 "Hotkey: Unable to create %s entry\n",
361 device->poll_hotkey.poll_method));
362 return_VALUE(-ENODEV);
363 } else { 359 } else {
364 proc->proc_fops = &hotkey_polling_fops; 360 proc->proc_fops = &hotkey_polling_fops;
365 proc->owner = THIS_MODULE; 361 proc->owner = THIS_MODULE;
@@ -368,7 +364,7 @@ static int create_polling_proc(union acpi_hotkey *device)
368 proc->gid = 0; 364 proc->gid = 0;
369 device->poll_hotkey.proc = proc; 365 device->poll_hotkey.proc = proc;
370 } 366 }
371 return_VALUE(0); 367 return 0;
372} 368}
373 369
374static int hotkey_add(union acpi_hotkey *device) 370static int hotkey_add(union acpi_hotkey *device)
@@ -376,7 +372,6 @@ static int hotkey_add(union acpi_hotkey *device)
376 int status = 0; 372 int status = 0;
377 struct acpi_device *dev = NULL; 373 struct acpi_device *dev = NULL;
378 374
379 ACPI_FUNCTION_TRACE("hotkey_add");
380 375
381 if (device->link.hotkey_type == ACPI_HOTKEY_EVENT) { 376 if (device->link.hotkey_type == ACPI_HOTKEY_EVENT) {
382 acpi_bus_get_device(device->event_hotkey.bus_handle, &dev); 377 acpi_bus_get_device(device->event_hotkey.bus_handle, &dev);
@@ -391,14 +386,13 @@ static int hotkey_add(union acpi_hotkey *device)
391 386
392 list_add_tail(&device->link.entries, global_hotkey_list.entries); 387 list_add_tail(&device->link.entries, global_hotkey_list.entries);
393 388
394 return_VALUE(status); 389 return status;
395} 390}
396 391
397static int hotkey_remove(union acpi_hotkey *device) 392static int hotkey_remove(union acpi_hotkey *device)
398{ 393{
399 struct list_head *entries, *next; 394 struct list_head *entries, *next;
400 395
401 ACPI_FUNCTION_TRACE("hotkey_remove");
402 396
403 list_for_each_safe(entries, next, global_hotkey_list.entries) { 397 list_for_each_safe(entries, next, global_hotkey_list.entries) {
404 union acpi_hotkey *key = 398 union acpi_hotkey *key =
@@ -412,14 +406,13 @@ static int hotkey_remove(union acpi_hotkey *device)
412 } 406 }
413 } 407 }
414 kfree(device); 408 kfree(device);
415 return_VALUE(0); 409 return 0;
416} 410}
417 411
418static int hotkey_update(union acpi_hotkey *key) 412static int hotkey_update(union acpi_hotkey *key)
419{ 413{
420 struct list_head *entries; 414 struct list_head *entries;
421 415
422 ACPI_FUNCTION_TRACE("hotkey_update");
423 416
424 list_for_each(entries, global_hotkey_list.entries) { 417 list_for_each(entries, global_hotkey_list.entries) {
425 union acpi_hotkey *tmp = 418 union acpi_hotkey *tmp =
@@ -461,19 +454,18 @@ static int hotkey_update(union acpi_hotkey *key)
461 */ 454 */
462 kfree(key); 455 kfree(key);
463 } 456 }
464 return_VALUE(0); 457 return 0;
465 break; 458 break;
466 } 459 }
467 } 460 }
468 461
469 return_VALUE(-ENODEV); 462 return -ENODEV;
470} 463}
471 464
472static void free_hotkey_device(union acpi_hotkey *key) 465static void free_hotkey_device(union acpi_hotkey *key)
473{ 466{
474 struct acpi_device *dev; 467 struct acpi_device *dev;
475 468
476 ACPI_FUNCTION_TRACE("free_hotkey_device");
477 469
478 if (key->link.hotkey_type == ACPI_HOTKEY_EVENT) { 470 if (key->link.hotkey_type == ACPI_HOTKEY_EVENT) {
479 acpi_bus_get_device(key->event_hotkey.bus_handle, &dev); 471 acpi_bus_get_device(key->event_hotkey.bus_handle, &dev);
@@ -493,119 +485,119 @@ static void free_hotkey_device(union acpi_hotkey *key)
493 free_poll_hotkey_buffer(key); 485 free_poll_hotkey_buffer(key);
494 } 486 }
495 kfree(key); 487 kfree(key);
496 return_VOID; 488 return;
497} 489}
498 490
499static void free_hotkey_buffer(union acpi_hotkey *key) 491static void free_hotkey_buffer(union acpi_hotkey *key)
500{ 492{
493 /* key would never be null, action method could be */
501 kfree(key->event_hotkey.action_method); 494 kfree(key->event_hotkey.action_method);
502} 495}
503 496
504static void free_poll_hotkey_buffer(union acpi_hotkey *key) 497static void free_poll_hotkey_buffer(union acpi_hotkey *key)
505{ 498{
499 /* key would never be null, others could be*/
506 kfree(key->poll_hotkey.action_method); 500 kfree(key->poll_hotkey.action_method);
507 kfree(key->poll_hotkey.poll_method); 501 kfree(key->poll_hotkey.poll_method);
508 kfree(key->poll_hotkey.poll_result); 502 kfree(key->poll_hotkey.poll_result);
509} 503}
510static int 504static int
511init_hotkey_device(union acpi_hotkey *key, char *bus_str, char *action_str, 505init_hotkey_device(union acpi_hotkey *key, char **config_entry,
512 char *method, int std_num, int external_num) 506 int std_num, int external_num)
513{ 507{
514 acpi_handle tmp_handle; 508 acpi_handle tmp_handle;
515 acpi_status status = AE_OK; 509 acpi_status status = AE_OK;
516 510
517 ACPI_FUNCTION_TRACE("init_hotkey_device");
518
519 if (std_num < 0 || IS_POLL(std_num) || !key) 511 if (std_num < 0 || IS_POLL(std_num) || !key)
520 goto do_fail; 512 goto do_fail;
521 513
522 if (!bus_str || !action_str || !method) 514 if (!config_entry[bus_handle] || !config_entry[action_handle]
515 || !config_entry[method])
523 goto do_fail; 516 goto do_fail;
524 517
525 key->link.hotkey_type = ACPI_HOTKEY_EVENT; 518 key->link.hotkey_type = ACPI_HOTKEY_EVENT;
526 key->link.hotkey_standard_num = std_num; 519 key->link.hotkey_standard_num = std_num;
527 key->event_hotkey.flag = 0; 520 key->event_hotkey.flag = 0;
528 key->event_hotkey.action_method = method; 521 key->event_hotkey.action_method = config_entry[method];
529 522
530 status = 523 status = acpi_get_handle(NULL, config_entry[bus_handle],
531 acpi_get_handle(NULL, bus_str, &(key->event_hotkey.bus_handle)); 524 &(key->event_hotkey.bus_handle));
532 if (ACPI_FAILURE(status)) 525 if (ACPI_FAILURE(status))
533 goto do_fail; 526 goto do_fail_zero;
534 key->event_hotkey.external_hotkey_num = external_num; 527 key->event_hotkey.external_hotkey_num = external_num;
535 status = 528 status = acpi_get_handle(NULL, config_entry[action_handle],
536 acpi_get_handle(NULL, action_str,
537 &(key->event_hotkey.action_handle)); 529 &(key->event_hotkey.action_handle));
538 if (ACPI_FAILURE(status)) 530 if (ACPI_FAILURE(status))
539 goto do_fail; 531 goto do_fail_zero;
540 status = acpi_get_handle(key->event_hotkey.action_handle, 532 status = acpi_get_handle(key->event_hotkey.action_handle,
541 method, &tmp_handle); 533 config_entry[method], &tmp_handle);
542 if (ACPI_FAILURE(status)) 534 if (ACPI_FAILURE(status))
543 goto do_fail; 535 goto do_fail_zero;
544 return_VALUE(AE_OK); 536 return AE_OK;
545 do_fail: 537do_fail_zero:
546 return_VALUE(-ENODEV); 538 key->event_hotkey.action_method = NULL;
539do_fail:
540 return -ENODEV;
547} 541}
548 542
549static int 543static int
550init_poll_hotkey_device(union acpi_hotkey *key, 544init_poll_hotkey_device(union acpi_hotkey *key, char **config_entry,
551 char *poll_str, 545 int std_num)
552 char *poll_method,
553 char *action_str, char *action_method, int std_num)
554{ 546{
555 acpi_status status = AE_OK; 547 acpi_status status = AE_OK;
556 acpi_handle tmp_handle; 548 acpi_handle tmp_handle;
557 549
558 ACPI_FUNCTION_TRACE("init_poll_hotkey_device");
559
560 if (std_num < 0 || IS_EVENT(std_num) || !key) 550 if (std_num < 0 || IS_EVENT(std_num) || !key)
561 goto do_fail; 551 goto do_fail;
562 552 if (!config_entry[bus_handle] ||!config_entry[bus_method] ||
563 if (!poll_str || !poll_method || !action_str || !action_method) 553 !config_entry[action_handle] || !config_entry[method])
564 goto do_fail; 554 goto do_fail;
565 555
566 key->link.hotkey_type = ACPI_HOTKEY_POLLING; 556 key->link.hotkey_type = ACPI_HOTKEY_POLLING;
567 key->link.hotkey_standard_num = std_num; 557 key->link.hotkey_standard_num = std_num;
568 key->poll_hotkey.flag = 0; 558 key->poll_hotkey.flag = 0;
569 key->poll_hotkey.poll_method = poll_method; 559 key->poll_hotkey.poll_method = config_entry[bus_method];
570 key->poll_hotkey.action_method = action_method; 560 key->poll_hotkey.action_method = config_entry[method];
571 561
572 status = 562 status = acpi_get_handle(NULL, config_entry[bus_handle],
573 acpi_get_handle(NULL, poll_str, &(key->poll_hotkey.poll_handle)); 563 &(key->poll_hotkey.poll_handle));
574 if (ACPI_FAILURE(status)) 564 if (ACPI_FAILURE(status))
575 goto do_fail; 565 goto do_fail_zero;
576 status = acpi_get_handle(key->poll_hotkey.poll_handle, 566 status = acpi_get_handle(key->poll_hotkey.poll_handle,
577 poll_method, &tmp_handle); 567 config_entry[bus_method], &tmp_handle);
578 if (ACPI_FAILURE(status)) 568 if (ACPI_FAILURE(status))
579 goto do_fail; 569 goto do_fail_zero;
580 status = 570 status =
581 acpi_get_handle(NULL, action_str, 571 acpi_get_handle(NULL, config_entry[action_handle],
582 &(key->poll_hotkey.action_handle)); 572 &(key->poll_hotkey.action_handle));
583 if (ACPI_FAILURE(status)) 573 if (ACPI_FAILURE(status))
584 goto do_fail; 574 goto do_fail_zero;
585 status = acpi_get_handle(key->poll_hotkey.action_handle, 575 status = acpi_get_handle(key->poll_hotkey.action_handle,
586 action_method, &tmp_handle); 576 config_entry[method], &tmp_handle);
587 if (ACPI_FAILURE(status)) 577 if (ACPI_FAILURE(status))
588 goto do_fail; 578 goto do_fail_zero;
589 key->poll_hotkey.poll_result = 579 key->poll_hotkey.poll_result =
590 (union acpi_object *)kmalloc(sizeof(union acpi_object), GFP_KERNEL); 580 (union acpi_object *)kmalloc(sizeof(union acpi_object), GFP_KERNEL);
591 if (!key->poll_hotkey.poll_result) 581 if (!key->poll_hotkey.poll_result)
592 goto do_fail; 582 goto do_fail_zero;
593 return_VALUE(AE_OK); 583 return AE_OK;
594 do_fail: 584
595 return_VALUE(-ENODEV); 585do_fail_zero:
586 key->poll_hotkey.poll_method = NULL;
587 key->poll_hotkey.action_method = NULL;
588do_fail:
589 return -ENODEV;
596} 590}
597 591
598static int hotkey_open_config(struct inode *inode, struct file *file) 592static int hotkey_open_config(struct inode *inode, struct file *file)
599{ 593{
600 ACPI_FUNCTION_TRACE("hotkey_open_config"); 594 return (single_open
601 return_VALUE(single_open
602 (file, hotkey_config_seq_show, PDE(inode)->data)); 595 (file, hotkey_config_seq_show, PDE(inode)->data));
603} 596}
604 597
605static int hotkey_poll_open_config(struct inode *inode, struct file *file) 598static int hotkey_poll_open_config(struct inode *inode, struct file *file)
606{ 599{
607 ACPI_FUNCTION_TRACE("hotkey_poll_open_config"); 600 return (single_open
608 return_VALUE(single_open
609 (file, hotkey_poll_config_seq_show, PDE(inode)->data)); 601 (file, hotkey_poll_config_seq_show, PDE(inode)->data));
610} 602}
611 603
@@ -618,7 +610,6 @@ static int hotkey_config_seq_show(struct seq_file *seq, void *offset)
618 struct acpi_buffer bus = { ACPI_PATHNAME_MAX, bus_name }; 610 struct acpi_buffer bus = { ACPI_PATHNAME_MAX, bus_name };
619 struct acpi_buffer act = { ACPI_PATHNAME_MAX, action_name }; 611 struct acpi_buffer act = { ACPI_PATHNAME_MAX, action_name };
620 612
621 ACPI_FUNCTION_TRACE(("hotkey_config_seq_show"));
622 613
623 list_for_each(entries, hotkey_list->entries) { 614 list_for_each(entries, hotkey_list->entries) {
624 union acpi_hotkey *key = 615 union acpi_hotkey *key =
@@ -636,7 +627,7 @@ static int hotkey_config_seq_show(struct seq_file *seq, void *offset)
636 } 627 }
637 } 628 }
638 seq_puts(seq, "\n"); 629 seq_puts(seq, "\n");
639 return_VALUE(0); 630 return 0;
640} 631}
641 632
642static int hotkey_poll_config_seq_show(struct seq_file *seq, void *offset) 633static int hotkey_poll_config_seq_show(struct seq_file *seq, void *offset)
@@ -648,7 +639,6 @@ static int hotkey_poll_config_seq_show(struct seq_file *seq, void *offset)
648 struct acpi_buffer bus = { ACPI_PATHNAME_MAX, bus_name }; 639 struct acpi_buffer bus = { ACPI_PATHNAME_MAX, bus_name };
649 struct acpi_buffer act = { ACPI_PATHNAME_MAX, action_name }; 640 struct acpi_buffer act = { ACPI_PATHNAME_MAX, action_name };
650 641
651 ACPI_FUNCTION_TRACE(("hotkey_config_seq_show"));
652 642
653 list_for_each(entries, hotkey_list->entries) { 643 list_for_each(entries, hotkey_list->entries) {
654 union acpi_hotkey *key = 644 union acpi_hotkey *key =
@@ -666,22 +656,22 @@ static int hotkey_poll_config_seq_show(struct seq_file *seq, void *offset)
666 } 656 }
667 } 657 }
668 seq_puts(seq, "\n"); 658 seq_puts(seq, "\n");
669 return_VALUE(0); 659 return 0;
670} 660}
671 661
672static int 662static int
673get_parms(char *config_record, 663get_parms(char *config_record, int *cmd, char **config_entry,
674 int *cmd, 664 int *internal_event_num, int *external_event_num)
675 char **bus_handle,
676 char **bus_method,
677 char **action_handle,
678 char **method, int *internal_event_num, int *external_event_num)
679{ 665{
666/* the format of *config_record =
667 * "1:\d+:*" : "cmd:internal_event_num"
668 * "\d+:\w+:\w+:\w+:\w+:\d+:\d+" :
669 * "cmd:bus_handle:bus_method:action_handle:method:internal_event_num:external_event_num"
670 */
680 char *tmp, *tmp1, count; 671 char *tmp, *tmp1, count;
681 ACPI_FUNCTION_TRACE(("get_parms")); 672 int i;
682 673
683 sscanf(config_record, "%d", cmd); 674 sscanf(config_record, "%d", cmd);
684
685 if (*cmd == 1) { 675 if (*cmd == 1) {
686 if (sscanf(config_record, "%d:%d", cmd, internal_event_num) != 676 if (sscanf(config_record, "%d:%d", cmd, internal_event_num) !=
687 2) 677 2)
@@ -693,60 +683,28 @@ get_parms(char *config_record,
693 if (!tmp) 683 if (!tmp)
694 goto do_fail; 684 goto do_fail;
695 tmp++; 685 tmp++;
696 tmp1 = strchr(tmp, ':'); 686 for (i = 0; i < LAST_CONF_ENTRY; i++) {
697 if (!tmp1) 687 tmp1 = strchr(tmp, ':');
698 goto do_fail; 688 if (!tmp1) {
699 689 goto do_fail;
700 count = tmp1 - tmp; 690 }
701 *bus_handle = (char *)kmalloc(count + 1, GFP_KERNEL); 691 count = tmp1 - tmp;
702 if (!*bus_handle) 692 config_entry[i] = kzalloc(count + 1, GFP_KERNEL);
703 goto do_fail; 693 if (!config_entry[i])
704 strncpy(*bus_handle, tmp, count); 694 goto handle_failure;
705 *(*bus_handle + count) = 0; 695 strncpy(config_entry[i], tmp, count);
706 696 tmp = tmp1 + 1;
707 tmp = tmp1; 697 }
708 tmp++; 698 if (sscanf(tmp, "%d:%d", internal_event_num, external_event_num) <= 0)
709 tmp1 = strchr(tmp, ':'); 699 goto handle_failure;
710 if (!tmp1) 700 if (!IS_OTHERS(*internal_event_num)) {
711 goto do_fail; 701 return 6;
712 count = tmp1 - tmp; 702 }
713 *bus_method = (char *)kmalloc(count + 1, GFP_KERNEL); 703handle_failure:
714 if (!*bus_method) 704 while (i-- > 0)
715 goto do_fail; 705 kfree(config_entry[i]);
716 strncpy(*bus_method, tmp, count); 706do_fail:
717 *(*bus_method + count) = 0; 707 return -1;
718
719 tmp = tmp1;
720 tmp++;
721 tmp1 = strchr(tmp, ':');
722 if (!tmp1)
723 goto do_fail;
724 count = tmp1 - tmp;
725 *action_handle = (char *)kmalloc(count + 1, GFP_KERNEL);
726 if (!*action_handle)
727 goto do_fail;
728 strncpy(*action_handle, tmp, count);
729 *(*action_handle + count) = 0;
730
731 tmp = tmp1;
732 tmp++;
733 tmp1 = strchr(tmp, ':');
734 if (!tmp1)
735 goto do_fail;
736 count = tmp1 - tmp;
737 *method = (char *)kmalloc(count + 1, GFP_KERNEL);
738 if (!*method)
739 goto do_fail;
740 strncpy(*method, tmp, count);
741 *(*method + count) = 0;
742
743 if (sscanf(tmp1 + 1, "%d:%d", internal_event_num, external_event_num) <=
744 0)
745 goto do_fail;
746
747 return_VALUE(6);
748 do_fail:
749 return_VALUE(-1);
750} 708}
751 709
752/* count is length for one input record */ 710/* count is length for one input record */
@@ -755,91 +713,58 @@ static ssize_t hotkey_write_config(struct file *file,
755 size_t count, loff_t * data) 713 size_t count, loff_t * data)
756{ 714{
757 char *config_record = NULL; 715 char *config_record = NULL;
758 char *bus_handle = NULL; 716 char *config_entry[LAST_CONF_ENTRY];
759 char *bus_method = NULL;
760 char *action_handle = NULL;
761 char *method = NULL;
762 int cmd, internal_event_num, external_event_num; 717 int cmd, internal_event_num, external_event_num;
763 int ret = 0; 718 int ret = 0;
764 union acpi_hotkey *key = NULL; 719 union acpi_hotkey *key = kzalloc(sizeof(union acpi_hotkey), GFP_KERNEL);
765 720
766 ACPI_FUNCTION_TRACE(("hotkey_write_config")); 721 if (!key)
722 return -ENOMEM;
767 723
768 config_record = (char *)kmalloc(count + 1, GFP_KERNEL); 724 config_record = kzalloc(count + 1, GFP_KERNEL);
769 if (!config_record) 725 if (!config_record) {
770 return_VALUE(-ENOMEM); 726 kfree(key);
727 return -ENOMEM;
728 }
771 729
772 if (copy_from_user(config_record, buffer, count)) { 730 if (copy_from_user(config_record, buffer, count)) {
773 kfree(config_record); 731 kfree(config_record);
774 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid data \n")); 732 kfree(key);
775 return_VALUE(-EINVAL); 733 printk(KERN_ERR PREFIX "Invalid data\n");
734 return -EINVAL;
776 } 735 }
777 config_record[count] = 0; 736 ret = get_parms(config_record, &cmd, config_entry,
778 737 &internal_event_num, &external_event_num);
779 ret = get_parms(config_record,
780 &cmd,
781 &bus_handle,
782 &bus_method,
783 &action_handle,
784 &method, &internal_event_num, &external_event_num);
785
786 kfree(config_record); 738 kfree(config_record);
787 if (IS_OTHERS(internal_event_num))
788 goto do_fail;
789 if (ret != 6) { 739 if (ret != 6) {
790 do_fail: 740 printk(KERN_ERR PREFIX "Invalid data format ret=%d\n", ret);
791 kfree(bus_handle); 741 return -EINVAL;
792 kfree(bus_method);
793 kfree(action_handle);
794 kfree(method);
795 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
796 "Invalid data format ret=%d\n", ret));
797 return_VALUE(-EINVAL);
798 } 742 }
799 743
800 key = kmalloc(sizeof(union acpi_hotkey), GFP_KERNEL);
801 if (!key)
802 goto do_fail;
803 memset(key, 0, sizeof(union acpi_hotkey));
804 if (cmd == 1) { 744 if (cmd == 1) {
805 union acpi_hotkey *tmp = NULL; 745 union acpi_hotkey *tmp = NULL;
806 tmp = get_hotkey_by_event(&global_hotkey_list, 746 tmp = get_hotkey_by_event(&global_hotkey_list,
807 internal_event_num); 747 internal_event_num);
808 if (!tmp) 748 if (!tmp)
809 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid key")); 749 printk(KERN_ERR PREFIX "Invalid key\n");
810 else 750 else
811 memcpy(key, tmp, sizeof(union acpi_hotkey)); 751 memcpy(key, tmp, sizeof(union acpi_hotkey));
812 goto cont_cmd; 752 goto cont_cmd;
813 } 753 }
814 if (IS_EVENT(internal_event_num)) { 754 if (IS_EVENT(internal_event_num)) {
815 kfree(bus_method); 755 if (init_hotkey_device(key, config_entry,
816 ret = init_hotkey_device(key, bus_handle, action_handle, method, 756 internal_event_num, external_event_num))
817 internal_event_num, 757 goto init_hotkey_fail;
818 external_event_num); 758 } else {
819 } else 759 if (init_poll_hotkey_device(key, config_entry,
820 ret = init_poll_hotkey_device(key, bus_handle, bus_method, 760 internal_event_num))
821 action_handle, method, 761 goto init_poll_hotkey_fail;
822 internal_event_num);
823 if (ret) {
824 kfree(bus_handle);
825 kfree(action_handle);
826 if (IS_EVENT(internal_event_num))
827 free_hotkey_buffer(key);
828 else
829 free_poll_hotkey_buffer(key);
830 kfree(key);
831 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid hotkey \n"));
832 return_VALUE(-EINVAL);
833 } 762 }
834 763cont_cmd:
835 cont_cmd:
836 kfree(bus_handle);
837 kfree(action_handle);
838
839 switch (cmd) { 764 switch (cmd) {
840 case 0: 765 case 0:
841 if (get_hotkey_by_event 766 if (get_hotkey_by_event(&global_hotkey_list,
842 (&global_hotkey_list, key->link.hotkey_standard_num)) 767 key->link.hotkey_standard_num))
843 goto fail_out; 768 goto fail_out;
844 else 769 else
845 hotkey_add(key); 770 hotkey_add(key);
@@ -848,6 +773,7 @@ static ssize_t hotkey_write_config(struct file *file,
848 hotkey_remove(key); 773 hotkey_remove(key);
849 break; 774 break;
850 case 2: 775 case 2:
776 /* key is kfree()ed if matched*/
851 if (hotkey_update(key)) 777 if (hotkey_update(key))
852 goto fail_out; 778 goto fail_out;
853 break; 779 break;
@@ -855,15 +781,26 @@ static ssize_t hotkey_write_config(struct file *file,
855 goto fail_out; 781 goto fail_out;
856 break; 782 break;
857 } 783 }
858 return_VALUE(count); 784 return count;
859 fail_out: 785
860 if (IS_EVENT(internal_event_num)) 786init_poll_hotkey_fail: /* failed init_poll_hotkey_device */
861 free_hotkey_buffer(key); 787 kfree(config_entry[bus_method]);
862 else 788 config_entry[bus_method] = NULL;
863 free_poll_hotkey_buffer(key); 789init_hotkey_fail: /* failed init_hotkey_device */
790 kfree(config_entry[method]);
791fail_out:
792 kfree(config_entry[bus_handle]);
793 kfree(config_entry[action_handle]);
794 /* No double free since elements =NULL for error cases */
795 if (IS_EVENT(internal_event_num)) {
796 if (config_entry[bus_method])
797 kfree(config_entry[bus_method]);
798 free_hotkey_buffer(key); /* frees [method] */
799 } else
800 free_poll_hotkey_buffer(key); /* frees [bus_method]+[method] */
864 kfree(key); 801 kfree(key);
865 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "invalid key\n")); 802 printk(KERN_ERR PREFIX "invalid key\n");
866 return_VALUE(-EINVAL); 803 return -EINVAL;
867} 804}
868 805
869/* 806/*
@@ -880,7 +817,6 @@ static int write_acpi_int(acpi_handle handle, const char *method, int val,
880 union acpi_object in_obj; /* the only param we use */ 817 union acpi_object in_obj; /* the only param we use */
881 acpi_status status; 818 acpi_status status;
882 819
883 ACPI_FUNCTION_TRACE("write_acpi_int");
884 params.count = 1; 820 params.count = 1;
885 params.pointer = &in_obj; 821 params.pointer = &in_obj;
886 in_obj.type = ACPI_TYPE_INTEGER; 822 in_obj.type = ACPI_TYPE_INTEGER;
@@ -888,7 +824,7 @@ static int write_acpi_int(acpi_handle handle, const char *method, int val,
888 824
889 status = acpi_evaluate_object(handle, (char *)method, &params, output); 825 status = acpi_evaluate_object(handle, (char *)method, &params, output);
890 826
891 return_VALUE(status == AE_OK); 827 return (status == AE_OK);
892} 828}
893 829
894static int read_acpi_int(acpi_handle handle, const char *method, 830static int read_acpi_int(acpi_handle handle, const char *method,
@@ -898,7 +834,6 @@ static int read_acpi_int(acpi_handle handle, const char *method,
898 union acpi_object out_obj; 834 union acpi_object out_obj;
899 acpi_status status; 835 acpi_status status;
900 836
901 ACPI_FUNCTION_TRACE("read_acpi_int");
902 output.length = sizeof(out_obj); 837 output.length = sizeof(out_obj);
903 output.pointer = &out_obj; 838 output.pointer = &out_obj;
904 839
@@ -907,8 +842,8 @@ static int read_acpi_int(acpi_handle handle, const char *method,
907 val->integer.value = out_obj.integer.value; 842 val->integer.value = out_obj.integer.value;
908 val->type = out_obj.type; 843 val->type = out_obj.type;
909 } else 844 } else
910 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "null val pointer")); 845 printk(KERN_ERR PREFIX "null val pointer\n");
911 return_VALUE((status == AE_OK) 846 return ((status == AE_OK)
912 && (out_obj.type == ACPI_TYPE_INTEGER)); 847 && (out_obj.type == ACPI_TYPE_INTEGER));
913} 848}
914 849
@@ -945,24 +880,22 @@ static ssize_t hotkey_execute_aml_method(struct file *file,
945 int event, method_type, type, value; 880 int event, method_type, type, value;
946 union acpi_hotkey *key; 881 union acpi_hotkey *key;
947 882
948 ACPI_FUNCTION_TRACE("hotkey_execte_aml_method");
949 883
950 arg = (char *)kmalloc(count + 1, GFP_KERNEL); 884 arg = kzalloc(count + 1, GFP_KERNEL);
951 if (!arg) 885 if (!arg)
952 return_VALUE(-ENOMEM); 886 return -ENOMEM;
953 arg[count] = 0;
954 887
955 if (copy_from_user(arg, buffer, count)) { 888 if (copy_from_user(arg, buffer, count)) {
956 kfree(arg); 889 kfree(arg);
957 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid argument 2")); 890 printk(KERN_ERR PREFIX "Invalid argument 2\n");
958 return_VALUE(-EINVAL); 891 return -EINVAL;
959 } 892 }
960 893
961 if (sscanf(arg, "%d:%d:%d:%d", &event, &method_type, &type, &value) != 894 if (sscanf(arg, "%d:%d:%d:%d", &event, &method_type, &type, &value) !=
962 4) { 895 4) {
963 kfree(arg); 896 kfree(arg);
964 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid argument 3")); 897 printk(KERN_ERR PREFIX "Invalid argument 3\n");
965 return_VALUE(-EINVAL); 898 return -EINVAL;
966 } 899 }
967 kfree(arg); 900 kfree(arg);
968 if (type == ACPI_TYPE_INTEGER) { 901 if (type == ACPI_TYPE_INTEGER) {
@@ -987,12 +920,12 @@ static ssize_t hotkey_execute_aml_method(struct file *file,
987 920
988 } 921 }
989 } else { 922 } else {
990 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Not supported")); 923 printk(KERN_WARNING "Not supported\n");
991 return_VALUE(-EINVAL); 924 return -EINVAL;
992 } 925 }
993 return_VALUE(count); 926 return count;
994 do_fail: 927 do_fail:
995 return_VALUE(-EINVAL); 928 return -EINVAL;
996 929
997} 930}
998 931
@@ -1001,7 +934,6 @@ static int __init hotkey_init(void)
1001 int result; 934 int result;
1002 mode_t mode = S_IFREG | S_IRUGO | S_IWUGO; 935 mode_t mode = S_IFREG | S_IRUGO | S_IWUGO;
1003 936
1004 ACPI_FUNCTION_TRACE("hotkey_init");
1005 937
1006 if (acpi_disabled) 938 if (acpi_disabled)
1007 return -ENODEV; 939 return -ENODEV;
@@ -1013,9 +945,6 @@ static int __init hotkey_init(void)
1013 945
1014 hotkey_proc_dir = proc_mkdir(HOTKEY_PROC, acpi_root_dir); 946 hotkey_proc_dir = proc_mkdir(HOTKEY_PROC, acpi_root_dir);
1015 if (!hotkey_proc_dir) { 947 if (!hotkey_proc_dir) {
1016 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1017 "Hotkey: Unable to create %s entry\n",
1018 HOTKEY_PROC));
1019 return (-ENODEV); 948 return (-ENODEV);
1020 } 949 }
1021 hotkey_proc_dir->owner = THIS_MODULE; 950 hotkey_proc_dir->owner = THIS_MODULE;
@@ -1023,9 +952,6 @@ static int __init hotkey_init(void)
1023 hotkey_config = 952 hotkey_config =
1024 create_proc_entry(HOTKEY_EV_CONFIG, mode, hotkey_proc_dir); 953 create_proc_entry(HOTKEY_EV_CONFIG, mode, hotkey_proc_dir);
1025 if (!hotkey_config) { 954 if (!hotkey_config) {
1026 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1027 "Hotkey: Unable to create %s entry\n",
1028 HOTKEY_EV_CONFIG));
1029 goto do_fail1; 955 goto do_fail1;
1030 } else { 956 } else {
1031 hotkey_config->proc_fops = &hotkey_config_fops; 957 hotkey_config->proc_fops = &hotkey_config_fops;
@@ -1038,10 +964,6 @@ static int __init hotkey_init(void)
1038 hotkey_poll_config = 964 hotkey_poll_config =
1039 create_proc_entry(HOTKEY_PL_CONFIG, mode, hotkey_proc_dir); 965 create_proc_entry(HOTKEY_PL_CONFIG, mode, hotkey_proc_dir);
1040 if (!hotkey_poll_config) { 966 if (!hotkey_poll_config) {
1041 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1042 "Hotkey: Unable to create %s entry\n",
1043 HOTKEY_EV_CONFIG));
1044
1045 goto do_fail2; 967 goto do_fail2;
1046 } else { 968 } else {
1047 hotkey_poll_config->proc_fops = &hotkey_poll_config_fops; 969 hotkey_poll_config->proc_fops = &hotkey_poll_config_fops;
@@ -1053,9 +975,6 @@ static int __init hotkey_init(void)
1053 975
1054 hotkey_action = create_proc_entry(HOTKEY_ACTION, mode, hotkey_proc_dir); 976 hotkey_action = create_proc_entry(HOTKEY_ACTION, mode, hotkey_proc_dir);
1055 if (!hotkey_action) { 977 if (!hotkey_action) {
1056 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1057 "Hotkey: Unable to create %s entry\n",
1058 HOTKEY_ACTION));
1059 goto do_fail3; 978 goto do_fail3;
1060 } else { 979 } else {
1061 hotkey_action->proc_fops = &hotkey_action_fops; 980 hotkey_action->proc_fops = &hotkey_action_fops;
@@ -1066,9 +985,6 @@ static int __init hotkey_init(void)
1066 985
1067 hotkey_info = create_proc_entry(HOTKEY_INFO, mode, hotkey_proc_dir); 986 hotkey_info = create_proc_entry(HOTKEY_INFO, mode, hotkey_proc_dir);
1068 if (!hotkey_info) { 987 if (!hotkey_info) {
1069 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1070 "Hotkey: Unable to create %s entry\n",
1071 HOTKEY_INFO));
1072 goto do_fail4; 988 goto do_fail4;
1073 } else { 989 } else {
1074 hotkey_info->proc_fops = &hotkey_info_fops; 990 hotkey_info->proc_fops = &hotkey_info_fops;
@@ -1104,7 +1020,6 @@ static void __exit hotkey_exit(void)
1104{ 1020{
1105 struct list_head *entries, *next; 1021 struct list_head *entries, *next;
1106 1022
1107 ACPI_FUNCTION_TRACE("hotkey_exit");
1108 1023
1109 list_for_each_safe(entries, next, global_hotkey_list.entries) { 1024 list_for_each_safe(entries, next, global_hotkey_list.entries) {
1110 union acpi_hotkey *key = 1025 union acpi_hotkey *key =
diff --git a/drivers/acpi/i2c_ec.c b/drivers/acpi/i2c_ec.c
new file mode 100644
index 000000000000..6342e612c203
--- /dev/null
+++ b/drivers/acpi/i2c_ec.c
@@ -0,0 +1,406 @@
1/*
2 * SMBus driver for ACPI Embedded Controller ($Revision: 1.3 $)
3 *
4 * Copyright (c) 2002, 2005 Ducrot Bruno
5 * Copyright (c) 2005 Rich Townsend (tiny hacks & tweaks)
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation version 2.
10 */
11
12#include <linux/version.h>
13#include <linux/module.h>
14#include <linux/slab.h>
15#include <linux/kernel.h>
16#include <linux/stddef.h>
17#include <linux/sched.h>
18#include <linux/init.h>
19#include <linux/i2c.h>
20#include <linux/acpi.h>
21#include <linux/delay.h>
22
23#include "i2c_ec.h"
24
25#define xudelay(t) udelay(t)
26#define xmsleep(t) msleep(t)
27
28#define ACPI_EC_HC_COMPONENT 0x00080000
29#define ACPI_EC_HC_CLASS "ec_hc_smbus"
30#define ACPI_EC_HC_HID "ACPI0001"
31#define ACPI_EC_HC_DRIVER_NAME "ACPI EC HC smbus driver"
32#define ACPI_EC_HC_DEVICE_NAME "EC HC smbus"
33
34#define _COMPONENT ACPI_EC_HC_COMPONENT
35
36ACPI_MODULE_NAME("acpi_smbus")
37
38static int acpi_ec_hc_add(struct acpi_device *device);
39static int acpi_ec_hc_remove(struct acpi_device *device, int type);
40
41static struct acpi_driver acpi_ec_hc_driver = {
42 .name = ACPI_EC_HC_DRIVER_NAME,
43 .class = ACPI_EC_HC_CLASS,
44 .ids = ACPI_EC_HC_HID,
45 .ops = {
46 .add = acpi_ec_hc_add,
47 .remove = acpi_ec_hc_remove,
48 },
49};
50
51/* Various bit mask for EC_SC (R) */
52#define OBF 0x01
53#define IBF 0x02
54#define CMD 0x08
55#define BURST 0x10
56#define SCI_EVT 0x20
57#define SMI_EVT 0x40
58
59/* Commands for EC_SC (W) */
60#define RD_EC 0x80
61#define WR_EC 0x81
62#define BE_EC 0x82
63#define BD_EC 0x83
64#define QR_EC 0x84
65
66/*
67 * ACPI 2.0 chapter 13 SMBus 2.0 EC register model
68 */
69
70#define ACPI_EC_SMB_PRTCL 0x00 /* protocol, PEC */
71#define ACPI_EC_SMB_STS 0x01 /* status */
72#define ACPI_EC_SMB_ADDR 0x02 /* address */
73#define ACPI_EC_SMB_CMD 0x03 /* command */
74#define ACPI_EC_SMB_DATA 0x04 /* 32 data registers */
75#define ACPI_EC_SMB_BCNT 0x24 /* number of data bytes */
76#define ACPI_EC_SMB_ALRM_A 0x25 /* alarm address */
77#define ACPI_EC_SMB_ALRM_D 0x26 /* 2 bytes alarm data */
78
79#define ACPI_EC_SMB_STS_DONE 0x80
80#define ACPI_EC_SMB_STS_ALRM 0x40
81#define ACPI_EC_SMB_STS_RES 0x20
82#define ACPI_EC_SMB_STS_STATUS 0x1f
83
84#define ACPI_EC_SMB_STATUS_OK 0x00
85#define ACPI_EC_SMB_STATUS_FAIL 0x07
86#define ACPI_EC_SMB_STATUS_DNAK 0x10
87#define ACPI_EC_SMB_STATUS_DERR 0x11
88#define ACPI_EC_SMB_STATUS_CMD_DENY 0x12
89#define ACPI_EC_SMB_STATUS_UNKNOWN 0x13
90#define ACPI_EC_SMB_STATUS_ACC_DENY 0x17
91#define ACPI_EC_SMB_STATUS_TIMEOUT 0x18
92#define ACPI_EC_SMB_STATUS_NOTSUP 0x19
93#define ACPI_EC_SMB_STATUS_BUSY 0x1A
94#define ACPI_EC_SMB_STATUS_PEC 0x1F
95
96#define ACPI_EC_SMB_PRTCL_WRITE 0x00
97#define ACPI_EC_SMB_PRTCL_READ 0x01
98#define ACPI_EC_SMB_PRTCL_QUICK 0x02
99#define ACPI_EC_SMB_PRTCL_BYTE 0x04
100#define ACPI_EC_SMB_PRTCL_BYTE_DATA 0x06
101#define ACPI_EC_SMB_PRTCL_WORD_DATA 0x08
102#define ACPI_EC_SMB_PRTCL_BLOCK_DATA 0x0a
103#define ACPI_EC_SMB_PRTCL_PROC_CALL 0x0c
104#define ACPI_EC_SMB_PRTCL_BLOCK_PROC_CALL 0x0d
105#define ACPI_EC_SMB_PRTCL_I2C_BLOCK_DATA 0x4a
106#define ACPI_EC_SMB_PRTCL_PEC 0x80
107
108/* Length of pre/post transaction sleep (msec) */
109#define ACPI_EC_SMB_TRANSACTION_SLEEP 1
110#define ACPI_EC_SMB_ACCESS_SLEEP1 1
111#define ACPI_EC_SMB_ACCESS_SLEEP2 10
112
113static int acpi_ec_smb_read(struct acpi_ec_smbus *smbus, u8 address, u8 * data)
114{
115 u8 val;
116 int err;
117
118 err = ec_read(smbus->base + address, &val);
119 if (!err) {
120 *data = val;
121 }
122 xmsleep(ACPI_EC_SMB_TRANSACTION_SLEEP);
123 return (err);
124}
125
126static int acpi_ec_smb_write(struct acpi_ec_smbus *smbus, u8 address, u8 data)
127{
128 int err;
129
130 err = ec_write(smbus->base + address, data);
131 return (err);
132}
133
134static int
135acpi_ec_smb_access(struct i2c_adapter *adap, u16 addr, unsigned short flags,
136 char read_write, u8 command, int size,
137 union i2c_smbus_data *data)
138{
139 struct acpi_ec_smbus *smbus = adap->algo_data;
140 unsigned char protocol, len = 0, pec, temp[2] = { 0, 0 };
141 int i;
142
143 if (read_write == I2C_SMBUS_READ) {
144 protocol = ACPI_EC_SMB_PRTCL_READ;
145 } else {
146 protocol = ACPI_EC_SMB_PRTCL_WRITE;
147 }
148 pec = (flags & I2C_CLIENT_PEC) ? ACPI_EC_SMB_PRTCL_PEC : 0;
149
150 switch (size) {
151
152 case I2C_SMBUS_QUICK:
153 protocol |= ACPI_EC_SMB_PRTCL_QUICK;
154 read_write = I2C_SMBUS_WRITE;
155 break;
156
157 case I2C_SMBUS_BYTE:
158 if (read_write == I2C_SMBUS_WRITE) {
159 acpi_ec_smb_write(smbus, ACPI_EC_SMB_DATA, data->byte);
160 }
161 protocol |= ACPI_EC_SMB_PRTCL_BYTE;
162 break;
163
164 case I2C_SMBUS_BYTE_DATA:
165 acpi_ec_smb_write(smbus, ACPI_EC_SMB_CMD, command);
166 if (read_write == I2C_SMBUS_WRITE) {
167 acpi_ec_smb_write(smbus, ACPI_EC_SMB_DATA, data->byte);
168 }
169 protocol |= ACPI_EC_SMB_PRTCL_BYTE_DATA;
170 break;
171
172 case I2C_SMBUS_WORD_DATA:
173 acpi_ec_smb_write(smbus, ACPI_EC_SMB_CMD, command);
174 if (read_write == I2C_SMBUS_WRITE) {
175 acpi_ec_smb_write(smbus, ACPI_EC_SMB_DATA, data->word);
176 acpi_ec_smb_write(smbus, ACPI_EC_SMB_DATA + 1,
177 data->word >> 8);
178 }
179 protocol |= ACPI_EC_SMB_PRTCL_WORD_DATA | pec;
180 break;
181
182 case I2C_SMBUS_BLOCK_DATA:
183 acpi_ec_smb_write(smbus, ACPI_EC_SMB_CMD, command);
184 if (read_write == I2C_SMBUS_WRITE) {
185 len = min_t(u8, data->block[0], 32);
186 acpi_ec_smb_write(smbus, ACPI_EC_SMB_BCNT, len);
187 for (i = 0; i < len; i++)
188 acpi_ec_smb_write(smbus, ACPI_EC_SMB_DATA + i,
189 data->block[i + 1]);
190 }
191 protocol |= ACPI_EC_SMB_PRTCL_BLOCK_DATA | pec;
192 break;
193
194 case I2C_SMBUS_I2C_BLOCK_DATA:
195 len = min_t(u8, data->block[0], 32);
196 acpi_ec_smb_write(smbus, ACPI_EC_SMB_CMD, command);
197 acpi_ec_smb_write(smbus, ACPI_EC_SMB_BCNT, len);
198 if (read_write == I2C_SMBUS_WRITE) {
199 for (i = 0; i < len; i++) {
200 acpi_ec_smb_write(smbus, ACPI_EC_SMB_DATA + i,
201 data->block[i + 1]);
202 }
203 }
204 protocol |= ACPI_EC_SMB_PRTCL_I2C_BLOCK_DATA;
205 break;
206
207 case I2C_SMBUS_PROC_CALL:
208 acpi_ec_smb_write(smbus, ACPI_EC_SMB_CMD, command);
209 acpi_ec_smb_write(smbus, ACPI_EC_SMB_DATA, data->word);
210 acpi_ec_smb_write(smbus, ACPI_EC_SMB_DATA + 1, data->word >> 8);
211 protocol = ACPI_EC_SMB_PRTCL_PROC_CALL | pec;
212 read_write = I2C_SMBUS_READ;
213 break;
214
215 case I2C_SMBUS_BLOCK_PROC_CALL:
216 protocol |= pec;
217 len = min_t(u8, data->block[0], 31);
218 acpi_ec_smb_write(smbus, ACPI_EC_SMB_CMD, command);
219 acpi_ec_smb_write(smbus, ACPI_EC_SMB_BCNT, len);
220 for (i = 0; i < len; i++)
221 acpi_ec_smb_write(smbus, ACPI_EC_SMB_DATA + i,
222 data->block[i + 1]);
223 protocol = ACPI_EC_SMB_PRTCL_BLOCK_PROC_CALL | pec;
224 read_write = I2C_SMBUS_READ;
225 break;
226
227 default:
228 ACPI_DEBUG_PRINT((ACPI_DB_WARN, "EC SMBus adapter: "
229 "Unsupported transaction %d\n", size));
230 return (-1);
231 }
232
233 acpi_ec_smb_write(smbus, ACPI_EC_SMB_ADDR, addr << 1);
234 acpi_ec_smb_write(smbus, ACPI_EC_SMB_PRTCL, protocol);
235
236 acpi_ec_smb_read(smbus, ACPI_EC_SMB_STS, temp + 0);
237
238 if (~temp[0] & ACPI_EC_SMB_STS_DONE) {
239 xudelay(500);
240 acpi_ec_smb_read(smbus, ACPI_EC_SMB_STS, temp + 0);
241 }
242 if (~temp[0] & ACPI_EC_SMB_STS_DONE) {
243 xmsleep(ACPI_EC_SMB_ACCESS_SLEEP2);
244 acpi_ec_smb_read(smbus, ACPI_EC_SMB_STS, temp + 0);
245 }
246 if ((~temp[0] & ACPI_EC_SMB_STS_DONE)
247 || (temp[0] & ACPI_EC_SMB_STS_STATUS)) {
248 return (-1);
249 }
250
251 if (read_write == I2C_SMBUS_WRITE) {
252 return (0);
253 }
254
255 switch (size) {
256
257 case I2C_SMBUS_BYTE:
258 case I2C_SMBUS_BYTE_DATA:
259 acpi_ec_smb_read(smbus, ACPI_EC_SMB_DATA, &data->byte);
260 break;
261
262 case I2C_SMBUS_WORD_DATA:
263 case I2C_SMBUS_PROC_CALL:
264 acpi_ec_smb_read(smbus, ACPI_EC_SMB_DATA, temp + 0);
265 acpi_ec_smb_read(smbus, ACPI_EC_SMB_DATA + 1, temp + 1);
266 data->word = (temp[1] << 8) | temp[0];
267 break;
268
269 case I2C_SMBUS_BLOCK_DATA:
270 case I2C_SMBUS_BLOCK_PROC_CALL:
271 len = 0;
272 acpi_ec_smb_read(smbus, ACPI_EC_SMB_BCNT, &len);
273 len = min_t(u8, len, 32);
274 case I2C_SMBUS_I2C_BLOCK_DATA:
275 for (i = 0; i < len; i++)
276 acpi_ec_smb_read(smbus, ACPI_EC_SMB_DATA + i,
277 data->block + i + 1);
278 data->block[0] = len;
279 break;
280 }
281
282 return (0);
283}
284
285static u32 acpi_ec_smb_func(struct i2c_adapter *adapter)
286{
287
288 return (I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
289 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
290 I2C_FUNC_SMBUS_BLOCK_DATA |
291 I2C_FUNC_SMBUS_PROC_CALL |
292 I2C_FUNC_SMBUS_BLOCK_PROC_CALL |
293 I2C_FUNC_SMBUS_I2C_BLOCK | I2C_FUNC_SMBUS_HWPEC_CALC);
294}
295
296static const struct i2c_algorithm acpi_ec_smbus_algorithm = {
297 .smbus_xfer = acpi_ec_smb_access,
298 .functionality = acpi_ec_smb_func,
299};
300
301static int acpi_ec_hc_add(struct acpi_device *device)
302{
303 int status;
304 unsigned long val;
305 struct acpi_ec_hc *ec_hc;
306 struct acpi_ec_smbus *smbus;
307
308 if (!device) {
309 return -EINVAL;
310 }
311
312 ec_hc = kmalloc(sizeof(struct acpi_ec_hc), GFP_KERNEL);
313 if (!ec_hc) {
314 return -ENOMEM;
315 }
316 memset(ec_hc, 0, sizeof(struct acpi_ec_hc));
317
318 smbus = kmalloc(sizeof(struct acpi_ec_smbus), GFP_KERNEL);
319 if (!smbus) {
320 kfree(ec_hc);
321 return -ENOMEM;
322 }
323 memset(smbus, 0, sizeof(struct acpi_ec_smbus));
324
325 ec_hc->handle = device->handle;
326 strcpy(acpi_device_name(device), ACPI_EC_HC_DEVICE_NAME);
327 strcpy(acpi_device_class(device), ACPI_EC_HC_CLASS);
328 acpi_driver_data(device) = ec_hc;
329
330 status = acpi_evaluate_integer(ec_hc->handle, "_EC", NULL, &val);
331 if (ACPI_FAILURE(status)) {
332 ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Error obtaining _EC\n"));
333 kfree(ec_hc);
334 kfree(smbus);
335 return -EIO;
336 }
337
338 smbus->ec = acpi_driver_data(device->parent);
339 smbus->base = (val & 0xff00ull) >> 8;
340 smbus->alert = val & 0xffull;
341
342 smbus->adapter.owner = THIS_MODULE;
343 smbus->adapter.algo = &acpi_ec_smbus_algorithm;
344 smbus->adapter.algo_data = smbus;
345
346 if (i2c_add_adapter(&smbus->adapter)) {
347 ACPI_DEBUG_PRINT((ACPI_DB_WARN,
348 "EC SMBus adapter: Failed to register adapter\n"));
349 kfree(smbus);
350 kfree(ec_hc);
351 return -EIO;
352 }
353
354 ec_hc->smbus = smbus;
355
356 printk(KERN_INFO PREFIX "%s [%s]\n",
357 acpi_device_name(device), acpi_device_bid(device));
358
359 return AE_OK;
360}
361
362static int acpi_ec_hc_remove(struct acpi_device *device, int type)
363{
364 struct acpi_ec_hc *ec_hc;
365
366 if (!device) {
367 return -EINVAL;
368 }
369 ec_hc = acpi_driver_data(device);
370
371 i2c_del_adapter(&ec_hc->smbus->adapter);
372 kfree(ec_hc->smbus);
373 kfree(ec_hc);
374
375 return AE_OK;
376}
377
378static int __init acpi_ec_hc_init(void)
379{
380 int result;
381
382 result = acpi_bus_register_driver(&acpi_ec_hc_driver);
383 if (result < 0) {
384 return -ENODEV;
385 }
386 return 0;
387}
388
389static void __exit acpi_ec_hc_exit(void)
390{
391 acpi_bus_unregister_driver(&acpi_ec_hc_driver);
392}
393
394struct acpi_ec_hc *acpi_get_ec_hc(struct acpi_device *device)
395{
396 return ((struct acpi_ec_hc *)acpi_driver_data(device->parent));
397}
398
399EXPORT_SYMBOL(acpi_get_ec_hc);
400
401module_init(acpi_ec_hc_init);
402module_exit(acpi_ec_hc_exit);
403
404MODULE_LICENSE("GPL");
405MODULE_AUTHOR("Ducrot Bruno");
406MODULE_DESCRIPTION("ACPI EC SMBus driver");
diff --git a/drivers/acpi/i2c_ec.h b/drivers/acpi/i2c_ec.h
new file mode 100644
index 000000000000..7c53fb732d61
--- /dev/null
+++ b/drivers/acpi/i2c_ec.h
@@ -0,0 +1,23 @@
1/*
2 * SMBus driver for ACPI Embedded Controller ($Revision: 1.2 $)
3 *
4 * Copyright (c) 2002, 2005 Ducrot Bruno
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation version 2.
9 */
10
11struct acpi_ec_smbus {
12 struct i2c_adapter adapter;
13 union acpi_ec *ec;
14 int base;
15 int alert;
16};
17
18struct acpi_ec_hc {
19 acpi_handle handle;
20 struct acpi_ec_smbus *smbus;
21};
22
23struct acpi_ec_hc *acpi_get_ec_hc(struct acpi_device *device);
diff --git a/drivers/acpi/motherboard.c b/drivers/acpi/motherboard.c
index d51d68f5dd8d..ec6b7f9ede34 100644
--- a/drivers/acpi/motherboard.c
+++ b/drivers/acpi/motherboard.c
@@ -52,13 +52,12 @@ static acpi_status acpi_reserve_io_ranges(struct acpi_resource *res, void *data)
52{ 52{
53 struct resource *requested_res = NULL; 53 struct resource *requested_res = NULL;
54 54
55 ACPI_FUNCTION_TRACE("acpi_reserve_io_ranges");
56 55
57 if (res->type == ACPI_RESOURCE_TYPE_IO) { 56 if (res->type == ACPI_RESOURCE_TYPE_IO) {
58 struct acpi_resource_io *io_res = &res->data.io; 57 struct acpi_resource_io *io_res = &res->data.io;
59 58
60 if (io_res->minimum != io_res->maximum) 59 if (io_res->minimum != io_res->maximum)
61 return_VALUE(AE_OK); 60 return AE_OK;
62 if (IS_RESERVED_ADDR 61 if (IS_RESERVED_ADDR
63 (io_res->minimum, io_res->address_length)) { 62 (io_res->minimum, io_res->address_length)) {
64 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 63 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
@@ -92,7 +91,7 @@ static acpi_status acpi_reserve_io_ranges(struct acpi_resource *res, void *data)
92 91
93 if (requested_res) 92 if (requested_res)
94 requested_res->flags &= ~IORESOURCE_BUSY; 93 requested_res->flags &= ~IORESOURCE_BUSY;
95 return_VALUE(AE_OK); 94 return AE_OK;
96} 95}
97 96
98static int acpi_motherboard_add(struct acpi_device *device) 97static int acpi_motherboard_add(struct acpi_device *device)
diff --git a/drivers/acpi/namespace/nsaccess.c b/drivers/acpi/namespace/nsaccess.c
index 48fadade52e2..c1c6c236df9a 100644
--- a/drivers/acpi/namespace/nsaccess.c
+++ b/drivers/acpi/namespace/nsaccess.c
@@ -196,33 +196,30 @@ acpi_status acpi_ns_root_initialize(void)
196 (u8) (ACPI_TO_INTEGER(val) - 1); 196 (u8) (ACPI_TO_INTEGER(val) - 1);
197 197
198 if (ACPI_STRCMP(init_val->name, "_GL_") == 0) { 198 if (ACPI_STRCMP(init_val->name, "_GL_") == 0) {
199 /* 199
200 * Create a counting semaphore for the 200 /* Create a counting semaphore for the global lock */
201 * global lock 201
202 */
203 status = 202 status =
204 acpi_os_create_semaphore 203 acpi_os_create_semaphore
205 (ACPI_NO_UNIT_LIMIT, 1, 204 (ACPI_NO_UNIT_LIMIT, 1,
206 &obj_desc->mutex.semaphore); 205 &acpi_gbl_global_lock_semaphore);
207 if (ACPI_FAILURE(status)) { 206 if (ACPI_FAILURE(status)) {
208 acpi_ut_remove_reference 207 acpi_ut_remove_reference
209 (obj_desc); 208 (obj_desc);
210 goto unlock_and_exit; 209 goto unlock_and_exit;
211 } 210 }
212 211
213 /* 212 /* Mark this mutex as very special */
214 * We just created the mutex for the 213
215 * global lock, save it 214 obj_desc->mutex.os_mutex =
216 */ 215 ACPI_GLOBAL_LOCK;
217 acpi_gbl_global_lock_semaphore =
218 obj_desc->mutex.semaphore;
219 } else { 216 } else {
220 /* Create a mutex */ 217 /* Create a mutex */
221 218
222 status = acpi_os_create_semaphore(1, 1, 219 status =
223 &obj_desc-> 220 acpi_os_create_mutex(&obj_desc->
224 mutex. 221 mutex.
225 semaphore); 222 os_mutex);
226 if (ACPI_FAILURE(status)) { 223 if (ACPI_FAILURE(status)) {
227 acpi_ut_remove_reference 224 acpi_ut_remove_reference
228 (obj_desc); 225 (obj_desc);
diff --git a/drivers/acpi/namespace/nsalloc.c b/drivers/acpi/namespace/nsalloc.c
index dc3f0739a46b..55b407aae266 100644
--- a/drivers/acpi/namespace/nsalloc.c
+++ b/drivers/acpi/namespace/nsalloc.c
@@ -386,14 +386,17 @@ void acpi_ns_delete_namespace_subtree(struct acpi_namespace_node *parent_node)
386 * specific ID. Used to delete entire ACPI tables. All 386 * specific ID. Used to delete entire ACPI tables. All
387 * reference counts are updated. 387 * reference counts are updated.
388 * 388 *
389 * MUTEX: Locks namespace during deletion walk.
390 *
389 ******************************************************************************/ 391 ******************************************************************************/
390 392
391void acpi_ns_delete_namespace_by_owner(acpi_owner_id owner_id) 393void acpi_ns_delete_namespace_by_owner(acpi_owner_id owner_id)
392{ 394{
393 struct acpi_namespace_node *child_node; 395 struct acpi_namespace_node *child_node;
394 struct acpi_namespace_node *deletion_node; 396 struct acpi_namespace_node *deletion_node;
395 u32 level;
396 struct acpi_namespace_node *parent_node; 397 struct acpi_namespace_node *parent_node;
398 u32 level;
399 acpi_status status;
397 400
398 ACPI_FUNCTION_TRACE_U32(ns_delete_namespace_by_owner, owner_id); 401 ACPI_FUNCTION_TRACE_U32(ns_delete_namespace_by_owner, owner_id);
399 402
@@ -401,6 +404,13 @@ void acpi_ns_delete_namespace_by_owner(acpi_owner_id owner_id)
401 return_VOID; 404 return_VOID;
402 } 405 }
403 406
407 /* Lock namespace for possible update */
408
409 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
410 if (ACPI_FAILURE(status)) {
411 return_VOID;
412 }
413
404 deletion_node = NULL; 414 deletion_node = NULL;
405 parent_node = acpi_gbl_root_node; 415 parent_node = acpi_gbl_root_node;
406 child_node = NULL; 416 child_node = NULL;
@@ -469,5 +479,6 @@ void acpi_ns_delete_namespace_by_owner(acpi_owner_id owner_id)
469 } 479 }
470 } 480 }
471 481
482 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
472 return_VOID; 483 return_VOID;
473} 484}
diff --git a/drivers/acpi/namespace/nsxfeval.c b/drivers/acpi/namespace/nsxfeval.c
index 6d9bd45af30a..dca6799ac678 100644
--- a/drivers/acpi/namespace/nsxfeval.c
+++ b/drivers/acpi/namespace/nsxfeval.c
@@ -133,7 +133,7 @@ acpi_evaluate_object_typed(acpi_handle handle,
133 133
134 /* Caller used ACPI_ALLOCATE_BUFFER, free the return buffer */ 134 /* Caller used ACPI_ALLOCATE_BUFFER, free the return buffer */
135 135
136 acpi_os_free(return_buffer->pointer); 136 ACPI_FREE(return_buffer->pointer);
137 return_buffer->pointer = NULL; 137 return_buffer->pointer = NULL;
138 } 138 }
139 139
diff --git a/drivers/acpi/numa.c b/drivers/acpi/numa.c
index e2c1a16078c9..e5e448edca41 100644
--- a/drivers/acpi/numa.c
+++ b/drivers/acpi/numa.c
@@ -23,7 +23,6 @@
23 * 23 *
24 */ 24 */
25#include <linux/module.h> 25#include <linux/module.h>
26#include <linux/config.h>
27#include <linux/init.h> 26#include <linux/init.h>
28#include <linux/kernel.h> 27#include <linux/kernel.h>
29#include <linux/types.h> 28#include <linux/types.h>
@@ -254,5 +253,16 @@ int acpi_get_pxm(acpi_handle h)
254 } while (ACPI_SUCCESS(status)); 253 } while (ACPI_SUCCESS(status));
255 return -1; 254 return -1;
256} 255}
257
258EXPORT_SYMBOL(acpi_get_pxm); 256EXPORT_SYMBOL(acpi_get_pxm);
257
258int acpi_get_node(acpi_handle *handle)
259{
260 int pxm, node = -1;
261
262 pxm = acpi_get_pxm(handle);
263 if (pxm >= 0)
264 node = acpi_map_pxm_to_node(pxm);
265
266 return node;
267}
268EXPORT_SYMBOL(acpi_get_node);
diff --git a/drivers/acpi/osl.c b/drivers/acpi/osl.c
index 1bb558adee66..20beea778ea2 100644
--- a/drivers/acpi/osl.c
+++ b/drivers/acpi/osl.c
@@ -25,7 +25,6 @@
25 * 25 *
26 */ 26 */
27 27
28#include <linux/config.h>
29#include <linux/module.h> 28#include <linux/module.h>
30#include <linux/kernel.h> 29#include <linux/kernel.h>
31#include <linux/slab.h> 30#include <linux/slab.h>
@@ -37,7 +36,6 @@
37#include <linux/delay.h> 36#include <linux/delay.h>
38#include <linux/workqueue.h> 37#include <linux/workqueue.h>
39#include <linux/nmi.h> 38#include <linux/nmi.h>
40#include <linux/kthread.h>
41#include <acpi/acpi.h> 39#include <acpi/acpi.h>
42#include <asm/io.h> 40#include <asm/io.h>
43#include <acpi/acpi_bus.h> 41#include <acpi/acpi_bus.h>
@@ -137,22 +135,6 @@ void acpi_os_vprintf(const char *fmt, va_list args)
137#endif 135#endif
138} 136}
139 137
140extern int acpi_in_resume;
141void *acpi_os_allocate(acpi_size size)
142{
143 if (acpi_in_resume)
144 return kmalloc(size, GFP_ATOMIC);
145 else
146 return kmalloc(size, GFP_KERNEL);
147}
148
149void acpi_os_free(void *ptr)
150{
151 kfree(ptr);
152}
153
154EXPORT_SYMBOL(acpi_os_free);
155
156acpi_status acpi_os_get_root_pointer(u32 flags, struct acpi_pointer *addr) 138acpi_status acpi_os_get_root_pointer(u32 flags, struct acpi_pointer *addr)
157{ 139{
158 if (efi_enabled) { 140 if (efi_enabled) {
@@ -280,7 +262,7 @@ acpi_os_install_interrupt_handler(u32 gsi, acpi_osd_handler handler,
280 262
281 acpi_irq_handler = handler; 263 acpi_irq_handler = handler;
282 acpi_irq_context = context; 264 acpi_irq_context = context;
283 if (request_irq(irq, acpi_irq, SA_SHIRQ, "acpi", acpi_irq)) { 265 if (request_irq(irq, acpi_irq, IRQF_SHARED, "acpi", acpi_irq)) {
284 printk(KERN_ERR PREFIX "SCI (IRQ%d) allocation failed\n", irq); 266 printk(KERN_ERR PREFIX "SCI (IRQ%d) allocation failed\n", irq);
285 return AE_NOT_ACQUIRED; 267 return AE_NOT_ACQUIRED;
286 } 268 }
@@ -586,29 +568,18 @@ static void acpi_os_execute_deferred(void *context)
586{ 568{
587 struct acpi_os_dpc *dpc = NULL; 569 struct acpi_os_dpc *dpc = NULL;
588 570
589 ACPI_FUNCTION_TRACE("os_execute_deferred");
590 571
591 dpc = (struct acpi_os_dpc *)context; 572 dpc = (struct acpi_os_dpc *)context;
592 if (!dpc) { 573 if (!dpc) {
593 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid (NULL) context.\n")); 574 printk(KERN_ERR PREFIX "Invalid (NULL) context\n");
594 return_VOID; 575 return;
595 } 576 }
596 577
597 dpc->function(dpc->context); 578 dpc->function(dpc->context);
598 579
599 kfree(dpc); 580 kfree(dpc);
600 581
601 return_VOID; 582 return;
602}
603
604static int acpi_os_execute_thread(void *context)
605{
606 struct acpi_os_dpc *dpc = (struct acpi_os_dpc *)context;
607 if (dpc) {
608 dpc->function(dpc->context);
609 kfree(dpc);
610 }
611 do_exit(0);
612} 583}
613 584
614/******************************************************************************* 585/*******************************************************************************
@@ -632,10 +603,16 @@ acpi_status acpi_os_execute(acpi_execute_type type,
632 acpi_status status = AE_OK; 603 acpi_status status = AE_OK;
633 struct acpi_os_dpc *dpc; 604 struct acpi_os_dpc *dpc;
634 struct work_struct *task; 605 struct work_struct *task;
635 struct task_struct *p; 606
607 ACPI_FUNCTION_TRACE("os_queue_for_execution");
608
609 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
610 "Scheduling function [%p(%p)] for deferred execution.\n",
611 function, context));
636 612
637 if (!function) 613 if (!function)
638 return AE_BAD_PARAMETER; 614 return_ACPI_STATUS(AE_BAD_PARAMETER);
615
639 /* 616 /*
640 * Allocate/initialize DPC structure. Note that this memory will be 617 * Allocate/initialize DPC structure. Note that this memory will be
641 * freed by the callee. The kernel handles the tq_struct list in a 618 * freed by the callee. The kernel handles the tq_struct list in a
@@ -646,34 +623,27 @@ acpi_status acpi_os_execute(acpi_execute_type type,
646 * We can save time and code by allocating the DPC and tq_structs 623 * We can save time and code by allocating the DPC and tq_structs
647 * from the same memory. 624 * from the same memory.
648 */ 625 */
649 if (type == OSL_NOTIFY_HANDLER) { 626
650 dpc = kmalloc(sizeof(struct acpi_os_dpc), GFP_KERNEL); 627 dpc =
651 } else { 628 kmalloc(sizeof(struct acpi_os_dpc) + sizeof(struct work_struct),
652 dpc = kmalloc(sizeof(struct acpi_os_dpc) + 629 GFP_ATOMIC);
653 sizeof(struct work_struct), GFP_ATOMIC);
654 }
655 if (!dpc) 630 if (!dpc)
656 return AE_NO_MEMORY; 631 return_ACPI_STATUS(AE_NO_MEMORY);
632
657 dpc->function = function; 633 dpc->function = function;
658 dpc->context = context; 634 dpc->context = context;
659 635
660 if (type == OSL_NOTIFY_HANDLER) { 636 task = (void *)(dpc + 1);
661 p = kthread_create(acpi_os_execute_thread, dpc, "kacpid_notify"); 637 INIT_WORK(task, acpi_os_execute_deferred, (void *)dpc);
662 if (!IS_ERR(p)) { 638
663 wake_up_process(p); 639 if (!queue_work(kacpid_wq, task)) {
664 } else { 640 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
665 status = AE_NO_MEMORY; 641 "Call to queue_work() failed.\n"));
666 kfree(dpc); 642 kfree(dpc);
667 } 643 status = AE_ERROR;
668 } else {
669 task = (void *)(dpc + 1);
670 INIT_WORK(task, acpi_os_execute_deferred, (void *)dpc);
671 if (!queue_work(kacpid_wq, task)) {
672 status = AE_ERROR;
673 kfree(dpc);
674 }
675 } 644 }
676 return status; 645
646 return_ACPI_STATUS(status);
677} 647}
678 648
679EXPORT_SYMBOL(acpi_os_execute); 649EXPORT_SYMBOL(acpi_os_execute);
@@ -688,35 +658,19 @@ EXPORT_SYMBOL(acpi_os_wait_events_complete);
688/* 658/*
689 * Allocate the memory for a spinlock and initialize it. 659 * Allocate the memory for a spinlock and initialize it.
690 */ 660 */
691acpi_status acpi_os_create_lock(acpi_handle * out_handle) 661acpi_status acpi_os_create_lock(acpi_spinlock * handle)
692{ 662{
693 spinlock_t *lock_ptr; 663 spin_lock_init(*handle);
694
695 ACPI_FUNCTION_TRACE("os_create_lock");
696
697 lock_ptr = acpi_os_allocate(sizeof(spinlock_t));
698
699 spin_lock_init(lock_ptr);
700
701 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Creating spinlock[%p].\n", lock_ptr));
702 664
703 *out_handle = lock_ptr; 665 return AE_OK;
704
705 return_ACPI_STATUS(AE_OK);
706} 666}
707 667
708/* 668/*
709 * Deallocate the memory for a spinlock. 669 * Deallocate the memory for a spinlock.
710 */ 670 */
711void acpi_os_delete_lock(acpi_handle handle) 671void acpi_os_delete_lock(acpi_spinlock handle)
712{ 672{
713 ACPI_FUNCTION_TRACE("os_create_lock"); 673 return;
714
715 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting spinlock[%p].\n", handle));
716
717 acpi_os_free(handle);
718
719 return_VOID;
720} 674}
721 675
722acpi_status 676acpi_status
@@ -724,11 +678,10 @@ acpi_os_create_semaphore(u32 max_units, u32 initial_units, acpi_handle * handle)
724{ 678{
725 struct semaphore *sem = NULL; 679 struct semaphore *sem = NULL;
726 680
727 ACPI_FUNCTION_TRACE("os_create_semaphore");
728 681
729 sem = acpi_os_allocate(sizeof(struct semaphore)); 682 sem = acpi_os_allocate(sizeof(struct semaphore));
730 if (!sem) 683 if (!sem)
731 return_ACPI_STATUS(AE_NO_MEMORY); 684 return AE_NO_MEMORY;
732 memset(sem, 0, sizeof(struct semaphore)); 685 memset(sem, 0, sizeof(struct semaphore));
733 686
734 sema_init(sem, initial_units); 687 sema_init(sem, initial_units);
@@ -738,7 +691,7 @@ acpi_os_create_semaphore(u32 max_units, u32 initial_units, acpi_handle * handle)
738 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Creating semaphore[%p|%d].\n", 691 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Creating semaphore[%p|%d].\n",
739 *handle, initial_units)); 692 *handle, initial_units));
740 693
741 return_ACPI_STATUS(AE_OK); 694 return AE_OK;
742} 695}
743 696
744EXPORT_SYMBOL(acpi_os_create_semaphore); 697EXPORT_SYMBOL(acpi_os_create_semaphore);
@@ -754,17 +707,16 @@ acpi_status acpi_os_delete_semaphore(acpi_handle handle)
754{ 707{
755 struct semaphore *sem = (struct semaphore *)handle; 708 struct semaphore *sem = (struct semaphore *)handle;
756 709
757 ACPI_FUNCTION_TRACE("os_delete_semaphore");
758 710
759 if (!sem) 711 if (!sem)
760 return_ACPI_STATUS(AE_BAD_PARAMETER); 712 return AE_BAD_PARAMETER;
761 713
762 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting semaphore[%p].\n", handle)); 714 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting semaphore[%p].\n", handle));
763 715
764 acpi_os_free(sem); 716 kfree(sem);
765 sem = NULL; 717 sem = NULL;
766 718
767 return_ACPI_STATUS(AE_OK); 719 return AE_OK;
768} 720}
769 721
770EXPORT_SYMBOL(acpi_os_delete_semaphore); 722EXPORT_SYMBOL(acpi_os_delete_semaphore);
@@ -784,17 +736,26 @@ acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout)
784 struct semaphore *sem = (struct semaphore *)handle; 736 struct semaphore *sem = (struct semaphore *)handle;
785 int ret = 0; 737 int ret = 0;
786 738
787 ACPI_FUNCTION_TRACE("os_wait_semaphore");
788 739
789 if (!sem || (units < 1)) 740 if (!sem || (units < 1))
790 return_ACPI_STATUS(AE_BAD_PARAMETER); 741 return AE_BAD_PARAMETER;
791 742
792 if (units > 1) 743 if (units > 1)
793 return_ACPI_STATUS(AE_SUPPORT); 744 return AE_SUPPORT;
794 745
795 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Waiting for semaphore[%p|%d|%d]\n", 746 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Waiting for semaphore[%p|%d|%d]\n",
796 handle, units, timeout)); 747 handle, units, timeout));
797 748
749 /*
750 * This can be called during resume with interrupts off.
751 * Like boot-time, we should be single threaded and will
752 * always get the lock if we try -- timeout or not.
753 * If this doesn't succeed, then we will oops courtesy of
754 * might_sleep() in down().
755 */
756 if (!down_trylock(sem))
757 return AE_OK;
758
798 switch (timeout) { 759 switch (timeout) {
799 /* 760 /*
800 * No Wait: 761 * No Wait:
@@ -839,17 +800,17 @@ acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout)
839 } 800 }
840 801
841 if (ACPI_FAILURE(status)) { 802 if (ACPI_FAILURE(status)) {
842 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 803 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
843 "Failed to acquire semaphore[%p|%d|%d], %s\n", 804 "Failed to acquire semaphore[%p|%d|%d], %s",
844 handle, units, timeout, 805 handle, units, timeout,
845 acpi_format_exception(status))); 806 acpi_format_exception(status)));
846 } else { 807 } else {
847 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, 808 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
848 "Acquired semaphore[%p|%d|%d]\n", handle, 809 "Acquired semaphore[%p|%d|%d]", handle,
849 units, timeout)); 810 units, timeout));
850 } 811 }
851 812
852 return_ACPI_STATUS(status); 813 return status;
853} 814}
854 815
855EXPORT_SYMBOL(acpi_os_wait_semaphore); 816EXPORT_SYMBOL(acpi_os_wait_semaphore);
@@ -861,20 +822,19 @@ acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units)
861{ 822{
862 struct semaphore *sem = (struct semaphore *)handle; 823 struct semaphore *sem = (struct semaphore *)handle;
863 824
864 ACPI_FUNCTION_TRACE("os_signal_semaphore");
865 825
866 if (!sem || (units < 1)) 826 if (!sem || (units < 1))
867 return_ACPI_STATUS(AE_BAD_PARAMETER); 827 return AE_BAD_PARAMETER;
868 828
869 if (units > 1) 829 if (units > 1)
870 return_ACPI_STATUS(AE_SUPPORT); 830 return AE_SUPPORT;
871 831
872 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Signaling semaphore[%p|%d]\n", handle, 832 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Signaling semaphore[%p|%d]\n", handle,
873 units)); 833 units));
874 834
875 up(sem); 835 up(sem);
876 836
877 return_ACPI_STATUS(AE_OK); 837 return AE_OK;
878} 838}
879 839
880EXPORT_SYMBOL(acpi_os_signal_semaphore); 840EXPORT_SYMBOL(acpi_os_signal_semaphore);
@@ -1043,10 +1003,10 @@ EXPORT_SYMBOL(max_cstate);
1043 * handle is a pointer to the spinlock_t. 1003 * handle is a pointer to the spinlock_t.
1044 */ 1004 */
1045 1005
1046acpi_cpu_flags acpi_os_acquire_lock(acpi_handle handle) 1006acpi_cpu_flags acpi_os_acquire_lock(acpi_spinlock lockp)
1047{ 1007{
1048 acpi_cpu_flags flags; 1008 acpi_cpu_flags flags;
1049 spin_lock_irqsave((spinlock_t *) handle, flags); 1009 spin_lock_irqsave(lockp, flags);
1050 return flags; 1010 return flags;
1051} 1011}
1052 1012
@@ -1054,9 +1014,9 @@ acpi_cpu_flags acpi_os_acquire_lock(acpi_handle handle)
1054 * Release a spinlock. See above. 1014 * Release a spinlock. See above.
1055 */ 1015 */
1056 1016
1057void acpi_os_release_lock(acpi_handle handle, acpi_cpu_flags flags) 1017void acpi_os_release_lock(acpi_spinlock lockp, acpi_cpu_flags flags)
1058{ 1018{
1059 spin_unlock_irqrestore((spinlock_t *) handle, flags); 1019 spin_unlock_irqrestore(lockp, flags);
1060} 1020}
1061 1021
1062#ifndef ACPI_USE_LOCAL_CACHE 1022#ifndef ACPI_USE_LOCAL_CACHE
@@ -1119,7 +1079,7 @@ acpi_status acpi_os_purge_cache(acpi_cache_t * cache)
1119 1079
1120acpi_status acpi_os_delete_cache(acpi_cache_t * cache) 1080acpi_status acpi_os_delete_cache(acpi_cache_t * cache)
1121{ 1081{
1122 (void)kmem_cache_destroy(cache); 1082 kmem_cache_destroy(cache);
1123 return (AE_OK); 1083 return (AE_OK);
1124} 1084}
1125 1085
@@ -1143,26 +1103,6 @@ acpi_status acpi_os_release_object(acpi_cache_t * cache, void *object)
1143 return (AE_OK); 1103 return (AE_OK);
1144} 1104}
1145 1105
1146/*******************************************************************************
1147 *
1148 * FUNCTION: acpi_os_acquire_object
1149 *
1150 * PARAMETERS: Cache - Handle to cache object
1151 * ReturnObject - Where the object is returned
1152 *
1153 * RETURN: Status
1154 *
1155 * DESCRIPTION: Return a zero-filled object.
1156 *
1157 ******************************************************************************/
1158
1159void *acpi_os_acquire_object(acpi_cache_t * cache)
1160{
1161 void *object = kmem_cache_zalloc(cache, GFP_KERNEL);
1162 WARN_ON(!object);
1163 return object;
1164}
1165
1166/****************************************************************************** 1106/******************************************************************************
1167 * 1107 *
1168 * FUNCTION: acpi_os_validate_interface 1108 * FUNCTION: acpi_os_validate_interface
diff --git a/drivers/acpi/parser/psparse.c b/drivers/acpi/parser/psparse.c
index 7ee2f2e77525..a02aa62fe1e5 100644
--- a/drivers/acpi/parser/psparse.c
+++ b/drivers/acpi/parser/psparse.c
@@ -469,6 +469,16 @@ acpi_status acpi_ps_parse_aml(struct acpi_walk_state *walk_state)
469 } 469 }
470 470
471 walk_state->thread = thread; 471 walk_state->thread = thread;
472
473 /*
474 * If executing a method, the starting sync_level is this method's
475 * sync_level
476 */
477 if (walk_state->method_desc) {
478 walk_state->thread->current_sync_level =
479 walk_state->method_desc->method.sync_level;
480 }
481
472 acpi_ds_push_walk_state(walk_state, thread); 482 acpi_ds_push_walk_state(walk_state, thread);
473 483
474 /* 484 /*
@@ -505,6 +515,10 @@ acpi_status acpi_ps_parse_aml(struct acpi_walk_state *walk_state)
505 status = 515 status =
506 acpi_ds_call_control_method(thread, walk_state, 516 acpi_ds_call_control_method(thread, walk_state,
507 NULL); 517 NULL);
518 if (ACPI_FAILURE(status)) {
519 status =
520 acpi_ds_method_error(status, walk_state);
521 }
508 522
509 /* 523 /*
510 * If the transfer to the new method method call worked, a new walk 524 * If the transfer to the new method method call worked, a new walk
@@ -525,7 +539,7 @@ acpi_status acpi_ps_parse_aml(struct acpi_walk_state *walk_state)
525 /* Check for possible multi-thread reentrancy problem */ 539 /* Check for possible multi-thread reentrancy problem */
526 540
527 if ((status == AE_ALREADY_EXISTS) && 541 if ((status == AE_ALREADY_EXISTS) &&
528 (!walk_state->method_desc->method.semaphore)) { 542 (!walk_state->method_desc->method.mutex)) {
529 /* 543 /*
530 * Method tried to create an object twice. The probable cause is 544 * Method tried to create an object twice. The probable cause is
531 * that the method cannot handle reentrancy. 545 * that the method cannot handle reentrancy.
@@ -537,7 +551,7 @@ acpi_status acpi_ps_parse_aml(struct acpi_walk_state *walk_state)
537 */ 551 */
538 walk_state->method_desc->method.method_flags |= 552 walk_state->method_desc->method.method_flags |=
539 AML_METHOD_SERIALIZED; 553 AML_METHOD_SERIALIZED;
540 walk_state->method_desc->method.concurrency = 1; 554 walk_state->method_desc->method.sync_level = 0;
541 } 555 }
542 } 556 }
543 557
diff --git a/drivers/acpi/parser/psutils.c b/drivers/acpi/parser/psutils.c
index 182474ae8ce9..d405387b7414 100644
--- a/drivers/acpi/parser/psutils.c
+++ b/drivers/acpi/parser/psutils.c
@@ -139,12 +139,10 @@ union acpi_parse_object *acpi_ps_alloc_op(u16 opcode)
139 /* The generic op (default) is by far the most common (16 to 1) */ 139 /* The generic op (default) is by far the most common (16 to 1) */
140 140
141 op = acpi_os_acquire_object(acpi_gbl_ps_node_cache); 141 op = acpi_os_acquire_object(acpi_gbl_ps_node_cache);
142 memset(op, 0, sizeof(struct acpi_parse_obj_common));
143 } else { 142 } else {
144 /* Extended parseop */ 143 /* Extended parseop */
145 144
146 op = acpi_os_acquire_object(acpi_gbl_ps_node_ext_cache); 145 op = acpi_os_acquire_object(acpi_gbl_ps_node_ext_cache);
147 memset(op, 0, sizeof(struct acpi_parse_obj_named));
148 } 146 }
149 147
150 /* Initialize the Op */ 148 /* Initialize the Op */
diff --git a/drivers/acpi/pci_bind.c b/drivers/acpi/pci_bind.c
index 2a718df769b5..1e2ae6e7a7e4 100644
--- a/drivers/acpi/pci_bind.c
+++ b/drivers/acpi/pci_bind.c
@@ -47,11 +47,10 @@ struct acpi_pci_data {
47static void acpi_pci_data_handler(acpi_handle handle, u32 function, 47static void acpi_pci_data_handler(acpi_handle handle, u32 function,
48 void *context) 48 void *context)
49{ 49{
50 ACPI_FUNCTION_TRACE("acpi_pci_data_handler");
51 50
52 /* TBD: Anything we need to do here? */ 51 /* TBD: Anything we need to do here? */
53 52
54 return_VOID; 53 return;
55} 54}
56 55
57/** 56/**
@@ -68,25 +67,24 @@ acpi_status acpi_get_pci_id(acpi_handle handle, struct acpi_pci_id *id)
68 struct acpi_device *device = NULL; 67 struct acpi_device *device = NULL;
69 struct acpi_pci_data *data = NULL; 68 struct acpi_pci_data *data = NULL;
70 69
71 ACPI_FUNCTION_TRACE("acpi_get_pci_id");
72 70
73 if (!id) 71 if (!id)
74 return_ACPI_STATUS(AE_BAD_PARAMETER); 72 return AE_BAD_PARAMETER;
75 73
76 result = acpi_bus_get_device(handle, &device); 74 result = acpi_bus_get_device(handle, &device);
77 if (result) { 75 if (result) {
78 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 76 printk(KERN_ERR PREFIX
79 "Invalid ACPI Bus context for device %s\n", 77 "Invalid ACPI Bus context for device %s\n",
80 acpi_device_bid(device))); 78 acpi_device_bid(device));
81 return_ACPI_STATUS(AE_NOT_EXIST); 79 return AE_NOT_EXIST;
82 } 80 }
83 81
84 status = acpi_get_data(handle, acpi_pci_data_handler, (void **)&data); 82 status = acpi_get_data(handle, acpi_pci_data_handler, (void **)&data);
85 if (ACPI_FAILURE(status) || !data) { 83 if (ACPI_FAILURE(status) || !data) {
86 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 84 ACPI_EXCEPTION((AE_INFO, status,
87 "Invalid ACPI-PCI context for device %s\n", 85 "Invalid ACPI-PCI context for device %s",
88 acpi_device_bid(device))); 86 acpi_device_bid(device)));
89 return_ACPI_STATUS(status); 87 return status;
90 } 88 }
91 89
92 *id = data->id; 90 *id = data->id;
@@ -103,7 +101,7 @@ acpi_status acpi_get_pci_id(acpi_handle handle, struct acpi_pci_id *id)
103 acpi_device_bid(device), id->segment, id->bus, 101 acpi_device_bid(device), id->segment, id->bus,
104 id->device, id->function)); 102 id->device, id->function));
105 103
106 return_ACPI_STATUS(AE_OK); 104 return AE_OK;
107} 105}
108 106
109EXPORT_SYMBOL(acpi_get_pci_id); 107EXPORT_SYMBOL(acpi_get_pci_id);
@@ -120,14 +118,13 @@ int acpi_pci_bind(struct acpi_device *device)
120 struct pci_dev *dev; 118 struct pci_dev *dev;
121 struct pci_bus *bus; 119 struct pci_bus *bus;
122 120
123 ACPI_FUNCTION_TRACE("acpi_pci_bind");
124 121
125 if (!device || !device->parent) 122 if (!device || !device->parent)
126 return_VALUE(-EINVAL); 123 return -EINVAL;
127 124
128 pathname = kmalloc(ACPI_PATHNAME_MAX, GFP_KERNEL); 125 pathname = kmalloc(ACPI_PATHNAME_MAX, GFP_KERNEL);
129 if (!pathname) 126 if (!pathname)
130 return_VALUE(-ENOMEM); 127 return -ENOMEM;
131 memset(pathname, 0, ACPI_PATHNAME_MAX); 128 memset(pathname, 0, ACPI_PATHNAME_MAX);
132 buffer.length = ACPI_PATHNAME_MAX; 129 buffer.length = ACPI_PATHNAME_MAX;
133 buffer.pointer = pathname; 130 buffer.pointer = pathname;
@@ -135,7 +132,7 @@ int acpi_pci_bind(struct acpi_device *device)
135 data = kmalloc(sizeof(struct acpi_pci_data), GFP_KERNEL); 132 data = kmalloc(sizeof(struct acpi_pci_data), GFP_KERNEL);
136 if (!data) { 133 if (!data) {
137 kfree(pathname); 134 kfree(pathname);
138 return_VALUE(-ENOMEM); 135 return -ENOMEM;
139 } 136 }
140 memset(data, 0, sizeof(struct acpi_pci_data)); 137 memset(data, 0, sizeof(struct acpi_pci_data));
141 138
@@ -151,9 +148,9 @@ int acpi_pci_bind(struct acpi_device *device)
151 status = acpi_get_data(device->parent->handle, acpi_pci_data_handler, 148 status = acpi_get_data(device->parent->handle, acpi_pci_data_handler,
152 (void **)&pdata); 149 (void **)&pdata);
153 if (ACPI_FAILURE(status) || !pdata || !pdata->bus) { 150 if (ACPI_FAILURE(status) || !pdata || !pdata->bus) {
154 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 151 ACPI_EXCEPTION((AE_INFO, status,
155 "Invalid ACPI-PCI context for parent device %s\n", 152 "Invalid ACPI-PCI context for parent device %s",
156 acpi_device_bid(device->parent))); 153 acpi_device_bid(device->parent)));
157 result = -ENODEV; 154 result = -ENODEV;
158 goto end; 155 goto end;
159 } 156 }
@@ -206,10 +203,10 @@ int acpi_pci_bind(struct acpi_device *device)
206 goto end; 203 goto end;
207 } 204 }
208 if (!data->dev->bus) { 205 if (!data->dev->bus) {
209 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 206 printk(KERN_ERR PREFIX
210 "Device %02x:%02x:%02x.%02x has invalid 'bus' field\n", 207 "Device %02x:%02x:%02x.%02x has invalid 'bus' field\n",
211 data->id.segment, data->id.bus, 208 data->id.segment, data->id.bus,
212 data->id.device, data->id.function)); 209 data->id.device, data->id.function);
213 result = -ENODEV; 210 result = -ENODEV;
214 goto end; 211 goto end;
215 } 212 }
@@ -237,9 +234,9 @@ int acpi_pci_bind(struct acpi_device *device)
237 */ 234 */
238 status = acpi_attach_data(device->handle, acpi_pci_data_handler, data); 235 status = acpi_attach_data(device->handle, acpi_pci_data_handler, data);
239 if (ACPI_FAILURE(status)) { 236 if (ACPI_FAILURE(status)) {
240 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 237 ACPI_EXCEPTION((AE_INFO, status,
241 "Unable to attach ACPI-PCI context to device %s\n", 238 "Unable to attach ACPI-PCI context to device %s",
242 acpi_device_bid(device))); 239 acpi_device_bid(device)));
243 result = -ENODEV; 240 result = -ENODEV;
244 goto end; 241 goto end;
245 } 242 }
@@ -269,7 +266,7 @@ int acpi_pci_bind(struct acpi_device *device)
269 if (result) 266 if (result)
270 kfree(data); 267 kfree(data);
271 268
272 return_VALUE(result); 269 return result;
273} 270}
274 271
275int acpi_pci_unbind(struct acpi_device *device) 272int acpi_pci_unbind(struct acpi_device *device)
@@ -280,14 +277,13 @@ int acpi_pci_unbind(struct acpi_device *device)
280 char *pathname = NULL; 277 char *pathname = NULL;
281 struct acpi_buffer buffer = { 0, NULL }; 278 struct acpi_buffer buffer = { 0, NULL };
282 279
283 ACPI_FUNCTION_TRACE("acpi_pci_unbind");
284 280
285 if (!device || !device->parent) 281 if (!device || !device->parent)
286 return_VALUE(-EINVAL); 282 return -EINVAL;
287 283
288 pathname = (char *)kmalloc(ACPI_PATHNAME_MAX, GFP_KERNEL); 284 pathname = (char *)kmalloc(ACPI_PATHNAME_MAX, GFP_KERNEL);
289 if (!pathname) 285 if (!pathname)
290 return_VALUE(-ENOMEM); 286 return -ENOMEM;
291 memset(pathname, 0, ACPI_PATHNAME_MAX); 287 memset(pathname, 0, ACPI_PATHNAME_MAX);
292 288
293 buffer.length = ACPI_PATHNAME_MAX; 289 buffer.length = ACPI_PATHNAME_MAX;
@@ -301,18 +297,18 @@ int acpi_pci_unbind(struct acpi_device *device)
301 acpi_get_data(device->handle, acpi_pci_data_handler, 297 acpi_get_data(device->handle, acpi_pci_data_handler,
302 (void **)&data); 298 (void **)&data);
303 if (ACPI_FAILURE(status)) { 299 if (ACPI_FAILURE(status)) {
304 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 300 ACPI_EXCEPTION((AE_INFO, status,
305 "Unable to get data from device %s\n", 301 "Unable to get data from device %s",
306 acpi_device_bid(device))); 302 acpi_device_bid(device)));
307 result = -ENODEV; 303 result = -ENODEV;
308 goto end; 304 goto end;
309 } 305 }
310 306
311 status = acpi_detach_data(device->handle, acpi_pci_data_handler); 307 status = acpi_detach_data(device->handle, acpi_pci_data_handler);
312 if (ACPI_FAILURE(status)) { 308 if (ACPI_FAILURE(status)) {
313 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 309 ACPI_EXCEPTION((AE_INFO, status,
314 "Unable to detach data from device %s\n", 310 "Unable to detach data from device %s",
315 acpi_device_bid(device))); 311 acpi_device_bid(device)));
316 result = -ENODEV; 312 result = -ENODEV;
317 goto end; 313 goto end;
318 } 314 }
@@ -322,7 +318,7 @@ int acpi_pci_unbind(struct acpi_device *device)
322 kfree(data); 318 kfree(data);
323 319
324 end: 320 end:
325 return_VALUE(result); 321 return result;
326} 322}
327 323
328int 324int
@@ -335,11 +331,10 @@ acpi_pci_bind_root(struct acpi_device *device,
335 char *pathname = NULL; 331 char *pathname = NULL;
336 struct acpi_buffer buffer = { 0, NULL }; 332 struct acpi_buffer buffer = { 0, NULL };
337 333
338 ACPI_FUNCTION_TRACE("acpi_pci_bind_root");
339 334
340 pathname = (char *)kmalloc(ACPI_PATHNAME_MAX, GFP_KERNEL); 335 pathname = (char *)kmalloc(ACPI_PATHNAME_MAX, GFP_KERNEL);
341 if (!pathname) 336 if (!pathname)
342 return_VALUE(-ENOMEM); 337 return -ENOMEM;
343 memset(pathname, 0, ACPI_PATHNAME_MAX); 338 memset(pathname, 0, ACPI_PATHNAME_MAX);
344 339
345 buffer.length = ACPI_PATHNAME_MAX; 340 buffer.length = ACPI_PATHNAME_MAX;
@@ -347,13 +342,13 @@ acpi_pci_bind_root(struct acpi_device *device,
347 342
348 if (!device || !id || !bus) { 343 if (!device || !id || !bus) {
349 kfree(pathname); 344 kfree(pathname);
350 return_VALUE(-EINVAL); 345 return -EINVAL;
351 } 346 }
352 347
353 data = kmalloc(sizeof(struct acpi_pci_data), GFP_KERNEL); 348 data = kmalloc(sizeof(struct acpi_pci_data), GFP_KERNEL);
354 if (!data) { 349 if (!data) {
355 kfree(pathname); 350 kfree(pathname);
356 return_VALUE(-ENOMEM); 351 return -ENOMEM;
357 } 352 }
358 memset(data, 0, sizeof(struct acpi_pci_data)); 353 memset(data, 0, sizeof(struct acpi_pci_data));
359 354
@@ -369,9 +364,9 @@ acpi_pci_bind_root(struct acpi_device *device,
369 364
370 status = acpi_attach_data(device->handle, acpi_pci_data_handler, data); 365 status = acpi_attach_data(device->handle, acpi_pci_data_handler, data);
371 if (ACPI_FAILURE(status)) { 366 if (ACPI_FAILURE(status)) {
372 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 367 ACPI_EXCEPTION((AE_INFO, status,
373 "Unable to attach ACPI-PCI context to device %s\n", 368 "Unable to attach ACPI-PCI context to device %s",
374 pathname)); 369 pathname));
375 result = -ENODEV; 370 result = -ENODEV;
376 goto end; 371 goto end;
377 } 372 }
@@ -381,5 +376,5 @@ acpi_pci_bind_root(struct acpi_device *device,
381 if (result != 0) 376 if (result != 0)
382 kfree(data); 377 kfree(data);
383 378
384 return_VALUE(result); 379 return result;
385} 380}
diff --git a/drivers/acpi/pci_irq.c b/drivers/acpi/pci_irq.c
index 65aee79b3971..feda0341f5a7 100644
--- a/drivers/acpi/pci_irq.c
+++ b/drivers/acpi/pci_irq.c
@@ -24,7 +24,6 @@
24 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 24 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
25 */ 25 */
26 26
27#include <linux/config.h>
28 27
29#include <linux/kernel.h> 28#include <linux/kernel.h>
30#include <linux/module.h> 29#include <linux/module.h>
@@ -55,10 +54,9 @@ static struct acpi_prt_entry *acpi_pci_irq_find_prt_entry(int segment,
55 struct list_head *node = NULL; 54 struct list_head *node = NULL;
56 struct acpi_prt_entry *entry = NULL; 55 struct acpi_prt_entry *entry = NULL;
57 56
58 ACPI_FUNCTION_TRACE("acpi_pci_irq_find_prt_entry");
59 57
60 if (!acpi_prt.count) 58 if (!acpi_prt.count)
61 return_PTR(NULL); 59 return NULL;
62 60
63 /* 61 /*
64 * Parse through all PRT entries looking for a match on the specified 62 * Parse through all PRT entries looking for a match on the specified
@@ -73,12 +71,12 @@ static struct acpi_prt_entry *acpi_pci_irq_find_prt_entry(int segment,
73 && (device == entry->id.device) 71 && (device == entry->id.device)
74 && (pin == entry->pin)) { 72 && (pin == entry->pin)) {
75 spin_unlock(&acpi_prt_lock); 73 spin_unlock(&acpi_prt_lock);
76 return_PTR(entry); 74 return entry;
77 } 75 }
78 } 76 }
79 77
80 spin_unlock(&acpi_prt_lock); 78 spin_unlock(&acpi_prt_lock);
81 return_PTR(NULL); 79 return NULL;
82} 80}
83 81
84static int 82static int
@@ -87,14 +85,13 @@ acpi_pci_irq_add_entry(acpi_handle handle,
87{ 85{
88 struct acpi_prt_entry *entry = NULL; 86 struct acpi_prt_entry *entry = NULL;
89 87
90 ACPI_FUNCTION_TRACE("acpi_pci_irq_add_entry");
91 88
92 if (!prt) 89 if (!prt)
93 return_VALUE(-EINVAL); 90 return -EINVAL;
94 91
95 entry = kmalloc(sizeof(struct acpi_prt_entry), GFP_KERNEL); 92 entry = kmalloc(sizeof(struct acpi_prt_entry), GFP_KERNEL);
96 if (!entry) 93 if (!entry)
97 return_VALUE(-ENOMEM); 94 return -ENOMEM;
98 memset(entry, 0, sizeof(struct acpi_prt_entry)); 95 memset(entry, 0, sizeof(struct acpi_prt_entry));
99 96
100 entry->id.segment = segment; 97 entry->id.segment = segment;
@@ -141,7 +138,7 @@ acpi_pci_irq_add_entry(acpi_handle handle,
141 acpi_prt.count++; 138 acpi_prt.count++;
142 spin_unlock(&acpi_prt_lock); 139 spin_unlock(&acpi_prt_lock);
143 140
144 return_VALUE(0); 141 return 0;
145} 142}
146 143
147static void 144static void
@@ -163,11 +160,10 @@ int acpi_pci_irq_add_prt(acpi_handle handle, int segment, int bus)
163 struct acpi_pci_routing_table *entry = NULL; 160 struct acpi_pci_routing_table *entry = NULL;
164 static int first_time = 1; 161 static int first_time = 1;
165 162
166 ACPI_FUNCTION_TRACE("acpi_pci_irq_add_prt");
167 163
168 pathname = (char *)kmalloc(ACPI_PATHNAME_MAX, GFP_KERNEL); 164 pathname = (char *)kmalloc(ACPI_PATHNAME_MAX, GFP_KERNEL);
169 if (!pathname) 165 if (!pathname)
170 return_VALUE(-ENOMEM); 166 return -ENOMEM;
171 memset(pathname, 0, ACPI_PATHNAME_MAX); 167 memset(pathname, 0, ACPI_PATHNAME_MAX);
172 168
173 if (first_time) { 169 if (first_time) {
@@ -197,24 +193,24 @@ int acpi_pci_irq_add_prt(acpi_handle handle, int segment, int bus)
197 kfree(pathname); 193 kfree(pathname);
198 status = acpi_get_irq_routing_table(handle, &buffer); 194 status = acpi_get_irq_routing_table(handle, &buffer);
199 if (status != AE_BUFFER_OVERFLOW) { 195 if (status != AE_BUFFER_OVERFLOW) {
200 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error evaluating _PRT [%s]\n", 196 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PRT [%s]",
201 acpi_format_exception(status))); 197 acpi_format_exception(status)));
202 return_VALUE(-ENODEV); 198 return -ENODEV;
203 } 199 }
204 200
205 prt = kmalloc(buffer.length, GFP_KERNEL); 201 prt = kmalloc(buffer.length, GFP_KERNEL);
206 if (!prt) { 202 if (!prt) {
207 return_VALUE(-ENOMEM); 203 return -ENOMEM;
208 } 204 }
209 memset(prt, 0, buffer.length); 205 memset(prt, 0, buffer.length);
210 buffer.pointer = prt; 206 buffer.pointer = prt;
211 207
212 status = acpi_get_irq_routing_table(handle, &buffer); 208 status = acpi_get_irq_routing_table(handle, &buffer);
213 if (ACPI_FAILURE(status)) { 209 if (ACPI_FAILURE(status)) {
214 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error evaluating _PRT [%s]\n", 210 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PRT [%s]",
215 acpi_format_exception(status))); 211 acpi_format_exception(status)));
216 kfree(buffer.pointer); 212 kfree(buffer.pointer);
217 return_VALUE(-ENODEV); 213 return -ENODEV;
218 } 214 }
219 215
220 entry = prt; 216 entry = prt;
@@ -227,7 +223,7 @@ int acpi_pci_irq_add_prt(acpi_handle handle, int segment, int bus)
227 223
228 kfree(prt); 224 kfree(prt);
229 225
230 return_VALUE(0); 226 return 0;
231} 227}
232 228
233void acpi_pci_irq_del_prt(int segment, int bus) 229void acpi_pci_irq_del_prt(int segment, int bus)
@@ -262,16 +258,15 @@ acpi_pci_allocate_irq(struct acpi_prt_entry *entry,
262{ 258{
263 int irq; 259 int irq;
264 260
265 ACPI_FUNCTION_TRACE("acpi_pci_allocate_irq");
266 261
267 if (entry->link.handle) { 262 if (entry->link.handle) {
268 irq = acpi_pci_link_allocate_irq(entry->link.handle, 263 irq = acpi_pci_link_allocate_irq(entry->link.handle,
269 entry->link.index, triggering, 264 entry->link.index, triggering,
270 polarity, link); 265 polarity, link);
271 if (irq < 0) { 266 if (irq < 0) {
272 ACPI_DEBUG_PRINT((ACPI_DB_WARN, 267 printk(KERN_WARNING PREFIX
273 "Invalid IRQ link routing entry\n")); 268 "Invalid IRQ link routing entry\n");
274 return_VALUE(-1); 269 return -1;
275 } 270 }
276 } else { 271 } else {
277 irq = entry->link.index; 272 irq = entry->link.index;
@@ -280,7 +275,7 @@ acpi_pci_allocate_irq(struct acpi_prt_entry *entry,
280 } 275 }
281 276
282 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found IRQ %d\n", irq)); 277 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found IRQ %d\n", irq));
283 return_VALUE(irq); 278 return irq;
284} 279}
285 280
286static int 281static int
@@ -289,13 +284,12 @@ acpi_pci_free_irq(struct acpi_prt_entry *entry,
289{ 284{
290 int irq; 285 int irq;
291 286
292 ACPI_FUNCTION_TRACE("acpi_pci_free_irq");
293 if (entry->link.handle) { 287 if (entry->link.handle) {
294 irq = acpi_pci_link_free_irq(entry->link.handle); 288 irq = acpi_pci_link_free_irq(entry->link.handle);
295 } else { 289 } else {
296 irq = entry->link.index; 290 irq = entry->link.index;
297 } 291 }
298 return_VALUE(irq); 292 return irq;
299} 293}
300 294
301/* 295/*
@@ -315,7 +309,6 @@ acpi_pci_irq_lookup(struct pci_bus *bus,
315 int bus_nr = bus->number; 309 int bus_nr = bus->number;
316 int ret; 310 int ret;
317 311
318 ACPI_FUNCTION_TRACE("acpi_pci_irq_lookup");
319 312
320 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 313 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
321 "Searching for PRT entry for %02x:%02x:%02x[%c]\n", 314 "Searching for PRT entry for %02x:%02x:%02x[%c]\n",
@@ -324,11 +317,11 @@ acpi_pci_irq_lookup(struct pci_bus *bus,
324 entry = acpi_pci_irq_find_prt_entry(segment, bus_nr, device, pin); 317 entry = acpi_pci_irq_find_prt_entry(segment, bus_nr, device, pin);
325 if (!entry) { 318 if (!entry) {
326 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "PRT entry not found\n")); 319 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "PRT entry not found\n"));
327 return_VALUE(-1); 320 return -1;
328 } 321 }
329 322
330 ret = func(entry, triggering, polarity, link); 323 ret = func(entry, triggering, polarity, link);
331 return_VALUE(ret); 324 return ret;
332} 325}
333 326
334/* 327/*
@@ -346,10 +339,9 @@ acpi_pci_irq_derive(struct pci_dev *dev,
346 int irq = -1; 339 int irq = -1;
347 u8 bridge_pin = 0; 340 u8 bridge_pin = 0;
348 341
349 ACPI_FUNCTION_TRACE("acpi_pci_irq_derive");
350 342
351 if (!dev) 343 if (!dev)
352 return_VALUE(-EINVAL); 344 return -EINVAL;
353 345
354 /* 346 /*
355 * Attempt to derive an IRQ for this device from a parent bridge's 347 * Attempt to derive an IRQ for this device from a parent bridge's
@@ -366,7 +358,7 @@ acpi_pci_irq_derive(struct pci_dev *dev,
366 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 358 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
367 "No interrupt pin configured for device %s\n", 359 "No interrupt pin configured for device %s\n",
368 pci_name(bridge))); 360 pci_name(bridge)));
369 return_VALUE(-1); 361 return -1;
370 } 362 }
371 /* Pin is from 0 to 3 */ 363 /* Pin is from 0 to 3 */
372 bridge_pin--; 364 bridge_pin--;
@@ -379,16 +371,15 @@ acpi_pci_irq_derive(struct pci_dev *dev,
379 } 371 }
380 372
381 if (irq < 0) { 373 if (irq < 0) {
382 ACPI_DEBUG_PRINT((ACPI_DB_WARN, 374 printk(KERN_WARNING PREFIX "Unable to derive IRQ for device %s\n",
383 "Unable to derive IRQ for device %s\n", 375 pci_name(dev));
384 pci_name(dev))); 376 return -1;
385 return_VALUE(-1);
386 } 377 }
387 378
388 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Derive IRQ %d for device %s from %s\n", 379 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Derive IRQ %d for device %s from %s\n",
389 irq, pci_name(dev), pci_name(bridge))); 380 irq, pci_name(dev), pci_name(bridge)));
390 381
391 return_VALUE(irq); 382 return irq;
392} 383}
393 384
394/* 385/*
@@ -406,24 +397,22 @@ int acpi_pci_irq_enable(struct pci_dev *dev)
406 char *link = NULL; 397 char *link = NULL;
407 int rc; 398 int rc;
408 399
409 ACPI_FUNCTION_TRACE("acpi_pci_irq_enable");
410 400
411 if (!dev) 401 if (!dev)
412 return_VALUE(-EINVAL); 402 return -EINVAL;
413 403
414 pin = dev->pin; 404 pin = dev->pin;
415 if (!pin) { 405 if (!pin) {
416 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 406 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
417 "No interrupt pin configured for device %s\n", 407 "No interrupt pin configured for device %s\n",
418 pci_name(dev))); 408 pci_name(dev)));
419 return_VALUE(0); 409 return 0;
420 } 410 }
421 pin--; 411 pin--;
422 412
423 if (!dev->bus) { 413 if (!dev->bus) {
424 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 414 printk(KERN_ERR PREFIX "Invalid (NULL) 'bus' field\n");
425 "Invalid (NULL) 'bus' field\n")); 415 return -ENODEV;
426 return_VALUE(-ENODEV);
427 } 416 }
428 417
429 /* 418 /*
@@ -455,10 +444,10 @@ int acpi_pci_irq_enable(struct pci_dev *dev)
455 printk(" - using IRQ %d\n", dev->irq); 444 printk(" - using IRQ %d\n", dev->irq);
456 acpi_register_gsi(dev->irq, ACPI_LEVEL_SENSITIVE, 445 acpi_register_gsi(dev->irq, ACPI_LEVEL_SENSITIVE,
457 ACPI_ACTIVE_LOW); 446 ACPI_ACTIVE_LOW);
458 return_VALUE(0); 447 return 0;
459 } else { 448 } else {
460 printk("\n"); 449 printk("\n");
461 return_VALUE(0); 450 return 0;
462 } 451 }
463 } 452 }
464 453
@@ -466,7 +455,7 @@ int acpi_pci_irq_enable(struct pci_dev *dev)
466 if (rc < 0) { 455 if (rc < 0) {
467 printk(KERN_WARNING PREFIX "PCI Interrupt %s[%c]: failed " 456 printk(KERN_WARNING PREFIX "PCI Interrupt %s[%c]: failed "
468 "to register GSI\n", pci_name(dev), ('A' + pin)); 457 "to register GSI\n", pci_name(dev), ('A' + pin));
469 return_VALUE(rc); 458 return rc;
470 } 459 }
471 dev->irq = rc; 460 dev->irq = rc;
472 461
@@ -480,7 +469,7 @@ int acpi_pci_irq_enable(struct pci_dev *dev)
480 (triggering == ACPI_LEVEL_SENSITIVE) ? "level" : "edge", 469 (triggering == ACPI_LEVEL_SENSITIVE) ? "level" : "edge",
481 (polarity == ACPI_ACTIVE_LOW) ? "low" : "high", dev->irq); 470 (polarity == ACPI_ACTIVE_LOW) ? "low" : "high", dev->irq);
482 471
483 return_VALUE(0); 472 return 0;
484} 473}
485 474
486EXPORT_SYMBOL(acpi_pci_irq_enable); 475EXPORT_SYMBOL(acpi_pci_irq_enable);
@@ -497,14 +486,13 @@ void acpi_pci_irq_disable(struct pci_dev *dev)
497 int triggering = ACPI_LEVEL_SENSITIVE; 486 int triggering = ACPI_LEVEL_SENSITIVE;
498 int polarity = ACPI_ACTIVE_LOW; 487 int polarity = ACPI_ACTIVE_LOW;
499 488
500 ACPI_FUNCTION_TRACE("acpi_pci_irq_disable");
501 489
502 if (!dev || !dev->bus) 490 if (!dev || !dev->bus)
503 return_VOID; 491 return;
504 492
505 pin = dev->pin; 493 pin = dev->pin;
506 if (!pin) 494 if (!pin)
507 return_VOID; 495 return;
508 pin--; 496 pin--;
509 497
510 /* 498 /*
@@ -522,7 +510,7 @@ void acpi_pci_irq_disable(struct pci_dev *dev)
522 &triggering, &polarity, NULL, 510 &triggering, &polarity, NULL,
523 acpi_pci_free_irq); 511 acpi_pci_free_irq);
524 if (gsi < 0) 512 if (gsi < 0)
525 return_VOID; 513 return;
526 514
527 /* 515 /*
528 * TBD: It might be worth clearing dev->irq by magic constant 516 * TBD: It might be worth clearing dev->irq by magic constant
@@ -534,5 +522,5 @@ void acpi_pci_irq_disable(struct pci_dev *dev)
534 522
535 acpi_unregister_gsi(gsi); 523 acpi_unregister_gsi(gsi);
536 524
537 return_VOID; 525 return;
538} 526}
diff --git a/drivers/acpi/pci_link.c b/drivers/acpi/pci_link.c
index 228bdb626502..7f3e7e77e794 100644
--- a/drivers/acpi/pci_link.c
+++ b/drivers/acpi/pci_link.c
@@ -83,7 +83,6 @@ struct acpi_pci_link_irq {
83struct acpi_pci_link { 83struct acpi_pci_link {
84 struct list_head node; 84 struct list_head node;
85 struct acpi_device *device; 85 struct acpi_device *device;
86 acpi_handle handle;
87 struct acpi_pci_link_irq irq; 86 struct acpi_pci_link_irq irq;
88 int refcnt; 87 int refcnt;
89}; 88};
@@ -107,26 +106,23 @@ acpi_pci_link_check_possible(struct acpi_resource *resource, void *context)
107 struct acpi_pci_link *link = (struct acpi_pci_link *)context; 106 struct acpi_pci_link *link = (struct acpi_pci_link *)context;
108 u32 i = 0; 107 u32 i = 0;
109 108
110 ACPI_FUNCTION_TRACE("acpi_pci_link_check_possible");
111 109
112 switch (resource->type) { 110 switch (resource->type) {
113 case ACPI_RESOURCE_TYPE_START_DEPENDENT: 111 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
114 return_ACPI_STATUS(AE_OK); 112 return AE_OK;
115 case ACPI_RESOURCE_TYPE_IRQ: 113 case ACPI_RESOURCE_TYPE_IRQ:
116 { 114 {
117 struct acpi_resource_irq *p = &resource->data.irq; 115 struct acpi_resource_irq *p = &resource->data.irq;
118 if (!p || !p->interrupt_count) { 116 if (!p || !p->interrupt_count) {
119 ACPI_DEBUG_PRINT((ACPI_DB_WARN, 117 printk(KERN_WARNING PREFIX "Blank IRQ resource\n");
120 "Blank IRQ resource\n")); 118 return AE_OK;
121 return_ACPI_STATUS(AE_OK);
122 } 119 }
123 for (i = 0; 120 for (i = 0;
124 (i < p->interrupt_count 121 (i < p->interrupt_count
125 && i < ACPI_PCI_LINK_MAX_POSSIBLE); i++) { 122 && i < ACPI_PCI_LINK_MAX_POSSIBLE); i++) {
126 if (!p->interrupts[i]) { 123 if (!p->interrupts[i]) {
127 ACPI_DEBUG_PRINT((ACPI_DB_WARN, 124 printk(KERN_WARNING PREFIX "Invalid IRQ %d\n",
128 "Invalid IRQ %d\n", 125 p->interrupts[i]);
129 p->interrupts[i]));
130 continue; 126 continue;
131 } 127 }
132 link->irq.possible[i] = p->interrupts[i]; 128 link->irq.possible[i] = p->interrupts[i];
@@ -142,17 +138,16 @@ acpi_pci_link_check_possible(struct acpi_resource *resource, void *context)
142 struct acpi_resource_extended_irq *p = 138 struct acpi_resource_extended_irq *p =
143 &resource->data.extended_irq; 139 &resource->data.extended_irq;
144 if (!p || !p->interrupt_count) { 140 if (!p || !p->interrupt_count) {
145 ACPI_DEBUG_PRINT((ACPI_DB_WARN, 141 printk(KERN_WARNING PREFIX
146 "Blank EXT IRQ resource\n")); 142 "Blank EXT IRQ resource\n");
147 return_ACPI_STATUS(AE_OK); 143 return AE_OK;
148 } 144 }
149 for (i = 0; 145 for (i = 0;
150 (i < p->interrupt_count 146 (i < p->interrupt_count
151 && i < ACPI_PCI_LINK_MAX_POSSIBLE); i++) { 147 && i < ACPI_PCI_LINK_MAX_POSSIBLE); i++) {
152 if (!p->interrupts[i]) { 148 if (!p->interrupts[i]) {
153 ACPI_DEBUG_PRINT((ACPI_DB_WARN, 149 printk(KERN_WARNING PREFIX "Invalid IRQ %d\n",
154 "Invalid IRQ %d\n", 150 p->interrupts[i]);
155 p->interrupts[i]));
156 continue; 151 continue;
157 } 152 }
158 link->irq.possible[i] = p->interrupts[i]; 153 link->irq.possible[i] = p->interrupts[i];
@@ -164,35 +159,33 @@ acpi_pci_link_check_possible(struct acpi_resource *resource, void *context)
164 break; 159 break;
165 } 160 }
166 default: 161 default:
167 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 162 printk(KERN_ERR PREFIX "Resource is not an IRQ entry\n");
168 "Resource is not an IRQ entry\n")); 163 return AE_OK;
169 return_ACPI_STATUS(AE_OK);
170 } 164 }
171 165
172 return_ACPI_STATUS(AE_CTRL_TERMINATE); 166 return AE_CTRL_TERMINATE;
173} 167}
174 168
175static int acpi_pci_link_get_possible(struct acpi_pci_link *link) 169static int acpi_pci_link_get_possible(struct acpi_pci_link *link)
176{ 170{
177 acpi_status status; 171 acpi_status status;
178 172
179 ACPI_FUNCTION_TRACE("acpi_pci_link_get_possible");
180 173
181 if (!link) 174 if (!link)
182 return_VALUE(-EINVAL); 175 return -EINVAL;
183 176
184 status = acpi_walk_resources(link->handle, METHOD_NAME__PRS, 177 status = acpi_walk_resources(link->device->handle, METHOD_NAME__PRS,
185 acpi_pci_link_check_possible, link); 178 acpi_pci_link_check_possible, link);
186 if (ACPI_FAILURE(status)) { 179 if (ACPI_FAILURE(status)) {
187 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error evaluating _PRS\n")); 180 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PRS"));
188 return_VALUE(-ENODEV); 181 return -ENODEV;
189 } 182 }
190 183
191 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 184 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
192 "Found %d possible IRQs\n", 185 "Found %d possible IRQs\n",
193 link->irq.possible_count)); 186 link->irq.possible_count));
194 187
195 return_VALUE(0); 188 return 0;
196} 189}
197 190
198static acpi_status 191static acpi_status
@@ -200,7 +193,6 @@ acpi_pci_link_check_current(struct acpi_resource *resource, void *context)
200{ 193{
201 int *irq = (int *)context; 194 int *irq = (int *)context;
202 195
203 ACPI_FUNCTION_TRACE("acpi_pci_link_check_current");
204 196
205 switch (resource->type) { 197 switch (resource->type) {
206 case ACPI_RESOURCE_TYPE_IRQ: 198 case ACPI_RESOURCE_TYPE_IRQ:
@@ -213,7 +205,7 @@ acpi_pci_link_check_current(struct acpi_resource *resource, void *context)
213 */ 205 */
214 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 206 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
215 "Blank IRQ resource\n")); 207 "Blank IRQ resource\n"));
216 return_ACPI_STATUS(AE_OK); 208 return AE_OK;
217 } 209 }
218 *irq = p->interrupts[0]; 210 *irq = p->interrupts[0];
219 break; 211 break;
@@ -227,20 +219,20 @@ acpi_pci_link_check_current(struct acpi_resource *resource, void *context)
227 * extended IRQ descriptors must 219 * extended IRQ descriptors must
228 * return at least 1 IRQ 220 * return at least 1 IRQ
229 */ 221 */
230 ACPI_DEBUG_PRINT((ACPI_DB_WARN, 222 printk(KERN_WARNING PREFIX
231 "Blank EXT IRQ resource\n")); 223 "Blank EXT IRQ resource\n");
232 return_ACPI_STATUS(AE_OK); 224 return AE_OK;
233 } 225 }
234 *irq = p->interrupts[0]; 226 *irq = p->interrupts[0];
235 break; 227 break;
236 } 228 }
237 break; 229 break;
238 default: 230 default:
239 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Resource %d isn't an IRQ\n", resource->type)); 231 printk(KERN_ERR PREFIX "Resource %d isn't an IRQ\n", resource->type);
240 case ACPI_RESOURCE_TYPE_END_TAG: 232 case ACPI_RESOURCE_TYPE_END_TAG:
241 return_ACPI_STATUS(AE_OK); 233 return AE_OK;
242 } 234 }
243 return_ACPI_STATUS(AE_CTRL_TERMINATE); 235 return AE_CTRL_TERMINATE;
244} 236}
245 237
246/* 238/*
@@ -256,10 +248,8 @@ static int acpi_pci_link_get_current(struct acpi_pci_link *link)
256 acpi_status status = AE_OK; 248 acpi_status status = AE_OK;
257 int irq = 0; 249 int irq = 0;
258 250
259 ACPI_FUNCTION_TRACE("acpi_pci_link_get_current"); 251 if (!link)
260 252 return -EINVAL;
261 if (!link || !link->handle)
262 return_VALUE(-EINVAL);
263 253
264 link->irq.active = 0; 254 link->irq.active = 0;
265 255
@@ -268,14 +258,13 @@ static int acpi_pci_link_get_current(struct acpi_pci_link *link)
268 /* Query _STA, set link->device->status */ 258 /* Query _STA, set link->device->status */
269 result = acpi_bus_get_status(link->device); 259 result = acpi_bus_get_status(link->device);
270 if (result) { 260 if (result) {
271 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 261 printk(KERN_ERR PREFIX "Unable to read status\n");
272 "Unable to read status\n"));
273 goto end; 262 goto end;
274 } 263 }
275 264
276 if (!link->device->status.enabled) { 265 if (!link->device->status.enabled) {
277 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Link disabled\n")); 266 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Link disabled\n"));
278 return_VALUE(0); 267 return 0;
279 } 268 }
280 } 269 }
281 270
@@ -283,16 +272,16 @@ static int acpi_pci_link_get_current(struct acpi_pci_link *link)
283 * Query and parse _CRS to get the current IRQ assignment. 272 * Query and parse _CRS to get the current IRQ assignment.
284 */ 273 */
285 274
286 status = acpi_walk_resources(link->handle, METHOD_NAME__CRS, 275 status = acpi_walk_resources(link->device->handle, METHOD_NAME__CRS,
287 acpi_pci_link_check_current, &irq); 276 acpi_pci_link_check_current, &irq);
288 if (ACPI_FAILURE(status)) { 277 if (ACPI_FAILURE(status)) {
289 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error evaluating _CRS\n")); 278 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _CRS"));
290 result = -ENODEV; 279 result = -ENODEV;
291 goto end; 280 goto end;
292 } 281 }
293 282
294 if (acpi_strict && !irq) { 283 if (acpi_strict && !irq) {
295 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "_CRS returned 0\n")); 284 printk(KERN_ERR PREFIX "_CRS returned 0\n");
296 result = -ENODEV; 285 result = -ENODEV;
297 } 286 }
298 287
@@ -301,7 +290,7 @@ static int acpi_pci_link_get_current(struct acpi_pci_link *link)
301 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Link at IRQ %d \n", link->irq.active)); 290 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Link at IRQ %d \n", link->irq.active));
302 291
303 end: 292 end:
304 return_VALUE(result); 293 return result;
305} 294}
306 295
307static int acpi_pci_link_set(struct acpi_pci_link *link, int irq) 296static int acpi_pci_link_set(struct acpi_pci_link *link, int irq)
@@ -314,14 +303,13 @@ static int acpi_pci_link_set(struct acpi_pci_link *link, int irq)
314 } *resource; 303 } *resource;
315 struct acpi_buffer buffer = { 0, NULL }; 304 struct acpi_buffer buffer = { 0, NULL };
316 305
317 ACPI_FUNCTION_TRACE("acpi_pci_link_set");
318 306
319 if (!link || !irq) 307 if (!link || !irq)
320 return_VALUE(-EINVAL); 308 return -EINVAL;
321 309
322 resource = kmalloc(sizeof(*resource) + 1, GFP_ATOMIC); 310 resource = kmalloc(sizeof(*resource) + 1, GFP_ATOMIC);
323 if (!resource) 311 if (!resource)
324 return_VALUE(-ENOMEM); 312 return -ENOMEM;
325 313
326 memset(resource, 0, sizeof(*resource) + 1); 314 memset(resource, 0, sizeof(*resource) + 1);
327 buffer.length = sizeof(*resource) + 1; 315 buffer.length = sizeof(*resource) + 1;
@@ -362,7 +350,7 @@ static int acpi_pci_link_set(struct acpi_pci_link *link, int irq)
362 /* ignore resource_source, it's optional */ 350 /* ignore resource_source, it's optional */
363 break; 351 break;
364 default: 352 default:
365 printk("ACPI BUG: resource_type %d\n", link->irq.resource_type); 353 printk(KERN_ERR PREFIX "Invalid Resource_type %d\n", link->irq.resource_type);
366 result = -EINVAL; 354 result = -EINVAL;
367 goto end; 355 goto end;
368 356
@@ -370,11 +358,11 @@ static int acpi_pci_link_set(struct acpi_pci_link *link, int irq)
370 resource->end.type = ACPI_RESOURCE_TYPE_END_TAG; 358 resource->end.type = ACPI_RESOURCE_TYPE_END_TAG;
371 359
372 /* Attempt to set the resource */ 360 /* Attempt to set the resource */
373 status = acpi_set_current_resources(link->handle, &buffer); 361 status = acpi_set_current_resources(link->device->handle, &buffer);
374 362
375 /* check for total failure */ 363 /* check for total failure */
376 if (ACPI_FAILURE(status)) { 364 if (ACPI_FAILURE(status)) {
377 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error evaluating _SRS\n")); 365 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _SRS"));
378 result = -ENODEV; 366 result = -ENODEV;
379 goto end; 367 goto end;
380 } 368 }
@@ -382,14 +370,14 @@ static int acpi_pci_link_set(struct acpi_pci_link *link, int irq)
382 /* Query _STA, set device->status */ 370 /* Query _STA, set device->status */
383 result = acpi_bus_get_status(link->device); 371 result = acpi_bus_get_status(link->device);
384 if (result) { 372 if (result) {
385 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Unable to read status\n")); 373 printk(KERN_ERR PREFIX "Unable to read status\n");
386 goto end; 374 goto end;
387 } 375 }
388 if (!link->device->status.enabled) { 376 if (!link->device->status.enabled) {
389 printk(KERN_WARNING PREFIX 377 printk(KERN_WARNING PREFIX
390 "%s [%s] disabled and referenced, BIOS bug.\n", 378 "%s [%s] disabled and referenced, BIOS bug\n",
391 acpi_device_name(link->device), 379 acpi_device_name(link->device),
392 acpi_device_bid(link->device)); 380 acpi_device_bid(link->device));
393 } 381 }
394 382
395 /* Query _CRS, set link->irq.active */ 383 /* Query _CRS, set link->irq.active */
@@ -408,9 +396,9 @@ static int acpi_pci_link_set(struct acpi_pci_link *link, int irq)
408 * assume _SRS worked and override _CRS value. 396 * assume _SRS worked and override _CRS value.
409 */ 397 */
410 printk(KERN_WARNING PREFIX 398 printk(KERN_WARNING PREFIX
411 "%s [%s] BIOS reported IRQ %d, using IRQ %d\n", 399 "%s [%s] BIOS reported IRQ %d, using IRQ %d\n",
412 acpi_device_name(link->device), 400 acpi_device_name(link->device),
413 acpi_device_bid(link->device), link->irq.active, irq); 401 acpi_device_bid(link->device), link->irq.active, irq);
414 link->irq.active = irq; 402 link->irq.active = irq;
415 } 403 }
416 404
@@ -418,7 +406,7 @@ static int acpi_pci_link_set(struct acpi_pci_link *link, int irq)
418 406
419 end: 407 end:
420 kfree(resource); 408 kfree(resource);
421 return_VALUE(result); 409 return result;
422} 410}
423 411
424/* -------------------------------------------------------------------------- 412/* --------------------------------------------------------------------------
@@ -492,7 +480,6 @@ int __init acpi_irq_penalty_init(void)
492 struct acpi_pci_link *link = NULL; 480 struct acpi_pci_link *link = NULL;
493 int i = 0; 481 int i = 0;
494 482
495 ACPI_FUNCTION_TRACE("acpi_irq_penalty_init");
496 483
497 /* 484 /*
498 * Update penalties to facilitate IRQ balancing. 485 * Update penalties to facilitate IRQ balancing.
@@ -501,8 +488,7 @@ int __init acpi_irq_penalty_init(void)
501 488
502 link = list_entry(node, struct acpi_pci_link, node); 489 link = list_entry(node, struct acpi_pci_link, node);
503 if (!link) { 490 if (!link) {
504 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 491 printk(KERN_ERR PREFIX "Invalid link context\n");
505 "Invalid link context\n"));
506 continue; 492 continue;
507 } 493 }
508 494
@@ -530,7 +516,7 @@ int __init acpi_irq_penalty_init(void)
530 /* Add a penalty for the SCI */ 516 /* Add a penalty for the SCI */
531 acpi_irq_penalty[acpi_fadt.sci_int] += PIRQ_PENALTY_PCI_USING; 517 acpi_irq_penalty[acpi_fadt.sci_int] += PIRQ_PENALTY_PCI_USING;
532 518
533 return_VALUE(0); 519 return 0;
534} 520}
535 521
536static int acpi_irq_balance; /* 0: static, 1: balance */ 522static int acpi_irq_balance; /* 0: static, 1: balance */
@@ -540,13 +526,12 @@ static int acpi_pci_link_allocate(struct acpi_pci_link *link)
540 int irq; 526 int irq;
541 int i; 527 int i;
542 528
543 ACPI_FUNCTION_TRACE("acpi_pci_link_allocate");
544 529
545 if (link->irq.initialized) { 530 if (link->irq.initialized) {
546 if (link->refcnt == 0) 531 if (link->refcnt == 0)
547 /* This means the link is disabled but initialized */ 532 /* This means the link is disabled but initialized */
548 acpi_pci_link_set(link, link->irq.active); 533 acpi_pci_link_set(link, link->irq.active);
549 return_VALUE(0); 534 return 0;
550 } 535 }
551 536
552 /* 537 /*
@@ -562,7 +547,7 @@ static int acpi_pci_link_allocate(struct acpi_pci_link *link)
562 if (i == link->irq.possible_count) { 547 if (i == link->irq.possible_count) {
563 if (acpi_strict) 548 if (acpi_strict)
564 printk(KERN_WARNING PREFIX "_CRS %d not found" 549 printk(KERN_WARNING PREFIX "_CRS %d not found"
565 " in _PRS\n", link->irq.active); 550 " in _PRS\n", link->irq.active);
566 link->irq.active = 0; 551 link->irq.active = 0;
567 } 552 }
568 553
@@ -589,12 +574,11 @@ static int acpi_pci_link_allocate(struct acpi_pci_link *link)
589 574
590 /* Attempt to enable the link device at this IRQ. */ 575 /* Attempt to enable the link device at this IRQ. */
591 if (acpi_pci_link_set(link, irq)) { 576 if (acpi_pci_link_set(link, irq)) {
592 printk(PREFIX 577 printk(KERN_ERR PREFIX "Unable to set IRQ for %s [%s]. "
593 "Unable to set IRQ for %s [%s] (likely buggy ACPI BIOS).\n" 578 "Try pci=noacpi or acpi=off\n",
594 "Try pci=noacpi or acpi=off\n", 579 acpi_device_name(link->device),
595 acpi_device_name(link->device), 580 acpi_device_bid(link->device));
596 acpi_device_bid(link->device)); 581 return -ENODEV;
597 return_VALUE(-ENODEV);
598 } else { 582 } else {
599 acpi_irq_penalty[link->irq.active] += PIRQ_PENALTY_PCI_USING; 583 acpi_irq_penalty[link->irq.active] += PIRQ_PENALTY_PCI_USING;
600 printk(PREFIX "%s [%s] enabled at IRQ %d\n", 584 printk(PREFIX "%s [%s] enabled at IRQ %d\n",
@@ -604,7 +588,7 @@ static int acpi_pci_link_allocate(struct acpi_pci_link *link)
604 588
605 link->irq.initialized = 1; 589 link->irq.initialized = 1;
606 590
607 return_VALUE(0); 591 return 0;
608} 592}
609 593
610/* 594/*
@@ -622,36 +606,35 @@ acpi_pci_link_allocate_irq(acpi_handle handle,
622 struct acpi_device *device = NULL; 606 struct acpi_device *device = NULL;
623 struct acpi_pci_link *link = NULL; 607 struct acpi_pci_link *link = NULL;
624 608
625 ACPI_FUNCTION_TRACE("acpi_pci_link_allocate_irq");
626 609
627 result = acpi_bus_get_device(handle, &device); 610 result = acpi_bus_get_device(handle, &device);
628 if (result) { 611 if (result) {
629 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid link device\n")); 612 printk(KERN_ERR PREFIX "Invalid link device\n");
630 return_VALUE(-1); 613 return -1;
631 } 614 }
632 615
633 link = (struct acpi_pci_link *)acpi_driver_data(device); 616 link = (struct acpi_pci_link *)acpi_driver_data(device);
634 if (!link) { 617 if (!link) {
635 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid link context\n")); 618 printk(KERN_ERR PREFIX "Invalid link context\n");
636 return_VALUE(-1); 619 return -1;
637 } 620 }
638 621
639 /* TBD: Support multiple index (IRQ) entries per Link Device */ 622 /* TBD: Support multiple index (IRQ) entries per Link Device */
640 if (index) { 623 if (index) {
641 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid index %d\n", index)); 624 printk(KERN_ERR PREFIX "Invalid index %d\n", index);
642 return_VALUE(-1); 625 return -1;
643 } 626 }
644 627
645 mutex_lock(&acpi_link_lock); 628 mutex_lock(&acpi_link_lock);
646 if (acpi_pci_link_allocate(link)) { 629 if (acpi_pci_link_allocate(link)) {
647 mutex_unlock(&acpi_link_lock); 630 mutex_unlock(&acpi_link_lock);
648 return_VALUE(-1); 631 return -1;
649 } 632 }
650 633
651 if (!link->irq.active) { 634 if (!link->irq.active) {
652 mutex_unlock(&acpi_link_lock); 635 mutex_unlock(&acpi_link_lock);
653 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Link active IRQ is 0!\n")); 636 printk(KERN_ERR PREFIX "Link active IRQ is 0!\n");
654 return_VALUE(-1); 637 return -1;
655 } 638 }
656 link->refcnt++; 639 link->refcnt++;
657 mutex_unlock(&acpi_link_lock); 640 mutex_unlock(&acpi_link_lock);
@@ -665,7 +648,7 @@ acpi_pci_link_allocate_irq(acpi_handle handle,
665 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 648 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
666 "Link %s is referenced\n", 649 "Link %s is referenced\n",
667 acpi_device_bid(link->device))); 650 acpi_device_bid(link->device)));
668 return_VALUE(link->irq.active); 651 return (link->irq.active);
669} 652}
670 653
671/* 654/*
@@ -678,25 +661,24 @@ int acpi_pci_link_free_irq(acpi_handle handle)
678 struct acpi_pci_link *link = NULL; 661 struct acpi_pci_link *link = NULL;
679 acpi_status result; 662 acpi_status result;
680 663
681 ACPI_FUNCTION_TRACE("acpi_pci_link_free_irq");
682 664
683 result = acpi_bus_get_device(handle, &device); 665 result = acpi_bus_get_device(handle, &device);
684 if (result) { 666 if (result) {
685 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid link device\n")); 667 printk(KERN_ERR PREFIX "Invalid link device\n");
686 return_VALUE(-1); 668 return -1;
687 } 669 }
688 670
689 link = (struct acpi_pci_link *)acpi_driver_data(device); 671 link = (struct acpi_pci_link *)acpi_driver_data(device);
690 if (!link) { 672 if (!link) {
691 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid link context\n")); 673 printk(KERN_ERR PREFIX "Invalid link context\n");
692 return_VALUE(-1); 674 return -1;
693 } 675 }
694 676
695 mutex_lock(&acpi_link_lock); 677 mutex_lock(&acpi_link_lock);
696 if (!link->irq.initialized) { 678 if (!link->irq.initialized) {
697 mutex_unlock(&acpi_link_lock); 679 mutex_unlock(&acpi_link_lock);
698 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Link isn't initialized\n")); 680 printk(KERN_ERR PREFIX "Link isn't initialized\n");
699 return_VALUE(-1); 681 return -1;
700 } 682 }
701#ifdef FUTURE_USE 683#ifdef FUTURE_USE
702 /* 684 /*
@@ -715,10 +697,10 @@ int acpi_pci_link_free_irq(acpi_handle handle)
715 acpi_device_bid(link->device))); 697 acpi_device_bid(link->device)));
716 698
717 if (link->refcnt == 0) { 699 if (link->refcnt == 0) {
718 acpi_ut_evaluate_object(link->handle, "_DIS", 0, NULL); 700 acpi_ut_evaluate_object(link->device->handle, "_DIS", 0, NULL);
719 } 701 }
720 mutex_unlock(&acpi_link_lock); 702 mutex_unlock(&acpi_link_lock);
721 return_VALUE(link->irq.active); 703 return (link->irq.active);
722} 704}
723 705
724/* -------------------------------------------------------------------------- 706/* --------------------------------------------------------------------------
@@ -732,18 +714,16 @@ static int acpi_pci_link_add(struct acpi_device *device)
732 int i = 0; 714 int i = 0;
733 int found = 0; 715 int found = 0;
734 716
735 ACPI_FUNCTION_TRACE("acpi_pci_link_add");
736 717
737 if (!device) 718 if (!device)
738 return_VALUE(-EINVAL); 719 return -EINVAL;
739 720
740 link = kmalloc(sizeof(struct acpi_pci_link), GFP_KERNEL); 721 link = kmalloc(sizeof(struct acpi_pci_link), GFP_KERNEL);
741 if (!link) 722 if (!link)
742 return_VALUE(-ENOMEM); 723 return -ENOMEM;
743 memset(link, 0, sizeof(struct acpi_pci_link)); 724 memset(link, 0, sizeof(struct acpi_pci_link));
744 725
745 link->device = device; 726 link->device = device;
746 link->handle = device->handle;
747 strcpy(acpi_device_name(device), ACPI_PCI_LINK_DEVICE_NAME); 727 strcpy(acpi_device_name(device), ACPI_PCI_LINK_DEVICE_NAME);
748 strcpy(acpi_device_class(device), ACPI_PCI_LINK_CLASS); 728 strcpy(acpi_device_class(device), ACPI_PCI_LINK_CLASS);
749 acpi_driver_data(device) = link; 729 acpi_driver_data(device) = link;
@@ -782,62 +762,51 @@ static int acpi_pci_link_add(struct acpi_device *device)
782 762
783 end: 763 end:
784 /* disable all links -- to be activated on use */ 764 /* disable all links -- to be activated on use */
785 acpi_ut_evaluate_object(link->handle, "_DIS", 0, NULL); 765 acpi_ut_evaluate_object(device->handle, "_DIS", 0, NULL);
786 mutex_unlock(&acpi_link_lock); 766 mutex_unlock(&acpi_link_lock);
787 767
788 if (result) 768 if (result)
789 kfree(link); 769 kfree(link);
790 770
791 return_VALUE(result); 771 return result;
792} 772}
793 773
794static int acpi_pci_link_resume(struct acpi_pci_link *link) 774static int acpi_pci_link_resume(struct acpi_pci_link *link)
795{ 775{
796 ACPI_FUNCTION_TRACE("acpi_pci_link_resume");
797 776
798 if (link->refcnt && link->irq.active && link->irq.initialized) 777 if (link->refcnt && link->irq.active && link->irq.initialized)
799 return_VALUE(acpi_pci_link_set(link, link->irq.active)); 778 return (acpi_pci_link_set(link, link->irq.active));
800 else 779 else
801 return_VALUE(0); 780 return 0;
802} 781}
803 782
804/*
805 * FIXME: this is a workaround to avoid nasty warning. It will be removed
806 * after every device calls pci_disable_device in .resume.
807 */
808int acpi_in_resume;
809static int irqrouter_resume(struct sys_device *dev) 783static int irqrouter_resume(struct sys_device *dev)
810{ 784{
811 struct list_head *node = NULL; 785 struct list_head *node = NULL;
812 struct acpi_pci_link *link = NULL; 786 struct acpi_pci_link *link = NULL;
813 787
814 ACPI_FUNCTION_TRACE("irqrouter_resume");
815 788
816 /* Make sure SCI is enabled again (Apple firmware bug?) */ 789 /* Make sure SCI is enabled again (Apple firmware bug?) */
817 acpi_set_register(ACPI_BITREG_SCI_ENABLE, 1, ACPI_MTX_DO_NOT_LOCK); 790 acpi_set_register(ACPI_BITREG_SCI_ENABLE, 1, ACPI_MTX_DO_NOT_LOCK);
818 791
819 acpi_in_resume = 1;
820 list_for_each(node, &acpi_link.entries) { 792 list_for_each(node, &acpi_link.entries) {
821 link = list_entry(node, struct acpi_pci_link, node); 793 link = list_entry(node, struct acpi_pci_link, node);
822 if (!link) { 794 if (!link) {
823 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 795 printk(KERN_ERR PREFIX "Invalid link context\n");
824 "Invalid link context\n"));
825 continue; 796 continue;
826 } 797 }
827 acpi_pci_link_resume(link); 798 acpi_pci_link_resume(link);
828 } 799 }
829 acpi_in_resume = 0; 800 return 0;
830 return_VALUE(0);
831} 801}
832 802
833static int acpi_pci_link_remove(struct acpi_device *device, int type) 803static int acpi_pci_link_remove(struct acpi_device *device, int type)
834{ 804{
835 struct acpi_pci_link *link = NULL; 805 struct acpi_pci_link *link = NULL;
836 806
837 ACPI_FUNCTION_TRACE("acpi_pci_link_remove");
838 807
839 if (!device || !acpi_driver_data(device)) 808 if (!device || !acpi_driver_data(device))
840 return_VALUE(-EINVAL); 809 return -EINVAL;
841 810
842 link = (struct acpi_pci_link *)acpi_driver_data(device); 811 link = (struct acpi_pci_link *)acpi_driver_data(device);
843 812
@@ -847,7 +816,7 @@ static int acpi_pci_link_remove(struct acpi_device *device, int type)
847 816
848 kfree(link); 817 kfree(link);
849 818
850 return_VALUE(0); 819 return 0;
851} 820}
852 821
853/* 822/*
@@ -953,34 +922,32 @@ static int __init irqrouter_init_sysfs(void)
953{ 922{
954 int error; 923 int error;
955 924
956 ACPI_FUNCTION_TRACE("irqrouter_init_sysfs");
957 925
958 if (acpi_disabled || acpi_noirq) 926 if (acpi_disabled || acpi_noirq)
959 return_VALUE(0); 927 return 0;
960 928
961 error = sysdev_class_register(&irqrouter_sysdev_class); 929 error = sysdev_class_register(&irqrouter_sysdev_class);
962 if (!error) 930 if (!error)
963 error = sysdev_register(&device_irqrouter); 931 error = sysdev_register(&device_irqrouter);
964 932
965 return_VALUE(error); 933 return error;
966} 934}
967 935
968device_initcall(irqrouter_init_sysfs); 936device_initcall(irqrouter_init_sysfs);
969 937
970static int __init acpi_pci_link_init(void) 938static int __init acpi_pci_link_init(void)
971{ 939{
972 ACPI_FUNCTION_TRACE("acpi_pci_link_init");
973 940
974 if (acpi_noirq) 941 if (acpi_noirq)
975 return_VALUE(0); 942 return 0;
976 943
977 acpi_link.count = 0; 944 acpi_link.count = 0;
978 INIT_LIST_HEAD(&acpi_link.entries); 945 INIT_LIST_HEAD(&acpi_link.entries);
979 946
980 if (acpi_bus_register_driver(&acpi_pci_link_driver) < 0) 947 if (acpi_bus_register_driver(&acpi_pci_link_driver) < 0)
981 return_VALUE(-ENODEV); 948 return -ENODEV;
982 949
983 return_VALUE(0); 950 return 0;
984} 951}
985 952
986subsys_initcall(acpi_pci_link_init); 953subsys_initcall(acpi_pci_link_init);
diff --git a/drivers/acpi/pci_root.c b/drivers/acpi/pci_root.c
index 4c313eab6313..0984a1ee24ed 100644
--- a/drivers/acpi/pci_root.c
+++ b/drivers/acpi/pci_root.c
@@ -58,7 +58,7 @@ static struct acpi_driver acpi_pci_root_driver = {
58 58
59struct acpi_pci_root { 59struct acpi_pci_root {
60 struct list_head node; 60 struct list_head node;
61 acpi_handle handle; 61 struct acpi_device * device;
62 struct acpi_pci_id id; 62 struct acpi_pci_id id;
63 struct pci_bus *bus; 63 struct pci_bus *bus;
64}; 64};
@@ -83,7 +83,7 @@ int acpi_pci_register_driver(struct acpi_pci_driver *driver)
83 list_for_each(entry, &acpi_pci_roots) { 83 list_for_each(entry, &acpi_pci_roots) {
84 struct acpi_pci_root *root; 84 struct acpi_pci_root *root;
85 root = list_entry(entry, struct acpi_pci_root, node); 85 root = list_entry(entry, struct acpi_pci_root, node);
86 driver->add(root->handle); 86 driver->add(root->device->handle);
87 n++; 87 n++;
88 } 88 }
89 89
@@ -110,7 +110,7 @@ void acpi_pci_unregister_driver(struct acpi_pci_driver *driver)
110 list_for_each(entry, &acpi_pci_roots) { 110 list_for_each(entry, &acpi_pci_roots) {
111 struct acpi_pci_root *root; 111 struct acpi_pci_root *root;
112 root = list_entry(entry, struct acpi_pci_root, node); 112 root = list_entry(entry, struct acpi_pci_root, node);
113 driver->remove(root->handle); 113 driver->remove(root->device->handle);
114 } 114 }
115} 115}
116 116
@@ -160,18 +160,17 @@ static int acpi_pci_root_add(struct acpi_device *device)
160 unsigned long value = 0; 160 unsigned long value = 0;
161 acpi_handle handle = NULL; 161 acpi_handle handle = NULL;
162 162
163 ACPI_FUNCTION_TRACE("acpi_pci_root_add");
164 163
165 if (!device) 164 if (!device)
166 return_VALUE(-EINVAL); 165 return -EINVAL;
167 166
168 root = kmalloc(sizeof(struct acpi_pci_root), GFP_KERNEL); 167 root = kmalloc(sizeof(struct acpi_pci_root), GFP_KERNEL);
169 if (!root) 168 if (!root)
170 return_VALUE(-ENOMEM); 169 return -ENOMEM;
171 memset(root, 0, sizeof(struct acpi_pci_root)); 170 memset(root, 0, sizeof(struct acpi_pci_root));
172 INIT_LIST_HEAD(&root->node); 171 INIT_LIST_HEAD(&root->node);
173 172
174 root->handle = device->handle; 173 root->device = device;
175 strcpy(acpi_device_name(device), ACPI_PCI_ROOT_DEVICE_NAME); 174 strcpy(acpi_device_name(device), ACPI_PCI_ROOT_DEVICE_NAME);
176 strcpy(acpi_device_class(device), ACPI_PCI_ROOT_CLASS); 175 strcpy(acpi_device_class(device), ACPI_PCI_ROOT_CLASS);
177 acpi_driver_data(device) = root; 176 acpi_driver_data(device) = root;
@@ -186,7 +185,7 @@ static int acpi_pci_root_add(struct acpi_device *device)
186 * ------- 185 * -------
187 * Obtained via _SEG, if exists, otherwise assumed to be zero (0). 186 * Obtained via _SEG, if exists, otherwise assumed to be zero (0).
188 */ 187 */
189 status = acpi_evaluate_integer(root->handle, METHOD_NAME__SEG, NULL, 188 status = acpi_evaluate_integer(device->handle, METHOD_NAME__SEG, NULL,
190 &value); 189 &value);
191 switch (status) { 190 switch (status) {
192 case AE_OK: 191 case AE_OK:
@@ -198,7 +197,7 @@ static int acpi_pci_root_add(struct acpi_device *device)
198 root->id.segment = 0; 197 root->id.segment = 0;
199 break; 198 break;
200 default: 199 default:
201 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error evaluating _SEG\n")); 200 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _SEG"));
202 result = -ENODEV; 201 result = -ENODEV;
203 goto end; 202 goto end;
204 } 203 }
@@ -208,7 +207,7 @@ static int acpi_pci_root_add(struct acpi_device *device)
208 * --- 207 * ---
209 * Obtained via _BBN, if exists, otherwise assumed to be zero (0). 208 * Obtained via _BBN, if exists, otherwise assumed to be zero (0).
210 */ 209 */
211 status = acpi_evaluate_integer(root->handle, METHOD_NAME__BBN, NULL, 210 status = acpi_evaluate_integer(device->handle, METHOD_NAME__BBN, NULL,
212 &value); 211 &value);
213 switch (status) { 212 switch (status) {
214 case AE_OK: 213 case AE_OK:
@@ -219,7 +218,7 @@ static int acpi_pci_root_add(struct acpi_device *device)
219 root->id.bus = 0; 218 root->id.bus = 0;
220 break; 219 break;
221 default: 220 default:
222 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error evaluating _BBN\n")); 221 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _BBN"));
223 result = -ENODEV; 222 result = -ENODEV;
224 goto end; 223 goto end;
225 } 224 }
@@ -231,10 +230,11 @@ static int acpi_pci_root_add(struct acpi_device *device)
231 int bus = 0; 230 int bus = 0;
232 acpi_status status; 231 acpi_status status;
233 232
234 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 233 printk(KERN_ERR PREFIX
235 "Wrong _BBN value, please reboot and using option 'pci=noacpi'\n")); 234 "Wrong _BBN value, reboot"
235 " and use option 'pci=noacpi'\n");
236 236
237 status = try_get_root_bridge_busnr(root->handle, &bus); 237 status = try_get_root_bridge_busnr(device->handle, &bus);
238 if (ACPI_FAILURE(status)) 238 if (ACPI_FAILURE(status))
239 break; 239 break;
240 if (bus != root->id.bus) { 240 if (bus != root->id.bus) {
@@ -273,9 +273,9 @@ static int acpi_pci_root_add(struct acpi_device *device)
273 */ 273 */
274 root->bus = pci_acpi_scan_root(device, root->id.segment, root->id.bus); 274 root->bus = pci_acpi_scan_root(device, root->id.segment, root->id.bus);
275 if (!root->bus) { 275 if (!root->bus) {
276 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 276 printk(KERN_ERR PREFIX
277 "Bus %04x:%02x not present in PCI namespace\n", 277 "Bus %04x:%02x not present in PCI namespace\n",
278 root->id.segment, root->id.bus)); 278 root->id.segment, root->id.bus);
279 result = -ENODEV; 279 result = -ENODEV;
280 goto end; 280 goto end;
281 } 281 }
@@ -294,9 +294,9 @@ static int acpi_pci_root_add(struct acpi_device *device)
294 * ----------------- 294 * -----------------
295 * Evaluate and parse _PRT, if exists. 295 * Evaluate and parse _PRT, if exists.
296 */ 296 */
297 status = acpi_get_handle(root->handle, METHOD_NAME__PRT, &handle); 297 status = acpi_get_handle(device->handle, METHOD_NAME__PRT, &handle);
298 if (ACPI_SUCCESS(status)) 298 if (ACPI_SUCCESS(status))
299 result = acpi_pci_irq_add_prt(root->handle, root->id.segment, 299 result = acpi_pci_irq_add_prt(device->handle, root->id.segment,
300 root->id.bus); 300 root->id.bus);
301 301
302 end: 302 end:
@@ -306,46 +306,43 @@ static int acpi_pci_root_add(struct acpi_device *device)
306 kfree(root); 306 kfree(root);
307 } 307 }
308 308
309 return_VALUE(result); 309 return result;
310} 310}
311 311
312static int acpi_pci_root_start(struct acpi_device *device) 312static int acpi_pci_root_start(struct acpi_device *device)
313{ 313{
314 struct acpi_pci_root *root; 314 struct acpi_pci_root *root;
315 315
316 ACPI_FUNCTION_TRACE("acpi_pci_root_start");
317 316
318 list_for_each_entry(root, &acpi_pci_roots, node) { 317 list_for_each_entry(root, &acpi_pci_roots, node) {
319 if (root->handle == device->handle) { 318 if (root->device == device) {
320 pci_bus_add_devices(root->bus); 319 pci_bus_add_devices(root->bus);
321 return_VALUE(0); 320 return 0;
322 } 321 }
323 } 322 }
324 return_VALUE(-ENODEV); 323 return -ENODEV;
325} 324}
326 325
327static int acpi_pci_root_remove(struct acpi_device *device, int type) 326static int acpi_pci_root_remove(struct acpi_device *device, int type)
328{ 327{
329 struct acpi_pci_root *root = NULL; 328 struct acpi_pci_root *root = NULL;
330 329
331 ACPI_FUNCTION_TRACE("acpi_pci_root_remove");
332 330
333 if (!device || !acpi_driver_data(device)) 331 if (!device || !acpi_driver_data(device))
334 return_VALUE(-EINVAL); 332 return -EINVAL;
335 333
336 root = (struct acpi_pci_root *)acpi_driver_data(device); 334 root = (struct acpi_pci_root *)acpi_driver_data(device);
337 335
338 kfree(root); 336 kfree(root);
339 337
340 return_VALUE(0); 338 return 0;
341} 339}
342 340
343static int __init acpi_pci_root_init(void) 341static int __init acpi_pci_root_init(void)
344{ 342{
345 ACPI_FUNCTION_TRACE("acpi_pci_root_init");
346 343
347 if (acpi_pci_disabled) 344 if (acpi_pci_disabled)
348 return_VALUE(0); 345 return 0;
349 346
350 /* DEBUG: 347 /* DEBUG:
351 acpi_dbg_layer = ACPI_PCI_COMPONENT; 348 acpi_dbg_layer = ACPI_PCI_COMPONENT;
@@ -353,9 +350,9 @@ static int __init acpi_pci_root_init(void)
353 */ 350 */
354 351
355 if (acpi_bus_register_driver(&acpi_pci_root_driver) < 0) 352 if (acpi_bus_register_driver(&acpi_pci_root_driver) < 0)
356 return_VALUE(-ENODEV); 353 return -ENODEV;
357 354
358 return_VALUE(0); 355 return 0;
359} 356}
360 357
361subsys_initcall(acpi_pci_root_init); 358subsys_initcall(acpi_pci_root_init);
diff --git a/drivers/acpi/power.c b/drivers/acpi/power.c
index 62a5595ed8bc..fec225d1b6b7 100644
--- a/drivers/acpi/power.c
+++ b/drivers/acpi/power.c
@@ -70,7 +70,7 @@ static struct acpi_driver acpi_power_driver = {
70}; 70};
71 71
72struct acpi_power_resource { 72struct acpi_power_resource {
73 acpi_handle handle; 73 struct acpi_device * device;
74 acpi_bus_id name; 74 acpi_bus_id name;
75 u32 system_level; 75 u32 system_level;
76 u32 order; 76 u32 order;
@@ -80,7 +80,7 @@ struct acpi_power_resource {
80 80
81static struct list_head acpi_power_resource_list; 81static struct list_head acpi_power_resource_list;
82 82
83static struct file_operations acpi_power_fops = { 83static const struct file_operations acpi_power_fops = {
84 .open = acpi_power_open_fs, 84 .open = acpi_power_open_fs,
85 .read = seq_read, 85 .read = seq_read,
86 .llseek = seq_lseek, 86 .llseek = seq_lseek,
@@ -98,23 +98,21 @@ acpi_power_get_context(acpi_handle handle,
98 int result = 0; 98 int result = 0;
99 struct acpi_device *device = NULL; 99 struct acpi_device *device = NULL;
100 100
101 ACPI_FUNCTION_TRACE("acpi_power_get_context");
102 101
103 if (!resource) 102 if (!resource)
104 return_VALUE(-ENODEV); 103 return -ENODEV;
105 104
106 result = acpi_bus_get_device(handle, &device); 105 result = acpi_bus_get_device(handle, &device);
107 if (result) { 106 if (result) {
108 ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Error getting context [%p]\n", 107 printk(KERN_WARNING PREFIX "Getting context [%p]\n", handle);
109 handle)); 108 return result;
110 return_VALUE(result);
111 } 109 }
112 110
113 *resource = (struct acpi_power_resource *)acpi_driver_data(device); 111 *resource = (struct acpi_power_resource *)acpi_driver_data(device);
114 if (!resource) 112 if (!resource)
115 return_VALUE(-ENODEV); 113 return -ENODEV;
116 114
117 return_VALUE(0); 115 return 0;
118} 116}
119 117
120static int acpi_power_get_state(struct acpi_power_resource *resource) 118static int acpi_power_get_state(struct acpi_power_resource *resource)
@@ -122,14 +120,13 @@ static int acpi_power_get_state(struct acpi_power_resource *resource)
122 acpi_status status = AE_OK; 120 acpi_status status = AE_OK;
123 unsigned long sta = 0; 121 unsigned long sta = 0;
124 122
125 ACPI_FUNCTION_TRACE("acpi_power_get_state");
126 123
127 if (!resource) 124 if (!resource)
128 return_VALUE(-EINVAL); 125 return -EINVAL;
129 126
130 status = acpi_evaluate_integer(resource->handle, "_STA", NULL, &sta); 127 status = acpi_evaluate_integer(resource->device->handle, "_STA", NULL, &sta);
131 if (ACPI_FAILURE(status)) 128 if (ACPI_FAILURE(status))
132 return_VALUE(-ENODEV); 129 return -ENODEV;
133 130
134 if (sta & 0x01) 131 if (sta & 0x01)
135 resource->state = ACPI_POWER_RESOURCE_STATE_ON; 132 resource->state = ACPI_POWER_RESOURCE_STATE_ON;
@@ -139,7 +136,7 @@ static int acpi_power_get_state(struct acpi_power_resource *resource)
139 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resource [%s] is %s\n", 136 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resource [%s] is %s\n",
140 resource->name, resource->state ? "on" : "off")); 137 resource->name, resource->state ? "on" : "off"));
141 138
142 return_VALUE(0); 139 return 0;
143} 140}
144 141
145static int acpi_power_get_list_state(struct acpi_handle_list *list, int *state) 142static int acpi_power_get_list_state(struct acpi_handle_list *list, int *state)
@@ -148,20 +145,19 @@ static int acpi_power_get_list_state(struct acpi_handle_list *list, int *state)
148 struct acpi_power_resource *resource = NULL; 145 struct acpi_power_resource *resource = NULL;
149 u32 i = 0; 146 u32 i = 0;
150 147
151 ACPI_FUNCTION_TRACE("acpi_power_get_list_state");
152 148
153 if (!list || !state) 149 if (!list || !state)
154 return_VALUE(-EINVAL); 150 return -EINVAL;
155 151
156 /* The state of the list is 'on' IFF all resources are 'on'. */ 152 /* The state of the list is 'on' IFF all resources are 'on'. */
157 153
158 for (i = 0; i < list->count; i++) { 154 for (i = 0; i < list->count; i++) {
159 result = acpi_power_get_context(list->handles[i], &resource); 155 result = acpi_power_get_context(list->handles[i], &resource);
160 if (result) 156 if (result)
161 return_VALUE(result); 157 return result;
162 result = acpi_power_get_state(resource); 158 result = acpi_power_get_state(resource);
163 if (result) 159 if (result)
164 return_VALUE(result); 160 return result;
165 161
166 *state = resource->state; 162 *state = resource->state;
167 163
@@ -172,7 +168,7 @@ static int acpi_power_get_list_state(struct acpi_handle_list *list, int *state)
172 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resource list is %s\n", 168 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resource list is %s\n",
173 *state ? "on" : "off")); 169 *state ? "on" : "off"));
174 170
175 return_VALUE(result); 171 return result;
176} 172}
177 173
178static int acpi_power_on(acpi_handle handle) 174static int acpi_power_on(acpi_handle handle)
@@ -182,11 +178,10 @@ static int acpi_power_on(acpi_handle handle)
182 struct acpi_device *device = NULL; 178 struct acpi_device *device = NULL;
183 struct acpi_power_resource *resource = NULL; 179 struct acpi_power_resource *resource = NULL;
184 180
185 ACPI_FUNCTION_TRACE("acpi_power_on");
186 181
187 result = acpi_power_get_context(handle, &resource); 182 result = acpi_power_get_context(handle, &resource);
188 if (result) 183 if (result)
189 return_VALUE(result); 184 return result;
190 185
191 resource->references++; 186 resource->references++;
192 187
@@ -194,29 +189,27 @@ static int acpi_power_on(acpi_handle handle)
194 || (resource->state == ACPI_POWER_RESOURCE_STATE_ON)) { 189 || (resource->state == ACPI_POWER_RESOURCE_STATE_ON)) {
195 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resource [%s] already on\n", 190 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resource [%s] already on\n",
196 resource->name)); 191 resource->name));
197 return_VALUE(0); 192 return 0;
198 } 193 }
199 194
200 status = acpi_evaluate_object(resource->handle, "_ON", NULL, NULL); 195 status = acpi_evaluate_object(resource->device->handle, "_ON", NULL, NULL);
201 if (ACPI_FAILURE(status)) 196 if (ACPI_FAILURE(status))
202 return_VALUE(-ENODEV); 197 return -ENODEV;
203 198
204 result = acpi_power_get_state(resource); 199 result = acpi_power_get_state(resource);
205 if (result) 200 if (result)
206 return_VALUE(result); 201 return result;
207 if (resource->state != ACPI_POWER_RESOURCE_STATE_ON) 202 if (resource->state != ACPI_POWER_RESOURCE_STATE_ON)
208 return_VALUE(-ENOEXEC); 203 return -ENOEXEC;
209 204
210 /* Update the power resource's _device_ power state */ 205 /* Update the power resource's _device_ power state */
211 result = acpi_bus_get_device(resource->handle, &device); 206 device = resource->device;
212 if (result) 207 resource->device->power.state = ACPI_STATE_D0;
213 return_VALUE(result);
214 device->power.state = ACPI_STATE_D0;
215 208
216 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resource [%s] turned on\n", 209 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resource [%s] turned on\n",
217 resource->name)); 210 resource->name));
218 211
219 return_VALUE(0); 212 return 0;
220} 213}
221 214
222static int acpi_power_off_device(acpi_handle handle) 215static int acpi_power_off_device(acpi_handle handle)
@@ -226,11 +219,10 @@ static int acpi_power_off_device(acpi_handle handle)
226 struct acpi_device *device = NULL; 219 struct acpi_device *device = NULL;
227 struct acpi_power_resource *resource = NULL; 220 struct acpi_power_resource *resource = NULL;
228 221
229 ACPI_FUNCTION_TRACE("acpi_power_off_device");
230 222
231 result = acpi_power_get_context(handle, &resource); 223 result = acpi_power_get_context(handle, &resource);
232 if (result) 224 if (result)
233 return_VALUE(result); 225 return result;
234 226
235 if (resource->references) 227 if (resource->references)
236 resource->references--; 228 resource->references--;
@@ -239,35 +231,33 @@ static int acpi_power_off_device(acpi_handle handle)
239 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 231 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
240 "Resource [%s] is still in use, dereferencing\n", 232 "Resource [%s] is still in use, dereferencing\n",
241 device->pnp.bus_id)); 233 device->pnp.bus_id));
242 return_VALUE(0); 234 return 0;
243 } 235 }
244 236
245 if (resource->state == ACPI_POWER_RESOURCE_STATE_OFF) { 237 if (resource->state == ACPI_POWER_RESOURCE_STATE_OFF) {
246 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resource [%s] already off\n", 238 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resource [%s] already off\n",
247 device->pnp.bus_id)); 239 device->pnp.bus_id));
248 return_VALUE(0); 240 return 0;
249 } 241 }
250 242
251 status = acpi_evaluate_object(resource->handle, "_OFF", NULL, NULL); 243 status = acpi_evaluate_object(resource->device->handle, "_OFF", NULL, NULL);
252 if (ACPI_FAILURE(status)) 244 if (ACPI_FAILURE(status))
253 return_VALUE(-ENODEV); 245 return -ENODEV;
254 246
255 result = acpi_power_get_state(resource); 247 result = acpi_power_get_state(resource);
256 if (result) 248 if (result)
257 return_VALUE(result); 249 return result;
258 if (resource->state != ACPI_POWER_RESOURCE_STATE_OFF) 250 if (resource->state != ACPI_POWER_RESOURCE_STATE_OFF)
259 return_VALUE(-ENOEXEC); 251 return -ENOEXEC;
260 252
261 /* Update the power resource's _device_ power state */ 253 /* Update the power resource's _device_ power state */
262 result = acpi_bus_get_device(resource->handle, &device); 254 device = resource->device;
263 if (result)
264 return_VALUE(result);
265 device->power.state = ACPI_STATE_D3; 255 device->power.state = ACPI_STATE_D3;
266 256
267 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resource [%s] turned off\n", 257 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resource [%s] turned off\n",
268 resource->name)); 258 resource->name));
269 259
270 return_VALUE(0); 260 return 0;
271} 261}
272 262
273/* 263/*
@@ -283,31 +273,29 @@ int acpi_enable_wakeup_device_power(struct acpi_device *dev)
283 int i; 273 int i;
284 int ret = 0; 274 int ret = 0;
285 275
286 ACPI_FUNCTION_TRACE("acpi_enable_wakeup_device_power");
287 if (!dev || !dev->wakeup.flags.valid) 276 if (!dev || !dev->wakeup.flags.valid)
288 return_VALUE(-1); 277 return -1;
289 278
290 arg.integer.value = 1; 279 arg.integer.value = 1;
291 /* Open power resource */ 280 /* Open power resource */
292 for (i = 0; i < dev->wakeup.resources.count; i++) { 281 for (i = 0; i < dev->wakeup.resources.count; i++) {
293 ret = acpi_power_on(dev->wakeup.resources.handles[i]); 282 ret = acpi_power_on(dev->wakeup.resources.handles[i]);
294 if (ret) { 283 if (ret) {
295 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 284 printk(KERN_ERR PREFIX "Transition power state\n");
296 "Error transition power state\n"));
297 dev->wakeup.flags.valid = 0; 285 dev->wakeup.flags.valid = 0;
298 return_VALUE(-1); 286 return -1;
299 } 287 }
300 } 288 }
301 289
302 /* Execute PSW */ 290 /* Execute PSW */
303 status = acpi_evaluate_object(dev->handle, "_PSW", &arg_list, NULL); 291 status = acpi_evaluate_object(dev->handle, "_PSW", &arg_list, NULL);
304 if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) { 292 if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) {
305 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error evaluate _PSW\n")); 293 printk(KERN_ERR PREFIX "Evaluate _PSW\n");
306 dev->wakeup.flags.valid = 0; 294 dev->wakeup.flags.valid = 0;
307 ret = -1; 295 ret = -1;
308 } 296 }
309 297
310 return_VALUE(ret); 298 return ret;
311} 299}
312 300
313/* 301/*
@@ -323,32 +311,30 @@ int acpi_disable_wakeup_device_power(struct acpi_device *dev)
323 int i; 311 int i;
324 int ret = 0; 312 int ret = 0;
325 313
326 ACPI_FUNCTION_TRACE("acpi_disable_wakeup_device_power");
327 314
328 if (!dev || !dev->wakeup.flags.valid) 315 if (!dev || !dev->wakeup.flags.valid)
329 return_VALUE(-1); 316 return -1;
330 317
331 arg.integer.value = 0; 318 arg.integer.value = 0;
332 /* Execute PSW */ 319 /* Execute PSW */
333 status = acpi_evaluate_object(dev->handle, "_PSW", &arg_list, NULL); 320 status = acpi_evaluate_object(dev->handle, "_PSW", &arg_list, NULL);
334 if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) { 321 if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) {
335 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error evaluate _PSW\n")); 322 printk(KERN_ERR PREFIX "Evaluate _PSW\n");
336 dev->wakeup.flags.valid = 0; 323 dev->wakeup.flags.valid = 0;
337 return_VALUE(-1); 324 return -1;
338 } 325 }
339 326
340 /* Close power resource */ 327 /* Close power resource */
341 for (i = 0; i < dev->wakeup.resources.count; i++) { 328 for (i = 0; i < dev->wakeup.resources.count; i++) {
342 ret = acpi_power_off_device(dev->wakeup.resources.handles[i]); 329 ret = acpi_power_off_device(dev->wakeup.resources.handles[i]);
343 if (ret) { 330 if (ret) {
344 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 331 printk(KERN_ERR PREFIX "Transition power state\n");
345 "Error transition power state\n"));
346 dev->wakeup.flags.valid = 0; 332 dev->wakeup.flags.valid = 0;
347 return_VALUE(-1); 333 return -1;
348 } 334 }
349 } 335 }
350 336
351 return_VALUE(ret); 337 return ret;
352} 338}
353 339
354/* -------------------------------------------------------------------------- 340/* --------------------------------------------------------------------------
@@ -362,10 +348,9 @@ int acpi_power_get_inferred_state(struct acpi_device *device)
362 int list_state = 0; 348 int list_state = 0;
363 int i = 0; 349 int i = 0;
364 350
365 ACPI_FUNCTION_TRACE("acpi_power_get_inferred_state");
366 351
367 if (!device) 352 if (!device)
368 return_VALUE(-EINVAL); 353 return -EINVAL;
369 354
370 device->power.state = ACPI_STATE_UNKNOWN; 355 device->power.state = ACPI_STATE_UNKNOWN;
371 356
@@ -380,17 +365,17 @@ int acpi_power_get_inferred_state(struct acpi_device *device)
380 365
381 result = acpi_power_get_list_state(list, &list_state); 366 result = acpi_power_get_list_state(list, &list_state);
382 if (result) 367 if (result)
383 return_VALUE(result); 368 return result;
384 369
385 if (list_state == ACPI_POWER_RESOURCE_STATE_ON) { 370 if (list_state == ACPI_POWER_RESOURCE_STATE_ON) {
386 device->power.state = i; 371 device->power.state = i;
387 return_VALUE(0); 372 return 0;
388 } 373 }
389 } 374 }
390 375
391 device->power.state = ACPI_STATE_D3; 376 device->power.state = ACPI_STATE_D3;
392 377
393 return_VALUE(0); 378 return 0;
394} 379}
395 380
396int acpi_power_transition(struct acpi_device *device, int state) 381int acpi_power_transition(struct acpi_device *device, int state)
@@ -400,14 +385,13 @@ int acpi_power_transition(struct acpi_device *device, int state)
400 struct acpi_handle_list *tl = NULL; /* Target Resources */ 385 struct acpi_handle_list *tl = NULL; /* Target Resources */
401 int i = 0; 386 int i = 0;
402 387
403 ACPI_FUNCTION_TRACE("acpi_power_transition");
404 388
405 if (!device || (state < ACPI_STATE_D0) || (state > ACPI_STATE_D3)) 389 if (!device || (state < ACPI_STATE_D0) || (state > ACPI_STATE_D3))
406 return_VALUE(-EINVAL); 390 return -EINVAL;
407 391
408 if ((device->power.state < ACPI_STATE_D0) 392 if ((device->power.state < ACPI_STATE_D0)
409 || (device->power.state > ACPI_STATE_D3)) 393 || (device->power.state > ACPI_STATE_D3))
410 return_VALUE(-ENODEV); 394 return -ENODEV;
411 395
412 cl = &device->power.states[device->power.state].resources; 396 cl = &device->power.states[device->power.state].resources;
413 tl = &device->power.states[state].resources; 397 tl = &device->power.states[state].resources;
@@ -444,11 +428,10 @@ int acpi_power_transition(struct acpi_device *device, int state)
444 device->power.state = state; 428 device->power.state = state;
445 end: 429 end:
446 if (result) 430 if (result)
447 ACPI_DEBUG_PRINT((ACPI_DB_WARN, 431 printk(KERN_WARNING PREFIX "Transitioning device [%s] to D%d\n",
448 "Error transitioning device [%s] to D%d\n", 432 device->pnp.bus_id, state);
449 device->pnp.bus_id, state));
450 433
451 return_VALUE(result); 434 return result;
452} 435}
453 436
454/* -------------------------------------------------------------------------- 437/* --------------------------------------------------------------------------
@@ -461,7 +444,6 @@ static int acpi_power_seq_show(struct seq_file *seq, void *offset)
461{ 444{
462 struct acpi_power_resource *resource = NULL; 445 struct acpi_power_resource *resource = NULL;
463 446
464 ACPI_FUNCTION_TRACE("acpi_power_seq_show");
465 447
466 resource = (struct acpi_power_resource *)seq->private; 448 resource = (struct acpi_power_resource *)seq->private;
467 449
@@ -488,7 +470,7 @@ static int acpi_power_seq_show(struct seq_file *seq, void *offset)
488 resource->order, resource->references); 470 resource->order, resource->references);
489 471
490 end: 472 end:
491 return_VALUE(0); 473 return 0;
492} 474}
493 475
494static int acpi_power_open_fs(struct inode *inode, struct file *file) 476static int acpi_power_open_fs(struct inode *inode, struct file *file)
@@ -500,36 +482,32 @@ static int acpi_power_add_fs(struct acpi_device *device)
500{ 482{
501 struct proc_dir_entry *entry = NULL; 483 struct proc_dir_entry *entry = NULL;
502 484
503 ACPI_FUNCTION_TRACE("acpi_power_add_fs");
504 485
505 if (!device) 486 if (!device)
506 return_VALUE(-EINVAL); 487 return -EINVAL;
507 488
508 if (!acpi_device_dir(device)) { 489 if (!acpi_device_dir(device)) {
509 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), 490 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
510 acpi_power_dir); 491 acpi_power_dir);
511 if (!acpi_device_dir(device)) 492 if (!acpi_device_dir(device))
512 return_VALUE(-ENODEV); 493 return -ENODEV;
513 } 494 }
514 495
515 /* 'status' [R] */ 496 /* 'status' [R] */
516 entry = create_proc_entry(ACPI_POWER_FILE_STATUS, 497 entry = create_proc_entry(ACPI_POWER_FILE_STATUS,
517 S_IRUGO, acpi_device_dir(device)); 498 S_IRUGO, acpi_device_dir(device));
518 if (!entry) 499 if (!entry)
519 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 500 return -EIO;
520 "Unable to create '%s' fs entry\n",
521 ACPI_POWER_FILE_STATUS));
522 else { 501 else {
523 entry->proc_fops = &acpi_power_fops; 502 entry->proc_fops = &acpi_power_fops;
524 entry->data = acpi_driver_data(device); 503 entry->data = acpi_driver_data(device);
525 } 504 }
526 505
527 return_VALUE(0); 506 return 0;
528} 507}
529 508
530static int acpi_power_remove_fs(struct acpi_device *device) 509static int acpi_power_remove_fs(struct acpi_device *device)
531{ 510{
532 ACPI_FUNCTION_TRACE("acpi_power_remove_fs");
533 511
534 if (acpi_device_dir(device)) { 512 if (acpi_device_dir(device)) {
535 remove_proc_entry(ACPI_POWER_FILE_STATUS, 513 remove_proc_entry(ACPI_POWER_FILE_STATUS,
@@ -538,7 +516,7 @@ static int acpi_power_remove_fs(struct acpi_device *device)
538 acpi_device_dir(device) = NULL; 516 acpi_device_dir(device) = NULL;
539 } 517 }
540 518
541 return_VALUE(0); 519 return 0;
542} 520}
543 521
544/* -------------------------------------------------------------------------- 522/* --------------------------------------------------------------------------
@@ -553,24 +531,23 @@ static int acpi_power_add(struct acpi_device *device)
553 union acpi_object acpi_object; 531 union acpi_object acpi_object;
554 struct acpi_buffer buffer = { sizeof(acpi_object), &acpi_object }; 532 struct acpi_buffer buffer = { sizeof(acpi_object), &acpi_object };
555 533
556 ACPI_FUNCTION_TRACE("acpi_power_add");
557 534
558 if (!device) 535 if (!device)
559 return_VALUE(-EINVAL); 536 return -EINVAL;
560 537
561 resource = kmalloc(sizeof(struct acpi_power_resource), GFP_KERNEL); 538 resource = kmalloc(sizeof(struct acpi_power_resource), GFP_KERNEL);
562 if (!resource) 539 if (!resource)
563 return_VALUE(-ENOMEM); 540 return -ENOMEM;
564 memset(resource, 0, sizeof(struct acpi_power_resource)); 541 memset(resource, 0, sizeof(struct acpi_power_resource));
565 542
566 resource->handle = device->handle; 543 resource->device = device;
567 strcpy(resource->name, device->pnp.bus_id); 544 strcpy(resource->name, device->pnp.bus_id);
568 strcpy(acpi_device_name(device), ACPI_POWER_DEVICE_NAME); 545 strcpy(acpi_device_name(device), ACPI_POWER_DEVICE_NAME);
569 strcpy(acpi_device_class(device), ACPI_POWER_CLASS); 546 strcpy(acpi_device_class(device), ACPI_POWER_CLASS);
570 acpi_driver_data(device) = resource; 547 acpi_driver_data(device) = resource;
571 548
572 /* Evalute the object to get the system level and resource order. */ 549 /* Evalute the object to get the system level and resource order. */
573 status = acpi_evaluate_object(resource->handle, NULL, NULL, &buffer); 550 status = acpi_evaluate_object(device->handle, NULL, NULL, &buffer);
574 if (ACPI_FAILURE(status)) { 551 if (ACPI_FAILURE(status)) {
575 result = -ENODEV; 552 result = -ENODEV;
576 goto end; 553 goto end;
@@ -605,17 +582,16 @@ static int acpi_power_add(struct acpi_device *device)
605 if (result) 582 if (result)
606 kfree(resource); 583 kfree(resource);
607 584
608 return_VALUE(result); 585 return result;
609} 586}
610 587
611static int acpi_power_remove(struct acpi_device *device, int type) 588static int acpi_power_remove(struct acpi_device *device, int type)
612{ 589{
613 struct acpi_power_resource *resource = NULL; 590 struct acpi_power_resource *resource = NULL;
614 591
615 ACPI_FUNCTION_TRACE("acpi_power_remove");
616 592
617 if (!device || !acpi_driver_data(device)) 593 if (!device || !acpi_driver_data(device))
618 return_VALUE(-EINVAL); 594 return -EINVAL;
619 595
620 resource = (struct acpi_power_resource *)acpi_driver_data(device); 596 resource = (struct acpi_power_resource *)acpi_driver_data(device);
621 597
@@ -623,31 +599,30 @@ static int acpi_power_remove(struct acpi_device *device, int type)
623 599
624 kfree(resource); 600 kfree(resource);
625 601
626 return_VALUE(0); 602 return 0;
627} 603}
628 604
629static int __init acpi_power_init(void) 605static int __init acpi_power_init(void)
630{ 606{
631 int result = 0; 607 int result = 0;
632 608
633 ACPI_FUNCTION_TRACE("acpi_power_init");
634 609
635 if (acpi_disabled) 610 if (acpi_disabled)
636 return_VALUE(0); 611 return 0;
637 612
638 INIT_LIST_HEAD(&acpi_power_resource_list); 613 INIT_LIST_HEAD(&acpi_power_resource_list);
639 614
640 acpi_power_dir = proc_mkdir(ACPI_POWER_CLASS, acpi_root_dir); 615 acpi_power_dir = proc_mkdir(ACPI_POWER_CLASS, acpi_root_dir);
641 if (!acpi_power_dir) 616 if (!acpi_power_dir)
642 return_VALUE(-ENODEV); 617 return -ENODEV;
643 618
644 result = acpi_bus_register_driver(&acpi_power_driver); 619 result = acpi_bus_register_driver(&acpi_power_driver);
645 if (result < 0) { 620 if (result < 0) {
646 remove_proc_entry(ACPI_POWER_CLASS, acpi_root_dir); 621 remove_proc_entry(ACPI_POWER_CLASS, acpi_root_dir);
647 return_VALUE(-ENODEV); 622 return -ENODEV;
648 } 623 }
649 624
650 return_VALUE(0); 625 return 0;
651} 626}
652 627
653subsys_initcall(acpi_power_init); 628subsys_initcall(acpi_power_init);
diff --git a/drivers/acpi/processor_core.c b/drivers/acpi/processor_core.c
index decaebb4cbe9..b13d64415b7a 100644
--- a/drivers/acpi/processor_core.c
+++ b/drivers/acpi/processor_core.c
@@ -102,7 +102,7 @@ static struct acpi_driver acpi_processor_driver = {
102#define INSTALL_NOTIFY_HANDLER 1 102#define INSTALL_NOTIFY_HANDLER 1
103#define UNINSTALL_NOTIFY_HANDLER 2 103#define UNINSTALL_NOTIFY_HANDLER 2
104 104
105static struct file_operations acpi_processor_info_fops = { 105static const struct file_operations acpi_processor_info_fops = {
106 .open = acpi_processor_info_open_fs, 106 .open = acpi_processor_info_open_fs,
107 .read = seq_read, 107 .read = seq_read,
108 .llseek = seq_lseek, 108 .llseek = seq_lseek,
@@ -122,10 +122,9 @@ static int acpi_processor_errata_piix4(struct pci_dev *dev)
122 u8 value1 = 0; 122 u8 value1 = 0;
123 u8 value2 = 0; 123 u8 value2 = 0;
124 124
125 ACPI_FUNCTION_TRACE("acpi_processor_errata_piix4");
126 125
127 if (!dev) 126 if (!dev)
128 return_VALUE(-EINVAL); 127 return -EINVAL;
129 128
130 /* 129 /*
131 * Note that 'dev' references the PIIX4 ACPI Controller. 130 * Note that 'dev' references the PIIX4 ACPI Controller.
@@ -218,7 +217,7 @@ static int acpi_processor_errata_piix4(struct pci_dev *dev)
218 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 217 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
219 "Type-F DMA livelock erratum (C3 disabled)\n")); 218 "Type-F DMA livelock erratum (C3 disabled)\n"));
220 219
221 return_VALUE(0); 220 return 0;
222} 221}
223 222
224static int acpi_processor_errata(struct acpi_processor *pr) 223static int acpi_processor_errata(struct acpi_processor *pr)
@@ -226,10 +225,9 @@ static int acpi_processor_errata(struct acpi_processor *pr)
226 int result = 0; 225 int result = 0;
227 struct pci_dev *dev = NULL; 226 struct pci_dev *dev = NULL;
228 227
229 ACPI_FUNCTION_TRACE("acpi_processor_errata");
230 228
231 if (!pr) 229 if (!pr)
232 return_VALUE(-EINVAL); 230 return -EINVAL;
233 231
234 /* 232 /*
235 * PIIX4 233 * PIIX4
@@ -242,7 +240,7 @@ static int acpi_processor_errata(struct acpi_processor *pr)
242 pci_dev_put(dev); 240 pci_dev_put(dev);
243 } 241 }
244 242
245 return_VALUE(result); 243 return result;
246} 244}
247 245
248/* -------------------------------------------------------------------------- 246/* --------------------------------------------------------------------------
@@ -258,10 +256,9 @@ static int acpi_processor_set_pdc(struct acpi_processor *pr)
258 struct acpi_object_list *pdc_in = pr->pdc; 256 struct acpi_object_list *pdc_in = pr->pdc;
259 acpi_status status = AE_OK; 257 acpi_status status = AE_OK;
260 258
261 ACPI_FUNCTION_TRACE("acpi_processor_set_pdc");
262 259
263 if (!pdc_in) 260 if (!pdc_in)
264 return_VALUE(status); 261 return status;
265 262
266 status = acpi_evaluate_object(pr->handle, "_PDC", pdc_in, NULL); 263 status = acpi_evaluate_object(pr->handle, "_PDC", pdc_in, NULL);
267 264
@@ -269,7 +266,7 @@ static int acpi_processor_set_pdc(struct acpi_processor *pr)
269 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 266 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
270 "Could not evaluate _PDC, using legacy perf. control...\n")); 267 "Could not evaluate _PDC, using legacy perf. control...\n"));
271 268
272 return_VALUE(status); 269 return status;
273} 270}
274 271
275/* -------------------------------------------------------------------------- 272/* --------------------------------------------------------------------------
@@ -282,7 +279,6 @@ static int acpi_processor_info_seq_show(struct seq_file *seq, void *offset)
282{ 279{
283 struct acpi_processor *pr = (struct acpi_processor *)seq->private; 280 struct acpi_processor *pr = (struct acpi_processor *)seq->private;
284 281
285 ACPI_FUNCTION_TRACE("acpi_processor_info_seq_show");
286 282
287 if (!pr) 283 if (!pr)
288 goto end; 284 goto end;
@@ -301,7 +297,7 @@ static int acpi_processor_info_seq_show(struct seq_file *seq, void *offset)
301 pr->flags.limit ? "yes" : "no"); 297 pr->flags.limit ? "yes" : "no");
302 298
303 end: 299 end:
304 return_VALUE(0); 300 return 0;
305} 301}
306 302
307static int acpi_processor_info_open_fs(struct inode *inode, struct file *file) 303static int acpi_processor_info_open_fs(struct inode *inode, struct file *file)
@@ -314,13 +310,12 @@ static int acpi_processor_add_fs(struct acpi_device *device)
314{ 310{
315 struct proc_dir_entry *entry = NULL; 311 struct proc_dir_entry *entry = NULL;
316 312
317 ACPI_FUNCTION_TRACE("acpi_processor_add_fs");
318 313
319 if (!acpi_device_dir(device)) { 314 if (!acpi_device_dir(device)) {
320 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), 315 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
321 acpi_processor_dir); 316 acpi_processor_dir);
322 if (!acpi_device_dir(device)) 317 if (!acpi_device_dir(device))
323 return_VALUE(-ENODEV); 318 return -ENODEV;
324 } 319 }
325 acpi_device_dir(device)->owner = THIS_MODULE; 320 acpi_device_dir(device)->owner = THIS_MODULE;
326 321
@@ -328,9 +323,7 @@ static int acpi_processor_add_fs(struct acpi_device *device)
328 entry = create_proc_entry(ACPI_PROCESSOR_FILE_INFO, 323 entry = create_proc_entry(ACPI_PROCESSOR_FILE_INFO,
329 S_IRUGO, acpi_device_dir(device)); 324 S_IRUGO, acpi_device_dir(device));
330 if (!entry) 325 if (!entry)
331 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 326 return -EIO;
332 "Unable to create '%s' fs entry\n",
333 ACPI_PROCESSOR_FILE_INFO));
334 else { 327 else {
335 entry->proc_fops = &acpi_processor_info_fops; 328 entry->proc_fops = &acpi_processor_info_fops;
336 entry->data = acpi_driver_data(device); 329 entry->data = acpi_driver_data(device);
@@ -342,9 +335,7 @@ static int acpi_processor_add_fs(struct acpi_device *device)
342 S_IFREG | S_IRUGO | S_IWUSR, 335 S_IFREG | S_IRUGO | S_IWUSR,
343 acpi_device_dir(device)); 336 acpi_device_dir(device));
344 if (!entry) 337 if (!entry)
345 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 338 return -EIO;
346 "Unable to create '%s' fs entry\n",
347 ACPI_PROCESSOR_FILE_THROTTLING));
348 else { 339 else {
349 entry->proc_fops = &acpi_processor_throttling_fops; 340 entry->proc_fops = &acpi_processor_throttling_fops;
350 entry->data = acpi_driver_data(device); 341 entry->data = acpi_driver_data(device);
@@ -356,21 +347,18 @@ static int acpi_processor_add_fs(struct acpi_device *device)
356 S_IFREG | S_IRUGO | S_IWUSR, 347 S_IFREG | S_IRUGO | S_IWUSR,
357 acpi_device_dir(device)); 348 acpi_device_dir(device));
358 if (!entry) 349 if (!entry)
359 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 350 return -EIO;
360 "Unable to create '%s' fs entry\n",
361 ACPI_PROCESSOR_FILE_LIMIT));
362 else { 351 else {
363 entry->proc_fops = &acpi_processor_limit_fops; 352 entry->proc_fops = &acpi_processor_limit_fops;
364 entry->data = acpi_driver_data(device); 353 entry->data = acpi_driver_data(device);
365 entry->owner = THIS_MODULE; 354 entry->owner = THIS_MODULE;
366 } 355 }
367 356
368 return_VALUE(0); 357 return 0;
369} 358}
370 359
371static int acpi_processor_remove_fs(struct acpi_device *device) 360static int acpi_processor_remove_fs(struct acpi_device *device)
372{ 361{
373 ACPI_FUNCTION_TRACE("acpi_processor_remove_fs");
374 362
375 if (acpi_device_dir(device)) { 363 if (acpi_device_dir(device)) {
376 remove_proc_entry(ACPI_PROCESSOR_FILE_INFO, 364 remove_proc_entry(ACPI_PROCESSOR_FILE_INFO,
@@ -383,7 +371,7 @@ static int acpi_processor_remove_fs(struct acpi_device *device)
383 acpi_device_dir(device) = NULL; 371 acpi_device_dir(device) = NULL;
384 } 372 }
385 373
386 return_VALUE(0); 374 return 0;
387} 375}
388 376
389/* Use the acpiid in MADT to map cpus in case of SMP */ 377/* Use the acpiid in MADT to map cpus in case of SMP */
@@ -430,10 +418,9 @@ static int acpi_processor_get_info(struct acpi_processor *pr)
430 int cpu_index; 418 int cpu_index;
431 static int cpu0_initialized; 419 static int cpu0_initialized;
432 420
433 ACPI_FUNCTION_TRACE("acpi_processor_get_info");
434 421
435 if (!pr) 422 if (!pr)
436 return_VALUE(-EINVAL); 423 return -EINVAL;
437 424
438 if (num_online_cpus() > 1) 425 if (num_online_cpus() > 1)
439 errata.smp = TRUE; 426 errata.smp = TRUE;
@@ -459,9 +446,8 @@ static int acpi_processor_get_info(struct acpi_processor *pr)
459 */ 446 */
460 status = acpi_evaluate_object(pr->handle, NULL, NULL, &buffer); 447 status = acpi_evaluate_object(pr->handle, NULL, NULL, &buffer);
461 if (ACPI_FAILURE(status)) { 448 if (ACPI_FAILURE(status)) {
462 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 449 printk(KERN_ERR PREFIX "Evaluating processor object\n");
463 "Error evaluating processor object\n")); 450 return -ENODEV;
464 return_VALUE(-ENODEV);
465 } 451 }
466 452
467 /* 453 /*
@@ -490,10 +476,10 @@ static int acpi_processor_get_info(struct acpi_processor *pr)
490 if (cpu_index == -1) { 476 if (cpu_index == -1) {
491 if (ACPI_FAILURE 477 if (ACPI_FAILURE
492 (acpi_processor_hotadd_init(pr->handle, &pr->id))) { 478 (acpi_processor_hotadd_init(pr->handle, &pr->id))) {
493 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 479 printk(KERN_ERR PREFIX
494 "Error getting cpuindex for acpiid 0x%x\n", 480 "Getting cpuindex for acpiid 0x%x\n",
495 pr->acpi_id)); 481 pr->acpi_id);
496 return_VALUE(-ENODEV); 482 return -ENODEV;
497 } 483 }
498 } 484 }
499 485
@@ -503,8 +489,8 @@ static int acpi_processor_get_info(struct acpi_processor *pr)
503 if (!object.processor.pblk_address) 489 if (!object.processor.pblk_address)
504 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No PBLK (NULL address)\n")); 490 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No PBLK (NULL address)\n"));
505 else if (object.processor.pblk_length != 6) 491 else if (object.processor.pblk_length != 6)
506 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid PBLK length [%d]\n", 492 printk(KERN_ERR PREFIX "Invalid PBLK length [%d]\n",
507 object.processor.pblk_length)); 493 object.processor.pblk_length);
508 else { 494 else {
509 pr->throttling.address = object.processor.pblk_address; 495 pr->throttling.address = object.processor.pblk_address;
510 pr->throttling.duty_offset = acpi_fadt.duty_offset; 496 pr->throttling.duty_offset = acpi_fadt.duty_offset;
@@ -528,7 +514,7 @@ static int acpi_processor_get_info(struct acpi_processor *pr)
528 acpi_processor_get_throttling_info(pr); 514 acpi_processor_get_throttling_info(pr);
529 acpi_processor_get_limit_info(pr); 515 acpi_processor_get_limit_info(pr);
530 516
531 return_VALUE(0); 517 return 0;
532} 518}
533 519
534static void *processor_device_array[NR_CPUS]; 520static void *processor_device_array[NR_CPUS];
@@ -539,14 +525,13 @@ static int acpi_processor_start(struct acpi_device *device)
539 acpi_status status = AE_OK; 525 acpi_status status = AE_OK;
540 struct acpi_processor *pr; 526 struct acpi_processor *pr;
541 527
542 ACPI_FUNCTION_TRACE("acpi_processor_start");
543 528
544 pr = acpi_driver_data(device); 529 pr = acpi_driver_data(device);
545 530
546 result = acpi_processor_get_info(pr); 531 result = acpi_processor_get_info(pr);
547 if (result) { 532 if (result) {
548 /* Processor is physically not present */ 533 /* Processor is physically not present */
549 return_VALUE(0); 534 return 0;
550 } 535 }
551 536
552 BUG_ON((pr->id >= NR_CPUS) || (pr->id < 0)); 537 BUG_ON((pr->id >= NR_CPUS) || (pr->id < 0));
@@ -560,7 +545,7 @@ static int acpi_processor_start(struct acpi_device *device)
560 processor_device_array[pr->id] != (void *)device) { 545 processor_device_array[pr->id] != (void *)device) {
561 printk(KERN_WARNING "BIOS reported wrong ACPI id" 546 printk(KERN_WARNING "BIOS reported wrong ACPI id"
562 "for the processor\n"); 547 "for the processor\n");
563 return_VALUE(-ENODEV); 548 return -ENODEV;
564 } 549 }
565 processor_device_array[pr->id] = (void *)device; 550 processor_device_array[pr->id] = (void *)device;
566 551
@@ -572,10 +557,6 @@ static int acpi_processor_start(struct acpi_device *device)
572 557
573 status = acpi_install_notify_handler(pr->handle, ACPI_DEVICE_NOTIFY, 558 status = acpi_install_notify_handler(pr->handle, ACPI_DEVICE_NOTIFY,
574 acpi_processor_notify, pr); 559 acpi_processor_notify, pr);
575 if (ACPI_FAILURE(status)) {
576 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
577 "Error installing device notify handler\n"));
578 }
579 560
580 /* _PDC call should be done before doing anything else (if reqd.). */ 561 /* _PDC call should be done before doing anything else (if reqd.). */
581 arch_acpi_processor_init_pdc(pr); 562 arch_acpi_processor_init_pdc(pr);
@@ -592,7 +573,7 @@ static int acpi_processor_start(struct acpi_device *device)
592 573
593 end: 574 end:
594 575
595 return_VALUE(result); 576 return result;
596} 577}
597 578
598static void acpi_processor_notify(acpi_handle handle, u32 event, void *data) 579static void acpi_processor_notify(acpi_handle handle, u32 event, void *data)
@@ -600,13 +581,12 @@ static void acpi_processor_notify(acpi_handle handle, u32 event, void *data)
600 struct acpi_processor *pr = (struct acpi_processor *)data; 581 struct acpi_processor *pr = (struct acpi_processor *)data;
601 struct acpi_device *device = NULL; 582 struct acpi_device *device = NULL;
602 583
603 ACPI_FUNCTION_TRACE("acpi_processor_notify");
604 584
605 if (!pr) 585 if (!pr)
606 return_VOID; 586 return;
607 587
608 if (acpi_bus_get_device(pr->handle, &device)) 588 if (acpi_bus_get_device(pr->handle, &device))
609 return_VOID; 589 return;
610 590
611 switch (event) { 591 switch (event) {
612 case ACPI_PROCESSOR_NOTIFY_PERFORMANCE: 592 case ACPI_PROCESSOR_NOTIFY_PERFORMANCE:
@@ -624,21 +604,20 @@ static void acpi_processor_notify(acpi_handle handle, u32 event, void *data)
624 break; 604 break;
625 } 605 }
626 606
627 return_VOID; 607 return;
628} 608}
629 609
630static int acpi_processor_add(struct acpi_device *device) 610static int acpi_processor_add(struct acpi_device *device)
631{ 611{
632 struct acpi_processor *pr = NULL; 612 struct acpi_processor *pr = NULL;
633 613
634 ACPI_FUNCTION_TRACE("acpi_processor_add");
635 614
636 if (!device) 615 if (!device)
637 return_VALUE(-EINVAL); 616 return -EINVAL;
638 617
639 pr = kmalloc(sizeof(struct acpi_processor), GFP_KERNEL); 618 pr = kmalloc(sizeof(struct acpi_processor), GFP_KERNEL);
640 if (!pr) 619 if (!pr)
641 return_VALUE(-ENOMEM); 620 return -ENOMEM;
642 memset(pr, 0, sizeof(struct acpi_processor)); 621 memset(pr, 0, sizeof(struct acpi_processor));
643 622
644 pr->handle = device->handle; 623 pr->handle = device->handle;
@@ -646,7 +625,7 @@ static int acpi_processor_add(struct acpi_device *device)
646 strcpy(acpi_device_class(device), ACPI_PROCESSOR_CLASS); 625 strcpy(acpi_device_class(device), ACPI_PROCESSOR_CLASS);
647 acpi_driver_data(device) = pr; 626 acpi_driver_data(device) = pr;
648 627
649 return_VALUE(0); 628 return 0;
650} 629}
651 630
652static int acpi_processor_remove(struct acpi_device *device, int type) 631static int acpi_processor_remove(struct acpi_device *device, int type)
@@ -654,31 +633,26 @@ static int acpi_processor_remove(struct acpi_device *device, int type)
654 acpi_status status = AE_OK; 633 acpi_status status = AE_OK;
655 struct acpi_processor *pr = NULL; 634 struct acpi_processor *pr = NULL;
656 635
657 ACPI_FUNCTION_TRACE("acpi_processor_remove");
658 636
659 if (!device || !acpi_driver_data(device)) 637 if (!device || !acpi_driver_data(device))
660 return_VALUE(-EINVAL); 638 return -EINVAL;
661 639
662 pr = (struct acpi_processor *)acpi_driver_data(device); 640 pr = (struct acpi_processor *)acpi_driver_data(device);
663 641
664 if (pr->id >= NR_CPUS) { 642 if (pr->id >= NR_CPUS) {
665 kfree(pr); 643 kfree(pr);
666 return_VALUE(0); 644 return 0;
667 } 645 }
668 646
669 if (type == ACPI_BUS_REMOVAL_EJECT) { 647 if (type == ACPI_BUS_REMOVAL_EJECT) {
670 if (acpi_processor_handle_eject(pr)) 648 if (acpi_processor_handle_eject(pr))
671 return_VALUE(-EINVAL); 649 return -EINVAL;
672 } 650 }
673 651
674 acpi_processor_power_exit(pr, device); 652 acpi_processor_power_exit(pr, device);
675 653
676 status = acpi_remove_notify_handler(pr->handle, ACPI_DEVICE_NOTIFY, 654 status = acpi_remove_notify_handler(pr->handle, ACPI_DEVICE_NOTIFY,
677 acpi_processor_notify); 655 acpi_processor_notify);
678 if (ACPI_FAILURE(status)) {
679 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
680 "Error removing notify handler\n"));
681 }
682 656
683 acpi_processor_remove_fs(device); 657 acpi_processor_remove_fs(device);
684 658
@@ -686,7 +660,7 @@ static int acpi_processor_remove(struct acpi_device *device, int type)
686 660
687 kfree(pr); 661 kfree(pr);
688 662
689 return_VALUE(0); 663 return 0;
690} 664}
691 665
692#ifdef CONFIG_ACPI_HOTPLUG_CPU 666#ifdef CONFIG_ACPI_HOTPLUG_CPU
@@ -701,15 +675,13 @@ static int is_processor_present(acpi_handle handle)
701 acpi_status status; 675 acpi_status status;
702 unsigned long sta = 0; 676 unsigned long sta = 0;
703 677
704 ACPI_FUNCTION_TRACE("is_processor_present");
705 678
706 status = acpi_evaluate_integer(handle, "_STA", NULL, &sta); 679 status = acpi_evaluate_integer(handle, "_STA", NULL, &sta);
707 if (ACPI_FAILURE(status) || !(sta & ACPI_STA_PRESENT)) { 680 if (ACPI_FAILURE(status) || !(sta & ACPI_STA_PRESENT)) {
708 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 681 ACPI_EXCEPTION((AE_INFO, status, "Processor Device is not present"));
709 "Processor Device is not present\n")); 682 return 0;
710 return_VALUE(0);
711 } 683 }
712 return_VALUE(1); 684 return 1;
713} 685}
714 686
715static 687static
@@ -719,30 +691,29 @@ int acpi_processor_device_add(acpi_handle handle, struct acpi_device **device)
719 struct acpi_device *pdev; 691 struct acpi_device *pdev;
720 struct acpi_processor *pr; 692 struct acpi_processor *pr;
721 693
722 ACPI_FUNCTION_TRACE("acpi_processor_device_add");
723 694
724 if (acpi_get_parent(handle, &phandle)) { 695 if (acpi_get_parent(handle, &phandle)) {
725 return_VALUE(-ENODEV); 696 return -ENODEV;
726 } 697 }
727 698
728 if (acpi_bus_get_device(phandle, &pdev)) { 699 if (acpi_bus_get_device(phandle, &pdev)) {
729 return_VALUE(-ENODEV); 700 return -ENODEV;
730 } 701 }
731 702
732 if (acpi_bus_add(device, pdev, handle, ACPI_BUS_TYPE_PROCESSOR)) { 703 if (acpi_bus_add(device, pdev, handle, ACPI_BUS_TYPE_PROCESSOR)) {
733 return_VALUE(-ENODEV); 704 return -ENODEV;
734 } 705 }
735 706
736 acpi_bus_start(*device); 707 acpi_bus_start(*device);
737 708
738 pr = acpi_driver_data(*device); 709 pr = acpi_driver_data(*device);
739 if (!pr) 710 if (!pr)
740 return_VALUE(-ENODEV); 711 return -ENODEV;
741 712
742 if ((pr->id >= 0) && (pr->id < NR_CPUS)) { 713 if ((pr->id >= 0) && (pr->id < NR_CPUS)) {
743 kobject_uevent(&(*device)->kobj, KOBJ_ONLINE); 714 kobject_uevent(&(*device)->kobj, KOBJ_ONLINE);
744 } 715 }
745 return_VALUE(0); 716 return 0;
746} 717}
747 718
748static void 719static void
@@ -752,7 +723,6 @@ acpi_processor_hotplug_notify(acpi_handle handle, u32 event, void *data)
752 struct acpi_device *device = NULL; 723 struct acpi_device *device = NULL;
753 int result; 724 int result;
754 725
755 ACPI_FUNCTION_TRACE("acpi_processor_hotplug_notify");
756 726
757 switch (event) { 727 switch (event) {
758 case ACPI_NOTIFY_BUS_CHECK: 728 case ACPI_NOTIFY_BUS_CHECK:
@@ -767,15 +737,14 @@ acpi_processor_hotplug_notify(acpi_handle handle, u32 event, void *data)
767 if (acpi_bus_get_device(handle, &device)) { 737 if (acpi_bus_get_device(handle, &device)) {
768 result = acpi_processor_device_add(handle, &device); 738 result = acpi_processor_device_add(handle, &device);
769 if (result) 739 if (result)
770 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 740 printk(KERN_ERR PREFIX
771 "Unable to add the device\n")); 741 "Unable to add the device\n");
772 break; 742 break;
773 } 743 }
774 744
775 pr = acpi_driver_data(device); 745 pr = acpi_driver_data(device);
776 if (!pr) { 746 if (!pr) {
777 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 747 printk(KERN_ERR PREFIX "Driver data is NULL\n");
778 "Driver data is NULL\n"));
779 break; 748 break;
780 } 749 }
781 750
@@ -788,9 +757,8 @@ acpi_processor_hotplug_notify(acpi_handle handle, u32 event, void *data)
788 if ((!result) && ((pr->id >= 0) && (pr->id < NR_CPUS))) { 757 if ((!result) && ((pr->id >= 0) && (pr->id < NR_CPUS))) {
789 kobject_uevent(&device->kobj, KOBJ_ONLINE); 758 kobject_uevent(&device->kobj, KOBJ_ONLINE);
790 } else { 759 } else {
791 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 760 printk(KERN_ERR PREFIX "Device [%s] failed to start\n",
792 "Device [%s] failed to start\n", 761 acpi_device_bid(device));
793 acpi_device_bid(device)));
794 } 762 }
795 break; 763 break;
796 case ACPI_NOTIFY_EJECT_REQUEST: 764 case ACPI_NOTIFY_EJECT_REQUEST:
@@ -798,15 +766,15 @@ acpi_processor_hotplug_notify(acpi_handle handle, u32 event, void *data)
798 "received ACPI_NOTIFY_EJECT_REQUEST\n")); 766 "received ACPI_NOTIFY_EJECT_REQUEST\n"));
799 767
800 if (acpi_bus_get_device(handle, &device)) { 768 if (acpi_bus_get_device(handle, &device)) {
801 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 769 printk(KERN_ERR PREFIX
802 "Device don't exist, dropping EJECT\n")); 770 "Device don't exist, dropping EJECT\n");
803 break; 771 break;
804 } 772 }
805 pr = acpi_driver_data(device); 773 pr = acpi_driver_data(device);
806 if (!pr) { 774 if (!pr) {
807 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 775 printk(KERN_ERR PREFIX
808 "Driver data is NULL, dropping EJECT\n")); 776 "Driver data is NULL, dropping EJECT\n");
809 return_VOID; 777 return;
810 } 778 }
811 779
812 if ((pr->id < NR_CPUS) && (cpu_present(pr->id))) 780 if ((pr->id < NR_CPUS) && (cpu_present(pr->id)))
@@ -818,7 +786,7 @@ acpi_processor_hotplug_notify(acpi_handle handle, u32 event, void *data)
818 break; 786 break;
819 } 787 }
820 788
821 return_VOID; 789 return;
822} 790}
823 791
824static acpi_status 792static acpi_status
@@ -857,21 +825,20 @@ processor_walk_namespace_cb(acpi_handle handle,
857 825
858static acpi_status acpi_processor_hotadd_init(acpi_handle handle, int *p_cpu) 826static acpi_status acpi_processor_hotadd_init(acpi_handle handle, int *p_cpu)
859{ 827{
860 ACPI_FUNCTION_TRACE("acpi_processor_hotadd_init");
861 828
862 if (!is_processor_present(handle)) { 829 if (!is_processor_present(handle)) {
863 return_VALUE(AE_ERROR); 830 return AE_ERROR;
864 } 831 }
865 832
866 if (acpi_map_lsapic(handle, p_cpu)) 833 if (acpi_map_lsapic(handle, p_cpu))
867 return_VALUE(AE_ERROR); 834 return AE_ERROR;
868 835
869 if (arch_register_cpu(*p_cpu)) { 836 if (arch_register_cpu(*p_cpu)) {
870 acpi_unmap_lsapic(*p_cpu); 837 acpi_unmap_lsapic(*p_cpu);
871 return_VALUE(AE_ERROR); 838 return AE_ERROR;
872 } 839 }
873 840
874 return_VALUE(AE_OK); 841 return AE_OK;
875} 842}
876 843
877static int acpi_processor_handle_eject(struct acpi_processor *pr) 844static int acpi_processor_handle_eject(struct acpi_processor *pr)
@@ -928,20 +895,19 @@ static int __init acpi_processor_init(void)
928{ 895{
929 int result = 0; 896 int result = 0;
930 897
931 ACPI_FUNCTION_TRACE("acpi_processor_init");
932 898
933 memset(&processors, 0, sizeof(processors)); 899 memset(&processors, 0, sizeof(processors));
934 memset(&errata, 0, sizeof(errata)); 900 memset(&errata, 0, sizeof(errata));
935 901
936 acpi_processor_dir = proc_mkdir(ACPI_PROCESSOR_CLASS, acpi_root_dir); 902 acpi_processor_dir = proc_mkdir(ACPI_PROCESSOR_CLASS, acpi_root_dir);
937 if (!acpi_processor_dir) 903 if (!acpi_processor_dir)
938 return_VALUE(0); 904 return 0;
939 acpi_processor_dir->owner = THIS_MODULE; 905 acpi_processor_dir->owner = THIS_MODULE;
940 906
941 result = acpi_bus_register_driver(&acpi_processor_driver); 907 result = acpi_bus_register_driver(&acpi_processor_driver);
942 if (result < 0) { 908 if (result < 0) {
943 remove_proc_entry(ACPI_PROCESSOR_CLASS, acpi_root_dir); 909 remove_proc_entry(ACPI_PROCESSOR_CLASS, acpi_root_dir);
944 return_VALUE(0); 910 return 0;
945 } 911 }
946 912
947 acpi_processor_install_hotplug_notify(); 913 acpi_processor_install_hotplug_notify();
@@ -950,12 +916,11 @@ static int __init acpi_processor_init(void)
950 916
951 acpi_processor_ppc_init(); 917 acpi_processor_ppc_init();
952 918
953 return_VALUE(0); 919 return 0;
954} 920}
955 921
956static void __exit acpi_processor_exit(void) 922static void __exit acpi_processor_exit(void)
957{ 923{
958 ACPI_FUNCTION_TRACE("acpi_processor_exit");
959 924
960 acpi_processor_ppc_exit(); 925 acpi_processor_ppc_exit();
961 926
@@ -967,7 +932,7 @@ static void __exit acpi_processor_exit(void)
967 932
968 remove_proc_entry(ACPI_PROCESSOR_CLASS, acpi_root_dir); 933 remove_proc_entry(ACPI_PROCESSOR_CLASS, acpi_root_dir);
969 934
970 return_VOID; 935 return;
971} 936}
972 937
973module_init(acpi_processor_init); 938module_init(acpi_processor_init);
diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
index 3b97a5eae9e8..71066066d626 100644
--- a/drivers/acpi/processor_idle.c
+++ b/drivers/acpi/processor_idle.c
@@ -3,7 +3,7 @@
3 * 3 *
4 * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com> 4 * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
5 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com> 5 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
6 * Copyright (C) 2004 Dominik Brodowski <linux@brodo.de> 6 * Copyright (C) 2004, 2005 Dominik Brodowski <linux@brodo.de>
7 * Copyright (C) 2004 Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com> 7 * Copyright (C) 2004 Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
8 * - Added processor hotplug support 8 * - Added processor hotplug support
9 * Copyright (C) 2005 Venkatesh Pallipadi <venkatesh.pallipadi@intel.com> 9 * Copyright (C) 2005 Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
@@ -99,6 +99,9 @@ static int set_max_cstate(struct dmi_system_id *id)
99static struct dmi_system_id __cpuinitdata processor_power_dmi_table[] = { 99static struct dmi_system_id __cpuinitdata processor_power_dmi_table[] = {
100 { set_max_cstate, "IBM ThinkPad R40e", { 100 { set_max_cstate, "IBM ThinkPad R40e", {
101 DMI_MATCH(DMI_BIOS_VENDOR,"IBM"), 101 DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
102 DMI_MATCH(DMI_BIOS_VERSION,"1SET70WW")}, (void *)1},
103 { set_max_cstate, "IBM ThinkPad R40e", {
104 DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
102 DMI_MATCH(DMI_BIOS_VERSION,"1SET60WW")}, (void *)1}, 105 DMI_MATCH(DMI_BIOS_VERSION,"1SET60WW")}, (void *)1},
103 { set_max_cstate, "IBM ThinkPad R40e", { 106 { set_max_cstate, "IBM ThinkPad R40e", {
104 DMI_MATCH(DMI_BIOS_VENDOR,"IBM"), 107 DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
@@ -206,11 +209,11 @@ acpi_processor_power_activate(struct acpi_processor *pr,
206 209
207static void acpi_safe_halt(void) 210static void acpi_safe_halt(void)
208{ 211{
209 clear_thread_flag(TIF_POLLING_NRFLAG); 212 current_thread_info()->status &= ~TS_POLLING;
210 smp_mb__after_clear_bit(); 213 smp_mb__after_clear_bit();
211 if (!need_resched()) 214 if (!need_resched())
212 safe_halt(); 215 safe_halt();
213 set_thread_flag(TIF_POLLING_NRFLAG); 216 current_thread_info()->status |= TS_POLLING;
214} 217}
215 218
216static atomic_t c3_cpu_count; 219static atomic_t c3_cpu_count;
@@ -261,21 +264,15 @@ static void acpi_processor_idle(void)
261 u32 bm_status = 0; 264 u32 bm_status = 0;
262 unsigned long diff = jiffies - pr->power.bm_check_timestamp; 265 unsigned long diff = jiffies - pr->power.bm_check_timestamp;
263 266
264 if (diff > 32) 267 if (diff > 31)
265 diff = 32; 268 diff = 31;
266 269
267 while (diff) { 270 pr->power.bm_activity <<= diff;
268 /* if we didn't get called, assume there was busmaster activity */
269 diff--;
270 if (diff)
271 pr->power.bm_activity |= 0x1;
272 pr->power.bm_activity <<= 1;
273 }
274 271
275 acpi_get_register(ACPI_BITREG_BUS_MASTER_STATUS, 272 acpi_get_register(ACPI_BITREG_BUS_MASTER_STATUS,
276 &bm_status, ACPI_MTX_DO_NOT_LOCK); 273 &bm_status, ACPI_MTX_DO_NOT_LOCK);
277 if (bm_status) { 274 if (bm_status) {
278 pr->power.bm_activity++; 275 pr->power.bm_activity |= 0x1;
279 acpi_set_register(ACPI_BITREG_BUS_MASTER_STATUS, 276 acpi_set_register(ACPI_BITREG_BUS_MASTER_STATUS,
280 1, ACPI_MTX_DO_NOT_LOCK); 277 1, ACPI_MTX_DO_NOT_LOCK);
281 } 278 }
@@ -287,16 +284,16 @@ static void acpi_processor_idle(void)
287 else if (errata.piix4.bmisx) { 284 else if (errata.piix4.bmisx) {
288 if ((inb_p(errata.piix4.bmisx + 0x02) & 0x01) 285 if ((inb_p(errata.piix4.bmisx + 0x02) & 0x01)
289 || (inb_p(errata.piix4.bmisx + 0x0A) & 0x01)) 286 || (inb_p(errata.piix4.bmisx + 0x0A) & 0x01))
290 pr->power.bm_activity++; 287 pr->power.bm_activity |= 0x1;
291 } 288 }
292 289
293 pr->power.bm_check_timestamp = jiffies; 290 pr->power.bm_check_timestamp = jiffies;
294 291
295 /* 292 /*
296 * Apply bus mastering demotion policy. Automatically demote 293 * If bus mastering is or was active this jiffy, demote
297 * to avoid a faulty transition. Note that the processor 294 * to avoid a faulty transition. Note that the processor
298 * won't enter a low-power state during this call (to this 295 * won't enter a low-power state during this call (to this
299 * funciton) but should upon the next. 296 * function) but should upon the next.
300 * 297 *
301 * TBD: A better policy might be to fallback to the demotion 298 * TBD: A better policy might be to fallback to the demotion
302 * state (use it for this quantum only) istead of 299 * state (use it for this quantum only) istead of
@@ -304,7 +301,8 @@ static void acpi_processor_idle(void)
304 * qualification. This may, however, introduce DMA 301 * qualification. This may, however, introduce DMA
305 * issues (e.g. floppy DMA transfer overrun/underrun). 302 * issues (e.g. floppy DMA transfer overrun/underrun).
306 */ 303 */
307 if (pr->power.bm_activity & cx->demotion.threshold.bm) { 304 if ((pr->power.bm_activity & 0x1) &&
305 cx->demotion.threshold.bm) {
308 local_irq_enable(); 306 local_irq_enable();
309 next_state = cx->demotion.state; 307 next_state = cx->demotion.state;
310 goto end; 308 goto end;
@@ -322,18 +320,16 @@ static void acpi_processor_idle(void)
322 cx = &pr->power.states[ACPI_STATE_C1]; 320 cx = &pr->power.states[ACPI_STATE_C1];
323#endif 321#endif
324 322
325 cx->usage++;
326
327 /* 323 /*
328 * Sleep: 324 * Sleep:
329 * ------ 325 * ------
330 * Invoke the current Cx state to put the processor to sleep. 326 * Invoke the current Cx state to put the processor to sleep.
331 */ 327 */
332 if (cx->type == ACPI_STATE_C2 || cx->type == ACPI_STATE_C3) { 328 if (cx->type == ACPI_STATE_C2 || cx->type == ACPI_STATE_C3) {
333 clear_thread_flag(TIF_POLLING_NRFLAG); 329 current_thread_info()->status &= ~TS_POLLING;
334 smp_mb__after_clear_bit(); 330 smp_mb__after_clear_bit();
335 if (need_resched()) { 331 if (need_resched()) {
336 set_thread_flag(TIF_POLLING_NRFLAG); 332 current_thread_info()->status |= TS_POLLING;
337 local_irq_enable(); 333 local_irq_enable();
338 return; 334 return;
339 } 335 }
@@ -365,13 +361,20 @@ static void acpi_processor_idle(void)
365 t1 = inl(acpi_fadt.xpm_tmr_blk.address); 361 t1 = inl(acpi_fadt.xpm_tmr_blk.address);
366 /* Invoke C2 */ 362 /* Invoke C2 */
367 inb(cx->address); 363 inb(cx->address);
368 /* Dummy op - must do something useless after P_LVL2 read */ 364 /* Dummy wait op - must do something useless after P_LVL2 read
365 because chipsets cannot guarantee that STPCLK# signal
366 gets asserted in time to freeze execution properly. */
369 t2 = inl(acpi_fadt.xpm_tmr_blk.address); 367 t2 = inl(acpi_fadt.xpm_tmr_blk.address);
370 /* Get end time (ticks) */ 368 /* Get end time (ticks) */
371 t2 = inl(acpi_fadt.xpm_tmr_blk.address); 369 t2 = inl(acpi_fadt.xpm_tmr_blk.address);
370
371#ifdef CONFIG_GENERIC_TIME
372 /* TSC halts in C2, so notify users */
373 mark_tsc_unstable();
374#endif
372 /* Re-enable interrupts */ 375 /* Re-enable interrupts */
373 local_irq_enable(); 376 local_irq_enable();
374 set_thread_flag(TIF_POLLING_NRFLAG); 377 current_thread_info()->status |= TS_POLLING;
375 /* Compute time (ticks) that we were actually asleep */ 378 /* Compute time (ticks) that we were actually asleep */
376 sleep_ticks = 379 sleep_ticks =
377 ticks_elapsed(t1, t2) - cx->latency_ticks - C2_OVERHEAD; 380 ticks_elapsed(t1, t2) - cx->latency_ticks - C2_OVERHEAD;
@@ -398,7 +401,7 @@ static void acpi_processor_idle(void)
398 t1 = inl(acpi_fadt.xpm_tmr_blk.address); 401 t1 = inl(acpi_fadt.xpm_tmr_blk.address);
399 /* Invoke C3 */ 402 /* Invoke C3 */
400 inb(cx->address); 403 inb(cx->address);
401 /* Dummy op - must do something useless after P_LVL3 read */ 404 /* Dummy wait op (see above) */
402 t2 = inl(acpi_fadt.xpm_tmr_blk.address); 405 t2 = inl(acpi_fadt.xpm_tmr_blk.address);
403 /* Get end time (ticks) */ 406 /* Get end time (ticks) */
404 t2 = inl(acpi_fadt.xpm_tmr_blk.address); 407 t2 = inl(acpi_fadt.xpm_tmr_blk.address);
@@ -409,9 +412,13 @@ static void acpi_processor_idle(void)
409 ACPI_MTX_DO_NOT_LOCK); 412 ACPI_MTX_DO_NOT_LOCK);
410 } 413 }
411 414
415#ifdef CONFIG_GENERIC_TIME
416 /* TSC halts in C3, so notify users */
417 mark_tsc_unstable();
418#endif
412 /* Re-enable interrupts */ 419 /* Re-enable interrupts */
413 local_irq_enable(); 420 local_irq_enable();
414 set_thread_flag(TIF_POLLING_NRFLAG); 421 current_thread_info()->status |= TS_POLLING;
415 /* Compute time (ticks) that we were actually asleep */ 422 /* Compute time (ticks) that we were actually asleep */
416 sleep_ticks = 423 sleep_ticks =
417 ticks_elapsed(t1, t2) - cx->latency_ticks - C3_OVERHEAD; 424 ticks_elapsed(t1, t2) - cx->latency_ticks - C3_OVERHEAD;
@@ -421,6 +428,9 @@ static void acpi_processor_idle(void)
421 local_irq_enable(); 428 local_irq_enable();
422 return; 429 return;
423 } 430 }
431 cx->usage++;
432 if ((cx->type != ACPI_STATE_C1) && (sleep_ticks > 0))
433 cx->time += sleep_ticks;
424 434
425 next_state = pr->power.state; 435 next_state = pr->power.state;
426 436
@@ -508,10 +518,9 @@ static int acpi_processor_set_power_policy(struct acpi_processor *pr)
508 struct acpi_processor_cx *higher = NULL; 518 struct acpi_processor_cx *higher = NULL;
509 struct acpi_processor_cx *cx; 519 struct acpi_processor_cx *cx;
510 520
511 ACPI_FUNCTION_TRACE("acpi_processor_set_power_policy");
512 521
513 if (!pr) 522 if (!pr)
514 return_VALUE(-EINVAL); 523 return -EINVAL;
515 524
516 /* 525 /*
517 * This function sets the default Cx state policy (OS idle handler). 526 * This function sets the default Cx state policy (OS idle handler).
@@ -535,7 +544,7 @@ static int acpi_processor_set_power_policy(struct acpi_processor *pr)
535 } 544 }
536 545
537 if (!state_is_set) 546 if (!state_is_set)
538 return_VALUE(-ENODEV); 547 return -ENODEV;
539 548
540 /* demotion */ 549 /* demotion */
541 for (i = 1; i < ACPI_PROCESSOR_MAX_POWER; i++) { 550 for (i = 1; i < ACPI_PROCESSOR_MAX_POWER; i++) {
@@ -574,18 +583,17 @@ static int acpi_processor_set_power_policy(struct acpi_processor *pr)
574 higher = cx; 583 higher = cx;
575 } 584 }
576 585
577 return_VALUE(0); 586 return 0;
578} 587}
579 588
580static int acpi_processor_get_power_info_fadt(struct acpi_processor *pr) 589static int acpi_processor_get_power_info_fadt(struct acpi_processor *pr)
581{ 590{
582 ACPI_FUNCTION_TRACE("acpi_processor_get_power_info_fadt");
583 591
584 if (!pr) 592 if (!pr)
585 return_VALUE(-EINVAL); 593 return -EINVAL;
586 594
587 if (!pr->pblk) 595 if (!pr->pblk)
588 return_VALUE(-ENODEV); 596 return -ENODEV;
589 597
590 /* if info is obtained from pblk/fadt, type equals state */ 598 /* if info is obtained from pblk/fadt, type equals state */
591 pr->power.states[ACPI_STATE_C2].type = ACPI_STATE_C2; 599 pr->power.states[ACPI_STATE_C2].type = ACPI_STATE_C2;
@@ -597,7 +605,7 @@ static int acpi_processor_get_power_info_fadt(struct acpi_processor *pr)
597 * an SMP system. 605 * an SMP system.
598 */ 606 */
599 if ((num_online_cpus() > 1) && !acpi_fadt.plvl2_up) 607 if ((num_online_cpus() > 1) && !acpi_fadt.plvl2_up)
600 return_VALUE(-ENODEV); 608 return -ENODEV;
601#endif 609#endif
602 610
603 /* determine C2 and C3 address from pblk */ 611 /* determine C2 and C3 address from pblk */
@@ -613,12 +621,11 @@ static int acpi_processor_get_power_info_fadt(struct acpi_processor *pr)
613 pr->power.states[ACPI_STATE_C2].address, 621 pr->power.states[ACPI_STATE_C2].address,
614 pr->power.states[ACPI_STATE_C3].address)); 622 pr->power.states[ACPI_STATE_C3].address));
615 623
616 return_VALUE(0); 624 return 0;
617} 625}
618 626
619static int acpi_processor_get_power_info_default_c1(struct acpi_processor *pr) 627static int acpi_processor_get_power_info_default_c1(struct acpi_processor *pr)
620{ 628{
621 ACPI_FUNCTION_TRACE("acpi_processor_get_power_info_default_c1");
622 629
623 /* Zero initialize all the C-states info. */ 630 /* Zero initialize all the C-states info. */
624 memset(pr->power.states, 0, sizeof(pr->power.states)); 631 memset(pr->power.states, 0, sizeof(pr->power.states));
@@ -631,7 +638,7 @@ static int acpi_processor_get_power_info_default_c1(struct acpi_processor *pr)
631 pr->power.states[ACPI_STATE_C0].valid = 1; 638 pr->power.states[ACPI_STATE_C0].valid = 1;
632 pr->power.states[ACPI_STATE_C1].valid = 1; 639 pr->power.states[ACPI_STATE_C1].valid = 1;
633 640
634 return_VALUE(0); 641 return 0;
635} 642}
636 643
637static int acpi_processor_get_power_info_cst(struct acpi_processor *pr) 644static int acpi_processor_get_power_info_cst(struct acpi_processor *pr)
@@ -643,10 +650,9 @@ static int acpi_processor_get_power_info_cst(struct acpi_processor *pr)
643 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; 650 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
644 union acpi_object *cst; 651 union acpi_object *cst;
645 652
646 ACPI_FUNCTION_TRACE("acpi_processor_get_power_info_cst");
647 653
648 if (nocst) 654 if (nocst)
649 return_VALUE(-ENODEV); 655 return -ENODEV;
650 656
651 current_count = 1; 657 current_count = 1;
652 658
@@ -658,15 +664,14 @@ static int acpi_processor_get_power_info_cst(struct acpi_processor *pr)
658 status = acpi_evaluate_object(pr->handle, "_CST", NULL, &buffer); 664 status = acpi_evaluate_object(pr->handle, "_CST", NULL, &buffer);
659 if (ACPI_FAILURE(status)) { 665 if (ACPI_FAILURE(status)) {
660 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No _CST, giving up\n")); 666 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No _CST, giving up\n"));
661 return_VALUE(-ENODEV); 667 return -ENODEV;
662 } 668 }
663 669
664 cst = (union acpi_object *)buffer.pointer; 670 cst = (union acpi_object *)buffer.pointer;
665 671
666 /* There must be at least 2 elements */ 672 /* There must be at least 2 elements */
667 if (!cst || (cst->type != ACPI_TYPE_PACKAGE) || cst->package.count < 2) { 673 if (!cst || (cst->type != ACPI_TYPE_PACKAGE) || cst->package.count < 2) {
668 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 674 printk(KERN_ERR PREFIX "not enough elements in _CST\n");
669 "not enough elements in _CST\n"));
670 status = -EFAULT; 675 status = -EFAULT;
671 goto end; 676 goto end;
672 } 677 }
@@ -675,8 +680,7 @@ static int acpi_processor_get_power_info_cst(struct acpi_processor *pr)
675 680
676 /* Validate number of power states. */ 681 /* Validate number of power states. */
677 if (count < 1 || count != cst->package.count - 1) { 682 if (count < 1 || count != cst->package.count - 1) {
678 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 683 printk(KERN_ERR PREFIX "count given by _CST is not valid\n");
679 "count given by _CST is not valid\n"));
680 status = -EFAULT; 684 status = -EFAULT;
681 goto end; 685 goto end;
682 } 686 }
@@ -764,17 +768,16 @@ static int acpi_processor_get_power_info_cst(struct acpi_processor *pr)
764 status = -EFAULT; 768 status = -EFAULT;
765 769
766 end: 770 end:
767 acpi_os_free(buffer.pointer); 771 kfree(buffer.pointer);
768 772
769 return_VALUE(status); 773 return status;
770} 774}
771 775
772static void acpi_processor_power_verify_c2(struct acpi_processor_cx *cx) 776static void acpi_processor_power_verify_c2(struct acpi_processor_cx *cx)
773{ 777{
774 ACPI_FUNCTION_TRACE("acpi_processor_get_power_verify_c2");
775 778
776 if (!cx->address) 779 if (!cx->address)
777 return_VOID; 780 return;
778 781
779 /* 782 /*
780 * C2 latency must be less than or equal to 100 783 * C2 latency must be less than or equal to 100
@@ -783,7 +786,7 @@ static void acpi_processor_power_verify_c2(struct acpi_processor_cx *cx)
783 else if (cx->latency > ACPI_PROCESSOR_MAX_C2_LATENCY) { 786 else if (cx->latency > ACPI_PROCESSOR_MAX_C2_LATENCY) {
784 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 787 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
785 "latency too large [%d]\n", cx->latency)); 788 "latency too large [%d]\n", cx->latency));
786 return_VOID; 789 return;
787 } 790 }
788 791
789 /* 792 /*
@@ -793,7 +796,7 @@ static void acpi_processor_power_verify_c2(struct acpi_processor_cx *cx)
793 cx->valid = 1; 796 cx->valid = 1;
794 cx->latency_ticks = US_TO_PM_TIMER_TICKS(cx->latency); 797 cx->latency_ticks = US_TO_PM_TIMER_TICKS(cx->latency);
795 798
796 return_VOID; 799 return;
797} 800}
798 801
799static void acpi_processor_power_verify_c3(struct acpi_processor *pr, 802static void acpi_processor_power_verify_c3(struct acpi_processor *pr,
@@ -801,10 +804,9 @@ static void acpi_processor_power_verify_c3(struct acpi_processor *pr,
801{ 804{
802 static int bm_check_flag; 805 static int bm_check_flag;
803 806
804 ACPI_FUNCTION_TRACE("acpi_processor_get_power_verify_c3");
805 807
806 if (!cx->address) 808 if (!cx->address)
807 return_VOID; 809 return;
808 810
809 /* 811 /*
810 * C3 latency must be less than or equal to 1000 812 * C3 latency must be less than or equal to 1000
@@ -813,7 +815,7 @@ static void acpi_processor_power_verify_c3(struct acpi_processor *pr,
813 else if (cx->latency > ACPI_PROCESSOR_MAX_C3_LATENCY) { 815 else if (cx->latency > ACPI_PROCESSOR_MAX_C3_LATENCY) {
814 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 816 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
815 "latency too large [%d]\n", cx->latency)); 817 "latency too large [%d]\n", cx->latency));
816 return_VOID; 818 return;
817 } 819 }
818 820
819 /* 821 /*
@@ -826,7 +828,7 @@ static void acpi_processor_power_verify_c3(struct acpi_processor *pr,
826 else if (errata.piix4.fdma) { 828 else if (errata.piix4.fdma) {
827 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 829 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
828 "C3 not supported on PIIX4 with Type-F DMA\n")); 830 "C3 not supported on PIIX4 with Type-F DMA\n"));
829 return_VOID; 831 return;
830 } 832 }
831 833
832 /* All the logic here assumes flags.bm_check is same across all CPUs */ 834 /* All the logic here assumes flags.bm_check is same across all CPUs */
@@ -843,7 +845,7 @@ static void acpi_processor_power_verify_c3(struct acpi_processor *pr,
843 if (!pr->flags.bm_control) { 845 if (!pr->flags.bm_control) {
844 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 846 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
845 "C3 support requires bus mastering control\n")); 847 "C3 support requires bus mastering control\n"));
846 return_VOID; 848 return;
847 } 849 }
848 } else { 850 } else {
849 /* 851 /*
@@ -854,7 +856,7 @@ static void acpi_processor_power_verify_c3(struct acpi_processor *pr,
854 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 856 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
855 "Cache invalidation should work properly" 857 "Cache invalidation should work properly"
856 " for C3 to be enabled on SMP systems\n")); 858 " for C3 to be enabled on SMP systems\n"));
857 return_VOID; 859 return;
858 } 860 }
859 acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD, 861 acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD,
860 0, ACPI_MTX_DO_NOT_LOCK); 862 0, ACPI_MTX_DO_NOT_LOCK);
@@ -869,7 +871,7 @@ static void acpi_processor_power_verify_c3(struct acpi_processor *pr,
869 cx->valid = 1; 871 cx->valid = 1;
870 cx->latency_ticks = US_TO_PM_TIMER_TICKS(cx->latency); 872 cx->latency_ticks = US_TO_PM_TIMER_TICKS(cx->latency);
871 873
872 return_VOID; 874 return;
873} 875}
874 876
875static int acpi_processor_power_verify(struct acpi_processor *pr) 877static int acpi_processor_power_verify(struct acpi_processor *pr)
@@ -928,7 +930,6 @@ static int acpi_processor_get_power_info(struct acpi_processor *pr)
928 unsigned int i; 930 unsigned int i;
929 int result; 931 int result;
930 932
931 ACPI_FUNCTION_TRACE("acpi_processor_get_power_info");
932 933
933 /* NOTE: the idle thread may not be running while calling 934 /* NOTE: the idle thread may not be running while calling
934 * this function */ 935 * this function */
@@ -951,7 +952,7 @@ static int acpi_processor_get_power_info(struct acpi_processor *pr)
951 */ 952 */
952 result = acpi_processor_set_power_policy(pr); 953 result = acpi_processor_set_power_policy(pr);
953 if (result) 954 if (result)
954 return_VALUE(result); 955 return result;
955 956
956 /* 957 /*
957 * if one state of type C2 or C3 is available, mark this 958 * if one state of type C2 or C3 is available, mark this
@@ -965,24 +966,23 @@ static int acpi_processor_get_power_info(struct acpi_processor *pr)
965 } 966 }
966 } 967 }
967 968
968 return_VALUE(0); 969 return 0;
969} 970}
970 971
971int acpi_processor_cst_has_changed(struct acpi_processor *pr) 972int acpi_processor_cst_has_changed(struct acpi_processor *pr)
972{ 973{
973 int result = 0; 974 int result = 0;
974 975
975 ACPI_FUNCTION_TRACE("acpi_processor_cst_has_changed");
976 976
977 if (!pr) 977 if (!pr)
978 return_VALUE(-EINVAL); 978 return -EINVAL;
979 979
980 if (nocst) { 980 if (nocst) {
981 return_VALUE(-ENODEV); 981 return -ENODEV;
982 } 982 }
983 983
984 if (!pr->flags.power_setup_done) 984 if (!pr->flags.power_setup_done)
985 return_VALUE(-ENODEV); 985 return -ENODEV;
986 986
987 /* Fall back to the default idle loop */ 987 /* Fall back to the default idle loop */
988 pm_idle = pm_idle_save; 988 pm_idle = pm_idle_save;
@@ -993,7 +993,7 @@ int acpi_processor_cst_has_changed(struct acpi_processor *pr)
993 if ((pr->flags.power == 1) && (pr->flags.power_setup_done)) 993 if ((pr->flags.power == 1) && (pr->flags.power_setup_done))
994 pm_idle = acpi_processor_idle; 994 pm_idle = acpi_processor_idle;
995 995
996 return_VALUE(result); 996 return result;
997} 997}
998 998
999/* proc interface */ 999/* proc interface */
@@ -1003,7 +1003,6 @@ static int acpi_processor_power_seq_show(struct seq_file *seq, void *offset)
1003 struct acpi_processor *pr = (struct acpi_processor *)seq->private; 1003 struct acpi_processor *pr = (struct acpi_processor *)seq->private;
1004 unsigned int i; 1004 unsigned int i;
1005 1005
1006 ACPI_FUNCTION_TRACE("acpi_processor_power_seq_show");
1007 1006
1008 if (!pr) 1007 if (!pr)
1009 goto end; 1008 goto end;
@@ -1055,13 +1054,14 @@ static int acpi_processor_power_seq_show(struct seq_file *seq, void *offset)
1055 else 1054 else
1056 seq_puts(seq, "demotion[--] "); 1055 seq_puts(seq, "demotion[--] ");
1057 1056
1058 seq_printf(seq, "latency[%03d] usage[%08d]\n", 1057 seq_printf(seq, "latency[%03d] usage[%08d] duration[%020llu]\n",
1059 pr->power.states[i].latency, 1058 pr->power.states[i].latency,
1060 pr->power.states[i].usage); 1059 pr->power.states[i].usage,
1060 pr->power.states[i].time);
1061 } 1061 }
1062 1062
1063 end: 1063 end:
1064 return_VALUE(0); 1064 return 0;
1065} 1065}
1066 1066
1067static int acpi_processor_power_open_fs(struct inode *inode, struct file *file) 1067static int acpi_processor_power_open_fs(struct inode *inode, struct file *file)
@@ -1070,7 +1070,7 @@ static int acpi_processor_power_open_fs(struct inode *inode, struct file *file)
1070 PDE(inode)->data); 1070 PDE(inode)->data);
1071} 1071}
1072 1072
1073static struct file_operations acpi_processor_power_fops = { 1073static const struct file_operations acpi_processor_power_fops = {
1074 .open = acpi_processor_power_open_fs, 1074 .open = acpi_processor_power_open_fs,
1075 .read = seq_read, 1075 .read = seq_read,
1076 .llseek = seq_lseek, 1076 .llseek = seq_lseek,
@@ -1085,7 +1085,6 @@ int acpi_processor_power_init(struct acpi_processor *pr,
1085 struct proc_dir_entry *entry = NULL; 1085 struct proc_dir_entry *entry = NULL;
1086 unsigned int i; 1086 unsigned int i;
1087 1087
1088 ACPI_FUNCTION_TRACE("acpi_processor_power_init");
1089 1088
1090 if (!first_run) { 1089 if (!first_run) {
1091 dmi_check_system(processor_power_dmi_table); 1090 dmi_check_system(processor_power_dmi_table);
@@ -1097,14 +1096,14 @@ int acpi_processor_power_init(struct acpi_processor *pr,
1097 } 1096 }
1098 1097
1099 if (!pr) 1098 if (!pr)
1100 return_VALUE(-EINVAL); 1099 return -EINVAL;
1101 1100
1102 if (acpi_fadt.cst_cnt && !nocst) { 1101 if (acpi_fadt.cst_cnt && !nocst) {
1103 status = 1102 status =
1104 acpi_os_write_port(acpi_fadt.smi_cmd, acpi_fadt.cst_cnt, 8); 1103 acpi_os_write_port(acpi_fadt.smi_cmd, acpi_fadt.cst_cnt, 8);
1105 if (ACPI_FAILURE(status)) { 1104 if (ACPI_FAILURE(status)) {
1106 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1105 ACPI_EXCEPTION((AE_INFO, status,
1107 "Notifying BIOS of _CST ability failed\n")); 1106 "Notifying BIOS of _CST ability failed"));
1108 } 1107 }
1109 } 1108 }
1110 1109
@@ -1133,9 +1132,7 @@ int acpi_processor_power_init(struct acpi_processor *pr,
1133 entry = create_proc_entry(ACPI_PROCESSOR_FILE_POWER, 1132 entry = create_proc_entry(ACPI_PROCESSOR_FILE_POWER,
1134 S_IRUGO, acpi_device_dir(device)); 1133 S_IRUGO, acpi_device_dir(device));
1135 if (!entry) 1134 if (!entry)
1136 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1135 return -EIO;
1137 "Unable to create '%s' fs entry\n",
1138 ACPI_PROCESSOR_FILE_POWER));
1139 else { 1136 else {
1140 entry->proc_fops = &acpi_processor_power_fops; 1137 entry->proc_fops = &acpi_processor_power_fops;
1141 entry->data = acpi_driver_data(device); 1138 entry->data = acpi_driver_data(device);
@@ -1144,13 +1141,12 @@ int acpi_processor_power_init(struct acpi_processor *pr,
1144 1141
1145 pr->flags.power_setup_done = 1; 1142 pr->flags.power_setup_done = 1;
1146 1143
1147 return_VALUE(0); 1144 return 0;
1148} 1145}
1149 1146
1150int acpi_processor_power_exit(struct acpi_processor *pr, 1147int acpi_processor_power_exit(struct acpi_processor *pr,
1151 struct acpi_device *device) 1148 struct acpi_device *device)
1152{ 1149{
1153 ACPI_FUNCTION_TRACE("acpi_processor_power_exit");
1154 1150
1155 pr->flags.power_setup_done = 0; 1151 pr->flags.power_setup_done = 0;
1156 1152
@@ -1170,5 +1166,5 @@ int acpi_processor_power_exit(struct acpi_processor *pr,
1170 cpu_idle_wait(); 1166 cpu_idle_wait();
1171 } 1167 }
1172 1168
1173 return_VALUE(0); 1169 return 0;
1174} 1170}
diff --git a/drivers/acpi/processor_perflib.c b/drivers/acpi/processor_perflib.c
index 41aaaba74b19..7ba5e49ab302 100644
--- a/drivers/acpi/processor_perflib.c
+++ b/drivers/acpi/processor_perflib.c
@@ -108,10 +108,9 @@ static int acpi_processor_get_platform_limit(struct acpi_processor *pr)
108 acpi_status status = 0; 108 acpi_status status = 0;
109 unsigned long ppc = 0; 109 unsigned long ppc = 0;
110 110
111 ACPI_FUNCTION_TRACE("acpi_processor_get_platform_limit");
112 111
113 if (!pr) 112 if (!pr)
114 return_VALUE(-EINVAL); 113 return -EINVAL;
115 114
116 /* 115 /*
117 * _PPC indicates the maximum state currently supported by the platform 116 * _PPC indicates the maximum state currently supported by the platform
@@ -123,13 +122,13 @@ static int acpi_processor_get_platform_limit(struct acpi_processor *pr)
123 acpi_processor_ppc_status |= PPC_IN_USE; 122 acpi_processor_ppc_status |= PPC_IN_USE;
124 123
125 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { 124 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
126 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error evaluating _PPC\n")); 125 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PPC"));
127 return_VALUE(-ENODEV); 126 return -ENODEV;
128 } 127 }
129 128
130 pr->performance_platform_limit = (int)ppc; 129 pr->performance_platform_limit = (int)ppc;
131 130
132 return_VALUE(0); 131 return 0;
133} 132}
134 133
135int acpi_processor_ppc_has_changed(struct acpi_processor *pr) 134int acpi_processor_ppc_has_changed(struct acpi_processor *pr)
@@ -168,18 +167,17 @@ static int acpi_processor_get_performance_control(struct acpi_processor *pr)
168 union acpi_object *pct = NULL; 167 union acpi_object *pct = NULL;
169 union acpi_object obj = { 0 }; 168 union acpi_object obj = { 0 };
170 169
171 ACPI_FUNCTION_TRACE("acpi_processor_get_performance_control");
172 170
173 status = acpi_evaluate_object(pr->handle, "_PCT", NULL, &buffer); 171 status = acpi_evaluate_object(pr->handle, "_PCT", NULL, &buffer);
174 if (ACPI_FAILURE(status)) { 172 if (ACPI_FAILURE(status)) {
175 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error evaluating _PCT\n")); 173 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PCT"));
176 return_VALUE(-ENODEV); 174 return -ENODEV;
177 } 175 }
178 176
179 pct = (union acpi_object *)buffer.pointer; 177 pct = (union acpi_object *)buffer.pointer;
180 if (!pct || (pct->type != ACPI_TYPE_PACKAGE) 178 if (!pct || (pct->type != ACPI_TYPE_PACKAGE)
181 || (pct->package.count != 2)) { 179 || (pct->package.count != 2)) {
182 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _PCT data\n")); 180 printk(KERN_ERR PREFIX "Invalid _PCT data\n");
183 result = -EFAULT; 181 result = -EFAULT;
184 goto end; 182 goto end;
185 } 183 }
@@ -193,8 +191,7 @@ static int acpi_processor_get_performance_control(struct acpi_processor *pr)
193 if ((obj.type != ACPI_TYPE_BUFFER) 191 if ((obj.type != ACPI_TYPE_BUFFER)
194 || (obj.buffer.length < sizeof(struct acpi_pct_register)) 192 || (obj.buffer.length < sizeof(struct acpi_pct_register))
195 || (obj.buffer.pointer == NULL)) { 193 || (obj.buffer.pointer == NULL)) {
196 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 194 printk(KERN_ERR PREFIX "Invalid _PCT data (control_register)\n");
197 "Invalid _PCT data (control_register)\n"));
198 result = -EFAULT; 195 result = -EFAULT;
199 goto end; 196 goto end;
200 } 197 }
@@ -210,8 +207,7 @@ static int acpi_processor_get_performance_control(struct acpi_processor *pr)
210 if ((obj.type != ACPI_TYPE_BUFFER) 207 if ((obj.type != ACPI_TYPE_BUFFER)
211 || (obj.buffer.length < sizeof(struct acpi_pct_register)) 208 || (obj.buffer.length < sizeof(struct acpi_pct_register))
212 || (obj.buffer.pointer == NULL)) { 209 || (obj.buffer.pointer == NULL)) {
213 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 210 printk(KERN_ERR PREFIX "Invalid _PCT data (status_register)\n");
214 "Invalid _PCT data (status_register)\n"));
215 result = -EFAULT; 211 result = -EFAULT;
216 goto end; 212 goto end;
217 } 213 }
@@ -220,9 +216,9 @@ static int acpi_processor_get_performance_control(struct acpi_processor *pr)
220 sizeof(struct acpi_pct_register)); 216 sizeof(struct acpi_pct_register));
221 217
222 end: 218 end:
223 acpi_os_free(buffer.pointer); 219 kfree(buffer.pointer);
224 220
225 return_VALUE(result); 221 return result;
226} 222}
227 223
228static int acpi_processor_get_performance_states(struct acpi_processor *pr) 224static int acpi_processor_get_performance_states(struct acpi_processor *pr)
@@ -235,17 +231,16 @@ static int acpi_processor_get_performance_states(struct acpi_processor *pr)
235 union acpi_object *pss = NULL; 231 union acpi_object *pss = NULL;
236 int i; 232 int i;
237 233
238 ACPI_FUNCTION_TRACE("acpi_processor_get_performance_states");
239 234
240 status = acpi_evaluate_object(pr->handle, "_PSS", NULL, &buffer); 235 status = acpi_evaluate_object(pr->handle, "_PSS", NULL, &buffer);
241 if (ACPI_FAILURE(status)) { 236 if (ACPI_FAILURE(status)) {
242 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error evaluating _PSS\n")); 237 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PSS"));
243 return_VALUE(-ENODEV); 238 return -ENODEV;
244 } 239 }
245 240
246 pss = (union acpi_object *)buffer.pointer; 241 pss = (union acpi_object *)buffer.pointer;
247 if (!pss || (pss->type != ACPI_TYPE_PACKAGE)) { 242 if (!pss || (pss->type != ACPI_TYPE_PACKAGE)) {
248 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _PSS data\n")); 243 printk(KERN_ERR PREFIX "Invalid _PSS data\n");
249 result = -EFAULT; 244 result = -EFAULT;
250 goto end; 245 goto end;
251 } 246 }
@@ -274,8 +269,7 @@ static int acpi_processor_get_performance_states(struct acpi_processor *pr)
274 status = acpi_extract_package(&(pss->package.elements[i]), 269 status = acpi_extract_package(&(pss->package.elements[i]),
275 &format, &state); 270 &format, &state);
276 if (ACPI_FAILURE(status)) { 271 if (ACPI_FAILURE(status)) {
277 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 272 ACPI_EXCEPTION((AE_INFO, status, "Invalid _PSS data"));
278 "Invalid _PSS data\n"));
279 result = -EFAULT; 273 result = -EFAULT;
280 kfree(pr->performance->states); 274 kfree(pr->performance->states);
281 goto end; 275 goto end;
@@ -291,8 +285,8 @@ static int acpi_processor_get_performance_states(struct acpi_processor *pr)
291 (u32) px->control, (u32) px->status)); 285 (u32) px->control, (u32) px->status));
292 286
293 if (!px->core_frequency) { 287 if (!px->core_frequency) {
294 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 288 printk(KERN_ERR PREFIX
295 "Invalid _PSS data: freq is zero\n")); 289 "Invalid _PSS data: freq is zero\n");
296 result = -EFAULT; 290 result = -EFAULT;
297 kfree(pr->performance->states); 291 kfree(pr->performance->states);
298 goto end; 292 goto end;
@@ -300,9 +294,9 @@ static int acpi_processor_get_performance_states(struct acpi_processor *pr)
300 } 294 }
301 295
302 end: 296 end:
303 acpi_os_free(buffer.pointer); 297 kfree(buffer.pointer);
304 298
305 return_VALUE(result); 299 return result;
306} 300}
307 301
308static int acpi_processor_get_performance_info(struct acpi_processor *pr) 302static int acpi_processor_get_performance_info(struct acpi_processor *pr)
@@ -311,31 +305,30 @@ static int acpi_processor_get_performance_info(struct acpi_processor *pr)
311 acpi_status status = AE_OK; 305 acpi_status status = AE_OK;
312 acpi_handle handle = NULL; 306 acpi_handle handle = NULL;
313 307
314 ACPI_FUNCTION_TRACE("acpi_processor_get_performance_info");
315 308
316 if (!pr || !pr->performance || !pr->handle) 309 if (!pr || !pr->performance || !pr->handle)
317 return_VALUE(-EINVAL); 310 return -EINVAL;
318 311
319 status = acpi_get_handle(pr->handle, "_PCT", &handle); 312 status = acpi_get_handle(pr->handle, "_PCT", &handle);
320 if (ACPI_FAILURE(status)) { 313 if (ACPI_FAILURE(status)) {
321 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 314 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
322 "ACPI-based processor performance control unavailable\n")); 315 "ACPI-based processor performance control unavailable\n"));
323 return_VALUE(-ENODEV); 316 return -ENODEV;
324 } 317 }
325 318
326 result = acpi_processor_get_performance_control(pr); 319 result = acpi_processor_get_performance_control(pr);
327 if (result) 320 if (result)
328 return_VALUE(result); 321 return result;
329 322
330 result = acpi_processor_get_performance_states(pr); 323 result = acpi_processor_get_performance_states(pr);
331 if (result) 324 if (result)
332 return_VALUE(result); 325 return result;
333 326
334 result = acpi_processor_get_platform_limit(pr); 327 result = acpi_processor_get_platform_limit(pr);
335 if (result) 328 if (result)
336 return_VALUE(result); 329 return result;
337 330
338 return_VALUE(0); 331 return 0;
339} 332}
340 333
341int acpi_processor_notify_smm(struct module *calling_module) 334int acpi_processor_notify_smm(struct module *calling_module)
@@ -343,13 +336,12 @@ int acpi_processor_notify_smm(struct module *calling_module)
343 acpi_status status; 336 acpi_status status;
344 static int is_done = 0; 337 static int is_done = 0;
345 338
346 ACPI_FUNCTION_TRACE("acpi_processor_notify_smm");
347 339
348 if (!(acpi_processor_ppc_status & PPC_REGISTERED)) 340 if (!(acpi_processor_ppc_status & PPC_REGISTERED))
349 return_VALUE(-EBUSY); 341 return -EBUSY;
350 342
351 if (!try_module_get(calling_module)) 343 if (!try_module_get(calling_module))
352 return_VALUE(-EINVAL); 344 return -EINVAL;
353 345
354 /* is_done is set to negative if an error occured, 346 /* is_done is set to negative if an error occured,
355 * and to postitive if _no_ error occured, but SMM 347 * and to postitive if _no_ error occured, but SMM
@@ -358,10 +350,10 @@ int acpi_processor_notify_smm(struct module *calling_module)
358 */ 350 */
359 if (is_done > 0) { 351 if (is_done > 0) {
360 module_put(calling_module); 352 module_put(calling_module);
361 return_VALUE(0); 353 return 0;
362 } else if (is_done < 0) { 354 } else if (is_done < 0) {
363 module_put(calling_module); 355 module_put(calling_module);
364 return_VALUE(is_done); 356 return is_done;
365 } 357 }
366 358
367 is_done = -EIO; 359 is_done = -EIO;
@@ -370,7 +362,7 @@ int acpi_processor_notify_smm(struct module *calling_module)
370 if ((!acpi_fadt.smi_cmd) || (!acpi_fadt.pstate_cnt)) { 362 if ((!acpi_fadt.smi_cmd) || (!acpi_fadt.pstate_cnt)) {
371 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No SMI port or pstate_cnt\n")); 363 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No SMI port or pstate_cnt\n"));
372 module_put(calling_module); 364 module_put(calling_module);
373 return_VALUE(0); 365 return 0;
374 } 366 }
375 367
376 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 368 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
@@ -387,12 +379,12 @@ int acpi_processor_notify_smm(struct module *calling_module)
387 status = acpi_os_write_port(acpi_fadt.smi_cmd, 379 status = acpi_os_write_port(acpi_fadt.smi_cmd,
388 (u32) acpi_fadt.pstate_cnt, 8); 380 (u32) acpi_fadt.pstate_cnt, 8);
389 if (ACPI_FAILURE(status)) { 381 if (ACPI_FAILURE(status)) {
390 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 382 ACPI_EXCEPTION((AE_INFO, status,
391 "Failed to write pstate_cnt [0x%x] to " 383 "Failed to write pstate_cnt [0x%x] to "
392 "smi_cmd [0x%x]\n", acpi_fadt.pstate_cnt, 384 "smi_cmd [0x%x]", acpi_fadt.pstate_cnt,
393 acpi_fadt.smi_cmd)); 385 acpi_fadt.smi_cmd));
394 module_put(calling_module); 386 module_put(calling_module);
395 return_VALUE(status); 387 return status;
396 } 388 }
397 389
398 /* Success. If there's no _PPC, we need to fear nothing, so 390 /* Success. If there's no _PPC, we need to fear nothing, so
@@ -402,7 +394,7 @@ int acpi_processor_notify_smm(struct module *calling_module)
402 if (!(acpi_processor_ppc_status & PPC_IN_USE)) 394 if (!(acpi_processor_ppc_status & PPC_IN_USE))
403 module_put(calling_module); 395 module_put(calling_module);
404 396
405 return_VALUE(0); 397 return 0;
406} 398}
407 399
408EXPORT_SYMBOL(acpi_processor_notify_smm); 400EXPORT_SYMBOL(acpi_processor_notify_smm);
@@ -423,7 +415,6 @@ static int acpi_processor_perf_seq_show(struct seq_file *seq, void *offset)
423 struct acpi_processor *pr = (struct acpi_processor *)seq->private; 415 struct acpi_processor *pr = (struct acpi_processor *)seq->private;
424 int i; 416 int i;
425 417
426 ACPI_FUNCTION_TRACE("acpi_processor_perf_seq_show");
427 418
428 if (!pr) 419 if (!pr)
429 goto end; 420 goto end;
@@ -447,7 +438,7 @@ static int acpi_processor_perf_seq_show(struct seq_file *seq, void *offset)
447 (u32) pr->performance->states[i].transition_latency); 438 (u32) pr->performance->states[i].transition_latency);
448 439
449 end: 440 end:
450 return_VALUE(0); 441 return 0;
451} 442}
452 443
453static int acpi_processor_perf_open_fs(struct inode *inode, struct file *file) 444static int acpi_processor_perf_open_fs(struct inode *inode, struct file *file)
@@ -469,23 +460,22 @@ acpi_processor_write_performance(struct file *file,
469 unsigned int new_state = 0; 460 unsigned int new_state = 0;
470 struct cpufreq_policy policy; 461 struct cpufreq_policy policy;
471 462
472 ACPI_FUNCTION_TRACE("acpi_processor_write_performance");
473 463
474 if (!pr || (count > sizeof(state_string) - 1)) 464 if (!pr || (count > sizeof(state_string) - 1))
475 return_VALUE(-EINVAL); 465 return -EINVAL;
476 466
477 perf = pr->performance; 467 perf = pr->performance;
478 if (!perf) 468 if (!perf)
479 return_VALUE(-EINVAL); 469 return -EINVAL;
480 470
481 if (copy_from_user(state_string, buffer, count)) 471 if (copy_from_user(state_string, buffer, count))
482 return_VALUE(-EFAULT); 472 return -EFAULT;
483 473
484 state_string[count] = '\0'; 474 state_string[count] = '\0';
485 new_state = simple_strtoul(state_string, NULL, 0); 475 new_state = simple_strtoul(state_string, NULL, 0);
486 476
487 if (new_state >= perf->state_count) 477 if (new_state >= perf->state_count)
488 return_VALUE(-EINVAL); 478 return -EINVAL;
489 479
490 cpufreq_get_policy(&policy, pr->id); 480 cpufreq_get_policy(&policy, pr->id);
491 481
@@ -495,9 +485,9 @@ acpi_processor_write_performance(struct file *file,
495 485
496 result = cpufreq_set_policy(&policy); 486 result = cpufreq_set_policy(&policy);
497 if (result) 487 if (result)
498 return_VALUE(result); 488 return result;
499 489
500 return_VALUE(count); 490 return count;
501} 491}
502 492
503static void acpi_cpufreq_add_file(struct acpi_processor *pr) 493static void acpi_cpufreq_add_file(struct acpi_processor *pr)
@@ -505,42 +495,36 @@ static void acpi_cpufreq_add_file(struct acpi_processor *pr)
505 struct proc_dir_entry *entry = NULL; 495 struct proc_dir_entry *entry = NULL;
506 struct acpi_device *device = NULL; 496 struct acpi_device *device = NULL;
507 497
508 ACPI_FUNCTION_TRACE("acpi_cpufreq_addfile");
509 498
510 if (acpi_bus_get_device(pr->handle, &device)) 499 if (acpi_bus_get_device(pr->handle, &device))
511 return_VOID; 500 return;
512 501
513 /* add file 'performance' [R/W] */ 502 /* add file 'performance' [R/W] */
514 entry = create_proc_entry(ACPI_PROCESSOR_FILE_PERFORMANCE, 503 entry = create_proc_entry(ACPI_PROCESSOR_FILE_PERFORMANCE,
515 S_IFREG | S_IRUGO | S_IWUSR, 504 S_IFREG | S_IRUGO | S_IWUSR,
516 acpi_device_dir(device)); 505 acpi_device_dir(device));
517 if (!entry) 506 if (entry){
518 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
519 "Unable to create '%s' fs entry\n",
520 ACPI_PROCESSOR_FILE_PERFORMANCE));
521 else {
522 acpi_processor_perf_fops.write = acpi_processor_write_performance; 507 acpi_processor_perf_fops.write = acpi_processor_write_performance;
523 entry->proc_fops = &acpi_processor_perf_fops; 508 entry->proc_fops = &acpi_processor_perf_fops;
524 entry->data = acpi_driver_data(device); 509 entry->data = acpi_driver_data(device);
525 entry->owner = THIS_MODULE; 510 entry->owner = THIS_MODULE;
526 } 511 }
527 return_VOID; 512 return;
528} 513}
529 514
530static void acpi_cpufreq_remove_file(struct acpi_processor *pr) 515static void acpi_cpufreq_remove_file(struct acpi_processor *pr)
531{ 516{
532 struct acpi_device *device = NULL; 517 struct acpi_device *device = NULL;
533 518
534 ACPI_FUNCTION_TRACE("acpi_cpufreq_addfile");
535 519
536 if (acpi_bus_get_device(pr->handle, &device)) 520 if (acpi_bus_get_device(pr->handle, &device))
537 return_VOID; 521 return;
538 522
539 /* remove file 'performance' */ 523 /* remove file 'performance' */
540 remove_proc_entry(ACPI_PROCESSOR_FILE_PERFORMANCE, 524 remove_proc_entry(ACPI_PROCESSOR_FILE_PERFORMANCE,
541 acpi_device_dir(device)); 525 acpi_device_dir(device));
542 526
543 return_VOID; 527 return;
544} 528}
545 529
546#else 530#else
@@ -608,7 +592,7 @@ static int acpi_processor_get_psd(struct acpi_processor *pr)
608 } 592 }
609 593
610end: 594end:
611 acpi_os_free(buffer.pointer); 595 kfree(buffer.pointer);
612 return result; 596 return result;
613} 597}
614 598
@@ -698,12 +682,12 @@ int acpi_processor_preregister_performance(
698 /* Validate the Domain info */ 682 /* Validate the Domain info */
699 count_target = pdomain->num_processors; 683 count_target = pdomain->num_processors;
700 count = 1; 684 count = 1;
701 if (pdomain->coord_type == DOMAIN_COORD_TYPE_SW_ALL || 685 if (pdomain->coord_type == DOMAIN_COORD_TYPE_SW_ALL)
702 pdomain->coord_type == DOMAIN_COORD_TYPE_HW_ALL) {
703 pr->performance->shared_type = CPUFREQ_SHARED_TYPE_ALL; 686 pr->performance->shared_type = CPUFREQ_SHARED_TYPE_ALL;
704 } else if (pdomain->coord_type == DOMAIN_COORD_TYPE_SW_ANY) { 687 else if (pdomain->coord_type == DOMAIN_COORD_TYPE_HW_ALL)
688 pr->performance->shared_type = CPUFREQ_SHARED_TYPE_HW;
689 else if (pdomain->coord_type == DOMAIN_COORD_TYPE_SW_ANY)
705 pr->performance->shared_type = CPUFREQ_SHARED_TYPE_ANY; 690 pr->performance->shared_type = CPUFREQ_SHARED_TYPE_ANY;
706 }
707 691
708 for_each_possible_cpu(j) { 692 for_each_possible_cpu(j) {
709 if (i == j) 693 if (i == j)
@@ -784,22 +768,21 @@ acpi_processor_register_performance(struct acpi_processor_performance
784{ 768{
785 struct acpi_processor *pr; 769 struct acpi_processor *pr;
786 770
787 ACPI_FUNCTION_TRACE("acpi_processor_register_performance");
788 771
789 if (!(acpi_processor_ppc_status & PPC_REGISTERED)) 772 if (!(acpi_processor_ppc_status & PPC_REGISTERED))
790 return_VALUE(-EINVAL); 773 return -EINVAL;
791 774
792 mutex_lock(&performance_mutex); 775 mutex_lock(&performance_mutex);
793 776
794 pr = processors[cpu]; 777 pr = processors[cpu];
795 if (!pr) { 778 if (!pr) {
796 mutex_unlock(&performance_mutex); 779 mutex_unlock(&performance_mutex);
797 return_VALUE(-ENODEV); 780 return -ENODEV;
798 } 781 }
799 782
800 if (pr->performance) { 783 if (pr->performance) {
801 mutex_unlock(&performance_mutex); 784 mutex_unlock(&performance_mutex);
802 return_VALUE(-EBUSY); 785 return -EBUSY;
803 } 786 }
804 787
805 WARN_ON(!performance); 788 WARN_ON(!performance);
@@ -809,13 +792,13 @@ acpi_processor_register_performance(struct acpi_processor_performance
809 if (acpi_processor_get_performance_info(pr)) { 792 if (acpi_processor_get_performance_info(pr)) {
810 pr->performance = NULL; 793 pr->performance = NULL;
811 mutex_unlock(&performance_mutex); 794 mutex_unlock(&performance_mutex);
812 return_VALUE(-EIO); 795 return -EIO;
813 } 796 }
814 797
815 acpi_cpufreq_add_file(pr); 798 acpi_cpufreq_add_file(pr);
816 799
817 mutex_unlock(&performance_mutex); 800 mutex_unlock(&performance_mutex);
818 return_VALUE(0); 801 return 0;
819} 802}
820 803
821EXPORT_SYMBOL(acpi_processor_register_performance); 804EXPORT_SYMBOL(acpi_processor_register_performance);
@@ -826,14 +809,13 @@ acpi_processor_unregister_performance(struct acpi_processor_performance
826{ 809{
827 struct acpi_processor *pr; 810 struct acpi_processor *pr;
828 811
829 ACPI_FUNCTION_TRACE("acpi_processor_unregister_performance");
830 812
831 mutex_lock(&performance_mutex); 813 mutex_lock(&performance_mutex);
832 814
833 pr = processors[cpu]; 815 pr = processors[cpu];
834 if (!pr) { 816 if (!pr) {
835 mutex_unlock(&performance_mutex); 817 mutex_unlock(&performance_mutex);
836 return_VOID; 818 return;
837 } 819 }
838 820
839 if (pr->performance) 821 if (pr->performance)
@@ -844,7 +826,7 @@ acpi_processor_unregister_performance(struct acpi_processor_performance
844 826
845 mutex_unlock(&performance_mutex); 827 mutex_unlock(&performance_mutex);
846 828
847 return_VOID; 829 return;
848} 830}
849 831
850EXPORT_SYMBOL(acpi_processor_unregister_performance); 832EXPORT_SYMBOL(acpi_processor_unregister_performance);
diff --git a/drivers/acpi/processor_thermal.c b/drivers/acpi/processor_thermal.c
index f99ad05cd6a2..ef5e0f6efdba 100644
--- a/drivers/acpi/processor_thermal.c
+++ b/drivers/acpi/processor_thermal.c
@@ -54,13 +54,12 @@ static int acpi_processor_apply_limit(struct acpi_processor *pr)
54 u16 px = 0; 54 u16 px = 0;
55 u16 tx = 0; 55 u16 tx = 0;
56 56
57 ACPI_FUNCTION_TRACE("acpi_processor_apply_limit");
58 57
59 if (!pr) 58 if (!pr)
60 return_VALUE(-EINVAL); 59 return -EINVAL;
61 60
62 if (!pr->flags.limit) 61 if (!pr->flags.limit)
63 return_VALUE(-ENODEV); 62 return -ENODEV;
64 63
65 if (pr->flags.throttling) { 64 if (pr->flags.throttling) {
66 if (pr->limit.user.tx > tx) 65 if (pr->limit.user.tx > tx)
@@ -82,9 +81,9 @@ static int acpi_processor_apply_limit(struct acpi_processor *pr)
82 81
83 end: 82 end:
84 if (result) 83 if (result)
85 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Unable to set limit\n")); 84 printk(KERN_ERR PREFIX "Unable to set limit\n");
86 85
87 return_VALUE(result); 86 return result;
88} 87}
89 88
90#ifdef CONFIG_CPU_FREQ 89#ifdef CONFIG_CPU_FREQ
@@ -200,19 +199,18 @@ int acpi_processor_set_thermal_limit(acpi_handle handle, int type)
200 struct acpi_device *device = NULL; 199 struct acpi_device *device = NULL;
201 int tx = 0, max_tx_px = 0; 200 int tx = 0, max_tx_px = 0;
202 201
203 ACPI_FUNCTION_TRACE("acpi_processor_set_thermal_limit");
204 202
205 if ((type < ACPI_PROCESSOR_LIMIT_NONE) 203 if ((type < ACPI_PROCESSOR_LIMIT_NONE)
206 || (type > ACPI_PROCESSOR_LIMIT_DECREMENT)) 204 || (type > ACPI_PROCESSOR_LIMIT_DECREMENT))
207 return_VALUE(-EINVAL); 205 return -EINVAL;
208 206
209 result = acpi_bus_get_device(handle, &device); 207 result = acpi_bus_get_device(handle, &device);
210 if (result) 208 if (result)
211 return_VALUE(result); 209 return result;
212 210
213 pr = (struct acpi_processor *)acpi_driver_data(device); 211 pr = (struct acpi_processor *)acpi_driver_data(device);
214 if (!pr) 212 if (!pr)
215 return_VALUE(-ENODEV); 213 return -ENODEV;
216 214
217 /* Thermal limits are always relative to the current Px/Tx state. */ 215 /* Thermal limits are always relative to the current Px/Tx state. */
218 if (pr->flags.throttling) 216 if (pr->flags.throttling)
@@ -289,30 +287,28 @@ int acpi_processor_set_thermal_limit(acpi_handle handle, int type)
289 287
290 result = acpi_processor_apply_limit(pr); 288 result = acpi_processor_apply_limit(pr);
291 if (result) 289 if (result)
292 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 290 printk(KERN_ERR PREFIX "Unable to set thermal limit\n");
293 "Unable to set thermal limit\n"));
294 291
295 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Thermal limit now (P%d:T%d)\n", 292 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Thermal limit now (P%d:T%d)\n",
296 pr->limit.thermal.px, pr->limit.thermal.tx)); 293 pr->limit.thermal.px, pr->limit.thermal.tx));
297 } else 294 } else
298 result = 0; 295 result = 0;
299 if (max_tx_px) 296 if (max_tx_px)
300 return_VALUE(1); 297 return 1;
301 else 298 else
302 return_VALUE(result); 299 return result;
303} 300}
304 301
305int acpi_processor_get_limit_info(struct acpi_processor *pr) 302int acpi_processor_get_limit_info(struct acpi_processor *pr)
306{ 303{
307 ACPI_FUNCTION_TRACE("acpi_processor_get_limit_info");
308 304
309 if (!pr) 305 if (!pr)
310 return_VALUE(-EINVAL); 306 return -EINVAL;
311 307
312 if (pr->flags.throttling) 308 if (pr->flags.throttling)
313 pr->flags.limit = 1; 309 pr->flags.limit = 1;
314 310
315 return_VALUE(0); 311 return 0;
316} 312}
317 313
318/* /proc interface */ 314/* /proc interface */
@@ -321,7 +317,6 @@ static int acpi_processor_limit_seq_show(struct seq_file *seq, void *offset)
321{ 317{
322 struct acpi_processor *pr = (struct acpi_processor *)seq->private; 318 struct acpi_processor *pr = (struct acpi_processor *)seq->private;
323 319
324 ACPI_FUNCTION_TRACE("acpi_processor_limit_seq_show");
325 320
326 if (!pr) 321 if (!pr)
327 goto end; 322 goto end;
@@ -339,7 +334,7 @@ static int acpi_processor_limit_seq_show(struct seq_file *seq, void *offset)
339 pr->limit.thermal.px, pr->limit.thermal.tx); 334 pr->limit.thermal.px, pr->limit.thermal.tx);
340 335
341 end: 336 end:
342 return_VALUE(0); 337 return 0;
343} 338}
344 339
345static int acpi_processor_limit_open_fs(struct inode *inode, struct file *file) 340static int acpi_processor_limit_open_fs(struct inode *inode, struct file *file)
@@ -359,36 +354,33 @@ static ssize_t acpi_processor_write_limit(struct file * file,
359 int px = 0; 354 int px = 0;
360 int tx = 0; 355 int tx = 0;
361 356
362 ACPI_FUNCTION_TRACE("acpi_processor_write_limit");
363 357
364 if (!pr || (count > sizeof(limit_string) - 1)) { 358 if (!pr || (count > sizeof(limit_string) - 1)) {
365 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid argument\n")); 359 return -EINVAL;
366 return_VALUE(-EINVAL);
367 } 360 }
368 361
369 if (copy_from_user(limit_string, buffer, count)) { 362 if (copy_from_user(limit_string, buffer, count)) {
370 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid data\n")); 363 return -EFAULT;
371 return_VALUE(-EFAULT);
372 } 364 }
373 365
374 limit_string[count] = '\0'; 366 limit_string[count] = '\0';
375 367
376 if (sscanf(limit_string, "%d:%d", &px, &tx) != 2) { 368 if (sscanf(limit_string, "%d:%d", &px, &tx) != 2) {
377 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid data format\n")); 369 printk(KERN_ERR PREFIX "Invalid data format\n");
378 return_VALUE(-EINVAL); 370 return -EINVAL;
379 } 371 }
380 372
381 if (pr->flags.throttling) { 373 if (pr->flags.throttling) {
382 if ((tx < 0) || (tx > (pr->throttling.state_count - 1))) { 374 if ((tx < 0) || (tx > (pr->throttling.state_count - 1))) {
383 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid tx\n")); 375 printk(KERN_ERR PREFIX "Invalid tx\n");
384 return_VALUE(-EINVAL); 376 return -EINVAL;
385 } 377 }
386 pr->limit.user.tx = tx; 378 pr->limit.user.tx = tx;
387 } 379 }
388 380
389 result = acpi_processor_apply_limit(pr); 381 result = acpi_processor_apply_limit(pr);
390 382
391 return_VALUE(count); 383 return count;
392} 384}
393 385
394struct file_operations acpi_processor_limit_fops = { 386struct file_operations acpi_processor_limit_fops = {
diff --git a/drivers/acpi/processor_throttling.c b/drivers/acpi/processor_throttling.c
index b966549ec000..d044ec519db0 100644
--- a/drivers/acpi/processor_throttling.c
+++ b/drivers/acpi/processor_throttling.c
@@ -55,13 +55,12 @@ static int acpi_processor_get_throttling(struct acpi_processor *pr)
55 u32 duty_mask = 0; 55 u32 duty_mask = 0;
56 u32 duty_value = 0; 56 u32 duty_value = 0;
57 57
58 ACPI_FUNCTION_TRACE("acpi_processor_get_throttling");
59 58
60 if (!pr) 59 if (!pr)
61 return_VALUE(-EINVAL); 60 return -EINVAL;
62 61
63 if (!pr->flags.throttling) 62 if (!pr->flags.throttling)
64 return_VALUE(-ENODEV); 63 return -ENODEV;
65 64
66 pr->throttling.state = 0; 65 pr->throttling.state = 0;
67 66
@@ -93,7 +92,7 @@ static int acpi_processor_get_throttling(struct acpi_processor *pr)
93 "Throttling state is T%d (%d%% throttling applied)\n", 92 "Throttling state is T%d (%d%% throttling applied)\n",
94 state, pr->throttling.states[state].performance)); 93 state, pr->throttling.states[state].performance));
95 94
96 return_VALUE(0); 95 return 0;
97} 96}
98 97
99int acpi_processor_set_throttling(struct acpi_processor *pr, int state) 98int acpi_processor_set_throttling(struct acpi_processor *pr, int state)
@@ -102,19 +101,18 @@ int acpi_processor_set_throttling(struct acpi_processor *pr, int state)
102 u32 duty_mask = 0; 101 u32 duty_mask = 0;
103 u32 duty_value = 0; 102 u32 duty_value = 0;
104 103
105 ACPI_FUNCTION_TRACE("acpi_processor_set_throttling");
106 104
107 if (!pr) 105 if (!pr)
108 return_VALUE(-EINVAL); 106 return -EINVAL;
109 107
110 if ((state < 0) || (state > (pr->throttling.state_count - 1))) 108 if ((state < 0) || (state > (pr->throttling.state_count - 1)))
111 return_VALUE(-EINVAL); 109 return -EINVAL;
112 110
113 if (!pr->flags.throttling) 111 if (!pr->flags.throttling)
114 return_VALUE(-ENODEV); 112 return -ENODEV;
115 113
116 if (state == pr->throttling.state) 114 if (state == pr->throttling.state)
117 return_VALUE(0); 115 return 0;
118 116
119 /* 117 /*
120 * Calculate the duty_value and duty_mask. 118 * Calculate the duty_value and duty_mask.
@@ -165,7 +163,7 @@ int acpi_processor_set_throttling(struct acpi_processor *pr, int state)
165 (pr->throttling.states[state].performance ? pr-> 163 (pr->throttling.states[state].performance ? pr->
166 throttling.states[state].performance / 10 : 0))); 164 throttling.states[state].performance / 10 : 0)));
167 165
168 return_VALUE(0); 166 return 0;
169} 167}
170 168
171int acpi_processor_get_throttling_info(struct acpi_processor *pr) 169int acpi_processor_get_throttling_info(struct acpi_processor *pr)
@@ -174,7 +172,6 @@ int acpi_processor_get_throttling_info(struct acpi_processor *pr)
174 int step = 0; 172 int step = 0;
175 int i = 0; 173 int i = 0;
176 174
177 ACPI_FUNCTION_TRACE("acpi_processor_get_throttling_info");
178 175
179 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 176 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
180 "pblk_address[0x%08x] duty_offset[%d] duty_width[%d]\n", 177 "pblk_address[0x%08x] duty_offset[%d] duty_width[%d]\n",
@@ -183,21 +180,21 @@ int acpi_processor_get_throttling_info(struct acpi_processor *pr)
183 pr->throttling.duty_width)); 180 pr->throttling.duty_width));
184 181
185 if (!pr) 182 if (!pr)
186 return_VALUE(-EINVAL); 183 return -EINVAL;
187 184
188 /* TBD: Support ACPI 2.0 objects */ 185 /* TBD: Support ACPI 2.0 objects */
189 186
190 if (!pr->throttling.address) { 187 if (!pr->throttling.address) {
191 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No throttling register\n")); 188 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No throttling register\n"));
192 return_VALUE(0); 189 return 0;
193 } else if (!pr->throttling.duty_width) { 190 } else if (!pr->throttling.duty_width) {
194 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No throttling states\n")); 191 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No throttling states\n"));
195 return_VALUE(0); 192 return 0;
196 } 193 }
197 /* TBD: Support duty_cycle values that span bit 4. */ 194 /* TBD: Support duty_cycle values that span bit 4. */
198 else if ((pr->throttling.duty_offset + pr->throttling.duty_width) > 4) { 195 else if ((pr->throttling.duty_offset + pr->throttling.duty_width) > 4) {
199 ACPI_DEBUG_PRINT((ACPI_DB_WARN, "duty_cycle spans bit 4\n")); 196 printk(KERN_WARNING PREFIX "duty_cycle spans bit 4\n");
200 return_VALUE(0); 197 return 0;
201 } 198 }
202 199
203 /* 200 /*
@@ -208,7 +205,7 @@ int acpi_processor_get_throttling_info(struct acpi_processor *pr)
208 if (errata.piix4.throttle) { 205 if (errata.piix4.throttle) {
209 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 206 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
210 "Throttling not supported on PIIX4 A- or B-step\n")); 207 "Throttling not supported on PIIX4 A- or B-step\n"));
211 return_VALUE(0); 208 return 0;
212 } 209 }
213 210
214 pr->throttling.state_count = 1 << acpi_fadt.duty_width; 211 pr->throttling.state_count = 1 << acpi_fadt.duty_width;
@@ -254,7 +251,7 @@ int acpi_processor_get_throttling_info(struct acpi_processor *pr)
254 if (result) 251 if (result)
255 pr->flags.throttling = 0; 252 pr->flags.throttling = 0;
256 253
257 return_VALUE(result); 254 return result;
258} 255}
259 256
260/* proc interface */ 257/* proc interface */
@@ -266,7 +263,6 @@ static int acpi_processor_throttling_seq_show(struct seq_file *seq,
266 int i = 0; 263 int i = 0;
267 int result = 0; 264 int result = 0;
268 265
269 ACPI_FUNCTION_TRACE("acpi_processor_throttling_seq_show");
270 266
271 if (!pr) 267 if (!pr)
272 goto end; 268 goto end;
@@ -296,7 +292,7 @@ static int acpi_processor_throttling_seq_show(struct seq_file *seq,
296 throttling.states[i].performance / 10 : 0)); 292 throttling.states[i].performance / 10 : 0));
297 293
298 end: 294 end:
299 return_VALUE(0); 295 return 0;
300} 296}
301 297
302static int acpi_processor_throttling_open_fs(struct inode *inode, 298static int acpi_processor_throttling_open_fs(struct inode *inode,
@@ -315,13 +311,12 @@ static ssize_t acpi_processor_write_throttling(struct file * file,
315 struct acpi_processor *pr = (struct acpi_processor *)m->private; 311 struct acpi_processor *pr = (struct acpi_processor *)m->private;
316 char state_string[12] = { '\0' }; 312 char state_string[12] = { '\0' };
317 313
318 ACPI_FUNCTION_TRACE("acpi_processor_write_throttling");
319 314
320 if (!pr || (count > sizeof(state_string) - 1)) 315 if (!pr || (count > sizeof(state_string) - 1))
321 return_VALUE(-EINVAL); 316 return -EINVAL;
322 317
323 if (copy_from_user(state_string, buffer, count)) 318 if (copy_from_user(state_string, buffer, count))
324 return_VALUE(-EFAULT); 319 return -EFAULT;
325 320
326 state_string[count] = '\0'; 321 state_string[count] = '\0';
327 322
@@ -329,9 +324,9 @@ static ssize_t acpi_processor_write_throttling(struct file * file,
329 simple_strtoul(state_string, 324 simple_strtoul(state_string,
330 NULL, 0)); 325 NULL, 0));
331 if (result) 326 if (result)
332 return_VALUE(result); 327 return result;
333 328
334 return_VALUE(count); 329 return count;
335} 330}
336 331
337struct file_operations acpi_processor_throttling_fops = { 332struct file_operations acpi_processor_throttling_fops = {
diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c
new file mode 100644
index 000000000000..62bef0b3b614
--- /dev/null
+++ b/drivers/acpi/sbs.c
@@ -0,0 +1,1769 @@
1/*
2 * acpi_sbs.c - ACPI Smart Battery System Driver ($Revision: 1.16 $)
3 *
4 * Copyright (c) 2005 Rich Townsend <rhdt@bartol.udel.edu>
5 *
6 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or (at
11 * your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 *
22 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
23 */
24
25#include <linux/init.h>
26#include <linux/module.h>
27#include <linux/moduleparam.h>
28#include <linux/kernel.h>
29#include <linux/proc_fs.h>
30#include <linux/seq_file.h>
31#include <asm/uaccess.h>
32#include <linux/acpi.h>
33#include <linux/i2c.h>
34#include <linux/delay.h>
35
36#include "i2c_ec.h"
37
38#define DEF_CAPACITY_UNIT 3
39#define MAH_CAPACITY_UNIT 1
40#define MWH_CAPACITY_UNIT 2
41#define CAPACITY_UNIT DEF_CAPACITY_UNIT
42
43#define REQUEST_UPDATE_MODE 1
44#define QUEUE_UPDATE_MODE 2
45
46#define DATA_TYPE_COMMON 0
47#define DATA_TYPE_INFO 1
48#define DATA_TYPE_STATE 2
49#define DATA_TYPE_ALARM 3
50#define DATA_TYPE_AC_STATE 4
51
52extern struct proc_dir_entry *acpi_lock_ac_dir(void);
53extern struct proc_dir_entry *acpi_lock_battery_dir(void);
54extern void acpi_unlock_ac_dir(struct proc_dir_entry *acpi_ac_dir);
55extern void acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir);
56
57#define ACPI_SBS_COMPONENT 0x00080000
58#define ACPI_SBS_CLASS "sbs"
59#define ACPI_AC_CLASS "ac_adapter"
60#define ACPI_BATTERY_CLASS "battery"
61#define ACPI_SBS_HID "ACPI0002"
62#define ACPI_SBS_DRIVER_NAME "ACPI Smart Battery System Driver"
63#define ACPI_SBS_DEVICE_NAME "Smart Battery System"
64#define ACPI_SBS_FILE_INFO "info"
65#define ACPI_SBS_FILE_STATE "state"
66#define ACPI_SBS_FILE_ALARM "alarm"
67#define ACPI_BATTERY_DIR_NAME "BAT%i"
68#define ACPI_AC_DIR_NAME "AC0"
69#define ACPI_SBC_SMBUS_ADDR 0x9
70#define ACPI_SBSM_SMBUS_ADDR 0xa
71#define ACPI_SB_SMBUS_ADDR 0xb
72#define ACPI_SBS_AC_NOTIFY_STATUS 0x80
73#define ACPI_SBS_BATTERY_NOTIFY_STATUS 0x80
74#define ACPI_SBS_BATTERY_NOTIFY_INFO 0x81
75
76#define _COMPONENT ACPI_SBS_COMPONENT
77
78#define MAX_SBS_BAT 4
79#define MAX_SMBUS_ERR 1
80
81ACPI_MODULE_NAME("acpi_sbs");
82
83MODULE_AUTHOR("Rich Townsend");
84MODULE_DESCRIPTION("Smart Battery System ACPI interface driver");
85MODULE_LICENSE("GPL");
86
87static struct semaphore sbs_sem;
88
89#define UPDATE_MODE QUEUE_UPDATE_MODE
90/* REQUEST_UPDATE_MODE QUEUE_UPDATE_MODE */
91#define UPDATE_INFO_MODE 0
92#define UPDATE_TIME 60
93#define UPDATE_TIME2 0
94
95static int capacity_mode = CAPACITY_UNIT;
96static int update_mode = UPDATE_MODE;
97static int update_info_mode = UPDATE_INFO_MODE;
98static int update_time = UPDATE_TIME;
99static int update_time2 = UPDATE_TIME2;
100
101module_param(capacity_mode, int, CAPACITY_UNIT);
102module_param(update_mode, int, UPDATE_MODE);
103module_param(update_info_mode, int, UPDATE_INFO_MODE);
104module_param(update_time, int, UPDATE_TIME);
105module_param(update_time2, int, UPDATE_TIME2);
106
107static int acpi_sbs_add(struct acpi_device *device);
108static int acpi_sbs_remove(struct acpi_device *device, int type);
109static void acpi_battery_smbus_err_handler(struct acpi_ec_smbus *smbus);
110static void acpi_sbs_update_queue(void *data);
111
112static struct acpi_driver acpi_sbs_driver = {
113 .name = ACPI_SBS_DRIVER_NAME,
114 .class = ACPI_SBS_CLASS,
115 .ids = ACPI_SBS_HID,
116 .ops = {
117 .add = acpi_sbs_add,
118 .remove = acpi_sbs_remove,
119 },
120};
121
122struct acpi_battery_info {
123 int capacity_mode;
124 s16 full_charge_capacity;
125 s16 design_capacity;
126 s16 design_voltage;
127 int vscale;
128 int ipscale;
129 s16 serial_number;
130 char manufacturer_name[I2C_SMBUS_BLOCK_MAX + 3];
131 char device_name[I2C_SMBUS_BLOCK_MAX + 3];
132 char device_chemistry[I2C_SMBUS_BLOCK_MAX + 3];
133};
134
135struct acpi_battery_state {
136 s16 voltage;
137 s16 amperage;
138 s16 remaining_capacity;
139 s16 average_time_to_empty;
140 s16 average_time_to_full;
141 s16 battery_status;
142};
143
144struct acpi_battery_alarm {
145 s16 remaining_capacity;
146};
147
148struct acpi_battery {
149 int alive;
150 int battery_present;
151 int id;
152 int init_state;
153 struct acpi_sbs *sbs;
154 struct acpi_battery_info info;
155 struct acpi_battery_state state;
156 struct acpi_battery_alarm alarm;
157 struct proc_dir_entry *battery_entry;
158};
159
160struct acpi_sbs {
161 acpi_handle handle;
162 struct acpi_device *device;
163 struct acpi_ec_smbus *smbus;
164 int sbsm_present;
165 int sbsm_batteries_supported;
166 int ac_present;
167 struct proc_dir_entry *ac_entry;
168 struct acpi_battery battery[MAX_SBS_BAT];
169 int update_info_mode;
170 int zombie;
171 int update_time;
172 int update_time2;
173 struct timer_list update_timer;
174};
175
176static void acpi_update_delay(struct acpi_sbs *sbs);
177static int acpi_sbs_update_run(struct acpi_sbs *sbs, int data_type);
178
179/* --------------------------------------------------------------------------
180 SMBus Communication
181 -------------------------------------------------------------------------- */
182
183static void acpi_battery_smbus_err_handler(struct acpi_ec_smbus *smbus)
184{
185 union i2c_smbus_data data;
186 int result = 0;
187 char *err_str;
188 int err_number;
189
190 data.word = 0;
191
192 result = smbus->adapter.algo->
193 smbus_xfer(&smbus->adapter,
194 ACPI_SB_SMBUS_ADDR,
195 0, I2C_SMBUS_READ, 0x16, I2C_SMBUS_BLOCK_DATA, &data);
196
197 err_number = (data.word & 0x000f);
198
199 switch (data.word & 0x000f) {
200 case 0x0000:
201 err_str = "unexpected bus error";
202 break;
203 case 0x0001:
204 err_str = "busy";
205 break;
206 case 0x0002:
207 err_str = "reserved command";
208 break;
209 case 0x0003:
210 err_str = "unsupported command";
211 break;
212 case 0x0004:
213 err_str = "access denied";
214 break;
215 case 0x0005:
216 err_str = "overflow/underflow";
217 break;
218 case 0x0006:
219 err_str = "bad size";
220 break;
221 case 0x0007:
222 err_str = "unknown error";
223 break;
224 default:
225 err_str = "unrecognized error";
226 }
227 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
228 "%s: ret %i, err %i\n", err_str, result, err_number));
229}
230
231static int
232acpi_sbs_smbus_read_word(struct acpi_ec_smbus *smbus, int addr, int func,
233 u16 * word,
234 void (*err_handler) (struct acpi_ec_smbus * smbus))
235{
236 union i2c_smbus_data data;
237 int result = 0;
238 int i;
239
240 if (err_handler == NULL) {
241 err_handler = acpi_battery_smbus_err_handler;
242 }
243
244 for (i = 0; i < MAX_SMBUS_ERR; i++) {
245 result =
246 smbus->adapter.algo->smbus_xfer(&smbus->adapter, addr, 0,
247 I2C_SMBUS_READ, func,
248 I2C_SMBUS_WORD_DATA, &data);
249 if (result) {
250 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
251 "try %i: smbus->adapter.algo->smbus_xfer() failed\n",
252 i));
253 if (err_handler) {
254 err_handler(smbus);
255 }
256 } else {
257 *word = data.word;
258 break;
259 }
260 }
261
262 return result;
263}
264
265static int
266acpi_sbs_smbus_read_str(struct acpi_ec_smbus *smbus, int addr, int func,
267 char *str,
268 void (*err_handler) (struct acpi_ec_smbus * smbus))
269{
270 union i2c_smbus_data data;
271 int result = 0;
272 int i;
273
274 if (err_handler == NULL) {
275 err_handler = acpi_battery_smbus_err_handler;
276 }
277
278 for (i = 0; i < MAX_SMBUS_ERR; i++) {
279 result =
280 smbus->adapter.algo->smbus_xfer(&smbus->adapter, addr, 0,
281 I2C_SMBUS_READ, func,
282 I2C_SMBUS_BLOCK_DATA,
283 &data);
284 if (result) {
285 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
286 "try %i: smbus->adapter.algo->smbus_xfer() failed\n",
287 i));
288 if (err_handler) {
289 err_handler(smbus);
290 }
291 } else {
292 strncpy(str, (const char *)data.block + 1,
293 data.block[0]);
294 str[data.block[0]] = 0;
295 break;
296 }
297 }
298
299 return result;
300}
301
302static int
303acpi_sbs_smbus_write_word(struct acpi_ec_smbus *smbus, int addr, int func,
304 int word,
305 void (*err_handler) (struct acpi_ec_smbus * smbus))
306{
307 union i2c_smbus_data data;
308 int result = 0;
309 int i;
310
311 if (err_handler == NULL) {
312 err_handler = acpi_battery_smbus_err_handler;
313 }
314
315 data.word = word;
316
317 for (i = 0; i < MAX_SMBUS_ERR; i++) {
318 result =
319 smbus->adapter.algo->smbus_xfer(&smbus->adapter, addr, 0,
320 I2C_SMBUS_WRITE, func,
321 I2C_SMBUS_WORD_DATA, &data);
322 if (result) {
323 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
324 "try %i: smbus->adapter.algo"
325 "->smbus_xfer() failed\n", i));
326 if (err_handler) {
327 err_handler(smbus);
328 }
329 } else {
330 break;
331 }
332 }
333
334 return result;
335}
336
337/* --------------------------------------------------------------------------
338 Smart Battery System Management
339 -------------------------------------------------------------------------- */
340
341/* Smart Battery */
342
343static int acpi_sbs_generate_event(struct acpi_device *device,
344 int event, int state, char *bid, char *class)
345{
346 char bid_saved[5];
347 char class_saved[20];
348 int result = 0;
349
350 strcpy(bid_saved, acpi_device_bid(device));
351 strcpy(class_saved, acpi_device_class(device));
352
353 strcpy(acpi_device_bid(device), bid);
354 strcpy(acpi_device_class(device), class);
355
356 result = acpi_bus_generate_event(device, event, state);
357
358 strcpy(acpi_device_bid(device), bid_saved);
359 strcpy(acpi_device_class(device), class_saved);
360
361 return result;
362}
363
364static int acpi_battery_get_present(struct acpi_battery *battery)
365{
366 s16 state;
367 int result = 0;
368 int is_present = 0;
369
370 result = acpi_sbs_smbus_read_word(battery->sbs->smbus,
371 ACPI_SBSM_SMBUS_ADDR, 0x01,
372 &state, NULL);
373 if (result) {
374 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
375 "acpi_sbs_smbus_read_word() failed"));
376 }
377 if (!result) {
378 is_present = (state & 0x000f) & (1 << battery->id);
379 }
380 battery->battery_present = is_present;
381
382 return result;
383}
384
385static int acpi_battery_is_present(struct acpi_battery *battery)
386{
387 return (battery->battery_present);
388}
389
390static int acpi_ac_is_present(struct acpi_sbs *sbs)
391{
392 return (sbs->ac_present);
393}
394
395static int acpi_battery_select(struct acpi_battery *battery)
396{
397 struct acpi_ec_smbus *smbus = battery->sbs->smbus;
398 int result = 0;
399 s16 state;
400 int foo;
401
402 if (battery->sbs->sbsm_present) {
403
404 /* Take special care not to knobble other nibbles of
405 * state (aka selector_state), since
406 * it causes charging to halt on SBSELs */
407
408 result =
409 acpi_sbs_smbus_read_word(smbus, ACPI_SBSM_SMBUS_ADDR, 0x01,
410 &state, NULL);
411 if (result) {
412 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
413 "acpi_sbs_smbus_read_word() failed\n"));
414 goto end;
415 }
416
417 foo = (state & 0x0fff) | (1 << (battery->id + 12));
418 result =
419 acpi_sbs_smbus_write_word(smbus, ACPI_SBSM_SMBUS_ADDR, 0x01,
420 foo, NULL);
421 if (result) {
422 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
423 "acpi_sbs_smbus_write_word() failed\n"));
424 goto end;
425 }
426 }
427
428 end:
429 return result;
430}
431
432static int acpi_sbsm_get_info(struct acpi_sbs *sbs)
433{
434 struct acpi_ec_smbus *smbus = sbs->smbus;
435 int result = 0;
436 s16 battery_system_info;
437
438 result = acpi_sbs_smbus_read_word(smbus, ACPI_SBSM_SMBUS_ADDR, 0x04,
439 &battery_system_info, NULL);
440 if (result) {
441 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
442 "acpi_sbs_smbus_read_word() failed\n"));
443 goto end;
444 }
445
446 sbs->sbsm_batteries_supported = battery_system_info & 0x000f;
447
448 end:
449
450 return result;
451}
452
453static int acpi_battery_get_info(struct acpi_battery *battery)
454{
455 struct acpi_ec_smbus *smbus = battery->sbs->smbus;
456 int result = 0;
457 s16 battery_mode;
458 s16 specification_info;
459
460 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x03,
461 &battery_mode,
462 &acpi_battery_smbus_err_handler);
463 if (result) {
464 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
465 "acpi_sbs_smbus_read_word() failed\n"));
466 goto end;
467 }
468 battery->info.capacity_mode = (battery_mode & 0x8000) >> 15;
469
470 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x10,
471 &battery->info.full_charge_capacity,
472 &acpi_battery_smbus_err_handler);
473 if (result) {
474 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
475 "acpi_sbs_smbus_read_word() failed\n"));
476 goto end;
477 }
478
479 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x18,
480 &battery->info.design_capacity,
481 &acpi_battery_smbus_err_handler);
482
483 if (result) {
484 goto end;
485 }
486
487 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x19,
488 &battery->info.design_voltage,
489 &acpi_battery_smbus_err_handler);
490 if (result) {
491 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
492 "acpi_sbs_smbus_read_word() failed\n"));
493 goto end;
494 }
495
496 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x1a,
497 &specification_info,
498 &acpi_battery_smbus_err_handler);
499 if (result) {
500 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
501 "acpi_sbs_smbus_read_word() failed\n"));
502 goto end;
503 }
504
505 switch ((specification_info & 0x0f00) >> 8) {
506 case 1:
507 battery->info.vscale = 10;
508 break;
509 case 2:
510 battery->info.vscale = 100;
511 break;
512 case 3:
513 battery->info.vscale = 1000;
514 break;
515 default:
516 battery->info.vscale = 1;
517 }
518
519 switch ((specification_info & 0xf000) >> 12) {
520 case 1:
521 battery->info.ipscale = 10;
522 break;
523 case 2:
524 battery->info.ipscale = 100;
525 break;
526 case 3:
527 battery->info.ipscale = 1000;
528 break;
529 default:
530 battery->info.ipscale = 1;
531 }
532
533 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x1c,
534 &battery->info.serial_number,
535 &acpi_battery_smbus_err_handler);
536 if (result) {
537 goto end;
538 }
539
540 result = acpi_sbs_smbus_read_str(smbus, ACPI_SB_SMBUS_ADDR, 0x20,
541 battery->info.manufacturer_name,
542 &acpi_battery_smbus_err_handler);
543 if (result) {
544 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
545 "acpi_sbs_smbus_read_str() failed\n"));
546 goto end;
547 }
548
549 result = acpi_sbs_smbus_read_str(smbus, ACPI_SB_SMBUS_ADDR, 0x21,
550 battery->info.device_name,
551 &acpi_battery_smbus_err_handler);
552 if (result) {
553 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
554 "acpi_sbs_smbus_read_str() failed\n"));
555 goto end;
556 }
557
558 result = acpi_sbs_smbus_read_str(smbus, ACPI_SB_SMBUS_ADDR, 0x22,
559 battery->info.device_chemistry,
560 &acpi_battery_smbus_err_handler);
561 if (result) {
562 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
563 "acpi_sbs_smbus_read_str() failed\n"));
564 goto end;
565 }
566
567 end:
568 return result;
569}
570
571static void acpi_update_delay(struct acpi_sbs *sbs)
572{
573 if (sbs->zombie) {
574 return;
575 }
576 if (sbs->update_time2 > 0) {
577 msleep(sbs->update_time2 * 1000);
578 }
579}
580
581static int acpi_battery_get_state(struct acpi_battery *battery)
582{
583 struct acpi_ec_smbus *smbus = battery->sbs->smbus;
584 int result = 0;
585
586 acpi_update_delay(battery->sbs);
587 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x09,
588 &battery->state.voltage,
589 &acpi_battery_smbus_err_handler);
590 if (result) {
591 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
592 "acpi_sbs_smbus_read_word() failed\n"));
593 goto end;
594 }
595
596 acpi_update_delay(battery->sbs);
597 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x0a,
598 &battery->state.amperage,
599 &acpi_battery_smbus_err_handler);
600 if (result) {
601 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
602 "acpi_sbs_smbus_read_word() failed\n"));
603 goto end;
604 }
605
606 acpi_update_delay(battery->sbs);
607 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x0f,
608 &battery->state.remaining_capacity,
609 &acpi_battery_smbus_err_handler);
610 if (result) {
611 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
612 "acpi_sbs_smbus_read_word() failed\n"));
613 goto end;
614 }
615
616 acpi_update_delay(battery->sbs);
617 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x12,
618 &battery->state.average_time_to_empty,
619 &acpi_battery_smbus_err_handler);
620 if (result) {
621 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
622 "acpi_sbs_smbus_read_word() failed\n"));
623 goto end;
624 }
625
626 acpi_update_delay(battery->sbs);
627 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x13,
628 &battery->state.average_time_to_full,
629 &acpi_battery_smbus_err_handler);
630 if (result) {
631 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
632 "acpi_sbs_smbus_read_word() failed\n"));
633 goto end;
634 }
635
636 acpi_update_delay(battery->sbs);
637 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x16,
638 &battery->state.battery_status,
639 &acpi_battery_smbus_err_handler);
640 if (result) {
641 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
642 "acpi_sbs_smbus_read_word() failed\n"));
643 goto end;
644 }
645
646 acpi_update_delay(battery->sbs);
647
648 end:
649 return result;
650}
651
652static int acpi_battery_get_alarm(struct acpi_battery *battery)
653{
654 struct acpi_ec_smbus *smbus = battery->sbs->smbus;
655 int result = 0;
656
657 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x01,
658 &battery->alarm.remaining_capacity,
659 &acpi_battery_smbus_err_handler);
660 if (result) {
661 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
662 "acpi_sbs_smbus_read_word() failed\n"));
663 goto end;
664 }
665
666 acpi_update_delay(battery->sbs);
667
668 end:
669
670 return result;
671}
672
673static int acpi_battery_set_alarm(struct acpi_battery *battery,
674 unsigned long alarm)
675{
676 struct acpi_ec_smbus *smbus = battery->sbs->smbus;
677 int result = 0;
678 s16 battery_mode;
679 int foo;
680
681 result = acpi_battery_select(battery);
682 if (result) {
683 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
684 "acpi_battery_select() failed\n"));
685 goto end;
686 }
687
688 /* If necessary, enable the alarm */
689
690 if (alarm > 0) {
691 result =
692 acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x03,
693 &battery_mode,
694 &acpi_battery_smbus_err_handler);
695 if (result) {
696 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
697 "acpi_sbs_smbus_read_word() failed\n"));
698 goto end;
699 }
700
701 result =
702 acpi_sbs_smbus_write_word(smbus, ACPI_SB_SMBUS_ADDR, 0x01,
703 battery_mode & 0xbfff,
704 &acpi_battery_smbus_err_handler);
705 if (result) {
706 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
707 "acpi_sbs_smbus_write_word() failed\n"));
708 goto end;
709 }
710 }
711
712 foo = alarm / (battery->info.capacity_mode ? 10 : 1);
713 result = acpi_sbs_smbus_write_word(smbus, ACPI_SB_SMBUS_ADDR, 0x01,
714 foo,
715 &acpi_battery_smbus_err_handler);
716 if (result) {
717 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
718 "acpi_sbs_smbus_write_word() failed\n"));
719 goto end;
720 }
721
722 end:
723
724 return result;
725}
726
727static int acpi_battery_set_mode(struct acpi_battery *battery)
728{
729 int result = 0;
730 s16 battery_mode;
731
732 if (capacity_mode == DEF_CAPACITY_UNIT) {
733 goto end;
734 }
735
736 result = acpi_sbs_smbus_read_word(battery->sbs->smbus,
737 ACPI_SB_SMBUS_ADDR, 0x03,
738 &battery_mode, NULL);
739 if (result) {
740 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
741 "acpi_sbs_smbus_read_word() failed\n"));
742 goto end;
743 }
744
745 if (capacity_mode == MAH_CAPACITY_UNIT) {
746 battery_mode &= 0x7fff;
747 } else {
748 battery_mode |= 0x8000;
749 }
750 result = acpi_sbs_smbus_write_word(battery->sbs->smbus,
751 ACPI_SB_SMBUS_ADDR, 0x03,
752 battery_mode, NULL);
753 if (result) {
754 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
755 "acpi_sbs_smbus_write_word() failed\n"));
756 goto end;
757 }
758
759 result = acpi_sbs_smbus_read_word(battery->sbs->smbus,
760 ACPI_SB_SMBUS_ADDR, 0x03,
761 &battery_mode, NULL);
762 if (result) {
763 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
764 "acpi_sbs_smbus_read_word() failed\n"));
765 goto end;
766 }
767
768 end:
769 return result;
770}
771
772static int acpi_battery_init(struct acpi_battery *battery)
773{
774 int result = 0;
775
776 result = acpi_battery_select(battery);
777 if (result) {
778 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
779 "acpi_battery_init() failed\n"));
780 goto end;
781 }
782
783 result = acpi_battery_set_mode(battery);
784 if (result) {
785 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
786 "acpi_battery_set_mode() failed\n"));
787 goto end;
788 }
789
790 result = acpi_battery_get_info(battery);
791 if (result) {
792 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
793 "acpi_battery_get_info() failed\n"));
794 goto end;
795 }
796
797 result = acpi_battery_get_state(battery);
798 if (result) {
799 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
800 "acpi_battery_get_state() failed\n"));
801 goto end;
802 }
803
804 result = acpi_battery_get_alarm(battery);
805 if (result) {
806 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
807 "acpi_battery_get_alarm() failed\n"));
808 goto end;
809 }
810
811 end:
812 return result;
813}
814
815static int acpi_ac_get_present(struct acpi_sbs *sbs)
816{
817 struct acpi_ec_smbus *smbus = sbs->smbus;
818 int result = 0;
819 s16 charger_status;
820
821 result = acpi_sbs_smbus_read_word(smbus, ACPI_SBC_SMBUS_ADDR, 0x13,
822 &charger_status, NULL);
823
824 if (result) {
825 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
826 "acpi_sbs_smbus_read_word() failed\n"));
827 goto end;
828 }
829
830 sbs->ac_present = (charger_status & 0x8000) >> 15;
831
832 end:
833
834 return result;
835}
836
837/* --------------------------------------------------------------------------
838 FS Interface (/proc/acpi)
839 -------------------------------------------------------------------------- */
840
841/* Generic Routines */
842
843static int
844acpi_sbs_generic_add_fs(struct proc_dir_entry **dir,
845 struct proc_dir_entry *parent_dir,
846 char *dir_name,
847 struct file_operations *info_fops,
848 struct file_operations *state_fops,
849 struct file_operations *alarm_fops, void *data)
850{
851 struct proc_dir_entry *entry = NULL;
852
853 if (!*dir) {
854 *dir = proc_mkdir(dir_name, parent_dir);
855 if (!*dir) {
856 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
857 "proc_mkdir() failed\n"));
858 return -ENODEV;
859 }
860 (*dir)->owner = THIS_MODULE;
861 }
862
863 /* 'info' [R] */
864 if (info_fops) {
865 entry = create_proc_entry(ACPI_SBS_FILE_INFO, S_IRUGO, *dir);
866 if (!entry) {
867 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
868 "create_proc_entry() failed\n"));
869 } else {
870 entry->proc_fops = info_fops;
871 entry->data = data;
872 entry->owner = THIS_MODULE;
873 }
874 }
875
876 /* 'state' [R] */
877 if (state_fops) {
878 entry = create_proc_entry(ACPI_SBS_FILE_STATE, S_IRUGO, *dir);
879 if (!entry) {
880 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
881 "create_proc_entry() failed\n"));
882 } else {
883 entry->proc_fops = state_fops;
884 entry->data = data;
885 entry->owner = THIS_MODULE;
886 }
887 }
888
889 /* 'alarm' [R/W] */
890 if (alarm_fops) {
891 entry = create_proc_entry(ACPI_SBS_FILE_ALARM, S_IRUGO, *dir);
892 if (!entry) {
893 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
894 "create_proc_entry() failed\n"));
895 } else {
896 entry->proc_fops = alarm_fops;
897 entry->data = data;
898 entry->owner = THIS_MODULE;
899 }
900 }
901
902 return 0;
903}
904
905static void
906acpi_sbs_generic_remove_fs(struct proc_dir_entry **dir,
907 struct proc_dir_entry *parent_dir)
908{
909
910 if (*dir) {
911 remove_proc_entry(ACPI_SBS_FILE_INFO, *dir);
912 remove_proc_entry(ACPI_SBS_FILE_STATE, *dir);
913 remove_proc_entry(ACPI_SBS_FILE_ALARM, *dir);
914 remove_proc_entry((*dir)->name, parent_dir);
915 *dir = NULL;
916 }
917
918}
919
920/* Smart Battery Interface */
921
922static struct proc_dir_entry *acpi_battery_dir = NULL;
923
924static int acpi_battery_read_info(struct seq_file *seq, void *offset)
925{
926 struct acpi_battery *battery = (struct acpi_battery *)seq->private;
927 int cscale;
928 int result = 0;
929
930 if (battery->sbs->zombie) {
931 return -ENODEV;
932 }
933
934 down(&sbs_sem);
935
936 if (update_mode == REQUEST_UPDATE_MODE) {
937 result = acpi_sbs_update_run(battery->sbs, DATA_TYPE_INFO);
938 if (result) {
939 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
940 "acpi_sbs_update_run() failed\n"));
941 }
942 }
943
944 if (acpi_battery_is_present(battery)) {
945 seq_printf(seq, "present: yes\n");
946 } else {
947 seq_printf(seq, "present: no\n");
948 goto end;
949 }
950
951 if (battery->info.capacity_mode) {
952 cscale = battery->info.vscale * battery->info.ipscale;
953 } else {
954 cscale = battery->info.ipscale;
955 }
956 seq_printf(seq, "design capacity: %i%s",
957 battery->info.design_capacity * cscale,
958 battery->info.capacity_mode ? "0 mWh\n" : " mAh\n");
959
960 seq_printf(seq, "last full capacity: %i%s",
961 battery->info.full_charge_capacity * cscale,
962 battery->info.capacity_mode ? "0 mWh\n" : " mAh\n");
963
964 seq_printf(seq, "battery technology: rechargeable\n");
965
966 seq_printf(seq, "design voltage: %i mV\n",
967 battery->info.design_voltage * battery->info.vscale);
968
969 seq_printf(seq, "design capacity warning: unknown\n");
970 seq_printf(seq, "design capacity low: unknown\n");
971 seq_printf(seq, "capacity granularity 1: unknown\n");
972 seq_printf(seq, "capacity granularity 2: unknown\n");
973
974 seq_printf(seq, "model number: %s\n",
975 battery->info.device_name);
976
977 seq_printf(seq, "serial number: %i\n",
978 battery->info.serial_number);
979
980 seq_printf(seq, "battery type: %s\n",
981 battery->info.device_chemistry);
982
983 seq_printf(seq, "OEM info: %s\n",
984 battery->info.manufacturer_name);
985
986 end:
987
988 up(&sbs_sem);
989
990 return result;
991}
992
993static int acpi_battery_info_open_fs(struct inode *inode, struct file *file)
994{
995 return single_open(file, acpi_battery_read_info, PDE(inode)->data);
996}
997
998static int acpi_battery_read_state(struct seq_file *seq, void *offset)
999{
1000 struct acpi_battery *battery = (struct acpi_battery *)seq->private;
1001 int result = 0;
1002 int cscale;
1003 int foo;
1004
1005 if (battery->sbs->zombie) {
1006 return -ENODEV;
1007 }
1008
1009 down(&sbs_sem);
1010
1011 if (update_mode == REQUEST_UPDATE_MODE) {
1012 result = acpi_sbs_update_run(battery->sbs, DATA_TYPE_STATE);
1013 if (result) {
1014 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1015 "acpi_sbs_update_run() failed\n"));
1016 }
1017 }
1018
1019 if (acpi_battery_is_present(battery)) {
1020 seq_printf(seq, "present: yes\n");
1021 } else {
1022 seq_printf(seq, "present: no\n");
1023 goto end;
1024 }
1025
1026 if (battery->info.capacity_mode) {
1027 cscale = battery->info.vscale * battery->info.ipscale;
1028 } else {
1029 cscale = battery->info.ipscale;
1030 }
1031
1032 if (battery->state.battery_status & 0x0010) {
1033 seq_printf(seq, "capacity state: critical\n");
1034 } else {
1035 seq_printf(seq, "capacity state: ok\n");
1036 }
1037 if (battery->state.amperage < 0) {
1038 seq_printf(seq, "charging state: discharging\n");
1039 foo = battery->state.remaining_capacity * cscale * 60 /
1040 (battery->state.average_time_to_empty == 0 ? 1 :
1041 battery->state.average_time_to_empty);
1042 seq_printf(seq, "present rate: %i%s\n",
1043 foo, battery->info.capacity_mode ? "0 mW" : " mA");
1044 } else if (battery->state.amperage > 0) {
1045 seq_printf(seq, "charging state: charging\n");
1046 foo = (battery->info.full_charge_capacity -
1047 battery->state.remaining_capacity) * cscale * 60 /
1048 (battery->state.average_time_to_full == 0 ? 1 :
1049 battery->state.average_time_to_full);
1050 seq_printf(seq, "present rate: %i%s\n",
1051 foo, battery->info.capacity_mode ? "0 mW" : " mA");
1052 } else {
1053 seq_printf(seq, "charging state: charged\n");
1054 seq_printf(seq, "present rate: 0 %s\n",
1055 battery->info.capacity_mode ? "mW" : "mA");
1056 }
1057
1058 seq_printf(seq, "remaining capacity: %i%s",
1059 battery->state.remaining_capacity * cscale,
1060 battery->info.capacity_mode ? "0 mWh\n" : " mAh\n");
1061
1062 seq_printf(seq, "present voltage: %i mV\n",
1063 battery->state.voltage * battery->info.vscale);
1064
1065 end:
1066
1067 up(&sbs_sem);
1068
1069 return result;
1070}
1071
1072static int acpi_battery_state_open_fs(struct inode *inode, struct file *file)
1073{
1074 return single_open(file, acpi_battery_read_state, PDE(inode)->data);
1075}
1076
1077static int acpi_battery_read_alarm(struct seq_file *seq, void *offset)
1078{
1079 struct acpi_battery *battery = (struct acpi_battery *)seq->private;
1080 int result = 0;
1081 int cscale;
1082
1083 if (battery->sbs->zombie) {
1084 return -ENODEV;
1085 }
1086
1087 down(&sbs_sem);
1088
1089 if (update_mode == REQUEST_UPDATE_MODE) {
1090 result = acpi_sbs_update_run(battery->sbs, DATA_TYPE_ALARM);
1091 if (result) {
1092 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1093 "acpi_sbs_update_run() failed\n"));
1094 }
1095 }
1096
1097 if (!acpi_battery_is_present(battery)) {
1098 seq_printf(seq, "present: no\n");
1099 goto end;
1100 }
1101
1102 if (battery->info.capacity_mode) {
1103 cscale = battery->info.vscale * battery->info.ipscale;
1104 } else {
1105 cscale = battery->info.ipscale;
1106 }
1107
1108 seq_printf(seq, "alarm: ");
1109 if (battery->alarm.remaining_capacity) {
1110 seq_printf(seq, "%i%s",
1111 battery->alarm.remaining_capacity * cscale,
1112 battery->info.capacity_mode ? "0 mWh\n" : " mAh\n");
1113 } else {
1114 seq_printf(seq, "disabled\n");
1115 }
1116
1117 end:
1118
1119 up(&sbs_sem);
1120
1121 return result;
1122}
1123
1124static ssize_t
1125acpi_battery_write_alarm(struct file *file, const char __user * buffer,
1126 size_t count, loff_t * ppos)
1127{
1128 struct seq_file *seq = (struct seq_file *)file->private_data;
1129 struct acpi_battery *battery = (struct acpi_battery *)seq->private;
1130 char alarm_string[12] = { '\0' };
1131 int result, old_alarm, new_alarm;
1132
1133 if (battery->sbs->zombie) {
1134 return -ENODEV;
1135 }
1136
1137 down(&sbs_sem);
1138
1139 if (!acpi_battery_is_present(battery)) {
1140 result = -ENODEV;
1141 goto end;
1142 }
1143
1144 if (count > sizeof(alarm_string) - 1) {
1145 result = -EINVAL;
1146 goto end;
1147 }
1148
1149 if (copy_from_user(alarm_string, buffer, count)) {
1150 result = -EFAULT;
1151 goto end;
1152 }
1153
1154 alarm_string[count] = 0;
1155
1156 old_alarm = battery->alarm.remaining_capacity;
1157 new_alarm = simple_strtoul(alarm_string, NULL, 0);
1158
1159 result = acpi_battery_set_alarm(battery, new_alarm);
1160 if (result) {
1161 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1162 "acpi_battery_set_alarm() failed\n"));
1163 (void)acpi_battery_set_alarm(battery, old_alarm);
1164 goto end;
1165 }
1166 result = acpi_battery_get_alarm(battery);
1167 if (result) {
1168 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1169 "acpi_battery_get_alarm() failed\n"));
1170 (void)acpi_battery_set_alarm(battery, old_alarm);
1171 goto end;
1172 }
1173
1174 end:
1175 up(&sbs_sem);
1176
1177 if (result) {
1178 return result;
1179 } else {
1180 return count;
1181 }
1182}
1183
1184static int acpi_battery_alarm_open_fs(struct inode *inode, struct file *file)
1185{
1186 return single_open(file, acpi_battery_read_alarm, PDE(inode)->data);
1187}
1188
1189static struct file_operations acpi_battery_info_fops = {
1190 .open = acpi_battery_info_open_fs,
1191 .read = seq_read,
1192 .llseek = seq_lseek,
1193 .release = single_release,
1194 .owner = THIS_MODULE,
1195};
1196
1197static struct file_operations acpi_battery_state_fops = {
1198 .open = acpi_battery_state_open_fs,
1199 .read = seq_read,
1200 .llseek = seq_lseek,
1201 .release = single_release,
1202 .owner = THIS_MODULE,
1203};
1204
1205static struct file_operations acpi_battery_alarm_fops = {
1206 .open = acpi_battery_alarm_open_fs,
1207 .read = seq_read,
1208 .write = acpi_battery_write_alarm,
1209 .llseek = seq_lseek,
1210 .release = single_release,
1211 .owner = THIS_MODULE,
1212};
1213
1214/* Legacy AC Adapter Interface */
1215
1216static struct proc_dir_entry *acpi_ac_dir = NULL;
1217
1218static int acpi_ac_read_state(struct seq_file *seq, void *offset)
1219{
1220 struct acpi_sbs *sbs = (struct acpi_sbs *)seq->private;
1221 int result;
1222
1223 if (sbs->zombie) {
1224 return -ENODEV;
1225 }
1226
1227 down(&sbs_sem);
1228
1229 if (update_mode == REQUEST_UPDATE_MODE) {
1230 result = acpi_sbs_update_run(sbs, DATA_TYPE_AC_STATE);
1231 if (result) {
1232 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1233 "acpi_sbs_update_run() failed\n"));
1234 }
1235 }
1236
1237 seq_printf(seq, "state: %s\n",
1238 sbs->ac_present ? "on-line" : "off-line");
1239
1240 up(&sbs_sem);
1241
1242 return 0;
1243}
1244
1245static int acpi_ac_state_open_fs(struct inode *inode, struct file *file)
1246{
1247 return single_open(file, acpi_ac_read_state, PDE(inode)->data);
1248}
1249
1250static struct file_operations acpi_ac_state_fops = {
1251 .open = acpi_ac_state_open_fs,
1252 .read = seq_read,
1253 .llseek = seq_lseek,
1254 .release = single_release,
1255 .owner = THIS_MODULE,
1256};
1257
1258/* --------------------------------------------------------------------------
1259 Driver Interface
1260 -------------------------------------------------------------------------- */
1261
1262/* Smart Battery */
1263
1264static int acpi_battery_add(struct acpi_sbs *sbs, int id)
1265{
1266 int is_present;
1267 int result;
1268 char dir_name[32];
1269 struct acpi_battery *battery;
1270
1271 battery = &sbs->battery[id];
1272
1273 battery->alive = 0;
1274
1275 battery->init_state = 0;
1276 battery->id = id;
1277 battery->sbs = sbs;
1278
1279 result = acpi_battery_select(battery);
1280 if (result) {
1281 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1282 "acpi_battery_select() failed\n"));
1283 goto end;
1284 }
1285
1286 result = acpi_battery_get_present(battery);
1287 if (result) {
1288 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1289 "acpi_battery_get_present() failed\n"));
1290 goto end;
1291 }
1292
1293 is_present = acpi_battery_is_present(battery);
1294
1295 if (is_present) {
1296 result = acpi_battery_init(battery);
1297 if (result) {
1298 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1299 "acpi_battery_init() failed\n"));
1300 goto end;
1301 }
1302 battery->init_state = 1;
1303 }
1304
1305 (void)sprintf(dir_name, ACPI_BATTERY_DIR_NAME, id);
1306
1307 result = acpi_sbs_generic_add_fs(&battery->battery_entry,
1308 acpi_battery_dir,
1309 dir_name,
1310 &acpi_battery_info_fops,
1311 &acpi_battery_state_fops,
1312 &acpi_battery_alarm_fops, battery);
1313 if (result) {
1314 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1315 "acpi_sbs_generic_add_fs() failed\n"));
1316 goto end;
1317 }
1318 battery->alive = 1;
1319
1320 end:
1321 return result;
1322}
1323
1324static void acpi_battery_remove(struct acpi_sbs *sbs, int id)
1325{
1326
1327 if (sbs->battery[id].battery_entry) {
1328 acpi_sbs_generic_remove_fs(&(sbs->battery[id].battery_entry),
1329 acpi_battery_dir);
1330 }
1331}
1332
1333static int acpi_ac_add(struct acpi_sbs *sbs)
1334{
1335 int result;
1336
1337 result = acpi_ac_get_present(sbs);
1338 if (result) {
1339 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1340 "acpi_ac_get_present() failed\n"));
1341 goto end;
1342 }
1343
1344 result = acpi_sbs_generic_add_fs(&sbs->ac_entry,
1345 acpi_ac_dir,
1346 ACPI_AC_DIR_NAME,
1347 NULL, &acpi_ac_state_fops, NULL, sbs);
1348 if (result) {
1349 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1350 "acpi_sbs_generic_add_fs() failed\n"));
1351 goto end;
1352 }
1353
1354 end:
1355
1356 return result;
1357}
1358
1359static void acpi_ac_remove(struct acpi_sbs *sbs)
1360{
1361
1362 if (sbs->ac_entry) {
1363 acpi_sbs_generic_remove_fs(&sbs->ac_entry, acpi_ac_dir);
1364 }
1365}
1366
1367static void acpi_sbs_update_queue_run(unsigned long data)
1368{
1369 acpi_os_execute(OSL_GPE_HANDLER, acpi_sbs_update_queue, (void *)data);
1370}
1371
1372static int acpi_sbs_update_run(struct acpi_sbs *sbs, int data_type)
1373{
1374 struct acpi_battery *battery;
1375 int result = 0;
1376 int old_ac_present;
1377 int old_battery_present;
1378 int new_ac_present;
1379 int new_battery_present;
1380 int id;
1381 char dir_name[32];
1382 int do_battery_init, do_ac_init;
1383 s16 old_remaining_capacity;
1384
1385 if (sbs->zombie) {
1386 goto end;
1387 }
1388
1389 old_ac_present = acpi_ac_is_present(sbs);
1390
1391 result = acpi_ac_get_present(sbs);
1392 if (result) {
1393 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1394 "acpi_ac_get_present() failed\n"));
1395 }
1396
1397 new_ac_present = acpi_ac_is_present(sbs);
1398
1399 do_ac_init = (old_ac_present != new_ac_present);
1400
1401 if (data_type == DATA_TYPE_AC_STATE) {
1402 goto end;
1403 }
1404
1405 for (id = 0; id < MAX_SBS_BAT; id++) {
1406 battery = &sbs->battery[id];
1407 if (battery->alive == 0) {
1408 continue;
1409 }
1410
1411 old_remaining_capacity = battery->state.remaining_capacity;
1412
1413 old_battery_present = acpi_battery_is_present(battery);
1414
1415 result = acpi_battery_select(battery);
1416 if (result) {
1417 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1418 "acpi_battery_select() failed\n"));
1419 }
1420 if (sbs->zombie) {
1421 goto end;
1422 }
1423
1424 result = acpi_battery_get_present(battery);
1425 if (result) {
1426 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1427 "acpi_battery_get_present() failed\n"));
1428 }
1429 if (sbs->zombie) {
1430 goto end;
1431 }
1432
1433 new_battery_present = acpi_battery_is_present(battery);
1434
1435 do_battery_init = ((old_battery_present != new_battery_present)
1436 && new_battery_present);
1437
1438 if (sbs->zombie) {
1439 goto end;
1440 }
1441 if (do_ac_init || do_battery_init ||
1442 update_info_mode || sbs->update_info_mode) {
1443 if (sbs->update_info_mode) {
1444 sbs->update_info_mode = 0;
1445 } else {
1446 sbs->update_info_mode = 1;
1447 }
1448 result = acpi_battery_init(battery);
1449 if (result) {
1450 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1451 "acpi_battery_init() "
1452 "failed\n"));
1453 }
1454 }
1455 if (data_type == DATA_TYPE_INFO) {
1456 continue;
1457 }
1458
1459 if (sbs->zombie) {
1460 goto end;
1461 }
1462 if (new_battery_present) {
1463 result = acpi_battery_get_alarm(battery);
1464 if (result) {
1465 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1466 "acpi_battery_get_alarm() "
1467 "failed\n"));
1468 }
1469 if (data_type == DATA_TYPE_ALARM) {
1470 continue;
1471 }
1472
1473 result = acpi_battery_get_state(battery);
1474 if (result) {
1475 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1476 "acpi_battery_get_state() "
1477 "failed\n"));
1478 }
1479 }
1480 if (sbs->zombie) {
1481 goto end;
1482 }
1483 if (data_type != DATA_TYPE_COMMON) {
1484 continue;
1485 }
1486
1487 if (old_battery_present != new_battery_present) {
1488 (void)sprintf(dir_name, ACPI_BATTERY_DIR_NAME, id);
1489 result = acpi_sbs_generate_event(sbs->device,
1490 ACPI_SBS_BATTERY_NOTIFY_STATUS,
1491 new_battery_present,
1492 dir_name,
1493 ACPI_BATTERY_CLASS);
1494 if (result) {
1495 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1496 "acpi_sbs_generate_event() "
1497 "failed\n"));
1498 }
1499 }
1500 if (old_remaining_capacity != battery->state.remaining_capacity) {
1501 (void)sprintf(dir_name, ACPI_BATTERY_DIR_NAME, id);
1502 result = acpi_sbs_generate_event(sbs->device,
1503 ACPI_SBS_BATTERY_NOTIFY_STATUS,
1504 new_battery_present,
1505 dir_name,
1506 ACPI_BATTERY_CLASS);
1507 if (result) {
1508 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1509 "acpi_sbs_generate_event() failed\n"));
1510 }
1511 }
1512
1513 }
1514 if (sbs->zombie) {
1515 goto end;
1516 }
1517 if (data_type != DATA_TYPE_COMMON) {
1518 goto end;
1519 }
1520
1521 if (old_ac_present != new_ac_present) {
1522 result = acpi_sbs_generate_event(sbs->device,
1523 ACPI_SBS_AC_NOTIFY_STATUS,
1524 new_ac_present,
1525 ACPI_AC_DIR_NAME,
1526 ACPI_AC_CLASS);
1527 if (result) {
1528 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1529 "acpi_sbs_generate_event() failed\n"));
1530 }
1531 }
1532
1533 end:
1534 return result;
1535}
1536
1537static void acpi_sbs_update_queue(void *data)
1538{
1539 struct acpi_sbs *sbs = data;
1540 unsigned long delay = -1;
1541 int result;
1542
1543 if (sbs->zombie) {
1544 goto end;
1545 }
1546
1547 result = acpi_sbs_update_run(sbs, DATA_TYPE_COMMON);
1548 if (result) {
1549 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1550 "acpi_sbs_update_run() failed\n"));
1551 }
1552
1553 if (sbs->zombie) {
1554 goto end;
1555 }
1556
1557 if (update_mode == REQUEST_UPDATE_MODE) {
1558 goto end;
1559 }
1560
1561 delay = jiffies + HZ * update_time;
1562 sbs->update_timer.data = (unsigned long)data;
1563 sbs->update_timer.function = acpi_sbs_update_queue_run;
1564 sbs->update_timer.expires = delay;
1565 add_timer(&sbs->update_timer);
1566 end:
1567 ;
1568}
1569
1570static int acpi_sbs_add(struct acpi_device *device)
1571{
1572 struct acpi_sbs *sbs = NULL;
1573 struct acpi_ec_hc *ec_hc = NULL;
1574 int result, remove_result = 0;
1575 unsigned long sbs_obj;
1576 int id, cnt;
1577 acpi_status status = AE_OK;
1578
1579 sbs = kmalloc(sizeof(struct acpi_sbs), GFP_KERNEL);
1580 if (!sbs) {
1581 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "kmalloc() failed\n"));
1582 return -ENOMEM;
1583 }
1584 memset(sbs, 0, sizeof(struct acpi_sbs));
1585
1586 cnt = 0;
1587 while (cnt < 10) {
1588 cnt++;
1589 ec_hc = acpi_get_ec_hc(device);
1590 if (ec_hc) {
1591 break;
1592 }
1593 msleep(1000);
1594 }
1595
1596 if (!ec_hc) {
1597 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1598 "acpi_get_ec_hc() failed: "
1599 "NO driver found for EC HC SMBus\n"));
1600 result = -ENODEV;
1601 goto end;
1602 }
1603
1604 sbs->device = device;
1605 sbs->smbus = ec_hc->smbus;
1606
1607 strcpy(acpi_device_name(device), ACPI_SBS_DEVICE_NAME);
1608 strcpy(acpi_device_class(device), ACPI_SBS_CLASS);
1609 acpi_driver_data(device) = sbs;
1610
1611 sbs->update_time = 0;
1612 sbs->update_time2 = 0;
1613
1614 result = acpi_ac_add(sbs);
1615 if (result) {
1616 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "acpi_ac_add() failed\n"));
1617 goto end;
1618 }
1619 result = acpi_evaluate_integer(device->handle, "_SBS", NULL, &sbs_obj);
1620 if (ACPI_FAILURE(result)) {
1621 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1622 "acpi_evaluate_integer() failed\n"));
1623 result = -EIO;
1624 goto end;
1625 }
1626
1627 if (sbs_obj > 0) {
1628 result = acpi_sbsm_get_info(sbs);
1629 if (result) {
1630 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1631 "acpi_sbsm_get_info() failed\n"));
1632 goto end;
1633 }
1634 sbs->sbsm_present = 1;
1635 }
1636 if (sbs->sbsm_present == 0) {
1637 result = acpi_battery_add(sbs, 0);
1638 if (result) {
1639 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1640 "acpi_battery_add() failed\n"));
1641 goto end;
1642 }
1643 } else {
1644 for (id = 0; id < MAX_SBS_BAT; id++) {
1645 if ((sbs->sbsm_batteries_supported & (1 << id))) {
1646 result = acpi_battery_add(sbs, id);
1647 if (result) {
1648 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1649 "acpi_battery_add() "
1650 "failed\n"));
1651 goto end;
1652 }
1653 }
1654 }
1655 }
1656
1657 sbs->handle = device->handle;
1658
1659 init_timer(&sbs->update_timer);
1660 if (update_mode == QUEUE_UPDATE_MODE) {
1661 status = acpi_os_execute(OSL_GPE_HANDLER,
1662 acpi_sbs_update_queue, (void *)sbs);
1663 if (status != AE_OK) {
1664 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1665 "acpi_os_execute() failed\n"));
1666 }
1667 }
1668 sbs->update_time = update_time;
1669 sbs->update_time2 = update_time2;
1670
1671 printk(KERN_INFO PREFIX "%s [%s]\n",
1672 acpi_device_name(device), acpi_device_bid(device));
1673
1674 end:
1675 if (result) {
1676 remove_result = acpi_sbs_remove(device, 0);
1677 if (remove_result) {
1678 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1679 "acpi_sbs_remove() failed\n"));
1680 }
1681 }
1682
1683 return result;
1684}
1685
1686int acpi_sbs_remove(struct acpi_device *device, int type)
1687{
1688 struct acpi_sbs *sbs = (struct acpi_sbs *)acpi_driver_data(device);
1689 int id;
1690
1691 if (!device || !sbs) {
1692 return -EINVAL;
1693 }
1694
1695 sbs->zombie = 1;
1696 sbs->update_time = 0;
1697 sbs->update_time2 = 0;
1698 del_timer_sync(&sbs->update_timer);
1699 acpi_os_wait_events_complete(NULL);
1700 del_timer_sync(&sbs->update_timer);
1701
1702 for (id = 0; id < MAX_SBS_BAT; id++) {
1703 acpi_battery_remove(sbs, id);
1704 }
1705
1706 acpi_ac_remove(sbs);
1707
1708 kfree(sbs);
1709
1710 return 0;
1711}
1712
1713static int __init acpi_sbs_init(void)
1714{
1715 int result = 0;
1716
1717 if (acpi_disabled)
1718 return -ENODEV;
1719
1720 init_MUTEX(&sbs_sem);
1721
1722 if (capacity_mode != DEF_CAPACITY_UNIT
1723 && capacity_mode != MAH_CAPACITY_UNIT
1724 && capacity_mode != MWH_CAPACITY_UNIT) {
1725 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "acpi_sbs_init: "
1726 "invalid capacity_mode = %d\n",
1727 capacity_mode));
1728 return -EINVAL;
1729 }
1730
1731 acpi_ac_dir = acpi_lock_ac_dir();
1732 if (!acpi_ac_dir) {
1733 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1734 "acpi_lock_ac_dir() failed\n"));
1735 return -ENODEV;
1736 }
1737
1738 acpi_battery_dir = acpi_lock_battery_dir();
1739 if (!acpi_battery_dir) {
1740 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1741 "acpi_lock_battery_dir() failed\n"));
1742 return -ENODEV;
1743 }
1744
1745 result = acpi_bus_register_driver(&acpi_sbs_driver);
1746 if (result < 0) {
1747 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1748 "acpi_bus_register_driver() failed\n"));
1749 return -ENODEV;
1750 }
1751
1752 return 0;
1753}
1754
1755static void __exit acpi_sbs_exit(void)
1756{
1757
1758 acpi_bus_unregister_driver(&acpi_sbs_driver);
1759
1760 acpi_unlock_ac_dir(acpi_ac_dir);
1761 acpi_ac_dir = NULL;
1762 acpi_unlock_battery_dir(acpi_battery_dir);
1763 acpi_battery_dir = NULL;
1764
1765 return;
1766}
1767
1768module_init(acpi_sbs_init);
1769module_exit(acpi_sbs_exit);
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index f8316a05ede7..698a1540e303 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -4,6 +4,7 @@
4 4
5#include <linux/module.h> 5#include <linux/module.h>
6#include <linux/init.h> 6#include <linux/init.h>
7#include <linux/kernel.h>
7#include <linux/acpi.h> 8#include <linux/acpi.h>
8 9
9#include <acpi/acpi_drivers.h> 10#include <acpi/acpi_drivers.h>
@@ -113,6 +114,8 @@ static struct kset acpi_namespace_kset = {
113static void acpi_device_register(struct acpi_device *device, 114static void acpi_device_register(struct acpi_device *device,
114 struct acpi_device *parent) 115 struct acpi_device *parent)
115{ 116{
117 int err;
118
116 /* 119 /*
117 * Linkage 120 * Linkage
118 * ------- 121 * -------
@@ -138,7 +141,10 @@ static void acpi_device_register(struct acpi_device *device,
138 device->kobj.parent = &parent->kobj; 141 device->kobj.parent = &parent->kobj;
139 device->kobj.ktype = &ktype_acpi_ns; 142 device->kobj.ktype = &ktype_acpi_ns;
140 device->kobj.kset = &acpi_namespace_kset; 143 device->kobj.kset = &acpi_namespace_kset;
141 kobject_register(&device->kobj); 144 err = kobject_register(&device->kobj);
145 if (err < 0)
146 printk(KERN_WARNING "%s: kobject_register error: %d\n",
147 __FUNCTION__, err);
142 create_sysfs_device_files(device); 148 create_sysfs_device_files(device);
143} 149}
144 150
@@ -162,11 +168,10 @@ static void acpi_device_unregister(struct acpi_device *device, int type)
162 168
163void acpi_bus_data_handler(acpi_handle handle, u32 function, void *context) 169void acpi_bus_data_handler(acpi_handle handle, u32 function, void *context)
164{ 170{
165 ACPI_FUNCTION_TRACE("acpi_bus_data_handler");
166 171
167 /* TBD */ 172 /* TBD */
168 173
169 return_VOID; 174 return;
170} 175}
171 176
172static int acpi_bus_get_power_flags(struct acpi_device *device) 177static int acpi_bus_get_power_flags(struct acpi_device *device)
@@ -175,7 +180,6 @@ static int acpi_bus_get_power_flags(struct acpi_device *device)
175 acpi_handle handle = NULL; 180 acpi_handle handle = NULL;
176 u32 i = 0; 181 u32 i = 0;
177 182
178 ACPI_FUNCTION_TRACE("acpi_bus_get_power_flags");
179 183
180 /* 184 /*
181 * Power Management Flags 185 * Power Management Flags
@@ -228,7 +232,7 @@ static int acpi_bus_get_power_flags(struct acpi_device *device)
228 232
229 device->power.state = ACPI_STATE_UNKNOWN; 233 device->power.state = ACPI_STATE_UNKNOWN;
230 234
231 return_VALUE(0); 235 return 0;
232} 236}
233 237
234int acpi_match_ids(struct acpi_device *device, char *ids) 238int acpi_match_ids(struct acpi_device *device, char *ids)
@@ -306,24 +310,22 @@ static int acpi_bus_get_wakeup_device_flags(struct acpi_device *device)
306 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; 310 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
307 union acpi_object *package = NULL; 311 union acpi_object *package = NULL;
308 312
309 ACPI_FUNCTION_TRACE("acpi_bus_get_wakeup_flags");
310 313
311 /* _PRW */ 314 /* _PRW */
312 status = acpi_evaluate_object(device->handle, "_PRW", NULL, &buffer); 315 status = acpi_evaluate_object(device->handle, "_PRW", NULL, &buffer);
313 if (ACPI_FAILURE(status)) { 316 if (ACPI_FAILURE(status)) {
314 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error evaluating _PRW\n")); 317 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PRW"));
315 goto end; 318 goto end;
316 } 319 }
317 320
318 package = (union acpi_object *)buffer.pointer; 321 package = (union acpi_object *)buffer.pointer;
319 status = acpi_bus_extract_wakeup_device_power_package(device, package); 322 status = acpi_bus_extract_wakeup_device_power_package(device, package);
320 if (ACPI_FAILURE(status)) { 323 if (ACPI_FAILURE(status)) {
321 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 324 ACPI_EXCEPTION((AE_INFO, status, "Extracting _PRW package"));
322 "Error extracting _PRW package\n"));
323 goto end; 325 goto end;
324 } 326 }
325 327
326 acpi_os_free(buffer.pointer); 328 kfree(buffer.pointer);
327 329
328 device->wakeup.flags.valid = 1; 330 device->wakeup.flags.valid = 1;
329 /* Power button, Lid switch always enable wakeup */ 331 /* Power button, Lid switch always enable wakeup */
@@ -333,7 +335,7 @@ static int acpi_bus_get_wakeup_device_flags(struct acpi_device *device)
333 end: 335 end:
334 if (ACPI_FAILURE(status)) 336 if (ACPI_FAILURE(status))
335 device->flags.wake_capable = 0; 337 device->flags.wake_capable = 0;
336 return_VALUE(0); 338 return 0;
337} 339}
338 340
339/* -------------------------------------------------------------------------- 341/* --------------------------------------------------------------------------
@@ -489,19 +491,18 @@ acpi_bus_driver_init(struct acpi_device *device, struct acpi_driver *driver)
489{ 491{
490 int result = 0; 492 int result = 0;
491 493
492 ACPI_FUNCTION_TRACE("acpi_bus_driver_init");
493 494
494 if (!device || !driver) 495 if (!device || !driver)
495 return_VALUE(-EINVAL); 496 return -EINVAL;
496 497
497 if (!driver->ops.add) 498 if (!driver->ops.add)
498 return_VALUE(-ENOSYS); 499 return -ENOSYS;
499 500
500 result = driver->ops.add(device); 501 result = driver->ops.add(device);
501 if (result) { 502 if (result) {
502 device->driver = NULL; 503 device->driver = NULL;
503 acpi_driver_data(device) = NULL; 504 acpi_driver_data(device) = NULL;
504 return_VALUE(result); 505 return result;
505 } 506 }
506 507
507 device->driver = driver; 508 device->driver = driver;
@@ -513,7 +514,7 @@ acpi_bus_driver_init(struct acpi_device *device, struct acpi_driver *driver)
513 514
514 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 515 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
515 "Driver successfully bound to device\n")); 516 "Driver successfully bound to device\n"));
516 return_VALUE(0); 517 return 0;
517} 518}
518 519
519static int acpi_start_single_object(struct acpi_device *device) 520static int acpi_start_single_object(struct acpi_device *device)
@@ -521,10 +522,9 @@ static int acpi_start_single_object(struct acpi_device *device)
521 int result = 0; 522 int result = 0;
522 struct acpi_driver *driver; 523 struct acpi_driver *driver;
523 524
524 ACPI_FUNCTION_TRACE("acpi_start_single_object");
525 525
526 if (!(driver = device->driver)) 526 if (!(driver = device->driver))
527 return_VALUE(0); 527 return 0;
528 528
529 if (driver->ops.start) { 529 if (driver->ops.start) {
530 result = driver->ops.start(device); 530 result = driver->ops.start(device);
@@ -532,14 +532,13 @@ static int acpi_start_single_object(struct acpi_device *device)
532 driver->ops.remove(device, ACPI_BUS_REMOVAL_NORMAL); 532 driver->ops.remove(device, ACPI_BUS_REMOVAL_NORMAL);
533 } 533 }
534 534
535 return_VALUE(result); 535 return result;
536} 536}
537 537
538static void acpi_driver_attach(struct acpi_driver *drv) 538static void acpi_driver_attach(struct acpi_driver *drv)
539{ 539{
540 struct list_head *node, *next; 540 struct list_head *node, *next;
541 541
542 ACPI_FUNCTION_TRACE("acpi_driver_attach");
543 542
544 spin_lock(&acpi_device_lock); 543 spin_lock(&acpi_device_lock);
545 list_for_each_safe(node, next, &acpi_device_list) { 544 list_for_each_safe(node, next, &acpi_device_list) {
@@ -568,7 +567,6 @@ static void acpi_driver_detach(struct acpi_driver *drv)
568{ 567{
569 struct list_head *node, *next; 568 struct list_head *node, *next;
570 569
571 ACPI_FUNCTION_TRACE("acpi_driver_detach");
572 570
573 spin_lock(&acpi_device_lock); 571 spin_lock(&acpi_device_lock);
574 list_for_each_safe(node, next, &acpi_device_list) { 572 list_for_each_safe(node, next, &acpi_device_list) {
@@ -598,17 +596,16 @@ static void acpi_driver_detach(struct acpi_driver *drv)
598 */ 596 */
599int acpi_bus_register_driver(struct acpi_driver *driver) 597int acpi_bus_register_driver(struct acpi_driver *driver)
600{ 598{
601 ACPI_FUNCTION_TRACE("acpi_bus_register_driver");
602 599
603 if (acpi_disabled) 600 if (acpi_disabled)
604 return_VALUE(-ENODEV); 601 return -ENODEV;
605 602
606 spin_lock(&acpi_device_lock); 603 spin_lock(&acpi_device_lock);
607 list_add_tail(&driver->node, &acpi_bus_drivers); 604 list_add_tail(&driver->node, &acpi_bus_drivers);
608 spin_unlock(&acpi_device_lock); 605 spin_unlock(&acpi_device_lock);
609 acpi_driver_attach(driver); 606 acpi_driver_attach(driver);
610 607
611 return_VALUE(0); 608 return 0;
612} 609}
613 610
614EXPORT_SYMBOL(acpi_bus_register_driver); 611EXPORT_SYMBOL(acpi_bus_register_driver);
@@ -646,7 +643,6 @@ static int acpi_bus_find_driver(struct acpi_device *device)
646 int result = 0; 643 int result = 0;
647 struct list_head *node, *next; 644 struct list_head *node, *next;
648 645
649 ACPI_FUNCTION_TRACE("acpi_bus_find_driver");
650 646
651 spin_lock(&acpi_device_lock); 647 spin_lock(&acpi_device_lock);
652 list_for_each_safe(node, next, &acpi_bus_drivers) { 648 list_for_each_safe(node, next, &acpi_bus_drivers) {
@@ -666,19 +662,41 @@ static int acpi_bus_find_driver(struct acpi_device *device)
666 spin_unlock(&acpi_device_lock); 662 spin_unlock(&acpi_device_lock);
667 663
668 Done: 664 Done:
669 return_VALUE(result); 665 return result;
670} 666}
671 667
672/* -------------------------------------------------------------------------- 668/* --------------------------------------------------------------------------
673 Device Enumeration 669 Device Enumeration
674 -------------------------------------------------------------------------- */ 670 -------------------------------------------------------------------------- */
675 671
672acpi_status
673acpi_bus_get_ejd(acpi_handle handle, acpi_handle *ejd)
674{
675 acpi_status status;
676 acpi_handle tmp;
677 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
678 union acpi_object *obj;
679
680 status = acpi_get_handle(handle, "_EJD", &tmp);
681 if (ACPI_FAILURE(status))
682 return status;
683
684 status = acpi_evaluate_object(handle, "_EJD", NULL, &buffer);
685 if (ACPI_SUCCESS(status)) {
686 obj = buffer.pointer;
687 status = acpi_get_handle(NULL, obj->string.pointer, ejd);
688 kfree(buffer.pointer);
689 }
690 return status;
691}
692EXPORT_SYMBOL_GPL(acpi_bus_get_ejd);
693
694
676static int acpi_bus_get_flags(struct acpi_device *device) 695static int acpi_bus_get_flags(struct acpi_device *device)
677{ 696{
678 acpi_status status = AE_OK; 697 acpi_status status = AE_OK;
679 acpi_handle temp = NULL; 698 acpi_handle temp = NULL;
680 699
681 ACPI_FUNCTION_TRACE("acpi_bus_get_flags");
682 700
683 /* Presence of _STA indicates 'dynamic_status' */ 701 /* Presence of _STA indicates 'dynamic_status' */
684 status = acpi_get_handle(device->handle, "_STA", &temp); 702 status = acpi_get_handle(device->handle, "_STA", &temp);
@@ -724,7 +742,7 @@ static int acpi_bus_get_flags(struct acpi_device *device)
724 742
725 /* TBD: Peformance management */ 743 /* TBD: Peformance management */
726 744
727 return_VALUE(0); 745 return 0;
728} 746}
729 747
730static void acpi_device_get_busid(struct acpi_device *device, 748static void acpi_device_get_busid(struct acpi_device *device,
@@ -842,7 +860,7 @@ static void acpi_device_set_id(struct acpi_device *device,
842 printk(KERN_ERR "Memory allocation error\n"); 860 printk(KERN_ERR "Memory allocation error\n");
843 } 861 }
844 862
845 acpi_os_free(buffer.pointer); 863 kfree(buffer.pointer);
846} 864}
847 865
848static int acpi_device_set_context(struct acpi_device *device, int type) 866static int acpi_device_set_context(struct acpi_device *device, int type)
@@ -918,10 +936,9 @@ static int acpi_bus_remove(struct acpi_device *dev, int rmdevice)
918 int result = 0; 936 int result = 0;
919 struct acpi_driver *driver; 937 struct acpi_driver *driver;
920 938
921 ACPI_FUNCTION_TRACE("acpi_bus_remove");
922 939
923 if (!dev) 940 if (!dev)
924 return_VALUE(-EINVAL); 941 return -EINVAL;
925 942
926 driver = dev->driver; 943 driver = dev->driver;
927 944
@@ -930,12 +947,12 @@ static int acpi_bus_remove(struct acpi_device *dev, int rmdevice)
930 if (driver->ops.stop) { 947 if (driver->ops.stop) {
931 result = driver->ops.stop(dev, ACPI_BUS_REMOVAL_EJECT); 948 result = driver->ops.stop(dev, ACPI_BUS_REMOVAL_EJECT);
932 if (result) 949 if (result)
933 return_VALUE(result); 950 return result;
934 } 951 }
935 952
936 result = dev->driver->ops.remove(dev, ACPI_BUS_REMOVAL_EJECT); 953 result = dev->driver->ops.remove(dev, ACPI_BUS_REMOVAL_EJECT);
937 if (result) { 954 if (result) {
938 return_VALUE(result); 955 return result;
939 } 956 }
940 957
941 atomic_dec(&dev->driver->references); 958 atomic_dec(&dev->driver->references);
@@ -944,7 +961,7 @@ static int acpi_bus_remove(struct acpi_device *dev, int rmdevice)
944 } 961 }
945 962
946 if (!rmdevice) 963 if (!rmdevice)
947 return_VALUE(0); 964 return 0;
948 965
949 if (dev->flags.bus_address) { 966 if (dev->flags.bus_address) {
950 if ((dev->parent) && (dev->parent->ops.unbind)) 967 if ((dev->parent) && (dev->parent->ops.unbind))
@@ -953,7 +970,7 @@ static int acpi_bus_remove(struct acpi_device *dev, int rmdevice)
953 970
954 acpi_device_unregister(dev, ACPI_BUS_REMOVAL_EJECT); 971 acpi_device_unregister(dev, ACPI_BUS_REMOVAL_EJECT);
955 972
956 return_VALUE(0); 973 return 0;
957} 974}
958 975
959static int 976static int
@@ -963,15 +980,14 @@ acpi_add_single_object(struct acpi_device **child,
963 int result = 0; 980 int result = 0;
964 struct acpi_device *device = NULL; 981 struct acpi_device *device = NULL;
965 982
966 ACPI_FUNCTION_TRACE("acpi_add_single_object");
967 983
968 if (!child) 984 if (!child)
969 return_VALUE(-EINVAL); 985 return -EINVAL;
970 986
971 device = kmalloc(sizeof(struct acpi_device), GFP_KERNEL); 987 device = kmalloc(sizeof(struct acpi_device), GFP_KERNEL);
972 if (!device) { 988 if (!device) {
973 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Memory allocation error\n")); 989 printk(KERN_ERR PREFIX "Memory allocation error\n");
974 return_VALUE(-ENOMEM); 990 return -ENOMEM;
975 } 991 }
976 memset(device, 0, sizeof(struct acpi_device)); 992 memset(device, 0, sizeof(struct acpi_device));
977 993
@@ -1096,7 +1112,7 @@ acpi_add_single_object(struct acpi_device **child,
1096 kfree(device); 1112 kfree(device);
1097 } 1113 }
1098 1114
1099 return_VALUE(result); 1115 return result;
1100} 1116}
1101 1117
1102static int acpi_bus_scan(struct acpi_device *start, struct acpi_bus_ops *ops) 1118static int acpi_bus_scan(struct acpi_device *start, struct acpi_bus_ops *ops)
@@ -1109,10 +1125,9 @@ static int acpi_bus_scan(struct acpi_device *start, struct acpi_bus_ops *ops)
1109 acpi_object_type type = 0; 1125 acpi_object_type type = 0;
1110 u32 level = 1; 1126 u32 level = 1;
1111 1127
1112 ACPI_FUNCTION_TRACE("acpi_bus_scan");
1113 1128
1114 if (!start) 1129 if (!start)
1115 return_VALUE(-EINVAL); 1130 return -EINVAL;
1116 1131
1117 parent = start; 1132 parent = start;
1118 phandle = start->handle; 1133 phandle = start->handle;
@@ -1209,7 +1224,7 @@ static int acpi_bus_scan(struct acpi_device *start, struct acpi_bus_ops *ops)
1209 } 1224 }
1210 } 1225 }
1211 1226
1212 return_VALUE(0); 1227 return 0;
1213} 1228}
1214 1229
1215int 1230int
@@ -1219,7 +1234,6 @@ acpi_bus_add(struct acpi_device **child,
1219 int result; 1234 int result;
1220 struct acpi_bus_ops ops; 1235 struct acpi_bus_ops ops;
1221 1236
1222 ACPI_FUNCTION_TRACE("acpi_bus_add");
1223 1237
1224 result = acpi_add_single_object(child, parent, handle, type); 1238 result = acpi_add_single_object(child, parent, handle, type);
1225 if (!result) { 1239 if (!result) {
@@ -1227,7 +1241,7 @@ acpi_bus_add(struct acpi_device **child,
1227 ops.acpi_op_add = 1; 1241 ops.acpi_op_add = 1;
1228 result = acpi_bus_scan(*child, &ops); 1242 result = acpi_bus_scan(*child, &ops);
1229 } 1243 }
1230 return_VALUE(result); 1244 return result;
1231} 1245}
1232 1246
1233EXPORT_SYMBOL(acpi_bus_add); 1247EXPORT_SYMBOL(acpi_bus_add);
@@ -1237,10 +1251,9 @@ int acpi_bus_start(struct acpi_device *device)
1237 int result; 1251 int result;
1238 struct acpi_bus_ops ops; 1252 struct acpi_bus_ops ops;
1239 1253
1240 ACPI_FUNCTION_TRACE("acpi_bus_start");
1241 1254
1242 if (!device) 1255 if (!device)
1243 return_VALUE(-EINVAL); 1256 return -EINVAL;
1244 1257
1245 result = acpi_start_single_object(device); 1258 result = acpi_start_single_object(device);
1246 if (!result) { 1259 if (!result) {
@@ -1248,7 +1261,7 @@ int acpi_bus_start(struct acpi_device *device)
1248 ops.acpi_op_start = 1; 1261 ops.acpi_op_start = 1;
1249 result = acpi_bus_scan(device, &ops); 1262 result = acpi_bus_scan(device, &ops);
1250 } 1263 }
1251 return_VALUE(result); 1264 return result;
1252} 1265}
1253 1266
1254EXPORT_SYMBOL(acpi_bus_start); 1267EXPORT_SYMBOL(acpi_bus_start);
@@ -1314,10 +1327,9 @@ static int acpi_bus_scan_fixed(struct acpi_device *root)
1314 int result = 0; 1327 int result = 0;
1315 struct acpi_device *device = NULL; 1328 struct acpi_device *device = NULL;
1316 1329
1317 ACPI_FUNCTION_TRACE("acpi_bus_scan_fixed");
1318 1330
1319 if (!root) 1331 if (!root)
1320 return_VALUE(-ENODEV); 1332 return -ENODEV;
1321 1333
1322 /* 1334 /*
1323 * Enumerate all fixed-feature devices. 1335 * Enumerate all fixed-feature devices.
@@ -1338,7 +1350,7 @@ static int acpi_bus_scan_fixed(struct acpi_device *root)
1338 result = acpi_start_single_object(device); 1350 result = acpi_start_single_object(device);
1339 } 1351 }
1340 1352
1341 return_VALUE(result); 1353 return result;
1342} 1354}
1343 1355
1344 1356
@@ -1427,7 +1439,7 @@ static int acpi_device_resume(struct device * dev)
1427} 1439}
1428 1440
1429 1441
1430struct bus_type acpi_bus_type = { 1442static struct bus_type acpi_bus_type = {
1431 .name = "acpi", 1443 .name = "acpi",
1432 .suspend = acpi_device_suspend, 1444 .suspend = acpi_device_suspend,
1433 .resume = acpi_device_resume, 1445 .resume = acpi_device_resume,
@@ -1440,12 +1452,13 @@ static int __init acpi_scan_init(void)
1440 int result; 1452 int result;
1441 struct acpi_bus_ops ops; 1453 struct acpi_bus_ops ops;
1442 1454
1443 ACPI_FUNCTION_TRACE("acpi_scan_init");
1444 1455
1445 if (acpi_disabled) 1456 if (acpi_disabled)
1446 return_VALUE(0); 1457 return 0;
1447 1458
1448 kset_register(&acpi_namespace_kset); 1459 result = kset_register(&acpi_namespace_kset);
1460 if (result < 0)
1461 printk(KERN_ERR PREFIX "kset_register error: %d\n", result);
1449 1462
1450 result = bus_register(&acpi_bus_type); 1463 result = bus_register(&acpi_bus_type);
1451 if (result) { 1464 if (result) {
@@ -1488,7 +1501,7 @@ static int __init acpi_scan_init(void)
1488 acpi_device_unregister(acpi_root, ACPI_BUS_REMOVAL_NORMAL); 1501 acpi_device_unregister(acpi_root, ACPI_BUS_REMOVAL_NORMAL);
1489 1502
1490 Done: 1503 Done:
1491 return_VALUE(result); 1504 return result;
1492} 1505}
1493 1506
1494subsys_initcall(acpi_scan_init); 1507subsys_initcall(acpi_scan_init);
diff --git a/drivers/acpi/sleep/proc.c b/drivers/acpi/sleep/proc.c
index 4696a85a98b9..34962578039d 100644
--- a/drivers/acpi/sleep/proc.c
+++ b/drivers/acpi/sleep/proc.c
@@ -434,7 +434,7 @@ acpi_system_wakeup_device_open_fs(struct inode *inode, struct file *file)
434 PDE(inode)->data); 434 PDE(inode)->data);
435} 435}
436 436
437static struct file_operations acpi_system_wakeup_device_fops = { 437static const struct file_operations acpi_system_wakeup_device_fops = {
438 .open = acpi_system_wakeup_device_open_fs, 438 .open = acpi_system_wakeup_device_open_fs,
439 .read = seq_read, 439 .read = seq_read,
440 .write = acpi_system_write_wakeup_device, 440 .write = acpi_system_write_wakeup_device,
@@ -443,7 +443,7 @@ static struct file_operations acpi_system_wakeup_device_fops = {
443}; 443};
444 444
445#ifdef CONFIG_ACPI_SLEEP_PROC_SLEEP 445#ifdef CONFIG_ACPI_SLEEP_PROC_SLEEP
446static struct file_operations acpi_system_sleep_fops = { 446static const struct file_operations acpi_system_sleep_fops = {
447 .open = acpi_system_sleep_open_fs, 447 .open = acpi_system_sleep_open_fs,
448 .read = seq_read, 448 .read = seq_read,
449 .write = acpi_system_write_sleep, 449 .write = acpi_system_write_sleep,
@@ -452,7 +452,7 @@ static struct file_operations acpi_system_sleep_fops = {
452}; 452};
453#endif /* CONFIG_ACPI_SLEEP_PROC_SLEEP */ 453#endif /* CONFIG_ACPI_SLEEP_PROC_SLEEP */
454 454
455static struct file_operations acpi_system_alarm_fops = { 455static const struct file_operations acpi_system_alarm_fops = {
456 .open = acpi_system_alarm_open_fs, 456 .open = acpi_system_alarm_open_fs,
457 .read = seq_read, 457 .read = seq_read,
458 .write = acpi_system_write_alarm, 458 .write = acpi_system_write_alarm,
diff --git a/drivers/acpi/system.c b/drivers/acpi/system.c
index a934ac42178d..d86dcb3c2366 100644
--- a/drivers/acpi/system.c
+++ b/drivers/acpi/system.c
@@ -47,10 +47,9 @@ extern struct fadt_descriptor acpi_fadt;
47 47
48static int acpi_system_read_info(struct seq_file *seq, void *offset) 48static int acpi_system_read_info(struct seq_file *seq, void *offset)
49{ 49{
50 ACPI_FUNCTION_TRACE("acpi_system_read_info");
51 50
52 seq_printf(seq, "version: %x\n", ACPI_CA_VERSION); 51 seq_printf(seq, "version: %x\n", ACPI_CA_VERSION);
53 return_VALUE(0); 52 return 0;
54} 53}
55 54
56static int acpi_system_info_open_fs(struct inode *inode, struct file *file) 55static int acpi_system_info_open_fs(struct inode *inode, struct file *file)
@@ -58,7 +57,7 @@ static int acpi_system_info_open_fs(struct inode *inode, struct file *file)
58 return single_open(file, acpi_system_read_info, PDE(inode)->data); 57 return single_open(file, acpi_system_read_info, PDE(inode)->data);
59} 58}
60 59
61static struct file_operations acpi_system_info_ops = { 60static const struct file_operations acpi_system_info_ops = {
62 .open = acpi_system_info_open_fs, 61 .open = acpi_system_info_open_fs,
63 .read = seq_read, 62 .read = seq_read,
64 .llseek = seq_lseek, 63 .llseek = seq_lseek,
@@ -68,7 +67,7 @@ static struct file_operations acpi_system_info_ops = {
68static ssize_t acpi_system_read_dsdt(struct file *, char __user *, size_t, 67static ssize_t acpi_system_read_dsdt(struct file *, char __user *, size_t,
69 loff_t *); 68 loff_t *);
70 69
71static struct file_operations acpi_system_dsdt_ops = { 70static const struct file_operations acpi_system_dsdt_ops = {
72 .read = acpi_system_read_dsdt, 71 .read = acpi_system_read_dsdt,
73}; 72};
74 73
@@ -80,23 +79,22 @@ acpi_system_read_dsdt(struct file *file,
80 struct acpi_buffer dsdt = { ACPI_ALLOCATE_BUFFER, NULL }; 79 struct acpi_buffer dsdt = { ACPI_ALLOCATE_BUFFER, NULL };
81 ssize_t res; 80 ssize_t res;
82 81
83 ACPI_FUNCTION_TRACE("acpi_system_read_dsdt");
84 82
85 status = acpi_get_table(ACPI_TABLE_ID_DSDT, 1, &dsdt); 83 status = acpi_get_table(ACPI_TABLE_ID_DSDT, 1, &dsdt);
86 if (ACPI_FAILURE(status)) 84 if (ACPI_FAILURE(status))
87 return_VALUE(-ENODEV); 85 return -ENODEV;
88 86
89 res = simple_read_from_buffer(buffer, count, ppos, 87 res = simple_read_from_buffer(buffer, count, ppos,
90 dsdt.pointer, dsdt.length); 88 dsdt.pointer, dsdt.length);
91 acpi_os_free(dsdt.pointer); 89 kfree(dsdt.pointer);
92 90
93 return_VALUE(res); 91 return res;
94} 92}
95 93
96static ssize_t acpi_system_read_fadt(struct file *, char __user *, size_t, 94static ssize_t acpi_system_read_fadt(struct file *, char __user *, size_t,
97 loff_t *); 95 loff_t *);
98 96
99static struct file_operations acpi_system_fadt_ops = { 97static const struct file_operations acpi_system_fadt_ops = {
100 .read = acpi_system_read_fadt, 98 .read = acpi_system_read_fadt,
101}; 99};
102 100
@@ -108,17 +106,16 @@ acpi_system_read_fadt(struct file *file,
108 struct acpi_buffer fadt = { ACPI_ALLOCATE_BUFFER, NULL }; 106 struct acpi_buffer fadt = { ACPI_ALLOCATE_BUFFER, NULL };
109 ssize_t res; 107 ssize_t res;
110 108
111 ACPI_FUNCTION_TRACE("acpi_system_read_fadt");
112 109
113 status = acpi_get_table(ACPI_TABLE_ID_FADT, 1, &fadt); 110 status = acpi_get_table(ACPI_TABLE_ID_FADT, 1, &fadt);
114 if (ACPI_FAILURE(status)) 111 if (ACPI_FAILURE(status))
115 return_VALUE(-ENODEV); 112 return -ENODEV;
116 113
117 res = simple_read_from_buffer(buffer, count, ppos, 114 res = simple_read_from_buffer(buffer, count, ppos,
118 fadt.pointer, fadt.length); 115 fadt.pointer, fadt.length);
119 acpi_os_free(fadt.pointer); 116 kfree(fadt.pointer);
120 117
121 return_VALUE(res); 118 return res;
122} 119}
123 120
124static int __init acpi_system_init(void) 121static int __init acpi_system_init(void)
@@ -127,10 +124,9 @@ static int __init acpi_system_init(void)
127 int error = 0; 124 int error = 0;
128 char *name; 125 char *name;
129 126
130 ACPI_FUNCTION_TRACE("acpi_system_init");
131 127
132 if (acpi_disabled) 128 if (acpi_disabled)
133 return_VALUE(0); 129 return 0;
134 130
135 /* 'info' [R] */ 131 /* 'info' [R] */
136 name = ACPI_SYSTEM_FILE_INFO; 132 name = ACPI_SYSTEM_FILE_INFO;
@@ -158,12 +154,9 @@ static int __init acpi_system_init(void)
158 goto Error; 154 goto Error;
159 155
160 Done: 156 Done:
161 return_VALUE(error); 157 return error;
162 158
163 Error: 159 Error:
164 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
165 "Unable to create '%s' proc fs entry\n", name));
166
167 remove_proc_entry(ACPI_SYSTEM_FILE_FADT, acpi_root_dir); 160 remove_proc_entry(ACPI_SYSTEM_FILE_FADT, acpi_root_dir);
168 remove_proc_entry(ACPI_SYSTEM_FILE_DSDT, acpi_root_dir); 161 remove_proc_entry(ACPI_SYSTEM_FILE_DSDT, acpi_root_dir);
169 remove_proc_entry(ACPI_SYSTEM_FILE_INFO, acpi_root_dir); 162 remove_proc_entry(ACPI_SYSTEM_FILE_INFO, acpi_root_dir);
diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c
index ed5e8816d83d..bfb3bfcf9e91 100644
--- a/drivers/acpi/tables.c
+++ b/drivers/acpi/tables.c
@@ -23,7 +23,6 @@
23 * 23 *
24 */ 24 */
25 25
26#include <linux/config.h>
27#include <linux/init.h> 26#include <linux/init.h>
28#include <linux/kernel.h> 27#include <linux/kernel.h>
29#include <linux/sched.h> 28#include <linux/sched.h>
diff --git a/drivers/acpi/tables/tbget.c b/drivers/acpi/tables/tbget.c
index 99eacceff563..7856db759af0 100644
--- a/drivers/acpi/tables/tbget.c
+++ b/drivers/acpi/tables/tbget.c
@@ -320,6 +320,16 @@ acpi_tb_get_this_table(struct acpi_pointer *address,
320 320
321 ACPI_FUNCTION_TRACE(tb_get_this_table); 321 ACPI_FUNCTION_TRACE(tb_get_this_table);
322 322
323 /* Validate minimum length */
324
325 if (header->length < sizeof(struct acpi_table_header)) {
326 ACPI_ERROR((AE_INFO,
327 "Table length (%X) is smaller than minimum (%X)",
328 header->length, sizeof(struct acpi_table_header)));
329
330 return_ACPI_STATUS(AE_INVALID_TABLE_LENGTH);
331 }
332
323 /* 333 /*
324 * Flags contains the current processor mode (Virtual or Physical 334 * Flags contains the current processor mode (Virtual or Physical
325 * addressing) The pointer_type is either Logical or Physical 335 * addressing) The pointer_type is either Logical or Physical
@@ -356,7 +366,7 @@ acpi_tb_get_this_table(struct acpi_pointer *address,
356 */ 366 */
357 status = acpi_os_map_memory(address->pointer.physical, 367 status = acpi_os_map_memory(address->pointer.physical,
358 (acpi_size) header->length, 368 (acpi_size) header->length,
359 (void *)&full_table); 369 ACPI_CAST_PTR(void, &full_table));
360 if (ACPI_FAILURE(status)) { 370 if (ACPI_FAILURE(status)) {
361 ACPI_ERROR((AE_INFO, 371 ACPI_ERROR((AE_INFO,
362 "Could not map memory for table [%4.4s] at %8.8X%8.8X for length %X", 372 "Could not map memory for table [%4.4s] at %8.8X%8.8X for length %X",
diff --git a/drivers/acpi/tables/tbinstal.c b/drivers/acpi/tables/tbinstal.c
index 7ca2df75bb11..1668a232fb67 100644
--- a/drivers/acpi/tables/tbinstal.c
+++ b/drivers/acpi/tables/tbinstal.c
@@ -256,7 +256,7 @@ acpi_tb_init_table_descriptor(acpi_table_type table_type,
256 256
257 status = acpi_ut_allocate_owner_id(&table_desc->owner_id); 257 status = acpi_ut_allocate_owner_id(&table_desc->owner_id);
258 if (ACPI_FAILURE(status)) { 258 if (ACPI_FAILURE(status)) {
259 return_ACPI_STATUS(status); 259 goto error_exit1;
260 } 260 }
261 261
262 /* Install the table into the global data structure */ 262 /* Install the table into the global data structure */
@@ -274,8 +274,8 @@ acpi_tb_init_table_descriptor(acpi_table_type table_type,
274 * at this location, so return an error. 274 * at this location, so return an error.
275 */ 275 */
276 if (list_head->next) { 276 if (list_head->next) {
277 ACPI_FREE(table_desc); 277 status = AE_ALREADY_EXISTS;
278 return_ACPI_STATUS(AE_ALREADY_EXISTS); 278 goto error_exit2;
279 } 279 }
280 280
281 table_desc->next = list_head->next; 281 table_desc->next = list_head->next;
@@ -335,6 +335,17 @@ acpi_tb_init_table_descriptor(acpi_table_type table_type,
335 table_info->owner_id = table_desc->owner_id; 335 table_info->owner_id = table_desc->owner_id;
336 table_info->installed_desc = table_desc; 336 table_info->installed_desc = table_desc;
337 return_ACPI_STATUS(AE_OK); 337 return_ACPI_STATUS(AE_OK);
338
339 /* Error exit with cleanup */
340
341 error_exit2:
342
343 acpi_ut_release_owner_id(&table_desc->owner_id);
344
345 error_exit1:
346
347 ACPI_FREE(table_desc);
348 return_ACPI_STATUS(status);
338} 349}
339 350
340/******************************************************************************* 351/*******************************************************************************
@@ -525,6 +536,10 @@ struct acpi_table_desc *acpi_tb_uninstall_table(struct acpi_table_desc
525 536
526 acpi_tb_delete_single_table(table_desc); 537 acpi_tb_delete_single_table(table_desc);
527 538
539 /* Free the owner ID associated with this table */
540
541 acpi_ut_release_owner_id(&table_desc->owner_id);
542
528 /* Free the table descriptor */ 543 /* Free the table descriptor */
529 544
530 next_desc = table_desc->next; 545 next_desc = table_desc->next;
diff --git a/drivers/acpi/tables/tbrsdt.c b/drivers/acpi/tables/tbrsdt.c
index abcb08c2592a..0ad3dbb9ebca 100644
--- a/drivers/acpi/tables/tbrsdt.c
+++ b/drivers/acpi/tables/tbrsdt.c
@@ -183,6 +183,17 @@ acpi_status acpi_tb_validate_rsdt(struct acpi_table_header *table_ptr)
183 183
184 ACPI_FUNCTION_ENTRY(); 184 ACPI_FUNCTION_ENTRY();
185 185
186 /* Validate minimum length */
187
188 if (table_ptr->length < sizeof(struct acpi_table_header)) {
189 ACPI_ERROR((AE_INFO,
190 "RSDT/XSDT length (%X) is smaller than minimum (%X)",
191 table_ptr->length,
192 sizeof(struct acpi_table_header)));
193
194 return (AE_INVALID_TABLE_LENGTH);
195 }
196
186 /* Search for appropriate signature, RSDT or XSDT */ 197 /* Search for appropriate signature, RSDT or XSDT */
187 198
188 if (acpi_gbl_root_table_type == ACPI_TABLE_TYPE_RSDT) { 199 if (acpi_gbl_root_table_type == ACPI_TABLE_TYPE_RSDT) {
@@ -210,7 +221,7 @@ acpi_status acpi_tb_validate_rsdt(struct acpi_table_header *table_ptr)
210 ACPI_ERROR((AE_INFO, "Looking for XSDT")); 221 ACPI_ERROR((AE_INFO, "Looking for XSDT"));
211 } 222 }
212 223
213 ACPI_DUMP_BUFFER((char *)table_ptr, 48); 224 ACPI_DUMP_BUFFER(ACPI_CAST_PTR(char, table_ptr), 48);
214 return (AE_BAD_SIGNATURE); 225 return (AE_BAD_SIGNATURE);
215 } 226 }
216 227
@@ -258,7 +269,7 @@ acpi_status acpi_tb_get_table_rsdt(void)
258 269
259 status = acpi_tb_validate_rsdt(table_info.pointer); 270 status = acpi_tb_validate_rsdt(table_info.pointer);
260 if (ACPI_FAILURE(status)) { 271 if (ACPI_FAILURE(status)) {
261 return_ACPI_STATUS(status); 272 goto error_cleanup;
262 } 273 }
263 274
264 /* Get the number of tables defined in the RSDT or XSDT */ 275 /* Get the number of tables defined in the RSDT or XSDT */
@@ -270,14 +281,14 @@ acpi_status acpi_tb_get_table_rsdt(void)
270 281
271 status = acpi_tb_convert_to_xsdt(&table_info); 282 status = acpi_tb_convert_to_xsdt(&table_info);
272 if (ACPI_FAILURE(status)) { 283 if (ACPI_FAILURE(status)) {
273 return_ACPI_STATUS(status); 284 goto error_cleanup;
274 } 285 }
275 286
276 /* Save the table pointers and allocation info */ 287 /* Save the table pointers and allocation info */
277 288
278 status = acpi_tb_init_table_descriptor(ACPI_TABLE_ID_XSDT, &table_info); 289 status = acpi_tb_init_table_descriptor(ACPI_TABLE_ID_XSDT, &table_info);
279 if (ACPI_FAILURE(status)) { 290 if (ACPI_FAILURE(status)) {
280 return_ACPI_STATUS(status); 291 goto error_cleanup;
281 } 292 }
282 293
283 acpi_gbl_XSDT = 294 acpi_gbl_XSDT =
@@ -285,4 +296,12 @@ acpi_status acpi_tb_get_table_rsdt(void)
285 296
286 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "XSDT located at %p\n", acpi_gbl_XSDT)); 297 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "XSDT located at %p\n", acpi_gbl_XSDT));
287 return_ACPI_STATUS(status); 298 return_ACPI_STATUS(status);
299
300 error_cleanup:
301
302 /* Free table allocated by acpi_tb_get_table */
303
304 acpi_tb_delete_single_table(&table_info);
305
306 return_ACPI_STATUS(status);
288} 307}
diff --git a/drivers/acpi/tables/tbxface.c b/drivers/acpi/tables/tbxface.c
index 4e91f2984815..7767987be15a 100644
--- a/drivers/acpi/tables/tbxface.c
+++ b/drivers/acpi/tables/tbxface.c
@@ -134,8 +134,8 @@ ACPI_EXPORT_SYMBOL(acpi_load_tables)
134 * RETURN: Status 134 * RETURN: Status
135 * 135 *
136 * DESCRIPTION: This function is called to load a table from the caller's 136 * DESCRIPTION: This function is called to load a table from the caller's
137 * buffer. The buffer must contain an entire ACPI Table including 137 * buffer. The buffer must contain an entire ACPI Table including
138 * a valid header. The header fields will be verified, and if it 138 * a valid header. The header fields will be verified, and if it
139 * is determined that the table is invalid, the call will fail. 139 * is determined that the table is invalid, the call will fail.
140 * 140 *
141 ******************************************************************************/ 141 ******************************************************************************/
@@ -245,15 +245,18 @@ acpi_status acpi_unload_table(acpi_table_type table_type)
245 /* Find all tables of the requested type */ 245 /* Find all tables of the requested type */
246 246
247 table_desc = acpi_gbl_table_lists[table_type].next; 247 table_desc = acpi_gbl_table_lists[table_type].next;
248 if (!table_desc) {
249 return_ACPI_STATUS(AE_NOT_EXIST);
250 }
251
248 while (table_desc) { 252 while (table_desc) {
249 /* 253 /*
250 * Delete all namespace entries owned by this table. Note that these 254 * Delete all namespace objects owned by this table. Note that these
251 * entries can appear anywhere in the namespace by virtue of the AML 255 * objects can appear anywhere in the namespace by virtue of the AML
252 * "Scope" operator. Thus, we need to track ownership by an ID, not 256 * "Scope" operator. Thus, we need to track ownership by an ID, not
253 * simply a position within the hierarchy 257 * simply a position within the hierarchy
254 */ 258 */
255 acpi_ns_delete_namespace_by_owner(table_desc->owner_id); 259 acpi_ns_delete_namespace_by_owner(table_desc->owner_id);
256 acpi_ut_release_owner_id(&table_desc->owner_id);
257 table_desc = table_desc->next; 260 table_desc = table_desc->next;
258 } 261 }
259 262
@@ -275,12 +278,12 @@ ACPI_EXPORT_SYMBOL(acpi_unload_table)
275 * see acpi_gbl_acpi_table_flag 278 * see acpi_gbl_acpi_table_flag
276 * out_table_header - pointer to the struct acpi_table_header if successful 279 * out_table_header - pointer to the struct acpi_table_header if successful
277 * 280 *
278 * DESCRIPTION: This function is called to get an ACPI table header. The caller 281 * DESCRIPTION: This function is called to get an ACPI table header. The caller
279 * supplies an pointer to a data area sufficient to contain an ACPI 282 * supplies an pointer to a data area sufficient to contain an ACPI
280 * struct acpi_table_header structure. 283 * struct acpi_table_header structure.
281 * 284 *
282 * The header contains a length field that can be used to determine 285 * The header contains a length field that can be used to determine
283 * the size of the buffer needed to contain the entire table. This 286 * the size of the buffer needed to contain the entire table. This
284 * function is not valid for the RSD PTR table since it does not 287 * function is not valid for the RSD PTR table since it does not
285 * have a standard header and is fixed length. 288 * have a standard header and is fixed length.
286 * 289 *
@@ -322,7 +325,8 @@ acpi_get_table_header(acpi_table_type table_type,
322 325
323 /* Copy the header to the caller's buffer */ 326 /* Copy the header to the caller's buffer */
324 327
325 ACPI_MEMCPY((void *)out_table_header, (void *)tbl_ptr, 328 ACPI_MEMCPY(ACPI_CAST_PTR(void, out_table_header),
329 ACPI_CAST_PTR(void, tbl_ptr),
326 sizeof(struct acpi_table_header)); 330 sizeof(struct acpi_table_header));
327 331
328 return_ACPI_STATUS(status); 332 return_ACPI_STATUS(status);
@@ -344,10 +348,10 @@ ACPI_EXPORT_SYMBOL(acpi_get_table_header)
344 * 348 *
345 * RETURN: Status 349 * RETURN: Status
346 * 350 *
347 * DESCRIPTION: This function is called to get an ACPI table. The caller 351 * DESCRIPTION: This function is called to get an ACPI table. The caller
348 * supplies an out_buffer large enough to contain the entire ACPI 352 * supplies an out_buffer large enough to contain the entire ACPI
349 * table. The caller should call the acpi_get_table_header function 353 * table. The caller should call the acpi_get_table_header function
350 * first to determine the buffer size needed. Upon completion 354 * first to determine the buffer size needed. Upon completion
351 * the out_buffer->Length field will indicate the number of bytes 355 * the out_buffer->Length field will indicate the number of bytes
352 * copied into the out_buffer->buf_ptr buffer. This table will be 356 * copied into the out_buffer->buf_ptr buffer. This table will be
353 * a complete table including the header. 357 * a complete table including the header.
@@ -417,7 +421,9 @@ acpi_get_table(acpi_table_type table_type,
417 421
418 /* Copy the table to the buffer */ 422 /* Copy the table to the buffer */
419 423
420 ACPI_MEMCPY((void *)ret_buffer->pointer, (void *)tbl_ptr, table_length); 424 ACPI_MEMCPY(ACPI_CAST_PTR(void, ret_buffer->pointer),
425 ACPI_CAST_PTR(void, tbl_ptr), table_length);
426
421 return_ACPI_STATUS(AE_OK); 427 return_ACPI_STATUS(AE_OK);
422} 428}
423 429
diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c
index e7fe3a14fdaf..5753d06b7860 100644
--- a/drivers/acpi/thermal.c
+++ b/drivers/acpi/thermal.c
@@ -162,7 +162,7 @@ struct acpi_thermal_flags {
162}; 162};
163 163
164struct acpi_thermal { 164struct acpi_thermal {
165 acpi_handle handle; 165 struct acpi_device * device;
166 acpi_bus_id name; 166 acpi_bus_id name;
167 unsigned long temperature; 167 unsigned long temperature;
168 unsigned long last_temperature; 168 unsigned long last_temperature;
@@ -176,21 +176,21 @@ struct acpi_thermal {
176 struct timer_list timer; 176 struct timer_list timer;
177}; 177};
178 178
179static struct file_operations acpi_thermal_state_fops = { 179static const struct file_operations acpi_thermal_state_fops = {
180 .open = acpi_thermal_state_open_fs, 180 .open = acpi_thermal_state_open_fs,
181 .read = seq_read, 181 .read = seq_read,
182 .llseek = seq_lseek, 182 .llseek = seq_lseek,
183 .release = single_release, 183 .release = single_release,
184}; 184};
185 185
186static struct file_operations acpi_thermal_temp_fops = { 186static const struct file_operations acpi_thermal_temp_fops = {
187 .open = acpi_thermal_temp_open_fs, 187 .open = acpi_thermal_temp_open_fs,
188 .read = seq_read, 188 .read = seq_read,
189 .llseek = seq_lseek, 189 .llseek = seq_lseek,
190 .release = single_release, 190 .release = single_release,
191}; 191};
192 192
193static struct file_operations acpi_thermal_trip_fops = { 193static const struct file_operations acpi_thermal_trip_fops = {
194 .open = acpi_thermal_trip_open_fs, 194 .open = acpi_thermal_trip_open_fs,
195 .read = seq_read, 195 .read = seq_read,
196 .write = acpi_thermal_write_trip_points, 196 .write = acpi_thermal_write_trip_points,
@@ -198,7 +198,7 @@ static struct file_operations acpi_thermal_trip_fops = {
198 .release = single_release, 198 .release = single_release,
199}; 199};
200 200
201static struct file_operations acpi_thermal_cooling_fops = { 201static const struct file_operations acpi_thermal_cooling_fops = {
202 .open = acpi_thermal_cooling_open_fs, 202 .open = acpi_thermal_cooling_open_fs,
203 .read = seq_read, 203 .read = seq_read,
204 .write = acpi_thermal_write_cooling_mode, 204 .write = acpi_thermal_write_cooling_mode,
@@ -206,7 +206,7 @@ static struct file_operations acpi_thermal_cooling_fops = {
206 .release = single_release, 206 .release = single_release,
207}; 207};
208 208
209static struct file_operations acpi_thermal_polling_fops = { 209static const struct file_operations acpi_thermal_polling_fops = {
210 .open = acpi_thermal_polling_open_fs, 210 .open = acpi_thermal_polling_open_fs,
211 .read = seq_read, 211 .read = seq_read,
212 .write = acpi_thermal_write_polling, 212 .write = acpi_thermal_write_polling,
@@ -222,51 +222,48 @@ static int acpi_thermal_get_temperature(struct acpi_thermal *tz)
222{ 222{
223 acpi_status status = AE_OK; 223 acpi_status status = AE_OK;
224 224
225 ACPI_FUNCTION_TRACE("acpi_thermal_get_temperature");
226 225
227 if (!tz) 226 if (!tz)
228 return_VALUE(-EINVAL); 227 return -EINVAL;
229 228
230 tz->last_temperature = tz->temperature; 229 tz->last_temperature = tz->temperature;
231 230
232 status = 231 status =
233 acpi_evaluate_integer(tz->handle, "_TMP", NULL, &tz->temperature); 232 acpi_evaluate_integer(tz->device->handle, "_TMP", NULL, &tz->temperature);
234 if (ACPI_FAILURE(status)) 233 if (ACPI_FAILURE(status))
235 return_VALUE(-ENODEV); 234 return -ENODEV;
236 235
237 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Temperature is %lu dK\n", 236 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Temperature is %lu dK\n",
238 tz->temperature)); 237 tz->temperature));
239 238
240 return_VALUE(0); 239 return 0;
241} 240}
242 241
243static int acpi_thermal_get_polling_frequency(struct acpi_thermal *tz) 242static int acpi_thermal_get_polling_frequency(struct acpi_thermal *tz)
244{ 243{
245 acpi_status status = AE_OK; 244 acpi_status status = AE_OK;
246 245
247 ACPI_FUNCTION_TRACE("acpi_thermal_get_polling_frequency");
248 246
249 if (!tz) 247 if (!tz)
250 return_VALUE(-EINVAL); 248 return -EINVAL;
251 249
252 status = 250 status =
253 acpi_evaluate_integer(tz->handle, "_TZP", NULL, 251 acpi_evaluate_integer(tz->device->handle, "_TZP", NULL,
254 &tz->polling_frequency); 252 &tz->polling_frequency);
255 if (ACPI_FAILURE(status)) 253 if (ACPI_FAILURE(status))
256 return_VALUE(-ENODEV); 254 return -ENODEV;
257 255
258 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Polling frequency is %lu dS\n", 256 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Polling frequency is %lu dS\n",
259 tz->polling_frequency)); 257 tz->polling_frequency));
260 258
261 return_VALUE(0); 259 return 0;
262} 260}
263 261
264static int acpi_thermal_set_polling(struct acpi_thermal *tz, int seconds) 262static int acpi_thermal_set_polling(struct acpi_thermal *tz, int seconds)
265{ 263{
266 ACPI_FUNCTION_TRACE("acpi_thermal_set_polling");
267 264
268 if (!tz) 265 if (!tz)
269 return_VALUE(-EINVAL); 266 return -EINVAL;
270 267
271 tz->polling_frequency = seconds * 10; /* Convert value to deci-seconds */ 268 tz->polling_frequency = seconds * 10; /* Convert value to deci-seconds */
272 269
@@ -274,7 +271,7 @@ static int acpi_thermal_set_polling(struct acpi_thermal *tz, int seconds)
274 "Polling frequency set to %lu seconds\n", 271 "Polling frequency set to %lu seconds\n",
275 tz->polling_frequency)); 272 tz->polling_frequency));
276 273
277 return_VALUE(0); 274 return 0;
278} 275}
279 276
280static int acpi_thermal_set_cooling_mode(struct acpi_thermal *tz, int mode) 277static int acpi_thermal_set_cooling_mode(struct acpi_thermal *tz, int mode)
@@ -284,29 +281,28 @@ static int acpi_thermal_set_cooling_mode(struct acpi_thermal *tz, int mode)
284 struct acpi_object_list arg_list = { 1, &arg0 }; 281 struct acpi_object_list arg_list = { 1, &arg0 };
285 acpi_handle handle = NULL; 282 acpi_handle handle = NULL;
286 283
287 ACPI_FUNCTION_TRACE("acpi_thermal_set_cooling_mode");
288 284
289 if (!tz) 285 if (!tz)
290 return_VALUE(-EINVAL); 286 return -EINVAL;
291 287
292 status = acpi_get_handle(tz->handle, "_SCP", &handle); 288 status = acpi_get_handle(tz->device->handle, "_SCP", &handle);
293 if (ACPI_FAILURE(status)) { 289 if (ACPI_FAILURE(status)) {
294 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "_SCP not present\n")); 290 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "_SCP not present\n"));
295 return_VALUE(-ENODEV); 291 return -ENODEV;
296 } 292 }
297 293
298 arg0.integer.value = mode; 294 arg0.integer.value = mode;
299 295
300 status = acpi_evaluate_object(handle, NULL, &arg_list, NULL); 296 status = acpi_evaluate_object(handle, NULL, &arg_list, NULL);
301 if (ACPI_FAILURE(status)) 297 if (ACPI_FAILURE(status))
302 return_VALUE(-ENODEV); 298 return -ENODEV;
303 299
304 tz->cooling_mode = mode; 300 tz->cooling_mode = mode;
305 301
306 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Cooling mode [%s]\n", 302 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Cooling mode [%s]\n",
307 mode ? "passive" : "active")); 303 mode ? "passive" : "active"));
308 304
309 return_VALUE(0); 305 return 0;
310} 306}
311 307
312static int acpi_thermal_get_trip_points(struct acpi_thermal *tz) 308static int acpi_thermal_get_trip_points(struct acpi_thermal *tz)
@@ -314,19 +310,18 @@ static int acpi_thermal_get_trip_points(struct acpi_thermal *tz)
314 acpi_status status = AE_OK; 310 acpi_status status = AE_OK;
315 int i = 0; 311 int i = 0;
316 312
317 ACPI_FUNCTION_TRACE("acpi_thermal_get_trip_points");
318 313
319 if (!tz) 314 if (!tz)
320 return_VALUE(-EINVAL); 315 return -EINVAL;
321 316
322 /* Critical Shutdown (required) */ 317 /* Critical Shutdown (required) */
323 318
324 status = acpi_evaluate_integer(tz->handle, "_CRT", NULL, 319 status = acpi_evaluate_integer(tz->device->handle, "_CRT", NULL,
325 &tz->trips.critical.temperature); 320 &tz->trips.critical.temperature);
326 if (ACPI_FAILURE(status)) { 321 if (ACPI_FAILURE(status)) {
327 tz->trips.critical.flags.valid = 0; 322 tz->trips.critical.flags.valid = 0;
328 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "No critical threshold\n")); 323 ACPI_EXCEPTION((AE_INFO, status, "No critical threshold"));
329 return_VALUE(-ENODEV); 324 return -ENODEV;
330 } else { 325 } else {
331 tz->trips.critical.flags.valid = 1; 326 tz->trips.critical.flags.valid = 1;
332 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 327 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
@@ -337,7 +332,7 @@ static int acpi_thermal_get_trip_points(struct acpi_thermal *tz)
337 /* Critical Sleep (optional) */ 332 /* Critical Sleep (optional) */
338 333
339 status = 334 status =
340 acpi_evaluate_integer(tz->handle, "_HOT", NULL, 335 acpi_evaluate_integer(tz->device->handle, "_HOT", NULL,
341 &tz->trips.hot.temperature); 336 &tz->trips.hot.temperature);
342 if (ACPI_FAILURE(status)) { 337 if (ACPI_FAILURE(status)) {
343 tz->trips.hot.flags.valid = 0; 338 tz->trips.hot.flags.valid = 0;
@@ -351,7 +346,7 @@ static int acpi_thermal_get_trip_points(struct acpi_thermal *tz)
351 /* Passive: Processors (optional) */ 346 /* Passive: Processors (optional) */
352 347
353 status = 348 status =
354 acpi_evaluate_integer(tz->handle, "_PSV", NULL, 349 acpi_evaluate_integer(tz->device->handle, "_PSV", NULL,
355 &tz->trips.passive.temperature); 350 &tz->trips.passive.temperature);
356 if (ACPI_FAILURE(status)) { 351 if (ACPI_FAILURE(status)) {
357 tz->trips.passive.flags.valid = 0; 352 tz->trips.passive.flags.valid = 0;
@@ -360,32 +355,31 @@ static int acpi_thermal_get_trip_points(struct acpi_thermal *tz)
360 tz->trips.passive.flags.valid = 1; 355 tz->trips.passive.flags.valid = 1;
361 356
362 status = 357 status =
363 acpi_evaluate_integer(tz->handle, "_TC1", NULL, 358 acpi_evaluate_integer(tz->device->handle, "_TC1", NULL,
364 &tz->trips.passive.tc1); 359 &tz->trips.passive.tc1);
365 if (ACPI_FAILURE(status)) 360 if (ACPI_FAILURE(status))
366 tz->trips.passive.flags.valid = 0; 361 tz->trips.passive.flags.valid = 0;
367 362
368 status = 363 status =
369 acpi_evaluate_integer(tz->handle, "_TC2", NULL, 364 acpi_evaluate_integer(tz->device->handle, "_TC2", NULL,
370 &tz->trips.passive.tc2); 365 &tz->trips.passive.tc2);
371 if (ACPI_FAILURE(status)) 366 if (ACPI_FAILURE(status))
372 tz->trips.passive.flags.valid = 0; 367 tz->trips.passive.flags.valid = 0;
373 368
374 status = 369 status =
375 acpi_evaluate_integer(tz->handle, "_TSP", NULL, 370 acpi_evaluate_integer(tz->device->handle, "_TSP", NULL,
376 &tz->trips.passive.tsp); 371 &tz->trips.passive.tsp);
377 if (ACPI_FAILURE(status)) 372 if (ACPI_FAILURE(status))
378 tz->trips.passive.flags.valid = 0; 373 tz->trips.passive.flags.valid = 0;
379 374
380 status = 375 status =
381 acpi_evaluate_reference(tz->handle, "_PSL", NULL, 376 acpi_evaluate_reference(tz->device->handle, "_PSL", NULL,
382 &tz->trips.passive.devices); 377 &tz->trips.passive.devices);
383 if (ACPI_FAILURE(status)) 378 if (ACPI_FAILURE(status))
384 tz->trips.passive.flags.valid = 0; 379 tz->trips.passive.flags.valid = 0;
385 380
386 if (!tz->trips.passive.flags.valid) 381 if (!tz->trips.passive.flags.valid)
387 ACPI_DEBUG_PRINT((ACPI_DB_WARN, 382 printk(KERN_WARNING PREFIX "Invalid passive threshold\n");
388 "Invalid passive threshold\n"));
389 else 383 else
390 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 384 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
391 "Found passive threshold [%lu]\n", 385 "Found passive threshold [%lu]\n",
@@ -399,14 +393,14 @@ static int acpi_thermal_get_trip_points(struct acpi_thermal *tz)
399 char name[5] = { '_', 'A', 'C', ('0' + i), '\0' }; 393 char name[5] = { '_', 'A', 'C', ('0' + i), '\0' };
400 394
401 status = 395 status =
402 acpi_evaluate_integer(tz->handle, name, NULL, 396 acpi_evaluate_integer(tz->device->handle, name, NULL,
403 &tz->trips.active[i].temperature); 397 &tz->trips.active[i].temperature);
404 if (ACPI_FAILURE(status)) 398 if (ACPI_FAILURE(status))
405 break; 399 break;
406 400
407 name[2] = 'L'; 401 name[2] = 'L';
408 status = 402 status =
409 acpi_evaluate_reference(tz->handle, name, NULL, 403 acpi_evaluate_reference(tz->device->handle, name, NULL,
410 &tz->trips.active[i].devices); 404 &tz->trips.active[i].devices);
411 if (ACPI_SUCCESS(status)) { 405 if (ACPI_SUCCESS(status)) {
412 tz->trips.active[i].flags.valid = 1; 406 tz->trips.active[i].flags.valid = 1;
@@ -414,29 +408,27 @@ static int acpi_thermal_get_trip_points(struct acpi_thermal *tz)
414 "Found active threshold [%d]:[%lu]\n", 408 "Found active threshold [%d]:[%lu]\n",
415 i, tz->trips.active[i].temperature)); 409 i, tz->trips.active[i].temperature));
416 } else 410 } else
417 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 411 ACPI_EXCEPTION((AE_INFO, status,
418 "Invalid active threshold [%d]\n", 412 "Invalid active threshold [%d]", i));
419 i));
420 } 413 }
421 414
422 return_VALUE(0); 415 return 0;
423} 416}
424 417
425static int acpi_thermal_get_devices(struct acpi_thermal *tz) 418static int acpi_thermal_get_devices(struct acpi_thermal *tz)
426{ 419{
427 acpi_status status = AE_OK; 420 acpi_status status = AE_OK;
428 421
429 ACPI_FUNCTION_TRACE("acpi_thermal_get_devices");
430 422
431 if (!tz) 423 if (!tz)
432 return_VALUE(-EINVAL); 424 return -EINVAL;
433 425
434 status = 426 status =
435 acpi_evaluate_reference(tz->handle, "_TZD", NULL, &tz->devices); 427 acpi_evaluate_reference(tz->device->handle, "_TZD", NULL, &tz->devices);
436 if (ACPI_FAILURE(status)) 428 if (ACPI_FAILURE(status))
437 return_VALUE(-ENODEV); 429 return -ENODEV;
438 430
439 return_VALUE(0); 431 return 0;
440} 432}
441 433
442static int acpi_thermal_call_usermode(char *path) 434static int acpi_thermal_call_usermode(char *path)
@@ -444,10 +436,9 @@ static int acpi_thermal_call_usermode(char *path)
444 char *argv[2] = { NULL, NULL }; 436 char *argv[2] = { NULL, NULL };
445 char *envp[3] = { NULL, NULL, NULL }; 437 char *envp[3] = { NULL, NULL, NULL };
446 438
447 ACPI_FUNCTION_TRACE("acpi_thermal_call_usermode");
448 439
449 if (!path) 440 if (!path)
450 return_VALUE(-EINVAL); 441 return -EINVAL;
451 442
452 argv[0] = path; 443 argv[0] = path;
453 444
@@ -457,66 +448,48 @@ static int acpi_thermal_call_usermode(char *path)
457 448
458 call_usermodehelper(argv[0], argv, envp, 0); 449 call_usermodehelper(argv[0], argv, envp, 0);
459 450
460 return_VALUE(0); 451 return 0;
461} 452}
462 453
463static int acpi_thermal_critical(struct acpi_thermal *tz) 454static int acpi_thermal_critical(struct acpi_thermal *tz)
464{ 455{
465 int result = 0;
466 struct acpi_device *device = NULL;
467
468 ACPI_FUNCTION_TRACE("acpi_thermal_critical");
469
470 if (!tz || !tz->trips.critical.flags.valid) 456 if (!tz || !tz->trips.critical.flags.valid)
471 return_VALUE(-EINVAL); 457 return -EINVAL;
472 458
473 if (tz->temperature >= tz->trips.critical.temperature) { 459 if (tz->temperature >= tz->trips.critical.temperature) {
474 ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Critical trip point\n")); 460 printk(KERN_WARNING PREFIX "Critical trip point\n");
475 tz->trips.critical.flags.enabled = 1; 461 tz->trips.critical.flags.enabled = 1;
476 } else if (tz->trips.critical.flags.enabled) 462 } else if (tz->trips.critical.flags.enabled)
477 tz->trips.critical.flags.enabled = 0; 463 tz->trips.critical.flags.enabled = 0;
478 464
479 result = acpi_bus_get_device(tz->handle, &device);
480 if (result)
481 return_VALUE(result);
482
483 printk(KERN_EMERG 465 printk(KERN_EMERG
484 "Critical temperature reached (%ld C), shutting down.\n", 466 "Critical temperature reached (%ld C), shutting down.\n",
485 KELVIN_TO_CELSIUS(tz->temperature)); 467 KELVIN_TO_CELSIUS(tz->temperature));
486 acpi_bus_generate_event(device, ACPI_THERMAL_NOTIFY_CRITICAL, 468 acpi_bus_generate_event(tz->device, ACPI_THERMAL_NOTIFY_CRITICAL,
487 tz->trips.critical.flags.enabled); 469 tz->trips.critical.flags.enabled);
488 470
489 acpi_thermal_call_usermode(ACPI_THERMAL_PATH_POWEROFF); 471 acpi_thermal_call_usermode(ACPI_THERMAL_PATH_POWEROFF);
490 472
491 return_VALUE(0); 473 return 0;
492} 474}
493 475
494static int acpi_thermal_hot(struct acpi_thermal *tz) 476static int acpi_thermal_hot(struct acpi_thermal *tz)
495{ 477{
496 int result = 0;
497 struct acpi_device *device = NULL;
498
499 ACPI_FUNCTION_TRACE("acpi_thermal_hot");
500
501 if (!tz || !tz->trips.hot.flags.valid) 478 if (!tz || !tz->trips.hot.flags.valid)
502 return_VALUE(-EINVAL); 479 return -EINVAL;
503 480
504 if (tz->temperature >= tz->trips.hot.temperature) { 481 if (tz->temperature >= tz->trips.hot.temperature) {
505 ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Hot trip point\n")); 482 printk(KERN_WARNING PREFIX "Hot trip point\n");
506 tz->trips.hot.flags.enabled = 1; 483 tz->trips.hot.flags.enabled = 1;
507 } else if (tz->trips.hot.flags.enabled) 484 } else if (tz->trips.hot.flags.enabled)
508 tz->trips.hot.flags.enabled = 0; 485 tz->trips.hot.flags.enabled = 0;
509 486
510 result = acpi_bus_get_device(tz->handle, &device); 487 acpi_bus_generate_event(tz->device, ACPI_THERMAL_NOTIFY_HOT,
511 if (result)
512 return_VALUE(result);
513
514 acpi_bus_generate_event(device, ACPI_THERMAL_NOTIFY_HOT,
515 tz->trips.hot.flags.enabled); 488 tz->trips.hot.flags.enabled);
516 489
517 /* TBD: Call user-mode "sleep(S4)" function */ 490 /* TBD: Call user-mode "sleep(S4)" function */
518 491
519 return_VALUE(0); 492 return 0;
520} 493}
521 494
522static void acpi_thermal_passive(struct acpi_thermal *tz) 495static void acpi_thermal_passive(struct acpi_thermal *tz)
@@ -526,7 +499,6 @@ static void acpi_thermal_passive(struct acpi_thermal *tz)
526 int trend = 0; 499 int trend = 0;
527 int i = 0; 500 int i = 0;
528 501
529 ACPI_FUNCTION_TRACE("acpi_thermal_passive");
530 502
531 if (!tz || !tz->trips.passive.flags.valid) 503 if (!tz || !tz->trips.passive.flags.valid)
532 return; 504 return;
@@ -615,7 +587,6 @@ static void acpi_thermal_active(struct acpi_thermal *tz)
615 int j = 0; 587 int j = 0;
616 unsigned long maxtemp = 0; 588 unsigned long maxtemp = 0;
617 589
618 ACPI_FUNCTION_TRACE("acpi_thermal_active");
619 590
620 if (!tz) 591 if (!tz)
621 return; 592 return;
@@ -642,10 +613,10 @@ static void acpi_thermal_active(struct acpi_thermal *tz)
642 handles[j], 613 handles[j],
643 ACPI_STATE_D0); 614 ACPI_STATE_D0);
644 if (result) { 615 if (result) {
645 ACPI_DEBUG_PRINT((ACPI_DB_WARN, 616 printk(KERN_WARNING PREFIX
646 "Unable to turn cooling device [%p] 'on'\n", 617 "Unable to turn cooling device [%p] 'on'\n",
647 active->devices. 618 active->devices.
648 handles[j])); 619 handles[j]);
649 continue; 620 continue;
650 } 621 }
651 active->flags.enabled = 1; 622 active->flags.enabled = 1;
@@ -667,9 +638,9 @@ static void acpi_thermal_active(struct acpi_thermal *tz)
667 result = acpi_bus_set_power(active->devices.handles[j], 638 result = acpi_bus_set_power(active->devices.handles[j],
668 ACPI_STATE_D3); 639 ACPI_STATE_D3);
669 if (result) { 640 if (result) {
670 ACPI_DEBUG_PRINT((ACPI_DB_WARN, 641 printk(KERN_WARNING PREFIX
671 "Unable to turn cooling device [%p] 'off'\n", 642 "Unable to turn cooling device [%p] 'off'\n",
672 active->devices.handles[j])); 643 active->devices.handles[j]);
673 continue; 644 continue;
674 } 645 }
675 active->flags.enabled = 0; 646 active->flags.enabled = 0;
@@ -697,18 +668,17 @@ static void acpi_thermal_check(void *data)
697 int i = 0; 668 int i = 0;
698 struct acpi_thermal_state state; 669 struct acpi_thermal_state state;
699 670
700 ACPI_FUNCTION_TRACE("acpi_thermal_check");
701 671
702 if (!tz) { 672 if (!tz) {
703 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid (NULL) context.\n")); 673 printk(KERN_ERR PREFIX "Invalid (NULL) context\n");
704 return_VOID; 674 return;
705 } 675 }
706 676
707 state = tz->state; 677 state = tz->state;
708 678
709 result = acpi_thermal_get_temperature(tz); 679 result = acpi_thermal_get_temperature(tz);
710 if (result) 680 if (result)
711 return_VOID; 681 return;
712 682
713 memset(&tz->state, 0, sizeof(tz->state)); 683 memset(&tz->state, 0, sizeof(tz->state));
714 684
@@ -797,7 +767,7 @@ static void acpi_thermal_check(void *data)
797 } 767 }
798 } 768 }
799 769
800 return_VOID; 770 return;
801} 771}
802 772
803/* -------------------------------------------------------------------------- 773/* --------------------------------------------------------------------------
@@ -810,7 +780,6 @@ static int acpi_thermal_state_seq_show(struct seq_file *seq, void *offset)
810{ 780{
811 struct acpi_thermal *tz = (struct acpi_thermal *)seq->private; 781 struct acpi_thermal *tz = (struct acpi_thermal *)seq->private;
812 782
813 ACPI_FUNCTION_TRACE("acpi_thermal_state_seq_show");
814 783
815 if (!tz) 784 if (!tz)
816 goto end; 785 goto end;
@@ -833,7 +802,7 @@ static int acpi_thermal_state_seq_show(struct seq_file *seq, void *offset)
833 } 802 }
834 803
835 end: 804 end:
836 return_VALUE(0); 805 return 0;
837} 806}
838 807
839static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file) 808static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file)
@@ -846,7 +815,6 @@ static int acpi_thermal_temp_seq_show(struct seq_file *seq, void *offset)
846 int result = 0; 815 int result = 0;
847 struct acpi_thermal *tz = (struct acpi_thermal *)seq->private; 816 struct acpi_thermal *tz = (struct acpi_thermal *)seq->private;
848 817
849 ACPI_FUNCTION_TRACE("acpi_thermal_temp_seq_show");
850 818
851 if (!tz) 819 if (!tz)
852 goto end; 820 goto end;
@@ -859,7 +827,7 @@ static int acpi_thermal_temp_seq_show(struct seq_file *seq, void *offset)
859 KELVIN_TO_CELSIUS(tz->temperature)); 827 KELVIN_TO_CELSIUS(tz->temperature));
860 828
861 end: 829 end:
862 return_VALUE(0); 830 return 0;
863} 831}
864 832
865static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file) 833static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file)
@@ -873,7 +841,6 @@ static int acpi_thermal_trip_seq_show(struct seq_file *seq, void *offset)
873 int i = 0; 841 int i = 0;
874 int j = 0; 842 int j = 0;
875 843
876 ACPI_FUNCTION_TRACE("acpi_thermal_trip_seq_show");
877 844
878 if (!tz) 845 if (!tz)
879 goto end; 846 goto end;
@@ -913,7 +880,7 @@ static int acpi_thermal_trip_seq_show(struct seq_file *seq, void *offset)
913 } 880 }
914 881
915 end: 882 end:
916 return_VALUE(0); 883 return 0;
917} 884}
918 885
919static int acpi_thermal_trip_open_fs(struct inode *inode, struct file *file) 886static int acpi_thermal_trip_open_fs(struct inode *inode, struct file *file)
@@ -934,28 +901,25 @@ acpi_thermal_write_trip_points(struct file *file,
934 int *active; 901 int *active;
935 int i = 0; 902 int i = 0;
936 903
937 ACPI_FUNCTION_TRACE("acpi_thermal_write_trip_points");
938 904
939 limit_string = kmalloc(ACPI_THERMAL_MAX_LIMIT_STR_LEN, GFP_KERNEL); 905 limit_string = kmalloc(ACPI_THERMAL_MAX_LIMIT_STR_LEN, GFP_KERNEL);
940 if (!limit_string) 906 if (!limit_string)
941 return_VALUE(-ENOMEM); 907 return -ENOMEM;
942 908
943 memset(limit_string, 0, ACPI_THERMAL_MAX_LIMIT_STR_LEN); 909 memset(limit_string, 0, ACPI_THERMAL_MAX_LIMIT_STR_LEN);
944 910
945 active = kmalloc(ACPI_THERMAL_MAX_ACTIVE * sizeof(int), GFP_KERNEL); 911 active = kmalloc(ACPI_THERMAL_MAX_ACTIVE * sizeof(int), GFP_KERNEL);
946 if (!active) { 912 if (!active) {
947 kfree(limit_string); 913 kfree(limit_string);
948 return_VALUE(-ENOMEM); 914 return -ENOMEM;
949 } 915 }
950 916
951 if (!tz || (count > ACPI_THERMAL_MAX_LIMIT_STR_LEN - 1)) { 917 if (!tz || (count > ACPI_THERMAL_MAX_LIMIT_STR_LEN - 1)) {
952 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid argument\n"));
953 count = -EINVAL; 918 count = -EINVAL;
954 goto end; 919 goto end;
955 } 920 }
956 921
957 if (copy_from_user(limit_string, buffer, count)) { 922 if (copy_from_user(limit_string, buffer, count)) {
958 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid data\n"));
959 count = -EFAULT; 923 count = -EFAULT;
960 goto end; 924 goto end;
961 } 925 }
@@ -968,7 +932,6 @@ acpi_thermal_write_trip_points(struct file *file,
968 &active[5], &active[6], &active[7], &active[8], 932 &active[5], &active[6], &active[7], &active[8],
969 &active[9]); 933 &active[9]);
970 if (!(num >= 5 && num < (ACPI_THERMAL_MAX_ACTIVE + 3))) { 934 if (!(num >= 5 && num < (ACPI_THERMAL_MAX_ACTIVE + 3))) {
971 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid data format\n"));
972 count = -EINVAL; 935 count = -EINVAL;
973 goto end; 936 goto end;
974 } 937 }
@@ -985,14 +948,13 @@ acpi_thermal_write_trip_points(struct file *file,
985 end: 948 end:
986 kfree(active); 949 kfree(active);
987 kfree(limit_string); 950 kfree(limit_string);
988 return_VALUE(count); 951 return count;
989} 952}
990 953
991static int acpi_thermal_cooling_seq_show(struct seq_file *seq, void *offset) 954static int acpi_thermal_cooling_seq_show(struct seq_file *seq, void *offset)
992{ 955{
993 struct acpi_thermal *tz = (struct acpi_thermal *)seq->private; 956 struct acpi_thermal *tz = (struct acpi_thermal *)seq->private;
994 957
995 ACPI_FUNCTION_TRACE("acpi_thermal_cooling_seq_show");
996 958
997 if (!tz) 959 if (!tz)
998 goto end; 960 goto end;
@@ -1008,7 +970,7 @@ static int acpi_thermal_cooling_seq_show(struct seq_file *seq, void *offset)
1008 tz->cooling_mode ? "passive" : "active"); 970 tz->cooling_mode ? "passive" : "active");
1009 971
1010 end: 972 end:
1011 return_VALUE(0); 973 return 0;
1012} 974}
1013 975
1014static int acpi_thermal_cooling_open_fs(struct inode *inode, struct file *file) 976static int acpi_thermal_cooling_open_fs(struct inode *inode, struct file *file)
@@ -1027,16 +989,15 @@ acpi_thermal_write_cooling_mode(struct file *file,
1027 int result = 0; 989 int result = 0;
1028 char mode_string[12] = { '\0' }; 990 char mode_string[12] = { '\0' };
1029 991
1030 ACPI_FUNCTION_TRACE("acpi_thermal_write_cooling_mode");
1031 992
1032 if (!tz || (count > sizeof(mode_string) - 1)) 993 if (!tz || (count > sizeof(mode_string) - 1))
1033 return_VALUE(-EINVAL); 994 return -EINVAL;
1034 995
1035 if (!tz->flags.cooling_mode) 996 if (!tz->flags.cooling_mode)
1036 return_VALUE(-ENODEV); 997 return -ENODEV;
1037 998
1038 if (copy_from_user(mode_string, buffer, count)) 999 if (copy_from_user(mode_string, buffer, count))
1039 return_VALUE(-EFAULT); 1000 return -EFAULT;
1040 1001
1041 mode_string[count] = '\0'; 1002 mode_string[count] = '\0';
1042 1003
@@ -1044,18 +1005,17 @@ acpi_thermal_write_cooling_mode(struct file *file,
1044 simple_strtoul(mode_string, NULL, 1005 simple_strtoul(mode_string, NULL,
1045 0)); 1006 0));
1046 if (result) 1007 if (result)
1047 return_VALUE(result); 1008 return result;
1048 1009
1049 acpi_thermal_check(tz); 1010 acpi_thermal_check(tz);
1050 1011
1051 return_VALUE(count); 1012 return count;
1052} 1013}
1053 1014
1054static int acpi_thermal_polling_seq_show(struct seq_file *seq, void *offset) 1015static int acpi_thermal_polling_seq_show(struct seq_file *seq, void *offset)
1055{ 1016{
1056 struct acpi_thermal *tz = (struct acpi_thermal *)seq->private; 1017 struct acpi_thermal *tz = (struct acpi_thermal *)seq->private;
1057 1018
1058 ACPI_FUNCTION_TRACE("acpi_thermal_polling_seq_show");
1059 1019
1060 if (!tz) 1020 if (!tz)
1061 goto end; 1021 goto end;
@@ -1069,7 +1029,7 @@ static int acpi_thermal_polling_seq_show(struct seq_file *seq, void *offset)
1069 (tz->polling_frequency / 10)); 1029 (tz->polling_frequency / 10));
1070 1030
1071 end: 1031 end:
1072 return_VALUE(0); 1032 return 0;
1073} 1033}
1074 1034
1075static int acpi_thermal_polling_open_fs(struct inode *inode, struct file *file) 1035static int acpi_thermal_polling_open_fs(struct inode *inode, struct file *file)
@@ -1089,13 +1049,12 @@ acpi_thermal_write_polling(struct file *file,
1089 char polling_string[12] = { '\0' }; 1049 char polling_string[12] = { '\0' };
1090 int seconds = 0; 1050 int seconds = 0;
1091 1051
1092 ACPI_FUNCTION_TRACE("acpi_thermal_write_polling");
1093 1052
1094 if (!tz || (count > sizeof(polling_string) - 1)) 1053 if (!tz || (count > sizeof(polling_string) - 1))
1095 return_VALUE(-EINVAL); 1054 return -EINVAL;
1096 1055
1097 if (copy_from_user(polling_string, buffer, count)) 1056 if (copy_from_user(polling_string, buffer, count))
1098 return_VALUE(-EFAULT); 1057 return -EFAULT;
1099 1058
1100 polling_string[count] = '\0'; 1059 polling_string[count] = '\0';
1101 1060
@@ -1103,24 +1062,23 @@ acpi_thermal_write_polling(struct file *file,
1103 1062
1104 result = acpi_thermal_set_polling(tz, seconds); 1063 result = acpi_thermal_set_polling(tz, seconds);
1105 if (result) 1064 if (result)
1106 return_VALUE(result); 1065 return result;
1107 1066
1108 acpi_thermal_check(tz); 1067 acpi_thermal_check(tz);
1109 1068
1110 return_VALUE(count); 1069 return count;
1111} 1070}
1112 1071
1113static int acpi_thermal_add_fs(struct acpi_device *device) 1072static int acpi_thermal_add_fs(struct acpi_device *device)
1114{ 1073{
1115 struct proc_dir_entry *entry = NULL; 1074 struct proc_dir_entry *entry = NULL;
1116 1075
1117 ACPI_FUNCTION_TRACE("acpi_thermal_add_fs");
1118 1076
1119 if (!acpi_device_dir(device)) { 1077 if (!acpi_device_dir(device)) {
1120 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), 1078 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
1121 acpi_thermal_dir); 1079 acpi_thermal_dir);
1122 if (!acpi_device_dir(device)) 1080 if (!acpi_device_dir(device))
1123 return_VALUE(-ENODEV); 1081 return -ENODEV;
1124 acpi_device_dir(device)->owner = THIS_MODULE; 1082 acpi_device_dir(device)->owner = THIS_MODULE;
1125 } 1083 }
1126 1084
@@ -1128,9 +1086,7 @@ static int acpi_thermal_add_fs(struct acpi_device *device)
1128 entry = create_proc_entry(ACPI_THERMAL_FILE_STATE, 1086 entry = create_proc_entry(ACPI_THERMAL_FILE_STATE,
1129 S_IRUGO, acpi_device_dir(device)); 1087 S_IRUGO, acpi_device_dir(device));
1130 if (!entry) 1088 if (!entry)
1131 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1089 return -ENODEV;
1132 "Unable to create '%s' fs entry\n",
1133 ACPI_THERMAL_FILE_STATE));
1134 else { 1090 else {
1135 entry->proc_fops = &acpi_thermal_state_fops; 1091 entry->proc_fops = &acpi_thermal_state_fops;
1136 entry->data = acpi_driver_data(device); 1092 entry->data = acpi_driver_data(device);
@@ -1141,9 +1097,7 @@ static int acpi_thermal_add_fs(struct acpi_device *device)
1141 entry = create_proc_entry(ACPI_THERMAL_FILE_TEMPERATURE, 1097 entry = create_proc_entry(ACPI_THERMAL_FILE_TEMPERATURE,
1142 S_IRUGO, acpi_device_dir(device)); 1098 S_IRUGO, acpi_device_dir(device));
1143 if (!entry) 1099 if (!entry)
1144 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1100 return -ENODEV;
1145 "Unable to create '%s' fs entry\n",
1146 ACPI_THERMAL_FILE_TEMPERATURE));
1147 else { 1101 else {
1148 entry->proc_fops = &acpi_thermal_temp_fops; 1102 entry->proc_fops = &acpi_thermal_temp_fops;
1149 entry->data = acpi_driver_data(device); 1103 entry->data = acpi_driver_data(device);
@@ -1155,9 +1109,7 @@ static int acpi_thermal_add_fs(struct acpi_device *device)
1155 S_IFREG | S_IRUGO | S_IWUSR, 1109 S_IFREG | S_IRUGO | S_IWUSR,
1156 acpi_device_dir(device)); 1110 acpi_device_dir(device));
1157 if (!entry) 1111 if (!entry)
1158 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1112 return -ENODEV;
1159 "Unable to create '%s' fs entry\n",
1160 ACPI_THERMAL_FILE_TRIP_POINTS));
1161 else { 1113 else {
1162 entry->proc_fops = &acpi_thermal_trip_fops; 1114 entry->proc_fops = &acpi_thermal_trip_fops;
1163 entry->data = acpi_driver_data(device); 1115 entry->data = acpi_driver_data(device);
@@ -1169,9 +1121,7 @@ static int acpi_thermal_add_fs(struct acpi_device *device)
1169 S_IFREG | S_IRUGO | S_IWUSR, 1121 S_IFREG | S_IRUGO | S_IWUSR,
1170 acpi_device_dir(device)); 1122 acpi_device_dir(device));
1171 if (!entry) 1123 if (!entry)
1172 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1124 return -ENODEV;
1173 "Unable to create '%s' fs entry\n",
1174 ACPI_THERMAL_FILE_COOLING_MODE));
1175 else { 1125 else {
1176 entry->proc_fops = &acpi_thermal_cooling_fops; 1126 entry->proc_fops = &acpi_thermal_cooling_fops;
1177 entry->data = acpi_driver_data(device); 1127 entry->data = acpi_driver_data(device);
@@ -1183,21 +1133,18 @@ static int acpi_thermal_add_fs(struct acpi_device *device)
1183 S_IFREG | S_IRUGO | S_IWUSR, 1133 S_IFREG | S_IRUGO | S_IWUSR,
1184 acpi_device_dir(device)); 1134 acpi_device_dir(device));
1185 if (!entry) 1135 if (!entry)
1186 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1136 return -ENODEV;
1187 "Unable to create '%s' fs entry\n",
1188 ACPI_THERMAL_FILE_POLLING_FREQ));
1189 else { 1137 else {
1190 entry->proc_fops = &acpi_thermal_polling_fops; 1138 entry->proc_fops = &acpi_thermal_polling_fops;
1191 entry->data = acpi_driver_data(device); 1139 entry->data = acpi_driver_data(device);
1192 entry->owner = THIS_MODULE; 1140 entry->owner = THIS_MODULE;
1193 } 1141 }
1194 1142
1195 return_VALUE(0); 1143 return 0;
1196} 1144}
1197 1145
1198static int acpi_thermal_remove_fs(struct acpi_device *device) 1146static int acpi_thermal_remove_fs(struct acpi_device *device)
1199{ 1147{
1200 ACPI_FUNCTION_TRACE("acpi_thermal_remove_fs");
1201 1148
1202 if (acpi_device_dir(device)) { 1149 if (acpi_device_dir(device)) {
1203 remove_proc_entry(ACPI_THERMAL_FILE_POLLING_FREQ, 1150 remove_proc_entry(ACPI_THERMAL_FILE_POLLING_FREQ,
@@ -1214,7 +1161,7 @@ static int acpi_thermal_remove_fs(struct acpi_device *device)
1214 acpi_device_dir(device) = NULL; 1161 acpi_device_dir(device) = NULL;
1215 } 1162 }
1216 1163
1217 return_VALUE(0); 1164 return 0;
1218} 1165}
1219 1166
1220/* -------------------------------------------------------------------------- 1167/* --------------------------------------------------------------------------
@@ -1226,13 +1173,11 @@ static void acpi_thermal_notify(acpi_handle handle, u32 event, void *data)
1226 struct acpi_thermal *tz = (struct acpi_thermal *)data; 1173 struct acpi_thermal *tz = (struct acpi_thermal *)data;
1227 struct acpi_device *device = NULL; 1174 struct acpi_device *device = NULL;
1228 1175
1229 ACPI_FUNCTION_TRACE("acpi_thermal_notify");
1230 1176
1231 if (!tz) 1177 if (!tz)
1232 return_VOID; 1178 return;
1233 1179
1234 if (acpi_bus_get_device(tz->handle, &device)) 1180 device = tz->device;
1235 return_VOID;
1236 1181
1237 switch (event) { 1182 switch (event) {
1238 case ACPI_THERMAL_NOTIFY_TEMPERATURE: 1183 case ACPI_THERMAL_NOTIFY_TEMPERATURE:
@@ -1254,27 +1199,26 @@ static void acpi_thermal_notify(acpi_handle handle, u32 event, void *data)
1254 break; 1199 break;
1255 } 1200 }
1256 1201
1257 return_VOID; 1202 return;
1258} 1203}
1259 1204
1260static int acpi_thermal_get_info(struct acpi_thermal *tz) 1205static int acpi_thermal_get_info(struct acpi_thermal *tz)
1261{ 1206{
1262 int result = 0; 1207 int result = 0;
1263 1208
1264 ACPI_FUNCTION_TRACE("acpi_thermal_get_info");
1265 1209
1266 if (!tz) 1210 if (!tz)
1267 return_VALUE(-EINVAL); 1211 return -EINVAL;
1268 1212
1269 /* Get temperature [_TMP] (required) */ 1213 /* Get temperature [_TMP] (required) */
1270 result = acpi_thermal_get_temperature(tz); 1214 result = acpi_thermal_get_temperature(tz);
1271 if (result) 1215 if (result)
1272 return_VALUE(result); 1216 return result;
1273 1217
1274 /* Get trip points [_CRT, _PSV, etc.] (required) */ 1218 /* Get trip points [_CRT, _PSV, etc.] (required) */
1275 result = acpi_thermal_get_trip_points(tz); 1219 result = acpi_thermal_get_trip_points(tz);
1276 if (result) 1220 if (result)
1277 return_VALUE(result); 1221 return result;
1278 1222
1279 /* Set the cooling mode [_SCP] to active cooling (default) */ 1223 /* Set the cooling mode [_SCP] to active cooling (default) */
1280 result = acpi_thermal_set_cooling_mode(tz, ACPI_THERMAL_MODE_ACTIVE); 1224 result = acpi_thermal_set_cooling_mode(tz, ACPI_THERMAL_MODE_ACTIVE);
@@ -1314,7 +1258,7 @@ static int acpi_thermal_get_info(struct acpi_thermal *tz)
1314 if (!result) 1258 if (!result)
1315 tz->flags.devices = 1; 1259 tz->flags.devices = 1;
1316 1260
1317 return_VALUE(0); 1261 return 0;
1318} 1262}
1319 1263
1320static int acpi_thermal_add(struct acpi_device *device) 1264static int acpi_thermal_add(struct acpi_device *device)
@@ -1323,17 +1267,16 @@ static int acpi_thermal_add(struct acpi_device *device)
1323 acpi_status status = AE_OK; 1267 acpi_status status = AE_OK;
1324 struct acpi_thermal *tz = NULL; 1268 struct acpi_thermal *tz = NULL;
1325 1269
1326 ACPI_FUNCTION_TRACE("acpi_thermal_add");
1327 1270
1328 if (!device) 1271 if (!device)
1329 return_VALUE(-EINVAL); 1272 return -EINVAL;
1330 1273
1331 tz = kmalloc(sizeof(struct acpi_thermal), GFP_KERNEL); 1274 tz = kmalloc(sizeof(struct acpi_thermal), GFP_KERNEL);
1332 if (!tz) 1275 if (!tz)
1333 return_VALUE(-ENOMEM); 1276 return -ENOMEM;
1334 memset(tz, 0, sizeof(struct acpi_thermal)); 1277 memset(tz, 0, sizeof(struct acpi_thermal));
1335 1278
1336 tz->handle = device->handle; 1279 tz->device = device;
1337 strcpy(tz->name, device->pnp.bus_id); 1280 strcpy(tz->name, device->pnp.bus_id);
1338 strcpy(acpi_device_name(device), ACPI_THERMAL_DEVICE_NAME); 1281 strcpy(acpi_device_name(device), ACPI_THERMAL_DEVICE_NAME);
1339 strcpy(acpi_device_class(device), ACPI_THERMAL_CLASS); 1282 strcpy(acpi_device_class(device), ACPI_THERMAL_CLASS);
@@ -1351,12 +1294,10 @@ static int acpi_thermal_add(struct acpi_device *device)
1351 1294
1352 acpi_thermal_check(tz); 1295 acpi_thermal_check(tz);
1353 1296
1354 status = acpi_install_notify_handler(tz->handle, 1297 status = acpi_install_notify_handler(device->handle,
1355 ACPI_DEVICE_NOTIFY, 1298 ACPI_DEVICE_NOTIFY,
1356 acpi_thermal_notify, tz); 1299 acpi_thermal_notify, tz);
1357 if (ACPI_FAILURE(status)) { 1300 if (ACPI_FAILURE(status)) {
1358 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1359 "Error installing notify handler\n"));
1360 result = -ENODEV; 1301 result = -ENODEV;
1361 goto end; 1302 goto end;
1362 } 1303 }
@@ -1371,7 +1312,7 @@ static int acpi_thermal_add(struct acpi_device *device)
1371 kfree(tz); 1312 kfree(tz);
1372 } 1313 }
1373 1314
1374 return_VALUE(result); 1315 return result;
1375} 1316}
1376 1317
1377static int acpi_thermal_remove(struct acpi_device *device, int type) 1318static int acpi_thermal_remove(struct acpi_device *device, int type)
@@ -1379,10 +1320,9 @@ static int acpi_thermal_remove(struct acpi_device *device, int type)
1379 acpi_status status = AE_OK; 1320 acpi_status status = AE_OK;
1380 struct acpi_thermal *tz = NULL; 1321 struct acpi_thermal *tz = NULL;
1381 1322
1382 ACPI_FUNCTION_TRACE("acpi_thermal_remove");
1383 1323
1384 if (!device || !acpi_driver_data(device)) 1324 if (!device || !acpi_driver_data(device))
1385 return_VALUE(-EINVAL); 1325 return -EINVAL;
1386 1326
1387 tz = (struct acpi_thermal *)acpi_driver_data(device); 1327 tz = (struct acpi_thermal *)acpi_driver_data(device);
1388 1328
@@ -1395,12 +1335,9 @@ static int acpi_thermal_remove(struct acpi_device *device, int type)
1395 /* deferred task may reinsert timer */ 1335 /* deferred task may reinsert timer */
1396 del_timer_sync(&(tz->timer)); 1336 del_timer_sync(&(tz->timer));
1397 1337
1398 status = acpi_remove_notify_handler(tz->handle, 1338 status = acpi_remove_notify_handler(device->handle,
1399 ACPI_DEVICE_NOTIFY, 1339 ACPI_DEVICE_NOTIFY,
1400 acpi_thermal_notify); 1340 acpi_thermal_notify);
1401 if (ACPI_FAILURE(status))
1402 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1403 "Error removing notify handler\n"));
1404 1341
1405 /* Terminate policy */ 1342 /* Terminate policy */
1406 if (tz->trips.passive.flags.valid && tz->trips.passive.flags.enabled) { 1343 if (tz->trips.passive.flags.valid && tz->trips.passive.flags.enabled) {
@@ -1416,19 +1353,34 @@ static int acpi_thermal_remove(struct acpi_device *device, int type)
1416 acpi_thermal_remove_fs(device); 1353 acpi_thermal_remove_fs(device);
1417 1354
1418 kfree(tz); 1355 kfree(tz);
1419 return_VALUE(0); 1356 return 0;
1420} 1357}
1421 1358
1422static int acpi_thermal_resume(struct acpi_device *device, int state) 1359static int acpi_thermal_resume(struct acpi_device *device, int state)
1423{ 1360{
1424 struct acpi_thermal *tz = NULL; 1361 struct acpi_thermal *tz = NULL;
1362 int i;
1425 1363
1426 if (!device || !acpi_driver_data(device)) 1364 if (!device || !acpi_driver_data(device))
1427 return_VALUE(-EINVAL); 1365 return -EINVAL;
1428 1366
1429 tz = (struct acpi_thermal *)acpi_driver_data(device); 1367 tz = (struct acpi_thermal *)acpi_driver_data(device);
1430 1368
1431 acpi_thermal_check(tz); 1369 acpi_thermal_get_temperature(tz);
1370
1371 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
1372 if (tz->trips.active[i].flags.valid) {
1373 tz->temperature = tz->trips.active[i].temperature;
1374 tz->trips.active[i].flags.enabled = 0;
1375
1376 acpi_thermal_active(tz);
1377
1378 tz->state.active |= tz->trips.active[i].flags.enabled;
1379 tz->state.active_index = i;
1380 }
1381 }
1382
1383 acpi_thermal_check(tz);
1432 1384
1433 return AE_OK; 1385 return AE_OK;
1434} 1386}
@@ -1437,31 +1389,29 @@ static int __init acpi_thermal_init(void)
1437{ 1389{
1438 int result = 0; 1390 int result = 0;
1439 1391
1440 ACPI_FUNCTION_TRACE("acpi_thermal_init");
1441 1392
1442 acpi_thermal_dir = proc_mkdir(ACPI_THERMAL_CLASS, acpi_root_dir); 1393 acpi_thermal_dir = proc_mkdir(ACPI_THERMAL_CLASS, acpi_root_dir);
1443 if (!acpi_thermal_dir) 1394 if (!acpi_thermal_dir)
1444 return_VALUE(-ENODEV); 1395 return -ENODEV;
1445 acpi_thermal_dir->owner = THIS_MODULE; 1396 acpi_thermal_dir->owner = THIS_MODULE;
1446 1397
1447 result = acpi_bus_register_driver(&acpi_thermal_driver); 1398 result = acpi_bus_register_driver(&acpi_thermal_driver);
1448 if (result < 0) { 1399 if (result < 0) {
1449 remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir); 1400 remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir);
1450 return_VALUE(-ENODEV); 1401 return -ENODEV;
1451 } 1402 }
1452 1403
1453 return_VALUE(0); 1404 return 0;
1454} 1405}
1455 1406
1456static void __exit acpi_thermal_exit(void) 1407static void __exit acpi_thermal_exit(void)
1457{ 1408{
1458 ACPI_FUNCTION_TRACE("acpi_thermal_exit");
1459 1409
1460 acpi_bus_unregister_driver(&acpi_thermal_driver); 1410 acpi_bus_unregister_driver(&acpi_thermal_driver);
1461 1411
1462 remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir); 1412 remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir);
1463 1413
1464 return_VOID; 1414 return;
1465} 1415}
1466 1416
1467module_init(acpi_thermal_init); 1417module_init(acpi_thermal_init);
diff --git a/drivers/acpi/utilities/utalloc.c b/drivers/acpi/utilities/utalloc.c
index 7940fc1bd69e..f6cbc0b1bfd0 100644
--- a/drivers/acpi/utilities/utalloc.c
+++ b/drivers/acpi/utilities/utalloc.c
@@ -166,10 +166,10 @@ acpi_status acpi_ut_delete_caches(void)
166 166
167 /* Free memory lists */ 167 /* Free memory lists */
168 168
169 acpi_os_free(acpi_gbl_global_list); 169 ACPI_FREE(acpi_gbl_global_list);
170 acpi_gbl_global_list = NULL; 170 acpi_gbl_global_list = NULL;
171 171
172 acpi_os_free(acpi_gbl_ns_node_list); 172 ACPI_FREE(acpi_gbl_ns_node_list);
173 acpi_gbl_ns_node_list = NULL; 173 acpi_gbl_ns_node_list = NULL;
174#endif 174#endif
175 175
@@ -285,6 +285,7 @@ acpi_ut_initialize_buffer(struct acpi_buffer * buffer,
285 return (status); 285 return (status);
286} 286}
287 287
288#ifdef NOT_USED_BY_LINUX
288/******************************************************************************* 289/*******************************************************************************
289 * 290 *
290 * FUNCTION: acpi_ut_allocate 291 * FUNCTION: acpi_ut_allocate
@@ -360,3 +361,4 @@ void *acpi_ut_allocate_zeroed(acpi_size size,
360 361
361 return (allocation); 362 return (allocation);
362} 363}
364#endif
diff --git a/drivers/acpi/utilities/utcache.c b/drivers/acpi/utilities/utcache.c
index 56270a30718a..1a1f8109159c 100644
--- a/drivers/acpi/utilities/utcache.c
+++ b/drivers/acpi/utilities/utcache.c
@@ -162,7 +162,7 @@ acpi_status acpi_os_delete_cache(struct acpi_memory_list * cache)
162 162
163 /* Now we can delete the cache object */ 163 /* Now we can delete the cache object */
164 164
165 acpi_os_free(cache); 165 ACPI_FREE(cache);
166 return (AE_OK); 166 return (AE_OK);
167} 167}
168 168
diff --git a/drivers/acpi/utilities/utdebug.c b/drivers/acpi/utilities/utdebug.c
index 5ec1cfcc611d..bb1eaf9aa653 100644
--- a/drivers/acpi/utilities/utdebug.c
+++ b/drivers/acpi/utilities/utdebug.c
@@ -47,7 +47,7 @@
47ACPI_MODULE_NAME("utdebug") 47ACPI_MODULE_NAME("utdebug")
48 48
49#ifdef ACPI_DEBUG_OUTPUT 49#ifdef ACPI_DEBUG_OUTPUT
50static u32 acpi_gbl_prev_thread_id = 0xFFFFFFFF; 50static acpi_thread_id acpi_gbl_prev_thread_id;
51static char *acpi_gbl_fn_entry_str = "----Entry"; 51static char *acpi_gbl_fn_entry_str = "----Entry";
52static char *acpi_gbl_fn_exit_str = "----Exit-"; 52static char *acpi_gbl_fn_exit_str = "----Exit-";
53 53
@@ -181,7 +181,7 @@ acpi_ut_debug_print(u32 requested_debug_level,
181 if (ACPI_LV_THREADS & acpi_dbg_level) { 181 if (ACPI_LV_THREADS & acpi_dbg_level) {
182 acpi_os_printf 182 acpi_os_printf
183 ("\n**** Context Switch from TID %X to TID %X ****\n\n", 183 ("\n**** Context Switch from TID %X to TID %X ****\n\n",
184 acpi_gbl_prev_thread_id, thread_id); 184 (u32) acpi_gbl_prev_thread_id, (u32) thread_id);
185 } 185 }
186 186
187 acpi_gbl_prev_thread_id = thread_id; 187 acpi_gbl_prev_thread_id = thread_id;
diff --git a/drivers/acpi/utilities/utdelete.c b/drivers/acpi/utilities/utdelete.c
index 67b9f325c6fa..9d3f1149ba21 100644
--- a/drivers/acpi/utilities/utdelete.c
+++ b/drivers/acpi/utilities/utdelete.c
@@ -155,21 +155,30 @@ static void acpi_ut_delete_internal_obj(union acpi_operand_object *object)
155 case ACPI_TYPE_MUTEX: 155 case ACPI_TYPE_MUTEX:
156 156
157 ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS, 157 ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS,
158 "***** Mutex %p, Semaphore %p\n", 158 "***** Mutex %p, OS Mutex %p\n",
159 object, object->mutex.semaphore)); 159 object, object->mutex.os_mutex));
160 160
161 acpi_ex_unlink_mutex(object); 161 if (object->mutex.os_mutex != ACPI_GLOBAL_LOCK) {
162 (void)acpi_os_delete_semaphore(object->mutex.semaphore); 162 acpi_ex_unlink_mutex(object);
163 acpi_os_delete_mutex(object->mutex.os_mutex);
164 } else {
165 /* Global Lock "mutex" is actually a counting semaphore */
166
167 (void)
168 acpi_os_delete_semaphore
169 (acpi_gbl_global_lock_semaphore);
170 acpi_gbl_global_lock_semaphore = NULL;
171 }
163 break; 172 break;
164 173
165 case ACPI_TYPE_EVENT: 174 case ACPI_TYPE_EVENT:
166 175
167 ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS, 176 ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS,
168 "***** Event %p, Semaphore %p\n", 177 "***** Event %p, OS Semaphore %p\n",
169 object, object->event.semaphore)); 178 object, object->event.os_semaphore));
170 179
171 (void)acpi_os_delete_semaphore(object->event.semaphore); 180 (void)acpi_os_delete_semaphore(object->event.os_semaphore);
172 object->event.semaphore = NULL; 181 object->event.os_semaphore = NULL;
173 break; 182 break;
174 183
175 case ACPI_TYPE_METHOD: 184 case ACPI_TYPE_METHOD:
@@ -177,12 +186,13 @@ static void acpi_ut_delete_internal_obj(union acpi_operand_object *object)
177 ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS, 186 ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS,
178 "***** Method %p\n", object)); 187 "***** Method %p\n", object));
179 188
180 /* Delete the method semaphore if it exists */ 189 /* Delete the method mutex if it exists */
181 190
182 if (object->method.semaphore) { 191 if (object->method.mutex) {
183 (void)acpi_os_delete_semaphore(object->method. 192 acpi_os_delete_mutex(object->method.mutex->mutex.
184 semaphore); 193 os_mutex);
185 object->method.semaphore = NULL; 194 acpi_ut_delete_object_desc(object->method.mutex);
195 object->method.mutex = NULL;
186 } 196 }
187 break; 197 break;
188 198
@@ -437,11 +447,16 @@ acpi_ut_update_object_reference(union acpi_operand_object *object, u16 action)
437 */ 447 */
438 switch (ACPI_GET_OBJECT_TYPE(object)) { 448 switch (ACPI_GET_OBJECT_TYPE(object)) {
439 case ACPI_TYPE_DEVICE: 449 case ACPI_TYPE_DEVICE:
450 case ACPI_TYPE_PROCESSOR:
451 case ACPI_TYPE_POWER:
452 case ACPI_TYPE_THERMAL:
453
454 /* Update the notify objects for these types (if present) */
440 455
441 acpi_ut_update_ref_count(object->device.system_notify, 456 acpi_ut_update_ref_count(object->common_notify.
442 action); 457 system_notify, action);
443 acpi_ut_update_ref_count(object->device.device_notify, 458 acpi_ut_update_ref_count(object->common_notify.
444 action); 459 device_notify, action);
445 break; 460 break;
446 461
447 case ACPI_TYPE_PACKAGE: 462 case ACPI_TYPE_PACKAGE:
diff --git a/drivers/acpi/utilities/utglobal.c b/drivers/acpi/utilities/utglobal.c
index e5999c65c0b8..014030af8b50 100644
--- a/drivers/acpi/utilities/utglobal.c
+++ b/drivers/acpi/utilities/utglobal.c
@@ -794,6 +794,7 @@ void acpi_ut_init_globals(void)
794 794
795 /* Global Lock support */ 795 /* Global Lock support */
796 796
797 acpi_gbl_global_lock_semaphore = NULL;
797 acpi_gbl_global_lock_acquired = FALSE; 798 acpi_gbl_global_lock_acquired = FALSE;
798 acpi_gbl_global_lock_thread_count = 0; 799 acpi_gbl_global_lock_thread_count = 0;
799 acpi_gbl_global_lock_handle = 0; 800 acpi_gbl_global_lock_handle = 0;
diff --git a/drivers/acpi/utilities/utmisc.c b/drivers/acpi/utilities/utmisc.c
index 5c75d35ad1cd..6d8a8211be90 100644
--- a/drivers/acpi/utilities/utmisc.c
+++ b/drivers/acpi/utilities/utmisc.c
@@ -41,6 +41,8 @@
41 * POSSIBILITY OF SUCH DAMAGES. 41 * POSSIBILITY OF SUCH DAMAGES.
42 */ 42 */
43 43
44#include <linux/module.h>
45
44#include <acpi/acpi.h> 46#include <acpi/acpi.h>
45#include <acpi/acnamesp.h> 47#include <acpi/acnamesp.h>
46 48
@@ -63,7 +65,7 @@ ACPI_MODULE_NAME("utmisc")
63u8 acpi_ut_is_aml_table(struct acpi_table_header *table) 65u8 acpi_ut_is_aml_table(struct acpi_table_header *table)
64{ 66{
65 67
66 /* Ignore tables that contain AML */ 68 /* These are the only tables that contain executable AML */
67 69
68 if (ACPI_COMPARE_NAME(table->signature, DSDT_SIG) || 70 if (ACPI_COMPARE_NAME(table->signature, DSDT_SIG) ||
69 ACPI_COMPARE_NAME(table->signature, PSDT_SIG) || 71 ACPI_COMPARE_NAME(table->signature, PSDT_SIG) ||
@@ -417,10 +419,15 @@ void acpi_ut_set_integer_width(u8 revision)
417{ 419{
418 420
419 if (revision <= 1) { 421 if (revision <= 1) {
422
423 /* 32-bit case */
424
420 acpi_gbl_integer_bit_width = 32; 425 acpi_gbl_integer_bit_width = 32;
421 acpi_gbl_integer_nybble_width = 8; 426 acpi_gbl_integer_nybble_width = 8;
422 acpi_gbl_integer_byte_width = 4; 427 acpi_gbl_integer_byte_width = 4;
423 } else { 428 } else {
429 /* 64-bit case (ACPI 2.0+) */
430
424 acpi_gbl_integer_bit_width = 64; 431 acpi_gbl_integer_bit_width = 64;
425 acpi_gbl_integer_nybble_width = 16; 432 acpi_gbl_integer_nybble_width = 16;
426 acpi_gbl_integer_byte_width = 8; 433 acpi_gbl_integer_byte_width = 8;
@@ -500,6 +507,7 @@ acpi_ut_display_init_pathname(u8 type,
500 * FUNCTION: acpi_ut_valid_acpi_char 507 * FUNCTION: acpi_ut_valid_acpi_char
501 * 508 *
502 * PARAMETERS: Char - The character to be examined 509 * PARAMETERS: Char - The character to be examined
510 * Position - Byte position (0-3)
503 * 511 *
504 * RETURN: TRUE if the character is valid, FALSE otherwise 512 * RETURN: TRUE if the character is valid, FALSE otherwise
505 * 513 *
@@ -607,7 +615,9 @@ acpi_name acpi_ut_repair_name(acpi_name name)
607 * 615 *
608 * RETURN: Status and Converted value 616 * RETURN: Status and Converted value
609 * 617 *
610 * DESCRIPTION: Convert a string into an unsigned value. 618 * DESCRIPTION: Convert a string into an unsigned value. Performs either a
619 * 32-bit or 64-bit conversion, depending on the current mode
620 * of the interpreter.
611 * NOTE: Does not support Octal strings, not needed. 621 * NOTE: Does not support Octal strings, not needed.
612 * 622 *
613 ******************************************************************************/ 623 ******************************************************************************/
@@ -625,7 +635,7 @@ acpi_ut_strtoul64(char *string, u32 base, acpi_integer * ret_integer)
625 u8 sign_of0x = 0; 635 u8 sign_of0x = 0;
626 u8 term = 0; 636 u8 term = 0;
627 637
628 ACPI_FUNCTION_TRACE(ut_stroul64); 638 ACPI_FUNCTION_TRACE_STR(ut_stroul64, string);
629 639
630 switch (base) { 640 switch (base) {
631 case ACPI_ANY_BASE: 641 case ACPI_ANY_BASE:
@@ -673,11 +683,13 @@ acpi_ut_strtoul64(char *string, u32 base, acpi_integer * ret_integer)
673 } 683 }
674 } 684 }
675 685
686 /*
687 * Perform a 32-bit or 64-bit conversion, depending upon the current
688 * execution mode of the interpreter
689 */
676 dividend = (mode32) ? ACPI_UINT32_MAX : ACPI_UINT64_MAX; 690 dividend = (mode32) ? ACPI_UINT32_MAX : ACPI_UINT64_MAX;
677 691
678 /* At least one character in the string here */ 692 /* Main loop: convert the string to a 32- or 64-bit integer */
679
680 /* Main loop: convert the string to a 64-bit integer */
681 693
682 while (*string) { 694 while (*string) {
683 if (ACPI_IS_DIGIT(*string)) { 695 if (ACPI_IS_DIGIT(*string)) {
@@ -752,6 +764,9 @@ acpi_ut_strtoul64(char *string, u32 base, acpi_integer * ret_integer)
752 764
753 all_done: 765 all_done:
754 766
767 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Converted value: %8.8X%8.8X\n",
768 ACPI_FORMAT_UINT64(return_value)));
769
755 *ret_integer = return_value; 770 *ret_integer = return_value;
756 return_ACPI_STATUS(AE_OK); 771 return_ACPI_STATUS(AE_OK);
757 772
@@ -962,6 +977,7 @@ acpi_ut_exception(char *module_name,
962 acpi_os_vprintf(format, args); 977 acpi_os_vprintf(format, args);
963 acpi_os_printf(" [%X]\n", ACPI_CA_VERSION); 978 acpi_os_printf(" [%X]\n", ACPI_CA_VERSION);
964} 979}
980EXPORT_SYMBOL(acpi_ut_exception);
965 981
966void ACPI_INTERNAL_VAR_XFACE 982void ACPI_INTERNAL_VAR_XFACE
967acpi_ut_warning(char *module_name, u32 line_number, char *format, ...) 983acpi_ut_warning(char *module_name, u32 line_number, char *format, ...)
diff --git a/drivers/acpi/utilities/utmutex.c b/drivers/acpi/utilities/utmutex.c
index 25eb34369afa..c39062a047cd 100644
--- a/drivers/acpi/utilities/utmutex.c
+++ b/drivers/acpi/utilities/utmutex.c
@@ -82,12 +82,9 @@ acpi_status acpi_ut_mutex_initialize(void)
82 82
83 /* Create the spinlocks for use at interrupt level */ 83 /* Create the spinlocks for use at interrupt level */
84 84
85 status = acpi_os_create_lock(&acpi_gbl_gpe_lock); 85 spin_lock_init(acpi_gbl_gpe_lock);
86 if (ACPI_FAILURE(status)) { 86 spin_lock_init(acpi_gbl_hardware_lock);
87 return_ACPI_STATUS(status);
88 }
89 87
90 status = acpi_os_create_lock(&acpi_gbl_hardware_lock);
91 return_ACPI_STATUS(status); 88 return_ACPI_STATUS(status);
92} 89}
93 90
@@ -146,9 +143,8 @@ static acpi_status acpi_ut_create_mutex(acpi_mutex_handle mutex_id)
146 } 143 }
147 144
148 if (!acpi_gbl_mutex_info[mutex_id].mutex) { 145 if (!acpi_gbl_mutex_info[mutex_id].mutex) {
149 status = acpi_os_create_semaphore(1, 1, 146 status =
150 &acpi_gbl_mutex_info 147 acpi_os_create_mutex(&acpi_gbl_mutex_info[mutex_id].mutex);
151 [mutex_id].mutex);
152 acpi_gbl_mutex_info[mutex_id].thread_id = 148 acpi_gbl_mutex_info[mutex_id].thread_id =
153 ACPI_MUTEX_NOT_ACQUIRED; 149 ACPI_MUTEX_NOT_ACQUIRED;
154 acpi_gbl_mutex_info[mutex_id].use_count = 0; 150 acpi_gbl_mutex_info[mutex_id].use_count = 0;
@@ -171,7 +167,6 @@ static acpi_status acpi_ut_create_mutex(acpi_mutex_handle mutex_id)
171 167
172static acpi_status acpi_ut_delete_mutex(acpi_mutex_handle mutex_id) 168static acpi_status acpi_ut_delete_mutex(acpi_mutex_handle mutex_id)
173{ 169{
174 acpi_status status;
175 170
176 ACPI_FUNCTION_TRACE_U32(ut_delete_mutex, mutex_id); 171 ACPI_FUNCTION_TRACE_U32(ut_delete_mutex, mutex_id);
177 172
@@ -179,12 +174,12 @@ static acpi_status acpi_ut_delete_mutex(acpi_mutex_handle mutex_id)
179 return_ACPI_STATUS(AE_BAD_PARAMETER); 174 return_ACPI_STATUS(AE_BAD_PARAMETER);
180 } 175 }
181 176
182 status = acpi_os_delete_semaphore(acpi_gbl_mutex_info[mutex_id].mutex); 177 acpi_os_delete_mutex(acpi_gbl_mutex_info[mutex_id].mutex);
183 178
184 acpi_gbl_mutex_info[mutex_id].mutex = NULL; 179 acpi_gbl_mutex_info[mutex_id].mutex = NULL;
185 acpi_gbl_mutex_info[mutex_id].thread_id = ACPI_MUTEX_NOT_ACQUIRED; 180 acpi_gbl_mutex_info[mutex_id].thread_id = ACPI_MUTEX_NOT_ACQUIRED;
186 181
187 return_ACPI_STATUS(status); 182 return_ACPI_STATUS(AE_OK);
188} 183}
189 184
190/******************************************************************************* 185/*******************************************************************************
@@ -249,14 +244,14 @@ acpi_status acpi_ut_acquire_mutex(acpi_mutex_handle mutex_id)
249 244
250 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, 245 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
251 "Thread %X attempting to acquire Mutex [%s]\n", 246 "Thread %X attempting to acquire Mutex [%s]\n",
252 this_thread_id, acpi_ut_get_mutex_name(mutex_id))); 247 (u32) this_thread_id, acpi_ut_get_mutex_name(mutex_id)));
253 248
254 status = acpi_os_wait_semaphore(acpi_gbl_mutex_info[mutex_id].mutex, 249 status = acpi_os_acquire_mutex(acpi_gbl_mutex_info[mutex_id].mutex,
255 1, ACPI_WAIT_FOREVER); 250 ACPI_WAIT_FOREVER);
256 if (ACPI_SUCCESS(status)) { 251 if (ACPI_SUCCESS(status)) {
257 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, 252 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
258 "Thread %X acquired Mutex [%s]\n", 253 "Thread %X acquired Mutex [%s]\n",
259 this_thread_id, 254 (u32) this_thread_id,
260 acpi_ut_get_mutex_name(mutex_id))); 255 acpi_ut_get_mutex_name(mutex_id)));
261 256
262 acpi_gbl_mutex_info[mutex_id].use_count++; 257 acpi_gbl_mutex_info[mutex_id].use_count++;
@@ -264,7 +259,7 @@ acpi_status acpi_ut_acquire_mutex(acpi_mutex_handle mutex_id)
264 } else { 259 } else {
265 ACPI_EXCEPTION((AE_INFO, status, 260 ACPI_EXCEPTION((AE_INFO, status,
266 "Thread %X could not acquire Mutex [%X]", 261 "Thread %X could not acquire Mutex [%X]",
267 this_thread_id, mutex_id)); 262 (u32) this_thread_id, mutex_id));
268 } 263 }
269 264
270 return (status); 265 return (status);
@@ -284,14 +279,13 @@ acpi_status acpi_ut_acquire_mutex(acpi_mutex_handle mutex_id)
284 279
285acpi_status acpi_ut_release_mutex(acpi_mutex_handle mutex_id) 280acpi_status acpi_ut_release_mutex(acpi_mutex_handle mutex_id)
286{ 281{
287 acpi_status status;
288 acpi_thread_id this_thread_id; 282 acpi_thread_id this_thread_id;
289 283
290 ACPI_FUNCTION_NAME(ut_release_mutex); 284 ACPI_FUNCTION_NAME(ut_release_mutex);
291 285
292 this_thread_id = acpi_os_get_thread_id(); 286 this_thread_id = acpi_os_get_thread_id();
293 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, 287 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
294 "Thread %X releasing Mutex [%s]\n", this_thread_id, 288 "Thread %X releasing Mutex [%s]\n", (u32) this_thread_id,
295 acpi_ut_get_mutex_name(mutex_id))); 289 acpi_ut_get_mutex_name(mutex_id)));
296 290
297 if (mutex_id > ACPI_MAX_MUTEX) { 291 if (mutex_id > ACPI_MAX_MUTEX) {
@@ -340,19 +334,6 @@ acpi_status acpi_ut_release_mutex(acpi_mutex_handle mutex_id)
340 334
341 acpi_gbl_mutex_info[mutex_id].thread_id = ACPI_MUTEX_NOT_ACQUIRED; 335 acpi_gbl_mutex_info[mutex_id].thread_id = ACPI_MUTEX_NOT_ACQUIRED;
342 336
343 status = 337 acpi_os_release_mutex(acpi_gbl_mutex_info[mutex_id].mutex);
344 acpi_os_signal_semaphore(acpi_gbl_mutex_info[mutex_id].mutex, 1); 338 return (AE_OK);
345
346 if (ACPI_FAILURE(status)) {
347 ACPI_EXCEPTION((AE_INFO, status,
348 "Thread %X could not release Mutex [%X]",
349 this_thread_id, mutex_id));
350 } else {
351 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
352 "Thread %X released Mutex [%s]\n",
353 this_thread_id,
354 acpi_ut_get_mutex_name(mutex_id)));
355 }
356
357 return (status);
358} 339}
diff --git a/drivers/acpi/utilities/utstate.c b/drivers/acpi/utilities/utstate.c
index 0f5c5bb5deff..eaa13d05c859 100644
--- a/drivers/acpi/utilities/utstate.c
+++ b/drivers/acpi/utilities/utstate.c
@@ -199,6 +199,13 @@ struct acpi_thread_state *acpi_ut_create_thread_state(void)
199 state->common.descriptor_type = ACPI_DESC_TYPE_STATE_THREAD; 199 state->common.descriptor_type = ACPI_DESC_TYPE_STATE_THREAD;
200 state->thread.thread_id = acpi_os_get_thread_id(); 200 state->thread.thread_id = acpi_os_get_thread_id();
201 201
202 /* Check for invalid thread ID - zero is very bad, it will break things */
203
204 if (!state->thread.thread_id) {
205 ACPI_ERROR((AE_INFO, "Invalid zero ID from AcpiOsGetThreadId"));
206 state->thread.thread_id = (acpi_thread_id) 1;
207 }
208
202 return_PTR((struct acpi_thread_state *)state); 209 return_PTR((struct acpi_thread_state *)state);
203} 210}
204 211
diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c
index 6b516852ac12..d0d84c43a9d4 100644
--- a/drivers/acpi/utils.c
+++ b/drivers/acpi/utils.c
@@ -58,31 +58,29 @@ acpi_extract_package(union acpi_object *package,
58 u8 *head = NULL; 58 u8 *head = NULL;
59 u8 *tail = NULL; 59 u8 *tail = NULL;
60 60
61 ACPI_FUNCTION_TRACE("acpi_extract_package");
62 61
63 if (!package || (package->type != ACPI_TYPE_PACKAGE) 62 if (!package || (package->type != ACPI_TYPE_PACKAGE)
64 || (package->package.count < 1)) { 63 || (package->package.count < 1)) {
65 ACPI_DEBUG_PRINT((ACPI_DB_WARN, 64 printk(KERN_WARNING PREFIX "Invalid package argument\n");
66 "Invalid 'package' argument\n")); 65 return AE_BAD_PARAMETER;
67 return_ACPI_STATUS(AE_BAD_PARAMETER);
68 } 66 }
69 67
70 if (!format || !format->pointer || (format->length < 1)) { 68 if (!format || !format->pointer || (format->length < 1)) {
71 ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Invalid 'format' argument\n")); 69 printk(KERN_WARNING PREFIX "Invalid format argument\n");
72 return_ACPI_STATUS(AE_BAD_PARAMETER); 70 return AE_BAD_PARAMETER;
73 } 71 }
74 72
75 if (!buffer) { 73 if (!buffer) {
76 ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Invalid 'buffer' argument\n")); 74 printk(KERN_WARNING PREFIX "Invalid buffer argument\n");
77 return_ACPI_STATUS(AE_BAD_PARAMETER); 75 return AE_BAD_PARAMETER;
78 } 76 }
79 77
80 format_count = (format->length / sizeof(char)) - 1; 78 format_count = (format->length / sizeof(char)) - 1;
81 if (format_count > package->package.count) { 79 if (format_count > package->package.count) {
82 ACPI_DEBUG_PRINT((ACPI_DB_WARN, 80 printk(KERN_WARNING PREFIX "Format specifies more objects [%d]"
83 "Format specifies more objects [%d] than exist in package [%d].", 81 " than exist in package [%d].\n",
84 format_count, package->package.count)); 82 format_count, package->package.count);
85 return_ACPI_STATUS(AE_BAD_DATA); 83 return AE_BAD_DATA;
86 } 84 }
87 85
88 format_string = (char *)format->pointer; 86 format_string = (char *)format->pointer;
@@ -95,7 +93,7 @@ acpi_extract_package(union acpi_object *package,
95 union acpi_object *element = &(package->package.elements[i]); 93 union acpi_object *element = &(package->package.elements[i]);
96 94
97 if (!element) { 95 if (!element) {
98 return_ACPI_STATUS(AE_BAD_DATA); 96 return AE_BAD_DATA;
99 } 97 }
100 98
101 switch (element->type) { 99 switch (element->type) {
@@ -113,10 +111,11 @@ acpi_extract_package(union acpi_object *package,
113 tail_offset += sizeof(char *); 111 tail_offset += sizeof(char *);
114 break; 112 break;
115 default: 113 default:
116 ACPI_DEBUG_PRINT((ACPI_DB_WARN, 114 printk(KERN_WARNING PREFIX "Invalid package element"
117 "Invalid package element [%d]: got number, expecing [%c].\n", 115 " [%d]: got number, expecing"
118 i, format_string[i])); 116 " [%c]\n",
119 return_ACPI_STATUS(AE_BAD_DATA); 117 i, format_string[i]);
118 return AE_BAD_DATA;
120 break; 119 break;
121 } 120 }
122 break; 121 break;
@@ -138,10 +137,11 @@ acpi_extract_package(union acpi_object *package,
138 tail_offset += sizeof(u8 *); 137 tail_offset += sizeof(u8 *);
139 break; 138 break;
140 default: 139 default:
141 ACPI_DEBUG_PRINT((ACPI_DB_WARN, 140 printk(KERN_WARNING PREFIX "Invalid package element"
142 "Invalid package element [%d] got string/buffer, expecing [%c].\n", 141 " [%d] got string/buffer,"
143 i, format_string[i])); 142 " expecing [%c]\n",
144 return_ACPI_STATUS(AE_BAD_DATA); 143 i, format_string[i]);
144 return AE_BAD_DATA;
145 break; 145 break;
146 } 146 }
147 break; 147 break;
@@ -152,7 +152,7 @@ acpi_extract_package(union acpi_object *package,
152 "Found unsupported element at index=%d\n", 152 "Found unsupported element at index=%d\n",
153 i)); 153 i));
154 /* TBD: handle nested packages... */ 154 /* TBD: handle nested packages... */
155 return_ACPI_STATUS(AE_SUPPORT); 155 return AE_SUPPORT;
156 break; 156 break;
157 } 157 }
158 } 158 }
@@ -162,9 +162,9 @@ acpi_extract_package(union acpi_object *package,
162 */ 162 */
163 if (buffer->length < size_required) { 163 if (buffer->length < size_required) {
164 buffer->length = size_required; 164 buffer->length = size_required;
165 return_ACPI_STATUS(AE_BUFFER_OVERFLOW); 165 return AE_BUFFER_OVERFLOW;
166 } else if (buffer->length != size_required || !buffer->pointer) { 166 } else if (buffer->length != size_required || !buffer->pointer) {
167 return_ACPI_STATUS(AE_BAD_PARAMETER); 167 return AE_BAD_PARAMETER;
168 } 168 }
169 169
170 head = buffer->pointer; 170 head = buffer->pointer;
@@ -179,7 +179,7 @@ acpi_extract_package(union acpi_object *package,
179 union acpi_object *element = &(package->package.elements[i]); 179 union acpi_object *element = &(package->package.elements[i]);
180 180
181 if (!element) { 181 if (!element) {
182 return_ACPI_STATUS(AE_BAD_DATA); 182 return AE_BAD_DATA;
183 } 183 }
184 184
185 switch (element->type) { 185 switch (element->type) {
@@ -244,7 +244,7 @@ acpi_extract_package(union acpi_object *package,
244 } 244 }
245 } 245 }
246 246
247 return_ACPI_STATUS(AE_OK); 247 return AE_OK;
248} 248}
249 249
250EXPORT_SYMBOL(acpi_extract_package); 250EXPORT_SYMBOL(acpi_extract_package);
@@ -258,14 +258,13 @@ acpi_evaluate_integer(acpi_handle handle,
258 union acpi_object *element; 258 union acpi_object *element;
259 struct acpi_buffer buffer = { 0, NULL }; 259 struct acpi_buffer buffer = { 0, NULL };
260 260
261 ACPI_FUNCTION_TRACE("acpi_evaluate_integer");
262 261
263 if (!data) 262 if (!data)
264 return_ACPI_STATUS(AE_BAD_PARAMETER); 263 return AE_BAD_PARAMETER;
265 264
266 element = kmalloc(sizeof(union acpi_object), GFP_KERNEL); 265 element = kmalloc(sizeof(union acpi_object), irqs_disabled() ? GFP_ATOMIC: GFP_KERNEL);
267 if (!element) 266 if (!element)
268 return_ACPI_STATUS(AE_NO_MEMORY); 267 return AE_NO_MEMORY;
269 268
270 memset(element, 0, sizeof(union acpi_object)); 269 memset(element, 0, sizeof(union acpi_object));
271 buffer.length = sizeof(union acpi_object); 270 buffer.length = sizeof(union acpi_object);
@@ -274,13 +273,13 @@ acpi_evaluate_integer(acpi_handle handle,
274 if (ACPI_FAILURE(status)) { 273 if (ACPI_FAILURE(status)) {
275 acpi_util_eval_error(handle, pathname, status); 274 acpi_util_eval_error(handle, pathname, status);
276 kfree(element); 275 kfree(element);
277 return_ACPI_STATUS(status); 276 return status;
278 } 277 }
279 278
280 if (element->type != ACPI_TYPE_INTEGER) { 279 if (element->type != ACPI_TYPE_INTEGER) {
281 acpi_util_eval_error(handle, pathname, AE_BAD_DATA); 280 acpi_util_eval_error(handle, pathname, AE_BAD_DATA);
282 kfree(element); 281 kfree(element);
283 return_ACPI_STATUS(AE_BAD_DATA); 282 return AE_BAD_DATA;
284 } 283 }
285 284
286 *data = element->integer.value; 285 *data = element->integer.value;
@@ -288,7 +287,7 @@ acpi_evaluate_integer(acpi_handle handle,
288 287
289 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Return value [%lu]\n", *data)); 288 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Return value [%lu]\n", *data));
290 289
291 return_ACPI_STATUS(AE_OK); 290 return AE_OK;
292} 291}
293 292
294EXPORT_SYMBOL(acpi_evaluate_integer); 293EXPORT_SYMBOL(acpi_evaluate_integer);
@@ -303,15 +302,14 @@ acpi_evaluate_string(acpi_handle handle,
303 acpi_object *element = NULL; 302 acpi_object *element = NULL;
304 acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; 303 acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
305 304
306 ACPI_FUNCTION_TRACE("acpi_evaluate_string");
307 305
308 if (!data) 306 if (!data)
309 return_ACPI_STATUS(AE_BAD_PARAMETER); 307 return AE_BAD_PARAMETER;
310 308
311 status = acpi_evaluate_object(handle, pathname, arguments, &buffer); 309 status = acpi_evaluate_object(handle, pathname, arguments, &buffer);
312 if (ACPI_FAILURE(status)) { 310 if (ACPI_FAILURE(status)) {
313 acpi_util_eval_error(handle, pathname, status); 311 acpi_util_eval_error(handle, pathname, status);
314 return_ACPI_STATUS(status); 312 return status;
315 } 313 }
316 314
317 element = (acpi_object *) buffer.pointer; 315 element = (acpi_object *) buffer.pointer;
@@ -320,13 +318,13 @@ acpi_evaluate_string(acpi_handle handle,
320 || (element->type != ACPI_TYPE_BUFFER) 318 || (element->type != ACPI_TYPE_BUFFER)
321 || !element->string.length) { 319 || !element->string.length) {
322 acpi_util_eval_error(handle, pathname, AE_BAD_DATA); 320 acpi_util_eval_error(handle, pathname, AE_BAD_DATA);
323 return_ACPI_STATUS(AE_BAD_DATA); 321 return AE_BAD_DATA;
324 } 322 }
325 323
326 *data = kmalloc(element->string.length + 1, GFP_KERNEL); 324 *data = kmalloc(element->string.length + 1, GFP_KERNEL);
327 if (!data) { 325 if (!data) {
328 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Memory allocation error\n")); 326 printk(KERN_ERR PREFIX "Memory allocation\n");
329 return_VALUE(-ENOMEM); 327 return -ENOMEM;
330 } 328 }
331 memset(*data, 0, element->string.length + 1); 329 memset(*data, 0, element->string.length + 1);
332 330
@@ -334,9 +332,9 @@ acpi_evaluate_string(acpi_handle handle,
334 332
335 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Return value [%s]\n", *data)); 333 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Return value [%s]\n", *data));
336 334
337 acpi_os_free(buffer.pointer); 335 kfree(buffer.pointer);
338 336
339 return_ACPI_STATUS(AE_OK); 337 return AE_OK;
340} 338}
341#endif 339#endif
342 340
@@ -352,10 +350,9 @@ acpi_evaluate_reference(acpi_handle handle,
352 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; 350 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
353 u32 i = 0; 351 u32 i = 0;
354 352
355 ACPI_FUNCTION_TRACE("acpi_evaluate_reference");
356 353
357 if (!list) { 354 if (!list) {
358 return_ACPI_STATUS(AE_BAD_PARAMETER); 355 return AE_BAD_PARAMETER;
359 } 356 }
360 357
361 /* Evaluate object. */ 358 /* Evaluate object. */
@@ -367,32 +364,29 @@ acpi_evaluate_reference(acpi_handle handle,
367 package = (union acpi_object *)buffer.pointer; 364 package = (union acpi_object *)buffer.pointer;
368 365
369 if ((buffer.length == 0) || !package) { 366 if ((buffer.length == 0) || !package) {
370 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 367 printk(KERN_ERR PREFIX "No return object (len %X ptr %p)\n",
371 "No return object (len %X ptr %p)\n", 368 (unsigned)buffer.length, package);
372 (unsigned)buffer.length, package));
373 status = AE_BAD_DATA; 369 status = AE_BAD_DATA;
374 acpi_util_eval_error(handle, pathname, status); 370 acpi_util_eval_error(handle, pathname, status);
375 goto end; 371 goto end;
376 } 372 }
377 if (package->type != ACPI_TYPE_PACKAGE) { 373 if (package->type != ACPI_TYPE_PACKAGE) {
378 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 374 printk(KERN_ERR PREFIX "Expecting a [Package], found type %X\n",
379 "Expecting a [Package], found type %X\n", 375 package->type);
380 package->type));
381 status = AE_BAD_DATA; 376 status = AE_BAD_DATA;
382 acpi_util_eval_error(handle, pathname, status); 377 acpi_util_eval_error(handle, pathname, status);
383 goto end; 378 goto end;
384 } 379 }
385 if (!package->package.count) { 380 if (!package->package.count) {
386 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 381 printk(KERN_ERR PREFIX "[Package] has zero elements (%p)\n",
387 "[Package] has zero elements (%p)\n", 382 package);
388 package));
389 status = AE_BAD_DATA; 383 status = AE_BAD_DATA;
390 acpi_util_eval_error(handle, pathname, status); 384 acpi_util_eval_error(handle, pathname, status);
391 goto end; 385 goto end;
392 } 386 }
393 387
394 if (package->package.count > ACPI_MAX_HANDLES) { 388 if (package->package.count > ACPI_MAX_HANDLES) {
395 return_ACPI_STATUS(AE_NO_MEMORY); 389 return AE_NO_MEMORY;
396 } 390 }
397 list->count = package->package.count; 391 list->count = package->package.count;
398 392
@@ -404,9 +398,9 @@ acpi_evaluate_reference(acpi_handle handle,
404 398
405 if (element->type != ACPI_TYPE_ANY) { 399 if (element->type != ACPI_TYPE_ANY) {
406 status = AE_BAD_DATA; 400 status = AE_BAD_DATA;
407 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 401 printk(KERN_ERR PREFIX
408 "Expecting a [Reference] package element, found type %X\n", 402 "Expecting a [Reference] package element, found type %X\n",
409 element->type)); 403 element->type);
410 acpi_util_eval_error(handle, pathname, status); 404 acpi_util_eval_error(handle, pathname, status);
411 break; 405 break;
412 } 406 }
@@ -424,9 +418,9 @@ acpi_evaluate_reference(acpi_handle handle,
424 //kfree(list->handles); 418 //kfree(list->handles);
425 } 419 }
426 420
427 acpi_os_free(buffer.pointer); 421 kfree(buffer.pointer);
428 422
429 return_ACPI_STATUS(status); 423 return status;
430} 424}
431 425
432EXPORT_SYMBOL(acpi_evaluate_reference); 426EXPORT_SYMBOL(acpi_evaluate_reference);
diff --git a/drivers/acpi/video.c b/drivers/acpi/video.c
index e7e9a693953a..56666a982476 100644
--- a/drivers/acpi/video.c
+++ b/drivers/acpi/video.c
@@ -117,7 +117,7 @@ struct acpi_video_enumerated_device {
117}; 117};
118 118
119struct acpi_video_bus { 119struct acpi_video_bus {
120 acpi_handle handle; 120 struct acpi_device *device;
121 u8 dos_setting; 121 u8 dos_setting;
122 struct acpi_video_enumerated_device *attached_array; 122 struct acpi_video_enumerated_device *attached_array;
123 u8 attached_count; 123 u8 attached_count;
@@ -155,7 +155,6 @@ struct acpi_video_device_brightness {
155}; 155};
156 156
157struct acpi_video_device { 157struct acpi_video_device {
158 acpi_handle handle;
159 unsigned long device_id; 158 unsigned long device_id;
160 struct acpi_video_device_flags flags; 159 struct acpi_video_device_flags flags;
161 struct acpi_video_device_cap cap; 160 struct acpi_video_device_cap cap;
@@ -272,10 +271,10 @@ static int
272acpi_video_device_query(struct acpi_video_device *device, unsigned long *state) 271acpi_video_device_query(struct acpi_video_device *device, unsigned long *state)
273{ 272{
274 int status; 273 int status;
275 ACPI_FUNCTION_TRACE("acpi_video_device_query");
276 status = acpi_evaluate_integer(device->handle, "_DGS", NULL, state);
277 274
278 return_VALUE(status); 275 status = acpi_evaluate_integer(device->dev->handle, "_DGS", NULL, state);
276
277 return status;
279} 278}
280 279
281static int 280static int
@@ -284,11 +283,9 @@ acpi_video_device_get_state(struct acpi_video_device *device,
284{ 283{
285 int status; 284 int status;
286 285
287 ACPI_FUNCTION_TRACE("acpi_video_device_get_state"); 286 status = acpi_evaluate_integer(device->dev->handle, "_DCS", NULL, state);
288
289 status = acpi_evaluate_integer(device->handle, "_DCS", NULL, state);
290 287
291 return_VALUE(status); 288 return status;
292} 289}
293 290
294static int 291static int
@@ -299,12 +296,11 @@ acpi_video_device_set_state(struct acpi_video_device *device, int state)
299 struct acpi_object_list args = { 1, &arg0 }; 296 struct acpi_object_list args = { 1, &arg0 };
300 unsigned long ret; 297 unsigned long ret;
301 298
302 ACPI_FUNCTION_TRACE("acpi_video_device_set_state");
303 299
304 arg0.integer.value = state; 300 arg0.integer.value = state;
305 status = acpi_evaluate_integer(device->handle, "_DSS", &args, &ret); 301 status = acpi_evaluate_integer(device->dev->handle, "_DSS", &args, &ret);
306 302
307 return_VALUE(status); 303 return status;
308} 304}
309 305
310static int 306static int
@@ -315,28 +311,27 @@ acpi_video_device_lcd_query_levels(struct acpi_video_device *device,
315 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; 311 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
316 union acpi_object *obj; 312 union acpi_object *obj;
317 313
318 ACPI_FUNCTION_TRACE("acpi_video_device_lcd_query_levels");
319 314
320 *levels = NULL; 315 *levels = NULL;
321 316
322 status = acpi_evaluate_object(device->handle, "_BCL", NULL, &buffer); 317 status = acpi_evaluate_object(device->dev->handle, "_BCL", NULL, &buffer);
323 if (!ACPI_SUCCESS(status)) 318 if (!ACPI_SUCCESS(status))
324 return_VALUE(status); 319 return status;
325 obj = (union acpi_object *)buffer.pointer; 320 obj = (union acpi_object *)buffer.pointer;
326 if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) { 321 if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) {
327 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _BCL data\n")); 322 printk(KERN_ERR PREFIX "Invalid _BCL data\n");
328 status = -EFAULT; 323 status = -EFAULT;
329 goto err; 324 goto err;
330 } 325 }
331 326
332 *levels = obj; 327 *levels = obj;
333 328
334 return_VALUE(0); 329 return 0;
335 330
336 err: 331 err:
337 kfree(buffer.pointer); 332 kfree(buffer.pointer);
338 333
339 return_VALUE(status); 334 return status;
340} 335}
341 336
342static int 337static int
@@ -346,13 +341,12 @@ acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level)
346 union acpi_object arg0 = { ACPI_TYPE_INTEGER }; 341 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
347 struct acpi_object_list args = { 1, &arg0 }; 342 struct acpi_object_list args = { 1, &arg0 };
348 343
349 ACPI_FUNCTION_TRACE("acpi_video_device_lcd_set_level");
350 344
351 arg0.integer.value = level; 345 arg0.integer.value = level;
352 status = acpi_evaluate_object(device->handle, "_BCM", &args, NULL); 346 status = acpi_evaluate_object(device->dev->handle, "_BCM", &args, NULL);
353 347
354 printk(KERN_DEBUG "set_level status: %x\n", status); 348 printk(KERN_DEBUG "set_level status: %x\n", status);
355 return_VALUE(status); 349 return status;
356} 350}
357 351
358static int 352static int
@@ -360,11 +354,10 @@ acpi_video_device_lcd_get_level_current(struct acpi_video_device *device,
360 unsigned long *level) 354 unsigned long *level)
361{ 355{
362 int status; 356 int status;
363 ACPI_FUNCTION_TRACE("acpi_video_device_lcd_get_level_current");
364 357
365 status = acpi_evaluate_integer(device->handle, "_BQC", NULL, level); 358 status = acpi_evaluate_integer(device->dev->handle, "_BQC", NULL, level);
366 359
367 return_VALUE(status); 360 return status;
368} 361}
369 362
370static int 363static int
@@ -377,34 +370,33 @@ acpi_video_device_EDID(struct acpi_video_device *device,
377 union acpi_object arg0 = { ACPI_TYPE_INTEGER }; 370 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
378 struct acpi_object_list args = { 1, &arg0 }; 371 struct acpi_object_list args = { 1, &arg0 };
379 372
380 ACPI_FUNCTION_TRACE("acpi_video_device_get_EDID");
381 373
382 *edid = NULL; 374 *edid = NULL;
383 375
384 if (!device) 376 if (!device)
385 return_VALUE(-ENODEV); 377 return -ENODEV;
386 if (length == 128) 378 if (length == 128)
387 arg0.integer.value = 1; 379 arg0.integer.value = 1;
388 else if (length == 256) 380 else if (length == 256)
389 arg0.integer.value = 2; 381 arg0.integer.value = 2;
390 else 382 else
391 return_VALUE(-EINVAL); 383 return -EINVAL;
392 384
393 status = acpi_evaluate_object(device->handle, "_DDC", &args, &buffer); 385 status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer);
394 if (ACPI_FAILURE(status)) 386 if (ACPI_FAILURE(status))
395 return_VALUE(-ENODEV); 387 return -ENODEV;
396 388
397 obj = (union acpi_object *)buffer.pointer; 389 obj = (union acpi_object *)buffer.pointer;
398 390
399 if (obj && obj->type == ACPI_TYPE_BUFFER) 391 if (obj && obj->type == ACPI_TYPE_BUFFER)
400 *edid = obj; 392 *edid = obj;
401 else { 393 else {
402 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _DDC data\n")); 394 printk(KERN_ERR PREFIX "Invalid _DDC data\n");
403 status = -EFAULT; 395 status = -EFAULT;
404 kfree(obj); 396 kfree(obj);
405 } 397 }
406 398
407 return_VALUE(status); 399 return status;
408} 400}
409 401
410/* bus */ 402/* bus */
@@ -417,15 +409,14 @@ acpi_video_bus_set_POST(struct acpi_video_bus *video, unsigned long option)
417 union acpi_object arg0 = { ACPI_TYPE_INTEGER }; 409 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
418 struct acpi_object_list args = { 1, &arg0 }; 410 struct acpi_object_list args = { 1, &arg0 };
419 411
420 ACPI_FUNCTION_TRACE("acpi_video_bus_set_POST");
421 412
422 arg0.integer.value = option; 413 arg0.integer.value = option;
423 414
424 status = acpi_evaluate_integer(video->handle, "_SPD", &args, &tmp); 415 status = acpi_evaluate_integer(video->device->handle, "_SPD", &args, &tmp);
425 if (ACPI_SUCCESS(status)) 416 if (ACPI_SUCCESS(status))
426 status = tmp ? (-EINVAL) : (AE_OK); 417 status = tmp ? (-EINVAL) : (AE_OK);
427 418
428 return_VALUE(status); 419 return status;
429} 420}
430 421
431static int 422static int
@@ -433,11 +424,9 @@ acpi_video_bus_get_POST(struct acpi_video_bus *video, unsigned long *id)
433{ 424{
434 int status; 425 int status;
435 426
436 ACPI_FUNCTION_TRACE("acpi_video_bus_get_POST"); 427 status = acpi_evaluate_integer(video->device->handle, "_GPD", NULL, id);
437
438 status = acpi_evaluate_integer(video->handle, "_GPD", NULL, id);
439 428
440 return_VALUE(status); 429 return status;
441} 430}
442 431
443static int 432static int
@@ -445,12 +434,11 @@ acpi_video_bus_POST_options(struct acpi_video_bus *video,
445 unsigned long *options) 434 unsigned long *options)
446{ 435{
447 int status; 436 int status;
448 ACPI_FUNCTION_TRACE("acpi_video_bus_POST_options");
449 437
450 status = acpi_evaluate_integer(video->handle, "_VPO", NULL, options); 438 status = acpi_evaluate_integer(video->device->handle, "_VPO", NULL, options);
451 *options &= 3; 439 *options &= 3;
452 440
453 return_VALUE(status); 441 return status;
454} 442}
455 443
456/* 444/*
@@ -481,7 +469,6 @@ acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
481 union acpi_object arg0 = { ACPI_TYPE_INTEGER }; 469 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
482 struct acpi_object_list args = { 1, &arg0 }; 470 struct acpi_object_list args = { 1, &arg0 };
483 471
484 ACPI_FUNCTION_TRACE("acpi_video_bus_DOS");
485 472
486 if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1) { 473 if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1) {
487 status = -1; 474 status = -1;
@@ -489,10 +476,10 @@ acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
489 } 476 }
490 arg0.integer.value = (lcd_flag << 2) | bios_flag; 477 arg0.integer.value = (lcd_flag << 2) | bios_flag;
491 video->dos_setting = arg0.integer.value; 478 video->dos_setting = arg0.integer.value;
492 acpi_evaluate_object(video->handle, "_DOS", &args, NULL); 479 acpi_evaluate_object(video->device->handle, "_DOS", &args, NULL);
493 480
494 Failed: 481 Failed:
495 return_VALUE(status); 482 return status;
496} 483}
497 484
498/* 485/*
@@ -514,29 +501,28 @@ static void acpi_video_device_find_cap(struct acpi_video_device *device)
514 union acpi_object *obj = NULL; 501 union acpi_object *obj = NULL;
515 struct acpi_video_device_brightness *br = NULL; 502 struct acpi_video_device_brightness *br = NULL;
516 503
517 ACPI_FUNCTION_TRACE("acpi_video_device_find_cap");
518 504
519 memset(&device->cap, 0, 4); 505 memset(&device->cap, 0, 4);
520 506
521 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_ADR", &h_dummy1))) { 507 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_ADR", &h_dummy1))) {
522 device->cap._ADR = 1; 508 device->cap._ADR = 1;
523 } 509 }
524 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_BCL", &h_dummy1))) { 510 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCL", &h_dummy1))) {
525 device->cap._BCL = 1; 511 device->cap._BCL = 1;
526 } 512 }
527 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_BCM", &h_dummy1))) { 513 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCM", &h_dummy1))) {
528 device->cap._BCM = 1; 514 device->cap._BCM = 1;
529 } 515 }
530 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_DDC", &h_dummy1))) { 516 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DDC", &h_dummy1))) {
531 device->cap._DDC = 1; 517 device->cap._DDC = 1;
532 } 518 }
533 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_DCS", &h_dummy1))) { 519 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DCS", &h_dummy1))) {
534 device->cap._DCS = 1; 520 device->cap._DCS = 1;
535 } 521 }
536 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_DGS", &h_dummy1))) { 522 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DGS", &h_dummy1))) {
537 device->cap._DGS = 1; 523 device->cap._DGS = 1;
538 } 524 }
539 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_DSS", &h_dummy1))) { 525 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DSS", &h_dummy1))) {
540 device->cap._DSS = 1; 526 device->cap._DSS = 1;
541 } 527 }
542 528
@@ -560,8 +546,7 @@ static void acpi_video_device_find_cap(struct acpi_video_device *device)
560 o = (union acpi_object *)&obj->package. 546 o = (union acpi_object *)&obj->package.
561 elements[i]; 547 elements[i];
562 if (o->type != ACPI_TYPE_INTEGER) { 548 if (o->type != ACPI_TYPE_INTEGER) {
563 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 549 printk(KERN_ERR PREFIX "Invalid data\n");
564 "Invalid data\n"));
565 continue; 550 continue;
566 } 551 }
567 br->levels[count] = (u32) o->integer.value; 552 br->levels[count] = (u32) o->integer.value;
@@ -583,7 +568,7 @@ static void acpi_video_device_find_cap(struct acpi_video_device *device)
583 568
584 kfree(obj); 569 kfree(obj);
585 570
586 return_VOID; 571 return;
587} 572}
588 573
589/* 574/*
@@ -601,22 +586,22 @@ static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
601 acpi_handle h_dummy1; 586 acpi_handle h_dummy1;
602 587
603 memset(&video->cap, 0, 4); 588 memset(&video->cap, 0, 4);
604 if (ACPI_SUCCESS(acpi_get_handle(video->handle, "_DOS", &h_dummy1))) { 589 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOS", &h_dummy1))) {
605 video->cap._DOS = 1; 590 video->cap._DOS = 1;
606 } 591 }
607 if (ACPI_SUCCESS(acpi_get_handle(video->handle, "_DOD", &h_dummy1))) { 592 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOD", &h_dummy1))) {
608 video->cap._DOD = 1; 593 video->cap._DOD = 1;
609 } 594 }
610 if (ACPI_SUCCESS(acpi_get_handle(video->handle, "_ROM", &h_dummy1))) { 595 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_ROM", &h_dummy1))) {
611 video->cap._ROM = 1; 596 video->cap._ROM = 1;
612 } 597 }
613 if (ACPI_SUCCESS(acpi_get_handle(video->handle, "_GPD", &h_dummy1))) { 598 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_GPD", &h_dummy1))) {
614 video->cap._GPD = 1; 599 video->cap._GPD = 1;
615 } 600 }
616 if (ACPI_SUCCESS(acpi_get_handle(video->handle, "_SPD", &h_dummy1))) { 601 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_SPD", &h_dummy1))) {
617 video->cap._SPD = 1; 602 video->cap._SPD = 1;
618 } 603 }
619 if (ACPI_SUCCESS(acpi_get_handle(video->handle, "_VPO", &h_dummy1))) { 604 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_VPO", &h_dummy1))) {
620 video->cap._VPO = 1; 605 video->cap._VPO = 1;
621 } 606 }
622} 607}
@@ -630,10 +615,9 @@ static int acpi_video_bus_check(struct acpi_video_bus *video)
630{ 615{
631 acpi_status status = -ENOENT; 616 acpi_status status = -ENOENT;
632 617
633 ACPI_FUNCTION_TRACE("acpi_video_bus_check");
634 618
635 if (!video) 619 if (!video)
636 return_VALUE(-EINVAL); 620 return -EINVAL;
637 621
638 /* Since there is no HID, CID and so on for VGA driver, we have 622 /* Since there is no HID, CID and so on for VGA driver, we have
639 * to check well known required nodes. 623 * to check well known required nodes.
@@ -657,7 +641,7 @@ static int acpi_video_bus_check(struct acpi_video_bus *video)
657 status = 0; 641 status = 0;
658 } 642 }
659 643
660 return_VALUE(status); 644 return status;
661} 645}
662 646
663/* -------------------------------------------------------------------------- 647/* --------------------------------------------------------------------------
@@ -673,7 +657,6 @@ static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset)
673 struct acpi_video_device *dev = 657 struct acpi_video_device *dev =
674 (struct acpi_video_device *)seq->private; 658 (struct acpi_video_device *)seq->private;
675 659
676 ACPI_FUNCTION_TRACE("acpi_video_device_info_seq_show");
677 660
678 if (!dev) 661 if (!dev)
679 goto end; 662 goto end;
@@ -692,7 +675,7 @@ static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset)
692 seq_printf(seq, "known by bios: %s\n", dev->flags.bios ? "yes" : "no"); 675 seq_printf(seq, "known by bios: %s\n", dev->flags.bios ? "yes" : "no");
693 676
694 end: 677 end:
695 return_VALUE(0); 678 return 0;
696} 679}
697 680
698static int 681static int
@@ -709,7 +692,6 @@ static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset)
709 (struct acpi_video_device *)seq->private; 692 (struct acpi_video_device *)seq->private;
710 unsigned long state; 693 unsigned long state;
711 694
712 ACPI_FUNCTION_TRACE("acpi_video_device_state_seq_show");
713 695
714 if (!dev) 696 if (!dev)
715 goto end; 697 goto end;
@@ -729,7 +711,7 @@ static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset)
729 seq_printf(seq, "<not supported>\n"); 711 seq_printf(seq, "<not supported>\n");
730 712
731 end: 713 end:
732 return_VALUE(0); 714 return 0;
733} 715}
734 716
735static int 717static int
@@ -750,13 +732,12 @@ acpi_video_device_write_state(struct file *file,
750 char str[12] = { 0 }; 732 char str[12] = { 0 };
751 u32 state = 0; 733 u32 state = 0;
752 734
753 ACPI_FUNCTION_TRACE("acpi_video_device_write_state");
754 735
755 if (!dev || count + 1 > sizeof str) 736 if (!dev || count + 1 > sizeof str)
756 return_VALUE(-EINVAL); 737 return -EINVAL;
757 738
758 if (copy_from_user(str, buffer, count)) 739 if (copy_from_user(str, buffer, count))
759 return_VALUE(-EFAULT); 740 return -EFAULT;
760 741
761 str[count] = 0; 742 str[count] = 0;
762 state = simple_strtoul(str, NULL, 0); 743 state = simple_strtoul(str, NULL, 0);
@@ -765,9 +746,9 @@ acpi_video_device_write_state(struct file *file,
765 status = acpi_video_device_set_state(dev, state); 746 status = acpi_video_device_set_state(dev, state);
766 747
767 if (status) 748 if (status)
768 return_VALUE(-EFAULT); 749 return -EFAULT;
769 750
770 return_VALUE(count); 751 return count;
771} 752}
772 753
773static int 754static int
@@ -777,11 +758,10 @@ acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset)
777 (struct acpi_video_device *)seq->private; 758 (struct acpi_video_device *)seq->private;
778 int i; 759 int i;
779 760
780 ACPI_FUNCTION_TRACE("acpi_video_device_brightness_seq_show");
781 761
782 if (!dev || !dev->brightness) { 762 if (!dev || !dev->brightness) {
783 seq_printf(seq, "<not supported>\n"); 763 seq_printf(seq, "<not supported>\n");
784 return_VALUE(0); 764 return 0;
785 } 765 }
786 766
787 seq_printf(seq, "levels: "); 767 seq_printf(seq, "levels: ");
@@ -789,7 +769,7 @@ acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset)
789 seq_printf(seq, " %d", dev->brightness->levels[i]); 769 seq_printf(seq, " %d", dev->brightness->levels[i]);
790 seq_printf(seq, "\ncurrent: %d\n", dev->brightness->curr); 770 seq_printf(seq, "\ncurrent: %d\n", dev->brightness->curr);
791 771
792 return_VALUE(0); 772 return 0;
793} 773}
794 774
795static int 775static int
@@ -810,19 +790,18 @@ acpi_video_device_write_brightness(struct file *file,
810 unsigned int level = 0; 790 unsigned int level = 0;
811 int i; 791 int i;
812 792
813 ACPI_FUNCTION_TRACE("acpi_video_device_write_brightness");
814 793
815 if (!dev || !dev->brightness || count + 1 > sizeof str) 794 if (!dev || !dev->brightness || count + 1 > sizeof str)
816 return_VALUE(-EINVAL); 795 return -EINVAL;
817 796
818 if (copy_from_user(str, buffer, count)) 797 if (copy_from_user(str, buffer, count))
819 return_VALUE(-EFAULT); 798 return -EFAULT;
820 799
821 str[count] = 0; 800 str[count] = 0;
822 level = simple_strtoul(str, NULL, 0); 801 level = simple_strtoul(str, NULL, 0);
823 802
824 if (level > 100) 803 if (level > 100)
825 return_VALUE(-EFAULT); 804 return -EFAULT;
826 805
827 /* validate though the list of available levels */ 806 /* validate though the list of available levels */
828 for (i = 0; i < dev->brightness->count; i++) 807 for (i = 0; i < dev->brightness->count; i++)
@@ -833,7 +812,7 @@ acpi_video_device_write_brightness(struct file *file,
833 break; 812 break;
834 } 813 }
835 814
836 return_VALUE(count); 815 return count;
837} 816}
838 817
839static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset) 818static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset)
@@ -844,7 +823,6 @@ static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset)
844 int i; 823 int i;
845 union acpi_object *edid = NULL; 824 union acpi_object *edid = NULL;
846 825
847 ACPI_FUNCTION_TRACE("acpi_video_device_EDID_seq_show");
848 826
849 if (!dev) 827 if (!dev)
850 goto out; 828 goto out;
@@ -869,7 +847,7 @@ static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset)
869 else 847 else
870 kfree(edid); 848 kfree(edid);
871 849
872 return_VALUE(0); 850 return 0;
873} 851}
874 852
875static int 853static int
@@ -884,28 +862,26 @@ static int acpi_video_device_add_fs(struct acpi_device *device)
884 struct proc_dir_entry *entry = NULL; 862 struct proc_dir_entry *entry = NULL;
885 struct acpi_video_device *vid_dev; 863 struct acpi_video_device *vid_dev;
886 864
887 ACPI_FUNCTION_TRACE("acpi_video_device_add_fs");
888 865
889 if (!device) 866 if (!device)
890 return_VALUE(-ENODEV); 867 return -ENODEV;
891 868
892 vid_dev = (struct acpi_video_device *)acpi_driver_data(device); 869 vid_dev = (struct acpi_video_device *)acpi_driver_data(device);
893 if (!vid_dev) 870 if (!vid_dev)
894 return_VALUE(-ENODEV); 871 return -ENODEV;
895 872
896 if (!acpi_device_dir(device)) { 873 if (!acpi_device_dir(device)) {
897 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), 874 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
898 vid_dev->video->dir); 875 vid_dev->video->dir);
899 if (!acpi_device_dir(device)) 876 if (!acpi_device_dir(device))
900 return_VALUE(-ENODEV); 877 return -ENODEV;
901 acpi_device_dir(device)->owner = THIS_MODULE; 878 acpi_device_dir(device)->owner = THIS_MODULE;
902 } 879 }
903 880
904 /* 'info' [R] */ 881 /* 'info' [R] */
905 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device)); 882 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
906 if (!entry) 883 if (!entry)
907 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 884 return -ENODEV;
908 "Unable to create 'info' fs entry\n"));
909 else { 885 else {
910 entry->proc_fops = &acpi_video_device_info_fops; 886 entry->proc_fops = &acpi_video_device_info_fops;
911 entry->data = acpi_driver_data(device); 887 entry->data = acpi_driver_data(device);
@@ -917,8 +893,7 @@ static int acpi_video_device_add_fs(struct acpi_device *device)
917 create_proc_entry("state", S_IFREG | S_IRUGO | S_IWUSR, 893 create_proc_entry("state", S_IFREG | S_IRUGO | S_IWUSR,
918 acpi_device_dir(device)); 894 acpi_device_dir(device));
919 if (!entry) 895 if (!entry)
920 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 896 return -ENODEV;
921 "Unable to create 'state' fs entry\n"));
922 else { 897 else {
923 acpi_video_device_state_fops.write = acpi_video_device_write_state; 898 acpi_video_device_state_fops.write = acpi_video_device_write_state;
924 entry->proc_fops = &acpi_video_device_state_fops; 899 entry->proc_fops = &acpi_video_device_state_fops;
@@ -931,8 +906,7 @@ static int acpi_video_device_add_fs(struct acpi_device *device)
931 create_proc_entry("brightness", S_IFREG | S_IRUGO | S_IWUSR, 906 create_proc_entry("brightness", S_IFREG | S_IRUGO | S_IWUSR,
932 acpi_device_dir(device)); 907 acpi_device_dir(device));
933 if (!entry) 908 if (!entry)
934 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 909 return -ENODEV;
935 "Unable to create 'brightness' fs entry\n"));
936 else { 910 else {
937 acpi_video_device_brightness_fops.write = acpi_video_device_write_brightness; 911 acpi_video_device_brightness_fops.write = acpi_video_device_write_brightness;
938 entry->proc_fops = &acpi_video_device_brightness_fops; 912 entry->proc_fops = &acpi_video_device_brightness_fops;
@@ -943,25 +917,23 @@ static int acpi_video_device_add_fs(struct acpi_device *device)
943 /* 'EDID' [R] */ 917 /* 'EDID' [R] */
944 entry = create_proc_entry("EDID", S_IRUGO, acpi_device_dir(device)); 918 entry = create_proc_entry("EDID", S_IRUGO, acpi_device_dir(device));
945 if (!entry) 919 if (!entry)
946 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 920 return -ENODEV;
947 "Unable to create 'brightness' fs entry\n"));
948 else { 921 else {
949 entry->proc_fops = &acpi_video_device_EDID_fops; 922 entry->proc_fops = &acpi_video_device_EDID_fops;
950 entry->data = acpi_driver_data(device); 923 entry->data = acpi_driver_data(device);
951 entry->owner = THIS_MODULE; 924 entry->owner = THIS_MODULE;
952 } 925 }
953 926
954 return_VALUE(0); 927 return 0;
955} 928}
956 929
957static int acpi_video_device_remove_fs(struct acpi_device *device) 930static int acpi_video_device_remove_fs(struct acpi_device *device)
958{ 931{
959 struct acpi_video_device *vid_dev; 932 struct acpi_video_device *vid_dev;
960 ACPI_FUNCTION_TRACE("acpi_video_device_remove_fs");
961 933
962 vid_dev = (struct acpi_video_device *)acpi_driver_data(device); 934 vid_dev = (struct acpi_video_device *)acpi_driver_data(device);
963 if (!vid_dev || !vid_dev->video || !vid_dev->video->dir) 935 if (!vid_dev || !vid_dev->video || !vid_dev->video->dir)
964 return_VALUE(-ENODEV); 936 return -ENODEV;
965 937
966 if (acpi_device_dir(device)) { 938 if (acpi_device_dir(device)) {
967 remove_proc_entry("info", acpi_device_dir(device)); 939 remove_proc_entry("info", acpi_device_dir(device));
@@ -972,7 +944,7 @@ static int acpi_video_device_remove_fs(struct acpi_device *device)
972 acpi_device_dir(device) = NULL; 944 acpi_device_dir(device) = NULL;
973 } 945 }
974 946
975 return_VALUE(0); 947 return 0;
976} 948}
977 949
978/* video bus */ 950/* video bus */
@@ -980,7 +952,6 @@ static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset)
980{ 952{
981 struct acpi_video_bus *video = (struct acpi_video_bus *)seq->private; 953 struct acpi_video_bus *video = (struct acpi_video_bus *)seq->private;
982 954
983 ACPI_FUNCTION_TRACE("acpi_video_bus_info_seq_show");
984 955
985 if (!video) 956 if (!video)
986 goto end; 957 goto end;
@@ -993,7 +964,7 @@ static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset)
993 video->flags.post ? "yes" : "no"); 964 video->flags.post ? "yes" : "no");
994 965
995 end: 966 end:
996 return_VALUE(0); 967 return 0;
997} 968}
998 969
999static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file) 970static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file)
@@ -1006,7 +977,6 @@ static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset)
1006{ 977{
1007 struct acpi_video_bus *video = (struct acpi_video_bus *)seq->private; 978 struct acpi_video_bus *video = (struct acpi_video_bus *)seq->private;
1008 979
1009 ACPI_FUNCTION_TRACE("acpi_video_bus_ROM_seq_show");
1010 980
1011 if (!video) 981 if (!video)
1012 goto end; 982 goto end;
@@ -1015,7 +985,7 @@ static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset)
1015 seq_printf(seq, "<TODO>\n"); 985 seq_printf(seq, "<TODO>\n");
1016 986
1017 end: 987 end:
1018 return_VALUE(0); 988 return 0;
1019} 989}
1020 990
1021static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file) 991static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file)
@@ -1029,7 +999,6 @@ static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset)
1029 unsigned long options; 999 unsigned long options;
1030 int status; 1000 int status;
1031 1001
1032 ACPI_FUNCTION_TRACE("acpi_video_bus_POST_info_seq_show");
1033 1002
1034 if (!video) 1003 if (!video)
1035 goto end; 1004 goto end;
@@ -1052,7 +1021,7 @@ static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset)
1052 } else 1021 } else
1053 seq_printf(seq, "<not supported>\n"); 1022 seq_printf(seq, "<not supported>\n");
1054 end: 1023 end:
1055 return_VALUE(0); 1024 return 0;
1056} 1025}
1057 1026
1058static int 1027static int
@@ -1068,7 +1037,6 @@ static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
1068 int status; 1037 int status;
1069 unsigned long id; 1038 unsigned long id;
1070 1039
1071 ACPI_FUNCTION_TRACE("acpi_video_bus_POST_seq_show");
1072 1040
1073 if (!video) 1041 if (!video)
1074 goto end; 1042 goto end;
@@ -1081,18 +1049,17 @@ static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
1081 seq_printf(seq, "device posted is <%s>\n", device_decode[id & 3]); 1049 seq_printf(seq, "device posted is <%s>\n", device_decode[id & 3]);
1082 1050
1083 end: 1051 end:
1084 return_VALUE(0); 1052 return 0;
1085} 1053}
1086 1054
1087static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset) 1055static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset)
1088{ 1056{
1089 struct acpi_video_bus *video = (struct acpi_video_bus *)seq->private; 1057 struct acpi_video_bus *video = (struct acpi_video_bus *)seq->private;
1090 1058
1091 ACPI_FUNCTION_TRACE("acpi_video_bus_DOS_seq_show");
1092 1059
1093 seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting); 1060 seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting);
1094 1061
1095 return_VALUE(0); 1062 return 0;
1096} 1063}
1097 1064
1098static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file) 1065static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file)
@@ -1117,22 +1084,21 @@ acpi_video_bus_write_POST(struct file *file,
1117 char str[12] = { 0 }; 1084 char str[12] = { 0 };
1118 unsigned long opt, options; 1085 unsigned long opt, options;
1119 1086
1120 ACPI_FUNCTION_TRACE("acpi_video_bus_write_POST");
1121 1087
1122 if (!video || count + 1 > sizeof str) 1088 if (!video || count + 1 > sizeof str)
1123 return_VALUE(-EINVAL); 1089 return -EINVAL;
1124 1090
1125 status = acpi_video_bus_POST_options(video, &options); 1091 status = acpi_video_bus_POST_options(video, &options);
1126 if (!ACPI_SUCCESS(status)) 1092 if (!ACPI_SUCCESS(status))
1127 return_VALUE(-EINVAL); 1093 return -EINVAL;
1128 1094
1129 if (copy_from_user(str, buffer, count)) 1095 if (copy_from_user(str, buffer, count))
1130 return_VALUE(-EFAULT); 1096 return -EFAULT;
1131 1097
1132 str[count] = 0; 1098 str[count] = 0;
1133 opt = strtoul(str, NULL, 0); 1099 opt = strtoul(str, NULL, 0);
1134 if (opt > 3) 1100 if (opt > 3)
1135 return_VALUE(-EFAULT); 1101 return -EFAULT;
1136 1102
1137 /* just in case an OEM 'forget' the motherboard... */ 1103 /* just in case an OEM 'forget' the motherboard... */
1138 options |= 1; 1104 options |= 1;
@@ -1140,11 +1106,11 @@ acpi_video_bus_write_POST(struct file *file,
1140 if (options & (1ul << opt)) { 1106 if (options & (1ul << opt)) {
1141 status = acpi_video_bus_set_POST(video, opt); 1107 status = acpi_video_bus_set_POST(video, opt);
1142 if (!ACPI_SUCCESS(status)) 1108 if (!ACPI_SUCCESS(status))
1143 return_VALUE(-EFAULT); 1109 return -EFAULT;
1144 1110
1145 } 1111 }
1146 1112
1147 return_VALUE(count); 1113 return count;
1148} 1114}
1149 1115
1150static ssize_t 1116static ssize_t
@@ -1158,25 +1124,24 @@ acpi_video_bus_write_DOS(struct file *file,
1158 char str[12] = { 0 }; 1124 char str[12] = { 0 };
1159 unsigned long opt; 1125 unsigned long opt;
1160 1126
1161 ACPI_FUNCTION_TRACE("acpi_video_bus_write_DOS");
1162 1127
1163 if (!video || count + 1 > sizeof str) 1128 if (!video || count + 1 > sizeof str)
1164 return_VALUE(-EINVAL); 1129 return -EINVAL;
1165 1130
1166 if (copy_from_user(str, buffer, count)) 1131 if (copy_from_user(str, buffer, count))
1167 return_VALUE(-EFAULT); 1132 return -EFAULT;
1168 1133
1169 str[count] = 0; 1134 str[count] = 0;
1170 opt = strtoul(str, NULL, 0); 1135 opt = strtoul(str, NULL, 0);
1171 if (opt > 7) 1136 if (opt > 7)
1172 return_VALUE(-EFAULT); 1137 return -EFAULT;
1173 1138
1174 status = acpi_video_bus_DOS(video, opt & 0x3, (opt & 0x4) >> 2); 1139 status = acpi_video_bus_DOS(video, opt & 0x3, (opt & 0x4) >> 2);
1175 1140
1176 if (!ACPI_SUCCESS(status)) 1141 if (!ACPI_SUCCESS(status))
1177 return_VALUE(-EFAULT); 1142 return -EFAULT;
1178 1143
1179 return_VALUE(count); 1144 return count;
1180} 1145}
1181 1146
1182static int acpi_video_bus_add_fs(struct acpi_device *device) 1147static int acpi_video_bus_add_fs(struct acpi_device *device)
@@ -1184,7 +1149,6 @@ static int acpi_video_bus_add_fs(struct acpi_device *device)
1184 struct proc_dir_entry *entry = NULL; 1149 struct proc_dir_entry *entry = NULL;
1185 struct acpi_video_bus *video; 1150 struct acpi_video_bus *video;
1186 1151
1187 ACPI_FUNCTION_TRACE("acpi_video_bus_add_fs");
1188 1152
1189 video = (struct acpi_video_bus *)acpi_driver_data(device); 1153 video = (struct acpi_video_bus *)acpi_driver_data(device);
1190 1154
@@ -1192,7 +1156,7 @@ static int acpi_video_bus_add_fs(struct acpi_device *device)
1192 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), 1156 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
1193 acpi_video_dir); 1157 acpi_video_dir);
1194 if (!acpi_device_dir(device)) 1158 if (!acpi_device_dir(device))
1195 return_VALUE(-ENODEV); 1159 return -ENODEV;
1196 video->dir = acpi_device_dir(device); 1160 video->dir = acpi_device_dir(device);
1197 acpi_device_dir(device)->owner = THIS_MODULE; 1161 acpi_device_dir(device)->owner = THIS_MODULE;
1198 } 1162 }
@@ -1200,8 +1164,7 @@ static int acpi_video_bus_add_fs(struct acpi_device *device)
1200 /* 'info' [R] */ 1164 /* 'info' [R] */
1201 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device)); 1165 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
1202 if (!entry) 1166 if (!entry)
1203 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1167 return -ENODEV;
1204 "Unable to create 'info' fs entry\n"));
1205 else { 1168 else {
1206 entry->proc_fops = &acpi_video_bus_info_fops; 1169 entry->proc_fops = &acpi_video_bus_info_fops;
1207 entry->data = acpi_driver_data(device); 1170 entry->data = acpi_driver_data(device);
@@ -1211,8 +1174,7 @@ static int acpi_video_bus_add_fs(struct acpi_device *device)
1211 /* 'ROM' [R] */ 1174 /* 'ROM' [R] */
1212 entry = create_proc_entry("ROM", S_IRUGO, acpi_device_dir(device)); 1175 entry = create_proc_entry("ROM", S_IRUGO, acpi_device_dir(device));
1213 if (!entry) 1176 if (!entry)
1214 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1177 return -ENODEV;
1215 "Unable to create 'ROM' fs entry\n"));
1216 else { 1178 else {
1217 entry->proc_fops = &acpi_video_bus_ROM_fops; 1179 entry->proc_fops = &acpi_video_bus_ROM_fops;
1218 entry->data = acpi_driver_data(device); 1180 entry->data = acpi_driver_data(device);
@@ -1223,8 +1185,7 @@ static int acpi_video_bus_add_fs(struct acpi_device *device)
1223 entry = 1185 entry =
1224 create_proc_entry("POST_info", S_IRUGO, acpi_device_dir(device)); 1186 create_proc_entry("POST_info", S_IRUGO, acpi_device_dir(device));
1225 if (!entry) 1187 if (!entry)
1226 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1188 return -ENODEV;
1227 "Unable to create 'POST_info' fs entry\n"));
1228 else { 1189 else {
1229 entry->proc_fops = &acpi_video_bus_POST_info_fops; 1190 entry->proc_fops = &acpi_video_bus_POST_info_fops;
1230 entry->data = acpi_driver_data(device); 1191 entry->data = acpi_driver_data(device);
@@ -1236,8 +1197,7 @@ static int acpi_video_bus_add_fs(struct acpi_device *device)
1236 create_proc_entry("POST", S_IFREG | S_IRUGO | S_IRUSR, 1197 create_proc_entry("POST", S_IFREG | S_IRUGO | S_IRUSR,
1237 acpi_device_dir(device)); 1198 acpi_device_dir(device));
1238 if (!entry) 1199 if (!entry)
1239 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1200 return -ENODEV;
1240 "Unable to create 'POST' fs entry\n"));
1241 else { 1201 else {
1242 acpi_video_bus_POST_fops.write = acpi_video_bus_write_POST; 1202 acpi_video_bus_POST_fops.write = acpi_video_bus_write_POST;
1243 entry->proc_fops = &acpi_video_bus_POST_fops; 1203 entry->proc_fops = &acpi_video_bus_POST_fops;
@@ -1250,8 +1210,7 @@ static int acpi_video_bus_add_fs(struct acpi_device *device)
1250 create_proc_entry("DOS", S_IFREG | S_IRUGO | S_IRUSR, 1210 create_proc_entry("DOS", S_IFREG | S_IRUGO | S_IRUSR,
1251 acpi_device_dir(device)); 1211 acpi_device_dir(device));
1252 if (!entry) 1212 if (!entry)
1253 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1213 return -ENODEV;
1254 "Unable to create 'DOS' fs entry\n"));
1255 else { 1214 else {
1256 acpi_video_bus_DOS_fops.write = acpi_video_bus_write_DOS; 1215 acpi_video_bus_DOS_fops.write = acpi_video_bus_write_DOS;
1257 entry->proc_fops = &acpi_video_bus_DOS_fops; 1216 entry->proc_fops = &acpi_video_bus_DOS_fops;
@@ -1259,14 +1218,13 @@ static int acpi_video_bus_add_fs(struct acpi_device *device)
1259 entry->owner = THIS_MODULE; 1218 entry->owner = THIS_MODULE;
1260 } 1219 }
1261 1220
1262 return_VALUE(0); 1221 return 0;
1263} 1222}
1264 1223
1265static int acpi_video_bus_remove_fs(struct acpi_device *device) 1224static int acpi_video_bus_remove_fs(struct acpi_device *device)
1266{ 1225{
1267 struct acpi_video_bus *video; 1226 struct acpi_video_bus *video;
1268 1227
1269 ACPI_FUNCTION_TRACE("acpi_video_bus_remove_fs");
1270 1228
1271 video = (struct acpi_video_bus *)acpi_driver_data(device); 1229 video = (struct acpi_video_bus *)acpi_driver_data(device);
1272 1230
@@ -1280,7 +1238,7 @@ static int acpi_video_bus_remove_fs(struct acpi_device *device)
1280 acpi_device_dir(device) = NULL; 1238 acpi_device_dir(device) = NULL;
1281 } 1239 }
1282 1240
1283 return_VALUE(0); 1241 return 0;
1284} 1242}
1285 1243
1286/* -------------------------------------------------------------------------- 1244/* --------------------------------------------------------------------------
@@ -1297,10 +1255,9 @@ acpi_video_bus_get_one_device(struct acpi_device *device,
1297 int status; 1255 int status;
1298 struct acpi_video_device *data; 1256 struct acpi_video_device *data;
1299 1257
1300 ACPI_FUNCTION_TRACE("acpi_video_bus_get_one_device");
1301 1258
1302 if (!device || !video) 1259 if (!device || !video)
1303 return_VALUE(-EINVAL); 1260 return -EINVAL;
1304 1261
1305 status = 1262 status =
1306 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id); 1263 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
@@ -1308,11 +1265,10 @@ acpi_video_bus_get_one_device(struct acpi_device *device,
1308 1265
1309 data = kmalloc(sizeof(struct acpi_video_device), GFP_KERNEL); 1266 data = kmalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
1310 if (!data) 1267 if (!data)
1311 return_VALUE(-ENOMEM); 1268 return -ENOMEM;
1312 1269
1313 memset(data, 0, sizeof(struct acpi_video_device)); 1270 memset(data, 0, sizeof(struct acpi_video_device));
1314 1271
1315 data->handle = device->handle;
1316 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME); 1272 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
1317 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS); 1273 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1318 acpi_driver_data(device) = data; 1274 acpi_driver_data(device) = data;
@@ -1339,7 +1295,7 @@ acpi_video_bus_get_one_device(struct acpi_device *device,
1339 acpi_video_device_bind(video, data); 1295 acpi_video_device_bind(video, data);
1340 acpi_video_device_find_cap(data); 1296 acpi_video_device_find_cap(data);
1341 1297
1342 status = acpi_install_notify_handler(data->handle, 1298 status = acpi_install_notify_handler(device->handle,
1343 ACPI_DEVICE_NOTIFY, 1299 ACPI_DEVICE_NOTIFY,
1344 acpi_video_device_notify, 1300 acpi_video_device_notify,
1345 data); 1301 data);
@@ -1359,10 +1315,10 @@ acpi_video_bus_get_one_device(struct acpi_device *device,
1359 1315
1360 acpi_video_device_add_fs(device); 1316 acpi_video_device_add_fs(device);
1361 1317
1362 return_VALUE(0); 1318 return 0;
1363 } 1319 }
1364 1320
1365 return_VALUE(-ENOENT); 1321 return -ENOENT;
1366} 1322}
1367 1323
1368/* 1324/*
@@ -1405,7 +1361,6 @@ acpi_video_device_bind(struct acpi_video_bus *video,
1405 struct acpi_video_device *device) 1361 struct acpi_video_device *device)
1406{ 1362{
1407 int i; 1363 int i;
1408 ACPI_FUNCTION_TRACE("acpi_video_device_bind");
1409 1364
1410#define IDS_VAL(i) video->attached_array[i].value.int_val 1365#define IDS_VAL(i) video->attached_array[i].value.int_val
1411#define IDS_BIND(i) video->attached_array[i].bind_info 1366#define IDS_BIND(i) video->attached_array[i].bind_info
@@ -1442,17 +1397,15 @@ static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1442 union acpi_object *dod = NULL; 1397 union acpi_object *dod = NULL;
1443 union acpi_object *obj; 1398 union acpi_object *obj;
1444 1399
1445 ACPI_FUNCTION_TRACE("acpi_video_device_enumerate"); 1400 status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer);
1446
1447 status = acpi_evaluate_object(video->handle, "_DOD", NULL, &buffer);
1448 if (!ACPI_SUCCESS(status)) { 1401 if (!ACPI_SUCCESS(status)) {
1449 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error evaluating _DOD\n")); 1402 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD"));
1450 return_VALUE(status); 1403 return status;
1451 } 1404 }
1452 1405
1453 dod = (union acpi_object *)buffer.pointer; 1406 dod = (union acpi_object *)buffer.pointer;
1454 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) { 1407 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
1455 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _DOD data\n")); 1408 ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
1456 status = -EFAULT; 1409 status = -EFAULT;
1457 goto out; 1410 goto out;
1458 } 1411 }
@@ -1476,8 +1429,7 @@ static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1476 obj = (union acpi_object *)&dod->package.elements[i]; 1429 obj = (union acpi_object *)&dod->package.elements[i];
1477 1430
1478 if (obj->type != ACPI_TYPE_INTEGER) { 1431 if (obj->type != ACPI_TYPE_INTEGER) {
1479 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1432 printk(KERN_ERR PREFIX "Invalid _DOD data\n");
1480 "Invalid _DOD data\n"));
1481 active_device_list[i].value.int_val = 1433 active_device_list[i].value.int_val =
1482 ACPI_VIDEO_HEAD_INVALID; 1434 ACPI_VIDEO_HEAD_INVALID;
1483 } 1435 }
@@ -1494,8 +1446,8 @@ static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1494 video->attached_array = active_device_list; 1446 video->attached_array = active_device_list;
1495 video->attached_count = count; 1447 video->attached_count = count;
1496 out: 1448 out:
1497 acpi_os_free(buffer.pointer); 1449 kfree(buffer.pointer);
1498 return_VALUE(status); 1450 return status;
1499} 1451}
1500 1452
1501/* 1453/*
@@ -1520,7 +1472,6 @@ static int acpi_video_switch_output(struct acpi_video_bus *video, int event)
1520 unsigned long state; 1472 unsigned long state;
1521 int status = 0; 1473 int status = 0;
1522 1474
1523 ACPI_FUNCTION_TRACE("acpi_video_switch_output");
1524 1475
1525 list_for_each_safe(node, next, &video->video_device_list) { 1476 list_for_each_safe(node, next, &video->video_device_list) {
1526 dev = container_of(node, struct acpi_video_device, entry); 1477 dev = container_of(node, struct acpi_video_device, entry);
@@ -1551,7 +1502,7 @@ static int acpi_video_switch_output(struct acpi_video_bus *video, int event)
1551 break; 1502 break;
1552 } 1503 }
1553 1504
1554 return_VALUE(status); 1505 return status;
1555} 1506}
1556 1507
1557static int 1508static int
@@ -1578,7 +1529,6 @@ acpi_video_bus_get_devices(struct acpi_video_bus *video,
1578 int status = 0; 1529 int status = 0;
1579 struct list_head *node, *next; 1530 struct list_head *node, *next;
1580 1531
1581 ACPI_FUNCTION_TRACE("acpi_video_get_devices");
1582 1532
1583 acpi_video_device_enumerate(video); 1533 acpi_video_device_enumerate(video);
1584 1534
@@ -1591,13 +1541,12 @@ acpi_video_bus_get_devices(struct acpi_video_bus *video,
1591 1541
1592 status = acpi_video_bus_get_one_device(dev, video); 1542 status = acpi_video_bus_get_one_device(dev, video);
1593 if (ACPI_FAILURE(status)) { 1543 if (ACPI_FAILURE(status)) {
1594 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1544 ACPI_EXCEPTION((AE_INFO, status, "Cant attach device"));
1595 "Cant attach device\n"));
1596 continue; 1545 continue;
1597 } 1546 }
1598 1547
1599 } 1548 }
1600 return_VALUE(status); 1549 return status;
1601} 1550}
1602 1551
1603static int acpi_video_bus_put_one_device(struct acpi_video_device *device) 1552static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
@@ -1605,10 +1554,9 @@ static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
1605 acpi_status status; 1554 acpi_status status;
1606 struct acpi_video_bus *video; 1555 struct acpi_video_bus *video;
1607 1556
1608 ACPI_FUNCTION_TRACE("acpi_video_bus_put_one_device");
1609 1557
1610 if (!device || !device->video) 1558 if (!device || !device->video)
1611 return_VALUE(-ENOENT); 1559 return -ENOENT;
1612 1560
1613 video = device->video; 1561 video = device->video;
1614 1562
@@ -1617,14 +1565,11 @@ static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
1617 up(&video->sem); 1565 up(&video->sem);
1618 acpi_video_device_remove_fs(device->dev); 1566 acpi_video_device_remove_fs(device->dev);
1619 1567
1620 status = acpi_remove_notify_handler(device->handle, 1568 status = acpi_remove_notify_handler(device->dev->handle,
1621 ACPI_DEVICE_NOTIFY, 1569 ACPI_DEVICE_NOTIFY,
1622 acpi_video_device_notify); 1570 acpi_video_device_notify);
1623 if (ACPI_FAILURE(status))
1624 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1625 "Error removing notify handler\n"));
1626 1571
1627 return_VALUE(0); 1572 return 0;
1628} 1573}
1629 1574
1630static int acpi_video_bus_put_devices(struct acpi_video_bus *video) 1575static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
@@ -1632,7 +1577,6 @@ static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
1632 int status; 1577 int status;
1633 struct list_head *node, *next; 1578 struct list_head *node, *next;
1634 1579
1635 ACPI_FUNCTION_TRACE("acpi_video_bus_put_devices");
1636 1580
1637 list_for_each_safe(node, next, &video->video_device_list) { 1581 list_for_each_safe(node, next, &video->video_device_list) {
1638 struct acpi_video_device *data = 1582 struct acpi_video_device *data =
@@ -1651,7 +1595,7 @@ static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
1651 kfree(data); 1595 kfree(data);
1652 } 1596 }
1653 1597
1654 return_VALUE(0); 1598 return 0;
1655} 1599}
1656 1600
1657/* acpi_video interface */ 1601/* acpi_video interface */
@@ -1671,14 +1615,12 @@ static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data)
1671 struct acpi_video_bus *video = (struct acpi_video_bus *)data; 1615 struct acpi_video_bus *video = (struct acpi_video_bus *)data;
1672 struct acpi_device *device = NULL; 1616 struct acpi_device *device = NULL;
1673 1617
1674 ACPI_FUNCTION_TRACE("acpi_video_bus_notify");
1675 printk("video bus notify\n"); 1618 printk("video bus notify\n");
1676 1619
1677 if (!video) 1620 if (!video)
1678 return_VOID; 1621 return;
1679 1622
1680 if (acpi_bus_get_device(handle, &device)) 1623 device = video->device;
1681 return_VOID;
1682 1624
1683 switch (event) { 1625 switch (event) {
1684 case ACPI_VIDEO_NOTIFY_SWITCH: /* User request that a switch occur, 1626 case ACPI_VIDEO_NOTIFY_SWITCH: /* User request that a switch occur,
@@ -1707,7 +1649,7 @@ static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data)
1707 break; 1649 break;
1708 } 1650 }
1709 1651
1710 return_VOID; 1652 return;
1711} 1653}
1712 1654
1713static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data) 1655static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
@@ -1716,14 +1658,12 @@ static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
1716 (struct acpi_video_device *)data; 1658 (struct acpi_video_device *)data;
1717 struct acpi_device *device = NULL; 1659 struct acpi_device *device = NULL;
1718 1660
1719 ACPI_FUNCTION_TRACE("acpi_video_device_notify");
1720 1661
1721 printk("video device notify\n"); 1662 printk("video device notify\n");
1722 if (!video_device) 1663 if (!video_device)
1723 return_VOID; 1664 return;
1724 1665
1725 if (acpi_bus_get_device(handle, &device)) 1666 device = video_device->dev;
1726 return_VOID;
1727 1667
1728 switch (event) { 1668 switch (event) {
1729 case ACPI_VIDEO_NOTIFY_SWITCH: /* change in status (cycle output device) */ 1669 case ACPI_VIDEO_NOTIFY_SWITCH: /* change in status (cycle output device) */
@@ -1743,7 +1683,7 @@ static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
1743 "Unsupported event [0x%x]\n", event)); 1683 "Unsupported event [0x%x]\n", event));
1744 break; 1684 break;
1745 } 1685 }
1746 return_VOID; 1686 return;
1747} 1687}
1748 1688
1749static int acpi_video_bus_add(struct acpi_device *device) 1689static int acpi_video_bus_add(struct acpi_device *device)
@@ -1752,17 +1692,16 @@ static int acpi_video_bus_add(struct acpi_device *device)
1752 acpi_status status = 0; 1692 acpi_status status = 0;
1753 struct acpi_video_bus *video = NULL; 1693 struct acpi_video_bus *video = NULL;
1754 1694
1755 ACPI_FUNCTION_TRACE("acpi_video_bus_add");
1756 1695
1757 if (!device) 1696 if (!device)
1758 return_VALUE(-EINVAL); 1697 return -EINVAL;
1759 1698
1760 video = kmalloc(sizeof(struct acpi_video_bus), GFP_KERNEL); 1699 video = kmalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
1761 if (!video) 1700 if (!video)
1762 return_VALUE(-ENOMEM); 1701 return -ENOMEM;
1763 memset(video, 0, sizeof(struct acpi_video_bus)); 1702 memset(video, 0, sizeof(struct acpi_video_bus));
1764 1703
1765 video->handle = device->handle; 1704 video->device = device;
1766 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME); 1705 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
1767 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS); 1706 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1768 acpi_driver_data(device) = video; 1707 acpi_driver_data(device) = video;
@@ -1782,7 +1721,7 @@ static int acpi_video_bus_add(struct acpi_device *device)
1782 acpi_video_bus_get_devices(video, device); 1721 acpi_video_bus_get_devices(video, device);
1783 acpi_video_bus_start_devices(video); 1722 acpi_video_bus_start_devices(video);
1784 1723
1785 status = acpi_install_notify_handler(video->handle, 1724 status = acpi_install_notify_handler(device->handle,
1786 ACPI_DEVICE_NOTIFY, 1725 ACPI_DEVICE_NOTIFY,
1787 acpi_video_bus_notify, video); 1726 acpi_video_bus_notify, video);
1788 if (ACPI_FAILURE(status)) { 1727 if (ACPI_FAILURE(status)) {
@@ -1806,7 +1745,7 @@ static int acpi_video_bus_add(struct acpi_device *device)
1806 if (result) 1745 if (result)
1807 kfree(video); 1746 kfree(video);
1808 1747
1809 return_VALUE(result); 1748 return result;
1810} 1749}
1811 1750
1812static int acpi_video_bus_remove(struct acpi_device *device, int type) 1751static int acpi_video_bus_remove(struct acpi_device *device, int type)
@@ -1814,21 +1753,17 @@ static int acpi_video_bus_remove(struct acpi_device *device, int type)
1814 acpi_status status = 0; 1753 acpi_status status = 0;
1815 struct acpi_video_bus *video = NULL; 1754 struct acpi_video_bus *video = NULL;
1816 1755
1817 ACPI_FUNCTION_TRACE("acpi_video_bus_remove");
1818 1756
1819 if (!device || !acpi_driver_data(device)) 1757 if (!device || !acpi_driver_data(device))
1820 return_VALUE(-EINVAL); 1758 return -EINVAL;
1821 1759
1822 video = (struct acpi_video_bus *)acpi_driver_data(device); 1760 video = (struct acpi_video_bus *)acpi_driver_data(device);
1823 1761
1824 acpi_video_bus_stop_devices(video); 1762 acpi_video_bus_stop_devices(video);
1825 1763
1826 status = acpi_remove_notify_handler(video->handle, 1764 status = acpi_remove_notify_handler(video->device->handle,
1827 ACPI_DEVICE_NOTIFY, 1765 ACPI_DEVICE_NOTIFY,
1828 acpi_video_bus_notify); 1766 acpi_video_bus_notify);
1829 if (ACPI_FAILURE(status))
1830 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1831 "Error removing notify handler\n"));
1832 1767
1833 acpi_video_bus_put_devices(video); 1768 acpi_video_bus_put_devices(video);
1834 acpi_video_bus_remove_fs(device); 1769 acpi_video_bus_remove_fs(device);
@@ -1836,7 +1771,7 @@ static int acpi_video_bus_remove(struct acpi_device *device, int type)
1836 kfree(video->attached_array); 1771 kfree(video->attached_array);
1837 kfree(video); 1772 kfree(video);
1838 1773
1839 return_VALUE(0); 1774 return 0;
1840} 1775}
1841 1776
1842static int 1777static int
@@ -1846,10 +1781,9 @@ acpi_video_bus_match(struct acpi_device *device, struct acpi_driver *driver)
1846 acpi_handle h_dummy2; 1781 acpi_handle h_dummy2;
1847 acpi_handle h_dummy3; 1782 acpi_handle h_dummy3;
1848 1783
1849 ACPI_FUNCTION_TRACE("acpi_video_bus_match");
1850 1784
1851 if (!device || !driver) 1785 if (!device || !driver)
1852 return_VALUE(-EINVAL); 1786 return -EINVAL;
1853 1787
1854 /* Since there is no HID, CID for ACPI Video drivers, we have 1788 /* Since there is no HID, CID for ACPI Video drivers, we have
1855 * to check well known required nodes for each feature we support. 1789 * to check well known required nodes for each feature we support.
@@ -1858,26 +1792,25 @@ acpi_video_bus_match(struct acpi_device *device, struct acpi_driver *driver)
1858 /* Does this device able to support video switching ? */ 1792 /* Does this device able to support video switching ? */
1859 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_DOD", &h_dummy1)) && 1793 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_DOD", &h_dummy1)) &&
1860 ACPI_SUCCESS(acpi_get_handle(device->handle, "_DOS", &h_dummy2))) 1794 ACPI_SUCCESS(acpi_get_handle(device->handle, "_DOS", &h_dummy2)))
1861 return_VALUE(0); 1795 return 0;
1862 1796
1863 /* Does this device able to retrieve a video ROM ? */ 1797 /* Does this device able to retrieve a video ROM ? */
1864 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_ROM", &h_dummy1))) 1798 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_ROM", &h_dummy1)))
1865 return_VALUE(0); 1799 return 0;
1866 1800
1867 /* Does this device able to configure which video head to be POSTed ? */ 1801 /* Does this device able to configure which video head to be POSTed ? */
1868 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_VPO", &h_dummy1)) && 1802 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_VPO", &h_dummy1)) &&
1869 ACPI_SUCCESS(acpi_get_handle(device->handle, "_GPD", &h_dummy2)) && 1803 ACPI_SUCCESS(acpi_get_handle(device->handle, "_GPD", &h_dummy2)) &&
1870 ACPI_SUCCESS(acpi_get_handle(device->handle, "_SPD", &h_dummy3))) 1804 ACPI_SUCCESS(acpi_get_handle(device->handle, "_SPD", &h_dummy3)))
1871 return_VALUE(0); 1805 return 0;
1872 1806
1873 return_VALUE(-ENODEV); 1807 return -ENODEV;
1874} 1808}
1875 1809
1876static int __init acpi_video_init(void) 1810static int __init acpi_video_init(void)
1877{ 1811{
1878 int result = 0; 1812 int result = 0;
1879 1813
1880 ACPI_FUNCTION_TRACE("acpi_video_init");
1881 1814
1882 /* 1815 /*
1883 acpi_dbg_level = 0xFFFFFFFF; 1816 acpi_dbg_level = 0xFFFFFFFF;
@@ -1886,27 +1819,26 @@ static int __init acpi_video_init(void)
1886 1819
1887 acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir); 1820 acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir);
1888 if (!acpi_video_dir) 1821 if (!acpi_video_dir)
1889 return_VALUE(-ENODEV); 1822 return -ENODEV;
1890 acpi_video_dir->owner = THIS_MODULE; 1823 acpi_video_dir->owner = THIS_MODULE;
1891 1824
1892 result = acpi_bus_register_driver(&acpi_video_bus); 1825 result = acpi_bus_register_driver(&acpi_video_bus);
1893 if (result < 0) { 1826 if (result < 0) {
1894 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir); 1827 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
1895 return_VALUE(-ENODEV); 1828 return -ENODEV;
1896 } 1829 }
1897 1830
1898 return_VALUE(0); 1831 return 0;
1899} 1832}
1900 1833
1901static void __exit acpi_video_exit(void) 1834static void __exit acpi_video_exit(void)
1902{ 1835{
1903 ACPI_FUNCTION_TRACE("acpi_video_exit");
1904 1836
1905 acpi_bus_unregister_driver(&acpi_video_bus); 1837 acpi_bus_unregister_driver(&acpi_video_bus);
1906 1838
1907 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir); 1839 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
1908 1840
1909 return_VOID; 1841 return;
1910} 1842}
1911 1843
1912module_init(acpi_video_init); 1844module_init(acpi_video_init);