blob: 7502ca83ffea2826351391d920025612fdbebba0 [file] [log] [blame]
Angel Ponsf23ae0b2020-04-02 23:48:12 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Damien Rothbedbd672016-01-18 13:59:26 -07002
Kyösti Mälkki2446c1e2020-07-09 07:13:37 +03003#include <amdblocks/biosram.h>
Eric Biedermanfcd5ace2004-10-14 19:29:29 +00004#include <console/console.h>
5#include <device/device.h>
Tobias Diedrichc2924672010-11-09 22:31:11 +00006#include <arch/cpu.h>
Arthur Heymans7e272022021-10-28 10:13:39 +02007#include <cpu/cpu.h>
Eric Biedermanfcd5ace2004-10-14 19:29:29 +00008#include <cpu/x86/mtrr.h>
Kyösti Mälkki190011e2013-03-25 12:48:49 +02009#include <cpu/x86/msr.h>
Eric Biedermanfcd5ace2004-10-14 19:29:29 +000010#include <cpu/amd/mtrr.h>
11#include <cpu/x86/cache.h>
Eric Biedermanfcd5ace2004-10-14 19:29:29 +000012
Kyösti Mälkkidbc47392012-08-05 12:11:40 +030013/* These will likely move to some device node or cbmem. */
14static uint64_t amd_topmem = 0;
15static uint64_t amd_topmem2 = 0;
16
17uint64_t bsp_topmem(void)
18{
19 return amd_topmem;
20}
21
22uint64_t bsp_topmem2(void)
23{
24 return amd_topmem2;
25}
26
27/* Take a copy of BSP CPUs TOP_MEM and TOP_MEM2 registers,
28 * so they can be distributed to AP CPUs. Not strictly MTRRs,
29 * but this is not that bad a place to have this code.
30 */
31void setup_bsp_ramtop(void)
32{
33 msr_t msr, msr2;
34
35 /* TOP_MEM: the top of DRAM below 4G */
36 msr = rdmsr(TOP_MEM);
37 printk(BIOS_INFO,
38 "%s, TOP MEM: msr.lo = 0x%08x, msr.hi = 0x%08x\n",
39 __func__, msr.lo, msr.hi);
40
41 /* TOP_MEM2: the top of DRAM above 4G */
42 msr2 = rdmsr(TOP_MEM2);
43 printk(BIOS_INFO,
44 "%s, TOP MEM2: msr.lo = 0x%08x, msr.hi = 0x%08x\n",
45 __func__, msr2.lo, msr2.hi);
46
Elyes HAOUAS168ef392017-06-27 22:54:42 +020047 amd_topmem = (uint64_t) msr.hi << 32 | msr.lo;
48 amd_topmem2 = (uint64_t) msr2.hi << 32 | msr2.lo;
Kyösti Mälkkidbc47392012-08-05 12:11:40 +030049}
50
Kyösti Mälkki17bb2252017-04-19 19:55:54 +030051void add_uma_resource_below_tolm(struct device *nb, int idx)
52{
53 uint32_t topmem = bsp_topmem();
Kyösti Mälkki70d92b92017-04-19 19:57:01 +030054 uint32_t top_of_cacheable = restore_top_of_low_cacheable();
Kyösti Mälkki17bb2252017-04-19 19:55:54 +030055
56 if (top_of_cacheable == topmem)
57 return;
58
59 uint32_t uma_base = top_of_cacheable;
60 uint32_t uma_size = topmem - top_of_cacheable;
61
62 printk(BIOS_INFO, "%s: uma size 0x%08x, memory start 0x%08x\n",
63 __func__, uma_size, uma_base);
64
65 uma_resource(nb, idx, uma_base / KiB, uma_size / KiB);
66}