PebbleOS v4.47.0-1075-g013613c8a
Loading...
Searching...
No Matches
Hardware spinlock

Hardware spinlock class. More...

Data Structures

struct  pbl_hwspinlock_controller_ops
 Hardware spinlock controller driver operations, called with interrupts locked. More...
 
struct  pbl_hwspinlock_controller
 A hardware spinlock controller. More...
 
struct  pbl_hwspinlock
 A hardware spinlock, as used by a consumer. More...
 

Macros

#define PBL_HWSPINLOCK_CONTROLLER_STATE_DEFINE(sym)   PBL_DEVICE_STATE_DEFINE(sym)
 Define the class state of hardware spinlock controller sym, for the driver's define macro.
 
#define PBL_HWSPINLOCK_CONTROLLER_INIT(sym, _name, _init, _parent, _ops, _num_locks)
 Initializer for the struct pbl_hwspinlock_controller of controller sym.
 
#define PBL_HWSPINLOCK(_ctrl, _id)   {.ctrl = (_ctrl), .id = (_id)}
 Initializer for a struct pbl_hwspinlock.
 
#define PBL_HWSPINLOCK_NONE   {.ctrl = nullptr, .id = 0U}
 Initializer for a struct pbl_hwspinlock without a lock.
 

Functions

int pbl_hwspinlock_lock (const struct pbl_hwspinlock *lock)
 Lock interrupts, then take a lock, spinning while another processor holds it.
 
void pbl_hwspinlock_unlock (const struct pbl_hwspinlock *lock)
 Release a lock taken with pbl_hwspinlock_lock(), then unlock interrupts.
 

Detailed Description

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:

int ret = pbl_hwspinlock_lock(&ctrl->hwlock);
if (ret != 0) {
return ret;
}
pbl_modifyl(mask, value, reg);
pbl_hwspinlock_unlock(&ctrl->hwlock);
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.


Data Structure Documentation

◆ pbl_hwspinlock_controller

struct pbl_hwspinlock_controller

A hardware spinlock controller.

Data Fields
struct pbl_device dev Device.
uint16_t num_locks Number of locks.
const struct pbl_hwspinlock_controller_ops * ops Driver operations.

◆ pbl_hwspinlock

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

Macro Definition Documentation

◆ PBL_HWSPINLOCK

#define PBL_HWSPINLOCK (   _ctrl,
  _id 
)    {.ctrl = (_ctrl), .id = (_id)}

Initializer for a struct pbl_hwspinlock.

Parameters
_ctrlHardware spinlock controller.
_idLock number.

◆ PBL_HWSPINLOCK_CONTROLLER_INIT

#define PBL_HWSPINLOCK_CONTROLLER_INIT (   sym,
  _name,
  _init,
  _parent,
  _ops,
  _num_locks 
)
Value:
{ \
.dev = PBL_DEVICE_INIT_CLASS(sym, _name, _init, _parent, &pbl_hwspinlock_controller_class), \
.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
symSymbol of the controller instance, with its state defined by PBL_HWSPINLOCK_CONTROLLER_STATE_DEFINE().
_nameName.
_initDevice init function, or NULL.
_parentParent device, or NULL.
_opsDriver operations.
_num_locksNumber of locks.

◆ PBL_HWSPINLOCK_CONTROLLER_STATE_DEFINE

#define PBL_HWSPINLOCK_CONTROLLER_STATE_DEFINE (   sym)    PBL_DEVICE_STATE_DEFINE(sym)

Define the class state of hardware spinlock controller sym, for the driver's define macro.

Parameters
symSymbol of the controller instance.

◆ PBL_HWSPINLOCK_NONE

#define PBL_HWSPINLOCK_NONE   {.ctrl = nullptr, .id = 0U}

Initializer for a struct pbl_hwspinlock without a lock.

Function Documentation

◆ pbl_hwspinlock_lock()

int pbl_hwspinlock_lock ( const struct 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
lockLock, or one without a lock, which only locks interrupts.
Return values
0On success, with interrupts locked.
-EINVALThe lock is not one of its controller.
-ETIMEDOUTAnother processor held the lock for too long; interrupts are as they were.

◆ pbl_hwspinlock_unlock()

void pbl_hwspinlock_unlock ( const struct pbl_hwspinlock *  lock)

Release a lock taken with pbl_hwspinlock_lock(), then unlock interrupts.

Parameters
lockLock.