spdmem.c revision 1.36 1 1.36 msaitoh /* $NetBSD: spdmem.c,v 1.36 2022/01/29 08:14:24 msaitoh Exp $ */
2 1.1 pgoyette
3 1.1 pgoyette /*
4 1.1 pgoyette * Copyright (c) 2007 Nicolas Joly
5 1.1 pgoyette * Copyright (c) 2007 Paul Goyette
6 1.1 pgoyette * Copyright (c) 2007 Tobias Nygren
7 1.1 pgoyette * All rights reserved.
8 1.1 pgoyette *
9 1.1 pgoyette * Redistribution and use in source and binary forms, with or without
10 1.1 pgoyette * modification, are permitted provided that the following conditions
11 1.1 pgoyette * are met:
12 1.1 pgoyette * 1. Redistributions of source code must retain the above copyright
13 1.1 pgoyette * notice, this list of conditions and the following disclaimer.
14 1.1 pgoyette * 2. Redistributions in binary form must reproduce the above copyright
15 1.1 pgoyette * notice, this list of conditions and the following disclaimer in the
16 1.1 pgoyette * documentation and/or other materials provided with the distribution.
17 1.1 pgoyette * 3. The name of the author may not be used to endorse or promote products
18 1.1 pgoyette * derived from this software without specific prior written permission.
19 1.1 pgoyette *
20 1.1 pgoyette * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS
21 1.1 pgoyette * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 1.1 pgoyette * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 1.1 pgoyette * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 1.1 pgoyette * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 1.1 pgoyette * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 1.1 pgoyette * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 1.1 pgoyette * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 1.1 pgoyette * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 1.1 pgoyette * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 1.1 pgoyette * POSSIBILITY OF SUCH DAMAGE.
31 1.1 pgoyette */
32 1.1 pgoyette
33 1.1 pgoyette /*
34 1.1 pgoyette * Serial Presence Detect (SPD) memory identification
35 1.1 pgoyette */
36 1.1 pgoyette
37 1.1 pgoyette #include <sys/cdefs.h>
38 1.36 msaitoh __KERNEL_RCSID(0, "$NetBSD: spdmem.c,v 1.36 2022/01/29 08:14:24 msaitoh Exp $");
39 1.1 pgoyette
40 1.1 pgoyette #include <sys/param.h>
41 1.1 pgoyette #include <sys/device.h>
42 1.1 pgoyette #include <sys/endian.h>
43 1.1 pgoyette #include <sys/sysctl.h>
44 1.1 pgoyette #include <machine/bswap.h>
45 1.1 pgoyette
46 1.1 pgoyette #include <dev/i2c/i2cvar.h>
47 1.1 pgoyette #include <dev/ic/spdmemreg.h>
48 1.1 pgoyette #include <dev/ic/spdmemvar.h>
49 1.1 pgoyette
50 1.1 pgoyette /* Routines for decoding spd data */
51 1.1 pgoyette static void decode_edofpm(const struct sysctlnode *, device_t, struct spdmem *);
52 1.1 pgoyette static void decode_rom(const struct sysctlnode *, device_t, struct spdmem *);
53 1.1 pgoyette static void decode_sdram(const struct sysctlnode *, device_t, struct spdmem *,
54 1.1 pgoyette int);
55 1.1 pgoyette static void decode_ddr(const struct sysctlnode *, device_t, struct spdmem *);
56 1.1 pgoyette static void decode_ddr2(const struct sysctlnode *, device_t, struct spdmem *);
57 1.1 pgoyette static void decode_ddr3(const struct sysctlnode *, device_t, struct spdmem *);
58 1.13 pgoyette static void decode_ddr4(const struct sysctlnode *, device_t, struct spdmem *);
59 1.1 pgoyette static void decode_fbdimm(const struct sysctlnode *, device_t, struct spdmem *);
60 1.1 pgoyette
61 1.3 pgoyette static void decode_size_speed(device_t, const struct sysctlnode *,
62 1.3 pgoyette int, int, int, int, bool, const char *, int);
63 1.1 pgoyette static void decode_voltage_refresh(device_t, struct spdmem *);
64 1.1 pgoyette
65 1.1 pgoyette #define IS_RAMBUS_TYPE (s->sm_len < 4)
66 1.1 pgoyette
67 1.12 matt static const char* const spdmem_basic_types[] = {
68 1.1 pgoyette "unknown",
69 1.1 pgoyette "FPM",
70 1.1 pgoyette "EDO",
71 1.1 pgoyette "Pipelined Nibble",
72 1.1 pgoyette "SDRAM",
73 1.1 pgoyette "ROM",
74 1.1 pgoyette "DDR SGRAM",
75 1.1 pgoyette "DDR SDRAM",
76 1.1 pgoyette "DDR2 SDRAM",
77 1.1 pgoyette "DDR2 SDRAM FB",
78 1.1 pgoyette "DDR2 SDRAM FB Probe",
79 1.12 matt "DDR3 SDRAM",
80 1.20 msaitoh "DDR4 SDRAM",
81 1.20 msaitoh "unknown",
82 1.20 msaitoh "DDR4E SDRAM",
83 1.20 msaitoh "LPDDR3 SDRAM",
84 1.20 msaitoh "LPDDR4 SDRAM"
85 1.36 msaitoh "LPDDR4X SDRAM",
86 1.36 msaitoh "DDR5 SDRAM",
87 1.1 pgoyette };
88 1.1 pgoyette
89 1.13 pgoyette static const char* const spdmem_ddr4_module_types[] = {
90 1.13 pgoyette "DDR4 Extended",
91 1.13 pgoyette "DDR4 RDIMM",
92 1.13 pgoyette "DDR4 UDIMM",
93 1.13 pgoyette "DDR4 SO-DIMM",
94 1.13 pgoyette "DDR4 Load-Reduced DIMM",
95 1.13 pgoyette "DDR4 Mini-RDIMM",
96 1.13 pgoyette "DDR4 Mini-UDIMM",
97 1.13 pgoyette "DDR4 Reserved",
98 1.13 pgoyette "DDR4 72Bit SO-RDIMM",
99 1.13 pgoyette "DDR4 72Bit SO-UDIMM",
100 1.13 pgoyette "DDR4 Undefined",
101 1.13 pgoyette "DDR4 Reserved",
102 1.13 pgoyette "DDR4 16Bit SO-DIMM",
103 1.13 pgoyette "DDR4 32Bit SO-DIMM",
104 1.13 pgoyette "DDR4 Reserved",
105 1.13 pgoyette "DDR4 Undefined"
106 1.13 pgoyette };
107 1.13 pgoyette
108 1.12 matt static const char* const spdmem_superset_types[] = {
109 1.1 pgoyette "unknown",
110 1.1 pgoyette "ESDRAM",
111 1.1 pgoyette "DDR ESDRAM",
112 1.1 pgoyette "PEM EDO",
113 1.1 pgoyette "PEM SDRAM"
114 1.1 pgoyette };
115 1.1 pgoyette
116 1.12 matt static const char* const spdmem_voltage_types[] = {
117 1.1 pgoyette "TTL (5V tolerant)",
118 1.1 pgoyette "LvTTL (not 5V tolerant)",
119 1.1 pgoyette "HSTL 1.5V",
120 1.1 pgoyette "SSTL 3.3V",
121 1.1 pgoyette "SSTL 2.5V",
122 1.1 pgoyette "SSTL 1.8V"
123 1.1 pgoyette };
124 1.1 pgoyette
125 1.12 matt static const char* const spdmem_refresh_types[] = {
126 1.1 pgoyette "15.625us",
127 1.1 pgoyette "3.9us",
128 1.1 pgoyette "7.8us",
129 1.1 pgoyette "31.3us",
130 1.1 pgoyette "62.5us",
131 1.1 pgoyette "125us"
132 1.1 pgoyette };
133 1.1 pgoyette
134 1.12 matt static const char* const spdmem_parity_types[] = {
135 1.1 pgoyette "no parity or ECC",
136 1.1 pgoyette "data parity",
137 1.1 pgoyette "data ECC",
138 1.1 pgoyette "data parity and ECC",
139 1.1 pgoyette "cmd/addr parity",
140 1.1 pgoyette "cmd/addr/data parity",
141 1.1 pgoyette "cmd/addr parity, data ECC",
142 1.1 pgoyette "cmd/addr/data parity, data ECC"
143 1.1 pgoyette };
144 1.1 pgoyette
145 1.13 pgoyette int spd_rom_sizes[] = { 0, 128, 256, 384, 512 };
146 1.13 pgoyette
147 1.13 pgoyette
148 1.1 pgoyette /* Cycle time fractional values (units of .001 ns) for DDR2 SDRAM */
149 1.1 pgoyette static const uint16_t spdmem_cycle_frac[] = {
150 1.1 pgoyette 0, 100, 200, 300, 400, 500, 600, 700, 800, 900,
151 1.1 pgoyette 250, 333, 667, 750, 999, 999
152 1.1 pgoyette };
153 1.1 pgoyette
154 1.1 pgoyette /* Format string for timing info */
155 1.5 wiz #define LATENCY "tAA-tRCD-tRP-tRAS: %d-%d-%d-%d\n"
156 1.1 pgoyette
157 1.1 pgoyette /* CRC functions used for certain memory types */
158 1.1 pgoyette
159 1.21 msaitoh static uint16_t
160 1.21 msaitoh spdcrc16(struct spdmem_softc *sc, int count)
161 1.1 pgoyette {
162 1.1 pgoyette uint16_t crc;
163 1.1 pgoyette int i, j;
164 1.1 pgoyette uint8_t val;
165 1.1 pgoyette crc = 0;
166 1.1 pgoyette for (j = 0; j <= count; j++) {
167 1.21 msaitoh (sc->sc_read)(sc, j, &val);
168 1.1 pgoyette crc = crc ^ val << 8;
169 1.1 pgoyette for (i = 0; i < 8; ++i)
170 1.1 pgoyette if (crc & 0x8000)
171 1.1 pgoyette crc = crc << 1 ^ 0x1021;
172 1.1 pgoyette else
173 1.1 pgoyette crc = crc << 1;
174 1.1 pgoyette }
175 1.1 pgoyette return (crc & 0xFFFF);
176 1.1 pgoyette }
177 1.1 pgoyette
178 1.1 pgoyette int
179 1.1 pgoyette spdmem_common_probe(struct spdmem_softc *sc)
180 1.1 pgoyette {
181 1.1 pgoyette int cksum = 0;
182 1.1 pgoyette uint8_t i, val, spd_type;
183 1.1 pgoyette int spd_len, spd_crc_cover;
184 1.1 pgoyette uint16_t crc_calc, crc_spd;
185 1.1 pgoyette
186 1.21 msaitoh /* Read failed means a device doesn't exist */
187 1.21 msaitoh if ((sc->sc_read)(sc, 2, &spd_type) != 0)
188 1.21 msaitoh return 0;
189 1.1 pgoyette
190 1.22 msaitoh /* Memory type should not be 0 */
191 1.22 msaitoh if (spd_type == 0x00)
192 1.22 msaitoh return 0;
193 1.22 msaitoh
194 1.1 pgoyette /* For older memory types, validate the checksum over 1st 63 bytes */
195 1.1 pgoyette if (spd_type <= SPDMEM_MEMTYPE_DDR2SDRAM) {
196 1.21 msaitoh for (i = 0; i < 63; i++) {
197 1.21 msaitoh (sc->sc_read)(sc, i, &val);
198 1.21 msaitoh cksum += val;
199 1.21 msaitoh }
200 1.1 pgoyette
201 1.21 msaitoh (sc->sc_read)(sc, 63, &val);
202 1.1 pgoyette
203 1.21 msaitoh if ((cksum & 0xff) != val) {
204 1.1 pgoyette aprint_debug("spd checksum failed, calc = 0x%02x, "
205 1.1 pgoyette "spd = 0x%02x\n", cksum, val);
206 1.1 pgoyette return 0;
207 1.1 pgoyette } else
208 1.1 pgoyette return 1;
209 1.1 pgoyette }
210 1.1 pgoyette
211 1.1 pgoyette /* For DDR3 and FBDIMM, verify the CRC */
212 1.1 pgoyette else if (spd_type <= SPDMEM_MEMTYPE_DDR3SDRAM) {
213 1.21 msaitoh (sc->sc_read)(sc, 0, &val);
214 1.21 msaitoh spd_len = val;
215 1.2 pgoyette if (spd_len & SPDMEM_SPDCRC_116)
216 1.1 pgoyette spd_crc_cover = 116;
217 1.1 pgoyette else
218 1.1 pgoyette spd_crc_cover = 125;
219 1.1 pgoyette switch (spd_len & SPDMEM_SPDLEN_MASK) {
220 1.1 pgoyette case SPDMEM_SPDLEN_128:
221 1.1 pgoyette spd_len = 128;
222 1.1 pgoyette break;
223 1.1 pgoyette case SPDMEM_SPDLEN_176:
224 1.1 pgoyette spd_len = 176;
225 1.1 pgoyette break;
226 1.1 pgoyette case SPDMEM_SPDLEN_256:
227 1.1 pgoyette spd_len = 256;
228 1.1 pgoyette break;
229 1.1 pgoyette default:
230 1.1 pgoyette return 0;
231 1.1 pgoyette }
232 1.1 pgoyette if (spd_crc_cover > spd_len)
233 1.1 pgoyette return 0;
234 1.1 pgoyette crc_calc = spdcrc16(sc, spd_crc_cover);
235 1.21 msaitoh (sc->sc_read)(sc, 127, &val);
236 1.21 msaitoh crc_spd = val << 8;
237 1.21 msaitoh (sc->sc_read)(sc, 126, &val);
238 1.21 msaitoh crc_spd |= val;
239 1.1 pgoyette if (crc_calc != crc_spd) {
240 1.1 pgoyette aprint_debug("crc16 failed, covers %d bytes, "
241 1.1 pgoyette "calc = 0x%04x, spd = 0x%04x\n",
242 1.1 pgoyette spd_crc_cover, crc_calc, crc_spd);
243 1.1 pgoyette return 0;
244 1.1 pgoyette }
245 1.1 pgoyette return 1;
246 1.13 pgoyette } else if (spd_type == SPDMEM_MEMTYPE_DDR4SDRAM) {
247 1.21 msaitoh (sc->sc_read)(sc, 0, &val);
248 1.21 msaitoh spd_len = val & 0x0f;
249 1.23 maya if ((unsigned int)spd_len >= __arraycount(spd_rom_sizes))
250 1.13 pgoyette return 0;
251 1.13 pgoyette spd_len = spd_rom_sizes[spd_len];
252 1.17 msaitoh spd_crc_cover = 125; /* For byte 0 to 125 */
253 1.13 pgoyette if (spd_crc_cover > spd_len)
254 1.13 pgoyette return 0;
255 1.13 pgoyette crc_calc = spdcrc16(sc, spd_crc_cover);
256 1.21 msaitoh (sc->sc_read)(sc, 127, &val);
257 1.21 msaitoh crc_spd = val << 8;
258 1.21 msaitoh (sc->sc_read)(sc, 126, &val);
259 1.21 msaitoh crc_spd |= val;
260 1.13 pgoyette if (crc_calc != crc_spd) {
261 1.13 pgoyette aprint_debug("crc16 failed, covers %d bytes, "
262 1.13 pgoyette "calc = 0x%04x, spd = 0x%04x\n",
263 1.13 pgoyette spd_crc_cover, crc_calc, crc_spd);
264 1.13 pgoyette return 0;
265 1.13 pgoyette }
266 1.13 pgoyette /*
267 1.13 pgoyette * We probably could also verify the CRC for the other
268 1.13 pgoyette * "pages" of SPD data in blocks 1 and 2, but we'll do
269 1.13 pgoyette * it some other time.
270 1.13 pgoyette */
271 1.13 pgoyette return 1;
272 1.22 msaitoh }
273 1.1 pgoyette
274 1.1 pgoyette /* For unrecognized memory types, don't match at all */
275 1.1 pgoyette return 0;
276 1.1 pgoyette }
277 1.1 pgoyette
278 1.1 pgoyette void
279 1.1 pgoyette spdmem_common_attach(struct spdmem_softc *sc, device_t self)
280 1.1 pgoyette {
281 1.1 pgoyette struct spdmem *s = &(sc->sc_spd_data);
282 1.1 pgoyette const char *type;
283 1.1 pgoyette const char *rambus_rev = "Reserved";
284 1.1 pgoyette int dimm_size;
285 1.3 pgoyette unsigned int i, spd_len, spd_size;
286 1.1 pgoyette const struct sysctlnode *node = NULL;
287 1.1 pgoyette
288 1.21 msaitoh (sc->sc_read)(sc, 0, &s->sm_len);
289 1.21 msaitoh (sc->sc_read)(sc, 1, &s->sm_size);
290 1.21 msaitoh (sc->sc_read)(sc, 2, &s->sm_type);
291 1.1 pgoyette
292 1.13 pgoyette if (s->sm_type == SPDMEM_MEMTYPE_DDR4SDRAM) {
293 1.13 pgoyette /*
294 1.13 pgoyette * An even newer encoding with one byte holding both
295 1.13 pgoyette * the used-size and capacity values
296 1.13 pgoyette */
297 1.13 pgoyette spd_len = s->sm_len & 0x0f;
298 1.13 pgoyette spd_size = (s->sm_len >> 4) & 0x07;
299 1.13 pgoyette
300 1.13 pgoyette spd_len = spd_rom_sizes[spd_len];
301 1.13 pgoyette spd_size *= 512;
302 1.13 pgoyette
303 1.13 pgoyette } else if (s->sm_type >= SPDMEM_MEMTYPE_FBDIMM) {
304 1.13 pgoyette /*
305 1.13 pgoyette * FBDIMM and DDR3 (and probably all newer) have a different
306 1.13 pgoyette * encoding of the SPD EEPROM used/total sizes
307 1.13 pgoyette */
308 1.1 pgoyette spd_size = 64 << (s->sm_len & SPDMEM_SPDSIZE_MASK);
309 1.1 pgoyette switch (s->sm_len & SPDMEM_SPDLEN_MASK) {
310 1.1 pgoyette case SPDMEM_SPDLEN_128:
311 1.1 pgoyette spd_len = 128;
312 1.1 pgoyette break;
313 1.1 pgoyette case SPDMEM_SPDLEN_176:
314 1.1 pgoyette spd_len = 176;
315 1.1 pgoyette break;
316 1.1 pgoyette case SPDMEM_SPDLEN_256:
317 1.1 pgoyette spd_len = 256;
318 1.1 pgoyette break;
319 1.1 pgoyette default:
320 1.1 pgoyette spd_len = 64;
321 1.1 pgoyette break;
322 1.1 pgoyette }
323 1.1 pgoyette } else {
324 1.1 pgoyette spd_size = 1 << s->sm_size;
325 1.1 pgoyette spd_len = s->sm_len;
326 1.1 pgoyette if (spd_len < 64)
327 1.1 pgoyette spd_len = 64;
328 1.1 pgoyette }
329 1.1 pgoyette if (spd_len > spd_size)
330 1.1 pgoyette spd_len = spd_size;
331 1.1 pgoyette if (spd_len > sizeof(struct spdmem))
332 1.1 pgoyette spd_len = sizeof(struct spdmem);
333 1.1 pgoyette for (i = 3; i < spd_len; i++)
334 1.21 msaitoh (sc->sc_read)(sc, i, &((uint8_t *)s)[i]);
335 1.1 pgoyette
336 1.1 pgoyette /*
337 1.1 pgoyette * Setup our sysctl subtree, hw.spdmemN
338 1.1 pgoyette */
339 1.3 pgoyette sc->sc_sysctl_log = NULL;
340 1.9 pooka sysctl_createv(&sc->sc_sysctl_log, 0, NULL, &node,
341 1.9 pooka 0, CTLTYPE_NODE,
342 1.9 pooka device_xname(self), NULL, NULL, 0, NULL, 0,
343 1.9 pooka CTL_HW, CTL_CREATE, CTL_EOL);
344 1.1 pgoyette if (node != NULL && spd_len != 0)
345 1.33 msaitoh sysctl_createv(&sc->sc_sysctl_log, 0, NULL, NULL,
346 1.33 msaitoh 0,
347 1.33 msaitoh CTLTYPE_STRUCT, "spd_data",
348 1.1 pgoyette SYSCTL_DESCR("raw spd data"), NULL,
349 1.33 msaitoh 0, s, spd_len,
350 1.33 msaitoh CTL_HW, node->sysctl_num, CTL_CREATE, CTL_EOL);
351 1.1 pgoyette
352 1.1 pgoyette /*
353 1.1 pgoyette * Decode and print key SPD contents
354 1.1 pgoyette */
355 1.1 pgoyette if (IS_RAMBUS_TYPE) {
356 1.1 pgoyette if (s->sm_type == SPDMEM_MEMTYPE_RAMBUS)
357 1.1 pgoyette type = "Rambus";
358 1.1 pgoyette else if (s->sm_type == SPDMEM_MEMTYPE_DIRECTRAMBUS)
359 1.1 pgoyette type = "Direct Rambus";
360 1.1 pgoyette else
361 1.1 pgoyette type = "Rambus (unknown)";
362 1.1 pgoyette
363 1.1 pgoyette switch (s->sm_len) {
364 1.1 pgoyette case 0:
365 1.1 pgoyette rambus_rev = "Invalid";
366 1.1 pgoyette break;
367 1.1 pgoyette case 1:
368 1.1 pgoyette rambus_rev = "0.7";
369 1.1 pgoyette break;
370 1.1 pgoyette case 2:
371 1.1 pgoyette rambus_rev = "1.0";
372 1.1 pgoyette break;
373 1.1 pgoyette default:
374 1.1 pgoyette rambus_rev = "Reserved";
375 1.1 pgoyette break;
376 1.1 pgoyette }
377 1.1 pgoyette } else {
378 1.1 pgoyette if (s->sm_type < __arraycount(spdmem_basic_types))
379 1.1 pgoyette type = spdmem_basic_types[s->sm_type];
380 1.1 pgoyette else
381 1.1 pgoyette type = "unknown memory type";
382 1.1 pgoyette
383 1.1 pgoyette if (s->sm_type == SPDMEM_MEMTYPE_EDO &&
384 1.1 pgoyette s->sm_fpm.fpm_superset == SPDMEM_SUPERSET_EDO_PEM)
385 1.1 pgoyette type = spdmem_superset_types[SPDMEM_SUPERSET_EDO_PEM];
386 1.1 pgoyette if (s->sm_type == SPDMEM_MEMTYPE_SDRAM &&
387 1.1 pgoyette s->sm_sdr.sdr_superset == SPDMEM_SUPERSET_SDRAM_PEM)
388 1.1 pgoyette type = spdmem_superset_types[SPDMEM_SUPERSET_SDRAM_PEM];
389 1.1 pgoyette if (s->sm_type == SPDMEM_MEMTYPE_DDRSDRAM &&
390 1.1 pgoyette s->sm_ddr.ddr_superset == SPDMEM_SUPERSET_DDR_ESDRAM)
391 1.1 pgoyette type =
392 1.1 pgoyette spdmem_superset_types[SPDMEM_SUPERSET_DDR_ESDRAM];
393 1.1 pgoyette if (s->sm_type == SPDMEM_MEMTYPE_SDRAM &&
394 1.1 pgoyette s->sm_sdr.sdr_superset == SPDMEM_SUPERSET_ESDRAM) {
395 1.1 pgoyette type = spdmem_superset_types[SPDMEM_SUPERSET_ESDRAM];
396 1.1 pgoyette }
397 1.13 pgoyette if (s->sm_type == SPDMEM_MEMTYPE_DDR4SDRAM &&
398 1.13 pgoyette s->sm_ddr4.ddr4_mod_type <
399 1.13 pgoyette __arraycount(spdmem_ddr4_module_types)) {
400 1.13 pgoyette type = spdmem_ddr4_module_types[s->sm_ddr4.ddr4_mod_type];
401 1.13 pgoyette }
402 1.1 pgoyette }
403 1.1 pgoyette
404 1.1 pgoyette strlcpy(sc->sc_type, type, SPDMEM_TYPE_MAXLEN);
405 1.20 msaitoh
406 1.20 msaitoh if (s->sm_type == SPDMEM_MEMTYPE_DDR4SDRAM) {
407 1.20 msaitoh /*
408 1.20 msaitoh * The latest spec (DDR4 SPD Document Release 3) defines
409 1.20 msaitoh * NVDIMM Hybrid only.
410 1.20 msaitoh */
411 1.20 msaitoh if ((s->sm_ddr4.ddr4_hybrid)
412 1.20 msaitoh && (s->sm_ddr4.ddr4_hybrid_media == 1))
413 1.20 msaitoh strlcat(sc->sc_type, " NVDIMM hybrid",
414 1.20 msaitoh SPDMEM_TYPE_MAXLEN);
415 1.20 msaitoh }
416 1.33 msaitoh
417 1.1 pgoyette if (node != NULL)
418 1.3 pgoyette sysctl_createv(&sc->sc_sysctl_log, 0, NULL, NULL,
419 1.1 pgoyette 0,
420 1.1 pgoyette CTLTYPE_STRING, "mem_type",
421 1.1 pgoyette SYSCTL_DESCR("memory module type"), NULL,
422 1.1 pgoyette 0, sc->sc_type, 0,
423 1.1 pgoyette CTL_HW, node->sysctl_num, CTL_CREATE, CTL_EOL);
424 1.1 pgoyette
425 1.1 pgoyette if (IS_RAMBUS_TYPE) {
426 1.8 soren aprint_naive("\n");
427 1.8 soren aprint_normal("\n");
428 1.8 soren aprint_normal_dev(self, "%s, SPD Revision %s", type, rambus_rev);
429 1.1 pgoyette dimm_size = 1 << (s->sm_rdr.rdr_rows + s->sm_rdr.rdr_cols - 13);
430 1.1 pgoyette if (dimm_size >= 1024)
431 1.1 pgoyette aprint_normal(", %dGB\n", dimm_size / 1024);
432 1.1 pgoyette else
433 1.1 pgoyette aprint_normal(", %dMB\n", dimm_size);
434 1.1 pgoyette
435 1.1 pgoyette /* No further decode for RAMBUS memory */
436 1.1 pgoyette return;
437 1.1 pgoyette }
438 1.1 pgoyette switch (s->sm_type) {
439 1.1 pgoyette case SPDMEM_MEMTYPE_EDO:
440 1.1 pgoyette case SPDMEM_MEMTYPE_FPM:
441 1.1 pgoyette decode_edofpm(node, self, s);
442 1.1 pgoyette break;
443 1.1 pgoyette case SPDMEM_MEMTYPE_ROM:
444 1.1 pgoyette decode_rom(node, self, s);
445 1.1 pgoyette break;
446 1.1 pgoyette case SPDMEM_MEMTYPE_SDRAM:
447 1.1 pgoyette decode_sdram(node, self, s, spd_len);
448 1.1 pgoyette break;
449 1.1 pgoyette case SPDMEM_MEMTYPE_DDRSDRAM:
450 1.1 pgoyette decode_ddr(node, self, s);
451 1.1 pgoyette break;
452 1.1 pgoyette case SPDMEM_MEMTYPE_DDR2SDRAM:
453 1.1 pgoyette decode_ddr2(node, self, s);
454 1.1 pgoyette break;
455 1.1 pgoyette case SPDMEM_MEMTYPE_DDR3SDRAM:
456 1.1 pgoyette decode_ddr3(node, self, s);
457 1.1 pgoyette break;
458 1.1 pgoyette case SPDMEM_MEMTYPE_FBDIMM:
459 1.1 pgoyette case SPDMEM_MEMTYPE_FBDIMM_PROBE:
460 1.1 pgoyette decode_fbdimm(node, self, s);
461 1.1 pgoyette break;
462 1.13 pgoyette case SPDMEM_MEMTYPE_DDR4SDRAM:
463 1.13 pgoyette decode_ddr4(node, self, s);
464 1.13 pgoyette break;
465 1.1 pgoyette }
466 1.8 soren
467 1.8 soren /* Dump SPD */
468 1.8 soren for (i = 0; i < spd_len; i += 16) {
469 1.8 soren unsigned int j, k;
470 1.8 soren aprint_debug_dev(self, "0x%02x:", i);
471 1.8 soren k = (spd_len > (i + 16)) ? i + 16 : spd_len;
472 1.8 soren for (j = i; j < k; j++)
473 1.8 soren aprint_debug(" %02x", ((uint8_t *)s)[j]);
474 1.8 soren aprint_debug("\n");
475 1.8 soren }
476 1.1 pgoyette }
477 1.1 pgoyette
478 1.3 pgoyette int
479 1.3 pgoyette spdmem_common_detach(struct spdmem_softc *sc, device_t self)
480 1.3 pgoyette {
481 1.3 pgoyette sysctl_teardown(&sc->sc_sysctl_log);
482 1.3 pgoyette
483 1.3 pgoyette return 0;
484 1.3 pgoyette }
485 1.3 pgoyette
486 1.1 pgoyette static void
487 1.3 pgoyette decode_size_speed(device_t self, const struct sysctlnode *node,
488 1.3 pgoyette int dimm_size, int cycle_time, int d_clk, int bits,
489 1.3 pgoyette bool round, const char *ddr_type_string, int speed)
490 1.1 pgoyette {
491 1.1 pgoyette int p_clk;
492 1.7 chs struct spdmem_softc *sc = device_private(self);
493 1.1 pgoyette
494 1.1 pgoyette if (dimm_size < 1024)
495 1.1 pgoyette aprint_normal("%dMB", dimm_size);
496 1.1 pgoyette else
497 1.1 pgoyette aprint_normal("%dGB", dimm_size / 1024);
498 1.1 pgoyette if (node != NULL)
499 1.3 pgoyette sysctl_createv(&sc->sc_sysctl_log, 0, NULL, NULL,
500 1.1 pgoyette CTLFLAG_IMMEDIATE,
501 1.1 pgoyette CTLTYPE_INT, "size",
502 1.1 pgoyette SYSCTL_DESCR("module size in MB"), NULL,
503 1.1 pgoyette dimm_size, NULL, 0,
504 1.1 pgoyette CTL_HW, node->sysctl_num, CTL_CREATE, CTL_EOL);
505 1.1 pgoyette
506 1.1 pgoyette if (cycle_time == 0) {
507 1.1 pgoyette aprint_normal("\n");
508 1.1 pgoyette return;
509 1.1 pgoyette }
510 1.1 pgoyette
511 1.1 pgoyette /*
512 1.1 pgoyette * Calculate p_clk first, since for DDR3 we need maximum significance.
513 1.1 pgoyette * DDR3 rating is not rounded to a multiple of 100. This results in
514 1.1 pgoyette * cycle_time of 1.5ns displayed as PC3-10666.
515 1.1 pgoyette *
516 1.1 pgoyette * For SDRAM, the speed is provided by the caller so we use it.
517 1.1 pgoyette */
518 1.1 pgoyette d_clk *= 1000 * 1000;
519 1.1 pgoyette if (speed)
520 1.1 pgoyette p_clk = speed;
521 1.1 pgoyette else
522 1.1 pgoyette p_clk = (d_clk * bits) / 8 / cycle_time;
523 1.1 pgoyette d_clk = ((d_clk + cycle_time / 2) ) / cycle_time;
524 1.1 pgoyette if (round) {
525 1.1 pgoyette if ((p_clk % 100) >= 50)
526 1.1 pgoyette p_clk += 50;
527 1.1 pgoyette p_clk -= p_clk % 100;
528 1.1 pgoyette }
529 1.1 pgoyette aprint_normal(", %dMHz (%s-%d)\n",
530 1.1 pgoyette d_clk, ddr_type_string, p_clk);
531 1.1 pgoyette if (node != NULL)
532 1.3 pgoyette sysctl_createv(&sc->sc_sysctl_log, 0, NULL, NULL,
533 1.1 pgoyette CTLFLAG_IMMEDIATE,
534 1.1 pgoyette CTLTYPE_INT, "speed",
535 1.1 pgoyette SYSCTL_DESCR("memory speed in MHz"),
536 1.1 pgoyette NULL, d_clk, NULL, 0,
537 1.1 pgoyette CTL_HW, node->sysctl_num, CTL_CREATE, CTL_EOL);
538 1.1 pgoyette }
539 1.1 pgoyette
540 1.1 pgoyette static void
541 1.1 pgoyette decode_voltage_refresh(device_t self, struct spdmem *s)
542 1.1 pgoyette {
543 1.1 pgoyette const char *voltage, *refresh;
544 1.1 pgoyette
545 1.1 pgoyette if (s->sm_voltage < __arraycount(spdmem_voltage_types))
546 1.1 pgoyette voltage = spdmem_voltage_types[s->sm_voltage];
547 1.1 pgoyette else
548 1.1 pgoyette voltage = "unknown";
549 1.1 pgoyette
550 1.1 pgoyette if (s->sm_refresh < __arraycount(spdmem_refresh_types))
551 1.1 pgoyette refresh = spdmem_refresh_types[s->sm_refresh];
552 1.1 pgoyette else
553 1.1 pgoyette refresh = "unknown";
554 1.1 pgoyette
555 1.1 pgoyette aprint_verbose_dev(self, "voltage %s, refresh time %s%s\n",
556 1.1 pgoyette voltage, refresh,
557 1.1 pgoyette s->sm_selfrefresh?" (self-refreshing)":"");
558 1.1 pgoyette }
559 1.1 pgoyette
560 1.1 pgoyette static void
561 1.18 msaitoh decode_edofpm(const struct sysctlnode *node, device_t self, struct spdmem *s)
562 1.18 msaitoh {
563 1.18 msaitoh
564 1.8 soren aprint_naive("\n");
565 1.8 soren aprint_normal("\n");
566 1.8 soren aprint_normal_dev(self, "%s", spdmem_basic_types[s->sm_type]);
567 1.8 soren
568 1.1 pgoyette aprint_normal("\n");
569 1.1 pgoyette aprint_verbose_dev(self,
570 1.1 pgoyette "%d rows, %d cols, %d banks, %dns tRAC, %dns tCAC\n",
571 1.1 pgoyette s->sm_fpm.fpm_rows, s->sm_fpm.fpm_cols, s->sm_fpm.fpm_banks,
572 1.1 pgoyette s->sm_fpm.fpm_tRAC, s->sm_fpm.fpm_tCAC);
573 1.1 pgoyette }
574 1.1 pgoyette
575 1.1 pgoyette static void
576 1.18 msaitoh decode_rom(const struct sysctlnode *node, device_t self, struct spdmem *s)
577 1.18 msaitoh {
578 1.18 msaitoh
579 1.8 soren aprint_naive("\n");
580 1.8 soren aprint_normal("\n");
581 1.8 soren aprint_normal_dev(self, "%s", spdmem_basic_types[s->sm_type]);
582 1.8 soren
583 1.1 pgoyette aprint_normal("\n");
584 1.1 pgoyette aprint_verbose_dev(self, "%d rows, %d cols, %d banks\n",
585 1.1 pgoyette s->sm_rom.rom_rows, s->sm_rom.rom_cols, s->sm_rom.rom_banks);
586 1.1 pgoyette }
587 1.1 pgoyette
588 1.1 pgoyette static void
589 1.1 pgoyette decode_sdram(const struct sysctlnode *node, device_t self, struct spdmem *s,
590 1.18 msaitoh int spd_len)
591 1.18 msaitoh {
592 1.1 pgoyette int dimm_size, cycle_time, bits, tAA, i, speed, freq;
593 1.1 pgoyette
594 1.8 soren aprint_naive("\n");
595 1.8 soren aprint_normal("\n");
596 1.8 soren aprint_normal_dev(self, "%s", spdmem_basic_types[s->sm_type]);
597 1.8 soren
598 1.1 pgoyette aprint_normal("%s, %s, ",
599 1.1 pgoyette (s->sm_sdr.sdr_mod_attrs & SPDMEM_SDR_MASK_REG)?
600 1.1 pgoyette " (registered)":"",
601 1.1 pgoyette (s->sm_config < __arraycount(spdmem_parity_types))?
602 1.1 pgoyette spdmem_parity_types[s->sm_config]:"invalid parity");
603 1.1 pgoyette
604 1.1 pgoyette dimm_size = 1 << (s->sm_sdr.sdr_rows + s->sm_sdr.sdr_cols - 17);
605 1.1 pgoyette dimm_size *= s->sm_sdr.sdr_banks * s->sm_sdr.sdr_banks_per_chip;
606 1.1 pgoyette
607 1.1 pgoyette cycle_time = s->sm_sdr.sdr_cycle_whole * 1000 +
608 1.1 pgoyette s->sm_sdr.sdr_cycle_tenths * 100;
609 1.1 pgoyette bits = le16toh(s->sm_sdr.sdr_datawidth);
610 1.1 pgoyette if (s->sm_config == 1 || s->sm_config == 2)
611 1.1 pgoyette bits -= 8;
612 1.1 pgoyette
613 1.1 pgoyette /* Calculate speed here - from OpenBSD */
614 1.1 pgoyette if (spd_len >= 128)
615 1.1 pgoyette freq = ((uint8_t *)s)[126];
616 1.1 pgoyette else
617 1.1 pgoyette freq = 0;
618 1.1 pgoyette switch (freq) {
619 1.1 pgoyette /*
620 1.33 msaitoh * Must check cycle time since some PC-133 DIMMs
621 1.1 pgoyette * actually report PC-100
622 1.1 pgoyette */
623 1.1 pgoyette case 100:
624 1.1 pgoyette case 133:
625 1.1 pgoyette if (cycle_time < 8000)
626 1.1 pgoyette speed = 133;
627 1.1 pgoyette else
628 1.1 pgoyette speed = 100;
629 1.1 pgoyette break;
630 1.1 pgoyette case 0x66: /* Legacy DIMMs use _hex_ 66! */
631 1.1 pgoyette default:
632 1.1 pgoyette speed = 66;
633 1.1 pgoyette }
634 1.3 pgoyette decode_size_speed(self, node, dimm_size, cycle_time, 1, bits, FALSE,
635 1.3 pgoyette "PC", speed);
636 1.1 pgoyette
637 1.1 pgoyette aprint_verbose_dev(self,
638 1.1 pgoyette "%d rows, %d cols, %d banks, %d banks/chip, %d.%dns cycle time\n",
639 1.1 pgoyette s->sm_sdr.sdr_rows, s->sm_sdr.sdr_cols, s->sm_sdr.sdr_banks,
640 1.1 pgoyette s->sm_sdr.sdr_banks_per_chip, cycle_time/1000,
641 1.1 pgoyette (cycle_time % 1000) / 100);
642 1.1 pgoyette
643 1.1 pgoyette tAA = 0;
644 1.1 pgoyette for (i = 0; i < 8; i++)
645 1.1 pgoyette if (s->sm_sdr.sdr_tCAS & (1 << i))
646 1.1 pgoyette tAA = i;
647 1.1 pgoyette tAA++;
648 1.4 christos aprint_verbose_dev(self, LATENCY, tAA, s->sm_sdr.sdr_tRCD,
649 1.1 pgoyette s->sm_sdr.sdr_tRP, s->sm_sdr.sdr_tRAS);
650 1.1 pgoyette
651 1.1 pgoyette decode_voltage_refresh(self, s);
652 1.1 pgoyette }
653 1.1 pgoyette
654 1.1 pgoyette static void
655 1.18 msaitoh decode_ddr(const struct sysctlnode *node, device_t self, struct spdmem *s)
656 1.18 msaitoh {
657 1.1 pgoyette int dimm_size, cycle_time, bits, tAA, i;
658 1.1 pgoyette
659 1.8 soren aprint_naive("\n");
660 1.8 soren aprint_normal("\n");
661 1.8 soren aprint_normal_dev(self, "%s", spdmem_basic_types[s->sm_type]);
662 1.8 soren
663 1.1 pgoyette aprint_normal("%s, %s, ",
664 1.1 pgoyette (s->sm_ddr.ddr_mod_attrs & SPDMEM_DDR_MASK_REG)?
665 1.1 pgoyette " (registered)":"",
666 1.1 pgoyette (s->sm_config < __arraycount(spdmem_parity_types))?
667 1.1 pgoyette spdmem_parity_types[s->sm_config]:"invalid parity");
668 1.1 pgoyette
669 1.1 pgoyette dimm_size = 1 << (s->sm_ddr.ddr_rows + s->sm_ddr.ddr_cols - 17);
670 1.1 pgoyette dimm_size *= s->sm_ddr.ddr_ranks * s->sm_ddr.ddr_banks_per_chip;
671 1.1 pgoyette
672 1.1 pgoyette cycle_time = s->sm_ddr.ddr_cycle_whole * 1000 +
673 1.1 pgoyette spdmem_cycle_frac[s->sm_ddr.ddr_cycle_tenths];
674 1.1 pgoyette bits = le16toh(s->sm_ddr.ddr_datawidth);
675 1.1 pgoyette if (s->sm_config == 1 || s->sm_config == 2)
676 1.1 pgoyette bits -= 8;
677 1.3 pgoyette decode_size_speed(self, node, dimm_size, cycle_time, 2, bits, TRUE,
678 1.3 pgoyette "PC", 0);
679 1.1 pgoyette
680 1.1 pgoyette aprint_verbose_dev(self,
681 1.1 pgoyette "%d rows, %d cols, %d ranks, %d banks/chip, %d.%dns cycle time\n",
682 1.1 pgoyette s->sm_ddr.ddr_rows, s->sm_ddr.ddr_cols, s->sm_ddr.ddr_ranks,
683 1.1 pgoyette s->sm_ddr.ddr_banks_per_chip, cycle_time/1000,
684 1.1 pgoyette (cycle_time % 1000 + 50) / 100);
685 1.1 pgoyette
686 1.1 pgoyette tAA = 0;
687 1.1 pgoyette for (i = 2; i < 8; i++)
688 1.1 pgoyette if (s->sm_ddr.ddr_tCAS & (1 << i))
689 1.1 pgoyette tAA = i;
690 1.1 pgoyette tAA /= 2;
691 1.1 pgoyette
692 1.1 pgoyette #define __DDR_ROUND(scale, field) \
693 1.1 pgoyette ((scale * s->sm_ddr.field + cycle_time - 1) / cycle_time)
694 1.1 pgoyette
695 1.4 christos aprint_verbose_dev(self, LATENCY, tAA, __DDR_ROUND(250, ddr_tRCD),
696 1.1 pgoyette __DDR_ROUND(250, ddr_tRP), __DDR_ROUND(1000, ddr_tRAS));
697 1.1 pgoyette
698 1.1 pgoyette #undef __DDR_ROUND
699 1.1 pgoyette
700 1.1 pgoyette decode_voltage_refresh(self, s);
701 1.1 pgoyette }
702 1.1 pgoyette
703 1.1 pgoyette static void
704 1.18 msaitoh decode_ddr2(const struct sysctlnode *node, device_t self, struct spdmem *s)
705 1.18 msaitoh {
706 1.1 pgoyette int dimm_size, cycle_time, bits, tAA, i;
707 1.1 pgoyette
708 1.8 soren aprint_naive("\n");
709 1.8 soren aprint_normal("\n");
710 1.8 soren aprint_normal_dev(self, "%s", spdmem_basic_types[s->sm_type]);
711 1.8 soren
712 1.1 pgoyette aprint_normal("%s, %s, ",
713 1.1 pgoyette (s->sm_ddr2.ddr2_mod_attrs & SPDMEM_DDR2_MASK_REG)?
714 1.1 pgoyette " (registered)":"",
715 1.1 pgoyette (s->sm_config < __arraycount(spdmem_parity_types))?
716 1.1 pgoyette spdmem_parity_types[s->sm_config]:"invalid parity");
717 1.1 pgoyette
718 1.1 pgoyette dimm_size = 1 << (s->sm_ddr2.ddr2_rows + s->sm_ddr2.ddr2_cols - 17);
719 1.1 pgoyette dimm_size *= (s->sm_ddr2.ddr2_ranks + 1) *
720 1.1 pgoyette s->sm_ddr2.ddr2_banks_per_chip;
721 1.1 pgoyette
722 1.1 pgoyette cycle_time = s->sm_ddr2.ddr2_cycle_whole * 1000 +
723 1.1 pgoyette spdmem_cycle_frac[s->sm_ddr2.ddr2_cycle_frac];
724 1.1 pgoyette bits = s->sm_ddr2.ddr2_datawidth;
725 1.1 pgoyette if ((s->sm_config & 0x03) != 0)
726 1.1 pgoyette bits -= 8;
727 1.3 pgoyette decode_size_speed(self, node, dimm_size, cycle_time, 2, bits, TRUE,
728 1.3 pgoyette "PC2", 0);
729 1.1 pgoyette
730 1.1 pgoyette aprint_verbose_dev(self,
731 1.1 pgoyette "%d rows, %d cols, %d ranks, %d banks/chip, %d.%02dns cycle time\n",
732 1.1 pgoyette s->sm_ddr2.ddr2_rows, s->sm_ddr2.ddr2_cols,
733 1.1 pgoyette s->sm_ddr2.ddr2_ranks + 1, s->sm_ddr2.ddr2_banks_per_chip,
734 1.1 pgoyette cycle_time / 1000, (cycle_time % 1000 + 5) /10 );
735 1.1 pgoyette
736 1.1 pgoyette tAA = 0;
737 1.1 pgoyette for (i = 2; i < 8; i++)
738 1.1 pgoyette if (s->sm_ddr2.ddr2_tCAS & (1 << i))
739 1.1 pgoyette tAA = i;
740 1.1 pgoyette
741 1.1 pgoyette #define __DDR2_ROUND(scale, field) \
742 1.1 pgoyette ((scale * s->sm_ddr2.field + cycle_time - 1) / cycle_time)
743 1.1 pgoyette
744 1.4 christos aprint_verbose_dev(self, LATENCY, tAA, __DDR2_ROUND(250, ddr2_tRCD),
745 1.1 pgoyette __DDR2_ROUND(250, ddr2_tRP), __DDR2_ROUND(1000, ddr2_tRAS));
746 1.1 pgoyette
747 1.1 pgoyette #undef __DDR_ROUND
748 1.1 pgoyette
749 1.1 pgoyette decode_voltage_refresh(self, s);
750 1.1 pgoyette }
751 1.1 pgoyette
752 1.1 pgoyette static void
753 1.26 christos print_part(const char *part, size_t pnsize)
754 1.18 msaitoh {
755 1.27 christos const char *p = memchr(part, ' ', pnsize);
756 1.27 christos if (p == NULL)
757 1.27 christos p = part + pnsize;
758 1.27 christos aprint_normal(": %.*s\n", (int)(p - part), part);
759 1.26 christos }
760 1.26 christos
761 1.34 msaitoh static u_int
762 1.34 msaitoh ddr3_value_pico(struct spdmem *s, uint8_t txx_mtb, uint8_t txx_ftb)
763 1.34 msaitoh {
764 1.34 msaitoh u_int mtb, ftb; /* in picoseconds */
765 1.34 msaitoh intmax_t signed_txx_ftb;
766 1.34 msaitoh u_int val;
767 1.34 msaitoh
768 1.34 msaitoh mtb = (u_int)s->sm_ddr3.ddr3_mtb_dividend * 1000 /
769 1.34 msaitoh s->sm_ddr3.ddr3_mtb_divisor;
770 1.34 msaitoh ftb = (u_int)s->sm_ddr3.ddr3_ftb_dividend * 1000 /
771 1.34 msaitoh s->sm_ddr3.ddr3_ftb_divisor;
772 1.34 msaitoh
773 1.34 msaitoh /* tXX_ftb is signed value */
774 1.34 msaitoh signed_txx_ftb = (int8_t)txx_ftb;
775 1.34 msaitoh val = txx_mtb * mtb +
776 1.34 msaitoh ((txx_ftb > 127) ? signed_txx_ftb : txx_ftb) * ftb / 1000;
777 1.34 msaitoh
778 1.34 msaitoh return val;
779 1.34 msaitoh }
780 1.34 msaitoh
781 1.34 msaitoh #define __DDR3_VALUE_PICO(s, field) \
782 1.34 msaitoh ddr3_value_pico(s, s->sm_ddr3.ddr3_##field##_mtb, \
783 1.34 msaitoh s->sm_ddr3.ddr3_##field##_ftb)
784 1.34 msaitoh
785 1.26 christos static void
786 1.26 christos decode_ddr3(const struct sysctlnode *node, device_t self, struct spdmem *s)
787 1.26 christos {
788 1.26 christos int dimm_size, cycle_time, bits;
789 1.26 christos
790 1.8 soren aprint_naive("\n");
791 1.26 christos print_part(s->sm_ddr3.ddr3_part, sizeof(s->sm_ddr3.ddr3_part));
792 1.8 soren aprint_normal_dev(self, "%s", spdmem_basic_types[s->sm_type]);
793 1.8 soren
794 1.1 pgoyette if (s->sm_ddr3.ddr3_mod_type ==
795 1.1 pgoyette SPDMEM_DDR3_TYPE_MINI_RDIMM ||
796 1.1 pgoyette s->sm_ddr3.ddr3_mod_type == SPDMEM_DDR3_TYPE_RDIMM)
797 1.1 pgoyette aprint_normal(" (registered)");
798 1.1 pgoyette aprint_normal(", %sECC, %stemp-sensor, ",
799 1.1 pgoyette (s->sm_ddr3.ddr3_hasECC)?"":"no ",
800 1.1 pgoyette (s->sm_ddr3.ddr3_has_therm_sensor)?"":"no ");
801 1.1 pgoyette
802 1.1 pgoyette /*
803 1.1 pgoyette * DDR3 size specification is quite different from others
804 1.1 pgoyette *
805 1.1 pgoyette * Module capacity is defined as
806 1.1 pgoyette * Chip_Capacity_in_bits / 8bits-per-byte *
807 1.1 pgoyette * external_bus_width / internal_bus_width
808 1.1 pgoyette * We further divide by 2**20 to get our answer in MB
809 1.1 pgoyette */
810 1.1 pgoyette dimm_size = (s->sm_ddr3.ddr3_chipsize + 28 - 20) - 3 +
811 1.1 pgoyette (s->sm_ddr3.ddr3_datawidth + 3) -
812 1.1 pgoyette (s->sm_ddr3.ddr3_chipwidth + 2);
813 1.1 pgoyette dimm_size = (1 << dimm_size) * (s->sm_ddr3.ddr3_physbanks + 1);
814 1.1 pgoyette
815 1.34 msaitoh cycle_time = __DDR3_VALUE_PICO(s, tCKmin);
816 1.1 pgoyette bits = 1 << (s->sm_ddr3.ddr3_datawidth + 3);
817 1.3 pgoyette decode_size_speed(self, node, dimm_size, cycle_time, 2, bits, FALSE,
818 1.3 pgoyette "PC3", 0);
819 1.1 pgoyette
820 1.1 pgoyette aprint_verbose_dev(self,
821 1.1 pgoyette "%d rows, %d cols, %d log. banks, %d phys. banks, "
822 1.1 pgoyette "%d.%03dns cycle time\n",
823 1.32 msaitoh s->sm_ddr3.ddr3_rows + 12, s->sm_ddr3.ddr3_cols + 9,
824 1.1 pgoyette 1 << (s->sm_ddr3.ddr3_logbanks + 3),
825 1.1 pgoyette s->sm_ddr3.ddr3_physbanks + 1,
826 1.1 pgoyette cycle_time/1000, cycle_time % 1000);
827 1.1 pgoyette
828 1.34 msaitoh #define __DDR3_CYCLES(val) \
829 1.34 msaitoh ((val / cycle_time) + ((val % cycle_time) ? 1 : 0))
830 1.1 pgoyette
831 1.34 msaitoh aprint_verbose_dev(self, LATENCY,
832 1.34 msaitoh __DDR3_CYCLES(__DDR3_VALUE_PICO(s, tAAmin)),
833 1.34 msaitoh __DDR3_CYCLES(__DDR3_VALUE_PICO(s, tRCDmin)),
834 1.34 msaitoh __DDR3_CYCLES(__DDR3_VALUE_PICO(s, tRPmin)),
835 1.35 msaitoh __DDR3_CYCLES((s->sm_ddr3.ddr3_tRAS_msb * 256
836 1.35 msaitoh + s->sm_ddr3.ddr3_tRAS_lsb) * s->sm_ddr3.ddr3_mtb_dividend
837 1.35 msaitoh / s->sm_ddr3.ddr3_mtb_divisor * 1000));
838 1.1 pgoyette
839 1.1 pgoyette #undef __DDR3_CYCLES
840 1.14 msaitoh
841 1.14 msaitoh /* For DDR3, Voltage is written in another area */
842 1.14 msaitoh if (!s->sm_ddr3.ddr3_NOT15V || s->sm_ddr3.ddr3_135V
843 1.14 msaitoh || s->sm_ddr3.ddr3_125V) {
844 1.14 msaitoh aprint_verbose("%s:", device_xname(self));
845 1.14 msaitoh if (!s->sm_ddr3.ddr3_NOT15V)
846 1.14 msaitoh aprint_verbose(" 1.5V");
847 1.14 msaitoh if (s->sm_ddr3.ddr3_135V)
848 1.14 msaitoh aprint_verbose(" 1.35V");
849 1.14 msaitoh if (s->sm_ddr3.ddr3_125V)
850 1.14 msaitoh aprint_verbose(" 1.25V");
851 1.14 msaitoh aprint_verbose(" operable\n");
852 1.14 msaitoh }
853 1.1 pgoyette }
854 1.1 pgoyette
855 1.1 pgoyette static void
856 1.18 msaitoh decode_fbdimm(const struct sysctlnode *node, device_t self, struct spdmem *s)
857 1.18 msaitoh {
858 1.1 pgoyette int dimm_size, cycle_time, bits;
859 1.1 pgoyette
860 1.8 soren aprint_naive("\n");
861 1.8 soren aprint_normal("\n");
862 1.8 soren aprint_normal_dev(self, "%s", spdmem_basic_types[s->sm_type]);
863 1.8 soren
864 1.1 pgoyette /*
865 1.1 pgoyette * FB-DIMM module size calculation is very much like DDR3
866 1.1 pgoyette */
867 1.1 pgoyette dimm_size = s->sm_fbd.fbdimm_rows + 12 +
868 1.1 pgoyette s->sm_fbd.fbdimm_cols + 9 - 20 - 3;
869 1.1 pgoyette dimm_size = (1 << dimm_size) * (1 << (s->sm_fbd.fbdimm_banks + 2));
870 1.1 pgoyette
871 1.1 pgoyette cycle_time = (1000 * s->sm_fbd.fbdimm_mtb_dividend +
872 1.1 pgoyette (s->sm_fbd.fbdimm_mtb_divisor / 2)) /
873 1.1 pgoyette s->sm_fbd.fbdimm_mtb_divisor;
874 1.1 pgoyette bits = 1 << (s->sm_fbd.fbdimm_dev_width + 2);
875 1.3 pgoyette decode_size_speed(self, node, dimm_size, cycle_time, 2, bits, TRUE,
876 1.3 pgoyette "PC2", 0);
877 1.1 pgoyette
878 1.1 pgoyette aprint_verbose_dev(self,
879 1.1 pgoyette "%d rows, %d cols, %d banks, %d.%02dns cycle time\n",
880 1.1 pgoyette s->sm_fbd.fbdimm_rows, s->sm_fbd.fbdimm_cols,
881 1.1 pgoyette 1 << (s->sm_fbd.fbdimm_banks + 2),
882 1.1 pgoyette cycle_time / 1000, (cycle_time % 1000 + 5) /10 );
883 1.1 pgoyette
884 1.1 pgoyette #define __FBDIMM_CYCLES(field) (s->sm_fbd.field / s->sm_fbd.fbdimm_tCKmin)
885 1.1 pgoyette
886 1.4 christos aprint_verbose_dev(self, LATENCY, __FBDIMM_CYCLES(fbdimm_tAAmin),
887 1.33 msaitoh __FBDIMM_CYCLES(fbdimm_tRCDmin), __FBDIMM_CYCLES(fbdimm_tRPmin),
888 1.33 msaitoh (s->sm_fbd.fbdimm_tRAS_msb * 256 + s->sm_fbd.fbdimm_tRAS_lsb) /
889 1.33 msaitoh s->sm_fbd.fbdimm_tCKmin);
890 1.1 pgoyette
891 1.1 pgoyette #undef __FBDIMM_CYCLES
892 1.1 pgoyette
893 1.1 pgoyette decode_voltage_refresh(self, s);
894 1.1 pgoyette }
895 1.13 pgoyette
896 1.13 pgoyette static void
897 1.18 msaitoh decode_ddr4(const struct sysctlnode *node, device_t self, struct spdmem *s)
898 1.18 msaitoh {
899 1.30 msaitoh int dimm_size, cycle_time, ranks;
900 1.33 msaitoh int tAA_clocks, tRCD_clocks, tRP_clocks, tRAS_clocks;
901 1.13 pgoyette
902 1.13 pgoyette aprint_naive("\n");
903 1.26 christos print_part(s->sm_ddr4.ddr4_part_number,
904 1.26 christos sizeof(s->sm_ddr4.ddr4_part_number));
905 1.13 pgoyette aprint_normal_dev(self, "%s", spdmem_basic_types[s->sm_type]);
906 1.13 pgoyette if (s->sm_ddr4.ddr4_mod_type < __arraycount(spdmem_ddr4_module_types))
907 1.33 msaitoh aprint_normal(" (%s)",
908 1.13 pgoyette spdmem_ddr4_module_types[s->sm_ddr4.ddr4_mod_type]);
909 1.28 msaitoh aprint_normal(", %sECC, %stemp-sensor, ",
910 1.28 msaitoh (s->sm_ddr4.ddr4_bus_width_extension) ? "" : "no ",
911 1.28 msaitoh (s->sm_ddr4.ddr4_has_therm_sensor) ? "" : "no ");
912 1.13 pgoyette
913 1.13 pgoyette /*
914 1.13 pgoyette * DDR4 size calculation from JEDEC spec
915 1.13 pgoyette *
916 1.13 pgoyette * Module capacity in bytes is defined as
917 1.13 pgoyette * Chip_Capacity_in_bits / 8bits-per-byte *
918 1.13 pgoyette * primary_bus_width / DRAM_width *
919 1.13 pgoyette * logical_ranks_per_DIMM
920 1.13 pgoyette *
921 1.13 pgoyette * logical_ranks_per DIMM equals package_ranks, but multiply
922 1.13 pgoyette * by diecount for 3DS packages
923 1.13 pgoyette *
924 1.13 pgoyette * We further divide by 2**20 to get our answer in MB
925 1.13 pgoyette */
926 1.13 pgoyette dimm_size = (s->sm_ddr4.ddr4_capacity + 28) /* chip_capacity */
927 1.13 pgoyette - 20 /* convert to MB */
928 1.13 pgoyette - 3 /* bits --> bytes */
929 1.13 pgoyette + (s->sm_ddr4.ddr4_primary_bus_width + 3); /* bus width */
930 1.13 pgoyette switch (s->sm_ddr4.ddr4_device_width) { /* DRAM width */
931 1.13 pgoyette case 0: dimm_size -= 2;
932 1.13 pgoyette break;
933 1.13 pgoyette case 1: dimm_size -= 3;
934 1.13 pgoyette break;
935 1.13 pgoyette case 2: dimm_size -= 4;
936 1.13 pgoyette break;
937 1.13 pgoyette case 4: dimm_size -= 5;
938 1.13 pgoyette break;
939 1.13 pgoyette default:
940 1.13 pgoyette dimm_size = -1; /* flag invalid value */
941 1.13 pgoyette }
942 1.33 msaitoh if (dimm_size >= 0) {
943 1.13 pgoyette dimm_size = (1 << dimm_size) *
944 1.13 pgoyette (s->sm_ddr4.ddr4_package_ranks + 1); /* log.ranks/DIMM */
945 1.13 pgoyette if (s->sm_ddr4.ddr4_signal_loading == 2) {
946 1.19 pgoyette dimm_size *= (s->sm_ddr4.ddr4_diecount + 1);
947 1.13 pgoyette }
948 1.13 pgoyette }
949 1.13 pgoyette
950 1.24 msaitoh /*
951 1.24 msaitoh * Note that the ddr4_xxx_ftb fields are actually signed offsets from
952 1.24 msaitoh * the corresponding mtb value, so we might have to subtract 256!
953 1.24 msaitoh */
954 1.18 msaitoh #define __DDR4_VALUE(field) ((s->sm_ddr4.ddr4_##field##_mtb * 125 + \
955 1.18 msaitoh s->sm_ddr4.ddr4_##field##_ftb) - \
956 1.18 msaitoh ((s->sm_ddr4.ddr4_##field##_ftb > 127)?256:0))
957 1.13 pgoyette /*
958 1.33 msaitoh * For now, the only value for mtb is 0 = 125ps, and ftb = 1ps
959 1.13 pgoyette * so we don't need to figure out the time-base units - just
960 1.13 pgoyette * hard-code them for now.
961 1.13 pgoyette */
962 1.18 msaitoh cycle_time = __DDR4_VALUE(tCKAVGmin);
963 1.13 pgoyette decode_size_speed(self, node, dimm_size, cycle_time, 2,
964 1.19 pgoyette 1 << (s->sm_ddr4.ddr4_primary_bus_width + 3),
965 1.13 pgoyette TRUE, "PC4", 0);
966 1.13 pgoyette
967 1.30 msaitoh ranks = s->sm_ddr4.ddr4_package_ranks + 1;
968 1.13 pgoyette aprint_verbose_dev(self,
969 1.30 msaitoh "%d rows, %d cols, %d ranks%s, %d banks/group, %d bank groups\n",
970 1.29 msaitoh s->sm_ddr4.ddr4_rows + 12, s->sm_ddr4.ddr4_cols + 9,
971 1.30 msaitoh ranks, (ranks > 1) ? ((s->sm_ddr4.ddr4_rank_mix == 1)
972 1.31 pgoyette ? " (asymmetric)" : " (symmetric)") : "",
973 1.13 pgoyette 1 << (2 + s->sm_ddr4.ddr4_logbanks),
974 1.30 msaitoh 1 << s->sm_ddr4.ddr4_bankgroups);
975 1.30 msaitoh
976 1.30 msaitoh aprint_verbose_dev(self, "%d.%03dns cycle time\n",
977 1.20 msaitoh cycle_time / 1000, cycle_time % 1000);
978 1.13 pgoyette
979 1.18 msaitoh tAA_clocks = __DDR4_VALUE(tAAmin) * 1000 / cycle_time;
980 1.18 msaitoh tRCD_clocks = __DDR4_VALUE(tRCDmin) * 1000 / cycle_time;
981 1.18 msaitoh tRP_clocks = __DDR4_VALUE(tRPmin) * 1000 / cycle_time;
982 1.13 pgoyette tRAS_clocks = (s->sm_ddr4.ddr4_tRASmin_msb * 256 +
983 1.13 pgoyette s->sm_ddr4.ddr4_tRASmin_lsb) * 125 * 1000 / cycle_time;
984 1.13 pgoyette
985 1.13 pgoyette /*
986 1.13 pgoyette * Per JEDEC spec, rounding is done by taking the time value, dividing
987 1.13 pgoyette * by the cycle time, subtracting .010 from the result, and then
988 1.13 pgoyette * rounded up to the nearest integer. Unfortunately, none of their
989 1.13 pgoyette * examples say what to do when the result of the subtraction is already
990 1.13 pgoyette * an integer. For now, assume that we still round up (so an interval
991 1.13 pgoyette * of exactly 12.010 clock cycles will be printed as 13).
992 1.13 pgoyette */
993 1.13 pgoyette #define __DDR4_ROUND(value) ((value - 10) / 1000 + 1)
994 1.13 pgoyette
995 1.13 pgoyette aprint_verbose_dev(self, LATENCY, __DDR4_ROUND(tAA_clocks),
996 1.18 msaitoh __DDR4_ROUND(tRCD_clocks),
997 1.13 pgoyette __DDR4_ROUND(tRP_clocks),
998 1.13 pgoyette __DDR4_ROUND(tRAS_clocks));
999 1.13 pgoyette
1000 1.13 pgoyette #undef __DDR4_VALUE
1001 1.13 pgoyette #undef __DDR4_ROUND
1002 1.13 pgoyette }
1003