Debian Codegraph @

src/drivers/intel/fsp2_0/cb_logo.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2
3 #define __SIMPLE_DEVICE__
4
5 #include <bootmode.h>
6 #include <bootsplash.h>
7 #include <console/console.h>
8 #include <cpu/x86/mtrr.h>
9 #include <device/pci_ops.h>
10 #include <fsp/api.h>
11 #include <fsp/fsp_gop_blt.h>
12 #include <fsp/graphics.h>
13 #include <fsp/util.h>
14 #include <intelblocks/graphics.h>
15 #include <soc/iomap.h>
16 #include <soc/soc_chip.h>
17 #include <stdlib.h>
18 #include <string.h>
19
20 /*
21 * Programs the Local Memory BAR (LMEMBAR) for the IGD.
22 *
23 * This function disables PCI command bits related to I/O, memory, and bus mastering
24 * for the IGD, programs the LMEMBAR with the provided base address, and then
25 * re-enables the PCI command bits.
26 */
27 static void program_igd_lmembar(uint32_t base)
28 {
29 const uint16_t disable_mask = ~(PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
30 const uint16_t enable_mask = (PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
31
32 /* Disable response in IO, MMIO space and Bus Master. */
33 pci_and_config16(SA_DEV_IGD, PCI_COMMAND, disable_mask);
34
35 /* Program IGD Base Address Register 2 aka LMEMBAR */
36 pci_write_config32(SA_DEV_IGD, PCI_BASE_ADDRESS_2, base);
37
38 /* Enable response in IO, MMIO space and Bus Master. */
39 pci_or_config16(SA_DEV_IGD, PCI_COMMAND, enable_mask);
40 }
41
42 /*
43 * Marks the GMADR range as Write-Combine (WC) memory.
44 *
45 * This function acquires and configures a temporary MTRR for the GMADR range.
46 *
47 * @return valid MTRR index on success, -1 on failure.
48 */
49 int soc_mark_gfx_memory(void)
50 {
51 /* Set up a temporary Write Combine (WC) MTRR for the GMADR range */
52 int temp_mtrr_index = acquire_and_configure_mtrr(GMADR_BASE, GMADR_SIZE, MTRR_TYPE_WRCOMB);
53 if (temp_mtrr_index < 0) {
54 printk(BIOS_ERR, "Failed to configure WC MTRR for GMADR.\n");
55 return -1;
56 }
57
58 return temp_mtrr_index;
59 }
60
61 void soc_load_logo_by_coreboot(void)
62 {
63 const struct hob_graphics_info *ginfo;
64 struct soc_intel_common_config *config = chip_get_common_soc_structure();
65 struct logo_config logo_cfg;
66 size_t size;
67
68 /* Find the graphics information HOB */
69 ginfo = fsp_find_extension_hob_by_guid(fsp_graphics_info_guid, &size);
70 if (!ginfo || ginfo->framebuffer_base == 0) {
71 printk(BIOS_ERR, "Graphics information HOB not found or invalid framebuffer base.\n");
72 return;
73 }
74
75 /* Program the IGD LMEMBAR */
76 program_igd_lmembar(GMADR_BASE);
77
78 /*
79 * Adjusts panel orientation for external display when the lid is closed.
80 *
81 * When the lid is closed, indicating the onboard display is inactive,
82 * below logic forces the panel orientation to normal. This ensures proper display
83 * on an external monitor, as rotated orientations are typically not suitable in
84 * such state.
85 */
86 if (CONFIG(VBOOT_LID_SWITCH) ? !get_lid_switch() : !CONFIG(RUN_FSP_GOP))
87 config->panel_orientation = LB_FB_ORIENTATION_NORMAL;
88
89
90 memset((void *)&logo_cfg, 0, sizeof(logo_cfg));
91 logo_cfg.framebuffer_base = ginfo->framebuffer_base;
92 logo_cfg.horizontal_resolution = ginfo->horizontal_resolution;
93 logo_cfg.vertical_resolution = ginfo->vertical_resolution;
94 logo_cfg.bytes_per_scanline = ginfo->pixels_per_scanline *
95 sizeof(efi_graphics_output_blt_pixel);
96 logo_cfg.panel_orientation = config->panel_orientation;
97 logo_cfg.halignment = FW_SPLASH_HALIGNMENT_CENTER;
98 logo_cfg.valignment = config->logo_valignment;
99 logo_cfg.logo_bottom_margin = config->logo_bottom_margin;
100
101 render_logo_to_framebuffer(&logo_cfg);
102 }