aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKenji Kaneshige <kaneshige.kenji@jp.fujitsu.com>2009-02-09 01:59:29 -0500
committerJesse Barnes <jbarnes@hobbes.lan>2009-03-19 22:29:32 -0400
commit63f10f0f6df4e4e860b790d64bebfde85b540b0a (patch)
tree4fd6f1332ec8c0ed0d1758fbddc3d49c5924bdbd
parent5fe5db05f64d0d10b563b1c13b58e4a52b190686 (diff)
PCI/ACPI: move _OSC code to pci_root.c
Move PCI _OSC management code from drivers/pci/pci-acpi.c to drivers/acpi/pci_root.c. The benefits are - We no longer need struct osc_data and its management code (contents are moved to struct acpi_pci_root). This simplify the code, and we no longer care about kmalloc() failure. - We can make pci_acpi_osc_support() be a static function, which is called only from drivers/acpi/pci_root.c. Signed-off-by: Kenji Kaneshige <kaneshige.kenji@jp.fujitsu.com> Reviewed-by: Andrew Patterson <andrew.patterson@hp.com> Tested-by: Andrew Patterson <andrew.patterson@hp.com> Acked-by: Alex Chiang <achiang@hp.com> Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
-rw-r--r--drivers/acpi/pci_root.c180
-rw-r--r--drivers/pci/pci-acpi.c215
-rw-r--r--include/linux/pci-acpi.h1
3 files changed, 178 insertions, 218 deletions
diff --git a/drivers/acpi/pci_root.c b/drivers/acpi/pci_root.c
index 5b38a026d122..979eccc82c5b 100644
--- a/drivers/acpi/pci_root.c
+++ b/drivers/acpi/pci_root.c
@@ -66,11 +66,18 @@ struct acpi_pci_root {
66 struct acpi_device * device; 66 struct acpi_device * device;
67 struct acpi_pci_id id; 67 struct acpi_pci_id id;
68 struct pci_bus *bus; 68 struct pci_bus *bus;
69
70 u32 osc_support_set; /* _OSC state of support bits */
71 u32 osc_control_set; /* _OSC state of control bits */
72 u32 osc_control_qry; /* the latest _OSC query result */
73
74 u32 osc_queried:1; /* has _OSC control been queried? */
69}; 75};
70 76
71static LIST_HEAD(acpi_pci_roots); 77static LIST_HEAD(acpi_pci_roots);
72 78
73static struct acpi_pci_driver *sub_driver; 79static struct acpi_pci_driver *sub_driver;
80static DEFINE_MUTEX(osc_lock);
74 81
75int acpi_pci_register_driver(struct acpi_pci_driver *driver) 82int acpi_pci_register_driver(struct acpi_pci_driver *driver)
76{ 83{
@@ -185,6 +192,175 @@ static void acpi_pci_bridge_scan(struct acpi_device *device)
185 } 192 }
186} 193}
187 194
195static u8 OSC_UUID[16] = {0x5B, 0x4D, 0xDB, 0x33, 0xF7, 0x1F, 0x1C, 0x40,
196 0x96, 0x57, 0x74, 0x41, 0xC0, 0x3D, 0xD7, 0x66};
197
198static acpi_status acpi_pci_run_osc(acpi_handle handle,
199 const u32 *capbuf, u32 *retval)
200{
201 acpi_status status;
202 struct acpi_object_list input;
203 union acpi_object in_params[4];
204 struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL};
205 union acpi_object *out_obj;
206 u32 errors;
207
208 /* Setting up input parameters */
209 input.count = 4;
210 input.pointer = in_params;
211 in_params[0].type = ACPI_TYPE_BUFFER;
212 in_params[0].buffer.length = 16;
213 in_params[0].buffer.pointer = OSC_UUID;
214 in_params[1].type = ACPI_TYPE_INTEGER;
215 in_params[1].integer.value = 1;
216 in_params[2].type = ACPI_TYPE_INTEGER;
217 in_params[2].integer.value = 3;
218 in_params[3].type = ACPI_TYPE_BUFFER;
219 in_params[3].buffer.length = 12;
220 in_params[3].buffer.pointer = (u8 *)capbuf;
221
222 status = acpi_evaluate_object(handle, "_OSC", &input, &output);
223 if (ACPI_FAILURE(status))
224 return status;
225
226 if (!output.length)
227 return AE_NULL_OBJECT;
228
229 out_obj = output.pointer;
230 if (out_obj->type != ACPI_TYPE_BUFFER) {
231 printk(KERN_DEBUG "_OSC evaluation returned wrong type\n");
232 status = AE_TYPE;
233 goto out_kfree;
234 }
235 /* Need to ignore the bit0 in result code */
236 errors = *((u32 *)out_obj->buffer.pointer) & ~(1 << 0);
237 if (errors) {
238 if (errors & OSC_REQUEST_ERROR)
239 printk(KERN_DEBUG "_OSC request failed\n");
240 if (errors & OSC_INVALID_UUID_ERROR)
241 printk(KERN_DEBUG "_OSC invalid UUID\n");
242 if (errors & OSC_INVALID_REVISION_ERROR)
243 printk(KERN_DEBUG "_OSC invalid revision\n");
244 if (errors & OSC_CAPABILITIES_MASK_ERROR) {
245 if (capbuf[OSC_QUERY_TYPE] & OSC_QUERY_ENABLE)
246 goto out_success;
247 printk(KERN_DEBUG
248 "Firmware did not grant requested _OSC control\n");
249 status = AE_SUPPORT;
250 goto out_kfree;
251 }
252 status = AE_ERROR;
253 goto out_kfree;
254 }
255out_success:
256 *retval = *((u32 *)(out_obj->buffer.pointer + 8));
257 status = AE_OK;
258
259out_kfree:
260 kfree(output.pointer);
261 return status;
262}
263
264static acpi_status acpi_pci_query_osc(struct acpi_pci_root *root, u32 flags)
265{
266 acpi_status status;
267 u32 support_set, result, capbuf[3];
268
269 /* do _OSC query for all possible controls */
270 support_set = root->osc_support_set | (flags & OSC_SUPPORT_MASKS);
271 capbuf[OSC_QUERY_TYPE] = OSC_QUERY_ENABLE;
272 capbuf[OSC_SUPPORT_TYPE] = support_set;
273 capbuf[OSC_CONTROL_TYPE] = OSC_CONTROL_MASKS;
274
275 status = acpi_pci_run_osc(root->device->handle, capbuf, &result);
276 if (ACPI_SUCCESS(status)) {
277 root->osc_support_set = support_set;
278 root->osc_control_qry = result;
279 root->osc_queried = 1;
280 }
281 return status;
282}
283
284static acpi_status acpi_pci_osc_support(struct acpi_pci_root *root, u32 flags)
285{
286 acpi_status status;
287 acpi_handle tmp;
288
289 status = acpi_get_handle(root->device->handle, "_OSC", &tmp);
290 if (ACPI_FAILURE(status))
291 return status;
292 mutex_lock(&osc_lock);
293 status = acpi_pci_query_osc(root, flags);
294 mutex_unlock(&osc_lock);
295 return status;
296}
297
298static struct acpi_pci_root *acpi_pci_find_root(acpi_handle handle)
299{
300 struct acpi_pci_root *root;
301 list_for_each_entry(root, &acpi_pci_roots, node) {
302 if (root->device->handle == handle)
303 return root;
304 }
305 return NULL;
306}
307
308/**
309 * pci_osc_control_set - commit requested control to Firmware
310 * @handle: acpi_handle for the target ACPI object
311 * @flags: driver's requested control bits
312 *
313 * Attempt to take control from Firmware on requested control bits.
314 **/
315acpi_status pci_osc_control_set(acpi_handle handle, u32 flags)
316{
317 acpi_status status;
318 u32 control_req, result, capbuf[3];
319 acpi_handle tmp;
320 struct acpi_pci_root *root;
321
322 status = acpi_get_handle(handle, "_OSC", &tmp);
323 if (ACPI_FAILURE(status))
324 return status;
325
326 control_req = (flags & OSC_CONTROL_MASKS);
327 if (!control_req)
328 return AE_TYPE;
329
330 root = acpi_pci_find_root(handle);
331 if (!root)
332 return AE_NOT_EXIST;
333
334 mutex_lock(&osc_lock);
335 /* No need to evaluate _OSC if the control was already granted. */
336 if ((root->osc_control_set & control_req) == control_req)
337 goto out;
338
339 /* Need to query controls first before requesting them */
340 if (!root->osc_queried) {
341 status = acpi_pci_query_osc(root, root->osc_support_set);
342 if (ACPI_FAILURE(status))
343 goto out;
344 }
345 if ((root->osc_control_qry & control_req) != control_req) {
346 printk(KERN_DEBUG
347 "Firmware did not grant requested _OSC control\n");
348 status = AE_SUPPORT;
349 goto out;
350 }
351
352 capbuf[OSC_QUERY_TYPE] = 0;
353 capbuf[OSC_SUPPORT_TYPE] = root->osc_support_set;
354 capbuf[OSC_CONTROL_TYPE] = root->osc_control_set | control_req;
355 status = acpi_pci_run_osc(handle, capbuf, &result);
356 if (ACPI_SUCCESS(status))
357 root->osc_control_set = result;
358out:
359 mutex_unlock(&osc_lock);
360 return status;
361}
362EXPORT_SYMBOL(pci_osc_control_set);
363
188static int __devinit acpi_pci_root_add(struct acpi_device *device) 364static int __devinit acpi_pci_root_add(struct acpi_device *device)
189{ 365{
190 int result = 0; 366 int result = 0;
@@ -217,7 +393,7 @@ static int __devinit acpi_pci_root_add(struct acpi_device *device)
217 * PCI domains, so we indicate this in _OSC support capabilities. 393 * PCI domains, so we indicate this in _OSC support capabilities.
218 */ 394 */
219 flags = base_flags = OSC_PCI_SEGMENT_GROUPS_SUPPORT; 395 flags = base_flags = OSC_PCI_SEGMENT_GROUPS_SUPPORT;
220 pci_acpi_osc_support(device->handle, flags); 396 acpi_pci_osc_support(root, flags);
221 397
222 /* 398 /*
223 * Segment 399 * Segment
@@ -353,7 +529,7 @@ static int __devinit acpi_pci_root_add(struct acpi_device *device)
353 if (pci_msi_enabled()) 529 if (pci_msi_enabled())
354 flags |= OSC_MSI_SUPPORT; 530 flags |= OSC_MSI_SUPPORT;
355 if (flags != base_flags) 531 if (flags != base_flags)
356 pci_acpi_osc_support(device->handle, flags); 532 acpi_pci_osc_support(root, flags);
357 533
358 end: 534 end:
359 if (result) { 535 if (result) {
diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c
index deea8a187eb8..fac5eddcefd2 100644
--- a/drivers/pci/pci-acpi.c
+++ b/drivers/pci/pci-acpi.c
@@ -18,221 +18,6 @@
18#include <linux/pci-acpi.h> 18#include <linux/pci-acpi.h>
19#include "pci.h" 19#include "pci.h"
20 20
21struct acpi_osc_data {
22 acpi_handle handle;
23 u32 support_set;
24 u32 control_set;
25 u32 control_query;
26 int is_queried;
27 struct list_head sibiling;
28};
29static LIST_HEAD(acpi_osc_data_list);
30
31struct acpi_osc_args {
32 u32 capbuf[3];
33};
34
35static DEFINE_MUTEX(pci_acpi_lock);
36
37static struct acpi_osc_data *acpi_get_osc_data(acpi_handle handle)
38{
39 struct acpi_osc_data *data;
40
41 list_for_each_entry(data, &acpi_osc_data_list, sibiling) {
42 if (data->handle == handle)
43 return data;
44 }
45 data = kzalloc(sizeof(*data), GFP_KERNEL);
46 if (!data)
47 return NULL;
48 INIT_LIST_HEAD(&data->sibiling);
49 data->handle = handle;
50 list_add_tail(&data->sibiling, &acpi_osc_data_list);
51 return data;
52}
53
54static u8 OSC_UUID[16] = {0x5B, 0x4D, 0xDB, 0x33, 0xF7, 0x1F, 0x1C, 0x40,
55 0x96, 0x57, 0x74, 0x41, 0xC0, 0x3D, 0xD7, 0x66};
56
57static acpi_status acpi_run_osc(acpi_handle handle,
58 struct acpi_osc_args *osc_args, u32 *retval)
59{
60 acpi_status status;
61 struct acpi_object_list input;
62 union acpi_object in_params[4];
63 struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL};
64 union acpi_object *out_obj;
65 u32 errors, flags = osc_args->capbuf[OSC_QUERY_TYPE];
66
67 /* Setting up input parameters */
68 input.count = 4;
69 input.pointer = in_params;
70 in_params[0].type = ACPI_TYPE_BUFFER;
71 in_params[0].buffer.length = 16;
72 in_params[0].buffer.pointer = OSC_UUID;
73 in_params[1].type = ACPI_TYPE_INTEGER;
74 in_params[1].integer.value = 1;
75 in_params[2].type = ACPI_TYPE_INTEGER;
76 in_params[2].integer.value = 3;
77 in_params[3].type = ACPI_TYPE_BUFFER;
78 in_params[3].buffer.length = 12;
79 in_params[3].buffer.pointer = (u8 *)osc_args->capbuf;
80
81 status = acpi_evaluate_object(handle, "_OSC", &input, &output);
82 if (ACPI_FAILURE(status))
83 return status;
84
85 if (!output.length)
86 return AE_NULL_OBJECT;
87
88 out_obj = output.pointer;
89 if (out_obj->type != ACPI_TYPE_BUFFER) {
90 printk(KERN_DEBUG "Evaluate _OSC returns wrong type\n");
91 status = AE_TYPE;
92 goto out_kfree;
93 }
94 /* Need to ignore the bit0 in result code */
95 errors = *((u32 *)out_obj->buffer.pointer) & ~(1 << 0);
96 if (errors) {
97 if (errors & OSC_REQUEST_ERROR)
98 printk(KERN_DEBUG "_OSC request fails\n");
99 if (errors & OSC_INVALID_UUID_ERROR)
100 printk(KERN_DEBUG "_OSC invalid UUID\n");
101 if (errors & OSC_INVALID_REVISION_ERROR)
102 printk(KERN_DEBUG "_OSC invalid revision\n");
103 if (errors & OSC_CAPABILITIES_MASK_ERROR) {
104 if (flags & OSC_QUERY_ENABLE)
105 goto out_success;
106 printk(KERN_DEBUG "_OSC FW not grant req. control\n");
107 status = AE_SUPPORT;
108 goto out_kfree;
109 }
110 status = AE_ERROR;
111 goto out_kfree;
112 }
113out_success:
114 *retval = *((u32 *)(out_obj->buffer.pointer + 8));
115 status = AE_OK;
116
117out_kfree:
118 kfree(output.pointer);
119 return status;
120}
121
122static acpi_status __acpi_query_osc(u32 flags, struct acpi_osc_data *osc_data)
123{
124 acpi_status status;
125 u32 support_set, result;
126 struct acpi_osc_args osc_args;
127
128 /* do _OSC query for all possible controls */
129 support_set = osc_data->support_set | (flags & OSC_SUPPORT_MASKS);
130 osc_args.capbuf[OSC_QUERY_TYPE] = OSC_QUERY_ENABLE;
131 osc_args.capbuf[OSC_SUPPORT_TYPE] = support_set;
132 osc_args.capbuf[OSC_CONTROL_TYPE] = OSC_CONTROL_MASKS;
133
134 status = acpi_run_osc(osc_data->handle, &osc_args, &result);
135 if (ACPI_SUCCESS(status)) {
136 osc_data->support_set = support_set;
137 osc_data->control_query = result;
138 osc_data->is_queried = 1;
139 }
140
141 return status;
142}
143
144/*
145 * pci_acpi_osc_support: Invoke _OSC indicating support for the given feature
146 * @flags: Bitmask of flags to support
147 *
148 * See the ACPI spec for the definition of the flags
149 */
150int pci_acpi_osc_support(acpi_handle handle, u32 flags)
151{
152 acpi_status status;
153 acpi_handle tmp;
154 struct acpi_osc_data *osc_data;
155 int rc = 0;
156
157 status = acpi_get_handle(handle, "_OSC", &tmp);
158 if (ACPI_FAILURE(status))
159 return -ENOTTY;
160
161 mutex_lock(&pci_acpi_lock);
162 osc_data = acpi_get_osc_data(handle);
163 if (!osc_data) {
164 printk(KERN_ERR "acpi osc data array is full\n");
165 rc = -ENOMEM;
166 goto out;
167 }
168
169 __acpi_query_osc(flags, osc_data);
170out:
171 mutex_unlock(&pci_acpi_lock);
172 return rc;
173}
174
175/**
176 * pci_osc_control_set - commit requested control to Firmware
177 * @handle: acpi_handle for the target ACPI object
178 * @flags: driver's requested control bits
179 *
180 * Attempt to take control from Firmware on requested control bits.
181 **/
182acpi_status pci_osc_control_set(acpi_handle handle, u32 flags)
183{
184 acpi_status status;
185 u32 control_req, control_set, result;
186 acpi_handle tmp;
187 struct acpi_osc_data *osc_data;
188 struct acpi_osc_args osc_args;
189
190 status = acpi_get_handle(handle, "_OSC", &tmp);
191 if (ACPI_FAILURE(status))
192 return status;
193
194 mutex_lock(&pci_acpi_lock);
195 osc_data = acpi_get_osc_data(handle);
196 if (!osc_data) {
197 printk(KERN_ERR "acpi osc data array is full\n");
198 status = AE_ERROR;
199 goto out;
200 }
201
202 control_req = (flags & OSC_CONTROL_MASKS);
203 if (!control_req) {
204 status = AE_TYPE;
205 goto out;
206 }
207
208 /* No need to evaluate _OSC if the control was already granted. */
209 if ((osc_data->control_set & control_req) == control_req)
210 goto out;
211
212 if (!osc_data->is_queried) {
213 status = __acpi_query_osc(osc_data->support_set, osc_data);
214 if (ACPI_FAILURE(status))
215 goto out;
216 }
217
218 if ((osc_data->control_query & control_req) != control_req) {
219 status = AE_SUPPORT;
220 goto out;
221 }
222
223 control_set = osc_data->control_set | control_req;
224 osc_args.capbuf[OSC_QUERY_TYPE] = 0;
225 osc_args.capbuf[OSC_SUPPORT_TYPE] = osc_data->support_set;
226 osc_args.capbuf[OSC_CONTROL_TYPE] = control_set;
227 status = acpi_run_osc(handle, &osc_args, &result);
228 if (ACPI_SUCCESS(status))
229 osc_data->control_set = result;
230out:
231 mutex_unlock(&pci_acpi_lock);
232 return status;
233}
234EXPORT_SYMBOL(pci_osc_control_set);
235
236/* 21/*
237 * _SxD returns the D-state with the highest power 22 * _SxD returns the D-state with the highest power
238 * (lowest D-state number) supported in the S-state "x". 23 * (lowest D-state number) supported in the S-state "x".
diff --git a/include/linux/pci-acpi.h b/include/linux/pci-acpi.h
index 042c166f65d5..65cb103b21db 100644
--- a/include/linux/pci-acpi.h
+++ b/include/linux/pci-acpi.h
@@ -50,7 +50,6 @@
50 50
51#ifdef CONFIG_ACPI 51#ifdef CONFIG_ACPI
52extern acpi_status pci_osc_control_set(acpi_handle handle, u32 flags); 52extern acpi_status pci_osc_control_set(acpi_handle handle, u32 flags);
53int pci_acpi_osc_support(acpi_handle handle, u32 flags);
54static inline acpi_handle acpi_find_root_bridge_handle(struct pci_dev *pdev) 53static inline acpi_handle acpi_find_root_bridge_handle(struct pci_dev *pdev)
55{ 54{
56 /* Find root host bridge */ 55 /* Find root host bridge */