Consistently use spci_vm_id_t for VM ID.
Before we had a mix of spci_vm_id_t, uint32_t and uint64_t.
Change-Id: I7b51e48490f0f54064e1121242052873bddad2b5
diff --git a/driver/linux b/driver/linux
index ece5ef4..01390ae 160000
--- a/driver/linux
+++ b/driver/linux
@@ -1 +1 @@
-Subproject commit ece5ef4a217938841e3157d258212c6d29e3a326
+Subproject commit 01390ae4e344f1363f1c169e3430fa3e72cafaee
diff --git a/inc/hf/arch/cpu.h b/inc/hf/arch/cpu.h
index ccacbbb..384da06 100644
--- a/inc/hf/arch/cpu.h
+++ b/inc/hf/arch/cpu.h
@@ -24,6 +24,8 @@
#include "hf/addr.h"
+#include "vmapi/hf/spci.h"
+
/**
* Disables interrutps.
*/
@@ -38,7 +40,7 @@
* Reset the register values other than the PC and argument which are set with
* `arch_regs_set_pc_arg()`.
*/
-void arch_regs_reset(struct arch_regs *r, bool is_primary, uint64_t vm_id,
+void arch_regs_reset(struct arch_regs *r, bool is_primary, spci_vm_id_t vm_id,
uint64_t vcpu_id, paddr_t table);
/**
diff --git a/inc/hf/vm.h b/inc/hf/vm.h
index 9548f2b..e35edc6 100644
--- a/inc/hf/vm.h
+++ b/inc/hf/vm.h
@@ -73,7 +73,7 @@
};
struct vm {
- uint32_t id;
+ spci_vm_id_t id;
/** See api.c for the partial ordering on locks. */
struct spinlock lock;
uint32_t vcpu_count;
diff --git a/inc/vmapi/hf/abi.h b/inc/vmapi/hf/abi.h
index 55c7491..a625a8e 100644
--- a/inc/vmapi/hf/abi.h
+++ b/inc/vmapi/hf/abi.h
@@ -16,6 +16,7 @@
#pragma once
+#include "hf/spci.h"
#include "hf/types.h"
enum hf_vcpu_run_code {
@@ -88,11 +89,11 @@
enum hf_vcpu_run_code code;
union {
struct {
- uint32_t vm_id;
+ spci_vm_id_t vm_id;
uint16_t vcpu;
} wake_up;
struct {
- uint16_t vm_id;
+ spci_vm_id_t vm_id;
} message;
struct {
uint64_t ns;
diff --git a/inc/vmapi/hf/call.h b/inc/vmapi/hf/call.h
index 69296d6..239244f 100644
--- a/inc/vmapi/hf/call.h
+++ b/inc/vmapi/hf/call.h
@@ -48,7 +48,7 @@
/**
* Returns the VM's own ID.
*/
-static inline uint32_t hf_vm_get_id(void)
+static inline spci_vm_id_t hf_vm_get_id(void)
{
return hf_call(HF_VM_GET_ID, 0, 0, 0);
}
@@ -64,7 +64,7 @@
/**
* Returns the number of VCPUs configured in the given secondary VM.
*/
-static inline int64_t hf_vcpu_get_count(uint32_t vm_id)
+static inline int64_t hf_vcpu_get_count(spci_vm_id_t vm_id)
{
return hf_call(HF_VCPU_GET_COUNT, vm_id, 0, 0);
}
@@ -74,7 +74,7 @@
*
* Returns an hf_vcpu_run_return struct telling the scheduler what to do next.
*/
-static inline struct hf_vcpu_run_return hf_vcpu_run(uint32_t vm_id,
+static inline struct hf_vcpu_run_return hf_vcpu_run(spci_vm_id_t vm_id,
uint32_t vcpu_idx)
{
return hf_vcpu_run_return_decode(
@@ -179,7 +179,7 @@
* Returns -1 on failure or if there are no waiters; the VM id of the next
* waiter otherwise.
*/
-static inline int64_t hf_mailbox_waiter_get(uint32_t vm_id)
+static inline int64_t hf_mailbox_waiter_get(spci_vm_id_t vm_id)
{
return hf_call(HF_MAILBOX_WAITER_GET, vm_id, 0, 0);
}
@@ -217,7 +217,7 @@
* - 1 if it was called by the primary VM and the primary VM now needs to wake
* up or kick the target vCPU.
*/
-static inline int64_t hf_interrupt_inject(uint32_t target_vm_id,
+static inline int64_t hf_interrupt_inject(spci_vm_id_t target_vm_id,
uint32_t target_vcpu_idx,
uint32_t intid)
{
@@ -233,7 +233,7 @@
* TODO: replace this with a better API once we have decided what that should
* look like.
*/
-static inline int64_t hf_share_memory(uint32_t vm_id, hf_ipaddr_t addr,
+static inline int64_t hf_share_memory(spci_vm_id_t vm_id, hf_ipaddr_t addr,
size_t size, enum hf_share share)
{
return hf_call(HF_SHARE_MEMORY, (((uint64_t)vm_id) << 32) | share, addr,
diff --git a/src/abi_test.cc b/src/abi_test.cc
index ed060e8..204472d 100644
--- a/src/abi_test.cc
+++ b/src/abi_test.cc
@@ -151,9 +151,9 @@
{
struct hf_vcpu_run_return res = dirty_vcpu_run_return();
res.code = HF_VCPU_RUN_WAKE_UP;
- res.wake_up.vm_id = 0x12345678;
+ res.wake_up.vm_id = 0x1234;
res.wake_up.vcpu = 0xabcd;
- EXPECT_THAT(hf_vcpu_run_return_encode(res), Eq(0x12345678abcd0004));
+ EXPECT_THAT(hf_vcpu_run_return_encode(res), Eq(0x1234abcd0004));
}
/**
@@ -162,9 +162,9 @@
TEST(abi, hf_vcpu_run_return_decode_wake_up)
{
struct hf_vcpu_run_return res =
- hf_vcpu_run_return_decode(0xbeefd00df00daf04);
+ hf_vcpu_run_return_decode(0xbeeff00daf04);
EXPECT_THAT(res.code, Eq(HF_VCPU_RUN_WAKE_UP));
- EXPECT_THAT(res.wake_up.vm_id, Eq(0xbeefd00d));
+ EXPECT_THAT(res.wake_up.vm_id, Eq(0xbeef));
EXPECT_THAT(res.wake_up.vcpu, Eq(0xf00d));
}
diff --git a/src/arch/aarch64/cpu.c b/src/arch/aarch64/cpu.c
index bfe9c42..dae0fd8 100644
--- a/src/arch/aarch64/cpu.c
+++ b/src/arch/aarch64/cpu.c
@@ -47,7 +47,7 @@
#endif
}
-void arch_regs_reset(struct arch_regs *r, bool is_primary, uint64_t vm_id,
+void arch_regs_reset(struct arch_regs *r, bool is_primary, spci_vm_id_t vm_id,
uint64_t vcpu_id, paddr_t table)
{
uintreg_t pc = r->pc;
@@ -90,7 +90,7 @@
r->lazy.hcr_el2 = hcr;
r->lazy.cptr_el2 = cptr;
r->lazy.cnthctl_el2 = cnthctl;
- r->lazy.vttbr_el2 = pa_addr(table) | (vm_id << 48);
+ r->lazy.vttbr_el2 = pa_addr(table) | ((uint64_t)vm_id << 48);
r->lazy.vmpidr_el2 = vcpu_id;
/* TODO: Use constant here. */
r->spsr = 5 | /* M bits, set to EL1h. */
diff --git a/src/arch/fake/hypervisor/cpu.c b/src/arch/fake/hypervisor/cpu.c
index 0f206fc..8542dbc 100644
--- a/src/arch/fake/hypervisor/cpu.c
+++ b/src/arch/fake/hypervisor/cpu.c
@@ -26,7 +26,7 @@
/* TODO */
}
-void arch_regs_reset(struct arch_regs *r, bool is_primary, uint64_t vm_id,
+void arch_regs_reset(struct arch_regs *r, bool is_primary, spci_vm_id_t vm_id,
uint64_t vcpu_id, paddr_t table)
{
/* TODO */
diff --git a/test/vmapi/primary_only/primary_only.c b/test/vmapi/primary_only/primary_only.c
index 984a846..3125b20 100644
--- a/test/vmapi/primary_only/primary_only.c
+++ b/test/vmapi/primary_only/primary_only.c
@@ -63,7 +63,7 @@
*/
TEST(hf_vcpu_get_count, large_invalid_vm_index)
{
- EXPECT_EQ(hf_vcpu_get_count(0xffffffff), -1);
+ EXPECT_EQ(hf_vcpu_get_count(0xffff), -1);
}
/**
diff --git a/test/vmapi/primary_with_secondaries/mailbox.c b/test/vmapi/primary_with_secondaries/mailbox.c
index 28eda77..adb4ba2 100644
--- a/test/vmapi/primary_with_secondaries/mailbox.c
+++ b/test/vmapi/primary_with_secondaries/mailbox.c
@@ -159,14 +159,15 @@
* SERVICE_VM0, then to SERVICE_VM1 and finally back to here.
*/
{
- uint32_t *chain = (uint32_t *)mb.send->payload;
+ spci_vm_id_t *chain = (spci_vm_id_t *)mb.send->payload;
*chain++ = htole32(SERVICE_VM1);
*chain++ = htole32(HF_PRIMARY_VM_ID);
- memcpy_s(chain, SPCI_MSG_PAYLOAD_MAX - (2 * sizeof(uint32_t)),
+ memcpy_s(chain,
+ SPCI_MSG_PAYLOAD_MAX - (2 * sizeof(spci_vm_id_t)),
message, sizeof(message));
spci_message_init(mb.send,
- sizeof(message) + (2 * sizeof(uint32_t)),
+ sizeof(message) + (2 * sizeof(spci_vm_id_t)),
SERVICE_VM0, HF_PRIMARY_VM_ID);
EXPECT_EQ(spci_msg_send(0), 0);
}
@@ -181,7 +182,7 @@
run_res = hf_vcpu_run(SERVICE_VM1, 0);
EXPECT_EQ(run_res.code, HF_VCPU_RUN_MESSAGE);
- /* Ensure the message is in tact. */
+ /* Ensure the message is intact. */
EXPECT_EQ(run_res.message.vm_id, HF_PRIMARY_VM_ID);
EXPECT_EQ(mb.recv->length, sizeof(message));
EXPECT_EQ(memcmp(mb.recv->payload, message, sizeof(message)), 0);
diff --git a/test/vmapi/primary_with_secondaries/no_services.c b/test/vmapi/primary_with_secondaries/no_services.c
index b6e27be..98687ec 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(0xffffffff), -1);
+ EXPECT_EQ(hf_vcpu_get_count(0xffff), -1);
}
/**
diff --git a/test/vmapi/primary_with_secondaries/services/interruptible.c b/test/vmapi/primary_with_secondaries/services/interruptible.c
index 3df67eb..5a04515 100644
--- a/test/vmapi/primary_with_secondaries/services/interruptible.c
+++ b/test/vmapi/primary_with_secondaries/services/interruptible.c
@@ -64,7 +64,7 @@
TEST_SERVICE(interruptible)
{
- uint32_t this_vm_id = hf_vm_get_id();
+ spci_vm_id_t this_vm_id = hf_vm_get_id();
struct spci_message *recv_buf = SERVICE_RECV_BUFFER();
exception_setup(irq);
diff --git a/test/vmapi/primary_with_secondaries/services/relay.c b/test/vmapi/primary_with_secondaries/services/relay.c
index 413fbbf..5ccda5f 100644
--- a/test/vmapi/primary_with_secondaries/services/relay.c
+++ b/test/vmapi/primary_with_secondaries/services/relay.c
@@ -30,8 +30,8 @@
* message so multiple IDs can be places at the start of the message.
*/
for (;;) {
- uint32_t *chain;
- uint32_t next_vm_id;
+ spci_vm_id_t *chain;
+ spci_vm_id_t next_vm_id;
void *next_message;
uint32_t next_message_size;
@@ -41,12 +41,12 @@
/* Prepare to relay the message. */
struct spci_message *recv_buf = SERVICE_RECV_BUFFER();
struct spci_message *send_buf = SERVICE_SEND_BUFFER();
- ASSERT_GE(recv_buf->length, sizeof(uint32_t));
+ ASSERT_GE(recv_buf->length, sizeof(spci_vm_id_t));
- chain = (uint32_t *)recv_buf->payload;
- next_vm_id = le32toh(*chain);
+ chain = (spci_vm_id_t *)recv_buf->payload;
+ next_vm_id = le16toh(*chain);
next_message = chain + 1;
- next_message_size = recv_buf->length - sizeof(uint32_t);
+ next_message_size = recv_buf->length - sizeof(spci_vm_id_t);
/* Send the message to the next stage. */
memcpy_s(send_buf->payload, SPCI_MSG_PAYLOAD_MAX, next_message,