1 | /* $NetBSD: xen.h,v 1.11 2011/12/07 15:04:18 cegger Exp $ */ |
2 | /****************************************************************************** |
3 | * xen.h |
4 | * |
5 | * Guest OS interface to Xen. |
6 | * |
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
8 | * of this software and associated documentation files (the "Software"), to |
9 | * deal in the Software without restriction, including without limitation the |
10 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
11 | * sell copies of the Software, and to permit persons to whom the Software is |
12 | * furnished to do so, subject to the following conditions: |
13 | * |
14 | * The above copyright notice and this permission notice shall be included in |
15 | * all copies or substantial portions of the Software. |
16 | * |
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
23 | * DEALINGS IN THE SOFTWARE. |
24 | * |
25 | * Copyright (c) 2004, K A Fraser |
26 | */ |
27 | |
28 | #ifndef __XEN_PUBLIC_XEN_H__ |
29 | #define __XEN_PUBLIC_XEN_H__ |
30 | |
31 | #include "xen-compat.h" |
32 | |
33 | #if defined(__i386__) || defined(__x86_64__) |
34 | #include "arch-x86/xen.h" |
35 | #elif defined(__ia64__) |
36 | #include "arch-ia64.h" |
37 | #else |
38 | #error "Unsupported architecture" |
39 | #endif |
40 | |
41 | #ifndef __ASSEMBLY__ |
42 | /* Guest handles for primitive C types. */ |
43 | DEFINE_XEN_GUEST_HANDLE(char); |
44 | __DEFINE_XEN_GUEST_HANDLE(uchar, unsigned char); |
45 | DEFINE_XEN_GUEST_HANDLE(int); |
46 | __DEFINE_XEN_GUEST_HANDLE(uint, unsigned int); |
47 | DEFINE_XEN_GUEST_HANDLE(long); |
48 | __DEFINE_XEN_GUEST_HANDLE(ulong, unsigned long); |
49 | DEFINE_XEN_GUEST_HANDLE(void); |
50 | |
51 | DEFINE_XEN_GUEST_HANDLE(uint64_t); |
52 | DEFINE_XEN_GUEST_HANDLE(xen_pfn_t); |
53 | #endif |
54 | |
55 | /* |
56 | * HYPERCALLS |
57 | */ |
58 | |
59 | #define __HYPERVISOR_set_trap_table 0 |
60 | #define __HYPERVISOR_mmu_update 1 |
61 | #define __HYPERVISOR_set_gdt 2 |
62 | #define __HYPERVISOR_stack_switch 3 |
63 | #define __HYPERVISOR_set_callbacks 4 |
64 | #define __HYPERVISOR_fpu_taskswitch 5 |
65 | #define __HYPERVISOR_sched_op_compat 6 /* compat since 0x00030101 */ |
66 | #define __HYPERVISOR_platform_op 7 |
67 | #define __HYPERVISOR_set_debugreg 8 |
68 | #define __HYPERVISOR_get_debugreg 9 |
69 | #define __HYPERVISOR_update_descriptor 10 |
70 | #define __HYPERVISOR_memory_op 12 |
71 | #define __HYPERVISOR_multicall 13 |
72 | #define __HYPERVISOR_update_va_mapping 14 |
73 | #define __HYPERVISOR_set_timer_op 15 |
74 | #define __HYPERVISOR_event_channel_op_compat 16 /* compat since 0x00030202 */ |
75 | #define __HYPERVISOR_xen_version 17 |
76 | #define __HYPERVISOR_console_io 18 |
77 | #define __HYPERVISOR_physdev_op_compat 19 /* compat since 0x00030202 */ |
78 | #define __HYPERVISOR_grant_table_op 20 |
79 | #define __HYPERVISOR_vm_assist 21 |
80 | #define __HYPERVISOR_update_va_mapping_otherdomain 22 |
81 | #define __HYPERVISOR_iret 23 /* x86 only */ |
82 | #define __HYPERVISOR_vcpu_op 24 |
83 | #define __HYPERVISOR_set_segment_base 25 /* x86/64 only */ |
84 | #define __HYPERVISOR_mmuext_op 26 |
85 | #define __HYPERVISOR_xsm_op 27 |
86 | #define __HYPERVISOR_nmi_op 28 |
87 | #define __HYPERVISOR_sched_op 29 |
88 | #define __HYPERVISOR_callback_op 30 |
89 | #define __HYPERVISOR_xenoprof_op 31 |
90 | #define __HYPERVISOR_event_channel_op 32 |
91 | #define __HYPERVISOR_physdev_op 33 |
92 | #define __HYPERVISOR_hvm_op 34 |
93 | #define __HYPERVISOR_sysctl 35 |
94 | #define __HYPERVISOR_domctl 36 |
95 | #define __HYPERVISOR_kexec_op 37 |
96 | #define __HYPERVISOR_tmem_op 38 |
97 | |
98 | /* Architecture-specific hypercall definitions. */ |
99 | #define __HYPERVISOR_arch_0 48 |
100 | #define __HYPERVISOR_arch_1 49 |
101 | #define __HYPERVISOR_arch_2 50 |
102 | #define __HYPERVISOR_arch_3 51 |
103 | #define __HYPERVISOR_arch_4 52 |
104 | #define __HYPERVISOR_arch_5 53 |
105 | #define __HYPERVISOR_arch_6 54 |
106 | #define __HYPERVISOR_arch_7 55 |
107 | |
108 | /* |
109 | * HYPERCALL COMPATIBILITY. |
110 | */ |
111 | |
112 | /* New sched_op hypercall introduced in 0x00030101. */ |
113 | #if __XEN_INTERFACE_VERSION__ < 0x00030101 |
114 | #undef __HYPERVISOR_sched_op |
115 | #define __HYPERVISOR_sched_op __HYPERVISOR_sched_op_compat |
116 | #endif |
117 | |
118 | /* New event-channel and physdev hypercalls introduced in 0x00030202. */ |
119 | #if __XEN_INTERFACE_VERSION__ < 0x00030202 |
120 | #undef __HYPERVISOR_event_channel_op |
121 | #define __HYPERVISOR_event_channel_op __HYPERVISOR_event_channel_op_compat |
122 | #undef __HYPERVISOR_physdev_op |
123 | #define __HYPERVISOR_physdev_op __HYPERVISOR_physdev_op_compat |
124 | #endif |
125 | |
126 | /* New platform_op hypercall introduced in 0x00030204. */ |
127 | #if __XEN_INTERFACE_VERSION__ < 0x00030204 |
128 | #define __HYPERVISOR_dom0_op __HYPERVISOR_platform_op |
129 | #endif |
130 | |
131 | /* |
132 | * VIRTUAL INTERRUPTS |
133 | * |
134 | * Virtual interrupts that a guest OS may receive from Xen. |
135 | * |
136 | * In the side comments, 'V.' denotes a per-VCPU VIRQ while 'G.' denotes a |
137 | * global VIRQ. The former can be bound once per VCPU and cannot be re-bound. |
138 | * The latter can be allocated only once per guest: they must initially be |
139 | * allocated to VCPU0 but can subsequently be re-bound. |
140 | */ |
141 | #define VIRQ_TIMER 0 /* V. Timebase update, and/or requested timeout. */ |
142 | #define VIRQ_DEBUG 1 /* V. Request guest to dump debug info. */ |
143 | #define VIRQ_CONSOLE 2 /* G. (DOM0) Bytes received on emergency console. */ |
144 | #define VIRQ_DOM_EXC 3 /* G. (DOM0) Exceptional event for some domain. */ |
145 | #define VIRQ_TBUF 4 /* G. (DOM0) Trace buffer has records available. */ |
146 | #define VIRQ_DEBUGGER 6 /* G. (DOM0) A domain has paused for debugging. */ |
147 | #define VIRQ_XENOPROF 7 /* V. XenOprofile interrupt: new sample available */ |
148 | #define VIRQ_CON_RING 8 /* G. (DOM0) Bytes received on console */ |
149 | #define VIRQ_PCPU_STATE 9 /* G. (DOM0) PCPU state changed */ |
150 | #define VIRQ_MEM_EVENT 10 /* G. (DOM0) A memory event has occured */ |
151 | |
152 | /* Architecture-specific VIRQ definitions. */ |
153 | #define VIRQ_ARCH_0 16 |
154 | #define VIRQ_ARCH_1 17 |
155 | #define VIRQ_ARCH_2 18 |
156 | #define VIRQ_ARCH_3 19 |
157 | #define VIRQ_ARCH_4 20 |
158 | #define VIRQ_ARCH_5 21 |
159 | #define VIRQ_ARCH_6 22 |
160 | #define VIRQ_ARCH_7 23 |
161 | |
162 | #define NR_VIRQS 24 |
163 | |
164 | /* |
165 | * HYPERVISOR_mmu_update(reqs, count, pdone, foreigndom) |
166 | * |
167 | * @reqs is an array of mmu_update_t structures ((ptr, val) pairs). |
168 | * @count is the length of the above array. |
169 | * @pdone is an output parameter indicating number of completed operations |
170 | * @foreigndom[15:0]: FD, the expected owner of data pages referenced in this |
171 | * hypercall invocation. Can be DOMID_SELF. |
172 | * @foreigndom[31:16]: PFD, the expected owner of pagetable pages referenced |
173 | * in this hypercall invocation. The value of this field |
174 | * (x) encodes the PFD as follows: |
175 | * x == 0 => PFD == DOMID_SELF |
176 | * x != 0 => PFD == x - 1 |
177 | * |
178 | * Sub-commands: ptr[1:0] specifies the appropriate MMU_* command. |
179 | * ------------- |
180 | * ptr[1:0] == MMU_NORMAL_PT_UPDATE: |
181 | * Updates an entry in a page table belonging to PFD. If updating an L1 table, |
182 | * and the new table entry is valid/present, the mapped frame must belong to |
183 | * FD. If attempting to map an I/O page then the caller assumes the privilege |
184 | * of the FD. |
185 | * FD == DOMID_IO: Permit /only/ I/O mappings, at the priv level of the caller. |
186 | * FD == DOMID_XEN: Map restricted areas of Xen's heap space. |
187 | * ptr[:2] -- Machine address of the page-table entry to modify. |
188 | * val -- Value to write. |
189 | * |
190 | * ptr[1:0] == MMU_MACHPHYS_UPDATE: |
191 | * Updates an entry in the machine->pseudo-physical mapping table. |
192 | * ptr[:2] -- Machine address within the frame whose mapping to modify. |
193 | * The frame must belong to the FD, if one is specified. |
194 | * val -- Value to write into the mapping entry. |
195 | * |
196 | * ptr[1:0] == MMU_PT_UPDATE_PRESERVE_AD: |
197 | * As MMU_NORMAL_PT_UPDATE above, but A/D bits currently in the PTE are ORed |
198 | * with those in @val. |
199 | */ |
200 | #define MMU_NORMAL_PT_UPDATE 0 /* checked '*ptr = val'. ptr is MA. */ |
201 | #define MMU_MACHPHYS_UPDATE 1 /* ptr = MA of frame to modify entry for */ |
202 | #define MMU_PT_UPDATE_PRESERVE_AD 2 /* atomically: *ptr = val | (*ptr&(A|D)) */ |
203 | |
204 | /* |
205 | * MMU EXTENDED OPERATIONS |
206 | * |
207 | * HYPERVISOR_mmuext_op() accepts a list of mmuext_op structures. |
208 | * A foreigndom (FD) can be specified (or DOMID_SELF for none). |
209 | * Where the FD has some effect, it is described below. |
210 | * |
211 | * cmd: MMUEXT_(UN)PIN_*_TABLE |
212 | * mfn: Machine frame number to be (un)pinned as a p.t. page. |
213 | * The frame must belong to the FD, if one is specified. |
214 | * |
215 | * cmd: MMUEXT_NEW_BASEPTR |
216 | * mfn: Machine frame number of new page-table base to install in MMU. |
217 | * |
218 | * cmd: MMUEXT_NEW_USER_BASEPTR [x86/64 only] |
219 | * mfn: Machine frame number of new page-table base to install in MMU |
220 | * when in user space. |
221 | * |
222 | * cmd: MMUEXT_TLB_FLUSH_LOCAL |
223 | * No additional arguments. Flushes local TLB. |
224 | * |
225 | * cmd: MMUEXT_INVLPG_LOCAL |
226 | * linear_addr: Linear address to be flushed from the local TLB. |
227 | * |
228 | * cmd: MMUEXT_TLB_FLUSH_MULTI |
229 | * vcpumask: Pointer to bitmap of VCPUs to be flushed. |
230 | * |
231 | * cmd: MMUEXT_INVLPG_MULTI |
232 | * linear_addr: Linear address to be flushed. |
233 | * vcpumask: Pointer to bitmap of VCPUs to be flushed. |
234 | * |
235 | * cmd: MMUEXT_TLB_FLUSH_ALL |
236 | * No additional arguments. Flushes all VCPUs' TLBs. |
237 | * |
238 | * cmd: MMUEXT_INVLPG_ALL |
239 | * linear_addr: Linear address to be flushed from all VCPUs' TLBs. |
240 | * |
241 | * cmd: MMUEXT_FLUSH_CACHE |
242 | * No additional arguments. Writes back and flushes cache contents. |
243 | * |
244 | * cmd: MMUEXT_FLUSH_CACHE_GLOBAL |
245 | * No additional arguments. Writes back and flushes cache contents |
246 | * on all CPUs in the system. |
247 | * |
248 | * cmd: MMUEXT_SET_LDT |
249 | * linear_addr: Linear address of LDT base (NB. must be page-aligned). |
250 | * nr_ents: Number of entries in LDT. |
251 | * |
252 | * cmd: MMUEXT_CLEAR_PAGE |
253 | * mfn: Machine frame number to be cleared. |
254 | * |
255 | * cmd: MMUEXT_COPY_PAGE |
256 | * mfn: Machine frame number of the destination page. |
257 | * src_mfn: Machine frame number of the source page. |
258 | * |
259 | * cmd: MMUEXT_[UN]MARK_SUPER |
260 | * mfn: Machine frame number of head of superpage to be [un]marked. |
261 | */ |
262 | #define MMUEXT_PIN_L1_TABLE 0 |
263 | #define MMUEXT_PIN_L2_TABLE 1 |
264 | #define MMUEXT_PIN_L3_TABLE 2 |
265 | #define MMUEXT_PIN_L4_TABLE 3 |
266 | #define MMUEXT_UNPIN_TABLE 4 |
267 | #define MMUEXT_NEW_BASEPTR 5 |
268 | #define MMUEXT_TLB_FLUSH_LOCAL 6 |
269 | #define MMUEXT_INVLPG_LOCAL 7 |
270 | #define MMUEXT_TLB_FLUSH_MULTI 8 |
271 | #define MMUEXT_INVLPG_MULTI 9 |
272 | #define MMUEXT_TLB_FLUSH_ALL 10 |
273 | #define MMUEXT_INVLPG_ALL 11 |
274 | #define MMUEXT_FLUSH_CACHE 12 |
275 | #define MMUEXT_SET_LDT 13 |
276 | #define MMUEXT_NEW_USER_BASEPTR 15 |
277 | #define MMUEXT_CLEAR_PAGE 16 |
278 | #define MMUEXT_COPY_PAGE 17 |
279 | #define MMUEXT_FLUSH_CACHE_GLOBAL 18 |
280 | #define MMUEXT_MARK_SUPER 19 |
281 | #define MMUEXT_UNMARK_SUPER 20 |
282 | |
283 | #ifndef __ASSEMBLY__ |
284 | struct mmuext_op { |
285 | unsigned int cmd; |
286 | union { |
287 | /* [UN]PIN_TABLE, NEW_BASEPTR, NEW_USER_BASEPTR |
288 | * CLEAR_PAGE, COPY_PAGE, [UN]MARK_SUPER */ |
289 | xen_pfn_t mfn; |
290 | /* INVLPG_LOCAL, INVLPG_ALL, SET_LDT */ |
291 | unsigned long linear_addr; |
292 | } arg1; |
293 | union { |
294 | /* SET_LDT */ |
295 | unsigned int nr_ents; |
296 | /* TLB_FLUSH_MULTI, INVLPG_MULTI */ |
297 | #if __XEN_INTERFACE_VERSION__ >= 0x00030205 |
298 | XEN_GUEST_HANDLE(const_void) vcpumask; |
299 | #else |
300 | const void *vcpumask; |
301 | #endif |
302 | /* COPY_PAGE */ |
303 | xen_pfn_t src_mfn; |
304 | } arg2; |
305 | }; |
306 | typedef struct mmuext_op mmuext_op_t; |
307 | DEFINE_XEN_GUEST_HANDLE(mmuext_op_t); |
308 | #endif |
309 | |
310 | /* These are passed as 'flags' to update_va_mapping. They can be ORed. */ |
311 | /* When specifying UVMF_MULTI, also OR in a pointer to a CPU bitmap. */ |
312 | /* UVMF_LOCAL is merely UVMF_MULTI with a NULL bitmap pointer. */ |
313 | #define UVMF_NONE (0UL<<0) /* No flushing at all. */ |
314 | #define UVMF_TLB_FLUSH (1UL<<0) /* Flush entire TLB(s). */ |
315 | #define UVMF_INVLPG (2UL<<0) /* Flush only one entry. */ |
316 | #define UVMF_FLUSHTYPE_MASK (3UL<<0) |
317 | #define UVMF_MULTI (0UL<<2) /* Flush subset of TLBs. */ |
318 | #define UVMF_LOCAL (0UL<<2) /* Flush local TLB. */ |
319 | #define UVMF_ALL (1UL<<2) /* Flush all TLBs. */ |
320 | |
321 | /* |
322 | * Commands to HYPERVISOR_console_io(). |
323 | */ |
324 | #define CONSOLEIO_write 0 |
325 | #define CONSOLEIO_read 1 |
326 | |
327 | /* |
328 | * Commands to HYPERVISOR_vm_assist(). |
329 | */ |
330 | #define VMASST_CMD_enable 0 |
331 | #define VMASST_CMD_disable 1 |
332 | |
333 | /* x86/32 guests: simulate full 4GB segment limits. */ |
334 | #define VMASST_TYPE_4gb_segments 0 |
335 | |
336 | /* x86/32 guests: trap (vector 15) whenever above vmassist is used. */ |
337 | #define VMASST_TYPE_4gb_segments_notify 1 |
338 | |
339 | /* |
340 | * x86 guests: support writes to bottom-level PTEs. |
341 | * NB1. Page-directory entries cannot be written. |
342 | * NB2. Guest must continue to remove all writable mappings of PTEs. |
343 | */ |
344 | #define VMASST_TYPE_writable_pagetables 2 |
345 | |
346 | /* x86/PAE guests: support PDPTs above 4GB. */ |
347 | #define VMASST_TYPE_pae_extended_cr3 3 |
348 | |
349 | #define MAX_VMASST_TYPE 3 |
350 | |
351 | #ifndef __ASSEMBLY__ |
352 | |
353 | typedef uint16_t domid_t; |
354 | |
355 | /* Domain ids >= DOMID_FIRST_RESERVED cannot be used for ordinary domains. */ |
356 | #define DOMID_FIRST_RESERVED (0x7FF0U) |
357 | |
358 | /* DOMID_SELF is used in certain contexts to refer to oneself. */ |
359 | #define DOMID_SELF (0x7FF0U) |
360 | |
361 | /* |
362 | * DOMID_IO is used to restrict page-table updates to mapping I/O memory. |
363 | * Although no Foreign Domain need be specified to map I/O pages, DOMID_IO |
364 | * is useful to ensure that no mappings to the OS's own heap are accidentally |
365 | * installed. (e.g., in Linux this could cause havoc as reference counts |
366 | * aren't adjusted on the I/O-mapping code path). |
367 | * This only makes sense in MMUEXT_SET_FOREIGNDOM, but in that context can |
368 | * be specified by any calling domain. |
369 | */ |
370 | #define DOMID_IO (0x7FF1U) |
371 | |
372 | /* |
373 | * DOMID_XEN is used to allow privileged domains to map restricted parts of |
374 | * Xen's heap space (e.g., the machine_to_phys table). |
375 | * This only makes sense in MMUEXT_SET_FOREIGNDOM, and is only permitted if |
376 | * the caller is privileged. |
377 | */ |
378 | #define DOMID_XEN (0x7FF2U) |
379 | |
380 | /* |
381 | * DOMID_COW is used as the owner of sharable pages */ |
382 | #define DOMID_COW (0x7FF3U) |
383 | |
384 | /* DOMID_INVALID is used to identify pages with unknown owner. */ |
385 | #define DOMID_INVALID (0x7FF4U) |
386 | |
387 | /* Idle domain. */ |
388 | #define DOMID_IDLE (0x7FFFU) |
389 | |
390 | /* |
391 | * Send an array of these to HYPERVISOR_mmu_update(). |
392 | * NB. The fields are natural pointer/address size for this architecture. |
393 | */ |
394 | struct mmu_update { |
395 | uint64_t ptr; /* Machine address of PTE. */ |
396 | uint64_t val; /* New contents of PTE. */ |
397 | }; |
398 | typedef struct mmu_update mmu_update_t; |
399 | DEFINE_XEN_GUEST_HANDLE(mmu_update_t); |
400 | |
401 | /* |
402 | * Send an array of these to HYPERVISOR_multicall(). |
403 | * NB. The fields are natural register size for this architecture. |
404 | */ |
405 | struct multicall_entry { |
406 | unsigned long op, result; |
407 | unsigned long args[6]; |
408 | }; |
409 | typedef struct multicall_entry multicall_entry_t; |
410 | DEFINE_XEN_GUEST_HANDLE(multicall_entry_t); |
411 | |
412 | /* |
413 | * Event channel endpoints per domain: |
414 | * 1024 if a long is 32 bits; 4096 if a long is 64 bits. |
415 | */ |
416 | #define NR_EVENT_CHANNELS (sizeof(unsigned long) * sizeof(unsigned long) * 64) |
417 | |
418 | struct vcpu_time_info { |
419 | /* |
420 | * Updates to the following values are preceded and followed by an |
421 | * increment of 'version'. The guest can therefore detect updates by |
422 | * looking for changes to 'version'. If the least-significant bit of |
423 | * the version number is set then an update is in progress and the guest |
424 | * must wait to read a consistent set of values. |
425 | * The correct way to interact with the version number is similar to |
426 | * Linux's seqlock: see the implementations of read_seqbegin/read_seqretry. |
427 | */ |
428 | uint32_t version; |
429 | uint32_t pad0; |
430 | uint64_t tsc_timestamp; /* TSC at last update of time vals. */ |
431 | uint64_t system_time; /* Time, in nanosecs, since boot. */ |
432 | /* |
433 | * Current system time: |
434 | * system_time + |
435 | * ((((tsc - tsc_timestamp) << tsc_shift) * tsc_to_system_mul) >> 32) |
436 | * CPU frequency (Hz): |
437 | * ((10^9 << 32) / tsc_to_system_mul) >> tsc_shift |
438 | */ |
439 | uint32_t tsc_to_system_mul; |
440 | int8_t tsc_shift; |
441 | int8_t pad1[3]; |
442 | }; /* 32 bytes */ |
443 | typedef struct vcpu_time_info vcpu_time_info_t; |
444 | |
445 | struct vcpu_info { |
446 | /* |
447 | * 'evtchn_upcall_pending' is written non-zero by Xen to indicate |
448 | * a pending notification for a particular VCPU. It is then cleared |
449 | * by the guest OS /before/ checking for pending work, thus avoiding |
450 | * a set-and-check race. Note that the mask is only accessed by Xen |
451 | * on the CPU that is currently hosting the VCPU. This means that the |
452 | * pending and mask flags can be updated by the guest without special |
453 | * synchronisation (i.e., no need for the x86 LOCK prefix). |
454 | * This may seem suboptimal because if the pending flag is set by |
455 | * a different CPU then an IPI may be scheduled even when the mask |
456 | * is set. However, note: |
457 | * 1. The task of 'interrupt holdoff' is covered by the per-event- |
458 | * channel mask bits. A 'noisy' event that is continually being |
459 | * triggered can be masked at source at this very precise |
460 | * granularity. |
461 | * 2. The main purpose of the per-VCPU mask is therefore to restrict |
462 | * reentrant execution: whether for concurrency control, or to |
463 | * prevent unbounded stack usage. Whatever the purpose, we expect |
464 | * that the mask will be asserted only for short periods at a time, |
465 | * and so the likelihood of a 'spurious' IPI is suitably small. |
466 | * The mask is read before making an event upcall to the guest: a |
467 | * non-zero mask therefore guarantees that the VCPU will not receive |
468 | * an upcall activation. The mask is cleared when the VCPU requests |
469 | * to block: this avoids wakeup-waiting races. |
470 | */ |
471 | uint8_t evtchn_upcall_pending; |
472 | uint8_t evtchn_upcall_mask; |
473 | unsigned long evtchn_pending_sel; |
474 | struct arch_vcpu_info arch; |
475 | struct vcpu_time_info time; |
476 | }; /* 64 bytes (x86) */ |
477 | #ifndef __XEN__ |
478 | typedef struct vcpu_info vcpu_info_t; |
479 | #endif |
480 | |
481 | /* |
482 | * Xen/kernel shared data -- pointer provided in start_info. |
483 | * |
484 | * This structure is defined to be both smaller than a page, and the |
485 | * only data on the shared page, but may vary in actual size even within |
486 | * compatible Xen versions; guests should not rely on the size |
487 | * of this structure remaining constant. |
488 | */ |
489 | struct shared_info { |
490 | struct vcpu_info vcpu_info[XEN_LEGACY_MAX_VCPUS]; |
491 | |
492 | /* |
493 | * A domain can create "event channels" on which it can send and receive |
494 | * asynchronous event notifications. There are three classes of event that |
495 | * are delivered by this mechanism: |
496 | * 1. Bi-directional inter- and intra-domain connections. Domains must |
497 | * arrange out-of-band to set up a connection (usually by allocating |
498 | * an unbound 'listener' port and avertising that via a storage service |
499 | * such as xenstore). |
500 | * 2. Physical interrupts. A domain with suitable hardware-access |
501 | * privileges can bind an event-channel port to a physical interrupt |
502 | * source. |
503 | * 3. Virtual interrupts ('events'). A domain can bind an event-channel |
504 | * port to a virtual interrupt source, such as the virtual-timer |
505 | * device or the emergency console. |
506 | * |
507 | * Event channels are addressed by a "port index". Each channel is |
508 | * associated with two bits of information: |
509 | * 1. PENDING -- notifies the domain that there is a pending notification |
510 | * to be processed. This bit is cleared by the guest. |
511 | * 2. MASK -- if this bit is clear then a 0->1 transition of PENDING |
512 | * will cause an asynchronous upcall to be scheduled. This bit is only |
513 | * updated by the guest. It is read-only within Xen. If a channel |
514 | * becomes pending while the channel is masked then the 'edge' is lost |
515 | * (i.e., when the channel is unmasked, the guest must manually handle |
516 | * pending notifications as no upcall will be scheduled by Xen). |
517 | * |
518 | * To expedite scanning of pending notifications, any 0->1 pending |
519 | * transition on an unmasked channel causes a corresponding bit in a |
520 | * per-vcpu selector word to be set. Each bit in the selector covers a |
521 | * 'C long' in the PENDING bitfield array. |
522 | */ |
523 | unsigned long evtchn_pending[sizeof(unsigned long) * 8]; |
524 | unsigned long evtchn_mask[sizeof(unsigned long) * 8]; |
525 | |
526 | /* |
527 | * Wallclock time: updated only by control software. Guests should base |
528 | * their gettimeofday() syscall on this wallclock-base value. |
529 | */ |
530 | uint32_t wc_version; /* Version counter: see vcpu_time_info_t. */ |
531 | uint32_t wc_sec; /* Secs 00:00:00 UTC, Jan 1, 1970. */ |
532 | uint32_t wc_nsec; /* Nsecs 00:00:00 UTC, Jan 1, 1970. */ |
533 | |
534 | struct arch_shared_info arch; |
535 | |
536 | }; |
537 | #ifndef __XEN__ |
538 | typedef struct shared_info shared_info_t; |
539 | #endif |
540 | |
541 | /* |
542 | * Start-of-day memory layout: |
543 | * 1. The domain is started within contiguous virtual-memory region. |
544 | * 2. The contiguous region ends on an aligned 4MB boundary. |
545 | * 3. This the order of bootstrap elements in the initial virtual region: |
546 | * a. relocated kernel image |
547 | * b. initial ram disk [mod_start, mod_len] |
548 | * c. list of allocated page frames [mfn_list, nr_pages] |
549 | * (unless relocated due to XEN_ELFNOTE_INIT_P2M) |
550 | * d. start_info_t structure [register ESI (x86)] |
551 | * e. bootstrap page tables [pt_base, CR3 (x86)] |
552 | * f. bootstrap stack [register ESP (x86)] |
553 | * 4. Bootstrap elements are packed together, but each is 4kB-aligned. |
554 | * 5. The initial ram disk may be omitted. |
555 | * 6. The list of page frames forms a contiguous 'pseudo-physical' memory |
556 | * layout for the domain. In particular, the bootstrap virtual-memory |
557 | * region is a 1:1 mapping to the first section of the pseudo-physical map. |
558 | * 7. All bootstrap elements are mapped read-writable for the guest OS. The |
559 | * only exception is the bootstrap page table, which is mapped read-only. |
560 | * 8. There is guaranteed to be at least 512kB padding after the final |
561 | * bootstrap element. If necessary, the bootstrap virtual region is |
562 | * extended by an extra 4MB to ensure this. |
563 | */ |
564 | |
565 | #define MAX_GUEST_CMDLINE 1024 |
566 | struct start_info { |
567 | /* THE FOLLOWING ARE FILLED IN BOTH ON INITIAL BOOT AND ON RESUME. */ |
568 | char magic[32]; /* "xen-<version>-<platform>". */ |
569 | unsigned long nr_pages; /* Total pages allocated to this domain. */ |
570 | unsigned long shared_info; /* MACHINE address of shared info struct. */ |
571 | uint32_t flags; /* SIF_xxx flags. */ |
572 | xen_pfn_t store_mfn; /* MACHINE page number of shared page. */ |
573 | uint32_t store_evtchn; /* Event channel for store communication. */ |
574 | union { |
575 | struct { |
576 | xen_pfn_t mfn; /* MACHINE page number of console page. */ |
577 | uint32_t evtchn; /* Event channel for console page. */ |
578 | } domU; |
579 | struct { |
580 | uint32_t info_off; /* Offset of console_info struct. */ |
581 | uint32_t info_size; /* Size of console_info struct from start.*/ |
582 | } dom0; |
583 | } console; |
584 | /* THE FOLLOWING ARE ONLY FILLED IN ON INITIAL BOOT (NOT RESUME). */ |
585 | unsigned long pt_base; /* VIRTUAL address of page directory. */ |
586 | unsigned long nr_pt_frames; /* Number of bootstrap p.t. frames. */ |
587 | unsigned long mfn_list; /* VIRTUAL address of page-frame list. */ |
588 | unsigned long mod_start; /* VIRTUAL address of pre-loaded module */ |
589 | /* (PFN of pre-loaded module if */ |
590 | /* SIF_MOD_START_PFN set in flags). */ |
591 | unsigned long mod_len; /* Size (bytes) of pre-loaded module. */ |
592 | int8_t cmd_line[MAX_GUEST_CMDLINE]; |
593 | /* The pfn range here covers both page table and p->m table frames. */ |
594 | unsigned long first_p2m_pfn;/* 1st pfn forming initial P->M table. */ |
595 | unsigned long nr_p2m_frames;/* # of pfns forming initial P->M table. */ |
596 | }; |
597 | typedef struct start_info start_info_t; |
598 | |
599 | /* New console union for dom0 introduced in 0x00030203. */ |
600 | #if __XEN_INTERFACE_VERSION__ < 0x00030203 |
601 | #define console_mfn console.domU.mfn |
602 | #define console_evtchn console.domU.evtchn |
603 | #endif |
604 | |
605 | /* These flags are passed in the 'flags' field of start_info_t. */ |
606 | #define SIF_PRIVILEGED (1<<0) /* Is the domain privileged? */ |
607 | #define SIF_INITDOMAIN (1<<1) /* Is this the initial control domain? */ |
608 | #define SIF_MULTIBOOT_MOD (1<<2) /* Is mod_start a multiboot module? */ |
609 | #define SIF_MOD_START_PFN (1<<3) /* Is mod_start a PFN? */ |
610 | #define SIF_PM_MASK (0xFF<<8) /* reserve 1 byte for xen-pm options */ |
611 | |
612 | /* |
613 | * A multiboot module is a package containing modules very similar to a |
614 | * multiboot module array. The only differences are: |
615 | * - the array of module descriptors is by convention simply at the beginning |
616 | * of the multiboot module, |
617 | * - addresses in the module descriptors are based on the beginning of the |
618 | * multiboot module, |
619 | * - the number of modules is determined by a termination descriptor that has |
620 | * mod_start == 0. |
621 | * |
622 | * This permits to both build it statically and reference it in a configuration |
623 | * file, and let the PV guest easily rebase the addresses to virtual addresses |
624 | * and at the same time count the number of modules. |
625 | */ |
626 | struct xen_multiboot_mod_list |
627 | { |
628 | /* Address of first byte of the module */ |
629 | uint32_t mod_start; |
630 | /* Address of last byte of the module (inclusive) */ |
631 | uint32_t mod_end; |
632 | /* Address of zero-terminated command line */ |
633 | uint32_t cmdline; |
634 | /* Unused, must be zero */ |
635 | uint32_t pad; |
636 | }; |
637 | |
638 | typedef struct dom0_vga_console_info { |
639 | uint8_t video_type; /* DOM0_VGA_CONSOLE_??? */ |
640 | #define XEN_VGATYPE_TEXT_MODE_3 0x03 |
641 | #define XEN_VGATYPE_VESA_LFB 0x23 |
642 | |
643 | union { |
644 | struct { |
645 | /* Font height, in pixels. */ |
646 | uint16_t font_height; |
647 | /* Cursor location (column, row). */ |
648 | uint16_t cursor_x, cursor_y; |
649 | /* Number of rows and columns (dimensions in characters). */ |
650 | uint16_t rows, columns; |
651 | } text_mode_3; |
652 | |
653 | struct { |
654 | /* Width and height, in pixels. */ |
655 | uint16_t width, height; |
656 | /* Bytes per scan line. */ |
657 | uint16_t bytes_per_line; |
658 | /* Bits per pixel. */ |
659 | uint16_t bits_per_pixel; |
660 | /* LFB physical address, and size (in units of 64kB). */ |
661 | uint32_t lfb_base; |
662 | uint32_t lfb_size; |
663 | /* RGB mask offsets and sizes, as defined by VBE 1.2+ */ |
664 | uint8_t red_pos, red_size; |
665 | uint8_t green_pos, green_size; |
666 | uint8_t blue_pos, blue_size; |
667 | uint8_t rsvd_pos, rsvd_size; |
668 | #if __XEN_INTERFACE_VERSION__ >= 0x00030206 |
669 | /* VESA capabilities (offset 0xa, VESA command 0x4f00). */ |
670 | uint32_t gbl_caps; |
671 | /* Mode attributes (offset 0x0, VESA command 0x4f01). */ |
672 | uint16_t mode_attrs; |
673 | #endif |
674 | } vesa_lfb; |
675 | } u; |
676 | } dom0_vga_console_info_t; |
677 | #define xen_vga_console_info dom0_vga_console_info |
678 | #define xen_vga_console_info_t dom0_vga_console_info_t |
679 | |
680 | typedef uint8_t xen_domain_handle_t[16]; |
681 | |
682 | /* Turn a plain number into a C unsigned long constant. */ |
683 | #define __mk_unsigned_long(x) x ## UL |
684 | #define mk_unsigned_long(x) __mk_unsigned_long(x) |
685 | |
686 | __DEFINE_XEN_GUEST_HANDLE(uint8, uint8_t); |
687 | __DEFINE_XEN_GUEST_HANDLE(uint16, uint16_t); |
688 | __DEFINE_XEN_GUEST_HANDLE(uint32, uint32_t); |
689 | __DEFINE_XEN_GUEST_HANDLE(uint64, uint64_t); |
690 | |
691 | #else /* __ASSEMBLY__ */ |
692 | |
693 | /* In assembly code we cannot use C numeric constant suffixes. */ |
694 | #define mk_unsigned_long(x) x |
695 | |
696 | #endif /* !__ASSEMBLY__ */ |
697 | |
698 | /* Default definitions for macros used by domctl/sysctl. */ |
699 | #if defined(__XEN__) || defined(__XEN_TOOLS__) |
700 | |
701 | #ifndef uint64_aligned_t |
702 | #define uint64_aligned_t uint64_t |
703 | #endif |
704 | #ifndef XEN_GUEST_HANDLE_64 |
705 | #define XEN_GUEST_HANDLE_64(name) XEN_GUEST_HANDLE(name) |
706 | #endif |
707 | |
708 | #ifndef __ASSEMBLY__ |
709 | struct xenctl_cpumap { |
710 | XEN_GUEST_HANDLE_64(uint8) bitmap; |
711 | uint32_t nr_cpus; |
712 | }; |
713 | #endif |
714 | |
715 | #endif /* defined(__XEN__) || defined(__XEN_TOOLS__) */ |
716 | |
717 | #endif /* __XEN_PUBLIC_XEN_H__ */ |
718 | |
719 | /* |
720 | * Local variables: |
721 | * mode: C |
722 | * c-set-style: "BSD" |
723 | * c-basic-offset: 4 |
724 | * tab-width: 4 |
725 | * indent-tabs-mode: nil |
726 | * End: |
727 | */ |
728 | |