summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYe Li <ye.li@nxp.com>2017-06-07 03:41:22 -0500
committerAnson Huang <Anson.Huang@nxp.com>2017-07-12 23:30:25 +0800
commit5978d97ebfc5246ba36d066d7a0f569c3c015679 (patch)
tree7fae478012072046180252b8efae316e115008f9
parentbca5cc6043355af4dfc04b22ce0bcd7b1c7b8f6b (diff)
iMX8QM/QXP: Allocate memory regions to NS partition
Not only the resources, but also the memory regions need to assign to non-secure partition. Otherwise, when the boot partition is secured, the OS non-secure partition can't access any memory. This patch currently assign all memory to NS partition, since it is not isolated, the current secure partition also can access them. In future, may need to change the regions for reserving some memory in secure partition for ATF and BL32. Signed-off-by: Ye Li <ye.li@nxp.com>
-rw-r--r--plat/freescale/imx8qm/imx8qm_bl31_setup.c73
-rw-r--r--plat/freescale/imx8qm/include/sec_rsrc.h16
-rw-r--r--plat/freescale/imx8qxp/imx8qxp_bl31_setup.c18
-rw-r--r--plat/freescale/imx8qxp/include/sec_rsrc.h14
4 files changed, 87 insertions, 34 deletions
diff --git a/plat/freescale/imx8qm/imx8qm_bl31_setup.c b/plat/freescale/imx8qm/imx8qm_bl31_setup.c
index bf36d920..c4e2aeae 100644
--- a/plat/freescale/imx8qm/imx8qm_bl31_setup.c
+++ b/plat/freescale/imx8qm/imx8qm_bl31_setup.c
@@ -189,46 +189,57 @@ static int lpuart32_serial_init(unsigned int base)
void mx8_partition_resources(void)
{
- sc_err_t err;
- sc_rm_pt_t secure_part, os_part;
- int i;
+ sc_err_t err;
+ sc_rm_pt_t secure_part, os_part;
+ sc_rm_mr_t mr;
+ int i;
- err = sc_rm_get_partition(ipc_handle, &secure_part);
+ err = sc_rm_get_partition(ipc_handle, &secure_part);
- err = sc_rm_partition_alloc(ipc_handle, &os_part, false, false,
- false, false, false);
+ err = sc_rm_partition_alloc(ipc_handle, &os_part, false, false,
+ false, false, false);
- err = sc_rm_set_parent(ipc_handle, os_part, secure_part);
+ err = sc_rm_set_parent(ipc_handle, os_part, secure_part);
- /* set secure resources to NOT-movable */
- for(i = 0; i<(sizeof(secure_rsrcs)/sizeof(sc_rsrc_t)); i++){
- err = sc_rm_set_resource_movable(ipc_handle, secure_rsrcs[i],
- secure_rsrcs[i], false);
+ /* set secure resources to NOT-movable */
+ for (i = 0; i < (sizeof(secure_rsrcs) / sizeof(sc_rsrc_t)); i++) {
+ err = sc_rm_set_resource_movable(ipc_handle, secure_rsrcs[i],
+ secure_rsrcs[i], false);
+ }
- }
+ /* move all movable resources and pins to non-secure partition */
+ err = sc_rm_move_all(ipc_handle, secure_part, os_part, true, true);
- /* move all movable resources and pins to non-secure partition */
- err = sc_rm_move_all(ipc_handle, secure_part, os_part, true, true);
+ /* iterate through peripherals to give NS OS part access */
+ for (i = 0; i < (sizeof(ns_access_allowed) / sizeof(sc_rsrc_t)); i++) {
+ err = sc_rm_set_peripheral_permissions(ipc_handle, ns_access_allowed[i],
+ os_part, SC_RM_PERM_FULL);
+ }
- /* iterate through peripherals to give NS OS part access */
- for(i = 0; i<(sizeof(ns_access_allowed)/sizeof(sc_rsrc_t)); i++){
- err = sc_rm_set_peripheral_permissions(ipc_handle, ns_access_allowed[i],
- os_part, SC_RM_PERM_FULL);
- }
+ /*
+ * sc_rm_set_peripheral_permissions
+ *
+ * sc_rm_set_memreg_permissions
+ *
+ * sc_rm_set_pin_movable
+ *
+ */
- /*
- * sc_rm_set_peripheral_permissions
- *
- * sc_rm_set_memreg_permissions
- *
- * sc_rm_set_pin_movable
- *
- */
+ for (i = 0; i < (sizeof(ns_mem_region) / sizeof(struct mem_region)); i++) {
+ err = sc_rm_memreg_alloc(ipc_handle, &mr, ns_mem_region[i].start, ns_mem_region[i].end);
+ if (err) {
+ ERROR("Memreg alloc failed, 0x%lx -- 0x%lx\n", ns_mem_region[i].start, ns_mem_region[i].end);
+ } else {
+ err = sc_rm_assign_memreg(ipc_handle, os_part, mr);
+ if (err)
+ ERROR("Memreg assign failed, 0x%lx -- 0x%lx\n", ns_mem_region[i].start, ns_mem_region[i].end);
+ }
+ }
- if(err)
- NOTICE("Partitioning Failed\n");
- else
- NOTICE("Non-secure Partitioning Succeeded\n");
+ if (err)
+ NOTICE("Partitioning Failed\n");
+ else
+ NOTICE("Non-secure Partitioning Succeeded\n");
}
diff --git a/plat/freescale/imx8qm/include/sec_rsrc.h b/plat/freescale/imx8qm/include/sec_rsrc.h
index b05f0aa0..fa72c4cf 100644
--- a/plat/freescale/imx8qm/include/sec_rsrc.h
+++ b/plat/freescale/imx8qm/include/sec_rsrc.h
@@ -23,3 +23,19 @@ sc_rsrc_t ns_access_allowed[] = {
SC_R_GIC_SMMU,
SC_R_CCI
};
+
+struct mem_region {
+ unsigned long start;
+ unsigned long end;
+};
+
+struct mem_region ns_mem_region[] = {
+ {0x000000000, 0x01BFFFFFF},
+ {0x034000000, 0x037FFFFFF},
+ {0x038000000, 0x03BFFFFFF},
+ {0x060000000, 0x06FFFFFFF},
+ {0x070000000, 0x07FFFFFFF},
+ {0x080000000, 0x0FFFFFFFF},
+ {0x400000000, 0x43FFFFFFF},
+ {0x880000000, 0xFFFFFFFFF},
+};
diff --git a/plat/freescale/imx8qxp/imx8qxp_bl31_setup.c b/plat/freescale/imx8qxp/imx8qxp_bl31_setup.c
index 62d9f318..85c0442b 100644
--- a/plat/freescale/imx8qxp/imx8qxp_bl31_setup.c
+++ b/plat/freescale/imx8qxp/imx8qxp_bl31_setup.c
@@ -189,6 +189,7 @@ void imx8_partition_resources(void)
{
sc_err_t err;
sc_rm_pt_t secure_part, os_part;
+ sc_rm_mr_t mr;
int i;
err = sc_rm_get_partition(ipc_handle, &secure_part);
@@ -199,7 +200,7 @@ void imx8_partition_resources(void)
err = sc_rm_set_parent(ipc_handle, os_part, secure_part);
/* set secure resources to NOT-movable */
- for(i = 0; i<(sizeof(secure_rsrcs)/sizeof(sc_rsrc_t)); i++){
+ for (i = 0; i < (sizeof(secure_rsrcs) / sizeof(sc_rsrc_t)); i++) {
err = sc_rm_set_resource_movable(ipc_handle,
secure_rsrcs[i], secure_rsrcs[i], false);
}
@@ -208,7 +209,7 @@ void imx8_partition_resources(void)
err = sc_rm_move_all(ipc_handle, secure_part, os_part, true, true);
/* iterate through peripherals to give NS OS part access */
- for(i = 0; i<(sizeof(ns_access_allowed)/sizeof(sc_rsrc_t)); i++){
+ for (i = 0; i< (sizeof(ns_access_allowed) / sizeof(sc_rsrc_t)); i++) {
err = sc_rm_set_peripheral_permissions(ipc_handle,
ns_access_allowed[i], os_part, SC_RM_PERM_FULL);
}
@@ -222,6 +223,17 @@ void imx8_partition_resources(void)
*
*/
+ for (i = 0; i < (sizeof(ns_mem_region) / sizeof(struct mem_region)); i++) {
+ err = sc_rm_memreg_alloc(ipc_handle, &mr, ns_mem_region[i].start, ns_mem_region[i].end);
+ if (err) {
+ ERROR("Memreg alloc failed, 0x%lx -- 0x%lx\n", ns_mem_region[i].start, ns_mem_region[i].end);
+ } else {
+ err = sc_rm_assign_memreg(ipc_handle, os_part, mr);
+ if (err)
+ ERROR("Memreg assign failed, 0x%lx -- 0x%lx\n", ns_mem_region[i].start, ns_mem_region[i].end);
+ }
+ }
+
if (err)
NOTICE("Partitioning Failed\n");
else
@@ -283,7 +295,7 @@ void bl31_early_platform_setup(bl31_params_t *from_bl2,
void bl31_plat_arch_setup(void)
{
/*
- * add the mmap
+ * add the mmap
* Change to 128KB?
* Fix Me
*/
diff --git a/plat/freescale/imx8qxp/include/sec_rsrc.h b/plat/freescale/imx8qxp/include/sec_rsrc.h
index 46585881..34d234dc 100644
--- a/plat/freescale/imx8qxp/include/sec_rsrc.h
+++ b/plat/freescale/imx8qxp/include/sec_rsrc.h
@@ -16,3 +16,17 @@ sc_rsrc_t secure_rsrcs[] = {
sc_rsrc_t ns_access_allowed[] = {
SC_R_GIC,
};
+
+struct mem_region {
+ unsigned long start;
+ unsigned long end;
+};
+
+struct mem_region ns_mem_region[] = {
+ {0x000000000, 0x01BFFFFFF},
+ {0x034000000, 0x037FFFFFF},
+ {0x070000000, 0x07FFFFFFF},
+ {0x080000000, 0x0FFFFFFFF},
+ {0x400000000, 0x43FFFFFFF},
+ {0x880000000, 0xFFFFFFFFF},
+};