utresrc.c revision 1.1.1.9 1 1.1 jruoho /*******************************************************************************
2 1.1 jruoho *
3 1.1.1.3 christos * Module Name: utresrc - Resource management utilities
4 1.1 jruoho *
5 1.1 jruoho ******************************************************************************/
6 1.1 jruoho
7 1.1.1.2 jruoho /*
8 1.1.1.7 christos * Copyright (C) 2000 - 2017, Intel Corp.
9 1.1 jruoho * All rights reserved.
10 1.1 jruoho *
11 1.1.1.2 jruoho * Redistribution and use in source and binary forms, with or without
12 1.1.1.2 jruoho * modification, are permitted provided that the following conditions
13 1.1.1.2 jruoho * are met:
14 1.1.1.2 jruoho * 1. Redistributions of source code must retain the above copyright
15 1.1.1.2 jruoho * notice, this list of conditions, and the following disclaimer,
16 1.1.1.2 jruoho * without modification.
17 1.1.1.2 jruoho * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.1.1.2 jruoho * substantially similar to the "NO WARRANTY" disclaimer below
19 1.1.1.2 jruoho * ("Disclaimer") and any redistribution must be conditioned upon
20 1.1.1.2 jruoho * including a substantially similar Disclaimer requirement for further
21 1.1.1.2 jruoho * binary redistribution.
22 1.1.1.2 jruoho * 3. Neither the names of the above-listed copyright holders nor the names
23 1.1.1.2 jruoho * of any contributors may be used to endorse or promote products derived
24 1.1.1.2 jruoho * from this software without specific prior written permission.
25 1.1.1.2 jruoho *
26 1.1.1.2 jruoho * Alternatively, this software may be distributed under the terms of the
27 1.1.1.2 jruoho * GNU General Public License ("GPL") version 2 as published by the Free
28 1.1.1.2 jruoho * Software Foundation.
29 1.1.1.2 jruoho *
30 1.1.1.2 jruoho * NO WARRANTY
31 1.1.1.2 jruoho * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.1.1.2 jruoho * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.1.1.2 jruoho * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.1.1.2 jruoho * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.1.1.2 jruoho * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.1.1.2 jruoho * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.1.1.2 jruoho * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.1.1.2 jruoho * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.1.1.2 jruoho * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.1.1.2 jruoho * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.1.1.2 jruoho * POSSIBILITY OF SUCH DAMAGES.
42 1.1.1.2 jruoho */
43 1.1 jruoho
44 1.1 jruoho #include "acpi.h"
45 1.1 jruoho #include "accommon.h"
46 1.1.1.3 christos #include "acresrc.h"
47 1.1 jruoho
48 1.1 jruoho
49 1.1 jruoho #define _COMPONENT ACPI_UTILITIES
50 1.1 jruoho ACPI_MODULE_NAME ("utresrc")
51 1.1 jruoho
52 1.1 jruoho
53 1.1 jruoho /*
54 1.1 jruoho * Base sizes of the raw AML resource descriptors, indexed by resource type.
55 1.1 jruoho * Zero indicates a reserved (and therefore invalid) resource type.
56 1.1 jruoho */
57 1.1 jruoho const UINT8 AcpiGbl_ResourceAmlSizes[] =
58 1.1 jruoho {
59 1.1 jruoho /* Small descriptors */
60 1.1 jruoho
61 1.1 jruoho 0,
62 1.1 jruoho 0,
63 1.1 jruoho 0,
64 1.1 jruoho 0,
65 1.1 jruoho ACPI_AML_SIZE_SMALL (AML_RESOURCE_IRQ),
66 1.1 jruoho ACPI_AML_SIZE_SMALL (AML_RESOURCE_DMA),
67 1.1 jruoho ACPI_AML_SIZE_SMALL (AML_RESOURCE_START_DEPENDENT),
68 1.1 jruoho ACPI_AML_SIZE_SMALL (AML_RESOURCE_END_DEPENDENT),
69 1.1 jruoho ACPI_AML_SIZE_SMALL (AML_RESOURCE_IO),
70 1.1 jruoho ACPI_AML_SIZE_SMALL (AML_RESOURCE_FIXED_IO),
71 1.1.1.3 christos ACPI_AML_SIZE_SMALL (AML_RESOURCE_FIXED_DMA),
72 1.1 jruoho 0,
73 1.1 jruoho 0,
74 1.1 jruoho 0,
75 1.1 jruoho ACPI_AML_SIZE_SMALL (AML_RESOURCE_VENDOR_SMALL),
76 1.1 jruoho ACPI_AML_SIZE_SMALL (AML_RESOURCE_END_TAG),
77 1.1 jruoho
78 1.1 jruoho /* Large descriptors */
79 1.1 jruoho
80 1.1 jruoho 0,
81 1.1 jruoho ACPI_AML_SIZE_LARGE (AML_RESOURCE_MEMORY24),
82 1.1 jruoho ACPI_AML_SIZE_LARGE (AML_RESOURCE_GENERIC_REGISTER),
83 1.1 jruoho 0,
84 1.1 jruoho ACPI_AML_SIZE_LARGE (AML_RESOURCE_VENDOR_LARGE),
85 1.1 jruoho ACPI_AML_SIZE_LARGE (AML_RESOURCE_MEMORY32),
86 1.1 jruoho ACPI_AML_SIZE_LARGE (AML_RESOURCE_FIXED_MEMORY32),
87 1.1 jruoho ACPI_AML_SIZE_LARGE (AML_RESOURCE_ADDRESS32),
88 1.1 jruoho ACPI_AML_SIZE_LARGE (AML_RESOURCE_ADDRESS16),
89 1.1 jruoho ACPI_AML_SIZE_LARGE (AML_RESOURCE_EXTENDED_IRQ),
90 1.1 jruoho ACPI_AML_SIZE_LARGE (AML_RESOURCE_ADDRESS64),
91 1.1.1.3 christos ACPI_AML_SIZE_LARGE (AML_RESOURCE_EXTENDED_ADDRESS64),
92 1.1.1.3 christos ACPI_AML_SIZE_LARGE (AML_RESOURCE_GPIO),
93 1.1.1.9 christos ACPI_AML_SIZE_LARGE (AML_RESOURCE_PIN_FUNCTION),
94 1.1.1.3 christos ACPI_AML_SIZE_LARGE (AML_RESOURCE_COMMON_SERIALBUS),
95 1.1.1.9 christos ACPI_AML_SIZE_LARGE (AML_RESOURCE_PIN_CONFIG),
96 1.1.1.9 christos ACPI_AML_SIZE_LARGE (AML_RESOURCE_PIN_GROUP),
97 1.1.1.9 christos ACPI_AML_SIZE_LARGE (AML_RESOURCE_PIN_GROUP_FUNCTION),
98 1.1.1.9 christos ACPI_AML_SIZE_LARGE (AML_RESOURCE_PIN_GROUP_CONFIG),
99 1.1.1.3 christos };
100 1.1.1.3 christos
101 1.1.1.3 christos const UINT8 AcpiGbl_ResourceAmlSerialBusSizes[] =
102 1.1.1.3 christos {
103 1.1.1.3 christos 0,
104 1.1.1.3 christos ACPI_AML_SIZE_LARGE (AML_RESOURCE_I2C_SERIALBUS),
105 1.1.1.3 christos ACPI_AML_SIZE_LARGE (AML_RESOURCE_SPI_SERIALBUS),
106 1.1.1.3 christos ACPI_AML_SIZE_LARGE (AML_RESOURCE_UART_SERIALBUS),
107 1.1 jruoho };
108 1.1 jruoho
109 1.1 jruoho
110 1.1 jruoho /*
111 1.1 jruoho * Resource types, used to validate the resource length field.
112 1.1 jruoho * The length of fixed-length types must match exactly, variable
113 1.1 jruoho * lengths must meet the minimum required length, etc.
114 1.1 jruoho * Zero indicates a reserved (and therefore invalid) resource type.
115 1.1 jruoho */
116 1.1 jruoho static const UINT8 AcpiGbl_ResourceTypes[] =
117 1.1 jruoho {
118 1.1 jruoho /* Small descriptors */
119 1.1 jruoho
120 1.1 jruoho 0,
121 1.1 jruoho 0,
122 1.1 jruoho 0,
123 1.1 jruoho 0,
124 1.1.1.3 christos ACPI_SMALL_VARIABLE_LENGTH, /* 04 IRQ */
125 1.1.1.3 christos ACPI_FIXED_LENGTH, /* 05 DMA */
126 1.1.1.3 christos ACPI_SMALL_VARIABLE_LENGTH, /* 06 StartDependentFunctions */
127 1.1.1.3 christos ACPI_FIXED_LENGTH, /* 07 EndDependentFunctions */
128 1.1.1.3 christos ACPI_FIXED_LENGTH, /* 08 IO */
129 1.1.1.3 christos ACPI_FIXED_LENGTH, /* 09 FixedIO */
130 1.1.1.3 christos ACPI_FIXED_LENGTH, /* 0A FixedDMA */
131 1.1 jruoho 0,
132 1.1 jruoho 0,
133 1.1 jruoho 0,
134 1.1.1.3 christos ACPI_VARIABLE_LENGTH, /* 0E VendorShort */
135 1.1.1.3 christos ACPI_FIXED_LENGTH, /* 0F EndTag */
136 1.1 jruoho
137 1.1 jruoho /* Large descriptors */
138 1.1 jruoho
139 1.1 jruoho 0,
140 1.1.1.3 christos ACPI_FIXED_LENGTH, /* 01 Memory24 */
141 1.1.1.3 christos ACPI_FIXED_LENGTH, /* 02 GenericRegister */
142 1.1 jruoho 0,
143 1.1.1.3 christos ACPI_VARIABLE_LENGTH, /* 04 VendorLong */
144 1.1.1.3 christos ACPI_FIXED_LENGTH, /* 05 Memory32 */
145 1.1.1.3 christos ACPI_FIXED_LENGTH, /* 06 Memory32Fixed */
146 1.1.1.3 christos ACPI_VARIABLE_LENGTH, /* 07 Dword* address */
147 1.1.1.3 christos ACPI_VARIABLE_LENGTH, /* 08 Word* address */
148 1.1.1.3 christos ACPI_VARIABLE_LENGTH, /* 09 ExtendedIRQ */
149 1.1.1.3 christos ACPI_VARIABLE_LENGTH, /* 0A Qword* address */
150 1.1.1.3 christos ACPI_FIXED_LENGTH, /* 0B Extended* address */
151 1.1.1.3 christos ACPI_VARIABLE_LENGTH, /* 0C Gpio* */
152 1.1.1.9 christos ACPI_VARIABLE_LENGTH, /* 0D PinFunction */
153 1.1.1.9 christos ACPI_VARIABLE_LENGTH, /* 0E *SerialBus */
154 1.1.1.9 christos ACPI_VARIABLE_LENGTH, /* 0F PinConfig */
155 1.1.1.9 christos ACPI_VARIABLE_LENGTH, /* 10 PinGroup */
156 1.1.1.9 christos ACPI_VARIABLE_LENGTH, /* 11 PinGroupFunction */
157 1.1.1.9 christos ACPI_VARIABLE_LENGTH, /* 12 PinGroupConfig */
158 1.1 jruoho };
159 1.1 jruoho
160 1.1 jruoho
161 1.1 jruoho /*******************************************************************************
162 1.1 jruoho *
163 1.1 jruoho * FUNCTION: AcpiUtWalkAmlResources
164 1.1 jruoho *
165 1.1.1.3 christos * PARAMETERS: WalkState - Current walk info
166 1.1.1.3 christos * PARAMETERS: Aml - Pointer to the raw AML resource template
167 1.1.1.3 christos * AmlLength - Length of the entire template
168 1.1.1.3 christos * UserFunction - Called once for each descriptor found. If
169 1.1.1.3 christos * NULL, a pointer to the EndTag is returned
170 1.1.1.3 christos * Context - Passed to UserFunction
171 1.1 jruoho *
172 1.1 jruoho * RETURN: Status
173 1.1 jruoho *
174 1.1 jruoho * DESCRIPTION: Walk a raw AML resource list(buffer). User function called
175 1.1 jruoho * once for each resource found.
176 1.1 jruoho *
177 1.1 jruoho ******************************************************************************/
178 1.1 jruoho
179 1.1 jruoho ACPI_STATUS
180 1.1 jruoho AcpiUtWalkAmlResources (
181 1.1.1.3 christos ACPI_WALK_STATE *WalkState,
182 1.1 jruoho UINT8 *Aml,
183 1.1 jruoho ACPI_SIZE AmlLength,
184 1.1 jruoho ACPI_WALK_AML_CALLBACK UserFunction,
185 1.1.1.3 christos void **Context)
186 1.1 jruoho {
187 1.1 jruoho ACPI_STATUS Status;
188 1.1 jruoho UINT8 *EndAml;
189 1.1 jruoho UINT8 ResourceIndex;
190 1.1 jruoho UINT32 Length;
191 1.1 jruoho UINT32 Offset = 0;
192 1.1.1.3 christos UINT8 EndTag[2] = {0x79, 0x00};
193 1.1 jruoho
194 1.1 jruoho
195 1.1 jruoho ACPI_FUNCTION_TRACE (UtWalkAmlResources);
196 1.1 jruoho
197 1.1 jruoho
198 1.1.1.9 christos /* The absolute minimum resource template is one EndTag descriptor */
199 1.1.1.9 christos
200 1.1 jruoho if (AmlLength < sizeof (AML_RESOURCE_END_TAG))
201 1.1 jruoho {
202 1.1 jruoho return_ACPI_STATUS (AE_AML_NO_RESOURCE_END_TAG);
203 1.1 jruoho }
204 1.1 jruoho
205 1.1 jruoho /* Point to the end of the resource template buffer */
206 1.1 jruoho
207 1.1 jruoho EndAml = Aml + AmlLength;
208 1.1 jruoho
209 1.1 jruoho /* Walk the byte list, abort on any invalid descriptor type or length */
210 1.1 jruoho
211 1.1 jruoho while (Aml < EndAml)
212 1.1 jruoho {
213 1.1 jruoho /* Validate the Resource Type and Resource Length */
214 1.1 jruoho
215 1.1.1.3 christos Status = AcpiUtValidateResource (WalkState, Aml, &ResourceIndex);
216 1.1 jruoho if (ACPI_FAILURE (Status))
217 1.1 jruoho {
218 1.1.1.3 christos /*
219 1.1.1.6 christos * Exit on failure. Cannot continue because the descriptor
220 1.1.1.6 christos * length may be bogus also.
221 1.1.1.3 christos */
222 1.1 jruoho return_ACPI_STATUS (Status);
223 1.1 jruoho }
224 1.1 jruoho
225 1.1 jruoho /* Get the length of this descriptor */
226 1.1 jruoho
227 1.1 jruoho Length = AcpiUtGetDescriptorLength (Aml);
228 1.1 jruoho
229 1.1 jruoho /* Invoke the user function */
230 1.1 jruoho
231 1.1 jruoho if (UserFunction)
232 1.1 jruoho {
233 1.1.1.9 christos Status = UserFunction (
234 1.1.1.9 christos Aml, Length, Offset, ResourceIndex, Context);
235 1.1 jruoho if (ACPI_FAILURE (Status))
236 1.1 jruoho {
237 1.1.1.3 christos return_ACPI_STATUS (Status);
238 1.1 jruoho }
239 1.1 jruoho }
240 1.1 jruoho
241 1.1 jruoho /* An EndTag descriptor terminates this resource template */
242 1.1 jruoho
243 1.1 jruoho if (AcpiUtGetResourceType (Aml) == ACPI_RESOURCE_NAME_END_TAG)
244 1.1 jruoho {
245 1.1 jruoho /*
246 1.1 jruoho * There must be at least one more byte in the buffer for
247 1.1 jruoho * the 2nd byte of the EndTag
248 1.1 jruoho */
249 1.1 jruoho if ((Aml + 1) >= EndAml)
250 1.1 jruoho {
251 1.1 jruoho return_ACPI_STATUS (AE_AML_NO_RESOURCE_END_TAG);
252 1.1 jruoho }
253 1.1 jruoho
254 1.1.1.8 christos /*
255 1.1.1.9 christos * Don't attempt to perform any validation on the 2nd byte.
256 1.1.1.9 christos * Although all known ASL compilers insert a zero for the 2nd
257 1.1.1.9 christos * byte, it can also be a checksum (as per the ACPI spec),
258 1.1.1.9 christos * and this is occasionally seen in the field. July 2017.
259 1.1.1.8 christos */
260 1.1.1.8 christos
261 1.1 jruoho /* Return the pointer to the EndTag if requested */
262 1.1 jruoho
263 1.1 jruoho if (!UserFunction)
264 1.1 jruoho {
265 1.1.1.3 christos *Context = Aml;
266 1.1 jruoho }
267 1.1 jruoho
268 1.1 jruoho /* Normal exit */
269 1.1 jruoho
270 1.1 jruoho return_ACPI_STATUS (AE_OK);
271 1.1 jruoho }
272 1.1 jruoho
273 1.1 jruoho Aml += Length;
274 1.1 jruoho Offset += Length;
275 1.1 jruoho }
276 1.1 jruoho
277 1.1 jruoho /* Did not find an EndTag descriptor */
278 1.1 jruoho
279 1.1.1.3 christos if (UserFunction)
280 1.1.1.3 christos {
281 1.1.1.3 christos /* Insert an EndTag anyway. AcpiRsGetListLength always leaves room */
282 1.1.1.3 christos
283 1.1.1.3 christos (void) AcpiUtValidateResource (WalkState, EndTag, &ResourceIndex);
284 1.1.1.3 christos Status = UserFunction (EndTag, 2, Offset, ResourceIndex, Context);
285 1.1.1.3 christos if (ACPI_FAILURE (Status))
286 1.1.1.3 christos {
287 1.1.1.3 christos return_ACPI_STATUS (Status);
288 1.1.1.3 christos }
289 1.1.1.3 christos }
290 1.1.1.3 christos
291 1.1.1.3 christos return_ACPI_STATUS (AE_AML_NO_RESOURCE_END_TAG);
292 1.1 jruoho }
293 1.1 jruoho
294 1.1 jruoho
295 1.1 jruoho /*******************************************************************************
296 1.1 jruoho *
297 1.1 jruoho * FUNCTION: AcpiUtValidateResource
298 1.1 jruoho *
299 1.1.1.3 christos * PARAMETERS: WalkState - Current walk info
300 1.1.1.3 christos * Aml - Pointer to the raw AML resource descriptor
301 1.1.1.3 christos * ReturnIndex - Where the resource index is returned. NULL
302 1.1.1.3 christos * if the index is not required.
303 1.1 jruoho *
304 1.1 jruoho * RETURN: Status, and optionally the Index into the global resource tables
305 1.1 jruoho *
306 1.1 jruoho * DESCRIPTION: Validate an AML resource descriptor by checking the Resource
307 1.1 jruoho * Type and Resource Length. Returns an index into the global
308 1.1 jruoho * resource information/dispatch tables for later use.
309 1.1 jruoho *
310 1.1 jruoho ******************************************************************************/
311 1.1 jruoho
312 1.1 jruoho ACPI_STATUS
313 1.1 jruoho AcpiUtValidateResource (
314 1.1.1.3 christos ACPI_WALK_STATE *WalkState,
315 1.1 jruoho void *Aml,
316 1.1 jruoho UINT8 *ReturnIndex)
317 1.1 jruoho {
318 1.1.1.3 christos AML_RESOURCE *AmlResource;
319 1.1 jruoho UINT8 ResourceType;
320 1.1 jruoho UINT8 ResourceIndex;
321 1.1 jruoho ACPI_RS_LENGTH ResourceLength;
322 1.1 jruoho ACPI_RS_LENGTH MinimumResourceLength;
323 1.1 jruoho
324 1.1 jruoho
325 1.1 jruoho ACPI_FUNCTION_ENTRY ();
326 1.1 jruoho
327 1.1 jruoho
328 1.1 jruoho /*
329 1.1 jruoho * 1) Validate the ResourceType field (Byte 0)
330 1.1 jruoho */
331 1.1 jruoho ResourceType = ACPI_GET8 (Aml);
332 1.1 jruoho
333 1.1 jruoho /*
334 1.1 jruoho * Byte 0 contains the descriptor name (Resource Type)
335 1.1 jruoho * Examine the large/small bit in the resource header
336 1.1 jruoho */
337 1.1 jruoho if (ResourceType & ACPI_RESOURCE_NAME_LARGE)
338 1.1 jruoho {
339 1.1 jruoho /* Verify the large resource type (name) against the max */
340 1.1 jruoho
341 1.1 jruoho if (ResourceType > ACPI_RESOURCE_NAME_LARGE_MAX)
342 1.1 jruoho {
343 1.1.1.3 christos goto InvalidResource;
344 1.1 jruoho }
345 1.1 jruoho
346 1.1 jruoho /*
347 1.1 jruoho * Large Resource Type -- bits 6:0 contain the name
348 1.1 jruoho * Translate range 0x80-0x8B to index range 0x10-0x1B
349 1.1 jruoho */
350 1.1 jruoho ResourceIndex = (UINT8) (ResourceType - 0x70);
351 1.1 jruoho }
352 1.1 jruoho else
353 1.1 jruoho {
354 1.1 jruoho /*
355 1.1 jruoho * Small Resource Type -- bits 6:3 contain the name
356 1.1 jruoho * Shift range to index range 0x00-0x0F
357 1.1 jruoho */
358 1.1 jruoho ResourceIndex = (UINT8)
359 1.1 jruoho ((ResourceType & ACPI_RESOURCE_NAME_SMALL_MASK) >> 3);
360 1.1 jruoho }
361 1.1 jruoho
362 1.1.1.3 christos /*
363 1.1.1.6 christos * Check validity of the resource type, via AcpiGbl_ResourceTypes.
364 1.1.1.6 christos * Zero indicates an invalid resource.
365 1.1.1.3 christos */
366 1.1 jruoho if (!AcpiGbl_ResourceTypes[ResourceIndex])
367 1.1 jruoho {
368 1.1.1.3 christos goto InvalidResource;
369 1.1 jruoho }
370 1.1 jruoho
371 1.1 jruoho /*
372 1.1.1.3 christos * Validate the ResourceLength field. This ensures that the length
373 1.1.1.3 christos * is at least reasonable, and guarantees that it is non-zero.
374 1.1 jruoho */
375 1.1 jruoho ResourceLength = AcpiUtGetResourceLength (Aml);
376 1.1 jruoho MinimumResourceLength = AcpiGbl_ResourceAmlSizes[ResourceIndex];
377 1.1 jruoho
378 1.1 jruoho /* Validate based upon the type of resource - fixed length or variable */
379 1.1 jruoho
380 1.1 jruoho switch (AcpiGbl_ResourceTypes[ResourceIndex])
381 1.1 jruoho {
382 1.1 jruoho case ACPI_FIXED_LENGTH:
383 1.1 jruoho
384 1.1 jruoho /* Fixed length resource, length must match exactly */
385 1.1 jruoho
386 1.1 jruoho if (ResourceLength != MinimumResourceLength)
387 1.1 jruoho {
388 1.1.1.3 christos goto BadResourceLength;
389 1.1 jruoho }
390 1.1 jruoho break;
391 1.1 jruoho
392 1.1 jruoho case ACPI_VARIABLE_LENGTH:
393 1.1 jruoho
394 1.1 jruoho /* Variable length resource, length must be at least the minimum */
395 1.1 jruoho
396 1.1 jruoho if (ResourceLength < MinimumResourceLength)
397 1.1 jruoho {
398 1.1.1.3 christos goto BadResourceLength;
399 1.1 jruoho }
400 1.1 jruoho break;
401 1.1 jruoho
402 1.1 jruoho case ACPI_SMALL_VARIABLE_LENGTH:
403 1.1 jruoho
404 1.1 jruoho /* Small variable length resource, length can be (Min) or (Min-1) */
405 1.1 jruoho
406 1.1 jruoho if ((ResourceLength > MinimumResourceLength) ||
407 1.1 jruoho (ResourceLength < (MinimumResourceLength - 1)))
408 1.1 jruoho {
409 1.1.1.3 christos goto BadResourceLength;
410 1.1 jruoho }
411 1.1 jruoho break;
412 1.1 jruoho
413 1.1 jruoho default:
414 1.1 jruoho
415 1.1 jruoho /* Shouldn't happen (because of validation earlier), but be sure */
416 1.1 jruoho
417 1.1.1.3 christos goto InvalidResource;
418 1.1.1.3 christos }
419 1.1.1.3 christos
420 1.1.1.3 christos AmlResource = ACPI_CAST_PTR (AML_RESOURCE, Aml);
421 1.1.1.3 christos if (ResourceType == ACPI_RESOURCE_NAME_SERIAL_BUS)
422 1.1.1.3 christos {
423 1.1.1.3 christos /* Validate the BusType field */
424 1.1.1.3 christos
425 1.1.1.3 christos if ((AmlResource->CommonSerialBus.Type == 0) ||
426 1.1.1.3 christos (AmlResource->CommonSerialBus.Type > AML_RESOURCE_MAX_SERIALBUSTYPE))
427 1.1.1.3 christos {
428 1.1.1.3 christos if (WalkState)
429 1.1.1.3 christos {
430 1.1.1.3 christos ACPI_ERROR ((AE_INFO,
431 1.1.1.3 christos "Invalid/unsupported SerialBus resource descriptor: BusType 0x%2.2X",
432 1.1.1.3 christos AmlResource->CommonSerialBus.Type));
433 1.1.1.3 christos }
434 1.1.1.3 christos return (AE_AML_INVALID_RESOURCE_TYPE);
435 1.1.1.3 christos }
436 1.1 jruoho }
437 1.1 jruoho
438 1.1 jruoho /* Optionally return the resource table index */
439 1.1 jruoho
440 1.1 jruoho if (ReturnIndex)
441 1.1 jruoho {
442 1.1 jruoho *ReturnIndex = ResourceIndex;
443 1.1 jruoho }
444 1.1 jruoho
445 1.1 jruoho return (AE_OK);
446 1.1.1.3 christos
447 1.1.1.3 christos
448 1.1.1.3 christos InvalidResource:
449 1.1.1.3 christos
450 1.1.1.3 christos if (WalkState)
451 1.1.1.3 christos {
452 1.1.1.3 christos ACPI_ERROR ((AE_INFO,
453 1.1.1.3 christos "Invalid/unsupported resource descriptor: Type 0x%2.2X",
454 1.1.1.3 christos ResourceType));
455 1.1.1.3 christos }
456 1.1.1.3 christos return (AE_AML_INVALID_RESOURCE_TYPE);
457 1.1.1.3 christos
458 1.1.1.3 christos BadResourceLength:
459 1.1.1.3 christos
460 1.1.1.3 christos if (WalkState)
461 1.1.1.3 christos {
462 1.1.1.3 christos ACPI_ERROR ((AE_INFO,
463 1.1.1.3 christos "Invalid resource descriptor length: Type "
464 1.1.1.3 christos "0x%2.2X, Length 0x%4.4X, MinLength 0x%4.4X",
465 1.1.1.3 christos ResourceType, ResourceLength, MinimumResourceLength));
466 1.1.1.3 christos }
467 1.1.1.3 christos return (AE_AML_BAD_RESOURCE_LENGTH);
468 1.1 jruoho }
469 1.1 jruoho
470 1.1 jruoho
471 1.1 jruoho /*******************************************************************************
472 1.1 jruoho *
473 1.1 jruoho * FUNCTION: AcpiUtGetResourceType
474 1.1 jruoho *
475 1.1 jruoho * PARAMETERS: Aml - Pointer to the raw AML resource descriptor
476 1.1 jruoho *
477 1.1 jruoho * RETURN: The Resource Type with no extraneous bits (except the
478 1.1 jruoho * Large/Small descriptor bit -- this is left alone)
479 1.1 jruoho *
480 1.1 jruoho * DESCRIPTION: Extract the Resource Type/Name from the first byte of
481 1.1 jruoho * a resource descriptor.
482 1.1 jruoho *
483 1.1 jruoho ******************************************************************************/
484 1.1 jruoho
485 1.1 jruoho UINT8
486 1.1 jruoho AcpiUtGetResourceType (
487 1.1 jruoho void *Aml)
488 1.1 jruoho {
489 1.1 jruoho ACPI_FUNCTION_ENTRY ();
490 1.1 jruoho
491 1.1 jruoho
492 1.1 jruoho /*
493 1.1 jruoho * Byte 0 contains the descriptor name (Resource Type)
494 1.1 jruoho * Examine the large/small bit in the resource header
495 1.1 jruoho */
496 1.1 jruoho if (ACPI_GET8 (Aml) & ACPI_RESOURCE_NAME_LARGE)
497 1.1 jruoho {
498 1.1 jruoho /* Large Resource Type -- bits 6:0 contain the name */
499 1.1 jruoho
500 1.1 jruoho return (ACPI_GET8 (Aml));
501 1.1 jruoho }
502 1.1 jruoho else
503 1.1 jruoho {
504 1.1 jruoho /* Small Resource Type -- bits 6:3 contain the name */
505 1.1 jruoho
506 1.1 jruoho return ((UINT8) (ACPI_GET8 (Aml) & ACPI_RESOURCE_NAME_SMALL_MASK));
507 1.1 jruoho }
508 1.1 jruoho }
509 1.1 jruoho
510 1.1 jruoho
511 1.1 jruoho /*******************************************************************************
512 1.1 jruoho *
513 1.1 jruoho * FUNCTION: AcpiUtGetResourceLength
514 1.1 jruoho *
515 1.1 jruoho * PARAMETERS: Aml - Pointer to the raw AML resource descriptor
516 1.1 jruoho *
517 1.1 jruoho * RETURN: Byte Length
518 1.1 jruoho *
519 1.1 jruoho * DESCRIPTION: Get the "Resource Length" of a raw AML descriptor. By
520 1.1 jruoho * definition, this does not include the size of the descriptor
521 1.1 jruoho * header or the length field itself.
522 1.1 jruoho *
523 1.1 jruoho ******************************************************************************/
524 1.1 jruoho
525 1.1 jruoho UINT16
526 1.1 jruoho AcpiUtGetResourceLength (
527 1.1 jruoho void *Aml)
528 1.1 jruoho {
529 1.1 jruoho ACPI_RS_LENGTH ResourceLength;
530 1.1 jruoho
531 1.1 jruoho
532 1.1 jruoho ACPI_FUNCTION_ENTRY ();
533 1.1 jruoho
534 1.1 jruoho
535 1.1 jruoho /*
536 1.1 jruoho * Byte 0 contains the descriptor name (Resource Type)
537 1.1 jruoho * Examine the large/small bit in the resource header
538 1.1 jruoho */
539 1.1 jruoho if (ACPI_GET8 (Aml) & ACPI_RESOURCE_NAME_LARGE)
540 1.1 jruoho {
541 1.1 jruoho /* Large Resource type -- bytes 1-2 contain the 16-bit length */
542 1.1 jruoho
543 1.1 jruoho ACPI_MOVE_16_TO_16 (&ResourceLength, ACPI_ADD_PTR (UINT8, Aml, 1));
544 1.1 jruoho
545 1.1 jruoho }
546 1.1 jruoho else
547 1.1 jruoho {
548 1.1 jruoho /* Small Resource type -- bits 2:0 of byte 0 contain the length */
549 1.1 jruoho
550 1.1 jruoho ResourceLength = (UINT16) (ACPI_GET8 (Aml) &
551 1.1.1.6 christos ACPI_RESOURCE_NAME_SMALL_LENGTH_MASK);
552 1.1 jruoho }
553 1.1 jruoho
554 1.1 jruoho return (ResourceLength);
555 1.1 jruoho }
556 1.1 jruoho
557 1.1 jruoho
558 1.1 jruoho /*******************************************************************************
559 1.1 jruoho *
560 1.1 jruoho * FUNCTION: AcpiUtGetResourceHeaderLength
561 1.1 jruoho *
562 1.1 jruoho * PARAMETERS: Aml - Pointer to the raw AML resource descriptor
563 1.1 jruoho *
564 1.1 jruoho * RETURN: Length of the AML header (depends on large/small descriptor)
565 1.1 jruoho *
566 1.1 jruoho * DESCRIPTION: Get the length of the header for this resource.
567 1.1 jruoho *
568 1.1 jruoho ******************************************************************************/
569 1.1 jruoho
570 1.1 jruoho UINT8
571 1.1 jruoho AcpiUtGetResourceHeaderLength (
572 1.1 jruoho void *Aml)
573 1.1 jruoho {
574 1.1 jruoho ACPI_FUNCTION_ENTRY ();
575 1.1 jruoho
576 1.1 jruoho
577 1.1 jruoho /* Examine the large/small bit in the resource header */
578 1.1 jruoho
579 1.1 jruoho if (ACPI_GET8 (Aml) & ACPI_RESOURCE_NAME_LARGE)
580 1.1 jruoho {
581 1.1 jruoho return (sizeof (AML_RESOURCE_LARGE_HEADER));
582 1.1 jruoho }
583 1.1 jruoho else
584 1.1 jruoho {
585 1.1 jruoho return (sizeof (AML_RESOURCE_SMALL_HEADER));
586 1.1 jruoho }
587 1.1 jruoho }
588 1.1 jruoho
589 1.1 jruoho
590 1.1 jruoho /*******************************************************************************
591 1.1 jruoho *
592 1.1 jruoho * FUNCTION: AcpiUtGetDescriptorLength
593 1.1 jruoho *
594 1.1 jruoho * PARAMETERS: Aml - Pointer to the raw AML resource descriptor
595 1.1 jruoho *
596 1.1 jruoho * RETURN: Byte length
597 1.1 jruoho *
598 1.1 jruoho * DESCRIPTION: Get the total byte length of a raw AML descriptor, including the
599 1.1 jruoho * length of the descriptor header and the length field itself.
600 1.1 jruoho * Used to walk descriptor lists.
601 1.1 jruoho *
602 1.1 jruoho ******************************************************************************/
603 1.1 jruoho
604 1.1 jruoho UINT32
605 1.1 jruoho AcpiUtGetDescriptorLength (
606 1.1 jruoho void *Aml)
607 1.1 jruoho {
608 1.1 jruoho ACPI_FUNCTION_ENTRY ();
609 1.1 jruoho
610 1.1 jruoho
611 1.1 jruoho /*
612 1.1 jruoho * Get the Resource Length (does not include header length) and add
613 1.1 jruoho * the header length (depends on if this is a small or large resource)
614 1.1 jruoho */
615 1.1 jruoho return (AcpiUtGetResourceLength (Aml) +
616 1.1.1.6 christos AcpiUtGetResourceHeaderLength (Aml));
617 1.1 jruoho }
618 1.1 jruoho
619 1.1 jruoho
620 1.1 jruoho /*******************************************************************************
621 1.1 jruoho *
622 1.1 jruoho * FUNCTION: AcpiUtGetResourceEndTag
623 1.1 jruoho *
624 1.1 jruoho * PARAMETERS: ObjDesc - The resource template buffer object
625 1.1 jruoho * EndTag - Where the pointer to the EndTag is returned
626 1.1 jruoho *
627 1.1 jruoho * RETURN: Status, pointer to the end tag
628 1.1 jruoho *
629 1.1 jruoho * DESCRIPTION: Find the EndTag resource descriptor in an AML resource template
630 1.1 jruoho * Note: allows a buffer length of zero.
631 1.1 jruoho *
632 1.1 jruoho ******************************************************************************/
633 1.1 jruoho
634 1.1 jruoho ACPI_STATUS
635 1.1 jruoho AcpiUtGetResourceEndTag (
636 1.1 jruoho ACPI_OPERAND_OBJECT *ObjDesc,
637 1.1 jruoho UINT8 **EndTag)
638 1.1 jruoho {
639 1.1 jruoho ACPI_STATUS Status;
640 1.1 jruoho
641 1.1 jruoho
642 1.1 jruoho ACPI_FUNCTION_TRACE (UtGetResourceEndTag);
643 1.1 jruoho
644 1.1 jruoho
645 1.1 jruoho /* Allow a buffer length of zero */
646 1.1 jruoho
647 1.1 jruoho if (!ObjDesc->Buffer.Length)
648 1.1 jruoho {
649 1.1 jruoho *EndTag = ObjDesc->Buffer.Pointer;
650 1.1 jruoho return_ACPI_STATUS (AE_OK);
651 1.1 jruoho }
652 1.1 jruoho
653 1.1 jruoho /* Validate the template and get a pointer to the EndTag */
654 1.1 jruoho
655 1.1.1.3 christos Status = AcpiUtWalkAmlResources (NULL, ObjDesc->Buffer.Pointer,
656 1.1.1.6 christos ObjDesc->Buffer.Length, NULL, (void **) EndTag);
657 1.1 jruoho
658 1.1 jruoho return_ACPI_STATUS (Status);
659 1.1 jruoho }
660