1 /*******************************************************************************
3 * Module Name: rslist - Linked list utilities
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2011, 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.
46 #include <contrib/dev/acpica/include/acpi.h>
47 #include <contrib/dev/acpica/include/accommon.h>
48 #include <contrib/dev/acpica/include/acresrc.h>
50 #define _COMPONENT ACPI_RESOURCES
51 ACPI_MODULE_NAME ("rslist")
54 /*******************************************************************************
56 * FUNCTION: AcpiRsConvertAmlToResources
58 * PARAMETERS: ACPI_WALK_AML_CALLBACK
59 * ResourcePtr - Pointer to the buffer that will
60 * contain the output structures
64 * DESCRIPTION: Convert an AML resource to an internal representation of the
65 * resource that is aligned and easier to access.
67 ******************************************************************************/
70 AcpiRsConvertAmlToResources (
77 ACPI_RESOURCE **ResourcePtr = ACPI_CAST_INDIRECT_PTR (
78 ACPI_RESOURCE, Context);
79 ACPI_RESOURCE *Resource;
83 ACPI_FUNCTION_TRACE (RsConvertAmlToResources);
87 * Check that the input buffer and all subsequent pointers into it
88 * are aligned on a native word boundary. Most important on IA64
90 Resource = *ResourcePtr;
91 if (ACPI_IS_MISALIGNED (Resource))
93 ACPI_WARNING ((AE_INFO,
94 "Misaligned resource pointer %p", Resource));
97 /* Convert the AML byte stream resource to a local resource struct */
99 Status = AcpiRsConvertAmlToResource (
100 Resource, ACPI_CAST_PTR (AML_RESOURCE, Aml),
101 AcpiGbl_GetResourceDispatch[ResourceIndex]);
102 if (ACPI_FAILURE (Status))
104 ACPI_EXCEPTION ((AE_INFO, Status,
105 "Could not convert AML resource (Type 0x%X)", *Aml));
106 return_ACPI_STATUS (Status);
109 ACPI_DEBUG_PRINT ((ACPI_DB_RESOURCES,
110 "Type %.2X, AmlLength %.2X InternalLength %.2X\n",
111 AcpiUtGetResourceType (Aml), Length,
114 /* Point to the next structure in the output buffer */
116 *ResourcePtr = ACPI_ADD_PTR (void, Resource, Resource->Length);
117 return_ACPI_STATUS (AE_OK);
121 /*******************************************************************************
123 * FUNCTION: AcpiRsConvertResourcesToAml
125 * PARAMETERS: Resource - Pointer to the resource linked list
126 * AmlSizeNeeded - Calculated size of the byte stream
127 * needed from calling AcpiRsGetAmlLength()
128 * The size of the OutputBuffer is
129 * guaranteed to be >= AmlSizeNeeded
130 * OutputBuffer - Pointer to the buffer that will
131 * contain the byte stream
135 * DESCRIPTION: Takes the resource linked list and parses it, creating a
136 * byte stream of resources in the caller's output buffer
138 ******************************************************************************/
141 AcpiRsConvertResourcesToAml (
142 ACPI_RESOURCE *Resource,
143 ACPI_SIZE AmlSizeNeeded,
146 UINT8 *Aml = OutputBuffer;
147 UINT8 *EndAml = OutputBuffer + AmlSizeNeeded;
151 ACPI_FUNCTION_TRACE (RsConvertResourcesToAml);
154 /* Walk the resource descriptor list, convert each descriptor */
158 /* Validate the (internal) Resource Type */
160 if (Resource->Type > ACPI_RESOURCE_TYPE_MAX)
162 ACPI_ERROR ((AE_INFO,
163 "Invalid descriptor type (0x%X) in resource list",
165 return_ACPI_STATUS (AE_BAD_DATA);
168 /* Perform the conversion */
170 Status = AcpiRsConvertResourceToAml (Resource,
171 ACPI_CAST_PTR (AML_RESOURCE, Aml),
172 AcpiGbl_SetResourceDispatch[Resource->Type]);
173 if (ACPI_FAILURE (Status))
175 ACPI_EXCEPTION ((AE_INFO, Status,
176 "Could not convert resource (type 0x%X) to AML",
178 return_ACPI_STATUS (Status);
181 /* Perform final sanity check on the new AML resource descriptor */
183 Status = AcpiUtValidateResource (
184 ACPI_CAST_PTR (AML_RESOURCE, Aml), NULL);
185 if (ACPI_FAILURE (Status))
187 return_ACPI_STATUS (Status);
190 /* Check for end-of-list, normal exit */
192 if (Resource->Type == ACPI_RESOURCE_TYPE_END_TAG)
194 /* An End Tag indicates the end of the input Resource Template */
196 return_ACPI_STATUS (AE_OK);
200 * Extract the total length of the new descriptor and set the
201 * Aml to point to the next (output) resource descriptor
203 Aml += AcpiUtGetDescriptorLength (Aml);
205 /* Point to the next input resource descriptor */
207 Resource = ACPI_ADD_PTR (ACPI_RESOURCE, Resource, Resource->Length);
210 /* Completed buffer, but did not find an EndTag resource descriptor */
212 return_ACPI_STATUS (AE_AML_NO_RESOURCE_END_TAG);