Introducing hf_vcpu_count_t for vCPU count.
Return 0 rather than -1 on error.
Change-Id: I95cdde0744ef13e9bd748ce8ed32439d3d7f2010
diff --git a/driver/linux b/driver/linux
index afea42a..3eeb1de 160000
--- a/driver/linux
+++ b/driver/linux
@@ -1 +1 @@
-Subproject commit afea42a6cd9592170fb6fff362e998b3706a7512
+Subproject commit 3eeb1de32dc117cf58114ca7775b94a2197b0b2f
diff --git a/inc/hf/api.h b/inc/hf/api.h
index 4060075..43497bf 100644
--- a/inc/hf/api.h
+++ b/inc/hf/api.h
@@ -25,7 +25,8 @@
void api_init(struct mpool *ppool);
spci_vm_id_t api_vm_get_id(const struct vcpu *current);
spci_vm_count_t api_vm_get_count(void);
-int64_t api_vcpu_get_count(spci_vm_id_t vm_id, const struct vcpu *current);
+spci_vcpu_count_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(spci_vm_id_t vm_id,
spci_vcpu_index_t vcpu_idx,
diff --git a/inc/hf/vm.h b/inc/hf/vm.h
index bd8a905..c86da21 100644
--- a/inc/hf/vm.h
+++ b/inc/hf/vm.h
@@ -78,7 +78,7 @@
spci_vm_id_t id;
/** See api.c for the partial ordering on locks. */
struct spinlock lock;
- uint32_t vcpu_count;
+ spci_vcpu_count_t vcpu_count;
struct vcpu vcpus[MAX_CPUS];
struct mm_ptable ptable;
struct mailbox mailbox;
@@ -97,7 +97,8 @@
struct vm *vm;
};
-bool vm_init(uint32_t vcpu_count, struct mpool *ppool, struct vm **new_vm);
+bool vm_init(spci_vcpu_count_t vcpu_count, struct mpool *ppool,
+ struct vm **new_vm);
spci_vm_count_t vm_get_count(void);
struct vm *vm_find(spci_vm_id_t id);
struct vm_locked vm_lock(struct vm *vm);
diff --git a/inc/vmapi/hf/call.h b/inc/vmapi/hf/call.h
index 3ba985c..6e68a50 100644
--- a/inc/vmapi/hf/call.h
+++ b/inc/vmapi/hf/call.h
@@ -64,7 +64,7 @@
/**
* Returns the number of VCPUs configured in the given secondary VM.
*/
-static inline int64_t hf_vcpu_get_count(spci_vm_id_t vm_id)
+static inline spci_vcpu_count_t hf_vcpu_get_count(spci_vm_id_t vm_id)
{
return hf_call(HF_VCPU_GET_COUNT, vm_id, 0, 0);
}
diff --git a/inc/vmapi/hf/spci.h b/inc/vmapi/hf/spci.h
index 25e8e83..e55ea97 100644
--- a/inc/vmapi/hf/spci.h
+++ b/inc/vmapi/hf/spci.h
@@ -68,8 +68,16 @@
* different name to make the different semantics clear.
*/
typedef spci_vm_id_t spci_vm_count_t;
+
+/** The index of a vCPU within a particular VM. */
typedef uint16_t spci_vcpu_index_t;
+/**
+ * A count of vCPUs. This has the same range as the vCPU indices but we give it
+ * a different name to make the different semantics clear.
+ */
+typedef spci_vcpu_index_t spci_vcpu_count_t;
+
/** SPCI common message header. */
struct spci_message {
/*
diff --git a/src/api.c b/src/api.c
index 5506a04..bb954a6 100644
--- a/src/api.c
+++ b/src/api.c
@@ -224,20 +224,22 @@
}
/**
- * Returns the number of vcpus configured in the given VM.
+ * Returns the number of vCPUs configured in the given VM, or 0 if there is no
+ * such VM or the caller is not the primary VM.
*/
-int64_t api_vcpu_get_count(spci_vm_id_t vm_id, const struct vcpu *current)
+spci_vcpu_count_t api_vcpu_get_count(spci_vm_id_t vm_id,
+ const struct vcpu *current)
{
struct vm *vm;
/* Only the primary VM needs to know about vcpus for scheduling. */
if (current->vm->id != HF_PRIMARY_VM_ID) {
- return -1;
+ return 0;
}
vm = vm_find(vm_id);
if (vm == NULL) {
- return -1;
+ return 0;
}
return vm->vcpu_count;
diff --git a/src/vm.c b/src/vm.c
index 0119fd8..f1b79e6 100644
--- a/src/vm.c
+++ b/src/vm.c
@@ -27,7 +27,8 @@
static struct vm vms[MAX_VMS];
static spci_vm_count_t vm_count;
-bool vm_init(uint32_t vcpu_count, struct mpool *ppool, struct vm **new_vm)
+bool vm_init(spci_vcpu_count_t vcpu_count, struct mpool *ppool,
+ struct vm **new_vm)
{
uint32_t i;
struct vm *vm;
diff --git a/test/vmapi/primary_only/primary_only.c b/test/vmapi/primary_only/primary_only.c
index 3125b20..c57561d 100644
--- a/test/vmapi/primary_only/primary_only.c
+++ b/test/vmapi/primary_only/primary_only.c
@@ -54,7 +54,7 @@
*/
TEST(hf_vcpu_get_count, no_secondary_vms)
{
- EXPECT_EQ(hf_vcpu_get_count(1), -1);
+ EXPECT_EQ(hf_vcpu_get_count(1), 0);
}
/**
@@ -63,7 +63,7 @@
*/
TEST(hf_vcpu_get_count, large_invalid_vm_index)
{
- EXPECT_EQ(hf_vcpu_get_count(0xffff), -1);
+ EXPECT_EQ(hf_vcpu_get_count(0xffff), 0);
}
/**
diff --git a/test/vmapi/primary_with_secondaries/no_services.c b/test/vmapi/primary_with_secondaries/no_services.c
index e2c52f1..7b171e8 100644
--- a/test/vmapi/primary_with_secondaries/no_services.c
+++ b/test/vmapi/primary_with_secondaries/no_services.c
@@ -64,7 +64,7 @@
*/
TEST(hf_vcpu_get_count, large_invalid_vm_index)
{
- EXPECT_EQ(hf_vcpu_get_count(0xffff), -1);
+ EXPECT_EQ(hf_vcpu_get_count(0xffff), 0);
}
/**