Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 53A4DC433F5 for ; Wed, 16 Mar 2022 15:41:40 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D982483C9E; Wed, 16 Mar 2022 16:41:33 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="EYo3nOaF"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 063B983CCC; Wed, 16 Mar 2022 16:41:13 +0100 (CET) Received: from mail-wm1-x34a.google.com (mail-wm1-x34a.google.com [IPv6:2a00:1450:4864:20::34a]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id B215F82155 for ; Wed, 16 Mar 2022 16:40:56 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=3CAUyYgUKBvEimhlbZhhZeX.Vhfn-Uhhmeblml.WXgq.WX@flex--ptosi.bounces.google.com Received: by mail-wm1-x34a.google.com with SMTP id a26-20020a7bc1da000000b003857205ec7cso1187544wmj.2 for ; Wed, 16 Mar 2022 08:40:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc:content-transfer-encoding; bh=XPw2hIi626frn0KX2UGi5bMWd4zHJ3JIXjDYODkpoVM=; b=EYo3nOaFRngbUzyA3rZNxHAKC8J+mD+DilJNrNr+tY2zFzT3OMkx/C568T7E/JxHIs RXImwQKjL2u8SF7/yh+LVAnqskLP90xrYCqCb2J8+jyInVE1nUU5E5morij488fm2D9Z kkv8HJkkve0AcEfYeLvrdfmoNNtByWwy2hNvUV+LaR+ChhhawNI3ipIzt/EKvXvsw8ez 3kAnCwYdK20TgLNghIaURa6rRHn0OuwQ0bTfLhM0hg54Q5EyhvpDzwa7nJmALi3cALw8 RLCSQj63jQ/Uu8vt84DleBSXJVV9E+RtHStUCpXmjc3ZKoapqlsaZ+G6dYbidth3TGwf 1SDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc:content-transfer-encoding; bh=XPw2hIi626frn0KX2UGi5bMWd4zHJ3JIXjDYODkpoVM=; b=HAgGhwP6XSdBToxVY9bDTfyi6qSTey7oB8TTe73eZO3cLeZalv7njghXqsAsZEjgll I57jFO/w0UkQ3CrNogFE0n3uzazmiMOREr7Z7Ir+jKpsZE34WIrdG8w+PtTUtZe5gmg8 +pCul3z2Yt7YacFOoMgUhOS+eSpQuoTuyuTRcXcJpnu6zSLbBkr45mZuxZB18v+NwRnL FbGFUYfHykahLXGn3OUiA6DFJjeJde6eLxVxFUslWqd1wog07Tc2uOr/KPYyEb7cWCwb Bd8wlDHB5tWX9iZlAyf0PQU3ujf4RZXaDXQrhV0S2WVm+mqaFbTtWd2fX4AvSLdjI+PZ zWpA== X-Gm-Message-State: AOAM531GeH9kBm5TF6kMSYfKqpnUXO3dcoeNlILlxh2AJPGioI960DZt NCBf8MY4JEyUTHsoW3gP9luaMO+tRse+cyxep9+zYVMzK8OMpt7l5CuL9LHWTqXcIjVeESe0v8a XeS2HeBeQAiJx1Oy2HGLpMVvJ4voTQfYzAFihqFuLkGIFtxfk9K+7MQY3 X-Google-Smtp-Source: ABdhPJxsrd4XJachmajUyHGa4C1xf1ED6YbdC1tL+/MwsdAKERTnFQKbiwRRFagRuIKgSSjcUg3Tn8ziNw== X-Received: from ptosi1.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:afb]) (user=ptosi job=sendgmr) by 2002:a05:600c:190c:b0:389:bf36:ce3c with SMTP id j12-20020a05600c190c00b00389bf36ce3cmr7758614wmq.155.1647445256285; Wed, 16 Mar 2022 08:40:56 -0700 (PDT) Date: Wed, 16 Mar 2022 15:39:44 +0000 In-Reply-To: <20220316153948.197650-1-ptosi@google.com> Message-Id: <20220316153948.197650-5-ptosi@google.com> Mime-Version: 1.0 References: <20220316153948.197650-1-ptosi@google.com> X-Mailer: git-send-email 2.35.1.723.g4982287a31-goog Subject: [PATCH 5/9] include: Import & Update bitops.h From: "=?UTF-8?q?Pierre-Cl=C3=A9ment=20Tosi?=" To: u-boot@lists.denx.de Cc: "=?UTF-8?q?Pierre-Cl=C3=A9ment=20Tosi?=" , Simon Glass , Tom Rini Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean Import the header from version 5.16 of the kernel: commit df0cc57e057f18e44dac8e6c18aba47ab53202f9 Inline the included and prevent U-Boot from including as BITS_PER_LONG is defined in . Remove now-duplicate definitions from . Note: This brings extra compile-time checks through GENMASK_INPUT_CHECK. Signed-off-by: Pierre-Cl=C3=A9ment Tosi Cc: Simon Glass Cc: Tom Rini --- include/linux/bitops.h | 27 ++++++--------------- include/linux/bits.h | 55 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 20 deletions(-) create mode 100644 include/linux/bits.h diff --git a/include/linux/bitops.h b/include/linux/bitops.h index d2e5ca026e..6d465077d6 100644 --- a/include/linux/bitops.h +++ b/include/linux/bitops.h @@ -5,37 +5,24 @@ =20 #include #include +#include #include =20 #ifdef __KERNEL__ -#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)) #endif =20 /* kernel.h includes log.h which include bitops.h */ #include =20 -/* - * 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. - */ #ifdef CONFIG_SANDBOX -#define GENMASK(h, l) \ - (((~0UL) << (l)) & (~0UL >> (CONFIG_SANDBOX_BITS_PER_LONG - 1 - (h)))) -#else -#define GENMASK(h, l) \ - (((~0UL) << (l)) & (~0UL >> (BITS_PER_LONG - 1 - (h)))) +#ifdef __GENMASK +#undef __GENMASK +#endif +#define __GENMASK(h, l) \ + (((~UL(0)) - (UL(1) << (l)) + 1) & \ + (~UL(0) >> (CONFIG_SANDBOX_BITS_PER_LONG - 1 - (h)))) #endif - -#define GENMASK_ULL(h, l) \ - (((~0ULL) << (l)) & (~0ULL >> (BITS_PER_LONG_LONG - 1 - (h)))) =20 /* * ffs: find first bit set. This is defined the same way as diff --git a/include/linux/bits.h b/include/linux/bits.h new file mode 100644 index 0000000000..04e7dae7f9 --- /dev/null +++ b/include/linux/bits.h @@ -0,0 +1,55 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __LINUX_BITS_H +#define __LINUX_BITS_H + +#include +#ifndef __UBOOT__ +#include +#else +#define BIT(nr) (UL(1) << (nr)) +#endif +#ifndef __UBOOT__ +#include +#else +/* U-Boot defines BITS_PER_LONG in . */ +#include +#endif + +#define BIT_ULL(nr) (ULL(1) << (nr)) +#define BIT_MASK(nr) (UL(1) << ((nr) % BITS_PER_LONG)) +#define BIT_WORD(nr) ((nr) / BITS_PER_LONG) +#define BIT_ULL_MASK(nr) (ULL(1) << ((nr) % BITS_PER_LONG_LONG)) +#define BIT_ULL_WORD(nr) ((nr) / BITS_PER_LONG_LONG) +#define BITS_PER_BYTE 8 + +/* + * 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. + */ +#if !defined(__ASSEMBLY__) +#include +#define GENMASK_INPUT_CHECK(h, l) \ + (BUILD_BUG_ON_ZERO(__builtin_choose_expr( \ + __is_constexpr((l) > (h)), (l) > (h), 0))) +#else +/* + * BUILD_BUG_ON_ZERO is not available in h files included from asm files, + * disable the input check if that is the case. + */ +#define GENMASK_INPUT_CHECK(h, l) 0 +#endif + +#define __GENMASK(h, l) \ + (((~UL(0)) - (UL(1) << (l)) + 1) & \ + (~UL(0) >> (BITS_PER_LONG - 1 - (h)))) +#define GENMASK(h, l) \ + (GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l)) + +#define __GENMASK_ULL(h, l) \ + (((~ULL(0)) - (ULL(1) << (l)) + 1) & \ + (~ULL(0) >> (BITS_PER_LONG_LONG - 1 - (h)))) +#define GENMASK_ULL(h, l) \ + (GENMASK_INPUT_CHECK(h, l) + __GENMASK_ULL(h, l)) + +#endif /* __LINUX_BITS_H */ --=20 2.35.1.723.g4982287a31-goog