mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "René Rebe" <rene@exactco.de>
To: tzimmermann@suse.de
Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
	airlied@redhat.com
Subject: Re: [PATCH V2] drm/mgag200: Fix big-endian support
Date: Mon, 08 Dec 2025 13:39:50 +0100 (CET)	[thread overview]
Message-ID: <20251208.133950.469837482614896193.rene@exactco.de> (raw)
In-Reply-To: <816e40d2-e451-4d70-bc44-e07562138b1b@suse.de>

Moin Thomas,

On Mon, 8 Dec 2025 09:29:53 +0100, Thomas Zimmermann <tzimmermann@suse.de> wrote:

> Hi,
> 
> thanks for the update.

of course!

> Am 05.12.25 um 18:24 schrieb René Rebe:
> > Unlike the original, deleted Matrox mga driver, the new mgag200 driver
> > has the XRGB frame-buffer byte swapped on big-endian "RISC"
> > systems. Fix by enabling byte swapping "PowerPC" OPMODE for any
> > __BIG_ENDIAN config.
> >
> > Fixes: 414c45310625 ("mgag200: initial g200se driver (v2)")
> > Signed-off-by: René Rebe <rene@exactco.de>
> > Cc: stable@kernel.org
> > ---
> > V2: move to atomic_update
> > Tested on IBM 43p Model 150 (7043-150) running T2/Linux.
> > ---
> >   drivers/gpu/drm/mgag200/mgag200_mode.c | 14 ++++++++++++++
> >   1 file changed, 14 insertions(+)
> >
> > diff --git a/drivers/gpu/drm/mgag200/mgag200_mode.c
> > b/drivers/gpu/drm/mgag200/mgag200_mode.c
> > index 951d715dea30..d40434ec68ab 100644
> > --- a/drivers/gpu/drm/mgag200/mgag200_mode.c
> > +++ b/drivers/gpu/drm/mgag200/mgag200_mode.c
> > @@ -496,6 +496,20 @@ void
> > mgag200_primary_plane_helper_atomic_update(struct drm_plane *plane,
> >   	struct drm_atomic_helper_damage_iter iter;
> >   	struct drm_rect damage;
> >   +#ifdef __BIG_ENDIAN
> > +	/* Big-endian byte-swapping */
> > +	switch (fb->format->format) {
> > +	case DRM_FORMAT_RGB565:
> > +		WREG32(MGAREG_OPMODE, 0x10100);
> > +		break;
> > +	case DRM_FORMAT_XRGB8888:
> > +		WREG32(MGAREG_OPMODE, 0x20200);
> > +		break;
> > +	default:
> > +		break;
> 
> No need for a default branch IIRC.

Hm, it was a preventitive measure to avoid compiler warnings, but I'll
check if we don't get one for unhandled format cases, ...

> > +	}
> 
> This is the right place to set up the write mode.
> 
> But looking at the G200 docs, I found that the reset value for OPMODE
> has bit 18 set to 1. These writes clear the value. If that
> intentional?

Well the same doc says: "Reserved <1:0> <7:4> <15:10> <31:18>
Reserved. When writing to this register, the bits in these fields must
be set to ‘0’.  Reading will return ‘0’s"

So I would guess the reset value is a typo. But I'll adjust the code
nontheless.

> For better style and compatibility, I suggest to first read the value
> and keep the reserved bit as-is.
> 
> u32 opmode
> 
> opmode = RREG32(MGAREG_OPMODE)
> opmode &= ~GENMASK(17, 16)
> opmode &= ~GENMASK(9, 8)
> opmode &= ~GENMASK(3, 2)

I'll merge that in one line of GENMASK, hope that's acceptable.

> switch (format) {
>         opmode |= ...;
> }
> 
> WREG32(OPMODE, opmode);
> 
> You can put that in a helper near set_startadd [1]
> 
> void mgag200_set_datasiz(struct mga_device *mdev, u32 format)
> {
> #if __BIG_ENDIAN
> ...
> #endif
> }
> 
> Then call that from atomic_update and it should be fine.

I'll make it a function that if that is what is preferred.

     René

> [1]
> https://elixir.bootlin.com/linux/v6.18/source/drivers/gpu/drm/mgag200/mgag200_mode.c#L117

-- 
René Rebe, ExactCODE GmbH, Berlin, Germany
https://exactco.de • https://t2linux.com • https://patreon.com/renerebe

      reply	other threads:[~2025-12-08 12:39 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-05 17:24 René Rebe
2025-12-08  8:29 ` Thomas Zimmermann
2025-12-08 12:39   ` René Rebe [this message]

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=20251208.133950.469837482614896193.rene@exactco.de \
    --to=rene@exactco.de \
    --cc=airlied@redhat.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tzimmermann@suse.de \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®