From: Ben Dooks <ben-linux@fluff.org>
To: Leon Woestenberg <leon.woestenberg@gmail.com>
Cc: LAK <linux-arm-kernel@lists.arm.linux.org.uk>,
Linux Kernel list <linux-kernel@vger.kernel.org>
Subject: Re: Locking in the (now generic) GPIO infrastructure?
Date: Fri, 6 Jun 2008 11:28:58 +0100 [thread overview]
Message-ID: <20080606102858.GD14683@trinity.fluff.org> (raw)
In-Reply-To: <c384c5ea0806040400j35236d5fo3854ce2ed30cd755@mail.gmail.com>
On Wed, Jun 04, 2008 at 01:00:19PM +0200, Leon Woestenberg wrote:
> Hello,
>
> compare void gpio_line_set() in
>
> arch/arm/plat-iop/gpio.c:
> void gpio_line_set(int line, int value)
> {
> unsigned long flags;
>
> local_irq_save(flags);
> if (value == GPIO_LOW) {
> *IOP3XX_GPOD &= ~(1 << line);
> } else if (value == GPIO_HIGH) {
> *IOP3XX_GPOD |= 1 << line;
> }
> local_irq_restore(flags);
> }
>
> with
>
> include/asm-arm/arch-ixp4xx/platform.h:
> static inline void gpio_line_set(u8 line, int value)
> {
> if (value == IXP4XX_GPIO_HIGH)
> *IXP4XX_GPIO_GPOUTR |= (1 << line);
> else if (value == IXP4XX_GPIO_LOW)
> *IXP4XX_GPIO_GPOUTR &= ~(1 << line);
> }
Yes, that looks rather buggy to me, and also sub-optimal to boot. The
u8 line should be changed to just 'unsigned' having the compiler truncate
to 8bit isn't useful when then used with a shift.
static inline void gpio_line_set(unsigned line, int value)
{
unsigned long flags;
unsigned regval;
local_irq_save(flags);
regval = *IXP4XX_GPIO_GPOUTR;
if (value == IXP4XX_GPIO_HIGH)
regval |= (1 << line);
else if (value == IXP4XX_GPIO_LOW)
regval &= ~(1 << line);
*IXP4XX_GPIO_GPOUTR = regval;
local_irq_restore(flags);
}
> Under a Linux kernel where multiple drivers are accessing GPIO, the
> latter does not seem safe against preemption (assuming the memory
> read-modify-write is not atomic).
>
> Shouldn't GPIO access be protected against concurrent access here?
>
> Documentation/gpio.txt does not really mention the locking mechanism
> assumed to modify GPIO lines.
I think it depends on whether gpiolib is being used or not, there may
be some locking in there.
--
Ben
Q: What's a light-year?
A: One-third less calories than a regular year.
next prev parent reply other threads:[~2008-06-06 10:28 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-06-04 11:00 Locking in the (now generic) GPIO infrastructure? Leon Woestenberg
2008-06-06 8:52 ` Russell King - ARM Linux
2008-06-06 10:28 ` Ben Dooks [this message]
2008-06-06 12:53 ` David Brownell
2008-06-06 19:23 ` Leon Woestenberg
2008-06-06 20:13 ` David Brownell
2008-06-07 11:52 ` Mikael Pettersson
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=20080606102858.GD14683@trinity.fluff.org \
--to=ben-linux@fluff.org \
--cc=leon.woestenberg@gmail.com \
--cc=linux-arm-kernel@lists.arm.linux.org.uk \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.