Introduce typedef for vCPU index.
Change-Id: I51194706edb86811487f2a22b3bda5405e605b5e
diff --git a/src/api.c b/src/api.c
index ccbeeda..91b582d 100644
--- a/src/api.c
+++ b/src/api.c
@@ -22,6 +22,7 @@
#include "hf/assert.h"
#include "hf/dlog.h"
#include "hf/mm.h"
+#include "hf/spci.h"
#include "hf/spinlock.h"
#include "hf/std.h"
#include "hf/vm.h"
@@ -481,7 +482,8 @@
/**
* Runs the given vcpu of the given vm.
*/
-struct hf_vcpu_run_return api_vcpu_run(spci_vm_id_t vm_id, uint32_t vcpu_idx,
+struct hf_vcpu_run_return api_vcpu_run(spci_vm_id_t vm_id,
+ spci_vcpu_index_t vcpu_idx,
const struct vcpu *current,
struct vcpu **next)
{
@@ -1159,7 +1161,7 @@
* up or kick the target vCPU.
*/
int64_t api_interrupt_inject(spci_vm_id_t target_vm_id,
- uint32_t target_vcpu_idx, uint32_t intid,
+ spci_vcpu_index_t target_vcpu_idx, uint32_t intid,
struct vcpu *current, struct vcpu **next)
{
struct vcpu *target_vcpu;
diff --git a/src/arch/aarch64/hypervisor/handler.c b/src/arch/aarch64/hypervisor/handler.c
index 7943401..04223db 100644
--- a/src/arch/aarch64/hypervisor/handler.c
+++ b/src/arch/aarch64/hypervisor/handler.c
@@ -134,7 +134,7 @@
void maybe_invalidate_tlb(struct vcpu *vcpu)
{
size_t current_cpu_index = cpu_index(vcpu->cpu);
- size_t new_vcpu_index = vcpu_index(vcpu);
+ spci_vcpu_index_t new_vcpu_index = vcpu_index(vcpu);
if (vcpu->vm->arch.last_vcpu_on_cpu[current_cpu_index] !=
new_vcpu_index) {
diff --git a/src/arch/aarch64/hypervisor/psci_handler.c b/src/arch/aarch64/hypervisor/psci_handler.c
index 76e4798..2736814 100644
--- a/src/arch/aarch64/hypervisor/psci_handler.c
+++ b/src/arch/aarch64/hypervisor/psci_handler.c
@@ -24,6 +24,7 @@
#include "hf/cpu.h"
#include "hf/dlog.h"
#include "hf/panic.h"
+#include "hf/spci.h"
#include "hf/vm.h"
#include "psci.h"
@@ -227,7 +228,7 @@
* Convert a PSCI CPU / affinity ID for a secondary VM to the corresponding vCPU
* index.
*/
-uint32_t vcpu_id_to_index(uint64_t vcpu_id)
+spci_vcpu_index_t vcpu_id_to_index(uint64_t vcpu_id)
{
/* For now we use indices as IDs for the purposes of PSCI. */
return vcpu_id;
@@ -282,7 +283,8 @@
uint32_t lowest_affinity_level = arg1;
struct vm *vm = vcpu->vm;
struct vcpu_locked target_vcpu;
- uint32_t target_vcpu_index = vcpu_id_to_index(target_affinity);
+ spci_vcpu_index_t target_vcpu_index =
+ vcpu_id_to_index(target_affinity);
if (lowest_affinity_level != 0) {
/* Affinity levels greater than 0 not supported. */
@@ -327,7 +329,8 @@
uint64_t target_cpu = arg0;
ipaddr_t entry_point_address = ipa_init(arg1);
uint64_t context_id = arg2;
- uint32_t target_vcpu_index = vcpu_id_to_index(target_cpu);
+ spci_vcpu_index_t target_vcpu_index =
+ vcpu_id_to_index(target_cpu);
struct vm *vm = vcpu->vm;
struct vcpu *target_vcpu;
diff --git a/src/arch/aarch64/inc/hf/arch/types.h b/src/arch/aarch64/inc/hf/arch/types.h
index cc1cbef..527ce92 100644
--- a/src/arch/aarch64/inc/hf/arch/types.h
+++ b/src/arch/aarch64/inc/hf/arch/types.h
@@ -20,6 +20,7 @@
#include <stdint.h>
#include "hf/assert.h"
+#include "hf/spci.h"
#define PAGE_BITS 12
#define PAGE_LEVEL_BITS 9
@@ -58,7 +59,7 @@
* on that CPU, which avoids contention and so no lock is needed to
* access this field.
*/
- uint32_t last_vcpu_on_cpu[MAX_CPUS];
+ spci_vcpu_index_t last_vcpu_on_cpu[MAX_CPUS];
};
/** Type to represent the register state of a vCPU. */
diff --git a/src/cpu.c b/src/cpu.c
index affba4a..eeea904 100644
--- a/src/cpu.c
+++ b/src/cpu.c
@@ -22,6 +22,7 @@
#include "hf/api.h"
#include "hf/dlog.h"
+#include "hf/spci.h"
#include "hf/std.h"
#include "hf/vm.h"
@@ -203,9 +204,12 @@
vcpu.vcpu->state = VCPU_STATE_READY;
}
-size_t vcpu_index(const struct vcpu *vcpu)
+spci_vcpu_index_t vcpu_index(const struct vcpu *vcpu)
{
- return vcpu - vcpu->vm->vcpus;
+ size_t index = vcpu - vcpu->vm->vcpus;
+
+ assert(index < UINT16_MAX);
+ return index;
}
/**
diff --git a/src/vm.c b/src/vm.c
index 8532144..7c5166b 100644
--- a/src/vm.c
+++ b/src/vm.c
@@ -18,6 +18,7 @@
#include "hf/api.h"
#include "hf/cpu.h"
+#include "hf/spci.h"
#include "hf/std.h"
#include "vmapi/hf/call.h"
@@ -112,7 +113,7 @@
* Get the vCPU with the given index from the given VM.
* This assumes the index is valid, i.e. less than vm->vcpu_count.
*/
-struct vcpu *vm_get_vcpu(struct vm *vm, uint32_t vcpu_index)
+struct vcpu *vm_get_vcpu(struct vm *vm, spci_vcpu_index_t vcpu_index)
{
assert(vcpu_index < vm->vcpu_count);
return &vm->vcpus[vcpu_index];