LKML Archive on
help / color / mirror / Atom feed
From: Ohad Ben-Cohen <>
To: <>, <>,
Cc: Greg KH <>, Tony Lindgren <>,
	Benoit Cousson <>,
	Grant Likely <>,
	Suman Anna <>, Kevin Hilman <>,
	Arnd Bergmann <>, Paul Walmsley <>,
	Hari Kanigeri <>,
	Simon Que <>
Subject: [PATCH v4 0/4] Introduce hardware spinlock framework
Date: Mon, 31 Jan 2011 12:33:40 +0200	[thread overview]
Message-ID: <> (raw)

OMAP4 introduces a Hardware Spinlock device, which provides hardware
assistance for synchronization and mutual exclusion between heterogeneous
processors and those not operating under a single, shared operating system
(e.g. OMAP4 has dual Cortex-A9, dual Cortex-M3 and a C64x+ DSP).

The intention of this hardware device is to allow remote processors,
that have no alternative mechanism to accomplish synchronization and mutual
exclusion operations, to share resources (such as memory and/or any other
hardware resource).

This patch set adds hwspinlock framework that makes it possible
for drivers to use those hwspinlock devices and stay platform-independent.

Currently there are two use cases for this hwspinlock interface:

1. Inter-processor communications: on OMAP4, cpu-intensive multimedia
tasks are offloaded by the host to the remote M3 and/or C64x+ slave

To achieve fast message-based communications, a minimal kernel support
is needed to deliver messages arriving from a remote processor to the
appropriate user process.

