summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjruoho <jruoho@NetBSD.org>2011-06-15 03:22:39 +0000
committerjruoho <jruoho@NetBSD.org>2011-06-15 03:22:39 +0000
commit8fb7e0d1928d5886c349beff9cdcdd98bc372fba (patch)
treee618af74ec822ce9a8aae472c616a2c1f38b58a0
parent54c2ddfbd71b2b3416d5a7773aa30c75020b44e6 (diff)
Modularize amdtemp(4).
-rw-r--r--distrib/sets/lists/modules/md.amd644
-rw-r--r--distrib/sets/lists/modules/md.i3864
-rw-r--r--sys/arch/x86/pci/amdtemp.c79
-rw-r--r--sys/modules/Makefile3
-rw-r--r--sys/modules/amdtemp/Makefile13
-rw-r--r--sys/modules/amdtemp/amdtemp.ioconf11
6 files changed, 96 insertions, 18 deletions
diff --git a/distrib/sets/lists/modules/md.amd64 b/distrib/sets/lists/modules/md.amd64
index 81ae2349296..ea182f0b281 100644
--- a/distrib/sets/lists/modules/md.amd64
+++ b/distrib/sets/lists/modules/md.amd64
@@ -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
diff --git a/distrib/sets/lists/modules/md.i386 b/distrib/sets/lists/modules/md.i386
index 8cfaa8f12b2..d16dbb4ca90 100644
--- a/distrib/sets/lists/modules/md.i386
+++ b/distrib/sets/lists/modules/md.i386
@@ -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
diff --git a/sys/arch/x86/pci/amdtemp.c b/sys/arch/x86/pci/amdtemp.c
index 39d329d2f84..ba5c967e968 100644
--- a/sys/arch/x86/pci/amdtemp.c
+++ b/sys/arch/x86/pci/amdtemp.c
@@ -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;
+ }
+}
diff --git a/sys/modules/Makefile b/sys/modules/Makefile
index 5f4cdcd4c3d..62828311999 100644
--- a/sys/modules/Makefile
+++ b/sys/modules/Makefile
@@ -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
diff --git a/sys/modules/amdtemp/Makefile b/sys/modules/amdtemp/Makefile
new file mode 100644
index 00000000000..79751f4d4e1
--- /dev/null
+++ b/sys/modules/amdtemp/Makefile
@@ -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>
diff --git a/sys/modules/amdtemp/amdtemp.ioconf b/sys/modules/amdtemp/amdtemp.ioconf
new file mode 100644
index 00000000000..4da00656d8f
--- /dev/null
+++ b/sys/modules/amdtemp/amdtemp.ioconf
@@ -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 ?