- Kai Germaschewski: ISDN update (including Makefiles)
[davej-history.git] / drivers / acpi / resources / rsutils.c
blob0a3f766680e965f7877dc67820442b3cc058d71c
1 /*******************************************************************************
3 * Module Name: rsutils - Utilities for the resource manager
4 * $Revision: 12 $
6 ******************************************************************************/
8 /*
9 * Copyright (C) 2000 R. Byron Moore
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include "acpi.h"
28 #include "acnamesp.h"
29 #include "acresrc.h"
32 #define _COMPONENT RESOURCE_MANAGER
33 MODULE_NAME ("rsutils")
36 /*******************************************************************************
38 * FUNCTION: Acpi_rs_get_prt_method_data
40 * PARAMETERS: Handle - a handle to the containing object
41 * Ret_buffer - a pointer to a buffer structure for the
42 * results
44 * RETURN: Status - the status of the call
46 * DESCRIPTION: This function is called to get the _PRT value of an object
47 * contained in an object specified by the handle passed in
49 * If the function fails an appropriate status will be returned
50 * and the contents of the callers buffer is undefined.
52 ******************************************************************************/
54 ACPI_STATUS
55 acpi_rs_get_prt_method_data (
56 ACPI_HANDLE handle,
57 ACPI_BUFFER *ret_buffer)
59 ACPI_OPERAND_OBJECT *ret_obj;
60 ACPI_STATUS status;
61 u32 buffer_space_needed;
64 /* already validated params, so we won't repeat here */
66 buffer_space_needed = ret_buffer->length;
69 * Execute the method, no parameters
71 status = acpi_ns_evaluate_relative (handle, "_PRT", NULL, &ret_obj);
72 if (ACPI_FAILURE (status)) {
73 return (status);
76 if (!ret_obj) {
77 /* Return object is required */
79 return (AE_TYPE);
84 * The return object will be a package, so check the
85 * parameters. If the return object is not a package,
86 * then the underlying AML code is corrupt or improperly
87 * written.
89 if (ACPI_TYPE_PACKAGE != ret_obj->common.type) {
90 status = AE_AML_OPERAND_TYPE;
91 goto cleanup;
95 * Make the call to create a resource linked list from the
96 * byte stream buffer that comes back from the _CRS method
97 * execution.
99 status = acpi_rs_create_pci_routing_table (ret_obj,
100 ret_buffer->pointer,
101 &buffer_space_needed);
104 * Tell the user how much of the buffer we have used or is needed
105 * and return the final status.
107 ret_buffer->length = buffer_space_needed;
110 /* On exit, we must delete the object returned by evaluate_object */
112 cleanup:
114 acpi_cm_remove_reference (ret_obj);
116 return (status);
120 /*******************************************************************************
122 * FUNCTION: Acpi_rs_get_crs_method_data
124 * PARAMETERS: Handle - a handle to the containing object
125 * Ret_buffer - a pointer to a buffer structure for the
126 * results
128 * RETURN: Status - the status of the call
130 * DESCRIPTION: This function is called to get the _CRS value of an object
131 * contained in an object specified by the handle passed in
133 * If the function fails an appropriate status will be returned
134 * and the contents of the callers buffer is undefined.
136 ******************************************************************************/
138 ACPI_STATUS
139 acpi_rs_get_crs_method_data (
140 ACPI_HANDLE handle,
141 ACPI_BUFFER *ret_buffer)
143 ACPI_OPERAND_OBJECT *ret_obj;
144 ACPI_STATUS status;
145 u32 buffer_space_needed = ret_buffer->length;
148 /* already validated params, so we won't repeat here */
151 * Execute the method, no parameters
153 status = acpi_ns_evaluate_relative (handle, "_CRS", NULL, &ret_obj);
154 if (ACPI_FAILURE (status)) {
155 return (status);
158 if (!ret_obj) {
159 /* Return object is required */
161 return (AE_TYPE);
165 * The return object will be a buffer, but check the
166 * parameters. If the return object is not a buffer,
167 * then the underlying AML code is corrupt or improperly
168 * written.
170 if (ACPI_TYPE_BUFFER != ret_obj->common.type) {
171 status = AE_AML_OPERAND_TYPE;
172 goto cleanup;
176 * Make the call to create a resource linked list from the
177 * byte stream buffer that comes back from the _CRS method
178 * execution.
180 status = acpi_rs_create_resource_list (ret_obj,
181 ret_buffer->pointer,
182 &buffer_space_needed);
187 * Tell the user how much of the buffer we have used or is needed
188 * and return the final status.
190 ret_buffer->length = buffer_space_needed;
193 /* On exit, we must delete the object returned by evaluate_object */
195 cleanup:
197 acpi_cm_remove_reference (ret_obj);
199 return (status);
203 /*******************************************************************************
205 * FUNCTION: Acpi_rs_get_prs_method_data
207 * PARAMETERS: Handle - a handle to the containing object
208 * Ret_buffer - a pointer to a buffer structure for the
209 * results
211 * RETURN: Status - the status of the call
213 * DESCRIPTION: This function is called to get the _PRS value of an object
214 * contained in an object specified by the handle passed in
216 * If the function fails an appropriate status will be returned
217 * and the contents of the callers buffer is undefined.
219 ******************************************************************************/
221 ACPI_STATUS
222 acpi_rs_get_prs_method_data (
223 ACPI_HANDLE handle,
224 ACPI_BUFFER *ret_buffer)
226 ACPI_OPERAND_OBJECT *ret_obj;
227 ACPI_STATUS status;
228 u32 buffer_space_needed = ret_buffer->length;
231 /* already validated params, so we won't repeat here */
234 * Execute the method, no parameters
236 status = acpi_ns_evaluate_relative (handle, "_PRS", NULL, &ret_obj);
237 if (ACPI_FAILURE (status)) {
238 return (status);
241 if (!ret_obj) {
242 /* Return object is required */
244 return (AE_TYPE);
248 * The return object will be a buffer, but check the
249 * parameters. If the return object is not a buffer,
250 * then the underlying AML code is corrupt or improperly
251 * written..
253 if (ACPI_TYPE_BUFFER != ret_obj->common.type) {
254 status = AE_AML_OPERAND_TYPE;
255 goto cleanup;
259 * Make the call to create a resource linked list from the
260 * byte stream buffer that comes back from the _CRS method
261 * execution.
263 status = acpi_rs_create_resource_list (ret_obj,
264 ret_buffer->pointer,
265 &buffer_space_needed);
268 * Tell the user how much of the buffer we have used or is needed
269 * and return the final status.
271 ret_buffer->length = buffer_space_needed;
274 /* On exit, we must delete the object returned by evaluate_object */
276 cleanup:
278 acpi_cm_remove_reference (ret_obj);
280 return (status);
284 /*******************************************************************************
286 * FUNCTION: Acpi_rs_set_srs_method_data
288 * PARAMETERS: Handle - a handle to the containing object
289 * In_buffer - a pointer to a buffer structure of the
290 * parameter
292 * RETURN: Status - the status of the call
294 * DESCRIPTION: This function is called to set the _SRS of an object contained
295 * in an object specified by the handle passed in
297 * If the function fails an appropriate status will be returned
298 * and the contents of the callers buffer is undefined.
300 ******************************************************************************/
302 ACPI_STATUS
303 acpi_rs_set_srs_method_data (
304 ACPI_HANDLE handle,
305 ACPI_BUFFER *in_buffer)
307 ACPI_OPERAND_OBJECT *params[2];
308 ACPI_OPERAND_OBJECT param_obj;
309 ACPI_STATUS status;
310 u8 *byte_stream = NULL;
311 u32 buffer_size_needed = 0;
314 /* already validated params, so we won't repeat here */
317 * The In_buffer parameter will point to a linked list of
318 * resource parameters. It needs to be formatted into a
319 * byte stream to be sent in as an input parameter.
321 buffer_size_needed = 0;
324 * First call is to get the buffer size needed
326 status = acpi_rs_create_byte_stream (in_buffer->pointer,
327 byte_stream,
328 &buffer_size_needed);
330 * We expect a return of AE_BUFFER_OVERFLOW
331 * if not, exit with the error
333 if (AE_BUFFER_OVERFLOW != status) {
334 return (status);
338 * Allocate the buffer needed
340 byte_stream = acpi_cm_callocate(buffer_size_needed);
341 if (NULL == byte_stream) {
342 return (AE_NO_MEMORY);
346 * Now call to convert the linked list into a byte stream
348 status = acpi_rs_create_byte_stream (in_buffer->pointer,
349 byte_stream,
350 &buffer_size_needed);
351 if (ACPI_FAILURE (status)) {
352 goto cleanup;
356 * Init the param object
358 acpi_cm_init_static_object (&param_obj);
361 * Method requires one parameter. Set it up
363 params [0] = &param_obj;
364 params [1] = NULL;
367 * Set up the parameter object
369 param_obj.common.type = ACPI_TYPE_BUFFER;
370 param_obj.buffer.length = buffer_size_needed;
371 param_obj.buffer.pointer = byte_stream;
374 * Execute the method, no return value
376 status = acpi_ns_evaluate_relative (handle, "_SRS", params, NULL);
379 * Clean up and return the status from Acpi_ns_evaluate_relative
382 cleanup:
384 acpi_cm_free (byte_stream);
385 return (status);