blob: 1999e2ab7daad1971559302ae9e0e05b21c33e3e [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 Moore4a90c7e2006-01-13 16:22:00 -05008 * Copyright (C) 2000 - 2006, R. Byron Moore
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <acpi/acpi.h>
45#include <acpi/acresrc.h>
Bob Moore41195322006-05-26 16:36:00 -040046#include <acpi/acnamesp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
48#define _COMPONENT ACPI_RESOURCES
Len Brown4be44fc2005-08-05 00:44:28 -040049ACPI_MODULE_NAME("rsxface")
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
Robert Moore44f6c012005-04-18 22:49:35 -040051/* Local macros for 16,32-bit to 64-bit conversion */
Robert Moore44f6c012005-04-18 22:49:35 -040052#define ACPI_COPY_FIELD(out, in, field) ((out)->field = (in)->field)
53#define ACPI_COPY_ADDRESS(out, in) \
54 ACPI_COPY_FIELD(out, in, resource_type); \
55 ACPI_COPY_FIELD(out, in, producer_consumer); \
56 ACPI_COPY_FIELD(out, in, decode); \
57 ACPI_COPY_FIELD(out, in, min_address_fixed); \
58 ACPI_COPY_FIELD(out, in, max_address_fixed); \
Bob Moore08978312005-10-21 00:00:00 -040059 ACPI_COPY_FIELD(out, in, info); \
Robert Moore44f6c012005-04-18 22:49:35 -040060 ACPI_COPY_FIELD(out, in, granularity); \
Bob Moore50eca3e2005-09-30 19:03:00 -040061 ACPI_COPY_FIELD(out, in, minimum); \
62 ACPI_COPY_FIELD(out, in, maximum); \
63 ACPI_COPY_FIELD(out, in, translation_offset); \
Robert Moore44f6c012005-04-18 22:49:35 -040064 ACPI_COPY_FIELD(out, in, address_length); \
65 ACPI_COPY_FIELD(out, in, resource_source);
Bob Moorec51a4de2005-11-17 13:07:00 -050066/* Local prototypes */
67static acpi_status
68acpi_rs_match_vendor_resource(struct acpi_resource *resource, void *context);
69
Bob Moore41195322006-05-26 16:36:00 -040070static acpi_status
71acpi_rs_validate_parameters(acpi_handle device_handle,
72 struct acpi_buffer *buffer,
73 struct acpi_namespace_node **return_node);
74
75/*******************************************************************************
76 *
77 * FUNCTION: acpi_rs_validate_parameters
78 *
79 * PARAMETERS: device_handle - Handle to a device
80 * Buffer - Pointer to a data buffer
81 * return_node - Pointer to where the device node is returned
82 *
83 * RETURN: Status
84 *
85 * DESCRIPTION: Common parameter validation for resource interfaces
86 *
87 ******************************************************************************/
88
89static acpi_status
90acpi_rs_validate_parameters(acpi_handle device_handle,
91 struct acpi_buffer *buffer,
92 struct acpi_namespace_node **return_node)
93{
94 acpi_status status;
95 struct acpi_namespace_node *node;
96
97 ACPI_FUNCTION_TRACE(rs_validate_parameters);
98
99 /*
100 * Must have a valid handle to an ACPI device
101 */
102 if (!device_handle) {
103 return_ACPI_STATUS(AE_BAD_PARAMETER);
104 }
105
106 node = acpi_ns_map_handle_to_node(device_handle);
107 if (!node) {
108 return_ACPI_STATUS(AE_BAD_PARAMETER);
109 }
110
111 if (node->type != ACPI_TYPE_DEVICE) {
112 return_ACPI_STATUS(AE_TYPE);
113 }
114
115 /*
116 * Validate the user buffer object
117 *
118 * if there is a non-zero buffer length we also need a valid pointer in
119 * the buffer. If it's a zero buffer length, we'll be returning the
120 * needed buffer size (later), so keep going.
121 */
122 status = acpi_ut_validate_buffer(buffer);
123 if (ACPI_FAILURE(status)) {
124 return_ACPI_STATUS(status);
125 }
126
127 *return_node = node;
128 return_ACPI_STATUS(AE_OK);
129}
130
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131/*******************************************************************************
132 *
133 * FUNCTION: acpi_get_irq_routing_table
134 *
Bob Moore41195322006-05-26 16:36:00 -0400135 * PARAMETERS: device_handle - Handle to the Bus device we are querying
136 * ret_buffer - Pointer to a buffer to receive the
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 * current resources for the device
138 *
139 * RETURN: Status
140 *
141 * DESCRIPTION: This function is called to get the IRQ routing table for a
Bob Moore41195322006-05-26 16:36:00 -0400142 * specific bus. The caller must first acquire a handle for the
143 * desired bus. The routine table is placed in the buffer pointed
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 * to by the ret_buffer variable parameter.
145 *
146 * If the function fails an appropriate status will be returned
147 * and the value of ret_buffer is undefined.
148 *
149 * This function attempts to execute the _PRT method contained in
150 * the object indicated by the passed device_handle.
151 *
152 ******************************************************************************/
Bob Moorec51a4de2005-11-17 13:07:00 -0500153
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400155acpi_get_irq_routing_table(acpi_handle device_handle,
156 struct acpi_buffer *ret_buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157{
Len Brown4be44fc2005-08-05 00:44:28 -0400158 acpi_status status;
Bob Moore41195322006-05-26 16:36:00 -0400159 struct acpi_namespace_node *node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160
Bob Mooreb229cf92006-04-21 17:15:00 -0400161 ACPI_FUNCTION_TRACE(acpi_get_irq_routing_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
Bob Moore41195322006-05-26 16:36:00 -0400163 /* Validate parameters then dispatch to internal routine */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164
Bob Moore41195322006-05-26 16:36:00 -0400165 status = acpi_rs_validate_parameters(device_handle, ret_buffer, &node);
Len Brown4be44fc2005-08-05 00:44:28 -0400166 if (ACPI_FAILURE(status)) {
167 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 }
169
Bob Moore41195322006-05-26 16:36:00 -0400170 status = acpi_rs_get_prt_method_data(node, ret_buffer);
Len Brown4be44fc2005-08-05 00:44:28 -0400171 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172}
173
Bob Moore83135242006-10-03 00:00:00 -0400174ACPI_EXPORT_SYMBOL(acpi_get_irq_routing_table)
175
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176/*******************************************************************************
177 *
178 * FUNCTION: acpi_get_current_resources
179 *
Bob Moore41195322006-05-26 16:36:00 -0400180 * PARAMETERS: device_handle - Handle to the device object for the
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 * device we are querying
Bob Moore41195322006-05-26 16:36:00 -0400182 * ret_buffer - Pointer to a buffer to receive the
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 * current resources for the device
184 *
185 * RETURN: Status
186 *
187 * DESCRIPTION: This function is called to get the current resources for a
Bob Moore41195322006-05-26 16:36:00 -0400188 * specific device. The caller must first acquire a handle for
189 * the desired device. The resource data is placed in the buffer
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 * pointed to by the ret_buffer variable parameter.
191 *
192 * If the function fails an appropriate status will be returned
193 * and the value of ret_buffer is undefined.
194 *
195 * This function attempts to execute the _CRS method contained in
196 * the object indicated by the passed device_handle.
197 *
198 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400200acpi_get_current_resources(acpi_handle device_handle,
201 struct acpi_buffer *ret_buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202{
Len Brown4be44fc2005-08-05 00:44:28 -0400203 acpi_status status;
Bob Moore41195322006-05-26 16:36:00 -0400204 struct acpi_namespace_node *node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205
Bob Mooreb229cf92006-04-21 17:15:00 -0400206 ACPI_FUNCTION_TRACE(acpi_get_current_resources);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207
Bob Moore41195322006-05-26 16:36:00 -0400208 /* Validate parameters then dispatch to internal routine */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
Bob Moore41195322006-05-26 16:36:00 -0400210 status = acpi_rs_validate_parameters(device_handle, ret_buffer, &node);
Len Brown4be44fc2005-08-05 00:44:28 -0400211 if (ACPI_FAILURE(status)) {
212 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 }
214
Bob Moore41195322006-05-26 16:36:00 -0400215 status = acpi_rs_get_crs_method_data(node, ret_buffer);
Len Brown4be44fc2005-08-05 00:44:28 -0400216 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218
Bob Moore83135242006-10-03 00:00:00 -0400219ACPI_EXPORT_SYMBOL(acpi_get_current_resources)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
Bob Moore83135242006-10-03 00:00:00 -0400221#ifdef ACPI_FUTURE_USAGE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222/*******************************************************************************
223 *
224 * FUNCTION: acpi_get_possible_resources
225 *
Bob Moore41195322006-05-26 16:36:00 -0400226 * PARAMETERS: device_handle - Handle to the device object for the
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 * device we are querying
Bob Moore41195322006-05-26 16:36:00 -0400228 * ret_buffer - Pointer to a buffer to receive the
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 * resources for the device
230 *
231 * RETURN: Status
232 *
233 * DESCRIPTION: This function is called to get a list of the possible resources
Bob Moore41195322006-05-26 16:36:00 -0400234 * for a specific device. The caller must first acquire a handle
235 * for the desired device. The resource data is placed in the
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 * buffer pointed to by the ret_buffer variable.
237 *
238 * If the function fails an appropriate status will be returned
239 * and the value of ret_buffer is undefined.
240 *
241 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400243acpi_get_possible_resources(acpi_handle device_handle,
244 struct acpi_buffer *ret_buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245{
Len Brown4be44fc2005-08-05 00:44:28 -0400246 acpi_status status;
Bob Moore41195322006-05-26 16:36:00 -0400247 struct acpi_namespace_node *node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248
Bob Mooreb229cf92006-04-21 17:15:00 -0400249 ACPI_FUNCTION_TRACE(acpi_get_possible_resources);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250
Bob Moore41195322006-05-26 16:36:00 -0400251 /* Validate parameters then dispatch to internal routine */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252
Bob Moore41195322006-05-26 16:36:00 -0400253 status = acpi_rs_validate_parameters(device_handle, ret_buffer, &node);
Len Brown4be44fc2005-08-05 00:44:28 -0400254 if (ACPI_FAILURE(status)) {
255 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 }
257
Bob Moore41195322006-05-26 16:36:00 -0400258 status = acpi_rs_get_prs_method_data(node, ret_buffer);
Len Brown4be44fc2005-08-05 00:44:28 -0400259 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261
Bob Moore83135242006-10-03 00:00:00 -0400262ACPI_EXPORT_SYMBOL(acpi_get_possible_resources)
Len Brown4be44fc2005-08-05 00:44:28 -0400263#endif /* ACPI_FUTURE_USAGE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264
265/*******************************************************************************
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
Len Brown4be44fc2005-08-05 00:44:28 -0400342 address16 = (struct acpi_resource_address16 *)&resource->data;
343 ACPI_COPY_ADDRESS(out, address16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 break;
345
Bob Moore50eca3e2005-09-30 19:03:00 -0400346 case ACPI_RESOURCE_TYPE_ADDRESS32:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347
Len Brown4be44fc2005-08-05 00:44:28 -0400348 address32 = (struct acpi_resource_address32 *)&resource->data;
349 ACPI_COPY_ADDRESS(out, address32);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 break;
351
Bob Moore50eca3e2005-09-30 19:03:00 -0400352 case ACPI_RESOURCE_TYPE_ADDRESS64:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353
354 /* Simple copy for 64 bit source */
355
Len Brown4be44fc2005-08-05 00:44:28 -0400356 ACPI_MEMCPY(out, &resource->data,
357 sizeof(struct acpi_resource_address64));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 break;
359
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 default:
361 return (AE_BAD_PARAMETER);
362 }
363
364 return (AE_OK);
365}
Len Brown4be44fc2005-08-05 00:44:28 -0400366
Bob Moore83135242006-10-03 00:00:00 -0400367ACPI_EXPORT_SYMBOL(acpi_resource_to_address64)
Bob Moorec51a4de2005-11-17 13:07:00 -0500368
369/*******************************************************************************
370 *
371 * FUNCTION: acpi_get_vendor_resource
372 *
Bob Moore41195322006-05-26 16:36:00 -0400373 * PARAMETERS: device_handle - Handle for the parent device object
374 * Name - Method name for the parent resource
375 * (METHOD_NAME__CRS or METHOD_NAME__PRS)
376 * Uuid - Pointer to the UUID to be matched.
377 * includes both subtype and 16-byte UUID
378 * ret_buffer - Where the vendor resource is returned
Bob Moorec51a4de2005-11-17 13:07:00 -0500379 *
380 * RETURN: Status
381 *
382 * DESCRIPTION: Walk a resource template for the specified evice to find a
383 * vendor-defined resource that matches the supplied UUID and
384 * UUID subtype. Returns a struct acpi_resource of type Vendor.
385 *
386 ******************************************************************************/
Bob Moorec51a4de2005-11-17 13:07:00 -0500387acpi_status
388acpi_get_vendor_resource(acpi_handle device_handle,
389 char *name,
390 struct acpi_vendor_uuid * uuid,
391 struct acpi_buffer * ret_buffer)
392{
393 struct acpi_vendor_walk_info info;
394 acpi_status status;
395
396 /* Other parameters are validated by acpi_walk_resources */
397
398 if (!uuid || !ret_buffer) {
399 return (AE_BAD_PARAMETER);
400 }
401
402 info.uuid = uuid;
403 info.buffer = ret_buffer;
404 info.status = AE_NOT_EXIST;
405
406 /* Walk the _CRS or _PRS resource list for this device */
407
408 status =
409 acpi_walk_resources(device_handle, name,
410 acpi_rs_match_vendor_resource, &info);
411 if (ACPI_FAILURE(status)) {
412 return (status);
413 }
414
415 return (info.status);
416}
417
Bob Moore83135242006-10-03 00:00:00 -0400418ACPI_EXPORT_SYMBOL(acpi_get_vendor_resource)
419
Bob Moorec51a4de2005-11-17 13:07:00 -0500420/*******************************************************************************
421 *
422 * FUNCTION: acpi_rs_match_vendor_resource
423 *
Bob Moore616861242006-03-17 16:44:00 -0500424 * PARAMETERS: acpi_walk_resource_callback
Bob Moorec51a4de2005-11-17 13:07:00 -0500425 *
426 * RETURN: Status
427 *
428 * DESCRIPTION: Match a vendor resource via the ACPI 3.0 UUID
429 *
430 ******************************************************************************/
Bob Moorec51a4de2005-11-17 13:07:00 -0500431static acpi_status
432acpi_rs_match_vendor_resource(struct acpi_resource *resource, void *context)
433{
434 struct acpi_vendor_walk_info *info = context;
435 struct acpi_resource_vendor_typed *vendor;
436 struct acpi_buffer *buffer;
437 acpi_status status;
438
439 /* Ignore all descriptors except Vendor */
440
441 if (resource->type != ACPI_RESOURCE_TYPE_VENDOR) {
442 return (AE_OK);
443 }
444
445 vendor = &resource->data.vendor_typed;
446
447 /*
448 * For a valid match, these conditions must hold:
449 *
450 * 1) Length of descriptor data must be at least as long as a UUID struct
451 * 2) The UUID subtypes must match
452 * 3) The UUID data must match
453 */
454 if ((vendor->byte_length < (ACPI_UUID_LENGTH + 1)) ||
455 (vendor->uuid_subtype != info->uuid->subtype) ||
456 (ACPI_MEMCMP(vendor->uuid, info->uuid->data, ACPI_UUID_LENGTH))) {
457 return (AE_OK);
458 }
459
460 /* Validate/Allocate/Clear caller buffer */
461
462 buffer = info->buffer;
463 status = acpi_ut_initialize_buffer(buffer, resource->length);
464 if (ACPI_FAILURE(status)) {
465 return (status);
466 }
467
468 /* Found the correct resource, copy and return it */
469
470 ACPI_MEMCPY(buffer->pointer, resource, resource->length);
471 buffer->length = resource->length;
472
473 /* Found the desired descriptor, terminate resource walk */
474
475 info->status = AE_OK;
476 return (AE_CTRL_TERMINATE);
477}
Bob Moore83135242006-10-03 00:00:00 -0400478
479ACPI_EXPORT_SYMBOL(acpi_rs_match_vendor_resource)
Bob Moore41195322006-05-26 16:36:00 -0400480
481/*******************************************************************************
482 *
483 * FUNCTION: acpi_walk_resources
484 *
485 * PARAMETERS: device_handle - Handle to the device object for the
486 * device we are querying
487 * Name - Method name of the resources we want
488 * (METHOD_NAME__CRS or METHOD_NAME__PRS)
489 * user_function - Called for each resource
490 * Context - Passed to user_function
491 *
492 * RETURN: Status
493 *
494 * DESCRIPTION: Retrieves the current or possible resource list for the
495 * specified device. The user_function is called once for
496 * each resource in the list.
497 *
498 ******************************************************************************/
499
500acpi_status
501acpi_walk_resources(acpi_handle device_handle,
502 char *name,
503 acpi_walk_resource_callback user_function, void *context)
504{
505 acpi_status status;
506 struct acpi_buffer buffer;
507 struct acpi_resource *resource;
508 struct acpi_resource *resource_end;
509
510 ACPI_FUNCTION_TRACE(acpi_walk_resources);
511
512 /* Parameter validation */
513
514 if (!device_handle || !user_function || !name ||
515 (!ACPI_COMPARE_NAME(name, METHOD_NAME__CRS) &&
516 !ACPI_COMPARE_NAME(name, METHOD_NAME__PRS))) {
517 return_ACPI_STATUS(AE_BAD_PARAMETER);
518 }
519
520 /* Get the _CRS or _PRS resource list */
521
522 buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER;
523 status = acpi_rs_get_method_data(device_handle, name, &buffer);
524 if (ACPI_FAILURE(status)) {
525 return_ACPI_STATUS(status);
526 }
527
528 /* Buffer now contains the resource list */
529
530 resource = ACPI_CAST_PTR(struct acpi_resource, buffer.pointer);
531 resource_end =
532 ACPI_ADD_PTR(struct acpi_resource, buffer.pointer, buffer.length);
533
534 /* Walk the resource list until the end_tag is found (or buffer end) */
535
536 while (resource < resource_end) {
537
538 /* Sanity check the resource */
539
540 if (resource->type > ACPI_RESOURCE_TYPE_MAX) {
541 status = AE_AML_INVALID_RESOURCE_TYPE;
542 break;
543 }
544
545 /* Invoke the user function, abort on any error returned */
546
547 status = user_function(resource, context);
548 if (ACPI_FAILURE(status)) {
549 if (status == AE_CTRL_TERMINATE) {
550
551 /* This is an OK termination by the user function */
552
553 status = AE_OK;
554 }
555 break;
556 }
557
558 /* end_tag indicates end-of-list */
559
560 if (resource->type == ACPI_RESOURCE_TYPE_END_TAG) {
561 break;
562 }
563
564 /* Get the next resource descriptor */
565
566 resource =
567 ACPI_ADD_PTR(struct acpi_resource, resource,
568 resource->length);
569 }
570
571 ACPI_FREE(buffer.pointer);
572 return_ACPI_STATUS(status);
573}
574
575ACPI_EXPORT_SYMBOL(acpi_walk_resources)