coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
memmap.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 /* Use simple device model for this file even in ramstage */
4 #define __SIMPLE_DEVICE__
5 
6 #include <arch/romstage.h>
7 #include <cbmem.h>
8 #include <cpu/x86/smm.h>
9 #include <device/pci.h>
10 #include <device/pci_ops.h>
11 #include <soc/pci_devs.h>
12 #include <soc/systemagent.h>
13 #include <stdint.h>
14 
16 {
17  /*
18  * 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.
21  */
23  uintptr_t tom = ALIGN_DOWN(dpr, 1 * MiB);
24 
25  /* Subtract DMA Protected Range size if enabled */
26  if (dpr & DPR_EPM)
27  tom -= (dpr & DPR_SIZE_MASK) << 16;
28 
29  return tom;
30 }
31 
32 void *cbmem_top_chipset(void)
33 {
34  return (void *) dpr_region_start();
35 }
36 
37 void smm_region(uintptr_t *start, size_t *size)
38 {
41 
42  tseg = ALIGN_DOWN(tseg, 1 * MiB);
43  bgsm = ALIGN_DOWN(bgsm, 1 * MiB);
44  *start = tseg;
45  *size = bgsm - tseg;
46 }
47 
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,
59 }
void postcar_frame_add_mtrr(struct postcar_frame *pcf, uintptr_t addr, size_t size, int type)
#define ALIGN_DOWN(x, a)
Definition: helpers.h:18
#define MiB
Definition: helpers.h:76
void * cbmem_top(void)
Definition: imd_cbmem.c:18
#define DPR_SIZE_MASK
Definition: host_bridge.h:30
#define TSEG
Definition: host_bridge.h:60
#define DPR_EPM
Definition: host_bridge.h:28
#define DPR
Definition: host_bridge.h:27
#define BGSM
Definition: host_bridge.h:59
static __always_inline u32 pci_read_config32(const struct device *dev, u16 reg)
Definition: pci_ops.h:58
void * cbmem_top_chipset(void)
Definition: memmap.c:44
void fill_postcar_frame(struct postcar_frame *pcf)
Definition: memmap.c:63
void smm_region(uintptr_t *start, size_t *size)
Definition: memmap.c:50
static uintptr_t dpr_region_start(void)
Definition: memmap.c:15
@ HOST_BRIDGE
Definition: reg_access.h:23
unsigned long uintptr_t
Definition: stdint.h:21
#define MTRR_TYPE_WRBACK
Definition: mtrr.h:14