Print this page
update to acpica-unix2-20140114
update to acpica-unix2-20131115
acpica-unix2-20130823
PANKOVs restructure

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/intel/io/acpica/namespace/nsutils.c
          +++ new/usr/src/common/acpica/components/namespace/nsutils.c
   1    1  /******************************************************************************
   2    2   *
   3    3   * Module Name: nsutils - Utilities for accessing ACPI namespace, accessing
   4    4   *                        parents and siblings and Scope manipulation
   5    5   *
   6    6   *****************************************************************************/
   7    7  
   8    8  /*
   9      - * Copyright (C) 2000 - 2011, Intel Corp.
        9 + * Copyright (C) 2000 - 2014, Intel Corp.
  10   10   * All rights reserved.
  11   11   *
  12   12   * Redistribution and use in source and binary forms, with or without
  13   13   * modification, are permitted provided that the following conditions
  14   14   * are met:
  15   15   * 1. Redistributions of source code must retain the above copyright
  16   16   *    notice, this list of conditions, and the following disclaimer,
  17   17   *    without modification.
  18   18   * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  19   19   *    substantially similar to the "NO WARRANTY" disclaimer below
↓ open down ↓ 27 lines elided ↑ open up ↑
  47   47  #include "acpi.h"
  48   48  #include "accommon.h"
  49   49  #include "acnamesp.h"
  50   50  #include "amlcode.h"
  51   51  
  52   52  #define _COMPONENT          ACPI_NAMESPACE
  53   53          ACPI_MODULE_NAME    ("nsutils")
  54   54  
  55   55  /* Local prototypes */
  56   56  
  57      -static BOOLEAN
  58      -AcpiNsValidPathSeparator (
  59      -    char                    Sep);
  60      -
  61   57  #ifdef ACPI_OBSOLETE_FUNCTIONS
  62   58  ACPI_NAME
  63   59  AcpiNsFindParentName (
  64   60      ACPI_NAMESPACE_NODE     *NodeToSearch);
  65   61  #endif
  66   62  
  67   63  
  68   64  /*******************************************************************************
  69   65   *
  70   66   * FUNCTION:    AcpiNsPrintNodePathname
↓ open down ↓ 34 lines elided ↑ open up ↑
 105  101          }
 106  102  
 107  103          AcpiOsPrintf ("[%s] (Node %p)", (char *) Buffer.Pointer, Node);
 108  104          ACPI_FREE (Buffer.Pointer);
 109  105      }
 110  106  }
 111  107  
 112  108  
 113  109  /*******************************************************************************
 114  110   *
 115      - * FUNCTION:    AcpiNsValidRootPrefix
 116      - *
 117      - * PARAMETERS:  Prefix          - Character to be checked
 118      - *
 119      - * RETURN:      TRUE if a valid prefix
 120      - *
 121      - * DESCRIPTION: Check if a character is a valid ACPI Root prefix
 122      - *
 123      - ******************************************************************************/
 124      -
 125      -BOOLEAN
 126      -AcpiNsValidRootPrefix (
 127      -    char                    Prefix)
 128      -{
 129      -
 130      -    return ((BOOLEAN) (Prefix == '\\'));
 131      -}
 132      -
 133      -
 134      -/*******************************************************************************
 135      - *
 136      - * FUNCTION:    AcpiNsValidPathSeparator
 137      - *
 138      - * PARAMETERS:  Sep         - Character to be checked
 139      - *
 140      - * RETURN:      TRUE if a valid path separator
 141      - *
 142      - * DESCRIPTION: Check if a character is a valid ACPI path separator
 143      - *
 144      - ******************************************************************************/
 145      -
 146      -static BOOLEAN
 147      -AcpiNsValidPathSeparator (
 148      -    char                    Sep)
 149      -{
 150      -
 151      -    return ((BOOLEAN) (Sep == '.'));
 152      -}
 153      -
 154      -
 155      -/*******************************************************************************
 156      - *
 157  111   * FUNCTION:    AcpiNsGetType
 158  112   *
 159  113   * PARAMETERS:  Node        - Parent Node to be examined
 160  114   *
 161  115   * RETURN:      Type field from Node whose handle is passed
 162  116   *
 163  117   * DESCRIPTION: Return the type of a Namespace node
 164  118   *
 165  119   ******************************************************************************/
 166  120  
 167  121  ACPI_OBJECT_TYPE
 168  122  AcpiNsGetType (
 169  123      ACPI_NAMESPACE_NODE     *Node)
 170  124  {
 171  125      ACPI_FUNCTION_TRACE (NsGetType);
 172  126  
 173  127  
 174  128      if (!Node)
 175  129      {
 176  130          ACPI_WARNING ((AE_INFO, "Null Node parameter"));
 177      -        return_UINT32 (ACPI_TYPE_ANY);
      131 +        return_UINT8 (ACPI_TYPE_ANY);
 178  132      }
 179  133  
 180      -    return_UINT32 ((ACPI_OBJECT_TYPE) Node->Type);
      134 +    return_UINT8 (Node->Type);
 181  135  }
 182  136  
 183  137  
 184  138  /*******************************************************************************
 185  139   *
 186  140   * FUNCTION:    AcpiNsLocal
 187  141   *
 188  142   * PARAMETERS:  Type        - A namespace object type
 189  143   *
 190  144   * RETURN:      LOCAL if names must be found locally in objects of the
↓ open down ↓ 11 lines elided ↑ open up ↑
 202  156  
 203  157  
 204  158      if (!AcpiUtValidObjectType (Type))
 205  159      {
 206  160          /* Type code out of range  */
 207  161  
 208  162          ACPI_WARNING ((AE_INFO, "Invalid Object Type 0x%X", Type));
 209  163          return_UINT32 (ACPI_NS_NORMAL);
 210  164      }
 211  165  
 212      -    return_UINT32 ((UINT32) AcpiGbl_NsProperties[Type] & ACPI_NS_LOCAL);
      166 +    return_UINT32 (AcpiGbl_NsProperties[Type] & ACPI_NS_LOCAL);
 213  167  }
 214  168  
 215  169  
 216  170  /*******************************************************************************
 217  171   *
 218  172   * FUNCTION:    AcpiNsGetInternalNameLength
 219  173   *
 220  174   * PARAMETERS:  Info            - Info struct initialized with the
 221  175   *                                external name pointer.
 222  176   *
↓ open down ↓ 20 lines elided ↑ open up ↑
 243  197      Info->NumSegments = 0;
 244  198      Info->FullyQualified = FALSE;
 245  199  
 246  200      /*
 247  201       * For the internal name, the required length is 4 bytes per segment, plus
 248  202       * 1 each for RootPrefix, MultiNamePrefixOp, segment count, trailing null
 249  203       * (which is not really needed, but no there's harm in putting it there)
 250  204       *
 251  205       * strlen() + 1 covers the first NameSeg, which has no path separator
 252  206       */
 253      -    if (AcpiNsValidRootPrefix (*NextExternalChar))
      207 +    if (ACPI_IS_ROOT_PREFIX (*NextExternalChar))
 254  208      {
 255  209          Info->FullyQualified = TRUE;
 256  210          NextExternalChar++;
 257  211  
 258  212          /* Skip redundant RootPrefix, like \\_SB.PCI0.SBRG.EC0 */
 259  213  
 260      -        while (AcpiNsValidRootPrefix (*NextExternalChar))
      214 +        while (ACPI_IS_ROOT_PREFIX (*NextExternalChar))
 261  215          {
 262  216              NextExternalChar++;
 263  217          }
 264  218      }
 265  219      else
 266  220      {
 267  221          /* Handle Carat prefixes */
 268  222  
 269      -        while (*NextExternalChar == '^')
      223 +        while (ACPI_IS_PARENT_PREFIX (*NextExternalChar))
 270  224          {
 271  225              Info->NumCarats++;
 272  226              NextExternalChar++;
 273  227          }
 274  228      }
 275  229  
 276  230      /*
 277  231       * Determine the number of ACPI name "segments" by counting the number of
 278  232       * path separators within the string. Start with one segment since the
 279  233       * segment count is [(# separators) + 1], and zero separators is ok.
 280  234       */
 281  235      if (*NextExternalChar)
 282  236      {
 283  237          Info->NumSegments = 1;
 284  238          for (i = 0; NextExternalChar[i]; i++)
 285  239          {
 286      -            if (AcpiNsValidPathSeparator (NextExternalChar[i]))
      240 +            if (ACPI_IS_PATH_SEPARATOR (NextExternalChar[i]))
 287  241              {
 288  242                  Info->NumSegments++;
 289  243              }
 290  244          }
 291  245      }
 292  246  
 293  247      Info->Length = (ACPI_NAME_SIZE * Info->NumSegments) +
 294  248                      4 + Info->NumCarats;
 295  249  
 296  250      Info->NextExternalChar = NextExternalChar;
