Annotation of src/sys/arch/riscv/include/pmap.h, Revision 1.6
1.6 ! skrll 1: /* $NetBSD: pmap.h,v 1.5 2020/08/07 07:19:45 skrll Exp $ */
1.1 matt 2:
1.3 maxv 3: /*
4: * Copyright (c) 2014, 2019 The NetBSD Foundation, Inc.
1.1 matt 5: * All rights reserved.
6: *
7: * This code is derived from software contributed to The NetBSD Foundation
1.3 maxv 8: * by Matt Thomas (of 3am Software Foundry) and Maxime Villard.
1.1 matt 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:
1.2 maxv 45: #include <uvm/uvm_physseg.h>
1.1 matt 46: #include <uvm/pmap/vmpagemd.h>
47:
48: #include <riscv/pte.h>
49:
1.3 maxv 50: #define PMAP_SEGTABSIZE NPTEPG
51:
52: #define NBSEG (PAGE_SIZE * NPTEPG)
1.1 matt 53:
54: #ifdef _LP64
1.3 maxv 55: #define NBXSEG (NBSEG * NSEGPG)
1.1 matt 56: #define XSEGSHIFT (SEGSHIFT + PGSHIFT - 3)
1.3 maxv 57: #define XSEGOFSET (PTE_PPN1 | SEGOFSET)
1.1 matt 58: #define SEGSHIFT (PGSHIFT + PGSHIFT - 3)
59: #else
60: #define SEGSHIFT (PGSHIFT + PGSHIFT - 2)
61: #endif
1.3 maxv 62:
1.1 matt 63: #define SEGOFSET (PTE_PPN0|PAGE_MASK)
64:
65: #define KERNEL_PID 0
66:
67: #define PMAP_HWPAGEWALKER 1
68: #define PMAP_TLB_NUM_PIDS 256
69: #define PMAP_TLB_MAX 1
70: #ifdef _LP64
71: #define PMAP_INVALID_PDETAB_ADDRESS ((pmap_pdetab_t *)(VM_MIN_KERNEL_ADDRESS - PAGE_SIZE))
72: #define PMAP_INVALID_SEGTAB_ADDRESS ((pmap_segtab_t *)(VM_MIN_KERNEL_ADDRESS - PAGE_SIZE))
73: #else
74: #define PMAP_INVALID_PDETAB_ADDRESS ((pmap_pdetab_t *)0xdeadbeef)
75: #define PMAP_INVALID_SEGTAB_ADDRESS ((pmap_segtab_t *)0xdeadbeef)
76: #endif
77: #define PMAP_TLB_FLUSH_ASID_ON_RESET false
78:
79: #define pmap_phys_address(x) (x)
80:
1.2 maxv 81: #ifndef __BSD_PTENTRY_T__
82: #define __BSD_PTENTRY_T__
83: #ifdef _LP64
84: #define PRIxPTE PRIx64
85: #else
86: #define PRIxPTE PRIx32
87: #endif
88: #endif /* __BSD_PTENTRY_T__ */
89:
1.1 matt 90: #define PMAP_NEED_PROCWR
91: static inline void
92: pmap_procwr(struct proc *p, vaddr_t va, vsize_t len)
93: {
94: __asm __volatile("fence\trw,rw; fence.i");
95: }
96:
97: #include <uvm/pmap/tlb.h>
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;
1.2 maxv 108: pd_entry_t *md_pdetab;
1.1 matt 109: };
110:
1.4 thorpej 111: void pmap_bootstrap(void);
112:
1.1 matt 113: struct vm_page *
1.6 ! skrll 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);
1.1 matt 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 *);
1.2 maxv 127: bool pmap_md_ok_to_steal_p(const uvm_physseg_t, size_t);
1.1 matt 128:
1.3 maxv 129: extern vaddr_t pmap_direct_base;
130: extern vaddr_t pmap_direct_end;
131: #define PMAP_DIRECT_MAP(pa) (pmap_direct_base + (pa))
132: #define PMAP_DIRECT_UNMAP(va) ((paddr_t)(va) - pmap_direct_base)
133:
1.1 matt 134: #ifdef __PMAP_PRIVATE
135: static inline void
136: pmap_md_page_syncicache(struct vm_page *pg, const kcpuset_t *kc)
137: {
138: __asm __volatile("fence\trw,rw; fence.i");
139: }
140:
141: /*
142: * Virtual Cache Alias helper routines. Not a problem for RISCV CPUs.
143: */
144: static inline bool
145: pmap_md_vca_add(struct vm_page *pg, vaddr_t va, pt_entry_t *nptep)
146: {
147: return false;
148: }
149:
150: static inline void
151: pmap_md_vca_remove(struct vm_page *pg, vaddr_t va)
152: {
153:
154: }
155:
156: static inline void
157: pmap_md_vca_clean(struct vm_page *pg, vaddr_t va, int op)
158: {
159: }
160:
161: static inline size_t
162: pmap_md_tlb_asid_max(void)
163: {
164: return PMAP_TLB_NUM_PIDS - 1;
165: }
1.5 skrll 166:
167: static inline void
168: pmap_md_xtab_activate(struct pmap *pm, struct lwp *l)
169: {
170:
171: /* nothing */
172: }
173:
174: static inline void
175: pmap_md_xtab_deactivate(struct pmap *pm)
176: {
177:
178: /* nothing */
179: }
180:
1.1 matt 181: #endif /* __PMAP_PRIVATE */
182: #endif /* _KERNEL */
183:
184: #include <uvm/pmap/pmap.h>
185:
186: #endif /* !_MODULE */
187:
188: #if defined(MODULAR) || defined(_MODULE)
189: /*
190: * Define a compatible vm_page_md so that struct vm_page is the same size
191: * whether we are using modules or not.
192: */
193: #ifndef __HAVE_VM_PAGE_MD
194: #define __HAVE_VM_PAGE_MD
195:
196: struct vm_page_md {
197: uintptr_t mdpg_dummy[3];
198: };
1.2 maxv 199: __CTASSERT(sizeof(struct vm_page_md) == sizeof(uintptr_t)*3);
1.1 matt 200:
1.2 maxv 201: #endif /* !__HAVE_VM_PAGE_MD */
1.1 matt 202:
203: #endif /* MODULAR || _MODULE */
204:
205: #endif /* !_RISCV_PMAP_H_ */
CVSweb <webmaster@jp.NetBSD.org>