utcopy.c revision 1.1 1 1.1 jruoho /******************************************************************************
2 1.1 jruoho *
3 1.1 jruoho * Module Name: utcopy - Internal to external object translation utilities
4 1.1 jruoho *
5 1.1 jruoho *****************************************************************************/
6 1.1 jruoho
7 1.1 jruoho /******************************************************************************
8 1.1 jruoho *
9 1.1 jruoho * 1. Copyright Notice
10 1.1 jruoho *
11 1.1 jruoho * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
12 1.1 jruoho * All rights reserved.
13 1.1 jruoho *
14 1.1 jruoho * 2. License
15 1.1 jruoho *
16 1.1 jruoho * 2.1. This is your license from Intel Corp. under its intellectual property
17 1.1 jruoho * rights. You may have additional license terms from the party that provided
18 1.1 jruoho * you this software, covering your right to use that party's intellectual
19 1.1 jruoho * property rights.
20 1.1 jruoho *
21 1.1 jruoho * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 1.1 jruoho * copy of the source code appearing in this file ("Covered Code") an
23 1.1 jruoho * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 1.1 jruoho * base code distributed originally by Intel ("Original Intel Code") to copy,
25 1.1 jruoho * make derivatives, distribute, use and display any portion of the Covered
26 1.1 jruoho * Code in any form, with the right to sublicense such rights; and
27 1.1 jruoho *
28 1.1 jruoho * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 1.1 jruoho * license (with the right to sublicense), under only those claims of Intel
30 1.1 jruoho * patents that are infringed by the Original Intel Code, to make, use, sell,
31 1.1 jruoho * offer to sell, and import the Covered Code and derivative works thereof
32 1.1 jruoho * solely to the minimum extent necessary to exercise the above copyright
33 1.1 jruoho * license, and in no event shall the patent license extend to any additions
34 1.1 jruoho * to or modifications of the Original Intel Code. No other license or right
35 1.1 jruoho * is granted directly or by implication, estoppel or otherwise;
36 1.1 jruoho *
37 1.1 jruoho * The above copyright and patent license is granted only if the following
38 1.1 jruoho * conditions are met:
39 1.1 jruoho *
40 1.1 jruoho * 3. Conditions
41 1.1 jruoho *
42 1.1 jruoho * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 1.1 jruoho * Redistribution of source code of any substantial portion of the Covered
44 1.1 jruoho * Code or modification with rights to further distribute source must include
45 1.1 jruoho * the above Copyright Notice, the above License, this list of Conditions,
46 1.1 jruoho * and the following Disclaimer and Export Compliance provision. In addition,
47 1.1 jruoho * Licensee must cause all Covered Code to which Licensee contributes to
48 1.1 jruoho * contain a file documenting the changes Licensee made to create that Covered
49 1.1 jruoho * Code and the date of any change. Licensee must include in that file the
50 1.1 jruoho * documentation of any changes made by any predecessor Licensee. Licensee
51 1.1 jruoho * must include a prominent statement that the modification is derived,
52 1.1 jruoho * directly or indirectly, from Original Intel Code.
53 1.1 jruoho *
54 1.1 jruoho * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 1.1 jruoho * Redistribution of source code of any substantial portion of the Covered
56 1.1 jruoho * Code or modification without rights to further distribute source must
57 1.1 jruoho * include the following Disclaimer and Export Compliance provision in the
58 1.1 jruoho * documentation and/or other materials provided with distribution. In
59 1.1 jruoho * addition, Licensee may not authorize further sublicense of source of any
60 1.1 jruoho * portion of the Covered Code, and must include terms to the effect that the
61 1.1 jruoho * license from Licensee to its licensee is limited to the intellectual
62 1.1 jruoho * property embodied in the software Licensee provides to its licensee, and
63 1.1 jruoho * not to intellectual property embodied in modifications its licensee may
64 1.1 jruoho * make.
65 1.1 jruoho *
66 1.1 jruoho * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 1.1 jruoho * substantial portion of the Covered Code or modification must reproduce the
68 1.1 jruoho * above Copyright Notice, and the following Disclaimer and Export Compliance
69 1.1 jruoho * provision in the documentation and/or other materials provided with the
70 1.1 jruoho * distribution.
71 1.1 jruoho *
72 1.1 jruoho * 3.4. Intel retains all right, title, and interest in and to the Original
73 1.1 jruoho * Intel Code.
74 1.1 jruoho *
75 1.1 jruoho * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 1.1 jruoho * Intel shall be used in advertising or otherwise to promote the sale, use or
77 1.1 jruoho * other dealings in products derived from or relating to the Covered Code
78 1.1 jruoho * without prior written authorization from Intel.
79 1.1 jruoho *
80 1.1 jruoho * 4. Disclaimer and Export Compliance
81 1.1 jruoho *
82 1.1 jruoho * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 1.1 jruoho * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 1.1 jruoho * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 1.1 jruoho * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 1.1 jruoho * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 1.1 jruoho * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88 1.1 jruoho * PARTICULAR PURPOSE.
89 1.1 jruoho *
90 1.1 jruoho * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 1.1 jruoho * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 1.1 jruoho * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 1.1 jruoho * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 1.1 jruoho * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 1.1 jruoho * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 1.1 jruoho * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97 1.1 jruoho * LIMITED REMEDY.
98 1.1 jruoho *
99 1.1 jruoho * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 1.1 jruoho * software or system incorporating such software without first obtaining any
101 1.1 jruoho * required license or other approval from the U. S. Department of Commerce or
102 1.1 jruoho * any other agency or department of the United States Government. In the
103 1.1 jruoho * event Licensee exports any such software from the United States or
104 1.1 jruoho * re-exports any such software from a foreign destination, Licensee shall
105 1.1 jruoho * ensure that the distribution and export/re-export of the software is in
106 1.1 jruoho * compliance with all laws, regulations, orders, or other restrictions of the
107 1.1 jruoho * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 1.1 jruoho * any of its subsidiaries will export/re-export any technical data, process,
109 1.1 jruoho * software, or service, directly or indirectly, to any country for which the
110 1.1 jruoho * United States government or any agency thereof requires an export license,
111 1.1 jruoho * other governmental approval, or letter of assurance, without first obtaining
112 1.1 jruoho * such license, approval or letter.
113 1.1 jruoho *
114 1.1 jruoho *****************************************************************************/
115 1.1 jruoho
116 1.1 jruoho #define __UTCOPY_C__
117 1.1 jruoho
118 1.1 jruoho #include "acpi.h"
119 1.1 jruoho #include "accommon.h"
120 1.1 jruoho #include "acnamesp.h"
121 1.1 jruoho
122 1.1 jruoho
123 1.1 jruoho #define _COMPONENT ACPI_UTILITIES
124 1.1 jruoho ACPI_MODULE_NAME ("utcopy")
125 1.1 jruoho
126 1.1 jruoho /* Local prototypes */
127 1.1 jruoho
128 1.1 jruoho static ACPI_STATUS
129 1.1 jruoho AcpiUtCopyIsimpleToEsimple (
130 1.1 jruoho ACPI_OPERAND_OBJECT *InternalObject,
131 1.1 jruoho ACPI_OBJECT *ExternalObject,
132 1.1 jruoho UINT8 *DataSpace,
133 1.1 jruoho ACPI_SIZE *BufferSpaceUsed);
134 1.1 jruoho
135 1.1 jruoho static ACPI_STATUS
136 1.1 jruoho AcpiUtCopyIelementToIelement (
137 1.1 jruoho UINT8 ObjectType,
138 1.1 jruoho ACPI_OPERAND_OBJECT *SourceObject,
139 1.1 jruoho ACPI_GENERIC_STATE *State,
140 1.1 jruoho void *Context);
141 1.1 jruoho
142 1.1 jruoho static ACPI_STATUS
143 1.1 jruoho AcpiUtCopyIpackageToEpackage (
144 1.1 jruoho ACPI_OPERAND_OBJECT *InternalObject,
145 1.1 jruoho UINT8 *Buffer,
146 1.1 jruoho ACPI_SIZE *SpaceUsed);
147 1.1 jruoho
148 1.1 jruoho static ACPI_STATUS
149 1.1 jruoho AcpiUtCopyEsimpleToIsimple(
150 1.1 jruoho ACPI_OBJECT *UserObj,
151 1.1 jruoho ACPI_OPERAND_OBJECT **ReturnObj);
152 1.1 jruoho
153 1.1 jruoho static ACPI_STATUS
154 1.1 jruoho AcpiUtCopyEpackageToIpackage (
155 1.1 jruoho ACPI_OBJECT *ExternalObject,
156 1.1 jruoho ACPI_OPERAND_OBJECT **InternalObject);
157 1.1 jruoho
158 1.1 jruoho static ACPI_STATUS
159 1.1 jruoho AcpiUtCopySimpleObject (
160 1.1 jruoho ACPI_OPERAND_OBJECT *SourceDesc,
161 1.1 jruoho ACPI_OPERAND_OBJECT *DestDesc);
162 1.1 jruoho
163 1.1 jruoho static ACPI_STATUS
164 1.1 jruoho AcpiUtCopyIelementToEelement (
165 1.1 jruoho UINT8 ObjectType,
166 1.1 jruoho ACPI_OPERAND_OBJECT *SourceObject,
167 1.1 jruoho ACPI_GENERIC_STATE *State,
168 1.1 jruoho void *Context);
169 1.1 jruoho
170 1.1 jruoho static ACPI_STATUS
171 1.1 jruoho AcpiUtCopyIpackageToIpackage (
172 1.1 jruoho ACPI_OPERAND_OBJECT *SourceObj,
173 1.1 jruoho ACPI_OPERAND_OBJECT *DestObj,
174 1.1 jruoho ACPI_WALK_STATE *WalkState);
175 1.1 jruoho
176 1.1 jruoho
177 1.1 jruoho /*******************************************************************************
178 1.1 jruoho *
179 1.1 jruoho * FUNCTION: AcpiUtCopyIsimpleToEsimple
180 1.1 jruoho *
181 1.1 jruoho * PARAMETERS: InternalObject - Source object to be copied
182 1.1 jruoho * ExternalObject - Where to return the copied object
183 1.1 jruoho * DataSpace - Where object data is returned (such as
184 1.1 jruoho * buffer and string data)
185 1.1 jruoho * BufferSpaceUsed - Length of DataSpace that was used
186 1.1 jruoho *
187 1.1 jruoho * RETURN: Status
188 1.1 jruoho *
189 1.1 jruoho * DESCRIPTION: This function is called to copy a simple internal object to
190 1.1 jruoho * an external object.
191 1.1 jruoho *
192 1.1 jruoho * The DataSpace buffer is assumed to have sufficient space for
193 1.1 jruoho * the object.
194 1.1 jruoho *
195 1.1 jruoho ******************************************************************************/
196 1.1 jruoho
197 1.1 jruoho static ACPI_STATUS
198 1.1 jruoho AcpiUtCopyIsimpleToEsimple (
199 1.1 jruoho ACPI_OPERAND_OBJECT *InternalObject,
200 1.1 jruoho ACPI_OBJECT *ExternalObject,
201 1.1 jruoho UINT8 *DataSpace,
202 1.1 jruoho ACPI_SIZE *BufferSpaceUsed)
203 1.1 jruoho {
204 1.1 jruoho ACPI_STATUS Status = AE_OK;
205 1.1 jruoho
206 1.1 jruoho
207 1.1 jruoho ACPI_FUNCTION_TRACE (UtCopyIsimpleToEsimple);
208 1.1 jruoho
209 1.1 jruoho
210 1.1 jruoho *BufferSpaceUsed = 0;
211 1.1 jruoho
212 1.1 jruoho /*
213 1.1 jruoho * Check for NULL object case (could be an uninitialized
214 1.1 jruoho * package element)
215 1.1 jruoho */
216 1.1 jruoho if (!InternalObject)
217 1.1 jruoho {
218 1.1 jruoho return_ACPI_STATUS (AE_OK);
219 1.1 jruoho }
220 1.1 jruoho
221 1.1 jruoho /* Always clear the external object */
222 1.1 jruoho
223 1.1 jruoho ACPI_MEMSET (ExternalObject, 0, sizeof (ACPI_OBJECT));
224 1.1 jruoho
225 1.1 jruoho /*
226 1.1 jruoho * In general, the external object will be the same type as
227 1.1 jruoho * the internal object
228 1.1 jruoho */
229 1.1 jruoho ExternalObject->Type = InternalObject->Common.Type;
230 1.1 jruoho
231 1.1 jruoho /* However, only a limited number of external types are supported */
232 1.1 jruoho
233 1.1 jruoho switch (InternalObject->Common.Type)
234 1.1 jruoho {
235 1.1 jruoho case ACPI_TYPE_STRING:
236 1.1 jruoho
237 1.1 jruoho ExternalObject->String.Pointer = (char *) DataSpace;
238 1.1 jruoho ExternalObject->String.Length = InternalObject->String.Length;
239 1.1 jruoho *BufferSpaceUsed = ACPI_ROUND_UP_TO_NATIVE_WORD (
240 1.1 jruoho (ACPI_SIZE) InternalObject->String.Length + 1);
241 1.1 jruoho
242 1.1 jruoho ACPI_MEMCPY ((void *) DataSpace,
243 1.1 jruoho (void *) InternalObject->String.Pointer,
244 1.1 jruoho (ACPI_SIZE) InternalObject->String.Length + 1);
245 1.1 jruoho break;
246 1.1 jruoho
247 1.1 jruoho
248 1.1 jruoho case ACPI_TYPE_BUFFER:
249 1.1 jruoho
250 1.1 jruoho ExternalObject->Buffer.Pointer = DataSpace;
251 1.1 jruoho ExternalObject->Buffer.Length = InternalObject->Buffer.Length;
252 1.1 jruoho *BufferSpaceUsed = ACPI_ROUND_UP_TO_NATIVE_WORD (
253 1.1 jruoho InternalObject->String.Length);
254 1.1 jruoho
255 1.1 jruoho ACPI_MEMCPY ((void *) DataSpace,
256 1.1 jruoho (void *) InternalObject->Buffer.Pointer,
257 1.1 jruoho InternalObject->Buffer.Length);
258 1.1 jruoho break;
259 1.1 jruoho
260 1.1 jruoho
261 1.1 jruoho case ACPI_TYPE_INTEGER:
262 1.1 jruoho
263 1.1 jruoho ExternalObject->Integer.Value = InternalObject->Integer.Value;
264 1.1 jruoho break;
265 1.1 jruoho
266 1.1 jruoho
267 1.1 jruoho case ACPI_TYPE_LOCAL_REFERENCE:
268 1.1 jruoho
269 1.1 jruoho /* This is an object reference. */
270 1.1 jruoho
271 1.1 jruoho switch (InternalObject->Reference.Class)
272 1.1 jruoho {
273 1.1 jruoho case ACPI_REFCLASS_NAME:
274 1.1 jruoho
275 1.1 jruoho /*
276 1.1 jruoho * For namepath, return the object handle ("reference")
277 1.1 jruoho * We are referring to the namespace node
278 1.1 jruoho */
279 1.1 jruoho ExternalObject->Reference.Handle =
280 1.1 jruoho InternalObject->Reference.Node;
281 1.1 jruoho ExternalObject->Reference.ActualType =
282 1.1 jruoho AcpiNsGetType (InternalObject->Reference.Node);
283 1.1 jruoho break;
284 1.1 jruoho
285 1.1 jruoho default:
286 1.1 jruoho
287 1.1 jruoho /* All other reference types are unsupported */
288 1.1 jruoho
289 1.1 jruoho return_ACPI_STATUS (AE_TYPE);
290 1.1 jruoho }
291 1.1 jruoho break;
292 1.1 jruoho
293 1.1 jruoho
294 1.1 jruoho case ACPI_TYPE_PROCESSOR:
295 1.1 jruoho
296 1.1 jruoho ExternalObject->Processor.ProcId =
297 1.1 jruoho InternalObject->Processor.ProcId;
298 1.1 jruoho ExternalObject->Processor.PblkAddress =
299 1.1 jruoho InternalObject->Processor.Address;
300 1.1 jruoho ExternalObject->Processor.PblkLength =
301 1.1 jruoho InternalObject->Processor.Length;
302 1.1 jruoho break;
303 1.1 jruoho
304 1.1 jruoho
305 1.1 jruoho case ACPI_TYPE_POWER:
306 1.1 jruoho
307 1.1 jruoho ExternalObject->PowerResource.SystemLevel =
308 1.1 jruoho InternalObject->PowerResource.SystemLevel;
309 1.1 jruoho
310 1.1 jruoho ExternalObject->PowerResource.ResourceOrder =
311 1.1 jruoho InternalObject->PowerResource.ResourceOrder;
312 1.1 jruoho break;
313 1.1 jruoho
314 1.1 jruoho
315 1.1 jruoho default:
316 1.1 jruoho /*
317 1.1 jruoho * There is no corresponding external object type
318 1.1 jruoho */
319 1.1 jruoho ACPI_ERROR ((AE_INFO,
320 1.1 jruoho "Unsupported object type, cannot convert to external object: %s",
321 1.1 jruoho AcpiUtGetTypeName (InternalObject->Common.Type)));
322 1.1 jruoho
323 1.1 jruoho return_ACPI_STATUS (AE_SUPPORT);
324 1.1 jruoho }
325 1.1 jruoho
326 1.1 jruoho return_ACPI_STATUS (Status);
327 1.1 jruoho }
328 1.1 jruoho
329 1.1 jruoho
330 1.1 jruoho /*******************************************************************************
331 1.1 jruoho *
332 1.1 jruoho * FUNCTION: AcpiUtCopyIelementToEelement
333 1.1 jruoho *
334 1.1 jruoho * PARAMETERS: ACPI_PKG_CALLBACK
335 1.1 jruoho *
336 1.1 jruoho * RETURN: Status
337 1.1 jruoho *
338 1.1 jruoho * DESCRIPTION: Copy one package element to another package element
339 1.1 jruoho *
340 1.1 jruoho ******************************************************************************/
341 1.1 jruoho
342 1.1 jruoho static ACPI_STATUS
343 1.1 jruoho AcpiUtCopyIelementToEelement (
344 1.1 jruoho UINT8 ObjectType,
345 1.1 jruoho ACPI_OPERAND_OBJECT *SourceObject,
346 1.1 jruoho ACPI_GENERIC_STATE *State,
347 1.1 jruoho void *Context)
348 1.1 jruoho {
349 1.1 jruoho ACPI_STATUS Status = AE_OK;
350 1.1 jruoho ACPI_PKG_INFO *Info = (ACPI_PKG_INFO *) Context;
351 1.1 jruoho ACPI_SIZE ObjectSpace;
352 1.1 jruoho UINT32 ThisIndex;
353 1.1 jruoho ACPI_OBJECT *TargetObject;
354 1.1 jruoho
355 1.1 jruoho
356 1.1 jruoho ACPI_FUNCTION_ENTRY ();
357 1.1 jruoho
358 1.1 jruoho
359 1.1 jruoho ThisIndex = State->Pkg.Index;
360 1.1 jruoho TargetObject = (ACPI_OBJECT *)
361 1.1 jruoho &((ACPI_OBJECT *)(State->Pkg.DestObject))->Package.Elements[ThisIndex];
362 1.1 jruoho
363 1.1 jruoho switch (ObjectType)
364 1.1 jruoho {
365 1.1 jruoho case ACPI_COPY_TYPE_SIMPLE:
366 1.1 jruoho
367 1.1 jruoho /*
368 1.1 jruoho * This is a simple or null object
369 1.1 jruoho */
370 1.1 jruoho Status = AcpiUtCopyIsimpleToEsimple (SourceObject,
371 1.1 jruoho TargetObject, Info->FreeSpace, &ObjectSpace);
372 1.1 jruoho if (ACPI_FAILURE (Status))
373 1.1 jruoho {
374 1.1 jruoho return (Status);
375 1.1 jruoho }
376 1.1 jruoho break;
377 1.1 jruoho
378 1.1 jruoho
379 1.1 jruoho case ACPI_COPY_TYPE_PACKAGE:
380 1.1 jruoho
381 1.1 jruoho /*
382 1.1 jruoho * Build the package object
383 1.1 jruoho */
384 1.1 jruoho TargetObject->Type = ACPI_TYPE_PACKAGE;
385 1.1 jruoho TargetObject->Package.Count = SourceObject->Package.Count;
386 1.1 jruoho TargetObject->Package.Elements =
387 1.1 jruoho ACPI_CAST_PTR (ACPI_OBJECT, Info->FreeSpace);
388 1.1 jruoho
389 1.1 jruoho /*
390 1.1 jruoho * Pass the new package object back to the package walk routine
391 1.1 jruoho */
392 1.1 jruoho State->Pkg.ThisTargetObj = TargetObject;
393 1.1 jruoho
394 1.1 jruoho /*
395 1.1 jruoho * Save space for the array of objects (Package elements)
396 1.1 jruoho * update the buffer length counter
397 1.1 jruoho */
398 1.1 jruoho ObjectSpace = ACPI_ROUND_UP_TO_NATIVE_WORD (
399 1.1 jruoho (ACPI_SIZE) TargetObject->Package.Count *
400 1.1 jruoho sizeof (ACPI_OBJECT));
401 1.1 jruoho break;
402 1.1 jruoho
403 1.1 jruoho
404 1.1 jruoho default:
405 1.1 jruoho return (AE_BAD_PARAMETER);
406 1.1 jruoho }
407 1.1 jruoho
408 1.1 jruoho Info->FreeSpace += ObjectSpace;
409 1.1 jruoho Info->Length += ObjectSpace;
410 1.1 jruoho return (Status);
411 1.1 jruoho }
412 1.1 jruoho
413 1.1 jruoho
414 1.1 jruoho /*******************************************************************************
415 1.1 jruoho *
416 1.1 jruoho * FUNCTION: AcpiUtCopyIpackageToEpackage
417 1.1 jruoho *
418 1.1 jruoho * PARAMETERS: InternalObject - Pointer to the object we are returning
419 1.1 jruoho * Buffer - Where the object is returned
420 1.1 jruoho * SpaceUsed - Where the object length is returned
421 1.1 jruoho *
422 1.1 jruoho * RETURN: Status
423 1.1 jruoho *
424 1.1 jruoho * DESCRIPTION: This function is called to place a package object in a user
425 1.1 jruoho * buffer. A package object by definition contains other objects.
426 1.1 jruoho *
427 1.1 jruoho * The buffer is assumed to have sufficient space for the object.
428 1.1 jruoho * The caller must have verified the buffer length needed using
429 1.1 jruoho * the AcpiUtGetObjectSize function before calling this function.
430 1.1 jruoho *
431 1.1 jruoho ******************************************************************************/
432 1.1 jruoho
433 1.1 jruoho static ACPI_STATUS
434 1.1 jruoho AcpiUtCopyIpackageToEpackage (
435 1.1 jruoho ACPI_OPERAND_OBJECT *InternalObject,
436 1.1 jruoho UINT8 *Buffer,
437 1.1 jruoho ACPI_SIZE *SpaceUsed)
438 1.1 jruoho {
439 1.1 jruoho ACPI_OBJECT *ExternalObject;
440 1.1 jruoho ACPI_STATUS Status;
441 1.1 jruoho ACPI_PKG_INFO Info;
442 1.1 jruoho
443 1.1 jruoho
444 1.1 jruoho ACPI_FUNCTION_TRACE (UtCopyIpackageToEpackage);
445 1.1 jruoho
446 1.1 jruoho
447 1.1 jruoho /*
448 1.1 jruoho * First package at head of the buffer
449 1.1 jruoho */
450 1.1 jruoho ExternalObject = ACPI_CAST_PTR (ACPI_OBJECT, Buffer);
451 1.1 jruoho
452 1.1 jruoho /*
453 1.1 jruoho * Free space begins right after the first package
454 1.1 jruoho */
455 1.1 jruoho Info.Length = ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT));
456 1.1 jruoho Info.FreeSpace = Buffer + ACPI_ROUND_UP_TO_NATIVE_WORD (
457 1.1 jruoho sizeof (ACPI_OBJECT));
458 1.1 jruoho Info.ObjectSpace = 0;
459 1.1 jruoho Info.NumPackages = 1;
460 1.1 jruoho
461 1.1 jruoho ExternalObject->Type = InternalObject->Common.Type;
462 1.1 jruoho ExternalObject->Package.Count = InternalObject->Package.Count;
463 1.1 jruoho ExternalObject->Package.Elements = ACPI_CAST_PTR (ACPI_OBJECT,
464 1.1 jruoho Info.FreeSpace);
465 1.1 jruoho
466 1.1 jruoho /*
467 1.1 jruoho * Leave room for an array of ACPI_OBJECTS in the buffer
468 1.1 jruoho * and move the free space past it
469 1.1 jruoho */
470 1.1 jruoho Info.Length += (ACPI_SIZE) ExternalObject->Package.Count *
471 1.1 jruoho ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT));
472 1.1 jruoho Info.FreeSpace += ExternalObject->Package.Count *
473 1.1 jruoho ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT));
474 1.1 jruoho
475 1.1 jruoho Status = AcpiUtWalkPackageTree (InternalObject, ExternalObject,
476 1.1 jruoho AcpiUtCopyIelementToEelement, &Info);
477 1.1 jruoho
478 1.1 jruoho *SpaceUsed = Info.Length;
479 1.1 jruoho return_ACPI_STATUS (Status);
480 1.1 jruoho }
481 1.1 jruoho
482 1.1 jruoho
483 1.1 jruoho /*******************************************************************************
484 1.1 jruoho *
485 1.1 jruoho * FUNCTION: AcpiUtCopyIobjectToEobject
486 1.1 jruoho *
487 1.1 jruoho * PARAMETERS: InternalObject - The internal object to be converted
488 1.1 jruoho * RetBuffer - Where the object is returned
489 1.1 jruoho *
490 1.1 jruoho * RETURN: Status
491 1.1 jruoho *
492 1.1 jruoho * DESCRIPTION: This function is called to build an API object to be returned
493 1.1 jruoho * to the caller.
494 1.1 jruoho *
495 1.1 jruoho ******************************************************************************/
496 1.1 jruoho
497 1.1 jruoho ACPI_STATUS
498 1.1 jruoho AcpiUtCopyIobjectToEobject (
499 1.1 jruoho ACPI_OPERAND_OBJECT *InternalObject,
500 1.1 jruoho ACPI_BUFFER *RetBuffer)
501 1.1 jruoho {
502 1.1 jruoho ACPI_STATUS Status;
503 1.1 jruoho
504 1.1 jruoho
505 1.1 jruoho ACPI_FUNCTION_TRACE (UtCopyIobjectToEobject);
506 1.1 jruoho
507 1.1 jruoho
508 1.1 jruoho if (InternalObject->Common.Type == ACPI_TYPE_PACKAGE)
509 1.1 jruoho {
510 1.1 jruoho /*
511 1.1 jruoho * Package object: Copy all subobjects (including
512 1.1 jruoho * nested packages)
513 1.1 jruoho */
514 1.1 jruoho Status = AcpiUtCopyIpackageToEpackage (InternalObject,
515 1.1 jruoho RetBuffer->Pointer, &RetBuffer->Length);
516 1.1 jruoho }
517 1.1 jruoho else
518 1.1 jruoho {
519 1.1 jruoho /*
520 1.1 jruoho * Build a simple object (no nested objects)
521 1.1 jruoho */
522 1.1 jruoho Status = AcpiUtCopyIsimpleToEsimple (InternalObject,
523 1.1 jruoho ACPI_CAST_PTR (ACPI_OBJECT, RetBuffer->Pointer),
524 1.1 jruoho ACPI_ADD_PTR (UINT8, RetBuffer->Pointer,
525 1.1 jruoho ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT))),
526 1.1 jruoho &RetBuffer->Length);
527 1.1 jruoho /*
528 1.1 jruoho * build simple does not include the object size in the length
529 1.1 jruoho * so we add it in here
530 1.1 jruoho */
531 1.1 jruoho RetBuffer->Length += sizeof (ACPI_OBJECT);
532 1.1 jruoho }
533 1.1 jruoho
534 1.1 jruoho return_ACPI_STATUS (Status);
535 1.1 jruoho }
536 1.1 jruoho
537 1.1 jruoho
538 1.1 jruoho /*******************************************************************************
539 1.1 jruoho *
540 1.1 jruoho * FUNCTION: AcpiUtCopyEsimpleToIsimple
541 1.1 jruoho *
542 1.1 jruoho * PARAMETERS: ExternalObject - The external object to be converted
543 1.1 jruoho * RetInternalObject - Where the internal object is returned
544 1.1 jruoho *
545 1.1 jruoho * RETURN: Status
546 1.1 jruoho *
547 1.1 jruoho * DESCRIPTION: This function copies an external object to an internal one.
548 1.1 jruoho * NOTE: Pointers can be copied, we don't need to copy data.
549 1.1 jruoho * (The pointers have to be valid in our address space no matter
550 1.1 jruoho * what we do with them!)
551 1.1 jruoho *
552 1.1 jruoho ******************************************************************************/
553 1.1 jruoho
554 1.1 jruoho static ACPI_STATUS
555 1.1 jruoho AcpiUtCopyEsimpleToIsimple (
556 1.1 jruoho ACPI_OBJECT *ExternalObject,
557 1.1 jruoho ACPI_OPERAND_OBJECT **RetInternalObject)
558 1.1 jruoho {
559 1.1 jruoho ACPI_OPERAND_OBJECT *InternalObject;
560 1.1 jruoho
561 1.1 jruoho
562 1.1 jruoho ACPI_FUNCTION_TRACE (UtCopyEsimpleToIsimple);
563 1.1 jruoho
564 1.1 jruoho
565 1.1 jruoho /*
566 1.1 jruoho * Simple types supported are: String, Buffer, Integer
567 1.1 jruoho */
568 1.1 jruoho switch (ExternalObject->Type)
569 1.1 jruoho {
570 1.1 jruoho case ACPI_TYPE_STRING:
571 1.1 jruoho case ACPI_TYPE_BUFFER:
572 1.1 jruoho case ACPI_TYPE_INTEGER:
573 1.1 jruoho case ACPI_TYPE_LOCAL_REFERENCE:
574 1.1 jruoho
575 1.1 jruoho InternalObject = AcpiUtCreateInternalObject (
576 1.1 jruoho (UINT8) ExternalObject->Type);
577 1.1 jruoho if (!InternalObject)
578 1.1 jruoho {
579 1.1 jruoho return_ACPI_STATUS (AE_NO_MEMORY);
580 1.1 jruoho }
581 1.1 jruoho break;
582 1.1 jruoho
583 1.1 jruoho case ACPI_TYPE_ANY: /* This is the case for a NULL object */
584 1.1 jruoho
585 1.1 jruoho *RetInternalObject = NULL;
586 1.1 jruoho return_ACPI_STATUS (AE_OK);
587 1.1 jruoho
588 1.1 jruoho default:
589 1.1 jruoho /* All other types are not supported */
590 1.1 jruoho
591 1.1 jruoho ACPI_ERROR ((AE_INFO,
592 1.1 jruoho "Unsupported object type, cannot convert to internal object: %s",
593 1.1 jruoho AcpiUtGetTypeName (ExternalObject->Type)));
594 1.1 jruoho
595 1.1 jruoho return_ACPI_STATUS (AE_SUPPORT);
596 1.1 jruoho }
597 1.1 jruoho
598 1.1 jruoho
599 1.1 jruoho /* Must COPY string and buffer contents */
600 1.1 jruoho
601 1.1 jruoho switch (ExternalObject->Type)
602 1.1 jruoho {
603 1.1 jruoho case ACPI_TYPE_STRING:
604 1.1 jruoho
605 1.1 jruoho InternalObject->String.Pointer =
606 1.1 jruoho ACPI_ALLOCATE_ZEROED ((ACPI_SIZE)
607 1.1 jruoho ExternalObject->String.Length + 1);
608 1.1 jruoho
609 1.1 jruoho if (!InternalObject->String.Pointer)
610 1.1 jruoho {
611 1.1 jruoho goto ErrorExit;
612 1.1 jruoho }
613 1.1 jruoho
614 1.1 jruoho ACPI_MEMCPY (InternalObject->String.Pointer,
615 1.1 jruoho ExternalObject->String.Pointer,
616 1.1 jruoho ExternalObject->String.Length);
617 1.1 jruoho
618 1.1 jruoho InternalObject->String.Length = ExternalObject->String.Length;
619 1.1 jruoho break;
620 1.1 jruoho
621 1.1 jruoho
622 1.1 jruoho case ACPI_TYPE_BUFFER:
623 1.1 jruoho
624 1.1 jruoho InternalObject->Buffer.Pointer =
625 1.1 jruoho ACPI_ALLOCATE_ZEROED (ExternalObject->Buffer.Length);
626 1.1 jruoho if (!InternalObject->Buffer.Pointer)
627 1.1 jruoho {
628 1.1 jruoho goto ErrorExit;
629 1.1 jruoho }
630 1.1 jruoho
631 1.1 jruoho ACPI_MEMCPY (InternalObject->Buffer.Pointer,
632 1.1 jruoho ExternalObject->Buffer.Pointer,
633 1.1 jruoho ExternalObject->Buffer.Length);
634 1.1 jruoho
635 1.1 jruoho InternalObject->Buffer.Length = ExternalObject->Buffer.Length;
636 1.1 jruoho
637 1.1 jruoho /* Mark buffer data valid */
638 1.1 jruoho
639 1.1 jruoho InternalObject->Buffer.Flags |= AOPOBJ_DATA_VALID;
640 1.1 jruoho break;
641 1.1 jruoho
642 1.1 jruoho
643 1.1 jruoho case ACPI_TYPE_INTEGER:
644 1.1 jruoho
645 1.1 jruoho InternalObject->Integer.Value = ExternalObject->Integer.Value;
646 1.1 jruoho break;
647 1.1 jruoho
648 1.1 jruoho case ACPI_TYPE_LOCAL_REFERENCE:
649 1.1 jruoho
650 1.1 jruoho /* TBD: should validate incoming handle */
651 1.1 jruoho
652 1.1 jruoho InternalObject->Reference.Class = ACPI_REFCLASS_NAME;
653 1.1 jruoho InternalObject->Reference.Node = ExternalObject->Reference.Handle;
654 1.1 jruoho break;
655 1.1 jruoho
656 1.1 jruoho default:
657 1.1 jruoho /* Other types can't get here */
658 1.1 jruoho break;
659 1.1 jruoho }
660 1.1 jruoho
661 1.1 jruoho *RetInternalObject = InternalObject;
662 1.1 jruoho return_ACPI_STATUS (AE_OK);
663 1.1 jruoho
664 1.1 jruoho
665 1.1 jruoho ErrorExit:
666 1.1 jruoho AcpiUtRemoveReference (InternalObject);
667 1.1 jruoho return_ACPI_STATUS (AE_NO_MEMORY);
668 1.1 jruoho }
669 1.1 jruoho
670 1.1 jruoho
671 1.1 jruoho /*******************************************************************************
672 1.1 jruoho *
673 1.1 jruoho * FUNCTION: AcpiUtCopyEpackageToIpackage
674 1.1 jruoho *
675 1.1 jruoho * PARAMETERS: ExternalObject - The external object to be converted
676 1.1 jruoho * InternalObject - Where the internal object is returned
677 1.1 jruoho *
678 1.1 jruoho * RETURN: Status
679 1.1 jruoho *
680 1.1 jruoho * DESCRIPTION: Copy an external package object to an internal package.
681 1.1 jruoho * Handles nested packages.
682 1.1 jruoho *
683 1.1 jruoho ******************************************************************************/
684 1.1 jruoho
685 1.1 jruoho static ACPI_STATUS
686 1.1 jruoho AcpiUtCopyEpackageToIpackage (
687 1.1 jruoho ACPI_OBJECT *ExternalObject,
688 1.1 jruoho ACPI_OPERAND_OBJECT **InternalObject)
689 1.1 jruoho {
690 1.1 jruoho ACPI_STATUS Status = AE_OK;
691 1.1 jruoho ACPI_OPERAND_OBJECT *PackageObject;
692 1.1 jruoho ACPI_OPERAND_OBJECT **PackageElements;
693 1.1 jruoho UINT32 i;
694 1.1 jruoho
695 1.1 jruoho
696 1.1 jruoho ACPI_FUNCTION_TRACE (UtCopyEpackageToIpackage);
697 1.1 jruoho
698 1.1 jruoho
699 1.1 jruoho /* Create the package object */
700 1.1 jruoho
701 1.1 jruoho PackageObject = AcpiUtCreatePackageObject (ExternalObject->Package.Count);
702 1.1 jruoho if (!PackageObject)
703 1.1 jruoho {
704 1.1 jruoho return_ACPI_STATUS (AE_NO_MEMORY);
705 1.1 jruoho }
706 1.1 jruoho
707 1.1 jruoho PackageElements = PackageObject->Package.Elements;
708 1.1 jruoho
709 1.1 jruoho /*
710 1.1 jruoho * Recursive implementation. Probably ok, since nested external packages
711 1.1 jruoho * as parameters should be very rare.
712 1.1 jruoho */
713 1.1 jruoho for (i = 0; i < ExternalObject->Package.Count; i++)
714 1.1 jruoho {
715 1.1 jruoho Status = AcpiUtCopyEobjectToIobject (
716 1.1 jruoho &ExternalObject->Package.Elements[i],
717 1.1 jruoho &PackageElements[i]);
718 1.1 jruoho if (ACPI_FAILURE (Status))
719 1.1 jruoho {
720 1.1 jruoho /* Truncate package and delete it */
721 1.1 jruoho
722 1.1 jruoho PackageObject->Package.Count = i;
723 1.1 jruoho PackageElements[i] = NULL;
724 1.1 jruoho AcpiUtRemoveReference (PackageObject);
725 1.1 jruoho return_ACPI_STATUS (Status);
726 1.1 jruoho }
727 1.1 jruoho }
728 1.1 jruoho
729 1.1 jruoho /* Mark package data valid */
730 1.1 jruoho
731 1.1 jruoho PackageObject->Package.Flags |= AOPOBJ_DATA_VALID;
732 1.1 jruoho
733 1.1 jruoho *InternalObject = PackageObject;
734 1.1 jruoho return_ACPI_STATUS (Status);
735 1.1 jruoho }
736 1.1 jruoho
737 1.1 jruoho
738 1.1 jruoho /*******************************************************************************
739 1.1 jruoho *
740 1.1 jruoho * FUNCTION: AcpiUtCopyEobjectToIobject
741 1.1 jruoho *
742 1.1 jruoho * PARAMETERS: ExternalObject - The external object to be converted
743 1.1 jruoho * InternalObject - Where the internal object is returned
744 1.1 jruoho *
745 1.1 jruoho * RETURN: Status
746 1.1 jruoho *
747 1.1 jruoho * DESCRIPTION: Converts an external object to an internal object.
748 1.1 jruoho *
749 1.1 jruoho ******************************************************************************/
750 1.1 jruoho
751 1.1 jruoho ACPI_STATUS
752 1.1 jruoho AcpiUtCopyEobjectToIobject (
753 1.1 jruoho ACPI_OBJECT *ExternalObject,
754 1.1 jruoho ACPI_OPERAND_OBJECT **InternalObject)
755 1.1 jruoho {
756 1.1 jruoho ACPI_STATUS Status;
757 1.1 jruoho
758 1.1 jruoho
759 1.1 jruoho ACPI_FUNCTION_TRACE (UtCopyEobjectToIobject);
760 1.1 jruoho
761 1.1 jruoho
762 1.1 jruoho if (ExternalObject->Type == ACPI_TYPE_PACKAGE)
763 1.1 jruoho {
764 1.1 jruoho Status = AcpiUtCopyEpackageToIpackage (ExternalObject, InternalObject);
765 1.1 jruoho }
766 1.1 jruoho else
767 1.1 jruoho {
768 1.1 jruoho /*
769 1.1 jruoho * Build a simple object (no nested objects)
770 1.1 jruoho */
771 1.1 jruoho Status = AcpiUtCopyEsimpleToIsimple (ExternalObject, InternalObject);
772 1.1 jruoho }
773 1.1 jruoho
774 1.1 jruoho return_ACPI_STATUS (Status);
775 1.1 jruoho }
776 1.1 jruoho
777 1.1 jruoho
778 1.1 jruoho /*******************************************************************************
779 1.1 jruoho *
780 1.1 jruoho * FUNCTION: AcpiUtCopySimpleObject
781 1.1 jruoho *
782 1.1 jruoho * PARAMETERS: SourceDesc - The internal object to be copied
783 1.1 jruoho * DestDesc - New target object
784 1.1 jruoho *
785 1.1 jruoho * RETURN: Status
786 1.1 jruoho *
787 1.1 jruoho * DESCRIPTION: Simple copy of one internal object to another. Reference count
788 1.1 jruoho * of the destination object is preserved.
789 1.1 jruoho *
790 1.1 jruoho ******************************************************************************/
791 1.1 jruoho
792 1.1 jruoho static ACPI_STATUS
793 1.1 jruoho AcpiUtCopySimpleObject (
794 1.1 jruoho ACPI_OPERAND_OBJECT *SourceDesc,
795 1.1 jruoho ACPI_OPERAND_OBJECT *DestDesc)
796 1.1 jruoho {
797 1.1 jruoho UINT16 ReferenceCount;
798 1.1 jruoho ACPI_OPERAND_OBJECT *NextObject;
799 1.1 jruoho ACPI_STATUS Status;
800 1.1 jruoho ACPI_SIZE CopySize;
801 1.1 jruoho
802 1.1 jruoho
803 1.1 jruoho /* Save fields from destination that we don't want to overwrite */
804 1.1 jruoho
805 1.1 jruoho ReferenceCount = DestDesc->Common.ReferenceCount;
806 1.1 jruoho NextObject = DestDesc->Common.NextObject;
807 1.1 jruoho
808 1.1 jruoho /*
809 1.1 jruoho * Copy the entire source object over the destination object.
810 1.1 jruoho * Note: Source can be either an operand object or namespace node.
811 1.1 jruoho */
812 1.1 jruoho CopySize = sizeof (ACPI_OPERAND_OBJECT);
813 1.1 jruoho if (ACPI_GET_DESCRIPTOR_TYPE (SourceDesc) == ACPI_DESC_TYPE_NAMED)
814 1.1 jruoho {
815 1.1 jruoho CopySize = sizeof (ACPI_NAMESPACE_NODE);
816 1.1 jruoho }
817 1.1 jruoho
818 1.1 jruoho ACPI_MEMCPY (ACPI_CAST_PTR (char, DestDesc),
819 1.1 jruoho ACPI_CAST_PTR (char, SourceDesc), CopySize);
820 1.1 jruoho
821 1.1 jruoho /* Restore the saved fields */
822 1.1 jruoho
823 1.1 jruoho DestDesc->Common.ReferenceCount = ReferenceCount;
824 1.1 jruoho DestDesc->Common.NextObject = NextObject;
825 1.1 jruoho
826 1.1 jruoho /* New object is not static, regardless of source */
827 1.1 jruoho
828 1.1 jruoho DestDesc->Common.Flags &= ~AOPOBJ_STATIC_POINTER;
829 1.1 jruoho
830 1.1 jruoho /* Handle the objects with extra data */
831 1.1 jruoho
832 1.1 jruoho switch (DestDesc->Common.Type)
833 1.1 jruoho {
834 1.1 jruoho case ACPI_TYPE_BUFFER:
835 1.1 jruoho /*
836 1.1 jruoho * Allocate and copy the actual buffer if and only if:
837 1.1 jruoho * 1) There is a valid buffer pointer
838 1.1 jruoho * 2) The buffer has a length > 0
839 1.1 jruoho */
840 1.1 jruoho if ((SourceDesc->Buffer.Pointer) &&
841 1.1 jruoho (SourceDesc->Buffer.Length))
842 1.1 jruoho {
843 1.1 jruoho DestDesc->Buffer.Pointer =
844 1.1 jruoho ACPI_ALLOCATE (SourceDesc->Buffer.Length);
845 1.1 jruoho if (!DestDesc->Buffer.Pointer)
846 1.1 jruoho {
847 1.1 jruoho return (AE_NO_MEMORY);
848 1.1 jruoho }
849 1.1 jruoho
850 1.1 jruoho /* Copy the actual buffer data */
851 1.1 jruoho
852 1.1 jruoho ACPI_MEMCPY (DestDesc->Buffer.Pointer,
853 1.1 jruoho SourceDesc->Buffer.Pointer, SourceDesc->Buffer.Length);
854 1.1 jruoho }
855 1.1 jruoho break;
856 1.1 jruoho
857 1.1 jruoho case ACPI_TYPE_STRING:
858 1.1 jruoho /*
859 1.1 jruoho * Allocate and copy the actual string if and only if:
860 1.1 jruoho * 1) There is a valid string pointer
861 1.1 jruoho * (Pointer to a NULL string is allowed)
862 1.1 jruoho */
863 1.1 jruoho if (SourceDesc->String.Pointer)
864 1.1 jruoho {
865 1.1 jruoho DestDesc->String.Pointer =
866 1.1 jruoho ACPI_ALLOCATE ((ACPI_SIZE) SourceDesc->String.Length + 1);
867 1.1 jruoho if (!DestDesc->String.Pointer)
868 1.1 jruoho {
869 1.1 jruoho return (AE_NO_MEMORY);
870 1.1 jruoho }
871 1.1 jruoho
872 1.1 jruoho /* Copy the actual string data */
873 1.1 jruoho
874 1.1 jruoho ACPI_MEMCPY (DestDesc->String.Pointer, SourceDesc->String.Pointer,
875 1.1 jruoho (ACPI_SIZE) SourceDesc->String.Length + 1);
876 1.1 jruoho }
877 1.1 jruoho break;
878 1.1 jruoho
879 1.1 jruoho case ACPI_TYPE_LOCAL_REFERENCE:
880 1.1 jruoho /*
881 1.1 jruoho * We copied the reference object, so we now must add a reference
882 1.1 jruoho * to the object pointed to by the reference
883 1.1 jruoho *
884 1.1 jruoho * DDBHandle reference (from Load/LoadTable) is a special reference,
885 1.1 jruoho * it does not have a Reference.Object, so does not need to
886 1.1 jruoho * increase the reference count
887 1.1 jruoho */
888 1.1 jruoho if (SourceDesc->Reference.Class == ACPI_REFCLASS_TABLE)
889 1.1 jruoho {
890 1.1 jruoho break;
891 1.1 jruoho }
892 1.1 jruoho
893 1.1 jruoho AcpiUtAddReference (SourceDesc->Reference.Object);
894 1.1 jruoho break;
895 1.1 jruoho
896 1.1 jruoho case ACPI_TYPE_REGION:
897 1.1 jruoho /*
898 1.1 jruoho * We copied the Region Handler, so we now must add a reference
899 1.1 jruoho */
900 1.1 jruoho if (DestDesc->Region.Handler)
901 1.1 jruoho {
902 1.1 jruoho AcpiUtAddReference (DestDesc->Region.Handler);
903 1.1 jruoho }
904 1.1 jruoho break;
905 1.1 jruoho
906 1.1 jruoho /*
907 1.1 jruoho * For Mutex and Event objects, we cannot simply copy the underlying
908 1.1 jruoho * OS object. We must create a new one.
909 1.1 jruoho */
910 1.1 jruoho case ACPI_TYPE_MUTEX:
911 1.1 jruoho
912 1.1 jruoho Status = AcpiOsCreateMutex (&DestDesc->Mutex.OsMutex);
913 1.1 jruoho if (ACPI_FAILURE (Status))
914 1.1 jruoho {
915 1.1 jruoho return (Status);
916 1.1 jruoho }
917 1.1 jruoho break;
918 1.1 jruoho
919 1.1 jruoho case ACPI_TYPE_EVENT:
920 1.1 jruoho
921 1.1 jruoho Status = AcpiOsCreateSemaphore (ACPI_NO_UNIT_LIMIT, 0,
922 1.1 jruoho &DestDesc->Event.OsSemaphore);
923 1.1 jruoho if (ACPI_FAILURE (Status))
924 1.1 jruoho {
925 1.1 jruoho return (Status);
926 1.1 jruoho }
927 1.1 jruoho break;
928 1.1 jruoho
929 1.1 jruoho default:
930 1.1 jruoho /* Nothing to do for other simple objects */
931 1.1 jruoho break;
932 1.1 jruoho }
933 1.1 jruoho
934 1.1 jruoho return (AE_OK);
935 1.1 jruoho }
936 1.1 jruoho
937 1.1 jruoho
938 1.1 jruoho /*******************************************************************************
939 1.1 jruoho *
940 1.1 jruoho * FUNCTION: AcpiUtCopyIelementToIelement
941 1.1 jruoho *
942 1.1 jruoho * PARAMETERS: ACPI_PKG_CALLBACK
943 1.1 jruoho *
944 1.1 jruoho * RETURN: Status
945 1.1 jruoho *
946 1.1 jruoho * DESCRIPTION: Copy one package element to another package element
947 1.1 jruoho *
948 1.1 jruoho ******************************************************************************/
949 1.1 jruoho
950 1.1 jruoho static ACPI_STATUS
951 1.1 jruoho AcpiUtCopyIelementToIelement (
952 1.1 jruoho UINT8 ObjectType,
953 1.1 jruoho ACPI_OPERAND_OBJECT *SourceObject,
954 1.1 jruoho ACPI_GENERIC_STATE *State,
955 1.1 jruoho void *Context)
956 1.1 jruoho {
957 1.1 jruoho ACPI_STATUS Status = AE_OK;
958 1.1 jruoho UINT32 ThisIndex;
959 1.1 jruoho ACPI_OPERAND_OBJECT **ThisTargetPtr;
960 1.1 jruoho ACPI_OPERAND_OBJECT *TargetObject;
961 1.1 jruoho
962 1.1 jruoho
963 1.1 jruoho ACPI_FUNCTION_ENTRY ();
964 1.1 jruoho
965 1.1 jruoho
966 1.1 jruoho ThisIndex = State->Pkg.Index;
967 1.1 jruoho ThisTargetPtr = (ACPI_OPERAND_OBJECT **)
968 1.1 jruoho &State->Pkg.DestObject->Package.Elements[ThisIndex];
969 1.1 jruoho
970 1.1 jruoho switch (ObjectType)
971 1.1 jruoho {
972 1.1 jruoho case ACPI_COPY_TYPE_SIMPLE:
973 1.1 jruoho
974 1.1 jruoho /* A null source object indicates a (legal) null package element */
975 1.1 jruoho
976 1.1 jruoho if (SourceObject)
977 1.1 jruoho {
978 1.1 jruoho /*
979 1.1 jruoho * This is a simple object, just copy it
980 1.1 jruoho */
981 1.1 jruoho TargetObject = AcpiUtCreateInternalObject (
982 1.1 jruoho SourceObject->Common.Type);
983 1.1 jruoho if (!TargetObject)
984 1.1 jruoho {
985 1.1 jruoho return (AE_NO_MEMORY);
986 1.1 jruoho }
987 1.1 jruoho
988 1.1 jruoho Status = AcpiUtCopySimpleObject (SourceObject, TargetObject);
989 1.1 jruoho if (ACPI_FAILURE (Status))
990 1.1 jruoho {
991 1.1 jruoho goto ErrorExit;
992 1.1 jruoho }
993 1.1 jruoho
994 1.1 jruoho *ThisTargetPtr = TargetObject;
995 1.1 jruoho }
996 1.1 jruoho else
997 1.1 jruoho {
998 1.1 jruoho /* Pass through a null element */
999 1.1 jruoho
1000 1.1 jruoho *ThisTargetPtr = NULL;
1001 1.1 jruoho }
1002 1.1 jruoho break;
1003 1.1 jruoho
1004 1.1 jruoho
1005 1.1 jruoho case ACPI_COPY_TYPE_PACKAGE:
1006 1.1 jruoho
1007 1.1 jruoho /*
1008 1.1 jruoho * This object is a package - go down another nesting level
1009 1.1 jruoho * Create and build the package object
1010 1.1 jruoho */
1011 1.1 jruoho TargetObject = AcpiUtCreatePackageObject (SourceObject->Package.Count);
1012 1.1 jruoho if (!TargetObject)
1013 1.1 jruoho {
1014 1.1 jruoho return (AE_NO_MEMORY);
1015 1.1 jruoho }
1016 1.1 jruoho
1017 1.1 jruoho TargetObject->Common.Flags = SourceObject->Common.Flags;
1018 1.1 jruoho
1019 1.1 jruoho /* Pass the new package object back to the package walk routine */
1020 1.1 jruoho
1021 1.1 jruoho State->Pkg.ThisTargetObj = TargetObject;
1022 1.1 jruoho
1023 1.1 jruoho /* Store the object pointer in the parent package object */
1024 1.1 jruoho
1025 1.1 jruoho *ThisTargetPtr = TargetObject;
1026 1.1 jruoho break;
1027 1.1 jruoho
1028 1.1 jruoho
1029 1.1 jruoho default:
1030 1.1 jruoho return (AE_BAD_PARAMETER);
1031 1.1 jruoho }
1032 1.1 jruoho
1033 1.1 jruoho return (Status);
1034 1.1 jruoho
1035 1.1 jruoho ErrorExit:
1036 1.1 jruoho AcpiUtRemoveReference (TargetObject);
1037 1.1 jruoho return (Status);
1038 1.1 jruoho }
1039 1.1 jruoho
1040 1.1 jruoho
1041 1.1 jruoho /*******************************************************************************
1042 1.1 jruoho *
1043 1.1 jruoho * FUNCTION: AcpiUtCopyIpackageToIpackage
1044 1.1 jruoho *
1045 1.1 jruoho * PARAMETERS: SourceObj - Pointer to the source package object
1046 1.1 jruoho * DestObj - Where the internal object is returned
1047 1.1 jruoho * WalkState - Current Walk state descriptor
1048 1.1 jruoho *
1049 1.1 jruoho * RETURN: Status
1050 1.1 jruoho *
1051 1.1 jruoho * DESCRIPTION: This function is called to copy an internal package object
1052 1.1 jruoho * into another internal package object.
1053 1.1 jruoho *
1054 1.1 jruoho ******************************************************************************/
1055 1.1 jruoho
1056 1.1 jruoho static ACPI_STATUS
1057 1.1 jruoho AcpiUtCopyIpackageToIpackage (
1058 1.1 jruoho ACPI_OPERAND_OBJECT *SourceObj,
1059 1.1 jruoho ACPI_OPERAND_OBJECT *DestObj,
1060 1.1 jruoho ACPI_WALK_STATE *WalkState)
1061 1.1 jruoho {
1062 1.1 jruoho ACPI_STATUS Status = AE_OK;
1063 1.1 jruoho
1064 1.1 jruoho
1065 1.1 jruoho ACPI_FUNCTION_TRACE (UtCopyIpackageToIpackage);
1066 1.1 jruoho
1067 1.1 jruoho
1068 1.1 jruoho DestObj->Common.Type = SourceObj->Common.Type;
1069 1.1 jruoho DestObj->Common.Flags = SourceObj->Common.Flags;
1070 1.1 jruoho DestObj->Package.Count = SourceObj->Package.Count;
1071 1.1 jruoho
1072 1.1 jruoho /*
1073 1.1 jruoho * Create the object array and walk the source package tree
1074 1.1 jruoho */
1075 1.1 jruoho DestObj->Package.Elements = ACPI_ALLOCATE_ZEROED (
1076 1.1 jruoho ((ACPI_SIZE) SourceObj->Package.Count + 1) *
1077 1.1 jruoho sizeof (void *));
1078 1.1 jruoho if (!DestObj->Package.Elements)
1079 1.1 jruoho {
1080 1.1 jruoho ACPI_ERROR ((AE_INFO, "Package allocation failure"));
1081 1.1 jruoho return_ACPI_STATUS (AE_NO_MEMORY);
1082 1.1 jruoho }
1083 1.1 jruoho
1084 1.1 jruoho /*
1085 1.1 jruoho * Copy the package element-by-element by walking the package "tree".
1086 1.1 jruoho * This handles nested packages of arbitrary depth.
1087 1.1 jruoho */
1088 1.1 jruoho Status = AcpiUtWalkPackageTree (SourceObj, DestObj,
1089 1.1 jruoho AcpiUtCopyIelementToIelement, WalkState);
1090 1.1 jruoho if (ACPI_FAILURE (Status))
1091 1.1 jruoho {
1092 1.1 jruoho /* On failure, delete the destination package object */
1093 1.1 jruoho
1094 1.1 jruoho AcpiUtRemoveReference (DestObj);
1095 1.1 jruoho }
1096 1.1 jruoho
1097 1.1 jruoho return_ACPI_STATUS (Status);
1098 1.1 jruoho }
1099 1.1 jruoho
1100 1.1 jruoho
1101 1.1 jruoho /*******************************************************************************
1102 1.1 jruoho *
1103 1.1 jruoho * FUNCTION: AcpiUtCopyIobjectToIobject
1104 1.1 jruoho *
1105 1.1 jruoho * PARAMETERS: SourceDesc - The internal object to be copied
1106 1.1 jruoho * DestDesc - Where the copied object is returned
1107 1.1 jruoho * WalkState - Current walk state
1108 1.1 jruoho *
1109 1.1 jruoho * RETURN: Status
1110 1.1 jruoho *
1111 1.1 jruoho * DESCRIPTION: Copy an internal object to a new internal object
1112 1.1 jruoho *
1113 1.1 jruoho ******************************************************************************/
1114 1.1 jruoho
1115 1.1 jruoho ACPI_STATUS
1116 1.1 jruoho AcpiUtCopyIobjectToIobject (
1117 1.1 jruoho ACPI_OPERAND_OBJECT *SourceDesc,
1118 1.1 jruoho ACPI_OPERAND_OBJECT **DestDesc,
1119 1.1 jruoho ACPI_WALK_STATE *WalkState)
1120 1.1 jruoho {
1121 1.1 jruoho ACPI_STATUS Status = AE_OK;
1122 1.1 jruoho
1123 1.1 jruoho
1124 1.1 jruoho ACPI_FUNCTION_TRACE (UtCopyIobjectToIobject);
1125 1.1 jruoho
1126 1.1 jruoho
1127 1.1 jruoho /* Create the top level object */
1128 1.1 jruoho
1129 1.1 jruoho *DestDesc = AcpiUtCreateInternalObject (SourceDesc->Common.Type);
1130 1.1 jruoho if (!*DestDesc)
1131 1.1 jruoho {
1132 1.1 jruoho return_ACPI_STATUS (AE_NO_MEMORY);
1133 1.1 jruoho }
1134 1.1 jruoho
1135 1.1 jruoho /* Copy the object and possible subobjects */
1136 1.1 jruoho
1137 1.1 jruoho if (SourceDesc->Common.Type == ACPI_TYPE_PACKAGE)
1138 1.1 jruoho {
1139 1.1 jruoho Status = AcpiUtCopyIpackageToIpackage (SourceDesc, *DestDesc,
1140 1.1 jruoho WalkState);
1141 1.1 jruoho }
1142 1.1 jruoho else
1143 1.1 jruoho {
1144 1.1 jruoho Status = AcpiUtCopySimpleObject (SourceDesc, *DestDesc);
1145 1.1 jruoho }
1146 1.1 jruoho
1147 1.1 jruoho return_ACPI_STATUS (Status);
1148 1.1 jruoho }
1149 1.1 jruoho
1150 1.1 jruoho
1151