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 #include <arch/romstage.h>
4 #include <cbmem.h>
5 #include <console/console.h>
6 #include <device/pci_ops.h>
7 #include <cpu/x86/smm.h>
8 #include <soc/soc_util.h>
9 #include <soc/pci_devs.h>
10 #include <soc/util.h>
12 
13 void smm_region(uintptr_t *start, size_t *size)
14 {
17 
18  tseg_base = ALIGN_DOWN(tseg_base, 1 * MiB);
19  tseg_limit = ALIGN_DOWN(tseg_limit, 1 * MiB);
20  /* Only the upper [31:20] bits of an address are checked against
21  * VTD_TSEG_LIMIT_CSR[31:20] which must be below or equal, so this
22  * effectively means +1MiB for the limit.
23  */
24  tseg_limit += 1 * MiB;
25 
26  *start = tseg_base;
27  *size = tseg_limit - tseg_base;
28 }
29 
31 {
32  const uintptr_t top_of_ram = (uintptr_t)cbmem_top();
33  uintptr_t cbmem_base;
34  size_t cbmem_size;
35 
36  /* Try account for the CBMEM region currently used and for future use */
37  cbmem_get_region((void **)&cbmem_base, &cbmem_size);
38  printk(BIOS_DEBUG, "top_of_ram = 0x%lx\n", top_of_ram);
39  printk(BIOS_DEBUG, "cbmem base_ptr: 0x%lx, size: 0x%zx\n", cbmem_base, cbmem_size);
40  /* Assume 4MiB will be enough for future cbmem objects (FSP-S, ramstage, ...) */
41  cbmem_base -= 4 * MiB;
42  cbmem_base = ALIGN_DOWN(cbmem_base, 4 * MiB);
43 
44  /* Align the top to make sure we don't use too many MTRR's */
45  cbmem_size = ALIGN_UP(top_of_ram - cbmem_base, 4 * MiB);
46 
47  postcar_frame_add_mtrr(pcf, cbmem_base, cbmem_size, MTRR_TYPE_WRBACK);
48  /* Cache the TSEG region */
49  if (CONFIG(TSEG_STAGE_CACHE))
51 }
52 
53 #if !defined(__SIMPLE_DEVICE__)
55 {
56  const IIO_UDS *hob = get_iio_uds();
57  union dpr_register dpr;
58  struct device *dev = VTD_DEV(0);
59 
60  dpr.raw = 0;
61 
62  if (dev == NULL) {
63  printk(BIOS_ERR, "BUS 0: Unable to find VTD PCI dev");
64  return dpr;
65  }
66 
67  dpr.raw = pci_read_config32(dev, VTD_LTDPR);
68 
69  /* Compare the LTDPR register on all iio stacks */
70  for (int socket = 0; socket < hob->PlatformData.numofIIO; ++socket) {
71  for (int stack = 0; stack < MAX_IIO_STACK; ++stack) {
72  const STACK_RES *ri =
73  &hob->PlatformData.IIO_resource[socket].StackRes[stack];
74  if (!is_iio_stack_res(ri))
75  continue;
76  uint8_t bus = ri->BusBase;
77  dev = VTD_DEV(bus);
78 
79  if (dev == NULL) {
80  printk(BIOS_ERR, "BUS %x: Unable to find VTD PCI dev\n", bus);
81  dpr.raw = 0;
82  return dpr;
83  }
84 
85  union dpr_register test_dpr = { .raw = pci_read_config32(dev, VTD_LTDPR) };
86  if (dpr.raw != test_dpr.raw) {
87  printk(BIOS_ERR, "LTDPR not the same on all IIO's");
88  dpr.raw = 0;
89  return dpr;
90  }
91  }
92  }
93  return dpr;
94 }
95 #endif
void postcar_frame_add_mtrr(struct postcar_frame *pcf, uintptr_t addr, size_t size, int type)
void postcar_enable_tseg_cache(struct postcar_frame *pcf)
#define ALIGN_DOWN(x, a)
Definition: helpers.h:18
#define MiB
Definition: helpers.h:76
#define ALIGN_UP(x, a)
Definition: helpers.h:17
void * cbmem_top(void)
Definition: imd_cbmem.c:18
void cbmem_get_region(void **baseptr, size_t *size)
Definition: imd_cbmem.c:204
#define printk(level,...)
Definition: stdlib.h:16
@ CONFIG
Definition: dsi_common.h:201
static __always_inline u32 pci_read_config32(const struct device *dev, u16 reg)
Definition: pci_ops.h:58
bool is_iio_stack_res(const STACK_RES *res)
Definition: soc_util.c:28
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
Definition: loglevel.h:128
#define BIOS_ERR
BIOS_ERR - System in incomplete state.
Definition: loglevel.h:72
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
union dpr_register txt_get_chipset_dpr(void)
Definition: memmap.c:27
#define VTD_TSEG_BASE_CSR
Definition: pci_devs.h:105
#define VTD_LTDPR
Definition: pci_devs.h:119
#define VTD_DEV(bus)
Definition: pci_devs.h:145
#define VTD_TSEG_LIMIT_CSR
Definition: pci_devs.h:106
const IIO_UDS * get_iio_uds(void)
Definition: util.c:89
#define NULL
Definition: stddef.h:19
unsigned long uintptr_t
Definition: stdint.h:21
unsigned char uint8_t
Definition: stdint.h:8
Definition: device.h:76
Definition: device.h:107
uint32_t raw
Definition: txt_register.h:174
#define MTRR_TYPE_WRBACK
Definition: mtrr.h:14
typedef void(X86APIP X86EMU_intrFuncs)(int num)