xref: /dflybsd-src/sys/dev/drm/include/linux/gfp.h (revision 1e707bbf0eb43c7533729f4e377560a49e9320bf)
1f43360b9SFrançois Tigeot /*
2f43360b9SFrançois Tigeot  * Copyright (c) 2015 François Tigeot
3f43360b9SFrançois Tigeot  * All rights reserved.
4f43360b9SFrançois Tigeot  *
5f43360b9SFrançois Tigeot  * Redistribution and use in source and binary forms, with or without
6f43360b9SFrançois Tigeot  * modification, are permitted provided that the following conditions
7f43360b9SFrançois Tigeot  * are met:
8f43360b9SFrançois Tigeot  * 1. Redistributions of source code must retain the above copyright
9f43360b9SFrançois Tigeot  *    notice unmodified, this list of conditions, and the following
10f43360b9SFrançois Tigeot  *    disclaimer.
11f43360b9SFrançois Tigeot  * 2. Redistributions in binary form must reproduce the above copyright
12f43360b9SFrançois Tigeot  *    notice, this list of conditions and the following disclaimer in the
13f43360b9SFrançois Tigeot  *    documentation and/or other materials provided with the distribution.
14f43360b9SFrançois Tigeot  *
15f43360b9SFrançois Tigeot  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16f43360b9SFrançois Tigeot  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17f43360b9SFrançois Tigeot  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18f43360b9SFrançois Tigeot  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19f43360b9SFrançois Tigeot  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20f43360b9SFrançois Tigeot  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21f43360b9SFrançois Tigeot  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22f43360b9SFrançois Tigeot  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23f43360b9SFrançois Tigeot  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24f43360b9SFrançois Tigeot  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25f43360b9SFrançois Tigeot  */
26f43360b9SFrançois Tigeot 
27f43360b9SFrançois Tigeot #ifndef _LINUX_GFP_H_
28f43360b9SFrançois Tigeot #define _LINUX_GFP_H_
29f43360b9SFrançois Tigeot 
309db5a7ceSFrançois Tigeot #include <vm/vm_page.h>
31a5da6ec1SFrançois Tigeot #include <machine/bus_dma.h>
329db5a7ceSFrançois Tigeot 
33*1e707bbfSFrançois Tigeot #define GFP_NOWAIT	M_NOWAIT
3447ad44e8SFrançois Tigeot #define GFP_ATOMIC	M_NOWAIT
35f43360b9SFrançois Tigeot #define GFP_KERNEL	M_WAITOK
36f43360b9SFrançois Tigeot #define GFP_TEMPORARY	M_WAITOK
37a5da6ec1SFrançois Tigeot #define __GFP_ZERO	M_ZERO
38a5da6ec1SFrançois Tigeot 
39a5da6ec1SFrançois Tigeot #define GFP_DMA32	0x10000	/* XXX: MUST NOT collide with the M_XXX definitions */
40f43360b9SFrançois Tigeot 
419db5a7ceSFrançois Tigeot static inline void __free_page(struct vm_page *page)
429db5a7ceSFrançois Tigeot {
439db5a7ceSFrançois Tigeot 	vm_page_free_contig(page, PAGE_SIZE);
449db5a7ceSFrançois Tigeot }
459db5a7ceSFrançois Tigeot 
46a5da6ec1SFrançois Tigeot static inline struct vm_page * alloc_page(int flags)
47a5da6ec1SFrançois Tigeot {
48a5da6ec1SFrançois Tigeot 	vm_paddr_t high = ~0LLU;
49a5da6ec1SFrançois Tigeot 
50a5da6ec1SFrançois Tigeot 	if (flags & GFP_DMA32)
51a5da6ec1SFrançois Tigeot 		high = BUS_SPACE_MAXADDR_32BIT;
52a5da6ec1SFrançois Tigeot 
53a5da6ec1SFrançois Tigeot 	return vm_page_alloc_contig(0LLU, ~0LLU,
54a5da6ec1SFrançois Tigeot 			PAGE_SIZE, PAGE_SIZE, PAGE_SIZE,
55a5da6ec1SFrançois Tigeot 			VM_MEMATTR_DEFAULT);
56a5da6ec1SFrançois Tigeot }
57a5da6ec1SFrançois Tigeot 
58f43360b9SFrançois Tigeot #endif	/* _LINUX_GFP_H_ */
59