utobject.c revision 1.1.1.1 1 1.1 jruoho /******************************************************************************
2 1.1 jruoho *
3 1.1 jruoho * Module Name: utobject - ACPI object create/delete/size/cache routines
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 __UTOBJECT_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 ("utobject")
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 AcpiUtGetSimpleObjectSize (
130 1.1 jruoho ACPI_OPERAND_OBJECT *Obj,
131 1.1 jruoho ACPI_SIZE *ObjLength);
132 1.1 jruoho
133 1.1 jruoho static ACPI_STATUS
134 1.1 jruoho AcpiUtGetPackageObjectSize (
135 1.1 jruoho ACPI_OPERAND_OBJECT *Obj,
136 1.1 jruoho ACPI_SIZE *ObjLength);
137 1.1 jruoho
138 1.1 jruoho static ACPI_STATUS
139 1.1 jruoho AcpiUtGetElementLength (
140 1.1 jruoho UINT8 ObjectType,
141 1.1 jruoho ACPI_OPERAND_OBJECT *SourceObject,
142 1.1 jruoho ACPI_GENERIC_STATE *State,
143 1.1 jruoho void *Context);
144 1.1 jruoho
145 1.1 jruoho
146 1.1 jruoho /*******************************************************************************
147 1.1 jruoho *
148 1.1 jruoho * FUNCTION: AcpiUtCreateInternalObjectDbg
149 1.1 jruoho *
150 1.1 jruoho * PARAMETERS: ModuleName - Source file name of caller
151 1.1 jruoho * LineNumber - Line number of caller
152 1.1 jruoho * ComponentId - Component type of caller
153 1.1 jruoho * Type - ACPI Type of the new object
154 1.1 jruoho *
155 1.1 jruoho * RETURN: A new internal object, null on failure
156 1.1 jruoho *
157 1.1 jruoho * DESCRIPTION: Create and initialize a new internal object.
158 1.1 jruoho *
159 1.1 jruoho * NOTE: We always allocate the worst-case object descriptor because
160 1.1 jruoho * these objects are cached, and we want them to be
161 1.1 jruoho * one-size-satisifies-any-request. This in itself may not be
162 1.1 jruoho * the most memory efficient, but the efficiency of the object
163 1.1 jruoho * cache should more than make up for this!
164 1.1 jruoho *
165 1.1 jruoho ******************************************************************************/
166 1.1 jruoho
167 1.1 jruoho ACPI_OPERAND_OBJECT *
168 1.1 jruoho AcpiUtCreateInternalObjectDbg (
169 1.1 jruoho const char *ModuleName,
170 1.1 jruoho UINT32 LineNumber,
171 1.1 jruoho UINT32 ComponentId,
172 1.1 jruoho ACPI_OBJECT_TYPE Type)
173 1.1 jruoho {
174 1.1 jruoho ACPI_OPERAND_OBJECT *Object;
175 1.1 jruoho ACPI_OPERAND_OBJECT *SecondObject;
176 1.1 jruoho
177 1.1 jruoho
178 1.1 jruoho ACPI_FUNCTION_TRACE_STR (UtCreateInternalObjectDbg,
179 1.1 jruoho AcpiUtGetTypeName (Type));
180 1.1 jruoho
181 1.1 jruoho
182 1.1 jruoho /* Allocate the raw object descriptor */
183 1.1 jruoho
184 1.1 jruoho Object = AcpiUtAllocateObjectDescDbg (ModuleName, LineNumber, ComponentId);
185 1.1 jruoho if (!Object)
186 1.1 jruoho {
187 1.1 jruoho return_PTR (NULL);
188 1.1 jruoho }
189 1.1 jruoho
190 1.1 jruoho switch (Type)
191 1.1 jruoho {
192 1.1 jruoho case ACPI_TYPE_REGION:
193 1.1 jruoho case ACPI_TYPE_BUFFER_FIELD:
194 1.1 jruoho case ACPI_TYPE_LOCAL_BANK_FIELD:
195 1.1 jruoho
196 1.1 jruoho /* These types require a secondary object */
197 1.1 jruoho
198 1.1 jruoho SecondObject = AcpiUtAllocateObjectDescDbg (ModuleName,
199 1.1 jruoho LineNumber, ComponentId);
200 1.1 jruoho if (!SecondObject)
201 1.1 jruoho {
202 1.1 jruoho AcpiUtDeleteObjectDesc (Object);
203 1.1 jruoho return_PTR (NULL);
204 1.1 jruoho }
205 1.1 jruoho
206 1.1 jruoho SecondObject->Common.Type = ACPI_TYPE_LOCAL_EXTRA;
207 1.1 jruoho SecondObject->Common.ReferenceCount = 1;
208 1.1 jruoho
209 1.1 jruoho /* Link the second object to the first */
210 1.1 jruoho
211 1.1 jruoho Object->Common.NextObject = SecondObject;
212 1.1 jruoho break;
213 1.1 jruoho
214 1.1 jruoho default:
215 1.1 jruoho /* All others have no secondary object */
216 1.1 jruoho break;
217 1.1 jruoho }
218 1.1 jruoho
219 1.1 jruoho /* Save the object type in the object descriptor */
220 1.1 jruoho
221 1.1 jruoho Object->Common.Type = (UINT8) Type;
222 1.1 jruoho
223 1.1 jruoho /* Init the reference count */
224 1.1 jruoho
225 1.1 jruoho Object->Common.ReferenceCount = 1;
226 1.1 jruoho
227 1.1 jruoho /* Any per-type initialization should go here */
228 1.1 jruoho
229 1.1 jruoho return_PTR (Object);
230 1.1 jruoho }
231 1.1 jruoho
232 1.1 jruoho
233 1.1 jruoho /*******************************************************************************
234 1.1 jruoho *
235 1.1 jruoho * FUNCTION: AcpiUtCreatePackageObject
236 1.1 jruoho *
237 1.1 jruoho * PARAMETERS: Count - Number of package elements
238 1.1 jruoho *
239 1.1 jruoho * RETURN: Pointer to a new Package object, null on failure
240 1.1 jruoho *
241 1.1 jruoho * DESCRIPTION: Create a fully initialized package object
242 1.1 jruoho *
243 1.1 jruoho ******************************************************************************/
244 1.1 jruoho
245 1.1 jruoho ACPI_OPERAND_OBJECT *
246 1.1 jruoho AcpiUtCreatePackageObject (
247 1.1 jruoho UINT32 Count)
248 1.1 jruoho {
249 1.1 jruoho ACPI_OPERAND_OBJECT *PackageDesc;
250 1.1 jruoho ACPI_OPERAND_OBJECT **PackageElements;
251 1.1 jruoho
252 1.1 jruoho
253 1.1 jruoho ACPI_FUNCTION_TRACE_U32 (UtCreatePackageObject, Count);
254 1.1 jruoho
255 1.1 jruoho
256 1.1 jruoho /* Create a new Package object */
257 1.1 jruoho
258 1.1 jruoho PackageDesc = AcpiUtCreateInternalObject (ACPI_TYPE_PACKAGE);
259 1.1 jruoho if (!PackageDesc)
260 1.1 jruoho {
261 1.1 jruoho return_PTR (NULL);
262 1.1 jruoho }
263 1.1 jruoho
264 1.1 jruoho /*
265 1.1 jruoho * Create the element array. Count+1 allows the array to be null
266 1.1 jruoho * terminated.
267 1.1 jruoho */
268 1.1 jruoho PackageElements = ACPI_ALLOCATE_ZEROED (
269 1.1 jruoho ((ACPI_SIZE) Count + 1) * sizeof (void *));
270 1.1 jruoho if (!PackageElements)
271 1.1 jruoho {
272 1.1 jruoho ACPI_FREE (PackageDesc);
273 1.1 jruoho return_PTR (NULL);
274 1.1 jruoho }
275 1.1 jruoho
276 1.1 jruoho PackageDesc->Package.Count = Count;
277 1.1 jruoho PackageDesc->Package.Elements = PackageElements;
278 1.1 jruoho return_PTR (PackageDesc);
279 1.1 jruoho }
280 1.1 jruoho
281 1.1 jruoho
282 1.1 jruoho /*******************************************************************************
283 1.1 jruoho *
284 1.1 jruoho * FUNCTION: AcpiUtCreateIntegerObject
285 1.1 jruoho *
286 1.1 jruoho * PARAMETERS: InitialValue - Initial value for the integer
287 1.1 jruoho *
288 1.1 jruoho * RETURN: Pointer to a new Integer object, null on failure
289 1.1 jruoho *
290 1.1 jruoho * DESCRIPTION: Create an initialized integer object
291 1.1 jruoho *
292 1.1 jruoho ******************************************************************************/
293 1.1 jruoho
294 1.1 jruoho ACPI_OPERAND_OBJECT *
295 1.1 jruoho AcpiUtCreateIntegerObject (
296 1.1 jruoho UINT64 InitialValue)
297 1.1 jruoho {
298 1.1 jruoho ACPI_OPERAND_OBJECT *IntegerDesc;
299 1.1 jruoho
300 1.1 jruoho
301 1.1 jruoho ACPI_FUNCTION_TRACE (UtCreateIntegerObject);
302 1.1 jruoho
303 1.1 jruoho
304 1.1 jruoho /* Create and initialize a new integer object */
305 1.1 jruoho
306 1.1 jruoho IntegerDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
307 1.1 jruoho if (!IntegerDesc)
308 1.1 jruoho {
309 1.1 jruoho return_PTR (NULL);
310 1.1 jruoho }
311 1.1 jruoho
312 1.1 jruoho IntegerDesc->Integer.Value = InitialValue;
313 1.1 jruoho return_PTR (IntegerDesc);
314 1.1 jruoho }
315 1.1 jruoho
316 1.1 jruoho
317 1.1 jruoho /*******************************************************************************
318 1.1 jruoho *
319 1.1 jruoho * FUNCTION: AcpiUtCreateBufferObject
320 1.1 jruoho *
321 1.1 jruoho * PARAMETERS: BufferSize - Size of buffer to be created
322 1.1 jruoho *
323 1.1 jruoho * RETURN: Pointer to a new Buffer object, null on failure
324 1.1 jruoho *
325 1.1 jruoho * DESCRIPTION: Create a fully initialized buffer object
326 1.1 jruoho *
327 1.1 jruoho ******************************************************************************/
328 1.1 jruoho
329 1.1 jruoho ACPI_OPERAND_OBJECT *
330 1.1 jruoho AcpiUtCreateBufferObject (
331 1.1 jruoho ACPI_SIZE BufferSize)
332 1.1 jruoho {
333 1.1 jruoho ACPI_OPERAND_OBJECT *BufferDesc;
334 1.1 jruoho UINT8 *Buffer = NULL;
335 1.1 jruoho
336 1.1 jruoho
337 1.1 jruoho ACPI_FUNCTION_TRACE_U32 (UtCreateBufferObject, BufferSize);
338 1.1 jruoho
339 1.1 jruoho
340 1.1 jruoho /* Create a new Buffer object */
341 1.1 jruoho
342 1.1 jruoho BufferDesc = AcpiUtCreateInternalObject (ACPI_TYPE_BUFFER);
343 1.1 jruoho if (!BufferDesc)
344 1.1 jruoho {
345 1.1 jruoho return_PTR (NULL);
346 1.1 jruoho }
347 1.1 jruoho
348 1.1 jruoho /* Create an actual buffer only if size > 0 */
349 1.1 jruoho
350 1.1 jruoho if (BufferSize > 0)
351 1.1 jruoho {
352 1.1 jruoho /* Allocate the actual buffer */
353 1.1 jruoho
354 1.1 jruoho Buffer = ACPI_ALLOCATE_ZEROED (BufferSize);
355 1.1 jruoho if (!Buffer)
356 1.1 jruoho {
357 1.1 jruoho ACPI_ERROR ((AE_INFO, "Could not allocate size %u",
358 1.1 jruoho (UINT32) BufferSize));
359 1.1 jruoho AcpiUtRemoveReference (BufferDesc);
360 1.1 jruoho return_PTR (NULL);
361 1.1 jruoho }
362 1.1 jruoho }
363 1.1 jruoho
364 1.1 jruoho /* Complete buffer object initialization */
365 1.1 jruoho
366 1.1 jruoho BufferDesc->Buffer.Flags |= AOPOBJ_DATA_VALID;
367 1.1 jruoho BufferDesc->Buffer.Pointer = Buffer;
368 1.1 jruoho BufferDesc->Buffer.Length = (UINT32) BufferSize;
369 1.1 jruoho
370 1.1 jruoho /* Return the new buffer descriptor */
371 1.1 jruoho
372 1.1 jruoho return_PTR (BufferDesc);
373 1.1 jruoho }
374 1.1 jruoho
375 1.1 jruoho
376 1.1 jruoho /*******************************************************************************
377 1.1 jruoho *
378 1.1 jruoho * FUNCTION: AcpiUtCreateStringObject
379 1.1 jruoho *
380 1.1 jruoho * PARAMETERS: StringSize - Size of string to be created. Does not
381 1.1 jruoho * include NULL terminator, this is added
382 1.1 jruoho * automatically.
383 1.1 jruoho *
384 1.1 jruoho * RETURN: Pointer to a new String object
385 1.1 jruoho *
386 1.1 jruoho * DESCRIPTION: Create a fully initialized string object
387 1.1 jruoho *
388 1.1 jruoho ******************************************************************************/
389 1.1 jruoho
390 1.1 jruoho ACPI_OPERAND_OBJECT *
391 1.1 jruoho AcpiUtCreateStringObject (
392 1.1 jruoho ACPI_SIZE StringSize)
393 1.1 jruoho {
394 1.1 jruoho ACPI_OPERAND_OBJECT *StringDesc;
395 1.1 jruoho char *String;
396 1.1 jruoho
397 1.1 jruoho
398 1.1 jruoho ACPI_FUNCTION_TRACE_U32 (UtCreateStringObject, StringSize);
399 1.1 jruoho
400 1.1 jruoho
401 1.1 jruoho /* Create a new String object */
402 1.1 jruoho
403 1.1 jruoho StringDesc = AcpiUtCreateInternalObject (ACPI_TYPE_STRING);
404 1.1 jruoho if (!StringDesc)
405 1.1 jruoho {
406 1.1 jruoho return_PTR (NULL);
407 1.1 jruoho }
408 1.1 jruoho
409 1.1 jruoho /*
410 1.1 jruoho * Allocate the actual string buffer -- (Size + 1) for NULL terminator.
411 1.1 jruoho * NOTE: Zero-length strings are NULL terminated
412 1.1 jruoho */
413 1.1 jruoho String = ACPI_ALLOCATE_ZEROED (StringSize + 1);
414 1.1 jruoho if (!String)
415 1.1 jruoho {
416 1.1 jruoho ACPI_ERROR ((AE_INFO, "Could not allocate size %u",
417 1.1 jruoho (UINT32) StringSize));
418 1.1 jruoho AcpiUtRemoveReference (StringDesc);
419 1.1 jruoho return_PTR (NULL);
420 1.1 jruoho }
421 1.1 jruoho
422 1.1 jruoho /* Complete string object initialization */
423 1.1 jruoho
424 1.1 jruoho StringDesc->String.Pointer = String;
425 1.1 jruoho StringDesc->String.Length = (UINT32) StringSize;
426 1.1 jruoho
427 1.1 jruoho /* Return the new string descriptor */
428 1.1 jruoho
429 1.1 jruoho return_PTR (StringDesc);
430 1.1 jruoho }
431 1.1 jruoho
432 1.1 jruoho
433 1.1 jruoho /*******************************************************************************
434 1.1 jruoho *
435 1.1 jruoho * FUNCTION: AcpiUtValidInternalObject
436 1.1 jruoho *
437 1.1 jruoho * PARAMETERS: Object - Object to be validated
438 1.1 jruoho *
439 1.1 jruoho * RETURN: TRUE if object is valid, FALSE otherwise
440 1.1 jruoho *
441 1.1 jruoho * DESCRIPTION: Validate a pointer to be an ACPI_OPERAND_OBJECT
442 1.1 jruoho *
443 1.1 jruoho ******************************************************************************/
444 1.1 jruoho
445 1.1 jruoho BOOLEAN
446 1.1 jruoho AcpiUtValidInternalObject (
447 1.1 jruoho void *Object)
448 1.1 jruoho {
449 1.1 jruoho
450 1.1 jruoho ACPI_FUNCTION_NAME (UtValidInternalObject);
451 1.1 jruoho
452 1.1 jruoho
453 1.1 jruoho /* Check for a null pointer */
454 1.1 jruoho
455 1.1 jruoho if (!Object)
456 1.1 jruoho {
457 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "**** Null Object Ptr\n"));
458 1.1 jruoho return (FALSE);
459 1.1 jruoho }
460 1.1 jruoho
461 1.1 jruoho /* Check the descriptor type field */
462 1.1 jruoho
463 1.1 jruoho switch (ACPI_GET_DESCRIPTOR_TYPE (Object))
464 1.1 jruoho {
465 1.1 jruoho case ACPI_DESC_TYPE_OPERAND:
466 1.1 jruoho
467 1.1 jruoho /* The object appears to be a valid ACPI_OPERAND_OBJECT */
468 1.1 jruoho
469 1.1 jruoho return (TRUE);
470 1.1 jruoho
471 1.1 jruoho default:
472 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
473 1.1 jruoho "%p is not not an ACPI operand obj [%s]\n",
474 1.1 jruoho Object, AcpiUtGetDescriptorName (Object)));
475 1.1 jruoho break;
476 1.1 jruoho }
477 1.1 jruoho
478 1.1 jruoho return (FALSE);
479 1.1 jruoho }
480 1.1 jruoho
481 1.1 jruoho
482 1.1 jruoho /*******************************************************************************
483 1.1 jruoho *
484 1.1 jruoho * FUNCTION: AcpiUtAllocateObjectDescDbg
485 1.1 jruoho *
486 1.1 jruoho * PARAMETERS: ModuleName - Caller's module name (for error output)
487 1.1 jruoho * LineNumber - Caller's line number (for error output)
488 1.1 jruoho * ComponentId - Caller's component ID (for error output)
489 1.1 jruoho *
490 1.1 jruoho * RETURN: Pointer to newly allocated object descriptor. Null on error
491 1.1 jruoho *
492 1.1 jruoho * DESCRIPTION: Allocate a new object descriptor. Gracefully handle
493 1.1 jruoho * error conditions.
494 1.1 jruoho *
495 1.1 jruoho ******************************************************************************/
496 1.1 jruoho
497 1.1 jruoho void *
498 1.1 jruoho AcpiUtAllocateObjectDescDbg (
499 1.1 jruoho const char *ModuleName,
500 1.1 jruoho UINT32 LineNumber,
501 1.1 jruoho UINT32 ComponentId)
502 1.1 jruoho {
503 1.1 jruoho ACPI_OPERAND_OBJECT *Object;
504 1.1 jruoho
505 1.1 jruoho
506 1.1 jruoho ACPI_FUNCTION_TRACE (UtAllocateObjectDescDbg);
507 1.1 jruoho
508 1.1 jruoho
509 1.1 jruoho Object = AcpiOsAcquireObject (AcpiGbl_OperandCache);
510 1.1 jruoho if (!Object)
511 1.1 jruoho {
512 1.1 jruoho ACPI_ERROR ((ModuleName, LineNumber,
513 1.1 jruoho "Could not allocate an object descriptor"));
514 1.1 jruoho
515 1.1 jruoho return_PTR (NULL);
516 1.1 jruoho }
517 1.1 jruoho
518 1.1 jruoho /* Mark the descriptor type */
519 1.1 jruoho
520 1.1 jruoho ACPI_SET_DESCRIPTOR_TYPE (Object, ACPI_DESC_TYPE_OPERAND);
521 1.1 jruoho
522 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "%p Size %X\n",
523 1.1 jruoho Object, (UINT32) sizeof (ACPI_OPERAND_OBJECT)));
524 1.1 jruoho
525 1.1 jruoho return_PTR (Object);
526 1.1 jruoho }
527 1.1 jruoho
528 1.1 jruoho
529 1.1 jruoho /*******************************************************************************
530 1.1 jruoho *
531 1.1 jruoho * FUNCTION: AcpiUtDeleteObjectDesc
532 1.1 jruoho *
533 1.1 jruoho * PARAMETERS: Object - An Acpi internal object to be deleted
534 1.1 jruoho *
535 1.1 jruoho * RETURN: None.
536 1.1 jruoho *
537 1.1 jruoho * DESCRIPTION: Free an ACPI object descriptor or add it to the object cache
538 1.1 jruoho *
539 1.1 jruoho ******************************************************************************/
540 1.1 jruoho
541 1.1 jruoho void
542 1.1 jruoho AcpiUtDeleteObjectDesc (
543 1.1 jruoho ACPI_OPERAND_OBJECT *Object)
544 1.1 jruoho {
545 1.1 jruoho ACPI_FUNCTION_TRACE_PTR (UtDeleteObjectDesc, Object);
546 1.1 jruoho
547 1.1 jruoho
548 1.1 jruoho /* Object must be an ACPI_OPERAND_OBJECT */
549 1.1 jruoho
550 1.1 jruoho if (ACPI_GET_DESCRIPTOR_TYPE (Object) != ACPI_DESC_TYPE_OPERAND)
551 1.1 jruoho {
552 1.1 jruoho ACPI_ERROR ((AE_INFO,
553 1.1 jruoho "%p is not an ACPI Operand object [%s]", Object,
554 1.1 jruoho AcpiUtGetDescriptorName (Object)));
555 1.1 jruoho return_VOID;
556 1.1 jruoho }
557 1.1 jruoho
558 1.1 jruoho (void) AcpiOsReleaseObject (AcpiGbl_OperandCache, Object);
559 1.1 jruoho return_VOID;
560 1.1 jruoho }
561 1.1 jruoho
562 1.1 jruoho
563 1.1 jruoho /*******************************************************************************
564 1.1 jruoho *
565 1.1 jruoho * FUNCTION: AcpiUtGetSimpleObjectSize
566 1.1 jruoho *
567 1.1 jruoho * PARAMETERS: InternalObject - An ACPI operand object
568 1.1 jruoho * ObjLength - Where the length is returned
569 1.1 jruoho *
570 1.1 jruoho * RETURN: Status
571 1.1 jruoho *
572 1.1 jruoho * DESCRIPTION: This function is called to determine the space required to
573 1.1 jruoho * contain a simple object for return to an external user.
574 1.1 jruoho *
575 1.1 jruoho * The length includes the object structure plus any additional
576 1.1 jruoho * needed space.
577 1.1 jruoho *
578 1.1 jruoho ******************************************************************************/
579 1.1 jruoho
580 1.1 jruoho static ACPI_STATUS
581 1.1 jruoho AcpiUtGetSimpleObjectSize (
582 1.1 jruoho ACPI_OPERAND_OBJECT *InternalObject,
583 1.1 jruoho ACPI_SIZE *ObjLength)
584 1.1 jruoho {
585 1.1 jruoho ACPI_SIZE Length;
586 1.1 jruoho ACPI_SIZE Size;
587 1.1 jruoho ACPI_STATUS Status = AE_OK;
588 1.1 jruoho
589 1.1 jruoho
590 1.1 jruoho ACPI_FUNCTION_TRACE_PTR (UtGetSimpleObjectSize, InternalObject);
591 1.1 jruoho
592 1.1 jruoho
593 1.1 jruoho /* Start with the length of the (external) Acpi object */
594 1.1 jruoho
595 1.1 jruoho Length = sizeof (ACPI_OBJECT);
596 1.1 jruoho
597 1.1 jruoho /* A NULL object is allowed, can be a legal uninitialized package element */
598 1.1 jruoho
599 1.1 jruoho if (!InternalObject)
600 1.1 jruoho {
601 1.1 jruoho /*
602 1.1 jruoho * Object is NULL, just return the length of ACPI_OBJECT
603 1.1 jruoho * (A NULL ACPI_OBJECT is an object of all zeroes.)
604 1.1 jruoho */
605 1.1 jruoho *ObjLength = ACPI_ROUND_UP_TO_NATIVE_WORD (Length);
606 1.1 jruoho return_ACPI_STATUS (AE_OK);
607 1.1 jruoho }
608 1.1 jruoho
609 1.1 jruoho /* A Namespace Node should never appear here */
610 1.1 jruoho
611 1.1 jruoho if (ACPI_GET_DESCRIPTOR_TYPE (InternalObject) == ACPI_DESC_TYPE_NAMED)
612 1.1 jruoho {
613 1.1 jruoho /* A namespace node should never get here */
614 1.1 jruoho
615 1.1 jruoho return_ACPI_STATUS (AE_AML_INTERNAL);
616 1.1 jruoho }
617 1.1 jruoho
618 1.1 jruoho /*
619 1.1 jruoho * The final length depends on the object type
620 1.1 jruoho * Strings and Buffers are packed right up against the parent object and
621 1.1 jruoho * must be accessed bytewise or there may be alignment problems on
622 1.1 jruoho * certain processors
623 1.1 jruoho */
624 1.1 jruoho switch (InternalObject->Common.Type)
625 1.1 jruoho {
626 1.1 jruoho case ACPI_TYPE_STRING:
627 1.1 jruoho
628 1.1 jruoho Length += (ACPI_SIZE) InternalObject->String.Length + 1;
629 1.1 jruoho break;
630 1.1 jruoho
631 1.1 jruoho
632 1.1 jruoho case ACPI_TYPE_BUFFER:
633 1.1 jruoho
634 1.1 jruoho Length += (ACPI_SIZE) InternalObject->Buffer.Length;
635 1.1 jruoho break;
636 1.1 jruoho
637 1.1 jruoho
638 1.1 jruoho case ACPI_TYPE_INTEGER:
639 1.1 jruoho case ACPI_TYPE_PROCESSOR:
640 1.1 jruoho case ACPI_TYPE_POWER:
641 1.1 jruoho
642 1.1 jruoho /* No extra data for these types */
643 1.1 jruoho
644 1.1 jruoho break;
645 1.1 jruoho
646 1.1 jruoho
647 1.1 jruoho case ACPI_TYPE_LOCAL_REFERENCE:
648 1.1 jruoho
649 1.1 jruoho switch (InternalObject->Reference.Class)
650 1.1 jruoho {
651 1.1 jruoho case ACPI_REFCLASS_NAME:
652 1.1 jruoho
653 1.1 jruoho /*
654 1.1 jruoho * Get the actual length of the full pathname to this object.
655 1.1 jruoho * The reference will be converted to the pathname to the object
656 1.1 jruoho */
657 1.1 jruoho Size = AcpiNsGetPathnameLength (InternalObject->Reference.Node);
658 1.1 jruoho if (!Size)
659 1.1 jruoho {
660 1.1 jruoho return_ACPI_STATUS (AE_BAD_PARAMETER);
661 1.1 jruoho }
662 1.1 jruoho
663 1.1 jruoho Length += ACPI_ROUND_UP_TO_NATIVE_WORD (Size);
664 1.1 jruoho break;
665 1.1 jruoho
666 1.1 jruoho default:
667 1.1 jruoho
668 1.1 jruoho /*
669 1.1 jruoho * No other reference opcodes are supported.
670 1.1 jruoho * Notably, Locals and Args are not supported, but this may be
671 1.1 jruoho * required eventually.
672 1.1 jruoho */
673 1.1 jruoho ACPI_ERROR ((AE_INFO, "Cannot convert to external object - "
674 1.1 jruoho "unsupported Reference Class [%s] 0x%X in object %p",
675 1.1 jruoho AcpiUtGetReferenceName (InternalObject),
676 1.1 jruoho InternalObject->Reference.Class, InternalObject));
677 1.1 jruoho Status = AE_TYPE;
678 1.1 jruoho break;
679 1.1 jruoho }
680 1.1 jruoho break;
681 1.1 jruoho
682 1.1 jruoho
683 1.1 jruoho default:
684 1.1 jruoho
685 1.1 jruoho ACPI_ERROR ((AE_INFO, "Cannot convert to external object - "
686 1.1 jruoho "unsupported type [%s] 0x%X in object %p",
687 1.1 jruoho AcpiUtGetObjectTypeName (InternalObject),
688 1.1 jruoho InternalObject->Common.Type, InternalObject));
689 1.1 jruoho Status = AE_TYPE;
690 1.1 jruoho break;
691 1.1 jruoho }
692 1.1 jruoho
693 1.1 jruoho /*
694 1.1 jruoho * Account for the space required by the object rounded up to the next
695 1.1 jruoho * multiple of the machine word size. This keeps each object aligned
696 1.1 jruoho * on a machine word boundary. (preventing alignment faults on some
697 1.1 jruoho * machines.)
698 1.1 jruoho */
699 1.1 jruoho *ObjLength = ACPI_ROUND_UP_TO_NATIVE_WORD (Length);
700 1.1 jruoho return_ACPI_STATUS (Status);
701 1.1 jruoho }
702 1.1 jruoho
703 1.1 jruoho
704 1.1 jruoho /*******************************************************************************
705 1.1 jruoho *
706 1.1 jruoho * FUNCTION: AcpiUtGetElementLength
707 1.1 jruoho *
708 1.1 jruoho * PARAMETERS: ACPI_PKG_CALLBACK
709 1.1 jruoho *
710 1.1 jruoho * RETURN: Status
711 1.1 jruoho *
712 1.1 jruoho * DESCRIPTION: Get the length of one package element.
713 1.1 jruoho *
714 1.1 jruoho ******************************************************************************/
715 1.1 jruoho
716 1.1 jruoho static ACPI_STATUS
717 1.1 jruoho AcpiUtGetElementLength (
718 1.1 jruoho UINT8 ObjectType,
719 1.1 jruoho ACPI_OPERAND_OBJECT *SourceObject,
720 1.1 jruoho ACPI_GENERIC_STATE *State,
721 1.1 jruoho void *Context)
722 1.1 jruoho {
723 1.1 jruoho ACPI_STATUS Status = AE_OK;
724 1.1 jruoho ACPI_PKG_INFO *Info = (ACPI_PKG_INFO *) Context;
725 1.1 jruoho ACPI_SIZE ObjectSpace;
726 1.1 jruoho
727 1.1 jruoho
728 1.1 jruoho switch (ObjectType)
729 1.1 jruoho {
730 1.1 jruoho case ACPI_COPY_TYPE_SIMPLE:
731 1.1 jruoho
732 1.1 jruoho /*
733 1.1 jruoho * Simple object - just get the size (Null object/entry is handled
734 1.1 jruoho * here also) and sum it into the running package length
735 1.1 jruoho */
736 1.1 jruoho Status = AcpiUtGetSimpleObjectSize (SourceObject, &ObjectSpace);
737 1.1 jruoho if (ACPI_FAILURE (Status))
738 1.1 jruoho {
739 1.1 jruoho return (Status);
740 1.1 jruoho }
741 1.1 jruoho
742 1.1 jruoho Info->Length += ObjectSpace;
743 1.1 jruoho break;
744 1.1 jruoho
745 1.1 jruoho
746 1.1 jruoho case ACPI_COPY_TYPE_PACKAGE:
747 1.1 jruoho
748 1.1 jruoho /* Package object - nothing much to do here, let the walk handle it */
749 1.1 jruoho
750 1.1 jruoho Info->NumPackages++;
751 1.1 jruoho State->Pkg.ThisTargetObj = NULL;
752 1.1 jruoho break;
753 1.1 jruoho
754 1.1 jruoho
755 1.1 jruoho default:
756 1.1 jruoho
757 1.1 jruoho /* No other types allowed */
758 1.1 jruoho
759 1.1 jruoho return (AE_BAD_PARAMETER);
760 1.1 jruoho }
761 1.1 jruoho
762 1.1 jruoho return (Status);
763 1.1 jruoho }
764 1.1 jruoho
765 1.1 jruoho
766 1.1 jruoho /*******************************************************************************
767 1.1 jruoho *
768 1.1 jruoho * FUNCTION: AcpiUtGetPackageObjectSize
769 1.1 jruoho *
770 1.1 jruoho * PARAMETERS: InternalObject - An ACPI internal object
771 1.1 jruoho * ObjLength - Where the length is returned
772 1.1 jruoho *
773 1.1 jruoho * RETURN: Status
774 1.1 jruoho *
775 1.1 jruoho * DESCRIPTION: This function is called to determine the space required to
776 1.1 jruoho * contain a package object for return to an external user.
777 1.1 jruoho *
778 1.1 jruoho * This is moderately complex since a package contains other
779 1.1 jruoho * objects including packages.
780 1.1 jruoho *
781 1.1 jruoho ******************************************************************************/
782 1.1 jruoho
783 1.1 jruoho static ACPI_STATUS
784 1.1 jruoho AcpiUtGetPackageObjectSize (
785 1.1 jruoho ACPI_OPERAND_OBJECT *InternalObject,
786 1.1 jruoho ACPI_SIZE *ObjLength)
787 1.1 jruoho {
788 1.1 jruoho ACPI_STATUS Status;
789 1.1 jruoho ACPI_PKG_INFO Info;
790 1.1 jruoho
791 1.1 jruoho
792 1.1 jruoho ACPI_FUNCTION_TRACE_PTR (UtGetPackageObjectSize, InternalObject);
793 1.1 jruoho
794 1.1 jruoho
795 1.1 jruoho Info.Length = 0;
796 1.1 jruoho Info.ObjectSpace = 0;
797 1.1 jruoho Info.NumPackages = 1;
798 1.1 jruoho
799 1.1 jruoho Status = AcpiUtWalkPackageTree (InternalObject, NULL,
800 1.1 jruoho AcpiUtGetElementLength, &Info);
801 1.1 jruoho if (ACPI_FAILURE (Status))
802 1.1 jruoho {
803 1.1 jruoho return_ACPI_STATUS (Status);
804 1.1 jruoho }
805 1.1 jruoho
806 1.1 jruoho /*
807 1.1 jruoho * We have handled all of the objects in all levels of the package.
808 1.1 jruoho * just add the length of the package objects themselves.
809 1.1 jruoho * Round up to the next machine word.
810 1.1 jruoho */
811 1.1 jruoho Info.Length += ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT)) *
812 1.1 jruoho (ACPI_SIZE) Info.NumPackages;
813 1.1 jruoho
814 1.1 jruoho /* Return the total package length */
815 1.1 jruoho
816 1.1 jruoho *ObjLength = Info.Length;
817 1.1 jruoho return_ACPI_STATUS (Status);
818 1.1 jruoho }
819 1.1 jruoho
820 1.1 jruoho
821 1.1 jruoho /*******************************************************************************
822 1.1 jruoho *
823 1.1 jruoho * FUNCTION: AcpiUtGetObjectSize
824 1.1 jruoho *
825 1.1 jruoho * PARAMETERS: InternalObject - An ACPI internal object
826 1.1 jruoho * ObjLength - Where the length will be returned
827 1.1 jruoho *
828 1.1 jruoho * RETURN: Status
829 1.1 jruoho *
830 1.1 jruoho * DESCRIPTION: This function is called to determine the space required to
831 1.1 jruoho * contain an object for return to an API user.
832 1.1 jruoho *
833 1.1 jruoho ******************************************************************************/
834 1.1 jruoho
835 1.1 jruoho ACPI_STATUS
836 1.1 jruoho AcpiUtGetObjectSize (
837 1.1 jruoho ACPI_OPERAND_OBJECT *InternalObject,
838 1.1 jruoho ACPI_SIZE *ObjLength)
839 1.1 jruoho {
840 1.1 jruoho ACPI_STATUS Status;
841 1.1 jruoho
842 1.1 jruoho
843 1.1 jruoho ACPI_FUNCTION_ENTRY ();
844 1.1 jruoho
845 1.1 jruoho
846 1.1 jruoho if ((ACPI_GET_DESCRIPTOR_TYPE (InternalObject) == ACPI_DESC_TYPE_OPERAND) &&
847 1.1 jruoho (InternalObject->Common.Type == ACPI_TYPE_PACKAGE))
848 1.1 jruoho {
849 1.1 jruoho Status = AcpiUtGetPackageObjectSize (InternalObject, ObjLength);
850 1.1 jruoho }
851 1.1 jruoho else
852 1.1 jruoho {
853 1.1 jruoho Status = AcpiUtGetSimpleObjectSize (InternalObject, ObjLength);
854 1.1 jruoho }
855 1.1 jruoho
856 1.1 jruoho return (Status);
857 1.1 jruoho }
858 1.1 jruoho
859 1.1 jruoho
860