Skip to content

Commit

Permalink
libstb/cvc: update memory-region to point to /reserved-memory
Browse files Browse the repository at this point in the history
The linux documentation, reserved-memory.txt, says that memory-region is
a phandle that pairs to a children of /reserved-memory.

This updates /ibm,secureboot/ibm,cvc/memory-region to point to
/reserved-memory/secure-crypt-algo-code instead of
/ibm,hostboot/reserved-memory/secure-crypt-algo-code.

Signed-off-by: Claudio Carvalho <cclaudio@linux.vnet.ibm.com>
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
  • Loading branch information
Claudio Carvalho authored and stewartsmith committed Dec 19, 2017
1 parent 63110a7 commit 68a2557
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
7 changes: 7 additions & 0 deletions core/init.c
Expand Up @@ -1062,6 +1062,13 @@ void __noreturn __nomcount main_cpu_entry(const void *fdt)
/* ... and add remaining reservations to the DT */
mem_region_add_dt_reserved();

/*
* Update /ibm,secureboot/ibm,cvc/memory-region to point to
* /reserved-memory/secure-crypt-algo-code instead of
* /ibm,hostboot/reserved-memory/secure-crypt-algo-code.
*/
cvc_update_reserved_memory_phandle();

prd_register_reserved_memory();

/* On P9, switch to radix mode by default */
Expand Down
33 changes: 32 additions & 1 deletion libstb/cvc.c
Expand Up @@ -47,6 +47,9 @@ static struct container_verification_code *cvc = NULL;
static bool softrom = false;
static void *secure_rom_mem = NULL;

static struct dt_node *cvc_resv_mem = NULL;
static struct dt_node *cvc_node = NULL;

struct cvc_service {
int id;
uint64_t addr; /* base_addr + offset */
Expand Down Expand Up @@ -137,7 +140,6 @@ static void cvc_service_register(uint32_t id, uint32_t offset, uint32_t version)
static int cvc_reserved_mem_init(struct dt_node *parent) {
struct dt_node *node, *service;
struct dt_node *reserved_mem;
struct dt_node *cvc_resv_mem = NULL;
uint32_t phandle;
uint64_t addr, size;

Expand All @@ -156,6 +158,7 @@ static int cvc_reserved_mem_init(struct dt_node *parent) {
if (dt_node_is_compatible(node, "ibm,container-verification-code")) {
phandle = dt_prop_get_u32(node, "memory-region");
cvc_resv_mem = dt_find_by_phandle(reserved_mem, phandle);
cvc_node = node;
break;
}
}
Expand Down Expand Up @@ -218,6 +221,34 @@ static int cvc_secure_rom_init(void) {
return 0;
}

void cvc_update_reserved_memory_phandle(void) {
struct dt_node *reserved_mem;

if (!cvc_resv_mem || !cvc_node)
return;

/*
* The linux documentation, reserved-memory.txt, says that memory-region
* is a phandle that pairs to a children of /reserved-memory
*/
reserved_mem = dt_find_by_path(dt_root, "/reserved-memory");
if (!reserved_mem) {
prlog(PR_ERR, "/reserved-memory not found\n");
return;
}
cvc_resv_mem = dt_find_by_name(reserved_mem, cvc_resv_mem->name);
if (cvc_resv_mem) {
dt_check_del_prop(cvc_node, "memory-region");
dt_add_property_cells(cvc_node, "memory-region", cvc_resv_mem->phandle);
} else {
prlog(PR_WARNING, "CVC not found in /reserved-memory\n");
return;
}

cvc_resv_mem = NULL;
cvc_node = NULL;
}

int cvc_init(void)
{
struct dt_node *node;
Expand Down
1 change: 1 addition & 0 deletions libstb/cvc.h
Expand Up @@ -22,6 +22,7 @@ enum cvc_service_id {
CVC_VERIFY_SERVICE,
};

void cvc_update_reserved_memory_phandle(void);
int cvc_init(void);

/************************************************************************
Expand Down

0 comments on commit 68a2557

Please sign in to comment.