| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
#include <bdk.h> |
| 40 |
#include <bdk-coreboot.h> |
| 41 |
#include <libbdk-hal/bdk-utils.h> |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
int __bdk_dram_get_num_lmc(bdk_node_t node) |
| 52 |
{ |
| 53 |
if (CAVIUM_IS_MODEL(CAVIUM_CN88XX)) |
| 54 |
{ |
| 55 |
BDK_CSR_INIT(lmcx_dll_ctl2, node, BDK_LMCX_DLL_CTL2(2)); |
| 56 |
return (lmcx_dll_ctl2.s.intf_en) ? 4 : 2; |
| 57 |
} |
| 58 |
else if (CAVIUM_IS_MODEL(CAVIUM_CN83XX)) |
| 59 |
{ |
| 60 |
BDK_CSR_INIT(lmcx_dll_ctl1, node, BDK_LMCX_DLL_CTL2(1)); |
| 61 |
return (lmcx_dll_ctl1.s.intf_en) ? 2 : 1; |
| 62 |
} |
| 63 |
else if (CAVIUM_IS_MODEL(CAVIUM_CN81XX)) |
| 64 |
{ |
| 65 |
return 1; |
| 66 |
} |
| 67 |
else if (CAVIUM_IS_MODEL(CAVIUM_CN93XX)) |
| 68 |
{ |
| 69 |
BDK_CSR_INIT(lmcx_dll_ctl1, node, BDK_LMCX_DLL_CTL2(2)); |
| 70 |
if (lmcx_dll_ctl1.s.intf_en) |
| 71 |
return 3; |
| 72 |
lmcx_dll_ctl1.u = BDK_CSR_READ(node, BDK_LMCX_DLL_CTL2(1)); |
| 73 |
return (lmcx_dll_ctl1.s.intf_en) ? 2 : 1; |
| 74 |
} |
| 75 |
bdk_error("__bdk_dram_get_num_lmc() needs update for this chip\n"); |
| 76 |
return 1; |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
static int __bdk_dram_is_lmc_in_dreset(bdk_node_t node, int lmc) |
| 88 |
{ |
| 89 |
BDK_CSR_INIT(lmcx_dll_ctl2, node, BDK_LMCX_DLL_CTL2(lmc)); |
| 90 |
return (lmcx_dll_ctl2.s.dreset != 0) ? 1 : 0; |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
uint32_t __bdk_dram_get_row_mask(bdk_node_t node, int lmc) |
| 100 |
{ |
| 101 |
|
| 102 |
if (__bdk_dram_is_lmc_in_dreset(node, lmc)) |
| 103 |
return 0; |
| 104 |
BDK_CSR_INIT(lmcx_config, node, BDK_LMCX_CONFIG(lmc)); |
| 105 |
int numbits = 14 + lmcx_config.s.pbank_lsb - lmcx_config.s.row_lsb - lmcx_config.s.rank_ena; |
| 106 |
return ((1ul << numbits) - 1); |
| 107 |
} |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
uint32_t __bdk_dram_get_col_mask(bdk_node_t node, int lmc) |
| 116 |
{ |
| 117 |
|
| 118 |
if (__bdk_dram_is_lmc_in_dreset(node, lmc)) |
| 119 |
return 0; |
| 120 |
BDK_CSR_INIT(lmcx_config, node, BDK_LMCX_CONFIG(lmc)); |
| 121 |
int numbits = 11 + lmcx_config.s.row_lsb - __bdk_dram_get_num_bank_bits(node, lmc); |
| 122 |
return ((1ul << numbits) - 1); |
| 123 |
} |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
int __bdk_dram_get_num_bank_bits(bdk_node_t node, int lmc) |
| 134 |
{ |
| 135 |
|
| 136 |
if (__bdk_dram_is_lmc_in_dreset(node, lmc)) |
| 137 |
return 0; |
| 138 |
BDK_CSR_INIT(lmcx_config, node, BDK_LMCX_CONFIG(lmc)); |
| 139 |
int bank_width = (__bdk_dram_is_ddr4(node, lmc) && (lmcx_config.s.bg2_enable)) ? 4 : 3; |
| 140 |
return bank_width; |
| 141 |
} |
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
int __bdk_dram_is_ddr4(bdk_node_t node, int lmc) |
| 151 |
{ |
| 152 |
|
| 153 |
if (__bdk_dram_is_lmc_in_dreset(node, lmc)) |
| 154 |
return 0; |
| 155 |
if (CAVIUM_IS_MODEL(CAVIUM_CN9XXX)) |
| 156 |
return 1; |
| 157 |
BDK_CSR_INIT(lmcx_ddr_pll_ctl, node, BDK_LMCX_DDR_PLL_CTL(lmc)); |
| 158 |
return (lmcx_ddr_pll_ctl.cn83xx.ddr4_mode != 0); |
| 159 |
} |
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
int __bdk_dram_is_rdimm(bdk_node_t node, int lmc) |
| 169 |
{ |
| 170 |
|
| 171 |
if (__bdk_dram_is_lmc_in_dreset(node, lmc)) |
| 172 |
return 0; |
| 173 |
BDK_CSR_INIT(lmcx_control, node, BDK_LMCX_CONTROL(lmc)); |
| 174 |
return (lmcx_control.s.rdimm_ena != 0); |
| 175 |
} |
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
uint64_t bdk_dram_get_size_mbytes(int node) |
| 186 |
{ |
| 187 |
|
| 188 |
if (!__bdk_is_dram_enabled(node)) |
| 189 |
return 0; |
| 190 |
|
| 191 |
uint64_t memsize = 0; |
| 192 |
const int num_dram_controllers = __bdk_dram_get_num_lmc(node); |
| 193 |
for (int lmc = 0; lmc < num_dram_controllers; lmc++) |
| 194 |
{ |
| 195 |
|
| 196 |
if (__bdk_dram_is_lmc_in_dreset(node, lmc)) |
| 197 |
return 0; |
| 198 |
BDK_CSR_INIT(lmcx_config, node, BDK_LMCX_CONFIG(lmc)); |
| 199 |
int num_ranks = bdk_pop(lmcx_config.s.init_status); |
| 200 |
uint64_t rank_size = 1ull << (28 + lmcx_config.s.pbank_lsb - lmcx_config.s.rank_ena); |
| 201 |
memsize += rank_size * num_ranks; |
| 202 |
} |
| 203 |
return memsize >> 20; |
| 204 |
} |
| 205 |
|