xenpmap.h revision 1.23 1 1.23 cegger /* $NetBSD: xenpmap.h,v 1.23 2009/07/29 12:02:06 cegger 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.19 bouyer #include "opt_xen.h"
38 1.1 cl
39 1.4 bouyer #define INVALID_P2M_ENTRY (~0UL)
40 1.4 bouyer
41 1.8 bouyer void xpq_queue_machphys_update(paddr_t, paddr_t);
42 1.1 cl void xpq_queue_invlpg(vaddr_t);
43 1.19 bouyer void xpq_queue_pte_update(paddr_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.16 bouyer void xpq_queue_pin_table(paddr_t);
49 1.1 cl void xpq_queue_unpin_table(paddr_t);
50 1.19 bouyer int xpq_update_foreign(paddr_t, pt_entry_t, int);
51 1.1 cl
52 1.19 bouyer extern unsigned long *xpmap_phys_to_machine_mapping;
53 1.1 cl
54 1.12 bouyer /*
55 1.20 jym * On Xen-2, the start of the day virtual memory starts at KERNTEXTOFF
56 1.12 bouyer * (0xc0100000). On Xen-3 for domain0 it starts at KERNBASE (0xc0000000).
57 1.12 bouyer * So the offset between physical and virtual address is different on
58 1.12 bouyer * Xen-2 and Xen-3 for domain0.
59 1.20 jym * starting with xen-3.0.2, we can add notes so that virtual memory starts
60 1.15 bouyer * at KERNBASE for domU as well.
61 1.12 bouyer */
62 1.23 cegger #if defined(DOM0OPS) || !defined(XEN_COMPAT_030001)
63 1.12 bouyer #define XPMAP_OFFSET 0
64 1.12 bouyer #else
65 1.9 yamt #define XPMAP_OFFSET (KERNTEXTOFF - KERNBASE)
66 1.12 bouyer #endif
67 1.12 bouyer
68 1.21 jym #define mfn_to_pfn(mfn) (machine_to_phys_mapping[(mfn)])
69 1.21 jym #define pfn_to_mfn(pfn) (xpmap_phys_to_machine_mapping[(pfn)])
70 1.21 jym
71 1.13 perry static __inline paddr_t
72 1.1 cl xpmap_mtop(paddr_t mpa)
73 1.1 cl {
74 1.22 bouyer return (
75 1.22 bouyer ((paddr_t)machine_to_phys_mapping[mpa >> PAGE_SHIFT] << PAGE_SHIFT)
76 1.22 bouyer + XPMAP_OFFSET) | (mpa & ~PG_FRAME);
77 1.1 cl }
78 1.1 cl
79 1.13 perry static __inline paddr_t
80 1.16 bouyer xpmap_mtop_masked(paddr_t mpa)
81 1.16 bouyer {
82 1.22 bouyer return (
83 1.22 bouyer ((paddr_t)machine_to_phys_mapping[mpa >> PAGE_SHIFT] << PAGE_SHIFT)
84 1.22 bouyer + XPMAP_OFFSET);
85 1.16 bouyer }
86 1.16 bouyer
87 1.16 bouyer static __inline paddr_t
88 1.1 cl xpmap_ptom(paddr_t ppa)
89 1.1 cl {
90 1.19 bouyer return (((paddr_t)xpmap_phys_to_machine_mapping[(ppa -
91 1.19 bouyer XPMAP_OFFSET) >> PAGE_SHIFT]) << PAGE_SHIFT)
92 1.3 cl | (ppa & ~PG_FRAME);
93 1.3 cl }
94 1.3 cl
95 1.13 perry static __inline paddr_t
96 1.3 cl xpmap_ptom_masked(paddr_t ppa)
97 1.3 cl {
98 1.19 bouyer return (((paddr_t)xpmap_phys_to_machine_mapping[(ppa -
99 1.19 bouyer XPMAP_OFFSET) >> PAGE_SHIFT]) << PAGE_SHIFT);
100 1.1 cl }
101 1.1 cl
102 1.14 bouyer static inline void
103 1.14 bouyer MULTI_update_va_mapping(
104 1.14 bouyer multicall_entry_t *mcl, vaddr_t va,
105 1.19 bouyer pt_entry_t new_val, unsigned long flags)
106 1.14 bouyer {
107 1.14 bouyer mcl->op = __HYPERVISOR_update_va_mapping;
108 1.14 bouyer mcl->args[0] = va;
109 1.14 bouyer #if defined(__x86_64__)
110 1.14 bouyer mcl->args[1] = new_val;
111 1.14 bouyer mcl->args[2] = flags;
112 1.14 bouyer #else
113 1.19 bouyer mcl->args[1] = (new_val & 0xffffffff);
114 1.19 bouyer #ifdef PAE
115 1.19 bouyer mcl->args[2] = (new_val >> 32);
116 1.19 bouyer #else
117 1.14 bouyer mcl->args[2] = 0;
118 1.19 bouyer #endif
119 1.14 bouyer mcl->args[3] = flags;
120 1.14 bouyer #endif
121 1.14 bouyer }
122 1.14 bouyer
123 1.14 bouyer static inline void
124 1.14 bouyer MULTI_update_va_mapping_otherdomain(
125 1.14 bouyer multicall_entry_t *mcl, vaddr_t va,
126 1.19 bouyer pt_entry_t new_val, unsigned long flags, domid_t domid)
127 1.14 bouyer {
128 1.14 bouyer mcl->op = __HYPERVISOR_update_va_mapping_otherdomain;
129 1.14 bouyer mcl->args[0] = va;
130 1.14 bouyer #if defined(__x86_64__)
131 1.14 bouyer mcl->args[1] = new_val;
132 1.14 bouyer mcl->args[2] = flags;
133 1.14 bouyer mcl->args[3] = domid;
134 1.14 bouyer #else
135 1.19 bouyer mcl->args[1] = (new_val & 0xffffffff);
136 1.19 bouyer #ifdef PAE
137 1.19 bouyer mcl->args[2] = (new_val >> 32);
138 1.19 bouyer #else
139 1.14 bouyer mcl->args[2] = 0;
140 1.19 bouyer #endif
141 1.14 bouyer mcl->args[3] = flags;
142 1.14 bouyer mcl->args[4] = domid;
143 1.14 bouyer #endif
144 1.14 bouyer }
145 1.14 bouyer #if defined(__x86_64__)
146 1.14 bouyer #define MULTI_UVMFLAGS_INDEX 2
147 1.14 bouyer #define MULTI_UVMDOMID_INDEX 3
148 1.14 bouyer #else
149 1.14 bouyer #define MULTI_UVMFLAGS_INDEX 3
150 1.14 bouyer #define MULTI_UVMDOMID_INDEX 4
151 1.14 bouyer #endif
152 1.14 bouyer
153 1.16 bouyer #if defined(__x86_64__)
154 1.16 bouyer void xen_set_user_pgd(paddr_t);
155 1.16 bouyer #endif
156 1.16 bouyer
157 1.1 cl #endif /* _XEN_XENPMAP_H_ */
158