From: ezequiel.garcia@free-electrons.com (Ezequiel Garcia)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v3 1/3] ARM: Introduce atomic MMIO modify
Date: Fri, 23 Aug 2013 08:28:54 -0300 [thread overview]
Message-ID: <20130823112853.GE2389@localhost> (raw)
In-Reply-To: <1377253445-2842-2-git-send-email-ezequiel.garcia@free-electrons.com>
On Fri, Aug 23, 2013 at 07:24:03AM -0300, Ezequiel Garcia 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.
>
> 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.
>
> We add relaxed and non-relaxed variants, by using writel_relaxed and writel,
> respectively. The rationale for this is that some users may not require
> register write completion but only thread-safe access to a register.
>
> Signed-off-by: Ezequiel Garcia <ezequiel.garcia@free-electrons.com>
> ---
> Based on a similar approach suggested by Russell King:
> http://archive.arm.linux.org.uk/lurker/message/20130618.113606.d7d4fe4b.en.html
>
> Changes from v2:
> * As suggested by Will Deacon, dropped the iowmb() barrier
> and use relaxed variants instead. See Will's explanation for
> details:
> http://www.spinics.net/lists/arm-kernel/msg268775.html
>
> * Use spin_{}_irqsave/restore to allow irq-context usage
> also suggested by Will Deacon.
>
> * Re-work the API semantics as proposed by Russell King.
>
> Changes from v1:
> * Added an io barrier iowmb() as suggested by Will Deacon,
> to ensure the writel gets completed before the spin_unlock().
>
> arch/arm/include/asm/io.h | 6 ++++++
> arch/arm/kernel/io.c | 29 +++++++++++++++++++++++++++++
> 2 files changed, 35 insertions(+)
>
> diff --git a/arch/arm/include/asm/io.h b/arch/arm/include/asm/io.h
> index d070741..27521e1 100644
> --- a/arch/arm/include/asm/io.h
> +++ b/arch/arm/include/asm/io.h
> @@ -36,6 +36,12 @@
> #define isa_bus_to_virt phys_to_virt
>
> /*
> + * Atomic MMIO-wide IO modify
> + */
> +extern void atomic_io_modify(void __iomem *reg, u32 mask, u32 set);
> +extern void atomic_io_modify_relaxed(void __iomem *reg, u32 mask, 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..651f1ad 100644
> --- a/arch/arm/kernel/io.c
> +++ b/arch/arm/kernel/io.c
> @@ -1,6 +1,35 @@
> #include <linux/export.h>
> #include <linux/types.h>
> #include <linux/io.h>
> +#include <linux/spinlock.h>
> +
> +static DEFINE_SPINLOCK(__io_lock);
> +
> +void atomic_io_modify_relaxed(void __iomem *reg, u32 mask, u32 set)
> +{
> + unsigned long flags;
> + u32 value;
> +
> + spin_lock_irqsave(&__io_lock, flags);
> + value = readl_relaxed(reg) & ~mask;
> + value |= (set & mask);
> + writel_relaxed(value, reg);
> + spin_unlock_irqrestore(&__io_lock, flags);
> +}
And before anyone else screams at me, here's another typo:
> +EXPORT_SYMBOL(atomic_io_modify);
> +
--
Ezequiel Garc?a, Free Electrons
Embedded Linux, Kernel and Android Engineering
http://free-electrons.com
next prev parent reply other threads:[~2013-08-23 11:28 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-23 10:24 [PATCH v3 0/3] Introduce atomic MMIO register modify Ezequiel Garcia
2013-08-23 10:24 ` [PATCH v3 1/3] ARM: Introduce atomic MMIO modify Ezequiel Garcia
2013-08-23 10:38 ` Baruch Siach
2013-08-23 11:07 ` Ezequiel Garcia
2013-08-23 11:32 ` Ezequiel Garcia
2013-08-23 11:48 ` Catalin Marinas
2013-08-30 9:08 ` Will Deacon
2013-08-30 9:15 ` Catalin Marinas
2013-08-30 9:20 ` Will Deacon
2013-08-30 10:03 ` Catalin Marinas
2013-08-30 20:08 ` Jason Gunthorpe
2013-08-30 22:18 ` Russell King - ARM Linux
2013-09-05 8:59 ` Gregory CLEMENT
2013-09-05 9:08 ` Will Deacon
2013-09-05 9:20 ` Gregory CLEMENT
2013-09-06 16:48 ` Jason Gunthorpe
2013-08-23 11:28 ` Ezequiel Garcia [this message]
2013-08-23 10:24 ` [PATCH v3 2/3] clocksource: orion: Use atomic access for shared registers Ezequiel Garcia
2013-08-23 10:38 ` Baruch Siach
2013-08-23 10:49 ` Ezequiel Garcia
2013-08-23 10:24 ` [PATCH v3 3/3] watchdog: " 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=20130823112853.GE2389@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 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).