ACPI: ACPICA 20060217
[deliverable/linux.git] / drivers / acpi / resources / rsxface.c
CommitLineData
1da177e4
LT
1/*******************************************************************************
2 *
3 * Module Name: rsxface - Public interfaces to the resource manager
4 *
5 ******************************************************************************/
6
7/*
4a90c7e8 8 * Copyright (C) 2000 - 2006, R. Byron Moore
1da177e4
LT
9 * 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
44#include <linux/module.h>
45
46#include <acpi/acpi.h>
47#include <acpi/acresrc.h>
48
49#define _COMPONENT ACPI_RESOURCES
4be44fcd 50ACPI_MODULE_NAME("rsxface")
1da177e4 51
44f6c012 52/* Local macros for 16,32-bit to 64-bit conversion */
44f6c012
RM
53#define ACPI_COPY_FIELD(out, in, field) ((out)->field = (in)->field)
54#define ACPI_COPY_ADDRESS(out, in) \
55 ACPI_COPY_FIELD(out, in, resource_type); \
56 ACPI_COPY_FIELD(out, in, producer_consumer); \
57 ACPI_COPY_FIELD(out, in, decode); \
58 ACPI_COPY_FIELD(out, in, min_address_fixed); \
59 ACPI_COPY_FIELD(out, in, max_address_fixed); \
0897831b 60 ACPI_COPY_FIELD(out, in, info); \
44f6c012 61 ACPI_COPY_FIELD(out, in, granularity); \
50eca3eb
BM
62 ACPI_COPY_FIELD(out, in, minimum); \
63 ACPI_COPY_FIELD(out, in, maximum); \
64 ACPI_COPY_FIELD(out, in, translation_offset); \
44f6c012
RM
65 ACPI_COPY_FIELD(out, in, address_length); \
66 ACPI_COPY_FIELD(out, in, resource_source);
c51a4de8
BM
67/* Local prototypes */
68static acpi_status
69acpi_rs_match_vendor_resource(struct acpi_resource *resource, void *context);
70
1da177e4
LT
71/*******************************************************************************
72 *
73 * FUNCTION: acpi_get_irq_routing_table
74 *
75 * PARAMETERS: device_handle - a handle to the Bus device we are querying
76 * ret_buffer - a pointer to a buffer to receive the
77 * current resources for the device
78 *
79 * RETURN: Status
80 *
81 * DESCRIPTION: This function is called to get the IRQ routing table for a
82 * specific bus. The caller must first acquire a handle for the
83 * desired bus. The routine table is placed in the buffer pointed
84 * to by the ret_buffer variable parameter.
85 *
86 * If the function fails an appropriate status will be returned
87 * and the value of ret_buffer is undefined.
88 *
89 * This function attempts to execute the _PRT method contained in
90 * the object indicated by the passed device_handle.
91 *
92 ******************************************************************************/
c51a4de8 93
1da177e4 94acpi_status
4be44fcd
LB
95acpi_get_irq_routing_table(acpi_handle device_handle,
96 struct acpi_buffer *ret_buffer)
1da177e4 97{
4be44fcd 98 acpi_status status;
1da177e4 99
4be44fcd 100 ACPI_FUNCTION_TRACE("acpi_get_irq_routing_table ");
1da177e4
LT
101
102 /*
103 * Must have a valid handle and buffer, So we have to have a handle
104 * and a return buffer structure, and if there is a non-zero buffer length
105 * we also need a valid pointer in the buffer. If it's a zero buffer length,
106 * we'll be returning the needed buffer size, so keep going.
107 */
108 if (!device_handle) {
4be44fcd 109 return_ACPI_STATUS(AE_BAD_PARAMETER);
1da177e4
LT
110 }
111
4be44fcd
LB
112 status = acpi_ut_validate_buffer(ret_buffer);
113 if (ACPI_FAILURE(status)) {
114 return_ACPI_STATUS(status);
1da177e4
LT
115 }
116
4be44fcd
LB
117 status = acpi_rs_get_prt_method_data(device_handle, ret_buffer);
118 return_ACPI_STATUS(status);
1da177e4
LT
119}
120
1da177e4
LT
121/*******************************************************************************
122 *
123 * FUNCTION: acpi_get_current_resources
124 *
125 * PARAMETERS: device_handle - a handle to the device object for the
126 * device we are querying
127 * ret_buffer - a pointer to a buffer to receive the
128 * current resources for the device
129 *
130 * RETURN: Status
131 *
132 * DESCRIPTION: This function is called to get the current resources for a
133 * specific device. The caller must first acquire a handle for
134 * the desired device. The resource data is placed in the buffer
135 * pointed to by the ret_buffer variable parameter.
136 *
137 * If the function fails an appropriate status will be returned
138 * and the value of ret_buffer is undefined.
139 *
140 * This function attempts to execute the _CRS method contained in
141 * the object indicated by the passed device_handle.
142 *
143 ******************************************************************************/
144
145acpi_status
4be44fcd
LB
146acpi_get_current_resources(acpi_handle device_handle,
147 struct acpi_buffer *ret_buffer)
1da177e4 148{
4be44fcd 149 acpi_status status;
1da177e4 150
4be44fcd 151 ACPI_FUNCTION_TRACE("acpi_get_current_resources");
1da177e4
LT
152
153 /*
154 * Must have a valid handle and buffer, So we have to have a handle
155 * and a return buffer structure, and if there is a non-zero buffer length
156 * we also need a valid pointer in the buffer. If it's a zero buffer length,
157 * we'll be returning the needed buffer size, so keep going.
158 */
159 if (!device_handle) {
4be44fcd 160 return_ACPI_STATUS(AE_BAD_PARAMETER);
1da177e4
LT
161 }
162
4be44fcd
LB
163 status = acpi_ut_validate_buffer(ret_buffer);
164 if (ACPI_FAILURE(status)) {
165 return_ACPI_STATUS(status);
1da177e4
LT
166 }
167
4be44fcd
LB
168 status = acpi_rs_get_crs_method_data(device_handle, ret_buffer);
169 return_ACPI_STATUS(status);
1da177e4 170}
1da177e4 171
4be44fcd 172EXPORT_SYMBOL(acpi_get_current_resources);
1da177e4
LT
173
174/*******************************************************************************
175 *
176 * FUNCTION: acpi_get_possible_resources
177 *
178 * PARAMETERS: device_handle - a handle to the device object for the
179 * device we are querying
180 * ret_buffer - a pointer to a buffer to receive the
181 * resources for the device
182 *
183 * RETURN: Status
184 *
185 * DESCRIPTION: This function is called to get a list of the possible resources
186 * for a specific device. The caller must first acquire a handle
187 * for the desired device. The resource data is placed in the
188 * buffer pointed to by the ret_buffer variable.
189 *
190 * If the function fails an appropriate status will be returned
191 * and the value of ret_buffer is undefined.
192 *
193 ******************************************************************************/
44f6c012 194
1da177e4
LT
195#ifdef ACPI_FUTURE_USAGE
196acpi_status
4be44fcd
LB
197acpi_get_possible_resources(acpi_handle device_handle,
198 struct acpi_buffer *ret_buffer)
1da177e4 199{
4be44fcd 200 acpi_status status;
1da177e4 201
4be44fcd 202 ACPI_FUNCTION_TRACE("acpi_get_possible_resources");
1da177e4
LT
203
204 /*
205 * Must have a valid handle and buffer, So we have to have a handle
206 * and a return buffer structure, and if there is a non-zero buffer length
207 * we also need a valid pointer in the buffer. If it's a zero buffer length,
208 * we'll be returning the needed buffer size, so keep going.
209 */
210 if (!device_handle) {
4be44fcd 211 return_ACPI_STATUS(AE_BAD_PARAMETER);
1da177e4
LT
212 }
213
4be44fcd
LB
214 status = acpi_ut_validate_buffer(ret_buffer);
215 if (ACPI_FAILURE(status)) {
216 return_ACPI_STATUS(status);
1da177e4
LT
217 }
218
4be44fcd
LB
219 status = acpi_rs_get_prs_method_data(device_handle, ret_buffer);
220 return_ACPI_STATUS(status);
1da177e4 221}
1da177e4 222
4be44fcd
LB
223EXPORT_SYMBOL(acpi_get_possible_resources);
224#endif /* ACPI_FUTURE_USAGE */
1da177e4
LT
225
226/*******************************************************************************
227 *
228 * FUNCTION: acpi_walk_resources
229 *
c51a4de8 230 * PARAMETERS: device_handle - Handle to the device object for the
1da177e4 231 * device we are querying
c51a4de8 232 * Name - Method name of the resources we want
1da177e4 233 * (METHOD_NAME__CRS or METHOD_NAME__PRS)
c51a4de8
BM
234 * user_function - Called for each resource
235 * Context - Passed to user_function
1da177e4
LT
236 *
237 * RETURN: Status
238 *
239 * DESCRIPTION: Retrieves the current or possible resource list for the
240 * specified device. The user_function is called once for
241 * each resource in the list.
242 *
243 ******************************************************************************/
244
245acpi_status
4be44fcd 246acpi_walk_resources(acpi_handle device_handle,
c51a4de8 247 char *name,
4be44fcd 248 ACPI_WALK_RESOURCE_CALLBACK user_function, void *context)
1da177e4 249{
4be44fcd 250 acpi_status status;
c51a4de8 251 struct acpi_buffer buffer;
4be44fcd 252 struct acpi_resource *resource;
c51a4de8 253 struct acpi_resource *resource_end;
1da177e4 254
4be44fcd 255 ACPI_FUNCTION_TRACE("acpi_walk_resources");
1da177e4 256
c51a4de8
BM
257 /* Parameter validation */
258
259 if (!device_handle || !user_function || !name ||
260 (ACPI_STRNCMP(name, METHOD_NAME__CRS, sizeof(METHOD_NAME__CRS)) &&
261 ACPI_STRNCMP(name, METHOD_NAME__PRS, sizeof(METHOD_NAME__PRS)))) {
4be44fcd 262 return_ACPI_STATUS(AE_BAD_PARAMETER);
1da177e4
LT
263 }
264
c51a4de8
BM
265 /* Get the _CRS or _PRS resource list */
266
267 buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER;
268 status = acpi_rs_get_method_data(device_handle, name, &buffer);
4be44fcd
LB
269 if (ACPI_FAILURE(status)) {
270 return_ACPI_STATUS(status);
1da177e4
LT
271 }
272
c51a4de8 273 /* Buffer now contains the resource list */
1da177e4 274
c51a4de8
BM
275 resource = ACPI_CAST_PTR(struct acpi_resource, buffer.pointer);
276 resource_end =
277 ACPI_ADD_PTR(struct acpi_resource, buffer.pointer, buffer.length);
1da177e4 278
c51a4de8 279 /* Walk the resource list until the end_tag is found (or buffer end) */
1da177e4 280
c51a4de8 281 while (resource < resource_end) {
52fc0b02 282
c51a4de8
BM
283 /* Sanity check the resource */
284
285 if (resource->type > ACPI_RESOURCE_TYPE_MAX) {
286 status = AE_AML_INVALID_RESOURCE_TYPE;
1da177e4
LT
287 break;
288 }
289
c51a4de8 290 /* Invoke the user function, abort on any error returned */
1da177e4 291
c51a4de8
BM
292 status = user_function(resource, context);
293 if (ACPI_FAILURE(status)) {
294 if (status == AE_CTRL_TERMINATE) {
52fc0b02 295
c51a4de8 296 /* This is an OK termination by the user function */
1da177e4 297
c51a4de8
BM
298 status = AE_OK;
299 }
1da177e4 300 break;
c51a4de8 301 }
1da177e4 302
2ae41174
LB
303 /* end_tag indicates end-of-list */
304
305 if (resource->type == ACPI_RESOURCE_TYPE_END_TAG) {
306 break;
307 }
308
1da177e4
LT
309 /* Get the next resource descriptor */
310
c51a4de8
BM
311 resource =
312 ACPI_ADD_PTR(struct acpi_resource, resource,
313 resource->length);
1da177e4
LT
314 }
315
c51a4de8 316 ACPI_MEM_FREE(buffer.pointer);
4be44fcd 317 return_ACPI_STATUS(status);
1da177e4 318}
1da177e4 319
4be44fcd 320EXPORT_SYMBOL(acpi_walk_resources);
1da177e4
LT
321
322/*******************************************************************************
323 *
324 * FUNCTION: acpi_set_current_resources
325 *
326 * PARAMETERS: device_handle - a handle to the device object for the
327 * device we are changing the resources of
328 * in_buffer - a pointer to a buffer containing the
329 * resources to be set for the device
330 *
331 * RETURN: Status
332 *
333 * DESCRIPTION: This function is called to set the current resources for a
334 * specific device. The caller must first acquire a handle for
335 * the desired device. The resource data is passed to the routine
336 * the buffer pointed to by the in_buffer variable.
337 *
338 ******************************************************************************/
339
340acpi_status
4be44fcd
LB
341acpi_set_current_resources(acpi_handle device_handle,
342 struct acpi_buffer *in_buffer)
1da177e4 343{
4be44fcd 344 acpi_status status;
1da177e4 345
4be44fcd 346 ACPI_FUNCTION_TRACE("acpi_set_current_resources");
1da177e4 347
44f6c012
RM
348 /* Must have a valid handle and buffer */
349
4be44fcd
LB
350 if ((!device_handle) ||
351 (!in_buffer) || (!in_buffer->pointer) || (!in_buffer->length)) {
352 return_ACPI_STATUS(AE_BAD_PARAMETER);
1da177e4
LT
353 }
354
4be44fcd
LB
355 status = acpi_rs_set_srs_method_data(device_handle, in_buffer);
356 return_ACPI_STATUS(status);
1da177e4 357}
1da177e4 358
4be44fcd 359EXPORT_SYMBOL(acpi_set_current_resources);
1da177e4 360
1da177e4
LT
361/******************************************************************************
362 *
363 * FUNCTION: acpi_resource_to_address64
364 *
bda663d3
RM
365 * PARAMETERS: Resource - Pointer to a resource
366 * Out - Pointer to the users's return
1da177e4
LT
367 * buffer (a struct
368 * struct acpi_resource_address64)
369 *
370 * RETURN: Status
371 *
372 * DESCRIPTION: If the resource is an address16, address32, or address64,
373 * copy it to the address64 return buffer. This saves the
374 * caller from having to duplicate code for different-sized
375 * addresses.
376 *
377 ******************************************************************************/
378
379acpi_status
4be44fcd
LB
380acpi_resource_to_address64(struct acpi_resource *resource,
381 struct acpi_resource_address64 *out)
1da177e4 382{
4be44fcd
LB
383 struct acpi_resource_address16 *address16;
384 struct acpi_resource_address32 *address32;
1da177e4 385
c51a4de8
BM
386 if (!resource || !out) {
387 return (AE_BAD_PARAMETER);
388 }
389
390 /* Convert 16 or 32 address descriptor to 64 */
391
bda663d3 392 switch (resource->type) {
50eca3eb 393 case ACPI_RESOURCE_TYPE_ADDRESS16:
1da177e4 394
4be44fcd
LB
395 address16 = (struct acpi_resource_address16 *)&resource->data;
396 ACPI_COPY_ADDRESS(out, address16);
1da177e4
LT
397 break;
398
50eca3eb 399 case ACPI_RESOURCE_TYPE_ADDRESS32:
1da177e4 400
4be44fcd
LB
401 address32 = (struct acpi_resource_address32 *)&resource->data;
402 ACPI_COPY_ADDRESS(out, address32);
1da177e4
LT
403 break;
404
50eca3eb 405 case ACPI_RESOURCE_TYPE_ADDRESS64:
1da177e4
LT
406
407 /* Simple copy for 64 bit source */
408
4be44fcd
LB
409 ACPI_MEMCPY(out, &resource->data,
410 sizeof(struct acpi_resource_address64));
1da177e4
LT
411 break;
412
1da177e4
LT
413 default:
414 return (AE_BAD_PARAMETER);
415 }
416
417 return (AE_OK);
418}
4be44fcd 419
1da177e4 420EXPORT_SYMBOL(acpi_resource_to_address64);
c51a4de8
BM
421
422/*******************************************************************************
423 *
424 * FUNCTION: acpi_get_vendor_resource
425 *
426 * PARAMETERS: device_handle - Handle for the parent device object
427 * Name - Method name for the parent resource
428 * (METHOD_NAME__CRS or METHOD_NAME__PRS)
429 * Uuid - Pointer to the UUID to be matched.
430 * includes both subtype and 16-byte UUID
431 * ret_buffer - Where the vendor resource is returned
432 *
433 * RETURN: Status
434 *
435 * DESCRIPTION: Walk a resource template for the specified evice to find a
436 * vendor-defined resource that matches the supplied UUID and
437 * UUID subtype. Returns a struct acpi_resource of type Vendor.
438 *
439 ******************************************************************************/
440
441acpi_status
442acpi_get_vendor_resource(acpi_handle device_handle,
443 char *name,
444 struct acpi_vendor_uuid * uuid,
445 struct acpi_buffer * ret_buffer)
446{
447 struct acpi_vendor_walk_info info;
448 acpi_status status;
449
450 /* Other parameters are validated by acpi_walk_resources */
451
452 if (!uuid || !ret_buffer) {
453 return (AE_BAD_PARAMETER);
454 }
455
456 info.uuid = uuid;
457 info.buffer = ret_buffer;
458 info.status = AE_NOT_EXIST;
459
460 /* Walk the _CRS or _PRS resource list for this device */
461
462 status =
463 acpi_walk_resources(device_handle, name,
464 acpi_rs_match_vendor_resource, &info);
465 if (ACPI_FAILURE(status)) {
466 return (status);
467 }
468
469 return (info.status);
470}
471
472/*******************************************************************************
473 *
474 * FUNCTION: acpi_rs_match_vendor_resource
475 *
476 * PARAMETERS: ACPI_WALK_RESOURCE_CALLBACK
477 *
478 * RETURN: Status
479 *
480 * DESCRIPTION: Match a vendor resource via the ACPI 3.0 UUID
481 *
482 ******************************************************************************/
483
484static acpi_status
485acpi_rs_match_vendor_resource(struct acpi_resource *resource, void *context)
486{
487 struct acpi_vendor_walk_info *info = context;
488 struct acpi_resource_vendor_typed *vendor;
489 struct acpi_buffer *buffer;
490 acpi_status status;
491
492 /* Ignore all descriptors except Vendor */
493
494 if (resource->type != ACPI_RESOURCE_TYPE_VENDOR) {
495 return (AE_OK);
496 }
497
498 vendor = &resource->data.vendor_typed;
499
500 /*
501 * For a valid match, these conditions must hold:
502 *
503 * 1) Length of descriptor data must be at least as long as a UUID struct
504 * 2) The UUID subtypes must match
505 * 3) The UUID data must match
506 */
507 if ((vendor->byte_length < (ACPI_UUID_LENGTH + 1)) ||
508 (vendor->uuid_subtype != info->uuid->subtype) ||
509 (ACPI_MEMCMP(vendor->uuid, info->uuid->data, ACPI_UUID_LENGTH))) {
510 return (AE_OK);
511 }
512
513 /* Validate/Allocate/Clear caller buffer */
514
515 buffer = info->buffer;
516 status = acpi_ut_initialize_buffer(buffer, resource->length);
517 if (ACPI_FAILURE(status)) {
518 return (status);
519 }
520
521 /* Found the correct resource, copy and return it */
522
523 ACPI_MEMCPY(buffer->pointer, resource, resource->length);
524 buffer->length = resource->length;
525
526 /* Found the desired descriptor, terminate resource walk */
527
528 info->status = AE_OK;
529 return (AE_CTRL_TERMINATE);
530}
This page took 0.133031 seconds and 5 git commands to generate.