Best practice to lock a read/write to a HW register
binoy.jayan at wipro.com
binoy.jayan at wipro.com
Thu Nov 14 06:51:23 EST 2013
Hi Luca
The locking mechanism to be used depends on what your piece of code does and where your code runs.
If your code runs in a interrupt context (inside an interrupt handler), you should use a spinlock (with irq save and restore).
Else you can use mutex or a semaphore.
In either cases, you don't lock the hardware register but create a lock descriptor and lock the same.
So you need to implement locking at every place the register is accessed.
Please refer http://lwn.net/Kernel/LDD3/ on how to use locks.
Regards,
Binoy Jayan
________________________________________
From: kernelnewbies-bounces at kernelnewbies.org [kernelnewbies-bounces at kernelnewbies.org] on behalf of Luca Ellero [lroluk at gmail.com]
Sent: Thursday, November 14, 2013 4:02 PM
To: kernelnewbies at kernelnewbies.org
Subject: Best practice to lock a read/write to a HW register
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?
Thanks
Best regards
Luca
_______________________________________________
Kernelnewbies mailing list
Kernelnewbies at kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Please do not print this email unless it is absolutely necessary.
The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments.
WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.
www.wipro.com
More information about the Kernelnewbies
mailing list