xref: /linux/arch/x86/xen/vga.c (revision 4b660dbd9ee2059850fd30e0df420ca7a38a1856)
1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/screen_info.h>
3 #include <linux/init.h>
4 
5 #include <asm/setup.h>
6 
7 #include <xen/interface/xen.h>
8 
9 #include "xen-ops.h"
10 
11 void __init xen_init_vga(const struct dom0_vga_console_info *info, size_t size,
12 			 struct screen_info *screen_info)
13 {
14 	/* This is drawn from a dump from vgacon:startup in
15 	 * standard Linux. */
16 	screen_info->orig_video_mode = 3;
17 	screen_info->orig_video_isVGA = 1;
18 	screen_info->orig_video_lines = 25;
19 	screen_info->orig_video_cols = 80;
20 	screen_info->orig_video_ega_bx = 3;
21 	screen_info->orig_video_points = 16;
22 	screen_info->orig_y = screen_info->orig_video_lines - 1;
23 
24 	switch (info->video_type) {
25 	case XEN_VGATYPE_TEXT_MODE_3:
26 		if (size < offsetof(struct dom0_vga_console_info, u.text_mode_3)
27 		    + sizeof(info->u.text_mode_3))
28 			break;
29 		screen_info->orig_video_lines = info->u.text_mode_3.rows;
30 		screen_info->orig_video_cols = info->u.text_mode_3.columns;
31 		screen_info->orig_x = info->u.text_mode_3.cursor_x;
32 		screen_info->orig_y = info->u.text_mode_3.cursor_y;
33 		screen_info->orig_video_points =
34 			info->u.text_mode_3.font_height;
35 		break;
36 
37 	case XEN_VGATYPE_EFI_LFB:
38 	case XEN_VGATYPE_VESA_LFB:
39 		if (size < offsetof(struct dom0_vga_console_info,
40 				    u.vesa_lfb.gbl_caps))
41 			break;
42 		screen_info->orig_video_isVGA = VIDEO_TYPE_VLFB;
43 		screen_info->lfb_width = info->u.vesa_lfb.width;
44 		screen_info->lfb_height = info->u.vesa_lfb.height;
45 		screen_info->lfb_depth = info->u.vesa_lfb.bits_per_pixel;
46 		screen_info->lfb_base = info->u.vesa_lfb.lfb_base;
47 		screen_info->lfb_size = info->u.vesa_lfb.lfb_size;
48 		screen_info->lfb_linelength = info->u.vesa_lfb.bytes_per_line;
49 		screen_info->red_size = info->u.vesa_lfb.red_size;
50 		screen_info->red_pos = info->u.vesa_lfb.red_pos;
51 		screen_info->green_size = info->u.vesa_lfb.green_size;
52 		screen_info->green_pos = info->u.vesa_lfb.green_pos;
53 		screen_info->blue_size = info->u.vesa_lfb.blue_size;
54 		screen_info->blue_pos = info->u.vesa_lfb.blue_pos;
55 		screen_info->rsvd_size = info->u.vesa_lfb.rsvd_size;
56 		screen_info->rsvd_pos = info->u.vesa_lfb.rsvd_pos;
57 
58 		if (size >= offsetof(struct dom0_vga_console_info,
59 				     u.vesa_lfb.ext_lfb_base)
60 		    + sizeof(info->u.vesa_lfb.ext_lfb_base)
61 		    && info->u.vesa_lfb.ext_lfb_base) {
62 			screen_info->ext_lfb_base = info->u.vesa_lfb.ext_lfb_base;
63 			screen_info->capabilities |= VIDEO_CAPABILITY_64BIT_BASE;
64 		}
65 
66 		if (info->video_type == XEN_VGATYPE_EFI_LFB) {
67 			screen_info->orig_video_isVGA = VIDEO_TYPE_EFI;
68 			break;
69 		}
70 
71 		if (size >= offsetof(struct dom0_vga_console_info,
72 				     u.vesa_lfb.mode_attrs)
73 		    + sizeof(info->u.vesa_lfb.mode_attrs))
74 			screen_info->vesa_attributes = info->u.vesa_lfb.mode_attrs;
75 		break;
76 	}
77 }
78