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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxxxxx [kernelnewbies-bounces@xxxxxxxxxxxxxxxxx] on behalf of Luca Ellero [lroluk@xxxxxxxxx]
Sent: Thursday, November 14, 2013 4:02 PM
To: kernelnewbies@xxxxxxxxxxxxxxxxx
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@xxxxxxxxxxxxxxxxx
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

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@xxxxxxxxxxxxxxxxx
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies




[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux