Timothy Pearson | 4916880 | 2015-03-13 12:48:31 -0500 | [diff] [blame] | 1 | /* |
| 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 Pearson | 4916880 | 2015-03-13 12:48:31 -0500 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <cpu/cpu.h> |
| 18 | #include <cpu/x86/msr.h> |
| 19 | #include <cpu/amd/mtrr.h> |
| 20 | |
Timothy Pearson | 86f4ca5 | 2015-03-13 13:27:58 -0500 | [diff] [blame] | 21 | #include <cbmem.h> |
| 22 | |
Timothy Pearson | 4916880 | 2015-03-13 12:48:31 -0500 | [diff] [blame] | 23 | #include "ram_calc.h" |
| 24 | |
Timothy Pearson | 1c4508e | 2015-09-05 17:50:29 -0500 | [diff] [blame] | 25 | #if !IS_ENABLED(CONFIG_LATE_CBMEM_INIT) |
Timothy Pearson | 4916880 | 2015-03-13 12:48:31 -0500 | [diff] [blame] | 26 | uint64_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 Pearson | e24f7d3 | 2015-03-19 00:03:59 -0500 | [diff] [blame] | 31 | if (topmem >= 0x40000000) /* 1GB and above system memory */ |
Timothy Pearson | 4916880 | 2015-03-13 12:48:31 -0500 | [diff] [blame] | 32 | uma_size = 0x10000000; /* 256M recommended UMA */ |
| 33 | |
Timothy Pearson | e24f7d3 | 2015-03-19 00:03:59 -0500 | [diff] [blame] | 34 | else if (topmem >= 0x20000000) /* 512M - 1023M system memory */ |
Timothy Pearson | 4916880 | 2015-03-13 12:48:31 -0500 | [diff] [blame] | 35 | uma_size = 0x8000000; /* 128M recommended UMA */ |
| 36 | |
Timothy Pearson | e24f7d3 | 2015-03-19 00:03:59 -0500 | [diff] [blame] | 37 | else if (topmem >= 0x10000000) /* 256M - 511M system memory */ |
Timothy Pearson | 4916880 | 2015-03-13 12:48:31 -0500 | [diff] [blame] | 38 | uma_size = 0x4000000; /* 64M recommended UMA */ |
| 39 | } |
| 40 | |
| 41 | return uma_size; |
| 42 | } |
Timothy Pearson | 86f4ca5 | 2015-03-13 13:27:58 -0500 | [diff] [blame] | 43 | |
| 44 | void *cbmem_top(void) |
| 45 | { |
| 46 | uint32_t topmem = rdmsr(TOP_MEM).lo; |
| 47 | |
| 48 | return (void *) topmem - get_uma_memory_size(topmem); |
| 49 | } |
Timothy Pearson | 1c4508e | 2015-09-05 17:50:29 -0500 | [diff] [blame] | 50 | #endif |