Fixed compatibility of output.
[AROS.git] / arch / all-pc / acpica / source / components / resources / rslist.c
blob80d6f78d2c71c0a6e0a4e7e9dc34847efbb6fedb
1 /*******************************************************************************
3 * Module Name: rslist - Linked list utilities
5 ******************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2013, Intel Corp.
9 * All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
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.
30 * NO WARRANTY
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 __RSLIST_C__
46 #include "acpi.h"
47 #include "accommon.h"
48 #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
62 * RETURN: Status
64 * DESCRIPTION: Convert an AML resource to an internal representation of the
65 * resource that is aligned and easier to access.
67 ******************************************************************************/
69 ACPI_STATUS
70 AcpiRsConvertAmlToResources (
71 UINT8 *Aml,
72 UINT32 Length,
73 UINT32 Offset,
74 UINT8 ResourceIndex,
75 void **Context)
77 ACPI_RESOURCE **ResourcePtr = ACPI_CAST_INDIRECT_PTR (
78 ACPI_RESOURCE, Context);
79 ACPI_RESOURCE *Resource;
80 AML_RESOURCE *AmlResource;
81 ACPI_RSCONVERT_INFO *ConversionTable;
82 ACPI_STATUS Status;
85 ACPI_FUNCTION_TRACE (RsConvertAmlToResources);
89 * Check that the input buffer and all subsequent pointers into it
90 * are aligned on a native word boundary. Most important on IA64
92 Resource = *ResourcePtr;
93 if (ACPI_IS_MISALIGNED (Resource))
95 ACPI_WARNING ((AE_INFO,
96 "Misaligned resource pointer %p", Resource));
99 /* Get the appropriate conversion info table */
101 AmlResource = ACPI_CAST_PTR (AML_RESOURCE, Aml);
102 if (AcpiUtGetResourceType (Aml) == ACPI_RESOURCE_NAME_SERIAL_BUS)
104 if (AmlResource->CommonSerialBus.Type > AML_RESOURCE_MAX_SERIALBUSTYPE)
106 ConversionTable = NULL;
108 else
110 /* This is an I2C, SPI, or UART SerialBus descriptor */
112 ConversionTable =
113 AcpiGbl_ConvertResourceSerialBusDispatch[
114 AmlResource->CommonSerialBus.Type];
117 else
119 ConversionTable =
120 AcpiGbl_GetResourceDispatch[ResourceIndex];
123 if (!ConversionTable)
125 ACPI_ERROR ((AE_INFO,
126 "Invalid/unsupported resource descriptor: Type 0x%2.2X",
127 ResourceIndex));
128 return_ACPI_STATUS (AE_AML_INVALID_RESOURCE_TYPE);
131 /* Convert the AML byte stream resource to a local resource struct */
133 Status = AcpiRsConvertAmlToResource (
134 Resource, AmlResource, ConversionTable);
135 if (ACPI_FAILURE (Status))
137 ACPI_EXCEPTION ((AE_INFO, Status,
138 "Could not convert AML resource (Type 0x%X)", *Aml));
139 return_ACPI_STATUS (Status);
142 ACPI_DEBUG_PRINT ((ACPI_DB_RESOURCES,
143 "Type %.2X, AmlLength %.2X InternalLength %.2X\n",
144 AcpiUtGetResourceType (Aml), Length,
145 Resource->Length));
147 /* Point to the next structure in the output buffer */
149 *ResourcePtr = ACPI_NEXT_RESOURCE (Resource);
150 return_ACPI_STATUS (AE_OK);
154 /*******************************************************************************
156 * FUNCTION: AcpiRsConvertResourcesToAml
158 * PARAMETERS: Resource - Pointer to the resource linked list
159 * AmlSizeNeeded - Calculated size of the byte stream
160 * needed from calling AcpiRsGetAmlLength()
161 * The size of the OutputBuffer is
162 * guaranteed to be >= AmlSizeNeeded
163 * OutputBuffer - Pointer to the buffer that will
164 * contain the byte stream
166 * RETURN: Status
168 * DESCRIPTION: Takes the resource linked list and parses it, creating a
169 * byte stream of resources in the caller's output buffer
171 ******************************************************************************/
173 ACPI_STATUS
174 AcpiRsConvertResourcesToAml (
175 ACPI_RESOURCE *Resource,
176 ACPI_SIZE AmlSizeNeeded,
177 UINT8 *OutputBuffer)
179 UINT8 *Aml = OutputBuffer;
180 UINT8 *EndAml = OutputBuffer + AmlSizeNeeded;
181 ACPI_RSCONVERT_INFO *ConversionTable;
182 ACPI_STATUS Status;
185 ACPI_FUNCTION_TRACE (RsConvertResourcesToAml);
188 /* Walk the resource descriptor list, convert each descriptor */
190 while (Aml < EndAml)
192 /* Validate the (internal) Resource Type */
194 if (Resource->Type > ACPI_RESOURCE_TYPE_MAX)
196 ACPI_ERROR ((AE_INFO,
197 "Invalid descriptor type (0x%X) in resource list",
198 Resource->Type));
199 return_ACPI_STATUS (AE_BAD_DATA);
202 /* Sanity check the length. It must not be zero, or we loop forever */
204 if (!Resource->Length)
206 ACPI_ERROR ((AE_INFO,
207 "Invalid zero length descriptor in resource list\n"));
208 return_ACPI_STATUS (AE_AML_BAD_RESOURCE_LENGTH);
211 /* Perform the conversion */
213 if (Resource->Type == ACPI_RESOURCE_TYPE_SERIAL_BUS)
215 if (Resource->Data.CommonSerialBus.Type > AML_RESOURCE_MAX_SERIALBUSTYPE)
217 ConversionTable = NULL;
219 else
221 /* This is an I2C, SPI, or UART SerialBus descriptor */
223 ConversionTable = AcpiGbl_ConvertResourceSerialBusDispatch[
224 Resource->Data.CommonSerialBus.Type];
227 else
229 ConversionTable = AcpiGbl_SetResourceDispatch[Resource->Type];
232 if (!ConversionTable)
234 ACPI_ERROR ((AE_INFO,
235 "Invalid/unsupported resource descriptor: Type 0x%2.2X",
236 Resource->Type));
237 return_ACPI_STATUS (AE_AML_INVALID_RESOURCE_TYPE);
240 Status = AcpiRsConvertResourceToAml (Resource,
241 ACPI_CAST_PTR (AML_RESOURCE, Aml),
242 ConversionTable);
243 if (ACPI_FAILURE (Status))
245 ACPI_EXCEPTION ((AE_INFO, Status,
246 "Could not convert resource (type 0x%X) to AML",
247 Resource->Type));
248 return_ACPI_STATUS (Status);
251 /* Perform final sanity check on the new AML resource descriptor */
253 Status = AcpiUtValidateResource (NULL,
254 ACPI_CAST_PTR (AML_RESOURCE, Aml), NULL);
255 if (ACPI_FAILURE (Status))
257 return_ACPI_STATUS (Status);
260 /* Check for end-of-list, normal exit */
262 if (Resource->Type == ACPI_RESOURCE_TYPE_END_TAG)
264 /* An End Tag indicates the end of the input Resource Template */
266 return_ACPI_STATUS (AE_OK);
270 * Extract the total length of the new descriptor and set the
271 * Aml to point to the next (output) resource descriptor
273 Aml += AcpiUtGetDescriptorLength (Aml);
275 /* Point to the next input resource descriptor */
277 Resource = ACPI_NEXT_RESOURCE (Resource);
280 /* Completed buffer, but did not find an EndTag resource descriptor */
282 return_ACPI_STATUS (AE_AML_NO_RESOURCE_END_TAG);