]> git.proxmox.com Git - mirror_edk2.git/blob - ArmVirtPkg/Library/KvmtoolPlatformPeiLib/KvmtoolPlatformPeiLib.c
ArmVirtPkg: Apply uncrustify changes
[mirror_edk2.git] / ArmVirtPkg / Library / KvmtoolPlatformPeiLib / KvmtoolPlatformPeiLib.c
1 /** @file
2 Kvmtool platform PEI library.
3
4 Copyright (c) 2020, ARM Limited. All rights reserved.
5
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9
10 #include <PiPei.h>
11
12 #include <Guid/Early16550UartBaseAddress.h>
13 #include <Guid/FdtHob.h>
14
15 #include <Library/MemoryAllocationLib.h>
16 #include <Library/DebugLib.h>
17 #include <Library/HobLib.h>
18 #include <Library/PcdLib.h>
19 #include <Library/PeiServicesLib.h>
20 #include <libfdt.h>
21
22 /** Initialise Platform HOBs
23
24 @retval EFI_SUCCESS Success.
25 @retval EFI_INVALID_PARAMETER A parameter is invalid.
26 @retval EFI_OUT_OF_RESOURCES Out of resources.
27 **/
28 EFI_STATUS
29 EFIAPI
30 PlatformPeim (
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 }