blob: 4446778eaf7927df16f9b29a49fb2a6395871086 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*******************************************************************************
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <acpi/acpi.h>
45#include <acpi/acnamesp.h>
46#include <acpi/acresrc.h>
47
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#define _COMPONENT ACPI_RESOURCES
Len Brown4be44fc2005-08-05 00:44:28 -040049ACPI_MODULE_NAME("rsutils")
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
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 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -070068acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040069acpi_rs_get_prt_method_data(acpi_handle handle, struct acpi_buffer *ret_buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -070070{
Len Brown4be44fc2005-08-05 00:44:28 -040071 union acpi_operand_object *obj_desc;
72 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
Len Brown4be44fc2005-08-05 00:44:28 -040074 ACPI_FUNCTION_TRACE("rs_get_prt_method_data");
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
76 /* Parameters guaranteed valid by caller */
77
Robert Moore44f6c012005-04-18 22:49:35 -040078 /* Execute the method, no parameters */
79
Len Brown4be44fc2005-08-05 00:44:28 -040080 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 }
85
86 /*
87 * Create a resource linked list from the byte stream buffer that comes
88 * back from the _CRS method execution.
89 */
Len Brown4be44fc2005-08-05 00:44:28 -040090 status = acpi_rs_create_pci_routing_table(obj_desc, ret_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
92 /* On exit, we must delete the object returned by evaluate_object */
93
Len Brown4be44fc2005-08-05 00:44:28 -040094 acpi_ut_remove_reference(obj_desc);
95 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -070096}
97
Linus Torvalds1da177e2005-04-16 15:20:36 -070098/*******************************************************************************
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
Len Brown4be44fc2005-08-05 00:44:28 -0400117acpi_rs_get_crs_method_data(acpi_handle handle, struct acpi_buffer *ret_buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118{
Len Brown4be44fc2005-08-05 00:44:28 -0400119 union acpi_operand_object *obj_desc;
120 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
Len Brown4be44fc2005-08-05 00:44:28 -0400122 ACPI_FUNCTION_TRACE("rs_get_crs_method_data");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
124 /* Parameters guaranteed valid by caller */
125
Robert Moore44f6c012005-04-18 22:49:35 -0400126 /* Execute the method, no parameters */
127
Len Brown4be44fc2005-08-05 00:44:28 -0400128 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 }
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 */
Len Brown4be44fc2005-08-05 00:44:28 -0400139 status = acpi_rs_create_resource_list(obj_desc, ret_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
141 /* on exit, we must delete the object returned by evaluate_object */
142
Len Brown4be44fc2005-08-05 00:44:28 -0400143 acpi_ut_remove_reference(obj_desc);
144 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145}
146
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147/*******************************************************************************
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 ******************************************************************************/
Robert Moore44f6c012005-04-18 22:49:35 -0400164
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165#ifdef ACPI_FUTURE_USAGE
166acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400167acpi_rs_get_prs_method_data(acpi_handle handle, struct acpi_buffer *ret_buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168{
Len Brown4be44fc2005-08-05 00:44:28 -0400169 union acpi_operand_object *obj_desc;
170 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
Len Brown4be44fc2005-08-05 00:44:28 -0400172 ACPI_FUNCTION_TRACE("rs_get_prs_method_data");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173
174 /* Parameters guaranteed valid by caller */
175
Robert Moore44f6c012005-04-18 22:49:35 -0400176 /* Execute the method, no parameters */
177
Len Brown4be44fc2005-08-05 00:44:28 -0400178 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 }
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 */
Len Brown4be44fc2005-08-05 00:44:28 -0400189 status = acpi_rs_create_resource_list(obj_desc, ret_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190
191 /* on exit, we must delete the object returned by evaluate_object */
192
Len Brown4be44fc2005-08-05 00:44:28 -0400193 acpi_ut_remove_reference(obj_desc);
194 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195}
Len Brown4be44fc2005-08-05 00:44:28 -0400196#endif /* ACPI_FUTURE_USAGE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197
198/*******************************************************************************
199 *
200 * FUNCTION: acpi_rs_get_method_data
201 *
202 * PARAMETERS: Handle - a handle to the containing object
Robert Moore44f6c012005-04-18 22:49:35 -0400203 * Path - Path to method, relative to Handle
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 * 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
Len Brown4be44fc2005-08-05 00:44:28 -0400218acpi_rs_get_method_data(acpi_handle handle,
219 char *path, struct acpi_buffer *ret_buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220{
Len Brown4be44fc2005-08-05 00:44:28 -0400221 union acpi_operand_object *obj_desc;
222 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223
Len Brown4be44fc2005-08-05 00:44:28 -0400224 ACPI_FUNCTION_TRACE("rs_get_method_data");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225
226 /* Parameters guaranteed valid by caller */
227
Robert Moore44f6c012005-04-18 22:49:35 -0400228 /* Execute the method, no parameters */
229
Len Brown4be44fc2005-08-05 00:44:28 -0400230 status =
231 acpi_ut_evaluate_object(handle, path, ACPI_BTYPE_BUFFER, &obj_desc);
232 if (ACPI_FAILURE(status)) {
233 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 }
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 */
Len Brown4be44fc2005-08-05 00:44:28 -0400241 status = acpi_rs_create_resource_list(obj_desc, ret_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242
243 /* On exit, we must delete the object returned by evaluate_object */
244
Len Brown4be44fc2005-08-05 00:44:28 -0400245 acpi_ut_remove_reference(obj_desc);
246 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247}
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
Len Brown4be44fc2005-08-05 00:44:28 -0400268acpi_rs_set_srs_method_data(acpi_handle handle, struct acpi_buffer *in_buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269{
Len Brown4be44fc2005-08-05 00:44:28 -0400270 struct acpi_parameter_info info;
271 union acpi_operand_object *params[2];
272 acpi_status status;
273 struct acpi_buffer buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274
Len Brown4be44fc2005-08-05 00:44:28 -0400275 ACPI_FUNCTION_TRACE("rs_set_srs_method_data");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276
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;
Len Brown4be44fc2005-08-05 00:44:28 -0400287 status = acpi_rs_create_byte_stream(in_buffer->pointer, &buffer);
288 if (ACPI_FAILURE(status)) {
289 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 }
291
Robert Moore44f6c012005-04-18 22:49:35 -0400292 /* Init the param object */
293
Len Brown4be44fc2005-08-05 00:44:28 -0400294 params[0] = acpi_ut_create_internal_object(ACPI_TYPE_BUFFER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 if (!params[0]) {
Len Brown4be44fc2005-08-05 00:44:28 -0400296 acpi_os_free(buffer.pointer);
297 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 }
299
Robert Moore44f6c012005-04-18 22:49:35 -0400300 /* Set up the parameter object */
301
Len Brown4be44fc2005-08-05 00:44:28 -0400302 params[0]->buffer.length = (u32) buffer.length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 params[0]->buffer.pointer = buffer.pointer;
Len Brown4be44fc2005-08-05 00:44:28 -0400304 params[0]->common.flags = AOPOBJ_DATA_VALID;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 params[1] = NULL;
306
307 info.node = handle;
308 info.parameters = params;
309 info.parameter_type = ACPI_PARAM_ARGS;
310
Robert Moore44f6c012005-04-18 22:49:35 -0400311 /* Execute the method, no return value */
312
Len Brown4be44fc2005-08-05 00:44:28 -0400313 status = acpi_ns_evaluate_relative(METHOD_NAME__SRS, &info);
314 if (ACPI_SUCCESS(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 /* Delete any return object (especially if implicit_return is enabled) */
316
317 if (info.return_object) {
Len Brown4be44fc2005-08-05 00:44:28 -0400318 acpi_ut_remove_reference(info.return_object);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 }
320 }
321
Robert Moore44f6c012005-04-18 22:49:35 -0400322 /* Clean up and return the status from acpi_ns_evaluate_relative */
323
Len Brown4be44fc2005-08-05 00:44:28 -0400324 acpi_ut_remove_reference(params[0]);
325 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326}