Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev Modularize the spdmem(4) driver
details: https://anonhg.NetBSD.org/src/rev/5094a6c6a616
branches: trunk
changeset: 767831:5094a6c6a616
user: pgoyette <pgoyette%NetBSD.org@localhost>
date: Mon Aug 01 03:49:52 2011 +0000
description:
Modularize the spdmem(4) driver
diffstat:
sys/dev/i2c/spdmem_i2c.c | 54 ++++++++++++++++++++++++++++++++++----
sys/dev/ic/spdmem.c | 66 +++++++++++++++++++++++++++++------------------
sys/dev/ic/spdmemvar.h | 6 ++-
3 files changed, 92 insertions(+), 34 deletions(-)
diffs (truncated from 302 to 300 lines):
diff -r 78a971b66456 -r 5094a6c6a616 sys/dev/i2c/spdmem_i2c.c
--- a/sys/dev/i2c/spdmem_i2c.c Mon Aug 01 02:13:21 2011 +0000
+++ b/sys/dev/i2c/spdmem_i2c.c Mon Aug 01 03:49:52 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: spdmem_i2c.c,v 1.1 2010/03/24 00:31:41 pgoyette Exp $ */
+/* $NetBSD: spdmem_i2c.c,v 1.2 2011/08/01 03:49:52 pgoyette Exp $ */
/*
* Copyright (c) 2007 Nicolas Joly
@@ -35,11 +35,12 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: spdmem_i2c.c,v 1.1 2010/03/24 00:31:41 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: spdmem_i2c.c,v 1.2 2011/08/01 03:49:52 pgoyette Exp $");
#include <sys/param.h>
#include <sys/device.h>
#include <sys/endian.h>
+#include <sys/module.h>
#include <sys/sysctl.h>
#include <machine/bswap.h>
@@ -57,14 +58,16 @@
i2c_addr_t sc_addr;
};
-static int spdmem_i2c_match(device_t, cfdata_t, void *);
+static int spdmem_i2c_match(device_t, cfdata_t, void *);
static void spdmem_i2c_attach(device_t, device_t, void *);
-SYSCTL_SETUP_PROTO(sysctl_spdmem_setup);
+static int spdmem_i2c_detach(device_t, int);
+
+CFATTACH_DECL_NEW(spdmem_iic, sizeof(struct spdmem_i2c_softc),
+ spdmem_i2c_match, spdmem_i2c_attach, spdmem_i2c_detach, NULL);
static uint8_t spdmem_i2c_read(struct spdmem_softc *, uint8_t);
-CFATTACH_DECL_NEW(spdmem_iic, sizeof(struct spdmem_i2c_softc),
- spdmem_i2c_match, spdmem_i2c_attach, NULL, NULL);
+SYSCTL_SETUP_PROTO(sysctl_spdmem_setup);
static int
spdmem_i2c_match(device_t parent, cfdata_t match, void *aux)
@@ -107,6 +110,16 @@
spdmem_common_attach(&sc->sc_base, self);
}
+static int
+spdmem_i2c_detach(device_t self, int flags)
+{
+ struct spdmem_i2c_softc *sc = device_private(self);
+
+ pmf_device_deregister(self);
+
+ return spdmem_common_detach(&sc->sc_base, self);
+}
+
static uint8_t
spdmem_i2c_read(struct spdmem_softc *softc, uint8_t reg)
{
@@ -120,3 +133,32 @@
return val;
}
+
+MODULE(MODULE_CLASS_DRIVER, spdmem, NULL);
+
+#ifdef _MODULE
+#include "ioconf.c"
+#endif
+
+static int
+spdmem_modcmd(modcmd_t cmd, void *opaque)
+{
+ int error = 0;
+
+ switch (cmd) {
+ case MODULE_CMD_INIT:
+#ifdef _MODULE
+ error = config_init_component(cfdriver_ioconf_spdmem,
+ cfattach_ioconf_spdmem, cfdata_ioconf_spdmem);
+#endif
+ return error;
+ case MODULE_CMD_FINI:
+#ifdef _MODULE
+ error = config_fini_component(cfdriver_ioconf_spdmem,
+ cfattach_ioconf_spdmem, cfdata_ioconf_spdmem);
+#endif
+ return error;
+ default:
+ return ENOTTY;
+ }
+}
diff -r 78a971b66456 -r 5094a6c6a616 sys/dev/ic/spdmem.c
--- a/sys/dev/ic/spdmem.c Mon Aug 01 02:13:21 2011 +0000
+++ b/sys/dev/ic/spdmem.c Mon Aug 01 03:49:52 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: spdmem.c,v 1.2 2010/06/29 04:42:30 pgoyette Exp $ */
+/* $NetBSD: spdmem.c,v 1.3 2011/08/01 03:49:52 pgoyette Exp $ */
/*
* Copyright (c) 2007 Nicolas Joly
@@ -35,7 +35,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: spdmem.c,v 1.2 2010/06/29 04:42:30 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: spdmem.c,v 1.3 2011/08/01 03:49:52 pgoyette Exp $");
#include <sys/param.h>
#include <sys/device.h>
@@ -59,8 +59,8 @@
static void decode_ddr3(const struct sysctlnode *, device_t, struct spdmem *);
static void decode_fbdimm(const struct sysctlnode *, device_t, struct spdmem *);
-static void decode_size_speed(const struct sysctlnode *, int, int, int, int,
- bool, const char *, int);
+static void decode_size_speed(device_t, const struct sysctlnode *,
+ int, int, int, int, bool, const char *, int);
static void decode_voltage_refresh(device_t, struct spdmem *);
#define IS_RAMBUS_TYPE (s->sm_len < 4)
@@ -219,8 +219,7 @@
const char *type;
const char *rambus_rev = "Reserved";
int dimm_size;
- int i;
- unsigned int spd_len, spd_size;
+ unsigned int i, spd_len, spd_size;
const struct sysctlnode *node = NULL;
/*
@@ -262,7 +261,7 @@
#ifdef DEBUG
for (i = 0; i < spd_len; i += 16) {
- int j, k;
+ unsigned int j, k;
aprint_debug("\n");
aprint_debug_dev(self, "0x%02x:", i);
k = (spd_len > i + 16) ? spd_len : i + 16;
@@ -276,13 +275,17 @@
/*
* Setup our sysctl subtree, hw.spdmemN
*/
+ sc->sc_sysctl_log = NULL;
+#ifdef _MODULE
+ sysctl_spdmem_setup(&sc->sc_sysctl_log);
+#endif
if (hw_node != CTL_EOL)
- sysctl_createv(NULL, 0, NULL, &node,
+ sysctl_createv(&sc->sc_sysctl_log, 0, NULL, &node,
0, CTLTYPE_NODE,
device_xname(self), NULL, NULL, 0, NULL, 0,
CTL_HW, CTL_CREATE, CTL_EOL);
if (node != NULL && spd_len != 0)
- sysctl_createv(NULL, 0, NULL, NULL,
+ sysctl_createv(&sc->sc_sysctl_log, 0, NULL, NULL,
0,
CTLTYPE_STRUCT, "spd_data",
SYSCTL_DESCR("raw spd data"), NULL,
@@ -341,7 +344,7 @@
aprint_normal_dev(self, "%s", type);
strlcpy(sc->sc_type, type, SPDMEM_TYPE_MAXLEN);
if (node != NULL)
- sysctl_createv(NULL, 0, NULL, NULL,
+ sysctl_createv(&sc->sc_sysctl_log, 0, NULL, NULL,
0,
CTLTYPE_STRING, "mem_type",
SYSCTL_DESCR("memory module type"), NULL,
@@ -386,33 +389,40 @@
}
}
+int
+spdmem_common_detach(struct spdmem_softc *sc, device_t self)
+{
+ sysctl_teardown(&sc->sc_sysctl_log);
+
+ return 0;
+}
+
SYSCTL_SETUP(sysctl_spdmem_setup, "sysctl hw.spdmem subtree setup")
{
const struct sysctlnode *node;
- if (sysctl_createv(clog, 0, NULL, &node,
- CTLFLAG_PERMANENT,
- CTLTYPE_NODE, "hw", NULL,
- NULL, 0, NULL, 0,
- CTL_HW, CTL_EOL) != 0)
+ if (sysctl_createv(clog, 0, NULL, &node, CTLFLAG_PERMANENT,
+ CTLTYPE_NODE, "hw", NULL, NULL, 0, NULL, 0,
+ CTL_HW, CTL_EOL) != 0)
return;
hw_node = node->sysctl_num;
}
static void
-decode_size_speed(const struct sysctlnode *node, int dimm_size, int cycle_time,
- int d_clk, int bits, bool round, const char *ddr_type_string,
- int speed)
+decode_size_speed(device_t self, const struct sysctlnode *node,
+ int dimm_size, int cycle_time, int d_clk, int bits,
+ bool round, const char *ddr_type_string, int speed)
{
int p_clk;
+ struct spdmem_softc *sc = (struct spdmem_softc *)device_private(self);
if (dimm_size < 1024)
aprint_normal("%dMB", dimm_size);
else
aprint_normal("%dGB", dimm_size / 1024);
if (node != NULL)
- sysctl_createv(NULL, 0, NULL, NULL,
+ sysctl_createv(&sc->sc_sysctl_log, 0, NULL, NULL,
CTLFLAG_IMMEDIATE,
CTLTYPE_INT, "size",
SYSCTL_DESCR("module size in MB"), NULL,
@@ -445,7 +455,7 @@
aprint_normal(", %dMHz (%s-%d)\n",
d_clk, ddr_type_string, p_clk);
if (node != NULL)
- sysctl_createv(NULL, 0, NULL, NULL,
+ sysctl_createv(&sc->sc_sysctl_log, 0, NULL, NULL,
CTLFLAG_IMMEDIATE,
CTLTYPE_INT, "speed",
SYSCTL_DESCR("memory speed in MHz"),
@@ -530,8 +540,8 @@
default:
speed = 66;
}
- decode_size_speed(node, dimm_size, cycle_time, 1, bits, FALSE, "PC",
- speed);
+ decode_size_speed(self, node, dimm_size, cycle_time, 1, bits, FALSE,
+ "PC", speed);
aprint_verbose_dev(self,
"%d rows, %d cols, %d banks, %d banks/chip, %d.%dns cycle time\n",
@@ -568,7 +578,8 @@
bits = le16toh(s->sm_ddr.ddr_datawidth);
if (s->sm_config == 1 || s->sm_config == 2)
bits -= 8;
- decode_size_speed(node, dimm_size, cycle_time, 2, bits, TRUE, "PC", 0);
+ decode_size_speed(self, node, dimm_size, cycle_time, 2, bits, TRUE,
+ "PC", 0);
aprint_verbose_dev(self,
"%d rows, %d cols, %d ranks, %d banks/chip, %d.%dns cycle time\n",
@@ -612,7 +623,8 @@
bits = s->sm_ddr2.ddr2_datawidth;
if ((s->sm_config & 0x03) != 0)
bits -= 8;
- decode_size_speed(node, dimm_size, cycle_time, 2, bits, TRUE, "PC2", 0);
+ decode_size_speed(self, node, dimm_size, cycle_time, 2, bits, TRUE,
+ "PC2", 0);
aprint_verbose_dev(self,
"%d rows, %d cols, %d ranks, %d banks/chip, %d.%02dns cycle time\n",
@@ -666,7 +678,8 @@
s->sm_ddr3.ddr3_mtb_divisor;
cycle_time *= s->sm_ddr3.ddr3_tCKmin;
bits = 1 << (s->sm_ddr3.ddr3_datawidth + 3);
- decode_size_speed(node, dimm_size, cycle_time, 2, bits, FALSE, "PC3", 0);
+ decode_size_speed(self, node, dimm_size, cycle_time, 2, bits, FALSE,
+ "PC3", 0);
aprint_verbose_dev(self,
"%d rows, %d cols, %d log. banks, %d phys. banks, "
@@ -701,7 +714,8 @@
(s->sm_fbd.fbdimm_mtb_divisor / 2)) /
s->sm_fbd.fbdimm_mtb_divisor;
bits = 1 << (s->sm_fbd.fbdimm_dev_width + 2);
- decode_size_speed(node, dimm_size, cycle_time, 2, bits, TRUE, "PC2", 0);
+ decode_size_speed(self, node, dimm_size, cycle_time, 2, bits, TRUE,
+ "PC2", 0);
aprint_verbose_dev(self,
"%d rows, %d cols, %d banks, %d.%02dns cycle time\n",
diff -r 78a971b66456 -r 5094a6c6a616 sys/dev/ic/spdmemvar.h
--- a/sys/dev/ic/spdmemvar.h Mon Aug 01 02:13:21 2011 +0000
+++ b/sys/dev/ic/spdmemvar.h Mon Aug 01 03:49:52 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: spdmemvar.h,v 1.1 2010/03/24 00:31:41 pgoyette Exp $ */
+/* $NetBSD: spdmemvar.h,v 1.2 2011/08/01 03:49:52 pgoyette Exp $ */
/*
* Copyright (c) 2007 Paul Goyette
@@ -518,8 +518,10 @@
struct spdmem_softc {
uint8_t (*sc_read)(struct spdmem_softc *, uint8_t);
struct spdmem sc_spd_data;
+ struct sysctllog *sc_sysctl_log;
char sc_type[SPDMEM_TYPE_MAXLEN];
};
-int spdmem_common_probe(struct spdmem_softc *);
+int spdmem_common_probe(struct spdmem_softc *);
Home |
Main Index |
Thread Index |
Old Index