1 /*******************************************************************************
3 * Module Name: rslist - Linked list utilities
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 #include <contrib/dev/acpica/include/acpi.h>
45 #include <contrib/dev/acpica/include/accommon.h>
46 #include <contrib/dev/acpica/include/acresrc.h>
48 #define _COMPONENT ACPI_RESOURCES
49 ACPI_MODULE_NAME ("rslist")
52 /*******************************************************************************
54 * FUNCTION: AcpiRsConvertAmlToResources
56 * PARAMETERS: ACPI_WALK_AML_CALLBACK
57 * ResourcePtr - Pointer to the buffer that will
58 * contain the output structures
62 * DESCRIPTION: Convert an AML resource to an internal representation of the
63 * resource that is aligned and easier to access.
65 ******************************************************************************/
68 AcpiRsConvertAmlToResources (
75 ACPI_RESOURCE **ResourcePtr = ACPI_CAST_INDIRECT_PTR (
76 ACPI_RESOURCE, Context);
77 ACPI_RESOURCE *Resource;
78 AML_RESOURCE *AmlResource;
79 ACPI_RSCONVERT_INFO *ConversionTable;
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 /* Get the appropriate conversion info table */
99 AmlResource = ACPI_CAST_PTR (AML_RESOURCE, Aml);
100 if (AcpiUtGetResourceType (Aml) == ACPI_RESOURCE_NAME_SERIAL_BUS)
102 if (AmlResource->CommonSerialBus.Type > AML_RESOURCE_MAX_SERIALBUSTYPE)
104 ConversionTable = NULL;
108 /* This is an I2C, SPI, or UART SerialBus descriptor */
111 AcpiGbl_ConvertResourceSerialBusDispatch[
112 AmlResource->CommonSerialBus.Type];
118 AcpiGbl_GetResourceDispatch[ResourceIndex];
121 if (!ConversionTable)
123 ACPI_ERROR ((AE_INFO,
124 "Invalid/unsupported resource descriptor: Type 0x%2.2X",
126 return_ACPI_STATUS (AE_AML_INVALID_RESOURCE_TYPE);
129 /* Convert the AML byte stream resource to a local resource struct */
131 Status = AcpiRsConvertAmlToResource (
132 Resource, AmlResource, ConversionTable);
133 if (ACPI_FAILURE (Status))
135 ACPI_EXCEPTION ((AE_INFO, Status,
136 "Could not convert AML resource (Type 0x%X)", *Aml));
137 return_ACPI_STATUS (Status);
140 ACPI_DEBUG_PRINT ((ACPI_DB_RESOURCES,
141 "Type %.2X, AmlLength %.2X InternalLength %.2X\n",
142 AcpiUtGetResourceType (Aml), Length,
145 /* Point to the next structure in the output buffer */
147 *ResourcePtr = ACPI_NEXT_RESOURCE (Resource);
148 return_ACPI_STATUS (AE_OK);
152 /*******************************************************************************
154 * FUNCTION: AcpiRsConvertResourcesToAml
156 * PARAMETERS: Resource - Pointer to the resource linked list
157 * AmlSizeNeeded - Calculated size of the byte stream
158 * needed from calling AcpiRsGetAmlLength()
159 * The size of the OutputBuffer is
160 * guaranteed to be >= AmlSizeNeeded
161 * OutputBuffer - Pointer to the buffer that will
162 * contain the byte stream
166 * DESCRIPTION: Takes the resource linked list and parses it, creating a
167 * byte stream of resources in the caller's output buffer
169 ******************************************************************************/
172 AcpiRsConvertResourcesToAml (
173 ACPI_RESOURCE *Resource,
174 ACPI_SIZE AmlSizeNeeded,
177 UINT8 *Aml = OutputBuffer;
178 UINT8 *EndAml = OutputBuffer + AmlSizeNeeded;
179 ACPI_RSCONVERT_INFO *ConversionTable;
183 ACPI_FUNCTION_TRACE (RsConvertResourcesToAml);
186 /* Walk the resource descriptor list, convert each descriptor */
190 /* Validate the (internal) Resource Type */
192 if (Resource->Type > ACPI_RESOURCE_TYPE_MAX)
194 ACPI_ERROR ((AE_INFO,
195 "Invalid descriptor type (0x%X) in resource list",
197 return_ACPI_STATUS (AE_BAD_DATA);
200 /* Sanity check the length. It must not be zero, or we loop forever */
202 if (!Resource->Length)
204 ACPI_ERROR ((AE_INFO,
205 "Invalid zero length descriptor in resource list\n"));
206 return_ACPI_STATUS (AE_AML_BAD_RESOURCE_LENGTH);
209 /* Perform the conversion */
211 if (Resource->Type == ACPI_RESOURCE_TYPE_SERIAL_BUS)
213 if (Resource->Data.CommonSerialBus.Type > AML_RESOURCE_MAX_SERIALBUSTYPE)
215 ConversionTable = NULL;
219 /* This is an I2C, SPI, or UART SerialBus descriptor */
221 ConversionTable = AcpiGbl_ConvertResourceSerialBusDispatch[
222 Resource->Data.CommonSerialBus.Type];
227 ConversionTable = AcpiGbl_SetResourceDispatch[Resource->Type];
230 if (!ConversionTable)
232 ACPI_ERROR ((AE_INFO,
233 "Invalid/unsupported resource descriptor: Type 0x%2.2X",
235 return_ACPI_STATUS (AE_AML_INVALID_RESOURCE_TYPE);
238 Status = AcpiRsConvertResourceToAml (Resource,
239 ACPI_CAST_PTR (AML_RESOURCE, Aml),
241 if (ACPI_FAILURE (Status))
243 ACPI_EXCEPTION ((AE_INFO, Status,
244 "Could not convert resource (type 0x%X) to AML",
246 return_ACPI_STATUS (Status);
249 /* Perform final sanity check on the new AML resource descriptor */
251 Status = AcpiUtValidateResource (NULL,
252 ACPI_CAST_PTR (AML_RESOURCE, Aml), NULL);
253 if (ACPI_FAILURE (Status))
255 return_ACPI_STATUS (Status);
258 /* Check for end-of-list, normal exit */
260 if (Resource->Type == ACPI_RESOURCE_TYPE_END_TAG)
262 /* An End Tag indicates the end of the input Resource Template */
264 return_ACPI_STATUS (AE_OK);
268 * Extract the total length of the new descriptor and set the
269 * Aml to point to the next (output) resource descriptor
271 Aml += AcpiUtGetDescriptorLength (Aml);
273 /* Point to the next input resource descriptor */
275 Resource = ACPI_NEXT_RESOURCE (Resource);
278 /* Completed buffer, but did not find an EndTag resource descriptor */
280 return_ACPI_STATUS (AE_AML_NO_RESOURCE_END_TAG);