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

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/intel/io/acpica/resources/rscreate.c
          +++ new/usr/src/common/acpica/components/resources/rscreate.c
   1    1  /*******************************************************************************
   2    2   *
   3    3   * Module Name: rscreate - Create resource lists/tables
   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 ↓ 28 lines elided ↑ open up ↑
  47   47  #include "accommon.h"
  48   48  #include "acresrc.h"
  49   49  #include "acnamesp.h"
  50   50  
  51   51  #define _COMPONENT          ACPI_RESOURCES
  52   52          ACPI_MODULE_NAME    ("rscreate")
  53   53  
  54   54  
  55   55  /*******************************************************************************
  56   56   *
       57 + * FUNCTION:    AcpiBufferToResource
       58 + *
       59 + * PARAMETERS:  AmlBuffer           - Pointer to the resource byte stream
       60 + *              AmlBufferLength     - Length of the AmlBuffer
       61 + *              ResourcePtr         - Where the converted resource is returned
       62 + *
       63 + * RETURN:      Status
       64 + *
       65 + * DESCRIPTION: Convert a raw AML buffer to a resource list
       66 + *
       67 + ******************************************************************************/
       68 +
       69 +ACPI_STATUS
       70 +AcpiBufferToResource (
       71 +    UINT8                   *AmlBuffer,
       72 +    UINT16                  AmlBufferLength,
       73 +    ACPI_RESOURCE           **ResourcePtr)
       74 +{
       75 +    ACPI_STATUS             Status;
       76 +    ACPI_SIZE               ListSizeNeeded;
       77 +    void                    *Resource;
       78 +    void                    *CurrentResourcePtr;
       79 +
       80 +    /*
       81 +     * Note: we allow AE_AML_NO_RESOURCE_END_TAG, since an end tag
       82 +     * is not required here.
       83 +     */
       84 +
       85 +    /* Get the required length for the converted resource */
       86 +
       87 +    Status = AcpiRsGetListLength (AmlBuffer, AmlBufferLength,
       88 +                &ListSizeNeeded);
       89 +    if (Status == AE_AML_NO_RESOURCE_END_TAG)
       90 +    {
       91 +        Status = AE_OK;
       92 +    }
       93 +    if (ACPI_FAILURE (Status))
       94 +    {
       95 +        return (Status);
       96 +    }
       97 +
       98 +    /* Allocate a buffer for the converted resource */
       99 +
      100 +    Resource = ACPI_ALLOCATE_ZEROED (ListSizeNeeded);
      101 +    CurrentResourcePtr = Resource;
      102 +    if (!Resource)
      103 +    {
      104 +        return (AE_NO_MEMORY);
      105 +    }
      106 +
      107 +    /* Perform the AML-to-Resource conversion */
      108 +
      109 +    Status = AcpiUtWalkAmlResources (NULL, AmlBuffer, AmlBufferLength,
      110 +                AcpiRsConvertAmlToResources, &CurrentResourcePtr);
      111 +    if (Status == AE_AML_NO_RESOURCE_END_TAG)
      112 +    {
      113 +        Status = AE_OK;
      114 +    }
      115 +    if (ACPI_FAILURE (Status))
      116 +    {
      117 +        ACPI_FREE (Resource);
      118 +    }
      119 +    else
      120 +    {
      121 +        *ResourcePtr = Resource;
      122 +    }
      123 +
      124 +    return (Status);
      125 +}
      126 +
      127 +
      128 +/*******************************************************************************
      129 + *
  57  130   * FUNCTION:    AcpiRsCreateResourceList
  58  131   *
  59  132   * PARAMETERS:  AmlBuffer           - Pointer to the resource byte stream
  60  133   *              OutputBuffer        - Pointer to the user's buffer
  61  134   *
  62  135   * RETURN:      Status: AE_OK if okay, else a valid ACPI_STATUS code
  63  136   *              If OutputBuffer is not large enough, OutputBufferLength
  64  137   *              indicates how large OutputBuffer should be, else it
  65  138   *              indicates how may UINT8 elements of OutputBuffer are valid.
  66  139   *
↓ open down ↓ 45 lines elided ↑ open up ↑
 112  185  
 113  186      Status = AcpiUtInitializeBuffer (OutputBuffer, ListSizeNeeded);
 114  187      if (ACPI_FAILURE (Status))
 115  188      {
 116  189          return_ACPI_STATUS (Status);
 117  190      }
 118  191  
 119  192      /* Do the conversion */
 120  193  
 121  194      Resource = OutputBuffer->Pointer;
 122      -    Status = AcpiUtWalkAmlResources (AmlStart, AmlBufferLength,
      195 +    Status = AcpiUtWalkAmlResources (NULL, AmlStart, AmlBufferLength,
 123  196                  AcpiRsConvertAmlToResources, &Resource);
 124  197      if (ACPI_FAILURE (Status))
 125  198      {
 126  199          return_ACPI_STATUS (Status);
 127  200      }
 128  201  
 129  202      ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "OutputBuffer %p Length %X\n",
 130  203              OutputBuffer->Pointer, (UINT32) OutputBuffer->Length));
 131  204      return_ACPI_STATUS (AE_OK);
 132  205  }
 133  206  
 134  207  
 135  208  /*******************************************************************************
 136  209   *
 137  210   * FUNCTION:    AcpiRsCreatePciRoutingTable
 138  211   *
 139      - * PARAMETERS:  PackageObject           - Pointer to an ACPI_OPERAND_OBJECT
 140      - *                                        package
      212 + * PARAMETERS:  PackageObject           - Pointer to a package containing one
      213 + *                                        of more ACPI_OPERAND_OBJECTs
 141  214   *              OutputBuffer            - Pointer to the user's buffer
 142  215   *
 143  216   * RETURN:      Status  AE_OK if okay, else a valid ACPI_STATUS code.
 144  217   *              If the OutputBuffer is too small, the error will be
 145  218   *              AE_BUFFER_OVERFLOW and OutputBuffer->Length will point
 146  219   *              to the size buffer needed.
 147  220   *
 148      - * DESCRIPTION: Takes the ACPI_OPERAND_OBJECT  package and creates a
      221 + * DESCRIPTION: Takes the ACPI_OPERAND_OBJECT package and creates a
 149  222   *              linked list of PCI interrupt descriptions
 150  223   *
 151  224   * NOTE: It is the caller's responsibility to ensure that the start of the
 152  225   * output buffer is aligned properly (if necessary).
 153  226   *
 154  227   ******************************************************************************/
 155  228  
 156  229  ACPI_STATUS
 157  230  AcpiRsCreatePciRoutingTable (
 158  231      ACPI_OPERAND_OBJECT     *PackageObject,
↓ open down ↓ 58 lines elided ↑ open up ↑
 217  290          Buffer += UserPrt->Length;
 218  291          UserPrt = ACPI_CAST_PTR (ACPI_PCI_ROUTING_TABLE, Buffer);
 219  292  
 220  293          /*
 221  294           * Fill in the Length field with the information we have at this point.
 222  295           * The minus four is to subtract the size of the UINT8 Source[4] member
 223  296           * because it is added below.
 224  297           */
 225  298          UserPrt->Length = (sizeof (ACPI_PCI_ROUTING_TABLE) - 4);
 226  299  
 227      -        /* Each element of the top-level package must also be a package */
 228      -
 229      -        if ((*TopObjectList)->Common.Type != ACPI_TYPE_PACKAGE)
 230      -        {
 231      -            ACPI_ERROR ((AE_INFO,
 232      -                "(PRT[%u]) Need sub-package, found %s",
 233      -                Index, AcpiUtGetObjectTypeName (*TopObjectList)));
 234      -            return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
 235      -        }
 236      -
 237  300          /* Each sub-package must be of length 4 */
 238  301  
 239  302          if ((*TopObjectList)->Package.Count != 4)
 240  303          {
 241  304              ACPI_ERROR ((AE_INFO,
 242  305                  "(PRT[%u]) Need package of length 4, found length %u",
 243  306                  Index, (*TopObjectList)->Package.Count));
 244  307              return_ACPI_STATUS (AE_AML_PACKAGE_LIMIT);
 245  308          }
 246  309  
↓ open down ↓ 22 lines elided ↑ open up ↑
 269  332          if (ObjDesc->Common.Type != ACPI_TYPE_INTEGER)
 270  333          {
 271  334              ACPI_ERROR ((AE_INFO, "(PRT[%u].Pin) Need Integer, found %s",
 272  335                  Index, AcpiUtGetObjectTypeName (ObjDesc)));
 273  336              return_ACPI_STATUS (AE_BAD_DATA);
 274  337          }
 275  338  
 276  339          UserPrt->Pin = (UINT32) ObjDesc->Integer.Value;
 277  340  
 278  341          /*
 279      -         * If the BIOS has erroneously reversed the _PRT SourceName (index 2)
 280      -         * and the SourceIndex (index 3), fix it. _PRT is important enough to
 281      -         * workaround this BIOS error. This also provides compatibility with
 282      -         * other ACPI implementations.
 283      -         */
 284      -        ObjDesc = SubObjectList[3];
 285      -        if (!ObjDesc || (ObjDesc->Common.Type != ACPI_TYPE_INTEGER))
 286      -        {
 287      -            SubObjectList[3] = SubObjectList[2];
 288      -            SubObjectList[2] = ObjDesc;
 289      -
 290      -            ACPI_WARNING ((AE_INFO,
 291      -                "(PRT[%X].Source) SourceName and SourceIndex are reversed, fixed",
 292      -                Index));
 293      -        }
 294      -
 295      -        /*
 296  342           * 3) Third subobject: Dereference the PRT.SourceName
 297  343           * The name may be unresolved (slack mode), so allow a null object
 298  344           */
 299  345          ObjDesc = SubObjectList[2];
 300  346          if (ObjDesc)
 301  347          {
 302  348              switch (ObjDesc->Common.Type)
 303  349              {
 304  350              case ACPI_TYPE_LOCAL_REFERENCE:
 305  351  
↓ open down ↓ 14 lines elided ↑ open up ↑
 320  366                                      (UINT8 *) OutputBuffer->Pointer);
 321  367                  PathBuffer.Pointer = UserPrt->Source;
 322  368  
 323  369                  Status = AcpiNsHandleToPathname ((ACPI_HANDLE) Node, &PathBuffer);
 324  370  
 325  371                  /* +1 to include null terminator */
 326  372  
 327  373                  UserPrt->Length += (UINT32) ACPI_STRLEN (UserPrt->Source) + 1;
 328  374                  break;
 329  375  
 330      -
 331  376              case ACPI_TYPE_STRING:
 332  377  
 333  378                  ACPI_STRCPY (UserPrt->Source, ObjDesc->String.Pointer);
 334  379  
 335  380                  /*
 336  381                   * Add to the Length field the length of the string
 337  382                   * (add 1 for terminator)
 338  383                   */
 339  384                  UserPrt->Length += ObjDesc->String.Length + 1;
 340  385                  break;
 341  386  
 342      -
 343  387              case ACPI_TYPE_INTEGER:
 344  388                  /*
 345  389                   * If this is a number, then the Source Name is NULL, since the
 346  390                   * entire buffer was zeroed out, we can leave this alone.
 347  391                   *
 348  392                   * Add to the Length field the length of the UINT32 NULL
 349  393                   */
 350  394                  UserPrt->Length += sizeof (UINT32);
 351  395                  break;
 352  396  
 353      -
 354  397              default:
 355  398  
 356  399                 ACPI_ERROR ((AE_INFO,
 357  400                     "(PRT[%u].Source) Need Ref/String/Integer, found %s",
 358  401                     Index, AcpiUtGetObjectTypeName (ObjDesc)));
 359  402                 return_ACPI_STATUS (AE_BAD_DATA);
 360  403              }
 361  404          }
 362  405  
 363  406          /* Now align the current length */
