Skip to contentSkip to conversation

Fix AST2500 graphics on ppc64 systems in big-endian mode

PATCH In review Timothy Pearson 2 participants 6 messages Oct 17, 2025 – Dec 3, 2025

Subsystems (5)
DRM drivers DRM misc PowerPC PCI +1 more subsystems
lore
Share & tools
lore
#0 lore raw

cover Fix AST2500 graphics on ppc64 systems in big-endian mode

On ppc64 systems that use the AST2500 graphics device, such as the Blackbird POWER9 system, the red and blue channels are inverted when the host is running in big endian mode. This is due to a ppc64 hardware quirk, which when combined with a hardware design fault in the AST2500 VGA controller results in a need to use software-based red-blue channel swapping.

Tested to fix color graphics on Debian sid/ppc64 on a Blackbird system.

Timothy Pearson (2):
PCI: Add CONFIG_PCI_ARCH_ENDIAN_AUTOSWAP drm/ast: Fix framebuffer color swapping on ppc64 systems

 arch/powerpc/Kconfig           |  1 +
 drivers/gpu/drm/ast/ast_mode.c | 33 +++++++++++++++++++++++++++++++--
 drivers/pci/Kconfig            |  4 ++++
 3 files changed, 36 insertions(+), 2 deletions(-)
Signature · 1 line
2.51.0
#1 lore raw

PATCH 1/2 PCI: Add CONFIG_PCI_ARCH_ENDIAN_AUTOSWAP

Certain hardware devices, such as the IBM POWER9 CPU, transparently swap PCI bus MMIO data endianness when running in big endian mode. This transparent data swapping presents issues for certain types of BARs, for example little endian framebuffers, where the device driver needs to be aware the PCI BAR is now appearing as big endian from the host's perspective.

Introduce CONFIG_PCI_ARCH_ENDIAN_AUTOSWAP and enable on ppc64 systems.

---
 arch/powerpc/Kconfig | 1 +
 drivers/pci/Kconfig  | 4 ++++
 2 files changed, 5 insertions(+)
arch/powerpc/Kconfig +1 -0
index e24f4d88885a..0e75fe570389 100644
@@ -314,6 +314,7 @@ config PPC
 	select OF_EARLY_FLATTREE
 	select OLD_SIGACTION			if PPC32
 	select OLD_SIGSUSPEND
+	select PCI_ARCH_ENDIAN_AUTOSWAP		if PCI && PPC64
 	select PCI_DOMAINS			if PCI
 	select PCI_MSI_ARCH_FALLBACKS		if PCI_MSI
 	select PCI_SYSCALL			if PCI
drivers/pci/Kconfig +4 -0
index 7065a8e5f9b1..fccc01110763 100644
@@ -40,6 +40,10 @@ config PCI_DOMAINS_GENERIC
 config PCI_SYSCALL
 	bool
 
+config PCI_ARCH_ENDIAN_AUTOSWAP
+	bool
+	depends on PCI
+
 source "drivers/pci/pcie/Kconfig"
 
 config PCI_MSI
Signature · 1 line
2.51.0
#2 lore raw

PATCH 2/2 drm/ast: Fix framebuffer color swapping on ppc64 systems

On certain big endian systems, such as the POWER9 operating in big endian mode, PCI MMIO BAR accesses are transparently endian-swapped by hardware. On the AST2xx0 series devices, this results in the little endian framebuffer appearing to the host as a big endian device, resulting in unwanted color swapping.

Furthermore, per ASpeed technical support, the big endian mode on these devices is not supported and, per Raptor's internal testing, does not function at a hardware level.

Detect transparent PCI swapping via CONFIG_PCI_ARCH_ENDIAN_AUTOSWAP, and expose the framebuffer as a big endian device with software swapping.

Tested on a POWER9 Blackbird system with Debian sid/ppc64.

---
 drivers/gpu/drm/ast/ast_mode.c | 33 +++++++++++++++++++++++++++++++--
 1 file changed, 31 insertions(+), 2 deletions(-)
