blob: 9ac2c993f83ad757168ab42f1fe8555fe7cb3b3a [file] [log] [blame]
Timothy Pearson49168802015-03-13 12:48:31 -05001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2015 Timothy Pearson <tpearson@raptorengineeringinc.com>, Raptor Engineering
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.
Timothy Pearson49168802015-03-13 12:48:31 -050015 */
16
17#include <cpu/cpu.h>
18#include <cpu/x86/msr.h>
19#include <cpu/amd/mtrr.h>
20
Timothy Pearson86f4ca52015-03-13 13:27:58 -050021#include <cbmem.h>
22
Timothy Pearson49168802015-03-13 12:48:31 -050023#include "ram_calc.h"
24
Timothy Pearson1c4508e2015-09-05 17:50:29 -050025#if !IS_ENABLED(CONFIG_LATE_CBMEM_INIT)
Timothy Pearson49168802015-03-13 12:48:31 -050026uint64_t get_uma_memory_size(uint64_t topmem)
27{
28 uint64_t uma_size = 0;
29 if (IS_ENABLED(CONFIG_GFXUMA)) {
30 /* refer to UMA Size Consideration in 780 BDG. */
Timothy Pearsone24f7d32015-03-19 00:03:59 -050031 if (topmem >= 0x40000000) /* 1GB and above system memory */
Timothy Pearson49168802015-03-13 12:48:31 -050032 uma_size = 0x10000000; /* 256M recommended UMA */
33
Timothy Pearsone24f7d32015-03-19 00:03:59 -050034 else if (topmem >= 0x20000000) /* 512M - 1023M system memory */
Timothy Pearson49168802015-03-13 12:48:31 -050035 uma_size = 0x8000000; /* 128M recommended UMA */
36
Timothy Pearsone24f7d32015-03-19 00:03:59 -050037 else if (topmem >= 0x10000000) /* 256M - 511M system memory */
Timothy Pearson49168802015-03-13 12:48:31 -050038 uma_size = 0x4000000; /* 64M recommended UMA */
39 }
40
41 return uma_size;
42}
Timothy Pearson86f4ca52015-03-13 13:27:58 -050043
44void *cbmem_top(void)
45{
46 uint32_t topmem = rdmsr(TOP_MEM).lo;
47
48 return (void *) topmem - get_uma_memory_size(topmem);
49}
Timothy Pearson1c4508e2015-09-05 17:50:29 -050050#endif