Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp965173rdb; Tue, 23 Jan 2024 23:59:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IHq4gGIMEsqVcOQ1+ftwzc6B/GIlabhw7WKI/vVeclTujjA+8gQgSHi7Q+WcXV4WGaeyYWx X-Received: by 2002:ae9:e643:0:b0:783:ab18:976c with SMTP id x3-20020ae9e643000000b00783ab18976cmr2221512qkl.13.1706083145329; Tue, 23 Jan 2024 23:59:05 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706083145; cv=pass; d=google.com; s=arc-20160816; b=rqCsQql6ro+S2GysROo8E7inSUOKLcPLrmkrbcQJuLhhPs4NTfTZOfuO9KlD3PaL6C p5Vr4m/sA7Hj4HFh40e4j9FPlpzcpPdmbvf4jreaQaoMK768EfkFMd+vdqzfPapgecJu jXw2w9qE7jDPHRzzkOSIcegVqP96EUNfXa70dDvnpLsZkK0ef5dMXr057qu1zAJGUAs0 fRVCkCEmx1i1kmnaLmpFSTGmkLAy//1uscumsGkvvxK8QzStLgFpD4XUjIMtExec0nEk Nn6ZLpEgiy95kwc3qIRb/nkS0LqWzKP3kWJXgTQwot92BjtUz2RlgVHD6n6SaeOIyANr fjfw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :message-id:date:references:organization:in-reply-to:subject:cc:to :from:dkim-signature; bh=f7KcKQJ+y6yHr+2QzoUZ2xQu+FwePWAXmRhe6Dbna70=; fh=h+eWT6J4VsJyFf/gGbaXGPUmdvTppNJ0nCPoXwQkd3Q=; b=imDZ0zeXedMvq7BGal9GUHpkGLtLESS3lKzZU0RFSvq/K/AsB1ktVGf7CtbQwcjYNs SEr6Ps2HTs+0ZlUL4n/TR6W9Bv41whfiIIyR9JQgc4e7aHrN/DHiuO6ZQXs8VaXD0nGq Igz5tAVEgwZ+qjcj8ylcPa39nQBQdHqhImWsDNhiK8Fv0YL6awu+AH/QZ19T1FrnmUiJ jGb5aE3vDk2hZEFCb1FWvSzX+s3Ls7xBSRFAtf1ISATOtCtvi5Xu6HbSNcjPXOqA653y Ilh1tH0kmW80Dae0uPcNjqk82KDNjjQ4xUaN7sRzVIE/W834sMsQly9wKhkvFEBRP6Ih ongQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=VnnRLoV8; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-36600-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-36600-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id x1-20020a05620a098100b007834a7b552fsi9364641qkx.289.2024.01.23.23.59.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 23:59:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-36600-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=VnnRLoV8; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-36600-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-36600-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id D8F651C21786 for ; Wed, 24 Jan 2024 07:59:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E4F5C1754F; Wed, 24 Jan 2024 07:58:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="VnnRLoV8" Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) (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 9D2A91754A for ; Wed, 24 Jan 2024 07:58:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=134.134.136.20 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706083138; cv=none; b=tsZFjV5fYNX6Y2VMVms2yMGZ1MekP+CNyo1lo2Mv5wwbf7W/JVWaHVcqlM1NTRujOP43Jo+1bm+C/NNWyRdeOyMrMP5UqUk2Bav2N70nUcLLvkBZnSZ6KyvQA0f4XqCx5veDWMPE3SrKe0yvlLA0Tb93bqVj38A49Qqu0ktygoE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706083138; c=relaxed/simple; bh=315CdLizWLGLXyaVNYVsttdv0aOnIMeQbKpRicgFKUQ=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=JmRZj1QnBxIIsaQghYog2MY8WE+6zgWzTeybVyoiFX5eo/6LRpCRDOzQis92J9UgW3f/U8f9KClQUJBEmimSFOwElCfsQ3zzFdCdQFU4hzYdpfQ53LiotqqyppJM5k6H4fA9ihhfX1ij0ONQqwDtB9JdfB5M4PZ4kZYSEpi3Ins= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=VnnRLoV8; arc=none smtp.client-ip=134.134.136.20 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.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=1706083135; x=1737619135; h=from:to:cc:subject:in-reply-to:references:date: message-id:mime-version; bh=315CdLizWLGLXyaVNYVsttdv0aOnIMeQbKpRicgFKUQ=; b=VnnRLoV8kVcP1n4rC0b0idnor2QrfNfgaMsBMOo7mUvFsR8geI6kzRNO TloMEfHGaAVUgknDOWcu24ef3/xp2Rx3g8lctsiGHeWlRYhDZBbDZyEsT Cx2belT/WRAd2W/jcO27WAOJx3yixP+W0uwbGGTZHXFYI88fVsdllZRUH 3s5WLaeEtyKfudRzv9ddHekfhsyFqb192jNXZaJ1vNOaQTw6WU3h+XIWs VuTC360E2do/TC41xPqgowY1+37Zu4Q89A07Qxoj/64LOFaBLq6CcTCJB mMmFbaJ5BcaDM/cw0wTH9aAB1ztB4XoJ+ckTHox8Nkq2ErUSsLAuqQQcD A==; X-IronPort-AV: E=McAfee;i="6600,9927,10962"; a="392188418" X-IronPort-AV: E=Sophos;i="6.05,216,1701158400"; d="scan'208";a="392188418" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jan 2024 23:58:32 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,216,1701158400"; d="scan'208";a="1926470" Received: from komalav-mobl2.gar.corp.intel.com (HELO localhost) ([10.252.41.195]) by orviesa004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jan 2024 23:58:29 -0800 From: Jani Nikula To: Lucas De Marchi , Yury Norov Cc: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Andy Shevchenko , intel-xe@lists.freedesktop.org, intel-gfx@lists.freedesktop.org Subject: Re: [PATCH 1/3] bits: introduce fixed-type genmasks In-Reply-To: <20240124050205.3646390-2-lucas.demarchi@intel.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo References: <20240124050205.3646390-1-lucas.demarchi@intel.com> <20240124050205.3646390-2-lucas.demarchi@intel.com> Date: Wed, 24 Jan 2024 09:58:26 +0200 Message-ID: <87v87jkvrx.fsf@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain On Tue, 23 Jan 2024, Lucas De Marchi wrote: > 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. Mmh, the commit message says the fixed-type version allows more strict checks, but none are actually added. GENMASK_INPUT_CHECK() remains the same. Compared to the i915 and xe versions, this is more lax now. You could specify GENMASK_U32(63,32) without complaints. BR, Jani. > > 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 */ -- Jani Nikula, Intel