2001-07-07 10:27:17 +00:00
|
|
|
/*-
|
2003-11-19 20:27:06 +00:00
|
|
|
* Copyright (c) 2003 Nate Lawson (SDG)
|
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/bus.h>
|
2003-11-19 20:27:06 +00:00
|
|
|
#include <sys/kernel.h>
|
2003-12-03 20:27:48 +00:00
|
|
|
#include <sys/malloc.h>
|
2004-05-30 20:08:47 +00:00
|
|
|
#include <sys/module.h>
|
2003-11-19 20:27:06 +00:00
|
|
|
#include <sys/pcpu.h>
|
2002-03-04 18:46:13 +00:00
|
|
|
#include <sys/power.h>
|
2003-11-19 20:27:06 +00:00
|
|
|
#include <sys/proc.h>
|
2003-11-15 19:26:06 +00:00
|
|
|
#include <sys/sbuf.h>
|
|
|
|
#include <sys/smp.h>
|
2001-07-07 10:27:17 +00:00
|
|
|
|
2003-11-15 19:26:06 +00:00
|
|
|
#include <dev/pci/pcivar.h>
|
2003-11-19 20:27:06 +00:00
|
|
|
#include <machine/atomic.h>
|
2001-07-07 10:27:17 +00:00
|
|
|
#include <machine/bus.h>
|
2003-11-19 20:27:06 +00:00
|
|
|
#include <sys/rman.h>
|
2001-07-07 10:27:17 +00:00
|
|
|
|
|
|
|
#include "acpi.h"
|
|
|
|
#include <dev/acpica/acpivar.h>
|
|
|
|
|
|
|
|
/*
|
2003-11-15 19:26:06 +00:00
|
|
|
* Support for ACPI Processor devices, including ACPI 2.0 throttling
|
|
|
|
* and C[1-3] sleep states.
|
2001-07-07 10:27:17 +00:00
|
|
|
*
|
2003-11-15 19:26:06 +00:00
|
|
|
* TODO: implement scans of all CPUs to be sure all Cx states are
|
|
|
|
* equivalent.
|
2001-07-07 10:27:17 +00:00
|
|
|
*/
|
|
|
|
|
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
|
|
|
|
2003-11-15 19:26:06 +00:00
|
|
|
struct acpi_cx {
|
|
|
|
struct resource *p_lvlx; /* Register to read to enter state. */
|
|
|
|
uint32_t type; /* C1-3 (C4 and up treated as C3). */
|
|
|
|
uint32_t trans_lat; /* Transition latency (usec). */
|
|
|
|
uint32_t power; /* Power consumed (mW). */
|
|
|
|
};
|
|
|
|
#define MAX_CX_STATES 8
|
2001-07-07 10:27:17 +00:00
|
|
|
|
2003-11-15 19:26:06 +00:00
|
|
|
struct acpi_cpu_softc {
|
|
|
|
device_t cpu_dev;
|
|
|
|
ACPI_HANDLE cpu_handle;
|
2003-11-26 19:01:33 +00:00
|
|
|
uint32_t acpi_id; /* ACPI processor id */
|
2003-11-19 20:27:06 +00:00
|
|
|
uint32_t cpu_p_blk; /* ACPI P_BLK location */
|
|
|
|
uint32_t cpu_p_blk_len; /* P_BLK length (must be 6). */
|
2003-11-15 19:26:06 +00:00
|
|
|
struct resource *cpu_p_cnt; /* Throttling control register */
|
|
|
|
struct acpi_cx cpu_cx_states[MAX_CX_STATES];
|
2003-11-19 20:27:06 +00:00
|
|
|
int cpu_cx_count; /* Number of valid Cx states. */
|
2004-06-05 07:02:18 +00:00
|
|
|
int cpu_prev_sleep;/* Last idle sleep duration. */
|
2001-07-07 10:27:17 +00:00
|
|
|
};
|
|
|
|
|
2003-11-15 19:26:06 +00:00
|
|
|
#define CPU_GET_REG(reg, width) \
|
|
|
|
(bus_space_read_ ## width(rman_get_bustag((reg)), \
|
|
|
|
rman_get_bushandle((reg)), 0))
|
|
|
|
#define CPU_SET_REG(reg, width, val) \
|
|
|
|
(bus_space_write_ ## width(rman_get_bustag((reg)), \
|
|
|
|
rman_get_bushandle((reg)), 0, (val)))
|
2003-08-28 16:06:30 +00:00
|
|
|
|
2003-12-10 19:10:27 +00:00
|
|
|
/*
|
2003-12-12 19:42:16 +00:00
|
|
|
* Speeds are stored in counts, from 1 to CPU_MAX_SPEED, and
|
2001-07-07 10:27:17 +00:00
|
|
|
* reported to the user in tenths of a percent.
|
|
|
|
*/
|
2003-11-15 19:26:06 +00:00
|
|
|
static uint32_t cpu_duty_offset;
|
|
|
|
static uint32_t cpu_duty_width;
|
2001-07-07 10:27:17 +00:00
|
|
|
#define CPU_MAX_SPEED (1 << cpu_duty_width)
|
|
|
|
#define CPU_SPEED_PERCENT(x) ((1000 * (x)) / CPU_MAX_SPEED)
|
2003-11-15 19:26:06 +00:00
|
|
|
#define CPU_SPEED_PRINTABLE(x) (CPU_SPEED_PERCENT(x) / 10), \
|
|
|
|
(CPU_SPEED_PERCENT(x) % 10)
|
|
|
|
#define CPU_P_CNT_THT_EN (1<<4)
|
|
|
|
#define PM_USEC(x) ((x) >> 2) /* ~4 clocks per usec (3.57955 Mhz) */
|
|
|
|
|
|
|
|
#define ACPI_CPU_NOTIFY_PERF_STATES 0x80 /* _PSS changed. */
|
|
|
|
#define ACPI_CPU_NOTIFY_CX_STATES 0x81 /* _CST changed. */
|
|
|
|
|
2004-10-11 06:06:42 +00:00
|
|
|
#define CPU_QUIRK_NO_C3 (1<<0) /* C3-type states are not usable. */
|
|
|
|
#define CPU_QUIRK_NO_THROTTLE (1<<1) /* Throttling is not usable. */
|
|
|
|
#define CPU_QUIRK_NO_BM_CTRL (1<<2) /* No bus mastering control. */
|
2001-07-07 10:27:17 +00:00
|
|
|
|
2003-11-15 19:26:06 +00:00
|
|
|
#define PCI_VENDOR_INTEL 0x8086
|
|
|
|
#define PCI_DEVICE_82371AB_3 0x7113 /* PIIX4 chipset for quirks. */
|
|
|
|
#define PCI_REVISION_A_STEP 0
|
|
|
|
#define PCI_REVISION_B_STEP 1
|
|
|
|
#define PCI_REVISION_4E 2
|
|
|
|
#define PCI_REVISION_4M 3
|
2001-07-07 10:27:17 +00:00
|
|
|
|
2003-11-15 19:26:06 +00:00
|
|
|
/* Platform hardware resource information. */
|
|
|
|
static uint32_t cpu_smi_cmd; /* Value to write to SMI_CMD. */
|
|
|
|
static uint8_t cpu_pstate_cnt;/* Register to take over throttling. */
|
2003-11-19 20:27:06 +00:00
|
|
|
static uint8_t cpu_cst_cnt; /* Indicate we are _CST aware. */
|
2004-06-05 07:02:18 +00:00
|
|
|
static int cpu_rid; /* Driver-wide resource id. */
|
|
|
|
static int cpu_quirks; /* Indicate any hardware bugs. */
|
2003-11-15 19:26:06 +00:00
|
|
|
|
|
|
|
/* Runtime state. */
|
|
|
|
static int cpu_cx_count; /* Number of valid states */
|
2004-06-05 07:02:18 +00:00
|
|
|
static int cpu_non_c3; /* Index of lowest non-C3 state. */
|
|
|
|
static u_int cpu_cx_stats[MAX_CX_STATES];/* Cx usage history. */
|
2003-11-15 19:26:06 +00:00
|
|
|
|
|
|
|
/* Values for sysctl. */
|
2003-12-18 04:38:45 +00:00
|
|
|
static uint32_t cpu_throttle_state;
|
|
|
|
static uint32_t cpu_throttle_max;
|
2003-11-15 19:26:06 +00:00
|
|
|
static int cpu_cx_lowest;
|
|
|
|
static char cpu_cx_supported[64];
|
2001-07-07 10:27:17 +00:00
|
|
|
|
|
|
|
static device_t *cpu_devices;
|
2003-11-15 19:26:06 +00:00
|
|
|
static int cpu_ndevices;
|
2003-12-03 20:27:48 +00:00
|
|
|
static struct acpi_cpu_softc **cpu_softc;
|
2004-08-13 06:21:47 +00:00
|
|
|
ACPI_SERIAL_DECL(cpu, "ACPI CPU");
|
2001-07-07 10:27:17 +00:00
|
|
|
|
|
|
|
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);
|
2003-11-26 19:01:33 +00:00
|
|
|
static int acpi_pcpu_get_id(uint32_t idx, uint32_t *acpi_id,
|
|
|
|
uint32_t *cpu_id);
|
2003-11-19 20:27:06 +00:00
|
|
|
static int acpi_cpu_shutdown(device_t dev);
|
2003-11-15 19:26:06 +00:00
|
|
|
static int acpi_cpu_throttle_probe(struct acpi_cpu_softc *sc);
|
|
|
|
static int acpi_cpu_cx_probe(struct acpi_cpu_softc *sc);
|
|
|
|
static int acpi_cpu_cx_cst(struct acpi_cpu_softc *sc);
|
|
|
|
static void acpi_cpu_startup(void *arg);
|
|
|
|
static void acpi_cpu_startup_throttling(void);
|
2003-11-19 20:27:06 +00:00
|
|
|
static void acpi_cpu_startup_cx(void);
|
2003-11-15 19:26:06 +00:00
|
|
|
static void acpi_cpu_throttle_set(uint32_t speed);
|
|
|
|
static void acpi_cpu_idle(void);
|
|
|
|
static void acpi_cpu_notify(ACPI_HANDLE h, UINT32 notify, void *context);
|
|
|
|
static int acpi_cpu_quirks(struct acpi_cpu_softc *sc);
|
|
|
|
static int acpi_cpu_throttle_sysctl(SYSCTL_HANDLER_ARGS);
|
2004-06-05 07:02:18 +00:00
|
|
|
static int acpi_cpu_usage_sysctl(SYSCTL_HANDLER_ARGS);
|
2003-11-15 19:26:06 +00:00
|
|
|
static int acpi_cpu_cx_lowest_sysctl(SYSCTL_HANDLER_ARGS);
|
2001-07-07 10:27:17 +00:00
|
|
|
|
|
|
|
static device_method_t acpi_cpu_methods[] = {
|
|
|
|
/* Device interface */
|
|
|
|
DEVMETHOD(device_probe, acpi_cpu_probe),
|
|
|
|
DEVMETHOD(device_attach, acpi_cpu_attach),
|
2003-11-19 20:27:06 +00:00
|
|
|
DEVMETHOD(device_shutdown, acpi_cpu_shutdown),
|
2001-07-07 10:27:17 +00:00
|
|
|
|
|
|
|
{0, 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t acpi_cpu_driver = {
|
2004-05-06 17:25:23 +00:00
|
|
|
"cpu",
|
2001-07-07 10:27:17 +00:00
|
|
|
acpi_cpu_methods,
|
|
|
|
sizeof(struct acpi_cpu_softc),
|
|
|
|
};
|
|
|
|
|
2002-01-08 06:46:01 +00:00
|
|
|
static devclass_t acpi_cpu_devclass;
|
2004-05-06 17:25:23 +00:00
|
|
|
DRIVER_MODULE(cpu, acpi, acpi_cpu_driver, acpi_cpu_devclass, 0, 0);
|
|
|
|
MODULE_DEPEND(cpu, acpi, 1, 1, 1);
|
2003-11-19 20:27:06 +00:00
|
|
|
|
2001-07-07 10:27:17 +00:00
|
|
|
static int
|
|
|
|
acpi_cpu_probe(device_t dev)
|
|
|
|
{
|
2004-05-06 17:25:23 +00:00
|
|
|
int acpi_id, cpu_id, cx_count;
|
2003-11-15 19:26:06 +00:00
|
|
|
ACPI_BUFFER buf;
|
2004-05-06 17:25:23 +00:00
|
|
|
ACPI_HANDLE handle;
|
|
|
|
char msg[32];
|
|
|
|
ACPI_OBJECT *obj;
|
2003-11-15 19:26:06 +00:00
|
|
|
ACPI_STATUS status;
|
2001-07-07 10:27:17 +00:00
|
|
|
|
2004-05-06 17:25:23 +00:00
|
|
|
if (acpi_disabled("cpu") || acpi_get_type(dev) != ACPI_TYPE_PROCESSOR)
|
|
|
|
return (ENXIO);
|
2001-07-07 10:27:17 +00:00
|
|
|
|
2004-05-06 17:25:23 +00:00
|
|
|
handle = acpi_get_handle(dev);
|
|
|
|
if (cpu_softc == NULL)
|
|
|
|
cpu_softc = malloc(sizeof(struct acpi_cpu_softc *) *
|
|
|
|
(mp_maxid + 1), M_TEMP /* XXX */, M_WAITOK | M_ZERO);
|
2001-07-07 10:27:17 +00:00
|
|
|
|
2003-11-15 19:26:06 +00:00
|
|
|
/* Get our Processor object. */
|
2004-05-06 17:25:23 +00:00
|
|
|
buf.Pointer = NULL;
|
|
|
|
buf.Length = ACPI_ALLOCATE_BUFFER;
|
|
|
|
status = AcpiEvaluateObject(handle, NULL, NULL, &buf);
|
2003-08-28 16:06:30 +00:00
|
|
|
if (ACPI_FAILURE(status)) {
|
2004-05-06 17:25:23 +00:00
|
|
|
device_printf(dev, "probe failed to get Processor obj - %s\n",
|
2003-08-28 16:06:30 +00:00
|
|
|
AcpiFormatException(status));
|
2004-05-06 17:25:23 +00:00
|
|
|
return (ENXIO);
|
2001-07-07 10:27:17 +00:00
|
|
|
}
|
2004-05-06 17:25:23 +00:00
|
|
|
obj = (ACPI_OBJECT *)buf.Pointer;
|
|
|
|
if (obj->Type != ACPI_TYPE_PROCESSOR) {
|
|
|
|
device_printf(dev, "Processor object has bad type %d\n", obj->Type);
|
|
|
|
AcpiOsFree(obj);
|
|
|
|
return (ENXIO);
|
2001-07-07 10:27:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2003-11-26 19:01:33 +00:00
|
|
|
* Find the processor associated with our unit. We could use the
|
|
|
|
* ProcId as a key, however, some boxes do not have the same values
|
|
|
|
* in their Processor object as the ProcId values in the MADT.
|
2001-07-07 10:27:17 +00:00
|
|
|
*/
|
2004-05-06 17:25:23 +00:00
|
|
|
acpi_id = obj->Processor.ProcId;
|
|
|
|
AcpiOsFree(obj);
|
|
|
|
if (acpi_pcpu_get_id(device_get_unit(dev), &acpi_id, &cpu_id) != 0)
|
|
|
|
return (ENXIO);
|
2003-11-15 19:26:06 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if we already probed this processor. We scan the bus twice
|
|
|
|
* so it's possible we've already seen this one.
|
|
|
|
*/
|
|
|
|
if (cpu_softc[cpu_id] != NULL)
|
|
|
|
return (ENXIO);
|
|
|
|
|
2004-05-06 17:25:23 +00:00
|
|
|
/* Get a count of Cx states for our device string. */
|
|
|
|
cx_count = 0;
|
|
|
|
buf.Pointer = NULL;
|
|
|
|
buf.Length = ACPI_ALLOCATE_BUFFER;
|
|
|
|
status = AcpiEvaluateObject(handle, "_CST", NULL, &buf);
|
|
|
|
if (ACPI_SUCCESS(status)) {
|
|
|
|
obj = (ACPI_OBJECT *)buf.Pointer;
|
|
|
|
if (ACPI_PKG_VALID(obj, 2))
|
|
|
|
acpi_PkgInt32(obj, 0, &cx_count);
|
|
|
|
AcpiOsFree(obj);
|
|
|
|
} else {
|
|
|
|
if (AcpiGbl_FADT->Plvl2Lat <= 100)
|
|
|
|
cx_count++;
|
|
|
|
if (AcpiGbl_FADT->Plvl3Lat <= 1000)
|
|
|
|
cx_count++;
|
|
|
|
if (cx_count > 0)
|
|
|
|
cx_count++;
|
|
|
|
}
|
|
|
|
if (cx_count > 0)
|
|
|
|
snprintf(msg, sizeof(msg), "ACPI CPU (%d Cx states)", cx_count);
|
|
|
|
else
|
|
|
|
strlcpy(msg, "ACPI CPU", sizeof(msg));
|
|
|
|
device_set_desc_copy(dev, msg);
|
|
|
|
|
|
|
|
/* Mark this processor as in-use and save our derived id for attach. */
|
|
|
|
cpu_softc[cpu_id] = (void *)1;
|
|
|
|
acpi_set_magic(dev, cpu_id);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
acpi_cpu_attach(device_t dev)
|
|
|
|
{
|
|
|
|
ACPI_BUFFER buf;
|
|
|
|
ACPI_OBJECT *obj;
|
|
|
|
struct acpi_cpu_softc *sc;
|
|
|
|
struct acpi_softc *acpi_sc;
|
|
|
|
ACPI_STATUS status;
|
|
|
|
int thr_ret, cx_ret;
|
|
|
|
|
|
|
|
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
|
|
|
|
|
|
|
|
sc = device_get_softc(dev);
|
|
|
|
sc->cpu_dev = dev;
|
|
|
|
sc->cpu_handle = acpi_get_handle(dev);
|
|
|
|
cpu_softc[acpi_get_magic(dev)] = sc;
|
|
|
|
|
|
|
|
buf.Pointer = NULL;
|
|
|
|
buf.Length = ACPI_ALLOCATE_BUFFER;
|
|
|
|
status = AcpiEvaluateObject(sc->cpu_handle, NULL, NULL, &buf);
|
|
|
|
if (ACPI_FAILURE(status)) {
|
|
|
|
device_printf(dev, "attach failed to get Processor obj - %s\n",
|
|
|
|
AcpiFormatException(status));
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
obj = (ACPI_OBJECT *)buf.Pointer;
|
|
|
|
sc->cpu_p_blk = obj->Processor.PblkAddress;
|
|
|
|
sc->cpu_p_blk_len = obj->Processor.PblkLength;
|
|
|
|
sc->acpi_id = obj->Processor.ProcId;
|
|
|
|
AcpiOsFree(obj);
|
2003-11-19 20:27:06 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_INFO, "acpi_cpu%d: P_BLK at %#x/%d\n",
|
|
|
|
device_get_unit(dev), sc->cpu_p_blk, sc->cpu_p_blk_len));
|
2003-11-15 19:26:06 +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,
|
|
|
|
SYSCTL_CHILDREN(acpi_sc->acpi_sysctl_tree),
|
|
|
|
OID_AUTO, "cpu", CTLFLAG_RD, 0, "");
|
|
|
|
|
|
|
|
/* If this is the first device probed, check for quirks. */
|
|
|
|
if (device_get_unit(dev) == 0)
|
|
|
|
acpi_cpu_quirks(sc);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Probe for throttling and Cx state support.
|
|
|
|
* If none of these is present, free up unused resources.
|
|
|
|
*/
|
|
|
|
thr_ret = acpi_cpu_throttle_probe(sc);
|
|
|
|
cx_ret = acpi_cpu_cx_probe(sc);
|
|
|
|
if (thr_ret == 0 || cx_ret == 0) {
|
|
|
|
status = AcpiInstallNotifyHandler(sc->cpu_handle, ACPI_DEVICE_NOTIFY,
|
|
|
|
acpi_cpu_notify, sc);
|
2003-11-19 20:27:06 +00:00
|
|
|
if (device_get_unit(dev) == 0)
|
|
|
|
AcpiOsQueueForExecution(OSD_PRIORITY_LO, acpi_cpu_startup, NULL);
|
2003-11-15 19:26:06 +00:00
|
|
|
} else {
|
|
|
|
sysctl_ctx_free(&acpi_cpu_sysctl_ctx);
|
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
|
|
|
}
|
|
|
|
|
2003-11-26 19:01:33 +00:00
|
|
|
/*
|
|
|
|
* Find the nth present CPU and return its pc_cpuid as well as set the
|
|
|
|
* pc_acpi_id from the most reliable source.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
acpi_pcpu_get_id(uint32_t idx, uint32_t *acpi_id, uint32_t *cpu_id)
|
|
|
|
{
|
|
|
|
struct pcpu *pcpu_data;
|
|
|
|
uint32_t i;
|
2003-12-10 19:10:27 +00:00
|
|
|
|
2003-11-26 19:01:33 +00:00
|
|
|
KASSERT(acpi_id != NULL, ("Null acpi_id"));
|
|
|
|
KASSERT(cpu_id != NULL, ("Null cpu_id"));
|
2003-12-03 20:27:48 +00:00
|
|
|
for (i = 0; i <= mp_maxid; i++) {
|
2003-11-26 19:01:33 +00:00
|
|
|
if (CPU_ABSENT(i))
|
|
|
|
continue;
|
|
|
|
pcpu_data = pcpu_find(i);
|
|
|
|
KASSERT(pcpu_data != NULL, ("no pcpu data for %d", i));
|
|
|
|
if (idx-- == 0) {
|
|
|
|
/*
|
|
|
|
* If pc_acpi_id was not initialized (e.g., a non-APIC UP box)
|
|
|
|
* override it with the value from the ASL. Otherwise, if the
|
|
|
|
* two don't match, prefer the MADT-derived value. Finally,
|
|
|
|
* return the pc_cpuid to reference this processor.
|
|
|
|
*/
|
|
|
|
if (pcpu_data->pc_acpi_id == 0xffffffff)
|
|
|
|
pcpu_data->pc_acpi_id = *acpi_id;
|
|
|
|
else if (pcpu_data->pc_acpi_id != *acpi_id)
|
|
|
|
*acpi_id = pcpu_data->pc_acpi_id;
|
|
|
|
*cpu_id = pcpu_data->pc_cpuid;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (ESRCH);
|
|
|
|
}
|
2003-12-10 19:10:27 +00:00
|
|
|
|
2003-11-19 20:27:06 +00:00
|
|
|
static int
|
|
|
|
acpi_cpu_shutdown(device_t dev)
|
|
|
|
{
|
|
|
|
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
|
|
|
|
|
|
|
|
/* Disable any entry to the idle function. */
|
|
|
|
cpu_cx_count = 0;
|
|
|
|
|
2004-06-05 07:02:18 +00:00
|
|
|
/* Signal and wait for all processors to exit acpi_cpu_idle(). */
|
2003-11-19 20:27:06 +00:00
|
|
|
smp_rendezvous(NULL, NULL, NULL, NULL);
|
|
|
|
|
|
|
|
return_VALUE (0);
|
|
|
|
}
|
|
|
|
|
2003-11-15 19:26:06 +00:00
|
|
|
static int
|
|
|
|
acpi_cpu_throttle_probe(struct acpi_cpu_softc *sc)
|
|
|
|
{
|
|
|
|
uint32_t duty_end;
|
|
|
|
ACPI_BUFFER buf;
|
|
|
|
ACPI_OBJECT obj;
|
|
|
|
ACPI_GENERIC_ADDRESS gas;
|
|
|
|
ACPI_STATUS status;
|
|
|
|
|
|
|
|
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
|
|
|
|
|
|
|
|
/* Get throttling parameters from the FADT. 0 means not supported. */
|
2003-11-19 20:27:06 +00:00
|
|
|
if (device_get_unit(sc->cpu_dev) == 0) {
|
|
|
|
cpu_smi_cmd = AcpiGbl_FADT->SmiCmd;
|
|
|
|
cpu_pstate_cnt = AcpiGbl_FADT->PstateCnt;
|
|
|
|
cpu_cst_cnt = AcpiGbl_FADT->CstCnt;
|
|
|
|
cpu_duty_offset = AcpiGbl_FADT->DutyOffset;
|
|
|
|
cpu_duty_width = AcpiGbl_FADT->DutyWidth;
|
|
|
|
}
|
2003-11-15 19:26:06 +00:00
|
|
|
if (cpu_duty_width == 0 || (cpu_quirks & CPU_QUIRK_NO_THROTTLE) != 0)
|
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
/* Validate the duty offset/width. */
|
|
|
|
duty_end = cpu_duty_offset + cpu_duty_width - 1;
|
|
|
|
if (duty_end > 31) {
|
|
|
|
device_printf(sc->cpu_dev, "CLK_VAL field overflows P_CNT register\n");
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
if (cpu_duty_offset <= 4 && duty_end >= 4) {
|
|
|
|
device_printf(sc->cpu_dev, "CLK_VAL field overlaps THT_EN bit\n");
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If not present, fall back to using the processor's P_BLK to find
|
|
|
|
* the P_CNT register.
|
|
|
|
*
|
|
|
|
* Note that some systems seem to duplicate the P_BLK pointer
|
|
|
|
* across multiple CPUs, so not getting the resource is not fatal.
|
|
|
|
*/
|
|
|
|
buf.Pointer = &obj;
|
|
|
|
buf.Length = sizeof(obj);
|
|
|
|
status = AcpiEvaluateObject(sc->cpu_handle, "_PTC", NULL, &buf);
|
|
|
|
if (ACPI_SUCCESS(status)) {
|
|
|
|
if (obj.Buffer.Length < sizeof(ACPI_GENERIC_ADDRESS) + 3) {
|
|
|
|
device_printf(sc->cpu_dev, "_PTC buffer too small\n");
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
memcpy(&gas, obj.Buffer.Pointer + 3, sizeof(gas));
|
|
|
|
sc->cpu_p_cnt = acpi_bus_alloc_gas(sc->cpu_dev, &cpu_rid, &gas);
|
|
|
|
if (sc->cpu_p_cnt != NULL) {
|
2003-11-19 20:27:06 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_INFO, "acpi_cpu%d: P_CNT from _PTC\n",
|
2003-11-15 19:26:06 +00:00
|
|
|
device_get_unit(sc->cpu_dev)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If _PTC not present or other failure, try the P_BLK. */
|
|
|
|
if (sc->cpu_p_cnt == NULL) {
|
2004-03-04 05:17:52 +00:00
|
|
|
/*
|
|
|
|
* The spec says P_BLK must be 6 bytes long. However, some
|
|
|
|
* systems use it to indicate a fractional set of features
|
|
|
|
* present so we take anything >= 4.
|
|
|
|
*/
|
|
|
|
if (sc->cpu_p_blk_len < 4)
|
2003-11-15 19:26:06 +00:00
|
|
|
return (ENXIO);
|
2003-11-19 20:27:06 +00:00
|
|
|
gas.Address = sc->cpu_p_blk;
|
2003-11-15 19:26:06 +00:00
|
|
|
gas.AddressSpaceId = ACPI_ADR_SPACE_SYSTEM_IO;
|
|
|
|
gas.RegisterBitWidth = 32;
|
|
|
|
sc->cpu_p_cnt = acpi_bus_alloc_gas(sc->cpu_dev, &cpu_rid, &gas);
|
|
|
|
if (sc->cpu_p_cnt != NULL) {
|
2003-11-19 20:27:06 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_INFO, "acpi_cpu%d: P_CNT from P_BLK\n",
|
2003-11-15 19:26:06 +00:00
|
|
|
device_get_unit(sc->cpu_dev)));
|
|
|
|
} else {
|
|
|
|
device_printf(sc->cpu_dev, "Failed to attach throttling P_CNT\n");
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cpu_rid++;
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
acpi_cpu_cx_probe(struct acpi_cpu_softc *sc)
|
|
|
|
{
|
|
|
|
ACPI_GENERIC_ADDRESS gas;
|
|
|
|
struct acpi_cx *cx_ptr;
|
2003-11-19 20:27:06 +00:00
|
|
|
int error;
|
|
|
|
|
|
|
|
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
|
2003-11-15 19:26:06 +00:00
|
|
|
|
2004-10-11 06:06:42 +00:00
|
|
|
/*
|
|
|
|
* Bus mastering arbitration control is needed to keep caches coherent
|
|
|
|
* while sleeping in C3. If it's not present, we flush the caches before
|
|
|
|
* entering C3 instead.
|
|
|
|
*/
|
2003-11-15 19:26:06 +00:00
|
|
|
if (AcpiGbl_FADT->V1_Pm2CntBlk == 0 || AcpiGbl_FADT->Pm2CntLen == 0) {
|
2004-10-11 06:06:42 +00:00
|
|
|
cpu_quirks |= CPU_QUIRK_NO_BM_CTRL;
|
2003-11-19 20:27:06 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_INFO,
|
2004-10-11 06:06:42 +00:00
|
|
|
"acpi_cpu%d: no BM control, using flush cache method\n",
|
|
|
|
device_get_unit(sc->cpu_dev)));
|
2003-11-15 19:26:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* First, check for the ACPI 2.0 _CST sleep states object.
|
|
|
|
* If not usable, fall back to the P_BLK's P_LVL2 and P_LVL3.
|
|
|
|
*/
|
2003-11-19 20:27:06 +00:00
|
|
|
sc->cpu_cx_count = 0;
|
2003-11-15 19:26:06 +00:00
|
|
|
error = acpi_cpu_cx_cst(sc);
|
|
|
|
if (error != 0) {
|
|
|
|
cx_ptr = sc->cpu_cx_states;
|
|
|
|
|
|
|
|
/* C1 has been required since just after ACPI 1.0 */
|
|
|
|
cx_ptr->type = ACPI_STATE_C1;
|
|
|
|
cx_ptr->trans_lat = 0;
|
|
|
|
cpu_non_c3 = 0;
|
|
|
|
cx_ptr++;
|
2003-11-19 20:27:06 +00:00
|
|
|
sc->cpu_cx_count++;
|
|
|
|
|
2004-03-04 05:17:52 +00:00
|
|
|
/*
|
|
|
|
* The spec says P_BLK must be 6 bytes long. However, some systems
|
|
|
|
* use it to indicate a fractional set of features present so we
|
|
|
|
* take 5 as C2. Some may also have a value of 7 to indicate
|
|
|
|
* another C3 but most use _CST for this (as required) and having
|
|
|
|
* "only" C1-C3 is not a hardship.
|
|
|
|
*/
|
|
|
|
if (sc->cpu_p_blk_len < 5)
|
2003-11-19 20:27:06 +00:00
|
|
|
goto done;
|
2003-11-15 19:26:06 +00:00
|
|
|
|
|
|
|
/* Validate and allocate resources for C2 (P_LVL2). */
|
|
|
|
gas.AddressSpaceId = ACPI_ADR_SPACE_SYSTEM_IO;
|
|
|
|
gas.RegisterBitWidth = 8;
|
2004-03-17 21:49:47 +00:00
|
|
|
if (AcpiGbl_FADT->Plvl2Lat <= 100) {
|
2003-11-19 20:27:06 +00:00
|
|
|
gas.Address = sc->cpu_p_blk + 4;
|
2003-11-15 19:26:06 +00:00
|
|
|
cx_ptr->p_lvlx = acpi_bus_alloc_gas(sc->cpu_dev, &cpu_rid, &gas);
|
|
|
|
if (cx_ptr->p_lvlx != NULL) {
|
|
|
|
cpu_rid++;
|
|
|
|
cx_ptr->type = ACPI_STATE_C2;
|
|
|
|
cx_ptr->trans_lat = AcpiGbl_FADT->Plvl2Lat;
|
|
|
|
cpu_non_c3 = 1;
|
|
|
|
cx_ptr++;
|
2003-11-19 20:27:06 +00:00
|
|
|
sc->cpu_cx_count++;
|
2003-11-15 19:26:06 +00:00
|
|
|
}
|
|
|
|
}
|
2004-03-04 05:17:52 +00:00
|
|
|
if (sc->cpu_p_blk_len < 6)
|
|
|
|
goto done;
|
2003-11-15 19:26:06 +00:00
|
|
|
|
|
|
|
/* Validate and allocate resources for C3 (P_LVL3). */
|
2004-03-17 21:49:47 +00:00
|
|
|
if (AcpiGbl_FADT->Plvl3Lat <= 1000 &&
|
2003-11-15 19:26:06 +00:00
|
|
|
(cpu_quirks & CPU_QUIRK_NO_C3) == 0) {
|
|
|
|
|
2003-11-19 20:27:06 +00:00
|
|
|
gas.Address = sc->cpu_p_blk + 5;
|
2003-11-15 19:26:06 +00:00
|
|
|
cx_ptr->p_lvlx = acpi_bus_alloc_gas(sc->cpu_dev, &cpu_rid, &gas);
|
|
|
|
if (cx_ptr->p_lvlx != NULL) {
|
|
|
|
cpu_rid++;
|
|
|
|
cx_ptr->type = ACPI_STATE_C3;
|
|
|
|
cx_ptr->trans_lat = AcpiGbl_FADT->Plvl3Lat;
|
|
|
|
cx_ptr++;
|
2003-11-19 20:27:06 +00:00
|
|
|
sc->cpu_cx_count++;
|
2003-11-15 19:26:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-19 20:27:06 +00:00
|
|
|
done:
|
2003-11-15 19:26:06 +00:00
|
|
|
/* If no valid registers were found, don't attach. */
|
2003-11-19 20:27:06 +00:00
|
|
|
if (sc->cpu_cx_count == 0)
|
2003-11-15 19:26:06 +00:00
|
|
|
return (ENXIO);
|
|
|
|
|
2004-06-05 07:02:18 +00:00
|
|
|
/* Use initial sleep value of 1 sec. to start with lowest idle state. */
|
|
|
|
sc->cpu_prev_sleep = 1000000;
|
|
|
|
|
2003-11-15 19:26:06 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Parse a _CST package and set up its Cx states. Since the _CST object
|
|
|
|
* can change dynamically, our notify handler may call this function
|
|
|
|
* to clean up and probe the new _CST package.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
acpi_cpu_cx_cst(struct acpi_cpu_softc *sc)
|
|
|
|
{
|
|
|
|
struct acpi_cx *cx_ptr;
|
|
|
|
ACPI_STATUS status;
|
|
|
|
ACPI_BUFFER buf;
|
|
|
|
ACPI_OBJECT *top;
|
|
|
|
ACPI_OBJECT *pkg;
|
|
|
|
uint32_t count;
|
|
|
|
int i;
|
|
|
|
|
2003-11-19 20:27:06 +00:00
|
|
|
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
|
|
|
|
|
2003-11-15 19:26:06 +00:00
|
|
|
buf.Pointer = NULL;
|
|
|
|
buf.Length = ACPI_ALLOCATE_BUFFER;
|
|
|
|
status = AcpiEvaluateObject(sc->cpu_handle, "_CST", NULL, &buf);
|
|
|
|
if (ACPI_FAILURE(status))
|
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
/* _CST is a package with a count and at least one Cx package. */
|
|
|
|
top = (ACPI_OBJECT *)buf.Pointer;
|
2003-12-23 18:26:53 +00:00
|
|
|
if (!ACPI_PKG_VALID(top, 2) || acpi_PkgInt32(top, 0, &count) != 0) {
|
2003-11-15 19:26:06 +00:00
|
|
|
device_printf(sc->cpu_dev, "Invalid _CST package\n");
|
|
|
|
AcpiOsFree(buf.Pointer);
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
if (count != top->Package.Count - 1) {
|
|
|
|
device_printf(sc->cpu_dev, "Invalid _CST state count (%d != %d)\n",
|
|
|
|
count, top->Package.Count - 1);
|
|
|
|
count = top->Package.Count - 1;
|
|
|
|
}
|
|
|
|
if (count > MAX_CX_STATES) {
|
2003-11-19 20:27:06 +00:00
|
|
|
device_printf(sc->cpu_dev, "_CST has too many states (%d)\n", count);
|
2003-11-15 19:26:06 +00:00
|
|
|
count = MAX_CX_STATES;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set up all valid states. */
|
2003-11-19 20:27:06 +00:00
|
|
|
sc->cpu_cx_count = 0;
|
2003-11-15 19:26:06 +00:00
|
|
|
cx_ptr = sc->cpu_cx_states;
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
pkg = &top->Package.Elements[i + 1];
|
2003-12-23 18:26:53 +00:00
|
|
|
if (!ACPI_PKG_VALID(pkg, 4) ||
|
|
|
|
acpi_PkgInt32(pkg, 1, &cx_ptr->type) != 0 ||
|
|
|
|
acpi_PkgInt32(pkg, 2, &cx_ptr->trans_lat) != 0 ||
|
|
|
|
acpi_PkgInt32(pkg, 3, &cx_ptr->power) != 0) {
|
|
|
|
|
2003-11-15 19:26:06 +00:00
|
|
|
device_printf(sc->cpu_dev, "Skipping invalid Cx state package\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Validate the state to see if we should use it. */
|
|
|
|
switch (cx_ptr->type) {
|
|
|
|
case ACPI_STATE_C1:
|
|
|
|
cpu_non_c3 = i;
|
|
|
|
cx_ptr++;
|
2003-11-19 20:27:06 +00:00
|
|
|
sc->cpu_cx_count++;
|
2003-11-15 19:26:06 +00:00
|
|
|
continue;
|
|
|
|
case ACPI_STATE_C2:
|
|
|
|
if (cx_ptr->trans_lat > 100) {
|
2003-11-19 20:27:06 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_INFO,
|
|
|
|
"acpi_cpu%d: C2[%d] not available.\n",
|
|
|
|
device_get_unit(sc->cpu_dev), i));
|
2003-11-15 19:26:06 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
cpu_non_c3 = i;
|
|
|
|
break;
|
|
|
|
case ACPI_STATE_C3:
|
|
|
|
default:
|
|
|
|
if (cx_ptr->trans_lat > 1000 ||
|
|
|
|
(cpu_quirks & CPU_QUIRK_NO_C3) != 0) {
|
|
|
|
|
2003-11-19 20:27:06 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_INFO,
|
|
|
|
"acpi_cpu%d: C3[%d] not available.\n",
|
|
|
|
device_get_unit(sc->cpu_dev), i));
|
2003-11-15 19:26:06 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef notyet
|
|
|
|
/* Free up any previous register. */
|
|
|
|
if (cx_ptr->p_lvlx != NULL) {
|
|
|
|
bus_release_resource(sc->cpu_dev, 0, 0, cx_ptr->p_lvlx);
|
|
|
|
cx_ptr->p_lvlx = NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Allocate the control register for C2 or C3. */
|
|
|
|
acpi_PkgGas(sc->cpu_dev, pkg, 0, &cpu_rid, &cx_ptr->p_lvlx);
|
|
|
|
if (cx_ptr->p_lvlx != NULL) {
|
|
|
|
cpu_rid++;
|
2003-11-19 20:27:06 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_INFO,
|
|
|
|
"acpi_cpu%d: Got C%d - %d latency\n",
|
|
|
|
device_get_unit(sc->cpu_dev), cx_ptr->type,
|
|
|
|
cx_ptr->trans_lat));
|
2003-11-15 19:26:06 +00:00
|
|
|
cx_ptr++;
|
2003-11-19 20:27:06 +00:00
|
|
|
sc->cpu_cx_count++;
|
2003-11-15 19:26:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
AcpiOsFree(buf.Pointer);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2001-07-07 10:27:17 +00:00
|
|
|
/*
|
|
|
|
* Call this *after* all CPUs have been attached.
|
|
|
|
*/
|
|
|
|
static void
|
2003-11-15 19:26:06 +00:00
|
|
|
acpi_cpu_startup(void *arg)
|
2001-07-07 10:27:17 +00:00
|
|
|
{
|
2003-11-19 20:27:06 +00:00
|
|
|
struct acpi_cpu_softc *sc;
|
|
|
|
int count, i;
|
2001-07-07 10:27:17 +00:00
|
|
|
|
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-11-19 20:27:06 +00:00
|
|
|
/*
|
|
|
|
* Make sure all the processors' Cx counts match. We should probably
|
|
|
|
* also check the contents of each. However, no known systems have
|
|
|
|
* non-matching Cx counts so we'll deal with this later.
|
|
|
|
*/
|
|
|
|
count = MAX_CX_STATES;
|
|
|
|
for (i = 0; i < cpu_ndevices; i++) {
|
|
|
|
sc = device_get_softc(cpu_devices[i]);
|
|
|
|
count = min(sc->cpu_cx_count, count);
|
|
|
|
}
|
|
|
|
cpu_cx_count = count;
|
|
|
|
|
|
|
|
/* Perform throttling and Cx final initialization. */
|
|
|
|
sc = device_get_softc(cpu_devices[0]);
|
2003-11-15 19:26:06 +00:00
|
|
|
if (sc->cpu_p_cnt != NULL)
|
|
|
|
acpi_cpu_startup_throttling();
|
2003-11-19 20:27:06 +00:00
|
|
|
if (cpu_cx_count > 0)
|
|
|
|
acpi_cpu_startup_cx();
|
2003-11-15 19:26:06 +00:00
|
|
|
}
|
|
|
|
|
2003-11-19 20:27:06 +00:00
|
|
|
/*
|
|
|
|
* Takes the ACPI lock to avoid fighting anyone over the SMI command
|
|
|
|
* port.
|
|
|
|
*/
|
2003-11-15 19:26:06 +00:00
|
|
|
static void
|
|
|
|
acpi_cpu_startup_throttling()
|
|
|
|
{
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Initialise throttling states */
|
2003-12-18 04:38:45 +00:00
|
|
|
cpu_throttle_max = CPU_MAX_SPEED;
|
|
|
|
cpu_throttle_state = CPU_MAX_SPEED;
|
2001-07-07 10:27:17 +00:00
|
|
|
|
2003-11-19 20:27:06 +00:00
|
|
|
SYSCTL_ADD_INT(&acpi_cpu_sysctl_ctx,
|
|
|
|
SYSCTL_CHILDREN(acpi_cpu_sysctl_tree),
|
2003-12-18 04:38:45 +00:00
|
|
|
OID_AUTO, "throttle_max", CTLFLAG_RD,
|
|
|
|
&cpu_throttle_max, 0, "maximum CPU speed");
|
2003-11-19 20:27:06 +00:00
|
|
|
SYSCTL_ADD_PROC(&acpi_cpu_sysctl_ctx,
|
|
|
|
SYSCTL_CHILDREN(acpi_cpu_sysctl_tree),
|
2003-12-18 04:38:45 +00:00
|
|
|
OID_AUTO, "throttle_state",
|
|
|
|
CTLTYPE_INT | CTLFLAG_RW, &cpu_throttle_state,
|
|
|
|
0, acpi_cpu_throttle_sysctl, "I", "current CPU speed");
|
2003-11-19 20:27:06 +00:00
|
|
|
|
2003-11-15 19:26:06 +00:00
|
|
|
/* If ACPI 2.0+, signal platform that we are taking over throttling. */
|
2004-08-13 06:21:47 +00:00
|
|
|
if (cpu_pstate_cnt != 0) {
|
|
|
|
ACPI_LOCK(acpi);
|
2001-07-21 04:05:32 +00:00
|
|
|
AcpiOsWritePort(cpu_smi_cmd, cpu_pstate_cnt, 8);
|
2004-08-13 06:21:47 +00:00
|
|
|
ACPI_UNLOCK(acpi);
|
|
|
|
}
|
2001-07-07 10:27:17 +00:00
|
|
|
|
2003-12-18 04:38:45 +00:00
|
|
|
/* Set initial speed to maximum. */
|
2004-08-13 06:21:47 +00:00
|
|
|
ACPI_SERIAL_BEGIN(cpu);
|
2003-12-18 04:38:45 +00:00
|
|
|
acpi_cpu_throttle_set(cpu_throttle_max);
|
2004-08-13 06:21:47 +00:00
|
|
|
ACPI_SERIAL_END(cpu);
|
2003-11-15 19:26:06 +00:00
|
|
|
|
2003-12-10 19:10:27 +00:00
|
|
|
printf("acpi_cpu: throttling enabled, %d steps (100%% to %d.%d%%), "
|
2003-01-23 22:18:14 +00:00
|
|
|
"currently %d.%d%%\n", CPU_MAX_SPEED, CPU_SPEED_PRINTABLE(1),
|
2003-12-18 04:38:45 +00:00
|
|
|
CPU_SPEED_PRINTABLE(cpu_throttle_state));
|
2001-07-07 10:27:17 +00:00
|
|
|
}
|
|
|
|
|
2003-11-19 20:27:06 +00:00
|
|
|
static void
|
|
|
|
acpi_cpu_startup_cx()
|
|
|
|
{
|
|
|
|
struct acpi_cpu_softc *sc;
|
|
|
|
struct sbuf sb;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
sc = device_get_softc(cpu_devices[0]);
|
|
|
|
sbuf_new(&sb, cpu_cx_supported, sizeof(cpu_cx_supported), SBUF_FIXEDLEN);
|
2004-05-07 05:22:38 +00:00
|
|
|
for (i = 0; i < cpu_cx_count; i++)
|
|
|
|
sbuf_printf(&sb, "C%d/%d ", i + 1, sc->cpu_cx_states[i].trans_lat);
|
2003-11-19 20:27:06 +00:00
|
|
|
sbuf_trim(&sb);
|
|
|
|
sbuf_finish(&sb);
|
|
|
|
SYSCTL_ADD_STRING(&acpi_cpu_sysctl_ctx,
|
|
|
|
SYSCTL_CHILDREN(acpi_cpu_sysctl_tree),
|
|
|
|
OID_AUTO, "cx_supported", CTLFLAG_RD, cpu_cx_supported,
|
|
|
|
0, "Cx/microsecond values for supported Cx states");
|
|
|
|
SYSCTL_ADD_PROC(&acpi_cpu_sysctl_ctx,
|
|
|
|
SYSCTL_CHILDREN(acpi_cpu_sysctl_tree),
|
2004-05-07 05:22:38 +00:00
|
|
|
OID_AUTO, "cx_lowest", CTLTYPE_STRING | CTLFLAG_RW,
|
|
|
|
NULL, 0, acpi_cpu_cx_lowest_sysctl, "A",
|
2003-11-19 20:27:06 +00:00
|
|
|
"lowest Cx sleep state to use");
|
|
|
|
SYSCTL_ADD_PROC(&acpi_cpu_sysctl_ctx,
|
|
|
|
SYSCTL_CHILDREN(acpi_cpu_sysctl_tree),
|
2004-06-05 07:02:18 +00:00
|
|
|
OID_AUTO, "cx_usage", CTLTYPE_STRING | CTLFLAG_RD,
|
|
|
|
NULL, 0, acpi_cpu_usage_sysctl, "A",
|
|
|
|
"percent usage for each Cx state");
|
2003-11-19 20:27:06 +00:00
|
|
|
|
|
|
|
#ifdef notyet
|
|
|
|
/* Signal platform that we can handle _CST notification. */
|
|
|
|
if (cpu_cst_cnt != 0) {
|
2004-08-13 06:21:47 +00:00
|
|
|
ACPI_LOCK(acpi);
|
2003-11-19 20:27:06 +00:00
|
|
|
AcpiOsWritePort(cpu_smi_cmd, cpu_cst_cnt, 8);
|
2004-08-13 06:21:47 +00:00
|
|
|
ACPI_UNLOCK(acpi);
|
2003-11-19 20:27:06 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Take over idling from cpu_idle_default(). */
|
|
|
|
cpu_idle_hook = acpi_cpu_idle;
|
|
|
|
}
|
|
|
|
|
2001-07-07 10:27:17 +00:00
|
|
|
/*
|
|
|
|
* Set CPUs to the new state.
|
|
|
|
*
|
|
|
|
* Must be called with the ACPI lock held.
|
|
|
|
*/
|
|
|
|
static void
|
2003-11-15 19:26:06 +00:00
|
|
|
acpi_cpu_throttle_set(uint32_t speed)
|
2001-07-07 10:27:17 +00:00
|
|
|
{
|
|
|
|
struct acpi_cpu_softc *sc;
|
|
|
|
int i;
|
2003-11-15 19:26:06 +00:00
|
|
|
uint32_t p_cnt, clk_val;
|
2001-07-07 10:27:17 +00:00
|
|
|
|
2004-08-13 06:21:47 +00:00
|
|
|
ACPI_SERIAL_ASSERT(cpu);
|
2001-07-07 10:27:17 +00:00
|
|
|
|
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]);
|
2003-11-15 19:26:06 +00:00
|
|
|
if (sc->cpu_p_cnt == NULL)
|
2001-07-07 10:27:17 +00:00
|
|
|
continue;
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Get the current P_CNT value and disable throttling */
|
2003-11-15 19:26:06 +00:00
|
|
|
p_cnt = CPU_GET_REG(sc->cpu_p_cnt, 4);
|
2001-07-07 10:27:17 +00:00
|
|
|
p_cnt &= ~CPU_P_CNT_THT_EN;
|
2003-11-15 19:26:06 +00:00
|
|
|
CPU_SET_REG(sc->cpu_p_cnt, 4, p_cnt);
|
2001-07-07 10:27:17 +00:00
|
|
|
|
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 */
|
2003-12-12 19:42:16 +00:00
|
|
|
clk_val = (CPU_MAX_SPEED - 1) << cpu_duty_offset;
|
2001-07-07 10:27:17 +00:00
|
|
|
p_cnt &= ~clk_val;
|
|
|
|
p_cnt |= (speed << cpu_duty_offset);
|
2003-12-10 19:10:27 +00:00
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Write the new P_CNT value and then enable throttling */
|
2003-11-15 19:26:06 +00:00
|
|
|
CPU_SET_REG(sc->cpu_p_cnt, 4, p_cnt);
|
2001-07-07 10:27:17 +00:00
|
|
|
p_cnt |= CPU_P_CNT_THT_EN;
|
2003-11-15 19:26:06 +00:00
|
|
|
CPU_SET_REG(sc->cpu_p_cnt, 4, p_cnt);
|
2001-07-07 10:27:17 +00:00
|
|
|
}
|
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
|
|
|
}
|
2003-12-18 04:38:45 +00:00
|
|
|
cpu_throttle_state = speed;
|
2001-07-07 10:27:17 +00:00
|
|
|
}
|
|
|
|
|
2003-11-15 19:26:06 +00:00
|
|
|
/*
|
2004-06-05 07:02:18 +00:00
|
|
|
* Idle the CPU in the lowest state possible. This function is called with
|
|
|
|
* interrupts disabled. Note that once it re-enables interrupts, a task
|
|
|
|
* switch can occur so do not access shared data (i.e. the softc) after
|
|
|
|
* interrupts are re-enabled.
|
2003-11-15 19:26:06 +00:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
acpi_cpu_idle()
|
|
|
|
{
|
2003-11-19 20:27:06 +00:00
|
|
|
struct acpi_cpu_softc *sc;
|
|
|
|
struct acpi_cx *cx_next;
|
|
|
|
uint32_t start_time, end_time;
|
2004-06-05 07:02:18 +00:00
|
|
|
int bm_active, cx_next_idx, i;
|
2003-11-15 19:26:06 +00:00
|
|
|
|
|
|
|
/* If disabled, return immediately. */
|
2003-11-19 20:27:06 +00:00
|
|
|
if (cpu_cx_count == 0) {
|
2003-11-15 19:26:06 +00:00
|
|
|
ACPI_ENABLE_IRQS();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-11-27 16:32:46 +00:00
|
|
|
/*
|
|
|
|
* Look up our CPU id to get our softc. If it's NULL, we'll use C1
|
|
|
|
* since there is no ACPI processor object for this CPU. This occurs
|
|
|
|
* for logical CPUs in the HTT case.
|
|
|
|
*/
|
|
|
|
sc = cpu_softc[PCPU_GET(cpuid)];
|
|
|
|
if (sc == NULL) {
|
|
|
|
acpi_cpu_c1();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-06-05 07:02:18 +00:00
|
|
|
/*
|
|
|
|
* If we slept 100 us or more, use the lowest Cx state. Otherwise,
|
|
|
|
* find the lowest state that has a latency less than or equal to
|
|
|
|
* the length of our last sleep.
|
|
|
|
*/
|
|
|
|
cx_next_idx = cpu_cx_lowest;
|
|
|
|
if (sc->cpu_prev_sleep < 100)
|
|
|
|
for (i = cpu_cx_lowest; i >= 0; i--)
|
|
|
|
if (sc->cpu_cx_states[i].trans_lat <= sc->cpu_prev_sleep) {
|
|
|
|
cx_next_idx = i;
|
|
|
|
break;
|
|
|
|
}
|
2003-11-19 20:27:06 +00:00
|
|
|
|
2003-11-15 19:26:06 +00:00
|
|
|
/*
|
|
|
|
* Check for bus master activity. If there was activity, clear
|
|
|
|
* the bit and use the lowest non-C3 state. Note that the USB
|
|
|
|
* driver polling for new devices keeps this bit set all the
|
2004-10-11 06:06:42 +00:00
|
|
|
* time if USB is loaded. If bus mastering control is not available,
|
|
|
|
* flush caches. This can be quite slow but may be useful since not
|
|
|
|
* all systems support BM control.
|
2003-11-15 19:26:06 +00:00
|
|
|
*/
|
2004-10-11 06:06:42 +00:00
|
|
|
if ((cpu_quirks & CPU_QUIRK_NO_BM_CTRL) == 0) {
|
|
|
|
AcpiGetRegister(ACPI_BITREG_BUS_MASTER_STATUS, &bm_active,
|
|
|
|
ACPI_MTX_DO_NOT_LOCK);
|
|
|
|
if (bm_active != 0) {
|
|
|
|
AcpiSetRegister(ACPI_BITREG_BUS_MASTER_STATUS, 1,
|
|
|
|
ACPI_MTX_DO_NOT_LOCK);
|
|
|
|
cx_next_idx = min(cx_next_idx, cpu_non_c3);
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
ACPI_FLUSH_CPU_CACHE();
|
2003-11-15 19:26:06 +00:00
|
|
|
|
2004-06-05 07:02:18 +00:00
|
|
|
/* Select the next state and update statistics. */
|
|
|
|
cx_next = &sc->cpu_cx_states[cx_next_idx];
|
|
|
|
cpu_cx_stats[cx_next_idx]++;
|
|
|
|
KASSERT(cx_next->type != ACPI_STATE_C0, ("acpi_cpu_idle: C0 sleep"));
|
2003-11-15 19:26:06 +00:00
|
|
|
|
2004-06-05 07:02:18 +00:00
|
|
|
/*
|
|
|
|
* Execute HLT (or equivalent) and wait for an interrupt. We can't
|
|
|
|
* calculate the time spent in C1 since the place we wake up is an
|
|
|
|
* ISR. Assume we slept one quantum and return.
|
|
|
|
*/
|
|
|
|
if (cx_next->type == ACPI_STATE_C1) {
|
|
|
|
sc->cpu_prev_sleep = 1000000 / hz;
|
|
|
|
acpi_cpu_c1();
|
|
|
|
return;
|
|
|
|
}
|
2003-11-15 19:26:06 +00:00
|
|
|
|
2004-06-05 07:02:18 +00:00
|
|
|
/* For C3, disable bus master arbitration and enable bus master wake. */
|
|
|
|
if (cx_next->type == ACPI_STATE_C3) {
|
2003-11-15 19:26:06 +00:00
|
|
|
AcpiSetRegister(ACPI_BITREG_ARB_DISABLE, 1, ACPI_MTX_DO_NOT_LOCK);
|
|
|
|
AcpiSetRegister(ACPI_BITREG_BUS_MASTER_RLD, 1, ACPI_MTX_DO_NOT_LOCK);
|
2004-06-05 07:02:18 +00:00
|
|
|
}
|
2003-11-15 19:26:06 +00:00
|
|
|
|
2004-06-05 07:02:18 +00:00
|
|
|
/*
|
|
|
|
* Read from P_LVLx to enter C2(+), checking time spent asleep.
|
|
|
|
* Use the ACPI timer for measuring sleep time. Since we need to
|
|
|
|
* get the time very close to the CPU start/stop clock logic, this
|
|
|
|
* is the only reliable time source.
|
|
|
|
*/
|
|
|
|
AcpiHwLowLevelRead(32, &start_time, &AcpiGbl_FADT->XPmTmrBlk);
|
|
|
|
CPU_GET_REG(cx_next->p_lvlx, 1);
|
2003-11-15 19:26:06 +00:00
|
|
|
|
2004-06-05 07:02:18 +00:00
|
|
|
/*
|
|
|
|
* Read the end time twice. Since it may take an arbitrary time
|
|
|
|
* to enter the idle state, the first read may be executed before
|
|
|
|
* the processor has stopped. Doing it again provides enough
|
|
|
|
* margin that we are certain to have a correct value.
|
|
|
|
*/
|
|
|
|
AcpiHwLowLevelRead(32, &end_time, &AcpiGbl_FADT->XPmTmrBlk);
|
|
|
|
AcpiHwLowLevelRead(32, &end_time, &AcpiGbl_FADT->XPmTmrBlk);
|
2003-11-15 19:26:06 +00:00
|
|
|
|
2004-06-05 07:02:18 +00:00
|
|
|
/* Enable bus master arbitration and disable bus master wakeup. */
|
2004-10-11 06:06:42 +00:00
|
|
|
if (cx_next->type == ACPI_STATE_C3 &&
|
|
|
|
(cpu_quirks & CPU_QUIRK_NO_BM_CTRL) == 0) {
|
2003-11-15 19:26:06 +00:00
|
|
|
AcpiSetRegister(ACPI_BITREG_ARB_DISABLE, 0, ACPI_MTX_DO_NOT_LOCK);
|
|
|
|
AcpiSetRegister(ACPI_BITREG_BUS_MASTER_RLD, 0, ACPI_MTX_DO_NOT_LOCK);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find the actual time asleep in microseconds, minus overhead. */
|
2004-04-21 00:36:15 +00:00
|
|
|
end_time = acpi_TimerDelta(end_time, start_time);
|
2004-06-05 07:02:18 +00:00
|
|
|
sc->cpu_prev_sleep = PM_USEC(end_time) - cx_next->trans_lat;
|
|
|
|
ACPI_ENABLE_IRQS();
|
2003-11-15 19:26:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Re-evaluate the _PSS and _CST objects when we are notified that they
|
|
|
|
* have changed.
|
2003-11-19 20:27:06 +00:00
|
|
|
*
|
2003-11-15 19:26:06 +00:00
|
|
|
* XXX Re-evaluation disabled until locking is done.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
acpi_cpu_notify(ACPI_HANDLE h, UINT32 notify, void *context)
|
|
|
|
{
|
|
|
|
struct acpi_cpu_softc *sc = (struct acpi_cpu_softc *)context;
|
|
|
|
|
|
|
|
switch (notify) {
|
|
|
|
case ACPI_CPU_NOTIFY_PERF_STATES:
|
|
|
|
device_printf(sc->cpu_dev, "Performance states changed\n");
|
|
|
|
/* acpi_cpu_px_available(sc); */
|
|
|
|
break;
|
|
|
|
case ACPI_CPU_NOTIFY_CX_STATES:
|
|
|
|
device_printf(sc->cpu_dev, "Cx states changed\n");
|
|
|
|
/* acpi_cpu_cx_cst(sc); */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
device_printf(sc->cpu_dev, "Unknown notify %#x\n", notify);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
acpi_cpu_quirks(struct acpi_cpu_softc *sc)
|
|
|
|
{
|
|
|
|
|
|
|
|
/*
|
|
|
|
* C3 is not supported on multiple CPUs since this would require
|
|
|
|
* flushing all caches which is currently too expensive.
|
|
|
|
*/
|
2003-12-03 20:27:48 +00:00
|
|
|
if (mp_ncpus > 1)
|
2004-10-11 06:06:42 +00:00
|
|
|
cpu_quirks |= CPU_QUIRK_NO_BM_CTRL;
|
2003-11-15 19:26:06 +00:00
|
|
|
|
|
|
|
#ifdef notyet
|
|
|
|
/* Look for various quirks of the PIIX4 part. */
|
|
|
|
acpi_dev = pci_find_device(PCI_VENDOR_INTEL, PCI_DEVICE_82371AB_3);
|
|
|
|
if (acpi_dev != NULL) {
|
|
|
|
switch (pci_get_revid(acpi_dev)) {
|
|
|
|
/*
|
|
|
|
* Disable throttling control on PIIX4 A and B-step.
|
|
|
|
* See specification changes #13 ("Manual Throttle Duty Cycle")
|
|
|
|
* and #14 ("Enabling and Disabling Manual Throttle"), plus
|
2003-12-10 19:10:27 +00:00
|
|
|
* erratum #5 ("STPCLK# Deassertion Time") from the January
|
2003-11-15 19:26:06 +00:00
|
|
|
* 2002 PIIX4 specification update. Note that few (if any)
|
|
|
|
* mobile systems ever used this part.
|
|
|
|
*/
|
|
|
|
case PCI_REVISION_A_STEP:
|
|
|
|
case PCI_REVISION_B_STEP:
|
|
|
|
cpu_quirks |= CPU_QUIRK_NO_THROTTLE;
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
/*
|
|
|
|
* Disable C3 support for all PIIX4 chipsets. Some of these parts
|
|
|
|
* do not report the BMIDE status to the BM status register and
|
|
|
|
* others have a livelock bug if Type-F DMA is enabled. Linux
|
|
|
|
* works around the BMIDE bug by reading the BM status directly
|
|
|
|
* but we take the simpler approach of disabling C3 for these
|
|
|
|
* parts.
|
|
|
|
*
|
2003-12-10 19:10:27 +00:00
|
|
|
* See erratum #18 ("C3 Power State/BMIDE and Type-F DMA
|
2003-11-15 19:26:06 +00:00
|
|
|
* Livelock") from the January 2002 PIIX4 specification update.
|
|
|
|
* Applies to all PIIX4 models.
|
|
|
|
*/
|
|
|
|
case PCI_REVISION_4E:
|
|
|
|
case PCI_REVISION_4M:
|
|
|
|
cpu_quirks |= CPU_QUIRK_NO_C3;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2003-12-18 04:38:45 +00:00
|
|
|
/* Handle changes in the CPU throttling setting. */
|
2001-07-07 10:27:17 +00:00
|
|
|
static int
|
2003-11-15 19:26:06 +00:00
|
|
|
acpi_cpu_throttle_sysctl(SYSCTL_HANDLER_ARGS)
|
2001-07-07 10:27:17 +00:00
|
|
|
{
|
2003-11-15 19:26:06 +00:00
|
|
|
uint32_t *argp;
|
|
|
|
uint32_t arg;
|
|
|
|
int error;
|
2001-07-07 10:27:17 +00:00
|
|
|
|
2003-11-15 19:26:06 +00:00
|
|
|
argp = (uint32_t *)oidp->oid_arg1;
|
2001-07-07 10:27:17 +00:00
|
|
|
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);
|
2003-12-18 04:38:45 +00:00
|
|
|
if (arg < 1 || arg > cpu_throttle_max)
|
2003-08-28 16:06:30 +00:00
|
|
|
return (EINVAL);
|
2001-07-07 10:27:17 +00:00
|
|
|
|
2003-12-18 04:38:45 +00:00
|
|
|
/* If throttling changed, notify the BIOS of the new rate. */
|
2004-08-13 06:21:47 +00:00
|
|
|
ACPI_SERIAL_BEGIN(cpu);
|
2003-12-18 04:38:45 +00:00
|
|
|
if (*argp != arg) {
|
|
|
|
*argp = arg;
|
|
|
|
acpi_cpu_throttle_set(arg);
|
|
|
|
}
|
2004-08-13 06:21:47 +00:00
|
|
|
ACPI_SERIAL_END(cpu);
|
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
|
|
|
}
|
2003-11-15 19:26:06 +00:00
|
|
|
|
|
|
|
static int
|
2004-06-05 07:02:18 +00:00
|
|
|
acpi_cpu_usage_sysctl(SYSCTL_HANDLER_ARGS)
|
2003-11-15 19:26:06 +00:00
|
|
|
{
|
|
|
|
struct sbuf sb;
|
|
|
|
char buf[128];
|
|
|
|
int i;
|
2004-06-24 00:38:51 +00:00
|
|
|
uintmax_t fract, sum, whole;
|
2003-11-15 19:26:06 +00:00
|
|
|
|
2004-06-19 02:27:23 +00:00
|
|
|
sum = 0;
|
2004-06-05 07:02:18 +00:00
|
|
|
for (i = 0; i < cpu_cx_count; i++)
|
|
|
|
sum += cpu_cx_stats[i];
|
2003-11-15 19:26:06 +00:00
|
|
|
sbuf_new(&sb, buf, sizeof(buf), SBUF_FIXEDLEN);
|
2004-06-19 02:27:23 +00:00
|
|
|
for (i = 0; i < cpu_cx_count; i++) {
|
|
|
|
if (sum > 0) {
|
2004-06-24 00:38:51 +00:00
|
|
|
whole = (uintmax_t)cpu_cx_stats[i] * 100;
|
2004-06-19 02:27:23 +00:00
|
|
|
fract = (whole % sum) * 100;
|
|
|
|
sbuf_printf(&sb, "%u.%02u%% ", (u_int)(whole / sum),
|
|
|
|
(u_int)(fract / sum));
|
|
|
|
} else
|
|
|
|
sbuf_printf(&sb, "0%% ");
|
|
|
|
}
|
2003-11-15 19:26:06 +00:00
|
|
|
sbuf_trim(&sb);
|
|
|
|
sbuf_finish(&sb);
|
2004-05-07 05:22:38 +00:00
|
|
|
sysctl_handle_string(oidp, sbuf_data(&sb), sbuf_len(&sb), req);
|
|
|
|
sbuf_delete(&sb);
|
2003-11-15 19:26:06 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
acpi_cpu_cx_lowest_sysctl(SYSCTL_HANDLER_ARGS)
|
|
|
|
{
|
|
|
|
struct acpi_cpu_softc *sc;
|
2004-05-07 05:22:38 +00:00
|
|
|
char state[8];
|
2003-11-15 19:26:06 +00:00
|
|
|
int val, error, i;
|
|
|
|
|
|
|
|
sc = device_get_softc(cpu_devices[0]);
|
2004-05-07 05:22:38 +00:00
|
|
|
snprintf(state, sizeof(state), "C%d", cpu_cx_lowest + 1);
|
|
|
|
error = sysctl_handle_string(oidp, state, sizeof(state), req);
|
2003-11-15 19:26:06 +00:00
|
|
|
if (error != 0 || req->newptr == NULL)
|
|
|
|
return (error);
|
2004-05-07 05:22:38 +00:00
|
|
|
if (strlen(state) < 2 || toupper(state[0]) != 'C')
|
|
|
|
return (EINVAL);
|
|
|
|
val = (int) strtol(state + 1, NULL, 10) - 1;
|
2003-11-19 20:27:06 +00:00
|
|
|
if (val < 0 || val > cpu_cx_count - 1)
|
2003-11-15 19:26:06 +00:00
|
|
|
return (EINVAL);
|
|
|
|
|
2004-08-13 06:21:47 +00:00
|
|
|
ACPI_SERIAL_BEGIN(cpu);
|
2003-11-15 19:26:06 +00:00
|
|
|
cpu_cx_lowest = val;
|
|
|
|
|
|
|
|
/* If not disabling, cache the new lowest non-C3 state. */
|
|
|
|
cpu_non_c3 = 0;
|
|
|
|
for (i = cpu_cx_lowest; i >= 0; i--) {
|
|
|
|
if (sc->cpu_cx_states[i].type < ACPI_STATE_C3) {
|
|
|
|
cpu_non_c3 = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reset the statistics counters. */
|
2004-06-05 07:02:18 +00:00
|
|
|
bzero(cpu_cx_stats, sizeof(cpu_cx_stats));
|
2004-08-13 06:21:47 +00:00
|
|
|
ACPI_SERIAL_END(cpu);
|
2003-11-15 19:26:06 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|