linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: ezequiel.garcia@free-electrons.com (Ezequiel Garcia)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v4 1/4] lib: Introduce atomic MMIO modify
Date: Sat, 24 Aug 2013 17:49:13 -0300	[thread overview]
Message-ID: <20130824204912.GA9456@localhost> (raw)
In-Reply-To: <52191916.4080600@nod.at>

On Sat, Aug 24, 2013 at 10:35:34PM +0200, Richard Weinberger wrote:
> Am 24.08.2013 21:58, schrieb Ezequiel Garcia:
> > On Sat, Aug 24, 2013 at 08:27:10PM +0200, richard -rw- weinberger wrote:
> >> On Sat, Aug 24, 2013 at 5:35 PM, Ezequiel Garcia
> >> <ezequiel.garcia@free-electrons.com> wrote:
> >>> Some platforms 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.
> >>>
> >>> Signed-off-by: Ezequiel Garcia <ezequiel.garcia@free-electrons.com>
> >>> ---
> >>>  include/linux/io.h |  5 +++++
> >>>  lib/Makefile       |  2 +-
> >>>  lib/atomicio.c     | 27 +++++++++++++++++++++++++++
> >>>  3 files changed, 33 insertions(+), 1 deletion(-)
> >>>  create mode 100644 lib/atomicio.c
> >>>
> >>> diff --git a/include/linux/io.h b/include/linux/io.h
> >>> index f4f42fa..c331dcb 100644
> >>> --- a/include/linux/io.h
> >>> +++ b/include/linux/io.h
> >>> @@ -101,4 +101,9 @@ static inline void arch_phys_wc_del(int handle)
> >>>  #define arch_phys_wc_add arch_phys_wc_add
> >>>  #endif
> >>>
> >>> +#ifndef __HAVE_ARCH_ATOMIC_IO_MODIFY
> >>> +/* Atomic MMIO-wide IO modify */
> >>> +extern void atomic_io_modify(void __iomem *reg, u32 mask, u32 set);
> >>> +#endif
> >>> +
> >>>  #endif /* _LINUX_IO_H */
> >>> diff --git a/lib/Makefile b/lib/Makefile
> >>> index 7baccfd..695d6e2 100644
> >>> --- a/lib/Makefile
> >>> +++ b/lib/Makefile
> >>> @@ -13,7 +13,7 @@ lib-y := ctype.o string.o vsprintf.o cmdline.o \
> >>>          sha1.o md5.o irq_regs.o reciprocal_div.o argv_split.o \
> >>>          proportions.o flex_proportions.o prio_heap.o ratelimit.o show_mem.o \
> >>>          is_single_threaded.o plist.o decompress.o kobject_uevent.o \
> >>> -        earlycpio.o percpu-refcount.o
> >>> +        earlycpio.o percpu-refcount.o atomicio.o
> >>>
> >>>  obj-$(CONFIG_ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS) += usercopy.o
> >>>  lib-$(CONFIG_MMU) += ioremap.o
> >>> diff --git a/lib/atomicio.c b/lib/atomicio.c
> >>> new file mode 100644
> >>> index 0000000..1750f9d
> >>> --- /dev/null
> >>> +++ b/lib/atomicio.c
> >>> @@ -0,0 +1,27 @@
> >>> +#include <linux/io.h>
> >>> +#include <linux/spinlock.h>
> >>> +
> >>> +#ifndef __HAVE_ARCH_ATOMIC_IO_MODIFY
> >>> +/*
> >>> + * Generic atomic MMIO modify.
> >>> + *
> >>> + * Allows thread-safe access to registers shared by unrelated subsystems.
> >>> + * The access is protected by a single MMIO-wide lock.
> >>> + *
> >>> + * Optimized variants can be implemented on a per-architecture basis.
> >>> + */
> >>> +static DEFINE_RAW_SPINLOCK(__io_lock);
> >>> +void atomic_io_modify(void __iomem *reg, u32 mask, u32 set)
> >>> +{
> >>> +       unsigned long flags;
> >>> +       u32 value;
> >>> +
> >>> +       raw_spin_lock_irqsave(&__io_lock, flags);
> >>> +       value = readl(reg) & ~mask;
> >>> +       value |= (set & mask);
> >>> +       writel(value, reg);
> >>> +       raw_spin_unlock_irqrestore(&__io_lock, flags);
> >>> +
> >>> +}
> >>> +EXPORT_SYMBOL(atomic_io_modify);
> >>
> >> Why not the default case EXPORT_SYMBOL_GPL()?
> >>
> > 
> > Because I copy-pasted the export from some other lib/.. :-)
> > 
> > Mind explaining me the difference, why you say _GPL it's the default,
> > and why EXPORT_SYMBOL is more frequently used in lib/ ?
> 
> As the kernel is GPL it is the default case to mark new things as GPL symbols.
> If your new feature is a core feature which is used by mostly everyone, EXPORT_SYMBOL()
> is appropriate.
> I.e. having kmalloc() and friends EXPORT_SYMBOL_GPL() would be a bad idea. :)
> EXPORT_SYMBOL() seems to be often used in lib/ because most lib/ things are core features.
> 

In that case, EXPORT_SYMBOL is certainly the most appropriate one,
for the reasons you stated above.
-- 
Ezequiel Garc?a, Free Electrons
Embedded Linux, Kernel and Android Engineering
http://free-electrons.com

  reply	other threads:[~2013-08-24 20:49 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-24 15:35 [PATCH v4 0/4] Introduce atomic MMIO modify Ezequiel Garcia
2013-08-24 15:35 ` [PATCH v4 1/4] lib: " Ezequiel Garcia
2013-08-24 18:27   ` richard -rw- weinberger
2013-08-24 19:58     ` Ezequiel Garcia
2013-08-24 20:35       ` Richard Weinberger
2013-08-24 20:49         ` Ezequiel Garcia [this message]
2013-08-24 20:53           ` Richard Weinberger
2013-08-24 23:15       ` Russell King - ARM Linux
2013-08-27 14:37   ` Ezequiel Garcia
2013-08-27 20:37   ` Andrew Morton
2013-08-28 10:24     ` Ezequiel Garcia
2013-08-28 19:33       ` Andrew Morton
2013-08-29  8:03         ` Thomas Petazzoni
2013-08-28 10:37   ` Ezequiel Garcia
2013-08-28 16:16     ` Linus Torvalds
2013-08-24 15:35 ` [PATCH v4 2/4] ARM: Add atomic_io_modify optimized routines Ezequiel Garcia
2013-08-28  8:53   ` Catalin Marinas
2013-08-28  9:49     ` Ezequiel Garcia
2013-08-28 10:01       ` Thomas Petazzoni
2013-08-28 11:39         ` Catalin Marinas
2013-08-24 15:35 ` [PATCH v4 3/4] clocksource: orion: Use atomic access for shared registers Ezequiel Garcia
2013-08-24 15:35 ` [PATCH v4 4/4] 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=20130824204912.GA9456@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).