Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/external/bsd move bitops.h so we can include it from ker...
details: https://anonhg.NetBSD.org/src/rev/86297a890696
branches: trunk
changeset: 992407:86297a890696
user: riastradh <riastradh%NetBSD.org@localhost>
date: Mon Aug 27 06:15:32 2018 +0000
description:
move bitops.h so we can include it from kernel.h
match linux side-loading of this header.
Author: coypu <coypu%sdf.org@localhost>
Committer: Taylor R Campbell <riastradh%NetBSD.org@localhost>
diffstat:
sys/external/bsd/common/include/linux/bitops.h | 186 +++++++++++++++++++++++++
sys/external/bsd/common/include/linux/kernel.h | 3 +-
sys/external/bsd/drm2/include/linux/bitops.h | 186 -------------------------
3 files changed, 188 insertions(+), 187 deletions(-)
diffs (truncated from 397 to 300 lines):
diff -r 97ee127cf905 -r 86297a890696 sys/external/bsd/common/include/linux/bitops.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/external/bsd/common/include/linux/bitops.h Mon Aug 27 06:15:32 2018 +0000
@@ -0,0 +1,186 @@
+/* $NetBSD: bitops.h,v 1.1 2018/08/27 06:15:32 riastradh Exp $ */
+
+/*-
+ * Copyright (c) 2013 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Taylor R. Campbell.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _LINUX_BITOPS_H_
+#define _LINUX_BITOPS_H_
+
+#include <sys/cdefs.h>
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/atomic.h>
+#include <sys/bitops.h>
+
+#include <machine/limits.h>
+
+#include <lib/libkern/libkern.h>
+
+/*
+ * Linux __ffs/__ffs64 is zero-based; zero input is undefined. Our
+ * ffs/ffs64 is one-based; zero input yields zero.
+ */
+static inline unsigned long
+__ffs(unsigned long x)
+{
+
+ KASSERT(x != 0);
+ return ffs64(x) - 1;
+}
+
+static inline unsigned long
+__ffs64(uint64_t x)
+{
+
+ KASSERT(x != 0);
+ return ffs64(x) - 1;
+}
+
+static inline unsigned int
+hweight16(uint16_t n)
+{
+ return popcount32(n);
+}
+
+static inline unsigned int
+hweight32(uint32_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))
+
+#define BIT(n) ((uintmax_t)1 << (n))
+
+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));
+}
+
+static inline unsigned long
+__test_and_set_bit(unsigned int bit, volatile unsigned long *ptr)
+{
+ const unsigned int units = (sizeof(*ptr) * CHAR_BIT);
+ volatile unsigned long *const p = &ptr[bit / units];
+ const unsigned long mask = (1UL << (bit % units));
+ unsigned long v;
+
+ v = *p;
+ *p |= mask;
+
+ return ((v & mask) != 0);
+}
+
+static inline unsigned long
+__test_and_clear_bit(unsigned int bit, volatile unsigned long *ptr)
+{
+ const unsigned int units = (sizeof(*ptr) * CHAR_BIT);
+ volatile unsigned long *const p = &ptr[bit / units];
+ const unsigned long mask = (1UL << (bit % units));
+ unsigned long v;
+
+ v = *p;
+ *p &= ~mask;
+
+ return ((v & mask) != 0);
+}
+
+static inline unsigned long
+__test_and_change_bit(unsigned int bit, volatile unsigned long *ptr)
+{
+ const unsigned int units = (sizeof(*ptr) * CHAR_BIT);
+ volatile unsigned long *const p = &ptr[bit / units];
+ const unsigned long mask = (1UL << (bit % units));
+ unsigned long v;
+
+ v = *p;
+ *p ^= mask;
+
+ return ((v & mask) != 0);
+}
+
+static inline unsigned long
+find_first_zero_bit(const unsigned long *ptr, unsigned long nbits)
+{
+ const size_t bpl = (CHAR_BIT * sizeof(*ptr));
+ const unsigned long *p;
+ unsigned long result = 0;
+
+ for (p = ptr; bpl < nbits; nbits -= bpl, p++, result += bpl) {
+ if (~*p)
+ break;
+ }
+
+ CTASSERT(sizeof(unsigned long) <= sizeof(uint64_t));
+ result += ffs64(~(uint64_t)*p | (~0UL << MIN(nbits, bpl)));
+ return result;
+}
+
+static inline unsigned
+hweight8(unsigned w)
+{
+
+ return popcount(w & 0xff);
+}
+
+#endif /* _LINUX_BITOPS_H_ */
diff -r 97ee127cf905 -r 86297a890696 sys/external/bsd/common/include/linux/kernel.h
--- a/sys/external/bsd/common/include/linux/kernel.h Mon Aug 27 06:08:38 2018 +0000
+++ b/sys/external/bsd/common/include/linux/kernel.h Mon Aug 27 06:15:32 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kernel.h,v 1.12 2018/08/27 06:08:25 riastradh Exp $ */
+/* $NetBSD: kernel.h,v 1.13 2018/08/27 06:15:32 riastradh Exp $ */
/*-
* Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -38,6 +38,7 @@
#include <sys/systm.h>
#include <lib/libkern/libkern.h>
+#include <linux/bitops.h>
#include <linux/printk.h>
#define U16_MAX UINT16_MAX
diff -r 97ee127cf905 -r 86297a890696 sys/external/bsd/drm2/include/linux/bitops.h
--- a/sys/external/bsd/drm2/include/linux/bitops.h Mon Aug 27 06:08:38 2018 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,186 +0,0 @@
-/* $NetBSD: bitops.h,v 1.13 2018/08/06 00:29:57 riastradh Exp $ */
-
-/*-
- * Copyright (c) 2013 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software contributed to The NetBSD Foundation
- * by Taylor R. Campbell.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef _LINUX_BITOPS_H_
-#define _LINUX_BITOPS_H_
-
-#include <sys/cdefs.h>
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/atomic.h>
-#include <sys/bitops.h>
-
-#include <machine/limits.h>
-
-#include <lib/libkern/libkern.h>
-
-/*
- * Linux __ffs/__ffs64 is zero-based; zero input is undefined. Our
- * ffs/ffs64 is one-based; zero input yields zero.
- */
-static inline unsigned long
-__ffs(unsigned long x)
-{
-
- KASSERT(x != 0);
- return ffs64(x) - 1;
-}
-
-static inline unsigned long
-__ffs64(uint64_t x)
-{
-
- KASSERT(x != 0);
- return ffs64(x) - 1;
-}
-
-static inline unsigned int
-hweight16(uint16_t n)
-{
- return popcount32(n);
-}
-
-static inline unsigned int
-hweight32(uint32_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))
-
-#define BIT(n) ((uintmax_t)1 << (n))
-
-static inline int
-test_bit(unsigned int n, const volatile unsigned long *p)
Home |
Main Index |
Thread Index |
Old Index