Skip to content

Commit

Permalink
mem_region: Add HW-only memory resevations
Browse files Browse the repository at this point in the history
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@gmail.com>
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
  • Loading branch information
oohal authored and stewartsmith committed May 26, 2017
1 parent 0039819 commit 36ec8dd
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
23 changes: 21 additions & 2 deletions core/mem_region.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down
1 change: 1 addition & 0 deletions hdata/test/stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,4 @@ static void noop_function(void) {}

NOOP_STUB(early_uart_init);
NOOP_STUB(mem_reserve_fw);
NOOP_STUB(mem_reserve_hwbuf);
1 change: 1 addition & 0 deletions include/mem_region.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 36ec8dd

Please sign in to comment.