1 /*******************************************************************************
3 * Module Name: rsxface - Public interfaces to the resource manager
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2013, 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.
47 #include <contrib/dev/acpica/include/acpi.h>
48 #include <contrib/dev/acpica/include/accommon.h>
49 #include <contrib/dev/acpica/include/acresrc.h>
50 #include <contrib/dev/acpica/include/acnamesp.h>
52 #define _COMPONENT ACPI_RESOURCES
53 ACPI_MODULE_NAME ("rsxface")
55 /* Local macros for 16,32-bit to 64-bit conversion */
57 #define ACPI_COPY_FIELD(Out, In, Field) ((Out)->Field = (In)->Field)
58 #define ACPI_COPY_ADDRESS(Out, In) \
59 ACPI_COPY_FIELD(Out, In, ResourceType); \
60 ACPI_COPY_FIELD(Out, In, ProducerConsumer); \
61 ACPI_COPY_FIELD(Out, In, Decode); \
62 ACPI_COPY_FIELD(Out, In, MinAddressFixed); \
63 ACPI_COPY_FIELD(Out, In, MaxAddressFixed); \
64 ACPI_COPY_FIELD(Out, In, Info); \
65 ACPI_COPY_FIELD(Out, In, Granularity); \
66 ACPI_COPY_FIELD(Out, In, Minimum); \
67 ACPI_COPY_FIELD(Out, In, Maximum); \
68 ACPI_COPY_FIELD(Out, In, TranslationOffset); \
69 ACPI_COPY_FIELD(Out, In, AddressLength); \
70 ACPI_COPY_FIELD(Out, In, ResourceSource);
73 /* Local prototypes */
76 AcpiRsMatchVendorResource (
77 ACPI_RESOURCE *Resource,
81 AcpiRsValidateParameters (
82 ACPI_HANDLE DeviceHandle,
84 ACPI_NAMESPACE_NODE **ReturnNode);
87 /*******************************************************************************
89 * FUNCTION: AcpiRsValidateParameters
91 * PARAMETERS: DeviceHandle - Handle to a device
92 * Buffer - Pointer to a data buffer
93 * ReturnNode - Pointer to where the device node is returned
97 * DESCRIPTION: Common parameter validation for resource interfaces
99 ******************************************************************************/
102 AcpiRsValidateParameters (
103 ACPI_HANDLE DeviceHandle,
105 ACPI_NAMESPACE_NODE **ReturnNode)
108 ACPI_NAMESPACE_NODE *Node;
111 ACPI_FUNCTION_TRACE (RsValidateParameters);
115 * Must have a valid handle to an ACPI device
119 return_ACPI_STATUS (AE_BAD_PARAMETER);
122 Node = AcpiNsValidateHandle (DeviceHandle);
125 return_ACPI_STATUS (AE_BAD_PARAMETER);
128 if (Node->Type != ACPI_TYPE_DEVICE)
130 return_ACPI_STATUS (AE_TYPE);
134 * Validate the user buffer object
136 * if there is a non-zero buffer length we also need a valid pointer in
137 * the buffer. If it's a zero buffer length, we'll be returning the
138 * needed buffer size (later), so keep going.
140 Status = AcpiUtValidateBuffer (Buffer);
141 if (ACPI_FAILURE (Status))
143 return_ACPI_STATUS (Status);
147 return_ACPI_STATUS (AE_OK);
151 /*******************************************************************************
153 * FUNCTION: AcpiGetIrqRoutingTable
155 * PARAMETERS: DeviceHandle - Handle to the Bus device we are querying
156 * RetBuffer - Pointer to a buffer to receive the
157 * current resources for the device
161 * DESCRIPTION: This function is called to get the IRQ routing table for a
162 * specific bus. The caller must first acquire a handle for the
163 * desired bus. The routine table is placed in the buffer pointed
164 * to by the RetBuffer variable parameter.
166 * If the function fails an appropriate status will be returned
167 * and the value of RetBuffer is undefined.
169 * This function attempts to execute the _PRT method contained in
170 * the object indicated by the passed DeviceHandle.
172 ******************************************************************************/
175 AcpiGetIrqRoutingTable (
176 ACPI_HANDLE DeviceHandle,
177 ACPI_BUFFER *RetBuffer)
180 ACPI_NAMESPACE_NODE *Node;
183 ACPI_FUNCTION_TRACE (AcpiGetIrqRoutingTable);
186 /* Validate parameters then dispatch to internal routine */
188 Status = AcpiRsValidateParameters (DeviceHandle, RetBuffer, &Node);
189 if (ACPI_FAILURE (Status))
191 return_ACPI_STATUS (Status);
194 Status = AcpiRsGetPrtMethodData (Node, RetBuffer);
195 return_ACPI_STATUS (Status);
198 ACPI_EXPORT_SYMBOL (AcpiGetIrqRoutingTable)
201 /*******************************************************************************
203 * FUNCTION: AcpiGetCurrentResources
205 * PARAMETERS: DeviceHandle - Handle to the device object for the
206 * device we are querying
207 * RetBuffer - Pointer to a buffer to receive the
208 * current resources for the device
212 * DESCRIPTION: This function is called to get the current resources for a
213 * specific device. The caller must first acquire a handle for
214 * the desired device. The resource data is placed in the buffer
215 * pointed to by the RetBuffer variable parameter.
217 * If the function fails an appropriate status will be returned
218 * and the value of RetBuffer is undefined.
220 * This function attempts to execute the _CRS method contained in
221 * the object indicated by the passed DeviceHandle.
223 ******************************************************************************/
226 AcpiGetCurrentResources (
227 ACPI_HANDLE DeviceHandle,
228 ACPI_BUFFER *RetBuffer)
231 ACPI_NAMESPACE_NODE *Node;
234 ACPI_FUNCTION_TRACE (AcpiGetCurrentResources);
237 /* Validate parameters then dispatch to internal routine */
239 Status = AcpiRsValidateParameters (DeviceHandle, RetBuffer, &Node);
240 if (ACPI_FAILURE (Status))
242 return_ACPI_STATUS (Status);
245 Status = AcpiRsGetCrsMethodData (Node, RetBuffer);
246 return_ACPI_STATUS (Status);
249 ACPI_EXPORT_SYMBOL (AcpiGetCurrentResources)
252 /*******************************************************************************
254 * FUNCTION: AcpiGetPossibleResources
256 * PARAMETERS: DeviceHandle - Handle to the device object for the
257 * device we are querying
258 * RetBuffer - Pointer to a buffer to receive the
259 * resources for the device
263 * DESCRIPTION: This function is called to get a list of the possible resources
264 * for a specific device. The caller must first acquire a handle
265 * for the desired device. The resource data is placed in the
266 * buffer pointed to by the RetBuffer variable.
268 * If the function fails an appropriate status will be returned
269 * and the value of RetBuffer is undefined.
271 ******************************************************************************/
274 AcpiGetPossibleResources (
275 ACPI_HANDLE DeviceHandle,
276 ACPI_BUFFER *RetBuffer)
279 ACPI_NAMESPACE_NODE *Node;
282 ACPI_FUNCTION_TRACE (AcpiGetPossibleResources);
285 /* Validate parameters then dispatch to internal routine */
287 Status = AcpiRsValidateParameters (DeviceHandle, RetBuffer, &Node);
288 if (ACPI_FAILURE (Status))
290 return_ACPI_STATUS (Status);
293 Status = AcpiRsGetPrsMethodData (Node, RetBuffer);
294 return_ACPI_STATUS (Status);
297 ACPI_EXPORT_SYMBOL (AcpiGetPossibleResources)
300 /*******************************************************************************
302 * FUNCTION: AcpiSetCurrentResources
304 * PARAMETERS: DeviceHandle - Handle to the device object for the
305 * device we are setting resources
306 * InBuffer - Pointer to a buffer containing the
307 * resources to be set for the device
311 * DESCRIPTION: This function is called to set the current resources for a
312 * specific device. The caller must first acquire a handle for
313 * the desired device. The resource data is passed to the routine
314 * the buffer pointed to by the InBuffer variable.
316 ******************************************************************************/
319 AcpiSetCurrentResources (
320 ACPI_HANDLE DeviceHandle,
321 ACPI_BUFFER *InBuffer)
324 ACPI_NAMESPACE_NODE *Node;
327 ACPI_FUNCTION_TRACE (AcpiSetCurrentResources);
330 /* Validate the buffer, don't allow zero length */
333 (!InBuffer->Pointer) ||
336 return_ACPI_STATUS (AE_BAD_PARAMETER);
339 /* Validate parameters then dispatch to internal routine */
341 Status = AcpiRsValidateParameters (DeviceHandle, InBuffer, &Node);
342 if (ACPI_FAILURE (Status))
344 return_ACPI_STATUS (Status);
347 Status = AcpiRsSetSrsMethodData (Node, InBuffer);
348 return_ACPI_STATUS (Status);
351 ACPI_EXPORT_SYMBOL (AcpiSetCurrentResources)
354 /*******************************************************************************
356 * FUNCTION: AcpiGetEventResources
358 * PARAMETERS: DeviceHandle - Handle to the device object for the
359 * device we are getting resources
360 * InBuffer - Pointer to a buffer containing the
361 * resources to be set for the device
365 * DESCRIPTION: This function is called to get the event resources for a
366 * specific device. The caller must first acquire a handle for
367 * the desired device. The resource data is passed to the routine
368 * the buffer pointed to by the InBuffer variable. Uses the
371 ******************************************************************************/
374 AcpiGetEventResources (
375 ACPI_HANDLE DeviceHandle,
376 ACPI_BUFFER *RetBuffer)
379 ACPI_NAMESPACE_NODE *Node;
382 ACPI_FUNCTION_TRACE (AcpiGetEventResources);
385 /* Validate parameters then dispatch to internal routine */
387 Status = AcpiRsValidateParameters (DeviceHandle, RetBuffer, &Node);
388 if (ACPI_FAILURE (Status))
390 return_ACPI_STATUS (Status);
393 Status = AcpiRsGetAeiMethodData (Node, RetBuffer);
394 return_ACPI_STATUS (Status);
397 ACPI_EXPORT_SYMBOL (AcpiGetEventResources)
400 /******************************************************************************
402 * FUNCTION: AcpiResourceToAddress64
404 * PARAMETERS: Resource - Pointer to a resource
405 * Out - Pointer to the users's return buffer
406 * (a struct acpi_resource_address64)
410 * DESCRIPTION: If the resource is an address16, address32, or address64,
411 * copy it to the address64 return buffer. This saves the
412 * caller from having to duplicate code for different-sized
415 ******************************************************************************/
418 AcpiResourceToAddress64 (
419 ACPI_RESOURCE *Resource,
420 ACPI_RESOURCE_ADDRESS64 *Out)
422 ACPI_RESOURCE_ADDRESS16 *Address16;
423 ACPI_RESOURCE_ADDRESS32 *Address32;
426 if (!Resource || !Out)
428 return (AE_BAD_PARAMETER);
431 /* Convert 16 or 32 address descriptor to 64 */
433 switch (Resource->Type)
435 case ACPI_RESOURCE_TYPE_ADDRESS16:
437 Address16 = ACPI_CAST_PTR (ACPI_RESOURCE_ADDRESS16, &Resource->Data);
438 ACPI_COPY_ADDRESS (Out, Address16);
441 case ACPI_RESOURCE_TYPE_ADDRESS32:
443 Address32 = ACPI_CAST_PTR (ACPI_RESOURCE_ADDRESS32, &Resource->Data);
444 ACPI_COPY_ADDRESS (Out, Address32);
447 case ACPI_RESOURCE_TYPE_ADDRESS64:
449 /* Simple copy for 64 bit source */
451 ACPI_MEMCPY (Out, &Resource->Data, sizeof (ACPI_RESOURCE_ADDRESS64));
456 return (AE_BAD_PARAMETER);
462 ACPI_EXPORT_SYMBOL (AcpiResourceToAddress64)
465 /*******************************************************************************
467 * FUNCTION: AcpiGetVendorResource
469 * PARAMETERS: DeviceHandle - Handle for the parent device object
470 * Name - Method name for the parent resource
471 * (METHOD_NAME__CRS or METHOD_NAME__PRS)
472 * Uuid - Pointer to the UUID to be matched.
473 * includes both subtype and 16-byte UUID
474 * RetBuffer - Where the vendor resource is returned
478 * DESCRIPTION: Walk a resource template for the specified device to find a
479 * vendor-defined resource that matches the supplied UUID and
480 * UUID subtype. Returns a ACPI_RESOURCE of type Vendor.
482 ******************************************************************************/
485 AcpiGetVendorResource (
486 ACPI_HANDLE DeviceHandle,
488 ACPI_VENDOR_UUID *Uuid,
489 ACPI_BUFFER *RetBuffer)
491 ACPI_VENDOR_WALK_INFO Info;
495 /* Other parameters are validated by AcpiWalkResources */
497 if (!Uuid || !RetBuffer)
499 return (AE_BAD_PARAMETER);
503 Info.Buffer = RetBuffer;
504 Info.Status = AE_NOT_EXIST;
506 /* Walk the _CRS or _PRS resource list for this device */
508 Status = AcpiWalkResources (DeviceHandle, Name, AcpiRsMatchVendorResource,
510 if (ACPI_FAILURE (Status))
515 return (Info.Status);
518 ACPI_EXPORT_SYMBOL (AcpiGetVendorResource)
521 /*******************************************************************************
523 * FUNCTION: AcpiRsMatchVendorResource
525 * PARAMETERS: ACPI_WALK_RESOURCE_CALLBACK
529 * DESCRIPTION: Match a vendor resource via the ACPI 3.0 UUID
531 ******************************************************************************/
534 AcpiRsMatchVendorResource (
535 ACPI_RESOURCE *Resource,
538 ACPI_VENDOR_WALK_INFO *Info = Context;
539 ACPI_RESOURCE_VENDOR_TYPED *Vendor;
544 /* Ignore all descriptors except Vendor */
546 if (Resource->Type != ACPI_RESOURCE_TYPE_VENDOR)
551 Vendor = &Resource->Data.VendorTyped;
554 * For a valid match, these conditions must hold:
556 * 1) Length of descriptor data must be at least as long as a UUID struct
557 * 2) The UUID subtypes must match
558 * 3) The UUID data must match
560 if ((Vendor->ByteLength < (ACPI_UUID_LENGTH + 1)) ||
561 (Vendor->UuidSubtype != Info->Uuid->Subtype) ||
562 (ACPI_MEMCMP (Vendor->Uuid, Info->Uuid->Data, ACPI_UUID_LENGTH)))
567 /* Validate/Allocate/Clear caller buffer */
569 Buffer = Info->Buffer;
570 Status = AcpiUtInitializeBuffer (Buffer, Resource->Length);
571 if (ACPI_FAILURE (Status))
576 /* Found the correct resource, copy and return it */
578 ACPI_MEMCPY (Buffer->Pointer, Resource, Resource->Length);
579 Buffer->Length = Resource->Length;
581 /* Found the desired descriptor, terminate resource walk */
583 Info->Status = AE_OK;
584 return (AE_CTRL_TERMINATE);
588 /*******************************************************************************
590 * FUNCTION: AcpiWalkResourceBuffer
592 * PARAMETERS: Buffer - Formatted buffer returned by one of the
593 * various Get*Resource functions
594 * UserFunction - Called for each resource
595 * Context - Passed to UserFunction
599 * DESCRIPTION: Walks the input resource template. The UserFunction is called
600 * once for each resource in the list.
602 ******************************************************************************/
605 AcpiWalkResourceBuffer (
607 ACPI_WALK_RESOURCE_CALLBACK UserFunction,
610 ACPI_STATUS Status = AE_OK;
611 ACPI_RESOURCE *Resource;
612 ACPI_RESOURCE *ResourceEnd;
615 ACPI_FUNCTION_TRACE (AcpiWalkResourceBuffer);
618 /* Parameter validation */
620 if (!Buffer || !Buffer->Pointer || !UserFunction)
622 return_ACPI_STATUS (AE_BAD_PARAMETER);
625 /* Buffer contains the resource list and length */
627 Resource = ACPI_CAST_PTR (ACPI_RESOURCE, Buffer->Pointer);
628 ResourceEnd = ACPI_ADD_PTR (ACPI_RESOURCE, Buffer->Pointer, Buffer->Length);
630 /* Walk the resource list until the EndTag is found (or buffer end) */
632 while (Resource < ResourceEnd)
634 /* Sanity check the resource type */
636 if (Resource->Type > ACPI_RESOURCE_TYPE_MAX)
638 Status = AE_AML_INVALID_RESOURCE_TYPE;
642 /* Sanity check the length. It must not be zero, or we loop forever */
644 if (!Resource->Length)
646 return_ACPI_STATUS (AE_AML_BAD_RESOURCE_LENGTH);
649 /* Invoke the user function, abort on any error returned */
651 Status = UserFunction (Resource, Context);
652 if (ACPI_FAILURE (Status))
654 if (Status == AE_CTRL_TERMINATE)
656 /* This is an OK termination by the user function */
663 /* EndTag indicates end-of-list */
665 if (Resource->Type == ACPI_RESOURCE_TYPE_END_TAG)
670 /* Get the next resource descriptor */
672 Resource = ACPI_NEXT_RESOURCE (Resource);
675 return_ACPI_STATUS (Status);
678 ACPI_EXPORT_SYMBOL (AcpiWalkResourceBuffer)
681 /*******************************************************************************
683 * FUNCTION: AcpiWalkResources
685 * PARAMETERS: DeviceHandle - Handle to the device object for the
686 * device we are querying
687 * Name - Method name of the resources we want.
688 * (METHOD_NAME__CRS, METHOD_NAME__PRS, or
690 * UserFunction - Called for each resource
691 * Context - Passed to UserFunction
695 * DESCRIPTION: Retrieves the current or possible resource list for the
696 * specified device. The UserFunction is called once for
697 * each resource in the list.
699 ******************************************************************************/
703 ACPI_HANDLE DeviceHandle,
705 ACPI_WALK_RESOURCE_CALLBACK UserFunction,
712 ACPI_FUNCTION_TRACE (AcpiWalkResources);
715 /* Parameter validation */
717 if (!DeviceHandle || !UserFunction || !Name ||
718 (!ACPI_COMPARE_NAME (Name, METHOD_NAME__CRS) &&
719 !ACPI_COMPARE_NAME (Name, METHOD_NAME__PRS) &&
720 !ACPI_COMPARE_NAME (Name, METHOD_NAME__AEI)))
722 return_ACPI_STATUS (AE_BAD_PARAMETER);
725 /* Get the _CRS/_PRS/_AEI resource list */
727 Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
728 Status = AcpiRsGetMethodData (DeviceHandle, Name, &Buffer);
729 if (ACPI_FAILURE (Status))
731 return_ACPI_STATUS (Status);
734 /* Walk the resource list and cleanup */
736 Status = AcpiWalkResourceBuffer (&Buffer, UserFunction, Context);
737 ACPI_FREE (Buffer.Pointer);
738 return_ACPI_STATUS (Status);
741 ACPI_EXPORT_SYMBOL (AcpiWalkResources)