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