Sync ACPICA with Intel's version 20180508 (from previously 20170831).
[dragonfly.git] / sys / contrib / dev / acpica / source / components / resources / rsxface.c
blob6c856db7ad86c85596e9a14c8df6c024c464b796
1 /*******************************************************************************
3 * Module Name: rsxface - Public interfaces to the resource manager
5 ******************************************************************************/
7 /******************************************************************************
9 * 1. Copyright Notice
11 * Some or all of this work - Copyright (c) 1999 - 2018, Intel Corp.
12 * All rights reserved.
14 * 2. License
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.
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
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;
37 * The above copyright and patent license is granted only if the following
38 * conditions are met:
40 * 3. Conditions
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.
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.
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.
72 * 3.4. Intel retains all right, title, and interest in and to the Original
73 * Intel Code.
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.
80 * 4. Disclaimer and Export Compliance
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.
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.
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.
114 *****************************************************************************
116 * Alternatively, you may choose to be licensed under the terms of the
117 * following license:
119 * Redistribution and use in source and binary forms, with or without
120 * modification, are permitted provided that the following conditions
121 * are met:
122 * 1. Redistributions of source code must retain the above copyright
123 * notice, this list of conditions, and the following disclaimer,
124 * without modification.
125 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126 * substantially similar to the "NO WARRANTY" disclaimer below
127 * ("Disclaimer") and any redistribution must be conditioned upon
128 * including a substantially similar Disclaimer requirement for further
129 * binary redistribution.
130 * 3. Neither the names of the above-listed copyright holders nor the names
131 * of any contributors may be used to endorse or promote products derived
132 * from this software without specific prior written permission.
134 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
146 * Alternatively, you may choose to be licensed under the terms of the
147 * GNU General Public License ("GPL") version 2 as published by the Free
148 * Software Foundation.
150 *****************************************************************************/
152 #define EXPORT_ACPI_INTERFACES
154 #include "acpi.h"
155 #include "accommon.h"
156 #include "acresrc.h"
157 #include "acnamesp.h"
159 #define _COMPONENT ACPI_RESOURCES
160 ACPI_MODULE_NAME ("rsxface")
162 /* Local macros for 16,32-bit to 64-bit conversion */
164 #define ACPI_COPY_FIELD(Out, In, Field) ((Out)->Field = (In)->Field)
165 #define ACPI_COPY_ADDRESS(Out, In) \
166 ACPI_COPY_FIELD(Out, In, ResourceType); \
167 ACPI_COPY_FIELD(Out, In, ProducerConsumer); \
168 ACPI_COPY_FIELD(Out, In, Decode); \
169 ACPI_COPY_FIELD(Out, In, MinAddressFixed); \
170 ACPI_COPY_FIELD(Out, In, MaxAddressFixed); \
171 ACPI_COPY_FIELD(Out, In, Info); \
172 ACPI_COPY_FIELD(Out, In, Address.Granularity); \
173 ACPI_COPY_FIELD(Out, In, Address.Minimum); \
174 ACPI_COPY_FIELD(Out, In, Address.Maximum); \
175 ACPI_COPY_FIELD(Out, In, Address.TranslationOffset); \
176 ACPI_COPY_FIELD(Out, In, Address.AddressLength); \
177 ACPI_COPY_FIELD(Out, In, ResourceSource);
180 /* Local prototypes */
182 static ACPI_STATUS
183 AcpiRsMatchVendorResource (
184 ACPI_RESOURCE *Resource,
185 void *Context);
187 static ACPI_STATUS
188 AcpiRsValidateParameters (
189 ACPI_HANDLE DeviceHandle,
190 ACPI_BUFFER *Buffer,
191 ACPI_NAMESPACE_NODE **ReturnNode);
194 /*******************************************************************************
196 * FUNCTION: AcpiRsValidateParameters
198 * PARAMETERS: DeviceHandle - Handle to a device
199 * Buffer - Pointer to a data buffer
200 * ReturnNode - Pointer to where the device node is returned
202 * RETURN: Status
204 * DESCRIPTION: Common parameter validation for resource interfaces
206 ******************************************************************************/
208 static ACPI_STATUS
209 AcpiRsValidateParameters (
210 ACPI_HANDLE DeviceHandle,
211 ACPI_BUFFER *Buffer,
212 ACPI_NAMESPACE_NODE **ReturnNode)
214 ACPI_STATUS Status;
215 ACPI_NAMESPACE_NODE *Node;
218 ACPI_FUNCTION_TRACE (RsValidateParameters);
222 * Must have a valid handle to an ACPI device
224 if (!DeviceHandle)
226 return_ACPI_STATUS (AE_BAD_PARAMETER);
229 Node = AcpiNsValidateHandle (DeviceHandle);
230 if (!Node)
232 return_ACPI_STATUS (AE_BAD_PARAMETER);
235 if (Node->Type != ACPI_TYPE_DEVICE)
237 return_ACPI_STATUS (AE_TYPE);
241 * Validate the user buffer object
243 * if there is a non-zero buffer length we also need a valid pointer in
244 * the buffer. If it's a zero buffer length, we'll be returning the
245 * needed buffer size (later), so keep going.
247 Status = AcpiUtValidateBuffer (Buffer);
248 if (ACPI_FAILURE (Status))
250 return_ACPI_STATUS (Status);
253 *ReturnNode = Node;
254 return_ACPI_STATUS (AE_OK);
258 /*******************************************************************************
260 * FUNCTION: AcpiGetIrqRoutingTable
262 * PARAMETERS: DeviceHandle - Handle to the Bus device we are querying
263 * RetBuffer - Pointer to a buffer to receive the
264 * current resources for the device
266 * RETURN: Status
268 * DESCRIPTION: This function is called to get the IRQ routing table for a
269 * specific bus. The caller must first acquire a handle for the
270 * desired bus. The routine table is placed in the buffer pointed
271 * to by the RetBuffer variable parameter.
273 * If the function fails an appropriate status will be returned
274 * and the value of RetBuffer is undefined.
276 * This function attempts to execute the _PRT method contained in
277 * the object indicated by the passed DeviceHandle.
279 ******************************************************************************/
281 ACPI_STATUS
282 AcpiGetIrqRoutingTable (
283 ACPI_HANDLE DeviceHandle,
284 ACPI_BUFFER *RetBuffer)
286 ACPI_STATUS Status;
287 ACPI_NAMESPACE_NODE *Node;
290 ACPI_FUNCTION_TRACE (AcpiGetIrqRoutingTable);
293 /* Validate parameters then dispatch to internal routine */
295 Status = AcpiRsValidateParameters (DeviceHandle, RetBuffer, &Node);
296 if (ACPI_FAILURE (Status))
298 return_ACPI_STATUS (Status);
301 Status = AcpiRsGetPrtMethodData (Node, RetBuffer);
302 return_ACPI_STATUS (Status);
305 ACPI_EXPORT_SYMBOL (AcpiGetIrqRoutingTable)
308 /*******************************************************************************
310 * FUNCTION: AcpiGetCurrentResources
312 * PARAMETERS: DeviceHandle - Handle to the device object for the
313 * device we are querying
314 * RetBuffer - Pointer to a buffer to receive the
315 * current resources for the device
317 * RETURN: Status
319 * DESCRIPTION: This function is called to get the current resources for a
320 * specific device. The caller must first acquire a handle for
321 * the desired device. The resource data is placed in the buffer
322 * pointed to by the RetBuffer variable parameter.
324 * If the function fails an appropriate status will be returned
325 * and the value of RetBuffer is undefined.
327 * This function attempts to execute the _CRS method contained in
328 * the object indicated by the passed DeviceHandle.
330 ******************************************************************************/
332 ACPI_STATUS
333 AcpiGetCurrentResources (
334 ACPI_HANDLE DeviceHandle,
335 ACPI_BUFFER *RetBuffer)
337 ACPI_STATUS Status;
338 ACPI_NAMESPACE_NODE *Node;
341 ACPI_FUNCTION_TRACE (AcpiGetCurrentResources);
344 /* Validate parameters then dispatch to internal routine */
346 Status = AcpiRsValidateParameters (DeviceHandle, RetBuffer, &Node);
347 if (ACPI_FAILURE (Status))
349 return_ACPI_STATUS (Status);
352 Status = AcpiRsGetCrsMethodData (Node, RetBuffer);
353 return_ACPI_STATUS (Status);
356 ACPI_EXPORT_SYMBOL (AcpiGetCurrentResources)
359 /*******************************************************************************
361 * FUNCTION: AcpiGetPossibleResources
363 * PARAMETERS: DeviceHandle - Handle to the device object for the
364 * device we are querying
365 * RetBuffer - Pointer to a buffer to receive the
366 * resources for the device
368 * RETURN: Status
370 * DESCRIPTION: This function is called to get a list of the possible resources
371 * for a specific device. The caller must first acquire a handle
372 * for the desired device. The resource data is placed in the
373 * buffer pointed to by the RetBuffer variable.
375 * If the function fails an appropriate status will be returned
376 * and the value of RetBuffer is undefined.
378 ******************************************************************************/
380 ACPI_STATUS
381 AcpiGetPossibleResources (
382 ACPI_HANDLE DeviceHandle,
383 ACPI_BUFFER *RetBuffer)
385 ACPI_STATUS Status;
386 ACPI_NAMESPACE_NODE *Node;
389 ACPI_FUNCTION_TRACE (AcpiGetPossibleResources);
392 /* Validate parameters then dispatch to internal routine */
394 Status = AcpiRsValidateParameters (DeviceHandle, RetBuffer, &Node);
395 if (ACPI_FAILURE (Status))
397 return_ACPI_STATUS (Status);
400 Status = AcpiRsGetPrsMethodData (Node, RetBuffer);
401 return_ACPI_STATUS (Status);
404 ACPI_EXPORT_SYMBOL (AcpiGetPossibleResources)
407 /*******************************************************************************
409 * FUNCTION: AcpiSetCurrentResources
411 * PARAMETERS: DeviceHandle - Handle to the device object for the
412 * device we are setting resources
413 * InBuffer - Pointer to a buffer containing the
414 * resources to be set for the device
416 * RETURN: Status
418 * DESCRIPTION: This function is called to set the current resources for a
419 * specific device. The caller must first acquire a handle for
420 * the desired device. The resource data is passed to the routine
421 * the buffer pointed to by the InBuffer variable.
423 ******************************************************************************/
425 ACPI_STATUS
426 AcpiSetCurrentResources (
427 ACPI_HANDLE DeviceHandle,
428 ACPI_BUFFER *InBuffer)
430 ACPI_STATUS Status;
431 ACPI_NAMESPACE_NODE *Node;
434 ACPI_FUNCTION_TRACE (AcpiSetCurrentResources);
437 /* Validate the buffer, don't allow zero length */
439 if ((!InBuffer) ||
440 (!InBuffer->Pointer) ||
441 (!InBuffer->Length))
443 return_ACPI_STATUS (AE_BAD_PARAMETER);
446 /* Validate parameters then dispatch to internal routine */
448 Status = AcpiRsValidateParameters (DeviceHandle, InBuffer, &Node);
449 if (ACPI_FAILURE (Status))
451 return_ACPI_STATUS (Status);
454 Status = AcpiRsSetSrsMethodData (Node, InBuffer);
455 return_ACPI_STATUS (Status);
458 ACPI_EXPORT_SYMBOL (AcpiSetCurrentResources)
461 /*******************************************************************************
463 * FUNCTION: AcpiGetEventResources
465 * PARAMETERS: DeviceHandle - Handle to the device object for the
466 * device we are getting resources
467 * InBuffer - Pointer to a buffer containing the
468 * resources to be set for the device
470 * RETURN: Status
472 * DESCRIPTION: This function is called to get the event resources for a
473 * specific device. The caller must first acquire a handle for
474 * the desired device. The resource data is passed to the routine
475 * the buffer pointed to by the InBuffer variable. Uses the
476 * _AEI method.
478 ******************************************************************************/
480 ACPI_STATUS
481 AcpiGetEventResources (
482 ACPI_HANDLE DeviceHandle,
483 ACPI_BUFFER *RetBuffer)
485 ACPI_STATUS Status;
486 ACPI_NAMESPACE_NODE *Node;
489 ACPI_FUNCTION_TRACE (AcpiGetEventResources);
492 /* Validate parameters then dispatch to internal routine */
494 Status = AcpiRsValidateParameters (DeviceHandle, RetBuffer, &Node);
495 if (ACPI_FAILURE (Status))
497 return_ACPI_STATUS (Status);
500 Status = AcpiRsGetAeiMethodData (Node, RetBuffer);
501 return_ACPI_STATUS (Status);
504 ACPI_EXPORT_SYMBOL (AcpiGetEventResources)
507 /******************************************************************************
509 * FUNCTION: AcpiResourceToAddress64
511 * PARAMETERS: Resource - Pointer to a resource
512 * Out - Pointer to the users's return buffer
513 * (a struct acpi_resource_address64)
515 * RETURN: Status
517 * DESCRIPTION: If the resource is an address16, address32, or address64,
518 * copy it to the address64 return buffer. This saves the
519 * caller from having to duplicate code for different-sized
520 * addresses.
522 ******************************************************************************/
524 ACPI_STATUS
525 AcpiResourceToAddress64 (
526 ACPI_RESOURCE *Resource,
527 ACPI_RESOURCE_ADDRESS64 *Out)
529 ACPI_RESOURCE_ADDRESS16 *Address16;
530 ACPI_RESOURCE_ADDRESS32 *Address32;
533 if (!Resource || !Out)
535 return (AE_BAD_PARAMETER);
538 /* Convert 16 or 32 address descriptor to 64 */
540 switch (Resource->Type)
542 case ACPI_RESOURCE_TYPE_ADDRESS16:
544 Address16 = ACPI_CAST_PTR (
545 ACPI_RESOURCE_ADDRESS16, &Resource->Data);
546 ACPI_COPY_ADDRESS (Out, Address16);
547 break;
549 case ACPI_RESOURCE_TYPE_ADDRESS32:
551 Address32 = ACPI_CAST_PTR (
552 ACPI_RESOURCE_ADDRESS32, &Resource->Data);
553 ACPI_COPY_ADDRESS (Out, Address32);
554 break;
556 case ACPI_RESOURCE_TYPE_ADDRESS64:
558 /* Simple copy for 64 bit source */
560 memcpy (Out, &Resource->Data, sizeof (ACPI_RESOURCE_ADDRESS64));
561 break;
563 default:
565 return (AE_BAD_PARAMETER);
568 return (AE_OK);
571 ACPI_EXPORT_SYMBOL (AcpiResourceToAddress64)
574 /*******************************************************************************
576 * FUNCTION: AcpiGetVendorResource
578 * PARAMETERS: DeviceHandle - Handle for the parent device object
579 * Name - Method name for the parent resource
580 * (METHOD_NAME__CRS or METHOD_NAME__PRS)
581 * Uuid - Pointer to the UUID to be matched.
582 * includes both subtype and 16-byte UUID
583 * RetBuffer - Where the vendor resource is returned
585 * RETURN: Status
587 * DESCRIPTION: Walk a resource template for the specified device to find a
588 * vendor-defined resource that matches the supplied UUID and
589 * UUID subtype. Returns a ACPI_RESOURCE of type Vendor.
591 ******************************************************************************/
593 ACPI_STATUS
594 AcpiGetVendorResource (
595 ACPI_HANDLE DeviceHandle,
596 char *Name,
597 ACPI_VENDOR_UUID *Uuid,
598 ACPI_BUFFER *RetBuffer)
600 ACPI_VENDOR_WALK_INFO Info;
601 ACPI_STATUS Status;
604 /* Other parameters are validated by AcpiWalkResources */
606 if (!Uuid || !RetBuffer)
608 return (AE_BAD_PARAMETER);
611 Info.Uuid = Uuid;
612 Info.Buffer = RetBuffer;
613 Info.Status = AE_NOT_EXIST;
615 /* Walk the _CRS or _PRS resource list for this device */
617 Status = AcpiWalkResources (
618 DeviceHandle, Name, AcpiRsMatchVendorResource, &Info);
619 if (ACPI_FAILURE (Status))
621 return (Status);
624 return (Info.Status);
627 ACPI_EXPORT_SYMBOL (AcpiGetVendorResource)
630 /*******************************************************************************
632 * FUNCTION: AcpiRsMatchVendorResource
634 * PARAMETERS: ACPI_WALK_RESOURCE_CALLBACK
636 * RETURN: Status
638 * DESCRIPTION: Match a vendor resource via the ACPI 3.0 UUID
640 ******************************************************************************/
642 static ACPI_STATUS
643 AcpiRsMatchVendorResource (
644 ACPI_RESOURCE *Resource,
645 void *Context)
647 ACPI_VENDOR_WALK_INFO *Info = Context;
648 ACPI_RESOURCE_VENDOR_TYPED *Vendor;
649 ACPI_BUFFER *Buffer;
650 ACPI_STATUS Status;
653 /* Ignore all descriptors except Vendor */
655 if (Resource->Type != ACPI_RESOURCE_TYPE_VENDOR)
657 return (AE_OK);
660 Vendor = &Resource->Data.VendorTyped;
663 * For a valid match, these conditions must hold:
665 * 1) Length of descriptor data must be at least as long as a UUID struct
666 * 2) The UUID subtypes must match
667 * 3) The UUID data must match
669 if ((Vendor->ByteLength < (ACPI_UUID_LENGTH + 1)) ||
670 (Vendor->UuidSubtype != Info->Uuid->Subtype) ||
671 (memcmp (Vendor->Uuid, Info->Uuid->Data, ACPI_UUID_LENGTH)))
673 return (AE_OK);
676 /* Validate/Allocate/Clear caller buffer */
678 Buffer = Info->Buffer;
679 Status = AcpiUtInitializeBuffer (Buffer, Resource->Length);
680 if (ACPI_FAILURE (Status))
682 return (Status);
685 /* Found the correct resource, copy and return it */
687 memcpy (Buffer->Pointer, Resource, Resource->Length);
688 Buffer->Length = Resource->Length;
690 /* Found the desired descriptor, terminate resource walk */
692 Info->Status = AE_OK;
693 return (AE_CTRL_TERMINATE);
697 /*******************************************************************************
699 * FUNCTION: AcpiWalkResourceBuffer
701 * PARAMETERS: Buffer - Formatted buffer returned by one of the
702 * various Get*Resource functions
703 * UserFunction - Called for each resource
704 * Context - Passed to UserFunction
706 * RETURN: Status
708 * DESCRIPTION: Walks the input resource template. The UserFunction is called
709 * once for each resource in the list.
711 ******************************************************************************/
713 ACPI_STATUS
714 AcpiWalkResourceBuffer (
715 ACPI_BUFFER *Buffer,
716 ACPI_WALK_RESOURCE_CALLBACK UserFunction,
717 void *Context)
719 ACPI_STATUS Status = AE_OK;
720 ACPI_RESOURCE *Resource;
721 ACPI_RESOURCE *ResourceEnd;
724 ACPI_FUNCTION_TRACE (AcpiWalkResourceBuffer);
727 /* Parameter validation */
729 if (!Buffer || !Buffer->Pointer || !UserFunction)
731 return_ACPI_STATUS (AE_BAD_PARAMETER);
734 /* Buffer contains the resource list and length */
736 Resource = ACPI_CAST_PTR (ACPI_RESOURCE, Buffer->Pointer);
737 ResourceEnd = ACPI_ADD_PTR (
738 ACPI_RESOURCE, Buffer->Pointer, Buffer->Length);
740 /* Walk the resource list until the EndTag is found (or buffer end) */
742 while (Resource < ResourceEnd)
744 /* Sanity check the resource type */
746 if (Resource->Type > ACPI_RESOURCE_TYPE_MAX)
748 Status = AE_AML_INVALID_RESOURCE_TYPE;
749 break;
752 /* Sanity check the length. It must not be zero, or we loop forever */
754 if (!Resource->Length)
756 return_ACPI_STATUS (AE_AML_BAD_RESOURCE_LENGTH);
759 /* Invoke the user function, abort on any error returned */
761 Status = UserFunction (Resource, Context);
762 if (ACPI_FAILURE (Status))
764 if (Status == AE_CTRL_TERMINATE)
766 /* This is an OK termination by the user function */
768 Status = AE_OK;
770 break;
773 /* EndTag indicates end-of-list */
775 if (Resource->Type == ACPI_RESOURCE_TYPE_END_TAG)
777 break;
780 /* Get the next resource descriptor */
782 Resource = ACPI_NEXT_RESOURCE (Resource);
785 return_ACPI_STATUS (Status);
788 ACPI_EXPORT_SYMBOL (AcpiWalkResourceBuffer)
791 /*******************************************************************************
793 * FUNCTION: AcpiWalkResources
795 * PARAMETERS: DeviceHandle - Handle to the device object for the
796 * device we are querying
797 * Name - Method name of the resources we want.
798 * (METHOD_NAME__CRS, METHOD_NAME__PRS, or
799 * METHOD_NAME__AEI or METHOD_NAME__DMA)
800 * UserFunction - Called for each resource
801 * Context - Passed to UserFunction
803 * RETURN: Status
805 * DESCRIPTION: Retrieves the current or possible resource list for the
806 * specified device. The UserFunction is called once for
807 * each resource in the list.
809 ******************************************************************************/
811 ACPI_STATUS
812 AcpiWalkResources (
813 ACPI_HANDLE DeviceHandle,
814 char *Name,
815 ACPI_WALK_RESOURCE_CALLBACK UserFunction,
816 void *Context)
818 ACPI_STATUS Status;
819 ACPI_BUFFER Buffer;
822 ACPI_FUNCTION_TRACE (AcpiWalkResources);
825 /* Parameter validation */
827 if (!DeviceHandle || !UserFunction || !Name ||
828 (!ACPI_COMPARE_NAME (Name, METHOD_NAME__CRS) &&
829 !ACPI_COMPARE_NAME (Name, METHOD_NAME__PRS) &&
830 !ACPI_COMPARE_NAME (Name, METHOD_NAME__AEI) &&
831 !ACPI_COMPARE_NAME (Name, METHOD_NAME__DMA)))
833 return_ACPI_STATUS (AE_BAD_PARAMETER);
836 /* Get the _CRS/_PRS/_AEI/_DMA resource list */
838 Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
839 Status = AcpiRsGetMethodData (DeviceHandle, Name, &Buffer);
840 if (ACPI_FAILURE (Status))
842 return_ACPI_STATUS (Status);
845 /* Walk the resource list and cleanup */
847 Status = AcpiWalkResourceBuffer (&Buffer, UserFunction, Context);
848 ACPI_FREE (Buffer.Pointer);
849 return_ACPI_STATUS (Status);
852 ACPI_EXPORT_SYMBOL (AcpiWalkResources)