All of lore.kernel.org
 help / color / mirror / Atom feed
From: ezequiel.garcia@free-electrons.com (Ezequiel Garcia)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 1/3] ARM: Introduce atomic MMIO clear/set
Date: Sat, 10 Aug 2013 11:09:28 -0300	[thread overview]
Message-ID: <20130810140927.GC3080@localhost> (raw)
In-Reply-To: <20130810140237.GB3080@localhost>

On Sat, Aug 10, 2013 at 11:02:38AM -0300, Ezequiel Garcia wrote:
> On Sat, Aug 10, 2013 at 04:49:28PM +0400, Alexander Shiyan wrote:
> > > Some SoC have MMIO regions that are shared across orthogonal
> > > subsystems. This commit implements a possible solution for the
> > > thread-safe access of such regions through a spinlock-protected API
> > > with clear-set semantics.
> > > 
> > > Concurrent access is protected with a single spinlock for the
> > > entire MMIO address space. While this protects shared-registers,
> > > it also serializes access to unrelated/unshared registers.
> > > 
> > > Signed-off-by: Ezequiel Garcia <ezequiel.garcia@free-electrons.com>
> > > ---
> > >  arch/arm/include/asm/io.h |  5 +++++
> > >  arch/arm/kernel/io.c      | 24 ++++++++++++++++++++++++
> > >  2 files changed, 29 insertions(+)
> > > 
> > > diff --git a/arch/arm/include/asm/io.h b/arch/arm/include/asm/io.h
> > > index d070741..c84658d 100644
> > > --- a/arch/arm/include/asm/io.h
> > > +++ b/arch/arm/include/asm/io.h
> > > @@ -36,6 +36,11 @@
> > >  #define isa_bus_to_virt phys_to_virt
> > >  
> > >  /*
> > > + * Atomic MMIO-wide IO clear/set
> > > + */
> > > +extern void atomic_io_clear_set(void __iomem *reg, u32 clear, u32 set);
> > > +
> > > +/*
> > >   * Generic IO read/write.  These perform native-endian accesses.  Note
> > >   * that some architectures will want to re-define __raw_{read,write}w.
> > >   */
> > > diff --git a/arch/arm/kernel/io.c b/arch/arm/kernel/io.c
> > > index dcd5b4d..3ab8201 100644
> > > --- a/arch/arm/kernel/io.c
> > > +++ b/arch/arm/kernel/io.c
> > > @@ -1,6 +1,30 @@
> > >  #include <linux/export.h>
> > >  #include <linux/types.h>
> > >  #include <linux/io.h>
> > > +#include <linux/spinlock.h>
> > > +
> > > +static DEFINE_SPINLOCK(__io_lock);
> > > +
> > > +/*
> > > + * Some platforms have MMIO regions that are shared across orthogonal
> > > + * subsystems. This API implements thread-safe access to such regions
> > > + * through a spinlock-protected API with clear-set semantics.
> > > + *
> > > + * Concurrent access is protected with a single spinlock for the entire MMIO
> > > + * address space. While this protects shared-registers, it also serializes
> > > + * access to unrelated/unshared registers.
> > > + *
> > > + * Using this API on frequently accessed registers in performance-critical
> > > + * paths is not recommended, as the spinlock used by this API would become
> > > + * highly contended.
> > > + */
> > > +void atomic_io_clear_set(void __iomem *reg, u32 clear, u32 set)
> > > +{
> > > +	spin_lock(&__io_lock);
> > > +	writel((readl(reg) & ~clear) | set, reg);
> > > +	spin_unlock(&__io_lock);
> > > +}
> > > +EXPORT_SYMBOL(atomic_io_clear_set);
> > 
> > So, one lock is used to all possible registers?
> > Seems a regmap-mmio can be used for such access.
> > 
> 
> Thanks for the hint! Quite frankly, I wasn't familiar with regmap-mmio.
> 
> However, after reading some code, I fail to see how that helps in this case.
> 
> Note that we need to access the *same* MMIO address from completely
> different (and unrelated) drivers, such as watchdog and clocksource.
> 
> So I wonder who would "own" the regmap descriptor, and how does the other
> one gets aware of that descriptor?
> 
> In addition given we can use orion_wdt (originally meant for mach-kirkwood)
> to support mvebu SoC watchdog, we need to sort this out in a completely
> multiplatform capable way.
> 
> Ideas?

