Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2014 Google Inc. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | */ |
| 19 | |
| 20 | #include <arch/io.h> |
| 21 | #include <cbmem.h> |
| 22 | #include <device/pci.h> |
| 23 | #include <broadwell/pci_devs.h> |
| 24 | #include <broadwell/systemagent.h> |
| 25 | |
Kyösti Mälkki | 13a845a | 2014-11-10 19:12:53 +0200 | [diff] [blame] | 26 | unsigned long get_top_of_ram(void) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 27 | { |
| 28 | /* |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 29 | * Base of DPR is top of usable DRAM below 4GiB. The register has |
| 30 | * 1 MiB alignment and reports the TOP of the range, the base |
| 31 | * must be calculated from the size in MiB in bits 11:4. |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 32 | */ |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 33 | u32 dpr = pci_read_config32(SA_DEV_ROOT, DPR); |
| 34 | u32 tom = dpr & ~((1 << 20) - 1); |
| 35 | |
| 36 | /* Subtract DMA Protected Range size if enabled */ |
| 37 | if (dpr & DPR_EPM) |
| 38 | tom -= (dpr & DPR_SIZE_MASK) << 16; |
| 39 | |
| 40 | return (unsigned long)tom; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 41 | } |