1 /*******************************************************************************
3 * Module Name: rsxface - Public interfaces to the resource manager
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2015, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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.
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.
44 #define EXPORT_ACPI_INTERFACES
51 #define _COMPONENT ACPI_RESOURCES
52 ACPI_MODULE_NAME ("rsxface")
54 /* Local macros for 16,32-bit to 64-bit conversion */
56 #define ACPI_COPY_FIELD(Out, In, Field) ((Out)->Field = (In)->Field)
57 #define ACPI_COPY_ADDRESS(Out, In) \
58 ACPI_COPY_FIELD(Out, In, ResourceType); \
59 ACPI_COPY_FIELD(Out, In, ProducerConsumer); \
60 ACPI_COPY_FIELD(Out, In, Decode); \
61 ACPI_COPY_FIELD(Out, In, MinAddressFixed); \
62 ACPI_COPY_FIELD(Out, In, MaxAddressFixed); \
63 ACPI_COPY_FIELD(Out, In, Info); \
64 ACPI_COPY_FIELD(Out, In, Address.Granularity); \
65 ACPI_COPY_FIELD(Out, In, Address.Minimum); \
66 ACPI_COPY_FIELD(Out, In, Address.Maximum); \
67 ACPI_COPY_FIELD(Out, In, Address.TranslationOffset); \
68 ACPI_COPY_FIELD(Out, In, Address.AddressLength); \
69 ACPI_COPY_FIELD(Out, In, ResourceSource);
72 /* Local prototypes */
75 AcpiRsMatchVendorResource (
76 ACPI_RESOURCE *Resource,
80 AcpiRsValidateParameters (
81 ACPI_HANDLE DeviceHandle,
83 ACPI_NAMESPACE_NODE **ReturnNode);
86 /*******************************************************************************
88 * FUNCTION: AcpiRsValidateParameters
90 * PARAMETERS: DeviceHandle - Handle to a device
91 * Buffer - Pointer to a data buffer
92 * ReturnNode - Pointer to where the device node is returned
96 * DESCRIPTION: Common parameter validation for resource interfaces
98 ******************************************************************************/
101 AcpiRsValidateParameters (
102 ACPI_HANDLE DeviceHandle,
104 ACPI_NAMESPACE_NODE **ReturnNode)
107 ACPI_NAMESPACE_NODE *Node;
110 ACPI_FUNCTION_TRACE (RsValidateParameters);
114 * Must have a valid handle to an ACPI device
118 return_ACPI_STATUS (AE_BAD_PARAMETER);
121 Node = AcpiNsValidateHandle (DeviceHandle);
124 return_ACPI_STATUS (AE_BAD_PARAMETER);
127 if (Node->Type != ACPI_TYPE_DEVICE)
129 return_ACPI_STATUS (AE_TYPE);
133 * Validate the user buffer object
135 * if there is a non-zero buffer length we also need a valid pointer in
136 * the buffer. If it's a zero buffer length, we'll be returning the
137 * needed buffer size (later), so keep going.
139 Status = AcpiUtValidateBuffer (Buffer);
140 if (ACPI_FAILURE (Status))
142 return_ACPI_STATUS (Status);
146 return_ACPI_STATUS (AE_OK);
150 /*******************************************************************************
152 * FUNCTION: AcpiGetIrqRoutingTable
154 * PARAMETERS: DeviceHandle - Handle to the Bus device we are querying
155 * RetBuffer - Pointer to a buffer to receive the
156 * current resources for the device
160 * DESCRIPTION: This function is called to get the IRQ routing table for a
161 * specific bus. The caller must first acquire a handle for the
162 * desired bus. The routine table is placed in the buffer pointed
163 * to by the RetBuffer variable parameter.
165 * If the function fails an appropriate status will be returned
166 * and the value of RetBuffer is undefined.
168 * This function attempts to execute the _PRT method contained in
169 * the object indicated by the passed DeviceHandle.
171 ******************************************************************************/
174 AcpiGetIrqRoutingTable (
175 ACPI_HANDLE DeviceHandle,
176 ACPI_BUFFER *RetBuffer)
179 ACPI_NAMESPACE_NODE *Node;
182 ACPI_FUNCTION_TRACE (AcpiGetIrqRoutingTable);
185 /* Validate parameters then dispatch to internal routine */
187 Status = AcpiRsValidateParameters (DeviceHandle, RetBuffer, &Node);
188 if (ACPI_FAILURE (Status))
190 return_ACPI_STATUS (Status);
193 Status = AcpiRsGetPrtMethodData (Node, RetBuffer);
194 return_ACPI_STATUS (Status);
197 ACPI_EXPORT_SYMBOL (AcpiGetIrqRoutingTable)
200 /*******************************************************************************
202 * FUNCTION: AcpiGetCurrentResources
204 * PARAMETERS: DeviceHandle - Handle to the device object for the
205 * device we are querying
206 * RetBuffer - Pointer to a buffer to receive the
207 * current resources for the device
211 * DESCRIPTION: This function is called to get the current resources for a
212 * specific device. The caller must first acquire a handle for
213 * the desired device. The resource data is placed in the buffer
214 * pointed to by the RetBuffer variable parameter.
216 * If the function fails an appropriate status will be returned
217 * and the value of RetBuffer is undefined.
219 * This function attempts to execute the _CRS method contained in
220 * the object indicated by the passed DeviceHandle.
222 ******************************************************************************/
225 AcpiGetCurrentResources (
226 ACPI_HANDLE DeviceHandle,
227 ACPI_BUFFER *RetBuffer)
230 ACPI_NAMESPACE_NODE *Node;
233 ACPI_FUNCTION_TRACE (AcpiGetCurrentResources);
236 /* Validate parameters then dispatch to internal routine */
238 Status = AcpiRsValidateParameters (DeviceHandle, RetBuffer, &Node);
239 if (ACPI_FAILURE (Status))
241 return_ACPI_STATUS (Status);
244 Status = AcpiRsGetCrsMethodData (Node, RetBuffer);
245 return_ACPI_STATUS (Status);
248 ACPI_EXPORT_SYMBOL (AcpiGetCurrentResources)
251 /*******************************************************************************
253 * FUNCTION: AcpiGetPossibleResources
255 * PARAMETERS: DeviceHandle - Handle to the device object for the
256 * device we are querying
257 * RetBuffer - Pointer to a buffer to receive the
258 * resources for the device
262 * DESCRIPTION: This function is called to get a list of the possible resources
263 * for a specific device. The caller must first acquire a handle
264 * for the desired device. The resource data is placed in the
265 * buffer pointed to by the RetBuffer variable.
267 * If the function fails an appropriate status will be returned
268 * and the value of RetBuffer is undefined.
270 ******************************************************************************/
273 AcpiGetPossibleResources (
274 ACPI_HANDLE DeviceHandle,
275 ACPI_BUFFER *RetBuffer)
278 ACPI_NAMESPACE_NODE *Node;
281 ACPI_FUNCTION_TRACE (AcpiGetPossibleResources);
284 /* Validate parameters then dispatch to internal routine */
286 Status = AcpiRsValidateParameters (DeviceHandle, RetBuffer, &Node);
287 if (ACPI_FAILURE (Status))
289 return_ACPI_STATUS (Status);
292 Status = AcpiRsGetPrsMethodData (Node, RetBuffer);
293 return_ACPI_STATUS (Status);
296 ACPI_EXPORT_SYMBOL (AcpiGetPossibleResources)
299 /*******************************************************************************
301 * FUNCTION: AcpiSetCurrentResources
303 * PARAMETERS: DeviceHandle - Handle to the device object for the
304 * device we are setting resources
305 * InBuffer - Pointer to a buffer containing the
306 * resources to be set for the device
310 * DESCRIPTION: This function is called to set the current resources for a
311 * specific device. The caller must first acquire a handle for
312 * the desired device. The resource data is passed to the routine
313 * the buffer pointed to by the InBuffer variable.
315 ******************************************************************************/
318 AcpiSetCurrentResources (
319 ACPI_HANDLE DeviceHandle,
320 ACPI_BUFFER *InBuffer)
323 ACPI_NAMESPACE_NODE *Node;
326 ACPI_FUNCTION_TRACE (AcpiSetCurrentResources);
329 /* Validate the buffer, don't allow zero length */
332 (!InBuffer->Pointer) ||
335 return_ACPI_STATUS (AE_BAD_PARAMETER);
338 /* Validate parameters then dispatch to internal routine */
340 Status = AcpiRsValidateParameters (DeviceHandle, InBuffer, &Node);
341 if (ACPI_FAILURE (Status))
343 return_ACPI_STATUS (Status);
346 Status = AcpiRsSetSrsMethodData (Node, InBuffer);
347 return_ACPI_STATUS (Status);
350 ACPI_EXPORT_SYMBOL (AcpiSetCurrentResources)
353 /*******************************************************************************
355 * FUNCTION: AcpiGetEventResources
357 * PARAMETERS: DeviceHandle - Handle to the device object for the
358 * device we are getting resources
359 * InBuffer - Pointer to a buffer containing the
360 * resources to be set for the device
364 * DESCRIPTION: This function is called to get the event resources for a
365 * specific device. The caller must first acquire a handle for
366 * the desired device. The resource data is passed to the routine
367 * the buffer pointed to by the InBuffer variable. Uses the
370 ******************************************************************************/
373 AcpiGetEventResources (
374 ACPI_HANDLE DeviceHandle,
375 ACPI_BUFFER *RetBuffer)
378 ACPI_NAMESPACE_NODE *Node;
381 ACPI_FUNCTION_TRACE (AcpiGetEventResources);
384 /* Validate parameters then dispatch to internal routine */
386 Status = AcpiRsValidateParameters (DeviceHandle, RetBuffer, &Node);
387 if (ACPI_FAILURE (Status))
389 return_ACPI_STATUS (Status);
392 Status = AcpiRsGetAeiMethodData (Node, RetBuffer);
393 return_ACPI_STATUS (Status);
396 ACPI_EXPORT_SYMBOL (AcpiGetEventResources)
399 /******************************************************************************
401 * FUNCTION: AcpiResourceToAddress64
403 * PARAMETERS: Resource - Pointer to a resource
404 * Out - Pointer to the users's return buffer
405 * (a struct acpi_resource_address64)
409 * DESCRIPTION: If the resource is an address16, address32, or address64,
410 * copy it to the address64 return buffer. This saves the
411 * caller from having to duplicate code for different-sized
414 ******************************************************************************/
417 AcpiResourceToAddress64 (
418 ACPI_RESOURCE *Resource,
419 ACPI_RESOURCE_ADDRESS64 *Out)
421 ACPI_RESOURCE_ADDRESS16 *Address16;
422 ACPI_RESOURCE_ADDRESS32 *Address32;
425 if (!Resource || !Out)
427 return (AE_BAD_PARAMETER);
430 /* Convert 16 or 32 address descriptor to 64 */
432 switch (Resource->Type)
434 case ACPI_RESOURCE_TYPE_ADDRESS16:
436 Address16 = ACPI_CAST_PTR (ACPI_RESOURCE_ADDRESS16, &Resource->Data);
437 ACPI_COPY_ADDRESS (Out, Address16);
440 case ACPI_RESOURCE_TYPE_ADDRESS32:
442 Address32 = ACPI_CAST_PTR (ACPI_RESOURCE_ADDRESS32, &Resource->Data);
443 ACPI_COPY_ADDRESS (Out, Address32);
446 case ACPI_RESOURCE_TYPE_ADDRESS64:
448 /* Simple copy for 64 bit source */
450 memcpy (Out, &Resource->Data, sizeof (ACPI_RESOURCE_ADDRESS64));
455 return (AE_BAD_PARAMETER);
461 ACPI_EXPORT_SYMBOL (AcpiResourceToAddress64)
464 /*******************************************************************************
466 * FUNCTION: AcpiGetVendorResource
468 * PARAMETERS: DeviceHandle - Handle for the parent device object
469 * Name - Method name for the parent resource
470 * (METHOD_NAME__CRS or METHOD_NAME__PRS)
471 * Uuid - Pointer to the UUID to be matched.
472 * includes both subtype and 16-byte UUID
473 * RetBuffer - Where the vendor resource is returned
477 * DESCRIPTION: Walk a resource template for the specified device to find a
478 * vendor-defined resource that matches the supplied UUID and
479 * UUID subtype. Returns a ACPI_RESOURCE of type Vendor.
481 ******************************************************************************/
484 AcpiGetVendorResource (
485 ACPI_HANDLE DeviceHandle,
487 ACPI_VENDOR_UUID *Uuid,
488 ACPI_BUFFER *RetBuffer)
490 ACPI_VENDOR_WALK_INFO Info;
494 /* Other parameters are validated by AcpiWalkResources */
496 if (!Uuid || !RetBuffer)
498 return (AE_BAD_PARAMETER);
502 Info.Buffer = RetBuffer;
503 Info.Status = AE_NOT_EXIST;
505 /* Walk the _CRS or _PRS resource list for this device */
507 Status = AcpiWalkResources (DeviceHandle, Name, AcpiRsMatchVendorResource,
509 if (ACPI_FAILURE (Status))
514 return (Info.Status);
517 ACPI_EXPORT_SYMBOL (AcpiGetVendorResource)
520 /*******************************************************************************
522 * FUNCTION: AcpiRsMatchVendorResource
524 * PARAMETERS: ACPI_WALK_RESOURCE_CALLBACK
528 * DESCRIPTION: Match a vendor resource via the ACPI 3.0 UUID
530 ******************************************************************************/
533 AcpiRsMatchVendorResource (
534 ACPI_RESOURCE *Resource,
537 ACPI_VENDOR_WALK_INFO *Info = Context;
538 ACPI_RESOURCE_VENDOR_TYPED *Vendor;
543 /* Ignore all descriptors except Vendor */
545 if (Resource->Type != ACPI_RESOURCE_TYPE_VENDOR)
550 Vendor = &Resource->Data.VendorTyped;
553 * For a valid match, these conditions must hold:
555 * 1) Length of descriptor data must be at least as long as a UUID struct
556 * 2) The UUID subtypes must match
557 * 3) The UUID data must match
559 if ((Vendor->ByteLength < (ACPI_UUID_LENGTH + 1)) ||
560 (Vendor->UuidSubtype != Info->Uuid->Subtype) ||
561 (memcmp (Vendor->Uuid, Info->Uuid->Data, ACPI_UUID_LENGTH)))
566 /* Validate/Allocate/Clear caller buffer */
568 Buffer = Info->Buffer;
569 Status = AcpiUtInitializeBuffer (Buffer, Resource->Length);
570 if (ACPI_FAILURE (Status))
575 /* Found the correct resource, copy and return it */
577 memcpy (Buffer->Pointer, Resource, Resource->Length);
578 Buffer->Length = Resource->Length;
580 /* Found the desired descriptor, terminate resource walk */
582 Info->Status = AE_OK;
583 return (AE_CTRL_TERMINATE);
587 /*******************************************************************************
589 * FUNCTION: AcpiWalkResourceBuffer
591 * PARAMETERS: Buffer - Formatted buffer returned by one of the
592 * various Get*Resource functions
593 * UserFunction - Called for each resource
594 * Context - Passed to UserFunction
598 * DESCRIPTION: Walks the input resource template. The UserFunction is called
599 * once for each resource in the list.
601 ******************************************************************************/
604 AcpiWalkResourceBuffer (
606 ACPI_WALK_RESOURCE_CALLBACK UserFunction,
609 ACPI_STATUS Status = AE_OK;
610 ACPI_RESOURCE *Resource;
611 ACPI_RESOURCE *ResourceEnd;
614 ACPI_FUNCTION_TRACE (AcpiWalkResourceBuffer);
617 /* Parameter validation */
619 if (!Buffer || !Buffer->Pointer || !UserFunction)
621 return_ACPI_STATUS (AE_BAD_PARAMETER);
624 /* Buffer contains the resource list and length */
626 Resource = ACPI_CAST_PTR (ACPI_RESOURCE, Buffer->Pointer);
627 ResourceEnd = ACPI_ADD_PTR (ACPI_RESOURCE, Buffer->Pointer, Buffer->Length);
629 /* Walk the resource list until the EndTag is found (or buffer end) */
631 while (Resource < ResourceEnd)
633 /* Sanity check the resource type */
635 if (Resource->Type > ACPI_RESOURCE_TYPE_MAX)
637 Status = AE_AML_INVALID_RESOURCE_TYPE;
641 /* Sanity check the length. It must not be zero, or we loop forever */
643 if (!Resource->Length)
645 return_ACPI_STATUS (AE_AML_BAD_RESOURCE_LENGTH);
648 /* Invoke the user function, abort on any error returned */
650 Status = UserFunction (Resource, Context);
651 if (ACPI_FAILURE (Status))
653 if (Status == AE_CTRL_TERMINATE)
655 /* This is an OK termination by the user function */
662 /* EndTag indicates end-of-list */
664 if (Resource->Type == ACPI_RESOURCE_TYPE_END_TAG)
669 /* Get the next resource descriptor */
671 Resource = ACPI_NEXT_RESOURCE (Resource);
674 return_ACPI_STATUS (Status);
677 ACPI_EXPORT_SYMBOL (AcpiWalkResourceBuffer)
680 /*******************************************************************************
682 * FUNCTION: AcpiWalkResources
684 * PARAMETERS: DeviceHandle - Handle to the device object for the
685 * device we are querying
686 * Name - Method name of the resources we want.
687 * (METHOD_NAME__CRS, METHOD_NAME__PRS, or
689 * UserFunction - Called for each resource
690 * Context - Passed to UserFunction
694 * DESCRIPTION: Retrieves the current or possible resource list for the
695 * specified device. The UserFunction is called once for
696 * each resource in the list.
698 ******************************************************************************/
702 ACPI_HANDLE DeviceHandle,
704 ACPI_WALK_RESOURCE_CALLBACK UserFunction,
711 ACPI_FUNCTION_TRACE (AcpiWalkResources);
714 /* Parameter validation */
716 if (!DeviceHandle || !UserFunction || !Name ||
717 (!ACPI_COMPARE_NAME (Name, METHOD_NAME__CRS) &&
718 !ACPI_COMPARE_NAME (Name, METHOD_NAME__PRS) &&
719 !ACPI_COMPARE_NAME (Name, METHOD_NAME__AEI)))
721 return_ACPI_STATUS (AE_BAD_PARAMETER);
724 /* Get the _CRS/_PRS/_AEI resource list */
726 Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
727 Status = AcpiRsGetMethodData (DeviceHandle, Name, &Buffer);
728 if (ACPI_FAILURE (Status))
730 return_ACPI_STATUS (Status);
733 /* Walk the resource list and cleanup */
735 Status = AcpiWalkResourceBuffer (&Buffer, UserFunction, Context);
736 ACPI_FREE (Buffer.Pointer);
737 return_ACPI_STATUS (Status);
740 ACPI_EXPORT_SYMBOL (AcpiWalkResources)