Kyösti Mälkki | cb08e16 | 2013-10-15 17:19:41 +0300 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Kyösti Mälkki | cb08e16 | 2013-10-15 17:19:41 +0300 | [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. |
Kyösti Mälkki | cb08e16 | 2013-10-15 17:19:41 +0300 | [diff] [blame] | 13 | */ |
| 14 | |
Angel Pons | 1db5bc7 | 2020-01-15 00:49:03 +0100 | [diff] [blame] | 15 | /* Use simple device model for this file even in ramstage */ |
Kyösti Mälkki | cb08e16 | 2013-10-15 17:19:41 +0300 | [diff] [blame] | 16 | #define __SIMPLE_DEVICE__ |
| 17 | |
Kyösti Mälkki | a963acd | 2019-08-16 20:34:25 +0300 | [diff] [blame] | 18 | #include <arch/romstage.h> |
Kyösti Mälkki | cd7a70f | 2019-08-17 20:51:08 +0300 | [diff] [blame] | 19 | #include <commonlib/helpers.h> |
Kyösti Mälkki | e2e1f12 | 2019-08-09 09:34:23 +0300 | [diff] [blame] | 20 | #include <cpu/x86/mtrr.h> |
Kyösti Mälkki | 540151f | 2019-08-15 11:20:18 +0300 | [diff] [blame] | 21 | #include <cpu/x86/smm.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 22 | #include <device/pci_ops.h> |
Kyösti Mälkki | cb08e16 | 2013-10-15 17:19:41 +0300 | [diff] [blame] | 23 | #include <cbmem.h> |
| 24 | #include "haswell.h" |
| 25 | |
Kyösti Mälkki | f1e3c76 | 2014-12-22 12:28:07 +0200 | [diff] [blame] | 26 | static uintptr_t smm_region_start(void) |
Kyösti Mälkki | cb08e16 | 2013-10-15 17:19:41 +0300 | [diff] [blame] | 27 | { |
| 28 | /* |
| 29 | * Base of TSEG is top of usable DRAM below 4GiB. The register has |
Martin Roth | 128c104 | 2016-11-18 09:29:03 -0700 | [diff] [blame] | 30 | * 1 MiB alignment. |
Kyösti Mälkki | cb08e16 | 2013-10-15 17:19:41 +0300 | [diff] [blame] | 31 | */ |
Angel Pons | 1db5bc7 | 2020-01-15 00:49:03 +0100 | [diff] [blame] | 32 | uintptr_t tom = pci_read_config32(HOST_BRIDGE, TSEG); |
Kyösti Mälkki | f1e3c76 | 2014-12-22 12:28:07 +0200 | [diff] [blame] | 33 | return tom & ~((1 << 20) - 1); |
| 34 | } |
| 35 | |
Arthur Heymans | 340e4b8 | 2019-10-23 17:25:58 +0200 | [diff] [blame] | 36 | void *cbmem_top_chipset(void) |
Kyösti Mälkki | f1e3c76 | 2014-12-22 12:28:07 +0200 | [diff] [blame] | 37 | { |
| 38 | return (void *)smm_region_start(); |
Kyösti Mälkki | cb08e16 | 2013-10-15 17:19:41 +0300 | [diff] [blame] | 39 | } |
Kyösti Mälkki | 825646e | 2019-08-02 06:14:50 +0300 | [diff] [blame] | 40 | |
Kyösti Mälkki | 540151f | 2019-08-15 11:20:18 +0300 | [diff] [blame] | 41 | void smm_region(uintptr_t *start, size_t *size) |
Kyösti Mälkki | 825646e | 2019-08-02 06:14:50 +0300 | [diff] [blame] | 42 | { |
Kyösti Mälkki | 540151f | 2019-08-15 11:20:18 +0300 | [diff] [blame] | 43 | *start = smm_region_start(); |
| 44 | *size = CONFIG_SMM_TSEG_SIZE; |
Kyösti Mälkki | 825646e | 2019-08-02 06:14:50 +0300 | [diff] [blame] | 45 | } |
Kyösti Mälkki | e2e1f12 | 2019-08-09 09:34:23 +0300 | [diff] [blame] | 46 | |
Kyösti Mälkki | 5bc641a | 2019-08-09 09:37:49 +0300 | [diff] [blame] | 47 | void fill_postcar_frame(struct postcar_frame *pcf) |
Kyösti Mälkki | e2e1f12 | 2019-08-09 09:34:23 +0300 | [diff] [blame] | 48 | { |
Kyösti Mälkki | e2e1f12 | 2019-08-09 09:34:23 +0300 | [diff] [blame] | 49 | uintptr_t top_of_ram; |
| 50 | |
Kyösti Mälkki | e2e1f12 | 2019-08-09 09:34:23 +0300 | [diff] [blame] | 51 | /* Cache at least 8 MiB below the top of ram, and at most 8 MiB |
| 52 | * above top of the ram. This satisfies MTRR alignment requirement |
| 53 | * with different TSEG size configurations. |
| 54 | */ |
Angel Pons | 1db5bc7 | 2020-01-15 00:49:03 +0100 | [diff] [blame] | 55 | top_of_ram = ALIGN_DOWN((uintptr_t)cbmem_top(), 8 * MiB); |
| 56 | postcar_frame_add_mtrr(pcf, top_of_ram - 8 * MiB, 16 * MiB, MTRR_TYPE_WRBACK); |
Kyösti Mälkki | e2e1f12 | 2019-08-09 09:34:23 +0300 | [diff] [blame] | 57 | } |