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 resource;
16
17static inline bool __screen_info_has_lfb(unsigned int type)
18{
19 return (type == VIDEO_TYPE_VLFB) || (type == VIDEO_TYPE_EFI);
20}
21
22static inline u64 __screen_info_lfb_base(const struct screen_info *si)
23{
24 u64 lfb_base = si->lfb_base;
25
26 if (si->capabilities & VIDEO_CAPABILITY_64BIT_BASE)
27 lfb_base |= (u64)si->ext_lfb_base << 32;
28
29 return lfb_base;
30}
31
32static inline void __screen_info_set_lfb_base(struct screen_info *si, u64 lfb_base)
33{
34 si->lfb_base = lfb_base & GENMASK_ULL(31, 0);
35 si->ext_lfb_base = (lfb_base & GENMASK_ULL(63, 32)) >> 32;
36
37 if (si->ext_lfb_base)
38 si->capabilities |= VIDEO_CAPABILITY_64BIT_BASE;
39 else
40 si->capabilities &= ~VIDEO_CAPABILITY_64BIT_BASE;
41}
42
43static inline u64 __screen_info_lfb_size(const struct screen_info *si, unsigned int type)
44{
45 u64 lfb_size = si->lfb_size;
46
47 if (type == VIDEO_TYPE_VLFB)
48 lfb_size <<= 16;
49 return lfb_size;
50}
51
52static inline unsigned int __screen_info_video_type(unsigned int type)
53{
54 switch (type) {
55 case VIDEO_TYPE_MDA:
56 case VIDEO_TYPE_CGA:
57 case VIDEO_TYPE_EGAM:
58 case VIDEO_TYPE_EGAC:
59 case VIDEO_TYPE_VGAC:
60 case VIDEO_TYPE_VLFB:
61 case VIDEO_TYPE_PICA_S3:
62 case VIDEO_TYPE_MIPS_G364:
63 case VIDEO_TYPE_SGI:
64 case VIDEO_TYPE_TGAC:
65 case VIDEO_TYPE_SUN:
66 case VIDEO_TYPE_SUNPCI:
67 case VIDEO_TYPE_PMAC:
68 case VIDEO_TYPE_EFI:
69 return type;
70 default:
71 return 0;
72 }
73}
74
75/**
76 * screen_info_video_type() - Decodes the video type from struct screen_info
77 * @si: an instance of struct screen_info
78 *
79 * Returns:
80 * A VIDEO_TYPE_ constant representing si's type of video display, or 0 otherwise.
81 */
82static inline unsigned int screen_info_video_type(const struct screen_info *si)
83{
84 unsigned int type;
85
86 // check if display output is on
87 if (!si->orig_video_isVGA)
88 return 0;
89
90 // check for a known VIDEO_TYPE_ constant
91 type = __screen_info_video_type(type: si->orig_video_isVGA);
92 if (type)
93 return si->orig_video_isVGA;
94
95 // check if text mode has been initialized
96 if (!si->orig_video_lines || !si->orig_video_cols)
97 return 0;
98
99 // 80x25 text, mono
100 if (si->orig_video_mode == 0x07) {
101 if ((si->orig_video_ega_bx & 0xff) != 0x10)
102 return VIDEO_TYPE_EGAM;
103 else
104 return VIDEO_TYPE_MDA;
105 }
106
107 // EGA/VGA, 16 colors
108 if ((si->orig_video_ega_bx & 0xff) != 0x10) {
109 if (si->orig_video_isVGA)
110 return VIDEO_TYPE_VGAC;
111 else
112 return VIDEO_TYPE_EGAC;
113 }
114
115 // the rest...
116 return VIDEO_TYPE_CGA;
117}
118
119ssize_t screen_info_resources(const struct screen_info *si, struct resource *r, size_t num);
120
121#if defined(CONFIG_PCI)
122void screen_info_apply_fixups(void);
123struct pci_dev *screen_info_pci_dev(const struct screen_info *si);
124#else
125static inline void screen_info_apply_fixups(void)
126{ }
127static inline struct pci_dev *screen_info_pci_dev(const struct screen_info *si)
128{
129 return NULL;
130}
131#endif
132
133extern struct screen_info screen_info;
134
135#endif /* _SCREEN_INFO_H */
136

source code of linux/include/linux/screen_info.h