aslbtypes.c revision 245582
10SN/A/****************************************************************************** 24013Sdarcy * 30SN/A * Module Name: aslbtypes - Support for bitfield types 40SN/A * 50SN/A *****************************************************************************/ 60SN/A 7553SN/A/* 80SN/A * Copyright (C) 2000 - 2013, Intel Corp. 9553SN/A * All rights reserved. 100SN/A * 110SN/A * Redistribution and use in source and binary forms, with or without 120SN/A * modification, are permitted provided that the following conditions 130SN/A * are met: 140SN/A * 1. Redistributions of source code must retain the above copyright 150SN/A * notice, this list of conditions, and the following disclaimer, 160SN/A * without modification. 170SN/A * 2. Redistributions in binary form must reproduce at minimum a disclaimer 180SN/A * substantially similar to the "NO WARRANTY" disclaimer below 190SN/A * ("Disclaimer") and any redistribution must be conditioned upon 200SN/A * including a substantially similar Disclaimer requirement for further 21553SN/A * binary redistribution. 22553SN/A * 3. Neither the names of the above-listed copyright holders nor the names 23553SN/A * of any contributors may be used to endorse or promote products derived 240SN/A * from this software without specific prior written permission. 250SN/A * 260SN/A * Alternatively, this software may be distributed under the terms of the 270SN/A * GNU General Public License ("GPL") version 2 as published by the Free 281520SN/A * Software Foundation. 291520SN/A * 301520SN/A * NO WARRANTY 310SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 320SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 330SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 340SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 350SN/A * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 360SN/A * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 370SN/A * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 380SN/A * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 390SN/A * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 400SN/A * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 410SN/A * POSSIBILITY OF SUCH DAMAGES. 420SN/A */ 430SN/A 440SN/A 450SN/A#include <contrib/dev/acpica/compiler/aslcompiler.h> 460SN/A#include "aslcompiler.y.h" 470SN/A#include <contrib/dev/acpica/include/amlcode.h> 480SN/A 490SN/A 500SN/A#define _COMPONENT ACPI_COMPILER 510SN/A ACPI_MODULE_NAME ("aslbtypes") 520SN/A 530SN/A/* Local prototypes */ 540SN/A 551724SN/Astatic UINT32 560SN/AAnMapEtypeToBtype ( 570SN/A UINT32 Etype); 580SN/A 590SN/A 600SN/A/******************************************************************************* 610SN/A * 620SN/A * FUNCTION: AnMapArgTypeToBtype 630SN/A * 640SN/A * PARAMETERS: ArgType - The ARGI required type(s) for this 650SN/A * argument, from the opcode info table 660SN/A * 670SN/A * RETURN: The corresponding Bit-encoded types 680SN/A * 690SN/A * DESCRIPTION: Convert an encoded ARGI required argument type code into a 700SN/A * bitfield type code. Implements the implicit source conversion 710SN/A * rules. 720SN/A * 732226SN/A ******************************************************************************/ 742226SN/A 752226SN/AUINT32 762226SN/AAnMapArgTypeToBtype ( 772226SN/A UINT32 ArgType) 782226SN/A{ 792226SN/A 800SN/A switch (ArgType) 810SN/A { 820SN/A 830SN/A /* Simple types */ 840SN/A 850SN/A case ARGI_ANYTYPE: 860SN/A return (ACPI_BTYPE_OBJECTS_AND_REFS); 870SN/A 880SN/A case ARGI_PACKAGE: 890SN/A return (ACPI_BTYPE_PACKAGE); 900SN/A 910SN/A case ARGI_EVENT: 920SN/A return (ACPI_BTYPE_EVENT); 930SN/A 944013Sdarcy case ARGI_MUTEX: 95971SN/A return (ACPI_BTYPE_MUTEX); 960SN/A 970SN/A case ARGI_DDBHANDLE: 980SN/A /* 990SN/A * DDBHandleObject := SuperName 1000SN/A * ACPI_BTYPE_REFERENCE: Index reference as parameter of Load/Unload 1010SN/A */ 1020SN/A return (ACPI_BTYPE_DDB_HANDLE | ACPI_BTYPE_REFERENCE); 1030SN/A 1040SN/A /* Interchangeable types */ 1050SN/A /* 1064013Sdarcy * Source conversion rules: 107971SN/A * Integer, String, and Buffer are all interchangeable 1080SN/A */ 1090SN/A case ARGI_INTEGER: 1100SN/A case ARGI_STRING: 1110SN/A case ARGI_BUFFER: 1120SN/A case ARGI_BUFFER_OR_STRING: 1130SN/A case ARGI_COMPUTEDATA: 1140SN/A return (ACPI_BTYPE_COMPUTE_DATA); 1150SN/A 1160SN/A /* References */ 1174013Sdarcy 118971SN/A case ARGI_INTEGER_REF: 1190SN/A return (ACPI_BTYPE_INTEGER); 1200SN/A 1210SN/A case ARGI_OBJECT_REF: 1220SN/A return (ACPI_BTYPE_ALL_OBJECTS); 1230SN/A 1240SN/A case ARGI_DEVICE_REF: 1250SN/A return (ACPI_BTYPE_DEVICE_OBJECTS); 1260SN/A 1270SN/A case ARGI_REFERENCE: 1280SN/A return (ACPI_BTYPE_REFERENCE); 1290SN/A 130971SN/A case ARGI_TARGETREF: 1310SN/A case ARGI_FIXED_TARGET: 1320SN/A case ARGI_SIMPLE_TARGET: 1330SN/A return (ACPI_BTYPE_OBJECTS_AND_REFS); 1340SN/A 1352347SN/A /* Complex types */ 1362347SN/A 1372347SN/A case ARGI_DATAOBJECT: 1382347SN/A 1390SN/A /* 1400SN/A * Buffer, string, package or reference to a Op - 1410SN/A * Used only by SizeOf operator 1424013Sdarcy */ 1432347SN/A return (ACPI_BTYPE_STRING | ACPI_BTYPE_BUFFER | 1440SN/A ACPI_BTYPE_PACKAGE | ACPI_BTYPE_REFERENCE); 1450SN/A 1460SN/A case ARGI_COMPLEXOBJ: 1470SN/A 1480SN/A /* Buffer, String, or package */ 1490SN/A 1500SN/A return (ACPI_BTYPE_STRING | ACPI_BTYPE_BUFFER | ACPI_BTYPE_PACKAGE); 1510SN/A 1524013Sdarcy case ARGI_REF_OR_STRING: 153971SN/A return (ACPI_BTYPE_STRING | ACPI_BTYPE_REFERENCE); 1540SN/A 1550SN/A case ARGI_REGION_OR_BUFFER: 1560SN/A 1570SN/A /* Used by Load() only. Allow buffers in addition to regions/fields */ 1580SN/A 1590SN/A return (ACPI_BTYPE_REGION | ACPI_BTYPE_BUFFER | ACPI_BTYPE_FIELD_UNIT); 1600SN/A 1610SN/A case ARGI_DATAREFOBJ: 1620SN/A return (ACPI_BTYPE_INTEGER |ACPI_BTYPE_STRING | ACPI_BTYPE_BUFFER | 163971SN/A ACPI_BTYPE_PACKAGE | ACPI_BTYPE_REFERENCE | ACPI_BTYPE_DDB_HANDLE); 1640SN/A 1650SN/A default: 1660SN/A break; 1670SN/A } 1680SN/A 1690SN/A return (ACPI_BTYPE_OBJECTS_AND_REFS); 1700SN/A} 1710SN/A 1720SN/A 1730SN/A/******************************************************************************* 1740SN/A * 175971SN/A * FUNCTION: AnMapEtypeToBtype 1760SN/A * 1770SN/A * PARAMETERS: Etype - Encoded ACPI Type 1780SN/A * 1790SN/A * RETURN: Btype corresponding to the Etype 1800SN/A * 1810SN/A * DESCRIPTION: Convert an encoded ACPI type to a bitfield type applying the 1820SN/A * operand conversion rules. In other words, returns the type(s) 1830SN/A * this Etype is implicitly converted to during interpretation. 1844013Sdarcy * 185971SN/A ******************************************************************************/ 1860SN/A 1870SN/Astatic UINT32 1880SN/AAnMapEtypeToBtype ( 1890SN/A UINT32 Etype) 1900SN/A{ 1910SN/A 1920SN/A 1930SN/A if (Etype == ACPI_TYPE_ANY) 1940SN/A { 1950SN/A return (ACPI_BTYPE_OBJECTS_AND_REFS); 1960SN/A } 1970SN/A 1980SN/A /* Try the standard ACPI data types */ 1990SN/A 2000SN/A if (Etype <= ACPI_TYPE_EXTERNAL_MAX) 2010SN/A { 2020SN/A /* 2030SN/A * This switch statement implements the allowed operand conversion 2040SN/A * rules as per the "ASL Data Types" section of the ACPI 2050SN/A * specification. 2060SN/A */ 2070SN/A switch (Etype) 2080SN/A { 2094013Sdarcy case ACPI_TYPE_INTEGER: 2104013Sdarcy return (ACPI_BTYPE_COMPUTE_DATA | ACPI_BTYPE_DDB_HANDLE); 2114013Sdarcy 2124013Sdarcy case ACPI_TYPE_STRING: 2134013Sdarcy case ACPI_TYPE_BUFFER: 2144013Sdarcy return (ACPI_BTYPE_COMPUTE_DATA); 2154013Sdarcy 2164013Sdarcy case ACPI_TYPE_PACKAGE: 2170SN/A return (ACPI_BTYPE_PACKAGE); 2180SN/A 2190SN/A case ACPI_TYPE_FIELD_UNIT: 2200SN/A return (ACPI_BTYPE_COMPUTE_DATA | ACPI_BTYPE_FIELD_UNIT); 2210SN/A 2220SN/A case ACPI_TYPE_BUFFER_FIELD: 2230SN/A return (ACPI_BTYPE_COMPUTE_DATA | ACPI_BTYPE_BUFFER_FIELD); 2240SN/A 2250SN/A case ACPI_TYPE_DDB_HANDLE: 2260SN/A return (ACPI_BTYPE_INTEGER | ACPI_BTYPE_DDB_HANDLE); 2270SN/A 2280SN/A case ACPI_BTYPE_DEBUG_OBJECT: 2290SN/A 2300SN/A /* Cannot be used as a source operand */ 2310SN/A 2320SN/A return (0); 2330SN/A 2340SN/A default: 2350SN/A return (1 << (Etype - 1)); 2360SN/A } 2370SN/A } 2380SN/A 2390SN/A /* Try the internal data types */ 2400SN/A 2410SN/A switch (Etype) 2420SN/A { 2430SN/A case ACPI_TYPE_LOCAL_REGION_FIELD: 2440SN/A case ACPI_TYPE_LOCAL_BANK_FIELD: 2450SN/A case ACPI_TYPE_LOCAL_INDEX_FIELD: 2460SN/A 2470SN/A /* Named fields can be either Integer/Buffer/String */ 2480SN/A 2490SN/A return (ACPI_BTYPE_COMPUTE_DATA | ACPI_BTYPE_FIELD_UNIT); 2500SN/A 2510SN/A case ACPI_TYPE_LOCAL_ALIAS: 2520SN/A 2530SN/A return (ACPI_BTYPE_INTEGER); 2540SN/A 2550SN/A 2560SN/A case ACPI_TYPE_LOCAL_RESOURCE: 2570SN/A case ACPI_TYPE_LOCAL_RESOURCE_FIELD: 2580SN/A 2590SN/A return (ACPI_BTYPE_REFERENCE); 2600SN/A 2610SN/A default: 2620SN/A printf ("Unhandled encoded type: %X\n", Etype); 2630SN/A return (0); 2640SN/A } 2650SN/A} 2660SN/A 2670SN/A 2680SN/A/******************************************************************************* 2690SN/A * 2700SN/A * FUNCTION: AnFormatBtype 2710SN/A * 2720SN/A * PARAMETERS: Btype - Bitfield of ACPI types 2730SN/A * Buffer - Where to put the ascii string 2740SN/A * 2750SN/A * RETURN: None. 2760SN/A * 2770SN/A * DESCRIPTION: Convert a Btype to a string of ACPI types 2780SN/A * 2790SN/A ******************************************************************************/ 2800SN/A 2810SN/Avoid 2820SN/AAnFormatBtype ( 2830SN/A char *Buffer, 2840SN/A UINT32 Btype) 2850SN/A{ 2860SN/A UINT32 Type; 2870SN/A BOOLEAN First = TRUE; 2880SN/A 2890SN/A 2900SN/A *Buffer = 0; 2910SN/A 2920SN/A if (Btype == 0) 2930SN/A { 2940SN/A strcat (Buffer, "NoReturnValue"); 2950SN/A return; 2960SN/A } 2970SN/A 2980SN/A for (Type = 1; Type <= ACPI_TYPE_EXTERNAL_MAX; Type++) 2990SN/A { 3000SN/A if (Btype & 0x00000001) 3010SN/A { 3020SN/A if (!First) 3030SN/A { 3040SN/A strcat (Buffer, "|"); 3050SN/A } 3060SN/A First = FALSE; 3070SN/A strcat (Buffer, AcpiUtGetTypeName (Type)); 3080SN/A } 3090SN/A Btype >>= 1; 3100SN/A } 3110SN/A 3120SN/A if (Btype & 0x00000001) 3130SN/A { 3140SN/A if (!First) 3150SN/A { 3160SN/A strcat (Buffer, "|"); 3170SN/A } 3180SN/A First = FALSE; 3190SN/A strcat (Buffer, "Reference"); 3200SN/A } 321 322 Btype >>= 1; 323 if (Btype & 0x00000001) 324 { 325 if (!First) 326 { 327 strcat (Buffer, "|"); 328 } 329 First = FALSE; 330 strcat (Buffer, "Resource"); 331 } 332} 333 334 335/******************************************************************************* 336 * 337 * FUNCTION: AnGetBtype 338 * 339 * PARAMETERS: Op - Parse node whose type will be returned. 340 * 341 * RETURN: The Btype associated with the Op. 342 * 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. 346 * 347 ******************************************************************************/ 348 349UINT32 350AnGetBtype ( 351 ACPI_PARSE_OBJECT *Op) 352{ 353 ACPI_NAMESPACE_NODE *Node; 354 ACPI_PARSE_OBJECT *ReferencedNode; 355 UINT32 ThisNodeBtype = 0; 356 357 358 if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG) || 359 (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING) || 360 (Op->Asl.ParseOpcode == PARSEOP_METHODCALL)) 361 { 362 Node = Op->Asl.Node; 363 if (!Node) 364 { 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); 370 } 371 372 ThisNodeBtype = AnMapEtypeToBtype (Node->Type); 373 if (!ThisNodeBtype) 374 { 375 AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, Op, 376 "could not map type"); 377 } 378 379 /* 380 * Since it was a named reference, enable the 381 * reference bit also 382 */ 383 ThisNodeBtype |= ACPI_BTYPE_REFERENCE; 384 385 if (Op->Asl.ParseOpcode == PARSEOP_METHODCALL) 386 { 387 ReferencedNode = Node->Op; 388 if (!ReferencedNode) 389 { 390 /* Check for an internal method */ 391 392 if (AnIsInternalMethod (Op)) 393 { 394 return (AnGetInternalMethodReturnType (Op)); 395 } 396 397 AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, Op, 398 "null Op pointer"); 399 return (ACPI_UINT32_MAX); 400 } 401 402 if (ReferencedNode->Asl.CompileFlags & NODE_METHOD_TYPED) 403 { 404 ThisNodeBtype = ReferencedNode->Asl.AcpiBtype; 405 } 406 else 407 { 408 return (ACPI_UINT32_MAX -1); 409 } 410 } 411 } 412 else 413 { 414 ThisNodeBtype = Op->Asl.AcpiBtype; 415 } 416 417 return (ThisNodeBtype); 418} 419 420 421/******************************************************************************* 422 * 423 * FUNCTION: AnMapObjTypeToBtype 424 * 425 * PARAMETERS: Op - A parse node 426 * 427 * RETURN: A Btype 428 * 429 * DESCRIPTION: Map object to the associated "Btype" 430 * 431 ******************************************************************************/ 432 433UINT32 434AnMapObjTypeToBtype ( 435 ACPI_PARSE_OBJECT *Op) 436{ 437 438 switch (Op->Asl.ParseOpcode) 439 { 440 case PARSEOP_OBJECTTYPE_BFF: /* "BuffFieldObj" */ 441 return (ACPI_BTYPE_BUFFER_FIELD); 442 443 case PARSEOP_OBJECTTYPE_BUF: /* "BuffObj" */ 444 return (ACPI_BTYPE_BUFFER); 445 446 case PARSEOP_OBJECTTYPE_DDB: /* "DDBHandleObj" */ 447 return (ACPI_BTYPE_DDB_HANDLE); 448 449 case PARSEOP_OBJECTTYPE_DEV: /* "DeviceObj" */ 450 return (ACPI_BTYPE_DEVICE); 451 452 case PARSEOP_OBJECTTYPE_EVT: /* "EventObj" */ 453 return (ACPI_BTYPE_EVENT); 454 455 case PARSEOP_OBJECTTYPE_FLD: /* "FieldUnitObj" */ 456 return (ACPI_BTYPE_FIELD_UNIT); 457 458 case PARSEOP_OBJECTTYPE_INT: /* "IntObj" */ 459 return (ACPI_BTYPE_INTEGER); 460 461 case PARSEOP_OBJECTTYPE_MTH: /* "MethodObj" */ 462 return (ACPI_BTYPE_METHOD); 463 464 case PARSEOP_OBJECTTYPE_MTX: /* "MutexObj" */ 465 return (ACPI_BTYPE_MUTEX); 466 467 case PARSEOP_OBJECTTYPE_OPR: /* "OpRegionObj" */ 468 return (ACPI_BTYPE_REGION); 469 470 case PARSEOP_OBJECTTYPE_PKG: /* "PkgObj" */ 471 return (ACPI_BTYPE_PACKAGE); 472 473 case PARSEOP_OBJECTTYPE_POW: /* "PowerResObj" */ 474 return (ACPI_BTYPE_POWER); 475 476 case PARSEOP_OBJECTTYPE_STR: /* "StrObj" */ 477 return (ACPI_BTYPE_STRING); 478 479 case PARSEOP_OBJECTTYPE_THZ: /* "ThermalZoneObj" */ 480 return (ACPI_BTYPE_THERMAL); 481 482 case PARSEOP_OBJECTTYPE_UNK: /* "UnknownObj" */ 483 return (ACPI_BTYPE_OBJECTS_AND_REFS); 484 485 default: 486 return (0); 487 } 488} 489 490 491#ifdef ACPI_OBSOLETE_FUNCTIONS 492/******************************************************************************* 493 * 494 * FUNCTION: AnMapBtypeToEtype 495 * 496 * PARAMETERS: Btype - Bitfield of ACPI types 497 * 498 * RETURN: The Etype corresponding the the Btype 499 * 500 * DESCRIPTION: Convert a bitfield type to an encoded type 501 * 502 ******************************************************************************/ 503 504UINT32 505AnMapBtypeToEtype ( 506 UINT32 Btype) 507{ 508 UINT32 i; 509 UINT32 Etype; 510 511 512 if (Btype == 0) 513 { 514 return (0); 515 } 516 517 Etype = 1; 518 for (i = 1; i < Btype; i *= 2) 519 { 520 Etype++; 521 } 522 523 return (Etype); 524} 525#endif 526