Skip to content

Commit d6d05e2

Browse files
committed
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
1 parent cff5fb8 commit d6d05e2

2 files changed

Lines changed: 57 additions & 0 deletions

File tree

drivers/video/screen_info_generic.c

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include <linux/screen_info.h>
66
#include <linux/string.h>
77

8+
#include <video/pixel_format.h>
9+
810
static void resource_init_named(struct resource *r,
911
resource_size_t start, resource_size_t size,
1012
const char *name, unsigned int flags)
@@ -180,3 +182,56 @@ u32 __screen_info_lfb_bits_per_pixel(const struct screen_info *si)
180182
return bits_per_pixel;
181183
}
182184
EXPORT_SYMBOL(__screen_info_lfb_bits_per_pixel);
185+
186+
static int __screen_info_lfb_pixel_format(const struct screen_info *si, struct pixel_format *f)
187+
{
188+
u32 bits_per_pixel = __screen_info_lfb_bits_per_pixel(si);
189+
190+
if (bits_per_pixel > U8_MAX)
191+
return -EINVAL;
192+
193+
f->bits_per_pixel = bits_per_pixel;
194+
195+
if (si->lfb_depth > 8) {
196+
f->indexed = false;
197+
f->alpha.offset = 0;
198+
f->alpha.length = 0;
199+
f->red.offset = si->red_pos;
200+
f->red.length = si->red_size;
201+
f->green.offset = si->green_pos;
202+
f->green.length = si->green_size;
203+
f->blue.offset = si->blue_pos;
204+
f->blue.length = si->blue_size;
205+
} else {
206+
f->indexed = true;
207+
f->index.offset = 0;
208+
f->index.length = si->lfb_depth;
209+
}
210+
211+
return 0;
212+
}
213+
214+
/**
215+
* screen_info_pixel_format - Returns the screen-info format as pixel-format description
216+
*
217+
* @si: the screen_info
218+
* @f: pointer to return pixel-format description
219+
*
220+
* Returns:
221+
* 0 on success, or a negative errno code otherwise.
222+
*/
223+
int screen_info_pixel_format(const struct screen_info *si, struct pixel_format *f)
224+
{
225+
unsigned int type = screen_info_video_type(si);
226+
227+
/* TODO: Add support for additional types as needed. */
228+
switch (type) {
229+
case VIDEO_TYPE_VLFB:
230+
case VIDEO_TYPE_EFI:
231+
return __screen_info_lfb_pixel_format(si, f);
232+
}
233+
234+
/* not supported */
235+
return -EINVAL;
236+
}
237+
EXPORT_SYMBOL(screen_info_pixel_format);

include/linux/screen_info.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#define SCREEN_INFO_MAX_RESOURCES 3
1313

1414
struct pci_dev;
15+
struct pixel_format;
1516
struct resource;
1617

1718
static inline bool __screen_info_has_lfb(unsigned int type)
@@ -136,6 +137,7 @@ static inline u32 __screen_info_vesapm_info_base(const struct screen_info *si)
136137
ssize_t screen_info_resources(const struct screen_info *si, struct resource *r, size_t num);
137138

138139
u32 __screen_info_lfb_bits_per_pixel(const struct screen_info *si);
140+
int screen_info_pixel_format(const struct screen_info *si, struct pixel_format *f);
139141

140142
#if defined(CONFIG_PCI)
141143
void screen_info_apply_fixups(void);

0 commit comments

Comments
 (0)