17c478bd9Sstevel@tonic-gate /*******************************************************************************
27c478bd9Sstevel@tonic-gate  *
37c478bd9Sstevel@tonic-gate  * Module Name: rsutils - Utilities for the resource manager
47c478bd9Sstevel@tonic-gate  *
57c478bd9Sstevel@tonic-gate  ******************************************************************************/
67c478bd9Sstevel@tonic-gate 
7*35786f68SRobert Mustacchi /******************************************************************************
8*35786f68SRobert Mustacchi  *
9*35786f68SRobert Mustacchi  * 1. Copyright Notice
10*35786f68SRobert Mustacchi  *
11*35786f68SRobert Mustacchi  * Some or all of this work - Copyright (c) 1999 - 2018, Intel Corp.
127c478bd9Sstevel@tonic-gate  * All rights reserved.
137c478bd9Sstevel@tonic-gate  *
14*35786f68SRobert Mustacchi  * 2. License
15*35786f68SRobert Mustacchi  *
16*35786f68SRobert Mustacchi  * 2.1. This is your license from Intel Corp. under its intellectual property
17*35786f68SRobert Mustacchi  * rights. You may have additional license terms from the party that provided
18*35786f68SRobert Mustacchi  * you this software, covering your right to use that party's intellectual
19*35786f68SRobert Mustacchi  * property rights.
20*35786f68SRobert Mustacchi  *
21*35786f68SRobert Mustacchi  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22*35786f68SRobert Mustacchi  * copy of the source code appearing in this file ("Covered Code") an
23*35786f68SRobert Mustacchi  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24*35786f68SRobert Mustacchi  * base code distributed originally by Intel ("Original Intel Code") to copy,
25*35786f68SRobert Mustacchi  * make derivatives, distribute, use and display any portion of the Covered
26*35786f68SRobert Mustacchi  * Code in any form, with the right to sublicense such rights; and
27*35786f68SRobert Mustacchi  *
28*35786f68SRobert Mustacchi  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29*35786f68SRobert Mustacchi  * license (with the right to sublicense), under only those claims of Intel
30*35786f68SRobert Mustacchi  * patents that are infringed by the Original Intel Code, to make, use, sell,
31*35786f68SRobert Mustacchi  * offer to sell, and import the Covered Code and derivative works thereof
32*35786f68SRobert Mustacchi  * solely to the minimum extent necessary to exercise the above copyright
33*35786f68SRobert Mustacchi  * license, and in no event shall the patent license extend to any additions
34*35786f68SRobert Mustacchi  * to or modifications of the Original Intel Code. No other license or right
35*35786f68SRobert Mustacchi  * is granted directly or by implication, estoppel or otherwise;
36*35786f68SRobert Mustacchi  *
37*35786f68SRobert Mustacchi  * The above copyright and patent license is granted only if the following
38*35786f68SRobert Mustacchi  * conditions are met:
39*35786f68SRobert Mustacchi  *
40*35786f68SRobert Mustacchi  * 3. Conditions
41*35786f68SRobert Mustacchi  *
42*35786f68SRobert Mustacchi  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43*35786f68SRobert Mustacchi  * Redistribution of source code of any substantial portion of the Covered
44*35786f68SRobert Mustacchi  * Code or modification with rights to further distribute source must include
45*35786f68SRobert Mustacchi  * the above Copyright Notice, the above License, this list of Conditions,
46*35786f68SRobert Mustacchi  * and the following Disclaimer and Export Compliance provision. In addition,
47*35786f68SRobert Mustacchi  * Licensee must cause all Covered Code to which Licensee contributes to
48*35786f68SRobert Mustacchi  * contain a file documenting the changes Licensee made to create that Covered
49*35786f68SRobert Mustacchi  * Code and the date of any change. Licensee must include in that file the
50*35786f68SRobert Mustacchi  * documentation of any changes made by any predecessor Licensee. Licensee
51*35786f68SRobert Mustacchi  * must include a prominent statement that the modification is derived,
52*35786f68SRobert Mustacchi  * directly or indirectly, from Original Intel Code.
53*35786f68SRobert Mustacchi  *
54*35786f68SRobert Mustacchi  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55*35786f68SRobert Mustacchi  * Redistribution of source code of any substantial portion of the Covered
56*35786f68SRobert Mustacchi  * Code or modification without rights to further distribute source must
57*35786f68SRobert Mustacchi  * include the following Disclaimer and Export Compliance provision in the
58*35786f68SRobert Mustacchi  * documentation and/or other materials provided with distribution. In
59*35786f68SRobert Mustacchi  * addition, Licensee may not authorize further sublicense of source of any
60*35786f68SRobert Mustacchi  * portion of the Covered Code, and must include terms to the effect that the
61*35786f68SRobert Mustacchi  * license from Licensee to its licensee is limited to the intellectual
62*35786f68SRobert Mustacchi  * property embodied in the software Licensee provides to its licensee, and
63*35786f68SRobert Mustacchi  * not to intellectual property embodied in modifications its licensee may
64*35786f68SRobert Mustacchi  * make.
65*35786f68SRobert Mustacchi  *
66*35786f68SRobert Mustacchi  * 3.3. Redistribution of Executable. Redistribution in executable form of any
67*35786f68SRobert Mustacchi  * substantial portion of the Covered Code or modification must reproduce the
68*35786f68SRobert Mustacchi  * above Copyright Notice, and the following Disclaimer and Export Compliance
69*35786f68SRobert Mustacchi  * provision in the documentation and/or other materials provided with the
70*35786f68SRobert Mustacchi  * distribution.
71*35786f68SRobert Mustacchi  *
72*35786f68SRobert Mustacchi  * 3.4. Intel retains all right, title, and interest in and to the Original
73*35786f68SRobert Mustacchi  * Intel Code.
74*35786f68SRobert Mustacchi  *
75*35786f68SRobert Mustacchi  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76*35786f68SRobert Mustacchi  * Intel shall be used in advertising or otherwise to promote the sale, use or
77*35786f68SRobert Mustacchi  * other dealings in products derived from or relating to the Covered Code
78*35786f68SRobert Mustacchi  * without prior written authorization from Intel.
79*35786f68SRobert Mustacchi  *
80*35786f68SRobert Mustacchi  * 4. Disclaimer and Export Compliance
81*35786f68SRobert Mustacchi  *
82*35786f68SRobert Mustacchi  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83*35786f68SRobert Mustacchi  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84*35786f68SRobert Mustacchi  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85*35786f68SRobert Mustacchi  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86*35786f68SRobert Mustacchi  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87*35786f68SRobert Mustacchi  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88*35786f68SRobert Mustacchi  * PARTICULAR PURPOSE.
89*35786f68SRobert Mustacchi  *
90*35786f68SRobert Mustacchi  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91*35786f68SRobert Mustacchi  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92*35786f68SRobert Mustacchi  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93*35786f68SRobert Mustacchi  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94*35786f68SRobert Mustacchi  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95*35786f68SRobert Mustacchi  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96*35786f68SRobert Mustacchi  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97*35786f68SRobert Mustacchi  * LIMITED REMEDY.
98*35786f68SRobert Mustacchi  *
99*35786f68SRobert Mustacchi  * 4.3. Licensee shall not export, either directly or indirectly, any of this
100*35786f68SRobert Mustacchi  * software or system incorporating such software without first obtaining any
101*35786f68SRobert Mustacchi  * required license or other approval from the U. S. Department of Commerce or
102*35786f68SRobert Mustacchi  * any other agency or department of the United States Government. In the
103*35786f68SRobert Mustacchi  * event Licensee exports any such software from the United States or
104*35786f68SRobert Mustacchi  * re-exports any such software from a foreign destination, Licensee shall
105*35786f68SRobert Mustacchi  * ensure that the distribution and export/re-export of the software is in
106*35786f68SRobert Mustacchi  * compliance with all laws, regulations, orders, or other restrictions of the
107*35786f68SRobert Mustacchi  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108*35786f68SRobert Mustacchi  * any of its subsidiaries will export/re-export any technical data, process,
109*35786f68SRobert Mustacchi  * software, or service, directly or indirectly, to any country for which the
110*35786f68SRobert Mustacchi  * United States government or any agency thereof requires an export license,
111*35786f68SRobert Mustacchi  * other governmental approval, or letter of assurance, without first obtaining
112*35786f68SRobert Mustacchi  * such license, approval or letter.
113*35786f68SRobert Mustacchi  *
114*35786f68SRobert Mustacchi  *****************************************************************************
115*35786f68SRobert Mustacchi  *
116*35786f68SRobert Mustacchi  * Alternatively, you may choose to be licensed under the terms of the
117*35786f68SRobert Mustacchi  * following license:
118*35786f68SRobert Mustacchi  *
11926f3cdf0SGordon Ross  * Redistribution and use in source and binary forms, with or without
12026f3cdf0SGordon Ross  * modification, are permitted provided that the following conditions
12126f3cdf0SGordon Ross  * are met:
12226f3cdf0SGordon Ross  * 1. Redistributions of source code must retain the above copyright
12326f3cdf0SGordon Ross  *    notice, this list of conditions, and the following disclaimer,
12426f3cdf0SGordon Ross  *    without modification.
12526f3cdf0SGordon Ross  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12626f3cdf0SGordon Ross  *    substantially similar to the "NO WARRANTY" disclaimer below
12726f3cdf0SGordon Ross  *    ("Disclaimer") and any redistribution must be conditioned upon
12826f3cdf0SGordon Ross  *    including a substantially similar Disclaimer requirement for further
12926f3cdf0SGordon Ross  *    binary redistribution.
13026f3cdf0SGordon Ross  * 3. Neither the names of the above-listed copyright holders nor the names
13126f3cdf0SGordon Ross  *    of any contributors may be used to endorse or promote products derived
13226f3cdf0SGordon Ross  *    from this software without specific prior written permission.
13326f3cdf0SGordon Ross  *
13426f3cdf0SGordon Ross  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
13526f3cdf0SGordon Ross  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136*35786f68SRobert Mustacchi  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
13726f3cdf0SGordon Ross  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138*35786f68SRobert Mustacchi  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139*35786f68SRobert Mustacchi  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140*35786f68SRobert Mustacchi  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141*35786f68SRobert Mustacchi  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142*35786f68SRobert Mustacchi  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143*35786f68SRobert Mustacchi  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144*35786f68SRobert Mustacchi  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145*35786f68SRobert Mustacchi  *
146*35786f68SRobert Mustacchi  * Alternatively, you may choose to be licensed under the terms of the
147*35786f68SRobert Mustacchi  * GNU General Public License ("GPL") version 2 as published by the Free
148*35786f68SRobert Mustacchi  * Software Foundation.
149*35786f68SRobert Mustacchi  *
150*35786f68SRobert Mustacchi  *****************************************************************************/
1517c478bd9Sstevel@tonic-gate 
1527c478bd9Sstevel@tonic-gate #include "acpi.h"
153aa2aa9a6SDana Myers #include "accommon.h"
1547c478bd9Sstevel@tonic-gate #include "acnamesp.h"
1557c478bd9Sstevel@tonic-gate #include "acresrc.h"
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate 
1587c478bd9Sstevel@tonic-gate #define _COMPONENT          ACPI_RESOURCES
1597c478bd9Sstevel@tonic-gate         ACPI_MODULE_NAME    ("rsutils")
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate 
162186507a7Smyers /*******************************************************************************
163186507a7Smyers  *
16430082d0cSmyers  * FUNCTION:    AcpiRsDecodeBitmask
165186507a7Smyers  *
16630082d0cSmyers  * PARAMETERS:  Mask            - Bitmask to decode
16730082d0cSmyers  *              List            - Where the converted list is returned
168186507a7Smyers  *
16930082d0cSmyers  * RETURN:      Count of bits set (length of list)
170186507a7Smyers  *
17130082d0cSmyers  * DESCRIPTION: Convert a bit mask into a list of values
172186507a7Smyers  *
173186507a7Smyers  ******************************************************************************/
174186507a7Smyers 
17530082d0cSmyers UINT8
AcpiRsDecodeBitmask(UINT16 Mask,UINT8 * List)17630082d0cSmyers AcpiRsDecodeBitmask (
17730082d0cSmyers     UINT16                  Mask,
17830082d0cSmyers     UINT8                   *List)
179186507a7Smyers {
180db2bae30SDana Myers     UINT8                   i;
18130082d0cSmyers     UINT8                   BitCount;
182186507a7Smyers 
183186507a7Smyers 
184186507a7Smyers     ACPI_FUNCTION_ENTRY ();
185186507a7Smyers 
186186507a7Smyers 
18730082d0cSmyers     /* Decode the mask bits */
188186507a7Smyers 
18930082d0cSmyers     for (i = 0, BitCount = 0; Mask; i++)
190186507a7Smyers     {
19130082d0cSmyers         if (Mask & 0x0001)
192186507a7Smyers         {
193db2bae30SDana Myers             List[BitCount] = i;
19430082d0cSmyers             BitCount++;
195186507a7Smyers         }
196186507a7Smyers 
19730082d0cSmyers         Mask >>= 1;
198186507a7Smyers     }
199186507a7Smyers 
20030082d0cSmyers     return (BitCount);
201186507a7Smyers }
202186507a7Smyers 
203186507a7Smyers 
204186507a7Smyers /*******************************************************************************
205186507a7Smyers  *
20630082d0cSmyers  * FUNCTION:    AcpiRsEncodeBitmask
207186507a7Smyers  *
20830082d0cSmyers  * PARAMETERS:  List            - List of values to encode
20930082d0cSmyers  *              Count           - Length of list
210186507a7Smyers  *
21130082d0cSmyers  * RETURN:      Encoded bitmask
212186507a7Smyers  *
21330082d0cSmyers  * DESCRIPTION: Convert a list of values to an encoded bitmask
214186507a7Smyers  *
215186507a7Smyers  ******************************************************************************/
216186507a7Smyers 
217186507a7Smyers UINT16
AcpiRsEncodeBitmask(UINT8 * List,UINT8 Count)21830082d0cSmyers AcpiRsEncodeBitmask (
21930082d0cSmyers     UINT8                   *List,
22030082d0cSmyers     UINT8                   Count)
221186507a7Smyers {
222db2bae30SDana Myers     UINT32                  i;
22330082d0cSmyers     UINT16                  Mask;
224186507a7Smyers 
225186507a7Smyers 
226186507a7Smyers     ACPI_FUNCTION_ENTRY ();
227186507a7Smyers 
228186507a7Smyers 
22930082d0cSmyers     /* Encode the list into a single bitmask */
230186507a7Smyers 
23130082d0cSmyers     for (i = 0, Mask = 0; i < Count; i++)
232186507a7Smyers     {
233db2bae30SDana Myers         Mask |= (0x1 << List[i]);
234186507a7Smyers     }
235186507a7Smyers 
23630082d0cSmyers     return (Mask);
237186507a7Smyers }
238186507a7Smyers 
239186507a7Smyers 
240186507a7Smyers /*******************************************************************************
241186507a7Smyers  *
24230082d0cSmyers  * FUNCTION:    AcpiRsMoveData
243186507a7Smyers  *
24430082d0cSmyers  * PARAMETERS:  Destination         - Pointer to the destination descriptor
24530082d0cSmyers  *              Source              - Pointer to the source descriptor
24630082d0cSmyers  *              ItemCount           - How many items to move
24730082d0cSmyers  *              MoveType            - Byte width
248186507a7Smyers  *
24930082d0cSmyers  * RETURN:      None
250186507a7Smyers  *
25130082d0cSmyers  * DESCRIPTION: Move multiple data items from one descriptor to another. Handles
25230082d0cSmyers  *              alignment issues and endian issues if necessary, as configured
25330082d0cSmyers  *              via the ACPI_MOVE_* macros. (This is why a memcpy is not used)
254186507a7Smyers  *
255186507a7Smyers  ******************************************************************************/
256186507a7Smyers 
25730082d0cSmyers void
AcpiRsMoveData(void * Destination,void * Source,UINT16 ItemCount,UINT8 MoveType)25830082d0cSmyers AcpiRsMoveData (
25930082d0cSmyers     void                    *Destination,
26030082d0cSmyers     void                    *Source,
26130082d0cSmyers     UINT16                  ItemCount,
26230082d0cSmyers     UINT8                   MoveType)
263186507a7Smyers {
264db2bae30SDana Myers     UINT32                  i;
265186507a7Smyers 
266186507a7Smyers 
267186507a7Smyers     ACPI_FUNCTION_ENTRY ();
268186507a7Smyers 
269186507a7Smyers 
27030082d0cSmyers     /* One move per item */
271186507a7Smyers 
27230082d0cSmyers     for (i = 0; i < ItemCount; i++)
273186507a7Smyers     {
27430082d0cSmyers         switch (MoveType)
27530082d0cSmyers         {
27630082d0cSmyers         /*
27730082d0cSmyers          * For the 8-bit case, we can perform the move all at once
27830082d0cSmyers          * since there are no alignment or endian issues
27930082d0cSmyers          */
28030082d0cSmyers         case ACPI_RSC_MOVE8:
2817b1019a6SJerry Jelinek         case ACPI_RSC_MOVE_GPIO_RES:
2827b1019a6SJerry Jelinek         case ACPI_RSC_MOVE_SERIAL_VEN:
2837b1019a6SJerry Jelinek         case ACPI_RSC_MOVE_SERIAL_RES:
2847b1019a6SJerry Jelinek 
2857b1019a6SJerry Jelinek             memcpy (Destination, Source, ItemCount);
28630082d0cSmyers             return;
287186507a7Smyers 
28830082d0cSmyers         /*
28930082d0cSmyers          * 16-, 32-, and 64-bit cases must use the move macros that perform
2907b1019a6SJerry Jelinek          * endian conversion and/or accommodate hardware that cannot perform
29130082d0cSmyers          * misaligned memory transfers
29230082d0cSmyers          */
29330082d0cSmyers         case ACPI_RSC_MOVE16:
2947b1019a6SJerry Jelinek         case ACPI_RSC_MOVE_GPIO_PIN:
2957b1019a6SJerry Jelinek 
2967b1019a6SJerry Jelinek             ACPI_MOVE_16_TO_16 (
2977b1019a6SJerry Jelinek                 &ACPI_CAST_PTR (UINT16, Destination)[i],
2987b1019a6SJerry Jelinek                 &ACPI_CAST_PTR (UINT16, Source)[i]);
29930082d0cSmyers             break;
300186507a7Smyers 
30130082d0cSmyers         case ACPI_RSC_MOVE32:
3027b1019a6SJerry Jelinek 
3037b1019a6SJerry Jelinek             ACPI_MOVE_32_TO_32 (
3047b1019a6SJerry Jelinek                 &ACPI_CAST_PTR (UINT32, Destination)[i],
3057b1019a6SJerry Jelinek                 &ACPI_CAST_PTR (UINT32, Source)[i]);
30630082d0cSmyers             break;
307186507a7Smyers 
30830082d0cSmyers         case ACPI_RSC_MOVE64:
3097b1019a6SJerry Jelinek 
3107b1019a6SJerry Jelinek             ACPI_MOVE_64_TO_64 (
3117b1019a6SJerry Jelinek                 &ACPI_CAST_PTR (UINT64, Destination)[i],
3127b1019a6SJerry Jelinek                 &ACPI_CAST_PTR (UINT64, Source)[i]);
31330082d0cSmyers             break;
314186507a7Smyers 
31530082d0cSmyers         default:
3167b1019a6SJerry Jelinek 
31730082d0cSmyers             return;
31830082d0cSmyers         }
31930082d0cSmyers     }
320186507a7Smyers }
321186507a7Smyers 
322186507a7Smyers 
323186507a7Smyers /*******************************************************************************
324186507a7Smyers  *
32530082d0cSmyers  * FUNCTION:    AcpiRsSetResourceLength
326186507a7Smyers  *
32730082d0cSmyers  * PARAMETERS:  TotalLength         - Length of the AML descriptor, including
328186507a7Smyers  *                                    the header and length fields.
329186507a7Smyers  *              Aml                 - Pointer to the raw AML descriptor
330186507a7Smyers  *
331186507a7Smyers  * RETURN:      None
332186507a7Smyers  *
33330082d0cSmyers  * DESCRIPTION: Set the ResourceLength field of an AML
334186507a7Smyers  *              resource descriptor, both Large and Small descriptors are
33530082d0cSmyers  *              supported automatically. Note: Descriptor Type field must
33630082d0cSmyers  *              be valid.
337186507a7Smyers  *
338186507a7Smyers  ******************************************************************************/
339186507a7Smyers 
340186507a7Smyers void
AcpiRsSetResourceLength(ACPI_RSDESC_SIZE TotalLength,AML_RESOURCE * Aml)34130082d0cSmyers AcpiRsSetResourceLength (
34230082d0cSmyers     ACPI_RSDESC_SIZE        TotalLength,
343186507a7Smyers     AML_RESOURCE            *Aml)
344186507a7Smyers {
34530082d0cSmyers     ACPI_RS_LENGTH          ResourceLength;
346186507a7Smyers 
347186507a7Smyers 
348186507a7Smyers     ACPI_FUNCTION_ENTRY ();
349186507a7Smyers 
350186507a7Smyers 
35130082d0cSmyers     /* Length is the total descriptor length minus the header length */
352186507a7Smyers 
35330082d0cSmyers     ResourceLength = (ACPI_RS_LENGTH)
35430082d0cSmyers         (TotalLength - AcpiUtGetResourceHeaderLength (Aml));
355186507a7Smyers 
35630082d0cSmyers     /* Length is stored differently for large and small descriptors */
357186507a7Smyers 
358186507a7Smyers     if (Aml->SmallHeader.DescriptorType & ACPI_RESOURCE_NAME_LARGE)
359186507a7Smyers     {
36030082d0cSmyers         /* Large descriptor -- bytes 1-2 contain the 16-bit length */
361186507a7Smyers 
3627b1019a6SJerry Jelinek         ACPI_MOVE_16_TO_16 (
3637b1019a6SJerry Jelinek             &Aml->LargeHeader.ResourceLength, &ResourceLength);
364186507a7Smyers     }
365186507a7Smyers     else
366186507a7Smyers     {
3677b1019a6SJerry Jelinek         /*
3687b1019a6SJerry Jelinek          * Small descriptor -- bits 2:0 of byte 0 contain the length
3697b1019a6SJerry Jelinek          * Clear any existing length, preserving descriptor type bits
3707b1019a6SJerry Jelinek          */
37130082d0cSmyers         Aml->SmallHeader.DescriptorType = (UINT8)
3727b1019a6SJerry Jelinek             ((Aml->SmallHeader.DescriptorType &
3737b1019a6SJerry Jelinek                 ~ACPI_RESOURCE_NAME_SMALL_LENGTH_MASK)
37430082d0cSmyers             | ResourceLength);
375186507a7Smyers     }
376186507a7Smyers }
377186507a7Smyers 
378186507a7Smyers 
379186507a7Smyers /*******************************************************************************
380186507a7Smyers  *
38130082d0cSmyers  * FUNCTION:    AcpiRsSetResourceHeader
382186507a7Smyers  *
38330082d0cSmyers  * PARAMETERS:  DescriptorType      - Byte to be inserted as the type
38430082d0cSmyers  *              TotalLength         - Length of the AML descriptor, including
38530082d0cSmyers  *                                    the header and length fields.
38630082d0cSmyers  *              Aml                 - Pointer to the raw AML descriptor
387186507a7Smyers  *
38830082d0cSmyers  * RETURN:      None
389186507a7Smyers  *
39030082d0cSmyers  * DESCRIPTION: Set the DescriptorType and ResourceLength fields of an AML
39130082d0cSmyers  *              resource descriptor, both Large and Small descriptors are
39230082d0cSmyers  *              supported automatically
393186507a7Smyers  *
394186507a7Smyers  ******************************************************************************/
395186507a7Smyers 
39630082d0cSmyers void
AcpiRsSetResourceHeader(UINT8 DescriptorType,ACPI_RSDESC_SIZE TotalLength,AML_RESOURCE * Aml)39730082d0cSmyers AcpiRsSetResourceHeader (
39830082d0cSmyers     UINT8                   DescriptorType,
39930082d0cSmyers     ACPI_RSDESC_SIZE        TotalLength,
40030082d0cSmyers     AML_RESOURCE            *Aml)
401186507a7Smyers {
402186507a7Smyers     ACPI_FUNCTION_ENTRY ();
403186507a7Smyers 
404186507a7Smyers 
40530082d0cSmyers     /* Set the Resource Type */
406186507a7Smyers 
40730082d0cSmyers     Aml->SmallHeader.DescriptorType = DescriptorType;
408186507a7Smyers 
40930082d0cSmyers     /* Set the Resource Length */
410186507a7Smyers 
41130082d0cSmyers     AcpiRsSetResourceLength (TotalLength, Aml);
412186507a7Smyers }
413186507a7Smyers 
414186507a7Smyers 
415186507a7Smyers /*******************************************************************************
416186507a7Smyers  *
417186507a7Smyers  * FUNCTION:    AcpiRsStrcpy
418186507a7Smyers  *
419186507a7Smyers  * PARAMETERS:  Destination         - Pointer to the destination string
420186507a7Smyers  *              Source              - Pointer to the source string
421186507a7Smyers  *
422186507a7Smyers  * RETURN:      String length, including NULL terminator
423186507a7Smyers  *
424186507a7Smyers  * DESCRIPTION: Local string copy that returns the string length, saving a
425186507a7Smyers  *              strcpy followed by a strlen.
426186507a7Smyers  *
427186507a7Smyers  ******************************************************************************/
428186507a7Smyers 
429186507a7Smyers static UINT16
AcpiRsStrcpy(char * Destination,char * Source)430186507a7Smyers AcpiRsStrcpy (
431186507a7Smyers     char                    *Destination,
432186507a7Smyers     char                    *Source)
433186507a7Smyers {
434186507a7Smyers     UINT16                  i;
435186507a7Smyers 
436186507a7Smyers 
437186507a7Smyers     ACPI_FUNCTION_ENTRY ();
438186507a7Smyers 
439186507a7Smyers 
440186507a7Smyers     for (i = 0; Source[i]; i++)
441186507a7Smyers     {
442186507a7Smyers         Destination[i] = Source[i];
443186507a7Smyers     }
444186507a7Smyers 
445186507a7Smyers     Destination[i] = 0;
446186507a7Smyers 
447186507a7Smyers     /* Return string length including the NULL terminator */
448186507a7Smyers 
449186507a7Smyers     return ((UINT16) (i + 1));
450186507a7Smyers }
451186507a7Smyers 
452186507a7Smyers 
453186507a7Smyers /*******************************************************************************
454186507a7Smyers  *
455186507a7Smyers  * FUNCTION:    AcpiRsGetResourceSource
456186507a7Smyers  *
457186507a7Smyers  * PARAMETERS:  ResourceLength      - Length field of the descriptor
458186507a7Smyers  *              MinimumLength       - Minimum length of the descriptor (minus
459186507a7Smyers  *                                    any optional fields)
460186507a7Smyers  *              ResourceSource      - Where the ResourceSource is returned
461186507a7Smyers  *              Aml                 - Pointer to the raw AML descriptor
462186507a7Smyers  *              StringPtr           - (optional) where to store the actual
463186507a7Smyers  *                                    ResourceSource string
464186507a7Smyers  *
46530082d0cSmyers  * RETURN:      Length of the string plus NULL terminator, rounded up to native
46630082d0cSmyers  *              word boundary
467186507a7Smyers  *
468186507a7Smyers  * DESCRIPTION: Copy the optional ResourceSource data from a raw AML descriptor
469186507a7Smyers  *              to an internal resource descriptor
470186507a7Smyers  *
471186507a7Smyers  ******************************************************************************/
472186507a7Smyers 
47330082d0cSmyers ACPI_RS_LENGTH
AcpiRsGetResourceSource(ACPI_RS_LENGTH ResourceLength,ACPI_RS_LENGTH MinimumLength,ACPI_RESOURCE_SOURCE * ResourceSource,AML_RESOURCE * Aml,char * StringPtr)474186507a7Smyers AcpiRsGetResourceSource (
47530082d0cSmyers     ACPI_RS_LENGTH          ResourceLength,
47630082d0cSmyers     ACPI_RS_LENGTH          MinimumLength,
477186507a7Smyers     ACPI_RESOURCE_SOURCE    *ResourceSource,
478186507a7Smyers     AML_RESOURCE            *Aml,
479186507a7Smyers     char                    *StringPtr)
480186507a7Smyers {
48130082d0cSmyers     ACPI_RSDESC_SIZE        TotalLength;
482186507a7Smyers     UINT8                   *AmlResourceSource;
483186507a7Smyers 
484186507a7Smyers 
485186507a7Smyers     ACPI_FUNCTION_ENTRY ();
486186507a7Smyers 
487186507a7Smyers 
488186507a7Smyers     TotalLength = ResourceLength + sizeof (AML_RESOURCE_LARGE_HEADER);
48930082d0cSmyers     AmlResourceSource = ACPI_ADD_PTR (UINT8, Aml, MinimumLength);
490186507a7Smyers 
491186507a7Smyers     /*
4927b1019a6SJerry Jelinek      * ResourceSource is present if the length of the descriptor is longer
4937b1019a6SJerry Jelinek      * than the minimum length.
494186507a7Smyers      *
495186507a7Smyers      * Note: Some resource descriptors will have an additional null, so
496186507a7Smyers      * we add 1 to the minimum length.
497186507a7Smyers      */
49830082d0cSmyers     if (TotalLength > (ACPI_RSDESC_SIZE) (MinimumLength + 1))
499186507a7Smyers     {
500186507a7Smyers         /* Get the ResourceSourceIndex */
501186507a7Smyers 
502186507a7Smyers         ResourceSource->Index = AmlResourceSource[0];
503186507a7Smyers 
504186507a7Smyers         ResourceSource->StringPtr = StringPtr;
505186507a7Smyers         if (!StringPtr)
506186507a7Smyers         {
507186507a7Smyers             /*
508186507a7Smyers              * String destination pointer is not specified; Set the String
509186507a7Smyers              * pointer to the end of the current ResourceSource structure.
510186507a7Smyers              */
5117b1019a6SJerry Jelinek             ResourceSource->StringPtr = ACPI_ADD_PTR (
5127b1019a6SJerry Jelinek                 char, ResourceSource, sizeof (ACPI_RESOURCE_SOURCE));
513186507a7Smyers         }
514186507a7Smyers 
51530082d0cSmyers         /*
51630082d0cSmyers          * In order for the Resource length to be a multiple of the native
51730082d0cSmyers          * word, calculate the length of the string (+1 for NULL terminator)
51830082d0cSmyers          * and expand to the next word multiple.
51930082d0cSmyers          *
52030082d0cSmyers          * Zero the entire area of the buffer.
52130082d0cSmyers          */
5227b1019a6SJerry Jelinek         TotalLength = (UINT32) strlen (
52327f7c583Smyers             ACPI_CAST_PTR (char, &AmlResourceSource[1])) + 1;
5247b1019a6SJerry Jelinek 
52530082d0cSmyers         TotalLength = (UINT32) ACPI_ROUND_UP_TO_NATIVE_WORD (TotalLength);
52627f7c583Smyers 
5277b1019a6SJerry Jelinek         memset (ResourceSource->StringPtr, 0, TotalLength);
52830082d0cSmyers 
529186507a7Smyers         /* Copy the ResourceSource string to the destination */
530186507a7Smyers 
5317b1019a6SJerry Jelinek         ResourceSource->StringLength = AcpiRsStrcpy (
5327b1019a6SJerry Jelinek             ResourceSource->StringPtr,
53330082d0cSmyers             ACPI_CAST_PTR (char, &AmlResourceSource[1]));
534186507a7Smyers 
53530082d0cSmyers         return ((ACPI_RS_LENGTH) TotalLength);
536186507a7Smyers     }
537186507a7Smyers 
53830082d0cSmyers     /* ResourceSource is not present */
53930082d0cSmyers 
54030082d0cSmyers     ResourceSource->Index = 0;
54130082d0cSmyers     ResourceSource->StringLength = 0;
54230082d0cSmyers     ResourceSource->StringPtr = NULL;
54330082d0cSmyers     return (0);
544186507a7Smyers }
545186507a7Smyers 
54630082d0cSmyers 
547186507a7Smyers /*******************************************************************************
548186507a7Smyers  *
549186507a7Smyers  * FUNCTION:    AcpiRsSetResourceSource
550186507a7Smyers  *
551186507a7Smyers  * PARAMETERS:  Aml                 - Pointer to the raw AML descriptor
552186507a7Smyers  *              MinimumLength       - Minimum length of the descriptor (minus
553186507a7Smyers  *                                    any optional fields)
554186507a7Smyers  *              ResourceSource      - Internal ResourceSource
555186507a7Smyers 
556186507a7Smyers  *
557186507a7Smyers  * RETURN:      Total length of the AML descriptor
558186507a7Smyers  *
55930082d0cSmyers  * DESCRIPTION: Convert an optional ResourceSource from internal format to a
560186507a7Smyers  *              raw AML resource descriptor
561186507a7Smyers  *
562186507a7Smyers  ******************************************************************************/
563186507a7Smyers 
56430082d0cSmyers ACPI_RSDESC_SIZE
AcpiRsSetResourceSource(AML_RESOURCE * Aml,ACPI_RS_LENGTH MinimumLength,ACPI_RESOURCE_SOURCE * ResourceSource)565186507a7Smyers AcpiRsSetResourceSource (
566186507a7Smyers     AML_RESOURCE            *Aml,
56730082d0cSmyers     ACPI_RS_LENGTH          MinimumLength,
568186507a7Smyers     ACPI_RESOURCE_SOURCE    *ResourceSource)
569186507a7Smyers {
570186507a7Smyers     UINT8                   *AmlResourceSource;
57130082d0cSmyers     ACPI_RSDESC_SIZE        DescriptorLength;
572186507a7Smyers 
573186507a7Smyers 
574186507a7Smyers     ACPI_FUNCTION_ENTRY ();
575186507a7Smyers 
576186507a7Smyers 
577186507a7Smyers     DescriptorLength = MinimumLength;
578186507a7Smyers 
579186507a7Smyers     /* Non-zero string length indicates presence of a ResourceSource */
580186507a7Smyers 
581186507a7Smyers     if (ResourceSource->StringLength)
582186507a7Smyers     {
583186507a7Smyers         /* Point to the end of the AML descriptor */
584186507a7Smyers 
58530082d0cSmyers         AmlResourceSource = ACPI_ADD_PTR (UINT8, Aml, MinimumLength);
586186507a7Smyers 
587186507a7Smyers         /* Copy the ResourceSourceIndex */
588186507a7Smyers 
589186507a7Smyers         AmlResourceSource[0] = (UINT8) ResourceSource->Index;
590186507a7Smyers 
591186507a7Smyers         /* Copy the ResourceSource string */
592186507a7Smyers 
5937b1019a6SJerry Jelinek         strcpy (ACPI_CAST_PTR (char, &AmlResourceSource[1]),
59430082d0cSmyers             ResourceSource->StringPtr);
595186507a7Smyers 
596186507a7Smyers         /*
597186507a7Smyers          * Add the length of the string (+ 1 for null terminator) to the
598186507a7Smyers          * final descriptor length
599186507a7Smyers          */
6007b1019a6SJerry Jelinek         DescriptorLength += ((ACPI_RSDESC_SIZE)
6017b1019a6SJerry Jelinek             ResourceSource->StringLength + 1);
602186507a7Smyers     }
603186507a7Smyers 
604186507a7Smyers     /* Return the new total length of the AML descriptor */
605186507a7Smyers 
606186507a7Smyers     return (DescriptorLength);
607186507a7Smyers }
608186507a7Smyers 
609186507a7Smyers 
6107c478bd9Sstevel@tonic-gate /*******************************************************************************
6117c478bd9Sstevel@tonic-gate  *
6127c478bd9Sstevel@tonic-gate  * FUNCTION:    AcpiRsGetPrtMethodData
6137c478bd9Sstevel@tonic-gate  *
61427f7c583Smyers  * PARAMETERS:  Node            - Device node
61530082d0cSmyers  *              RetBuffer       - Pointer to a buffer structure for the
61630082d0cSmyers  *                                results
6177c478bd9Sstevel@tonic-gate  *
6187c478bd9Sstevel@tonic-gate  * RETURN:      Status
6197c478bd9Sstevel@tonic-gate  *
6207c478bd9Sstevel@tonic-gate  * DESCRIPTION: This function is called to get the _PRT value of an object
6217c478bd9Sstevel@tonic-gate  *              contained in an object specified by the handle passed in
6227c478bd9Sstevel@tonic-gate  *
6237c478bd9Sstevel@tonic-gate  *              If the function fails an appropriate status will be returned
6247c478bd9Sstevel@tonic-gate  *              and the contents of the callers buffer is undefined.
6257c478bd9Sstevel@tonic-gate  *
6267c478bd9Sstevel@tonic-gate  ******************************************************************************/
6277c478bd9Sstevel@tonic-gate 
6287c478bd9Sstevel@tonic-gate ACPI_STATUS
AcpiRsGetPrtMethodData(ACPI_NAMESPACE_NODE * Node,ACPI_BUFFER * RetBuffer)6297c478bd9Sstevel@tonic-gate AcpiRsGetPrtMethodData (
63027f7c583Smyers     ACPI_NAMESPACE_NODE     *Node,
6317c478bd9Sstevel@tonic-gate     ACPI_BUFFER             *RetBuffer)
6327c478bd9Sstevel@tonic-gate {
6337c478bd9Sstevel@tonic-gate     ACPI_OPERAND_OBJECT     *ObjDesc;
6347c478bd9Sstevel@tonic-gate     ACPI_STATUS             Status;
6357c478bd9Sstevel@tonic-gate 
6367c478bd9Sstevel@tonic-gate 
63727f7c583Smyers     ACPI_FUNCTION_TRACE (RsGetPrtMethodData);
6387c478bd9Sstevel@tonic-gate 
6397c478bd9Sstevel@tonic-gate 
6407c478bd9Sstevel@tonic-gate     /* Parameters guaranteed valid by caller */
6417c478bd9Sstevel@tonic-gate 
6427c478bd9Sstevel@tonic-gate     /* Execute the method, no parameters */
6437c478bd9Sstevel@tonic-gate 
6447b1019a6SJerry Jelinek     Status = AcpiUtEvaluateObject (
6457b1019a6SJerry Jelinek         Node, METHOD_NAME__PRT, ACPI_BTYPE_PACKAGE, &ObjDesc);
6467c478bd9Sstevel@tonic-gate     if (ACPI_FAILURE (Status))
6477c478bd9Sstevel@tonic-gate     {
6487c478bd9Sstevel@tonic-gate         return_ACPI_STATUS (Status);
6497c478bd9Sstevel@tonic-gate     }
6507c478bd9Sstevel@tonic-gate 
6517c478bd9Sstevel@tonic-gate     /*
6527c478bd9Sstevel@tonic-gate      * Create a resource linked list from the byte stream buffer that comes
6537c478bd9Sstevel@tonic-gate      * back from the _CRS method execution.
6547c478bd9Sstevel@tonic-gate      */
6557c478bd9Sstevel@tonic-gate     Status = AcpiRsCreatePciRoutingTable (ObjDesc, RetBuffer);
6567c478bd9Sstevel@tonic-gate 
6577c478bd9Sstevel@tonic-gate     /* On exit, we must delete the object returned by EvaluateObject */
6587c478bd9Sstevel@tonic-gate 
6597c478bd9Sstevel@tonic-gate     AcpiUtRemoveReference (ObjDesc);
6607c478bd9Sstevel@tonic-gate     return_ACPI_STATUS (Status);
6617c478bd9Sstevel@tonic-gate }
6627c478bd9Sstevel@tonic-gate 
6637c478bd9Sstevel@tonic-gate 
6647c478bd9Sstevel@tonic-gate /*******************************************************************************
6657c478bd9Sstevel@tonic-gate  *
6667c478bd9Sstevel@tonic-gate  * FUNCTION:    AcpiRsGetCrsMethodData
6677c478bd9Sstevel@tonic-gate  *
66827f7c583Smyers  * PARAMETERS:  Node            - Device node
66930082d0cSmyers  *              RetBuffer       - Pointer to a buffer structure for the
67030082d0cSmyers  *                                results
6717c478bd9Sstevel@tonic-gate  *
6727c478bd9Sstevel@tonic-gate  * RETURN:      Status
6737c478bd9Sstevel@tonic-gate  *
6747c478bd9Sstevel@tonic-gate  * DESCRIPTION: This function is called to get the _CRS value of an object
6757c478bd9Sstevel@tonic-gate  *              contained in an object specified by the handle passed in
6767c478bd9Sstevel@tonic-gate  *
6777c478bd9Sstevel@tonic-gate  *              If the function fails an appropriate status will be returned
6787c478bd9Sstevel@tonic-gate  *              and the contents of the callers buffer is undefined.
6797c478bd9Sstevel@tonic-gate  *
6807c478bd9Sstevel@tonic-gate  ******************************************************************************/
6817c478bd9Sstevel@tonic-gate 
6827c478bd9Sstevel@tonic-gate ACPI_STATUS
AcpiRsGetCrsMethodData(ACPI_NAMESPACE_NODE * Node,ACPI_BUFFER * RetBuffer)6837c478bd9Sstevel@tonic-gate AcpiRsGetCrsMethodData (
68427f7c583Smyers     ACPI_NAMESPACE_NODE     *Node,
6857c478bd9Sstevel@tonic-gate     ACPI_BUFFER             *RetBuffer)
6867c478bd9Sstevel@tonic-gate {
6877c478bd9Sstevel@tonic-gate     ACPI_OPERAND_OBJECT     *ObjDesc;
6887c478bd9Sstevel@tonic-gate     ACPI_STATUS             Status;
6897c478bd9Sstevel@tonic-gate 
6907c478bd9Sstevel@tonic-gate 
69127f7c583Smyers     ACPI_FUNCTION_TRACE (RsGetCrsMethodData);
6927c478bd9Sstevel@tonic-gate 
6937c478bd9Sstevel@tonic-gate 
6947c478bd9Sstevel@tonic-gate     /* Parameters guaranteed valid by caller */
6957c478bd9Sstevel@tonic-gate 
6967c478bd9Sstevel@tonic-gate     /* Execute the method, no parameters */
6977c478bd9Sstevel@tonic-gate 
6987b1019a6SJerry Jelinek     Status = AcpiUtEvaluateObject (
6997b1019a6SJerry Jelinek         Node, METHOD_NAME__CRS, ACPI_BTYPE_BUFFER, &ObjDesc);
7007c478bd9Sstevel@tonic-gate     if (ACPI_FAILURE (Status))
7017c478bd9Sstevel@tonic-gate     {
7027c478bd9Sstevel@tonic-gate         return_ACPI_STATUS (Status);
7037c478bd9Sstevel@tonic-gate     }
7047c478bd9Sstevel@tonic-gate 
7057c478bd9Sstevel@tonic-gate     /*
7067c478bd9Sstevel@tonic-gate      * Make the call to create a resource linked list from the
7077c478bd9Sstevel@tonic-gate      * byte stream buffer that comes back from the _CRS method
7087c478bd9Sstevel@tonic-gate      * execution.
7097c478bd9Sstevel@tonic-gate      */
7107c478bd9Sstevel@tonic-gate     Status = AcpiRsCreateResourceList (ObjDesc, RetBuffer);
7117c478bd9Sstevel@tonic-gate 
7127c478bd9Sstevel@tonic-gate     /* On exit, we must delete the object returned by evaluateObject */
7137c478bd9Sstevel@tonic-gate 
7147c478bd9Sstevel@tonic-gate     AcpiUtRemoveReference (ObjDesc);
7157c478bd9Sstevel@tonic-gate     return_ACPI_STATUS (Status);
7167c478bd9Sstevel@tonic-gate }
7177c478bd9Sstevel@tonic-gate 
7187c478bd9Sstevel@tonic-gate 
7197c478bd9Sstevel@tonic-gate /*******************************************************************************
7207c478bd9Sstevel@tonic-gate  *
7217c478bd9Sstevel@tonic-gate  * FUNCTION:    AcpiRsGetPrsMethodData
7227c478bd9Sstevel@tonic-gate  *
72327f7c583Smyers  * PARAMETERS:  Node            - Device node
72430082d0cSmyers  *              RetBuffer       - Pointer to a buffer structure for the
72530082d0cSmyers  *                                results
7267c478bd9Sstevel@tonic-gate  *
7277c478bd9Sstevel@tonic-gate  * RETURN:      Status
7287c478bd9Sstevel@tonic-gate  *
7297c478bd9Sstevel@tonic-gate  * DESCRIPTION: This function is called to get the _PRS value of an object
7307c478bd9Sstevel@tonic-gate  *              contained in an object specified by the handle passed in
7317c478bd9Sstevel@tonic-gate  *
7327c478bd9Sstevel@tonic-gate  *              If the function fails an appropriate status will be returned
7337c478bd9Sstevel@tonic-gate  *              and the contents of the callers buffer is undefined.
7347c478bd9Sstevel@tonic-gate  *
7357c478bd9Sstevel@tonic-gate  ******************************************************************************/
7367c478bd9Sstevel@tonic-gate 
7377c478bd9Sstevel@tonic-gate ACPI_STATUS
AcpiRsGetPrsMethodData(ACPI_NAMESPACE_NODE * Node,ACPI_BUFFER * RetBuffer)7387c478bd9Sstevel@tonic-gate AcpiRsGetPrsMethodData (
73927f7c583Smyers     ACPI_NAMESPACE_NODE     *Node,
7407c478bd9Sstevel@tonic-gate     ACPI_BUFFER             *RetBuffer)
7417c478bd9Sstevel@tonic-gate {
7427c478bd9Sstevel@tonic-gate     ACPI_OPERAND_OBJECT     *ObjDesc;
7437c478bd9Sstevel@tonic-gate     ACPI_STATUS             Status;
7447c478bd9Sstevel@tonic-gate 
7457c478bd9Sstevel@tonic-gate 
74627f7c583Smyers     ACPI_FUNCTION_TRACE (RsGetPrsMethodData);
7477c478bd9Sstevel@tonic-gate 
7487c478bd9Sstevel@tonic-gate 
7497c478bd9Sstevel@tonic-gate     /* Parameters guaranteed valid by caller */
7507c478bd9Sstevel@tonic-gate 
7517c478bd9Sstevel@tonic-gate     /* Execute the method, no parameters */
7527c478bd9Sstevel@tonic-gate 
7537b1019a6SJerry Jelinek     Status = AcpiUtEvaluateObject (
7547b1019a6SJerry Jelinek         Node, METHOD_NAME__PRS, ACPI_BTYPE_BUFFER, &ObjDesc);
7557b1019a6SJerry Jelinek     if (ACPI_FAILURE (Status))
7567b1019a6SJerry Jelinek     {
7577b1019a6SJerry Jelinek         return_ACPI_STATUS (Status);
7587b1019a6SJerry Jelinek     }
7597b1019a6SJerry Jelinek 
7607b1019a6SJerry Jelinek     /*
7617b1019a6SJerry Jelinek      * Make the call to create a resource linked list from the
7627b1019a6SJerry Jelinek      * byte stream buffer that comes back from the _CRS method
7637b1019a6SJerry Jelinek      * execution.
7647b1019a6SJerry Jelinek      */
7657b1019a6SJerry Jelinek     Status = AcpiRsCreateResourceList (ObjDesc, RetBuffer);
7667b1019a6SJerry Jelinek 
7677b1019a6SJerry Jelinek     /* On exit, we must delete the object returned by evaluateObject */
7687b1019a6SJerry Jelinek 
7697b1019a6SJerry Jelinek     AcpiUtRemoveReference (ObjDesc);
7707b1019a6SJerry Jelinek     return_ACPI_STATUS (Status);
7717b1019a6SJerry Jelinek }
7727b1019a6SJerry Jelinek 
7737b1019a6SJerry Jelinek 
7747b1019a6SJerry Jelinek /*******************************************************************************
7757b1019a6SJerry Jelinek  *
7767b1019a6SJerry Jelinek  * FUNCTION:    AcpiRsGetAeiMethodData
7777b1019a6SJerry Jelinek  *
7787b1019a6SJerry Jelinek  * PARAMETERS:  Node            - Device node
7797b1019a6SJerry Jelinek  *              RetBuffer       - Pointer to a buffer structure for the
7807b1019a6SJerry Jelinek  *                                results
7817b1019a6SJerry Jelinek  *
7827b1019a6SJerry Jelinek  * RETURN:      Status
7837b1019a6SJerry Jelinek  *
7847b1019a6SJerry Jelinek  * DESCRIPTION: This function is called to get the _AEI value of an object
7857b1019a6SJerry Jelinek  *              contained in an object specified by the handle passed in
7867b1019a6SJerry Jelinek  *
7877b1019a6SJerry Jelinek  *              If the function fails an appropriate status will be returned
7887b1019a6SJerry Jelinek  *              and the contents of the callers buffer is undefined.
7897b1019a6SJerry Jelinek  *
7907b1019a6SJerry Jelinek  ******************************************************************************/
7917b1019a6SJerry Jelinek 
7927b1019a6SJerry Jelinek ACPI_STATUS
AcpiRsGetAeiMethodData(ACPI_NAMESPACE_NODE * Node,ACPI_BUFFER * RetBuffer)7937b1019a6SJerry Jelinek AcpiRsGetAeiMethodData (
7947b1019a6SJerry Jelinek     ACPI_NAMESPACE_NODE     *Node,
7957b1019a6SJerry Jelinek     ACPI_BUFFER             *RetBuffer)
7967b1019a6SJerry Jelinek {
7977b1019a6SJerry Jelinek     ACPI_OPERAND_OBJECT     *ObjDesc;
7987b1019a6SJerry Jelinek     ACPI_STATUS             Status;
7997b1019a6SJerry Jelinek 
8007b1019a6SJerry Jelinek 
8017b1019a6SJerry Jelinek     ACPI_FUNCTION_TRACE (RsGetAeiMethodData);
8027b1019a6SJerry Jelinek 
8037b1019a6SJerry Jelinek 
8047b1019a6SJerry Jelinek     /* Parameters guaranteed valid by caller */
8057b1019a6SJerry Jelinek 
8067b1019a6SJerry Jelinek     /* Execute the method, no parameters */
8077b1019a6SJerry Jelinek 
8087b1019a6SJerry Jelinek     Status = AcpiUtEvaluateObject (
8097b1019a6SJerry Jelinek         Node, METHOD_NAME__AEI, ACPI_BTYPE_BUFFER, &ObjDesc);
8107c478bd9Sstevel@tonic-gate     if (ACPI_FAILURE (Status))
8117c478bd9Sstevel@tonic-gate     {
8127c478bd9Sstevel@tonic-gate         return_ACPI_STATUS (Status);
8137c478bd9Sstevel@tonic-gate     }
8147c478bd9Sstevel@tonic-gate 
8157c478bd9Sstevel@tonic-gate     /*
8167c478bd9Sstevel@tonic-gate      * Make the call to create a resource linked list from the
8177c478bd9Sstevel@tonic-gate      * byte stream buffer that comes back from the _CRS method
8187c478bd9Sstevel@tonic-gate      * execution.
8197c478bd9Sstevel@tonic-gate      */
8207c478bd9Sstevel@tonic-gate     Status = AcpiRsCreateResourceList (ObjDesc, RetBuffer);
8217c478bd9Sstevel@tonic-gate 
8227c478bd9Sstevel@tonic-gate     /* On exit, we must delete the object returned by evaluateObject */
8237c478bd9Sstevel@tonic-gate 
8247c478bd9Sstevel@tonic-gate     AcpiUtRemoveReference (ObjDesc);
8257c478bd9Sstevel@tonic-gate     return_ACPI_STATUS (Status);
8267c478bd9Sstevel@tonic-gate }
8277c478bd9Sstevel@tonic-gate 
8287c478bd9Sstevel@tonic-gate 
8297c478bd9Sstevel@tonic-gate /*******************************************************************************
8307c478bd9Sstevel@tonic-gate  *
8317c478bd9Sstevel@tonic-gate  * FUNCTION:    AcpiRsGetMethodData
8327c478bd9Sstevel@tonic-gate  *
83330082d0cSmyers  * PARAMETERS:  Handle          - Handle to the containing object
8347c478bd9Sstevel@tonic-gate  *              Path            - Path to method, relative to Handle
83530082d0cSmyers  *              RetBuffer       - Pointer to a buffer structure for the
83630082d0cSmyers  *                                results
8377c478bd9Sstevel@tonic-gate  *
8387c478bd9Sstevel@tonic-gate  * RETURN:      Status
8397c478bd9Sstevel@tonic-gate  *
8407c478bd9Sstevel@tonic-gate  * DESCRIPTION: This function is called to get the _CRS or _PRS value of an
8417c478bd9Sstevel@tonic-gate  *              object contained in an object specified by the handle passed in
8427c478bd9Sstevel@tonic-gate  *
8437c478bd9Sstevel@tonic-gate  *              If the function fails an appropriate status will be returned
8447c478bd9Sstevel@tonic-gate  *              and the contents of the callers buffer is undefined.
8457c478bd9Sstevel@tonic-gate  *
8467c478bd9Sstevel@tonic-gate  ******************************************************************************/
8477c478bd9Sstevel@tonic-gate 
8487c478bd9Sstevel@tonic-gate ACPI_STATUS
AcpiRsGetMethodData(ACPI_HANDLE Handle,const char * Path,ACPI_BUFFER * RetBuffer)8497c478bd9Sstevel@tonic-gate AcpiRsGetMethodData (
8507c478bd9Sstevel@tonic-gate     ACPI_HANDLE             Handle,
8517b1019a6SJerry Jelinek     const char              *Path,
8527c478bd9Sstevel@tonic-gate     ACPI_BUFFER             *RetBuffer)
8537c478bd9Sstevel@tonic-gate {
8547c478bd9Sstevel@tonic-gate     ACPI_OPERAND_OBJECT     *ObjDesc;
8557c478bd9Sstevel@tonic-gate     ACPI_STATUS             Status;
8567c478bd9Sstevel@tonic-gate 
8577c478bd9Sstevel@tonic-gate 
85827f7c583Smyers     ACPI_FUNCTION_TRACE (RsGetMethodData);
8597c478bd9Sstevel@tonic-gate 
8607c478bd9Sstevel@tonic-gate 
8617c478bd9Sstevel@tonic-gate     /* Parameters guaranteed valid by caller */
8627c478bd9Sstevel@tonic-gate 
8637c478bd9Sstevel@tonic-gate     /* Execute the method, no parameters */
8647c478bd9Sstevel@tonic-gate 
8657b1019a6SJerry Jelinek     Status = AcpiUtEvaluateObject (
8667b1019a6SJerry Jelinek         ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Handle),
8677b1019a6SJerry Jelinek         Path, ACPI_BTYPE_BUFFER, &ObjDesc);
86827f7c583Smyers     if (ACPI_FAILURE (Status))
86927f7c583Smyers     {
8707c478bd9Sstevel@tonic-gate         return_ACPI_STATUS (Status);
8717c478bd9Sstevel@tonic-gate     }
8727c478bd9Sstevel@tonic-gate 
8737c478bd9Sstevel@tonic-gate     /*
8747c478bd9Sstevel@tonic-gate      * Make the call to create a resource linked list from the
8757c478bd9Sstevel@tonic-gate      * byte stream buffer that comes back from the method
8767c478bd9Sstevel@tonic-gate      * execution.
8777c478bd9Sstevel@tonic-gate      */
8787c478bd9Sstevel@tonic-gate     Status = AcpiRsCreateResourceList (ObjDesc, RetBuffer);
8797c478bd9Sstevel@tonic-gate 
8807c478bd9Sstevel@tonic-gate     /* On exit, we must delete the object returned by EvaluateObject */
8817c478bd9Sstevel@tonic-gate 
8827c478bd9Sstevel@tonic-gate     AcpiUtRemoveReference (ObjDesc);
8837c478bd9Sstevel@tonic-gate     return_ACPI_STATUS (Status);
8847c478bd9Sstevel@tonic-gate }
8857c478bd9Sstevel@tonic-gate 
88630082d0cSmyers 
8877c478bd9Sstevel@tonic-gate /*******************************************************************************
8887c478bd9Sstevel@tonic-gate  *
8897c478bd9Sstevel@tonic-gate  * FUNCTION:    AcpiRsSetSrsMethodData
8907c478bd9Sstevel@tonic-gate  *
89127f7c583Smyers  * PARAMETERS:  Node            - Device node
89230082d0cSmyers  *              InBuffer        - Pointer to a buffer structure of the
89330082d0cSmyers  *                                parameter
8947c478bd9Sstevel@tonic-gate  *
8957c478bd9Sstevel@tonic-gate  * RETURN:      Status
8967c478bd9Sstevel@tonic-gate  *
8977c478bd9Sstevel@tonic-gate  * DESCRIPTION: This function is called to set the _SRS of an object contained
8987c478bd9Sstevel@tonic-gate  *              in an object specified by the handle passed in
8997c478bd9Sstevel@tonic-gate  *
9007c478bd9Sstevel@tonic-gate  *              If the function fails an appropriate status will be returned
9017c478bd9Sstevel@tonic-gate  *              and the contents of the callers buffer is undefined.
9027c478bd9Sstevel@tonic-gate  *
90327f7c583Smyers  * Note: Parameters guaranteed valid by caller
90427f7c583Smyers  *
9057c478bd9Sstevel@tonic-gate  ******************************************************************************/
9067c478bd9Sstevel@tonic-gate 
9077c478bd9Sstevel@tonic-gate ACPI_STATUS
AcpiRsSetSrsMethodData(ACPI_NAMESPACE_NODE * Node,ACPI_BUFFER * InBuffer)9087c478bd9Sstevel@tonic-gate AcpiRsSetSrsMethodData (
90927f7c583Smyers     ACPI_NAMESPACE_NODE     *Node,
9107c478bd9Sstevel@tonic-gate     ACPI_BUFFER             *InBuffer)
9117c478bd9Sstevel@tonic-gate {
91227f7c583Smyers     ACPI_EVALUATE_INFO      *Info;
91327f7c583Smyers     ACPI_OPERAND_OBJECT     *Args[2];
9147c478bd9Sstevel@tonic-gate     ACPI_STATUS             Status;
9157c478bd9Sstevel@tonic-gate     ACPI_BUFFER             Buffer;
9167c478bd9Sstevel@tonic-gate 
9177c478bd9Sstevel@tonic-gate 
91827f7c583Smyers     ACPI_FUNCTION_TRACE (RsSetSrsMethodData);
9197c478bd9Sstevel@tonic-gate 
9207c478bd9Sstevel@tonic-gate 
92127f7c583Smyers     /* Allocate and initialize the evaluation information block */
92227f7c583Smyers 
92327f7c583Smyers     Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
92427f7c583Smyers     if (!Info)
92527f7c583Smyers     {
92627f7c583Smyers         return_ACPI_STATUS (AE_NO_MEMORY);
92727f7c583Smyers     }
92827f7c583Smyers 
92927f7c583Smyers     Info->PrefixNode = Node;
9307b1019a6SJerry Jelinek     Info->RelativePathname = METHOD_NAME__SRS;
93127f7c583Smyers     Info->Parameters = Args;
93227f7c583Smyers     Info->Flags = ACPI_IGNORE_RETURN_VALUE;
9337c478bd9Sstevel@tonic-gate 
9347c478bd9Sstevel@tonic-gate     /*
9357c478bd9Sstevel@tonic-gate      * The InBuffer parameter will point to a linked list of
93627f7c583Smyers      * resource parameters. It needs to be formatted into a
9377c478bd9Sstevel@tonic-gate      * byte stream to be sent in as an input parameter to _SRS
9387c478bd9Sstevel@tonic-gate      *
9397c478bd9Sstevel@tonic-gate      * Convert the linked list into a byte stream
9407c478bd9Sstevel@tonic-gate      */
9417c478bd9Sstevel@tonic-gate     Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
9427b1019a6SJerry Jelinek     Status = AcpiRsCreateAmlResources (InBuffer, &Buffer);
9437c478bd9Sstevel@tonic-gate     if (ACPI_FAILURE (Status))
9447c478bd9Sstevel@tonic-gate     {
94527f7c583Smyers         goto Cleanup;
9467c478bd9Sstevel@tonic-gate     }
9477c478bd9Sstevel@tonic-gate 
94827f7c583Smyers     /* Create and initialize the method parameter object */
9497c478bd9Sstevel@tonic-gate 
95027f7c583Smyers     Args[0] = AcpiUtCreateInternalObject (ACPI_TYPE_BUFFER);
95127f7c583Smyers     if (!Args[0])
9527c478bd9Sstevel@tonic-gate     {
95327f7c583Smyers         /*
95427f7c583Smyers          * Must free the buffer allocated above (otherwise it is freed
95527f7c583Smyers          * later)
95627f7c583Smyers          */
95727f7c583Smyers         ACPI_FREE (Buffer.Pointer);
95827f7c583Smyers         Status = AE_NO_MEMORY;
95927f7c583Smyers         goto Cleanup;
9607c478bd9Sstevel@tonic-gate     }
9617c478bd9Sstevel@tonic-gate 
96227f7c583Smyers     Args[0]->Buffer.Length  = (UINT32) Buffer.Length;
96327f7c583Smyers     Args[0]->Buffer.Pointer = Buffer.Pointer;
96427f7c583Smyers     Args[0]->Common.Flags   = AOPOBJ_DATA_VALID;
96527f7c583Smyers     Args[1] = NULL;
9667c478bd9Sstevel@tonic-gate 
96727f7c583Smyers     /* Execute the method, no return value is expected */
9687c478bd9Sstevel@tonic-gate 
96927f7c583Smyers     Status = AcpiNsEvaluate (Info);
9707c478bd9Sstevel@tonic-gate 
97127f7c583Smyers     /* Clean up and return the status from AcpiNsEvaluate */
9727c478bd9Sstevel@tonic-gate 
97327f7c583Smyers     AcpiUtRemoveReference (Args[0]);
9747c478bd9Sstevel@tonic-gate 
97527f7c583Smyers Cleanup:
97627f7c583Smyers     ACPI_FREE (Info);
9777c478bd9Sstevel@tonic-gate     return_ACPI_STATUS (Status);
9787c478bd9Sstevel@tonic-gate }
979