public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Orlando Chamberlain <orlandoch.dev@gmail.com>
To: Hans de Goede <hdegoede@redhat.com>
Cc: platform-driver-x86@vger.kernel.org,
	amd-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org,
	alsa-devel@alsa-project.org,
	"Alex Deucher" <alexander.deucher@amd.com>,
	"Christian König" <christian.koenig@amd.com>,
	"Pan, Xinhui" <Xinhui.Pan@amd.com>,
	"David Airlie" <airlied@gmail.com>,
	"Daniel Vetter" <daniel@ffwll.ch>,
	"Mark Gross" <markgross@kernel.org>,
	"Jaroslav Kysela" <perex@perex.cz>,
	"Takashi Iwai" <tiwai@suse.com>,
	"Hawking Zhang" <Hawking.Zhang@amd.com>,
	"Andrey Grodzovsky" <andrey.grodzovsky@amd.com>,
	"Lijo Lazar" <lijo.lazar@amd.com>,
	"YiPeng Chai" <YiPeng.Chai@amd.com>,
	"Somalapuram Amaranath" <Amaranath.Somalapuram@amd.com>,
	"Mario Limonciello" <mario.limonciello@amd.com>,
	"Bokun Zhang" <Bokun.Zhang@amd.com>,
	"Jack Xiao" <Jack.Xiao@amd.com>,
	"Kai Vehmanen" <kai.vehmanen@linux.intel.com>,
	"Pierre-Louis Bossart" <pierre-louis.bossart@linux.intel.com>,
	"Rander Wang" <rander.wang@intel.com>,
	"Ranjani Sridharan" <ranjani.sridharan@linux.intel.com>,
	"Amadeusz Sławiński" <amadeuszx.slawinski@linux.intel.com>,
	"Yong Zhi" <yong.zhi@intel.com>, "Evan Quan" <evan.quan@amd.com>,
	"Kerem Karabay" <kekrby@gmail.com>,
	"Aditya Garg" <gargaditya08@live.com>,
	"Aun-Ali Zaidi" <admin@kodeit.net>
Subject: Re: [RFC PATCH 1/9] apple-gmux: use cpu_to_be32 instead of manual reorder
Date: Sat, 11 Feb 2023 10:30:24 +1100	[thread overview]
Message-ID: <20230211103024.2a204487@redecorated-mbp> (raw)
In-Reply-To: <74e3c9ae-b1f1-1e7b-4af1-56f918471b36@redhat.com>

On Fri, 10 Feb 2023 20:19:27 +0100
Hans de Goede <hdegoede@redhat.com> wrote:

