dmresrc.c revision 245636
1318Srgrimes/******************************************************************************* 2318Srgrimes * 31012Srgrimes * Module Name: dmresrc.c - Resource Descriptor disassembly 4318Srgrimes * 5318Srgrimes ******************************************************************************/ 6318Srgrimes 73357Sache/* 8318Srgrimes * Copyright (C) 2000 - 2013, Intel Corp. 9318Srgrimes * All rights reserved. 10318Srgrimes * 11554Srgrimes * Redistribution and use in source and binary forms, with or without 12554Srgrimes * modification, are permitted provided that the following conditions 132325Sdg * are met: 14318Srgrimes * 1. Redistributions of source code must retain the above copyright 15318Srgrimes * notice, this list of conditions, and the following disclaimer, 162673Sats * without modification. 17350Srgrimes * 2. Redistributions in binary form must reproduce at minimum a disclaimer 18318Srgrimes * substantially similar to the "NO WARRANTY" disclaimer below 191434Sgclarkii * ("Disclaimer") and any redistribution must be conditioned upon 201434Sgclarkii * including a substantially similar Disclaimer requirement for further 211434Sgclarkii * binary redistribution. 221434Sgclarkii * 3. Neither the names of the above-listed copyright holders nor the names 232321Sdg * of any contributors may be used to endorse or promote products derived 24318Srgrimes * from this software without specific prior written permission. 25318Srgrimes * 26318Srgrimes * Alternatively, this software may be distributed under the terms of the 27318Srgrimes * GNU General Public License ("GPL") version 2 as published by the Free 28318Srgrimes * Software Foundation. 291032Sache * 301026Sache * NO WARRANTY 31318Srgrimes * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 321407Swollman * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 33318Srgrimes * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 34318Srgrimes * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 351064Sache * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36318Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 37694Sats * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 383064Sache * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 393064Sache * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 401064Sache * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 411506Sjkh * POSSIBILITY OF SUCH DAMAGES. 421506Sjkh */ 431506Sjkh 442422Sdg 452422Sdg#include <contrib/dev/acpica/include/acpi.h> 463182Swollman#include <contrib/dev/acpica/include/accommon.h> 47714Swollman#include <contrib/dev/acpica/include/amlcode.h> 48318Srgrimes#include <contrib/dev/acpica/include/acdisasm.h> 49714Swollman 50714Swollman#ifdef ACPI_DISASSEMBLER 51714Swollman 52714Swollman#define _COMPONENT ACPI_CA_DEBUGGER 53714Swollman ACPI_MODULE_NAME ("dbresrc") 54714Swollman 55717Swollman 56723Swollman/* Dispatch tables for Resource disassembly functions */ 57777Swollman 58777Swollmanstatic ACPI_RESOURCE_HANDLER AcpiGbl_DmResourceDispatch [] = 59881Swollman{ 601260Sswallace /* Small descriptors */ 612705Sphk 623150Sphk NULL, /* 0x00, Reserved */ 633150Sphk NULL, /* 0x01, Reserved */ 64318Srgrimes NULL, /* 0x02, Reserved */ 653265Sdg NULL, /* 0x03, Reserved */ 663265Sdg AcpiDmIrqDescriptor, /* 0x04, ACPI_RESOURCE_NAME_IRQ_FORMAT */ 673265Sdg AcpiDmDmaDescriptor, /* 0x05, ACPI_RESOURCE_NAME_DMA_FORMAT */ 683357Sache AcpiDmStartDependentDescriptor, /* 0x06, ACPI_RESOURCE_NAME_START_DEPENDENT */ 693357Sache AcpiDmEndDependentDescriptor, /* 0x07, ACPI_RESOURCE_NAME_END_DEPENDENT */ 703357Sache AcpiDmIoDescriptor, /* 0x08, ACPI_RESOURCE_NAME_IO_PORT */ 711260Sswallace AcpiDmFixedIoDescriptor, /* 0x09, ACPI_RESOURCE_NAME_FIXED_IO_PORT */ 721260Sswallace AcpiDmFixedDmaDescriptor, /* 0x0A, ACPI_RESOURCE_NAME_FIXED_DMA */ 731011Sache NULL, /* 0x0B, Reserved */ 741511Sjkh NULL, /* 0x0C, Reserved */ 751508Sjkh NULL, /* 0x0D, Reserved */ 761508Sjkh AcpiDmVendorSmallDescriptor, /* 0x0E, ACPI_RESOURCE_NAME_SMALL_VENDOR */ 77318Srgrimes NULL, /* 0x0F, ACPI_RESOURCE_NAME_END_TAG (not used) */ 78318Srgrimes 79318Srgrimes /* Large descriptors */ 802325Sdg 812325Sdg NULL, /* 0x00, Reserved */ 822325Sdg AcpiDmMemory24Descriptor, /* 0x01, ACPI_RESOURCE_NAME_MEMORY_24 */ 832325Sdg AcpiDmGenericRegisterDescriptor,/* 0x02, ACPI_RESOURCE_NAME_GENERIC_REGISTER */ 842325Sdg NULL, /* 0x03, Reserved */ 852325Sdg AcpiDmVendorLargeDescriptor, /* 0x04, ACPI_RESOURCE_NAME_LARGE_VENDOR */ 862325Sdg AcpiDmMemory32Descriptor, /* 0x05, ACPI_RESOURCE_NAME_MEMORY_32 */ 872325Sdg AcpiDmFixedMemory32Descriptor, /* 0x06, ACPI_RESOURCE_NAME_FIXED_MEMORY_32 */ 882894Sdfr AcpiDmDwordDescriptor, /* 0x07, ACPI_RESOURCE_NAME_DWORD_ADDRESS_SPACE */ 892325Sdg AcpiDmWordDescriptor, /* 0x08, ACPI_RESOURCE_NAME_WORD_ADDRESS_SPACE */ 902325Sdg AcpiDmInterruptDescriptor, /* 0x09, ACPI_RESOURCE_NAME_EXTENDED_XRUPT */ 912325Sdg AcpiDmQwordDescriptor, /* 0x0A, ACPI_RESOURCE_NAME_QWORD_ADDRESS_SPACE */ 922325Sdg AcpiDmExtendedDescriptor, /* 0x0B, ACPI_RESOURCE_NAME_EXTENDED_ADDRESS_SPACE */ 932325Sdg AcpiDmGpioDescriptor, /* 0x0C, ACPI_RESOURCE_NAME_GPIO */ 942325Sdg NULL, /* 0x0D, Reserved */ 95490Srgrimes AcpiDmSerialBusDescriptor /* 0x0E, ACPI_RESOURCE_NAME_SERIAL_BUS */ 96318Srgrimes}; 97526Srgrimes 98318Srgrimes 992321Sdg/* Only used for single-threaded applications */ 100318Srgrimes/* TBD: remove when name is passed as parameter to the dump functions */ 101318Srgrimes 102318Srgrimesstatic UINT32 ResourceName; 103318Srgrimes 104318Srgrimes 1052321Sdg/******************************************************************************* 106398Srgrimes * 107832Swollman * FUNCTION: AcpiDmDescriptorName 1082321Sdg * 1092321Sdg * PARAMETERS: None 110318Srgrimes * 111725Swollman * RETURN: None 112318Srgrimes * 113318Srgrimes * DESCRIPTION: Emit a name for the descriptor if one is present (indicated 114318Srgrimes * by the name being changed from the default name.) A name is only 115318Srgrimes * emitted if a reference to the descriptor has been made somewhere 116318Srgrimes * in the original ASL code. 117318Srgrimes * 118318Srgrimes ******************************************************************************/ 119318Srgrimes 1202823Sjkhvoid 1211012SrgrimesAcpiDmDescriptorName ( 1221012Srgrimes void) 123318Srgrimes{ 124832Swollman 125318Srgrimes if (ResourceName == ACPI_DEFAULT_RESNAME) 126785Srgrimes { 127318Srgrimes return; 128318Srgrimes } 129318Srgrimes 130318Srgrimes AcpiOsPrintf ("%4.4s", (char *) &ResourceName); 131318Srgrimes} 132318Srgrimes 1333168Sse 1343168Sse/******************************************************************************* 135318Srgrimes * 1363265Sdg * FUNCTION: AcpiDmDumpInteger* 1373269Sphk * 1383265Sdg * PARAMETERS: Value - Value to emit 139977Sats * Name - Associated name (emitted as a comment) 140318Srgrimes * 141977Sats * RETURN: None 142318Srgrimes * 1433114Sjkh * DESCRIPTION: Integer output helper functions 1443114Sjkh * 145977Sats ******************************************************************************/ 1461012Srgrimes 1473168Ssevoid 1483168SseAcpiDmDumpInteger8 ( 1493168Sse UINT8 Value, 1503168Sse char *Name) 1512519Sats{ 1521115Salm AcpiOsPrintf ("0x%2.2X, // %s\n", Value, Name); 1531115Salm} 1541115Salm 1551115Salmvoid 1561343SdgAcpiDmDumpInteger16 ( 157977Sats UINT16 Value, 1581343Sdg char *Name) 159368Srgrimes{ 160977Sats AcpiOsPrintf ("0x%4.4X, // %s\n", Value, Name); 161632Srgrimes} 162977Sats 163318Srgrimesvoid 164318SrgrimesAcpiDmDumpInteger32 ( 165962Sats UINT32 Value, 166962Sats char *Name) 1671343Sdg{ 1681343Sdg AcpiOsPrintf ("0x%8.8X, // %s\n", Value, Name); 1691343Sdg} 170318Srgrimes 171318Srgrimesvoid 1721135SnateAcpiDmDumpInteger64 ( 173318Srgrimes UINT64 Value, 174318Srgrimes char *Name) 1751135Snate{ 176318Srgrimes AcpiOsPrintf ("0x%8.8X%8.8X, // %s\n", ACPI_FORMAT_UINT64 (Value), Name); 1771506Sjkh} 1781264Swollman 1791135Snate 180638Snate/******************************************************************************* 181318Srgrimes * 1822114Sphk * FUNCTION: AcpiDmBitList 1832114Sphk * 1842114Sphk * PARAMETERS: Mask - 16-bit value corresponding to 16 interrupt 1852114Sphk * or DMA values 1862114Sphk * 1872114Sphk * RETURN: None 188318Srgrimes * 189318Srgrimes * DESCRIPTION: Dump a bit mask as a list of individual interrupt/DMA levels. 190318Srgrimes * 191318Srgrimes ******************************************************************************/ 192318Srgrimes 1931506Sjkhvoid 1941506SjkhAcpiDmBitList ( 1951507Sjkh UINT16 Mask) 1961506Sjkh{ 197318Srgrimes UINT32 i; 198318Srgrimes BOOLEAN Previous = FALSE; 199454Srgrimes 200937Snate 201937Snate /* Open the initializer list */ 202937Snate 203937Snate AcpiOsPrintf ("{"); 204937Snate 205937Snate /* Examine each bit */ 206318Srgrimes 207318Srgrimes for (i = 0; i < 16; i++) 208660Sjkh { 2091333Sphk /* Only interested in bits that are set to 1 */ 2101344Sache 211660Sjkh if (Mask & 1) 2121259Sswallace { 213657Sjkh if (Previous) 2141259Sswallace { 2151356Sache AcpiOsPrintf (","); 2161344Sache } 2171406Sache Previous = TRUE; 2183272Sdg AcpiOsPrintf ("%u", i); 2193272Sdg } 2203272Sdg 2211490Sjkh Mask >>= 1; 2221406Sache } 2231407Swollman 224318Srgrimes /* Close list */ 225318Srgrimes 2263341Sphk AcpiOsPrintf ("}\n"); 2273341Sphk} 228 229 230/******************************************************************************* 231 * 232 * FUNCTION: AcpiDmResourceTemplate 233 * 234 * PARAMETERS: Info - Curent parse tree walk info 235 * ByteData - Pointer to the byte list data 236 * ByteCount - Length of the byte list 237 * 238 * RETURN: None 239 * 240 * DESCRIPTION: Dump the contents of a Resource Template containing a set of 241 * Resource Descriptors. 242 * 243 ******************************************************************************/ 244 245void 246AcpiDmResourceTemplate ( 247 ACPI_OP_WALK_INFO *Info, 248 ACPI_PARSE_OBJECT *Op, 249 UINT8 *ByteData, 250 UINT32 ByteCount) 251{ 252 ACPI_STATUS Status; 253 UINT32 CurrentByteOffset; 254 UINT8 ResourceType; 255 UINT32 ResourceLength; 256 void *Aml; 257 UINT32 Level; 258 BOOLEAN DependentFns = FALSE; 259 UINT8 ResourceIndex; 260 ACPI_NAMESPACE_NODE *Node; 261 262 263 Level = Info->Level; 264 ResourceName = ACPI_DEFAULT_RESNAME; 265 Node = Op->Common.Node; 266 if (Node) 267 { 268 Node = Node->Child; 269 } 270 271 for (CurrentByteOffset = 0; CurrentByteOffset < ByteCount;) 272 { 273 Aml = &ByteData[CurrentByteOffset]; 274 275 /* Get the descriptor type and length */ 276 277 ResourceType = AcpiUtGetResourceType (Aml); 278 ResourceLength = AcpiUtGetResourceLength (Aml); 279 280 /* Validate the Resource Type and Resource Length */ 281 282 Status = AcpiUtValidateResource (NULL, Aml, &ResourceIndex); 283 if (ACPI_FAILURE (Status)) 284 { 285 AcpiOsPrintf ("/*** Could not validate Resource, type (%X) %s***/\n", 286 ResourceType, AcpiFormatException (Status)); 287 return; 288 } 289 290 /* Point to next descriptor */ 291 292 CurrentByteOffset += AcpiUtGetDescriptorLength (Aml); 293 294 /* Descriptor pre-processing */ 295 296 switch (ResourceType) 297 { 298 case ACPI_RESOURCE_NAME_START_DEPENDENT: 299 300 /* Finish a previous StartDependentFns */ 301 302 if (DependentFns) 303 { 304 Level--; 305 AcpiDmIndent (Level); 306 AcpiOsPrintf ("}\n"); 307 } 308 break; 309 310 case ACPI_RESOURCE_NAME_END_DEPENDENT: 311 312 Level--; 313 DependentFns = FALSE; 314 break; 315 316 case ACPI_RESOURCE_NAME_END_TAG: 317 318 /* Normal exit, the resource list is finished */ 319 320 if (DependentFns) 321 { 322 /* 323 * Close an open StartDependentDescriptor. This indicates a 324 * missing EndDependentDescriptor. 325 */ 326 Level--; 327 DependentFns = FALSE; 328 329 /* Go ahead and insert EndDependentFn() */ 330 331 AcpiDmEndDependentDescriptor (Aml, ResourceLength, Level); 332 333 AcpiDmIndent (Level); 334 AcpiOsPrintf ( 335 "/*** Disassembler: inserted missing EndDependentFn () ***/\n"); 336 } 337 return; 338 339 default: 340 break; 341 } 342 343 /* Disassemble the resource structure */ 344 345 if (Node) 346 { 347 ResourceName = Node->Name.Integer; 348 Node = Node->Peer; 349 } 350 351 AcpiGbl_DmResourceDispatch [ResourceIndex] ( 352 Aml, ResourceLength, Level); 353 354 /* Descriptor post-processing */ 355 356 if (ResourceType == ACPI_RESOURCE_NAME_START_DEPENDENT) 357 { 358 DependentFns = TRUE; 359 Level++; 360 } 361 } 362} 363 364 365/******************************************************************************* 366 * 367 * FUNCTION: AcpiDmIsResourceTemplate 368 * 369 * PARAMETERS: WalkState - Current walk info 370 * Op - Buffer Op to be examined 371 * 372 * RETURN: Status. AE_OK if valid template 373 * 374 * DESCRIPTION: Walk a byte list to determine if it consists of a valid set 375 * of resource descriptors. Nothing is output. 376 * 377 ******************************************************************************/ 378 379ACPI_STATUS 380AcpiDmIsResourceTemplate ( 381 ACPI_WALK_STATE *WalkState, 382 ACPI_PARSE_OBJECT *Op) 383{ 384 ACPI_STATUS Status; 385 ACPI_PARSE_OBJECT *NextOp; 386 UINT8 *Aml; 387 UINT8 *EndAml; 388 ACPI_SIZE Length; 389 390 391 /* This op must be a buffer */ 392 393 if (Op->Common.AmlOpcode != AML_BUFFER_OP) 394 { 395 return (AE_TYPE); 396 } 397 398 /* Get the ByteData list and length */ 399 400 NextOp = Op->Common.Value.Arg; 401 if (!NextOp) 402 { 403 AcpiOsPrintf ("NULL byte list in buffer\n"); 404 return (AE_TYPE); 405 } 406 407 NextOp = NextOp->Common.Next; 408 if (!NextOp) 409 { 410 return (AE_TYPE); 411 } 412 413 Aml = NextOp->Named.Data; 414 Length = (ACPI_SIZE) NextOp->Common.Value.Integer; 415 416 /* Walk the byte list, abort on any invalid descriptor type or length */ 417 418 Status = AcpiUtWalkAmlResources (WalkState, Aml, Length, 419 NULL, ACPI_CAST_INDIRECT_PTR (void, &EndAml)); 420 if (ACPI_FAILURE (Status)) 421 { 422 return (AE_TYPE); 423 } 424 425 /* 426 * For the resource template to be valid, one EndTag must appear 427 * at the very end of the ByteList, not before. (For proper disassembly 428 * of a ResourceTemplate, the buffer must not have any extra data after 429 * the EndTag.) 430 */ 431 if ((Aml + Length - sizeof (AML_RESOURCE_END_TAG)) != EndAml) 432 { 433 return (AE_AML_NO_RESOURCE_END_TAG); 434 } 435 436 /* 437 * All resource descriptors are valid, therefore this list appears 438 * to be a valid resource template 439 */ 440 return (AE_OK); 441} 442 443#endif 444