Rev 2017 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2017 | Rev 2071 | ||
---|---|---|---|
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 KERN_ia32xen_HYPERCALL_H_ |
29 | #ifndef KERN_ia32xen_HYPERCALL_H_ |
30 | #define KERN_ia32xen_HYPERCALL_H_ |
30 | #define KERN_ia32xen_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 | typedef uint16_t domid_t; |
35 | typedef uint16_t domid_t; |
36 | 36 | ||
37 | typedef struct { |
37 | typedef struct { |
38 | uint8_t vector; /**< Exception vector */ |
38 | uint8_t vector; /**< Exception vector */ |
39 | uint8_t flags; /**< 0-3: privilege level; 4: clear event enable */ |
39 | uint8_t flags; /**< 0-3: privilege level; 4: clear event enable */ |
40 | uint16_t cs; /**< Code selector */ |
40 | uint16_t cs; /**< Code selector */ |
41 | void *address; /**< Code offset */ |
41 | void *address; /**< Code offset */ |
42 | } trap_info_t; |
42 | } trap_info_t; |
43 | 43 | ||
44 | 44 | ||
45 | typedef struct { |
45 | typedef struct { |
46 | evtchn_t port; |
46 | evtchn_t port; |
47 | } evtchn_send_t; |
47 | } evtchn_send_t; |
48 | 48 | ||
49 | typedef struct { |
49 | typedef struct { |
50 | uint32_t cmd; |
50 | uint32_t cmd; |
51 | union { |
51 | union { |
52 | evtchn_send_t send; |
52 | evtchn_send_t send; |
53 | }; |
53 | }; |
54 | } evtchn_op_t; |
54 | } evtchn_op_t; |
55 | 55 | ||
56 | 56 | ||
57 | #define XEN_SET_TRAP_TABLE 0 |
57 | #define XEN_SET_TRAP_TABLE 0 |
58 | #define XEN_MMU_UPDATE 1 |
58 | #define XEN_MMU_UPDATE 1 |
59 | #define XEN_SET_CALLBACKS 4 |
59 | #define XEN_SET_CALLBACKS 4 |
60 | #define XEN_UPDATE_VA_MAPPING 14 |
60 | #define XEN_UPDATE_VA_MAPPING 14 |
61 | #define XEN_EVENT_CHANNEL_OP 16 |
61 | #define XEN_EVENT_CHANNEL_OP 16 |
62 | #define XEN_VERSION 17 |
62 | #define XEN_VERSION 17 |
63 | #define XEN_CONSOLE_IO 18 |
63 | #define XEN_CONSOLE_IO 18 |
64 | #define XEN_MMUEXT_OP 26 |
64 | #define XEN_MMUEXT_OP 26 |
65 | 65 | ||
66 | 66 | ||
67 | /* |
67 | /* |
68 | * Commands for XEN_CONSOLE_IO |
68 | * Commands for XEN_CONSOLE_IO |
69 | */ |
69 | */ |
70 | #define CONSOLE_IO_WRITE 0 |
70 | #define CONSOLE_IO_WRITE 0 |
71 | #define CONSOLE_IO_READ 1 |
71 | #define CONSOLE_IO_READ 1 |
72 | 72 | ||
73 | 73 | ||
74 | #define MMUEXT_PIN_L1_TABLE 0 |
74 | #define MMUEXT_PIN_L1_TABLE 0 |
75 | #define MMUEXT_PIN_L2_TABLE 1 |
75 | #define MMUEXT_PIN_L2_TABLE 1 |
76 | #define MMUEXT_PIN_L3_TABLE 2 |
76 | #define MMUEXT_PIN_L3_TABLE 2 |
77 | #define MMUEXT_PIN_L4_TABLE 3 |
77 | #define MMUEXT_PIN_L4_TABLE 3 |
78 | #define MMUEXT_UNPIN_TABLE 4 |
78 | #define MMUEXT_UNPIN_TABLE 4 |
79 | #define MMUEXT_NEW_BASEPTR 5 |
79 | #define MMUEXT_NEW_BASEPTR 5 |
80 | #define MMUEXT_TLB_FLUSH_LOCAL 6 |
80 | #define MMUEXT_TLB_FLUSH_LOCAL 6 |
81 | #define MMUEXT_INVLPG_LOCAL 7 |
81 | #define MMUEXT_INVLPG_LOCAL 7 |
82 | #define MMUEXT_TLB_FLUSH_MULTI 8 |
82 | #define MMUEXT_TLB_FLUSH_MULTI 8 |
83 | #define MMUEXT_INVLPG_MULTI 9 |
83 | #define MMUEXT_INVLPG_MULTI 9 |
84 | #define MMUEXT_TLB_FLUSH_ALL 10 |
84 | #define MMUEXT_TLB_FLUSH_ALL 10 |
85 | #define MMUEXT_INVLPG_ALL 11 |
85 | #define MMUEXT_INVLPG_ALL 11 |
86 | #define MMUEXT_FLUSH_CACHE 12 |
86 | #define MMUEXT_FLUSH_CACHE 12 |
87 | #define MMUEXT_SET_LDT 13 |
87 | #define MMUEXT_SET_LDT 13 |
88 | #define MMUEXT_NEW_USER_BASEPTR 15 |
88 | #define MMUEXT_NEW_USER_BASEPTR 15 |
89 | 89 | ||
90 | 90 | ||
91 | #define EVTCHNOP_SEND 4 |
91 | #define EVTCHNOP_SEND 4 |
92 | 92 | ||
93 | 93 | ||
94 | #define UVMF_NONE 0 /**< No flushing at all */ |
94 | #define UVMF_NONE 0 /**< No flushing at all */ |
95 | #define UVMF_TLB_FLUSH 1 /**< Flush entire TLB(s) */ |
95 | #define UVMF_TLB_FLUSH 1 /**< Flush entire TLB(s) */ |
96 | #define UVMF_INVLPG 2 /**< Flush only one entry */ |
96 | #define UVMF_INVLPG 2 /**< Flush only one entry */ |
97 | #define UVMF_FLUSHTYPE_MASK 3 |
97 | #define UVMF_FLUSHTYPE_MASK 3 |
98 | #define UVMF_MULTI 0 /**< Flush subset of TLBs */ |
98 | #define UVMF_MULTI 0 /**< Flush subset of TLBs */ |
99 | #define UVMF_LOCAL 0 /**< Flush local TLB */ |
99 | #define UVMF_LOCAL 0 /**< Flush local TLB */ |
100 | #define UVMF_ALL (1 << 2) /**< Flush all TLBs */ |
100 | #define UVMF_ALL (1 << 2) /**< Flush all TLBs */ |
101 | 101 | ||
102 | 102 | ||
103 | #define DOMID_SELF (0x7FF0U) |
103 | #define DOMID_SELF (0x7FF0U) |
104 | #define DOMID_IO (0x7FF1U) |
104 | #define DOMID_IO (0x7FF1U) |
105 | 105 | ||
106 | 106 | ||
107 | #define force_evtchn_callback() ((void) xen_version(0, 0)) |
107 | #define force_evtchn_callback() ((void) xen_version(0, 0)) |
108 | 108 | ||
109 | #define hypercall0(id) \ |
109 | #define hypercall0(id) \ |
110 | ({ \ |
110 | ({ \ |
111 | unative_t ret; \ |
111 | unative_t ret; \ |
112 | asm volatile ( \ |
112 | asm volatile ( \ |
113 | "call hypercall_page + (" STRING(id) " * 32)\n" \ |
113 | "call hypercall_page + (" STRING(id) " * 32)\n" \ |
114 | : "=a" (ret) \ |
114 | : "=a" (ret) \ |
115 | : \ |
115 | : \ |
116 | : "memory" \ |
116 | : "memory" \ |
117 | ); \ |
117 | ); \ |
118 | ret; \ |
118 | ret; \ |
119 | }) |
119 | }) |
120 | 120 | ||
121 | #define hypercall1(id, p1) \ |
121 | #define hypercall1(id, p1) \ |
122 | ({ \ |
122 | ({ \ |
123 | unative_t ret, __ign1; \ |
123 | unative_t ret, __ign1; \ |
124 | asm volatile ( \ |
124 | asm volatile ( \ |
125 | "call hypercall_page + (" STRING(id) " * 32)\n" \ |
125 | "call hypercall_page + (" STRING(id) " * 32)\n" \ |
126 | : "=a" (ret), \ |
126 | : "=a" (ret), \ |
127 | "=b" (__ign1) \ |
127 | "=b" (__ign1) \ |
128 | : "1" (p1) \ |
128 | : "1" (p1) \ |
129 | : "memory" \ |
129 | : "memory" \ |
130 | ); \ |
130 | ); \ |
131 | ret; \ |
131 | ret; \ |
132 | }) |
132 | }) |
133 | 133 | ||
134 | #define hypercall2(id, p1, p2) \ |
134 | #define hypercall2(id, p1, p2) \ |
135 | ({ \ |
135 | ({ \ |
136 | unative_t ret, __ign1, __ign2; \ |
136 | unative_t ret, __ign1, __ign2; \ |
137 | asm volatile ( \ |
137 | asm volatile ( \ |
138 | "call hypercall_page + (" STRING(id) " * 32)\n" \ |
138 | "call hypercall_page + (" STRING(id) " * 32)\n" \ |
139 | : "=a" (ret), \ |
139 | : "=a" (ret), \ |
140 | "=b" (__ign1), \ |
140 | "=b" (__ign1), \ |
141 | "=c" (__ign2) \ |
141 | "=c" (__ign2) \ |
142 | : "1" (p1), \ |
142 | : "1" (p1), \ |
143 | "2" (p2) \ |
143 | "2" (p2) \ |
144 | : "memory" \ |
144 | : "memory" \ |
145 | ); \ |
145 | ); \ |
146 | ret; \ |
146 | ret; \ |
147 | }) |
147 | }) |
148 | 148 | ||
149 | #define hypercall3(id, p1, p2, p3) \ |
149 | #define hypercall3(id, p1, p2, p3) \ |
150 | ({ \ |
150 | ({ \ |
151 | unative_t ret, __ign1, __ign2, __ign3; \ |
151 | unative_t ret, __ign1, __ign2, __ign3; \ |
152 | asm volatile ( \ |
152 | asm volatile ( \ |
153 | "call hypercall_page + (" STRING(id) " * 32)\n" \ |
153 | "call hypercall_page + (" STRING(id) " * 32)\n" \ |
154 | : "=a" (ret), \ |
154 | : "=a" (ret), \ |
155 | "=b" (__ign1), \ |
155 | "=b" (__ign1), \ |
156 | "=c" (__ign2), \ |
156 | "=c" (__ign2), \ |
157 | "=d" (__ign3) \ |
157 | "=d" (__ign3) \ |
158 | : "1" (p1), \ |
158 | : "1" (p1), \ |
159 | "2" (p2), \ |
159 | "2" (p2), \ |
160 | "3" (p3) \ |
160 | "3" (p3) \ |
161 | : "memory" \ |
161 | : "memory" \ |
162 | ); \ |
162 | ); \ |
163 | ret; \ |
163 | ret; \ |
164 | }) |
164 | }) |
165 | 165 | ||
166 | #define hypercall4(id, p1, p2, p3, p4) \ |
166 | #define hypercall4(id, p1, p2, p3, p4) \ |
167 | ({ \ |
167 | ({ \ |
168 | unative_t ret, __ign1, __ign2, __ign3, __ign4; \ |
168 | unative_t ret, __ign1, __ign2, __ign3, __ign4; \ |
169 | asm volatile ( \ |
169 | asm volatile ( \ |
170 | "call hypercall_page + (" STRING(id) " * 32)\n" \ |
170 | "call hypercall_page + (" STRING(id) " * 32)\n" \ |
171 | : "=a" (ret), \ |
171 | : "=a" (ret), \ |
172 | "=b" (__ign1), \ |
172 | "=b" (__ign1), \ |
173 | "=c" (__ign2), \ |
173 | "=c" (__ign2), \ |
174 | "=d" (__ign3), \ |
174 | "=d" (__ign3), \ |
175 | "=S" (__ign4) \ |
175 | "=S" (__ign4) \ |
176 | : "1" (p1), \ |
176 | : "1" (p1), \ |
177 | "2" (p2), \ |
177 | "2" (p2), \ |
178 | "3" (p3), \ |
178 | "3" (p3), \ |
179 | "4" (p4) \ |
179 | "4" (p4) \ |
180 | : "memory" \ |
180 | : "memory" \ |
181 | ); \ |
181 | ); \ |
182 | ret; \ |
182 | ret; \ |
183 | }) |
183 | }) |
184 | 184 | ||
185 | #define hypercall5(id, p1, p2, p3, p4, p5) \ |
185 | #define hypercall5(id, p1, p2, p3, p4, p5) \ |
186 | ({ \ |
186 | ({ \ |
187 | unative_t ret, __ign1, __ign2, __ign3, __ign4, __ign5; \ |
187 | unative_t ret, __ign1, __ign2, __ign3, __ign4, __ign5; \ |
188 | asm volatile ( \ |
188 | asm volatile ( \ |
189 | "call hypercall_page + (" STRING(id) " * 32)\n" \ |
189 | "call hypercall_page + (" STRING(id) " * 32)\n" \ |
190 | : "=a" (ret), \ |
190 | : "=a" (ret), \ |
191 | "=b" (__ign1), \ |
191 | "=b" (__ign1), \ |
192 | "=c" (__ign2), \ |
192 | "=c" (__ign2), \ |
193 | "=d" (__ign3), \ |
193 | "=d" (__ign3), \ |
194 | "=S" (__ign4), \ |
194 | "=S" (__ign4), \ |
195 | "=D" (__ign5) \ |
195 | "=D" (__ign5) \ |
196 | : "1" (p1), \ |
196 | : "1" (p1), \ |
197 | "2" (p2), \ |
197 | "2" (p2), \ |
198 | "3" (p3), \ |
198 | "3" (p3), \ |
199 | "4" (p4), \ |
199 | "4" (p4), \ |
200 | "5" (p5) \ |
200 | "5" (p5) \ |
201 | : "memory" \ |
201 | : "memory" \ |
202 | ); \ |
202 | ); \ |
203 | ret; \ |
203 | ret; \ |
204 | }) |
204 | }) |
205 | 205 | ||
206 | 206 | ||
207 | static inline int xen_console_io(const unsigned int cmd, const unsigned int count, const char *str) |
207 | static inline int xen_console_io(const unsigned int cmd, const unsigned int count, const char *str) |
208 | { |
208 | { |
209 | return hypercall3(XEN_CONSOLE_IO, cmd, count, str); |
209 | return hypercall3(XEN_CONSOLE_IO, cmd, count, str); |
210 | } |
210 | } |
211 | 211 | ||
212 | static inline int xen_set_callbacks(const unsigned int event_selector, const void *event_address, const unsigned int failsafe_selector, void *failsafe_address) |
212 | static inline int xen_set_callbacks(const unsigned int event_selector, const void *event_address, const unsigned int failsafe_selector, void *failsafe_address) |
213 | { |
213 | { |
214 | return hypercall4(XEN_SET_CALLBACKS, event_selector, event_address, failsafe_selector, failsafe_address); |
214 | return hypercall4(XEN_SET_CALLBACKS, event_selector, event_address, failsafe_selector, failsafe_address); |
215 | } |
215 | } |
216 | 216 | ||
217 | static inline int xen_set_trap_table(const trap_info_t *table) |
217 | static inline int xen_set_trap_table(const trap_info_t *table) |
218 | { |
218 | { |
219 | return hypercall1(XEN_SET_TRAP_TABLE, table); |
219 | return hypercall1(XEN_SET_TRAP_TABLE, table); |
220 | } |
220 | } |
221 | 221 | ||
222 | static inline int xen_version(const unsigned int cmd, const void *arg) |
222 | static inline int xen_version(const unsigned int cmd, const void *arg) |
223 | { |
223 | { |
224 | return hypercall2(XEN_VERSION, cmd, arg); |
224 | return hypercall2(XEN_VERSION, cmd, arg); |
225 | } |
225 | } |
226 | 226 | ||
227 | static inline int xen_notify_remote(evtchn_t channel) |
227 | static inline int xen_notify_remote(evtchn_t channel) |
228 | { |
228 | { |
229 | evtchn_op_t op; |
229 | evtchn_op_t op; |
230 | 230 | ||
231 | op.cmd = EVTCHNOP_SEND; |
231 | op.cmd = EVTCHNOP_SEND; |
232 | op.send.port = channel; |
232 | op.send.port = channel; |
233 | return hypercall1(XEN_EVENT_CHANNEL_OP, &op); |
233 | return hypercall1(XEN_EVENT_CHANNEL_OP, &op); |
234 | } |
234 | } |
235 | 235 | ||
236 | #endif |
236 | #endif |
237 | 237 |