From: Jani Nikula <jani.nikula@intel.com>
To: Michal Wajdeczko <michal.wajdeczko@intel.com>,
intel-gfx@lists.freedesktop.org
Subject: Re: [PATCH v3 1/3] drm/i915: introduce REG_BIT() and REG_GENMASK() to define register contents
Date: Thu, 28 Feb 2019 12:07:06 +0200 [thread overview]
Message-ID: <87lg20ns51.fsf@intel.com> (raw)
In-Reply-To: <op.zxv7sohvxaggs7@mwajdecz-mobl1.ger.corp.intel.com>
On Thu, 28 Feb 2019, Michal Wajdeczko <michal.wajdeczko@intel.com> wrote:
> On Wed, 27 Feb 2019 18:02:36 +0100, Jani Nikula <jani.nikula@intel.com>
> wrote:
>
>> @@ -116,6 +116,34 @@
>> * #define GEN8_BAR _MMIO(0xb888)
>> */
>> +/**
>> + * REG_BIT() - Prepare a u32 bit value
>> + * @__n: 0-based bit number
>> + *
>> + * Local wrapper for BIT() to force u32, with compile time checks.
>> + *
>> + * @return: Value with bit @__n set.
>> + */
>> +#define REG_BIT(__n) \
>> + ((u32)(BIT(__n) + \
>> + BUILD_BUG_ON_ZERO(__builtin_constant_p(__n) && \
>> + ((__n) < 0 || (__n) > 31))))
>
> Maybe to simplify the code we can define this macro using macro below:
>
> #define REG_BIT(__n) REG_GENMASK(__n, __n)
I don't want to limit the macro to constant expressions (even if that's
the most common use for us), and in non-constant expressions the simple
shift becomes unnecessarily complicated with GENMASK. Plus there's the
double evaluation of __n.
>
>> +
>> +/**
>> + * REG_GENMASK() - Prepare a continuous u32 bitmask
>> + * @__high: 0-based high bit
>> + * @__low: 0-based low bit
>> + *
>> + * Local wrapper for GENMASK() to force u32, with compile time checks.
>> + *
>> + * @return: Continuous bitmask from @__high to @__low, inclusive.
>> + */
>> +#define REG_GENMASK(__high, __low) \
>> + ((u32)(GENMASK(__high, __low) + \
>> + BUILD_BUG_ON_ZERO(__builtin_constant_p(__high) && \
>> + __builtin_constant_p(__low) && \
>> + ((__low) < 0 || (__high) > 31 || (__low) > (__high)))))
>> +
>
> nit: Since we are defining new set of macros, do we really have to follow
> naming of the underlying macros? maybe we can can have clear new names:
>
> REG_BIT(n)
> REG_BITS(hi,low)
We've pretty much been having this conversation ever since the first RFC
was posted. It could be BITS, MASK, GENMASK, FIELD (except that clashes
with REG_FIELD from regmap.h), BITFIELD, whatnot. And next thing you
know, we look at REG_FIELD_PREP and REG_FIELD_GET and wonder if we
should have our own names for them too. REG_BITS_PREP? REG_BITS_VALUE?
REG_BITS_GET?
We *might* be able to come up with internally consistent naming
everyone's happy with, and have those names grow on people, but based on
the discussion so far I'm not optimistic.
So basically I gave up on that, and with the current proposal, the names
are the same as the widely used kernel macros, with REG_ prefix
added. If you know what they do, you know what these do. It's still
consistent, just in a different way.
Also, I pretty much expect our code outside of i915_reg.h to use a mix
of our versions and the underlying ones. And I'm not sure I want to
start policing people to use our versions exclusively. If the names
differ only with the REG_ part, I think the mix will be much easier to
live with.
BR,
Jani.
>
> Thanks,
> Michal
>
--
Jani Nikula, Intel Open Source Graphics Center
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
next prev parent reply other threads:[~2019-02-28 10:05 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-27 17:02 [PATCH v3 0/3] drm/i915: introduce macros to define register contents Jani Nikula
2019-02-27 17:02 ` [PATCH v3 1/3] drm/i915: introduce REG_BIT() and REG_GENMASK() " Jani Nikula
2019-02-27 20:50 ` Chris Wilson
2019-02-27 21:13 ` Ville Syrjälä
2019-02-27 23:06 ` Michal Wajdeczko
2019-02-28 10:07 ` Jani Nikula [this message]
2019-02-28 10:12 ` Chris Wilson
2019-02-28 11:12 ` Michal Wajdeczko
2019-02-27 17:02 ` [PATCH v3 2/3] drm/i915: deprecate _SHIFT in favor of _MASK passed to accessors Jani Nikula
2019-02-27 20:58 ` Chris Wilson
2019-02-27 17:02 ` [PATCH v3 3/3] drm/i915: use REG_FIELD_PREP() to define register bitfield values Jani Nikula
2019-02-27 21:07 ` Chris Wilson
2019-02-27 21:11 ` Ville Syrjälä
2019-02-28 0:17 ` Michal Wajdeczko
2019-02-28 10:24 ` Jani Nikula
2019-02-28 11:38 ` Michal Wajdeczko
2019-02-28 13:48 ` Jani Nikula
2019-02-28 4:49 ` kbuild test robot
2019-02-27 17:44 ` ✗ Fi.CI.CHECKPATCH: warning for drm/i915: introduce macros to define register contents (rev3) Patchwork
2019-02-27 17:46 ` ✗ Fi.CI.SPARSE: " Patchwork
2019-02-27 18:20 ` ✓ Fi.CI.BAT: success " Patchwork
2019-02-27 20:13 ` ✓ Fi.CI.IGT: " Patchwork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87lg20ns51.fsf@intel.com \
--to=jani.nikula@intel.com \
--cc=intel-gfx@lists.freedesktop.org \
--cc=michal.wajdeczko@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.