blob: ee24de1c5faef6edda5bb6f3c4688db322411589 [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 Kaneshige9f5404d2009-02-09 16:00:04 +090033#include <linux/acpi.h>
Kenji Kaneshigeac9c0522008-05-28 15:01:03 +090034#include <linux/pci-acpi.h>
Kristen Accardi783c49f2006-03-03 10:16:05 -080035
Kenji Kaneshigeaad20ca2006-05-10 22:20:34 +090036#define MY_NAME "acpi_pcihp"
37
Harvey Harrison66bef8c2008-03-03 19:09:46 -080038#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 +090039#define err(format, arg...) printk(KERN_ERR "%s: " format , MY_NAME , ## arg)
40#define info(format, arg...) printk(KERN_INFO "%s: " format , MY_NAME , ## arg)
41#define warn(format, arg...) printk(KERN_WARNING "%s: " format , MY_NAME , ## arg)
42
Kristen Accardi783c49f2006-03-03 10:16:05 -080043#define METHOD_NAME__SUN "_SUN"
44#define METHOD_NAME__HPP "_HPP"
45#define METHOD_NAME_OSHP "OSHP"
46
Kenji Kaneshigeaad20ca2006-05-10 22:20:34 +090047static int debug_acpi;
48
Kenji Kaneshigee22b73502006-05-02 10:57:14 +090049static acpi_status
50decode_type0_hpx_record(union acpi_object *record, struct hotplug_params *hpx)
51{
52 int i;
53 union acpi_object *fields = record->package.elements;
54 u32 revision = fields[1].integer.value;
55
56 switch (revision) {
57 case 1:
58 if (record->package.count != 6)
59 return AE_ERROR;
60 for (i = 2; i < 6; i++)
61 if (fields[i].type != ACPI_TYPE_INTEGER)
62 return AE_ERROR;
63 hpx->t0 = &hpx->type0_data;
64 hpx->t0->revision = revision;
65 hpx->t0->cache_line_size = fields[2].integer.value;
66 hpx->t0->latency_timer = fields[3].integer.value;
67 hpx->t0->enable_serr = fields[4].integer.value;
68 hpx->t0->enable_perr = fields[5].integer.value;
69 break;
70 default:
71 printk(KERN_WARNING
72 "%s: Type 0 Revision %d record not supported\n",
Harvey Harrison66bef8c2008-03-03 19:09:46 -080073 __func__, revision);
Kenji Kaneshigee22b73502006-05-02 10:57:14 +090074 return AE_ERROR;
75 }
76 return AE_OK;
77}
78
79static acpi_status
80decode_type1_hpx_record(union acpi_object *record, struct hotplug_params *hpx)
81{
82 int i;
83 union acpi_object *fields = record->package.elements;
84 u32 revision = fields[1].integer.value;
85
86 switch (revision) {
87 case 1:
88 if (record->package.count != 5)
89 return AE_ERROR;
90 for (i = 2; i < 5; i++)
91 if (fields[i].type != ACPI_TYPE_INTEGER)
92 return AE_ERROR;
93 hpx->t1 = &hpx->type1_data;
94 hpx->t1->revision = revision;
95 hpx->t1->max_mem_read = fields[2].integer.value;
96 hpx->t1->avg_max_split = fields[3].integer.value;
97 hpx->t1->tot_max_split = fields[4].integer.value;
98 break;
99 default:
100 printk(KERN_WARNING
101 "%s: Type 1 Revision %d record not supported\n",
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800102 __func__, revision);
Kenji Kaneshigee22b73502006-05-02 10:57:14 +0900103 return AE_ERROR;
104 }
105 return AE_OK;
106}
107
108static acpi_status
109decode_type2_hpx_record(union acpi_object *record, struct hotplug_params *hpx)
110{
111 int i;
112 union acpi_object *fields = record->package.elements;
113 u32 revision = fields[1].integer.value;
114
115 switch (revision) {
116 case 1:
117 if (record->package.count != 18)
118 return AE_ERROR;
119 for (i = 2; i < 18; i++)
120 if (fields[i].type != ACPI_TYPE_INTEGER)
121 return AE_ERROR;
122 hpx->t2 = &hpx->type2_data;
123 hpx->t2->revision = revision;
124 hpx->t2->unc_err_mask_and = fields[2].integer.value;
125 hpx->t2->unc_err_mask_or = fields[3].integer.value;
126 hpx->t2->unc_err_sever_and = fields[4].integer.value;
127 hpx->t2->unc_err_sever_or = fields[5].integer.value;
128 hpx->t2->cor_err_mask_and = fields[6].integer.value;
129 hpx->t2->cor_err_mask_or = fields[7].integer.value;
130 hpx->t2->adv_err_cap_and = fields[8].integer.value;
131 hpx->t2->adv_err_cap_or = fields[9].integer.value;
132 hpx->t2->pci_exp_devctl_and = fields[10].integer.value;
133 hpx->t2->pci_exp_devctl_or = fields[11].integer.value;
134 hpx->t2->pci_exp_lnkctl_and = fields[12].integer.value;
135 hpx->t2->pci_exp_lnkctl_or = fields[13].integer.value;
136 hpx->t2->sec_unc_err_sever_and = fields[14].integer.value;
137 hpx->t2->sec_unc_err_sever_or = fields[15].integer.value;
138 hpx->t2->sec_unc_err_mask_and = fields[16].integer.value;
139 hpx->t2->sec_unc_err_mask_or = fields[17].integer.value;
140 break;
141 default:
142 printk(KERN_WARNING
143 "%s: Type 2 Revision %d record not supported\n",
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800144 __func__, revision);
Kenji Kaneshigee22b73502006-05-02 10:57:14 +0900145 return AE_ERROR;
146 }
147 return AE_OK;
148}
149
150static acpi_status
151acpi_run_hpx(acpi_handle handle, struct hotplug_params *hpx)
152{
153 acpi_status status;
154 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
155 union acpi_object *package, *record, *fields;
156 u32 type;
157 int i;
158
159 /* Clear the return buffer with zeros */
160 memset(hpx, 0, sizeof(struct hotplug_params));
161
162 status = acpi_evaluate_object(handle, "_HPX", NULL, &buffer);
163 if (ACPI_FAILURE(status))
164 return status;
165
166 package = (union acpi_object *)buffer.pointer;
167 if (package->type != ACPI_TYPE_PACKAGE) {
168 status = AE_ERROR;
169 goto exit;
170 }
171
172 for (i = 0; i < package->package.count; i++) {
173 record = &package->package.elements[i];
174 if (record->type != ACPI_TYPE_PACKAGE) {
175 status = AE_ERROR;
176 goto exit;
177 }
178
179 fields = record->package.elements;
180 if (fields[0].type != ACPI_TYPE_INTEGER ||
181 fields[1].type != ACPI_TYPE_INTEGER) {
182 status = AE_ERROR;
183 goto exit;
184 }
185
186 type = fields[0].integer.value;
187 switch (type) {
188 case 0:
189 status = decode_type0_hpx_record(record, hpx);
190 if (ACPI_FAILURE(status))
191 goto exit;
192 break;
193 case 1:
194 status = decode_type1_hpx_record(record, hpx);
195 if (ACPI_FAILURE(status))
196 goto exit;
197 break;
198 case 2:
199 status = decode_type2_hpx_record(record, hpx);
200 if (ACPI_FAILURE(status))
201 goto exit;
202 break;
203 default:
204 printk(KERN_ERR "%s: Type %d record not supported\n",
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800205 __func__, type);
Kenji Kaneshigee22b73502006-05-02 10:57:14 +0900206 status = AE_ERROR;
207 goto exit;
208 }
209 }
210 exit:
211 kfree(buffer.pointer);
212 return status;
213}
Kristen Accardi783c49f2006-03-03 10:16:05 -0800214
215static acpi_status
216acpi_run_hpp(acpi_handle handle, struct hotplug_params *hpp)
217{
218 acpi_status status;
219 u8 nui[4];
220 struct acpi_buffer ret_buf = { 0, NULL};
MUNEDA Takahirob2e6e3b2006-03-17 09:18:39 +0900221 struct acpi_buffer string = { ACPI_ALLOCATE_BUFFER, NULL };
Kristen Accardi783c49f2006-03-03 10:16:05 -0800222 union acpi_object *ext_obj, *package;
Kristen Accardi783c49f2006-03-03 10:16:05 -0800223 int i, len = 0;
224
MUNEDA Takahirob2e6e3b2006-03-17 09:18:39 +0900225 acpi_get_name(handle, ACPI_FULL_PATHNAME, &string);
226
Kenji Kaneshigee22b73502006-05-02 10:57:14 +0900227 /* Clear the return buffer with zeros */
228 memset(hpp, 0, sizeof(struct hotplug_params));
229
Kristen Accardi783c49f2006-03-03 10:16:05 -0800230 /* get _hpp */
231 status = acpi_evaluate_object(handle, METHOD_NAME__HPP, NULL, &ret_buf);
232 switch (status) {
233 case AE_BUFFER_OVERFLOW:
234 ret_buf.pointer = kmalloc (ret_buf.length, GFP_KERNEL);
235 if (!ret_buf.pointer) {
236 printk(KERN_ERR "%s:%s alloc for _HPP fail\n",
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800237 __func__, (char *)string.pointer);
Kristen Accardi81b26bc2006-04-18 14:36:43 -0700238 kfree(string.pointer);
Kristen Accardi783c49f2006-03-03 10:16:05 -0800239 return AE_NO_MEMORY;
240 }
241 status = acpi_evaluate_object(handle, METHOD_NAME__HPP,
242 NULL, &ret_buf);
243 if (ACPI_SUCCESS(status))
244 break;
245 default:
246 if (ACPI_FAILURE(status)) {
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800247 pr_debug("%s:%s _HPP fail=0x%x\n", __func__,
MUNEDA Takahirob2e6e3b2006-03-17 09:18:39 +0900248 (char *)string.pointer, status);
Kristen Accardi81b26bc2006-04-18 14:36:43 -0700249 kfree(string.pointer);
Kristen Accardi783c49f2006-03-03 10:16:05 -0800250 return status;
251 }
252 }
253
254 ext_obj = (union acpi_object *) ret_buf.pointer;
255 if (ext_obj->type != ACPI_TYPE_PACKAGE) {
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800256 printk(KERN_ERR "%s:%s _HPP obj not a package\n", __func__,
MUNEDA Takahirob2e6e3b2006-03-17 09:18:39 +0900257 (char *)string.pointer);
Kristen Accardi783c49f2006-03-03 10:16:05 -0800258 status = AE_ERROR;
259 goto free_and_return;
260 }
261
262 len = ext_obj->package.count;
263 package = (union acpi_object *) ret_buf.pointer;
264 for ( i = 0; (i < len) || (i < 4); i++) {
265 ext_obj = (union acpi_object *) &package->package.elements[i];
266 switch (ext_obj->type) {
267 case ACPI_TYPE_INTEGER:
268 nui[i] = (u8)ext_obj->integer.value;
269 break;
270 default:
271 printk(KERN_ERR "%s:%s _HPP obj type incorrect\n",
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800272 __func__, (char *)string.pointer);
Kristen Accardi783c49f2006-03-03 10:16:05 -0800273 status = AE_ERROR;
274 goto free_and_return;
275 }
276 }
277
Kenji Kaneshigee22b73502006-05-02 10:57:14 +0900278 hpp->t0 = &hpp->type0_data;
279 hpp->t0->cache_line_size = nui[0];
280 hpp->t0->latency_timer = nui[1];
281 hpp->t0->enable_serr = nui[2];
282 hpp->t0->enable_perr = nui[3];
Kristen Accardi783c49f2006-03-03 10:16:05 -0800283
Kenji Kaneshigee22b73502006-05-02 10:57:14 +0900284 pr_debug(" _HPP: cache_line_size=0x%x\n", hpp->t0->cache_line_size);
285 pr_debug(" _HPP: latency timer =0x%x\n", hpp->t0->latency_timer);
286 pr_debug(" _HPP: enable SERR =0x%x\n", hpp->t0->enable_serr);
287 pr_debug(" _HPP: enable PERR =0x%x\n", hpp->t0->enable_perr);
Kristen Accardi783c49f2006-03-03 10:16:05 -0800288
289free_and_return:
Kristen Accardi81b26bc2006-04-18 14:36:43 -0700290 kfree(string.pointer);
291 kfree(ret_buf.pointer);
Kristen Accardi783c49f2006-03-03 10:16:05 -0800292 return status;
293}
294
295
296
297/* acpi_run_oshp - get control of hotplug from the firmware
298 *
299 * @handle - the handle of the hotplug controller.
300 */
Kenji Kaneshigeac9c0522008-05-28 15:01:03 +0900301static acpi_status acpi_run_oshp(acpi_handle handle)
Kristen Accardi783c49f2006-03-03 10:16:05 -0800302{
303 acpi_status status;
MUNEDA Takahirob2e6e3b2006-03-17 09:18:39 +0900304 struct acpi_buffer string = { ACPI_ALLOCATE_BUFFER, NULL };
305
306 acpi_get_name(handle, ACPI_FULL_PATHNAME, &string);
Kristen Accardi783c49f2006-03-03 10:16:05 -0800307
308 /* run OSHP */
309 status = acpi_evaluate_object(handle, METHOD_NAME_OSHP, NULL, NULL);
310 if (ACPI_FAILURE(status))
Kenji Kaneshigeaad20ca2006-05-10 22:20:34 +0900311 if (status != AE_NOT_FOUND)
312 printk(KERN_ERR "%s:%s OSHP fails=0x%x\n",
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800313 __func__, (char *)string.pointer, status);
Kenji Kaneshigeaad20ca2006-05-10 22:20:34 +0900314 else
315 dbg("%s:%s OSHP not found\n",
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800316 __func__, (char *)string.pointer);
Kristen Accardi783c49f2006-03-03 10:16:05 -0800317 else
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800318 pr_debug("%s:%s OSHP passes\n", __func__,
MUNEDA Takahirob2e6e3b2006-03-17 09:18:39 +0900319 (char *)string.pointer);
320
Kristen Accardi81b26bc2006-04-18 14:36:43 -0700321 kfree(string.pointer);
Kristen Accardi783c49f2006-03-03 10:16:05 -0800322 return status;
323}
Kristen Accardi783c49f2006-03-03 10:16:05 -0800324
Bjorn Helgaase81995b2009-09-14 16:35:35 -0600325/* pci_get_hp_params
Kristen Accardi783c49f2006-03-03 10:16:05 -0800326 *
Bjorn Helgaas6a291722009-09-14 16:35:15 -0600327 * @dev - the pci_dev for which we want parameters
Kristen Accardi783c49f2006-03-03 10:16:05 -0800328 * @hpp - allocated by the caller
329 */
Bjorn Helgaase81995b2009-09-14 16:35:35 -0600330int pci_get_hp_params(struct pci_dev *dev, struct hotplug_params *hpp)
Kristen Accardi783c49f2006-03-03 10:16:05 -0800331{
Bjorn Helgaas6a291722009-09-14 16:35:15 -0600332 acpi_status status;
Kenji Kaneshige7430e342006-05-02 10:54:50 +0900333 acpi_handle handle, phandle;
Kenji Kaneshige267efd72009-02-17 14:13:20 +0900334 struct pci_bus *pbus;
Kenji Kaneshige7430e342006-05-02 10:54:50 +0900335
Kenji Kaneshige267efd72009-02-17 14:13:20 +0900336 handle = NULL;
Bjorn Helgaas6a291722009-09-14 16:35:15 -0600337 for (pbus = dev->bus; pbus; pbus = pbus->parent) {
Kenji Kaneshige267efd72009-02-17 14:13:20 +0900338 handle = acpi_pci_get_bridge_handle(pbus);
339 if (handle)
Kenji Kaneshige7430e342006-05-02 10:54:50 +0900340 break;
Kenji Kaneshige267efd72009-02-17 14:13:20 +0900341 }
Kristen Accardi783c49f2006-03-03 10:16:05 -0800342
343 /*
344 * _HPP settings apply to all child buses, until another _HPP is
345 * encountered. If we don't find an _HPP for the input pci dev,
346 * look for it in the parent device scope since that would apply to
Bjorn Helgaase81995b2009-09-14 16:35:35 -0600347 * this pci dev.
Kristen Accardi783c49f2006-03-03 10:16:05 -0800348 */
Kenji Kaneshige7430e342006-05-02 10:54:50 +0900349 while (handle) {
Kenji Kaneshigee22b73502006-05-02 10:57:14 +0900350 status = acpi_run_hpx(handle, hpp);
351 if (ACPI_SUCCESS(status))
Bjorn Helgaas6a291722009-09-14 16:35:15 -0600352 return 0;
Kristen Accardi783c49f2006-03-03 10:16:05 -0800353 status = acpi_run_hpp(handle, hpp);
Kenji Kaneshige7430e342006-05-02 10:54:50 +0900354 if (ACPI_SUCCESS(status))
Bjorn Helgaas6a291722009-09-14 16:35:15 -0600355 return 0;
Alexander Chiang27558202009-06-10 19:55:14 +0000356 if (acpi_is_root_bridge(handle))
Kenji Kaneshige7430e342006-05-02 10:54:50 +0900357 break;
358 status = acpi_get_parent(handle, &phandle);
359 if (ACPI_FAILURE(status))
360 break;
361 handle = phandle;
Kristen Accardi783c49f2006-03-03 10:16:05 -0800362 }
Bjorn Helgaas6a291722009-09-14 16:35:15 -0600363 return -ENODEV;
Kristen Accardi783c49f2006-03-03 10:16:05 -0800364}
Bjorn Helgaase81995b2009-09-14 16:35:35 -0600365EXPORT_SYMBOL_GPL(pci_get_hp_params);
Kristen Accardi783c49f2006-03-03 10:16:05 -0800366
Kenji Kaneshigeac9c0522008-05-28 15:01:03 +0900367/**
368 * acpi_get_hp_hw_control_from_firmware
369 * @dev: the pci_dev of the bridge that has a hotplug controller
370 * @flags: requested control bits for _OSC
371 *
372 * Attempt to take hotplug control from firmware.
373 */
Kenji Kaneshiged391f002009-02-17 14:13:59 +0900374int acpi_get_hp_hw_control_from_firmware(struct pci_dev *pdev, u32 flags)
Kenji Kaneshigeac9c0522008-05-28 15:01:03 +0900375{
376 acpi_status status;
Jiri Slabye0d94be2008-08-11 17:47:40 +0200377 acpi_handle chandle, handle;
Kenji Kaneshigeac9c0522008-05-28 15:01:03 +0900378 struct acpi_buffer string = { ACPI_ALLOCATE_BUFFER, NULL };
379
380 flags &= (OSC_PCI_EXPRESS_NATIVE_HP_CONTROL |
381 OSC_SHPC_NATIVE_HP_CONTROL |
382 OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL);
383 if (!flags) {
384 err("Invalid flags %u specified!\n", flags);
385 return -EINVAL;
386 }
387
388 /*
389 * Per PCI firmware specification, we should run the ACPI _OSC
390 * method to get control of hotplug hardware before using it. If
391 * an _OSC is missing, we look for an OSHP to do the same thing.
Jiri Slabye0d94be2008-08-11 17:47:40 +0200392 * To handle different BIOS behavior, we look for _OSC on a root
393 * bridge preferentially (according to PCI fw spec). Later for
394 * OSHP within the scope of the hotplug controller and its parents,
Kenji Kaneshigeac9c0522008-05-28 15:01:03 +0900395 * upto the host bridge under which this controller exists.
396 */
Jiri Slaby056c58e2008-08-18 20:22:54 +0200397 handle = acpi_find_root_bridge_handle(pdev);
Jiri Slabye0d94be2008-08-11 17:47:40 +0200398 if (handle) {
399 acpi_get_name(handle, ACPI_FULL_PATHNAME, &string);
400 dbg("Trying to get hotplug control for %s\n",
401 (char *)string.pointer);
Kenji Kaneshige9f5404d2009-02-09 16:00:04 +0900402 status = acpi_pci_osc_control_set(handle, flags);
Jiri Slabye0d94be2008-08-11 17:47:40 +0200403 if (ACPI_SUCCESS(status))
404 goto got_one;
405 kfree(string.pointer);
406 string = (struct acpi_buffer){ ACPI_ALLOCATE_BUFFER, NULL };
407 }
408
Kenji Kaneshiged391f002009-02-17 14:13:59 +0900409 handle = DEVICE_ACPI_HANDLE(&pdev->dev);
410 if (!handle) {
Kenji Kaneshigeac9c0522008-05-28 15:01:03 +0900411 /*
412 * This hotplug controller was not listed in the ACPI name
413 * space at all. Try to get acpi handle of parent pci bus.
414 */
Kenji Kaneshiged391f002009-02-17 14:13:59 +0900415 struct pci_bus *pbus;
416 for (pbus = pdev->bus; pbus; pbus = pbus->parent) {
417 handle = acpi_pci_get_bridge_handle(pbus);
418 if (handle)
419 break;
420 }
Kenji Kaneshigeac9c0522008-05-28 15:01:03 +0900421 }
422
423 while (handle) {
424 acpi_get_name(handle, ACPI_FULL_PATHNAME, &string);
425 dbg("Trying to get hotplug control for %s \n",
426 (char *)string.pointer);
Jiri Slabye0d94be2008-08-11 17:47:40 +0200427 status = acpi_run_oshp(handle);
428 if (ACPI_SUCCESS(status))
429 goto got_one;
Alexander Chiang27558202009-06-10 19:55:14 +0000430 if (acpi_is_root_bridge(handle))
Kenji Kaneshigeac9c0522008-05-28 15:01:03 +0900431 break;
432 chandle = handle;
433 status = acpi_get_parent(chandle, &handle);
434 if (ACPI_FAILURE(status))
435 break;
436 }
437
438 dbg("Cannot get control of hotplug hardware for pci %s\n",
Kenji Kaneshiged391f002009-02-17 14:13:59 +0900439 pci_name(pdev));
Kenji Kaneshigeac9c0522008-05-28 15:01:03 +0900440
441 kfree(string.pointer);
442 return -ENODEV;
Jiri Slabye0d94be2008-08-11 17:47:40 +0200443got_one:
Kenji Kaneshiged391f002009-02-17 14:13:59 +0900444 dbg("Gained control for hotplug HW for pci %s (%s)\n",
445 pci_name(pdev), (char *)string.pointer);
Jiri Slabye0d94be2008-08-11 17:47:40 +0200446 kfree(string.pointer);
447 return 0;
Kenji Kaneshigeac9c0522008-05-28 15:01:03 +0900448}
449EXPORT_SYMBOL(acpi_get_hp_hw_control_from_firmware);
Kristen Accardi783c49f2006-03-03 10:16:05 -0800450
Kenji Kaneshigee8c331e2008-12-17 12:09:12 +0900451static int is_ejectable(acpi_handle handle)
452{
453 acpi_status status;
454 acpi_handle tmp;
455 unsigned long long removable;
456 status = acpi_get_handle(handle, "_ADR", &tmp);
457 if (ACPI_FAILURE(status))
458 return 0;
459 status = acpi_get_handle(handle, "_EJ0", &tmp);
460 if (ACPI_SUCCESS(status))
461 return 1;
462 status = acpi_evaluate_integer(handle, "_RMV", NULL, &removable);
463 if (ACPI_SUCCESS(status) && removable)
464 return 1;
465 return 0;
466}
467
468/**
469 * acpi_pcihp_check_ejectable - check if handle is ejectable ACPI PCI slot
470 * @pbus: the PCI bus of the PCI slot corresponding to 'handle'
471 * @handle: ACPI handle to check
472 *
473 * Return 1 if handle is ejectable PCI slot, 0 otherwise.
474 */
475int acpi_pci_check_ejectable(struct pci_bus *pbus, acpi_handle handle)
476{
477 acpi_handle bridge_handle, parent_handle;
478
479 if (!(bridge_handle = acpi_pci_get_bridge_handle(pbus)))
480 return 0;
481 if ((ACPI_FAILURE(acpi_get_parent(handle, &parent_handle))))
482 return 0;
483 if (bridge_handle != parent_handle)
484 return 0;
485 return is_ejectable(handle);
486}
487EXPORT_SYMBOL_GPL(acpi_pci_check_ejectable);
488
489static acpi_status
490check_hotplug(acpi_handle handle, u32 lvl, void *context, void **rv)
491{
492 int *found = (int *)context;
493 if (is_ejectable(handle)) {
494 *found = 1;
495 return AE_CTRL_TERMINATE;
496 }
497 return AE_OK;
498}
499
500/**
501 * acpi_pci_detect_ejectable - check if the PCI bus has ejectable slots
Alex Chiang7f538662009-09-10 12:34:09 -0600502 * @handle - handle of the PCI bus to scan
Kenji Kaneshigee8c331e2008-12-17 12:09:12 +0900503 *
504 * Returns 1 if the PCI bus has ACPI based ejectable slots, 0 otherwise.
505 */
Alex Chiang7f538662009-09-10 12:34:09 -0600506int acpi_pci_detect_ejectable(acpi_handle handle)
Kenji Kaneshigee8c331e2008-12-17 12:09:12 +0900507{
Kenji Kaneshigee8c331e2008-12-17 12:09:12 +0900508 int found = 0;
509
Alex Chiang7f538662009-09-10 12:34:09 -0600510 if (!handle)
511 return found;
512
513 acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, 1,
Kenji Kaneshigee8c331e2008-12-17 12:09:12 +0900514 check_hotplug, (void *)&found, NULL);
515 return found;
516}
517EXPORT_SYMBOL_GPL(acpi_pci_detect_ejectable);
518
Kenji Kaneshigeaad20ca2006-05-10 22:20:34 +0900519module_param(debug_acpi, bool, 0644);
520MODULE_PARM_DESC(debug_acpi, "Debugging mode for ACPI enabled or not");