↓ open down ↓ 24 lines elided ↑ open up ↑
 321  275      UINT32                  i;
 322  276  
 323  277  
 324  278      ACPI_FUNCTION_TRACE (NsBuildInternalName);
 325  279  
 326  280  
 327  281      /* Setup the correct prefixes, counts, and pointers */
 328  282  
 329  283      if (Info->FullyQualified)
 330  284      {
 331      -        InternalName[0] = '\\';
      285 +        InternalName[0] = AML_ROOT_PREFIX;
 332  286  
 333  287          if (NumSegments <= 1)
 334  288          {
 335  289              Result = &InternalName[1];
 336  290          }
 337  291          else if (NumSegments == 2)
 338  292          {
 339  293              InternalName[1] = AML_DUAL_NAME_PREFIX;
 340  294              Result = &InternalName[2];
 341  295          }
↓ open down ↓ 8 lines elided ↑ open up ↑
 350  304      {
 351  305          /*
 352  306           * Not fully qualified.
 353  307           * Handle Carats first, then append the name segments
 354  308           */
 355  309          i = 0;
 356  310          if (Info->NumCarats)
 357  311          {
 358  312              for (i = 0; i < Info->NumCarats; i++)
 359  313              {
 360      -                InternalName[i] = '^';
      314 +                InternalName[i] = AML_PARENT_PREFIX;
 361  315              }
 362  316          }
 363  317  
 364  318          if (NumSegments <= 1)
 365  319          {
 366  320              Result = &InternalName[i];
 367  321          }
 368  322          else if (NumSegments == 2)
 369  323          {
 370  324              InternalName[i] = AML_DUAL_NAME_PREFIX;
↓ open down ↓ 6 lines elided ↑ open up ↑
 377  331              Result = &InternalName[(ACPI_SIZE) i+2];
 378  332          }
 379  333      }
 380  334  
 381  335      /* Build the name (minus path separators) */
 382  336  
 383  337      for (; NumSegments; NumSegments--)
 384  338      {
 385  339          for (i = 0; i < ACPI_NAME_SIZE; i++)
 386  340          {
 387      -            if (AcpiNsValidPathSeparator (*ExternalName) ||
      341 +            if (ACPI_IS_PATH_SEPARATOR (*ExternalName) ||
 388  342                 (*ExternalName == 0))
 389  343              {
 390  344                  /* Pad the segment with underscore(s) if segment is short */
 391  345  
 392  346                  Result[i] = '_';
 393  347              }
 394  348              else
 395  349              {
 396  350                  /* Convert the character to uppercase and save it */
 397  351  
 398  352                  Result[i] = (char) ACPI_TOUPPER ((int) *ExternalName);
 399  353                  ExternalName++;
 400  354              }
 401  355          }
 402  356  
 403  357          /* Now we must have a path separator, or the pathname is bad */
 404  358  
 405      -        if (!AcpiNsValidPathSeparator (*ExternalName) &&
      359 +        if (!ACPI_IS_PATH_SEPARATOR (*ExternalName) &&
 406  360              (*ExternalName != 0))
 407  361          {
 408      -            return_ACPI_STATUS (AE_BAD_PARAMETER);
      362 +            return_ACPI_STATUS (AE_BAD_PATHNAME);
 409  363          }
 410  364  
 411  365          /* Move on the next segment */
 412  366  
 413  367          ExternalName++;
 414  368          Result += ACPI_NAME_SIZE;
 415  369      }
 416  370  
 417  371      /* Terminate the string */
 418  372  
↓ open down ↓ 116 lines elided ↑ open up ↑
 535  489          !InternalName           ||
 536  490          !ConvertedName)
 537  491      {
 538  492          return_ACPI_STATUS (AE_BAD_PARAMETER);
 539  493      }
 540  494  
 541  495      /* Check for a prefix (one '\' | one or more '^') */
 542  496  
 543  497      switch (InternalName[0])
 544  498      {
 545      -    case '\\':
      499 +    case AML_ROOT_PREFIX:
      500 +
 546  501          PrefixLength = 1;
 547  502          break;
 548  503  
 549      -    case '^':
      504 +    case AML_PARENT_PREFIX:
      505 +
 550  506          for (i = 0; i < InternalNameLength; i++)
 551  507          {
 552      -            if (InternalName[i] == '^')
      508 +            if (ACPI_IS_PARENT_PREFIX (InternalName[i]))
 553  509              {
 554  510                  PrefixLength = i + 1;
 555  511              }
 556  512              else
 557  513              {
 558  514                  break;
 559  515              }
 560  516          }
 561  517  
 562  518          if (i == InternalNameLength)
 563  519          {
 564  520              PrefixLength = i;
 565  521          }
 566  522  
 567  523          break;
 568  524  
 569  525      default:
      526 +
 570  527          break;
 571  528      }
 572  529  
 573  530      /*
 574  531       * Check for object names. Note that there could be 0-255 of these
 575  532       * 4-byte elements.
 576  533       */
 577  534      if (PrefixLength < InternalNameLength)
 578  535      {
 579  536          switch (InternalName[PrefixLength])
↓ open down ↓ 35 lines elided ↑ open up ↑
 615  572  
 616  573      /*
 617  574       * Calculate the length of ConvertedName, which equals the length
 618  575       * of the prefix, length of all object names, length of any required
 619  576       * punctuation ('.') between object names, plus the NULL terminator.
 620  577       */
 621  578      RequiredLength = PrefixLength + (4 * NumSegments) +
 622  579                          ((NumSegments > 0) ? (NumSegments - 1) : 0) + 1;
 623  580  
 624  581      /*
 625      -     * Check to see if we're still in bounds.  If not, there's a problem
      582 +     * Check to see if we're still in bounds. If not, there's a problem
 626  583       * with InternalName (invalid format).
 627  584       */
 628  585      if (RequiredLength > InternalNameLength)
 629  586      {
 630  587          ACPI_ERROR ((AE_INFO, "Invalid internal name"));
 631  588          return_ACPI_STATUS (AE_BAD_PATHNAME);
 632  589      }
 633  590  
 634  591      /* Build the ConvertedName */
 635  592  
↓ open down ↓ 12 lines elided ↑ open up ↑
 648  605  
 649  606      if (NumSegments > 0)
 650  607      {
 651  608          for (i = 0; i < NumSegments; i++)
 652  609          {
 653  610              if (i > 0)
 654  611              {
 655  612                  (*ConvertedName)[j++] = '.';
 656  613              }
 657  614  
 658      -            (*ConvertedName)[j++] = InternalName[NamesIndex++];
 659      -            (*ConvertedName)[j++] = InternalName[NamesIndex++];
 660      -            (*ConvertedName)[j++] = InternalName[NamesIndex++];
 661      -            (*ConvertedName)[j++] = InternalName[NamesIndex++];
      615 +            /* Copy and validate the 4-char name segment */
      616 +
      617 +            ACPI_MOVE_NAME (&(*ConvertedName)[j], &InternalName[NamesIndex]);
      618 +            AcpiUtRepairName (&(*ConvertedName)[j]);
      619 +
      620 +            j += ACPI_NAME_SIZE;
      621 +            NamesIndex += ACPI_NAME_SIZE;
 662  622          }
 663  623      }
 664  624  
 665  625      if (ConvertedNameLength)
 666  626      {
 667  627          *ConvertedNameLength = (UINT32) RequiredLength;
 668  628      }
 669  629  
 670  630      return_ACPI_STATUS (AE_OK);
 671  631  }
↓ open down ↓ 54 lines elided ↑ open up ↑
 726  686   * RETURN:      none
 727  687   *
 728  688   * DESCRIPTION: free memory allocated for namespace and ACPI table storage.
 729  689   *
 730  690   ******************************************************************************/
 731  691  
 732  692  void
 733  693  AcpiNsTerminate (
 734  694      void)
 735  695  {
 736      -    ACPI_OPERAND_OBJECT     *ObjDesc;
      696 +    ACPI_STATUS             Status;
 737  697  
 738  698  
 739  699      ACPI_FUNCTION_TRACE (NsTerminate);
 740  700  
 741  701  
 742  702      /*
 743      -     * 1) Free the entire namespace -- all nodes and objects
 744      -     *
 745      -     * Delete all object descriptors attached to namepsace nodes
      703 +     * Free the entire namespace -- all nodes and all objects
      704 +     * attached to the nodes
 746  705       */
 747  706      AcpiNsDeleteNamespaceSubtree (AcpiGbl_RootNode);
 748  707  
 749      -    /* Detach any objects attached to the root */
      708 +    /* Delete any objects attached to the root node */
 750  709  
 751      -    ObjDesc = AcpiNsGetAttachedObject (AcpiGbl_RootNode);
 752      -    if (ObjDesc)
      710 +    Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
      711 +    if (ACPI_FAILURE (Status))
 753  712      {
 754      -        AcpiNsDetachObject (AcpiGbl_RootNode);
      713 +        return_VOID;
 755  714      }
 756  715  
      716 +    AcpiNsDeleteNode (AcpiGbl_RootNode);
      717 +    (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
      718 +
 757  719      ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Namespace freed\n"));
 758  720      return_VOID;
 759  721  }
 760  722  
 761  723  
 762  724  /*******************************************************************************
 763  725   *
 764  726   * FUNCTION:    AcpiNsOpensScope
 765  727   *
 766  728   * PARAMETERS:  Type        - A valid namespace type
 767  729   *
 768  730   * RETURN:      NEWSCOPE if the passed type "opens a name scope" according
 769  731   *              to the ACPI specification, else 0
 770  732   *
 771  733   ******************************************************************************/
 772  734  
 773  735  UINT32
 774  736  AcpiNsOpensScope (
 775  737      ACPI_OBJECT_TYPE        Type)
 776  738  {
 777      -    ACPI_FUNCTION_TRACE_STR (NsOpensScope, AcpiUtGetTypeName (Type));
      739 +    ACPI_FUNCTION_ENTRY ();
 778  740  
 779  741  
 780      -    if (!AcpiUtValidObjectType (Type))
      742 +    if (Type > ACPI_TYPE_LOCAL_MAX)
 781  743      {
 782  744          /* type code out of range  */
 783  745  
 784  746          ACPI_WARNING ((AE_INFO, "Invalid Object Type 0x%X", Type));
 785      -        return_UINT32 (ACPI_NS_NORMAL);
      747 +        return (ACPI_NS_NORMAL);
 786  748      }
 787  749  
 788      -    return_UINT32 (((UINT32) AcpiGbl_NsProperties[Type]) & ACPI_NS_NEWSCOPE);
      750 +    return (((UINT32) AcpiGbl_NsProperties[Type]) & ACPI_NS_NEWSCOPE);
 789  751  }
 790  752  
 791  753  
 792  754  /*******************************************************************************
 793  755   *
 794  756   * FUNCTION:    AcpiNsGetNode
 795  757   *
 796  758   * PARAMETERS:  *Pathname   - Name to be found, in external (ASL) format. The
 797  759   *                            \ (backslash) and ^ (carat) prefixes, and the
 798  760   *                            . (period) to separate segments are supported.
 799  761   *              PrefixNode   - Root of subtree to be searched, or NS_ALL for the
 800      - *                            root of the name space.  If Name is fully
      762 + *                            root of the name space. If Name is fully
 801  763   *                            qualified (first INT8 is '\'), the passed value
 802  764   *                            of Scope will not be accessed.
 803  765   *              Flags       - Used to indicate whether to perform upsearch or
 804  766   *                            not.
 805  767   *              ReturnNode  - Where the Node is returned
 806  768   *
 807  769   * DESCRIPTION: Look up a name relative to a given scope and return the
 808      - *              corresponding Node.  NOTE: Scope can be null.
      770 + *              corresponding Node. NOTE: Scope can be null.
 809  771   *
 810  772   * MUTEX:       Locks namespace
 811  773   *
 812  774   ******************************************************************************/
 813  775  
 814  776  ACPI_STATUS
 815  777  AcpiNsGetNode (
 816  778      ACPI_NAMESPACE_NODE     *PrefixNode,
 817  779      const char              *Pathname,
 818  780      UINT32                  Flags,
 819  781      ACPI_NAMESPACE_NODE     **ReturnNode)
 820  782  {
 821  783      ACPI_GENERIC_STATE      ScopeInfo;
 822  784      ACPI_STATUS             Status;
 823  785      char                    *InternalPath;
 824  786  
 825  787  
 826  788      ACPI_FUNCTION_TRACE_PTR (NsGetNode, ACPI_CAST_PTR (char, Pathname));
 827  789  
 828  790  
      791 +    /* Simplest case is a null pathname */
      792 +
 829  793      if (!Pathname)
 830  794      {
 831  795          *ReturnNode = PrefixNode;
 832  796          if (!PrefixNode)
 833  797          {
 834  798              *ReturnNode = AcpiGbl_RootNode;
 835  799          }
 836  800          return_ACPI_STATUS (AE_OK);
 837  801      }
      802 +
      803 +    /* Quick check for a reference to the root */
      804 +
      805 +    if (ACPI_IS_ROOT_PREFIX (Pathname[0]) && (!Pathname[1]))
      806 +    {
      807 +        *ReturnNode = AcpiGbl_RootNode;
      808 +        return_ACPI_STATUS (AE_OK);
      809 +    }
 838  810  
 839  811      /* Convert path to internal representation */
 840  812  
 841  813      Status = AcpiNsInternalizeName (Pathname, &InternalPath);
 842  814      if (ACPI_FAILURE (Status))
 843  815      {
 844  816          return_ACPI_STATUS (Status);
 845  817      }
 846  818  
 847  819      /* Must lock namespace during lookup */
↓ open down ↓ 28 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX