1f43360b9SFrançois Tigeot /* 2*cfe46a34SFrançois Tigeot * Copyright (c) 2015-2019 François Tigeot <ftigeot@wolfpond.org> 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 30f0bba3d1SFrançois Tigeot #include <linux/mmdebug.h> 31f0bba3d1SFrançois Tigeot #include <linux/mmzone.h> 32f0bba3d1SFrançois Tigeot #include <linux/stddef.h> 33f0bba3d1SFrançois Tigeot 349db5a7ceSFrançois Tigeot #include <vm/vm_page.h> 35a5da6ec1SFrançois Tigeot #include <machine/bus_dma.h> 369db5a7ceSFrançois Tigeot 37*cfe46a34SFrançois Tigeot #define GFP_NOWAIT M_NOWAIT | M_CACHEALIGN 38*cfe46a34SFrançois Tigeot #define GFP_ATOMIC M_NOWAIT | M_CACHEALIGN 39*cfe46a34SFrançois Tigeot #define GFP_KERNEL M_WAITOK | M_CACHEALIGN 40*cfe46a34SFrançois Tigeot #define GFP_TEMPORARY GFP_KERNEL 41*cfe46a34SFrançois Tigeot #define GFP_USER GFP_KERNEL 42*cfe46a34SFrançois Tigeot #define GFP_HIGHUSER GFP_KERNEL 439e08aba5SFrançois Tigeot 44a5da6ec1SFrançois Tigeot #define __GFP_ZERO M_ZERO 45a5da6ec1SFrançois Tigeot 46a5da6ec1SFrançois Tigeot #define GFP_DMA32 0x10000 /* XXX: MUST NOT collide with the M_XXX definitions */ 47f43360b9SFrançois Tigeot 48f0bba3d1SFrançois Tigeot static inline void __free_page(struct page *page) 499db5a7ceSFrançois Tigeot { 50f0bba3d1SFrançois Tigeot vm_page_free_contig((struct vm_page *)page, PAGE_SIZE); 519db5a7ceSFrançois Tigeot } 529db5a7ceSFrançois Tigeot 53f0bba3d1SFrançois Tigeot static inline struct page * alloc_page(int flags) 54a5da6ec1SFrançois Tigeot { 55a5da6ec1SFrançois Tigeot vm_paddr_t high = ~0LLU; 56a5da6ec1SFrançois Tigeot 57a5da6ec1SFrançois Tigeot if (flags & GFP_DMA32) 58a5da6ec1SFrançois Tigeot high = BUS_SPACE_MAXADDR_32BIT; 59a5da6ec1SFrançois Tigeot 60f0bba3d1SFrançois Tigeot return (struct page *)vm_page_alloc_contig(0LLU, ~0LLU, 61a5da6ec1SFrançois Tigeot PAGE_SIZE, PAGE_SIZE, PAGE_SIZE, 62a5da6ec1SFrançois Tigeot VM_MEMATTR_DEFAULT); 63a5da6ec1SFrançois Tigeot } 64a5da6ec1SFrançois Tigeot 65f43360b9SFrançois Tigeot #endif /* _LINUX_GFP_H_ */ 66