blob: ea3d66687e2ebc5d8ae4cb7e4c1219f05bade6c1 [file] [log] [blame]
Angel Pons6e5aabd2020-03-23 23:44:42 +01001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +01003
4#ifndef RAMINIT_COMMON_H
5#define RAMINIT_COMMON_H
6
Felix Held380c6b22020-01-26 05:06:38 +01007#include <stdint.h>
8
Angel Pons7c49cb82020-03-16 23:17:32 +01009#define BASEFREQ 133
10#define tDLLK 512
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +010011
Angel Pons7c49cb82020-03-16 23:17:32 +010012#define IS_SANDY_CPU(x) ((x & 0xffff0) == 0x206a0)
13#define IS_SANDY_CPU_C(x) ((x & 0xf) == 4)
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +010014#define IS_SANDY_CPU_D0(x) ((x & 0xf) == 5)
15#define IS_SANDY_CPU_D1(x) ((x & 0xf) == 6)
16#define IS_SANDY_CPU_D2(x) ((x & 0xf) == 7)
17
Angel Pons7c49cb82020-03-16 23:17:32 +010018#define IS_IVY_CPU(x) ((x & 0xffff0) == 0x306a0)
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +010019#define IS_IVY_CPU_C(x) ((x & 0xf) == 4)
20#define IS_IVY_CPU_K(x) ((x & 0xf) == 5)
21#define IS_IVY_CPU_D(x) ((x & 0xf) == 6)
22#define IS_IVY_CPU_E(x) ((x & 0xf) >= 8)
23
Angel Pons7c49cb82020-03-16 23:17:32 +010024#define NUM_CHANNELS 2
25#define NUM_SLOTRANKS 4
26#define NUM_SLOTS 2
27#define NUM_LANES 8
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +010028
Angel Pons69e17142020-03-23 12:26:29 +010029#define NO_RANKSEL (~(1 << 16))
30#define IOSAV_MRS (0x1f000)
31#define IOSAV_PRE (0x1f002)
32#define IOSAV_ZQCS (0x1f003)
33#define IOSAV_ACT (0x1f006)
34#define IOSAV_RD (0x1f105)
35#define IOSAV_NOP_ALT (0x1f107)
36#define IOSAV_WR (0x1f201)
37#define IOSAV_NOP (0x1f207)
38
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +010039/* FIXME: Vendor BIOS uses 64 but our algorithms are less
40 performant and even 1 seems to be enough in practice. */
Angel Pons7c49cb82020-03-16 23:17:32 +010041#define NUM_PATTERNS 4
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +010042
Angel Pons5c1baf52020-03-22 12:23:35 +010043/*
44 * WARNING: Do not forget to increase MRC_CACHE_VERSION when the saved data is changed!
45 */
Patrick Rudolph05d4bf7e2017-10-28 16:36:09 +020046#define MRC_CACHE_VERSION 4
Angel Pons5c1baf52020-03-22 12:23:35 +010047
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +010048typedef struct odtmap_st {
49 u16 rttwr;
50 u16 rttnom;
51} odtmap;
52
Angel Pons5c1baf52020-03-22 12:23:35 +010053/* WARNING: Do not forget to increase MRC_CACHE_VERSION when this struct is changed! */
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +010054typedef struct dimm_info_st {
55 dimm_attr dimm[NUM_CHANNELS][NUM_SLOTS];
56} dimm_info;
57
Angel Pons5c1baf52020-03-22 12:23:35 +010058/* WARNING: Do not forget to increase MRC_CACHE_VERSION when this struct is changed! */
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +010059struct ram_rank_timings {
Angel Pons7c49cb82020-03-16 23:17:32 +010060 /* ROUNDT_LAT register: One byte per slotrank */
Angel Pons88521882020-01-05 20:21:20 +010061 u8 roundtrip_latency;
62
Angel Pons7c49cb82020-03-16 23:17:32 +010063 /* IO_LATENCY register: One nibble per slotrank */
Felix Heldef4fe3e2019-12-31 14:15:05 +010064 u8 io_latency;
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +010065
Angel Pons7c49cb82020-03-16 23:17:32 +010066 /* Phase interpolator coding for command and control */
Angel Pons88521882020-01-05 20:21:20 +010067 int pi_coding;
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +010068
69 struct ram_lane_timings {
Angel Pons7c49cb82020-03-16 23:17:32 +010070 /* Lane register offset 0x10 */
71 u16 timA; /* bits 0 - 5, bits 16 - 18 */
72 u8 rising; /* bits 8 - 14 */
73 u8 falling; /* bits 20 - 26 */
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +010074
Angel Pons7c49cb82020-03-16 23:17:32 +010075 /* Lane register offset 0x20 */
76 int timC; /* bits 0 - 5, 19 */
77 u16 timB; /* bits 8 - 13, 15 - 17 */
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +010078 } lanes[NUM_LANES];
79};
80
Angel Pons5c1baf52020-03-22 12:23:35 +010081/* WARNING: Do not forget to increase MRC_CACHE_VERSION when this struct is changed! */
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +010082typedef struct ramctr_timing_st {
83 u16 spd_crc[NUM_CHANNELS][NUM_SLOTS];
Angel Pons80037f72020-03-21 13:12:37 +010084
85 /* CPUID value */
86 u32 cpu;
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +010087
Patrick Rudolph77eaba32016-11-11 18:55:54 +010088 /* DDR base_freq = 100 Mhz / 133 Mhz */
89 u8 base_freq;
90
Angel Pons48409b82020-03-23 22:19:29 +010091 /* Frequency index */
92 u32 FRQ;
93
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +010094 u16 cas_supported;
Angel Pons7c49cb82020-03-16 23:17:32 +010095 /* Latencies are in units of ns, scaled by x256 */
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +010096 u32 tCK;
97 u32 tAA;
98 u32 tWR;
99 u32 tRCD;
100 u32 tRRD;
101 u32 tRP;
102 u32 tRAS;
103 u32 tRFC;
104 u32 tWTR;
105 u32 tRTP;
106 u32 tFAW;
Dan Elkoubydabebc32018-04-13 18:47:10 +0300107 u32 tCWL;
108 u32 tCMD;
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +0100109 /* Latencies in terms of clock cycles
Angel Pons7c49cb82020-03-16 23:17:32 +0100110 They are saved separately as they are needed for DRAM MRS commands */
111 u8 CAS; /* CAS read latency */
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +0100112 u8 CWL; /* CAS write latency */
113
114 u32 tREFI;
115 u32 tMOD;
116 u32 tXSOffset;
117 u32 tWLO;
118 u32 tCKE;
119 u32 tXPDLL;
120 u32 tXP;
121 u32 tAONPD;
122
Angel Pons7c49cb82020-03-16 23:17:32 +0100123 /* Bits [0..11] of PM_DLL_CONFIG: Master DLL wakeup delay timer */
Angel Pons88521882020-01-05 20:21:20 +0100124 u16 mdll_wake_delay;
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +0100125
126 u8 rankmap[NUM_CHANNELS];
127 int ref_card_offset[NUM_CHANNELS];
128 u32 mad_dimm[NUM_CHANNELS];
129 int channel_size_mb[NUM_CHANNELS];
130 u32 cmd_stretch[NUM_CHANNELS];
131
Angel Pons88521882020-01-05 20:21:20 +0100132 int pi_code_offset;
133 int pi_coding_threshold;
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +0100134
Patrick Rudolph05d4bf7e2017-10-28 16:36:09 +0200135 bool ecc_supported;
136 bool ecc_forced;
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +0100137 int edge_offset[3];
138 int timC_offset[3];
139
140 int extended_temperature_range;
141 int auto_self_refresh;
142
143 int rank_mirror[NUM_CHANNELS][NUM_SLOTRANKS];
144
145 struct ram_rank_timings timings[NUM_CHANNELS][NUM_SLOTRANKS];
146
147 dimm_info info;
148} ramctr_timing;
149
Felix Held87ddea22020-01-26 04:55:27 +0100150#define SOUTHBRIDGE PCI_DEV(0, 0x1f, 0)
151
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +0100152#define FOR_ALL_LANES for (lane = 0; lane < NUM_LANES; lane++)
153#define FOR_ALL_CHANNELS for (channel = 0; channel < NUM_CHANNELS; channel++)
154#define FOR_ALL_POPULATED_RANKS for (slotrank = 0; slotrank < NUM_SLOTRANKS; slotrank++) if (ctrl->rankmap[channel] & (1 << slotrank))
155#define FOR_ALL_POPULATED_CHANNELS for (channel = 0; channel < NUM_CHANNELS; channel++) if (ctrl->rankmap[channel])
156#define MAX_EDGE_TIMING 71
157#define MAX_TIMC 127
158#define MAX_TIMB 511
159#define MAX_TIMA 127
160#define MAX_CAS 18
161#define MIN_CAS 4
162
Angel Pons7c49cb82020-03-16 23:17:32 +0100163#define MAKE_ERR ((channel << 16) | (slotrank << 8) | 1)
164#define GET_ERR_CHANNEL(x) (x >> 16)
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +0100165
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +0100166u8 get_CWL(u32 tCK);
Angel Pons88521882020-01-05 20:21:20 +0100167void dram_mrscommands(ramctr_timing *ctrl);
168void program_timings(ramctr_timing *ctrl, int channel);
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +0100169void dram_find_common_params(ramctr_timing *ctrl);
Angel Pons88521882020-01-05 20:21:20 +0100170void dram_xover(ramctr_timing *ctrl);
171void dram_timing_regs(ramctr_timing *ctrl);
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +0100172void dram_dimm_mapping(ramctr_timing *ctrl);
Angel Pons88521882020-01-05 20:21:20 +0100173void dram_dimm_set_mapping(ramctr_timing *ctrl);
174void dram_zones(ramctr_timing *ctrl, int training);
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +0100175unsigned int get_mem_min_tck(void);
Angel Pons88521882020-01-05 20:21:20 +0100176void dram_memorymap(ramctr_timing *ctrl, int me_uma_size);
177void dram_jedecreset(ramctr_timing *ctrl);
178int read_training(ramctr_timing *ctrl);
179int write_training(ramctr_timing *ctrl);
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +0100180int command_training(ramctr_timing *ctrl);
181int discover_edges(ramctr_timing *ctrl);
182int discover_edges_write(ramctr_timing *ctrl);
183int discover_timC_write(ramctr_timing *ctrl);
Angel Pons88521882020-01-05 20:21:20 +0100184void normalize_training(ramctr_timing *ctrl);
185void write_controller_mr(ramctr_timing *ctrl);
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +0100186int channel_test(ramctr_timing *ctrl);
Angel Pons88521882020-01-05 20:21:20 +0100187void set_scrambling_seed(ramctr_timing *ctrl);
Angel Pons89ae6b82020-03-21 13:23:32 +0100188void set_wmm_behavior(const u32 cpu);
Angel Pons88521882020-01-05 20:21:20 +0100189void prepare_training(ramctr_timing *ctrl);
Angel Pons7c49cb82020-03-16 23:17:32 +0100190void set_read_write_timings(ramctr_timing *ctrl);
Angel Pons88521882020-01-05 20:21:20 +0100191void set_normal_operation(ramctr_timing *ctrl);
192void final_registers(ramctr_timing *ctrl);
193void restore_timings(ramctr_timing *ctrl);
Angel Ponsefbed262020-03-23 23:18:03 +0100194int try_init_dram_ddr3(ramctr_timing *ctrl, int fast_boot, int s3resume, int me_uma_size);
Patrick Rudolphfd5fa2a2016-11-11 18:22:33 +0100195
Patrick Rudolph05d4bf7e2017-10-28 16:36:09 +0200196bool get_host_ecc_cap(void);
197bool get_host_ecc_forced(void);
198
Patrick Rudolph305035c2016-11-11 18:38:50 +0100199#endif