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