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