[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <8737m3bsau.fsf@kamboji.qca.qualcomm.com>
Date: Wed, 17 Aug 2016 13:31:21 +0300
From: Kalle Valo <kvalo@...eaurora.org>
To: torvalds@...ux-foundation.org, akpm@...ux-foundation.org,
gregkh@...uxfoundation.org, davem@...emloft.net
Cc: linux-wireless@...r.kernel.org, linux-kernel@...r.kernel.org,
dinan.gunawardena@...ronome.com,
Jakub Kicinski <jakub.kicinski@...ronome.com>
Subject: Re: [PATCHv6 1/2] add basic register-field manipulation macros
Jakub Kicinski <jakub.kicinski@...ronome.com> writes:
> Common approach to accessing register fields is to define
> structures or sets of macros containing mask and shift pair.
> Operations on the register are then performed as follows:
>
> field = (reg >> shift) & mask;
>
> reg &= ~(mask << shift);
> reg |= (field & mask) << shift;
>
> Defining shift and mask separately is tedious. Ivo van Doorn
> came up with an idea of computing them at compilation time
> based on a single shifted mask (later refined by Felix) which
> can be used like this:
>
> #define REG_FIELD 0x000ff000
>
> field = FIELD_GET(REG_FIELD, reg);
>
> reg &= ~REG_FIELD;
> reg |= FIELD_PUT(REG_FIELD, field);
>
> FIELD_{GET,PUT} macros take care of finding out what the
> appropriate shift is based on compilation time ffs operation.
>
> GENMASK can be used to define registers (which is usually
> less error-prone and easier to match with datasheets).
>
> This approach is the most convenient I've seen so to limit code
> multiplication let's move the macros to a global header file.
> Attempts to use static inlines instead of macros failed due
> to false positive triggering of BUILD_BUG_ON()s, especially with
> GCC < 6.0.
>
> Signed-off-by: Jakub Kicinski <jakub.kicinski@...ronome.com>
> Reviewed-by: Dinan Gunawardena <dinan.gunawardena@...ronome.com>
Are people ok with this? I think they are useful and I can take these
through my tree, but I would prefer to get an ack from other maintainers
first. Dave? Andrew?
Full patches here:
https://patchwork.kernel.org/patch/9284153/
https://patchwork.kernel.org/patch/9284155/
--
Kalle Valo
Powered by blists - more mailing lists