From: Christoffer Dall <christoffer.dall@linaro.org>
To: Andrew Jones <drjones@redhat.com>
Cc: kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org
Subject: Re: [PATCH 08/17] Introduce libio to common code for io read/write
Date: Mon, 3 Feb 2014 08:30:16 -0800 [thread overview]
Message-ID: <20140203163016.GD4167@cbox> (raw)
In-Reply-To: <20140203135115.GC6832@hawk.usersys.redhat.com>
On Mon, Feb 03, 2014 at 02:51:15PM +0100, Andrew Jones wrote:
> On Sat, Feb 01, 2014 at 06:24:51PM -0800, Christoffer Dall wrote:
> > On Tue, Jan 21, 2014 at 05:21:54PM +0100, Andrew Jones wrote:
> > > v3:
> > > - get rid of CONFIG_64BIT, replace with asserts
> > > - get rid of {read,write}_len()
> > > - fix bad *64_to_cpu macros
> >
> > note that putting the changelog after the "---" prevents it from
> > getting committed, but I'm not sure if there are different
> > conventions for the unit-tests framework.
>
> I'll drop the '---' in the v4 patches
>
no, I meant that the v3 changelog should be below the '---' not above it
- we don't want to commit a changelog to git.
> >
> > >
> > > Signed-off-by: Andrew Jones <drjones@redhat.com>
> > > ---
> > > lib/libio.h | 173 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> > > 1 file changed, 173 insertions(+)
> > > create mode 100644 lib/libio.h
> > >
> > > diff --git a/lib/libio.h b/lib/libio.h
> > > new file mode 100644
> > > index 0000000000000..6adc6a7bbee61
> > > --- /dev/null
> > > +++ b/lib/libio.h
> > > @@ -0,0 +1,173 @@
> > > +#ifndef _LIBIO_H_
> > > +#define _LIBIO_H_
> > > +/*
> > > + * Adapted from the Linux kernel's include/asm-generic/io.h and
> > > + * arch/arm/include/asm/io.h
> > > + */
> > > +#include "libcflat.h"
> > > +
> > > +#ifndef NDEBUG
> > > +#define LIBIO_ASSERT(expr) do { \
> > > + if (!(expr)) printf("%s:%d: assert failed!\n", __FILE__, __LINE__);\
> > > +} while (0)
> > > +#else
> > > +#define LIBIO_ASSERT(expr) do { } while (0)
> > > +#endif
> > > +
> > > +typedef u32 compat_ptr_t;
> > > +
> > > +/*
> > > + * Use compat_ptr() on 64-bit arches when casting 32-bit
> >
> > arches? architectures? archs?
>
> kernel code has 88 archs and 55 arches, I guess we could go with
> archs by majority rules, but I prefer arches.
>
fair enough, I associated a national park. Bike shedding on my part
anyway.
> >
> > > + * addresses to pointers in order to avoid compiler warnings.
> > > + */
> > > +static inline void *compat_ptr(compat_ptr_t ptr)
> > > +{
> > > + return (void *)(unsigned long)ptr;
> > > +}
> > > +
> > > +static inline compat_ptr_t ptr_to_compat(void *ptr)
> > > +{
> > > + return (u32)(unsigned long)ptr;
> > > +}
> > > +
> > > +#ifndef __raw_readb
> > > +static inline u8 __raw_readb(const volatile void *addr)
> > > +{
> > > + return *(const volatile u8 *)addr;
> > > +}
> > > +#endif
> > > +
> > > +#ifndef __raw_readw
> > > +static inline u16 __raw_readw(const volatile void *addr)
> > > +{
> > > + return *(const volatile u16 *)addr;
> > > +}
> > > +#endif
> > > +
> > > +#ifndef __raw_readl
> > > +static inline u32 __raw_readl(const volatile void *addr)
> > > +{
> > > + return *(const volatile u32 *)addr;
> > > +}
> > > +#endif
> > > +
> > > +#ifndef __raw_readq
> > > +static inline u64 __raw_readq(const volatile void *addr)
> > > +{
> > > + LIBIO_ASSERT(sizeof(unsigned long) == sizeof(u64));
> > > + return *(const volatile u64 *)addr;
> > > +}
> > > +#endif
> > > +
> > > +#ifndef __raw_writeb
> > > +static inline void __raw_writeb(u8 b, volatile void *addr)
> > > +{
> > > + *(volatile u8 *)addr = b;
> > > +}
> > > +#endif
> > > +
> > > +#ifndef __raw_writew
> > > +static inline void __raw_writew(u16 b, volatile void *addr)
> > > +{
> > > + *(volatile u16 *)addr = b;
> > > +}
> > > +#endif
> > > +
> > > +#ifndef __raw_writel
> > > +static inline void __raw_writel(u32 b, volatile void *addr)
> > > +{
> > > + *(volatile u32 *)addr = b;
> > > +}
> > > +#endif
> > > +
> > > +#ifndef __raw_writeq
> > > +static inline void __raw_writeq(u64 b, volatile void *addr)
> > > +{
> > > + LIBIO_ASSERT(sizeof(unsigned long) == sizeof(u64));
> > > + *(volatile u64 *)addr = b;
> > > +}
> > > +#endif
> > > +
> > > +#ifndef __bswap16
> > > +static inline u16 __bswap16(u16 x)
> > > +{
> > > + return ((x >> 8) & 0xff) | ((x & 0xff) << 8);
> > > +}
> > > +#endif
> > > +
> > > +#ifndef __bswap32
> > > +static inline u32 __bswap32(u32 x)
> > > +{
> > > + return ((x & 0xff000000) >> 24) | ((x & 0x00ff0000) >> 8) |
> > > + ((x & 0x0000ff00) << 8) | ((x & 0x000000ff) << 24);
> > > +}
> > > +#endif
> > > +
> > > +#ifndef __bswap64
> > > +static inline u64 __bswap64(u64 x)
> > > +{
> > > + return ((x & 0x00000000000000ffULL) << 56) |
> > > + ((x & 0x000000000000ff00ULL) << 40) |
> > > + ((x & 0x0000000000ff0000ULL) << 24) |
> > > + ((x & 0x00000000ff000000ULL) << 8) |
> > > + ((x & 0x000000ff00000000ULL) >> 8) |
> > > + ((x & 0x0000ff0000000000ULL) >> 24) |
> > > + ((x & 0x00ff000000000000ULL) >> 40) |
> > > + ((x & 0xff00000000000000ULL) >> 56);
> > > +}
> > > +#endif
> > > +
> > > +#ifndef cpu_is_be
> > > +#define cpu_is_be 0
> > > +#endif
> > > +
> > > +#define le16_to_cpu(x) \
> > > + ({ u16 __r = cpu_is_be ? __bswap16(x) : (x); __r; })
> > > +#define cpu_to_le16 le16_to_cpu
> > > +
> > > +#define le32_to_cpu(x) \
> > > + ({ u32 __r = cpu_is_be ? __bswap32(x) : (x); __r; })
> > > +#define cpu_to_le32 le32_to_cpu
> > > +
> > > +#define le64_to_cpu(x) \
> > > + ({ u64 __r = cpu_is_be ? __bswap64(x) : (x); __r; })
> > > +#define cpu_to_le64 le64_to_cpu
> > > +
> > > +#define be16_to_cpu(x) \
> > > + ({ u16 __r = !cpu_is_be ? __bswap16(x) : (x); __r; })
> > > +#define cpu_to_be16 be16_to_cpu
> > > +
> > > +#define be32_to_cpu(x) \
> > > + ({ u32 __r = !cpu_is_be ? __bswap32(x) : (x); __r; })
> > > +#define cpu_to_be32 be32_to_cpu
> > > +
> > > +#define be64_to_cpu(x) \
> > > + ({ u64 __r = !cpu_is_be ? __bswap64(x) : (x); __r; })
> > > +#define cpu_to_be64 be64_to_cpu
> > > +
> > > +#ifndef rmb
> > > +#define rmb() do { } while (0)
> > > +#endif
> > > +#ifndef wmb
> > > +#define wmb() do { } while (0)
> > > +#endif
> > > +
> > > +#define readb(addr) \
> > > + ({ u8 __r = __raw_readb(addr); rmb(); __r; })
> > > +#define readw(addr) \
> > > + ({ u16 __r = le16_to_cpu(__raw_readw(addr)); rmb(); __r; })
> > > +#define readl(addr) \
> > > + ({ u32 __r = le32_to_cpu(__raw_readl(addr)); rmb(); __r; })
> > > +#define readq(addr) \
> > > + ({ u64 __r = le64_to_cpu(__raw_readq(addr)); rmb(); __r; })
> > > +
> > > +#define writeb(b, addr) \
> > > + ({ wmb(); __raw_writeb(b, addr); })
> > > +#define writew(b, addr) \
> > > + ({ wmb(); __raw_writew(cpu_to_le16(b), addr); })
> > > +#define writel(b, addr) \
> > > + ({ wmb(); __raw_writel(cpu_to_le32(b), addr); })
> > > +#define writeq(b, addr) \
> > > + ({ wmb(); __raw_writeq(cpu_to_le64(b), addr); })
> > > +
> > > +#endif
> >
> > so these definitions always assume that your device is LE, which is
> > probably true for ARM and x86 for now, but if we ever use this on PPC or
> > want to test ARM BE with a BE QEMU, will it still work?
>
> I don't know if it'll be an issue or not. Let's cross that bridge when we
> get to it. We can alway move/duplicate these accessors into each arch
> specific io.h file, when necessary.
>
ok, I can live with that.
> >
> > (There's some trickery with virtio and endianness that I don't remember
> > 100%, so if we assume this ever only reads and writes to virtio space,
> > we may be in the clear.)
>
> The virtio spec is switching to everything LE, I believe, so the above
> should be good for virtio devices anyway.
>
>
yep.
next prev parent reply other threads:[~2014-02-03 16:30 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-21 16:21 [PATCH 00/17] kvm-unit-tests/arm: initial drop Andrew Jones
2014-01-21 16:21 ` [PATCH 01/17] remove unused files Andrew Jones
2014-01-21 16:21 ` [PATCH 02/17] makefile and run_tests tweaks Andrew Jones
2014-01-21 16:21 ` [PATCH 03/17] clean root dir of all x86-ness Andrew Jones
2014-01-21 16:21 ` [PATCH 04/17] gitignore: Ignore more Andrew Jones
2014-01-21 16:21 ` [PATCH 05/17] add 'make cscope' support Andrew Jones
2014-02-02 2:22 ` Christoffer Dall
2014-02-03 13:25 ` Andrew Jones
2014-01-21 16:21 ` [PATCH 06/17] Add halt() and some error codes Andrew Jones
2014-02-02 2:23 ` Christoffer Dall
2014-01-21 16:21 ` [PATCH 07/17] move x86's simple heap management to common code Andrew Jones
2014-02-02 2:23 ` Christoffer Dall
2014-01-21 16:21 ` [PATCH 08/17] Introduce libio to common code for io read/write Andrew Jones
2014-02-02 2:24 ` Christoffer Dall
2014-02-03 13:51 ` Andrew Jones
2014-02-03 16:30 ` Christoffer Dall [this message]
2014-01-21 16:21 ` [PATCH 10/17] libfdt: get libfdt to build Andrew Jones
2014-02-02 2:25 ` Christoffer Dall
2014-02-03 13:57 ` Andrew Jones
2014-01-21 16:21 ` [PATCH 11/17] add support for device trees Andrew Jones
2014-02-02 2:27 ` Christoffer Dall
2014-02-03 15:31 ` Andrew Jones
2014-02-03 16:36 ` Christoffer Dall
2014-01-21 16:21 ` [PATCH 12/17] Introduce virtio-testdev Andrew Jones
2014-02-02 2:27 ` Christoffer Dall
2014-02-03 15:44 ` Andrew Jones
2014-02-03 16:41 ` Christoffer Dall
2014-01-21 16:21 ` [PATCH 13/17] arm: initial drop Andrew Jones
2014-02-02 2:28 ` Christoffer Dall
2014-02-03 15:55 ` Andrew Jones
2014-01-21 16:22 ` [PATCH 14/17] arm: Add IO accessors to avoid register-writeback Andrew Jones
2014-01-21 16:22 ` [PATCH 15/17] printf: support field padding Andrew Jones
2014-02-02 2:28 ` Christoffer Dall
2014-01-21 16:22 ` [PATCH 16/17] arm: add useful headers from the linux kernel Andrew Jones
2014-02-02 2:29 ` Christoffer Dall
2014-02-03 16:46 ` Andrew Jones
2014-02-03 17:38 ` Christoffer Dall
2014-01-21 16:22 ` [PATCH 17/17] arm: vectors support Andrew Jones
2014-02-02 2:29 ` Christoffer Dall
2014-02-03 16:50 ` Andrew Jones
2014-02-03 21:19 ` Christoffer Dall
2014-02-04 7:12 ` Andrew Jones
[not found] ` <CABWnSnPMc_CrH8N28TScBVvQmCk+XD-bVWvdmJAxxVczHsVx_g@mail.gmail.com>
2014-01-29 15:35 ` [PATCH 00/17] kvm-unit-tests/arm: initial drop Andrew Jones
2014-02-02 2:22 ` Christoffer Dall
2014-02-03 13:24 ` Andrew Jones
[not found] ` <CALxX4v-h+gOCZDukCnGK_GUQepu07KYw4BGjzjGNgA0SdDcLNw@mail.gmail.com>
2014-02-04 8:33 ` Andrew Jones
[not found] ` <1390321323-1855-10-git-send-email-drjones@redhat.com>
2014-02-02 2:25 ` [PATCH 09/17] libfdt: Import libfdt source Christoffer Dall
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=20140203163016.GD4167@cbox \
--to=christoffer.dall@linaro.org \
--cc=drjones@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.cs.columbia.edu \
/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