TianoCore EDK2 master
Loading...
Searching...
No Matches
KvmtoolPlatformPeiLib.c
Go to the documentation of this file.
1
10#include <PiPei.h>
11
13#include <Guid/FdtHob.h>
14
16#include <Library/DebugLib.h>
17#include <Library/HobLib.h>
18#include <Library/PcdLib.h>
20#include <libfdt.h>
21
29EFIAPI
31 VOID
32 )
33{
34 VOID *Base;
35 VOID *NewBase;
36 UINTN FdtSize;
37 UINTN FdtPages;
38 UINT64 *FdtHobData;
39 UINT64 *UartHobData;
40
41 Base = (VOID *)(UINTN)PcdGet64 (PcdDeviceTreeInitialBaseAddress);
42 if ((Base == NULL) || (fdt_check_header (Base) != 0)) {
43 ASSERT (0);
44 return EFI_INVALID_PARAMETER;
45 }
46
47 FdtSize = fdt_totalsize (Base) + PcdGet32 (PcdDeviceTreeAllocationPadding);
48 FdtPages = EFI_SIZE_TO_PAGES (FdtSize);
49 NewBase = AllocatePages (FdtPages);
50 if (NewBase == NULL) {
51 ASSERT (0);
52 return EFI_OUT_OF_RESOURCES;
53 }
54
55 fdt_open_into (Base, NewBase, EFI_PAGES_TO_SIZE (FdtPages));
56
57 FdtHobData = BuildGuidHob (&gFdtHobGuid, sizeof (*FdtHobData));
58 if (FdtHobData == NULL) {
59 ASSERT (0);
60 return EFI_OUT_OF_RESOURCES;
61 }
62
63 *FdtHobData = (UINTN)NewBase;
64
65 UartHobData = BuildGuidHob (
66 &gEarly16550UartBaseAddressGuid,
67 sizeof (*UartHobData)
68 );
69 if (UartHobData == NULL) {
70 ASSERT (0);
71 return EFI_OUT_OF_RESOURCES;
72 }
73
74 *UartHobData = PcdGet64 (PcdSerialRegisterBase);
75
76 BuildFvHob (PcdGet64 (PcdFvBaseAddress), PcdGet32 (PcdFvSize));
77
78 return EFI_SUCCESS;
79}
UINT64 UINTN
VOID EFIAPI BuildFvHob(IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length)
Definition: HobLib.c:404
VOID *EFIAPI BuildGuidHob(IN CONST EFI_GUID *Guid, IN UINTN DataLength)
Definition: HobLib.c:336
EFI_STATUS EFIAPI PlatformPeim(VOID)
#define NULL
Definition: Base.h:319
#define PcdGet64(TokenName)
Definition: PcdLib.h:375
#define PcdGet32(TokenName)
Definition: PcdLib.h:362
VOID *EFIAPI AllocatePages(IN UINTN Pages)
#define EFI_PAGES_TO_SIZE(Pages)
Definition: UefiBaseType.h:213
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SIZE_TO_PAGES(Size)
Definition: UefiBaseType.h:200
#define EFI_SUCCESS
Definition: UefiBaseType.h:112