Changeset View
Changeset View
Standalone View
Standalone View
sys/x86/x86/local_apic.c
| Show First 20 Lines • Show All 309 Lines • ▼ Show 20 Lines | |||||
| SYSCTL_INT(_hw_apic, OID_AUTO, ds_idle_timeout, CTLFLAG_RWTUN, | SYSCTL_INT(_hw_apic, OID_AUTO, ds_idle_timeout, CTLFLAG_RWTUN, | ||||
| &lapic_ds_idle_timeout, 0, | &lapic_ds_idle_timeout, 0, | ||||
| "timeout (in us) for APIC Delivery Status to become Idle (xAPIC only)"); | "timeout (in us) for APIC Delivery Status to become Idle (xAPIC only)"); | ||||
| #endif | #endif | ||||
| static void lapic_calibrate_initcount(struct lapic *la); | 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) | |||||
markj: You can use this helper in a few other places, e.g., lapic_dump(). | |||||
| { | |||||
| return ((version & APIC_VER_MAXLVT) >> MAXLVTSHIFT); | |||||
| } | |||||
| /* | |||||
| * Use __nosanitizethread to exempt the LAPIC I/O accessors from KCSan | * Use __nosanitizethread to exempt the LAPIC I/O accessors from KCSan | ||||
| * instrumentation. Otherwise, if x2APIC is not available, use of the global | * instrumentation. Otherwise, if x2APIC is not available, use of the global | ||||
| * lapic_map will generate a KCSan false positive. While the mapping is | * lapic_map will generate a KCSan false positive. While the mapping is | ||||
| * shared among all CPUs, the physical access will always take place on the | * shared among all CPUs, the physical access will always take place on the | ||||
| * local CPU's APIC, so there isn't in fact a race here. Furthermore, the | * local CPU's APIC, so there isn't in fact a race here. Furthermore, the | ||||
| * KCSan warning printf can cause a panic if issued during LAPIC access, | * KCSan warning printf can cause a panic if issued during LAPIC access, | ||||
| * due to attempted recursive use of event timer resources. | * due to attempted recursive use of event timer resources. | ||||
| */ | */ | ||||
| ▲ Show 20 Lines • Show All 422 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| uint32_t version; | uint32_t version; | ||||
| uint32_t maxlvt; | uint32_t maxlvt; | ||||
| uint32_t extf; | uint32_t extf; | ||||
| int elvt_count; | int elvt_count; | ||||
| int i; | int i; | ||||
| version = lapic_read32(LAPIC_VERSION); | 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("cpu%d %s:\n", PCPU_GET(cpuid), str); | ||||
| printf(" ID: 0x%08x VER: 0x%08x LDR: 0x%08x DFR: 0x%08x", | printf(" ID: 0x%08x VER: 0x%08x LDR: 0x%08x DFR: 0x%08x", | ||||
| lapic_read32(LAPIC_ID), version, | lapic_read32(LAPIC_ID), version, | ||||
| lapic_read32(LAPIC_LDR), x2apic_mode ? 0 : lapic_read32(LAPIC_DFR)); | lapic_read32(LAPIC_LDR), x2apic_mode ? 0 : lapic_read32(LAPIC_DFR)); | ||||
| if ((cpu_feature2 & CPUID2_X2APIC) != 0) | if ((cpu_feature2 & CPUID2_X2APIC) != 0) | ||||
| printf(" x2APIC: %d", x2apic_mode); | printf(" x2APIC: %d", x2apic_mode); | ||||
| printf("\n lint0: 0x%08x lint1: 0x%08x TPR: 0x%08x SVR: 0x%08x\n", | printf("\n lint0: 0x%08x lint1: 0x%08x TPR: 0x%08x SVR: 0x%08x\n", | ||||
| lapic_read32(LAPIC_LVT_LINT0), lapic_read32(LAPIC_LVT_LINT1), | lapic_read32(LAPIC_LVT_LINT0), lapic_read32(LAPIC_LVT_LINT1), | ||||
| ▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | lapic_setup(int boot) | ||||
| int elvt_count; | int elvt_count; | ||||
| int i; | int i; | ||||
| saveintr = intr_disable(); | saveintr = intr_disable(); | ||||
| la = &lapics[lapic_id()]; | la = &lapics[lapic_id()]; | ||||
| KASSERT(la->la_present, ("missing APIC structure")); | KASSERT(la->la_present, ("missing APIC structure")); | ||||
| version = lapic_read32(LAPIC_VERSION); | version = lapic_read32(LAPIC_VERSION); | ||||
| maxlvt = (version & APIC_VER_MAXLVT) >> MAXLVTSHIFT; | maxlvt = lapic_maxlvt(version); | ||||
| /* Initialize the TPR to allow all interrupts. */ | /* Initialize the TPR to allow all interrupts. */ | ||||
| lapic_set_tpr(0); | lapic_set_tpr(0); | ||||
| /* Setup spurious vector and enable the local APIC. */ | /* Setup spurious vector and enable the local APIC. */ | ||||
| lapic_enable(); | lapic_enable(); | ||||
| /* Program LINT[01] LVT entries. */ | /* Program LINT[01] LVT entries. */ | ||||
| ▲ Show 20 Lines • Show All 139 Lines • ▼ Show 20 Lines | |||||
| #ifdef DEV_ATPIC | #ifdef DEV_ATPIC | ||||
| /* Fail if the local APIC is not present. */ | /* Fail if the local APIC is not present. */ | ||||
| if (!x2apic_mode && lapic_map == NULL) | if (!x2apic_mode && lapic_map == NULL) | ||||
| return (0); | return (0); | ||||
| #endif | #endif | ||||
| /* Fail if the PMC LVT is not present. */ | /* 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) | if (maxlvt < APIC_LVT_PMC) | ||||
| return (0); | return (0); | ||||
| if (refcount_acquire(&pcint_refcnt) > 0) | if (refcount_acquire(&pcint_refcnt) > 0) | ||||
| return (1); | return (1); | ||||
| lvts[APIC_LVT_PMC].lvt_masked = 0; | lvts[APIC_LVT_PMC].lvt_masked = 0; | ||||
| MPASS(mp_ncpus == 1 || smp_started); | MPASS(mp_ncpus == 1 || smp_started); | ||||
| smp_rendezvous(NULL, lapic_update_pcint, NULL, NULL); | smp_rendezvous(NULL, lapic_update_pcint, NULL, NULL); | ||||
| return (1); | return (1); | ||||
| } | } | ||||
| void | void | ||||
| lapic_disable_pcint(void) | lapic_disable_pcint(void) | ||||
| { | { | ||||
| u_int32_t maxlvt; | u_int32_t maxlvt; | ||||
| #ifdef DEV_ATPIC | #ifdef DEV_ATPIC | ||||
| /* Fail if the local APIC is not present. */ | /* Fail if the local APIC is not present. */ | ||||
| if (!x2apic_mode && lapic_map == NULL) | if (!x2apic_mode && lapic_map == NULL) | ||||
| return; | return; | ||||
| #endif | #endif | ||||
| /* Fail if the PMC LVT is not present. */ | /* 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) | if (maxlvt < APIC_LVT_PMC) | ||||
| return; | return; | ||||
| if (!refcount_release(&pcint_refcnt)) | if (!refcount_release(&pcint_refcnt)) | ||||
| return; | return; | ||||
| lvts[APIC_LVT_PMC].lvt_masked = 1; | lvts[APIC_LVT_PMC].lvt_masked = 1; | ||||
| #ifdef SMP | #ifdef SMP | ||||
| /* The APs should always be started when hwpmc is unloaded. */ | /* The APs should always be started when hwpmc is unloaded. */ | ||||
| ▲ Show 20 Lines • Show All 852 Lines • ▼ Show 20 Lines | |||||
| DB_SHOW_COMMAND_FLAGS(lapic, db_show_lapic, DB_CMD_MEMSAFE) | DB_SHOW_COMMAND_FLAGS(lapic, db_show_lapic, DB_CMD_MEMSAFE) | ||||
| { | { | ||||
| uint32_t v; | uint32_t v; | ||||
| db_printf("lapic ID = %d\n", lapic_id()); | db_printf("lapic ID = %d\n", lapic_id()); | ||||
| v = lapic_read32(LAPIC_VERSION); | v = lapic_read32(LAPIC_VERSION); | ||||
| db_printf("version = %d.%d\n", (v & APIC_VER_VERSION) >> 4, | db_printf("version = %d.%d\n", (v & APIC_VER_VERSION) >> 4, | ||||
| v & 0xf); | 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); | v = lapic_read32(LAPIC_SVR); | ||||
| db_printf("SVR = %02x (%s)\n", v & APIC_SVR_VECTOR, | db_printf("SVR = %02x (%s)\n", v & APIC_SVR_VECTOR, | ||||
| v & APIC_SVR_ENABLE ? "enabled" : "disabled"); | v & APIC_SVR_ENABLE ? "enabled" : "disabled"); | ||||
| db_printf("TPR = %02x\n", lapic_read32(LAPIC_TPR)); | db_printf("TPR = %02x\n", lapic_read32(LAPIC_TPR)); | ||||
| #define dump_field(prefix, regn, index) \ | #define dump_field(prefix, regn, index) \ | ||||
| dump_mask(__XSTRING(prefix ## index), \ | dump_mask(__XSTRING(prefix ## index), \ | ||||
| lapic_read32(LAPIC_ ## regn ## index), \ | lapic_read32(LAPIC_ ## regn ## index), \ | ||||
| ▲ Show 20 Lines • Show All 390 Lines • Show Last 20 Lines | |||||
You can use this helper in a few other places, e.g., lapic_dump().