[PATCH v4 10/11] x86/irq: Move __prepare_ICR to x86 common header

From: Jacob Pan
Date: Tue Jul 09 2024 - 10:35:48 EST


To reuse __prepare_ICR() outside APIC local code, move it to the x86
common header. e.g. It can be used by the KVM PV IPI code.

Signed-off-by: Jacob Pan <jacob.jun.pan@xxxxxxxxxxxxxxx>
---
arch/x86/include/asm/apic.h | 21 +++++++++++++++++++++
arch/x86/kernel/apic/local.h | 22 ----------------------
2 files changed, 21 insertions(+), 22 deletions(-)

diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
index d284eff7849c..6c98c51dc1b7 100644
--- a/arch/x86/include/asm/apic.h
+++ b/arch/x86/include/asm/apic.h
@@ -477,6 +477,27 @@ static __always_inline bool apic_id_valid(u32 apic_id)
return apic_id <= apic->max_apic_id;
}

+static inline bool is_nmi_vector(int vector)
+{
+ return (vector & NMI_SOURCE_VEC_MASK) == NMI_VECTOR;
+}
+
+static inline unsigned int __prepare_ICR(unsigned int shortcut, int vector,
+ unsigned int dest)
+{
+ unsigned int icr = shortcut | dest;
+
+ if (is_nmi_vector(vector)) {
+ icr |= APIC_DM_NMI;
+ if (cpu_feature_enabled(X86_FEATURE_NMI_SOURCE))
+ icr |= vector >> 16;
+ } else {
+ icr |= APIC_DM_FIXED | vector;
+ }
+
+ return icr;
+}
+
#else /* CONFIG_X86_LOCAL_APIC */

static inline u32 apic_read(u32 reg) { return 0; }
diff --git a/arch/x86/kernel/apic/local.h b/arch/x86/kernel/apic/local.h
index 60e90b7bf058..8b1fe152cd2d 100644
--- a/arch/x86/kernel/apic/local.h
+++ b/arch/x86/kernel/apic/local.h
@@ -12,7 +12,6 @@

#include <asm/irq_vectors.h>
#include <asm/apic.h>
-#include <asm/nmi.h>

/* X2APIC */
void __x2apic_send_IPI_dest(unsigned int apicid, int vector, unsigned int dest);
@@ -27,27 +26,6 @@ extern u32 x2apic_max_apicid;

DECLARE_STATIC_KEY_FALSE(apic_use_ipi_shorthand);

-static inline bool is_nmi_vector(int vector)
-{
- return (vector & NMI_SOURCE_VEC_MASK) == NMI_VECTOR;
-}
-
-static inline unsigned int __prepare_ICR(unsigned int shortcut, int vector,
- unsigned int dest)
-{
- unsigned int icr = shortcut | dest;
-
- if (is_nmi_vector(vector)) {
- icr |= APIC_DM_NMI;
- if (cpu_feature_enabled(X86_FEATURE_NMI_SOURCE))
- icr |= vector >> 16;
- } else {
- icr |= APIC_DM_FIXED | vector;
- }
-
- return icr;
-}
-
void default_init_apic_ldr(void);

void apic_mem_wait_icr_idle(void);
--
2.25.1