linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Wolfram Sang <wsa@kernel.org>
To: Terry Bowman <Terry.Bowman@amd.com>,
	Jean Delvare <jdelvare@suse.de>,
	Guenter Roeck <linux@roeck-us.net>
Cc: linux-i2c@vger.kernel.org, linux-watchdog@vger.kernel.org,
	linux-kernel@vger.kernel.org, thomas.lendacky@amd.com
Subject: Re: [PATCH] i2c: piix4: Replace piix4_smbus driver's cd6h/cd7h port io accesses with mmio accesses
Date: Thu, 6 Jan 2022 14:01:48 +0100	[thread overview]
Message-ID: <YdboPCYlhExlLWhX@ninjato> (raw)
In-Reply-To: <c28ab909-99b4-b43c-e330-b07e35afb981@amd.com>

[-- Attachment #1: Type: text/plain, Size: 6727 bytes --]

Hi Jean and Guenter,

> This is a gentle reminder to review my previous response when possible. Thanks!

Quite some modern AMD laptops seem to suffer from slow touchpads and
this patch is part of the fix [1]. So, if you could comment on Terry's
questions, this is highly appreciated!

Thanks and all the best,

   Wolfram

[1] https://lore.kernel.org/r/CAPoEpV0ZSidL6aMXvB6LN1uS-3CUHS4ggT8RwFgmkzzCiYJ-XQ@mail.gmail.com

> 
> Regards,
> Terry
> 
> On 12/13/21 11:48 AM, Terry Bowman wrote:
> > Hi Jean and Guenter,
> > 
> > Jean, Thanks for your responses. I added comments below.
> > 
> > I added Guenter to this email because his input is needed for adding the same
> > changes to the sp5100_tco driver. The sp5100_tco and piix4_smbus driver
> > must use the same synchronization logic for the shared register.
> > 
> > On 11/5/21 11:05, Jean Delvare wrote:
> >> On Tue, 7 Sep 2021 18:37:20 +0200, Jean Delvare wrote:
> >>> More generally, I am worried about the overall design. The driver
> >>> originally used per-access I/O port requesting because keeping the I/O
> >>> ports busy all the time would prevent other drivers from working. Do we
> >>> still need to do the same with the new code? If it is possible and safe
> >>> to have a permanent mapping to the memory ports, that would be a lot
> >>> faster.
> >>>
> > 
> > Permanent mapping would likely improve performance but will not provide the
> > needed synchronization. As you mentioned below the sp5100 driver only uses
> > the DECODEEN register during initialization but the access must be
> > synchronized or an i2c transaction or sp5100_tco timer enable access may be
> > lost. I considered alternatives but most lead to driver coupling or considerable
> > complexity.
> > 
> >>> On the other hand, the read-modify-write cycle in
> >>> piix4_setup_sb800_smba() is unsafe if 2 drivers can actually call
> >>> request_mem_region() on the same memory area successfully.
> >>>
> >>> I'm not opposed to taking your patch with minimal changes (as long as
> >>> the code is safe) and working on performance improvements later.
> >>
> > 
> > I confirmed through testing the request_mem_region() and request_muxed_region() 
> > macros provide exclusive locking. One difference between the 2 macros is the 
> > flag parameter, IORESOURCE_MUXED. request_muxed_region() uses the 
> > IORESOURCE_MUXED flag to retry the region lock if it's already locked. 
> > request_mem_region() does not use the IORESOURCE_MUXED and as a result will 
> > return -EBUSY immediately if the region is already locked.
> > 
> > I must clarify: the piix4_smbus v1 patch uses request_mem_region() which is not 
> > correct because it doesn't retry locking an already locked region.  The driver 
> > must support retrying the lock or piix4_smbus and sp5100_tco drivers may 
> > potentially fail loading. I added proposed piix4_smbus v2 changes below to solve.
> > 
> > I propose reusing the existing request_*() framework from include/linux/ioport.h 
> > and kernel/resource.c. A new helper macro will be required to provide an 
> > interface to the "muxed" iomem locking functionality already present in 
> > kernel/resource.c. The new macro will be similar to request_muxed_region() 
> > but will instead operate on iomem. This should provide the same performance 
> > while using the existing framework.
> > 
> > My plan is to add the following to include/linux/ioport.h in v2. This macro
> > will add the interface for using "muxed" iomem support:
> > #define request_mem_muxed_region(start,n,name)  __request_region(&iomem_resource, (start), (n), (name), IORESOURCE_MUXED)
> > 
> > The proposed changes will need review from more than one subsystem maintainer.
> > The macro addition in include/linux/ioport.h would reside in a
> > different maintainer's tree than this driver. The change to use the
> > request_mem_muxed_region() macro will also be made to the sp5100_tco driver.
> > The v2 review will include maintainers from subsystems owning piix4_smbus
> > driver, sp5100_tco driver, and include/linux/ioport.h.
> > 
> > The details provided above are described in a piix4_smbus context but would also be 
> > applied to the sp5100_tco driver for synchronizing the shared register.
> > 
> > Jean and Guenter, do you have concerns or changes you prefer to the proposal I 
> > described above? 
> > 
> >> I looked some more at the code. I was thinking that maybe if the
> >> registers accessed by the two drivers (i2c-piix4 and sp5100_tco) were
> >> disjoint, then each driver could simply request subsets of the mapped
> >> memory.
> >>
> >> Unfortunately, while most registers are indeed exclusively used by one
> >> of the drivers, there's one register (0x00 = IsaDecode) which is used
> >> by both. So this simple approach isn't possible.
> >>
> >> That being said, the register in question is only accessed at device
> >> initialization time (on the sp5100_tco side, that's in function
> >> sp5100_tco_setupdevice) and only for some devices (Embedded FCH). So
> >> one approach which may work is to let the i2c-piix4 driver instantiate
> >> the watchdog platform device in that case, instead of having sp5100_tco
> >> instantiate its own device as is currently the case. That way, the
> >> i2c-piix4 driver would request the "shared" memory area, perform the
> >> initialization steps for both functions (SMBus and watchdog) and then
> >> instantiate the watchdog device so that sp5100_tco gets loaded and goes
> >> on with the runtime management of the watchdog device.
> >>
> >> If I'm not mistaken, this is what the i2c-i801 driver is already doing
> >> for the watchdog device in all recent Intel chipsets. So maybe the same
> >> approach can work for the i2c-piix4 driver for the AMD chipsets.
> >> However I must confess that I did not try to do it nor am I familiar
> >> with the sp5100_tco driver details, so maybe it's not possible for some
> >> reason.
> >>
> >> If it's not possible then the only safe approach would be to migrate
> >> i2c-piix4 and sp5100_tco to a true MFD setup with 3 separate drivers:
> >> one new MFD PCI driver binding to the PCI device, providing access to
> >> the registers with proper locking, and instantiating the platform
> >> device, one driver for SMBus (basically i2c-piix4 converted to a
> >> platform driver and relying on the MFD driver for register access) and
> >> one driver for the watchdog (basically sp5100_tco converted to a
> >> platform driver and relying on the MFD driver for register access).
> >> That's a much larger change though, so I suppose we'd try avoid it if
> >> at all possible.
> >>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2022-01-06 13:01 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-15 22:18 [PATCH] i2c: piix4: Replace piix4_smbus driver's cd6h/cd7h port io accesses with mmio accesses Terry Bowman
2021-09-07 16:37 ` Jean Delvare
2021-11-05 16:05   ` Jean Delvare
2021-12-13 17:48     ` Terry Bowman
2022-01-04 19:34       ` Terry Bowman
2022-01-06 13:01         ` Wolfram Sang [this message]
2022-01-06 18:18         ` Guenter Roeck
2022-01-08 21:49           ` Wolfram Sang
2022-01-10 10:29             ` Andy Shevchenko
2022-01-11 12:39               ` Wolfram Sang
2022-01-11 14:13                 ` Terry Bowman
2022-01-11 14:53                   ` Andy Shevchenko
2022-01-11 14:54                     ` Andy Shevchenko
2022-01-11 15:50                       ` Terry Bowman
2022-01-11 16:17                         ` Andy Shevchenko
2022-01-12  0:40                           ` Terry Bowman
2022-01-13  7:42                         ` Wolfram Sang
2022-01-13 10:24                           ` Andy Shevchenko
2022-01-18 13:09                             ` Jean Delvare
2022-01-18 14:22       ` Jean Delvare
     [not found] <20210715221828.244536-1-Terry.Bowman () amd ! com>
2021-08-16 16:55 ` Terry Bowman
2021-08-16 17:03 ` Terry Bowman

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=YdboPCYlhExlLWhX@ninjato \
    --to=wsa@kernel.org \
    --cc=Terry.Bowman@amd.com \
    --cc=jdelvare@suse.de \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-watchdog@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=thomas.lendacky@amd.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;
as well as URLs for NNTP newsgroup(s).