1/*******************************************************************************
2 *
3 * Module Name: rsutils - Utilities for the resource manager
4 *
5 ******************************************************************************/
6
7/******************************************************************************
8 *
9 * 1. Copyright Notice
10 *
11 * Some or all of this work - Copyright (c) 1999 - 2012, Intel Corp.
12 * All rights reserved.
13 *
14 * 2. License
15 *
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
19 * property rights.
20 *
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
27 *
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
36 *
37 * The above copyright and patent license is granted only if the following
38 * conditions are met:
39 *
40 * 3. Conditions
41 *
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
53 *
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
64 * make.
65 *
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
70 * distribution.
71 *
72 * 3.4. Intel retains all right, title, and interest in and to the Original
73 * Intel Code.
74 *
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
79 *
80 * 4. Disclaimer and Export Compliance
81 *
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88 * PARTICULAR PURPOSE.
89 *
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97 * LIMITED REMEDY.
98 *
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
113 *
114 *****************************************************************************/
115
116
117#define __RSUTILS_C__
118
119#include "acpi.h"
120#include "accommon.h"
121#include "acnamesp.h"
122#include "acresrc.h"
123
124
125#define _COMPONENT          ACPI_RESOURCES
126        ACPI_MODULE_NAME    ("rsutils")
127
128
129/*******************************************************************************
130 *
131 * FUNCTION:    AcpiRsDecodeBitmask
132 *
133 * PARAMETERS:  Mask            - Bitmask to decode
134 *              List            - Where the converted list is returned
135 *
136 * RETURN:      Count of bits set (length of list)
137 *
138 * DESCRIPTION: Convert a bit mask into a list of values
139 *
140 ******************************************************************************/
141
142UINT8
143AcpiRsDecodeBitmask (
144    UINT16                  Mask,
145    UINT8                   *List)
146{
147    UINT8                   i;
148    UINT8                   BitCount;
149
150
151    ACPI_FUNCTION_ENTRY ();
152
153
154    /* Decode the mask bits */
155
156    for (i = 0, BitCount = 0; Mask; i++)
157    {
158        if (Mask & 0x0001)
159        {
160            List[BitCount] = i;
161            BitCount++;
162        }
163
164        Mask >>= 1;
165    }
166
167    return (BitCount);
168}
169
170
171/*******************************************************************************
172 *
173 * FUNCTION:    AcpiRsEncodeBitmask
174 *
175 * PARAMETERS:  List            - List of values to encode
176 *              Count           - Length of list
177 *
178 * RETURN:      Encoded bitmask
179 *
180 * DESCRIPTION: Convert a list of values to an encoded bitmask
181 *
182 ******************************************************************************/
183
184UINT16
185AcpiRsEncodeBitmask (
186    UINT8                   *List,
187    UINT8                   Count)
188{
189    UINT32                  i;
190    UINT16                  Mask;
191
192
193    ACPI_FUNCTION_ENTRY ();
194
195
196    /* Encode the list into a single bitmask */
197
198    for (i = 0, Mask = 0; i < Count; i++)
199    {
200        Mask |= (0x1 << List[i]);
201    }
202
203    return (Mask);
204}
205
206
207/*******************************************************************************
208 *
209 * FUNCTION:    AcpiRsMoveData
210 *
211 * PARAMETERS:  Destination         - Pointer to the destination descriptor
212 *              Source              - Pointer to the source descriptor
213 *              ItemCount           - How many items to move
214 *              MoveType            - Byte width
215 *
216 * RETURN:      None
217 *
218 * DESCRIPTION: Move multiple data items from one descriptor to another. Handles
219 *              alignment issues and endian issues if necessary, as configured
220 *              via the ACPI_MOVE_* macros. (This is why a memcpy is not used)
221 *
222 ******************************************************************************/
223
224void
225AcpiRsMoveData (
226    void                    *Destination,
227    void                    *Source,
228    UINT16                  ItemCount,
229    UINT8                   MoveType)
230{
231    UINT32                  i;
232
233
234    ACPI_FUNCTION_ENTRY ();
235
236
237    /* One move per item */
238
239    for (i = 0; i < ItemCount; i++)
240    {
241        switch (MoveType)
242        {
243        /*
244         * For the 8-bit case, we can perform the move all at once
245         * since there are no alignment or endian issues
246         */
247        case ACPI_RSC_MOVE8:
248        case ACPI_RSC_MOVE_GPIO_RES:
249        case ACPI_RSC_MOVE_SERIAL_VEN:
250        case ACPI_RSC_MOVE_SERIAL_RES:
251            ACPI_MEMCPY (Destination, Source, ItemCount);
252            return;
253
254        /*
255         * 16-, 32-, and 64-bit cases must use the move macros that perform
256         * endian conversion and/or accommodate hardware that cannot perform
257         * misaligned memory transfers
258         */
259        case ACPI_RSC_MOVE16:
260        case ACPI_RSC_MOVE_GPIO_PIN:
261            ACPI_MOVE_16_TO_16 (&ACPI_CAST_PTR (UINT16, Destination)[i],
262                                &ACPI_CAST_PTR (UINT16, Source)[i]);
263            break;
264
265        case ACPI_RSC_MOVE32:
266            ACPI_MOVE_32_TO_32 (&ACPI_CAST_PTR (UINT32, Destination)[i],
267                                &ACPI_CAST_PTR (UINT32, Source)[i]);
268            break;
269
270        case ACPI_RSC_MOVE64:
271            ACPI_MOVE_64_TO_64 (&ACPI_CAST_PTR (UINT64, Destination)[i],
272                                &ACPI_CAST_PTR (UINT64, Source)[i]);
273            break;
274
275        default:
276            return;
277        }
278    }
279}
280
281
282/*******************************************************************************
283 *
284 * FUNCTION:    AcpiRsSetResourceLength
285 *
286 * PARAMETERS:  TotalLength         - Length of the AML descriptor, including
287 *                                    the header and length fields.
288 *              Aml                 - Pointer to the raw AML descriptor
289 *
290 * RETURN:      None
291 *
292 * DESCRIPTION: Set the ResourceLength field of an AML
293 *              resource descriptor, both Large and Small descriptors are
294 *              supported automatically. Note: Descriptor Type field must
295 *              be valid.
296 *
297 ******************************************************************************/
298
299void
300AcpiRsSetResourceLength (
301    ACPI_RSDESC_SIZE        TotalLength,
302    AML_RESOURCE            *Aml)
303{
304    ACPI_RS_LENGTH          ResourceLength;
305
306
307    ACPI_FUNCTION_ENTRY ();
308
309
310    /* Length is the total descriptor length minus the header length */
311
312    ResourceLength = (ACPI_RS_LENGTH)
313        (TotalLength - AcpiUtGetResourceHeaderLength (Aml));
314
315    /* Length is stored differently for large and small descriptors */
316
317    if (Aml->SmallHeader.DescriptorType & ACPI_RESOURCE_NAME_LARGE)
318    {
319        /* Large descriptor -- bytes 1-2 contain the 16-bit length */
320
321        ACPI_MOVE_16_TO_16 (&Aml->LargeHeader.ResourceLength, &ResourceLength);
322    }
323    else
324    {
325        /* Small descriptor -- bits 2:0 of byte 0 contain the length */
326
327        Aml->SmallHeader.DescriptorType = (UINT8)
328
329            /* Clear any existing length, preserving descriptor type bits */
330
331            ((Aml->SmallHeader.DescriptorType & ~ACPI_RESOURCE_NAME_SMALL_LENGTH_MASK)
332
333            | ResourceLength);
334    }
335}
336
337
338/*******************************************************************************
339 *
340 * FUNCTION:    AcpiRsSetResourceHeader
341 *
342 * PARAMETERS:  DescriptorType      - Byte to be inserted as the type
343 *              TotalLength         - Length of the AML descriptor, including
344 *                                    the header and length fields.
345 *              Aml                 - Pointer to the raw AML descriptor
346 *
347 * RETURN:      None
348 *
349 * DESCRIPTION: Set the DescriptorType and ResourceLength fields of an AML
350 *              resource descriptor, both Large and Small descriptors are
351 *              supported automatically
352 *
353 ******************************************************************************/
354
355void
356AcpiRsSetResourceHeader (
357    UINT8                   DescriptorType,
358    ACPI_RSDESC_SIZE        TotalLength,
359    AML_RESOURCE            *Aml)
360{
361    ACPI_FUNCTION_ENTRY ();
362
363
364    /* Set the Resource Type */
365
366    Aml->SmallHeader.DescriptorType = DescriptorType;
367
368    /* Set the Resource Length */
369
370    AcpiRsSetResourceLength (TotalLength, Aml);
371}
372
373
374/*******************************************************************************
375 *
376 * FUNCTION:    AcpiRsStrcpy
377 *
378 * PARAMETERS:  Destination         - Pointer to the destination string
379 *              Source              - Pointer to the source string
380 *
381 * RETURN:      String length, including NULL terminator
382 *
383 * DESCRIPTION: Local string copy that returns the string length, saving a
384 *              strcpy followed by a strlen.
385 *
386 ******************************************************************************/
387
388static UINT16
389AcpiRsStrcpy (
390    char                    *Destination,
391    char                    *Source)
392{
393    UINT16                  i;
394
395
396    ACPI_FUNCTION_ENTRY ();
397
398
399    for (i = 0; Source[i]; i++)
400    {
401        Destination[i] = Source[i];
402    }
403
404    Destination[i] = 0;
405
406    /* Return string length including the NULL terminator */
407
408    return ((UINT16) (i + 1));
409}
410
411
412/*******************************************************************************
413 *
414 * FUNCTION:    AcpiRsGetResourceSource
415 *
416 * PARAMETERS:  ResourceLength      - Length field of the descriptor
417 *              MinimumLength       - Minimum length of the descriptor (minus
418 *                                    any optional fields)
419 *              ResourceSource      - Where the ResourceSource is returned
420 *              Aml                 - Pointer to the raw AML descriptor
421 *              StringPtr           - (optional) where to store the actual
422 *                                    ResourceSource string
423 *
424 * RETURN:      Length of the string plus NULL terminator, rounded up to native
425 *              word boundary
426 *
427 * DESCRIPTION: Copy the optional ResourceSource data from a raw AML descriptor
428 *              to an internal resource descriptor
429 *
430 ******************************************************************************/
431
432ACPI_RS_LENGTH
433AcpiRsGetResourceSource (
434    ACPI_RS_LENGTH          ResourceLength,
435    ACPI_RS_LENGTH          MinimumLength,
436    ACPI_RESOURCE_SOURCE    *ResourceSource,
437    AML_RESOURCE            *Aml,
438    char                    *StringPtr)
439{
440    ACPI_RSDESC_SIZE        TotalLength;
441    UINT8                   *AmlResourceSource;
442
443
444    ACPI_FUNCTION_ENTRY ();
445
446
447    TotalLength = ResourceLength + sizeof (AML_RESOURCE_LARGE_HEADER);
448    AmlResourceSource = ACPI_ADD_PTR (UINT8, Aml, MinimumLength);
449
450    /*
451     * ResourceSource is present if the length of the descriptor is longer than
452     * the minimum length.
453     *
454     * Note: Some resource descriptors will have an additional null, so
455     * we add 1 to the minimum length.
456     */
457    if (TotalLength > (ACPI_RSDESC_SIZE) (MinimumLength + 1))
458    {
459        /* Get the ResourceSourceIndex */
460
461        ResourceSource->Index = AmlResourceSource[0];
462
463        ResourceSource->StringPtr = StringPtr;
464        if (!StringPtr)
465        {
466            /*
467             * String destination pointer is not specified; Set the String
468             * pointer to the end of the current ResourceSource structure.
469             */
470            ResourceSource->StringPtr = ACPI_ADD_PTR (char, ResourceSource,
471                sizeof (ACPI_RESOURCE_SOURCE));
472        }
473
474        /*
475         * In order for the Resource length to be a multiple of the native
476         * word, calculate the length of the string (+1 for NULL terminator)
477         * and expand to the next word multiple.
478         *
479         * Zero the entire area of the buffer.
480         */
481        TotalLength = (UINT32) ACPI_STRLEN (
482            ACPI_CAST_PTR (char, &AmlResourceSource[1])) + 1;
483        TotalLength = (UINT32) ACPI_ROUND_UP_TO_NATIVE_WORD (TotalLength);
484
485        ACPI_MEMSET (ResourceSource->StringPtr, 0, TotalLength);
486
487        /* Copy the ResourceSource string to the destination */
488
489        ResourceSource->StringLength = AcpiRsStrcpy (ResourceSource->StringPtr,
490            ACPI_CAST_PTR (char, &AmlResourceSource[1]));
491
492        return ((ACPI_RS_LENGTH) TotalLength);
493    }
494
495    /* ResourceSource is not present */
496
497    ResourceSource->Index = 0;
498    ResourceSource->StringLength = 0;
499    ResourceSource->StringPtr = NULL;
500    return (0);
501}
502
503
504/*******************************************************************************
505 *
506 * FUNCTION:    AcpiRsSetResourceSource
507 *
508 * PARAMETERS:  Aml                 - Pointer to the raw AML descriptor
509 *              MinimumLength       - Minimum length of the descriptor (minus
510 *                                    any optional fields)
511 *              ResourceSource      - Internal ResourceSource
512
513 *
514 * RETURN:      Total length of the AML descriptor
515 *
516 * DESCRIPTION: Convert an optional ResourceSource from internal format to a
517 *              raw AML resource descriptor
518 *
519 ******************************************************************************/
520
521ACPI_RSDESC_SIZE
522AcpiRsSetResourceSource (
523    AML_RESOURCE            *Aml,
524    ACPI_RS_LENGTH          MinimumLength,
525    ACPI_RESOURCE_SOURCE    *ResourceSource)
526{
527    UINT8                   *AmlResourceSource;
528    ACPI_RSDESC_SIZE        DescriptorLength;
529
530
531    ACPI_FUNCTION_ENTRY ();
532
533
534    DescriptorLength = MinimumLength;
535
536    /* Non-zero string length indicates presence of a ResourceSource */
537
538    if (ResourceSource->StringLength)
539    {
540        /* Point to the end of the AML descriptor */
541
542        AmlResourceSource = ACPI_ADD_PTR (UINT8, Aml, MinimumLength);
543
544        /* Copy the ResourceSourceIndex */
545
546        AmlResourceSource[0] = (UINT8) ResourceSource->Index;
547
548        /* Copy the ResourceSource string */
549
550        ACPI_STRCPY (ACPI_CAST_PTR (char, &AmlResourceSource[1]),
551            ResourceSource->StringPtr);
552
553        /*
554         * Add the length of the string (+ 1 for null terminator) to the
555         * final descriptor length
556         */
557        DescriptorLength += ((ACPI_RSDESC_SIZE) ResourceSource->StringLength + 1);
558    }
559
560    /* Return the new total length of the AML descriptor */
561
562    return (DescriptorLength);
563}
564
565
566/*******************************************************************************
567 *
568 * FUNCTION:    AcpiRsGetPrtMethodData
569 *
570 * PARAMETERS:  Node            - Device node
571 *              RetBuffer       - Pointer to a buffer structure for the
572 *                                results
573 *
574 * RETURN:      Status
575 *
576 * DESCRIPTION: This function is called to get the _PRT value of an object
577 *              contained in an object specified by the handle passed in
578 *
579 *              If the function fails an appropriate status will be returned
580 *              and the contents of the callers buffer is undefined.
581 *
582 ******************************************************************************/
583
584ACPI_STATUS
585AcpiRsGetPrtMethodData (
586    ACPI_NAMESPACE_NODE     *Node,
587    ACPI_BUFFER             *RetBuffer)
588{
589    ACPI_OPERAND_OBJECT     *ObjDesc;
590    ACPI_STATUS             Status;
591
592
593    ACPI_FUNCTION_TRACE (RsGetPrtMethodData);
594
595
596    /* Parameters guaranteed valid by caller */
597
598    /* Execute the method, no parameters */
599
600    Status = AcpiUtEvaluateObject (Node, METHOD_NAME__PRT,
601                ACPI_BTYPE_PACKAGE, &ObjDesc);
602    if (ACPI_FAILURE (Status))
603    {
604        return_ACPI_STATUS (Status);
605    }
606
607    /*
608     * Create a resource linked list from the byte stream buffer that comes
609     * back from the _CRS method execution.
610     */
611    Status = AcpiRsCreatePciRoutingTable (ObjDesc, RetBuffer);
612
613    /* On exit, we must delete the object returned by EvaluateObject */
614
615    AcpiUtRemoveReference (ObjDesc);
616    return_ACPI_STATUS (Status);
617}
618
619
620/*******************************************************************************
621 *
622 * FUNCTION:    AcpiRsGetCrsMethodData
623 *
624 * PARAMETERS:  Node            - Device node
625 *              RetBuffer       - Pointer to a buffer structure for the
626 *                                results
627 *
628 * RETURN:      Status
629 *
630 * DESCRIPTION: This function is called to get the _CRS value of an object
631 *              contained in an object specified by the handle passed in
632 *
633 *              If the function fails an appropriate status will be returned
634 *              and the contents of the callers buffer is undefined.
635 *
636 ******************************************************************************/
637
638ACPI_STATUS
639AcpiRsGetCrsMethodData (
640    ACPI_NAMESPACE_NODE     *Node,
641    ACPI_BUFFER             *RetBuffer)
642{
643    ACPI_OPERAND_OBJECT     *ObjDesc;
644    ACPI_STATUS             Status;
645
646
647    ACPI_FUNCTION_TRACE (RsGetCrsMethodData);
648
649
650    /* Parameters guaranteed valid by caller */
651
652    /* Execute the method, no parameters */
653
654    Status = AcpiUtEvaluateObject (Node, METHOD_NAME__CRS,
655                ACPI_BTYPE_BUFFER, &ObjDesc);
656    if (ACPI_FAILURE (Status))
657    {
658        return_ACPI_STATUS (Status);
659    }
660
661    /*
662     * Make the call to create a resource linked list from the
663     * byte stream buffer that comes back from the _CRS method
664     * execution.
665     */
666    Status = AcpiRsCreateResourceList (ObjDesc, RetBuffer);
667
668    /* On exit, we must delete the object returned by evaluateObject */
669
670    AcpiUtRemoveReference (ObjDesc);
671    return_ACPI_STATUS (Status);
672}
673
674
675/*******************************************************************************
676 *
677 * FUNCTION:    AcpiRsGetPrsMethodData
678 *
679 * PARAMETERS:  Node            - Device node
680 *              RetBuffer       - Pointer to a buffer structure for the
681 *                                results
682 *
683 * RETURN:      Status
684 *
685 * DESCRIPTION: This function is called to get the _PRS value of an object
686 *              contained in an object specified by the handle passed in
687 *
688 *              If the function fails an appropriate status will be returned
689 *              and the contents of the callers buffer is undefined.
690 *
691 ******************************************************************************/
692
693ACPI_STATUS
694AcpiRsGetPrsMethodData (
695    ACPI_NAMESPACE_NODE     *Node,
696    ACPI_BUFFER             *RetBuffer)
697{
698    ACPI_OPERAND_OBJECT     *ObjDesc;
699    ACPI_STATUS             Status;
700
701
702    ACPI_FUNCTION_TRACE (RsGetPrsMethodData);
703
704
705    /* Parameters guaranteed valid by caller */
706
707    /* Execute the method, no parameters */
708
709    Status = AcpiUtEvaluateObject (Node, METHOD_NAME__PRS,
710                ACPI_BTYPE_BUFFER, &ObjDesc);
711    if (ACPI_FAILURE (Status))
712    {
713        return_ACPI_STATUS (Status);
714    }
715
716    /*
717     * Make the call to create a resource linked list from the
718     * byte stream buffer that comes back from the _CRS method
719     * execution.
720     */
721    Status = AcpiRsCreateResourceList (ObjDesc, RetBuffer);
722
723    /* On exit, we must delete the object returned by evaluateObject */
724
725    AcpiUtRemoveReference (ObjDesc);
726    return_ACPI_STATUS (Status);
727}
728
729
730/*******************************************************************************
731 *
732 * FUNCTION:    AcpiRsGetAeiMethodData
733 *
734 * PARAMETERS:  Node            - Device node
735 *              RetBuffer       - Pointer to a buffer structure for the
736 *                                results
737 *
738 * RETURN:      Status
739 *
740 * DESCRIPTION: This function is called to get the _AEI value of an object
741 *              contained in an object specified by the handle passed in
742 *
743 *              If the function fails an appropriate status will be returned
744 *              and the contents of the callers buffer is undefined.
745 *
746 ******************************************************************************/
747
748ACPI_STATUS
749AcpiRsGetAeiMethodData (
750    ACPI_NAMESPACE_NODE     *Node,
751    ACPI_BUFFER             *RetBuffer)
752{
753    ACPI_OPERAND_OBJECT     *ObjDesc;
754    ACPI_STATUS             Status;
755
756
757    ACPI_FUNCTION_TRACE (RsGetAeiMethodData);
758
759
760    /* Parameters guaranteed valid by caller */
761
762    /* Execute the method, no parameters */
763
764    Status = AcpiUtEvaluateObject (Node, METHOD_NAME__AEI,
765                ACPI_BTYPE_BUFFER, &ObjDesc);
766    if (ACPI_FAILURE (Status))
767    {
768        return_ACPI_STATUS (Status);
769    }
770
771    /*
772     * Make the call to create a resource linked list from the
773     * byte stream buffer that comes back from the _CRS method
774     * execution.
775     */
776    Status = AcpiRsCreateResourceList (ObjDesc, RetBuffer);
777
778    /* On exit, we must delete the object returned by evaluateObject */
779
780    AcpiUtRemoveReference (ObjDesc);
781    return_ACPI_STATUS (Status);
782}
783
784
785/*******************************************************************************
786 *
787 * FUNCTION:    AcpiRsGetMethodData
788 *
789 * PARAMETERS:  Handle          - Handle to the containing object
790 *              Path            - Path to method, relative to Handle
791 *              RetBuffer       - Pointer to a buffer structure for the
792 *                                results
793 *
794 * RETURN:      Status
795 *
796 * DESCRIPTION: This function is called to get the _CRS or _PRS value of an
797 *              object contained in an object specified by the handle passed in
798 *
799 *              If the function fails an appropriate status will be returned
800 *              and the contents of the callers buffer is undefined.
801 *
802 ******************************************************************************/
803
804ACPI_STATUS
805AcpiRsGetMethodData (
806    ACPI_HANDLE             Handle,
807    char                    *Path,
808    ACPI_BUFFER             *RetBuffer)
809{
810    ACPI_OPERAND_OBJECT     *ObjDesc;
811    ACPI_STATUS             Status;
812
813
814    ACPI_FUNCTION_TRACE (RsGetMethodData);
815
816
817    /* Parameters guaranteed valid by caller */
818
819    /* Execute the method, no parameters */
820
821    Status = AcpiUtEvaluateObject (Handle, Path, ACPI_BTYPE_BUFFER, &ObjDesc);
822    if (ACPI_FAILURE (Status))
823    {
824        return_ACPI_STATUS (Status);
825    }
826
827    /*
828     * Make the call to create a resource linked list from the
829     * byte stream buffer that comes back from the method
830     * execution.
831     */
832    Status = AcpiRsCreateResourceList (ObjDesc, RetBuffer);
833
834    /* On exit, we must delete the object returned by EvaluateObject */
835
836    AcpiUtRemoveReference (ObjDesc);
837    return_ACPI_STATUS (Status);
838}
839
840
841/*******************************************************************************
842 *
843 * FUNCTION:    AcpiRsSetSrsMethodData
844 *
845 * PARAMETERS:  Node            - Device node
846 *              InBuffer        - Pointer to a buffer structure of the
847 *                                parameter
848 *
849 * RETURN:      Status
850 *
851 * DESCRIPTION: This function is called to set the _SRS of an object contained
852 *              in an object specified by the handle passed in
853 *
854 *              If the function fails an appropriate status will be returned
855 *              and the contents of the callers buffer is undefined.
856 *
857 * Note: Parameters guaranteed valid by caller
858 *
859 ******************************************************************************/
860
861ACPI_STATUS
862AcpiRsSetSrsMethodData (
863    ACPI_NAMESPACE_NODE     *Node,
864    ACPI_BUFFER             *InBuffer)
865{
866    ACPI_EVALUATE_INFO      *Info;
867    ACPI_OPERAND_OBJECT     *Args[2];
868    ACPI_STATUS             Status;
869    ACPI_BUFFER             Buffer;
870
871
872    ACPI_FUNCTION_TRACE (RsSetSrsMethodData);
873
874
875    /* Allocate and initialize the evaluation information block */
876
877    Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
878    if (!Info)
879    {
880        return_ACPI_STATUS (AE_NO_MEMORY);
881    }
882
883    Info->PrefixNode = Node;
884    Info->Pathname = METHOD_NAME__SRS;
885    Info->Parameters = Args;
886    Info->Flags = ACPI_IGNORE_RETURN_VALUE;
887
888    /*
889     * The InBuffer parameter will point to a linked list of
890     * resource parameters. It needs to be formatted into a
891     * byte stream to be sent in as an input parameter to _SRS
892     *
893     * Convert the linked list into a byte stream
894     */
895    Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
896    Status = AcpiRsCreateAmlResources (InBuffer->Pointer, &Buffer);
897    if (ACPI_FAILURE (Status))
898    {
899        goto Cleanup;
900    }
901
902    /* Create and initialize the method parameter object */
903
904    Args[0] = AcpiUtCreateInternalObject (ACPI_TYPE_BUFFER);
905    if (!Args[0])
906    {
907        /*
908         * Must free the buffer allocated above (otherwise it is freed
909         * later)
910         */
911        ACPI_FREE (Buffer.Pointer);
912        Status = AE_NO_MEMORY;
913        goto Cleanup;
914    }
915
916    Args[0]->Buffer.Length  = (UINT32) Buffer.Length;
917    Args[0]->Buffer.Pointer = Buffer.Pointer;
918    Args[0]->Common.Flags   = AOPOBJ_DATA_VALID;
919    Args[1] = NULL;
920
921    /* Execute the method, no return value is expected */
922
923    Status = AcpiNsEvaluate (Info);
924
925    /* Clean up and return the status from AcpiNsEvaluate */
926
927    AcpiUtRemoveReference (Args[0]);
928
929Cleanup:
930    ACPI_FREE (Info);
931    return_ACPI_STATUS (Status);
932}
933