Module Name: src Committed By: riastradh Date: Sun Sep 8 15:37:34 UTC 2013
Modified Files: src/sys/external/bsd/drm2/include/linux [riastradh-drm2]: bitops.h Log Message: Add Linuxoid non-atomic __set/clear_bit to <linux/bitops.h>. To generate a diff of this commit: cvs rdiff -u -r1.1.2.2 -r1.1.2.3 \ src/sys/external/bsd/drm2/include/linux/bitops.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/external/bsd/drm2/include/linux/bitops.h diff -u src/sys/external/bsd/drm2/include/linux/bitops.h:1.1.2.2 src/sys/external/bsd/drm2/include/linux/bitops.h:1.1.2.3 --- src/sys/external/bsd/drm2/include/linux/bitops.h:1.1.2.2 Wed Jul 24 03:44:39 2013 +++ src/sys/external/bsd/drm2/include/linux/bitops.h Sun Sep 8 15:37:34 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: bitops.h,v 1.1.2.2 2013/07/24 03:44:39 riastradh Exp $ */ +/* $NetBSD: bitops.h,v 1.1.2.3 2013/09/08 15:37:34 riastradh Exp $ */ /*- * Copyright (c) 2013 The NetBSD Foundation, Inc. @@ -32,6 +32,13 @@ #ifndef _LINUX_BITOPS_H_ #define _LINUX_BITOPS_H_ +#include <sys/types.h> +#include <sys/param.h> +#include <sys/atomic.h> +#include <sys/cdefs.h> + +#include <machine/limits.h> + #include <lib/libkern/libkern.h> static inline unsigned int @@ -40,4 +47,45 @@ hweight16(uint16_t n) return popcount32(n); } +/* + * XXX Don't define BITS_PER_LONG as sizeof(unsigned long)*CHAR_BIT + * because that won't work in preprocessor conditionals, where it often + * turns up. + */ + +#define BITS_TO_LONGS(n) \ + roundup2((n), (sizeof(unsigned long) * CHAR_BIT)) + +static inline int +test_bit(unsigned int n, const volatile unsigned long *p) +{ + const unsigned units = (sizeof(unsigned long) * CHAR_BIT); + + return ((p[n / units] & (1UL << (n % units))) != 0); +} + +static inline void +__set_bit(unsigned int n, volatile unsigned long *p) +{ + const unsigned units = (sizeof(unsigned long) * CHAR_BIT); + + p[n / units] |= (1UL << (n % units)); +} + +static inline void +__clear_bit(unsigned int n, volatile unsigned long *p) +{ + const unsigned units = (sizeof(unsigned long) * CHAR_BIT); + + p[n / units] &= ~(1UL << (n % units)); +} + +static inline void +__change_bit(unsigned int n, volatile unsigned long *p) +{ + const unsigned units = (sizeof(unsigned long) * CHAR_BIT); + + p[n / units] ^= (1UL << (n % units)); +} + #endif /* _LINUX_BITOPS_H_ */