Changeset View
Changeset View
Standalone View
Standalone View
sys/compat/linuxkpi/common/include/linux/page.h
Show All 35 Lines | |||||
#include <sys/param.h> | #include <sys/param.h> | ||||
#include <sys/vmmeter.h> | #include <sys/vmmeter.h> | ||||
#include <machine/atomic.h> | #include <machine/atomic.h> | ||||
#include <vm/vm.h> | #include <vm/vm.h> | ||||
#include <vm/vm_page.h> | #include <vm/vm_page.h> | ||||
#include <vm/pmap.h> | #include <vm/pmap.h> | ||||
#if defined(__i386__) || defined(__amd64__) | |||||
#include <machine/md_var.h> | |||||
#endif | |||||
typedef unsigned long linux_pte_t; | typedef unsigned long linux_pte_t; | ||||
typedef unsigned long linux_pmd_t; | typedef unsigned long linux_pmd_t; | ||||
typedef unsigned long linux_pgd_t; | typedef unsigned long linux_pgd_t; | ||||
typedef unsigned long pgprot_t; | typedef unsigned long pgprot_t; | ||||
#define page vm_page | #define page vm_page | ||||
#define LINUXKPI_PROT_VALID (1 << 3) | #define LINUXKPI_PROT_VALID (1 << 3) | ||||
#define LINUXKPI_CACHE_MODE_SHIFT 4 | #define LINUXKPI_CACHE_MODE_SHIFT 4 | ||||
CTASSERT((VM_PROT_ALL & -LINUXKPI_PROT_VALID) == 0); | CTASSERT((VM_PROT_ALL & -LINUXKPI_PROT_VALID) == 0); | ||||
#define PAGE_KERNEL_IO 0x0000 | |||||
static inline pgprot_t | static inline pgprot_t | ||||
cachemode2protval(vm_memattr_t attr) | cachemode2protval(vm_memattr_t attr) | ||||
{ | { | ||||
return ((attr << LINUXKPI_CACHE_MODE_SHIFT) | LINUXKPI_PROT_VALID); | return ((attr << LINUXKPI_CACHE_MODE_SHIFT) | LINUXKPI_PROT_VALID); | ||||
} | } | ||||
static inline vm_memattr_t | static inline vm_memattr_t | ||||
pgprot2cachemode(pgprot_t prot) | pgprot2cachemode(pgprot_t prot) | ||||
{ | { | ||||
if (prot & LINUXKPI_PROT_VALID) | if (prot & LINUXKPI_PROT_VALID) | ||||
return (prot >> LINUXKPI_CACHE_MODE_SHIFT); | return (prot >> LINUXKPI_CACHE_MODE_SHIFT); | ||||
else | else | ||||
return (VM_MEMATTR_DEFAULT); | return (VM_MEMATTR_DEFAULT); | ||||
} | } | ||||
#define virt_to_page(x) PHYS_TO_VM_PAGE(vtophys(x)) | #define virt_to_page(x) PHYS_TO_VM_PAGE(vtophys(x)) | ||||
#define page_to_pfn(pp) (VM_PAGE_TO_PHYS(pp) >> PAGE_SHIFT) | #define page_to_pfn(pp) (VM_PAGE_TO_PHYS(pp) >> PAGE_SHIFT) | ||||
#define pfn_to_page(pfn) (PHYS_TO_VM_PAGE((pfn) << PAGE_SHIFT)) | #define pfn_to_page(pfn) (PHYS_TO_VM_PAGE((pfn) << PAGE_SHIFT)) | ||||
#define nth_page(page,n) pfn_to_page(page_to_pfn(page) + (n)) | #define nth_page(page,n) pfn_to_page(page_to_pfn(page) + (n)) | ||||
#define page_to_phys(page) VM_PAGE_TO_PHYS(page) | |||||
#define clear_page(page) memset(page, 0, PAGE_SIZE) | #define clear_page(page) memset(page, 0, PAGE_SIZE) | ||||
#define pgprot_noncached(prot) \ | #define pgprot_noncached(prot) \ | ||||
(((prot) & VM_PROT_ALL) | cachemode2protval(VM_MEMATTR_UNCACHEABLE)) | (((prot) & VM_PROT_ALL) | cachemode2protval(VM_MEMATTR_UNCACHEABLE)) | ||||
#define pgprot_writecombine(prot) \ | #define pgprot_writecombine(prot) \ | ||||
(((prot) & VM_PROT_ALL) | cachemode2protval(VM_MEMATTR_WRITE_COMBINING)) | (((prot) & VM_PROT_ALL) | cachemode2protval(VM_MEMATTR_WRITE_COMBINING)) | ||||
#undef PAGE_MASK | #undef PAGE_MASK | ||||
#define PAGE_MASK (~(PAGE_SIZE-1)) | #define PAGE_MASK (~(PAGE_SIZE-1)) | ||||
/* | /* | ||||
* Modifying PAGE_MASK in the above way breaks trunc_page, round_page, | * Modifying PAGE_MASK in the above way breaks trunc_page, round_page, | ||||
* and btoc macros. Therefore, redefine them in a way that makes sense | * and btoc macros. Therefore, redefine them in a way that makes sense | ||||
* so the LinuxKPI consumers don't get totally broken behavior. | * so the LinuxKPI consumers don't get totally broken behavior. | ||||
*/ | */ | ||||
#undef btoc | #undef btoc | ||||
#define btoc(x) (((vm_offset_t)(x) + PAGE_SIZE - 1) >> PAGE_SHIFT) | #define btoc(x) (((vm_offset_t)(x) + PAGE_SIZE - 1) >> PAGE_SHIFT) | ||||
#undef round_page | #undef round_page | ||||
#define round_page(x) ((((uintptr_t)(x)) + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1)) | #define round_page(x) ((((uintptr_t)(x)) + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1)) | ||||
#undef trunc_page | #undef trunc_page | ||||
#define trunc_page(x) ((uintptr_t)(x) & ~(PAGE_SIZE - 1)) | #define trunc_page(x) ((uintptr_t)(x) & ~(PAGE_SIZE - 1)) | ||||
#if defined(__i386__) || defined(__amd64__) | |||||
#undef clflushopt | |||||
static inline void | |||||
lkpi_clflushopt(unsigned long addr) | |||||
{ | |||||
if (cpu_stdext_feature & CPUID_STDEXT_CLFLUSHOPT) | |||||
clflushopt(addr); | |||||
else if (cpu_feature & CPUID_CLFSH) | |||||
clflush(addr); | |||||
else | |||||
pmap_invalidate_cache(); | |||||
} | |||||
#define clflushopt(x) lkpi_clflushopt((unsigned long)(x)) | |||||
#endif | |||||
#endif /* _LINUX_PAGE_H_ */ | #endif /* _LINUX_PAGE_H_ */ |