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 | * |
| 4 | * Copyright (C) 2011 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. |
Kyösti Mälkki | cb08e16 | 2013-10-15 17:19:41 +0300 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | // Use simple device model for this file even in ramstage |
| 17 | #define __SIMPLE_DEVICE__ |
| 18 | |
Kyösti Mälkki | a963acd | 2019-08-16 20:34:25 +0300 | [diff] [blame] | 19 | #include <arch/romstage.h> |
Kyösti Mälkki | e2e1f12 | 2019-08-09 09:34:23 +0300 | [diff] [blame] | 20 | #include <console/console.h> |
| 21 | #include <cpu/x86/mtrr.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> |
Kyösti Mälkki | e2e1f12 | 2019-08-09 09:34:23 +0300 | [diff] [blame] | 24 | #include <cpu/intel/romstage.h> |
Kyösti Mälkki | 825646e | 2019-08-02 06:14:50 +0300 | [diff] [blame] | 25 | #include <stage_cache.h> |
Kyösti Mälkki | cb08e16 | 2013-10-15 17:19:41 +0300 | [diff] [blame] | 26 | #include "haswell.h" |
| 27 | |
Kyösti Mälkki | f1e3c76 | 2014-12-22 12:28:07 +0200 | [diff] [blame] | 28 | static uintptr_t smm_region_start(void) |
Kyösti Mälkki | cb08e16 | 2013-10-15 17:19:41 +0300 | [diff] [blame] | 29 | { |
| 30 | /* |
| 31 | * 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] | 32 | * 1 MiB alignment. |
Kyösti Mälkki | cb08e16 | 2013-10-15 17:19:41 +0300 | [diff] [blame] | 33 | */ |
Kyösti Mälkki | f1e3c76 | 2014-12-22 12:28:07 +0200 | [diff] [blame] | 34 | uintptr_t tom = pci_read_config32(PCI_DEV(0,0,0), TSEG); |
| 35 | return tom & ~((1 << 20) - 1); |
| 36 | } |
| 37 | |
| 38 | void *cbmem_top(void) |
| 39 | { |
| 40 | return (void *)smm_region_start(); |
Kyösti Mälkki | cb08e16 | 2013-10-15 17:19:41 +0300 | [diff] [blame] | 41 | } |
Kyösti Mälkki | 825646e | 2019-08-02 06:14:50 +0300 | [diff] [blame] | 42 | |
| 43 | /* Region of SMM space is reserved for multipurpose use. It falls below |
| 44 | * the IED region and above the SMM handler. */ |
| 45 | #define RESERVED_SMM_OFFSET \ |
| 46 | (CONFIG_SMM_TSEG_SIZE - CONFIG_IED_REGION_SIZE - CONFIG_SMM_RESERVED_SIZE) |
| 47 | |
| 48 | void stage_cache_external_region(void **base, size_t *size) |
| 49 | { |
| 50 | /* The ramstage cache lives in the TSEG region at RESERVED_SMM_OFFSET. |
| 51 | * The top of RAM is defined to be the TSEG base address. */ |
| 52 | *size = CONFIG_SMM_RESERVED_SIZE; |
| 53 | *base = (void *)((uint32_t)cbmem_top() + RESERVED_SMM_OFFSET); |
| 54 | } |
Kyösti Mälkki | e2e1f12 | 2019-08-09 09:34:23 +0300 | [diff] [blame] | 55 | |
Kyösti Mälkki | 5bc641a | 2019-08-09 09:37:49 +0300 | [diff] [blame] | 56 | void fill_postcar_frame(struct postcar_frame *pcf) |
Kyösti Mälkki | e2e1f12 | 2019-08-09 09:34:23 +0300 | [diff] [blame] | 57 | { |
Kyösti Mälkki | e2e1f12 | 2019-08-09 09:34:23 +0300 | [diff] [blame] | 58 | uintptr_t top_of_ram; |
| 59 | |
Kyösti Mälkki | e2e1f12 | 2019-08-09 09:34:23 +0300 | [diff] [blame] | 60 | /* Cache at least 8 MiB below the top of ram, and at most 8 MiB |
| 61 | * above top of the ram. This satisfies MTRR alignment requirement |
| 62 | * with different TSEG size configurations. |
| 63 | */ |
| 64 | top_of_ram = ALIGN_DOWN((uintptr_t)cbmem_top(), 8*MiB); |
Kyösti Mälkki | 5bc641a | 2019-08-09 09:37:49 +0300 | [diff] [blame] | 65 | postcar_frame_add_mtrr(pcf, top_of_ram - 8*MiB, 16*MiB, |
Kyösti Mälkki | e2e1f12 | 2019-08-09 09:34:23 +0300 | [diff] [blame] | 66 | MTRR_TYPE_WRBACK); |
Kyösti Mälkki | e2e1f12 | 2019-08-09 09:34:23 +0300 | [diff] [blame] | 67 | } |