17#include <Library/BaseLib.h> 
   18#include <Library/DebugLib.h> 
   19#include <Library/BaseMemoryLib.h> 
   20#include <Library/MemoryAllocationLib.h> 
   21#include <Library/PrintLib.h> 
   25#include <Library/UefiBootServicesTableLib.h> 
   26#include <Library/UefiLib.h> 
   31#define DEVICE_TREE_GET_NEXT_PROPERTY(Prop)  \ 
   32  (DTProperty *)(((UINT8 *)(UINTN)(Prop))    \ 
   33    + sizeof (*Prop) + ALIGN_VALUE (Prop->Length, sizeof (UINT32))) 
 
   62  if ((Entry == NULL) || (Entry->NumProperties == 0)) {
 
   66    for (Count = 0; Count < Entry->NumProperties; ++Count) {
 
 
   89  for (Count = 0; Count < Root->NumChildren; ++Count) {
 
 
  146  if (Cur->NumChildren == 0) {
 
  153    if (EFI_ERROR (
DTGetProperty (Child, 
"name", (VOID **)&Str, &Dummy))) {
 
  157    if (AsciiStrCmp (Str, Buf) == 0) {
 
  161    if (Index >= Cur->NumChildren) {
 
 
  188    return EFI_INVALID_PARAMETER;
 
  191  if (SearchPoint == NULL) {
 
  222  } 
while (Cur != NULL);
 
  224  return EFI_INVALID_PARAMETER;
 
 
  236    return EFI_INVALID_PARAMETER;
 
  242    return EFI_OUT_OF_RESOURCES;
 
  245  if (StartEntry != NULL) {
 
 
  268  while ((Scope = Iterator->SavedScope) != NULL) {
 
 
  285  if (ChildEntry == NULL) {
 
  286    return EFI_INVALID_PARAMETER;
 
  291  if (NewScope == NULL) {
 
  292    return EFI_OUT_OF_RESOURCES;
 
  295  NewScope->
NextScope = Iterator->SavedScope;
 
  296  NewScope->
Scope     = Iterator->CurrentScope;
 
  297  NewScope->
Entry     = Iterator->CurrentEntry;
 
  298  NewScope->
Index     = Iterator->CurrentIndex;
 
  300  Iterator->CurrentScope = ChildEntry;
 
  301  Iterator->CurrentEntry = NULL;
 
  302  Iterator->SavedScope   = NewScope;
 
  303  Iterator->CurrentIndex = 0;
 
 
  316  NewScope = Iterator->SavedScope;
 
  318  if (NewScope == NULL) {
 
  319    return EFI_INVALID_PARAMETER;
 
  322  Iterator->SavedScope   = NewScope->
NextScope;
 
  323  Iterator->CurrentScope = NewScope->
Scope;
 
  324  Iterator->CurrentEntry = NewScope->
Entry;
 
  325  Iterator->CurrentIndex = NewScope->
Index;
 
  327  *CurrentPosition = Iterator->CurrentEntry;
 
 
  340  if (Iterator->CurrentIndex >= Iterator->CurrentScope->NumChildren) {
 
  342    return EFI_END_OF_MEDIA;
 
  345  ++Iterator->CurrentIndex;
 
  346  if (Iterator->CurrentIndex == 1) {
 
  347    Iterator->CurrentEntry = 
GetFirstChild (Iterator->CurrentScope);
 
  349    Iterator->CurrentEntry = 
GetNextChild (Iterator->CurrentEntry);
 
  352  *NextEntry = Iterator->CurrentEntry;
 
 
  361  Iterator->CurrentEntry = NULL;
 
  362  Iterator->CurrentIndex = 0;
 
 
  369  IN CHAR8          *PropertyName,
 
  370  IN VOID           **PropertyValue,
 
  371  IN UINT32         *PropertySize
 
  377  if ((Entry == NULL) || (Entry->NumProperties == 0)) {
 
  378    return EFI_INVALID_PARAMETER;
 
  382  for (Count = 0; Count < Entry->NumProperties; Count++) {
 
  383    if (AsciiStrCmp (Prop->
Name, PropertyName) == 0) {
 
  384      *PropertyValue = (VOID *)(((UINT8 *)Prop) + 
sizeof (
DTProperty));
 
  385      *PropertySize  = Prop->Length;
 
  392  return EFI_INVALID_PARAMETER;
 
 
  401  Iterator->Entry           = Entry;
 
  402  Iterator->CurrentProperty = NULL;
 
  403  Iterator->CurrentIndex    = 0;
 
 
  411  IN CHAR8               **FoundProperty
 
  414  if (Iterator->CurrentIndex >= Iterator->Entry->NumProperties) {
 
  415    *FoundProperty = NULL;
 
  416    return EFI_END_OF_MEDIA;
 
  419  Iterator->CurrentIndex++;
 
  420  if (Iterator->CurrentIndex == 1) {
 
  421    Iterator->CurrentProperty = (
DTProperty *)(Iterator->Entry + 1);
 
  426  *FoundProperty = Iterator->CurrentProperty->
Name;
 
 
  436  Iterator->CurrentProperty = NULL;
 
  437  Iterator->CurrentIndex    = 0;
 
 
  457  CHAR8  *PropertyParent = NULL;
 
  458  CHAR8  *PropertyName   = NULL;
 
  459  CHAR8  *PropertyValue  = NULL;
 
  461  UINT32  PropertySize = 0;
 
  466    return EFI_INVALID_PARAMETER;
 
  474  if (!EFI_ERROR (Status)) {
 
  475    PropertyParent = 
"/";
 
  478      if ((Status = 
DTGetProperty (Entry, (CHAR8 *)PropertyName, (
void *)&PropertyValue, &PropertySize)) != EFI_SUCCESS) {
 
  479        DEBUG ((DEBUG_WARN, 
"DeviceTree is probably invalid - %r\n", Status));
 
  483      if (AsciiStrnCmp (PropertyName, 
"name", 4) == 0) {
 
  486        PropertyParent = PropertyValue;
 
  488      } 
else if (AsciiStrnCmp (PropertyName, 
"guid", 4) == 0) {
 
  492        DEBUG ((DEBUG_INFO, 
"|%*a \"%a\" = < %g >\n", 
mDTNodeDepth * Spacer, 
" ", PropertyName, PropertyValue, PropertySize));
 
  493      } 
else if (AsciiStrnCmp (PropertyParent, 
"memory-map", 10) == 0) {
 
  496        if (AsciiStrnCmp (PropertyName, 
"Driver-", 7) == 0) {
 
  502              "|%*a \"%a\" = < Dict 0x%0X Binary 0x%0X \"%a\" >\n",
 
  512          Address = (UINT8 *)(UINTN)
MemMap->Address;
 
  513          if (Address != NULL) {
 
  516              "|%*a \"%a\" = < 0x%0X %02X %02X %02X %02X Length %X >\n",
 
  535          "|%*a \"%a\" = < ... > (%d)\n",
 
  549  if (!EFI_ERROR (Status)) {
 
  556  return !EFI_ERROR (Status) ? EFI_SUCCESS : EFI_NOT_FOUND;
 
 
  584  if ((Base != NULL) && (
Length != NULL)) {
 
 
  600  IN CHAR8  *DeletePropertyName
 
  606  CHAR8               *DeletePosition;
 
  607  CHAR8               *DeviceTreeEnd;
 
  613  DeletePosition = NULL;
 
  620        if (AsciiStrStr (DeletePosition, DeletePropertyName) != NULL) {
 
  622          DeleteLength = 
sizeof (
DTProperty) + ALIGN_VALUE (Property->
Length, sizeof (UINT32));
 
  632          CopyMem (DeletePosition, DeletePosition + DeleteLength, DeviceTreeEnd - DeletePosition);
 
  633          ZeroMem (DeviceTreeEnd - DeleteLength, DeleteLength);
 
 
  663  IN CHAR8    *InsertPropertyName,
 
  664  IN CHAR8    *AddPropertyName,
 
  665  IN VOID     *AddPropertyValue,
 
  666  IN UINT32   ValueLength,
 
  667  IN BOOLEAN  InsertAfter
 
  675  CHAR8               *DeviceTreeEnd;
 
  676  CHAR8               *InsertPosition;
 
  681  EntryLength    = ALIGN_VALUE (ValueLength, 
sizeof (UINT32));
 
  684  InsertPosition = NULL;
 
  689        InsertPosition = DeviceTree;
 
  690        if (AsciiStrStr (InsertPosition, InsertPropertyName) != NULL) {
 
  697        InsertPosition += 
sizeof (
DTProperty) + ALIGN_VALUE (Property->
Length, sizeof (UINT32));
 
  705      CopyMem (InsertPosition + 
sizeof (
DTProperty) + EntryLength, InsertPosition, DeviceTreeEnd - InsertPosition);
 
  711      CopyMem (Property->
Name, AddPropertyName, AsciiStrLen (AddPropertyName));
 
  716      Property->
Length = ValueLength;
 
 
MEMMAP_DEVICE_PATH MemMap
 
CHAR16 PathName[DMG_FILE_PATH_LEN]
 
EFI_STATUS DTLookupEntry(IN CONST DTEntry SearchPoint, IN CONST CHAR8 *PathName, IN DTEntry *FoundEntry)
 
STATIC CONST CHAR8 * GetNextComponent(IN CONST CHAR8 *Cp, IN CHAR8 *Bp)
 
EFI_STATUS DTDisposeEntryIterator(IN DTEntryIterator Iterator)
 
VOID DTInit(IN VOID *Base, IN UINT32 *Length)
 
EFI_STATUS DTIterateProperties(IN DTPropertyIterator Iterator, IN CHAR8 **FoundProperty)
 
EFI_STATUS DTRestartPropertyIteration(IN DTPropertyIterator Iterator)
 
STATIC DTEntry DTSkipTree(IN DTEntry Root)
 
EFI_STATUS DTCreateEntryIterator(IN CONST DTEntry StartEntry, IN DTEntryIterator *Iterator)
 
EFI_STATUS DTGetProperty(IN CONST DTEntry Entry, IN CHAR8 *PropertyName, IN VOID **PropertyValue, IN UINT32 *PropertySize)
 
STATIC UINT32 mDTNodeDepth
 
STATIC UINT32 * mDTLength
 
STATIC DTEntry GetFirstChild(IN DTEntry Parent)
 
UINT32 DTDeleteProperty(IN CHAR8 *NodeName, IN CHAR8 *DeletePropertyName)
 
VOID DTInsertProperty(IN CHAR8 *NodeName, IN CHAR8 *InsertPropertyName, IN CHAR8 *AddPropertyName, IN VOID *AddPropertyValue, IN UINT32 ValueLength, IN BOOLEAN InsertAfter)
 
EFI_STATUS DTCreatePropertyIterator(IN CONST DTEntry Entry, IN DTPropertyIterator Iterator)
 
#define DEVICE_TREE_GET_NEXT_PROPERTY(Prop)
 
STATIC OpaqueDTPropertyIterator mOpaquePropIter
 
EFI_STATUS DumpDeviceTreeNodeRecusively(IN DTEntry Entry)
 
STATIC DTEntry DTSkipProperties(IN DTEntry Entry)
 
EFI_STATUS DTExitEntry(IN DTEntryIterator Iterator, IN DTEntry *CurrentPosition)
 
STATIC DTEntry mDTRootNode
 
EFI_STATUS DTIterateEntries(IN DTEntryIterator Iterator, IN DTEntry *NextEntry)
 
STATIC DTEntry GetNextChild(IN DTEntry Sibling)
 
EFI_STATUS DTRestartEntryIteration(IN DTEntryIterator Iterator)
 
EFI_STATUS DTEnterEntry(IN DTEntryIterator Iterator, IN DTEntry ChildEntry)
 
STATIC DTEntry FindChild(IN DTEntry Cur, IN CHAR8 *Buf)
 
VOID DumpDeviceTree(VOID)
 
struct OpaqueDTProperty_ DTProperty
 
DeviceTreeNode * DTEntry
Entry.
 
#define DT_PATH_NAME_SEPERATOR
0x2F
 
CHAR8 DTEntryNameBuf[DT_PROPERTY_NAME_LENGTH]
Length of DTEntryNameBuf = DT_MAX_ENTRY_NAME_LENGTH + 1.
 
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
 
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
 
UINT32 BundlePathPhysAddr
 
UINT32 ExecutablePhysAddr
 
DTSavedScopePtr NextScope
 
DTSavedScopePtr SavedScope
 
UINT32 Length
Length (bytes) of folloing prop value.
 
CHAR8 Name[DT_PROPERTY_NAME_LENGTH]
NUL terminated property name.