blob: da9dad2a5768d724f7291be385b15d89ce75d7ac [file] [log] [blame]
Alexandru Gagniucf97ff3f2013-05-21 14:43:45 -05001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2013 Alexandru Gagniuc <mr.nuke.me@gmail.com>
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
Alexandru Gagniucf97ff3f2013-05-21 14:43:45 -050015 */
16
17#ifndef DEVICE_DRAM_DDR3L_H
18#define DEVICE_DRAM_DDR3L_H
19
20/**
21 * @file ddr3.h
22 *
23 * \brief Utilities for decoding DDR3 SPDs
24 */
25
26#include <stdint.h>
27#include <spd.h>
28
29/**
30 * \brief Convenience definitions for TCK values
31 *
32 * Different values for tCK, representing standard DDR3 frequencies.
33 * These values are in 1/256 ns units.
34 * @{
35 */
Patrick Rudolph9f3f9152016-01-26 20:02:14 +010036#define TCK_1333MHZ 192
37#define TCK_1200MHZ 212
Alexandru Gagniucf97ff3f2013-05-21 14:43:45 -050038#define TCK_1066MHZ 240
Patrick Rudolph9f3f9152016-01-26 20:02:14 +010039#define TCK_933MHZ 275
Alexandru Gagniucf97ff3f2013-05-21 14:43:45 -050040#define TCK_800MHZ 320
41#define TCK_666MHZ 384
42#define TCK_533MHZ 480
43#define TCK_400MHZ 640
44#define TCK_333MHZ 768
45#define TCK_266MHZ 960
46#define TCK_200MHZ 1280
47/** @} */
48
49/**
50 * \brief Convenience macro for enabling printk with CONFIG_DEBUG_RAM_SETUP
51 *
52 * Use this macro instead of printk(); for verbose RAM initialization messages.
53 * When CONFIG_DEBUG_RAM_SETUP is not selected, these messages are automatically
54 * disabled.
55 * @{
56 */
Martin Rothc4e49f62015-07-11 13:42:54 -060057#if IS_ENABLED(CONFIG_DEBUG_RAM_SETUP)
Alexandru Gagniucf97ff3f2013-05-21 14:43:45 -050058#define printram(x, ...) printk(BIOS_DEBUG, x, ##__VA_ARGS__)
59#else
60#define printram(x, ...)
61#endif
62/** @} */
63
64/*
65 * Module type (byte 3, bits 3:0) of SPD
Martin Roth0cb07e32013-07-09 21:46:01 -060066 * This definition is specific to DDR3. DDR2 SPDs have a different structure.
Alexandru Gagniucf97ff3f2013-05-21 14:43:45 -050067 */
68enum spd_dimm_type {
69 SPD_DIMM_TYPE_UNDEFINED = 0x00,
70 SPD_DIMM_TYPE_RDIMM = 0x01,
71 SPD_DIMM_TYPE_UDIMM = 0x02,
72 SPD_DIMM_TYPE_SO_DIMM = 0x03,
73 SPD_DIMM_TYPE_MICRO_DIMM = 0x04,
74 SPD_DIMM_TYPE_MINI_RDIMM = 0x05,
75 SPD_DIMM_TYPE_MINI_UDIMM = 0x06,
76 SPD_DIMM_TYPE_MINI_CDIMM = 0x07,
77 SPD_DIMM_TYPE_72B_SO_UDIMM = 0x08,
78 SPD_DIMM_TYPE_72B_SO_RDIMM = 0x09,
79 SPD_DIMM_TYPE_72B_SO_CDIMM = 0x0a,
80 SPD_DIMM_TYPE_LRDIMM = 0x0b,
81 SPD_DIMM_TYPE_16B_SO_DIMM = 0x0d,
82 SPD_DIMM_TYPE_32B_SO_DIMM = 0x0e,
83 /* Masks to bits 3:0 to give the dimm type */
84 SPD_DIMM_TYPE_MASK = 0x0f,
85};
86
87/**
88 * \brief DIMM flags
89 *
90 * Characteristic flags for the DIMM, as presented by the SPD
91 */
92typedef union dimm_flags_st {
93 /* The whole point of the union/struct construct is to allow us to clear
94 * all the bits with one line: flags.raw = 0.
95 * We do not care how these bits are ordered */
96 struct {
97 /* Indicates if rank 1 of DIMM uses a mirrored pin mapping. See:
98 * Annex K: Serial Presence Detect (SPD) for DDR3 SDRAM */
99 unsigned pins_mirrored:1;
100 /* Module can work at 1.50V - All DIMMS must be 1.5V operable */
101 unsigned operable_1_50V:1;
102 /* Module can work at 1.35V */
103 unsigned operable_1_35V:1;
104 /* Module can work at 1.20V */
105 unsigned operable_1_25V:1;
106 /* Has an 8-bit bus extension, meaning the DIMM supports ECC */
107 unsigned is_ecc:1;
108 /* DLL-Off Mode Support */
109 unsigned dll_off_mode:1;
110 /* Indicates a drive strength of RZQ/6 (40 Ohm) is supported */
111 unsigned rzq6_supported:1;
112 /* Indicates a drive strength of RZQ/7 (35 Ohm) is supported */
113 unsigned rzq7_supported:1;
114 /* Partial Array Self Refresh */
115 unsigned pasr:1;
116 /* On-die Thermal Sensor Readout */
117 unsigned odts:1;
118 /* Auto Self Refresh */
119 unsigned asr:1;
120 /* Extended temperature range supported */
121 unsigned ext_temp_range:1;
122 /* Operating at extended temperature requires 2X refresh rate */
123 unsigned ext_temp_refresh:1;
124 /* Thermal sensor incorporated */
125 unsigned therm_sensor:1;
126 };
127 unsigned raw;
128} dimm_flags_t;
129
130/**
131 * \brief DIMM characteristics
132 *
133 * The characteristics of each DIMM, as presented by the SPD
134 */
135typedef struct dimm_attr_st {
136 enum spd_memory_type dram_type;
Vladimir Serbinenko0e675f72014-12-07 13:56:48 +0100137 enum spd_dimm_type dimm_type;
Alexandru Gagniucf97ff3f2013-05-21 14:43:45 -0500138 u16 cas_supported;
139 /* Flags extracted from SPD */
140 dimm_flags_t flags;
Vladimir Serbinenko7686a562014-05-18 11:05:56 +0200141 /* SDRAM width */
142 u8 width;
Alexandru Gagniucf97ff3f2013-05-21 14:43:45 -0500143 /* Number of ranks */
144 u8 ranks;
145 /* Number or row address bits */
146 u8 row_bits;
147 /* Number or column address bits */
148 u8 col_bits;
149 /* Size of module in MiB */
150 u32 size_mb;
151 /* Latencies are in units of 1/256 ns */
152 u32 tCK;
153 u32 tAA;
154 u32 tWR;
155 u32 tRCD;
156 u32 tRRD;
157 u32 tRP;
158 u32 tRAS;
159 u32 tRC;
160 u32 tRFC;
161 u32 tWTR;
162 u32 tRTP;
163 u32 tFAW;
Vladimir Serbinenko7686a562014-05-18 11:05:56 +0200164
165 u8 reference_card;
Patrick Rudolphbd1fdc62016-01-26 08:45:21 +0100166 /* XMP: Module voltage in mV */
167 u16 voltage;
168 /* XMP: max DIMMs per channel supported (1-4) */
169 u8 dimms_per_channel;
Patrick Rudolph07691592016-02-29 18:21:00 +0100170 /* Manufacturer ID */
171 u16 manufacturer_id;
172 /* ASCII part number - NULL terminated */
173 u8 part_number[17];
Alexandru Gagniucf97ff3f2013-05-21 14:43:45 -0500174} dimm_attr;
175
176/** Result of the SPD decoding process */
177enum spd_status {
178 SPD_STATUS_OK = 0,
179 SPD_STATUS_INVALID,
180 SPD_STATUS_CRC_ERROR,
181 SPD_STATUS_INVALID_FIELD,
182};
183
Patrick Rudolphbd1fdc62016-01-26 08:45:21 +0100184enum ddr3_xmp_profile {
185 DDR3_XMP_PROFILE_1 = 0,
186 DDR3_XMP_PROFILE_2 = 1,
187};
188
Alexandru Gagniucf97ff3f2013-05-21 14:43:45 -0500189typedef u8 spd_raw_data[256];
190
Alexandru Gagniuc4c37e582013-12-17 13:08:01 -0500191u16 spd_ddr3_calc_crc(u8 *spd, int len);
Alexandru Gagniucf97ff3f2013-05-21 14:43:45 -0500192int spd_decode_ddr3(dimm_attr * dimm, spd_raw_data spd_data);
193int dimm_is_registered(enum spd_dimm_type type);
194void dram_print_spd_ddr3(const dimm_attr * dimm);
Patrick Rudolphbd1fdc62016-01-26 08:45:21 +0100195int spd_xmp_decode_ddr3(dimm_attr * dimm,
196 spd_raw_data spd,
197 enum ddr3_xmp_profile profile);
Alexandru Gagniucf97ff3f2013-05-21 14:43:45 -0500198
199/**
200 * \brief Read double word from specified address
201 *
202 * Should be useful when doing an MRS to the DIMM
203 */
Stefan Reinauer1e2500e2015-06-19 14:59:06 -0700204static inline u32 volatile_read(volatile uintptr_t addr)
Alexandru Gagniucf97ff3f2013-05-21 14:43:45 -0500205{
206 volatile u32 result;
207 result = *(volatile u32 *)addr;
208 return result;
209}
210
Alexandru Gagniuc78706fd2013-06-03 13:58:10 -0500211/**
212 * \brief Representation of an MRS command
213 *
214 * This represents an MRS command as seen by the DIMM. This is not a memory
215 * address that can be read to generate an MRS command. The mapping of CPU
216 * to memory pins is hardware-dependent.
217 * \n
218 * The idea is to generalize the MRS code, and only need a hardware-specific
219 * function to map the MRS bits to CPU address bits. An MRS command can be
220 * sent like:
221 * @code{.c}
222 * u32 addr;
223 * mrs_cmd_t mrs;
224 * chipset_enable_mrs_command_mode();
225 * mrs = ddr3_get_mr2(rtt_wr, srt, asr, cwl)
226 * if (rank_has_mirrorred_pins)
227 * mrs = ddr3_mrs_mirror_pins(mrs);
228 * addr = chipset_specific_get_mrs_addr(mrs);
229 * volatile_read(addr);
230 * @endcode
231 *
232 * The MRS representation has the following structure:
233 * - cmd[15:0] = Address pins MA[15:0]
234 * - cmd[18:16] = Bank address BA[2:0]
235 */
236typedef u32 mrs_cmd_t;
237
238enum ddr3_mr0_precharge {
239 DDR3_MR0_PRECHARGE_SLOW = 0,
240 DDR3_MR0_PRECHARGE_FAST = 1,
241};
242enum ddr3_mr0_mode {
243 DDR3_MR0_MODE_NORMAL = 0,
244 DDR3_MR0_MODE_TEST = 1,
245};
246enum ddr3_mr0_dll_reset {
247 DDR3_MR0_DLL_RESET_NO = 0,
248 DDR3_MR0_DLL_RESET_YES = 1,
249};
250enum ddr3_mr0_burst_type {
251 DDR3_MR0_BURST_TYPE_SEQUENTIAL = 0,
252 DDR3_MR0_BURST_TYPE_INTERLEAVED = 1,
253};
254enum ddr3_mr0_burst_length {
255 DDR3_MR0_BURST_LENGTH_8 = 0,
256 DDR3_MR0_BURST_LENGTH_CHOP = 1,
257 DDR3_MR0_BURST_LENGTH_4 = 2,
258};
259mrs_cmd_t ddr3_get_mr0(enum ddr3_mr0_precharge precharge_pd,
260 u8 write_recovery,
261 enum ddr3_mr0_dll_reset dll_reset,
262 enum ddr3_mr0_mode mode,
263 u8 cas,
264 enum ddr3_mr0_burst_type interleaved_burst,
265 enum ddr3_mr0_burst_length burst_length);
266
267enum ddr3_mr1_qoff {
268 DDR3_MR1_QOFF_ENABLE = 0,
269 DDR3_MR1_QOFF_DISABLE = 1,
270};
271enum ddr3_mr1_tqds {
272 DDR3_MR1_TQDS_DISABLE = 0,
273 DDR3_MR1_TQDS_ENABLE = 1,
274};
275enum ddr3_mr1_write_leveling {
276 DDR3_MR1_WRLVL_DISABLE = 0,
277 DDR3_MR1_WRLVL_ENABLE = 1,
278};
279enum ddr3_mr1_rtt_nom {
280 DDR3_MR1_RTT_NOM_OFF = 0,
281 DDR3_MR1_RTT_NOM_RZQ4 = 1,
282 DDR3_MR1_RTT_NOM_RZQ2 = 2,
283 DDR3_MR1_RTT_NOM_RZQ6 = 3,
284 DDR3_MR1_RTT_NOM_RZQ12 = 4,
285 DDR3_MR1_RTT_NOM_RZQ8 = 5,
286};
287enum ddr3_mr1_additive_latency {
288 DDR3_MR1_AL_DISABLE = 0,
289 DDR3_MR1_AL_CL_MINUS_1 = 1,
290 DDR3_MR1_AL_CL_MINUS_2 = 2,
291};
292enum ddr3_mr1_ods {
293 DDR3_MR1_ODS_RZQ6 = 0,
294 DDR3_MR1_ODS_RZQ7 = 1,
295};
296enum ddr3_mr1_dll {
297 DDR3_MR1_DLL_ENABLE = 0,
298 DDR3_MR1_DLL_DISABLE = 1,
299};
300
301mrs_cmd_t ddr3_get_mr1(enum ddr3_mr1_qoff qoff,
302 enum ddr3_mr1_tqds tqds,
303 enum ddr3_mr1_rtt_nom rtt_nom,
304 enum ddr3_mr1_write_leveling write_leveling,
305 enum ddr3_mr1_ods output_drive_strenght,
306 enum ddr3_mr1_additive_latency additive_latency,
307 enum ddr3_mr1_dll dll_disable);
308
309enum ddr3_mr2_rttwr {
310 DDR3_MR2_RTTWR_OFF = 0,
311 DDR3_MR2_RTTWR_RZQ4 = 1,
312 DDR3_MR2_RTTWR_RZQ2 = 2,
313};
314enum ddr3_mr2_srt_range {
315 DDR3_MR2_SRT_NORMAL = 0,
316 DDR3_MR2_SRT_EXTENDED = 1,
317};
318enum ddr3_mr2_asr {
319 DDR3_MR2_ASR_MANUAL = 0,
320 DDR3_MR2_ASR_AUTO = 1,
321};
322
323mrs_cmd_t ddr3_get_mr2(enum ddr3_mr2_rttwr rtt_wr,
324 enum ddr3_mr2_srt_range extended_temp,
325 enum ddr3_mr2_asr self_refresh, u8 cas_cwl);
326
327mrs_cmd_t ddr3_get_mr3(char dataflow_from_mpr);
328mrs_cmd_t ddr3_mrs_mirror_pins(mrs_cmd_t cmd);
329
Martin Rothfd277d82016-01-11 12:47:30 -0700330#endif /* DEVICE_DRAM_DDR3L_H */