]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPlatformPkg/ArmJunoPkg/Drivers/ArmJunoDxe/ArmJunoDxe.c
ArmPlatformPkg/ArmJunoPkg: Update with Juno R1 device tree names
[mirror_edk2.git] / ArmPlatformPkg / ArmJunoPkg / Drivers / ArmJunoDxe / ArmJunoDxe.c
1 /** @file
2 *
3 * Copyright (c) 2013-2015, ARM Limited. All rights reserved.
4 *
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
9 *
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.
12 *
13 **/
14
15 #include "ArmJunoDxeInternal.h"
16 #include <Library/ArmShellCmdLib.h>
17 #include <Library/AcpiLib.h>
18
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 } };
21
22 EFI_STATUS
23 EFIAPI
24 ArmJunoEntryPoint (
25 IN EFI_HANDLE ImageHandle,
26 IN EFI_SYSTEM_TABLE *SystemTable
27 )
28 {
29 EFI_STATUS Status;
30 EFI_PHYSICAL_ADDRESS HypBase;
31 CHAR16 *TextDevicePath;
32 UINTN TextDevicePathSize;
33 VOID *Buffer;
34 UINT32 Midr;
35 UINT32 CpuType;
36 UINT32 CpuRev;
37
38 Status = PciEmulationEntryPoint ();
39 if (EFI_ERROR (Status)) {
40 return Status;
41 }
42
43 //
44 // If a hypervisor has been declared then we need to make sure its region is protected at runtime
45 //
46 // Note: This code is only a workaround for our dummy hypervisor (ArmPkg/Extra/AArch64ToAArch32Shim/)
47 // that does not set up (yet) the stage 2 translation table to hide its own memory to EL1.
48 //
49 if (FixedPcdGet32 (PcdHypFvSize) != 0) {
50 // Ensure the hypervisor region is strictly contained into a EFI_PAGE_SIZE-aligned region.
51 // The memory must be a multiple of EFI_PAGE_SIZE to ensure we do not reserve more memory than the hypervisor itself.
52 // A UEFI Runtime region size granularity cannot be smaller than EFI_PAGE_SIZE. If the hypervisor size is not rounded
53 // to this size then there is a risk some non-runtime memory could be visible to the OS view.
54 if (((FixedPcdGet32 (PcdHypFvSize) & EFI_PAGE_MASK) == 0) && ((FixedPcdGet32 (PcdHypFvBaseAddress) & EFI_PAGE_MASK) == 0)) {
55 // The memory needs to be declared because the DXE core marked it as reserved and removed it from the memory space
56 // as it contains the Firmware.
57 Status = gDS->AddMemorySpace (
58 EfiGcdMemoryTypeSystemMemory,
59 FixedPcdGet32 (PcdHypFvBaseAddress), FixedPcdGet32 (PcdHypFvSize),
60 EFI_MEMORY_WB | EFI_MEMORY_RUNTIME
61 );
62 if (!EFI_ERROR (Status)) {
63 // We allocate the memory to ensure it is marked as runtime memory
64 HypBase = FixedPcdGet32 (PcdHypFvBaseAddress);
65 Status = gBS->AllocatePages (AllocateAddress, EfiRuntimeServicesCode,
66 EFI_SIZE_TO_PAGES (FixedPcdGet32 (PcdHypFvSize)), &HypBase);
67 }
68 } else {
69 // The hypervisor must be contained into a EFI_PAGE_SIZE-aligned region and its size must also be aligned
70 // on a EFI_PAGE_SIZE boundary (ie: 4KB).
71 Status = EFI_UNSUPPORTED;
72 ASSERT_EFI_ERROR (Status);
73 }
74
75 if (EFI_ERROR (Status)) {
76 return Status;
77 }
78 }
79
80 // Install dynamic Shell command to run baremetal binaries.
81 Status = ShellDynCmdRunAxfInstall (ImageHandle);
82 if (EFI_ERROR (Status)) {
83 DEBUG ((EFI_D_ERROR, "ArmJunoDxe: Failed to install ShellDynCmdRunAxf\n"));
84 }
85
86 //
87 // Set up the device path to the FDT.
88 // We detect whether we are running on a Juno r0 or Juno r1 board at
89 // runtime by checking the value of the MIDR register.
90 //
91
92 Midr = ArmReadMidr ();
93 CpuType = (Midr >> ARM_CPU_TYPE_SHIFT) & ARM_CPU_TYPE_MASK;
94 CpuRev = Midr & ARM_CPU_REV_MASK;
95 TextDevicePath = NULL;
96
97 switch (CpuType) {
98 case ARM_CPU_TYPE_A53:
99 if (CpuRev == ARM_CPU_REV (0, 0)) {
100 TextDevicePath = (CHAR16*)FixedPcdGetPtr (PcdJunoR0FdtDevicePath);
101 } else if (CpuRev == ARM_CPU_REV (0, 3)) {
102 TextDevicePath = (CHAR16*)FixedPcdGetPtr (PcdJunoR1A57x2FdtDevicePath);
103 }
104 break;
105
106 case ARM_CPU_TYPE_A57:
107 if (CpuRev == ARM_CPU_REV (0, 0)) {
108 TextDevicePath = (CHAR16*)FixedPcdGetPtr (PcdJunoR0FdtDevicePath);
109 } else if (CpuRev == ARM_CPU_REV (1, 1)) {
110 TextDevicePath = (CHAR16*)FixedPcdGetPtr (PcdJunoR1A57x2FdtDevicePath);
111 }
112 }
113
114 if (TextDevicePath != NULL) {
115 TextDevicePathSize = StrSize (TextDevicePath);
116 Buffer = PcdSetPtr (PcdFdtDevicePaths, &TextDevicePathSize, TextDevicePath);
117 Status = (Buffer != NULL) ? EFI_SUCCESS : EFI_BUFFER_TOO_SMALL;
118 } else {
119 Status = EFI_NOT_FOUND;
120 }
121
122 if (EFI_ERROR (Status)) {
123 DEBUG (
124 (EFI_D_ERROR,
125 "ArmJunoDxe: Setting of FDT device path in PcdFdtDevicePaths failed - %r\n", Status)
126 );
127 return Status;
128 }
129
130 // Try to install the ACPI Tables
131 Status = LocateAndInstallAcpiFromFv (&mJunoAcpiTableFile);
132
133 return Status;
134 }