↓ open down ↓ 21 lines elided ↑ open up ↑
 385  428      ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "OutputBuffer %p Length %X\n",
 386  429              OutputBuffer->Pointer, (UINT32) OutputBuffer->Length));
 387  430      return_ACPI_STATUS (AE_OK);
 388  431  }
 389  432  
 390  433  
 391  434  /*******************************************************************************
 392  435   *
 393  436   * FUNCTION:    AcpiRsCreateAmlResources
 394  437   *
 395      - * PARAMETERS:  LinkedListBuffer        - Pointer to the resource linked list
 396      - *              OutputBuffer            - Pointer to the user's buffer
      438 + * PARAMETERS:  ResourceList            - Pointer to the resource list buffer
      439 + *              OutputBuffer            - Where the AML buffer is returned
 397  440   *
 398  441   * RETURN:      Status  AE_OK if okay, else a valid ACPI_STATUS code.
 399  442   *              If the OutputBuffer is too small, the error will be
 400  443   *              AE_BUFFER_OVERFLOW and OutputBuffer->Length will point
 401  444   *              to the size buffer needed.
 402  445   *
 403      - * DESCRIPTION: Takes the linked list of device resources and
 404      - *              creates a bytestream to be used as input for the
 405      - *              _SRS control method.
      446 + * DESCRIPTION: Converts a list of device resources to an AML bytestream
      447 + *              to be used as input for the _SRS control method.
 406  448   *
 407  449   ******************************************************************************/
 408  450  
 409  451  ACPI_STATUS
 410  452  AcpiRsCreateAmlResources (
 411      -    ACPI_RESOURCE           *LinkedListBuffer,
      453 +    ACPI_BUFFER             *ResourceList,
 412  454      ACPI_BUFFER             *OutputBuffer)
 413  455  {
 414  456      ACPI_STATUS             Status;
 415  457      ACPI_SIZE               AmlSizeNeeded = 0;
 416  458  
 417  459  
 418  460      ACPI_FUNCTION_TRACE (RsCreateAmlResources);
 419  461  
 420  462  
 421      -    ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "LinkedListBuffer = %p\n",
 422      -        LinkedListBuffer));
      463 +    /* Params already validated, no need to re-validate here */
 423  464  
 424      -    /*
 425      -     * Params already validated, so we don't re-validate here
 426      -     *
 427      -     * Pass the LinkedListBuffer into a module that calculates
 428      -     * the buffer size needed for the byte stream.
 429      -     */
 430      -    Status = AcpiRsGetAmlLength (LinkedListBuffer,
 431      -                &AmlSizeNeeded);
      465 +    ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "ResourceList Buffer = %p\n",
      466 +        ResourceList->Pointer));
 432  467  
      468 +    /* Get the buffer size needed for the AML byte stream */
      469 +
      470 +    Status = AcpiRsGetAmlLength (ResourceList->Pointer,
      471 +                ResourceList->Length, &AmlSizeNeeded);
      472 +
 433  473      ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "AmlSizeNeeded=%X, %s\n",
 434  474          (UINT32) AmlSizeNeeded, AcpiFormatException (Status)));
 435  475      if (ACPI_FAILURE (Status))
 436  476      {
 437  477          return_ACPI_STATUS (Status);
 438  478      }
 439  479  
 440  480      /* Validate/Allocate/Clear caller buffer */
 441  481  
 442  482      Status = AcpiUtInitializeBuffer (OutputBuffer, AmlSizeNeeded);
 443  483      if (ACPI_FAILURE (Status))
 444  484      {
 445  485          return_ACPI_STATUS (Status);
 446  486      }
 447  487  
 448  488      /* Do the conversion */
 449  489  
 450      -    Status = AcpiRsConvertResourcesToAml (LinkedListBuffer, AmlSizeNeeded,
 451      -                    OutputBuffer->Pointer);
      490 +    Status = AcpiRsConvertResourcesToAml (ResourceList->Pointer,
      491 +                AmlSizeNeeded, OutputBuffer->Pointer);
 452  492      if (ACPI_FAILURE (Status))
 453  493      {
 454  494          return_ACPI_STATUS (Status);
 455  495      }
 456  496  
 457  497      ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "OutputBuffer %p Length %X\n",
 458      -            OutputBuffer->Pointer, (UINT32) OutputBuffer->Length));
      498 +        OutputBuffer->Pointer, (UINT32) OutputBuffer->Length));
 459  499      return_ACPI_STATUS (AE_OK);
 460  500  }
 461      -
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX