3 * Copyright (c) 2013-2015, 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>
17 #include <Library/AcpiLib.h>
19 // This GUID must match the FILE_GUID in ArmPlatformPkg/ArmJunoPkg/AcpiTables/AcpiTables.inf
20 STATIC CONST EFI_GUID mJunoAcpiTableFile
= { 0xa1dd808e, 0x1e95, 0x4399, { 0xab, 0xc0, 0x65, 0x3c, 0x82, 0xe8, 0x53, 0x0c } };
25 IN EFI_HANDLE ImageHandle
,
26 IN EFI_SYSTEM_TABLE
*SystemTable
30 EFI_PHYSICAL_ADDRESS HypBase
;
32 Status
= PciEmulationEntryPoint ();
33 if (EFI_ERROR (Status
)) {
38 // If a hypervisor has been declared then we need to make sure its region is protected at runtime
40 // Note: This code is only a workaround for our dummy hypervisor (ArmPkg/Extra/AArch64ToAArch32Shim/)
41 // that does not set up (yet) the stage 2 translation table to hide its own memory to EL1.
43 if (FixedPcdGet32 (PcdHypFvSize
) != 0) {
44 // Ensure the hypervisor region is strictly contained into a EFI_PAGE_SIZE-aligned region.
45 // The memory must be a multiple of EFI_PAGE_SIZE to ensure we do not reserve more memory than the hypervisor itself.
46 // A UEFI Runtime region size granularity cannot be smaller than EFI_PAGE_SIZE. If the hypervisor size is not rounded
47 // to this size then there is a risk some non-runtime memory could be visible to the OS view.
48 if (((FixedPcdGet32 (PcdHypFvSize
) & EFI_PAGE_MASK
) == 0) && ((FixedPcdGet32 (PcdHypFvBaseAddress
) & EFI_PAGE_MASK
) == 0)) {
49 // The memory needs to be declared because the DXE core marked it as reserved and removed it from the memory space
50 // as it contains the Firmware.
51 Status
= gDS
->AddMemorySpace (
52 EfiGcdMemoryTypeSystemMemory
,
53 FixedPcdGet32 (PcdHypFvBaseAddress
), FixedPcdGet32 (PcdHypFvSize
),
54 EFI_MEMORY_WB
| EFI_MEMORY_RUNTIME
56 if (!EFI_ERROR (Status
)) {
57 // We allocate the memory to ensure it is marked as runtime memory
58 HypBase
= FixedPcdGet32 (PcdHypFvBaseAddress
);
59 Status
= gBS
->AllocatePages (AllocateAddress
, EfiRuntimeServicesCode
,
60 EFI_SIZE_TO_PAGES (FixedPcdGet32 (PcdHypFvSize
)), &HypBase
);
63 // The hypervisor must be contained into a EFI_PAGE_SIZE-aligned region and its size must also be aligned
64 // on a EFI_PAGE_SIZE boundary (ie: 4KB).
65 Status
= EFI_UNSUPPORTED
;
66 ASSERT_EFI_ERROR (Status
);
69 if (EFI_ERROR (Status
)) {
74 // Install dynamic Shell command to run baremetal binaries.
75 Status
= ShellDynCmdRunAxfInstall (ImageHandle
);
76 if (EFI_ERROR (Status
)) {
77 DEBUG ((EFI_D_ERROR
, "ArmJunoDxe: Failed to install ShellDynCmdRunAxf\n"));
80 // Try to install the ACPI Tables
81 Status
= LocateAndInstallAcpiFromFv (&mJunoAcpiTableFile
);
82 if (EFI_ERROR (Status
)) {