Best practice to lock a read/write to a HW register

Mandeep Sandhu mandeepsandhu.chd at gmail.com
Thu Nov 14 06:20:47 EST 2013


On Thu, Nov 14, 2013 at 4:02 PM, Luca Ellero <lroluk at gmail.com> wrote:
> Hi all,
> 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 IRQ handlers can touch this register, then I think you'll have to
disable interrupts as well (spin_lock_irq*() ?).

HTH,
-mandep

> Thanks
> Best regards
> Luca
>
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies



More information about the Kernelnewbies mailing list