From nobody Sun Mar 22 15:34:37 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=eik.bme.hu Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1774055170633984.8346474749047; Fri, 20 Mar 2026 18:06:10 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w3klV-0008Pe-F2; Fri, 20 Mar 2026 21:04:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w3klU-0008P4-IQ for qemu-devel@nongnu.org; Fri, 20 Mar 2026 21:04:32 -0400 Received: from zero.eik.bme.hu ([152.66.115.2]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w3klR-0003yL-BL for qemu-devel@nongnu.org; Fri, 20 Mar 2026 21:04:32 -0400 Received: from localhost (localhost [127.0.0.1]) by zero.eik.bme.hu (Postfix) with ESMTP id 86B03596E00; Sat, 21 Mar 2026 02:04:23 +0100 (CET) Received: from zero.eik.bme.hu ([127.0.0.1]) by localhost (zero.eik.bme.hu [127.0.0.1]) (amavis, port 10028) with ESMTP id c19mO70v-B_g; Sat, 21 Mar 2026 02:04:19 +0100 (CET) Received: by zero.eik.bme.hu (Postfix, from userid 432) id 11A1D5969F3; Sat, 21 Mar 2026 02:04:19 +0100 (CET) X-Virus-Scanned: amavis at eik.bme.hu Message-ID: <759ed5e3b019cce94e9a4ef003f1fc2e0cea2ec1.1774054635.git.balaton@eik.bme.hu> In-Reply-To: References: From: BALATON Zoltan Subject: [PATCH v5 1/8] ati-vga: Fix colors when frame buffer endianness does not match host MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , marcandre.lureau@redhat.com, Chad Jablonski , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Date: Sat, 21 Mar 2026 02:04:19 +0100 (CET) Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=152.66.115.2; envelope-from=balaton@eik.bme.hu; helo=zero.eik.bme.hu X-Spam_score_int: -1 X-Spam_score: -0.2 X-Spam_bar: / X-Spam_report: (-0.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.819, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.903, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1774055173220158500 Content-Type: text/plain; charset="utf-8" When writing pixels we have to take into account if the frame buffer endianness matches the host endianness or we need to swap to correct endianness. This caused wrong colors e.g. with PPC Linux guest that uses big endian frame buffer when running on little endian host. Signed-off-by: BALATON Zoltan Tested-by: Chad Jablonski Reviewed-by: Chad Jablonski --- hw/display/ati_2d.c | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/hw/display/ati_2d.c b/hw/display/ati_2d.c index 37fe6c17ee..0cbbdc33f4 100644 --- a/hw/display/ati_2d.c +++ b/hw/display/ati_2d.c @@ -50,6 +50,7 @@ typedef struct { bool host_data_active; bool left_to_right; bool top_to_bottom; + bool need_swap; uint32_t frgd_clr; const uint8_t *palette; const uint8_t *vram_end; @@ -89,6 +90,7 @@ static void setup_2d_blt_ctx(const ATIVGAState *s, ATI2DC= tx *ctx) ctx->host_data_active =3D s->host_data.active; ctx->left_to_right =3D s->regs.dp_cntl & DST_X_LEFT_TO_RIGHT; ctx->top_to_bottom =3D s->regs.dp_cntl & DST_Y_TOP_TO_BOTTOM; + ctx->need_swap =3D HOST_BIG_ENDIAN !=3D s->vga.big_endian_fb ? true : = false; ctx->frgd_clr =3D s->regs.dp_brush_frgd_clr; ctx->palette =3D s->vga.palette; ctx->dst_offset =3D s->regs.dst_offset; @@ -131,6 +133,17 @@ static void setup_2d_blt_ctx(const ATIVGAState *s, ATI= 2DCtx *ctx) (ctx->top_to_bottom ? 'v' : '^')); } =20 +static uint32_t make_filler(int bpp, uint32_t color) +{ + if (bpp < 24) { + color |=3D color << 16; + if (bpp < 15) { + color |=3D color << 8; + } + } + return color; +} + static bool ati_2d_do_blt(ATI2DCtx *ctx, uint8_t use_pixman) { QemuRect vis_src, vis_dst; @@ -255,7 +268,7 @@ static bool ati_2d_do_blt(ATI2DCtx *ctx, uint8_t use_pi= xman) =20 switch (ctx->rop3) { case ROP3_PATCOPY: - filler =3D ctx->frgd_clr; + filler =3D make_filler(ctx->bpp, ctx->frgd_clr); break; case ROP3_BLACKNESS: filler =3D 0xffUL << 24 | rgb_to_pixel32(ctx->palette[0], @@ -268,10 +281,12 @@ static bool ati_2d_do_blt(ATI2DCtx *ctx, uint8_t use_= pixman) ctx->palette[5]); break; } - DPRINTF("pixman_fill(%p, %ld, %d, %d, %d, %d, %d, %x)\n", ctx->dst_bits, ctx->dst_stride / sizeof(uint32_t), ctx->bp= p, vis_dst.x, vis_dst.y, vis_dst.width, vis_dst.height, fille= r); + if (ctx->need_swap) { + bswap32s(&filler); + } #ifdef CONFIG_PIXMAN if (!(use_pixman & BIT(0)) || !pixman_fill((uint32_t *)ctx->dst_bits, @@ -325,11 +340,8 @@ void ati_2d_blt(ATIVGAState *s) bool ati_host_data_flush(ATIVGAState *s) { ATI2DCtx ctx, chunk; - uint32_t fg =3D s->regs.dp_src_frgd_clr; - uint32_t bg =3D s->regs.dp_src_bkgd_clr; unsigned bypp, pix_count, row, col, idx; uint8_t pix_buf[ATI_HOST_DATA_ACC_BITS * sizeof(uint32_t)]; - uint32_t byte_pix_order =3D s->regs.dp_datatype & DP_BYTE_PIX_ORDER; uint32_t src_source =3D s->regs.dp_mix & DP_SRC_SOURCE; uint32_t src_datatype =3D s->regs.dp_datatype & DP_SRC_DATATYPE; =20 @@ -360,21 +372,27 @@ bool ati_host_data_flush(ATIVGAState *s) } =20 bypp =3D ctx.bpp / 8; - + pix_count =3D ATI_HOST_DATA_ACC_BITS; if (src_datatype =3D=3D SRC_COLOR) { - pix_count =3D ATI_HOST_DATA_ACC_BITS / ctx.bpp; - memcpy(pix_buf, &s->host_data.acc[0], sizeof(s->host_data.acc)); + pix_count /=3D ctx.bpp; + memcpy(pix_buf, s->host_data.acc, sizeof(s->host_data.acc)); } else { - pix_count =3D ATI_HOST_DATA_ACC_BITS; /* Expand monochrome bits to color pixels */ + uint32_t byte_pix_order =3D s->regs.dp_datatype & DP_BYTE_PIX_ORDE= R; + uint32_t fg =3D make_filler(ctx.bpp, s->regs.dp_src_frgd_clr); + uint32_t bg =3D make_filler(ctx.bpp, s->regs.dp_src_bkgd_clr); + + if (ctx.need_swap) { + bswap32s(&fg); + bswap32s(&bg); + } idx =3D 0; for (int word =3D 0; word < 4; word++) { for (int byte =3D 0; byte < 4; byte++) { uint8_t byte_val =3D s->host_data.acc[word] >> (byte * 8); for (int i =3D 0; i < 8; i++) { bool is_fg =3D byte_val & BIT(byte_pix_order ? i : 7 -= i); - uint32_t color =3D is_fg ? fg : bg; - stn_he_p(&pix_buf[idx], bypp, color); + stn_he_p(&pix_buf[idx], bypp, is_fg ? fg : bg); idx +=3D bypp; } } --=20 2.41.3