xref: /linux/arch/hexagon/include/asm/page.h (revision 7f71507851fc7764b36a3221839607d3a45c2025)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Page management definitions for the Hexagon architecture
4  *
5  * Copyright (c) 2010-2013, The Linux Foundation. All rights reserved.
6  */
7 
8 #ifndef _ASM_PAGE_H
9 #define _ASM_PAGE_H
10 
11 #include <linux/const.h>
12 
13 /*  This is probably not the most graceful way to handle this.  */
14 
15 #ifdef CONFIG_PAGE_SIZE_4KB
16 #define HEXAGON_L1_PTE_SIZE __HVM_PDE_S_4KB
17 #endif
18 
19 #ifdef CONFIG_PAGE_SIZE_16KB
20 #define HEXAGON_L1_PTE_SIZE __HVM_PDE_S_16KB
21 #endif
22 
23 #ifdef CONFIG_PAGE_SIZE_64KB
24 #define HEXAGON_L1_PTE_SIZE __HVM_PDE_S_64KB
25 #endif
26 
27 #ifdef CONFIG_PAGE_SIZE_256KB
28 #define HEXAGON_L1_PTE_SIZE __HVM_PDE_S_256KB
29 #endif
30 
31 #ifdef CONFIG_PAGE_SIZE_1MB
32 #define HEXAGON_L1_PTE_SIZE __HVM_PDE_S_1MB
33 #endif
34 
35 /*
36  *  These should be defined in hugetlb.h, but apparently not.
37  *  "Huge" for us should be 4MB or 16MB, which are both represented
38  *  in L1 PTE's.  Right now, it's set up for 4MB.
39  */
40 #ifdef CONFIG_HUGETLB_PAGE
41 #define HPAGE_SHIFT 22
42 #define HPAGE_SIZE (1UL << HPAGE_SHIFT)
43 #define HPAGE_MASK (~(HPAGE_SIZE-1))
44 #define HUGETLB_PAGE_ORDER (HPAGE_SHIFT-PAGE_SHIFT)
45 #define HVM_HUGEPAGE_SIZE 0x5
46 #endif
47 
48 #include <vdso/page.h>
49 
50 #ifdef __KERNEL__
51 #ifndef __ASSEMBLY__
52 
53 /*
54  * This is for PFN_DOWN, which mm.h needs.  Seems the right place to pull it in.
55  */
56 #include <linux/pfn.h>
57 
58 /*
59  * We implement a two-level architecture-specific page table structure.
60  * Null intermediate page table level (pmd, pud) definitions will come from
61  * asm-generic/pagetable-nopmd.h and asm-generic/pagetable-nopud.h
62  */
63 typedef struct { unsigned long pte; } pte_t;
64 typedef struct { unsigned long pgd; } pgd_t;
65 typedef struct { unsigned long pgprot; } pgprot_t;
66 typedef struct page *pgtable_t;
67 
68 #define pte_val(x)     ((x).pte)
69 #define pgd_val(x)     ((x).pgd)
70 #define pgprot_val(x)  ((x).pgprot)
71 #define __pte(x)       ((pte_t) { (x) })
72 #define __pgd(x)       ((pgd_t) { (x) })
73 #define __pgprot(x)    ((pgprot_t) { (x) })
74 
75 /* Needed for PAGE_OFFSET used in the macro right below */
76 #include <asm/mem-layout.h>
77 
78 /*
79  * We need a __pa and a __va routine for kernel space.
80  * MIPS says they're only used during mem_init.
81  * also, check if we need a PHYS_OFFSET.
82  */
83 #define __pa(x) ((unsigned long)(x) - PAGE_OFFSET + PHYS_OFFSET)
84 #define __va(x) ((void *)((unsigned long)(x) - PHYS_OFFSET + PAGE_OFFSET))
85 
86 /* The "page frame" descriptor is defined in linux/mm.h */
87 struct page;
88 
89 /* Returns page frame descriptor for virtual address. */
90 #define virt_to_page(kaddr) pfn_to_page(PFN_DOWN(__pa(kaddr)))
91 
92 /* Default vm area behavior is non-executable.  */
93 #define VM_DATA_DEFAULT_FLAGS	VM_DATA_FLAGS_NON_EXEC
94 
95 #define virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
96 
97 /*  Need to not use a define for linesize; may move this to another file.  */
98 static inline void clear_page(void *page)
99 {
100 	/*  This can only be done on pages with L1 WB cache */
101 	asm volatile(
102 		"	loop0(1f,%1);\n"
103 		"1:	{ dczeroa(%0);\n"
104 		"	  %0 = add(%0,#32); }:endloop0\n"
105 		: "+r" (page)
106 		: "r" (PAGE_SIZE/32)
107 		: "lc0", "sa0", "memory"
108 	);
109 }
110 
111 #define copy_page(to, from)	memcpy((to), (from), PAGE_SIZE)
112 
113 /*
114  * Under assumption that kernel always "sees" user map...
115  */
116 #define clear_user_page(page, vaddr, pg)	clear_page(page)
117 #define copy_user_page(to, from, vaddr, pg)	copy_page(to, from)
118 
119 static inline unsigned long virt_to_pfn(const void *kaddr)
120 {
121 	return __pa(kaddr) >> PAGE_SHIFT;
122 }
123 
124 #define page_to_virt(page)	__va(page_to_phys(page))
125 
126 #include <asm/mem-layout.h>
127 #include <asm-generic/memory_model.h>
128 /* XXX Todo: implement assembly-optimized version of getorder. */
129 #include <asm-generic/getorder.h>
130 
131 #endif /* ifdef __ASSEMBLY__ */
132 #endif /* ifdef __KERNEL__ */
133 
134 #endif
135