Message ID | 20230210044826.9834-2-orlandoch.dev@gmail.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp755645wrn; Thu, 9 Feb 2023 20:52:00 -0800 (PST) X-Google-Smtp-Source: AK7set+V0ncz35biLl3V4Q88tjGNg5/4/xCoXwH+7bXZpuybl4+yr3ZQX1QKBlLaDNDnRVUbTJyP X-Received: by 2002:a50:a41b:0:b0:4ab:1689:64f1 with SMTP id u27-20020a50a41b000000b004ab168964f1mr7210759edb.8.1676004720193; Thu, 09 Feb 2023 20:52:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676004720; cv=none; d=google.com; s=arc-20160816; b=MHh0brR+TYexEzucU4hDTElzVKVMnQCMOhGLSKMORRGeS56xgvar9403U9uNhM7n2I z6O+cl3BIz8nsDtwIh+9DBxr5jK+ZPxpoE2AQsiTSoIpg/SmT2CNTVKDB6YerIvDMhlP Cap5T6SyDokGe2Fnk/7SoAxo7P0wCFCm0KLFtihQ/fGCA0YlBfR5N5XzDnkNNPFP304h vp1nxowkyf0PapyM63Cox/BwPF+Si0kYhNrHjCpGklqbTkxVRypxOCShdZIjJ8rSSN7L VHhTBStCVBdwZwY8ZwAxIrsClpI8mJ1ZgpFapxPAOSb3N0mnVzgm6kVryn2lkZDTEz/3 0reA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=5mAzAHTdZsC5IqNul3xJsl6wPXmAHfKwZ27VCzKXGF4=; b=Y7rVo9k9TQPuuiTL3mWwQ+2p5DhXDH4igdG5dQMpvk5XcXRGs/JITAVEjbWVX9RqJb dE0uUt2UeLPL5tj2DlCT+Copz0f2F3yrPm7B1hxhJW8inRtYpYYDklctvoiYlaAgZCd2 ouoOGsrJ8yzLjdZTISo8Q1n2D5nqdyyANEpjTbpgQG2Y3kYSy9liol6gGU2Il30OcyaQ TvChzgjwDgba2AmnLFjHt+smTJgj5kmMThCi0ns7S+k20hWp/+hX4igWU/qrsxmTbgsb 4JwEGwG2lq83GGyKyKmw3j/e5DFoRVvWDsBHkg7RTKBFk8jzMusOOH/mq7/Zu9r7d6pH Qukw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=JVtiloj7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z16-20020aa7d410000000b004aad854e24csi4261102edq.24.2023.02.09.20.51.37; Thu, 09 Feb 2023 20:52:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=JVtiloj7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229762AbjBJEuX (ORCPT <rfc822;ybw1215001957@gmail.com> + 99 others); Thu, 9 Feb 2023 23:50:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230477AbjBJEuK (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 9 Feb 2023 23:50:10 -0500 Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1F775B74E; Thu, 9 Feb 2023 20:50:09 -0800 (PST) Received: by mail-pg1-x533.google.com with SMTP id q9so2973528pgq.5; Thu, 09 Feb 2023 20:50:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5mAzAHTdZsC5IqNul3xJsl6wPXmAHfKwZ27VCzKXGF4=; b=JVtiloj7yRa4BQFYW86RmJebSQYTmr6ulQWbaNdE813YnQNwxXxigdeqKGwJ547OA9 iKneGqYybribFvactjWAxLOC1FFyHyE+vrJN9XEm4Abm2yHTeo6rcn+1OgEhy5wP98gZ +ThcUd3YSIgv/n1tSUkAQD0bQGEO9epBP65UtYfzB4TDt5HkYEHAUsO9ybZHG+TDzu0u hqJKP33cLtrVl0eYH6Qi6HmbIoL1D0nmoU8eLgaP0zLDynkeKmwUzTLzZaRDN3rU0PL/ En5vvM6GmtpTk46YMQcS55SP+xFg1xh1ZcTgKWrbYfmIOMTZVYpC6OIy+kKwcbJ4fUCF NfGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5mAzAHTdZsC5IqNul3xJsl6wPXmAHfKwZ27VCzKXGF4=; b=QsU4lTjw8OkLlk8yMyhfB/0Au9kN822s3nOScVY9NuQMCAav7klgBpMFNkNpzMPyd1 +YXXu1kBm8LeznkG6+hakTDxVLL/fnbwGpaSJjGWtKJRlbDU581LiXn4iuwBePBIN93E 7cvYgGVjoqST/LejMIqUuRJ+QYm0slKEAhRuxaJeTOm914hD06o0IMhFiHBmtAlPQLgF 2/43wFFSiM6d4nn6YLBpEOjXy3rVG5LP5P3JrXDmFTk6AnxcKjO5UDxA/JJZek0ePA9h fujqrIGGRUj7h+EpnXY+BPeAfw9HgtQje4nf88/cWnnCWIgRI6NQZRXMh6sPx0Ypr0gQ hnSg== X-Gm-Message-State: AO0yUKX9pwwzJJd6Iu8gWfGpb4CdmvIGl5owLMpAfSE7P+lb+uSB5b7E 619dkjR5HU1G7Ljk6LZUpPLKrRHBA14tBw== X-Received: by 2002:a62:1c13:0:b0:593:2289:f01c with SMTP id c19-20020a621c13000000b005932289f01cmr11514678pfc.25.1676004609052; Thu, 09 Feb 2023 20:50:09 -0800 (PST) Received: from localhost.localdomain ([202.53.32.211]) by smtp.gmail.com with ESMTPSA id t13-20020a62ea0d000000b0057fec210d33sm2269218pfh.152.2023.02.09.20.49.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Feb 2023 20:50:08 -0800 (PST) From: Orlando Chamberlain <orlandoch.dev@gmail.com> To: platform-driver-x86@vger.kernel.org, amd-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org Cc: Alex Deucher <alexander.deucher@amd.com>, =?utf-8?q?Christian_K=C3=B6nig?= <christian.koenig@amd.com>, "Pan, Xinhui" <Xinhui.Pan@amd.com>, David Airlie <airlied@gmail.com>, Daniel Vetter <daniel@ffwll.ch>, Hans de Goede <hdegoede@redhat.com>, 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>, =?utf-8?q?Amadeusz_S?= =?utf-8?q?=C5=82awi=C5=84ski?= <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>, Orlando Chamberlain <orlandoch.dev@gmail.com> Subject: [RFC PATCH 1/9] apple-gmux: use cpu_to_be32 instead of manual reorder Date: Fri, 10 Feb 2023 15:48:18 +1100 Message-Id: <20230210044826.9834-2-orlandoch.dev@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230210044826.9834-1-orlandoch.dev@gmail.com> References: <20230210044826.9834-1-orlandoch.dev@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757418325797210599?= X-GMAIL-MSGID: =?utf-8?q?1757418325797210599?= |
Series |
apple-gmux: support MMIO gmux type on T2 Macs
|
|
Commit Message
Orlando Chamberlain
Feb. 10, 2023, 4:48 a.m. UTC
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(-)
Comments
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. Regards, Hans > @@ -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);
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 >> @@ -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); >
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. Correction to myself, re-reading the LPC specification, then if I'm right and this is a LPC device then all IO in/out accesses are always 1 byte accesses. Since the LPC bus only supports 16 / 32 bit accesses for DMA cycles. So presumably the outl() would get split into 4 separate 8 bit (port) IO accesses. Regards, Hans >> @@ -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); >
From: Hans de Goede > Sent: 10 February 2023 19:33 > > 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. > > Correction to myself, re-reading the LPC specification, then > if I'm right and this is a LPC device then all IO in/out accesses > are always 1 byte accesses. Since the LPC bus only supports 16 / 32 > bit accesses for DMA cycles. > > So presumably the outl() would get split into 4 separate 8 bit > (port) IO accesses. I wonder if there is something obscure and the order of the 4 bytes writes matters? In any case writing as: xxxx iostart = gmux_data->iostart + port; outb(val, iostart); outb(val >> 8, iostart + 1); outb(val >> 16, iostart + 2); outb(val >> 24, ioctart + 3); almost certainly generates better code. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
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); > > >
Hi, On 2/11/23 00:30, Orlando Chamberlain wrote: > 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. Yes if it is easy to drop this please drop this. And the same more or less applies to 2/9. I would rather have an extra "if () ... else ..." in the code in a couple of places then change behavior on old hw where we cannot get proper test coverage (but will likely eventually get regressions reports if we break things). Thanks & Regards, Hans >>>> @@ -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); >>> >> >
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) @@ -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);