blob: 027c958a13ed51d2e6860d71ce63787cb39ff292 [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
16#include <arch/io.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020017#include <device/pci_ops.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070018#include <cbmem.h>
19#include <device/pci.h>
Julius Werner4ee4bd52014-10-20 13:46:39 -070020#include <soc/pci_devs.h>
21#include <soc/systemagent.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070022
Kyösti Mälkkif1e3c762014-12-22 12:28:07 +020023static uintptr_t dpr_region_start(void)
Duncan Lauriec88c54c2014-04-30 16:36:13 -070024{
25 /*
Duncan Laurie61680272014-05-05 12:42:35 -050026 * Base of DPR is top of usable DRAM below 4GiB. The register has
27 * 1 MiB alignment and reports the TOP of the range, the base
28 * must be calculated from the size in MiB in bits 11:4.
Duncan Lauriec88c54c2014-04-30 16:36:13 -070029 */
Kyösti Mälkkif1e3c762014-12-22 12:28:07 +020030 uintptr_t dpr = pci_read_config32(SA_DEV_ROOT, DPR);
31 uintptr_t tom = dpr & ~((1 << 20) - 1);
Duncan Laurie61680272014-05-05 12:42:35 -050032
33 /* Subtract DMA Protected Range size if enabled */
34 if (dpr & DPR_EPM)
35 tom -= (dpr & DPR_SIZE_MASK) << 16;
36
Kyösti Mälkkif1e3c762014-12-22 12:28:07 +020037 return tom;
38}
39
40void *cbmem_top(void)
41{
42 return (void *) dpr_region_start();
Duncan Lauriec88c54c2014-04-30 16:36:13 -070043}