ReactOS  0.4.14-dev-1115-gebeeb9d
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 605 of file utresrc.c.

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

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

◆ AcpiUtGetResourceEndTag()

ACPI_STATUS AcpiUtGetResourceEndTag ( ACPI_OPERAND_OBJECT ObjDesc,
UINT8 **  EndTag 
)

Definition at line 635 of file utresrc.c.

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

Referenced by AcpiExConcatTemplate().

◆ AcpiUtGetResourceHeaderLength()

UINT8 AcpiUtGetResourceHeaderLength ( void Aml)

Definition at line 571 of file utresrc.c.

573 {
575 
576 
577  /* Examine the large/small bit in the resource header */
578 
580  {
581  return (sizeof (AML_RESOURCE_LARGE_HEADER));
582  }
583  else
584  {
585  return (sizeof (AML_RESOURCE_SMALL_HEADER));
586  }
587 }
#define ACPI_RESOURCE_NAME_LARGE
Definition: aclocal.h:1300
#define ACPI_GET8(ptr)
Definition: acmacros.h:57
#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:1297

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

◆ AcpiUtGetResourceLength()

UINT16 AcpiUtGetResourceLength ( void Aml)

Definition at line 526 of file utresrc.c.

528 {
529  ACPI_RS_LENGTH ResourceLength;
530 
531 
533 
534 
535  /*
536  * Byte 0 contains the descriptor name (Resource Type)
537  * Examine the large/small bit in the resource header
538  */
540  {
541  /* Large Resource type -- bytes 1-2 contain the 16-bit length */
542 
543  ACPI_MOVE_16_TO_16 (&ResourceLength, ACPI_ADD_PTR (UINT8, Aml, 1));
544 
545  }
546  else
547  {
548  /* Small Resource type -- bits 2:0 of byte 0 contain the length */
549 
550  ResourceLength = (UINT16) (ACPI_GET8 (Aml) &
552  }
553 
554  return (ResourceLength);
555 }
#define ACPI_MOVE_16_TO_16(d, s)
Definition: acmacros.h:141
#define ACPI_RESOURCE_NAME_LARGE
Definition: aclocal.h:1300
#define ACPI_GET8(ptr)
Definition: acmacros.h:57
#define ACPI_FUNCTION_ENTRY()
Definition: acoutput.h:484
#define ACPI_RESOURCE_NAME_SMALL_LENGTH_MASK
Definition: aclocal.h:1304
unsigned short UINT16
UINT16 ACPI_RS_LENGTH
Definition: acrestyp.h:51
#define ACPI_ADD_PTR(t, a, b)
Definition: actypes.h:546
unsigned char UINT8
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:1297

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

◆ AcpiUtGetResourceType()

UINT8 AcpiUtGetResourceType ( void Aml)

Definition at line 486 of file utresrc.c.

488 {
490 
491 
492  /*
493  * Byte 0 contains the descriptor name (Resource Type)
494  * Examine the large/small bit in the resource header
495  */
497  {
498  /* Large Resource Type -- bits 6:0 contain the name */
499 
500  return (ACPI_GET8 (Aml));
501  }
502  else
503  {
504  /* Small Resource Type -- bits 6:3 contain the name */
505 
507  }
508 }
#define ACPI_RESOURCE_NAME_SMALL_MASK
Definition: aclocal.h:1303
#define ACPI_RESOURCE_NAME_LARGE
Definition: aclocal.h:1300
#define ACPI_GET8(ptr)
Definition: acmacros.h:57
#define ACPI_FUNCTION_ENTRY()
Definition: acoutput.h:484
unsigned char UINT8
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:1297

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

◆ AcpiUtValidateResource()

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

Definition at line 313 of file utresrc.c.

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

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 180 of file utresrc.c.

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

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 116 of file utresrc.c.

Referenced by AcpiUtValidateResource().