dsobject.c revision 1.1.1.3 1 1.1 jruoho /******************************************************************************
2 1.1 jruoho *
3 1.1 jruoho * Module Name: dsobject - Dispatcher object management routines
4 1.1 jruoho *
5 1.1 jruoho *****************************************************************************/
6 1.1 jruoho
7 1.1.1.2 jruoho /*
8 1.1.1.3 christos * 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 __DSOBJECT_C__
45 1.1 jruoho
46 1.1 jruoho #include "acpi.h"
47 1.1 jruoho #include "accommon.h"
48 1.1 jruoho #include "acparser.h"
49 1.1 jruoho #include "amlcode.h"
50 1.1 jruoho #include "acdispat.h"
51 1.1 jruoho #include "acnamesp.h"
52 1.1 jruoho #include "acinterp.h"
53 1.1 jruoho
54 1.1 jruoho #define _COMPONENT ACPI_DISPATCHER
55 1.1 jruoho ACPI_MODULE_NAME ("dsobject")
56 1.1 jruoho
57 1.1 jruoho /* Local prototypes */
58 1.1 jruoho
59 1.1 jruoho static ACPI_STATUS
60 1.1 jruoho AcpiDsBuildInternalObject (
61 1.1 jruoho ACPI_WALK_STATE *WalkState,
62 1.1 jruoho ACPI_PARSE_OBJECT *Op,
63 1.1 jruoho ACPI_OPERAND_OBJECT **ObjDescPtr);
64 1.1 jruoho
65 1.1 jruoho
66 1.1 jruoho #ifndef ACPI_NO_METHOD_EXECUTION
67 1.1 jruoho /*******************************************************************************
68 1.1 jruoho *
69 1.1 jruoho * FUNCTION: AcpiDsBuildInternalObject
70 1.1 jruoho *
71 1.1 jruoho * PARAMETERS: WalkState - Current walk state
72 1.1 jruoho * Op - Parser object to be translated
73 1.1 jruoho * ObjDescPtr - Where the ACPI internal object is returned
74 1.1 jruoho *
75 1.1 jruoho * RETURN: Status
76 1.1 jruoho *
77 1.1 jruoho * DESCRIPTION: Translate a parser Op object to the equivalent namespace object
78 1.1 jruoho * Simple objects are any objects other than a package object!
79 1.1 jruoho *
80 1.1 jruoho ******************************************************************************/
81 1.1 jruoho
82 1.1 jruoho static ACPI_STATUS
83 1.1 jruoho AcpiDsBuildInternalObject (
84 1.1 jruoho ACPI_WALK_STATE *WalkState,
85 1.1 jruoho ACPI_PARSE_OBJECT *Op,
86 1.1 jruoho ACPI_OPERAND_OBJECT **ObjDescPtr)
87 1.1 jruoho {
88 1.1 jruoho ACPI_OPERAND_OBJECT *ObjDesc;
89 1.1 jruoho ACPI_STATUS Status;
90 1.1.1.2 jruoho ACPI_OBJECT_TYPE Type;
91 1.1 jruoho
92 1.1 jruoho
93 1.1 jruoho ACPI_FUNCTION_TRACE (DsBuildInternalObject);
94 1.1 jruoho
95 1.1 jruoho
96 1.1 jruoho *ObjDescPtr = NULL;
97 1.1 jruoho if (Op->Common.AmlOpcode == AML_INT_NAMEPATH_OP)
98 1.1 jruoho {
99 1.1 jruoho /*
100 1.1 jruoho * This is a named object reference. If this name was
101 1.1 jruoho * previously looked up in the namespace, it was stored in this op.
102 1.1 jruoho * Otherwise, go ahead and look it up now
103 1.1 jruoho */
104 1.1 jruoho if (!Op->Common.Node)
105 1.1 jruoho {
106 1.1 jruoho Status = AcpiNsLookup (WalkState->ScopeInfo,
107 1.1 jruoho Op->Common.Value.String,
108 1.1 jruoho ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
109 1.1 jruoho ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE, NULL,
110 1.1 jruoho ACPI_CAST_INDIRECT_PTR (ACPI_NAMESPACE_NODE, &(Op->Common.Node)));
111 1.1 jruoho if (ACPI_FAILURE (Status))
112 1.1 jruoho {
113 1.1 jruoho /* Check if we are resolving a named reference within a package */
114 1.1 jruoho
115 1.1 jruoho if ((Status == AE_NOT_FOUND) && (AcpiGbl_EnableInterpreterSlack) &&
116 1.1 jruoho
117 1.1 jruoho ((Op->Common.Parent->Common.AmlOpcode == AML_PACKAGE_OP) ||
118 1.1 jruoho (Op->Common.Parent->Common.AmlOpcode == AML_VAR_PACKAGE_OP)))
119 1.1 jruoho {
120 1.1 jruoho /*
121 1.1 jruoho * We didn't find the target and we are populating elements
122 1.1 jruoho * of a package - ignore if slack enabled. Some ASL code
123 1.1 jruoho * contains dangling invalid references in packages and
124 1.1 jruoho * expects that no exception will be issued. Leave the
125 1.1 jruoho * element as a null element. It cannot be used, but it
126 1.1 jruoho * can be overwritten by subsequent ASL code - this is
127 1.1 jruoho * typically the case.
128 1.1 jruoho */
129 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
130 1.1 jruoho "Ignoring unresolved reference in package [%4.4s]\n",
131 1.1 jruoho WalkState->ScopeInfo->Scope.Node->Name.Ascii));
132 1.1 jruoho
133 1.1 jruoho return_ACPI_STATUS (AE_OK);
134 1.1 jruoho }
135 1.1 jruoho else
136 1.1 jruoho {
137 1.1 jruoho ACPI_ERROR_NAMESPACE (Op->Common.Value.String, Status);
138 1.1 jruoho }
139 1.1 jruoho
140 1.1 jruoho return_ACPI_STATUS (Status);
141 1.1 jruoho }
142 1.1 jruoho }
143 1.1 jruoho
144 1.1 jruoho /* Special object resolution for elements of a package */
145 1.1 jruoho
146 1.1 jruoho if ((Op->Common.Parent->Common.AmlOpcode == AML_PACKAGE_OP) ||
147 1.1 jruoho (Op->Common.Parent->Common.AmlOpcode == AML_VAR_PACKAGE_OP))
148 1.1 jruoho {
149 1.1 jruoho /*
150 1.1 jruoho * Attempt to resolve the node to a value before we insert it into
151 1.1 jruoho * the package. If this is a reference to a common data type,
152 1.1 jruoho * resolve it immediately. According to the ACPI spec, package
153 1.1 jruoho * elements can only be "data objects" or method references.
154 1.1 jruoho * Attempt to resolve to an Integer, Buffer, String or Package.
155 1.1 jruoho * If cannot, return the named reference (for things like Devices,
156 1.1 jruoho * Methods, etc.) Buffer Fields and Fields will resolve to simple
157 1.1 jruoho * objects (int/buf/str/pkg).
158 1.1 jruoho *
159 1.1 jruoho * NOTE: References to things like Devices, Methods, Mutexes, etc.
160 1.1 jruoho * will remain as named references. This behavior is not described
161 1.1 jruoho * in the ACPI spec, but it appears to be an oversight.
162 1.1 jruoho */
163 1.1 jruoho ObjDesc = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, Op->Common.Node);
164 1.1 jruoho
165 1.1 jruoho Status = AcpiExResolveNodeToValue (
166 1.1 jruoho ACPI_CAST_INDIRECT_PTR (ACPI_NAMESPACE_NODE, &ObjDesc),
167 1.1 jruoho WalkState);
168 1.1 jruoho if (ACPI_FAILURE (Status))
169 1.1 jruoho {
170 1.1 jruoho return_ACPI_STATUS (Status);
171 1.1 jruoho }
172 1.1 jruoho
173 1.1.1.2 jruoho /*
174 1.1.1.2 jruoho * Special handling for Alias objects. We need to setup the type
175 1.1.1.2 jruoho * and the Op->Common.Node to point to the Alias target. Note,
176 1.1.1.2 jruoho * Alias has at most one level of indirection internally.
177 1.1.1.2 jruoho */
178 1.1.1.2 jruoho Type = Op->Common.Node->Type;
179 1.1.1.2 jruoho if (Type == ACPI_TYPE_LOCAL_ALIAS)
180 1.1.1.2 jruoho {
181 1.1.1.2 jruoho Type = ObjDesc->Common.Type;
182 1.1.1.2 jruoho Op->Common.Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE,
183 1.1.1.2 jruoho Op->Common.Node->Object);
184 1.1.1.2 jruoho }
185 1.1.1.2 jruoho
186 1.1.1.2 jruoho switch (Type)
187 1.1 jruoho {
188 1.1 jruoho /*
189 1.1 jruoho * For these types, we need the actual node, not the subobject.
190 1.1 jruoho * However, the subobject did not get an extra reference count above.
191 1.1 jruoho *
192 1.1 jruoho * TBD: should ExResolveNodeToValue be changed to fix this?
193 1.1 jruoho */
194 1.1 jruoho case ACPI_TYPE_DEVICE:
195 1.1 jruoho case ACPI_TYPE_THERMAL:
196 1.1 jruoho
197 1.1 jruoho AcpiUtAddReference (Op->Common.Node->Object);
198 1.1 jruoho
199 1.1 jruoho /*lint -fallthrough */
200 1.1 jruoho /*
201 1.1 jruoho * For these types, we need the actual node, not the subobject.
202 1.1 jruoho * The subobject got an extra reference count in ExResolveNodeToValue.
203 1.1 jruoho */
204 1.1 jruoho case ACPI_TYPE_MUTEX:
205 1.1 jruoho case ACPI_TYPE_METHOD:
206 1.1 jruoho case ACPI_TYPE_POWER:
207 1.1 jruoho case ACPI_TYPE_PROCESSOR:
208 1.1 jruoho case ACPI_TYPE_EVENT:
209 1.1 jruoho case ACPI_TYPE_REGION:
210 1.1 jruoho
211 1.1 jruoho /* We will create a reference object for these types below */
212 1.1 jruoho break;
213 1.1 jruoho
214 1.1 jruoho default:
215 1.1 jruoho /*
216 1.1 jruoho * All other types - the node was resolved to an actual
217 1.1 jruoho * object, we are done.
218 1.1 jruoho */
219 1.1 jruoho goto Exit;
220 1.1 jruoho }
221 1.1 jruoho }
222 1.1 jruoho }
223 1.1 jruoho
224 1.1 jruoho /* Create and init a new internal ACPI object */
225 1.1 jruoho
226 1.1 jruoho ObjDesc = AcpiUtCreateInternalObject (
227 1.1 jruoho (AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode))->ObjectType);
228 1.1 jruoho if (!ObjDesc)
229 1.1 jruoho {
230 1.1 jruoho return_ACPI_STATUS (AE_NO_MEMORY);
231 1.1 jruoho }
232 1.1 jruoho
233 1.1 jruoho Status = AcpiDsInitObjectFromOp (WalkState, Op, Op->Common.AmlOpcode,
234 1.1 jruoho &ObjDesc);
235 1.1 jruoho if (ACPI_FAILURE (Status))
236 1.1 jruoho {
237 1.1 jruoho AcpiUtRemoveReference (ObjDesc);
238 1.1 jruoho return_ACPI_STATUS (Status);
239 1.1 jruoho }
240 1.1 jruoho
241 1.1 jruoho Exit:
242 1.1 jruoho *ObjDescPtr = ObjDesc;
243 1.1 jruoho return_ACPI_STATUS (Status);
244 1.1 jruoho }
245 1.1 jruoho
246 1.1 jruoho
247 1.1 jruoho /*******************************************************************************
248 1.1 jruoho *
249 1.1 jruoho * FUNCTION: AcpiDsBuildInternalBufferObj
250 1.1 jruoho *
251 1.1 jruoho * PARAMETERS: WalkState - Current walk state
252 1.1 jruoho * Op - Parser object to be translated
253 1.1 jruoho * BufferLength - Length of the buffer
254 1.1 jruoho * ObjDescPtr - Where the ACPI internal object is returned
255 1.1 jruoho *
256 1.1 jruoho * RETURN: Status
257 1.1 jruoho *
258 1.1 jruoho * DESCRIPTION: Translate a parser Op package object to the equivalent
259 1.1 jruoho * namespace object
260 1.1 jruoho *
261 1.1 jruoho ******************************************************************************/
262 1.1 jruoho
263 1.1 jruoho ACPI_STATUS
264 1.1 jruoho AcpiDsBuildInternalBufferObj (
265 1.1 jruoho ACPI_WALK_STATE *WalkState,
266 1.1 jruoho ACPI_PARSE_OBJECT *Op,
267 1.1 jruoho UINT32 BufferLength,
268 1.1 jruoho ACPI_OPERAND_OBJECT **ObjDescPtr)
269 1.1 jruoho {
270 1.1 jruoho ACPI_PARSE_OBJECT *Arg;
271 1.1 jruoho ACPI_OPERAND_OBJECT *ObjDesc;
272 1.1 jruoho ACPI_PARSE_OBJECT *ByteList;
273 1.1 jruoho UINT32 ByteListLength = 0;
274 1.1 jruoho
275 1.1 jruoho
276 1.1 jruoho ACPI_FUNCTION_TRACE (DsBuildInternalBufferObj);
277 1.1 jruoho
278 1.1 jruoho
279 1.1 jruoho /*
280 1.1 jruoho * If we are evaluating a Named buffer object "Name (xxxx, Buffer)".
281 1.1 jruoho * The buffer object already exists (from the NS node), otherwise it must
282 1.1 jruoho * be created.
283 1.1 jruoho */
284 1.1 jruoho ObjDesc = *ObjDescPtr;
285 1.1 jruoho if (!ObjDesc)
286 1.1 jruoho {
287 1.1 jruoho /* Create a new buffer object */
288 1.1 jruoho
289 1.1 jruoho ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_BUFFER);
290 1.1 jruoho *ObjDescPtr = ObjDesc;
291 1.1 jruoho if (!ObjDesc)
292 1.1 jruoho {
293 1.1 jruoho return_ACPI_STATUS (AE_NO_MEMORY);
294 1.1 jruoho }
295 1.1 jruoho }
296 1.1 jruoho
297 1.1 jruoho /*
298 1.1 jruoho * Second arg is the buffer data (optional) ByteList can be either
299 1.1.1.3 christos * individual bytes or a string initializer. In either case, a
300 1.1 jruoho * ByteList appears in the AML.
301 1.1 jruoho */
302 1.1 jruoho Arg = Op->Common.Value.Arg; /* skip first arg */
303 1.1 jruoho
304 1.1 jruoho ByteList = Arg->Named.Next;
305 1.1 jruoho if (ByteList)
306 1.1 jruoho {
307 1.1 jruoho if (ByteList->Common.AmlOpcode != AML_INT_BYTELIST_OP)
308 1.1 jruoho {
309 1.1 jruoho ACPI_ERROR ((AE_INFO,
310 1.1 jruoho "Expecting bytelist, found AML opcode 0x%X in op %p",
311 1.1 jruoho ByteList->Common.AmlOpcode, ByteList));
312 1.1 jruoho
313 1.1 jruoho AcpiUtRemoveReference (ObjDesc);
314 1.1 jruoho return (AE_TYPE);
315 1.1 jruoho }
316 1.1 jruoho
317 1.1 jruoho ByteListLength = (UINT32) ByteList->Common.Value.Integer;
318 1.1 jruoho }
319 1.1 jruoho
320 1.1 jruoho /*
321 1.1 jruoho * The buffer length (number of bytes) will be the larger of:
322 1.1 jruoho * 1) The specified buffer length and
323 1.1 jruoho * 2) The length of the initializer byte list
324 1.1 jruoho */
325 1.1 jruoho ObjDesc->Buffer.Length = BufferLength;
326 1.1 jruoho if (ByteListLength > BufferLength)
327 1.1 jruoho {
328 1.1 jruoho ObjDesc->Buffer.Length = ByteListLength;
329 1.1 jruoho }
330 1.1 jruoho
331 1.1 jruoho /* Allocate the buffer */
332 1.1 jruoho
333 1.1 jruoho if (ObjDesc->Buffer.Length == 0)
334 1.1 jruoho {
335 1.1 jruoho ObjDesc->Buffer.Pointer = NULL;
336 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
337 1.1 jruoho "Buffer defined with zero length in AML, creating\n"));
338 1.1 jruoho }
339 1.1 jruoho else
340 1.1 jruoho {
341 1.1 jruoho ObjDesc->Buffer.Pointer = ACPI_ALLOCATE_ZEROED (
342 1.1 jruoho ObjDesc->Buffer.Length);
343 1.1 jruoho if (!ObjDesc->Buffer.Pointer)
344 1.1 jruoho {
345 1.1 jruoho AcpiUtDeleteObjectDesc (ObjDesc);
346 1.1 jruoho return_ACPI_STATUS (AE_NO_MEMORY);
347 1.1 jruoho }
348 1.1 jruoho
349 1.1 jruoho /* Initialize buffer from the ByteList (if present) */
350 1.1 jruoho
351 1.1 jruoho if (ByteList)
352 1.1 jruoho {
353 1.1 jruoho ACPI_MEMCPY (ObjDesc->Buffer.Pointer, ByteList->Named.Data,
354 1.1 jruoho ByteListLength);
355 1.1 jruoho }
356 1.1 jruoho }
357 1.1 jruoho
358 1.1 jruoho ObjDesc->Buffer.Flags |= AOPOBJ_DATA_VALID;
359 1.1 jruoho Op->Common.Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjDesc);
360 1.1 jruoho return_ACPI_STATUS (AE_OK);
361 1.1 jruoho }
362 1.1 jruoho
363 1.1 jruoho
364 1.1 jruoho /*******************************************************************************
365 1.1 jruoho *
366 1.1 jruoho * FUNCTION: AcpiDsBuildInternalPackageObj
367 1.1 jruoho *
368 1.1 jruoho * PARAMETERS: WalkState - Current walk state
369 1.1 jruoho * Op - Parser object to be translated
370 1.1 jruoho * ElementCount - Number of elements in the package - this is
371 1.1 jruoho * the NumElements argument to Package()
372 1.1 jruoho * ObjDescPtr - Where the ACPI internal object is returned
373 1.1 jruoho *
374 1.1 jruoho * RETURN: Status
375 1.1 jruoho *
376 1.1 jruoho * DESCRIPTION: Translate a parser Op package object to the equivalent
377 1.1 jruoho * namespace object
378 1.1 jruoho *
379 1.1 jruoho * NOTE: The number of elements in the package will be always be the NumElements
380 1.1 jruoho * count, regardless of the number of elements in the package list. If
381 1.1 jruoho * NumElements is smaller, only that many package list elements are used.
382 1.1 jruoho * if NumElements is larger, the Package object is padded out with
383 1.1 jruoho * objects of type Uninitialized (as per ACPI spec.)
384 1.1 jruoho *
385 1.1 jruoho * Even though the ASL compilers do not allow NumElements to be smaller
386 1.1 jruoho * than the Package list length (for the fixed length package opcode), some
387 1.1 jruoho * BIOS code modifies the AML on the fly to adjust the NumElements, and
388 1.1 jruoho * this code compensates for that. This also provides compatibility with
389 1.1 jruoho * other AML interpreters.
390 1.1 jruoho *
391 1.1 jruoho ******************************************************************************/
392 1.1 jruoho
393 1.1 jruoho ACPI_STATUS
394 1.1 jruoho AcpiDsBuildInternalPackageObj (
395 1.1 jruoho ACPI_WALK_STATE *WalkState,
396 1.1 jruoho ACPI_PARSE_OBJECT *Op,
397 1.1 jruoho UINT32 ElementCount,
398 1.1 jruoho ACPI_OPERAND_OBJECT **ObjDescPtr)
399 1.1 jruoho {
400 1.1 jruoho ACPI_PARSE_OBJECT *Arg;
401 1.1 jruoho ACPI_PARSE_OBJECT *Parent;
402 1.1 jruoho ACPI_OPERAND_OBJECT *ObjDesc = NULL;
403 1.1 jruoho ACPI_STATUS Status = AE_OK;
404 1.1 jruoho UINT32 i;
405 1.1 jruoho UINT16 Index;
406 1.1 jruoho UINT16 ReferenceCount;
407 1.1 jruoho
408 1.1 jruoho
409 1.1 jruoho ACPI_FUNCTION_TRACE (DsBuildInternalPackageObj);
410 1.1 jruoho
411 1.1 jruoho
412 1.1 jruoho /* Find the parent of a possibly nested package */
413 1.1 jruoho
414 1.1 jruoho Parent = Op->Common.Parent;
415 1.1 jruoho while ((Parent->Common.AmlOpcode == AML_PACKAGE_OP) ||
416 1.1 jruoho (Parent->Common.AmlOpcode == AML_VAR_PACKAGE_OP))
417 1.1 jruoho {
418 1.1 jruoho Parent = Parent->Common.Parent;
419 1.1 jruoho }
420 1.1 jruoho
421 1.1 jruoho /*
422 1.1 jruoho * If we are evaluating a Named package object "Name (xxxx, Package)",
423 1.1 jruoho * the package object already exists, otherwise it must be created.
424 1.1 jruoho */
425 1.1 jruoho ObjDesc = *ObjDescPtr;
426 1.1 jruoho if (!ObjDesc)
427 1.1 jruoho {
428 1.1 jruoho ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_PACKAGE);
429 1.1 jruoho *ObjDescPtr = ObjDesc;
430 1.1 jruoho if (!ObjDesc)
431 1.1 jruoho {
432 1.1 jruoho return_ACPI_STATUS (AE_NO_MEMORY);
433 1.1 jruoho }
434 1.1 jruoho
435 1.1 jruoho ObjDesc->Package.Node = Parent->Common.Node;
436 1.1 jruoho }
437 1.1 jruoho
438 1.1 jruoho /*
439 1.1 jruoho * Allocate the element array (array of pointers to the individual
440 1.1 jruoho * objects) based on the NumElements parameter. Add an extra pointer slot
441 1.1 jruoho * so that the list is always null terminated.
442 1.1 jruoho */
443 1.1 jruoho ObjDesc->Package.Elements = ACPI_ALLOCATE_ZEROED (
444 1.1 jruoho ((ACPI_SIZE) ElementCount + 1) * sizeof (void *));
445 1.1 jruoho
446 1.1 jruoho if (!ObjDesc->Package.Elements)
447 1.1 jruoho {
448 1.1 jruoho AcpiUtDeleteObjectDesc (ObjDesc);
449 1.1 jruoho return_ACPI_STATUS (AE_NO_MEMORY);
450 1.1 jruoho }
451 1.1 jruoho
452 1.1 jruoho ObjDesc->Package.Count = ElementCount;
453 1.1 jruoho
454 1.1 jruoho /*
455 1.1 jruoho * Initialize the elements of the package, up to the NumElements count.
456 1.1 jruoho * Package is automatically padded with uninitialized (NULL) elements
457 1.1 jruoho * if NumElements is greater than the package list length. Likewise,
458 1.1 jruoho * Package is truncated if NumElements is less than the list length.
459 1.1 jruoho */
460 1.1 jruoho Arg = Op->Common.Value.Arg;
461 1.1 jruoho Arg = Arg->Common.Next;
462 1.1 jruoho for (i = 0; Arg && (i < ElementCount); i++)
463 1.1 jruoho {
464 1.1 jruoho if (Arg->Common.AmlOpcode == AML_INT_RETURN_VALUE_OP)
465 1.1 jruoho {
466 1.1 jruoho if (Arg->Common.Node->Type == ACPI_TYPE_METHOD)
467 1.1 jruoho {
468 1.1 jruoho /*
469 1.1 jruoho * A method reference "looks" to the parser to be a method
470 1.1 jruoho * invocation, so we special case it here
471 1.1 jruoho */
472 1.1 jruoho Arg->Common.AmlOpcode = AML_INT_NAMEPATH_OP;
473 1.1 jruoho Status = AcpiDsBuildInternalObject (WalkState, Arg,
474 1.1 jruoho &ObjDesc->Package.Elements[i]);
475 1.1 jruoho }
476 1.1 jruoho else
477 1.1 jruoho {
478 1.1 jruoho /* This package element is already built, just get it */
479 1.1 jruoho
480 1.1 jruoho ObjDesc->Package.Elements[i] =
481 1.1 jruoho ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, Arg->Common.Node);
482 1.1 jruoho }
483 1.1 jruoho }
484 1.1 jruoho else
485 1.1 jruoho {
486 1.1 jruoho Status = AcpiDsBuildInternalObject (WalkState, Arg,
487 1.1 jruoho &ObjDesc->Package.Elements[i]);
488 1.1 jruoho }
489 1.1 jruoho
490 1.1 jruoho if (*ObjDescPtr)
491 1.1 jruoho {
492 1.1 jruoho /* Existing package, get existing reference count */
493 1.1 jruoho
494 1.1 jruoho ReferenceCount = (*ObjDescPtr)->Common.ReferenceCount;
495 1.1 jruoho if (ReferenceCount > 1)
496 1.1 jruoho {
497 1.1 jruoho /* Make new element ref count match original ref count */
498 1.1 jruoho
499 1.1 jruoho for (Index = 0; Index < (ReferenceCount - 1); Index++)
500 1.1 jruoho {
501 1.1 jruoho AcpiUtAddReference ((ObjDesc->Package.Elements[i]));
502 1.1 jruoho }
503 1.1 jruoho }
504 1.1 jruoho }
505 1.1 jruoho
506 1.1 jruoho Arg = Arg->Common.Next;
507 1.1 jruoho }
508 1.1 jruoho
509 1.1 jruoho /* Check for match between NumElements and actual length of PackageList */
510 1.1 jruoho
511 1.1 jruoho if (Arg)
512 1.1 jruoho {
513 1.1 jruoho /*
514 1.1 jruoho * NumElements was exhausted, but there are remaining elements in the
515 1.1 jruoho * PackageList. Truncate the package to NumElements.
516 1.1 jruoho *
517 1.1 jruoho * Note: technically, this is an error, from ACPI spec: "It is an error
518 1.1 jruoho * for NumElements to be less than the number of elements in the
519 1.1 jruoho * PackageList". However, we just print a message and
520 1.1 jruoho * no exception is returned. This provides Windows compatibility. Some
521 1.1 jruoho * BIOSs will alter the NumElements on the fly, creating this type
522 1.1 jruoho * of ill-formed package object.
523 1.1 jruoho */
524 1.1 jruoho while (Arg)
525 1.1 jruoho {
526 1.1 jruoho /*
527 1.1 jruoho * We must delete any package elements that were created earlier
528 1.1 jruoho * and are not going to be used because of the package truncation.
529 1.1 jruoho */
530 1.1 jruoho if (Arg->Common.Node)
531 1.1 jruoho {
532 1.1 jruoho AcpiUtRemoveReference (
533 1.1 jruoho ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, Arg->Common.Node));
534 1.1 jruoho Arg->Common.Node = NULL;
535 1.1 jruoho }
536 1.1 jruoho
537 1.1 jruoho /* Find out how many elements there really are */
538 1.1 jruoho
539 1.1 jruoho i++;
540 1.1 jruoho Arg = Arg->Common.Next;
541 1.1 jruoho }
542 1.1 jruoho
543 1.1 jruoho ACPI_INFO ((AE_INFO,
544 1.1.1.3 christos "Actual Package length (%u) is larger than NumElements field (%u), truncated",
545 1.1 jruoho i, ElementCount));
546 1.1 jruoho }
547 1.1 jruoho else if (i < ElementCount)
548 1.1 jruoho {
549 1.1 jruoho /*
550 1.1 jruoho * Arg list (elements) was exhausted, but we did not reach NumElements count.
551 1.1 jruoho * Note: this is not an error, the package is padded out with NULLs.
552 1.1 jruoho */
553 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
554 1.1 jruoho "Package List length (%u) smaller than NumElements count (%u), padded with null elements\n",
555 1.1 jruoho i, ElementCount));
556 1.1 jruoho }
557 1.1 jruoho
558 1.1 jruoho ObjDesc->Package.Flags |= AOPOBJ_DATA_VALID;
559 1.1 jruoho Op->Common.Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjDesc);
560 1.1 jruoho return_ACPI_STATUS (Status);
561 1.1 jruoho }
562 1.1 jruoho
563 1.1 jruoho
564 1.1 jruoho /*******************************************************************************
565 1.1 jruoho *
566 1.1 jruoho * FUNCTION: AcpiDsCreateNode
567 1.1 jruoho *
568 1.1 jruoho * PARAMETERS: WalkState - Current walk state
569 1.1 jruoho * Node - NS Node to be initialized
570 1.1 jruoho * Op - Parser object to be translated
571 1.1 jruoho *
572 1.1 jruoho * RETURN: Status
573 1.1 jruoho *
574 1.1 jruoho * DESCRIPTION: Create the object to be associated with a namespace node
575 1.1 jruoho *
576 1.1 jruoho ******************************************************************************/
577 1.1 jruoho
578 1.1 jruoho ACPI_STATUS
579 1.1 jruoho AcpiDsCreateNode (
580 1.1 jruoho ACPI_WALK_STATE *WalkState,
581 1.1 jruoho ACPI_NAMESPACE_NODE *Node,
582 1.1 jruoho ACPI_PARSE_OBJECT *Op)
583 1.1 jruoho {
584 1.1 jruoho ACPI_STATUS Status;
585 1.1 jruoho ACPI_OPERAND_OBJECT *ObjDesc;
586 1.1 jruoho
587 1.1 jruoho
588 1.1 jruoho ACPI_FUNCTION_TRACE_PTR (DsCreateNode, Op);
589 1.1 jruoho
590 1.1 jruoho
591 1.1 jruoho /*
592 1.1 jruoho * Because of the execution pass through the non-control-method
593 1.1.1.3 christos * parts of the table, we can arrive here twice. Only init
594 1.1 jruoho * the named object node the first time through
595 1.1 jruoho */
596 1.1 jruoho if (AcpiNsGetAttachedObject (Node))
597 1.1 jruoho {
598 1.1 jruoho return_ACPI_STATUS (AE_OK);
599 1.1 jruoho }
600 1.1 jruoho
601 1.1 jruoho if (!Op->Common.Value.Arg)
602 1.1 jruoho {
603 1.1 jruoho /* No arguments, there is nothing to do */
604 1.1 jruoho
605 1.1 jruoho return_ACPI_STATUS (AE_OK);
606 1.1 jruoho }
607 1.1 jruoho
608 1.1 jruoho /* Build an internal object for the argument(s) */
609 1.1 jruoho
610 1.1 jruoho Status = AcpiDsBuildInternalObject (WalkState, Op->Common.Value.Arg,
611 1.1 jruoho &ObjDesc);
612 1.1 jruoho if (ACPI_FAILURE (Status))
613 1.1 jruoho {
614 1.1 jruoho return_ACPI_STATUS (Status);
615 1.1 jruoho }
616 1.1 jruoho
617 1.1 jruoho /* Re-type the object according to its argument */
618 1.1 jruoho
619 1.1 jruoho Node->Type = ObjDesc->Common.Type;
620 1.1 jruoho
621 1.1 jruoho /* Attach obj to node */
622 1.1 jruoho
623 1.1 jruoho Status = AcpiNsAttachObject (Node, ObjDesc, Node->Type);
624 1.1 jruoho
625 1.1 jruoho /* Remove local reference to the object */
626 1.1 jruoho
627 1.1 jruoho AcpiUtRemoveReference (ObjDesc);
628 1.1 jruoho return_ACPI_STATUS (Status);
629 1.1 jruoho }
630 1.1 jruoho
631 1.1 jruoho #endif /* ACPI_NO_METHOD_EXECUTION */
632 1.1 jruoho
633 1.1 jruoho
634 1.1 jruoho /*******************************************************************************
635 1.1 jruoho *
636 1.1 jruoho * FUNCTION: AcpiDsInitObjectFromOp
637 1.1 jruoho *
638 1.1 jruoho * PARAMETERS: WalkState - Current walk state
639 1.1 jruoho * Op - Parser op used to init the internal object
640 1.1 jruoho * Opcode - AML opcode associated with the object
641 1.1 jruoho * RetObjDesc - Namespace object to be initialized
642 1.1 jruoho *
643 1.1 jruoho * RETURN: Status
644 1.1 jruoho *
645 1.1 jruoho * DESCRIPTION: Initialize a namespace object from a parser Op and its
646 1.1.1.3 christos * associated arguments. The namespace object is a more compact
647 1.1 jruoho * representation of the Op and its arguments.
648 1.1 jruoho *
649 1.1 jruoho ******************************************************************************/
650 1.1 jruoho
651 1.1 jruoho ACPI_STATUS
652 1.1 jruoho AcpiDsInitObjectFromOp (
653 1.1 jruoho ACPI_WALK_STATE *WalkState,
654 1.1 jruoho ACPI_PARSE_OBJECT *Op,
655 1.1 jruoho UINT16 Opcode,
656 1.1 jruoho ACPI_OPERAND_OBJECT **RetObjDesc)
657 1.1 jruoho {
658 1.1 jruoho const ACPI_OPCODE_INFO *OpInfo;
659 1.1 jruoho ACPI_OPERAND_OBJECT *ObjDesc;
660 1.1 jruoho ACPI_STATUS Status = AE_OK;
661 1.1 jruoho
662 1.1 jruoho
663 1.1 jruoho ACPI_FUNCTION_TRACE (DsInitObjectFromOp);
664 1.1 jruoho
665 1.1 jruoho
666 1.1 jruoho ObjDesc = *RetObjDesc;
667 1.1 jruoho OpInfo = AcpiPsGetOpcodeInfo (Opcode);
668 1.1 jruoho if (OpInfo->Class == AML_CLASS_UNKNOWN)
669 1.1 jruoho {
670 1.1 jruoho /* Unknown opcode */
671 1.1 jruoho
672 1.1 jruoho return_ACPI_STATUS (AE_TYPE);
673 1.1 jruoho }
674 1.1 jruoho
675 1.1 jruoho /* Perform per-object initialization */
676 1.1 jruoho
677 1.1 jruoho switch (ObjDesc->Common.Type)
678 1.1 jruoho {
679 1.1 jruoho case ACPI_TYPE_BUFFER:
680 1.1 jruoho /*
681 1.1 jruoho * Defer evaluation of Buffer TermArg operand
682 1.1 jruoho */
683 1.1 jruoho ObjDesc->Buffer.Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE,
684 1.1 jruoho WalkState->Operands[0]);
685 1.1 jruoho ObjDesc->Buffer.AmlStart = Op->Named.Data;
686 1.1 jruoho ObjDesc->Buffer.AmlLength = Op->Named.Length;
687 1.1 jruoho break;
688 1.1 jruoho
689 1.1 jruoho case ACPI_TYPE_PACKAGE:
690 1.1 jruoho /*
691 1.1 jruoho * Defer evaluation of Package TermArg operand
692 1.1 jruoho */
693 1.1 jruoho ObjDesc->Package.Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE,
694 1.1 jruoho WalkState->Operands[0]);
695 1.1 jruoho ObjDesc->Package.AmlStart = Op->Named.Data;
696 1.1 jruoho ObjDesc->Package.AmlLength = Op->Named.Length;
697 1.1 jruoho break;
698 1.1 jruoho
699 1.1 jruoho case ACPI_TYPE_INTEGER:
700 1.1 jruoho
701 1.1 jruoho switch (OpInfo->Type)
702 1.1 jruoho {
703 1.1 jruoho case AML_TYPE_CONSTANT:
704 1.1 jruoho /*
705 1.1 jruoho * Resolve AML Constants here - AND ONLY HERE!
706 1.1 jruoho * All constants are integers.
707 1.1 jruoho * We mark the integer with a flag that indicates that it started
708 1.1 jruoho * life as a constant -- so that stores to constants will perform
709 1.1 jruoho * as expected (noop). ZeroOp is used as a placeholder for optional
710 1.1 jruoho * target operands.
711 1.1 jruoho */
712 1.1 jruoho ObjDesc->Common.Flags = AOPOBJ_AML_CONSTANT;
713 1.1 jruoho
714 1.1 jruoho switch (Opcode)
715 1.1 jruoho {
716 1.1 jruoho case AML_ZERO_OP:
717 1.1 jruoho
718 1.1 jruoho ObjDesc->Integer.Value = 0;
719 1.1 jruoho break;
720 1.1 jruoho
721 1.1 jruoho case AML_ONE_OP:
722 1.1 jruoho
723 1.1 jruoho ObjDesc->Integer.Value = 1;
724 1.1 jruoho break;
725 1.1 jruoho
726 1.1 jruoho case AML_ONES_OP:
727 1.1 jruoho
728 1.1 jruoho ObjDesc->Integer.Value = ACPI_UINT64_MAX;
729 1.1 jruoho
730 1.1 jruoho /* Truncate value if we are executing from a 32-bit ACPI table */
731 1.1 jruoho
732 1.1 jruoho #ifndef ACPI_NO_METHOD_EXECUTION
733 1.1.1.3 christos (void) AcpiExTruncateFor32bitTable (ObjDesc);
734 1.1 jruoho #endif
735 1.1 jruoho break;
736 1.1 jruoho
737 1.1 jruoho case AML_REVISION_OP:
738 1.1 jruoho
739 1.1 jruoho ObjDesc->Integer.Value = ACPI_CA_VERSION;
740 1.1 jruoho break;
741 1.1 jruoho
742 1.1 jruoho default:
743 1.1 jruoho
744 1.1 jruoho ACPI_ERROR ((AE_INFO,
745 1.1 jruoho "Unknown constant opcode 0x%X", Opcode));
746 1.1 jruoho Status = AE_AML_OPERAND_TYPE;
747 1.1 jruoho break;
748 1.1 jruoho }
749 1.1 jruoho break;
750 1.1 jruoho
751 1.1 jruoho case AML_TYPE_LITERAL:
752 1.1 jruoho
753 1.1 jruoho ObjDesc->Integer.Value = Op->Common.Value.Integer;
754 1.1.1.3 christos
755 1.1 jruoho #ifndef ACPI_NO_METHOD_EXECUTION
756 1.1.1.3 christos if (AcpiExTruncateFor32bitTable (ObjDesc))
757 1.1.1.3 christos {
758 1.1.1.3 christos /* Warn if we found a 64-bit constant in a 32-bit table */
759 1.1.1.3 christos
760 1.1.1.3 christos ACPI_WARNING ((AE_INFO,
761 1.1.1.3 christos "Truncated 64-bit constant found in 32-bit table: %8.8X%8.8X => %8.8X",
762 1.1.1.3 christos ACPI_FORMAT_UINT64 (Op->Common.Value.Integer),
763 1.1.1.3 christos (UINT32) ObjDesc->Integer.Value));
764 1.1.1.3 christos }
765 1.1 jruoho #endif
766 1.1 jruoho break;
767 1.1 jruoho
768 1.1 jruoho default:
769 1.1.1.3 christos
770 1.1 jruoho ACPI_ERROR ((AE_INFO, "Unknown Integer type 0x%X",
771 1.1 jruoho OpInfo->Type));
772 1.1 jruoho Status = AE_AML_OPERAND_TYPE;
773 1.1 jruoho break;
774 1.1 jruoho }
775 1.1 jruoho break;
776 1.1 jruoho
777 1.1 jruoho case ACPI_TYPE_STRING:
778 1.1 jruoho
779 1.1 jruoho ObjDesc->String.Pointer = Op->Common.Value.String;
780 1.1 jruoho ObjDesc->String.Length = (UINT32) ACPI_STRLEN (Op->Common.Value.String);
781 1.1 jruoho
782 1.1 jruoho /*
783 1.1 jruoho * The string is contained in the ACPI table, don't ever try
784 1.1 jruoho * to delete it
785 1.1 jruoho */
786 1.1 jruoho ObjDesc->Common.Flags |= AOPOBJ_STATIC_POINTER;
787 1.1 jruoho break;
788 1.1 jruoho
789 1.1 jruoho case ACPI_TYPE_METHOD:
790 1.1 jruoho break;
791 1.1 jruoho
792 1.1 jruoho case ACPI_TYPE_LOCAL_REFERENCE:
793 1.1 jruoho
794 1.1 jruoho switch (OpInfo->Type)
795 1.1 jruoho {
796 1.1 jruoho case AML_TYPE_LOCAL_VARIABLE:
797 1.1 jruoho
798 1.1 jruoho /* Local ID (0-7) is (AML opcode - base AML_LOCAL_OP) */
799 1.1 jruoho
800 1.1 jruoho ObjDesc->Reference.Value = ((UINT32) Opcode) - AML_LOCAL_OP;
801 1.1 jruoho ObjDesc->Reference.Class = ACPI_REFCLASS_LOCAL;
802 1.1 jruoho
803 1.1 jruoho #ifndef ACPI_NO_METHOD_EXECUTION
804 1.1 jruoho Status = AcpiDsMethodDataGetNode (ACPI_REFCLASS_LOCAL,
805 1.1 jruoho ObjDesc->Reference.Value, WalkState,
806 1.1 jruoho ACPI_CAST_INDIRECT_PTR (ACPI_NAMESPACE_NODE,
807 1.1 jruoho &ObjDesc->Reference.Object));
808 1.1 jruoho #endif
809 1.1 jruoho break;
810 1.1 jruoho
811 1.1 jruoho case AML_TYPE_METHOD_ARGUMENT:
812 1.1 jruoho
813 1.1 jruoho /* Arg ID (0-6) is (AML opcode - base AML_ARG_OP) */
814 1.1 jruoho
815 1.1 jruoho ObjDesc->Reference.Value = ((UINT32) Opcode) - AML_ARG_OP;
816 1.1 jruoho ObjDesc->Reference.Class = ACPI_REFCLASS_ARG;
817 1.1 jruoho
818 1.1 jruoho #ifndef ACPI_NO_METHOD_EXECUTION
819 1.1 jruoho Status = AcpiDsMethodDataGetNode (ACPI_REFCLASS_ARG,
820 1.1 jruoho ObjDesc->Reference.Value, WalkState,
821 1.1 jruoho ACPI_CAST_INDIRECT_PTR (ACPI_NAMESPACE_NODE,
822 1.1 jruoho &ObjDesc->Reference.Object));
823 1.1 jruoho #endif
824 1.1 jruoho break;
825 1.1 jruoho
826 1.1 jruoho default: /* Object name or Debug object */
827 1.1 jruoho
828 1.1 jruoho switch (Op->Common.AmlOpcode)
829 1.1 jruoho {
830 1.1 jruoho case AML_INT_NAMEPATH_OP:
831 1.1 jruoho
832 1.1 jruoho /* Node was saved in Op */
833 1.1 jruoho
834 1.1 jruoho ObjDesc->Reference.Node = Op->Common.Node;
835 1.1 jruoho ObjDesc->Reference.Object = Op->Common.Node->Object;
836 1.1 jruoho ObjDesc->Reference.Class = ACPI_REFCLASS_NAME;
837 1.1 jruoho break;
838 1.1 jruoho
839 1.1 jruoho case AML_DEBUG_OP:
840 1.1 jruoho
841 1.1 jruoho ObjDesc->Reference.Class = ACPI_REFCLASS_DEBUG;
842 1.1 jruoho break;
843 1.1 jruoho
844 1.1 jruoho default:
845 1.1 jruoho
846 1.1 jruoho ACPI_ERROR ((AE_INFO,
847 1.1 jruoho "Unimplemented reference type for AML opcode: 0x%4.4X", Opcode));
848 1.1 jruoho return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
849 1.1 jruoho }
850 1.1 jruoho break;
851 1.1 jruoho }
852 1.1 jruoho break;
853 1.1 jruoho
854 1.1 jruoho default:
855 1.1 jruoho
856 1.1 jruoho ACPI_ERROR ((AE_INFO, "Unimplemented data type: 0x%X",
857 1.1 jruoho ObjDesc->Common.Type));
858 1.1 jruoho
859 1.1 jruoho Status = AE_AML_OPERAND_TYPE;
860 1.1 jruoho break;
861 1.1 jruoho }
862 1.1 jruoho
863 1.1 jruoho return_ACPI_STATUS (Status);
864 1.1 jruoho }
865