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 | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 19 | #include <device/pci_ops.h> |
Kyösti Mälkki | cb08e16 | 2013-10-15 17:19:41 +0300 | [diff] [blame] | 20 | #include <cbmem.h> |
Kyösti Mälkki | 825646e | 2019-08-02 06:14:50 +0300 | [diff] [blame^] | 21 | #include <stage_cache.h> |
Kyösti Mälkki | cb08e16 | 2013-10-15 17:19:41 +0300 | [diff] [blame] | 22 | #include "haswell.h" |
| 23 | |
Kyösti Mälkki | f1e3c76 | 2014-12-22 12:28:07 +0200 | [diff] [blame] | 24 | static uintptr_t smm_region_start(void) |
Kyösti Mälkki | cb08e16 | 2013-10-15 17:19:41 +0300 | [diff] [blame] | 25 | { |
| 26 | /* |
| 27 | * 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] | 28 | * 1 MiB alignment. |
Kyösti Mälkki | cb08e16 | 2013-10-15 17:19:41 +0300 | [diff] [blame] | 29 | */ |
Kyösti Mälkki | f1e3c76 | 2014-12-22 12:28:07 +0200 | [diff] [blame] | 30 | uintptr_t tom = pci_read_config32(PCI_DEV(0,0,0), TSEG); |
| 31 | return tom & ~((1 << 20) - 1); |
| 32 | } |
| 33 | |
| 34 | void *cbmem_top(void) |
| 35 | { |
| 36 | return (void *)smm_region_start(); |
Kyösti Mälkki | cb08e16 | 2013-10-15 17:19:41 +0300 | [diff] [blame] | 37 | } |
Kyösti Mälkki | 825646e | 2019-08-02 06:14:50 +0300 | [diff] [blame^] | 38 | |
| 39 | /* Region of SMM space is reserved for multipurpose use. It falls below |
| 40 | * the IED region and above the SMM handler. */ |
| 41 | #define RESERVED_SMM_OFFSET \ |
| 42 | (CONFIG_SMM_TSEG_SIZE - CONFIG_IED_REGION_SIZE - CONFIG_SMM_RESERVED_SIZE) |
| 43 | |
| 44 | void stage_cache_external_region(void **base, size_t *size) |
| 45 | { |
| 46 | /* The ramstage cache lives in the TSEG region at RESERVED_SMM_OFFSET. |
| 47 | * The top of RAM is defined to be the TSEG base address. */ |
| 48 | *size = CONFIG_SMM_RESERVED_SIZE; |
| 49 | *base = (void *)((uint32_t)cbmem_top() + RESERVED_SMM_OFFSET); |
| 50 | } |