2 * Common ACPI functions for hot plug platforms
4 * Copyright (C) 2006 Intel Corporation
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.
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
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.
23 * Send feedback to <kristen.c.accardi@intel.com>
27 #include <linux/module.h>
28 #include <linux/kernel.h>
29 #include <linux/types.h>
30 #include <linux/pci.h>
31 #include <acpi/acpi.h>
32 #include <acpi/acpi_bus.h>
33 #include <acpi/actypes.h>
34 #include "pci_hotplug.h"
36 #define METHOD_NAME__SUN "_SUN"
37 #define METHOD_NAME__HPP "_HPP"
38 #define METHOD_NAME_OSHP "OSHP"
42 acpi_run_hpp(acpi_handle handle, struct hotplug_params *hpp)
46 struct acpi_buffer ret_buf = { 0, NULL};
47 struct acpi_buffer string = { ACPI_ALLOCATE_BUFFER, NULL };
48 union acpi_object *ext_obj, *package;
51 acpi_get_name(handle, ACPI_FULL_PATHNAME, &string);
54 status = acpi_evaluate_object(handle, METHOD_NAME__HPP, NULL, &ret_buf);
56 case AE_BUFFER_OVERFLOW:
57 ret_buf.pointer = kmalloc (ret_buf.length, GFP_KERNEL);
58 if (!ret_buf.pointer) {
59 printk(KERN_ERR "%s:%s alloc for _HPP fail\n",
60 __FUNCTION__, (char *)string.pointer);
61 kfree(string.pointer);
64 status = acpi_evaluate_object(handle, METHOD_NAME__HPP,
66 if (ACPI_SUCCESS(status))
69 if (ACPI_FAILURE(status)) {
70 pr_debug("%s:%s _HPP fail=0x%x\n", __FUNCTION__,
71 (char *)string.pointer, status);
72 kfree(string.pointer);
77 ext_obj = (union acpi_object *) ret_buf.pointer;
78 if (ext_obj->type != ACPI_TYPE_PACKAGE) {
79 printk(KERN_ERR "%s:%s _HPP obj not a package\n", __FUNCTION__,
80 (char *)string.pointer);
85 len = ext_obj->package.count;
86 package = (union acpi_object *) ret_buf.pointer;
87 for ( i = 0; (i < len) || (i < 4); i++) {
88 ext_obj = (union acpi_object *) &package->package.elements[i];
89 switch (ext_obj->type) {
90 case ACPI_TYPE_INTEGER:
91 nui[i] = (u8)ext_obj->integer.value;
94 printk(KERN_ERR "%s:%s _HPP obj type incorrect\n",
95 __FUNCTION__, (char *)string.pointer);
101 hpp->cache_line_size = nui[0];
102 hpp->latency_timer = nui[1];
103 hpp->enable_serr = nui[2];
104 hpp->enable_perr = nui[3];
106 pr_debug(" _HPP: cache_line_size=0x%x\n", hpp->cache_line_size);
107 pr_debug(" _HPP: latency timer =0x%x\n", hpp->latency_timer);
108 pr_debug(" _HPP: enable SERR =0x%x\n", hpp->enable_serr);
109 pr_debug(" _HPP: enable PERR =0x%x\n", hpp->enable_perr);
112 kfree(string.pointer);
113 kfree(ret_buf.pointer);
119 /* acpi_run_oshp - get control of hotplug from the firmware
121 * @handle - the handle of the hotplug controller.
123 acpi_status acpi_run_oshp(acpi_handle handle)
126 struct acpi_buffer string = { ACPI_ALLOCATE_BUFFER, NULL };
128 acpi_get_name(handle, ACPI_FULL_PATHNAME, &string);
131 status = acpi_evaluate_object(handle, METHOD_NAME_OSHP, NULL, NULL);
132 if (ACPI_FAILURE(status))
133 printk(KERN_ERR "%s:%s OSHP fails=0x%x\n", __FUNCTION__,
134 (char *)string.pointer, status);
136 pr_debug("%s:%s OSHP passes\n", __FUNCTION__,
137 (char *)string.pointer);
139 kfree(string.pointer);
142 EXPORT_SYMBOL_GPL(acpi_run_oshp);
146 /* acpi_get_hp_params_from_firmware
148 * @bus - the pci_bus of the bus on which the device is newly added
149 * @hpp - allocated by the caller
151 acpi_status acpi_get_hp_params_from_firmware(struct pci_bus *bus,
152 struct hotplug_params *hpp)
154 acpi_status status = AE_NOT_FOUND;
155 acpi_handle handle, phandle;
156 struct pci_bus *pbus = bus;
157 struct pci_dev *pdev;
162 handle = acpi_get_pci_rootbridge_handle(
163 pci_domain_nr(pbus), pbus->number);
166 handle = DEVICE_ACPI_HANDLE(&(pdev->dev));
171 * _HPP settings apply to all child buses, until another _HPP is
172 * encountered. If we don't find an _HPP for the input pci dev,
173 * look for it in the parent device scope since that would apply to
174 * this pci dev. If we don't find any _HPP, use hardcoded defaults
177 status = acpi_run_hpp(handle, hpp);
178 if (ACPI_SUCCESS(status))
180 if (acpi_root_bridge(handle))
182 status = acpi_get_parent(handle, &phandle);
183 if (ACPI_FAILURE(status))
189 EXPORT_SYMBOL_GPL(acpi_get_hp_params_from_firmware);
192 /* acpi_root_bridge - check to see if this acpi object is a root bridge
194 * @handle - the acpi object in question.
196 int acpi_root_bridge(acpi_handle handle)
199 struct acpi_device_info *info;
200 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
203 status = acpi_get_object_info(handle, &buffer);
204 if (ACPI_SUCCESS(status)) {
205 info = buffer.pointer;
206 if ((info->valid & ACPI_VALID_HID) &&
207 !strcmp(PCI_ROOT_HID_STRING,
208 info->hardware_id.value)) {
209 kfree(buffer.pointer);
212 if (info->valid & ACPI_VALID_CID) {
213 for (i=0; i < info->compatibility_id.count; i++) {
214 if (!strcmp(PCI_ROOT_HID_STRING,
215 info->compatibility_id.id[i].value)) {
216 kfree(buffer.pointer);
221 kfree(buffer.pointer);
225 EXPORT_SYMBOL_GPL(acpi_root_bridge);