refactor(interrupts): make bitmap and count functions private
Move the functions to modify the interrupt bitmap or count into
vcpu.c and make them static so only the getter functions can be
accessed externally. This helps ensure consistency between the
bitmap, queue and count.
Also rename the count_get functions to match the
vcpu_virt_interrupt_ naming used for other public functions
for virtual interrupts within the vcpu.c file.
Signed-off-by: Daniel Boulby <daniel.boulby@arm.com>
Change-Id: Id4eaa76f448ddddfd9ca99e2e12789b0c57c20f3
diff --git a/inc/hf/vcpu.h b/inc/hf/vcpu.h
index f335b9d..2e26ff4 100644
--- a/inc/hf/vcpu.h
+++ b/inc/hf/vcpu.h
@@ -259,124 +259,6 @@
void vcpu_set_phys_core_idx(struct vcpu *vcpu);
void vcpu_set_boot_info_gp_reg(struct vcpu *vcpu);
-static inline bool vcpu_is_virt_interrupt_enabled(struct interrupts *interrupts,
- uint32_t intid)
-{
- return interrupt_bitmap_get_value(&interrupts->interrupt_enabled,
- intid) == 1U;
-}
-
-static inline void vcpu_virt_interrupt_set_enabled(
- struct interrupts *interrupts, uint32_t intid)
-{
- interrupt_bitmap_set_value(&interrupts->interrupt_enabled, intid);
-}
-
-static inline void vcpu_virt_interrupt_clear_enabled(
- struct interrupts *interrupts, uint32_t intid)
-{
- interrupt_bitmap_clear_value(&interrupts->interrupt_enabled, intid);
-}
-
-static inline bool vcpu_is_virt_interrupt_pending(struct interrupts *interrupts,
- uint32_t intid)
-{
- return interrupt_bitmap_get_value(&interrupts->interrupt_pending,
- intid) == 1U;
-}
-
-static inline void vcpu_virt_interrupt_set_pending(
- struct interrupts *interrupts, uint32_t intid)
-{
- interrupt_bitmap_set_value(&interrupts->interrupt_pending, intid);
-}
-
-static inline void vcpu_virt_interrupt_clear_pending(
- struct interrupts *interrupts, uint32_t intid)
-{
- interrupt_bitmap_clear_value(&interrupts->interrupt_pending, intid);
-}
-
-static inline enum interrupt_type vcpu_virt_interrupt_get_type(
- struct interrupts *interrupts, uint32_t intid)
-{
- return (enum interrupt_type)interrupt_bitmap_get_value(
- &interrupts->interrupt_type, intid);
-}
-
-static inline void vcpu_virt_interrupt_set_type(struct interrupts *interrupts,
- uint32_t intid,
- enum interrupt_type type)
-{
- if (type == INTERRUPT_TYPE_IRQ) {
- interrupt_bitmap_clear_value(&interrupts->interrupt_type,
- intid);
- } else {
- interrupt_bitmap_set_value(&interrupts->interrupt_type, intid);
- }
-}
-
-static inline void vcpu_irq_count_increment(struct vcpu_locked vcpu_locked)
-{
- vcpu_locked.vcpu->interrupts.enabled_and_pending_irq_count++;
-}
-
-static inline void vcpu_irq_count_decrement(struct vcpu_locked vcpu_locked)
-{
- vcpu_locked.vcpu->interrupts.enabled_and_pending_irq_count--;
-}
-
-static inline void vcpu_fiq_count_increment(struct vcpu_locked vcpu_locked)
-{
- vcpu_locked.vcpu->interrupts.enabled_and_pending_fiq_count++;
-}
-
-static inline void vcpu_fiq_count_decrement(struct vcpu_locked vcpu_locked)
-{
- vcpu_locked.vcpu->interrupts.enabled_and_pending_fiq_count--;
-}
-static inline void vcpu_interrupt_count_increment(
- struct vcpu_locked vcpu_locked, struct interrupts *interrupts,
- uint32_t intid)
-{
- if (vcpu_virt_interrupt_get_type(interrupts, intid) ==
- INTERRUPT_TYPE_IRQ) {
- vcpu_irq_count_increment(vcpu_locked);
- } else {
- vcpu_fiq_count_increment(vcpu_locked);
- }
-}
-
-static inline void vcpu_interrupt_count_decrement(
- struct vcpu_locked vcpu_locked, struct interrupts *interrupts,
- uint32_t intid)
-{
- if (vcpu_virt_interrupt_get_type(interrupts, intid) ==
- INTERRUPT_TYPE_IRQ) {
- vcpu_irq_count_decrement(vcpu_locked);
- } else {
- vcpu_fiq_count_decrement(vcpu_locked);
- }
-}
-
-static inline uint32_t vcpu_interrupt_irq_count_get(
- struct vcpu_locked vcpu_locked)
-{
- return vcpu_locked.vcpu->interrupts.enabled_and_pending_irq_count;
-}
-
-static inline uint32_t vcpu_interrupt_fiq_count_get(
- struct vcpu_locked vcpu_locked)
-{
- return vcpu_locked.vcpu->interrupts.enabled_and_pending_fiq_count;
-}
-
-static inline uint32_t vcpu_interrupt_count_get(struct vcpu_locked vcpu_locked)
-{
- return vcpu_locked.vcpu->interrupts.enabled_and_pending_irq_count +
- vcpu_locked.vcpu->interrupts.enabled_and_pending_fiq_count;
-}
-
static inline void vcpu_call_chain_extend(struct vcpu_locked vcpu1_locked,
struct vcpu_locked vcpu2_locked)
{
@@ -422,13 +304,65 @@
void vcpu_save_interrupt_priority(struct vcpu_locked vcpu_locked,
uint8_t priority);
+void vcpu_enter_secure_interrupt_rtm(struct vcpu_locked vcpu_locked);
+
+void vcpu_secure_interrupt_complete(struct vcpu_locked vcpu_locked);
+
+static inline bool vcpu_is_virt_interrupt_enabled(struct interrupts *interrupts,
+ uint32_t intid)
+{
+ return interrupt_bitmap_get_value(&interrupts->interrupt_enabled,
+ intid) == 1U;
+}
+
+static inline void vcpu_virt_interrupt_set_enabled(
+ struct interrupts *interrupts, uint32_t intid)
+{
+ interrupt_bitmap_set_value(&interrupts->interrupt_enabled, intid);
+}
+
+static inline void vcpu_virt_interrupt_clear_enabled(
+ struct interrupts *interrupts, uint32_t intid)
+{
+ interrupt_bitmap_clear_value(&interrupts->interrupt_enabled, intid);
+}
+
+static inline bool vcpu_is_virt_interrupt_pending(struct interrupts *interrupts,
+ uint32_t intid)
+{
+ return interrupt_bitmap_get_value(&interrupts->interrupt_pending,
+ intid) == 1U;
+}
+
+static inline enum interrupt_type vcpu_virt_interrupt_get_type(
+ struct interrupts *interrupts, uint32_t intid)
+{
+ return (enum interrupt_type)interrupt_bitmap_get_value(
+ &interrupts->interrupt_type, intid);
+}
+
+static inline void vcpu_virt_interrupt_set_type(struct interrupts *interrupts,
+ uint32_t intid,
+ enum interrupt_type type)
+{
+ if (type == INTERRUPT_TYPE_IRQ) {
+ interrupt_bitmap_clear_value(&interrupts->interrupt_type,
+ intid);
+ } else {
+ interrupt_bitmap_set_value(&interrupts->interrupt_type, intid);
+ }
+}
+
+uint32_t vcpu_virt_interrupt_irq_count_get(struct vcpu_locked vcpu_locked);
+uint32_t vcpu_virt_interrupt_fiq_count_get(struct vcpu_locked vcpu_locked);
+uint32_t vcpu_virt_interrupt_count_get(struct vcpu_locked vcpu_locked);
+
+void vcpu_virt_interrupt_enable(struct vcpu_locked vcpu_locked,
+ uint32_t vint_id, bool enable);
+
uint32_t vcpu_virt_interrupt_peek_pending_and_enabled(
struct vcpu_locked vcpu_locked);
uint32_t vcpu_virt_interrupt_get_pending_and_enabled(
struct vcpu_locked vcpu_locked);
void vcpu_virt_interrupt_inject(struct vcpu_locked vcpu_locked,
uint32_t vint_id);
-
-void vcpu_enter_secure_interrupt_rtm(struct vcpu_locked vcpu_locked);
-
-void vcpu_secure_interrupt_complete(struct vcpu_locked vcpu_locked);
diff --git a/src/api.c b/src/api.c
index b369b26..23a2d52 100644
--- a/src/api.c
+++ b/src/api.c
@@ -1271,12 +1271,13 @@
if (need_vm_lock &&
ffa_interrupts_inject_notification_pending_interrupt(
vcpu_next_locked, vm_locked)) {
- assert(vcpu_interrupt_count_get(vcpu_next_locked) > 0);
+ assert(vcpu_virt_interrupt_count_get(vcpu_next_locked) >
+ 0);
break;
}
/* Allow virtual interrupts to be delivered. */
- if (vcpu_interrupt_count_get(vcpu_next_locked) > 0) {
+ if (vcpu_virt_interrupt_count_get(vcpu_next_locked) > 0) {
break;
}
@@ -2306,32 +2307,11 @@
plat_interrupts_configure_interrupt(*int_desc);
}
- if (enable) {
- /*
- * If it is pending and was not enabled before, increment the
- * count.
- */
- if (vcpu_is_virt_interrupt_pending(interrupts, intid) &&
- !vcpu_is_virt_interrupt_enabled(interrupts, intid)) {
- vcpu_interrupt_count_increment(current_locked,
- interrupts, intid);
- }
-
- vcpu_virt_interrupt_set_enabled(interrupts, intid);
- vcpu_virt_interrupt_set_type(interrupts, intid, type);
- } else {
- /*
- * If it is pending and was enabled before, decrement the count.
- */
- if (vcpu_is_virt_interrupt_pending(interrupts, intid) &&
- vcpu_is_virt_interrupt_enabled(interrupts, intid)) {
- vcpu_interrupt_count_decrement(current_locked,
- interrupts, intid);
- }
- vcpu_virt_interrupt_clear_enabled(interrupts, intid);
- vcpu_virt_interrupt_set_type(interrupts, intid,
- INTERRUPT_TYPE_IRQ);
- }
+ /*
+ * The type must be set first so that the correct count is modfied.
+ */
+ vcpu_virt_interrupt_set_type(interrupts, intid, type);
+ vcpu_virt_interrupt_enable(current_locked, intid, enable);
ret = 0;
diff --git a/src/arch/aarch64/hypervisor/handler.c b/src/arch/aarch64/hypervisor/handler.c
index 56f0d98..85bd6a0 100644
--- a/src/arch/aarch64/hypervisor/handler.c
+++ b/src/arch/aarch64/hypervisor/handler.c
@@ -759,9 +759,9 @@
vcpu_locked = vcpu_lock(vcpu);
set_virtual_irq(&vcpu->regs,
- vcpu_interrupt_irq_count_get(vcpu_locked) > 0);
+ vcpu_virt_interrupt_irq_count_get(vcpu_locked) > 0);
set_virtual_fiq(&vcpu->regs,
- vcpu_interrupt_fiq_count_get(vcpu_locked) > 0);
+ vcpu_virt_interrupt_fiq_count_get(vcpu_locked) > 0);
vcpu_unlock(&vcpu_locked);
}
diff --git a/src/ffa/hypervisor/indirect_messaging.c b/src/ffa/hypervisor/indirect_messaging.c
index 0c29348..3e43349 100644
--- a/src/ffa/hypervisor/indirect_messaging.c
+++ b/src/ffa/hypervisor/indirect_messaging.c
@@ -70,7 +70,7 @@
* Don't block if there are enabled and pending interrupts, to match
* behaviour of wait_for_interrupt.
*/
- interrupted = (vcpu_interrupt_count_get(current_locked) > 0);
+ interrupted = (vcpu_virt_interrupt_count_get(current_locked) > 0);
return interrupted;
}
diff --git a/src/ffa/spmc/cpu_cycles.c b/src/ffa/spmc/cpu_cycles.c
index 72ba019..4785f39 100644
--- a/src/ffa/spmc/cpu_cycles.c
+++ b/src/ffa/spmc/cpu_cycles.c
@@ -111,7 +111,7 @@
* Deny the state transition if the SP didnt perform the
* deactivation of the secure virtual interrupt.
*/
- if (vcpu_interrupt_count_get(current_locked) > 0) {
+ if (vcpu_virt_interrupt_count_get(current_locked) > 0) {
run_ret->arg2 = FFA_DENIED;
ret = false;
goto out;
diff --git a/src/vcpu.c b/src/vcpu.c
index e4229e2..3175ac2 100644
--- a/src/vcpu.c
+++ b/src/vcpu.c
@@ -219,6 +219,80 @@
}
}
+static void vcpu_virt_interrupt_set_pending(struct interrupts *interrupts,
+ uint32_t intid)
+{
+ interrupt_bitmap_set_value(&interrupts->interrupt_pending, intid);
+}
+
+static void vcpu_virt_interrupt_clear_pending(struct interrupts *interrupts,
+ uint32_t intid)
+{
+ interrupt_bitmap_clear_value(&interrupts->interrupt_pending, intid);
+}
+
+static void vcpu_irq_count_increment(struct vcpu_locked vcpu_locked)
+{
+ vcpu_locked.vcpu->interrupts.enabled_and_pending_irq_count++;
+}
+
+static void vcpu_irq_count_decrement(struct vcpu_locked vcpu_locked)
+{
+ vcpu_locked.vcpu->interrupts.enabled_and_pending_irq_count--;
+}
+
+static void vcpu_fiq_count_increment(struct vcpu_locked vcpu_locked)
+{
+ vcpu_locked.vcpu->interrupts.enabled_and_pending_fiq_count++;
+}
+
+static void vcpu_fiq_count_decrement(struct vcpu_locked vcpu_locked)
+{
+ vcpu_locked.vcpu->interrupts.enabled_and_pending_fiq_count--;
+}
+
+static void vcpu_interrupt_count_increment(struct vcpu_locked vcpu_locked,
+ uint32_t intid)
+{
+ struct interrupts *interrupts = &vcpu_locked.vcpu->interrupts;
+
+ if (vcpu_virt_interrupt_get_type(interrupts, intid) ==
+ INTERRUPT_TYPE_IRQ) {
+ vcpu_irq_count_increment(vcpu_locked);
+ } else {
+ vcpu_fiq_count_increment(vcpu_locked);
+ }
+}
+
+static void vcpu_interrupt_count_decrement(struct vcpu_locked vcpu_locked,
+ uint32_t intid)
+{
+ struct interrupts *interrupts = &vcpu_locked.vcpu->interrupts;
+
+ if (vcpu_virt_interrupt_get_type(interrupts, intid) ==
+ INTERRUPT_TYPE_IRQ) {
+ vcpu_irq_count_decrement(vcpu_locked);
+ } else {
+ vcpu_fiq_count_decrement(vcpu_locked);
+ }
+}
+
+uint32_t vcpu_virt_interrupt_irq_count_get(struct vcpu_locked vcpu_locked)
+{
+ return vcpu_locked.vcpu->interrupts.enabled_and_pending_irq_count;
+}
+
+uint32_t vcpu_virt_interrupt_fiq_count_get(struct vcpu_locked vcpu_locked)
+{
+ return vcpu_locked.vcpu->interrupts.enabled_and_pending_fiq_count;
+}
+
+uint32_t vcpu_virt_interrupt_count_get(struct vcpu_locked vcpu_locked)
+{
+ return vcpu_virt_interrupt_irq_count_get(vcpu_locked) +
+ vcpu_virt_interrupt_fiq_count_get(vcpu_locked);
+}
+
void vcpu_interrupt_clear_decrement(struct vcpu_locked vcpu_locked,
uint32_t intid)
{
@@ -234,8 +308,12 @@
break;
}
+ /*
+ * Mark the virtual interrupt as no longer pending and decrement
+ * the interrupt count.
+ */
vcpu_virt_interrupt_clear_pending(interrupts, intid);
- vcpu_interrupt_count_decrement(vcpu_locked, interrupts, intid);
+ vcpu_interrupt_count_decrement(vcpu_locked, intid);
}
/**
@@ -402,6 +480,33 @@
vcpu->requires_deactivate_call = false;
}
+void vcpu_virt_interrupt_enable(struct vcpu_locked vcpu_locked,
+ uint32_t vint_id, bool enable)
+{
+ struct interrupts *interrupts = &vcpu_locked.vcpu->interrupts;
+
+ if (enable) {
+ /*
+ * If it is pending and was not enabled before, increment the
+ * count.
+ */
+ if (vcpu_is_virt_interrupt_pending(interrupts, vint_id) &&
+ !vcpu_is_virt_interrupt_enabled(interrupts, vint_id)) {
+ vcpu_interrupt_count_increment(vcpu_locked, vint_id);
+ }
+ vcpu_virt_interrupt_set_enabled(interrupts, vint_id);
+ } else {
+ /*
+ * If it is pending and was enabled before, decrement the count.
+ */
+ if (vcpu_is_virt_interrupt_pending(interrupts, vint_id) &&
+ vcpu_is_virt_interrupt_enabled(interrupts, vint_id)) {
+ vcpu_interrupt_count_decrement(vcpu_locked, vint_id);
+ }
+ vcpu_virt_interrupt_clear_enabled(interrupts, vint_id);
+ }
+}
+
/*
* Find and return the first intid that is pending and enabled, the interrupt
* struct for this intid will be at the head of the list so can be popped.
@@ -414,7 +519,7 @@
uint32_t vint_id = HF_INVALID_INTID;
struct interrupts *interrupts = &vcpu_locked.vcpu->interrupts;
uint32_t pending_and_enabled_count =
- vcpu_interrupt_count_get(vcpu_locked);
+ vcpu_virt_interrupt_count_get(vcpu_locked);
/* First check there is a pending and enabled interrupt to return. */
if (pending_and_enabled_count == 0) {
@@ -480,7 +585,6 @@
vcpu_virt_interrupt_set_pending(interrupts, vint_id);
if (vcpu_is_virt_interrupt_enabled(interrupts, vint_id)) {
- vcpu_interrupt_count_increment(vcpu_locked, interrupts,
- vint_id);
+ vcpu_interrupt_count_increment(vcpu_locked, vint_id);
}
}