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#include <linux/bits.h>
8
9/**
10 * SCREEN_INFO_MAX_RESOURCES - maximum number of resources per screen_info
11 */
12#define SCREEN_INFO_MAX_RESOURCES 3
13
14struct pci_dev;
15struct pixel_format;
16struct resource;
17
18static inline bool __screen_info_has_lfb(unsigned int type)
19{
20 return (type == VIDEO_TYPE_VLFB) || (type == VIDEO_TYPE_EFI);
21}
22
23static inline u64 __screen_info_lfb_base(const struct screen_info *si)
24{
25 u64 lfb_base = si->lfb_base;
26
27 if (si->capabilities & VIDEO_CAPABILITY_64BIT_BASE)
28 lfb_base |= (u64)si->ext_lfb_base << 32;
29
30 return lfb_base;
31}
32
33static inline void __screen_info_set_lfb_base(struct screen_info *si, u64 lfb_base)
34{
35 si->lfb_base = lfb_base & GENMASK_ULL(31, 0);
36 si->ext_lfb_base = (lfb_base & GENMASK_ULL(63, 32)) >> 32;
37
38 if (si->ext_lfb_base)
39 si->capabilities |= VIDEO_CAPABILITY_64BIT_BASE;
40 else
41 si->capabilities &= ~VIDEO_CAPABILITY_64BIT_BASE;
42}
43
44static inline u64 __screen_info_lfb_size(const struct screen_info *si, unsigned int type)
45{
46 u64 lfb_size = si->lfb_size;
47
48 if (type == VIDEO_TYPE_VLFB)
49 lfb_size <<= 16;
50 return lfb_size;
51}
52
53static inline bool __screen_info_vbe_mode_nonvga(const struct screen_info *si)
54{
55 /*
56 * VESA modes typically run on VGA hardware. Set bit 5 signals that this
57 * is not the case. Drivers can then not make use of VGA resources. See
58 * Sec 4.4 of the VBE 2.0 spec.
59 */
60 return si->vesa_attributes & BIT(5);
61}
62
63static inline unsigned int __screen_info_video_type(unsigned int type)
64{
65 switch (type) {
66 case VIDEO_TYPE_MDA:
67 case VIDEO_TYPE_CGA:
68 case VIDEO_TYPE_EGAM:
69 case VIDEO_TYPE_EGAC:
70 case VIDEO_TYPE_VGAC:
71 case VIDEO_TYPE_VLFB:
72 case VIDEO_TYPE_PICA_S3:
73 case VIDEO_TYPE_MIPS_G364:
74 case VIDEO_TYPE_SGI:
75 case VIDEO_TYPE_TGAC:
76 case VIDEO_TYPE_SUN:
77 case VIDEO_TYPE_SUNPCI:
78 case VIDEO_TYPE_PMAC:
79 case VIDEO_TYPE_EFI:
80 return type;
81 default:
82 return 0;
83 }
84}
85
86/**
87 * screen_info_video_type() - Decodes the video type from struct screen_info
88 * @si: an instance of struct screen_info
89 *
90 * Returns:
91 * A VIDEO_TYPE_ constant representing si's type of video display, or 0 otherwise.
92 */
93static inline unsigned int screen_info_video_type(const struct screen_info *si)
94{
95 unsigned int type;
96
97 // check if display output is on
98 if (!si->orig_video_isVGA)
99 return 0;
100
101 // check for a known VIDEO_TYPE_ constant
102 type = __screen_info_video_type(type: si->orig_video_isVGA);
103 if (type)
104 return si->orig_video_isVGA;
105
106 // check if text mode has been initialized
107 if (!si->orig_video_lines || !si->orig_video_cols)
108 return 0;
109
110 // 80x25 text, mono
111 if (si->orig_video_mode == 0x07) {
112 if ((si->orig_video_ega_bx & 0xff) != 0x10)
113 return VIDEO_TYPE_EGAM;
114 else
115 return VIDEO_TYPE_MDA;
116 }
117
118 // EGA/VGA, 16 colors
119 if ((si->orig_video_ega_bx & 0xff) != 0x10) {
120 if (si->orig_video_isVGA)
121 return VIDEO_TYPE_VGAC;
122 else
123 return VIDEO_TYPE_EGAC;
124 }
125
126 // the rest...
127 return VIDEO_TYPE_CGA;
128}
129
130static inline u32 __screen_info_vesapm_info_base(const struct screen_info *si)
131{
132 if (si->vesapm_seg < 0xc000)
133 return 0;
134 return (si->vesapm_seg << 4) + si->vesapm_off;
135}
136
137ssize_t screen_info_resources(const struct screen_info *si, struct resource *r, size_t num);
138
139u32 __screen_info_lfb_bits_per_pixel(const struct screen_info *si);
140int screen_info_pixel_format(const struct screen_info *si, struct pixel_format *f);
141
142#if defined(CONFIG_PCI)
143void screen_info_apply_fixups(void);
144struct pci_dev *screen_info_pci_dev(const struct screen_info *si);
145#else
146static inline void screen_info_apply_fixups(void)
147{ }
148static inline struct pci_dev *screen_info_pci_dev(const struct screen_info *si)
149{
150 return NULL;
151}
152#endif
153
154extern struct screen_info screen_info;
155
156#endif /* _SCREEN_INFO_H */
157