blob: 7c53fa646807736883d52f1639acd0e037795732 [file] [log] [blame]
Duncan Lauriec88c54c2014-04-30 16:36:13 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2014 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.
Duncan Lauriec88c54c2014-04-30 16:36:13 -070014 */
15
Kyösti Mälkki326edeb2019-07-24 13:27:46 +030016#define __SIMPLE_DEVICE__
17
Duncan Lauriec88c54c2014-04-30 16:36:13 -070018#include <cbmem.h>
19#include <device/pci.h>
Kyösti Mälkki26a682c2019-08-02 06:13:22 +030020#include <device/pci_ops.h>
Julius Werner4ee4bd52014-10-20 13:46:39 -070021#include <soc/pci_devs.h>
22#include <soc/systemagent.h>
Kyösti Mälkki26a682c2019-08-02 06:13:22 +030023#include <soc/smm.h>
24#include <stage_cache.h>
25#include <stdint.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070026
Kyösti Mälkkif1e3c762014-12-22 12:28:07 +020027static uintptr_t dpr_region_start(void)
Duncan Lauriec88c54c2014-04-30 16:36:13 -070028{
29 /*
Duncan Laurie61680272014-05-05 12:42:35 -050030 * Base of DPR is top of usable DRAM below 4GiB. The register has
31 * 1 MiB alignment and reports the TOP of the range, the base
32 * must be calculated from the size in MiB in bits 11:4.
Duncan Lauriec88c54c2014-04-30 16:36:13 -070033 */
Kyösti Mälkkif1e3c762014-12-22 12:28:07 +020034 uintptr_t dpr = pci_read_config32(SA_DEV_ROOT, DPR);
35 uintptr_t tom = dpr & ~((1 << 20) - 1);
Duncan Laurie61680272014-05-05 12:42:35 -050036
37 /* Subtract DMA Protected Range size if enabled */
38 if (dpr & DPR_EPM)
39 tom -= (dpr & DPR_SIZE_MASK) << 16;
40
Kyösti Mälkkif1e3c762014-12-22 12:28:07 +020041 return tom;
42}
43
44void *cbmem_top(void)
45{
46 return (void *) dpr_region_start();
Duncan Lauriec88c54c2014-04-30 16:36:13 -070047}
Kyösti Mälkki26a682c2019-08-02 06:13:22 +030048
49void stage_cache_external_region(void **base, size_t *size)
50{
51 /* The ramstage cache lives in the TSEG region.
52 * The top of RAM is defined to be the TSEG base address. */
53 u32 offset = smm_region_size();
54 offset -= CONFIG_IED_REGION_SIZE;
55 offset -= CONFIG_SMM_RESERVED_SIZE;
56
57 *base = (void *)(cbmem_top() + offset);
58 *size = CONFIG_SMM_RESERVED_SIZE;
59}