blob: fe86b37b16ce657bd719b68c656ce252581a0452 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*******************************************************************************
2 *
3 * Module Name: rsxface - Public interfaces to the resource manager
4 *
5 ******************************************************************************/
6
7/*
Bob Mooreb4e104e2011-01-17 11:05:40 +08008 * Copyright (C) 2000 - 2011, Intel Corp.
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
Paul Gortmaker214f2c92011-10-26 16:22:14 -040044#include <linux/export.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <acpi/acpi.h>
Len Browne2f7a772009-01-09 00:30:03 -050046#include "accommon.h"
47#include "acresrc.h"
48#include "acnamesp.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50#define _COMPONENT ACPI_RESOURCES
Len Brown4be44fc2005-08-05 00:44:28 -040051ACPI_MODULE_NAME("rsxface")
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Robert Moore44f6c012005-04-18 22:49:35 -040053/* Local macros for 16,32-bit to 64-bit conversion */
Robert Moore44f6c012005-04-18 22:49:35 -040054#define ACPI_COPY_FIELD(out, in, field) ((out)->field = (in)->field)
55#define ACPI_COPY_ADDRESS(out, in) \
56 ACPI_COPY_FIELD(out, in, resource_type); \
57 ACPI_COPY_FIELD(out, in, producer_consumer); \
58 ACPI_COPY_FIELD(out, in, decode); \
59 ACPI_COPY_FIELD(out, in, min_address_fixed); \
60 ACPI_COPY_FIELD(out, in, max_address_fixed); \
Bob Moore08978312005-10-21 00:00:00 -040061 ACPI_COPY_FIELD(out, in, info); \
Robert Moore44f6c012005-04-18 22:49:35 -040062 ACPI_COPY_FIELD(out, in, granularity); \
Bob Moore50eca3e2005-09-30 19:03:00 -040063 ACPI_COPY_FIELD(out, in, minimum); \
64 ACPI_COPY_FIELD(out, in, maximum); \
65 ACPI_COPY_FIELD(out, in, translation_offset); \
Robert Moore44f6c012005-04-18 22:49:35 -040066 ACPI_COPY_FIELD(out, in, address_length); \
67 ACPI_COPY_FIELD(out, in, resource_source);
Bob Moorec51a4de2005-11-17 13:07:00 -050068/* Local prototypes */
69static acpi_status
70acpi_rs_match_vendor_resource(struct acpi_resource *resource, void *context);
71
Bob Moore41195322006-05-26 16:36:00 -040072static acpi_status
73acpi_rs_validate_parameters(acpi_handle device_handle,
74 struct acpi_buffer *buffer,
75 struct acpi_namespace_node **return_node);
76
77/*******************************************************************************
78 *
79 * FUNCTION: acpi_rs_validate_parameters
80 *
81 * PARAMETERS: device_handle - Handle to a device
82 * Buffer - Pointer to a data buffer
83 * return_node - Pointer to where the device node is returned
84 *
85 * RETURN: Status
86 *
87 * DESCRIPTION: Common parameter validation for resource interfaces
88 *
89 ******************************************************************************/
90
91static acpi_status
92acpi_rs_validate_parameters(acpi_handle device_handle,
93 struct acpi_buffer *buffer,
94 struct acpi_namespace_node **return_node)
95{
96 acpi_status status;
97 struct acpi_namespace_node *node;
98
99 ACPI_FUNCTION_TRACE(rs_validate_parameters);
100
101 /*
102 * Must have a valid handle to an ACPI device
103 */
104 if (!device_handle) {
105 return_ACPI_STATUS(AE_BAD_PARAMETER);
106 }
107
Bob Mooref24b6642009-12-11 14:57:00 +0800108 node = acpi_ns_validate_handle(device_handle);
Bob Moore41195322006-05-26 16:36:00 -0400109 if (!node) {
110 return_ACPI_STATUS(AE_BAD_PARAMETER);
111 }
112
113 if (node->type != ACPI_TYPE_DEVICE) {
114 return_ACPI_STATUS(AE_TYPE);
115 }
116
117 /*
118 * Validate the user buffer object
119 *
120 * if there is a non-zero buffer length we also need a valid pointer in
121 * the buffer. If it's a zero buffer length, we'll be returning the
122 * needed buffer size (later), so keep going.
123 */
124 status = acpi_ut_validate_buffer(buffer);
125 if (ACPI_FAILURE(status)) {
126 return_ACPI_STATUS(status);
127 }
128
129 *return_node = node;
130 return_ACPI_STATUS(AE_OK);
131}
132
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133/*******************************************************************************
134 *
135 * FUNCTION: acpi_get_irq_routing_table
136 *
Bob Moore41195322006-05-26 16:36:00 -0400137 * PARAMETERS: device_handle - Handle to the Bus device we are querying
138 * ret_buffer - Pointer to a buffer to receive the
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 * current resources for the device
140 *
141 * RETURN: Status
142 *
143 * DESCRIPTION: This function is called to get the IRQ routing table for a
Bob Moore41195322006-05-26 16:36:00 -0400144 * specific bus. The caller must first acquire a handle for the
145 * desired bus. The routine table is placed in the buffer pointed
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 * to by the ret_buffer variable parameter.
147 *
148 * If the function fails an appropriate status will be returned
149 * and the value of ret_buffer is undefined.
150 *
151 * This function attempts to execute the _PRT method contained in
152 * the object indicated by the passed device_handle.
153 *
154 ******************************************************************************/
Bob Moorec51a4de2005-11-17 13:07:00 -0500155
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400157acpi_get_irq_routing_table(acpi_handle device_handle,
158 struct acpi_buffer *ret_buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159{
Len Brown4be44fc2005-08-05 00:44:28 -0400160 acpi_status status;
Bob Moore41195322006-05-26 16:36:00 -0400161 struct acpi_namespace_node *node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
Bob Mooreb229cf92006-04-21 17:15:00 -0400163 ACPI_FUNCTION_TRACE(acpi_get_irq_routing_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164
Bob Moore41195322006-05-26 16:36:00 -0400165 /* Validate parameters then dispatch to internal routine */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
Bob Moore41195322006-05-26 16:36:00 -0400167 status = acpi_rs_validate_parameters(device_handle, ret_buffer, &node);
Len Brown4be44fc2005-08-05 00:44:28 -0400168 if (ACPI_FAILURE(status)) {
169 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 }
171
Bob Moore41195322006-05-26 16:36:00 -0400172 status = acpi_rs_get_prt_method_data(node, ret_buffer);
Len Brown4be44fc2005-08-05 00:44:28 -0400173 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174}
175
Bob Moore83135242006-10-03 00:00:00 -0400176ACPI_EXPORT_SYMBOL(acpi_get_irq_routing_table)
177
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178/*******************************************************************************
179 *
180 * FUNCTION: acpi_get_current_resources
181 *
Bob Moore41195322006-05-26 16:36:00 -0400182 * PARAMETERS: device_handle - Handle to the device object for the
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 * device we are querying
Bob Moore41195322006-05-26 16:36:00 -0400184 * ret_buffer - Pointer to a buffer to receive the
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 * current resources for the device
186 *
187 * RETURN: Status
188 *
189 * DESCRIPTION: This function is called to get the current resources for a
Bob Moore41195322006-05-26 16:36:00 -0400190 * specific device. The caller must first acquire a handle for
191 * the desired device. The resource data is placed in the buffer
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 * pointed to by the ret_buffer variable parameter.
193 *
194 * If the function fails an appropriate status will be returned
195 * and the value of ret_buffer is undefined.
196 *
197 * This function attempts to execute the _CRS method contained in
198 * the object indicated by the passed device_handle.
199 *
200 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400202acpi_get_current_resources(acpi_handle device_handle,
203 struct acpi_buffer *ret_buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204{
Len Brown4be44fc2005-08-05 00:44:28 -0400205 acpi_status status;
Bob Moore41195322006-05-26 16:36:00 -0400206 struct acpi_namespace_node *node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207
Bob Mooreb229cf92006-04-21 17:15:00 -0400208 ACPI_FUNCTION_TRACE(acpi_get_current_resources);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
Bob Moore41195322006-05-26 16:36:00 -0400210 /* Validate parameters then dispatch to internal routine */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
Bob Moore41195322006-05-26 16:36:00 -0400212 status = acpi_rs_validate_parameters(device_handle, ret_buffer, &node);
Len Brown4be44fc2005-08-05 00:44:28 -0400213 if (ACPI_FAILURE(status)) {
214 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 }
216
Bob Moore41195322006-05-26 16:36:00 -0400217 status = acpi_rs_get_crs_method_data(node, ret_buffer);
Len Brown4be44fc2005-08-05 00:44:28 -0400218 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
Bob Moore83135242006-10-03 00:00:00 -0400221ACPI_EXPORT_SYMBOL(acpi_get_current_resources)
Bob Moore83135242006-10-03 00:00:00 -0400222#ifdef ACPI_FUTURE_USAGE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223/*******************************************************************************
224 *
225 * FUNCTION: acpi_get_possible_resources
226 *
Bob Moore41195322006-05-26 16:36:00 -0400227 * PARAMETERS: device_handle - Handle to the device object for the
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 * device we are querying
Bob Moore41195322006-05-26 16:36:00 -0400229 * ret_buffer - Pointer to a buffer to receive the
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 * resources for the device
231 *
232 * RETURN: Status
233 *
234 * DESCRIPTION: This function is called to get a list of the possible resources
Bob Moore41195322006-05-26 16:36:00 -0400235 * for a specific device. The caller must first acquire a handle
236 * for the desired device. The resource data is placed in the
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 * buffer pointed to by the ret_buffer variable.
238 *
239 * If the function fails an appropriate status will be returned
240 * and the value of ret_buffer is undefined.
241 *
242 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400244acpi_get_possible_resources(acpi_handle device_handle,
245 struct acpi_buffer *ret_buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246{
Len Brown4be44fc2005-08-05 00:44:28 -0400247 acpi_status status;
Bob Moore41195322006-05-26 16:36:00 -0400248 struct acpi_namespace_node *node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249
Bob Mooreb229cf92006-04-21 17:15:00 -0400250 ACPI_FUNCTION_TRACE(acpi_get_possible_resources);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251
Bob Moore41195322006-05-26 16:36:00 -0400252 /* Validate parameters then dispatch to internal routine */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253
Bob Moore41195322006-05-26 16:36:00 -0400254 status = acpi_rs_validate_parameters(device_handle, ret_buffer, &node);
Len Brown4be44fc2005-08-05 00:44:28 -0400255 if (ACPI_FAILURE(status)) {
256 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 }
258
Bob Moore41195322006-05-26 16:36:00 -0400259 status = acpi_rs_get_prs_method_data(node, ret_buffer);
Len Brown4be44fc2005-08-05 00:44:28 -0400260 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262
Bob Moore83135242006-10-03 00:00:00 -0400263ACPI_EXPORT_SYMBOL(acpi_get_possible_resources)
Len Brown4be44fc2005-08-05 00:44:28 -0400264#endif /* ACPI_FUTURE_USAGE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265/*******************************************************************************
266 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 * FUNCTION: acpi_set_current_resources
268 *
Bob Moore41195322006-05-26 16:36:00 -0400269 * PARAMETERS: device_handle - Handle to the device object for the
270 * device we are setting resources
271 * in_buffer - Pointer to a buffer containing the
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 * resources to be set for the device
273 *
274 * RETURN: Status
275 *
276 * DESCRIPTION: This function is called to set the current resources for a
Bob Moore41195322006-05-26 16:36:00 -0400277 * specific device. The caller must first acquire a handle for
278 * the desired device. The resource data is passed to the routine
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 * the buffer pointed to by the in_buffer variable.
280 *
281 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400283acpi_set_current_resources(acpi_handle device_handle,
284 struct acpi_buffer *in_buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285{
Len Brown4be44fc2005-08-05 00:44:28 -0400286 acpi_status status;
Bob Moore41195322006-05-26 16:36:00 -0400287 struct acpi_namespace_node *node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288
Bob Mooreb229cf92006-04-21 17:15:00 -0400289 ACPI_FUNCTION_TRACE(acpi_set_current_resources);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290
Bob Moore41195322006-05-26 16:36:00 -0400291 /* Validate the buffer, don't allow zero length */
Robert Moore44f6c012005-04-18 22:49:35 -0400292
Bob Moore41195322006-05-26 16:36:00 -0400293 if ((!in_buffer) || (!in_buffer->pointer) || (!in_buffer->length)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400294 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 }
296
Bob Moore41195322006-05-26 16:36:00 -0400297 /* Validate parameters then dispatch to internal routine */
298
299 status = acpi_rs_validate_parameters(device_handle, in_buffer, &node);
300 if (ACPI_FAILURE(status)) {
301 return_ACPI_STATUS(status);
302 }
303
304 status = acpi_rs_set_srs_method_data(node, in_buffer);
Len Brown4be44fc2005-08-05 00:44:28 -0400305 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307
Bob Moore83135242006-10-03 00:00:00 -0400308ACPI_EXPORT_SYMBOL(acpi_set_current_resources)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310/******************************************************************************
311 *
312 * FUNCTION: acpi_resource_to_address64
313 *
Bob Moore41195322006-05-26 16:36:00 -0400314 * PARAMETERS: Resource - Pointer to a resource
315 * Out - Pointer to the users's return buffer
316 * (a struct acpi_resource_address64)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 *
318 * RETURN: Status
319 *
320 * DESCRIPTION: If the resource is an address16, address32, or address64,
Bob Moore41195322006-05-26 16:36:00 -0400321 * copy it to the address64 return buffer. This saves the
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 * caller from having to duplicate code for different-sized
323 * addresses.
324 *
325 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400327acpi_resource_to_address64(struct acpi_resource *resource,
328 struct acpi_resource_address64 *out)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329{
Len Brown4be44fc2005-08-05 00:44:28 -0400330 struct acpi_resource_address16 *address16;
331 struct acpi_resource_address32 *address32;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332
Bob Moorec51a4de2005-11-17 13:07:00 -0500333 if (!resource || !out) {
334 return (AE_BAD_PARAMETER);
335 }
336
337 /* Convert 16 or 32 address descriptor to 64 */
338
Robert Moorebda663d2005-09-16 16:51:15 -0400339 switch (resource->type) {
Bob Moore50eca3e2005-09-30 19:03:00 -0400340 case ACPI_RESOURCE_TYPE_ADDRESS16:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341
Bob Mooreba9c3f52009-04-22 13:13:48 +0800342 address16 =
343 ACPI_CAST_PTR(struct acpi_resource_address16,
344 &resource->data);
Len Brown4be44fc2005-08-05 00:44:28 -0400345 ACPI_COPY_ADDRESS(out, address16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 break;
347
Bob Moore50eca3e2005-09-30 19:03:00 -0400348 case ACPI_RESOURCE_TYPE_ADDRESS32:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349
Bob Mooreba9c3f52009-04-22 13:13:48 +0800350 address32 =
351 ACPI_CAST_PTR(struct acpi_resource_address32,
352 &resource->data);
Len Brown4be44fc2005-08-05 00:44:28 -0400353 ACPI_COPY_ADDRESS(out, address32);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 break;
355
Bob Moore50eca3e2005-09-30 19:03:00 -0400356 case ACPI_RESOURCE_TYPE_ADDRESS64:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357
358 /* Simple copy for 64 bit source */
359
Len Brown4be44fc2005-08-05 00:44:28 -0400360 ACPI_MEMCPY(out, &resource->data,
361 sizeof(struct acpi_resource_address64));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 break;
363
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 default:
365 return (AE_BAD_PARAMETER);
366 }
367
368 return (AE_OK);
369}
Len Brown4be44fc2005-08-05 00:44:28 -0400370
Bob Moore83135242006-10-03 00:00:00 -0400371ACPI_EXPORT_SYMBOL(acpi_resource_to_address64)
Bob Moorec51a4de2005-11-17 13:07:00 -0500372
373/*******************************************************************************
374 *
375 * FUNCTION: acpi_get_vendor_resource
376 *
Bob Moore41195322006-05-26 16:36:00 -0400377 * PARAMETERS: device_handle - Handle for the parent device object
378 * Name - Method name for the parent resource
379 * (METHOD_NAME__CRS or METHOD_NAME__PRS)
380 * Uuid - Pointer to the UUID to be matched.
381 * includes both subtype and 16-byte UUID
382 * ret_buffer - Where the vendor resource is returned
Bob Moorec51a4de2005-11-17 13:07:00 -0500383 *
384 * RETURN: Status
385 *
386 * DESCRIPTION: Walk a resource template for the specified evice to find a
387 * vendor-defined resource that matches the supplied UUID and
388 * UUID subtype. Returns a struct acpi_resource of type Vendor.
389 *
390 ******************************************************************************/
Bob Moorec51a4de2005-11-17 13:07:00 -0500391acpi_status
392acpi_get_vendor_resource(acpi_handle device_handle,
393 char *name,
394 struct acpi_vendor_uuid * uuid,
395 struct acpi_buffer * ret_buffer)
396{
397 struct acpi_vendor_walk_info info;
398 acpi_status status;
399
400 /* Other parameters are validated by acpi_walk_resources */
401
402 if (!uuid || !ret_buffer) {
403 return (AE_BAD_PARAMETER);
404 }
405
406 info.uuid = uuid;
407 info.buffer = ret_buffer;
408 info.status = AE_NOT_EXIST;
409
410 /* Walk the _CRS or _PRS resource list for this device */
411
412 status =
413 acpi_walk_resources(device_handle, name,
414 acpi_rs_match_vendor_resource, &info);
415 if (ACPI_FAILURE(status)) {
416 return (status);
417 }
418
419 return (info.status);
420}
421
Bob Moore83135242006-10-03 00:00:00 -0400422ACPI_EXPORT_SYMBOL(acpi_get_vendor_resource)
423
Bob Moorec51a4de2005-11-17 13:07:00 -0500424/*******************************************************************************
425 *
426 * FUNCTION: acpi_rs_match_vendor_resource
427 *
Bob Moore616861242006-03-17 16:44:00 -0500428 * PARAMETERS: acpi_walk_resource_callback
Bob Moorec51a4de2005-11-17 13:07:00 -0500429 *
430 * RETURN: Status
431 *
432 * DESCRIPTION: Match a vendor resource via the ACPI 3.0 UUID
433 *
434 ******************************************************************************/
Bob Moorec51a4de2005-11-17 13:07:00 -0500435static acpi_status
436acpi_rs_match_vendor_resource(struct acpi_resource *resource, void *context)
437{
438 struct acpi_vendor_walk_info *info = context;
439 struct acpi_resource_vendor_typed *vendor;
440 struct acpi_buffer *buffer;
441 acpi_status status;
442
443 /* Ignore all descriptors except Vendor */
444
445 if (resource->type != ACPI_RESOURCE_TYPE_VENDOR) {
446 return (AE_OK);
447 }
448
449 vendor = &resource->data.vendor_typed;
450
451 /*
452 * For a valid match, these conditions must hold:
453 *
454 * 1) Length of descriptor data must be at least as long as a UUID struct
455 * 2) The UUID subtypes must match
456 * 3) The UUID data must match
457 */
458 if ((vendor->byte_length < (ACPI_UUID_LENGTH + 1)) ||
459 (vendor->uuid_subtype != info->uuid->subtype) ||
460 (ACPI_MEMCMP(vendor->uuid, info->uuid->data, ACPI_UUID_LENGTH))) {
461 return (AE_OK);
462 }
463
464 /* Validate/Allocate/Clear caller buffer */
465
466 buffer = info->buffer;
467 status = acpi_ut_initialize_buffer(buffer, resource->length);
468 if (ACPI_FAILURE(status)) {
469 return (status);
470 }
471
472 /* Found the correct resource, copy and return it */
473
474 ACPI_MEMCPY(buffer->pointer, resource, resource->length);
475 buffer->length = resource->length;
476
477 /* Found the desired descriptor, terminate resource walk */
478
479 info->status = AE_OK;
480 return (AE_CTRL_TERMINATE);
481}
Bob Moore83135242006-10-03 00:00:00 -0400482
Bob Moore41195322006-05-26 16:36:00 -0400483/*******************************************************************************
484 *
485 * FUNCTION: acpi_walk_resources
486 *
487 * PARAMETERS: device_handle - Handle to the device object for the
488 * device we are querying
489 * Name - Method name of the resources we want
490 * (METHOD_NAME__CRS or METHOD_NAME__PRS)
491 * user_function - Called for each resource
492 * Context - Passed to user_function
493 *
494 * RETURN: Status
495 *
496 * DESCRIPTION: Retrieves the current or possible resource list for the
497 * specified device. The user_function is called once for
498 * each resource in the list.
499 *
500 ******************************************************************************/
Bob Moore41195322006-05-26 16:36:00 -0400501acpi_status
502acpi_walk_resources(acpi_handle device_handle,
503 char *name,
504 acpi_walk_resource_callback user_function, void *context)
505{
506 acpi_status status;
507 struct acpi_buffer buffer;
508 struct acpi_resource *resource;
509 struct acpi_resource *resource_end;
510
511 ACPI_FUNCTION_TRACE(acpi_walk_resources);
512
513 /* Parameter validation */
514
515 if (!device_handle || !user_function || !name ||
516 (!ACPI_COMPARE_NAME(name, METHOD_NAME__CRS) &&
517 !ACPI_COMPARE_NAME(name, METHOD_NAME__PRS))) {
518 return_ACPI_STATUS(AE_BAD_PARAMETER);
519 }
520
521 /* Get the _CRS or _PRS resource list */
522
523 buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER;
524 status = acpi_rs_get_method_data(device_handle, name, &buffer);
525 if (ACPI_FAILURE(status)) {
526 return_ACPI_STATUS(status);
527 }
528
529 /* Buffer now contains the resource list */
530
531 resource = ACPI_CAST_PTR(struct acpi_resource, buffer.pointer);
532 resource_end =
533 ACPI_ADD_PTR(struct acpi_resource, buffer.pointer, buffer.length);
534
535 /* Walk the resource list until the end_tag is found (or buffer end) */
536
537 while (resource < resource_end) {
538
539 /* Sanity check the resource */
540
541 if (resource->type > ACPI_RESOURCE_TYPE_MAX) {
542 status = AE_AML_INVALID_RESOURCE_TYPE;
543 break;
544 }
545
546 /* Invoke the user function, abort on any error returned */
547
548 status = user_function(resource, context);
549 if (ACPI_FAILURE(status)) {
550 if (status == AE_CTRL_TERMINATE) {
551
552 /* This is an OK termination by the user function */
553
554 status = AE_OK;
555 }
556 break;
557 }
558
559 /* end_tag indicates end-of-list */
560
561 if (resource->type == ACPI_RESOURCE_TYPE_END_TAG) {
562 break;
563 }
564
565 /* Get the next resource descriptor */
566
567 resource =
568 ACPI_ADD_PTR(struct acpi_resource, resource,
569 resource->length);
570 }
571
572 ACPI_FREE(buffer.pointer);
573 return_ACPI_STATUS(status);
574}
575
576ACPI_EXPORT_SYMBOL(acpi_walk_resources)