Use spci_vm_id_t for VM IDs, and rename vm_get to vm_find.
This means that we consistently use _get for looking up by index, _find
for looking up by ID (even if the ID happens to be the same as the index
for now).
Change-Id: I54c958be771151316781f80e2057e3076fc4ae0c
diff --git a/inc/hf/api.h b/inc/hf/api.h
index 75a85e2..1de07ec 100644
--- a/inc/hf/api.h
+++ b/inc/hf/api.h
@@ -25,17 +25,17 @@
void api_init(struct mpool *ppool);
int64_t api_vm_get_id(const struct vcpu *current);
int64_t api_vm_get_count(void);
-int64_t api_vcpu_get_count(uint32_t vm_id, const struct vcpu *current);
+int64_t api_vcpu_get_count(spci_vm_id_t vm_id, const struct vcpu *current);
void api_regs_state_saved(struct vcpu *vcpu);
-struct hf_vcpu_run_return api_vcpu_run(uint32_t vm_id, uint32_t vcpu_idx,
+struct hf_vcpu_run_return api_vcpu_run(spci_vm_id_t vm_id, uint32_t vcpu_idx,
const struct vcpu *current,
struct vcpu **next);
int64_t api_vm_configure(ipaddr_t send, ipaddr_t recv, struct vcpu *current,
struct vcpu **next);
int64_t api_mailbox_clear(struct vcpu *current, struct vcpu **next);
int64_t api_mailbox_writable_get(const struct vcpu *current);
-int64_t api_mailbox_waiter_get(uint32_t vm_id, const struct vcpu *current);
-int64_t api_share_memory(uint32_t vm_id, ipaddr_t addr, size_t size,
+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);
struct vcpu *api_preempt(struct vcpu *current);
@@ -44,9 +44,9 @@
int64_t api_interrupt_enable(uint32_t intid, bool enable, struct vcpu *current);
uint32_t api_interrupt_get(struct vcpu *current);
-int64_t api_interrupt_inject(uint32_t target_vm_id, uint32_t target_vcpu_idx,
- uint32_t intid, struct vcpu *current,
- struct vcpu **next);
+int64_t api_interrupt_inject(spci_vm_id_t target_vm_id,
+ uint32_t target_vcpu_idx, uint32_t intid,
+ struct vcpu *current, struct vcpu **next);
int32_t api_spci_msg_send(uint32_t attributes, struct vcpu *current,
struct vcpu **next);
diff --git a/inc/hf/vm.h b/inc/hf/vm.h
index c54c5f0..9548f2b 100644
--- a/inc/hf/vm.h
+++ b/inc/hf/vm.h
@@ -94,7 +94,7 @@
bool vm_init(uint32_t vcpu_count, struct mpool *ppool, struct vm **new_vm);
uint32_t vm_get_count(void);
-struct vm *vm_get(uint32_t id);
+struct vm *vm_find(spci_vm_id_t id);
struct vm_locked vm_lock(struct vm *vm);
void vm_unlock(struct vm_locked *locked);
struct vcpu *vm_get_vcpu(struct vm *vm, uint32_t vcpu_index);
diff --git a/src/api.c b/src/api.c
index 7babccd..89500db 100644
--- a/src/api.c
+++ b/src/api.c
@@ -66,7 +66,7 @@
struct hf_vcpu_run_return primary_ret,
enum vcpu_state secondary_state)
{
- struct vm *primary = vm_get(HF_PRIMARY_VM_ID);
+ struct vm *primary = vm_find(HF_PRIMARY_VM_ID);
struct vcpu *next = vm_get_vcpu(primary, cpu_index(current->cpu));
/*
@@ -192,7 +192,7 @@
/**
* Returns the number of vcpus configured in the given VM.
*/
-int64_t api_vcpu_get_count(uint32_t vm_id, const struct vcpu *current)
+int64_t api_vcpu_get_count(spci_vm_id_t vm_id, const struct vcpu *current)
{
struct vm *vm;
@@ -201,7 +201,7 @@
return -1;
}
- vm = vm_get(vm_id);
+ vm = vm_find(vm_id);
if (vm == NULL) {
return -1;
}
@@ -458,7 +458,7 @@
/**
* Runs the given vcpu of the given vm.
*/
-struct hf_vcpu_run_return api_vcpu_run(uint32_t vm_id, uint32_t vcpu_idx,
+struct hf_vcpu_run_return api_vcpu_run(spci_vm_id_t vm_id, uint32_t vcpu_idx,
const struct vcpu *current,
struct vcpu **next)
{
@@ -480,7 +480,7 @@
}
/* The requested VM must exist. */
- vm = vm_get(vm_id);
+ vm = vm_find(vm_id);
if (vm == NULL) {
goto out;
}
@@ -780,7 +780,7 @@
}
/* Ensure the target VM exists. */
- to = vm_get(from_msg_replica.target_vm_id);
+ to = vm_find(from_msg_replica.target_vm_id);
if (to == NULL) {
return SPCI_INVALID_PARAMETERS;
}
@@ -946,7 +946,7 @@
* Returns -1 on failure or if there are no waiters; the VM id of the next
* waiter otherwise.
*/
-int64_t api_mailbox_waiter_get(uint32_t vm_id, const struct vcpu *current)
+int64_t api_mailbox_waiter_get(spci_vm_id_t vm_id, const struct vcpu *current)
{
struct vm *vm;
struct vm_locked locked;
@@ -958,7 +958,7 @@
return -1;
}
- vm = vm_get(vm_id);
+ vm = vm_find(vm_id);
if (vm == NULL) {
return -1;
}
@@ -1135,12 +1135,12 @@
* - 1 if it was called by the primary VM and the primary VM now needs to wake
* up or kick the target vCPU.
*/
-int64_t api_interrupt_inject(uint32_t target_vm_id, uint32_t target_vcpu_idx,
- uint32_t intid, struct vcpu *current,
- struct vcpu **next)
+int64_t api_interrupt_inject(spci_vm_id_t target_vm_id,
+ uint32_t target_vcpu_idx, uint32_t intid,
+ struct vcpu *current, struct vcpu **next)
{
struct vcpu *target_vcpu;
- struct vm *target_vm = vm_get(target_vm_id);
+ struct vm *target_vm = vm_find(target_vm_id);
if (intid >= HF_NUM_INTIDS) {
return -1;
@@ -1206,7 +1206,7 @@
* possibly allowing multiple blocks to be transferred. What this will
* look like is TBD.
*/
-int64_t api_share_memory(uint32_t vm_id, ipaddr_t addr, size_t size,
+int64_t api_share_memory(spci_vm_id_t vm_id, ipaddr_t addr, size_t size,
enum hf_share share, struct vcpu *current)
{
struct vm *from = current->vm;
@@ -1227,7 +1227,7 @@
}
/* Ensure the target VM exists. */
- to = vm_get(vm_id);
+ to = vm_find(vm_id);
if (to == NULL) {
return -1;
}
diff --git a/src/cpu.c b/src/cpu.c
index 7d181dc..e35b1ec 100644
--- a/src/cpu.c
+++ b/src/cpu.c
@@ -122,7 +122,7 @@
sl_unlock(&c->lock);
if (!prev) {
- struct vm *vm = vm_get(HF_PRIMARY_VM_ID);
+ struct vm *vm = vm_find(HF_PRIMARY_VM_ID);
struct vcpu *vcpu = vm_get_vcpu(vm, cpu_index(c));
struct vcpu_locked vcpu_locked;
diff --git a/src/load.c b/src/load.c
index c1da513..41c417c 100644
--- a/src/load.c
+++ b/src/load.c
@@ -267,7 +267,7 @@
memcpy_s(mem_ranges_available, sizeof(mem_ranges_available),
params->mem_ranges, sizeof(params->mem_ranges));
- primary = vm_get(HF_PRIMARY_VM_ID);
+ primary = vm_find(HF_PRIMARY_VM_ID);
if (!find_file(cpio, "vms.txt", &it)) {
dlog("vms.txt is missing\n");
diff --git a/src/main.c b/src/main.c
index bd4c319..e5dc7b7 100644
--- a/src/main.c
+++ b/src/main.c
@@ -146,7 +146,7 @@
panic("mm_cpu_init failed");
}
- vcpu = vm_get_vcpu(vm_get(HF_PRIMARY_VM_ID), cpu_index(c));
+ vcpu = vm_get_vcpu(vm_find(HF_PRIMARY_VM_ID), cpu_index(c));
vm = vcpu->vm;
vcpu->cpu = c;
diff --git a/src/vm.c b/src/vm.c
index c154eca..e9919d8 100644
--- a/src/vm.c
+++ b/src/vm.c
@@ -74,7 +74,7 @@
return vm_count;
}
-struct vm *vm_get(uint32_t id)
+struct vm *vm_find(spci_vm_id_t id)
{
/* Ensure the VM is initialized. */
if (id >= vm_count) {