This communication is based on a simple data structure that is shared between
the remote processors, and access to it is synchronized using the hwspinlock
module (remote processor directly places new messages in this shared data

2. On some OMAP4 boards, the I2C bus is shared between the A9 and the M3,
and the hwspinlock is used to synchronize access to it.

While (2) can get away with an omap-specific hwspinlock implementation,
(1) is by no means omap-specific, and a common hwspinlock interface is
needed to keep it generic, in hopes that it will be useful for other
platforms as well.

Additional users, besides OMAP4:

* Davinci Netra (DM8168) has the same hwspinlock device, and will probably
use the same host implementation (this is untested since hardware is
not available yet, but the specs looks identical).

* Platforms (such as omap3530 and omapl1xx) that have no such hardware
support, but would still need to achieve multi-core synchronization (to
communicate with their DSP).

The only way to achieve mutual exclusion on those platforms is by
using a shared-memory synchronization algorithm such as Peterson's

We would still need the same hwspinlock framework for that - the busy
looping, the timeout, the various locking schemes, the lock resource
allocation - are all still valid. The only difference would be the
actual lock implementation, therefore we will add another host
implementation for these platforms.

* The C6474, a multi-core DSP device, have Linux running on one
of its cores, and hardware support for synchronization (the C6474
has a richer hardware module that would need more than the hwspinlock
framework offer today - it also supports queuing, owner semantics and
interrupt notification to let a processor know when it acquires a
lock, so it wouldn't have to spin..).  Disclaimer: it will probably
take some time until c6x support is merged upstream, but this is
something that is being actively worked on. For additional information,
see and

- Rebased to 2.6.38-rc2
- Added Tony's Acked-by
- Use hweight (akpm)

- Remove the timeout-less _lock API variant (Tony)
- s/state->io_base/io_base/ (Ionut)
- Remove the "generic" wording (David)
- s/hwspinlock_/hwspin_lock_/ (Mugdha)
- Use MAX_SCHEDULE_TIMEOUT to indicate no timeout (Mugdha)
- Be more verbose on egregious API misuse (Olof)
- locking API misuse is BUG_ON material (Russell)

  Note: Russell also suggested compiling out NULL checks on ARM.
  I've posted an initial proposal for this (see, which I'm going to resubmit
  separately. If accepted, I'll adopt hwspinlocks to use it.

- Convert to a generic interface (Tony)
- API should silently succeed if framework isn't built (Greg)
- Don't use ERR_PTR pattern (Grant)
- Use tristate, fix and extend commentary (Kevin)
- Provide API flexibility regarding irq handling (Arnd, Grant)

  Note: after reviewing OMAP's L4 access times, and comparing them with
  external memory latencies, I can say that there is no notable difference.
  Because of that, we can safely treat the hwspinlock like we do
  with regular spinlocks: preemption should be disabled, but whether
  to disable interrupts or not is up to the caller.

  So despite the TRM's recommendation to always disable local interrupts
  when taking an OMAP Hardware Spinlock, I have decided to allow callers
  not to do that (by providing the full extent of hwspin_lock(),
  hwspin_lock_irq() and hwspin_lock_irqsave() API).

  Just like regular spinlocks, it's up to the callers to decide whether
  interrupts should be disabled or not.

  Sleeping, btw, is still prohibited of course.


Previous versions of an omap-specific hwspinlock driver circulated in
linux-omap several times, and received substantial attention and contribution
from many developers (see [1][2][3][4][5][6]):

Simon Que did the initial implementation and pushed several iterations
Benoit Cousson provided extensive review, help, improvements and hwmod support
Hari Kanigeri helped out when Simon was away
Sanjeev Premi, Santosh Shilimkar and Nishanth Menon did lots of review

I'd like to thank Benoit Cousson, Steve Krueger, Hari Kanigeri,
Nourredine Hamoudi and Richard Woodruff for useful discussions about
the OMAP Spinlock requirements and use-cases.

Relevant linux-omap threads:


Benoit Cousson (1):
  OMAP4: hwmod data: Add hwspinlock

Ohad Ben-Cohen (1):
  drivers: hwspinlock: add framework

Simon Que (2):
  drivers: hwspinlock: add OMAP implementation
  omap: add hwspinlock device

 Documentation/hwspinlock.txt               |  299 +++++++++++++++
 arch/arm/mach-omap2/Makefile               |    1 +
 arch/arm/mach-omap2/hwspinlock.c           |   63 ++++
 arch/arm/mach-omap2/omap_hwmod_44xx_data.c |   63 ++++
 drivers/Kconfig                            |    2 +
 drivers/Makefile                           |    2 +
 drivers/hwspinlock/Kconfig                 |   22 ++
 drivers/hwspinlock/Makefile                |    6 +
 drivers/hwspinlock/hwspinlock.h            |   61 +++
 drivers/hwspinlock/hwspinlock_core.c       |  557 ++++++++++++++++++++++++++++
 drivers/hwspinlock/omap_hwspinlock.c       |  231 ++++++++++++
 include/linux/hwspinlock.h                 |  298 +++++++++++++++
 12 files changed, 1605 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/hwspinlock.txt
 create mode 100644 arch/arm/mach-omap2/hwspinlock.c
 create mode 100644 drivers/hwspinlock/Kconfig
 create mode 100644 drivers/hwspinlock/Makefile
 create mode 100644 drivers/hwspinlock/hwspinlock.h
 create mode 100644 drivers/hwspinlock/hwspinlock_core.c
 create mode 100644 drivers/hwspinlock/omap_hwspinlock.c
 create mode 100644 include/linux/hwspinlock.h

             reply	other threads:[~2011-01-31 10:34 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-31 10:33 Ohad Ben-Cohen [this message]
2011-01-31 10:33 ` [PATCH v4 1/4] drivers: hwspinlock: add framework Ohad Ben-Cohen
2011-01-31 23:38   ` Andrew Morton
2011-02-01  6:20     ` Ohad Ben-Cohen
2011-02-01  6:38       ` Andrew Morton
2011-02-01  7:36         ` Ohad Ben-Cohen
2011-02-01  7:40           ` Andrew Morton
2011-02-01  8:12             ` Ohad Ben-Cohen
2011-02-02 12:11               ` Russell King - ARM Linux
2011-02-04  1:47                 ` Tony Lindgren
2011-02-01 14:17         ` Greg KH
2011-02-01 15:34   ` Arnd Bergmann
2011-01-31 10:33 ` [PATCH v4 2/4] drivers: hwspinlock: add OMAP implementation Ohad Ben-Cohen
2011-01-31 10:33 ` [PATCH v4 3/4] OMAP4: hwmod data: Add hwspinlock Ohad Ben-Cohen
2011-01-31 10:33 ` [PATCH v4 4/4] omap: add hwspinlock device Ohad Ben-Cohen

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:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \
    --subject='Re: [PATCH v4 0/4] Introduce hardware spinlock framework' \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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).