pmap.h revision 1.1.22.2 1 /* $NetBSD: pmap.h,v 1.1.22.2 2020/04/08 14:07:50 martin Exp $ */
2
3 /*-
4 * Copyright (c) 2014 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Matt Thomas of 3am Software Foundry.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #ifndef _RISCV_PMAP_H_
33 #define _RISCV_PMAP_H_
34
35 #ifdef _KERNEL_OPT
36 #include "opt_modular.h"
37 #endif
38
39 #if !defined(_MODULE)
40
41 #include <sys/types.h>
42 #include <sys/pool.h>
43 #include <sys/evcnt.h>
44
45 #include <uvm/uvm_physseg.h>
46 #include <uvm/pmap/vmpagemd.h>
47
48 #include <riscv/pte.h>
49
50 #define PMAP_SEGTABSIZE NPTEPG
51
52 #define NBSEG (NBPG*NPTEPG)
53 #ifdef _LP64
54 #define NBXSEG (NBSEG*NSEGPG)
55 #define XSEGSHIFT (SEGSHIFT + PGSHIFT - 3)
56 #define XSEGOFSET (PTE_PPN1|SEGOFSET)
57 #define SEGSHIFT (PGSHIFT + PGSHIFT - 3)
58 #else
59 #define SEGSHIFT (PGSHIFT + PGSHIFT - 2)
60 #endif
61 #define SEGOFSET (PTE_PPN0|PAGE_MASK)
62
63 #define KERNEL_PID 0
64
65 #define PMAP_HWPAGEWALKER 1
66 #define PMAP_TLB_NUM_PIDS 256
67 #define PMAP_TLB_MAX 1
68 #ifdef _LP64
69 #define PMAP_INVALID_PDETAB_ADDRESS ((pmap_pdetab_t *)(VM_MIN_KERNEL_ADDRESS - PAGE_SIZE))
70 #define PMAP_INVALID_SEGTAB_ADDRESS ((pmap_segtab_t *)(VM_MIN_KERNEL_ADDRESS - PAGE_SIZE))
71 #else
72 #define PMAP_INVALID_PDETAB_ADDRESS ((pmap_pdetab_t *)0xdeadbeef)
73 #define PMAP_INVALID_SEGTAB_ADDRESS ((pmap_segtab_t *)0xdeadbeef)
74 #endif
75 #define PMAP_TLB_FLUSH_ASID_ON_RESET false
76
77 #define pmap_phys_address(x) (x)
78
79 #ifndef __BSD_PTENTRY_T__
80 #define __BSD_PTENTRY_T__
81 #ifdef _LP64
82 #define PRIxPTE PRIx64
83 #else
84 #define PRIxPTE PRIx32
85 #endif
86 #endif /* __BSD_PTENTRY_T__ */
87
88 #define PMAP_NEED_PROCWR
89 static inline void
90 pmap_procwr(struct proc *p, vaddr_t va, vsize_t len)
91 {
92 __asm __volatile("fence\trw,rw; fence.i");
93 }
94
95
96 #include <uvm/pmap/tlb.h>
97
98 #include <uvm/pmap/pmap_tlb.h>
99
100 #define PMAP_GROWKERNEL
101 #define PMAP_STEAL_MEMORY
102
103 #ifdef _KERNEL
104
105 #define __HAVE_PMAP_MD
106 struct pmap_md {
107 paddr_t md_ptbr;
108 pd_entry_t *md_pdetab;
109 };
110
111 void pmap_bootstrap(void);
112
113 struct vm_page *
114 pmap_md_alloc_poolpage(int flags);
115 vaddr_t pmap_md_map_poolpage(paddr_t, vsize_t);
116 void pmap_md_unmap_poolpage(vaddr_t, vsize_t);
117 bool pmap_md_direct_mapped_vaddr_p(vaddr_t);
118 bool pmap_md_io_vaddr_p(vaddr_t);
119 paddr_t pmap_md_direct_mapped_vaddr_to_paddr(vaddr_t);
120 vaddr_t pmap_md_direct_map_paddr(paddr_t);
121 void pmap_md_init(void);
122 bool pmap_md_tlb_check_entry(void *, vaddr_t, tlb_asid_t, pt_entry_t);
123 //void pmap_md_page_syncicache(struct vm_page *, const kcpuset_t *);
124
125 void pmap_md_pdetab_activate(struct pmap *);
126 void pmap_md_pdetab_init(struct pmap *);
127 bool pmap_md_ok_to_steal_p(const uvm_physseg_t, size_t);
128
129 #ifdef __PMAP_PRIVATE
130 static inline void
131 pmap_md_page_syncicache(struct vm_page *pg, const kcpuset_t *kc)
132 {
133 __asm __volatile("fence\trw,rw; fence.i");
134 }
135
136 /*
137 * Virtual Cache Alias helper routines. Not a problem for RISCV CPUs.
138 */
139 static inline bool
140 pmap_md_vca_add(struct vm_page *pg, vaddr_t va, pt_entry_t *nptep)
141 {
142 return false;
143 }
144
145 static inline void
146 pmap_md_vca_remove(struct vm_page *pg, vaddr_t va)
147 {
148
149 }
150
151 static inline void
152 pmap_md_vca_clean(struct vm_page *pg, vaddr_t va, int op)
153 {
154 }
155
156 static inline size_t
157 pmap_md_tlb_asid_max(void)
158 {
159 return PMAP_TLB_NUM_PIDS - 1;
160 }
161 #endif /* __PMAP_PRIVATE */
162 #endif /* _KERNEL */
163
164 #define POOL_VTOPHYS(va) ((paddr_t)((vaddr_t)(va)-VM_MAX_KERNEL_ADDRESS))
165 #define POOL_PHYSTOV(pa) ((vaddr_t)(paddr_t)(pa)+VM_MAX_KERNEL_ADDRESS)
166
167 #include <uvm/pmap/pmap.h>
168
169 #endif /* !_MODULE */
170
171 #if defined(MODULAR) || defined(_MODULE)
172 /*
173 * Define a compatible vm_page_md so that struct vm_page is the same size
174 * whether we are using modules or not.
175 */
176 #ifndef __HAVE_VM_PAGE_MD
177 #define __HAVE_VM_PAGE_MD
178
179 struct vm_page_md {
180 uintptr_t mdpg_dummy[3];
181 };
182 __CTASSERT(sizeof(struct vm_page_md) == sizeof(uintptr_t)*3);
183
184 #endif /* !__HAVE_VM_PAGE_MD */
185
186 #endif /* MODULAR || _MODULE */
187
188 #endif /* !_RISCV_PMAP_H_ */
189