Move common socket related code to separate header

The socket code is used by other components and unit tests.  Move it to a
common header file.

Bug: 138977432
Change-Id: I60ba153a2351269a2c69a4d9bc389b5e11761766
diff --git a/Makefile b/Makefile
index d98fd5a..6807442 100644
--- a/Makefile
+++ b/Makefile
@@ -21,7 +21,7 @@
 hafnium-y += main.o
 hafnium-y += hf_call.o
 
-ccflags-y = -I$(HAFNIUM_PATH)/inc/vmapi
+ccflags-y = -I$(HAFNIUM_PATH)/inc/vmapi -I$(PWD)/inc
 
 else
 
diff --git a/inc/uapi/hf/socket.h b/inc/uapi/hf/socket.h
new file mode 100644
index 0000000..26d6432
--- /dev/null
+++ b/inc/uapi/hf/socket.h
@@ -0,0 +1,32 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright 2019 The Hafnium Authors.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
+
+#include <linux/socket.h>
+
+#include <hf/spci.h>
+
+/* TODO: Reusing AF_ECONET for now as it's otherwise unused. */
+#define AF_HF AF_ECONET
+#define PF_HF AF_HF
+
+/*
+ * Address of a Hafnium socket
+ */
+struct hf_sockaddr {
+	__kernel_sa_family_t family;
+	spci_vm_id_t vm_id;
+	uint64_t port;
+};
diff --git a/main.c b/main.c
index 9b55798..20a67a1 100644
--- a/main.c
+++ b/main.c
@@ -32,10 +32,9 @@
 
 #include <hf/call.h>
 #include <hf/spci.h>
+#include <hf/transport.h>
 
-/* TODO: Reusing AF_ECONET for now as it's otherwise unused. */
-#define AF_HF AF_ECONET
-#define PF_HF AF_HF
+#include "uapi/hf/socket.h"
 
 #define HYPERVISOR_TIMER_NAME "el2_timer"
 
@@ -59,11 +58,6 @@
 	struct hf_vcpu *vcpu;
 };
 
-struct hf_msg_hdr {
-	uint64_t src_port;
-	uint64_t dst_port;
-};
-
 struct hf_sock {
 	/* This needs to be the first field. */
 	struct sock sk;
@@ -77,12 +71,6 @@
 	struct hf_vm *peer_vm;
 };
 
-struct sockaddr_hf {
-	sa_family_t family;
-	spci_vm_id_t vm_id;
-	uint64_t port;
-};
-
 static struct proto hf_sock_proto = {
 	.name = "hafnium",
 	.owner = THIS_MODULE,
@@ -516,15 +504,15 @@
 	struct sock *sk = sock->sk;
 	struct hf_sock *hsock = hsock_from_sk(sk);
 	struct hf_vm *vm;
-	struct sockaddr_hf *addr;
+	struct hf_sockaddr *addr;
 	int err;
 	unsigned long flags;
 
 	/* Basic address validation. */
-	if (len < sizeof(struct sockaddr_hf) || saddr->sa_family != AF_HF)
+	if (len < sizeof(struct hf_sockaddr) || saddr->sa_family != AF_HF)
 		return -EINVAL;
 
-	addr = (struct sockaddr_hf *)saddr;
+	addr = (struct hf_sockaddr *)saddr;
 	vm = hf_vm_from_id(addr->vm_id);
 	if (!vm)
 		return -ENETUNREACH;