3 * Copyright (c) 2013-2014, ARM Limited. All rights reserved.
5 * This program and the accompanying materials
6 * are licensed and made available under the terms and conditions of the BSD License
7 * which accompanies this distribution. The full text of the license may be found at
8 * http://opensource.org/licenses/bsd-license.php
10 * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "ArmJunoDxeInternal.h"
16 #include <Library/ArmShellCmdLib.h>
21 IN EFI_HANDLE ImageHandle
,
22 IN EFI_SYSTEM_TABLE
*SystemTable
26 EFI_PHYSICAL_ADDRESS HypBase
;
28 Status
= PciEmulationEntryPoint ();
29 if (EFI_ERROR (Status
)) {
34 // If a hypervisor has been declared then we need to make sure its region is protected at runtime
36 // Note: This code is only a workaround for our dummy hypervisor (ArmPkg/Extra/AArch64ToAArch32Shim/)
37 // that does not set up (yet) the stage 2 translation table to hide its own memory to EL1.
39 if (FixedPcdGet32 (PcdHypFvSize
) != 0) {
40 // Ensure the hypervisor region is strictly contained into a EFI_PAGE_SIZE-aligned region.
41 // The memory must be a multiple of EFI_PAGE_SIZE to ensure we do not reserve more memory than the hypervisor itself.
42 // A UEFI Runtime region size granularity cannot be smaller than EFI_PAGE_SIZE. If the hypervisor size is not rounded
43 // to this size then there is a risk some non-runtime memory could be visible to the OS view.
44 if (((FixedPcdGet32 (PcdHypFvSize
) & EFI_PAGE_MASK
) == 0) && ((FixedPcdGet32 (PcdHypFvBaseAddress
) & EFI_PAGE_MASK
) == 0)) {
45 // The memory needs to be declared because the DXE core marked it as reserved and removed it from the memory space
46 // as it contains the Firmware.
47 Status
= gDS
->AddMemorySpace (
48 EfiGcdMemoryTypeSystemMemory
,
49 FixedPcdGet32 (PcdHypFvBaseAddress
), FixedPcdGet32 (PcdHypFvSize
),
50 EFI_MEMORY_WB
| EFI_MEMORY_RUNTIME
52 if (!EFI_ERROR (Status
)) {
53 // We allocate the memory to ensure it is marked as runtime memory
54 HypBase
= FixedPcdGet32 (PcdHypFvBaseAddress
);
55 Status
= gBS
->AllocatePages (AllocateAddress
, EfiRuntimeServicesCode
,
56 EFI_SIZE_TO_PAGES (FixedPcdGet32 (PcdHypFvSize
)), &HypBase
);
59 // The hypervisor must be contained into a EFI_PAGE_SIZE-aligned region and its size must also be aligned
60 // on a EFI_PAGE_SIZE boundary (ie: 4KB).
61 Status
= EFI_UNSUPPORTED
;
62 ASSERT_EFI_ERROR (Status
);
65 if (EFI_ERROR (Status
)) {
70 // Install dynamic Shell command to run baremetal binaries.
71 Status
= ShellDynCmdRunAxfInstall (ImageHandle
);
72 if (EFI_ERROR (Status
)) {
73 DEBUG ((EFI_D_ERROR
, "ArmJunoDxe: Failed to install ShellDynCmdRunAxf\n"));
76 // Try to install the Flat Device Tree (FDT). This function actually installs the
77 // UEFI Driver Binding Protocol.
78 Status
= JunoFdtInstall (ImageHandle
);