Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 1 | /* |
Stefan Reinauer | 7e61e45 | 2008-01-18 10:35:56 +0000 | [diff] [blame] | 2 | * This file is part of the coreboot project. |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 3 | * |
Timothy Pearson | 3c20678 | 2015-02-14 03:32:21 -0600 | [diff] [blame] | 4 | * Copyright (C) 2015 Timothy Pearson <tpearson@raptorengineeringinc.com>, Raptor Engineering |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 5 | * Copyright (C) 2007 Advanced Micro Devices, Inc. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 15 | */ |
| 16 | |
Stefan Reinauer | 6f57b51 | 2010-07-08 16:41:05 +0000 | [diff] [blame] | 17 | |
| 18 | #if (CONFIG_DIMM_SUPPORT & 0x000F)!=0x0005 /* not needed for AMD_FAM10_DDR3 */ |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 19 | static void print_tx(const char *strval, u32 val) |
| 20 | { |
Uwe Hermann | 01ce601 | 2010-03-05 10:03:50 +0000 | [diff] [blame] | 21 | #if CONFIG_DEBUG_RAM_SETUP |
Myles Watson | 362db61 | 2010-04-08 15:12:18 +0000 | [diff] [blame] | 22 | printk(BIOS_DEBUG, "%s%08x\n", strval, val); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 23 | #endif |
| 24 | } |
| 25 | |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 26 | static void print_t(const char *strval) |
| 27 | { |
Uwe Hermann | 01ce601 | 2010-03-05 10:03:50 +0000 | [diff] [blame] | 28 | #if CONFIG_DEBUG_RAM_SETUP |
Myles Watson | 362db61 | 2010-04-08 15:12:18 +0000 | [diff] [blame] | 29 | printk(BIOS_DEBUG, "%s", strval); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 30 | #endif |
| 31 | } |
Timothy Pearson | b8a355d | 2015-09-05 17:55:58 -0500 | [diff] [blame] | 32 | #endif |
Zheng Bao | eb75f65 | 2010-04-23 17:32:48 +0000 | [diff] [blame] | 33 | |
Timothy Pearson | 3c20678 | 2015-02-14 03:32:21 -0600 | [diff] [blame] | 34 | static void print_tf(const char *func, const char *strval) |
| 35 | { |
| 36 | #if CONFIG_DEBUG_RAM_SETUP |
| 37 | printk(BIOS_DEBUG, "%s: %s", func, strval); |
| 38 | #endif |
| 39 | } |
| 40 | |
Timothy Pearson | 730a043 | 2015-10-16 13:51:51 -0500 | [diff] [blame^] | 41 | static inline void fam15h_switch_dct(uint32_t dev, uint8_t dct) |
Timothy Pearson | 3c20678 | 2015-02-14 03:32:21 -0600 | [diff] [blame] | 42 | { |
Timothy Pearson | 730a043 | 2015-10-16 13:51:51 -0500 | [diff] [blame^] | 43 | uint32_t dword; |
| 44 | |
| 45 | dword = Get_NB32(dev, 0x10c); |
| 46 | dword &= ~0x1; |
| 47 | dword |= (dct & 0x1); |
| 48 | Set_NB32(dev, 0x10c, dword); |
| 49 | } |
| 50 | |
| 51 | static inline void fam15h_switch_nb_pstate_config_reg(uint32_t dev, uint8_t nb_pstate) |
| 52 | { |
| 53 | uint32_t dword; |
| 54 | |
| 55 | dword = Get_NB32(dev, 0x10c); |
| 56 | dword &= ~(0x3 << 4); |
| 57 | dword |= (nb_pstate & 0x3) << 4; |
| 58 | Set_NB32(dev, 0x10c, dword); |
| 59 | } |
| 60 | |
| 61 | static inline uint32_t Get_NB32_DCT(uint32_t dev, uint8_t dct, uint32_t reg) |
| 62 | { |
| 63 | if (is_fam15h()) { |
| 64 | /* Obtain address of function 0x1 */ |
| 65 | uint32_t dev_map = (dev & (~(0x7 << 12))) | (0x1 << 12); |
| 66 | fam15h_switch_dct(dev_map, dct); |
| 67 | return Get_NB32(dev, reg); |
| 68 | } else { |
| 69 | return Get_NB32(dev, (0x100 * dct) + reg); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | static inline void Set_NB32_DCT(uint32_t dev, uint8_t dct, uint32_t reg, uint32_t val) |
| 74 | { |
| 75 | if (is_fam15h()) { |
| 76 | /* Obtain address of function 0x1 */ |
| 77 | uint32_t dev_map = (dev & (~(0x7 << 12))) | (0x1 << 12); |
| 78 | fam15h_switch_dct(dev_map, dct); |
| 79 | Set_NB32(dev, reg, val); |
| 80 | } else { |
| 81 | Set_NB32(dev, (0x100 * dct) + reg, val); |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | static inline uint32_t Get_NB32_DCT_NBPstate(uint32_t dev, uint8_t dct, uint8_t nb_pstate, uint32_t reg) |
| 86 | { |
| 87 | if (is_fam15h()) { |
| 88 | /* Obtain address of function 0x1 */ |
| 89 | uint32_t dev_map = (dev & (~(0x7 << 12))) | (0x1 << 12); |
| 90 | fam15h_switch_dct(dev_map, dct); |
| 91 | fam15h_switch_nb_pstate_config_reg(dev_map, nb_pstate); |
| 92 | return Get_NB32(dev, reg); |
| 93 | } else { |
| 94 | return Get_NB32(dev, (0x100 * dct) + reg); |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | static inline void Set_NB32_DCT_NBPstate(uint32_t dev, uint8_t dct, uint8_t nb_pstate, uint32_t reg, uint32_t val) |
| 99 | { |
| 100 | if (is_fam15h()) { |
| 101 | /* Obtain address of function 0x1 */ |
| 102 | uint32_t dev_map = (dev & (~(0x7 << 12))) | (0x1 << 12); |
| 103 | fam15h_switch_dct(dev_map, dct); |
| 104 | fam15h_switch_nb_pstate_config_reg(dev_map, nb_pstate); |
| 105 | Set_NB32(dev, reg, val); |
| 106 | } else { |
| 107 | Set_NB32(dev, (0x100 * dct) + reg, val); |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | static inline uint32_t Get_NB32_index_wait_DCT(uint32_t dev, uint8_t dct, uint32_t index_reg, uint32_t index) |
| 112 | { |
| 113 | if (is_fam15h()) { |
| 114 | /* Obtain address of function 0x1 */ |
| 115 | uint32_t dev_map = (dev & (~(0x7 << 12))) | (0x1 << 12); |
| 116 | fam15h_switch_dct(dev_map, dct); |
| 117 | return Get_NB32_index_wait(dev, index_reg, index); |
| 118 | } else { |
| 119 | return Get_NB32_index_wait(dev, (0x100 * dct) + index_reg, index); |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | static inline void Set_NB32_index_wait_DCT(uint32_t dev, uint8_t dct, uint32_t index_reg, uint32_t index, uint32_t data) |
| 124 | { |
| 125 | if (is_fam15h()) { |
| 126 | /* Obtain address of function 0x1 */ |
| 127 | uint32_t dev_map = (dev & (~(0x7 << 12))) | (0x1 << 12); |
| 128 | fam15h_switch_dct(dev_map, dct); |
| 129 | Set_NB32_index_wait(dev, index_reg, index, data); |
| 130 | } else { |
| 131 | Set_NB32_index_wait(dev, (0x100 * dct) + index_reg, index, data); |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | static uint16_t voltage_index_to_mv(uint8_t index) |
| 136 | { |
| 137 | if (index & 0x8) |
| 138 | return 1150; |
| 139 | if (index & 0x4) |
| 140 | return 1250; |
| 141 | else if (index & 0x2) |
| 142 | return 1350; |
| 143 | else |
| 144 | return 1500; |
| 145 | } |
| 146 | |
| 147 | static uint16_t mct_MaxLoadFreq(uint8_t count, uint8_t highest_rank_count, uint8_t registered, uint8_t voltage, uint16_t freq) |
| 148 | { |
| 149 | /* FIXME |
| 150 | * Mainboards need to be able to specify the maximum number of DIMMs installable per channel |
| 151 | * For now assume a maximum of 2 DIMMs per channel can be installed |
| 152 | */ |
| 153 | uint8_t MaxDimmsInstallable = 2; |
| 154 | |
Timothy Pearson | 3c20678 | 2015-02-14 03:32:21 -0600 | [diff] [blame] | 155 | /* Return limited maximum RAM frequency */ |
| 156 | if (IS_ENABLED(CONFIG_DIMM_DDR2)) { |
Timothy Pearson | 99e1a67 | 2015-09-05 18:00:27 -0500 | [diff] [blame] | 157 | if (IS_ENABLED(CONFIG_DIMM_REGISTERED) && registered) { |
Timothy Pearson | 3c20678 | 2015-02-14 03:32:21 -0600 | [diff] [blame] | 158 | /* K10 BKDG Rev. 3.62 Table 53 */ |
| 159 | if (count > 2) { |
| 160 | /* Limit to DDR2-533 */ |
| 161 | if (freq > 266) { |
| 162 | freq = 266; |
Timothy Pearson | 99e1a67 | 2015-09-05 18:00:27 -0500 | [diff] [blame] | 163 | print_tf(__func__, ": More than 2 registered DIMMs on channel; limiting to DDR2-533\n"); |
Timothy Pearson | 3c20678 | 2015-02-14 03:32:21 -0600 | [diff] [blame] | 164 | } |
| 165 | } |
Timothy Pearson | 99e1a67 | 2015-09-05 18:00:27 -0500 | [diff] [blame] | 166 | } else { |
Timothy Pearson | 3c20678 | 2015-02-14 03:32:21 -0600 | [diff] [blame] | 167 | /* K10 BKDG Rev. 3.62 Table 52 */ |
| 168 | if (count > 1) { |
| 169 | /* Limit to DDR2-800 */ |
| 170 | if (freq > 400) { |
| 171 | freq = 400; |
Timothy Pearson | 99e1a67 | 2015-09-05 18:00:27 -0500 | [diff] [blame] | 172 | print_tf(__func__, ": More than 1 unbuffered DIMM on channel; limiting to DDR2-800\n"); |
Timothy Pearson | 3c20678 | 2015-02-14 03:32:21 -0600 | [diff] [blame] | 173 | } |
| 174 | } |
| 175 | } |
Timothy Pearson | 99e1a67 | 2015-09-05 18:00:27 -0500 | [diff] [blame] | 176 | } else if (IS_ENABLED(CONFIG_DIMM_DDR3)) { |
Timothy Pearson | 730a043 | 2015-10-16 13:51:51 -0500 | [diff] [blame^] | 177 | if (voltage == 0) { |
| 178 | printk(BIOS_DEBUG, "%s: WARNING: Mainboard DDR3 voltage unknown, assuming 1.5V!\n", __func__); |
| 179 | voltage = 0x1; |
| 180 | } |
| 181 | |
| 182 | if (is_fam15h()) { |
| 183 | if (IS_ENABLED(CONFIG_DIMM_REGISTERED) && registered) { |
| 184 | /* Fam15h BKDG Rev. 3.14 Table 27 */ |
| 185 | if (voltage & 0x4) { |
| 186 | /* 1.25V */ |
| 187 | if (count > 1) { |
| 188 | if (highest_rank_count > 1) { |
| 189 | /* Limit to DDR3-1066 */ |
| 190 | if (freq > 533) { |
| 191 | freq = 533; |
| 192 | printk(BIOS_DEBUG, "%s: More than 1 registered DIMM on %dmV channel; limiting to DDR3-1066\n", __func__, voltage_index_to_mv(voltage)); |
| 193 | } |
| 194 | } else { |
| 195 | /* Limit to DDR3-1333 */ |
| 196 | if (freq > 666) { |
| 197 | freq = 666; |
| 198 | printk(BIOS_DEBUG, "%s: More than 1 registered DIMM on %dmV channel; limiting to DDR3-1333\n", __func__, voltage_index_to_mv(voltage)); |
| 199 | } |
| 200 | } |
| 201 | } else { |
| 202 | /* Limit to DDR3-1333 */ |
| 203 | if (freq > 666) { |
| 204 | freq = 666; |
| 205 | printk(BIOS_DEBUG, "%s: 1 registered DIMM on %dmV channel; limiting to DDR3-1333\n", __func__, voltage_index_to_mv(voltage)); |
| 206 | } |
| 207 | } |
| 208 | } else if (voltage & 0x2) { |
| 209 | /* 1.35V */ |
| 210 | if (count > 1) { |
| 211 | /* Limit to DDR3-1333 */ |
| 212 | if (freq > 666) { |
| 213 | freq = 666; |
| 214 | printk(BIOS_DEBUG, "%s: More than 1 registered DIMM on %dmV channel; limiting to DDR3-1333\n", __func__, voltage_index_to_mv(voltage)); |
| 215 | } |
| 216 | } else { |
| 217 | /* Limit to DDR3-1600 */ |
| 218 | if (freq > 800) { |
| 219 | freq = 800; |
| 220 | printk(BIOS_DEBUG, "%s: 1 registered DIMM on %dmV channel; limiting to DDR3-1600\n", __func__, voltage_index_to_mv(voltage)); |
| 221 | } |
| 222 | } |
| 223 | } else if (voltage & 0x1) { |
| 224 | /* 1.50V */ |
| 225 | if (count > 1) { |
| 226 | /* Limit to DDR3-1600 */ |
| 227 | if (freq > 800) { |
| 228 | freq = 800; |
| 229 | printk(BIOS_DEBUG, "%s: More than 1 registered DIMM on %dmV channel; limiting to DDR3-1600\n", __func__, voltage_index_to_mv(voltage)); |
| 230 | } |
| 231 | } else { |
| 232 | /* Limit to DDR3-1866 */ |
| 233 | if (freq > 933) { |
| 234 | freq = 933; |
| 235 | printk(BIOS_DEBUG, "%s: 1 registered DIMM on %dmV channel; limiting to DDR3-1866\n", __func__, voltage_index_to_mv(voltage)); |
| 236 | } |
| 237 | } |
Timothy Pearson | 99e1a67 | 2015-09-05 18:00:27 -0500 | [diff] [blame] | 238 | } |
| 239 | } else { |
Timothy Pearson | 730a043 | 2015-10-16 13:51:51 -0500 | [diff] [blame^] | 240 | /* Fam15h BKDG Rev. 3.14 Table 26 */ |
| 241 | if (voltage & 0x4) { |
| 242 | /* 1.25V */ |
| 243 | if (count > 1) { |
| 244 | if (highest_rank_count > 1) { |
| 245 | /* Limit to DDR3-1066 */ |
| 246 | if (freq > 533) { |
| 247 | freq = 533; |
| 248 | printk(BIOS_DEBUG, "%s: More than 1 unbuffered DIMM on %dmV channel; limiting to DDR3-1066\n", __func__, voltage_index_to_mv(voltage)); |
| 249 | } |
| 250 | } else { |
| 251 | /* Limit to DDR3-1333 */ |
| 252 | if (freq > 666) { |
| 253 | freq = 666; |
| 254 | printk(BIOS_DEBUG, "%s: More than 1 unbuffered DIMM on %dmV channel; limiting to DDR3-1333\n", __func__, voltage_index_to_mv(voltage)); |
| 255 | } |
| 256 | } |
| 257 | } else { |
| 258 | /* Limit to DDR3-1333 */ |
| 259 | if (freq > 666) { |
| 260 | freq = 666; |
| 261 | printk(BIOS_DEBUG, "%s: 1 unbuffered DIMM on %dmV channel; limiting to DDR3-1333\n", __func__, voltage_index_to_mv(voltage)); |
| 262 | } |
| 263 | } |
| 264 | } else if (voltage & 0x2) { |
| 265 | /* 1.35V */ |
| 266 | if (MaxDimmsInstallable > 1) { |
| 267 | /* Limit to DDR3-1333 */ |
| 268 | if (freq > 666) { |
| 269 | freq = 666; |
| 270 | printk(BIOS_DEBUG, "%s: More than 1 unbuffered DIMM on %dmV channel; limiting to DDR3-1333\n", __func__, voltage_index_to_mv(voltage)); |
| 271 | } |
| 272 | } else { |
| 273 | /* Limit to DDR3-1600 */ |
| 274 | if (freq > 800) { |
| 275 | freq = 800; |
| 276 | printk(BIOS_DEBUG, "%s: 1 unbuffered DIMM on %dmV channel; limiting to DDR3-1600\n", __func__, voltage_index_to_mv(voltage)); |
| 277 | } |
| 278 | } |
| 279 | } else if (voltage & 0x1) { |
| 280 | if (MaxDimmsInstallable == 1) { |
| 281 | if (count > 1) { |
| 282 | /* Limit to DDR3-1600 */ |
| 283 | if (freq > 800) { |
| 284 | freq = 800; |
| 285 | printk(BIOS_DEBUG, "%s: More than 1 unbuffered DIMM on %dmV channel; limiting to DDR3-1600\n", __func__, voltage_index_to_mv(voltage)); |
| 286 | } |
| 287 | } else { |
| 288 | /* Limit to DDR3-1866 */ |
| 289 | if (freq > 933) { |
| 290 | freq = 933; |
| 291 | printk(BIOS_DEBUG, "%s: 1 unbuffered DIMM on %dmV channel; limiting to DDR3-1866\n", __func__, voltage_index_to_mv(voltage)); |
| 292 | } |
| 293 | } |
| 294 | } else { |
| 295 | if (count > 1) { |
| 296 | if (highest_rank_count > 1) { |
| 297 | /* Limit to DDR3-1333 */ |
| 298 | if (freq > 666) { |
| 299 | freq = 666; |
| 300 | printk(BIOS_DEBUG, "%s: More than 1 unbuffered DIMM on %dmV channel; limiting to DDR3-1333\n", __func__, voltage_index_to_mv(voltage)); |
| 301 | } |
| 302 | } else { |
| 303 | /* Limit to DDR3-1600 */ |
| 304 | if (freq > 800) { |
| 305 | freq = 800; |
| 306 | printk(BIOS_DEBUG, "%s: More than 1 unbuffered DIMM on %dmV channel; limiting to DDR3-1600\n", __func__, voltage_index_to_mv(voltage)); |
| 307 | } |
| 308 | } |
| 309 | } else { |
| 310 | /* Limit to DDR3-1600 */ |
| 311 | if (freq > 800) { |
| 312 | freq = 800; |
| 313 | printk(BIOS_DEBUG, "%s: 1 unbuffered DIMM on %dmV channel; limiting to DDR3-1600\n", __func__, voltage_index_to_mv(voltage)); |
| 314 | } |
| 315 | } |
| 316 | } |
Timothy Pearson | 99e1a67 | 2015-09-05 18:00:27 -0500 | [diff] [blame] | 317 | } |
| 318 | } |
| 319 | } else { |
Timothy Pearson | 730a043 | 2015-10-16 13:51:51 -0500 | [diff] [blame^] | 320 | if (IS_ENABLED(CONFIG_DIMM_REGISTERED) && registered) { |
| 321 | /* K10 BKDG Rev. 3.62 Table 34 */ |
| 322 | if (count > 2) { |
| 323 | /* Limit to DDR3-800 */ |
| 324 | if (freq > 400) { |
| 325 | freq = 400; |
| 326 | printk(BIOS_DEBUG, "%s: More than 2 registered DIMMs on %dmV channel; limiting to DDR3-800\n", __func__, voltage_index_to_mv(voltage)); |
| 327 | } |
| 328 | } else if (count == 2) { |
| 329 | /* Limit to DDR3-1066 */ |
| 330 | if (freq > 533) { |
| 331 | freq = 533; |
| 332 | printk(BIOS_DEBUG, "%s: 2 registered DIMMs on %dmV channel; limiting to DDR3-1066\n", __func__, voltage_index_to_mv(voltage)); |
| 333 | } |
| 334 | } else { |
| 335 | /* Limit to DDR3-1333 */ |
| 336 | if (freq > 666) { |
| 337 | freq = 666; |
| 338 | printk(BIOS_DEBUG, "%s: 1 registered DIMM on %dmV channel; limiting to DDR3-1333\n", __func__, voltage_index_to_mv(voltage)); |
| 339 | } |
| 340 | } |
| 341 | } else { |
| 342 | /* K10 BKDG Rev. 3.62 Table 33 */ |
| 343 | /* Limit to DDR3-1333 */ |
| 344 | if (freq > 666) { |
| 345 | freq = 666; |
| 346 | printk(BIOS_DEBUG, "%s: unbuffered DIMMs on %dmV channel; limiting to DDR3-1333\n", __func__, voltage_index_to_mv(voltage)); |
| 347 | } |
Timothy Pearson | 99e1a67 | 2015-09-05 18:00:27 -0500 | [diff] [blame] | 348 | } |
| 349 | } |
Timothy Pearson | 3c20678 | 2015-02-14 03:32:21 -0600 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | return freq; |
| 353 | } |
| 354 | |
Zheng Bao | eb75f65 | 2010-04-23 17:32:48 +0000 | [diff] [blame] | 355 | #if (CONFIG_DIMM_SUPPORT & 0x000F)==0x0005 /* AMD_FAM10_DDR3 */ |
| 356 | #include "amdfam10.h" |
| 357 | #include "../amdmct/wrappers/mcti.h" |
| 358 | #include "../amdmct/amddefs.h" |
| 359 | #include "../amdmct/mct_ddr3/mwlc_d.h" |
| 360 | #include "../amdmct/mct_ddr3/mct_d.h" |
| 361 | #include "../amdmct/mct_ddr3/mct_d_gcc.h" |
| 362 | |
Timothy Pearson | 4ea0cc0 | 2015-09-05 18:39:34 -0500 | [diff] [blame] | 363 | #if IS_ENABLED(CONFIG_HAVE_ACPI_RESUME) |
| 364 | #include "../amdmct/mct_ddr3/s3utils.c" |
| 365 | #endif |
| 366 | |
Zheng Bao | eb75f65 | 2010-04-23 17:32:48 +0000 | [diff] [blame] | 367 | #include "../amdmct/wrappers/mcti_d.c" |
| 368 | #include "../amdmct/mct_ddr3/mct_d.c" |
| 369 | |
| 370 | #include "../amdmct/mct_ddr3/mctmtr_d.c" |
| 371 | #include "../amdmct/mct_ddr3/mctcsi_d.c" |
| 372 | #include "../amdmct/mct_ddr3/mctecc_d.c" |
| 373 | #include "../amdmct/mct_ddr3/mctdqs_d.c" |
| 374 | #include "../amdmct/mct_ddr3/mctsrc.c" |
| 375 | #include "../amdmct/mct_ddr3/mctsdi.c" |
| 376 | #include "../amdmct/mct_ddr3/mctproc.c" |
| 377 | #include "../amdmct/mct_ddr3/mctprob.c" |
| 378 | #include "../amdmct/mct_ddr3/mcthwl.c" |
| 379 | #include "../amdmct/mct_ddr3/mctwl.c" |
| 380 | #include "../amdmct/mct_ddr3/mport_d.c" |
| 381 | #include "../amdmct/mct_ddr3/mutilc_d.c" |
| 382 | #include "../amdmct/mct_ddr3/modtrdim.c" |
| 383 | #include "../amdmct/mct_ddr3/mhwlc_d.c" |
| 384 | #include "../amdmct/mct_ddr3/mctrci.c" |
| 385 | #include "../amdmct/mct_ddr3/mctsrc1p.c" |
| 386 | #include "../amdmct/mct_ddr3/mcttmrl.c" |
| 387 | #include "../amdmct/mct_ddr3/mcthdi.c" |
| 388 | #include "../amdmct/mct_ddr3/mctndi_d.c" |
| 389 | #include "../amdmct/mct_ddr3/mctchi_d.c" |
Zheng Bao | 69436e1 | 2011-01-06 02:18:12 +0000 | [diff] [blame] | 390 | #include "../amdmct/mct_ddr3/modtrd.c" |
Zheng Bao | eb75f65 | 2010-04-23 17:32:48 +0000 | [diff] [blame] | 391 | |
| 392 | #if CONFIG_CPU_SOCKET_TYPE == 0x10 |
| 393 | //TODO: S1G1? |
| 394 | #elif CONFIG_CPU_SOCKET_TYPE == 0x11 |
| 395 | //AM3 |
| 396 | #include "../amdmct/mct_ddr3/mctardk5.c" |
| 397 | #elif CONFIG_CPU_SOCKET_TYPE == 0x12 |
| 398 | //F (1207), Fr2, G (1207) |
| 399 | #include "../amdmct/mct_ddr3/mctardk6.c" |
| 400 | #elif CONFIG_CPU_SOCKET_TYPE == 0x13 |
| 401 | //ASB2 |
| 402 | #include "../amdmct/mct_ddr3/mctardk5.c" |
Zheng Bao | 2ca2f17 | 2011-03-28 04:29:14 +0000 | [diff] [blame] | 403 | //C32 |
| 404 | #elif CONFIG_CPU_SOCKET_TYPE == 0x14 |
| 405 | #include "../amdmct/mct_ddr3/mctardk5.c" |
Timothy Pearson | 99e1a67 | 2015-09-05 18:00:27 -0500 | [diff] [blame] | 406 | //G34 |
| 407 | #elif CONFIG_CPU_SOCKET_TYPE == 0x15 |
| 408 | #include "../amdmct/mct_ddr3/mctardk5.c" |
Zheng Bao | eb75f65 | 2010-04-23 17:32:48 +0000 | [diff] [blame] | 409 | #endif |
| 410 | |
| 411 | #else /* DDR2 */ |
| 412 | |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 413 | #include "amdfam10.h" |
| 414 | #include "../amdmct/wrappers/mcti.h" |
| 415 | #include "../amdmct/amddefs.h" |
| 416 | #include "../amdmct/mct/mct_d.h" |
| 417 | #include "../amdmct/mct/mct_d_gcc.h" |
| 418 | |
| 419 | #include "../amdmct/wrappers/mcti_d.c" |
| 420 | #include "../amdmct/mct/mct_d.c" |
| 421 | |
| 422 | |
| 423 | #include "../amdmct/mct/mctmtr_d.c" |
| 424 | #include "../amdmct/mct/mctcsi_d.c" |
| 425 | #include "../amdmct/mct/mctecc_d.c" |
| 426 | #include "../amdmct/mct/mctpro_d.c" |
| 427 | #include "../amdmct/mct/mctdqs_d.c" |
| 428 | #include "../amdmct/mct/mctsrc.c" |
| 429 | #include "../amdmct/mct/mctsrc1p.c" |
| 430 | #include "../amdmct/mct/mcttmrl.c" |
| 431 | #include "../amdmct/mct/mcthdi.c" |
| 432 | #include "../amdmct/mct/mctndi_d.c" |
| 433 | #include "../amdmct/mct/mctchi_d.c" |
| 434 | |
Zheng Bao | db8b411 | 2009-07-01 07:01:32 +0000 | [diff] [blame] | 435 | #if CONFIG_CPU_SOCKET_TYPE == 0x10 |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 436 | //L1 |
| 437 | #include "../amdmct/mct/mctardk3.c" |
Zheng Bao | db8b411 | 2009-07-01 07:01:32 +0000 | [diff] [blame] | 438 | #elif CONFIG_CPU_SOCKET_TYPE == 0x11 |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 439 | //AM2 |
| 440 | #include "../amdmct/mct/mctardk4.c" |
| 441 | //#elif SYSTEM_TYPE == MOBILE |
| 442 | //s1g1 |
| 443 | //#include "../amdmct/mct/mctardk5.c" |
| 444 | #endif |
| 445 | |
Zheng Bao | eb75f65 | 2010-04-23 17:32:48 +0000 | [diff] [blame] | 446 | #endif /* DDR2 */ |
| 447 | |
Stefan Reinauer | fd4f413 | 2013-06-19 12:25:44 -0700 | [diff] [blame] | 448 | #include <arch/early_variables.h> |
Patrick Georgi | bbc880e | 2012-11-20 18:20:56 +0100 | [diff] [blame] | 449 | struct sys_info sysinfo_car CAR_GLOBAL; |
| 450 | |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 451 | int mctRead_SPD(u32 smaddr, u32 reg) |
| 452 | { |
| 453 | return spd_read_byte(smaddr, reg); |
| 454 | } |
| 455 | |
| 456 | |
| 457 | void mctSMBhub_Init(u32 node) |
| 458 | { |
Patrick Georgi | bbc880e | 2012-11-20 18:20:56 +0100 | [diff] [blame] | 459 | struct sys_info *sysinfo = &sysinfo_car; |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 460 | struct mem_controller *ctrl = &( sysinfo->ctrl[node] ); |
| 461 | activate_spd_rom(ctrl); |
| 462 | } |
| 463 | |
| 464 | |
| 465 | void mctGet_DIMMAddr(struct DCTStatStruc *pDCTstat, u32 node) |
| 466 | { |
| 467 | int j; |
Patrick Georgi | bbc880e | 2012-11-20 18:20:56 +0100 | [diff] [blame] | 468 | struct sys_info *sysinfo = &sysinfo_car; |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 469 | struct mem_controller *ctrl = &( sysinfo->ctrl[node] ); |
| 470 | |
| 471 | for(j=0;j<DIMM_SOCKETS;j++) { |
| 472 | pDCTstat->DIMMAddr[j*2] = ctrl->spd_addr[j] & 0xff; |
| 473 | pDCTstat->DIMMAddr[j*2+1] = ctrl->spd_addr[DIMM_SOCKETS + j] & 0xff; |
| 474 | } |
| 475 | |
| 476 | } |
| 477 | |
Timothy Pearson | 730a043 | 2015-10-16 13:51:51 -0500 | [diff] [blame^] | 478 | #if IS_ENABLED(CONFIG_SET_FIDVID) |
Xavi Drudis Ferran | adb23a5 | 2011-02-28 00:10:37 +0000 | [diff] [blame] | 479 | static u8 mctGetProcessorPackageType(void) { |
| 480 | /* FIXME: I guess this belongs wherever mctGetLogicalCPUID ends up ? */ |
Timothy Pearson | 730a043 | 2015-10-16 13:51:51 -0500 | [diff] [blame^] | 481 | u32 BrandId = cpuid_ebx(0x80000001); |
| 482 | return (u8)((BrandId >> 28) & 0x0F); |
Xavi Drudis Ferran | adb23a5 | 2011-02-28 00:10:37 +0000 | [diff] [blame] | 483 | } |
Timothy Pearson | 730a043 | 2015-10-16 13:51:51 -0500 | [diff] [blame^] | 484 | #endif |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 485 | |
Myles Watson | 075fbe8 | 2010-04-15 05:19:29 +0000 | [diff] [blame] | 486 | static void raminit_amdmct(struct sys_info *sysinfo) |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 487 | { |
| 488 | struct MCTStatStruc *pMCTstat = &(sysinfo->MCTstat); |
| 489 | struct DCTStatStruc *pDCTstatA = sysinfo->DCTstatA; |
| 490 | |
Stefan Reinauer | 65b72ab | 2015-01-05 12:59:54 -0800 | [diff] [blame] | 491 | printk(BIOS_DEBUG, "raminit_amdmct begin:\n"); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 492 | |
| 493 | mctAutoInitMCT_D(pMCTstat, pDCTstatA); |
| 494 | |
Stefan Reinauer | 65b72ab | 2015-01-05 12:59:54 -0800 | [diff] [blame] | 495 | printk(BIOS_DEBUG, "raminit_amdmct end:\n"); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 496 | } |
Timothy Pearson | 2256408 | 2015-03-27 22:49:18 -0500 | [diff] [blame] | 497 | |
| 498 | static void amdmct_cbmem_store_info(struct sys_info *sysinfo) |
| 499 | { |
Timothy Pearson | 46b2271 | 2015-04-12 14:11:27 -0500 | [diff] [blame] | 500 | if (!sysinfo) |
| 501 | return; |
| 502 | |
Timothy Pearson | 2256408 | 2015-03-27 22:49:18 -0500 | [diff] [blame] | 503 | /* Save memory info structures for use in ramstage */ |
| 504 | size_t i; |
Timothy Pearson | 2256408 | 2015-03-27 22:49:18 -0500 | [diff] [blame] | 505 | struct DCTStatStruc *pDCTstatA = NULL; |
| 506 | |
Timothy Pearson | 4ea0cc0 | 2015-09-05 18:39:34 -0500 | [diff] [blame] | 507 | if (!acpi_is_wakeup_s3()) { |
| 508 | /* Allocate memory */ |
| 509 | struct amdmct_memory_info *mem_info; |
| 510 | mem_info = cbmem_add(CBMEM_ID_AMDMCT_MEMINFO, sizeof(struct amdmct_memory_info)); |
| 511 | if (!mem_info) |
| 512 | return; |
Timothy Pearson | 2256408 | 2015-03-27 22:49:18 -0500 | [diff] [blame] | 513 | |
Timothy Pearson | 4ea0cc0 | 2015-09-05 18:39:34 -0500 | [diff] [blame] | 514 | printk(BIOS_DEBUG, "%s: Storing AMDMCT configuration in CBMEM\n", __func__); |
Timothy Pearson | 2256408 | 2015-03-27 22:49:18 -0500 | [diff] [blame] | 515 | |
Timothy Pearson | 4ea0cc0 | 2015-09-05 18:39:34 -0500 | [diff] [blame] | 516 | /* Initialize memory */ |
| 517 | memset(mem_info, 0, sizeof(struct amdmct_memory_info)); |
Timothy Pearson | 2256408 | 2015-03-27 22:49:18 -0500 | [diff] [blame] | 518 | |
Timothy Pearson | 4ea0cc0 | 2015-09-05 18:39:34 -0500 | [diff] [blame] | 519 | /* Copy data */ |
| 520 | memcpy(&mem_info->mct_stat, &sysinfo->MCTstat, sizeof(struct MCTStatStruc)); |
| 521 | for (i = 0; i < MAX_NODES_SUPPORTED; i++) { |
| 522 | pDCTstatA = sysinfo->DCTstatA + i; |
| 523 | memcpy(&mem_info->dct_stat[i], pDCTstatA, sizeof(struct DCTStatStruc)); |
| 524 | } |
| 525 | mem_info->ecc_enabled = mctGet_NVbits(NV_ECC_CAP); |
| 526 | mem_info->ecc_scrub_rate = mctGet_NVbits(NV_DramBKScrub); |
Timothy Pearson | 46b2271 | 2015-04-12 14:11:27 -0500 | [diff] [blame] | 527 | |
Timothy Pearson | 4ea0cc0 | 2015-09-05 18:39:34 -0500 | [diff] [blame] | 528 | /* Zero out invalid/unused pointers */ |
Timothy Pearson | 46b2271 | 2015-04-12 14:11:27 -0500 | [diff] [blame] | 529 | #if IS_ENABLED(CONFIG_DIMM_DDR3) |
Timothy Pearson | 4ea0cc0 | 2015-09-05 18:39:34 -0500 | [diff] [blame] | 530 | for (i = 0; i < MAX_NODES_SUPPORTED; i++) { |
| 531 | mem_info->dct_stat[i].C_MCTPtr = NULL; |
| 532 | mem_info->dct_stat[i].C_DCTPtr[0] = NULL; |
| 533 | mem_info->dct_stat[i].C_DCTPtr[1] = NULL; |
| 534 | } |
Timothy Pearson | 46b2271 | 2015-04-12 14:11:27 -0500 | [diff] [blame] | 535 | #endif |
Timothy Pearson | 4ea0cc0 | 2015-09-05 18:39:34 -0500 | [diff] [blame] | 536 | } |
Timothy Pearson | 2256408 | 2015-03-27 22:49:18 -0500 | [diff] [blame] | 537 | } |