2001-07-07 10:27:17 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2001 Michael Smith
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2003-08-24 17:55:58 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2001-07-07 10:27:17 +00:00
|
|
|
#include "opt_acpi.h"
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/bus.h>
|
2002-03-04 18:46:13 +00:00
|
|
|
#include <sys/power.h>
|
2001-07-07 10:27:17 +00:00
|
|
|
|
|
|
|
#include <machine/bus_pio.h>
|
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <machine/resource.h>
|
|
|
|
#include <sys/rman.h>
|
|
|
|
|
|
|
|
#include "acpi.h"
|
|
|
|
#include <dev/acpica/acpivar.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Support for ACPI Processor devices.
|
|
|
|
*
|
|
|
|
* Note that this only provides ACPI 1.0 support (with the exception of the
|
|
|
|
* PSTATE_CNT field). 2.0 support will involve implementing _PTC, _PCT,
|
|
|
|
* _PSS and _PPC.
|
|
|
|
*/
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Hooks for the ACPI CA debugging infrastructure */
|
2001-07-07 10:27:17 +00:00
|
|
|
#define _COMPONENT ACPI_PROCESSOR
|
2002-02-23 05:26:45 +00:00
|
|
|
ACPI_MODULE_NAME("PROCESSOR")
|
2001-07-07 10:27:17 +00:00
|
|
|
|
|
|
|
struct acpi_cpu_softc {
|
|
|
|
device_t cpu_dev;
|
|
|
|
ACPI_HANDLE cpu_handle;
|
|
|
|
|
|
|
|
u_int32_t cpu_id;
|
|
|
|
|
|
|
|
/* CPU throttling control register */
|
|
|
|
struct resource *cpu_p_blk;
|
2003-08-28 16:06:30 +00:00
|
|
|
#define CPU_P_CNT_THT_EN (1<<4)
|
2001-07-07 10:27:17 +00:00
|
|
|
};
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
#define CPU_GET_P_CNT(sc) \
|
|
|
|
(bus_space_read_4(rman_get_bustag((sc)->cpu_p_blk), \
|
|
|
|
rman_get_bushandle((sc)->cpu_p_blk), 0))
|
|
|
|
#define CPU_SET_P_CNT(sc, val) \
|
|
|
|
(bus_space_write_4(rman_get_bustag((sc)->cpu_p_blk), \
|
|
|
|
rman_get_bushandle((sc)->cpu_p_blk), 0, (val)))
|
|
|
|
|
2001-07-07 10:27:17 +00:00
|
|
|
/*
|
|
|
|
* Speeds are stored in counts, from 1 - CPU_MAX_SPEED, and
|
|
|
|
* reported to the user in tenths of a percent.
|
|
|
|
*/
|
|
|
|
static u_int32_t cpu_duty_offset;
|
|
|
|
static u_int32_t cpu_duty_width;
|
|
|
|
#define CPU_MAX_SPEED (1 << cpu_duty_width)
|
|
|
|
#define CPU_SPEED_PERCENT(x) ((1000 * (x)) / CPU_MAX_SPEED)
|
|
|
|
#define CPU_SPEED_PRINTABLE(x) (CPU_SPEED_PERCENT(x) / 10),(CPU_SPEED_PERCENT(x) % 10)
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* XXX Should be a generic way to do this */
|
|
|
|
static u_int32_t cpu_smi_cmd;
|
2001-07-07 10:27:17 +00:00
|
|
|
static u_int8_t cpu_pstate_cnt;
|
|
|
|
|
|
|
|
static u_int32_t cpu_current_state;
|
|
|
|
static u_int32_t cpu_performance_state;
|
|
|
|
static u_int32_t cpu_economy_state;
|
|
|
|
static u_int32_t cpu_max_state;
|
|
|
|
|
|
|
|
static device_t *cpu_devices;
|
|
|
|
static int cpu_ndevices;
|
|
|
|
|
|
|
|
static struct sysctl_ctx_list acpi_cpu_sysctl_ctx;
|
|
|
|
static struct sysctl_oid *acpi_cpu_sysctl_tree;
|
|
|
|
|
|
|
|
static int acpi_cpu_probe(device_t dev);
|
|
|
|
static int acpi_cpu_attach(device_t dev);
|
|
|
|
static void acpi_cpu_init_throttling(void *arg);
|
|
|
|
static void acpi_cpu_set_speed(u_int32_t speed);
|
2002-03-04 18:46:13 +00:00
|
|
|
static void acpi_cpu_power_profile(void *arg);
|
2001-07-07 10:27:17 +00:00
|
|
|
static int acpi_cpu_speed_sysctl(SYSCTL_HANDLER_ARGS);
|
|
|
|
|
|
|
|
static device_method_t acpi_cpu_methods[] = {
|
|
|
|
/* Device interface */
|
|
|
|
DEVMETHOD(device_probe, acpi_cpu_probe),
|
|
|
|
DEVMETHOD(device_attach, acpi_cpu_attach),
|
|
|
|
|
|
|
|
{0, 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t acpi_cpu_driver = {
|
|
|
|
"acpi_cpu",
|
|
|
|
acpi_cpu_methods,
|
|
|
|
sizeof(struct acpi_cpu_softc),
|
|
|
|
};
|
|
|
|
|
2002-01-08 06:46:01 +00:00
|
|
|
static devclass_t acpi_cpu_devclass;
|
2001-07-07 10:27:17 +00:00
|
|
|
DRIVER_MODULE(acpi_cpu, acpi, acpi_cpu_driver, acpi_cpu_devclass, 0, 0);
|
|
|
|
|
|
|
|
static int
|
|
|
|
acpi_cpu_probe(device_t dev)
|
|
|
|
{
|
2003-08-28 16:06:30 +00:00
|
|
|
if (!acpi_disabled("cpu") && acpi_get_type(dev) == ACPI_TYPE_PROCESSOR) {
|
|
|
|
/* XXX get more verbose description? */
|
|
|
|
device_set_desc(dev, "CPU");
|
|
|
|
return (0);
|
2001-07-07 10:27:17 +00:00
|
|
|
}
|
2003-08-28 16:06:30 +00:00
|
|
|
|
|
|
|
return (ENXIO);
|
2001-07-07 10:27:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
acpi_cpu_attach(device_t dev)
|
|
|
|
{
|
|
|
|
struct acpi_cpu_softc *sc;
|
|
|
|
struct acpi_softc *acpi_sc;
|
|
|
|
ACPI_OBJECT processor;
|
|
|
|
ACPI_BUFFER buf;
|
|
|
|
ACPI_STATUS status;
|
|
|
|
u_int32_t p_blk;
|
|
|
|
u_int32_t p_blk_length;
|
|
|
|
u_int32_t duty_end;
|
|
|
|
int rid;
|
|
|
|
|
2002-05-19 06:16:47 +00:00
|
|
|
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
|
2001-07-07 10:27:17 +00:00
|
|
|
|
|
|
|
ACPI_ASSERTLOCK;
|
|
|
|
|
|
|
|
sc = device_get_softc(dev);
|
|
|
|
sc->cpu_dev = dev;
|
|
|
|
sc->cpu_handle = acpi_get_handle(dev);
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Get global parameters from the FADT. */
|
2001-07-07 10:27:17 +00:00
|
|
|
if (device_get_unit(sc->cpu_dev) == 0) {
|
2001-07-21 04:05:32 +00:00
|
|
|
cpu_duty_offset = AcpiGbl_FADT->DutyOffset;
|
|
|
|
cpu_duty_width = AcpiGbl_FADT->DutyWidth;
|
|
|
|
cpu_smi_cmd = AcpiGbl_FADT->SmiCmd;
|
|
|
|
cpu_pstate_cnt = AcpiGbl_FADT->PstateCnt;
|
2001-07-07 10:27:17 +00:00
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Validate the offset/width */
|
2002-01-02 10:53:10 +00:00
|
|
|
if (cpu_duty_width > 0) {
|
2003-08-28 16:06:30 +00:00
|
|
|
duty_end = cpu_duty_offset + cpu_duty_width - 1;
|
|
|
|
|
|
|
|
/* Check that it fits */
|
|
|
|
if (duty_end > 31) {
|
|
|
|
printf("acpi_cpu: CLK_VAL field overflows P_CNT register\n");
|
|
|
|
cpu_duty_width = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for overlap with the THT_EN bit */
|
|
|
|
if (cpu_duty_offset <= 4 && duty_end >= 4) {
|
|
|
|
printf("acpi_cpu: CLK_VAL field overlaps THT_EN bit\n");
|
|
|
|
cpu_duty_width = 0;
|
|
|
|
}
|
2001-07-07 10:27:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2003-08-28 16:06:30 +00:00
|
|
|
* Start the throttling process once the probe phase completes, if we
|
|
|
|
* think that it's going to be useful. If the duty width value is
|
|
|
|
* zero, there are no significant bits in the register and thus no
|
|
|
|
* throttled states.
|
2001-07-07 10:27:17 +00:00
|
|
|
*/
|
|
|
|
if (cpu_duty_width > 0) {
|
2003-08-28 16:06:30 +00:00
|
|
|
AcpiOsQueueForExecution(OSD_PRIORITY_LO, acpi_cpu_init_throttling,
|
|
|
|
NULL);
|
2001-07-07 10:27:17 +00:00
|
|
|
acpi_sc = acpi_device_get_parent_softc(dev);
|
|
|
|
sysctl_ctx_init(&acpi_cpu_sysctl_ctx);
|
|
|
|
acpi_cpu_sysctl_tree = SYSCTL_ADD_NODE(&acpi_cpu_sysctl_ctx,
|
2003-08-28 16:06:30 +00:00
|
|
|
SYSCTL_CHILDREN(acpi_sc->acpi_sysctl_tree),
|
|
|
|
OID_AUTO, "cpu", CTLFLAG_RD, 0, "");
|
2001-07-07 10:27:17 +00:00
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
SYSCTL_ADD_INT(&acpi_cpu_sysctl_ctx,
|
|
|
|
SYSCTL_CHILDREN(acpi_cpu_sysctl_tree),
|
2001-07-07 10:27:17 +00:00
|
|
|
OID_AUTO, "max_speed", CTLFLAG_RD,
|
|
|
|
&cpu_max_state, 0, "maximum CPU speed");
|
2003-08-28 16:06:30 +00:00
|
|
|
SYSCTL_ADD_INT(&acpi_cpu_sysctl_ctx,
|
|
|
|
SYSCTL_CHILDREN(acpi_cpu_sysctl_tree),
|
2001-07-07 10:27:17 +00:00
|
|
|
OID_AUTO, "current_speed", CTLFLAG_RD,
|
|
|
|
&cpu_current_state, 0, "current CPU speed");
|
2003-08-28 16:06:30 +00:00
|
|
|
SYSCTL_ADD_PROC(&acpi_cpu_sysctl_ctx,
|
|
|
|
SYSCTL_CHILDREN(acpi_cpu_sysctl_tree),
|
|
|
|
OID_AUTO, "performance_speed",
|
|
|
|
CTLTYPE_INT | CTLFLAG_RW, &cpu_performance_state,
|
|
|
|
0, acpi_cpu_speed_sysctl, "I", "");
|
|
|
|
SYSCTL_ADD_PROC(&acpi_cpu_sysctl_ctx,
|
|
|
|
SYSCTL_CHILDREN(acpi_cpu_sysctl_tree),
|
|
|
|
OID_AUTO, "economy_speed",
|
|
|
|
CTLTYPE_INT | CTLFLAG_RW, &cpu_economy_state,
|
|
|
|
0, acpi_cpu_speed_sysctl, "I", "");
|
2001-07-07 10:27:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Get the processor object. */
|
2001-07-07 10:27:17 +00:00
|
|
|
buf.Pointer = &processor;
|
|
|
|
buf.Length = sizeof(processor);
|
2003-08-28 16:06:30 +00:00
|
|
|
status = AcpiEvaluateObject(sc->cpu_handle, NULL, NULL, &buf);
|
|
|
|
if (ACPI_FAILURE(status)) {
|
|
|
|
device_printf(sc->cpu_dev, "couldn't get Processor object - %s\n",
|
|
|
|
AcpiFormatException(status));
|
|
|
|
return_VALUE (ENXIO);
|
2001-07-07 10:27:17 +00:00
|
|
|
}
|
|
|
|
if (processor.Type != ACPI_TYPE_PROCESSOR) {
|
2003-08-28 16:06:30 +00:00
|
|
|
device_printf(sc->cpu_dev, "Processor object has bad type %d\n",
|
|
|
|
processor.Type);
|
|
|
|
return_VALUE (ENXIO);
|
2001-07-07 10:27:17 +00:00
|
|
|
}
|
|
|
|
sc->cpu_id = processor.Processor.ProcId;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If it looks like we support throttling, find this CPU's P_BLK.
|
|
|
|
*
|
|
|
|
* Note that some systems seem to duplicate the P_BLK pointer across
|
|
|
|
* multiple CPUs, so not getting the resource is not fatal.
|
|
|
|
*
|
|
|
|
* XXX should support _PTC here as well, once we work out how to parse it.
|
|
|
|
*
|
|
|
|
* XXX is it valid to assume that the P_BLK must be 6 bytes long?
|
|
|
|
*/
|
|
|
|
if (cpu_duty_width > 0) {
|
|
|
|
p_blk = processor.Processor.PblkAddress;
|
|
|
|
p_blk_length = processor.Processor.PblkLength;
|
|
|
|
|
|
|
|
/* allocate bus space if possible */
|
2003-08-28 16:06:30 +00:00
|
|
|
if (p_blk > 0 && p_blk_length == 6) {
|
2001-07-07 10:27:17 +00:00
|
|
|
rid = 0;
|
2003-08-28 16:06:30 +00:00
|
|
|
bus_set_resource(sc->cpu_dev, SYS_RES_IOPORT, rid, p_blk,
|
|
|
|
p_blk_length);
|
|
|
|
sc->cpu_p_blk = bus_alloc_resource(sc->cpu_dev, SYS_RES_IOPORT,
|
|
|
|
&rid, 0, ~0, 1, RF_ACTIVE);
|
|
|
|
|
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_IO, "acpi_cpu%d: throttling with P_BLK "
|
|
|
|
"at 0x%x/%d%s\n", device_get_unit(sc->cpu_dev),
|
|
|
|
p_blk, p_blk_length,
|
|
|
|
sc->cpu_p_blk ? "" : " (shadowed)"));
|
2001-07-07 10:27:17 +00:00
|
|
|
}
|
|
|
|
}
|
2003-08-28 16:06:30 +00:00
|
|
|
|
|
|
|
return_VALUE (0);
|
2001-07-07 10:27:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Call this *after* all CPUs have been attached.
|
|
|
|
*
|
|
|
|
* Takes the ACPI lock to avoid fighting anyone over the SMI command
|
|
|
|
* port. Could probably lock less code.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
acpi_cpu_init_throttling(void *arg)
|
|
|
|
{
|
2001-10-23 22:37:36 +00:00
|
|
|
int cpu_temp_speed;
|
2002-10-16 17:28:53 +00:00
|
|
|
ACPI_LOCK_DECL;
|
2001-07-07 10:27:17 +00:00
|
|
|
|
|
|
|
ACPI_LOCK;
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Get set of CPU devices */
|
2001-07-07 10:27:17 +00:00
|
|
|
devclass_get_devices(acpi_cpu_devclass, &cpu_devices, &cpu_ndevices);
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Initialise throttling states */
|
2001-07-07 10:27:17 +00:00
|
|
|
cpu_max_state = CPU_MAX_SPEED;
|
|
|
|
cpu_performance_state = cpu_max_state;
|
|
|
|
cpu_economy_state = cpu_performance_state / 2;
|
2003-08-28 16:06:30 +00:00
|
|
|
|
|
|
|
/* 0 is 'reserved' */
|
|
|
|
if (cpu_economy_state == 0)
|
2001-07-07 10:27:17 +00:00
|
|
|
cpu_economy_state++;
|
2003-08-28 16:06:30 +00:00
|
|
|
if (TUNABLE_INT_FETCH("hw.acpi.cpu.performance_speed", &cpu_temp_speed) &&
|
|
|
|
cpu_temp_speed > 0 && cpu_temp_speed <= cpu_max_state) {
|
|
|
|
|
2001-10-23 22:37:36 +00:00
|
|
|
cpu_performance_state = cpu_temp_speed;
|
2003-08-28 16:06:30 +00:00
|
|
|
}
|
|
|
|
if (TUNABLE_INT_FETCH("hw.acpi.cpu.economy_speed", &cpu_temp_speed) &&
|
|
|
|
cpu_temp_speed > 0 && cpu_temp_speed <= cpu_max_state) {
|
|
|
|
|
2001-10-23 22:37:36 +00:00
|
|
|
cpu_economy_state = cpu_temp_speed;
|
2003-08-28 16:06:30 +00:00
|
|
|
}
|
2001-07-07 10:27:17 +00:00
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Register performance profile change handler */
|
|
|
|
EVENTHANDLER_REGISTER(power_profile_change, acpi_cpu_power_profile, NULL,
|
|
|
|
0);
|
2001-07-07 10:27:17 +00:00
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/*
|
|
|
|
* If ACPI 2.0+, signal platform that we are taking over throttling
|
|
|
|
* XXX should be a generic interface for this
|
|
|
|
*/
|
|
|
|
if (cpu_pstate_cnt != 0)
|
2001-07-21 04:05:32 +00:00
|
|
|
AcpiOsWritePort(cpu_smi_cmd, cpu_pstate_cnt, 8);
|
2001-07-07 10:27:17 +00:00
|
|
|
|
|
|
|
ACPI_UNLOCK;
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Set initial speed */
|
2002-03-04 18:46:13 +00:00
|
|
|
acpi_cpu_power_profile(NULL);
|
2001-07-07 10:27:17 +00:00
|
|
|
|
2003-01-23 22:18:14 +00:00
|
|
|
printf("acpi_cpu: throttling enabled, %d steps (100%% to %d.%d%%), "
|
|
|
|
"currently %d.%d%%\n", CPU_MAX_SPEED, CPU_SPEED_PRINTABLE(1),
|
|
|
|
CPU_SPEED_PRINTABLE(cpu_current_state));
|
2001-07-07 10:27:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set CPUs to the new state.
|
|
|
|
*
|
|
|
|
* Must be called with the ACPI lock held.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
acpi_cpu_set_speed(u_int32_t speed)
|
|
|
|
{
|
|
|
|
struct acpi_cpu_softc *sc;
|
|
|
|
int i;
|
|
|
|
u_int32_t p_cnt, clk_val;
|
|
|
|
|
|
|
|
ACPI_ASSERTLOCK;
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Iterate over processors */
|
2001-07-07 10:27:17 +00:00
|
|
|
for (i = 0; i < cpu_ndevices; i++) {
|
|
|
|
sc = device_get_softc(cpu_devices[i]);
|
|
|
|
if (sc->cpu_p_blk == NULL)
|
|
|
|
continue;
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Get the current P_CNT value and disable throttling */
|
2001-07-07 10:27:17 +00:00
|
|
|
p_cnt = CPU_GET_P_CNT(sc);
|
|
|
|
p_cnt &= ~CPU_P_CNT_THT_EN;
|
|
|
|
CPU_SET_P_CNT(sc, p_cnt);
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* If we're at maximum speed, that's all */
|
2001-07-07 10:27:17 +00:00
|
|
|
if (speed < CPU_MAX_SPEED) {
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Mask the old CLK_VAL off and or-in the new value */
|
2001-07-07 10:27:17 +00:00
|
|
|
clk_val = CPU_MAX_SPEED << cpu_duty_offset;
|
|
|
|
p_cnt &= ~clk_val;
|
|
|
|
p_cnt |= (speed << cpu_duty_offset);
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Write the new P_CNT value and then enable throttling */
|
2001-07-07 10:27:17 +00:00
|
|
|
CPU_SET_P_CNT(sc, p_cnt);
|
|
|
|
p_cnt |= CPU_P_CNT_THT_EN;
|
|
|
|
CPU_SET_P_CNT(sc, p_cnt);
|
|
|
|
}
|
2001-11-18 18:12:07 +00:00
|
|
|
ACPI_VPRINT(sc->cpu_dev, acpi_device_get_parent_softc(sc->cpu_dev),
|
2003-08-28 16:06:30 +00:00
|
|
|
"set speed to %d.%d%%\n", CPU_SPEED_PRINTABLE(speed));
|
2001-07-07 10:27:17 +00:00
|
|
|
}
|
|
|
|
cpu_current_state = speed;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Power profile change hook.
|
|
|
|
*
|
|
|
|
* Uses the ACPI lock to avoid reentrancy.
|
|
|
|
*/
|
|
|
|
static void
|
2002-03-04 18:46:13 +00:00
|
|
|
acpi_cpu_power_profile(void *arg)
|
2001-07-07 10:27:17 +00:00
|
|
|
{
|
2002-03-04 18:46:13 +00:00
|
|
|
int state;
|
2001-07-07 10:27:17 +00:00
|
|
|
u_int32_t new;
|
2002-10-16 17:28:53 +00:00
|
|
|
ACPI_LOCK_DECL;
|
2001-07-07 10:27:17 +00:00
|
|
|
|
2002-03-04 18:46:13 +00:00
|
|
|
state = power_profile_get_state();
|
2003-08-28 16:06:30 +00:00
|
|
|
if (state != POWER_PROFILE_PERFORMANCE && state != POWER_PROFILE_ECONOMY)
|
2002-03-04 18:46:13 +00:00
|
|
|
return;
|
|
|
|
|
2001-07-07 10:27:17 +00:00
|
|
|
ACPI_LOCK;
|
|
|
|
|
2002-03-04 18:46:13 +00:00
|
|
|
switch (state) {
|
|
|
|
case POWER_PROFILE_PERFORMANCE:
|
|
|
|
new = cpu_performance_state;
|
|
|
|
break;
|
|
|
|
case POWER_PROFILE_ECONOMY:
|
|
|
|
new = cpu_economy_state;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
new = cpu_current_state;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2001-07-07 10:27:17 +00:00
|
|
|
if (cpu_current_state != new)
|
|
|
|
acpi_cpu_set_speed(new);
|
|
|
|
|
|
|
|
ACPI_UNLOCK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle changes in the performance/ecomony CPU settings.
|
|
|
|
*
|
|
|
|
* Does not need the ACPI lock (although setting *argp should
|
|
|
|
* probably be atomic).
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
acpi_cpu_speed_sysctl(SYSCTL_HANDLER_ARGS)
|
|
|
|
{
|
|
|
|
u_int32_t *argp;
|
|
|
|
u_int32_t arg;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
argp = (u_int32_t *)oidp->oid_arg1;
|
|
|
|
arg = *argp;
|
|
|
|
error = sysctl_handle_int(oidp, &arg, 0, req);
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Error or no new value */
|
|
|
|
if (error != 0 || req->newptr == NULL)
|
|
|
|
return (error);
|
|
|
|
if (arg < 1 || arg > cpu_max_state)
|
|
|
|
return (EINVAL);
|
2001-07-07 10:27:17 +00:00
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Set new value and possibly switch */
|
2001-07-07 10:27:17 +00:00
|
|
|
*argp = arg;
|
2002-03-04 18:46:13 +00:00
|
|
|
acpi_cpu_power_profile(NULL);
|
2001-07-07 10:27:17 +00:00
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
return (0);
|
2001-07-07 10:27:17 +00:00
|
|
|
}
|