drivers/gpu/drm/ast/ast_mode.c +31 -2
index 30b011ed0a05..07f04668ef92 100644
@@ -105,9 +105,11 @@ static void ast_crtc_fill_gamma(struct ast_device *ast,
 		drm_crtc_fill_palette_8(crtc, ast_set_gamma_lut);
 		break;
 	case DRM_FORMAT_RGB565:
+	case DRM_FORMAT_HOST_RGB565:
 		/* also uses 8-bit gamma ramp on low-color modes */
 		fallthrough;
 	case DRM_FORMAT_XRGB8888:
+	case DRM_FORMAT_HOST_XRGB8888:
 		drm_crtc_fill_gamma_888(crtc, ast_set_gamma_lut);
 		break;
 	default:
@@ -129,9 +131,11 @@ static void ast_crtc_load_gamma(struct ast_device *ast,
 		drm_crtc_load_palette_8(crtc, lut, ast_set_gamma_lut);
 		break;
 	case DRM_FORMAT_RGB565:
+	case DRM_FORMAT_HOST_RGB565:
 		/* also uses 8-bit gamma ramp on low-color modes */
 		fallthrough;
 	case DRM_FORMAT_XRGB8888:
+	case DRM_FORMAT_HOST_XRGB8888:
 		drm_crtc_load_gamma_888(crtc, lut, ast_set_gamma_lut);
 		break;
 	default:
@@ -502,8 +506,13 @@ void __iomem *ast_plane_vaddr(struct ast_plane *ast_plane)
  */
 
 static const uint32_t ast_primary_plane_formats[] = {
+#if defined(__BIG_ENDIAN) && defined(CONFIG_PCI_ARCH_ENDIAN_AUTOSWAP)
+	DRM_FORMAT_HOST_XRGB8888,
+	DRM_FORMAT_HOST_RGB565,
+#else
 	DRM_FORMAT_XRGB8888,
 	DRM_FORMAT_RGB565,
+#endif
 	DRM_FORMAT_C8,
 };
 
@@ -541,12 +550,24 @@ static int ast_primary_plane_helper_atomic_check(struct drm_plane *plane,
 
 static void ast_handle_damage(struct ast_plane *ast_plane, struct iosys_map *src,
 			      struct drm_framebuffer *fb,
-			      const struct drm_rect *clip)
+			      const struct drm_rect *clip,
+			      struct drm_format_conv_state *fmtcnv_state)
 {
 	struct iosys_map dst = IOSYS_MAP_INIT_VADDR_IOMEM(ast_plane_vaddr(ast_plane));
 
 	iosys_map_incr(&dst, drm_fb_clip_offset(fb->pitches[0], fb->format, clip));
+#if defined(__BIG_ENDIAN) && defined(CONFIG_PCI_ARCH_ENDIAN_AUTOSWAP)
+	switch (fb->format->format) {
+		case DRM_FORMAT_HOST_XRGB8888:
+		case DRM_FORMAT_HOST_RGB565:
+			drm_fb_swab(&dst, fb->pitches, src, fb, clip, false, fmtcnv_state);
+			break;
+		default:
+			drm_fb_memcpy(&dst, fb->pitches, src, fb, clip);
+	}
+#else
 	drm_fb_memcpy(&dst, fb->pitches, src, fb, clip);
+#endif
 }
 
 static void ast_primary_plane_helper_atomic_update(struct drm_plane *plane,
@@ -574,7 +595,7 @@ static void ast_primary_plane_helper_atomic_update(struct drm_plane *plane,
 
 	drm_atomic_helper_damage_iter_init(&iter, old_plane_state, plane_state);
 	drm_atomic_for_each_plane_damage(&iter, &damage) {
-		ast_handle_damage(ast_plane, shadow_plane_state->data, fb, &damage);
+		ast_handle_damage(ast_plane, shadow_plane_state->data, fb, &damage, &shadow_plane_state->fmtcnv_state);
 	}
 
 	/*
@@ -766,10 +787,13 @@ static int ast_crtc_helper_atomic_check(struct drm_crtc *crtc,
 		ast_state->std_table = &vbios_stdtable[VGAModeIndex];
 		break;
 	case DRM_FORMAT_RGB565:
+	case DRM_FORMAT_HOST_RGB565:
 		ast_state->std_table = &vbios_stdtable[HiCModeIndex];
 		break;
 	case DRM_FORMAT_RGB888:
+	case DRM_FORMAT_BGR888:
 	case DRM_FORMAT_XRGB8888:
+	case DRM_FORMAT_HOST_XRGB8888:
 		ast_state->std_table = &vbios_stdtable[TrueCModeIndex];
 		break;
 	default:
@@ -978,7 +1002,11 @@ static const struct drm_mode_config_helper_funcs ast_mode_config_helper_funcs =
 static enum drm_mode_status ast_mode_config_mode_valid(struct drm_device *dev,
 						       const struct drm_display_mode *mode)
 {
+#if defined(__BIG_ENDIAN) && defined(CONFIG_PCI_ARCH_ENDIAN_AUTOSWAP)
+	const struct drm_format_info *info = drm_format_info(DRM_FORMAT_HOST_XRGB8888);
+#else
 	const struct drm_format_info *info = drm_format_info(DRM_FORMAT_XRGB8888);
+#endif
 	struct ast_device *ast = to_ast_device(dev);
 	unsigned long max_fb_size = ast_fb_vram_size(ast);
 	u64 pitch;
@@ -1021,6 +1049,7 @@ int ast_mode_config_init(struct ast_device *ast)
 	dev->mode_config.min_width = 0;
 	dev->mode_config.min_height = 0;
 	dev->mode_config.preferred_depth = 24;
+	dev->mode_config.quirk_addfb_prefer_host_byte_order = true;
 
 	if (ast->support_fullhd) {
 		dev->mode_config.max_width = 1920;
Signature · 1 line
2.51.0
#3 lore raw

Re: [PATCH 2/2] drm/ast: Fix framebuffer color swapping on ppc64 systems

Hi

Am 17.10.25 um 20:18 schrieb Timothy Pearson:

Quoted 68 lines

On certain big endian systems, such as the POWER9 operating in big endian mode, PCI MMIO BAR accesses are transparently endian-swapped by hardware. On the AST2xx0 series devices, this results in the little endian framebuffer appearing to the host as a big endian device, resulting in unwanted color swapping.

Furthermore, per ASpeed technical support, the big endian mode on these devices is not supported and, per Raptor's internal testing, does not function at a hardware level.

Detect transparent PCI swapping via CONFIG_PCI_ARCH_ENDIAN_AUTOSWAP, and expose the framebuffer as a big endian device with software swapping.

Tested on a POWER9 Blackbird system with Debian sid/ppc64.

---
  drivers/gpu/drm/ast/ast_mode.c | 33 +++++++++++++++++++++++++++++++--
  1 file changed, 31 insertions(+), 2 deletions(-)
drivers/gpu/drm/ast/ast_mode.c +10 -1
index 30b011ed0a05..07f04668ef92 100644
@@ -105,9 +105,11 @@ static void ast_crtc_fill_gamma(struct ast_device *ast,
  		drm_crtc_fill_palette_8(crtc, ast_set_gamma_lut);
  		break;
  	case DRM_FORMAT_RGB565:
+	case DRM_FORMAT_HOST_RGB565:
  		/* also uses 8-bit gamma ramp on low-color modes */
  		fallthrough;
  	case DRM_FORMAT_XRGB8888:
+	case DRM_FORMAT_HOST_XRGB8888:
  		drm_crtc_fill_gamma_888(crtc, ast_set_gamma_lut);
  		break;
  	default:
@@ -129,9 +131,11 @@ static void ast_crtc_load_gamma(struct ast_device *ast,
  		drm_crtc_load_palette_8(crtc, lut, ast_set_gamma_lut);
  		break;
  	case DRM_FORMAT_RGB565:
+	case DRM_FORMAT_HOST_RGB565:
  		/* also uses 8-bit gamma ramp on low-color modes */
  		fallthrough;
  	case DRM_FORMAT_XRGB8888:
+	case DRM_FORMAT_HOST_XRGB8888:
  		drm_crtc_load_gamma_888(crtc, lut, ast_set_gamma_lut);
  		break;
  	default:
@@ -502,8 +506,13 @@ void __iomem *ast_plane_vaddr(struct ast_plane *ast_plane)
   */
 
  static const uint32_t ast_primary_plane_formats[] = {
+#if defined(__BIG_ENDIAN) && defined(CONFIG_PCI_ARCH_ENDIAN_AUTOSWAP)
+	DRM_FORMAT_HOST_XRGB8888,
+	DRM_FORMAT_HOST_RGB565,
+#else
  	DRM_FORMAT_XRGB8888,
  	DRM_FORMAT_RGB565,
+#endif
  	DRM_FORMAT_C8,
  };
 
@@ -541,12 +550,24 @@ static int ast_primary_plane_helper_atomic_check(struct drm_plane *plane,
 
  static void ast_handle_damage(struct ast_plane *ast_plane, struct iosys_map *src,
  			      struct drm_framebuffer *fb,
-			      const struct drm_rect *clip)
+			      const struct drm_rect *clip,

drivers/gpu/drm/ast/ast_mode.c static int ast_primary_plane_helper_atomic_check(struct drm_plane *plane, · line 563

Quoted 10 lines
drivers/gpu/drm/ast/ast_mode.c +6 -0
+			      struct drm_format_conv_state *fmtcnv_state)
  {
  	struct iosys_map dst = IOSYS_MAP_INIT_VADDR_IOMEM(ast_plane_vaddr(ast_plane));
 
  	iosys_map_incr(&dst, drm_fb_clip_offset(fb->pitches[0], fb->format, clip));
+#if defined(__BIG_ENDIAN) && defined(CONFIG_PCI_ARCH_ENDIAN_AUTOSWAP)
+	switch (fb->format->format) {
+		case DRM_FORMAT_HOST_XRGB8888:
+		case DRM_FORMAT_HOST_RGB565:
+			drm_fb_swab(&dst, fb->pitches, src, fb, clip, false, fmtcnv_state);

DRM formats are always little endian. I'm not sure if most user space even supports anything else.  Can we just drop the whole _FORMAT_HOST_ formats and do a swap here if we're on BE PPC64?

Best regards
Thomas

Quoted 53 lines
drivers/gpu/drm/ast/ast_mode.c +15 -1
+			break;
+		default:
+			drm_fb_memcpy(&dst, fb->pitches, src, fb, clip);
+	}
+#else
  	drm_fb_memcpy(&dst, fb->pitches, src, fb, clip);
+#endif
  }
 
  static void ast_primary_plane_helper_atomic_update(struct drm_plane *plane,
@@ -574,7 +595,7 @@ static void ast_primary_plane_helper_atomic_update(struct drm_plane *plane,
 
  	drm_atomic_helper_damage_iter_init(&iter, old_plane_state, plane_state);
  	drm_atomic_for_each_plane_damage(&iter, &damage) {
-		ast_handle_damage(ast_plane, shadow_plane_state->data, fb, &damage);
+		ast_handle_damage(ast_plane, shadow_plane_state->data, fb, &damage, &shadow_plane_state->fmtcnv_state);
  	}
 
  	/*
@@ -766,10 +787,13 @@ static int ast_crtc_helper_atomic_check(struct drm_crtc *crtc,
  		ast_state->std_table = &vbios_stdtable[VGAModeIndex];
  		break;
  	case DRM_FORMAT_RGB565:
+	case DRM_FORMAT_HOST_RGB565:
  		ast_state->std_table = &vbios_stdtable[HiCModeIndex];
  		break;
  	case DRM_FORMAT_RGB888:
+	case DRM_FORMAT_BGR888:
  	case DRM_FORMAT_XRGB8888:
+	case DRM_FORMAT_HOST_XRGB8888:
  		ast_state->std_table = &vbios_stdtable[TrueCModeIndex];
  		break;
  	default:
@@ -978,7 +1002,11 @@ static const struct drm_mode_config_helper_funcs ast_mode_config_helper_funcs =
  static enum drm_mode_status ast_mode_config_mode_valid(struct drm_device *dev,
  						       const struct drm_display_mode *mode)
  {
+#if defined(__BIG_ENDIAN) && defined(CONFIG_PCI_ARCH_ENDIAN_AUTOSWAP)
+	const struct drm_format_info *info = drm_format_info(DRM_FORMAT_HOST_XRGB8888);
+#else
  	const struct drm_format_info *info = drm_format_info(DRM_FORMAT_XRGB8888);
+#endif
  	struct ast_device *ast = to_ast_device(dev);
  	unsigned long max_fb_size = ast_fb_vram_size(ast);
  	u64 pitch;
@@ -1021,6 +1049,7 @@ int ast_mode_config_init(struct ast_device *ast)
  	dev->mode_config.min_width = 0;
  	dev->mode_config.min_height = 0;
  	dev->mode_config.preferred_depth = 24;
+	dev->mode_config.quirk_addfb_prefer_host_byte_order = true;
 
  	if (ast->support_fullhd) {
  		dev->mode_config.max_width = 1920;
Signature · 6 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)
#4 lore raw

Re: [PATCH 1/2] PCI: Add CONFIG_PCI_ARCH_ENDIAN_AUTOSWAP

In reply to Timothy Pearson

Hi,

sorry for the delay in reviewing. I've wondered for some time what to make of this series.

Am 17.10.25 um 20:17 schrieb Timothy Pearson:

Quoted 7 lines

Certain hardware devices, such as the IBM POWER9 CPU, transparently swap PCI bus MMIO data endianness when running in big endian mode. This transparent data swapping presents issues for certain types of BARs, for example little endian framebuffers, where the device driver needs to be aware the PCI BAR is now appearing as big endian from the host's perspective.

Introduce CONFIG_PCI_ARCH_ENDIAN_AUTOSWAP and enable on ppc64 systems.

I would not want a config option. In the latest version of the driver, we have a struct to describe device quirks. [1] I think we should detect this scenario in the driver and set the quirk if necessary. The detection can be at compile time though.

If this problem affects many graphics drivers, we can re-evaluate.

[1] https://gitlab.freedesktop.org/drm/misc/kernel/-/blob/drm-misc-next-2025-11-14/drivers/gpu/drm/ast/ast_drv.h?ref_type=tags#L167

Best regards
Thomas

Quoted 34 lines
---
  arch/powerpc/Kconfig | 1 +
  drivers/pci/Kconfig  | 4 ++++
  2 files changed, 5 insertions(+)
arch/powerpc/Kconfig +1 -0
index e24f4d88885a..0e75fe570389 100644
@@ -314,6 +314,7 @@ config PPC
  	select OF_EARLY_FLATTREE
  	select OLD_SIGACTION			if PPC32
  	select OLD_SIGSUSPEND
+	select PCI_ARCH_ENDIAN_AUTOSWAP		if PCI && PPC64
  	select PCI_DOMAINS			if PCI
  	select PCI_MSI_ARCH_FALLBACKS		if PCI_MSI
  	select PCI_SYSCALL			if PCI
drivers/pci/Kconfig +4 -0
index 7065a8e5f9b1..fccc01110763 100644
@@ -40,6 +40,10 @@ config PCI_DOMAINS_GENERIC
  config PCI_SYSCALL
  	bool
 
+config PCI_ARCH_ENDIAN_AUTOSWAP
+	bool
+	depends on PCI
+
  source "drivers/pci/pcie/Kconfig"
 
  config PCI_MSI
Signature · 6 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)
#5 lore raw
In reply to Timothy Pearson

Hi,

please take a look at the patch at [1]. Testing is welcome, if you can.

Best regards
Thomas

[1] https://lore.kernel.org/dri-devel/[email protected]/

Am 17.10.25 um 20:17 schrieb Timothy Pearson:

Quoted 17 lines

On ppc64 systems that use the AST2500 graphics device, such as the Blackbird POWER9 system, the red and blue channels are inverted when the host is running in big endian mode. This is due to a ppc64 hardware quirk, which when combined with a hardware design fault in the AST2500 VGA controller results in a need to use software-based red-blue channel swapping.

Tested to fix color graphics on Debian sid/ppc64 on a Blackbird system.

Timothy Pearson (2):
PCI: Add CONFIG_PCI_ARCH_ENDIAN_AUTOSWAP drm/ast: Fix framebuffer color swapping on ppc64 systems

  arch/powerpc/Kconfig           |  1 +
  drivers/gpu/drm/ast/ast_mode.c | 33 +++++++++++++++++++++++++++++++--
  drivers/pci/Kconfig            |  4 ++++
  3 files changed, 36 insertions(+), 2 deletions(-)
Signature · 6 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)