Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/external/bsd gfp.h and slab.h are now used in kernel.h, ...
details: https://anonhg.NetBSD.org/src/rev/1158cc31f2b3
branches: trunk
changeset: 366431:1158cc31f2b3
user: riastradh <riastradh%NetBSD.org@localhost>
date: Mon Aug 27 15:45:06 2018 +0000
description:
gfp.h and slab.h are now used in kernel.h, so move to common.
diffstat:
sys/external/bsd/common/include/linux/gfp.h | 74 +++++++++
sys/external/bsd/common/include/linux/slab.h | 209 +++++++++++++++++++++++++++
sys/external/bsd/drm2/include/linux/gfp.h | 74 ---------
sys/external/bsd/drm2/include/linux/slab.h | 209 ---------------------------
4 files changed, 283 insertions(+), 283 deletions(-)
diffs (truncated from 582 to 300 lines):
diff -r f6805a7395ed -r 1158cc31f2b3 sys/external/bsd/common/include/linux/gfp.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/external/bsd/common/include/linux/gfp.h Mon Aug 27 15:45:06 2018 +0000
@@ -0,0 +1,74 @@
+/* $NetBSD: gfp.h,v 1.1 2018/08/27 15:45:06 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_GFP_H_
+#define _LINUX_GFP_H_
+
+/* GFP: `Get Free Page' */
+
+#include <sys/param.h>
+#include <sys/cdefs.h>
+
+typedef int gfp_t;
+
+#define GFP_ATOMIC (__GFP_HIGH)
+#define GFP_DMA32 (__GFP_DMA32)
+#define GFP_HIGHUSER (__GFP_FS | __GFP_HARDWALL | __GFP_HIGHMEM | \
+ __GFP_IO | __GFP_WAIT)
+#define GFP_KERNEL (__GFP_FS | __GFP_IO | __GFP_WAIT)
+#define GFP_TEMPORARY (__GFP_FS | __GFP_IO | __GFP_RECLAIMABLE | __GFP_WAIT)
+#define GFP_USER (__GFP_FS | __GFP_HARDWALL | __GFP_IO | __GFP_WAIT)
+
+#define GFP_NOWAIT (GFP_ATOMIC & ~__GFP_HIGH)
+
+#define __GFP_COMP __BIT(0)
+#define __GFP_DMA32 __BIT(1)
+#define __GFP_FS __BIT(2)
+#define __GFP_HARDWALL __BIT(3)
+#define __GFP_HIGH __BIT(4)
+#define __GFP_HIGHMEM __BIT(5)
+#define __GFP_IO __BIT(6)
+#define __GFP_NORETRY __BIT(7)
+#define __GFP_NOWARN __BIT(8)
+#define __GFP_NO_KSWAPD __BIT(9)
+#define __GFP_RECLAIMABLE __BIT(10)
+#define __GFP_WAIT __BIT(11)
+#define __GFP_ZERO __BIT(12)
+
+/*
+ * XXX Linux sez nobody should be using this in new code. We never
+ * fail in the wait case anyway, so the point is moot.
+ */
+#define __GFP_NOFAIL 0
+
+struct page;
+
+#endif /* _LINUX_GFP_H_ */
diff -r f6805a7395ed -r 1158cc31f2b3 sys/external/bsd/common/include/linux/slab.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/external/bsd/common/include/linux/slab.h Mon Aug 27 15:45:06 2018 +0000
@@ -0,0 +1,209 @@
+/* $NetBSD: slab.h,v 1.1 2018/08/27 15:45:06 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_SLAB_H_
+#define _LINUX_SLAB_H_
+
+#include <sys/kmem.h>
+#include <sys/malloc.h>
+
+#include <machine/limits.h>
+
+#include <uvm/uvm_extern.h> /* For PAGE_SIZE. */
+
+#include <linux/gfp.h>
+
+/* XXX Should use kmem, but Linux kfree doesn't take the size. */
+
+static inline int
+linux_gfp_to_malloc(gfp_t gfp)
+{
+ int flags = 0;
+
+ /* This has no meaning to us. */
+ gfp &= ~__GFP_NOWARN;
+ gfp &= ~__GFP_RECLAIMABLE;
+
+ /* Pretend this was the same as not passing __GFP_WAIT. */
+ if (ISSET(gfp, __GFP_NORETRY)) {
+ gfp &= ~__GFP_NORETRY;
+ gfp &= ~__GFP_WAIT;
+ }
+
+ if (ISSET(gfp, __GFP_ZERO)) {
+ flags |= M_ZERO;
+ gfp &= ~__GFP_ZERO;
+ }
+
+ /*
+ * XXX Handle other cases as they arise -- prefer to fail early
+ * rather than allocate memory without respecting parameters we
+ * don't understand.
+ */
+ KASSERT((gfp == GFP_ATOMIC) ||
+ ((gfp & ~__GFP_WAIT) == (GFP_KERNEL & ~__GFP_WAIT)));
+
+ if (ISSET(gfp, __GFP_WAIT)) {
+ flags |= M_WAITOK;
+ gfp &= ~__GFP_WAIT;
+ } else {
+ flags |= M_NOWAIT;
+ }
+
+ return flags;
+}
+
+/*
+ * XXX vmalloc and kmalloc both use malloc(9). If you change this, be
+ * sure to update vmalloc in <linux/vmalloc.h> and kvfree in
+ * <linux/mm.h>.
+ */
+
+static inline void *
+kmalloc(size_t size, gfp_t gfp)
+{
+ return malloc(size, M_TEMP, linux_gfp_to_malloc(gfp));
+}
+
+static inline void *
+kzalloc(size_t size, gfp_t gfp)
+{
+ return malloc(size, M_TEMP, (linux_gfp_to_malloc(gfp) | M_ZERO));
+}
+
+static inline void *
+kmalloc_array(size_t n, size_t size, gfp_t gfp)
+{
+ if ((size != 0) && (n > (SIZE_MAX / size)))
+ return NULL;
+ return malloc((n * size), M_TEMP, linux_gfp_to_malloc(gfp));
+}
+
+static inline void *
+kcalloc(size_t n, size_t size, gfp_t gfp)
+{
+ return kmalloc_array(n, size, (gfp | __GFP_ZERO));
+}
+
+static inline void *
+krealloc(void *ptr, size_t size, gfp_t gfp)
+{
+ return realloc(ptr, size, M_TEMP, linux_gfp_to_malloc(gfp));
+}
+
+static inline void
+kfree(void *ptr)
+{
+ if (ptr != NULL)
+ free(ptr, M_TEMP);
+}
+
+#define SLAB_HWCACHE_ALIGN 1
+
+struct kmem_cache {
+ pool_cache_t kc_pool_cache;
+ size_t kc_size;
+ void (*kc_ctor)(void *);
+};
+
+static int
+kmem_cache_ctor(void *cookie, void *ptr, int flags __unused)
+{
+ struct kmem_cache *const kc = cookie;
+
+ if (kc->kc_ctor)
+ (*kc->kc_ctor)(ptr);
+
+ return 0;
+}
+
+static inline struct kmem_cache *
+kmem_cache_create(const char *name, size_t size, size_t align,
+ unsigned long flags, void (*ctor)(void *))
+{
+ struct kmem_cache *kc;
+
+ if (ISSET(flags, SLAB_HWCACHE_ALIGN))
+ align = roundup(MAX(1, align), CACHE_LINE_SIZE);
+
+ kc = kmem_alloc(sizeof(*kc), KM_SLEEP);
+ kc->kc_pool_cache = pool_cache_init(size, align, 0, 0, name, NULL,
+ IPL_NONE, &kmem_cache_ctor, NULL, kc);
+ kc->kc_size = size;
+ kc->kc_ctor = ctor;
+
+ return kc;
+}
+
+static inline void
+kmem_cache_destroy(struct kmem_cache *kc)
+{
+
+ pool_cache_destroy(kc->kc_pool_cache);
+ kmem_free(kc, sizeof(*kc));
+}
+
+static inline void *
+kmem_cache_alloc(struct kmem_cache *kc, gfp_t gfp)
+{
+ int flags = 0;
+ void *ptr;
+
+ if (gfp & __GFP_WAIT)
+ flags |= PR_NOWAIT;
+ else
+ flags |= PR_WAITOK;
+
+ ptr = pool_cache_get(kc->kc_pool_cache, flags);
+ if (ptr == NULL)
+ return NULL;
+
+ if (ISSET(gfp, __GFP_ZERO))
+ (void)memset(ptr, 0, kc->kc_size);
+
+ return ptr;
+}
+
+static inline void *
+kmem_cache_zalloc(struct kmem_cache *kc, gfp_t gfp)
+{
+
+ return kmem_cache_alloc(kc, (gfp | __GFP_ZERO));
+}
+
+static inline void
+kmem_cache_free(struct kmem_cache *kc, void *ptr)
+{
+
+ pool_cache_put(kc->kc_pool_cache, ptr);
+}
+
+#endif /* _LINUX_SLAB_H_ */
diff -r f6805a7395ed -r 1158cc31f2b3 sys/external/bsd/drm2/include/linux/gfp.h
--- a/sys/external/bsd/drm2/include/linux/gfp.h Mon Aug 27 15:43:37 2018 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,74 +0,0 @@
-/* $NetBSD: gfp.h,v 1.6 2018/08/27 06:56:31 riastradh Exp $ */
-
-/*-
- * Copyright (c) 2013 The NetBSD Foundation, Inc.
- * All rights reserved.
Home |
Main Index |
Thread Index |
Old Index