From: Andrew Jones <drjones@redhat.com>
To: kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org
Cc: christoffer.dall@linaro.org, pbonzini@redhat.com
Subject: [PATCH v7 03/14] Introduce asm-generic/*.h files
Date: Wed, 16 Jul 2014 10:47:32 +0200 [thread overview]
Message-ID: <1405500463-20713-4-git-send-email-drjones@redhat.com> (raw)
In-Reply-To: <1405500463-20713-1-git-send-email-drjones@redhat.com>
Architecture neutral code may need to call low-level io accessors,
or use spinlocks. Create a generic io.h to ensure those accessors
are defined, and a generic spinlock.h that complains when included,
as we can't write a generic spinlock. These files can be overridden
or extended by architecture specific versions placed in
lib/$ARCH/asm/.
Signed-off-by: Andrew Jones <drjones@redhat.com>
Acked-by: Christoffer Dall <christoffer.dall@linaro.org>
---
v5: added a trivial ioremap function [Christoffer Dall]
v4: introduce lib/asm symlink to get rid of #ifdef __arm__,
add spinlock.h too
v3: wrt to io.h (was libio.[ch]) only
- get rid of CONFIG_64BIT, replace with asserts
- get rid of {read,write}_len() [libio.c]
- fix bad *64_to_cpu macros
---
.gitignore | 1 +
Makefile | 6 +-
configure | 11 +++
lib/asm-generic/io.h | 162 +++++++++++++++++++++++++++++++++++++++++++++
lib/asm-generic/spinlock.h | 4 ++
5 files changed, 181 insertions(+), 3 deletions(-)
create mode 100644 lib/asm-generic/io.h
create mode 100644 lib/asm-generic/spinlock.h
diff --git a/.gitignore b/.gitignore
index 775d0dfd8263e..e21939a8771e9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,6 +9,7 @@ patches
.stgit-*
cscope.*
*.swp
+/lib/asm
/config.mak
/*-run
/test.log
diff --git a/Makefile b/Makefile
index 180189ecd6d8c..dd7e6e94bfe7b 100644
--- a/Makefile
+++ b/Makefile
@@ -77,11 +77,11 @@ libfdt_clean:
$(LIBFDT_objdir)/.*.d
distclean: clean libfdt_clean
- $(RM) config.mak $(TEST_DIR)-run test.log msr.out cscope.*
+ $(RM) lib/asm config.mak $(TEST_DIR)-run test.log msr.out cscope.*
-cscope: common_dirs = lib lib/libfdt
+cscope: common_dirs = lib lib/libfdt lib/asm lib/asm-generic
cscope:
$(RM) ./cscope.*
- find $(TEST_DIR) lib/$(TEST_DIR) $(common_dirs) -maxdepth 1 \
+ find -L $(TEST_DIR) lib/$(TEST_DIR) $(common_dirs) -maxdepth 1 \
-name '*.[chsS]' -print | sed 's,^\./,,' > ./cscope.files
cscope -bk
diff --git a/configure b/configure
index dbbc6045d214a..aaa1b50ab1b98 100755
--- a/configure
+++ b/configure
@@ -91,6 +91,17 @@ if [ $exit -eq 0 ]; then
fi
rm -f lib_test.c
+# link lib/asm for the architecture
+rm -f lib/asm
+asm=asm-generic
+if [ -d lib/$arch/asm ]; then
+ asm=$arch/asm
+elif [ -d lib/$testdir/asm ]; then
+ asm=$testdir/asm
+fi
+ln -s $asm lib/asm
+
+# create the config
cat <<EOF > config.mak
PREFIX=$prefix
KERNELDIR=$(readlink -f $kerneldir)
diff --git a/lib/asm-generic/io.h b/lib/asm-generic/io.h
new file mode 100644
index 0000000000000..f00f4d3e68fe1
--- /dev/null
+++ b/lib/asm-generic/io.h
@@ -0,0 +1,162 @@
+#ifndef _ASM_GENERIC_IO_H_
+#define _ASM_GENERIC_IO_H_
+/*
+ * asm-generic/io.h
+ * adapted from the Linux kernel's include/asm-generic/io.h
+ * and arch/arm/include/asm/io.h
+ *
+ * Copyright (C) 2014, Red Hat Inc, Andrew Jones <drjones@redhat.com>
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.
+ */
+#include "libcflat.h"
+
+#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)
+{
+ 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)
+{
+ 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); })
+
+#ifndef ioremap
+static inline void *ioremap(u64 phys_addr, size_t size __unused)
+{
+ assert(sizeof(long) == 8 || !(phys_addr >> 32));
+ return (void *)(unsigned long)phys_addr;
+}
+#endif
+
+#endif /* _ASM_GENERIC_IO_H_ */
diff --git a/lib/asm-generic/spinlock.h b/lib/asm-generic/spinlock.h
new file mode 100644
index 0000000000000..31417442e3330
--- /dev/null
+++ b/lib/asm-generic/spinlock.h
@@ -0,0 +1,4 @@
+#ifndef _ASM_GENERIC_SPINLOCK_H_
+#define _ASM_GENERIC_SPINLOCK_H_
+#error need architecture specific asm/spinlock.h
+#endif
--
1.9.3
next prev parent reply other threads:[~2014-07-16 8:47 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-16 8:47 [PATCH v7 00/14] kvm-unit-tests/arm: initial drop Andrew Jones
2014-07-16 8:47 ` [PATCH v7 02/14] add support for Linux device trees Andrew Jones
2014-07-16 8:47 ` Andrew Jones [this message]
2014-07-16 8:47 ` [PATCH v7 04/14] Introduce lib/alloc Andrew Jones
2014-07-16 8:47 ` [PATCH v7 05/14] add minimal virtio support for devtree virtio-mmio Andrew Jones
2014-07-16 8:47 ` [PATCH v7 06/14] lib/asm-generic: add page.h and virt_to_phys/phys_to_virt Andrew Jones
2014-07-16 8:47 ` [PATCH v7 07/14] virtio: add minimal support for virtqueues Andrew Jones
2014-07-16 8:47 ` [PATCH v7 08/14] Introduce chr-testdev Andrew Jones
2014-07-16 9:31 ` Levente Kurusa
2014-07-16 9:33 ` Andrew Jones
2014-07-22 18:06 ` Radim Krčmář
2014-07-16 8:47 ` [PATCH v7 09/14] arm: initial drop Andrew Jones
2014-07-16 9:22 ` Paolo Bonzini
2014-07-16 9:39 ` Andrew Jones
2014-07-16 10:59 ` Paolo Bonzini
2014-07-16 8:47 ` [PATCH v7 10/14] arm: Add spinlock implementation Andrew Jones
2014-07-16 8:47 ` [PATCH v7 11/14] arm: Add IO accessors to avoid register-writeback Andrew Jones
2014-07-16 8:47 ` [PATCH v7 12/14] arm: Add arch-specific asm/page.h and __va/__pa Andrew Jones
2014-07-16 8:47 ` [PATCH v7 13/14] arm: add useful headers from the Linux kernel Andrew Jones
2014-07-16 8:47 ` [PATCH v7 14/14] arm: vectors support Andrew Jones
2014-08-22 18:51 ` [PATCH v7 00/14] kvm-unit-tests/arm: initial drop Paolo Bonzini
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=1405500463-20713-4-git-send-email-drjones@redhat.com \
--to=drjones@redhat.com \
--cc=christoffer.dall@linaro.org \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.cs.columbia.edu \
--cc=pbonzini@redhat.com \
/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