All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@siemens.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v5 08/14] virt-dt: Allow reservation of secure region when in a RAM carveout
Date: Mon,  9 Mar 2015 08:00:18 +0100	[thread overview]
Message-ID: <1a57b23ba809626854ceff612d3fed9e19ef5e10.1425884424.git.jan.kiszka@siemens.com> (raw)
In-Reply-To: <cover.1425884424.git.jan.kiszka@siemens.com>

In this case the secure code lives in RAM, and hence the memory node in
the device tree needs to be adjusted. This avoids that the OS will map
and possibly access the reservation.

Add support for setting CONFIG_ARMV7_SECURE_RESERVE_SIZE to carve out
such a region. We only support cutting off memory from the beginning or
the end of a RAM bank as we do not want to increase their number (which
would happen if punching a hole) for simplicity reasons

This will be used in a subsequent patch for Jetson-TK1.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 arch/arm/cpu/armv7/virt-dt.c | 29 +++++++++++++++++++++++++++++
 arch/arm/include/asm/armv7.h |  1 +
 arch/arm/lib/bootm-fdt.c     |  5 +++++
 3 files changed, 35 insertions(+)

diff --git a/arch/arm/cpu/armv7/virt-dt.c b/arch/arm/cpu/armv7/virt-dt.c
index ad19e4c..06edeec 100644
--- a/arch/arm/cpu/armv7/virt-dt.c
+++ b/arch/arm/cpu/armv7/virt-dt.c
@@ -16,6 +16,7 @@
  */
 
 #include <common.h>
+#include <errno.h>
 #include <stdio_dev.h>
 #include <linux/ctype.h>
 #include <linux/types.h>
@@ -88,6 +89,34 @@ static int fdt_psci(void *fdt)
 	return 0;
 }
 
+int armv7_apply_memory_carveout(u64 *start, u64 *size)
+{
+#ifdef CONFIG_ARMV7_SECURE_RESERVE_SIZE
+	if (*start + *size < CONFIG_ARMV7_SECURE_BASE ||
+	    *start >= (u64)CONFIG_ARMV7_SECURE_BASE +
+		      CONFIG_ARMV7_SECURE_RESERVE_SIZE)
+		return 0;
+
+	/* carveout must be at the beginning or the end of the bank */
+	if (*start == CONFIG_ARMV7_SECURE_BASE ||
+	    *start + *size == (u64)CONFIG_ARMV7_SECURE_BASE +
+			      CONFIG_ARMV7_SECURE_RESERVE_SIZE) {
+		if (*size < CONFIG_ARMV7_SECURE_RESERVE_SIZE) {
+			debug("Secure monitor larger than RAM bank!?\n");
+			return -EINVAL;
+		}
+		*size -= CONFIG_ARMV7_SECURE_RESERVE_SIZE;
+		if (*start == CONFIG_ARMV7_SECURE_BASE)
+			*start += CONFIG_ARMV7_SECURE_RESERVE_SIZE;
+		return 0;
+	}
+	debug("Secure monitor not located@beginning or end of RAM bank\n");
+	return -EINVAL;
+#else /* !CONFIG_ARMV7_SECURE_RESERVE_SIZE */
+	return 0;
+#endif
+}
+
 int armv7_update_dt(void *fdt)
 {
 	if (!armv7_boot_nonsec())
diff --git a/arch/arm/include/asm/armv7.h b/arch/arm/include/asm/armv7.h
index edb3b80..7843ba7 100644
--- a/arch/arm/include/asm/armv7.h
+++ b/arch/arm/include/asm/armv7.h
@@ -124,6 +124,7 @@ void v7_outer_cache_inval_range(u32 start, u32 end);
 #if defined(CONFIG_ARMV7_NONSEC) || defined(CONFIG_ARMV7_VIRT)
 
 int armv7_init_nonsec(void);
+int armv7_apply_memory_carveout(u64 *start, u64 *size);
 int armv7_update_dt(void *fdt);
 bool armv7_boot_nonsec(void);
 
diff --git a/arch/arm/lib/bootm-fdt.c b/arch/arm/lib/bootm-fdt.c
index d4f1578..7b88739 100644
--- a/arch/arm/lib/bootm-fdt.c
+++ b/arch/arm/lib/bootm-fdt.c
@@ -31,6 +31,11 @@ int arch_fixup_fdt(void *blob)
 	for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) {
 		start[bank] = bd->bi_dram[bank].start;
 		size[bank] = bd->bi_dram[bank].size;
+#if defined(CONFIG_ARMV7_NONSEC) || defined(CONFIG_ARMV7_VIRT)
+		ret = armv7_apply_memory_carveout(&start[bank], &size[bank]);
+		if (ret)
+			return ret;
+#endif
 	}
 
 	ret = fdt_fixup_memory_banks(blob, start, size, CONFIG_NR_DRAM_BANKS);
