Module Name:    src
Committed By:   riastradh
Date:           Wed Jul 24 03:30:42 UTC 2013

Modified Files:
        src/sys/external/bsd/drm2/include/linux [riastradh-drm2]: slab.h
Added Files:
        src/sys/external/bsd/drm2/include/linux [riastradh-drm2]: gfp.h

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

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


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1.2.1 src/sys/external/bsd/drm2/include/linux/gfp.h
cvs rdiff -u -r1.1.2.5 -r1.1.2.6 \
    src/sys/external/bsd/drm2/include/linux/slab.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/slab.h
diff -u src/sys/external/bsd/drm2/include/linux/slab.h:1.1.2.5 src/sys/external/bsd/drm2/include/linux/slab.h:1.1.2.6
--- src/sys/external/bsd/drm2/include/linux/slab.h:1.1.2.5	Wed Jul 24 02:37:13 2013
+++ src/sys/external/bsd/drm2/include/linux/slab.h	Wed Jul 24 03:30:42 2013
@@ -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));
+
+	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 *
-kmalloc(size_t size, int flags)
+kmalloc(size_t size, gfp_t gfp)
 {
-	return malloc(size, M_TEMP, flags);
+	return malloc(size, M_TEMP, linux_gfp_to_malloc(gfp));
 }
 
 static inline void *
-kzalloc(size_t size, int flags)
+kzalloc(size_t size, gfp_t gfp)
 {
-	return malloc(size, M_TEMP, (flags | M_ZERO));
+	return malloc(size, M_TEMP, (linux_gfp_to_malloc(gfp) | M_ZERO));
 }
 
 static inline void *
-kcalloc(size_t n, size_t size, int flags)
+kcalloc(size_t n, size_t size, gfp_t gfp)
 {
 	KASSERT((SIZE_MAX / n) <= size);
-	return malloc((n * size), M_TEMP, (flags | M_ZERO));
+	return malloc((n * size), M_TEMP, (linux_gfp_to_malloc(gfp) | M_ZERO));
 }
 
 static inline void *
-krealloc(void *ptr, size_t size, int flags)
+krealloc(void *ptr, size_t size, gfp_t gfp)
 {
-	return realloc(ptr, size, M_TEMP, flags);
+	return realloc(ptr, size, M_TEMP, linux_gfp_to_malloc(gfp));
 }
 
 static inline void

Added files:

Index: src/sys/external/bsd/drm2/include/linux/gfp.h
diff -u /dev/null src/sys/external/bsd/drm2/include/linux/gfp.h:1.1.2.1
--- /dev/null	Wed Jul 24 03:30:42 2013
+++ src/sys/external/bsd/drm2/include/linux/gfp.h	Wed Jul 24 03:30:42 2013
@@ -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_ */

Reply via email to