xenpmap.h revision 1.5 1 1.5 yamt /* $NetBSD: xenpmap.h,v 1.5 2005/04/16 08:49:29 yamt 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 * 3. All advertising materials mentioning features or use of this software
17 1.1 cl * must display the following acknowledgement:
18 1.1 cl * This product includes software developed by Christian Limpach.
19 1.1 cl * 4. The name of the author may not be used to endorse or promote products
20 1.1 cl * derived from this software without specific prior written permission.
21 1.1 cl *
22 1.1 cl * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 1.1 cl * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 1.1 cl * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 1.1 cl * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 1.1 cl * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 1.1 cl * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 1.1 cl * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 1.1 cl * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 1.1 cl * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 1.1 cl * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 1.1 cl */
33 1.1 cl
34 1.1 cl
35 1.1 cl #ifndef _XEN_XENPMAP_H_
36 1.1 cl #define _XEN_XENPMAP_H_
37 1.1 cl
38 1.4 bouyer #define INVALID_P2M_ENTRY (~0UL)
39 1.4 bouyer
40 1.1 cl void xpq_queue_invlpg(vaddr_t);
41 1.1 cl void xpq_queue_pde_update(pd_entry_t *, pd_entry_t);
42 1.1 cl void xpq_queue_pte_update(pt_entry_t *, pt_entry_t);
43 1.3 cl void xpq_queue_unchecked_pte_update(pt_entry_t *, pt_entry_t);
44 1.1 cl void xpq_queue_pt_switch(paddr_t);
45 1.1 cl void xpq_flush_queue(void);
46 1.1 cl void xpq_queue_set_ldt(vaddr_t, uint32_t);
47 1.1 cl void xpq_queue_tlb_flush(void);
48 1.1 cl void xpq_queue_pin_table(paddr_t, int);
49 1.1 cl void xpq_queue_unpin_table(paddr_t);
50 1.5 yamt int xpq_update_foreign(pt_entry_t *, pt_entry_t, int);
51 1.1 cl
52 1.1 cl extern paddr_t *xpmap_phys_to_machine_mapping;
53 1.1 cl
54 1.1 cl #define XPQ_PIN_L1_TABLE 1
55 1.1 cl #define XPQ_PIN_L2_TABLE 2
56 1.1 cl
57 1.1 cl #ifndef XEN
58 1.1 cl #define PDE_GET(_pdp) \
59 1.1 cl *(_pdp)
60 1.4 bouyer #define PDE_SET(_pdp,_mapdp,_npde) \
61 1.4 bouyer *(_mapdp) = (_npde)
62 1.4 bouyer #define PDE_CLEAR(_pdp,_mapdp) \
63 1.4 bouyer *(_mapdp) = 0
64 1.4 bouyer #define PTE_SET(_ptp,_maptp,_npte) \
65 1.4 bouyer *(_maptp) = (_npte)
66 1.4 bouyer #define PTE_CLEAR(_ptp,_maptp) \
67 1.4 bouyer *(_maptp) = 0
68 1.4 bouyer #define PTE_ATOMIC_SET(_ptp,_maptp,_npte,_opte) \
69 1.4 bouyer (_opte) = x86_atomic_testset_ul((_maptp), (_npte))
70 1.4 bouyer #define PTE_ATOMIC_CLEAR(_ptp,_maptp,_opte) \
71 1.4 bouyer (_opte) = x86_atomic_testset_ul((_maptp), 0)
72 1.4 bouyer #define PDE_CLEARBITS(_pdp,_mapdp,_bits) \
73 1.4 bouyer *(_mapdp) &= ~(_bits)
74 1.4 bouyer #define PTE_ATOMIC_CLEARBITS(_ptp,_maptp,_bits) \
75 1.4 bouyer x86_atomic_clearbits_l((_maptp), (_bits))
76 1.4 bouyer #define PTE_SETBITS(_ptp,_maptp,_bits) \
77 1.4 bouyer *(_maptp) |= (_bits)
78 1.4 bouyer #define PTE_ATOMIC_SETBITS(_ptp,_maptp,_bits) \
79 1.4 bouyer x86_atomic_setbits_l((_maptp), (_bits))
80 1.1 cl #else
81 1.1 cl paddr_t *xpmap_phys_to_machine_mapping;
82 1.1 cl
83 1.1 cl #define PDE_GET(_pdp) \
84 1.1 cl (pmap_valid_entry(*(_pdp)) ? xpmap_mtop(*(_pdp)) : *(_pdp))
85 1.4 bouyer #define PDE_SET(_pdp,_mapdp,_npde) do { \
86 1.4 bouyer xpq_queue_pde_update((_mapdp), xpmap_ptom((_npde))); \
87 1.1 cl xpq_flush_queue(); \
88 1.1 cl } while (/*CONSTCOND*/0)
89 1.4 bouyer #define PDE_CLEAR(_pdp,_mapdp) do { \
90 1.4 bouyer xpq_queue_pde_update((_mapdp), 0); \
91 1.1 cl xpq_flush_queue(); \
92 1.1 cl } while (/*CONSTCOND*/0)
93 1.1 cl #define PTE_GET(_ptp) \
94 1.1 cl (pmap_valid_entry(*(_ptp)) ? xpmap_mtop(*(_ptp)) : *(_ptp))
95 1.3 cl #define PTE_GET_MA(_ptp) \
96 1.3 cl *(_ptp)
97 1.4 bouyer #define PTE_SET(_ptp,_maptp,_npte) do { \
98 1.4 bouyer xpq_queue_pte_update((_maptp), xpmap_ptom((_npte))); \
99 1.1 cl xpq_flush_queue(); \
100 1.1 cl } while (/*CONSTCOND*/0)
101 1.4 bouyer #define PTE_SET_MA(_ptp,_maptp,_npte) do { \
102 1.4 bouyer xpq_queue_pte_update((_maptp), (_npte)); \
103 1.1 cl xpq_flush_queue(); \
104 1.1 cl } while (/*CONSTCOND*/0)
105 1.4 bouyer #define PTE_SET_MA_UNCHECKED(_ptp,_maptp,_npte) do { \
106 1.4 bouyer xpq_queue_unchecked_pte_update((_maptp), (_npte)); \
107 1.3 cl xpq_flush_queue(); \
108 1.3 cl } while (/*CONSTCOND*/0)
109 1.4 bouyer #define PTE_CLEAR(_ptp,_maptp) do { \
110 1.4 bouyer xpq_queue_pte_update((_maptp), 0); \
111 1.1 cl xpq_flush_queue(); \
112 1.1 cl } while (/*CONSTCOND*/0)
113 1.4 bouyer #define PTE_ATOMIC_SET(_ptp,_maptp,_npte,_opte) do { \
114 1.1 cl (_opte) = PTE_GET(_ptp); \
115 1.4 bouyer xpq_queue_pte_update((_maptp), xpmap_ptom((_npte))); \
116 1.1 cl xpq_flush_queue(); \
117 1.1 cl } while (/*CONSTCOND*/0)
118 1.4 bouyer #define PTE_ATOMIC_SET_MA(_ptp,_maptp,_npte,_opte) do { \
119 1.3 cl (_opte) = *(_ptp); \
120 1.4 bouyer xpq_queue_pte_update((_maptp), (_npte)); \
121 1.1 cl xpq_flush_queue(); \
122 1.1 cl } while (/*CONSTCOND*/0)
123 1.4 bouyer #define PTE_ATOMIC_CLEAR(_ptp,_maptp,_opte) do { \
124 1.1 cl (_opte) = PTE_GET(_ptp); \
125 1.4 bouyer xpq_queue_pte_update((_maptp), 0); \
126 1.1 cl xpq_flush_queue(); \
127 1.1 cl } while (/*CONSTCOND*/0)
128 1.4 bouyer #define PTE_ATOMIC_CLEAR_MA(_ptp,_maptp,_opte) do { \
129 1.3 cl (_opte) = *(_ptp); \
130 1.4 bouyer xpq_queue_pte_update((_maptp), 0); \
131 1.3 cl xpq_flush_queue(); \
132 1.3 cl } while (/*CONSTCOND*/0)
133 1.4 bouyer #define PDE_CLEARBITS(_pdp,_mapdp,_bits) do { \
134 1.4 bouyer xpq_queue_pte_update((_mapdp), *(_pdp) & ~((_bits) & ~PG_FRAME)); \
135 1.1 cl xpq_flush_queue(); \
136 1.1 cl } while (/*CONSTCOND*/0)
137 1.4 bouyer #define PTE_CLEARBITS(_ptp,_maptp,_bits) do { \
138 1.4 bouyer xpq_queue_pte_update((_maptp), *(_ptp) & ~((_bits) & ~PG_FRAME)); \
139 1.1 cl xpq_flush_queue(); \
140 1.1 cl } while (/*CONSTCOND*/0)
141 1.4 bouyer #define PDE_ATOMIC_CLEARBITS(_pdp,_mapdp,_bits) do { \
142 1.4 bouyer xpq_queue_pde_update((_mapdp), *(_pdp) & ~((_bits) & ~PG_FRAME)); \
143 1.1 cl xpq_flush_queue(); \
144 1.1 cl } while (/*CONSTCOND*/0)
145 1.4 bouyer #define PTE_ATOMIC_CLEARBITS(_ptp,_maptp,_bits) do { \
146 1.4 bouyer xpq_queue_pte_update((_maptp), *(_ptp) & ~((_bits) & ~PG_FRAME)); \
147 1.1 cl xpq_flush_queue(); \
148 1.1 cl } while (/*CONSTCOND*/0)
149 1.4 bouyer #define PTE_SETBITS(_ptp,_maptp,_bits) do { \
150 1.4 bouyer xpq_queue_pte_update((_maptp), *(_ptp) | ((_bits) & ~PG_FRAME)); \
151 1.2 cl xpq_flush_queue(); \
152 1.1 cl } while (/*CONSTCOND*/0)
153 1.4 bouyer #define PDE_ATOMIC_SETBITS(_pdp,_mapdp,_bits) do { \
154 1.4 bouyer xpq_queue_pde_update((_mapdp), *(_pdp) | ((_bits) & ~PG_FRAME)); \
155 1.1 cl xpq_flush_queue(); \
156 1.1 cl } while (/*CONSTCOND*/0)
157 1.4 bouyer #define PTE_ATOMIC_SETBITS(_ptp,_maptp,_bits) do { \
158 1.4 bouyer xpq_queue_pte_update((_maptp), *(_ptp) | ((_bits) & ~PG_FRAME)); \
159 1.1 cl xpq_flush_queue(); \
160 1.1 cl } while (/*CONSTCOND*/0)
161 1.4 bouyer #define PDE_COPY(_dpdp,_madpdp,_spdp) do { \
162 1.4 bouyer xpq_queue_pde_update((_madpdp), *(_spdp)); \
163 1.1 cl xpq_flush_queue(); \
164 1.1 cl } while (/*CONSTCOND*/0)
165 1.1 cl #define PTE_UPDATES_FLUSH() do { \
166 1.1 cl xpq_flush_queue(); \
167 1.1 cl } while (/*CONSTCOND*/0)
168 1.1 cl
169 1.1 cl #endif
170 1.1 cl
171 1.4 bouyer #define XPMAP_OFFSET (KERNTEXTOFF - KERNBASE_LOCORE)
172 1.1 cl static __inline paddr_t
173 1.1 cl xpmap_mtop(paddr_t mpa)
174 1.1 cl {
175 1.3 cl return ((machine_to_phys_mapping[mpa >> PAGE_SHIFT] << PAGE_SHIFT) +
176 1.4 bouyer XPMAP_OFFSET) | (mpa & ~PG_FRAME);
177 1.1 cl }
178 1.1 cl
179 1.1 cl static __inline paddr_t
180 1.1 cl xpmap_ptom(paddr_t ppa)
181 1.1 cl {
182 1.3 cl return (xpmap_phys_to_machine_mapping[(ppa -
183 1.4 bouyer XPMAP_OFFSET) >> PAGE_SHIFT] << PAGE_SHIFT)
184 1.3 cl | (ppa & ~PG_FRAME);
185 1.3 cl }
186 1.3 cl
187 1.3 cl static __inline paddr_t
188 1.3 cl xpmap_ptom_masked(paddr_t ppa)
189 1.3 cl {
190 1.3 cl return (xpmap_phys_to_machine_mapping[(ppa -
191 1.4 bouyer XPMAP_OFFSET) >> PAGE_SHIFT] << PAGE_SHIFT);
192 1.1 cl }
193 1.1 cl
194 1.1 cl #endif /* _XEN_XENPMAP_H_ */
195