| 1 |
|
| 2 |
|
| 3 |
#include <northbridge/intel/haswell/haswell.h> |
| 4 |
#include <types.h> |
| 5 |
|
| 6 |
#include "raminit_native.h" |
| 7 |
|
| 8 |
static void ldat_write_cacheline( |
| 9 |
const struct sysinfo *const ctrl, |
| 10 |
const uint8_t chunk, |
| 11 |
const uint16_t start, |
| 12 |
const uint64_t data) |
| 13 |
{ |
| 14 |
for (uint8_t channel = 0; channel < NUM_CHANNELS; channel++) { |
| 15 |
if (!does_ch_exist(ctrl, channel)) |
| 16 |
continue; |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
mchbar_write32(QCLK_ch_LDAT_DATA_IN_x(channel, 0), data & UINT32_MAX); |
| 23 |
mchbar_write32(QCLK_ch_LDAT_DATA_IN_x(channel, 1), data >> 32); |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
const union ldat_sdat_reg ldat_sdat = { |
| 30 |
.bank_sel = chunk, |
| 31 |
.mode = 1, |
| 32 |
}; |
| 33 |
mchbar_write32(QCLK_ch_LDAT_SDAT(channel), ldat_sdat.raw); |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
const union ldat_pdat_reg ldat_pdat = { |
| 41 |
.fast_addr = MIN(start, 0xfff), |
| 42 |
.cmd_b = 8, |
| 43 |
}; |
| 44 |
mchbar_write32(QCLK_ch_LDAT_PDAT(channel), ldat_pdat.raw); |
| 45 |
} |
| 46 |
} |
| 47 |
|
| 48 |
static void clear_ldat_mode(const struct sysinfo *const ctrl) |
| 49 |
{ |
| 50 |
for (uint8_t channel = 0; channel < NUM_CHANNELS; channel++) |
| 51 |
mchbar_write32(QCLK_ch_LDAT_SDAT(channel), 0); |
| 52 |
} |
| 53 |
|
| 54 |
void write_wdb_fixed_pat( |
| 55 |
const struct sysinfo *const ctrl, |
| 56 |
const uint8_t patterns[], |
| 57 |
const uint8_t pat_mask[], |
| 58 |
const uint8_t spread, |
| 59 |
const uint16_t start) |
| 60 |
{ |
| 61 |
for (uint8_t chunk = 0; chunk < WDB_CACHE_LINE_SIZE; chunk++) { |
| 62 |
uint64_t data = 0; |
| 63 |
for (uint8_t b = 0; b < 64; b++) { |
| 64 |
const uint8_t beff = b % spread; |
| 65 |
const uint8_t burst = patterns[pat_mask[beff]]; |
| 66 |
if (burst & BIT(chunk)) |
| 67 |
data |= 1ULL << b; |
| 68 |
} |
| 69 |
ldat_write_cacheline(ctrl, chunk, start, data); |
| 70 |
} |
| 71 |
clear_ldat_mode(ctrl); |
| 72 |
} |
| 73 |
|
| 74 |
static inline uint32_t rol_u32(const uint32_t val) |
| 75 |
{ |
| 76 |
return (val << 1) | ((val >> 31) & 1); |
| 77 |
} |
| 78 |
|
| 79 |
void write_wdb_va_pat( |
| 80 |
const struct sysinfo *const ctrl, |
| 81 |
const uint32_t agg_mask, |
| 82 |
const uint32_t vic_mask, |
| 83 |
const uint8_t vic_rot, |
| 84 |
const uint16_t start) |
| 85 |
{ |
| 86 |
static const uint8_t va_mask_to_compressed[4] = {0xaa, 0xc0, 0xcc, 0xf0}; |
| 87 |
uint32_t v_mask = vic_mask; |
| 88 |
uint32_t a_mask = agg_mask; |
| 89 |
for (uint8_t v = 0; v < vic_rot; v++) { |
| 90 |
uint8_t compressed[32] = {0}; |
| 91 |
|
| 92 |
for (uint8_t b = 0; b < ARRAY_SIZE(compressed); b++) { |
| 93 |
const uint8_t vic = !!(v_mask & BIT(b)); |
| 94 |
const uint8_t agg = !!(a_mask & BIT(b)); |
| 95 |
const uint8_t index = !vic << 1 | agg << 0; |
| 96 |
compressed[b] = va_mask_to_compressed[index]; |
| 97 |
} |
| 98 |
for (uint8_t chunk = 0; chunk < WDB_CACHE_LINE_SIZE; chunk++) { |
| 99 |
uint32_t data = 0; |
| 100 |
for (uint8_t b = 0; b < ARRAY_SIZE(compressed); b++) |
| 101 |
data |= !!(compressed[b] & BIT(chunk)) << b; |
| 102 |
|
| 103 |
const uint64_t data64 = (uint64_t)data << 32 | data; |
| 104 |
ldat_write_cacheline(ctrl, chunk, start + v, data64); |
| 105 |
} |
| 106 |
v_mask = rol_u32(v_mask); |
| 107 |
a_mask = rol_u32(a_mask); |
| 108 |
} |
| 109 |
clear_ldat_mode(ctrl); |
| 110 |
} |
| 111 |
|
| 112 |
void program_wdb_lfsr(const struct sysinfo *ctrl, const bool cleanup) |
| 113 |
{ |
| 114 |
|
| 115 |
const uint32_t cleanup_seeds[NUM_WDB_CL_MUX_SEEDS] = { 0xaaaaaa, 0xcccccc, 0xf0f0f0 }; |
| 116 |
const uint32_t regular_seeds[NUM_WDB_CL_MUX_SEEDS] = { 0xa10ca1, 0xef0d08, 0xad0a1e }; |
| 117 |
const uint32_t *seeds = cleanup ? cleanup_seeds : regular_seeds; |
| 118 |
|
| 119 |
for (uint8_t channel = 0; channel < NUM_CHANNELS; channel++) { |
| 120 |
if (!does_ch_exist(ctrl, channel)) |
| 121 |
continue; |
| 122 |
|
| 123 |
for (uint8_t i = 0; i < NUM_WDB_CL_MUX_SEEDS; i++) { |
| 124 |
mchbar_write32(REUT_ch_PAT_WDB_CL_MUX_RD_x(channel, i), seeds[i]); |
| 125 |
mchbar_write32(REUT_ch_PAT_WDB_CL_MUX_WR_x(channel, i), seeds[i]); |
| 126 |
} |
| 127 |
} |
| 128 |
} |
| 129 |
|
| 130 |
void setup_wdb(const struct sysinfo *ctrl) |
| 131 |
{ |
| 132 |
const uint32_t amask[9] = { |
| 133 |
0x86186186, 0x18618618, 0x30c30c30, |
| 134 |
0xa28a28a2, 0x8a28a28a, 0x14514514, |
| 135 |
0x28a28a28, 0x92492492, 0x24924924, |
| 136 |
}; |
| 137 |
const uint32_t vmask = 0x41041041; |
| 138 |
|
| 139 |
|
| 140 |
write_wdb_va_pat(ctrl, 0, BASIC_VA_PAT_SPREAD_8, 8, 0); |
| 141 |
|
| 142 |
|
| 143 |
for (uint8_t a = 0; a < ARRAY_SIZE(amask); a++) |
| 144 |
write_wdb_va_pat(ctrl, amask[a], vmask, 6, 8 + a * 6); |
| 145 |
|
| 146 |
program_wdb_lfsr(ctrl, false); |
| 147 |
for (uint8_t channel = 0; channel < NUM_CHANNELS; channel++) { |
| 148 |
if (!does_ch_exist(ctrl, channel)) |
| 149 |
continue; |
| 150 |
|
| 151 |
const union reut_pat_cl_mux_lmn_reg wdb_cl_mux_lmn = { |
| 152 |
.en_sweep_freq = 1, |
| 153 |
.l_counter = 1, |
| 154 |
.m_counter = 1, |
| 155 |
.n_counter = 10, |
| 156 |
}; |
| 157 |
mchbar_write32(REUT_ch_PAT_WDB_CL_MUX_LMN(channel), wdb_cl_mux_lmn.raw); |
| 158 |
} |
| 159 |
} |