Add GENMASK macros
authorYann Gautier <[email protected]>
Thu, 14 Jun 2018 16:35:33 +0000 (18:35 +0200)
committerYann Gautier <[email protected]>
Thu, 14 Jun 2018 16:35:33 +0000 (18:35 +0200)
Import GENMASK_32 and GENMASK_64 macros from optee-os (permissive license).
And default GENMASK is set to GENMASK_32 for AARCH32,
and to GENMASK_64 for 64bit arch.

fixes arm-software/tf-issues#596

Signed-off-by: Yann Gautier <[email protected]>
Signed-off-by: Nicolas Le Bayon <[email protected]>
include/lib/utils_def.h

index 31b129454a0dbf83b4aad31ee6f460293e127462..2975103f5e14629b598897c52eecc2f9cd4458a1 100644 (file)
 
 #define BIT(nr)                                (ULL(1) << (nr))
 
+/*
+ * Create a contiguous bitmask starting at bit position @l and ending at
+ * position @h. For example
+ * GENMASK_64(39, 21) gives us the 64bit vector 0x000000ffffe00000.
+ */
+#define GENMASK_32(h, l) \
+       (((~UINT32_C(0)) << (l)) & (~UINT32_C(0) >> (32 - 1 - (h))))
+
+#define GENMASK_64(h, l) \
+       (((~UINT64_C(0)) << (l)) & (~UINT64_C(0) >> (64 - 1 - (h))))
+
+#ifdef AARCH32
+#define GENMASK                                GENMASK_32
+#else
+#define GENMASK                                GENMASK_64
+#endif
+
 /*
  * This variant of div_round_up can be used in macro definition but should not
  * be used in C code as the `div` parameter is evaluated twice.