Print this page
    
acpica-unix2-20130823
PANKOVs restructure
    
      
        | Split | Close | 
      | Expand all | 
      | Collapse all | 
    
    
          --- old/usr/src/uts/intel/io/acpica/executer/exnames.c
          +++ new/usr/src/common/acpica/components/executer/exnames.c
   1      -
   2    1  /******************************************************************************
   3    2   *
   4    3   * Module Name: exnames - interpreter/scanner name load/execute
   5    4   *
   6    5   *****************************************************************************/
   7    6  
   8    7  /*
   9      - * Copyright (C) 2000 - 2011, Intel Corp.
        8 + * Copyright (C) 2000 - 2013, Intel Corp.
  10    9   * All rights reserved.
  11   10   *
  12   11   * Redistribution and use in source and binary forms, with or without
  13   12   * modification, are permitted provided that the following conditions
  14   13   * are met:
  15   14   * 1. Redistributions of source code must retain the above copyright
  16   15   *    notice, this list of conditions, and the following disclaimer,
  17   16   *    without modification.
  18   17   * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  19   18   *    substantially similar to the "NO WARRANTY" disclaimer below
  20   19   *    ("Disclaimer") and any redistribution must be conditioned upon
  21   20   *    including a substantially similar Disclaimer requirement for further
  22   21   *    binary redistribution.
  23   22   * 3. Neither the names of the above-listed copyright holders nor the names
  24   23   *    of any contributors may be used to endorse or promote products derived
  25   24   *    from this software without specific prior written permission.
  26   25   *
  27   26   * Alternatively, this software may be distributed under the terms of the
  28   27   * GNU General Public License ("GPL") version 2 as published by the Free
  29   28   * Software Foundation.
  30   29   *
  31   30   * NO WARRANTY
  32   31   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  33   32   * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  34   33   * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  35   34   * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  36   35   * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  37   36   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  38   37   * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  39   38   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  40   39   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  41   40   * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  42   41   * POSSIBILITY OF SUCH DAMAGES.
  43   42   */
  44   43  
  45   44  #define __EXNAMES_C__
  46   45  
  47   46  #include "acpi.h"
  48   47  #include "accommon.h"
  49   48  #include "acinterp.h"
  50   49  #include "amlcode.h"
  51   50  
  52   51  #define _COMPONENT          ACPI_EXECUTER
  53   52          ACPI_MODULE_NAME    ("exnames")
  54   53  
  55   54  /* Local prototypes */
  56   55  
  57   56  static char *
  58   57  AcpiExAllocateNameString (
  59   58      UINT32                  PrefixCount,
  60   59      UINT32                  NumNameSegs);
  61   60  
  62   61  static ACPI_STATUS
  63   62  AcpiExNameSegment (
  64   63      UINT8                   **InAmlAddress,
  65   64      char                    *NameString);
  
    | ↓ open down ↓ | 46 lines elided | ↑ open up ↑ | 
  66   65  
  67   66  
  68   67  /*******************************************************************************
  69   68   *
  70   69   * FUNCTION:    AcpiExAllocateNameString
  71   70   *
  72   71   * PARAMETERS:  PrefixCount         - Count of parent levels. Special cases:
  73   72   *                                    (-1)==root,  0==none
  74   73   *              NumNameSegs         - count of 4-character name segments
  75   74   *
  76      - * RETURN:      A pointer to the allocated string segment.  This segment must
       75 + * RETURN:      A pointer to the allocated string segment. This segment must
  77   76   *              be deleted by the caller.
  78   77   *
  79   78   * DESCRIPTION: Allocate a buffer for a name string. Ensure allocated name
  80   79   *              string is long enough, and set up prefix if any.
  81   80   *
  82   81   ******************************************************************************/
  83   82  
  84   83  static char *
  85   84  AcpiExAllocateNameString (
  86   85      UINT32                  PrefixCount,
  87   86      UINT32                  NumNameSegs)
  88   87  {
  89   88      char                    *TempPtr;
  90   89      char                    *NameString;
  91   90      UINT32                   SizeNeeded;
  92   91  
  93   92      ACPI_FUNCTION_TRACE (ExAllocateNameString);
  94   93  
  95   94  
  96   95      /*
  97   96       * Allow room for all \ and ^ prefixes, all segments and a MultiNamePrefix.
  98   97       * Also, one byte for the null terminator.
  99   98       * This may actually be somewhat longer than needed.
 100   99       */
 101  100      if (PrefixCount == ACPI_UINT32_MAX)
 102  101      {
 103  102          /* Special case for root */
 104  103  
 105  104          SizeNeeded = 1 + (ACPI_NAME_SIZE * NumNameSegs) + 2 + 1;
 106  105      }
 107  106      else
 108  107      {
 109  108          SizeNeeded = PrefixCount + (ACPI_NAME_SIZE * NumNameSegs) + 2 + 1;
 110  109      }
 111  110  
 112  111      /*
 113  112       * Allocate a buffer for the name.
 114  113       * This buffer must be deleted by the caller!
 115  114       */
 116  115      NameString = ACPI_ALLOCATE (SizeNeeded);
 117  116      if (!NameString)
 118  117      {
 119  118          ACPI_ERROR ((AE_INFO,
 120  119              "Could not allocate size %u", SizeNeeded));
 121  120          return_PTR (NULL);
 122  121      }
 123  122  
 124  123      TempPtr = NameString;
 125  124  
 126  125      /* Set up Root or Parent prefixes if needed */
 127  126  
 128  127      if (PrefixCount == ACPI_UINT32_MAX)
 129  128      {
 130  129          *TempPtr++ = AML_ROOT_PREFIX;
 131  130      }
 132  131      else
 133  132      {
 134  133          while (PrefixCount--)
 135  134          {
 136  135              *TempPtr++ = AML_PARENT_PREFIX;
 137  136          }
 138  137      }
 139  138  
 140  139  
 141  140      /* Set up Dual or Multi prefixes if needed */
 142  141  
 143  142      if (NumNameSegs > 2)
 144  143      {
 145  144          /* Set up multi prefixes   */
 146  145  
 147  146          *TempPtr++ = AML_MULTI_NAME_PREFIX_OP;
 148  147          *TempPtr++ = (char) NumNameSegs;
 149  148      }
 150  149      else if (2 == NumNameSegs)
 151  150      {
 152  151          /* Set up dual prefixes */
 153  152  
 154  153          *TempPtr++ = AML_DUAL_NAME_PREFIX;
 155  154      }
 156  155  
 157  156      /*
 158  157       * Terminate string following prefixes. AcpiExNameSegment() will
 159  158       * append the segment(s)
 160  159       */
 161  160      *TempPtr = 0;
 162  161  
 163  162      return_PTR (NameString);
 164  163  }
 165  164  
 166  165  /*******************************************************************************
 167  166   *
 168  167   * FUNCTION:    AcpiExNameSegment
 169  168   *
 170  169   * PARAMETERS:  InAmlAddress    - Pointer to the name in the AML code
 171  170   *              NameString      - Where to return the name. The name is appended
 172  171   *                                to any existing string to form a namepath
 173  172   *
 174  173   * RETURN:      Status
 175  174   *
 176  175   * DESCRIPTION: Extract an ACPI name (4 bytes) from the AML byte stream
 177  176   *
 178  177   ******************************************************************************/
 179  178  
 180  179  static ACPI_STATUS
 181  180  AcpiExNameSegment (
 182  181      UINT8                   **InAmlAddress,
 183  182      char                    *NameString)
 184  183  {
 185  184      char                    *AmlAddress = (void *) *InAmlAddress;
 186  185      ACPI_STATUS             Status = AE_OK;
 187  186      UINT32                  Index;
 188  187      char                    CharBuf[5];
 189  188  
 190  189  
 191  190      ACPI_FUNCTION_TRACE (ExNameSegment);
 192  191  
 193  192  
 194  193      /*
 195  194       * If first character is a digit, then we know that we aren't looking at a
 196  195       * valid name segment
 197  196       */
 198  197      CharBuf[0] = *AmlAddress;
 199  198  
 200  199      if ('0' <= CharBuf[0] && CharBuf[0] <= '9')
 201  200      {
 202  201          ACPI_ERROR ((AE_INFO, "Invalid leading digit: %c", CharBuf[0]));
 203  202          return_ACPI_STATUS (AE_CTRL_PENDING);
 204  203      }
 205  204  
 206  205      ACPI_DEBUG_PRINT ((ACPI_DB_LOAD, "Bytes from stream:\n"));
 207  206  
 208  207      for (Index = 0;
 209  208          (Index < ACPI_NAME_SIZE) && (AcpiUtValidAcpiChar (*AmlAddress, 0));
 210  209          Index++)
 211  210      {
 212  211          CharBuf[Index] = *AmlAddress++;
 213  212          ACPI_DEBUG_PRINT ((ACPI_DB_LOAD, "%c\n", CharBuf[Index]));
 214  213      }
 215  214  
 216  215  
 217  216      /* Valid name segment  */
 218  217  
 219  218      if (Index == 4)
 220  219      {
 221  220          /* Found 4 valid characters */
 222  221  
 223  222          CharBuf[4] = '\0';
 224  223  
 225  224          if (NameString)
 226  225          {
 227  226              ACPI_STRCAT (NameString, CharBuf);
 228  227              ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
 229  228                  "Appended to - %s\n", NameString));
 230  229          }
 231  230          else
 232  231          {
 233  232              ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
 234  233                  "No Name string - %s\n", CharBuf));
 235  234          }
 236  235      }
 237  236      else if (Index == 0)
 238  237      {
 239  238          /*
 240  239           * First character was not a valid name character,
 241  240           * so we are looking at something other than a name.
 242  241           */
 243  242          ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
 244  243              "Leading character is not alpha: %02Xh (not a name)\n",
 245  244              CharBuf[0]));
 246  245          Status = AE_CTRL_PENDING;
 247  246      }
 248  247      else
 249  248      {
 250  249          /*
 251  250           * Segment started with one or more valid characters, but fewer than
 252  251           * the required 4
 253  252           */
 254  253          Status = AE_AML_BAD_NAME;
 255  254          ACPI_ERROR ((AE_INFO,
 256  255              "Bad character 0x%02x in name, at %p",
 257  256              *AmlAddress, AmlAddress));
 258  257      }
 259  258  
 260  259      *InAmlAddress = ACPI_CAST_PTR (UINT8, AmlAddress);
 261  260      return_ACPI_STATUS (Status);
 262  261  }
 263  262  
 264  263  
 265  264  /*******************************************************************************
 266  265   *
 267  266   * FUNCTION:    AcpiExGetNameString
 268  267   *
 269  268   * PARAMETERS:  DataType            - Object type to be associated with this
 270  269   *                                    name
 271  270   *              InAmlAddress        - Pointer to the namestring in the AML code
 272  271   *              OutNameString       - Where the namestring is returned
 273  272   *              OutNameLength       - Length of the returned string
 274  273   *
 275  274   * RETURN:      Status, namestring and length
 276  275   *
 277  276   * DESCRIPTION: Extract a full namepath from the AML byte stream,
 278  277   *              including any prefixes.
 279  278   *
 280  279   ******************************************************************************/
 281  280  
 282  281  ACPI_STATUS
 283  282  AcpiExGetNameString (
 284  283      ACPI_OBJECT_TYPE        DataType,
 285  284      UINT8                   *InAmlAddress,
 286  285      char                    **OutNameString,
 287  286      UINT32                  *OutNameLength)
 288  287  {
 289  288      ACPI_STATUS             Status = AE_OK;
 290  289      UINT8                   *AmlAddress = InAmlAddress;
 291  290      char                    *NameString = NULL;
 292  291      UINT32                  NumSegments;
 293  292      UINT32                  PrefixCount = 0;
 294  293      BOOLEAN                 HasPrefix = FALSE;
 295  294  
 296  295  
 297  296      ACPI_FUNCTION_TRACE_PTR (ExGetNameString, AmlAddress);
 298  297  
 299  298  
 300  299      if (ACPI_TYPE_LOCAL_REGION_FIELD == DataType   ||
 301  300          ACPI_TYPE_LOCAL_BANK_FIELD == DataType     ||
 302  301          ACPI_TYPE_LOCAL_INDEX_FIELD == DataType)
 303  302      {
 304  303          /* Disallow prefixes for types associated with FieldUnit names */
 305  304  
 306  305          NameString = AcpiExAllocateNameString (0, 1);
 307  306          if (!NameString)
 308  307          {
 309  308              Status = AE_NO_MEMORY;
 310  309          }
 311  310          else
 312  311          {
 313  312              Status = AcpiExNameSegment (&AmlAddress, NameString);
 314  313          }
 315  314      }
 316  315      else
 317  316      {
 318  317          /*
 319  318           * DataType is not a field name.
 320  319           * Examine first character of name for root or parent prefix operators
 321  320           */
 322  321          switch (*AmlAddress)
 323  322          {
 324  323          case AML_ROOT_PREFIX:
 325  324  
 326  325              ACPI_DEBUG_PRINT ((ACPI_DB_LOAD, "RootPrefix(\\) at %p\n",
 327  326                  AmlAddress));
  
    | ↓ open down ↓ | 241 lines elided | ↑ open up ↑ | 
 328  327  
 329  328              /*
 330  329               * Remember that we have a RootPrefix --
 331  330               * see comment in AcpiExAllocateNameString()
 332  331               */
 333  332              AmlAddress++;
 334  333              PrefixCount = ACPI_UINT32_MAX;
 335  334              HasPrefix = TRUE;
 336  335              break;
 337  336  
 338      -
 339  337          case AML_PARENT_PREFIX:
 340  338  
 341  339              /* Increment past possibly multiple parent prefixes */
 342  340  
 343  341              do
 344  342              {
 345  343                  ACPI_DEBUG_PRINT ((ACPI_DB_LOAD, "ParentPrefix (^) at %p\n",
 346  344                      AmlAddress));
 347  345  
 348  346                  AmlAddress++;
 349  347                  PrefixCount++;
 350  348  
 351  349              } while (*AmlAddress == AML_PARENT_PREFIX);
 352  350  
 353  351              HasPrefix = TRUE;
 354  352              break;
 355  353  
 356      -
 357  354          default:
 358  355  
 359  356              /* Not a prefix character */
 360  357  
 361  358              break;
 362  359          }
 363  360  
 364  361          /* Examine first character of name for name segment prefix operator */
 365  362  
 366  363          switch (*AmlAddress)
 367  364          {
 368  365          case AML_DUAL_NAME_PREFIX:
 369  366  
 370  367              ACPI_DEBUG_PRINT ((ACPI_DB_LOAD, "DualNamePrefix at %p\n",
 371  368                  AmlAddress));
 372  369  
 373  370              AmlAddress++;
 374  371              NameString = AcpiExAllocateNameString (PrefixCount, 2);
 375  372              if (!NameString)
 376  373              {
 377  374                  Status = AE_NO_MEMORY;
 378  375                  break;
 379  376              }
 380  377  
 381  378              /* Indicate that we processed a prefix */
  
    | ↓ open down ↓ | 15 lines elided | ↑ open up ↑ | 
 382  379  
 383  380              HasPrefix = TRUE;
 384  381  
 385  382              Status = AcpiExNameSegment (&AmlAddress, NameString);
 386  383              if (ACPI_SUCCESS (Status))
 387  384              {
 388  385                  Status = AcpiExNameSegment (&AmlAddress, NameString);
 389  386              }
 390  387              break;
 391  388  
 392      -
 393  389          case AML_MULTI_NAME_PREFIX_OP:
 394  390  
 395  391              ACPI_DEBUG_PRINT ((ACPI_DB_LOAD, "MultiNamePrefix at %p\n",
 396  392                  AmlAddress));
 397  393  
 398  394              /* Fetch count of segments remaining in name path */
 399  395  
 400  396              AmlAddress++;
 401  397              NumSegments = *AmlAddress;
 402  398  
 403  399              NameString = AcpiExAllocateNameString (PrefixCount, NumSegments);
 404  400              if (!NameString)
 405  401              {
 406  402                  Status = AE_NO_MEMORY;
 407  403                  break;
 408  404              }
 409  405  
 410  406              /* Indicate that we processed a prefix */
 411  407  
 412  408              AmlAddress++;
 413  409              HasPrefix = TRUE;
  
    | ↓ open down ↓ | 11 lines elided | ↑ open up ↑ | 
 414  410  
 415  411              while (NumSegments &&
 416  412                      (Status = AcpiExNameSegment (&AmlAddress, NameString)) ==
 417  413                          AE_OK)
 418  414              {
 419  415                  NumSegments--;
 420  416              }
 421  417  
 422  418              break;
 423  419  
 424      -
 425  420          case 0:
 426  421  
 427  422              /* NullName valid as of 8-12-98 ASL/AML Grammar Update */
 428  423  
 429  424              if (PrefixCount == ACPI_UINT32_MAX)
 430  425              {
 431  426                  ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
 432  427                      "NameSeg is \"\\\" followed by NULL\n"));
 433  428              }
 434  429  
 435  430              /* Consume the NULL byte */
 436  431  
  
    | ↓ open down ↓ | 2 lines elided | ↑ open up ↑ | 
 437  432              AmlAddress++;
 438  433              NameString = AcpiExAllocateNameString (PrefixCount, 0);
 439  434              if (!NameString)
 440  435              {
 441  436                  Status = AE_NO_MEMORY;
 442  437                  break;
 443  438              }
 444  439  
 445  440              break;
 446  441  
 447      -
 448  442          default:
 449  443  
 450  444              /* Name segment string */
 451  445  
 452  446              NameString = AcpiExAllocateNameString (PrefixCount, 1);
 453  447              if (!NameString)
 454  448              {
 455  449                  Status = AE_NO_MEMORY;
 456  450                  break;
 457  451              }
 458  452  
 459  453              Status = AcpiExNameSegment (&AmlAddress, NameString);
 460  454              break;
 461  455          }
 462  456      }
 463  457  
 464  458      if (AE_CTRL_PENDING == Status && HasPrefix)
 465  459      {
 466  460          /* Ran out of segments after processing a prefix */
 467  461  
 468  462          ACPI_ERROR ((AE_INFO,
 469  463              "Malformed Name at %p", NameString));
 470  464          Status = AE_AML_BAD_NAME;
 471  465      }
 472  466  
 473  467      if (ACPI_FAILURE (Status))
 474  468      {
 475  469          if (NameString)
 476  470          {
  
    | ↓ open down ↓ | 19 lines elided | ↑ open up ↑ | 
 477  471              ACPI_FREE (NameString);
 478  472          }
 479  473          return_ACPI_STATUS (Status);
 480  474      }
 481  475  
 482  476      *OutNameString = NameString;
 483  477      *OutNameLength = (UINT32) (AmlAddress - InAmlAddress);
 484  478  
 485  479      return_ACPI_STATUS (Status);
 486  480  }
 487      -
 488      -
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX