From nobody Fri Apr 3 17:39:04 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1774284877; cv=none; d=zohomail.com; s=zohoarc; b=mfGI8+54CQJpgusY8mPD6CGffRFQZ3onQC3GETIzFH7VtwXHGq0hhNIab1xWr7X5QlreH5DgL6KKw2BdOBOp00Fq/AGY8xt+ewqVmS1Akasw3OyuFFw7OaVVesxawRZFxxaTYT1O1MfmRwdII092IxbOCBVkGB2onf+aJuuVEbg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1774284877; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To:Cc; bh=eVldjBV0nVVV4/9MikBff2Nx48pteq1xXd1LtYfWGrc=; b=G4y2OaTmk0ol6WdGX8RFO18xdcOIyKxNSPhxAQMrCFDg8FUztzlHyDhoV8CmXhcp0o9xmlwJf9Aa1uzC9bIFBr66XRonYZzk+PeCxNKpU4vtx3CMZULtd+MjmDqJCxG6My+Y7FeT+03iPIZ5dL8gp5Au9Ru0nCmOH0WuFqA7SrA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1774284877105362.47689247818914; Mon, 23 Mar 2026 09:54:37 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w4iXq-0005j5-Tw; Mon, 23 Mar 2026 12:54:26 -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 1w4iXi-0005Yf-Dz for qemu-devel@nongnu.org; Mon, 23 Mar 2026 12:54:22 -0400 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1w4iXg-0000dI-2h for qemu-devel@nongnu.org; Mon, 23 Mar 2026 12:54:18 -0400 Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-43b40003d13so2722084f8f.2 for ; Mon, 23 Mar 2026 09:54:15 -0700 (PDT) Received: from localhost.localdomain (88-187-86-199.subs.proxad.net. [88.187.86.199]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43b64714e2esm33143191f8f.32.2026.03.23.09.54.13 for (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 23 Mar 2026 09:54:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1774284854; x=1774889654; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=eVldjBV0nVVV4/9MikBff2Nx48pteq1xXd1LtYfWGrc=; b=PjBY0ljQpLILOVf/sTmYU3ffLeFxGuFrtetmRuncziLR8ZASdnTHJxSbYKp56Oaf8s f56/w27+L/tDgBAuH3f7ZfSA4ktdk77Q5v5btNiDl4E1fcd5ekKzR/9Go8X3jvWR+k3B m2E71joXjPrQHf5Cz7Ox1Su8szFAJVoaUWOAPl/bo1J5Sp2gqeXPJjNdJMZ3/vIXTJhY zpTbUxxUGSvZGdy2PZas1hkLZgfhsjd0noqTpKteLEqRqSwMb+sRw+vrDtzLmOU/ICOt 6EJxr6UUFBGINNAefCCMXpnD/UfnEoTsmytTUdgPKNjO+L1+8KRI3+qeVesdmMFb7QdT zHXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774284854; x=1774889654; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=eVldjBV0nVVV4/9MikBff2Nx48pteq1xXd1LtYfWGrc=; b=JHPSk+HbQMN3Q55mwRleXY2/QTVMlkEFgMxSCXQCrlv3AgZ38FHJXLnGDn8j5P7rt1 m4dofKMMEDdNVMNNeHU3uayPDm4ME0S2+1oItUinbO0rbzmvMw+8dY64FeXrR1Sq+VT2 hKLqZebjVEHiLpB6NwQvcxxVUjlTUByABnZ3XkJ3gnc/Btlz8jslk2QgWLRjvLEozkAK foxu9W94NPSEorF8hoJ2Zr05qlC904idKiVDRfpJ9W+bsgnF46hYoWnP28yLlgZrMqTd DmjtaAYX4H4AeHPMaHT0J1Ik40noUx6xk/v8vmOf71/Bg2Sdyq65pjwmfb1+gsd30E8e XvYg== X-Gm-Message-State: AOJu0YxDYZX12nbII5OGu5+h9NxR5yEN7ti23edCHjv0DnWH7oTxvU6D qMOS1EOy6rzKlesderRf+NqgwXq9tbZTv3Yf+1JiIOLprX0H3VLYk9p1PfRln/0xPaTUAZqof7K Lr+VO0HQ= X-Gm-Gg: ATEYQzy2GddFlSli2Ogj47sO0WfuPwqtxi5H1VXaVeb1Q8BlsmIlrUZq8VVTrvmDta+ uWI2i0yPS3OVBoPqeJdwg0Jm0hcCbh5RkrSZHBpq0quioCe1xl1VSuCw/qOHWjBnS84RtdyhElE 7soCvdhIhF/K2wpUzMWaNBV+a/nNA58dOw8GKqLHFvWWgYAoof55Z/Fe7o9Xd2g8gIhhHh2LWx/ qGrh148un0bIw+e3dvW0trkMqk+tNtyiGCDTRm6mSPhRXF0DH4N7LNPXmX+0/SjZDmqAVzPGmE7 kcHxpXVkig3isXVJVyUBoZUZj0itzNBi6Z8A07Kh0PWlfLge6JkRi6jx7D4IBD9unNXdFOtdzzD TrgbrWrDhJSwKQn4XkE8cFjIzp+d/In2zjcgbS8yWby73Ho+tfLW0LdDgcIJYIeLh8oH6RdVt0Q B5MaS8RNkrzwnp8uoHnhOV3vJiL1xzk25r9JM9n+kboboXXTuVOkyllW1UczvT2hT711mVMEgW X-Received: by 2002:a05:6000:26c8:b0:439:bcb8:54b7 with SMTP id ffacd0b85a97d-43b6424b9eemr19335140f8f.15.1774284853906; Mon, 23 Mar 2026 09:54:13 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PULL 17/27] ati-vga: Fix colors when frame buffer endianness does not match host Date: Mon, 23 Mar 2026 17:52:08 +0100 Message-ID: <20260323165218.96607-18-philmd@linaro.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260323165218.96607-1-philmd@linaro.org> References: <20260323165218.96607-1-philmd@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=2a00:1450:4864:20::435; envelope-from=philmd@linaro.org; helo=mail-wr1-x435.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1774284879170158500 From: BALATON Zoltan 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 Message-ID: <759ed5e3b019cce94e9a4ef003f1fc2e0cea2ec1.1774110169.git.balato= n@eik.bme.hu> Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- 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 37fe6c17ee9..0cbbdc33f47 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.53.0