1 /******************************************************************************
3 * Module Name: aslbtypes - Support for bitfield types
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2013, 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 ******************************************************************************/
87 return (ACPI_BTYPE_OBJECTS_AND_REFS);
91 return (ACPI_BTYPE_PACKAGE);
95 return (ACPI_BTYPE_EVENT);
99 return (ACPI_BTYPE_MUTEX);
103 * DDBHandleObject := SuperName
104 * ACPI_BTYPE_REFERENCE: Index reference as parameter of Load/Unload
106 return (ACPI_BTYPE_DDB_HANDLE | ACPI_BTYPE_REFERENCE);
108 /* Interchangeable types */
110 * Source conversion rules:
111 * Integer, String, and Buffer are all interchangeable
116 case ARGI_BUFFER_OR_STRING:
117 case ARGI_COMPUTEDATA:
119 return (ACPI_BTYPE_COMPUTE_DATA);
123 case ARGI_INTEGER_REF:
125 return (ACPI_BTYPE_INTEGER);
127 case ARGI_OBJECT_REF:
129 return (ACPI_BTYPE_ALL_OBJECTS);
131 case ARGI_DEVICE_REF:
133 return (ACPI_BTYPE_DEVICE_OBJECTS);
137 return (ACPI_BTYPE_REFERENCE);
140 case ARGI_FIXED_TARGET:
141 case ARGI_SIMPLE_TARGET:
143 return (ACPI_BTYPE_OBJECTS_AND_REFS);
147 case ARGI_DATAOBJECT:
149 * Buffer, string, package or reference to a Op -
150 * Used only by SizeOf operator
152 return (ACPI_BTYPE_STRING | ACPI_BTYPE_BUFFER |
153 ACPI_BTYPE_PACKAGE | ACPI_BTYPE_REFERENCE);
155 case ARGI_COMPLEXOBJ:
157 /* Buffer, String, or package */
159 return (ACPI_BTYPE_STRING | ACPI_BTYPE_BUFFER | ACPI_BTYPE_PACKAGE);
161 case ARGI_REF_OR_STRING:
163 return (ACPI_BTYPE_STRING | ACPI_BTYPE_REFERENCE);
165 case ARGI_REGION_OR_BUFFER:
167 /* Used by Load() only. Allow buffers in addition to regions/fields */
169 return (ACPI_BTYPE_REGION | ACPI_BTYPE_BUFFER | ACPI_BTYPE_FIELD_UNIT);
171 case ARGI_DATAREFOBJ:
173 return (ACPI_BTYPE_INTEGER |ACPI_BTYPE_STRING | ACPI_BTYPE_BUFFER |
174 ACPI_BTYPE_PACKAGE | ACPI_BTYPE_REFERENCE | ACPI_BTYPE_DDB_HANDLE);
181 return (ACPI_BTYPE_OBJECTS_AND_REFS);
185 /*******************************************************************************
187 * FUNCTION: AnMapEtypeToBtype
189 * PARAMETERS: Etype - Encoded ACPI Type
191 * RETURN: Btype corresponding to the Etype
193 * DESCRIPTION: Convert an encoded ACPI type to a bitfield type applying the
194 * operand conversion rules. In other words, returns the type(s)
195 * this Etype is implicitly converted to during interpretation.
197 ******************************************************************************/
205 if (Etype == ACPI_TYPE_ANY)
207 return (ACPI_BTYPE_OBJECTS_AND_REFS);
210 /* Try the standard ACPI data types */
212 if (Etype <= ACPI_TYPE_EXTERNAL_MAX)
215 * This switch statement implements the allowed operand conversion
216 * rules as per the "ASL Data Types" section of the ACPI
221 case ACPI_TYPE_INTEGER:
223 return (ACPI_BTYPE_COMPUTE_DATA | ACPI_BTYPE_DDB_HANDLE);
225 case ACPI_TYPE_STRING:
226 case ACPI_TYPE_BUFFER:
228 return (ACPI_BTYPE_COMPUTE_DATA);
230 case ACPI_TYPE_PACKAGE:
232 return (ACPI_BTYPE_PACKAGE);
234 case ACPI_TYPE_FIELD_UNIT:
236 return (ACPI_BTYPE_COMPUTE_DATA | ACPI_BTYPE_FIELD_UNIT);
238 case ACPI_TYPE_BUFFER_FIELD:
240 return (ACPI_BTYPE_COMPUTE_DATA | ACPI_BTYPE_BUFFER_FIELD);
242 case ACPI_TYPE_DDB_HANDLE:
244 return (ACPI_BTYPE_INTEGER | ACPI_BTYPE_DDB_HANDLE);
246 case ACPI_BTYPE_DEBUG_OBJECT:
248 /* Cannot be used as a source operand */
254 return (1 << (Etype - 1));
258 /* Try the internal data types */
262 case ACPI_TYPE_LOCAL_REGION_FIELD:
263 case ACPI_TYPE_LOCAL_BANK_FIELD:
264 case ACPI_TYPE_LOCAL_INDEX_FIELD:
266 /* Named fields can be either Integer/Buffer/String */
268 return (ACPI_BTYPE_COMPUTE_DATA | ACPI_BTYPE_FIELD_UNIT);
270 case ACPI_TYPE_LOCAL_ALIAS:
272 return (ACPI_BTYPE_INTEGER);
275 case ACPI_TYPE_LOCAL_RESOURCE:
276 case ACPI_TYPE_LOCAL_RESOURCE_FIELD:
278 return (ACPI_BTYPE_REFERENCE);
282 printf ("Unhandled encoded type: %X\n", Etype);
288 /*******************************************************************************
290 * FUNCTION: AnFormatBtype
292 * PARAMETERS: Btype - Bitfield of ACPI types
293 * Buffer - Where to put the ascii string
297 * DESCRIPTION: Convert a Btype to a string of ACPI types
299 ******************************************************************************/
307 BOOLEAN First = TRUE;
314 strcat (Buffer, "NoReturnValue");
318 for (Type = 1; Type <= ACPI_TYPE_EXTERNAL_MAX; Type++)
320 if (Btype & 0x00000001)
324 strcat (Buffer, "|");
327 strcat (Buffer, AcpiUtGetTypeName (Type));
332 if (Btype & 0x00000001)
336 strcat (Buffer, "|");
339 strcat (Buffer, "Reference");
343 if (Btype & 0x00000001)
347 strcat (Buffer, "|");
350 strcat (Buffer, "Resource");
355 /*******************************************************************************
357 * FUNCTION: AnGetBtype
359 * PARAMETERS: Op - Parse node whose type will be returned.
361 * RETURN: The Btype associated with the Op.
363 * DESCRIPTION: Get the (bitfield) ACPI type associated with the parse node.
364 * Handles the case where the node is a name or method call and
365 * the actual type must be obtained from the namespace node.
367 ******************************************************************************/
371 ACPI_PARSE_OBJECT *Op)
373 ACPI_NAMESPACE_NODE *Node;
374 ACPI_PARSE_OBJECT *ReferencedNode;
375 UINT32 ThisNodeBtype = 0;
378 if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG) ||
379 (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING) ||
380 (Op->Asl.ParseOpcode == PARSEOP_METHODCALL))
385 DbgPrint (ASL_DEBUG_OUTPUT,
386 "No attached Nsnode: [%s] at line %u name [%s], ignoring typecheck\n",
387 Op->Asl.ParseOpName, Op->Asl.LineNumber,
388 Op->Asl.ExternalName);
389 return (ACPI_UINT32_MAX);
392 ThisNodeBtype = AnMapEtypeToBtype (Node->Type);
395 AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, Op,
396 "could not map type");
400 * Since it was a named reference, enable the
403 ThisNodeBtype |= ACPI_BTYPE_REFERENCE;
405 if (Op->Asl.ParseOpcode == PARSEOP_METHODCALL)
407 ReferencedNode = Node->Op;
410 /* Check for an internal method */
412 if (AnIsInternalMethod (Op))
414 return (AnGetInternalMethodReturnType (Op));
417 AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, Op,
419 return (ACPI_UINT32_MAX);
422 if (ReferencedNode->Asl.CompileFlags & NODE_METHOD_TYPED)
424 ThisNodeBtype = ReferencedNode->Asl.AcpiBtype;
428 return (ACPI_UINT32_MAX -1);
434 ThisNodeBtype = Op->Asl.AcpiBtype;
437 return (ThisNodeBtype);
441 /*******************************************************************************
443 * FUNCTION: AnMapObjTypeToBtype
445 * PARAMETERS: Op - A parse node
449 * DESCRIPTION: Map object to the associated "Btype"
451 ******************************************************************************/
454 AnMapObjTypeToBtype (
455 ACPI_PARSE_OBJECT *Op)
458 switch (Op->Asl.ParseOpcode)
460 case PARSEOP_OBJECTTYPE_BFF: /* "BuffFieldObj" */
462 return (ACPI_BTYPE_BUFFER_FIELD);
464 case PARSEOP_OBJECTTYPE_BUF: /* "BuffObj" */
466 return (ACPI_BTYPE_BUFFER);
468 case PARSEOP_OBJECTTYPE_DDB: /* "DDBHandleObj" */
470 return (ACPI_BTYPE_DDB_HANDLE);
472 case PARSEOP_OBJECTTYPE_DEV: /* "DeviceObj" */
474 return (ACPI_BTYPE_DEVICE);
476 case PARSEOP_OBJECTTYPE_EVT: /* "EventObj" */
478 return (ACPI_BTYPE_EVENT);
480 case PARSEOP_OBJECTTYPE_FLD: /* "FieldUnitObj" */
482 return (ACPI_BTYPE_FIELD_UNIT);
484 case PARSEOP_OBJECTTYPE_INT: /* "IntObj" */
486 return (ACPI_BTYPE_INTEGER);
488 case PARSEOP_OBJECTTYPE_MTH: /* "MethodObj" */
490 return (ACPI_BTYPE_METHOD);
492 case PARSEOP_OBJECTTYPE_MTX: /* "MutexObj" */
494 return (ACPI_BTYPE_MUTEX);
496 case PARSEOP_OBJECTTYPE_OPR: /* "OpRegionObj" */
498 return (ACPI_BTYPE_REGION);
500 case PARSEOP_OBJECTTYPE_PKG: /* "PkgObj" */
502 return (ACPI_BTYPE_PACKAGE);
504 case PARSEOP_OBJECTTYPE_POW: /* "PowerResObj" */
506 return (ACPI_BTYPE_POWER);
508 case PARSEOP_OBJECTTYPE_STR: /* "StrObj" */
510 return (ACPI_BTYPE_STRING);
512 case PARSEOP_OBJECTTYPE_THZ: /* "ThermalZoneObj" */
514 return (ACPI_BTYPE_THERMAL);
516 case PARSEOP_OBJECTTYPE_UNK: /* "UnknownObj" */
518 return (ACPI_BTYPE_OBJECTS_AND_REFS);
527 #ifdef ACPI_OBSOLETE_FUNCTIONS
528 /*******************************************************************************
530 * FUNCTION: AnMapBtypeToEtype
532 * PARAMETERS: Btype - Bitfield of ACPI types
534 * RETURN: The Etype corresponding the the Btype
536 * DESCRIPTION: Convert a bitfield type to an encoded type
538 ******************************************************************************/
554 for (i = 1; i < Btype; i *= 2)