feat(notifications): state structures and initialization

Defined the structures to keep track of Notifications state within
hafnium:
- 'struct notifications' keeps track of notification bindings, and
respective states (referring to 'struct notifications_state').
- 'struct notifications_state' keeps track of pending notifications and
those retrieved by the scheduler using FFA_NOTIFICATIONS_INFO_GET.
- Initialization of notifications structure, to allow for the
implementation of the notifications related FF-A calls.

The SPMC is responsible for maintaining the state of VM's notifications
from SPs. Reused 'struct vm' to represent NWd VMs, for simplicity and
scalability.

Change-Id: Id222aa0f6a11a29009668cfbae4edc067afd9130
Signed-off-by: J-Alves <joao.alves@arm.com>
diff --git a/inc/hf/arch/plat/ffa.h b/inc/hf/arch/plat/ffa.h
index 0d8813e..fde3bba 100644
--- a/inc/hf/arch/plat/ffa.h
+++ b/inc/hf/arch/plat/ffa.h
@@ -48,3 +48,8 @@
  */
 ffa_partition_properties_t plat_ffa_partition_properties(
 	ffa_vm_id_t current_id, const struct vm *target);
+
+/**
+ * Initializes the NWd VM structures for Notifications support.
+ */
+void plat_ffa_vm_init(void);
diff --git a/inc/hf/vm.h b/inc/hf/vm.h
index 1eccd91..f7a73da 100644
--- a/inc/hf/vm.h
+++ b/inc/hf/vm.h
@@ -92,6 +92,37 @@
 	struct list_entry ready_list;
 };
 
+struct notifications_state {
+	/**
+	 * To keep track of the notifications pending.
+	 * Set on call to FFA_NOTIFICATION_SET, and cleared on call to
+	 * FFA_NOTIFICATION_GET.
+	 */
+	ffa_notifications_bitmap_t pending;
+
+	/**
+	 * Set on FFA_NOTIFICATION_INFO_GET to keep track of the notifications
+	 * whose information has been retrieved by the referred ABI.
+	 * Cleared on call to FFA_NOTIFICATION_GET.
+	 */
+	ffa_notifications_bitmap_t info_get_retrieved;
+};
+
+struct notifications {
+	/**
+	 * The following array maps the notifications to the bound FF-A
+	 * endpoint.
+	 * The index in the bindings array relates to the notification
+	 * ID, and bit position in 'ffa_notifications_bitmap_t'.
+	 */
+	ffa_vm_id_t bindings_sender_id[MAX_FFA_NOTIFICATIONS];
+	ffa_notifications_bitmap_t bindings_per_vcpu;
+
+	/* The index of the array below relates to the ID of the VCPU. */
+	struct notifications_state per_vcpu[MAX_CPUS];
+	struct notifications_state global;
+};
+
 struct smc_whitelist {
 	uint32_t smcs[MAX_SMCS];
 	uint16_t smc_count;
@@ -109,6 +140,20 @@
 	struct vcpu vcpus[MAX_CPUS];
 	struct mm_ptable ptable;
 	struct mailbox mailbox;
+
+	struct {
+		/**
+		 * State structures for notifications coming from VMs or coming
+		 * from SPs. Both fields are maintained by the SPMC.
+		 * The hypervisor ignores the 'from_sp' field, given VM
+		 * notifications from SPs are managed by the SPMC.
+		 */
+		struct notifications from_vm;
+		struct notifications from_sp;
+		/* TODO: include framework notifications */
+		bool enabled;
+	} notifications;
+
 	char log_buffer[LOG_BUFFER_SIZE];
 	uint16_t log_buffer_length;
 
@@ -178,3 +223,5 @@
 
 void vm_update_boot(struct vm *vm);
 struct vm *vm_get_first_boot(void);
+
+void vm_notifications_init_bindings(struct notifications *n);