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

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

+39 -30
+1 -30
drivers/firmware/sysfb_simplefb.c
··· 35 35 if (type != VIDEO_TYPE_VLFB && type != VIDEO_TYPE_EFI) 36 36 return false; 37 37 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); 68 39 69 40 for (i = 0; i < ARRAY_SIZE(formats); ++i) { 70 41 const struct simplefb_format *f = &formats[i];
+36
drivers/video/screen_info_generic.c
··· 144 144 return pos - r; 145 145 } 146 146 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);
+2
include/linux/screen_info.h
··· 128 128 129 129 ssize_t screen_info_resources(const struct screen_info *si, struct resource *r, size_t num); 130 130 131 + u32 __screen_info_lfb_bits_per_pixel(const struct screen_info *si); 132 + 131 133 #if defined(CONFIG_PCI) 132 134 void screen_info_apply_fixups(void); 133 135 struct pci_dev *screen_info_pci_dev(const struct screen_info *si);