From patchwork Sun Jun 9 15:39:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 166226 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp2076ilk; Sun, 9 Jun 2019 08:40:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqw5byfl1fPVPHjpBvz8XsHOz7WQn2kTGIJYKZdTwmpyCmRVZWC+/urfp9dGdF00Q3qhqO/p X-Received: by 2002:a17:90a:cb12:: with SMTP id z18mr15914183pjt.82.1560094823366; Sun, 09 Jun 2019 08:40:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560094823; cv=none; d=google.com; s=arc-20160816; b=0Qtsm6wEXGzkvJsogK3WR+9guWms/qefoViK8J2kvdvPVOrHy8kEsHtAfw7YpwkE1C mL96eZZzpNnRT5twQfTh424EetEgTjR+AYBKXyksxA1xRec5dFPeIn/0b0h9FIVvdspT sXGQokWwd2ViBpSodbtj9gEnauBA7e3+3/E5z4Pdd5oN58XQyUiNx8/p3iC+ce+WStKJ HVFpWKluxSkteNIY85iNiMeWpTSJZ6XWynFM8/AxAgApIUYFTT3NptFfqlcZ4YnO4/4j 7mujA7rb91gGm0rsgADWUDuv7//RT6jN3FtEPlSwHBy7PCy1I9y1V1jB4BU1CxrblAw1 gxlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=QRU//lhSODxOzUbblXINj/fJfjp7ttS/yZ3jFWUK/iQ=; b=L7OWLgnilsqD8P8SB0n2h4NpHz+IiYJ21ZHSp1xKKZELm8ym9+f762rTqd1tF3MX0K Dj1OgpCqtRrvtpLI5r2fal6ktxJXqlXWBTuCVSoKC6MJX1Xompmo8GvqM31v8MjYwcIi m6fZZRKWk3qdsS6qJTCvNeSgQkRbjhTCxNVk9fqsPJ0vUFtXSfN8AU4odrnaVEoyPrbT ipeKrE3+qZwaj1hPS3AdgyyZoWpfSgY8ZOcId6PP9oE55xgPO0+Fr9fDydirzWxffgLr jOZ5muRoeyTVDyQ5ZJNxkpaR1rDwOtytCWED0Hl3rcmADUWCKC0/5Cg3fzy6yz2pFV9L 1lvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=XPmKEJA4; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f15si7372198pgf.303.2019.06.09.08.40.22; Sun, 09 Jun 2019 08:40:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=XPmKEJA4; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728984AbfFIPkS (ORCPT + 30 others); Sun, 9 Jun 2019 11:40:18 -0400 Received: from conuserg-11.nifty.com ([210.131.2.78]:44112 "EHLO conuserg-11.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728628AbfFIPkS (ORCPT ); Sun, 9 Jun 2019 11:40:18 -0400 Received: from grover.flets-west.jp (softbank126125154139.bbtec.net [126.125.154.139]) (authenticated) by conuserg-11.nifty.com with ESMTP id x59Fdj4j004189; Mon, 10 Jun 2019 00:39:45 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-11.nifty.com x59Fdj4j004189 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1560094785; bh=QRU//lhSODxOzUbblXINj/fJfjp7ttS/yZ3jFWUK/iQ=; h=From:To:Cc:Subject:Date:From; b=XPmKEJA4Vyq6WiDIX2dHX9hWuMnEmtDqiunkVloZ+UIhC8Y3VaaP0nJsqIIMka6aW OSL7iPqdWuQFF3tJE19uhKveM6qqduw52LpfOATgeXOiexTc2ErOtZRAJeDVbvun+1 uGMvaR0Hqx2i9hzpuX3gv5EWEVhAIZZGoGsrQAl2Ra0lmlwpjLCHFw2PBfBCccwMyF iLOtASe0tKYrxgPVVOLan7JfBoD+RMTs6QaZ/umSRifGwJ+HTBDEz9uMSeKogOyZRV xdhEKwsLpco1/aKr9nFTjHEwlgBuIqKC32Y67KDtcbH8JYdixSqPYhhF3JrlfHgEII fTnLa7PA+1vPA== X-Nifty-SrcIP: [126.125.154.139] From: Masahiro Yamada To: Andrew Morton Cc: linux-s390@vger.kernel.org, linux-snps-arc@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, Masahiro Yamada Subject: [PATCH 1/2] linux/bits.h: make BIT(), GENMASK(), and friends available in assembly Date: Mon, 10 Jun 2019 00:39:40 +0900 Message-Id: <20190609153941.17249-1-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org BIT(), GENMASK(), etc. are useful to define register bits of hardware. However, low-level code is often written in assembly, where they are not available due to the hard-coded 1UL, 0UL. In fact, in-kernel headers such as arch/arm64/include/asm/sysreg.h use _BITUL() instead of BIT() so that the register bit macros are available in assembly. Using macros in include/uapi/linux/const.h have two reasons: [1] For use in uapi headers We should use underscore-prefixed variants for user-space. [2] For use in assembly code Since _BITUL() uses UL(1) instead of 1UL, it can be used as an alternative of BIT(). For [2], it is pretty easy to change BIT() etc. for use in assembly. This allows to replace _BUTUL() in kernel-space headers with BIT(). Signed-off-by: Masahiro Yamada --- include/linux/bits.h | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) -- 2.17.1 diff --git a/include/linux/bits.h b/include/linux/bits.h index 2b7b532c1d51..669d69441a62 100644 --- a/include/linux/bits.h +++ b/include/linux/bits.h @@ -1,13 +1,15 @@ /* SPDX-License-Identifier: GPL-2.0 */ #ifndef __LINUX_BITS_H #define __LINUX_BITS_H + +#include #include -#define BIT(nr) (1UL << (nr)) -#define BIT_ULL(nr) (1ULL << (nr)) -#define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG)) +#define BIT(nr) (UL(1) << (nr)) +#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) (1ULL << ((nr) % BITS_PER_LONG_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 @@ -17,10 +19,11 @@ * GENMASK_ULL(39, 21) gives us the 64bit vector 0x000000ffffe00000. */ #define GENMASK(h, l) \ - (((~0UL) - (1UL << (l)) + 1) & (~0UL >> (BITS_PER_LONG - 1 - (h)))) + (((~UL(0)) - (UL(1) << (l)) + 1) & \ + (~UL(0) >> (BITS_PER_LONG - 1 - (h)))) #define GENMASK_ULL(h, l) \ - (((~0ULL) - (1ULL << (l)) + 1) & \ - (~0ULL >> (BITS_PER_LONG_LONG - 1 - (h)))) + (((~ULL(0)) - (ULL(1) << (l)) + 1) & \ + (~ULL(0) >> (BITS_PER_LONG_LONG - 1 - (h)))) #endif /* __LINUX_BITS_H */