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