From a2e7ce2e7e7bf515b258c93881714cc7fbbb0dd4 Mon Sep 17 00:00:00 2001 From: kettenis Date: Thu, 28 Jul 2016 21:57:56 +0000 Subject: [PATCH] Store the acpi processor ID/UID in struct cpu_info, and use it to attach acpicpu(4) drivers to the right cpu(4). ok mlarkin@, guenther@ --- sys/arch/amd64/amd64/cpu.c | 15 ++++++++------- sys/arch/amd64/amd64/mainbus.c | 4 +--- sys/arch/amd64/amd64/mpbios.c | 4 ++-- sys/arch/amd64/include/cpu.h | 3 ++- sys/arch/amd64/include/cpuvar.h | 5 +++-- sys/arch/i386/i386/cpu.c | 15 ++++++++------- sys/arch/i386/i386/mainbus.c | 4 ++-- sys/arch/i386/i386/mpbios.c | 4 ++-- sys/arch/i386/include/cpu.h | 3 ++- sys/arch/i386/include/cpuvar.h | 5 +++-- sys/dev/acpi/acpi.c | 11 ++++++++--- sys/dev/acpi/acpicpu.c | 4 ++-- sys/dev/acpi/acpimadt.c | 12 +++++------- sys/dev/acpi/acpivar.h | 5 +---- 14 files changed, 49 insertions(+), 45 deletions(-) diff --git a/sys/arch/amd64/amd64/cpu.c b/sys/arch/amd64/amd64/cpu.c index c1dedf9115d..033f4f3c03a 100644 --- a/sys/arch/amd64/amd64/cpu.c +++ b/sys/arch/amd64/amd64/cpu.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cpu.c,v 1.101 2016/06/28 05:37:50 mlarkin Exp $ */ +/* $OpenBSD: cpu.c,v 1.102 2016/07/28 21:57:57 kettenis Exp $ */ /* $NetBSD: cpu.c,v 1.1 2003/04/26 18:39:26 fvdl Exp $ */ /*- @@ -349,10 +349,10 @@ cpu_attach(struct device *parent, struct device *self, void *aux) } else { ci = &cpu_info_primary; #if defined(MULTIPROCESSOR) - if (caa->cpu_number != lapic_cpu_number()) { + if (caa->cpu_apicid != lapic_cpu_number()) { panic("%s: running cpu is at apic %d" " instead of at expected %d", - sc->sc_dev.dv_xname, lapic_cpu_number(), caa->cpu_number); + sc->sc_dev.dv_xname, lapic_cpu_number(), caa->cpu_apicid); } #endif } @@ -361,7 +361,8 @@ cpu_attach(struct device *parent, struct device *self, void *aux) sc->sc_info = ci; ci->ci_dev = self; - ci->ci_apicid = caa->cpu_number; + ci->ci_apicid = caa->cpu_apicid; + ci->ci_acpi_proc_id = caa->cpu_acpi_proc_id; #ifdef MULTIPROCESSOR ci->ci_cpuid = cpunum; #else @@ -412,7 +413,7 @@ cpu_attach(struct device *parent, struct device *self, void *aux) break; case CPU_ROLE_BP: - printf("apid %d (boot processor)\n", caa->cpu_number); + printf("apid %d (boot processor)\n", caa->cpu_apicid); ci->ci_flags |= CPUF_PRESENT | CPUF_BSP | CPUF_PRIMARY; cpu_intr_init(ci); identifycpu(ci); @@ -429,7 +430,7 @@ cpu_attach(struct device *parent, struct device *self, void *aux) lapic_calibrate_timer(ci); #endif #if NIOAPIC > 0 - ioapic_bsp_id = caa->cpu_number; + ioapic_bsp_id = caa->cpu_apicid; #endif cpu_init_mwait(sc); break; @@ -438,7 +439,7 @@ cpu_attach(struct device *parent, struct device *self, void *aux) /* * report on an AP */ - printf("apid %d (application processor)\n", caa->cpu_number); + printf("apid %d (application processor)\n", caa->cpu_apicid); #if defined(MULTIPROCESSOR) cpu_intr_init(ci); diff --git a/sys/arch/amd64/amd64/mainbus.c b/sys/arch/amd64/amd64/mainbus.c index 4afbae1b39f..2d280b055dc 100644 --- a/sys/arch/amd64/amd64/mainbus.c +++ b/sys/arch/amd64/amd64/mainbus.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mainbus.c,v 1.37 2016/06/21 15:24:55 jcs Exp $ */ +/* $OpenBSD: mainbus.c,v 1.38 2016/07/28 21:57:57 kettenis Exp $ */ /* $NetBSD: mainbus.c,v 1.1 2003/04/26 18:39:29 fvdl Exp $ */ /* @@ -194,9 +194,7 @@ mainbus_attach(struct device *parent, struct device *self, void *aux) memset(&caa, 0, sizeof(caa)); caa.caa_name = "cpu"; - caa.cpu_number = 0; caa.cpu_role = CPU_ROLE_SP; - caa.cpu_func = 0; config_found(self, &caa, mainbus_print); } diff --git a/sys/arch/amd64/amd64/mpbios.c b/sys/arch/amd64/amd64/mpbios.c index f6bdc2e3441..75382e93084 100644 --- a/sys/arch/amd64/amd64/mpbios.c +++ b/sys/arch/amd64/amd64/mpbios.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mpbios.c,v 1.26 2016/04/21 22:13:27 mlarkin Exp $ */ +/* $OpenBSD: mpbios.c,v 1.27 2016/07/28 21:57:57 kettenis Exp $ */ /* $NetBSD: mpbios.c,v 1.7 2003/05/15 16:32:50 fvdl Exp $ */ /*- @@ -654,7 +654,7 @@ mpbios_cpu(const u_int8_t *ent, struct device *self) } caa.caa_name = "cpu"; - caa.cpu_number = entry->apic_id; + caa.cpu_apicid = entry->apic_id; #ifdef MULTIPROCESSOR caa.cpu_func = &mp_cpu_funcs; #endif diff --git a/sys/arch/amd64/include/cpu.h b/sys/arch/amd64/include/cpu.h index 809766aa328..cfa735af48d 100644 --- a/sys/arch/amd64/include/cpu.h +++ b/sys/arch/amd64/include/cpu.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cpu.h,v 1.101 2016/05/09 22:45:07 deraadt Exp $ */ +/* $OpenBSD: cpu.h,v 1.102 2016/07/28 21:57:57 kettenis Exp $ */ /* $NetBSD: cpu.h,v 1.1 2003/04/26 18:39:39 fvdl Exp $ */ /*- @@ -92,6 +92,7 @@ struct cpu_info { struct proc *ci_curproc; u_int ci_cpuid; u_int ci_apicid; + u_int ci_acpi_proc_id; u_int32_t ci_randseed; u_int64_t ci_scratch; diff --git a/sys/arch/amd64/include/cpuvar.h b/sys/arch/amd64/include/cpuvar.h index 3870ab6e5b0..24fc8fe880d 100644 --- a/sys/arch/amd64/include/cpuvar.h +++ b/sys/arch/amd64/include/cpuvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cpuvar.h,v 1.7 2015/07/18 19:21:03 sf Exp $ */ +/* $OpenBSD: cpuvar.h,v 1.8 2016/07/28 21:57:57 kettenis Exp $ */ /* $NetBSD: cpuvar.h,v 1.1 2003/03/01 18:29:28 fvdl Exp $ */ /*- @@ -78,7 +78,8 @@ extern struct cpu_functions mp_cpu_funcs; struct cpu_attach_args { const char *caa_name; - int cpu_number; + int cpu_apicid; + int cpu_acpi_proc_id; int cpu_role; struct cpu_functions *cpu_func; }; diff --git a/sys/arch/i386/i386/cpu.c b/sys/arch/i386/i386/cpu.c index acc1f6a73a4..babc4f56b76 100644 --- a/sys/arch/i386/i386/cpu.c +++ b/sys/arch/i386/i386/cpu.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cpu.c,v 1.78 2016/06/28 05:37:50 mlarkin Exp $ */ +/* $OpenBSD: cpu.c,v 1.79 2016/07/28 21:57:56 kettenis Exp $ */ /* $NetBSD: cpu.c,v 1.1.2.7 2000/06/26 02:04:05 sommerfeld Exp $ */ /*- @@ -229,17 +229,18 @@ cpu_attach(struct device *parent, struct device *self, void *aux) } else { ci = &cpu_info_primary; #ifdef MULTIPROCESSOR - if (caa->cpu_number != lapic_cpu_number()) { + if (caa->cpu_apicid != lapic_cpu_number()) { panic("%s: running cpu is at apic %d" " instead of at expected %d", - self->dv_xname, lapic_cpu_number(), caa->cpu_number); + self->dv_xname, lapic_cpu_number(), caa->cpu_apicid); } #endif bcopy(self, &ci->ci_dev, sizeof *self); } ci->ci_self = ci; - ci->ci_apicid = caa->cpu_number; + ci->ci_apicid = caa->cpu_apicid; + ci->ci_acpi_proc_id = caa->cpu_acpi_proc_id; #ifdef MULTIPROCESSOR ci->ci_cpuid = cpunum; #else @@ -294,7 +295,7 @@ cpu_attach(struct device *parent, struct device *self, void *aux) break; case CPU_ROLE_BP: - printf("apid %d (boot processor)\n", caa->cpu_number); + printf("apid %d (boot processor)\n", caa->cpu_apicid); ci->ci_flags |= CPUF_PRESENT | CPUF_BSP | CPUF_PRIMARY; identifycpu(ci); #ifdef MTRR @@ -310,7 +311,7 @@ cpu_attach(struct device *parent, struct device *self, void *aux) lapic_calibrate_timer(ci); #endif #if NIOAPIC > 0 - ioapic_bsp_id = caa->cpu_number; + ioapic_bsp_id = caa->cpu_apicid; #endif cpu_init_mwait(&ci->ci_dev); break; @@ -319,7 +320,7 @@ cpu_attach(struct device *parent, struct device *self, void *aux) /* * report on an AP */ - printf("apid %d (application processor)\n", caa->cpu_number); + printf("apid %d (application processor)\n", caa->cpu_apicid); #ifdef MULTIPROCESSOR gdt_alloc_cpu(ci); diff --git a/sys/arch/i386/i386/mainbus.c b/sys/arch/i386/i386/mainbus.c index c32a41348c4..d44a0f1c695 100644 --- a/sys/arch/i386/i386/mainbus.c +++ b/sys/arch/i386/i386/mainbus.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mainbus.c,v 1.54 2015/12/12 12:33:49 reyk Exp $ */ +/* $OpenBSD: mainbus.c,v 1.55 2016/07/28 21:57:56 kettenis Exp $ */ /* $NetBSD: mainbus.c,v 1.21 1997/06/06 23:14:20 thorpej Exp $ */ /* @@ -174,7 +174,7 @@ mainbus_attach(struct device *parent, struct device *self, void *aux) memset(&caa, 0, sizeof(caa)); caa.caa_name = "cpu"; - caa.cpu_number = 0; + caa.cpu_apicid = 0; caa.cpu_role = CPU_ROLE_SP; caa.cpu_func = 0; caa.cpu_signature = cpu_id; diff --git a/sys/arch/i386/i386/mpbios.c b/sys/arch/i386/i386/mpbios.c index 06ed6e64c21..75019e2c31d 100644 --- a/sys/arch/i386/i386/mpbios.c +++ b/sys/arch/i386/i386/mpbios.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mpbios.c,v 1.39 2016/04/21 22:13:27 mlarkin Exp $ */ +/* $OpenBSD: mpbios.c,v 1.40 2016/07/28 21:57:56 kettenis Exp $ */ /* $NetBSD: mpbios.c,v 1.2 2002/10/01 12:56:57 fvdl Exp $ */ /*- @@ -708,7 +708,7 @@ mpbios_cpu(const u_int8_t *ent, struct device *self) } caa.caa_name = "cpu"; - caa.cpu_number = entry->apic_id; + caa.cpu_apicid = entry->apic_id; #ifdef MULTIPROCESSOR caa.cpu_func = &mp_cpu_funcs; #endif diff --git a/sys/arch/i386/include/cpu.h b/sys/arch/i386/include/cpu.h index 18166923abd..2c98cc221bf 100644 --- a/sys/arch/i386/include/cpu.h +++ b/sys/arch/i386/include/cpu.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cpu.h,v 1.147 2016/03/15 03:17:51 guenther Exp $ */ +/* $OpenBSD: cpu.h,v 1.148 2016/07/28 21:57:57 kettenis Exp $ */ /* $NetBSD: cpu.h,v 1.35 1996/05/05 19:29:26 christos Exp $ */ /*- @@ -83,6 +83,7 @@ struct cpu_info { struct proc *ci_curproc; /* current owner of the processor */ cpuid_t ci_cpuid; /* our CPU ID */ u_int ci_apicid; /* our APIC ID */ + u_int ci_acpi_proc_id; u_int32_t ci_randseed; #if defined(MULTIPROCESSOR) diff --git a/sys/arch/i386/include/cpuvar.h b/sys/arch/i386/include/cpuvar.h index 1fcb4634f16..1e4cca64be9 100644 --- a/sys/arch/i386/include/cpuvar.h +++ b/sys/arch/i386/include/cpuvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cpuvar.h,v 1.6 2015/07/18 19:21:03 sf Exp $ */ +/* $OpenBSD: cpuvar.h,v 1.7 2016/07/28 21:57:57 kettenis Exp $ */ /* $NetBSD: cpuvar.h,v 1.1.2.3 2000/02/21 18:54:07 sommerfeld Exp $ */ /*- @@ -78,7 +78,8 @@ extern struct cpu_functions mp_cpu_funcs; struct cpu_attach_args { const char *caa_name; - int cpu_number; + int cpu_apicid; + int cpu_acpi_proc_id; int cpu_role; struct cpu_functions *cpu_func; int cpu_signature; diff --git a/sys/dev/acpi/acpi.c b/sys/dev/acpi/acpi.c index 0d2d56fa46b..a676d4551df 100644 --- a/sys/dev/acpi/acpi.c +++ b/sys/dev/acpi/acpi.c @@ -1,4 +1,4 @@ -/* $OpenBSD: acpi.c,v 1.312 2016/06/10 20:03:46 kettenis Exp $ */ +/* $OpenBSD: acpi.c,v 1.313 2016/07/28 21:57:56 kettenis Exp $ */ /* * Copyright (c) 2005 Thorsten Lockert * Copyright (c) 2005 Jordan Hargrave @@ -1960,6 +1960,8 @@ acpi_add_device(struct aml_node *node, void *arg) struct acpi_attach_args aaa; #ifdef MULTIPROCESSOR struct aml_value res; + CPU_INFO_ITERATOR cii; + struct cpu_info *ci; int proc_id = -1; #endif @@ -1980,8 +1982,11 @@ acpi_add_device(struct aml_node *node, void *arg) proc_id = res.v_processor.proc_id; aml_freevalue(&res); } - if (proc_id < -1 || proc_id >= LAPIC_MAP_SIZE || - (acpi_lapic_flags[proc_id] & ACPI_PROC_ENABLE) == 0) + CPU_INFO_FOREACH(cii, ci) { + if (ci->ci_acpi_proc_id == proc_id) + break; + } + if (ci == NULL) return 0; #endif nacpicpus++; diff --git a/sys/dev/acpi/acpicpu.c b/sys/dev/acpi/acpicpu.c index fc8d36a9108..ea61ca24615 100644 --- a/sys/dev/acpi/acpicpu.c +++ b/sys/dev/acpi/acpicpu.c @@ -1,4 +1,4 @@ -/* $OpenBSD: acpicpu.c,v 1.74 2016/03/17 13:18:47 mpi Exp $ */ +/* $OpenBSD: acpicpu.c,v 1.75 2016/07/28 21:57:56 kettenis Exp $ */ /* * Copyright (c) 2005 Marco Peereboom * Copyright (c) 2015 Philip Guenther @@ -675,7 +675,7 @@ acpicpu_attach(struct device *parent, struct device *self, void *aux) /* link in the matching cpu_info */ CPU_INFO_FOREACH(cii, ci) - if (ci->ci_cpuid == sc->sc_dev.dv_unit) { + if (ci->ci_acpi_proc_id == sc->sc_cpu) { ci->ci_acpicpudev = self; sc->sc_ci = ci; break; diff --git a/sys/dev/acpi/acpimadt.c b/sys/dev/acpi/acpimadt.c index 7c3ce723cf9..4d67501b700 100644 --- a/sys/dev/acpi/acpimadt.c +++ b/sys/dev/acpi/acpimadt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: acpimadt.c,v 1.34 2016/07/10 20:41:19 kettenis Exp $ */ +/* $OpenBSD: acpimadt.c,v 1.35 2016/07/28 21:57:56 kettenis Exp $ */ /* * Copyright (c) 2006 Mark Kettenis * @@ -40,8 +40,6 @@ #include "ioapic.h" -u_int8_t acpi_lapic_flags[LAPIC_MAP_SIZE]; - int acpimadt_match(struct device *, void *, void *); void acpimadt_attach(struct device *, struct device *, void *); @@ -244,8 +242,6 @@ acpimadt_attach(struct device *parent, struct device *self, void *aux) lapic_map[entry->madt_lapic.acpi_proc_id] = entry->madt_lapic.apic_id; - acpi_lapic_flags[entry->madt_lapic.acpi_proc_id] = - entry->madt_lapic.flags; memset(&caa, 0, sizeof(struct cpu_attach_args)); if (lapic_cpu_number() == entry->madt_lapic.apic_id) @@ -255,7 +251,8 @@ acpimadt_attach(struct device *parent, struct device *self, void *aux) ncpusfound++; } caa.caa_name = "cpu"; - caa.cpu_number = entry->madt_lapic.apic_id; + caa.cpu_apicid = entry->madt_lapic.apic_id; + caa.cpu_acpi_proc_id = entry->madt_lapic.acpi_proc_id; #ifdef MULTIPROCESSOR caa.cpu_func = &mp_cpu_funcs; #endif @@ -308,7 +305,8 @@ acpimadt_attach(struct device *parent, struct device *self, void *aux) ncpusfound++; } caa.caa_name = "cpu"; - caa.cpu_number = entry->madt_x2apic.apic_id; + caa.cpu_apicid = entry->madt_x2apic.apic_id; + caa.cpu_acpi_proc_id = entry->madt_x2apic.acpi_proc_uid; #ifdef MULTIPROCESSOR caa.cpu_func = &mp_cpu_funcs; #endif diff --git a/sys/dev/acpi/acpivar.h b/sys/dev/acpi/acpivar.h index 6b84fe1f1a6..aaf35fa030c 100644 --- a/sys/dev/acpi/acpivar.h +++ b/sys/dev/acpi/acpivar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: acpivar.h,v 1.82 2016/01/12 01:11:15 jcs Exp $ */ +/* $OpenBSD: acpivar.h,v 1.83 2016/07/28 21:57:56 kettenis Exp $ */ /* * Copyright (c) 2005 Thorsten Lockert * @@ -41,9 +41,6 @@ extern int acpi_debug; extern int acpi_hasprocfvs; -#define LAPIC_MAP_SIZE 256 -extern u_int8_t acpi_lapic_flags[LAPIC_MAP_SIZE]; - struct klist; struct acpiec_softc; struct acpipwrres_softc; -- 2.20.1