1 /******************************************************************************
3 * Module Name: aslbtypes - Support for bitfield types
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2011, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
45 #include <contrib/dev/acpica/compiler/aslcompiler.h>
46 #include "aslcompiler.y.h"
47 #include <contrib/dev/acpica/include/amlcode.h>
50 #define _COMPONENT ACPI_COMPILER
51 ACPI_MODULE_NAME ("aslbtypes")
53 /* Local prototypes */
60 /*******************************************************************************
62 * FUNCTION: AnMapArgTypeToBtype
64 * PARAMETERS: ArgType - The ARGI required type(s) for this
65 * argument, from the opcode info table
67 * RETURN: The corresponding Bit-encoded types
69 * DESCRIPTION: Convert an encoded ARGI required argument type code into a
70 * bitfield type code. Implements the implicit source conversion
73 ******************************************************************************/
86 return (ACPI_BTYPE_OBJECTS_AND_REFS);
89 return (ACPI_BTYPE_PACKAGE);
92 return (ACPI_BTYPE_EVENT);
95 return (ACPI_BTYPE_MUTEX);
99 * DDBHandleObject := SuperName
100 * ACPI_BTYPE_REFERENCE: Index reference as parameter of Load/Unload
102 return (ACPI_BTYPE_DDB_HANDLE | ACPI_BTYPE_REFERENCE);
104 /* Interchangeable types */
106 * Source conversion rules:
107 * Integer, String, and Buffer are all interchangeable
112 case ARGI_BUFFER_OR_STRING:
113 case ARGI_COMPUTEDATA:
114 return (ACPI_BTYPE_COMPUTE_DATA);
118 case ARGI_INTEGER_REF:
119 return (ACPI_BTYPE_INTEGER);
121 case ARGI_OBJECT_REF:
122 return (ACPI_BTYPE_ALL_OBJECTS);
124 case ARGI_DEVICE_REF:
125 return (ACPI_BTYPE_DEVICE_OBJECTS);
128 return (ACPI_BTYPE_REFERENCE);
131 case ARGI_FIXED_TARGET:
132 case ARGI_SIMPLE_TARGET:
133 return (ACPI_BTYPE_OBJECTS_AND_REFS);
137 case ARGI_DATAOBJECT:
140 * Buffer, string, package or reference to a Op -
141 * Used only by SizeOf operator
143 return (ACPI_BTYPE_STRING | ACPI_BTYPE_BUFFER |
144 ACPI_BTYPE_PACKAGE | ACPI_BTYPE_REFERENCE);
146 case ARGI_COMPLEXOBJ:
148 /* Buffer, String, or package */
150 return (ACPI_BTYPE_STRING | ACPI_BTYPE_BUFFER | ACPI_BTYPE_PACKAGE);
152 case ARGI_REF_OR_STRING:
153 return (ACPI_BTYPE_STRING | ACPI_BTYPE_REFERENCE);
155 case ARGI_REGION_OR_BUFFER:
157 /* Used by Load() only. Allow buffers in addition to regions/fields */
159 return (ACPI_BTYPE_REGION | ACPI_BTYPE_BUFFER | ACPI_BTYPE_FIELD_UNIT);
161 case ARGI_DATAREFOBJ:
162 return (ACPI_BTYPE_INTEGER |ACPI_BTYPE_STRING | ACPI_BTYPE_BUFFER |
163 ACPI_BTYPE_PACKAGE | ACPI_BTYPE_REFERENCE | ACPI_BTYPE_DDB_HANDLE);
169 return (ACPI_BTYPE_OBJECTS_AND_REFS);
173 /*******************************************************************************
175 * FUNCTION: AnMapEtypeToBtype
177 * PARAMETERS: Etype - Encoded ACPI Type
179 * RETURN: Btype corresponding to the Etype
181 * DESCRIPTION: Convert an encoded ACPI type to a bitfield type applying the
182 * operand conversion rules. In other words, returns the type(s)
183 * this Etype is implicitly converted to during interpretation.
185 ******************************************************************************/
193 if (Etype == ACPI_TYPE_ANY)
195 return (ACPI_BTYPE_OBJECTS_AND_REFS);
198 /* Try the standard ACPI data types */
200 if (Etype <= ACPI_TYPE_EXTERNAL_MAX)
203 * This switch statement implements the allowed operand conversion
204 * rules as per the "ASL Data Types" section of the ACPI
209 case ACPI_TYPE_INTEGER:
210 return (ACPI_BTYPE_COMPUTE_DATA | ACPI_BTYPE_DDB_HANDLE);
212 case ACPI_TYPE_STRING:
213 case ACPI_TYPE_BUFFER:
214 return (ACPI_BTYPE_COMPUTE_DATA);
216 case ACPI_TYPE_PACKAGE:
217 return (ACPI_BTYPE_PACKAGE);
219 case ACPI_TYPE_FIELD_UNIT:
220 return (ACPI_BTYPE_COMPUTE_DATA | ACPI_BTYPE_FIELD_UNIT);
222 case ACPI_TYPE_BUFFER_FIELD:
223 return (ACPI_BTYPE_COMPUTE_DATA | ACPI_BTYPE_BUFFER_FIELD);
225 case ACPI_TYPE_DDB_HANDLE:
226 return (ACPI_BTYPE_INTEGER | ACPI_BTYPE_DDB_HANDLE);
228 case ACPI_BTYPE_DEBUG_OBJECT:
230 /* Cannot be used as a source operand */
235 return (1 << (Etype - 1));
239 /* Try the internal data types */
243 case ACPI_TYPE_LOCAL_REGION_FIELD:
244 case ACPI_TYPE_LOCAL_BANK_FIELD:
245 case ACPI_TYPE_LOCAL_INDEX_FIELD:
247 /* Named fields can be either Integer/Buffer/String */
249 return (ACPI_BTYPE_COMPUTE_DATA | ACPI_BTYPE_FIELD_UNIT);
251 case ACPI_TYPE_LOCAL_ALIAS:
253 return (ACPI_BTYPE_INTEGER);
256 case ACPI_TYPE_LOCAL_RESOURCE:
257 case ACPI_TYPE_LOCAL_RESOURCE_FIELD:
259 return (ACPI_BTYPE_REFERENCE);
262 printf ("Unhandled encoded type: %X\n", Etype);
268 /*******************************************************************************
270 * FUNCTION: AnFormatBtype
272 * PARAMETERS: Btype - Bitfield of ACPI types
273 * Buffer - Where to put the ascii string
277 * DESCRIPTION: Convert a Btype to a string of ACPI types
279 ******************************************************************************/
287 BOOLEAN First = TRUE;
294 strcat (Buffer, "NoReturnValue");
298 for (Type = 1; Type <= ACPI_TYPE_EXTERNAL_MAX; Type++)
300 if (Btype & 0x00000001)
304 strcat (Buffer, "|");
307 strcat (Buffer, AcpiUtGetTypeName (Type));
312 if (Btype & 0x00000001)
316 strcat (Buffer, "|");
319 strcat (Buffer, "Reference");
323 if (Btype & 0x00000001)
327 strcat (Buffer, "|");
330 strcat (Buffer, "Resource");
335 /*******************************************************************************
337 * FUNCTION: AnGetBtype
339 * PARAMETERS: Op - Parse node whose type will be returned.
341 * RETURN: The Btype associated with the Op.
343 * DESCRIPTION: Get the (bitfield) ACPI type associated with the parse node.
344 * Handles the case where the node is a name or method call and
345 * the actual type must be obtained from the namespace node.
347 ******************************************************************************/
351 ACPI_PARSE_OBJECT *Op)
353 ACPI_NAMESPACE_NODE *Node;
354 ACPI_PARSE_OBJECT *ReferencedNode;
355 UINT32 ThisNodeBtype = 0;
358 if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG) ||
359 (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING) ||
360 (Op->Asl.ParseOpcode == PARSEOP_METHODCALL))
365 DbgPrint (ASL_DEBUG_OUTPUT,
366 "No attached Nsnode: [%s] at line %u name [%s], ignoring typecheck\n",
367 Op->Asl.ParseOpName, Op->Asl.LineNumber,
368 Op->Asl.ExternalName);
369 return (ACPI_UINT32_MAX);
372 ThisNodeBtype = AnMapEtypeToBtype (Node->Type);
375 AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, Op,
376 "could not map type");
380 * Since it was a named reference, enable the
383 ThisNodeBtype |= ACPI_BTYPE_REFERENCE;
385 if (Op->Asl.ParseOpcode == PARSEOP_METHODCALL)
387 ReferencedNode = Node->Op;
390 /* Check for an internal method */
392 if (AnIsInternalMethod (Op))
394 return (AnGetInternalMethodReturnType (Op));
397 AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, Op,
399 return (ACPI_UINT32_MAX);
402 if (ReferencedNode->Asl.CompileFlags & NODE_METHOD_TYPED)
404 ThisNodeBtype = ReferencedNode->Asl.AcpiBtype;
408 return (ACPI_UINT32_MAX -1);
414 ThisNodeBtype = Op->Asl.AcpiBtype;
417 return (ThisNodeBtype);
421 /*******************************************************************************
423 * FUNCTION: AnMapObjTypeToBtype
425 * PARAMETERS: Op - A parse node
429 * DESCRIPTION: Map object to the associated "Btype"
431 ******************************************************************************/
434 AnMapObjTypeToBtype (
435 ACPI_PARSE_OBJECT *Op)
438 switch (Op->Asl.ParseOpcode)
440 case PARSEOP_OBJECTTYPE_BFF: /* "BuffFieldObj" */
441 return (ACPI_BTYPE_BUFFER_FIELD);
443 case PARSEOP_OBJECTTYPE_BUF: /* "BuffObj" */
444 return (ACPI_BTYPE_BUFFER);
446 case PARSEOP_OBJECTTYPE_DDB: /* "DDBHandleObj" */
447 return (ACPI_BTYPE_DDB_HANDLE);
449 case PARSEOP_OBJECTTYPE_DEV: /* "DeviceObj" */
450 return (ACPI_BTYPE_DEVICE);
452 case PARSEOP_OBJECTTYPE_EVT: /* "EventObj" */
453 return (ACPI_BTYPE_EVENT);
455 case PARSEOP_OBJECTTYPE_FLD: /* "FieldUnitObj" */
456 return (ACPI_BTYPE_FIELD_UNIT);
458 case PARSEOP_OBJECTTYPE_INT: /* "IntObj" */
459 return (ACPI_BTYPE_INTEGER);
461 case PARSEOP_OBJECTTYPE_MTH: /* "MethodObj" */
462 return (ACPI_BTYPE_METHOD);
464 case PARSEOP_OBJECTTYPE_MTX: /* "MutexObj" */
465 return (ACPI_BTYPE_MUTEX);
467 case PARSEOP_OBJECTTYPE_OPR: /* "OpRegionObj" */
468 return (ACPI_BTYPE_REGION);
470 case PARSEOP_OBJECTTYPE_PKG: /* "PkgObj" */
471 return (ACPI_BTYPE_PACKAGE);
473 case PARSEOP_OBJECTTYPE_POW: /* "PowerResObj" */
474 return (ACPI_BTYPE_POWER);
476 case PARSEOP_OBJECTTYPE_STR: /* "StrObj" */
477 return (ACPI_BTYPE_STRING);
479 case PARSEOP_OBJECTTYPE_THZ: /* "ThermalZoneObj" */
480 return (ACPI_BTYPE_THERMAL);
482 case PARSEOP_OBJECTTYPE_UNK: /* "UnknownObj" */
483 return (ACPI_BTYPE_OBJECTS_AND_REFS);
491 #ifdef ACPI_OBSOLETE_FUNCTIONS
492 /*******************************************************************************
494 * FUNCTION: AnMapBtypeToEtype
496 * PARAMETERS: Btype - Bitfield of ACPI types
498 * RETURN: The Etype corresponding the the Btype
500 * DESCRIPTION: Convert a bitfield type to an encoded type
502 ******************************************************************************/
518 for (i = 1; i < Btype; i *= 2)