rsutils.c revision 228110
167754Smsmith/*******************************************************************************
267754Smsmith *
367754Smsmith * Module Name: rsutils - Utilities for the resource manager
467754Smsmith *
567754Smsmith ******************************************************************************/
667754Smsmith
7217365Sjkim/*
8217365Sjkim * Copyright (C) 2000 - 2011, Intel Corp.
970243Smsmith * All rights reserved.
1067754Smsmith *
11217365Sjkim * Redistribution and use in source and binary forms, with or without
12217365Sjkim * modification, are permitted provided that the following conditions
13217365Sjkim * are met:
14217365Sjkim * 1. Redistributions of source code must retain the above copyright
15217365Sjkim *    notice, this list of conditions, and the following disclaimer,
16217365Sjkim *    without modification.
17217365Sjkim * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18217365Sjkim *    substantially similar to the "NO WARRANTY" disclaimer below
19217365Sjkim *    ("Disclaimer") and any redistribution must be conditioned upon
20217365Sjkim *    including a substantially similar Disclaimer requirement for further
21217365Sjkim *    binary redistribution.
22217365Sjkim * 3. Neither the names of the above-listed copyright holders nor the names
23217365Sjkim *    of any contributors may be used to endorse or promote products derived
24217365Sjkim *    from this software without specific prior written permission.
2567754Smsmith *
26217365Sjkim * Alternatively, this software may be distributed under the terms of the
27217365Sjkim * GNU General Public License ("GPL") version 2 as published by the Free
28217365Sjkim * Software Foundation.
2967754Smsmith *
30217365Sjkim * NO WARRANTY
31217365Sjkim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32217365Sjkim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33217365Sjkim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34217365Sjkim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35217365Sjkim * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36217365Sjkim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37217365Sjkim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38217365Sjkim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39217365Sjkim * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40217365Sjkim * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41217365Sjkim * POSSIBILITY OF SUCH DAMAGES.
42217365Sjkim */
4367754Smsmith
4467754Smsmith
4567754Smsmith#define __RSUTILS_C__
4667754Smsmith
47193341Sjkim#include <contrib/dev/acpica/include/acpi.h>
48193341Sjkim#include <contrib/dev/acpica/include/accommon.h>
49193341Sjkim#include <contrib/dev/acpica/include/acnamesp.h>
50193341Sjkim#include <contrib/dev/acpica/include/acresrc.h>
5167754Smsmith
5267754Smsmith
5377424Smsmith#define _COMPONENT          ACPI_RESOURCES
5491116Smsmith        ACPI_MODULE_NAME    ("rsutils")
5567754Smsmith
5667754Smsmith
5767754Smsmith/*******************************************************************************
5867754Smsmith *
59151937Sjkim * FUNCTION:    AcpiRsDecodeBitmask
60151937Sjkim *
61151937Sjkim * PARAMETERS:  Mask            - Bitmask to decode
62151937Sjkim *              List            - Where the converted list is returned
63151937Sjkim *
64151937Sjkim * RETURN:      Count of bits set (length of list)
65151937Sjkim *
66151937Sjkim * DESCRIPTION: Convert a bit mask into a list of values
67151937Sjkim *
68151937Sjkim ******************************************************************************/
69151937Sjkim
70151937SjkimUINT8
71151937SjkimAcpiRsDecodeBitmask (
72151937Sjkim    UINT16                  Mask,
73151937Sjkim    UINT8                   *List)
74151937Sjkim{
75193267Sjkim    UINT8                   i;
76151937Sjkim    UINT8                   BitCount;
77151937Sjkim
78151937Sjkim
79167802Sjkim    ACPI_FUNCTION_ENTRY ();
80167802Sjkim
81167802Sjkim
82151937Sjkim    /* Decode the mask bits */
83151937Sjkim
84151937Sjkim    for (i = 0, BitCount = 0; Mask; i++)
85151937Sjkim    {
86151937Sjkim        if (Mask & 0x0001)
87151937Sjkim        {
88193267Sjkim            List[BitCount] = i;
89151937Sjkim            BitCount++;
90151937Sjkim        }
91151937Sjkim
92151937Sjkim        Mask >>= 1;
93151937Sjkim    }
94151937Sjkim
95151937Sjkim    return (BitCount);
96151937Sjkim}
97151937Sjkim
98151937Sjkim
99151937Sjkim/*******************************************************************************
100151937Sjkim *
101151937Sjkim * FUNCTION:    AcpiRsEncodeBitmask
102151937Sjkim *
103151937Sjkim * PARAMETERS:  List            - List of values to encode
104151937Sjkim *              Count           - Length of list
105151937Sjkim *
106151937Sjkim * RETURN:      Encoded bitmask
107151937Sjkim *
108151937Sjkim * DESCRIPTION: Convert a list of values to an encoded bitmask
109151937Sjkim *
110151937Sjkim ******************************************************************************/
111151937Sjkim
112151937SjkimUINT16
113151937SjkimAcpiRsEncodeBitmask (
114151937Sjkim    UINT8                   *List,
115151937Sjkim    UINT8                   Count)
116151937Sjkim{
117193267Sjkim    UINT32                  i;
118151937Sjkim    UINT16                  Mask;
119151937Sjkim
120151937Sjkim
121167802Sjkim    ACPI_FUNCTION_ENTRY ();
122167802Sjkim
123167802Sjkim
124151937Sjkim    /* Encode the list into a single bitmask */
125151937Sjkim
126151937Sjkim    for (i = 0, Mask = 0; i < Count; i++)
127151937Sjkim    {
128193267Sjkim        Mask |= (0x1 << List[i]);
129151937Sjkim    }
130151937Sjkim
131151937Sjkim    return (Mask);
132151937Sjkim}
133151937Sjkim
134151937Sjkim
135151937Sjkim/*******************************************************************************
136151937Sjkim *
137151937Sjkim * FUNCTION:    AcpiRsMoveData
138151937Sjkim *
139151937Sjkim * PARAMETERS:  Destination         - Pointer to the destination descriptor
140151937Sjkim *              Source              - Pointer to the source descriptor
141151937Sjkim *              ItemCount           - How many items to move
142151937Sjkim *              MoveType            - Byte width
143151937Sjkim *
144151937Sjkim * RETURN:      None
145151937Sjkim *
146151937Sjkim * DESCRIPTION: Move multiple data items from one descriptor to another. Handles
147151937Sjkim *              alignment issues and endian issues if necessary, as configured
148151937Sjkim *              via the ACPI_MOVE_* macros. (This is why a memcpy is not used)
149151937Sjkim *
150151937Sjkim ******************************************************************************/
151151937Sjkim
152151937Sjkimvoid
153151937SjkimAcpiRsMoveData (
154151937Sjkim    void                    *Destination,
155151937Sjkim    void                    *Source,
156151937Sjkim    UINT16                  ItemCount,
157151937Sjkim    UINT8                   MoveType)
158151937Sjkim{
159193267Sjkim    UINT32                  i;
160151937Sjkim
161151937Sjkim
162167802Sjkim    ACPI_FUNCTION_ENTRY ();
163167802Sjkim
164167802Sjkim
165151937Sjkim    /* One move per item */
166151937Sjkim
167151937Sjkim    for (i = 0; i < ItemCount; i++)
168151937Sjkim    {
169151937Sjkim        switch (MoveType)
170151937Sjkim        {
171151937Sjkim        /*
172151937Sjkim         * For the 8-bit case, we can perform the move all at once
173151937Sjkim         * since there are no alignment or endian issues
174151937Sjkim         */
175151937Sjkim        case ACPI_RSC_MOVE8:
176228110Sjkim        case ACPI_RSC_MOVE_GPIO_RES:
177228110Sjkim        case ACPI_RSC_MOVE_SERIAL_VEN:
178228110Sjkim        case ACPI_RSC_MOVE_SERIAL_RES:
179151937Sjkim            ACPI_MEMCPY (Destination, Source, ItemCount);
180151937Sjkim            return;
181151937Sjkim
182151937Sjkim        /*
183151937Sjkim         * 16-, 32-, and 64-bit cases must use the move macros that perform
184151937Sjkim         * endian conversion and/or accomodate hardware that cannot perform
185151937Sjkim         * misaligned memory transfers
186151937Sjkim         */
187151937Sjkim        case ACPI_RSC_MOVE16:
188228110Sjkim        case ACPI_RSC_MOVE_GPIO_PIN:
189167802Sjkim            ACPI_MOVE_16_TO_16 (&ACPI_CAST_PTR (UINT16, Destination)[i],
190167802Sjkim                                &ACPI_CAST_PTR (UINT16, Source)[i]);
191151937Sjkim            break;
192151937Sjkim
193151937Sjkim        case ACPI_RSC_MOVE32:
194167802Sjkim            ACPI_MOVE_32_TO_32 (&ACPI_CAST_PTR (UINT32, Destination)[i],
195167802Sjkim                                &ACPI_CAST_PTR (UINT32, Source)[i]);
196151937Sjkim            break;
197151937Sjkim
198151937Sjkim        case ACPI_RSC_MOVE64:
199167802Sjkim            ACPI_MOVE_64_TO_64 (&ACPI_CAST_PTR (UINT64, Destination)[i],
200167802Sjkim                                &ACPI_CAST_PTR (UINT64, Source)[i]);
201151937Sjkim            break;
202151937Sjkim
203151937Sjkim        default:
204151937Sjkim            return;
205151937Sjkim        }
206151937Sjkim    }
207151937Sjkim}
208151937Sjkim
209151937Sjkim
210151937Sjkim/*******************************************************************************
211151937Sjkim *
212151937Sjkim * FUNCTION:    AcpiRsSetResourceLength
213151937Sjkim *
214151937Sjkim * PARAMETERS:  TotalLength         - Length of the AML descriptor, including
215151937Sjkim *                                    the header and length fields.
216151937Sjkim *              Aml                 - Pointer to the raw AML descriptor
217151937Sjkim *
218151937Sjkim * RETURN:      None
219151937Sjkim *
220151937Sjkim * DESCRIPTION: Set the ResourceLength field of an AML
221151937Sjkim *              resource descriptor, both Large and Small descriptors are
222151937Sjkim *              supported automatically. Note: Descriptor Type field must
223151937Sjkim *              be valid.
224151937Sjkim *
225151937Sjkim ******************************************************************************/
226151937Sjkim
227151937Sjkimvoid
228151937SjkimAcpiRsSetResourceLength (
229151937Sjkim    ACPI_RSDESC_SIZE        TotalLength,
230151937Sjkim    AML_RESOURCE            *Aml)
231151937Sjkim{
232151937Sjkim    ACPI_RS_LENGTH          ResourceLength;
233151937Sjkim
234151937Sjkim
235151937Sjkim    ACPI_FUNCTION_ENTRY ();
236151937Sjkim
237151937Sjkim
238167802Sjkim    /* Length is the total descriptor length minus the header length */
239151937Sjkim
240167802Sjkim    ResourceLength = (ACPI_RS_LENGTH)
241167802Sjkim        (TotalLength - AcpiUtGetResourceHeaderLength (Aml));
242167802Sjkim
243167802Sjkim    /* Length is stored differently for large and small descriptors */
244167802Sjkim
245151937Sjkim    if (Aml->SmallHeader.DescriptorType & ACPI_RESOURCE_NAME_LARGE)
246151937Sjkim    {
247167802Sjkim        /* Large descriptor -- bytes 1-2 contain the 16-bit length */
248151937Sjkim
249151937Sjkim        ACPI_MOVE_16_TO_16 (&Aml->LargeHeader.ResourceLength, &ResourceLength);
250151937Sjkim    }
251151937Sjkim    else
252151937Sjkim    {
253167802Sjkim        /* Small descriptor -- bits 2:0 of byte 0 contain the length */
254151937Sjkim
255151937Sjkim        Aml->SmallHeader.DescriptorType = (UINT8)
256151937Sjkim
257151937Sjkim            /* Clear any existing length, preserving descriptor type bits */
258151937Sjkim
259151937Sjkim            ((Aml->SmallHeader.DescriptorType & ~ACPI_RESOURCE_NAME_SMALL_LENGTH_MASK)
260151937Sjkim
261151937Sjkim            | ResourceLength);
262151937Sjkim    }
263151937Sjkim}
264151937Sjkim
265151937Sjkim
266151937Sjkim/*******************************************************************************
267151937Sjkim *
268151937Sjkim * FUNCTION:    AcpiRsSetResourceHeader
269151937Sjkim *
270151937Sjkim * PARAMETERS:  DescriptorType      - Byte to be inserted as the type
271151937Sjkim *              TotalLength         - Length of the AML descriptor, including
272151937Sjkim *                                    the header and length fields.
273151937Sjkim *              Aml                 - Pointer to the raw AML descriptor
274151937Sjkim *
275151937Sjkim * RETURN:      None
276151937Sjkim *
277151937Sjkim * DESCRIPTION: Set the DescriptorType and ResourceLength fields of an AML
278151937Sjkim *              resource descriptor, both Large and Small descriptors are
279151937Sjkim *              supported automatically
280151937Sjkim *
281151937Sjkim ******************************************************************************/
282151937Sjkim
283151937Sjkimvoid
284151937SjkimAcpiRsSetResourceHeader (
285151937Sjkim    UINT8                   DescriptorType,
286151937Sjkim    ACPI_RSDESC_SIZE        TotalLength,
287151937Sjkim    AML_RESOURCE            *Aml)
288151937Sjkim{
289151937Sjkim    ACPI_FUNCTION_ENTRY ();
290151937Sjkim
291151937Sjkim
292167802Sjkim    /* Set the Resource Type */
293151937Sjkim
294151937Sjkim    Aml->SmallHeader.DescriptorType = DescriptorType;
295151937Sjkim
296151937Sjkim    /* Set the Resource Length */
297151937Sjkim
298151937Sjkim    AcpiRsSetResourceLength (TotalLength, Aml);
299151937Sjkim}
300151937Sjkim
301151937Sjkim
302151937Sjkim/*******************************************************************************
303151937Sjkim *
304151937Sjkim * FUNCTION:    AcpiRsStrcpy
305151937Sjkim *
306151937Sjkim * PARAMETERS:  Destination         - Pointer to the destination string
307151937Sjkim *              Source              - Pointer to the source string
308151937Sjkim *
309151937Sjkim * RETURN:      String length, including NULL terminator
310151937Sjkim *
311151937Sjkim * DESCRIPTION: Local string copy that returns the string length, saving a
312151937Sjkim *              strcpy followed by a strlen.
313151937Sjkim *
314151937Sjkim ******************************************************************************/
315151937Sjkim
316151937Sjkimstatic UINT16
317151937SjkimAcpiRsStrcpy (
318151937Sjkim    char                    *Destination,
319151937Sjkim    char                    *Source)
320151937Sjkim{
321151937Sjkim    UINT16                  i;
322151937Sjkim
323151937Sjkim
324151937Sjkim    ACPI_FUNCTION_ENTRY ();
325151937Sjkim
326151937Sjkim
327151937Sjkim    for (i = 0; Source[i]; i++)
328151937Sjkim    {
329151937Sjkim        Destination[i] = Source[i];
330151937Sjkim    }
331151937Sjkim
332151937Sjkim    Destination[i] = 0;
333151937Sjkim
334151937Sjkim    /* Return string length including the NULL terminator */
335151937Sjkim
336151937Sjkim    return ((UINT16) (i + 1));
337151937Sjkim}
338151937Sjkim
339151937Sjkim
340151937Sjkim/*******************************************************************************
341151937Sjkim *
342151937Sjkim * FUNCTION:    AcpiRsGetResourceSource
343151937Sjkim *
344151937Sjkim * PARAMETERS:  ResourceLength      - Length field of the descriptor
345151937Sjkim *              MinimumLength       - Minimum length of the descriptor (minus
346151937Sjkim *                                    any optional fields)
347151937Sjkim *              ResourceSource      - Where the ResourceSource is returned
348151937Sjkim *              Aml                 - Pointer to the raw AML descriptor
349151937Sjkim *              StringPtr           - (optional) where to store the actual
350151937Sjkim *                                    ResourceSource string
351151937Sjkim *
352167802Sjkim * RETURN:      Length of the string plus NULL terminator, rounded up to native
353167802Sjkim *              word boundary
354151937Sjkim *
355151937Sjkim * DESCRIPTION: Copy the optional ResourceSource data from a raw AML descriptor
356151937Sjkim *              to an internal resource descriptor
357151937Sjkim *
358151937Sjkim ******************************************************************************/
359151937Sjkim
360151937SjkimACPI_RS_LENGTH
361151937SjkimAcpiRsGetResourceSource (
362151937Sjkim    ACPI_RS_LENGTH          ResourceLength,
363151937Sjkim    ACPI_RS_LENGTH          MinimumLength,
364151937Sjkim    ACPI_RESOURCE_SOURCE    *ResourceSource,
365151937Sjkim    AML_RESOURCE            *Aml,
366151937Sjkim    char                    *StringPtr)
367151937Sjkim{
368151937Sjkim    ACPI_RSDESC_SIZE        TotalLength;
369151937Sjkim    UINT8                   *AmlResourceSource;
370151937Sjkim
371151937Sjkim
372151937Sjkim    ACPI_FUNCTION_ENTRY ();
373151937Sjkim
374151937Sjkim
375151937Sjkim    TotalLength = ResourceLength + sizeof (AML_RESOURCE_LARGE_HEADER);
376167802Sjkim    AmlResourceSource = ACPI_ADD_PTR (UINT8, Aml, MinimumLength);
377151937Sjkim
378151937Sjkim    /*
379151937Sjkim     * ResourceSource is present if the length of the descriptor is longer than
380151937Sjkim     * the minimum length.
381151937Sjkim     *
382151937Sjkim     * Note: Some resource descriptors will have an additional null, so
383151937Sjkim     * we add 1 to the minimum length.
384151937Sjkim     */
385167802Sjkim    if (TotalLength > (ACPI_RSDESC_SIZE) (MinimumLength + 1))
386151937Sjkim    {
387151937Sjkim        /* Get the ResourceSourceIndex */
388151937Sjkim
389151937Sjkim        ResourceSource->Index = AmlResourceSource[0];
390151937Sjkim
391151937Sjkim        ResourceSource->StringPtr = StringPtr;
392151937Sjkim        if (!StringPtr)
393151937Sjkim        {
394151937Sjkim            /*
395151937Sjkim             * String destination pointer is not specified; Set the String
396151937Sjkim             * pointer to the end of the current ResourceSource structure.
397151937Sjkim             */
398167802Sjkim            ResourceSource->StringPtr = ACPI_ADD_PTR (char, ResourceSource,
399167802Sjkim                sizeof (ACPI_RESOURCE_SOURCE));
400151937Sjkim        }
401151937Sjkim
402151937Sjkim        /*
403167802Sjkim         * In order for the Resource length to be a multiple of the native
404167802Sjkim         * word, calculate the length of the string (+1 for NULL terminator)
405167802Sjkim         * and expand to the next word multiple.
406151937Sjkim         *
407151937Sjkim         * Zero the entire area of the buffer.
408151937Sjkim         */
409167802Sjkim        TotalLength = (UINT32) ACPI_STRLEN (
410167802Sjkim            ACPI_CAST_PTR (char, &AmlResourceSource[1])) + 1;
411167802Sjkim        TotalLength = (UINT32) ACPI_ROUND_UP_TO_NATIVE_WORD (TotalLength);
412167802Sjkim
413151937Sjkim        ACPI_MEMSET (ResourceSource->StringPtr, 0, TotalLength);
414151937Sjkim
415151937Sjkim        /* Copy the ResourceSource string to the destination */
416151937Sjkim
417151937Sjkim        ResourceSource->StringLength = AcpiRsStrcpy (ResourceSource->StringPtr,
418167802Sjkim            ACPI_CAST_PTR (char, &AmlResourceSource[1]));
419151937Sjkim
420151937Sjkim        return ((ACPI_RS_LENGTH) TotalLength);
421151937Sjkim    }
422151937Sjkim
423167802Sjkim    /* ResourceSource is not present */
424167802Sjkim
425167802Sjkim    ResourceSource->Index = 0;
426167802Sjkim    ResourceSource->StringLength = 0;
427167802Sjkim    ResourceSource->StringPtr = NULL;
428167802Sjkim    return (0);
429151937Sjkim}
430151937Sjkim
431167802Sjkim
432151937Sjkim/*******************************************************************************
433151937Sjkim *
434151937Sjkim * FUNCTION:    AcpiRsSetResourceSource
435151937Sjkim *
436151937Sjkim * PARAMETERS:  Aml                 - Pointer to the raw AML descriptor
437151937Sjkim *              MinimumLength       - Minimum length of the descriptor (minus
438151937Sjkim *                                    any optional fields)
439151937Sjkim *              ResourceSource      - Internal ResourceSource
440151937Sjkim
441151937Sjkim *
442151937Sjkim * RETURN:      Total length of the AML descriptor
443151937Sjkim *
444151937Sjkim * DESCRIPTION: Convert an optional ResourceSource from internal format to a
445151937Sjkim *              raw AML resource descriptor
446151937Sjkim *
447151937Sjkim ******************************************************************************/
448151937Sjkim
449151937SjkimACPI_RSDESC_SIZE
450151937SjkimAcpiRsSetResourceSource (
451151937Sjkim    AML_RESOURCE            *Aml,
452151937Sjkim    ACPI_RS_LENGTH          MinimumLength,
453151937Sjkim    ACPI_RESOURCE_SOURCE    *ResourceSource)
454151937Sjkim{
455151937Sjkim    UINT8                   *AmlResourceSource;
456151937Sjkim    ACPI_RSDESC_SIZE        DescriptorLength;
457151937Sjkim
458151937Sjkim
459151937Sjkim    ACPI_FUNCTION_ENTRY ();
460151937Sjkim
461151937Sjkim
462151937Sjkim    DescriptorLength = MinimumLength;
463151937Sjkim
464151937Sjkim    /* Non-zero string length indicates presence of a ResourceSource */
465151937Sjkim
466151937Sjkim    if (ResourceSource->StringLength)
467151937Sjkim    {
468151937Sjkim        /* Point to the end of the AML descriptor */
469151937Sjkim
470167802Sjkim        AmlResourceSource = ACPI_ADD_PTR (UINT8, Aml, MinimumLength);
471151937Sjkim
472151937Sjkim        /* Copy the ResourceSourceIndex */
473151937Sjkim
474151937Sjkim        AmlResourceSource[0] = (UINT8) ResourceSource->Index;
475151937Sjkim
476151937Sjkim        /* Copy the ResourceSource string */
477151937Sjkim
478167802Sjkim        ACPI_STRCPY (ACPI_CAST_PTR (char, &AmlResourceSource[1]),
479167802Sjkim            ResourceSource->StringPtr);
480151937Sjkim
481151937Sjkim        /*
482151937Sjkim         * Add the length of the string (+ 1 for null terminator) to the
483151937Sjkim         * final descriptor length
484151937Sjkim         */
485151937Sjkim        DescriptorLength += ((ACPI_RSDESC_SIZE) ResourceSource->StringLength + 1);
486151937Sjkim    }
487151937Sjkim
488151937Sjkim    /* Return the new total length of the AML descriptor */
489151937Sjkim
490151937Sjkim    return (DescriptorLength);
491151937Sjkim}
492151937Sjkim
493151937Sjkim
494151937Sjkim/*******************************************************************************
495151937Sjkim *
49667754Smsmith * FUNCTION:    AcpiRsGetPrtMethodData
49767754Smsmith *
498167802Sjkim * PARAMETERS:  Node            - Device node
499167802Sjkim *              RetBuffer       - Pointer to a buffer structure for the
500167802Sjkim *                                results
50167754Smsmith *
50277424Smsmith * RETURN:      Status
50367754Smsmith *
50467754Smsmith * DESCRIPTION: This function is called to get the _PRT value of an object
50567754Smsmith *              contained in an object specified by the handle passed in
50667754Smsmith *
50767754Smsmith *              If the function fails an appropriate status will be returned
50867754Smsmith *              and the contents of the callers buffer is undefined.
50967754Smsmith *
51067754Smsmith ******************************************************************************/
51167754Smsmith
51267754SmsmithACPI_STATUS
51367754SmsmithAcpiRsGetPrtMethodData (
514167802Sjkim    ACPI_NAMESPACE_NODE     *Node,
51567754Smsmith    ACPI_BUFFER             *RetBuffer)
51667754Smsmith{
51799679Siwasaki    ACPI_OPERAND_OBJECT     *ObjDesc;
51867754Smsmith    ACPI_STATUS             Status;
51967754Smsmith
52067754Smsmith
521167802Sjkim    ACPI_FUNCTION_TRACE (RsGetPrtMethodData);
52267754Smsmith
52367754Smsmith
52491116Smsmith    /* Parameters guaranteed valid by caller */
52567754Smsmith
526151937Sjkim    /* Execute the method, no parameters */
527151937Sjkim
528167802Sjkim    Status = AcpiUtEvaluateObject (Node, METHOD_NAME__PRT,
529151937Sjkim                ACPI_BTYPE_PACKAGE, &ObjDesc);
53067754Smsmith    if (ACPI_FAILURE (Status))
53167754Smsmith    {
53267754Smsmith        return_ACPI_STATUS (Status);
53367754Smsmith    }
53467754Smsmith
53567754Smsmith    /*
53691116Smsmith     * Create a resource linked list from the byte stream buffer that comes
53791116Smsmith     * back from the _CRS method execution.
53867754Smsmith     */
53999679Siwasaki    Status = AcpiRsCreatePciRoutingTable (ObjDesc, RetBuffer);
54067754Smsmith
54191116Smsmith    /* On exit, we must delete the object returned by EvaluateObject */
54267754Smsmith
54399679Siwasaki    AcpiUtRemoveReference (ObjDesc);
54467754Smsmith    return_ACPI_STATUS (Status);
54567754Smsmith}
54667754Smsmith
54767754Smsmith
54867754Smsmith/*******************************************************************************
54967754Smsmith *
55067754Smsmith * FUNCTION:    AcpiRsGetCrsMethodData
55167754Smsmith *
552167802Sjkim * PARAMETERS:  Node            - Device node
553167802Sjkim *              RetBuffer       - Pointer to a buffer structure for the
554167802Sjkim *                                results
55567754Smsmith *
55677424Smsmith * RETURN:      Status
55767754Smsmith *
55867754Smsmith * DESCRIPTION: This function is called to get the _CRS value of an object
55967754Smsmith *              contained in an object specified by the handle passed in
56067754Smsmith *
56167754Smsmith *              If the function fails an appropriate status will be returned
56267754Smsmith *              and the contents of the callers buffer is undefined.
56367754Smsmith *
56467754Smsmith ******************************************************************************/
56567754Smsmith
56667754SmsmithACPI_STATUS
56767754SmsmithAcpiRsGetCrsMethodData (
568167802Sjkim    ACPI_NAMESPACE_NODE     *Node,
56967754Smsmith    ACPI_BUFFER             *RetBuffer)
57067754Smsmith{
57199679Siwasaki    ACPI_OPERAND_OBJECT     *ObjDesc;
57267754Smsmith    ACPI_STATUS             Status;
57367754Smsmith
57467754Smsmith
575167802Sjkim    ACPI_FUNCTION_TRACE (RsGetCrsMethodData);
57667754Smsmith
57767754Smsmith
57891116Smsmith    /* Parameters guaranteed valid by caller */
57967754Smsmith
580151937Sjkim    /* Execute the method, no parameters */
581151937Sjkim
582167802Sjkim    Status = AcpiUtEvaluateObject (Node, METHOD_NAME__CRS,
583151937Sjkim                ACPI_BTYPE_BUFFER, &ObjDesc);
58467754Smsmith    if (ACPI_FAILURE (Status))
58567754Smsmith    {
58667754Smsmith        return_ACPI_STATUS (Status);
58767754Smsmith    }
58867754Smsmith
58967754Smsmith    /*
59067754Smsmith     * Make the call to create a resource linked list from the
59191116Smsmith     * byte stream buffer that comes back from the _CRS method
59291116Smsmith     * execution.
59367754Smsmith     */
59499679Siwasaki    Status = AcpiRsCreateResourceList (ObjDesc, RetBuffer);
59567754Smsmith
59667754Smsmith    /* On exit, we must delete the object returned by evaluateObject */
59767754Smsmith
59899679Siwasaki    AcpiUtRemoveReference (ObjDesc);
59967754Smsmith    return_ACPI_STATUS (Status);
60067754Smsmith}
60167754Smsmith
60267754Smsmith
60367754Smsmith/*******************************************************************************
60467754Smsmith *
60567754Smsmith * FUNCTION:    AcpiRsGetPrsMethodData
60667754Smsmith *
607167802Sjkim * PARAMETERS:  Node            - Device node
608167802Sjkim *              RetBuffer       - Pointer to a buffer structure for the
609167802Sjkim *                                results
61067754Smsmith *
61177424Smsmith * RETURN:      Status
61267754Smsmith *
61367754Smsmith * DESCRIPTION: This function is called to get the _PRS value of an object
61467754Smsmith *              contained in an object specified by the handle passed in
61567754Smsmith *
61667754Smsmith *              If the function fails an appropriate status will be returned
61767754Smsmith *              and the contents of the callers buffer is undefined.
61867754Smsmith *
61967754Smsmith ******************************************************************************/
62067754Smsmith
62167754SmsmithACPI_STATUS
62267754SmsmithAcpiRsGetPrsMethodData (
623167802Sjkim    ACPI_NAMESPACE_NODE     *Node,
62467754Smsmith    ACPI_BUFFER             *RetBuffer)
62567754Smsmith{
62699679Siwasaki    ACPI_OPERAND_OBJECT     *ObjDesc;
62767754Smsmith    ACPI_STATUS             Status;
62867754Smsmith
62967754Smsmith
630167802Sjkim    ACPI_FUNCTION_TRACE (RsGetPrsMethodData);
63167754Smsmith
63267754Smsmith
63391116Smsmith    /* Parameters guaranteed valid by caller */
63467754Smsmith
635151937Sjkim    /* Execute the method, no parameters */
636151937Sjkim
637167802Sjkim    Status = AcpiUtEvaluateObject (Node, METHOD_NAME__PRS,
638151937Sjkim                ACPI_BTYPE_BUFFER, &ObjDesc);
63967754Smsmith    if (ACPI_FAILURE (Status))
64067754Smsmith    {
64167754Smsmith        return_ACPI_STATUS (Status);
64267754Smsmith    }
64367754Smsmith
644114237Snjl    /*
645114237Snjl     * Make the call to create a resource linked list from the
646114237Snjl     * byte stream buffer that comes back from the _CRS method
647114237Snjl     * execution.
648114237Snjl     */
649114237Snjl    Status = AcpiRsCreateResourceList (ObjDesc, RetBuffer);
65067754Smsmith
651114237Snjl    /* On exit, we must delete the object returned by evaluateObject */
65267754Smsmith
653114237Snjl    AcpiUtRemoveReference (ObjDesc);
654114237Snjl    return_ACPI_STATUS (Status);
655114237Snjl}
656114237Snjl
657114237Snjl
658114237Snjl/*******************************************************************************
659114237Snjl *
660228110Sjkim * FUNCTION:    AcpiRsGetAeiMethodData
661228110Sjkim *
662228110Sjkim * PARAMETERS:  Node            - Device node
663228110Sjkim *              RetBuffer       - Pointer to a buffer structure for the
664228110Sjkim *                                results
665228110Sjkim *
666228110Sjkim * RETURN:      Status
667228110Sjkim *
668228110Sjkim * DESCRIPTION: This function is called to get the _AEI value of an object
669228110Sjkim *              contained in an object specified by the handle passed in
670228110Sjkim *
671228110Sjkim *              If the function fails an appropriate status will be returned
672228110Sjkim *              and the contents of the callers buffer is undefined.
673228110Sjkim *
674228110Sjkim ******************************************************************************/
675228110Sjkim
676228110SjkimACPI_STATUS
677228110SjkimAcpiRsGetAeiMethodData (
678228110Sjkim    ACPI_NAMESPACE_NODE     *Node,
679228110Sjkim    ACPI_BUFFER             *RetBuffer)
680228110Sjkim{
681228110Sjkim    ACPI_OPERAND_OBJECT     *ObjDesc;
682228110Sjkim    ACPI_STATUS             Status;
683228110Sjkim
684228110Sjkim
685228110Sjkim    ACPI_FUNCTION_TRACE (RsGetAeiMethodData);
686228110Sjkim
687228110Sjkim
688228110Sjkim    /* Parameters guaranteed valid by caller */
689228110Sjkim
690228110Sjkim    /* Execute the method, no parameters */
691228110Sjkim
692228110Sjkim    Status = AcpiUtEvaluateObject (Node, METHOD_NAME__AEI,
693228110Sjkim                ACPI_BTYPE_BUFFER, &ObjDesc);
694228110Sjkim    if (ACPI_FAILURE (Status))
695228110Sjkim    {
696228110Sjkim        return_ACPI_STATUS (Status);
697228110Sjkim    }
698228110Sjkim
699228110Sjkim    /*
700228110Sjkim     * Make the call to create a resource linked list from the
701228110Sjkim     * byte stream buffer that comes back from the _CRS method
702228110Sjkim     * execution.
703228110Sjkim     */
704228110Sjkim    Status = AcpiRsCreateResourceList (ObjDesc, RetBuffer);
705228110Sjkim
706228110Sjkim    /* On exit, we must delete the object returned by evaluateObject */
707228110Sjkim
708228110Sjkim    AcpiUtRemoveReference (ObjDesc);
709228110Sjkim    return_ACPI_STATUS (Status);
710228110Sjkim}
711228110Sjkim
712228110Sjkim
713228110Sjkim/*******************************************************************************
714228110Sjkim *
715114237Snjl * FUNCTION:    AcpiRsGetMethodData
716114237Snjl *
717167802Sjkim * PARAMETERS:  Handle          - Handle to the containing object
718151937Sjkim *              Path            - Path to method, relative to Handle
719167802Sjkim *              RetBuffer       - Pointer to a buffer structure for the
720167802Sjkim *                                results
721114237Snjl *
722114237Snjl * RETURN:      Status
723114237Snjl *
724114237Snjl * DESCRIPTION: This function is called to get the _CRS or _PRS value of an
725114237Snjl *              object contained in an object specified by the handle passed in
726114237Snjl *
727114237Snjl *              If the function fails an appropriate status will be returned
728114237Snjl *              and the contents of the callers buffer is undefined.
729114237Snjl *
730114237Snjl ******************************************************************************/
731114237Snjl
732114237SnjlACPI_STATUS
733114237SnjlAcpiRsGetMethodData (
734114237Snjl    ACPI_HANDLE             Handle,
735114237Snjl    char                    *Path,
736114237Snjl    ACPI_BUFFER             *RetBuffer)
737114237Snjl{
738114237Snjl    ACPI_OPERAND_OBJECT     *ObjDesc;
739114237Snjl    ACPI_STATUS             Status;
740114237Snjl
741114237Snjl
742167802Sjkim    ACPI_FUNCTION_TRACE (RsGetMethodData);
743114237Snjl
744114237Snjl
745114237Snjl    /* Parameters guaranteed valid by caller */
746114237Snjl
747151937Sjkim    /* Execute the method, no parameters */
748151937Sjkim
749114237Snjl    Status = AcpiUtEvaluateObject (Handle, Path, ACPI_BTYPE_BUFFER, &ObjDesc);
750167802Sjkim    if (ACPI_FAILURE (Status))
751167802Sjkim    {
752114237Snjl        return_ACPI_STATUS (Status);
75367754Smsmith    }
75467754Smsmith
75567754Smsmith    /*
75667754Smsmith     * Make the call to create a resource linked list from the
757114237Snjl     * byte stream buffer that comes back from the method
75891116Smsmith     * execution.
75967754Smsmith     */
76099679Siwasaki    Status = AcpiRsCreateResourceList (ObjDesc, RetBuffer);
76167754Smsmith
762114237Snjl    /* On exit, we must delete the object returned by EvaluateObject */
76367754Smsmith
76499679Siwasaki    AcpiUtRemoveReference (ObjDesc);
76567754Smsmith    return_ACPI_STATUS (Status);
76667754Smsmith}
76767754Smsmith
768167802Sjkim
76967754Smsmith/*******************************************************************************
77067754Smsmith *
77167754Smsmith * FUNCTION:    AcpiRsSetSrsMethodData
77267754Smsmith *
773167802Sjkim * PARAMETERS:  Node            - Device node
774167802Sjkim *              InBuffer        - Pointer to a buffer structure of the
775167802Sjkim *                                parameter
77667754Smsmith *
77777424Smsmith * RETURN:      Status
77867754Smsmith *
77967754Smsmith * DESCRIPTION: This function is called to set the _SRS of an object contained
78067754Smsmith *              in an object specified by the handle passed in
78167754Smsmith *
78267754Smsmith *              If the function fails an appropriate status will be returned
78367754Smsmith *              and the contents of the callers buffer is undefined.
78467754Smsmith *
785167802Sjkim * Note: Parameters guaranteed valid by caller
786167802Sjkim *
78767754Smsmith ******************************************************************************/
78867754Smsmith
78967754SmsmithACPI_STATUS
79067754SmsmithAcpiRsSetSrsMethodData (
791167802Sjkim    ACPI_NAMESPACE_NODE     *Node,
79267754Smsmith    ACPI_BUFFER             *InBuffer)
79367754Smsmith{
794167802Sjkim    ACPI_EVALUATE_INFO      *Info;
795167802Sjkim    ACPI_OPERAND_OBJECT     *Args[2];
79667754Smsmith    ACPI_STATUS             Status;
79791116Smsmith    ACPI_BUFFER             Buffer;
79867754Smsmith
79967754Smsmith
800167802Sjkim    ACPI_FUNCTION_TRACE (RsSetSrsMethodData);
80167754Smsmith
80267754Smsmith
803167802Sjkim    /* Allocate and initialize the evaluation information block */
80467754Smsmith
805167802Sjkim    Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
806167802Sjkim    if (!Info)
807167802Sjkim    {
808167802Sjkim        return_ACPI_STATUS (AE_NO_MEMORY);
809167802Sjkim    }
810167802Sjkim
811167802Sjkim    Info->PrefixNode = Node;
812167802Sjkim    Info->Pathname = METHOD_NAME__SRS;
813167802Sjkim    Info->Parameters = Args;
814167802Sjkim    Info->Flags = ACPI_IGNORE_RETURN_VALUE;
815167802Sjkim
81667754Smsmith    /*
81767754Smsmith     * The InBuffer parameter will point to a linked list of
818167802Sjkim     * resource parameters. It needs to be formatted into a
81991116Smsmith     * byte stream to be sent in as an input parameter to _SRS
82091116Smsmith     *
82191116Smsmith     * Convert the linked list into a byte stream
82267754Smsmith     */
82391116Smsmith    Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
824151937Sjkim    Status = AcpiRsCreateAmlResources (InBuffer->Pointer, &Buffer);
82591116Smsmith    if (ACPI_FAILURE (Status))
82667754Smsmith    {
827167802Sjkim        goto Cleanup;
82867754Smsmith    }
82967754Smsmith
830167802Sjkim    /* Create and initialize the method parameter object */
831151937Sjkim
832167802Sjkim    Args[0] = AcpiUtCreateInternalObject (ACPI_TYPE_BUFFER);
833167802Sjkim    if (!Args[0])
83484491Smsmith    {
835167802Sjkim        /*
836167802Sjkim         * Must free the buffer allocated above (otherwise it is freed
837167802Sjkim         * later)
838167802Sjkim         */
839167802Sjkim        ACPI_FREE (Buffer.Pointer);
840167802Sjkim        Status = AE_NO_MEMORY;
841167802Sjkim        goto Cleanup;
84284491Smsmith    }
84367754Smsmith
844167802Sjkim    Args[0]->Buffer.Length  = (UINT32) Buffer.Length;
845167802Sjkim    Args[0]->Buffer.Pointer = Buffer.Pointer;
846167802Sjkim    Args[0]->Common.Flags   = AOPOBJ_DATA_VALID;
847167802Sjkim    Args[1] = NULL;
848151937Sjkim
849167802Sjkim    /* Execute the method, no return value is expected */
85067754Smsmith
851167802Sjkim    Status = AcpiNsEvaluate (Info);
852129684Snjl
853167802Sjkim    /* Clean up and return the status from AcpiNsEvaluate */
85467754Smsmith
855167802Sjkim    AcpiUtRemoveReference (Args[0]);
856151937Sjkim
857167802SjkimCleanup:
858167802Sjkim    ACPI_FREE (Info);
85967754Smsmith    return_ACPI_STATUS (Status);
86067754Smsmith}
86167754Smsmith
862