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> 31*a5da6ec1SFrançois Tigeot #include <machine/bus_dma.h> 329db5a7ceSFrançois Tigeot 3347ad44e8SFrançois Tigeot #define GFP_ATOMIC M_NOWAIT 34f43360b9SFrançois Tigeot #define GFP_KERNEL M_WAITOK 35f43360b9SFrançois Tigeot #define GFP_TEMPORARY M_WAITOK 36*a5da6ec1SFrançois Tigeot #define __GFP_ZERO M_ZERO 37*a5da6ec1SFrançois Tigeot 38*a5da6ec1SFrançois Tigeot #define GFP_DMA32 0x10000 /* XXX: MUST NOT collide with the M_XXX definitions */ 39f43360b9SFrançois Tigeot 409db5a7ceSFrançois Tigeot static inline void __free_page(struct vm_page *page) 419db5a7ceSFrançois Tigeot { 429db5a7ceSFrançois Tigeot vm_page_free_contig(page, PAGE_SIZE); 439db5a7ceSFrançois Tigeot } 449db5a7ceSFrançois Tigeot 45*a5da6ec1SFrançois Tigeot static inline struct vm_page * alloc_page(int flags) 46*a5da6ec1SFrançois Tigeot { 47*a5da6ec1SFrançois Tigeot vm_paddr_t high = ~0LLU; 48*a5da6ec1SFrançois Tigeot 49*a5da6ec1SFrançois Tigeot if (flags & GFP_DMA32) 50*a5da6ec1SFrançois Tigeot high = BUS_SPACE_MAXADDR_32BIT; 51*a5da6ec1SFrançois Tigeot 52*a5da6ec1SFrançois Tigeot return vm_page_alloc_contig(0LLU, ~0LLU, 53*a5da6ec1SFrançois Tigeot PAGE_SIZE, PAGE_SIZE, PAGE_SIZE, 54*a5da6ec1SFrançois Tigeot VM_MEMATTR_DEFAULT); 55*a5da6ec1SFrançois Tigeot } 56*a5da6ec1SFrançois Tigeot 57f43360b9SFrançois Tigeot #endif /* _LINUX_GFP_H_ */ 58