blob: 1c1141801060ea1c791e6c788a225e29921c752d [file] [log] [blame]
Kristen Accardi783c49f2006-03-03 10:16:05 -08001/*
2 * Common ACPI functions for hot plug platforms
3 *
4 * Copyright (C) 2006 Intel Corporation
5 *
6 * All rights reserved.
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, GOOD TITLE or
16 * NON INFRINGEMENT. See the GNU General Public License for more
17 * details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 * Send feedback to <kristen.c.accardi@intel.com>
24 *
25 */
26
27#include <linux/module.h>
Kenji Kaneshigeaad20ca2006-05-10 22:20:34 +090028#include <linux/moduleparam.h>
Kristen Accardi783c49f2006-03-03 10:16:05 -080029#include <linux/kernel.h>
30#include <linux/types.h>
31#include <linux/pci.h>
Greg Kroah-Hartman7a54f252006-10-13 20:05:19 -070032#include <linux/pci_hotplug.h>
Kenji Kaneshigeac9c0522008-05-28 15:01:03 +090033#include <linux/pci-acpi.h>
Kristen Accardi783c49f2006-03-03 10:16:05 -080034#include <acpi/acpi.h>
35#include <acpi/acpi_bus.h>
Kristen Accardi783c49f2006-03-03 10:16:05 -080036
Kenji Kaneshigeaad20ca2006-05-10 22:20:34 +090037#define MY_NAME "acpi_pcihp"
38
Harvey Harrison66bef8c2008-03-03 19:09:46 -080039#define dbg(fmt, arg...) do { if (debug_acpi) printk(KERN_DEBUG "%s: %s: " fmt , MY_NAME , __func__ , ## arg); } while (0)
Kenji Kaneshigeaad20ca2006-05-10 22:20:34 +090040#define err(format, arg...) printk(KERN_ERR "%s: " format , MY_NAME , ## arg)
41#define info(format, arg...) printk(KERN_INFO "%s: " format , MY_NAME , ## arg)
42#define warn(format, arg...) printk(KERN_WARNING "%s: " format , MY_NAME , ## arg)
43
Kristen Accardi783c49f2006-03-03 10:16:05 -080044#define METHOD_NAME__SUN "_SUN"
45#define METHOD_NAME__HPP "_HPP"
46#define METHOD_NAME_OSHP "OSHP"
47
Kenji Kaneshigeaad20ca2006-05-10 22:20:34 +090048static int debug_acpi;
49
Kenji Kaneshigee22b73502006-05-02 10:57:14 +090050static acpi_status
51decode_type0_hpx_record(union acpi_object *record, struct hotplug_params *hpx)
52{
53 int i;
54 union acpi_object *fields = record->package.elements;
55 u32 revision = fields[1].integer.value;
56
57 switch (revision) {
58 case 1:
59 if (record->package.count != 6)
60 return AE_ERROR;
61 for (i = 2; i < 6; i++)
62 if (fields[i].type != ACPI_TYPE_INTEGER)
63 return AE_ERROR;
64 hpx->t0 = &hpx->type0_data;
65 hpx->t0->revision = revision;
66 hpx->t0->cache_line_size = fields[2].integer.value;
67 hpx->t0->latency_timer = fields[3].integer.value;
68 hpx->t0->enable_serr = fields[4].integer.value;
69 hpx->t0->enable_perr = fields[5].integer.value;
70 break;
71 default:
72 printk(KERN_WARNING
73 "%s: Type 0 Revision %d record not supported\n",
Harvey Harrison66bef8c2008-03-03 19:09:46 -080074 __func__, revision);
Kenji Kaneshigee22b73502006-05-02 10:57:14 +090075 return AE_ERROR;
76 }
77 return AE_OK;
78}
79
80static acpi_status
81decode_type1_hpx_record(union acpi_object *record, struct hotplug_params *hpx)
82{
83 int i;
84 union acpi_object *fields = record->package.elements;
85 u32 revision = fields[1].integer.value;
86
87 switch (revision) {
88 case 1:
89 if (record->package.count != 5)
90 return AE_ERROR;
91 for (i = 2; i < 5; i++)
92 if (fields[i].type != ACPI_TYPE_INTEGER)
93 return AE_ERROR;
94 hpx->t1 = &hpx->type1_data;
95 hpx->t1->revision = revision;
96 hpx->t1->max_mem_read = fields[2].integer.value;
97 hpx->t1->avg_max_split = fields[3].integer.value;
98 hpx->t1->tot_max_split = fields[4].integer.value;
99 break;
100 default:
101 printk(KERN_WARNING
102 "%s: Type 1 Revision %d record not supported\n",
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800103 __func__, revision);
Kenji Kaneshigee22b73502006-05-02 10:57:14 +0900104 return AE_ERROR;
105 }
106 return AE_OK;
107}
108
109static acpi_status
110decode_type2_hpx_record(union acpi_object *record, struct hotplug_params *hpx)
111{
112 int i;
113 union acpi_object *fields = record->package.elements;
114 u32 revision = fields[1].integer.value;
115
116 switch (revision) {
117 case 1:
118 if (record->package.count != 18)
119 return AE_ERROR;
120 for (i = 2; i < 18; i++)
121 if (fields[i].type != ACPI_TYPE_INTEGER)
122 return AE_ERROR;
123 hpx->t2 = &hpx->type2_data;
124 hpx->t2->revision = revision;
125 hpx->t2->unc_err_mask_and = fields[2].integer.value;
126 hpx->t2->unc_err_mask_or = fields[3].integer.value;
127 hpx->t2->unc_err_sever_and = fields[4].integer.value;
128 hpx->t2->unc_err_sever_or = fields[5].integer.value;
129 hpx->t2->cor_err_mask_and = fields[6].integer.value;
130 hpx->t2->cor_err_mask_or = fields[7].integer.value;
131 hpx->t2->adv_err_cap_and = fields[8].integer.value;
132 hpx->t2->adv_err_cap_or = fields[9].integer.value;
133 hpx->t2->pci_exp_devctl_and = fields[10].integer.value;
134 hpx->t2->pci_exp_devctl_or = fields[11].integer.value;
135 hpx->t2->pci_exp_lnkctl_and = fields[12].integer.value;
136 hpx->t2->pci_exp_lnkctl_or = fields[13].integer.value;
137 hpx->t2->sec_unc_err_sever_and = fields[14].integer.value;
138 hpx->t2->sec_unc_err_sever_or = fields[15].integer.value;
139 hpx->t2->sec_unc_err_mask_and = fields[16].integer.value;
140 hpx->t2->sec_unc_err_mask_or = fields[17].integer.value;
141 break;
142 default:
143 printk(KERN_WARNING
144 "%s: Type 2 Revision %d record not supported\n",
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800145 __func__, revision);
Kenji Kaneshigee22b73502006-05-02 10:57:14 +0900146 return AE_ERROR;
147 }
148 return AE_OK;
149}
150
151static acpi_status
152acpi_run_hpx(acpi_handle handle, struct hotplug_params *hpx)
153{
154 acpi_status status;
155 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
156 union acpi_object *package, *record, *fields;
157 u32 type;
158 int i;
159
160 /* Clear the return buffer with zeros */
161 memset(hpx, 0, sizeof(struct hotplug_params));
162
163 status = acpi_evaluate_object(handle, "_HPX", NULL, &buffer);
164 if (ACPI_FAILURE(status))
165 return status;
166
167 package = (union acpi_object *)buffer.pointer;
168 if (package->type != ACPI_TYPE_PACKAGE) {
169 status = AE_ERROR;
170 goto exit;
171 }
172
173 for (i = 0; i < package->package.count; i++) {
174 record = &package->package.elements[i];
175 if (record->type != ACPI_TYPE_PACKAGE) {
176 status = AE_ERROR;
177 goto exit;
178 }
179
180 fields = record->package.elements;
181 if (fields[0].type != ACPI_TYPE_INTEGER ||
182 fields[1].type != ACPI_TYPE_INTEGER) {
183 status = AE_ERROR;
184 goto exit;
185 }
186
187 type = fields[0].integer.value;
188 switch (type) {
189 case 0:
190 status = decode_type0_hpx_record(record, hpx);
191 if (ACPI_FAILURE(status))
192 goto exit;
193 break;
194 case 1:
195 status = decode_type1_hpx_record(record, hpx);
196 if (ACPI_FAILURE(status))
197 goto exit;
198 break;
199 case 2:
200 status = decode_type2_hpx_record(record, hpx);
201 if (ACPI_FAILURE(status))
202 goto exit;
203 break;
204 default:
205 printk(KERN_ERR "%s: Type %d record not supported\n",
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800206 __func__, type);
Kenji Kaneshigee22b73502006-05-02 10:57:14 +0900207 status = AE_ERROR;
208 goto exit;
209 }
210 }
211 exit:
212 kfree(buffer.pointer);
213 return status;
214}
Kristen Accardi783c49f2006-03-03 10:16:05 -0800215
216static acpi_status
217acpi_run_hpp(acpi_handle handle, struct hotplug_params *hpp)
218{
219 acpi_status status;
220 u8 nui[4];
221 struct acpi_buffer ret_buf = { 0, NULL};
MUNEDA Takahirob2e6e3b2006-03-17 09:18:39 +0900222 struct acpi_buffer string = { ACPI_ALLOCATE_BUFFER, NULL };
Kristen Accardi783c49f2006-03-03 10:16:05 -0800223 union acpi_object *ext_obj, *package;
Kristen Accardi783c49f2006-03-03 10:16:05 -0800224 int i, len = 0;
225
MUNEDA Takahirob2e6e3b2006-03-17 09:18:39 +0900226 acpi_get_name(handle, ACPI_FULL_PATHNAME, &string);
227
Kenji Kaneshigee22b73502006-05-02 10:57:14 +0900228 /* Clear the return buffer with zeros */
229 memset(hpp, 0, sizeof(struct hotplug_params));
230
Kristen Accardi783c49f2006-03-03 10:16:05 -0800231 /* get _hpp */
232 status = acpi_evaluate_object(handle, METHOD_NAME__HPP, NULL, &ret_buf);
233 switch (status) {
234 case AE_BUFFER_OVERFLOW:
235 ret_buf.pointer = kmalloc (ret_buf.length, GFP_KERNEL);
236 if (!ret_buf.pointer) {
237 printk(KERN_ERR "%s:%s alloc for _HPP fail\n",
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800238 __func__, (char *)string.pointer);
Kristen Accardi81b26bc2006-04-18 14:36:43 -0700239 kfree(string.pointer);
Kristen Accardi783c49f2006-03-03 10:16:05 -0800240 return AE_NO_MEMORY;
241 }
242 status = acpi_evaluate_object(handle, METHOD_NAME__HPP,
243 NULL, &ret_buf);
244 if (ACPI_SUCCESS(status))
245 break;
246 default:
247 if (ACPI_FAILURE(status)) {
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800248 pr_debug("%s:%s _HPP fail=0x%x\n", __func__,
MUNEDA Takahirob2e6e3b2006-03-17 09:18:39 +0900249 (char *)string.pointer, status);
Kristen Accardi81b26bc2006-04-18 14:36:43 -0700250 kfree(string.pointer);
Kristen Accardi783c49f2006-03-03 10:16:05 -0800251 return status;
252 }
253 }
254
255 ext_obj = (union acpi_object *) ret_buf.pointer;
256 if (ext_obj->type != ACPI_TYPE_PACKAGE) {
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800257 printk(KERN_ERR "%s:%s _HPP obj not a package\n", __func__,
MUNEDA Takahirob2e6e3b2006-03-17 09:18:39 +0900258 (char *)string.pointer);
Kristen Accardi783c49f2006-03-03 10:16:05 -0800259 status = AE_ERROR;
260 goto free_and_return;
261 }
262
263 len = ext_obj->package.count;
264 package = (union acpi_object *) ret_buf.pointer;
265 for ( i = 0; (i < len) || (i < 4); i++) {
266 ext_obj = (union acpi_object *) &package->package.elements[i];
267 switch (ext_obj->type) {
268 case ACPI_TYPE_INTEGER:
269 nui[i] = (u8)ext_obj->integer.value;
270 break;
271 default:
272 printk(KERN_ERR "%s:%s _HPP obj type incorrect\n",
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800273 __func__, (char *)string.pointer);
Kristen Accardi783c49f2006-03-03 10:16:05 -0800274 status = AE_ERROR;
275 goto free_and_return;
276 }
277 }
278
Kenji Kaneshigee22b73502006-05-02 10:57:14 +0900279 hpp->t0 = &hpp->type0_data;
280 hpp->t0->cache_line_size = nui[0];
281 hpp->t0->latency_timer = nui[1];
282 hpp->t0->enable_serr = nui[2];
283 hpp->t0->enable_perr = nui[3];
Kristen Accardi783c49f2006-03-03 10:16:05 -0800284
Kenji Kaneshigee22b73502006-05-02 10:57:14 +0900285 pr_debug(" _HPP: cache_line_size=0x%x\n", hpp->t0->cache_line_size);
286 pr_debug(" _HPP: latency timer =0x%x\n", hpp->t0->latency_timer);
287 pr_debug(" _HPP: enable SERR =0x%x\n", hpp->t0->enable_serr);
288 pr_debug(" _HPP: enable PERR =0x%x\n", hpp->t0->enable_perr);
Kristen Accardi783c49f2006-03-03 10:16:05 -0800289
290free_and_return:
Kristen Accardi81b26bc2006-04-18 14:36:43 -0700291 kfree(string.pointer);
292 kfree(ret_buf.pointer);
Kristen Accardi783c49f2006-03-03 10:16:05 -0800293 return status;
294}
295
296
297
298/* acpi_run_oshp - get control of hotplug from the firmware
299 *
300 * @handle - the handle of the hotplug controller.
301 */
Kenji Kaneshigeac9c0522008-05-28 15:01:03 +0900302static acpi_status acpi_run_oshp(acpi_handle handle)
Kristen Accardi783c49f2006-03-03 10:16:05 -0800303{
304 acpi_status status;
MUNEDA Takahirob2e6e3b2006-03-17 09:18:39 +0900305 struct acpi_buffer string = { ACPI_ALLOCATE_BUFFER, NULL };
306
307 acpi_get_name(handle, ACPI_FULL_PATHNAME, &string);
Kristen Accardi783c49f2006-03-03 10:16:05 -0800308
309 /* run OSHP */
310 status = acpi_evaluate_object(handle, METHOD_NAME_OSHP, NULL, NULL);
311 if (ACPI_FAILURE(status))
Kenji Kaneshigeaad20ca2006-05-10 22:20:34 +0900312 if (status != AE_NOT_FOUND)
313 printk(KERN_ERR "%s:%s OSHP fails=0x%x\n",
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800314 __func__, (char *)string.pointer, status);
Kenji Kaneshigeaad20ca2006-05-10 22:20:34 +0900315 else
316 dbg("%s:%s OSHP not found\n",
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800317 __func__, (char *)string.pointer);
Kristen Accardi783c49f2006-03-03 10:16:05 -0800318 else
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800319 pr_debug("%s:%s OSHP passes\n", __func__,
MUNEDA Takahirob2e6e3b2006-03-17 09:18:39 +0900320 (char *)string.pointer);
321
Kristen Accardi81b26bc2006-04-18 14:36:43 -0700322 kfree(string.pointer);
Kristen Accardi783c49f2006-03-03 10:16:05 -0800323 return status;
324}
Kristen Accardi783c49f2006-03-03 10:16:05 -0800325
326/* acpi_get_hp_params_from_firmware
327 *
Kenji Kaneshige7430e342006-05-02 10:54:50 +0900328 * @bus - the pci_bus of the bus on which the device is newly added
Kristen Accardi783c49f2006-03-03 10:16:05 -0800329 * @hpp - allocated by the caller
330 */
Kenji Kaneshige7430e342006-05-02 10:54:50 +0900331acpi_status acpi_get_hp_params_from_firmware(struct pci_bus *bus,
Kristen Accardi783c49f2006-03-03 10:16:05 -0800332 struct hotplug_params *hpp)
333{
334 acpi_status status = AE_NOT_FOUND;
Kenji Kaneshige7430e342006-05-02 10:54:50 +0900335 acpi_handle handle, phandle;
336 struct pci_bus *pbus = bus;
337 struct pci_dev *pdev;
338
339 do {
340 pdev = pbus->self;
341 if (!pdev) {
342 handle = acpi_get_pci_rootbridge_handle(
343 pci_domain_nr(pbus), pbus->number);
344 break;
345 }
346 handle = DEVICE_ACPI_HANDLE(&(pdev->dev));
347 pbus = pbus->parent;
348 } while (!handle);
Kristen Accardi783c49f2006-03-03 10:16:05 -0800349
350 /*
351 * _HPP settings apply to all child buses, until another _HPP is
352 * encountered. If we don't find an _HPP for the input pci dev,
353 * look for it in the parent device scope since that would apply to
354 * this pci dev. If we don't find any _HPP, use hardcoded defaults
355 */
Kenji Kaneshige7430e342006-05-02 10:54:50 +0900356 while (handle) {
Kenji Kaneshigee22b73502006-05-02 10:57:14 +0900357 status = acpi_run_hpx(handle, hpp);
358 if (ACPI_SUCCESS(status))
359 break;
Kristen Accardi783c49f2006-03-03 10:16:05 -0800360 status = acpi_run_hpp(handle, hpp);
Kenji Kaneshige7430e342006-05-02 10:54:50 +0900361 if (ACPI_SUCCESS(status))
Kristen Accardi783c49f2006-03-03 10:16:05 -0800362 break;
Kenji Kaneshige7430e342006-05-02 10:54:50 +0900363 if (acpi_root_bridge(handle))
364 break;
365 status = acpi_get_parent(handle, &phandle);
366 if (ACPI_FAILURE(status))
367 break;
368 handle = phandle;
Kristen Accardi783c49f2006-03-03 10:16:05 -0800369 }
370 return status;
371}
372EXPORT_SYMBOL_GPL(acpi_get_hp_params_from_firmware);
373
Kenji Kaneshigeac9c0522008-05-28 15:01:03 +0900374/**
375 * acpi_get_hp_hw_control_from_firmware
376 * @dev: the pci_dev of the bridge that has a hotplug controller
377 * @flags: requested control bits for _OSC
378 *
379 * Attempt to take hotplug control from firmware.
380 */
381int acpi_get_hp_hw_control_from_firmware(struct pci_dev *dev, u32 flags)
382{
383 acpi_status status;
Jiri Slabye0d94be2008-08-11 17:47:40 +0200384 acpi_handle chandle, handle;
Kenji Kaneshigeac9c0522008-05-28 15:01:03 +0900385 struct pci_dev *pdev = dev;
386 struct pci_bus *parent;
387 struct acpi_buffer string = { ACPI_ALLOCATE_BUFFER, NULL };
388
389 flags &= (OSC_PCI_EXPRESS_NATIVE_HP_CONTROL |
390 OSC_SHPC_NATIVE_HP_CONTROL |
391 OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL);
392 if (!flags) {
393 err("Invalid flags %u specified!\n", flags);
394 return -EINVAL;
395 }
396
397 /*
398 * Per PCI firmware specification, we should run the ACPI _OSC
399 * method to get control of hotplug hardware before using it. If
400 * an _OSC is missing, we look for an OSHP to do the same thing.
Jiri Slabye0d94be2008-08-11 17:47:40 +0200401 * To handle different BIOS behavior, we look for _OSC on a root
402 * bridge preferentially (according to PCI fw spec). Later for
403 * OSHP within the scope of the hotplug controller and its parents,
Kenji Kaneshigeac9c0522008-05-28 15:01:03 +0900404 * upto the host bridge under which this controller exists.
405 */
Jiri Slaby056c58e2008-08-18 20:22:54 +0200406 handle = acpi_find_root_bridge_handle(pdev);
Jiri Slabye0d94be2008-08-11 17:47:40 +0200407 if (handle) {
408 acpi_get_name(handle, ACPI_FULL_PATHNAME, &string);
409 dbg("Trying to get hotplug control for %s\n",
410 (char *)string.pointer);
411 status = pci_osc_control_set(handle, flags);
412 if (ACPI_SUCCESS(status))
413 goto got_one;
414 kfree(string.pointer);
415 string = (struct acpi_buffer){ ACPI_ALLOCATE_BUFFER, NULL };
416 }
417
418 pdev = dev;
419 handle = DEVICE_ACPI_HANDLE(&dev->dev);
Kenji Kaneshigeac9c0522008-05-28 15:01:03 +0900420 while (!handle) {
421 /*
422 * This hotplug controller was not listed in the ACPI name
423 * space at all. Try to get acpi handle of parent pci bus.
424 */
425 if (!pdev || !pdev->bus->parent)
426 break;
427 parent = pdev->bus->parent;
428 dbg("Could not find %s in acpi namespace, trying parent\n",
429 pci_name(pdev));
430 if (!parent->self)
431 /* Parent must be a host bridge */
432 handle = acpi_get_pci_rootbridge_handle(
433 pci_domain_nr(parent),
434 parent->number);
435 else
436 handle = DEVICE_ACPI_HANDLE(&(parent->self->dev));
437 pdev = parent->self;
438 }
439
440 while (handle) {
441 acpi_get_name(handle, ACPI_FULL_PATHNAME, &string);
442 dbg("Trying to get hotplug control for %s \n",
443 (char *)string.pointer);
Jiri Slabye0d94be2008-08-11 17:47:40 +0200444 status = acpi_run_oshp(handle);
445 if (ACPI_SUCCESS(status))
446 goto got_one;
Kenji Kaneshigeac9c0522008-05-28 15:01:03 +0900447 if (acpi_root_bridge(handle))
448 break;
449 chandle = handle;
450 status = acpi_get_parent(chandle, &handle);
451 if (ACPI_FAILURE(status))
452 break;
453 }
454
455 dbg("Cannot get control of hotplug hardware for pci %s\n",
456 pci_name(dev));
457
458 kfree(string.pointer);
459 return -ENODEV;
Jiri Slabye0d94be2008-08-11 17:47:40 +0200460got_one:
461 dbg("Gained control for hotplug HW for pci %s (%s)\n", pci_name(dev),
462 (char *)string.pointer);
463 kfree(string.pointer);
464 return 0;
Kenji Kaneshigeac9c0522008-05-28 15:01:03 +0900465}
466EXPORT_SYMBOL(acpi_get_hp_hw_control_from_firmware);
Kristen Accardi783c49f2006-03-03 10:16:05 -0800467
468/* acpi_root_bridge - check to see if this acpi object is a root bridge
469 *
470 * @handle - the acpi object in question.
471 */
472int acpi_root_bridge(acpi_handle handle)
473{
474 acpi_status status;
475 struct acpi_device_info *info;
476 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
477 int i;
478
479 status = acpi_get_object_info(handle, &buffer);
480 if (ACPI_SUCCESS(status)) {
481 info = buffer.pointer;
482 if ((info->valid & ACPI_VALID_HID) &&
483 !strcmp(PCI_ROOT_HID_STRING,
484 info->hardware_id.value)) {
Kristen Accardi81b26bc2006-04-18 14:36:43 -0700485 kfree(buffer.pointer);
Kristen Accardi783c49f2006-03-03 10:16:05 -0800486 return 1;
487 }
488 if (info->valid & ACPI_VALID_CID) {
489 for (i=0; i < info->compatibility_id.count; i++) {
490 if (!strcmp(PCI_ROOT_HID_STRING,
491 info->compatibility_id.id[i].value)) {
Kristen Accardi81b26bc2006-04-18 14:36:43 -0700492 kfree(buffer.pointer);
Kristen Accardi783c49f2006-03-03 10:16:05 -0800493 return 1;
494 }
495 }
496 }
Kristen Accardi81b26bc2006-04-18 14:36:43 -0700497 kfree(buffer.pointer);
Kristen Accardi783c49f2006-03-03 10:16:05 -0800498 }
499 return 0;
500}
501EXPORT_SYMBOL_GPL(acpi_root_bridge);
Kenji Kaneshigeaad20ca2006-05-10 22:20:34 +0900502
Kenji Kaneshigee8c331e2008-12-17 12:09:12 +0900503
504static int is_ejectable(acpi_handle handle)
505{
506 acpi_status status;
507 acpi_handle tmp;
508 unsigned long long removable;
509 status = acpi_get_handle(handle, "_ADR", &tmp);
510 if (ACPI_FAILURE(status))
511 return 0;
512 status = acpi_get_handle(handle, "_EJ0", &tmp);
513 if (ACPI_SUCCESS(status))
514 return 1;
515 status = acpi_evaluate_integer(handle, "_RMV", NULL, &removable);
516 if (ACPI_SUCCESS(status) && removable)
517 return 1;
518 return 0;
519}
520
521/**
522 * acpi_pcihp_check_ejectable - check if handle is ejectable ACPI PCI slot
523 * @pbus: the PCI bus of the PCI slot corresponding to 'handle'
524 * @handle: ACPI handle to check
525 *
526 * Return 1 if handle is ejectable PCI slot, 0 otherwise.
527 */
528int acpi_pci_check_ejectable(struct pci_bus *pbus, acpi_handle handle)
529{
530 acpi_handle bridge_handle, parent_handle;
531
532 if (!(bridge_handle = acpi_pci_get_bridge_handle(pbus)))
533 return 0;
534 if ((ACPI_FAILURE(acpi_get_parent(handle, &parent_handle))))
535 return 0;
536 if (bridge_handle != parent_handle)
537 return 0;
538 return is_ejectable(handle);
539}
540EXPORT_SYMBOL_GPL(acpi_pci_check_ejectable);
541
542static acpi_status
543check_hotplug(acpi_handle handle, u32 lvl, void *context, void **rv)
544{
545 int *found = (int *)context;
546 if (is_ejectable(handle)) {
547 *found = 1;
548 return AE_CTRL_TERMINATE;
549 }
550 return AE_OK;
551}
552
553/**
554 * acpi_pci_detect_ejectable - check if the PCI bus has ejectable slots
555 * @pbus - PCI bus to scan
556 *
557 * Returns 1 if the PCI bus has ACPI based ejectable slots, 0 otherwise.
558 */
559int acpi_pci_detect_ejectable(struct pci_bus *pbus)
560{
561 acpi_handle handle;
562 int found = 0;
563
564 if (!(handle = acpi_pci_get_bridge_handle(pbus)))
565 return 0;
566 acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, (u32)1,
567 check_hotplug, (void *)&found, NULL);
568 return found;
569}
570EXPORT_SYMBOL_GPL(acpi_pci_detect_ejectable);
571
Kenji Kaneshigeaad20ca2006-05-10 22:20:34 +0900572module_param(debug_acpi, bool, 0644);
573MODULE_PARM_DESC(debug_acpi, "Debugging mode for ACPI enabled or not");