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