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
35
static
uintptr_t
northbridge_get_tseg_base
(
void
)
36
{
37
uintptr_t
tom;
38
39
if
(
pci_read_config8
(
HOST_BRIDGE
,
DEVEN
) & (
DEVEN_D2F0
|
DEVEN_D2F1
))
40
/* IGD enabled, get top of Memory from BSM register */
41
tom =
pci_read_config32
(
IGD_DEV
,
BSM
);
42
else
43
tom = (
pci_read_config8
(
HOST_BRIDGE
,
TOLUD
) & 0xf8) << 24;
44
45
/* subtract TSEG size */
46
tom -=
decode_tseg_size
(
pci_read_config8
(
HOST_BRIDGE
,
ESMRAMC
));
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
{
63
uintptr_t
top_of_ram =
ALIGN_DOWN
(
northbridge_get_tseg_base
(), 4*
MiB
);
64
return
(
void
*) top_of_ram;
65
}
66
67
/* Decodes used Graphics Mode Select (GMS) to kilobytes. */
68
u32
decode_igd_memory_size
(
const
u32
gms)
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
84
void
fill_postcar_frame
(
struct
postcar_frame
*pcf)
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
);
93
postcar_frame_add_mtrr
(pcf,
northbridge_get_tseg_base
(),
94
northbridge_get_tseg_size
(),
MTRR_TYPE_WRBACK
);
95
}
romstage.h
postcar_frame_add_mtrr
void postcar_frame_add_mtrr(struct postcar_frame *pcf, uintptr_t addr, size_t size, int type)
Definition:
postcar_loader.c:71
ARRAY_SIZE
#define ARRAY_SIZE(a)
Definition:
helpers.h:12
ALIGN_DOWN
#define ALIGN_DOWN(x, a)
Definition:
helpers.h:18
MiB
#define MiB
Definition:
helpers.h:76
cbmem.h
cbmem_top
void * cbmem_top(void)
Definition:
imd_cbmem.c:18
die
void __noreturn die(const char *fmt,...)
Definition:
die.c:17
console.h
TOLUD
#define TOLUD
Definition:
host_bridge.h:61
DEVEN
#define DEVEN
Definition:
host_bridge.h:16
i945.h
IGD_DEV
#define IGD_DEV
Definition:
i945.h:82
BSM
#define BSM
Definition:
i945.h:86
DEVEN_D2F0
#define DEVEN_D2F0
Definition:
i945.h:38
DEVEN_D2F1
#define DEVEN_D2F1
Definition:
i945.h:39
smm.h
pci_ops.h
pci_read_config32
static __always_inline u32 pci_read_config32(const struct device *dev, u16 reg)
Definition:
pci_ops.h:58
pci_read_config8
static __always_inline u8 pci_read_config8(const struct device *dev, u16 reg)
Definition:
pci_ops.h:46
cbmem_top_chipset
void * cbmem_top_chipset(void)
Definition:
memmap.c:44
fill_postcar_frame
void fill_postcar_frame(struct postcar_frame *pcf)
Definition:
memmap.c:63
smm_region
void smm_region(uintptr_t *start, size_t *size)
Definition:
memmap.c:50
ESMRAMC
#define ESMRAMC
Definition:
memmap.c:45
decode_igd_memory_size
u32 decode_igd_memory_size(const u32 gms)
Definition:
memmap.c:24
decode_tseg_size
u32 decode_tseg_size(u8 esmramc)
Definition:
memmap.c:57
northbridge_get_tseg_size
static size_t northbridge_get_tseg_size(void)
Definition:
memmap.c:50
northbridge_get_tseg_base
static uintptr_t northbridge_get_tseg_base(void)
Definition:
memmap.c:35
program_loading.h
smm_reloc.h
HOST_BRIDGE
@ HOST_BRIDGE
Definition:
reg_access.h:23
u32
uint32_t u32
Definition:
stdint.h:51
uintptr_t
unsigned long uintptr_t
Definition:
stdint.h:21
u16
uint16_t u16
Definition:
stdint.h:48
u8
uint8_t u8
Definition:
stdint.h:45
postcar_frame
Definition:
romstage.h:18
mtrr.h
MTRR_TYPE_WRBACK
#define MTRR_TYPE_WRBACK
Definition:
mtrr.h:14
src
northbridge
intel
i945
memmap.c
Generated by
1.9.1