kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
From: bernd@petrovitsch.priv.at (Bernd Petrovitsch)
To: kernelnewbies@lists.kernelnewbies.org
Subject: Best practice to lock a read/write to a HW register
Date: Thu, 14 Nov 2013 13:14:29 +0100	[thread overview]
Message-ID: <1384431269.1520.16.camel@thorin> (raw)
In-Reply-To: <5284A6AE.90901@gmail.com>

Hi!

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
-- 
Bernd Petrovitsch                  Email : bernd at petrovitsch.priv.at
                     LUGA : http://www.luga.at

  parent reply	other threads:[~2013-11-14 12:14 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-14 10:32 Best practice to lock a read/write to a HW register Luca Ellero
2013-11-14 11:20 ` Mandeep Sandhu
2013-11-14 11:51 ` binoy.jayan at wipro.com
2013-11-14 12:14 ` Bernd Petrovitsch [this message]
2013-11-15  1:30   ` manty kuma
2013-11-15  8:53     ` Luca Ellero

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1384431269.1520.16.camel@thorin \
    --to=bernd@petrovitsch.priv.at \
    --cc=kernelnewbies@lists.kernelnewbies.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).