1 /******************************************************************************
3 * Module Name: aslbtypes - Support for bitfield types
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2015, 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 ******************************************************************************/
86 return (ACPI_BTYPE_OBJECTS_AND_REFS);
90 return (ACPI_BTYPE_PACKAGE);
94 return (ACPI_BTYPE_EVENT);
98 return (ACPI_BTYPE_MUTEX);
102 * DDBHandleObject := SuperName
103 * ACPI_BTYPE_REFERENCE: Index reference as parameter of Load/Unload
105 return (ACPI_BTYPE_DDB_HANDLE | ACPI_BTYPE_REFERENCE);
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_REFERENCE);
139 case ARGI_FIXED_TARGET:
140 case ARGI_SIMPLE_TARGET:
142 return (ACPI_BTYPE_OBJECTS_AND_REFS);
146 case ARGI_DATAOBJECT:
148 * Buffer, string, package or reference to a Op -
149 * Used only by SizeOf operator
151 return (ACPI_BTYPE_STRING | ACPI_BTYPE_BUFFER |
152 ACPI_BTYPE_PACKAGE | ACPI_BTYPE_REFERENCE);
154 case ARGI_COMPLEXOBJ:
156 /* Buffer, String, or package */
158 return (ACPI_BTYPE_STRING | ACPI_BTYPE_BUFFER | ACPI_BTYPE_PACKAGE);
160 case ARGI_REF_OR_STRING:
162 return (ACPI_BTYPE_STRING | ACPI_BTYPE_REFERENCE);
164 case ARGI_REGION_OR_BUFFER:
166 /* Used by Load() only. Allow buffers in addition to regions/fields */
168 return (ACPI_BTYPE_REGION | ACPI_BTYPE_BUFFER | ACPI_BTYPE_FIELD_UNIT);
170 case ARGI_DATAREFOBJ:
172 return (ACPI_BTYPE_INTEGER |ACPI_BTYPE_STRING | ACPI_BTYPE_BUFFER |
173 ACPI_BTYPE_PACKAGE | ACPI_BTYPE_REFERENCE | ACPI_BTYPE_DDB_HANDLE);
180 return (ACPI_BTYPE_OBJECTS_AND_REFS);
184 /*******************************************************************************
186 * FUNCTION: AnMapEtypeToBtype
188 * PARAMETERS: Etype - Encoded ACPI Type
190 * RETURN: Btype corresponding to the Etype
192 * DESCRIPTION: Convert an encoded ACPI type to a bitfield type applying the
193 * operand conversion rules. In other words, returns the type(s)
194 * this Etype is implicitly converted to during interpretation.
196 ******************************************************************************/
204 if (Etype == ACPI_TYPE_ANY)
206 return (ACPI_BTYPE_OBJECTS_AND_REFS);
209 /* Try the standard ACPI data types */
211 if (Etype <= ACPI_TYPE_EXTERNAL_MAX)
214 * This switch statement implements the allowed operand conversion
215 * rules as per the "ASL Data Types" section of the ACPI
220 case ACPI_TYPE_INTEGER:
222 return (ACPI_BTYPE_COMPUTE_DATA | ACPI_BTYPE_DDB_HANDLE);
224 case ACPI_TYPE_STRING:
225 case ACPI_TYPE_BUFFER:
227 return (ACPI_BTYPE_COMPUTE_DATA);
229 case ACPI_TYPE_PACKAGE:
231 return (ACPI_BTYPE_PACKAGE);
233 case ACPI_TYPE_FIELD_UNIT:
235 return (ACPI_BTYPE_COMPUTE_DATA | ACPI_BTYPE_FIELD_UNIT);
237 case ACPI_TYPE_BUFFER_FIELD:
239 return (ACPI_BTYPE_COMPUTE_DATA | ACPI_BTYPE_BUFFER_FIELD);
241 case ACPI_TYPE_DDB_HANDLE:
243 return (ACPI_BTYPE_INTEGER | ACPI_BTYPE_DDB_HANDLE);
245 case ACPI_TYPE_DEBUG_OBJECT:
247 /* Cannot be used as a source operand */
253 return (1 << (Etype - 1));
257 /* Try the internal data types */
261 case ACPI_TYPE_LOCAL_REGION_FIELD:
262 case ACPI_TYPE_LOCAL_BANK_FIELD:
263 case ACPI_TYPE_LOCAL_INDEX_FIELD:
265 /* Named fields can be either Integer/Buffer/String */
267 return (ACPI_BTYPE_COMPUTE_DATA | ACPI_BTYPE_FIELD_UNIT);
269 case ACPI_TYPE_LOCAL_ALIAS:
271 return (ACPI_BTYPE_INTEGER);
274 case ACPI_TYPE_LOCAL_RESOURCE:
275 case ACPI_TYPE_LOCAL_RESOURCE_FIELD:
277 return (ACPI_BTYPE_REFERENCE);
281 printf ("Unhandled encoded type: %X\n", Etype);
287 /*******************************************************************************
289 * FUNCTION: AnFormatBtype
291 * PARAMETERS: Btype - Bitfield of ACPI types
292 * Buffer - Where to put the ascii string
296 * DESCRIPTION: Convert a Btype to a string of ACPI types
298 ******************************************************************************/
306 BOOLEAN First = TRUE;
313 strcat (Buffer, "NoReturnValue");
317 for (Type = 1; Type <= ACPI_TYPE_EXTERNAL_MAX; Type++)
319 if (Btype & 0x00000001)
323 strcat (Buffer, "|");
326 strcat (Buffer, AcpiUtGetTypeName (Type));
331 if (Btype & 0x00000001)
335 strcat (Buffer, "|");
338 strcat (Buffer, "Reference");
342 if (Btype & 0x00000001)
346 strcat (Buffer, "|");
349 strcat (Buffer, "Resource");
354 /*******************************************************************************
356 * FUNCTION: AnGetBtype
358 * PARAMETERS: Op - Parse node whose type will be returned.
360 * RETURN: The Btype associated with the Op.
362 * DESCRIPTION: Get the (bitfield) ACPI type associated with the parse node.
363 * Handles the case where the node is a name or method call and
364 * the actual type must be obtained from the namespace node.
366 ******************************************************************************/
370 ACPI_PARSE_OBJECT *Op)
372 ACPI_NAMESPACE_NODE *Node;
373 ACPI_PARSE_OBJECT *ReferencedNode;
374 UINT32 ThisNodeBtype = 0;
379 AcpiOsPrintf ("Null Op in AnGetBtype\n");
380 return (ACPI_UINT32_MAX);
383 if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG) ||
384 (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING) ||
385 (Op->Asl.ParseOpcode == PARSEOP_METHODCALL))
390 DbgPrint (ASL_DEBUG_OUTPUT,
391 "No attached Nsnode: [%s] at line %u name [%s], ignoring typecheck\n",
392 Op->Asl.ParseOpName, Op->Asl.LineNumber,
393 Op->Asl.ExternalName);
394 return (ACPI_UINT32_MAX);
397 ThisNodeBtype = AnMapEtypeToBtype (Node->Type);
400 AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, Op,
401 "could not map type");
405 * Since it was a named reference, enable the
408 ThisNodeBtype |= ACPI_BTYPE_REFERENCE;
410 if (Op->Asl.ParseOpcode == PARSEOP_METHODCALL)
412 ReferencedNode = Node->Op;
415 /* Check for an internal method */
417 if (AnIsInternalMethod (Op))
419 return (AnGetInternalMethodReturnType (Op));
422 AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, Op,
424 return (ACPI_UINT32_MAX);
427 if (ReferencedNode->Asl.CompileFlags & NODE_METHOD_TYPED)
429 ThisNodeBtype = ReferencedNode->Asl.AcpiBtype;
433 return (ACPI_UINT32_MAX -1);
439 ThisNodeBtype = Op->Asl.AcpiBtype;
442 return (ThisNodeBtype);
446 /*******************************************************************************
448 * FUNCTION: AnMapObjTypeToBtype
450 * PARAMETERS: Op - A parse node
454 * DESCRIPTION: Map object to the associated "Btype"
456 ******************************************************************************/
459 AnMapObjTypeToBtype (
460 ACPI_PARSE_OBJECT *Op)
463 switch (Op->Asl.ParseOpcode)
465 case PARSEOP_OBJECTTYPE_BFF: /* "BuffFieldObj" */
467 return (ACPI_BTYPE_BUFFER_FIELD);
469 case PARSEOP_OBJECTTYPE_BUF: /* "BuffObj" */
471 return (ACPI_BTYPE_BUFFER);
473 case PARSEOP_OBJECTTYPE_DDB: /* "DDBHandleObj" */
475 return (ACPI_BTYPE_DDB_HANDLE);
477 case PARSEOP_OBJECTTYPE_DEV: /* "DeviceObj" */
479 return (ACPI_BTYPE_DEVICE);
481 case PARSEOP_OBJECTTYPE_EVT: /* "EventObj" */
483 return (ACPI_BTYPE_EVENT);
485 case PARSEOP_OBJECTTYPE_FLD: /* "FieldUnitObj" */
487 return (ACPI_BTYPE_FIELD_UNIT);
489 case PARSEOP_OBJECTTYPE_INT: /* "IntObj" */
491 return (ACPI_BTYPE_INTEGER);
493 case PARSEOP_OBJECTTYPE_MTH: /* "MethodObj" */
495 return (ACPI_BTYPE_METHOD);
497 case PARSEOP_OBJECTTYPE_MTX: /* "MutexObj" */
499 return (ACPI_BTYPE_MUTEX);
501 case PARSEOP_OBJECTTYPE_OPR: /* "OpRegionObj" */
503 return (ACPI_BTYPE_REGION);
505 case PARSEOP_OBJECTTYPE_PKG: /* "PkgObj" */
507 return (ACPI_BTYPE_PACKAGE);
509 case PARSEOP_OBJECTTYPE_POW: /* "PowerResObj" */
511 return (ACPI_BTYPE_POWER);
513 case PARSEOP_OBJECTTYPE_STR: /* "StrObj" */
515 return (ACPI_BTYPE_STRING);
517 case PARSEOP_OBJECTTYPE_THZ: /* "ThermalZoneObj" */
519 return (ACPI_BTYPE_THERMAL);
521 case PARSEOP_OBJECTTYPE_UNK: /* "UnknownObj" */
523 return (ACPI_BTYPE_OBJECTS_AND_REFS);
532 #ifdef ACPI_OBSOLETE_FUNCTIONS
533 /*******************************************************************************
535 * FUNCTION: AnMapBtypeToEtype
537 * PARAMETERS: Btype - Bitfield of ACPI types
539 * RETURN: The Etype corresponding the the Btype
541 * DESCRIPTION: Convert a bitfield type to an encoded type
543 ******************************************************************************/
559 for (i = 1; i < Btype; i *= 2)