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 <ArmPlatform.h>
18 #include <Protocol/DevicePathFromText.h>
19 #include <Protocol/PciRootBridgeIo.h>
21 #include <Guid/EventGroup.h>
22 #include <Guid/GlobalVariable.h>
24 #include <Library/ArmShellCmdLib.h>
25 #include <Library/AcpiLib.h>
26 #include <Library/BaseMemoryLib.h>
27 #include <Library/DevicePathLib.h>
28 #include <Library/MemoryAllocationLib.h>
29 #include <Library/UefiRuntimeServicesTableLib.h>
30 #include <Library/IoLib.h>
31 #include <Library/PrintLib.h>
34 // This GUID must match the FILE_GUID in ArmPlatformPkg/ArmJunoPkg/AcpiTables/AcpiTables.inf
35 STATIC CONST EFI_GUID mJunoAcpiTableFile
= { 0xa1dd808e, 0x1e95, 0x4399, { 0xab, 0xc0, 0x65, 0x3c, 0x82, 0xe8, 0x53, 0x0c } };
38 ACPI_HID_DEVICE_PATH AcpiDevicePath
;
39 PCI_DEVICE_PATH PciDevicePath
;
40 EFI_DEVICE_PATH_PROTOCOL EndDevicePath
;
41 } EFI_PCI_ROOT_BRIDGE_DEVICE_PATH
;
43 STATIC CONST EFI_PCI_ROOT_BRIDGE_DEVICE_PATH mPciRootComplexDevicePath
= {
47 { (UINT8
) (sizeof (ACPI_HID_DEVICE_PATH
)),
48 (UINT8
) ((sizeof (ACPI_HID_DEVICE_PATH
)) >> 8) }
54 { HARDWARE_DEVICE_PATH
,
56 { (UINT8
) (sizeof (PCI_DEVICE_PATH
)),
57 (UINT8
) ((sizeof (PCI_DEVICE_PATH
)) >> 8) }
64 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
65 { END_DEVICE_PATH_LENGTH
, 0 }
69 EFI_EVENT mAcpiRegistration
= NULL
;
72 Notification function of the event defined as belonging to the
73 EFI_END_OF_DXE_EVENT_GROUP_GUID event group that was created in
74 the entry point of the driver.
76 This function is called when an event belonging to the
77 EFI_END_OF_DXE_EVENT_GROUP_GUID event group is signalled. Such an
78 event is signalled once at the end of the dispatching of all
79 drivers (end of the so called DXE phase).
81 @param[in] Event Event declared in the entry point of the driver whose
82 notification function is being invoked.
83 @param[in] Context NULL
92 EFI_DEVICE_PATH_PROTOCOL
* PciRootComplexDevicePath
;
97 // PCI Root Complex initialization
98 // At the end of the DXE phase, we should get all the driver dispatched.
99 // Force the PCI Root Complex to be initialized. It allows the OS to skip
102 PciRootComplexDevicePath
= (EFI_DEVICE_PATH_PROTOCOL
*) &mPciRootComplexDevicePath
;
103 Status
= gBS
->LocateDevicePath (&gEfiPciRootBridgeIoProtocolGuid
,
104 &PciRootComplexDevicePath
,
107 Status
= gBS
->ConnectController (Handle
, NULL
, PciRootComplexDevicePath
, FALSE
);
108 ASSERT_EFI_ERROR (Status
);
113 AcpiTableJunoR0Check (
114 IN EFI_ACPI_DESCRIPTION_HEADER
*AcpiHeader
122 AcpiTableJunoR1Check (
123 IN EFI_ACPI_DESCRIPTION_HEADER
*AcpiHeader
131 AcpiTableJunoR2Check (
132 IN EFI_ACPI_DESCRIPTION_HEADER
*AcpiHeader
142 IN EFI_HANDLE ImageHandle
,
143 IN EFI_SYSTEM_TABLE
*SystemTable
147 EFI_PHYSICAL_ADDRESS HypBase
;
148 CHAR16
*TextDevicePath
;
149 UINTN TextDevicePathSize
;
152 EFI_EVENT EndOfDxeEvent
;
154 Status
= PciEmulationEntryPoint ();
155 if (EFI_ERROR (Status
)) {
160 // If a hypervisor has been declared then we need to make sure its region is protected at runtime
162 // Note: This code is only a workaround for our dummy hypervisor (ArmPkg/Extra/AArch64ToAArch32Shim/)
163 // that does not set up (yet) the stage 2 translation table to hide its own memory to EL1.
165 if (FixedPcdGet32 (PcdHypFvSize
) != 0) {
166 // Ensure the hypervisor region is strictly contained into a EFI_PAGE_SIZE-aligned region.
167 // The memory must be a multiple of EFI_PAGE_SIZE to ensure we do not reserve more memory than the hypervisor itself.
168 // A UEFI Runtime region size granularity cannot be smaller than EFI_PAGE_SIZE. If the hypervisor size is not rounded
169 // to this size then there is a risk some non-runtime memory could be visible to the OS view.
170 if (((FixedPcdGet32 (PcdHypFvSize
) & EFI_PAGE_MASK
) == 0) && ((FixedPcdGet32 (PcdHypFvBaseAddress
) & EFI_PAGE_MASK
) == 0)) {
171 // The memory needs to be declared because the DXE core marked it as reserved and removed it from the memory space
172 // as it contains the Firmware.
173 Status
= gDS
->AddMemorySpace (
174 EfiGcdMemoryTypeSystemMemory
,
175 FixedPcdGet32 (PcdHypFvBaseAddress
), FixedPcdGet32 (PcdHypFvSize
),
176 EFI_MEMORY_WB
| EFI_MEMORY_RUNTIME
178 if (!EFI_ERROR (Status
)) {
179 // We allocate the memory to ensure it is marked as runtime memory
180 HypBase
= FixedPcdGet32 (PcdHypFvBaseAddress
);
181 Status
= gBS
->AllocatePages (AllocateAddress
, EfiRuntimeServicesCode
,
182 EFI_SIZE_TO_PAGES (FixedPcdGet32 (PcdHypFvSize
)), &HypBase
);
185 // The hypervisor must be contained into a EFI_PAGE_SIZE-aligned region and its size must also be aligned
186 // on a EFI_PAGE_SIZE boundary (ie: 4KB).
187 Status
= EFI_UNSUPPORTED
;
188 ASSERT_EFI_ERROR (Status
);
191 if (EFI_ERROR (Status
)) {
197 // Create an event belonging to the "gEfiEndOfDxeEventGroupGuid" group.
198 // The "OnEndOfDxe()" function is declared as the call back function.
199 // It will be called at the end of the DXE phase when an event of the
200 // same group is signalled to inform about the end of the DXE phase.
201 // Install the INSTALL_FDT_PROTOCOL protocol.
203 Status
= gBS
->CreateEventEx (
208 &gEfiEndOfDxeEventGroupGuid
,
212 // Install dynamic Shell command to run baremetal binaries.
213 Status
= ShellDynCmdRunAxfInstall (ImageHandle
);
214 if (EFI_ERROR (Status
)) {
215 DEBUG ((EFI_D_ERROR
, "ArmJunoDxe: Failed to install ShellDynCmdRunAxf\n"));
218 GetJunoRevision(JunoRevision
);
221 // Try to install the ACPI Tables
223 if (JunoRevision
== JUNO_REVISION_R0
) {
224 Status
= LocateAndInstallAcpiFromFvConditional (&mJunoAcpiTableFile
, AcpiTableJunoR0Check
);
225 } else if (JunoRevision
== JUNO_REVISION_R1
) {
226 Status
= LocateAndInstallAcpiFromFvConditional (&mJunoAcpiTableFile
, AcpiTableJunoR1Check
);
227 } else if (JunoRevision
== JUNO_REVISION_R2
) {
228 Status
= LocateAndInstallAcpiFromFvConditional (&mJunoAcpiTableFile
, AcpiTableJunoR2Check
);
231 ASSERT_EFI_ERROR (Status
);
234 // Setup R1/R2 options if not already done.
236 if (JunoRevision
!= JUNO_REVISION_R0
) {
237 // Enable PCI enumeration
238 PcdSetBool (PcdPciDisableBusEnumeration
, FALSE
);
240 // Declare the related ACPI Tables
241 EfiCreateProtocolNotifyEvent (
242 &gEfiAcpiTableProtocolGuid
,
244 AcpiPciNotificationEvent
,
251 // Set up the device path to the FDT.
253 TextDevicePath
= (CHAR16
*)FixedPcdGetPtr (PcdJunoFdtDevicePath
);
254 if (TextDevicePath
!= NULL
) {
255 TextDevicePathSize
= StrSize (TextDevicePath
);
256 Buffer
= PcdSetPtr (PcdFdtDevicePaths
, &TextDevicePathSize
, TextDevicePath
);
257 Status
= (Buffer
!= NULL
) ? EFI_SUCCESS
: EFI_BUFFER_TOO_SMALL
;
259 Status
= EFI_NOT_FOUND
;
262 if (EFI_ERROR (Status
)) {
265 "ArmJunoDxe: Setting of FDT device path in PcdFdtDevicePaths failed - %r\n", Status
)