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 <device/pci_ops.h>
7 #include <arch/romstage.h>
8 #include <cbmem.h>
9 #include "i945.h"
10 #include <console/console.h>
11 #include <cpu/x86/mtrr.h>
12 #include <cpu/x86/smm.h>
13 #include <program_loading.h>
14 #include <cpu/intel/smm_reloc.h>
15 #include <types.h>
16 
17 /* Decodes TSEG region size to bytes. */
18 u32 decode_tseg_size(const u8 esmramc)
19 {
20  if (!(esmramc & 1))
21  return 0;
22  switch ((esmramc >> 1) & 3) {
23  case 0:
24  return 1 << 20;
25  case 1:
26  return 2 << 20;
27  case 2:
28  return 8 << 20;
29  case 3:
30  default:
31  die("Bad TSEG setting.\n");
32  }
33 }
34 
36 {
37  uintptr_t tom;
38 
40  /* IGD enabled, get top of Memory from BSM register */
42  else
43  tom = (pci_read_config8(HOST_BRIDGE, TOLUD) & 0xf8) << 24;
44 
45  /* subtract TSEG size */
47  return tom;
48 }
49 
50 static size_t northbridge_get_tseg_size(void)
51 {
52  const u8 esmramc = pci_read_config8(HOST_BRIDGE, ESMRAMC);
53  return decode_tseg_size(esmramc);
54 }
55 
56 /*
57  * Depending of UMA and TSEG configuration, TSEG might start at any
58  * 1 MiB alignment. As this may cause very greedy MTRR setup, push
59  * CBMEM top downwards to 4 MiB boundary.
60  */
61 void *cbmem_top_chipset(void)
62 {
64  return (void *) top_of_ram;
65 }
66 
67 /* Decodes used Graphics Mode Select (GMS) to kilobytes. */
69 {
70  static const u16 ggc2uma[] = { 0, 1, 4, 8, 16, 32, 48, 64 };
71 
72  if (gms >= ARRAY_SIZE(ggc2uma))
73  die("Bad Graphics Mode Select (GMS) setting.\n");
74 
75  return ggc2uma[gms] << 10;
76 }
77 
78 void smm_region(uintptr_t *start, size_t *size)
79 {
80  *start = northbridge_get_tseg_base();
81  *size = northbridge_get_tseg_size();
82 }
83 
85 {
86  uintptr_t top_of_ram;
87 
88  /* Cache 8 MiB region below the top of RAM and 2 MiB above top of
89  * RAM to cover both cbmem as the TSEG region.
90  */
91  top_of_ram = (uintptr_t)cbmem_top();
92  postcar_frame_add_mtrr(pcf, top_of_ram - 8*MiB, 8*MiB, MTRR_TYPE_WRBACK);
95 }
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 TOLUD
Definition: host_bridge.h:61
#define DEVEN
Definition: host_bridge.h:16
#define IGD_DEV
Definition: i945.h:82
#define BSM
Definition: i945.h:86
#define DEVEN_D2F0
Definition: i945.h:38
#define DEVEN_D2F1
Definition: i945.h:39
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
#define ESMRAMC
Definition: memmap.c:45
u32 decode_igd_memory_size(const u32 gms)
Definition: memmap.c:24
u32 decode_tseg_size(u8 esmramc)
Definition: memmap.c:57
static size_t northbridge_get_tseg_size(void)
Definition: memmap.c:50
static uintptr_t northbridge_get_tseg_base(void)
Definition: memmap.c:35
@ 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 MTRR_TYPE_WRBACK
Definition: mtrr.h:14