-- 
2.1.4

  parent reply	other threads:[~2015-03-09  7:00 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-09  7:00 [U-Boot] [PATCH v5 00/14] Add PSCI support for Jetson TK1/Tegra124 + CNTFRQ fix Jan Kiszka
2015-03-09  7:00 ` [U-Boot] [PATCH v5 01/14] sun7i: Remove duplicate call to psci_arch_init Jan Kiszka
2015-03-11 15:11   ` Tom Rini
2015-03-12  7:34     ` Jan Kiszka
2015-03-12 12:28       ` Tom Rini
2015-03-12 13:44         ` Jan Kiszka
2015-03-21 13:34     ` Hans de Goede
2015-03-09  7:00 ` [U-Boot] [PATCH v5 02/14] ARM: Factor out common psci_get_cpu_id Jan Kiszka
2015-03-11 15:11   ` Tom Rini
2015-03-18 16:54   ` Ian Campbell
2015-03-19  7:52     ` Jan Kiszka
2015-03-09  7:00 ` [U-Boot] [PATCH v5 03/14] ARM: Factor out reusable psci_cpu_off_common Jan Kiszka
2015-03-11 15:12   ` Tom Rini
2015-03-09  7:00 ` [U-Boot] [PATCH v5 04/14] ARM: Factor out reusable psci_cpu_entry Jan Kiszka
2015-03-11 15:12   ` Tom Rini
2015-03-09  7:00 ` [U-Boot] [PATCH v5 05/14] ARM: Factor out reusable psci_get_cpu_stack_top Jan Kiszka
2015-03-11 15:12   ` Tom Rini
2015-03-09  7:00 ` [U-Boot] [PATCH v5 06/14] ARM: Put target PC for PSCI CPU_ON on per-CPU stack Jan Kiszka
2015-03-11 15:12   ` Tom Rini
2015-03-09  7:00 ` [U-Boot] [PATCH v5 07/14] tegra124: Add more registers to struct mc_ctlr Jan Kiszka
2015-03-11 15:12   ` Tom Rini
2015-03-09  7:00 ` Jan Kiszka [this message]
2015-03-11 15:12   ` [U-Boot] [PATCH v5 08/14] virt-dt: Allow reservation of secure region when in a RAM carveout Tom Rini
2015-03-12  7:34     ` Jan Kiszka
2015-03-12  8:18     ` Thierry Reding
2015-03-12 12:30       ` Tom Rini
2015-03-09  7:00 ` [U-Boot] [PATCH v5 09/14] tegra: Make tegra_powergate_power_on public Jan Kiszka
2015-03-11 15:12   ` Tom Rini
2015-03-09  7:00 ` [U-Boot] [PATCH v5 10/14] tegra: Add ap_pm_init hook Jan Kiszka
2015-03-11 15:12   ` Tom Rini
2015-03-09  7:00 ` [U-Boot] [PATCH v5 11/14] tegra124: Add PSCI support for Tegra124 Jan Kiszka
2015-03-11 15:12   ` Tom Rini
2015-03-09  7:00 ` [U-Boot] [PATCH v5 12/14] jetson-tk1: Add PSCI configuration options and reserve secure code Jan Kiszka
2015-03-11 15:12   ` Tom Rini
2015-03-09  7:00 ` [U-Boot] [PATCH v5 13/14] tegra124: Reserve secure RAM using MC_SECURITY_CFG{0, 1}_0 Jan Kiszka
2015-03-11 15:12   ` Tom Rini
2015-03-09  7:00 ` [U-Boot] [PATCH v5 14/14] tegra: Set CNTFRQ for secondary CPUs Jan Kiszka
2015-03-11 15:13   ` Tom Rini
2015-03-11  8:56 ` [U-Boot] [PATCH v5 00/14] Add PSCI support for Jetson TK1/Tegra124 + CNTFRQ fix Ian Campbell
2015-03-12  7:55   ` Ian Campbell
2015-03-11 15:11 ` Tom Rini
2015-03-18  6:40   ` Jan Kiszka
2015-03-18 16:02     ` Tom Warren
2015-03-18 16:54   ` Ian Campbell
2015-03-19  7:52     ` Jan Kiszka
2015-03-19 15:02 ` Thierry Reding
2015-04-08  8:37   ` Jan Kiszka
2015-04-08 13:43     ` Tom Rini
2015-04-08 13:55       ` Jan Kiszka
2015-04-08 14:02         ` Tom Rini
2015-04-08 14:12           ` Jan Kiszka
2015-04-08 15:54             ` Tom Rini
2015-04-08 16:13               ` Jan Kiszka
2015-04-08 16:22                 ` Tom Rini
2015-04-10  6:59     ` Thierry Reding
2015-04-10  7:07       ` Jan Kiszka
2015-04-10  9:54         ` Thierry Reding
2015-04-10 10:19           ` Jan Kiszka
2015-04-10 10:22             ` Thierry Reding

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1a57b23ba809626854ceff612d3fed9e19ef5e10.1425884424.git.jan.kiszka@siemens.com \
    --to=jan.kiszka@siemens.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.