Update powernow module with POWERNOW_K7 and POWERNOW_K8 support.

Works fine on amd64 cpus running in 32-bit mode.

Tested by Joel Carnat.
This commit is contained in:
xtraeme 2006-08-27 10:10:55 +00:00
parent 690289e97b
commit ca450bca52
4 changed files with 57 additions and 19 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: powernow.h,v 1.4 2006/08/23 22:59:45 xtraeme Exp $ */
/* $NetBSD: powernow.h,v 1.5 2006/08/27 10:10:55 xtraeme Exp $ */
/*-
* Copyright (c) 2004 Martin Végiard.
@ -184,5 +184,6 @@ void k7_powernow_destroy(void);
/* x86/x86/powernow_k8.c */
void k8_powernow_init(void);
void k8_powernow_destroy(void);
#endif

View File

@ -1,4 +1,4 @@
/* $NetBSD: powernow_k8.c,v 1.4 2006/08/26 10:10:00 xtraeme Exp $ */
/* $NetBSD: powernow_k8.c,v 1.5 2006/08/27 10:10:55 xtraeme Exp $ */
/* $OpenBSD: powernow-k8.c,v 1.8 2006/06/16 05:58:50 gwk Exp $ */
/*-
@ -66,7 +66,7 @@
/* AMD POWERNOW K8 driver */
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: powernow_k8.c,v 1.4 2006/08/26 10:10:00 xtraeme Exp $");
__KERNEL_RCSID(0, "$NetBSD: powernow_k8.c,v 1.5 2006/08/27 10:10:55 xtraeme Exp $");
#include <sys/types.h>
#include <sys/param.h>
@ -74,7 +74,6 @@ __KERNEL_RCSID(0, "$NetBSD: powernow_k8.c,v 1.4 2006/08/26 10:10:00 xtraeme Exp
#include <sys/malloc.h>
#include <sys/sysctl.h>
#include <x86/include/cpuvar.h>
#include <x86/include/powernow.h>
#include <dev/isa/isareg.h>
@ -84,6 +83,13 @@ __KERNEL_RCSID(0, "$NetBSD: powernow_k8.c,v 1.4 2006/08/26 10:10:00 xtraeme Exp
#include <machine/cpufunc.h>
#include <machine/bus.h>
#ifdef _LKM
static struct sysctllog *sysctllog;
#define SYSCTLLOG &sysctllog
#else
#define SYSCTLLOG NULL
#endif
/* Global variables */
struct powernow_cpu_state *k8pnow_current_state;
unsigned int cur_freq;
@ -412,28 +418,28 @@ k8_powernow_init(void)
}
/* Create sysctl machdep.powernow.frequency. */
if (sysctl_createv(NULL, 0, NULL, &node,
if (sysctl_createv(SYSCTLLOG, 0, NULL, &node,
CTLFLAG_PERMANENT,
CTLTYPE_NODE, "machdep", NULL,
NULL, 0, NULL, 0,
CTL_MACHDEP, CTL_EOL) != 0)
goto err;
if (sysctl_createv(NULL, 0, &node, &pnownode,
if (sysctl_createv(SYSCTLLOG, 0, &node, &pnownode,
0,
CTLTYPE_NODE, "powernow", NULL,
NULL, 0, NULL, 0,
CTL_CREATE, CTL_EOL) != 0)
goto err;
if (sysctl_createv(NULL, 0, &pnownode, &freqnode,
if (sysctl_createv(SYSCTLLOG, 0, &pnownode, &freqnode,
0,
CTLTYPE_NODE, "frequency", NULL,
NULL, 0, NULL, 0,
CTL_CREATE, CTL_EOL) != 0)
goto err;
if (sysctl_createv(NULL, 0, &freqnode, &node,
if (sysctl_createv(SYSCTLLOG, 0, &freqnode, &node,
CTLFLAG_READWRITE,
CTLTYPE_INT, "target", NULL,
k8pnow_sysctl_helper, 0, NULL, 0,
@ -442,7 +448,7 @@ k8_powernow_init(void)
powernow_node_target = node->sysctl_num;
if (sysctl_createv(NULL, 0, &freqnode, &node,
if (sysctl_createv(SYSCTLLOG, 0, &freqnode, &node,
0,
CTLTYPE_INT, "current", NULL,
k8pnow_sysctl_helper, 0, NULL, 0,
@ -451,7 +457,7 @@ k8_powernow_init(void)
powernow_node_current = node->sysctl_num;
if (sysctl_createv(NULL, 0, &freqnode, &node,
if (sysctl_createv(SYSCTLLOG, 0, &freqnode, &node,
0,
CTLTYPE_STRING, "available", NULL,
NULL, 0, freq_names, freq_names_len,
@ -473,3 +479,14 @@ k8_powernow_init(void)
free(cstate, M_DEVBUF);
free(freq_names, M_SYSCTLDATA);
}
void
k8_powernow_destroy(void)
{
#ifdef _LKM
sysctl_teardown(SYSCTLLOG);
if (freq_names)
free(freq_names, M_SYSCTLDATA);
#endif
}

View File

@ -1,6 +1,6 @@
# $NetBSD: Makefile,v 1.2 2006/08/06 16:05:07 xtraeme Exp $
# $NetBSD: Makefile,v 1.3 2006/08/27 10:10:55 xtraeme Exp $
#
# Makefile for loadable AMD PowerNow K7 device driver kernel module
# Makefile for loadable AMD PowerNow K[78] device driver kernel module
#
.include "../Makefile.inc"
@ -8,7 +8,8 @@
.PATH: $S/arch/x86/x86
.PATH: $S/arch/i386/i386
CFILES= lkminit_powernow.c powernow_common.c powernow_k7.c
CFILES= lkminit_powernow.c powernow_common.c powernow_k7.c \
powernow_k8.c
SRCS= ${CFILES}
WARNS= 3
@ -16,6 +17,9 @@ WARNS= 3
KMOD= powernow
MAN=
# Enable this one to show debug output
# CPPFLAGS+= -DPOWERNOW_DEBUG
CLEANFILES+= *~ ${KMOD}
.include <bsd.kmod.mk>

View File

@ -1,4 +1,4 @@
/* $NetBSD: lkminit_powernow.c,v 1.5 2006/08/08 21:04:29 xtraeme Exp $ */
/* $NetBSD: lkminit_powernow.c,v 1.6 2006/08/27 10:10:55 xtraeme Exp $ */
/*
* Derived from:
@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: lkminit_powernow.c,v 1.5 2006/08/08 21:04:29 xtraeme Exp $");
__KERNEL_RCSID(0, "$NetBSD: lkminit_powernow.c,v 1.6 2006/08/27 10:10:55 xtraeme Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -69,6 +69,8 @@ powernow_mod_handle(struct lkm_table *lkmtp, int cmd)
struct cpu_info *ci;
int err = 0; /* default = success */
rval = 0;
switch (cmd) {
case LKM_E_LOAD:
/*
@ -79,17 +81,31 @@ powernow_mod_handle(struct lkm_table *lkmtp, int cmd)
ci = curcpu();
/* Test for Athlon M first... */
rval = powernow_probe(ci, 0x600);
if (!rval)
/* not found... try Athlon 64 now */
rval = powernow_probe(ci, 0xf00);
if (rval) {
DPRINTF(("%s: rval=%d\n", __func__, rval));
if (rval != 0) {
featflags = powernow_extflags(ci, rval);
if (featflags)
k7_powernow_init();
if (featflags) {
if (rval == 6) /* Athlon M */
k7_powernow_init();
else if (rval == 15) /* Athlon 64 */
k8_powernow_init();
}
}
break; /* Success */
case LKM_E_UNLOAD:
k7_powernow_destroy();
if (rval == 6)
k7_powernow_destroy();
else if (rval == 15)
k8_powernow_destroy();
break; /* Success */
default: /* we only understand load/unload */