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 */
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);
67 /*******************************************************************************
69 * FUNCTION: acpi_get_irq_routing_table
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
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.
82 * If the function fails an appropriate status will be returned
83 * and the value of ret_buffer is undefined.
85 * This function attempts to execute the _PRT method contained in
86 * the object indicated by the passed device_handle.
88 ******************************************************************************/
90 acpi_get_irq_routing_table(acpi_handle device_handle,
91 struct acpi_buffer *ret_buffer)
95 ACPI_FUNCTION_TRACE("acpi_get_irq_routing_table ");
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.
103 if (!device_handle) {
104 return_ACPI_STATUS(AE_BAD_PARAMETER);
107 status = acpi_ut_validate_buffer(ret_buffer);
108 if (ACPI_FAILURE(status)) {
109 return_ACPI_STATUS(status);
112 status = acpi_rs_get_prt_method_data(device_handle, ret_buffer);
113 return_ACPI_STATUS(status);
116 /*******************************************************************************
118 * FUNCTION: acpi_get_current_resources
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
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.
132 * If the function fails an appropriate status will be returned
133 * and the value of ret_buffer is undefined.
135 * This function attempts to execute the _CRS method contained in
136 * the object indicated by the passed device_handle.
138 ******************************************************************************/
141 acpi_get_current_resources(acpi_handle device_handle,
142 struct acpi_buffer *ret_buffer)
146 ACPI_FUNCTION_TRACE("acpi_get_current_resources");
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.
154 if (!device_handle) {
155 return_ACPI_STATUS(AE_BAD_PARAMETER);
158 status = acpi_ut_validate_buffer(ret_buffer);
159 if (ACPI_FAILURE(status)) {
160 return_ACPI_STATUS(status);
163 status = acpi_rs_get_crs_method_data(device_handle, ret_buffer);
164 return_ACPI_STATUS(status);
167 EXPORT_SYMBOL(acpi_get_current_resources);
169 /*******************************************************************************
171 * FUNCTION: acpi_get_possible_resources
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
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.
185 * If the function fails an appropriate status will be returned
186 * and the value of ret_buffer is undefined.
188 ******************************************************************************/
190 #ifdef ACPI_FUTURE_USAGE
192 acpi_get_possible_resources(acpi_handle device_handle,
193 struct acpi_buffer *ret_buffer)
197 ACPI_FUNCTION_TRACE("acpi_get_possible_resources");
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.
205 if (!device_handle) {
206 return_ACPI_STATUS(AE_BAD_PARAMETER);
209 status = acpi_ut_validate_buffer(ret_buffer);
210 if (ACPI_FAILURE(status)) {
211 return_ACPI_STATUS(status);
214 status = acpi_rs_get_prs_method_data(device_handle, ret_buffer);
215 return_ACPI_STATUS(status);
218 EXPORT_SYMBOL(acpi_get_possible_resources);
219 #endif /* ACPI_FUTURE_USAGE */
221 /*******************************************************************************
223 * FUNCTION: acpi_walk_resources
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
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.
238 ******************************************************************************/
241 acpi_walk_resources(acpi_handle device_handle,
243 ACPI_WALK_RESOURCE_CALLBACK user_function, void *context)
246 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
247 struct acpi_resource *resource;
248 struct acpi_resource *buffer_end;
250 ACPI_FUNCTION_TRACE("acpi_walk_resources");
252 if (!device_handle ||
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);
258 status = acpi_rs_get_method_data(device_handle, path, &buffer);
259 if (ACPI_FAILURE(status)) {
260 return_ACPI_STATUS(status);
265 resource = (struct acpi_resource *)buffer.pointer;
266 buffer_end = ACPI_CAST_PTR(struct acpi_resource,
267 ((u8 *) buffer.pointer + buffer.length));
269 /* Walk the resource list */
272 if (!resource || resource->id == ACPI_RSTYPE_END_TAG) {
276 status = user_function(resource, context);
282 /* Just keep going */
287 case AE_CTRL_TERMINATE:
289 /* Exit now, with OK stats */
296 /* All others are valid exceptions */
301 /* Get the next resource descriptor */
303 resource = ACPI_NEXT_RESOURCE(resource);
305 /* Check for end-of-buffer */
307 if (resource >= buffer_end) {
314 acpi_os_free(buffer.pointer);
315 return_ACPI_STATUS(status);
318 EXPORT_SYMBOL(acpi_walk_resources);
320 /*******************************************************************************
322 * FUNCTION: acpi_set_current_resources
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
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.
336 ******************************************************************************/
339 acpi_set_current_resources(acpi_handle device_handle,
340 struct acpi_buffer *in_buffer)
344 ACPI_FUNCTION_TRACE("acpi_set_current_resources");
346 /* Must have a valid handle and buffer */
348 if ((!device_handle) ||
349 (!in_buffer) || (!in_buffer->pointer) || (!in_buffer->length)) {
350 return_ACPI_STATUS(AE_BAD_PARAMETER);
353 status = acpi_rs_set_srs_method_data(device_handle, in_buffer);
354 return_ACPI_STATUS(status);
357 EXPORT_SYMBOL(acpi_set_current_resources);
359 /******************************************************************************
361 * FUNCTION: acpi_resource_to_address64
363 * PARAMETERS: resource - Pointer to a resource
364 * out - Pointer to the users's return
366 * struct acpi_resource_address64)
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
375 ******************************************************************************/
378 acpi_resource_to_address64(struct acpi_resource *resource,
379 struct acpi_resource_address64 *out)
381 struct acpi_resource_address16 *address16;
382 struct acpi_resource_address32 *address32;
384 switch (resource->id) {
385 case ACPI_RSTYPE_ADDRESS16:
387 address16 = (struct acpi_resource_address16 *)&resource->data;
388 ACPI_COPY_ADDRESS(out, address16);
391 case ACPI_RSTYPE_ADDRESS32:
393 address32 = (struct acpi_resource_address32 *)&resource->data;
394 ACPI_COPY_ADDRESS(out, address32);
397 case ACPI_RSTYPE_ADDRESS64:
399 /* Simple copy for 64 bit source */
401 ACPI_MEMCPY(out, &resource->data,
402 sizeof(struct acpi_resource_address64));
406 return (AE_BAD_PARAMETER);
412 EXPORT_SYMBOL(acpi_resource_to_address64);