Use hf/call.h shared header.
Change-Id: I4f4ea20ad08d03ee46dfdd8fb76207e3b53e3b77
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..8fd2089
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,7 @@
+*.ko
+*.mod.c
+*.o
+.*o.cmd
+.tmp_versions/
+Module.symvers
+modules.order
diff --git a/Makefile b/Makefile
index 5318d5b..8b10ec1 100644
--- a/Makefile
+++ b/Makefile
@@ -1,9 +1,15 @@
-KERNEL_PATH ?= ../linux
+# By default, assume this was checked out as a submodule of the Hafnium repo
+# and that Linux was checked out along side that checkout. These paths can be
+# overridden if that assumption is incorrect.
+HAFNIUM_PATH ?= $(PWD)/../..
+KERNEL_PATH ?= $(HAFNIUM_PATH)/../linux
obj-m += hafnium.o
hafnium-y += main.o
-hafnium-y += hvc.o
+hafnium-y += hf_call.o
+
+ccflags-y = -I$(HAFNIUM_PATH)/inc/vmapi
all:
make -C $(KERNEL_PATH) M=$(PWD) modules
diff --git a/hf_call.S b/hf_call.S
new file mode 100644
index 0000000..07743ca
--- /dev/null
+++ b/hf_call.S
@@ -0,0 +1,6 @@
+.text
+
+.global hf_call
+hf_call:
+ hvc #0
+ ret
diff --git a/hvc.S b/hvc.S
deleted file mode 100644
index bec077b..0000000
--- a/hvc.S
+++ /dev/null
@@ -1,6 +0,0 @@
-.text
-
-.global hf_hvc
-hf_hvc:
- hvc #0
- ret
diff --git a/main.c b/main.c
index a0c8641..a985fb7 100644
--- a/main.c
+++ b/main.c
@@ -7,10 +7,12 @@
#include <linux/sched/task.h>
#include <linux/slab.h>
+#include <hf/call.h>
+
struct hf_vcpu {
spinlock_t lock;
- long vm_index;
- long vcpu_index;
+ uint32_t vm_index;
+ uint32_t vcpu_index;
struct task_struct *task;
struct hrtimer timer;
bool pending_irq;
@@ -21,23 +23,11 @@
struct hf_vcpu *vcpu;
};
-long hf_hvc(size_t arg0, size_t arg1, size_t arg2, size_t arg3);
-
static struct hf_vm *hf_vms;
static long hf_vm_count;
static struct page *hf_send_page = NULL;
static struct page *hf_recv_page = NULL;
-/* TODO: Define constants below according to spec. Include shared header. */
-#define HF_VCPU_RUN 0xff00
-#define HF_VM_GET_COUNT 0xff01
-#define HF_VCPU_GET_COUNT 0xff02
-#define HF_VM_CONFIGURE 0xff03
-#define HF_RPC_REQUEST 0xff04
-#define HF_RPC_READ_REQUEST 0xff05
-#define HF_RPC_ACK 0xff06
-#define HF_RPC_REPLY 0xff07
-
/**
* Wakes up the thread associated with the vcpu that owns the given timer. This
* is called when the timer the thread is waiting on expires.
@@ -73,8 +63,7 @@
spin_unlock_irqrestore(&vcpu->lock, flags);
/* Call into hafnium to run vcpu. */
- ret = hf_hvc(HF_VCPU_RUN, vcpu->vm_index, vcpu->vcpu_index,
- irqs);
+ ret = hf_vcpu_run(vcpu->vm_index, vcpu->vcpu_index);
/* A negative return value indicates that this vcpu needs to
* sleep for the given number of nanoseconds.
@@ -119,7 +108,7 @@
for (i = 0; i < count; i++)
printk(KERN_CONT "%c", buf[i]);
printk(KERN_CONT "\n");
- hf_hvc(HF_RPC_ACK, 0, 0, 0);
+ hf_rpc_ack();
}
break;
}
@@ -199,7 +188,7 @@
/* Copy data to send buffer. */
memcpy(page_address(hf_send_page), buf, count);
- ret = hf_hvc(HF_RPC_REQUEST, 0, count, 0);
+ ret = hf_rpc_request(0, count);
if (ret < 0)
return -EAGAIN;
@@ -256,8 +245,8 @@
* because the hypervisor will use them, even if the module is
* unloaded.
*/
- ret = hf_hvc(HF_VM_CONFIGURE, (size_t)page_to_phys(hf_send_page),
- (size_t)page_to_phys(hf_recv_page), 0);
+ ret = hf_vm_configure(page_to_phys(hf_send_page),
+ page_to_phys(hf_recv_page));
if (ret) {
__free_page(hf_send_page);
__free_page(hf_recv_page);
@@ -268,7 +257,7 @@
}
/* Get the number of VMs and allocate storage for them. */
- ret = hf_hvc(HF_VM_GET_COUNT, 0, 0, 0);
+ ret = hf_vm_get_count();
if (ret < 0) {
pr_err("Unable to retrieve number of VMs: %ld\n", ret);
return ret;
@@ -283,7 +272,7 @@
for (i = 0; i < hf_vm_count; i++) {
struct hf_vm *vm = hf_vms + i;
- ret = hf_hvc(HF_VCPU_GET_COUNT, i, 0, 0);
+ ret = hf_vcpu_get_count(i);
if (ret < 0) {
pr_err("HF_VCPU_GET_COUNT failed for vm=%ld: %ld", i,
ret);