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")
53 /*******************************************************************************
55 * FUNCTION: acpi_get_irq_routing_table
57 * PARAMETERS: device_handle - a handle to the Bus device we are querying
58 * ret_buffer - a pointer to a buffer to receive the
59 * current resources for the device
63 * DESCRIPTION: This function is called to get the IRQ routing table for a
64 * specific bus. The caller must first acquire a handle for the
65 * desired bus. The routine table is placed in the buffer pointed
66 * to by the ret_buffer variable parameter.
68 * If the function fails an appropriate status will be returned
69 * and the value of ret_buffer is undefined.
71 * This function attempts to execute the _PRT method contained in
72 * the object indicated by the passed device_handle.
74 ******************************************************************************/
77 acpi_get_irq_routing_table (
78 acpi_handle device_handle
,
79 struct acpi_buffer
*ret_buffer
)
84 ACPI_FUNCTION_TRACE ("acpi_get_irq_routing_table ");
88 * Must have a valid handle and buffer, So we have to have a handle
89 * and a return buffer structure, and if there is a non-zero buffer length
90 * we also need a valid pointer in the buffer. If it's a zero buffer length,
91 * we'll be returning the needed buffer size, so keep going.
94 return_ACPI_STATUS (AE_BAD_PARAMETER
);
97 status
= acpi_ut_validate_buffer (ret_buffer
);
98 if (ACPI_FAILURE (status
)) {
99 return_ACPI_STATUS (status
);
102 status
= acpi_rs_get_prt_method_data (device_handle
, ret_buffer
);
103 return_ACPI_STATUS (status
);
107 /*******************************************************************************
109 * FUNCTION: acpi_get_current_resources
111 * PARAMETERS: device_handle - a handle to the device object for the
112 * device we are querying
113 * ret_buffer - a pointer to a buffer to receive the
114 * current resources for the device
118 * DESCRIPTION: This function is called to get the current resources for a
119 * specific device. The caller must first acquire a handle for
120 * the desired device. The resource data is placed in the buffer
121 * pointed to by the ret_buffer variable parameter.
123 * If the function fails an appropriate status will be returned
124 * and the value of ret_buffer is undefined.
126 * This function attempts to execute the _CRS method contained in
127 * the object indicated by the passed device_handle.
129 ******************************************************************************/
132 acpi_get_current_resources (
133 acpi_handle device_handle
,
134 struct acpi_buffer
*ret_buffer
)
139 ACPI_FUNCTION_TRACE ("acpi_get_current_resources");
143 * Must have a valid handle and buffer, So we have to have a handle
144 * and a return buffer structure, and if there is a non-zero buffer length
145 * we also need a valid pointer in the buffer. If it's a zero buffer length,
146 * we'll be returning the needed buffer size, so keep going.
148 if (!device_handle
) {
149 return_ACPI_STATUS (AE_BAD_PARAMETER
);
152 status
= acpi_ut_validate_buffer (ret_buffer
);
153 if (ACPI_FAILURE (status
)) {
154 return_ACPI_STATUS (status
);
157 status
= acpi_rs_get_crs_method_data (device_handle
, ret_buffer
);
158 return_ACPI_STATUS (status
);
160 EXPORT_SYMBOL(acpi_get_current_resources
);
163 /*******************************************************************************
165 * FUNCTION: acpi_get_possible_resources
167 * PARAMETERS: device_handle - a handle to the device object for the
168 * device we are querying
169 * ret_buffer - a pointer to a buffer to receive the
170 * resources for the device
174 * DESCRIPTION: This function is called to get a list of the possible resources
175 * for a specific device. The caller must first acquire a handle
176 * for the desired device. The resource data is placed in the
177 * buffer pointed to by the ret_buffer variable.
179 * If the function fails an appropriate status will be returned
180 * and the value of ret_buffer is undefined.
182 ******************************************************************************/
183 #ifdef ACPI_FUTURE_USAGE
185 acpi_get_possible_resources (
186 acpi_handle device_handle
,
187 struct acpi_buffer
*ret_buffer
)
192 ACPI_FUNCTION_TRACE ("acpi_get_possible_resources");
196 * Must have a valid handle and buffer, So we have to have a handle
197 * and a return buffer structure, and if there is a non-zero buffer length
198 * we also need a valid pointer in the buffer. If it's a zero buffer length,
199 * we'll be returning the needed buffer size, so keep going.
201 if (!device_handle
) {
202 return_ACPI_STATUS (AE_BAD_PARAMETER
);
205 status
= acpi_ut_validate_buffer (ret_buffer
);
206 if (ACPI_FAILURE (status
)) {
207 return_ACPI_STATUS (status
);
210 status
= acpi_rs_get_prs_method_data (device_handle
, ret_buffer
);
211 return_ACPI_STATUS (status
);
213 EXPORT_SYMBOL(acpi_get_possible_resources
);
214 #endif /* ACPI_FUTURE_USAGE */
217 /*******************************************************************************
219 * FUNCTION: acpi_walk_resources
221 * PARAMETERS: device_handle - a handle to the device object for the
222 * device we are querying
223 * Path - method name of the resources we want
224 * (METHOD_NAME__CRS or METHOD_NAME__PRS)
225 * user_function - called for each resource
226 * Context - passed to user_function
230 * DESCRIPTION: Retrieves the current or possible resource list for the
231 * specified device. The user_function is called once for
232 * each resource in the list.
234 ******************************************************************************/
237 acpi_walk_resources (
238 acpi_handle device_handle
,
240 ACPI_WALK_RESOURCE_CALLBACK user_function
,
244 struct acpi_buffer buffer
= {ACPI_ALLOCATE_BUFFER
, NULL
};
245 struct acpi_resource
*resource
;
246 struct acpi_resource
*buffer_end
;
249 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
);
317 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 (
340 acpi_handle device_handle
,
341 struct acpi_buffer
*in_buffer
)
346 ACPI_FUNCTION_TRACE ("acpi_set_current_resources");
350 * Must have a valid handle and buffer
352 if ((!device_handle
) ||
354 (!in_buffer
->pointer
) ||
355 (!in_buffer
->length
)) {
356 return_ACPI_STATUS (AE_BAD_PARAMETER
);
359 status
= acpi_rs_set_srs_method_data (device_handle
, in_buffer
);
360 return_ACPI_STATUS (status
);
362 EXPORT_SYMBOL(acpi_set_current_resources
);
365 #define ACPI_COPY_FIELD(out, in, field) ((out)->field = (in)->field)
366 #define ACPI_COPY_ADDRESS(out, in) \
367 ACPI_COPY_FIELD(out, in, resource_type); \
368 ACPI_COPY_FIELD(out, in, producer_consumer); \
369 ACPI_COPY_FIELD(out, in, decode); \
370 ACPI_COPY_FIELD(out, in, min_address_fixed); \
371 ACPI_COPY_FIELD(out, in, max_address_fixed); \
372 ACPI_COPY_FIELD(out, in, attribute); \
373 ACPI_COPY_FIELD(out, in, granularity); \
374 ACPI_COPY_FIELD(out, in, min_address_range); \
375 ACPI_COPY_FIELD(out, in, max_address_range); \
376 ACPI_COPY_FIELD(out, in, address_translation_offset); \
377 ACPI_COPY_FIELD(out, in, address_length); \
378 ACPI_COPY_FIELD(out, in, resource_source);
380 /******************************************************************************
382 * FUNCTION: acpi_resource_to_address64
384 * PARAMETERS: resource - Pointer to a resource
385 * out - Pointer to the users's return
387 * struct acpi_resource_address64)
391 * DESCRIPTION: If the resource is an address16, address32, or address64,
392 * copy it to the address64 return buffer. This saves the
393 * caller from having to duplicate code for different-sized
396 ******************************************************************************/
399 acpi_resource_to_address64 (
400 struct acpi_resource
*resource
,
401 struct acpi_resource_address64
*out
)
403 struct acpi_resource_address16
*address16
;
404 struct acpi_resource_address32
*address32
;
407 switch (resource
->id
) {
408 case ACPI_RSTYPE_ADDRESS16
:
410 address16
= (struct acpi_resource_address16
*) &resource
->data
;
411 ACPI_COPY_ADDRESS(out
, address16
);
415 case ACPI_RSTYPE_ADDRESS32
:
417 address32
= (struct acpi_resource_address32
*) &resource
->data
;
418 ACPI_COPY_ADDRESS(out
, address32
);
422 case ACPI_RSTYPE_ADDRESS64
:
424 /* Simple copy for 64 bit source */
426 ACPI_MEMCPY (out
, &resource
->data
, sizeof (struct acpi_resource_address64
));
431 return (AE_BAD_PARAMETER
);
436 EXPORT_SYMBOL(acpi_resource_to_address64
);