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 #define __SIMPLE_DEVICE__
4 
5 #include <cbmem.h>
6 #include <commonlib/helpers.h>
7 #include <arch/romstage.h>
8 #include <device/pci_ops.h>
9 #include <device/pci_def.h>
10 #include <console/console.h>
11 #include <cpu/x86/mtrr.h>
12 #include <cpu/x86/smm.h>
14 #include <program_loading.h>
15 #include <cpu/intel/smm_reloc.h>
16 #include <types.h>
17 
18 /** Decodes used Graphics Mode Select (GMS) to kilobytes. */
20 {
21  static const u16 ggc2uma[] = {0, 1, 4, 8, 16, 32, 48, 64, 128, 256, 96, 160, 224, 352};
22 
23  if (gms >= ARRAY_SIZE(ggc2uma))
24  die("Bad Graphics Mode Select (GMS) setting.\n");
25 
26  return ggc2uma[gms] << 10;
27 }
28 
29 /** Decodes used GTT Graphics Memory Size (GGMS) to kilobytes. */
31 {
32  static const u8 ggc2gtt[] = {0, 1, 0, 2, 0, 0, 0, 0, 0, 2, 3, 4};
33 
34  if (gsm >= ARRAY_SIZE(ggc2gtt))
35  die("Bad GTT Graphics Memory Size (GGMS) setting.\n");
36 
37  return ggc2gtt[gsm] << 10;
38 }
39 
40 /** Decodes used TSEG size to bytes. */
41 u32 decode_tseg_size(const u32 esmramc)
42 {
43  if (!(esmramc & 1))
44  return 0;
45 
46  switch ((esmramc >> 1) & 3) {
47  case 0:
48  return 1 << 20;
49  case 1:
50  return 2 << 20;
51  case 2:
52  return 8 << 20;
53  case 3:
54  default:
55  die("Bad TSEG setting.\n");
56  }
57 }
58 
59 static size_t northbridge_get_tseg_size(void)
60 {
61  const u8 esmramc = pci_read_config8(HOST_BRIDGE, D0F0_ESMRAMC);
62  return decode_tseg_size(esmramc);
63 }
64 
66 {
68 }
69 
70 /* Depending of UMA and TSEG configuration, TSEG might start at any
71  * 1 MiB alignment. As this may cause very greedy MTRR setup, push
72  * CBMEM top downwards to 4 MiB boundary.
73  */
74 void *cbmem_top_chipset(void)
75 {
77  return (void *) top_of_ram;
78 }
79 
80 void smm_region(uintptr_t *start, size_t *size)
81 {
82  *start = northbridge_get_tseg_base();
83  *size = northbridge_get_tseg_size();
84 }
85 
87 {
88  uintptr_t top_of_ram;
89 
90  /* Cache 8 MiB region below the top of RAM and 2 MiB above top of
91  * RAM to cover both cbmem as the TSEG region.
92  */
93  top_of_ram = (uintptr_t)cbmem_top();
94  postcar_frame_add_mtrr(pcf, top_of_ram - 8*MiB, 8*MiB,
98 }
void postcar_frame_add_mtrr(struct postcar_frame *pcf, uintptr_t addr, size_t size, int type)
#define ARRAY_SIZE(a)
Definition: helpers.h:12
#define ALIGN_DOWN(x, a)
Definition: helpers.h:18
#define MiB
Definition: helpers.h:76
void * cbmem_top(void)
Definition: imd_cbmem.c:18
void __noreturn die(const char *fmt,...)
Definition: die.c:17
#define D0F0_ESMRAMC
Definition: gm45.h:187
static __always_inline u32 pci_read_config32(const struct device *dev, u16 reg)
Definition: pci_ops.h:58
static __always_inline u8 pci_read_config8(const struct device *dev, u16 reg)
Definition: pci_ops.h:46
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
u32 decode_igd_memory_size(const u32 gms)
Definition: memmap.c:24
u32 decode_tseg_size(u8 esmramc)
Definition: memmap.c:57
u32 decode_igd_gtt_size(const u32 gsm)
Decodes used Graphics Stolen Memory (GSM) to kilobytes.
Definition: memmap.c:36
static size_t northbridge_get_tseg_size(void)
Definition: memmap.c:59
static uintptr_t northbridge_get_tseg_base(void)
Definition: memmap.c:65
@ HOST_BRIDGE
Definition: reg_access.h:23
uint32_t u32
Definition: stdint.h:51
unsigned long uintptr_t
Definition: stdint.h:21
uint16_t u16
Definition: stdint.h:48
uint8_t u8
Definition: stdint.h:45
#define D0F0_TSEG
Definition: host_bridge.h:36
#define MTRR_TYPE_WRBACK
Definition: mtrr.h:14