From patchwork Wed Mar 2 17:10:53 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Feiner X-Patchwork-Id: 8483941 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 9F9689F314 for ; Wed, 2 Mar 2016 17:11:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0D5D320383 for ; Wed, 2 Mar 2016 17:11:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 086ED20373 for ; Wed, 2 Mar 2016 17:11:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754611AbcCBRLM (ORCPT ); Wed, 2 Mar 2016 12:11:12 -0500 Received: from mail-pf0-f176.google.com ([209.85.192.176]:32891 "EHLO mail-pf0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754360AbcCBRLE (ORCPT ); Wed, 2 Mar 2016 12:11:04 -0500 Received: by mail-pf0-f176.google.com with SMTP id 124so75434442pfg.0 for ; Wed, 02 Mar 2016 09:11:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=NE8ngaQ4vHC+qRZesp7DcIkS+MOZLcBjzKcjUTn31tA=; b=lFfEMBw+/paJtfGQLPLb7amX25YNLgvryhWKVtTnSO94yJ8IwzU9OaJwR5Rm6N7Rsw bJXpPR6UNiTPa3w1+lBhsTCpJArDCsUFroRiTCVxo/+6pPzz7QQbx0BVsKJA9WyDHFqG WeuPjxvC8JiSnFT0zxwiv4eqiAdOL2pNnaJDELoTizpgcmj/UW3k4M+U/keYowryl3o2 CJ25dXKOzOFt21UZzEbOwEva5NaNS1m7lfeJkS4AwibgVgxYV/UuMz93DkELbkczmQ3/ muy24fs5Op8UsFCG715wS2E+4VF/YNPwQ4EdA68Ur2auS3lP40tKSFvIIc5zVewiB/bt jdbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=NE8ngaQ4vHC+qRZesp7DcIkS+MOZLcBjzKcjUTn31tA=; b=FWo6XJUPHtLhLArg6zQrXy7ylrU4++YEGxVkEFvFNYqBPvk9aLYu9WZBODdCq1hEJi b2kTbuhxNQzlB36OcOiWBhs+duQ8yzlaaeVsONpK8CM2vQ0ZV67vwkL7mYBInVDBipIb 2nrceDBkIFp6rMIDbEsgxV2PAoqd0rTzFKaslDuIyXjGkGvCwUjMBR+IcNqzeWLktau3 L4USIBhIKwlreVMtJQwEc/mNGXxjIdu2/THR1QeGm/+ISlr2fi9EEM2H9r8ra8m8j+80 JjjcLt2WSwSfWEsDlE2F0i/hw4k968Z5t9Cv1f1tcKnqvSoxo3izictJ3igKi/W6DIvd CRcQ== X-Gm-Message-State: AD7BkJJNIsqbQcRwfTq+XI7bXASsgpI7c7oW7ncw9csoiprsP9I+awcLNXsVWHnvk8hQdCHl X-Received: by 10.98.74.202 with SMTP id c71mr40189498pfj.25.1456938663224; Wed, 02 Mar 2016 09:11:03 -0800 (PST) Received: from localhost ([2620:0:1009:3:10b2:1b3a:febc:1b15]) by smtp.gmail.com with ESMTPSA id n66sm6570654pfj.39.2016.03.02.09.11.02 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Wed, 02 Mar 2016 09:11:02 -0800 (PST) From: Peter Feiner To: kvm@vger.kernel.org, jan.kiszka@siemens.com, drjones@redhat.com, pbonzini@redhat.com Cc: pfeiner@google.com Subject: [kvm-unit-tests v3 2/6] lib: generic bitops.h Date: Wed, 2 Mar 2016 09:10:53 -0800 Message-Id: <1456938657-20850-3-git-send-email-pfeiner@google.com> X-Mailer: git-send-email 2.7.0.rc3.207.g0ac5344 In-Reply-To: <1456938657-20850-1-git-send-email-pfeiner@google.com> References: <1456860622-31251-1-git-send-email-pfeiner@google.com> <1456938657-20850-1-git-send-email-pfeiner@google.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, 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 Factored out common bitops stuff, just like Linux's include/linux/bitops.h. Signed-off-by: Peter Feiner Reviewed-by: Andrew Jones --- lib/arm/asm/bitops.h | 8 ++++---- lib/arm/asm/cpumask.h | 2 +- lib/arm/bitops.c | 2 +- lib/arm64/asm/bitops.h | 8 ++++---- lib/bitops.h | 36 ++++++++++++++++++++++++++++++++++++ lib/ppc64/asm/bitops.h | 10 ++++++++++ lib/x86/asm/bitops.h | 14 ++++++++++++++ 7 files changed, 70 insertions(+), 10 deletions(-) create mode 100644 lib/bitops.h create mode 100644 lib/ppc64/asm/bitops.h create mode 100644 lib/x86/asm/bitops.h diff --git a/lib/arm/asm/bitops.h b/lib/arm/asm/bitops.h index 8049634..d46cc5d 100644 --- a/lib/arm/asm/bitops.h +++ b/lib/arm/asm/bitops.h @@ -2,7 +2,6 @@ #define _ASMARM_BITOPS_H_ /* * Adapated from - * include/linux/bitops.h * arch/arm/lib/bitops.h * * Copyright (C) 2015, Red Hat Inc, Andrew Jones @@ -10,10 +9,11 @@ * This work is licensed under the terms of the GNU LGPL, version 2. */ +#ifndef _BITOPS_H_ +#error only can be included directly +#endif + #define BITS_PER_LONG 32 -#define BIT(nr) (1UL << (nr)) -#define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG)) -#define BIT_WORD(nr) ((nr) / BITS_PER_LONG) #define ATOMIC_BITOP(insn, mask, word) \ ({ \ diff --git a/lib/arm/asm/cpumask.h b/lib/arm/asm/cpumask.h index 85b8e4b..6683bb6 100644 --- a/lib/arm/asm/cpumask.h +++ b/lib/arm/asm/cpumask.h @@ -8,7 +8,7 @@ * This work is licensed under the terms of the GNU LGPL, version 2. */ #include -#include +#include #define CPUMASK_NR_LONGS ((NR_CPUS + BITS_PER_LONG - 1) / BITS_PER_LONG) diff --git a/lib/arm/bitops.c b/lib/arm/bitops.c index 9ad1121..1f1db93 100644 --- a/lib/arm/bitops.c +++ b/lib/arm/bitops.c @@ -6,7 +6,7 @@ * * This work is licensed under the terms of the GNU LGPL, version 2. */ -#include +#include #include #include diff --git a/lib/arm64/asm/bitops.h b/lib/arm64/asm/bitops.h index 3371c60..618468c 100644 --- a/lib/arm64/asm/bitops.h +++ b/lib/arm64/asm/bitops.h @@ -2,7 +2,6 @@ #define _ASMARM64_BITOPS_H_ /* * Adapated from - * include/linux/bitops.h * arch/arm64/lib/bitops.S * * Copyright (C) 2015, Red Hat Inc, Andrew Jones @@ -10,10 +9,11 @@ * This work is licensed under the terms of the GNU LGPL, version 2. */ +#ifndef _BITOPS_H_ +#error only can be included directly +#endif + #define BITS_PER_LONG 64 -#define BIT(nr) (1UL << (nr)) -#define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG)) -#define BIT_WORD(nr) ((nr) / BITS_PER_LONG) #define ATOMIC_BITOP(insn, mask, word) \ ({ \ diff --git a/lib/bitops.h b/lib/bitops.h new file mode 100644 index 0000000..9aa847e --- /dev/null +++ b/lib/bitops.h @@ -0,0 +1,36 @@ +#ifndef _BITOPS_H_ +#define _BITOPS_H_ + +/* + * Adapated from + * include/linux/bitops.h + * + * Copyright (C) 2015, Red Hat Inc, Andrew Jones + * + * This work is licensed under the terms of the GNU LGPL, version 2. + */ + +#define BITS_PER_LONG_LONG 64 +#define BIT(nr) (1UL << (nr)) +#define BIT_ULL(nr) (1ULL << (nr)) +#define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG)) +#define BIT_WORD(nr) ((nr) / BITS_PER_LONG) +#define BIT_ULL_MASK(nr) (1ULL << ((nr) % BITS_PER_LONG_LONG)) +#define BIT_ULL_WORD(nr) ((nr) / BITS_PER_LONG_LONG) +#define BITS_PER_BYTE 8 +#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long)) + +#include + +/* + * Create a contiguous bitmask starting at bit position @l and ending at + * position @h. For example + * GENMASK_ULL(39, 21) gives us the 64bit vector 0x000000ffffe00000. + */ +#define GENMASK(h, l) \ + (((~0UL) << (l)) & (~0UL >> (BITS_PER_LONG - 1 - (h)))) + +#define GENMASK_ULL(h, l) \ + (((~0ULL) << (l)) & (~0ULL >> (BITS_PER_LONG_LONG - 1 - (h)))) + +#endif diff --git a/lib/ppc64/asm/bitops.h b/lib/ppc64/asm/bitops.h new file mode 100644 index 0000000..34624b4 --- /dev/null +++ b/lib/ppc64/asm/bitops.h @@ -0,0 +1,10 @@ +#ifndef _ASMPPC64_BITOPS_H_ +#define _ASMPPC64_BITOPS_H_ + +#ifndef _BITOPS_H_ +#error only can be included directly +#endif + +#define BITS_PER_LONG 64 + +#endif diff --git a/lib/x86/asm/bitops.h b/lib/x86/asm/bitops.h new file mode 100644 index 0000000..eb4aaa9 --- /dev/null +++ b/lib/x86/asm/bitops.h @@ -0,0 +1,14 @@ +#ifndef _ASMX86_BITOPS_H_ +#define _ASMX86_BITOPS_H_ + +#ifndef _BITOPS_H_ +#error only can be included directly +#endif + +#ifdef __x86_64__ +#define BITS_PER_LONG 64 +#else +#define BITS_PER_LONG 32 +#endif + +#endif