TianoCore EDK2 master
Loading...
Searching...
No Matches
CustomFdtNodeParserLib.c
Go to the documentation of this file.
1
5#include <PiPei.h>
6#include <Pi/PiHob.h>
7#include <Library/BaseLib.h>
10#include <Library/DebugLib.h>
11#include <Library/IoLib.h>
12#include <Library/PrintLib.h>
13#include <Library/FdtLib.h>
14#include <Library/HobLib.h>
15#include <Library/PcdLib.h>
16
27VOID *
28EFIAPI
30 IN UINT16 HobType,
31 IN UINT16 HobLength
32 );
33
38VOID
41 );
42
51BOOLEAN
52EFIAPI
55 )
56{
57 if (FixedPcdGetBool (PcdHandOffFdtEnable)) {
58 if (Hob.Header->HobType == EFI_HOB_TYPE_HANDOFF) {
59 return FALSE;
60 }
61
62 if (Hob.Header->HobType == EFI_HOB_TYPE_MEMORY_ALLOCATION) {
63 if (CompareGuid (&Hob.MemoryAllocation->AllocDescriptor.Name, &gUniversalPayloadDeviceTreeGuid)) {
64 return FALSE;
65 }
66
67 if (CompareGuid (&Hob.MemoryAllocationModule->MemoryAllocationHeader.Name, &gEfiHobMemoryAllocModuleGuid)) {
68 return FALSE;
69 }
70
71 if ((Hob.MemoryAllocation->AllocDescriptor.MemoryType == EfiReservedMemoryType) ||
72 (Hob.MemoryAllocation->AllocDescriptor.MemoryType == EfiBootServicesCode) ||
73 (Hob.MemoryAllocation->AllocDescriptor.MemoryType == EfiBootServicesData) ||
74 (Hob.MemoryAllocation->AllocDescriptor.MemoryType == EfiRuntimeServicesCode) ||
75 (Hob.MemoryAllocation->AllocDescriptor.MemoryType == EfiRuntimeServicesData) ||
76 (Hob.MemoryAllocation->AllocDescriptor.MemoryType == EfiACPIReclaimMemory) ||
77 (Hob.MemoryAllocation->AllocDescriptor.MemoryType == EfiACPIMemoryNVS))
78 {
79 return FALSE;
80 }
81 }
82
83 if (Hob.Header->HobType == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) {
84 if (Hob.ResourceDescriptor->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY) {
85 return FALSE;
86 }
87 }
88
89 if (Hob.Header->HobType == EFI_HOB_TYPE_GUID_EXTENSION) {
90 if (CompareGuid (&Hob.Guid->Name, &gUniversalPayloadSmbios3TableGuid)) {
91 return FALSE;
92 }
93
94 if (CompareGuid (&Hob.Guid->Name, &gUniversalPayloadSerialPortInfoGuid)) {
95 return FALSE;
96 }
97
98 if (CompareGuid (&Hob.Guid->Name, &gUniversalPayloadAcpiTableGuid)) {
99 return FALSE;
100 }
101
102 if (CompareGuid (&Hob.Guid->Name, &gUniversalPayloadPciRootBridgeInfoGuid)) {
103 return FALSE;
104 }
105 }
106 }
107
108 // Arrive here mean the HOB is need
109 return TRUE;
110}
111
118UINTN
119EFIAPI
121 IN VOID *FdtBase,
122 IN VOID *HobList
123 )
124{
125 INT32 Node, CustomNode;
126 INT32 TempLen;
127 UINT64 *Data64;
128 UINTN CHobList;
129 CONST FDT_PROPERTY *PropertyPtr;
131
132 CHobList = (UINTN)HobList;
133
134 DEBUG ((DEBUG_INFO, "%a() #1 \n", __func__));
135
136 //
137 // Look for if exists hob list node
138 //
139 Node = FdtSubnodeOffsetNameLen (FdtBase, 0, "options", (INT32)AsciiStrLen ("options"));
140 if (Node > 0) {
141 DEBUG ((DEBUG_INFO, " Found options node (%08X)", Node));
142 CustomNode = FdtSubnodeOffsetNameLen (FdtBase, Node, "upl-custom", (INT32)AsciiStrLen ("upl-custom"));
143 if (CustomNode > 0) {
144 DEBUG ((DEBUG_INFO, " Found upl-custom node (%08X)", CustomNode));
145 PropertyPtr = FdtGetProperty (FdtBase, CustomNode, "hoblistptr", &TempLen);
146 Data64 = (UINT64 *)(PropertyPtr->Data);
147 CHobList = (UINTN)Fdt64ToCpu (*Data64);
148 DEBUG ((DEBUG_INFO, " Found hob list node (%08X)", CustomNode));
149 DEBUG ((DEBUG_INFO, " -pointer %016lX\n", CHobList));
150 }
151 }
152
153 Hob.Raw = (UINT8 *)CHobList;
154
155 //
156 // Since payload created new Hob, move all hobs except PHIT from boot loader hob list.
157 //
158 while (!END_OF_HOB_LIST (Hob)) {
159 if (FitIsHobNeed (Hob)) {
160 // Add this hob to payload HOB
161 AddNewHob (&Hob);
162 }
163
164 Hob.Raw = GET_NEXT_HOB (Hob);
165 }
166
167 return CHobList;
168}
UINT64 UINTN
UINTN EFIAPI AsciiStrLen(IN CONST CHAR8 *String)
Definition: String.c:641
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
Definition: MemLibGuid.c:73
UINTN EFIAPI CustomFdtNodeParser(IN VOID *FdtBase, IN VOID *HobList)
VOID *EFIAPI CreateHob(IN UINT16 HobType, IN UINT16 HobLength)
Definition: Hob.c:101
VOID AddNewHob(IN EFI_PEI_HOB_POINTERS *Hob)
Definition: HobParseLib.c:101
BOOLEAN EFIAPI FitIsHobNeed(EFI_PEI_HOB_POINTERS Hob)
CONST FDT_PROPERTY *EFIAPI FdtGetProperty(IN CONST VOID *Fdt, IN INT32 NodeOffset, IN CONST CHAR8 *Name, IN INT32 *Length)
Definition: FdtLib.c:446
UINT64 EFIAPI Fdt64ToCpu(IN UINT64 Value)
Definition: FdtLib.c:91
INT32 EFIAPI FdtSubnodeOffsetNameLen(IN CONST VOID *Fdt, IN INT32 ParentOffset, IN CONST CHAR8 *Name, IN INT32 NameLength)
Definition: FdtLib.c:320
#define CONST
Definition: Base.h:259
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define DEBUG(Expression)
Definition: DebugLib.h:434
#define FixedPcdGetBool(TokenName)
Definition: PcdLib.h:120
@ EfiBootServicesData
@ EfiReservedMemoryType
@ EfiBootServicesCode
@ EfiACPIMemoryNVS
@ EfiACPIReclaimMemory
@ EfiRuntimeServicesCode
@ EfiRuntimeServicesData
EFI_GUID Name
Definition: PiHob.h:347
EFI_MEMORY_TYPE MemoryType
Definition: PiHob.h:131
EFI_HOB_MEMORY_ALLOCATION_HEADER MemoryAllocationHeader
Definition: PiHob.h:207
EFI_HOB_MEMORY_ALLOCATION_HEADER AllocDescriptor
Definition: PiHob.h:153
EFI_RESOURCE_TYPE ResourceType
Definition: PiHob.h:320