SPM: Support multiple xlat tables contexts
authorAntonio Nino Diaz <antonio.ninodiaz@arm.com>
Tue, 30 Oct 2018 11:36:47 +0000 (11:36 +0000)
committerAntonio Nino Diaz <antonio.ninodiaz@arm.com>
Tue, 11 Dec 2018 13:45:41 +0000 (13:45 +0000)
Change-Id: Ib7c2529b85bb5930d44907edfc8ead13d3b1ef4d
Co-authored-by: Sandrine Bailleux <sandrine.bailleux@arm.com>
Signed-off-by: Antonio Nino Diaz <antonio.ninodiaz@arm.com>
include/lib/xlat_tables/xlat_tables_v2.h
lib/xlat_tables_v2/xlat_tables_core.c
plat/arm/board/fvp/include/platform_def.h
services/std_svc/spm/sp_xlat.c

index 8c0a567a2534319065b0a10692211e1f5dc6ddf6..5c4edc31a8f20d67cd5e04fae75de47c7e21ca20 100644 (file)
@@ -208,6 +208,17 @@ typedef struct xlat_ctx xlat_ctx_t;
 void init_xlat_tables(void);
 void init_xlat_tables_ctx(xlat_ctx_t *ctx);
 
+/*
+ * Fill all fields of a dynamic translation tables context. It must be done
+ * either statically with REGISTER_XLAT_CONTEXT() or at runtime with this
+ * function.
+ */
+void xlat_setup_dynamic_ctx(xlat_ctx_t *ctx, unsigned long long pa_max,
+                           uintptr_t va_max, struct mmap_region *mmap,
+                           unsigned int mmap_num, uint64_t **tables,
+                           unsigned int tables_num, uint64_t *base_table,
+                           int xlat_regime, int *mapped_regions);
+
 /*
  * Add a static region with defined base PA and base VA. This function can only
  * be used before initializing the translation tables. The region cannot be
index 185473a14deb5e5c250bea934f54c4012748b335..53fc874d8797565e56f7f90545450df4b6081b2f 100644 (file)
@@ -1101,6 +1101,36 @@ int mmap_remove_dynamic_region_ctx(xlat_ctx_t *ctx, uintptr_t base_va,
        return 0;
 }
 
+void xlat_setup_dynamic_ctx(xlat_ctx_t *ctx, unsigned long long pa_max,
+                           uintptr_t va_max, struct mmap_region *mmap,
+                           unsigned int mmap_num, uint64_t **tables,
+                           unsigned int tables_num, uint64_t *base_table,
+                           int xlat_regime, int *mapped_regions)
+{
+       ctx->xlat_regime = xlat_regime;
+
+       ctx->pa_max_address = pa_max;
+       ctx->va_max_address = va_max;
+
+       ctx->mmap = mmap;
+       ctx->mmap_num = mmap_num;
+       memset(ctx->mmap, 0, sizeof(struct mmap_region) * mmap_num);
+
+       ctx->tables = (void *) tables;
+       ctx->tables_num = tables_num;
+
+       uintptr_t va_space_size = va_max + 1;
+       ctx->base_level = GET_XLAT_TABLE_LEVEL_BASE(va_space_size);
+       ctx->base_table = base_table;
+       ctx->base_table_entries = GET_NUM_BASE_LEVEL_ENTRIES(va_space_size);
+
+       ctx->tables_mapped_regions = mapped_regions;
+
+       ctx->max_pa = 0;
+       ctx->max_va = 0;
+       ctx->initialized = 0;
+}
+
 #endif /* PLAT_XLAT_TABLES_DYNAMIC */
 
 void __init init_xlat_tables_ctx(xlat_ctx_t *ctx)
index 4e1ebd92a9d17782e9047845a08ce8b90ec33cfc..3097f909bb6a8fd9c97bbd7fe72df30686fc4797 100644 (file)
  * calculated using the current BL31 PROGBITS debug size plus the sizes of
  * BL2 and BL1-RW
  */
+#if ENABLE_SPM && !SPM_DEPRECATED
+#define PLAT_ARM_MAX_BL31_SIZE         UL(0x60000)
+#else
 #define PLAT_ARM_MAX_BL31_SIZE         UL(0x3B000)
+#endif
 
 #ifdef AARCH32
 /*
index 0e7d243cc9c968a816947f9cc35842a22aebe352..443b0b983f03fbe0a6f1e06666f23e7c43ff43a1 100644 (file)
@@ -15,6 +15,7 @@
 #include <spm_svc.h>
 #include <string.h>
 #include <utils.h>
+#include <utils_def.h>
 #include <xlat_tables_v2.h>
 
 #include "spm_private.h"
  * Instantiation of translation table context
  ******************************************************************************/
 
+/* Lock used for SP_MEMORY_ATTRIBUTES_GET and SP_MEMORY_ATTRIBUTES_SET */
+static spinlock_t mem_attr_smc_lock;
+
 /* Place translation tables by default along with the ones used by BL31. */
 #ifndef PLAT_SP_IMAGE_XLAT_SECTION_NAME
 #define PLAT_SP_IMAGE_XLAT_SECTION_NAME        "xlat_table"
 #endif
 
