Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 4 | * |
| 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 Held | 380c6b2 | 2020-01-26 05:06:38 +0100 | [diff] [blame] | 18 | #include <stdint.h> |
| 19 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 20 | #define BASEFREQ 133 |
| 21 | #define tDLLK 512 |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 22 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 23 | #define IS_SANDY_CPU(x) ((x & 0xffff0) == 0x206a0) |
| 24 | #define IS_SANDY_CPU_C(x) ((x & 0xf) == 4) |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 25 | #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 Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 29 | #define IS_IVY_CPU(x) ((x & 0xffff0) == 0x306a0) |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 30 | #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 Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 35 | #define NUM_CHANNELS 2 |
| 36 | #define NUM_SLOTRANKS 4 |
| 37 | #define NUM_SLOTS 2 |
| 38 | #define NUM_LANES 8 |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 39 | |
| 40 | /* FIXME: Vendor BIOS uses 64 but our algorithms are less |
| 41 | performant and even 1 seems to be enough in practice. */ |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 42 | #define NUM_PATTERNS 4 |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 43 | |
Angel Pons | 5c1baf5 | 2020-03-22 12:23:35 +0100 | [diff] [blame] | 44 | /* |
| 45 | * WARNING: Do not forget to increase MRC_CACHE_VERSION when the saved data is changed! |
| 46 | */ |
Angel Pons | 80037f7 | 2020-03-21 13:12:37 +0100 | [diff] [blame] | 47 | #define MRC_CACHE_VERSION 2 |
Angel Pons | 5c1baf5 | 2020-03-22 12:23:35 +0100 | [diff] [blame] | 48 | |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 49 | typedef struct odtmap_st { |
| 50 | u16 rttwr; |
| 51 | u16 rttnom; |
| 52 | } odtmap; |
| 53 | |
Angel Pons | 5c1baf5 | 2020-03-22 12:23:35 +0100 | [diff] [blame] | 54 | /* WARNING: Do not forget to increase MRC_CACHE_VERSION when this struct is changed! */ |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 55 | typedef struct dimm_info_st { |
| 56 | dimm_attr dimm[NUM_CHANNELS][NUM_SLOTS]; |
| 57 | } dimm_info; |
| 58 | |
Angel Pons | 5c1baf5 | 2020-03-22 12:23:35 +0100 | [diff] [blame] | 59 | /* WARNING: Do not forget to increase MRC_CACHE_VERSION when this struct is changed! */ |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 60 | struct ram_rank_timings { |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 61 | /* ROUNDT_LAT register: One byte per slotrank */ |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 62 | u8 roundtrip_latency; |
| 63 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 64 | /* IO_LATENCY register: One nibble per slotrank */ |
Felix Held | ef4fe3e | 2019-12-31 14:15:05 +0100 | [diff] [blame] | 65 | u8 io_latency; |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 66 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 67 | /* Phase interpolator coding for command and control */ |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 68 | int pi_coding; |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 69 | |
| 70 | struct ram_lane_timings { |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 71 | /* 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 Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 75 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 76 | /* Lane register offset 0x20 */ |
| 77 | int timC; /* bits 0 - 5, 19 */ |
| 78 | u16 timB; /* bits 8 - 13, 15 - 17 */ |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 79 | } lanes[NUM_LANES]; |
| 80 | }; |
| 81 | |
Angel Pons | 5c1baf5 | 2020-03-22 12:23:35 +0100 | [diff] [blame] | 82 | /* WARNING: Do not forget to increase MRC_CACHE_VERSION when this struct is changed! */ |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 83 | typedef struct ramctr_timing_st { |
| 84 | u16 spd_crc[NUM_CHANNELS][NUM_SLOTS]; |
Angel Pons | 80037f7 | 2020-03-21 13:12:37 +0100 | [diff] [blame] | 85 | |
| 86 | /* CPUID value */ |
| 87 | u32 cpu; |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 88 | |
Patrick Rudolph | 77eaba3 | 2016-11-11 18:55:54 +0100 | [diff] [blame] | 89 | /* DDR base_freq = 100 Mhz / 133 Mhz */ |
| 90 | u8 base_freq; |
| 91 | |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 92 | u16 cas_supported; |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 93 | /* Latencies are in units of ns, scaled by x256 */ |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 94 | u32 tCK; |
| 95 | u32 tAA; |
| 96 | u32 tWR; |
| 97 | u32 tRCD; |
| 98 | u32 tRRD; |
| 99 | u32 tRP; |
| 100 | u32 tRAS; |
| 101 | u32 tRFC; |
| 102 | u32 tWTR; |
| 103 | u32 tRTP; |
| 104 | u32 tFAW; |
Dan Elkouby | dabebc3 | 2018-04-13 18:47:10 +0300 | [diff] [blame] | 105 | u32 tCWL; |
| 106 | u32 tCMD; |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 107 | /* Latencies in terms of clock cycles |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 108 | They are saved separately as they are needed for DRAM MRS commands */ |
| 109 | u8 CAS; /* CAS read latency */ |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 110 | u8 CWL; /* CAS write latency */ |
| 111 | |
| 112 | u32 tREFI; |
| 113 | u32 tMOD; |
| 114 | u32 tXSOffset; |
| 115 | u32 tWLO; |
| 116 | u32 tCKE; |
| 117 | u32 tXPDLL; |
| 118 | u32 tXP; |
| 119 | u32 tAONPD; |
| 120 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 121 | /* Bits [0..11] of PM_DLL_CONFIG: Master DLL wakeup delay timer */ |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 122 | u16 mdll_wake_delay; |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 123 | |
| 124 | u8 rankmap[NUM_CHANNELS]; |
| 125 | int ref_card_offset[NUM_CHANNELS]; |
| 126 | u32 mad_dimm[NUM_CHANNELS]; |
| 127 | int channel_size_mb[NUM_CHANNELS]; |
| 128 | u32 cmd_stretch[NUM_CHANNELS]; |
| 129 | |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 130 | int pi_code_offset; |
| 131 | int pi_coding_threshold; |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 132 | |
| 133 | int edge_offset[3]; |
| 134 | int timC_offset[3]; |
| 135 | |
| 136 | int extended_temperature_range; |
| 137 | int auto_self_refresh; |
| 138 | |
| 139 | int rank_mirror[NUM_CHANNELS][NUM_SLOTRANKS]; |
| 140 | |
| 141 | struct ram_rank_timings timings[NUM_CHANNELS][NUM_SLOTRANKS]; |
| 142 | |
| 143 | dimm_info info; |
| 144 | } ramctr_timing; |
| 145 | |
Felix Held | 87ddea2 | 2020-01-26 04:55:27 +0100 | [diff] [blame] | 146 | #define SOUTHBRIDGE PCI_DEV(0, 0x1f, 0) |
| 147 | |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 148 | #define FOR_ALL_LANES for (lane = 0; lane < NUM_LANES; lane++) |
| 149 | #define FOR_ALL_CHANNELS for (channel = 0; channel < NUM_CHANNELS; channel++) |
| 150 | #define FOR_ALL_POPULATED_RANKS for (slotrank = 0; slotrank < NUM_SLOTRANKS; slotrank++) if (ctrl->rankmap[channel] & (1 << slotrank)) |
| 151 | #define FOR_ALL_POPULATED_CHANNELS for (channel = 0; channel < NUM_CHANNELS; channel++) if (ctrl->rankmap[channel]) |
| 152 | #define MAX_EDGE_TIMING 71 |
| 153 | #define MAX_TIMC 127 |
| 154 | #define MAX_TIMB 511 |
| 155 | #define MAX_TIMA 127 |
| 156 | #define MAX_CAS 18 |
| 157 | #define MIN_CAS 4 |
| 158 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 159 | #define MAKE_ERR ((channel << 16) | (slotrank << 8) | 1) |
| 160 | #define GET_ERR_CHANNEL(x) (x >> 16) |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 161 | |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 162 | u8 get_CWL(u32 tCK); |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 163 | void dram_mrscommands(ramctr_timing *ctrl); |
| 164 | void program_timings(ramctr_timing *ctrl, int channel); |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 165 | void dram_find_common_params(ramctr_timing *ctrl); |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 166 | void dram_xover(ramctr_timing *ctrl); |
| 167 | void dram_timing_regs(ramctr_timing *ctrl); |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 168 | void dram_dimm_mapping(ramctr_timing *ctrl); |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 169 | void dram_dimm_set_mapping(ramctr_timing *ctrl); |
| 170 | void dram_zones(ramctr_timing *ctrl, int training); |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 171 | unsigned int get_mem_min_tck(void); |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 172 | void dram_memorymap(ramctr_timing *ctrl, int me_uma_size); |
| 173 | void dram_jedecreset(ramctr_timing *ctrl); |
| 174 | int read_training(ramctr_timing *ctrl); |
| 175 | int write_training(ramctr_timing *ctrl); |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 176 | int command_training(ramctr_timing *ctrl); |
| 177 | int discover_edges(ramctr_timing *ctrl); |
| 178 | int discover_edges_write(ramctr_timing *ctrl); |
| 179 | int discover_timC_write(ramctr_timing *ctrl); |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 180 | void normalize_training(ramctr_timing *ctrl); |
| 181 | void write_controller_mr(ramctr_timing *ctrl); |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 182 | int channel_test(ramctr_timing *ctrl); |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 183 | void set_scrambling_seed(ramctr_timing *ctrl); |
Angel Pons | 89ae6b8 | 2020-03-21 13:23:32 +0100 | [diff] [blame] | 184 | void set_wmm_behavior(const u32 cpu); |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 185 | void prepare_training(ramctr_timing *ctrl); |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 186 | void set_read_write_timings(ramctr_timing *ctrl); |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 187 | void set_normal_operation(ramctr_timing *ctrl); |
| 188 | void final_registers(ramctr_timing *ctrl); |
| 189 | void restore_timings(ramctr_timing *ctrl); |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 190 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 191 | int try_init_dram_ddr3_snb(ramctr_timing *ctrl, int fast_boot, int s3_resume, int me_uma_size); |
| 192 | int try_init_dram_ddr3_ivb(ramctr_timing *ctrl, int fast_boot, int s3_resume, int me_uma_size); |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 193 | |
| 194 | #endif |