utcopy.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930
  1. /******************************************************************************
  2. *
  3. * Module Name: utcopy - Internal to external object translation utilities
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2005, R. Byron Moore
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions, and the following disclaimer,
  15. * without modification.
  16. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  17. * substantially similar to the "NO WARRANTY" disclaimer below
  18. * ("Disclaimer") and any redistribution must be conditioned upon
  19. * including a substantially similar Disclaimer requirement for further
  20. * binary redistribution.
  21. * 3. Neither the names of the above-listed copyright holders nor the names
  22. * of any contributors may be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * Alternatively, this software may be distributed under the terms of the
  26. * GNU General Public License ("GPL") version 2 as published by the Free
  27. * Software Foundation.
  28. *
  29. * NO WARRANTY
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  31. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  32. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  33. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  34. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  35. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  36. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  37. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  38. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  39. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  40. * POSSIBILITY OF SUCH DAMAGES.
  41. */
  42. #include <acpi/acpi.h>
  43. #include <acpi/amlcode.h>
  44. #define _COMPONENT ACPI_UTILITIES
  45. ACPI_MODULE_NAME ("utcopy")
  46. /*******************************************************************************
  47. *
  48. * FUNCTION: acpi_ut_copy_isimple_to_esimple
  49. *
  50. * PARAMETERS: *internal_object - Pointer to the object we are examining
  51. * *Buffer - Where the object is returned
  52. * *space_used - Where the data length is returned
  53. *
  54. * RETURN: Status
  55. *
  56. * DESCRIPTION: This function is called to place a simple object in a user
  57. * buffer.
  58. *
  59. * The buffer is assumed to have sufficient space for the object.
  60. *
  61. ******************************************************************************/
  62. static acpi_status
  63. acpi_ut_copy_isimple_to_esimple (
  64. union acpi_operand_object *internal_object,
  65. union acpi_object *external_object,
  66. u8 *data_space,
  67. acpi_size *buffer_space_used)
  68. {
  69. acpi_status status = AE_OK;
  70. ACPI_FUNCTION_TRACE ("ut_copy_isimple_to_esimple");
  71. *buffer_space_used = 0;
  72. /*
  73. * Check for NULL object case (could be an uninitialized
  74. * package element)
  75. */
  76. if (!internal_object) {
  77. return_ACPI_STATUS (AE_OK);
  78. }
  79. /* Always clear the external object */
  80. ACPI_MEMSET (external_object, 0, sizeof (union acpi_object));
  81. /*
  82. * In general, the external object will be the same type as
  83. * the internal object
  84. */
  85. external_object->type = ACPI_GET_OBJECT_TYPE (internal_object);
  86. /* However, only a limited number of external types are supported */
  87. switch (ACPI_GET_OBJECT_TYPE (internal_object)) {
  88. case ACPI_TYPE_STRING:
  89. external_object->string.pointer = (char *) data_space;
  90. external_object->string.length = internal_object->string.length;
  91. *buffer_space_used = ACPI_ROUND_UP_TO_NATIVE_WORD ((acpi_size) internal_object->string.length + 1);
  92. ACPI_MEMCPY ((void *) data_space, (void *) internal_object->string.pointer,
  93. (acpi_size) internal_object->string.length + 1);
  94. break;
  95. case ACPI_TYPE_BUFFER:
  96. external_object->buffer.pointer = data_space;
  97. external_object->buffer.length = internal_object->buffer.length;
  98. *buffer_space_used = ACPI_ROUND_UP_TO_NATIVE_WORD (internal_object->string.length);
  99. ACPI_MEMCPY ((void *) data_space, (void *) internal_object->buffer.pointer,
  100. internal_object->buffer.length);
  101. break;
  102. case ACPI_TYPE_INTEGER:
  103. external_object->integer.value = internal_object->integer.value;
  104. break;
  105. case ACPI_TYPE_LOCAL_REFERENCE:
  106. /*
  107. * This is an object reference. Attempt to dereference it.
  108. */
  109. switch (internal_object->reference.opcode) {
  110. case AML_INT_NAMEPATH_OP:
  111. /* For namepath, return the object handle ("reference") */
  112. default:
  113. /*
  114. * Use the object type of "Any" to indicate a reference
  115. * to object containing a handle to an ACPI named object.
  116. */
  117. external_object->type = ACPI_TYPE_ANY;
  118. external_object->reference.handle = internal_object->reference.node;
  119. break;
  120. }
  121. break;
  122. case ACPI_TYPE_PROCESSOR:
  123. external_object->processor.proc_id = internal_object->processor.proc_id;
  124. external_object->processor.pblk_address = internal_object->processor.address;
  125. external_object->processor.pblk_length = internal_object->processor.length;
  126. break;
  127. case ACPI_TYPE_POWER:
  128. external_object->power_resource.system_level =
  129. internal_object->power_resource.system_level;
  130. external_object->power_resource.resource_order =
  131. internal_object->power_resource.resource_order;
  132. break;
  133. default:
  134. /*
  135. * There is no corresponding external object type
  136. */
  137. return_ACPI_STATUS (AE_SUPPORT);
  138. }
  139. return_ACPI_STATUS (status);
  140. }
  141. /*******************************************************************************
  142. *
  143. * FUNCTION: acpi_ut_copy_ielement_to_eelement
  144. *
  145. * PARAMETERS: acpi_pkg_callback
  146. *
  147. * RETURN: Status
  148. *
  149. * DESCRIPTION: Copy one package element to another package element
  150. *
  151. ******************************************************************************/
  152. acpi_status
  153. acpi_ut_copy_ielement_to_eelement (
  154. u8 object_type,
  155. union acpi_operand_object *source_object,
  156. union acpi_generic_state *state,
  157. void *context)
  158. {
  159. acpi_status status = AE_OK;
  160. struct acpi_pkg_info *info = (struct acpi_pkg_info *) context;
  161. acpi_size object_space;
  162. u32 this_index;
  163. union acpi_object *target_object;
  164. ACPI_FUNCTION_ENTRY ();
  165. this_index = state->pkg.index;
  166. target_object = (union acpi_object *)
  167. &((union acpi_object *)(state->pkg.dest_object))->package.elements[this_index];
  168. switch (object_type) {
  169. case ACPI_COPY_TYPE_SIMPLE:
  170. /*
  171. * This is a simple or null object
  172. */
  173. status = acpi_ut_copy_isimple_to_esimple (source_object,
  174. target_object, info->free_space, &object_space);
  175. if (ACPI_FAILURE (status)) {
  176. return (status);
  177. }
  178. break;
  179. case ACPI_COPY_TYPE_PACKAGE:
  180. /*
  181. * Build the package object
  182. */
  183. target_object->type = ACPI_TYPE_PACKAGE;
  184. target_object->package.count = source_object->package.count;
  185. target_object->package.elements = ACPI_CAST_PTR (union acpi_object, info->free_space);
  186. /*
  187. * Pass the new package object back to the package walk routine
  188. */
  189. state->pkg.this_target_obj = target_object;
  190. /*
  191. * Save space for the array of objects (Package elements)
  192. * update the buffer length counter
  193. */
  194. object_space = ACPI_ROUND_UP_TO_NATIVE_WORD (
  195. (acpi_size) target_object->package.count * sizeof (union acpi_object));
  196. break;
  197. default:
  198. return (AE_BAD_PARAMETER);
  199. }
  200. info->free_space += object_space;
  201. info->length += object_space;
  202. return (status);
  203. }
  204. /*******************************************************************************
  205. *
  206. * FUNCTION: acpi_ut_copy_ipackage_to_epackage
  207. *
  208. * PARAMETERS: *internal_object - Pointer to the object we are returning
  209. * *Buffer - Where the object is returned
  210. * *space_used - Where the object length is returned
  211. *
  212. * RETURN: Status
  213. *
  214. * DESCRIPTION: This function is called to place a package object in a user
  215. * buffer. A package object by definition contains other objects.
  216. *
  217. * The buffer is assumed to have sufficient space for the object.
  218. * The caller must have verified the buffer length needed using the
  219. * acpi_ut_get_object_size function before calling this function.
  220. *
  221. ******************************************************************************/
  222. static acpi_status
  223. acpi_ut_copy_ipackage_to_epackage (
  224. union acpi_operand_object *internal_object,
  225. u8 *buffer,
  226. acpi_size *space_used)
  227. {
  228. union acpi_object *external_object;
  229. acpi_status status;
  230. struct acpi_pkg_info info;
  231. ACPI_FUNCTION_TRACE ("ut_copy_ipackage_to_epackage");
  232. /*
  233. * First package at head of the buffer
  234. */
  235. external_object = ACPI_CAST_PTR (union acpi_object, buffer);
  236. /*
  237. * Free space begins right after the first package
  238. */
  239. info.length = ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (union acpi_object));
  240. info.free_space = buffer + ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (union acpi_object));
  241. info.object_space = 0;
  242. info.num_packages = 1;
  243. external_object->type = ACPI_GET_OBJECT_TYPE (internal_object);
  244. external_object->package.count = internal_object->package.count;
  245. external_object->package.elements = ACPI_CAST_PTR (union acpi_object, info.free_space);
  246. /*
  247. * Leave room for an array of ACPI_OBJECTS in the buffer
  248. * and move the free space past it
  249. */
  250. info.length += (acpi_size) external_object->package.count *
  251. ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (union acpi_object));
  252. info.free_space += external_object->package.count *
  253. ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (union acpi_object));
  254. status = acpi_ut_walk_package_tree (internal_object, external_object,
  255. acpi_ut_copy_ielement_to_eelement, &info);
  256. *space_used = info.length;
  257. return_ACPI_STATUS (status);
  258. }
  259. /*******************************************************************************
  260. *
  261. * FUNCTION: acpi_ut_copy_iobject_to_eobject
  262. *
  263. * PARAMETERS: *internal_object - The internal object to be converted
  264. * *buffer_ptr - Where the object is returned
  265. *
  266. * RETURN: Status
  267. *
  268. * DESCRIPTION: This function is called to build an API object to be returned to
  269. * the caller.
  270. *
  271. ******************************************************************************/
  272. acpi_status
  273. acpi_ut_copy_iobject_to_eobject (
  274. union acpi_operand_object *internal_object,
  275. struct acpi_buffer *ret_buffer)
  276. {
  277. acpi_status status;
  278. ACPI_FUNCTION_TRACE ("ut_copy_iobject_to_eobject");
  279. if (ACPI_GET_OBJECT_TYPE (internal_object) == ACPI_TYPE_PACKAGE) {
  280. /*
  281. * Package object: Copy all subobjects (including
  282. * nested packages)
  283. */
  284. status = acpi_ut_copy_ipackage_to_epackage (internal_object,
  285. ret_buffer->pointer, &ret_buffer->length);
  286. }
  287. else {
  288. /*
  289. * Build a simple object (no nested objects)
  290. */
  291. status = acpi_ut_copy_isimple_to_esimple (internal_object,
  292. (union acpi_object *) ret_buffer->pointer,
  293. ((u8 *) ret_buffer->pointer +
  294. ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (union acpi_object))),
  295. &ret_buffer->length);
  296. /*
  297. * build simple does not include the object size in the length
  298. * so we add it in here
  299. */
  300. ret_buffer->length += sizeof (union acpi_object);
  301. }
  302. return_ACPI_STATUS (status);
  303. }
  304. /*******************************************************************************
  305. *
  306. * FUNCTION: acpi_ut_copy_esimple_to_isimple
  307. *
  308. * PARAMETERS: *external_object - The external object to be converted
  309. * *internal_object - Where the internal object is returned
  310. *
  311. * RETURN: Status
  312. *
  313. * DESCRIPTION: This function copies an external object to an internal one.
  314. * NOTE: Pointers can be copied, we don't need to copy data.
  315. * (The pointers have to be valid in our address space no matter
  316. * what we do with them!)
  317. *
  318. ******************************************************************************/
  319. acpi_status
  320. acpi_ut_copy_esimple_to_isimple (
  321. union acpi_object *external_object,
  322. union acpi_operand_object **ret_internal_object)
  323. {
  324. union acpi_operand_object *internal_object;
  325. ACPI_FUNCTION_TRACE ("ut_copy_esimple_to_isimple");
  326. /*
  327. * Simple types supported are: String, Buffer, Integer
  328. */
  329. switch (external_object->type) {
  330. case ACPI_TYPE_STRING:
  331. case ACPI_TYPE_BUFFER:
  332. case ACPI_TYPE_INTEGER:
  333. internal_object = acpi_ut_create_internal_object ((u8) external_object->type);
  334. if (!internal_object) {
  335. return_ACPI_STATUS (AE_NO_MEMORY);
  336. }
  337. break;
  338. default:
  339. /* All other types are not supported */
  340. return_ACPI_STATUS (AE_SUPPORT);
  341. }
  342. /* Must COPY string and buffer contents */
  343. switch (external_object->type) {
  344. case ACPI_TYPE_STRING:
  345. internal_object->string.pointer =
  346. ACPI_MEM_CALLOCATE ((acpi_size) external_object->string.length + 1);
  347. if (!internal_object->string.pointer) {
  348. goto error_exit;
  349. }
  350. ACPI_MEMCPY (internal_object->string.pointer,
  351. external_object->string.pointer,
  352. external_object->string.length);
  353. internal_object->string.length = external_object->string.length;
  354. break;
  355. case ACPI_TYPE_BUFFER:
  356. internal_object->buffer.pointer =
  357. ACPI_MEM_CALLOCATE (external_object->buffer.length);
  358. if (!internal_object->buffer.pointer) {
  359. goto error_exit;
  360. }
  361. ACPI_MEMCPY (internal_object->buffer.pointer,
  362. external_object->buffer.pointer,
  363. external_object->buffer.length);
  364. internal_object->buffer.length = external_object->buffer.length;
  365. break;
  366. case ACPI_TYPE_INTEGER:
  367. internal_object->integer.value = external_object->integer.value;
  368. break;
  369. default:
  370. /* Other types can't get here */
  371. break;
  372. }
  373. *ret_internal_object = internal_object;
  374. return_ACPI_STATUS (AE_OK);
  375. error_exit:
  376. acpi_ut_remove_reference (internal_object);
  377. return_ACPI_STATUS (AE_NO_MEMORY);
  378. }
  379. #ifdef ACPI_FUTURE_IMPLEMENTATION
  380. /* Code to convert packages that are parameters to control methods */
  381. /*******************************************************************************
  382. *
  383. * FUNCTION: acpi_ut_copy_epackage_to_ipackage
  384. *
  385. * PARAMETERS: *internal_object - Pointer to the object we are returning
  386. * *Buffer - Where the object is returned
  387. * *space_used - Where the length of the object is returned
  388. *
  389. * RETURN: Status
  390. *
  391. * DESCRIPTION: This function is called to place a package object in a user
  392. * buffer. A package object by definition contains other objects.
  393. *
  394. * The buffer is assumed to have sufficient space for the object.
  395. * The caller must have verified the buffer length needed using the
  396. * acpi_ut_get_object_size function before calling this function.
  397. *
  398. ******************************************************************************/
  399. static acpi_status
  400. acpi_ut_copy_epackage_to_ipackage (
  401. union acpi_operand_object *internal_object,
  402. u8 *buffer,
  403. u32 *space_used)
  404. {
  405. u8 *free_space;
  406. union acpi_object *external_object;
  407. u32 length = 0;
  408. u32 this_index;
  409. u32 object_space = 0;
  410. union acpi_operand_object *this_internal_obj;
  411. union acpi_object *this_external_obj;
  412. ACPI_FUNCTION_TRACE ("ut_copy_epackage_to_ipackage");
  413. /*
  414. * First package at head of the buffer
  415. */
  416. external_object = (union acpi_object *)buffer;
  417. /*
  418. * Free space begins right after the first package
  419. */
  420. free_space = buffer + sizeof(union acpi_object);
  421. external_object->type = ACPI_GET_OBJECT_TYPE (internal_object);
  422. external_object->package.count = internal_object->package.count;
  423. external_object->package.elements = (union acpi_object *)free_space;
  424. /*
  425. * Build an array of ACPI_OBJECTS in the buffer
  426. * and move the free space past it
  427. */
  428. free_space += external_object->package.count * sizeof(union acpi_object);
  429. /* Call walk_package */
  430. }
  431. #endif /* Future implementation */
  432. /*******************************************************************************
  433. *
  434. * FUNCTION: acpi_ut_copy_eobject_to_iobject
  435. *
  436. * PARAMETERS: *internal_object - The external object to be converted
  437. * *buffer_ptr - Where the internal object is returned
  438. *
  439. * RETURN: Status - the status of the call
  440. *
  441. * DESCRIPTION: Converts an external object to an internal object.
  442. *
  443. ******************************************************************************/
  444. acpi_status
  445. acpi_ut_copy_eobject_to_iobject (
  446. union acpi_object *external_object,
  447. union acpi_operand_object **internal_object)
  448. {
  449. acpi_status status;
  450. ACPI_FUNCTION_TRACE ("ut_copy_eobject_to_iobject");
  451. if (external_object->type == ACPI_TYPE_PACKAGE) {
  452. /*
  453. * Packages as external input to control methods are not supported,
  454. */
  455. ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
  456. "Packages as parameters not implemented!\n"));
  457. return_ACPI_STATUS (AE_NOT_IMPLEMENTED);
  458. }
  459. else {
  460. /*
  461. * Build a simple object (no nested objects)
  462. */
  463. status = acpi_ut_copy_esimple_to_isimple (external_object, internal_object);
  464. }
  465. return_ACPI_STATUS (status);
  466. }
  467. /*******************************************************************************
  468. *
  469. * FUNCTION: acpi_ut_copy_simple_object
  470. *
  471. * PARAMETERS: source_desc - The internal object to be copied
  472. * dest_desc - New target object
  473. *
  474. * RETURN: Status
  475. *
  476. * DESCRIPTION: Simple copy of one internal object to another. Reference count
  477. * of the destination object is preserved.
  478. *
  479. ******************************************************************************/
  480. acpi_status
  481. acpi_ut_copy_simple_object (
  482. union acpi_operand_object *source_desc,
  483. union acpi_operand_object *dest_desc)
  484. {
  485. u16 reference_count;
  486. union acpi_operand_object *next_object;
  487. /* Save fields from destination that we don't want to overwrite */
  488. reference_count = dest_desc->common.reference_count;
  489. next_object = dest_desc->common.next_object;
  490. /* Copy the entire source object over the destination object*/
  491. ACPI_MEMCPY ((char *) dest_desc, (char *) source_desc,
  492. sizeof (union acpi_operand_object));
  493. /* Restore the saved fields */
  494. dest_desc->common.reference_count = reference_count;
  495. dest_desc->common.next_object = next_object;
  496. /* Handle the objects with extra data */
  497. switch (ACPI_GET_OBJECT_TYPE (dest_desc)) {
  498. case ACPI_TYPE_BUFFER:
  499. dest_desc->buffer.node = NULL;
  500. dest_desc->common.flags = source_desc->common.flags;
  501. /*
  502. * Allocate and copy the actual buffer if and only if:
  503. * 1) There is a valid buffer pointer
  504. * 2) The buffer is not static (not in an ACPI table) (in this case,
  505. * the actual pointer was already copied above)
  506. */
  507. if ((source_desc->buffer.pointer) &&
  508. (!(source_desc->common.flags & AOPOBJ_STATIC_POINTER))) {
  509. dest_desc->buffer.pointer = NULL;
  510. /* Create an actual buffer only if length > 0 */
  511. if (source_desc->buffer.length) {
  512. dest_desc->buffer.pointer =
  513. ACPI_MEM_ALLOCATE (source_desc->buffer.length);
  514. if (!dest_desc->buffer.pointer) {
  515. return (AE_NO_MEMORY);
  516. }
  517. /* Copy the actual buffer data */
  518. ACPI_MEMCPY (dest_desc->buffer.pointer,
  519. source_desc->buffer.pointer,
  520. source_desc->buffer.length);
  521. }
  522. }
  523. break;
  524. case ACPI_TYPE_STRING:
  525. /*
  526. * Allocate and copy the actual string if and only if:
  527. * 1) There is a valid string pointer
  528. * 2) The string is not static (not in an ACPI table) (in this case,
  529. * the actual pointer was already copied above)
  530. */
  531. if ((source_desc->string.pointer) &&
  532. (!(source_desc->common.flags & AOPOBJ_STATIC_POINTER))) {
  533. dest_desc->string.pointer =
  534. ACPI_MEM_ALLOCATE ((acpi_size) source_desc->string.length + 1);
  535. if (!dest_desc->string.pointer) {
  536. return (AE_NO_MEMORY);
  537. }
  538. ACPI_MEMCPY (dest_desc->string.pointer, source_desc->string.pointer,
  539. (acpi_size) source_desc->string.length + 1);
  540. }
  541. break;
  542. case ACPI_TYPE_LOCAL_REFERENCE:
  543. /*
  544. * We copied the reference object, so we now must add a reference
  545. * to the object pointed to by the reference
  546. */
  547. acpi_ut_add_reference (source_desc->reference.object);
  548. break;
  549. default:
  550. /* Nothing to do for other simple objects */
  551. break;
  552. }
  553. return (AE_OK);
  554. }
  555. /*******************************************************************************
  556. *
  557. * FUNCTION: acpi_ut_copy_ielement_to_ielement
  558. *
  559. * PARAMETERS: acpi_pkg_callback
  560. *
  561. * RETURN: Status
  562. *
  563. * DESCRIPTION: Copy one package element to another package element
  564. *
  565. ******************************************************************************/
  566. acpi_status
  567. acpi_ut_copy_ielement_to_ielement (
  568. u8 object_type,
  569. union acpi_operand_object *source_object,
  570. union acpi_generic_state *state,
  571. void *context)
  572. {
  573. acpi_status status = AE_OK;
  574. u32 this_index;
  575. union acpi_operand_object **this_target_ptr;
  576. union acpi_operand_object *target_object;
  577. ACPI_FUNCTION_ENTRY ();
  578. this_index = state->pkg.index;
  579. this_target_ptr = (union acpi_operand_object **)
  580. &state->pkg.dest_object->package.elements[this_index];
  581. switch (object_type) {
  582. case ACPI_COPY_TYPE_SIMPLE:
  583. /* A null source object indicates a (legal) null package element */
  584. if (source_object) {
  585. /*
  586. * This is a simple object, just copy it
  587. */
  588. target_object = acpi_ut_create_internal_object (
  589. ACPI_GET_OBJECT_TYPE (source_object));
  590. if (!target_object) {
  591. return (AE_NO_MEMORY);
  592. }
  593. status = acpi_ut_copy_simple_object (source_object, target_object);
  594. if (ACPI_FAILURE (status)) {
  595. goto error_exit;
  596. }
  597. *this_target_ptr = target_object;
  598. }
  599. else {
  600. /* Pass through a null element */
  601. *this_target_ptr = NULL;
  602. }
  603. break;
  604. case ACPI_COPY_TYPE_PACKAGE:
  605. /*
  606. * This object is a package - go down another nesting level
  607. * Create and build the package object
  608. */
  609. target_object = acpi_ut_create_internal_object (ACPI_TYPE_PACKAGE);
  610. if (!target_object) {
  611. return (AE_NO_MEMORY);
  612. }
  613. target_object->package.count = source_object->package.count;
  614. target_object->common.flags = source_object->common.flags;
  615. /*
  616. * Create the object array
  617. */
  618. target_object->package.elements =
  619. ACPI_MEM_CALLOCATE (((acpi_size) source_object->package.count + 1) *
  620. sizeof (void *));
  621. if (!target_object->package.elements) {
  622. status = AE_NO_MEMORY;
  623. goto error_exit;
  624. }
  625. /*
  626. * Pass the new package object back to the package walk routine
  627. */
  628. state->pkg.this_target_obj = target_object;
  629. /*
  630. * Store the object pointer in the parent package object
  631. */
  632. *this_target_ptr = target_object;
  633. break;
  634. default:
  635. return (AE_BAD_PARAMETER);
  636. }
  637. return (status);
  638. error_exit:
  639. acpi_ut_remove_reference (target_object);
  640. return (status);
  641. }
  642. /*******************************************************************************
  643. *
  644. * FUNCTION: acpi_ut_copy_ipackage_to_ipackage
  645. *
  646. * PARAMETERS: *source_obj - Pointer to the source package object
  647. * *dest_obj - Where the internal object is returned
  648. *
  649. * RETURN: Status - the status of the call
  650. *
  651. * DESCRIPTION: This function is called to copy an internal package object
  652. * into another internal package object.
  653. *
  654. ******************************************************************************/
  655. acpi_status
  656. acpi_ut_copy_ipackage_to_ipackage (
  657. union acpi_operand_object *source_obj,
  658. union acpi_operand_object *dest_obj,
  659. struct acpi_walk_state *walk_state)
  660. {
  661. acpi_status status = AE_OK;
  662. ACPI_FUNCTION_TRACE ("ut_copy_ipackage_to_ipackage");
  663. dest_obj->common.type = ACPI_GET_OBJECT_TYPE (source_obj);
  664. dest_obj->common.flags = source_obj->common.flags;
  665. dest_obj->package.count = source_obj->package.count;
  666. /*
  667. * Create the object array and walk the source package tree
  668. */
  669. dest_obj->package.elements = ACPI_MEM_CALLOCATE (
  670. ((acpi_size) source_obj->package.count + 1) *
  671. sizeof (void *));
  672. if (!dest_obj->package.elements) {
  673. ACPI_REPORT_ERROR (
  674. ("aml_build_copy_internal_package_object: Package allocation failure\n"));
  675. return_ACPI_STATUS (AE_NO_MEMORY);
  676. }
  677. /*
  678. * Copy the package element-by-element by walking the package "tree".
  679. * This handles nested packages of arbitrary depth.
  680. */
  681. status = acpi_ut_walk_package_tree (source_obj, dest_obj,
  682. acpi_ut_copy_ielement_to_ielement, walk_state);
  683. if (ACPI_FAILURE (status)) {
  684. /* On failure, delete the destination package object */
  685. acpi_ut_remove_reference (dest_obj);
  686. }
  687. return_ACPI_STATUS (status);
  688. }
  689. /*******************************************************************************
  690. *
  691. * FUNCTION: acpi_ut_copy_iobject_to_iobject
  692. *
  693. * PARAMETERS: walk_state - Current walk state
  694. * source_desc - The internal object to be copied
  695. * dest_desc - Where the copied object is returned
  696. *
  697. * RETURN: Status
  698. *
  699. * DESCRIPTION: Copy an internal object to a new internal object
  700. *
  701. ******************************************************************************/
  702. acpi_status
  703. acpi_ut_copy_iobject_to_iobject (
  704. union acpi_operand_object *source_desc,
  705. union acpi_operand_object **dest_desc,
  706. struct acpi_walk_state *walk_state)
  707. {
  708. acpi_status status = AE_OK;
  709. ACPI_FUNCTION_TRACE ("ut_copy_iobject_to_iobject");
  710. /* Create the top level object */
  711. *dest_desc = acpi_ut_create_internal_object (ACPI_GET_OBJECT_TYPE (source_desc));
  712. if (!*dest_desc) {
  713. return_ACPI_STATUS (AE_NO_MEMORY);
  714. }
  715. /* Copy the object and possible subobjects */
  716. if (ACPI_GET_OBJECT_TYPE (source_desc) == ACPI_TYPE_PACKAGE) {
  717. status = acpi_ut_copy_ipackage_to_ipackage (source_desc, *dest_desc,
  718. walk_state);
  719. }
  720. else {
  721. status = acpi_ut_copy_simple_object (source_desc, *dest_desc);
  722. }
  723. return_ACPI_STATUS (status);
  724. }