2010-08-14 09:41:22 +04:00
|
|
|
/* $NetBSD: acpi_cpu_pstate.c,v 1.18 2010/08/14 05:41:22 jruoho Exp $ */
|
2010-08-08 20:58:41 +04:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 2010 Jukka Ruohonen <jruohonen@iki.fi>
|
|
|
|
* 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>
|
2010-08-14 09:41:22 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: acpi_cpu_pstate.c,v 1.18 2010/08/14 05:41:22 jruoho Exp $");
|
2010-08-08 20:58:41 +04:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
2010-08-10 06:42:05 +04:00
|
|
|
#include <sys/evcnt.h>
|
2010-08-08 20:58:41 +04:00
|
|
|
#include <sys/kmem.h>
|
|
|
|
#include <sys/once.h>
|
|
|
|
|
|
|
|
#include <dev/acpi/acpireg.h>
|
|
|
|
#include <dev/acpi/acpivar.h>
|
|
|
|
#include <dev/acpi/acpi_cpu.h>
|
|
|
|
|
|
|
|
#define _COMPONENT ACPI_BUS_COMPONENT
|
|
|
|
ACPI_MODULE_NAME ("acpi_cpu_pstate")
|
|
|
|
|
|
|
|
static void acpicpu_pstate_attach_print(struct acpicpu_softc *);
|
2010-08-10 06:42:05 +04:00
|
|
|
static void acpicpu_pstate_attach_evcnt(struct acpicpu_softc *);
|
|
|
|
static void acpicpu_pstate_detach_evcnt(struct acpicpu_softc *);
|
2010-08-08 20:58:41 +04:00
|
|
|
static ACPI_STATUS acpicpu_pstate_pss(struct acpicpu_softc *sc);
|
|
|
|
static ACPI_STATUS acpicpu_pstate_pss_add(struct acpicpu_pstate *,
|
|
|
|
ACPI_OBJECT *);
|
|
|
|
static ACPI_STATUS acpicpu_pstate_pct(struct acpicpu_softc *);
|
|
|
|
static int acpicpu_pstate_max(struct acpicpu_softc *);
|
|
|
|
static void acpicpu_pstate_change(struct acpicpu_softc *);
|
|
|
|
static void acpicpu_pstate_bios(void);
|
|
|
|
|
|
|
|
void
|
|
|
|
acpicpu_pstate_attach(device_t self)
|
|
|
|
{
|
|
|
|
struct acpicpu_softc *sc = device_private(self);
|
2010-08-08 22:10:34 +04:00
|
|
|
const char *str;
|
2010-08-08 20:58:41 +04:00
|
|
|
ACPI_STATUS rv;
|
|
|
|
|
2010-08-13 20:21:50 +04:00
|
|
|
/*
|
|
|
|
* Three control methods are mandatory
|
|
|
|
* for P-states; _PSS, _PCT, and _PPC.
|
|
|
|
*/
|
2010-08-08 20:58:41 +04:00
|
|
|
rv = acpicpu_pstate_pss(sc);
|
|
|
|
|
2010-08-08 22:10:34 +04:00
|
|
|
if (ACPI_FAILURE(rv)) {
|
|
|
|
str = "_PSS";
|
|
|
|
goto fail;
|
|
|
|
}
|
2010-08-08 20:58:41 +04:00
|
|
|
|
|
|
|
rv = acpicpu_pstate_pct(sc);
|
|
|
|
|
2010-08-08 22:10:34 +04:00
|
|
|
if (ACPI_FAILURE(rv)) {
|
|
|
|
str = "_PCT";
|
|
|
|
goto fail;
|
|
|
|
}
|
2010-08-08 20:58:41 +04:00
|
|
|
|
|
|
|
rv = acpicpu_pstate_max(sc);
|
|
|
|
|
2010-08-13 20:21:50 +04:00
|
|
|
if (rv != 0) {
|
|
|
|
str = "_PPC";
|
|
|
|
goto fail;
|
|
|
|
}
|
2010-08-08 20:58:41 +04:00
|
|
|
|
|
|
|
sc->sc_flags |= ACPICPU_FLAG_P;
|
2010-08-09 19:56:45 +04:00
|
|
|
sc->sc_pstate_current = sc->sc_pstate[0].ps_freq;
|
2010-08-08 20:58:41 +04:00
|
|
|
|
|
|
|
acpicpu_pstate_bios();
|
2010-08-10 06:42:05 +04:00
|
|
|
acpicpu_pstate_attach_evcnt(sc);
|
2010-08-08 20:58:41 +04:00
|
|
|
acpicpu_pstate_attach_print(sc);
|
2010-08-08 22:10:34 +04:00
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
fail:
|
2010-08-13 20:21:50 +04:00
|
|
|
switch (rv) {
|
|
|
|
|
|
|
|
case AE_NOT_FOUND:
|
|
|
|
return;
|
|
|
|
|
|
|
|
case AE_SUPPORT:
|
|
|
|
aprint_verbose_dev(sc->sc_dev, "P-states not supported\n");
|
|
|
|
return;
|
|
|
|
|
|
|
|
default:
|
|
|
|
aprint_error_dev(sc->sc_dev, "failed to evaluate "
|
|
|
|
"%s: %s\n", str, AcpiFormatException(rv));
|
|
|
|
}
|
2010-08-08 20:58:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
acpicpu_pstate_attach_print(struct acpicpu_softc *sc)
|
|
|
|
{
|
|
|
|
const uint8_t method = sc->sc_pstate_control.reg_spaceid;
|
|
|
|
struct acpicpu_pstate *ps;
|
2010-08-11 20:41:19 +04:00
|
|
|
static bool once = false;
|
2010-08-08 20:58:41 +04:00
|
|
|
const char *str;
|
|
|
|
uint32_t i;
|
|
|
|
|
2010-08-11 20:41:19 +04:00
|
|
|
if (once != false)
|
|
|
|
return;
|
|
|
|
|
2010-08-11 14:44:07 +04:00
|
|
|
str = (method != ACPI_ADR_SPACE_SYSTEM_IO) ? "FFH" : "I/O";
|
2010-08-08 20:58:41 +04:00
|
|
|
|
|
|
|
for (i = 0; i < sc->sc_pstate_count; i++) {
|
|
|
|
|
|
|
|
ps = &sc->sc_pstate[i];
|
|
|
|
|
|
|
|
if (ps->ps_freq == 0)
|
|
|
|
continue;
|
|
|
|
|
2010-08-11 14:44:07 +04:00
|
|
|
aprint_debug_dev(sc->sc_dev, "P%d: %3s, "
|
2010-08-13 20:21:50 +04:00
|
|
|
"lat %3u us, pow %5u mW, %4u MHz\n", i, str,
|
|
|
|
ps->ps_latency, ps->ps_power, ps->ps_freq);
|
2010-08-08 20:58:41 +04:00
|
|
|
}
|
2010-08-11 20:41:19 +04:00
|
|
|
|
|
|
|
once = true;
|
2010-08-08 20:58:41 +04:00
|
|
|
}
|
|
|
|
|
2010-08-10 06:42:05 +04:00
|
|
|
static void
|
|
|
|
acpicpu_pstate_attach_evcnt(struct acpicpu_softc *sc)
|
|
|
|
{
|
|
|
|
struct acpicpu_pstate *ps;
|
|
|
|
uint32_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < sc->sc_pstate_count; i++) {
|
|
|
|
|
|
|
|
ps = &sc->sc_pstate[i];
|
|
|
|
|
|
|
|
if (ps->ps_freq == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
(void)snprintf(ps->ps_name, sizeof(ps->ps_name),
|
|
|
|
"P%u (%u MHz)", i, ps->ps_freq);
|
|
|
|
|
|
|
|
evcnt_attach_dynamic(&ps->ps_evcnt, EVCNT_TYPE_MISC,
|
|
|
|
NULL, device_xname(sc->sc_dev), ps->ps_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-08 20:58:41 +04:00
|
|
|
int
|
|
|
|
acpicpu_pstate_detach(device_t self)
|
|
|
|
{
|
|
|
|
struct acpicpu_softc *sc = device_private(self);
|
|
|
|
static ONCE_DECL(once_detach);
|
|
|
|
size_t size;
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
if ((sc->sc_flags & ACPICPU_FLAG_P) == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
rv = RUN_ONCE(&once_detach, acpicpu_md_pstate_stop);
|
|
|
|
|
|
|
|
if (rv != 0)
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
size = sc->sc_pstate_count * sizeof(*sc->sc_pstate);
|
|
|
|
|
|
|
|
if (sc->sc_pstate != NULL)
|
|
|
|
kmem_free(sc->sc_pstate, size);
|
|
|
|
|
|
|
|
sc->sc_flags &= ~ACPICPU_FLAG_P;
|
2010-08-10 06:42:05 +04:00
|
|
|
acpicpu_pstate_detach_evcnt(sc);
|
2010-08-08 20:58:41 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-08-10 06:42:05 +04:00
|
|
|
static void
|
|
|
|
acpicpu_pstate_detach_evcnt(struct acpicpu_softc *sc)
|
|
|
|
{
|
|
|
|
struct acpicpu_pstate *ps;
|
|
|
|
uint32_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < sc->sc_pstate_count; i++) {
|
|
|
|
|
|
|
|
ps = &sc->sc_pstate[i];
|
|
|
|
|
|
|
|
if (ps->ps_freq != 0)
|
|
|
|
evcnt_detach(&ps->ps_evcnt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-08 20:58:41 +04:00
|
|
|
int
|
|
|
|
acpicpu_pstate_start(device_t self)
|
|
|
|
{
|
|
|
|
struct acpicpu_softc *sc = device_private(self);
|
|
|
|
static ONCE_DECL(once_start);
|
|
|
|
|
|
|
|
if ((sc->sc_flags & ACPICPU_FLAG_P) == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return RUN_ONCE(&once_start, acpicpu_md_pstate_start);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
acpicpu_pstate_suspend(device_t self)
|
|
|
|
{
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
acpicpu_pstate_resume(device_t self)
|
|
|
|
{
|
|
|
|
|
2010-08-14 09:41:22 +04:00
|
|
|
acpicpu_pstate_callback(self);
|
2010-08-08 20:58:41 +04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
acpicpu_pstate_callback(void *aux)
|
|
|
|
{
|
|
|
|
struct acpicpu_softc *sc;
|
|
|
|
device_t self = aux;
|
|
|
|
uint32_t old, new;
|
|
|
|
|
|
|
|
sc = device_private(self);
|
|
|
|
|
|
|
|
mutex_enter(&sc->sc_mtx);
|
|
|
|
old = sc->sc_pstate_max;
|
|
|
|
acpicpu_pstate_change(sc);
|
|
|
|
new = sc->sc_pstate_max;
|
|
|
|
mutex_exit(&sc->sc_mtx);
|
|
|
|
|
|
|
|
if (old != new) {
|
|
|
|
|
2010-08-12 10:17:14 +04:00
|
|
|
aprint_debug_dev(sc->sc_dev, "maximum frequency "
|
|
|
|
"changed from P%u (%u MHz) to P%u (%u MHz)\n",
|
|
|
|
old, sc->sc_pstate[old].ps_freq, new,
|
|
|
|
sc->sc_pstate[sc->sc_pstate_max].ps_freq);
|
|
|
|
#if 0
|
2010-08-08 20:58:41 +04:00
|
|
|
/*
|
|
|
|
* If the maximum changed, proactively
|
|
|
|
* raise or lower the target frequency.
|
|
|
|
*/
|
|
|
|
acpicpu_pstate_set(sc, sc->sc_pstate[new].ps_freq);
|
|
|
|
|
|
|
|
#endif
|
2010-08-12 10:17:14 +04:00
|
|
|
}
|
2010-08-08 20:58:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
ACPI_STATUS
|
|
|
|
acpicpu_pstate_pss(struct acpicpu_softc *sc)
|
|
|
|
{
|
|
|
|
struct acpicpu_pstate *ps;
|
|
|
|
ACPI_OBJECT *obj;
|
|
|
|
ACPI_BUFFER buf;
|
|
|
|
ACPI_STATUS rv;
|
|
|
|
uint32_t count;
|
|
|
|
uint32_t i, j;
|
|
|
|
|
|
|
|
rv = acpi_eval_struct(sc->sc_node->ad_handle, "_PSS", &buf);
|
|
|
|
|
|
|
|
if (ACPI_FAILURE(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
obj = buf.Pointer;
|
|
|
|
|
|
|
|
if (obj->Type != ACPI_TYPE_PACKAGE) {
|
|
|
|
rv = AE_TYPE;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
sc->sc_pstate_count = obj->Package.Count;
|
|
|
|
|
|
|
|
if (sc->sc_pstate_count == 0) {
|
|
|
|
rv = AE_NOT_EXIST;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2010-08-11 15:48:21 +04:00
|
|
|
if (sc->sc_pstate_count > ACPICPU_P_STATE_MAX) {
|
2010-08-08 20:58:41 +04:00
|
|
|
rv = AE_LIMIT;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
sc->sc_pstate = kmem_zalloc(sc->sc_pstate_count *
|
|
|
|
sizeof(struct acpicpu_pstate), KM_SLEEP);
|
|
|
|
|
|
|
|
if (sc->sc_pstate == NULL) {
|
|
|
|
rv = AE_NO_MEMORY;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (count = i = 0; i < sc->sc_pstate_count; i++) {
|
|
|
|
|
|
|
|
ps = &sc->sc_pstate[i];
|
|
|
|
rv = acpicpu_pstate_pss_add(ps, &obj->Package.Elements[i]);
|
|
|
|
|
2010-08-11 22:15:52 +04:00
|
|
|
if (ACPI_FAILURE(rv)) {
|
|
|
|
ps->ps_freq = 0;
|
2010-08-08 20:58:41 +04:00
|
|
|
continue;
|
2010-08-11 22:15:52 +04:00
|
|
|
}
|
2010-08-08 20:58:41 +04:00
|
|
|
|
|
|
|
for (j = 0; j < i; j++) {
|
|
|
|
|
|
|
|
if (ps->ps_freq >= sc->sc_pstate[j].ps_freq) {
|
|
|
|
ps->ps_freq = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ps->ps_freq != 0)
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = (count != 0) ? AE_OK : AE_NOT_EXIST;
|
|
|
|
|
|
|
|
out:
|
|
|
|
if (buf.Pointer != NULL)
|
|
|
|
ACPI_FREE(buf.Pointer);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ACPI_STATUS
|
|
|
|
acpicpu_pstate_pss_add(struct acpicpu_pstate *ps, ACPI_OBJECT *obj)
|
|
|
|
{
|
|
|
|
ACPI_OBJECT *elm;
|
|
|
|
uint32_t val[6];
|
|
|
|
uint32_t *p;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (obj->Type != ACPI_TYPE_PACKAGE)
|
|
|
|
return AE_TYPE;
|
|
|
|
|
|
|
|
if (obj->Package.Count != 6)
|
|
|
|
return AE_BAD_DATA;
|
|
|
|
|
|
|
|
elm = obj->Package.Elements;
|
|
|
|
|
|
|
|
for (i = 0; i < 6; i++) {
|
|
|
|
|
|
|
|
if (elm[i].Type != ACPI_TYPE_INTEGER)
|
|
|
|
return AE_TYPE;
|
|
|
|
|
|
|
|
if (elm[i].Integer.Value > UINT32_MAX)
|
|
|
|
return AE_AML_NUMERIC_OVERFLOW;
|
|
|
|
|
|
|
|
val[i] = elm[i].Integer.Value;
|
|
|
|
}
|
|
|
|
|
|
|
|
p = &ps->ps_freq;
|
|
|
|
|
|
|
|
for (i = 0; i < 6; i++, p++)
|
|
|
|
*p = val[i];
|
|
|
|
|
2010-08-11 22:15:52 +04:00
|
|
|
if (ps->ps_freq == 0 || ps->ps_freq > 9999)
|
|
|
|
return AE_BAD_DECIMAL_CONSTANT;
|
|
|
|
|
2010-08-08 20:58:41 +04:00
|
|
|
/*
|
|
|
|
* The latency is typically around 10 usec
|
|
|
|
* on Intel CPUs. Use that as the minimum.
|
|
|
|
*/
|
|
|
|
if (ps->ps_latency < 10)
|
|
|
|
ps->ps_latency = 10;
|
|
|
|
|
|
|
|
return AE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
ACPI_STATUS
|
|
|
|
acpicpu_pstate_pct(struct acpicpu_softc *sc)
|
|
|
|
{
|
|
|
|
static const size_t size = sizeof(struct acpicpu_reg);
|
|
|
|
struct acpicpu_reg *reg[2];
|
|
|
|
ACPI_OBJECT *elm, *obj;
|
|
|
|
ACPI_BUFFER buf;
|
|
|
|
ACPI_STATUS rv;
|
|
|
|
uint8_t width;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
rv = acpi_eval_struct(sc->sc_node->ad_handle, "_PCT", &buf);
|
|
|
|
|
|
|
|
if (ACPI_FAILURE(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
obj = buf.Pointer;
|
|
|
|
|
|
|
|
if (obj->Type != ACPI_TYPE_PACKAGE) {
|
|
|
|
rv = AE_TYPE;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (obj->Package.Count != 2) {
|
|
|
|
rv = AE_LIMIT;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
|
|
|
|
elm = &obj->Package.Elements[i];
|
|
|
|
|
|
|
|
if (elm->Type != ACPI_TYPE_BUFFER) {
|
|
|
|
rv = AE_TYPE;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (size > elm->Buffer.Length) {
|
|
|
|
rv = AE_AML_BAD_RESOURCE_LENGTH;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
reg[i] = (struct acpicpu_reg *)elm->Buffer.Pointer;
|
|
|
|
|
|
|
|
switch (reg[i]->reg_spaceid) {
|
|
|
|
|
|
|
|
case ACPI_ADR_SPACE_SYSTEM_IO:
|
|
|
|
|
|
|
|
if (reg[i]->reg_addr == 0) {
|
|
|
|
rv = AE_AML_ILLEGAL_ADDRESS;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
width = reg[i]->reg_bitwidth;
|
|
|
|
|
2010-08-11 17:02:59 +04:00
|
|
|
if (width + reg[i]->reg_bitoffset > 32) {
|
|
|
|
rv = AE_AML_BAD_RESOURCE_VALUE;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2010-08-08 20:58:41 +04:00
|
|
|
if (width != 8 && width != 16 && width != 32) {
|
2010-08-08 22:25:06 +04:00
|
|
|
rv = AE_AML_BAD_RESOURCE_VALUE;
|
2010-08-08 20:58:41 +04:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ACPI_ADR_SPACE_FIXED_HARDWARE:
|
|
|
|
|
|
|
|
if ((sc->sc_flags & ACPICPU_FLAG_P_FFH) == 0) {
|
2010-08-08 22:25:06 +04:00
|
|
|
rv = AE_SUPPORT;
|
2010-08-08 20:58:41 +04:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
rv = AE_AML_INVALID_SPACE_ID;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (reg[0]->reg_spaceid != reg[1]->reg_spaceid) {
|
|
|
|
rv = AE_AML_INVALID_SPACE_ID;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2010-08-13 20:21:50 +04:00
|
|
|
(void)memcpy(&sc->sc_pstate_control, reg[0], size);
|
|
|
|
(void)memcpy(&sc->sc_pstate_status, reg[1], size);
|
2010-08-08 20:58:41 +04:00
|
|
|
|
|
|
|
out:
|
|
|
|
if (buf.Pointer != NULL)
|
|
|
|
ACPI_FREE(buf.Pointer);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
acpicpu_pstate_max(struct acpicpu_softc *sc)
|
|
|
|
{
|
|
|
|
ACPI_INTEGER val;
|
|
|
|
ACPI_STATUS rv;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Evaluate the currently highest P-state that can be used.
|
|
|
|
* If available, we can use either this state or any lower
|
|
|
|
* power (i.e. higher numbered) state from the _PSS object.
|
|
|
|
*/
|
|
|
|
rv = acpi_eval_integer(sc->sc_node->ad_handle, "_PPC", &val);
|
|
|
|
|
|
|
|
sc->sc_pstate_max = 0;
|
|
|
|
|
|
|
|
if (ACPI_FAILURE(rv))
|
|
|
|
return 1;
|
|
|
|
|
2010-08-12 10:17:14 +04:00
|
|
|
if (val > sc->sc_pstate_count - 1)
|
2010-08-08 20:58:41 +04:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (sc->sc_pstate[val].ps_freq == 0)
|
|
|
|
return 1;
|
|
|
|
|
2010-08-12 10:17:14 +04:00
|
|
|
sc->sc_pstate_max = val;
|
2010-08-08 20:58:41 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
acpicpu_pstate_change(struct acpicpu_softc *sc)
|
|
|
|
{
|
|
|
|
ACPI_OBJECT_LIST arg;
|
|
|
|
ACPI_OBJECT obj[2];
|
|
|
|
|
|
|
|
arg.Count = 2;
|
|
|
|
arg.Pointer = obj;
|
|
|
|
|
|
|
|
obj[0].Type = ACPI_TYPE_INTEGER;
|
|
|
|
obj[1].Type = ACPI_TYPE_INTEGER;
|
|
|
|
|
|
|
|
obj[0].Integer.Value = ACPICPU_P_NOTIFY;
|
|
|
|
obj[1].Integer.Value = acpicpu_pstate_max(sc);
|
|
|
|
|
|
|
|
(void)AcpiEvaluateObject(sc->sc_node->ad_handle, "_OST", &arg, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
acpicpu_pstate_bios(void)
|
|
|
|
{
|
|
|
|
const uint8_t val = AcpiGbl_FADT.PstateControl;
|
|
|
|
const uint32_t addr = AcpiGbl_FADT.SmiCommand;
|
|
|
|
|
|
|
|
if (addr == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
(void)AcpiOsWritePort(addr, val, 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
acpicpu_pstate_get(struct acpicpu_softc *sc, uint32_t *freq)
|
|
|
|
{
|
|
|
|
const uint8_t method = sc->sc_pstate_control.reg_spaceid;
|
|
|
|
struct acpicpu_pstate *ps = NULL;
|
|
|
|
uint32_t i, val = 0;
|
|
|
|
uint64_t addr;
|
|
|
|
uint8_t width;
|
|
|
|
int rv;
|
|
|
|
|
2010-08-11 20:22:18 +04:00
|
|
|
if (sc->sc_cold != false) {
|
|
|
|
rv = EBUSY;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2010-08-08 20:58:41 +04:00
|
|
|
if ((sc->sc_flags & ACPICPU_FLAG_P) == 0) {
|
|
|
|
rv = ENODEV;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2010-08-12 10:17:14 +04:00
|
|
|
mutex_enter(&sc->sc_mtx);
|
|
|
|
|
2010-08-08 20:58:41 +04:00
|
|
|
if (sc->sc_pstate_current != ACPICPU_P_STATE_UNKNOWN) {
|
|
|
|
*freq = sc->sc_pstate_current;
|
2010-08-12 10:17:14 +04:00
|
|
|
mutex_exit(&sc->sc_mtx);
|
2010-08-08 20:58:41 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-08-12 10:17:14 +04:00
|
|
|
mutex_exit(&sc->sc_mtx);
|
|
|
|
|
2010-08-08 20:58:41 +04:00
|
|
|
switch (method) {
|
|
|
|
|
|
|
|
case ACPI_ADR_SPACE_FIXED_HARDWARE:
|
|
|
|
|
|
|
|
rv = acpicpu_md_pstate_get(sc, freq);
|
|
|
|
|
|
|
|
if (rv != 0)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ACPI_ADR_SPACE_SYSTEM_IO:
|
|
|
|
|
|
|
|
addr = sc->sc_pstate_status.reg_addr;
|
|
|
|
width = sc->sc_pstate_status.reg_bitwidth;
|
|
|
|
|
|
|
|
(void)AcpiOsReadPort(addr, &val, width);
|
|
|
|
|
|
|
|
if (val == 0) {
|
|
|
|
rv = EIO;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2010-08-09 08:27:07 +04:00
|
|
|
for (i = 0; i < sc->sc_pstate_count; i++) {
|
2010-08-08 20:58:41 +04:00
|
|
|
|
|
|
|
if (sc->sc_pstate[i].ps_freq == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (val == sc->sc_pstate[i].ps_status) {
|
|
|
|
ps = &sc->sc_pstate[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-13 20:21:50 +04:00
|
|
|
if (__predict_false(ps == NULL)) {
|
2010-08-08 20:58:41 +04:00
|
|
|
rv = EIO;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
*freq = ps->ps_freq;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
rv = ENOTTY;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2010-08-12 10:17:14 +04:00
|
|
|
mutex_enter(&sc->sc_mtx);
|
2010-08-08 20:58:41 +04:00
|
|
|
sc->sc_pstate_current = *freq;
|
2010-08-12 10:17:14 +04:00
|
|
|
mutex_exit(&sc->sc_mtx);
|
2010-08-08 20:58:41 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
aprint_error_dev(sc->sc_dev, "failed "
|
|
|
|
"to get frequency (err %d)\n", rv);
|
|
|
|
|
2010-08-12 10:17:14 +04:00
|
|
|
mutex_enter(&sc->sc_mtx);
|
2010-08-08 20:58:41 +04:00
|
|
|
*freq = sc->sc_pstate_current = ACPICPU_P_STATE_UNKNOWN;
|
2010-08-12 10:17:14 +04:00
|
|
|
mutex_exit(&sc->sc_mtx);
|
2010-08-08 20:58:41 +04:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
acpicpu_pstate_set(struct acpicpu_softc *sc, uint32_t freq)
|
|
|
|
{
|
|
|
|
const uint8_t method = sc->sc_pstate_control.reg_spaceid;
|
|
|
|
struct acpicpu_pstate *ps = NULL;
|
|
|
|
uint32_t i, val;
|
|
|
|
uint64_t addr;
|
|
|
|
uint8_t width;
|
|
|
|
int rv;
|
|
|
|
|
2010-08-11 20:22:18 +04:00
|
|
|
if (sc->sc_cold != false) {
|
|
|
|
rv = EBUSY;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2010-08-08 20:58:41 +04:00
|
|
|
if ((sc->sc_flags & ACPICPU_FLAG_P) == 0) {
|
|
|
|
rv = ENODEV;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
mutex_enter(&sc->sc_mtx);
|
|
|
|
|
|
|
|
for (i = sc->sc_pstate_max; i < sc->sc_pstate_count; i++) {
|
|
|
|
|
|
|
|
if (sc->sc_pstate[i].ps_freq == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (sc->sc_pstate[i].ps_freq == freq) {
|
|
|
|
ps = &sc->sc_pstate[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mutex_exit(&sc->sc_mtx);
|
|
|
|
|
2010-08-13 20:21:50 +04:00
|
|
|
if (__predict_false(ps == NULL)) {
|
2010-08-08 20:58:41 +04:00
|
|
|
rv = EINVAL;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (method) {
|
|
|
|
|
|
|
|
case ACPI_ADR_SPACE_FIXED_HARDWARE:
|
|
|
|
|
|
|
|
rv = acpicpu_md_pstate_set(ps);
|
|
|
|
|
|
|
|
if (rv != 0)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ACPI_ADR_SPACE_SYSTEM_IO:
|
|
|
|
|
|
|
|
addr = sc->sc_pstate_control.reg_addr;
|
|
|
|
width = sc->sc_pstate_control.reg_bitwidth;
|
|
|
|
|
|
|
|
(void)AcpiOsWritePort(addr, ps->ps_control, width);
|
|
|
|
|
|
|
|
addr = sc->sc_pstate_status.reg_addr;
|
|
|
|
width = sc->sc_pstate_status.reg_bitwidth;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Some systems take longer to respond
|
|
|
|
* than the reported worst-case latency.
|
|
|
|
*/
|
|
|
|
for (i = val = 0; i < ACPICPU_P_STATE_RETRY; i++) {
|
|
|
|
|
|
|
|
(void)AcpiOsReadPort(addr, &val, width);
|
|
|
|
|
|
|
|
if (val == ps->ps_status)
|
|
|
|
break;
|
|
|
|
|
|
|
|
DELAY(ps->ps_latency);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == ACPICPU_P_STATE_RETRY) {
|
|
|
|
rv = EAGAIN;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
rv = ENOTTY;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2010-08-12 10:17:14 +04:00
|
|
|
mutex_enter(&sc->sc_mtx);
|
2010-08-13 22:44:24 +04:00
|
|
|
ps->ps_evcnt.ev_count++;
|
2010-08-08 20:58:41 +04:00
|
|
|
sc->sc_pstate_current = freq;
|
2010-08-12 10:17:14 +04:00
|
|
|
mutex_exit(&sc->sc_mtx);
|
2010-08-08 20:58:41 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
aprint_error_dev(sc->sc_dev, "failed to set "
|
|
|
|
"frequency to %u (err %d)\n", freq, rv);
|
|
|
|
|
2010-08-12 10:17:14 +04:00
|
|
|
mutex_enter(&sc->sc_mtx);
|
2010-08-08 20:58:41 +04:00
|
|
|
sc->sc_pstate_current = ACPICPU_P_STATE_UNKNOWN;
|
2010-08-12 10:17:14 +04:00
|
|
|
mutex_exit(&sc->sc_mtx);
|
2010-08-08 20:58:41 +04:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|