Print this page
acpica-unix2-20130823
PANKOVs restructure

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/intel/io/acpica/parser/psargs.c
          +++ new/usr/src/common/acpica/components/parser/psargs.c
   1    1  /******************************************************************************
   2    2   *
   3    3   * Module Name: psargs - Parse AML opcode arguments
   4    4   *
   5    5   *****************************************************************************/
   6    6  
   7    7  /*
   8      - * Copyright (C) 2000 - 2011, Intel Corp.
        8 + * Copyright (C) 2000 - 2013, Intel Corp.
   9    9   * All rights reserved.
  10   10   *
  11   11   * Redistribution and use in source and binary forms, with or without
  12   12   * modification, are permitted provided that the following conditions
  13   13   * are met:
  14   14   * 1. Redistributions of source code must retain the above copyright
  15   15   *    notice, this list of conditions, and the following disclaimer,
  16   16   *    without modification.
  17   17   * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  18   18   *    substantially similar to the "NO WARRANTY" disclaimer below
↓ open down ↓ 105 lines elided ↑ open up ↑
 124  124  
 125  125  /*******************************************************************************
 126  126   *
 127  127   * FUNCTION:    AcpiPsGetNextPackageEnd
 128  128   *
 129  129   * PARAMETERS:  ParserState         - Current parser state object
 130  130   *
 131  131   * RETURN:      Pointer to end-of-package +1
 132  132   *
 133  133   * DESCRIPTION: Get next package length and return a pointer past the end of
 134      - *              the package.  Consumes the package length field
      134 + *              the package. Consumes the package length field
 135  135   *
 136  136   ******************************************************************************/
 137  137  
 138  138  UINT8 *
 139  139  AcpiPsGetNextPackageEnd (
 140  140      ACPI_PARSE_STATE        *ParserState)
 141  141  {
 142  142      UINT8                   *Start = ParserState->Aml;
 143  143      UINT32                  PackageLength;
 144  144  
↓ open down ↓ 11 lines elided ↑ open up ↑
 156  156  
 157  157  /*******************************************************************************
 158  158   *
 159  159   * FUNCTION:    AcpiPsGetNextNamestring
 160  160   *
 161  161   * PARAMETERS:  ParserState         - Current parser state object
 162  162   *
 163  163   * RETURN:      Pointer to the start of the name string (pointer points into
 164  164   *              the AML.
 165  165   *
 166      - * DESCRIPTION: Get next raw namestring within the AML stream.  Handles all name
 167      - *              prefix characters.  Set parser state to point past the string.
      166 + * DESCRIPTION: Get next raw namestring within the AML stream. Handles all name
      167 + *              prefix characters. Set parser state to point past the string.
 168  168   *              (Name is consumed from the AML.)
 169  169   *
 170  170   ******************************************************************************/
 171  171  
 172  172  char *
 173  173  AcpiPsGetNextNamestring (
 174  174      ACPI_PARSE_STATE        *ParserState)
 175  175  {
 176  176      UINT8                   *Start = ParserState->Aml;
 177  177      UINT8                   *End = ParserState->Aml;
 178  178  
 179  179  
 180  180      ACPI_FUNCTION_TRACE (PsGetNextNamestring);
 181  181  
 182  182  
 183  183      /* Point past any namestring prefix characters (backslash or carat) */
 184  184  
 185      -    while (AcpiPsIsPrefixChar (*End))
      185 +    while (ACPI_IS_ROOT_PREFIX (*End) ||
      186 +           ACPI_IS_PARENT_PREFIX (*End))
 186  187      {
 187  188          End++;
 188  189      }
 189  190  
 190  191      /* Decode the path prefix character */
 191  192  
 192  193      switch (*End)
 193  194      {
 194  195      case 0:
 195  196  
↓ open down ↓ 41 lines elided ↑ open up ↑
 237  238   *              Arg                 - Where the namepath will be stored
 238  239   *              ArgCount            - If the namepath points to a control method
 239  240   *                                    the method's argument is returned here.
 240  241   *              PossibleMethodCall  - Whether the namepath can possibly be the
 241  242   *                                    start of a method call
 242  243   *
 243  244   * RETURN:      Status
 244  245   *
 245  246   * DESCRIPTION: Get next name (if method call, return # of required args).
 246  247   *              Names are looked up in the internal namespace to determine
 247      - *              if the name represents a control method.  If a method
      248 + *              if the name represents a control method. If a method
 248  249   *              is found, the number of arguments to the method is returned.
 249  250   *              This information is critical for parsing to continue correctly.
 250  251   *
 251  252   ******************************************************************************/
 252  253  
 253  254  ACPI_STATUS
 254  255  AcpiPsGetNextNamepath (
 255  256      ACPI_WALK_STATE         *WalkState,
 256  257      ACPI_PARSE_STATE        *ParserState,
 257  258      ACPI_PARSE_OBJECT       *Arg,
↓ open down ↓ 181 lines elided ↑ open up ↑
 439  440      {
 440  441      case ARGP_BYTEDATA:
 441  442  
 442  443          /* Get 1 byte from the AML stream */
 443  444  
 444  445          Opcode = AML_BYTE_OP;
 445  446          Arg->Common.Value.Integer = (UINT64) *Aml;
 446  447          Length = 1;
 447  448          break;
 448  449  
 449      -
 450  450      case ARGP_WORDDATA:
 451  451  
 452  452          /* Get 2 bytes from the AML stream */
 453  453  
 454  454          Opcode = AML_WORD_OP;
 455  455          ACPI_MOVE_16_TO_64 (&Arg->Common.Value.Integer, Aml);
 456  456          Length = 2;
 457  457          break;
 458  458  
 459      -
 460  459      case ARGP_DWORDDATA:
 461  460  
 462  461          /* Get 4 bytes from the AML stream */
 463  462  
 464  463          Opcode = AML_DWORD_OP;
 465  464          ACPI_MOVE_32_TO_64 (&Arg->Common.Value.Integer, Aml);
 466  465          Length = 4;
 467  466          break;
 468  467  
 469      -
 470  468      case ARGP_QWORDDATA:
 471  469  
 472  470          /* Get 8 bytes from the AML stream */
 473  471  
 474  472          Opcode = AML_QWORD_OP;
 475  473          ACPI_MOVE_64_TO_64 (&Arg->Common.Value.Integer, Aml);
 476  474          Length = 8;
 477  475          break;
 478  476  
 479      -
 480  477      case ARGP_CHARLIST:
 481  478  
 482  479          /* Get a pointer to the string, point past the string */
 483  480  
 484  481          Opcode = AML_STRING_OP;
 485  482          Arg->Common.Value.String = ACPI_CAST_PTR (char, Aml);
 486  483  
 487  484          /* Find the null terminator */
 488  485  
 489  486          Length = 0;
 490  487          while (Aml[Length])
 491  488          {
 492  489              Length++;
 493  490          }
 494  491          Length++;
 495  492          break;
 496  493  
 497      -
 498  494      case ARGP_NAME:
 499  495      case ARGP_NAMESTRING:
 500  496  
 501  497          AcpiPsInitOp (Arg, AML_INT_NAMEPATH_OP);
 502  498          Arg->Common.Value.Name = AcpiPsGetNextNamestring (ParserState);
 503  499          return_VOID;
 504  500  
 505      -
 506  501      default:
 507  502  
 508  503          ACPI_ERROR ((AE_INFO, "Invalid ArgType 0x%X", ArgType));
 509  504          return_VOID;
 510  505      }
 511  506  
 512  507      AcpiPsInitOp (Arg, Opcode);
 513  508      ParserState->Aml += Length;
 514  509      return_VOID;
 515  510  }
↓ open down ↓ 8 lines elided ↑ open up ↑
 524  519   * RETURN:      A newly allocated FIELD op
 525  520   *
 526  521   * DESCRIPTION: Get next field (NamedField, ReservedField, or AccessField)
 527  522   *
 528  523   ******************************************************************************/
 529  524  
 530  525  static ACPI_PARSE_OBJECT *
 531  526  AcpiPsGetNextField (
 532  527      ACPI_PARSE_STATE        *ParserState)
 533  528  {
 534      -    UINT32                  AmlOffset = (UINT32)
 535      -                                ACPI_PTR_DIFF (ParserState->Aml,
 536      -                                               ParserState->AmlStart);
      529 +    UINT32                  AmlOffset;
 537  530      ACPI_PARSE_OBJECT       *Field;
      531 +    ACPI_PARSE_OBJECT       *Arg = NULL;
 538  532      UINT16                  Opcode;
 539  533      UINT32                  Name;
      534 +    UINT8                   AccessType;
      535 +    UINT8                   AccessAttribute;
      536 +    UINT8                   AccessLength;
      537 +    UINT32                  PkgLength;
      538 +    UINT8                   *PkgEnd;
      539 +    UINT32                  BufferLength;
 540  540  
 541  541  
 542  542      ACPI_FUNCTION_TRACE (PsGetNextField);
 543  543  
 544  544  
      545 +    AmlOffset = (UINT32) ACPI_PTR_DIFF (
      546 +        ParserState->Aml, ParserState->AmlStart);
      547 +
 545  548      /* Determine field type */
 546  549  
 547  550      switch (ACPI_GET8 (ParserState->Aml))
 548  551      {
 549      -    default:
      552 +    case AML_FIELD_OFFSET_OP:
 550  553  
 551      -        Opcode = AML_INT_NAMEDFIELD_OP;
      554 +        Opcode = AML_INT_RESERVEDFIELD_OP;
      555 +        ParserState->Aml++;
 552  556          break;
 553  557  
 554      -    case 0x00:
      558 +    case AML_FIELD_ACCESS_OP:
 555  559  
 556      -        Opcode = AML_INT_RESERVEDFIELD_OP;
      560 +        Opcode = AML_INT_ACCESSFIELD_OP;
 557  561          ParserState->Aml++;
 558  562          break;
 559  563  
 560      -    case 0x01:
      564 +    case AML_FIELD_CONNECTION_OP:
 561  565  
 562      -        Opcode = AML_INT_ACCESSFIELD_OP;
      566 +        Opcode = AML_INT_CONNECTION_OP;
 563  567          ParserState->Aml++;
 564  568          break;
      569 +
      570 +    case AML_FIELD_EXT_ACCESS_OP:
      571 +
      572 +        Opcode = AML_INT_EXTACCESSFIELD_OP;
      573 +        ParserState->Aml++;
      574 +        break;
      575 +
      576 +    default:
      577 +
      578 +        Opcode = AML_INT_NAMEDFIELD_OP;
      579 +        break;
 565  580      }
 566  581  
 567  582      /* Allocate a new field op */
 568  583  
 569  584      Field = AcpiPsAllocOp (Opcode);
 570  585      if (!Field)
 571  586      {
 572  587          return_PTR (NULL);
 573  588      }
 574  589  
↓ open down ↓ 19 lines elided ↑ open up ↑
 594  609  
 595  610      case AML_INT_RESERVEDFIELD_OP:
 596  611  
 597  612          /* Get the length which is encoded as a package length */
 598  613  
 599  614          Field->Common.Value.Size = AcpiPsGetNextPackageLength (ParserState);
 600  615          break;
 601  616  
 602  617  
 603  618      case AML_INT_ACCESSFIELD_OP:
      619 +    case AML_INT_EXTACCESSFIELD_OP:
 604  620  
 605  621          /*
 606  622           * Get AccessType and AccessAttrib and merge into the field Op
 607      -         * AccessType is first operand, AccessAttribute is second
      623 +         * AccessType is first operand, AccessAttribute is second. stuff
      624 +         * these bytes into the node integer value for convenience.
 608  625           */
 609      -        Field->Common.Value.Integer = (((UINT32) ACPI_GET8 (ParserState->Aml) << 8));
      626 +
      627 +        /* Get the two bytes (Type/Attribute) */
      628 +
      629 +        AccessType = ACPI_GET8 (ParserState->Aml);
 610  630          ParserState->Aml++;
 611      -        Field->Common.Value.Integer |= ACPI_GET8 (ParserState->Aml);
      631 +        AccessAttribute = ACPI_GET8 (ParserState->Aml);
 612  632          ParserState->Aml++;
      633 +
      634 +        Field->Common.Value.Integer = (UINT8) AccessType;
      635 +        Field->Common.Value.Integer |= (UINT16) (AccessAttribute << 8);
      636 +
      637 +        /* This opcode has a third byte, AccessLength */
      638 +
      639 +        if (Opcode == AML_INT_EXTACCESSFIELD_OP)
      640 +        {
      641 +            AccessLength = ACPI_GET8 (ParserState->Aml);
      642 +            ParserState->Aml++;
      643 +
      644 +            Field->Common.Value.Integer |= (UINT32) (AccessLength << 16);
      645 +        }
 613  646          break;
 614  647  
      648 +
      649 +    case AML_INT_CONNECTION_OP:
      650 +
      651 +        /*
      652 +         * Argument for Connection operator can be either a Buffer
      653 +         * (resource descriptor), or a NameString.
      654 +         */
      655 +        if (ACPI_GET8 (ParserState->Aml) == AML_BUFFER_OP)
      656 +        {
      657 +            ParserState->Aml++;
      658 +
      659 +            PkgEnd = ParserState->Aml;
      660 +            PkgLength = AcpiPsGetNextPackageLength (ParserState);
      661 +            PkgEnd += PkgLength;
      662 +
      663 +            if (ParserState->Aml < PkgEnd)
      664 +            {
      665 +                /* Non-empty list */
      666 +
      667 +                Arg = AcpiPsAllocOp (AML_INT_BYTELIST_OP);
      668 +                if (!Arg)
      669 +                {
      670 +                    AcpiPsFreeOp (Field);
      671 +                    return_PTR (NULL);
      672 +                }
      673 +
      674 +                /* Get the actual buffer length argument */
      675 +
      676 +                Opcode = ACPI_GET8 (ParserState->Aml);
      677 +                ParserState->Aml++;
      678 +
      679 +                switch (Opcode)
      680 +                {
      681 +                case AML_BYTE_OP:       /* AML_BYTEDATA_ARG */
      682 +
      683 +                    BufferLength = ACPI_GET8 (ParserState->Aml);
      684 +                    ParserState->Aml += 1;
      685 +                    break;
      686 +
      687 +                case AML_WORD_OP:       /* AML_WORDDATA_ARG */
      688 +
      689 +                    BufferLength = ACPI_GET16 (ParserState->Aml);
      690 +                    ParserState->Aml += 2;
      691 +                    break;
      692 +
      693 +                case AML_DWORD_OP:      /* AML_DWORDATA_ARG */
      694 +
      695 +                    BufferLength = ACPI_GET32 (ParserState->Aml);
      696 +                    ParserState->Aml += 4;
      697 +                    break;
      698 +
      699 +                default:
      700 +
      701 +                    BufferLength = 0;
      702 +                    break;
      703 +                }
      704 +
      705 +                /* Fill in bytelist data */
      706 +
      707 +                Arg->Named.Value.Size = BufferLength;
      708 +                Arg->Named.Data = ParserState->Aml;
      709 +            }
      710 +
      711 +            /* Skip to End of byte data */
      712 +
      713 +            ParserState->Aml = PkgEnd;
      714 +        }
      715 +        else
      716 +        {
      717 +            Arg = AcpiPsAllocOp (AML_INT_NAMEPATH_OP);
      718 +            if (!Arg)
      719 +            {
      720 +                AcpiPsFreeOp (Field);
      721 +                return_PTR (NULL);
      722 +            }
      723 +
      724 +            /* Get the Namestring argument */
      725 +
      726 +            Arg->Common.Value.Name = AcpiPsGetNextNamestring (ParserState);
      727 +        }
      728 +
      729 +        /* Link the buffer/namestring to parent (CONNECTION_OP) */
      730 +
      731 +        AcpiPsAppendArg (Field, Arg);
      732 +        break;
      733 +
      734 +
 615  735      default:
 616  736  
 617  737          /* Opcode was set in previous switch */
 618  738          break;
 619  739      }
 620  740  
 621  741      return_PTR (Field);
 622  742  }
 623  743  
 624  744  
↓ open down ↓ 42 lines elided ↑ open up ↑
 667  787          /* Constants, strings, and namestrings are all the same size */
 668  788  
 669  789          Arg = AcpiPsAllocOp (AML_BYTE_OP);
 670  790          if (!Arg)
 671  791          {
 672  792              return_ACPI_STATUS (AE_NO_MEMORY);
 673  793          }
 674  794          AcpiPsGetNextSimpleArg (ParserState, ArgType, Arg);
 675  795          break;
 676  796  
 677      -
 678  797      case ARGP_PKGLENGTH:
 679  798  
 680  799          /* Package length, nothing returned */
 681  800  
 682  801          ParserState->PkgEnd = AcpiPsGetNextPackageEnd (ParserState);
 683  802          break;
 684  803  
 685      -
 686  804      case ARGP_FIELDLIST:
 687  805  
 688  806          if (ParserState->Aml < ParserState->PkgEnd)
 689  807          {
 690  808              /* Non-empty list */
 691  809  
 692  810              while (ParserState->Aml < ParserState->PkgEnd)
 693  811              {
 694  812                  Field = AcpiPsGetNextField (ParserState);
 695  813                  if (!Field)
↓ open down ↓ 11 lines elided ↑ open up ↑
 707  825                  }
 708  826                  Prev = Field;
 709  827              }
 710  828  
 711  829              /* Skip to End of byte data */
 712  830  
 713  831              ParserState->Aml = ParserState->PkgEnd;
 714  832          }
 715  833          break;
 716  834  
 717      -
 718  835      case ARGP_BYTELIST:
 719  836  
 720  837          if (ParserState->Aml < ParserState->PkgEnd)
 721  838          {
 722  839              /* Non-empty list */
 723  840  
 724  841              Arg = AcpiPsAllocOp (AML_INT_BYTELIST_OP);
 725  842              if (!Arg)
 726  843              {
 727  844                  return_ACPI_STATUS (AE_NO_MEMORY);
↓ open down ↓ 4 lines elided ↑ open up ↑
 732  849              Arg->Common.Value.Size = (UINT32)
 733  850                  ACPI_PTR_DIFF (ParserState->PkgEnd, ParserState->Aml);
 734  851              Arg->Named.Data = ParserState->Aml;
 735  852  
 736  853              /* Skip to End of byte data */
 737  854  
 738  855              ParserState->Aml = ParserState->PkgEnd;
 739  856          }
 740  857          break;
 741  858  
 742      -
 743  859      case ARGP_TARGET:
 744  860      case ARGP_SUPERNAME:
 745  861      case ARGP_SIMPLENAME:
 746  862  
 747  863          Subop = AcpiPsPeekOpcode (ParserState);
 748  864          if (Subop == 0                  ||
 749  865              AcpiPsIsLeadingChar (Subop) ||
 750      -            AcpiPsIsPrefixChar (Subop))
      866 +            ACPI_IS_ROOT_PREFIX (Subop) ||
      867 +            ACPI_IS_PARENT_PREFIX (Subop))
 751  868          {
 752  869              /* NullName or NameString */
 753  870  
 754  871              Arg = AcpiPsAllocOp (AML_INT_NAMEPATH_OP);
 755  872              if (!Arg)
 756  873              {
 757  874                  return_ACPI_STATUS (AE_NO_MEMORY);
 758  875              }
 759  876  
 760  877              /* To support SuperName arg of Unload */
↓ open down ↓ 18 lines elided ↑ open up ↑
 779  896              }
 780  897          }
 781  898          else
 782  899          {
 783  900              /* Single complex argument, nothing returned */
 784  901  
 785  902              WalkState->ArgCount = 1;
 786  903          }
 787  904          break;
 788  905  
 789      -
 790  906      case ARGP_DATAOBJ:
 791  907      case ARGP_TERMARG:
 792  908  
 793  909          /* Single complex argument, nothing returned */
 794  910  
 795  911          WalkState->ArgCount = 1;
 796  912          break;
 797  913  
 798      -
 799  914      case ARGP_DATAOBJLIST:
 800  915      case ARGP_TERMLIST:
 801  916      case ARGP_OBJLIST:
 802  917  
 803  918          if (ParserState->Aml < ParserState->PkgEnd)
 804  919          {
 805  920              /* Non-empty list of variable arguments, nothing returned */
 806  921  
 807  922              WalkState->ArgCount = ACPI_VAR_ARGS;
 808  923          }
 809  924          break;
 810  925  
 811      -
 812  926      default:
 813  927  
 814  928          ACPI_ERROR ((AE_INFO, "Invalid ArgType: 0x%X", ArgType));
 815  929          Status = AE_AML_OPERAND_TYPE;
 816  930          break;
 817  931      }
 818  932  
 819  933      *ReturnArg = Arg;
 820  934      return_ACPI_STATUS (Status);
 821  935  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX