]> git.proxmox.com Git - mirror_edk2.git/blame - ArmVirtPkg/Library/PlatformPeiLib/PlatformPeiLib.c
ArmVirtPkg/PlatformBootManagerLib: use EfiBootManagerUpdateConsoleVariable
[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
42 INT32 Len;\r
43 CONST UINT64 *RegProp;\r
44 UINT64 UartBase;\r
45\r
433b31dd 46\r
cc667df0
AB
47 Base = (VOID*)(UINTN)PcdGet64 (PcdDeviceTreeInitialBaseAddress);\r
48 ASSERT (Base != NULL);\r
433b31dd
AB
49 ASSERT (fdt_check_header (Base) == 0);\r
50\r
616ea9da
AB
51 FdtSize = fdt_totalsize (Base) + PcdGet32 (PcdDeviceTreeAllocationPadding);\r
52 FdtPages = EFI_SIZE_TO_PAGES (FdtSize);\r
53 NewBase = AllocatePages (FdtPages);\r
433b31dd 54 ASSERT (NewBase != NULL);\r
616ea9da 55 fdt_open_into (Base, NewBase, EFI_PAGES_TO_SIZE (FdtPages));\r
cc667df0
AB
56\r
57 FdtHobData = BuildGuidHob (&gFdtHobGuid, sizeof *FdtHobData);\r
58 ASSERT (FdtHobData != NULL);\r
59 *FdtHobData = (UINTN)NewBase;\r
433b31dd 60\r
337d450e
AB
61 UartHobData = BuildGuidHob (&gEarlyPL011BaseAddressGuid, sizeof *UartHobData);\r
62 ASSERT (UartHobData != NULL);\r
63 *UartHobData = 0;\r
64\r
65 //\r
66 // Look for a UART node\r
67 //\r
68 for (Prev = 0;; Prev = Node) {\r
69 Node = fdt_next_node (Base, Prev, NULL);\r
70 if (Node < 0) {\r
71 break;\r
72 }\r
73\r
74 //\r
75 // Check for UART node\r
76 //\r
77 Compatible = fdt_getprop (Base, Node, "compatible", &Len);\r
78\r
79 //\r
80 // Iterate over the NULL-separated items in the compatible string\r
81 //\r
82 for (CompItem = Compatible; CompItem != NULL && CompItem < Compatible + Len;\r
83 CompItem += 1 + AsciiStrLen (CompItem)) {\r
84\r
85 if (AsciiStrCmp (CompItem, "arm,pl011") == 0) {\r
86 RegProp = fdt_getprop (Base, Node, "reg", &Len);\r
87 ASSERT (Len == 16);\r
88\r
89 UartBase = fdt64_to_cpu (ReadUnaligned64 (RegProp));\r
90\r
91 DEBUG ((EFI_D_INFO, "%a: PL011 UART @ 0x%lx\n", __FUNCTION__, UartBase));\r
92\r
93 *UartHobData = UartBase;\r
94 break;\r
95 }\r
96 }\r
97 }\r
98\r
bb5420bb 99 BuildFvHob (PcdGet64 (PcdFvBaseAddress), PcdGet32 (PcdFvSize));\r
433b31dd
AB
100\r
101 return EFI_SUCCESS;\r
102}\r