merge ROS Shell without integrated explorer part into trunk
[reactos.git] / reactos / drivers / bus / acpi / resource / rsutils.c
1 /*******************************************************************************
2 *
3 * Module Name: rsutils - Utilities for the resource manager
4 * $Revision: 1.1 $
5 *
6 ******************************************************************************/
7
8 /*
9 * Copyright (C) 2000, 2001 R. Byron Moore
10 *
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.
15 *
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.
20 *
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
24 */
25
26
27 #include "acpi.h"
28 #include "acnamesp.h"
29 #include "acresrc.h"
30
31
32 #define _COMPONENT ACPI_RESOURCES
33 MODULE_NAME ("rsutils")
34
35
36 /*******************************************************************************
37 *
38 * FUNCTION: Acpi_rs_get_prt_method_data
39 *
40 * PARAMETERS: Handle - a handle to the containing object
41 * Ret_buffer - a pointer to a buffer structure for the
42 * results
43 *
44 * RETURN: Status - the status of the call
45 *
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
48 *
49 * If the function fails an appropriate status will be returned
50 * and the contents of the callers buffer is undefined.
51 *
52 ******************************************************************************/
53
54 ACPI_STATUS
55 acpi_rs_get_prt_method_data (
56 ACPI_HANDLE handle,
57 ACPI_BUFFER *ret_buffer)
58 {
59 ACPI_OPERAND_OBJECT *ret_obj;
60 ACPI_STATUS status;
61 u32 buffer_space_needed;
62
63
64 /* already validated params, so we won't repeat here */
65
66 buffer_space_needed = ret_buffer->length;
67
68 /*
69 * Execute the method, no parameters
70 */
71 status = acpi_ns_evaluate_relative (handle, "_PRT", NULL, &ret_obj);
72 if (ACPI_FAILURE (status)) {
73 return (status);
74 }
75
76 if (!ret_obj) {
77 /* Return object is required */
78
79 return (AE_TYPE);
80 }
81
82
83 /*
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.
88 */
89 if (ACPI_TYPE_PACKAGE != ret_obj->common.type) {
90 status = AE_AML_OPERAND_TYPE;
91 goto cleanup;
92 }
93
94 /*
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.
98 */
99 status = acpi_rs_create_pci_routing_table (ret_obj,
100 ret_buffer->pointer,
101 &buffer_space_needed);
102
103 /*
104 * Tell the user how much of the buffer we have used or is needed
105 * and return the final status.
106 */
107 ret_buffer->length = buffer_space_needed;
108
109
110 /* On exit, we must delete the object returned by evaluate_object */
111
112 cleanup:
113
114 acpi_cm_remove_reference (ret_obj);
115
116 return (status);
117 }
118
119
120 /*******************************************************************************
121 *
122 * FUNCTION: Acpi_rs_get_crs_method_data
123 *
124 * PARAMETERS: Handle - a handle to the containing object
125 * Ret_buffer - a pointer to a buffer structure for the
126 * results
127 *
128 * RETURN: Status - the status of the call
129 *
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
132 *
133 * If the function fails an appropriate status will be returned
134 * and the contents of the callers buffer is undefined.
135 *
136 ******************************************************************************/
137
138 ACPI_STATUS
139 acpi_rs_get_crs_method_data (
140 ACPI_HANDLE handle,
141 ACPI_BUFFER *ret_buffer)
142 {
143 ACPI_OPERAND_OBJECT *ret_obj;
144 ACPI_STATUS status;
145 u32 buffer_space_needed = ret_buffer->length;
146
147
148 /* already validated params, so we won't repeat here */
149
150 /*
151 * Execute the method, no parameters
152 */
153 status = acpi_ns_evaluate_relative (handle, "_CRS", NULL, &ret_obj);
154 if (ACPI_FAILURE (status)) {
155 return (status);
156 }
157
158 if (!ret_obj) {
159 /* Return object is required */
160
161 return (AE_TYPE);
162 }
163
164 /*
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.
169 */
170 if (ACPI_TYPE_BUFFER != ret_obj->common.type) {
171 status = AE_AML_OPERAND_TYPE;
172 goto cleanup;
173 }
174
175 /*
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.
179 */
180 status = acpi_rs_create_resource_list (ret_obj,
181 ret_buffer->pointer,
182 &buffer_space_needed);
183
184
185
186 /*
187 * Tell the user how much of the buffer we have used or is needed
188 * and return the final status.
189 */
190 ret_buffer->length = buffer_space_needed;
191
192
193 /* On exit, we must delete the object returned by evaluate_object */
194
195 cleanup:
196
197 acpi_cm_remove_reference (ret_obj);
198
199 return (status);
200 }
201
202
203 /*******************************************************************************
204 *
205 * FUNCTION: Acpi_rs_get_prs_method_data
206 *
207 * PARAMETERS: Handle - a handle to the containing object
208 * Ret_buffer - a pointer to a buffer structure for the
209 * results
210 *
211 * RETURN: Status - the status of the call
212 *
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
215 *
216 * If the function fails an appropriate status will be returned
217 * and the contents of the callers buffer is undefined.
218 *
219 ******************************************************************************/
220
221 ACPI_STATUS
222 acpi_rs_get_prs_method_data (
223 ACPI_HANDLE handle,
224 ACPI_BUFFER *ret_buffer)
225 {
226 ACPI_OPERAND_OBJECT *ret_obj;
227 ACPI_STATUS status;
228 u32 buffer_space_needed = ret_buffer->length;
229
230
231 /* already validated params, so we won't repeat here */
232
233 /*
234 * Execute the method, no parameters
235 */
236 status = acpi_ns_evaluate_relative (handle, "_PRS", NULL, &ret_obj);
237 if (ACPI_FAILURE (status)) {
238 return (status);
239 }
240
241 if (!ret_obj) {
242 /* Return object is required */
243
244 return (AE_TYPE);
245 }
246
247 /*
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..
252 */
253 if (ACPI_TYPE_BUFFER != ret_obj->common.type) {
254 status = AE_AML_OPERAND_TYPE;
255 goto cleanup;
256 }
257
258 /*
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.
262 */
263 status = acpi_rs_create_resource_list (ret_obj,
264 ret_buffer->pointer,
265 &buffer_space_needed);
266
267 /*
268 * Tell the user how much of the buffer we have used or is needed
269 * and return the final status.
270 */
271 ret_buffer->length = buffer_space_needed;
272
273
274 /* On exit, we must delete the object returned by evaluate_object */
275
276 cleanup:
277
278 acpi_cm_remove_reference (ret_obj);
279
280 return (status);
281 }
282
283
284 /*******************************************************************************
285 *
286 * FUNCTION: Acpi_rs_set_srs_method_data
287 *
288 * PARAMETERS: Handle - a handle to the containing object
289 * In_buffer - a pointer to a buffer structure of the
290 * parameter
291 *
292 * RETURN: Status - the status of the call
293 *
294 * DESCRIPTION: This function is called to set the _SRS of an object contained
295 * in an object specified by the handle passed in
296 *
297 * If the function fails an appropriate status will be returned
298 * and the contents of the callers buffer is undefined.
299 *
300 ******************************************************************************/
301
302 ACPI_STATUS
303 acpi_rs_set_srs_method_data (
304 ACPI_HANDLE handle,
305 ACPI_BUFFER *in_buffer)
306 {
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;
312
313
314 /* already validated params, so we won't repeat here */
315
316 /*
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.
320 */
321 buffer_size_needed = 0;
322
323 /*
324 * First call is to get the buffer size needed
325 */
326 status = acpi_rs_create_byte_stream (in_buffer->pointer,
327 byte_stream,
328 &buffer_size_needed);
329 /*
330 * We expect a return of AE_BUFFER_OVERFLOW
331 * if not, exit with the error
332 */
333 if (AE_BUFFER_OVERFLOW != status) {
334 return (status);
335 }
336
337 /*
338 * Allocate the buffer needed
339 */
340 byte_stream = acpi_cm_callocate(buffer_size_needed);
341 if (NULL == byte_stream) {
342 return (AE_NO_MEMORY);
343 }
344
345 /*
346 * Now call to convert the linked list into a byte stream
347 */
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;
353 }
354
355 /*
356 * Init the param object
357 */
358 acpi_cm_init_static_object (&param_obj);
359
360 /*
361 * Method requires one parameter. Set it up
362 */
363 params [0] = &param_obj;
364 params [1] = NULL;
365
366 /*
367 * Set up the parameter object
368 */
369 param_obj.common.type = ACPI_TYPE_BUFFER;
370 param_obj.buffer.length = buffer_size_needed;
371 param_obj.buffer.pointer = byte_stream;
372
373 /*
374 * Execute the method, no return value
375 */
376 status = acpi_ns_evaluate_relative (handle, "_SRS", params, NULL);
377
378 /*
379 * Clean up and return the status from Acpi_ns_evaluate_relative
380 */
381
382 cleanup:
383
384 acpi_cm_free (byte_stream);
385 return (status);
386 }
387