1 /*******************************************************************************
3 * Module Name: rsxface - Public interfaces to the resource manager
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2004, 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.
45 #include <acpi/acpi.h>
46 #include <acpi/acresrc.h>
48 #define _COMPONENT ACPI_RESOURCES
49 ACPI_MODULE_NAME ("rsxface")
52 /*******************************************************************************
54 * FUNCTION: acpi_get_irq_routing_table
56 * PARAMETERS: device_handle - a handle to the Bus device we are querying
57 * ret_buffer - a pointer to a buffer to receive the
58 * current resources for the device
62 * DESCRIPTION: This function is called to get the IRQ routing table for a
63 * specific bus. The caller must first acquire a handle for the
64 * desired bus. The routine table is placed in the buffer pointed
65 * to by the ret_buffer variable parameter.
67 * If the function fails an appropriate status will be returned
68 * and the value of ret_buffer is undefined.
70 * This function attempts to execute the _PRT method contained in
71 * the object indicated by the passed device_handle.
73 ******************************************************************************/
76 acpi_get_irq_routing_table (
77 acpi_handle device_handle,
78 struct acpi_buffer *ret_buffer)
83 ACPI_FUNCTION_TRACE ("acpi_get_irq_routing_table ");
87 * Must have a valid handle and buffer, So we have to have a handle
88 * and a return buffer structure, and if there is a non-zero buffer length
89 * we also need a valid pointer in the buffer. If it's a zero buffer length,
90 * we'll be returning the needed buffer size, so keep going.
93 return_ACPI_STATUS (AE_BAD_PARAMETER);
96 status = acpi_ut_validate_buffer (ret_buffer);
97 if (ACPI_FAILURE (status)) {
98 return_ACPI_STATUS (status);
101 status = acpi_rs_get_prt_method_data (device_handle, ret_buffer);
102 return_ACPI_STATUS (status);
106 /*******************************************************************************
108 * FUNCTION: acpi_get_current_resources
110 * PARAMETERS: device_handle - a handle to the device object for the
111 * device we are querying
112 * ret_buffer - a pointer to a buffer to receive the
113 * current resources for the device
117 * DESCRIPTION: This function is called to get the current resources for a
118 * specific device. The caller must first acquire a handle for
119 * the desired device. The resource data is placed in the buffer
120 * pointed to by the ret_buffer variable parameter.
122 * If the function fails an appropriate status will be returned
123 * and the value of ret_buffer is undefined.
125 * This function attempts to execute the _CRS method contained in
126 * the object indicated by the passed device_handle.
128 ******************************************************************************/
131 acpi_get_current_resources (
132 acpi_handle device_handle,
133 struct acpi_buffer *ret_buffer)
138 ACPI_FUNCTION_TRACE ("acpi_get_current_resources");
142 * Must have a valid handle and buffer, So we have to have a handle
143 * and a return buffer structure, and if there is a non-zero buffer length
144 * we also need a valid pointer in the buffer. If it's a zero buffer length,
145 * we'll be returning the needed buffer size, so keep going.
147 if (!device_handle) {
148 return_ACPI_STATUS (AE_BAD_PARAMETER);
151 status = acpi_ut_validate_buffer (ret_buffer);
152 if (ACPI_FAILURE (status)) {
153 return_ACPI_STATUS (status);
156 status = acpi_rs_get_crs_method_data (device_handle, ret_buffer);
157 return_ACPI_STATUS (status);
161 /*******************************************************************************
163 * FUNCTION: acpi_get_possible_resources
165 * PARAMETERS: device_handle - a handle to the device object for the
166 * device we are querying
167 * ret_buffer - a pointer to a buffer to receive the
168 * resources for the device
172 * DESCRIPTION: This function is called to get a list of the possible resources
173 * for a specific device. The caller must first acquire a handle
174 * for the desired device. The resource data is placed in the
175 * buffer pointed to by the ret_buffer variable.
177 * If the function fails an appropriate status will be returned
178 * and the value of ret_buffer is undefined.
180 ******************************************************************************/
183 acpi_get_possible_resources (
184 acpi_handle device_handle,
185 struct acpi_buffer *ret_buffer)
190 ACPI_FUNCTION_TRACE ("acpi_get_possible_resources");
194 * Must have a valid handle and buffer, So we have to have a handle
195 * and a return buffer structure, and if there is a non-zero buffer length
196 * we also need a valid pointer in the buffer. If it's a zero buffer length,
197 * we'll be returning the needed buffer size, so keep going.
199 if (!device_handle) {
200 return_ACPI_STATUS (AE_BAD_PARAMETER);
203 status = acpi_ut_validate_buffer (ret_buffer);
204 if (ACPI_FAILURE (status)) {
205 return_ACPI_STATUS (status);
208 status = acpi_rs_get_prs_method_data (device_handle, ret_buffer);
209 return_ACPI_STATUS (status);
213 /*******************************************************************************
215 * FUNCTION: acpi_walk_resources
217 * PARAMETERS: device_handle - a handle to the device object for the
218 * device we are querying
219 * Path - method name of the resources we want
220 * (METHOD_NAME__CRS or METHOD_NAME__PRS)
221 * user_function - called for each resource
222 * Context - passed to user_function
226 * DESCRIPTION: Retrieves the current or possible resource list for the
227 * specified device. The user_function is called once for
228 * each resource in the list.
230 ******************************************************************************/
233 acpi_walk_resources (
234 acpi_handle device_handle,
236 ACPI_WALK_RESOURCE_CALLBACK user_function,
240 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
241 struct acpi_resource *resource;
242 struct acpi_resource *buffer_end;
245 ACPI_FUNCTION_TRACE ("acpi_walk_resources");
248 if (!device_handle ||
249 (ACPI_STRNCMP (path, METHOD_NAME__CRS, sizeof (METHOD_NAME__CRS)) &&
250 ACPI_STRNCMP (path, METHOD_NAME__PRS, sizeof (METHOD_NAME__PRS)))) {
251 return_ACPI_STATUS (AE_BAD_PARAMETER);
254 status = acpi_rs_get_method_data (device_handle, path, &buffer);
255 if (ACPI_FAILURE (status)) {
256 return_ACPI_STATUS (status);
261 resource = (struct acpi_resource *) buffer.pointer;
262 buffer_end = ACPI_CAST_PTR (struct acpi_resource,
263 ((u8 *) buffer.pointer + buffer.length));
265 /* Walk the resource list */
268 if (!resource || resource->id == ACPI_RSTYPE_END_TAG) {
272 status = user_function (resource, context);
278 /* Just keep going */
283 case AE_CTRL_TERMINATE:
285 /* Exit now, with OK stats */
292 /* All others are valid exceptions */
297 /* Get the next resource descriptor */
299 resource = ACPI_NEXT_RESOURCE (resource);
301 /* Check for end-of-buffer */
303 if (resource >= buffer_end) {
310 acpi_os_free (buffer.pointer);
311 return_ACPI_STATUS (status);
315 /*******************************************************************************
317 * FUNCTION: acpi_set_current_resources
319 * PARAMETERS: device_handle - a handle to the device object for the
320 * device we are changing the resources of
321 * in_buffer - a pointer to a buffer containing the
322 * resources to be set for the device
326 * DESCRIPTION: This function is called to set the current resources for a
327 * specific device. The caller must first acquire a handle for
328 * the desired device. The resource data is passed to the routine
329 * the buffer pointed to by the in_buffer variable.
331 ******************************************************************************/
334 acpi_set_current_resources (
335 acpi_handle device_handle,
336 struct acpi_buffer *in_buffer)
341 ACPI_FUNCTION_TRACE ("acpi_set_current_resources");
345 * Must have a valid handle and buffer
347 if ((!device_handle) ||
349 (!in_buffer->pointer) ||
350 (!in_buffer->length)) {
351 return_ACPI_STATUS (AE_BAD_PARAMETER);
354 status = acpi_rs_set_srs_method_data (device_handle, in_buffer);
355 return_ACPI_STATUS (status);
359 #define ACPI_COPY_FIELD(out, in, field) ((out)->field = (in)->field)
360 #define ACPI_COPY_ADDRESS(out, in) \
361 ACPI_COPY_FIELD(out, in, resource_type); \
362 ACPI_COPY_FIELD(out, in, producer_consumer); \
363 ACPI_COPY_FIELD(out, in, decode); \
364 ACPI_COPY_FIELD(out, in, min_address_fixed); \
365 ACPI_COPY_FIELD(out, in, max_address_fixed); \
366 ACPI_COPY_FIELD(out, in, attribute); \
367 ACPI_COPY_FIELD(out, in, granularity); \
368 ACPI_COPY_FIELD(out, in, min_address_range); \
369 ACPI_COPY_FIELD(out, in, max_address_range); \
370 ACPI_COPY_FIELD(out, in, address_translation_offset); \
371 ACPI_COPY_FIELD(out, in, address_length); \
372 ACPI_COPY_FIELD(out, in, resource_source);
374 /******************************************************************************
376 * FUNCTION: acpi_resource_to_address64
378 * PARAMETERS: resource - Pointer to a resource
379 * out - Pointer to the users's return
381 * struct acpi_resource_address64)
385 * DESCRIPTION: If the resource is an address16, address32, or address64,
386 * copy it to the address64 return buffer. This saves the
387 * caller from having to duplicate code for different-sized
390 ******************************************************************************/
393 acpi_resource_to_address64 (
394 struct acpi_resource *resource,
395 struct acpi_resource_address64 *out)
397 struct acpi_resource_address16 *address16;
398 struct acpi_resource_address32 *address32;
401 switch (resource->id) {
402 case ACPI_RSTYPE_ADDRESS16:
404 address16 = (struct acpi_resource_address16 *) &resource->data;
405 ACPI_COPY_ADDRESS(out, address16);
409 case ACPI_RSTYPE_ADDRESS32:
411 address32 = (struct acpi_resource_address32 *) &resource->data;
412 ACPI_COPY_ADDRESS(out, address32);
416 case ACPI_RSTYPE_ADDRESS64:
418 /* Simple copy for 64 bit source */
420 ACPI_MEMCPY (out, &resource->data, sizeof (struct acpi_resource_address64));
425 return (AE_BAD_PARAMETER);