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