git: a9e4131375f8 - stable/14 - x86/local_apic.c: add lapic_maxlvt() helper
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 23 Jul 2026 10:01:18 UTC
The branch stable/14 has been updated by olce:
URL: https://cgit.FreeBSD.org/src/commit/?id=a9e4131375f87c6933f8321adde95d14f6d3764d
commit a9e4131375f87c6933f8321adde95d14f6d3764d
Author: Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2026-01-19 12:50:09 +0000
Commit: Olivier Certner <olce@FreeBSD.org>
CommitDate: 2026-07-23 09:59:16 +0000
x86/local_apic.c: add lapic_maxlvt() helper
that calculates the max index of the present LVT entry from the value of
the LAPIC version register.
Reviewed by: markj
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D54773
(cherry picked from commit ad5e3cb950344f9822dbbd90f5ac7c256f97fa4c)
---
sys/x86/x86/local_apic.c | 20 +++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)
diff --git a/sys/x86/x86/local_apic.c b/sys/x86/x86/local_apic.c
index 2636b87e78b3..ca2411c112a0 100644
--- a/sys/x86/x86/local_apic.c
+++ b/sys/x86/x86/local_apic.c
@@ -320,6 +320,16 @@ SYSCTL_INT(_hw_apic, OID_AUTO, ds_idle_timeout, CTLFLAG_RWTUN,
static void lapic_calibrate_initcount(struct lapic *la);
+/*
+ * Calculate the max index of the present LVT entry from the value of
+ * the LAPIC version register.
+ */
+static int
+lapic_maxlvt(uint32_t version)
+{
+ return ((version & APIC_VER_MAXLVT) >> MAXLVTSHIFT);
+}
+
/*
* Use __nosanitizethread to exempt the LAPIC I/O accessors from KCSan
* instrumentation. Otherwise, if x2APIC is not available, use of the global
@@ -761,7 +771,7 @@ lapic_dump(const char* str)
int i;
version = lapic_read32(LAPIC_VERSION);
- maxlvt = (version & APIC_VER_MAXLVT) >> MAXLVTSHIFT;
+ maxlvt = lapic_maxlvt(version);
printf("cpu%d %s:\n", PCPU_GET(cpuid), str);
printf(" ID: 0x%08x VER: 0x%08x LDR: 0x%08x DFR: 0x%08x",
lapic_read32(LAPIC_ID), version,
@@ -842,7 +852,7 @@ lapic_setup(int boot)
la = &lapics[lapic_id()];
KASSERT(la->la_present, ("missing APIC structure"));
version = lapic_read32(LAPIC_VERSION);
- maxlvt = (version & APIC_VER_MAXLVT) >> MAXLVTSHIFT;
+ maxlvt = lapic_maxlvt(version);
/* Initialize the TPR to allow all interrupts. */
lapic_set_tpr(0);
@@ -1003,7 +1013,7 @@ lapic_enable_pmc(void)
#endif
/* Fail if the PMC LVT is not present. */
- maxlvt = (lapic_read32(LAPIC_VERSION) & APIC_VER_MAXLVT) >> MAXLVTSHIFT;
+ maxlvt = lapic_maxlvt(lapic_read32(LAPIC_VERSION));
if (maxlvt < APIC_LVT_PMC)
return (0);
@@ -1030,7 +1040,7 @@ lapic_disable_pmc(void)
#endif
/* Fail if the PMC LVT is not present. */
- maxlvt = (lapic_read32(LAPIC_VERSION) & APIC_VER_MAXLVT) >> MAXLVTSHIFT;
+ maxlvt = lapic_maxlvt(lapic_read32(LAPIC_VERSION));
if (maxlvt < APIC_LVT_PMC)
return;
@@ -1965,7 +1975,7 @@ DB_SHOW_COMMAND_FLAGS(lapic, db_show_lapic, DB_CMD_MEMSAFE)
v = lapic_read32(LAPIC_VERSION);
db_printf("version = %d.%d\n", (v & APIC_VER_VERSION) >> 4,
v & 0xf);
- db_printf("max LVT = %d\n", (v & APIC_VER_MAXLVT) >> MAXLVTSHIFT);
+ db_printf("max LVT = %d\n", lapic_maxlvt(v));
v = lapic_read32(LAPIC_SVR);
db_printf("SVR = %02x (%s)\n", v & APIC_SVR_VECTOR,
v & APIC_SVR_ENABLE ? "enabled" : "disabled");