1 /****************************************************************************** 2 * 3 * Module Name: aslbtypes - Support for bitfield types 4 * 5 *****************************************************************************/ 6 7 /* 8 * Copyright (C) 2000 - 2015, Intel Corp. 9 * All rights reserved. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 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. 25 * 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. 29 * 30 * NO WARRANTY 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. 42 */ 43 44 #include "aslcompiler.h" 45 #include "aslcompiler.y.h" 46 #include "amlcode.h" 47 48 49 #define _COMPONENT ACPI_COMPILER 50 ACPI_MODULE_NAME ("aslbtypes") 51 52 /* Local prototypes */ 53 54 static UINT32 55 AnMapEtypeToBtype ( 56 UINT32 Etype); 57 58 59 /******************************************************************************* 60 * 61 * FUNCTION: AnMapArgTypeToBtype 62 * 63 * PARAMETERS: ArgType - The ARGI required type(s) for this 64 * argument, from the opcode info table 65 * 66 * RETURN: The corresponding Bit-encoded types 67 * 68 * DESCRIPTION: Convert an encoded ARGI required argument type code into a 69 * bitfield type code. Implements the implicit source conversion 70 * rules. 71 * 72 ******************************************************************************/ 73 74 UINT32 75 AnMapArgTypeToBtype ( 76 UINT32 ArgType) 77 { 78 79 switch (ArgType) 80 { 81 82 /* Simple types */ 83 84 case ARGI_ANYTYPE: 85 86 return (ACPI_BTYPE_OBJECTS_AND_REFS); 87 88 case ARGI_PACKAGE: 89 90 return (ACPI_BTYPE_PACKAGE); 91 92 case ARGI_EVENT: 93 94 return (ACPI_BTYPE_EVENT); 95 96 case ARGI_MUTEX: 97 98 return (ACPI_BTYPE_MUTEX); 99 100 case ARGI_DDBHANDLE: 101 /* 102 * DDBHandleObject := SuperName 103 * ACPI_BTYPE_REFERENCE_OBJECT: 104 * Index reference as parameter of Load/Unload 105 */ 106 return (ACPI_BTYPE_DDB_HANDLE | ACPI_BTYPE_REFERENCE_OBJECT); 107 108 /* Interchangeable types */ 109 /* 110 * Source conversion rules: 111 * Integer, String, and Buffer are all interchangeable 112 */ 113 case ARGI_INTEGER: 114 case ARGI_STRING: 115 case ARGI_BUFFER: 116 case ARGI_BUFFER_OR_STRING: 117 case ARGI_COMPUTEDATA: 118 119 return (ACPI_BTYPE_COMPUTE_DATA); 120 121 /* References */ 122 123 case ARGI_INTEGER_REF: 124 125 return (ACPI_BTYPE_INTEGER); 126 127 case ARGI_OBJECT_REF: 128 129 return (ACPI_BTYPE_ALL_OBJECTS); 130 131 case ARGI_DEVICE_REF: 132 133 return (ACPI_BTYPE_DEVICE_OBJECTS); 134 135 case ARGI_REFERENCE: 136 137 return (ACPI_BTYPE_NAMED_REFERENCE); /* Name or Namestring */ 138 139 case ARGI_TARGETREF: 140 141 /* 142 * Target operand for most math and logic operators. 143 * Package objects not allowed as target. 144 */ 145 return (ACPI_BTYPE_COMPUTE_DATA | ACPI_BTYPE_DEBUG_OBJECT | 146 ACPI_BTYPE_REFERENCE_OBJECT); 147 148 case ARGI_STORE_TARGET: 149 150 /* Special target for Store(), includes packages */ 151 152 return (ACPI_BTYPE_DATA | ACPI_BTYPE_DEBUG_OBJECT | 153 ACPI_BTYPE_REFERENCE_OBJECT); 154 155 case ARGI_FIXED_TARGET: 156 case ARGI_SIMPLE_TARGET: 157 158 return (ACPI_BTYPE_OBJECTS_AND_REFS); 159 160 /* Complex types */ 161 162 case ARGI_DATAOBJECT: 163 /* 164 * Buffer, string, package or reference to a Op - 165 * Used only by SizeOf operator 166 */ 167 return (ACPI_BTYPE_STRING | ACPI_BTYPE_BUFFER | 168 ACPI_BTYPE_PACKAGE | ACPI_BTYPE_REFERENCE_OBJECT); 169 170 case ARGI_COMPLEXOBJ: 171 172 /* Buffer, String, or package */ 173 174 return (ACPI_BTYPE_STRING | ACPI_BTYPE_BUFFER | 175 ACPI_BTYPE_PACKAGE); 176 177 case ARGI_REF_OR_STRING: 178 179 /* Used by DeRefOf operator only */ 180 181 return (ACPI_BTYPE_STRING | ACPI_BTYPE_REFERENCE_OBJECT); 182 183 case ARGI_REGION_OR_BUFFER: 184 185 /* Used by Load() only. Allow buffers in addition to regions/fields */ 186 187 return (ACPI_BTYPE_REGION | ACPI_BTYPE_BUFFER | 188 ACPI_BTYPE_FIELD_UNIT); 189 190 case ARGI_DATAREFOBJ: 191 192 /* Used by Store() only, as the source operand */ 193 194 return (ACPI_BTYPE_DATA_REFERENCE | ACPI_BTYPE_REFERENCE_OBJECT); 195 196 default: 197 198 break; 199 } 200 201 return (ACPI_BTYPE_OBJECTS_AND_REFS); 202 } 203 204 205 /******************************************************************************* 206 * 207 * FUNCTION: AnMapEtypeToBtype 208 * 209 * PARAMETERS: Etype - Encoded ACPI Type 210 * 211 * RETURN: Btype corresponding to the Etype 212 * 213 * DESCRIPTION: Convert an encoded ACPI type to a bitfield type applying the 214 * operand conversion rules. In other words, returns the type(s) 215 * this Etype is implicitly converted to during interpretation. 216 * 217 ******************************************************************************/ 218 219 static UINT32 220 AnMapEtypeToBtype ( 221 UINT32 Etype) 222 { 223 224 225 if (Etype == ACPI_TYPE_ANY) 226 { 227 return (ACPI_BTYPE_OBJECTS_AND_REFS); 228 } 229 230 /* Try the standard ACPI data types */ 231 232 if (Etype <= ACPI_TYPE_EXTERNAL_MAX) 233 { 234 /* 235 * This switch statement implements the allowed operand conversion 236 * rules as per the "ASL Data Types" section of the ACPI 237 * specification. 238 */ 239 switch (Etype) 240 { 241 case ACPI_TYPE_INTEGER: 242 243 return (ACPI_BTYPE_COMPUTE_DATA | ACPI_BTYPE_DDB_HANDLE); 244 245 case ACPI_TYPE_STRING: 246 case ACPI_TYPE_BUFFER: 247 248 return (ACPI_BTYPE_COMPUTE_DATA); 249 250 case ACPI_TYPE_PACKAGE: 251 252 return (ACPI_BTYPE_PACKAGE); 253 254 case ACPI_TYPE_FIELD_UNIT: 255 256 return (ACPI_BTYPE_COMPUTE_DATA | ACPI_BTYPE_FIELD_UNIT); 257 258 case ACPI_TYPE_BUFFER_FIELD: 259 260 return (ACPI_BTYPE_COMPUTE_DATA | ACPI_BTYPE_BUFFER_FIELD); 261 262 case ACPI_TYPE_DDB_HANDLE: 263 264 return (ACPI_BTYPE_INTEGER | ACPI_BTYPE_DDB_HANDLE); 265 266 case ACPI_TYPE_DEBUG_OBJECT: 267 268 /* Cannot be used as a source operand */ 269 270 return (0); 271 272 default: 273 274 return (1 << (Etype - 1)); 275 } 276 } 277 278 /* Try the internal data types */ 279 280 switch (Etype) 281 { 282 case ACPI_TYPE_LOCAL_REGION_FIELD: 283 case ACPI_TYPE_LOCAL_BANK_FIELD: 284 case ACPI_TYPE_LOCAL_INDEX_FIELD: 285 286 /* Named fields can be either Integer/Buffer/String */ 287 288 return (ACPI_BTYPE_COMPUTE_DATA | ACPI_BTYPE_FIELD_UNIT); 289 290 case ACPI_TYPE_LOCAL_ALIAS: 291 292 return (ACPI_BTYPE_INTEGER); 293 294 295 case ACPI_TYPE_LOCAL_RESOURCE: 296 case ACPI_TYPE_LOCAL_RESOURCE_FIELD: 297 298 return (ACPI_BTYPE_REFERENCE_OBJECT); 299 300 default: 301 302 printf ("Unhandled encoded type: %X\n", Etype); 303 return (0); 304 } 305 } 306 307 308 /******************************************************************************* 309 * 310 * FUNCTION: AnFormatBtype 311 * 312 * PARAMETERS: Btype - Bitfield of ACPI types 313 * Buffer - Where to put the ascii string 314 * 315 * RETURN: None. 316 * 317 * DESCRIPTION: Convert a Btype to a string of ACPI types 318 * 319 ******************************************************************************/ 320 321 void 322 AnFormatBtype ( 323 char *Buffer, 324 UINT32 Btype) 325 { 326 UINT32 Type; 327 BOOLEAN First = TRUE; 328 329 330 *Buffer = 0; 331 332 if (Btype == 0) 333 { 334 strcat (Buffer, "NoReturnValue"); 335 return; 336 } 337 338 for (Type = 1; Type <= ACPI_TYPE_EXTERNAL_MAX; Type++) 339 { 340 if (Btype & 0x00000001) 341 { 342 if (!First) 343 { 344 strcat (Buffer, "|"); 345 } 346 First = FALSE; 347 strcat (Buffer, AcpiUtGetTypeName (Type)); 348 } 349 Btype >>= 1; 350 } 351 352 if (Btype & 0x00000001) 353 { 354 if (!First) 355 { 356 strcat (Buffer, "|"); 357 } 358 First = FALSE; 359 strcat (Buffer, "Reference"); 360 } 361 362 Btype >>= 1; 363 if (Btype & 0x00000001) 364 { 365 if (!First) 366 { 367 strcat (Buffer, "|"); 368 } 369 First = FALSE; 370 strcat (Buffer, "Resource"); 371 } 372 } 373 374 375 /******************************************************************************* 376 * 377 * FUNCTION: AnGetBtype 378 * 379 * PARAMETERS: Op - Parse node whose type will be returned. 380 * 381 * RETURN: The Btype associated with the Op. 382 * 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. 386 * 387 ******************************************************************************/ 388 389 UINT32 390 AnGetBtype ( 391 ACPI_PARSE_OBJECT *Op) 392 { 393 ACPI_NAMESPACE_NODE *Node; 394 ACPI_PARSE_OBJECT *ReferencedNode; 395 UINT32 ThisNodeBtype = 0; 396 397 398 if (!Op) 399 { 400 AcpiOsPrintf ("Null Op in AnGetBtype\n"); 401 return (ACPI_UINT32_MAX); 402 } 403 404 if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG) || 405 (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING) || 406 (Op->Asl.ParseOpcode == PARSEOP_METHODCALL)) 407 { 408 Node = Op->Asl.Node; 409 if (!Node) 410 { 411 DbgPrint (ASL_DEBUG_OUTPUT, 412 "No attached Nsnode: [%s] at line %u name [%s], ignoring typecheck\n", 413 Op->Asl.ParseOpName, Op->Asl.LineNumber, 414 Op->Asl.ExternalName); 415 return (ACPI_UINT32_MAX); 416 } 417 418 ThisNodeBtype = AnMapEtypeToBtype (Node->Type); 419 if (!ThisNodeBtype) 420 { 421 AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, Op, 422 "could not map type"); 423 } 424 425 if (Op->Asl.ParseOpcode == PARSEOP_METHODCALL) 426 { 427 ReferencedNode = Node->Op; 428 if (!ReferencedNode) 429 { 430 /* Check for an internal method */ 431 432 if (AnIsInternalMethod (Op)) 433 { 434 return (AnGetInternalMethodReturnType (Op)); 435 } 436 437 AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, Op, 438 "null Op pointer"); 439 return (ACPI_UINT32_MAX); 440 } 441 442 if (ReferencedNode->Asl.CompileFlags & NODE_METHOD_TYPED) 443 { 444 ThisNodeBtype = ReferencedNode->Asl.AcpiBtype; 445 } 446 else 447 { 448 return (ACPI_UINT32_MAX -1); 449 } 450 } 451 } 452 else 453 { 454 ThisNodeBtype = Op->Asl.AcpiBtype; 455 } 456 457 return (ThisNodeBtype); 458 } 459 460 /******************************************************************************* 461 * 462 * FUNCTION: AnMapObjTypeToBtype 463 * 464 * PARAMETERS: Op - A parse node 465 * 466 * RETURN: A Btype 467 * 468 * DESCRIPTION: Map object to the associated "Btype" 469 * 470 ******************************************************************************/ 471 472 UINT32 473 AnMapObjTypeToBtype ( 474 ACPI_PARSE_OBJECT *Op) 475 { 476 477 switch (Op->Asl.ParseOpcode) 478 { 479 case PARSEOP_OBJECTTYPE_BFF: /* "BuffFieldObj" */ 480 481 return (ACPI_BTYPE_BUFFER_FIELD); 482 483 case PARSEOP_OBJECTTYPE_BUF: /* "BuffObj" */ 484 485 return (ACPI_BTYPE_BUFFER); 486 487 case PARSEOP_OBJECTTYPE_DDB: /* "DDBHandleObj" */ 488 489 return (ACPI_BTYPE_DDB_HANDLE); 490 491 case PARSEOP_OBJECTTYPE_DEV: /* "DeviceObj" */ 492 493 return (ACPI_BTYPE_DEVICE); 494 495 case PARSEOP_OBJECTTYPE_EVT: /* "EventObj" */ 496 497 return (ACPI_BTYPE_EVENT); 498 499 case PARSEOP_OBJECTTYPE_FLD: /* "FieldUnitObj" */ 500 501 return (ACPI_BTYPE_FIELD_UNIT); 502 503 case PARSEOP_OBJECTTYPE_INT: /* "IntObj" */ 504 505 return (ACPI_BTYPE_INTEGER); 506 507 case PARSEOP_OBJECTTYPE_MTH: /* "MethodObj" */ 508 509 return (ACPI_BTYPE_METHOD); 510 511 case PARSEOP_OBJECTTYPE_MTX: /* "MutexObj" */ 512 513 return (ACPI_BTYPE_MUTEX); 514 515 case PARSEOP_OBJECTTYPE_OPR: /* "OpRegionObj" */ 516 517 return (ACPI_BTYPE_REGION); 518 519 case PARSEOP_OBJECTTYPE_PKG: /* "PkgObj" */ 520 521 return (ACPI_BTYPE_PACKAGE); 522 523 case PARSEOP_OBJECTTYPE_POW: /* "PowerResObj" */ 524 525 return (ACPI_BTYPE_POWER); 526 527 case PARSEOP_OBJECTTYPE_STR: /* "StrObj" */ 528 529 return (ACPI_BTYPE_STRING); 530 531 case PARSEOP_OBJECTTYPE_THZ: /* "ThermalZoneObj" */ 532 533 return (ACPI_BTYPE_THERMAL); 534 535 case PARSEOP_OBJECTTYPE_UNK: /* "UnknownObj" */ 536 537 return (ACPI_BTYPE_OBJECTS_AND_REFS); 538 539 default: 540 541 return (0); 542 } 543 } 544 545 546 #ifdef ACPI_OBSOLETE_FUNCTIONS 547 /******************************************************************************* 548 * 549 * FUNCTION: AnMapBtypeToEtype 550 * 551 * PARAMETERS: Btype - Bitfield of ACPI types 552 * 553 * RETURN: The Etype corresponding the the Btype 554 * 555 * DESCRIPTION: Convert a bitfield type to an encoded type 556 * 557 ******************************************************************************/ 558 559 UINT32 560 AnMapBtypeToEtype ( 561 UINT32 Btype) 562 { 563 UINT32 i; 564 UINT32 Etype; 565 566 567 if (Btype == 0) 568 { 569 return (0); 570 } 571 572 Etype = 1; 573 for (i = 1; i < Btype; i *= 2) 574 { 575 Etype++; 576 } 577 578 return (Etype); 579 } 580 #endif 581