Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; version 2 of the License. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 13 | */ |
| 14 | |
Kyösti Mälkki | 326edeb | 2019-07-24 13:27:46 +0300 | [diff] [blame] | 15 | #define __SIMPLE_DEVICE__ |
| 16 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 17 | #include <cbmem.h> |
Kyösti Mälkki | 8f09688d | 2019-08-15 11:29:15 +0300 | [diff] [blame] | 18 | #include <cpu/x86/smm.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 19 | #include <device/pci.h> |
Kyösti Mälkki | 26a682c | 2019-08-02 06:13:22 +0300 | [diff] [blame] | 20 | #include <device/pci_ops.h> |
Julius Werner | 4ee4bd5 | 2014-10-20 13:46:39 -0700 | [diff] [blame] | 21 | #include <soc/pci_devs.h> |
| 22 | #include <soc/systemagent.h> |
Kyösti Mälkki | 26a682c | 2019-08-02 06:13:22 +0300 | [diff] [blame] | 23 | #include <stdint.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 24 | |
Kyösti Mälkki | f1e3c76 | 2014-12-22 12:28:07 +0200 | [diff] [blame] | 25 | static uintptr_t dpr_region_start(void) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 26 | { |
| 27 | /* |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 28 | * Base of DPR is top of usable DRAM below 4GiB. The register has |
| 29 | * 1 MiB alignment and reports the TOP of the range, the base |
| 30 | * must be calculated from the size in MiB in bits 11:4. |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 31 | */ |
Kyösti Mälkki | f1e3c76 | 2014-12-22 12:28:07 +0200 | [diff] [blame] | 32 | uintptr_t dpr = pci_read_config32(SA_DEV_ROOT, DPR); |
| 33 | uintptr_t tom = dpr & ~((1 << 20) - 1); |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 34 | |
| 35 | /* Subtract DMA Protected Range size if enabled */ |
| 36 | if (dpr & DPR_EPM) |
| 37 | tom -= (dpr & DPR_SIZE_MASK) << 16; |
| 38 | |
Kyösti Mälkki | f1e3c76 | 2014-12-22 12:28:07 +0200 | [diff] [blame] | 39 | return tom; |
| 40 | } |
| 41 | |
Arthur Heymans | 340e4b8 | 2019-10-23 17:25:58 +0200 | [diff] [blame] | 42 | void *cbmem_top_chipset(void) |
Kyösti Mälkki | f1e3c76 | 2014-12-22 12:28:07 +0200 | [diff] [blame] | 43 | { |
| 44 | return (void *) dpr_region_start(); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 45 | } |
Kyösti Mälkki | 26a682c | 2019-08-02 06:13:22 +0300 | [diff] [blame] | 46 | |
Kyösti Mälkki | 8f09688d | 2019-08-15 11:29:15 +0300 | [diff] [blame] | 47 | void smm_region(uintptr_t *start, size_t *size) |
Kyösti Mälkki | 26a682c | 2019-08-02 06:13:22 +0300 | [diff] [blame] | 48 | { |
Kyösti Mälkki | 8f09688d | 2019-08-15 11:29:15 +0300 | [diff] [blame] | 49 | uintptr_t tseg = pci_read_config32(PCI_DEV(0, 0, 0), TSEG); |
| 50 | uintptr_t bgsm = pci_read_config32(PCI_DEV(0, 0, 0), BGSM); |
Kyösti Mälkki | 26a682c | 2019-08-02 06:13:22 +0300 | [diff] [blame] | 51 | |
Kyösti Mälkki | 8f09688d | 2019-08-15 11:29:15 +0300 | [diff] [blame] | 52 | tseg = ALIGN_DOWN(tseg, 1 * MiB); |
| 53 | bgsm = ALIGN_DOWN(bgsm, 1 * MiB); |
| 54 | *start = tseg; |
| 55 | *size = bgsm - tseg; |
Kyösti Mälkki | 26a682c | 2019-08-02 06:13:22 +0300 | [diff] [blame] | 56 | } |