-/* Allocate and initialise the translation context for the secure partitions. */
-REGISTER_XLAT_CONTEXT2(sp,
-                      PLAT_SP_IMAGE_MMAP_REGIONS,
-                      PLAT_SP_IMAGE_MAX_XLAT_TABLES,
-                      PLAT_VIRT_ADDR_SPACE_SIZE, PLAT_PHY_ADDR_SPACE_SIZE,
-                      EL1_EL0_REGIME, PLAT_SP_IMAGE_XLAT_SECTION_NAME);
+/*
+ * Allocate elements of the translation contexts for the Secure Partitions.
+ */
 
-/* Lock used for SP_MEMORY_ATTRIBUTES_GET and SP_MEMORY_ATTRIBUTES_SET */
-static spinlock_t mem_attr_smc_lock;
+/* Allocate an array of mmap_region per partition. */
+static struct mmap_region sp_mmap_regions[PLAT_SP_IMAGE_MMAP_REGIONS + 1]
+       [PLAT_SPM_MAX_PARTITIONS];
+static OBJECT_POOL(sp_mmap_regions_pool, sp_mmap_regions,
+       sizeof(mmap_region_t) * (PLAT_SP_IMAGE_MMAP_REGIONS + 1),
+       PLAT_SPM_MAX_PARTITIONS);
+
+/* Allocate individual translation tables. */
+static uint64_t sp_xlat_tables[XLAT_TABLE_ENTRIES]
+       [(PLAT_SP_IMAGE_MAX_XLAT_TABLES + 1) * PLAT_SPM_MAX_PARTITIONS]
+       __aligned(XLAT_TABLE_SIZE) __section(PLAT_SP_IMAGE_XLAT_SECTION_NAME);
+static OBJECT_POOL(sp_xlat_tables_pool, sp_xlat_tables,
+       XLAT_TABLE_ENTRIES * sizeof(uint64_t),
+       (PLAT_SP_IMAGE_MAX_XLAT_TABLES + 1) * PLAT_SPM_MAX_PARTITIONS);
+
+/* Allocate base translation tables. */
+static uint64_t sp_xlat_base_tables
+       [GET_NUM_BASE_LEVEL_ENTRIES(PLAT_VIRT_ADDR_SPACE_SIZE)]
+       [PLAT_SPM_MAX_PARTITIONS]
+       __aligned(GET_NUM_BASE_LEVEL_ENTRIES(PLAT_VIRT_ADDR_SPACE_SIZE)
+                 * sizeof(uint64_t))
+       __section(PLAT_SP_IMAGE_XLAT_SECTION_NAME);
+static OBJECT_POOL(sp_xlat_base_tables_pool, sp_xlat_base_tables,
+       GET_NUM_BASE_LEVEL_ENTRIES(PLAT_VIRT_ADDR_SPACE_SIZE) * sizeof(uint64_t),
+       PLAT_SPM_MAX_PARTITIONS);
+
+/* Allocate arrays. */
+static int sp_xlat_mapped_regions[PLAT_SP_IMAGE_MAX_XLAT_TABLES]
+       [PLAT_SPM_MAX_PARTITIONS];
+static OBJECT_POOL(sp_xlat_mapped_regions_pool, sp_xlat_mapped_regions,
+       sizeof(int) * PLAT_SP_IMAGE_MAX_XLAT_TABLES, PLAT_SPM_MAX_PARTITIONS);
+
+/* Allocate individual contexts. */
+static xlat_ctx_t sp_xlat_ctx[PLAT_SPM_MAX_PARTITIONS];
+static OBJECT_POOL(sp_xlat_ctx_pool, sp_xlat_ctx, sizeof(xlat_ctx_t),
+       PLAT_SPM_MAX_PARTITIONS);
 
 /* Get handle of Secure Partition translation context */
 xlat_ctx_t *spm_sp_xlat_context_alloc(void)
 {
-       return &sp_xlat_ctx;
+       xlat_ctx_t *ctx = pool_alloc(&sp_xlat_ctx_pool);
+
+       struct mmap_region *mmap = pool_alloc(&sp_mmap_regions_pool);
+
+       uint64_t *base_table = pool_alloc(&sp_xlat_base_tables_pool);
+       uint64_t **tables = pool_alloc_n(&sp_xlat_tables_pool,
+                                       PLAT_SP_IMAGE_MAX_XLAT_TABLES);
+
+       int *mapped_regions = pool_alloc(&sp_xlat_mapped_regions_pool);
+
+       xlat_setup_dynamic_ctx(ctx, PLAT_PHY_ADDR_SPACE_SIZE - 1,
+                              PLAT_VIRT_ADDR_SPACE_SIZE - 1, mmap,
+                              PLAT_SP_IMAGE_MMAP_REGIONS, tables,
+                              PLAT_SP_IMAGE_MAX_XLAT_TABLES, base_table,
+                              EL1_EL0_REGIME, mapped_regions);
+
+       return ctx;
 };
 
 /*******************************************************************************