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
This commit is contained in:
Konstantin Belousov
2026-01-19 14:50:09 +02:00
parent 83d9882886
commit ad5e3cb950
+15 -5
View File
@@ -314,6 +314,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
@@ -753,7 +763,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,
@@ -834,7 +844,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);
@@ -990,7 +1000,7 @@ lapic_enable_pcint(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);
if (refcount_acquire(&pcint_refcnt) > 0)
@@ -1014,7 +1024,7 @@ lapic_disable_pcint(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;
if (!refcount_release(&pcint_refcnt))
@@ -1883,7 +1893,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");