diff --git a/sys/x86/x86/local_apic.c b/sys/x86/x86/local_apic.c --- a/sys/x86/x86/local_apic.c +++ b/sys/x86/x86/local_apic.c @@ -314,6 +314,16 @@ 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 @@ 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 @@ 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 @@ #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 @@ #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 @@ 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");