All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/6] video: pixel format handling fixes and improvements
@ 2024-05-16 22:16 Jiaxun Yang
  2024-05-16 22:16 ` [PATCH 1/6] video: Move generated bmp headers to include/generated Jiaxun Yang
                   ` (5 more replies)
  0 siblings, 6 replies; 9+ messages in thread
From: Jiaxun Yang @ 2024-05-16 22:16 UTC (permalink / raw
  To: u-boot
  Cc: Tom Rini, Heiko Schocher, Marcel Ziswiler, Anatolij Gustschin,
	Heinrich Schuchardt, Ilias Apalodimas, Simon Glass, Jiaxun Yang

Hi all,

This series fixes endian related problem I found in general
video system when testing my fresh virtio-gpu driver on big
endian target.

It also removed a lot of duplicated code on pixel handling,
and make implementation of new pixel formats easier. Further
more, it removed limitation on bpc for BMP display, now we
can display any image depth on any target display controller.

Please review.
Thanks

Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
---
Jiaxun Yang (6):
      video: Move generated bmp headers to include/generated
      video: Add gitignore for u_boot_logo.S
      video: Rework pixel format handling
      video: bmp: Rework with video_rgb_to_pixel_*
      video: sandbox_sdl: Implement more pixel formats
      video: bochs: Setup framebuffer endian

 Makefile                          |   2 +-
 arch/sandbox/cpu/sdl.c            |  58 +++++++++--
 arch/sandbox/include/asm/sdl.h    |  17 ++--
 board/aristainetos/aristainetos.c |   2 +-
 board/toradex/common/tdx-common.c |   2 +-
 common/splash.c                   |   4 +-
 drivers/video/.gitignore          |   1 +
 drivers/video/bochs.c             |   8 ++
 drivers/video/console_truetype.c  |   4 +-
 drivers/video/sandbox_sdl.c       |  16 +--
 drivers/video/simplefb.c          |   2 +-
 drivers/video/video-uclass.c      |  38 ++-----
 drivers/video/video_bmp.c         | 201 +++++++++++---------------------------
 include/dm/test.h                 |   2 +
 include/video.h                   |  31 +-----
 include/video_format.h            | 161 ++++++++++++++++++++++++++++++
 lib/efi_loader/efi_gop.c          |   2 +-
 test/dm/video.c                   |  18 ++--
 tools/Makefile                    |   4 +-
 19 files changed, 332 insertions(+), 241 deletions(-)
---
base-commit: ad7dce5abd49ef3b5c93da5303e15449c8c162b4
change-id: 20240516-rework-video-format-ae8afadc45a5

Best regards,
-- 
Jiaxun Yang <jiaxun.yang@flygoat.com>


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/6] video: Move generated bmp headers to include/generated
  2024-05-16 22:16 [PATCH 0/6] video: pixel format handling fixes and improvements Jiaxun Yang
@ 2024-05-16 22:16 ` Jiaxun Yang
  2024-05-16 22:19   ` Tom Rini
  2024-05-17  6:14   ` Heiko Schocher
  2024-05-16 22:16 ` [PATCH 2/6] video: Add gitignore for u_boot_logo.S Jiaxun Yang
                   ` (4 subsequent siblings)
  5 siblings, 2 replies; 9+ messages in thread
From: Jiaxun Yang @ 2024-05-16 22:16 UTC (permalink / raw
  To: u-boot
  Cc: Tom Rini, Heiko Schocher, Marcel Ziswiler, Anatolij Gustschin,
	Heinrich Schuchardt, Ilias Apalodimas, Simon Glass, Jiaxun Yang

Emphasis that those headers are generated.
Also naturally gitignore them.

Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
---
 Makefile                          | 2 +-
 board/aristainetos/aristainetos.c | 2 +-
 board/toradex/common/tdx-common.c | 2 +-
 common/splash.c                   | 4 ++--
 tools/Makefile                    | 4 ++--
 5 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/Makefile b/Makefile
index 44deb339af19..77f3fead7f26 100644
--- a/Makefile
+++ b/Makefile
@@ -2191,7 +2191,7 @@ CLEAN_DIRS  += $(MODVERDIR) \
 	       $(foreach d, spl tpl vpl, $(patsubst %,$d/%, \
 			$(filter-out include, $(shell ls -1 $d 2>/dev/null))))
 
-CLEAN_FILES += include/autoconf.mk* include/bmp_logo.h include/bmp_logo_data.h \
+CLEAN_FILES += include/autoconf.mk* include/generated/bmp_*.h \
 	       include/config.h include/generated/env.* drivers/video/u_boot_logo.S \
 	       tools/version.h u-boot* MLO* SPL System.map fit-dtb.blob* \
 	       u-boot-ivt.img.log u-boot-dtb.imx.log SPL.log u-boot.imx.log \
diff --git a/board/aristainetos/aristainetos.c b/board/aristainetos/aristainetos.c
index 8cfac9fbb342..bd7f00dfc0fe 100644
--- a/board/aristainetos/aristainetos.c
+++ b/board/aristainetos/aristainetos.c
@@ -27,7 +27,6 @@
 #include <asm/io.h>
 #include <asm/arch/sys_proto.h>
 #include <asm/sections.h>
-#include <bmp_logo.h>
 #include <dm/root.h>
 #include <env.h>
 #include <i2c_eeprom.h>
@@ -40,6 +39,7 @@
 #include <power/da9063_pmic.h>
 #include <splash.h>
 #include <video.h>
+#include <generated/bmp_logo.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
diff --git a/board/toradex/common/tdx-common.c b/board/toradex/common/tdx-common.c
index a6b45cdab810..ffd5946b4ec8 100644
--- a/board/toradex/common/tdx-common.c
+++ b/board/toradex/common/tdx-common.c
@@ -12,9 +12,9 @@
 #include <sysinfo.h>
 
 #ifdef CONFIG_VIDEO
-#include <bmp_logo.h>
 #include <splash.h>
 #include <video.h>
+#include <generated/bmp_logo.h>
 #endif
 
 #include "tdx-cfg-block.h"
diff --git a/common/splash.c b/common/splash.c
index c5591293634a..096fcba09913 100644
--- a/common/splash.c
+++ b/common/splash.c
@@ -62,7 +62,7 @@ static struct splash_location default_splash_locations[] = {
 
 #ifdef CONFIG_VIDEO_LOGO
 
-#include <bmp_logo_data.h>
+#include <generated/bmp_logo_data.h>
 
 static int splash_video_logo_load(void)
 {
@@ -121,7 +121,7 @@ void splash_get_pos(int *x, int *y)
 #if CONFIG_IS_ENABLED(VIDEO) && !CONFIG_IS_ENABLED(HIDE_LOGO_VERSION)
 
 #ifdef CONFIG_VIDEO_LOGO
-#include <bmp_logo.h>
+#include <generated/bmp_logo.h>
 #endif
 #include <dm.h>
 #include <video_console.h>
diff --git a/tools/Makefile b/tools/Makefile
index 6a4280e3668f..edbe3fabc105 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -283,8 +283,8 @@ always := $(hostprogs-y)
 hostprogs-y += printinitialenv
 
 # Generated LCD/video logo
-LOGO_H = $(objtree)/include/bmp_logo.h
-LOGO_DATA_H = $(objtree)/include/bmp_logo_data.h
+LOGO_H = $(objtree)/include/generated/bmp_logo.h
+LOGO_DATA_H = $(objtree)/include/generated/bmp_logo_data.h
 LOGO-$(CONFIG_VIDEO_LOGO) += $(LOGO_H)
 LOGO-$(CONFIG_VIDEO_LOGO) += $(LOGO_DATA_H)
 

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/6] video: Add gitignore for u_boot_logo.S
  2024-05-16 22:16 [PATCH 0/6] video: pixel format handling fixes and improvements Jiaxun Yang
  2024-05-16 22:16 ` [PATCH 1/6] video: Move generated bmp headers to include/generated Jiaxun Yang
