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/rscalc.c
          +++ new/usr/src/common/acpica/components/resources/rscalc.c
   1    1  /*******************************************************************************
   2    2   *
   3    3   * Module Name: rscalc - Calculate stream and list lengths
   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 ↓ 171 lines elided ↑ open up ↑
 190  190       */
 191  191      return ((UINT32) ACPI_ROUND_UP_TO_NATIVE_WORD (StringLength));
 192  192  }
 193  193  
 194  194  
 195  195  /*******************************************************************************
 196  196   *
 197  197   * FUNCTION:    AcpiRsGetAmlLength
 198  198   *
 199  199   * PARAMETERS:  Resource            - Pointer to the resource linked list
      200 + *              ResourceListSize    - Size of the resource linked list
 200  201   *              SizeNeeded          - Where the required size is returned
 201  202   *
 202  203   * RETURN:      Status
 203  204   *
 204  205   * DESCRIPTION: Takes a linked list of internal resource descriptors and
 205  206   *              calculates the size buffer needed to hold the corresponding
 206  207   *              external resource byte stream.
 207  208   *
 208  209   ******************************************************************************/
 209  210  
 210  211  ACPI_STATUS
 211  212  AcpiRsGetAmlLength (
 212  213      ACPI_RESOURCE           *Resource,
      214 +    ACPI_SIZE               ResourceListSize,
 213  215      ACPI_SIZE               *SizeNeeded)
 214  216  {
 215  217      ACPI_SIZE               AmlSizeNeeded = 0;
      218 +    ACPI_RESOURCE           *ResourceEnd;
 216  219      ACPI_RS_LENGTH          TotalSize;
 217  220  
 218  221  
 219  222      ACPI_FUNCTION_TRACE (RsGetAmlLength);
 220  223  
 221  224  
 222  225      /* Traverse entire list of internal resource descriptors */
 223  226  
 224      -    while (Resource)
      227 +    ResourceEnd = ACPI_ADD_PTR (ACPI_RESOURCE, Resource, ResourceListSize);
      228 +    while (Resource < ResourceEnd)
 225  229      {
 226  230          /* Validate the descriptor type */
 227  231  
 228  232          if (Resource->Type > ACPI_RESOURCE_TYPE_MAX)
 229  233          {
 230  234              return_ACPI_STATUS (AE_AML_INVALID_RESOURCE_TYPE);
 231  235          }
 232  236  
      237 +        /* Sanity check the length. It must not be zero, or we loop forever */
      238 +
      239 +        if (!Resource->Length)
      240 +        {
      241 +            return_ACPI_STATUS (AE_AML_BAD_RESOURCE_LENGTH);
      242 +        }
      243 +
 233  244          /* Get the base size of the (external stream) resource descriptor */
 234  245  
 235  246          TotalSize = AcpiGbl_AmlResourceSizes [Resource->Type];
 236  247  
 237  248          /*
 238  249           * Augment the base size for descriptors with optional and/or
 239  250           * variable-length fields
 240  251           */
 241  252          switch (Resource->Type)
 242  253          {
↓ open down ↓ 95 lines elided ↑ open up ↑
 338  349                  (TotalSize +
 339  350                  ((Resource->Data.ExtendedIrq.InterruptCount - 1) * 4) +
 340  351  
 341  352                  /* Add the size of the optional ResourceSource info */
 342  353  
 343  354                  AcpiRsStructOptionLength (
 344  355                      &Resource->Data.ExtendedIrq.ResourceSource));
 345  356              break;
 346  357  
 347  358  
      359 +        case ACPI_RESOURCE_TYPE_GPIO:
      360 +
      361 +            TotalSize = (ACPI_RS_LENGTH) (TotalSize + (Resource->Data.Gpio.PinTableLength * 2) +
      362 +                Resource->Data.Gpio.ResourceSource.StringLength +
      363 +                Resource->Data.Gpio.VendorLength);
      364 +
      365 +            break;
      366 +
      367 +
      368 +        case ACPI_RESOURCE_TYPE_SERIAL_BUS:
      369 +
      370 +            TotalSize = AcpiGbl_AmlResourceSerialBusSizes [Resource->Data.CommonSerialBus.Type];
      371 +
      372 +            TotalSize = (ACPI_RS_LENGTH) (TotalSize +
      373 +                Resource->Data.I2cSerialBus.ResourceSource.StringLength +
      374 +                Resource->Data.I2cSerialBus.VendorLength);
      375 +
      376 +            break;
      377 +
 348  378          default:
      379 +
 349  380              break;
 350  381          }
 351  382  
 352  383          /* Update the total */
 353  384  
 354  385          AmlSizeNeeded += TotalSize;
 355  386  
 356  387          /* Point to the next object */
 357  388  
 358  389          Resource = ACPI_ADD_PTR (ACPI_RESOURCE, Resource, Resource->Length);
↓ open down ↓ 29 lines elided ↑ open up ↑
 388  419  {
 389  420      ACPI_STATUS             Status;
 390  421      UINT8                   *EndAml;
 391  422      UINT8                   *Buffer;
 392  423      UINT32                  BufferSize;
 393  424      UINT16                  Temp16;
 394  425      UINT16                  ResourceLength;
 395  426      UINT32                  ExtraStructBytes;
 396  427      UINT8                   ResourceIndex;
 397  428      UINT8                   MinimumAmlResourceLength;
      429 +    AML_RESOURCE            *AmlResource;
 398  430  
 399  431  
 400  432      ACPI_FUNCTION_TRACE (RsGetListLength);
 401  433  
 402  434  
 403      -    *SizeNeeded = 0;
      435 +    *SizeNeeded = ACPI_RS_SIZE_MIN;         /* Minimum size is one EndTag */
 404  436      EndAml = AmlBuffer + AmlBufferLength;
 405  437  
 406  438      /* Walk the list of AML resource descriptors */
 407  439  
 408  440      while (AmlBuffer < EndAml)
 409  441      {
 410  442          /* Validate the Resource Type and Resource Length */
 411  443  
 412      -        Status = AcpiUtValidateResource (AmlBuffer, &ResourceIndex);
      444 +        Status = AcpiUtValidateResource (NULL, AmlBuffer, &ResourceIndex);
 413  445          if (ACPI_FAILURE (Status))
 414  446          {
      447 +            /*
      448 +             * Exit on failure. Cannot continue because the descriptor length
      449 +             * may be bogus also.
      450 +             */
 415  451              return_ACPI_STATUS (Status);
 416  452          }
 417  453  
      454 +        AmlResource = (void *) AmlBuffer;
      455 +
 418  456          /* Get the resource length and base (minimum) AML size */
 419  457  
 420  458          ResourceLength = AcpiUtGetResourceLength (AmlBuffer);
 421  459          MinimumAmlResourceLength = AcpiGbl_ResourceAmlSizes[ResourceIndex];
 422  460  
 423  461          /*
 424  462           * Augment the size for descriptors with optional
 425  463           * and/or variable length fields
 426  464           */
 427  465          ExtraStructBytes = 0;
↓ open down ↓ 20 lines elided ↑ open up ↑
 448  486              break;
 449  487  
 450  488  
 451  489          case ACPI_RESOURCE_NAME_VENDOR_SMALL:
 452  490          case ACPI_RESOURCE_NAME_VENDOR_LARGE:
 453  491              /*
 454  492               * Vendor Resource:
 455  493               * Get the number of vendor data bytes
 456  494               */
 457  495              ExtraStructBytes = ResourceLength;
      496 +
      497 +            /*
      498 +             * There is already one byte included in the minimum
      499 +             * descriptor size. If there are extra struct bytes,
      500 +             * subtract one from the count.
      501 +             */
      502 +            if (ExtraStructBytes)
      503 +            {
      504 +                ExtraStructBytes--;
      505 +            }
 458  506              break;
 459  507  
 460  508  
 461  509          case ACPI_RESOURCE_NAME_END_TAG:
 462  510              /*
 463      -             * End Tag:
 464      -             * This is the normal exit, add size of EndTag
      511 +             * End Tag: This is the normal exit
 465  512               */
 466      -            *SizeNeeded += ACPI_RS_SIZE_MIN;
 467  513              return_ACPI_STATUS (AE_OK);
 468  514  
 469  515  
 470  516          case ACPI_RESOURCE_NAME_ADDRESS32:
 471  517          case ACPI_RESOURCE_NAME_ADDRESS16:
 472  518          case ACPI_RESOURCE_NAME_ADDRESS64:
 473  519              /*
 474  520               * Address Resource:
 475  521               * Add the size of the optional ResourceSource
 476  522               */
↓ open down ↓ 10 lines elided ↑ open up ↑
 487  533               * included in the minimum descriptor size (reason for the -1)
 488  534               */
 489  535              ExtraStructBytes = (Buffer[1] - 1) * sizeof (UINT32);
 490  536  
 491  537              /* Add the size of the optional ResourceSource */
 492  538  
 493  539              ExtraStructBytes += AcpiRsStreamOptionLength (
 494  540                  ResourceLength - ExtraStructBytes, MinimumAmlResourceLength);
 495  541              break;
 496  542  
      543 +        case ACPI_RESOURCE_NAME_GPIO:
 497  544  
      545 +            /* Vendor data is optional */
      546 +
      547 +            if (AmlResource->Gpio.VendorLength)
      548 +            {
      549 +                ExtraStructBytes += AmlResource->Gpio.VendorOffset -
      550 +                    AmlResource->Gpio.PinTableOffset + AmlResource->Gpio.VendorLength;
      551 +            }
      552 +            else
      553 +            {
      554 +                ExtraStructBytes += AmlResource->LargeHeader.ResourceLength +
      555 +                    sizeof (AML_RESOURCE_LARGE_HEADER) -
      556 +                    AmlResource->Gpio.PinTableOffset;
      557 +            }
      558 +            break;
      559 +
      560 +        case ACPI_RESOURCE_NAME_SERIAL_BUS:
      561 +
      562 +            MinimumAmlResourceLength = AcpiGbl_ResourceAmlSerialBusSizes[
      563 +                AmlResource->CommonSerialBus.Type];
      564 +            ExtraStructBytes += AmlResource->CommonSerialBus.ResourceLength -
      565 +                MinimumAmlResourceLength;
      566 +            break;
      567 +
 498  568          default:
      569 +
 499  570              break;
 500  571          }
 501  572  
 502  573          /*
 503  574           * Update the required buffer size for the internal descriptor structs
 504  575           *
 505  576           * Important: Round the size up for the appropriate alignment. This
 506  577           * is a requirement on IA64.
 507  578           */
 508      -        BufferSize = AcpiGbl_ResourceStructSizes[ResourceIndex] +
      579 +        if (AcpiUtGetResourceType (AmlBuffer) == ACPI_RESOURCE_NAME_SERIAL_BUS)
      580 +        {
      581 +            BufferSize = AcpiGbl_ResourceStructSerialBusSizes[
      582 +                AmlResource->CommonSerialBus.Type] + ExtraStructBytes;
      583 +        }
      584 +        else
      585 +        {
      586 +            BufferSize = AcpiGbl_ResourceStructSizes[ResourceIndex] +
 509  587                          ExtraStructBytes;
      588 +        }
 510  589          BufferSize = (UINT32) ACPI_ROUND_UP_TO_NATIVE_WORD (BufferSize);
 511  590  
 512  591          *SizeNeeded += BufferSize;
 513  592  
 514  593          ACPI_DEBUG_PRINT ((ACPI_DB_RESOURCES,
 515  594              "Type %.2X, AmlLength %.2X InternalLength %.2X\n",
 516  595              AcpiUtGetResourceType (AmlBuffer),
 517  596              AcpiUtGetDescriptorLength (AmlBuffer), BufferSize));
 518  597  
 519  598          /*
↓ open down ↓ 42 lines elided ↑ open up ↑
 562  641  
 563  642  
 564  643      ACPI_FUNCTION_TRACE (RsGetPciRoutingTableLength);
 565  644  
 566  645  
 567  646      NumberOfElements = PackageObject->Package.Count;
 568  647  
 569  648      /*
 570  649       * Calculate the size of the return buffer.
 571  650       * The base size is the number of elements * the sizes of the
 572      -     * structures.  Additional space for the strings is added below.
      651 +     * structures. Additional space for the strings is added below.
 573  652       * The minus one is to subtract the size of the UINT8 Source[1]
 574  653       * member because it is added below.
 575  654       *
 576  655       * But each PRT_ENTRY structure has a pointer to a string and
 577  656       * the size of that string must be found.
 578  657       */
 579  658      TopObjectList = PackageObject->Package.Elements;
 580  659  
 581  660      for (Index = 0; Index < NumberOfElements; Index++)
 582  661      {
↓ open down ↓ 12 lines elided ↑ open up ↑
 595  674          /*
 596  675           * The SubObjectList will now point to an array of the
 597  676           * four IRQ elements: Address, Pin, Source and SourceIndex
 598  677           */
 599  678          SubObjectList = PackageElement->Package.Elements;
 600  679  
 601  680          /* Scan the IrqTableElements for the Source Name String */
 602  681  
 603  682          NameFound = FALSE;
 604  683  
 605      -        for (TableIndex = 0; TableIndex < 4 && !NameFound; TableIndex++)
      684 +        for (TableIndex = 0;
      685 +             TableIndex < PackageElement->Package.Count && !NameFound;
      686 +             TableIndex++)
 606  687          {
 607  688              if (*SubObjectList && /* Null object allowed */
 608  689  
 609  690                  ((ACPI_TYPE_STRING ==
 610  691                      (*SubObjectList)->Common.Type) ||
 611  692  
 612  693                  ((ACPI_TYPE_LOCAL_REFERENCE ==
 613  694                      (*SubObjectList)->Common.Type) &&
 614  695  
 615  696                      ((*SubObjectList)->Reference.Class ==
↓ open down ↓ 58 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX