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