[Skiboot] [PATCH 2/3] mem_region: Add HW-only memory resevations

Oliver O'Halloran oohall at gmail.com
Wed May 24 16:00:52 AEST 2017


Add a new type of memory reservation that indicates a memory region is
only used by hardware and should not be touched by software. This is
needed for the in-memory tracing buffers. These reservations have the
"no-map" property which indicates that the host kernel should not setup
any virtual address mappings that cover this range, unless of course a
device driver does so explicitly.

Signed-off-by: Oliver O'Halloran <oohall at gmail.com>
---
 core/mem_region.c    | 23 +++++++++++++++++++++--
 hdata/test/stubs.c   |  1 +
 include/mem_region.h |  1 +
 3 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/core/mem_region.c b/core/mem_region.c
index a8a92ff21171..ebca4476fcd7 100644
--- a/core/mem_region.c
+++ b/core/mem_region.c
@@ -756,13 +756,14 @@ static bool add_region(struct mem_region *region)
 	return true;
 }
 
-void mem_reserve_fw(const char *name, uint64_t start, uint64_t len)
+static void mem_reserve(enum mem_region_type type, const char *name,
+		uint64_t start, uint64_t len)
 {
 	struct mem_region *region;
 	bool added = true;
 
 	lock(&mem_region_lock);
-	region = new_region(name, start, len, NULL, REGION_FW_RESERVED);
+	region = new_region(name, start, len, NULL, type);
 	assert(region);
 
 	if (!mem_region_init_done)
@@ -774,6 +775,16 @@ void mem_reserve_fw(const char *name, uint64_t start, uint64_t len)
 	unlock(&mem_region_lock);
 }
 
+void mem_reserve_fw(const char *name, uint64_t start, uint64_t len)
+{
+	mem_reserve(REGION_FW_RESERVED, name, start, len);
+}
+
+void mem_reserve_hwbuf(const char *name, uint64_t start, uint64_t len)
+{
+	mem_reserve(REGION_RESERVED, name, start, len);
+}
+
 static bool matches_chip_id(const __be32 ids[], size_t num, u32 chip_id)
 {
 	size_t i;
@@ -1169,6 +1180,14 @@ static void mem_region_add_dt_reserved_node(struct dt_node *parent,
 	region->node = dt_new_addr(parent, name, region->start);
 	assert(region->node);
 	dt_add_property_u64s(region->node, "reg", region->start, region->len);
+
+	/*
+	 * This memory is used by hardware and may need special handling. Ask
+	 * the host kernel not to map it by default.
+	 */
+	if (region->type == REGION_RESERVED)
+		dt_add_property(region->node, "no-map", NULL, 0);
+
 	free(name);
 }
 
diff --git a/hdata/test/stubs.c b/hdata/test/stubs.c
index e3b0fdf0be6f..68f55e63a21b 100644
--- a/hdata/test/stubs.c
+++ b/hdata/test/stubs.c
@@ -107,3 +107,4 @@ static void noop_function(void) {}
 
 NOOP_STUB(early_uart_init);
 NOOP_STUB(mem_reserve_fw);
+NOOP_STUB(mem_reserve_hwbuf);
diff --git a/include/mem_region.h b/include/mem_region.h
index 8a6bf4079d0c..324e98e15a49 100644
--- a/include/mem_region.h
+++ b/include/mem_region.h
@@ -74,6 +74,7 @@ void mem_region_add_dt_reserved(void);
 
 /* Mark memory as reserved */
 void mem_reserve_fw(const char *name, uint64_t start, uint64_t len);
+void mem_reserve_hwbuf(const char *name, uint64_t start, uint64_t len);
 
 struct mem_region *find_mem_region(const char *name);
 
-- 
2.9.3



More information about the Skiboot mailing list