2017-05-14 19:23:08 +02:00
|
|
|
===========================
|
2011-02-17 18:52:03 +01:00
|
|
|
Hardware Spinlock Framework
|
2017-05-14 19:23:08 +02:00
|
|
|
===========================
|
2011-02-17 18:52:03 +01:00
|
|
|
|
2017-05-14 19:23:08 +02:00
|
|
|
Introduction
|
|
|
|
============
|
2011-02-17 18:52:03 +01:00
|
|
|
|
|
|
|
Hardware spinlock modules provide hardware assistance for synchronization
|
|
|
|
and mutual exclusion between heterogeneous processors and those not operating
|
|
|
|
under a single, shared operating system.
|
|
|
|
|
|
|
|
For example, OMAP4 has dual Cortex-A9, dual Cortex-M3 and a C64x+ DSP,
|
|
|
|
each of which is running a different Operating System (the master, A9,
|
|
|
|
is usually running Linux and the slave processors, the M3 and the DSP,
|
|
|
|
are running some flavor of RTOS).
|
|
|
|
|
|
|
|
A generic hwspinlock framework allows platform-independent drivers to use
|
|
|
|
the hwspinlock device in order to access data structures that are shared
|
|
|
|
between remote processors, that otherwise have no alternative mechanism
|
|
|
|
to accomplish synchronization and mutual exclusion operations.
|
|
|
|
|
|
|
|
This is necessary, for example, for Inter-processor communications:
|
|
|
|
on OMAP4, cpu-intensive multimedia tasks are offloaded by the host to the
|
|
|
|
remote M3 and/or C64x+ slave processors (by an IPC subsystem called Syslink).
|
|
|
|
|
|
|
|
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 simple data structures 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
|
|
|
|
structure).
|
|
|
|
|
|
|
|
A common hwspinlock interface makes it possible to have generic, platform-
|
|
|
|
independent, drivers.
|
|
|
|
|
2017-05-14 19:23:08 +02:00
|
|
|
User API
|
|
|
|
========
|
|
|
|
|
|
|
|
::
|
2011-02-17 18:52:03 +01:00
|
|
|
|
|
|
|
struct hwspinlock *hwspin_lock_request(void);
|
2017-05-14 19:23:08 +02:00
|
|
|
|
|
|
|
Dynamically assign an hwspinlock and return its address, or NULL
|
|
|
|
in case an unused hwspinlock isn't available. Users of this
|
|
|
|
API will usually want to communicate the lock's id to the remote core
|
|
|
|
before it can be used to achieve synchronization.
|
|
|
|
|
|
|
|
Should be called from a process context (might sleep).
|
|
|
|
|
|
|
|
::
|
2011-02-17 18:52:03 +01:00
|
|
|
|
|
|
|
struct hwspinlock *hwspin_lock_request_specific(unsigned int id);
|
2017-05-14 19:23:08 +02:00
|
|
|
|
|
|
|
Assign a specific hwspinlock id and return its address, or NULL
|
|
|
|
if that hwspinlock is already in use. Usually board code will
|
|
|
|
be calling this function in order to reserve specific hwspinlock
|
|
|
|
ids for predefined purposes.
|
|
|
|
|
|
|
|
Should be called from a process context (might sleep).
|
|
|
|
|
|
|
|
::
|
2011-02-17 18:52:03 +01:00
|
|
|
|
2015-03-05 03:01:14 +01:00
|
|
|
int of_hwspin_lock_get_id(struct device_node *np, int index);
|
2017-05-14 19:23:08 +02:00
|
|
|
|
|
|
|
Retrieve the global lock id for an OF phandle-based specific lock.
|
|
|
|
This function provides a means for DT users of a hwspinlock module
|
|
|
|
to get the global lock id of a specific hwspinlock, so that it can
|
|
|
|
be requested using the normal hwspin_lock_request_specific() API.
|
|
|
|
|
|
|
|
The function returns a lock id number on success, -EPROBE_DEFER if
|
|
|
|
the hwspinlock device is not yet registered with the core, or other
|
|
|
|
error values.
|
|
|
|
|
|
|
|
Should be called from a process context (might sleep).
|
|
|
|
|
|
|
|
::
|
2015-03-05 03:01:14 +01:00
|
|
|
|
2011-02-17 18:52:03 +01:00
|
|
|
int hwspin_lock_free(struct hwspinlock *hwlock);
|
2017-05-14 19:23:08 +02:00
|
|
|
|
|
|
|
Free a previously-assigned hwspinlock; returns 0 on success, or an
|
|
|
|
appropriate error code on failure (e.g. -EINVAL if the hwspinlock
|
|
|
|
is already free).
|
|
|
|
|
|
|
|
Should be called from a process context (might sleep).
|
|
|
|
|
|
|
|
::
|
2011-02-17 18:52:03 +01:00
|
|
|
|
|
|
|
int hwspin_lock_timeout(struct hwspinlock *hwlock, unsigned int timeout);
|
2017-05-14 19:23:08 +02:00
|
|
|
|
|
|
|
Lock a previously-assigned hwspinlock with a timeout limit (specified in
|
|
|
|
msecs). If the hwspinlock is already taken, the function will busy loop
|
|
|
|
waiting for it to be released, but give up when the timeout elapses.
|
|
|
|
Upon a successful return from this function, preemption is disabled so
|
|
|
|
the caller must not sleep, and is advised to release the hwspinlock as
|
|
|
|
soon as possible, in order to minimize remote cores polling on the
|
|
|
|
hardware interconnect.
|
|
|
|
|
|
|
|
Returns 0 when successful and an appropriate error code otherwise (most
|
|
|
|
notably -ETIMEDOUT if the hwspinlock is still busy after timeout msecs).
|
|
|
|
The function will never sleep.
|
|
|
|
|
|
|
|
::
|
2011-02-17 18:52:03 +01:00
|
|
|
|
|
|
|
int hwspin_lock_timeout_irq(struct hwspinlock *hwlock, unsigned int timeout);
|
2017-05-14 19:23:08 +02:00
|
|
|
|
|
|
|
Lock a previously-assigned hwspinlock with a timeout limit (specified in
|
|
|
|
msecs). If the hwspinlock is already taken, the function will busy loop
|
|
|
|
waiting for it to be released, but give up when the timeout elapses.
|
|
|
|
Upon a successful return from this function, preemption and the local
|
|
|
|
interrupts are disabled, so the caller must not sleep, and is advised to
|
|
|
|
release the hwspinlock as soon as possible.
|
|
|
|
|
|
|
|
Returns 0 when successful and an appropriate error code otherwise (most
|
|
|
|
notably -ETIMEDOUT if the hwspinlock is still busy after timeout msecs).
|
|
|
|
The function will never sleep.
|
|
|
|
|
|
|
|
::
|
2011-02-17 18:52:03 +01:00
|
|
|
|
|
|
|
int hwspin_lock_timeout_irqsave(struct hwspinlock *hwlock, unsigned int to,
|
2017-05-14 19:23:08 +02:00
|
|
|
unsigned long *flags);
|
|
|
|
|
|
|
|
Lock a previously-assigned hwspinlock with a timeout limit (specified in
|
|
|
|
msecs). If the hwspinlock is already taken, the function will busy loop
|
|
|
|
waiting for it to be released, but give up when the timeout elapses.
|
|
|
|
Upon a successful return from this function, preemption is disabled,
|
|
|
|
local interrupts are disabled and their previous state is saved at the
|
|
|
|
given flags placeholder. The caller must not sleep, and is advised to
|
|
|
|
release the hwspinlock as soon as possible.
|
|
|
|
|
|
|
|
Returns 0 when successful and an appropriate error code otherwise (most
|
|
|
|
notably -ETIMEDOUT if the hwspinlock is still busy after timeout msecs).
|
|
|
|
|
|
|
|
The function will never sleep.
|
|
|
|
|
|
|
|
::
|
2011-02-17 18:52:03 +01:00
|
|
|
|
|
|
|
int hwspin_trylock(struct hwspinlock *hwlock);
|
2017-05-14 19:23:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
Attempt to lock a previously-assigned hwspinlock, but immediately fail if
|
|
|
|
it is already taken.
|
|
|
|
|
|
|
|
Upon a successful return from this function, preemption is disabled so
|
|
|
|
caller must not sleep, and is advised to release the hwspinlock as soon as
|
|
|
|
possible, in order to minimize remote cores polling on the hardware
|
|
|
|
interconnect.
|
|
|
|
|
|
|
|
Returns 0 on success and an appropriate error code otherwise (most
|
|
|
|
notably -EBUSY if the hwspinlock was already taken).
|
|
|
|
The function will never sleep.
|
|
|
|
|
|
|
|
::
|
2011-02-17 18:52:03 +01:00
|
|
|
|
|
|
|
int hwspin_trylock_irq(struct hwspinlock *hwlock);
|
2017-05-14 19:23:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
Attempt to lock a previously-assigned hwspinlock, but immediately fail if
|
|
|
|
it is already taken.
|
|
|
|
|
|
|
|
Upon a successful return from this function, preemption and the local
|
|
|
|
interrupts are disabled so caller must not sleep, and is advised to
|
|
|
|
release the hwspinlock as soon as possible.
|
|
|
|
|
|
|
|
Returns 0 on success and an appropriate error code otherwise (most
|
|
|
|
notably -EBUSY if the hwspinlock was already taken).
|
|
|
|
|
|
|
|
The function will never sleep.
|
|
|
|
|
|
|
|
::
|
2011-02-17 18:52:03 +01:00
|
|
|
|
|
|
|
int hwspin_trylock_irqsave(struct hwspinlock *hwlock, unsigned long *flags);
|
2017-05-14 19:23:08 +02:00
|
|
|
|
|
|
|
Attempt to lock a previously-assigned hwspinlock, but immediately fail if
|
|
|
|
it is already taken.
|
|
|
|
|
|
|
|
Upon a successful return from this function, preemption is disabled,
|
|
|
|
the local interrupts are disabled and their previous state is saved
|
|
|
|
at the given flags placeholder. The caller must not sleep, and is advised
|
|
|
|
to release the hwspinlock as soon as possible.
|
|
|
|
|
|
|
|
Returns 0 on success and an appropriate error code otherwise (most
|
|
|
|
notably -EBUSY if the hwspinlock was already taken).
|
|
|
|
The function will never sleep.
|
|
|
|
|
|
|
|
::
|
2011-02-17 18:52:03 +01:00
|
|
|
|
|
|
|
void hwspin_unlock(struct hwspinlock *hwlock);
|
2017-05-14 19:23:08 +02:00
|
|
|
|
|
|
|
Unlock a previously-locked hwspinlock. Always succeed, and can be called
|
|
|
|
from any context (the function never sleeps).
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
code should **never** unlock an hwspinlock which is already unlocked
|
|
|
|
(there is no protection against this).
|
|
|
|
|
|
|
|
::
|
2011-02-17 18:52:03 +01:00
|
|
|
|
|
|
|
void hwspin_unlock_irq(struct hwspinlock *hwlock);
|
2017-05-14 19:23:08 +02:00
|
|
|
|
|
|
|
Unlock a previously-locked hwspinlock and enable local interrupts.
|
|
|
|
The caller should **never** unlock an hwspinlock which is already unlocked.
|
|
|
|
|
|
|
|
Doing so is considered a bug (there is no protection against this).
|
|
|
|
Upon a successful return from this function, preemption and local
|
|
|
|
interrupts are enabled. This function will never sleep.
|
|
|
|
|
|
|
|
::
|
2011-02-17 18:52:03 +01:00
|
|
|
|
|
|
|
void
|
|
|
|
hwspin_unlock_irqrestore(struct hwspinlock *hwlock, unsigned long *flags);
|
2017-05-14 19:23:08 +02:00
|
|
|
|
|
|
|
Unlock a previously-locked hwspinlock.
|
|
|
|
|
|
|
|
The caller should **never** unlock an hwspinlock which is already unlocked.
|
|
|
|
Doing so is considered a bug (there is no protection against this).
|
|
|
|
Upon a successful return from this function, preemption is reenabled,
|
|
|
|
and the state of the local interrupts is restored to the state saved at
|
|
|
|
the given flags. This function will never sleep.
|
|
|
|
|
|
|
|
::
|
2011-02-17 18:52:03 +01:00
|
|
|
|
|
|
|
int hwspin_lock_get_id(struct hwspinlock *hwlock);
|
|
|
|
|
2017-05-14 19:23:08 +02:00
|
|
|
Retrieve id number of a given hwspinlock. This is needed when an
|
|
|
|
hwspinlock is dynamically assigned: before it can be used to achieve
|
|
|
|
mutual exclusion with a remote cpu, the id number should be communicated
|
|
|
|
to the remote task with which we want to synchronize.
|
|
|
|
|
|
|
|
Returns the hwspinlock id number, or -EINVAL if hwlock is null.
|
|
|
|
|
|
|
|
Typical usage
|
|
|
|
=============
|
2011-02-17 18:52:03 +01:00
|
|
|
|
2017-05-14 19:23:08 +02:00
|
|
|
::
|
2011-02-17 18:52:03 +01:00
|
|
|
|
2017-05-14 19:23:08 +02:00
|
|
|
#include <linux/hwspinlock.h>
|
|
|
|
#include <linux/err.h>
|
2011-02-17 18:52:03 +01:00
|
|
|
|
2017-05-14 19:23:08 +02:00
|
|
|
int hwspinlock_example1(void)
|
|
|
|
{
|
|
|
|
struct hwspinlock *hwlock;
|
|
|
|
int ret;
|
2011-02-17 18:52:03 +01:00
|
|
|
|
2017-05-14 19:23:08 +02:00
|
|
|
/* dynamically assign a hwspinlock */
|
|
|
|
hwlock = hwspin_lock_request();
|
|
|
|
if (!hwlock)
|
|
|
|
...
|
2011-02-17 18:52:03 +01:00
|
|
|
|
2017-05-14 19:23:08 +02:00
|
|
|
id = hwspin_lock_get_id(hwlock);
|
|
|
|
/* probably need to communicate id to a remote processor now */
|
|
|
|
|
|
|
|
/* take the lock, spin for 1 sec if it's already taken */
|
|
|
|
ret = hwspin_lock_timeout(hwlock, 1000);
|
|
|
|
if (ret)
|
|
|
|
...
|
|
|
|
|
|
|
|
/*
|
|
|
|
* we took the lock, do our thing now, but do NOT sleep
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* release the lock */
|
|
|
|
hwspin_unlock(hwlock);
|
|
|
|
|
|
|
|
/* free the lock */
|
|
|
|
ret = hwspin_lock_free(hwlock);
|
|
|
|
if (ret)
|
|
|
|
...
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int hwspinlock_example2(void)
|
|
|
|
{
|
|
|
|
struct hwspinlock *hwlock;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* assign a specific hwspinlock id - this should be called early
|
|
|
|
* by board init code.
|
|
|
|
*/
|
|
|
|
hwlock = hwspin_lock_request_specific(PREDEFINED_LOCK_ID);
|
|
|
|
if (!hwlock)
|
|
|
|
...
|
|
|
|
|
|
|
|
/* try to take it, but don't spin on it */
|
|
|
|
ret = hwspin_trylock(hwlock);
|
|
|
|
if (!ret) {
|
|
|
|
pr_info("lock is already taken\n");
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* we took the lock, do our thing now, but do NOT sleep
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* release the lock */
|
|
|
|
hwspin_unlock(hwlock);
|
|
|
|
|
|
|
|
/* free the lock */
|
|
|
|
ret = hwspin_lock_free(hwlock);
|
|
|
|
if (ret)
|
|
|
|
...
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
API for implementors
|
|
|
|
====================
|
|
|
|
|
|
|
|
::
|
2011-02-17 18:52:03 +01:00
|
|
|
|
hwspinlock/core: register a bank of hwspinlocks in a single API call
Hardware Spinlock devices usually contain numerous locks (known
devices today support between 32 to 256 locks).
Originally hwspinlock core required drivers to register (and later,
when needed, unregister) each lock separately.
That worked, but required hwspinlocks drivers to do a bit extra work
when they were probed/removed.
This patch changes hwspin_lock_{un}register() to allow a bank of
hwspinlocks to be {un}registered in a single invocation.
A new 'struct hwspinlock_device', which contains an array of 'struct
hwspinlock's is now being passed to the core upon registration (so
instead of wrapping each struct hwspinlock, a priv member has been added
to allow drivers to piggyback their private data with each hwspinlock).
While at it, several per-lock members were moved to be per-device:
1. struct device *dev
2. struct hwspinlock_ops *ops
In addition, now that the array of locks is handled by the core,
there's no reason to maintain a per-lock 'int id' member: the id of the
lock anyway equals to its index in the bank's array plus the bank's
base_id.
Remove this per-lock id member too, and instead use a simple pointers
arithmetic to derive it.
As a result of this change, hwspinlocks drivers are now simpler and smaller
(about %20 code reduction) and the memory footprint of the hwspinlock
framework is reduced.
Signed-off-by: Ohad Ben-Cohen <ohad@wizery.com>
2011-09-06 14:39:21 +02:00
|
|
|
int hwspin_lock_register(struct hwspinlock_device *bank, struct device *dev,
|
|
|
|
const struct hwspinlock_ops *ops, int base_id, int num_locks);
|
2017-05-14 19:23:08 +02:00
|
|
|
|
|
|
|
To be called from the underlying platform-specific implementation, in
|
|
|
|
order to register a new hwspinlock device (which is usually a bank of
|
|
|
|
numerous locks). Should be called from a process context (this function
|
|
|
|
might sleep).
|
|
|
|
|
|
|
|
Returns 0 on success, or appropriate error code on failure.
|
|
|
|
|
|
|
|
::
|
2011-02-17 18:52:03 +01:00
|
|
|
|
hwspinlock/core: register a bank of hwspinlocks in a single API call
Hardware Spinlock devices usually contain numerous locks (known
devices today support between 32 to 256 locks).
Originally hwspinlock core required drivers to register (and later,
when needed, unregister) each lock separately.
That worked, but required hwspinlocks drivers to do a bit extra work
when they were probed/removed.
This patch changes hwspin_lock_{un}register() to allow a bank of
hwspinlocks to be {un}registered in a single invocation.
A new 'struct hwspinlock_device', which contains an array of 'struct
hwspinlock's is now being passed to the core upon registration (so
instead of wrapping each struct hwspinlock, a priv member has been added
to allow drivers to piggyback their private data with each hwspinlock).
While at it, several per-lock members were moved to be per-device:
1. struct device *dev
2. struct hwspinlock_ops *ops
In addition, now that the array of locks is handled by the core,
there's no reason to maintain a per-lock 'int id' member: the id of the
lock anyway equals to its index in the bank's array plus the bank's
base_id.
Remove this per-lock id member too, and instead use a simple pointers
arithmetic to derive it.
As a result of this change, hwspinlocks drivers are now simpler and smaller
(about %20 code reduction) and the memory footprint of the hwspinlock
framework is reduced.
Signed-off-by: Ohad Ben-Cohen <ohad@wizery.com>
2011-09-06 14:39:21 +02:00
|
|
|
int hwspin_lock_unregister(struct hwspinlock_device *bank);
|
2011-02-17 18:52:03 +01:00
|
|
|
|
2017-05-14 19:23:08 +02:00
|
|
|
To be called from the underlying vendor-specific implementation, in order
|
|
|
|
to unregister an hwspinlock device (which is usually a bank of numerous
|
|
|
|
locks).
|
|
|
|
|
|
|
|
Should be called from a process context (this function might sleep).
|
|
|
|
|
|
|
|
Returns the address of hwspinlock on success, or NULL on error (e.g.
|
|
|
|
if the hwspinlock is still in use).
|
|
|
|
|
|
|
|
Important structs
|
|
|
|
=================
|
2011-02-17 18:52:03 +01:00
|
|
|
|
hwspinlock/core: register a bank of hwspinlocks in a single API call
Hardware Spinlock devices usually contain numerous locks (known
devices today support between 32 to 256 locks).
Originally hwspinlock core required drivers to register (and later,
when needed, unregister) each lock separately.
That worked, but required hwspinlocks drivers to do a bit extra work
when they were probed/removed.
This patch changes hwspin_lock_{un}register() to allow a bank of
hwspinlocks to be {un}registered in a single invocation.
A new 'struct hwspinlock_device', which contains an array of 'struct
hwspinlock's is now being passed to the core upon registration (so
instead of wrapping each struct hwspinlock, a priv member has been added
to allow drivers to piggyback their private data with each hwspinlock).
While at it, several per-lock members were moved to be per-device:
1. struct device *dev
2. struct hwspinlock_ops *ops
In addition, now that the array of locks is handled by the core,
there's no reason to maintain a per-lock 'int id' member: the id of the
lock anyway equals to its index in the bank's array plus the bank's
base_id.
Remove this per-lock id member too, and instead use a simple pointers
arithmetic to derive it.
As a result of this change, hwspinlocks drivers are now simpler and smaller
(about %20 code reduction) and the memory footprint of the hwspinlock
framework is reduced.
Signed-off-by: Ohad Ben-Cohen <ohad@wizery.com>
2011-09-06 14:39:21 +02:00
|
|
|
struct hwspinlock_device is a device which usually contains a bank
|
|
|
|
of hardware locks. It is registered by the underlying hwspinlock
|
|
|
|
implementation using the hwspin_lock_register() API.
|
2011-02-17 18:52:03 +01:00
|
|
|
|
2017-05-14 19:23:08 +02:00
|
|
|
::
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct hwspinlock_device - a device which usually spans numerous hwspinlocks
|
|
|
|
* @dev: underlying device, will be used to invoke runtime PM api
|
|
|
|
* @ops: platform-specific hwspinlock handlers
|
|
|
|
* @base_id: id index of the first lock in this device
|
|
|
|
* @num_locks: number of locks in this device
|
|
|
|
* @lock: dynamically allocated array of 'struct hwspinlock'
|
|
|
|
*/
|
|
|
|
struct hwspinlock_device {
|
|
|
|
struct device *dev;
|
|
|
|
const struct hwspinlock_ops *ops;
|
|
|
|
int base_id;
|
|
|
|
int num_locks;
|
|
|
|
struct hwspinlock lock[0];
|
|
|
|
};
|
hwspinlock/core: register a bank of hwspinlocks in a single API call
Hardware Spinlock devices usually contain numerous locks (known
devices today support between 32 to 256 locks).
Originally hwspinlock core required drivers to register (and later,
when needed, unregister) each lock separately.
That worked, but required hwspinlocks drivers to do a bit extra work
when they were probed/removed.
This patch changes hwspin_lock_{un}register() to allow a bank of
hwspinlocks to be {un}registered in a single invocation.
A new 'struct hwspinlock_device', which contains an array of 'struct
hwspinlock's is now being passed to the core upon registration (so
instead of wrapping each struct hwspinlock, a priv member has been added
to allow drivers to piggyback their private data with each hwspinlock).
While at it, several per-lock members were moved to be per-device:
1. struct device *dev
2. struct hwspinlock_ops *ops
In addition, now that the array of locks is handled by the core,
there's no reason to maintain a per-lock 'int id' member: the id of the
lock anyway equals to its index in the bank's array plus the bank's
base_id.
Remove this per-lock id member too, and instead use a simple pointers
arithmetic to derive it.
As a result of this change, hwspinlocks drivers are now simpler and smaller
(about %20 code reduction) and the memory footprint of the hwspinlock
framework is reduced.
Signed-off-by: Ohad Ben-Cohen <ohad@wizery.com>
2011-09-06 14:39:21 +02:00
|
|
|
|
|
|
|
struct hwspinlock_device contains an array of hwspinlock structs, each
|
2017-05-14 19:23:08 +02:00
|
|
|
of which represents a single hardware lock::
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct hwspinlock - this struct represents a single hwspinlock instance
|
|
|
|
* @bank: the hwspinlock_device structure which owns this lock
|
|
|
|
* @lock: initialized and used by hwspinlock core
|
|
|
|
* @priv: private data, owned by the underlying platform-specific hwspinlock drv
|
|
|
|
*/
|
|
|
|
struct hwspinlock {
|
|
|
|
struct hwspinlock_device *bank;
|
|
|
|
spinlock_t lock;
|
|
|
|
void *priv;
|
|
|
|
};
|
2011-02-17 18:52:03 +01:00
|
|
|
|
hwspinlock/core: register a bank of hwspinlocks in a single API call
Hardware Spinlock devices usually contain numerous locks (known
devices today support between 32 to 256 locks).
Originally hwspinlock core required drivers to register (and later,
when needed, unregister) each lock separately.
That worked, but required hwspinlocks drivers to do a bit extra work
when they were probed/removed.
This patch changes hwspin_lock_{un}register() to allow a bank of
hwspinlocks to be {un}registered in a single invocation.
A new 'struct hwspinlock_device', which contains an array of 'struct
hwspinlock's is now being passed to the core upon registration (so
instead of wrapping each struct hwspinlock, a priv member has been added
to allow drivers to piggyback their private data with each hwspinlock).
While at it, several per-lock members were moved to be per-device:
1. struct device *dev
2. struct hwspinlock_ops *ops
In addition, now that the array of locks is handled by the core,
there's no reason to maintain a per-lock 'int id' member: the id of the
lock anyway equals to its index in the bank's array plus the bank's
base_id.
Remove this per-lock id member too, and instead use a simple pointers
arithmetic to derive it.
As a result of this change, hwspinlocks drivers are now simpler and smaller
(about %20 code reduction) and the memory footprint of the hwspinlock
framework is reduced.
Signed-off-by: Ohad Ben-Cohen <ohad@wizery.com>
2011-09-06 14:39:21 +02:00
|
|
|
When registering a bank of locks, the hwspinlock driver only needs to
|
|
|
|
set the priv members of the locks. The rest of the members are set and
|
|
|
|
initialized by the hwspinlock core itself.
|
2011-02-17 18:52:03 +01:00
|
|
|
|
2017-05-14 19:23:08 +02:00
|
|
|
Implementation callbacks
|
|
|
|
========================
|
2011-02-17 18:52:03 +01:00
|
|
|
|
2017-05-14 19:23:08 +02:00
|
|
|
There are three possible callbacks defined in 'struct hwspinlock_ops'::
|
2011-02-17 18:52:03 +01:00
|
|
|
|
2017-05-14 19:23:08 +02:00
|
|
|
struct hwspinlock_ops {
|
|
|
|
int (*trylock)(struct hwspinlock *lock);
|
|
|
|
void (*unlock)(struct hwspinlock *lock);
|
|
|
|
void (*relax)(struct hwspinlock *lock);
|
|
|
|
};
|
2011-02-17 18:52:03 +01:00
|
|
|
|
|
|
|
The first two callbacks are mandatory:
|
|
|
|
|
|
|
|
The ->trylock() callback should make a single attempt to take the lock, and
|
2017-05-14 19:23:08 +02:00
|
|
|
return 0 on failure and 1 on success. This callback may **not** sleep.
|
2011-02-17 18:52:03 +01:00
|
|
|
|
|
|
|
The ->unlock() callback releases the lock. It always succeed, and it, too,
|
2017-05-14 19:23:08 +02:00
|
|
|
may **not** sleep.
|
2011-02-17 18:52:03 +01:00
|
|
|
|
|
|
|
The ->relax() callback is optional. It is called by hwspinlock core while
|
|
|
|
spinning on a lock, and can be used by the underlying implementation to force
|
2017-05-14 19:23:08 +02:00
|
|
|
a delay between two successive invocations of ->trylock(). It may **not** sleep.
|