Skip to content

Commit 1ce4c3a

Browse files
committed
firmware: sysfb: Move bpp-depth calculation into screen_info helper
Move the calculation of the bits per pixels for screen_info into a helper function. This will make it available to other callers besides the firmware code. Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de> Reviewed-by: Javier Martinez Canillas <javierm@redhat.com> Link: https://lore.kernel.org/r/20250401094056.32904-14-tzimmermann@suse.de
1 parent e7f435b commit 1ce4c3a

File tree

3 files changed

+39
-30
lines changed

3 files changed

+39
-30
lines changed

drivers/firmware/sysfb_simplefb.c

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -35,36 +35,7 @@ __init bool sysfb_parse_mode(const struct screen_info *si,
3535
if (type != VIDEO_TYPE_VLFB && type != VIDEO_TYPE_EFI)
3636
return false;
3737

38-
/*
39-
* The meaning of depth and bpp for direct-color formats is
40-
* inconsistent:
41-
*
42-
* - DRM format info specifies depth as the number of color
43-
* bits; including alpha, but not including filler bits.
44-
* - Linux' EFI platform code computes lfb_depth from the
45-
* individual color channels, including the reserved bits.
46-
* - VBE 1.1 defines lfb_depth for XRGB1555 as 16, but later
47-
* versions use 15.
48-
* - On the kernel command line, 'bpp' of 32 is usually
49-
* XRGB8888 including the filler bits, but 15 is XRGB1555
50-
* not including the filler bit.
51-
*
52-
* It's not easily possible to fix this in struct screen_info,
53-
* as this could break UAPI. The best solution is to compute
54-
* bits_per_pixel from the color bits, reserved bits and
55-
* reported lfb_depth, whichever is highest. In the loop below,
56-
* ignore simplefb formats with alpha bits, as EFI and VESA
57-
* don't specify alpha channels.
58-
*/
59-
if (si->lfb_depth > 8) {
60-
bits_per_pixel = max(max3(si->red_size + si->red_pos,
61-
si->green_size + si->green_pos,
62-
si->blue_size + si->blue_pos),
63-
si->rsvd_size + si->rsvd_pos);
64-
bits_per_pixel = max_t(u32, bits_per_pixel, si->lfb_depth);
65-
} else {
66-
bits_per_pixel = si->lfb_depth;
67-
}
38+
bits_per_pixel = __screen_info_lfb_bits_per_pixel(si);
6839

6940
for (i = 0; i < ARRAY_SIZE(formats); ++i) {
7041
const struct simplefb_format *f = &formats[i];

drivers/video/screen_info_generic.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,39 @@ ssize_t screen_info_resources(const struct screen_info *si, struct resource *r,
144144
return pos - r;
145145
}
146146
EXPORT_SYMBOL(screen_info_resources);
147+
148+
/*
149+
* The meaning of depth and bpp for direct-color formats is
150+
* inconsistent:
151+
*
152+
* - DRM format info specifies depth as the number of color
153+
* bits; including alpha, but not including filler bits.
154+
* - Linux' EFI platform code computes lfb_depth from the
155+
* individual color channels, including the reserved bits.
156+
* - VBE 1.1 defines lfb_depth for XRGB1555 as 16, but later
157+
* versions use 15.
158+
* - On the kernel command line, 'bpp' of 32 is usually
159+
* XRGB8888 including the filler bits, but 15 is XRGB1555
160+
* not including the filler bit.
161+
*
162+
* It is not easily possible to fix this in struct screen_info,
163+
* as this could break UAPI. The best solution is to compute
164+
* bits_per_pixel from the color bits, reserved bits and
165+
* reported lfb_depth, whichever is highest.
166+
*/
167+
168+
u32 __screen_info_lfb_bits_per_pixel(const struct screen_info *si)
169+
{
170+
u32 bits_per_pixel = si->lfb_depth;
171+
172+
if (bits_per_pixel > 8) {
173+
bits_per_pixel = max(max3(si->red_size + si->red_pos,
174+
si->green_size + si->green_pos,
175+
si->blue_size + si->blue_pos),
176+
si->rsvd_size + si->rsvd_pos);
177+
bits_per_pixel = max_t(u32, bits_per_pixel, si->lfb_depth);
178+
}
179+
180+
return bits_per_pixel;
181+
}
182+
EXPORT_SYMBOL(__screen_info_lfb_bits_per_pixel);

include/linux/screen_info.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ static inline unsigned int screen_info_video_type(const struct screen_info *si)
128128

129129
ssize_t screen_info_resources(const struct screen_info *si, struct resource *r, size_t num);
130130

131+
u32 __screen_info_lfb_bits_per_pixel(const struct screen_info *si);
132+
131133
#if defined(CONFIG_PCI)
132134
void screen_info_apply_fixups(void);
133135
struct pci_dev *screen_info_pci_dev(const struct screen_info *si);

0 commit comments

Comments
 (0)