Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp907049rdb; Tue, 23 Jan 2024 21:02:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IGfEOqrojw1I5f+Q+wS2jJCaF1V2RtKiNJbaHU9wE8QIBJCXb28Xgrzf/O5n3YdtVRICizG X-Received: by 2002:a17:907:9801:b0:a2c:bc3e:1f31 with SMTP id ji1-20020a170907980100b00a2cbc3e1f31mr621671ejc.76.1706072576582; Tue, 23 Jan 2024 21:02:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706072576; cv=pass; d=google.com; s=arc-20160816; b=rPjWVWn367jxGZ1iHuPN7Vb4GgmZy8DbRadXv5jTfVjU9RJeAXhcE6qoTK8XH3wI7/ B4mFmtOmFOITMQQ27i3dimxzxserq2qT1Ze+29uUlP73CGMbuCIiHQsS/fGozN09K/qR RZyhmy4ORxl+r+ChENGH8WDRy0gDM9YVEXRC6g41Q2Ueqy9il/qtHMKdaTHfMatTGsDA snolY1+h9sW6URQGILI4drUCDINJEZcT1RqgcthAAF6q8AvqBgopUGZ+iZQzIqjCm64u +bklPypIrS9h9d7xcpVjQNzoDXkcYtFklJfscwNKunXU7H4cSqXig1qQONL0U1VnE5D/ UL7A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=9frCqJNZ9Ebl8UrjoEJV5vlBplYaNAj2sCVd9+6gDP0=; fh=/FcLXTpjOid3TvFfEUjbYIuo/hdxOddxBi/MbWsARlw=; b=pblF3J+tq/LlpydYsNnsU+WeuorY0SJK9sDhfbAEv7d6c3Ar8NLHe+M61Va/5pb04y 1UxzEbtAaUZjeaVtkTniI5TbMoLeI7LSomlHy3y/Cw/+S6R2HDhdMybzBbfyyL687lfj GoLzqn58jKAKjkKdLjCAup2kD3I+XMgNkiDpzeQBI7Kp4LoYiApcXCj9sWc6MDHjUUpD uTZJXlfa+xWTLFA3zYcLODE3Qf5wog1UF8jXsmL3Bsj5t0mXmHGjvMEt3gu+dcAWirsa fAqm7adZEu5Blm48d4kC+f73rcqak+ip09IRg8ArVuY41lvEjo1oEgIzSO0LqXc4l3lH 2C/g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MrQnhGrA; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-36446-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-36446-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id d4-20020a1709064c4400b00a30fbb98490si676542ejw.281.2024.01.23.21.02.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 21:02:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-36446-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MrQnhGrA; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-36446-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-36446-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 53C691F21C10 for ; Wed, 24 Jan 2024 05:02:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2D50AF9C1; Wed, 24 Jan 2024 05:02:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="MrQnhGrA" Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.115]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9F002C8F1 for ; Wed, 24 Jan 2024 05:02:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.55.52.115 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706072549; cv=none; b=Y3PY0QWGs6xBRpx8wRdvfTDCoswkgJFnnYJoDo7NNy2z8plvYQzEIv6yWh75gr4b0Yrm38L27l1S4/t953kGMiyQtXInwUd3C81b/ZPiZaC/JLPN5QC6W2KZLZZgRjAQr9fk/LyK41frczBhhsT3HbEzVpqquG8uYX7IRsbAhkA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706072549; c=relaxed/simple; bh=fGpX5d8msWVViBqm7sRAsYLfy5pDgJccFA8lspAl428=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uiocoVPPkilVTWn0nUry9KhbceSO61/LbkT4KG4oIcLgKtTYgncSVnaBNUwKWSglQCp1bgy2LksMYxXnucOqOfF7kP5pfYKPbKzTVyeKWHvRypWnJsyEgdRu7Zp2MJmlpNyHVBp0eAOxoWoIxPNQ4PYsmTRyhj+RUUsgulEghEY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=MrQnhGrA; arc=none smtp.client-ip=192.55.52.115 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706072547; x=1737608547; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fGpX5d8msWVViBqm7sRAsYLfy5pDgJccFA8lspAl428=; b=MrQnhGrA6wZIvmbGcsytF5q2nf2KbMhUGpwXbdolK5AlaNHuUqE9Ee6w 91z8AF/a79MuVhQH2x5sA+RzXanK7a6/PF7HjZrD4PmXNtbk5GovONj1S ZDJGLNrKDsaBOj11dkJgL+2JYrdoy5kGM3t0gaF+LUfpIpSZhUkEnKNdL faSa71kUMBaCztDcTuHHH0BbQ2KyX1mlcUP4Oitl7vSEzEx5VshMfegxE jhyYDSBdMWovfNH/clNry/q72YZuHmblNk6LpsJsStdX095CLRdF6gMnU vmVI3Dd30kOgtoqfIiDGdZAa4q+S9rIBwTqVbPwV75zpu05UP7jHfZ5Xy w==; X-IronPort-AV: E=McAfee;i="6600,9927,10962"; a="401399359" X-IronPort-AV: E=Sophos;i="6.05,216,1701158400"; d="scan'208";a="401399359" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jan 2024 21:02:24 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10962"; a="909551505" X-IronPort-AV: E=Sophos;i="6.05,216,1701158400"; d="scan'208";a="909551505" Received: from lucas-s2600cw.jf.intel.com ([10.165.21.196]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jan 2024 21:02:23 -0800 From: Lucas De Marchi To: Yury Norov Cc: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Andy Shevchenko , Jani Nikula , intel-xe@lists.freedesktop.org, intel-gfx@lists.freedesktop.org Subject: [PATCH 1/3] bits: introduce fixed-type genmasks Date: Tue, 23 Jan 2024 21:02:03 -0800 Message-ID: <20240124050205.3646390-2-lucas.demarchi@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240124050205.3646390-1-lucas.demarchi@intel.com> References: <20240124050205.3646390-1-lucas.demarchi@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Yury Norov Generalize __GENMASK() to support different types, and implement fixed-types versions of GENMASK() based on it. The fixed-type version allows more strict checks to the min/max values accepted, which is useful for defining registers like implemented by i915 and xe drivers with their REG_GENMASK*() macros. Signed-off-by: Yury Norov --- include/linux/bitops.h | 1 - include/linux/bits.h | 22 ++++++++++++---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/include/linux/bitops.h b/include/linux/bitops.h index 2ba557e067fe..1db50c69cfdb 100644 --- a/include/linux/bitops.h +++ b/include/linux/bitops.h @@ -15,7 +15,6 @@ # define aligned_byte_mask(n) (~0xffUL << (BITS_PER_LONG - 8 - 8*(n))) #endif -#define BITS_PER_TYPE(type) (sizeof(type) * BITS_PER_BYTE) #define BITS_TO_LONGS(nr) __KERNEL_DIV_ROUND_UP(nr, BITS_PER_TYPE(long)) #define BITS_TO_U64(nr) __KERNEL_DIV_ROUND_UP(nr, BITS_PER_TYPE(u64)) #define BITS_TO_U32(nr) __KERNEL_DIV_ROUND_UP(nr, BITS_PER_TYPE(u32)) diff --git a/include/linux/bits.h b/include/linux/bits.h index 7c0cf5031abe..cb94128171b2 100644 --- a/include/linux/bits.h +++ b/include/linux/bits.h @@ -6,6 +6,8 @@ #include #include +#define BITS_PER_TYPE(type) (sizeof(type) * BITS_PER_BYTE) + #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)) @@ -30,16 +32,16 @@ #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(t, h, l) \ + (GENMASK_INPUT_CHECK(h, l) + \ + (((t)~0ULL - ((t)(1) << (l)) + 1) & \ + ((t)~0ULL >> (BITS_PER_TYPE(t) - 1 - (h))))) -#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)) +#define GENMASK(h, l) __GENMASK(unsigned long, h, l) +#define GENMASK_ULL(h, l) __GENMASK(unsigned long long, h, l) +#define GENMASK_U8(h, l) __GENMASK(u8, h, l) +#define GENMASK_U16(h, l) __GENMASK(u16, h, l) +#define GENMASK_U32(h, l) __GENMASK(u32, h, l) +#define GENMASK_U64(h, l) __GENMASK(u64, h, l) #endif /* __LINUX_BITS_H */ -- 2.43.0