Answering myself...

How about using drivers/mfd/syscon.c to create the regmap owner for the shared
register (TIMER_CTRL in this case, but others might appear) ?

Or adding a new mfd implementation if syscon does not fit ?

Does this sound like an overkill ?

-- 
Ezequiel Garc?a, Free Electrons
Embedded Linux, Kernel and Android Engineering
http://free-electrons.com

WARNING: multiple messages have this Message-ID (diff)
From: Ezequiel Garcia <ezequiel.garcia@free-electrons.com>
To: Alexander Shiyan <shc_work@mail.ru>
Cc: linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, Lior Amsalem <alior@marvell.com>,
	Thomas Petazzoni <thomas.petazzoni@free-electrons.com>,
	Russell King <linux@arm.linux.org.uk>,
	Jason Cooper <jason@lakedaemon.net>, Andrew Lunn <andrew@lunn.ch>,
	Gregory Clement <gregory.clement@free-electrons.com>,
	Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
Subject: Re: [PATCH 1/3] ARM: Introduce atomic MMIO clear/set
Date: Sat, 10 Aug 2013 11:09:28 -0300	[thread overview]
Message-ID: <20130810140927.GC3080@localhost> (raw)
In-Reply-To: <20130810140237.GB3080@localhost>

On Sat, Aug 10, 2013 at 11:02:38AM -0300, Ezequiel Garcia wrote:
> On Sat, Aug 10, 2013 at 04:49:28PM +0400, Alexander Shiyan wrote:
> > > Some SoC have MMIO regions that are shared across orthogonal
> > > subsystems. This commit implements a possible solution for the
> > > thread-safe access of such regions through a spinlock-protected API
> > > with clear-set semantics.
> > > 
> > > Concurrent access is protected with a single spinlock for the
> > > entire MMIO address space. While this protects shared-registers,
> > > it also serializes access to unrelated/unshared registers.
> > > 
> > > Signed-off-by: Ezequiel Garcia <ezequiel.garcia@free-electrons.com>
> > > ---
> > >  arch/arm/include/asm/io.h |  5 +++++
> > >  arch/arm/kernel/io.c      | 24 ++++++++++++++++++++++++
> > >  2 files changed, 29 insertions(+)
> > > 
> > > diff --git a/arch/arm/include/asm/io.h b/arch/arm/include/asm/io.h
> > > index d070741..c84658d 100644
> > > --- a/arch/arm/include/asm/io.h
> > > +++ b/arch/arm/include/asm/io.h
> > > @@ -36,6 +36,11 @@
> > >  #define isa_bus_to_virt phys_to_virt
> > >  
> > >  /*
> > > + * Atomic MMIO-wide IO clear/set
> > > + */
> > > +extern void atomic_io_clear_set(void __iomem *reg, u32 clear, u32 set);
> > > +
> > > +/*
> > >   * Generic IO read/write.  These perform native-endian accesses.  Note
> > >   * that some architectures will want to re-define __raw_{read,write}w.
> > >   */
> > > diff --git a/arch/arm/kernel/io.c b/arch/arm/kernel/io.c
> > > index dcd5b4d..3ab8201 100644
> > > --- a/arch/arm/kernel/io.c
> > > +++ b/arch/arm/kernel/io.c
> > > @@ -1,6 +1,30 @@
> > >  #include <linux/export.h>
> > >  #include <linux/types.h>
> > >  #include <linux/io.h>
> > > +#include <linux/spinlock.h>
> > > +
> > > +static DEFINE_SPINLOCK(__io_lock);
> > > +
> > > +/*
> > > + * Some platforms have MMIO regions that are shared across orthogonal
> > > + * subsystems. This API implements thread-safe access to such regions
> > > + * through a spinlock-protected API with clear-set semantics.
> > > + *
> > > + * Concurrent access is protected with a single spinlock for the entire MMIO
> > > + * address space. While this protects shared-registers, it also serializes
> > > + * access to unrelated/unshared registers.
> > > + *
> > > + * Using this API on frequently accessed registers in performance-critical
> > > + * paths is not recommended, as the spinlock used by this API would become
> > > + * highly contended.
> > > + */
> > > +void atomic_io_clear_set(void __iomem *reg, u32 clear, u32 set)
> > > +{
> > > +	spin_lock(&__io_lock);
> > > +	writel((readl(reg) & ~clear) | set, reg);
> > > +	spin_unlock(&__io_lock);
> > > +}
> > > +EXPORT_SYMBOL(atomic_io_clear_set);
> > 
> > So, one lock is used to all possible registers?
> > Seems a regmap-mmio can be used for such access.
> > 
> 
> Thanks for the hint! Quite frankly, I wasn't familiar with regmap-mmio.
> 
> However, after reading some code, I fail to see how that helps in this case.
> 
> Note that we need to access the *same* MMIO address from completely
> different (and unrelated) drivers, such as watchdog and clocksource.
> 
> So I wonder who would "own" the regmap descriptor, and how does the other
> one gets aware of that descriptor?
> 
> In addition given we can use orion_wdt (originally meant for mach-kirkwood)
> to support mvebu SoC watchdog, we need to sort this out in a completely
> multiplatform capable way.
> 
> Ideas?

