Add HVC/SMC call for debug logging.

Bug: 115484857
Change-Id: I253adf03ebde97d4b620be9d3f2cc05f5265f45d
diff --git a/inc/hf/api.h b/inc/hf/api.h
index af21d00..a808e5d 100644
--- a/inc/hf/api.h
+++ b/inc/hf/api.h
@@ -39,6 +39,7 @@
 int64_t api_mailbox_waiter_get(spci_vm_id_t vm_id, const struct vcpu *current);
 int64_t api_share_memory(spci_vm_id_t vm_id, ipaddr_t addr, size_t size,
 			 enum hf_share share, struct vcpu *current);
+int64_t api_debug_log(char c, struct vcpu *current);
 
 struct vcpu *api_preempt(struct vcpu *current);
 struct vcpu *api_wait_for_interrupt(struct vcpu *current);
diff --git a/inc/hf/dlog.h b/inc/hf/dlog.h
index 3e83624..01dddd9 100644
--- a/inc/hf/dlog.h
+++ b/inc/hf/dlog.h
@@ -18,6 +18,8 @@
 
 #include <stdarg.h>
 
+#include "vm.h"
+
 #if DEBUG
 void dlog_enable_lock(void);
 void dlog(const char *fmt, ...);
@@ -27,3 +29,5 @@
 #define dlog(...)
 #define vdlog(fmt, args)
 #endif
+
+void dlog_flush_vm_buffer(struct vm_locked vm);
diff --git a/inc/hf/vm.h b/inc/hf/vm.h
index 8930c11..4abff00 100644
--- a/inc/hf/vm.h
+++ b/inc/hf/vm.h
@@ -27,6 +27,8 @@
 
 #include "vmapi/hf/spci.h"
 
+#define LOG_BUFFER_SIZE 256
+
 enum mailbox_state {
 	/** There is no message in the mailbox. */
 	MAILBOX_STATE_EMPTY,
@@ -83,6 +85,8 @@
 	struct vcpu vcpus[MAX_CPUS];
 	struct mm_ptable ptable;
 	struct mailbox mailbox;
+	char log_buffer[LOG_BUFFER_SIZE];
+	size_t log_buffer_length;
 
 	/** Wait entries to be used when waiting on other VM mailboxes. */
 	struct wait_entry wait_entries[MAX_VMS];
diff --git a/inc/vmapi/hf/call.h b/inc/vmapi/hf/call.h
index 6e68a50..d04b914 100644
--- a/inc/vmapi/hf/call.h
+++ b/inc/vmapi/hf/call.h
@@ -37,6 +37,9 @@
 #define HF_INTERRUPT_INJECT     0xff0d
 #define HF_SHARE_MEMORY         0xff0e
 
+/* This matches what Trusty and its ATF module currently use. */
+#define HF_DEBUG_LOG            0xbd000000
+
 /* clang-format on */
 
 /**
@@ -244,6 +247,16 @@
 		       size);
 }
 
+/**
+ * Sends a character to the debug log for the VM.
+ *
+ * Returns 0 on success, or -1 if it failed for some reason.
+ */
+static inline int64_t hf_debug_log(char c)
+{
+	return hf_call(HF_DEBUG_LOG, c, 0, 0);
+}
+
 /** Obtains the Hafnium's version of the implemented SPCI specification. */
 static inline int64_t spci_version(void)
 {