Modularize amdtemp(4).

This commit is contained in:
jruoho 2011-06-15 03:22:39 +00:00
parent 506691b53b
commit c6e5cf85e6
6 changed files with 96 additions and 18 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: md.amd64,v 1.20 2011/04/14 15:45:27 yamt Exp $
# $NetBSD: md.amd64,v 1.21 2011/06/15 03:22:39 jruoho Exp $
./@MODULEDIR@/acpiacad base-kernel-modules kmod
./@MODULEDIR@/acpiacad/acpiacad.kmod base-kernel-modules kmod
./@MODULEDIR@/acpibat base-kernel-modules kmod
@ -25,6 +25,8 @@
./@MODULEDIR@/acpiwmi/acpiwmi.kmod base-kernel-modules kmod
./@MODULEDIR@/aibs base-kernel-modules kmod
./@MODULEDIR@/aibs/aibs.kmod base-kernel-modules kmod
./@MODULEDIR@/amdtemp base-kernel-modules kmod
./@MODULEDIR@/amdtemp/amdtemp.kmod base-kernel-modules kmod
./@MODULEDIR@/aps base-kernel-modules kmod
./@MODULEDIR@/aps/aps.kmod base-kernel-modules kmod
./@MODULEDIR@/asus base-kernel-modules kmod

View File

@ -1,4 +1,4 @@
# $NetBSD: md.i386,v 1.24 2011/04/14 15:45:28 yamt Exp $
# $NetBSD: md.i386,v 1.25 2011/06/15 03:22:39 jruoho Exp $
./@MODULEDIR@/acpiacad base-kernel-modules kmod
./@MODULEDIR@/acpiacad/acpiacad.kmod base-kernel-modules kmod
./@MODULEDIR@/acpibat base-kernel-modules kmod
@ -25,6 +25,8 @@
./@MODULEDIR@/acpiwmi/acpiwmi.kmod base-kernel-modules kmod
./@MODULEDIR@/aibs base-kernel-modules kmod
./@MODULEDIR@/aibs/aibs.kmod base-kernel-modules kmod
./@MODULEDIR@/amdtemp base-kernel-modules kmod
./@MODULEDIR@/amdtemp/amdtemp.kmod base-kernel-modules kmod
./@MODULEDIR@/aps base-kernel-modules kmod
./@MODULEDIR@/aps/aps.kmod base-kernel-modules kmod
./@MODULEDIR@/asus base-kernel-modules kmod

View File

