blob: 98c80165b0dee3f75b228489a6ed57cd55528228 [file] [log] [blame]
Angel Ponsf94ac9a2020-04-05 15:46:48 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Duncan Lauriec88c54c2014-04-30 16:36:13 -07002
Angel Pons2ead3632020-09-24 16:50:05 +02003/* Use simple device model for this file even in ramstage */
Kyösti Mälkki326edeb2019-07-24 13:27:46 +03004#define __SIMPLE_DEVICE__
5
Angel Pons7fa445e2020-10-13 21:14:32 +02006#include <arch/romstage.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -07007#include <cbmem.h>
Kyösti Mälkki8f09688d2019-08-15 11:29:15 +03008#include <cpu/x86/smm.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -07009#include <device/pci.h>
Kyösti Mälkki26a682c2019-08-02 06:13:22 +030010#include <device/pci_ops.h>
Julius Werner4ee4bd52014-10-20 13:46:39 -070011#include <soc/pci_devs.h>
12#include <soc/systemagent.h>
Kyösti Mälkki26a682c2019-08-02 06:13:22 +030013#include <stdint.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070014
Kyösti Mälkkif1e3c762014-12-22 12:28:07 +020015static uintptr_t dpr_region_start(void)
Duncan Lauriec88c54c2014-04-30 16:36:13 -070016{
17 /*
Duncan Laurie61680272014-05-05 12:42:35 -050018 * Base of DPR is top of usable DRAM below 4GiB. The register has
19 * 1 MiB alignment and reports the TOP of the range, the base
20 * must be calculated from the size in MiB in bits 11:4.
Duncan Lauriec88c54c2014-04-30 16:36:13 -070021 */
Angel Pons29924b22021-06-15 13:55:03 +020022 uintptr_t dpr = pci_read_config32(HOST_BRIDGE, DPR);
Elyes HAOUAS694cbc02020-08-29 18:11:16 +020023 uintptr_t tom = ALIGN_DOWN(dpr, 1 * MiB);
Duncan Laurie61680272014-05-05 12:42:35 -050024
25 /* Subtract DMA Protected Range size if enabled */
26 if (dpr & DPR_EPM)
27 tom -= (dpr & DPR_SIZE_MASK) << 16;
28
Kyösti Mälkkif1e3c762014-12-22 12:28:07 +020029 return tom;
30}
31
Elyes Haouas799c3212022-11-09 14:00:44 +010032uintptr_t cbmem_top_chipset(void)
Kyösti Mälkkif1e3c762014-12-22 12:28:07 +020033{
Elyes Haouas799c3212022-11-09 14:00:44 +010034 return dpr_region_start();
Duncan Lauriec88c54c2014-04-30 16:36:13 -070035}
Kyösti Mälkki26a682c2019-08-02 06:13:22 +030036
Kyösti Mälkki8f09688d2019-08-15 11:29:15 +030037void smm_region(uintptr_t *start, size_t *size)
Kyösti Mälkki26a682c2019-08-02 06:13:22 +030038{
Angel Pons29924b22021-06-15 13:55:03 +020039 uintptr_t tseg = pci_read_config32(HOST_BRIDGE, TSEG);
40 uintptr_t bgsm = pci_read_config32(HOST_BRIDGE, BGSM);
Kyösti Mälkki26a682c2019-08-02 06:13:22 +030041
Kyösti Mälkki8f09688d2019-08-15 11:29:15 +030042 tseg = ALIGN_DOWN(tseg, 1 * MiB);
43 bgsm = ALIGN_DOWN(bgsm, 1 * MiB);
44 *start = tseg;
45 *size = bgsm - tseg;
Kyösti Mälkki26a682c2019-08-02 06:13:22 +030046}
Angel Pons7fa445e2020-10-13 21:14:32 +020047
48void fill_postcar_frame(struct postcar_frame *pcf)
49{
50 uintptr_t top_of_ram;
51
52 /* Cache at least 8 MiB below the top of ram, and at most 8 MiB
53 * above top of the ram. This satisfies MTRR alignment requirement
54 * with different TSEG size configurations.
55 */
56 top_of_ram = ALIGN_DOWN((uintptr_t)cbmem_top(), 8*MiB);
57 postcar_frame_add_mtrr(pcf, top_of_ram - 8*MiB, 16*MiB,
58 MTRR_TYPE_WRBACK);
59}