blob: f607d0f0df9d29a80a457c38b3050bb3fb7531fb [file] [log] [blame]
Patrick Georgiac959032020-05-05 22:49:26 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Mariusz Szafranskia4041332017-08-02 17:28:17 +02002
Kyösti Mälkki81100bf2019-08-16 10:37:15 +03003#include <arch/romstage.h>
Mariusz Szafranskia4041332017-08-02 17:28:17 +02004#include <cbmem.h>
5#include <assert.h>
Kyösti Mälkki81100bf2019-08-16 10:37:15 +03006#include <cpu/x86/mtrr.h>
Kyösti Mälkkib2a5f0b2019-08-04 19:54:32 +03007#include <cpu/x86/smm.h>
Mariusz Szafranskia4041332017-08-02 17:28:17 +02008#include <device/device.h>
9#include <device/pci_def.h>
10#include <device/pci_ops.h>
Mariusz Szafranskia4041332017-08-02 17:28:17 +020011#include <soc/pci_devs.h>
12#include <soc/systemagent.h>
Mariusz Szafranskia4041332017-08-02 17:28:17 +020013
14/* Returns base of requested region encoded in the system agent. */
15static inline uintptr_t system_agent_region_base(size_t reg)
16{
Elyes HAOUAS68c851b2018-06-12 22:06:09 +020017#if defined(__SIMPLE_DEVICE__)
18 pci_devfn_t dev = SA_DEV_ROOT;
19#else
Kyösti Mälkki28dc7dc2019-07-12 13:10:19 +030020 struct device *dev = pcidev_path_on_root(SA_DEVFN_ROOT);
Elyes HAOUAS68c851b2018-06-12 22:06:09 +020021#endif
Mariusz Szafranskia4041332017-08-02 17:28:17 +020022 /* All regions concerned for have 1 MiB alignment. */
23 return ALIGN_DOWN(pci_read_config32(dev, reg), 1 * MiB);
24}
25
Mariusz Szafranskia4041332017-08-02 17:28:17 +020026static inline uintptr_t smm_region_start(void)
27{
28 return system_agent_region_base(TSEGMB);
29}
30
31static inline size_t smm_region_size(void)
32{
33 return system_agent_region_base(TOLUD) - smm_region_start();
34}
35
Kyösti Mälkki14222d82019-08-05 15:10:18 +030036void smm_region(uintptr_t *start, size_t *size)
Mariusz Szafranskia4041332017-08-02 17:28:17 +020037{
Kyösti Mälkki14222d82019-08-05 15:10:18 +030038 *start = smm_region_start();
Mariusz Szafranskia4041332017-08-02 17:28:17 +020039 *size = smm_region_size();
40}
Kyösti Mälkki81100bf2019-08-16 10:37:15 +030041
42void fill_postcar_frame(struct postcar_frame *pcf)
43{
44 uintptr_t top_of_ram;
Kyösti Mälkki81100bf2019-08-16 10:37:15 +030045
46 /*
47 * We need to make sure ramstage will be run cached. At this point exact
48 * location of ramstage in cbmem is not known. Instruct postcar to cache
49 * 16 megs under cbmem top which is a safe bet to cover ramstage.
50 */
51 top_of_ram = (uintptr_t)cbmem_top();
52 postcar_frame_add_mtrr(pcf, top_of_ram - 16 * MiB, 16 * MiB,
53 MTRR_TYPE_WRBACK);
54
Subrata Banik3eff0372019-09-10 15:51:17 +053055 /* Cache the TSEG region */
56 postcar_enable_tseg_cache(pcf);
Kyösti Mälkki81100bf2019-08-16 10:37:15 +030057}