aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/acpi/glue.c135
-rw-r--r--drivers/acpi/proc.c57
-rw-r--r--drivers/acpi/scan.c2
-rw-r--r--drivers/pnp/pnpacpi/core.c7
-rw-r--r--include/acpi/acpi_bus.h15
5 files changed, 139 insertions, 77 deletions
diff --git a/drivers/acpi/glue.c b/drivers/acpi/glue.c
index 243ee85e4d2e..d1a2d74033e9 100644
--- a/drivers/acpi/glue.c
+++ b/drivers/acpi/glue.c
@@ -25,6 +25,8 @@
25static LIST_HEAD(bus_type_list); 25static LIST_HEAD(bus_type_list);
26static DECLARE_RWSEM(bus_type_sem); 26static DECLARE_RWSEM(bus_type_sem);
27 27
28#define PHYSICAL_NODE_STRING "physical_node"
29
28int register_acpi_bus_type(struct acpi_bus_type *type) 30int register_acpi_bus_type(struct acpi_bus_type *type)
29{ 31{
30 if (acpi_disabled) 32 if (acpi_disabled)
@@ -124,84 +126,119 @@ acpi_handle acpi_get_child(acpi_handle parent, u64 address)
124 126
125EXPORT_SYMBOL(acpi_get_child); 127EXPORT_SYMBOL(acpi_get_child);
126 128
127/* Link ACPI devices with physical devices */
128static void acpi_glue_data_handler(acpi_handle handle,
129 void *context)
130{
131 /* we provide an empty handler */
132}
133
134/* Note: a success call will increase reference count by one */
135struct device *acpi_get_physical_device(acpi_handle handle)
136{
137 acpi_status status;
138 struct device *dev;
139
140 status = acpi_get_data(handle, acpi_glue_data_handler, (void **)&dev);
141 if (ACPI_SUCCESS(status))
142 return get_device(dev);
143 return NULL;
144}
145
146EXPORT_SYMBOL(acpi_get_physical_device);
147
148static int acpi_bind_one(struct device *dev, acpi_handle handle) 129static int acpi_bind_one(struct device *dev, acpi_handle handle)
149{ 130{
150 struct acpi_device *acpi_dev; 131 struct acpi_device *acpi_dev;
151 acpi_status status; 132 acpi_status status;
133 struct acpi_device_physical_node *physical_node;
134 char physical_node_name[sizeof(PHYSICAL_NODE_STRING) + 2];
135 int retval = -EINVAL;
152 136
153 if (dev->archdata.acpi_handle) { 137 if (dev->archdata.acpi_handle) {
154 dev_warn(dev, "Drivers changed 'acpi_handle'\n"); 138 dev_warn(dev, "Drivers changed 'acpi_handle'\n");
155 return -EINVAL; 139 return -EINVAL;
156 } 140 }
141
157 get_device(dev); 142 get_device(dev);
158 status = acpi_attach_data(handle, acpi_glue_data_handler, dev); 143 status = acpi_bus_get_device(handle, &acpi_dev);
159 if (ACPI_FAILURE(status)) { 144 if (ACPI_FAILURE(status))
160 put_device(dev); 145 goto err;
161 return -EINVAL; 146
147 physical_node = kzalloc(sizeof(struct acpi_device_physical_node),
148 GFP_KERNEL);
149 if (!physical_node) {
150 retval = -ENOMEM;
151 goto err;
162 } 152 }
163 dev->archdata.acpi_handle = handle;
164 153
165 status = acpi_bus_get_device(handle, &acpi_dev); 154 mutex_lock(&acpi_dev->physical_node_lock);
166 if (!ACPI_FAILURE(status)) { 155 /* allocate physical node id according to physical_node_id_bitmap */
167 int ret; 156 physical_node->node_id =
168 157 find_first_zero_bit(acpi_dev->physical_node_id_bitmap,
169 ret = sysfs_create_link(&dev->kobj, &acpi_dev->dev.kobj, 158 ACPI_MAX_PHYSICAL_NODE);
170 "firmware_node"); 159 if (physical_node->node_id >= ACPI_MAX_PHYSICAL_NODE) {
171 ret = sysfs_create_link(&acpi_dev->dev.kobj, &dev->kobj, 160 retval = -ENOSPC;
172 "physical_node"); 161 mutex_unlock(&acpi_dev->physical_node_lock);
173 if (acpi_dev->wakeup.flags.valid) 162 goto err;
174 device_set_wakeup_capable(dev, true);
175 } 163 }
176 164
165 set_bit(physical_node->node_id, acpi_dev->physical_node_id_bitmap);
166 physical_node->dev = dev;
167 list_add_tail(&physical_node->node, &acpi_dev->physical_node_list);
168 acpi_dev->physical_node_count++;
169 mutex_unlock(&acpi_dev->physical_node_lock);
170
171 dev->archdata.acpi_handle = handle;
172
173 if (!physical_node->node_id)
174 strcpy(physical_node_name, PHYSICAL_NODE_STRING);
175 else
176 sprintf(physical_node_name,
177 "physical_node%d", physical_node->node_id);
178 retval = sysfs_create_link(&acpi_dev->dev.kobj, &dev->kobj,
179 physical_node_name);
180 retval = sysfs_create_link(&dev->kobj, &acpi_dev->dev.kobj,
181 "firmware_node");
182
183 if (acpi_dev->wakeup.flags.valid)
184 device_set_wakeup_capable(dev, true);
185
177 return 0; 186 return 0;
187
188 err:
189 put_device(dev);
190 return retval;
178} 191}
179 192
180static int acpi_unbind_one(struct device *dev) 193static int acpi_unbind_one(struct device *dev)
181{ 194{
195 struct acpi_device_physical_node *entry;
196 struct acpi_device *acpi_dev;
197 acpi_status status;
198 struct list_head *node, *next;
199
182 if (!dev->archdata.acpi_handle) 200 if (!dev->archdata.acpi_handle)
183 return 0; 201 return 0;
184 if (dev == acpi_get_physical_device(dev->archdata.acpi_handle)) {
185 struct acpi_device *acpi_dev;
186 202
187 /* acpi_get_physical_device increase refcnt by one */ 203 status = acpi_bus_get_device(dev->archdata.acpi_handle,
188 put_device(dev); 204 &acpi_dev);
205 if (ACPI_FAILURE(status))
206 goto err;
189 207
190 if (!acpi_bus_get_device(dev->archdata.acpi_handle, 208 mutex_lock(&acpi_dev->physical_node_lock);
191 &acpi_dev)) { 209 list_for_each_safe(node, next, &acpi_dev->physical_node_list) {
192 sysfs_remove_link(&dev->kobj, "firmware_node"); 210 char physical_node_name[sizeof(PHYSICAL_NODE_STRING) + 2];
193 sysfs_remove_link(&acpi_dev->dev.kobj, "physical_node"); 211
194 } 212 entry = list_entry(node, struct acpi_device_physical_node,
213 node);
214 if (entry->dev != dev)
215 continue;
216
217 list_del(node);
218 clear_bit(entry->node_id, acpi_dev->physical_node_id_bitmap);
195 219
196 acpi_detach_data(dev->archdata.acpi_handle, 220 acpi_dev->physical_node_count--;
197 acpi_glue_data_handler); 221
222 if (!entry->node_id)
223 strcpy(physical_node_name, PHYSICAL_NODE_STRING);
224 else
225 sprintf(physical_node_name,
226 "physical_node%d", entry->node_id);
227
228 sysfs_remove_link(&acpi_dev->dev.kobj, physical_node_name);
229 sysfs_remove_link(&dev->kobj, "firmware_node");
198 dev->archdata.acpi_handle = NULL; 230 dev->archdata.acpi_handle = NULL;
199 /* acpi_bind_one increase refcnt by one */ 231 /* acpi_bind_one increase refcnt by one */
200 put_device(dev); 232 put_device(dev);
201 } else { 233 kfree(entry);
202 dev_err(dev, "Oops, 'acpi_handle' corrupt\n");
203 } 234 }
235 mutex_unlock(&acpi_dev->physical_node_lock);
236
204 return 0; 237 return 0;
238
239err:
240 dev_err(dev, "Oops, 'acpi_handle' corrupt\n");
241 return -EINVAL;
205} 242}
206 243
207static int acpi_platform_notify(struct device *dev) 244static int acpi_platform_notify(struct device *dev)
diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
index 251c7b6273a9..27adb090bb30 100644
--- a/drivers/acpi/proc.c
+++ b/drivers/acpi/proc.c
@@ -302,26 +302,41 @@ acpi_system_wakeup_device_seq_show(struct seq_file *seq, void *offset)
302 list_for_each_safe(node, next, &acpi_wakeup_device_list) { 302 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
303 struct acpi_device *dev = 303 struct acpi_device *dev =
304 container_of(node, struct acpi_device, wakeup_list); 304 container_of(node, struct acpi_device, wakeup_list);
305 struct device *ldev; 305 struct acpi_device_physical_node *entry;
306 306
307 if (!dev->wakeup.flags.valid) 307 if (!dev->wakeup.flags.valid)
308 continue; 308 continue;
309 309
310 ldev = acpi_get_physical_device(dev->handle); 310 seq_printf(seq, "%s\t S%d\t",
311 seq_printf(seq, "%s\t S%d\t%c%-8s ",
312 dev->pnp.bus_id, 311 dev->pnp.bus_id,
313 (u32) dev->wakeup.sleep_state, 312 (u32) dev->wakeup.sleep_state);
314 dev->wakeup.flags.run_wake ? '*' : ' ', 313
315 (device_may_wakeup(&dev->dev) 314 if (!dev->physical_node_count)
316 || (ldev && device_may_wakeup(ldev))) ? 315 seq_printf(seq, "%c%-8s\n",
317 "enabled" : "disabled"); 316 dev->wakeup.flags.run_wake ?
318 if (ldev) 317 '*' : ' ', "disabled");
319 seq_printf(seq, "%s:%s", 318 else {
320 ldev->bus ? ldev->bus->name : "no-bus", 319 struct device *ldev;
321 dev_name(ldev)); 320 list_for_each_entry(entry, &dev->physical_node_list,
322 seq_printf(seq, "\n"); 321 node) {
323 put_device(ldev); 322 ldev = get_device(entry->dev);
324 323 if (!ldev)
324 continue;
325
326 if (&entry->node !=
327 dev->physical_node_list.next)
328 seq_printf(seq, "\t\t");
329
330 seq_printf(seq, "%c%-8s %s:%s\n",
331 dev->wakeup.flags.run_wake ? '*' : ' ',
332 (device_may_wakeup(&dev->dev) ||
333 (ldev && device_may_wakeup(ldev))) ?
334 "enabled" : "disabled",
335 ldev->bus ? ldev->bus->name :
336 "no-bus", dev_name(ldev));
337 put_device(ldev);
338 }
339 }
325 } 340 }
326 mutex_unlock(&acpi_device_lock); 341 mutex_unlock(&acpi_device_lock);
327 return 0; 342 return 0;
@@ -329,12 +344,14 @@ acpi_system_wakeup_device_seq_show(struct seq_file *seq, void *offset)
329 344
330static void physical_device_enable_wakeup(struct acpi_device *adev) 345static void physical_device_enable_wakeup(struct acpi_device *adev)
331{ 346{
332 struct device *dev = acpi_get_physical_device(adev->handle); 347 struct acpi_device_physical_node *entry;
333 348
334 if (dev && device_can_wakeup(dev)) { 349 list_for_each_entry(entry,
335 bool enable = !device_may_wakeup(dev); 350 &adev->physical_node_list, node)
336 device_set_wakeup_enable(dev, enable); 351 if (entry->dev && device_can_wakeup(entry->dev)) {
337 } 352 bool enable = !device_may_wakeup(entry->dev);
353 device_set_wakeup_enable(entry->dev, enable);
354 }
338} 355}
339 356
340static ssize_t 357static ssize_t
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index d1ecca2b641a..d730a939ead1 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -481,6 +481,8 @@ static int acpi_device_register(struct acpi_device *device)
481 INIT_LIST_HEAD(&device->children); 481 INIT_LIST_HEAD(&device->children);
482 INIT_LIST_HEAD(&device->node); 482 INIT_LIST_HEAD(&device->node);
483 INIT_LIST_HEAD(&device->wakeup_list); 483 INIT_LIST_HEAD(&device->wakeup_list);
484 INIT_LIST_HEAD(&device->physical_node_list);
485 mutex_init(&device->physical_node_lock);
484 486
485 new_bus_id = kzalloc(sizeof(struct acpi_device_bus_id), GFP_KERNEL); 487 new_bus_id = kzalloc(sizeof(struct acpi_device_bus_id), GFP_KERNEL);
486 if (!new_bus_id) { 488 if (!new_bus_id) {
diff --git a/drivers/pnp/pnpacpi/core.c b/drivers/pnp/pnpacpi/core.c
index 507a8e2b9a4c..26b5d4b18dd7 100644
--- a/drivers/pnp/pnpacpi/core.c
+++ b/drivers/pnp/pnpacpi/core.c
@@ -321,14 +321,9 @@ static int __init acpi_pnp_match(struct device *dev, void *_pnp)
321{ 321{
322 struct acpi_device *acpi = to_acpi_device(dev); 322 struct acpi_device *acpi = to_acpi_device(dev);
323 struct pnp_dev *pnp = _pnp; 323 struct pnp_dev *pnp = _pnp;
324 struct device *physical_device;
325
326 physical_device = acpi_get_physical_device(acpi->handle);
327 if (physical_device)
328 put_device(physical_device);
329 324
330 /* true means it matched */ 325 /* true means it matched */
331 return !physical_device 326 return !acpi->physical_node_count
332 && compare_pnp_id(pnp->id, acpi_device_hid(acpi)); 327 && compare_pnp_id(pnp->id, acpi_device_hid(acpi));
333} 328}
334 329
diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
index bde976ee068d..453596d4ce65 100644
--- a/include/acpi/acpi_bus.h
+++ b/include/acpi/acpi_bus.h
@@ -282,8 +282,16 @@ struct acpi_device_wakeup {
282 int prepare_count; 282 int prepare_count;
283}; 283};
284 284
285/* Device */ 285struct acpi_device_physical_node {
286 u8 node_id;
287 struct list_head node;
288 struct device *dev;
289};
286 290
291/* set maximum of physical nodes to 32 for expansibility */
292#define ACPI_MAX_PHYSICAL_NODE 32
293
294/* Device */
287struct acpi_device { 295struct acpi_device {
288 int device_type; 296 int device_type;
289 acpi_handle handle; /* no handle for fixed hardware */ 297 acpi_handle handle; /* no handle for fixed hardware */
@@ -304,6 +312,10 @@ struct acpi_device {
304 struct device dev; 312 struct device dev;
305 struct acpi_bus_ops bus_ops; /* workaround for different code path for hotplug */ 313 struct acpi_bus_ops bus_ops; /* workaround for different code path for hotplug */
306 enum acpi_bus_removal_type removal_type; /* indicate for different removal type */ 314 enum acpi_bus_removal_type removal_type; /* indicate for different removal type */
315 u8 physical_node_count;
316 struct list_head physical_node_list;
317 struct mutex physical_node_lock;
318 DECLARE_BITMAP(physical_node_id_bitmap, ACPI_MAX_PHYSICAL_NODE);
307}; 319};
308 320
309static inline void *acpi_driver_data(struct acpi_device *d) 321static inline void *acpi_driver_data(struct acpi_device *d)
@@ -394,7 +406,6 @@ struct acpi_bus_type {
394}; 406};
395int register_acpi_bus_type(struct acpi_bus_type *); 407int register_acpi_bus_type(struct acpi_bus_type *);
396int unregister_acpi_bus_type(struct acpi_bus_type *); 408int unregister_acpi_bus_type(struct acpi_bus_type *);
397struct device *acpi_get_physical_device(acpi_handle);
398 409
399struct acpi_pci_root { 410struct acpi_pci_root {
400 struct list_head node; 411 struct list_head node;