> Hi,
> 
> On 2/10/23 20:09, Hans de Goede wrote:
> > Hi,
> > 
> > On 2/10/23 05:48, Orlando Chamberlain wrote:  
> >> Currently it manually flips the byte order, but we can instead use
> >> cpu_to_be32(val) for this.
> >>
> >> Signed-off-by: Orlando Chamberlain <orlandoch.dev@gmail.com>
> >> ---
> >>  drivers/platform/x86/apple-gmux.c | 18 ++----------------
> >>  1 file changed, 2 insertions(+), 16 deletions(-)
> >>
> >> diff --git a/drivers/platform/x86/apple-gmux.c
> >> b/drivers/platform/x86/apple-gmux.c index
> >> 9333f82cfa8a..e8cb084cb81f 100644 ---
> >> a/drivers/platform/x86/apple-gmux.c +++
> >> b/drivers/platform/x86/apple-gmux.c @@ -94,13 +94,7 @@ static u32
> >> gmux_pio_read32(struct apple_gmux_data *gmux_data, int port)
> >> static void gmux_pio_write32(struct apple_gmux_data *gmux_data,
> >> int port, u32 val) {
> >> -	int i;
> >> -	u8 tmpval;
> >> -
> >> -	for (i = 0; i < 4; i++) {
> >> -		tmpval = (val >> (i * 8)) & 0xff;
> >> -		outb(tmpval, gmux_data->iostart + port + i);
> >> -	}
> >> +	outl(cpu_to_be32(val), gmux_data->iostart + port);
> >>  }
> >>  
> >>  static int gmux_index_wait_ready(struct apple_gmux_data
> >> *gmux_data)  
> > 
> > The ioport / indexed-ioport accessed apple_gmux-es likely are (part
> > of?) LPC bus devices . Looking at the bus level you are now
> > changing 4 io accesses with a size of 1 byte, to 1 32 bit io-access.
> > 
> > Depending on the decoding hw in the chip this may work fine,
> > or this may work not at all.
> > 
> > I realized that you have asked for more testing, but most surviving
> > macbooks from the older apple-gmux era appear to be models without
> > a discrete GPU (which are often the first thing to break) and thus
> > without a gmux.
> > 
> > Unless we get a bunch of testers to show up, which I doubt. I would
> > prefer slightly bigger / less pretty code and not change the
> > functional behavior of the driver on these older models.  
> 
> A quick follow up on this, I just noticed that only the pio_write32
> is doing the one byte at a time thing:
> 
> static u32 gmux_pio_read32(struct apple_gmux_data *gmux_data, int
> port) {
>         return inl(gmux_data->iostart + port);
> }
> 
> static void gmux_pio_write32(struct apple_gmux_data *gmux_data, int
> port, u32 val)
> {
>         int i;
>         u8 tmpval;
> 
>         for (i = 0; i < 4; i++) {
>                 tmpval = (val >> (i * 8)) & 0xff;
>                 outb(tmpval, gmux_data->iostart + port + i);
>         }
> }
> 
> And if you look closely gmux_pio_write32() is not swapping
> the order to be32 at all, it is just taking the bytes
> in little-endian memory order, starting with the first
> (index 0) byte which is the least significant byte of
> the value.
> 
> On x86 the original code is no different then doing:
> 
> static void gmux_pio_write32(struct apple_gmux_data *gmux_data, int
> port, u32 val)
> {
>         u8 *data = (u8 *)&val;
>         int i;
> 
>         for (i = 0; i < 4; i++)
>                 outb(data[i], gmux_data->iostart + port + i);
> }
> 
> So yeah this patch is definitely wrong, it actually swaps
> the byte order compared to the original code. Which becomes
> clear when you look the weird difference between the read32 and
> write32 functions after this patch.
> 
> Presumably there is a specific reason why gmux_pio_write32()
> is not already doing a single outl(..., val) and byte-ordering
> is not the reason.
> 
> Regards,
> 
> Hans

Sounds like it may be better to just drop this patch as there's very
little benefit for the risk of causing a regression.

