blob: 4673cceca09d7a3d5b06f7e6de3667a8aa89ed6d [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
Kyösti Mälkki326edeb2019-07-24 13:27:46 +03003#define __SIMPLE_DEVICE__
4
Duncan Lauriec88c54c2014-04-30 16:36:13 -07005#include <cbmem.h>
Kyösti Mälkki8f09688d2019-08-15 11:29:15 +03006#include <cpu/x86/smm.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -07007#include <device/pci.h>
Kyösti Mälkki26a682c2019-08-02 06:13:22 +03008#include <device/pci_ops.h>
Julius Werner4ee4bd52014-10-20 13:46:39 -07009#include <soc/pci_devs.h>
10#include <soc/systemagent.h>
Kyösti Mälkki26a682c2019-08-02 06:13:22 +030011#include <stdint.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070012
Kyösti Mälkkif1e3c762014-12-22 12:28:07 +020013static uintptr_t dpr_region_start(void)
Duncan Lauriec88c54c2014-04-30 16:36:13 -070014{
15 /*
Duncan Laurie61680272014-05-05 12:42:35 -050016 * Base of DPR is top of usable DRAM below 4GiB. The register has
17 * 1 MiB alignment and reports the TOP of the range, the base
18 * must be calculated from the size in MiB in bits 11:4.
Duncan Lauriec88c54c2014-04-30 16:36:13 -070019 */
Kyösti Mälkkif1e3c762014-12-22 12:28:07 +020020 uintptr_t dpr = pci_read_config32(SA_DEV_ROOT, DPR);
Elyes HAOUAS694cbc02020-08-29 18:11:16 +020021 uintptr_t tom = ALIGN_DOWN(dpr, 1 * MiB);
Duncan Laurie61680272014-05-05 12:42:35 -050022
23 /* Subtract DMA Protected Range size if enabled */
24 if (dpr & DPR_EPM)
25 tom -= (dpr & DPR_SIZE_MASK) << 16;
26
Kyösti Mälkkif1e3c762014-12-22 12:28:07 +020027 return tom;
28}
29
Arthur Heymans340e4b82019-10-23 17:25:58 +020030void *cbmem_top_chipset(void)
Kyösti Mälkkif1e3c762014-12-22 12:28:07 +020031{
32 return (void *) dpr_region_start();
Duncan Lauriec88c54c2014-04-30 16:36:13 -070033}
Kyösti Mälkki26a682c2019-08-02 06:13:22 +030034
Kyösti Mälkki8f09688d2019-08-15 11:29:15 +030035void smm_region(uintptr_t *start, size_t *size)
Kyösti Mälkki26a682c2019-08-02 06:13:22 +030036{
Kyösti Mälkki8f09688d2019-08-15 11:29:15 +030037 uintptr_t tseg = pci_read_config32(PCI_DEV(0, 0, 0), TSEG);
38 uintptr_t bgsm = pci_read_config32(PCI_DEV(0, 0, 0), BGSM);
Kyösti Mälkki26a682c2019-08-02 06:13:22 +030039
Kyösti Mälkki8f09688d2019-08-15 11:29:15 +030040 tseg = ALIGN_DOWN(tseg, 1 * MiB);
41 bgsm = ALIGN_DOWN(bgsm, 1 * MiB);
42 *start = tseg;
43 *size = bgsm - tseg;
Kyösti Mälkki26a682c2019-08-02 06:13:22 +030044}