diff --git a/sys/conf/files.amd64 b/sys/conf/files.amd64 --- a/sys/conf/files.amd64 +++ b/sys/conf/files.amd64 @@ -418,6 +418,7 @@ # config(8) doesn't have a way to force standard options, so we've been inconsistent # about marking non-optional things 'standard'. x86/acpica/madt.c optional acpi +x86/acpica/acpi_cppc_platform.c optional acpi x86/isa/atpic.c optional atpic isa x86/isa/elcr.c optional atpic isa | mptable x86/isa/isa.c standard diff --git a/sys/x86/acpica/acpi_cppc_platform.c b/sys/x86/acpica/acpi_cppc_platform.c new file mode 100644 --- /dev/null +++ b/sys/x86/acpica/acpi_cppc_platform.c @@ -0,0 +1,67 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2026 ShengYi Hung + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +#include +#include + +uint64_t +acpi_cppc_ffh_read(device_t dev, struct acpi_cppc_ffh *ffh) +{ + uint64_t val = 0; + + /* + * The MSR index comes from firmware (_CPC/_PCT), so use the _SAFE + * variant: a bogus register must not panic the machine. On a fault + * the value is left at 0. + */ + (void)x86_msr_op(ffh->address, + MSR_OP_RENDEZVOUS_ONE | MSR_OP_READ | MSR_OP_SAFE | + MSR_OP_CPUID(cpu_get_pcpu(dev)->pc_cpuid), + 0, &val); + return (val); +} + +void +acpi_cppc_ffh_write(device_t dev, struct acpi_cppc_ffh *ffh, uint64_t val) +{ + (void)x86_msr_op(ffh->address, + MSR_OP_RENDEZVOUS_ONE | MSR_OP_WRITE | MSR_OP_SAFE | + MSR_OP_CPUID(cpu_get_pcpu(dev)->pc_cpuid), + val, NULL); +} diff --git a/sys/x86/include/acpica_machdep.h b/sys/x86/include/acpica_machdep.h --- a/sys/x86/include/acpica_machdep.h +++ b/sys/x86/include/acpica_machdep.h @@ -86,6 +86,11 @@ void acpi_set_root(vm_paddr_t addr); +#define ACPI_CPPC_FFH +struct acpi_cppc_ffh; +uint64_t acpi_cppc_ffh_read(device_t dev, struct acpi_cppc_ffh *ffh); +void acpi_cppc_ffh_write(device_t dev, struct acpi_cppc_ffh *, uint64_t val); + #endif /* _KERNEL */ #endif /* __ACPICA_MACHDEP_H__ */