• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #include <boot/coreboot_tables.h>
4 #include <console/console.h>
5 #include <elog.h>
6 #include <fsp/graphics.h>
7 #include <fsp/util.h>
8 #include <soc/intel/common/vbt.h>
9 #include <types.h>
10 #include <framebuffer_info.h>
11 
12 enum pixel_format {
13 	pixel_rgbx_8bpc = 0,
14 	pixel_bgrx_8bpc = 1,
15 	pixel_bitmask = 2,		/* defined by <rgb>_mask values */
16 };
17 
18 static const uint8_t fsp_graphics_info_guid[16] = {
19 	0xce, 0x2c, 0xf6, 0x39, 0x25, 0x68, 0x69, 0x46,
20 	0xbb, 0x56, 0x54, 0x1a, 0xba, 0x75, 0x3a, 0x07
21 };
22 
23 struct hob_graphics_info {
24 	uint64_t framebuffer_base;
25 	uint32_t framebuffer_size;
26 	uint32_t version;
27 	uint32_t horizontal_resolution;
28 	uint32_t vertical_resolution;
29 	uint32_t pixel_format;		/* See enum pixel_format */
30 	uint32_t red_mask;
31 	uint32_t green_mask;
32 	uint32_t blue_mask;
33 	uint32_t reserved_mask;
34 	uint32_t pixels_per_scanline;
35 } __packed;
36 
37 struct pixel {
38 	uint8_t pos;
39 	uint8_t size;
40 };
41 
42 static const struct fsp_framebuffer {
43 	struct pixel red;
44 	struct pixel green;
45 	struct pixel blue;
46 	struct pixel rsvd;
47 } fsp_framebuffer_format_map[] = {
48 	[pixel_rgbx_8bpc] = { {0, 8}, {8, 8}, {16, 8}, {24, 8} },
49 	[pixel_bgrx_8bpc] = { {16, 8}, {8, 8}, {0, 8}, {24, 8} },
50 };
51 
52 enum fw_splash_screen_status {
53 	FW_SPLASH_SCREEN_DISABLED,
54 	FW_SPLASH_SCREEN_ENABLED,
55 };
56 
57 /* Check and report if an external display is attached */
fsp_soc_report_external_display(void)58 __weak int fsp_soc_report_external_display(void)
59 {
60 	/* Default implementation, on-board display enabled */
61 	return 0;
62 }
63 
64 /*
65  * Update elog with Firmware Splash Screen related information
66  * based on enum fw_splash_screen_status.
67  *
68  * Possible values for input argument are:
69  * TRUE - FSP initializes display when BMP_LOGO config is enabled.
70  * FALSE - Failed to initialize display although BMP_LOGO config is selected.
71  *
72  * Ignore if BMP_LOGO config is not selected.
73  */
update_fw_splash_screen_event(enum fw_splash_screen_status status)74 static void update_fw_splash_screen_event(enum fw_splash_screen_status status)
75 {
76 	if (!CONFIG(BMP_LOGO))
77 		return;
78 
79 	printk(BIOS_DEBUG, "Firmware Splash Screen : %s\n",
80 		       status ? "Enabled" : "Disabled");
81 
82 	elog_add_event_byte(ELOG_TYPE_FW_SPLASH_SCREEN, status);
83 }
84 
fsp_report_framebuffer_info(const uintptr_t framebuffer_bar,enum lb_fb_orientation orientation)85 void fsp_report_framebuffer_info(const uintptr_t framebuffer_bar,
86 				 enum lb_fb_orientation orientation)
87 {
88 	size_t size;
89 	const struct hob_graphics_info *ginfo;
90 	const struct fsp_framebuffer *fbinfo;
91 
92 	/*
93 	 * Pci enumeration happens after silicon init.
94 	 * After enumeration graphic framebuffer base may be relocated.
95 	 */
96 	if (!framebuffer_bar) {
97 		printk(BIOS_ALERT, "Framebuffer BAR invalid\n");
98 		update_fw_splash_screen_event(FW_SPLASH_SCREEN_DISABLED);
99 		return;
100 	}
101 
102 	ginfo = fsp_find_extension_hob_by_guid(fsp_graphics_info_guid, &size);
103 
104 	if (!ginfo) {
105 		printk(BIOS_ALERT, "Graphics hand-off block not found\n");
106 		update_fw_splash_screen_event(FW_SPLASH_SCREEN_DISABLED);
107 		return;
108 	}
109 
110 	if (ginfo->pixel_format >= ARRAY_SIZE(fsp_framebuffer_format_map)) {
111 		printk(BIOS_ALERT, "FSP set unknown framebuffer format: %d\n",
112 		       ginfo->pixel_format);
113 		update_fw_splash_screen_event(FW_SPLASH_SCREEN_DISABLED);
114 		return;
115 	}
116 
117 	update_fw_splash_screen_event(FW_SPLASH_SCREEN_ENABLED);
118 	fbinfo = fsp_framebuffer_format_map + ginfo->pixel_format;
119 
120 	const struct lb_framebuffer fb = {
121 		.physical_address    = framebuffer_bar,
122 		.x_resolution        = ginfo->horizontal_resolution,
123 		.y_resolution        = ginfo->vertical_resolution,
124 		.bytes_per_line      = ginfo->pixels_per_scanline * 4,
125 		.bits_per_pixel      = fbinfo->rsvd.size + fbinfo->red.size +
126 				       fbinfo->green.size + fbinfo->blue.size,
127 		.red_mask_pos        = fbinfo->red.pos,
128 		.red_mask_size       = fbinfo->red.size,
129 		.green_mask_pos      = fbinfo->green.pos,
130 		.green_mask_size     = fbinfo->green.size,
131 		.blue_mask_pos       = fbinfo->blue.pos,
132 		.blue_mask_size      = fbinfo->blue.size,
133 		.reserved_mask_pos   = fbinfo->rsvd.pos,
134 		.reserved_mask_size  = fbinfo->rsvd.size,
135 		.orientation         = orientation,
136 		.flags = {
137 			.has_external_display = fsp_soc_report_external_display(),
138 		},
139 	};
140 
141 	fb_add_framebuffer_info_ex(&fb);
142 }
143