Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2014 Damien Zammit <damien@zamaudio.com> |
| 5 | * Copyright (C) 2014 Vladimir Serbinenko <phcoder@gmail.com> |
| 6 | * Copyright (C) 2016 Patrick Rudolph <siro@das-labor.org> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; version 2 of the License. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | */ |
| 17 | |
| 18 | #ifndef RAMINIT_COMMON_H |
| 19 | #define RAMINIT_COMMON_H |
| 20 | |
| 21 | #define BASEFREQ 133 |
| 22 | #define tDLLK 512 |
| 23 | |
| 24 | #define IS_SANDY_CPU(x) ((x & 0xffff0) == 0x206a0) |
| 25 | #define IS_SANDY_CPU_C(x) ((x & 0xf) == 4) |
| 26 | #define IS_SANDY_CPU_D0(x) ((x & 0xf) == 5) |
| 27 | #define IS_SANDY_CPU_D1(x) ((x & 0xf) == 6) |
| 28 | #define IS_SANDY_CPU_D2(x) ((x & 0xf) == 7) |
| 29 | |
| 30 | #define IS_IVY_CPU(x) ((x & 0xffff0) == 0x306a0) |
| 31 | #define IS_IVY_CPU_C(x) ((x & 0xf) == 4) |
| 32 | #define IS_IVY_CPU_K(x) ((x & 0xf) == 5) |
| 33 | #define IS_IVY_CPU_D(x) ((x & 0xf) == 6) |
| 34 | #define IS_IVY_CPU_E(x) ((x & 0xf) >= 8) |
| 35 | |
| 36 | #define NUM_CHANNELS 2 |
| 37 | #define NUM_SLOTRANKS 4 |
| 38 | #define NUM_SLOTS 2 |
| 39 | #define NUM_LANES 8 |
| 40 | |
| 41 | /* FIXME: Vendor BIOS uses 64 but our algorithms are less |
| 42 | performant and even 1 seems to be enough in practice. */ |
| 43 | #define NUM_PATTERNS 4 |
| 44 | |
| 45 | typedef struct odtmap_st { |
| 46 | u16 rttwr; |
| 47 | u16 rttnom; |
| 48 | } odtmap; |
| 49 | |
| 50 | typedef struct dimm_info_st { |
| 51 | dimm_attr dimm[NUM_CHANNELS][NUM_SLOTS]; |
| 52 | } dimm_info; |
| 53 | |
| 54 | struct ram_rank_timings { |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 55 | /* ROUNDT_LAT register. One byte per slotrank. */ |
| 56 | u8 roundtrip_latency; |
| 57 | |
| 58 | /* IO_LATENCY register. One nibble per slotrank. */ |
Felix Held | ef4fe3e | 2019-12-31 14:15:05 +0100 | [diff] [blame] | 59 | u8 io_latency; |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 60 | |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 61 | /* Phase interpolator coding for command and control. */ |
| 62 | int pi_coding; |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 63 | |
| 64 | struct ram_lane_timings { |
| 65 | /* lane register offset 0x10. */ |
| 66 | u16 timA; /* bits 0 - 5, bits 16 - 18 */ |
| 67 | u8 rising; /* bits 8 - 14 */ |
| 68 | u8 falling; /* bits 20 - 26. */ |
| 69 | |
| 70 | /* lane register offset 0x20. */ |
| 71 | int timC; /* bit 0 - 5, 19. */ |
| 72 | u16 timB; /* bits 8 - 13, 15 - 17. */ |
| 73 | } lanes[NUM_LANES]; |
| 74 | }; |
| 75 | |
| 76 | struct ramctr_timing_st; |
| 77 | |
| 78 | typedef struct ramctr_timing_st { |
| 79 | u16 spd_crc[NUM_CHANNELS][NUM_SLOTS]; |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 80 | int sandybridge; |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 81 | |
Patrick Rudolph | 77eaba3 | 2016-11-11 18:55:54 +0100 | [diff] [blame] | 82 | /* DDR base_freq = 100 Mhz / 133 Mhz */ |
| 83 | u8 base_freq; |
| 84 | |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 85 | u16 cas_supported; |
| 86 | /* tLatencies are in units of ns, scaled by x256 */ |
| 87 | u32 tCK; |
| 88 | u32 tAA; |
| 89 | u32 tWR; |
| 90 | u32 tRCD; |
| 91 | u32 tRRD; |
| 92 | u32 tRP; |
| 93 | u32 tRAS; |
| 94 | u32 tRFC; |
| 95 | u32 tWTR; |
| 96 | u32 tRTP; |
| 97 | u32 tFAW; |
Dan Elkouby | dabebc3 | 2018-04-13 18:47:10 +0300 | [diff] [blame] | 98 | u32 tCWL; |
| 99 | u32 tCMD; |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 100 | /* Latencies in terms of clock cycles |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 101 | * They are saved separately as they are needed for DRAM MRS commands */ |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 102 | u8 CAS; /* CAS read latency */ |
| 103 | u8 CWL; /* CAS write latency */ |
| 104 | |
| 105 | u32 tREFI; |
| 106 | u32 tMOD; |
| 107 | u32 tXSOffset; |
| 108 | u32 tWLO; |
| 109 | u32 tCKE; |
| 110 | u32 tXPDLL; |
| 111 | u32 tXP; |
| 112 | u32 tAONPD; |
| 113 | |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 114 | /* Bits [0..11] of PM_DLL_CONFIG: Master DLL wakeup delay timer. */ |
| 115 | u16 mdll_wake_delay; |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 116 | |
| 117 | u8 rankmap[NUM_CHANNELS]; |
| 118 | int ref_card_offset[NUM_CHANNELS]; |
| 119 | u32 mad_dimm[NUM_CHANNELS]; |
| 120 | int channel_size_mb[NUM_CHANNELS]; |
| 121 | u32 cmd_stretch[NUM_CHANNELS]; |
| 122 | |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 123 | int pi_code_offset; |
| 124 | int pi_coding_threshold; |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 125 | |
| 126 | int edge_offset[3]; |
| 127 | int timC_offset[3]; |
| 128 | |
| 129 | int extended_temperature_range; |
| 130 | int auto_self_refresh; |
| 131 | |
| 132 | int rank_mirror[NUM_CHANNELS][NUM_SLOTRANKS]; |
| 133 | |
| 134 | struct ram_rank_timings timings[NUM_CHANNELS][NUM_SLOTRANKS]; |
| 135 | |
| 136 | dimm_info info; |
| 137 | } ramctr_timing; |
| 138 | |
| 139 | #define SOUTHBRIDGE PCI_DEV(0, 0x1f, 0) |
| 140 | #define NORTHBRIDGE PCI_DEV(0, 0x0, 0) |
| 141 | #define FOR_ALL_LANES for (lane = 0; lane < NUM_LANES; lane++) |
| 142 | #define FOR_ALL_CHANNELS for (channel = 0; channel < NUM_CHANNELS; channel++) |
| 143 | #define FOR_ALL_POPULATED_RANKS for (slotrank = 0; slotrank < NUM_SLOTRANKS; slotrank++) if (ctrl->rankmap[channel] & (1 << slotrank)) |
| 144 | #define FOR_ALL_POPULATED_CHANNELS for (channel = 0; channel < NUM_CHANNELS; channel++) if (ctrl->rankmap[channel]) |
| 145 | #define MAX_EDGE_TIMING 71 |
| 146 | #define MAX_TIMC 127 |
| 147 | #define MAX_TIMB 511 |
| 148 | #define MAX_TIMA 127 |
| 149 | #define MAX_CAS 18 |
| 150 | #define MIN_CAS 4 |
| 151 | |
| 152 | #define MAKE_ERR ((channel<<16)|(slotrank<<8)|1) |
| 153 | #define GET_ERR_CHANNEL(x) (x>>16) |
| 154 | |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 155 | u8 get_CWL(u32 tCK); |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 156 | void dram_mrscommands(ramctr_timing *ctrl); |
| 157 | void program_timings(ramctr_timing *ctrl, int channel); |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 158 | void dram_find_common_params(ramctr_timing *ctrl); |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 159 | void dram_xover(ramctr_timing *ctrl); |
| 160 | void dram_timing_regs(ramctr_timing *ctrl); |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 161 | void dram_dimm_mapping(ramctr_timing *ctrl); |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 162 | void dram_dimm_set_mapping(ramctr_timing *ctrl); |
| 163 | void dram_zones(ramctr_timing *ctrl, int training); |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 164 | unsigned int get_mem_min_tck(void); |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 165 | void dram_memorymap(ramctr_timing *ctrl, int me_uma_size); |
| 166 | void dram_jedecreset(ramctr_timing *ctrl); |
| 167 | int read_training(ramctr_timing *ctrl); |
| 168 | int write_training(ramctr_timing *ctrl); |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 169 | int command_training(ramctr_timing *ctrl); |
| 170 | int discover_edges(ramctr_timing *ctrl); |
| 171 | int discover_edges_write(ramctr_timing *ctrl); |
| 172 | int discover_timC_write(ramctr_timing *ctrl); |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 173 | void normalize_training(ramctr_timing *ctrl); |
| 174 | void write_controller_mr(ramctr_timing *ctrl); |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 175 | int channel_test(ramctr_timing *ctrl); |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 176 | void set_scrambling_seed(ramctr_timing *ctrl); |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 177 | void set_4f8c(void); |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 178 | void prepare_training(ramctr_timing *ctrl); |
| 179 | void set_4008c(ramctr_timing *ctrl); |
| 180 | void set_normal_operation(ramctr_timing *ctrl); |
| 181 | void final_registers(ramctr_timing *ctrl); |
| 182 | void restore_timings(ramctr_timing *ctrl); |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 183 | |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 184 | int try_init_dram_ddr3_sandy(ramctr_timing *ctrl, int fast_boot, |
| 185 | int s3_resume, int me_uma_size); |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 186 | |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 187 | int try_init_dram_ddr3_ivy(ramctr_timing *ctrl, int fast_boot, |
| 188 | int s3_resume, int me_uma_size); |
| 189 | |
| 190 | #endif |