blob: e4c787a0164c33dc63d1f24c640f16eb6ac8e3b3 [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
Duncan Lauriec88c54c2014-04-30 16:36:13 -07006#include <cbmem.h>
Kyösti Mälkki8f09688d2019-08-15 11:29:15 +03007#include <cpu/x86/smm.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -07008#include <device/pci.h>
Kyösti Mälkki26a682c2019-08-02 06:13:22 +03009#include <device/pci_ops.h>
Julius Werner4ee4bd52014-10-20 13:46:39 -070010#include <soc/pci_devs.h>
11#include <soc/systemagent.h>
Kyösti Mälkki26a682c2019-08-02 06:13:22 +030012#include <stdint.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070013
Kyösti Mälkkif1e3c762014-12-22 12:28:07 +020014static uintptr_t dpr_region_start(void)
Duncan Lauriec88c54c2014-04-30 16:36:13 -070015{
16 /*
Duncan Laurie61680272014-05-05 12:42:35 -050017 * Base of DPR is top of usable DRAM below 4GiB. The register has
18 * 1 MiB alignment and reports the TOP of the range, the base
19 * must be calculated from the size in MiB in bits 11:4.
Duncan Lauriec88c54c2014-04-30 16:36:13 -070020 */
Kyösti Mälkkif1e3c762014-12-22 12:28:07 +020021 uintptr_t dpr = pci_read_config32(SA_DEV_ROOT, DPR);
Elyes HAOUAS694cbc02020-08-29 18:11:16 +020022 uintptr_t tom = ALIGN_DOWN(dpr, 1 * MiB);
Duncan Laurie61680272014-05-05 12:42:35 -050023
24 /* Subtract DMA Protected Range size if enabled */
25 if (dpr & DPR_EPM)
26 tom -= (dpr & DPR_SIZE_MASK) << 16;
27
Kyösti Mälkkif1e3c762014-12-22 12:28:07 +020028 return tom;
29}
30
Arthur Heymans340e4b82019-10-23 17:25:58 +020031void *cbmem_top_chipset(void)
Kyösti Mälkkif1e3c762014-12-22 12:28:07 +020032{
33 return (void *) dpr_region_start();
Duncan Lauriec88c54c2014-04-30 16:36:13 -070034}
Kyösti Mälkki26a682c2019-08-02 06:13:22 +030035
Kyösti Mälkki8f09688d2019-08-15 11:29:15 +030036void smm_region(uintptr_t *start, size_t *size)
Kyösti Mälkki26a682c2019-08-02 06:13:22 +030037{
Angel Ponsac028142020-10-13 21:11:43 +020038 uintptr_t tseg = pci_read_config32(SA_DEV_ROOT, TSEG);
39 uintptr_t bgsm = pci_read_config32(SA_DEV_ROOT, BGSM);
Kyösti Mälkki26a682c2019-08-02 06:13:22 +030040
Kyösti Mälkki8f09688d2019-08-15 11:29:15 +030041 tseg = ALIGN_DOWN(tseg, 1 * MiB);
42 bgsm = ALIGN_DOWN(bgsm, 1 * MiB);
43 *start = tseg;
44 *size = bgsm - tseg;
Kyösti Mälkki26a682c2019-08-02 06:13:22 +030045}