Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

video: screen_info: Add pixel-format helper for linear framebuffers

Add screen_info_pixel_format(), which converts a screen_info's
information about the color format to struct pixel_format. The encoding
within the screen_info structure is complex and therefore prone to
errors. Later patches will convert callers to use the pixel format.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
Link: https://lore.kernel.org/r/20250714151513.309475-3-tzimmermann@suse.de

+57
+55
drivers/video/screen_info_generic.c
··· 5 5 #include <linux/screen_info.h> 6 6 #include <linux/string.h> 7 7 8 + #include <video/pixel_format.h> 9 + 8 10 static void resource_init_named(struct resource *r, 9 11 resource_size_t start, resource_size_t size, 10 12 const char *name, unsigned int flags) ··· 182 180 return bits_per_pixel; 183 181 } 184 182 EXPORT_SYMBOL(__screen_info_lfb_bits_per_pixel); 183 + 184 + static int __screen_info_lfb_pixel_format(const struct screen_info *si, struct pixel_format *f) 185 + { 186 + u32 bits_per_pixel = __screen_info_lfb_bits_per_pixel(si); 187 + 188 + if (bits_per_pixel > U8_MAX) 189 + return -EINVAL; 190 + 191 + f->bits_per_pixel = bits_per_pixel; 192 + 193 + if (si->lfb_depth > 8) { 194 + f->indexed = false; 195 + f->alpha.offset = 0; 196 + f->alpha.length = 0; 197 + f->red.offset = si->red_pos; 198 + f->red.length = si->red_size; 199 + f->green.offset = si->green_pos; 200 + f->green.length = si->green_size; 201 + f->blue.offset = si->blue_pos; 202 + f->blue.length = si->blue_size; 203 + } else { 204 + f->indexed = true; 205 + f->index.offset = 0; 206 + f->index.length = si->lfb_depth; 207 + } 208 + 209 + return 0; 210 + } 211 + 212 + /** 213 + * screen_info_pixel_format - Returns the screen-info format as pixel-format description 214 + * 215 + * @si: the screen_info 216 + * @f: pointer to return pixel-format description 217 + * 218 + * Returns: 219 + * 0 on success, or a negative errno code otherwise. 220 + */ 221 + int screen_info_pixel_format(const struct screen_info *si, struct pixel_format *f) 222 + { 223 + unsigned int type = screen_info_video_type(si); 224 + 225 + /* TODO: Add support for additional types as needed. */ 226 + switch (type) { 227 + case VIDEO_TYPE_VLFB: 228 + case VIDEO_TYPE_EFI: 229 + return __screen_info_lfb_pixel_format(si, f); 230 + } 231 + 232 + /* not supported */ 233 + return -EINVAL; 234 + } 235 + EXPORT_SYMBOL(screen_info_pixel_format);
+2
include/linux/screen_info.h
··· 12 12 #define SCREEN_INFO_MAX_RESOURCES 3 13 13 14 14 struct pci_dev; 15 + struct pixel_format; 15 16 struct resource; 16 17 17 18 static inline bool __screen_info_has_lfb(unsigned int type) ··· 137 136 ssize_t screen_info_resources(const struct screen_info *si, struct resource *r, size_t num); 138 137 139 138 u32 __screen_info_lfb_bits_per_pixel(const struct screen_info *si); 139 + int screen_info_pixel_format(const struct screen_info *si, struct pixel_format *f); 140 140 141 141 #if defined(CONFIG_PCI) 142 142 void screen_info_apply_fixups(void);