diff --git a/include/asm/hweight.h b/include/asm/hweight.h new file mode 100644 index 0000000..1a43977 --- /dev/null +++ b/include/asm/hweight.h @@ -0,0 +1,8 @@ +#ifndef _KVM_ASM_HWEIGHT_H_ +#define _KVM_ASM_HWEIGHT_H_ + +#include +unsigned int hweight32(unsigned int w); +unsigned long hweight64(__u64 w); + +#endif /* _KVM_ASM_HWEIGHT_H_ */ diff --git a/include/kvm/barrier.h b/include/kvm/barrier.h new file mode 100644 index 0000000..c11a239 --- /dev/null +++ b/include/kvm/barrier.h @@ -0,0 +1,15 @@ +#ifndef _KVM_BARRIER_H_ +#define _KVM_BARRIER_H_ + +/* + * asm/system.h cannot be #included standalone on 32-bit x86 yet. + * + * Provide the dependencies here - we can drop these wrappers once + * the header is fixed upstream: + */ +#include +#include +#include +#include + +#endif /* _KVM_BARRIER_H_ */ diff --git a/include/linux/bitops.h b/include/linux/bitops.h new file mode 100644 index 0000000..56448b7 --- /dev/null +++ b/include/linux/bitops.h @@ -0,0 +1,33 @@ +#ifndef _KVM_LINUX_BITOPS_H_ +#define _KVM_LINUX_BITOPS_H_ + +#include +#include +#include + +#define BITS_PER_LONG __WORDSIZE +#define BITS_PER_BYTE 8 +#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long)) + +static inline void set_bit(int nr, unsigned long *addr) +{ + addr[nr / BITS_PER_LONG] |= 1UL << (nr % BITS_PER_LONG); +} + +static inline void clear_bit(int nr, unsigned long *addr) +{ + addr[nr / BITS_PER_LONG] &= ~(1UL << (nr % BITS_PER_LONG)); +} + +static __always_inline int test_bit(unsigned int nr, const unsigned long *addr) +{ + return ((1UL << (nr % BITS_PER_LONG)) & + (((unsigned long *)addr)[nr / BITS_PER_LONG])) != 0; +} + +static inline unsigned long hweight_long(unsigned long w) +{ + return sizeof(w) == 4 ? hweight32(w) : hweight64(w); +} + +#endif diff --git a/virtio.c b/virtio.c index 266a1b6..4dcd092 100644 --- a/virtio.c +++ b/virtio.c @@ -1,7 +1,9 @@ #include #include #include -#include + +#include "kvm/barrier.h" + #include "kvm/kvm.h" #include "kvm/virtio.h"