xenpmap.h revision 1.44 1 1.44 bouyer /* $NetBSD: xenpmap.h,v 1.44 2020/05/26 10:10:32 bouyer Exp $ */
2 1.1 cl
3 1.1 cl /*
4 1.1 cl *
5 1.1 cl * Copyright (c) 2004 Christian Limpach.
6 1.1 cl * All rights reserved.
7 1.1 cl *
8 1.1 cl * Redistribution and use in source and binary forms, with or without
9 1.1 cl * modification, are permitted provided that the following conditions
10 1.1 cl * are met:
11 1.1 cl * 1. Redistributions of source code must retain the above copyright
12 1.1 cl * notice, this list of conditions and the following disclaimer.
13 1.1 cl * 2. Redistributions in binary form must reproduce the above copyright
14 1.1 cl * notice, this list of conditions and the following disclaimer in the
15 1.1 cl * documentation and/or other materials provided with the distribution.
16 1.1 cl *
17 1.1 cl * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 1.1 cl * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 1.1 cl * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 1.1 cl * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 1.1 cl * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 1.1 cl * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 1.1 cl * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 1.1 cl * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 1.1 cl * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 1.1 cl * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 1.1 cl */
28 1.1 cl
29 1.1 cl
30 1.1 cl #ifndef _XEN_XENPMAP_H_
31 1.1 cl #define _XEN_XENPMAP_H_
32 1.26 mrg
33 1.26 mrg #ifdef _KERNEL_OPT
34 1.19 bouyer #include "opt_xen.h"
35 1.26 mrg #endif
36 1.1 cl
37 1.34 rmind #include <sys/types.h>
38 1.34 rmind #include <sys/kcpuset.h>
39 1.34 rmind
40 1.4 bouyer #define INVALID_P2M_ENTRY (~0UL)
41 1.4 bouyer
42 1.8 bouyer void xpq_queue_machphys_update(paddr_t, paddr_t);
43 1.1 cl void xpq_queue_invlpg(vaddr_t);
44 1.19 bouyer void xpq_queue_pte_update(paddr_t, pt_entry_t);
45 1.1 cl void xpq_queue_pt_switch(paddr_t);
46 1.1 cl void xpq_flush_queue(void);
47 1.1 cl void xpq_queue_set_ldt(vaddr_t, uint32_t);
48 1.1 cl void xpq_queue_tlb_flush(void);
49 1.25 jym void xpq_queue_pin_table(paddr_t, int);
50 1.1 cl void xpq_queue_unpin_table(paddr_t);
51 1.44 bouyer int xpq_update_foreign(paddr_t, pt_entry_t, int, u_int);
52 1.34 rmind void xen_mcast_tlbflush(kcpuset_t *);
53 1.28 cherry void xen_bcast_tlbflush(void);
54 1.34 rmind void xen_mcast_invlpg(vaddr_t, kcpuset_t *);
55 1.28 cherry void xen_bcast_invlpg(vaddr_t);
56 1.38 cherry void xen_copy_page(paddr_t, paddr_t);
57 1.38 cherry void xen_pagezero(paddr_t);
58 1.28 cherry
59 1.32 jym void pmap_xen_resume(void);
60 1.32 jym void pmap_xen_suspend(void);
61 1.35 jym void pmap_map_recursive_entries(void);
62 1.35 jym void pmap_unmap_recursive_entries(void);
63 1.1 cl
64 1.33 cherry void xen_kpm_sync(struct pmap *, int);
65 1.33 cherry
66 1.25 jym #define xpq_queue_pin_l1_table(pa) \
67 1.25 jym xpq_queue_pin_table(pa, MMUEXT_PIN_L1_TABLE)
68 1.25 jym #define xpq_queue_pin_l2_table(pa) \
69 1.25 jym xpq_queue_pin_table(pa, MMUEXT_PIN_L2_TABLE)
70 1.25 jym #define xpq_queue_pin_l3_table(pa) \
71 1.25 jym xpq_queue_pin_table(pa, MMUEXT_PIN_L3_TABLE)
72 1.25 jym #define xpq_queue_pin_l4_table(pa) \
73 1.25 jym xpq_queue_pin_table(pa, MMUEXT_PIN_L4_TABLE)
74 1.25 jym
75 1.41 cherry #ifdef XENPV
76 1.19 bouyer extern unsigned long *xpmap_phys_to_machine_mapping;
77 1.1 cl
78 1.44 bouyer /* MD PMAP flags */
79 1.44 bouyer /* mmu_update with MMU_PT_UPDATE_NO_TRANSLATE */
80 1.44 bouyer #define PMAP_MD_XEN_NOTR 0x01000000
81 1.44 bouyer
82 1.13 perry static __inline paddr_t
83 1.27 jym xpmap_mtop_masked(paddr_t mpa)
84 1.1 cl {
85 1.22 bouyer return (
86 1.36 jym (paddr_t)machine_to_phys_mapping[mpa >> PAGE_SHIFT] << PAGE_SHIFT);
87 1.1 cl }
88 1.1 cl
89 1.13 perry static __inline paddr_t
90 1.27 jym xpmap_mtop(paddr_t mpa)
91 1.16 bouyer {
92 1.42 maxv return (xpmap_mtop_masked(mpa) | (mpa & ~PTE_4KFRAME));
93 1.16 bouyer }
94 1.16 bouyer
95 1.16 bouyer static __inline paddr_t
96 1.27 jym xpmap_ptom_masked(paddr_t ppa)
97 1.1 cl {
98 1.37 jym return (
99 1.37 jym (paddr_t)xpmap_phys_to_machine_mapping[ppa >> PAGE_SHIFT]
100 1.36 jym << PAGE_SHIFT);
101 1.3 cl }
102 1.3 cl
103 1.13 perry static __inline paddr_t
104 1.27 jym xpmap_ptom(paddr_t ppa)
105 1.3 cl {
106 1.42 maxv return (xpmap_ptom_masked(ppa) | (ppa & ~PTE_4KFRAME));
107 1.1 cl }
108 1.1 cl
109 1.37 jym static __inline void
110 1.37 jym xpmap_ptom_map(paddr_t ppa, paddr_t mpa)
111 1.37 jym {
112 1.37 jym xpmap_phys_to_machine_mapping[ppa >> PAGE_SHIFT] = mpa >> PAGE_SHIFT;
113 1.37 jym }
114 1.37 jym
115 1.37 jym static __inline void
116 1.37 jym xpmap_ptom_unmap(paddr_t ppa)
117 1.37 jym {
118 1.37 jym xpmap_phys_to_machine_mapping[ppa >> PAGE_SHIFT] = INVALID_P2M_ENTRY;
119 1.37 jym }
120 1.37 jym
121 1.37 jym static __inline bool
122 1.37 jym xpmap_ptom_isvalid(paddr_t ppa)
123 1.37 jym {
124 1.37 jym return (
125 1.37 jym xpmap_phys_to_machine_mapping[ppa >> PAGE_SHIFT]
126 1.37 jym != INVALID_P2M_ENTRY);
127 1.37 jym }
128 1.37 jym
129 1.41 cherry
130 1.14 bouyer static inline void
131 1.14 bouyer MULTI_update_va_mapping(
132 1.14 bouyer multicall_entry_t *mcl, vaddr_t va,
133 1.19 bouyer pt_entry_t new_val, unsigned long flags)
134 1.14 bouyer {
135 1.14 bouyer mcl->op = __HYPERVISOR_update_va_mapping;
136 1.14 bouyer mcl->args[0] = va;
137 1.14 bouyer #if defined(__x86_64__)
138 1.14 bouyer mcl->args[1] = new_val;
139 1.14 bouyer mcl->args[2] = flags;
140 1.14 bouyer #else
141 1.19 bouyer mcl->args[1] = (new_val & 0xffffffff);
142 1.19 bouyer mcl->args[2] = (new_val >> 32);
143 1.14 bouyer mcl->args[3] = flags;
144 1.14 bouyer #endif
145 1.14 bouyer }
146 1.14 bouyer
147 1.14 bouyer static inline void
148 1.14 bouyer MULTI_update_va_mapping_otherdomain(
149 1.14 bouyer multicall_entry_t *mcl, vaddr_t va,
150 1.19 bouyer pt_entry_t new_val, unsigned long flags, domid_t domid)
151 1.14 bouyer {
152 1.14 bouyer mcl->op = __HYPERVISOR_update_va_mapping_otherdomain;
153 1.14 bouyer mcl->args[0] = va;
154 1.14 bouyer #if defined(__x86_64__)
155 1.14 bouyer mcl->args[1] = new_val;
156 1.14 bouyer mcl->args[2] = flags;
157 1.14 bouyer mcl->args[3] = domid;
158 1.14 bouyer #else
159 1.19 bouyer mcl->args[1] = (new_val & 0xffffffff);
160 1.19 bouyer mcl->args[2] = (new_val >> 32);
161 1.14 bouyer mcl->args[3] = flags;
162 1.14 bouyer mcl->args[4] = domid;
163 1.14 bouyer #endif
164 1.14 bouyer }
165 1.14 bouyer #if defined(__x86_64__)
166 1.14 bouyer #define MULTI_UVMFLAGS_INDEX 2
167 1.14 bouyer #define MULTI_UVMDOMID_INDEX 3
168 1.14 bouyer #else
169 1.14 bouyer #define MULTI_UVMFLAGS_INDEX 3
170 1.14 bouyer #define MULTI_UVMDOMID_INDEX 4
171 1.14 bouyer #endif
172 1.14 bouyer
173 1.16 bouyer #if defined(__x86_64__)
174 1.16 bouyer void xen_set_user_pgd(paddr_t);
175 1.16 bouyer #endif
176 1.43 bouyer #endif /* XENPV */
177 1.16 bouyer
178 1.44 bouyer int pmap_enter_gnt(struct pmap *, vaddr_t, vaddr_t, int,
179 1.44 bouyer const struct gnttab_map_grant_ref *);
180 1.44 bouyer
181 1.1 cl #endif /* _XEN_XENPMAP_H_ */
182