1 /*******************************************************************************
   2  *
   3  * Module Name: dmnames - AML disassembler, names, namestrings, pathnames
   4  *
   5  ******************************************************************************/
   6 
   7 /*
   8  * Copyright (C) 2000 - 2011, 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 
  45 #include "acpi.h"
  46 #include "accommon.h"
  47 #include "acparser.h"
  48 #include "amlcode.h"
  49 #include "acnamesp.h"
  50 #include "acdisasm.h"
  51 
  52 
  53 #ifdef ACPI_DISASSEMBLER
  54 
  55 #define _COMPONENT          ACPI_CA_DEBUGGER
  56         ACPI_MODULE_NAME    ("dmnames")
  57 
  58 /* Local prototypes */
  59 
  60 #ifdef ACPI_OBSOLETE_FUNCTIONS
  61 void
  62 AcpiDmDisplayPath (
  63     ACPI_PARSE_OBJECT       *Op);
  64 #endif
  65 
  66 
  67 /*******************************************************************************
  68  *
  69  * FUNCTION:    AcpiDmDumpName
  70  *
  71  * PARAMETERS:  Name            - 4 character ACPI name
  72  *
  73  * RETURN:      Final length of name
  74  *
  75  * DESCRIPTION: Dump an ACPI name, minus any trailing underscores.
  76  *
  77  ******************************************************************************/
  78 
  79 UINT32
  80 AcpiDmDumpName (
  81     UINT32                  Name)
  82 {
  83     UINT32                  i;
  84     UINT32                  Length;
  85     char                    NewName[4];
  86 
  87 
  88     /* Copy name locally in case the original name is not writeable */
  89 
  90     *ACPI_CAST_PTR (UINT32, &NewName[0]) = Name;
  91 
  92     /* Ensure that the name is printable, even if we have to fix it */
  93 
  94     AcpiUtRepairName (NewName);
  95 
  96     /* Remove all trailing underscores from the name */
  97 
  98     Length = ACPI_NAME_SIZE;
  99     for (i = (ACPI_NAME_SIZE - 1); i != 0; i--)
 100     {
 101         if (NewName[i] == '_')
 102         {
 103             Length--;
 104         }
 105         else
 106         {
 107             break;
 108         }
 109     }
 110 
 111     /* Dump the name, up to the start of the trailing underscores */
 112 
 113     for (i = 0; i < Length; i++)
 114     {
 115         AcpiOsPrintf ("%c", NewName[i]);
 116     }
 117 
 118     return (Length);
 119 }
 120 
 121 
 122 /*******************************************************************************
 123  *
 124  * FUNCTION:    AcpiPsDisplayObjectPathname
 125  *
 126  * PARAMETERS:  WalkState       - Current walk state
 127  *              Op              - Object whose pathname is to be obtained
 128  *
 129  * RETURN:      Status
 130  *
 131  * DESCRIPTION: Diplay the pathname associated with a named object.  Two
 132  *              versions. One searches the parse tree (for parser-only
 133  *              applications suchas AcpiDump), and the other searches the
 134  *              ACPI namespace (the parse tree is probably deleted)
 135  *
 136  ******************************************************************************/
 137 
 138 ACPI_STATUS
 139 AcpiPsDisplayObjectPathname (
 140     ACPI_WALK_STATE         *WalkState,
 141     ACPI_PARSE_OBJECT       *Op)
 142 {
 143     ACPI_STATUS             Status;
 144     ACPI_NAMESPACE_NODE     *Node;
 145     ACPI_BUFFER             Buffer;
 146     UINT32                  DebugLevel;
 147 
 148 
 149     /* Save current debug level so we don't get extraneous debug output */
 150 
 151     DebugLevel = AcpiDbgLevel;
 152     AcpiDbgLevel = 0;
 153 
 154     /* Just get the Node out of the Op object */
 155 
 156     Node = Op->Common.Node;
 157     if (!Node)
 158     {
 159         /* Node not defined in this scope, look it up */
 160 
 161         Status = AcpiNsLookup (WalkState->ScopeInfo, Op->Common.Value.String,
 162                     ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT,
 163                     WalkState, &(Node));
 164 
 165         if (ACPI_FAILURE (Status))
 166         {
 167             /*
 168              * We can't get the pathname since the object
 169              * is not in the namespace.  This can happen during single
 170              * stepping where a dynamic named object is *about* to be created.
 171              */
 172             AcpiOsPrintf ("  [Path not found]");
 173             goto Exit;
 174         }
 175 
 176         /* Save it for next time. */
 177 
 178         Op->Common.Node = Node;
 179     }
 180 
 181     /* Convert NamedDesc/handle to a full pathname */
 182 
 183     Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
 184     Status = AcpiNsHandleToPathname (Node, &Buffer);
 185     if (ACPI_FAILURE (Status))
 186     {
 187         AcpiOsPrintf ("****Could not get pathname****)");
 188         goto Exit;
 189     }
 190 
 191     AcpiOsPrintf ("  (Path %s)", (char *) Buffer.Pointer);
 192     ACPI_FREE (Buffer.Pointer);
 193 
 194 
 195 Exit:
 196     /* Restore the debug level */
 197 
 198     AcpiDbgLevel = DebugLevel;
 199     return (Status);
 200 }
 201 
 202 
 203 /*******************************************************************************
 204  *
 205  * FUNCTION:    AcpiDmNamestring
 206  *
 207  * PARAMETERS:  Name                - ACPI Name string to store
 208  *
 209  * RETURN:      None
 210  *
 211  * DESCRIPTION: Decode and dump an ACPI namestring. Handles prefix characters
 212  *
 213  ******************************************************************************/
 214 
 215 void
 216 AcpiDmNamestring (
 217     char                    *Name)
 218 {
 219     UINT32                  SegCount;
 220 
 221 
 222     if (!Name)
 223     {
 224         return;
 225     }
 226 
 227     /* Handle all Scope Prefix operators */
 228 
 229     while (AcpiPsIsPrefixChar (ACPI_GET8 (Name)))
 230     {
 231         /* Append prefix character */
 232 
 233         AcpiOsPrintf ("%1c", ACPI_GET8 (Name));
 234         Name++;
 235     }
 236 
 237     switch (ACPI_GET8 (Name))
 238     {
 239     case 0:
 240         SegCount = 0;
 241         break;
 242 
 243     case AML_DUAL_NAME_PREFIX:
 244         SegCount = 2;
 245         Name++;
 246         break;
 247 
 248     case AML_MULTI_NAME_PREFIX_OP:
 249         SegCount = (UINT32) ACPI_GET8 (Name + 1);
 250         Name += 2;
 251         break;
 252 
 253     default:
 254         SegCount = 1;
 255         break;
 256     }
 257 
 258     while (SegCount)
 259     {
 260         /* Append Name segment */
 261 
 262         AcpiDmDumpName (*ACPI_CAST_PTR (UINT32, Name));
 263 
 264         SegCount--;
 265         if (SegCount)
 266         {
 267             /* Not last name, append dot separator */
 268 
 269             AcpiOsPrintf (".");
 270         }
 271         Name += ACPI_NAME_SIZE;
 272     }
 273 }
 274 
 275 
 276 #ifdef ACPI_OBSOLETE_FUNCTIONS
 277 /*******************************************************************************
 278  *
 279  * FUNCTION:    AcpiDmDisplayPath
 280  *
 281  * PARAMETERS:  Op                  - Named Op whose path is to be constructed
 282  *
 283  * RETURN:      None
 284  *
 285  * DESCRIPTION: Walk backwards from current scope and display the name
 286  *              of each previous level of scope up to the root scope
 287  *              (like "pwd" does with file systems)
 288  *
 289  ******************************************************************************/
 290 
 291 void
 292 AcpiDmDisplayPath (
 293     ACPI_PARSE_OBJECT       *Op)
 294 {
 295     ACPI_PARSE_OBJECT       *Prev;
 296     ACPI_PARSE_OBJECT       *Search;
 297     UINT32                  Name;
 298     BOOLEAN                 DoDot = FALSE;
 299     ACPI_PARSE_OBJECT       *NamePath;
 300     const ACPI_OPCODE_INFO  *OpInfo;
 301 
 302 
 303     /* We are only interested in named objects */
 304 
 305     OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
 306     if (!(OpInfo->Flags & AML_NSNODE))
 307     {
 308         return;
 309     }
 310 
 311     if (OpInfo->Flags & AML_CREATE)
 312     {
 313         /* Field creation - check for a fully qualified namepath */
 314 
 315         if (Op->Common.AmlOpcode == AML_CREATE_FIELD_OP)
 316         {
 317             NamePath = AcpiPsGetArg (Op, 3);
 318         }
 319         else
 320         {
 321             NamePath = AcpiPsGetArg (Op, 2);
 322         }
 323 
 324         if ((NamePath) &&
 325             (NamePath->Common.Value.String) &&
 326             (NamePath->Common.Value.String[0] == '\\'))
 327         {
 328             AcpiDmNamestring (NamePath->Common.Value.String);
 329             return;
 330         }
 331     }
 332 
 333     Prev = NULL;            /* Start with Root Node */
 334 
 335     while (Prev != Op)
 336     {
 337         /* Search upwards in the tree to find scope with "prev" as its parent */
 338 
 339         Search = Op;
 340         for (; ;)
 341         {
 342             if (Search->Common.Parent == Prev)
 343             {
 344                 break;
 345             }
 346 
 347             /* Go up one level */
 348 
 349             Search = Search->Common.Parent;
 350         }
 351 
 352         if (Prev)
 353         {
 354             OpInfo = AcpiPsGetOpcodeInfo (Search->Common.AmlOpcode);
 355             if (!(OpInfo->Flags & AML_FIELD))
 356             {
 357                 /* Below root scope, append scope name */
 358 
 359                 if (DoDot)
 360                 {
 361                     /* Append dot */
 362 
 363                     AcpiOsPrintf (".");
 364                 }
 365 
 366                 if (OpInfo->Flags & AML_CREATE)
 367                 {
 368                     if (Op->Common.AmlOpcode == AML_CREATE_FIELD_OP)
 369                     {
 370                         NamePath = AcpiPsGetArg (Op, 3);
 371                     }
 372                     else
 373                     {
 374                         NamePath = AcpiPsGetArg (Op, 2);
 375                     }
 376 
 377                     if ((NamePath) &&
 378                         (NamePath->Common.Value.String))
 379                     {
 380                         AcpiDmDumpName (NamePath->Common.Value.String);
 381                     }
 382                 }
 383                 else
 384                 {
 385                     Name = AcpiPsGetName (Search);
 386                     AcpiDmDumpName ((char *) &Name);
 387                 }
 388 
 389                 DoDot = TRUE;
 390             }
 391         }
 392         Prev = Search;
 393     }
 394 }
 395 
 396 
 397 /*******************************************************************************
 398  *
 399  * FUNCTION:    AcpiDmValidateName
 400  *
 401  * PARAMETERS:  Name            - 4 character ACPI name
 402  *
 403  * RETURN:      None
 404  *
 405  * DESCRIPTION: Lookup the name
 406  *
 407  ******************************************************************************/
 408 
 409 void
 410 AcpiDmValidateName (
 411     char                    *Name,
 412     ACPI_PARSE_OBJECT       *Op)
 413 {
 414 
 415     if ((!Name) ||
 416         (!Op->Common.Parent))
 417     {
 418         return;
 419     }
 420 
 421     if (!Op->Common.Node)
 422     {
 423         AcpiOsPrintf (
 424             " /**** Name not found or not accessible from this scope ****/ ");
 425     }
 426 
 427     ACPI_PARSE_OBJECT       *TargetOp;
 428 
 429 
 430     if ((!Name) ||
 431         (!Op->Common.Parent))
 432     {
 433         return;
 434     }
 435 
 436     TargetOp = AcpiPsFind (Op, Name, 0, 0);
 437     if (!TargetOp)
 438     {
 439         /*
 440          * Didn't find the name in the parse tree.  This may be
 441          * a problem, or it may simply be one of the predefined names
 442          * (such as _OS_).  Rather than worry about looking up all
 443          * the predefined names, just display the name as given
 444          */
 445         AcpiOsPrintf (
 446             " /**** Name not found or not accessible from this scope ****/ ");
 447     }
 448 }
 449 #endif
 450 
 451 #endif
 452 
 453