public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Alan Cox <alan@lxorguk.ukuu.org.uk>
To: moreau francis <francis_moreau2000@yahoo.fr>
Cc: linux-kernel@vger.kernel.org
Subject: Re: question on memory barrier
Date: Wed, 24 Aug 2005 22:57:46 +0100	[thread overview]
Message-ID: <1124920666.13833.13.camel@localhost.localdomain> (raw)
In-Reply-To: <20050824124348.44686.qmail@web25807.mail.ukl.yahoo.com>

On Mer, 2005-08-24 at 14:43 +0200, moreau francis wrote:
> I'm currently trying to write a USB driver for Linux. The device must be
> configured by writing some values into the same register but I want to be
> sure that the writing order is respected by either the compiler and the cpu.

The Linux kernel defines writel() in such a way that for each platform a
series of writel() calls are ordered with respect to the processor. In
other words if on one processor you issue 

	writel(0, foo);
	writel(1, foo);
	writel(2, foo);

the hardware will see 0, 1, 2. writel does not guarantee that the write
occurs immediately so while you know the writes are ordered you don't
know the write has "arrived" at the device when the writel() call
returns. That isn't usually a problem except when delays are required.
Then you need to avoid PCI posting and do

	writel(0, foo);
	readl(foo);
	udelay(50);
	writel(1, foo);

The only other complication is multiprocessor systems - if you have
multiple places that may issue these I/O's you may need a lock to
protect them from both processors configuring at the same time, and in
theory an mmiowb() call to ensure the first processor has finished its
I/O before the second starts - ie

	spin_lock(&conf_lock);
	writel(0, foo);
	writel(1, foo);
	mmiowb();
	spin_unlock(&conf_lock);


The "wmb/rmb" are barriers to memory not to device I/O. The locking
functions (spin_unlock etc) are implicit memory barriers, but atomic
operations are not.

Generally speaking if you use writel the right semantics just happen,
and that is why the writel definition is the way it is.


      parent reply	other threads:[~2005-08-24 21:29 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-08-24 12:43 question on memory barrier moreau francis
2005-08-24 13:04 ` linux-os (Dick Johnson)
2005-08-24 17:31   ` moreau francis
2005-08-24 18:22     ` linux-os (Dick Johnson)
2005-08-24 19:32       ` Oliver Neukum
2005-08-24 19:47         ` linux-os (Dick Johnson)
2005-08-24 19:55           ` Oliver Neukum
2005-08-24 19:48     ` Andy Isaacson
2005-08-24 19:53       ` Jesse Barnes
2005-08-24 21:45         ` Alan Cox
2005-08-24 21:22           ` Jesse Barnes
2005-08-24 20:03       ` linux-os (Dick Johnson)
2005-08-24 20:21         ` Oliver Neukum
2005-08-25  2:25         ` David Schwartz
2005-08-25  8:49       ` Denis Vlasenko
2005-08-25  9:14       ` moreau francis
2005-08-25 10:07         ` Alan Cox
2005-08-25 14:54         ` Andy Isaacson
2005-08-26  7:21           ` moreau francis
2005-08-26 10:37             ` Maciej W. Rozycki
2005-08-25 10:32       ` Maciej W. Rozycki
2005-08-24 21:57 ` Alan Cox [this message]

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=1124920666.13833.13.camel@localhost.localdomain \
    --to=alan@lxorguk.ukuu.org.uk \
    --cc=francis_moreau2000@yahoo.fr \
    --cc=linux-kernel@vger.kernel.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