xref: /linux-6.15/include/linux/screen_info.h (revision 75fa9b7e)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _SCREEN_INFO_H
3 #define _SCREEN_INFO_H
4 
5 #include <uapi/linux/screen_info.h>
6 
7 /**
8  * SCREEN_INFO_MAX_RESOURCES - maximum number of resources per screen_info
9  */
10 #define SCREEN_INFO_MAX_RESOURCES	3
11 
12 struct resource;
13 
14 static inline bool __screen_info_has_lfb(unsigned int type)
15 {
16 	return (type == VIDEO_TYPE_VLFB) || (type == VIDEO_TYPE_EFI);
17 }
18 
19 static inline u64 __screen_info_lfb_base(const struct screen_info *si)
20 {
21 	u64 lfb_base = si->lfb_base;
22 
23 	if (si->capabilities & VIDEO_CAPABILITY_64BIT_BASE)
24 		lfb_base |= (u64)si->ext_lfb_base << 32;
25 
26 	return lfb_base;
27 }
28 
29 static inline u64 __screen_info_lfb_size(const struct screen_info *si, unsigned int type)
30 {
31 	u64 lfb_size = si->lfb_size;
32 
33 	if (type == VIDEO_TYPE_VLFB)
34 		lfb_size <<= 16;
35 	return lfb_size;
36 }
37 
38 static inline unsigned int __screen_info_video_type(unsigned int type)
39 {
40 	switch (type) {
41 	case VIDEO_TYPE_MDA:
42 	case VIDEO_TYPE_CGA:
43 	case VIDEO_TYPE_EGAM:
44 	case VIDEO_TYPE_EGAC:
45 	case VIDEO_TYPE_VGAC:
46 	case VIDEO_TYPE_VLFB:
47 	case VIDEO_TYPE_PICA_S3:
48 	case VIDEO_TYPE_MIPS_G364:
49 	case VIDEO_TYPE_SGI:
50 	case VIDEO_TYPE_TGAC:
51 	case VIDEO_TYPE_SUN:
52 	case VIDEO_TYPE_SUNPCI:
53 	case VIDEO_TYPE_PMAC:
54 	case VIDEO_TYPE_EFI:
55 		return type;
56 	default:
57 		return 0;
58 	}
59 }
60 
61 /**
62  * screen_info_video_type() - Decodes the video type from struct screen_info
63  * @si: an instance of struct screen_info
64  *
65  * Returns:
66  * A VIDEO_TYPE_ constant representing si's type of video display, or 0 otherwise.
67  */
68 static inline unsigned int screen_info_video_type(const struct screen_info *si)
69 {
70 	unsigned int type;
71 
72 	// check if display output is on
73 	if (!si->orig_video_isVGA)
74 		return 0;
75 
76 	// check for a known VIDEO_TYPE_ constant
77 	type = __screen_info_video_type(si->orig_video_isVGA);
78 	if (type)
79 		return si->orig_video_isVGA;
80 
81 	// check if text mode has been initialized
82 	if (!si->orig_video_lines || !si->orig_video_cols)
83 		return 0;
84 
85 	// 80x25 text, mono
86 	if (si->orig_video_mode == 0x07) {
87 		if ((si->orig_video_ega_bx & 0xff) != 0x10)
88 			return VIDEO_TYPE_EGAM;
89 		else
90 			return VIDEO_TYPE_MDA;
91 	}
92 
93 	// EGA/VGA, 16 colors
94 	if ((si->orig_video_ega_bx & 0xff) != 0x10) {
95 		if (si->orig_video_isVGA)
96 			return VIDEO_TYPE_VGAC;
97 		else
98 			return VIDEO_TYPE_EGAC;
99 	}
100 
101 	// the rest...
102 	return VIDEO_TYPE_CGA;
103 }
104 
105 ssize_t screen_info_resources(const struct screen_info *si, struct resource *r, size_t num);
106 
107 extern struct screen_info screen_info;
108 
109 #endif /* _SCREEN_INFO_H */
110