Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Module Name: utcopy - Internal to external object translation utilities |
| 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/amlcode.h> |
| 46 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #define _COMPONENT ACPI_UTILITIES |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 48 | ACPI_MODULE_NAME("utcopy") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 50 | /* Local prototypes */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 51 | static acpi_status |
| 52 | acpi_ut_copy_isimple_to_esimple(union acpi_operand_object *internal_object, |
| 53 | union acpi_object *external_object, |
| 54 | u8 * data_space, acpi_size * buffer_space_used); |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 55 | |
| 56 | static acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 57 | acpi_ut_copy_ielement_to_ielement(u8 object_type, |
| 58 | union acpi_operand_object *source_object, |
| 59 | union acpi_generic_state *state, |
| 60 | void *context); |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 61 | |
| 62 | static acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 63 | acpi_ut_copy_ipackage_to_epackage(union acpi_operand_object *internal_object, |
| 64 | u8 * buffer, acpi_size * space_used); |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 65 | |
| 66 | static acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 67 | acpi_ut_copy_esimple_to_isimple(union acpi_object *user_obj, |
| 68 | union acpi_operand_object **return_obj); |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 69 | |
| 70 | static acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 71 | acpi_ut_copy_simple_object(union acpi_operand_object *source_desc, |
| 72 | union acpi_operand_object *dest_desc); |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 73 | |
| 74 | static acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 75 | acpi_ut_copy_ielement_to_eelement(u8 object_type, |
| 76 | union acpi_operand_object *source_object, |
| 77 | union acpi_generic_state *state, |
| 78 | void *context); |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 79 | |
| 80 | static acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 81 | acpi_ut_copy_ipackage_to_ipackage(union acpi_operand_object *source_obj, |
| 82 | union acpi_operand_object *dest_obj, |
| 83 | struct acpi_walk_state *walk_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | |
| 85 | /******************************************************************************* |
| 86 | * |
| 87 | * FUNCTION: acpi_ut_copy_isimple_to_esimple |
| 88 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 89 | * PARAMETERS: internal_object - Source object to be copied |
| 90 | * external_object - Where to return the copied object |
| 91 | * data_space - Where object data is returned (such as |
| 92 | * buffer and string data) |
| 93 | * buffer_space_used - Length of data_space that was used |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | * |
| 95 | * RETURN: Status |
| 96 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 97 | * DESCRIPTION: This function is called to copy a simple internal object to |
| 98 | * an external object. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 100 | * The data_space buffer is assumed to have sufficient space for |
| 101 | * the object. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | * |
| 103 | ******************************************************************************/ |
| 104 | |
| 105 | static acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 106 | acpi_ut_copy_isimple_to_esimple(union acpi_operand_object *internal_object, |
| 107 | union acpi_object *external_object, |
| 108 | u8 * data_space, acpi_size * buffer_space_used) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 110 | acpi_status status = AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 112 | ACPI_FUNCTION_TRACE("ut_copy_isimple_to_esimple"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | |
| 114 | *buffer_space_used = 0; |
| 115 | |
| 116 | /* |
| 117 | * Check for NULL object case (could be an uninitialized |
| 118 | * package element) |
| 119 | */ |
| 120 | if (!internal_object) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 121 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | /* Always clear the external object */ |
| 125 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 126 | ACPI_MEMSET(external_object, 0, sizeof(union acpi_object)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | |
| 128 | /* |
| 129 | * In general, the external object will be the same type as |
| 130 | * the internal object |
| 131 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 132 | external_object->type = ACPI_GET_OBJECT_TYPE(internal_object); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | |
| 134 | /* However, only a limited number of external types are supported */ |
| 135 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 136 | switch (ACPI_GET_OBJECT_TYPE(internal_object)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | case ACPI_TYPE_STRING: |
| 138 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 139 | external_object->string.pointer = (char *)data_space; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | external_object->string.length = internal_object->string.length; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 141 | *buffer_space_used = ACPI_ROUND_UP_TO_NATIVE_WORD((acpi_size) |
| 142 | internal_object-> |
| 143 | string. |
| 144 | length + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 146 | ACPI_MEMCPY((void *)data_space, |
| 147 | (void *)internal_object->string.pointer, |
| 148 | (acpi_size) internal_object->string.length + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | break; |
| 150 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | case ACPI_TYPE_BUFFER: |
| 152 | |
| 153 | external_object->buffer.pointer = data_space; |
| 154 | external_object->buffer.length = internal_object->buffer.length; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 155 | *buffer_space_used = |
| 156 | ACPI_ROUND_UP_TO_NATIVE_WORD(internal_object->string. |
| 157 | length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 159 | ACPI_MEMCPY((void *)data_space, |
| 160 | (void *)internal_object->buffer.pointer, |
| 161 | internal_object->buffer.length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | break; |
| 163 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | case ACPI_TYPE_INTEGER: |
| 165 | |
| 166 | external_object->integer.value = internal_object->integer.value; |
| 167 | break; |
| 168 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | case ACPI_TYPE_LOCAL_REFERENCE: |
| 170 | |
| 171 | /* |
| 172 | * This is an object reference. Attempt to dereference it. |
| 173 | */ |
| 174 | switch (internal_object->reference.opcode) { |
| 175 | case AML_INT_NAMEPATH_OP: |
| 176 | |
| 177 | /* For namepath, return the object handle ("reference") */ |
| 178 | |
| 179 | default: |
| 180 | /* |
| 181 | * Use the object type of "Any" to indicate a reference |
| 182 | * to object containing a handle to an ACPI named object. |
| 183 | */ |
| 184 | external_object->type = ACPI_TYPE_ANY; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 185 | external_object->reference.handle = |
| 186 | internal_object->reference.node; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | break; |
| 188 | } |
| 189 | break; |
| 190 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | case ACPI_TYPE_PROCESSOR: |
| 192 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 193 | external_object->processor.proc_id = |
| 194 | internal_object->processor.proc_id; |
| 195 | external_object->processor.pblk_address = |
| 196 | internal_object->processor.address; |
| 197 | external_object->processor.pblk_length = |
| 198 | internal_object->processor.length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | break; |
| 200 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | case ACPI_TYPE_POWER: |
| 202 | |
| 203 | external_object->power_resource.system_level = |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 204 | internal_object->power_resource.system_level; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | |
| 206 | external_object->power_resource.resource_order = |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 207 | internal_object->power_resource.resource_order; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | break; |
| 209 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | default: |
| 211 | /* |
| 212 | * There is no corresponding external object type |
| 213 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 214 | return_ACPI_STATUS(AE_SUPPORT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | } |
| 216 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 217 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | } |
| 219 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | /******************************************************************************* |
| 221 | * |
| 222 | * FUNCTION: acpi_ut_copy_ielement_to_eelement |
| 223 | * |
| 224 | * PARAMETERS: acpi_pkg_callback |
| 225 | * |
| 226 | * RETURN: Status |
| 227 | * |
| 228 | * DESCRIPTION: Copy one package element to another package element |
| 229 | * |
| 230 | ******************************************************************************/ |
| 231 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 232 | static acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 233 | acpi_ut_copy_ielement_to_eelement(u8 object_type, |
| 234 | union acpi_operand_object *source_object, |
| 235 | union acpi_generic_state *state, |
| 236 | void *context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 238 | acpi_status status = AE_OK; |
| 239 | struct acpi_pkg_info *info = (struct acpi_pkg_info *)context; |
| 240 | acpi_size object_space; |
| 241 | u32 this_index; |
| 242 | union acpi_object *target_object; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 244 | ACPI_FUNCTION_ENTRY(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 246 | this_index = state->pkg.index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | target_object = (union acpi_object *) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 248 | &((union acpi_object *)(state->pkg.dest_object))->package. |
| 249 | elements[this_index]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | |
| 251 | switch (object_type) { |
| 252 | case ACPI_COPY_TYPE_SIMPLE: |
| 253 | |
| 254 | /* |
| 255 | * This is a simple or null object |
| 256 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 257 | status = acpi_ut_copy_isimple_to_esimple(source_object, |
| 258 | target_object, |
| 259 | info->free_space, |
| 260 | &object_space); |
| 261 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | return (status); |
| 263 | } |
| 264 | break; |
| 265 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | case ACPI_COPY_TYPE_PACKAGE: |
| 267 | |
| 268 | /* |
| 269 | * Build the package object |
| 270 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 271 | target_object->type = ACPI_TYPE_PACKAGE; |
| 272 | target_object->package.count = source_object->package.count; |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 273 | target_object->package.elements = |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 274 | ACPI_CAST_PTR(union acpi_object, info->free_space); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | |
| 276 | /* |
| 277 | * Pass the new package object back to the package walk routine |
| 278 | */ |
| 279 | state->pkg.this_target_obj = target_object; |
| 280 | |
| 281 | /* |
| 282 | * Save space for the array of objects (Package elements) |
| 283 | * update the buffer length counter |
| 284 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 285 | object_space = ACPI_ROUND_UP_TO_NATIVE_WORD((acpi_size) |
| 286 | target_object-> |
| 287 | package.count * |
| 288 | sizeof(union |
| 289 | acpi_object)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | break; |
| 291 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | default: |
| 293 | return (AE_BAD_PARAMETER); |
| 294 | } |
| 295 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 296 | info->free_space += object_space; |
| 297 | info->length += object_space; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | return (status); |
| 299 | } |
| 300 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | /******************************************************************************* |
| 302 | * |
| 303 | * FUNCTION: acpi_ut_copy_ipackage_to_epackage |
| 304 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 305 | * PARAMETERS: internal_object - Pointer to the object we are returning |
| 306 | * Buffer - Where the object is returned |
| 307 | * space_used - Where the object length is returned |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | * |
| 309 | * RETURN: Status |
| 310 | * |
| 311 | * DESCRIPTION: This function is called to place a package object in a user |
| 312 | * buffer. A package object by definition contains other objects. |
| 313 | * |
| 314 | * The buffer is assumed to have sufficient space for the object. |
| 315 | * The caller must have verified the buffer length needed using the |
| 316 | * acpi_ut_get_object_size function before calling this function. |
| 317 | * |
| 318 | ******************************************************************************/ |
| 319 | |
| 320 | static acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 321 | acpi_ut_copy_ipackage_to_epackage(union acpi_operand_object *internal_object, |
| 322 | u8 * buffer, acpi_size * space_used) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 324 | union acpi_object *external_object; |
| 325 | acpi_status status; |
| 326 | struct acpi_pkg_info info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 328 | ACPI_FUNCTION_TRACE("ut_copy_ipackage_to_epackage"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | |
| 330 | /* |
| 331 | * First package at head of the buffer |
| 332 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 333 | external_object = ACPI_CAST_PTR(union acpi_object, buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | |
| 335 | /* |
| 336 | * Free space begins right after the first package |
| 337 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 338 | info.length = ACPI_ROUND_UP_TO_NATIVE_WORD(sizeof(union acpi_object)); |
| 339 | info.free_space = |
| 340 | buffer + ACPI_ROUND_UP_TO_NATIVE_WORD(sizeof(union acpi_object)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | info.object_space = 0; |
| 342 | info.num_packages = 1; |
| 343 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 344 | external_object->type = ACPI_GET_OBJECT_TYPE(internal_object); |
| 345 | external_object->package.count = internal_object->package.count; |
| 346 | external_object->package.elements = ACPI_CAST_PTR(union acpi_object, |
| 347 | info.free_space); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | |
| 349 | /* |
| 350 | * Leave room for an array of ACPI_OBJECTS in the buffer |
| 351 | * and move the free space past it |
| 352 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 353 | info.length += (acpi_size) external_object->package.count * |
| 354 | ACPI_ROUND_UP_TO_NATIVE_WORD(sizeof(union acpi_object)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | info.free_space += external_object->package.count * |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 356 | ACPI_ROUND_UP_TO_NATIVE_WORD(sizeof(union acpi_object)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 358 | status = acpi_ut_walk_package_tree(internal_object, external_object, |
| 359 | acpi_ut_copy_ielement_to_eelement, |
| 360 | &info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | |
| 362 | *space_used = info.length; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 363 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | } |
| 365 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | /******************************************************************************* |
| 367 | * |
| 368 | * FUNCTION: acpi_ut_copy_iobject_to_eobject |
| 369 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 370 | * PARAMETERS: internal_object - The internal object to be converted |
| 371 | * buffer_ptr - Where the object is returned |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | * |
| 373 | * RETURN: Status |
| 374 | * |
| 375 | * DESCRIPTION: This function is called to build an API object to be returned to |
| 376 | * the caller. |
| 377 | * |
| 378 | ******************************************************************************/ |
| 379 | |
| 380 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 381 | acpi_ut_copy_iobject_to_eobject(union acpi_operand_object *internal_object, |
| 382 | struct acpi_buffer *ret_buffer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 384 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 386 | ACPI_FUNCTION_TRACE("ut_copy_iobject_to_eobject"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 388 | if (ACPI_GET_OBJECT_TYPE(internal_object) == ACPI_TYPE_PACKAGE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | /* |
| 390 | * Package object: Copy all subobjects (including |
| 391 | * nested packages) |
| 392 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 393 | status = acpi_ut_copy_ipackage_to_epackage(internal_object, |
| 394 | ret_buffer->pointer, |
| 395 | &ret_buffer->length); |
| 396 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | /* |
| 398 | * Build a simple object (no nested objects) |
| 399 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 400 | status = acpi_ut_copy_isimple_to_esimple(internal_object, |
| 401 | (union acpi_object *) |
| 402 | ret_buffer->pointer, |
| 403 | ((u8 *) ret_buffer-> |
| 404 | pointer + |
| 405 | ACPI_ROUND_UP_TO_NATIVE_WORD |
| 406 | (sizeof |
| 407 | (union |
| 408 | acpi_object))), |
| 409 | &ret_buffer->length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | /* |
| 411 | * build simple does not include the object size in the length |
| 412 | * so we add it in here |
| 413 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 414 | ret_buffer->length += sizeof(union acpi_object); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | } |
| 416 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 417 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | } |
| 419 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | /******************************************************************************* |
| 421 | * |
| 422 | * FUNCTION: acpi_ut_copy_esimple_to_isimple |
| 423 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 424 | * PARAMETERS: external_object - The external object to be converted |
| 425 | * ret_internal_object - Where the internal object is returned |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | * |
| 427 | * RETURN: Status |
| 428 | * |
| 429 | * DESCRIPTION: This function copies an external object to an internal one. |
| 430 | * NOTE: Pointers can be copied, we don't need to copy data. |
| 431 | * (The pointers have to be valid in our address space no matter |
| 432 | * what we do with them!) |
| 433 | * |
| 434 | ******************************************************************************/ |
| 435 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 436 | static acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 437 | acpi_ut_copy_esimple_to_isimple(union acpi_object *external_object, |
| 438 | union acpi_operand_object **ret_internal_object) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 440 | union acpi_operand_object *internal_object; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 442 | ACPI_FUNCTION_TRACE("ut_copy_esimple_to_isimple"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | |
| 444 | /* |
| 445 | * Simple types supported are: String, Buffer, Integer |
| 446 | */ |
| 447 | switch (external_object->type) { |
| 448 | case ACPI_TYPE_STRING: |
| 449 | case ACPI_TYPE_BUFFER: |
| 450 | case ACPI_TYPE_INTEGER: |
| 451 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 452 | internal_object = acpi_ut_create_internal_object((u8) |
| 453 | external_object-> |
| 454 | type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | if (!internal_object) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 456 | return_ACPI_STATUS(AE_NO_MEMORY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | } |
| 458 | break; |
| 459 | |
| 460 | default: |
| 461 | /* All other types are not supported */ |
| 462 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 463 | return_ACPI_STATUS(AE_SUPPORT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | } |
| 465 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | /* Must COPY string and buffer contents */ |
| 467 | |
| 468 | switch (external_object->type) { |
| 469 | case ACPI_TYPE_STRING: |
| 470 | |
| 471 | internal_object->string.pointer = |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 472 | ACPI_MEM_CALLOCATE((acpi_size) external_object->string. |
| 473 | length + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | if (!internal_object->string.pointer) { |
| 475 | goto error_exit; |
| 476 | } |
| 477 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 478 | ACPI_MEMCPY(internal_object->string.pointer, |
| 479 | external_object->string.pointer, |
| 480 | external_object->string.length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | |
| 482 | internal_object->string.length = external_object->string.length; |
| 483 | break; |
| 484 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | case ACPI_TYPE_BUFFER: |
| 486 | |
| 487 | internal_object->buffer.pointer = |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 488 | ACPI_MEM_CALLOCATE(external_object->buffer.length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | if (!internal_object->buffer.pointer) { |
| 490 | goto error_exit; |
| 491 | } |
| 492 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 493 | ACPI_MEMCPY(internal_object->buffer.pointer, |
| 494 | external_object->buffer.pointer, |
| 495 | external_object->buffer.length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | |
| 497 | internal_object->buffer.length = external_object->buffer.length; |
| 498 | break; |
| 499 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | case ACPI_TYPE_INTEGER: |
| 501 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 502 | internal_object->integer.value = external_object->integer.value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | break; |
| 504 | |
| 505 | default: |
| 506 | /* Other types can't get here */ |
| 507 | break; |
| 508 | } |
| 509 | |
| 510 | *ret_internal_object = internal_object; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 511 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 513 | error_exit: |
| 514 | acpi_ut_remove_reference(internal_object); |
| 515 | return_ACPI_STATUS(AE_NO_MEMORY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | } |
| 517 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | #ifdef ACPI_FUTURE_IMPLEMENTATION |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | /* Code to convert packages that are parameters to control methods */ |
| 520 | |
| 521 | /******************************************************************************* |
| 522 | * |
| 523 | * FUNCTION: acpi_ut_copy_epackage_to_ipackage |
| 524 | * |
| 525 | * PARAMETERS: *internal_object - Pointer to the object we are returning |
| 526 | * *Buffer - Where the object is returned |
| 527 | * *space_used - Where the length of the object is returned |
| 528 | * |
| 529 | * RETURN: Status |
| 530 | * |
| 531 | * DESCRIPTION: This function is called to place a package object in a user |
| 532 | * buffer. A package object by definition contains other objects. |
| 533 | * |
| 534 | * The buffer is assumed to have sufficient space for the object. |
| 535 | * The caller must have verified the buffer length needed using the |
| 536 | * acpi_ut_get_object_size function before calling this function. |
| 537 | * |
| 538 | ******************************************************************************/ |
| 539 | |
| 540 | static acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 541 | acpi_ut_copy_epackage_to_ipackage(union acpi_operand_object *internal_object, |
| 542 | u8 * buffer, u32 * space_used) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 544 | u8 *free_space; |
| 545 | union acpi_object *external_object; |
| 546 | u32 length = 0; |
| 547 | u32 this_index; |
| 548 | u32 object_space = 0; |
| 549 | union acpi_operand_object *this_internal_obj; |
| 550 | union acpi_object *this_external_obj; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 552 | ACPI_FUNCTION_TRACE("ut_copy_epackage_to_ipackage"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | |
| 554 | /* |
| 555 | * First package at head of the buffer |
| 556 | */ |
| 557 | external_object = (union acpi_object *)buffer; |
| 558 | |
| 559 | /* |
| 560 | * Free space begins right after the first package |
| 561 | */ |
| 562 | free_space = buffer + sizeof(union acpi_object); |
| 563 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 564 | external_object->type = ACPI_GET_OBJECT_TYPE(internal_object); |
| 565 | external_object->package.count = internal_object->package.count; |
| 566 | external_object->package.elements = (union acpi_object *)free_space; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | |
| 568 | /* |
| 569 | * Build an array of ACPI_OBJECTS in the buffer |
| 570 | * and move the free space past it |
| 571 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 572 | free_space += |
| 573 | external_object->package.count * sizeof(union acpi_object); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | |
| 575 | /* Call walk_package */ |
| 576 | |
| 577 | } |
| 578 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 579 | #endif /* Future implementation */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | |
| 581 | /******************************************************************************* |
| 582 | * |
| 583 | * FUNCTION: acpi_ut_copy_eobject_to_iobject |
| 584 | * |
| 585 | * PARAMETERS: *internal_object - The external object to be converted |
| 586 | * *buffer_ptr - Where the internal object is returned |
| 587 | * |
| 588 | * RETURN: Status - the status of the call |
| 589 | * |
| 590 | * DESCRIPTION: Converts an external object to an internal object. |
| 591 | * |
| 592 | ******************************************************************************/ |
| 593 | |
| 594 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 595 | acpi_ut_copy_eobject_to_iobject(union acpi_object *external_object, |
| 596 | union acpi_operand_object **internal_object) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 598 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 600 | ACPI_FUNCTION_TRACE("ut_copy_eobject_to_iobject"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | |
| 602 | if (external_object->type == ACPI_TYPE_PACKAGE) { |
| 603 | /* |
| 604 | * Packages as external input to control methods are not supported, |
| 605 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 606 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
| 607 | "Packages as parameters not implemented!\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 609 | return_ACPI_STATUS(AE_NOT_IMPLEMENTED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | } |
| 611 | |
| 612 | else { |
| 613 | /* |
| 614 | * Build a simple object (no nested objects) |
| 615 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 616 | status = |
| 617 | acpi_ut_copy_esimple_to_isimple(external_object, |
| 618 | internal_object); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | } |
| 620 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 621 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | } |
| 623 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | /******************************************************************************* |
| 625 | * |
| 626 | * FUNCTION: acpi_ut_copy_simple_object |
| 627 | * |
| 628 | * PARAMETERS: source_desc - The internal object to be copied |
| 629 | * dest_desc - New target object |
| 630 | * |
| 631 | * RETURN: Status |
| 632 | * |
| 633 | * DESCRIPTION: Simple copy of one internal object to another. Reference count |
| 634 | * of the destination object is preserved. |
| 635 | * |
| 636 | ******************************************************************************/ |
| 637 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 638 | static acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 639 | acpi_ut_copy_simple_object(union acpi_operand_object *source_desc, |
| 640 | union acpi_operand_object *dest_desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 642 | u16 reference_count; |
| 643 | union acpi_operand_object *next_object; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | |
| 645 | /* Save fields from destination that we don't want to overwrite */ |
| 646 | |
| 647 | reference_count = dest_desc->common.reference_count; |
| 648 | next_object = dest_desc->common.next_object; |
| 649 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 650 | /* Copy the entire source object over the destination object */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 652 | ACPI_MEMCPY((char *)dest_desc, (char *)source_desc, |
| 653 | sizeof(union acpi_operand_object)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | |
| 655 | /* Restore the saved fields */ |
| 656 | |
| 657 | dest_desc->common.reference_count = reference_count; |
| 658 | dest_desc->common.next_object = next_object; |
| 659 | |
Robert Moore | 6f42ccf | 2005-05-13 00:00:00 -0400 | [diff] [blame] | 660 | /* New object is not static, regardless of source */ |
| 661 | |
| 662 | dest_desc->common.flags &= ~AOPOBJ_STATIC_POINTER; |
| 663 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | /* Handle the objects with extra data */ |
| 665 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 666 | switch (ACPI_GET_OBJECT_TYPE(dest_desc)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | case ACPI_TYPE_BUFFER: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | /* |
| 669 | * Allocate and copy the actual buffer if and only if: |
| 670 | * 1) There is a valid buffer pointer |
Robert Moore | 6f42ccf | 2005-05-13 00:00:00 -0400 | [diff] [blame] | 671 | * 2) The buffer has a length > 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | */ |
| 673 | if ((source_desc->buffer.pointer) && |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 674 | (source_desc->buffer.length)) { |
Robert Moore | 6f42ccf | 2005-05-13 00:00:00 -0400 | [diff] [blame] | 675 | dest_desc->buffer.pointer = |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 676 | ACPI_MEM_ALLOCATE(source_desc->buffer.length); |
Robert Moore | 6f42ccf | 2005-05-13 00:00:00 -0400 | [diff] [blame] | 677 | if (!dest_desc->buffer.pointer) { |
| 678 | return (AE_NO_MEMORY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | } |
Robert Moore | 6f42ccf | 2005-05-13 00:00:00 -0400 | [diff] [blame] | 680 | |
| 681 | /* Copy the actual buffer data */ |
| 682 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 683 | ACPI_MEMCPY(dest_desc->buffer.pointer, |
| 684 | source_desc->buffer.pointer, |
| 685 | source_desc->buffer.length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | } |
| 687 | break; |
| 688 | |
| 689 | case ACPI_TYPE_STRING: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | /* |
| 691 | * Allocate and copy the actual string if and only if: |
| 692 | * 1) There is a valid string pointer |
Robert Moore | 6f42ccf | 2005-05-13 00:00:00 -0400 | [diff] [blame] | 693 | * (Pointer to a NULL string is allowed) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | */ |
Robert Moore | 6f42ccf | 2005-05-13 00:00:00 -0400 | [diff] [blame] | 695 | if (source_desc->string.pointer) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | dest_desc->string.pointer = |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 697 | ACPI_MEM_ALLOCATE((acpi_size) source_desc->string. |
| 698 | length + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | if (!dest_desc->string.pointer) { |
| 700 | return (AE_NO_MEMORY); |
| 701 | } |
| 702 | |
Robert Moore | 6f42ccf | 2005-05-13 00:00:00 -0400 | [diff] [blame] | 703 | /* Copy the actual string data */ |
| 704 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 705 | ACPI_MEMCPY(dest_desc->string.pointer, |
| 706 | source_desc->string.pointer, |
| 707 | (acpi_size) source_desc->string.length + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | } |
| 709 | break; |
| 710 | |
| 711 | case ACPI_TYPE_LOCAL_REFERENCE: |
| 712 | /* |
| 713 | * We copied the reference object, so we now must add a reference |
| 714 | * to the object pointed to by the reference |
| 715 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 716 | acpi_ut_add_reference(source_desc->reference.object); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | break; |
| 718 | |
| 719 | default: |
| 720 | /* Nothing to do for other simple objects */ |
| 721 | break; |
| 722 | } |
| 723 | |
| 724 | return (AE_OK); |
| 725 | } |
| 726 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | /******************************************************************************* |
| 728 | * |
| 729 | * FUNCTION: acpi_ut_copy_ielement_to_ielement |
| 730 | * |
| 731 | * PARAMETERS: acpi_pkg_callback |
| 732 | * |
| 733 | * RETURN: Status |
| 734 | * |
| 735 | * DESCRIPTION: Copy one package element to another package element |
| 736 | * |
| 737 | ******************************************************************************/ |
| 738 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 739 | static acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 740 | acpi_ut_copy_ielement_to_ielement(u8 object_type, |
| 741 | union acpi_operand_object *source_object, |
| 742 | union acpi_generic_state *state, |
| 743 | void *context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 744 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 745 | acpi_status status = AE_OK; |
| 746 | u32 this_index; |
| 747 | union acpi_operand_object **this_target_ptr; |
| 748 | union acpi_operand_object *target_object; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 750 | ACPI_FUNCTION_ENTRY(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 752 | this_index = state->pkg.index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | this_target_ptr = (union acpi_operand_object **) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 754 | &state->pkg.dest_object->package.elements[this_index]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | |
| 756 | switch (object_type) { |
| 757 | case ACPI_COPY_TYPE_SIMPLE: |
| 758 | |
| 759 | /* A null source object indicates a (legal) null package element */ |
| 760 | |
| 761 | if (source_object) { |
| 762 | /* |
| 763 | * This is a simple object, just copy it |
| 764 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 765 | target_object = |
| 766 | acpi_ut_create_internal_object(ACPI_GET_OBJECT_TYPE |
| 767 | (source_object)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | if (!target_object) { |
| 769 | return (AE_NO_MEMORY); |
| 770 | } |
| 771 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 772 | status = |
| 773 | acpi_ut_copy_simple_object(source_object, |
| 774 | target_object); |
| 775 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | goto error_exit; |
| 777 | } |
| 778 | |
| 779 | *this_target_ptr = target_object; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 780 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | /* Pass through a null element */ |
| 782 | |
| 783 | *this_target_ptr = NULL; |
| 784 | } |
| 785 | break; |
| 786 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | case ACPI_COPY_TYPE_PACKAGE: |
| 788 | |
| 789 | /* |
| 790 | * This object is a package - go down another nesting level |
| 791 | * Create and build the package object |
| 792 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 793 | target_object = |
| 794 | acpi_ut_create_internal_object(ACPI_TYPE_PACKAGE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | if (!target_object) { |
| 796 | return (AE_NO_MEMORY); |
| 797 | } |
| 798 | |
| 799 | target_object->package.count = source_object->package.count; |
| 800 | target_object->common.flags = source_object->common.flags; |
| 801 | |
| 802 | /* |
| 803 | * Create the object array |
| 804 | */ |
| 805 | target_object->package.elements = |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 806 | ACPI_MEM_CALLOCATE(((acpi_size) source_object->package. |
| 807 | count + 1) * sizeof(void *)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | if (!target_object->package.elements) { |
| 809 | status = AE_NO_MEMORY; |
| 810 | goto error_exit; |
| 811 | } |
| 812 | |
| 813 | /* |
| 814 | * Pass the new package object back to the package walk routine |
| 815 | */ |
| 816 | state->pkg.this_target_obj = target_object; |
| 817 | |
| 818 | /* |
| 819 | * Store the object pointer in the parent package object |
| 820 | */ |
| 821 | *this_target_ptr = target_object; |
| 822 | break; |
| 823 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | default: |
| 825 | return (AE_BAD_PARAMETER); |
| 826 | } |
| 827 | |
| 828 | return (status); |
| 829 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 830 | error_exit: |
| 831 | acpi_ut_remove_reference(target_object); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | return (status); |
| 833 | } |
| 834 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | /******************************************************************************* |
| 836 | * |
| 837 | * FUNCTION: acpi_ut_copy_ipackage_to_ipackage |
| 838 | * |
| 839 | * PARAMETERS: *source_obj - Pointer to the source package object |
| 840 | * *dest_obj - Where the internal object is returned |
| 841 | * |
| 842 | * RETURN: Status - the status of the call |
| 843 | * |
| 844 | * DESCRIPTION: This function is called to copy an internal package object |
| 845 | * into another internal package object. |
| 846 | * |
| 847 | ******************************************************************************/ |
| 848 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 849 | static acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 850 | acpi_ut_copy_ipackage_to_ipackage(union acpi_operand_object *source_obj, |
| 851 | union acpi_operand_object *dest_obj, |
| 852 | struct acpi_walk_state *walk_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 854 | acpi_status status = AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 855 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 856 | ACPI_FUNCTION_TRACE("ut_copy_ipackage_to_ipackage"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 858 | dest_obj->common.type = ACPI_GET_OBJECT_TYPE(source_obj); |
| 859 | dest_obj->common.flags = source_obj->common.flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | dest_obj->package.count = source_obj->package.count; |
| 861 | |
| 862 | /* |
| 863 | * Create the object array and walk the source package tree |
| 864 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 865 | dest_obj->package.elements = ACPI_MEM_CALLOCATE(((acpi_size) |
| 866 | source_obj->package. |
| 867 | count + |
| 868 | 1) * sizeof(void *)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | if (!dest_obj->package.elements) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 870 | ACPI_REPORT_ERROR(("aml_build_copy_internal_package_object: Package allocation failure\n")); |
| 871 | return_ACPI_STATUS(AE_NO_MEMORY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | } |
| 873 | |
| 874 | /* |
| 875 | * Copy the package element-by-element by walking the package "tree". |
| 876 | * This handles nested packages of arbitrary depth. |
| 877 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 878 | status = acpi_ut_walk_package_tree(source_obj, dest_obj, |
| 879 | acpi_ut_copy_ielement_to_ielement, |
| 880 | walk_state); |
| 881 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | /* On failure, delete the destination package object */ |
| 883 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 884 | acpi_ut_remove_reference(dest_obj); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 885 | } |
| 886 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 887 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | } |
| 889 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 | /******************************************************************************* |
| 891 | * |
| 892 | * FUNCTION: acpi_ut_copy_iobject_to_iobject |
| 893 | * |
| 894 | * PARAMETERS: walk_state - Current walk state |
| 895 | * source_desc - The internal object to be copied |
| 896 | * dest_desc - Where the copied object is returned |
| 897 | * |
| 898 | * RETURN: Status |
| 899 | * |
| 900 | * DESCRIPTION: Copy an internal object to a new internal object |
| 901 | * |
| 902 | ******************************************************************************/ |
| 903 | |
| 904 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 905 | acpi_ut_copy_iobject_to_iobject(union acpi_operand_object *source_desc, |
| 906 | union acpi_operand_object **dest_desc, |
| 907 | struct acpi_walk_state *walk_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 909 | acpi_status status = AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 910 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 911 | ACPI_FUNCTION_TRACE("ut_copy_iobject_to_iobject"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | |
| 913 | /* Create the top level object */ |
| 914 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 915 | *dest_desc = |
| 916 | acpi_ut_create_internal_object(ACPI_GET_OBJECT_TYPE(source_desc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 917 | if (!*dest_desc) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 918 | return_ACPI_STATUS(AE_NO_MEMORY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | } |
| 920 | |
| 921 | /* Copy the object and possible subobjects */ |
| 922 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 923 | if (ACPI_GET_OBJECT_TYPE(source_desc) == ACPI_TYPE_PACKAGE) { |
| 924 | status = |
| 925 | acpi_ut_copy_ipackage_to_ipackage(source_desc, *dest_desc, |
| 926 | walk_state); |
| 927 | } else { |
| 928 | status = acpi_ut_copy_simple_object(source_desc, *dest_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | } |
| 930 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 931 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | } |