]> git.baikalelectronics.ru Git - arm-tf.git/commitdiff
feat(rme): set DRAM information in Boot Manifest platform data
authorAlexeiFedorov <Alexei.Fedorov@arm.com>
Wed, 14 Dec 2022 17:28:11 +0000 (17:28 +0000)
committerAlexeiFedorov <Alexei.Fedorov@arm.com>
Tue, 17 Jan 2023 16:35:41 +0000 (16:35 +0000)
This patch adds support for setting configuration of DRAM banks
for FVP model in RMM-EL3 Boot Manifest structure.
Structure 'rmm_manifest' is extended with 'plat_dram' structure
which contains information about platform's DRAM layout:
- number of DRAM banks;
- pointer to 'dram_bank[]' array;
- check sum: two's complement 64-bit value of the sum of
  data in 'plat_dram' and 'dram_bank[] array.
Each 'dram_bank' structure holds information about DRAM
bank base address and its size. This values must be aligned
to 4KB page size.
The patch increases Boot Manifest minor version to 2 and
removes 'typedef rmm_manifest_t' as per
"3.4.15.1. Avoid anonymous typedefs of structs/enums in headers" of
https://trustedfirmware-a.readthedocs.io/en/latest/process/coding-style.html

Signed-off-by: AlexeiFedorov <Alexei.Fedorov@arm.com>
Change-Id: I5176caa5780e27d1e0daeb5dea3e40cf6ad5fd12

include/plat/arm/common/arm_def.h
include/plat/common/platform.h
include/services/rmm_core_manifest.h
include/services/trp/platform_trp.h
plat/arm/board/fvp/fvp_common.c
plat/arm/common/arm_bl2_setup.c
plat/arm/common/arm_bl31_setup.c
plat/arm/common/trp/arm_trp_setup.c
services/std_svc/rmmd/rmmd_main.c
services/std_svc/rmmd/trp/trp_main.c

index 36b1bdb6d1b93e861508aad2bc9f1511227ea393..1e22c10735aeb19ec94e981f6a18fdb4cdec3a93 100644 (file)
 #define ARM_DRAM2_SIZE                 PLAT_ARM_DRAM2_SIZE
 #define ARM_DRAM2_END                  (ARM_DRAM2_BASE +               \
                                         ARM_DRAM2_SIZE - 1U)
+/* Number of DRAM banks */
+#define ARM_DRAM_BANKS_NUM             2UL
 
 #define ARM_IRQ_SEC_PHY_TIMER          29
 
index 3351036128ecc4da9ed30a958fe25771f14aa5d9..8543ac7130e5a3786851f5b11e4cf1073f09454a 100644 (file)
@@ -11,7 +11,7 @@
 
 #include <lib/psci/psci.h>
 #if defined(SPD_spmd)
- #include <services/spm_core_manifest.h>
+#include <services/spm_core_manifest.h>
 #endif
 #if ENABLE_RME
 #include <services/rmm_core_manifest.h>
@@ -37,6 +37,7 @@ struct bl_params;
 struct mmap_region;
 struct spm_mm_boot_info;
 struct sp_res_desc;
+struct rmm_manifest;
 enum fw_enc_status_t;
 
 /*******************************************************************************
@@ -322,7 +323,7 @@ int plat_rmmd_get_cca_attest_token(uintptr_t buf, size_t *len,
 int plat_rmmd_get_cca_realm_attest_key(uintptr_t buf, size_t *len,
                                       unsigned int type);
 size_t plat_rmmd_get_el3_rmm_shared_mem(uintptr_t *shared);
-int plat_rmmd_load_manifest(rmm_manifest_t *manifest);
+int plat_rmmd_load_manifest(struct rmm_manifest *manifest);
 #endif
 
 /*******************************************************************************
index 7edef469b166774413172448e87817eeeb162020..a59788392f084a754d58e3b2ffecb7cb5587a71c 100644 (file)
@@ -14,7 +14,7 @@
 #include <lib/cassert.h>
 
 #define RMMD_MANIFEST_VERSION_MAJOR            U(0)
-#define RMMD_MANIFEST_VERSION_MINOR            U(1)
+#define RMMD_MANIFEST_VERSION_MINOR            U(2)
 
 /*
  * Manifest version encoding:
 #define RMMD_GET_MANIFEST_VERSION_MINOR(_version)                      \
        (_version & 0xFFFF)
 
-/* Boot manifest core structure as per v0.1 */
-typedef struct rmm_manifest {
-       uint32_t version;       /* Manifest version */
-       uint32_t padding;       /* RES0 */
-       uintptr_t plat_data;    /* Manifest platform data */
-} rmm_manifest_t;
-
-CASSERT(offsetof(rmm_manifest_t, version) == 0,
-                               rmm_manifest_t_version_unaligned);
-CASSERT(offsetof(rmm_manifest_t, plat_data) == 8,
-                               rmm_manifest_t_plat_data_unaligned);
+/* DRAM bank structure */
+struct dram_bank {
+       uintptr_t base;                 /* Base address */
+       uint64_t size;                  /* Size of bank */
+};
+
+CASSERT(offsetof(struct dram_bank, base) == 0,
+                       rmm_manifest_base_unaligned);
+CASSERT(offsetof(struct dram_bank, size) == 8,
+                       rmm_manifest_size_unaligned);
+
+/* DRAM layout info structure */
+struct dram_info {
+       uint64_t banks_num;             /* Number of DRAM banks */
+       struct dram_bank *dram_data;    /* Pointer to dram_bank[] */
+       uint64_t check_sum;             /* Checksum of dram_info data */
+};
+
+CASSERT(offsetof(struct dram_info, banks_num) == 0,
+                       rmm_manifest_banks_num_unaligned);
+CASSERT(offsetof(struct dram_info, dram_data) == 8,
+                       rmm_manifest_dram_data_unaligned);
+CASSERT(offsetof(struct dram_info, check_sum) == 16,
+                       rmm_manifest_check_sum_unaligned);
+
+/* Boot manifest core structure as per v0.2 */
+struct rmm_manifest {
+       uint32_t version;               /* Manifest version */
+       uint32_t padding;               /* RES0 */
+       uintptr_t plat_data;            /* Manifest platform data */
+       struct dram_info plat_dram;     /* Platform DRAM data */
+};
+
+CASSERT(offsetof(struct rmm_manifest, version) == 0,
+                       rmm_manifest_version_unaligned);
+CASSERT(offsetof(struct rmm_manifest, plat_data) == 8,
+                       rmm_manifest_plat_data_unaligned);
+CASSERT(offsetof(struct rmm_manifest, plat_dram) == 16,
+                       rmm_manifest_plat_dram_unaligned);
 
 #endif /* RMM_CORE_MANIFEST_H */
index 1c963c851ecbea9ce3a19b9e39e44a2ab26c31a2..756e9db6c5ebe87355ed316d73e270c9e3ff0635 100644 (file)
@@ -9,9 +9,11 @@
 
 #include <services/rmm_core_manifest.h>
 
+struct rmm_manifest;
+
 /*******************************************************************************
  * Mandatory TRP functions (only if platform contains a TRP)
  ******************************************************************************/
-void trp_early_platform_setup(rmm_manifest_t *manifest);
+void trp_early_platform_setup(struct rmm_manifest *manifest);
 
 #endif /* PLATFORM_TRP_H */
index f5d9940f07264c10318233d526c2fbdaf1deba75..e6d5b159bf16b175828353b068a1b16fb85735d2 100644 (file)
 #include <lib/xlat_tables/xlat_tables_compat.h>
 #include <platform_def.h>
 #include <services/arm_arch_svc.h>
-#if ENABLE_RME
 #include <services/rmm_core_manifest.h>
-#endif
 #if SPM_MM
 #include <services/spm_mm_partition.h>
 #endif
 
 #include <plat/arm/common/arm_config.h>
+#include <plat/arm/common/arm_pas_def.h>
 #include <plat/arm/common/plat_arm.h>
 #include <plat/common/platform.h>
 
@@ -531,15 +530,46 @@ size_t plat_rmmd_get_el3_rmm_shared_mem(uintptr_t *shared)
        return (size_t)RMM_SHARED_SIZE;
 }
 
-int plat_rmmd_load_manifest(rmm_manifest_t *manifest)
+CASSERT(ARM_DRAM_BANKS_NUM == 2UL, ARM_DRAM_BANKS_NUM_mismatch);
+
+/* FVP DRAM banks */
+const struct dram_bank fvp_dram_banks[ARM_DRAM_BANKS_NUM] = {
+       {ARM_PAS_2_BASE, ARM_PAS_2_SIZE},
+       {ARM_PAS_4_BASE, ARM_PAS_4_SIZE}
+};
+
+int plat_rmmd_load_manifest(struct rmm_manifest *manifest)
 {
+       uint64_t check_sum;
+       struct dram_bank *bank_ptr;
+
        assert(manifest != NULL);
 
        manifest->version = RMMD_MANIFEST_VERSION;
        manifest->padding = 0U; /* RES0 */
        manifest->plat_data = (uintptr_t)NULL;
+       manifest->plat_dram.banks_num = ARM_DRAM_BANKS_NUM;
+
+       /* Array dram_banks[] follows dram_info structure */
+       bank_ptr = (struct dram_bank *)
+                       ((uintptr_t)&manifest->plat_dram.check_sum +
+                       sizeof(manifest->plat_dram.check_sum));
+
+       manifest->plat_dram.dram_data = bank_ptr;
+
+       /* Copy FVP DRAM banks data to Boot Manifest */
+       (void)memcpy((void *)bank_ptr, &fvp_dram_banks, sizeof(fvp_dram_banks));
+
+       /* Calculate check sum of plat_dram structure */
+       check_sum = ARM_DRAM_BANKS_NUM + (uint64_t)bank_ptr;
+
+       for (unsigned long i = 0UL; i < ARM_DRAM_BANKS_NUM; i++) {
+               check_sum += bank_ptr[i].base + bank_ptr[i].size;
+       }
+
+       /* Check sum must be 0 */
+       manifest->plat_dram.check_sum = ~check_sum + 1UL;
 
        return 0;
 }
-
-#endif
+#endif /* ENABLE_RME */
index 02e419a435e76cc351c3eed9dd0bc42493f61ee0..ca98422853ea99aab0912e7cdb75422f305adeb9 100644 (file)
 #include <drivers/partition/partition.h>
 #include <lib/fconf/fconf.h>
 #include <lib/fconf/fconf_dyn_cfg_getter.h>
-#if ENABLE_RME
 #include <lib/gpt_rme/gpt_rme.h>
-#endif /* ENABLE_RME */
 #ifdef SPD_opteed
 #include <lib/optee_utils.h>
 #endif
 #include <lib/utils.h>
-#if ENABLE_RME
 #include <plat/arm/common/arm_pas_def.h>
-#endif /* ENABLE_RME */
 #include <plat/arm/common/plat_arm.h>
 #include <plat/common/platform.h>
 
index cf403b161124f3114b6079ae5e0ee6d1d8278169..19efdd32e9d299efd99797b2923ea445ffc0e153 100644 (file)
@@ -13,9 +13,7 @@
 #include <drivers/console.h>
 #include <lib/debugfs.h>
 #include <lib/extensions/ras.h>
-#if ENABLE_RME
 #include <lib/gpt_rme/gpt_rme.h>
-#endif
 #include <lib/mmio.h>
 #include <lib/xlat_tables/xlat_tables_compat.h>
 #include <plat/arm/common/plat_arm.h>
index aeacd1054a397a9ec671e7853480617cd398ff20..04063219b796459344cf28e57779483b00510de3 100644 (file)
@@ -26,7 +26,7 @@ extern uint32_t trp_boot_manifest_version;
  ******************************************************************************/
 static console_t arm_trp_runtime_console;
 
-static int arm_trp_process_manifest(rmm_manifest_t *manifest)
+static int arm_trp_process_manifest(struct rmm_manifest *manifest)
 {
        /* padding field on the manifest must be RES0 */
        assert(manifest->padding == 0U);
@@ -38,12 +38,12 @@ static int arm_trp_process_manifest(rmm_manifest_t *manifest)
        }
 
        trp_boot_manifest_version = manifest->version;
-       flush_dcache_range((uintptr_t)manifest, sizeof(rmm_manifest_t));
+       flush_dcache_range((uintptr_t)manifest, sizeof(struct rmm_manifest));
 
        return 0;
 }
 
-void arm_trp_early_platform_setup(rmm_manifest_t *manifest)
+void arm_trp_early_platform_setup(struct rmm_manifest *manifest)
 {
        int rc;
 
@@ -66,10 +66,9 @@ void arm_trp_early_platform_setup(rmm_manifest_t *manifest)
 
        console_set_scope(&arm_trp_runtime_console,
                          CONSOLE_FLAG_BOOT | CONSOLE_FLAG_RUNTIME);
-
 }
 
-void trp_early_platform_setup(rmm_manifest_t *manifest)
+void trp_early_platform_setup(struct rmm_manifest *manifest)
 {
        arm_trp_early_platform_setup(manifest);
 }
index 6bd9fdf302aab5ce07aa2b0d33a93cef5fb58648..e12eae79fc162886c68a251487dd2e9c9b9fdfa3 100644 (file)
@@ -171,7 +171,7 @@ int rmmd_setup(void)
        uint32_t ep_attr;
        unsigned int linear_id = plat_my_core_pos();
        rmmd_rmm_context_t *rmm_ctx = &rmm_context[linear_id];
-       rmm_manifest_t *manifest;
+       struct rmm_manifest *manifest;
        int rc;
 
        /* Make sure RME is supported. */
@@ -206,7 +206,7 @@ int rmmd_setup(void)
                                        ((void *)shared_buf_base != NULL));
 
        /* Load the boot manifest at the beginning of the shared area */
-       manifest = (rmm_manifest_t *)shared_buf_base;
+       manifest = (struct rmm_manifest *)shared_buf_base;
        rc = plat_rmmd_load_manifest(manifest);
        if (rc != 0) {
                ERROR("Error loading RMM Boot Manifest (%i)\n", rc);
index 196bc119ea363c684f7c9217ab2191256820a7d8..4eb3e126697bec32b6018182e2a1b7d0a147a193 100644 (file)
@@ -62,7 +62,7 @@ void trp_setup(uint64_t x0,
                           sizeof(trp_shared_region_start));
 
        /* Perform early platform-specific setup */
-       trp_early_platform_setup((rmm_manifest_t *)trp_shared_region_start);
+       trp_early_platform_setup((struct rmm_manifest *)trp_shared_region_start);
 }
 
 int trp_validate_warmboot_args(uint64_t x0, uint64_t x1,