Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Modularize amdtemp(4).



details:   https://anonhg.NetBSD.org/src/rev/8b9ac3bfd4d1
branches:  trunk
changeset: 766076:8b9ac3bfd4d1
user:      jruoho <jruoho%NetBSD.org@localhost>
date:      Wed Jun 15 03:22:39 2011 +0000

description:
Modularize amdtemp(4).

diffstat:

 distrib/sets/lists/modules/md.amd64 |   4 +-
 distrib/sets/lists/modules/md.i386  |   4 +-
 sys/arch/x86/pci/amdtemp.c          |  79 +++++++++++++++++++++++++++++-------
 sys/modules/Makefile                |   3 +-
 sys/modules/amdtemp/Makefile        |  13 ++++++
 sys/modules/amdtemp/amdtemp.ioconf  |  11 +++++
 6 files changed, 96 insertions(+), 18 deletions(-)

diffs (248 lines):

diff -r a38f7f6ae1d4 -r 8b9ac3bfd4d1 distrib/sets/lists/modules/md.amd64
--- a/distrib/sets/lists/modules/md.amd64       Wed Jun 15 01:45:16 2011 +0000
+++ b/distrib/sets/lists/modules/md.amd64       Wed Jun 15 03:22:39 2011 +0000
@@ -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 -r a38f7f6ae1d4 -r 8b9ac3bfd4d1 distrib/sets/lists/modules/md.i386
--- a/distrib/sets/lists/modules/md.i386        Wed Jun 15 01:45:16 2011 +0000
+++ b/distrib/sets/lists/modules/md.i386        Wed Jun 15 03:22:39 2011 +0000
@@ -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 -r a38f7f6ae1d4 -r 8b9ac3bfd4d1 sys/arch/x86/pci/amdtemp.c
--- a/sys/arch/x86/pci/amdtemp.c        Wed Jun 15 01:45:16 2011 +0000
+++ b/sys/arch/x86/pci/amdtemp.c        Wed Jun 15 03:22:39 2011 +0000
@@ -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 @@
 #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 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 @@
 };
 
 
-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_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 @@
        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 @@
                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 @@
        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 @@
        /* 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 -r a38f7f6ae1d4 -r 8b9ac3bfd4d1 sys/modules/Makefile
--- a/sys/modules/Makefile      Wed Jun 15 01:45:16 2011 +0000
+++ b/sys/modules/Makefile      Wed Jun 15 03:22:39 2011 +0000
@@ -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 @@
 
 .if ${MACHINE_ARCH} == "i386" || \
     ${MACHINE_ARCH} == "x86_64"
+SUBDIR+=       amdtemp
 SUBDIR+=       coretemp
 SUBDIR+=       est
 SUBDIR+=       odcm
diff -r a38f7f6ae1d4 -r 8b9ac3bfd4d1 sys/modules/amdtemp/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/modules/amdtemp/Makefile      Wed Jun 15 03:22:39 2011 +0000
@@ -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 -r a38f7f6ae1d4 -r 8b9ac3bfd4d1 sys/modules/amdtemp/amdtemp.ioconf
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/modules/amdtemp/amdtemp.ioconf        Wed Jun 15 03:22:39 2011 +0000
@@ -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 ?



Home | Main Index | Thread Index | Old Index