1 /*******************************************************************************
3 * Module Name: rsxface - Public interfaces to the resource manager
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2005, R. Byron Moore
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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.
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.
44 #include <linux/module.h>
46 #include <acpi/acpi.h>
47 #include <acpi/acresrc.h>
49 #define _COMPONENT ACPI_RESOURCES
50 ACPI_MODULE_NAME ("rsxface")
52 /* Local macros for 16,32-bit to 64-bit conversion */
54 #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); \
61 ACPI_COPY_FIELD(out, in, attribute); \
62 ACPI_COPY_FIELD(out, in, granularity); \
63 ACPI_COPY_FIELD(out, in, min_address_range); \
64 ACPI_COPY_FIELD(out, in, max_address_range); \
65 ACPI_COPY_FIELD(out, in, address_translation_offset); \
66 ACPI_COPY_FIELD(out, in, address_length); \
67 ACPI_COPY_FIELD(out, in, resource_source);
70 /*******************************************************************************
72 * FUNCTION: acpi_get_irq_routing_table
74 * PARAMETERS: device_handle - a handle to the Bus device we are querying
75 * ret_buffer - a pointer to a buffer to receive the
76 * current resources for the device
80 * DESCRIPTION: This function is called to get the IRQ routing table for a
81 * specific bus. The caller must first acquire a handle for the
82 * desired bus. The routine table is placed in the buffer pointed
83 * to by the ret_buffer variable parameter.
85 * If the function fails an appropriate status will be returned
86 * and the value of ret_buffer is undefined.
88 * This function attempts to execute the _PRT method contained in
89 * the object indicated by the passed device_handle.
91 ******************************************************************************/
94 acpi_get_irq_routing_table (
95 acpi_handle device_handle,
96 struct acpi_buffer *ret_buffer)
101 ACPI_FUNCTION_TRACE ("acpi_get_irq_routing_table ");
105 * Must have a valid handle and buffer, So we have to have a handle
106 * and a return buffer structure, and if there is a non-zero buffer length
107 * we also need a valid pointer in the buffer. If it's a zero buffer length,
108 * we'll be returning the needed buffer size, so keep going.
110 if (!device_handle) {
111 return_ACPI_STATUS (AE_BAD_PARAMETER);
114 status = acpi_ut_validate_buffer (ret_buffer);
115 if (ACPI_FAILURE (status)) {
116 return_ACPI_STATUS (status);
119 status = acpi_rs_get_prt_method_data (device_handle, ret_buffer);
120 return_ACPI_STATUS (status);
124 /*******************************************************************************
126 * FUNCTION: acpi_get_current_resources
128 * PARAMETERS: device_handle - a handle to the device object for the
129 * device we are querying
130 * ret_buffer - a pointer to a buffer to receive the
131 * current resources for the device
135 * DESCRIPTION: This function is called to get the current resources for a
136 * specific device. The caller must first acquire a handle for
137 * the desired device. The resource data is placed in the buffer
138 * pointed to by the ret_buffer variable parameter.
140 * If the function fails an appropriate status will be returned
141 * and the value of ret_buffer is undefined.
143 * This function attempts to execute the _CRS method contained in
144 * the object indicated by the passed device_handle.
146 ******************************************************************************/
149 acpi_get_current_resources (
150 acpi_handle device_handle,
151 struct acpi_buffer *ret_buffer)
156 ACPI_FUNCTION_TRACE ("acpi_get_current_resources");
160 * Must have a valid handle and buffer, So we have to have a handle
161 * and a return buffer structure, and if there is a non-zero buffer length
162 * we also need a valid pointer in the buffer. If it's a zero buffer length,
163 * we'll be returning the needed buffer size, so keep going.
165 if (!device_handle) {
166 return_ACPI_STATUS (AE_BAD_PARAMETER);
169 status = acpi_ut_validate_buffer (ret_buffer);
170 if (ACPI_FAILURE (status)) {
171 return_ACPI_STATUS (status);
174 status = acpi_rs_get_crs_method_data (device_handle, ret_buffer);
175 return_ACPI_STATUS (status);
177 EXPORT_SYMBOL(acpi_get_current_resources);
180 /*******************************************************************************
182 * FUNCTION: acpi_get_possible_resources
184 * PARAMETERS: device_handle - a handle to the device object for the
185 * device we are querying
186 * ret_buffer - a pointer to a buffer to receive the
187 * resources for the device
191 * DESCRIPTION: This function is called to get a list of the possible resources
192 * for a specific device. The caller must first acquire a handle
193 * for the desired device. The resource data is placed in the
194 * buffer pointed to by the ret_buffer variable.
196 * If the function fails an appropriate status will be returned
197 * and the value of ret_buffer is undefined.
199 ******************************************************************************/
201 #ifdef ACPI_FUTURE_USAGE
203 acpi_get_possible_resources (
204 acpi_handle device_handle,
205 struct acpi_buffer *ret_buffer)
210 ACPI_FUNCTION_TRACE ("acpi_get_possible_resources");
214 * Must have a valid handle and buffer, So we have to have a handle
215 * and a return buffer structure, and if there is a non-zero buffer length
216 * we also need a valid pointer in the buffer. If it's a zero buffer length,
217 * we'll be returning the needed buffer size, so keep going.
219 if (!device_handle) {
220 return_ACPI_STATUS (AE_BAD_PARAMETER);
223 status = acpi_ut_validate_buffer (ret_buffer);
224 if (ACPI_FAILURE (status)) {
225 return_ACPI_STATUS (status);
228 status = acpi_rs_get_prs_method_data (device_handle, ret_buffer);
229 return_ACPI_STATUS (status);
231 EXPORT_SYMBOL(acpi_get_possible_resources);
232 #endif /* ACPI_FUTURE_USAGE */
235 /*******************************************************************************
237 * FUNCTION: acpi_walk_resources
239 * PARAMETERS: device_handle - a handle to the device object for the
240 * device we are querying
241 * Path - method name of the resources we want
242 * (METHOD_NAME__CRS or METHOD_NAME__PRS)
243 * user_function - called for each resource
244 * Context - passed to user_function
248 * DESCRIPTION: Retrieves the current or possible resource list for the
249 * specified device. The user_function is called once for
250 * each resource in the list.
252 ******************************************************************************/
255 acpi_walk_resources (
256 acpi_handle device_handle,
258 ACPI_WALK_RESOURCE_CALLBACK user_function,
262 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
263 struct acpi_resource *resource;
264 struct acpi_resource *buffer_end;
267 ACPI_FUNCTION_TRACE ("acpi_walk_resources");
270 if (!device_handle ||
271 (ACPI_STRNCMP (path, METHOD_NAME__CRS, sizeof (METHOD_NAME__CRS)) &&
272 ACPI_STRNCMP (path, METHOD_NAME__PRS, sizeof (METHOD_NAME__PRS)))) {
273 return_ACPI_STATUS (AE_BAD_PARAMETER);
276 status = acpi_rs_get_method_data (device_handle, path, &buffer);
277 if (ACPI_FAILURE (status)) {
278 return_ACPI_STATUS (status);
283 resource = (struct acpi_resource *) buffer.pointer;
284 buffer_end = ACPI_CAST_PTR (struct acpi_resource,
285 ((u8 *) buffer.pointer + buffer.length));
287 /* Walk the resource list */
290 if (!resource || resource->id == ACPI_RSTYPE_END_TAG) {
294 status = user_function (resource, context);
300 /* Just keep going */
305 case AE_CTRL_TERMINATE:
307 /* Exit now, with OK stats */
314 /* All others are valid exceptions */
319 /* Get the next resource descriptor */
321 resource = ACPI_NEXT_RESOURCE (resource);
323 /* Check for end-of-buffer */
325 if (resource >= buffer_end) {
332 acpi_os_free (buffer.pointer);
333 return_ACPI_STATUS (status);
335 EXPORT_SYMBOL(acpi_walk_resources);
338 /*******************************************************************************
340 * FUNCTION: acpi_set_current_resources
342 * PARAMETERS: device_handle - a handle to the device object for the
343 * device we are changing the resources of
344 * in_buffer - a pointer to a buffer containing the
345 * resources to be set for the device
349 * DESCRIPTION: This function is called to set the current resources for a
350 * specific device. The caller must first acquire a handle for
351 * the desired device. The resource data is passed to the routine
352 * the buffer pointed to by the in_buffer variable.
354 ******************************************************************************/
357 acpi_set_current_resources (
358 acpi_handle device_handle,
359 struct acpi_buffer *in_buffer)
364 ACPI_FUNCTION_TRACE ("acpi_set_current_resources");
367 /* Must have a valid handle and buffer */
369 if ((!device_handle) ||
371 (!in_buffer->pointer) ||
372 (!in_buffer->length)) {
373 return_ACPI_STATUS (AE_BAD_PARAMETER);
376 status = acpi_rs_set_srs_method_data (device_handle, in_buffer);
377 return_ACPI_STATUS (status);
379 EXPORT_SYMBOL(acpi_set_current_resources);
382 /******************************************************************************
384 * FUNCTION: acpi_resource_to_address64
386 * PARAMETERS: resource - Pointer to a resource
387 * out - Pointer to the users's return
389 * struct acpi_resource_address64)
393 * DESCRIPTION: If the resource is an address16, address32, or address64,
394 * copy it to the address64 return buffer. This saves the
395 * caller from having to duplicate code for different-sized
398 ******************************************************************************/
401 acpi_resource_to_address64 (
402 struct acpi_resource *resource,
403 struct acpi_resource_address64 *out)
405 struct acpi_resource_address16 *address16;
406 struct acpi_resource_address32 *address32;
409 switch (resource->id) {
410 case ACPI_RSTYPE_ADDRESS16:
412 address16 = (struct acpi_resource_address16 *) &resource->data;
413 ACPI_COPY_ADDRESS (out, address16);
417 case ACPI_RSTYPE_ADDRESS32:
419 address32 = (struct acpi_resource_address32 *) &resource->data;
420 ACPI_COPY_ADDRESS (out, address32);
424 case ACPI_RSTYPE_ADDRESS64:
426 /* Simple copy for 64 bit source */
428 ACPI_MEMCPY (out, &resource->data, sizeof (struct acpi_resource_address64));
433 return (AE_BAD_PARAMETER);
438 EXPORT_SYMBOL(acpi_resource_to_address64);