xref: /openbsd/sys/arch/arm64/include/pmap.h (revision 4cfece93)
1 /* $OpenBSD: pmap.h,v 1.13 2019/06/04 14:07:22 patrick Exp $ */
2 /*
3  * Copyright (c) 2008,2009,2014 Dale Rahn <drahn@dalerahn.com>
4  *
5  * Permission to use, copy, modify, and distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17 #ifndef	_ARM64_PMAP_H_
18 #define	_ARM64_PMAP_H_
19 
20 #ifndef _LOCORE
21 #include <sys/mutex.h>
22 #include <sys/queue.h>
23 #include <machine/pte.h>
24 #endif
25 
26 
27 /* V->P mapping data */
28 #define VP_IDX0_CNT	512
29 #define VP_IDX0_MASK	(VP_IDX0_CNT-1)
30 #define VP_IDX0_POS	39
31 #define VP_IDX1_CNT	512
32 #define VP_IDX1_MASK	(VP_IDX1_CNT-1)
33 #define VP_IDX1_POS	30
34 #define VP_IDX2_CNT	512
35 #define VP_IDX2_MASK	(VP_IDX2_CNT-1)
36 #define VP_IDX2_POS	21
37 #define VP_IDX3_CNT	512
38 #define VP_IDX3_MASK	(VP_IDX3_CNT-1)
39 #define VP_IDX3_POS	12
40 
41 /* cache flags */
42 #define PMAP_CACHE_CI		(PMAP_MD0)		/* cache inhibit */
43 #define PMAP_CACHE_WT		(PMAP_MD1)	 	/* writethru */
44 #define PMAP_CACHE_WB		(PMAP_MD1|PMAP_MD0)	/* writeback */
45 #define PMAP_CACHE_DEV		(PMAP_MD2)		/* device mapping */
46 #define PMAP_CACHE_BITS		(PMAP_MD0|PMAP_MD1|PMAP_MD2)
47 
48 #define PTED_VA_MANAGED_M	(PMAP_MD3)
49 #define PTED_VA_WIRED_M		(PMAP_MD3 << 1)
50 #define PTED_VA_EXEC_M		(PMAP_MD3 << 2)
51 
52 
53 #if defined(_KERNEL) && !defined(_LOCORE)
54 /*
55  * Pmap stuff
56  */
57 
58 typedef struct pmap *pmap_t;
59 
60 struct pmap {
61 	struct mutex pm_mtx;
62 	union {
63 		struct pmapvp0 *l0;	/* virtual to physical table 4 lvl */
64 		struct pmapvp1 *l1;	/* virtual to physical table 3 lvl */
65 	} pm_vp;
66 	uint64_t pm_pt0pa;
67 	int have_4_level_pt;
68 	int pm_privileged;
69 	int pm_asid;
70 	int pm_refs;				/* ref count */
71 	struct pmap_statistics  pm_stats;	/* pmap statistics */
72 };
73 
74 #define PMAP_PA_MASK	~((paddr_t)PAGE_MASK) /* to remove the flags */
75 #define PMAP_NOCACHE	0x1 /* non-cacheable memory */
76 #define PMAP_DEVICE	0x2 /* device memory */
77 
78 #define PG_PMAP_MOD		PG_PMAP0
79 #define PG_PMAP_REF		PG_PMAP1
80 #define PG_PMAP_EXE		PG_PMAP2
81 
82 // [NCPUS]
83 extern paddr_t zero_page;
84 extern paddr_t copy_src_page;
85 extern paddr_t copy_dst_page;
86 
87 void pagezero_cache(vaddr_t);
88 
89 extern struct pmap kernel_pmap_;
90 #define pmap_kernel()   		(&kernel_pmap_)
91 #define	pmap_resident_count(pmap)	((pmap)->pm_stats.resident_count)
92 #define	pmap_wired_count(pmap)		((pmap)->pm_stats.wired_count)
93 
94 vaddr_t pmap_bootstrap(long kvo, paddr_t lpt1,  long kernelstart,
95     long kernelend, long ram_start, long ram_end);
96 void pmap_kenter_cache(vaddr_t va, paddr_t pa, vm_prot_t prot, int cacheable);
97 void pmap_page_ro(pmap_t pm, vaddr_t va, vm_prot_t prot);
98 
99 paddr_t pmap_steal_avail(size_t size, int align, void **kva);
100 void pmap_avail_fixup();
101 void pmap_physload_avail();
102 
103 #define PMAP_GROWKERNEL
104 
105 struct pv_entry;
106 
107 /* investigate */
108 #define pmap_unuse_final(p)		do { /* nothing */ } while (0)
109 int	pmap_fault_fixup(pmap_t, vaddr_t, vm_prot_t, int);
110 void pmap_postinit(void);
111 void	pmap_map_early(paddr_t, psize_t);
112 
113 #endif /* _KERNEL && !_LOCORE */
114 
115 #ifndef _LOCORE
116 #define __HAVE_VM_PAGE_MD
117 struct vm_page_md {
118 	struct mutex pv_mtx;
119 	LIST_HEAD(,pte_desc) pv_list;
120 };
121 
122 #define VM_MDPAGE_INIT(pg) do {			\
123 	mtx_init(&(pg)->mdpage.pv_mtx, IPL_VM);	\
124 	LIST_INIT(&((pg)->mdpage.pv_list));	\
125 } while (0)
126 #endif	/* _LOCORE */
127 
128 #endif	/* _ARM64_PMAP_H_ */
129