From: Thomas Zimmermann <tzimmermann@suse.de>
To: javierm@redhat.com
Cc: dri-devel@lists.freedesktop.org, Thomas Zimmermann <tzimmermann@suse.de>
Subject: [PATCH 2/9] video: screen_info: Add pixel-format helper for linear framebuffers
Date: Tue, 17 Jun 2025 16:23:14 +0200 [thread overview]
Message-ID: <20250617143649.143967-3-tzimmermann@suse.de> (raw)
In-Reply-To: <20250617143649.143967-1-tzimmermann@suse.de>
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>
---
drivers/video/screen_info_generic.c | 55 +++++++++++++++++++++++++++++
include/linux/screen_info.h | 2 ++
2 files changed, 57 insertions(+)
diff --git a/drivers/video/screen_info_generic.c b/drivers/video/screen_info_generic.c
index 900e9386eceb..763adbba71cb 100644
--- a/drivers/video/screen_info_generic.c
+++ b/drivers/video/screen_info_generic.c
@@ -5,6 +5,8 @@
#include <linux/screen_info.h>
#include <linux/string.h>
+#include <video/pixel_format.h>
+
static void resource_init_named(struct resource *r,
resource_size_t start, resource_size_t size,
const char *name, unsigned int flags)
@@ -180,3 +182,56 @@ u32 __screen_info_lfb_bits_per_pixel(const struct screen_info *si)
return bits_per_pixel;
}
EXPORT_SYMBOL(__screen_info_lfb_bits_per_pixel);
+
+static int __screen_info_lfb_pixel_format(const struct screen_info *si, struct pixel_format *f)
+{
+ u32 bits_per_pixel = __screen_info_lfb_bits_per_pixel(si);
+
+ if (bits_per_pixel > U8_MAX)
+ return -EINVAL;
+
+ f->bits_per_pixel = bits_per_pixel;
+
+ if (si->lfb_depth > 8) {
+ f->indexed = false;
+ f->alpha.offset = 0;
+ f->alpha.length = 0;
+ f->red.offset = si->red_pos;
+ f->red.length = si->red_size;
+ f->green.offset = si->green_pos;
+ f->green.length = si->green_size;
+ f->blue.offset = si->blue_pos;
+ f->blue.length = si->blue_size;
+ } else {
+ f->indexed = true;
+ f->index.offset = 0;
+ f->index.length = si->lfb_depth;
+ }
+
+ return 0;
+}
+
+/**
+ * screen_info_pixel_format - Returns the screen-info format as pixel-format description
+ *
+ * @si: the screen_info
+ * @f: pointer to return pixel-format description
+ *
+ * Returns:
+ * 0 on success, or a negative errno code otherwise.
+ */
+int screen_info_pixel_format(const struct screen_info *si, struct pixel_format *f)
+{
+ unsigned int type = screen_info_video_type(si);
+
+ /* TODO: Add support for additional types as needed. */
+ switch (type) {
+ case VIDEO_TYPE_VLFB:
+ case VIDEO_TYPE_EFI:
+ return __screen_info_lfb_pixel_format(si, f);
+ }
+
+ /* not supported */
+ return -EINVAL;
+}
+EXPORT_SYMBOL(screen_info_pixel_format);
diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
index 923d68e07679..1690706206e8 100644
--- a/include/linux/screen_info.h
+++ b/include/linux/screen_info.h
@@ -12,6 +12,7 @@
#define SCREEN_INFO_MAX_RESOURCES 3
struct pci_dev;
+struct pixel_format;
struct resource;
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)
ssize_t screen_info_resources(const struct screen_info *si, struct resource *r, size_t num);
u32 __screen_info_lfb_bits_per_pixel(const struct screen_info *si);
+int screen_info_pixel_format(const struct screen_info *si, struct pixel_format *f);
#if defined(CONFIG_PCI)
void screen_info_apply_fixups(void);
--
2.49.0
next prev parent reply other threads:[~2025-06-17 14:40 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-17 14:23 [PATCH 0/9] drm/vesadrm: Support 8-bit palettes Thomas Zimmermann
2025-06-17 14:23 ` [PATCH 1/9] video: pixel_format: Add compare helpers Thomas Zimmermann
2025-07-11 11:55 ` Javier Martinez Canillas
2025-06-17 14:23 ` Thomas Zimmermann [this message]
2025-07-11 11:58 ` [PATCH 2/9] video: screen_info: Add pixel-format helper for linear framebuffers Javier Martinez Canillas
2025-06-17 14:23 ` [PATCH 3/9] drm/sysfb: Find screen_info format with helpers Thomas Zimmermann
2025-07-11 12:08 ` Javier Martinez Canillas
2025-06-17 14:23 ` [PATCH 4/9] drm/sysfb: Blit to CRTC destination format Thomas Zimmermann
2025-07-11 12:10 ` Javier Martinez Canillas
2025-06-17 14:23 ` [PATCH 5/9] drm/color-mgmt: Prepare for RGB332 palettes Thomas Zimmermann
2025-07-11 12:24 ` Javier Martinez Canillas
2025-07-11 12:30 ` Thomas Zimmermann
2025-07-14 7:13 ` Thomas Zimmermann
2025-06-17 14:23 ` [PATCH 6/9] drm/format-helper: Add XRGB8888-to-RGB332 to drm_fb_blit() Thomas Zimmermann
2025-07-11 12:25 ` Javier Martinez Canillas
2025-06-17 14:23 ` [PATCH 7/9] drm/vesadrm: Rename vesadrm_set_gamma_lut() to vesadrm_set_color_lut() Thomas Zimmermann
2025-07-11 12:25 ` Javier Martinez Canillas
2025-06-17 14:23 ` [PATCH 8/9] drm/vesadrm: Prepare color management for palette-based framebuffers Thomas Zimmermann
2025-07-11 12:26 ` Javier Martinez Canillas
2025-06-17 14:23 ` [PATCH 9/9] drm/vesadrm: Support DRM_FORMAT_C8 Thomas Zimmermann
2025-07-11 12:33 ` Javier Martinez Canillas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250617143649.143967-3-tzimmermann@suse.de \
--to=tzimmermann@suse.de \
--cc=dri-devel@lists.freedesktop.org \
--cc=javierm@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.