Best practice to lock a read/write to a HW register
bernd at petrovitsch.priv.at
Thu Nov 14 07:14:29 EST 2013
On Don, 2013-11-14 at 11:32 +0100, Luca Ellero wrote:
> can someone please show me which is the best practice to lock a
> read/write to a hardware register.
> In other words if, in a driver, I want to modify a bit in a HW register,
> I have to read the register, set/reset the relevant bit and write back
> the reg.
> But what can I do to be sure that no other code modifies the register
> between my read and write?
> Is spin_lock() suitable for this purpose?
If the read-modify-write (read: the critical section) run-time is short,
a spin-lock is the usual means. If it is needed from IRQ-context - see
also other mails - you must use the *_irq() variant.
Bernd Petrovitsch Email : bernd at petrovitsch.priv.at
LUGA : http://www.luga.at
More information about the Kernelnewbies