feat: find vm and returned it locked
Change-Id: I05f1e21a5e60ff1e9e138e43c5e08cb6c04a455f
Signed-off-by: J-Alves <joao.alves@arm.com>
diff --git a/inc/hf/vm.h b/inc/hf/vm.h
index f7a73da..1a222ff 100644
--- a/inc/hf/vm.h
+++ b/inc/hf/vm.h
@@ -202,6 +202,7 @@
struct vm **new_vm, bool el0_partition);
ffa_vm_count_t vm_get_count(void);
struct vm *vm_find(ffa_vm_id_t id);
+struct vm_locked vm_find_locked(ffa_vm_id_t id);
struct vm *vm_find_index(uint16_t index);
struct vm_locked vm_lock(struct vm *vm);
struct two_vm_locked vm_lock_both(struct vm *vm1, struct vm *vm2);
diff --git a/src/vm.c b/src/vm.c
index e321121..635b3d1 100644
--- a/src/vm.c
+++ b/src/vm.c
@@ -136,6 +136,20 @@
}
/**
+ * Returns a locked instance of the VM with the corresponding id.
+ */
+struct vm_locked vm_find_locked(ffa_vm_id_t id)
+{
+ struct vm *vm = vm_find(id);
+
+ if (vm != NULL) {
+ return vm_lock(vm);
+ }
+
+ return (struct vm_locked){.vm = NULL};
+}
+
+/**
* Returns a pointer to the VM at the specified index.
*/
struct vm *vm_find_index(uint16_t index)