ReactOS 0.4.15-dev-7928-g68a8619
rslist.c
Go to the documentation of this file.
1/*******************************************************************************
2 *
3 * Module Name: rslist - Linked list utilities
4 *
5 ******************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2022, Intel Corp.
9 * All rights reserved.
10 *
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.
25 *
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.
29 *
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 MERCHANTABILITY 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.
42 */
43
44#include "acpi.h"
45#include "accommon.h"
46#include "acresrc.h"
47
48#define _COMPONENT ACPI_RESOURCES
49 ACPI_MODULE_NAME ("rslist")
50
51
52/*******************************************************************************
53 *
54 * FUNCTION: AcpiRsConvertAmlToResources
55 *
56 * PARAMETERS: ACPI_WALK_AML_CALLBACK
57 * ResourcePtr - Pointer to the buffer that will
58 * contain the output structures
59 *
60 * RETURN: Status
61 *
62 * DESCRIPTION: Convert an AML resource to an internal representation of the
63 * resource that is aligned and easier to access.
64 *
65 ******************************************************************************/
66
69 UINT8 *Aml,
72 UINT8 ResourceIndex,
73 void **Context)
74{
78 AML_RESOURCE *AmlResource;
79 ACPI_RSCONVERT_INFO *ConversionTable;
81
82
83 ACPI_FUNCTION_TRACE (RsConvertAmlToResources);
84
85
86 /*
87 * Check that the input buffer and all subsequent pointers into it
88 * are aligned on a native word boundary. Most important on IA64
89 */
90 Resource = *ResourcePtr;
92 {
94 "Misaligned resource pointer %p", Resource));
95 }
96
97 /* Get the appropriate conversion info table */
98
99 AmlResource = ACPI_CAST_PTR (AML_RESOURCE, Aml);
100
103 {
104 if (AmlResource->CommonSerialBus.Type >
106 {
107 ConversionTable = NULL;
108 }
109 else
110 {
111 /* This is an I2C, SPI, UART, or CSI2 SerialBus descriptor */
112
114 AmlResource->CommonSerialBus.Type];
115 }
116 }
117 else
118 {
119 ConversionTable = AcpiGbl_GetResourceDispatch[ResourceIndex];
120 }
121
122 if (!ConversionTable)
123 {
125 "Invalid/unsupported resource descriptor: Type 0x%2.2X",
126 ResourceIndex));
128 }
129
130 /* Convert the AML byte stream resource to a local resource struct */
131
133 Resource, AmlResource, ConversionTable);
134 if (ACPI_FAILURE (Status))
135 {
137 "Could not convert AML resource (Type 0x%X)", *Aml));
139 }
140
141 if (!Resource->Length)
142 {
144 "Zero-length resource returned from RsConvertAmlToResource"));
145 }
146
148 "Type %.2X, AmlLength %.2X InternalLength %.2X\n",
150 Resource->Length));
151
152 /* Point to the next structure in the output buffer */
153
154 *ResourcePtr = ACPI_NEXT_RESOURCE (Resource);
156}
157
158
159/*******************************************************************************
160 *
161 * FUNCTION: AcpiRsConvertResourcesToAml
162 *
163 * PARAMETERS: Resource - Pointer to the resource linked list
164 * AmlSizeNeeded - Calculated size of the byte stream
165 * needed from calling AcpiRsGetAmlLength()
166 * The size of the OutputBuffer is
167 * guaranteed to be >= AmlSizeNeeded
168 * OutputBuffer - Pointer to the buffer that will
169 * contain the byte stream
170 *
171 * RETURN: Status
172 *
173 * DESCRIPTION: Takes the resource linked list and parses it, creating a
174 * byte stream of resources in the caller's output buffer
175 *
176 ******************************************************************************/
177
181 ACPI_SIZE AmlSizeNeeded,
183{
185 UINT8 *EndAml = OutputBuffer + AmlSizeNeeded;
186 ACPI_RSCONVERT_INFO *ConversionTable;
188
189
190 ACPI_FUNCTION_TRACE (RsConvertResourcesToAml);
191
192
193 /* Walk the resource descriptor list, convert each descriptor */
194
195 while (Aml < EndAml)
196 {
197 /* Validate the (internal) Resource Type */
198
200 {
202 "Invalid descriptor type (0x%X) in resource list",
203 Resource->Type));
205 }
206
207 /* Sanity check the length. It must not be zero, or we loop forever */
208
209 if (!Resource->Length)
210 {
212 "Invalid zero length descriptor in resource list\n"));
214 }
215
216 /* Perform the conversion */
217
219 {
220 if (Resource->Data.CommonSerialBus.Type >
222 {
223 ConversionTable = NULL;
224 }
225 else
226 {
227 /* This is an I2C, SPI, UART or CSI2 SerialBus descriptor */
228
230 Resource->Data.CommonSerialBus.Type];
231 }
232 }
233 else
234 {
235 ConversionTable = AcpiGbl_SetResourceDispatch[Resource->Type];
236 }
237
238 if (!ConversionTable)
239 {
241 "Invalid/unsupported resource descriptor: Type 0x%2.2X",
242 Resource->Type));
244 }
245
247 ACPI_CAST_PTR (AML_RESOURCE, Aml), ConversionTable);
248 if (ACPI_FAILURE (Status))
249 {
251 "Could not convert resource (type 0x%X) to AML",
252 Resource->Type));
254 }
255
256 /* Perform final sanity check on the new AML resource descriptor */
257
260 if (ACPI_FAILURE (Status))
261 {
263 }
264
265 /* Check for end-of-list, normal exit */
266
268 {
269 /* An End Tag indicates the end of the input Resource Template */
270
272 }
273
274 /*
275 * Extract the total length of the new descriptor and set the
276 * Aml to point to the next (output) resource descriptor
277 */
279
280 /* Point to the next input resource descriptor */
281
283 }
284
285 /* Completed buffer, but did not find an EndTag resource descriptor */
286
288}
unsigned char UINT8
unsigned int UINT32
#define AE_AML_INVALID_RESOURCE_TYPE
Definition: acexcep.h:202
#define AE_BAD_DATA
Definition: acexcep.h:154
#define ACPI_FAILURE(a)
Definition: acexcep.h:95
#define AE_AML_BAD_RESOURCE_LENGTH
Definition: acexcep.h:210
#define AE_AML_NO_RESOURCE_END_TAG
Definition: acexcep.h:207
#define AE_OK
Definition: acexcep.h:97
#define ACPI_RESOURCE_NAME_SERIAL_BUS
Definition: aclocal.h:1342
#define ACPI_IS_MISALIGNED(value)
Definition: acmacros.h:265
#define ACPI_DEBUG_PRINT(pl)
Definition: acoutput.h:475
#define ACPI_EXCEPTION(plist)
Definition: acoutput.h:239
#define ACPI_MODULE_NAME(Name)
Definition: acoutput.h:216
#define ACPI_WARNING(plist)
Definition: acoutput.h:238
#define return_ACPI_STATUS(s)
Definition: acoutput.h:496
#define ACPI_FUNCTION_TRACE(a)
Definition: acoutput.h:480
#define ACPI_ERROR(plist)
Definition: acoutput.h:240
#define ACPI_DB_RESOURCES
Definition: acoutput.h:176
#define AE_INFO
Definition: acoutput.h:230
ACPI_BUFFER *RetBuffer ACPI_BUFFER *RetBuffer char ACPI_WALK_RESOURCE_CALLBACK void *Context ACPI_BUFFER *RetBuffer UINT16 ACPI_RESOURCE **ResourcePtr ACPI_GENERIC_ADDRESS *Reg UINT32 *ReturnValue UINT8 UINT8 *Slp_TypB ACPI_PHYSICAL_ADDRESS PhysicalAddress64 UINT32 UINT32 *TimeElapsed UINT32 ACPI_STATUS const char UINT32 ACPI_STATUS const char UINT32 const char const char UINT32 const char BOOLEAN UINT8 * Aml
Definition: acpixf.h:1302
ACPI_RSCONVERT_INFO * AcpiGbl_ConvertResourceSerialBusDispatch[]
Definition: rsinfo.c:142
ACPI_STATUS AcpiRsConvertResourceToAml(ACPI_RESOURCE *Resource, AML_RESOURCE *Aml, ACPI_RSCONVERT_INFO *Info)
Definition: rsmisc.c:478
ACPI_RSCONVERT_INFO * AcpiGbl_SetResourceDispatch[]
Definition: rsinfo.c:65
ACPI_RSCONVERT_INFO * AcpiGbl_GetResourceDispatch[]
Definition: rsinfo.c:96
ACPI_STATUS AcpiRsConvertAmlToResource(ACPI_RESOURCE *Resource, AML_RESOURCE *Aml, ACPI_RSCONVERT_INFO *Info)
Definition: rsmisc.c:77
#define ACPI_RESOURCE_TYPE_SERIAL_BUS
Definition: acrestyp.h:742
#define ACPI_NEXT_RESOURCE(Res)
Definition: acrestyp.h:812
#define ACPI_RESOURCE_TYPE_END_TAG
Definition: acrestyp.h:730
#define ACPI_RESOURCE_TYPE_MAX
Definition: acrestyp.h:748
#define ACPI_CAST_INDIRECT_PTR(t, p)
Definition: actypes.h:545
UINT32 ACPI_STATUS
Definition: actypes.h:460
#define ACPI_CAST_PTR(t, p)
Definition: actypes.h:544
UINT32 AcpiUtGetDescriptorLength(void *Aml)
Definition: utresrc.c:606
ACPI_STATUS AcpiUtValidateResource(ACPI_WALK_STATE *WalkState, void *Aml, UINT8 *ReturnIndex)
Definition: utresrc.c:314
UINT8 AcpiUtGetResourceType(void *Aml)
Definition: utresrc.c:487
#define AML_RESOURCE_MAX_SERIALBUSTYPE
Definition: amlresrc.h:466
_Acquires_exclusive_lock_ Resource _Acquires_shared_lock_ Resource _Inout_ PERESOURCE Resource
Definition: cdprocs.h:843
#define NULL
Definition: types.h:112
Status
Definition: gdiplustypes.h:25
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
ACPI_STATUS AcpiRsConvertResourcesToAml(ACPI_RESOURCE *Resource, ACPI_SIZE AmlSizeNeeded, UINT8 *OutputBuffer)
Definition: rslist.c:179
ACPI_STATUS AcpiRsConvertAmlToResources(UINT8 *Aml, UINT32 Length, UINT32 Offset, UINT8 ResourceIndex, void **Context)
Definition: rslist.c:68
AML_RESOURCE_COMMON_SERIALBUS CommonSerialBus
Definition: amlresrc.h:708
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR OutputBuffer
Definition: wdfiotarget.h:863