]> git.proxmox.com Git - mirror_edk2.git/blame - ArmVirtPkg/Library/PlatformPeiLib/PlatformPeiLib.c
ArmVirtPkg/PlatformBootManagerLib: unload image on EFI_SECURITY_VIOLATION
[mirror_edk2.git] / ArmVirtPkg / Library / PlatformPeiLib / PlatformPeiLib.c
CommitLineData
433b31dd
AB
1/** @file\r
2*\r
bb5420bb 3* Copyright (c) 2011-2014, ARM Limited. All rights reserved.\r
433b31dd
AB
4* Copyright (c) 2014, Linaro Limited. All rights reserved.\r
5*\r
9792fb0e 6* SPDX-License-Identifier: BSD-2-Clause-Patent\r
433b31dd
AB
7*\r
8**/\r
9\r
10#include <PiPei.h>\r
11\r
12#include <Library/MemoryAllocationLib.h>\r
13#include <Library/DebugLib.h>\r
14#include <Library/HobLib.h>\r
15#include <Library/PcdLib.h>\r
16#include <libfdt.h>\r
17\r
337d450e 18#include <Guid/EarlyPL011BaseAddress.h>\r
cc667df0 19#include <Guid/FdtHob.h>\r
337d450e 20\r
433b31dd
AB
21EFI_STATUS\r
22EFIAPI\r
23PlatformPeim (\r
24 VOID\r
25 )\r
26{\r
27 VOID *Base;\r
28 VOID *NewBase;\r
29 UINTN FdtSize;\r
616ea9da 30 UINTN FdtPages;\r
cc667df0 31 UINT64 *FdtHobData;\r
337d450e
AB
32 UINT64 *UartHobData;\r
33 INT32 Node, Prev;\r
34 CONST CHAR8 *Compatible;\r
35 CONST CHAR8 *CompItem;\r
83ae7589 36 CONST CHAR8 *NodeStatus;\r
337d450e 37 INT32 Len;\r
83ae7589 38 INT32 StatusLen;\r
337d450e
AB
39 CONST UINT64 *RegProp;\r
40 UINT64 UartBase;\r
41\r
433b31dd 42\r
cc667df0
AB
43 Base = (VOID*)(UINTN)PcdGet64 (PcdDeviceTreeInitialBaseAddress);\r
44 ASSERT (Base != NULL);\r
433b31dd
AB
45 ASSERT (fdt_check_header (Base) == 0);\r
46\r
616ea9da
AB
47 FdtSize = fdt_totalsize (Base) + PcdGet32 (PcdDeviceTreeAllocationPadding);\r
48 FdtPages = EFI_SIZE_TO_PAGES (FdtSize);\r
49 NewBase = AllocatePages (FdtPages);\r
433b31dd 50 ASSERT (NewBase != NULL);\r
616ea9da 51 fdt_open_into (Base, NewBase, EFI_PAGES_TO_SIZE (FdtPages));\r
cc667df0
AB
52\r
53 FdtHobData = BuildGuidHob (&gFdtHobGuid, sizeof *FdtHobData);\r
54 ASSERT (FdtHobData != NULL);\r
55 *FdtHobData = (UINTN)NewBase;\r
433b31dd 56\r
337d450e
AB
57 UartHobData = BuildGuidHob (&gEarlyPL011BaseAddressGuid, sizeof *UartHobData);\r
58 ASSERT (UartHobData != NULL);\r
59 *UartHobData = 0;\r
60\r
61 //\r
62 // Look for a UART node\r
63 //\r
64 for (Prev = 0;; Prev = Node) {\r
65 Node = fdt_next_node (Base, Prev, NULL);\r
66 if (Node < 0) {\r
67 break;\r
68 }\r
69\r
70 //\r
71 // Check for UART node\r
72 //\r
73 Compatible = fdt_getprop (Base, Node, "compatible", &Len);\r
74\r
75 //\r
76 // Iterate over the NULL-separated items in the compatible string\r
77 //\r
78 for (CompItem = Compatible; CompItem != NULL && CompItem < Compatible + Len;\r
79 CompItem += 1 + AsciiStrLen (CompItem)) {\r
80\r
81 if (AsciiStrCmp (CompItem, "arm,pl011") == 0) {\r
83ae7589
AB
82 NodeStatus = fdt_getprop (Base, Node, "status", &StatusLen);\r
83 if (NodeStatus != NULL && AsciiStrCmp (NodeStatus, "okay") != 0) {\r
84 continue;\r
85 }\r
86\r
337d450e
AB
87 RegProp = fdt_getprop (Base, Node, "reg", &Len);\r
88 ASSERT (Len == 16);\r
89\r
90 UartBase = fdt64_to_cpu (ReadUnaligned64 (RegProp));\r
91\r
92 DEBUG ((EFI_D_INFO, "%a: PL011 UART @ 0x%lx\n", __FUNCTION__, UartBase));\r
93\r
94 *UartHobData = UartBase;\r
95 break;\r
96 }\r
97 }\r
98 }\r
99\r
bb5420bb 100 BuildFvHob (PcdGet64 (PcdFvBaseAddress), PcdGet32 (PcdFvSize));\r
433b31dd
AB
101\r
102 return EFI_SUCCESS;\r
103}\r