Hardware spinlock class.
More...
Hardware spinlock class.
A hardware spinlock serializes processors that share registers or memory, where interrupt locks only serialize the code of one. A hardware spinlock controller is a struct pbl_hwspinlock_controller device holding a set of locks, each identified by a number. A consumer holds a struct pbl_hwspinlock, from its devicetree hwlocks, and takes it around the accesses it shares, in place of pbl_irq_lock(). Without one, PBL_HWSPINLOCK_NONE, taking it only locks interrupts:
if (ret != 0) {
return ret;
}
void pbl_hwspinlock_unlock(const struct pbl_hwspinlock *lock)
Release a lock taken with pbl_hwspinlock_lock(), then unlock interrupts.
int pbl_hwspinlock_lock(const struct pbl_hwspinlock *lock)
Lock interrupts, then take a lock, spinning while another processor holds it.
static void pbl_modifyl(uint32_t clear, uint32_t set, uintptr_t addr)
Atomically clear and set bits of a shared 32-bit register.
Definition mmio.h:134
Locks are usable before their controller is initialized, as for the pins of an early console.
◆ pbl_hwspinlock_controller
| struct pbl_hwspinlock_controller |
A hardware spinlock controller.
◆ pbl_hwspinlock
A hardware spinlock, as used by a consumer.
| Data Fields |
|
const struct pbl_hwspinlock_controller * |
ctrl |
Controller, NULL without a lock. |
|
uint32_t |
id |
Lock number on the controller. |
◆ PBL_HWSPINLOCK
| #define PBL_HWSPINLOCK |
( |
|
_ctrl, |
|
|
|
_id |
|
) |
| {.ctrl = (_ctrl), .id = (_id)} |
Initializer for a struct pbl_hwspinlock.
- Parameters
-
| _ctrl | Hardware spinlock controller. |
| _id | Lock number. |
◆ PBL_HWSPINLOCK_CONTROLLER_INIT
| #define PBL_HWSPINLOCK_CONTROLLER_INIT |
( |
|
sym, |
|
|
|
_name, |
|
|
|
_init, |
|
|
|
_parent, |
|
|
|
_ops, |
|
|
|
_num_locks |
|
) |
| |
Value: { \
.ops = (_ops), \
.num_locks = (_num_locks), \
}
#define PBL_DEVICE_INIT_CLASS(sym, _name, _init, _parent, _cls)
Initializer for the struct pbl_device of device instance sym, in class _cls.
Definition device.h:153
Initializer for the struct pbl_hwspinlock_controller of controller sym.
- Parameters
-
| sym | Symbol of the controller instance, with its state defined by PBL_HWSPINLOCK_CONTROLLER_STATE_DEFINE(). |
| _name | Name. |
| _init | Device init function, or NULL. |
| _parent | Parent device, or NULL. |
| _ops | Driver operations. |
| _num_locks | Number of locks. |
◆ PBL_HWSPINLOCK_CONTROLLER_STATE_DEFINE
Define the class state of hardware spinlock controller sym, for the driver's define macro.
- Parameters
-
| sym | Symbol of the controller instance. |
◆ PBL_HWSPINLOCK_NONE
| #define PBL_HWSPINLOCK_NONE {.ctrl = nullptr, .id = 0U} |
◆ pbl_hwspinlock_lock()
Lock interrupts, then take a lock, spinning while another processor holds it.
Holders keep a lock for a few register accesses: a lock held for longer than CONFIG_HWSPINLOCK_TIMEOUT_US belongs to a processor that stopped. On success, release it with pbl_hwspinlock_unlock().
- Parameters
-
| lock | Lock, or one without a lock, which only locks interrupts. |
- Return values
-
| 0 | On success, with interrupts locked. |
| -EINVAL | The lock is not one of its controller. |
| -ETIMEDOUT | Another processor held the lock for too long; interrupts are as they were. |
◆ pbl_hwspinlock_unlock()