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