<div dir="ltr"><div>Ideally, it depends on the platform you are working. You need to
discuss with them for the correct approach. For Qualcomm they have some
hardware caled as RPU(Register protection unit). They have systems calls
exposed for using them. You can associtate it to the register you want
protection. I dont know if there is any way you could do it in Linux
itself?<br>
<br></div>Regards,<br>Sandeep</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Nov 14, 2013 at 9:14 PM, Bernd Petrovitsch <span dir="ltr"><<a href="mailto:bernd@petrovitsch.priv.at" target="_blank">bernd@petrovitsch.priv.at</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi!<br>
<br>
On Don, 2013-11-14 at 11:32 +0100, Luca Ellero wrote:<br>
[...]<br>
<div class="im">> can someone please show me which is the best practice to lock a<br>
> read/write to a hardware register.<br>
> In other words if, in a driver, I want to modify a bit in a HW register,<br>
> I have to read the register, set/reset the relevant bit and write back<br>
> the reg.<br>
> But what can I do to be sure that no other code modifies the register<br>
> between my read and write?<br>
> Is spin_lock() suitable for this purpose?<br>
<br>
</div>If the read-modify-write (read: the critical section) run-time is short,<br>
a spin-lock is the usual means. If it is needed from IRQ-context - see<br>
also other mails - you must use the *_irq() variant.<br>
<span class="HOEnZb"><font color="#888888"><br>
Bernd<br>
--<br>
Bernd Petrovitsch Email : <a href="mailto:bernd@petrovitsch.priv.at">bernd@petrovitsch.priv.at</a><br>
LUGA : <a href="http://www.luga.at" target="_blank">http://www.luga.at</a><br>
</font></span><div class="HOEnZb"><div class="h5"><br>
<br>
_______________________________________________<br>
Kernelnewbies mailing list<br>
<a href="mailto:Kernelnewbies@kernelnewbies.org">Kernelnewbies@kernelnewbies.org</a><br>
<a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" target="_blank">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
</div></div></blockquote></div><br></div>