page.h revision 302408
180708Sjake/*- 286228Stmm * Copyright (c) 2010 Isilon Systems, Inc. 380708Sjake * Copyright (c) 2010 iX Systems, Inc. 480708Sjake * Copyright (c) 2010 Panasas, Inc. 586228Stmm * Copyright (c) 2013-2016 Mellanox Technologies, Ltd. 686228Stmm * All rights reserved. 786228Stmm * 886228Stmm * Redistribution and use in source and binary forms, with or without 980708Sjake * modification, are permitted provided that the following conditions 1080708Sjake * are met: 1180708Sjake * 1. Redistributions of source code must retain the above copyright 1280708Sjake * notice unmodified, this list of conditions, and the following 1380708Sjake * disclaimer. 1480708Sjake * 2. Redistributions in binary form must reproduce the above copyright 1580708Sjake * notice, this list of conditions and the following disclaimer in the 1680708Sjake * documentation and/or other materials provided with the distribution. 1786228Stmm * 1886228Stmm * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 1986228Stmm * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 2086228Stmm * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 2186228Stmm * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 2286228Stmm * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2386228Stmm * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2480708Sjake * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2586228Stmm * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2686228Stmm * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2786228Stmm * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2886228Stmm * 2986228Stmm * $FreeBSD: stable/11/sys/compat/linuxkpi/common/include/linux/page.h 299673 2016-05-13 12:41:21Z hselasky $ 3086228Stmm */ 3186228Stmm#ifndef _LINUX_PAGE_H_ 3286228Stmm#define _LINUX_PAGE_H_ 3386228Stmm 3486228Stmm#include <linux/types.h> 3586228Stmm 3686228Stmm#include <sys/param.h> 3786228Stmm 3886228Stmm#include <machine/atomic.h> 3986228Stmm#include <vm/vm.h> 4086228Stmm#include <vm/vm_page.h> 4180708Sjake#include <vm/pmap.h> 4286228Stmm 4386228Stmmtypedef unsigned long pgprot_t; 4486228Stmm 4586228Stmm#define page vm_page 4686228Stmm 4786228Stmm#define virt_to_page(x) PHYS_TO_VM_PAGE(vtophys((x))) 4886228Stmm#define page_to_pfn(pp) (VM_PAGE_TO_PHYS((pp)) >> PAGE_SHIFT) 4986228Stmm#define pfn_to_page(pfn) (PHYS_TO_VM_PAGE((pfn) << PAGE_SHIFT)) 5086228Stmm#define nth_page(page,n) pfn_to_page(page_to_pfn((page)) + (n)) 5186228Stmm 5286228Stmm#define clear_page(page) memset((page), 0, PAGE_SIZE) 5386228Stmm#define pgprot_noncached(prot) ((pgprot_t)VM_MEMATTR_UNCACHEABLE) 5486228Stmm#define pgprot_writecombine(prot) ((pgprot_t)VM_MEMATTR_WRITE_COMBINING) 5586228Stmm 5686228Stmm#undef PAGE_MASK 5786228Stmm#define PAGE_MASK (~(PAGE_SIZE-1)) 5886228Stmm/* 5986228Stmm * Modifying PAGE_MASK in the above way breaks trunc_page, round_page, 6086228Stmm * and btoc macros. Therefore, redefine them in a way that makes sense 6186228Stmm * so the LinuxKPI consumers don't get totally broken behavior. 6286228Stmm */ 6386228Stmm#undef btoc 6486228Stmm#define btoc(x) (((vm_offset_t)(x) + PAGE_SIZE - 1) >> PAGE_SHIFT) 6586228Stmm#undef round_page 6686228Stmm#define round_page(x) ((((uintptr_t)(x)) + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1)) 6786228Stmm#undef trunc_page 6886228Stmm#define trunc_page(x) ((uintptr_t)(x) & ~(PAGE_SIZE - 1)) 6986228Stmm 7086228Stmm#endif /* _LINUX_PAGE_H_ */ 7186228Stmm