ReactOS 0.4.15-dev-7953-g1f49173
utresrc.c File Reference
#include "acpi.h"
#include "accommon.h"
#include "acresrc.h"
Include dependency graph for utresrc.c:

Go to the source code of this file.

Macros

#define _COMPONENT   ACPI_UTILITIES
 

Functions

ACPI_STATUS AcpiUtWalkAmlResources (ACPI_WALK_STATE *WalkState, UINT8 *Aml, ACPI_SIZE AmlLength, ACPI_WALK_AML_CALLBACK UserFunction, void **Context)
 
ACPI_STATUS AcpiUtValidateResource (ACPI_WALK_STATE *WalkState, void *Aml, UINT8 *ReturnIndex)
 
UINT8 AcpiUtGetResourceType (void *Aml)
 
UINT16 AcpiUtGetResourceLength (void *Aml)
 
UINT8 AcpiUtGetResourceHeaderLength (void *Aml)
 
UINT32 AcpiUtGetDescriptorLength (void *Aml)
 
ACPI_STATUS AcpiUtGetResourceEndTag (ACPI_OPERAND_OBJECT *ObjDesc, UINT8 **EndTag)
 

Variables

const UINT8 AcpiGbl_ResourceAmlSizes []
 
const UINT8 AcpiGbl_ResourceAmlSerialBusSizes []
 
static const UINT8 AcpiGbl_ResourceTypes []
 

Macro Definition Documentation

◆ _COMPONENT

#define _COMPONENT   ACPI_UTILITIES

Definition at line 49 of file utresrc.c.

Function Documentation

◆ AcpiUtGetDescriptorLength()

UINT32 AcpiUtGetDescriptorLength ( void Aml)

Definition at line 606 of file utresrc.c.

