page.h (3014B)
1/* SPDX-License-Identifier: GPL-2.0 */ 2/* 3 * Copyright (C) 2020-2022 Loongson Technology Corporation Limited 4 */ 5#ifndef _ASM_PAGE_H 6#define _ASM_PAGE_H 7 8#include <linux/const.h> 9#include <asm/addrspace.h> 10 11/* 12 * PAGE_SHIFT determines the page size 13 */ 14#ifdef CONFIG_PAGE_SIZE_4KB 15#define PAGE_SHIFT 12 16#endif 17#ifdef CONFIG_PAGE_SIZE_16KB 18#define PAGE_SHIFT 14 19#endif 20#ifdef CONFIG_PAGE_SIZE_64KB 21#define PAGE_SHIFT 16 22#endif 23#define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT) 24#define PAGE_MASK (~(PAGE_SIZE - 1)) 25 26#define HPAGE_SHIFT (PAGE_SHIFT + PAGE_SHIFT - 3) 27#define HPAGE_SIZE (_AC(1, UL) << HPAGE_SHIFT) 28#define HPAGE_MASK (~(HPAGE_SIZE - 1)) 29#define HUGETLB_PAGE_ORDER (HPAGE_SHIFT - PAGE_SHIFT) 30 31#ifndef __ASSEMBLY__ 32 33#include <linux/kernel.h> 34#include <linux/pfn.h> 35 36#define MAX_DMA32_PFN (1UL << (32 - PAGE_SHIFT)) 37 38/* 39 * It's normally defined only for FLATMEM config but it's 40 * used in our early mem init code for all memory models. 41 * So always define it. 42 */ 43#define ARCH_PFN_OFFSET PFN_UP(PHYS_OFFSET) 44 45extern void clear_page(void *page); 46extern void copy_page(void *to, void *from); 47 48#define clear_user_page(page, vaddr, pg) clear_page(page) 49#define copy_user_page(to, from, vaddr, pg) copy_page(to, from) 50 51extern unsigned long shm_align_mask; 52 53struct page; 54struct vm_area_struct; 55void copy_user_highpage(struct page *to, struct page *from, 56 unsigned long vaddr, struct vm_area_struct *vma); 57 58#define __HAVE_ARCH_COPY_USER_HIGHPAGE 59 60typedef struct { unsigned long pte; } pte_t; 61#define pte_val(x) ((x).pte) 62#define __pte(x) ((pte_t) { (x) }) 63typedef struct page *pgtable_t; 64 65typedef struct { unsigned long pgd; } pgd_t; 66#define pgd_val(x) ((x).pgd) 67#define __pgd(x) ((pgd_t) { (x) }) 68 69/* 70 * Manipulate page protection bits 71 */ 72typedef struct { unsigned long pgprot; } pgprot_t; 73#define pgprot_val(x) ((x).pgprot) 74#define __pgprot(x) ((pgprot_t) { (x) }) 75#define pte_pgprot(x) __pgprot(pte_val(x) & ~_PFN_MASK) 76 77#define ptep_buddy(x) ((pte_t *)((unsigned long)(x) ^ sizeof(pte_t))) 78 79/* 80 * __pa()/__va() should be used only during mem init. 81 */ 82#define __pa(x) PHYSADDR(x) 83#define __va(x) ((void *)((unsigned long)(x) + PAGE_OFFSET - PHYS_OFFSET)) 84 85#define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT) 86 87#ifdef CONFIG_FLATMEM 88 89static inline int pfn_valid(unsigned long pfn) 90{ 91 /* avoid <linux/mm.h> include hell */ 92 extern unsigned long max_mapnr; 93 unsigned long pfn_offset = ARCH_PFN_OFFSET; 94 95 return pfn >= pfn_offset && pfn < max_mapnr; 96} 97 98#endif 99 100#define virt_to_pfn(kaddr) PFN_DOWN(virt_to_phys((void *)(kaddr))) 101#define virt_to_page(kaddr) pfn_to_page(virt_to_pfn(kaddr)) 102 103extern int __virt_addr_valid(volatile void *kaddr); 104#define virt_addr_valid(kaddr) __virt_addr_valid((volatile void *)(kaddr)) 105 106#define VM_DATA_DEFAULT_FLAGS \ 107 (VM_READ | VM_WRITE | \ 108 ((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \ 109 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC) 110 111#include <asm-generic/memory_model.h> 112#include <asm-generic/getorder.h> 113 114#endif /* !__ASSEMBLY__ */ 115 116#endif /* _ASM_PAGE_H */