aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/pci_bind.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/acpi/pci_bind.c')
-rw-r--r--drivers/acpi/pci_bind.c220
1 files changed, 104 insertions, 116 deletions
diff --git a/drivers/acpi/pci_bind.c b/drivers/acpi/pci_bind.c
index 5148f3c10b5c..2a718df769b5 100644
--- a/drivers/acpi/pci_bind.c
+++ b/drivers/acpi/pci_bind.c
@@ -35,22 +35,17 @@
35#include <acpi/acpi_bus.h> 35#include <acpi/acpi_bus.h>
36#include <acpi/acpi_drivers.h> 36#include <acpi/acpi_drivers.h>
37 37
38
39#define _COMPONENT ACPI_PCI_COMPONENT 38#define _COMPONENT ACPI_PCI_COMPONENT
40ACPI_MODULE_NAME ("pci_bind") 39ACPI_MODULE_NAME("pci_bind")
41 40
42struct acpi_pci_data { 41struct acpi_pci_data {
43 struct acpi_pci_id id; 42 struct acpi_pci_id id;
44 struct pci_bus *bus; 43 struct pci_bus *bus;
45 struct pci_dev *dev; 44 struct pci_dev *dev;
46}; 45};
47 46
48 47static void acpi_pci_data_handler(acpi_handle handle, u32 function,
49void 48 void *context)
50acpi_pci_data_handler (
51 acpi_handle handle,
52 u32 function,
53 void *context)
54{ 49{
55 ACPI_FUNCTION_TRACE("acpi_pci_data_handler"); 50 ACPI_FUNCTION_TRACE("acpi_pci_data_handler");
56 51
@@ -59,7 +54,6 @@ acpi_pci_data_handler (
59 return_VOID; 54 return_VOID;
60} 55}
61 56
62
63/** 57/**
64 * acpi_get_pci_id 58 * acpi_get_pci_id
65 * ------------------ 59 * ------------------
@@ -67,15 +61,12 @@ acpi_pci_data_handler (
67 * to resolve PCI information for ACPI-PCI devices defined in the namespace. 61 * to resolve PCI information for ACPI-PCI devices defined in the namespace.
68 * This typically occurs when resolving PCI operation region information. 62 * This typically occurs when resolving PCI operation region information.
69 */ 63 */
70acpi_status 64acpi_status acpi_get_pci_id(acpi_handle handle, struct acpi_pci_id *id)
71acpi_get_pci_id (
72 acpi_handle handle,
73 struct acpi_pci_id *id)
74{ 65{
75 int result = 0; 66 int result = 0;
76 acpi_status status = AE_OK; 67 acpi_status status = AE_OK;
77 struct acpi_device *device = NULL; 68 struct acpi_device *device = NULL;
78 struct acpi_pci_data *data = NULL; 69 struct acpi_pci_data *data = NULL;
79 70
80 ACPI_FUNCTION_TRACE("acpi_get_pci_id"); 71 ACPI_FUNCTION_TRACE("acpi_get_pci_id");
81 72
@@ -84,52 +75,50 @@ acpi_get_pci_id (
84 75
85 result = acpi_bus_get_device(handle, &device); 76 result = acpi_bus_get_device(handle, &device);
86 if (result) { 77 if (result) {
87 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 78 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
88 "Invalid ACPI Bus context for device %s\n", 79 "Invalid ACPI Bus context for device %s\n",
89 acpi_device_bid(device))); 80 acpi_device_bid(device)));
90 return_ACPI_STATUS(AE_NOT_EXIST); 81 return_ACPI_STATUS(AE_NOT_EXIST);
91 } 82 }
92 83
93 status = acpi_get_data(handle, acpi_pci_data_handler, (void**) &data); 84 status = acpi_get_data(handle, acpi_pci_data_handler, (void **)&data);
94 if (ACPI_FAILURE(status) || !data) { 85 if (ACPI_FAILURE(status) || !data) {
95 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 86 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
96 "Invalid ACPI-PCI context for device %s\n", 87 "Invalid ACPI-PCI context for device %s\n",
97 acpi_device_bid(device))); 88 acpi_device_bid(device)));
98 return_ACPI_STATUS(status); 89 return_ACPI_STATUS(status);
99 } 90 }
100 91
101 *id = data->id; 92 *id = data->id;
102 93
103 /* 94 /*
104 id->segment = data->id.segment; 95 id->segment = data->id.segment;
105 id->bus = data->id.bus; 96 id->bus = data->id.bus;
106 id->device = data->id.device; 97 id->device = data->id.device;
107 id->function = data->id.function; 98 id->function = data->id.function;
108 */ 99 */
109 100
110 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 101 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
111 "Device %s has PCI address %02x:%02x:%02x.%02x\n", 102 "Device %s has PCI address %02x:%02x:%02x.%02x\n",
112 acpi_device_bid(device), id->segment, id->bus, 103 acpi_device_bid(device), id->segment, id->bus,
113 id->device, id->function)); 104 id->device, id->function));
114 105
115 return_ACPI_STATUS(AE_OK); 106 return_ACPI_STATUS(AE_OK);
116} 107}
108
117EXPORT_SYMBOL(acpi_get_pci_id); 109EXPORT_SYMBOL(acpi_get_pci_id);
118 110
119 111int acpi_pci_bind(struct acpi_device *device)
120int
121acpi_pci_bind (
122 struct acpi_device *device)
123{ 112{
124 int result = 0; 113 int result = 0;
125 acpi_status status = AE_OK; 114 acpi_status status = AE_OK;
126 struct acpi_pci_data *data = NULL; 115 struct acpi_pci_data *data = NULL;
127 struct acpi_pci_data *pdata = NULL; 116 struct acpi_pci_data *pdata = NULL;
128 char *pathname = NULL; 117 char *pathname = NULL;
129 struct acpi_buffer buffer = {0, NULL}; 118 struct acpi_buffer buffer = { 0, NULL };
130 acpi_handle handle = NULL; 119 acpi_handle handle = NULL;
131 struct pci_dev *dev; 120 struct pci_dev *dev;
132 struct pci_bus *bus; 121 struct pci_bus *bus;
133 122
134 ACPI_FUNCTION_TRACE("acpi_pci_bind"); 123 ACPI_FUNCTION_TRACE("acpi_pci_bind");
135 124
@@ -137,34 +126,34 @@ acpi_pci_bind (
137 return_VALUE(-EINVAL); 126 return_VALUE(-EINVAL);
138 127
139 pathname = kmalloc(ACPI_PATHNAME_MAX, GFP_KERNEL); 128 pathname = kmalloc(ACPI_PATHNAME_MAX, GFP_KERNEL);
140 if(!pathname) 129 if (!pathname)
141 return_VALUE(-ENOMEM); 130 return_VALUE(-ENOMEM);
142 memset(pathname, 0, ACPI_PATHNAME_MAX); 131 memset(pathname, 0, ACPI_PATHNAME_MAX);
143 buffer.length = ACPI_PATHNAME_MAX; 132 buffer.length = ACPI_PATHNAME_MAX;
144 buffer.pointer = pathname; 133 buffer.pointer = pathname;
145 134
146 data = kmalloc(sizeof(struct acpi_pci_data), GFP_KERNEL); 135 data = kmalloc(sizeof(struct acpi_pci_data), GFP_KERNEL);
147 if (!data){ 136 if (!data) {
148 kfree (pathname); 137 kfree(pathname);
149 return_VALUE(-ENOMEM); 138 return_VALUE(-ENOMEM);
150 } 139 }
151 memset(data, 0, sizeof(struct acpi_pci_data)); 140 memset(data, 0, sizeof(struct acpi_pci_data));
152 141
153 acpi_get_name(device->handle, ACPI_FULL_PATHNAME, &buffer); 142 acpi_get_name(device->handle, ACPI_FULL_PATHNAME, &buffer);
154 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Binding PCI device [%s]...\n", 143 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Binding PCI device [%s]...\n",
155 pathname)); 144 pathname));
156 145
157 /* 146 /*
158 * Segment & Bus 147 * Segment & Bus
159 * ------------- 148 * -------------
160 * These are obtained via the parent device's ACPI-PCI context. 149 * These are obtained via the parent device's ACPI-PCI context.
161 */ 150 */
162 status = acpi_get_data(device->parent->handle, acpi_pci_data_handler, 151 status = acpi_get_data(device->parent->handle, acpi_pci_data_handler,
163 (void**) &pdata); 152 (void **)&pdata);
164 if (ACPI_FAILURE(status) || !pdata || !pdata->bus) { 153 if (ACPI_FAILURE(status) || !pdata || !pdata->bus) {
165 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 154 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
166 "Invalid ACPI-PCI context for parent device %s\n", 155 "Invalid ACPI-PCI context for parent device %s\n",
167 acpi_device_bid(device->parent))); 156 acpi_device_bid(device->parent)));
168 result = -ENODEV; 157 result = -ENODEV;
169 goto end; 158 goto end;
170 } 159 }
@@ -181,8 +170,8 @@ acpi_pci_bind (
181 data->id.function = device->pnp.bus_address & 0xFFFF; 170 data->id.function = device->pnp.bus_address & 0xFFFF;
182 171
183 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "...to %02x:%02x:%02x.%02x\n", 172 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "...to %02x:%02x:%02x.%02x\n",
184 data->id.segment, data->id.bus, data->id.device, 173 data->id.segment, data->id.bus, data->id.device,
185 data->id.function)); 174 data->id.function));
186 175
187 /* 176 /*
188 * TBD: Support slot devices (e.g. function=0xFFFF). 177 * TBD: Support slot devices (e.g. function=0xFFFF).
@@ -202,25 +191,25 @@ acpi_pci_bind (
202 if (bus) { 191 if (bus) {
203 list_for_each_entry(dev, &bus->devices, bus_list) { 192 list_for_each_entry(dev, &bus->devices, bus_list) {
204 if (dev->devfn == PCI_DEVFN(data->id.device, 193 if (dev->devfn == PCI_DEVFN(data->id.device,
205 data->id.function)) { 194 data->id.function)) {
206 data->dev = dev; 195 data->dev = dev;
207 break; 196 break;
208 } 197 }
209 } 198 }
210 } 199 }
211 if (!data->dev) { 200 if (!data->dev) {
212 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 201 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
213 "Device %02x:%02x:%02x.%02x not present in PCI namespace\n", 202 "Device %02x:%02x:%02x.%02x not present in PCI namespace\n",
214 data->id.segment, data->id.bus, 203 data->id.segment, data->id.bus,
215 data->id.device, data->id.function)); 204 data->id.device, data->id.function));
216 result = -ENODEV; 205 result = -ENODEV;
217 goto end; 206 goto end;
218 } 207 }
219 if (!data->dev->bus) { 208 if (!data->dev->bus) {
220 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 209 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
221 "Device %02x:%02x:%02x.%02x has invalid 'bus' field\n", 210 "Device %02x:%02x:%02x.%02x has invalid 'bus' field\n",
222 data->id.segment, data->id.bus, 211 data->id.segment, data->id.bus,
223 data->id.device, data->id.function)); 212 data->id.device, data->id.function));
224 result = -ENODEV; 213 result = -ENODEV;
225 goto end; 214 goto end;
226 } 215 }
@@ -232,10 +221,10 @@ acpi_pci_bind (
232 * facilitate callbacks for all of its children. 221 * facilitate callbacks for all of its children.
233 */ 222 */
234 if (data->dev->subordinate) { 223 if (data->dev->subordinate) {
235 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 224 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
236 "Device %02x:%02x:%02x.%02x is a PCI bridge\n", 225 "Device %02x:%02x:%02x.%02x is a PCI bridge\n",
237 data->id.segment, data->id.bus, 226 data->id.segment, data->id.bus,
238 data->id.device, data->id.function)); 227 data->id.device, data->id.function));
239 data->bus = data->dev->subordinate; 228 data->bus = data->dev->subordinate;
240 device->ops.bind = acpi_pci_bind; 229 device->ops.bind = acpi_pci_bind;
241 device->ops.unbind = acpi_pci_unbind; 230 device->ops.unbind = acpi_pci_unbind;
@@ -249,8 +238,8 @@ acpi_pci_bind (
249 status = acpi_attach_data(device->handle, acpi_pci_data_handler, data); 238 status = acpi_attach_data(device->handle, acpi_pci_data_handler, data);
250 if (ACPI_FAILURE(status)) { 239 if (ACPI_FAILURE(status)) {
251 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 240 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
252 "Unable to attach ACPI-PCI context to device %s\n", 241 "Unable to attach ACPI-PCI context to device %s\n",
253 acpi_device_bid(device))); 242 acpi_device_bid(device)));
254 result = -ENODEV; 243 result = -ENODEV;
255 goto end; 244 goto end;
256 } 245 }
@@ -267,15 +256,15 @@ acpi_pci_bind (
267 */ 256 */
268 status = acpi_get_handle(device->handle, METHOD_NAME__PRT, &handle); 257 status = acpi_get_handle(device->handle, METHOD_NAME__PRT, &handle);
269 if (ACPI_SUCCESS(status)) { 258 if (ACPI_SUCCESS(status)) {
270 if (data->bus) /* PCI-PCI bridge */ 259 if (data->bus) /* PCI-PCI bridge */
271 acpi_pci_irq_add_prt(device->handle, data->id.segment,
272 data->bus->number);
273 else /* non-bridge PCI device */
274 acpi_pci_irq_add_prt(device->handle, data->id.segment, 260 acpi_pci_irq_add_prt(device->handle, data->id.segment,
275 data->id.bus); 261 data->bus->number);
262 else /* non-bridge PCI device */
263 acpi_pci_irq_add_prt(device->handle, data->id.segment,
264 data->id.bus);
276 } 265 }
277 266
278end: 267 end:
279 kfree(pathname); 268 kfree(pathname);
280 if (result) 269 if (result)
281 kfree(data); 270 kfree(data);
@@ -283,22 +272,21 @@ end:
283 return_VALUE(result); 272 return_VALUE(result);
284} 273}
285 274
286int acpi_pci_unbind( 275int acpi_pci_unbind(struct acpi_device *device)
287 struct acpi_device *device)
288{ 276{
289 int result = 0; 277 int result = 0;
290 acpi_status status = AE_OK; 278 acpi_status status = AE_OK;
291 struct acpi_pci_data *data = NULL; 279 struct acpi_pci_data *data = NULL;
292 char *pathname = NULL; 280 char *pathname = NULL;
293 struct acpi_buffer buffer = {0, NULL}; 281 struct acpi_buffer buffer = { 0, NULL };
294 282
295 ACPI_FUNCTION_TRACE("acpi_pci_unbind"); 283 ACPI_FUNCTION_TRACE("acpi_pci_unbind");
296 284
297 if (!device || !device->parent) 285 if (!device || !device->parent)
298 return_VALUE(-EINVAL); 286 return_VALUE(-EINVAL);
299 287
300 pathname = (char *) kmalloc(ACPI_PATHNAME_MAX, GFP_KERNEL); 288 pathname = (char *)kmalloc(ACPI_PATHNAME_MAX, GFP_KERNEL);
301 if(!pathname) 289 if (!pathname)
302 return_VALUE(-ENOMEM); 290 return_VALUE(-ENOMEM);
303 memset(pathname, 0, ACPI_PATHNAME_MAX); 291 memset(pathname, 0, ACPI_PATHNAME_MAX);
304 292
@@ -306,14 +294,16 @@ int acpi_pci_unbind(
306 buffer.pointer = pathname; 294 buffer.pointer = pathname;
307 acpi_get_name(device->handle, ACPI_FULL_PATHNAME, &buffer); 295 acpi_get_name(device->handle, ACPI_FULL_PATHNAME, &buffer);
308 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Unbinding PCI device [%s]...\n", 296 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Unbinding PCI device [%s]...\n",
309 pathname)); 297 pathname));
310 kfree(pathname); 298 kfree(pathname);
311 299
312 status = acpi_get_data(device->handle, acpi_pci_data_handler, (void**)&data); 300 status =
301 acpi_get_data(device->handle, acpi_pci_data_handler,
302 (void **)&data);
313 if (ACPI_FAILURE(status)) { 303 if (ACPI_FAILURE(status)) {
314 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 304 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
315 "Unable to get data from device %s\n", 305 "Unable to get data from device %s\n",
316 acpi_device_bid(device))); 306 acpi_device_bid(device)));
317 result = -ENODEV; 307 result = -ENODEV;
318 goto end; 308 goto end;
319 } 309 }
@@ -321,8 +311,8 @@ int acpi_pci_unbind(
321 status = acpi_detach_data(device->handle, acpi_pci_data_handler); 311 status = acpi_detach_data(device->handle, acpi_pci_data_handler);
322 if (ACPI_FAILURE(status)) { 312 if (ACPI_FAILURE(status)) {
323 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 313 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
324 "Unable to detach data from device %s\n", 314 "Unable to detach data from device %s\n",
325 acpi_device_bid(device))); 315 acpi_device_bid(device)));
326 result = -ENODEV; 316 result = -ENODEV;
327 goto end; 317 goto end;
328 } 318 }
@@ -331,39 +321,37 @@ int acpi_pci_unbind(
331 } 321 }
332 kfree(data); 322 kfree(data);
333 323
334end: 324 end:
335 return_VALUE(result); 325 return_VALUE(result);
336} 326}
337 327
338int 328int
339acpi_pci_bind_root ( 329acpi_pci_bind_root(struct acpi_device *device,
340 struct acpi_device *device, 330 struct acpi_pci_id *id, struct pci_bus *bus)
341 struct acpi_pci_id *id,
342 struct pci_bus *bus)
343{ 331{
344 int result = 0; 332 int result = 0;
345 acpi_status status = AE_OK; 333 acpi_status status = AE_OK;
346 struct acpi_pci_data *data = NULL; 334 struct acpi_pci_data *data = NULL;
347 char *pathname = NULL; 335 char *pathname = NULL;
348 struct acpi_buffer buffer = {0, NULL}; 336 struct acpi_buffer buffer = { 0, NULL };
349 337
350 ACPI_FUNCTION_TRACE("acpi_pci_bind_root"); 338 ACPI_FUNCTION_TRACE("acpi_pci_bind_root");
351 339
352 pathname = (char *)kmalloc(ACPI_PATHNAME_MAX, GFP_KERNEL); 340 pathname = (char *)kmalloc(ACPI_PATHNAME_MAX, GFP_KERNEL);
353 if(!pathname) 341 if (!pathname)
354 return_VALUE(-ENOMEM); 342 return_VALUE(-ENOMEM);
355 memset(pathname, 0, ACPI_PATHNAME_MAX); 343 memset(pathname, 0, ACPI_PATHNAME_MAX);
356 344
357 buffer.length = ACPI_PATHNAME_MAX; 345 buffer.length = ACPI_PATHNAME_MAX;
358 buffer.pointer = pathname; 346 buffer.pointer = pathname;
359 347
360 if (!device || !id || !bus){ 348 if (!device || !id || !bus) {
361 kfree(pathname); 349 kfree(pathname);
362 return_VALUE(-EINVAL); 350 return_VALUE(-EINVAL);
363 } 351 }
364 352
365 data = kmalloc(sizeof(struct acpi_pci_data), GFP_KERNEL); 353 data = kmalloc(sizeof(struct acpi_pci_data), GFP_KERNEL);
366 if (!data){ 354 if (!data) {
367 kfree(pathname); 355 kfree(pathname);
368 return_VALUE(-ENOMEM); 356 return_VALUE(-ENOMEM);
369 } 357 }
@@ -377,18 +365,18 @@ acpi_pci_bind_root (
377 acpi_get_name(device->handle, ACPI_FULL_PATHNAME, &buffer); 365 acpi_get_name(device->handle, ACPI_FULL_PATHNAME, &buffer);
378 366
379 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Binding PCI root bridge [%s] to " 367 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Binding PCI root bridge [%s] to "
380 "%02x:%02x\n", pathname, id->segment, id->bus)); 368 "%02x:%02x\n", pathname, id->segment, id->bus));
381 369
382 status = acpi_attach_data(device->handle, acpi_pci_data_handler, data); 370 status = acpi_attach_data(device->handle, acpi_pci_data_handler, data);
383 if (ACPI_FAILURE(status)) { 371 if (ACPI_FAILURE(status)) {
384 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 372 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
385 "Unable to attach ACPI-PCI context to device %s\n", 373 "Unable to attach ACPI-PCI context to device %s\n",
386 pathname)); 374 pathname));
387 result = -ENODEV; 375 result = -ENODEV;
388 goto end; 376 goto end;
389 } 377 }
390 378
391end: 379 end:
392 kfree(pathname); 380 kfree(pathname);
393 if (result != 0) 381 if (result != 0)
394 kfree(data); 382 kfree(data);