xref: /haiku/src/add-ons/kernel/bus_managers/acpi/acpica/components/resources/rsutils.c (revision 599289f2f3bacad6ed9b4783daf52e17dbe55e47)
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 - 2015, 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 #include "acpi.h"
117 #include "accommon.h"
118 #include "acnamesp.h"
119 #include "acresrc.h"
120 
121 
122 #define _COMPONENT          ACPI_RESOURCES
123         ACPI_MODULE_NAME    ("rsutils")
124 
125 
126 /*******************************************************************************
127  *
128  * FUNCTION:    AcpiRsDecodeBitmask
129  *
130  * PARAMETERS:  Mask            - Bitmask to decode
131  *              List            - Where the converted list is returned
132  *
133  * RETURN:      Count of bits set (length of list)
134  *
135  * DESCRIPTION: Convert a bit mask into a list of values
136  *
137  ******************************************************************************/
138 
139 UINT8
140 AcpiRsDecodeBitmask (
141     UINT16                  Mask,
142     UINT8                   *List)
143 {
144     UINT8                   i;
145     UINT8                   BitCount;
146 
147 
148     ACPI_FUNCTION_ENTRY ();
149 
150 
151     /* Decode the mask bits */
152 
153     for (i = 0, BitCount = 0; Mask; i++)
154     {
155         if (Mask & 0x0001)
156         {
157             List[BitCount] = i;
158             BitCount++;
159         }
160 
161         Mask >>= 1;
162     }
163 
164     return (BitCount);
165 }
166 
167 
168 /*******************************************************************************
169  *
170  * FUNCTION:    AcpiRsEncodeBitmask
171  *
172  * PARAMETERS:  List            - List of values to encode
173  *              Count           - Length of list
174  *
175  * RETURN:      Encoded bitmask
176  *
177  * DESCRIPTION: Convert a list of values to an encoded bitmask
178  *
179  ******************************************************************************/
180 
181 UINT16
182 AcpiRsEncodeBitmask (
183     UINT8                   *List,
184     UINT8                   Count)
185 {
186     UINT32                  i;
187     UINT16                  Mask;
188 
189 
190     ACPI_FUNCTION_ENTRY ();
191 
192 
193     /* Encode the list into a single bitmask */
194 
195     for (i = 0, Mask = 0; i < Count; i++)
196     {
197         Mask |= (0x1 << List[i]);
198     }
199 
200     return (Mask);
201 }
202 
203 
204 /*******************************************************************************
205  *
206  * FUNCTION:    AcpiRsMoveData
207  *
208  * PARAMETERS:  Destination         - Pointer to the destination descriptor
209  *              Source              - Pointer to the source descriptor
210  *              ItemCount           - How many items to move
211  *              MoveType            - Byte width
212  *
213  * RETURN:      None
214  *
215  * DESCRIPTION: Move multiple data items from one descriptor to another. Handles
216  *              alignment issues and endian issues if necessary, as configured
217  *              via the ACPI_MOVE_* macros. (This is why a memcpy is not used)
218  *
219  ******************************************************************************/
220 
221 void
222 AcpiRsMoveData (
223     void                    *Destination,
224     void                    *Source,
225     UINT16                  ItemCount,
226     UINT8                   MoveType)
227 {
228     UINT32                  i;
229 
230 
231     ACPI_FUNCTION_ENTRY ();
232 
233 
234     /* One move per item */
235 
236     for (i = 0; i < ItemCount; i++)
237     {
238         switch (MoveType)
239         {
240         /*
241          * For the 8-bit case, we can perform the move all at once
242          * since there are no alignment or endian issues
243          */
244         case ACPI_RSC_MOVE8:
245         case ACPI_RSC_MOVE_GPIO_RES:
246         case ACPI_RSC_MOVE_SERIAL_VEN:
247         case ACPI_RSC_MOVE_SERIAL_RES:
248 
249             memcpy (Destination, Source, ItemCount);
250             return;
251 
252         /*
253          * 16-, 32-, and 64-bit cases must use the move macros that perform
254          * endian conversion and/or accommodate hardware that cannot perform
255          * misaligned memory transfers
256          */
257         case ACPI_RSC_MOVE16:
258         case ACPI_RSC_MOVE_GPIO_PIN:
259 
260             ACPI_MOVE_16_TO_16 (&ACPI_CAST_PTR (UINT16, Destination)[i],
261                                 &ACPI_CAST_PTR (UINT16, Source)[i]);
262             break;
263 
264         case ACPI_RSC_MOVE32:
265 
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 
272             ACPI_MOVE_64_TO_64 (&ACPI_CAST_PTR (UINT64, Destination)[i],
273                                 &ACPI_CAST_PTR (UINT64, Source)[i]);
274             break;
275 
276         default:
277 
278             return;
279         }
280     }
281 }
282 
283 
284 /*******************************************************************************
285  *
286  * FUNCTION:    AcpiRsSetResourceLength
287  *
288  * PARAMETERS:  TotalLength         - Length of the AML descriptor, including
289  *                                    the header and length fields.
290  *              Aml                 - Pointer to the raw AML descriptor
291  *
292  * RETURN:      None
293  *
294  * DESCRIPTION: Set the ResourceLength field of an AML
295  *              resource descriptor, both Large and Small descriptors are
296  *              supported automatically. Note: Descriptor Type field must
297  *              be valid.
298  *
299  ******************************************************************************/
300 
301 void
302 AcpiRsSetResourceLength (
303     ACPI_RSDESC_SIZE        TotalLength,
304     AML_RESOURCE            *Aml)
305 {
306     ACPI_RS_LENGTH          ResourceLength;
307 
308 
309     ACPI_FUNCTION_ENTRY ();
310 
311 
312     /* Length is the total descriptor length minus the header length */
313 
314     ResourceLength = (ACPI_RS_LENGTH)
315         (TotalLength - AcpiUtGetResourceHeaderLength (Aml));
316 
317     /* Length is stored differently for large and small descriptors */
318 
319     if (Aml->SmallHeader.DescriptorType & ACPI_RESOURCE_NAME_LARGE)
320     {
321         /* Large descriptor -- bytes 1-2 contain the 16-bit length */
322 
323         ACPI_MOVE_16_TO_16 (&Aml->LargeHeader.ResourceLength, &ResourceLength);
324     }
325     else
326     {
327         /* Small descriptor -- bits 2:0 of byte 0 contain the length */
328 
329         Aml->SmallHeader.DescriptorType = (UINT8)
330 
331             /* Clear any existing length, preserving descriptor type bits */
332 
333             ((Aml->SmallHeader.DescriptorType & ~ACPI_RESOURCE_NAME_SMALL_LENGTH_MASK)
334 
335             | ResourceLength);
336     }
337 }
338 
339 
340 /*******************************************************************************
341  *
342  * FUNCTION:    AcpiRsSetResourceHeader
343  *
344  * PARAMETERS:  DescriptorType      - Byte to be inserted as the type
345  *              TotalLength         - Length of the AML descriptor, including
346  *                                    the header and length fields.
347  *              Aml                 - Pointer to the raw AML descriptor
348  *
349  * RETURN:      None
350  *
351  * DESCRIPTION: Set the DescriptorType and ResourceLength fields of an AML
352  *              resource descriptor, both Large and Small descriptors are
353  *              supported automatically
354  *
355  ******************************************************************************/
356 
357 void
358 AcpiRsSetResourceHeader (
359     UINT8                   DescriptorType,
360     ACPI_RSDESC_SIZE        TotalLength,
361     AML_RESOURCE            *Aml)
362 {
363     ACPI_FUNCTION_ENTRY ();
364 
365 
366     /* Set the Resource Type */
367 
368     Aml->SmallHeader.DescriptorType = DescriptorType;
369 
370     /* Set the Resource Length */
371 
372     AcpiRsSetResourceLength (TotalLength, Aml);
373 }
374 
375 
376 /*******************************************************************************
377  *
378  * FUNCTION:    AcpiRsStrcpy
379  *
380  * PARAMETERS:  Destination         - Pointer to the destination string
381  *              Source              - Pointer to the source string
382  *
383  * RETURN:      String length, including NULL terminator
384  *
385  * DESCRIPTION: Local string copy that returns the string length, saving a
386  *              strcpy followed by a strlen.
387  *
388  ******************************************************************************/
389 
390 static UINT16
391 AcpiRsStrcpy (
392     char                    *Destination,
393     char                    *Source)
394 {
395     UINT16                  i;
396 
397 
398     ACPI_FUNCTION_ENTRY ();
399 
400 
401     for (i = 0; Source[i]; i++)
402     {
403         Destination[i] = Source[i];
404     }
405 
406     Destination[i] = 0;
407 
408     /* Return string length including the NULL terminator */
409 
410     return ((UINT16) (i + 1));
411 }
412 
413 
414 /*******************************************************************************
415  *
416  * FUNCTION:    AcpiRsGetResourceSource
417  *
418  * PARAMETERS:  ResourceLength      - Length field of the descriptor
419  *              MinimumLength       - Minimum length of the descriptor (minus
420  *                                    any optional fields)
421  *              ResourceSource      - Where the ResourceSource is returned
422  *              Aml                 - Pointer to the raw AML descriptor
423  *              StringPtr           - (optional) where to store the actual
424  *                                    ResourceSource string
425  *
426  * RETURN:      Length of the string plus NULL terminator, rounded up to native
427  *              word boundary
428  *
429  * DESCRIPTION: Copy the optional ResourceSource data from a raw AML descriptor
430  *              to an internal resource descriptor
431  *
432  ******************************************************************************/
433 
434 ACPI_RS_LENGTH
435 AcpiRsGetResourceSource (
436     ACPI_RS_LENGTH          ResourceLength,
437     ACPI_RS_LENGTH          MinimumLength,
438     ACPI_RESOURCE_SOURCE    *ResourceSource,
439     AML_RESOURCE            *Aml,
440     char                    *StringPtr)
441 {
442     ACPI_RSDESC_SIZE        TotalLength;
443     UINT8                   *AmlResourceSource;
444 
445 
446     ACPI_FUNCTION_ENTRY ();
447 
448 
449     TotalLength = ResourceLength + sizeof (AML_RESOURCE_LARGE_HEADER);
450     AmlResourceSource = ACPI_ADD_PTR (UINT8, Aml, MinimumLength);
451 
452     /*
453      * ResourceSource is present if the length of the descriptor is longer than
454      * the minimum length.
455      *
456      * Note: Some resource descriptors will have an additional null, so
457      * we add 1 to the minimum length.
458      */
459     if (TotalLength > (ACPI_RSDESC_SIZE) (MinimumLength + 1))
460     {
461         /* Get the ResourceSourceIndex */
462 
463         ResourceSource->Index = AmlResourceSource[0];
464 
465         ResourceSource->StringPtr = StringPtr;
466         if (!StringPtr)
467         {
468             /*
469              * String destination pointer is not specified; Set the String
470              * pointer to the end of the current ResourceSource structure.
471              */
472             ResourceSource->StringPtr = ACPI_ADD_PTR (char, ResourceSource,
473                 sizeof (ACPI_RESOURCE_SOURCE));
474         }
475 
476         /*
477          * In order for the Resource length to be a multiple of the native
478          * word, calculate the length of the string (+1 for NULL terminator)
479          * and expand to the next word multiple.
480          *
481          * Zero the entire area of the buffer.
482          */
483         TotalLength = (UINT32) strlen (
484             ACPI_CAST_PTR (char, &AmlResourceSource[1])) + 1;
485         TotalLength = (UINT32) ACPI_ROUND_UP_TO_NATIVE_WORD (TotalLength);
486 
487         memset (ResourceSource->StringPtr, 0, TotalLength);
488 
489         /* Copy the ResourceSource string to the destination */
490 
491         ResourceSource->StringLength = AcpiRsStrcpy (ResourceSource->StringPtr,
492             ACPI_CAST_PTR (char, &AmlResourceSource[1]));
493 
494         return ((ACPI_RS_LENGTH) TotalLength);
495     }
496 
497     /* ResourceSource is not present */
498 
499     ResourceSource->Index = 0;
500     ResourceSource->StringLength = 0;
501     ResourceSource->StringPtr = NULL;
502     return (0);
503 }
504 
505 
506 /*******************************************************************************
507  *
508  * FUNCTION:    AcpiRsSetResourceSource
509  *
510  * PARAMETERS:  Aml                 - Pointer to the raw AML descriptor
511  *              MinimumLength       - Minimum length of the descriptor (minus
512  *                                    any optional fields)
513  *              ResourceSource      - Internal ResourceSource
514 
515  *
516  * RETURN:      Total length of the AML descriptor
517  *
518  * DESCRIPTION: Convert an optional ResourceSource from internal format to a
519  *              raw AML resource descriptor
520  *
521  ******************************************************************************/
522 
523 ACPI_RSDESC_SIZE
524 AcpiRsSetResourceSource (
525     AML_RESOURCE            *Aml,
526     ACPI_RS_LENGTH          MinimumLength,
527     ACPI_RESOURCE_SOURCE    *ResourceSource)
528 {
529     UINT8                   *AmlResourceSource;
530     ACPI_RSDESC_SIZE        DescriptorLength;
531 
532 
533     ACPI_FUNCTION_ENTRY ();
534 
535 
536     DescriptorLength = MinimumLength;
537 
538     /* Non-zero string length indicates presence of a ResourceSource */
539 
540     if (ResourceSource->StringLength)
541     {
542         /* Point to the end of the AML descriptor */
543 
544         AmlResourceSource = ACPI_ADD_PTR (UINT8, Aml, MinimumLength);
545 
546         /* Copy the ResourceSourceIndex */
547 
548         AmlResourceSource[0] = (UINT8) ResourceSource->Index;
549 
550         /* Copy the ResourceSource string */
551 
552         strcpy (ACPI_CAST_PTR (char, &AmlResourceSource[1]),
553             ResourceSource->StringPtr);
554 
555         /*
556          * Add the length of the string (+ 1 for null terminator) to the
557          * final descriptor length
558          */
559         DescriptorLength += ((ACPI_RSDESC_SIZE) ResourceSource->StringLength + 1);
560     }
561 
562     /* Return the new total length of the AML descriptor */
563 
564     return (DescriptorLength);
565 }
566 
567 
568 /*******************************************************************************
569  *
570  * FUNCTION:    AcpiRsGetPrtMethodData
571  *
572  * PARAMETERS:  Node            - Device node
573  *              RetBuffer       - Pointer to a buffer structure for the
574  *                                results
575  *
576  * RETURN:      Status
577  *
578  * DESCRIPTION: This function is called to get the _PRT value of an object
579  *              contained in an object specified by the handle passed in
580  *
581  *              If the function fails an appropriate status will be returned
582  *              and the contents of the callers buffer is undefined.
583  *
584  ******************************************************************************/
585 
586 ACPI_STATUS
587 AcpiRsGetPrtMethodData (
588     ACPI_NAMESPACE_NODE     *Node,
589     ACPI_BUFFER             *RetBuffer)
590 {
591     ACPI_OPERAND_OBJECT     *ObjDesc;
592     ACPI_STATUS             Status;
593 
594 
595     ACPI_FUNCTION_TRACE (RsGetPrtMethodData);
596 
597 
598     /* Parameters guaranteed valid by caller */
599 
600     /* Execute the method, no parameters */
601 
602     Status = AcpiUtEvaluateObject (Node, METHOD_NAME__PRT,
603                 ACPI_BTYPE_PACKAGE, &ObjDesc);
604     if (ACPI_FAILURE (Status))
605     {
606         return_ACPI_STATUS (Status);
607     }
608 
609     /*
610      * Create a resource linked list from the byte stream buffer that comes
611      * back from the _CRS method execution.
612      */
613     Status = AcpiRsCreatePciRoutingTable (ObjDesc, RetBuffer);
614 
615     /* On exit, we must delete the object returned by EvaluateObject */
616 
617     AcpiUtRemoveReference (ObjDesc);
618     return_ACPI_STATUS (Status);
619 }
620 
621 
622 /*******************************************************************************
623  *
624  * FUNCTION:    AcpiRsGetCrsMethodData
625  *
626  * PARAMETERS:  Node            - Device node
627  *              RetBuffer       - Pointer to a buffer structure for the
628  *                                results
629  *
630  * RETURN:      Status
631  *
632  * DESCRIPTION: This function is called to get the _CRS value of an object
633  *              contained in an object specified by the handle passed in
634  *
635  *              If the function fails an appropriate status will be returned
636  *              and the contents of the callers buffer is undefined.
637  *
638  ******************************************************************************/
639 
640 ACPI_STATUS
641 AcpiRsGetCrsMethodData (
642     ACPI_NAMESPACE_NODE     *Node,
643     ACPI_BUFFER             *RetBuffer)
644 {
645     ACPI_OPERAND_OBJECT     *ObjDesc;
646     ACPI_STATUS             Status;
647 
648 
649     ACPI_FUNCTION_TRACE (RsGetCrsMethodData);
650 
651 
652     /* Parameters guaranteed valid by caller */
653 
654     /* Execute the method, no parameters */
655 
656     Status = AcpiUtEvaluateObject (Node, METHOD_NAME__CRS,
657                 ACPI_BTYPE_BUFFER, &ObjDesc);
658     if (ACPI_FAILURE (Status))
659     {
660         return_ACPI_STATUS (Status);
661     }
662 
663     /*
664      * Make the call to create a resource linked list from the
665      * byte stream buffer that comes back from the _CRS method
666      * execution.
667      */
668     Status = AcpiRsCreateResourceList (ObjDesc, RetBuffer);
669 
670     /* On exit, we must delete the object returned by evaluateObject */
671 
672     AcpiUtRemoveReference (ObjDesc);
673     return_ACPI_STATUS (Status);
674 }
675 
676 
677 /*******************************************************************************
678  *
679  * FUNCTION:    AcpiRsGetPrsMethodData
680  *
681  * PARAMETERS:  Node            - Device node
682  *              RetBuffer       - Pointer to a buffer structure for the
683  *                                results
684  *
685  * RETURN:      Status
686  *
687  * DESCRIPTION: This function is called to get the _PRS value of an object
688  *              contained in an object specified by the handle passed in
689  *
690  *              If the function fails an appropriate status will be returned
691  *              and the contents of the callers buffer is undefined.
692  *
693  ******************************************************************************/
694 
695 ACPI_STATUS
696 AcpiRsGetPrsMethodData (
697     ACPI_NAMESPACE_NODE     *Node,
698     ACPI_BUFFER             *RetBuffer)
699 {
700     ACPI_OPERAND_OBJECT     *ObjDesc;
701     ACPI_STATUS             Status;
702 
703 
704     ACPI_FUNCTION_TRACE (RsGetPrsMethodData);
705 
706 
707     /* Parameters guaranteed valid by caller */
708 
709     /* Execute the method, no parameters */
710 
711     Status = AcpiUtEvaluateObject (Node, METHOD_NAME__PRS,
712                 ACPI_BTYPE_BUFFER, &ObjDesc);
713     if (ACPI_FAILURE (Status))
714     {
715         return_ACPI_STATUS (Status);
716     }
717 
718     /*
719      * Make the call to create a resource linked list from the
720      * byte stream buffer that comes back from the _CRS method
721      * execution.
722      */
723     Status = AcpiRsCreateResourceList (ObjDesc, RetBuffer);
724 
725     /* On exit, we must delete the object returned by evaluateObject */
726 
727     AcpiUtRemoveReference (ObjDesc);
728     return_ACPI_STATUS (Status);
729 }
730 
731 
732 /*******************************************************************************
733  *
734  * FUNCTION:    AcpiRsGetAeiMethodData
735  *
736  * PARAMETERS:  Node            - Device node
737  *              RetBuffer       - Pointer to a buffer structure for the
738  *                                results
739  *
740  * RETURN:      Status
741  *
742  * DESCRIPTION: This function is called to get the _AEI value of an object
743  *              contained in an object specified by the handle passed in
744  *
745  *              If the function fails an appropriate status will be returned
746  *              and the contents of the callers buffer is undefined.
747  *
748  ******************************************************************************/
749 
750 ACPI_STATUS
751 AcpiRsGetAeiMethodData (
752     ACPI_NAMESPACE_NODE     *Node,
753     ACPI_BUFFER             *RetBuffer)
754 {
755     ACPI_OPERAND_OBJECT     *ObjDesc;
756     ACPI_STATUS             Status;
757 
758 
759     ACPI_FUNCTION_TRACE (RsGetAeiMethodData);
760 
761 
762     /* Parameters guaranteed valid by caller */
763 
764     /* Execute the method, no parameters */
765 
766     Status = AcpiUtEvaluateObject (Node, METHOD_NAME__AEI,
767                 ACPI_BTYPE_BUFFER, &ObjDesc);
768     if (ACPI_FAILURE (Status))
769     {
770         return_ACPI_STATUS (Status);
771     }
772 
773     /*
774      * Make the call to create a resource linked list from the
775      * byte stream buffer that comes back from the _CRS method
776      * execution.
777      */
778     Status = AcpiRsCreateResourceList (ObjDesc, RetBuffer);
779 
780     /* On exit, we must delete the object returned by evaluateObject */
781 
782     AcpiUtRemoveReference (ObjDesc);
783     return_ACPI_STATUS (Status);
784 }
785 
786 
787 /*******************************************************************************
788  *
789  * FUNCTION:    AcpiRsGetMethodData
790  *
791  * PARAMETERS:  Handle          - Handle to the containing object
792  *              Path            - Path to method, relative to Handle
793  *              RetBuffer       - Pointer to a buffer structure for the
794  *                                results
795  *
796  * RETURN:      Status
797  *
798  * DESCRIPTION: This function is called to get the _CRS or _PRS value of an
799  *              object contained in an object specified by the handle passed in
800  *
801  *              If the function fails an appropriate status will be returned
802  *              and the contents of the callers buffer is undefined.
803  *
804  ******************************************************************************/
805 
806 ACPI_STATUS
807 AcpiRsGetMethodData (
808     ACPI_HANDLE             Handle,
809     char                    *Path,
810     ACPI_BUFFER             *RetBuffer)
811 {
812     ACPI_OPERAND_OBJECT     *ObjDesc;
813     ACPI_STATUS             Status;
814 
815 
816     ACPI_FUNCTION_TRACE (RsGetMethodData);
817 
818 
819     /* Parameters guaranteed valid by caller */
820 
821     /* Execute the method, no parameters */
822 
823     Status = AcpiUtEvaluateObject (ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Handle),
824         Path, ACPI_BTYPE_BUFFER, &ObjDesc);
825     if (ACPI_FAILURE (Status))
826     {
827         return_ACPI_STATUS (Status);
828     }
829 
830     /*
831      * Make the call to create a resource linked list from the
832      * byte stream buffer that comes back from the method
833      * execution.
834      */
835     Status = AcpiRsCreateResourceList (ObjDesc, RetBuffer);
836 
837     /* On exit, we must delete the object returned by EvaluateObject */
838 
839     AcpiUtRemoveReference (ObjDesc);
840     return_ACPI_STATUS (Status);
841 }
842 
843 
844 /*******************************************************************************
845  *
846  * FUNCTION:    AcpiRsSetSrsMethodData
847  *
848  * PARAMETERS:  Node            - Device node
849  *              InBuffer        - Pointer to a buffer structure of the
850  *                                parameter
851  *
852  * RETURN:      Status
853  *
854  * DESCRIPTION: This function is called to set the _SRS of an object contained
855  *              in an object specified by the handle passed in
856  *
857  *              If the function fails an appropriate status will be returned
858  *              and the contents of the callers buffer is undefined.
859  *
860  * Note: Parameters guaranteed valid by caller
861  *
862  ******************************************************************************/
863 
864 ACPI_STATUS
865 AcpiRsSetSrsMethodData (
866     ACPI_NAMESPACE_NODE     *Node,
867     ACPI_BUFFER             *InBuffer)
868 {
869     ACPI_EVALUATE_INFO      *Info;
870     ACPI_OPERAND_OBJECT     *Args[2];
871     ACPI_STATUS             Status;
872     ACPI_BUFFER             Buffer;
873 
874 
875     ACPI_FUNCTION_TRACE (RsSetSrsMethodData);
876 
877 
878     /* Allocate and initialize the evaluation information block */
879 
880     Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
881     if (!Info)
882     {
883         return_ACPI_STATUS (AE_NO_MEMORY);
884     }
885 
886     Info->PrefixNode = Node;
887     Info->RelativePathname = METHOD_NAME__SRS;
888     Info->Parameters = Args;
889     Info->Flags = ACPI_IGNORE_RETURN_VALUE;
890 
891     /*
892      * The InBuffer parameter will point to a linked list of
893      * resource parameters. It needs to be formatted into a
894      * byte stream to be sent in as an input parameter to _SRS
895      *
896      * Convert the linked list into a byte stream
897      */
898     Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
899     Status = AcpiRsCreateAmlResources (InBuffer, &Buffer);
900     if (ACPI_FAILURE (Status))
901     {
902         goto Cleanup;
903     }
904 
905     /* Create and initialize the method parameter object */
906 
907     Args[0] = AcpiUtCreateInternalObject (ACPI_TYPE_BUFFER);
908     if (!Args[0])
909     {
910         /*
911          * Must free the buffer allocated above (otherwise it is freed
912          * later)
913          */
914         ACPI_FREE (Buffer.Pointer);
915         Status = AE_NO_MEMORY;
916         goto Cleanup;
917     }
918 
919     Args[0]->Buffer.Length  = (UINT32) Buffer.Length;
920     Args[0]->Buffer.Pointer = Buffer.Pointer;
921     Args[0]->Common.Flags   = AOPOBJ_DATA_VALID;
922     Args[1] = NULL;
923 
924     /* Execute the method, no return value is expected */
925 
926     Status = AcpiNsEvaluate (Info);
927 
928     /* Clean up and return the status from AcpiNsEvaluate */
929 
930     AcpiUtRemoveReference (Args[0]);
931 
932 Cleanup:
933     ACPI_FREE (Info);
934     return_ACPI_STATUS (Status);
935 }
936