10174267aSFredrik Holmqvist /*******************************************************************************
20174267aSFredrik Holmqvist *
30174267aSFredrik Holmqvist * Module Name: rscalc - Calculate stream and list lengths
40174267aSFredrik Holmqvist *
50174267aSFredrik Holmqvist ******************************************************************************/
60174267aSFredrik Holmqvist
70174267aSFredrik Holmqvist /******************************************************************************
80174267aSFredrik Holmqvist *
90174267aSFredrik Holmqvist * 1. Copyright Notice
100174267aSFredrik Holmqvist *
11*6dde014fSPulkoMandy * Some or all of this work - Copyright (c) 1999 - 2024, Intel Corp.
120174267aSFredrik Holmqvist * All rights reserved.
130174267aSFredrik Holmqvist *
140174267aSFredrik Holmqvist * 2. License
150174267aSFredrik Holmqvist *
160174267aSFredrik Holmqvist * 2.1. This is your license from Intel Corp. under its intellectual property
170174267aSFredrik Holmqvist * rights. You may have additional license terms from the party that provided
180174267aSFredrik Holmqvist * you this software, covering your right to use that party's intellectual
190174267aSFredrik Holmqvist * property rights.
200174267aSFredrik Holmqvist *
210174267aSFredrik Holmqvist * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
220174267aSFredrik Holmqvist * copy of the source code appearing in this file ("Covered Code") an
230174267aSFredrik Holmqvist * irrevocable, perpetual, worldwide license under Intel's copyrights in the
240174267aSFredrik Holmqvist * base code distributed originally by Intel ("Original Intel Code") to copy,
250174267aSFredrik Holmqvist * make derivatives, distribute, use and display any portion of the Covered
260174267aSFredrik Holmqvist * Code in any form, with the right to sublicense such rights; and
270174267aSFredrik Holmqvist *
280174267aSFredrik Holmqvist * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
290174267aSFredrik Holmqvist * license (with the right to sublicense), under only those claims of Intel
300174267aSFredrik Holmqvist * patents that are infringed by the Original Intel Code, to make, use, sell,
310174267aSFredrik Holmqvist * offer to sell, and import the Covered Code and derivative works thereof
320174267aSFredrik Holmqvist * solely to the minimum extent necessary to exercise the above copyright
330174267aSFredrik Holmqvist * license, and in no event shall the patent license extend to any additions
340174267aSFredrik Holmqvist * to or modifications of the Original Intel Code. No other license or right
350174267aSFredrik Holmqvist * is granted directly or by implication, estoppel or otherwise;
360174267aSFredrik Holmqvist *
370174267aSFredrik Holmqvist * The above copyright and patent license is granted only if the following
380174267aSFredrik Holmqvist * conditions are met:
390174267aSFredrik Holmqvist *
400174267aSFredrik Holmqvist * 3. Conditions
410174267aSFredrik Holmqvist *
420174267aSFredrik Holmqvist * 3.1. Redistribution of Source with Rights to Further Distribute Source.
430174267aSFredrik Holmqvist * Redistribution of source code of any substantial portion of the Covered
440174267aSFredrik Holmqvist * Code or modification with rights to further distribute source must include
450174267aSFredrik Holmqvist * the above Copyright Notice, the above License, this list of Conditions,
460174267aSFredrik Holmqvist * and the following Disclaimer and Export Compliance provision. In addition,
470174267aSFredrik Holmqvist * Licensee must cause all Covered Code to which Licensee contributes to
480174267aSFredrik Holmqvist * contain a file documenting the changes Licensee made to create that Covered
490174267aSFredrik Holmqvist * Code and the date of any change. Licensee must include in that file the
500174267aSFredrik Holmqvist * documentation of any changes made by any predecessor Licensee. Licensee
510174267aSFredrik Holmqvist * must include a prominent statement that the modification is derived,
520174267aSFredrik Holmqvist * directly or indirectly, from Original Intel Code.
530174267aSFredrik Holmqvist *
540174267aSFredrik Holmqvist * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
550174267aSFredrik Holmqvist * Redistribution of source code of any substantial portion of the Covered
560174267aSFredrik Holmqvist * Code or modification without rights to further distribute source must
570174267aSFredrik Holmqvist * include the following Disclaimer and Export Compliance provision in the
580174267aSFredrik Holmqvist * documentation and/or other materials provided with distribution. In
590174267aSFredrik Holmqvist * addition, Licensee may not authorize further sublicense of source of any
600174267aSFredrik Holmqvist * portion of the Covered Code, and must include terms to the effect that the
610174267aSFredrik Holmqvist * license from Licensee to its licensee is limited to the intellectual
620174267aSFredrik Holmqvist * property embodied in the software Licensee provides to its licensee, and
630174267aSFredrik Holmqvist * not to intellectual property embodied in modifications its licensee may
640174267aSFredrik Holmqvist * make.
650174267aSFredrik Holmqvist *
660174267aSFredrik Holmqvist * 3.3. Redistribution of Executable. Redistribution in executable form of any
670174267aSFredrik Holmqvist * substantial portion of the Covered Code or modification must reproduce the
680174267aSFredrik Holmqvist * above Copyright Notice, and the following Disclaimer and Export Compliance
690174267aSFredrik Holmqvist * provision in the documentation and/or other materials provided with the
700174267aSFredrik Holmqvist * distribution.
710174267aSFredrik Holmqvist *
720174267aSFredrik Holmqvist * 3.4. Intel retains all right, title, and interest in and to the Original
730174267aSFredrik Holmqvist * Intel Code.
740174267aSFredrik Holmqvist *
750174267aSFredrik Holmqvist * 3.5. Neither the name Intel nor any other trademark owned or controlled by
760174267aSFredrik Holmqvist * Intel shall be used in advertising or otherwise to promote the sale, use or
770174267aSFredrik Holmqvist * other dealings in products derived from or relating to the Covered Code
780174267aSFredrik Holmqvist * without prior written authorization from Intel.
790174267aSFredrik Holmqvist *
800174267aSFredrik Holmqvist * 4. Disclaimer and Export Compliance
810174267aSFredrik Holmqvist *
820174267aSFredrik Holmqvist * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
830174267aSFredrik Holmqvist * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
840174267aSFredrik Holmqvist * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
850174267aSFredrik Holmqvist * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
860174267aSFredrik Holmqvist * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
870174267aSFredrik Holmqvist * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
880174267aSFredrik Holmqvist * PARTICULAR PURPOSE.
890174267aSFredrik Holmqvist *
900174267aSFredrik Holmqvist * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
910174267aSFredrik Holmqvist * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
920174267aSFredrik Holmqvist * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
930174267aSFredrik Holmqvist * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
940174267aSFredrik Holmqvist * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
950174267aSFredrik Holmqvist * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
960174267aSFredrik Holmqvist * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
970174267aSFredrik Holmqvist * LIMITED REMEDY.
980174267aSFredrik Holmqvist *
990174267aSFredrik Holmqvist * 4.3. Licensee shall not export, either directly or indirectly, any of this
1000174267aSFredrik Holmqvist * software or system incorporating such software without first obtaining any
1010174267aSFredrik Holmqvist * required license or other approval from the U. S. Department of Commerce or
1020174267aSFredrik Holmqvist * any other agency or department of the United States Government. In the
1030174267aSFredrik Holmqvist * event Licensee exports any such software from the United States or
1040174267aSFredrik Holmqvist * re-exports any such software from a foreign destination, Licensee shall
1050174267aSFredrik Holmqvist * ensure that the distribution and export/re-export of the software is in
1060174267aSFredrik Holmqvist * compliance with all laws, regulations, orders, or other restrictions of the
1070174267aSFredrik Holmqvist * U.S. Export Administration Regulations. Licensee agrees that neither it nor
1080174267aSFredrik Holmqvist * any of its subsidiaries will export/re-export any technical data, process,
1090174267aSFredrik Holmqvist * software, or service, directly or indirectly, to any country for which the
1100174267aSFredrik Holmqvist * United States government or any agency thereof requires an export license,
1110174267aSFredrik Holmqvist * other governmental approval, or letter of assurance, without first obtaining
1120174267aSFredrik Holmqvist * such license, approval or letter.
1130174267aSFredrik Holmqvist *
114ff2e2f81SFredrik Holmqvist *****************************************************************************
115ff2e2f81SFredrik Holmqvist *
116ff2e2f81SFredrik Holmqvist * Alternatively, you may choose to be licensed under the terms of the
117ff2e2f81SFredrik Holmqvist * following license:
118ff2e2f81SFredrik Holmqvist *
119ff2e2f81SFredrik Holmqvist * Redistribution and use in source and binary forms, with or without
120ff2e2f81SFredrik Holmqvist * modification, are permitted provided that the following conditions
121ff2e2f81SFredrik Holmqvist * are met:
122ff2e2f81SFredrik Holmqvist * 1. Redistributions of source code must retain the above copyright
123ff2e2f81SFredrik Holmqvist * notice, this list of conditions, and the following disclaimer,
124ff2e2f81SFredrik Holmqvist * without modification.
125ff2e2f81SFredrik Holmqvist * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126ff2e2f81SFredrik Holmqvist * substantially similar to the "NO WARRANTY" disclaimer below
127ff2e2f81SFredrik Holmqvist * ("Disclaimer") and any redistribution must be conditioned upon
128ff2e2f81SFredrik Holmqvist * including a substantially similar Disclaimer requirement for further
129ff2e2f81SFredrik Holmqvist * binary redistribution.
130ff2e2f81SFredrik Holmqvist * 3. Neither the names of the above-listed copyright holders nor the names
131ff2e2f81SFredrik Holmqvist * of any contributors may be used to endorse or promote products derived
132ff2e2f81SFredrik Holmqvist * from this software without specific prior written permission.
133ff2e2f81SFredrik Holmqvist *
134ff2e2f81SFredrik Holmqvist * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135ff2e2f81SFredrik Holmqvist * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136ff2e2f81SFredrik Holmqvist * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137ff2e2f81SFredrik Holmqvist * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138ff2e2f81SFredrik Holmqvist * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139ff2e2f81SFredrik Holmqvist * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140ff2e2f81SFredrik Holmqvist * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141ff2e2f81SFredrik Holmqvist * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142ff2e2f81SFredrik Holmqvist * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143ff2e2f81SFredrik Holmqvist * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144ff2e2f81SFredrik Holmqvist * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145ff2e2f81SFredrik Holmqvist *
146ff2e2f81SFredrik Holmqvist * Alternatively, you may choose to be licensed under the terms of the
147ff2e2f81SFredrik Holmqvist * GNU General Public License ("GPL") version 2 as published by the Free
148ff2e2f81SFredrik Holmqvist * Software Foundation.
149ff2e2f81SFredrik Holmqvist *
1500174267aSFredrik Holmqvist *****************************************************************************/
1510174267aSFredrik Holmqvist
1520174267aSFredrik Holmqvist #include "acpi.h"
1530174267aSFredrik Holmqvist #include "accommon.h"
1540174267aSFredrik Holmqvist #include "acresrc.h"
1550174267aSFredrik Holmqvist #include "acnamesp.h"
1560174267aSFredrik Holmqvist
1570174267aSFredrik Holmqvist
1580174267aSFredrik Holmqvist #define _COMPONENT ACPI_RESOURCES
1590174267aSFredrik Holmqvist ACPI_MODULE_NAME ("rscalc")
1600174267aSFredrik Holmqvist
1610174267aSFredrik Holmqvist
1620174267aSFredrik Holmqvist /* Local prototypes */
1630174267aSFredrik Holmqvist
1640174267aSFredrik Holmqvist static UINT8
1650174267aSFredrik Holmqvist AcpiRsCountSetBits (
1660174267aSFredrik Holmqvist UINT16 BitField);
1670174267aSFredrik Holmqvist
1680174267aSFredrik Holmqvist static ACPI_RS_LENGTH
1690174267aSFredrik Holmqvist AcpiRsStructOptionLength (
1700174267aSFredrik Holmqvist ACPI_RESOURCE_SOURCE *ResourceSource);
1710174267aSFredrik Holmqvist
1720174267aSFredrik Holmqvist static UINT32
1730174267aSFredrik Holmqvist AcpiRsStreamOptionLength (
1740174267aSFredrik Holmqvist UINT32 ResourceLength,
1750174267aSFredrik Holmqvist UINT32 MinimumTotalLength);
1760174267aSFredrik Holmqvist
1770174267aSFredrik Holmqvist
1780174267aSFredrik Holmqvist /*******************************************************************************
1790174267aSFredrik Holmqvist *
1800174267aSFredrik Holmqvist * FUNCTION: AcpiRsCountSetBits
1810174267aSFredrik Holmqvist *
1820174267aSFredrik Holmqvist * PARAMETERS: BitField - Field in which to count bits
1830174267aSFredrik Holmqvist *
1840174267aSFredrik Holmqvist * RETURN: Number of bits set within the field
1850174267aSFredrik Holmqvist *
1860174267aSFredrik Holmqvist * DESCRIPTION: Count the number of bits set in a resource field. Used for
1870174267aSFredrik Holmqvist * (Short descriptor) interrupt and DMA lists.
1880174267aSFredrik Holmqvist *
1890174267aSFredrik Holmqvist ******************************************************************************/
1900174267aSFredrik Holmqvist
1910174267aSFredrik Holmqvist static UINT8
AcpiRsCountSetBits(UINT16 BitField)1920174267aSFredrik Holmqvist AcpiRsCountSetBits (
1930174267aSFredrik Holmqvist UINT16 BitField)
1940174267aSFredrik Holmqvist {
1950174267aSFredrik Holmqvist UINT8 BitsSet;
1960174267aSFredrik Holmqvist
1970174267aSFredrik Holmqvist
1980174267aSFredrik Holmqvist ACPI_FUNCTION_ENTRY ();
1990174267aSFredrik Holmqvist
2000174267aSFredrik Holmqvist
2010174267aSFredrik Holmqvist for (BitsSet = 0; BitField; BitsSet++)
2020174267aSFredrik Holmqvist {
2030174267aSFredrik Holmqvist /* Zero the least significant bit that is set */
2040174267aSFredrik Holmqvist
2050174267aSFredrik Holmqvist BitField &= (UINT16) (BitField - 1);
2060174267aSFredrik Holmqvist }
2070174267aSFredrik Holmqvist
2080174267aSFredrik Holmqvist return (BitsSet);
2090174267aSFredrik Holmqvist }
2100174267aSFredrik Holmqvist
2110174267aSFredrik Holmqvist
2120174267aSFredrik Holmqvist /*******************************************************************************
2130174267aSFredrik Holmqvist *
2140174267aSFredrik Holmqvist * FUNCTION: AcpiRsStructOptionLength
2150174267aSFredrik Holmqvist *
2160174267aSFredrik Holmqvist * PARAMETERS: ResourceSource - Pointer to optional descriptor field
2170174267aSFredrik Holmqvist *
2180174267aSFredrik Holmqvist * RETURN: Status
2190174267aSFredrik Holmqvist *
2200174267aSFredrik Holmqvist * DESCRIPTION: Common code to handle optional ResourceSourceIndex and
2210174267aSFredrik Holmqvist * ResourceSource fields in some Large descriptors. Used during
2220174267aSFredrik Holmqvist * list-to-stream conversion
2230174267aSFredrik Holmqvist *
2240174267aSFredrik Holmqvist ******************************************************************************/
2250174267aSFredrik Holmqvist
2260174267aSFredrik Holmqvist static ACPI_RS_LENGTH
AcpiRsStructOptionLength(ACPI_RESOURCE_SOURCE * ResourceSource)2270174267aSFredrik Holmqvist AcpiRsStructOptionLength (
2280174267aSFredrik Holmqvist ACPI_RESOURCE_SOURCE *ResourceSource)
2290174267aSFredrik Holmqvist {
2300174267aSFredrik Holmqvist ACPI_FUNCTION_ENTRY ();
2310174267aSFredrik Holmqvist
2320174267aSFredrik Holmqvist
2330174267aSFredrik Holmqvist /*
2340174267aSFredrik Holmqvist * If the ResourceSource string is valid, return the size of the string
2350174267aSFredrik Holmqvist * (StringLength includes the NULL terminator) plus the size of the
2360174267aSFredrik Holmqvist * ResourceSourceIndex (1).
2370174267aSFredrik Holmqvist */
2380174267aSFredrik Holmqvist if (ResourceSource->StringPtr)
2390174267aSFredrik Holmqvist {
2400174267aSFredrik Holmqvist return ((ACPI_RS_LENGTH) (ResourceSource->StringLength + 1));
2410174267aSFredrik Holmqvist }
2420174267aSFredrik Holmqvist
2430174267aSFredrik Holmqvist return (0);
2440174267aSFredrik Holmqvist }
2450174267aSFredrik Holmqvist
2460174267aSFredrik Holmqvist
2470174267aSFredrik Holmqvist /*******************************************************************************
2480174267aSFredrik Holmqvist *
2490174267aSFredrik Holmqvist * FUNCTION: AcpiRsStreamOptionLength
2500174267aSFredrik Holmqvist *
2510174267aSFredrik Holmqvist * PARAMETERS: ResourceLength - Length from the resource header
2520174267aSFredrik Holmqvist * MinimumTotalLength - Minimum length of this resource, before
2530174267aSFredrik Holmqvist * any optional fields. Includes header size
2540174267aSFredrik Holmqvist *
2550174267aSFredrik Holmqvist * RETURN: Length of optional string (0 if no string present)
2560174267aSFredrik Holmqvist *
2570174267aSFredrik Holmqvist * DESCRIPTION: Common code to handle optional ResourceSourceIndex and
2580174267aSFredrik Holmqvist * ResourceSource fields in some Large descriptors. Used during
2590174267aSFredrik Holmqvist * stream-to-list conversion
2600174267aSFredrik Holmqvist *
2610174267aSFredrik Holmqvist ******************************************************************************/
2620174267aSFredrik Holmqvist
2630174267aSFredrik Holmqvist static UINT32
AcpiRsStreamOptionLength(UINT32 ResourceLength,UINT32 MinimumAmlResourceLength)2640174267aSFredrik Holmqvist AcpiRsStreamOptionLength (
2650174267aSFredrik Holmqvist UINT32 ResourceLength,
2660174267aSFredrik Holmqvist UINT32 MinimumAmlResourceLength)
2670174267aSFredrik Holmqvist {
2680174267aSFredrik Holmqvist UINT32 StringLength = 0;
2690174267aSFredrik Holmqvist
2700174267aSFredrik Holmqvist
2710174267aSFredrik Holmqvist ACPI_FUNCTION_ENTRY ();
2720174267aSFredrik Holmqvist
2730174267aSFredrik Holmqvist
2740174267aSFredrik Holmqvist /*
275b64e8511SFredrik Holmqvist * The ResourceSourceIndex and ResourceSource are optional elements of
276b64e8511SFredrik Holmqvist * some Large-type resource descriptors.
2770174267aSFredrik Holmqvist */
2780174267aSFredrik Holmqvist
2790174267aSFredrik Holmqvist /*
280b64e8511SFredrik Holmqvist * If the length of the actual resource descriptor is greater than the
281b64e8511SFredrik Holmqvist * ACPI spec-defined minimum length, it means that a ResourceSourceIndex
282b64e8511SFredrik Holmqvist * exists and is followed by a (required) null terminated string. The
283b64e8511SFredrik Holmqvist * string length (including the null terminator) is the resource length
284b64e8511SFredrik Holmqvist * minus the minimum length, minus one byte for the ResourceSourceIndex
285b64e8511SFredrik Holmqvist * itself.
2860174267aSFredrik Holmqvist */
2870174267aSFredrik Holmqvist if (ResourceLength > MinimumAmlResourceLength)
2880174267aSFredrik Holmqvist {
2890174267aSFredrik Holmqvist /* Compute the length of the optional string */
2900174267aSFredrik Holmqvist
2910174267aSFredrik Holmqvist StringLength = ResourceLength - MinimumAmlResourceLength - 1;
2920174267aSFredrik Holmqvist }
2930174267aSFredrik Holmqvist
2940174267aSFredrik Holmqvist /*
2950174267aSFredrik Holmqvist * Round the length up to a multiple of the native word in order to
2960174267aSFredrik Holmqvist * guarantee that the entire resource descriptor is native word aligned
2970174267aSFredrik Holmqvist */
2980174267aSFredrik Holmqvist return ((UINT32) ACPI_ROUND_UP_TO_NATIVE_WORD (StringLength));
2990174267aSFredrik Holmqvist }
3000174267aSFredrik Holmqvist
3010174267aSFredrik Holmqvist
3020174267aSFredrik Holmqvist /*******************************************************************************
3030174267aSFredrik Holmqvist *
3040174267aSFredrik Holmqvist * FUNCTION: AcpiRsGetAmlLength
3050174267aSFredrik Holmqvist *
3060174267aSFredrik Holmqvist * PARAMETERS: Resource - Pointer to the resource linked list
307ad5bbfb8SFredrik Holmqvist * ResourceListSize - Size of the resource linked list
3080174267aSFredrik Holmqvist * SizeNeeded - Where the required size is returned
3090174267aSFredrik Holmqvist *
3100174267aSFredrik Holmqvist * RETURN: Status
3110174267aSFredrik Holmqvist *
3120174267aSFredrik Holmqvist * DESCRIPTION: Takes a linked list of internal resource descriptors and
3130174267aSFredrik Holmqvist * calculates the size buffer needed to hold the corresponding
3140174267aSFredrik Holmqvist * external resource byte stream.
3150174267aSFredrik Holmqvist *
3160174267aSFredrik Holmqvist ******************************************************************************/
3170174267aSFredrik Holmqvist
3180174267aSFredrik Holmqvist ACPI_STATUS
AcpiRsGetAmlLength(ACPI_RESOURCE * Resource,ACPI_SIZE ResourceListSize,ACPI_SIZE * SizeNeeded)3190174267aSFredrik Holmqvist AcpiRsGetAmlLength (
3200174267aSFredrik Holmqvist ACPI_RESOURCE *Resource,
321ad5bbfb8SFredrik Holmqvist ACPI_SIZE ResourceListSize,
3220174267aSFredrik Holmqvist ACPI_SIZE *SizeNeeded)
3230174267aSFredrik Holmqvist {
3240174267aSFredrik Holmqvist ACPI_SIZE AmlSizeNeeded = 0;
325ad5bbfb8SFredrik Holmqvist ACPI_RESOURCE *ResourceEnd;
3260174267aSFredrik Holmqvist ACPI_RS_LENGTH TotalSize;
3270174267aSFredrik Holmqvist
3280174267aSFredrik Holmqvist
3290174267aSFredrik Holmqvist ACPI_FUNCTION_TRACE (RsGetAmlLength);
3300174267aSFredrik Holmqvist
3310174267aSFredrik Holmqvist
3320174267aSFredrik Holmqvist /* Traverse entire list of internal resource descriptors */
3330174267aSFredrik Holmqvist
334ad5bbfb8SFredrik Holmqvist ResourceEnd = ACPI_ADD_PTR (ACPI_RESOURCE, Resource, ResourceListSize);
335ad5bbfb8SFredrik Holmqvist while (Resource < ResourceEnd)
3360174267aSFredrik Holmqvist {
3370174267aSFredrik Holmqvist /* Validate the descriptor type */
3380174267aSFredrik Holmqvist
3390174267aSFredrik Holmqvist if (Resource->Type > ACPI_RESOURCE_TYPE_MAX)
3400174267aSFredrik Holmqvist {
3410174267aSFredrik Holmqvist return_ACPI_STATUS (AE_AML_INVALID_RESOURCE_TYPE);
3420174267aSFredrik Holmqvist }
3430174267aSFredrik Holmqvist
344c70258b7SJérôme Duval /* Sanity check the length. It must not be zero, or we loop forever */
345c70258b7SJérôme Duval
346c70258b7SJérôme Duval if (!Resource->Length)
347c70258b7SJérôme Duval {
348c70258b7SJérôme Duval return_ACPI_STATUS (AE_AML_BAD_RESOURCE_LENGTH);
349c70258b7SJérôme Duval }
350c70258b7SJérôme Duval
3510174267aSFredrik Holmqvist /* Get the base size of the (external stream) resource descriptor */
3520174267aSFredrik Holmqvist
3530174267aSFredrik Holmqvist TotalSize = AcpiGbl_AmlResourceSizes [Resource->Type];
3540174267aSFredrik Holmqvist
3550174267aSFredrik Holmqvist /*
3560174267aSFredrik Holmqvist * Augment the base size for descriptors with optional and/or
3570174267aSFredrik Holmqvist * variable-length fields
3580174267aSFredrik Holmqvist */
3590174267aSFredrik Holmqvist switch (Resource->Type)
3600174267aSFredrik Holmqvist {
3610174267aSFredrik Holmqvist case ACPI_RESOURCE_TYPE_IRQ:
3620174267aSFredrik Holmqvist
3630174267aSFredrik Holmqvist /* Length can be 3 or 2 */
3640174267aSFredrik Holmqvist
3650174267aSFredrik Holmqvist if (Resource->Data.Irq.DescriptorLength == 2)
3660174267aSFredrik Holmqvist {
3670174267aSFredrik Holmqvist TotalSize--;
3680174267aSFredrik Holmqvist }
3690174267aSFredrik Holmqvist break;
3700174267aSFredrik Holmqvist
3710174267aSFredrik Holmqvist
3720174267aSFredrik Holmqvist case ACPI_RESOURCE_TYPE_START_DEPENDENT:
3730174267aSFredrik Holmqvist
3740174267aSFredrik Holmqvist /* Length can be 1 or 0 */
3750174267aSFredrik Holmqvist
3760174267aSFredrik Holmqvist if (Resource->Data.Irq.DescriptorLength == 0)
3770174267aSFredrik Holmqvist {
3780174267aSFredrik Holmqvist TotalSize--;
3790174267aSFredrik Holmqvist }
3800174267aSFredrik Holmqvist break;
3810174267aSFredrik Holmqvist
3820174267aSFredrik Holmqvist
3830174267aSFredrik Holmqvist case ACPI_RESOURCE_TYPE_VENDOR:
3840174267aSFredrik Holmqvist /*
3850174267aSFredrik Holmqvist * Vendor Defined Resource:
3860174267aSFredrik Holmqvist * For a Vendor Specific resource, if the Length is between 1 and 7
3870174267aSFredrik Holmqvist * it will be created as a Small Resource data type, otherwise it
3880174267aSFredrik Holmqvist * is a Large Resource data type.
3890174267aSFredrik Holmqvist */
3900174267aSFredrik Holmqvist if (Resource->Data.Vendor.ByteLength > 7)
3910174267aSFredrik Holmqvist {
3920174267aSFredrik Holmqvist /* Base size of a Large resource descriptor */
3930174267aSFredrik Holmqvist
3940174267aSFredrik Holmqvist TotalSize = sizeof (AML_RESOURCE_LARGE_HEADER);
3950174267aSFredrik Holmqvist }
3960174267aSFredrik Holmqvist
3970174267aSFredrik Holmqvist /* Add the size of the vendor-specific data */
3980174267aSFredrik Holmqvist
3990174267aSFredrik Holmqvist TotalSize = (ACPI_RS_LENGTH)
4000174267aSFredrik Holmqvist (TotalSize + Resource->Data.Vendor.ByteLength);
4010174267aSFredrik Holmqvist break;
4020174267aSFredrik Holmqvist
4030174267aSFredrik Holmqvist
4040174267aSFredrik Holmqvist case ACPI_RESOURCE_TYPE_END_TAG:
4050174267aSFredrik Holmqvist /*
4060174267aSFredrik Holmqvist * End Tag:
4070174267aSFredrik Holmqvist * We are done -- return the accumulated total size.
4080174267aSFredrik Holmqvist */
4090174267aSFredrik Holmqvist *SizeNeeded = AmlSizeNeeded + TotalSize;
4100174267aSFredrik Holmqvist
4110174267aSFredrik Holmqvist /* Normal exit */
4120174267aSFredrik Holmqvist
4130174267aSFredrik Holmqvist return_ACPI_STATUS (AE_OK);
4140174267aSFredrik Holmqvist
4150174267aSFredrik Holmqvist
4160174267aSFredrik Holmqvist case ACPI_RESOURCE_TYPE_ADDRESS16:
4170174267aSFredrik Holmqvist /*
4180174267aSFredrik Holmqvist * 16-Bit Address Resource:
4190174267aSFredrik Holmqvist * Add the size of the optional ResourceSource info
4200174267aSFredrik Holmqvist */
421b64e8511SFredrik Holmqvist TotalSize = (ACPI_RS_LENGTH) (TotalSize +
422b64e8511SFredrik Holmqvist AcpiRsStructOptionLength (
4230174267aSFredrik Holmqvist &Resource->Data.Address16.ResourceSource));
4240174267aSFredrik Holmqvist break;
4250174267aSFredrik Holmqvist
4260174267aSFredrik Holmqvist
4270174267aSFredrik Holmqvist case ACPI_RESOURCE_TYPE_ADDRESS32:
4280174267aSFredrik Holmqvist /*
4290174267aSFredrik Holmqvist * 32-Bit Address Resource:
4300174267aSFredrik Holmqvist * Add the size of the optional ResourceSource info
4310174267aSFredrik Holmqvist */
432b64e8511SFredrik Holmqvist TotalSize = (ACPI_RS_LENGTH) (TotalSize +
433b64e8511SFredrik Holmqvist AcpiRsStructOptionLength (
4340174267aSFredrik Holmqvist &Resource->Data.Address32.ResourceSource));
4350174267aSFredrik Holmqvist break;
4360174267aSFredrik Holmqvist
4370174267aSFredrik Holmqvist
4380174267aSFredrik Holmqvist case ACPI_RESOURCE_TYPE_ADDRESS64:
4390174267aSFredrik Holmqvist /*
4400174267aSFredrik Holmqvist * 64-Bit Address Resource:
4410174267aSFredrik Holmqvist * Add the size of the optional ResourceSource info
4420174267aSFredrik Holmqvist */
443b64e8511SFredrik Holmqvist TotalSize = (ACPI_RS_LENGTH) (TotalSize +
444b64e8511SFredrik Holmqvist AcpiRsStructOptionLength (
4450174267aSFredrik Holmqvist &Resource->Data.Address64.ResourceSource));
4460174267aSFredrik Holmqvist break;
4470174267aSFredrik Holmqvist
4480174267aSFredrik Holmqvist
4490174267aSFredrik Holmqvist case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
4500174267aSFredrik Holmqvist /*
4510174267aSFredrik Holmqvist * Extended IRQ Resource:
4520174267aSFredrik Holmqvist * Add the size of each additional optional interrupt beyond the
4530174267aSFredrik Holmqvist * required 1 (4 bytes for each UINT32 interrupt number)
4540174267aSFredrik Holmqvist */
455b64e8511SFredrik Holmqvist TotalSize = (ACPI_RS_LENGTH) (TotalSize +
4560174267aSFredrik Holmqvist ((Resource->Data.ExtendedIrq.InterruptCount - 1) * 4) +
4570174267aSFredrik Holmqvist
4580174267aSFredrik Holmqvist /* Add the size of the optional ResourceSource info */
4590174267aSFredrik Holmqvist
4600174267aSFredrik Holmqvist AcpiRsStructOptionLength (
4610174267aSFredrik Holmqvist &Resource->Data.ExtendedIrq.ResourceSource));
4620174267aSFredrik Holmqvist break;
4630174267aSFredrik Holmqvist
4640174267aSFredrik Holmqvist
4656822cda0SFredrik Holmqvist case ACPI_RESOURCE_TYPE_GPIO:
4666822cda0SFredrik Holmqvist
467b64e8511SFredrik Holmqvist TotalSize = (ACPI_RS_LENGTH) (TotalSize +
468b64e8511SFredrik Holmqvist (Resource->Data.Gpio.PinTableLength * 2) +
4696822cda0SFredrik Holmqvist Resource->Data.Gpio.ResourceSource.StringLength +
4706822cda0SFredrik Holmqvist Resource->Data.Gpio.VendorLength);
4716822cda0SFredrik Holmqvist
4726822cda0SFredrik Holmqvist break;
4736822cda0SFredrik Holmqvist
474ff2e2f81SFredrik Holmqvist case ACPI_RESOURCE_TYPE_PIN_FUNCTION:
475ff2e2f81SFredrik Holmqvist
476ff2e2f81SFredrik Holmqvist TotalSize = (ACPI_RS_LENGTH) (TotalSize +
477ff2e2f81SFredrik Holmqvist (Resource->Data.PinFunction.PinTableLength * 2) +
478ff2e2f81SFredrik Holmqvist Resource->Data.PinFunction.ResourceSource.StringLength +
479ff2e2f81SFredrik Holmqvist Resource->Data.PinFunction.VendorLength);
480ff2e2f81SFredrik Holmqvist
481ff2e2f81SFredrik Holmqvist break;
482ff2e2f81SFredrik Holmqvist
48315338de9SPulkoMandy case ACPI_RESOURCE_TYPE_CLOCK_INPUT:
48415338de9SPulkoMandy
48515338de9SPulkoMandy TotalSize = (ACPI_RS_LENGTH) (TotalSize +
48615338de9SPulkoMandy Resource->Data.ClockInput.ResourceSource.StringLength);
48715338de9SPulkoMandy
48815338de9SPulkoMandy break;
48915338de9SPulkoMandy
4906822cda0SFredrik Holmqvist
4916822cda0SFredrik Holmqvist case ACPI_RESOURCE_TYPE_SERIAL_BUS:
4926822cda0SFredrik Holmqvist
493b64e8511SFredrik Holmqvist TotalSize = AcpiGbl_AmlResourceSerialBusSizes [
494b64e8511SFredrik Holmqvist Resource->Data.CommonSerialBus.Type];
4956822cda0SFredrik Holmqvist
4966822cda0SFredrik Holmqvist TotalSize = (ACPI_RS_LENGTH) (TotalSize +
4976822cda0SFredrik Holmqvist Resource->Data.I2cSerialBus.ResourceSource.StringLength +
4986822cda0SFredrik Holmqvist Resource->Data.I2cSerialBus.VendorLength);
4996822cda0SFredrik Holmqvist
5006822cda0SFredrik Holmqvist break;
5016822cda0SFredrik Holmqvist
502ff2e2f81SFredrik Holmqvist case ACPI_RESOURCE_TYPE_PIN_CONFIG:
503ff2e2f81SFredrik Holmqvist
504ff2e2f81SFredrik Holmqvist TotalSize = (ACPI_RS_LENGTH) (TotalSize +
505ff2e2f81SFredrik Holmqvist (Resource->Data.PinConfig.PinTableLength * 2) +
506ff2e2f81SFredrik Holmqvist Resource->Data.PinConfig.ResourceSource.StringLength +
507ff2e2f81SFredrik Holmqvist Resource->Data.PinConfig.VendorLength);
508ff2e2f81SFredrik Holmqvist
509ff2e2f81SFredrik Holmqvist break;
510ff2e2f81SFredrik Holmqvist
511ff2e2f81SFredrik Holmqvist case ACPI_RESOURCE_TYPE_PIN_GROUP:
512ff2e2f81SFredrik Holmqvist
513ff2e2f81SFredrik Holmqvist TotalSize = (ACPI_RS_LENGTH) (TotalSize +
514ff2e2f81SFredrik Holmqvist (Resource->Data.PinGroup.PinTableLength * 2) +
515ff2e2f81SFredrik Holmqvist Resource->Data.PinGroup.ResourceLabel.StringLength +
516ff2e2f81SFredrik Holmqvist Resource->Data.PinGroup.VendorLength);
517ff2e2f81SFredrik Holmqvist
518ff2e2f81SFredrik Holmqvist break;
519ff2e2f81SFredrik Holmqvist
520ff2e2f81SFredrik Holmqvist case ACPI_RESOURCE_TYPE_PIN_GROUP_FUNCTION:
521ff2e2f81SFredrik Holmqvist
522ff2e2f81SFredrik Holmqvist TotalSize = (ACPI_RS_LENGTH) (TotalSize +
523ff2e2f81SFredrik Holmqvist Resource->Data.PinGroupFunction.ResourceSource.StringLength +
524ff2e2f81SFredrik Holmqvist Resource->Data.PinGroupFunction.ResourceSourceLabel.StringLength +
525ff2e2f81SFredrik Holmqvist Resource->Data.PinGroupFunction.VendorLength);
526ff2e2f81SFredrik Holmqvist
527ff2e2f81SFredrik Holmqvist break;
528ff2e2f81SFredrik Holmqvist
529ff2e2f81SFredrik Holmqvist case ACPI_RESOURCE_TYPE_PIN_GROUP_CONFIG:
530ff2e2f81SFredrik Holmqvist
531ff2e2f81SFredrik Holmqvist TotalSize = (ACPI_RS_LENGTH) (TotalSize +
532ff2e2f81SFredrik Holmqvist Resource->Data.PinGroupConfig.ResourceSource.StringLength +
533ff2e2f81SFredrik Holmqvist Resource->Data.PinGroupConfig.ResourceSourceLabel.StringLength +
534ff2e2f81SFredrik Holmqvist Resource->Data.PinGroupConfig.VendorLength);
535ff2e2f81SFredrik Holmqvist
536ff2e2f81SFredrik Holmqvist break;
537ff2e2f81SFredrik Holmqvist
5380174267aSFredrik Holmqvist default:
539c70258b7SJérôme Duval
5400174267aSFredrik Holmqvist break;
5410174267aSFredrik Holmqvist }
5420174267aSFredrik Holmqvist
5430174267aSFredrik Holmqvist /* Update the total */
5440174267aSFredrik Holmqvist
5450174267aSFredrik Holmqvist AmlSizeNeeded += TotalSize;
5460174267aSFredrik Holmqvist
5470174267aSFredrik Holmqvist /* Point to the next object */
5480174267aSFredrik Holmqvist
5490174267aSFredrik Holmqvist Resource = ACPI_ADD_PTR (ACPI_RESOURCE, Resource, Resource->Length);
5500174267aSFredrik Holmqvist }
5510174267aSFredrik Holmqvist
5520174267aSFredrik Holmqvist /* Did not find an EndTag resource descriptor */
5530174267aSFredrik Holmqvist
5540174267aSFredrik Holmqvist return_ACPI_STATUS (AE_AML_NO_RESOURCE_END_TAG);
5550174267aSFredrik Holmqvist }
5560174267aSFredrik Holmqvist
5570174267aSFredrik Holmqvist
5580174267aSFredrik Holmqvist /*******************************************************************************
5590174267aSFredrik Holmqvist *
5600174267aSFredrik Holmqvist * FUNCTION: AcpiRsGetListLength
5610174267aSFredrik Holmqvist *
5620174267aSFredrik Holmqvist * PARAMETERS: AmlBuffer - Pointer to the resource byte stream
5630174267aSFredrik Holmqvist * AmlBufferLength - Size of AmlBuffer
5640174267aSFredrik Holmqvist * SizeNeeded - Where the size needed is returned
5650174267aSFredrik Holmqvist *
5660174267aSFredrik Holmqvist * RETURN: Status
5670174267aSFredrik Holmqvist *
5680174267aSFredrik Holmqvist * DESCRIPTION: Takes an external resource byte stream and calculates the size
5690174267aSFredrik Holmqvist * buffer needed to hold the corresponding internal resource
5700174267aSFredrik Holmqvist * descriptor linked list.
5710174267aSFredrik Holmqvist *
5720174267aSFredrik Holmqvist ******************************************************************************/
5730174267aSFredrik Holmqvist
5740174267aSFredrik Holmqvist ACPI_STATUS
AcpiRsGetListLength(UINT8 * AmlBuffer,UINT32 AmlBufferLength,ACPI_SIZE * SizeNeeded)5750174267aSFredrik Holmqvist AcpiRsGetListLength (
5760174267aSFredrik Holmqvist UINT8 *AmlBuffer,
5770174267aSFredrik Holmqvist UINT32 AmlBufferLength,
5780174267aSFredrik Holmqvist ACPI_SIZE *SizeNeeded)
5790174267aSFredrik Holmqvist {
5800174267aSFredrik Holmqvist ACPI_STATUS Status;
5810174267aSFredrik Holmqvist UINT8 *EndAml;
5820174267aSFredrik Holmqvist UINT8 *Buffer;
5830174267aSFredrik Holmqvist UINT32 BufferSize;
5840174267aSFredrik Holmqvist UINT16 Temp16;
5850174267aSFredrik Holmqvist UINT16 ResourceLength;
5860174267aSFredrik Holmqvist UINT32 ExtraStructBytes;
5870174267aSFredrik Holmqvist UINT8 ResourceIndex;
5880174267aSFredrik Holmqvist UINT8 MinimumAmlResourceLength;
5896822cda0SFredrik Holmqvist AML_RESOURCE *AmlResource;
5900174267aSFredrik Holmqvist
5910174267aSFredrik Holmqvist
5920174267aSFredrik Holmqvist ACPI_FUNCTION_TRACE (RsGetListLength);
5930174267aSFredrik Holmqvist
5940174267aSFredrik Holmqvist
5956822cda0SFredrik Holmqvist *SizeNeeded = ACPI_RS_SIZE_MIN; /* Minimum size is one EndTag */
5960174267aSFredrik Holmqvist EndAml = AmlBuffer + AmlBufferLength;
5970174267aSFredrik Holmqvist
5980174267aSFredrik Holmqvist /* Walk the list of AML resource descriptors */
5990174267aSFredrik Holmqvist
6000174267aSFredrik Holmqvist while (AmlBuffer < EndAml)
6010174267aSFredrik Holmqvist {
6020174267aSFredrik Holmqvist /* Validate the Resource Type and Resource Length */
6030174267aSFredrik Holmqvist
604c70258b7SJérôme Duval Status = AcpiUtValidateResource (NULL, AmlBuffer, &ResourceIndex);
6050174267aSFredrik Holmqvist if (ACPI_FAILURE (Status))
6060174267aSFredrik Holmqvist {
6076822cda0SFredrik Holmqvist /*
6086822cda0SFredrik Holmqvist * Exit on failure. Cannot continue because the descriptor length
6096822cda0SFredrik Holmqvist * may be bogus also.
6106822cda0SFredrik Holmqvist */
6110174267aSFredrik Holmqvist return_ACPI_STATUS (Status);
6120174267aSFredrik Holmqvist }
6130174267aSFredrik Holmqvist
6146822cda0SFredrik Holmqvist AmlResource = (void *) AmlBuffer;
6156822cda0SFredrik Holmqvist
6160174267aSFredrik Holmqvist /* Get the resource length and base (minimum) AML size */
6170174267aSFredrik Holmqvist
6180174267aSFredrik Holmqvist ResourceLength = AcpiUtGetResourceLength (AmlBuffer);
6190174267aSFredrik Holmqvist MinimumAmlResourceLength = AcpiGbl_ResourceAmlSizes[ResourceIndex];
6200174267aSFredrik Holmqvist
6210174267aSFredrik Holmqvist /*
6220174267aSFredrik Holmqvist * Augment the size for descriptors with optional
6230174267aSFredrik Holmqvist * and/or variable length fields
6240174267aSFredrik Holmqvist */
6250174267aSFredrik Holmqvist ExtraStructBytes = 0;
6260174267aSFredrik Holmqvist Buffer = AmlBuffer + AcpiUtGetResourceHeaderLength (AmlBuffer);
6270174267aSFredrik Holmqvist
6280174267aSFredrik Holmqvist switch (AcpiUtGetResourceType (AmlBuffer))
6290174267aSFredrik Holmqvist {
6300174267aSFredrik Holmqvist case ACPI_RESOURCE_NAME_IRQ:
6310174267aSFredrik Holmqvist /*
6320174267aSFredrik Holmqvist * IRQ Resource:
6330174267aSFredrik Holmqvist * Get the number of bits set in the 16-bit IRQ mask
6340174267aSFredrik Holmqvist */
6350174267aSFredrik Holmqvist ACPI_MOVE_16_TO_16 (&Temp16, Buffer);
6360174267aSFredrik Holmqvist ExtraStructBytes = AcpiRsCountSetBits (Temp16);
6370174267aSFredrik Holmqvist break;
6380174267aSFredrik Holmqvist
6390174267aSFredrik Holmqvist
6400174267aSFredrik Holmqvist case ACPI_RESOURCE_NAME_DMA:
6410174267aSFredrik Holmqvist /*
6420174267aSFredrik Holmqvist * DMA Resource:
6430174267aSFredrik Holmqvist * Get the number of bits set in the 8-bit DMA mask
6440174267aSFredrik Holmqvist */
6450174267aSFredrik Holmqvist ExtraStructBytes = AcpiRsCountSetBits (*Buffer);
6460174267aSFredrik Holmqvist break;
6470174267aSFredrik Holmqvist
6480174267aSFredrik Holmqvist
6490174267aSFredrik Holmqvist case ACPI_RESOURCE_NAME_VENDOR_SMALL:
6500174267aSFredrik Holmqvist case ACPI_RESOURCE_NAME_VENDOR_LARGE:
6510174267aSFredrik Holmqvist /*
6520174267aSFredrik Holmqvist * Vendor Resource:
6530174267aSFredrik Holmqvist * Get the number of vendor data bytes
6540174267aSFredrik Holmqvist */
6550174267aSFredrik Holmqvist ExtraStructBytes = ResourceLength;
6569b0d045cSFredrik Holmqvist
6579b0d045cSFredrik Holmqvist /*
6589b0d045cSFredrik Holmqvist * There is already one byte included in the minimum
6599b0d045cSFredrik Holmqvist * descriptor size. If there are extra struct bytes,
6609b0d045cSFredrik Holmqvist * subtract one from the count.
6619b0d045cSFredrik Holmqvist */
6629b0d045cSFredrik Holmqvist if (ExtraStructBytes)
6639b0d045cSFredrik Holmqvist {
6649b0d045cSFredrik Holmqvist ExtraStructBytes--;
6659b0d045cSFredrik Holmqvist }
6660174267aSFredrik Holmqvist break;
6670174267aSFredrik Holmqvist
6680174267aSFredrik Holmqvist
6690174267aSFredrik Holmqvist case ACPI_RESOURCE_NAME_END_TAG:
6700174267aSFredrik Holmqvist /*
6716822cda0SFredrik Holmqvist * End Tag: This is the normal exit
6720174267aSFredrik Holmqvist */
6730174267aSFredrik Holmqvist return_ACPI_STATUS (AE_OK);
6740174267aSFredrik Holmqvist
6750174267aSFredrik Holmqvist
6760174267aSFredrik Holmqvist case ACPI_RESOURCE_NAME_ADDRESS32:
6770174267aSFredrik Holmqvist case ACPI_RESOURCE_NAME_ADDRESS16:
6780174267aSFredrik Holmqvist case ACPI_RESOURCE_NAME_ADDRESS64:
6790174267aSFredrik Holmqvist /*
6800174267aSFredrik Holmqvist * Address Resource:
6810174267aSFredrik Holmqvist * Add the size of the optional ResourceSource
6820174267aSFredrik Holmqvist */
6830174267aSFredrik Holmqvist ExtraStructBytes = AcpiRsStreamOptionLength (
6840174267aSFredrik Holmqvist ResourceLength, MinimumAmlResourceLength);
6850174267aSFredrik Holmqvist break;
6860174267aSFredrik Holmqvist
6870174267aSFredrik Holmqvist
6880174267aSFredrik Holmqvist case ACPI_RESOURCE_NAME_EXTENDED_IRQ:
6890174267aSFredrik Holmqvist /*
6900174267aSFredrik Holmqvist * Extended IRQ Resource:
6910174267aSFredrik Holmqvist * Using the InterruptTableLength, add 4 bytes for each additional
6920174267aSFredrik Holmqvist * interrupt. Note: at least one interrupt is required and is
6930174267aSFredrik Holmqvist * included in the minimum descriptor size (reason for the -1)
6940174267aSFredrik Holmqvist */
6950174267aSFredrik Holmqvist ExtraStructBytes = (Buffer[1] - 1) * sizeof (UINT32);
6960174267aSFredrik Holmqvist
6970174267aSFredrik Holmqvist /* Add the size of the optional ResourceSource */
6980174267aSFredrik Holmqvist
6990174267aSFredrik Holmqvist ExtraStructBytes += AcpiRsStreamOptionLength (
7000174267aSFredrik Holmqvist ResourceLength - ExtraStructBytes, MinimumAmlResourceLength);
7010174267aSFredrik Holmqvist break;
7020174267aSFredrik Holmqvist
7036822cda0SFredrik Holmqvist case ACPI_RESOURCE_NAME_GPIO:
7046822cda0SFredrik Holmqvist
7056822cda0SFredrik Holmqvist /* Vendor data is optional */
7066822cda0SFredrik Holmqvist
7076822cda0SFredrik Holmqvist if (AmlResource->Gpio.VendorLength)
7086822cda0SFredrik Holmqvist {
709b64e8511SFredrik Holmqvist ExtraStructBytes +=
710b64e8511SFredrik Holmqvist AmlResource->Gpio.VendorOffset -
711b64e8511SFredrik Holmqvist AmlResource->Gpio.PinTableOffset +
712b64e8511SFredrik Holmqvist AmlResource->Gpio.VendorLength;
7136822cda0SFredrik Holmqvist }
7146822cda0SFredrik Holmqvist else
7156822cda0SFredrik Holmqvist {
716b64e8511SFredrik Holmqvist ExtraStructBytes +=
717b64e8511SFredrik Holmqvist AmlResource->LargeHeader.ResourceLength +
7186822cda0SFredrik Holmqvist sizeof (AML_RESOURCE_LARGE_HEADER) -
7196822cda0SFredrik Holmqvist AmlResource->Gpio.PinTableOffset;
7206822cda0SFredrik Holmqvist }
7216822cda0SFredrik Holmqvist break;
7226822cda0SFredrik Holmqvist
723ff2e2f81SFredrik Holmqvist case ACPI_RESOURCE_NAME_PIN_FUNCTION:
724ff2e2f81SFredrik Holmqvist
725ff2e2f81SFredrik Holmqvist /* Vendor data is optional */
726ff2e2f81SFredrik Holmqvist
727ff2e2f81SFredrik Holmqvist if (AmlResource->PinFunction.VendorLength)
728ff2e2f81SFredrik Holmqvist {
729ff2e2f81SFredrik Holmqvist ExtraStructBytes +=
730ff2e2f81SFredrik Holmqvist AmlResource->PinFunction.VendorOffset -
731ff2e2f81SFredrik Holmqvist AmlResource->PinFunction.PinTableOffset +
732ff2e2f81SFredrik Holmqvist AmlResource->PinFunction.VendorLength;
733ff2e2f81SFredrik Holmqvist }
734ff2e2f81SFredrik Holmqvist else
735ff2e2f81SFredrik Holmqvist {
736ff2e2f81SFredrik Holmqvist ExtraStructBytes +=
737ff2e2f81SFredrik Holmqvist AmlResource->LargeHeader.ResourceLength +
738ff2e2f81SFredrik Holmqvist sizeof (AML_RESOURCE_LARGE_HEADER) -
739ff2e2f81SFredrik Holmqvist AmlResource->PinFunction.PinTableOffset;
740ff2e2f81SFredrik Holmqvist }
741ff2e2f81SFredrik Holmqvist break;
742ff2e2f81SFredrik Holmqvist
74315338de9SPulkoMandy case ACPI_RESOURCE_NAME_SERIAL_BUS: {
74415338de9SPulkoMandy /* Avoid undefined behavior: member access within misaligned address */
74515338de9SPulkoMandy
74615338de9SPulkoMandy AML_RESOURCE_COMMON_SERIALBUS CommonSerialBus;
74715338de9SPulkoMandy memcpy(&CommonSerialBus, AmlResource, sizeof(CommonSerialBus));
7486822cda0SFredrik Holmqvist
7496822cda0SFredrik Holmqvist MinimumAmlResourceLength = AcpiGbl_ResourceAmlSerialBusSizes[
75015338de9SPulkoMandy CommonSerialBus.Type];
751b64e8511SFredrik Holmqvist ExtraStructBytes +=
75215338de9SPulkoMandy CommonSerialBus.ResourceLength -
7536822cda0SFredrik Holmqvist MinimumAmlResourceLength;
7546822cda0SFredrik Holmqvist break;
75515338de9SPulkoMandy }
7560174267aSFredrik Holmqvist
757ff2e2f81SFredrik Holmqvist case ACPI_RESOURCE_NAME_PIN_CONFIG:
758ff2e2f81SFredrik Holmqvist
759ff2e2f81SFredrik Holmqvist /* Vendor data is optional */
760ff2e2f81SFredrik Holmqvist
761ff2e2f81SFredrik Holmqvist if (AmlResource->PinConfig.VendorLength)
762ff2e2f81SFredrik Holmqvist {
763ff2e2f81SFredrik Holmqvist ExtraStructBytes +=
764ff2e2f81SFredrik Holmqvist AmlResource->PinConfig.VendorOffset -
765ff2e2f81SFredrik Holmqvist AmlResource->PinConfig.PinTableOffset +
766ff2e2f81SFredrik Holmqvist AmlResource->PinConfig.VendorLength;
767ff2e2f81SFredrik Holmqvist }
768ff2e2f81SFredrik Holmqvist else
769ff2e2f81SFredrik Holmqvist {
770ff2e2f81SFredrik Holmqvist ExtraStructBytes +=
771ff2e2f81SFredrik Holmqvist AmlResource->LargeHeader.ResourceLength +
772ff2e2f81SFredrik Holmqvist sizeof (AML_RESOURCE_LARGE_HEADER) -
773ff2e2f81SFredrik Holmqvist AmlResource->PinConfig.PinTableOffset;
774ff2e2f81SFredrik Holmqvist }
775ff2e2f81SFredrik Holmqvist break;
776ff2e2f81SFredrik Holmqvist
777ff2e2f81SFredrik Holmqvist case ACPI_RESOURCE_NAME_PIN_GROUP:
778ff2e2f81SFredrik Holmqvist
779ff2e2f81SFredrik Holmqvist ExtraStructBytes +=
780ff2e2f81SFredrik Holmqvist AmlResource->PinGroup.VendorOffset -
781ff2e2f81SFredrik Holmqvist AmlResource->PinGroup.PinTableOffset +
782ff2e2f81SFredrik Holmqvist AmlResource->PinGroup.VendorLength;
783ff2e2f81SFredrik Holmqvist
784ff2e2f81SFredrik Holmqvist break;
785ff2e2f81SFredrik Holmqvist
786ff2e2f81SFredrik Holmqvist case ACPI_RESOURCE_NAME_PIN_GROUP_FUNCTION:
787ff2e2f81SFredrik Holmqvist
788ff2e2f81SFredrik Holmqvist ExtraStructBytes +=
789ff2e2f81SFredrik Holmqvist AmlResource->PinGroupFunction.VendorOffset -
790ff2e2f81SFredrik Holmqvist AmlResource->PinGroupFunction.ResSourceOffset +
791ff2e2f81SFredrik Holmqvist AmlResource->PinGroupFunction.VendorLength;
792ff2e2f81SFredrik Holmqvist
793ff2e2f81SFredrik Holmqvist break;
794ff2e2f81SFredrik Holmqvist
795ff2e2f81SFredrik Holmqvist case ACPI_RESOURCE_NAME_PIN_GROUP_CONFIG:
796ff2e2f81SFredrik Holmqvist
797ff2e2f81SFredrik Holmqvist ExtraStructBytes +=
798ff2e2f81SFredrik Holmqvist AmlResource->PinGroupConfig.VendorOffset -
799ff2e2f81SFredrik Holmqvist AmlResource->PinGroupConfig.ResSourceOffset +
800ff2e2f81SFredrik Holmqvist AmlResource->PinGroupConfig.VendorLength;
801ff2e2f81SFredrik Holmqvist
802ff2e2f81SFredrik Holmqvist break;
803ff2e2f81SFredrik Holmqvist
80415338de9SPulkoMandy case ACPI_RESOURCE_NAME_CLOCK_INPUT:
80515338de9SPulkoMandy ExtraStructBytes = AcpiRsStreamOptionLength (
80615338de9SPulkoMandy ResourceLength, MinimumAmlResourceLength);
80715338de9SPulkoMandy
80815338de9SPulkoMandy break;
80915338de9SPulkoMandy
8100174267aSFredrik Holmqvist default:
811c70258b7SJérôme Duval
8120174267aSFredrik Holmqvist break;
8130174267aSFredrik Holmqvist }
8140174267aSFredrik Holmqvist
8150174267aSFredrik Holmqvist /*
8160174267aSFredrik Holmqvist * Update the required buffer size for the internal descriptor structs
8170174267aSFredrik Holmqvist *
8180174267aSFredrik Holmqvist * Important: Round the size up for the appropriate alignment. This
8190174267aSFredrik Holmqvist * is a requirement on IA64.
8200174267aSFredrik Holmqvist */
821b64e8511SFredrik Holmqvist if (AcpiUtGetResourceType (AmlBuffer) ==
822b64e8511SFredrik Holmqvist ACPI_RESOURCE_NAME_SERIAL_BUS)
8236822cda0SFredrik Holmqvist {
82415338de9SPulkoMandy /* Avoid undefined behavior: member access within misaligned address */
82515338de9SPulkoMandy
82615338de9SPulkoMandy AML_RESOURCE_COMMON_SERIALBUS CommonSerialBus;
82715338de9SPulkoMandy memcpy(&CommonSerialBus, AmlResource, sizeof(CommonSerialBus));
82815338de9SPulkoMandy
8296822cda0SFredrik Holmqvist BufferSize = AcpiGbl_ResourceStructSerialBusSizes[
83015338de9SPulkoMandy CommonSerialBus.Type] + ExtraStructBytes;
8316822cda0SFredrik Holmqvist }
8326822cda0SFredrik Holmqvist else
8336822cda0SFredrik Holmqvist {
8340174267aSFredrik Holmqvist BufferSize = AcpiGbl_ResourceStructSizes[ResourceIndex] +
8350174267aSFredrik Holmqvist ExtraStructBytes;
8366822cda0SFredrik Holmqvist }
837599289f2SAugustin Cavalier
838b64e8511SFredrik Holmqvist BufferSize = (UINT32) ACPI_ROUND_UP_TO_NATIVE_WORD (BufferSize);
8390174267aSFredrik Holmqvist *SizeNeeded += BufferSize;
8400174267aSFredrik Holmqvist
8410174267aSFredrik Holmqvist ACPI_DEBUG_PRINT ((ACPI_DB_RESOURCES,
84215338de9SPulkoMandy "Type %.2X, AmlLength %.2X InternalLength %.2X%8X\n",
8430174267aSFredrik Holmqvist AcpiUtGetResourceType (AmlBuffer),
84415338de9SPulkoMandy AcpiUtGetDescriptorLength (AmlBuffer), ACPI_FORMAT_UINT64(*SizeNeeded)));
8450174267aSFredrik Holmqvist
8460174267aSFredrik Holmqvist /*
8470174267aSFredrik Holmqvist * Point to the next resource within the AML stream using the length
8480174267aSFredrik Holmqvist * contained in the resource descriptor header
8490174267aSFredrik Holmqvist */
8500174267aSFredrik Holmqvist AmlBuffer += AcpiUtGetDescriptorLength (AmlBuffer);
8510174267aSFredrik Holmqvist }
8520174267aSFredrik Holmqvist
8530174267aSFredrik Holmqvist /* Did not find an EndTag resource descriptor */
8540174267aSFredrik Holmqvist
8550174267aSFredrik Holmqvist return_ACPI_STATUS (AE_AML_NO_RESOURCE_END_TAG);
8560174267aSFredrik Holmqvist }
8570174267aSFredrik Holmqvist
8580174267aSFredrik Holmqvist
8590174267aSFredrik Holmqvist /*******************************************************************************
8600174267aSFredrik Holmqvist *
8610174267aSFredrik Holmqvist * FUNCTION: AcpiRsGetPciRoutingTableLength
8620174267aSFredrik Holmqvist *
8630174267aSFredrik Holmqvist * PARAMETERS: PackageObject - Pointer to the package object
8640174267aSFredrik Holmqvist * BufferSizeNeeded - UINT32 pointer of the size buffer
8650174267aSFredrik Holmqvist * needed to properly return the
8660174267aSFredrik Holmqvist * parsed data
8670174267aSFredrik Holmqvist *
8680174267aSFredrik Holmqvist * RETURN: Status
8690174267aSFredrik Holmqvist *
8700174267aSFredrik Holmqvist * DESCRIPTION: Given a package representing a PCI routing table, this
8710174267aSFredrik Holmqvist * calculates the size of the corresponding linked list of
8720174267aSFredrik Holmqvist * descriptions.
8730174267aSFredrik Holmqvist *
8740174267aSFredrik Holmqvist ******************************************************************************/
8750174267aSFredrik Holmqvist
8760174267aSFredrik Holmqvist ACPI_STATUS
AcpiRsGetPciRoutingTableLength(ACPI_OPERAND_OBJECT * PackageObject,ACPI_SIZE * BufferSizeNeeded)8770174267aSFredrik Holmqvist AcpiRsGetPciRoutingTableLength (
8780174267aSFredrik Holmqvist ACPI_OPERAND_OBJECT *PackageObject,
8790174267aSFredrik Holmqvist ACPI_SIZE *BufferSizeNeeded)
8800174267aSFredrik Holmqvist {
8810174267aSFredrik Holmqvist UINT32 NumberOfElements;
8820174267aSFredrik Holmqvist ACPI_SIZE TempSizeNeeded = 0;
8830174267aSFredrik Holmqvist ACPI_OPERAND_OBJECT **TopObjectList;
8840174267aSFredrik Holmqvist UINT32 Index;
8850174267aSFredrik Holmqvist ACPI_OPERAND_OBJECT *PackageElement;
8860174267aSFredrik Holmqvist ACPI_OPERAND_OBJECT **SubObjectList;
8870174267aSFredrik Holmqvist BOOLEAN NameFound;
8880174267aSFredrik Holmqvist UINT32 TableIndex;
8890174267aSFredrik Holmqvist
8900174267aSFredrik Holmqvist
8910174267aSFredrik Holmqvist ACPI_FUNCTION_TRACE (RsGetPciRoutingTableLength);
8920174267aSFredrik Holmqvist
8930174267aSFredrik Holmqvist
8940174267aSFredrik Holmqvist NumberOfElements = PackageObject->Package.Count;
8950174267aSFredrik Holmqvist
8960174267aSFredrik Holmqvist /*
8970174267aSFredrik Holmqvist * Calculate the size of the return buffer.
8980174267aSFredrik Holmqvist * The base size is the number of elements * the sizes of the
8990174267aSFredrik Holmqvist * structures. Additional space for the strings is added below.
9000174267aSFredrik Holmqvist * The minus one is to subtract the size of the UINT8 Source[1]
9010174267aSFredrik Holmqvist * member because it is added below.
9020174267aSFredrik Holmqvist *
9030174267aSFredrik Holmqvist * But each PRT_ENTRY structure has a pointer to a string and
9040174267aSFredrik Holmqvist * the size of that string must be found.
9050174267aSFredrik Holmqvist */
9060174267aSFredrik Holmqvist TopObjectList = PackageObject->Package.Elements;
9070174267aSFredrik Holmqvist
9080174267aSFredrik Holmqvist for (Index = 0; Index < NumberOfElements; Index++)
9090174267aSFredrik Holmqvist {
910ad5bbfb8SFredrik Holmqvist /* Dereference the subpackage */
9110174267aSFredrik Holmqvist
9120174267aSFredrik Holmqvist PackageElement = *TopObjectList;
9130174267aSFredrik Holmqvist
9140174267aSFredrik Holmqvist /* We must have a valid Package object */
9150174267aSFredrik Holmqvist
9160174267aSFredrik Holmqvist if (!PackageElement ||
9170174267aSFredrik Holmqvist (PackageElement->Common.Type != ACPI_TYPE_PACKAGE))
9180174267aSFredrik Holmqvist {
9190174267aSFredrik Holmqvist return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
9200174267aSFredrik Holmqvist }
9210174267aSFredrik Holmqvist
9220174267aSFredrik Holmqvist /*
9230174267aSFredrik Holmqvist * The SubObjectList will now point to an array of the
9240174267aSFredrik Holmqvist * four IRQ elements: Address, Pin, Source and SourceIndex
9250174267aSFredrik Holmqvist */
9260174267aSFredrik Holmqvist SubObjectList = PackageElement->Package.Elements;
9270174267aSFredrik Holmqvist
9280174267aSFredrik Holmqvist /* Scan the IrqTableElements for the Source Name String */
9290174267aSFredrik Holmqvist
9300174267aSFredrik Holmqvist NameFound = FALSE;
9310174267aSFredrik Holmqvist
932c70258b7SJérôme Duval for (TableIndex = 0;
933c70258b7SJérôme Duval TableIndex < PackageElement->Package.Count && !NameFound;
934c70258b7SJérôme Duval TableIndex++)
9350174267aSFredrik Holmqvist {
9360174267aSFredrik Holmqvist if (*SubObjectList && /* Null object allowed */
9370174267aSFredrik Holmqvist
9380174267aSFredrik Holmqvist ((ACPI_TYPE_STRING ==
9390174267aSFredrik Holmqvist (*SubObjectList)->Common.Type) ||
9400174267aSFredrik Holmqvist
9410174267aSFredrik Holmqvist ((ACPI_TYPE_LOCAL_REFERENCE ==
9420174267aSFredrik Holmqvist (*SubObjectList)->Common.Type) &&
9430174267aSFredrik Holmqvist
9440174267aSFredrik Holmqvist ((*SubObjectList)->Reference.Class ==
9450174267aSFredrik Holmqvist ACPI_REFCLASS_NAME))))
9460174267aSFredrik Holmqvist {
9470174267aSFredrik Holmqvist NameFound = TRUE;
9480174267aSFredrik Holmqvist }
9490174267aSFredrik Holmqvist else
9500174267aSFredrik Holmqvist {
9510174267aSFredrik Holmqvist /* Look at the next element */
9520174267aSFredrik Holmqvist
9530174267aSFredrik Holmqvist SubObjectList++;
9540174267aSFredrik Holmqvist }
9550174267aSFredrik Holmqvist }
9560174267aSFredrik Holmqvist
9570174267aSFredrik Holmqvist TempSizeNeeded += (sizeof (ACPI_PCI_ROUTING_TABLE) - 4);
9580174267aSFredrik Holmqvist
9590174267aSFredrik Holmqvist /* Was a String type found? */
9600174267aSFredrik Holmqvist
9610174267aSFredrik Holmqvist if (NameFound)
9620174267aSFredrik Holmqvist {
9630174267aSFredrik Holmqvist if ((*SubObjectList)->Common.Type == ACPI_TYPE_STRING)
9640174267aSFredrik Holmqvist {
9650174267aSFredrik Holmqvist /*
9660174267aSFredrik Holmqvist * The length String.Length field does not include the
9670174267aSFredrik Holmqvist * terminating NULL, add 1
9680174267aSFredrik Holmqvist */
9690174267aSFredrik Holmqvist TempSizeNeeded += ((ACPI_SIZE)
9700174267aSFredrik Holmqvist (*SubObjectList)->String.Length + 1);
9710174267aSFredrik Holmqvist }
9720174267aSFredrik Holmqvist else
9730174267aSFredrik Holmqvist {
9740174267aSFredrik Holmqvist TempSizeNeeded += AcpiNsGetPathnameLength (
9750174267aSFredrik Holmqvist (*SubObjectList)->Reference.Node);
9760174267aSFredrik Holmqvist }
9770174267aSFredrik Holmqvist }
9780174267aSFredrik Holmqvist else
9790174267aSFredrik Holmqvist {
9800174267aSFredrik Holmqvist /*
9810174267aSFredrik Holmqvist * If no name was found, then this is a NULL, which is
9820174267aSFredrik Holmqvist * translated as a UINT32 zero.
9830174267aSFredrik Holmqvist */
9840174267aSFredrik Holmqvist TempSizeNeeded += sizeof (UINT32);
9850174267aSFredrik Holmqvist }
9860174267aSFredrik Holmqvist
9870174267aSFredrik Holmqvist /* Round up the size since each element must be aligned */
9880174267aSFredrik Holmqvist
9890174267aSFredrik Holmqvist TempSizeNeeded = ACPI_ROUND_UP_TO_64BIT (TempSizeNeeded);
9900174267aSFredrik Holmqvist
9910174267aSFredrik Holmqvist /* Point to the next ACPI_OPERAND_OBJECT */
9920174267aSFredrik Holmqvist
9930174267aSFredrik Holmqvist TopObjectList++;
9940174267aSFredrik Holmqvist }
9950174267aSFredrik Holmqvist
9960174267aSFredrik Holmqvist /*
9970174267aSFredrik Holmqvist * Add an extra element to the end of the list, essentially a
9980174267aSFredrik Holmqvist * NULL terminator
9990174267aSFredrik Holmqvist */
10000174267aSFredrik Holmqvist *BufferSizeNeeded = TempSizeNeeded + sizeof (ACPI_PCI_ROUTING_TABLE);
10010174267aSFredrik Holmqvist return_ACPI_STATUS (AE_OK);
10020174267aSFredrik Holmqvist }
1003