blob: 64cb30d7fc9a9b1259e3c6b342ebf268a2476268 [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>
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"
35
36#define METHOD_NAME__SUN "_SUN"
37#define METHOD_NAME__HPP "_HPP"
38#define METHOD_NAME_OSHP "OSHP"
39
Kristen Accardi783c49f2006-03-03 10:16:05 -080040
41static acpi_status
42acpi_run_hpp(acpi_handle handle, struct hotplug_params *hpp)
43{
44 acpi_status status;
45 u8 nui[4];
46 struct acpi_buffer ret_buf = { 0, NULL};
MUNEDA Takahirob2e6e3b2006-03-17 09:18:39 +090047 struct acpi_buffer string = { ACPI_ALLOCATE_BUFFER, NULL };
Kristen Accardi783c49f2006-03-03 10:16:05 -080048 union acpi_object *ext_obj, *package;
Kristen Accardi783c49f2006-03-03 10:16:05 -080049 int i, len = 0;
50
MUNEDA Takahirob2e6e3b2006-03-17 09:18:39 +090051 acpi_get_name(handle, ACPI_FULL_PATHNAME, &string);
52
Kristen Accardi783c49f2006-03-03 10:16:05 -080053 /* get _hpp */
54 status = acpi_evaluate_object(handle, METHOD_NAME__HPP, NULL, &ret_buf);
55 switch (status) {
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",
MUNEDA Takahirob2e6e3b2006-03-17 09:18:39 +090060 __FUNCTION__, (char *)string.pointer);
Kristen Accardi81b26bc2006-04-18 14:36:43 -070061 kfree(string.pointer);
Kristen Accardi783c49f2006-03-03 10:16:05 -080062 return AE_NO_MEMORY;
63 }
64 status = acpi_evaluate_object(handle, METHOD_NAME__HPP,
65 NULL, &ret_buf);
66 if (ACPI_SUCCESS(status))
67 break;
68 default:
69 if (ACPI_FAILURE(status)) {
70 pr_debug("%s:%s _HPP fail=0x%x\n", __FUNCTION__,
MUNEDA Takahirob2e6e3b2006-03-17 09:18:39 +090071 (char *)string.pointer, status);
Kristen Accardi81b26bc2006-04-18 14:36:43 -070072 kfree(string.pointer);
Kristen Accardi783c49f2006-03-03 10:16:05 -080073 return status;
74 }
75 }
76
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__,
MUNEDA Takahirob2e6e3b2006-03-17 09:18:39 +090080 (char *)string.pointer);
Kristen Accardi783c49f2006-03-03 10:16:05 -080081 status = AE_ERROR;
82 goto free_and_return;
83 }
84
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;
92 break;
93 default:
94 printk(KERN_ERR "%s:%s _HPP obj type incorrect\n",
MUNEDA Takahirob2e6e3b2006-03-17 09:18:39 +090095 __FUNCTION__, (char *)string.pointer);
Kristen Accardi783c49f2006-03-03 10:16:05 -080096 status = AE_ERROR;
97 goto free_and_return;
98 }
99 }
100
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];
105
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);
110
111free_and_return:
Kristen Accardi81b26bc2006-04-18 14:36:43 -0700112 kfree(string.pointer);
113 kfree(ret_buf.pointer);
Kristen Accardi783c49f2006-03-03 10:16:05 -0800114 return status;
115}
116
117
118
119/* acpi_run_oshp - get control of hotplug from the firmware
120 *
121 * @handle - the handle of the hotplug controller.
122 */
123acpi_status acpi_run_oshp(acpi_handle handle)
124{
125 acpi_status status;
MUNEDA Takahirob2e6e3b2006-03-17 09:18:39 +0900126 struct acpi_buffer string = { ACPI_ALLOCATE_BUFFER, NULL };
127
128 acpi_get_name(handle, ACPI_FULL_PATHNAME, &string);
Kristen Accardi783c49f2006-03-03 10:16:05 -0800129
130 /* run OSHP */
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__,
MUNEDA Takahirob2e6e3b2006-03-17 09:18:39 +0900134 (char *)string.pointer, status);
Kristen Accardi783c49f2006-03-03 10:16:05 -0800135 else
MUNEDA Takahirob2e6e3b2006-03-17 09:18:39 +0900136 pr_debug("%s:%s OSHP passes\n", __FUNCTION__,
137 (char *)string.pointer);
138
Kristen Accardi81b26bc2006-04-18 14:36:43 -0700139 kfree(string.pointer);
Kristen Accardi783c49f2006-03-03 10:16:05 -0800140 return status;
141}
142EXPORT_SYMBOL_GPL(acpi_run_oshp);
143
144
145
146/* acpi_get_hp_params_from_firmware
147 *
148 * @dev - the pci_dev of the newly added device
149 * @hpp - allocated by the caller
150 */
151acpi_status acpi_get_hp_params_from_firmware(struct pci_dev *dev,
152 struct hotplug_params *hpp)
153{
154 acpi_status status = AE_NOT_FOUND;
155 struct pci_dev *pdev = dev;
156
157 /*
158 * _HPP settings apply to all child buses, until another _HPP is
159 * encountered. If we don't find an _HPP for the input pci dev,
160 * look for it in the parent device scope since that would apply to
161 * this pci dev. If we don't find any _HPP, use hardcoded defaults
162 */
163 while (pdev && (ACPI_FAILURE(status))) {
164 acpi_handle handle = DEVICE_ACPI_HANDLE(&(pdev->dev));
165 if (!handle)
166 break;
167 status = acpi_run_hpp(handle, hpp);
168 if (!(pdev->bus->parent))
169 break;
170 /* Check if a parent object supports _HPP */
171 pdev = pdev->bus->parent->self;
172 }
173 return status;
174}
175EXPORT_SYMBOL_GPL(acpi_get_hp_params_from_firmware);
176
177
178/* acpi_root_bridge - check to see if this acpi object is a root bridge
179 *
180 * @handle - the acpi object in question.
181 */
182int acpi_root_bridge(acpi_handle handle)
183{
184 acpi_status status;
185 struct acpi_device_info *info;
186 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
187 int i;
188
189 status = acpi_get_object_info(handle, &buffer);
190 if (ACPI_SUCCESS(status)) {
191 info = buffer.pointer;
192 if ((info->valid & ACPI_VALID_HID) &&
193 !strcmp(PCI_ROOT_HID_STRING,
194 info->hardware_id.value)) {
Kristen Accardi81b26bc2006-04-18 14:36:43 -0700195 kfree(buffer.pointer);
Kristen Accardi783c49f2006-03-03 10:16:05 -0800196 return 1;
197 }
198 if (info->valid & ACPI_VALID_CID) {
199 for (i=0; i < info->compatibility_id.count; i++) {
200 if (!strcmp(PCI_ROOT_HID_STRING,
201 info->compatibility_id.id[i].value)) {
Kristen Accardi81b26bc2006-04-18 14:36:43 -0700202 kfree(buffer.pointer);
Kristen Accardi783c49f2006-03-03 10:16:05 -0800203 return 1;
204 }
205 }
206 }
Kristen Accardi81b26bc2006-04-18 14:36:43 -0700207 kfree(buffer.pointer);
Kristen Accardi783c49f2006-03-03 10:16:05 -0800208 }
209 return 0;
210}
211EXPORT_SYMBOL_GPL(acpi_root_bridge);