13446Smrj /******************************************************************************* 23446Smrj * 33446Smrj * Module Name: rscalc - Calculate stream and list lengths 4*7851SDana.Myers@Sun.COM * $Revision: 1.84 $ 53446Smrj * 63446Smrj ******************************************************************************/ 73446Smrj 83446Smrj /****************************************************************************** 93446Smrj * 103446Smrj * 1. Copyright Notice 113446Smrj * 12*7851SDana.Myers@Sun.COM * Some or all of this work - Copyright (c) 1999 - 2008, Intel Corp. 133446Smrj * All rights reserved. 143446Smrj * 153446Smrj * 2. License 163446Smrj * 173446Smrj * 2.1. This is your license from Intel Corp. under its intellectual property 183446Smrj * rights. You may have additional license terms from the party that provided 193446Smrj * you this software, covering your right to use that party's intellectual 203446Smrj * property rights. 213446Smrj * 223446Smrj * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 233446Smrj * copy of the source code appearing in this file ("Covered Code") an 243446Smrj * irrevocable, perpetual, worldwide license under Intel's copyrights in the 253446Smrj * base code distributed originally by Intel ("Original Intel Code") to copy, 263446Smrj * make derivatives, distribute, use and display any portion of the Covered 273446Smrj * Code in any form, with the right to sublicense such rights; and 283446Smrj * 293446Smrj * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 303446Smrj * license (with the right to sublicense), under only those claims of Intel 313446Smrj * patents that are infringed by the Original Intel Code, to make, use, sell, 323446Smrj * offer to sell, and import the Covered Code and derivative works thereof 333446Smrj * solely to the minimum extent necessary to exercise the above copyright 343446Smrj * license, and in no event shall the patent license extend to any additions 353446Smrj * to or modifications of the Original Intel Code. No other license or right 363446Smrj * is granted directly or by implication, estoppel or otherwise; 373446Smrj * 383446Smrj * The above copyright and patent license is granted only if the following 393446Smrj * conditions are met: 403446Smrj * 413446Smrj * 3. Conditions 423446Smrj * 433446Smrj * 3.1. Redistribution of Source with Rights to Further Distribute Source. 443446Smrj * Redistribution of source code of any substantial portion of the Covered 453446Smrj * Code or modification with rights to further distribute source must include 463446Smrj * the above Copyright Notice, the above License, this list of Conditions, 473446Smrj * and the following Disclaimer and Export Compliance provision. In addition, 483446Smrj * Licensee must cause all Covered Code to which Licensee contributes to 493446Smrj * contain a file documenting the changes Licensee made to create that Covered 503446Smrj * Code and the date of any change. Licensee must include in that file the 513446Smrj * documentation of any changes made by any predecessor Licensee. Licensee 523446Smrj * must include a prominent statement that the modification is derived, 533446Smrj * directly or indirectly, from Original Intel Code. 543446Smrj * 553446Smrj * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 563446Smrj * Redistribution of source code of any substantial portion of the Covered 573446Smrj * Code or modification without rights to further distribute source must 583446Smrj * include the following Disclaimer and Export Compliance provision in the 593446Smrj * documentation and/or other materials provided with distribution. In 603446Smrj * addition, Licensee may not authorize further sublicense of source of any 613446Smrj * portion of the Covered Code, and must include terms to the effect that the 623446Smrj * license from Licensee to its licensee is limited to the intellectual 633446Smrj * property embodied in the software Licensee provides to its licensee, and 643446Smrj * not to intellectual property embodied in modifications its licensee may 653446Smrj * make. 663446Smrj * 673446Smrj * 3.3. Redistribution of Executable. Redistribution in executable form of any 683446Smrj * substantial portion of the Covered Code or modification must reproduce the 693446Smrj * above Copyright Notice, and the following Disclaimer and Export Compliance 703446Smrj * provision in the documentation and/or other materials provided with the 713446Smrj * distribution. 723446Smrj * 733446Smrj * 3.4. Intel retains all right, title, and interest in and to the Original 743446Smrj * Intel Code. 753446Smrj * 763446Smrj * 3.5. Neither the name Intel nor any other trademark owned or controlled by 773446Smrj * Intel shall be used in advertising or otherwise to promote the sale, use or 783446Smrj * other dealings in products derived from or relating to the Covered Code 793446Smrj * without prior written authorization from Intel. 803446Smrj * 813446Smrj * 4. Disclaimer and Export Compliance 823446Smrj * 833446Smrj * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 843446Smrj * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 853446Smrj * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 863446Smrj * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 873446Smrj * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 883446Smrj * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 893446Smrj * PARTICULAR PURPOSE. 903446Smrj * 913446Smrj * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 923446Smrj * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 933446Smrj * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 943446Smrj * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 953446Smrj * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 963446Smrj * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 973446Smrj * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 983446Smrj * LIMITED REMEDY. 993446Smrj * 1003446Smrj * 4.3. Licensee shall not export, either directly or indirectly, any of this 1013446Smrj * software or system incorporating such software without first obtaining any 1023446Smrj * required license or other approval from the U. S. Department of Commerce or 1033446Smrj * any other agency or department of the United States Government. In the 1043446Smrj * event Licensee exports any such software from the United States or 1053446Smrj * re-exports any such software from a foreign destination, Licensee shall 1063446Smrj * ensure that the distribution and export/re-export of the software is in 1073446Smrj * compliance with all laws, regulations, orders, or other restrictions of the 1083446Smrj * U.S. Export Administration Regulations. Licensee agrees that neither it nor 1093446Smrj * any of its subsidiaries will export/re-export any technical data, process, 1103446Smrj * software, or service, directly or indirectly, to any country for which the 1113446Smrj * United States government or any agency thereof requires an export license, 1123446Smrj * other governmental approval, or letter of assurance, without first obtaining 1133446Smrj * such license, approval or letter. 1143446Smrj * 1153446Smrj *****************************************************************************/ 1163446Smrj 1173446Smrj #define __RSCALC_C__ 1183446Smrj 1193446Smrj #include "acpi.h" 1203446Smrj #include "acresrc.h" 1213446Smrj #include "acnamesp.h" 1223446Smrj 123*7851SDana.Myers@Sun.COM 1243446Smrj #define _COMPONENT ACPI_RESOURCES 1253446Smrj ACPI_MODULE_NAME ("rscalc") 1263446Smrj 1273446Smrj 1283446Smrj /* Local prototypes */ 1293446Smrj 1303446Smrj static UINT8 1313446Smrj AcpiRsCountSetBits ( 1323446Smrj UINT16 BitField); 1333446Smrj 1343446Smrj static ACPI_RS_LENGTH 1353446Smrj AcpiRsStructOptionLength ( 1363446Smrj ACPI_RESOURCE_SOURCE *ResourceSource); 1373446Smrj 1383446Smrj static UINT32 1393446Smrj AcpiRsStreamOptionLength ( 1403446Smrj UINT32 ResourceLength, 1413446Smrj UINT32 MinimumTotalLength); 1423446Smrj 1433446Smrj 1443446Smrj /******************************************************************************* 1453446Smrj * 1463446Smrj * FUNCTION: AcpiRsCountSetBits 1473446Smrj * 1483446Smrj * PARAMETERS: BitField - Field in which to count bits 1493446Smrj * 1503446Smrj * RETURN: Number of bits set within the field 1513446Smrj * 1523446Smrj * DESCRIPTION: Count the number of bits set in a resource field. Used for 1533446Smrj * (Short descriptor) interrupt and DMA lists. 1543446Smrj * 1553446Smrj ******************************************************************************/ 1563446Smrj 1573446Smrj static UINT8 1583446Smrj AcpiRsCountSetBits ( 1593446Smrj UINT16 BitField) 1603446Smrj { 1613446Smrj UINT8 BitsSet; 1623446Smrj 1633446Smrj 1643446Smrj ACPI_FUNCTION_ENTRY (); 1653446Smrj 1663446Smrj 1673446Smrj for (BitsSet = 0; BitField; BitsSet++) 1683446Smrj { 1693446Smrj /* Zero the least significant bit that is set */ 1703446Smrj 171*7851SDana.Myers@Sun.COM BitField &= (UINT16) (BitField - 1); 1723446Smrj } 1733446Smrj 1743446Smrj return (BitsSet); 1753446Smrj } 1763446Smrj 1773446Smrj 1783446Smrj /******************************************************************************* 1793446Smrj * 1803446Smrj * FUNCTION: AcpiRsStructOptionLength 1813446Smrj * 1823446Smrj * PARAMETERS: ResourceSource - Pointer to optional descriptor field 1833446Smrj * 1843446Smrj * RETURN: Status 1853446Smrj * 1863446Smrj * DESCRIPTION: Common code to handle optional ResourceSourceIndex and 1873446Smrj * ResourceSource fields in some Large descriptors. Used during 1883446Smrj * list-to-stream conversion 1893446Smrj * 1903446Smrj ******************************************************************************/ 1913446Smrj 1923446Smrj static ACPI_RS_LENGTH 1933446Smrj AcpiRsStructOptionLength ( 1943446Smrj ACPI_RESOURCE_SOURCE *ResourceSource) 1953446Smrj { 1963446Smrj ACPI_FUNCTION_ENTRY (); 1973446Smrj 1983446Smrj 1993446Smrj /* 2003446Smrj * If the ResourceSource string is valid, return the size of the string 2013446Smrj * (StringLength includes the NULL terminator) plus the size of the 2023446Smrj * ResourceSourceIndex (1). 2033446Smrj */ 2043446Smrj if (ResourceSource->StringPtr) 2053446Smrj { 2063446Smrj return ((ACPI_RS_LENGTH) (ResourceSource->StringLength + 1)); 2073446Smrj } 2083446Smrj 2093446Smrj return (0); 2103446Smrj } 2113446Smrj 2123446Smrj 2133446Smrj /******************************************************************************* 2143446Smrj * 2153446Smrj * FUNCTION: AcpiRsStreamOptionLength 2163446Smrj * 2173446Smrj * PARAMETERS: ResourceLength - Length from the resource header 2183446Smrj * MinimumTotalLength - Minimum length of this resource, before 2193446Smrj * any optional fields. Includes header size 2203446Smrj * 2213446Smrj * RETURN: Length of optional string (0 if no string present) 2223446Smrj * 2233446Smrj * DESCRIPTION: Common code to handle optional ResourceSourceIndex and 2243446Smrj * ResourceSource fields in some Large descriptors. Used during 2253446Smrj * stream-to-list conversion 2263446Smrj * 2273446Smrj ******************************************************************************/ 2283446Smrj 2293446Smrj static UINT32 2303446Smrj AcpiRsStreamOptionLength ( 2313446Smrj UINT32 ResourceLength, 2323446Smrj UINT32 MinimumAmlResourceLength) 2333446Smrj { 2343446Smrj UINT32 StringLength = 0; 2353446Smrj 2363446Smrj 2373446Smrj ACPI_FUNCTION_ENTRY (); 2383446Smrj 2393446Smrj 2403446Smrj /* 2413446Smrj * The ResourceSourceIndex and ResourceSource are optional elements of some 2423446Smrj * Large-type resource descriptors. 2433446Smrj */ 2443446Smrj 2453446Smrj /* 2463446Smrj * If the length of the actual resource descriptor is greater than the ACPI 2473446Smrj * spec-defined minimum length, it means that a ResourceSourceIndex exists 2483446Smrj * and is followed by a (required) null terminated string. The string length 2493446Smrj * (including the null terminator) is the resource length minus the minimum 2503446Smrj * length, minus one byte for the ResourceSourceIndex itself. 2513446Smrj */ 2523446Smrj if (ResourceLength > MinimumAmlResourceLength) 2533446Smrj { 2543446Smrj /* Compute the length of the optional string */ 2553446Smrj 2563446Smrj StringLength = ResourceLength - MinimumAmlResourceLength - 1; 2573446Smrj } 2583446Smrj 2593446Smrj /* 2603446Smrj * Round the length up to a multiple of the native word in order to 2613446Smrj * guarantee that the entire resource descriptor is native word aligned 2623446Smrj */ 2633446Smrj return ((UINT32) ACPI_ROUND_UP_TO_NATIVE_WORD (StringLength)); 2643446Smrj } 2653446Smrj 2663446Smrj 2673446Smrj /******************************************************************************* 2683446Smrj * 2693446Smrj * FUNCTION: AcpiRsGetAmlLength 2703446Smrj * 2713446Smrj * PARAMETERS: Resource - Pointer to the resource linked list 2723446Smrj * SizeNeeded - Where the required size is returned 2733446Smrj * 2743446Smrj * RETURN: Status 2753446Smrj * 2763446Smrj * DESCRIPTION: Takes a linked list of internal resource descriptors and 2773446Smrj * calculates the size buffer needed to hold the corresponding 2783446Smrj * external resource byte stream. 2793446Smrj * 2803446Smrj ******************************************************************************/ 2813446Smrj 2823446Smrj ACPI_STATUS 2833446Smrj AcpiRsGetAmlLength ( 2843446Smrj ACPI_RESOURCE *Resource, 2853446Smrj ACPI_SIZE *SizeNeeded) 2863446Smrj { 2873446Smrj ACPI_SIZE AmlSizeNeeded = 0; 2883446Smrj ACPI_RS_LENGTH TotalSize; 2893446Smrj 2903446Smrj 2913446Smrj ACPI_FUNCTION_TRACE (RsGetAmlLength); 2923446Smrj 2933446Smrj 2943446Smrj /* Traverse entire list of internal resource descriptors */ 2953446Smrj 2963446Smrj while (Resource) 2973446Smrj { 2983446Smrj /* Validate the descriptor type */ 2993446Smrj 3003446Smrj if (Resource->Type > ACPI_RESOURCE_TYPE_MAX) 3013446Smrj { 3023446Smrj return_ACPI_STATUS (AE_AML_INVALID_RESOURCE_TYPE); 3033446Smrj } 3043446Smrj 3053446Smrj /* Get the base size of the (external stream) resource descriptor */ 3063446Smrj 3073446Smrj TotalSize = AcpiGbl_AmlResourceSizes [Resource->Type]; 3083446Smrj 3093446Smrj /* 3103446Smrj * Augment the base size for descriptors with optional and/or 3113446Smrj * variable-length fields 3123446Smrj */ 3133446Smrj switch (Resource->Type) 3143446Smrj { 315*7851SDana.Myers@Sun.COM case ACPI_RESOURCE_TYPE_IRQ: 316*7851SDana.Myers@Sun.COM 317*7851SDana.Myers@Sun.COM /* Length can be 3 or 2 */ 318*7851SDana.Myers@Sun.COM 319*7851SDana.Myers@Sun.COM if (Resource->Data.Irq.DescriptorLength == 2) 320*7851SDana.Myers@Sun.COM { 321*7851SDana.Myers@Sun.COM TotalSize--; 322*7851SDana.Myers@Sun.COM } 323*7851SDana.Myers@Sun.COM break; 324*7851SDana.Myers@Sun.COM 325*7851SDana.Myers@Sun.COM 326*7851SDana.Myers@Sun.COM case ACPI_RESOURCE_TYPE_START_DEPENDENT: 327*7851SDana.Myers@Sun.COM 328*7851SDana.Myers@Sun.COM /* Length can be 1 or 0 */ 329*7851SDana.Myers@Sun.COM 330*7851SDana.Myers@Sun.COM if (Resource->Data.Irq.DescriptorLength == 0) 331*7851SDana.Myers@Sun.COM { 332*7851SDana.Myers@Sun.COM TotalSize--; 333*7851SDana.Myers@Sun.COM } 334*7851SDana.Myers@Sun.COM break; 335*7851SDana.Myers@Sun.COM 336*7851SDana.Myers@Sun.COM 3373446Smrj case ACPI_RESOURCE_TYPE_VENDOR: 3383446Smrj /* 3393446Smrj * Vendor Defined Resource: 3403446Smrj * For a Vendor Specific resource, if the Length is between 1 and 7 3413446Smrj * it will be created as a Small Resource data type, otherwise it 3423446Smrj * is a Large Resource data type. 3433446Smrj */ 3443446Smrj if (Resource->Data.Vendor.ByteLength > 7) 3453446Smrj { 3463446Smrj /* Base size of a Large resource descriptor */ 3473446Smrj 3483446Smrj TotalSize = sizeof (AML_RESOURCE_LARGE_HEADER); 3493446Smrj } 3503446Smrj 3513446Smrj /* Add the size of the vendor-specific data */ 3523446Smrj 3533446Smrj TotalSize = (ACPI_RS_LENGTH) 3543446Smrj (TotalSize + Resource->Data.Vendor.ByteLength); 3553446Smrj break; 3563446Smrj 3573446Smrj 3583446Smrj case ACPI_RESOURCE_TYPE_END_TAG: 3593446Smrj /* 3603446Smrj * End Tag: 3613446Smrj * We are done -- return the accumulated total size. 3623446Smrj */ 3633446Smrj *SizeNeeded = AmlSizeNeeded + TotalSize; 3643446Smrj 3653446Smrj /* Normal exit */ 3663446Smrj 3673446Smrj return_ACPI_STATUS (AE_OK); 3683446Smrj 3693446Smrj 3703446Smrj case ACPI_RESOURCE_TYPE_ADDRESS16: 3713446Smrj /* 3723446Smrj * 16-Bit Address Resource: 3733446Smrj * Add the size of the optional ResourceSource info 3743446Smrj */ 3753446Smrj TotalSize = (ACPI_RS_LENGTH) 3763446Smrj (TotalSize + AcpiRsStructOptionLength ( 3773446Smrj &Resource->Data.Address16.ResourceSource)); 3783446Smrj break; 3793446Smrj 3803446Smrj 3813446Smrj case ACPI_RESOURCE_TYPE_ADDRESS32: 3823446Smrj /* 3833446Smrj * 32-Bit Address Resource: 3843446Smrj * Add the size of the optional ResourceSource info 3853446Smrj */ 3863446Smrj TotalSize = (ACPI_RS_LENGTH) 3873446Smrj (TotalSize + AcpiRsStructOptionLength ( 3883446Smrj &Resource->Data.Address32.ResourceSource)); 3893446Smrj break; 3903446Smrj 3913446Smrj 3923446Smrj case ACPI_RESOURCE_TYPE_ADDRESS64: 3933446Smrj /* 3943446Smrj * 64-Bit Address Resource: 3953446Smrj * Add the size of the optional ResourceSource info 3963446Smrj */ 3973446Smrj TotalSize = (ACPI_RS_LENGTH) 3983446Smrj (TotalSize + AcpiRsStructOptionLength ( 3993446Smrj &Resource->Data.Address64.ResourceSource)); 4003446Smrj break; 4013446Smrj 4023446Smrj 4033446Smrj case ACPI_RESOURCE_TYPE_EXTENDED_IRQ: 4043446Smrj /* 4053446Smrj * Extended IRQ Resource: 4063446Smrj * Add the size of each additional optional interrupt beyond the 4073446Smrj * required 1 (4 bytes for each UINT32 interrupt number) 4083446Smrj */ 4093446Smrj TotalSize = (ACPI_RS_LENGTH) 4103446Smrj (TotalSize + 4113446Smrj ((Resource->Data.ExtendedIrq.InterruptCount - 1) * 4) + 4123446Smrj 4133446Smrj /* Add the size of the optional ResourceSource info */ 4143446Smrj 4153446Smrj AcpiRsStructOptionLength ( 4163446Smrj &Resource->Data.ExtendedIrq.ResourceSource)); 4173446Smrj break; 4183446Smrj 4193446Smrj 4203446Smrj default: 4213446Smrj break; 4223446Smrj } 4233446Smrj 4243446Smrj /* Update the total */ 4253446Smrj 4263446Smrj AmlSizeNeeded += TotalSize; 4273446Smrj 4283446Smrj /* Point to the next object */ 4293446Smrj 4303446Smrj Resource = ACPI_ADD_PTR (ACPI_RESOURCE, Resource, Resource->Length); 4313446Smrj } 4323446Smrj 4333446Smrj /* Did not find an EndTag resource descriptor */ 4343446Smrj 4353446Smrj return_ACPI_STATUS (AE_AML_NO_RESOURCE_END_TAG); 4363446Smrj } 4373446Smrj 4383446Smrj 4393446Smrj /******************************************************************************* 4403446Smrj * 4413446Smrj * FUNCTION: AcpiRsGetListLength 4423446Smrj * 4433446Smrj * PARAMETERS: AmlBuffer - Pointer to the resource byte stream 4443446Smrj * AmlBufferLength - Size of AmlBuffer 4453446Smrj * SizeNeeded - Where the size needed is returned 4463446Smrj * 4473446Smrj * RETURN: Status 4483446Smrj * 4493446Smrj * DESCRIPTION: Takes an external resource byte stream and calculates the size 4503446Smrj * buffer needed to hold the corresponding internal resource 4513446Smrj * descriptor linked list. 4523446Smrj * 4533446Smrj ******************************************************************************/ 4543446Smrj 4553446Smrj ACPI_STATUS 4563446Smrj AcpiRsGetListLength ( 4573446Smrj UINT8 *AmlBuffer, 4583446Smrj UINT32 AmlBufferLength, 4593446Smrj ACPI_SIZE *SizeNeeded) 4603446Smrj { 4613446Smrj ACPI_STATUS Status; 4623446Smrj UINT8 *EndAml; 4633446Smrj UINT8 *Buffer; 4643446Smrj UINT32 BufferSize; 4653446Smrj UINT16 Temp16; 4663446Smrj UINT16 ResourceLength; 4673446Smrj UINT32 ExtraStructBytes; 4683446Smrj UINT8 ResourceIndex; 4693446Smrj UINT8 MinimumAmlResourceLength; 4703446Smrj 4713446Smrj 4723446Smrj ACPI_FUNCTION_TRACE (RsGetListLength); 4733446Smrj 4743446Smrj 4753446Smrj *SizeNeeded = 0; 4763446Smrj EndAml = AmlBuffer + AmlBufferLength; 4773446Smrj 4783446Smrj /* Walk the list of AML resource descriptors */ 4793446Smrj 4803446Smrj while (AmlBuffer < EndAml) 4813446Smrj { 4823446Smrj /* Validate the Resource Type and Resource Length */ 4833446Smrj 4843446Smrj Status = AcpiUtValidateResource (AmlBuffer, &ResourceIndex); 4853446Smrj if (ACPI_FAILURE (Status)) 4863446Smrj { 4873446Smrj return_ACPI_STATUS (Status); 4883446Smrj } 4893446Smrj 4903446Smrj /* Get the resource length and base (minimum) AML size */ 4913446Smrj 4923446Smrj ResourceLength = AcpiUtGetResourceLength (AmlBuffer); 4933446Smrj MinimumAmlResourceLength = AcpiGbl_ResourceAmlSizes[ResourceIndex]; 4943446Smrj 4953446Smrj /* 4963446Smrj * Augment the size for descriptors with optional 4973446Smrj * and/or variable length fields 4983446Smrj */ 4993446Smrj ExtraStructBytes = 0; 5003446Smrj Buffer = AmlBuffer + AcpiUtGetResourceHeaderLength (AmlBuffer); 5013446Smrj 5023446Smrj switch (AcpiUtGetResourceType (AmlBuffer)) 5033446Smrj { 5043446Smrj case ACPI_RESOURCE_NAME_IRQ: 5053446Smrj /* 5063446Smrj * IRQ Resource: 5073446Smrj * Get the number of bits set in the 16-bit IRQ mask 5083446Smrj */ 5093446Smrj ACPI_MOVE_16_TO_16 (&Temp16, Buffer); 5103446Smrj ExtraStructBytes = AcpiRsCountSetBits (Temp16); 5113446Smrj break; 5123446Smrj 5133446Smrj 5143446Smrj case ACPI_RESOURCE_NAME_DMA: 5153446Smrj /* 5163446Smrj * DMA Resource: 5173446Smrj * Get the number of bits set in the 8-bit DMA mask 5183446Smrj */ 5193446Smrj ExtraStructBytes = AcpiRsCountSetBits (*Buffer); 5203446Smrj break; 5213446Smrj 5223446Smrj 5233446Smrj case ACPI_RESOURCE_NAME_VENDOR_SMALL: 5243446Smrj case ACPI_RESOURCE_NAME_VENDOR_LARGE: 5253446Smrj /* 5263446Smrj * Vendor Resource: 5273446Smrj * Get the number of vendor data bytes 5283446Smrj */ 5293446Smrj ExtraStructBytes = ResourceLength; 5303446Smrj break; 5313446Smrj 5323446Smrj 5333446Smrj case ACPI_RESOURCE_NAME_END_TAG: 5343446Smrj /* 5353446Smrj * End Tag: 5363446Smrj * This is the normal exit, add size of EndTag 5373446Smrj */ 5383446Smrj *SizeNeeded += ACPI_RS_SIZE_MIN; 5393446Smrj return_ACPI_STATUS (AE_OK); 5403446Smrj 5413446Smrj 5423446Smrj case ACPI_RESOURCE_NAME_ADDRESS32: 5433446Smrj case ACPI_RESOURCE_NAME_ADDRESS16: 5443446Smrj case ACPI_RESOURCE_NAME_ADDRESS64: 5453446Smrj /* 5463446Smrj * Address Resource: 5473446Smrj * Add the size of the optional ResourceSource 5483446Smrj */ 5493446Smrj ExtraStructBytes = AcpiRsStreamOptionLength ( 5503446Smrj ResourceLength, MinimumAmlResourceLength); 5513446Smrj break; 5523446Smrj 5533446Smrj 5543446Smrj case ACPI_RESOURCE_NAME_EXTENDED_IRQ: 5553446Smrj /* 5563446Smrj * Extended IRQ Resource: 5573446Smrj * Using the InterruptTableLength, add 4 bytes for each additional 5583446Smrj * interrupt. Note: at least one interrupt is required and is 5593446Smrj * included in the minimum descriptor size (reason for the -1) 5603446Smrj */ 5613446Smrj ExtraStructBytes = (Buffer[1] - 1) * sizeof (UINT32); 5623446Smrj 5633446Smrj /* Add the size of the optional ResourceSource */ 5643446Smrj 5653446Smrj ExtraStructBytes += AcpiRsStreamOptionLength ( 5663446Smrj ResourceLength - ExtraStructBytes, MinimumAmlResourceLength); 5673446Smrj break; 5683446Smrj 5693446Smrj 5703446Smrj default: 5713446Smrj break; 5723446Smrj } 5733446Smrj 5743446Smrj /* 5753446Smrj * Update the required buffer size for the internal descriptor structs 5763446Smrj * 5773446Smrj * Important: Round the size up for the appropriate alignment. This 5783446Smrj * is a requirement on IA64. 5793446Smrj */ 5803446Smrj BufferSize = AcpiGbl_ResourceStructSizes[ResourceIndex] + 5813446Smrj ExtraStructBytes; 5823446Smrj BufferSize = (UINT32) ACPI_ROUND_UP_TO_NATIVE_WORD (BufferSize); 5833446Smrj 5843446Smrj *SizeNeeded += BufferSize; 5853446Smrj 5863446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_RESOURCES, 5873446Smrj "Type %.2X, AmlLength %.2X InternalLength %.2X\n", 5883446Smrj AcpiUtGetResourceType (AmlBuffer), 5893446Smrj AcpiUtGetDescriptorLength (AmlBuffer), BufferSize)); 5903446Smrj 5913446Smrj /* 5923446Smrj * Point to the next resource within the AML stream using the length 5933446Smrj * contained in the resource descriptor header 5943446Smrj */ 5953446Smrj AmlBuffer += AcpiUtGetDescriptorLength (AmlBuffer); 5963446Smrj } 5973446Smrj 5983446Smrj /* Did not find an EndTag resource descriptor */ 5993446Smrj 6003446Smrj return_ACPI_STATUS (AE_AML_NO_RESOURCE_END_TAG); 6013446Smrj } 6023446Smrj 6033446Smrj 6043446Smrj /******************************************************************************* 6053446Smrj * 6063446Smrj * FUNCTION: AcpiRsGetPciRoutingTableLength 6073446Smrj * 6083446Smrj * PARAMETERS: PackageObject - Pointer to the package object 6093446Smrj * BufferSizeNeeded - UINT32 pointer of the size buffer 6103446Smrj * needed to properly return the 6113446Smrj * parsed data 6123446Smrj * 6133446Smrj * RETURN: Status 6143446Smrj * 6153446Smrj * DESCRIPTION: Given a package representing a PCI routing table, this 6163446Smrj * calculates the size of the corresponding linked list of 6173446Smrj * descriptions. 6183446Smrj * 6193446Smrj ******************************************************************************/ 6203446Smrj 6213446Smrj ACPI_STATUS 6223446Smrj AcpiRsGetPciRoutingTableLength ( 6233446Smrj ACPI_OPERAND_OBJECT *PackageObject, 6243446Smrj ACPI_SIZE *BufferSizeNeeded) 6253446Smrj { 6263446Smrj UINT32 NumberOfElements; 6273446Smrj ACPI_SIZE TempSizeNeeded = 0; 6283446Smrj ACPI_OPERAND_OBJECT **TopObjectList; 6293446Smrj UINT32 Index; 6303446Smrj ACPI_OPERAND_OBJECT *PackageElement; 6313446Smrj ACPI_OPERAND_OBJECT **SubObjectList; 6323446Smrj BOOLEAN NameFound; 6333446Smrj UINT32 TableIndex; 6343446Smrj 6353446Smrj 6363446Smrj ACPI_FUNCTION_TRACE (RsGetPciRoutingTableLength); 6373446Smrj 6383446Smrj 6393446Smrj NumberOfElements = PackageObject->Package.Count; 6403446Smrj 6413446Smrj /* 6423446Smrj * Calculate the size of the return buffer. 6433446Smrj * The base size is the number of elements * the sizes of the 6443446Smrj * structures. Additional space for the strings is added below. 6453446Smrj * The minus one is to subtract the size of the UINT8 Source[1] 6463446Smrj * member because it is added below. 6473446Smrj * 6483446Smrj * But each PRT_ENTRY structure has a pointer to a string and 6493446Smrj * the size of that string must be found. 6503446Smrj */ 6513446Smrj TopObjectList = PackageObject->Package.Elements; 6523446Smrj 6533446Smrj for (Index = 0; Index < NumberOfElements; Index++) 6543446Smrj { 6553446Smrj /* Dereference the sub-package */ 6563446Smrj 6573446Smrj PackageElement = *TopObjectList; 6583446Smrj 6593446Smrj /* 6603446Smrj * The SubObjectList will now point to an array of the 6613446Smrj * four IRQ elements: Address, Pin, Source and SourceIndex 6623446Smrj */ 6633446Smrj SubObjectList = PackageElement->Package.Elements; 6643446Smrj 6653446Smrj /* Scan the IrqTableElements for the Source Name String */ 6663446Smrj 6673446Smrj NameFound = FALSE; 6683446Smrj 6693446Smrj for (TableIndex = 0; TableIndex < 4 && !NameFound; TableIndex++) 6703446Smrj { 6713446Smrj if (*SubObjectList && /* Null object allowed */ 6723446Smrj 6733446Smrj ((ACPI_TYPE_STRING == 6743446Smrj ACPI_GET_OBJECT_TYPE (*SubObjectList)) || 6753446Smrj 6763446Smrj ((ACPI_TYPE_LOCAL_REFERENCE == 6773446Smrj ACPI_GET_OBJECT_TYPE (*SubObjectList)) && 6783446Smrj 679*7851SDana.Myers@Sun.COM ((*SubObjectList)->Reference.Class == 680*7851SDana.Myers@Sun.COM ACPI_REFCLASS_NAME)))) 6813446Smrj { 6823446Smrj NameFound = TRUE; 6833446Smrj } 6843446Smrj else 6853446Smrj { 6863446Smrj /* Look at the next element */ 6873446Smrj 6883446Smrj SubObjectList++; 6893446Smrj } 6903446Smrj } 6913446Smrj 6923446Smrj TempSizeNeeded += (sizeof (ACPI_PCI_ROUTING_TABLE) - 4); 6933446Smrj 6943446Smrj /* Was a String type found? */ 6953446Smrj 6963446Smrj if (NameFound) 6973446Smrj { 6983446Smrj if (ACPI_GET_OBJECT_TYPE (*SubObjectList) == ACPI_TYPE_STRING) 6993446Smrj { 7003446Smrj /* 7013446Smrj * The length String.Length field does not include the 7023446Smrj * terminating NULL, add 1 7033446Smrj */ 7043446Smrj TempSizeNeeded += ((ACPI_SIZE) 7053446Smrj (*SubObjectList)->String.Length + 1); 7063446Smrj } 7073446Smrj else 7083446Smrj { 7093446Smrj TempSizeNeeded += AcpiNsGetPathnameLength ( 7103446Smrj (*SubObjectList)->Reference.Node); 711*7851SDana.Myers@Sun.COM if (!TempSizeNeeded) 712*7851SDana.Myers@Sun.COM { 713*7851SDana.Myers@Sun.COM return_ACPI_STATUS (AE_BAD_PARAMETER); 714*7851SDana.Myers@Sun.COM } 7153446Smrj } 7163446Smrj } 7173446Smrj else 7183446Smrj { 7193446Smrj /* 7203446Smrj * If no name was found, then this is a NULL, which is 7213446Smrj * translated as a UINT32 zero. 7223446Smrj */ 7233446Smrj TempSizeNeeded += sizeof (UINT32); 7243446Smrj } 7253446Smrj 7263446Smrj /* Round up the size since each element must be aligned */ 7273446Smrj 7283446Smrj TempSizeNeeded = ACPI_ROUND_UP_TO_64BIT (TempSizeNeeded); 7293446Smrj 7303446Smrj /* Point to the next ACPI_OPERAND_OBJECT */ 7313446Smrj 7323446Smrj TopObjectList++; 7333446Smrj } 7343446Smrj 7353446Smrj /* 7363446Smrj * Add an extra element to the end of the list, essentially a 7373446Smrj * NULL terminator 7383446Smrj */ 7393446Smrj *BufferSizeNeeded = TempSizeNeeded + sizeof (ACPI_PCI_ROUTING_TABLE); 7403446Smrj return_ACPI_STATUS (AE_OK); 7413446Smrj } 742