diff mbox series

[RFC,5/9] Add OPAL_FIND_VM_AREA

Message ID 20200502113649.176329-6-npiggin@gmail.com
State New
Headers show
Series OPAL V4 | expand

Checks

Context Check Description
snowpatch_ozlabs/apply_patch warning Failed to apply on branch master (0f1937ef40fca0c3212a9dff1010b832a24fb063)
snowpatch_ozlabs/apply_patch fail Failed to apply to any branch

Commit Message

Nicholas Piggin May 2, 2020, 11:36 a.m. UTC
This interface allows the OS to query the virtual mappings that were
set up at the time OPAL initiated the OS.

This allows the OS to set up its own virtual memory environment to call
OPAL in.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 core/vm.c          | 42 ++++++++++++++++++++++++++++++++++++++++++
 include/opal-api.h | 15 ++++++++++++++-
 2 files changed, 56 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/core/vm.c b/core/vm.c
index 3f910d0d6..236a0e70b 100644
--- a/core/vm.c
+++ b/core/vm.c
@@ -257,6 +257,22 @@  static void htab_remove(unsigned long va, int local)
 	}
 }
 
+static uint64_t vmm_os_map_flags(struct vm_map *vmm)
+{
+	uint64_t flags = 0;
+
+	if (vmm->readable)
+		flags |= OS_VM_FLAG_READ;
+	if (vmm->writeable)
+		flags |= OS_VM_FLAG_WRITE;
+	if (vmm->executable)
+		flags |= OS_VM_FLAG_EXECUTE;
+	if (vmm->ci)
+		flags |= OS_VM_FLAG_CI;
+
+	return flags;
+}
+
 /*
  * Try to fix problems in callers if !strict.
  */
@@ -934,3 +950,29 @@  void vm_destroy(void)
 	free(prtab);
 	prtab = NULL;
 }
+
+static int64_t opal_find_vm_area(uint64_t addr, struct opal_vm_area *opal_vm_area)
+{
+	struct vm_map *vmm;
+
+	/* OS takes over control of providing VM mappings */
+	list_for_each(&vm_maps, vmm, list) {
+		uint64_t flags;
+
+		if (addr >= vmm->address + vmm->length)
+			continue;
+
+		flags = vmm_os_map_flags(vmm);
+		opal_vm_area->address = cpu_to_be64(vmm->address);
+		opal_vm_area->length = cpu_to_be64(vmm->length);
+		opal_vm_area->pa = cpu_to_be64(vmm->pa);
+		opal_vm_area->vm_flags = cpu_to_be64(flags);
+
+		printf("0x%016llx-0x%016llx flags=%llx (%s)\n", vmm->address, vmm->address + vmm->length, flags, vmm->name);
+
+		return OPAL_SUCCESS;
+	}
+
+	return OPAL_EMPTY;
+}
+opal_call(OPAL_FIND_VM_AREA, opal_find_vm_area, 2);
diff --git a/include/opal-api.h b/include/opal-api.h
index 76d751c75..e5142f121 100644
--- a/include/opal-api.h
+++ b/include/opal-api.h
@@ -230,7 +230,8 @@ 
 #define OPAL_ADDR_TO_SYM			181
 #define OPAL_SYM_TO_ADDR			182
 #define OPAL_REPORT_TRAP			183
-#define OPAL_LAST				183
+#define OPAL_FIND_VM_AREA			184
+#define OPAL_LAST				184
 
 #define QUIESCE_HOLD			1 /* Spin all calls at entry */
 #define QUIESCE_REJECT			2 /* Fail all calls with OPAL_BUSY */
@@ -1262,6 +1263,18 @@  struct opal_mpipl_fadump {
 #define OPAL_TRAP_WARN	2
 #define OPAL_TRAP_PANIC	3
 
+#define OS_VM_FLAG_READ		0x1
+#define OS_VM_FLAG_WRITE	0x2
+#define OS_VM_FLAG_EXECUTE	0x4
+#define OS_VM_FLAG_CI		0x8
+
+struct opal_vm_area {
+	__be64	address;
+	__be64	length;
+	__be64	pa;
+	__be64	vm_flags;
+};
+
 #endif /* __ASSEMBLY__ */
 
 #endif /* __OPAL_API_H */