Merge branch 'vendor/XZ'
[dragonfly.git] / sys / contrib / dev / acpica / source / components / resources / rsutils.c
1 /*******************************************************************************
2  *
3  * Module Name: rsutils - Utilities for the resource manager
4  *
5  ******************************************************************************/
6
7 /*
8  * Copyright (C) 2000 - 2015, Intel Corp.
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions, and the following disclaimer,
16  *    without modification.
17  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18  *    substantially similar to the "NO WARRANTY" disclaimer below
19  *    ("Disclaimer") and any redistribution must be conditioned upon
20  *    including a substantially similar Disclaimer requirement for further
21  *    binary redistribution.
22  * 3. Neither the names of the above-listed copyright holders nor the names
23  *    of any contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * Alternatively, this software may be distributed under the terms of the
27  * GNU General Public License ("GPL") version 2 as published by the Free
28  * Software Foundation.
29  *
30  * NO WARRANTY
31  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41  * POSSIBILITY OF SUCH DAMAGES.
42  */
43
44 #include "acpi.h"
45 #include "accommon.h"
46 #include "acnamesp.h"
47 #include "acresrc.h"
48
49
50 #define _COMPONENT          ACPI_RESOURCES
51         ACPI_MODULE_NAME    ("rsutils")
52
53
54 /*******************************************************************************
55  *
56  * FUNCTION:    AcpiRsDecodeBitmask
57  *
58  * PARAMETERS:  Mask            - Bitmask to decode
59  *              List            - Where the converted list is returned
60  *
61  * RETURN:      Count of bits set (length of list)
62  *
63  * DESCRIPTION: Convert a bit mask into a list of values
64  *
65  ******************************************************************************/
66
67 UINT8
68 AcpiRsDecodeBitmask (
69     UINT16                  Mask,
70     UINT8                   *List)
71 {
72     UINT8                   i;
73     UINT8                   BitCount;
74
75
76     ACPI_FUNCTION_ENTRY ();
77
78
79     /* Decode the mask bits */
80
81     for (i = 0, BitCount = 0; Mask; i++)
82     {
83         if (Mask & 0x0001)
84         {
85             List[BitCount] = i;
86             BitCount++;
87         }
88
89         Mask >>= 1;
90     }
91
92     return (BitCount);
93 }
94
95
96 /*******************************************************************************
97  *
98  * FUNCTION:    AcpiRsEncodeBitmask
99  *
100  * PARAMETERS:  List            - List of values to encode
101  *              Count           - Length of list
102  *
103  * RETURN:      Encoded bitmask
104  *
105  * DESCRIPTION: Convert a list of values to an encoded bitmask
106  *
107  ******************************************************************************/
108
109 UINT16
110 AcpiRsEncodeBitmask (
111     UINT8                   *List,
112     UINT8                   Count)
113 {
114     UINT32                  i;
115     UINT16                  Mask;
116
117
118     ACPI_FUNCTION_ENTRY ();
119
120
121     /* Encode the list into a single bitmask */
122
123     for (i = 0, Mask = 0; i < Count; i++)
124     {
125         Mask |= (0x1 << List[i]);
126     }
127
128     return (Mask);
129 }
130
131
132 /*******************************************************************************
133  *
134  * FUNCTION:    AcpiRsMoveData
135  *
136  * PARAMETERS:  Destination         - Pointer to the destination descriptor
137  *              Source              - Pointer to the source descriptor
138  *              ItemCount           - How many items to move
139  *              MoveType            - Byte width
140  *
141  * RETURN:      None
142  *
143  * DESCRIPTION: Move multiple data items from one descriptor to another. Handles
144  *              alignment issues and endian issues if necessary, as configured
145  *              via the ACPI_MOVE_* macros. (This is why a memcpy is not used)
146  *
147  ******************************************************************************/
148
149 void
150 AcpiRsMoveData (
151     void                    *Destination,
152     void                    *Source,
153     UINT16                  ItemCount,
154     UINT8                   MoveType)
155 {
156     UINT32                  i;
157
158
159     ACPI_FUNCTION_ENTRY ();
160
161
162     /* One move per item */
163
164     for (i = 0; i < ItemCount; i++)
165     {
166         switch (MoveType)
167         {
168         /*
169          * For the 8-bit case, we can perform the move all at once
170          * since there are no alignment or endian issues
171          */
172         case ACPI_RSC_MOVE8:
173         case ACPI_RSC_MOVE_GPIO_RES:
174         case ACPI_RSC_MOVE_SERIAL_VEN:
175         case ACPI_RSC_MOVE_SERIAL_RES:
176
177             memcpy (Destination, Source, ItemCount);
178             return;
179
180         /*
181          * 16-, 32-, and 64-bit cases must use the move macros that perform
182          * endian conversion and/or accommodate hardware that cannot perform
183          * misaligned memory transfers
184          */
185         case ACPI_RSC_MOVE16:
186         case ACPI_RSC_MOVE_GPIO_PIN:
187
188             ACPI_MOVE_16_TO_16 (&ACPI_CAST_PTR (UINT16, Destination)[i],
189                                 &ACPI_CAST_PTR (UINT16, Source)[i]);
190             break;
191
192         case ACPI_RSC_MOVE32:
193
194             ACPI_MOVE_32_TO_32 (&ACPI_CAST_PTR (UINT32, Destination)[i],
195                                 &ACPI_CAST_PTR (UINT32, Source)[i]);
196             break;
197
198         case ACPI_RSC_MOVE64:
199
200             ACPI_MOVE_64_TO_64 (&ACPI_CAST_PTR (UINT64, Destination)[i],
201                                 &ACPI_CAST_PTR (UINT64, Source)[i]);
202             break;
203
204         default:
205
206             return;
207         }
208     }
209 }
210
211
212 /*******************************************************************************
213  *
214  * FUNCTION:    AcpiRsSetResourceLength
215  *
216  * PARAMETERS:  TotalLength         - Length of the AML descriptor, including
217  *                                    the header and length fields.
218  *              Aml                 - Pointer to the raw AML descriptor
219  *
220  * RETURN:      None
221  *
222  * DESCRIPTION: Set the ResourceLength field of an AML
223  *              resource descriptor, both Large and Small descriptors are
224  *              supported automatically. Note: Descriptor Type field must
225  *              be valid.
226  *
227  ******************************************************************************/
228
229 void
230 AcpiRsSetResourceLength (
231     ACPI_RSDESC_SIZE        TotalLength,
232     AML_RESOURCE            *Aml)
233 {
234     ACPI_RS_LENGTH          ResourceLength;
235
236
237     ACPI_FUNCTION_ENTRY ();
238
239
240     /* Length is the total descriptor length minus the header length */
241
242     ResourceLength = (ACPI_RS_LENGTH)
243         (TotalLength - AcpiUtGetResourceHeaderLength (Aml));
244
245     /* Length is stored differently for large and small descriptors */
246
247     if (Aml->SmallHeader.DescriptorType & ACPI_RESOURCE_NAME_LARGE)
248     {
249         /* Large descriptor -- bytes 1-2 contain the 16-bit length */
250
251         ACPI_MOVE_16_TO_16 (&Aml->LargeHeader.ResourceLength, &ResourceLength);
252     }
253     else
254     {
255         /* Small descriptor -- bits 2:0 of byte 0 contain the length */
256
257         Aml->SmallHeader.DescriptorType = (UINT8)
258
259             /* Clear any existing length, preserving descriptor type bits */
260
261             ((Aml->SmallHeader.DescriptorType & ~ACPI_RESOURCE_NAME_SMALL_LENGTH_MASK)
262
263             | ResourceLength);
264     }
265 }
266
267
268 /*******************************************************************************
269  *
270  * FUNCTION:    AcpiRsSetResourceHeader
271  *
272  * PARAMETERS:  DescriptorType      - Byte to be inserted as the type
273  *              TotalLength         - Length of the AML descriptor, including
274  *                                    the header and length fields.
275  *              Aml                 - Pointer to the raw AML descriptor
276  *
277  * RETURN:      None
278  *
279  * DESCRIPTION: Set the DescriptorType and ResourceLength fields of an AML
280  *              resource descriptor, both Large and Small descriptors are
281  *              supported automatically
282  *
283  ******************************************************************************/
284
285 void
286 AcpiRsSetResourceHeader (
287     UINT8                   DescriptorType,
288     ACPI_RSDESC_SIZE        TotalLength,
289     AML_RESOURCE            *Aml)
290 {
291     ACPI_FUNCTION_ENTRY ();
292
293
294     /* Set the Resource Type */
295
296     Aml->SmallHeader.DescriptorType = DescriptorType;
297
298     /* Set the Resource Length */
299
300     AcpiRsSetResourceLength (TotalLength, Aml);
301 }
302
303
304 /*******************************************************************************
305  *
306  * FUNCTION:    AcpiRsStrcpy
307  *
308  * PARAMETERS:  Destination         - Pointer to the destination string
309  *              Source              - Pointer to the source string
310  *
311  * RETURN:      String length, including NULL terminator
312  *
313  * DESCRIPTION: Local string copy that returns the string length, saving a
314  *              strcpy followed by a strlen.
315  *
316  ******************************************************************************/
317
318 static UINT16
319 AcpiRsStrcpy (
320     char                    *Destination,
321     char                    *Source)
322 {
323     UINT16                  i;
324
325
326     ACPI_FUNCTION_ENTRY ();
327
328
329     for (i = 0; Source[i]; i++)
330     {
331         Destination[i] = Source[i];
332     }
333
334     Destination[i] = 0;
335
336     /* Return string length including the NULL terminator */
337
338     return ((UINT16) (i + 1));
339 }
340
341
342 /*******************************************************************************
343  *
344  * FUNCTION:    AcpiRsGetResourceSource
345  *
346  * PARAMETERS:  ResourceLength      - Length field of the descriptor
347  *              MinimumLength       - Minimum length of the descriptor (minus
348  *                                    any optional fields)
349  *              ResourceSource      - Where the ResourceSource is returned
350  *              Aml                 - Pointer to the raw AML descriptor
351  *              StringPtr           - (optional) where to store the actual
352  *                                    ResourceSource string
353  *
354  * RETURN:      Length of the string plus NULL terminator, rounded up to native
355  *              word boundary
356  *
357  * DESCRIPTION: Copy the optional ResourceSource data from a raw AML descriptor
358  *              to an internal resource descriptor
359  *
360  ******************************************************************************/
361
362 ACPI_RS_LENGTH
363 AcpiRsGetResourceSource (
364     ACPI_RS_LENGTH          ResourceLength,
365     ACPI_RS_LENGTH          MinimumLength,
366     ACPI_RESOURCE_SOURCE    *ResourceSource,
367     AML_RESOURCE            *Aml,
368     char                    *StringPtr)
369 {
370     ACPI_RSDESC_SIZE        TotalLength;
371     UINT8                   *AmlResourceSource;
372
373
374     ACPI_FUNCTION_ENTRY ();
375
376
377     TotalLength = ResourceLength + sizeof (AML_RESOURCE_LARGE_HEADER);
378     AmlResourceSource = ACPI_ADD_PTR (UINT8, Aml, MinimumLength);
379
380     /*
381      * ResourceSource is present if the length of the descriptor is longer than
382      * the minimum length.
383      *
384      * Note: Some resource descriptors will have an additional null, so
385      * we add 1 to the minimum length.
386      */
387     if (TotalLength > (ACPI_RSDESC_SIZE) (MinimumLength + 1))
388     {
389         /* Get the ResourceSourceIndex */
390
391         ResourceSource->Index = AmlResourceSource[0];
392
393         ResourceSource->StringPtr = StringPtr;
394         if (!StringPtr)
395         {
396             /*
397              * String destination pointer is not specified; Set the String
398              * pointer to the end of the current ResourceSource structure.
399              */
400             ResourceSource->StringPtr = ACPI_ADD_PTR (char, ResourceSource,
401                 sizeof (ACPI_RESOURCE_SOURCE));
402         }
403
404         /*
405          * In order for the Resource length to be a multiple of the native
406          * word, calculate the length of the string (+1 for NULL terminator)
407          * and expand to the next word multiple.
408          *
409          * Zero the entire area of the buffer.
410          */
411         TotalLength = (UINT32) strlen (
412             ACPI_CAST_PTR (char, &AmlResourceSource[1])) + 1;
413         TotalLength = (UINT32) ACPI_ROUND_UP_TO_NATIVE_WORD (TotalLength);
414
415         memset (ResourceSource->StringPtr, 0, TotalLength);
416
417         /* Copy the ResourceSource string to the destination */
418
419         ResourceSource->StringLength = AcpiRsStrcpy (ResourceSource->StringPtr,
420             ACPI_CAST_PTR (char, &AmlResourceSource[1]));
421
422         return ((ACPI_RS_LENGTH) TotalLength);
423     }
424
425     /* ResourceSource is not present */
426
427     ResourceSource->Index = 0;
428     ResourceSource->StringLength = 0;
429     ResourceSource->StringPtr = NULL;
430     return (0);
431 }
432
433
434 /*******************************************************************************
435  *
436  * FUNCTION:    AcpiRsSetResourceSource
437  *
438  * PARAMETERS:  Aml                 - Pointer to the raw AML descriptor
439  *              MinimumLength       - Minimum length of the descriptor (minus
440  *                                    any optional fields)
441  *              ResourceSource      - Internal ResourceSource
442
443  *
444  * RETURN:      Total length of the AML descriptor
445  *
446  * DESCRIPTION: Convert an optional ResourceSource from internal format to a
447  *              raw AML resource descriptor
448  *
449  ******************************************************************************/
450
451 ACPI_RSDESC_SIZE
452 AcpiRsSetResourceSource (
453     AML_RESOURCE            *Aml,
454     ACPI_RS_LENGTH          MinimumLength,
455     ACPI_RESOURCE_SOURCE    *ResourceSource)
456 {
457     UINT8                   *AmlResourceSource;
458     ACPI_RSDESC_SIZE        DescriptorLength;
459
460
461     ACPI_FUNCTION_ENTRY ();
462
463
464     DescriptorLength = MinimumLength;
465
466     /* Non-zero string length indicates presence of a ResourceSource */
467
468     if (ResourceSource->StringLength)
469     {
470         /* Point to the end of the AML descriptor */
471
472         AmlResourceSource = ACPI_ADD_PTR (UINT8, Aml, MinimumLength);
473
474         /* Copy the ResourceSourceIndex */
475
476         AmlResourceSource[0] = (UINT8) ResourceSource->Index;
477
478         /* Copy the ResourceSource string */
479
480         strcpy (ACPI_CAST_PTR (char, &AmlResourceSource[1]),
481             ResourceSource->StringPtr);
482
483         /*
484          * Add the length of the string (+ 1 for null terminator) to the
485          * final descriptor length
486          */
487         DescriptorLength += ((ACPI_RSDESC_SIZE) ResourceSource->StringLength + 1);
488     }
489
490     /* Return the new total length of the AML descriptor */
491
492     return (DescriptorLength);
493 }
494
495
496 /*******************************************************************************
497  *
498  * FUNCTION:    AcpiRsGetPrtMethodData
499  *
500  * PARAMETERS:  Node            - Device node
501  *              RetBuffer       - Pointer to a buffer structure for the
502  *                                results
503  *
504  * RETURN:      Status
505  *
506  * DESCRIPTION: This function is called to get the _PRT value of an object
507  *              contained in an object specified by the handle passed in
508  *
509  *              If the function fails an appropriate status will be returned
510  *              and the contents of the callers buffer is undefined.
511  *
512  ******************************************************************************/
513
514 ACPI_STATUS
515 AcpiRsGetPrtMethodData (
516     ACPI_NAMESPACE_NODE     *Node,
517     ACPI_BUFFER             *RetBuffer)
518 {
519     ACPI_OPERAND_OBJECT     *ObjDesc;
520     ACPI_STATUS             Status;
521
522
523     ACPI_FUNCTION_TRACE (RsGetPrtMethodData);
524
525
526     /* Parameters guaranteed valid by caller */
527
528     /* Execute the method, no parameters */
529
530     Status = AcpiUtEvaluateObject (Node, METHOD_NAME__PRT,
531                 ACPI_BTYPE_PACKAGE, &ObjDesc);
532     if (ACPI_FAILURE (Status))
533     {
534         return_ACPI_STATUS (Status);
535     }
536
537     /*
538      * Create a resource linked list from the byte stream buffer that comes
539      * back from the _CRS method execution.
540      */
541     Status = AcpiRsCreatePciRoutingTable (ObjDesc, RetBuffer);
542
543     /* On exit, we must delete the object returned by EvaluateObject */
544
545     AcpiUtRemoveReference (ObjDesc);
546     return_ACPI_STATUS (Status);
547 }
548
549
550 /*******************************************************************************
551  *
552  * FUNCTION:    AcpiRsGetCrsMethodData
553  *
554  * PARAMETERS:  Node            - Device node
555  *              RetBuffer       - Pointer to a buffer structure for the
556  *                                results
557  *
558  * RETURN:      Status
559  *
560  * DESCRIPTION: This function is called to get the _CRS value of an object
561  *              contained in an object specified by the handle passed in
562  *
563  *              If the function fails an appropriate status will be returned
564  *              and the contents of the callers buffer is undefined.
565  *
566  ******************************************************************************/
567
568 ACPI_STATUS
569 AcpiRsGetCrsMethodData (
570     ACPI_NAMESPACE_NODE     *Node,
571     ACPI_BUFFER             *RetBuffer)
572 {
573     ACPI_OPERAND_OBJECT     *ObjDesc;
574     ACPI_STATUS             Status;
575
576
577     ACPI_FUNCTION_TRACE (RsGetCrsMethodData);
578
579
580     /* Parameters guaranteed valid by caller */
581
582     /* Execute the method, no parameters */
583
584     Status = AcpiUtEvaluateObject (Node, METHOD_NAME__CRS,
585                 ACPI_BTYPE_BUFFER, &ObjDesc);
586     if (ACPI_FAILURE (Status))
587     {
588         return_ACPI_STATUS (Status);
589     }
590
591     /*
592      * Make the call to create a resource linked list from the
593      * byte stream buffer that comes back from the _CRS method
594      * execution.
595      */
596     Status = AcpiRsCreateResourceList (ObjDesc, RetBuffer);
597
598     /* On exit, we must delete the object returned by evaluateObject */
599
600     AcpiUtRemoveReference (ObjDesc);
601     return_ACPI_STATUS (Status);
602 }
603
604
605 /*******************************************************************************
606  *
607  * FUNCTION:    AcpiRsGetPrsMethodData
608  *
609  * PARAMETERS:  Node            - Device node
610  *              RetBuffer       - Pointer to a buffer structure for the
611  *                                results
612  *
613  * RETURN:      Status
614  *
615  * DESCRIPTION: This function is called to get the _PRS value of an object
616  *              contained in an object specified by the handle passed in
617  *
618  *              If the function fails an appropriate status will be returned
619  *              and the contents of the callers buffer is undefined.
620  *
621  ******************************************************************************/
622
623 ACPI_STATUS
624 AcpiRsGetPrsMethodData (
625     ACPI_NAMESPACE_NODE     *Node,
626     ACPI_BUFFER             *RetBuffer)
627 {
628     ACPI_OPERAND_OBJECT     *ObjDesc;
629     ACPI_STATUS             Status;
630
631
632     ACPI_FUNCTION_TRACE (RsGetPrsMethodData);
633
634
635     /* Parameters guaranteed valid by caller */
636
637     /* Execute the method, no parameters */
638
639     Status = AcpiUtEvaluateObject (Node, METHOD_NAME__PRS,
640                 ACPI_BTYPE_BUFFER, &ObjDesc);
641     if (ACPI_FAILURE (Status))
642     {
643         return_ACPI_STATUS (Status);
644     }
645
646     /*
647      * Make the call to create a resource linked list from the
648      * byte stream buffer that comes back from the _CRS method
649      * execution.
650      */
651     Status = AcpiRsCreateResourceList (ObjDesc, RetBuffer);
652
653     /* On exit, we must delete the object returned by evaluateObject */
654
655     AcpiUtRemoveReference (ObjDesc);
656     return_ACPI_STATUS (Status);
657 }
658
659
660 /*******************************************************************************
661  *
662  * FUNCTION:    AcpiRsGetAeiMethodData
663  *
664  * PARAMETERS:  Node            - Device node
665  *              RetBuffer       - Pointer to a buffer structure for the
666  *                                results
667  *
668  * RETURN:      Status
669  *
670  * DESCRIPTION: This function is called to get the _AEI value of an object
671  *              contained in an object specified by the handle passed in
672  *
673  *              If the function fails an appropriate status will be returned
674  *              and the contents of the callers buffer is undefined.
675  *
676  ******************************************************************************/
677
678 ACPI_STATUS
679 AcpiRsGetAeiMethodData (
680     ACPI_NAMESPACE_NODE     *Node,
681     ACPI_BUFFER             *RetBuffer)
682 {
683     ACPI_OPERAND_OBJECT     *ObjDesc;
684     ACPI_STATUS             Status;
685
686
687     ACPI_FUNCTION_TRACE (RsGetAeiMethodData);
688
689
690     /* Parameters guaranteed valid by caller */
691
692     /* Execute the method, no parameters */
693
694     Status = AcpiUtEvaluateObject (Node, METHOD_NAME__AEI,
695                 ACPI_BTYPE_BUFFER, &ObjDesc);
696     if (ACPI_FAILURE (Status))
697     {
698         return_ACPI_STATUS (Status);
699     }
700
701     /*
702      * Make the call to create a resource linked list from the
703      * byte stream buffer that comes back from the _CRS method
704      * execution.
705      */
706     Status = AcpiRsCreateResourceList (ObjDesc, RetBuffer);
707
708     /* On exit, we must delete the object returned by evaluateObject */
709
710     AcpiUtRemoveReference (ObjDesc);
711     return_ACPI_STATUS (Status);
712 }
713
714
715 /*******************************************************************************
716  *
717  * FUNCTION:    AcpiRsGetMethodData
718  *
719  * PARAMETERS:  Handle          - Handle to the containing object
720  *              Path            - Path to method, relative to Handle
721  *              RetBuffer       - Pointer to a buffer structure for the
722  *                                results
723  *
724  * RETURN:      Status
725  *
726  * DESCRIPTION: This function is called to get the _CRS or _PRS value of an
727  *              object contained in an object specified by the handle passed in
728  *
729  *              If the function fails an appropriate status will be returned
730  *              and the contents of the callers buffer is undefined.
731  *
732  ******************************************************************************/
733
734 ACPI_STATUS
735 AcpiRsGetMethodData (
736     ACPI_HANDLE             Handle,
737     char                    *Path,
738     ACPI_BUFFER             *RetBuffer)
739 {
740     ACPI_OPERAND_OBJECT     *ObjDesc;
741     ACPI_STATUS             Status;
742
743
744     ACPI_FUNCTION_TRACE (RsGetMethodData);
745
746
747     /* Parameters guaranteed valid by caller */
748
749     /* Execute the method, no parameters */
750
751     Status = AcpiUtEvaluateObject (ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Handle),
752         Path, ACPI_BTYPE_BUFFER, &ObjDesc);
753     if (ACPI_FAILURE (Status))
754     {
755         return_ACPI_STATUS (Status);
756     }
757
758     /*
759      * Make the call to create a resource linked list from the
760      * byte stream buffer that comes back from the method
761      * execution.
762      */
763     Status = AcpiRsCreateResourceList (ObjDesc, RetBuffer);
764
765     /* On exit, we must delete the object returned by EvaluateObject */
766
767     AcpiUtRemoveReference (ObjDesc);
768     return_ACPI_STATUS (Status);
769 }
770
771
772 /*******************************************************************************
773  *
774  * FUNCTION:    AcpiRsSetSrsMethodData
775  *
776  * PARAMETERS:  Node            - Device node
777  *              InBuffer        - Pointer to a buffer structure of the
778  *                                parameter
779  *
780  * RETURN:      Status
781  *
782  * DESCRIPTION: This function is called to set the _SRS of an object contained
783  *              in an object specified by the handle passed in
784  *
785  *              If the function fails an appropriate status will be returned
786  *              and the contents of the callers buffer is undefined.
787  *
788  * Note: Parameters guaranteed valid by caller
789  *
790  ******************************************************************************/
791
792 ACPI_STATUS
793 AcpiRsSetSrsMethodData (
794     ACPI_NAMESPACE_NODE     *Node,
795     ACPI_BUFFER             *InBuffer)
796 {
797     ACPI_EVALUATE_INFO      *Info;
798     ACPI_OPERAND_OBJECT     *Args[2];
799     ACPI_STATUS             Status;
800     ACPI_BUFFER             Buffer;
801
802
803     ACPI_FUNCTION_TRACE (RsSetSrsMethodData);
804
805
806     /* Allocate and initialize the evaluation information block */
807
808     Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
809     if (!Info)
810     {
811         return_ACPI_STATUS (AE_NO_MEMORY);
812     }
813
814     Info->PrefixNode = Node;
815     Info->RelativePathname = METHOD_NAME__SRS;
816     Info->Parameters = Args;
817     Info->Flags = ACPI_IGNORE_RETURN_VALUE;
818
819     /*
820      * The InBuffer parameter will point to a linked list of
821      * resource parameters. It needs to be formatted into a
822      * byte stream to be sent in as an input parameter to _SRS
823      *
824      * Convert the linked list into a byte stream
825      */
826     Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
827     Status = AcpiRsCreateAmlResources (InBuffer, &Buffer);
828     if (ACPI_FAILURE (Status))
829     {
830         goto Cleanup;
831     }
832
833     /* Create and initialize the method parameter object */
834
835     Args[0] = AcpiUtCreateInternalObject (ACPI_TYPE_BUFFER);
836     if (!Args[0])
837     {
838         /*
839          * Must free the buffer allocated above (otherwise it is freed
840          * later)
841          */
842         ACPI_FREE (Buffer.Pointer);
843         Status = AE_NO_MEMORY;
844         goto Cleanup;
845     }
846
847     Args[0]->Buffer.Length  = (UINT32) Buffer.Length;
848     Args[0]->Buffer.Pointer = Buffer.Pointer;
849     Args[0]->Common.Flags   = AOPOBJ_DATA_VALID;
850     Args[1] = NULL;
851
852     /* Execute the method, no return value is expected */
853
854     Status = AcpiNsEvaluate (Info);
855
856     /* Clean up and return the status from AcpiNsEvaluate */
857
858     AcpiUtRemoveReference (Args[0]);
859
860 Cleanup:
861     ACPI_FREE (Info);
862     return_ACPI_STATUS (Status);
863 }