Source-Changes-HG archive

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

[src/trunk]: src/sys Split spdmem driver into a bus attachment and a common b...



details:   https://anonhg.NetBSD.org/src/rev/eb6003f5e667
branches:  trunk
changeset: 753361:eb6003f5e667
user:      pgoyette <pgoyette%NetBSD.org@localhost>
date:      Wed Mar 24 00:31:41 2010 +0000

description:
Split spdmem driver into a bus attachment and a common back-end
probe and ROM decode, to follow similar changes made in OpenBSD:

        http://article.gmane.org/gmane.os.openbsd.cvs/94948
        http://article.gmane.org/gmane.os.openbsd.cvs/94956

There exists at least one alternative attachment (for SGI IP35
systems; see http://article.gmane.org/gmane.os.openbsd.cvs/94947),
and there could be more in the future.

Thanks to Christoph Egger for pointing out the OpenBSD activity.

diffstat:

 sys/conf/files           |    9 +-
 sys/dev/i2c/files.i2c    |    7 +-
 sys/dev/i2c/spdmem.c     |  770 -----------------------------------------------
 sys/dev/i2c/spdmem_i2c.c |  122 +++++++
 sys/dev/i2c/spdmemreg.h  |  105 ------
 sys/dev/i2c/spdmemvar.h  |  522 -------------------------------
 sys/dev/ic/spdmem.c      |  723 ++++++++++++++++++++++++++++++++++++++++++++
 sys/dev/ic/spdmemreg.h   |  101 ++++++
 sys/dev/ic/spdmemvar.h   |  525 ++++++++++++++++++++++++++++++++
 9 files changed, 1482 insertions(+), 1402 deletions(-)

diffs (truncated from 2940 to 300 lines):

diff -r 421a36810999 -r eb6003f5e667 sys/conf/files
--- a/sys/conf/files    Tue Mar 23 21:54:23 2010 +0000
+++ b/sys/conf/files    Wed Mar 24 00:31:41 2010 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files,v 1.983 2010/03/15 20:35:19 christos Exp $
+#      $NetBSD: files,v 1.984 2010/03/24 00:31:41 pgoyette Exp $
 #      @(#)files.newconf       7.5 (Berkeley) 5/10/93
 
 version        20090313
@@ -328,6 +328,13 @@
 device lm: sysmon_envsys
 file   dev/ic/nslm7x.c                 lm                      needs-flag
 
+# JEDEC standard SPD EPROM
+#
+# (included here so files.i2c can define an attachment)
+
+device spdmem
+file   dev/ic/spdmem.c                 spdmem
+
 # I2C device support
 include "dev/i2c/files.i2c"
 
diff -r 421a36810999 -r eb6003f5e667 sys/dev/i2c/files.i2c
--- a/sys/dev/i2c/files.i2c     Tue Mar 23 21:54:23 2010 +0000
+++ b/sys/dev/i2c/files.i2c     Wed Mar 24 00:31:41 2010 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.i2c,v 1.26 2010/02/22 03:50:56 pgoyette Exp $
+#      $NetBSD: files.i2c,v 1.27 2010/03/24 00:31:41 pgoyette Exp $
 
 defflag        opt_i2cbus.h                            I2C_SCAN
 define i2cbus { }
@@ -102,9 +102,8 @@
 file   dev/i2c/xbseeprom.c             xbseeprom
 
 # Memory Serial Presence Detect
-device spdmem
-attach spdmem at iic
-file   dev/i2c/spdmem.c                spdmem
+attach spdmem at iic with spdmem_iic
+file   dev/i2c/spdmem_i2c.c            spdmem_iic
 
 # Memory Temp Sensor
 device sdtemp: sysmon_envsys
diff -r 421a36810999 -r eb6003f5e667 sys/dev/i2c/spdmem.c
--- a/sys/dev/i2c/spdmem.c      Tue Mar 23 21:54:23 2010 +0000
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,770 +0,0 @@
-/* $NetBSD: spdmem.c,v 1.18 2010/03/23 12:13:28 njoly Exp $ */
-
-/*
- * Copyright (c) 2007 Nicolas Joly
- * Copyright (c) 2007 Paul Goyette
- * Copyright (c) 2007 Tobias Nygren
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- *    derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * Serial Presence Detect (SPD) memory identification
- */
-
-#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: spdmem.c,v 1.18 2010/03/23 12:13:28 njoly Exp $");
-
-#include <sys/param.h>
-#include <sys/device.h>
-#include <sys/endian.h>
-#include <sys/sysctl.h>
-#include <machine/bswap.h>
-
-#include <dev/i2c/i2cvar.h>
-#include <dev/i2c/spdmemreg.h>
-#include <dev/i2c/spdmemvar.h>
-
-static int spdmem_match(device_t, cfdata_t, void *);
-static void spdmem_attach(device_t, device_t, void *);
-SYSCTL_SETUP_PROTO(sysctl_spdmem_setup);
-
-static uint8_t spdmem_read(struct spdmem_softc *, uint8_t);
-
-/* Routines for decoding spd data */
-static void decode_edofpm(const struct sysctlnode *, device_t, struct spdmem *);
-static void decode_rom(const struct sysctlnode *, device_t, struct spdmem *);
-static void decode_sdram(const struct sysctlnode *, device_t, struct spdmem *,
-       int);
-static void decode_ddr(const struct sysctlnode *, device_t, struct spdmem *);
-static void decode_ddr2(const struct sysctlnode *, device_t, struct spdmem *);
-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_voltage_refresh(device_t, struct spdmem *);
-
-CFATTACH_DECL_NEW(spdmem, sizeof(struct spdmem_softc),
-    spdmem_match, spdmem_attach, NULL, NULL);
-
-#define IS_RAMBUS_TYPE (s->sm_len < 4)
-
-static const char* spdmem_basic_types[] = {
-       "unknown",
-       "FPM",
-       "EDO",
-       "Pipelined Nibble",
-       "SDRAM",
-       "ROM",
-       "DDR SGRAM",
-       "DDR SDRAM",
-       "DDR2 SDRAM",
-       "DDR2 SDRAM FB",
-       "DDR2 SDRAM FB Probe",
-       "DDR3 SDRAM"
-};
-
-static const char* spdmem_superset_types[] = {
-       "unknown",
-       "ESDRAM",
-       "DDR ESDRAM",
-       "PEM EDO",
-       "PEM SDRAM"
-};
-
-static const char* spdmem_voltage_types[] = {
-       "TTL (5V tolerant)",
-       "LvTTL (not 5V tolerant)",
-       "HSTL 1.5V",
-       "SSTL 3.3V",
-       "SSTL 2.5V",
-       "SSTL 1.8V"
-};
-
-static const char* spdmem_refresh_types[] = {
-       "15.625us",
-       "3.9us",
-       "7.8us",
-       "31.3us",
-       "62.5us",
-       "125us"
-};
-
-static const char* spdmem_parity_types[] = {
-       "no parity or ECC",
-       "data parity",
-       "data ECC",
-       "data parity and ECC",
-       "cmd/addr parity",
-       "cmd/addr/data parity",
-       "cmd/addr parity, data ECC",
-       "cmd/addr/data parity, data ECC"
-};
-
-/* Cycle time fractional values (units of .001 ns) for DDR2 SDRAM */
-static const uint16_t spdmem_cycle_frac[] = {
-       0, 100, 200, 300, 400, 500, 600, 700, 800, 900,
-       250, 333, 667, 750, 999, 999
-};
-
-/* Format string for timing info */
-static const char* latency="tAA-tRCD-tRP-tRAS: %d-%d-%d-%d\n";
-
-/* sysctl stuff */
-static int hw_node = CTL_EOL;
-
-/* CRC functions used for certain memory types */
-
-static uint16_t spdcrc16 (struct spdmem_softc *sc, int count)
-{
-       uint16_t crc;
-       int i, j;
-       uint8_t val;
-       crc = 0;
-       for (j = 0; j <= count; j++) {
-               val = spdmem_read(sc, j);
-               crc = crc ^ val << 8;
-               for (i = 0; i < 8; ++i)
-                       if (crc & 0x8000)
-                               crc = crc << 1 ^ 0x1021;
-                       else
-                               crc = crc << 1;
-       }
-       return (crc & 0xFFFF);
-}
-
-static int
-spdmem_match(device_t parent, cfdata_t match, void *aux)
-{
-       struct i2c_attach_args *ia = aux;
-       struct spdmem_softc sc;
-       int cksum = 0;
-       uint8_t i, val, spd_type;
-       int spd_len, spd_crc_cover;
-       uint16_t crc_calc, crc_spd;
-
-       if (ia->ia_name) {
-               /* add other names as we find more firmware variations */
-               if (strcmp(ia->ia_name, "dimm-spd"))
-                       return 0;
-       }
-
-       /* only do this lame test when not using direct config */
-       if (ia->ia_name == NULL) {
-               if ((ia->ia_addr & SPDMEM_ADDRMASK) != SPDMEM_ADDR)
-                       return 0;
-       }
-
-       sc.sc_tag = ia->ia_tag;
-       sc.sc_addr = ia->ia_addr;
-
-       spd_type = spdmem_read(&sc, 2);
-
-       /* For older memory types, validate the checksum over 1st 63 bytes */
-       if (spd_type <= SPDMEM_MEMTYPE_DDR2SDRAM) {
-               for (i = 0; i < 63; i++)
-                       cksum += spdmem_read(&sc, i);
-
-               val = spdmem_read(&sc, 63);
-
-               if (cksum == 0 || (cksum & 0xff) != val) {
-                       aprint_debug("spd addr 0x%2x: ", sc.sc_addr);
-                       aprint_debug("spd checksum failed, calc = 0x%02x, "
-                                    "spd = 0x%02x\n", cksum, val);
-                       return 0;
-               } else
-                       return 1;
-       }
-
-       /* For DDR3 and FBDIMM, verify the CRC */
-       else if (spd_type <= SPDMEM_MEMTYPE_DDR3SDRAM) {
-               spd_len = spdmem_read(&sc, 0);
-               if (spd_len && SPDMEM_SPDCRC_116)
-                       spd_crc_cover = 116;
-               else
-                       spd_crc_cover = 125;
-               switch (spd_len & SPDMEM_SPDLEN_MASK) {
-               case SPDMEM_SPDLEN_128:
-                       spd_len = 128;
-                       break;
-               case SPDMEM_SPDLEN_176:
-                       spd_len = 176;
-                       break;
-               case SPDMEM_SPDLEN_256:
-                       spd_len = 256;
-                       break;
-               default:
-                       return 0;
-               }
-               if (spd_crc_cover > spd_len)
-                       return 0;
-               crc_calc = spdcrc16(&sc, spd_crc_cover);
-               crc_spd = spdmem_read(&sc, 127) << 8;
-               crc_spd |= spdmem_read(&sc, 126);
-               if (crc_calc != crc_spd) {
-                       aprint_debug("spd addr 0x%2x: ", sc.sc_addr);
-                       aprint_debug("crc16 failed, covers %d bytes, "
-                                    "calc = 0x%04x, spd = 0x%04x\n",
-                                    spd_crc_cover, crc_calc, crc_spd);
-                       return 0;
-               }
-               return 1;
-       }
-
-       /* For unrecognized memory types, don't match at all */
-       return 0;
-}
-
-static void
-spdmem_attach(device_t parent, device_t self, void *aux)
-{
-       struct spdmem_softc *sc = device_private(self);
-       struct i2c_attach_args *ia = aux;
-       struct spdmem *s = &(sc->sc_spd_data);
-       const char *type;
-       const char *rambus_rev = "Reserved";
-       int dimm_size;
-       int i;
-       unsigned int spd_len, spd_size;
-       const struct sysctlnode *node = NULL;



Home | Main Index | Thread Index | Old Index