@ -1,7 +1,7 @@
/* $NetBSD: amdtemp.c,v 1.9 2009/10/16 12:05:19 cegger Exp $ */
/* $NetBSD: amdtemp.c,v 1.10 2011/06/15 03:22:39 jruoho Exp $ */
/* $OpenBSD: kate.c,v 1.2 2008/03/27 04:52:03 cnst Exp $ */
/*
/*
* Copyright (c) 2008 The NetBSD Foundation, Inc.
* All rights reserved.
*
@ -48,22 +48,24 @@
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: amdtemp.c,v 1.9 2009/10/16 12:05:19 cegger Exp $ ");
__KERNEL_RCSID(0, "$NetBSD: amdtemp.c,v 1.10 2011/06/15 03:22:39 jruoho Exp $ ");
#include <sys/param.h>
#include <sys/bus.h>
#include <sys/cpu.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <sys/kmem.h>
#include <dev/sysmon/sysmonvar.h>
#include <sys/module.h>
#include <sys/bus.h>
#include <sys/cpu.h>
#include <machine/specialreg.h>
#include <dev/pci/pcireg.h>
#include <dev/pci/pcivar.h>
#include <dev/pci/pcidevs.h>
#include <dev/sysmon/sysmonvar.h>
/*
* AMD K8:
* http://www.amd.com/us-en/assets/content_type/white_papers_and_tech_docs/32559.pdf
@ -114,7 +116,7 @@ __KERNEL_RCSID(0, "$NetBSD: amdtemp.c,v 1.9 2009/10/16 12:05:19 cegger Exp $ ");
#define F10_TEMP_CURTEMP (1 << 21)
/*
* Revision Guide for AMD NPT Family 0Fh Processors,
* Revision Guide for AMD NPT Family 0Fh Processors,
* Publication # 33610, Revision 3.30, February 2008
*/
#define K8_SOCKET_F 1 /* Server */
@ -156,6 +158,7 @@ struct amdtemp_softc {
struct sysmon_envsys *sc_sme;
envsys_data_t *sc_sensor;
size_t sc_sensor_len;
char sc_rev;
int8_t sc_numsensors;
@ -164,8 +167,9 @@ struct amdtemp_softc {
};
static int amdtemp_match(device_t, cfdata_t, void *);
static int amdtemp_match(device_t, cfdata_t, void *);
static void amdtemp_attach(device_t, device_t, void *);
static int amdtemp_detach(device_t, int);
static void amdtemp_k8_init(struct amdtemp_softc *, pcireg_t);
static void amdtemp_k8_setup_sensors(struct amdtemp_softc *, int);
@ -175,8 +179,8 @@ static void amdtemp_family10_init(struct amdtemp_softc *);
static void amdtemp_family10_setup_sensors(struct amdtemp_softc *, int);
static void amdtemp_family10_refresh(struct sysmon_envsys *, envsys_data_t *);
CFATTACH_DECL_NEW(amdtemp, sizeof(struct amdtemp_softc),
amdtemp_match, amdtemp_attach, NULL, NULL);
CFATTACH_DECL_NEW(amdtemp, sizeof(struct amdtemp_softc),
amdtemp_match, amdtemp_attach, amdtemp_detach, NULL);
static int
amdtemp_match(device_t parent, cfdata_t match, void *aux)
@ -232,7 +236,6 @@ amdtemp_attach(device_t parent, device_t self, void *aux)
struct amdtemp_softc *sc = device_private(self);
struct pci_attach_args *pa = aux;
pcireg_t cpu_signature;
size_t len;
int error;
uint8_t i;
@ -275,9 +278,9 @@ amdtemp_attach(device_t parent, device_t self, void *aux)
aprint_debug_dev(self, "Workaround enabled\n");
sc->sc_sme = sysmon_envsys_create();
len = sizeof(envsys_data_t) * sc->sc_numsensors;
sc->sc_sensor = kmem_zalloc(len, KM_NOSLEEP);
if (!sc->sc_sensor)
sc->sc_sensor_len = sizeof(envsys_data_t) * sc->sc_numsensors;
sc->sc_sensor = kmem_zalloc(sc->sc_sensor_len, KM_NOSLEEP);
if (sc->sc_sensor == NULL)
goto bad2;
switch (sc->sc_family) {
@ -328,9 +331,26 @@ amdtemp_attach(device_t parent, device_t self, void *aux)
return;
bad:
kmem_free(sc->sc_sensor, len);
kmem_free(sc->sc_sensor, sc->sc_sensor_len);
sc->sc_sensor = NULL;
bad2:
sysmon_envsys_destroy(sc->sc_sme);
sc->sc_sme = NULL;
}
static int
amdtemp_detach(device_t self, int flags)
{
struct amdtemp_softc *sc = device_private(self);
if (sc->sc_sme != NULL)
sysmon_envsys_unregister(sc->sc_sme);
if (sc->sc_sensor != NULL)
kmem_free(sc->sc_sensor, sc->sc_sensor_len);
return 0;
}
static void
@ -492,3 +512,32 @@ amdtemp_family10_refresh(struct sysmon_envsys *sme, envsys_data_t *edata)
/* envsys(4) wants uK... convert from Celsius. */
edata->value_cur = (value * 125000) + 273150000;
}
MODULE(MODULE_CLASS_DRIVER, amdtemp, NULL);
#ifdef _MODULE
#include "ioconf.c"
#endif
static int
amdtemp_modcmd(modcmd_t cmd, void *aux)
{
int error = 0;
switch (cmd) {
case MODULE_CMD_INIT:
#ifdef _MODULE
error = config_init_component(cfdriver_ioconf_amdtemp,
cfattach_ioconf_amdtemp, cfdata_ioconf_amdtemp);
#endif
return error;
case MODULE_CMD_FINI:
#ifdef _MODULE
error = config_fini_component(cfdriver_ioconf_amdtemp,
cfattach_ioconf_amdtemp, cfdata_ioconf_amdtemp);
#endif
return error;
default:
return ENOTTY;
}
}

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.70 2011/04/14 15:45:27 yamt Exp $
# $NetBSD: Makefile,v 1.71 2011/06/15 03:22:40 jruoho Exp $
.include <bsd.own.mk>
@ -89,6 +89,7 @@ SUBDIR+= exec_elf64
.if ${MACHINE_ARCH} == "i386" || \
${MACHINE_ARCH} == "x86_64"
SUBDIR+= amdtemp
SUBDIR+= coretemp
SUBDIR+= est
SUBDIR+= odcm

View File

@ -0,0 +1,13 @@
# $NetBSD: Makefile,v 1.1 2011/06/15 03:22:40 jruoho Exp $
.include "../Makefile.inc"
.PATH: ${S}/arch/x86/pci
KMOD= amdtemp
IOCONF= amdtemp.ioconf
SRCS= amdtemp.c
WARNS= 4
.include <bsd.kmodule.mk>

View File

@ -0,0 +1,11 @@
# $NetBSD: amdtemp.ioconf,v 1.1 2011/06/15 03:22:40 jruoho Exp $
ioconf amdtemp
include "conf/files"
include "dev/pci/files.pci"
include "arch/x86/pci/files.pci"
pseudo-root pci*
amdtemp* at pci? dev ? function ?