• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /** @file
2 
3   Copyright (c) 2014-2015, ARM Ltd. All rights reserved.
4 
5   This program and the accompanying materials are licensed and made available
6   under the terms and conditions of the BSD License which accompanies this
7   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, WITHOUT
11   WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 
13 **/
14 
15 #include "ArmVExpressInternal.h"
16 #include <Library/ArmGicLib.h>
17 
18 //
19 // Description of the AARCH64 model platforms :
20 // Platform ids are defined in ArmVExpressInternal.h for
21 // all "ArmVExpress-like" platforms (AARCH64 or ARM architecture,
22 // model or hardware platforms).
23 //
24 CONST ARM_VEXPRESS_PLATFORM ArmVExpressPlatforms[] = {
25   { ARM_FVP_VEXPRESS_AEMv8x4,                  FixedPcdGetPtr (PcdFdtFvpVExpressAEMv8x4),        L"rtsm_ve-aemv8a.dtb"                  },
26   { ARM_FVP_BASE_AEMv8x4_AEMv8x4_GICV2,        FixedPcdGetPtr (PcdFdtFvpBaseAEMv8x4GicV2),       L"fvp-base-gicv2-psci.dtb"             },
27   { ARM_FVP_BASE_AEMv8x4_AEMv8x4_GICV2_LEGACY, FixedPcdGetPtr (PcdFdtFvpBaseAEMv8x4GicV2Legacy), L"fvp-base-gicv2legacy-psci.dtb"       },
28   { ARM_FVP_BASE_AEMv8x4_AEMv8x4_GICV3,        FixedPcdGetPtr (PcdFdtFvpBaseAEMv8x4GicV3),       L"fvp-base-gicv3-psci.dtb"             },
29   { ARM_FVP_FOUNDATION_GICV2,                  FixedPcdGetPtr (PcdFdtFvpFoundationGicV2),        L"fvp-foundation-gicv2-psci.dtb"       },
30   { ARM_FVP_FOUNDATION_GICV2_LEGACY,           FixedPcdGetPtr (PcdFdtFvpFoundationGicV2Legacy),  L"fvp-foundation-gicv2legacy-psci.dtb" },
31   { ARM_FVP_FOUNDATION_GICV3,                  FixedPcdGetPtr (PcdFdtFvpFoundationGicV3),        L"fvp-foundation-gicv3-psci.dtb"       },
32   { ARM_FVP_VEXPRESS_UNKNOWN }
33 };
34 
35 /**
36   Get information about the VExpress platform the firmware is running on.
37 
38   @param[out]  Platform   Address where the pointer to the platform information
39                           (type ARM_VEXPRESS_PLATFORM*) should be stored.
40                           The returned pointer does not point to an allocated
41                           memory area.
42 
43   @retval  EFI_SUCCESS    The platform information was returned.
44   @retval  EFI_NOT_FOUND  The platform was not recognised.
45 
46 **/
47 EFI_STATUS
ArmVExpressGetPlatform(OUT CONST ARM_VEXPRESS_PLATFORM ** Platform)48 ArmVExpressGetPlatform (
49   OUT CONST ARM_VEXPRESS_PLATFORM** Platform
50   )
51 {
52   EFI_STATUS            Status;
53   UINT32                SysId;
54   UINT32                FvpSysId;
55   UINT32                VariantSysId;
56   ARM_GIC_ARCH_REVISION GicRevision;
57 
58   ASSERT (Platform != NULL);
59 
60   Status = EFI_NOT_FOUND;
61 
62   SysId = MmioRead32 (ARM_VE_SYS_ID_REG);
63   if (SysId != ARM_RTSM_SYS_ID) {
64     // Remove the GIC variant to identify if we are running on the FVP Base or
65     // Foundation models
66     FvpSysId     = SysId & (ARM_FVP_SYS_ID_HBI_MASK |
67                             ARM_FVP_SYS_ID_PLAT_MASK );
68     // Extract the variant from the SysId
69     VariantSysId = SysId & ARM_FVP_SYS_ID_VARIANT_MASK;
70 
71     if (FvpSysId == ARM_FVP_BASE_BOARD_SYS_ID) {
72       if (VariantSysId == ARM_FVP_GIC_VE_MMAP) {
73         // FVP Base Model with legacy GIC memory map
74         Status = ArmVExpressGetPlatformFromId (ARM_FVP_BASE_AEMv8x4_AEMv8x4_GICV2_LEGACY, Platform);
75       } else {
76         GicRevision = ArmGicGetSupportedArchRevision ();
77 
78         if (GicRevision == ARM_GIC_ARCH_REVISION_2) {
79           // FVP Base Model with GICv2 support
80           Status = ArmVExpressGetPlatformFromId (ARM_FVP_BASE_AEMv8x4_AEMv8x4_GICV2, Platform);
81         } else {
82           // FVP Base Model with GICv3 support
83           Status = ArmVExpressGetPlatformFromId (ARM_FVP_BASE_AEMv8x4_AEMv8x4_GICV3, Platform);
84         }
85       }
86     } else if (FvpSysId == ARM_FVP_FOUNDATION_BOARD_SYS_ID) {
87       if (VariantSysId == ARM_FVP_GIC_VE_MMAP) {
88         // FVP Foundation Model with legacy GIC memory map
89         Status = ArmVExpressGetPlatformFromId (ARM_FVP_FOUNDATION_GICV2_LEGACY, Platform);
90       } else {
91         GicRevision = ArmGicGetSupportedArchRevision ();
92 
93         if (GicRevision == ARM_GIC_ARCH_REVISION_2) {
94           // FVP Foundation Model with GICv2
95           Status = ArmVExpressGetPlatformFromId (ARM_FVP_FOUNDATION_GICV2, Platform);
96         } else {
97           // FVP Foundation Model with GICv3
98           Status = ArmVExpressGetPlatformFromId (ARM_FVP_FOUNDATION_GICV3, Platform);
99         }
100       }
101     }
102   } else {
103     // FVP Versatile Express AEMv8
104     Status = ArmVExpressGetPlatformFromId (ARM_FVP_VEXPRESS_AEMv8x4, Platform);
105   }
106 
107   if (EFI_ERROR (Status)) {
108     DEBUG ((EFI_D_ERROR, "Unsupported AArch64 RTSM (SysId:0x%X).\n", SysId));
109     ASSERT_EFI_ERROR (Status);
110   }
111 
112   return Status;
113 }
114