feat(notifications): bitmaps create and destroy

Handle FF-A calls FFA_NOTIFICATION_BITMAP_CREATE and
FFA_NOTIFICATION_BITMAP_DESTROY.
Interfaces are to be used by the NWd (Hypervisor or single OS kernel).

Change-Id: I0d805875ae6c7f8c080bda04e9e496d9e0d79b00
Signed-off-by: J-Alves <joao.alves@arm.com>
diff --git a/src/vm.c b/src/vm.c
index bb9d7f1..ff74763 100644
--- a/src/vm.c
+++ b/src/vm.c
@@ -82,9 +82,6 @@
 	vm_notifications_init_bindings(&vm->notifications.from_sp);
 	vm_notifications_init_bindings(&vm->notifications.from_vm);
 
-	/* TODO: Enable in accordance to VM's manifest. */
-	vm->notifications.enabled = true;
-
 	return vm;
 }
 
@@ -384,16 +381,6 @@
 	vm->next_boot = current;
 }
 
-/*
- * Initializes the notifications structure.
- */
-void vm_notifications_init_bindings(struct notifications *notifications)
-{
-	for (uint32_t i = 0U; i < MAX_FFA_NOTIFICATIONS; i++) {
-		notifications->bindings_sender_id[i] = HF_INVALID_VM_ID;
-	}
-}
-
 /**
  * Gets the mode of the given range of ipa or va if they are mapped with the
  * same mode.
@@ -412,3 +399,37 @@
 	}
 	return mm_vm_get_mode(&vm_locked.vm->ptable, begin, end, mode);
 }
+
+/*
+ * Initializes the notifications structure.
+ */
+void vm_notifications_init_bindings(struct notifications *notifications)
+{
+	for (uint32_t i = 0U; i < MAX_FFA_NOTIFICATIONS; i++) {
+		notifications->bindings_sender_id[i] = HF_INVALID_VM_ID;
+	}
+}
+
+/**
+ * Checks if there are pending notifications.
+ */
+bool vm_are_notifications_pending(struct vm_locked vm_locked, bool from_vm,
+				  ffa_notifications_bitmap_t notifications)
+{
+	struct notifications *to_check;
+
+	CHECK(vm_locked.vm != NULL);
+
+	to_check = from_vm ? &vm_locked.vm->notifications.from_vm
+			   : &vm_locked.vm->notifications.from_sp;
+
+	/* Check if there are pending per vcpu notifications */
+	for (uint32_t i = 0U; i < MAX_CPUS; i++) {
+		if ((to_check->per_vcpu[i].pending & notifications) != 0U) {
+			return true;
+		}
+	}
+
+	/* Check if there are global pending notifications */
+	return (to_check->global.pending & notifications) != 0U;
+}