608{
610
611
612 /*
613 * Get the Resource Length (does not include header length) and add
614 * the header length (depends on if this is a small or large resource)
615 */
616 return (AcpiUtGetResourceLength (Aml) +
618}
#define ACPI_FUNCTION_ENTRY()
Definition: acoutput.h:484
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
UINT16 AcpiUtGetResourceLength(void *Aml)
Definition: utresrc.c:527
UINT8 AcpiUtGetResourceHeaderLength(void *Aml)
Definition: utresrc.c:572

Referenced by AcpiRsConvertResourcesToAml(), AcpiRsGetListLength(), and AcpiUtWalkAmlResources().

◆ AcpiUtGetResourceEndTag()

ACPI_STATUS AcpiUtGetResourceEndTag ( ACPI_OPERAND_OBJECT ObjDesc,
UINT8 **  EndTag 
)

Definition at line 636 of file utresrc.c.

639{
641
642
643 ACPI_FUNCTION_TRACE (UtGetResourceEndTag);
644
645
646 /* Allow a buffer length of zero */
647
648 if (!ObjDesc->Buffer.Length)
649 {
650 *EndTag = ObjDesc->Buffer.Pointer;
652 }
653
654 /* Validate the template and get a pointer to the EndTag */
655
656 Status = AcpiUtWalkAmlResources (NULL, ObjDesc->Buffer.Pointer,
657 ObjDesc->Buffer.Length, NULL, (void **) EndTag);
658
660}
#define AE_OK
Definition: acexcep.h:97
#define return_ACPI_STATUS(s)
Definition: acoutput.h:496
#define ACPI_FUNCTION_TRACE(a)
Definition: acoutput.h:480
UINT32 ACPI_STATUS
Definition: actypes.h:460
#define NULL
Definition: types.h:112
Status
Definition: gdiplustypes.h:25
ACPI_OBJECT_BUFFER Buffer
Definition: acobject.h:522
ACPI_STATUS AcpiUtWalkAmlResources(ACPI_WALK_STATE *WalkState, UINT8 *Aml, ACPI_SIZE AmlLength, ACPI_WALK_AML_CALLBACK UserFunction, void **Context)
Definition: utresrc.c:181

Referenced by AcpiExConcatTemplate().

◆ AcpiUtGetResourceHeaderLength()

UINT8 AcpiUtGetResourceHeaderLength ( void Aml)

Definition at line 572 of file utresrc.c.

574{
576
577
578 /* Examine the large/small bit in the resource header */
579
581 {
582 return (sizeof (AML_RESOURCE_LARGE_HEADER));
583 }
584 else
585 {
586 return (sizeof (AML_RESOURCE_SMALL_HEADER));
587 }
588}
#define ACPI_RESOURCE_NAME_LARGE
Definition: aclocal.h:1300
#define ACPI_GET8(ptr)
Definition: acmacros.h:57

Referenced by AcpiRsGetListLength(), AcpiRsSetResourceLength(), and AcpiUtGetDescriptorLength().

◆ AcpiUtGetResourceLength()

UINT16 AcpiUtGetResourceLength ( void Aml)

Definition at line 527 of file utresrc.c.

529{
530 ACPI_RS_LENGTH ResourceLength;
531
532
534
535
536 /*
537 * Byte 0 contains the descriptor name (Resource Type)
538 * Examine the large/small bit in the resource header
539 */
541 {
542 /* Large Resource type -- bytes 1-2 contain the 16-bit length */
543
544 ACPI_MOVE_16_TO_16 (&ResourceLength, ACPI_ADD_PTR (UINT8, Aml, 1));
545
546 }
547 else
548 {
549 /* Small Resource type -- bits 2:0 of byte 0 contain the length */
550
551 ResourceLength = (UINT16) (ACPI_GET8 (Aml) &
553 }
554
555 return (ResourceLength);
556}
unsigned short UINT16
unsigned char UINT8
#define ACPI_RESOURCE_NAME_SMALL_LENGTH_MASK
Definition: aclocal.h:1304
#define ACPI_MOVE_16_TO_16(d, s)
Definition: acmacros.h:141
UINT16 ACPI_RS_LENGTH
Definition: acrestyp.h:51
#define ACPI_ADD_PTR(t, a, b)
Definition: actypes.h:546

Referenced by AcpiRsConvertAmlToResource(), AcpiRsGetListLength(), AcpiUtGetDescriptorLength(), and AcpiUtValidateResource().

◆ AcpiUtGetResourceType()

UINT8 AcpiUtGetResourceType ( void Aml)

Definition at line 487 of file utresrc.c.

489{
491
492
493 /*
494 * Byte 0 contains the descriptor name (Resource Type)
495 * Examine the large/small bit in the resource header
496 */
498 {
499 /* Large Resource Type -- bits 6:0 contain the name */
500
501 return (ACPI_GET8 (Aml));
502 }
503 else
504 {
505 /* Small Resource Type -- bits 6:3 contain the name */
506
508 }
509}
#define ACPI_RESOURCE_NAME_SMALL_MASK
Definition: aclocal.h:1303

Referenced by AcpiRsConvertAmlToResources(), AcpiRsGetListLength(), and AcpiUtWalkAmlResources().

◆ AcpiUtValidateResource()

ACPI_STATUS AcpiUtValidateResource ( ACPI_WALK_STATE WalkState,
void Aml,
UINT8 ReturnIndex 
)

Definition at line 314 of file utresrc.c.

318{
319 AML_RESOURCE *AmlResource;
320 UINT8 ResourceType;
321 UINT8 ResourceIndex;
322 ACPI_RS_LENGTH ResourceLength;
323 ACPI_RS_LENGTH MinimumResourceLength;
324
325
327
328
329 /*
330 * 1) Validate the ResourceType field (Byte 0)
331 */
332 ResourceType = ACPI_GET8 (Aml);
333
334 /*
335 * Byte 0 contains the descriptor name (Resource Type)
336 * Examine the large/small bit in the resource header
337 */
338 if (ResourceType & ACPI_RESOURCE_NAME_LARGE)
339 {
340 /* Verify the large resource type (name) against the max */
341
342 if (ResourceType > ACPI_RESOURCE_NAME_LARGE_MAX)
343 {
344 goto InvalidResource;
345 }
346
347 /*
348 * Large Resource Type -- bits 6:0 contain the name
349 * Translate range 0x80-0x8B to index range 0x10-0x1B
350 */
351 ResourceIndex = (UINT8) (ResourceType - 0x70);
352 }
353 else
354 {
355 /*
356 * Small Resource Type -- bits 6:3 contain the name
357 * Shift range to index range 0x00-0x0F
358 */
359 ResourceIndex = (UINT8)
360 ((ResourceType & ACPI_RESOURCE_NAME_SMALL_MASK) >> 3);
361 }
362
363 /*
364 * Check validity of the resource type, via AcpiGbl_ResourceTypes.
365 * Zero indicates an invalid resource.
366 */
367 if (!AcpiGbl_ResourceTypes[ResourceIndex])
368 {
369 goto InvalidResource;
370 }
371
372 /*
373 * Validate the ResourceLength field. This ensures that the length
374 * is at least reasonable, and guarantees that it is non-zero.
375 */
376 ResourceLength = AcpiUtGetResourceLength (Aml);
377 MinimumResourceLength = AcpiGbl_ResourceAmlSizes[ResourceIndex];
378
379 /* Validate based upon the type of resource - fixed length or variable */
380
381 switch (AcpiGbl_ResourceTypes[ResourceIndex])
382 {
384
385 /* Fixed length resource, length must match exactly */
386
387 if (ResourceLength != MinimumResourceLength)
388 {
389 goto BadResourceLength;
390 }
391 break;
392
394
395 /* Variable length resource, length must be at least the minimum */
396
397 if (ResourceLength < MinimumResourceLength)
398 {
399 goto BadResourceLength;
400 }
401 break;
402
404
405 /* Small variable length resource, length can be (Min) or (Min-1) */
406
407 if ((ResourceLength > MinimumResourceLength) ||
408 (ResourceLength < (MinimumResourceLength - 1)))
409 {
410 goto BadResourceLength;
411 }
412 break;
413
414 default:
415
416 /* Shouldn't happen (because of validation earlier), but be sure */
417
418 goto InvalidResource;
419 }
420
421 AmlResource = ACPI_CAST_PTR (AML_RESOURCE, Aml);
422 if (ResourceType == ACPI_RESOURCE_NAME_SERIAL_BUS)
423 {
424 /* Validate the BusType field */
425
426 if ((AmlResource->CommonSerialBus.Type == 0) ||
428 {
429 if (WalkState)
430 {
432 "Invalid/unsupported SerialBus resource descriptor: BusType 0x%2.2X",
433 AmlResource->CommonSerialBus.Type));
434 }
436 }
437 }
438
439 /* Optionally return the resource table index */
440
441 if (ReturnIndex)
442 {
443 *ReturnIndex = ResourceIndex;
444 }
445
446 return (AE_OK);
447
448
449InvalidResource:
450
451 if (WalkState)
452 {
454 "Invalid/unsupported resource descriptor: Type 0x%2.2X",
455 ResourceType));
456 }
458
459BadResourceLength:
460
461 if (WalkState)
462 {
464 "Invalid resource descriptor length: Type "
465 "0x%2.2X, Length 0x%4.4X, MinLength 0x%4.4X",
466 ResourceType, ResourceLength, MinimumResourceLength));
467 }
469}
#define AE_AML_INVALID_RESOURCE_TYPE
Definition: acexcep.h:202
#define AE_AML_BAD_RESOURCE_LENGTH
Definition: acexcep.h:210
#define ACPI_RESOURCE_NAME_LARGE_MAX
Definition: aclocal.h:1347
#define ACPI_RESOURCE_NAME_SERIAL_BUS
Definition: aclocal.h:1342
#define ACPI_ERROR(plist)
Definition: acoutput.h:240
#define AE_INFO
Definition: acoutput.h:230
#define ACPI_CAST_PTR(t, p)
Definition: actypes.h:544
#define ACPI_SMALL_VARIABLE_LENGTH
Definition: acutils.h:153
#define ACPI_FIXED_LENGTH
Definition: acutils.h:151
#define ACPI_VARIABLE_LENGTH
Definition: acutils.h:152
#define AML_RESOURCE_MAX_SERIALBUSTYPE
Definition: amlresrc.h:466
AML_RESOURCE_COMMON_SERIALBUS CommonSerialBus
Definition: amlresrc.h:708
const UINT8 AcpiGbl_ResourceAmlSizes[]
Definition: utresrc.c:57
static const UINT8 AcpiGbl_ResourceTypes[]
Definition: utresrc.c:117

