utobject.c revision 1.1.1.2.10.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.1.2 jruoho /*
8 1.1.1.2.10.1 yamt * Copyright (C) 2000 - 2013, Intel Corp.
9 1.1 jruoho * All rights reserved.
10 1.1 jruoho *
11 1.1.1.2 jruoho * Redistribution and use in source and binary forms, with or without
12 1.1.1.2 jruoho * modification, are permitted provided that the following conditions
13 1.1.1.2 jruoho * are met:
14 1.1.1.2 jruoho * 1. Redistributions of source code must retain the above copyright
15 1.1.1.2 jruoho * notice, this list of conditions, and the following disclaimer,
16 1.1.1.2 jruoho * without modification.
17 1.1.1.2 jruoho * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.1.1.2 jruoho * substantially similar to the "NO WARRANTY" disclaimer below
19 1.1.1.2 jruoho * ("Disclaimer") and any redistribution must be conditioned upon
20 1.1.1.2 jruoho * including a substantially similar Disclaimer requirement for further
21 1.1.1.2 jruoho * binary redistribution.
22 1.1.1.2 jruoho * 3. Neither the names of the above-listed copyright holders nor the names
23 1.1.1.2 jruoho * of any contributors may be used to endorse or promote products derived
24 1.1.1.2 jruoho * from this software without specific prior written permission.
25 1.1.1.2 jruoho *
26 1.1.1.2 jruoho * Alternatively, this software may be distributed under the terms of the
27 1.1.1.2 jruoho * GNU General Public License ("GPL") version 2 as published by the Free
28 1.1.1.2 jruoho * Software Foundation.
29 1.1.1.2 jruoho *
30 1.1.1.2 jruoho * NO WARRANTY
31 1.1.1.2 jruoho * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.1.1.2 jruoho * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.1.1.2 jruoho * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.1.1.2 jruoho * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.1.1.2 jruoho * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.1.1.2 jruoho * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.1.1.2 jruoho * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.1.1.2 jruoho * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.1.1.2 jruoho * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.1.1.2 jruoho * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.1.1.2 jruoho * POSSIBILITY OF SUCH DAMAGES.
42 1.1.1.2 jruoho */
43 1.1 jruoho
44 1.1 jruoho #define __UTOBJECT_C__
45 1.1 jruoho
46 1.1 jruoho #include "acpi.h"
47 1.1 jruoho #include "accommon.h"
48 1.1 jruoho #include "acnamesp.h"
49 1.1 jruoho
50 1.1 jruoho
51 1.1 jruoho #define _COMPONENT ACPI_UTILITIES
52 1.1 jruoho ACPI_MODULE_NAME ("utobject")
53 1.1 jruoho
54 1.1 jruoho /* Local prototypes */
55 1.1 jruoho
56 1.1 jruoho static ACPI_STATUS
57 1.1 jruoho AcpiUtGetSimpleObjectSize (
58 1.1 jruoho ACPI_OPERAND_OBJECT *Obj,
59 1.1 jruoho ACPI_SIZE *ObjLength);
60 1.1 jruoho
61 1.1 jruoho static ACPI_STATUS
62 1.1 jruoho AcpiUtGetPackageObjectSize (
63 1.1 jruoho ACPI_OPERAND_OBJECT *Obj,
64 1.1 jruoho ACPI_SIZE *ObjLength);
65 1.1 jruoho
66 1.1 jruoho static ACPI_STATUS
67 1.1 jruoho AcpiUtGetElementLength (
68 1.1 jruoho UINT8 ObjectType,
69 1.1 jruoho ACPI_OPERAND_OBJECT *SourceObject,
70 1.1 jruoho ACPI_GENERIC_STATE *State,
71 1.1 jruoho void *Context);
72 1.1 jruoho
73 1.1 jruoho
74 1.1 jruoho /*******************************************************************************
75 1.1 jruoho *
76 1.1 jruoho * FUNCTION: AcpiUtCreateInternalObjectDbg
77 1.1 jruoho *
78 1.1 jruoho * PARAMETERS: ModuleName - Source file name of caller
79 1.1 jruoho * LineNumber - Line number of caller
80 1.1 jruoho * ComponentId - Component type of caller
81 1.1 jruoho * Type - ACPI Type of the new object
82 1.1 jruoho *
83 1.1 jruoho * RETURN: A new internal object, null on failure
84 1.1 jruoho *
85 1.1 jruoho * DESCRIPTION: Create and initialize a new internal object.
86 1.1 jruoho *
87 1.1 jruoho * NOTE: We always allocate the worst-case object descriptor because
88 1.1 jruoho * these objects are cached, and we want them to be
89 1.1.1.2.10.1 yamt * one-size-satisifies-any-request. This in itself may not be
90 1.1 jruoho * the most memory efficient, but the efficiency of the object
91 1.1 jruoho * cache should more than make up for this!
92 1.1 jruoho *
93 1.1 jruoho ******************************************************************************/
94 1.1 jruoho
95 1.1 jruoho ACPI_OPERAND_OBJECT *
96 1.1 jruoho AcpiUtCreateInternalObjectDbg (
97 1.1 jruoho const char *ModuleName,
98 1.1 jruoho UINT32 LineNumber,
99 1.1 jruoho UINT32 ComponentId,
100 1.1 jruoho ACPI_OBJECT_TYPE Type)
101 1.1 jruoho {
102 1.1 jruoho ACPI_OPERAND_OBJECT *Object;
103 1.1 jruoho ACPI_OPERAND_OBJECT *SecondObject;
104 1.1 jruoho
105 1.1 jruoho
106 1.1 jruoho ACPI_FUNCTION_TRACE_STR (UtCreateInternalObjectDbg,
107 1.1 jruoho AcpiUtGetTypeName (Type));
108 1.1 jruoho
109 1.1 jruoho
110 1.1 jruoho /* Allocate the raw object descriptor */
111 1.1 jruoho
112 1.1 jruoho Object = AcpiUtAllocateObjectDescDbg (ModuleName, LineNumber, ComponentId);
113 1.1 jruoho if (!Object)
114 1.1 jruoho {
115 1.1 jruoho return_PTR (NULL);
116 1.1 jruoho }
117 1.1 jruoho
118 1.1 jruoho switch (Type)
119 1.1 jruoho {
120 1.1 jruoho case ACPI_TYPE_REGION:
121 1.1 jruoho case ACPI_TYPE_BUFFER_FIELD:
122 1.1 jruoho case ACPI_TYPE_LOCAL_BANK_FIELD:
123 1.1 jruoho
124 1.1 jruoho /* These types require a secondary object */
125 1.1 jruoho
126 1.1 jruoho SecondObject = AcpiUtAllocateObjectDescDbg (ModuleName,
127 1.1 jruoho LineNumber, ComponentId);
128 1.1 jruoho if (!SecondObject)
129 1.1 jruoho {
130 1.1 jruoho AcpiUtDeleteObjectDesc (Object);
131 1.1 jruoho return_PTR (NULL);
132 1.1 jruoho }
133 1.1 jruoho
134 1.1 jruoho SecondObject->Common.Type = ACPI_TYPE_LOCAL_EXTRA;
135 1.1 jruoho SecondObject->Common.ReferenceCount = 1;
136 1.1 jruoho
137 1.1 jruoho /* Link the second object to the first */
138 1.1 jruoho
139 1.1 jruoho Object->Common.NextObject = SecondObject;
140 1.1 jruoho break;
141 1.1 jruoho
142 1.1 jruoho default:
143 1.1.1.2.10.1 yamt
144 1.1 jruoho /* All others have no secondary object */
145 1.1 jruoho break;
146 1.1 jruoho }
147 1.1 jruoho
148 1.1 jruoho /* Save the object type in the object descriptor */
149 1.1 jruoho
150 1.1 jruoho Object->Common.Type = (UINT8) Type;
151 1.1 jruoho
152 1.1 jruoho /* Init the reference count */
153 1.1 jruoho
154 1.1 jruoho Object->Common.ReferenceCount = 1;
155 1.1 jruoho
156 1.1 jruoho /* Any per-type initialization should go here */
157 1.1 jruoho
158 1.1 jruoho return_PTR (Object);
159 1.1 jruoho }
160 1.1 jruoho
161 1.1 jruoho
162 1.1 jruoho /*******************************************************************************
163 1.1 jruoho *
164 1.1 jruoho * FUNCTION: AcpiUtCreatePackageObject
165 1.1 jruoho *
166 1.1 jruoho * PARAMETERS: Count - Number of package elements
167 1.1 jruoho *
168 1.1 jruoho * RETURN: Pointer to a new Package object, null on failure
169 1.1 jruoho *
170 1.1 jruoho * DESCRIPTION: Create a fully initialized package object
171 1.1 jruoho *
172 1.1 jruoho ******************************************************************************/
173 1.1 jruoho
174 1.1 jruoho ACPI_OPERAND_OBJECT *
175 1.1 jruoho AcpiUtCreatePackageObject (
176 1.1 jruoho UINT32 Count)
177 1.1 jruoho {
178 1.1 jruoho ACPI_OPERAND_OBJECT *PackageDesc;
179 1.1 jruoho ACPI_OPERAND_OBJECT **PackageElements;
180 1.1 jruoho
181 1.1 jruoho
182 1.1 jruoho ACPI_FUNCTION_TRACE_U32 (UtCreatePackageObject, Count);
183 1.1 jruoho
184 1.1 jruoho
185 1.1 jruoho /* Create a new Package object */
186 1.1 jruoho
187 1.1 jruoho PackageDesc = AcpiUtCreateInternalObject (ACPI_TYPE_PACKAGE);
188 1.1 jruoho if (!PackageDesc)
189 1.1 jruoho {
190 1.1 jruoho return_PTR (NULL);
191 1.1 jruoho }
192 1.1 jruoho
193 1.1 jruoho /*
194 1.1 jruoho * Create the element array. Count+1 allows the array to be null
195 1.1 jruoho * terminated.
196 1.1 jruoho */
197 1.1 jruoho PackageElements = ACPI_ALLOCATE_ZEROED (
198 1.1 jruoho ((ACPI_SIZE) Count + 1) * sizeof (void *));
199 1.1 jruoho if (!PackageElements)
200 1.1 jruoho {
201 1.1 jruoho ACPI_FREE (PackageDesc);
202 1.1 jruoho return_PTR (NULL);
203 1.1 jruoho }
204 1.1 jruoho
205 1.1 jruoho PackageDesc->Package.Count = Count;
206 1.1 jruoho PackageDesc->Package.Elements = PackageElements;
207 1.1 jruoho return_PTR (PackageDesc);
208 1.1 jruoho }
209 1.1 jruoho
210 1.1 jruoho
211 1.1 jruoho /*******************************************************************************
212 1.1 jruoho *
213 1.1 jruoho * FUNCTION: AcpiUtCreateIntegerObject
214 1.1 jruoho *
215 1.1 jruoho * PARAMETERS: InitialValue - Initial value for the integer
216 1.1 jruoho *
217 1.1 jruoho * RETURN: Pointer to a new Integer object, null on failure
218 1.1 jruoho *
219 1.1 jruoho * DESCRIPTION: Create an initialized integer object
220 1.1 jruoho *
221 1.1 jruoho ******************************************************************************/
222 1.1 jruoho
223 1.1 jruoho ACPI_OPERAND_OBJECT *
224 1.1 jruoho AcpiUtCreateIntegerObject (
225 1.1 jruoho UINT64 InitialValue)
226 1.1 jruoho {
227 1.1 jruoho ACPI_OPERAND_OBJECT *IntegerDesc;
228 1.1 jruoho
229 1.1 jruoho
230 1.1 jruoho ACPI_FUNCTION_TRACE (UtCreateIntegerObject);
231 1.1 jruoho
232 1.1 jruoho
233 1.1 jruoho /* Create and initialize a new integer object */
234 1.1 jruoho
235 1.1 jruoho IntegerDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
236 1.1 jruoho if (!IntegerDesc)
237 1.1 jruoho {
238 1.1 jruoho return_PTR (NULL);
239 1.1 jruoho }
240 1.1 jruoho
241 1.1 jruoho IntegerDesc->Integer.Value = InitialValue;
242 1.1 jruoho return_PTR (IntegerDesc);
243 1.1 jruoho }
244 1.1 jruoho
245 1.1 jruoho
246 1.1 jruoho /*******************************************************************************
247 1.1 jruoho *
248 1.1 jruoho * FUNCTION: AcpiUtCreateBufferObject
249 1.1 jruoho *
250 1.1 jruoho * PARAMETERS: BufferSize - Size of buffer to be created
251 1.1 jruoho *
252 1.1 jruoho * RETURN: Pointer to a new Buffer object, null on failure
253 1.1 jruoho *
254 1.1 jruoho * DESCRIPTION: Create a fully initialized buffer object
255 1.1 jruoho *
256 1.1 jruoho ******************************************************************************/
257 1.1 jruoho
258 1.1 jruoho ACPI_OPERAND_OBJECT *
259 1.1 jruoho AcpiUtCreateBufferObject (
260 1.1 jruoho ACPI_SIZE BufferSize)
261 1.1 jruoho {
262 1.1 jruoho ACPI_OPERAND_OBJECT *BufferDesc;
263 1.1 jruoho UINT8 *Buffer = NULL;
264 1.1 jruoho
265 1.1 jruoho
266 1.1 jruoho ACPI_FUNCTION_TRACE_U32 (UtCreateBufferObject, BufferSize);
267 1.1 jruoho
268 1.1 jruoho
269 1.1 jruoho /* Create a new Buffer object */
270 1.1 jruoho
271 1.1 jruoho BufferDesc = AcpiUtCreateInternalObject (ACPI_TYPE_BUFFER);
272 1.1 jruoho if (!BufferDesc)
273 1.1 jruoho {
274 1.1 jruoho return_PTR (NULL);
275 1.1 jruoho }
276 1.1 jruoho
277 1.1 jruoho /* Create an actual buffer only if size > 0 */
278 1.1 jruoho
279 1.1 jruoho if (BufferSize > 0)
280 1.1 jruoho {
281 1.1 jruoho /* Allocate the actual buffer */
282 1.1 jruoho
283 1.1 jruoho Buffer = ACPI_ALLOCATE_ZEROED (BufferSize);
284 1.1 jruoho if (!Buffer)
285 1.1 jruoho {
286 1.1 jruoho ACPI_ERROR ((AE_INFO, "Could not allocate size %u",
287 1.1 jruoho (UINT32) BufferSize));
288 1.1 jruoho AcpiUtRemoveReference (BufferDesc);
289 1.1 jruoho return_PTR (NULL);
290 1.1 jruoho }
291 1.1 jruoho }
292 1.1 jruoho
293 1.1 jruoho /* Complete buffer object initialization */
294 1.1 jruoho
295 1.1 jruoho BufferDesc->Buffer.Flags |= AOPOBJ_DATA_VALID;
296 1.1 jruoho BufferDesc->Buffer.Pointer = Buffer;
297 1.1 jruoho BufferDesc->Buffer.Length = (UINT32) BufferSize;
298 1.1 jruoho
299 1.1 jruoho /* Return the new buffer descriptor */
300 1.1 jruoho
301 1.1 jruoho return_PTR (BufferDesc);
302 1.1 jruoho }
303 1.1 jruoho
304 1.1 jruoho
305 1.1 jruoho /*******************************************************************************
306 1.1 jruoho *
307 1.1 jruoho * FUNCTION: AcpiUtCreateStringObject
308 1.1 jruoho *
309 1.1 jruoho * PARAMETERS: StringSize - Size of string to be created. Does not
310 1.1 jruoho * include NULL terminator, this is added
311 1.1 jruoho * automatically.
312 1.1 jruoho *
313 1.1 jruoho * RETURN: Pointer to a new String object
314 1.1 jruoho *
315 1.1 jruoho * DESCRIPTION: Create a fully initialized string object
316 1.1 jruoho *
317 1.1 jruoho ******************************************************************************/
318 1.1 jruoho
319 1.1 jruoho ACPI_OPERAND_OBJECT *
320 1.1 jruoho AcpiUtCreateStringObject (
321 1.1 jruoho ACPI_SIZE StringSize)
322 1.1 jruoho {
323 1.1 jruoho ACPI_OPERAND_OBJECT *StringDesc;
324 1.1 jruoho char *String;
325 1.1 jruoho
326 1.1 jruoho
327 1.1 jruoho ACPI_FUNCTION_TRACE_U32 (UtCreateStringObject, StringSize);
328 1.1 jruoho
329 1.1 jruoho
330 1.1 jruoho /* Create a new String object */
331 1.1 jruoho
332 1.1 jruoho StringDesc = AcpiUtCreateInternalObject (ACPI_TYPE_STRING);
333 1.1 jruoho if (!StringDesc)
334 1.1 jruoho {
335 1.1 jruoho return_PTR (NULL);
336 1.1 jruoho }
337 1.1 jruoho
338 1.1 jruoho /*
339 1.1 jruoho * Allocate the actual string buffer -- (Size + 1) for NULL terminator.
340 1.1 jruoho * NOTE: Zero-length strings are NULL terminated
341 1.1 jruoho */
342 1.1 jruoho String = ACPI_ALLOCATE_ZEROED (StringSize + 1);
343 1.1 jruoho if (!String)
344 1.1 jruoho {
345 1.1 jruoho ACPI_ERROR ((AE_INFO, "Could not allocate size %u",
346 1.1 jruoho (UINT32) StringSize));
347 1.1 jruoho AcpiUtRemoveReference (StringDesc);
348 1.1 jruoho return_PTR (NULL);
349 1.1 jruoho }
350 1.1 jruoho
351 1.1 jruoho /* Complete string object initialization */
352 1.1 jruoho
353 1.1 jruoho StringDesc->String.Pointer = String;
354 1.1 jruoho StringDesc->String.Length = (UINT32) StringSize;
355 1.1 jruoho
356 1.1 jruoho /* Return the new string descriptor */
357 1.1 jruoho
358 1.1 jruoho return_PTR (StringDesc);
359 1.1 jruoho }
360 1.1 jruoho
361 1.1 jruoho
362 1.1 jruoho /*******************************************************************************
363 1.1 jruoho *
364 1.1 jruoho * FUNCTION: AcpiUtValidInternalObject
365 1.1 jruoho *
366 1.1 jruoho * PARAMETERS: Object - Object to be validated
367 1.1 jruoho *
368 1.1 jruoho * RETURN: TRUE if object is valid, FALSE otherwise
369 1.1 jruoho *
370 1.1.1.2.10.1 yamt * DESCRIPTION: Validate a pointer to be of type ACPI_OPERAND_OBJECT
371 1.1 jruoho *
372 1.1 jruoho ******************************************************************************/
373 1.1 jruoho
374 1.1 jruoho BOOLEAN
375 1.1 jruoho AcpiUtValidInternalObject (
376 1.1 jruoho void *Object)
377 1.1 jruoho {
378 1.1 jruoho
379 1.1 jruoho ACPI_FUNCTION_NAME (UtValidInternalObject);
380 1.1 jruoho
381 1.1 jruoho
382 1.1 jruoho /* Check for a null pointer */
383 1.1 jruoho
384 1.1 jruoho if (!Object)
385 1.1 jruoho {
386 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "**** Null Object Ptr\n"));
387 1.1 jruoho return (FALSE);
388 1.1 jruoho }
389 1.1 jruoho
390 1.1 jruoho /* Check the descriptor type field */
391 1.1 jruoho
392 1.1 jruoho switch (ACPI_GET_DESCRIPTOR_TYPE (Object))
393 1.1 jruoho {
394 1.1 jruoho case ACPI_DESC_TYPE_OPERAND:
395 1.1 jruoho
396 1.1.1.2.10.1 yamt /* The object appears to be a valid ACPI_OPERAND_OBJECT */
397 1.1 jruoho
398 1.1 jruoho return (TRUE);
399 1.1 jruoho
400 1.1 jruoho default:
401 1.1.1.2.10.1 yamt
402 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
403 1.1 jruoho "%p is not not an ACPI operand obj [%s]\n",
404 1.1 jruoho Object, AcpiUtGetDescriptorName (Object)));
405 1.1 jruoho break;
406 1.1 jruoho }
407 1.1 jruoho
408 1.1 jruoho return (FALSE);
409 1.1 jruoho }
410 1.1 jruoho
411 1.1 jruoho
412 1.1 jruoho /*******************************************************************************
413 1.1 jruoho *
414 1.1 jruoho * FUNCTION: AcpiUtAllocateObjectDescDbg
415 1.1 jruoho *
416 1.1 jruoho * PARAMETERS: ModuleName - Caller's module name (for error output)
417 1.1 jruoho * LineNumber - Caller's line number (for error output)
418 1.1 jruoho * ComponentId - Caller's component ID (for error output)
419 1.1 jruoho *
420 1.1.1.2.10.1 yamt * RETURN: Pointer to newly allocated object descriptor. Null on error
421 1.1 jruoho *
422 1.1.1.2.10.1 yamt * DESCRIPTION: Allocate a new object descriptor. Gracefully handle
423 1.1 jruoho * error conditions.
424 1.1 jruoho *
425 1.1 jruoho ******************************************************************************/
426 1.1 jruoho
427 1.1 jruoho void *
428 1.1 jruoho AcpiUtAllocateObjectDescDbg (
429 1.1 jruoho const char *ModuleName,
430 1.1 jruoho UINT32 LineNumber,
431 1.1 jruoho UINT32 ComponentId)
432 1.1 jruoho {
433 1.1 jruoho ACPI_OPERAND_OBJECT *Object;
434 1.1 jruoho
435 1.1 jruoho
436 1.1 jruoho ACPI_FUNCTION_TRACE (UtAllocateObjectDescDbg);
437 1.1 jruoho
438 1.1 jruoho
439 1.1 jruoho Object = AcpiOsAcquireObject (AcpiGbl_OperandCache);
440 1.1 jruoho if (!Object)
441 1.1 jruoho {
442 1.1 jruoho ACPI_ERROR ((ModuleName, LineNumber,
443 1.1 jruoho "Could not allocate an object descriptor"));
444 1.1 jruoho
445 1.1 jruoho return_PTR (NULL);
446 1.1 jruoho }
447 1.1 jruoho
448 1.1 jruoho /* Mark the descriptor type */
449 1.1 jruoho
450 1.1 jruoho ACPI_SET_DESCRIPTOR_TYPE (Object, ACPI_DESC_TYPE_OPERAND);
451 1.1 jruoho
452 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "%p Size %X\n",
453 1.1 jruoho Object, (UINT32) sizeof (ACPI_OPERAND_OBJECT)));
454 1.1 jruoho
455 1.1 jruoho return_PTR (Object);
456 1.1 jruoho }
457 1.1 jruoho
458 1.1 jruoho
459 1.1 jruoho /*******************************************************************************
460 1.1 jruoho *
461 1.1 jruoho * FUNCTION: AcpiUtDeleteObjectDesc
462 1.1 jruoho *
463 1.1 jruoho * PARAMETERS: Object - An Acpi internal object to be deleted
464 1.1 jruoho *
465 1.1 jruoho * RETURN: None.
466 1.1 jruoho *
467 1.1 jruoho * DESCRIPTION: Free an ACPI object descriptor or add it to the object cache
468 1.1 jruoho *
469 1.1 jruoho ******************************************************************************/
470 1.1 jruoho
471 1.1 jruoho void
472 1.1 jruoho AcpiUtDeleteObjectDesc (
473 1.1 jruoho ACPI_OPERAND_OBJECT *Object)
474 1.1 jruoho {
475 1.1 jruoho ACPI_FUNCTION_TRACE_PTR (UtDeleteObjectDesc, Object);
476 1.1 jruoho
477 1.1 jruoho
478 1.1.1.2.10.1 yamt /* Object must be of type ACPI_OPERAND_OBJECT */
479 1.1 jruoho
480 1.1 jruoho if (ACPI_GET_DESCRIPTOR_TYPE (Object) != ACPI_DESC_TYPE_OPERAND)
481 1.1 jruoho {
482 1.1 jruoho ACPI_ERROR ((AE_INFO,
483 1.1 jruoho "%p is not an ACPI Operand object [%s]", Object,
484 1.1 jruoho AcpiUtGetDescriptorName (Object)));
485 1.1 jruoho return_VOID;
486 1.1 jruoho }
487 1.1 jruoho
488 1.1 jruoho (void) AcpiOsReleaseObject (AcpiGbl_OperandCache, Object);
489 1.1 jruoho return_VOID;
490 1.1 jruoho }
491 1.1 jruoho
492 1.1 jruoho
493 1.1 jruoho /*******************************************************************************
494 1.1 jruoho *
495 1.1 jruoho * FUNCTION: AcpiUtGetSimpleObjectSize
496 1.1 jruoho *
497 1.1 jruoho * PARAMETERS: InternalObject - An ACPI operand object
498 1.1 jruoho * ObjLength - Where the length is returned
499 1.1 jruoho *
500 1.1 jruoho * RETURN: Status
501 1.1 jruoho *
502 1.1 jruoho * DESCRIPTION: This function is called to determine the space required to
503 1.1 jruoho * contain a simple object for return to an external user.
504 1.1 jruoho *
505 1.1 jruoho * The length includes the object structure plus any additional
506 1.1 jruoho * needed space.
507 1.1 jruoho *
508 1.1 jruoho ******************************************************************************/
509 1.1 jruoho
510 1.1 jruoho static ACPI_STATUS
511 1.1 jruoho AcpiUtGetSimpleObjectSize (
512 1.1 jruoho ACPI_OPERAND_OBJECT *InternalObject,
513 1.1 jruoho ACPI_SIZE *ObjLength)
514 1.1 jruoho {
515 1.1 jruoho ACPI_SIZE Length;
516 1.1 jruoho ACPI_SIZE Size;
517 1.1 jruoho ACPI_STATUS Status = AE_OK;
518 1.1 jruoho
519 1.1 jruoho
520 1.1 jruoho ACPI_FUNCTION_TRACE_PTR (UtGetSimpleObjectSize, InternalObject);
521 1.1 jruoho
522 1.1 jruoho
523 1.1 jruoho /* Start with the length of the (external) Acpi object */
524 1.1 jruoho
525 1.1 jruoho Length = sizeof (ACPI_OBJECT);
526 1.1 jruoho
527 1.1 jruoho /* A NULL object is allowed, can be a legal uninitialized package element */
528 1.1 jruoho
529 1.1 jruoho if (!InternalObject)
530 1.1 jruoho {
531 1.1 jruoho /*
532 1.1 jruoho * Object is NULL, just return the length of ACPI_OBJECT
533 1.1 jruoho * (A NULL ACPI_OBJECT is an object of all zeroes.)
534 1.1 jruoho */
535 1.1 jruoho *ObjLength = ACPI_ROUND_UP_TO_NATIVE_WORD (Length);
536 1.1 jruoho return_ACPI_STATUS (AE_OK);
537 1.1 jruoho }
538 1.1 jruoho
539 1.1 jruoho /* A Namespace Node should never appear here */
540 1.1 jruoho
541 1.1 jruoho if (ACPI_GET_DESCRIPTOR_TYPE (InternalObject) == ACPI_DESC_TYPE_NAMED)
542 1.1 jruoho {
543 1.1 jruoho /* A namespace node should never get here */
544 1.1 jruoho
545 1.1 jruoho return_ACPI_STATUS (AE_AML_INTERNAL);
546 1.1 jruoho }
547 1.1 jruoho
548 1.1 jruoho /*
549 1.1 jruoho * The final length depends on the object type
550 1.1 jruoho * Strings and Buffers are packed right up against the parent object and
551 1.1 jruoho * must be accessed bytewise or there may be alignment problems on
552 1.1 jruoho * certain processors
553 1.1 jruoho */
554 1.1 jruoho switch (InternalObject->Common.Type)
555 1.1 jruoho {
556 1.1 jruoho case ACPI_TYPE_STRING:
557 1.1 jruoho
558 1.1 jruoho Length += (ACPI_SIZE) InternalObject->String.Length + 1;
559 1.1 jruoho break;
560 1.1 jruoho
561 1.1 jruoho case ACPI_TYPE_BUFFER:
562 1.1 jruoho
563 1.1 jruoho Length += (ACPI_SIZE) InternalObject->Buffer.Length;
564 1.1 jruoho break;
565 1.1 jruoho
566 1.1 jruoho case ACPI_TYPE_INTEGER:
567 1.1 jruoho case ACPI_TYPE_PROCESSOR:
568 1.1 jruoho case ACPI_TYPE_POWER:
569 1.1 jruoho
570 1.1 jruoho /* No extra data for these types */
571 1.1 jruoho
572 1.1 jruoho break;
573 1.1 jruoho
574 1.1 jruoho case ACPI_TYPE_LOCAL_REFERENCE:
575 1.1 jruoho
576 1.1 jruoho switch (InternalObject->Reference.Class)
577 1.1 jruoho {
578 1.1 jruoho case ACPI_REFCLASS_NAME:
579 1.1 jruoho /*
580 1.1 jruoho * Get the actual length of the full pathname to this object.
581 1.1 jruoho * The reference will be converted to the pathname to the object
582 1.1 jruoho */
583 1.1 jruoho Size = AcpiNsGetPathnameLength (InternalObject->Reference.Node);
584 1.1 jruoho if (!Size)
585 1.1 jruoho {
586 1.1 jruoho return_ACPI_STATUS (AE_BAD_PARAMETER);
587 1.1 jruoho }
588 1.1 jruoho
589 1.1 jruoho Length += ACPI_ROUND_UP_TO_NATIVE_WORD (Size);
590 1.1 jruoho break;
591 1.1 jruoho
592 1.1 jruoho default:
593 1.1 jruoho /*
594 1.1 jruoho * No other reference opcodes are supported.
595 1.1 jruoho * Notably, Locals and Args are not supported, but this may be
596 1.1 jruoho * required eventually.
597 1.1 jruoho */
598 1.1 jruoho ACPI_ERROR ((AE_INFO, "Cannot convert to external object - "
599 1.1 jruoho "unsupported Reference Class [%s] 0x%X in object %p",
600 1.1 jruoho AcpiUtGetReferenceName (InternalObject),
601 1.1 jruoho InternalObject->Reference.Class, InternalObject));
602 1.1 jruoho Status = AE_TYPE;
603 1.1 jruoho break;
604 1.1 jruoho }
605 1.1 jruoho break;
606 1.1 jruoho
607 1.1 jruoho default:
608 1.1 jruoho
609 1.1 jruoho ACPI_ERROR ((AE_INFO, "Cannot convert to external object - "
610 1.1 jruoho "unsupported type [%s] 0x%X in object %p",
611 1.1 jruoho AcpiUtGetObjectTypeName (InternalObject),
612 1.1 jruoho InternalObject->Common.Type, InternalObject));
613 1.1 jruoho Status = AE_TYPE;
614 1.1 jruoho break;
615 1.1 jruoho }
616 1.1 jruoho
617 1.1 jruoho /*
618 1.1 jruoho * Account for the space required by the object rounded up to the next
619 1.1.1.2.10.1 yamt * multiple of the machine word size. This keeps each object aligned
620 1.1 jruoho * on a machine word boundary. (preventing alignment faults on some
621 1.1 jruoho * machines.)
622 1.1 jruoho */
623 1.1 jruoho *ObjLength = ACPI_ROUND_UP_TO_NATIVE_WORD (Length);
624 1.1 jruoho return_ACPI_STATUS (Status);
625 1.1 jruoho }
626 1.1 jruoho
627 1.1 jruoho
628 1.1 jruoho /*******************************************************************************
629 1.1 jruoho *
630 1.1 jruoho * FUNCTION: AcpiUtGetElementLength
631 1.1 jruoho *
632 1.1 jruoho * PARAMETERS: ACPI_PKG_CALLBACK
633 1.1 jruoho *
634 1.1 jruoho * RETURN: Status
635 1.1 jruoho *
636 1.1 jruoho * DESCRIPTION: Get the length of one package element.
637 1.1 jruoho *
638 1.1 jruoho ******************************************************************************/
639 1.1 jruoho
640 1.1 jruoho static ACPI_STATUS
641 1.1 jruoho AcpiUtGetElementLength (
642 1.1 jruoho UINT8 ObjectType,
643 1.1 jruoho ACPI_OPERAND_OBJECT *SourceObject,
644 1.1 jruoho ACPI_GENERIC_STATE *State,
645 1.1 jruoho void *Context)
646 1.1 jruoho {
647 1.1 jruoho ACPI_STATUS Status = AE_OK;
648 1.1 jruoho ACPI_PKG_INFO *Info = (ACPI_PKG_INFO *) Context;
649 1.1 jruoho ACPI_SIZE ObjectSpace;
650 1.1 jruoho
651 1.1 jruoho
652 1.1 jruoho switch (ObjectType)
653 1.1 jruoho {
654 1.1 jruoho case ACPI_COPY_TYPE_SIMPLE:
655 1.1 jruoho /*
656 1.1 jruoho * Simple object - just get the size (Null object/entry is handled
657 1.1 jruoho * here also) and sum it into the running package length
658 1.1 jruoho */
659 1.1 jruoho Status = AcpiUtGetSimpleObjectSize (SourceObject, &ObjectSpace);
660 1.1 jruoho if (ACPI_FAILURE (Status))
661 1.1 jruoho {
662 1.1 jruoho return (Status);
663 1.1 jruoho }
664 1.1 jruoho
665 1.1 jruoho Info->Length += ObjectSpace;
666 1.1 jruoho break;
667 1.1 jruoho
668 1.1 jruoho case ACPI_COPY_TYPE_PACKAGE:
669 1.1 jruoho
670 1.1 jruoho /* Package object - nothing much to do here, let the walk handle it */
671 1.1 jruoho
672 1.1 jruoho Info->NumPackages++;
673 1.1 jruoho State->Pkg.ThisTargetObj = NULL;
674 1.1 jruoho break;
675 1.1 jruoho
676 1.1 jruoho default:
677 1.1 jruoho
678 1.1 jruoho /* No other types allowed */
679 1.1 jruoho
680 1.1 jruoho return (AE_BAD_PARAMETER);
681 1.1 jruoho }
682 1.1 jruoho
683 1.1 jruoho return (Status);
684 1.1 jruoho }
685 1.1 jruoho
686 1.1 jruoho
687 1.1 jruoho /*******************************************************************************
688 1.1 jruoho *
689 1.1 jruoho * FUNCTION: AcpiUtGetPackageObjectSize
690 1.1 jruoho *
691 1.1 jruoho * PARAMETERS: InternalObject - An ACPI internal object
692 1.1 jruoho * ObjLength - Where the length is returned
693 1.1 jruoho *
694 1.1 jruoho * RETURN: Status
695 1.1 jruoho *
696 1.1 jruoho * DESCRIPTION: This function is called to determine the space required to
697 1.1 jruoho * contain a package object for return to an external user.
698 1.1 jruoho *
699 1.1 jruoho * This is moderately complex since a package contains other
700 1.1 jruoho * objects including packages.
701 1.1 jruoho *
702 1.1 jruoho ******************************************************************************/
703 1.1 jruoho
704 1.1 jruoho static ACPI_STATUS
705 1.1 jruoho AcpiUtGetPackageObjectSize (
706 1.1 jruoho ACPI_OPERAND_OBJECT *InternalObject,
707 1.1 jruoho ACPI_SIZE *ObjLength)
708 1.1 jruoho {
709 1.1 jruoho ACPI_STATUS Status;
710 1.1 jruoho ACPI_PKG_INFO Info;
711 1.1 jruoho
712 1.1 jruoho
713 1.1 jruoho ACPI_FUNCTION_TRACE_PTR (UtGetPackageObjectSize, InternalObject);
714 1.1 jruoho
715 1.1 jruoho
716 1.1 jruoho Info.Length = 0;
717 1.1 jruoho Info.ObjectSpace = 0;
718 1.1 jruoho Info.NumPackages = 1;
719 1.1 jruoho
720 1.1 jruoho Status = AcpiUtWalkPackageTree (InternalObject, NULL,
721 1.1.1.2.10.1 yamt AcpiUtGetElementLength, &Info);
722 1.1 jruoho if (ACPI_FAILURE (Status))
723 1.1 jruoho {
724 1.1 jruoho return_ACPI_STATUS (Status);
725 1.1 jruoho }
726 1.1 jruoho
727 1.1 jruoho /*
728 1.1 jruoho * We have handled all of the objects in all levels of the package.
729 1.1 jruoho * just add the length of the package objects themselves.
730 1.1 jruoho * Round up to the next machine word.
731 1.1 jruoho */
732 1.1 jruoho Info.Length += ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT)) *
733 1.1 jruoho (ACPI_SIZE) Info.NumPackages;
734 1.1 jruoho
735 1.1 jruoho /* Return the total package length */
736 1.1 jruoho
737 1.1 jruoho *ObjLength = Info.Length;
738 1.1 jruoho return_ACPI_STATUS (Status);
739 1.1 jruoho }
740 1.1 jruoho
741 1.1 jruoho
742 1.1 jruoho /*******************************************************************************
743 1.1 jruoho *
744 1.1 jruoho * FUNCTION: AcpiUtGetObjectSize
745 1.1 jruoho *
746 1.1 jruoho * PARAMETERS: InternalObject - An ACPI internal object
747 1.1 jruoho * ObjLength - Where the length will be returned
748 1.1 jruoho *
749 1.1 jruoho * RETURN: Status
750 1.1 jruoho *
751 1.1 jruoho * DESCRIPTION: This function is called to determine the space required to
752 1.1 jruoho * contain an object for return to an API user.
753 1.1 jruoho *
754 1.1 jruoho ******************************************************************************/
755 1.1 jruoho
756 1.1 jruoho ACPI_STATUS
757 1.1 jruoho AcpiUtGetObjectSize (
758 1.1 jruoho ACPI_OPERAND_OBJECT *InternalObject,
759 1.1 jruoho ACPI_SIZE *ObjLength)
760 1.1 jruoho {
761 1.1 jruoho ACPI_STATUS Status;
762 1.1 jruoho
763 1.1 jruoho
764 1.1 jruoho ACPI_FUNCTION_ENTRY ();
765 1.1 jruoho
766 1.1 jruoho
767 1.1 jruoho if ((ACPI_GET_DESCRIPTOR_TYPE (InternalObject) == ACPI_DESC_TYPE_OPERAND) &&
768 1.1 jruoho (InternalObject->Common.Type == ACPI_TYPE_PACKAGE))
769 1.1 jruoho {
770 1.1 jruoho Status = AcpiUtGetPackageObjectSize (InternalObject, ObjLength);
771 1.1 jruoho }
772 1.1 jruoho else
773 1.1 jruoho {
774 1.1 jruoho Status = AcpiUtGetSimpleObjectSize (InternalObject, ObjLength);
775 1.1 jruoho }
776 1.1 jruoho
777 1.1 jruoho return (Status);
778 1.1 jruoho }
779