Answering myself...

How about using drivers/mfd/syscon.c to create the regmap owner for the shared
register (TIMER_CTRL in this case, but others might appear) ?

Or adding a new mfd implementation if syscon does not fit ?

Does this sound like an overkill ?

-- 
Ezequiel García, Free Electrons
Embedded Linux, Kernel and Android Engineering
http://free-electrons.com

  reply	other threads:[~2013-08-10 14:09 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-10 12:42 [PATCH 0/3] Introduce atomic MMIO register clear-set Ezequiel Garcia
2013-08-10 12:42 ` Ezequiel Garcia
2013-08-10 12:43 ` [PATCH 1/3] ARM: Introduce atomic MMIO clear/set Ezequiel Garcia
2013-08-10 12:43   ` Ezequiel Garcia
2013-08-10 12:49   ` Alexander Shiyan
2013-08-10 12:49     ` Alexander Shiyan
2013-08-10 14:02     ` Ezequiel Garcia
2013-08-10 14:02       ` Ezequiel Garcia
2013-08-10 14:09       ` Ezequiel Garcia [this message]
2013-08-10 14:09         ` Ezequiel Garcia
2013-08-10 15:43         ` Alexander Shiyan
2013-08-10 15:43           ` Alexander Shiyan
2013-08-10 15:55           ` Ezequiel Garcia
2013-08-10 15:55             ` Ezequiel Garcia
2013-08-12 15:46             ` Ezequiel Garcia
2013-08-12 15:46               ` Ezequiel Garcia
2013-08-12 16:44               ` Sebastian Hesselbarth
2013-08-12 16:44                 ` Sebastian Hesselbarth
2013-08-12 17:09                 ` Ezequiel Garcia
2013-08-12 17:09                   ` Ezequiel Garcia
2013-08-12 18:29   ` Will Deacon
2013-08-12 18:29     ` Will Deacon
2013-08-19 16:59     ` Ezequiel Garcia
2013-08-19 16:59       ` Ezequiel Garcia
2013-08-20 14:32       ` Matt Sealey
2013-08-20 14:32         ` Matt Sealey
2013-08-20 14:52         ` Ezequiel Garcia
2013-08-20 14:52           ` Ezequiel Garcia
2013-08-20 15:04           ` Will Deacon
2013-08-20 15:04             ` Will Deacon
2013-08-10 12:43 ` [PATCH 2/3] clocksource: orion: Use atomic access for shared registers Ezequiel Garcia
2013-08-10 12:43   ` Ezequiel Garcia
2013-08-10 12:43 ` [PATCH 3/3] watchdog: " Ezequiel Garcia
2013-08-10 12:43   ` Ezequiel Garcia

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=20130810140927.GC3080@localhost \
    --to=ezequiel.garcia@free-electrons.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.