1/****************************************************************************** 2 * 3 * Module Name: dmrestag - Add tags to resource descriptors (Application-level) 4 * 5 *****************************************************************************/ 6 7/****************************************************************************** 8 * 9 * 1. Copyright Notice 10 * 11 * Some or all of this work - Copyright (c) 1999 - 2012, Intel Corp. 12 * All rights reserved. 13 * 14 * 2. License 15 * 16 * 2.1. This is your license from Intel Corp. under its intellectual property 17 * rights. You may have additional license terms from the party that provided 18 * you this software, covering your right to use that party's intellectual 19 * property rights. 20 * 21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 22 * copy of the source code appearing in this file ("Covered Code") an 23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the 24 * base code distributed originally by Intel ("Original Intel Code") to copy, 25 * make derivatives, distribute, use and display any portion of the Covered 26 * Code in any form, with the right to sublicense such rights; and 27 * 28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 29 * license (with the right to sublicense), under only those claims of Intel 30 * patents that are infringed by the Original Intel Code, to make, use, sell, 31 * offer to sell, and import the Covered Code and derivative works thereof 32 * solely to the minimum extent necessary to exercise the above copyright 33 * license, and in no event shall the patent license extend to any additions 34 * to or modifications of the Original Intel Code. No other license or right 35 * is granted directly or by implication, estoppel or otherwise; 36 * 37 * The above copyright and patent license is granted only if the following 38 * conditions are met: 39 * 40 * 3. Conditions 41 * 42 * 3.1. Redistribution of Source with Rights to Further Distribute Source. 43 * Redistribution of source code of any substantial portion of the Covered 44 * Code or modification with rights to further distribute source must include 45 * the above Copyright Notice, the above License, this list of Conditions, 46 * and the following Disclaimer and Export Compliance provision. In addition, 47 * Licensee must cause all Covered Code to which Licensee contributes to 48 * contain a file documenting the changes Licensee made to create that Covered 49 * Code and the date of any change. Licensee must include in that file the 50 * documentation of any changes made by any predecessor Licensee. Licensee 51 * must include a prominent statement that the modification is derived, 52 * directly or indirectly, from Original Intel Code. 53 * 54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 55 * Redistribution of source code of any substantial portion of the Covered 56 * Code or modification without rights to further distribute source must 57 * include the following Disclaimer and Export Compliance provision in the 58 * documentation and/or other materials provided with distribution. In 59 * addition, Licensee may not authorize further sublicense of source of any 60 * portion of the Covered Code, and must include terms to the effect that the 61 * license from Licensee to its licensee is limited to the intellectual 62 * property embodied in the software Licensee provides to its licensee, and 63 * not to intellectual property embodied in modifications its licensee may 64 * make. 65 * 66 * 3.3. Redistribution of Executable. Redistribution in executable form of any 67 * substantial portion of the Covered Code or modification must reproduce the 68 * above Copyright Notice, and the following Disclaimer and Export Compliance 69 * provision in the documentation and/or other materials provided with the 70 * distribution. 71 * 72 * 3.4. Intel retains all right, title, and interest in and to the Original 73 * Intel Code. 74 * 75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by 76 * Intel shall be used in advertising or otherwise to promote the sale, use or 77 * other dealings in products derived from or relating to the Covered Code 78 * without prior written authorization from Intel. 79 * 80 * 4. Disclaimer and Export Compliance 81 * 82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 88 * PARTICULAR PURPOSE. 89 * 90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 97 * LIMITED REMEDY. 98 * 99 * 4.3. Licensee shall not export, either directly or indirectly, any of this 100 * software or system incorporating such software without first obtaining any 101 * required license or other approval from the U. S. Department of Commerce or 102 * any other agency or department of the United States Government. In the 103 * event Licensee exports any such software from the United States or 104 * re-exports any such software from a foreign destination, Licensee shall 105 * ensure that the distribution and export/re-export of the software is in 106 * compliance with all laws, regulations, orders, or other restrictions of the 107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor 108 * any of its subsidiaries will export/re-export any technical data, process, 109 * software, or service, directly or indirectly, to any country for which the 110 * United States government or any agency thereof requires an export license, 111 * other governmental approval, or letter of assurance, without first obtaining 112 * such license, approval or letter. 113 * 114 *****************************************************************************/ 115 116 117#include "acpi.h" 118#include "accommon.h" 119#include "acparser.h" 120#include "acdisasm.h" 121#include "acnamesp.h" 122#include "amlcode.h" 123 124/* This module used for application-level code only */ 125 126#define _COMPONENT ACPI_CA_DISASSEMBLER 127 ACPI_MODULE_NAME ("dmrestag") 128 129/* Local prototypes */ 130 131static void 132AcpiDmUpdateResourceName ( 133 ACPI_NAMESPACE_NODE *ResourceNode); 134 135static char * 136AcpiDmSearchTagList ( 137 UINT32 BitIndex, 138 const ACPI_RESOURCE_TAG *TagList); 139 140static char * 141AcpiDmGetResourceTag ( 142 UINT32 BitIndex, 143 AML_RESOURCE *Resource, 144 UINT8 ResourceIndex); 145 146static char * 147AcpiGetTagPathname ( 148 ACPI_PARSE_OBJECT *Op, 149 ACPI_NAMESPACE_NODE *BufferNode, 150 ACPI_NAMESPACE_NODE *ResourceNode, 151 UINT32 BitIndex); 152 153static ACPI_NAMESPACE_NODE * 154AcpiDmGetResourceNode ( 155 ACPI_NAMESPACE_NODE *BufferNode, 156 UINT32 BitIndex); 157 158static ACPI_STATUS 159AcpiDmAddResourceToNamespace ( 160 UINT8 *Aml, 161 UINT32 Length, 162 UINT32 Offset, 163 UINT8 ResourceIndex, 164 void *Context); 165 166static void 167AcpiDmAddResourcesToNamespace ( 168 ACPI_NAMESPACE_NODE *BufferNode, 169 ACPI_PARSE_OBJECT *Op); 170 171 172/****************************************************************************** 173 * 174 * Resource Tag tables 175 * 176 * These are the predefined tags that refer to elements of a resource 177 * descriptor. Each name and offset is defined in the ACPI specification. 178 * 179 * Each table entry contains the bit offset of the field and the associated 180 * name. 181 * 182 ******************************************************************************/ 183 184static const ACPI_RESOURCE_TAG AcpiDmIrqTags[] = 185{ 186 {( 1 * 8), ACPI_RESTAG_INTERRUPT}, 187 {( 3 * 8) + 0, ACPI_RESTAG_INTERRUPTTYPE}, 188 {( 3 * 8) + 3, ACPI_RESTAG_INTERRUPTLEVEL}, 189 {( 3 * 8) + 4, ACPI_RESTAG_INTERRUPTSHARE}, 190 {0, NULL} 191}; 192 193static const ACPI_RESOURCE_TAG AcpiDmDmaTags[] = 194{ 195 {( 1 * 8), ACPI_RESTAG_DMA}, 196 {( 2 * 8) + 0, ACPI_RESTAG_XFERTYPE}, 197 {( 2 * 8) + 2, ACPI_RESTAG_BUSMASTER}, 198 {( 2 * 8) + 5, ACPI_RESTAG_DMATYPE}, 199 {0, NULL} 200}; 201 202static const ACPI_RESOURCE_TAG AcpiDmIoTags[] = 203{ 204 {( 1 * 8) + 0, ACPI_RESTAG_DECODE}, 205 {( 2 * 8), ACPI_RESTAG_MINADDR}, 206 {( 4 * 8), ACPI_RESTAG_MAXADDR}, 207 {( 6 * 8), ACPI_RESTAG_ALIGNMENT}, 208 {( 7 * 8), ACPI_RESTAG_LENGTH}, 209 {0, NULL} 210}; 211 212static const ACPI_RESOURCE_TAG AcpiDmFixedIoTags[] = 213{ 214 {( 1 * 8), ACPI_RESTAG_BASEADDRESS}, 215 {( 3 * 8), ACPI_RESTAG_LENGTH}, 216 {0, NULL} 217}; 218 219static const ACPI_RESOURCE_TAG AcpiDmFixedDmaTags[] = 220{ 221 {( 1 * 8), ACPI_RESTAG_DMA}, 222 {( 3 * 8), ACPI_RESTAG_DMATYPE}, 223 {( 5 * 8), ACPI_RESTAG_XFERTYPE}, 224 {0, NULL} 225}; 226 227static const ACPI_RESOURCE_TAG AcpiDmMemory24Tags[] = 228{ 229 {( 3 * 8) + 0, ACPI_RESTAG_READWRITETYPE}, 230 {( 4 * 8), ACPI_RESTAG_MINADDR}, 231 {( 6 * 8), ACPI_RESTAG_MAXADDR}, 232 {( 8 * 8), ACPI_RESTAG_ALIGNMENT}, 233 {(10 * 8), ACPI_RESTAG_LENGTH}, 234 {0, NULL} 235}; 236 237static const ACPI_RESOURCE_TAG AcpiDmRegisterTags[] = 238{ 239 {( 3 * 8), ACPI_RESTAG_ADDRESSSPACE}, 240 {( 4 * 8), ACPI_RESTAG_REGISTERBITWIDTH}, 241 {( 5 * 8), ACPI_RESTAG_REGISTERBITOFFSET}, 242 {( 6 * 8), ACPI_RESTAG_ACCESSSIZE}, 243 {( 7 * 8), ACPI_RESTAG_ADDRESS}, 244 {0, NULL} 245}; 246 247static const ACPI_RESOURCE_TAG AcpiDmMemory32Tags[] = 248{ 249 {( 3 * 8) + 0, ACPI_RESTAG_READWRITETYPE}, 250 {( 4 * 8), ACPI_RESTAG_MINADDR}, 251 {( 8 * 8), ACPI_RESTAG_MAXADDR}, 252 {(12 * 8), ACPI_RESTAG_ALIGNMENT}, 253 {(16 * 8), ACPI_RESTAG_LENGTH}, 254 {0, NULL} 255}; 256 257static const ACPI_RESOURCE_TAG AcpiDmFixedMemory32Tags[] = 258{ 259 {( 3 * 8) + 0, ACPI_RESTAG_READWRITETYPE}, 260 {( 4 * 8), ACPI_RESTAG_BASEADDRESS}, 261 {( 8 * 8), ACPI_RESTAG_LENGTH}, 262 {0, NULL} 263}; 264 265static const ACPI_RESOURCE_TAG AcpiDmInterruptTags[] = 266{ 267 {( 3 * 8) + 1, ACPI_RESTAG_INTERRUPTTYPE}, 268 {( 3 * 8) + 2, ACPI_RESTAG_INTERRUPTLEVEL}, 269 {( 3 * 8) + 3, ACPI_RESTAG_INTERRUPTSHARE}, 270 {( 5 * 8), ACPI_RESTAG_INTERRUPT}, 271 {0, NULL} 272}; 273 274static const ACPI_RESOURCE_TAG AcpiDmAddress16Tags[] = 275{ 276 {( 4 * 8) + 1, ACPI_RESTAG_DECODE}, 277 {( 4 * 8) + 2, ACPI_RESTAG_MINTYPE}, 278 {( 4 * 8) + 3, ACPI_RESTAG_MAXTYPE}, 279 {( 6 * 8), ACPI_RESTAG_GRANULARITY}, 280 {( 8 * 8), ACPI_RESTAG_MINADDR}, 281 {(10 * 8), ACPI_RESTAG_MAXADDR}, 282 {(12 * 8), ACPI_RESTAG_TRANSLATION}, 283 {(14 * 8), ACPI_RESTAG_LENGTH}, 284 {0, NULL} 285}; 286 287static const ACPI_RESOURCE_TAG AcpiDmAddress32Tags[] = 288{ 289 {( 4 * 8) + 1, ACPI_RESTAG_DECODE}, 290 {( 4 * 8) + 2, ACPI_RESTAG_MINTYPE}, 291 {( 4 * 8) + 3, ACPI_RESTAG_MAXTYPE}, 292 {( 6 * 8), ACPI_RESTAG_GRANULARITY}, 293 {(10 * 8), ACPI_RESTAG_MINADDR}, 294 {(14 * 8), ACPI_RESTAG_MAXADDR}, 295 {(18 * 8), ACPI_RESTAG_TRANSLATION}, 296 {(22 * 8), ACPI_RESTAG_LENGTH}, 297 {0, NULL} 298}; 299 300static const ACPI_RESOURCE_TAG AcpiDmAddress64Tags[] = 301{ 302 {( 4 * 8) + 1, ACPI_RESTAG_DECODE}, 303 {( 4 * 8) + 2, ACPI_RESTAG_MINTYPE}, 304 {( 4 * 8) + 3, ACPI_RESTAG_MAXTYPE}, 305 {( 6 * 8), ACPI_RESTAG_GRANULARITY}, 306 {(14 * 8), ACPI_RESTAG_MINADDR}, 307 {(22 * 8), ACPI_RESTAG_MAXADDR}, 308 {(30 * 8), ACPI_RESTAG_TRANSLATION}, 309 {(38 * 8), ACPI_RESTAG_LENGTH}, 310 {0, NULL} 311}; 312 313static const ACPI_RESOURCE_TAG AcpiDmExtendedAddressTags[] = 314{ 315 {( 4 * 8) + 1, ACPI_RESTAG_DECODE}, 316 {( 4 * 8) + 2, ACPI_RESTAG_MINTYPE}, 317 {( 4 * 8) + 3, ACPI_RESTAG_MAXTYPE}, 318 {( 8 * 8), ACPI_RESTAG_GRANULARITY}, 319 {(16 * 8), ACPI_RESTAG_MINADDR}, 320 {(24 * 8), ACPI_RESTAG_MAXADDR}, 321 {(32 * 8), ACPI_RESTAG_TRANSLATION}, 322 {(40 * 8), ACPI_RESTAG_LENGTH}, 323 {(48 * 8), ACPI_RESTAG_TYPESPECIFICATTRIBUTES}, 324 {0, NULL} 325}; 326 327/* Subtype tables for GPIO descriptors */ 328 329static const ACPI_RESOURCE_TAG AcpiDmGpioIntTags[] = 330{ 331 {( 7 * 8) + 0, ACPI_RESTAG_MODE}, 332 {( 7 * 8) + 1, ACPI_RESTAG_POLARITY}, 333 {( 7 * 8) + 3, ACPI_RESTAG_INTERRUPTSHARE}, 334 {( 9 * 8), ACPI_RESTAG_PINCONFIG}, 335 {(10 * 8), ACPI_RESTAG_DRIVESTRENGTH}, 336 {(12 * 8), ACPI_RESTAG_DEBOUNCETIME}, 337 {0, NULL} 338}; 339 340static const ACPI_RESOURCE_TAG AcpiDmGpioIoTags[] = 341{ 342 {( 7 * 8) + 0, ACPI_RESTAG_IORESTRICTION}, 343 {( 7 * 8) + 3, ACPI_RESTAG_INTERRUPTSHARE}, 344 {( 9 * 8), ACPI_RESTAG_PINCONFIG}, 345 {(10 * 8), ACPI_RESTAG_DRIVESTRENGTH}, 346 {(12 * 8), ACPI_RESTAG_DEBOUNCETIME}, 347 {0, NULL} 348}; 349 350/* Subtype tables for SerialBus descriptors */ 351 352static const ACPI_RESOURCE_TAG AcpiDmI2cSerialBusTags[] = 353{ 354 {( 6 * 8) + 0, ACPI_RESTAG_SLAVEMODE}, 355 {( 7 * 8) + 0, ACPI_RESTAG_MODE}, 356 {(12 * 8), ACPI_RESTAG_SPEED}, 357 {(16 * 8), ACPI_RESTAG_ADDRESS}, 358 {0, NULL} 359}; 360 361static const ACPI_RESOURCE_TAG AcpiDmSpiSerialBusTags[] = 362{ 363 {( 6 * 8) + 0, ACPI_RESTAG_SLAVEMODE}, 364 {( 7 * 8) + 0, ACPI_RESTAG_MODE}, 365 {( 7 * 8) + 1, ACPI_RESTAG_DEVICEPOLARITY}, 366 {(12 * 8), ACPI_RESTAG_SPEED}, 367 {(16 * 8), ACPI_RESTAG_LENGTH}, 368 {(17 * 8), ACPI_RESTAG_PHASE}, 369 {(18 * 8), ACPI_RESTAG_POLARITY}, 370 {(19 * 8), ACPI_RESTAG_ADDRESS}, 371 {0, NULL} 372}; 373 374static const ACPI_RESOURCE_TAG AcpiDmUartSerialBusTags[] = 375{ 376 {( 6 * 8) + 0, ACPI_RESTAG_SLAVEMODE}, /* Note: not part of original macro */ 377 {( 7 * 8) + 0, ACPI_RESTAG_FLOWCONTROL}, 378 {( 7 * 8) + 2, ACPI_RESTAG_STOPBITS}, 379 {( 7 * 8) + 4, ACPI_RESTAG_LENGTH}, 380 {( 7 * 8) + 7, ACPI_RESTAG_ENDIANNESS}, 381 {(12 * 8), ACPI_RESTAG_SPEED}, 382 {(16 * 8), ACPI_RESTAG_LENGTH_RX}, 383 {(18 * 8), ACPI_RESTAG_LENGTH_TX}, 384 {(20 * 8), ACPI_RESTAG_PARITY}, 385 {(21 * 8), ACPI_RESTAG_LINE}, 386 {0, NULL} 387}; 388 389/* Subtype tables for Address descriptor type-specific flags */ 390 391static const ACPI_RESOURCE_TAG AcpiDmMemoryFlagTags[] = 392{ 393 {( 5 * 8) + 0, ACPI_RESTAG_READWRITETYPE}, 394 {( 5 * 8) + 1, ACPI_RESTAG_MEMTYPE}, 395 {( 5 * 8) + 3, ACPI_RESTAG_MEMATTRIBUTES}, 396 {( 5 * 8) + 5, ACPI_RESTAG_TYPE}, 397 {0, NULL} 398}; 399 400static const ACPI_RESOURCE_TAG AcpiDmIoFlagTags[] = 401{ 402 {( 5 * 8) + 0, ACPI_RESTAG_RANGETYPE}, 403 {( 5 * 8) + 4, ACPI_RESTAG_TYPE}, 404 {( 5 * 8) + 5, ACPI_RESTAG_TRANSTYPE}, 405 {0, NULL} 406}; 407 408 409/* 410 * Dispatch table used to obtain the correct tag table for a descriptor. 411 * 412 * A NULL in this table means one of three things: 413 * 1) The descriptor ID is reserved and invalid 414 * 2) The descriptor has no tags associated with it 415 * 3) The descriptor has subtypes and a separate table will be used. 416 */ 417static const ACPI_RESOURCE_TAG *AcpiGbl_ResourceTags[] = 418{ 419 /* Small descriptors */ 420 421 NULL, /* 0x00, Reserved */ 422 NULL, /* 0x01, Reserved */ 423 NULL, /* 0x02, Reserved */ 424 NULL, /* 0x03, Reserved */ 425 AcpiDmIrqTags, /* 0x04, ACPI_RESOURCE_NAME_IRQ_FORMAT */ 426 AcpiDmDmaTags, /* 0x05, ACPI_RESOURCE_NAME_DMA_FORMAT */ 427 NULL, /* 0x06, ACPI_RESOURCE_NAME_START_DEPENDENT */ 428 NULL, /* 0x07, ACPI_RESOURCE_NAME_END_DEPENDENT */ 429 AcpiDmIoTags, /* 0x08, ACPI_RESOURCE_NAME_IO_PORT */ 430 AcpiDmFixedIoTags, /* 0x09, ACPI_RESOURCE_NAME_FIXED_IO_PORT */ 431 AcpiDmFixedDmaTags, /* 0x0A, ACPI_RESOURCE_NAME_FIXED_DMA */ 432 NULL, /* 0x0B, Reserved */ 433 NULL, /* 0x0C, Reserved */ 434 NULL, /* 0x0D, Reserved */ 435 NULL, /* 0x0E, ACPI_RESOURCE_NAME_SMALL_VENDOR */ 436 NULL, /* 0x0F, ACPI_RESOURCE_NAME_END_TAG (not used) */ 437 438 /* Large descriptors */ 439 440 NULL, /* 0x00, Reserved */ 441 AcpiDmMemory24Tags, /* 0x01, ACPI_RESOURCE_NAME_MEMORY_24 */ 442 AcpiDmRegisterTags, /* 0x02, ACPI_RESOURCE_NAME_GENERIC_REGISTER */ 443 NULL, /* 0x03, Reserved */ 444 NULL, /* 0x04, ACPI_RESOURCE_NAME_LARGE_VENDOR */ 445 AcpiDmMemory32Tags, /* 0x05, ACPI_RESOURCE_NAME_MEMORY_32 */ 446 AcpiDmFixedMemory32Tags, /* 0x06, ACPI_RESOURCE_NAME_FIXED_MEMORY_32 */ 447 AcpiDmAddress32Tags, /* 0x07, ACPI_RESOURCE_NAME_DWORD_ADDRESS_SPACE */ 448 AcpiDmAddress16Tags, /* 0x08, ACPI_RESOURCE_NAME_WORD_ADDRESS_SPACE */ 449 AcpiDmInterruptTags, /* 0x09, ACPI_RESOURCE_NAME_EXTENDED_XRUPT */ 450 AcpiDmAddress64Tags, /* 0x0A, ACPI_RESOURCE_NAME_QWORD_ADDRESS_SPACE */ 451 AcpiDmExtendedAddressTags, /* 0x0B, ACPI_RESOURCE_NAME_EXTENDED_ADDRESS_SPACE */ 452 NULL, /* 0x0C, ACPI_RESOURCE_NAME_GPIO - Use Subtype table below */ 453 NULL, /* 0x0D, Reserved */ 454 NULL /* 0x0E, ACPI_RESOURCE_NAME_SERIAL_BUS - Use Subtype table below */ 455}; 456 457/* GPIO Subtypes */ 458 459static const ACPI_RESOURCE_TAG *AcpiGbl_GpioResourceTags[] = 460{ 461 AcpiDmGpioIntTags, /* 0x00 Interrupt Connection */ 462 AcpiDmGpioIoTags /* 0x01 I/O Connection */ 463}; 464 465/* Serial Bus Subtypes */ 466 467static const ACPI_RESOURCE_TAG *AcpiGbl_SerialResourceTags[] = 468{ 469 NULL, /* 0x00 Reserved */ 470 AcpiDmI2cSerialBusTags, /* 0x01 I2C SerialBus */ 471 AcpiDmSpiSerialBusTags, /* 0x02 SPI SerialBus */ 472 AcpiDmUartSerialBusTags /* 0x03 UART SerialBus */ 473}; 474 475/* 476 * Globals used to generate unique resource descriptor names. We use names that 477 * start with underscore and a prefix letter that is not used by other ACPI 478 * reserved names. To this, we append hex 0x00 through 0xFF. These 5 prefixes 479 * allow for 5*256 = 1280 unique names, probably sufficient for any single ASL 480 * file. If this becomes too small, we can use alpha+numerals for a total 481 * of 5*36*36 = 6480. 482 */ 483#define ACPI_NUM_RES_PREFIX 5 484 485static UINT32 AcpiGbl_NextResourceId = 0; 486static UINT8 AcpiGbl_NextPrefix = 0; 487static char AcpiGbl_Prefix[ACPI_NUM_RES_PREFIX] = 488 {'Y','Z','J','K','X'}; 489 490 491/******************************************************************************* 492 * 493 * FUNCTION: AcpiDmCheckResourceReference 494 * 495 * PARAMETERS: Op - Parse Op for the AML opcode 496 * WalkState - Current walk state (with valid scope) 497 * 498 * RETURN: None 499 * 500 * DESCRIPTION: Convert a reference to a resource descriptor to a symbolic 501 * reference if possible 502 * 503 * NOTE: Bit index is used to transparently handle both resource bit 504 * fields and byte fields. 505 * 506 ******************************************************************************/ 507 508void 509AcpiDmCheckResourceReference ( 510 ACPI_PARSE_OBJECT *Op, 511 ACPI_WALK_STATE *WalkState) 512{ 513 ACPI_STATUS Status; 514 ACPI_PARSE_OBJECT *BufferNameOp; 515 ACPI_PARSE_OBJECT *IndexOp; 516 ACPI_NAMESPACE_NODE *BufferNode; 517 ACPI_NAMESPACE_NODE *ResourceNode; 518 const ACPI_OPCODE_INFO *OpInfo; 519 UINT32 BitIndex; 520 521 522 /* We are only interested in the CreateXxxxField opcodes */ 523 524 OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode); 525 if (OpInfo->Type != AML_TYPE_CREATE_FIELD) 526 { 527 return; 528 } 529 530 /* Get the buffer term operand */ 531 532 BufferNameOp = AcpiPsGetDepthNext (NULL, Op); 533 534 /* Must be a named buffer, not an arg or local or method call */ 535 536 if (BufferNameOp->Common.AmlOpcode != AML_INT_NAMEPATH_OP) 537 { 538 return; 539 } 540 541 /* Get the Index term, must be an integer constant to convert */ 542 543 IndexOp = BufferNameOp->Common.Next; 544 545 /* Major cheat: The Node field is also used for the Tag ptr. Clear it now */ 546 547 IndexOp->Common.Node = NULL; 548 549 OpInfo = AcpiPsGetOpcodeInfo (IndexOp->Common.AmlOpcode); 550 if (OpInfo->ObjectType != ACPI_TYPE_INTEGER) 551 { 552 return; 553 } 554 555 /* Get the bit offset of the descriptor within the buffer */ 556 557 if ((Op->Common.AmlOpcode == AML_CREATE_BIT_FIELD_OP) || 558 (Op->Common.AmlOpcode == AML_CREATE_FIELD_OP)) 559 { 560 /* Index operand is a bit offset */ 561 562 BitIndex = (UINT32) IndexOp->Common.Value.Integer; 563 } 564 else 565 { 566 /* Index operand is a byte offset, convert to bits */ 567 568 BitIndex = (UINT32) ACPI_MUL_8 (IndexOp->Common.Value.Integer); 569 } 570 571 /* Lookup the buffer in the namespace */ 572 573 Status = AcpiNsLookup (WalkState->ScopeInfo, 574 BufferNameOp->Common.Value.String, ACPI_TYPE_BUFFER, 575 ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, WalkState, 576 &BufferNode); 577 if (ACPI_FAILURE (Status)) 578 { 579 return; 580 } 581 582 /* Validate object type, we must have a buffer */ 583 584 if (BufferNode->Type != ACPI_TYPE_BUFFER) 585 { 586 return; 587 } 588 589 /* Find the resource descriptor node corresponding to the index */ 590 591 ResourceNode = AcpiDmGetResourceNode (BufferNode, BitIndex); 592 if (!ResourceNode) 593 { 594 return; 595 } 596 597 /* Translate the Index to a resource tag pathname */ 598 599 AcpiGetTagPathname (IndexOp, BufferNode, ResourceNode, BitIndex); 600} 601 602 603/******************************************************************************* 604 * 605 * FUNCTION: AcpiDmGetResourceNode 606 * 607 * PARAMETERS: BufferNode - Node for the parent buffer 608 * BitIndex - Index into the resource descriptor 609 * 610 * RETURN: Namespace node for the resource descriptor. NULL if not found 611 * 612 * DESCRIPTION: Find a resource descriptor that corresponds to the bit index 613 * 614 ******************************************************************************/ 615 616static ACPI_NAMESPACE_NODE * 617AcpiDmGetResourceNode ( 618 ACPI_NAMESPACE_NODE *BufferNode, 619 UINT32 BitIndex) 620{ 621 ACPI_NAMESPACE_NODE *Node; 622 UINT32 ByteIndex = ACPI_DIV_8 (BitIndex); 623 624 625 /* 626 * Child list contains an entry for each resource descriptor. Find 627 * the descriptor that corresponds to the Index. 628 * 629 * If there are no children, this is not a resource template 630 */ 631 Node = BufferNode->Child; 632 while (Node) 633 { 634 /* 635 * Check if the Index falls within this resource. 636 * 637 * Value contains the resource offset, Object contains the resource 638 * length (both in bytes) 639 */ 640 if ((ByteIndex >= Node->Value) && 641 (ByteIndex < (Node->Value + Node->Length))) 642 { 643 return (Node); 644 } 645 646 Node = Node->Peer; 647 } 648 649 return (NULL); 650} 651 652 653/******************************************************************************* 654 * 655 * FUNCTION: AcpiGetTagPathname 656 * 657 * PARAMETERS: BufferNode - Node for the parent buffer 658 * ResourceNode - Node for a resource descriptor 659 * BitIndex - Index into the resource descriptor 660 * 661 * RETURN: Full pathname for a resource tag. NULL if no match. 662 * Path is returned in AML (packed) format. 663 * 664 * DESCRIPTION: Convert a BitIndex into a symbolic resource tag (full pathname) 665 * 666 ******************************************************************************/ 667 668static char * 669AcpiGetTagPathname ( 670 ACPI_PARSE_OBJECT *IndexOp, 671 ACPI_NAMESPACE_NODE *BufferNode, 672 ACPI_NAMESPACE_NODE *ResourceNode, 673 UINT32 BitIndex) 674{ 675 ACPI_STATUS Status; 676 UINT32 ResourceBitIndex; 677 UINT8 ResourceTableIndex; 678 ACPI_SIZE RequiredSize; 679 char *Pathname; 680 AML_RESOURCE *Aml; 681 ACPI_PARSE_OBJECT *Op; 682 char *InternalPath; 683 char *Tag; 684 685 686 /* Get the Op that contains the actual buffer data */ 687 688 Op = BufferNode->Op->Common.Value.Arg; 689 Op = Op->Common.Next; 690 if (!Op) 691 { 692 return (NULL); 693 } 694 695 /* Get the individual resource descriptor and validate it */ 696 697 Aml = ACPI_CAST_PTR (AML_RESOURCE, 698 &Op->Named.Data[ResourceNode->Value]); 699 700 Status = AcpiUtValidateResource (Aml, &ResourceTableIndex); 701 if (ACPI_FAILURE (Status)) 702 { 703 return (NULL); 704 } 705 706 /* Get offset into this descriptor (from offset into entire buffer) */ 707 708 ResourceBitIndex = BitIndex - ACPI_MUL_8 (ResourceNode->Value); 709 710 /* Get the tag associated with this resource descriptor and offset */ 711 712 Tag = AcpiDmGetResourceTag (ResourceBitIndex, Aml, ResourceTableIndex); 713 if (!Tag) 714 { 715 return (NULL); 716 } 717 718 /* 719 * Now that we know that we have a reference that can be converted to a 720 * symbol, change the name of the resource to a unique name. 721 */ 722 AcpiDmUpdateResourceName (ResourceNode); 723 724 /* Get the full pathname to the parent buffer */ 725 726 RequiredSize = AcpiNsGetPathnameLength (BufferNode); 727 if (!RequiredSize) 728 { 729 return (NULL); 730 } 731 732 Pathname = ACPI_ALLOCATE_ZEROED (RequiredSize + ACPI_PATH_SEGMENT_LENGTH); 733 if (!Pathname) 734 { 735 return (NULL); 736 } 737 738 Status = AcpiNsBuildExternalPath (BufferNode, RequiredSize, Pathname); 739 if (ACPI_FAILURE (Status)) 740 { 741 return (NULL); 742 } 743 744 /* 745 * Create the full path to the resource and tag by: remove the buffer name, 746 * append the resource descriptor name, append a dot, append the tag name. 747 * 748 * TBD: Always using the full path is a bit brute force, the path can be 749 * often be optimized with carats (if the original buffer namepath is a 750 * single nameseg). This doesn't really matter, because these paths do not 751 * end up in the final compiled AML, it's just an appearance issue for the 752 * disassembled code. 753 */ 754 Pathname[ACPI_STRLEN (Pathname) - ACPI_NAME_SIZE] = 0; 755 ACPI_STRNCAT (Pathname, ResourceNode->Name.Ascii, ACPI_NAME_SIZE); 756 ACPI_STRCAT (Pathname, "."); 757 ACPI_STRNCAT (Pathname, Tag, ACPI_NAME_SIZE); 758 759 /* Internalize the namepath to AML format */ 760 761 AcpiNsInternalizeName (Pathname, &InternalPath); 762 ACPI_FREE (Pathname); 763 764 /* Update the Op with the symbol */ 765 766 AcpiPsInitOp (IndexOp, AML_INT_NAMEPATH_OP); 767 IndexOp->Common.Value.String = InternalPath; 768 769 /* We will need the tag later. Cheat by putting it in the Node field */ 770 771 IndexOp->Common.Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Tag); 772 return (InternalPath); 773} 774 775 776/******************************************************************************* 777 * 778 * FUNCTION: AcpiDmUpdateResourceName 779 * 780 * PARAMETERS: ResourceNode - Node for a resource descriptor 781 * 782 * RETURN: Stores new name in the ResourceNode 783 * 784 * DESCRIPTION: Create a new, unique name for a resource descriptor. Used by 785 * both the disassembly of the descriptor itself and any symbolic 786 * references to the descriptor. Ignored if a unique name has 787 * already been assigned to the resource. 788 * 789 * NOTE: Single threaded, suitable for applications only! 790 * 791 ******************************************************************************/ 792 793static void 794AcpiDmUpdateResourceName ( 795 ACPI_NAMESPACE_NODE *ResourceNode) 796{ 797 char Name[ACPI_NAME_SIZE]; 798 799 800 /* Ignore if a unique name has already been assigned */ 801 802 if (ResourceNode->Name.Integer != ACPI_DEFAULT_RESNAME) 803 { 804 return; 805 } 806 807 /* Generate a new ACPI name for the descriptor */ 808 809 Name[0] = '_'; 810 Name[1] = AcpiGbl_Prefix[AcpiGbl_NextPrefix]; 811 Name[2] = AcpiUtHexToAsciiChar ((UINT64) AcpiGbl_NextResourceId, 4); 812 Name[3] = AcpiUtHexToAsciiChar ((UINT64) AcpiGbl_NextResourceId, 0); 813 814 /* Update globals for next name */ 815 816 AcpiGbl_NextResourceId++; 817 if (AcpiGbl_NextResourceId >= 256) 818 { 819 AcpiGbl_NextResourceId = 0; 820 AcpiGbl_NextPrefix++; 821 if (AcpiGbl_NextPrefix > ACPI_NUM_RES_PREFIX) 822 { 823 AcpiGbl_NextPrefix = 0; 824 } 825 } 826 827 /* Change the resource descriptor name */ 828 829 ResourceNode->Name.Integer = *ACPI_CAST_PTR (UINT32, &Name[0]); 830} 831 832 833/******************************************************************************* 834 * 835 * FUNCTION: AcpiDmGetResourceTag 836 * 837 * PARAMETERS: BitIndex - Index into the resource descriptor 838 * Resource - Pointer to the raw resource data 839 * ResourceIndex - Index correspoinding to the resource type 840 * 841 * RETURN: Pointer to the resource tag (ACPI_NAME). NULL if no match. 842 * 843 * DESCRIPTION: Convert a BitIndex into a symbolic resource tag. 844 * 845 * Note: ResourceIndex should be previously validated and guaranteed to ve 846 * valid. 847 * 848 ******************************************************************************/ 849 850static char * 851AcpiDmGetResourceTag ( 852 UINT32 BitIndex, 853 AML_RESOURCE *Resource, 854 UINT8 ResourceIndex) 855{ 856 const ACPI_RESOURCE_TAG *TagList; 857 char *Tag = NULL; 858 859 860 /* Get the tag list for this resource descriptor type */ 861 862 TagList = AcpiGbl_ResourceTags[ResourceIndex]; 863 864 /* 865 * Handle descriptors that have multiple subtypes 866 */ 867 switch (Resource->DescriptorType) 868 { 869 case ACPI_RESOURCE_NAME_ADDRESS16: 870 case ACPI_RESOURCE_NAME_ADDRESS32: 871 case ACPI_RESOURCE_NAME_ADDRESS64: 872 case ACPI_RESOURCE_NAME_EXTENDED_ADDRESS64: 873 874 /* 875 * Subtype differentiation is the flags. 876 * Kindof brute force, but just blindly search for an index match 877 */ 878 if (Resource->Address.ResourceType == ACPI_ADDRESS_TYPE_MEMORY_RANGE) 879 { 880 Tag = AcpiDmSearchTagList (BitIndex, AcpiDmMemoryFlagTags); 881 } 882 else if (Resource->Address.ResourceType == ACPI_ADDRESS_TYPE_IO_RANGE) 883 { 884 Tag = AcpiDmSearchTagList (BitIndex, AcpiDmIoFlagTags); 885 } 886 887 /* If we found a match, all done. Else, drop to normal search below */ 888 889 if (Tag) 890 { 891 return (Tag); 892 } 893 break; 894 895 case ACPI_RESOURCE_NAME_GPIO: 896 897 /* GPIO connection has 2 subtypes: Interrupt and I/O */ 898 899 if (Resource->Gpio.ConnectionType > AML_RESOURCE_MAX_GPIOTYPE) 900 { 901 return (NULL); 902 } 903 904 TagList = AcpiGbl_GpioResourceTags[Resource->Gpio.ConnectionType]; 905 break; 906 907 case ACPI_RESOURCE_NAME_SERIAL_BUS: 908 909 /* SerialBus has 3 subtypes: I2C, SPI, and UART */ 910 911 if ((Resource->CommonSerialBus.Type == 0) || 912 (Resource->CommonSerialBus.Type > AML_RESOURCE_MAX_SERIALBUSTYPE)) 913 { 914 return (NULL); 915 } 916 917 TagList = AcpiGbl_SerialResourceTags[Resource->CommonSerialBus.Type]; 918 break; 919 920 default: 921 break; 922 } 923 924 /* Search for a match against the BitIndex */ 925 926 if (TagList) 927 { 928 Tag = AcpiDmSearchTagList (BitIndex, TagList); 929 } 930 931 return (Tag); 932} 933 934 935/******************************************************************************* 936 * 937 * FUNCTION: AcpiDmSearchTagList 938 * 939 * PARAMETERS: BitIndex - Index into the resource descriptor 940 * TagList - List to search 941 * 942 * RETURN: Pointer to a tag (ACPI_NAME). NULL if no match found. 943 * 944 * DESCRIPTION: Search a tag list for a match to the input BitIndex. Matches 945 * a fixed offset to a symbolic resource tag name. 946 * 947 ******************************************************************************/ 948 949static char * 950AcpiDmSearchTagList ( 951 UINT32 BitIndex, 952 const ACPI_RESOURCE_TAG *TagList) 953{ 954 955 /* 956 * Walk the null-terminated tag list to find a matching bit offset. 957 * We are looking for an exact match. 958 */ 959 for ( ; TagList->Tag; TagList++) 960 { 961 if (BitIndex == TagList->BitIndex) 962 { 963 return (TagList->Tag); 964 } 965 } 966 967 /* A matching offset was not found */ 968 969 return (NULL); 970} 971 972 973/******************************************************************************* 974 * 975 * FUNCTION: AcpiDmFindResources 976 * 977 * PARAMETERS: Root - Root of the parse tree 978 * 979 * RETURN: None 980 * 981 * DESCRIPTION: Add all ResourceTemplate declarations to the namespace. Each 982 * resource descriptor in each template is given a node -- used 983 * for later conversion of resource references to symbolic refs. 984 * 985 ******************************************************************************/ 986 987void 988AcpiDmFindResources ( 989 ACPI_PARSE_OBJECT *Root) 990{ 991 ACPI_PARSE_OBJECT *Op = Root; 992 ACPI_PARSE_OBJECT *Parent; 993 994 995 /* Walk the entire parse tree */ 996 997 while (Op) 998 { 999 /* We are interested in Buffer() declarations */ 1000 1001 if (Op->Common.AmlOpcode == AML_BUFFER_OP) 1002 { 1003 /* And only declarations of the form Name (XXXX, Buffer()... ) */ 1004 1005 Parent = Op->Common.Parent; 1006 if (Parent->Common.AmlOpcode == AML_NAME_OP) 1007 { 1008 /* 1009 * If the buffer is a resource template, add the individual 1010 * resource descriptors to the namespace, as children of the 1011 * buffer node. 1012 */ 1013 if (ACPI_SUCCESS (AcpiDmIsResourceTemplate (Op))) 1014 { 1015 Op->Common.DisasmOpcode = ACPI_DASM_RESOURCE; 1016 AcpiDmAddResourcesToNamespace (Parent->Common.Node, Op); 1017 } 1018 } 1019 } 1020 1021 Op = AcpiPsGetDepthNext (Root, Op); 1022 } 1023} 1024 1025 1026/******************************************************************************* 1027 * 1028 * FUNCTION: AcpiDmAddResourcesToNamespace 1029 * 1030 * PARAMETERS: BufferNode - Node for the parent buffer 1031 * Op - Parse op for the buffer 1032 * 1033 * RETURN: None 1034 * 1035 * DESCRIPTION: Add an entire resource template to the namespace. Each 1036 * resource descriptor is added as a namespace node. 1037 * 1038 ******************************************************************************/ 1039 1040static void 1041AcpiDmAddResourcesToNamespace ( 1042 ACPI_NAMESPACE_NODE *BufferNode, 1043 ACPI_PARSE_OBJECT *Op) 1044{ 1045 ACPI_PARSE_OBJECT *NextOp; 1046 1047 1048 /* Get to the ByteData list */ 1049 1050 NextOp = Op->Common.Value.Arg; 1051 NextOp = NextOp->Common.Next; 1052 if (!NextOp) 1053 { 1054 return; 1055 } 1056 1057 /* Set Node and Op to point to each other */ 1058 1059 BufferNode->Op = Op; 1060 Op->Common.Node = BufferNode; 1061 1062 /* 1063 * Insert each resource into the namespace 1064 * NextOp contains the Aml pointer and the Aml length 1065 */ 1066 AcpiUtWalkAmlResources ((UINT8 *) NextOp->Named.Data, 1067 (ACPI_SIZE) NextOp->Common.Value.Integer, 1068 AcpiDmAddResourceToNamespace, BufferNode); 1069} 1070 1071 1072/******************************************************************************* 1073 * 1074 * FUNCTION: AcpiDmAddResourceToNamespace 1075 * 1076 * PARAMETERS: ACPI_WALK_AML_CALLBACK 1077 * BufferNode - Node for the parent buffer 1078 * 1079 * RETURN: Status 1080 * 1081 * DESCRIPTION: Add one resource descriptor to the namespace as a child of the 1082 * parent buffer. The same name is used for each descriptor. This 1083 * is changed later to a unique name if the resource is actually 1084 * referenced by an AML operator. 1085 * 1086 ******************************************************************************/ 1087 1088static ACPI_STATUS 1089AcpiDmAddResourceToNamespace ( 1090 UINT8 *Aml, 1091 UINT32 Length, 1092 UINT32 Offset, 1093 UINT8 ResourceIndex, 1094 void *Context) 1095{ 1096 ACPI_STATUS Status; 1097 ACPI_GENERIC_STATE ScopeInfo; 1098 ACPI_NAMESPACE_NODE *Node; 1099 1100 1101 /* TBD: Don't need to add descriptors that have no tags defined? */ 1102 1103 /* Add the resource to the namespace, as child of the buffer */ 1104 1105 ScopeInfo.Scope.Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Context); 1106 Status = AcpiNsLookup (&ScopeInfo, "_TMP", ACPI_TYPE_LOCAL_RESOURCE, 1107 ACPI_IMODE_LOAD_PASS2, 1108 ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE | ACPI_NS_PREFIX_IS_SCOPE, 1109 NULL, &Node); 1110 if (ACPI_FAILURE (Status)) 1111 { 1112 return (AE_OK); 1113 } 1114 1115 /* Set the name to the default, changed later if resource is referenced */ 1116 1117 Node->Name.Integer = ACPI_DEFAULT_RESNAME; 1118 1119 /* Save the offset of the descriptor (within the original buffer) */ 1120 1121 Node->Value = Offset; 1122 Node->Length = Length; 1123 return (AE_OK); 1124} 1125