Referenced by AcpiRsConvertResourcesToAml(), AcpiRsGetListLength(), and AcpiUtWalkAmlResources().

◆ AcpiUtWalkAmlResources()

ACPI_STATUS AcpiUtWalkAmlResources ( ACPI_WALK_STATE WalkState,
UINT8 Aml,
ACPI_SIZE  AmlLength,
ACPI_WALK_AML_CALLBACK  UserFunction,
void **  Context 
)

Definition at line 181 of file utresrc.c.

187{
189 UINT8 *EndAml;
190 UINT8 ResourceIndex;
192 UINT32 Offset = 0;
193 UINT8 EndTag[2] = {0x79, 0x00};
194
195
196 ACPI_FUNCTION_TRACE (UtWalkAmlResources);
197
198
199 /* The absolute minimum resource template is one EndTag descriptor */
200
201 if (AmlLength < sizeof (AML_RESOURCE_END_TAG))
202 {
204 }
205
206 /* Point to the end of the resource template buffer */
207
208 EndAml = Aml + AmlLength;
209
210 /* Walk the byte list, abort on any invalid descriptor type or length */
211
212 while (Aml < EndAml)
213 {
214 /* Validate the Resource Type and Resource Length */
215
216 Status = AcpiUtValidateResource (WalkState, Aml, &ResourceIndex);
217 if (ACPI_FAILURE (Status))
218 {
219 /*
220 * Exit on failure. Cannot continue because the descriptor
221 * length may be bogus also.
222 */
224 }
225
226 /* Get the length of this descriptor */
227
229
230 /* Invoke the user function */
231
232 if (UserFunction)
233 {
235 Aml, Length, Offset, ResourceIndex, Context);
236 if (ACPI_FAILURE (Status))
237 {
239 }
240 }
241
242 /* An EndTag descriptor terminates this resource template */
243
245 {
246 /*
247 * There must be at least one more byte in the buffer for
248 * the 2nd byte of the EndTag
249 */
250 if ((Aml + 1) >= EndAml)
251 {
253 }
254
255 /*
256 * Don't attempt to perform any validation on the 2nd byte.
257 * Although all known ASL compilers insert a zero for the 2nd
258 * byte, it can also be a checksum (as per the ACPI spec),
259 * and this is occasionally seen in the field. July 2017.
260 */
261
262 /* Return the pointer to the EndTag if requested */
263
264 if (!UserFunction)
265 {
266 *Context = Aml;
267 }
268
269 /* Normal exit */
270
272 }
273
274 Aml += Length;
275 Offset += Length;
276 }
277
278 /* Did not find an EndTag descriptor */
279
280 if (UserFunction)
281 {
282 /* Insert an EndTag anyway. AcpiRsGetListLength always leaves room */
283
284 (void) AcpiUtValidateResource (WalkState, EndTag, &ResourceIndex);
285 Status = UserFunction (EndTag, 2, Offset, ResourceIndex, Context);
286 if (ACPI_FAILURE (Status))
287 {
289 }
290 }
291
293}
unsigned int UINT32
#define ACPI_FAILURE(a)
Definition: acexcep.h:95
#define AE_AML_NO_RESOURCE_END_TAG
Definition: acexcep.h:207
#define ACPI_RESOURCE_NAME_END_TAG
Definition: aclocal.h:1323
ACPI_BUFFER *RetBuffer ACPI_BUFFER *RetBuffer char ACPI_WALK_RESOURCE_CALLBACK UserFunction
Definition: acpixf.h:1078
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
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

Referenced by AcpiBufferToResource(), AcpiRsCreateResourceList(), and AcpiUtGetResourceEndTag().

Variable Documentation

◆ AcpiGbl_ResourceAmlSerialBusSizes

◆ AcpiGbl_ResourceAmlSizes

const UINT8 AcpiGbl_ResourceAmlSizes[]

Definition at line 57 of file utresrc.c.

Referenced by AcpiRsGetListLength(), and AcpiUtValidateResource().

◆ AcpiGbl_ResourceTypes

const UINT8 AcpiGbl_ResourceTypes[]
static

Definition at line 117 of file utresrc.c.

Referenced by AcpiUtValidateResource().