blob: d8023f808c4f460c809f6845f868e7ffda723288 [file] [log] [blame]
Marc Jones8ae8c882007-12-19 01:32:08 +00001/*
Stefan Reinauer7e61e452008-01-18 10:35:56 +00002 * This file is part of the coreboot project.
Marc Jones8ae8c882007-12-19 01:32:08 +00003 *
Timothy Pearson3c206782015-02-14 03:32:21 -06004 * Copyright (C) 2015 Timothy Pearson <tpearson@raptorengineeringinc.com>, Raptor Engineering
Marc Jones8ae8c882007-12-19 01:32:08 +00005 * 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 Jones8ae8c882007-12-19 01:32:08 +000015 */
16
Stefan Reinauer6f57b512010-07-08 16:41:05 +000017
18#if (CONFIG_DIMM_SUPPORT & 0x000F)!=0x0005 /* not needed for AMD_FAM10_DDR3 */
Marc Jones8ae8c882007-12-19 01:32:08 +000019static void print_tx(const char *strval, u32 val)
20{
Uwe Hermann01ce6012010-03-05 10:03:50 +000021#if CONFIG_DEBUG_RAM_SETUP
Myles Watson362db612010-04-08 15:12:18 +000022 printk(BIOS_DEBUG, "%s%08x\n", strval, val);
Marc Jones8ae8c882007-12-19 01:32:08 +000023#endif
24}
25
Marc Jones8ae8c882007-12-19 01:32:08 +000026static void print_t(const char *strval)
27{
Uwe Hermann01ce6012010-03-05 10:03:50 +000028#if CONFIG_DEBUG_RAM_SETUP
Myles Watson362db612010-04-08 15:12:18 +000029 printk(BIOS_DEBUG, "%s", strval);
Marc Jones8ae8c882007-12-19 01:32:08 +000030#endif
31}
Timothy Pearsonb8a355d2015-09-05 17:55:58 -050032#endif
Zheng Baoeb75f652010-04-23 17:32:48 +000033
Timothy Pearson3c206782015-02-14 03:32:21 -060034static 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 Pearson730a0432015-10-16 13:51:51 -050041static inline void fam15h_switch_dct(uint32_t dev, uint8_t dct)
Timothy Pearson3c206782015-02-14 03:32:21 -060042{
Timothy Pearson730a0432015-10-16 13:51:51 -050043 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
51static 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
61static 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
73static 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
85static 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
98static 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
111static 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
123static 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
135static 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
147static 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 Pearson3c206782015-02-14 03:32:21 -0600155 /* Return limited maximum RAM frequency */
156 if (IS_ENABLED(CONFIG_DIMM_DDR2)) {
Timothy Pearson99e1a672015-09-05 18:00:27 -0500157 if (IS_ENABLED(CONFIG_DIMM_REGISTERED) && registered) {
Timothy Pearson3c206782015-02-14 03:32:21 -0600158 /* K10 BKDG Rev. 3.62 Table 53 */
159 if (count > 2) {
160 /* Limit to DDR2-533 */
161 if (freq > 266) {
162 freq = 266;
Timothy Pearson99e1a672015-09-05 18:00:27 -0500163 print_tf(__func__, ": More than 2 registered DIMMs on channel; limiting to DDR2-533\n");
Timothy Pearson3c206782015-02-14 03:32:21 -0600164 }
165 }
Timothy Pearson99e1a672015-09-05 18:00:27 -0500166 } else {
Timothy Pearson3c206782015-02-14 03:32:21 -0600167 /* K10 BKDG Rev. 3.62 Table 52 */
168 if (count > 1) {
169 /* Limit to DDR2-800 */
170 if (freq > 400) {
171 freq = 400;
Timothy Pearson99e1a672015-09-05 18:00:27 -0500172 print_tf(__func__, ": More than 1 unbuffered DIMM on channel; limiting to DDR2-800\n");
Timothy Pearson3c206782015-02-14 03:32:21 -0600173 }
174 }
175 }
Timothy Pearson99e1a672015-09-05 18:00:27 -0500176 } else if (IS_ENABLED(CONFIG_DIMM_DDR3)) {
Timothy Pearson730a0432015-10-16 13:51:51 -0500177 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 Pearson99e1a672015-09-05 18:00:27 -0500238 }
239 } else {
Timothy Pearson730a0432015-10-16 13:51:51 -0500240 /* 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 Pearson99e1a672015-09-05 18:00:27 -0500317 }
318 }
319 } else {
Timothy Pearson730a0432015-10-16 13:51:51 -0500320 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 Pearson99e1a672015-09-05 18:00:27 -0500348 }
349 }
Timothy Pearson3c206782015-02-14 03:32:21 -0600350 }
351
352 return freq;
353}
354
Zheng Baoeb75f652010-04-23 17:32:48 +0000355#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 Pearson4ea0cc02015-09-05 18:39:34 -0500363#if IS_ENABLED(CONFIG_HAVE_ACPI_RESUME)
364#include "../amdmct/mct_ddr3/s3utils.c"
365#endif
366
Zheng Baoeb75f652010-04-23 17:32:48 +0000367#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 Bao69436e12011-01-06 02:18:12 +0000390#include "../amdmct/mct_ddr3/modtrd.c"
Zheng Baoeb75f652010-04-23 17:32:48 +0000391
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 Bao2ca2f172011-03-28 04:29:14 +0000403//C32
404#elif CONFIG_CPU_SOCKET_TYPE == 0x14
405#include "../amdmct/mct_ddr3/mctardk5.c"
Timothy Pearson99e1a672015-09-05 18:00:27 -0500406//G34
407#elif CONFIG_CPU_SOCKET_TYPE == 0x15
408#include "../amdmct/mct_ddr3/mctardk5.c"
Zheng Baoeb75f652010-04-23 17:32:48 +0000409#endif
410
411#else /* DDR2 */
412
Marc Jones8ae8c882007-12-19 01:32:08 +0000413#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 Baodb8b4112009-07-01 07:01:32 +0000435#if CONFIG_CPU_SOCKET_TYPE == 0x10
Marc Jones8ae8c882007-12-19 01:32:08 +0000436//L1
437#include "../amdmct/mct/mctardk3.c"
Zheng Baodb8b4112009-07-01 07:01:32 +0000438#elif CONFIG_CPU_SOCKET_TYPE == 0x11
Marc Jones8ae8c882007-12-19 01:32:08 +0000439//AM2
440#include "../amdmct/mct/mctardk4.c"
441//#elif SYSTEM_TYPE == MOBILE
442//s1g1
443//#include "../amdmct/mct/mctardk5.c"
444#endif
445
Zheng Baoeb75f652010-04-23 17:32:48 +0000446#endif /* DDR2 */
447
Stefan Reinauerfd4f4132013-06-19 12:25:44 -0700448#include <arch/early_variables.h>
Patrick Georgibbc880e2012-11-20 18:20:56 +0100449struct sys_info sysinfo_car CAR_GLOBAL;
450
Marc Jones8ae8c882007-12-19 01:32:08 +0000451int mctRead_SPD(u32 smaddr, u32 reg)
452{
453 return spd_read_byte(smaddr, reg);
454}
455
456
457void mctSMBhub_Init(u32 node)
458{
Patrick Georgibbc880e2012-11-20 18:20:56 +0100459 struct sys_info *sysinfo = &sysinfo_car;
Marc Jones8ae8c882007-12-19 01:32:08 +0000460 struct mem_controller *ctrl = &( sysinfo->ctrl[node] );
461 activate_spd_rom(ctrl);
462}
463
464
465void mctGet_DIMMAddr(struct DCTStatStruc *pDCTstat, u32 node)
466{
467 int j;
Patrick Georgibbc880e2012-11-20 18:20:56 +0100468 struct sys_info *sysinfo = &sysinfo_car;
Marc Jones8ae8c882007-12-19 01:32:08 +0000469 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 Pearson730a0432015-10-16 13:51:51 -0500478#if IS_ENABLED(CONFIG_SET_FIDVID)
Xavi Drudis Ferranadb23a52011-02-28 00:10:37 +0000479static u8 mctGetProcessorPackageType(void) {
480 /* FIXME: I guess this belongs wherever mctGetLogicalCPUID ends up ? */
Timothy Pearson730a0432015-10-16 13:51:51 -0500481 u32 BrandId = cpuid_ebx(0x80000001);
482 return (u8)((BrandId >> 28) & 0x0F);
Xavi Drudis Ferranadb23a52011-02-28 00:10:37 +0000483}
Timothy Pearson730a0432015-10-16 13:51:51 -0500484#endif
Marc Jones8ae8c882007-12-19 01:32:08 +0000485
Myles Watson075fbe82010-04-15 05:19:29 +0000486static void raminit_amdmct(struct sys_info *sysinfo)
Marc Jones8ae8c882007-12-19 01:32:08 +0000487{
488 struct MCTStatStruc *pMCTstat = &(sysinfo->MCTstat);
489 struct DCTStatStruc *pDCTstatA = sysinfo->DCTstatA;
490
Stefan Reinauer65b72ab2015-01-05 12:59:54 -0800491 printk(BIOS_DEBUG, "raminit_amdmct begin:\n");
Marc Jones8ae8c882007-12-19 01:32:08 +0000492
493 mctAutoInitMCT_D(pMCTstat, pDCTstatA);
494
Stefan Reinauer65b72ab2015-01-05 12:59:54 -0800495 printk(BIOS_DEBUG, "raminit_amdmct end:\n");
Marc Jones8ae8c882007-12-19 01:32:08 +0000496}
Timothy Pearson22564082015-03-27 22:49:18 -0500497
498static void amdmct_cbmem_store_info(struct sys_info *sysinfo)
499{
Timothy Pearson46b22712015-04-12 14:11:27 -0500500 if (!sysinfo)
501 return;
502
Timothy Pearson22564082015-03-27 22:49:18 -0500503 /* Save memory info structures for use in ramstage */
504 size_t i;
Timothy Pearson22564082015-03-27 22:49:18 -0500505 struct DCTStatStruc *pDCTstatA = NULL;
506
Timothy Pearson4ea0cc02015-09-05 18:39:34 -0500507 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 Pearson22564082015-03-27 22:49:18 -0500513
Timothy Pearson4ea0cc02015-09-05 18:39:34 -0500514 printk(BIOS_DEBUG, "%s: Storing AMDMCT configuration in CBMEM\n", __func__);
Timothy Pearson22564082015-03-27 22:49:18 -0500515
Timothy Pearson4ea0cc02015-09-05 18:39:34 -0500516 /* Initialize memory */
517 memset(mem_info, 0, sizeof(struct amdmct_memory_info));
Timothy Pearson22564082015-03-27 22:49:18 -0500518
Timothy Pearson4ea0cc02015-09-05 18:39:34 -0500519 /* 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 Pearson46b22712015-04-12 14:11:27 -0500527
Timothy Pearson4ea0cc02015-09-05 18:39:34 -0500528 /* Zero out invalid/unused pointers */
Timothy Pearson46b22712015-04-12 14:11:27 -0500529#if IS_ENABLED(CONFIG_DIMM_DDR3)
Timothy Pearson4ea0cc02015-09-05 18:39:34 -0500530 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 Pearson46b22712015-04-12 14:11:27 -0500535#endif
Timothy Pearson4ea0cc02015-09-05 18:39:34 -0500536 }
Timothy Pearson22564082015-03-27 22:49:18 -0500537}