2005-02-04 05:45:07 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2003-2005 Nate Lawson (SDG)
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
|
|
|
#include "opt_acpi.h"
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/sched.h>
|
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <sys/cpu.h>
|
|
|
|
#include <sys/power.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/module.h>
|
|
|
|
#include <sys/sbuf.h>
|
|
|
|
#include <sys/pcpu.h>
|
|
|
|
|
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <machine/resource.h>
|
|
|
|
#include <sys/rman.h>
|
|
|
|
|
2005-09-11 18:39:03 +00:00
|
|
|
#include <contrib/dev/acpica/acpi.h>
|
2005-02-04 05:45:07 +00:00
|
|
|
#include <dev/acpica/acpivar.h>
|
|
|
|
|
|
|
|
#include "cpufreq_if.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Support for ACPI processor performance states (Px) according to
|
2005-02-13 18:49:48 +00:00
|
|
|
* section 8.3.3 of the ACPI 2.0c specification.
|
2005-02-04 05:45:07 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
struct acpi_px {
|
|
|
|
uint32_t core_freq;
|
|
|
|
uint32_t power;
|
|
|
|
uint32_t trans_lat;
|
|
|
|
uint32_t bm_lat;
|
|
|
|
uint32_t ctrl_val;
|
|
|
|
uint32_t sts_val;
|
|
|
|
};
|
|
|
|
|
2005-02-19 06:13:26 +00:00
|
|
|
/* Offsets in struct cf_setting array for storing driver-specific values. */
|
|
|
|
#define PX_SPEC_CONTROL 0
|
|
|
|
#define PX_SPEC_STATUS 1
|
|
|
|
|
|
|
|
#define MAX_PX_STATES 16
|
2005-02-04 05:45:07 +00:00
|
|
|
|
|
|
|
struct acpi_perf_softc {
|
|
|
|
device_t dev;
|
|
|
|
ACPI_HANDLE handle;
|
|
|
|
struct resource *perf_ctrl; /* Set new performance state. */
|
2005-02-05 22:30:57 +00:00
|
|
|
int perf_ctrl_type; /* Resource type for perf_ctrl. */
|
2005-02-04 05:45:07 +00:00
|
|
|
struct resource *perf_status; /* Check that transition succeeded. */
|
2005-02-05 22:30:57 +00:00
|
|
|
int perf_sts_type; /* Resource type for perf_status. */
|
2005-02-04 05:45:07 +00:00
|
|
|
struct acpi_px *px_states; /* ACPI perf states. */
|
|
|
|
uint32_t px_count; /* Total number of perf states. */
|
|
|
|
uint32_t px_max_avail; /* Lowest index state available. */
|
|
|
|
int px_curr_state; /* Active state index. */
|
|
|
|
int px_rid;
|
2005-02-13 18:49:48 +00:00
|
|
|
int info_only; /* Can we set new states? */
|
2005-02-04 05:45:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define PX_GET_REG(reg) \
|
|
|
|
(bus_space_read_4(rman_get_bustag((reg)), \
|
|
|
|
rman_get_bushandle((reg)), 0))
|
|
|
|
#define PX_SET_REG(reg, val) \
|
|
|
|
(bus_space_write_4(rman_get_bustag((reg)), \
|
|
|
|
rman_get_bushandle((reg)), 0, (val)))
|
|
|
|
|
2005-02-07 04:03:06 +00:00
|
|
|
#define ACPI_NOTIFY_PERF_STATES 0x80 /* _PSS changed. */
|
|
|
|
|
2005-02-04 05:45:07 +00:00
|
|
|
static void acpi_perf_identify(driver_t *driver, device_t parent);
|
|
|
|
static int acpi_perf_probe(device_t dev);
|
|
|
|
static int acpi_perf_attach(device_t dev);
|
|
|
|
static int acpi_perf_detach(device_t dev);
|
|
|
|
static int acpi_perf_evaluate(device_t dev);
|
|
|
|
static int acpi_px_to_set(device_t dev, struct acpi_px *px,
|
|
|
|
struct cf_setting *set);
|
|
|
|
static void acpi_px_available(struct acpi_perf_softc *sc);
|
2005-02-06 20:12:28 +00:00
|
|
|
static void acpi_px_startup(void *arg);
|
2005-02-04 05:45:07 +00:00
|
|
|
static void acpi_px_notify(ACPI_HANDLE h, UINT32 notify, void *context);
|
|
|
|
static int acpi_px_settings(device_t dev, struct cf_setting *sets,
|
2005-02-18 00:23:36 +00:00
|
|
|
int *count);
|
2005-02-04 05:45:07 +00:00
|
|
|
static int acpi_px_set(device_t dev, const struct cf_setting *set);
|
|
|
|
static int acpi_px_get(device_t dev, struct cf_setting *set);
|
2005-02-18 00:23:36 +00:00
|
|
|
static int acpi_px_type(device_t dev, int *type);
|
2005-02-04 05:45:07 +00:00
|
|
|
|
|
|
|
static device_method_t acpi_perf_methods[] = {
|
|
|
|
/* Device interface */
|
|
|
|
DEVMETHOD(device_identify, acpi_perf_identify),
|
|
|
|
DEVMETHOD(device_probe, acpi_perf_probe),
|
|
|
|
DEVMETHOD(device_attach, acpi_perf_attach),
|
|
|
|
DEVMETHOD(device_detach, acpi_perf_detach),
|
|
|
|
|
|
|
|
/* cpufreq interface */
|
|
|
|
DEVMETHOD(cpufreq_drv_set, acpi_px_set),
|
|
|
|
DEVMETHOD(cpufreq_drv_get, acpi_px_get),
|
2005-02-18 00:23:36 +00:00
|
|
|
DEVMETHOD(cpufreq_drv_type, acpi_px_type),
|
2005-02-04 05:45:07 +00:00
|
|
|
DEVMETHOD(cpufreq_drv_settings, acpi_px_settings),
|
|
|
|
{0, 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t acpi_perf_driver = {
|
|
|
|
"acpi_perf",
|
|
|
|
acpi_perf_methods,
|
|
|
|
sizeof(struct acpi_perf_softc),
|
|
|
|
};
|
|
|
|
|
|
|
|
static devclass_t acpi_perf_devclass;
|
|
|
|
DRIVER_MODULE(acpi_perf, cpu, acpi_perf_driver, acpi_perf_devclass, 0, 0);
|
|
|
|
MODULE_DEPEND(acpi_perf, acpi, 1, 1, 1);
|
|
|
|
|
|
|
|
MALLOC_DEFINE(M_ACPIPERF, "acpi_perf", "ACPI Performance states");
|
|
|
|
|
|
|
|
static void
|
|
|
|
acpi_perf_identify(driver_t *driver, device_t parent)
|
|
|
|
{
|
|
|
|
ACPI_HANDLE handle;
|
2005-03-20 03:51:18 +00:00
|
|
|
device_t dev;
|
2005-02-04 05:45:07 +00:00
|
|
|
|
|
|
|
/* Make sure we're not being doubly invoked. */
|
2005-02-13 05:25:27 +00:00
|
|
|
if (device_find_child(parent, "acpi_perf", -1) != NULL)
|
2005-02-04 05:45:07 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* Get the handle for the Processor object and check for perf states. */
|
|
|
|
handle = acpi_get_handle(parent);
|
|
|
|
if (handle == NULL)
|
|
|
|
return;
|
|
|
|
if (ACPI_FAILURE(AcpiEvaluateObject(handle, "_PSS", NULL, NULL)))
|
|
|
|
return;
|
2005-02-27 02:43:02 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Add a child to every CPU that has the right methods. In future
|
|
|
|
* versions of the ACPI spec, CPUs can have different settings.
|
2005-03-20 03:51:18 +00:00
|
|
|
* We probe this child now so that other devices that depend
|
|
|
|
* on it (i.e., for info about supported states) will see it.
|
2005-02-27 02:43:02 +00:00
|
|
|
*/
|
2005-03-20 03:51:18 +00:00
|
|
|
if ((dev = BUS_ADD_CHILD(parent, 0, "acpi_perf", -1)) != NULL)
|
|
|
|
device_probe_and_attach(dev);
|
|
|
|
else
|
2005-02-07 04:03:06 +00:00
|
|
|
device_printf(parent, "add acpi_perf child failed\n");
|
2005-02-04 05:45:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
acpi_perf_probe(device_t dev)
|
|
|
|
{
|
2005-02-05 22:30:57 +00:00
|
|
|
ACPI_HANDLE handle;
|
|
|
|
ACPI_OBJECT *pkg;
|
|
|
|
struct resource *res;
|
|
|
|
ACPI_BUFFER buf;
|
|
|
|
int error, rid, type;
|
2005-02-04 05:45:07 +00:00
|
|
|
|
2005-02-22 06:31:45 +00:00
|
|
|
if (resource_disabled("acpi_perf", 0))
|
|
|
|
return (ENXIO);
|
|
|
|
|
2005-02-05 22:30:57 +00:00
|
|
|
/*
|
|
|
|
* Check the performance state registers. If they are of type
|
2005-02-13 18:49:48 +00:00
|
|
|
* "functional fixed hardware", we attach quietly since we will
|
|
|
|
* only be providing information on settings to other drivers.
|
2005-02-05 22:30:57 +00:00
|
|
|
*/
|
|
|
|
error = ENXIO;
|
|
|
|
handle = acpi_get_handle(dev);
|
|
|
|
buf.Pointer = NULL;
|
|
|
|
buf.Length = ACPI_ALLOCATE_BUFFER;
|
|
|
|
if (ACPI_FAILURE(AcpiEvaluateObject(handle, "_PCT", NULL, &buf)))
|
|
|
|
return (error);
|
|
|
|
pkg = (ACPI_OBJECT *)buf.Pointer;
|
2005-02-13 18:49:48 +00:00
|
|
|
if (ACPI_PKG_VALID(pkg, 2)) {
|
|
|
|
rid = 0;
|
2007-01-07 21:53:42 +00:00
|
|
|
error = acpi_PkgGas(dev, pkg, 0, &type, &rid, &res, 0);
|
2005-02-13 18:49:48 +00:00
|
|
|
switch (error) {
|
|
|
|
case 0:
|
|
|
|
bus_release_resource(dev, type, rid, res);
|
2005-03-27 22:38:28 +00:00
|
|
|
bus_delete_resource(dev, type, rid);
|
2005-02-13 18:49:48 +00:00
|
|
|
device_set_desc(dev, "ACPI CPU Frequency Control");
|
|
|
|
break;
|
|
|
|
case EOPNOTSUPP:
|
|
|
|
device_quiet(dev);
|
|
|
|
error = 0;
|
|
|
|
break;
|
|
|
|
}
|
2005-02-05 22:30:57 +00:00
|
|
|
}
|
|
|
|
AcpiOsFree(buf.Pointer);
|
|
|
|
|
|
|
|
return (error);
|
2005-02-04 05:45:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
acpi_perf_attach(device_t dev)
|
|
|
|
{
|
|
|
|
struct acpi_perf_softc *sc;
|
|
|
|
|
|
|
|
sc = device_get_softc(dev);
|
|
|
|
sc->dev = dev;
|
|
|
|
sc->handle = acpi_get_handle(dev);
|
|
|
|
sc->px_max_avail = 0;
|
|
|
|
sc->px_curr_state = CPUFREQ_VAL_UNKNOWN;
|
|
|
|
if (acpi_perf_evaluate(dev) != 0)
|
|
|
|
return (ENXIO);
|
2007-03-22 18:16:43 +00:00
|
|
|
AcpiOsExecute(OSL_NOTIFY_HANDLER, acpi_px_startup, NULL);
|
2005-02-26 22:09:05 +00:00
|
|
|
if (!sc->info_only)
|
|
|
|
cpufreq_register(dev);
|
2005-02-04 05:45:07 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
acpi_perf_detach(device_t dev)
|
|
|
|
{
|
|
|
|
/* TODO: teardown registers, remove notify handler. */
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Probe and setup any valid performance states (Px). */
|
|
|
|
static int
|
|
|
|
acpi_perf_evaluate(device_t dev)
|
|
|
|
{
|
|
|
|
struct acpi_perf_softc *sc;
|
|
|
|
ACPI_BUFFER buf;
|
|
|
|
ACPI_OBJECT *pkg, *res;
|
|
|
|
ACPI_STATUS status;
|
2005-03-26 17:30:34 +00:00
|
|
|
int count, error, i, j;
|
2005-12-12 11:15:20 +00:00
|
|
|
static int once = 1;
|
2005-02-04 05:45:07 +00:00
|
|
|
uint32_t *p;
|
|
|
|
|
|
|
|
/* Get the control values and parameters for each state. */
|
2005-02-04 18:09:01 +00:00
|
|
|
error = ENXIO;
|
2005-02-04 05:45:07 +00:00
|
|
|
sc = device_get_softc(dev);
|
|
|
|
buf.Pointer = NULL;
|
|
|
|
buf.Length = ACPI_ALLOCATE_BUFFER;
|
|
|
|
status = AcpiEvaluateObject(sc->handle, "_PSS", NULL, &buf);
|
|
|
|
if (ACPI_FAILURE(status))
|
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
pkg = (ACPI_OBJECT *)buf.Pointer;
|
|
|
|
if (!ACPI_PKG_VALID(pkg, 1)) {
|
|
|
|
device_printf(dev, "invalid top level _PSS package\n");
|
2005-02-04 18:09:01 +00:00
|
|
|
goto out;
|
2005-02-04 05:45:07 +00:00
|
|
|
}
|
|
|
|
sc->px_count = pkg->Package.Count;
|
|
|
|
|
|
|
|
sc->px_states = malloc(sc->px_count * sizeof(struct acpi_px),
|
|
|
|
M_ACPIPERF, M_WAITOK | M_ZERO);
|
|
|
|
if (sc->px_states == NULL)
|
2005-02-04 18:09:01 +00:00
|
|
|
goto out;
|
2005-02-04 05:45:07 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Each state is a package of {CoreFreq, Power, TransitionLatency,
|
|
|
|
* BusMasterLatency, ControlVal, StatusVal}, sorted from highest
|
|
|
|
* performance to lowest.
|
|
|
|
*/
|
2005-03-26 17:30:34 +00:00
|
|
|
count = 0;
|
2005-02-04 05:45:07 +00:00
|
|
|
for (i = 0; i < sc->px_count; i++) {
|
|
|
|
res = &pkg->Package.Elements[i];
|
|
|
|
if (!ACPI_PKG_VALID(res, 6)) {
|
2005-12-12 11:15:20 +00:00
|
|
|
if (once) {
|
|
|
|
once = 0;
|
|
|
|
device_printf(dev, "invalid _PSS package\n");
|
|
|
|
}
|
2005-02-04 05:45:07 +00:00
|
|
|
continue;
|
|
|
|
}
|
2005-03-04 05:29:56 +00:00
|
|
|
|
2005-03-26 17:30:34 +00:00
|
|
|
/* Parse the rest of the package into the struct. */
|
|
|
|
p = &sc->px_states[count].core_freq;
|
|
|
|
for (j = 0; j < 6; j++, p++)
|
|
|
|
acpi_PkgInt32(res, j, p);
|
|
|
|
|
2005-03-04 05:29:56 +00:00
|
|
|
/*
|
|
|
|
* Check for some impossible frequencies that some systems
|
2005-03-26 17:30:34 +00:00
|
|
|
* use to indicate they don't actually support this Px state.
|
2005-03-04 05:29:56 +00:00
|
|
|
*/
|
2005-03-26 17:30:34 +00:00
|
|
|
if (sc->px_states[count].core_freq == 0 ||
|
|
|
|
sc->px_states[count].core_freq == 9999 ||
|
|
|
|
sc->px_states[count].core_freq == 0x9999 ||
|
|
|
|
sc->px_states[count].core_freq >= 0xffff)
|
|
|
|
continue;
|
2005-03-04 05:29:56 +00:00
|
|
|
|
2006-07-15 17:34:03 +00:00
|
|
|
/* Check for duplicate entries */
|
|
|
|
if (count > 0 &&
|
|
|
|
sc->px_states[count - 1].core_freq ==
|
|
|
|
sc->px_states[count].core_freq)
|
|
|
|
continue;
|
|
|
|
|
2005-03-26 17:30:34 +00:00
|
|
|
count++;
|
2005-02-04 05:45:07 +00:00
|
|
|
}
|
2005-04-07 17:33:22 +00:00
|
|
|
sc->px_count = count;
|
2005-03-26 17:30:34 +00:00
|
|
|
|
2005-04-07 17:33:22 +00:00
|
|
|
/* No valid Px state found so give up. */
|
2005-03-26 17:30:34 +00:00
|
|
|
if (count == 0)
|
|
|
|
goto out;
|
2005-04-05 19:39:44 +00:00
|
|
|
AcpiOsFree(buf.Pointer);
|
2005-02-04 05:45:07 +00:00
|
|
|
|
|
|
|
/* Get the control and status registers (one of each). */
|
|
|
|
buf.Pointer = NULL;
|
|
|
|
buf.Length = ACPI_ALLOCATE_BUFFER;
|
|
|
|
status = AcpiEvaluateObject(sc->handle, "_PCT", NULL, &buf);
|
2005-02-04 18:09:01 +00:00
|
|
|
if (ACPI_FAILURE(status))
|
|
|
|
goto out;
|
2005-02-04 05:45:07 +00:00
|
|
|
|
|
|
|
/* Check the package of two registers, each a Buffer in GAS format. */
|
|
|
|
pkg = (ACPI_OBJECT *)buf.Pointer;
|
|
|
|
if (!ACPI_PKG_VALID(pkg, 2)) {
|
|
|
|
device_printf(dev, "invalid perf register package\n");
|
2005-02-04 18:09:01 +00:00
|
|
|
goto out;
|
2005-02-04 05:45:07 +00:00
|
|
|
}
|
|
|
|
|
2005-02-05 22:30:57 +00:00
|
|
|
error = acpi_PkgGas(sc->dev, pkg, 0, &sc->perf_ctrl_type, &sc->px_rid,
|
2007-01-07 21:53:42 +00:00
|
|
|
&sc->perf_ctrl, 0);
|
2005-02-05 22:30:57 +00:00
|
|
|
if (error) {
|
2005-02-13 18:49:48 +00:00
|
|
|
/*
|
|
|
|
* If the register is of type FFixedHW, we can only return
|
|
|
|
* info, we can't get or set new settings.
|
|
|
|
*/
|
|
|
|
if (error == EOPNOTSUPP) {
|
|
|
|
sc->info_only = TRUE;
|
|
|
|
error = 0;
|
|
|
|
} else
|
2005-02-04 18:09:01 +00:00
|
|
|
device_printf(dev, "failed in PERF_CTL attach\n");
|
|
|
|
goto out;
|
2005-02-04 05:45:07 +00:00
|
|
|
}
|
|
|
|
sc->px_rid++;
|
|
|
|
|
2005-02-05 22:30:57 +00:00
|
|
|
error = acpi_PkgGas(sc->dev, pkg, 1, &sc->perf_sts_type, &sc->px_rid,
|
2007-01-07 21:53:42 +00:00
|
|
|
&sc->perf_status, 0);
|
2005-02-05 22:30:57 +00:00
|
|
|
if (error) {
|
2005-02-13 18:49:48 +00:00
|
|
|
if (error == EOPNOTSUPP) {
|
|
|
|
sc->info_only = TRUE;
|
|
|
|
error = 0;
|
|
|
|
} else
|
2005-02-04 18:09:01 +00:00
|
|
|
device_printf(dev, "failed in PERF_STATUS attach\n");
|
|
|
|
goto out;
|
2005-02-04 05:45:07 +00:00
|
|
|
}
|
|
|
|
sc->px_rid++;
|
|
|
|
|
|
|
|
/* Get our current limit and register for notifies. */
|
|
|
|
acpi_px_available(sc);
|
|
|
|
AcpiInstallNotifyHandler(sc->handle, ACPI_DEVICE_NOTIFY,
|
|
|
|
acpi_px_notify, sc);
|
2005-02-04 18:09:01 +00:00
|
|
|
error = 0;
|
2005-02-04 05:45:07 +00:00
|
|
|
|
2005-02-04 18:09:01 +00:00
|
|
|
out:
|
|
|
|
if (error) {
|
2005-03-27 22:38:28 +00:00
|
|
|
if (sc->px_states) {
|
2005-02-04 18:09:01 +00:00
|
|
|
free(sc->px_states, M_ACPIPERF);
|
2005-03-27 22:38:28 +00:00
|
|
|
sc->px_states = NULL;
|
|
|
|
}
|
|
|
|
if (sc->perf_ctrl) {
|
|
|
|
bus_release_resource(sc->dev, sc->perf_ctrl_type, 0,
|
|
|
|
sc->perf_ctrl);
|
|
|
|
bus_delete_resource(sc->dev, sc->perf_ctrl_type, 0);
|
|
|
|
sc->perf_ctrl = NULL;
|
|
|
|
}
|
|
|
|
if (sc->perf_status) {
|
|
|
|
bus_release_resource(sc->dev, sc->perf_sts_type, 1,
|
|
|
|
sc->perf_status);
|
|
|
|
bus_delete_resource(sc->dev, sc->perf_sts_type, 1);
|
|
|
|
sc->perf_status = NULL;
|
|
|
|
}
|
|
|
|
sc->px_rid = 0;
|
2005-02-04 18:09:01 +00:00
|
|
|
sc->px_count = 0;
|
|
|
|
}
|
|
|
|
if (buf.Pointer)
|
|
|
|
AcpiOsFree(buf.Pointer);
|
|
|
|
return (error);
|
2005-02-04 05:45:07 +00:00
|
|
|
}
|
|
|
|
|
2005-02-06 20:12:28 +00:00
|
|
|
static void
|
|
|
|
acpi_px_startup(void *arg)
|
|
|
|
{
|
|
|
|
|
|
|
|
/* Signal to the platform that we are taking over CPU control. */
|
2007-03-22 18:16:43 +00:00
|
|
|
if (AcpiGbl_FADT.PstateControl == 0)
|
2005-02-06 20:12:28 +00:00
|
|
|
return;
|
|
|
|
ACPI_LOCK(acpi);
|
2007-03-22 18:16:43 +00:00
|
|
|
AcpiOsWritePort(AcpiGbl_FADT.SmiCommand, AcpiGbl_FADT.PstateControl, 8);
|
2005-02-06 20:12:28 +00:00
|
|
|
ACPI_UNLOCK(acpi);
|
|
|
|
}
|
|
|
|
|
2005-02-04 05:45:07 +00:00
|
|
|
static void
|
|
|
|
acpi_px_notify(ACPI_HANDLE h, UINT32 notify, void *context)
|
|
|
|
{
|
|
|
|
struct acpi_perf_softc *sc;
|
|
|
|
|
|
|
|
sc = context;
|
2005-02-07 04:03:06 +00:00
|
|
|
if (notify != ACPI_NOTIFY_PERF_STATES)
|
|
|
|
return;
|
|
|
|
|
2005-02-04 05:45:07 +00:00
|
|
|
acpi_px_available(sc);
|
|
|
|
|
|
|
|
/* TODO: Implement notification when frequency changes. */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find the highest currently-supported performance state.
|
|
|
|
* This can be called at runtime (e.g., due to a docking event) at
|
|
|
|
* the request of a Notify on the processor object.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
acpi_px_available(struct acpi_perf_softc *sc)
|
|
|
|
{
|
|
|
|
ACPI_STATUS status;
|
|
|
|
struct cf_setting set;
|
|
|
|
|
|
|
|
status = acpi_GetInteger(sc->handle, "_PPC", &sc->px_max_avail);
|
|
|
|
|
|
|
|
/* If the old state is too high, set current state to the new max. */
|
|
|
|
if (ACPI_SUCCESS(status)) {
|
|
|
|
if (sc->px_curr_state != CPUFREQ_VAL_UNKNOWN &&
|
|
|
|
sc->px_curr_state > sc->px_max_avail) {
|
|
|
|
acpi_px_to_set(sc->dev,
|
|
|
|
&sc->px_states[sc->px_max_avail], &set);
|
|
|
|
acpi_px_set(sc->dev, &set);
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
sc->px_max_avail = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
acpi_px_to_set(device_t dev, struct acpi_px *px, struct cf_setting *set)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (px == NULL || set == NULL)
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
set->freq = px->core_freq;
|
|
|
|
set->power = px->power;
|
|
|
|
/* XXX Include BM latency too? */
|
|
|
|
set->lat = px->trans_lat;
|
|
|
|
set->volts = CPUFREQ_VAL_UNKNOWN;
|
|
|
|
set->dev = dev;
|
2005-02-19 06:13:26 +00:00
|
|
|
set->spec[PX_SPEC_CONTROL] = px->ctrl_val;
|
|
|
|
set->spec[PX_SPEC_STATUS] = px->sts_val;
|
2005-02-04 05:45:07 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2005-02-18 00:23:36 +00:00
|
|
|
acpi_px_settings(device_t dev, struct cf_setting *sets, int *count)
|
2005-02-04 05:45:07 +00:00
|
|
|
{
|
|
|
|
struct acpi_perf_softc *sc;
|
|
|
|
int x, y;
|
|
|
|
|
|
|
|
sc = device_get_softc(dev);
|
|
|
|
if (sets == NULL || count == NULL)
|
|
|
|
return (EINVAL);
|
|
|
|
if (*count < sc->px_count - sc->px_max_avail)
|
2005-02-17 01:02:58 +00:00
|
|
|
return (E2BIG);
|
2005-02-04 05:45:07 +00:00
|
|
|
|
|
|
|
/* Return a list of settings that are currently valid. */
|
|
|
|
y = 0;
|
|
|
|
for (x = sc->px_max_avail; x < sc->px_count; x++, y++)
|
|
|
|
acpi_px_to_set(dev, &sc->px_states[x], &sets[y]);
|
|
|
|
*count = sc->px_count - sc->px_max_avail;
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
acpi_px_set(device_t dev, const struct cf_setting *set)
|
|
|
|
{
|
|
|
|
struct acpi_perf_softc *sc;
|
|
|
|
int i, status, sts_val, tries;
|
|
|
|
|
|
|
|
if (set == NULL)
|
|
|
|
return (EINVAL);
|
|
|
|
sc = device_get_softc(dev);
|
|
|
|
|
2005-02-13 18:49:48 +00:00
|
|
|
/* If we can't set new states, return immediately. */
|
|
|
|
if (sc->info_only)
|
|
|
|
return (ENXIO);
|
|
|
|
|
2005-02-04 05:45:07 +00:00
|
|
|
/* Look up appropriate state, based on frequency. */
|
|
|
|
for (i = sc->px_max_avail; i < sc->px_count; i++) {
|
|
|
|
if (CPUFREQ_CMP(set->freq, sc->px_states[i].core_freq))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i == sc->px_count)
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
/* Write the appropriate value to the register. */
|
|
|
|
PX_SET_REG(sc->perf_ctrl, sc->px_states[i].ctrl_val);
|
|
|
|
|
2005-02-22 06:34:53 +00:00
|
|
|
/*
|
|
|
|
* Try for up to 10 ms to verify the desired state was selected.
|
|
|
|
* This is longer than the standard says (1 ms) but in some modes,
|
|
|
|
* systems may take longer to respond.
|
|
|
|
*/
|
2005-02-04 05:45:07 +00:00
|
|
|
sts_val = sc->px_states[i].sts_val;
|
2005-02-22 06:34:53 +00:00
|
|
|
for (tries = 0; tries < 1000; tries++) {
|
2005-02-04 05:45:07 +00:00
|
|
|
status = PX_GET_REG(sc->perf_status);
|
2005-02-22 06:34:53 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If we match the status or the desired status is 8 bits
|
|
|
|
* and matches the relevant bits, assume we succeeded. It
|
|
|
|
* appears some systems (IBM R32) expect byte-wide access
|
|
|
|
* even though the standard says the register is 32-bit.
|
|
|
|
*/
|
|
|
|
if (status == sts_val ||
|
|
|
|
((sts_val & ~0xff) == 0 && (status & 0xff) == sts_val))
|
2005-02-04 05:45:07 +00:00
|
|
|
break;
|
|
|
|
DELAY(10);
|
|
|
|
}
|
2005-02-22 06:34:53 +00:00
|
|
|
if (tries == 1000) {
|
2005-02-04 05:45:07 +00:00
|
|
|
device_printf(dev, "Px transition to %d failed\n",
|
|
|
|
sc->px_states[i].core_freq);
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
sc->px_curr_state = i;
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
acpi_px_get(device_t dev, struct cf_setting *set)
|
|
|
|
{
|
|
|
|
struct acpi_perf_softc *sc;
|
|
|
|
uint64_t rate;
|
|
|
|
int i;
|
|
|
|
struct pcpu *pc;
|
|
|
|
|
|
|
|
if (set == NULL)
|
|
|
|
return (EINVAL);
|
|
|
|
sc = device_get_softc(dev);
|
|
|
|
|
2005-02-13 18:49:48 +00:00
|
|
|
/* If we can't get new states, return immediately. */
|
|
|
|
if (sc->info_only)
|
|
|
|
return (ENXIO);
|
|
|
|
|
2005-02-04 05:45:07 +00:00
|
|
|
/* If we've set the rate before, use the cached value. */
|
|
|
|
if (sc->px_curr_state != CPUFREQ_VAL_UNKNOWN) {
|
|
|
|
acpi_px_to_set(dev, &sc->px_states[sc->px_curr_state], set);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Otherwise, estimate and try to match against our settings. */
|
|
|
|
pc = cpu_get_pcpu(dev);
|
|
|
|
if (pc == NULL)
|
|
|
|
return (ENXIO);
|
|
|
|
cpu_est_clockrate(pc->pc_cpuid, &rate);
|
|
|
|
rate /= 1000000;
|
|
|
|
for (i = 0; i < sc->px_count; i++) {
|
|
|
|
if (CPUFREQ_CMP(sc->px_states[i].core_freq, rate)) {
|
|
|
|
sc->px_curr_state = i;
|
|
|
|
acpi_px_to_set(dev, &sc->px_states[i], set);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* No match, give up. */
|
|
|
|
if (i == sc->px_count) {
|
|
|
|
sc->px_curr_state = CPUFREQ_VAL_UNKNOWN;
|
|
|
|
set->freq = CPUFREQ_VAL_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
2005-02-18 00:23:36 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
acpi_px_type(device_t dev, int *type)
|
|
|
|
{
|
|
|
|
struct acpi_perf_softc *sc;
|
|
|
|
|
|
|
|
if (type == NULL)
|
|
|
|
return (EINVAL);
|
|
|
|
sc = device_get_softc(dev);
|
|
|
|
|
|
|
|
*type = CPUFREQ_TYPE_ABSOLUTE;
|
|
|
|
if (sc->info_only)
|
|
|
|
*type |= CPUFREQ_FLAG_INFO_ONLY;
|
|
|
|
return (0);
|
|
|
|
}
|