Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Arnd Bergmann | 5c01b46 | 2009-05-13 22:56:36 +0000 | [diff] [blame] | 2 | #ifndef __ASM_GENERIC_PAGE_H |
| 3 | #define __ASM_GENERIC_PAGE_H |
| 4 | /* |
| 5 | * Generic page.h implementation, for NOMMU architectures. |
| 6 | * This provides the dummy definitions for the memory management. |
| 7 | */ |
| 8 | |
| 9 | #ifdef CONFIG_MMU |
Mike Rapoport | d724444 | 2019-02-21 13:36:31 +0200 | [diff] [blame] | 10 | #error need to provide a real asm/page.h |
Arnd Bergmann | 5c01b46 | 2009-05-13 22:56:36 +0000 | [diff] [blame] | 11 | #endif |
| 12 | |
| 13 | |
| 14 | /* PAGE_SHIFT determines the page size */ |
| 15 | |
| 16 | #define PAGE_SHIFT 12 |
| 17 | #ifdef __ASSEMBLY__ |
| 18 | #define PAGE_SIZE (1 << PAGE_SHIFT) |
| 19 | #else |
| 20 | #define PAGE_SIZE (1UL << PAGE_SHIFT) |
| 21 | #endif |
| 22 | #define PAGE_MASK (~(PAGE_SIZE-1)) |
| 23 | |
| 24 | #include <asm/setup.h> |
| 25 | |
| 26 | #ifndef __ASSEMBLY__ |
| 27 | |
Arnd Bergmann | 5c01b46 | 2009-05-13 22:56:36 +0000 | [diff] [blame] | 28 | #define clear_page(page) memset((page), 0, PAGE_SIZE) |
| 29 | #define copy_page(to,from) memcpy((to), (from), PAGE_SIZE) |
| 30 | |
| 31 | #define clear_user_page(page, vaddr, pg) clear_page(page) |
| 32 | #define copy_user_page(to, from, vaddr, pg) copy_page(to, from) |
| 33 | |
| 34 | /* |
| 35 | * These are used to make use of C type-checking.. |
| 36 | */ |
| 37 | typedef struct { |
| 38 | unsigned long pte; |
| 39 | } pte_t; |
| 40 | typedef struct { |
| 41 | unsigned long pmd[16]; |
| 42 | } pmd_t; |
| 43 | typedef struct { |
| 44 | unsigned long pgd; |
| 45 | } pgd_t; |
| 46 | typedef struct { |
| 47 | unsigned long pgprot; |
| 48 | } pgprot_t; |
| 49 | typedef struct page *pgtable_t; |
| 50 | |
| 51 | #define pte_val(x) ((x).pte) |
| 52 | #define pmd_val(x) ((&x)->pmd[0]) |
| 53 | #define pgd_val(x) ((x).pgd) |
| 54 | #define pgprot_val(x) ((x).pgprot) |
| 55 | |
| 56 | #define __pte(x) ((pte_t) { (x) } ) |
| 57 | #define __pmd(x) ((pmd_t) { (x) } ) |
| 58 | #define __pgd(x) ((pgd_t) { (x) } ) |
| 59 | #define __pgprot(x) ((pgprot_t) { (x) } ) |
| 60 | |
| 61 | extern unsigned long memory_start; |
| 62 | extern unsigned long memory_end; |
| 63 | |
| 64 | #endif /* !__ASSEMBLY__ */ |
| 65 | |
Arnd Bergmann | 5c01b46 | 2009-05-13 22:56:36 +0000 | [diff] [blame] | 66 | #define PAGE_OFFSET (0) |
Arnd Bergmann | 5c01b46 | 2009-05-13 22:56:36 +0000 | [diff] [blame] | 67 | |
Mark Salter | b7a0556 | 2011-10-04 09:24:15 -0400 | [diff] [blame] | 68 | #ifndef ARCH_PFN_OFFSET |
| 69 | #define ARCH_PFN_OFFSET (PAGE_OFFSET >> PAGE_SHIFT) |
| 70 | #endif |
| 71 | |
Arnd Bergmann | 5c01b46 | 2009-05-13 22:56:36 +0000 | [diff] [blame] | 72 | #ifndef __ASSEMBLY__ |
| 73 | |
Mark Salter | b7a0556 | 2011-10-04 09:24:15 -0400 | [diff] [blame] | 74 | #define __va(x) ((void *)((unsigned long) (x))) |
| 75 | #define __pa(x) ((unsigned long) (x)) |
Arnd Bergmann | 5c01b46 | 2009-05-13 22:56:36 +0000 | [diff] [blame] | 76 | |
| 77 | #define virt_to_pfn(kaddr) (__pa(kaddr) >> PAGE_SHIFT) |
| 78 | #define pfn_to_virt(pfn) __va((pfn) << PAGE_SHIFT) |
| 79 | |
Sonic Zhang | 06d5e03 | 2011-10-31 17:08:31 -0700 | [diff] [blame] | 80 | #define virt_to_page(addr) pfn_to_page(virt_to_pfn(addr)) |
| 81 | #define page_to_virt(page) pfn_to_virt(page_to_pfn(page)) |
Arnd Bergmann | 5c01b46 | 2009-05-13 22:56:36 +0000 | [diff] [blame] | 82 | |
| 83 | #ifndef page_to_phys |
| 84 | #define page_to_phys(page) ((dma_addr_t)page_to_pfn(page) << PAGE_SHIFT) |
| 85 | #endif |
| 86 | |
Mark Salter | b7a0556 | 2011-10-04 09:24:15 -0400 | [diff] [blame] | 87 | #define pfn_valid(pfn) ((pfn) >= ARCH_PFN_OFFSET && ((pfn) - ARCH_PFN_OFFSET) < max_mapnr) |
Arnd Bergmann | 5c01b46 | 2009-05-13 22:56:36 +0000 | [diff] [blame] | 88 | |
| 89 | #define virt_addr_valid(kaddr) (((void *)(kaddr) >= (void *)PAGE_OFFSET) && \ |
| 90 | ((void *)(kaddr) < (void *)memory_end)) |
| 91 | |
| 92 | #endif /* __ASSEMBLY__ */ |
| 93 | |
| 94 | #include <asm-generic/memory_model.h> |
| 95 | #include <asm-generic/getorder.h> |
| 96 | |
| 97 | #endif /* __ASM_GENERIC_PAGE_H */ |