]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/acpi/resources/rsxface.c
[ACPI] ACPICA 20050916
[mirror_ubuntu-artful-kernel.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/*
8 * Copyright (C) 2000 - 2005, R. Byron Moore
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); \
60 ACPI_COPY_FIELD(out, in, attribute); \
61 ACPI_COPY_FIELD(out, in, granularity); \
62 ACPI_COPY_FIELD(out, in, min_address_range); \
63 ACPI_COPY_FIELD(out, in, max_address_range); \
64 ACPI_COPY_FIELD(out, in, address_translation_offset); \
65 ACPI_COPY_FIELD(out, in, address_length); \
66 ACPI_COPY_FIELD(out, in, resource_source);
1da177e4
LT
67/*******************************************************************************
68 *
69 * FUNCTION: acpi_get_irq_routing_table
70 *
71 * PARAMETERS: device_handle - a handle to the Bus device we are querying
72 * ret_buffer - a pointer to a buffer to receive the
73 * current resources for the device
74 *
75 * RETURN: Status
76 *
77 * DESCRIPTION: This function is called to get the IRQ routing table for a
78 * specific bus. The caller must first acquire a handle for the
79 * desired bus. The routine table is placed in the buffer pointed
80 * to by the ret_buffer variable parameter.
81 *
82 * If the function fails an appropriate status will be returned
83 * and the value of ret_buffer is undefined.
84 *
85 * This function attempts to execute the _PRT method contained in
86 * the object indicated by the passed device_handle.
87 *
88 ******************************************************************************/
1da177e4 89acpi_status
4be44fcd
LB
90acpi_get_irq_routing_table(acpi_handle device_handle,
91 struct acpi_buffer *ret_buffer)
1da177e4 92{
4be44fcd 93 acpi_status status;
1da177e4 94
4be44fcd 95 ACPI_FUNCTION_TRACE("acpi_get_irq_routing_table ");
1da177e4
LT
96
97 /*
98 * Must have a valid handle and buffer, So we have to have a handle
99 * and a return buffer structure, and if there is a non-zero buffer length
100 * we also need a valid pointer in the buffer. If it's a zero buffer length,
101 * we'll be returning the needed buffer size, so keep going.
102 */
103 if (!device_handle) {
4be44fcd 104 return_ACPI_STATUS(AE_BAD_PARAMETER);
1da177e4
LT
105 }
106
4be44fcd
LB
107 status = acpi_ut_validate_buffer(ret_buffer);
108 if (ACPI_FAILURE(status)) {
109 return_ACPI_STATUS(status);
1da177e4
LT
110 }
111
4be44fcd
LB
112 status = acpi_rs_get_prt_method_data(device_handle, ret_buffer);
113 return_ACPI_STATUS(status);
1da177e4
LT
114}
115
1da177e4
LT
116/*******************************************************************************
117 *
118 * FUNCTION: acpi_get_current_resources
119 *
120 * PARAMETERS: device_handle - a handle to the device object for the
121 * device we are querying
122 * ret_buffer - a pointer to a buffer to receive the
123 * current resources for the device
124 *
125 * RETURN: Status
126 *
127 * DESCRIPTION: This function is called to get the current resources for a
128 * specific device. The caller must first acquire a handle for
129 * the desired device. The resource data is placed in the buffer
130 * pointed to by the ret_buffer variable parameter.
131 *
132 * If the function fails an appropriate status will be returned
133 * and the value of ret_buffer is undefined.
134 *
135 * This function attempts to execute the _CRS method contained in
136 * the object indicated by the passed device_handle.
137 *
138 ******************************************************************************/
139
140acpi_status
4be44fcd
LB
141acpi_get_current_resources(acpi_handle device_handle,
142 struct acpi_buffer *ret_buffer)
1da177e4 143{
4be44fcd 144 acpi_status status;
1da177e4 145
4be44fcd 146 ACPI_FUNCTION_TRACE("acpi_get_current_resources");
1da177e4
LT
147
148 /*
149 * Must have a valid handle and buffer, So we have to have a handle
150 * and a return buffer structure, and if there is a non-zero buffer length
151 * we also need a valid pointer in the buffer. If it's a zero buffer length,
152 * we'll be returning the needed buffer size, so keep going.
153 */
154 if (!device_handle) {
4be44fcd 155 return_ACPI_STATUS(AE_BAD_PARAMETER);
1da177e4
LT
156 }
157
4be44fcd
LB
158 status = acpi_ut_validate_buffer(ret_buffer);
159 if (ACPI_FAILURE(status)) {
160 return_ACPI_STATUS(status);
1da177e4
LT
161 }
162
4be44fcd
LB
163 status = acpi_rs_get_crs_method_data(device_handle, ret_buffer);
164 return_ACPI_STATUS(status);
1da177e4 165}
1da177e4 166
4be44fcd 167EXPORT_SYMBOL(acpi_get_current_resources);
1da177e4
LT
168
169/*******************************************************************************
170 *
171 * FUNCTION: acpi_get_possible_resources
172 *
173 * PARAMETERS: device_handle - a handle to the device object for the
174 * device we are querying
175 * ret_buffer - a pointer to a buffer to receive the
176 * resources for the device
177 *
178 * RETURN: Status
179 *
180 * DESCRIPTION: This function is called to get a list of the possible resources
181 * for a specific device. The caller must first acquire a handle
182 * for the desired device. The resource data is placed in the
183 * buffer pointed to by the ret_buffer variable.
184 *
185 * If the function fails an appropriate status will be returned
186 * and the value of ret_buffer is undefined.
187 *
188 ******************************************************************************/
44f6c012 189
1da177e4
LT
190#ifdef ACPI_FUTURE_USAGE
191acpi_status
4be44fcd
LB
192acpi_get_possible_resources(acpi_handle device_handle,
193 struct acpi_buffer *ret_buffer)
1da177e4 194{
4be44fcd 195 acpi_status status;
1da177e4 196
4be44fcd 197 ACPI_FUNCTION_TRACE("acpi_get_possible_resources");
1da177e4
LT
198
199 /*
200 * Must have a valid handle and buffer, So we have to have a handle
201 * and a return buffer structure, and if there is a non-zero buffer length
202 * we also need a valid pointer in the buffer. If it's a zero buffer length,
203 * we'll be returning the needed buffer size, so keep going.
204 */
205 if (!device_handle) {
4be44fcd 206 return_ACPI_STATUS(AE_BAD_PARAMETER);
1da177e4
LT
207 }
208
4be44fcd
LB
209 status = acpi_ut_validate_buffer(ret_buffer);
210 if (ACPI_FAILURE(status)) {
211 return_ACPI_STATUS(status);
1da177e4
LT
212 }
213
4be44fcd
LB
214 status = acpi_rs_get_prs_method_data(device_handle, ret_buffer);
215 return_ACPI_STATUS(status);
1da177e4 216}
1da177e4 217
4be44fcd
LB
218EXPORT_SYMBOL(acpi_get_possible_resources);
219#endif /* ACPI_FUTURE_USAGE */
1da177e4
LT
220
221/*******************************************************************************
222 *
223 * FUNCTION: acpi_walk_resources
224 *
225 * PARAMETERS: device_handle - a handle to the device object for the
226 * device we are querying
227 * Path - method name of the resources we want
228 * (METHOD_NAME__CRS or METHOD_NAME__PRS)
229 * user_function - called for each resource
230 * Context - passed to user_function
231 *
232 * RETURN: Status
233 *
234 * DESCRIPTION: Retrieves the current or possible resource list for the
235 * specified device. The user_function is called once for
236 * each resource in the list.
237 *
238 ******************************************************************************/
239
240acpi_status
4be44fcd
LB
241acpi_walk_resources(acpi_handle device_handle,
242 char *path,
243 ACPI_WALK_RESOURCE_CALLBACK user_function, void *context)
1da177e4 244{
4be44fcd
LB
245 acpi_status status;
246 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
247 struct acpi_resource *resource;
248 struct acpi_resource *buffer_end;
1da177e4 249
4be44fcd 250 ACPI_FUNCTION_TRACE("acpi_walk_resources");
1da177e4
LT
251
252 if (!device_handle ||
4be44fcd
LB
253 (ACPI_STRNCMP(path, METHOD_NAME__CRS, sizeof(METHOD_NAME__CRS)) &&
254 ACPI_STRNCMP(path, METHOD_NAME__PRS, sizeof(METHOD_NAME__PRS)))) {
255 return_ACPI_STATUS(AE_BAD_PARAMETER);
1da177e4
LT
256 }
257
4be44fcd
LB
258 status = acpi_rs_get_method_data(device_handle, path, &buffer);
259 if (ACPI_FAILURE(status)) {
260 return_ACPI_STATUS(status);
1da177e4
LT
261 }
262
263 /* Setup pointers */
264
4be44fcd
LB
265 resource = (struct acpi_resource *)buffer.pointer;
266 buffer_end = ACPI_CAST_PTR(struct acpi_resource,
267 ((u8 *) buffer.pointer + buffer.length));
1da177e4
LT
268
269 /* Walk the resource list */
270
271 for (;;) {
bda663d3 272 if (!resource || resource->type == ACPI_RSTYPE_END_TAG) {
1da177e4
LT
273 break;
274 }
275
4be44fcd 276 status = user_function(resource, context);
1da177e4
LT
277
278 switch (status) {
279 case AE_OK:
280 case AE_CTRL_DEPTH:
281
282 /* Just keep going */
283
284 status = AE_OK;
285 break;
286
287 case AE_CTRL_TERMINATE:
288
289 /* Exit now, with OK stats */
290
291 status = AE_OK;
292 goto cleanup;
293
294 default:
295
296 /* All others are valid exceptions */
297
298 goto cleanup;
299 }
300
301 /* Get the next resource descriptor */
302
4be44fcd 303 resource = ACPI_NEXT_RESOURCE(resource);
1da177e4
LT
304
305 /* Check for end-of-buffer */
306
307 if (resource >= buffer_end) {
308 goto cleanup;
309 }
310 }
311
4be44fcd 312 cleanup:
1da177e4 313
4be44fcd
LB
314 acpi_os_free(buffer.pointer);
315 return_ACPI_STATUS(status);
1da177e4 316}
1da177e4 317
4be44fcd 318EXPORT_SYMBOL(acpi_walk_resources);
1da177e4
LT
319
320/*******************************************************************************
321 *
322 * FUNCTION: acpi_set_current_resources
323 *
324 * PARAMETERS: device_handle - a handle to the device object for the
325 * device we are changing the resources of
326 * in_buffer - a pointer to a buffer containing the
327 * resources to be set for the device
328 *
329 * RETURN: Status
330 *
331 * DESCRIPTION: This function is called to set the current resources for a
332 * specific device. The caller must first acquire a handle for
333 * the desired device. The resource data is passed to the routine
334 * the buffer pointed to by the in_buffer variable.
335 *
336 ******************************************************************************/
337
338acpi_status
4be44fcd
LB
339acpi_set_current_resources(acpi_handle device_handle,
340 struct acpi_buffer *in_buffer)
1da177e4 341{
4be44fcd 342 acpi_status status;
1da177e4 343
4be44fcd 344 ACPI_FUNCTION_TRACE("acpi_set_current_resources");
1da177e4 345
44f6c012
RM
346 /* Must have a valid handle and buffer */
347
4be44fcd
LB
348 if ((!device_handle) ||
349 (!in_buffer) || (!in_buffer->pointer) || (!in_buffer->length)) {
350 return_ACPI_STATUS(AE_BAD_PARAMETER);
1da177e4
LT
351 }
352
4be44fcd
LB
353 status = acpi_rs_set_srs_method_data(device_handle, in_buffer);
354 return_ACPI_STATUS(status);
1da177e4 355}
1da177e4 356
4be44fcd 357EXPORT_SYMBOL(acpi_set_current_resources);
1da177e4 358
1da177e4
LT
359/******************************************************************************
360 *
361 * FUNCTION: acpi_resource_to_address64
362 *
bda663d3
RM
363 * PARAMETERS: Resource - Pointer to a resource
364 * Out - Pointer to the users's return
1da177e4
LT
365 * buffer (a struct
366 * struct acpi_resource_address64)
367 *
368 * RETURN: Status
369 *
370 * DESCRIPTION: If the resource is an address16, address32, or address64,
371 * copy it to the address64 return buffer. This saves the
372 * caller from having to duplicate code for different-sized
373 * addresses.
374 *
375 ******************************************************************************/
376
377acpi_status
4be44fcd
LB
378acpi_resource_to_address64(struct acpi_resource *resource,
379 struct acpi_resource_address64 *out)
1da177e4 380{
4be44fcd
LB
381 struct acpi_resource_address16 *address16;
382 struct acpi_resource_address32 *address32;
1da177e4 383
bda663d3 384 switch (resource->type) {
1da177e4
LT
385 case ACPI_RSTYPE_ADDRESS16:
386
4be44fcd
LB
387 address16 = (struct acpi_resource_address16 *)&resource->data;
388 ACPI_COPY_ADDRESS(out, address16);
1da177e4
LT
389 break;
390
1da177e4
LT
391 case ACPI_RSTYPE_ADDRESS32:
392
4be44fcd
LB
393 address32 = (struct acpi_resource_address32 *)&resource->data;
394 ACPI_COPY_ADDRESS(out, address32);
1da177e4
LT
395 break;
396
1da177e4
LT
397 case ACPI_RSTYPE_ADDRESS64:
398
399 /* Simple copy for 64 bit source */
400
4be44fcd
LB
401 ACPI_MEMCPY(out, &resource->data,
402 sizeof(struct acpi_resource_address64));
1da177e4
LT
403 break;
404
1da177e4
LT
405 default:
406 return (AE_BAD_PARAMETER);
407 }
408
409 return (AE_OK);
410}
4be44fcd 411
1da177e4 412EXPORT_SYMBOL(acpi_resource_to_address64);