1 | /** @file
|
---|
2 | Copyright (c) 2024, Intel Corporation. All rights reserved.<BR>
|
---|
3 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
4 | **/
|
---|
5 | #include <PiPei.h>
|
---|
6 | #include <Pi/PiHob.h>
|
---|
7 | #include <Library/BaseLib.h>
|
---|
8 | #include <Library/BaseMemoryLib.h>
|
---|
9 | #include <Library/MemoryAllocationLib.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 |
|
---|
17 | /**
|
---|
18 | Add a new HOB to the HOB List.
|
---|
19 |
|
---|
20 | @param HobType Type of the new HOB.
|
---|
21 | @param HobLength Length of the new HOB to allocate.
|
---|
22 |
|
---|
23 | @return NULL if there is no space to create a hob.
|
---|
24 | @return The address point to the new created hob.
|
---|
25 |
|
---|
26 | **/
|
---|
27 | VOID *
|
---|
28 | EFIAPI
|
---|
29 | CreateHob (
|
---|
30 | IN UINT16 HobType,
|
---|
31 | IN UINT16 HobLength
|
---|
32 | );
|
---|
33 |
|
---|
34 | /**
|
---|
35 | Add HOB into HOB list
|
---|
36 | @param[in] Hob The HOB to be added into the HOB list.
|
---|
37 | **/
|
---|
38 | VOID
|
---|
39 | AddNewHob (
|
---|
40 | IN EFI_PEI_HOB_POINTERS *Hob
|
---|
41 | );
|
---|
42 |
|
---|
43 | /**
|
---|
44 | Check the HOB and decide if it is need inside Payload
|
---|
45 | Payload maintainer may make decision which HOB is need or needn't
|
---|
46 | Then add the check logic in the function.
|
---|
47 | @param[in] Hob The HOB to check
|
---|
48 | @retval TRUE If HOB is need inside Payload
|
---|
49 | @retval FALSE If HOB is needn't inside Payload
|
---|
50 | **/
|
---|
51 | BOOLEAN
|
---|
52 | EFIAPI
|
---|
53 | FitIsHobNeed (
|
---|
54 | EFI_PEI_HOB_POINTERS Hob
|
---|
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 |
|
---|
112 | /**
|
---|
113 | It will Parse FDT -custom node based on information from bootloaders.
|
---|
114 | @param[in] FdtBase The starting memory address of FdtBase
|
---|
115 | @param[in] HobList The starting memory address of New Hob list.
|
---|
116 |
|
---|
117 | **/
|
---|
118 | UINTN
|
---|
119 | EFIAPI
|
---|
120 | CustomFdtNodeParser (
|
---|
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;
|
---|
130 | EFI_PEI_HOB_POINTERS Hob;
|
---|
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 (ReadUnaligned64 (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 | }
|
---|