]> git.proxmox.com Git - mirror_edk2.git/blame - ArmVirtPkg/Library/PlatformPeiLib/PlatformPeiLib.c
SecurityPkg OpalPasswordDxe: Move OPAL request variable definition
[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
6* This program and the accompanying materials\r
7* are licensed and made available under the terms and conditions of the BSD License\r
8* which accompanies this distribution. The full text of the license may be found at\r
9* http://opensource.org/licenses/bsd-license.php\r
10*\r
11* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13*\r
14**/\r
15\r
16#include <PiPei.h>\r
17\r
18#include <Library/MemoryAllocationLib.h>\r
19#include <Library/DebugLib.h>\r
20#include <Library/HobLib.h>\r
21#include <Library/PcdLib.h>\r
22#include <libfdt.h>\r
23\r
337d450e 24#include <Guid/EarlyPL011BaseAddress.h>\r
cc667df0 25#include <Guid/FdtHob.h>\r
337d450e 26\r
433b31dd
AB
27EFI_STATUS\r
28EFIAPI\r
29PlatformPeim (\r
30 VOID\r
31 )\r
32{\r
33 VOID *Base;\r
34 VOID *NewBase;\r
35 UINTN FdtSize;\r
616ea9da 36 UINTN FdtPages;\r
cc667df0 37 UINT64 *FdtHobData;\r
337d450e
AB
38 UINT64 *UartHobData;\r
39 INT32 Node, Prev;\r
40 CONST CHAR8 *Compatible;\r
41 CONST CHAR8 *CompItem;\r
83ae7589 42 CONST CHAR8 *NodeStatus;\r
337d450e 43 INT32 Len;\r
83ae7589 44 INT32 StatusLen;\r
337d450e
AB
45 CONST UINT64 *RegProp;\r
46 UINT64 UartBase;\r
47\r
433b31dd 48\r
cc667df0
AB
49 Base = (VOID*)(UINTN)PcdGet64 (PcdDeviceTreeInitialBaseAddress);\r
50 ASSERT (Base != NULL);\r
433b31dd
AB
51 ASSERT (fdt_check_header (Base) == 0);\r
52\r
616ea9da
AB
53 FdtSize = fdt_totalsize (Base) + PcdGet32 (PcdDeviceTreeAllocationPadding);\r
54 FdtPages = EFI_SIZE_TO_PAGES (FdtSize);\r
55 NewBase = AllocatePages (FdtPages);\r
433b31dd 56 ASSERT (NewBase != NULL);\r
616ea9da 57 fdt_open_into (Base, NewBase, EFI_PAGES_TO_SIZE (FdtPages));\r
cc667df0
AB
58\r
59 FdtHobData = BuildGuidHob (&gFdtHobGuid, sizeof *FdtHobData);\r
60 ASSERT (FdtHobData != NULL);\r
61 *FdtHobData = (UINTN)NewBase;\r
433b31dd 62\r
337d450e
AB
63 UartHobData = BuildGuidHob (&gEarlyPL011BaseAddressGuid, sizeof *UartHobData);\r
64 ASSERT (UartHobData != NULL);\r
65 *UartHobData = 0;\r
66\r
67 //\r
68 // Look for a UART node\r
69 //\r
70 for (Prev = 0;; Prev = Node) {\r
71 Node = fdt_next_node (Base, Prev, NULL);\r
72 if (Node < 0) {\r
73 break;\r
74 }\r
75\r
76 //\r
77 // Check for UART node\r
78 //\r
79 Compatible = fdt_getprop (Base, Node, "compatible", &Len);\r
80\r
81 //\r
82 // Iterate over the NULL-separated items in the compatible string\r
83 //\r
84 for (CompItem = Compatible; CompItem != NULL && CompItem < Compatible + Len;\r
85 CompItem += 1 + AsciiStrLen (CompItem)) {\r
86\r
87 if (AsciiStrCmp (CompItem, "arm,pl011") == 0) {\r
83ae7589
AB
88 NodeStatus = fdt_getprop (Base, Node, "status", &StatusLen);\r
89 if (NodeStatus != NULL && AsciiStrCmp (NodeStatus, "okay") != 0) {\r
90 continue;\r
91 }\r
92\r
337d450e
AB
93 RegProp = fdt_getprop (Base, Node, "reg", &Len);\r
94 ASSERT (Len == 16);\r
95\r
96 UartBase = fdt64_to_cpu (ReadUnaligned64 (RegProp));\r
97\r
98 DEBUG ((EFI_D_INFO, "%a: PL011 UART @ 0x%lx\n", __FUNCTION__, UartBase));\r
99\r
100 *UartHobData = UartBase;\r
101 break;\r
102 }\r
103 }\r
104 }\r
105\r
bb5420bb 106 BuildFvHob (PcdGet64 (PcdFvBaseAddress), PcdGet32 (PcdFvSize));\r
433b31dd
AB
107\r
108 return EFI_SUCCESS;\r
109}\r