Rev 1830 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1830 | Rev 1831 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (C) 2006 Martin Decky |
2 | * Copyright (C) 2006 Martin Decky |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
13 | * documentation and/or other materials provided with the distribution. |
14 | * - The name of the author may not be used to endorse or promote products |
14 | * - The name of the author may not be used to endorse or promote products |
15 | * derived from this software without specific prior written permission. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | #ifndef __xen32_HYPERCALL_H__ |
29 | #ifndef __xen32_HYPERCALL_H__ |
30 | #define __xen32_HYPERCALL_H__ |
30 | #define __xen32_HYPERCALL_H__ |
31 | 31 | ||
32 | #include <arch/types.h> |
32 | #include <arch/types.h> |
33 | #include <macros.h> |
33 | #include <macros.h> |
34 | 34 | ||
35 | 35 | ||
36 | typedef uint16_t domid_t; |
36 | typedef uint16_t domid_t; |
37 | 37 | ||
38 | 38 | ||
39 | typedef struct { |
39 | typedef struct { |
40 | uint8_t vector; /**< Exception vector */ |
40 | uint8_t vector; /**< Exception vector */ |
41 | uint8_t flags; /**< 0-3: privilege level; 4: clear event enable */ |
41 | uint8_t flags; /**< 0-3: privilege level; 4: clear event enable */ |
42 | uint16_t cs; /**< Code selector */ |
42 | uint16_t cs; /**< Code selector */ |
43 | uintptr_t address; /**< Code offset */ |
43 | void *address; /**< Code offset */ |
44 | } trap_info_t; |
44 | } trap_info_t; |
45 | 45 | ||
46 | 46 | ||
- | 47 | typedef struct { |
|
- | 48 | evtchn_t port; |
|
- | 49 | } evtchn_send_t; |
|
- | 50 | ||
- | 51 | typedef struct { |
|
- | 52 | uint32_t cmd; |
|
- | 53 | union { |
|
- | 54 | evtchn_send_t send; |
|
- | 55 | }; |
|
- | 56 | } evtchn_op_t; |
|
- | 57 | ||
- | 58 | ||
47 | #define XEN_SET_TRAP_TABLE 0 |
59 | #define XEN_SET_TRAP_TABLE 0 |
48 | #define XEN_MMU_UPDATE 1 |
60 | #define XEN_MMU_UPDATE 1 |
49 | #define XEN_SET_CALLBACKS 4 |
61 | #define XEN_SET_CALLBACKS 4 |
50 | #define XEN_UPDATE_VA_MAPPING 14 |
62 | #define XEN_UPDATE_VA_MAPPING 14 |
- | 63 | #define XEN_EVENT_CHANNEL_OP 16 |
|
51 | #define XEN_VERSION 17 |
64 | #define XEN_VERSION 17 |
52 | #define XEN_CONSOLE_IO 18 |
65 | #define XEN_CONSOLE_IO 18 |
53 | #define XEN_VM_ASSIST 21 |
66 | #define XEN_VM_ASSIST 21 |
54 | #define XEN_MMUEXT_OP 26 |
67 | #define XEN_MMUEXT_OP 26 |
55 | 68 | ||
56 | 69 | ||
57 | /* |
70 | /* |
58 | * Commands for XEN_CONSOLE_IO |
71 | * Commands for XEN_CONSOLE_IO |
59 | */ |
72 | */ |
60 | #define CONSOLE_IO_WRITE 0 |
73 | #define CONSOLE_IO_WRITE 0 |
61 | #define CONSOLE_IO_READ 1 |
74 | #define CONSOLE_IO_READ 1 |
62 | 75 | ||
63 | 76 | ||
64 | #define MMUEXT_PIN_L1_TABLE 0 |
77 | #define MMUEXT_PIN_L1_TABLE 0 |
65 | #define MMUEXT_PIN_L2_TABLE 1 |
78 | #define MMUEXT_PIN_L2_TABLE 1 |
66 | #define MMUEXT_PIN_L3_TABLE 2 |
79 | #define MMUEXT_PIN_L3_TABLE 2 |
67 | #define MMUEXT_PIN_L4_TABLE 3 |
80 | #define MMUEXT_PIN_L4_TABLE 3 |
68 | #define MMUEXT_UNPIN_TABLE 4 |
81 | #define MMUEXT_UNPIN_TABLE 4 |
69 | #define MMUEXT_NEW_BASEPTR 5 |
82 | #define MMUEXT_NEW_BASEPTR 5 |
70 | #define MMUEXT_TLB_FLUSH_LOCAL 6 |
83 | #define MMUEXT_TLB_FLUSH_LOCAL 6 |
71 | #define MMUEXT_INVLPG_LOCAL 7 |
84 | #define MMUEXT_INVLPG_LOCAL 7 |
72 | #define MMUEXT_TLB_FLUSH_MULTI 8 |
85 | #define MMUEXT_TLB_FLUSH_MULTI 8 |
73 | #define MMUEXT_INVLPG_MULTI 9 |
86 | #define MMUEXT_INVLPG_MULTI 9 |
74 | #define MMUEXT_TLB_FLUSH_ALL 10 |
87 | #define MMUEXT_TLB_FLUSH_ALL 10 |
75 | #define MMUEXT_INVLPG_ALL 11 |
88 | #define MMUEXT_INVLPG_ALL 11 |
76 | #define MMUEXT_FLUSH_CACHE 12 |
89 | #define MMUEXT_FLUSH_CACHE 12 |
77 | #define MMUEXT_SET_LDT 13 |
90 | #define MMUEXT_SET_LDT 13 |
78 | #define MMUEXT_NEW_USER_BASEPTR 15 |
91 | #define MMUEXT_NEW_USER_BASEPTR 15 |
79 | 92 | ||
80 | 93 | ||
- | 94 | #define EVTCHNOP_SEND 4 |
|
- | 95 | ||
- | 96 | ||
81 | #define UVMF_NONE 0 /**< No flushing at all */ |
97 | #define UVMF_NONE 0 /**< No flushing at all */ |
82 | #define UVMF_TLB_FLUSH 1 /**< Flush entire TLB(s) */ |
98 | #define UVMF_TLB_FLUSH 1 /**< Flush entire TLB(s) */ |
83 | #define UVMF_INVLPG 2 /**< Flush only one entry */ |
99 | #define UVMF_INVLPG 2 /**< Flush only one entry */ |
84 | #define UVMF_FLUSHTYPE_MASK 3 |
100 | #define UVMF_FLUSHTYPE_MASK 3 |
85 | #define UVMF_MULTI 0 /**< Flush subset of TLBs */ |
101 | #define UVMF_MULTI 0 /**< Flush subset of TLBs */ |
86 | #define UVMF_LOCAL 0 /**< Flush local TLB */ |
102 | #define UVMF_LOCAL 0 /**< Flush local TLB */ |
87 | #define UVMF_ALL (1 << 2) /**< Flush all TLBs */ |
103 | #define UVMF_ALL (1 << 2) /**< Flush all TLBs */ |
88 | 104 | ||
89 | 105 | ||
90 | /* |
106 | /* |
91 | * Commands to XEN_VM_ASSIST |
107 | * Commands to XEN_VM_ASSIST |
92 | */ |
108 | */ |
93 | #define VMASST_CMD_ENABLE 0 |
109 | #define VMASST_CMD_ENABLE 0 |
94 | #define VMASST_CMD_DISABLE 1 |
110 | #define VMASST_CMD_DISABLE 1 |
95 | #define VMASST_TYPE_4GB_SEGMENTS 0 |
111 | #define VMASST_TYPE_4GB_SEGMENTS 0 |
96 | #define VMASST_TYPE_4GB_SEGMENTS_NOTIFY 1 |
112 | #define VMASST_TYPE_4GB_SEGMENTS_NOTIFY 1 |
97 | #define VMASST_TYPE_WRITABLE_PAGETABLES 2 |
113 | #define VMASST_TYPE_WRITABLE_PAGETABLES 2 |
98 | 114 | ||
99 | 115 | ||
100 | #define DOMID_SELF (0x7FF0U) |
116 | #define DOMID_SELF (0x7FF0U) |
101 | #define DOMID_IO (0x7FF1U) |
117 | #define DOMID_IO (0x7FF1U) |
102 | 118 | ||
103 | 119 | ||
104 | #define force_evtchn_callback() ((void) xen_version(0, 0)) |
120 | #define force_evtchn_callback() ((void) xen_version(0, 0)) |
105 | 121 | ||
106 | #define hypercall0(id) \ |
122 | #define hypercall0(id) \ |
107 | ({ \ |
123 | ({ \ |
108 | unative_t ret; \ |
124 | unative_t ret; \ |
109 | asm volatile ( \ |
125 | asm volatile ( \ |
110 | "call hypercall_page + (" STRING(id) " * 32)\n" \ |
126 | "call hypercall_page + (" STRING(id) " * 32)\n" \ |
111 | : "=a" (ret) \ |
127 | : "=a" (ret) \ |
112 | : \ |
128 | : \ |
113 | : "memory" \ |
129 | : "memory" \ |
114 | ); \ |
130 | ); \ |
115 | ret; \ |
131 | ret; \ |
116 | }) |
132 | }) |
117 | 133 | ||
118 | #define hypercall1(id, p1) \ |
134 | #define hypercall1(id, p1) \ |
119 | ({ \ |
135 | ({ \ |
120 | unative_t ret, __ign1; \ |
136 | unative_t ret, __ign1; \ |
121 | asm volatile ( \ |
137 | asm volatile ( \ |
122 | "call hypercall_page + (" STRING(id) " * 32)\n" \ |
138 | "call hypercall_page + (" STRING(id) " * 32)\n" \ |
123 | : "=a" (ret), \ |
139 | : "=a" (ret), \ |
124 | "=b" (__ign1) \ |
140 | "=b" (__ign1) \ |
125 | : "1" (p1) \ |
141 | : "1" (p1) \ |
126 | : "memory" \ |
142 | : "memory" \ |
127 | ); \ |
143 | ); \ |
128 | ret; \ |
144 | ret; \ |
129 | }) |
145 | }) |
130 | 146 | ||
131 | #define hypercall2(id, p1, p2) \ |
147 | #define hypercall2(id, p1, p2) \ |
132 | ({ \ |
148 | ({ \ |
133 | unative_t ret, __ign1, __ign2; \ |
149 | unative_t ret, __ign1, __ign2; \ |
134 | asm volatile ( \ |
150 | asm volatile ( \ |
135 | "call hypercall_page + (" STRING(id) " * 32)\n" \ |
151 | "call hypercall_page + (" STRING(id) " * 32)\n" \ |
136 | : "=a" (ret), \ |
152 | : "=a" (ret), \ |
137 | "=b" (__ign1), \ |
153 | "=b" (__ign1), \ |
138 | "=c" (__ign2) \ |
154 | "=c" (__ign2) \ |
139 | : "1" (p1), \ |
155 | : "1" (p1), \ |
140 | "2" (p2) \ |
156 | "2" (p2) \ |
141 | : "memory" \ |
157 | : "memory" \ |
142 | ); \ |
158 | ); \ |
143 | ret; \ |
159 | ret; \ |
144 | }) |
160 | }) |
145 | 161 | ||
146 | #define hypercall3(id, p1, p2, p3) \ |
162 | #define hypercall3(id, p1, p2, p3) \ |
147 | ({ \ |
163 | ({ \ |
148 | unative_t ret, __ign1, __ign2, __ign3; \ |
164 | unative_t ret, __ign1, __ign2, __ign3; \ |
149 | asm volatile ( \ |
165 | asm volatile ( \ |
150 | "call hypercall_page + (" STRING(id) " * 32)\n" \ |
166 | "call hypercall_page + (" STRING(id) " * 32)\n" \ |
151 | : "=a" (ret), \ |
167 | : "=a" (ret), \ |
152 | "=b" (__ign1), \ |
168 | "=b" (__ign1), \ |
153 | "=c" (__ign2), \ |
169 | "=c" (__ign2), \ |
154 | "=d" (__ign3) \ |
170 | "=d" (__ign3) \ |
155 | : "1" (p1), \ |
171 | : "1" (p1), \ |
156 | "2" (p2), \ |
172 | "2" (p2), \ |
157 | "3" (p3) \ |
173 | "3" (p3) \ |
158 | : "memory" \ |
174 | : "memory" \ |
159 | ); \ |
175 | ); \ |
160 | ret; \ |
176 | ret; \ |
161 | }) |
177 | }) |
162 | 178 | ||
163 | #define hypercall4(id, p1, p2, p3, p4) \ |
179 | #define hypercall4(id, p1, p2, p3, p4) \ |
164 | ({ \ |
180 | ({ \ |
165 | unative_t ret, __ign1, __ign2, __ign3, __ign4; \ |
181 | unative_t ret, __ign1, __ign2, __ign3, __ign4; \ |
166 | asm volatile ( \ |
182 | asm volatile ( \ |
167 | "call hypercall_page + (" STRING(id) " * 32)\n" \ |
183 | "call hypercall_page + (" STRING(id) " * 32)\n" \ |
168 | : "=a" (ret), \ |
184 | : "=a" (ret), \ |
169 | "=b" (__ign1), \ |
185 | "=b" (__ign1), \ |
170 | "=c" (__ign2), \ |
186 | "=c" (__ign2), \ |
171 | "=d" (__ign3), \ |
187 | "=d" (__ign3), \ |
172 | "=S" (__ign4) \ |
188 | "=S" (__ign4) \ |
173 | : "1" (p1), \ |
189 | : "1" (p1), \ |
174 | "2" (p2), \ |
190 | "2" (p2), \ |
175 | "3" (p3), \ |
191 | "3" (p3), \ |
176 | "4" (p4) \ |
192 | "4" (p4) \ |
177 | : "memory" \ |
193 | : "memory" \ |
178 | ); \ |
194 | ); \ |
179 | ret; \ |
195 | ret; \ |
180 | }) |
196 | }) |
181 | 197 | ||
182 | #define hypercall5(id, p1, p2, p3, p4, p5) \ |
198 | #define hypercall5(id, p1, p2, p3, p4, p5) \ |
183 | ({ \ |
199 | ({ \ |
184 | unative_t ret, __ign1, __ign2, __ign3, __ign4, __ign5; \ |
200 | unative_t ret, __ign1, __ign2, __ign3, __ign4, __ign5; \ |
185 | asm volatile ( \ |
201 | asm volatile ( \ |
186 | "call hypercall_page + (" STRING(id) " * 32)\n" \ |
202 | "call hypercall_page + (" STRING(id) " * 32)\n" \ |
187 | : "=a" (ret), \ |
203 | : "=a" (ret), \ |
188 | "=b" (__ign1), \ |
204 | "=b" (__ign1), \ |
189 | "=c" (__ign2), \ |
205 | "=c" (__ign2), \ |
190 | "=d" (__ign3), \ |
206 | "=d" (__ign3), \ |
191 | "=S" (__ign4), \ |
207 | "=S" (__ign4), \ |
192 | "=D" (__ign5) \ |
208 | "=D" (__ign5) \ |
193 | : "1" (p1), \ |
209 | : "1" (p1), \ |
194 | "2" (p2), \ |
210 | "2" (p2), \ |
195 | "3" (p3), \ |
211 | "3" (p3), \ |
196 | "4" (p4), \ |
212 | "4" (p4), \ |
197 | "5" (p5) \ |
213 | "5" (p5) \ |
198 | : "memory" \ |
214 | : "memory" \ |
199 | ); \ |
215 | ); \ |
200 | ret; \ |
216 | ret; \ |
201 | }) |
217 | }) |
202 | 218 | ||
203 | 219 | ||
204 | static inline int xen_console_io(const unsigned int cmd, const unsigned int count, const char *str) |
220 | static inline int xen_console_io(const unsigned int cmd, const unsigned int count, const char *str) |
205 | { |
221 | { |
206 | return hypercall3(XEN_CONSOLE_IO, cmd, count, str); |
222 | return hypercall3(XEN_CONSOLE_IO, cmd, count, str); |
207 | } |
223 | } |
208 | 224 | ||
209 | static inline int xen_vm_assist(const unsigned int cmd, const unsigned int type) |
225 | static inline int xen_vm_assist(const unsigned int cmd, const unsigned int type) |
210 | { |
226 | { |
211 | return hypercall2(XEN_VM_ASSIST, cmd, type); |
227 | return hypercall2(XEN_VM_ASSIST, cmd, type); |
212 | } |
228 | } |
213 | 229 | ||
214 | static inline int xen_set_callbacks(const unsigned int event_selector, const void *event_address, const unsigned int failsafe_selector, void *failsafe_address) |
230 | static inline int xen_set_callbacks(const unsigned int event_selector, const void *event_address, const unsigned int failsafe_selector, void *failsafe_address) |
215 | { |
231 | { |
216 | return hypercall4(XEN_SET_CALLBACKS, event_selector, event_address, failsafe_selector, failsafe_address); |
232 | return hypercall4(XEN_SET_CALLBACKS, event_selector, event_address, failsafe_selector, failsafe_address); |
217 | } |
233 | } |
218 | 234 | ||
219 | static inline int xen_set_trap_table(const trap_info_t *table) |
235 | static inline int xen_set_trap_table(const trap_info_t *table) |
220 | { |
236 | { |
221 | return hypercall1(XEN_SET_TRAP_TABLE, table); |
237 | return hypercall1(XEN_SET_TRAP_TABLE, table); |
222 | } |
238 | } |
223 | 239 | ||
224 | static inline int xen_version(const unsigned int cmd, const void *arg) |
240 | static inline int xen_version(const unsigned int cmd, const void *arg) |
225 | { |
241 | { |
226 | return hypercall2(XEN_VERSION, cmd, arg); |
242 | return hypercall2(XEN_VERSION, cmd, arg); |
227 | } |
243 | } |
- | 244 | ||
- | 245 | static inline int xen_notify_remote(evtchn_t channel) |
|
- | 246 | { |
|
- | 247 | evtchn_op_t op; |
|
- | 248 | ||
- | 249 | op.cmd = EVTCHNOP_SEND; |
|
- | 250 | op.send.port = channel; |
|
- | 251 | return hypercall1(XEN_EVENT_CHANNEL_OP, &op); |
|
- | 252 | } |
|
228 | 253 | ||
229 | #endif |
254 | #endif |
230 | 255 |