Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1710684 > unrolled thread

Re: [PATCH v6 02/17] powerpc/vas: Move GET_FIELD/SET_FIELD to vas.h

Started byMichael Ellerman <mpe@ellerman.id.au>
First post2017-08-14 09:30 +0200
Last post2017-08-14 09:30 +0200
Articles 1 — 1 participant

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: [PATCH v6 02/17] powerpc/vas: Move GET_FIELD/SET_FIELD to vas.h Michael Ellerman <mpe@ellerman.id.au> - 2017-08-14 09:30 +0200

#1710684 — Re: [PATCH v6 02/17] powerpc/vas: Move GET_FIELD/SET_FIELD to vas.h

FromMichael Ellerman <mpe@ellerman.id.au>
Date2017-08-14 09:30 +0200
SubjectRe: [PATCH v6 02/17] powerpc/vas: Move GET_FIELD/SET_FIELD to vas.h
Message-ID<uehZ0-1bj-19@gated-at.bofh.it>
Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com> writes:

> Move the GET_FIELD and SET_FIELD macros to vas.h as VAS and other
> users of VAS, including NX-842 can use those macros.
>
> There is a lot of related code between the VAS/NX kernel drivers
> and skiboot. For consistency switch the order of parameters in
> SET_FIELD to match the order in skiboot.
>
> Signed-off-by: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
> Reviewed-by: Dan Streetman <ddstreet@ieee.org>

> diff --git a/arch/powerpc/include/uapi/asm/vas.h b/arch/powerpc/include/uapi/asm/vas.h
> index ddfe046..21249f5 100644
> --- a/arch/powerpc/include/uapi/asm/vas.h
> +++ b/arch/powerpc/include/uapi/asm/vas.h
> @@ -22,4 +22,12 @@
>  #define VAS_THRESH_FIFO_GT_QTR_FULL	2
>  #define VAS_THRESH_FIFO_GT_EIGHTH_FULL	3
>  
> +/*
> + * Get/Set bit fields
> + */
> +#define GET_FIELD(m, v)		(((v) & (m)) >> MASK_LSH(m))
> +#define MASK_LSH(m)		(__builtin_ffsl(m) - 1)
> +#define SET_FIELD(m, v, val)	\
> +		(((v) & ~(m)) | ((((typeof(v))(val)) << MASK_LSH(m)) & (m)))

This has no business being in a uapi header for VAS.

Put it in asm/vas.h if you must.

Personally I really dislike these sort of macros because they completely
obscure what the final value should end up being, and it's the final
value you'll see when you're debugging it.

> +	ccw = SET_FIELD(CCW_CT, ccw, nx842_ct);
> +	ccw = SET_FIELD(CCW_CI_842, ccw, 0); /* use 0 for hw auto-selection */
> +	ccw = SET_FIELD(CCW_FC_842, ccw, fc);

eg. that could also be written:

       ccw = (nx842_ct << 16) | (fc & 7);

cheers

[toc] | [standalone]


Back to top | Article view | linux.kernel


csiph-web