From: Arnd Bergmann <arnd@arndb.de>
To: linaro-kernel@lists.linaro.org
Cc: Mark Brown <broonie@kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Jiri Slaby <jslaby@suse.cz>, Mark Brown <broonie@linaro.org>,
linux-serial@vger.kernel.org,
Victor Kamensky <victor.kamensky@linaro.org>
Subject: Re: [PATCH] exynos: serial clear and set big endian fix
Date: Mon, 21 Jul 2014 18:01:51 +0200 [thread overview]
Message-ID: <5011135.PCJ33lEv6t@wuerfel> (raw)
In-Reply-To: <1405957832-6444-1-git-send-email-broonie@kernel.org>
On Monday 21 July 2014 16:50:32 Mark Brown wrote:
> +#ifndef CONFIG_CPU_BIG_ENDIAN /* little endian */
> +static inline void __hw_set_bit(int nr, volatile unsigned long *addr)
> +{
> + __set_bit(nr, addr);
> +}
> +
> +static inline void __hw_clear_bit(int nr, volatile unsigned long *addr)
> +{
> + __clear_bit(nr, addr);
> +}
> +#else
> +static inline void __hw_set_bit(int nr, volatile unsigned long *addr)
> +{
> + unsigned long mask = BIT_MASK(nr);
> + unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
> + unsigned long val = le32_to_cpu(*p);
> +
> + val |= mask;
> +
> + *p = cpu_to_le32(val);
> +}
This is still wrong, because there is an associated bug: you must never
access pointers to MMIO registers from C code.
The correct way to do it is to use the readl()/writel() functions, or
readl_relaxed()/writel_relaxed() in case of drivers that don't need
to synchronize with DMA transfers.
I think what you want is something like
static inline void __hw_set_bit(int nr, unsigned long __iomem *addr)
{
addr += BIT_WORD(nr);
writel_relaxed(readl_relaxed(addr) | BIT_MASK(nr), addr);
}
which is also endian-safe.
Arnd
next prev parent reply other threads:[~2014-07-21 16:01 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-21 15:50 [PATCH] exynos: serial clear and set big endian fix Mark Brown
2014-07-21 16:01 ` Arnd Bergmann [this message]
2014-07-21 16:10 ` Mark Brown
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=5011135.PCJ33lEv6t@wuerfel \
--to=arnd@arndb.de \
--cc=broonie@kernel.org \
--cc=broonie@linaro.org \
--cc=gregkh@linuxfoundation.org \
--cc=jslaby@suse.cz \
--cc=linaro-kernel@lists.linaro.org \
--cc=linux-serial@vger.kernel.org \
--cc=victor.kamensky@linaro.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