summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorAlexandre Ghiti <alex@ghiti.fr>2020-06-13 09:59:13 +0300
committerAnup Patel <anup@brainfault.org>2020-06-15 06:55:44 +0300
commit6966ad0abe7077b1b5c9342f588621426d997c38 (patch)
tree2e3cc405f9c5bebff0b54621578fa04d18d52da7 /platform
parente2c3f01af4329aa7e9009edee13b7cfdf379071f (diff)
downloadopensbi-6966ad0abe7077b1b5c9342f588621426d997c38.tar.xz
platform/lib: Allow the OS to map the regions that are protected by PMP
This is achieved by removing the 'no-map' property from the 'reserved-memory' node when PMP is present, otherwise we keep it as it offers a small protection if the OS does not map this region at all. A new callback in platform_override is introduced and allows to fixup the device-tree. It is used here to override this new default behaviour on SiFive Fu540 platforms that has an erratum that prevents S-mode software to access a PMP protected region using 1GB page table mapping. If PMP is present, telling the OS not to map the reserved regions does not add much protection since it only avoids access to regions that are already protected by PMP. But by not allowing the OS to map those regions, it creates holes in the OS system memory map and prevents the use of hugepages which would generate, among other benefits, less TLB miss. Signed-off-by: Alexandre Ghiti <alex@ghiti.fr> Reviewed-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
Diffstat (limited to 'platform')
-rw-r--r--platform/generic/include/platform_override.h1
-rw-r--r--platform/generic/platform.c6
-rw-r--r--platform/generic/sifive_fu540.c14
-rw-r--r--platform/sifive/fu540/platform.c7
4 files changed, 28 insertions, 0 deletions
diff --git a/platform/generic/include/platform_override.h b/platform/generic/include/platform_override.h
index 1262627..8a53cdf 100644
--- a/platform/generic/include/platform_override.h
+++ b/platform/generic/include/platform_override.h
@@ -21,6 +21,7 @@ struct platform_override {
void (*early_exit)(const struct fdt_match *match);
void (*final_exit)(const struct fdt_match *match);
int (*system_reset)(u32 reset_type, const struct fdt_match *match);
+ int (*fdt_fixup)(void *fdt, const struct fdt_match *match);
};
#endif
diff --git a/platform/generic/platform.c b/platform/generic/platform.c
index 57058ff..c3cf423 100644
--- a/platform/generic/platform.c
+++ b/platform/generic/platform.c
@@ -153,6 +153,12 @@ static int generic_final_init(bool cold_boot)
fdt_cpu_fixup(fdt);
fdt_fixups(fdt);
+ if (generic_plat && generic_plat->fdt_fixup) {
+ rc = generic_plat->fdt_fixup(fdt, generic_plat_match);
+ if (rc)
+ return rc;
+ }
+
return 0;
}
diff --git a/platform/generic/sifive_fu540.c b/platform/generic/sifive_fu540.c
index 9ddafa0..08f7bfc 100644
--- a/platform/generic/sifive_fu540.c
+++ b/platform/generic/sifive_fu540.c
@@ -9,6 +9,7 @@
#include <platform_override.h>
#include <sbi_utils/fdt/fdt_helper.h>
+#include <sbi_utils/fdt/fdt_fixup.h>
static u64 sifive_fu540_tlbr_flush_limit(const struct fdt_match *match)
{
@@ -19,6 +20,18 @@ static u64 sifive_fu540_tlbr_flush_limit(const struct fdt_match *match)
return 0;
}
+static int sifive_fu540_fdt_fixup(void *fdt, const struct fdt_match *match)
+{
+ /*
+ * SiFive Freedom U540 has an erratum that prevents S-mode software
+ * to access a PMP protected region using 1GB page table mapping, so
+ * always add the no-map attribute on this platform.
+ */
+ fdt_reserved_memory_nomap_fixup(fdt);
+
+ return 0;
+}
+
static const struct fdt_match sifive_fu540_match[] = {
{ .compatible = "sifive,fu540" },
{ .compatible = "sifive,fu540g" },
@@ -30,4 +43,5 @@ static const struct fdt_match sifive_fu540_match[] = {
const struct platform_override sifive_fu540 = {
.match_table = sifive_fu540_match,
.tlbr_flush_limit = sifive_fu540_tlbr_flush_limit,
+ .fdt_fixup = sifive_fu540_fdt_fixup,
};
diff --git a/platform/sifive/fu540/platform.c b/platform/sifive/fu540/platform.c
index 48d887f..755e479 100644
--- a/platform/sifive/fu540/platform.c
+++ b/platform/sifive/fu540/platform.c
@@ -63,6 +63,13 @@ static void fu540_modify_dt(void *fdt)
fdt_cpu_fixup(fdt);
fdt_fixups(fdt);
+
+ /*
+ * SiFive Freedom U540 has an erratum that prevents S-mode software
+ * to access a PMP protected region using 1GB page table mapping, so
+ * always add the no-map attribute on this platform.
+ */
+ fdt_reserved_memory_nomap_fixup(fdt);
}
static int fu540_final_init(bool cold_boot)