lib: Import few bitmap functions from Linux

Import few basic bitmap functions (bitmap_{weight,fill,set,clear,or}())
and their dependencies from Linux. These are required for upcoming DMA
resource allocation support for TI's K3 SoCs.

Signed-off-by: Vignesh Raghavendra <vigneshr@ti.com>
Reviewed-by: Grygorii Strashko <grygorii.strashko@ti.com>
Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>
This commit is contained in:
Vignesh Raghavendra 2019-12-09 10:25:31 +05:30 committed by Lokesh Vutla
parent 0a7886c84d
commit 016e6d6a4f
2 changed files with 145 additions and 0 deletions

View file

@ -4,6 +4,7 @@
#include <asm/types.h>
#include <asm-generic/bitsperlong.h>
#include <linux/compiler.h>
#include <linux/kernel.h>
#ifdef __KERNEL__
#define BIT(nr) (1UL << (nr))
@ -133,6 +134,17 @@ static inline unsigned int generic_hweight8(unsigned int w)
return (res & 0x0F) + ((res >> 4) & 0x0F);
}
static inline unsigned long generic_hweight64(__u64 w)
{
return generic_hweight32((unsigned int)(w >> 32)) +
generic_hweight32((unsigned int)w);
}
static inline unsigned long hweight_long(unsigned long w)
{
return sizeof(w) == 4 ? generic_hweight32(w) : generic_hweight64(w);
}
#include <asm/bitops.h>
/* linux/include/asm-generic/bitops/non-atomic.h */