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