Thomas Gleixner | 50acfb2 | 2019-05-29 07:18:00 -0700 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Palmer Dabbelt | 07037db | 2017-07-10 18:06:09 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2009 Chen Liqin <liqin.chen@sunplusct.com> |
| 4 | * Copyright (C) 2012 Regents of the University of California |
| 5 | * Copyright (C) 2017 SiFive |
| 6 | * Copyright (C) 2017 XiaojingZhu <zhuxiaoj@ict.ac.cn> |
Palmer Dabbelt | 07037db | 2017-07-10 18:06:09 -0700 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #ifndef _ASM_RISCV_PAGE_H |
| 10 | #define _ASM_RISCV_PAGE_H |
| 11 | |
| 12 | #include <linux/pfn.h> |
| 13 | #include <linux/const.h> |
| 14 | |
| 15 | #define PAGE_SHIFT (12) |
| 16 | #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT) |
| 17 | #define PAGE_MASK (~(PAGE_SIZE - 1)) |
| 18 | |
| 19 | /* |
| 20 | * PAGE_OFFSET -- the first address of the first page of memory. |
| 21 | * When not using MMU this corresponds to the first free page in |
| 22 | * physical memory (aligned on a page boundary). |
| 23 | */ |
| 24 | #define PAGE_OFFSET _AC(CONFIG_PAGE_OFFSET, UL) |
| 25 | |
| 26 | #define KERN_VIRT_SIZE (-PAGE_OFFSET) |
| 27 | |
| 28 | #ifndef __ASSEMBLY__ |
| 29 | |
| 30 | #define PAGE_UP(addr) (((addr)+((PAGE_SIZE)-1))&(~((PAGE_SIZE)-1))) |
| 31 | #define PAGE_DOWN(addr) ((addr)&(~((PAGE_SIZE)-1))) |
| 32 | |
| 33 | /* align addr on a size boundary - adjust address up/down if needed */ |
| 34 | #define _ALIGN_UP(addr, size) (((addr)+((size)-1))&(~((size)-1))) |
| 35 | #define _ALIGN_DOWN(addr, size) ((addr)&(~((size)-1))) |
| 36 | |
| 37 | /* align addr on a size boundary - adjust address up if needed */ |
| 38 | #define _ALIGN(addr, size) _ALIGN_UP(addr, size) |
| 39 | |
| 40 | #define clear_page(pgaddr) memset((pgaddr), 0, PAGE_SIZE) |
| 41 | #define copy_page(to, from) memcpy((to), (from), PAGE_SIZE) |
| 42 | |
| 43 | #define clear_user_page(pgaddr, vaddr, page) memset((pgaddr), 0, PAGE_SIZE) |
| 44 | #define copy_user_page(vto, vfrom, vaddr, topg) \ |
| 45 | memcpy((vto), (vfrom), PAGE_SIZE) |
| 46 | |
| 47 | /* |
| 48 | * Use struct definitions to apply C type checking |
| 49 | */ |
| 50 | |
| 51 | /* Page Global Directory entry */ |
| 52 | typedef struct { |
| 53 | unsigned long pgd; |
| 54 | } pgd_t; |
| 55 | |
| 56 | /* Page Table entry */ |
| 57 | typedef struct { |
| 58 | unsigned long pte; |
| 59 | } pte_t; |
| 60 | |
| 61 | typedef struct { |
| 62 | unsigned long pgprot; |
| 63 | } pgprot_t; |
| 64 | |
| 65 | typedef struct page *pgtable_t; |
| 66 | |
| 67 | #define pte_val(x) ((x).pte) |
| 68 | #define pgd_val(x) ((x).pgd) |
| 69 | #define pgprot_val(x) ((x).pgprot) |
| 70 | |
| 71 | #define __pte(x) ((pte_t) { (x) }) |
| 72 | #define __pgd(x) ((pgd_t) { (x) }) |
| 73 | #define __pgprot(x) ((pgprot_t) { (x) }) |
| 74 | |
Antony Pavlov | 8581f38 | 2019-01-08 22:45:38 +0300 | [diff] [blame] | 75 | #ifdef CONFIG_64BIT |
Palmer Dabbelt | 07037db | 2017-07-10 18:06:09 -0700 | [diff] [blame] | 76 | #define PTE_FMT "%016lx" |
| 77 | #else |
| 78 | #define PTE_FMT "%08lx" |
| 79 | #endif |
| 80 | |
| 81 | extern unsigned long va_pa_offset; |
| 82 | extern unsigned long pfn_base; |
| 83 | |
| 84 | extern unsigned long max_low_pfn; |
| 85 | extern unsigned long min_low_pfn; |
| 86 | |
| 87 | #define __pa(x) ((unsigned long)(x) - va_pa_offset) |
| 88 | #define __va(x) ((void *)((unsigned long) (x) + va_pa_offset)) |
| 89 | |
| 90 | #define phys_to_pfn(phys) (PFN_DOWN(phys)) |
| 91 | #define pfn_to_phys(pfn) (PFN_PHYS(pfn)) |
| 92 | |
| 93 | #define virt_to_pfn(vaddr) (phys_to_pfn(__pa(vaddr))) |
| 94 | #define pfn_to_virt(pfn) (__va(pfn_to_phys(pfn))) |
| 95 | |
| 96 | #define virt_to_page(vaddr) (pfn_to_page(virt_to_pfn(vaddr))) |
| 97 | #define page_to_virt(page) (pfn_to_virt(page_to_pfn(page))) |
| 98 | |
| 99 | #define page_to_phys(page) (pfn_to_phys(page_to_pfn(page))) |
| 100 | #define page_to_bus(page) (page_to_phys(page)) |
| 101 | #define phys_to_page(paddr) (pfn_to_page(phys_to_pfn(paddr))) |
| 102 | |
| 103 | #define pfn_valid(pfn) \ |
| 104 | (((pfn) >= pfn_base) && (((pfn)-pfn_base) < max_mapnr)) |
| 105 | |
| 106 | #define ARCH_PFN_OFFSET (pfn_base) |
| 107 | |
| 108 | #endif /* __ASSEMBLY__ */ |
| 109 | |
| 110 | #define virt_addr_valid(vaddr) (pfn_valid(virt_to_pfn(vaddr))) |
| 111 | |
| 112 | #define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | \ |
| 113 | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC) |
| 114 | |
| 115 | #include <asm-generic/memory_model.h> |
| 116 | #include <asm-generic/getorder.h> |
| 117 | |
| 118 | /* vDSO support */ |
| 119 | /* We do define AT_SYSINFO_EHDR but don't use the gate mechanism */ |
| 120 | #define __HAVE_ARCH_GATE_AREA |
| 121 | |
| 122 | #endif /* _ASM_RISCV_PAGE_H */ |