1 /******************************************************************************
3 * Module Name: aslbtypes - Support for bitfield types
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2016, 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.
44 #include <contrib/dev/acpica/compiler/aslcompiler.h>
45 #include "aslcompiler.y.h"
46 #include <contrib/dev/acpica/include/amlcode.h>
49 #define _COMPONENT ACPI_COMPILER
50 ACPI_MODULE_NAME ("aslbtypes")
52 /* Local prototypes */
59 /*******************************************************************************
61 * FUNCTION: AnMapArgTypeToBtype
63 * PARAMETERS: ArgType - The ARGI required type(s) for this
64 * argument, from the opcode info table
66 * RETURN: The corresponding Bit-encoded types
68 * DESCRIPTION: Convert an encoded ARGI required argument type code into a
69 * bitfield type code. Implements the implicit source conversion
72 ******************************************************************************/
85 return (ACPI_BTYPE_OBJECTS_AND_REFS);
89 return (ACPI_BTYPE_PACKAGE);
93 return (ACPI_BTYPE_EVENT);
97 return (ACPI_BTYPE_MUTEX);
101 * DDBHandleObject := SuperName
102 * ACPI_BTYPE_REFERENCE_OBJECT:
103 * Index reference as parameter of Load/Unload
105 return (ACPI_BTYPE_DDB_HANDLE | ACPI_BTYPE_REFERENCE_OBJECT);
107 /* Interchangeable types */
109 * Source conversion rules:
110 * Integer, String, and Buffer are all interchangeable
115 case ARGI_BUFFER_OR_STRING:
116 case ARGI_COMPUTEDATA:
118 return (ACPI_BTYPE_COMPUTE_DATA);
122 case ARGI_INTEGER_REF:
124 return (ACPI_BTYPE_INTEGER);
126 case ARGI_OBJECT_REF:
128 return (ACPI_BTYPE_ALL_OBJECTS);
130 case ARGI_DEVICE_REF:
132 return (ACPI_BTYPE_DEVICE_OBJECTS);
136 return (ACPI_BTYPE_NAMED_REFERENCE); /* Name or Namestring */
141 * Target operand for most math and logic operators.
142 * Package objects not allowed as target.
144 return (ACPI_BTYPE_COMPUTE_DATA | ACPI_BTYPE_DEBUG_OBJECT |
145 ACPI_BTYPE_REFERENCE_OBJECT);
147 case ARGI_STORE_TARGET:
149 /* Special target for Store(), includes packages */
151 return (ACPI_BTYPE_DATA | ACPI_BTYPE_DEBUG_OBJECT |
152 ACPI_BTYPE_REFERENCE_OBJECT);
154 case ARGI_FIXED_TARGET:
155 case ARGI_SIMPLE_TARGET:
157 return (ACPI_BTYPE_OBJECTS_AND_REFS);
161 case ARGI_DATAOBJECT:
163 * Buffer, string, package or reference to a Op -
164 * Used only by SizeOf operator
166 return (ACPI_BTYPE_STRING | ACPI_BTYPE_BUFFER |
167 ACPI_BTYPE_PACKAGE | ACPI_BTYPE_REFERENCE_OBJECT);
169 case ARGI_COMPLEXOBJ:
171 /* Buffer, String, or package */
173 return (ACPI_BTYPE_STRING | ACPI_BTYPE_BUFFER |
176 case ARGI_REF_OR_STRING:
178 /* Used by DeRefOf operator only */
180 return (ACPI_BTYPE_STRING | ACPI_BTYPE_REFERENCE_OBJECT);
182 case ARGI_REGION_OR_BUFFER:
184 /* Used by Load() only. Allow buffers in addition to regions/fields */
186 return (ACPI_BTYPE_REGION | ACPI_BTYPE_BUFFER |
187 ACPI_BTYPE_FIELD_UNIT);
189 case ARGI_DATAREFOBJ:
191 /* Used by Store() only, as the source operand */
193 return (ACPI_BTYPE_DATA_REFERENCE | ACPI_BTYPE_REFERENCE_OBJECT);
200 return (ACPI_BTYPE_OBJECTS_AND_REFS);
204 /*******************************************************************************
206 * FUNCTION: AnMapEtypeToBtype
208 * PARAMETERS: Etype - Encoded ACPI Type
210 * RETURN: Btype corresponding to the Etype
212 * DESCRIPTION: Convert an encoded ACPI type to a bitfield type applying the
213 * operand conversion rules. In other words, returns the type(s)
214 * this Etype is implicitly converted to during interpretation.
216 ******************************************************************************/
223 if (Etype == ACPI_TYPE_ANY)
225 return (ACPI_BTYPE_OBJECTS_AND_REFS);
228 /* Try the standard ACPI data types */
230 if (Etype <= ACPI_TYPE_EXTERNAL_MAX)
233 * This switch statement implements the allowed operand conversion
234 * rules as per the "ASL Data Types" section of the ACPI
239 case ACPI_TYPE_INTEGER:
241 return (ACPI_BTYPE_COMPUTE_DATA | ACPI_BTYPE_DDB_HANDLE);
243 case ACPI_TYPE_STRING:
244 case ACPI_TYPE_BUFFER:
246 return (ACPI_BTYPE_COMPUTE_DATA);
248 case ACPI_TYPE_PACKAGE:
250 return (ACPI_BTYPE_PACKAGE);
252 case ACPI_TYPE_FIELD_UNIT:
254 return (ACPI_BTYPE_COMPUTE_DATA | ACPI_BTYPE_FIELD_UNIT);
256 case ACPI_TYPE_BUFFER_FIELD:
258 return (ACPI_BTYPE_COMPUTE_DATA | ACPI_BTYPE_BUFFER_FIELD);
260 case ACPI_TYPE_DDB_HANDLE:
262 return (ACPI_BTYPE_INTEGER | ACPI_BTYPE_DDB_HANDLE);
264 case ACPI_TYPE_DEBUG_OBJECT:
266 /* Cannot be used as a source operand */
272 return (1 << (Etype - 1));
276 /* Try the internal data types */
280 case ACPI_TYPE_LOCAL_REGION_FIELD:
281 case ACPI_TYPE_LOCAL_BANK_FIELD:
282 case ACPI_TYPE_LOCAL_INDEX_FIELD:
284 /* Named fields can be either Integer/Buffer/String */
286 return (ACPI_BTYPE_COMPUTE_DATA | ACPI_BTYPE_FIELD_UNIT);
288 case ACPI_TYPE_LOCAL_ALIAS:
290 return (ACPI_BTYPE_INTEGER);
293 case ACPI_TYPE_LOCAL_RESOURCE:
294 case ACPI_TYPE_LOCAL_RESOURCE_FIELD:
296 return (ACPI_BTYPE_REFERENCE_OBJECT);
300 printf ("Unhandled encoded type: %X\n", Etype);
306 /*******************************************************************************
308 * FUNCTION: AnFormatBtype
310 * PARAMETERS: Btype - Bitfield of ACPI types
311 * Buffer - Where to put the ascii string
315 * DESCRIPTION: Convert a Btype to a string of ACPI types
317 ******************************************************************************/
325 BOOLEAN First = TRUE;
331 strcat (Buffer, "NoReturnValue");
335 for (Type = 1; Type <= ACPI_TYPE_EXTERNAL_MAX; Type++)
337 if (Btype & 0x00000001)
341 strcat (Buffer, "|");
345 strcat (Buffer, AcpiUtGetTypeName (Type));
350 if (Btype & 0x00000001)
354 strcat (Buffer, "|");
358 strcat (Buffer, "Reference");
362 if (Btype & 0x00000001)
366 strcat (Buffer, "|");
370 strcat (Buffer, "Resource");
375 /*******************************************************************************
377 * FUNCTION: AnGetBtype
379 * PARAMETERS: Op - Parse node whose type will be returned.
381 * RETURN: The Btype associated with the Op.
383 * DESCRIPTION: Get the (bitfield) ACPI type associated with the parse node.
384 * Handles the case where the node is a name or method call and
385 * the actual type must be obtained from the namespace node.
387 ******************************************************************************/
391 ACPI_PARSE_OBJECT *Op)
393 ACPI_NAMESPACE_NODE *Node;
394 ACPI_PARSE_OBJECT *ReferencedNode;
395 UINT32 ThisNodeBtype = 0;
400 AcpiOsPrintf ("Null Op in AnGetBtype\n");
401 return (ACPI_UINT32_MAX);
404 if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG) ||
405 (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING) ||
406 (Op->Asl.ParseOpcode == PARSEOP_METHODCALL))
411 /* These are not expected to have a node at this time */
413 if ((Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_CREATEWORDFIELD) ||
414 (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_CREATEDWORDFIELD) ||
415 (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_CREATEQWORDFIELD) ||
416 (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_CREATEBYTEFIELD) ||
417 (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_CREATEBITFIELD) ||
418 (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_CREATEFIELD) ||
419 (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_CONDREFOF))
421 return (ACPI_UINT32_MAX - 1);
424 DbgPrint (ASL_DEBUG_OUTPUT,
425 "No attached Nsnode: [%s] at line %u name [%s], "
426 "ignoring typecheck. Parent [%s]\n",
427 Op->Asl.ParseOpName, Op->Asl.LineNumber,
428 Op->Asl.ExternalName, Op->Asl.Parent->Asl.ParseOpName);
429 return (ACPI_UINT32_MAX - 1);
432 ThisNodeBtype = AnMapEtypeToBtype (Node->Type);
435 AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, Op,
436 "could not map type");
439 if (Op->Asl.ParseOpcode == PARSEOP_METHODCALL)
441 ReferencedNode = Node->Op;
444 /* Check for an internal method */
446 if (AnIsInternalMethod (Op))
448 return (AnGetInternalMethodReturnType (Op));
451 AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, Op,
453 return (ACPI_UINT32_MAX);
456 if (ReferencedNode->Asl.CompileFlags & NODE_METHOD_TYPED)
458 ThisNodeBtype = ReferencedNode->Asl.AcpiBtype;
462 return (ACPI_UINT32_MAX -1);
468 ThisNodeBtype = Op->Asl.AcpiBtype;
471 return (ThisNodeBtype);
475 /*******************************************************************************
477 * FUNCTION: AnMapObjTypeToBtype
479 * PARAMETERS: Op - A parse node
483 * DESCRIPTION: Map object to the associated "Btype"
485 ******************************************************************************/
488 AnMapObjTypeToBtype (
489 ACPI_PARSE_OBJECT *Op)
492 switch (Op->Asl.ParseOpcode)
494 case PARSEOP_OBJECTTYPE_BFF: /* "BuffFieldObj" */
496 return (ACPI_BTYPE_BUFFER_FIELD);
498 case PARSEOP_OBJECTTYPE_BUF: /* "BuffObj" */
500 return (ACPI_BTYPE_BUFFER);
502 case PARSEOP_OBJECTTYPE_DDB: /* "DDBHandleObj" */
504 return (ACPI_BTYPE_DDB_HANDLE);
506 case PARSEOP_OBJECTTYPE_DEV: /* "DeviceObj" */
508 return (ACPI_BTYPE_DEVICE);
510 case PARSEOP_OBJECTTYPE_EVT: /* "EventObj" */
512 return (ACPI_BTYPE_EVENT);
514 case PARSEOP_OBJECTTYPE_FLD: /* "FieldUnitObj" */
516 return (ACPI_BTYPE_FIELD_UNIT);
518 case PARSEOP_OBJECTTYPE_INT: /* "IntObj" */
520 return (ACPI_BTYPE_INTEGER);
522 case PARSEOP_OBJECTTYPE_MTH: /* "MethodObj" */
524 return (ACPI_BTYPE_METHOD);
526 case PARSEOP_OBJECTTYPE_MTX: /* "MutexObj" */
528 return (ACPI_BTYPE_MUTEX);
530 case PARSEOP_OBJECTTYPE_OPR: /* "OpRegionObj" */
532 return (ACPI_BTYPE_REGION);
534 case PARSEOP_OBJECTTYPE_PKG: /* "PkgObj" */
536 return (ACPI_BTYPE_PACKAGE);
538 case PARSEOP_OBJECTTYPE_POW: /* "PowerResObj" */
540 return (ACPI_BTYPE_POWER);
542 case PARSEOP_OBJECTTYPE_STR: /* "StrObj" */
544 return (ACPI_BTYPE_STRING);
546 case PARSEOP_OBJECTTYPE_THZ: /* "ThermalZoneObj" */
548 return (ACPI_BTYPE_THERMAL);
550 case PARSEOP_OBJECTTYPE_UNK: /* "UnknownObj" */
552 return (ACPI_BTYPE_OBJECTS_AND_REFS);
561 #ifdef ACPI_OBSOLETE_FUNCTIONS
562 /*******************************************************************************
564 * FUNCTION: AnMapBtypeToEtype
566 * PARAMETERS: Btype - Bitfield of ACPI types
568 * RETURN: The Etype corresponding the the Btype
570 * DESCRIPTION: Convert a bitfield type to an encoded type
572 ******************************************************************************/
588 for (i = 1; i < Btype; i *= 2)