From patchwork Thu Apr 10 16:56:51 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 3963571 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 5BE43BFF02 for ; Thu, 10 Apr 2014 16:57:46 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4D9B620823 for ; Thu, 10 Apr 2014 16:57:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2870A20824 for ; Thu, 10 Apr 2014 16:57:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758786AbaDJQ5k (ORCPT ); Thu, 10 Apr 2014 12:57:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44627 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758758AbaDJQ50 (ORCPT ); Thu, 10 Apr 2014 12:57:26 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s3AGvMdO023772 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 10 Apr 2014 12:57:23 -0400 Received: from hawk.usersys.redhat.com.com (dhcp-1-170.brq.redhat.com [10.34.1.170]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id s3AGv4Ur021128; Thu, 10 Apr 2014 12:57:20 -0400 From: Andrew Jones To: kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org Cc: christoffer.dall@linaro.org Subject: [PATCH v4 10/19] Introduce asm-generic/*.h files Date: Thu, 10 Apr 2014 18:56:51 +0200 Message-Id: <1397149020-3501-11-git-send-email-drjones@redhat.com> In-Reply-To: <1397149020-3501-1-git-send-email-drjones@redhat.com> References: <1397149020-3501-1-git-send-email-drjones@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Acked-by: 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 | 154 +++++++++++++++++++++++++++++++++++++++++++++ lib/asm-generic/spinlock.h | 4 ++ 5 files changed, 173 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 fba58e36f272f..51cacdac00615 100644 --- a/Makefile +++ b/Makefile @@ -76,11 +76,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 6cfc64943f6e6..8a81bf92e27b7 100755 --- a/configure +++ b/configure @@ -95,6 +95,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 < 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..34569c99ae270 --- /dev/null +++ b/lib/asm-generic/io.h @@ -0,0 +1,154 @@ +#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 + * + * 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); }) + +#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