blob: 3946b67b2db4d99576d3e1dfaae1aa47d3572e41 [file] [log] [blame]
Timothy Pearson49168802015-03-13 12:48:31 -05001/*
2 * This file is part of the coreboot project.
3 *
Timothy Pearson49168802015-03-13 12:48:31 -05004 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
Timothy Pearson49168802015-03-13 12:48:31 -050012 */
13
Elyes HAOUASd2b9ec12018-10-27 09:41:02 +020014#include <arch/cpu.h>
Timothy Pearson49168802015-03-13 12:48:31 -050015#include <cpu/x86/msr.h>
16#include <cpu/amd/mtrr.h>
17
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020018#include <device/pci_ops.h>
Timothy Pearsonba2af2e2015-11-24 14:11:48 -060019#include <device/device.h>
20#include <device/pci.h>
21
Timothy Pearson86f4ca52015-03-13 13:27:58 -050022#include <cbmem.h>
23
Timothy Pearson49168802015-03-13 12:48:31 -050024#include "ram_calc.h"
25
Timothy Pearsonba2af2e2015-11-24 14:11:48 -060026static inline uint8_t is_fam15h(void)
27{
28 uint8_t fam15h = 0;
29 uint32_t family;
30
31 family = cpuid_eax(0x80000001);
32 family = ((family & 0xf00000) >> 16) | ((family & 0xf00) >> 8);
33
34 if (family >= 0x6f)
35 /* Family 15h or later */
36 fam15h = 1;
37
38 return fam15h;
39}
40
Timothy Pearson49168802015-03-13 12:48:31 -050041uint64_t get_uma_memory_size(uint64_t topmem)
42{
43 uint64_t uma_size = 0;
Julius Wernercd49cce2019-03-05 16:53:33 -080044 if (CONFIG(GFXUMA)) {
Timothy Pearson49168802015-03-13 12:48:31 -050045 /* refer to UMA Size Consideration in 780 BDG. */
Timothy Pearsone24f7d32015-03-19 00:03:59 -050046 if (topmem >= 0x40000000) /* 1GB and above system memory */
Timothy Pearson49168802015-03-13 12:48:31 -050047 uma_size = 0x10000000; /* 256M recommended UMA */
48
Timothy Pearsone24f7d32015-03-19 00:03:59 -050049 else if (topmem >= 0x20000000) /* 512M - 1023M system memory */
Timothy Pearson49168802015-03-13 12:48:31 -050050 uma_size = 0x8000000; /* 128M recommended UMA */
51
Timothy Pearsone24f7d32015-03-19 00:03:59 -050052 else if (topmem >= 0x10000000) /* 256M - 511M system memory */
Timothy Pearson49168802015-03-13 12:48:31 -050053 uma_size = 0x4000000; /* 64M recommended UMA */
54 }
55
56 return uma_size;
57}
Timothy Pearson86f4ca52015-03-13 13:27:58 -050058
Timothy Pearsonba2af2e2015-11-24 14:11:48 -060059uint64_t get_cc6_memory_size()
60{
61 uint8_t enable_cc6;
62
63 uint64_t cc6_size = 0;
64
65 if (is_fam15h()) {
66 enable_cc6 = 0;
67
Kyösti Mälkki23d4d9f2019-09-27 15:32:22 +030068#if ENV_PCI_SIMPLE_DEVICE
Timothy Pearsonba2af2e2015-11-24 14:11:48 -060069 if (pci_read_config32(PCI_DEV(0, 0x18, 2), 0x118) & (0x1 << 18))
70 enable_cc6 = 1;
71#else
Kyösti Mälkkic70eed12018-05-22 02:18:00 +030072 struct device *dct_dev = pcidev_on_root(0x18, 2);
Timothy Pearsonba2af2e2015-11-24 14:11:48 -060073 if (pci_read_config32(dct_dev, 0x118) & (0x1 << 18))
74 enable_cc6 = 1;
75#endif
76
77 if (enable_cc6) {
78 /* Preserve the maximum possible CC6 save region
79 * This needs to be kept in sync with
80 * amdfam10_domain_read_resources() in northbridge.c
81 */
82 cc6_size = 0x8000000;
83 }
84 }
85
86 return cc6_size;
87}
88
Timothy Pearson86f4ca52015-03-13 13:27:58 -050089void *cbmem_top(void)
90{
91 uint32_t topmem = rdmsr(TOP_MEM).lo;
92
Timothy Pearsonba2af2e2015-11-24 14:11:48 -060093 return (void *) topmem - get_uma_memory_size(topmem) - get_cc6_memory_size();
Timothy Pearson86f4ca52015-03-13 13:27:58 -050094}