Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/riastradh-drm2]: src/sys/external/bsd/drm2/include/linux Move GFP (`get ...



details:   https://anonhg.NetBSD.org/src/rev/35e16cbad60d
branches:  riastradh-drm2
changeset: 788378:35e16cbad60d
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Wed Jul 24 03:30:42 2013 +0000

description:
Move GFP (`get free page') constants to <linux/gfp.h>.

Declare alloc_page and __free_page there too, to be implemented soon.

diffstat:

 sys/external/bsd/drm2/include/linux/gfp.h  |  71 ++++++++++++++++++++++++++++++
 sys/external/bsd/drm2/include/linux/slab.h |  46 +++++++++++++-----
 2 files changed, 103 insertions(+), 14 deletions(-)

diffs (150 lines):

diff -r c213a0446298 -r 35e16cbad60d sys/external/bsd/drm2/include/linux/gfp.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/external/bsd/drm2/include/linux/gfp.h Wed Jul 24 03:30:42 2013 +0000
@@ -0,0 +1,71 @@
+/*     $NetBSD: gfp.h,v 1.1.2.1 2013/07/24 03:30:42 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_KERNEL      (__GFP_FS | __GFP_IO | __GFP_WAIT)
+#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_USER        (__GFP_FS | __GFP_HARDWALL | __GFP_IO | __GFP_WAIT)
+
+#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 Make the nm output a little more greppable...  */
+#define        alloc_page      linux_gfp_alloc_page
+#define        __free_page     linux_gfp___free_page
+
+struct page;
+struct page *  alloc_page(gfp_t);
+void           __free_page(struct page *);
+
+#endif /* _LINUX_GFP_H_ */
diff -r c213a0446298 -r 35e16cbad60d sys/external/bsd/drm2/include/linux/slab.h
--- a/sys/external/bsd/drm2/include/linux/slab.h        Wed Jul 24 03:30:19 2013 +0000
+++ b/sys/external/bsd/drm2/include/linux/slab.h        Wed Jul 24 03:30:42 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: slab.h,v 1.1.2.5 2013/07/24 02:37:13 riastradh Exp $   */
+/*     $NetBSD: slab.h,v 1.1.2.6 2013/07/24 03:30:42 riastradh Exp $   */
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -38,34 +38,52 @@
 
 #include <uvm/uvm_extern.h>    /* For PAGE_SIZE.  */
 
+#include <linux/gfp.h>
+
 /* XXX Should use kmem, but Linux kfree doesn't take the size.  */
 
-#define        GFP_KERNEL      M_WAITOK
-#define        GFP_ATOMIC      M_NOWAIT
+static inline int
+linux_gfp_to_malloc(gfp_t gfp)
+{
+       int flags = 0;
+
+       /* XXX Handle other cases as they arise.  */
+       KASSERT((gfp == GFP_ATOMIC) || (gfp == GFP_KERNEL));
 
-static inline void *
-kmalloc(size_t size, int flags)
-{
-       return malloc(size, M_TEMP, flags);
+       if (ISSET(gfp, __GFP_WAIT))
+               flags |= M_WAITOK;
+       else
+               flags |= M_NOWAIT;
+
+       if (ISSET(gfp, __GFP_ZERO))
+               flags |= M_ZERO;
+
+       return flags;
 }
 
 static inline void *
-kzalloc(size_t size, int flags)
+kmalloc(size_t size, gfp_t gfp)
 {
-       return malloc(size, M_TEMP, (flags | M_ZERO));
+       return malloc(size, M_TEMP, linux_gfp_to_malloc(gfp));
 }
 
 static inline void *
-kcalloc(size_t n, size_t size, int flags)
+kzalloc(size_t size, gfp_t gfp)
 {
-       KASSERT((SIZE_MAX / n) <= size);
-       return malloc((n * size), M_TEMP, (flags | M_ZERO));
+       return malloc(size, M_TEMP, (linux_gfp_to_malloc(gfp) | M_ZERO));
 }
 
 static inline void *
-krealloc(void *ptr, size_t size, int flags)
+kcalloc(size_t n, size_t size, gfp_t gfp)
 {
-       return realloc(ptr, size, M_TEMP, flags);
+       KASSERT((SIZE_MAX / n) <= size);
+       return malloc((n * size), M_TEMP, (linux_gfp_to_malloc(gfp) | M_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



Home | Main Index | Thread Index | Old Index