Debian Codegraph @

src/northbridge/intel/pineview/memmap.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #define __SIMPLE_DEVICE__
4
5 #include <arch/romstage.h>
6 #include <commonlib/helpers.h>
7 #include <device/pci_ops.h>
8 #include <device/device.h>
9 #include <device/pci_def.h>
10 #include <console/console.h>
11 #include <cbmem.h>
12 #include <northbridge/intel/pineview/pineview.h>
13 #include <cpu/x86/mtrr.h>
14 #include <cpu/x86/smm.h>
15 #include <cpu/intel/smm_reloc.h>
16 #include <types.h>
17
18 /** Decodes used Graphics Mode Select (GMS) to kilobytes. */
19 u32 decode_igd_memory_size(const u32 gms)
20 {
21 const u32 gmssize[] = {0, 1, 4, 8, 16, 32, 48, 64, 128, 256};
22
23 if (gms > 9) {
24 printk(BIOS_DEBUG, "Bad Graphics Mode Select (GMS) value.\n");
25 return 0;
26 }
27 return gmssize[gms] << 10;
28 }
29
30 /** Decodes used Graphics Stolen Memory (GSM) to kilobytes. */
31 u32 decode_igd_gtt_size(const u32 gsm)
32 {
33 const u8 gsmsize[] = {0, 1, 0, 0};
34
35 if (gsm > 3) {
36 printk(BIOS_DEBUG, "Bad Graphics Stolen Memory (GSM) value.\n");
37 return 0;
38 }
39 return (u32)(gsmsize[gsm] << 10);
40 }
41
42 /** Decodes used TSEG size to bytes. */
43 static u32 decode_tseg_size(const u32 esmramc)
44 {
45 if (!(esmramc & 1))
46 return 0;
47
48 switch ((esmramc >> 1) & 3) {
49 case 0:
50 return 1 * MiB;
51 case 1:
52 return 2 * MiB;
53 case 2:
54 return 8 * MiB;
55 case 3:
56 default:
57 die("Bad TSEG setting.\n");
58 }
59 }
60
61 static size_t northbridge_get_tseg_size(void)
62 {
63 const u8 esmramc = pci_read_config8(HOST_BRIDGE, ESMRAMC);
64 return decode_tseg_size(esmramc);
65 }
66
67 static uintptr_t northbridge_get_tseg_base(void)
68 {
69 return pci_read_config32(HOST_BRIDGE, TSEG);
70 }
71
72 /*
73 * Depending of UMA and TSEG configuration, TSEG might start at any 1 MiB alignment.
74 * As this may cause very greedy MTRR setup, push CBMEM top downwards to 4 MiB boundary.
75 */
76 uintptr_t cbmem_top_chipset(void)
77 {
78 return ALIGN_DOWN(northbridge_get_tseg_base(), 4 * MiB);
79 }
80
81 void smm_region(uintptr_t *start, size_t *size)
82 {
83 *start = northbridge_get_tseg_base();
84 *size = northbridge_get_tseg_size();
85 }
86
87 void fill_postcar_frame(struct postcar_frame *pcf)
88 {
89 /*
90 * Cache 8 MiB region below the top of RAM and 2 MiB above top of RAM to cover both
91 * CBMEM and the TSEG region.
92 */
93 const uintptr_t top_of_ram = cbmem_top();
94 postcar_frame_add_mtrr(pcf, top_of_ram - 8 * MiB, 8 * MiB, MTRR_TYPE_WRBACK);
95 postcar_frame_add_mtrr(pcf, northbridge_get_tseg_base(), northbridge_get_tseg_size(),
96 MTRR_TYPE_WRBACK);
97 }