diff mbox series

[RFC,v4,14/16] Add an ultravisor device tree in secure memory

Message ID 20200227122042.32692-15-grimm@linux.ibm.com
State Superseded
Headers show
Series Ultravisor support in skiboot | expand

Checks

Context Check Description
snowpatch_ozlabs/apply_patch success Successfully applied on branch master (82aed17a5468aff6b600ee1694a10a60f942c018)
snowpatch_ozlabs/snowpatch_job_snowpatch-skiboot success Test snowpatch/job/snowpatch-skiboot on branch master
snowpatch_ozlabs/snowpatch_job_snowpatch-skiboot-dco success Signed-off-by present

Commit Message

Ryan Grimm Feb. 27, 2020, 12:20 p.m. UTC
This patch adds a UV FDT created in secure memory.  It is allocated
directly after the ultravisor.

The UV FDT will contain information like the wrapping key.

The code uses libfdt directly to ensure only secure memory is used.

Signed-off-by: Ryan Grimm <grimm@linux.ibm.com>
Signed-off-by: Ram Pai <linuxram@us.ibm.com>
---
 hw/ultravisor.c      | 27 ++++++++++++++++++++++++++-
 include/ultravisor.h |  1 +
 2 files changed, 27 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/hw/ultravisor.c b/hw/ultravisor.c
index 650466e8..1467a1e5 100644
--- a/hw/ultravisor.c
+++ b/hw/ultravisor.c
@@ -12,6 +12,7 @@ 
 #include <console.h>
 #include <chip.h>
 #include <libstb/container.h>
+#include <libfdt/libfdt.h>
 
 static struct dt_node *uv_fw_node;
 static uint64_t uv_base_addr;
@@ -115,9 +116,27 @@  static int uv_decompress_image(void)
 	return OPAL_SUCCESS;
 }
 
+static int create_dtb_uv(void *uv_fdt)
+{
+	if (fdt_create(uv_fdt, UV_FDT_MAX_SIZE)) {
+		prerror("UV: Failed to create uv_fdt\n");
+		return OPAL_NO_MEM;
+	}
+
+	fdt_finish_reservemap(uv_fdt);
+	fdt_begin_node(uv_fdt, "");
+	fdt_property_string(uv_fdt, "description", "Ultravisor fdt");
+	fdt_begin_node(uv_fdt, "ibm,uv-fdt");
+	fdt_property_string(uv_fdt, "compatible", "ibm,uv-fdt");
+	fdt_end_node(uv_fdt);
+	fdt_finish(uv_fdt);
+
+	return OPAL_SUCCESS;
+}
+
 void init_uv()
 {
-	uint64_t uv_dt_src, uv_fw_sz;
+	uint64_t uv_dt_src, uv_fw_sz, uv_fdt_addr;
 	int ret;
 
 	if (!is_msr_bit_set(MSR_S)) {
@@ -131,6 +150,8 @@  void init_uv()
 		goto err;
 	}
 
+	uv_base_addr = dt_get_address(uv_fw_node, 0, &uv_fw_sz);
+
 	ret = uv_decompress_image();
 	if (ret) {
 		if (!dt_find_property(uv_fw_node, "uv-src-address")) {
@@ -149,6 +170,10 @@  void init_uv()
 
 	dt_add_property_u64(uv_fw_node, "memcons", (u64)&uv_memcons);
 	debug_descriptor.uv_memcons_phys = (u64)&uv_memcons;
+
+	uv_fdt_addr = uv_base_addr + UV_LOAD_MAX_SIZE;
+	create_dtb_uv((void *)uv_fdt_addr);
+	dt_add_property_u64(uv_fw_node, "uv-fdt", uv_fdt_addr);
 err:
 	local_free(uv_image);
 }
diff --git a/include/ultravisor.h b/include/ultravisor.h
index 26a986cd..347b085d 100644
--- a/include/ultravisor.h
+++ b/include/ultravisor.h
@@ -14,6 +14,7 @@ 
 #define UCALL_BUFSIZE 4
 #define UV_READ_SCOM  0xF114
 #define UV_WRITE_SCOM 0xF118
+#define UV_FDT_MAX_SIZE		0x100000
 
 extern long ucall(unsigned long opcode, unsigned long *retbuf, ...);
 extern int start_uv(uint64_t entry, void *fdt);