blob: 18a69af96f8a8f06c91351699334596cd38aaa63 [file] [log] [blame]
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +01001/*
2 * This file is part of the coreboot project.
3 *
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +01004 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14
15#ifndef RAMINIT_COMMON_H
16#define RAMINIT_COMMON_H
17
Felix Held380c6b22020-01-26 05:06:38 +010018#include <stdint.h>
19
Angel Pons7c49cb82020-03-16 23:17:32 +010020#define BASEFREQ 133
21#define tDLLK 512
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +010022
Angel Pons7c49cb82020-03-16 23:17:32 +010023#define IS_SANDY_CPU(x) ((x & 0xffff0) == 0x206a0)
24#define IS_SANDY_CPU_C(x) ((x & 0xf) == 4)
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +010025#define IS_SANDY_CPU_D0(x) ((x & 0xf) == 5)
26#define IS_SANDY_CPU_D1(x) ((x & 0xf) == 6)
27#define IS_SANDY_CPU_D2(x) ((x & 0xf) == 7)
28
Angel Pons7c49cb82020-03-16 23:17:32 +010029#define IS_IVY_CPU(x) ((x & 0xffff0) == 0x306a0)
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +010030#define IS_IVY_CPU_C(x) ((x & 0xf) == 4)
31#define IS_IVY_CPU_K(x) ((x & 0xf) == 5)
32#define IS_IVY_CPU_D(x) ((x & 0xf) == 6)
33#define IS_IVY_CPU_E(x) ((x & 0xf) >= 8)
34
Angel Pons7c49cb82020-03-16 23:17:32 +010035#define NUM_CHANNELS 2
36#define NUM_SLOTRANKS 4
37#define NUM_SLOTS 2
38#define NUM_LANES 8
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +010039
40/* FIXME: Vendor BIOS uses 64 but our algorithms are less
41 performant and even 1 seems to be enough in practice. */
Angel Pons7c49cb82020-03-16 23:17:32 +010042#define NUM_PATTERNS 4
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +010043
Angel Pons5c1baf52020-03-22 12:23:35 +010044/*
45 * WARNING: Do not forget to increase MRC_CACHE_VERSION when the saved data is changed!
46 */
47#define MRC_CACHE_VERSION 1
48
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +010049typedef struct odtmap_st {
50 u16 rttwr;
51 u16 rttnom;
52} odtmap;
53
Angel Pons5c1baf52020-03-22 12:23:35 +010054/* WARNING: Do not forget to increase MRC_CACHE_VERSION when this struct is changed! */
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +010055typedef struct dimm_info_st {
56 dimm_attr dimm[NUM_CHANNELS][NUM_SLOTS];
57} dimm_info;
58
Angel Pons5c1baf52020-03-22 12:23:35 +010059/* WARNING: Do not forget to increase MRC_CACHE_VERSION when this struct is changed! */
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +010060struct ram_rank_timings {
Angel Pons7c49cb82020-03-16 23:17:32 +010061 /* ROUNDT_LAT register: One byte per slotrank */
Angel Pons88521882020-01-05 20:21:20 +010062 u8 roundtrip_latency;
63
Angel Pons7c49cb82020-03-16 23:17:32 +010064 /* IO_LATENCY register: One nibble per slotrank */
Felix Heldef4fe3e2019-12-31 14:15:05 +010065 u8 io_latency;
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +010066
Angel Pons7c49cb82020-03-16 23:17:32 +010067 /* Phase interpolator coding for command and control */
Angel Pons88521882020-01-05 20:21:20 +010068 int pi_coding;
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +010069
70 struct ram_lane_timings {
Angel Pons7c49cb82020-03-16 23:17:32 +010071 /* Lane register offset 0x10 */
72 u16 timA; /* bits 0 - 5, bits 16 - 18 */
73 u8 rising; /* bits 8 - 14 */
74 u8 falling; /* bits 20 - 26 */
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +010075
Angel Pons7c49cb82020-03-16 23:17:32 +010076 /* Lane register offset 0x20 */
77 int timC; /* bits 0 - 5, 19 */
78 u16 timB; /* bits 8 - 13, 15 - 17 */
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +010079 } lanes[NUM_LANES];
80};
81
Angel Pons5c1baf52020-03-22 12:23:35 +010082/* WARNING: Do not forget to increase MRC_CACHE_VERSION when this struct is changed! */
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +010083typedef struct ramctr_timing_st {
84 u16 spd_crc[NUM_CHANNELS][NUM_SLOTS];
Patrick Rudolph305035c2016-11-11 18:38:50 +010085 int sandybridge;
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +010086
Patrick Rudolph77eaba32016-11-11 18:55:54 +010087 /* DDR base_freq = 100 Mhz / 133 Mhz */
88 u8 base_freq;
89
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +010090 u16 cas_supported;
Angel Pons7c49cb82020-03-16 23:17:32 +010091 /* Latencies are in units of ns, scaled by x256 */
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +010092 u32 tCK;
93 u32 tAA;
94 u32 tWR;
95 u32 tRCD;
96 u32 tRRD;
97 u32 tRP;
98 u32 tRAS;
99 u32 tRFC;
100 u32 tWTR;
101 u32 tRTP;
102 u32 tFAW;
Dan Elkoubydabebc32018-04-13 18:47:10 +0300103 u32 tCWL;
104 u32 tCMD;
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +0100105 /* Latencies in terms of clock cycles
Angel Pons7c49cb82020-03-16 23:17:32 +0100106 They are saved separately as they are needed for DRAM MRS commands */
107 u8 CAS; /* CAS read latency */
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +0100108 u8 CWL; /* CAS write latency */
109
110 u32 tREFI;
111 u32 tMOD;
112 u32 tXSOffset;
113 u32 tWLO;
114 u32 tCKE;
115 u32 tXPDLL;
116 u32 tXP;
117 u32 tAONPD;
118
Angel Pons7c49cb82020-03-16 23:17:32 +0100119 /* Bits [0..11] of PM_DLL_CONFIG: Master DLL wakeup delay timer */
Angel Pons88521882020-01-05 20:21:20 +0100120 u16 mdll_wake_delay;
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +0100121
122 u8 rankmap[NUM_CHANNELS];
123 int ref_card_offset[NUM_CHANNELS];
124 u32 mad_dimm[NUM_CHANNELS];
125 int channel_size_mb[NUM_CHANNELS];
126 u32 cmd_stretch[NUM_CHANNELS];
127
Angel Pons88521882020-01-05 20:21:20 +0100128 int pi_code_offset;
129 int pi_coding_threshold;
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +0100130
131 int edge_offset[3];
132 int timC_offset[3];
133
134 int extended_temperature_range;
135 int auto_self_refresh;
136
137 int rank_mirror[NUM_CHANNELS][NUM_SLOTRANKS];
138
139 struct ram_rank_timings timings[NUM_CHANNELS][NUM_SLOTRANKS];
140
141 dimm_info info;
142} ramctr_timing;
143
Felix Held87ddea22020-01-26 04:55:27 +0100144#define SOUTHBRIDGE PCI_DEV(0, 0x1f, 0)
145
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +0100146#define FOR_ALL_LANES for (lane = 0; lane < NUM_LANES; lane++)
147#define FOR_ALL_CHANNELS for (channel = 0; channel < NUM_CHANNELS; channel++)
148#define FOR_ALL_POPULATED_RANKS for (slotrank = 0; slotrank < NUM_SLOTRANKS; slotrank++) if (ctrl->rankmap[channel] & (1 << slotrank))
149#define FOR_ALL_POPULATED_CHANNELS for (channel = 0; channel < NUM_CHANNELS; channel++) if (ctrl->rankmap[channel])
150#define MAX_EDGE_TIMING 71
151#define MAX_TIMC 127
152#define MAX_TIMB 511
153#define MAX_TIMA 127
154#define MAX_CAS 18
155#define MIN_CAS 4
156
Angel Pons7c49cb82020-03-16 23:17:32 +0100157#define MAKE_ERR ((channel << 16) | (slotrank << 8) | 1)
158#define GET_ERR_CHANNEL(x) (x >> 16)
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +0100159
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +0100160u8 get_CWL(u32 tCK);
Angel Pons88521882020-01-05 20:21:20 +0100161void dram_mrscommands(ramctr_timing *ctrl);
162void program_timings(ramctr_timing *ctrl, int channel);
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +0100163void dram_find_common_params(ramctr_timing *ctrl);
Angel Pons88521882020-01-05 20:21:20 +0100164void dram_xover(ramctr_timing *ctrl);
165void dram_timing_regs(ramctr_timing *ctrl);
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +0100166void dram_dimm_mapping(ramctr_timing *ctrl);
Angel Pons88521882020-01-05 20:21:20 +0100167void dram_dimm_set_mapping(ramctr_timing *ctrl);
168void dram_zones(ramctr_timing *ctrl, int training);
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +0100169unsigned int get_mem_min_tck(void);
Angel Pons88521882020-01-05 20:21:20 +0100170void dram_memorymap(ramctr_timing *ctrl, int me_uma_size);
171void dram_jedecreset(ramctr_timing *ctrl);
172int read_training(ramctr_timing *ctrl);
173int write_training(ramctr_timing *ctrl);
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +0100174int command_training(ramctr_timing *ctrl);
175int discover_edges(ramctr_timing *ctrl);
176int discover_edges_write(ramctr_timing *ctrl);
177int discover_timC_write(ramctr_timing *ctrl);
Angel Pons88521882020-01-05 20:21:20 +0100178void normalize_training(ramctr_timing *ctrl);
179void write_controller_mr(ramctr_timing *ctrl);
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +0100180int channel_test(ramctr_timing *ctrl);
Angel Pons88521882020-01-05 20:21:20 +0100181void set_scrambling_seed(ramctr_timing *ctrl);
Angel Pons7c49cb82020-03-16 23:17:32 +0100182void set_wmm_behavior(void);
Angel Pons88521882020-01-05 20:21:20 +0100183void prepare_training(ramctr_timing *ctrl);
Angel Pons7c49cb82020-03-16 23:17:32 +0100184void set_read_write_timings(ramctr_timing *ctrl);
Angel Pons88521882020-01-05 20:21:20 +0100185void set_normal_operation(ramctr_timing *ctrl);
186void final_registers(ramctr_timing *ctrl);
187void restore_timings(ramctr_timing *ctrl);
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +0100188
Angel Pons7c49cb82020-03-16 23:17:32 +0100189int try_init_dram_ddr3_snb(ramctr_timing *ctrl, int fast_boot, int s3_resume, int me_uma_size);
190int try_init_dram_ddr3_ivb(ramctr_timing *ctrl, int fast_boot, int s3_resume, int me_uma_size);
Patrick Rudolph305035c2016-11-11 18:38:50 +0100191
192#endif