> 
> 
> 
> >> @@ -177,16 +171,8 @@ static u32 gmux_index_read32(struct
> >> apple_gmux_data *gmux_data, int port) static void
> >> gmux_index_write32(struct apple_gmux_data *gmux_data, int port,
> >> u32 val) {
> >> -	int i;
> >> -	u8 tmpval;
> >> -
> >>  	mutex_lock(&gmux_data->index_lock);
> >> -
> >> -	for (i = 0; i < 4; i++) {
> >> -		tmpval = (val >> (i * 8)) & 0xff;
> >> -		outb(tmpval, gmux_data->iostart + GMUX_PORT_VALUE
> >> + i);
> >> -	}
> >> -
> >> +	outl(cpu_to_be32(val), gmux_data->iostart +
> >> GMUX_PORT_VALUE); gmux_index_wait_ready(gmux_data);
> >>  	outb(port & 0xff, gmux_data->iostart + GMUX_PORT_WRITE);
> >>  	gmux_index_wait_complete(gmux_data);  
> >   
> 


  reply	other threads:[~2023-02-10 23:30 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-10  4:48 [RFC PATCH 0/9] apple-gmux: support MMIO gmux type on T2 Macs Orlando Chamberlain
2023-02-10  4:48 ` [RFC PATCH 1/9] apple-gmux: use cpu_to_be32 instead of manual reorder Orlando Chamberlain
2023-02-10 19:09   ` Hans de Goede
2023-02-10 19:19     ` Hans de Goede
2023-02-10 23:30       ` Orlando Chamberlain [this message]
2023-02-11 11:27         ` Hans de Goede
2023-02-10 19:33     ` Hans de Goede
2023-02-10 22:52       ` David Laight
2023-02-10  4:48 ` [RFC PATCH 2/9] apple-gmux: consolidate version reading Orlando Chamberlain
2023-02-10 19:41   ` Hans de Goede
2023-02-10 23:36     ` Orlando Chamberlain
2023-02-10  4:48 ` [RFC PATCH 3/9] apple-gmux: use first bit to check switch state Orlando Chamberlain
2023-02-10  4:48 ` [RFC PATCH 4/9] apple-gmux: refactor gmux types Orlando Chamberlain
2023-02-10  4:48 ` [RFC PATCH 5/9] apple-gmux: Use GMSP acpi method for interrupt clear Orlando Chamberlain
2023-02-10 19:43   ` Hans de Goede
2023-02-10 23:40     ` Orlando Chamberlain
2023-02-10  4:48 ` [RFC PATCH 6/9] apple-gmux: support MMIO gmux on T2 Macs Orlando Chamberlain
2023-02-10  4:48 ` [RFC PATCH 7/9] apple-gmux: add sysfs interface Orlando Chamberlain
2023-02-10 20:15   ` Hans de Goede
2023-02-10 20:23     ` Hans de Goede
2023-02-10 23:44       ` Orlando Chamberlain
2023-02-10  4:48 ` [RFC PATCH 8/9] hda/hdmi: Register with vga_switcheroo on Dual GPU Macbooks Orlando Chamberlain
2023-02-10  4:48 ` [RFC PATCH 9/9] drm/amdgpu: register a vga_switcheroo client for all GPUs that are not thunderbolt attached Orlando Chamberlain
2023-02-10 15:53   ` Alex Deucher
2023-02-10 16:07     ` Hans de Goede
2023-02-10 16:37       ` Alex Deucher
2023-02-10 23:54         ` Orlando Chamberlain
2023-02-10 16:30 ` [RFC PATCH 0/9] apple-gmux: support MMIO gmux type on T2 Macs Alex Deucher

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=20230211103024.2a204487@redecorated-mbp \
    --to=orlandoch.dev@gmail.com \
    --cc=Amaranath.Somalapuram@amd.com \
    --cc=Bokun.Zhang@amd.com \
    --cc=Hawking.Zhang@amd.com \
    --cc=Jack.Xiao@amd.com \
    --cc=Xinhui.Pan@amd.com \
    --cc=YiPeng.Chai@amd.com \
    --cc=admin@kodeit.net \
    --cc=airlied@gmail.com \
    --cc=alexander.deucher@amd.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=amadeuszx.slawinski@linux.intel.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=andrey.grodzovsky@amd.com \
    --cc=christian.koenig@amd.com \
    --cc=daniel@ffwll.ch \
    --cc=evan.quan@amd.com \
    --cc=gargaditya08@live.com \
    --cc=hdegoede@redhat.com \
    --cc=kai.vehmanen@linux.intel.com \
    --cc=kekrby@gmail.com \
    --cc=lijo.lazar@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mario.limonciello@amd.com \
    --cc=markgross@kernel.org \
    --cc=perex@perex.cz \
    --cc=pierre-louis.bossart@linux.intel.com \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=rander.wang@intel.com \
    --cc=ranjani.sridharan@linux.intel.com \
    --cc=tiwai@suse.com \
    --cc=yong.zhi@intel.com \
    /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