diff mbox series

[kvm-unit-tests,1/2] x86: apic: Move helpers for querying APIC state to library code

Message ID 20250304211223.124321-2-seanjc@google.com (mailing list archive)
State New
Headers show
Series x86: nSVM: Fix a bug with nNPT+x2AVIC | expand

Commit Message

Sean Christopherson March 4, 2025, 9:12 p.m. UTC
Expose the helpers to query if an APIC is enabled, and in xAPIC vs. x2APIC
mode, to library code so that the helpers can be used by all tests.

No funtional change intended.

Signed-off-by: Sean Christopherson <seanjc@google.com>
---
 lib/x86/apic.h | 21 +++++++++++++++++++++
 x86/apic.c     | 20 --------------------
 2 files changed, 21 insertions(+), 20 deletions(-)
diff mbox series

Patch

diff --git a/lib/x86/apic.h b/lib/x86/apic.h
index 23c771ed..cac6eab1 100644
--- a/lib/x86/apic.h
+++ b/lib/x86/apic.h
@@ -5,6 +5,7 @@ 
 #include <stdint.h>
 
 #include "apic-defs.h"
+#include "processor.h"
 #include "smp.h"
 
 extern u8 id_map[MAX_TEST_CPUS];
@@ -67,6 +68,26 @@  void apic_setup_timer(int vector, u32 mode);
 void apic_start_timer(u32 counter);
 void apic_stop_timer(void);
 
+static inline bool is_apic_hw_enabled(void)
+{
+	return rdmsr(MSR_IA32_APICBASE) & APIC_EN;
+}
+
+static inline bool is_apic_sw_enabled(void)
+{
+	return apic_read(APIC_SPIV) & APIC_SPIV_APIC_ENABLED;
+}
+
+static inline bool is_x2apic_enabled(void)
+{
+	return (rdmsr(MSR_IA32_APICBASE) & (APIC_EN | APIC_EXTD)) == (APIC_EN | APIC_EXTD);
+}
+
+static inline bool is_xapic_enabled(void)
+{
+	return (rdmsr(MSR_IA32_APICBASE) & (APIC_EN | APIC_EXTD)) == APIC_EN;
+}
+
 /* Converts byte-addressable APIC register offset to 4-byte offset. */
 static inline u32 apic_reg_index(u32 reg)
 {
diff --git a/x86/apic.c b/x86/apic.c
index dd7e7834..b45fc9c1 100644
--- a/x86/apic.c
+++ b/x86/apic.c
@@ -10,26 +10,6 @@ 
 
 #define MAX_TPR			0xf
 
-static bool is_apic_hw_enabled(void)
-{
-	return rdmsr(MSR_IA32_APICBASE) & APIC_EN;
-}
-
-static bool is_apic_sw_enabled(void)
-{
-	return apic_read(APIC_SPIV) & APIC_SPIV_APIC_ENABLED;
-}
-
-static bool is_x2apic_enabled(void)
-{
-	return (rdmsr(MSR_IA32_APICBASE) & (APIC_EN | APIC_EXTD)) == (APIC_EN | APIC_EXTD);
-}
-
-static bool is_xapic_enabled(void)
-{
-	return (rdmsr(MSR_IA32_APICBASE) & (APIC_EN | APIC_EXTD)) == APIC_EN;
-}
-
 static void test_lapic_existence(void)
 {
 	u8 version;