]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/acpi/resources/rsutils.c
Pull release into acpica branch
[mirror_ubuntu-artful-kernel.git] / drivers / acpi / resources / rsutils.c
CommitLineData
1da177e4
LT
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
1da177e4
LT
44#include <acpi/acpi.h>
45#include <acpi/acnamesp.h>
46#include <acpi/acresrc.h>
47
1da177e4 48#define _COMPONENT ACPI_RESOURCES
4be44fcd 49ACPI_MODULE_NAME("rsutils")
1da177e4
LT
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 ******************************************************************************/
1da177e4 68acpi_status
4be44fcd 69acpi_rs_get_prt_method_data(acpi_handle handle, struct acpi_buffer *ret_buffer)
1da177e4 70{
4be44fcd
LB
71 union acpi_operand_object *obj_desc;
72 acpi_status status;
1da177e4 73
4be44fcd 74 ACPI_FUNCTION_TRACE("rs_get_prt_method_data");
1da177e4
LT
75
76 /* Parameters guaranteed valid by caller */
77
44f6c012
RM
78 /* Execute the method, no parameters */
79
4be44fcd
LB
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);
1da177e4
LT
84 }
85
86 /*
87 * Create a resource linked list from the byte stream buffer that comes
88 * back from the _CRS method execution.
89 */
4be44fcd 90 status = acpi_rs_create_pci_routing_table(obj_desc, ret_buffer);
1da177e4
LT
91
92 /* On exit, we must delete the object returned by evaluate_object */
93
4be44fcd
LB
94 acpi_ut_remove_reference(obj_desc);
95 return_ACPI_STATUS(status);
1da177e4
LT
96}
97
1da177e4
LT
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
116acpi_status
4be44fcd 117acpi_rs_get_crs_method_data(acpi_handle handle, struct acpi_buffer *ret_buffer)
1da177e4 118{
4be44fcd
LB
119 union acpi_operand_object *obj_desc;
120 acpi_status status;
1da177e4 121
4be44fcd 122 ACPI_FUNCTION_TRACE("rs_get_crs_method_data");
1da177e4
LT
123
124 /* Parameters guaranteed valid by caller */
125
44f6c012
RM
126 /* Execute the method, no parameters */
127
4be44fcd
LB
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);
1da177e4
LT
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 */
4be44fcd 139 status = acpi_rs_create_resource_list(obj_desc, ret_buffer);
1da177e4
LT
140
141 /* on exit, we must delete the object returned by evaluate_object */
142
4be44fcd
LB
143 acpi_ut_remove_reference(obj_desc);
144 return_ACPI_STATUS(status);
1da177e4
LT
145}
146
1da177e4
LT
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 ******************************************************************************/
44f6c012 164
1da177e4
LT
165#ifdef ACPI_FUTURE_USAGE
166acpi_status
4be44fcd 167acpi_rs_get_prs_method_data(acpi_handle handle, struct acpi_buffer *ret_buffer)
1da177e4 168{
4be44fcd
LB
169 union acpi_operand_object *obj_desc;
170 acpi_status status;
1da177e4 171
4be44fcd 172 ACPI_FUNCTION_TRACE("rs_get_prs_method_data");
1da177e4
LT
173
174 /* Parameters guaranteed valid by caller */
175
44f6c012
RM
176 /* Execute the method, no parameters */
177
4be44fcd
LB
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);
1da177e4
LT
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 */
4be44fcd 189 status = acpi_rs_create_resource_list(obj_desc, ret_buffer);
1da177e4
LT
190
191 /* on exit, we must delete the object returned by evaluate_object */
192
4be44fcd
LB
193 acpi_ut_remove_reference(obj_desc);
194 return_ACPI_STATUS(status);
1da177e4 195}
4be44fcd 196#endif /* ACPI_FUTURE_USAGE */
1da177e4
LT
197
198/*******************************************************************************
199 *
200 * FUNCTION: acpi_rs_get_method_data
201 *
202 * PARAMETERS: Handle - a handle to the containing object
44f6c012 203 * Path - Path to method, relative to Handle
1da177e4
LT
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
217acpi_status
4be44fcd
LB
218acpi_rs_get_method_data(acpi_handle handle,
219 char *path, struct acpi_buffer *ret_buffer)
1da177e4 220{
4be44fcd
LB
221 union acpi_operand_object *obj_desc;
222 acpi_status status;
1da177e4 223
4be44fcd 224 ACPI_FUNCTION_TRACE("rs_get_method_data");
1da177e4
LT
225
226 /* Parameters guaranteed valid by caller */
227
44f6c012
RM
228 /* Execute the method, no parameters */
229
4be44fcd
LB
230 status =
231 acpi_ut_evaluate_object(handle, path, ACPI_BTYPE_BUFFER, &obj_desc);
232 if (ACPI_FAILURE(status)) {
233 return_ACPI_STATUS(status);
1da177e4
LT
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 */
4be44fcd 241 status = acpi_rs_create_resource_list(obj_desc, ret_buffer);
1da177e4
LT
242
243 /* On exit, we must delete the object returned by evaluate_object */
244
4be44fcd
LB
245 acpi_ut_remove_reference(obj_desc);
246 return_ACPI_STATUS(status);
1da177e4
LT
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
267acpi_status
4be44fcd 268acpi_rs_set_srs_method_data(acpi_handle handle, struct acpi_buffer *in_buffer)
1da177e4 269{
4be44fcd
LB
270 struct acpi_parameter_info info;
271 union acpi_operand_object *params[2];
272 acpi_status status;
273 struct acpi_buffer buffer;
1da177e4 274
4be44fcd 275 ACPI_FUNCTION_TRACE("rs_set_srs_method_data");
1da177e4
LT
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;
4be44fcd
LB
287 status = acpi_rs_create_byte_stream(in_buffer->pointer, &buffer);
288 if (ACPI_FAILURE(status)) {
289 return_ACPI_STATUS(status);
1da177e4
LT
290 }
291
44f6c012
RM
292 /* Init the param object */
293
4be44fcd 294 params[0] = acpi_ut_create_internal_object(ACPI_TYPE_BUFFER);
1da177e4 295 if (!params[0]) {
4be44fcd
LB
296 acpi_os_free(buffer.pointer);
297 return_ACPI_STATUS(AE_NO_MEMORY);
1da177e4
LT
298 }
299
44f6c012
RM
300 /* Set up the parameter object */
301
4be44fcd 302 params[0]->buffer.length = (u32) buffer.length;
1da177e4 303 params[0]->buffer.pointer = buffer.pointer;
4be44fcd 304 params[0]->common.flags = AOPOBJ_DATA_VALID;
1da177e4
LT
305 params[1] = NULL;
306
307 info.node = handle;
308 info.parameters = params;
309 info.parameter_type = ACPI_PARAM_ARGS;
310
44f6c012
RM
311 /* Execute the method, no return value */
312
4be44fcd
LB
313 status = acpi_ns_evaluate_relative(METHOD_NAME__SRS, &info);
314 if (ACPI_SUCCESS(status)) {
1da177e4
LT
315 /* Delete any return object (especially if implicit_return is enabled) */
316
317 if (info.return_object) {
4be44fcd 318 acpi_ut_remove_reference(info.return_object);
1da177e4
LT
319 }
320 }
321
44f6c012
RM
322 /* Clean up and return the status from acpi_ns_evaluate_relative */
323
4be44fcd
LB
324 acpi_ut_remove_reference(params[0]);
325 return_ACPI_STATUS(status);
1da177e4 326}