aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/glue.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/acpi/glue.c')
-rw-r--r--drivers/acpi/glue.c56
1 files changed, 39 insertions, 17 deletions
diff --git a/drivers/acpi/glue.c b/drivers/acpi/glue.c
index 08373086cd7e..01551840d236 100644
--- a/drivers/acpi/glue.c
+++ b/drivers/acpi/glue.c
@@ -130,46 +130,59 @@ static int acpi_bind_one(struct device *dev, acpi_handle handle)
130{ 130{
131 struct acpi_device *acpi_dev; 131 struct acpi_device *acpi_dev;
132 acpi_status status; 132 acpi_status status;
133 struct acpi_device_physical_node *physical_node; 133 struct acpi_device_physical_node *physical_node, *pn;
134 char physical_node_name[sizeof(PHYSICAL_NODE_STRING) + 2]; 134 char physical_node_name[sizeof(PHYSICAL_NODE_STRING) + 2];
135 int retval = -EINVAL; 135 int retval = -EINVAL;
136 136
137 if (dev->archdata.acpi_handle) { 137 if (ACPI_HANDLE(dev)) {
138 dev_warn(dev, "Drivers changed 'acpi_handle'\n"); 138 if (handle) {
139 return -EINVAL; 139 dev_warn(dev, "ACPI handle is already set\n");
140 return -EINVAL;
141 } else {
142 handle = ACPI_HANDLE(dev);
143 }
140 } 144 }
145 if (!handle)
146 return -EINVAL;
141 147
142 get_device(dev); 148 get_device(dev);
143 status = acpi_bus_get_device(handle, &acpi_dev); 149 status = acpi_bus_get_device(handle, &acpi_dev);
144 if (ACPI_FAILURE(status)) 150 if (ACPI_FAILURE(status))
145 goto err; 151 goto err;
146 152
147 physical_node = kzalloc(sizeof(struct acpi_device_physical_node), 153 physical_node = kzalloc(sizeof(*physical_node), GFP_KERNEL);
148 GFP_KERNEL);
149 if (!physical_node) { 154 if (!physical_node) {
150 retval = -ENOMEM; 155 retval = -ENOMEM;
151 goto err; 156 goto err;
152 } 157 }
153 158
154 mutex_lock(&acpi_dev->physical_node_lock); 159 mutex_lock(&acpi_dev->physical_node_lock);
160
161 /* Sanity check. */
162 list_for_each_entry(pn, &acpi_dev->physical_node_list, node)
163 if (pn->dev == dev) {
164 dev_warn(dev, "Already associated with ACPI node\n");
165 goto err_free;
166 }
167
155 /* allocate physical node id according to physical_node_id_bitmap */ 168 /* allocate physical node id according to physical_node_id_bitmap */
156 physical_node->node_id = 169 physical_node->node_id =
157 find_first_zero_bit(acpi_dev->physical_node_id_bitmap, 170 find_first_zero_bit(acpi_dev->physical_node_id_bitmap,
158 ACPI_MAX_PHYSICAL_NODE); 171 ACPI_MAX_PHYSICAL_NODE);
159 if (physical_node->node_id >= ACPI_MAX_PHYSICAL_NODE) { 172 if (physical_node->node_id >= ACPI_MAX_PHYSICAL_NODE) {
160 retval = -ENOSPC; 173 retval = -ENOSPC;
161 mutex_unlock(&acpi_dev->physical_node_lock); 174 goto err_free;
162 kfree(physical_node);
163 goto err;
164 } 175 }
165 176
166 set_bit(physical_node->node_id, acpi_dev->physical_node_id_bitmap); 177 set_bit(physical_node->node_id, acpi_dev->physical_node_id_bitmap);
167 physical_node->dev = dev; 178 physical_node->dev = dev;
168 list_add_tail(&physical_node->node, &acpi_dev->physical_node_list); 179 list_add_tail(&physical_node->node, &acpi_dev->physical_node_list);
169 acpi_dev->physical_node_count++; 180 acpi_dev->physical_node_count++;
181
170 mutex_unlock(&acpi_dev->physical_node_lock); 182 mutex_unlock(&acpi_dev->physical_node_lock);
171 183
172 dev->archdata.acpi_handle = handle; 184 if (!ACPI_HANDLE(dev))
185 ACPI_HANDLE_SET(dev, acpi_dev->handle);
173 186
174 if (!physical_node->node_id) 187 if (!physical_node->node_id)
175 strcpy(physical_node_name, PHYSICAL_NODE_STRING); 188 strcpy(physical_node_name, PHYSICAL_NODE_STRING);
@@ -187,8 +200,14 @@ static int acpi_bind_one(struct device *dev, acpi_handle handle)
187 return 0; 200 return 0;
188 201
189 err: 202 err:
203 ACPI_HANDLE_SET(dev, NULL);
190 put_device(dev); 204 put_device(dev);
191 return retval; 205 return retval;
206
207 err_free:
208 mutex_unlock(&acpi_dev->physical_node_lock);
209 kfree(physical_node);
210 goto err;
192} 211}
193 212
194static int acpi_unbind_one(struct device *dev) 213static int acpi_unbind_one(struct device *dev)
@@ -198,11 +217,10 @@ static int acpi_unbind_one(struct device *dev)
198 acpi_status status; 217 acpi_status status;
199 struct list_head *node, *next; 218 struct list_head *node, *next;
200 219
201 if (!dev->archdata.acpi_handle) 220 if (!ACPI_HANDLE(dev))
202 return 0; 221 return 0;
203 222
204 status = acpi_bus_get_device(dev->archdata.acpi_handle, 223 status = acpi_bus_get_device(ACPI_HANDLE(dev), &acpi_dev);
205 &acpi_dev);
206 if (ACPI_FAILURE(status)) 224 if (ACPI_FAILURE(status))
207 goto err; 225 goto err;
208 226
@@ -228,7 +246,7 @@ static int acpi_unbind_one(struct device *dev)
228 246
229 sysfs_remove_link(&acpi_dev->dev.kobj, physical_node_name); 247 sysfs_remove_link(&acpi_dev->dev.kobj, physical_node_name);
230 sysfs_remove_link(&dev->kobj, "firmware_node"); 248 sysfs_remove_link(&dev->kobj, "firmware_node");
231 dev->archdata.acpi_handle = NULL; 249 ACPI_HANDLE_SET(dev, NULL);
232 /* acpi_bind_one increase refcnt by one */ 250 /* acpi_bind_one increase refcnt by one */
233 put_device(dev); 251 put_device(dev);
234 kfree(entry); 252 kfree(entry);
@@ -248,6 +266,10 @@ static int acpi_platform_notify(struct device *dev)
248 acpi_handle handle; 266 acpi_handle handle;
249 int ret = -EINVAL; 267 int ret = -EINVAL;
250 268
269 ret = acpi_bind_one(dev, NULL);
270 if (!ret)
271 goto out;
272
251 if (!dev->bus || !dev->parent) { 273 if (!dev->bus || !dev->parent) {
252 /* bridge devices genernally haven't bus or parent */ 274 /* bridge devices genernally haven't bus or parent */
253 ret = acpi_find_bridge_device(dev, &handle); 275 ret = acpi_find_bridge_device(dev, &handle);
@@ -261,16 +283,16 @@ static int acpi_platform_notify(struct device *dev)
261 } 283 }
262 if ((ret = type->find_device(dev, &handle)) != 0) 284 if ((ret = type->find_device(dev, &handle)) != 0)
263 DBG("Can't get handler for %s\n", dev_name(dev)); 285 DBG("Can't get handler for %s\n", dev_name(dev));
264 end: 286 end:
265 if (!ret) 287 if (!ret)
266 acpi_bind_one(dev, handle); 288 acpi_bind_one(dev, handle);
267 289
290 out:
268#if ACPI_GLUE_DEBUG 291#if ACPI_GLUE_DEBUG
269 if (!ret) { 292 if (!ret) {
270 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; 293 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
271 294
272 acpi_get_name(dev->archdata.acpi_handle, 295 acpi_get_name(dev->acpi_handle, ACPI_FULL_PATHNAME, &buffer);
273 ACPI_FULL_PATHNAME, &buffer);
274 DBG("Device %s -> %s\n", dev_name(dev), (char *)buffer.pointer); 296 DBG("Device %s -> %s\n", dev_name(dev), (char *)buffer.pointer);
275 kfree(buffer.pointer); 297 kfree(buffer.pointer);
276 } else 298 } else