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