@ 2024-05-16 22:16 ` Jiaxun Yang
  2024-05-16 22:16 ` [PATCH 3/6] video: Rework pixel format handling Jiaxun Yang
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: Jiaxun Yang @ 2024-05-16 22:16 UTC (permalink / raw
  To: u-boot
  Cc: Tom Rini, Heiko Schocher, Marcel Ziswiler, Anatolij Gustschin,
	Heinrich Schuchardt, Ilias Apalodimas, Simon Glass, Jiaxun Yang

We don't want this generated file to be tracked by git.

Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
---
 drivers/video/.gitignore | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/video/.gitignore b/drivers/video/.gitignore
new file mode 100644
index 000000000000..163c491c7630
--- /dev/null
+++ b/drivers/video/.gitignore
@@ -0,0 +1 @@
+u_boot_logo.S

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 3/6] video: Rework pixel format handling
  2024-05-16 22:16 [PATCH 0/6] video: pixel format handling fixes and improvements Jiaxun Yang
  2024-05-16 22:16 ` [PATCH 1/6] video: Move generated bmp headers to include/generated Jiaxun Yang
  2024-05-16 22:16 ` [PATCH 2/6] video: Add gitignore for u_boot_logo.S Jiaxun Yang
@ 2024-05-16 22:16 ` Jiaxun Yang
  2024-05-16 22:16 ` [PATCH 4/6] video: bmp: Rework with video_rgb_to_pixel_* Jiaxun Yang
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: Jiaxun Yang @ 2024-05-16 22:16 UTC (permalink / raw
  To: u-boot
  Cc: Tom Rini, Heiko Schocher, Marcel Ziswiler, Anatolij Gustschin,
	Heinrich Schuchardt, Ilias Apalodimas, Simon Glass, Jiaxun Yang

Our current approach on naming pixel formats and handling them
is a little bit confusing, we don't consider endian for framebuffers.

Using Linux's naming approach instead to improve robustness of the
system, also consider both endians for all pixel formats.

Formats and RGB->Pixel conversion functions are stripped to
video_format.h so we can include them in sdl.c without pull in all
u-boot headers, and inline those conversion functions everywhere.

Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
---
 drivers/video/console_truetype.c |   4 +-
 drivers/video/simplefb.c         |   2 +-
 drivers/video/video-uclass.c     |  38 +++------
 drivers/video/video_bmp.c        |   6 +-
 include/video.h                  |  31 +-------
 include/video_format.h           | 161 +++++++++++++++++++++++++++++++++++++++
 lib/efi_loader/efi_gop.c         |   2 +-
 7 files changed, 179 insertions(+), 65 deletions(-)

diff --git a/drivers/video/console_truetype.c b/drivers/video/console_truetype.c
index c435162d3f94..ac0556ba1352 100644
--- a/drivers/video/console_truetype.c
+++ b/drivers/video/console_truetype.c
@@ -397,7 +397,7 @@ static int console_truetype_putc_xy(struct udevice *dev, uint x, uint y,
 
 					if (vid_priv->colour_bg)
 						val = 255 - val;
-					if (vid_priv->format == VIDEO_X2R10G10B10)
+					if (vid_priv->format == VIDEO_XRGB2101010)
 						out = val << 2 | val << 12 | val << 22;
 					else
 						out = val | val << 8 | val << 16;
@@ -923,7 +923,7 @@ static int truetype_set_cursor_visible(struct udevice *dev, bool visible,
 				for (i = 0; i < width; i++) {
 					int out;
 
-					if (vid_priv->format == VIDEO_X2R10G10B10)
+					if (vid_priv->format == VIDEO_XRGB2101010)
 						out = val << 2 | val << 12 | val << 22;
 					else
 						out = val | val << 8 | val << 16;
diff --git a/drivers/video/simplefb.c b/drivers/video/simplefb.c
index cb518b149cb5..5bbde0e8a9f9 100644
--- a/drivers/video/simplefb.c
+++ b/drivers/video/simplefb.c
@@ -72,7 +72,7 @@ static int simple_video_probe(struct udevice *dev)
 	} else if (strcmp(format, "a2r10g10b10") == 0 ||
 		   strcmp(format, "x2r10g10b10") == 0) {
 		uc_priv->bpix = VIDEO_BPP32;
-		uc_priv->format = VIDEO_X2R10G10B10;
+		uc_priv->format = VIDEO_XRGB2101010;
 	} else {
 		log_err("%s: invalid format: %s\n", __func__, format);
 		return -EINVAL;
diff --git a/drivers/video/video-uclass.c b/drivers/video/video-uclass.c
index ff1382f4a43b..513766b30fb1 100644
--- a/drivers/video/video-uclass.c
+++ b/drivers/video/video-uclass.c
@@ -65,13 +65,6 @@ struct video_uc_priv {
 	ulong video_ptr;
 };
 
-/** struct vid_rgb - Describes a video colour */
-struct vid_rgb {
-	u32 r;
-	u32 g;
-	u32 b;
-};
-
 void video_set_flush_dcache(struct udevice *dev, bool flush)
 {
 	struct video_priv *priv = dev_get_uclass_priv(dev);
@@ -259,7 +252,7 @@ int video_clear(struct udevice *dev)
 	return 0;
 }
 
-static const struct vid_rgb colours[VID_COLOUR_COUNT] = {
+static const struct video_rgb colours[VID_COLOUR_COUNT] = {
 	{ 0x00, 0x00, 0x00 },  /* black */
 	{ 0xc0, 0x00, 0x00 },  /* red */
 	{ 0x00, 0xc0, 0x00 },  /* green */
@@ -281,30 +274,17 @@ static const struct vid_rgb colours[VID_COLOUR_COUNT] = {
 u32 video_index_to_colour(struct video_priv *priv, enum colour_idx idx)
 {
 	switch (priv->bpix) {
+	case VIDEO_BPP8:
+		if (CONFIG_IS_ENABLED(VIDEO_BPP8))
+			return video_rgb_to_pixel8(priv->format, colours[idx]);
+		break;
 	case VIDEO_BPP16:
-		if (CONFIG_IS_ENABLED(VIDEO_BPP16)) {
-			return ((colours[idx].r >> 3) << 11) |
-			       ((colours[idx].g >> 2) <<  5) |
-			       ((colours[idx].b >> 3) <<  0);
-		}
+		if (CONFIG_IS_ENABLED(VIDEO_BPP16))
+			return video_rgb_to_pixel16(priv->format, colours[idx]);
 		break;
 	case VIDEO_BPP32:
-		if (CONFIG_IS_ENABLED(VIDEO_BPP32)) {
-			switch (priv->format) {
-			case VIDEO_X2R10G10B10:
-				return (colours[idx].r << 22) |
-				       (colours[idx].g << 12) |
-				       (colours[idx].b <<  2);
-			case VIDEO_RGBA8888:
-				return (colours[idx].r << 24) |
-				       (colours[idx].g << 16) |
-				       (colours[idx].b << 8) | 0xff;
-			default:
-				return (colours[idx].r << 16) |
-				       (colours[idx].g <<  8) |
-				       (colours[idx].b <<  0);
-			}
-		}
+		if (CONFIG_IS_ENABLED(VIDEO_BPP32))
+			return video_rgb_to_pixel32(priv->format, colours[idx]);
 		break;
 	default:
 		break;
diff --git a/drivers/video/video_bmp.c b/drivers/video/video_bmp.c
index ad512d99a1b9..83380a87fd2b 100644
--- a/drivers/video/video_bmp.c
+++ b/drivers/video/video_bmp.c
@@ -80,7 +80,7 @@ static void write_pix8(u8 *fb, uint bpix, enum video_format eformat,
 			*fb++ = cte->red;
 			*fb++ = cte->green;
 			*fb++ = cte->blue;
-		} else if (eformat == VIDEO_X2R10G10B10) {
+		} else if (eformat == VIDEO_XRGB2101010) {
 			*(u32 *)fb = get_bmp_col_x2r10g10b10(cte);
 		} else if (eformat == VIDEO_RGBA8888) {
 			*(u32 *)fb = get_bmp_col_rgba8888(cte);
@@ -385,7 +385,7 @@ int video_bmp_display(struct udevice *dev, ulong bmp_image, int x, int y,
 							(bmap[0] >> 3);
 						bmap += 3;
 						fb += 2;
-					} else if (eformat == VIDEO_X2R10G10B10) {
+					} else if (eformat == VIDEO_XRGB2101010) {
 						u32 pix;
 
 						pix = *bmap++ << 2U;
@@ -422,7 +422,7 @@ int video_bmp_display(struct udevice *dev, ulong bmp_image, int x, int y,
 		if (CONFIG_IS_ENABLED(BMP_32BPP)) {
 			for (i = 0; i < height; ++i) {
 				for (j = 0; j < width; j++) {
-					if (eformat == VIDEO_X2R10G10B10) {
+					if (eformat == VIDEO_XRGB2101010) {
 						u32 pix;
 
 						pix = *bmap++ << 2U;
diff --git a/include/video.h b/include/video.h
index 4d8df9baaada..d22d6ce5fd3c 100644
--- a/include/video.h
+++ b/include/video.h
@@ -8,6 +8,8 @@
 #define _VIDEO_H_
 
 #include <stdio_dev.h>
+#include <video_format.h>
+#include <asm/byteorder.h>
 
 struct udevice;
 
@@ -44,35 +46,6 @@ enum video_polarity {
 	VIDEO_ACTIVE_LOW,	/* Pins are active low */
 };
 
-/*
- * Bits per pixel selector. Each value n is such that the bits-per-pixel is
- * 2 ^ n
- */
-enum video_log2_bpp {
-	VIDEO_BPP1	= 0,
-	VIDEO_BPP2,
-	VIDEO_BPP4,
-	VIDEO_BPP8,
-	VIDEO_BPP16,
-	VIDEO_BPP32,
-};
-
-/*
- * Convert enum video_log2_bpp to bytes and bits. Note we omit the outer
- * brackets to allow multiplication by fractional pixels.
- */
-#define VNBYTES(bpix)	((1 << (bpix)) / 8)
-
-#define VNBITS(bpix)	(1 << (bpix))
-
-enum video_format {
-	VIDEO_UNKNOWN,
-	VIDEO_RGBA8888,
-	VIDEO_X8B8G8R8,
-	VIDEO_X8R8G8B8,
-	VIDEO_X2R10G10B10,
-};
-
 /**
  * struct video_priv - Device information used by the video uclass
  *
diff --git a/include/video_format.h b/include/video_format.h
new file mode 100644
index 000000000000..34a0609765c9
--- /dev/null
+++ b/include/video_format.h
@@ -0,0 +1,161 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (c) 2024 Jiaxun Yang <jiaxun.yang@flygoat.com>
+ */
+
+#ifndef _VIDEO_FORMAT_H_
+#define _VIDEO_FORMAT_H_
+
+#include <compiler.h>
+
+/*
+ * Bits per pixel selector. Each value n is such that the bits-per-pixel is
+ * 2 ^ n
+ */
+enum video_log2_bpp {
+	VIDEO_BPP8 = 3,
+	VIDEO_BPP16,
+	VIDEO_BPP32,
+};
+
+/*
+ * Convert enum video_log2_bpp to bytes and bits. Note we omit the outer
+ * brackets to allow multiplication by fractional pixels.
+ */
+#define VNBYTES(bpix)	((1 << (bpix)) / 8)
+
+#define VNBITS(bpix)	(1 << (bpix))
+
+/* Struct video_rgb - Describes a video colour, always 8 bpc */
+struct video_rgb {
+	uint8_t r;
+	uint8_t g;
+	uint8_t b;
+};
+
+/* Naming respects linux/include/uapi/drm/drm_fourcc.h */
+enum video_format {
+	VIDEO_DEFAULT = 0,
+	VIDEO_RGB332,		/* [7:0] R:G:B 3:3:2 */
+	VIDEO_RGB565,		/* [15:0] R:G:B 5:6:5 little endian */
+	VIDEO_RGB565_BE,	/* [15:0] R:G:B 5:6:5 big endian */
+	VIDEO_XRGB8888,		/* [31:0] x:R:G:B 8:8:8:8 little endian */
+	VIDEO_BGRX8888,		/* [31:0] B:G:R:x 8:8:8:8 little endian */
+	VIDEO_XRGB8888_BE = VIDEO_BGRX8888,
+	VIDEO_XBGR8888,		/* [31:0] x:B:G:R 8:8:8:8 little endian */
+	VIDEO_RGBA8888,		/* [31:0] R:G:B:A 8:8:8:8 little endian */
+	VIDEO_XRGB2101010,	/* [31:0] x:R:G:B 2:10:10:10 little endian */
+	VIDEO_XRGB2101010_BE,	/* [31:0] x:R:G:B 2:10:10:10 big endian */
+	VIDEO_FMT_END
+};
+
+/**
+ * video_rgb_to_pixel8() - convert a RGB color to a 8 bit pixel's
+ * memory representation.
+ *
+ * @video_format Format of pixel
+ * @rgb          RGB color
+ * Return:	 color value
+ */
+static inline uint8_t video_rgb_to_pixel8(enum video_format format,
+					  struct video_rgb rgb)
+{
+	switch (format) {
+	case VIDEO_DEFAULT:
+	case VIDEO_RGB332:
+		return ((rgb.r >> 5) << 5) |
+		       ((rgb.g >> 5) << 2) |
+		       (rgb.b >> 6);
+	default:
+		break;
+	}
+	return 0;
+}
+
+/**
+ * video_rgb_to_pixel16() - convert a RGB color to a 16 bit pixel's
+ * memory representation.
+ *
+ * @video_format Format of pixel
+ * @rgb          RGB color
+ * Return:	 color value
+ */
+static inline uint16_t video_rgb_to_pixel16(enum video_format format,
+					    struct video_rgb rgb)
+{
+	unsigned int val = 0;
+
+	/* Handle layout first */
+	switch (format) {
+	case VIDEO_DEFAULT:
+	case VIDEO_RGB565:
+	case VIDEO_RGB565_BE:
+		val = ((rgb.r >> 3) << 11) |
+		      ((rgb.g >> 2) <<  5) |
+		      ((rgb.b >> 3) <<  0);
+		break;
+	default:
+		break;
+	}
+
+	/* Then handle endian */
+	switch (format) {
+	case VIDEO_RGB565_BE:
+		return cpu_to_be16(val);
+	default:
+		return cpu_to_le16(val);
+	}
+
+}
+
+/**
+ * video_rgb_to_pixel32() - convert a RGB color to a 32 bit pixel's
+ * memory representation.
+ *
+ * @video_format Format of pixel
+ * @rgb          RGB color
+ * Return:	 color value
+ */
+static inline uint32_t video_rgb_to_pixel32(enum video_format format,
+					    struct video_rgb rgb)
+{
+	unsigned int val = 0;
+
+	/* Handle layout first */
+	switch (format) {
+#ifdef __LITTLE_ENDIAN
+	case VIDEO_DEFAULT:
+#endif
+	case VIDEO_XRGB8888:
+		val = (rgb.r << 16) | (rgb.g << 8) | rgb.b;
+		break;
+#ifdef __BIG_ENDIAN
+	case VIDEO_DEFAULT:
+#endif
+	case VIDEO_BGRX8888:
+		val = (rgb.b << 24) | (rgb.g << 8) | (rgb.r << 8);
+		break;
+	case VIDEO_XBGR8888:
+		val = (rgb.b << 16) | (rgb.g << 8) | rgb.b;
+		break;
+	case VIDEO_RGBA8888:
+		val = (rgb.r << 24) | (rgb.g << 16) | (rgb.b << 8) | 0xff;
+		break;
+	case VIDEO_XRGB2101010:
+	case VIDEO_XRGB2101010_BE:
+		val = (rgb.r << 22) | (rgb.g << 12) | (rgb.b << 2);
+	default:
+		break;
+	}
+
+	/* Then handle endian */
+	switch (format) {
+	case VIDEO_XRGB2101010_BE:
+		return cpu_to_be32(val);
+	default:
+		return cpu_to_le32(val);
+	}
+
+	return 0;
+}
+#endif
diff --git a/lib/efi_loader/efi_gop.c b/lib/efi_loader/efi_gop.c
index 41e12fa72460..fec48804a472 100644
--- a/lib/efi_loader/efi_gop.c
+++ b/lib/efi_loader/efi_gop.c
@@ -531,7 +531,7 @@ efi_status_t efi_gop_register(void)
 	gopobj->info.height = row;
 	if (bpix == VIDEO_BPP32)
 	{
-		if (format == VIDEO_X2R10G10B10) {
+		if (format == VIDEO_XRGB2101010) {
 			gopobj->info.pixel_format = EFI_GOT_BITMASK;
 			gopobj->info.pixel_bitmask[0] = 0x3ff00000; /* red */
 			gopobj->info.pixel_bitmask[1] = 0x000ffc00; /* green */

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 4/6] video: bmp: Rework with video_rgb_to_pixel_*
  2024-05-16 22:16 [PATCH 0/6] video: pixel format handling fixes and improvements Jiaxun Yang
                   ` (2 preceding siblings ...)
  2024-05-16 22:16 ` [PATCH 3/6] video: Rework pixel format handling Jiaxun Yang
@ 2024-05-16 22:16 ` Jiaxun Yang
  2024-05-16 22:16 ` [PATCH 5/6] video: sandbox_sdl: Implement more pixel formats Jiaxun Yang
  2024-05-16 22:16 ` [PATCH 6/6] video: bochs: Setup framebuffer endian Jiaxun Yang
  5 siblings, 0 replies; 9+ messages in thread
From: Jiaxun Yang @ 2024-05-16 22:16 UTC (permalink / raw
  To: u-boot
  Cc: Tom Rini, Heiko Schocher, Marcel Ziswiler, Anatolij Gustschin,
	Heinrich Schuchardt, Ilias Apalodimas, Simon Glass, Jiaxun Yang

Using RGB to pixel conversion function provided in previous
patch to implement frame buffer writing functions.

Massively simplifed the code, also get rid of limitations
on bmp_bpix vs display_bpix.

Test cases are also corrected to refect a tiny change in
color quantization.

Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
---
 drivers/video/video_bmp.c | 201 +++++++++++++---------------------------------
 test/dm/video.c           |   4 +-
 2 files changed, 59 insertions(+), 146 deletions(-)

diff --git a/drivers/video/video_bmp.c b/drivers/video/video_bmp.c
index 83380a87fd2b..80c276aaf231 100644
--- a/drivers/video/video_bmp.c
+++ b/drivers/video/video_bmp.c
@@ -17,42 +17,6 @@
 #define BMP_RLE8_EOBMP		1
 #define BMP_RLE8_DELTA		2
 
-/**
- * get_bmp_col_16bpp() - Convert a colour-table entry into a 16bpp pixel value
- *
- * Return: value to write to the 16bpp frame buffer for this palette entry
- */
-static uint get_bmp_col_16bpp(struct bmp_color_table_entry cte)
-{
-	return ((cte.red   << 8) & 0xf800) |
-		((cte.green << 3) & 0x07e0) |
-		((cte.blue  >> 3) & 0x001f);
-}
-
-/**
- * get_bmp_col_x2r10g10b10() - Convert a colour-table entry into a x2r10g10b10  pixel value
- *
- * Return: value to write to the x2r10g10b10 frame buffer for this palette entry
- */
-static u32 get_bmp_col_x2r10g10b10(struct bmp_color_table_entry *cte)
-{
-	return ((cte->red << 22U) |
-		(cte->green << 12U) |
-		(cte->blue << 2U));
-}
-
-/**
- * get_bmp_col_rgba8888() - Convert a colour-table entry into a rgba8888 pixel value
- *
- * Return: value to write to the rgba8888 frame buffer for this palette entry
- */
-static u32 get_bmp_col_rgba8888(struct bmp_color_table_entry *cte)
-{
-	return ((cte->red) |
-		(cte->green << 8U) |
-		(cte->blue << 16U) | 0xff << 24U);
-}
-
 /**
  * write_pix8() - Write a pixel from a BMP image into the framebuffer
  *
@@ -63,33 +27,37 @@ static u32 get_bmp_col_rgba8888(struct bmp_color_table_entry *cte)
  * @palette: BMP palette table
  * @bmap: Pointer to BMP bitmap position to write. This contains a single byte
  *	which is either written directly (bpix == 8) or used to look up the
- *	palette to get a colour to write
+ *	palette to get a colour to write, NULL if it's a pseudo palette with one entry.
  */
 static void write_pix8(u8 *fb, uint bpix, enum video_format eformat,
 		       struct bmp_color_table_entry *palette, u8 *bmap)
 {
-	if (bpix == 8) {
-		*fb++ = *bmap;
-	} else if (bpix == 16) {
-		*(u16 *)fb = get_bmp_col_16bpp(palette[*bmap]);
-	} else {
-		/* Only support big endian */
-		struct bmp_color_table_entry *cte = &palette[*bmap];
-
-		if (bpix == 24) {
-			*fb++ = cte->red;
-			*fb++ = cte->green;
-			*fb++ = cte->blue;
-		} else if (eformat == VIDEO_XRGB2101010) {
-			*(u32 *)fb = get_bmp_col_x2r10g10b10(cte);
-		} else if (eformat == VIDEO_RGBA8888) {
-			*(u32 *)fb = get_bmp_col_rgba8888(cte);
-		} else {
-			*fb++ = cte->blue;
-			*fb++ = cte->green;
-			*fb++ = cte->red;
-			*fb++ = 0;
-		}
+	const int entry = bmap ? *bmap : 0;
+	const struct video_rgb rgb = {
+		.r = palette[entry].red,
+		.g = palette[entry].green,
+		.b = palette[entry].blue
+	};
+
+	switch (bpix) {
+#if CONFIG_IS_ENABLED(VIDEO_BPP8)
+	case 8:
+		*(u8 *)fb = video_rgb_to_pixel8(eformat, rgb);
+		break;
+#endif
+#if CONFIG_IS_ENABLED(VIDEO_BPP16)
+	case 16:
+		*(u16 *)fb = video_rgb_to_pixel16(eformat, rgb);
+		break;
+#endif
+#if CONFIG_IS_ENABLED(VIDEO_BPP32)
+	case 32:
+		*(u32 *)fb = video_rgb_to_pixel32(eformat, rgb);
+		break;
+#endif
+	default:
+		log_debug("Unsupported BPP %d for BMP\n", bpix);
+		break;
 	}
 }
 
@@ -266,6 +234,7 @@ int video_bmp_display(struct udevice *dev, ulong bmp_image, int x, int y,
 	unsigned colours, bpix, bmp_bpix;
 	enum video_format eformat;
 	struct bmp_color_table_entry *palette;
+	struct bmp_color_table_entry pseudo_cte __maybe_unused;
 	int hdr_size;
 	int ret;
 
@@ -293,21 +262,6 @@ int video_bmp_display(struct udevice *dev, ulong bmp_image, int x, int y,
 		return -EINVAL;
 	}
 
-	/*
-	 * We support displaying 8bpp and 24bpp BMPs on 16bpp LCDs
-	 * and displaying 24bpp BMPs on 32bpp LCDs
-	 */
-	if (bpix != bmp_bpix &&
-	    !(bmp_bpix == 8 && bpix == 16) &&
-	    !(bmp_bpix == 8 && bpix == 24) &&
-	    !(bmp_bpix == 8 && bpix == 32) &&
-	    !(bmp_bpix == 24 && bpix == 16) &&
-	    !(bmp_bpix == 24 && bpix == 32)) {
-		printf("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
-		       bpix, colours);
-		return -EPERM;
-	}
-
 	debug("Display-bmp: %d x %d  with %d colours, display %d\n",
 	      (int)width, (int)height, (int)colours, 1 << bpix);
 
@@ -354,10 +308,10 @@ int video_bmp_display(struct udevice *dev, ulong bmp_image, int x, int y,
 			for (j = 0; j < width; j++) {
 				write_pix8(fb, bpix, eformat, palette, bmap);
 				bmap++;
-				fb += bpix / 8;
+				fb += bpix / BITS_PER_BYTE;
 			}
 			bmap += (padded_width - width);
-			fb -= byte_width + priv->line_length;
+			fb -= priv->line_length + width * (bpix / BITS_PER_BYTE);
 		}
 		break;
 	case 16:
@@ -365,93 +319,52 @@ int video_bmp_display(struct udevice *dev, ulong bmp_image, int x, int y,
 			for (i = 0; i < height; ++i) {
 				schedule();
 				for (j = 0; j < width; j++) {
-					*fb++ = *bmap++;
-					*fb++ = *bmap++;
+					u16 bmp_rgb = le16_to_cpu(*(u16 *)bmap);
+					/* RGB565 */
+					pseudo_cte.red = ((bmp_rgb & 0xf800) >> 11) << 3;
+					pseudo_cte.green = ((bmp_rgb & 0x7e0) >> 5) << 2;
+					pseudo_cte.blue = (bmp_rgb & 0x1F) << 3;
+					write_pix8(fb, bpix, eformat, &pseudo_cte, NULL);
+					fb += (bpix / BITS_PER_BYTE);
+					bmap += (bmp_bpix / BITS_PER_BYTE);
 				}
 				bmap += (padded_width - width);
-				fb -= width * 2 + priv->line_length;
+				fb -= priv->line_length + width * (bpix / BITS_PER_BYTE);
 			}
 		}
 		break;
 	case 24:
 		if (CONFIG_IS_ENABLED(BMP_24BPP)) {
 			for (i = 0; i < height; ++i) {
+				schedule();
 				for (j = 0; j < width; j++) {
-					if (bpix == 16) {
-						/* 16bit 565RGB format */
-						*(u16 *)fb = ((bmap[2] >> 3)
-							<< 11) |
-							((bmap[1] >> 2) << 5) |
-							(bmap[0] >> 3);
-						bmap += 3;
-						fb += 2;
-					} else if (eformat == VIDEO_XRGB2101010) {
-						u32 pix;
-
-						pix = *bmap++ << 2U;
-						pix |= *bmap++ << 12U;
-						pix |= *bmap++ << 22U;
-						*fb++ = pix & 0xff;
-						*fb++ = (pix >> 8) & 0xff;
-						*fb++ = (pix >> 16) & 0xff;
-						*fb++ = pix >> 24;
-					} else if (eformat == VIDEO_RGBA8888) {
-						u32 pix;
-
-						pix = *bmap++ << 8U; /* blue */
-						pix |= *bmap++ << 16U; /* green */
-						pix |= *bmap++ << 24U; /* red */
-
-						*fb++ = (pix >> 24) & 0xff;
-						*fb++ = (pix >> 16) & 0xff;
-						*fb++ = (pix >> 8) & 0xff;
-						*fb++ = 0xff;
-					} else {
-						*fb++ = *bmap++;
-						*fb++ = *bmap++;
-						*fb++ = *bmap++;
-						*fb++ = 0;
-					}
+					pseudo_cte.blue = *bmap++;
+					pseudo_cte.green = *bmap++;
+					pseudo_cte.red = *bmap++;
+					write_pix8(fb, bpix, eformat, &pseudo_cte, NULL);
+					fb += (bpix / BITS_PER_BYTE);
 				}
-				fb -= priv->line_length + width * (bpix / 8);
 				bmap += (padded_width - width);
+				fb -= priv->line_length + width * (bpix / BITS_PER_BYTE);
 			}
 		}
 		break;
 	case 32:
 		if (CONFIG_IS_ENABLED(BMP_32BPP)) {
 			for (i = 0; i < height; ++i) {
+				schedule();
 				for (j = 0; j < width; j++) {
-					if (eformat == VIDEO_XRGB2101010) {
-						u32 pix;
-
-						pix = *bmap++ << 2U;
-						pix |= *bmap++ << 12U;
-						pix |= *bmap++ << 22U;
-						pix |= (*bmap++ >> 6) << 30U;
-						*fb++ = pix & 0xff;
-						*fb++ = (pix >> 8) & 0xff;
-						*fb++ = (pix >> 16) & 0xff;
-						*fb++ = pix >> 24;
-					} else if (eformat == VIDEO_RGBA8888) {
-						u32 pix;
-
-						pix = *bmap++ << 8U; /* blue */
-						pix |= *bmap++ << 16U; /* green */
-						pix |= *bmap++ << 24U; /* red */
-						bmap++;
-						*fb++ = (pix >> 24) & 0xff;
-						*fb++ = (pix >> 16) & 0xff;
-						*fb++ = (pix >> 8) & 0xff;
-						*fb++ = 0xff; /* opacity */
-					} else {
-						*fb++ = *bmap++;
-						*fb++ = *bmap++;
-						*fb++ = *bmap++;
-						*fb++ = *bmap++;
-					}
+					u32 bmp_rgb = le32_to_cpu(*(u32 *)bmap);
+					/* RGBX8888 */
+					pseudo_cte.red = (bmp_rgb >> 24) & 0xff;
+					pseudo_cte.green = (bmp_rgb >> 16) & 0xff;
+					pseudo_cte.blue =  (bmp_rgb >> 8) & 0xff;
+					write_pix8(fb, bpix, eformat, &pseudo_cte, NULL);
+					fb += (bpix / BITS_PER_BYTE);
+					bmap += (bmp_bpix / BITS_PER_BYTE);
 				}
-				fb -= priv->line_length + width * (bpix / 8);
+				bmap += (padded_width - width);
+				fb -= priv->line_length + width * (bpix / BITS_PER_BYTE);
 			}
 		}
 		break;
diff --git a/test/dm/video.c b/test/dm/video.c
index 7dfbeb9555d1..0da96aec5efd 100644
--- a/test/dm/video.c
+++ b/test/dm/video.c
@@ -400,7 +400,7 @@ static int dm_test_video_bmp8(struct unit_test_state *uts)
 	ut_assertok(read_file(uts, "tools/logos/denx.bmp", &addr));
 
 	ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
-	ut_asserteq(1247, compress_frame_buffer(uts, dev));
+	ut_asserteq(1118, compress_frame_buffer(uts, dev));
 
 	return 0;
 }
@@ -541,7 +541,7 @@ static int dm_test_video_comp_bmp8(struct unit_test_state *uts)
 	ut_assertok(read_file(uts, "tools/logos/denx.bmp", &addr));
 
 	ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
-	ut_asserteq(1247, compress_frame_buffer(uts, dev));
+	ut_asserteq(1118, compress_frame_buffer(uts, dev));
 
 	return 0;
 }

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 5/6] video: sandbox_sdl: Implement more pixel formats
  2024-05-16 22:16 [PATCH 0/6] video: pixel format handling fixes and improvements Jiaxun Yang
                   ` (3 preceding siblings ...)
  2024-05-16 22:16 ` [PATCH 4/6] video: bmp: Rework with video_rgb_to_pixel_* Jiaxun Yang
@ 2024-05-16 22:16 ` Jiaxun Yang
  2024-05-16 22:16 ` [PATCH 6/6] video: bochs: Setup framebuffer endian Jiaxun Yang
  5 siblings, 0 replies; 9+ messages in thread
From: Jiaxun Yang @ 2024-05-16 22:16 UTC (permalink / raw
  To: u-boot
  Cc: Tom Rini, Heiko Schocher, Marcel Ziswiler, Anatolij Gustschin,
	Heinrich Schuchardt, Ilias Apalodimas, Simon Glass, Jiaxun Yang

Support most of possible pixel formats so we can test them
in sandbox.

Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
---
 arch/sandbox/cpu/sdl.c         | 58 +++++++++++++++++++++++++++++++++++++-----
 arch/sandbox/include/asm/sdl.h | 17 ++++++++-----
 drivers/video/sandbox_sdl.c    | 16 +++++++-----
 include/dm/test.h              |  2 ++
 test/dm/video.c                | 14 +++++-----
 5 files changed, 81 insertions(+), 26 deletions(-)

diff --git a/arch/sandbox/cpu/sdl.c b/arch/sandbox/cpu/sdl.c
index ed84646bdab7..436c0448de1f 100644
--- a/arch/sandbox/cpu/sdl.c
+++ b/arch/sandbox/cpu/sdl.c
@@ -5,8 +5,10 @@
 
 #include <errno.h>
 #include <unistd.h>
+#include <stdint.h>
 #include <stdbool.h>
 #include <sysreset.h>
+#include <video_format.h>
 #include <linux/input.h>
 #include <SDL2/SDL.h>
 #include <asm/state.h>
@@ -69,6 +71,47 @@ static struct sdl_info {
 	int src_depth;
 } sdl;
 
+static inline SDL_PixelFormatEnum sandbox_video_format(int l2bbp, int format)
+{
+	switch (l2bbp) {
+	case VIDEO_BPP8:
+		switch (format) {
+		case VIDEO_DEFAULT:
+		case VIDEO_RGB332:
+			return SDL_PIXELFORMAT_RGB332;
+		}
+	case VIDEO_BPP16:
+		switch (format) {
+		case VIDEO_DEFAULT:
+		case VIDEO_RGB565:
+			return SDL_PIXELFORMAT_RGB565;
+		default:
+			break;
+		}
+		break;
+	case VIDEO_BPP32:
+		switch (format) {
+		case VIDEO_DEFAULT:
+		case VIDEO_XRGB8888:
+			return SDL_PIXELFORMAT_RGB888;
+		case VIDEO_BGRX8888:
+			return SDL_PIXELFORMAT_BGRX8888;
+		case VIDEO_XBGR8888:
+			return SDL_PIXELFORMAT_BGR888;
+		case VIDEO_RGBA8888:
+			return SDL_PIXELFORMAT_RGBA8888;
+		case VIDEO_XRGB2101010:
+			return SDL_PIXELFORMAT_ARGB2101010;
+		default:
+			break;
+		}
+	default:
+		break;
+	}
+
+	return SDL_PIXELFORMAT_UNKNOWN;
+}
+
 static void sandbox_sdl_poll_events(void)
 {
 	/*
@@ -122,9 +165,10 @@ int sandbox_sdl_remove_display(void)
 }
 
 int sandbox_sdl_init_display(int width, int height, int log2_bpp,
-			     bool double_size)
+			     int format, bool double_size)
 {
 	struct sandbox_state *state = state_get_current();
+	SDL_PixelFormatEnum sdl_format;
 	int err;
 
 	if (!width || !state->show_lcd)
@@ -135,6 +179,12 @@ int sandbox_sdl_init_display(int width, int height, int log2_bpp,
 	if (sdl.renderer)
 		sandbox_sdl_remove_display();
 
+	sdl_format = sandbox_video_format(log2_bpp, format);
+	if (sdl_format == SDL_PIXELFORMAT_UNKNOWN) {
+		printf("Unsupported video format\n");
+		return -EINVAL;
+	}
+
 	if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) {
 		printf("Unable to initialise SDL LCD: %s\n", SDL_GetError());
 		return -EPERM;
@@ -153,8 +203,6 @@ int sandbox_sdl_init_display(int width, int height, int log2_bpp,
 		printf("Unable to init hinting: %s", SDL_GetError());
 
 	sdl.src_depth = 1 << log2_bpp;
-	if (log2_bpp != 4 && log2_bpp != 5)
-		log2_bpp = 5;
 	sdl.depth = 1 << log2_bpp;
 	sdl.pitch = sdl.width * sdl.depth / 8;
 	sdl.screen = SDL_CreateWindow("U-Boot", SDL_WINDOWPOS_UNDEFINED,
@@ -174,9 +222,7 @@ int sandbox_sdl_init_display(int width, int height, int log2_bpp,
 		return -EIO;
 	}
 
-	sdl.texture = SDL_CreateTexture(sdl.renderer, log2_bpp == 4 ?
-					SDL_PIXELFORMAT_RGB565 :
-					SDL_PIXELFORMAT_RGB888,
+	sdl.texture = SDL_CreateTexture(sdl.renderer, sdl_format,
 					SDL_TEXTUREACCESS_STREAMING,
 					width, height);
 	if (!sdl.texture) {
diff --git a/arch/sandbox/include/asm/sdl.h b/arch/sandbox/include/asm/sdl.h
index ee4991f7c24a..7b4f26f994da 100644
--- a/arch/sandbox/include/asm/sdl.h
+++ b/arch/sandbox/include/asm/sdl.h
@@ -24,7 +24,7 @@
  *		and -EPERM if the video failed to come up.
  */
 int sandbox_sdl_init_display(int width, int height, int log2_bpp,
-			     bool double_size);
+			     int format, bool double_size);
 
 /**
  * sandbox_sdl_remove_display() - Remove the SDL screen
@@ -89,12 +89,13 @@ int sandbox_sdl_sound_stop(void);
 int sandbox_sdl_sound_init(int rate, int channels);
 
 /**
- * sandbox_sdl_set_bpp() - Set the depth of the sandbox display
+ * sandbox_sdl_set_pixel() - Set depth and format of the sandbox display
  *
  * The device must not be active when this function is called. It activiates it
  * before returning.
  *
- * This updates the depth value and adjusts a few other settings accordingly.
+ * This updates the depth value and pixel format for the sandbox display, then
+ * it adjusts a few other settings accordingly.
  * It must be called before the display is probed.
  *
  * @dev: Device to adjust
@@ -102,11 +103,12 @@ int sandbox_sdl_sound_init(int rate, int channels);
  * Return: 0 if the device was already active, other error if it fails to probe
  * after the change
  */
-int sandbox_sdl_set_bpp(struct udevice *dev, enum video_log2_bpp l2bpp);
+int sandbox_sdl_set_pixel(struct udevice *dev, enum video_log2_bpp l2bpp,
+			  enum video_format format);
 
 #else
 static inline int sandbox_sdl_init_display(int width, int height, int log2_bpp,
-					   bool double_size)
+					   int format, bool double_size)
 {
 	return -ENODEV;
 }
@@ -151,8 +153,9 @@ static inline int sandbox_sdl_sound_init(int rate, int channels)
 	return -ENODEV;
 }
 
-static inline int sandbox_sdl_set_bpp(struct udevice *dev,
-				      enum video_log2_bpp l2bpp)
+static inline int sandbox_sdl_set_pixel(struct udevice *dev,
+					enum video_log2_bpp l2bpp,
+					enum video_format format)
 {
 	return -ENOSYS;
 }
diff --git a/drivers/video/sandbox_sdl.c b/drivers/video/sandbox_sdl.c
index 69dfa9302735..ddd72a14de83 100644
--- a/drivers/video/sandbox_sdl.c
+++ b/drivers/video/sandbox_sdl.c
@@ -31,7 +31,7 @@ static int sandbox_sdl_probe(struct udevice *dev)
 	int ret;
 
 	ret = sandbox_sdl_init_display(plat->xres, plat->yres, plat->bpix,
-				       state->double_lcd);
+				       plat->format, state->double_lcd);
 	if (ret) {
 		puts("LCD init failed\n");
 		return ret;
@@ -39,6 +39,7 @@ static int sandbox_sdl_probe(struct udevice *dev)
 	uc_priv->xsize = plat->xres;
 	uc_priv->ysize = plat->yres;
 	uc_priv->bpix = plat->bpix;
+	uc_priv->format = plat->format;
 	uc_priv->rot = plat->rot;
 	uc_priv->vidconsole_drv_name = plat->vidconsole_drv_name;
 	uc_priv->font_size = plat->font_size;
@@ -48,12 +49,14 @@ static int sandbox_sdl_probe(struct udevice *dev)
 	return 0;
 }
 
-static void set_bpp(struct udevice *dev, enum video_log2_bpp l2bpp)
+static void set_pixel(struct udevice *dev, enum video_log2_bpp l2bpp,
+		      enum video_format format)
 {
 	struct video_uc_plat *uc_plat = dev_get_uclass_plat(dev);
 	struct sandbox_sdl_plat *plat = dev_get_plat(dev);
 
 	plat->bpix = l2bpp;
+	plat->format = format;
 
 	uc_plat->size = plat->xres * plat->yres * VNBYTES(plat->bpix);
 
@@ -61,7 +64,7 @@ static void set_bpp(struct udevice *dev, enum video_log2_bpp l2bpp)
 	 * Set up to the maximum size we'll ever need. This is a strange case.
 	 * The video memory is allocated by video_post_bind() called from
 	 * board_init_r(). If a test changes the reoslution so it needs more
-	 * memory later (with sandbox_sdl_set_bpp()), it is too late to make
+	 * memory later (with sandbox_sdl_set_pixel()), it is too late to make
 	 * the frame buffer larger.
 	 *
 	 * So use a maximum size here.
@@ -79,7 +82,8 @@ static void set_bpp(struct udevice *dev, enum video_log2_bpp l2bpp)
 		uc_plat->size *= 2;
 }
 
-int sandbox_sdl_set_bpp(struct udevice *dev, enum video_log2_bpp l2bpp)
+int sandbox_sdl_set_pixel(struct udevice *dev, enum video_log2_bpp l2bpp,
+			  enum video_format format)
 {
 	struct video_uc_plat *uc_plat = dev_get_uclass_plat(dev);
 	int ret;
@@ -89,7 +93,7 @@ int sandbox_sdl_set_bpp(struct udevice *dev, enum video_log2_bpp l2bpp)
 	sandbox_sdl_remove_display();
 
 	uc_plat->hide_logo = true;
-	set_bpp(dev, l2bpp);
+	set_pixel(dev, l2bpp, format);
 
 	ret = device_probe(dev);
 	if (ret)
@@ -122,7 +126,7 @@ static int sandbox_sdl_bind(struct udevice *dev)
 	l2bpp = dev_read_u32_default(dev, "log2-depth", VIDEO_BPP16);
 	plat->rot = dev_read_u32_default(dev, "rotate", 0);
 
-	set_bpp(dev, l2bpp);
+	set_pixel(dev, l2bpp, VIDEO_DEFAULT);
 
 	return ret;
 }
diff --git a/include/dm/test.h b/include/dm/test.h
index 02737411a164..87568d741d49 100644
--- a/include/dm/test.h
+++ b/include/dm/test.h
@@ -153,6 +153,7 @@ extern struct unit_test_state global_dm_test_state;
  * @xres: Width of display in pixels
  * @yres: Height of display in pixels
  * @bpix: Log2 of bits per pixel (enum video_log2_bpp)
+ * @format: Pixel format (enum video_format)
  * @rot: Console rotation (0=normal orientation, 1=90 degrees clockwise,
  *	2=upside down, 3=90 degree counterclockwise)
  * @vidconsole_drv_name: Name of video console driver (set by tests)
@@ -162,6 +163,7 @@ struct sandbox_sdl_plat {
 	int xres;
 	int yres;
 	int bpix;
+	int format;
 	int rot;
 	const char *vidconsole_drv_name;
 	int font_size;
diff --git a/test/dm/video.c b/test/dm/video.c
index 0da96aec5efd..47a8df511e8b 100644
--- a/test/dm/video.c
+++ b/test/dm/video.c
@@ -395,7 +395,7 @@ static int dm_test_video_bmp8(struct unit_test_state *uts)
 
 	ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev));
 	ut_assertnonnull(dev);
-	ut_assertok(sandbox_sdl_set_bpp(dev, VIDEO_BPP8));
+	ut_assertok(sandbox_sdl_set_pixel(dev, VIDEO_BPP8, VIDEO_DEFAULT));
 
 	ut_assertok(read_file(uts, "tools/logos/denx.bmp", &addr));
 
@@ -416,7 +416,7 @@ static int dm_test_video_bmp16(struct unit_test_state *uts)
 
 	ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev));
 	ut_assertnonnull(dev);
-	ut_assertok(sandbox_sdl_set_bpp(dev, VIDEO_BPP16));
+	ut_assertok(sandbox_sdl_set_pixel(dev, VIDEO_BPP16, VIDEO_DEFAULT));
 
 	ut_assertok(read_file(uts, "tools/logos/denx-16bpp.bmp.gz", &src));
 	ut_assertok(gunzip(map_sysmem(dst, 0), dst_len, map_sysmem(src, 0),
@@ -439,7 +439,7 @@ static int dm_test_video_bmp24(struct unit_test_state *uts)
 
 	ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev));
 	ut_assertnonnull(dev);
-	ut_assertok(sandbox_sdl_set_bpp(dev, VIDEO_BPP16));
+	ut_assertok(sandbox_sdl_set_pixel(dev, VIDEO_BPP16, VIDEO_DEFAULT));
 
 	ut_assertok(read_file(uts, "tools/logos/denx-24bpp.bmp.gz", &src));
 	ut_assertok(gunzip(map_sysmem(dst, 0), dst_len, map_sysmem(src, 0),
@@ -462,7 +462,7 @@ static int dm_test_video_bmp24_32(struct unit_test_state *uts)
 
 	ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev));
 	ut_assertnonnull(dev);
-	ut_assertok(sandbox_sdl_set_bpp(dev, VIDEO_BPP32));
+	ut_assertok(sandbox_sdl_set_pixel(dev, VIDEO_BPP32, VIDEO_DEFAULT));
 
 	ut_assertok(read_file(uts, "tools/logos/denx-24bpp.bmp.gz", &src));
 	ut_assertok(gunzip(map_sysmem(dst, 0), dst_len, map_sysmem(src, 0),
@@ -483,7 +483,7 @@ static int dm_test_video_bmp32(struct unit_test_state *uts)
 
 	ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev));
 	ut_assertnonnull(dev);
-	ut_assertok(sandbox_sdl_set_bpp(dev, VIDEO_BPP32));
+	ut_assertok(sandbox_sdl_set_pixel(dev, VIDEO_BPP32, VIDEO_DEFAULT));
 	ut_assertok(read_file(uts, "tools/logos/denx.bmp", &addr));
 
 	ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
@@ -517,7 +517,7 @@ static int dm_test_video_comp_bmp32(struct unit_test_state *uts)
 
 	ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev));
 	ut_assertnonnull(dev);
-	ut_assertok(sandbox_sdl_set_bpp(dev, VIDEO_BPP32));
+	ut_assertok(sandbox_sdl_set_pixel(dev, VIDEO_BPP32, VIDEO_DEFAULT));
 
 	ut_assertok(read_file(uts, "tools/logos/denx.bmp", &addr));
 
@@ -536,7 +536,7 @@ static int dm_test_video_comp_bmp8(struct unit_test_state *uts)
 
 	ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev));
 	ut_assertnonnull(dev);
-	ut_assertok(sandbox_sdl_set_bpp(dev, VIDEO_BPP8));
+	ut_assertok(sandbox_sdl_set_pixel(dev, VIDEO_BPP8, VIDEO_DEFAULT));
 
 	ut_assertok(read_file(uts, "tools/logos/denx.bmp", &addr));
 

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 6/6] video: bochs: Setup framebuffer endian
  2024-05-16 22:16 [PATCH 0/6] video: pixel format handling fixes and improvements Jiaxun Yang
                   ` (4 preceding siblings ...)
  2024-05-16 22:16 ` [PATCH 5/6] video: sandbox_sdl: Implement more pixel formats Jiaxun Yang
@ 2024-05-16 22:16 ` Jiaxun Yang
  5 siblings, 0 replies; 9+ messages in thread
From: Jiaxun Yang @ 2024-05-16 22:16 UTC (permalink / raw
  To: u-boot
  Cc: Tom Rini, Heiko Schocher, Marcel Ziswiler, Anatolij Gustschin,
	Heinrich Schuchardt, Ilias Apalodimas, Simon Glass, Jiaxun Yang

So the current situation on endian of bochs framebufer
is a little bit complex. QEMU defaulted to little endian
for both endian hardware except on powerpc, but provided
an endian swich register allows OS to switch endian.

Since we can't guarantee the endian switch register is
functional, my approach is to default to little endian
framebuffer for ISAs except powerpc and perform endian
switch to match this assumption.

Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
---
 drivers/video/bochs.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/video/bochs.c b/drivers/video/bochs.c
index 00e673a4db08..c315c5477b14 100644
--- a/drivers/video/bochs.c
+++ b/drivers/video/bochs.c
@@ -65,6 +65,14 @@ static int bochs_init_fb(struct udevice *dev)
 	uc_priv->ysize = ysize;
 	uc_priv->bpix = VIDEO_BPP32;
 
+#if defined(__powerpc__) && defined(__BIG_ENDIAN)
+	uc_priv->format = VIDEO_XRGB8888_BE;
+	writel(0xbebebebe, mmio + 0x604);
+#else
+	uc_priv->format = VIDEO_XRGB8888;
+	writel(0x1e1e1e1e, mmio + 0x604);
+#endif
+
 	/* setup video mode */
 	bochs_write(mmio, INDEX_ENABLE,  0);
 	bochs_write(mmio, INDEX_BANK,  0);

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/6] video: Move generated bmp headers to include/generated
  2024-05-16 22:16 ` [PATCH 1/6] video: Move generated bmp headers to include/generated Jiaxun Yang
@ 2024-05-16 22:19   ` Tom Rini
  2024-05-17  6:14   ` Heiko Schocher
  1 sibling, 0 replies; 9+ messages in thread
From: Tom Rini @ 2024-05-16 22:19 UTC (permalink / raw
  To: Jiaxun Yang
  Cc: u-boot, Heiko Schocher, Marcel Ziswiler, Anatolij Gustschin,
	Heinrich Schuchardt, Ilias Apalodimas, Simon Glass

[-- Attachment #1: Type: text/plain, Size: 262 bytes --]

On Thu, May 16, 2024 at 11:16:41PM +0100, Jiaxun Yang wrote:

> Emphasis that those headers are generated.
> Also naturally gitignore them.
> 
> Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>

Reviewed-by: Tom Rini <trini@konsulko.com>

-- 
Tom

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/6] video: Move generated bmp headers to include/generated
  2024-05-16 22:16 ` [PATCH 1/6] video: Move generated bmp headers to include/generated Jiaxun Yang
  2024-05-16 22:19   ` Tom Rini
@ 2024-05-17  6:14   ` Heiko Schocher
  1 sibling, 0 replies; 9+ messages in thread
From: Heiko Schocher @ 2024-05-17  6:14 UTC (permalink / raw
  To: Jiaxun Yang, u-boot
  Cc: Tom Rini, Marcel Ziswiler, Anatolij Gustschin,
	Heinrich Schuchardt, Ilias Apalodimas, Simon Glass

Hello Yang,

On 17.05.24 00:16, Jiaxun Yang wrote:
> Emphasis that those headers are generated.
> Also naturally gitignore them.
> 
> Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
> ---
>   Makefile                          | 2 +-
>   board/aristainetos/aristainetos.c | 2 +-
>   board/toradex/common/tdx-common.c | 2 +-
>   common/splash.c                   | 4 ++--
>   tools/Makefile                    | 4 ++--
>   5 files changed, 7 insertions(+), 7 deletions(-)

Reviewed-by: Heiko Schocher <hs@denx.de>

for the aristainetos2 board part.

bye,
Heiko
-- 
DENX Software Engineering GmbH,      Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: hs@denx.de

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2024-05-17  6:15 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-16 22:16 [PATCH 0/6] video: pixel format handling fixes and improvements Jiaxun Yang
2024-05-16 22:16 ` [PATCH 1/6] video: Move generated bmp headers to include/generated Jiaxun Yang
2024-05-16 22:19   ` Tom Rini
2024-05-17  6:14   ` Heiko Schocher
2024-05-16 22:16 ` [PATCH 2/6] video: Add gitignore for u_boot_logo.S Jiaxun Yang
2024-05-16 22:16 ` [PATCH 3/6] video: Rework pixel format handling Jiaxun Yang
2024-05-16 22:16 ` [PATCH 4/6] video: bmp: Rework with video_rgb_to_pixel_* Jiaxun Yang
2024-05-16 22:16 ` [PATCH 5/6] video: sandbox_sdl: Implement more pixel formats Jiaxun Yang
2024-05-16 22:16 ` [PATCH 6/6] video: bochs: Setup framebuffer endian Jiaxun Yang

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.