blob: ef0d0ec606ca0715e68a317fa10e8a329d284c93 [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.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef DEVICE_DRAM_DDR3L_H
21#define DEVICE_DRAM_DDR3L_H
22
23/**
24 * @file ddr3.h
25 *
26 * \brief Utilities for decoding DDR3 SPDs
27 */
28
29#include <stdint.h>
30#include <spd.h>
31
32/**
33 * \brief Convenience definitions for TCK values
34 *
35 * Different values for tCK, representing standard DDR3 frequencies.
36 * These values are in 1/256 ns units.
37 * @{
38 */
39#define TCK_1066MHZ 240
Vladimir Serbinenko7686a562014-05-18 11:05:56 +020040#define TCK_933MHZ 275
Alexandru Gagniucf97ff3f2013-05-21 14:43:45 -050041#define TCK_800MHZ 320
42#define TCK_666MHZ 384
43#define TCK_533MHZ 480
44#define TCK_400MHZ 640
45#define TCK_333MHZ 768
46#define TCK_266MHZ 960
47#define TCK_200MHZ 1280
48/** @} */
49
50/**
51 * \brief Convenience macro for enabling printk with CONFIG_DEBUG_RAM_SETUP
52 *
53 * Use this macro instead of printk(); for verbose RAM initialization messages.
54 * When CONFIG_DEBUG_RAM_SETUP is not selected, these messages are automatically
55 * disabled.
56 * @{
57 */
58#if defined(CONFIG_DEBUG_RAM_SETUP) && (CONFIG_DEBUG_RAM_SETUP)
59#define printram(x, ...) printk(BIOS_DEBUG, x, ##__VA_ARGS__)
60#else
61#define printram(x, ...)
62#endif
63/** @} */
64
65/*
66 * Module type (byte 3, bits 3:0) of SPD
Martin Roth0cb07e32013-07-09 21:46:01 -060067 * This definition is specific to DDR3. DDR2 SPDs have a different structure.
Alexandru Gagniucf97ff3f2013-05-21 14:43:45 -050068 */
69enum spd_dimm_type {
70 SPD_DIMM_TYPE_UNDEFINED = 0x00,
71 SPD_DIMM_TYPE_RDIMM = 0x01,
72 SPD_DIMM_TYPE_UDIMM = 0x02,
73 SPD_DIMM_TYPE_SO_DIMM = 0x03,
74 SPD_DIMM_TYPE_MICRO_DIMM = 0x04,
75 SPD_DIMM_TYPE_MINI_RDIMM = 0x05,
76 SPD_DIMM_TYPE_MINI_UDIMM = 0x06,
77 SPD_DIMM_TYPE_MINI_CDIMM = 0x07,
78 SPD_DIMM_TYPE_72B_SO_UDIMM = 0x08,
79 SPD_DIMM_TYPE_72B_SO_RDIMM = 0x09,
80 SPD_DIMM_TYPE_72B_SO_CDIMM = 0x0a,
81 SPD_DIMM_TYPE_LRDIMM = 0x0b,
82 SPD_DIMM_TYPE_16B_SO_DIMM = 0x0d,
83 SPD_DIMM_TYPE_32B_SO_DIMM = 0x0e,
84 /* Masks to bits 3:0 to give the dimm type */
85 SPD_DIMM_TYPE_MASK = 0x0f,
86};
87
88/**
89 * \brief DIMM flags
90 *
91 * Characteristic flags for the DIMM, as presented by the SPD
92 */
93typedef union dimm_flags_st {
94 /* The whole point of the union/struct construct is to allow us to clear
95 * all the bits with one line: flags.raw = 0.
96 * We do not care how these bits are ordered */
97 struct {
98 /* Indicates if rank 1 of DIMM uses a mirrored pin mapping. See:
99 * Annex K: Serial Presence Detect (SPD) for DDR3 SDRAM */
100 unsigned pins_mirrored:1;
101 /* Module can work at 1.50V - All DIMMS must be 1.5V operable */
102 unsigned operable_1_50V:1;
103 /* Module can work at 1.35V */
104 unsigned operable_1_35V:1;
105 /* Module can work at 1.20V */
106 unsigned operable_1_25V:1;
107 /* Has an 8-bit bus extension, meaning the DIMM supports ECC */
108 unsigned is_ecc:1;
109 /* DLL-Off Mode Support */
110 unsigned dll_off_mode:1;
111 /* Indicates a drive strength of RZQ/6 (40 Ohm) is supported */
112 unsigned rzq6_supported:1;
113 /* Indicates a drive strength of RZQ/7 (35 Ohm) is supported */
114 unsigned rzq7_supported:1;
115 /* Partial Array Self Refresh */
116 unsigned pasr:1;
117 /* On-die Thermal Sensor Readout */
118 unsigned odts:1;
119 /* Auto Self Refresh */
120 unsigned asr:1;
121 /* Extended temperature range supported */
122 unsigned ext_temp_range:1;
123 /* Operating at extended temperature requires 2X refresh rate */
124 unsigned ext_temp_refresh:1;
125 /* Thermal sensor incorporated */
126 unsigned therm_sensor:1;
127 };
128 unsigned raw;
129} dimm_flags_t;
130
131/**
132 * \brief DIMM characteristics
133 *
134 * The characteristics of each DIMM, as presented by the SPD
135 */
136typedef struct dimm_attr_st {
137 enum spd_memory_type dram_type;
138 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;
Alexandru Gagniucf97ff3f2013-05-21 14:43:45 -0500166} dimm_attr;
167
168/** Result of the SPD decoding process */
169enum spd_status {
170 SPD_STATUS_OK = 0,
171 SPD_STATUS_INVALID,
172 SPD_STATUS_CRC_ERROR,
173 SPD_STATUS_INVALID_FIELD,
174};
175
176typedef u8 spd_raw_data[256];
177
Alexandru Gagniuc4c37e582013-12-17 13:08:01 -0500178u16 spd_ddr3_calc_crc(u8 *spd, int len);
Alexandru Gagniucf97ff3f2013-05-21 14:43:45 -0500179int spd_decode_ddr3(dimm_attr * dimm, spd_raw_data spd_data);
180int dimm_is_registered(enum spd_dimm_type type);
181void dram_print_spd_ddr3(const dimm_attr * dimm);
182
183/**
184 * \brief Read double word from specified address
185 *
186 * Should be useful when doing an MRS to the DIMM
187 */
188static inline u32 volatile_read(volatile u32 addr)
189{
190 volatile u32 result;
191 result = *(volatile u32 *)addr;
192 return result;
193}
194
Alexandru Gagniuc78706fd2013-06-03 13:58:10 -0500195/**
196 * \brief Representation of an MRS command
197 *
198 * This represents an MRS command as seen by the DIMM. This is not a memory
199 * address that can be read to generate an MRS command. The mapping of CPU
200 * to memory pins is hardware-dependent.
201 * \n
202 * The idea is to generalize the MRS code, and only need a hardware-specific
203 * function to map the MRS bits to CPU address bits. An MRS command can be
204 * sent like:
205 * @code{.c}
206 * u32 addr;
207 * mrs_cmd_t mrs;
208 * chipset_enable_mrs_command_mode();
209 * mrs = ddr3_get_mr2(rtt_wr, srt, asr, cwl)
210 * if (rank_has_mirrorred_pins)
211 * mrs = ddr3_mrs_mirror_pins(mrs);
212 * addr = chipset_specific_get_mrs_addr(mrs);
213 * volatile_read(addr);
214 * @endcode
215 *
216 * The MRS representation has the following structure:
217 * - cmd[15:0] = Address pins MA[15:0]
218 * - cmd[18:16] = Bank address BA[2:0]
219 */
220typedef u32 mrs_cmd_t;
221
222enum ddr3_mr0_precharge {
223 DDR3_MR0_PRECHARGE_SLOW = 0,
224 DDR3_MR0_PRECHARGE_FAST = 1,
225};
226enum ddr3_mr0_mode {
227 DDR3_MR0_MODE_NORMAL = 0,
228 DDR3_MR0_MODE_TEST = 1,
229};
230enum ddr3_mr0_dll_reset {
231 DDR3_MR0_DLL_RESET_NO = 0,
232 DDR3_MR0_DLL_RESET_YES = 1,
233};
234enum ddr3_mr0_burst_type {
235 DDR3_MR0_BURST_TYPE_SEQUENTIAL = 0,
236 DDR3_MR0_BURST_TYPE_INTERLEAVED = 1,
237};
238enum ddr3_mr0_burst_length {
239 DDR3_MR0_BURST_LENGTH_8 = 0,
240 DDR3_MR0_BURST_LENGTH_CHOP = 1,
241 DDR3_MR0_BURST_LENGTH_4 = 2,
242};
243mrs_cmd_t ddr3_get_mr0(enum ddr3_mr0_precharge precharge_pd,
244 u8 write_recovery,
245 enum ddr3_mr0_dll_reset dll_reset,
246 enum ddr3_mr0_mode mode,
247 u8 cas,
248 enum ddr3_mr0_burst_type interleaved_burst,
249 enum ddr3_mr0_burst_length burst_length);
250
251enum ddr3_mr1_qoff {
252 DDR3_MR1_QOFF_ENABLE = 0,
253 DDR3_MR1_QOFF_DISABLE = 1,
254};
255enum ddr3_mr1_tqds {
256 DDR3_MR1_TQDS_DISABLE = 0,
257 DDR3_MR1_TQDS_ENABLE = 1,
258};
259enum ddr3_mr1_write_leveling {
260 DDR3_MR1_WRLVL_DISABLE = 0,
261 DDR3_MR1_WRLVL_ENABLE = 1,
262};
263enum ddr3_mr1_rtt_nom {
264 DDR3_MR1_RTT_NOM_OFF = 0,
265 DDR3_MR1_RTT_NOM_RZQ4 = 1,
266 DDR3_MR1_RTT_NOM_RZQ2 = 2,
267 DDR3_MR1_RTT_NOM_RZQ6 = 3,
268 DDR3_MR1_RTT_NOM_RZQ12 = 4,
269 DDR3_MR1_RTT_NOM_RZQ8 = 5,
270};
271enum ddr3_mr1_additive_latency {
272 DDR3_MR1_AL_DISABLE = 0,
273 DDR3_MR1_AL_CL_MINUS_1 = 1,
274 DDR3_MR1_AL_CL_MINUS_2 = 2,
275};
276enum ddr3_mr1_ods {
277 DDR3_MR1_ODS_RZQ6 = 0,
278 DDR3_MR1_ODS_RZQ7 = 1,
279};
280enum ddr3_mr1_dll {
281 DDR3_MR1_DLL_ENABLE = 0,
282 DDR3_MR1_DLL_DISABLE = 1,
283};
284
285mrs_cmd_t ddr3_get_mr1(enum ddr3_mr1_qoff qoff,
286 enum ddr3_mr1_tqds tqds,
287 enum ddr3_mr1_rtt_nom rtt_nom,
288 enum ddr3_mr1_write_leveling write_leveling,
289 enum ddr3_mr1_ods output_drive_strenght,
290 enum ddr3_mr1_additive_latency additive_latency,
291 enum ddr3_mr1_dll dll_disable);
292
293enum ddr3_mr2_rttwr {
294 DDR3_MR2_RTTWR_OFF = 0,
295 DDR3_MR2_RTTWR_RZQ4 = 1,
296 DDR3_MR2_RTTWR_RZQ2 = 2,
297};
298enum ddr3_mr2_srt_range {
299 DDR3_MR2_SRT_NORMAL = 0,
300 DDR3_MR2_SRT_EXTENDED = 1,
301};
302enum ddr3_mr2_asr {
303 DDR3_MR2_ASR_MANUAL = 0,
304 DDR3_MR2_ASR_AUTO = 1,
305};
306
307mrs_cmd_t ddr3_get_mr2(enum ddr3_mr2_rttwr rtt_wr,
308 enum ddr3_mr2_srt_range extended_temp,
309 enum ddr3_mr2_asr self_refresh, u8 cas_cwl);
310
311mrs_cmd_t ddr3_get_mr3(char dataflow_from_mpr);
312mrs_cmd_t ddr3_mrs_mirror_pins(mrs_cmd_t cmd);
313
Alexandru Gagniucf97ff3f2013-05-21 14:43:45 -0500314#endif /* DEVICE_DRAM_DDR3_H */