mm.h revision 289624
1252661Snp/* $FreeBSD: head/sys/ofed/include/linux/mm.h 289624 2015-10-20 11:40:04Z hselasky $ */ 2252661Snp/*- 3252661Snp * Copyright (c) 2010 Isilon Systems, Inc. 4252661Snp * Copyright (c) 2010 iX Systems, Inc. 5269364Snp * Copyright (c) 2010 Panasas, Inc. 6252661Snp * Copyright (c) 2013-2015 Mellanox Technologies, Ltd. 7252661Snp * Copyright (c) 2015 Fran��ois Tigeot 8269364Snp * Copyright (c) 2015 Matthew Dillon <dillon@backplane.com> 9269364Snp * All rights reserved. 10252661Snp * 11252661Snp * Redistribution and use in source and binary forms, with or without 12252661Snp * modification, are permitted provided that the following conditions 13252661Snp * are met: 14252661Snp * 1. Redistributions of source code must retain the above copyright 15252661Snp * notice unmodified, this list of conditions, and the following 16269364Snp * disclaimer. 17252661Snp * 2. Redistributions in binary form must reproduce the above copyright 18252661Snp * notice, this list of conditions and the following disclaimer in the 19252661Snp * documentation and/or other materials provided with the distribution. 20299685Snp * 21269364Snp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22269364Snp * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23252661Snp * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24252661Snp * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 25252661Snp * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 26252661Snp * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27252661Snp * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32#ifndef _LINUX_MM_H_ 33#define _LINUX_MM_H_ 34 35#include <linux/spinlock.h> 36#include <linux/gfp.h> 37#include <linux/kernel.h> 38 39#define PAGE_ALIGN(x) ALIGN(x, PAGE_SIZE) 40 41struct vm_area_struct { 42 vm_offset_t vm_start; 43 vm_offset_t vm_end; 44 vm_offset_t vm_pgoff; 45 vm_paddr_t vm_pfn; /* PFN For mmap. */ 46 vm_size_t vm_len; /* length for mmap. */ 47 vm_memattr_t vm_page_prot; 48}; 49 50/* 51 * Compute log2 of the power of two rounded up count of pages 52 * needed for size bytes. 53 */ 54static inline int 55get_order(unsigned long size) 56{ 57 int order; 58 59 size = (size - 1) >> PAGE_SHIFT; 60 order = 0; 61 while (size) { 62 order++; 63 size >>= 1; 64 } 65 return (order); 66} 67 68static inline void * 69lowmem_page_address(struct page *page) 70{ 71 72 return page_address(page); 73} 74 75/* 76 * This only works via mmap ops. 77 */ 78static inline int 79io_remap_pfn_range(struct vm_area_struct *vma, 80 unsigned long addr, unsigned long pfn, unsigned long size, 81 vm_memattr_t prot) 82{ 83 vma->vm_page_prot = prot; 84 vma->vm_pfn = pfn; 85 vma->vm_len = size; 86 87 return (0); 88} 89 90static inline unsigned long 91vma_pages(struct vm_area_struct *vma) 92{ 93 return ((vma->vm_end - vma->vm_start) >> PAGE_SHIFT); 94} 95 96#define offset_in_page(off) ((off) & (PAGE_SIZE - 1)) 97 98static inline void 99set_page_dirty(struct vm_page *page) 100{ 101 vm_page_dirty(page); 102} 103 104static inline void 105get_page(struct vm_page *page) 106{ 107 vm_page_hold(page); 108} 109 110#endif /* _LINUX_MM_H_ */ 111