1 /*******************************************************************************
2 *
3 * Module Name: rsutils - Utilities for the resource manager
4 *
5 ******************************************************************************/
6
7 /*
8 * Copyright (C) 2000 - 2004, R. Byron Moore
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
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.
25 *
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.
29 *
30 * NO WARRANTY
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.
42 */
43
44
45 #include <acpi/acpi.h>
46 #include <acpi/acnamesp.h>
47 #include <acpi/acresrc.h>
48
49
50 #define _COMPONENT ACPI_RESOURCES
51 ACPI_MODULE_NAME ("rsutils")
52
53
54 /*******************************************************************************
55 *
56 * FUNCTION: acpi_rs_get_prt_method_data
57 *
58 * PARAMETERS: Handle - a handle to the containing object
59 * ret_buffer - a pointer to a buffer structure for the
60 * results
61 *
62 * RETURN: Status
63 *
64 * DESCRIPTION: This function is called to get the _PRT value of an object
65 * contained in an object specified by the handle passed in
66 *
67 * If the function fails an appropriate status will be returned
68 * and the contents of the callers buffer is undefined.
69 *
70 ******************************************************************************/
71
72 acpi_status
acpi_rs_get_prt_method_data(acpi_handle handle,struct acpi_buffer * ret_buffer)73 acpi_rs_get_prt_method_data (
74 acpi_handle handle,
75 struct acpi_buffer *ret_buffer)
76 {
77 union acpi_operand_object *obj_desc;
78 acpi_status status;
79
80
81 ACPI_FUNCTION_TRACE ("rs_get_prt_method_data");
82
83
84 /* Parameters guaranteed valid by caller */
85
86 /*
87 * Execute the method, no parameters
88 */
89 status = acpi_ut_evaluate_object (handle, "_PRT", ACPI_BTYPE_PACKAGE, &obj_desc);
90 if (ACPI_FAILURE (status)) {
91 return_ACPI_STATUS (status);
92 }
93
94 /*
95 * Create a resource linked list from the byte stream buffer that comes
96 * back from the _CRS method execution.
97 */
98 status = acpi_rs_create_pci_routing_table (obj_desc, ret_buffer);
99
100 /* On exit, we must delete the object returned by evaluate_object */
101
102 acpi_ut_remove_reference (obj_desc);
103 return_ACPI_STATUS (status);
104 }
105
106
107 /*******************************************************************************
108 *
109 * FUNCTION: acpi_rs_get_crs_method_data
110 *
111 * PARAMETERS: Handle - a handle to the containing object
112 * ret_buffer - a pointer to a buffer structure for the
113 * results
114 *
115 * RETURN: Status
116 *
117 * DESCRIPTION: This function is called to get the _CRS value of an object
118 * contained in an object specified by the handle passed in
119 *
120 * If the function fails an appropriate status will be returned
121 * and the contents of the callers buffer is undefined.
122 *
123 ******************************************************************************/
124
125 acpi_status
acpi_rs_get_crs_method_data(acpi_handle handle,struct acpi_buffer * ret_buffer)126 acpi_rs_get_crs_method_data (
127 acpi_handle handle,
128 struct acpi_buffer *ret_buffer)
129 {
130 union acpi_operand_object *obj_desc;
131 acpi_status status;
132
133
134 ACPI_FUNCTION_TRACE ("rs_get_crs_method_data");
135
136
137 /* Parameters guaranteed valid by caller */
138
139 /*
140 * Execute the method, no parameters
141 */
142 status = acpi_ut_evaluate_object (handle, "_CRS", ACPI_BTYPE_BUFFER, &obj_desc);
143 if (ACPI_FAILURE (status)) {
144 return_ACPI_STATUS (status);
145 }
146
147 /*
148 * Make the call to create a resource linked list from the
149 * byte stream buffer that comes back from the _CRS method
150 * execution.
151 */
152 status = acpi_rs_create_resource_list (obj_desc, ret_buffer);
153
154 /* on exit, we must delete the object returned by evaluate_object */
155
156 acpi_ut_remove_reference (obj_desc);
157 return_ACPI_STATUS (status);
158 }
159
160
161 /*******************************************************************************
162 *
163 * FUNCTION: acpi_rs_get_prs_method_data
164 *
165 * PARAMETERS: Handle - a handle to the containing object
166 * ret_buffer - a pointer to a buffer structure for the
167 * results
168 *
169 * RETURN: Status
170 *
171 * DESCRIPTION: This function is called to get the _PRS value of an object
172 * contained in an object specified by the handle passed in
173 *
174 * If the function fails an appropriate status will be returned
175 * and the contents of the callers buffer is undefined.
176 *
177 ******************************************************************************/
178
179 acpi_status
acpi_rs_get_prs_method_data(acpi_handle handle,struct acpi_buffer * ret_buffer)180 acpi_rs_get_prs_method_data (
181 acpi_handle handle,
182 struct acpi_buffer *ret_buffer)
183 {
184 union acpi_operand_object *obj_desc;
185 acpi_status status;
186
187
188 ACPI_FUNCTION_TRACE ("rs_get_prs_method_data");
189
190
191 /* Parameters guaranteed valid by caller */
192
193 /*
194 * Execute the method, no parameters
195 */
196 status = acpi_ut_evaluate_object (handle, "_PRS", ACPI_BTYPE_BUFFER, &obj_desc);
197 if (ACPI_FAILURE (status)) {
198 return_ACPI_STATUS (status);
199 }
200
201 /*
202 * Make the call to create a resource linked list from the
203 * byte stream buffer that comes back from the _CRS method
204 * execution.
205 */
206 status = acpi_rs_create_resource_list (obj_desc, ret_buffer);
207
208 /* on exit, we must delete the object returned by evaluate_object */
209
210 acpi_ut_remove_reference (obj_desc);
211 return_ACPI_STATUS (status);
212 }
213
214
215 /*******************************************************************************
216 *
217 * FUNCTION: acpi_rs_get_method_data
218 *
219 * PARAMETERS: Handle - a handle to the containing object
220 * ret_buffer - a pointer to a buffer structure for the
221 * results
222 *
223 * RETURN: Status
224 *
225 * DESCRIPTION: This function is called to get the _CRS or _PRS value of an
226 * object contained in an object specified by the handle passed in
227 *
228 * If the function fails an appropriate status will be returned
229 * and the contents of the callers buffer is undefined.
230 *
231 ******************************************************************************/
232
233 acpi_status
acpi_rs_get_method_data(acpi_handle handle,char * path,struct acpi_buffer * ret_buffer)234 acpi_rs_get_method_data (
235 acpi_handle handle,
236 char *path,
237 struct acpi_buffer *ret_buffer)
238 {
239 union acpi_operand_object *obj_desc;
240 acpi_status status;
241
242
243 ACPI_FUNCTION_TRACE ("rs_get_method_data");
244
245
246 /* Parameters guaranteed valid by caller */
247
248 /*
249 * Execute the method, no parameters
250 */
251 status = acpi_ut_evaluate_object (handle, path, ACPI_BTYPE_BUFFER, &obj_desc);
252 if (ACPI_FAILURE (status)) {
253 return_ACPI_STATUS (status);
254 }
255
256 /*
257 * Make the call to create a resource linked list from the
258 * byte stream buffer that comes back from the method
259 * execution.
260 */
261 status = acpi_rs_create_resource_list (obj_desc, ret_buffer);
262
263 /* On exit, we must delete the object returned by evaluate_object */
264
265 acpi_ut_remove_reference (obj_desc);
266 return_ACPI_STATUS (status);
267 }
268
269 /*******************************************************************************
270 *
271 * FUNCTION: acpi_rs_set_srs_method_data
272 *
273 * PARAMETERS: Handle - a handle to the containing object
274 * in_buffer - a pointer to a buffer structure of the
275 * parameter
276 *
277 * RETURN: Status
278 *
279 * DESCRIPTION: This function is called to set the _SRS of an object contained
280 * in an object specified by the handle passed in
281 *
282 * If the function fails an appropriate status will be returned
283 * and the contents of the callers buffer is undefined.
284 *
285 ******************************************************************************/
286
287 acpi_status
acpi_rs_set_srs_method_data(acpi_handle handle,struct acpi_buffer * in_buffer)288 acpi_rs_set_srs_method_data (
289 acpi_handle handle,
290 struct acpi_buffer *in_buffer)
291 {
292 union acpi_operand_object *params[2];
293 acpi_status status;
294 struct acpi_buffer buffer;
295
296
297 ACPI_FUNCTION_TRACE ("rs_set_srs_method_data");
298
299
300 /* Parameters guaranteed valid by caller */
301
302 /*
303 * The in_buffer parameter will point to a linked list of
304 * resource parameters. It needs to be formatted into a
305 * byte stream to be sent in as an input parameter to _SRS
306 *
307 * Convert the linked list into a byte stream
308 */
309 buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER;
310 status = acpi_rs_create_byte_stream (in_buffer->pointer, &buffer);
311 if (ACPI_FAILURE (status)) {
312 return_ACPI_STATUS (status);
313 }
314
315 /*
316 * Init the param object
317 */
318 params[0] = acpi_ut_create_internal_object (ACPI_TYPE_BUFFER);
319 if (!params[0]) {
320 acpi_os_free (buffer.pointer);
321 return_ACPI_STATUS (AE_NO_MEMORY);
322 }
323
324 /*
325 * Set up the parameter object
326 */
327 params[0]->buffer.length = (u32) buffer.length;
328 params[0]->buffer.pointer = buffer.pointer;
329 params[0]->common.flags = AOPOBJ_DATA_VALID;
330 params[1] = NULL;
331
332 /*
333 * Execute the method, no return value
334 */
335 status = acpi_ns_evaluate_relative (handle, "_SRS", params, NULL);
336
337 /*
338 * Clean up and return the status from acpi_ns_evaluate_relative
339 */
340 acpi_ut_remove_reference (params[0]);
341 return_ACPI_STATUS (status);
342 }
343
344