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