Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F151253348
D54773.id170049.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D54773.id170049.diff
View Options
diff --git a/sys/x86/include/apicreg.h b/sys/x86/include/apicreg.h
--- a/sys/x86/include/apicreg.h
+++ b/sys/x86/include/apicreg.h
@@ -439,7 +439,12 @@
#define APIC_EXTF_SEIO_CAP 0x00000002
#define APIC_EXTF_IER_CAP 0x00000001
-/* LVT table indices */
+/*
+ * LVT table indices.
+ * Must be ordered following the appearance of the LVT entries in
+ * series the LAPIC versions, which is reported by LAPIC_VERSION
+ * MAXLVT field.
+ */
#define APIC_LVT_LINT0 0
#define APIC_LVT_LINT1 1
#define APIC_LVT_TIMER 2
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,
@@ -809,9 +819,12 @@
static void
lapic_early_mask_vecs(void)
{
- int elvt_count, i;
+ int elvt_count, lvts_count, i;
+ uint32_t version;
- for (i = 0; i < APIC_LVT_MAX; i++)
+ version = lapic_read32(LAPIC_VERSION);
+ lvts_count = min(nitems(lvts), lapic_maxlvt(version) + 1);
+ for (i = 0; i < lvts_count; i++)
lapic_early_mask_vec(&lvts[i]);
elvt_count = amd_read_elvt_count();
@@ -834,7 +847,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 +1003,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 +1027,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 +1896,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");
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Apr 8, 3:29 AM (11 h, 27 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
31071664
Default Alt Text
D54773.id170049.diff (3 KB)
Attached To
Mode
D54773: x86/local_apic.c: Properly calculate the number of LVT entries
Attached
Detach File
Event Timeline
Log In to Comment