Debian Codegraph @

src/northbridge/via/cx700/memmap.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #define __SIMPLE_DEVICE__
4
5 #include <commonlib/bsd/helpers.h>
6 #include <stddef.h>
7 #include <stdint.h>
8 #include <device/pci_ops.h>
9 #include <static_devices.h>
10 #include <arch/romstage.h>
11 #include <cbmem.h>
12
13 static uintptr_t top_of_low_ram(void)
14 {
15 return (uintptr_t)pci_read_config8(_sdev_dram_ctrl, 0x88) << 24;
16 }
17
18 static size_t get_stolen_framebuffer_size(void)
19 {
20 const size_t size_selection = pci_read_config8(_sdev_dram_ctrl, 0xa1) >> 4 & 7;
21
22 return size_selection ? 1 << (size_selection + 22) : 0;
23 }
24
25 static size_t get_tseg_size(void)
26 {
27 return pci_read_config8(_sdev_dram_ctrl, 0x86) & 0x04 ? 1*MiB : 0;
28 }
29
30 uintptr_t cbmem_top_chipset(void)
31 {
32 /* Keep it below 2GiB to leave space for PCI MMIO.
33 If more than 2GiB are installed, CBMEM won't be
34 at the top of the available memory. */
35 return MIN(2ul*GiB, top_of_low_ram() - get_stolen_framebuffer_size() - get_tseg_size());
36 }
37
38 void fill_postcar_frame(struct postcar_frame *pcf)
39 {
40 /* TSEG top is at least 8MiB aligned, so
41 we cache 8MiB including TSEG if enabled. */
42 const uintptr_t top_down = ALIGN_DOWN(cbmem_top_chipset() - 7*MiB, 8*MiB);
43 postcar_frame_add_mtrr(pcf, top_down, 8*MiB, MTRR_TYPE_WRBACK);
44 }