Browse Source

[xen] Import selected public headers

Import selected headers from the xen/include/public directory of the
Xen repository at git://xenbits.xen.org/xen.git

The script ./include/xen/import.pl can be used to automatically import
any required headers and their dependencies (in a similar fashion to
./include/ipxe/efi/import.pl).  Trailing whitespace is stripped and an
appropriate FILE_LICENCE declaration is added to each header file.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 10 years ago
parent
commit
ec94a8798f

+ 422
- 0
src/include/xen/arch-arm.h View File

@@ -0,0 +1,422 @@
1
+/******************************************************************************
2
+ * arch-arm.h
3
+ *
4
+ * Guest OS interface to ARM Xen.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to
8
+ * deal in the Software without restriction, including without limitation the
9
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10
+ * sell copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in
14
+ * all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22
+ * DEALINGS IN THE SOFTWARE.
23
+ *
24
+ * Copyright 2011 (C) Citrix Systems
25
+ */
26
+
27
+#ifndef __XEN_PUBLIC_ARCH_ARM_H__
28
+#define __XEN_PUBLIC_ARCH_ARM_H__
29
+
30
+FILE_LICENCE ( MIT );
31
+
32
+/*
33
+ * `incontents 50 arm_abi Hypercall Calling Convention
34
+ *
35
+ * A hypercall is issued using the ARM HVC instruction.
36
+ *
37
+ * A hypercall can take up to 5 arguments. These are passed in
38
+ * registers, the first argument in x0/r0 (for arm64/arm32 guests
39
+ * respectively irrespective of whether the underlying hypervisor is
40
+ * 32- or 64-bit), the second argument in x1/r1, the third in x2/r2,
41
+ * the forth in x3/r3 and the fifth in x4/r4.
42
+ *
43
+ * The hypercall number is passed in r12 (arm) or x16 (arm64). In both
44
+ * cases the relevant ARM procedure calling convention specifies this
45
+ * is an inter-procedure-call scratch register (e.g. for use in linker
46
+ * stubs). This use does not conflict with use during a hypercall.
47
+ *
48
+ * The HVC ISS must contain a Xen specific TAG: XEN_HYPERCALL_TAG.
49
+ *
50
+ * The return value is in x0/r0.
51
+ *
52
+ * The hypercall will clobber x16/r12 and the argument registers used
53
+ * by that hypercall (except r0 which is the return value) i.e. in
54
+ * addition to x16/r12 a 2 argument hypercall will clobber x1/r1 and a
55
+ * 4 argument hypercall will clobber x1/r1, x2/r2 and x3/r3.
56
+ *
57
+ * Parameter structs passed to hypercalls are laid out according to
58
+ * the Procedure Call Standard for the ARM Architecture (AAPCS, AKA
59
+ * EABI) and Procedure Call Standard for the ARM 64-bit Architecture
60
+ * (AAPCS64). Where there is a conflict the 64-bit standard should be
61
+ * used regardless of guest type. Structures which are passed as
62
+ * hypercall arguments are always little endian.
63
+ *
64
+ * All memory which is shared with other entities in the system
65
+ * (including the hypervisor and other guests) must reside in memory
66
+ * which is mapped as Normal Inner-cacheable. This applies to:
67
+ *  - hypercall arguments passed via a pointer to guest memory.
68
+ *  - memory shared via the grant table mechanism (including PV I/O
69
+ *    rings etc).
70
+ *  - memory shared with the hypervisor (struct shared_info, struct
71
+ *    vcpu_info, the grant table, etc).
72
+ *
73
+ * Any Inner cache allocation strategy (Write-Back, Write-Through etc)
74
+ * is acceptable. There is no restriction on the Outer-cacheability.
75
+ */
76
+
77
+/*
78
+ * `incontents 55 arm_hcall Supported Hypercalls
79
+ *
80
+ * Xen on ARM makes extensive use of hardware facilities and therefore
81
+ * only a subset of the potential hypercalls are required.
82
+ *
83
+ * Since ARM uses second stage paging any machine/physical addresses
84
+ * passed to hypercalls are Guest Physical Addresses (Intermediate
85
+ * Physical Addresses) unless otherwise noted.
86
+ *
87
+ * The following hypercalls (and sub operations) are supported on the
88
+ * ARM platform. Other hypercalls should be considered
89
+ * unavailable/unsupported.
90
+ *
91
+ *  HYPERVISOR_memory_op
92
+ *   All generic sub-operations.
93
+ *
94
+ *   In addition the following arch specific sub-ops:
95
+ *    * XENMEM_add_to_physmap
96
+ *    * XENMEM_add_to_physmap_batch
97
+ *
98
+ *  HYPERVISOR_domctl
99
+ *   All generic sub-operations, with the exception of:
100
+ *    * XEN_DOMCTL_iomem_permission (not yet implemented)
101
+ *    * XEN_DOMCTL_irq_permission (not yet implemented)
102
+ *
103
+ *  HYPERVISOR_sched_op
104
+ *   All generic sub-operations, with the exception of:
105
+ *    * SCHEDOP_block -- prefer wfi hardware instruction
106
+ *
107
+ *  HYPERVISOR_console_io
108
+ *   All generic sub-operations
109
+ *
110
+ *  HYPERVISOR_xen_version
111
+ *   All generic sub-operations
112
+ *
113
+ *  HYPERVISOR_event_channel_op
114
+ *   All generic sub-operations
115
+ *
116
+ *  HYPERVISOR_physdev_op
117
+ *   No sub-operations are currenty supported
118
+ *
119
+ *  HYPERVISOR_sysctl
120
+ *   All generic sub-operations, with the exception of:
121
+ *    * XEN_SYSCTL_page_offline_op
122
+ *    * XEN_SYSCTL_get_pmstat
123
+ *    * XEN_SYSCTL_pm_op
124
+ *
125
+ *  HYPERVISOR_hvm_op
126
+ *   Exactly these sub-operations are supported:
127
+ *    * HVMOP_set_param
128
+ *    * HVMOP_get_param
129
+ *
130
+ *  HYPERVISOR_grant_table_op
131
+ *   All generic sub-operations
132
+ *
133
+ *  HYPERVISOR_vcpu_op
134
+ *   Exactly these sub-operations are supported:
135
+ *    * VCPUOP_register_vcpu_info
136
+ *    * VCPUOP_register_runstate_memory_area
137
+ *
138
+ *
139
+ * Other notes on the ARM ABI:
140
+ *
141
+ * - struct start_info is not exported to ARM guests.
142
+ *
143
+ * - struct shared_info is mapped by ARM guests using the
144
+ *   HYPERVISOR_memory_op sub-op XENMEM_add_to_physmap, passing
145
+ *   XENMAPSPACE_shared_info as space parameter.
146
+ *
147
+ * - All the per-cpu struct vcpu_info are mapped by ARM guests using the
148
+ *   HYPERVISOR_vcpu_op sub-op VCPUOP_register_vcpu_info, including cpu0
149
+ *   struct vcpu_info.
150
+ *
151
+ * - The grant table is mapped using the HYPERVISOR_memory_op sub-op
152
+ *   XENMEM_add_to_physmap, passing XENMAPSPACE_grant_table as space
153
+ *   parameter. The memory range specified under the Xen compatible
154
+ *   hypervisor node on device tree can be used as target gpfn for the
155
+ *   mapping.
156
+ *
157
+ * - Xenstore is initialized by using the two hvm_params
158
+ *   HVM_PARAM_STORE_PFN and HVM_PARAM_STORE_EVTCHN. They can be read
159
+ *   with the HYPERVISOR_hvm_op sub-op HVMOP_get_param.
160
+ *
161
+ * - The paravirtualized console is initialized by using the two
162
+ *   hvm_params HVM_PARAM_CONSOLE_PFN and HVM_PARAM_CONSOLE_EVTCHN. They
163
+ *   can be read with the HYPERVISOR_hvm_op sub-op HVMOP_get_param.
164
+ *
165
+ * - Event channel notifications are delivered using the percpu GIC
166
+ *   interrupt specified under the Xen compatible hypervisor node on
167
+ *   device tree.
168
+ *
169
+ * - The device tree Xen compatible node is fully described under Linux
170
+ *   at Documentation/devicetree/bindings/arm/xen.txt.
171
+ */
172
+
173
+#define XEN_HYPERCALL_TAG   0XEA1
174
+
175
+#define uint64_aligned_t uint64_t __attribute__((aligned(8)))
176
+
177
+#ifndef __ASSEMBLY__
178
+#define ___DEFINE_XEN_GUEST_HANDLE(name, type)                  \
179
+    typedef union { type *p; unsigned long q; }                 \
180
+        __guest_handle_ ## name;                                \
181
+    typedef union { type *p; uint64_aligned_t q; }              \
182
+        __guest_handle_64_ ## name;
183
+
184
+/*
185
+ * XEN_GUEST_HANDLE represents a guest pointer, when passed as a field
186
+ * in a struct in memory. On ARM is always 8 bytes sizes and 8 bytes
187
+ * aligned.
188
+ * XEN_GUEST_HANDLE_PARAM represent a guest pointer, when passed as an
189
+ * hypercall argument. It is 4 bytes on aarch and 8 bytes on aarch64.
190
+ */
191
+#define __DEFINE_XEN_GUEST_HANDLE(name, type) \
192
+    ___DEFINE_XEN_GUEST_HANDLE(name, type);   \
193
+    ___DEFINE_XEN_GUEST_HANDLE(const_##name, const type)
194
+#define DEFINE_XEN_GUEST_HANDLE(name)   __DEFINE_XEN_GUEST_HANDLE(name, name)
195
+#define __XEN_GUEST_HANDLE(name)        __guest_handle_64_ ## name
196
+#define XEN_GUEST_HANDLE(name)          __XEN_GUEST_HANDLE(name)
197
+/* this is going to be changed on 64 bit */
198
+#define XEN_GUEST_HANDLE_PARAM(name)    __guest_handle_ ## name
199
+#define set_xen_guest_handle_raw(hnd, val)                  \
200
+    do {                                                    \
201
+        typeof(&(hnd)) _sxghr_tmp = &(hnd);                 \
202
+        _sxghr_tmp->q = 0;                                  \
203
+        _sxghr_tmp->p = val;                                \
204
+    } while ( 0 )
205
+#ifdef __XEN_TOOLS__
206
+#define get_xen_guest_handle(val, hnd)  do { val = (hnd).p; } while (0)
207
+#endif
208
+#define set_xen_guest_handle(hnd, val) set_xen_guest_handle_raw(hnd, val)
209
+
210
+#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
211
+/* Anonymous union includes both 32- and 64-bit names (e.g., r0/x0). */
212
+# define __DECL_REG(n64, n32) union {          \
213
+        uint64_t n64;                          \
214
+        uint32_t n32;                          \
215
+    }
216
+#else
217
+/* Non-gcc sources must always use the proper 64-bit name (e.g., x0). */
218
+#define __DECL_REG(n64, n32) uint64_t n64
219
+#endif
220
+
221
+struct vcpu_guest_core_regs
222
+{
223
+    /*         Aarch64       Aarch32 */
224
+    __DECL_REG(x0,           r0_usr);
225
+    __DECL_REG(x1,           r1_usr);
226
+    __DECL_REG(x2,           r2_usr);
227
+    __DECL_REG(x3,           r3_usr);
228
+    __DECL_REG(x4,           r4_usr);
229
+    __DECL_REG(x5,           r5_usr);
230
+    __DECL_REG(x6,           r6_usr);
231
+    __DECL_REG(x7,           r7_usr);
232
+    __DECL_REG(x8,           r8_usr);
233
+    __DECL_REG(x9,           r9_usr);
234
+    __DECL_REG(x10,          r10_usr);
235
+    __DECL_REG(x11,          r11_usr);
236
+    __DECL_REG(x12,          r12_usr);
237
+
238
+    __DECL_REG(x13,          sp_usr);
239
+    __DECL_REG(x14,          lr_usr);
240
+
241
+    __DECL_REG(x15,          __unused_sp_hyp);
242
+
243
+    __DECL_REG(x16,          lr_irq);
244
+    __DECL_REG(x17,          sp_irq);
245
+
246
+    __DECL_REG(x18,          lr_svc);
247
+    __DECL_REG(x19,          sp_svc);
248
+
249
+    __DECL_REG(x20,          lr_abt);
250
+    __DECL_REG(x21,          sp_abt);
251
+
252
+    __DECL_REG(x22,          lr_und);
253
+    __DECL_REG(x23,          sp_und);
254
+
255
+    __DECL_REG(x24,          r8_fiq);
256
+    __DECL_REG(x25,          r9_fiq);
257
+    __DECL_REG(x26,          r10_fiq);
258
+    __DECL_REG(x27,          r11_fiq);
259
+    __DECL_REG(x28,          r12_fiq);
260
+
261
+    __DECL_REG(x29,          sp_fiq);
262
+    __DECL_REG(x30,          lr_fiq);
263
+
264
+    /* Return address and mode */
265
+    __DECL_REG(pc64,         pc32);             /* ELR_EL2 */
266
+    uint32_t cpsr;                              /* SPSR_EL2 */
267
+
268
+    union {
269
+        uint32_t spsr_el1;       /* AArch64 */
270
+        uint32_t spsr_svc;       /* AArch32 */
271
+    };
272
+
273
+    /* AArch32 guests only */
274
+    uint32_t spsr_fiq, spsr_irq, spsr_und, spsr_abt;
275
+
276
+    /* AArch64 guests only */
277
+    uint64_t sp_el0;
278
+    uint64_t sp_el1, elr_el1;
279
+};
280
+typedef struct vcpu_guest_core_regs vcpu_guest_core_regs_t;
281
+DEFINE_XEN_GUEST_HANDLE(vcpu_guest_core_regs_t);
282
+
283
+#undef __DECL_REG
284
+
285
+typedef uint64_t xen_pfn_t;
286
+#define PRI_xen_pfn PRIx64
287
+
288
+/* Maximum number of virtual CPUs in legacy multi-processor guests. */
289
+/* Only one. All other VCPUS must use VCPUOP_register_vcpu_info */
290
+#define XEN_LEGACY_MAX_VCPUS 1
291
+
292
+typedef uint64_t xen_ulong_t;
293
+#define PRI_xen_ulong PRIx64
294
+
295
+#if defined(__XEN__) || defined(__XEN_TOOLS__)
296
+struct vcpu_guest_context {
297
+#define _VGCF_online                   0
298
+#define VGCF_online                    (1<<_VGCF_online)
299
+    uint32_t flags;                         /* VGCF_* */
300
+
301
+    struct vcpu_guest_core_regs user_regs;  /* Core CPU registers */
302
+
303
+    uint32_t sctlr;
304
+    uint64_t ttbcr, ttbr0, ttbr1;
305
+};
306
+typedef struct vcpu_guest_context vcpu_guest_context_t;
307
+DEFINE_XEN_GUEST_HANDLE(vcpu_guest_context_t);
308
+#endif
309
+
310
+struct arch_vcpu_info {
311
+};
312
+typedef struct arch_vcpu_info arch_vcpu_info_t;
313
+
314
+struct arch_shared_info {
315
+};
316
+typedef struct arch_shared_info arch_shared_info_t;
317
+typedef uint64_t xen_callback_t;
318
+
319
+#endif
320
+
321
+#if defined(__XEN__) || defined(__XEN_TOOLS__)
322
+
323
+/* PSR bits (CPSR, SPSR)*/
324
+
325
+#define PSR_THUMB       (1<<5)        /* Thumb Mode enable */
326
+#define PSR_FIQ_MASK    (1<<6)        /* Fast Interrupt mask */
327
+#define PSR_IRQ_MASK    (1<<7)        /* Interrupt mask */
328
+#define PSR_ABT_MASK    (1<<8)        /* Asynchronous Abort mask */
329
+#define PSR_BIG_ENDIAN  (1<<9)        /* arm32: Big Endian Mode */
330
+#define PSR_DBG_MASK    (1<<9)        /* arm64: Debug Exception mask */
331
+#define PSR_IT_MASK     (0x0600fc00)  /* Thumb If-Then Mask */
332
+#define PSR_JAZELLE     (1<<24)       /* Jazelle Mode */
333
+
334
+/* 32 bit modes */
335
+#define PSR_MODE_USR 0x10
336
+#define PSR_MODE_FIQ 0x11
337
+#define PSR_MODE_IRQ 0x12
338
+#define PSR_MODE_SVC 0x13
339
+#define PSR_MODE_MON 0x16
340
+#define PSR_MODE_ABT 0x17
341
+#define PSR_MODE_HYP 0x1a
342
+#define PSR_MODE_UND 0x1b
343
+#define PSR_MODE_SYS 0x1f
344
+
345
+/* 64 bit modes */
346
+#define PSR_MODE_BIT  0x10 /* Set iff AArch32 */
347
+#define PSR_MODE_EL3h 0x0d
348
+#define PSR_MODE_EL3t 0x0c
349
+#define PSR_MODE_EL2h 0x09
350
+#define PSR_MODE_EL2t 0x08
351
+#define PSR_MODE_EL1h 0x05
352
+#define PSR_MODE_EL1t 0x04
353
+#define PSR_MODE_EL0t 0x00
354
+
355
+#define PSR_GUEST32_INIT  (PSR_ABT_MASK|PSR_FIQ_MASK|PSR_IRQ_MASK|PSR_MODE_SVC)
356
+#define PSR_GUEST64_INIT (PSR_ABT_MASK|PSR_FIQ_MASK|PSR_IRQ_MASK|PSR_MODE_EL1h)
357
+
358
+#define SCTLR_GUEST_INIT    0x00c50078
359
+
360
+/*
361
+ * Virtual machine platform (memory layout, interrupts)
362
+ *
363
+ * These are defined for consistency between the tools and the
364
+ * hypervisor. Guests must not rely on these hardcoded values but
365
+ * should instead use the FDT.
366
+ */
367
+
368
+/* Physical Address Space */
369
+#define GUEST_GICD_BASE   0x03001000ULL
370
+#define GUEST_GICD_SIZE   0x00001000ULL
371
+#define GUEST_GICC_BASE   0x03002000ULL
372
+#define GUEST_GICC_SIZE   0x00000100ULL
373
+
374
+/* 16MB == 4096 pages reserved for guest to use as a region to map its
375
+ * grant table in.
376
+ */
377
+#define GUEST_GNTTAB_BASE 0x38000000ULL
378
+#define GUEST_GNTTAB_SIZE 0x01000000ULL
379
+
380
+#define GUEST_MAGIC_BASE  0x39000000ULL
381
+#define GUEST_MAGIC_SIZE  0x01000000ULL
382
+
383
+#define GUEST_RAM_BANKS   2
384
+
385
+#define GUEST_RAM0_BASE   0x40000000ULL /* 3GB of low RAM @ 1GB */
386
+#define GUEST_RAM0_SIZE   0xc0000000ULL
387
+
388
+#define GUEST_RAM1_BASE   0x0200000000ULL /* 1016GB of RAM @ 8GB */
389
+#define GUEST_RAM1_SIZE   0xfe00000000ULL
390
+
391
+#define GUEST_RAM_BASE    GUEST_RAM0_BASE /* Lowest RAM address */
392
+/* Largest amount of actual RAM, not including holes */
393
+#define GUEST_RAM_MAX     (GUEST_RAM0_SIZE + GUEST_RAM1_SIZE)
394
+/* Suitable for e.g. const uint64_t ramfoo[] = GUEST_RAM_BANK_FOOS; */
395
+#define GUEST_RAM_BANK_BASES   { GUEST_RAM0_BASE, GUEST_RAM1_BASE }
396
+#define GUEST_RAM_BANK_SIZES   { GUEST_RAM0_SIZE, GUEST_RAM1_SIZE }
397
+
398
+/* Interrupts */
399
+#define GUEST_TIMER_VIRT_PPI    27
400
+#define GUEST_TIMER_PHYS_S_PPI  29
401
+#define GUEST_TIMER_PHYS_NS_PPI 30
402
+#define GUEST_EVTCHN_PPI        31
403
+
404
+/* PSCI functions */
405
+#define PSCI_cpu_suspend 0
406
+#define PSCI_cpu_off     1
407
+#define PSCI_cpu_on      2
408
+#define PSCI_migrate     3
409
+
410
+#endif
411
+
412
+#endif /*  __XEN_PUBLIC_ARCH_ARM_H__ */
413
+
414
+/*
415
+ * Local variables:
416
+ * mode: C
417
+ * c-file-style: "BSD"
418
+ * c-basic-offset: 4
419
+ * tab-width: 4
420
+ * indent-tabs-mode: nil
421
+ * End:
422
+ */

+ 173
- 0
src/include/xen/arch-x86/xen-x86_32.h View File

@@ -0,0 +1,173 @@
1
+/******************************************************************************
2
+ * xen-x86_32.h
3
+ *
4
+ * Guest OS interface to x86 32-bit Xen.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to
8
+ * deal in the Software without restriction, including without limitation the
9
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10
+ * sell copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in
14
+ * all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22
+ * DEALINGS IN THE SOFTWARE.
23
+ *
24
+ * Copyright (c) 2004-2007, K A Fraser
25
+ */
26
+
27
+#ifndef __XEN_PUBLIC_ARCH_X86_XEN_X86_32_H__
28
+#define __XEN_PUBLIC_ARCH_X86_XEN_X86_32_H__
29
+
30
+FILE_LICENCE ( MIT );
31
+
32
+/*
33
+ * Hypercall interface:
34
+ *  Input:  %ebx, %ecx, %edx, %esi, %edi, %ebp (arguments 1-6)
35
+ *  Output: %eax
36
+ * Access is via hypercall page (set up by guest loader or via a Xen MSR):
37
+ *  call hypercall_page + hypercall-number * 32
38
+ * Clobbered: Argument registers (e.g., 2-arg hypercall clobbers %ebx,%ecx)
39
+ */
40
+
41
+/*
42
+ * These flat segments are in the Xen-private section of every GDT. Since these
43
+ * are also present in the initial GDT, many OSes will be able to avoid
44
+ * installing their own GDT.
45
+ */
46
+#define FLAT_RING1_CS 0xe019    /* GDT index 259 */
47
+#define FLAT_RING1_DS 0xe021    /* GDT index 260 */
48
+#define FLAT_RING1_SS 0xe021    /* GDT index 260 */
49
+#define FLAT_RING3_CS 0xe02b    /* GDT index 261 */
50
+#define FLAT_RING3_DS 0xe033    /* GDT index 262 */
51
+#define FLAT_RING3_SS 0xe033    /* GDT index 262 */
52
+
53
+#define FLAT_KERNEL_CS FLAT_RING1_CS
54
+#define FLAT_KERNEL_DS FLAT_RING1_DS
55
+#define FLAT_KERNEL_SS FLAT_RING1_SS
56
+#define FLAT_USER_CS    FLAT_RING3_CS
57
+#define FLAT_USER_DS    FLAT_RING3_DS
58
+#define FLAT_USER_SS    FLAT_RING3_SS
59
+
60
+#define __HYPERVISOR_VIRT_START_PAE    0xF5800000
61
+#define __MACH2PHYS_VIRT_START_PAE     0xF5800000
62
+#define __MACH2PHYS_VIRT_END_PAE       0xF6800000
63
+#define HYPERVISOR_VIRT_START_PAE      \
64
+    mk_unsigned_long(__HYPERVISOR_VIRT_START_PAE)
65
+#define MACH2PHYS_VIRT_START_PAE       \
66
+    mk_unsigned_long(__MACH2PHYS_VIRT_START_PAE)
67
+#define MACH2PHYS_VIRT_END_PAE         \
68
+    mk_unsigned_long(__MACH2PHYS_VIRT_END_PAE)
69
+
70
+/* Non-PAE bounds are obsolete. */
71
+#define __HYPERVISOR_VIRT_START_NONPAE 0xFC000000
72
+#define __MACH2PHYS_VIRT_START_NONPAE  0xFC000000
73
+#define __MACH2PHYS_VIRT_END_NONPAE    0xFC400000
74
+#define HYPERVISOR_VIRT_START_NONPAE   \
75
+    mk_unsigned_long(__HYPERVISOR_VIRT_START_NONPAE)
76
+#define MACH2PHYS_VIRT_START_NONPAE    \
77
+    mk_unsigned_long(__MACH2PHYS_VIRT_START_NONPAE)
78
+#define MACH2PHYS_VIRT_END_NONPAE      \
79
+    mk_unsigned_long(__MACH2PHYS_VIRT_END_NONPAE)
80
+
81
+#define __HYPERVISOR_VIRT_START __HYPERVISOR_VIRT_START_PAE
82
+#define __MACH2PHYS_VIRT_START  __MACH2PHYS_VIRT_START_PAE
83
+#define __MACH2PHYS_VIRT_END    __MACH2PHYS_VIRT_END_PAE
84
+
85
+#ifndef HYPERVISOR_VIRT_START
86
+#define HYPERVISOR_VIRT_START mk_unsigned_long(__HYPERVISOR_VIRT_START)
87
+#endif
88
+
89
+#define MACH2PHYS_VIRT_START  mk_unsigned_long(__MACH2PHYS_VIRT_START)
90
+#define MACH2PHYS_VIRT_END    mk_unsigned_long(__MACH2PHYS_VIRT_END)
91
+#define MACH2PHYS_NR_ENTRIES  ((MACH2PHYS_VIRT_END-MACH2PHYS_VIRT_START)>>2)
92
+#ifndef machine_to_phys_mapping
93
+#define machine_to_phys_mapping ((unsigned long *)MACH2PHYS_VIRT_START)
94
+#endif
95
+
96
+/* 32-/64-bit invariability for control interfaces (domctl/sysctl). */
97
+#if defined(__XEN__) || defined(__XEN_TOOLS__)
98
+#undef ___DEFINE_XEN_GUEST_HANDLE
99
+#define ___DEFINE_XEN_GUEST_HANDLE(name, type)                  \
100
+    typedef struct { type *p; }                                 \
101
+        __guest_handle_ ## name;                                \
102
+    typedef struct { union { type *p; uint64_aligned_t q; }; }  \
103
+        __guest_handle_64_ ## name
104
+#undef set_xen_guest_handle_raw
105
+#define set_xen_guest_handle_raw(hnd, val)                  \
106
+    do { if ( sizeof(hnd) == 8 ) *(uint64_t *)&(hnd) = 0;   \
107
+         (hnd).p = val;                                     \
108
+    } while ( 0 )
109
+#define uint64_aligned_t uint64_t __attribute__((aligned(8)))
110
+#define __XEN_GUEST_HANDLE_64(name) __guest_handle_64_ ## name
111
+#define XEN_GUEST_HANDLE_64(name) __XEN_GUEST_HANDLE_64(name)
112
+#endif
113
+
114
+#ifndef __ASSEMBLY__
115
+
116
+struct cpu_user_regs {
117
+    uint32_t ebx;
118
+    uint32_t ecx;
119
+    uint32_t edx;
120
+    uint32_t esi;
121
+    uint32_t edi;
122
+    uint32_t ebp;
123
+    uint32_t eax;
124
+    uint16_t error_code;    /* private */
125
+    uint16_t entry_vector;  /* private */
126
+    uint32_t eip;
127
+    uint16_t cs;
128
+    uint8_t  saved_upcall_mask;
129
+    uint8_t  _pad0;
130
+    uint32_t eflags;        /* eflags.IF == !saved_upcall_mask */
131
+    uint32_t esp;
132
+    uint16_t ss, _pad1;
133
+    uint16_t es, _pad2;
134
+    uint16_t ds, _pad3;
135
+    uint16_t fs, _pad4;
136
+    uint16_t gs, _pad5;
137
+};
138
+typedef struct cpu_user_regs cpu_user_regs_t;
139
+DEFINE_XEN_GUEST_HANDLE(cpu_user_regs_t);
140
+
141
+/*
142
+ * Page-directory addresses above 4GB do not fit into architectural %cr3.
143
+ * When accessing %cr3, or equivalent field in vcpu_guest_context, guests
144
+ * must use the following accessor macros to pack/unpack valid MFNs.
145
+ */
146
+#define xen_pfn_to_cr3(pfn) (((unsigned)(pfn) << 12) | ((unsigned)(pfn) >> 20))
147
+#define xen_cr3_to_pfn(cr3) (((unsigned)(cr3) >> 12) | ((unsigned)(cr3) << 20))
148
+
149
+struct arch_vcpu_info {
150
+    unsigned long cr2;
151
+    unsigned long pad[5]; /* sizeof(vcpu_info_t) == 64 */
152
+};
153
+typedef struct arch_vcpu_info arch_vcpu_info_t;
154
+
155
+struct xen_callback {
156
+    unsigned long cs;
157
+    unsigned long eip;
158
+};
159
+typedef struct xen_callback xen_callback_t;
160
+
161
+#endif /* !__ASSEMBLY__ */
162
+
163
+#endif /* __XEN_PUBLIC_ARCH_X86_XEN_X86_32_H__ */
164
+
165
+/*
166
+ * Local variables:
167
+ * mode: C
168
+ * c-file-style: "BSD"
169
+ * c-basic-offset: 4
170
+ * tab-width: 4
171
+ * indent-tabs-mode: nil
172
+ * End:
173
+ */

+ 204
- 0
src/include/xen/arch-x86/xen-x86_64.h View File

@@ -0,0 +1,204 @@
1
+/******************************************************************************
2
+ * xen-x86_64.h
3
+ *
4
+ * Guest OS interface to x86 64-bit Xen.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to
8
+ * deal in the Software without restriction, including without limitation the
9
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10
+ * sell copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in
14
+ * all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22
+ * DEALINGS IN THE SOFTWARE.
23
+ *
24
+ * Copyright (c) 2004-2006, K A Fraser
25
+ */
26
+
27
+#ifndef __XEN_PUBLIC_ARCH_X86_XEN_X86_64_H__
28
+#define __XEN_PUBLIC_ARCH_X86_XEN_X86_64_H__
29
+
30
+FILE_LICENCE ( MIT );
31
+
32
+/*
33
+ * Hypercall interface:
34
+ *  Input:  %rdi, %rsi, %rdx, %r10, %r8, %r9 (arguments 1-6)
35
+ *  Output: %rax
36
+ * Access is via hypercall page (set up by guest loader or via a Xen MSR):
37
+ *  call hypercall_page + hypercall-number * 32
38
+ * Clobbered: argument registers (e.g., 2-arg hypercall clobbers %rdi,%rsi)
39
+ */
40
+
41
+/*
42
+ * 64-bit segment selectors
43
+ * These flat segments are in the Xen-private section of every GDT. Since these
44
+ * are also present in the initial GDT, many OSes will be able to avoid
45
+ * installing their own GDT.
46
+ */
47
+
48
+#define FLAT_RING3_CS32 0xe023  /* GDT index 260 */
49
+#define FLAT_RING3_CS64 0xe033  /* GDT index 261 */
50
+#define FLAT_RING3_DS32 0xe02b  /* GDT index 262 */
51
+#define FLAT_RING3_DS64 0x0000  /* NULL selector */
52
+#define FLAT_RING3_SS32 0xe02b  /* GDT index 262 */
53
+#define FLAT_RING3_SS64 0xe02b  /* GDT index 262 */
54
+
55
+#define FLAT_KERNEL_DS64 FLAT_RING3_DS64
56
+#define FLAT_KERNEL_DS32 FLAT_RING3_DS32
57
+#define FLAT_KERNEL_DS   FLAT_KERNEL_DS64
58
+#define FLAT_KERNEL_CS64 FLAT_RING3_CS64
59
+#define FLAT_KERNEL_CS32 FLAT_RING3_CS32
60
+#define FLAT_KERNEL_CS   FLAT_KERNEL_CS64
61
+#define FLAT_KERNEL_SS64 FLAT_RING3_SS64
62
+#define FLAT_KERNEL_SS32 FLAT_RING3_SS32
63
+#define FLAT_KERNEL_SS   FLAT_KERNEL_SS64
64
+
65
+#define FLAT_USER_DS64 FLAT_RING3_DS64
66
+#define FLAT_USER_DS32 FLAT_RING3_DS32
67
+#define FLAT_USER_DS   FLAT_USER_DS64
68
+#define FLAT_USER_CS64 FLAT_RING3_CS64
69
+#define FLAT_USER_CS32 FLAT_RING3_CS32
70
+#define FLAT_USER_CS   FLAT_USER_CS64
71
+#define FLAT_USER_SS64 FLAT_RING3_SS64
72
+#define FLAT_USER_SS32 FLAT_RING3_SS32
73
+#define FLAT_USER_SS   FLAT_USER_SS64
74
+
75
+#define __HYPERVISOR_VIRT_START 0xFFFF800000000000
76
+#define __HYPERVISOR_VIRT_END   0xFFFF880000000000
77
+#define __MACH2PHYS_VIRT_START  0xFFFF800000000000
78
+#define __MACH2PHYS_VIRT_END    0xFFFF804000000000
79
+
80
+#ifndef HYPERVISOR_VIRT_START
81
+#define HYPERVISOR_VIRT_START mk_unsigned_long(__HYPERVISOR_VIRT_START)
82
+#define HYPERVISOR_VIRT_END   mk_unsigned_long(__HYPERVISOR_VIRT_END)
83
+#endif
84
+
85
+#define MACH2PHYS_VIRT_START  mk_unsigned_long(__MACH2PHYS_VIRT_START)
86
+#define MACH2PHYS_VIRT_END    mk_unsigned_long(__MACH2PHYS_VIRT_END)
87
+#define MACH2PHYS_NR_ENTRIES  ((MACH2PHYS_VIRT_END-MACH2PHYS_VIRT_START)>>3)
88
+#ifndef machine_to_phys_mapping
89
+#define machine_to_phys_mapping ((unsigned long *)HYPERVISOR_VIRT_START)
90
+#endif
91
+
92
+/*
93
+ * int HYPERVISOR_set_segment_base(unsigned int which, unsigned long base)
94
+ *  @which == SEGBASE_*  ;  @base == 64-bit base address
95
+ * Returns 0 on success.
96
+ */
97
+#define SEGBASE_FS          0
98
+#define SEGBASE_GS_USER     1
99
+#define SEGBASE_GS_KERNEL   2
100
+#define SEGBASE_GS_USER_SEL 3 /* Set user %gs specified in base[15:0] */
101
+
102
+/*
103
+ * int HYPERVISOR_iret(void)
104
+ * All arguments are on the kernel stack, in the following format.
105
+ * Never returns if successful. Current kernel context is lost.
106
+ * The saved CS is mapped as follows:
107
+ *   RING0 -> RING3 kernel mode.
108
+ *   RING1 -> RING3 kernel mode.
109
+ *   RING2 -> RING3 kernel mode.
110
+ *   RING3 -> RING3 user mode.
111
+ * However RING0 indicates that the guest kernel should return to iteself
112
+ * directly with
113
+ *      orb   $3,1*8(%rsp)
114
+ *      iretq
115
+ * If flags contains VGCF_in_syscall:
116
+ *   Restore RAX, RIP, RFLAGS, RSP.
117
+ *   Discard R11, RCX, CS, SS.
118
+ * Otherwise:
119
+ *   Restore RAX, R11, RCX, CS:RIP, RFLAGS, SS:RSP.
120
+ * All other registers are saved on hypercall entry and restored to user.
121
+ */
122
+/* Guest exited in SYSCALL context? Return to guest with SYSRET? */
123
+#define _VGCF_in_syscall 8
124
+#define VGCF_in_syscall  (1<<_VGCF_in_syscall)
125
+#define VGCF_IN_SYSCALL  VGCF_in_syscall
126
+
127
+#ifndef __ASSEMBLY__
128
+
129
+struct iret_context {
130
+    /* Top of stack (%rsp at point of hypercall). */
131
+    uint64_t rax, r11, rcx, flags, rip, cs, rflags, rsp, ss;
132
+    /* Bottom of iret stack frame. */
133
+};
134
+
135
+#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
136
+/* Anonymous union includes both 32- and 64-bit names (e.g., eax/rax). */
137
+#define __DECL_REG(name) union { \
138
+    uint64_t r ## name, e ## name; \
139
+    uint32_t _e ## name; \
140
+}
141
+#else
142
+/* Non-gcc sources must always use the proper 64-bit name (e.g., rax). */
143
+#define __DECL_REG(name) uint64_t r ## name
144
+#endif
145
+
146
+struct cpu_user_regs {
147
+    uint64_t r15;
148
+    uint64_t r14;
149
+    uint64_t r13;
150
+    uint64_t r12;
151
+    __DECL_REG(bp);
152
+    __DECL_REG(bx);
153
+    uint64_t r11;
154
+    uint64_t r10;
155
+    uint64_t r9;
156
+    uint64_t r8;
157
+    __DECL_REG(ax);
158
+    __DECL_REG(cx);
159
+    __DECL_REG(dx);
160
+    __DECL_REG(si);
161
+    __DECL_REG(di);
162
+    uint32_t error_code;    /* private */
163
+    uint32_t entry_vector;  /* private */
164
+    __DECL_REG(ip);
165
+    uint16_t cs, _pad0[1];
166
+    uint8_t  saved_upcall_mask;
167
+    uint8_t  _pad1[3];
168
+    __DECL_REG(flags);      /* rflags.IF == !saved_upcall_mask */
169
+    __DECL_REG(sp);
170
+    uint16_t ss, _pad2[3];
171
+    uint16_t es, _pad3[3];
172
+    uint16_t ds, _pad4[3];
173
+    uint16_t fs, _pad5[3]; /* Non-zero => takes precedence over fs_base.     */
174
+    uint16_t gs, _pad6[3]; /* Non-zero => takes precedence over gs_base_usr. */
175
+};
176
+typedef struct cpu_user_regs cpu_user_regs_t;
177
+DEFINE_XEN_GUEST_HANDLE(cpu_user_regs_t);
178
+
179
+#undef __DECL_REG
180
+
181
+#define xen_pfn_to_cr3(pfn) ((unsigned long)(pfn) << 12)
182
+#define xen_cr3_to_pfn(cr3) ((unsigned long)(cr3) >> 12)
183
+
184
+struct arch_vcpu_info {
185
+    unsigned long cr2;
186
+    unsigned long pad; /* sizeof(vcpu_info_t) == 64 */
187
+};
188
+typedef struct arch_vcpu_info arch_vcpu_info_t;
189
+
190
+typedef unsigned long xen_callback_t;
191
+
192
+#endif /* !__ASSEMBLY__ */
193
+
194
+#endif /* __XEN_PUBLIC_ARCH_X86_XEN_X86_64_H__ */
195
+
196
+/*
197
+ * Local variables:
198
+ * mode: C
199
+ * c-file-style: "BSD"
200
+ * c-basic-offset: 4
201
+ * tab-width: 4
202
+ * indent-tabs-mode: nil
203
+ * End:
204
+ */

+ 275
- 0
src/include/xen/arch-x86/xen.h View File

@@ -0,0 +1,275 @@
1
+/******************************************************************************
2
+ * arch-x86/xen.h
3
+ *
4
+ * Guest OS interface to x86 Xen.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to
8
+ * deal in the Software without restriction, including without limitation the
9
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10
+ * sell copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in
14
+ * all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22
+ * DEALINGS IN THE SOFTWARE.
23
+ *
24
+ * Copyright (c) 2004-2006, K A Fraser
25
+ */
26
+
27
+#include "../xen.h"
28
+
29
+#ifndef __XEN_PUBLIC_ARCH_X86_XEN_H__
30
+#define __XEN_PUBLIC_ARCH_X86_XEN_H__
31
+
32
+FILE_LICENCE ( MIT );
33
+
34
+/* Structural guest handles introduced in 0x00030201. */
35
+#if __XEN_INTERFACE_VERSION__ >= 0x00030201
36
+#define ___DEFINE_XEN_GUEST_HANDLE(name, type) \
37
+    typedef struct { type *p; } __guest_handle_ ## name
38
+#else
39
+#define ___DEFINE_XEN_GUEST_HANDLE(name, type) \
40
+    typedef type * __guest_handle_ ## name
41
+#endif
42
+
43
+/*
44
+ * XEN_GUEST_HANDLE represents a guest pointer, when passed as a field
45
+ * in a struct in memory.
46
+ * XEN_GUEST_HANDLE_PARAM represent a guest pointer, when passed as an
47
+ * hypercall argument.
48
+ * XEN_GUEST_HANDLE_PARAM and XEN_GUEST_HANDLE are the same on X86 but
49
+ * they might not be on other architectures.
50
+ */
51
+#define __DEFINE_XEN_GUEST_HANDLE(name, type) \
52
+    ___DEFINE_XEN_GUEST_HANDLE(name, type);   \
53
+    ___DEFINE_XEN_GUEST_HANDLE(const_##name, const type)
54
+#define DEFINE_XEN_GUEST_HANDLE(name)   __DEFINE_XEN_GUEST_HANDLE(name, name)
55
+#define __XEN_GUEST_HANDLE(name)        __guest_handle_ ## name
56
+#define XEN_GUEST_HANDLE(name)          __XEN_GUEST_HANDLE(name)
57
+#define XEN_GUEST_HANDLE_PARAM(name)    XEN_GUEST_HANDLE(name)
58
+#define set_xen_guest_handle_raw(hnd, val)  do { (hnd).p = val; } while (0)
59
+#ifdef __XEN_TOOLS__
60
+#define get_xen_guest_handle(val, hnd)  do { val = (hnd).p; } while (0)
61
+#endif
62
+#define set_xen_guest_handle(hnd, val) set_xen_guest_handle_raw(hnd, val)
63
+
64
+#if defined(__i386__)
65
+#include "xen-x86_32.h"
66
+#elif defined(__x86_64__)
67
+#include "xen-x86_64.h"
68
+#endif
69
+
70
+#ifndef __ASSEMBLY__
71
+typedef unsigned long xen_pfn_t;
72
+#define PRI_xen_pfn "lx"
73
+#endif
74
+
75
+#define XEN_HAVE_PV_GUEST_ENTRY 1
76
+
77
+#define XEN_HAVE_PV_UPCALL_MASK 1
78
+
79
+/*
80
+ * `incontents 200 segdesc Segment Descriptor Tables
81
+ */
82
+/*
83
+ * ` enum neg_errnoval
84
+ * ` HYPERVISOR_set_gdt(const xen_pfn_t frames[], unsigned int entries);
85
+ * `
86
+ */
87
+/*
88
+ * A number of GDT entries are reserved by Xen. These are not situated at the
89
+ * start of the GDT because some stupid OSes export hard-coded selector values
90
+ * in their ABI. These hard-coded values are always near the start of the GDT,
91
+ * so Xen places itself out of the way, at the far end of the GDT.
92
+ *
93
+ * NB The LDT is set using the MMUEXT_SET_LDT op of HYPERVISOR_mmuext_op
94
+ */
95
+#define FIRST_RESERVED_GDT_PAGE  14
96
+#define FIRST_RESERVED_GDT_BYTE  (FIRST_RESERVED_GDT_PAGE * 4096)
97
+#define FIRST_RESERVED_GDT_ENTRY (FIRST_RESERVED_GDT_BYTE / 8)
98
+
99
+
100
+/*
101
+ * ` enum neg_errnoval
102
+ * ` HYPERVISOR_update_descriptor(u64 pa, u64 desc);
103
+ * `
104
+ * ` @pa   The machine physical address of the descriptor to
105
+ * `       update. Must be either a descriptor page or writable.
106
+ * ` @desc The descriptor value to update, in the same format as a
107
+ * `       native descriptor table entry.
108
+ */
109
+
110
+/* Maximum number of virtual CPUs in legacy multi-processor guests. */
111
+#define XEN_LEGACY_MAX_VCPUS 32
112
+
113
+#ifndef __ASSEMBLY__
114
+
115
+typedef unsigned long xen_ulong_t;
116
+#define PRI_xen_ulong "lx"
117
+
118
+/*
119
+ * ` enum neg_errnoval
120
+ * ` HYPERVISOR_stack_switch(unsigned long ss, unsigned long esp);
121
+ * `
122
+ * Sets the stack segment and pointer for the current vcpu.
123
+ */
124
+
125
+/*
126
+ * ` enum neg_errnoval
127
+ * ` HYPERVISOR_set_trap_table(const struct trap_info traps[]);
128
+ * `
129
+ */
130
+/*
131
+ * Send an array of these to HYPERVISOR_set_trap_table().
132
+ * Terminate the array with a sentinel entry, with traps[].address==0.
133
+ * The privilege level specifies which modes may enter a trap via a software
134
+ * interrupt. On x86/64, since rings 1 and 2 are unavailable, we allocate
135
+ * privilege levels as follows:
136
+ *  Level == 0: Noone may enter
137
+ *  Level == 1: Kernel may enter
138
+ *  Level == 2: Kernel may enter
139
+ *  Level == 3: Everyone may enter
140
+ */
141
+#define TI_GET_DPL(_ti)      ((_ti)->flags & 3)
142
+#define TI_GET_IF(_ti)       ((_ti)->flags & 4)
143
+#define TI_SET_DPL(_ti,_dpl) ((_ti)->flags |= (_dpl))
144
+#define TI_SET_IF(_ti,_if)   ((_ti)->flags |= ((!!(_if))<<2))
145
+struct trap_info {
146
+    uint8_t       vector;  /* exception vector                              */
147
+    uint8_t       flags;   /* 0-3: privilege level; 4: clear event enable?  */
148
+    uint16_t      cs;      /* code selector                                 */
149
+    unsigned long address; /* code offset                                   */
150
+};
151
+typedef struct trap_info trap_info_t;
152
+DEFINE_XEN_GUEST_HANDLE(trap_info_t);
153
+
154
+typedef uint64_t tsc_timestamp_t; /* RDTSC timestamp */
155
+
156
+/*
157
+ * The following is all CPU context. Note that the fpu_ctxt block is filled
158
+ * in by FXSAVE if the CPU has feature FXSR; otherwise FSAVE is used.
159
+ *
160
+ * Also note that when calling DOMCTL_setvcpucontext and VCPU_initialise
161
+ * for HVM and PVH guests, not all information in this structure is updated:
162
+ *
163
+ * - For HVM guests, the structures read include: fpu_ctxt (if
164
+ * VGCT_I387_VALID is set), flags, user_regs, debugreg[*]
165
+ *
166
+ * - PVH guests are the same as HVM guests, but additionally use ctrlreg[3] to
167
+ * set cr3. All other fields not used should be set to 0.
168
+ */
169
+struct vcpu_guest_context {
170
+    /* FPU registers come first so they can be aligned for FXSAVE/FXRSTOR. */
171
+    struct { char x[512]; } fpu_ctxt;       /* User-level FPU registers     */
172
+#define VGCF_I387_VALID                (1<<0)
173
+#define VGCF_IN_KERNEL                 (1<<2)
174
+#define _VGCF_i387_valid               0
175
+#define VGCF_i387_valid                (1<<_VGCF_i387_valid)
176
+#define _VGCF_in_kernel                2
177
+#define VGCF_in_kernel                 (1<<_VGCF_in_kernel)
178
+#define _VGCF_failsafe_disables_events 3
179
+#define VGCF_failsafe_disables_events  (1<<_VGCF_failsafe_disables_events)
180
+#define _VGCF_syscall_disables_events  4
181
+#define VGCF_syscall_disables_events   (1<<_VGCF_syscall_disables_events)
182
+#define _VGCF_online                   5
183
+#define VGCF_online                    (1<<_VGCF_online)
184
+    unsigned long flags;                    /* VGCF_* flags                 */
185
+    struct cpu_user_regs user_regs;         /* User-level CPU registers     */
186
+    struct trap_info trap_ctxt[256];        /* Virtual IDT                  */
187
+    unsigned long ldt_base, ldt_ents;       /* LDT (linear address, # ents) */
188
+    unsigned long gdt_frames[16], gdt_ents; /* GDT (machine frames, # ents) */
189
+    unsigned long kernel_ss, kernel_sp;     /* Virtual TSS (only SS1/SP1)   */
190
+    /* NB. User pagetable on x86/64 is placed in ctrlreg[1]. */
191
+    unsigned long ctrlreg[8];               /* CR0-CR7 (control registers)  */
192
+    unsigned long debugreg[8];              /* DB0-DB7 (debug registers)    */
193
+#ifdef __i386__
194
+    unsigned long event_callback_cs;        /* CS:EIP of event callback     */
195
+    unsigned long event_callback_eip;
196
+    unsigned long failsafe_callback_cs;     /* CS:EIP of failsafe callback  */
197
+    unsigned long failsafe_callback_eip;
198
+#else
199
+    unsigned long event_callback_eip;
200
+    unsigned long failsafe_callback_eip;
201
+#ifdef __XEN__
202
+    union {
203
+        unsigned long syscall_callback_eip;
204
+        struct {
205
+            unsigned int event_callback_cs;    /* compat CS of event cb     */
206
+            unsigned int failsafe_callback_cs; /* compat CS of failsafe cb  */
207
+        };
208
+    };
209
+#else
210
+    unsigned long syscall_callback_eip;
211
+#endif
212
+#endif
213
+    unsigned long vm_assist;                /* VMASST_TYPE_* bitmap */
214
+#ifdef __x86_64__
215
+    /* Segment base addresses. */
216
+    uint64_t      fs_base;
217
+    uint64_t      gs_base_kernel;
218
+    uint64_t      gs_base_user;
219
+#endif
220
+};
221
+typedef struct vcpu_guest_context vcpu_guest_context_t;
222
+DEFINE_XEN_GUEST_HANDLE(vcpu_guest_context_t);
223
+
224
+struct arch_shared_info {
225
+    unsigned long max_pfn;                  /* max pfn that appears in table */
226
+    /* Frame containing list of mfns containing list of mfns containing p2m. */
227
+    xen_pfn_t     pfn_to_mfn_frame_list_list;
228
+    unsigned long nmi_reason;
229
+    uint64_t pad[32];
230
+};
231
+typedef struct arch_shared_info arch_shared_info_t;
232
+
233
+#endif /* !__ASSEMBLY__ */
234
+
235
+/*
236
+ * ` enum neg_errnoval
237
+ * ` HYPERVISOR_fpu_taskswitch(int set);
238
+ * `
239
+ * Sets (if set!=0) or clears (if set==0) CR0.TS.
240
+ */
241
+
242
+/*
243
+ * ` enum neg_errnoval
244
+ * ` HYPERVISOR_set_debugreg(int regno, unsigned long value);
245
+ *
246
+ * ` unsigned long
247
+ * ` HYPERVISOR_get_debugreg(int regno);
248
+ * For 0<=reg<=7, returns the debug register value.
249
+ * For other values of reg, returns ((unsigned long)-EINVAL).
250
+ * (Unfortunately, this interface is defective.)
251
+ */
252
+
253
+/*
254
+ * Prefix forces emulation of some non-trapping instructions.
255
+ * Currently only CPUID.
256
+ */
257
+#ifdef __ASSEMBLY__
258
+#define XEN_EMULATE_PREFIX .byte 0x0f,0x0b,0x78,0x65,0x6e ;
259
+#define XEN_CPUID          XEN_EMULATE_PREFIX cpuid
260
+#else
261
+#define XEN_EMULATE_PREFIX ".byte 0x0f,0x0b,0x78,0x65,0x6e ; "
262
+#define XEN_CPUID          XEN_EMULATE_PREFIX "cpuid"
263
+#endif
264
+
265
+#endif /* __XEN_PUBLIC_ARCH_X86_XEN_H__ */
266
+
267
+/*
268
+ * Local variables:
269
+ * mode: C
270
+ * c-file-style: "BSD"
271
+ * c-basic-offset: 4
272
+ * tab-width: 4
273
+ * indent-tabs-mode: nil
274
+ * End:
275
+ */

+ 383
- 0
src/include/xen/event_channel.h View File

@@ -0,0 +1,383 @@
1
+/******************************************************************************
2
+ * event_channel.h
3
+ *
4
+ * Event channels between domains.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to
8
+ * deal in the Software without restriction, including without limitation the
9
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10
+ * sell copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in
14
+ * all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22
+ * DEALINGS IN THE SOFTWARE.
23
+ *
24
+ * Copyright (c) 2003-2004, K A Fraser.
25
+ */
26
+
27
+#ifndef __XEN_PUBLIC_EVENT_CHANNEL_H__
28
+#define __XEN_PUBLIC_EVENT_CHANNEL_H__
29
+
30
+FILE_LICENCE ( MIT );
31
+
32
+#include "xen.h"
33
+
34
+/*
35
+ * `incontents 150 evtchn Event Channels
36
+ *
37
+ * Event channels are the basic primitive provided by Xen for event
38
+ * notifications. An event is the Xen equivalent of a hardware
39
+ * interrupt. They essentially store one bit of information, the event
40
+ * of interest is signalled by transitioning this bit from 0 to 1.
41
+ *
42
+ * Notifications are received by a guest via an upcall from Xen,
43
+ * indicating when an event arrives (setting the bit). Further
44
+ * notifications are masked until the bit is cleared again (therefore,
45
+ * guests must check the value of the bit after re-enabling event
46
+ * delivery to ensure no missed notifications).
47
+ *
48
+ * Event notifications can be masked by setting a flag; this is
49
+ * equivalent to disabling interrupts and can be used to ensure
50
+ * atomicity of certain operations in the guest kernel.
51
+ *
52
+ * Event channels are represented by the evtchn_* fields in
53
+ * struct shared_info and struct vcpu_info.
54
+ */
55
+
56
+/*
57
+ * ` enum neg_errnoval
58
+ * ` HYPERVISOR_event_channel_op(enum event_channel_op cmd, void *args)
59
+ * `
60
+ * @cmd  == EVTCHNOP_* (event-channel operation).
61
+ * @args == struct evtchn_* Operation-specific extra arguments (NULL if none).
62
+ */
63
+
64
+/* ` enum event_channel_op { // EVTCHNOP_* => struct evtchn_* */
65
+#define EVTCHNOP_bind_interdomain 0
66
+#define EVTCHNOP_bind_virq        1
67
+#define EVTCHNOP_bind_pirq        2
68
+#define EVTCHNOP_close            3
69
+#define EVTCHNOP_send             4
70
+#define EVTCHNOP_status           5
71
+#define EVTCHNOP_alloc_unbound    6
72
+#define EVTCHNOP_bind_ipi         7
73
+#define EVTCHNOP_bind_vcpu        8
74
+#define EVTCHNOP_unmask           9
75
+#define EVTCHNOP_reset           10
76
+#define EVTCHNOP_init_control    11
77
+#define EVTCHNOP_expand_array    12
78
+#define EVTCHNOP_set_priority    13
79
+/* ` } */
80
+
81
+typedef uint32_t evtchn_port_t;
82
+DEFINE_XEN_GUEST_HANDLE(evtchn_port_t);
83
+
84
+/*
85
+ * EVTCHNOP_alloc_unbound: Allocate a port in domain <dom> and mark as
86
+ * accepting interdomain bindings from domain <remote_dom>. A fresh port
87
+ * is allocated in <dom> and returned as <port>.
88
+ * NOTES:
89
+ *  1. If the caller is unprivileged then <dom> must be DOMID_SELF.
90
+ *  2. <rdom> may be DOMID_SELF, allowing loopback connections.
91
+ */
92
+struct evtchn_alloc_unbound {
93
+    /* IN parameters */
94
+    domid_t dom, remote_dom;
95
+    /* OUT parameters */
96
+    evtchn_port_t port;
97
+};
98
+typedef struct evtchn_alloc_unbound evtchn_alloc_unbound_t;
99
+
100
+/*
101
+ * EVTCHNOP_bind_interdomain: Construct an interdomain event channel between
102
+ * the calling domain and <remote_dom>. <remote_dom,remote_port> must identify
103
+ * a port that is unbound and marked as accepting bindings from the calling
104
+ * domain. A fresh port is allocated in the calling domain and returned as
105
+ * <local_port>.
106
+ *
107
+ * In case the peer domain has already tried to set our event channel
108
+ * pending, before it was bound, EVTCHNOP_bind_interdomain always sets
109
+ * the local event channel pending.
110
+ *
111
+ * The usual pattern of use, in the guest's upcall (or subsequent
112
+ * handler) is as follows: (Re-enable the event channel for subsequent
113
+ * signalling and then) check for the existence of whatever condition
114
+ * is being waited for by other means, and take whatever action is
115
+ * needed (if any).
116
+ *
117
+ * NOTES:
118
+ *  1. <remote_dom> may be DOMID_SELF, allowing loopback connections.
119
+ */
120
+struct evtchn_bind_interdomain {
121
+    /* IN parameters. */
122
+    domid_t remote_dom;
123
+    evtchn_port_t remote_port;
124
+    /* OUT parameters. */
125
+    evtchn_port_t local_port;
126
+};
127
+typedef struct evtchn_bind_interdomain evtchn_bind_interdomain_t;
128
+
129
+/*
130
+ * EVTCHNOP_bind_virq: Bind a local event channel to VIRQ <irq> on specified
131
+ * vcpu.
132
+ * NOTES:
133
+ *  1. Virtual IRQs are classified as per-vcpu or global. See the VIRQ list
134
+ *     in xen.h for the classification of each VIRQ.
135
+ *  2. Global VIRQs must be allocated on VCPU0 but can subsequently be
136
+ *     re-bound via EVTCHNOP_bind_vcpu.
137
+ *  3. Per-vcpu VIRQs may be bound to at most one event channel per vcpu.
138
+ *     The allocated event channel is bound to the specified vcpu and the
139
+ *     binding cannot be changed.
140
+ */
141
+struct evtchn_bind_virq {
142
+    /* IN parameters. */
143
+    uint32_t virq; /* enum virq */
144
+    uint32_t vcpu;
145
+    /* OUT parameters. */
146
+    evtchn_port_t port;
147
+};
148
+typedef struct evtchn_bind_virq evtchn_bind_virq_t;
149
+
150
+/*
151
+ * EVTCHNOP_bind_pirq: Bind a local event channel to a real IRQ (PIRQ <irq>).
152
+ * NOTES:
153
+ *  1. A physical IRQ may be bound to at most one event channel per domain.
154
+ *  2. Only a sufficiently-privileged domain may bind to a physical IRQ.
155
+ */
156
+struct evtchn_bind_pirq {
157
+    /* IN parameters. */
158
+    uint32_t pirq;
159
+#define BIND_PIRQ__WILL_SHARE 1
160
+    uint32_t flags; /* BIND_PIRQ__* */
161
+    /* OUT parameters. */
162
+    evtchn_port_t port;
163
+};
164
+typedef struct evtchn_bind_pirq evtchn_bind_pirq_t;
165
+
166
+/*
167
+ * EVTCHNOP_bind_ipi: Bind a local event channel to receive events.
168
+ * NOTES:
169
+ *  1. The allocated event channel is bound to the specified vcpu. The binding
170
+ *     may not be changed.
171
+ */
172
+struct evtchn_bind_ipi {
173
+    uint32_t vcpu;
174
+    /* OUT parameters. */
175
+    evtchn_port_t port;
176
+};
177
+typedef struct evtchn_bind_ipi evtchn_bind_ipi_t;
178
+
179
+/*
180
+ * EVTCHNOP_close: Close a local event channel <port>. If the channel is
181
+ * interdomain then the remote end is placed in the unbound state
182
+ * (EVTCHNSTAT_unbound), awaiting a new connection.
183
+ */
184
+struct evtchn_close {
185
+    /* IN parameters. */
186
+    evtchn_port_t port;
187
+};
188
+typedef struct evtchn_close evtchn_close_t;
189
+
190
+/*
191
+ * EVTCHNOP_send: Send an event to the remote end of the channel whose local
192
+ * endpoint is <port>.
193
+ */
194
+struct evtchn_send {
195
+    /* IN parameters. */
196
+    evtchn_port_t port;
197
+};
198
+typedef struct evtchn_send evtchn_send_t;
199
+
200
+/*
201
+ * EVTCHNOP_status: Get the current status of the communication channel which
202
+ * has an endpoint at <dom, port>.
203
+ * NOTES:
204
+ *  1. <dom> may be specified as DOMID_SELF.
205
+ *  2. Only a sufficiently-privileged domain may obtain the status of an event
206
+ *     channel for which <dom> is not DOMID_SELF.
207
+ */
208
+struct evtchn_status {
209
+    /* IN parameters */
210
+    domid_t  dom;
211
+    evtchn_port_t port;
212
+    /* OUT parameters */
213
+#define EVTCHNSTAT_closed       0  /* Channel is not in use.                 */
214
+#define EVTCHNSTAT_unbound      1  /* Channel is waiting interdom connection.*/
215
+#define EVTCHNSTAT_interdomain  2  /* Channel is connected to remote domain. */
216
+#define EVTCHNSTAT_pirq         3  /* Channel is bound to a phys IRQ line.   */
217
+#define EVTCHNSTAT_virq         4  /* Channel is bound to a virtual IRQ line */
218
+#define EVTCHNSTAT_ipi          5  /* Channel is bound to a virtual IPI line */
219
+    uint32_t status;
220
+    uint32_t vcpu;                 /* VCPU to which this channel is bound.   */
221
+    union {
222
+        struct {
223
+            domid_t dom;
224
+        } unbound;                 /* EVTCHNSTAT_unbound */
225
+        struct {
226
+            domid_t dom;
227
+            evtchn_port_t port;
228
+        } interdomain;             /* EVTCHNSTAT_interdomain */
229
+        uint32_t pirq;             /* EVTCHNSTAT_pirq        */
230
+        uint32_t virq;             /* EVTCHNSTAT_virq        */
231
+    } u;
232
+};
233
+typedef struct evtchn_status evtchn_status_t;
234
+
235
+/*
236
+ * EVTCHNOP_bind_vcpu: Specify which vcpu a channel should notify when an
237
+ * event is pending.
238
+ * NOTES:
239
+ *  1. IPI-bound channels always notify the vcpu specified at bind time.
240
+ *     This binding cannot be changed.
241
+ *  2. Per-VCPU VIRQ channels always notify the vcpu specified at bind time.
242
+ *     This binding cannot be changed.
243
+ *  3. All other channels notify vcpu0 by default. This default is set when
244
+ *     the channel is allocated (a port that is freed and subsequently reused
245
+ *     has its binding reset to vcpu0).
246
+ */
247
+struct evtchn_bind_vcpu {
248
+    /* IN parameters. */
249
+    evtchn_port_t port;
250
+    uint32_t vcpu;
251
+};
252
+typedef struct evtchn_bind_vcpu evtchn_bind_vcpu_t;
253
+
254
+/*
255
+ * EVTCHNOP_unmask: Unmask the specified local event-channel port and deliver
256
+ * a notification to the appropriate VCPU if an event is pending.
257
+ */
258
+struct evtchn_unmask {
259
+    /* IN parameters. */
260
+    evtchn_port_t port;
261
+};
262
+typedef struct evtchn_unmask evtchn_unmask_t;
263
+
264
+/*
265
+ * EVTCHNOP_reset: Close all event channels associated with specified domain.
266
+ * NOTES:
267
+ *  1. <dom> may be specified as DOMID_SELF.
268
+ *  2. Only a sufficiently-privileged domain may specify other than DOMID_SELF.
269
+ */
270
+struct evtchn_reset {
271
+    /* IN parameters. */
272
+    domid_t dom;
273
+};
274
+typedef struct evtchn_reset evtchn_reset_t;
275
+
276
+/*
277
+ * EVTCHNOP_init_control: initialize the control block for the FIFO ABI.
278
+ *
279
+ * Note: any events that are currently pending will not be resent and
280
+ * will be lost.  Guests should call this before binding any event to
281
+ * avoid losing any events.
282
+ */
283
+struct evtchn_init_control {
284
+    /* IN parameters. */
285
+    uint64_t control_gfn;
286
+    uint32_t offset;
287
+    uint32_t vcpu;
288
+    /* OUT parameters. */
289
+    uint8_t link_bits;
290
+    uint8_t _pad[7];
291
+};
292
+typedef struct evtchn_init_control evtchn_init_control_t;
293
+
294
+/*
295
+ * EVTCHNOP_expand_array: add an additional page to the event array.
296
+ */
297
+struct evtchn_expand_array {
298
+    /* IN parameters. */
299
+    uint64_t array_gfn;
300
+};
301
+typedef struct evtchn_expand_array evtchn_expand_array_t;
302
+
303
+/*
304
+ * EVTCHNOP_set_priority: set the priority for an event channel.
305
+ */
306
+struct evtchn_set_priority {
307
+    /* IN parameters. */
308
+    uint32_t port;
309
+    uint32_t priority;
310
+};
311
+typedef struct evtchn_set_priority evtchn_set_priority_t;
312
+
313
+/*
314
+ * ` enum neg_errnoval
315
+ * ` HYPERVISOR_event_channel_op_compat(struct evtchn_op *op)
316
+ * `
317
+ * Superceded by new event_channel_op() hypercall since 0x00030202.
318
+ */
319
+struct evtchn_op {
320
+    uint32_t cmd; /* enum event_channel_op */
321
+    union {
322
+        struct evtchn_alloc_unbound    alloc_unbound;
323
+        struct evtchn_bind_interdomain bind_interdomain;
324
+        struct evtchn_bind_virq        bind_virq;
325
+        struct evtchn_bind_pirq        bind_pirq;
326
+        struct evtchn_bind_ipi         bind_ipi;
327
+        struct evtchn_close            close;
328
+        struct evtchn_send             send;
329
+        struct evtchn_status           status;
330
+        struct evtchn_bind_vcpu        bind_vcpu;
331
+        struct evtchn_unmask           unmask;
332
+    } u;
333
+};
334
+typedef struct evtchn_op evtchn_op_t;
335
+DEFINE_XEN_GUEST_HANDLE(evtchn_op_t);
336
+
337
+/*
338
+ * 2-level ABI
339
+ */
340
+
341
+#define EVTCHN_2L_NR_CHANNELS (sizeof(xen_ulong_t) * sizeof(xen_ulong_t) * 64)
342
+
343
+/*
344
+ * FIFO ABI
345
+ */
346
+
347
+/* Events may have priorities from 0 (highest) to 15 (lowest). */
348
+#define EVTCHN_FIFO_PRIORITY_MAX     0
349
+#define EVTCHN_FIFO_PRIORITY_DEFAULT 7
350
+#define EVTCHN_FIFO_PRIORITY_MIN     15
351
+
352
+#define EVTCHN_FIFO_MAX_QUEUES (EVTCHN_FIFO_PRIORITY_MIN + 1)
353
+
354
+typedef uint32_t event_word_t;
355
+
356
+#define EVTCHN_FIFO_PENDING 31
357
+#define EVTCHN_FIFO_MASKED  30
358
+#define EVTCHN_FIFO_LINKED  29
359
+#define EVTCHN_FIFO_BUSY    28
360
+
361
+#define EVTCHN_FIFO_LINK_BITS 17
362
+#define EVTCHN_FIFO_LINK_MASK ((1 << EVTCHN_FIFO_LINK_BITS) - 1)
363
+
364
+#define EVTCHN_FIFO_NR_CHANNELS (1 << EVTCHN_FIFO_LINK_BITS)
365
+
366
+struct evtchn_fifo_control_block {
367
+    uint32_t ready;
368
+    uint32_t _rsvd;
369
+    uint32_t head[EVTCHN_FIFO_MAX_QUEUES];
370
+};
371
+typedef struct evtchn_fifo_control_block evtchn_fifo_control_block_t;
372
+
373
+#endif /* __XEN_PUBLIC_EVENT_CHANNEL_H__ */
374
+
375
+/*
376
+ * Local variables:
377
+ * mode: C
378
+ * c-file-style: "BSD"
379
+ * c-basic-offset: 4
380
+ * tab-width: 4
381
+ * indent-tabs-mode: nil
382
+ * End:
383
+ */

+ 111
- 0
src/include/xen/features.h View File

@@ -0,0 +1,111 @@
1
+/******************************************************************************
2
+ * features.h
3
+ *
4
+ * Feature flags, reported by XENVER_get_features.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to
8
+ * deal in the Software without restriction, including without limitation the
9
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10
+ * sell copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in
14
+ * all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22
+ * DEALINGS IN THE SOFTWARE.
23
+ *
24
+ * Copyright (c) 2006, Keir Fraser <keir@xensource.com>
25
+ */
26
+
27
+#ifndef __XEN_PUBLIC_FEATURES_H__
28
+#define __XEN_PUBLIC_FEATURES_H__
29
+
30
+FILE_LICENCE ( MIT );
31
+
32
+/*
33
+ * `incontents 200 elfnotes_features XEN_ELFNOTE_FEATURES
34
+ *
35
+ * The list of all the features the guest supports. They are set by
36
+ * parsing the XEN_ELFNOTE_FEATURES and XEN_ELFNOTE_SUPPORTED_FEATURES
37
+ * string. The format is the  feature names (as given here without the
38
+ * "XENFEAT_" prefix) separated by '|' characters.
39
+ * If a feature is required for the kernel to function then the feature name
40
+ * must be preceded by a '!' character.
41
+ *
42
+ * Note that if XEN_ELFNOTE_SUPPORTED_FEATURES is used, then in the
43
+ * XENFEAT_dom0 MUST be set if the guest is to be booted as dom0,
44
+ */
45
+
46
+/*
47
+ * If set, the guest does not need to write-protect its pagetables, and can
48
+ * update them via direct writes.
49
+ */
50
+#define XENFEAT_writable_page_tables       0
51
+
52
+/*
53
+ * If set, the guest does not need to write-protect its segment descriptor
54
+ * tables, and can update them via direct writes.
55
+ */
56
+#define XENFEAT_writable_descriptor_tables 1
57
+
58
+/*
59
+ * If set, translation between the guest's 'pseudo-physical' address space
60
+ * and the host's machine address space are handled by the hypervisor. In this
61
+ * mode the guest does not need to perform phys-to/from-machine translations
62
+ * when performing page table operations.
63
+ */
64
+#define XENFEAT_auto_translated_physmap    2
65
+
66
+/* If set, the guest is running in supervisor mode (e.g., x86 ring 0). */
67
+#define XENFEAT_supervisor_mode_kernel     3
68
+
69
+/*
70
+ * If set, the guest does not need to allocate x86 PAE page directories
71
+ * below 4GB. This flag is usually implied by auto_translated_physmap.
72
+ */
73
+#define XENFEAT_pae_pgdir_above_4gb        4
74
+
75
+/* x86: Does this Xen host support the MMU_PT_UPDATE_PRESERVE_AD hypercall? */
76
+#define XENFEAT_mmu_pt_update_preserve_ad  5
77
+
78
+/* x86: Does this Xen host support the MMU_{CLEAR,COPY}_PAGE hypercall? */
79
+#define XENFEAT_highmem_assist             6
80
+
81
+/*
82
+ * If set, GNTTABOP_map_grant_ref honors flags to be placed into guest kernel
83
+ * available pte bits.
84
+ */
85
+#define XENFEAT_gnttab_map_avail_bits      7
86
+
87
+/* x86: Does this Xen host support the HVM callback vector type? */
88
+#define XENFEAT_hvm_callback_vector        8
89
+
90
+/* x86: pvclock algorithm is safe to use on HVM */
91
+#define XENFEAT_hvm_safe_pvclock           9
92
+
93
+/* x86: pirq can be used by HVM guests */
94
+#define XENFEAT_hvm_pirqs                 10
95
+
96
+/* operation as Dom0 is supported */
97
+#define XENFEAT_dom0                      11
98
+
99
+#define XENFEAT_NR_SUBMAPS 1
100
+
101
+#endif /* __XEN_PUBLIC_FEATURES_H__ */
102
+
103
+/*
104
+ * Local variables:
105
+ * mode: C
106
+ * c-file-style: "BSD"
107
+ * c-basic-offset: 4
108
+ * tab-width: 4
109
+ * indent-tabs-mode: nil
110
+ * End:
111
+ */

+ 664
- 0
src/include/xen/grant_table.h View File

@@ -0,0 +1,664 @@
1
+/******************************************************************************
2
+ * grant_table.h
3
+ *
4
+ * Interface for granting foreign access to page frames, and receiving
5
+ * page-ownership transfers.
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_GRANT_TABLE_H__
29
+#define __XEN_PUBLIC_GRANT_TABLE_H__
30
+
31
+FILE_LICENCE ( MIT );
32
+
33
+#include "xen.h"
34
+
35
+/*
36
+ * `incontents 150 gnttab Grant Tables
37
+ *
38
+ * Xen's grant tables provide a generic mechanism to memory sharing
39
+ * between domains. This shared memory interface underpins the split
40
+ * device drivers for block and network IO.
41
+ *
42
+ * Each domain has its own grant table. This is a data structure that
43
+ * is shared with Xen; it allows the domain to tell Xen what kind of
44
+ * permissions other domains have on its pages. Entries in the grant
45
+ * table are identified by grant references. A grant reference is an
46
+ * integer, which indexes into the grant table. It acts as a
47
+ * capability which the grantee can use to perform operations on the
48
+ * granter’s memory.
49
+ *
50
+ * This capability-based system allows shared-memory communications
51
+ * between unprivileged domains. A grant reference also encapsulates
52
+ * the details of a shared page, removing the need for a domain to
53
+ * know the real machine address of a page it is sharing. This makes
54
+ * it possible to share memory correctly with domains running in
55
+ * fully virtualised memory.
56
+ */
57
+
58
+/***********************************
59
+ * GRANT TABLE REPRESENTATION
60
+ */
61
+
62
+/* Some rough guidelines on accessing and updating grant-table entries
63
+ * in a concurrency-safe manner. For more information, Linux contains a
64
+ * reference implementation for guest OSes (drivers/xen/grant_table.c, see
65
+ * http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=drivers/xen/grant-table.c;hb=HEAD
66
+ *
67
+ * NB. WMB is a no-op on current-generation x86 processors. However, a
68
+ *     compiler barrier will still be required.
69
+ *
70
+ * Introducing a valid entry into the grant table:
71
+ *  1. Write ent->domid.
72
+ *  2. Write ent->frame:
73
+ *      GTF_permit_access:   Frame to which access is permitted.
74
+ *      GTF_accept_transfer: Pseudo-phys frame slot being filled by new
75
+ *                           frame, or zero if none.
76
+ *  3. Write memory barrier (WMB).
77
+ *  4. Write ent->flags, inc. valid type.
78
+ *
79
+ * Invalidating an unused GTF_permit_access entry:
80
+ *  1. flags = ent->flags.
81
+ *  2. Observe that !(flags & (GTF_reading|GTF_writing)).
82
+ *  3. Check result of SMP-safe CMPXCHG(&ent->flags, flags, 0).
83
+ *  NB. No need for WMB as reuse of entry is control-dependent on success of
84
+ *      step 3, and all architectures guarantee ordering of ctrl-dep writes.
85
+ *
86
+ * Invalidating an in-use GTF_permit_access entry:
87
+ *  This cannot be done directly. Request assistance from the domain controller
88
+ *  which can set a timeout on the use of a grant entry and take necessary
89
+ *  action. (NB. This is not yet implemented!).
90
+ *
91
+ * Invalidating an unused GTF_accept_transfer entry:
92
+ *  1. flags = ent->flags.
93
+ *  2. Observe that !(flags & GTF_transfer_committed). [*]
94
+ *  3. Check result of SMP-safe CMPXCHG(&ent->flags, flags, 0).
95
+ *  NB. No need for WMB as reuse of entry is control-dependent on success of
96
+ *      step 3, and all architectures guarantee ordering of ctrl-dep writes.
97
+ *  [*] If GTF_transfer_committed is set then the grant entry is 'committed'.
98
+ *      The guest must /not/ modify the grant entry until the address of the
99
+ *      transferred frame is written. It is safe for the guest to spin waiting
100
+ *      for this to occur (detect by observing GTF_transfer_completed in
101
+ *      ent->flags).
102
+ *
103
+ * Invalidating a committed GTF_accept_transfer entry:
104
+ *  1. Wait for (ent->flags & GTF_transfer_completed).
105
+ *
106
+ * Changing a GTF_permit_access from writable to read-only:
107
+ *  Use SMP-safe CMPXCHG to set GTF_readonly, while checking !GTF_writing.
108
+ *
109
+ * Changing a GTF_permit_access from read-only to writable:
110
+ *  Use SMP-safe bit-setting instruction.
111
+ */
112
+
113
+/*
114
+ * Reference to a grant entry in a specified domain's grant table.
115
+ */
116
+typedef uint32_t grant_ref_t;
117
+
118
+/*
119
+ * A grant table comprises a packed array of grant entries in one or more
120
+ * page frames shared between Xen and a guest.
121
+ * [XEN]: This field is written by Xen and read by the sharing guest.
122
+ * [GST]: This field is written by the guest and read by Xen.
123
+ */
124
+
125
+/*
126
+ * Version 1 of the grant table entry structure is maintained purely
127
+ * for backwards compatibility.  New guests should use version 2.
128
+ */
129
+#if __XEN_INTERFACE_VERSION__ < 0x0003020a
130
+#define grant_entry_v1 grant_entry
131
+#define grant_entry_v1_t grant_entry_t
132
+#endif
133
+struct grant_entry_v1 {
134
+    /* GTF_xxx: various type and flag information.  [XEN,GST] */
135
+    uint16_t flags;
136
+    /* The domain being granted foreign privileges. [GST] */
137
+    domid_t  domid;
138
+    /*
139
+     * GTF_permit_access: Frame that @domid is allowed to map and access. [GST]
140
+     * GTF_accept_transfer: Frame whose ownership transferred by @domid. [XEN]
141
+     */
142
+    uint32_t frame;
143
+};
144
+typedef struct grant_entry_v1 grant_entry_v1_t;
145
+
146
+/* The first few grant table entries will be preserved across grant table
147
+ * version changes and may be pre-populated at domain creation by tools.
148
+ */
149
+#define GNTTAB_NR_RESERVED_ENTRIES     8
150
+#define GNTTAB_RESERVED_CONSOLE        0
151
+#define GNTTAB_RESERVED_XENSTORE       1
152
+
153
+/*
154
+ * Type of grant entry.
155
+ *  GTF_invalid: This grant entry grants no privileges.
156
+ *  GTF_permit_access: Allow @domid to map/access @frame.
157
+ *  GTF_accept_transfer: Allow @domid to transfer ownership of one page frame
158
+ *                       to this guest. Xen writes the page number to @frame.
159
+ *  GTF_transitive: Allow @domid to transitively access a subrange of
160
+ *                  @trans_grant in @trans_domid.  No mappings are allowed.
161
+ */
162
+#define GTF_invalid         (0U<<0)
163
+#define GTF_permit_access   (1U<<0)
164
+#define GTF_accept_transfer (2U<<0)
165
+#define GTF_transitive      (3U<<0)
166
+#define GTF_type_mask       (3U<<0)
167
+
168
+/*
169
+ * Subflags for GTF_permit_access.
170
+ *  GTF_readonly: Restrict @domid to read-only mappings and accesses. [GST]
171
+ *  GTF_reading: Grant entry is currently mapped for reading by @domid. [XEN]
172
+ *  GTF_writing: Grant entry is currently mapped for writing by @domid. [XEN]
173
+ *  GTF_PAT, GTF_PWT, GTF_PCD: (x86) cache attribute flags for the grant [GST]
174
+ *  GTF_sub_page: Grant access to only a subrange of the page.  @domid
175
+ *                will only be allowed to copy from the grant, and not
176
+ *                map it. [GST]
177
+ */
178
+#define _GTF_readonly       (2)
179
+#define GTF_readonly        (1U<<_GTF_readonly)
180
+#define _GTF_reading        (3)
181
+#define GTF_reading         (1U<<_GTF_reading)
182
+#define _GTF_writing        (4)
183
+#define GTF_writing         (1U<<_GTF_writing)
184
+#define _GTF_PWT            (5)
185
+#define GTF_PWT             (1U<<_GTF_PWT)
186
+#define _GTF_PCD            (6)
187
+#define GTF_PCD             (1U<<_GTF_PCD)
188
+#define _GTF_PAT            (7)
189
+#define GTF_PAT             (1U<<_GTF_PAT)
190
+#define _GTF_sub_page       (8)
191
+#define GTF_sub_page        (1U<<_GTF_sub_page)
192
+
193
+/*
194
+ * Subflags for GTF_accept_transfer:
195
+ *  GTF_transfer_committed: Xen sets this flag to indicate that it is committed
196
+ *      to transferring ownership of a page frame. When a guest sees this flag
197
+ *      it must /not/ modify the grant entry until GTF_transfer_completed is
198
+ *      set by Xen.
199
+ *  GTF_transfer_completed: It is safe for the guest to spin-wait on this flag
200
+ *      after reading GTF_transfer_committed. Xen will always write the frame
201
+ *      address, followed by ORing this flag, in a timely manner.
202
+ */
203
+#define _GTF_transfer_committed (2)
204
+#define GTF_transfer_committed  (1U<<_GTF_transfer_committed)
205
+#define _GTF_transfer_completed (3)
206
+#define GTF_transfer_completed  (1U<<_GTF_transfer_completed)
207
+
208
+/*
209
+ * Version 2 grant table entries.  These fulfil the same role as
210
+ * version 1 entries, but can represent more complicated operations.
211
+ * Any given domain will have either a version 1 or a version 2 table,
212
+ * and every entry in the table will be the same version.
213
+ *
214
+ * The interface by which domains use grant references does not depend
215
+ * on the grant table version in use by the other domain.
216
+ */
217
+#if __XEN_INTERFACE_VERSION__ >= 0x0003020a
218
+/*
219
+ * Version 1 and version 2 grant entries share a common prefix.  The
220
+ * fields of the prefix are documented as part of struct
221
+ * grant_entry_v1.
222
+ */
223
+struct grant_entry_header {
224
+    uint16_t flags;
225
+    domid_t  domid;
226
+};
227
+typedef struct grant_entry_header grant_entry_header_t;
228
+
229
+/*
230
+ * Version 2 of the grant entry structure.
231
+ */
232
+union grant_entry_v2 {
233
+    grant_entry_header_t hdr;
234
+
235
+    /*
236
+     * This member is used for V1-style full page grants, where either:
237
+     *
238
+     * -- hdr.type is GTF_accept_transfer, or
239
+     * -- hdr.type is GTF_permit_access and GTF_sub_page is not set.
240
+     *
241
+     * In that case, the frame field has the same semantics as the
242
+     * field of the same name in the V1 entry structure.
243
+     */
244
+    struct {
245
+        grant_entry_header_t hdr;
246
+        uint32_t pad0;
247
+        uint64_t frame;
248
+    } full_page;
249
+
250
+    /*
251
+     * If the grant type is GTF_grant_access and GTF_sub_page is set,
252
+     * @domid is allowed to access bytes [@page_off,@page_off+@length)
253
+     * in frame @frame.
254
+     */
255
+    struct {
256
+        grant_entry_header_t hdr;
257
+        uint16_t page_off;
258
+        uint16_t length;
259
+        uint64_t frame;
260
+    } sub_page;
261
+
262
+    /*
263
+     * If the grant is GTF_transitive, @domid is allowed to use the
264
+     * grant @gref in domain @trans_domid, as if it was the local
265
+     * domain.  Obviously, the transitive access must be compatible
266
+     * with the original grant.
267
+     *
268
+     * The current version of Xen does not allow transitive grants
269
+     * to be mapped.
270
+     */
271
+    struct {
272
+        grant_entry_header_t hdr;
273
+        domid_t trans_domid;
274
+        uint16_t pad0;
275
+        grant_ref_t gref;
276
+    } transitive;
277
+
278
+    uint32_t __spacer[4]; /* Pad to a power of two */
279
+};
280
+typedef union grant_entry_v2 grant_entry_v2_t;
281
+
282
+typedef uint16_t grant_status_t;
283
+
284
+#endif /* __XEN_INTERFACE_VERSION__ */
285
+
286
+/***********************************
287
+ * GRANT TABLE QUERIES AND USES
288
+ */
289
+
290
+/* ` enum neg_errnoval
291
+ * ` HYPERVISOR_grant_table_op(enum grant_table_op cmd,
292
+ * `                           void *args,
293
+ * `                           unsigned int count)
294
+ * `
295
+ *
296
+ * @args points to an array of a per-command data structure. The array
297
+ * has @count members
298
+ */
299
+
300
+/* ` enum grant_table_op { // GNTTABOP_* => struct gnttab_* */
301
+#define GNTTABOP_map_grant_ref        0
302
+#define GNTTABOP_unmap_grant_ref      1
303
+#define GNTTABOP_setup_table          2
304
+#define GNTTABOP_dump_table           3
305
+#define GNTTABOP_transfer             4
306
+#define GNTTABOP_copy                 5
307
+#define GNTTABOP_query_size           6
308
+#define GNTTABOP_unmap_and_replace    7
309
+#if __XEN_INTERFACE_VERSION__ >= 0x0003020a
310
+#define GNTTABOP_set_version          8
311
+#define GNTTABOP_get_status_frames    9
312
+#define GNTTABOP_get_version          10
313
+#define GNTTABOP_swap_grant_ref	      11
314
+#endif /* __XEN_INTERFACE_VERSION__ */
315
+/* ` } */
316
+
317
+/*
318
+ * Handle to track a mapping created via a grant reference.
319
+ */
320
+typedef uint32_t grant_handle_t;
321
+
322
+/*
323
+ * GNTTABOP_map_grant_ref: Map the grant entry (<dom>,<ref>) for access
324
+ * by devices and/or host CPUs. If successful, <handle> is a tracking number
325
+ * that must be presented later to destroy the mapping(s). On error, <handle>
326
+ * is a negative status code.
327
+ * NOTES:
328
+ *  1. If GNTMAP_device_map is specified then <dev_bus_addr> is the address
329
+ *     via which I/O devices may access the granted frame.
330
+ *  2. If GNTMAP_host_map is specified then a mapping will be added at
331
+ *     either a host virtual address in the current address space, or at
332
+ *     a PTE at the specified machine address.  The type of mapping to
333
+ *     perform is selected through the GNTMAP_contains_pte flag, and the
334
+ *     address is specified in <host_addr>.
335
+ *  3. Mappings should only be destroyed via GNTTABOP_unmap_grant_ref. If a
336
+ *     host mapping is destroyed by other means then it is *NOT* guaranteed
337
+ *     to be accounted to the correct grant reference!
338
+ */
339
+struct gnttab_map_grant_ref {
340
+    /* IN parameters. */
341
+    uint64_t host_addr;
342
+    uint32_t flags;               /* GNTMAP_* */
343
+    grant_ref_t ref;
344
+    domid_t  dom;
345
+    /* OUT parameters. */
346
+    int16_t  status;              /* => enum grant_status */
347
+    grant_handle_t handle;
348
+    uint64_t dev_bus_addr;
349
+};
350
+typedef struct gnttab_map_grant_ref gnttab_map_grant_ref_t;
351
+DEFINE_XEN_GUEST_HANDLE(gnttab_map_grant_ref_t);
352
+
353
+/*
354
+ * GNTTABOP_unmap_grant_ref: Destroy one or more grant-reference mappings
355
+ * tracked by <handle>. If <host_addr> or <dev_bus_addr> is zero, that
356
+ * field is ignored. If non-zero, they must refer to a device/host mapping
357
+ * that is tracked by <handle>
358
+ * NOTES:
359
+ *  1. The call may fail in an undefined manner if either mapping is not
360
+ *     tracked by <handle>.
361
+ *  3. After executing a batch of unmaps, it is guaranteed that no stale
362
+ *     mappings will remain in the device or host TLBs.
363
+ */
364
+struct gnttab_unmap_grant_ref {
365
+    /* IN parameters. */
366
+    uint64_t host_addr;
367
+    uint64_t dev_bus_addr;
368
+    grant_handle_t handle;
369
+    /* OUT parameters. */
370
+    int16_t  status;              /* => enum grant_status */
371
+};
372
+typedef struct gnttab_unmap_grant_ref gnttab_unmap_grant_ref_t;
373
+DEFINE_XEN_GUEST_HANDLE(gnttab_unmap_grant_ref_t);
374
+
375
+/*
376
+ * GNTTABOP_setup_table: Set up a grant table for <dom> comprising at least
377
+ * <nr_frames> pages. The frame addresses are written to the <frame_list>.
378
+ * Only <nr_frames> addresses are written, even if the table is larger.
379
+ * NOTES:
380
+ *  1. <dom> may be specified as DOMID_SELF.
381
+ *  2. Only a sufficiently-privileged domain may specify <dom> != DOMID_SELF.
382
+ *  3. Xen may not support more than a single grant-table page per domain.
383
+ */
384
+struct gnttab_setup_table {
385
+    /* IN parameters. */
386
+    domid_t  dom;
387
+    uint32_t nr_frames;
388
+    /* OUT parameters. */
389
+    int16_t  status;              /* => enum grant_status */
390
+#if __XEN_INTERFACE_VERSION__ < 0x00040300
391
+    XEN_GUEST_HANDLE(ulong) frame_list;
392
+#else
393
+    XEN_GUEST_HANDLE(xen_pfn_t) frame_list;
394
+#endif
395
+};
396
+typedef struct gnttab_setup_table gnttab_setup_table_t;
397
+DEFINE_XEN_GUEST_HANDLE(gnttab_setup_table_t);
398
+
399
+/*
400
+ * GNTTABOP_dump_table: Dump the contents of the grant table to the
401
+ * xen console. Debugging use only.
402
+ */
403
+struct gnttab_dump_table {
404
+    /* IN parameters. */
405
+    domid_t dom;
406
+    /* OUT parameters. */
407
+    int16_t status;               /* => enum grant_status */
408
+};
409
+typedef struct gnttab_dump_table gnttab_dump_table_t;
410
+DEFINE_XEN_GUEST_HANDLE(gnttab_dump_table_t);
411
+
412
+/*
413
+ * GNTTABOP_transfer_grant_ref: Transfer <frame> to a foreign domain. The
414
+ * foreign domain has previously registered its interest in the transfer via
415
+ * <domid, ref>.
416
+ *
417
+ * Note that, even if the transfer fails, the specified page no longer belongs
418
+ * to the calling domain *unless* the error is GNTST_bad_page.
419
+ */
420
+struct gnttab_transfer {
421
+    /* IN parameters. */
422
+    xen_pfn_t     mfn;
423
+    domid_t       domid;
424
+    grant_ref_t   ref;
425
+    /* OUT parameters. */
426
+    int16_t       status;
427
+};
428
+typedef struct gnttab_transfer gnttab_transfer_t;
429
+DEFINE_XEN_GUEST_HANDLE(gnttab_transfer_t);
430
+
431
+
432
+/*
433
+ * GNTTABOP_copy: Hypervisor based copy
434
+ * source and destinations can be eithers MFNs or, for foreign domains,
435
+ * grant references. the foreign domain has to grant read/write access
436
+ * in its grant table.
437
+ *
438
+ * The flags specify what type source and destinations are (either MFN
439
+ * or grant reference).
440
+ *
441
+ * Note that this can also be used to copy data between two domains
442
+ * via a third party if the source and destination domains had previously
443
+ * grant appropriate access to their pages to the third party.
444
+ *
445
+ * source_offset specifies an offset in the source frame, dest_offset
446
+ * the offset in the target frame and  len specifies the number of
447
+ * bytes to be copied.
448
+ */
449
+
450
+#define _GNTCOPY_source_gref      (0)
451
+#define GNTCOPY_source_gref       (1<<_GNTCOPY_source_gref)
452
+#define _GNTCOPY_dest_gref        (1)
453
+#define GNTCOPY_dest_gref         (1<<_GNTCOPY_dest_gref)
454
+
455
+struct gnttab_copy {
456
+    /* IN parameters. */
457
+    struct {
458
+        union {
459
+            grant_ref_t ref;
460
+            xen_pfn_t   gmfn;
461
+        } u;
462
+        domid_t  domid;
463
+        uint16_t offset;
464
+    } source, dest;
465
+    uint16_t      len;
466
+    uint16_t      flags;          /* GNTCOPY_* */
467
+    /* OUT parameters. */
468
+    int16_t       status;
469
+};
470
+typedef struct gnttab_copy  gnttab_copy_t;
471
+DEFINE_XEN_GUEST_HANDLE(gnttab_copy_t);
472
+
473
+/*
474
+ * GNTTABOP_query_size: Query the current and maximum sizes of the shared
475
+ * grant table.
476
+ * NOTES:
477
+ *  1. <dom> may be specified as DOMID_SELF.
478
+ *  2. Only a sufficiently-privileged domain may specify <dom> != DOMID_SELF.
479
+ */
480
+struct gnttab_query_size {
481
+    /* IN parameters. */
482
+    domid_t  dom;
483
+    /* OUT parameters. */
484
+    uint32_t nr_frames;
485
+    uint32_t max_nr_frames;
486
+    int16_t  status;              /* => enum grant_status */
487
+};
488
+typedef struct gnttab_query_size gnttab_query_size_t;
489
+DEFINE_XEN_GUEST_HANDLE(gnttab_query_size_t);
490
+
491
+/*
492
+ * GNTTABOP_unmap_and_replace: Destroy one or more grant-reference mappings
493
+ * tracked by <handle> but atomically replace the page table entry with one
494
+ * pointing to the machine address under <new_addr>.  <new_addr> will be
495
+ * redirected to the null entry.
496
+ * NOTES:
497
+ *  1. The call may fail in an undefined manner if either mapping is not
498
+ *     tracked by <handle>.
499
+ *  2. After executing a batch of unmaps, it is guaranteed that no stale
500
+ *     mappings will remain in the device or host TLBs.
501
+ */
502
+struct gnttab_unmap_and_replace {
503
+    /* IN parameters. */
504
+    uint64_t host_addr;
505
+    uint64_t new_addr;
506
+    grant_handle_t handle;
507
+    /* OUT parameters. */
508
+    int16_t  status;              /* => enum grant_status */
509
+};
510
+typedef struct gnttab_unmap_and_replace gnttab_unmap_and_replace_t;
511
+DEFINE_XEN_GUEST_HANDLE(gnttab_unmap_and_replace_t);
512
+
513
+#if __XEN_INTERFACE_VERSION__ >= 0x0003020a
514
+/*
515
+ * GNTTABOP_set_version: Request a particular version of the grant
516
+ * table shared table structure.  This operation can only be performed
517
+ * once in any given domain.  It must be performed before any grants
518
+ * are activated; otherwise, the domain will be stuck with version 1.
519
+ * The only defined versions are 1 and 2.
520
+ */
521
+struct gnttab_set_version {
522
+    /* IN/OUT parameters */
523
+    uint32_t version;
524
+};
525
+typedef struct gnttab_set_version gnttab_set_version_t;
526
+DEFINE_XEN_GUEST_HANDLE(gnttab_set_version_t);
527
+
528
+
529
+/*
530
+ * GNTTABOP_get_status_frames: Get the list of frames used to store grant
531
+ * status for <dom>. In grant format version 2, the status is separated
532
+ * from the other shared grant fields to allow more efficient synchronization
533
+ * using barriers instead of atomic cmpexch operations.
534
+ * <nr_frames> specify the size of vector <frame_list>.
535
+ * The frame addresses are returned in the <frame_list>.
536
+ * Only <nr_frames> addresses are returned, even if the table is larger.
537
+ * NOTES:
538
+ *  1. <dom> may be specified as DOMID_SELF.
539
+ *  2. Only a sufficiently-privileged domain may specify <dom> != DOMID_SELF.
540
+ */
541
+struct gnttab_get_status_frames {
542
+    /* IN parameters. */
543
+    uint32_t nr_frames;
544
+    domid_t  dom;
545
+    /* OUT parameters. */
546
+    int16_t  status;              /* => enum grant_status */
547
+    XEN_GUEST_HANDLE(uint64_t) frame_list;
548
+};
549
+typedef struct gnttab_get_status_frames gnttab_get_status_frames_t;
550
+DEFINE_XEN_GUEST_HANDLE(gnttab_get_status_frames_t);
551
+
552
+/*
553
+ * GNTTABOP_get_version: Get the grant table version which is in
554
+ * effect for domain <dom>.
555
+ */
556
+struct gnttab_get_version {
557
+    /* IN parameters */
558
+    domid_t dom;
559
+    uint16_t pad;
560
+    /* OUT parameters */
561
+    uint32_t version;
562
+};
563
+typedef struct gnttab_get_version gnttab_get_version_t;
564
+DEFINE_XEN_GUEST_HANDLE(gnttab_get_version_t);
565
+
566
+/*
567
+ * GNTTABOP_swap_grant_ref: Swap the contents of two grant entries.
568
+ */
569
+struct gnttab_swap_grant_ref {
570
+    /* IN parameters */
571
+    grant_ref_t ref_a;
572
+    grant_ref_t ref_b;
573
+    /* OUT parameters */
574
+    int16_t status;             /* => enum grant_status */
575
+};
576
+typedef struct gnttab_swap_grant_ref gnttab_swap_grant_ref_t;
577
+DEFINE_XEN_GUEST_HANDLE(gnttab_swap_grant_ref_t);
578
+
579
+#endif /* __XEN_INTERFACE_VERSION__ */
580
+
581
+/*
582
+ * Bitfield values for gnttab_map_grant_ref.flags.
583
+ */
584
+ /* Map the grant entry for access by I/O devices. */
585
+#define _GNTMAP_device_map      (0)
586
+#define GNTMAP_device_map       (1<<_GNTMAP_device_map)
587
+ /* Map the grant entry for access by host CPUs. */
588
+#define _GNTMAP_host_map        (1)
589
+#define GNTMAP_host_map         (1<<_GNTMAP_host_map)
590
+ /* Accesses to the granted frame will be restricted to read-only access. */
591
+#define _GNTMAP_readonly        (2)
592
+#define GNTMAP_readonly         (1<<_GNTMAP_readonly)
593
+ /*
594
+  * GNTMAP_host_map subflag:
595
+  *  0 => The host mapping is usable only by the guest OS.
596
+  *  1 => The host mapping is usable by guest OS + current application.
597
+  */
598
+#define _GNTMAP_application_map (3)
599
+#define GNTMAP_application_map  (1<<_GNTMAP_application_map)
600
+
601
+ /*
602
+  * GNTMAP_contains_pte subflag:
603
+  *  0 => This map request contains a host virtual address.
604
+  *  1 => This map request contains the machine addess of the PTE to update.
605
+  */
606
+#define _GNTMAP_contains_pte    (4)
607
+#define GNTMAP_contains_pte     (1<<_GNTMAP_contains_pte)
608
+
609
+#define _GNTMAP_can_fail        (5)
610
+#define GNTMAP_can_fail         (1<<_GNTMAP_can_fail)
611
+
612
+/*
613
+ * Bits to be placed in guest kernel available PTE bits (architecture
614
+ * dependent; only supported when XENFEAT_gnttab_map_avail_bits is set).
615
+ */
616
+#define _GNTMAP_guest_avail0    (16)
617
+#define GNTMAP_guest_avail_mask ((uint32_t)~0 << _GNTMAP_guest_avail0)
618
+
619
+/*
620
+ * Values for error status returns. All errors are -ve.
621
+ */
622
+/* ` enum grant_status { */
623
+#define GNTST_okay             (0)  /* Normal return.                        */
624
+#define GNTST_general_error    (-1) /* General undefined error.              */
625
+#define GNTST_bad_domain       (-2) /* Unrecognsed domain id.                */
626
+#define GNTST_bad_gntref       (-3) /* Unrecognised or inappropriate gntref. */
627
+#define GNTST_bad_handle       (-4) /* Unrecognised or inappropriate handle. */
628
+#define GNTST_bad_virt_addr    (-5) /* Inappropriate virtual address to map. */
629
+#define GNTST_bad_dev_addr     (-6) /* Inappropriate device address to unmap.*/
630
+#define GNTST_no_device_space  (-7) /* Out of space in I/O MMU.              */
631
+#define GNTST_permission_denied (-8) /* Not enough privilege for operation.  */
632
+#define GNTST_bad_page         (-9) /* Specified page was invalid for op.    */
633
+#define GNTST_bad_copy_arg    (-10) /* copy arguments cross page boundary.   */
634
+#define GNTST_address_too_big (-11) /* transfer page address too large.      */
635
+#define GNTST_eagain          (-12) /* Operation not done; try again.        */
636
+/* ` } */
637
+
638
+#define GNTTABOP_error_msgs {                   \
639
+    "okay",                                     \
640
+    "undefined error",                          \
641
+    "unrecognised domain id",                   \
642
+    "invalid grant reference",                  \
643
+    "invalid mapping handle",                   \
644
+    "invalid virtual address",                  \
645
+    "invalid device address",                   \
646
+    "no spare translation slot in the I/O MMU", \
647
+    "permission denied",                        \
648
+    "bad page",                                 \
649
+    "copy arguments cross page boundary",       \
650
+    "page address size too large",              \
651
+    "operation not done; try again"             \
652
+}
653
+
654
+#endif /* __XEN_PUBLIC_GRANT_TABLE_H__ */
655
+
656
+/*
657
+ * Local variables:
658
+ * mode: C
659
+ * c-file-style: "BSD"
660
+ * c-basic-offset: 4
661
+ * tab-width: 4
662
+ * indent-tabs-mode: nil
663
+ * End:
664
+ */

+ 384
- 0
src/include/xen/hvm/hvm_op.h View File

@@ -0,0 +1,384 @@
1
+/*
2
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
3
+ * of this software and associated documentation files (the "Software"), to
4
+ * deal in the Software without restriction, including without limitation the
5
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
6
+ * sell copies of the Software, and to permit persons to whom the Software is
7
+ * furnished to do so, subject to the following conditions:
8
+ *
9
+ * The above copyright notice and this permission notice shall be included in
10
+ * all copies or substantial portions of the Software.
11
+ *
12
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
17
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
18
+ * DEALINGS IN THE SOFTWARE.
19
+ */
20
+
21
+#ifndef __XEN_PUBLIC_HVM_HVM_OP_H__
22
+#define __XEN_PUBLIC_HVM_HVM_OP_H__
23
+
24
+FILE_LICENCE ( MIT );
25
+
26
+#include "../xen.h"
27
+#include "../trace.h"
28
+#include "../event_channel.h"
29
+
30
+/* Get/set subcommands: extra argument == pointer to xen_hvm_param struct. */
31
+#define HVMOP_set_param           0
32
+#define HVMOP_get_param           1
33
+struct xen_hvm_param {
34
+    domid_t  domid;    /* IN */
35
+    uint32_t index;    /* IN */
36
+    uint64_t value;    /* IN/OUT */
37
+};
38
+typedef struct xen_hvm_param xen_hvm_param_t;
39
+DEFINE_XEN_GUEST_HANDLE(xen_hvm_param_t);
40
+
41
+/* Set the logical level of one of a domain's PCI INTx wires. */
42
+#define HVMOP_set_pci_intx_level  2
43
+struct xen_hvm_set_pci_intx_level {
44
+    /* Domain to be updated. */
45
+    domid_t  domid;
46
+    /* PCI INTx identification in PCI topology (domain:bus:device:intx). */
47
+    uint8_t  domain, bus, device, intx;
48
+    /* Assertion level (0 = unasserted, 1 = asserted). */
49
+    uint8_t  level;
50
+};
51
+typedef struct xen_hvm_set_pci_intx_level xen_hvm_set_pci_intx_level_t;
52
+DEFINE_XEN_GUEST_HANDLE(xen_hvm_set_pci_intx_level_t);
53
+
54
+/* Set the logical level of one of a domain's ISA IRQ wires. */
55
+#define HVMOP_set_isa_irq_level   3
56
+struct xen_hvm_set_isa_irq_level {
57
+    /* Domain to be updated. */
58
+    domid_t  domid;
59
+    /* ISA device identification, by ISA IRQ (0-15). */
60
+    uint8_t  isa_irq;
61
+    /* Assertion level (0 = unasserted, 1 = asserted). */
62
+    uint8_t  level;
63
+};
64
+typedef struct xen_hvm_set_isa_irq_level xen_hvm_set_isa_irq_level_t;
65
+DEFINE_XEN_GUEST_HANDLE(xen_hvm_set_isa_irq_level_t);
66
+
67
+#define HVMOP_set_pci_link_route  4
68
+struct xen_hvm_set_pci_link_route {
69
+    /* Domain to be updated. */
70
+    domid_t  domid;
71
+    /* PCI link identifier (0-3). */
72
+    uint8_t  link;
73
+    /* ISA IRQ (1-15), or 0 (disable link). */
74
+    uint8_t  isa_irq;
75
+};
76
+typedef struct xen_hvm_set_pci_link_route xen_hvm_set_pci_link_route_t;
77
+DEFINE_XEN_GUEST_HANDLE(xen_hvm_set_pci_link_route_t);
78
+
79
+/* Flushes all VCPU TLBs: @arg must be NULL. */
80
+#define HVMOP_flush_tlbs          5
81
+
82
+typedef enum {
83
+    HVMMEM_ram_rw,             /* Normal read/write guest RAM */
84
+    HVMMEM_ram_ro,             /* Read-only; writes are discarded */
85
+    HVMMEM_mmio_dm,            /* Reads and write go to the device model */
86
+} hvmmem_type_t;
87
+
88
+/* Following tools-only interfaces may change in future. */
89
+#if defined(__XEN__) || defined(__XEN_TOOLS__)
90
+
91
+/* Track dirty VRAM. */
92
+#define HVMOP_track_dirty_vram    6
93
+struct xen_hvm_track_dirty_vram {
94
+    /* Domain to be tracked. */
95
+    domid_t  domid;
96
+    /* Number of pages to track. */
97
+    uint32_t nr;
98
+    /* First pfn to track. */
99
+    uint64_aligned_t first_pfn;
100
+    /* OUT variable. */
101
+    /* Dirty bitmap buffer. */
102
+    XEN_GUEST_HANDLE_64(uint8) dirty_bitmap;
103
+};
104
+typedef struct xen_hvm_track_dirty_vram xen_hvm_track_dirty_vram_t;
105
+DEFINE_XEN_GUEST_HANDLE(xen_hvm_track_dirty_vram_t);
106
+
107
+/* Notify that some pages got modified by the Device Model. */
108
+#define HVMOP_modified_memory    7
109
+struct xen_hvm_modified_memory {
110
+    /* Domain to be updated. */
111
+    domid_t  domid;
112
+    /* Number of pages. */
113
+    uint32_t nr;
114
+    /* First pfn. */
115
+    uint64_aligned_t first_pfn;
116
+};
117
+typedef struct xen_hvm_modified_memory xen_hvm_modified_memory_t;
118
+DEFINE_XEN_GUEST_HANDLE(xen_hvm_modified_memory_t);
119
+
120
+#define HVMOP_set_mem_type    8
121
+/* Notify that a region of memory is to be treated in a specific way. */
122
+struct xen_hvm_set_mem_type {
123
+    /* Domain to be updated. */
124
+    domid_t domid;
125
+    /* Memory type */
126
+    uint16_t hvmmem_type;
127
+    /* Number of pages. */
128
+    uint32_t nr;
129
+    /* First pfn. */
130
+    uint64_aligned_t first_pfn;
131
+};
132
+typedef struct xen_hvm_set_mem_type xen_hvm_set_mem_type_t;
133
+DEFINE_XEN_GUEST_HANDLE(xen_hvm_set_mem_type_t);
134
+
135
+#endif /* defined(__XEN__) || defined(__XEN_TOOLS__) */
136
+
137
+/* Hint from PV drivers for pagetable destruction. */
138
+#define HVMOP_pagetable_dying        9
139
+struct xen_hvm_pagetable_dying {
140
+    /* Domain with a pagetable about to be destroyed. */
141
+    domid_t  domid;
142
+    uint16_t pad[3]; /* align next field on 8-byte boundary */
143
+    /* guest physical address of the toplevel pagetable dying */
144
+    uint64_t gpa;
145
+};
146
+typedef struct xen_hvm_pagetable_dying xen_hvm_pagetable_dying_t;
147
+DEFINE_XEN_GUEST_HANDLE(xen_hvm_pagetable_dying_t);
148
+
149
+/* Get the current Xen time, in nanoseconds since system boot. */
150
+#define HVMOP_get_time              10
151
+struct xen_hvm_get_time {
152
+    uint64_t now;      /* OUT */
153
+};
154
+typedef struct xen_hvm_get_time xen_hvm_get_time_t;
155
+DEFINE_XEN_GUEST_HANDLE(xen_hvm_get_time_t);
156
+
157
+#define HVMOP_xentrace              11
158
+struct xen_hvm_xentrace {
159
+    uint16_t event, extra_bytes;
160
+    uint8_t extra[TRACE_EXTRA_MAX * sizeof(uint32_t)];
161
+};
162
+typedef struct xen_hvm_xentrace xen_hvm_xentrace_t;
163
+DEFINE_XEN_GUEST_HANDLE(xen_hvm_xentrace_t);
164
+
165
+/* Following tools-only interfaces may change in future. */
166
+#if defined(__XEN__) || defined(__XEN_TOOLS__)
167
+
168
+/* Deprecated by XENMEM_access_op_set_access */
169
+#define HVMOP_set_mem_access        12
170
+
171
+/* Deprecated by XENMEM_access_op_get_access */
172
+#define HVMOP_get_mem_access        13
173
+
174
+#define HVMOP_inject_trap            14
175
+/* Inject a trap into a VCPU, which will get taken up on the next
176
+ * scheduling of it. Note that the caller should know enough of the
177
+ * state of the CPU before injecting, to know what the effect of
178
+ * injecting the trap will be.
179
+ */
180
+struct xen_hvm_inject_trap {
181
+    /* Domain to be queried. */
182
+    domid_t domid;
183
+    /* VCPU */
184
+    uint32_t vcpuid;
185
+    /* Vector number */
186
+    uint32_t vector;
187
+    /* Trap type (HVMOP_TRAP_*) */
188
+    uint32_t type;
189
+/* NB. This enumeration precisely matches hvm.h:X86_EVENTTYPE_* */
190
+# define HVMOP_TRAP_ext_int    0 /* external interrupt */
191
+# define HVMOP_TRAP_nmi        2 /* nmi */
192
+# define HVMOP_TRAP_hw_exc     3 /* hardware exception */
193
+# define HVMOP_TRAP_sw_int     4 /* software interrupt (CD nn) */
194
+# define HVMOP_TRAP_pri_sw_exc 5 /* ICEBP (F1) */
195
+# define HVMOP_TRAP_sw_exc     6 /* INT3 (CC), INTO (CE) */
196
+    /* Error code, or ~0u to skip */
197
+    uint32_t error_code;
198
+    /* Intruction length */
199
+    uint32_t insn_len;
200
+    /* CR2 for page faults */
201
+    uint64_aligned_t cr2;
202
+};
203
+typedef struct xen_hvm_inject_trap xen_hvm_inject_trap_t;
204
+DEFINE_XEN_GUEST_HANDLE(xen_hvm_inject_trap_t);
205
+
206
+#endif /* defined(__XEN__) || defined(__XEN_TOOLS__) */
207
+
208
+#define HVMOP_get_mem_type    15
209
+/* Return hvmmem_type_t for the specified pfn. */
210
+struct xen_hvm_get_mem_type {
211
+    /* Domain to be queried. */
212
+    domid_t domid;
213
+    /* OUT variable. */
214
+    uint16_t mem_type;
215
+    uint16_t pad[2]; /* align next field on 8-byte boundary */
216
+    /* IN variable. */
217
+    uint64_t pfn;
218
+};
219
+typedef struct xen_hvm_get_mem_type xen_hvm_get_mem_type_t;
220
+DEFINE_XEN_GUEST_HANDLE(xen_hvm_get_mem_type_t);
221
+
222
+/* Following tools-only interfaces may change in future. */
223
+#if defined(__XEN__) || defined(__XEN_TOOLS__)
224
+
225
+/* MSI injection for emulated devices */
226
+#define HVMOP_inject_msi         16
227
+struct xen_hvm_inject_msi {
228
+    /* Domain to be injected */
229
+    domid_t   domid;
230
+    /* Data -- lower 32 bits */
231
+    uint32_t  data;
232
+    /* Address (0xfeexxxxx) */
233
+    uint64_t  addr;
234
+};
235
+typedef struct xen_hvm_inject_msi xen_hvm_inject_msi_t;
236
+DEFINE_XEN_GUEST_HANDLE(xen_hvm_inject_msi_t);
237
+
238
+/*
239
+ * IOREQ Servers
240
+ *
241
+ * The interface between an I/O emulator an Xen is called an IOREQ Server.
242
+ * A domain supports a single 'legacy' IOREQ Server which is instantiated if
243
+ * parameter...
244
+ *
245
+ * HVM_PARAM_IOREQ_PFN is read (to get the gmfn containing the synchronous
246
+ * ioreq structures), or...
247
+ * HVM_PARAM_BUFIOREQ_PFN is read (to get the gmfn containing the buffered
248
+ * ioreq ring), or...
249
+ * HVM_PARAM_BUFIOREQ_EVTCHN is read (to get the event channel that Xen uses
250
+ * to request buffered I/O emulation).
251
+ *
252
+ * The following hypercalls facilitate the creation of IOREQ Servers for
253
+ * 'secondary' emulators which are invoked to implement port I/O, memory, or
254
+ * PCI config space ranges which they explicitly register.
255
+ */
256
+
257
+typedef uint16_t ioservid_t;
258
+
259
+/*
260
+ * HVMOP_create_ioreq_server: Instantiate a new IOREQ Server for a secondary
261
+ *                            emulator servicing domain <domid>.
262
+ *
263
+ * The <id> handed back is unique for <domid>. If <handle_bufioreq> is zero
264
+ * the buffered ioreq ring will not be allocated and hence all emulation
265
+ * requestes to this server will be synchronous.
266
+ */
267
+#define HVMOP_create_ioreq_server 17
268
+struct xen_hvm_create_ioreq_server {
269
+    domid_t domid;           /* IN - domain to be serviced */
270
+    uint8_t handle_bufioreq; /* IN - should server handle buffered ioreqs */
271
+    ioservid_t id;           /* OUT - server id */
272
+};
273
+typedef struct xen_hvm_create_ioreq_server xen_hvm_create_ioreq_server_t;
274
+DEFINE_XEN_GUEST_HANDLE(xen_hvm_create_ioreq_server_t);
275
+
276
+/*
277
+ * HVMOP_get_ioreq_server_info: Get all the information necessary to access
278
+ *                              IOREQ Server <id>.
279
+ *
280
+ * The emulator needs to map the synchronous ioreq structures and buffered
281
+ * ioreq ring (if it exists) that Xen uses to request emulation. These are
282
+ * hosted in domain <domid>'s gmfns <ioreq_pfn> and <bufioreq_pfn>
283
+ * respectively. In addition, if the IOREQ Server is handling buffered
284
+ * emulation requests, the emulator needs to bind to event channel
285
+ * <bufioreq_port> to listen for them. (The event channels used for
286
+ * synchronous emulation requests are specified in the per-CPU ioreq
287
+ * structures in <ioreq_pfn>).
288
+ * If the IOREQ Server is not handling buffered emulation requests then the
289
+ * values handed back in <bufioreq_pfn> and <bufioreq_port> will both be 0.
290
+ */
291
+#define HVMOP_get_ioreq_server_info 18
292
+struct xen_hvm_get_ioreq_server_info {
293
+    domid_t domid;                 /* IN - domain to be serviced */
294
+    ioservid_t id;                 /* IN - server id */
295
+    evtchn_port_t bufioreq_port;   /* OUT - buffered ioreq port */
296
+    uint64_aligned_t ioreq_pfn;    /* OUT - sync ioreq pfn */
297
+    uint64_aligned_t bufioreq_pfn; /* OUT - buffered ioreq pfn */
298
+};
299
+typedef struct xen_hvm_get_ioreq_server_info xen_hvm_get_ioreq_server_info_t;
300
+DEFINE_XEN_GUEST_HANDLE(xen_hvm_get_ioreq_server_info_t);
301
+
302
+/*
303
+ * HVM_map_io_range_to_ioreq_server: Register an I/O range of domain <domid>
304
+ *                                   for emulation by the client of IOREQ
305
+ *                                   Server <id>
306
+ * HVM_unmap_io_range_from_ioreq_server: Deregister an I/O range of <domid>
307
+ *                                       for emulation by the client of IOREQ
308
+ *                                       Server <id>
309
+ *
310
+ * There are three types of I/O that can be emulated: port I/O, memory accesses
311
+ * and PCI config space accesses. The <type> field denotes which type of range
312
+ * the <start> and <end> (inclusive) fields are specifying.
313
+ * PCI config space ranges are specified by segment/bus/device/function values
314
+ * which should be encoded using the HVMOP_PCI_SBDF helper macro below.
315
+ *
316
+ * NOTE: unless an emulation request falls entirely within a range mapped
317
+ * by a secondary emulator, it will not be passed to that emulator.
318
+ */
319
+#define HVMOP_map_io_range_to_ioreq_server 19
320
+#define HVMOP_unmap_io_range_from_ioreq_server 20
321
+struct xen_hvm_io_range {
322
+    domid_t domid;               /* IN - domain to be serviced */
323
+    ioservid_t id;               /* IN - server id */
324
+    uint32_t type;               /* IN - type of range */
325
+# define HVMOP_IO_RANGE_PORT   0 /* I/O port range */
326
+# define HVMOP_IO_RANGE_MEMORY 1 /* MMIO range */
327
+# define HVMOP_IO_RANGE_PCI    2 /* PCI segment/bus/dev/func range */
328
+    uint64_aligned_t start, end; /* IN - inclusive start and end of range */
329
+};
330
+typedef struct xen_hvm_io_range xen_hvm_io_range_t;
331
+DEFINE_XEN_GUEST_HANDLE(xen_hvm_io_range_t);
332
+
333
+#define HVMOP_PCI_SBDF(s,b,d,f)                 \
334
+	((((s) & 0xffff) << 16) |                   \
335
+	 (((b) & 0xff) << 8) |                      \
336
+	 (((d) & 0x1f) << 3) |                      \
337
+	 ((f) & 0x07))
338
+
339
+/*
340
+ * HVMOP_destroy_ioreq_server: Destroy the IOREQ Server <id> servicing domain
341
+ *                             <domid>.
342
+ *
343
+ * Any registered I/O ranges will be automatically deregistered.
344
+ */
345
+#define HVMOP_destroy_ioreq_server 21
346
+struct xen_hvm_destroy_ioreq_server {
347
+    domid_t domid; /* IN - domain to be serviced */
348
+    ioservid_t id; /* IN - server id */
349
+};
350
+typedef struct xen_hvm_destroy_ioreq_server xen_hvm_destroy_ioreq_server_t;
351
+DEFINE_XEN_GUEST_HANDLE(xen_hvm_destroy_ioreq_server_t);
352
+
353
+/*
354
+ * HVMOP_set_ioreq_server_state: Enable or disable the IOREQ Server <id> servicing
355
+ *                               domain <domid>.
356
+ *
357
+ * The IOREQ Server will not be passed any emulation requests until it is in the
358
+ * enabled state.
359
+ * Note that the contents of the ioreq_pfn and bufioreq_fn (see
360
+ * HVMOP_get_ioreq_server_info) are not meaningful until the IOREQ Server is in
361
+ * the enabled state.
362
+ */
363
+#define HVMOP_set_ioreq_server_state 22
364
+struct xen_hvm_set_ioreq_server_state {
365
+    domid_t domid;   /* IN - domain to be serviced */
366
+    ioservid_t id;   /* IN - server id */
367
+    uint8_t enabled; /* IN - enabled? */
368
+};
369
+typedef struct xen_hvm_set_ioreq_server_state xen_hvm_set_ioreq_server_state_t;
370
+DEFINE_XEN_GUEST_HANDLE(xen_hvm_set_ioreq_server_state_t);
371
+
372
+#endif /* defined(__XEN__) || defined(__XEN_TOOLS__) */
373
+
374
+#endif /* __XEN_PUBLIC_HVM_HVM_OP_H__ */
375
+
376
+/*
377
+ * Local variables:
378
+ * mode: C
379
+ * c-file-style: "BSD"
380
+ * c-basic-offset: 4
381
+ * tab-width: 4
382
+ * indent-tabs-mode: nil
383
+ * End:
384
+ */

+ 158
- 0
src/include/xen/hvm/params.h View File

@@ -0,0 +1,158 @@
1
+/*
2
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
3
+ * of this software and associated documentation files (the "Software"), to
4
+ * deal in the Software without restriction, including without limitation the
5
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
6
+ * sell copies of the Software, and to permit persons to whom the Software is
7
+ * furnished to do so, subject to the following conditions:
8
+ *
9
+ * The above copyright notice and this permission notice shall be included in
10
+ * all copies or substantial portions of the Software.
11
+ *
12
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
17
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
18
+ * DEALINGS IN THE SOFTWARE.
19
+ */
20
+
21
+#ifndef __XEN_PUBLIC_HVM_PARAMS_H__
22
+#define __XEN_PUBLIC_HVM_PARAMS_H__
23
+
24
+FILE_LICENCE ( MIT );
25
+
26
+#include "hvm_op.h"
27
+
28
+/*
29
+ * Parameter space for HVMOP_{set,get}_param.
30
+ */
31
+
32
+/*
33
+ * How should CPU0 event-channel notifications be delivered?
34
+ * val[63:56] == 0: val[55:0] is a delivery GSI (Global System Interrupt).
35
+ * val[63:56] == 1: val[55:0] is a delivery PCI INTx line, as follows:
36
+ *                  Domain = val[47:32], Bus  = val[31:16],
37
+ *                  DevFn  = val[15: 8], IntX = val[ 1: 0]
38
+ * val[63:56] == 2: val[7:0] is a vector number, check for
39
+ *                  XENFEAT_hvm_callback_vector to know if this delivery
40
+ *                  method is available.
41
+ * If val == 0 then CPU0 event-channel notifications are not delivered.
42
+ */
43
+#define HVM_PARAM_CALLBACK_IRQ 0
44
+
45
+/*
46
+ * These are not used by Xen. They are here for convenience of HVM-guest
47
+ * xenbus implementations.
48
+ */
49
+#define HVM_PARAM_STORE_PFN    1
50
+#define HVM_PARAM_STORE_EVTCHN 2
51
+
52
+#define HVM_PARAM_PAE_ENABLED  4
53
+
54
+#define HVM_PARAM_IOREQ_PFN    5
55
+
56
+#define HVM_PARAM_BUFIOREQ_PFN 6
57
+#define HVM_PARAM_BUFIOREQ_EVTCHN 26
58
+
59
+#if defined(__i386__) || defined(__x86_64__)
60
+
61
+/* Expose Viridian interfaces to this HVM guest? */
62
+#define HVM_PARAM_VIRIDIAN     9
63
+
64
+#endif
65
+
66
+/*
67
+ * Set mode for virtual timers (currently x86 only):
68
+ *  delay_for_missed_ticks (default):
69
+ *   Do not advance a vcpu's time beyond the correct delivery time for
70
+ *   interrupts that have been missed due to preemption. Deliver missed
71
+ *   interrupts when the vcpu is rescheduled and advance the vcpu's virtual
72
+ *   time stepwise for each one.
73
+ *  no_delay_for_missed_ticks:
74
+ *   As above, missed interrupts are delivered, but guest time always tracks
75
+ *   wallclock (i.e., real) time while doing so.
76
+ *  no_missed_ticks_pending:
77
+ *   No missed interrupts are held pending. Instead, to ensure ticks are
78
+ *   delivered at some non-zero rate, if we detect missed ticks then the
79
+ *   internal tick alarm is not disabled if the VCPU is preempted during the
80
+ *   next tick period.
81
+ *  one_missed_tick_pending:
82
+ *   Missed interrupts are collapsed together and delivered as one 'late tick'.
83
+ *   Guest time always tracks wallclock (i.e., real) time.
84
+ */
85
+#define HVM_PARAM_TIMER_MODE   10
86
+#define HVMPTM_delay_for_missed_ticks    0
87
+#define HVMPTM_no_delay_for_missed_ticks 1
88
+#define HVMPTM_no_missed_ticks_pending   2
89
+#define HVMPTM_one_missed_tick_pending   3
90
+
91
+/* Boolean: Enable virtual HPET (high-precision event timer)? (x86-only) */
92
+#define HVM_PARAM_HPET_ENABLED 11
93
+
94
+/* Identity-map page directory used by Intel EPT when CR0.PG=0. */
95
+#define HVM_PARAM_IDENT_PT     12
96
+
97
+/* Device Model domain, defaults to 0. */
98
+#define HVM_PARAM_DM_DOMAIN    13
99
+
100
+/* ACPI S state: currently support S0 and S3 on x86. */
101
+#define HVM_PARAM_ACPI_S_STATE 14
102
+
103
+/* TSS used on Intel when CR0.PE=0. */
104
+#define HVM_PARAM_VM86_TSS     15
105
+
106
+/* Boolean: Enable aligning all periodic vpts to reduce interrupts */
107
+#define HVM_PARAM_VPT_ALIGN    16
108
+
109
+/* Console debug shared memory ring and event channel */
110
+#define HVM_PARAM_CONSOLE_PFN    17
111
+#define HVM_PARAM_CONSOLE_EVTCHN 18
112
+
113
+/*
114
+ * Select location of ACPI PM1a and TMR control blocks. Currently two locations
115
+ * are supported, specified by version 0 or 1 in this parameter:
116
+ *   - 0: default, use the old addresses
117
+ *        PM1A_EVT == 0x1f40; PM1A_CNT == 0x1f44; PM_TMR == 0x1f48
118
+ *   - 1: use the new default qemu addresses
119
+ *        PM1A_EVT == 0xb000; PM1A_CNT == 0xb004; PM_TMR == 0xb008
120
+ * You can find these address definitions in <hvm/ioreq.h>
121
+ */
122
+#define HVM_PARAM_ACPI_IOPORTS_LOCATION 19
123
+
124
+/* Enable blocking memory events, async or sync (pause vcpu until response)
125
+ * onchangeonly indicates messages only on a change of value */
126
+#define HVM_PARAM_MEMORY_EVENT_CR0          20
127
+#define HVM_PARAM_MEMORY_EVENT_CR3          21
128
+#define HVM_PARAM_MEMORY_EVENT_CR4          22
129
+#define HVM_PARAM_MEMORY_EVENT_INT3         23
130
+#define HVM_PARAM_MEMORY_EVENT_SINGLE_STEP  25
131
+#define HVM_PARAM_MEMORY_EVENT_MSR          30
132
+
133
+#define HVMPME_MODE_MASK       (3 << 0)
134
+#define HVMPME_mode_disabled   0
135
+#define HVMPME_mode_async      1
136
+#define HVMPME_mode_sync       2
137
+#define HVMPME_onchangeonly    (1 << 2)
138
+
139
+/* Boolean: Enable nestedhvm (hvm only) */
140
+#define HVM_PARAM_NESTEDHVM    24
141
+
142
+/* Params for the mem event rings */
143
+#define HVM_PARAM_PAGING_RING_PFN   27
144
+#define HVM_PARAM_ACCESS_RING_PFN   28
145
+#define HVM_PARAM_SHARING_RING_PFN  29
146
+
147
+/* SHUTDOWN_* action in case of a triple fault */
148
+#define HVM_PARAM_TRIPLE_FAULT_REASON 31
149
+
150
+#define HVM_PARAM_IOREQ_SERVER_PFN 32
151
+#define HVM_PARAM_NR_IOREQ_SERVER_PAGES 33
152
+
153
+/* Location of the VM Generation ID in guest physical address space. */
154
+#define HVM_PARAM_VM_GENERATION_ID_ADDR 34
155
+
156
+#define HVM_NR_PARAMS          35
157
+
158
+#endif /* __XEN_PUBLIC_HVM_PARAMS_H__ */

+ 116
- 0
src/include/xen/import.pl View File

@@ -0,0 +1,116 @@
1
+#!/usr/bin/perl -w
2
+
3
+=head1 NAME
4
+
5
+import.pl
6
+
7
+=head1 SYNOPSIS
8
+
9
+import.pl [options] /path/to/xen
10
+
11
+Options:
12
+
13
+    -h,--help		Display brief help message
14
+    -v,--verbose	Increase verbosity
15
+    -q,--quiet		Decrease verbosity
16
+
17
+=cut
18
+
19
+use File::Spec::Functions qw ( :ALL );
20
+use File::Find;
21
+use File::Path;
22
+use Getopt::Long;
23
+use Pod::Usage;
24
+use FindBin;
25
+use strict;
26
+use warnings;
27
+
28
+my $verbosity = 0;
29
+
30
+sub try_import_file {
31
+  my $ipxedir = shift;
32
+  my $xendir = shift;
33
+  my $filename = shift;
34
+
35
+  # Skip everything except headers
36
+  return unless $filename =~ /\.h$/;
37
+
38
+  # Search for importable header
39
+  ( undef, my $subdir, undef ) = splitpath ( $filename );
40
+  my $outfile = catfile ( $ipxedir, $filename );
41
+  my $infile = catfile ( $xendir, "xen/include/public", $filename );
42
+  die "$infile does not exist\n" unless -e $infile;
43
+
44
+  # Import header file
45
+  print "$filename <- ".catfile ( $xendir, $filename )."\n"
46
+      if $verbosity >= 1;
47
+  open my $infh, "<", $infile or die "Could not open $infile: $!\n";
48
+  mkpath ( catdir ( $xendir, $subdir ) );
49
+  open my $outfh, ">", $outfile or die "Could not open $outfile: $!\n";
50
+  my @dependencies = ();
51
+  my $maybe_guard;
52
+  my $guard;
53
+  while ( <$infh> ) {
54
+    # Strip CR and trailing whitespace
55
+    s/\r//g;
56
+    s/\s*$//g;
57
+    chomp;
58
+    # Update include lines, and record included files
59
+    if ( /^\#include\s+[<\"](\S+)[>\"]/ ) {
60
+      push @dependencies, catfile ( $subdir, $1 );
61
+    }
62
+    # Write out line
63
+    print $outfh "$_\n";
64
+    # Apply FILE_LICENCE() immediately after include guard
65
+    if ( defined $maybe_guard ) {
66
+      if ( /^\#define\s+_+${maybe_guard}_H_*$/ ) {
67
+	die "Duplicate header guard detected in $infile\n" if $guard;
68
+	$guard = $maybe_guard;
69
+	print $outfh "\nFILE_LICENCE ( MIT );\n";
70
+      }
71
+      undef $maybe_guard;
72
+    }
73
+    if ( /^#ifndef\s+_+(\S+)_H_*$/ ) {
74
+      $maybe_guard = $1;
75
+    }
76
+  }
77
+  close $outfh;
78
+  close $infh;
79
+  # Warn if no header guard was detected
80
+  warn "Cannot detect header guard in $infile\n" unless $guard;
81
+  # Recurse to handle any included files that we don't already have
82
+  foreach my $dependency ( @dependencies ) {
83
+    if ( ! -e catfile ( $ipxedir, $dependency ) ) {
84
+      print "...following dependency on $dependency\n" if $verbosity >= 1;
85
+      try_import_file ( $ipxedir, $xendir, $dependency );
86
+    }
87
+  }
88
+  return;
89
+}
90
+
91
+# Parse command-line options
92
+Getopt::Long::Configure ( 'bundling', 'auto_abbrev' );
93
+GetOptions (
94
+  'verbose|v+' => sub { $verbosity++; },
95
+  'quiet|q+' => sub { $verbosity--; },
96
+  'help|h' => sub { pod2usage ( 1 ); },
97
+) or die "Could not parse command-line options\n";
98
+pod2usage ( 1 ) unless @ARGV == 1;
99
+my $xendir = shift;
100
+
101
+# Identify Xen import directory
102
+die "Directory \"$xendir\" does not appear to contain the Xen source tree\n"
103
+    unless -e catfile ( $xendir, "xen/include/public/xen.h" );
104
+
105
+# Identify iPXE Xen includes directory
106
+my $ipxedir = $FindBin::Bin;
107
+die "Directory \"$ipxedir\" does not appear to contain the iPXE Xen includes\n"
108
+    unless -e catfile ( $ipxedir, "../../include/ipxe" );
109
+
110
+print "Importing Xen headers into $ipxedir\nfrom $xendir\n"
111
+    if $verbosity >= 1;
112
+
113
+# Import headers
114
+find ( { wanted => sub {
115
+  try_import_file ( $ipxedir, $xendir, abs2rel ( $_, $ipxedir ) );
116
+}, no_chdir => 1 }, $ipxedir );

+ 307
- 0
src/include/xen/io/netif.h View File

@@ -0,0 +1,307 @@
1
+/******************************************************************************
2
+ * netif.h
3
+ *
4
+ * Unified network-device I/O interface for Xen guest OSes.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to
8
+ * deal in the Software without restriction, including without limitation the
9
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10
+ * sell copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in
14
+ * all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22
+ * DEALINGS IN THE SOFTWARE.
23
+ *
24
+ * Copyright (c) 2003-2004, Keir Fraser
25
+ */
26
+
27
+#ifndef __XEN_PUBLIC_IO_NETIF_H__
28
+#define __XEN_PUBLIC_IO_NETIF_H__
29
+
30
+FILE_LICENCE ( MIT );
31
+
32
+#include "ring.h"
33
+#include "../grant_table.h"
34
+
35
+/*
36
+ * Older implementation of Xen network frontend / backend has an
37
+ * implicit dependency on the MAX_SKB_FRAGS as the maximum number of
38
+ * ring slots a skb can use. Netfront / netback may not work as
39
+ * expected when frontend and backend have different MAX_SKB_FRAGS.
40
+ *
41
+ * A better approach is to add mechanism for netfront / netback to
42
+ * negotiate this value. However we cannot fix all possible
43
+ * frontends, so we need to define a value which states the minimum
44
+ * slots backend must support.
45
+ *
46
+ * The minimum value derives from older Linux kernel's MAX_SKB_FRAGS
47
+ * (18), which is proved to work with most frontends. Any new backend
48
+ * which doesn't negotiate with frontend should expect frontend to
49
+ * send a valid packet using slots up to this value.
50
+ */
51
+#define XEN_NETIF_NR_SLOTS_MIN 18
52
+
53
+/*
54
+ * Notifications after enqueuing any type of message should be conditional on
55
+ * the appropriate req_event or rsp_event field in the shared ring.
56
+ * If the client sends notification for rx requests then it should specify
57
+ * feature 'feature-rx-notify' via xenbus. Otherwise the backend will assume
58
+ * that it cannot safely queue packets (as it may not be kicked to send them).
59
+ */
60
+
61
+/*
62
+ * "feature-split-event-channels" is introduced to separate guest TX
63
+ * and RX notification. Backend either doesn't support this feature or
64
+ * advertises it via xenstore as 0 (disabled) or 1 (enabled).
65
+ *
66
+ * To make use of this feature, frontend should allocate two event
67
+ * channels for TX and RX, advertise them to backend as
68
+ * "event-channel-tx" and "event-channel-rx" respectively. If frontend
69
+ * doesn't want to use this feature, it just writes "event-channel"
70
+ * node as before.
71
+ */
72
+
73
+/*
74
+ * Multiple transmit and receive queues:
75
+ * If supported, the backend will write the key "multi-queue-max-queues" to
76
+ * the directory for that vif, and set its value to the maximum supported
77
+ * number of queues.
78
+ * Frontends that are aware of this feature and wish to use it can write the
79
+ * key "multi-queue-num-queues", set to the number they wish to use, which
80
+ * must be greater than zero, and no more than the value reported by the backend
81
+ * in "multi-queue-max-queues".
82
+ *
83
+ * Queues replicate the shared rings and event channels.
84
+ * "feature-split-event-channels" may optionally be used when using
85
+ * multiple queues, but is not mandatory.
86
+ *
87
+ * Each queue consists of one shared ring pair, i.e. there must be the same
88
+ * number of tx and rx rings.
89
+ *
90
+ * For frontends requesting just one queue, the usual event-channel and
91
+ * ring-ref keys are written as before, simplifying the backend processing
92
+ * to avoid distinguishing between a frontend that doesn't understand the
93
+ * multi-queue feature, and one that does, but requested only one queue.
94
+ *
95
+ * Frontends requesting two or more queues must not write the toplevel
96
+ * event-channel (or event-channel-{tx,rx}) and {tx,rx}-ring-ref keys,
97
+ * instead writing those keys under sub-keys having the name "queue-N" where
98
+ * N is the integer ID of the queue for which those keys belong. Queues
99
+ * are indexed from zero. For example, a frontend with two queues and split
100
+ * event channels must write the following set of queue-related keys:
101
+ *
102
+ * /local/domain/1/device/vif/0/multi-queue-num-queues = "2"
103
+ * /local/domain/1/device/vif/0/queue-0 = ""
104
+ * /local/domain/1/device/vif/0/queue-0/tx-ring-ref = "<ring-ref-tx0>"
105
+ * /local/domain/1/device/vif/0/queue-0/rx-ring-ref = "<ring-ref-rx0>"
106
+ * /local/domain/1/device/vif/0/queue-0/event-channel-tx = "<evtchn-tx0>"
107
+ * /local/domain/1/device/vif/0/queue-0/event-channel-rx = "<evtchn-rx0>"
108
+ * /local/domain/1/device/vif/0/queue-1 = ""
109
+ * /local/domain/1/device/vif/0/queue-1/tx-ring-ref = "<ring-ref-tx1>"
110
+ * /local/domain/1/device/vif/0/queue-1/rx-ring-ref = "<ring-ref-rx1"
111
+ * /local/domain/1/device/vif/0/queue-1/event-channel-tx = "<evtchn-tx1>"
112
+ * /local/domain/1/device/vif/0/queue-1/event-channel-rx = "<evtchn-rx1>"
113
+ *
114
+ * If there is any inconsistency in the XenStore data, the backend may
115
+ * choose not to connect any queues, instead treating the request as an
116
+ * error. This includes scenarios where more (or fewer) queues were
117
+ * requested than the frontend provided details for.
118
+ *
119
+ * Mapping of packets to queues is considered to be a function of the
120
+ * transmitting system (backend or frontend) and is not negotiated
121
+ * between the two. Guests are free to transmit packets on any queue
122
+ * they choose, provided it has been set up correctly. Guests must be
123
+ * prepared to receive packets on any queue they have requested be set up.
124
+ */
125
+
126
+/*
127
+ * "feature-no-csum-offload" should be used to turn IPv4 TCP/UDP checksum
128
+ * offload off or on. If it is missing then the feature is assumed to be on.
129
+ * "feature-ipv6-csum-offload" should be used to turn IPv6 TCP/UDP checksum
130
+ * offload on or off. If it is missing then the feature is assumed to be off.
131
+ */
132
+
133
+/*
134
+ * "feature-gso-tcpv4" and "feature-gso-tcpv6" advertise the capability to
135
+ * handle large TCP packets (in IPv4 or IPv6 form respectively). Neither
136
+ * frontends nor backends are assumed to be capable unless the flags are
137
+ * present.
138
+ */
139
+
140
+/*
141
+ * This is the 'wire' format for packets:
142
+ *  Request 1: netif_tx_request -- NETTXF_* (any flags)
143
+ * [Request 2: netif_tx_extra]  (only if request 1 has NETTXF_extra_info)
144
+ * [Request 3: netif_tx_extra]  (only if request 2 has XEN_NETIF_EXTRA_MORE)
145
+ *  Request 4: netif_tx_request -- NETTXF_more_data
146
+ *  Request 5: netif_tx_request -- NETTXF_more_data
147
+ *  ...
148
+ *  Request N: netif_tx_request -- 0
149
+ */
150
+
151
+/* Protocol checksum field is blank in the packet (hardware offload)? */
152
+#define _NETTXF_csum_blank     (0)
153
+#define  NETTXF_csum_blank     (1U<<_NETTXF_csum_blank)
154
+
155
+/* Packet data has been validated against protocol checksum. */
156
+#define _NETTXF_data_validated (1)
157
+#define  NETTXF_data_validated (1U<<_NETTXF_data_validated)
158
+
159
+/* Packet continues in the next request descriptor. */
160
+#define _NETTXF_more_data      (2)
161
+#define  NETTXF_more_data      (1U<<_NETTXF_more_data)
162
+
163
+/* Packet to be followed by extra descriptor(s). */
164
+#define _NETTXF_extra_info     (3)
165
+#define  NETTXF_extra_info     (1U<<_NETTXF_extra_info)
166
+
167
+#define XEN_NETIF_MAX_TX_SIZE 0xFFFF
168
+struct netif_tx_request {
169
+    grant_ref_t gref;      /* Reference to buffer page */
170
+    uint16_t offset;       /* Offset within buffer page */
171
+    uint16_t flags;        /* NETTXF_* */
172
+    uint16_t id;           /* Echoed in response message. */
173
+    uint16_t size;         /* Packet size in bytes.       */
174
+};
175
+typedef struct netif_tx_request netif_tx_request_t;
176
+
177
+/* Types of netif_extra_info descriptors. */
178
+#define XEN_NETIF_EXTRA_TYPE_NONE      (0)  /* Never used - invalid */
179
+#define XEN_NETIF_EXTRA_TYPE_GSO       (1)  /* u.gso */
180
+#define XEN_NETIF_EXTRA_TYPE_MCAST_ADD (2)  /* u.mcast */
181
+#define XEN_NETIF_EXTRA_TYPE_MCAST_DEL (3)  /* u.mcast */
182
+#define XEN_NETIF_EXTRA_TYPE_MAX       (4)
183
+
184
+/* netif_extra_info flags. */
185
+#define _XEN_NETIF_EXTRA_FLAG_MORE (0)
186
+#define XEN_NETIF_EXTRA_FLAG_MORE  (1U<<_XEN_NETIF_EXTRA_FLAG_MORE)
187
+
188
+/* GSO types */
189
+#define XEN_NETIF_GSO_TYPE_NONE         (0)
190
+#define XEN_NETIF_GSO_TYPE_TCPV4        (1)
191
+#define XEN_NETIF_GSO_TYPE_TCPV6        (2)
192
+
193
+/*
194
+ * This structure needs to fit within both netif_tx_request and
195
+ * netif_rx_response for compatibility.
196
+ */
197
+struct netif_extra_info {
198
+    uint8_t type;  /* XEN_NETIF_EXTRA_TYPE_* */
199
+    uint8_t flags; /* XEN_NETIF_EXTRA_FLAG_* */
200
+
201
+    union {
202
+        /*
203
+         * XEN_NETIF_EXTRA_TYPE_GSO:
204
+         */
205
+        struct {
206
+            /*
207
+             * Maximum payload size of each segment. For example, for TCP this
208
+             * is just the path MSS.
209
+             */
210
+            uint16_t size;
211
+
212
+            /*
213
+             * GSO type. This determines the protocol of the packet and any
214
+             * extra features required to segment the packet properly.
215
+             */
216
+            uint8_t type; /* XEN_NETIF_GSO_TYPE_* */
217
+
218
+            /* Future expansion. */
219
+            uint8_t pad;
220
+
221
+            /*
222
+             * GSO features. This specifies any extra GSO features required
223
+             * to process this packet, such as ECN support for TCPv4.
224
+             */
225
+            uint16_t features; /* XEN_NETIF_GSO_FEAT_* */
226
+        } gso;
227
+
228
+        /*
229
+         * XEN_NETIF_EXTRA_TYPE_MCAST_{ADD,DEL}:
230
+         * Backend advertises availability via 'feature-multicast-control'
231
+         * xenbus node containing value '1'.
232
+         * Frontend requests this feature by advertising
233
+         * 'request-multicast-control' xenbus node containing value '1'.
234
+         * If multicast control is requested then multicast flooding is
235
+         * disabled and the frontend must explicitly register its interest
236
+         * in multicast groups using dummy transmit requests containing
237
+         * MCAST_{ADD,DEL} extra-info fragments.
238
+         */
239
+        struct {
240
+            uint8_t addr[6]; /* Address to add/remove. */
241
+        } mcast;
242
+
243
+        uint16_t pad[3];
244
+    } u;
245
+};
246
+typedef struct netif_extra_info netif_extra_info_t;
247
+
248
+struct netif_tx_response {
249
+    uint16_t id;
250
+    int16_t  status;       /* NETIF_RSP_* */
251
+};
252
+typedef struct netif_tx_response netif_tx_response_t;
253
+
254
+struct netif_rx_request {
255
+    uint16_t    id;        /* Echoed in response message.        */
256
+    grant_ref_t gref;      /* Reference to incoming granted frame */
257
+};
258
+typedef struct netif_rx_request netif_rx_request_t;
259
+
260
+/* Packet data has been validated against protocol checksum. */
261
+#define _NETRXF_data_validated (0)
262
+#define  NETRXF_data_validated (1U<<_NETRXF_data_validated)
263
+
264
+/* Protocol checksum field is blank in the packet (hardware offload)? */
265
+#define _NETRXF_csum_blank     (1)
266
+#define  NETRXF_csum_blank     (1U<<_NETRXF_csum_blank)
267
+
268
+/* Packet continues in the next request descriptor. */
269
+#define _NETRXF_more_data      (2)
270
+#define  NETRXF_more_data      (1U<<_NETRXF_more_data)
271
+
272
+/* Packet to be followed by extra descriptor(s). */
273
+#define _NETRXF_extra_info     (3)
274
+#define  NETRXF_extra_info     (1U<<_NETRXF_extra_info)
275
+
276
+struct netif_rx_response {
277
+    uint16_t id;
278
+    uint16_t offset;       /* Offset in page of start of received packet  */
279
+    uint16_t flags;        /* NETRXF_* */
280
+    int16_t  status;       /* -ve: NETIF_RSP_* ; +ve: Rx'ed pkt size. */
281
+};
282
+typedef struct netif_rx_response netif_rx_response_t;
283
+
284
+/*
285
+ * Generate netif ring structures and types.
286
+ */
287
+
288
+DEFINE_RING_TYPES(netif_tx, struct netif_tx_request, struct netif_tx_response);
289
+DEFINE_RING_TYPES(netif_rx, struct netif_rx_request, struct netif_rx_response);
290
+
291
+#define NETIF_RSP_DROPPED         -2
292
+#define NETIF_RSP_ERROR           -1
293
+#define NETIF_RSP_OKAY             0
294
+/* No response: used for auxiliary requests (e.g., netif_tx_extra). */
295
+#define NETIF_RSP_NULL             1
296
+
297
+#endif
298
+
299
+/*
300
+ * Local variables:
301
+ * mode: C
302
+ * c-file-style: "BSD"
303
+ * c-basic-offset: 4
304
+ * tab-width: 4
305
+ * indent-tabs-mode: nil
306
+ * End:
307
+ */

+ 314
- 0
src/include/xen/io/ring.h View File

@@ -0,0 +1,314 @@
1
+/******************************************************************************
2
+ * ring.h
3
+ *
4
+ * Shared producer-consumer ring macros.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to
8
+ * deal in the Software without restriction, including without limitation the
9
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10
+ * sell copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in
14
+ * all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22
+ * DEALINGS IN THE SOFTWARE.
23
+ *
24
+ * Tim Deegan and Andrew Warfield November 2004.
25
+ */
26
+
27
+#ifndef __XEN_PUBLIC_IO_RING_H__
28
+#define __XEN_PUBLIC_IO_RING_H__
29
+
30
+FILE_LICENCE ( MIT );
31
+
32
+#include "../xen-compat.h"
33
+
34
+#if __XEN_INTERFACE_VERSION__ < 0x00030208
35
+#define xen_mb()  mb()
36
+#define xen_rmb() rmb()
37
+#define xen_wmb() wmb()
38
+#endif
39
+
40
+typedef unsigned int RING_IDX;
41
+
42
+/* Round a 32-bit unsigned constant down to the nearest power of two. */
43
+#define __RD2(_x)  (((_x) & 0x00000002) ? 0x2                  : ((_x) & 0x1))
44
+#define __RD4(_x)  (((_x) & 0x0000000c) ? __RD2((_x)>>2)<<2    : __RD2(_x))
45
+#define __RD8(_x)  (((_x) & 0x000000f0) ? __RD4((_x)>>4)<<4    : __RD4(_x))
46
+#define __RD16(_x) (((_x) & 0x0000ff00) ? __RD8((_x)>>8)<<8    : __RD8(_x))
47
+#define __RD32(_x) (((_x) & 0xffff0000) ? __RD16((_x)>>16)<<16 : __RD16(_x))
48
+
49
+/*
50
+ * Calculate size of a shared ring, given the total available space for the
51
+ * ring and indexes (_sz), and the name tag of the request/response structure.
52
+ * A ring contains as many entries as will fit, rounded down to the nearest
53
+ * power of two (so we can mask with (size-1) to loop around).
54
+ */
55
+#define __CONST_RING_SIZE(_s, _sz) \
56
+    (__RD32(((_sz) - offsetof(struct _s##_sring, ring)) / \
57
+	    sizeof(((struct _s##_sring *)0)->ring[0])))
58
+/*
59
+ * The same for passing in an actual pointer instead of a name tag.
60
+ */
61
+#define __RING_SIZE(_s, _sz) \
62
+    (__RD32(((_sz) - (long)(_s)->ring + (long)(_s)) / sizeof((_s)->ring[0])))
63
+
64
+/*
65
+ * Macros to make the correct C datatypes for a new kind of ring.
66
+ *
67
+ * To make a new ring datatype, you need to have two message structures,
68
+ * let's say request_t, and response_t already defined.
69
+ *
70
+ * In a header where you want the ring datatype declared, you then do:
71
+ *
72
+ *     DEFINE_RING_TYPES(mytag, request_t, response_t);
73
+ *
74
+ * These expand out to give you a set of types, as you can see below.
75
+ * The most important of these are:
76
+ *
77
+ *     mytag_sring_t      - The shared ring.
78
+ *     mytag_front_ring_t - The 'front' half of the ring.
79
+ *     mytag_back_ring_t  - The 'back' half of the ring.
80
+ *
81
+ * To initialize a ring in your code you need to know the location and size
82
+ * of the shared memory area (PAGE_SIZE, for instance). To initialise
83
+ * the front half:
84
+ *
85
+ *     mytag_front_ring_t front_ring;
86
+ *     SHARED_RING_INIT((mytag_sring_t *)shared_page);
87
+ *     FRONT_RING_INIT(&front_ring, (mytag_sring_t *)shared_page, PAGE_SIZE);
88
+ *
89
+ * Initializing the back follows similarly (note that only the front
90
+ * initializes the shared ring):
91
+ *
92
+ *     mytag_back_ring_t back_ring;
93
+ *     BACK_RING_INIT(&back_ring, (mytag_sring_t *)shared_page, PAGE_SIZE);
94
+ */
95
+
96
+#define DEFINE_RING_TYPES(__name, __req_t, __rsp_t)                     \
97
+                                                                        \
98
+/* Shared ring entry */                                                 \
99
+union __name##_sring_entry {                                            \
100
+    __req_t req;                                                        \
101
+    __rsp_t rsp;                                                        \
102
+};                                                                      \
103
+                                                                        \
104
+/* Shared ring page */                                                  \
105
+struct __name##_sring {                                                 \
106
+    RING_IDX req_prod, req_event;                                       \
107
+    RING_IDX rsp_prod, rsp_event;                                       \
108
+    union {                                                             \
109
+        struct {                                                        \
110
+            uint8_t smartpoll_active;                                   \
111
+        } netif;                                                        \
112
+        struct {                                                        \
113
+            uint8_t msg;                                                \
114
+        } tapif_user;                                                   \
115
+        uint8_t pvt_pad[4];                                             \
116
+    } private;                                                          \
117
+    uint8_t __pad[44];                                                  \
118
+    union __name##_sring_entry ring[1]; /* variable-length */           \
119
+};                                                                      \
120
+                                                                        \
121
+/* "Front" end's private variables */                                   \
122
+struct __name##_front_ring {                                            \
123
+    RING_IDX req_prod_pvt;                                              \
124
+    RING_IDX rsp_cons;                                                  \
125
+    unsigned int nr_ents;                                               \
126
+    struct __name##_sring *sring;                                       \
127
+};                                                                      \
128
+                                                                        \
129
+/* "Back" end's private variables */                                    \
130
+struct __name##_back_ring {                                             \
131
+    RING_IDX rsp_prod_pvt;                                              \
132
+    RING_IDX req_cons;                                                  \
133
+    unsigned int nr_ents;                                               \
134
+    struct __name##_sring *sring;                                       \
135
+};                                                                      \
136
+                                                                        \
137
+/* Syntactic sugar */                                                   \
138
+typedef struct __name##_sring __name##_sring_t;                         \
139
+typedef struct __name##_front_ring __name##_front_ring_t;               \
140
+typedef struct __name##_back_ring __name##_back_ring_t
141
+
142
+/*
143
+ * Macros for manipulating rings.
144
+ *
145
+ * FRONT_RING_whatever works on the "front end" of a ring: here
146
+ * requests are pushed on to the ring and responses taken off it.
147
+ *
148
+ * BACK_RING_whatever works on the "back end" of a ring: here
149
+ * requests are taken off the ring and responses put on.
150
+ *
151
+ * N.B. these macros do NO INTERLOCKS OR FLOW CONTROL.
152
+ * This is OK in 1-for-1 request-response situations where the
153
+ * requestor (front end) never has more than RING_SIZE()-1
154
+ * outstanding requests.
155
+ */
156
+
157
+/* Initialising empty rings */
158
+#define SHARED_RING_INIT(_s) do {                                       \
159
+    (_s)->req_prod  = (_s)->rsp_prod  = 0;                              \
160
+    (_s)->req_event = (_s)->rsp_event = 1;                              \
161
+    (void)memset((_s)->private.pvt_pad, 0, sizeof((_s)->private.pvt_pad)); \
162
+    (void)memset((_s)->__pad, 0, sizeof((_s)->__pad));                  \
163
+} while(0)
164
+
165
+#define FRONT_RING_INIT(_r, _s, __size) do {                            \
166
+    (_r)->req_prod_pvt = 0;                                             \
167
+    (_r)->rsp_cons = 0;                                                 \
168
+    (_r)->nr_ents = __RING_SIZE(_s, __size);                            \
169
+    (_r)->sring = (_s);                                                 \
170
+} while (0)
171
+
172
+#define BACK_RING_INIT(_r, _s, __size) do {                             \
173
+    (_r)->rsp_prod_pvt = 0;                                             \
174
+    (_r)->req_cons = 0;                                                 \
175
+    (_r)->nr_ents = __RING_SIZE(_s, __size);                            \
176
+    (_r)->sring = (_s);                                                 \
177
+} while (0)
178
+
179
+/* How big is this ring? */
180
+#define RING_SIZE(_r)                                                   \
181
+    ((_r)->nr_ents)
182
+
183
+/* Number of free requests (for use on front side only). */
184
+#define RING_FREE_REQUESTS(_r)                                          \
185
+    (RING_SIZE(_r) - ((_r)->req_prod_pvt - (_r)->rsp_cons))
186
+
187
+/* Test if there is an empty slot available on the front ring.
188
+ * (This is only meaningful from the front. )
189
+ */
190
+#define RING_FULL(_r)                                                   \
191
+    (RING_FREE_REQUESTS(_r) == 0)
192
+
193
+/* Test if there are outstanding messages to be processed on a ring. */
194
+#define RING_HAS_UNCONSUMED_RESPONSES(_r)                               \
195
+    ((_r)->sring->rsp_prod - (_r)->rsp_cons)
196
+
197
+#ifdef __GNUC__
198
+#define RING_HAS_UNCONSUMED_REQUESTS(_r) ({                             \
199
+    unsigned int req = (_r)->sring->req_prod - (_r)->req_cons;          \
200
+    unsigned int rsp = RING_SIZE(_r) -                                  \
201
+        ((_r)->req_cons - (_r)->rsp_prod_pvt);                          \
202
+    req < rsp ? req : rsp;                                              \
203
+})
204
+#else
205
+/* Same as above, but without the nice GCC ({ ... }) syntax. */
206
+#define RING_HAS_UNCONSUMED_REQUESTS(_r)                                \
207
+    ((((_r)->sring->req_prod - (_r)->req_cons) <                        \
208
+      (RING_SIZE(_r) - ((_r)->req_cons - (_r)->rsp_prod_pvt))) ?        \
209
+     ((_r)->sring->req_prod - (_r)->req_cons) :                         \
210
+     (RING_SIZE(_r) - ((_r)->req_cons - (_r)->rsp_prod_pvt)))
211
+#endif
212
+
213
+/* Direct access to individual ring elements, by index. */
214
+#define RING_GET_REQUEST(_r, _idx)                                      \
215
+    (&((_r)->sring->ring[((_idx) & (RING_SIZE(_r) - 1))].req))
216
+
217
+#define RING_GET_RESPONSE(_r, _idx)                                     \
218
+    (&((_r)->sring->ring[((_idx) & (RING_SIZE(_r) - 1))].rsp))
219
+
220
+/* Loop termination condition: Would the specified index overflow the ring? */
221
+#define RING_REQUEST_CONS_OVERFLOW(_r, _cons)                           \
222
+    (((_cons) - (_r)->rsp_prod_pvt) >= RING_SIZE(_r))
223
+
224
+/* Ill-behaved frontend determination: Can there be this many requests? */
225
+#define RING_REQUEST_PROD_OVERFLOW(_r, _prod)                           \
226
+    (((_prod) - (_r)->rsp_prod_pvt) > RING_SIZE(_r))
227
+
228
+#define RING_PUSH_REQUESTS(_r) do {                                     \
229
+    xen_wmb(); /* back sees requests /before/ updated producer index */ \
230
+    (_r)->sring->req_prod = (_r)->req_prod_pvt;                         \
231
+} while (0)
232
+
233
+#define RING_PUSH_RESPONSES(_r) do {                                    \
234
+    xen_wmb(); /* front sees resps /before/ updated producer index */   \
235
+    (_r)->sring->rsp_prod = (_r)->rsp_prod_pvt;                         \
236
+} while (0)
237
+
238
+/*
239
+ * Notification hold-off (req_event and rsp_event):
240
+ *
241
+ * When queueing requests or responses on a shared ring, it may not always be
242
+ * necessary to notify the remote end. For example, if requests are in flight
243
+ * in a backend, the front may be able to queue further requests without
244
+ * notifying the back (if the back checks for new requests when it queues
245
+ * responses).
246
+ *
247
+ * When enqueuing requests or responses:
248
+ *
249
+ *  Use RING_PUSH_{REQUESTS,RESPONSES}_AND_CHECK_NOTIFY(). The second argument
250
+ *  is a boolean return value. True indicates that the receiver requires an
251
+ *  asynchronous notification.
252
+ *
253
+ * After dequeuing requests or responses (before sleeping the connection):
254
+ *
255
+ *  Use RING_FINAL_CHECK_FOR_REQUESTS() or RING_FINAL_CHECK_FOR_RESPONSES().
256
+ *  The second argument is a boolean return value. True indicates that there
257
+ *  are pending messages on the ring (i.e., the connection should not be put
258
+ *  to sleep).
259
+ *
260
+ *  These macros will set the req_event/rsp_event field to trigger a
261
+ *  notification on the very next message that is enqueued. If you want to
262
+ *  create batches of work (i.e., only receive a notification after several
263
+ *  messages have been enqueued) then you will need to create a customised
264
+ *  version of the FINAL_CHECK macro in your own code, which sets the event
265
+ *  field appropriately.
266
+ */
267
+
268
+#define RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(_r, _notify) do {           \
269
+    RING_IDX __old = (_r)->sring->req_prod;                             \
270
+    RING_IDX __new = (_r)->req_prod_pvt;                                \
271
+    xen_wmb(); /* back sees requests /before/ updated producer index */ \
272
+    (_r)->sring->req_prod = __new;                                      \
273
+    xen_mb(); /* back sees new requests /before/ we check req_event */  \
274
+    (_notify) = ((RING_IDX)(__new - (_r)->sring->req_event) <           \
275
+                 (RING_IDX)(__new - __old));                            \
276
+} while (0)
277
+
278
+#define RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(_r, _notify) do {          \
279
+    RING_IDX __old = (_r)->sring->rsp_prod;                             \
280
+    RING_IDX __new = (_r)->rsp_prod_pvt;                                \
281
+    xen_wmb(); /* front sees resps /before/ updated producer index */   \
282
+    (_r)->sring->rsp_prod = __new;                                      \
283
+    xen_mb(); /* front sees new resps /before/ we check rsp_event */    \
284
+    (_notify) = ((RING_IDX)(__new - (_r)->sring->rsp_event) <           \
285
+                 (RING_IDX)(__new - __old));                            \
286
+} while (0)
287
+
288
+#define RING_FINAL_CHECK_FOR_REQUESTS(_r, _work_to_do) do {             \
289
+    (_work_to_do) = RING_HAS_UNCONSUMED_REQUESTS(_r);                   \
290
+    if (_work_to_do) break;                                             \
291
+    (_r)->sring->req_event = (_r)->req_cons + 1;                        \
292
+    xen_mb();                                                           \
293
+    (_work_to_do) = RING_HAS_UNCONSUMED_REQUESTS(_r);                   \
294
+} while (0)
295
+
296
+#define RING_FINAL_CHECK_FOR_RESPONSES(_r, _work_to_do) do {            \
297
+    (_work_to_do) = RING_HAS_UNCONSUMED_RESPONSES(_r);                  \
298
+    if (_work_to_do) break;                                             \
299
+    (_r)->sring->rsp_event = (_r)->rsp_cons + 1;                        \
300
+    xen_mb();                                                           \
301
+    (_work_to_do) = RING_HAS_UNCONSUMED_RESPONSES(_r);                  \
302
+} while (0)
303
+
304
+#endif /* __XEN_PUBLIC_IO_RING_H__ */
305
+
306
+/*
307
+ * Local variables:
308
+ * mode: C
309
+ * c-file-style: "BSD"
310
+ * c-basic-offset: 4
311
+ * tab-width: 4
312
+ * indent-tabs-mode: nil
313
+ * End:
314
+ */

+ 82
- 0
src/include/xen/io/xenbus.h View File

@@ -0,0 +1,82 @@
1
+/*****************************************************************************
2
+ * xenbus.h
3
+ *
4
+ * Xenbus protocol details.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to
8
+ * deal in the Software without restriction, including without limitation the
9
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10
+ * sell copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in
14
+ * all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22
+ * DEALINGS IN THE SOFTWARE.
23
+ *
24
+ * Copyright (C) 2005 XenSource Ltd.
25
+ */
26
+
27
+#ifndef _XEN_PUBLIC_IO_XENBUS_H
28
+#define _XEN_PUBLIC_IO_XENBUS_H
29
+
30
+FILE_LICENCE ( MIT );
31
+
32
+/*
33
+ * The state of either end of the Xenbus, i.e. the current communication
34
+ * status of initialisation across the bus.  States here imply nothing about
35
+ * the state of the connection between the driver and the kernel's device
36
+ * layers.
37
+ */
38
+enum xenbus_state {
39
+    XenbusStateUnknown       = 0,
40
+
41
+    XenbusStateInitialising  = 1,
42
+
43
+    /*
44
+     * InitWait: Finished early initialisation but waiting for information
45
+     * from the peer or hotplug scripts.
46
+     */
47
+    XenbusStateInitWait      = 2,
48
+
49
+    /*
50
+     * Initialised: Waiting for a connection from the peer.
51
+     */
52
+    XenbusStateInitialised   = 3,
53
+
54
+    XenbusStateConnected     = 4,
55
+
56
+    /*
57
+     * Closing: The device is being closed due to an error or an unplug event.
58
+     */
59
+    XenbusStateClosing       = 5,
60
+
61
+    XenbusStateClosed        = 6,
62
+
63
+    /*
64
+     * Reconfiguring: The device is being reconfigured.
65
+     */
66
+    XenbusStateReconfiguring = 7,
67
+
68
+    XenbusStateReconfigured  = 8
69
+};
70
+typedef enum xenbus_state XenbusState;
71
+
72
+#endif /* _XEN_PUBLIC_IO_XENBUS_H */
73
+
74
+/*
75
+ * Local variables:
76
+ * mode: C
77
+ * c-file-style: "BSD"
78
+ * c-basic-offset: 4
79
+ * tab-width: 4
80
+ * indent-tabs-mode: nil
81
+ * End:
82
+ */

+ 140
- 0
src/include/xen/io/xs_wire.h View File

@@ -0,0 +1,140 @@
1
+/*
2
+ * Details of the "wire" protocol between Xen Store Daemon and client
3
+ * library or guest kernel.
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to
7
+ * deal in the Software without restriction, including without limitation the
8
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9
+ * sell copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be included in
13
+ * all copies or substantial portions of the Software.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21
+ * DEALINGS IN THE SOFTWARE.
22
+ *
23
+ * Copyright (C) 2005 Rusty Russell IBM Corporation
24
+ */
25
+
26
+#ifndef _XS_WIRE_H
27
+#define _XS_WIRE_H
28
+
29
+FILE_LICENCE ( MIT );
30
+
31
+enum xsd_sockmsg_type
32
+{
33
+    XS_DEBUG,
34
+    XS_DIRECTORY,
35
+    XS_READ,
36
+    XS_GET_PERMS,
37
+    XS_WATCH,
38
+    XS_UNWATCH,
39
+    XS_TRANSACTION_START,
40
+    XS_TRANSACTION_END,
41
+    XS_INTRODUCE,
42
+    XS_RELEASE,
43
+    XS_GET_DOMAIN_PATH,
44
+    XS_WRITE,
45
+    XS_MKDIR,
46
+    XS_RM,
47
+    XS_SET_PERMS,
48
+    XS_WATCH_EVENT,
49
+    XS_ERROR,
50
+    XS_IS_DOMAIN_INTRODUCED,
51
+    XS_RESUME,
52
+    XS_SET_TARGET,
53
+    XS_RESTRICT,
54
+    XS_RESET_WATCHES
55
+};
56
+
57
+#define XS_WRITE_NONE "NONE"
58
+#define XS_WRITE_CREATE "CREATE"
59
+#define XS_WRITE_CREATE_EXCL "CREATE|EXCL"
60
+
61
+/* We hand errors as strings, for portability. */
62
+struct xsd_errors
63
+{
64
+    int errnum;
65
+    const char *errstring;
66
+};
67
+#ifdef EINVAL
68
+#define XSD_ERROR(x) { x, #x }
69
+/* LINTED: static unused */
70
+static struct xsd_errors xsd_errors[]
71
+#if defined(__GNUC__)
72
+__attribute__((unused))
73
+#endif
74
+    = {
75
+    XSD_ERROR(EINVAL),
76
+    XSD_ERROR(EACCES),
77
+    XSD_ERROR(EEXIST),
78
+    XSD_ERROR(EISDIR),
79
+    XSD_ERROR(ENOENT),
80
+    XSD_ERROR(ENOMEM),
81
+    XSD_ERROR(ENOSPC),
82
+    XSD_ERROR(EIO),
83
+    XSD_ERROR(ENOTEMPTY),
84
+    XSD_ERROR(ENOSYS),
85
+    XSD_ERROR(EROFS),
86
+    XSD_ERROR(EBUSY),
87
+    XSD_ERROR(EAGAIN),
88
+    XSD_ERROR(EISCONN),
89
+    XSD_ERROR(E2BIG)
90
+};
91
+#endif
92
+
93
+struct xsd_sockmsg
94
+{
95
+    uint32_t type;  /* XS_??? */
96
+    uint32_t req_id;/* Request identifier, echoed in daemon's response.  */
97
+    uint32_t tx_id; /* Transaction id (0 if not related to a transaction). */
98
+    uint32_t len;   /* Length of data following this. */
99
+
100
+    /* Generally followed by nul-terminated string(s). */
101
+};
102
+
103
+enum xs_watch_type
104
+{
105
+    XS_WATCH_PATH = 0,
106
+    XS_WATCH_TOKEN
107
+};
108
+
109
+/*
110
+ * `incontents 150 xenstore_struct XenStore wire protocol.
111
+ *
112
+ * Inter-domain shared memory communications. */
113
+#define XENSTORE_RING_SIZE 1024
114
+typedef uint32_t XENSTORE_RING_IDX;
115
+#define MASK_XENSTORE_IDX(idx) ((idx) & (XENSTORE_RING_SIZE-1))
116
+struct xenstore_domain_interface {
117
+    char req[XENSTORE_RING_SIZE]; /* Requests to xenstore daemon. */
118
+    char rsp[XENSTORE_RING_SIZE]; /* Replies and async watch events. */
119
+    XENSTORE_RING_IDX req_cons, req_prod;
120
+    XENSTORE_RING_IDX rsp_cons, rsp_prod;
121
+};
122
+
123
+/* Violating this is very bad.  See docs/misc/xenstore.txt. */
124
+#define XENSTORE_PAYLOAD_MAX 4096
125
+
126
+/* Violating these just gets you an error back */
127
+#define XENSTORE_ABS_PATH_MAX 3072
128
+#define XENSTORE_REL_PATH_MAX 2048
129
+
130
+#endif /* _XS_WIRE_H */
131
+
132
+/*
133
+ * Local variables:
134
+ * mode: C
135
+ * c-file-style: "BSD"
136
+ * c-basic-offset: 4
137
+ * tab-width: 4
138
+ * indent-tabs-mode: nil
139
+ * End:
140
+ */

+ 540
- 0
src/include/xen/memory.h View File

@@ -0,0 +1,540 @@
1
+/******************************************************************************
2
+ * memory.h
3
+ *
4
+ * Memory reservation and information.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to
8
+ * deal in the Software without restriction, including without limitation the
9
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10
+ * sell copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in
14
+ * all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22
+ * DEALINGS IN THE SOFTWARE.
23
+ *
24
+ * Copyright (c) 2005, Keir Fraser <keir@xensource.com>
25
+ */
26
+
27
+#ifndef __XEN_PUBLIC_MEMORY_H__
28
+#define __XEN_PUBLIC_MEMORY_H__
29
+
30
+FILE_LICENCE ( MIT );
31
+
32
+#include "xen.h"
33
+
34
+/*
35
+ * Increase or decrease the specified domain's memory reservation. Returns the
36
+ * number of extents successfully allocated or freed.
37
+ * arg == addr of struct xen_memory_reservation.
38
+ */
39
+#define XENMEM_increase_reservation 0
40
+#define XENMEM_decrease_reservation 1
41
+#define XENMEM_populate_physmap     6
42
+
43
+#if __XEN_INTERFACE_VERSION__ >= 0x00030209
44
+/*
45
+ * Maximum # bits addressable by the user of the allocated region (e.g., I/O
46
+ * devices often have a 32-bit limitation even in 64-bit systems). If zero
47
+ * then the user has no addressing restriction. This field is not used by
48
+ * XENMEM_decrease_reservation.
49
+ */
50
+#define XENMEMF_address_bits(x)     (x)
51
+#define XENMEMF_get_address_bits(x) ((x) & 0xffu)
52
+/* NUMA node to allocate from. */
53
+#define XENMEMF_node(x)     (((x) + 1) << 8)
54
+#define XENMEMF_get_node(x) ((((x) >> 8) - 1) & 0xffu)
55
+/* Flag to populate physmap with populate-on-demand entries */
56
+#define XENMEMF_populate_on_demand (1<<16)
57
+/* Flag to request allocation only from the node specified */
58
+#define XENMEMF_exact_node_request  (1<<17)
59
+#define XENMEMF_exact_node(n) (XENMEMF_node(n) | XENMEMF_exact_node_request)
60
+#endif
61
+
62
+struct xen_memory_reservation {
63
+
64
+    /*
65
+     * XENMEM_increase_reservation:
66
+     *   OUT: MFN (*not* GMFN) bases of extents that were allocated
67
+     * XENMEM_decrease_reservation:
68
+     *   IN:  GMFN bases of extents to free
69
+     * XENMEM_populate_physmap:
70
+     *   IN:  GPFN bases of extents to populate with memory
71
+     *   OUT: GMFN bases of extents that were allocated
72
+     *   (NB. This command also updates the mach_to_phys translation table)
73
+     * XENMEM_claim_pages:
74
+     *   IN: must be zero
75
+     */
76
+    XEN_GUEST_HANDLE(xen_pfn_t) extent_start;
77
+
78
+    /* Number of extents, and size/alignment of each (2^extent_order pages). */
79
+    xen_ulong_t    nr_extents;
80
+    unsigned int   extent_order;
81
+
82
+#if __XEN_INTERFACE_VERSION__ >= 0x00030209
83
+    /* XENMEMF flags. */
84
+    unsigned int   mem_flags;
85
+#else
86
+    unsigned int   address_bits;
87
+#endif
88
+
89
+    /*
90
+     * Domain whose reservation is being changed.
91
+     * Unprivileged domains can specify only DOMID_SELF.
92
+     */
93
+    domid_t        domid;
94
+};
95
+typedef struct xen_memory_reservation xen_memory_reservation_t;
96
+DEFINE_XEN_GUEST_HANDLE(xen_memory_reservation_t);
97
+
98
+/*
99
+ * An atomic exchange of memory pages. If return code is zero then
100
+ * @out.extent_list provides GMFNs of the newly-allocated memory.
101
+ * Returns zero on complete success, otherwise a negative error code.
102
+ * On complete success then always @nr_exchanged == @in.nr_extents.
103
+ * On partial success @nr_exchanged indicates how much work was done.
104
+ */
105
+#define XENMEM_exchange             11
106
+struct xen_memory_exchange {
107
+    /*
108
+     * [IN] Details of memory extents to be exchanged (GMFN bases).
109
+     * Note that @in.address_bits is ignored and unused.
110
+     */
111
+    struct xen_memory_reservation in;
112
+
113
+    /*
114
+     * [IN/OUT] Details of new memory extents.
115
+     * We require that:
116
+     *  1. @in.domid == @out.domid
117
+     *  2. @in.nr_extents  << @in.extent_order ==
118
+     *     @out.nr_extents << @out.extent_order
119
+     *  3. @in.extent_start and @out.extent_start lists must not overlap
120
+     *  4. @out.extent_start lists GPFN bases to be populated
121
+     *  5. @out.extent_start is overwritten with allocated GMFN bases
122
+     */
123
+    struct xen_memory_reservation out;
124
+
125
+    /*
126
+     * [OUT] Number of input extents that were successfully exchanged:
127
+     *  1. The first @nr_exchanged input extents were successfully
128
+     *     deallocated.
129
+     *  2. The corresponding first entries in the output extent list correctly
130
+     *     indicate the GMFNs that were successfully exchanged.
131
+     *  3. All other input and output extents are untouched.
132
+     *  4. If not all input exents are exchanged then the return code of this
133
+     *     command will be non-zero.
134
+     *  5. THIS FIELD MUST BE INITIALISED TO ZERO BY THE CALLER!
135
+     */
136
+    xen_ulong_t nr_exchanged;
137
+};
138
+typedef struct xen_memory_exchange xen_memory_exchange_t;
139
+DEFINE_XEN_GUEST_HANDLE(xen_memory_exchange_t);
140
+
141
+/*
142
+ * Returns the maximum machine frame number of mapped RAM in this system.
143
+ * This command always succeeds (it never returns an error code).
144
+ * arg == NULL.
145
+ */
146
+#define XENMEM_maximum_ram_page     2
147
+
148
+/*
149
+ * Returns the current or maximum memory reservation, in pages, of the
150
+ * specified domain (may be DOMID_SELF). Returns -ve errcode on failure.
151
+ * arg == addr of domid_t.
152
+ */
153
+#define XENMEM_current_reservation  3
154
+#define XENMEM_maximum_reservation  4
155
+
156
+/*
157
+ * Returns the maximum GPFN in use by the guest, or -ve errcode on failure.
158
+ */
159
+#define XENMEM_maximum_gpfn         14
160
+
161
+/*
162
+ * Returns a list of MFN bases of 2MB extents comprising the machine_to_phys
163
+ * mapping table. Architectures which do not have a m2p table do not implement
164
+ * this command.
165
+ * arg == addr of xen_machphys_mfn_list_t.
166
+ */
167
+#define XENMEM_machphys_mfn_list    5
168
+struct xen_machphys_mfn_list {
169
+    /*
170
+     * Size of the 'extent_start' array. Fewer entries will be filled if the
171
+     * machphys table is smaller than max_extents * 2MB.
172
+     */
173
+    unsigned int max_extents;
174
+
175
+    /*
176
+     * Pointer to buffer to fill with list of extent starts. If there are
177
+     * any large discontiguities in the machine address space, 2MB gaps in
178
+     * the machphys table will be represented by an MFN base of zero.
179
+     */
180
+    XEN_GUEST_HANDLE(xen_pfn_t) extent_start;
181
+
182
+    /*
183
+     * Number of extents written to the above array. This will be smaller
184
+     * than 'max_extents' if the machphys table is smaller than max_e * 2MB.
185
+     */
186
+    unsigned int nr_extents;
187
+};
188
+typedef struct xen_machphys_mfn_list xen_machphys_mfn_list_t;
189
+DEFINE_XEN_GUEST_HANDLE(xen_machphys_mfn_list_t);
190
+
191
+/*
192
+ * For a compat caller, this is identical to XENMEM_machphys_mfn_list.
193
+ *
194
+ * For a non compat caller, this functions similarly to
195
+ * XENMEM_machphys_mfn_list, but returns the mfns making up the compatibility
196
+ * m2p table.
197
+ */
198
+#define XENMEM_machphys_compat_mfn_list     25
199
+
200
+/*
201
+ * Returns the location in virtual address space of the machine_to_phys
202
+ * mapping table. Architectures which do not have a m2p table, or which do not
203
+ * map it by default into guest address space, do not implement this command.
204
+ * arg == addr of xen_machphys_mapping_t.
205
+ */
206
+#define XENMEM_machphys_mapping     12
207
+struct xen_machphys_mapping {
208
+    xen_ulong_t v_start, v_end; /* Start and end virtual addresses.   */
209
+    xen_ulong_t max_mfn;        /* Maximum MFN that can be looked up. */
210
+};
211
+typedef struct xen_machphys_mapping xen_machphys_mapping_t;
212
+DEFINE_XEN_GUEST_HANDLE(xen_machphys_mapping_t);
213
+
214
+/* Source mapping space. */
215
+/* ` enum phys_map_space { */
216
+#define XENMAPSPACE_shared_info  0 /* shared info page */
217
+#define XENMAPSPACE_grant_table  1 /* grant table page */
218
+#define XENMAPSPACE_gmfn         2 /* GMFN */
219
+#define XENMAPSPACE_gmfn_range   3 /* GMFN range, XENMEM_add_to_physmap only. */
220
+#define XENMAPSPACE_gmfn_foreign 4 /* GMFN from another dom,
221
+                                    * XENMEM_add_to_physmap_batch only. */
222
+/* ` } */
223
+
224
+/*
225
+ * Sets the GPFN at which a particular page appears in the specified guest's
226
+ * pseudophysical address space.
227
+ * arg == addr of xen_add_to_physmap_t.
228
+ */
229
+#define XENMEM_add_to_physmap      7
230
+struct xen_add_to_physmap {
231
+    /* Which domain to change the mapping for. */
232
+    domid_t domid;
233
+
234
+    /* Number of pages to go through for gmfn_range */
235
+    uint16_t    size;
236
+
237
+    unsigned int space; /* => enum phys_map_space */
238
+
239
+#define XENMAPIDX_grant_table_status 0x80000000
240
+
241
+    /* Index into space being mapped. */
242
+    xen_ulong_t idx;
243
+
244
+    /* GPFN in domid where the source mapping page should appear. */
245
+    xen_pfn_t     gpfn;
246
+};
247
+typedef struct xen_add_to_physmap xen_add_to_physmap_t;
248
+DEFINE_XEN_GUEST_HANDLE(xen_add_to_physmap_t);
249
+
250
+/* A batched version of add_to_physmap. */
251
+#define XENMEM_add_to_physmap_batch 23
252
+struct xen_add_to_physmap_batch {
253
+    /* IN */
254
+    /* Which domain to change the mapping for. */
255
+    domid_t domid;
256
+    uint16_t space; /* => enum phys_map_space */
257
+
258
+    /* Number of pages to go through */
259
+    uint16_t size;
260
+    domid_t foreign_domid; /* IFF gmfn_foreign */
261
+
262
+    /* Indexes into space being mapped. */
263
+    XEN_GUEST_HANDLE(xen_ulong_t) idxs;
264
+
265
+    /* GPFN in domid where the source mapping page should appear. */
266
+    XEN_GUEST_HANDLE(xen_pfn_t) gpfns;
267
+
268
+    /* OUT */
269
+
270
+    /* Per index error code. */
271
+    XEN_GUEST_HANDLE(int) errs;
272
+};
273
+typedef struct xen_add_to_physmap_batch xen_add_to_physmap_batch_t;
274
+DEFINE_XEN_GUEST_HANDLE(xen_add_to_physmap_batch_t);
275
+
276
+#if __XEN_INTERFACE_VERSION__ < 0x00040400
277
+#define XENMEM_add_to_physmap_range XENMEM_add_to_physmap_batch
278
+#define xen_add_to_physmap_range xen_add_to_physmap_batch
279
+typedef struct xen_add_to_physmap_batch xen_add_to_physmap_range_t;
280
+DEFINE_XEN_GUEST_HANDLE(xen_add_to_physmap_range_t);
281
+#endif
282
+
283
+/*
284
+ * Unmaps the page appearing at a particular GPFN from the specified guest's
285
+ * pseudophysical address space.
286
+ * arg == addr of xen_remove_from_physmap_t.
287
+ */
288
+#define XENMEM_remove_from_physmap      15
289
+struct xen_remove_from_physmap {
290
+    /* Which domain to change the mapping for. */
291
+    domid_t domid;
292
+
293
+    /* GPFN of the current mapping of the page. */
294
+    xen_pfn_t     gpfn;
295
+};
296
+typedef struct xen_remove_from_physmap xen_remove_from_physmap_t;
297
+DEFINE_XEN_GUEST_HANDLE(xen_remove_from_physmap_t);
298
+
299
+/*** REMOVED ***/
300
+/*#define XENMEM_translate_gpfn_list  8*/
301
+
302
+/*
303
+ * Returns the pseudo-physical memory map as it was when the domain
304
+ * was started (specified by XENMEM_set_memory_map).
305
+ * arg == addr of xen_memory_map_t.
306
+ */
307
+#define XENMEM_memory_map           9
308
+struct xen_memory_map {
309
+    /*
310
+     * On call the number of entries which can be stored in buffer. On
311
+     * return the number of entries which have been stored in
312
+     * buffer.
313
+     */
314
+    unsigned int nr_entries;
315
+
316
+    /*
317
+     * Entries in the buffer are in the same format as returned by the
318
+     * BIOS INT 0x15 EAX=0xE820 call.
319
+     */
320
+    XEN_GUEST_HANDLE(void) buffer;
321
+};
322
+typedef struct xen_memory_map xen_memory_map_t;
323
+DEFINE_XEN_GUEST_HANDLE(xen_memory_map_t);
324
+
325
+/*
326
+ * Returns the real physical memory map. Passes the same structure as
327
+ * XENMEM_memory_map.
328
+ * arg == addr of xen_memory_map_t.
329
+ */
330
+#define XENMEM_machine_memory_map   10
331
+
332
+/*
333
+ * Set the pseudo-physical memory map of a domain, as returned by
334
+ * XENMEM_memory_map.
335
+ * arg == addr of xen_foreign_memory_map_t.
336
+ */
337
+#define XENMEM_set_memory_map       13
338
+struct xen_foreign_memory_map {
339
+    domid_t domid;
340
+    struct xen_memory_map map;
341
+};
342
+typedef struct xen_foreign_memory_map xen_foreign_memory_map_t;
343
+DEFINE_XEN_GUEST_HANDLE(xen_foreign_memory_map_t);
344
+
345
+#define XENMEM_set_pod_target       16
346
+#define XENMEM_get_pod_target       17
347
+struct xen_pod_target {
348
+    /* IN */
349
+    uint64_t target_pages;
350
+    /* OUT */
351
+    uint64_t tot_pages;
352
+    uint64_t pod_cache_pages;
353
+    uint64_t pod_entries;
354
+    /* IN */
355
+    domid_t domid;
356
+};
357
+typedef struct xen_pod_target xen_pod_target_t;
358
+
359
+#if defined(__XEN__) || defined(__XEN_TOOLS__)
360
+
361
+#ifndef uint64_aligned_t
362
+#define uint64_aligned_t uint64_t
363
+#endif
364
+
365
+/*
366
+ * Get the number of MFNs saved through memory sharing.
367
+ * The call never fails.
368
+ */
369
+#define XENMEM_get_sharing_freed_pages    18
370
+#define XENMEM_get_sharing_shared_pages   19
371
+
372
+#define XENMEM_paging_op                    20
373
+#define XENMEM_paging_op_nominate           0
374
+#define XENMEM_paging_op_evict              1
375
+#define XENMEM_paging_op_prep               2
376
+
377
+struct xen_mem_event_op {
378
+    uint8_t     op;         /* XENMEM_*_op_* */
379
+    domid_t     domain;
380
+
381
+
382
+    /* PAGING_PREP IN: buffer to immediately fill page in */
383
+    uint64_aligned_t    buffer;
384
+    /* Other OPs */
385
+    uint64_aligned_t    gfn;           /* IN:  gfn of page being operated on */
386
+};
387
+typedef struct xen_mem_event_op xen_mem_event_op_t;
388
+DEFINE_XEN_GUEST_HANDLE(xen_mem_event_op_t);
389
+
390
+#define XENMEM_access_op                    21
391
+#define XENMEM_access_op_resume             0
392
+#define XENMEM_access_op_set_access         1
393
+#define XENMEM_access_op_get_access         2
394
+
395
+typedef enum {
396
+    XENMEM_access_n,
397
+    XENMEM_access_r,
398
+    XENMEM_access_w,
399
+    XENMEM_access_rw,
400
+    XENMEM_access_x,
401
+    XENMEM_access_rx,
402
+    XENMEM_access_wx,
403
+    XENMEM_access_rwx,
404
+    /*
405
+     * Page starts off as r-x, but automatically
406
+     * change to r-w on a write
407
+     */
408
+    XENMEM_access_rx2rw,
409
+    /*
410
+     * Log access: starts off as n, automatically
411
+     * goes to rwx, generating an event without
412
+     * pausing the vcpu
413
+     */
414
+    XENMEM_access_n2rwx,
415
+    /* Take the domain default */
416
+    XENMEM_access_default
417
+} xenmem_access_t;
418
+
419
+struct xen_mem_access_op {
420
+    /* XENMEM_access_op_* */
421
+    uint8_t op;
422
+    /* xenmem_access_t */
423
+    uint8_t access;
424
+    domid_t domid;
425
+    /*
426
+     * Number of pages for set op
427
+     * Ignored on setting default access and other ops
428
+     */
429
+    uint32_t nr;
430
+    /*
431
+     * First pfn for set op
432
+     * pfn for get op
433
+     * ~0ull is used to set and get the default access for pages
434
+     */
435
+    uint64_aligned_t pfn;
436
+};
437
+typedef struct xen_mem_access_op xen_mem_access_op_t;
438
+DEFINE_XEN_GUEST_HANDLE(xen_mem_access_op_t);
439
+
440
+#define XENMEM_sharing_op                   22
441
+#define XENMEM_sharing_op_nominate_gfn      0
442
+#define XENMEM_sharing_op_nominate_gref     1
443
+#define XENMEM_sharing_op_share             2
444
+#define XENMEM_sharing_op_resume            3
445
+#define XENMEM_sharing_op_debug_gfn         4
446
+#define XENMEM_sharing_op_debug_mfn         5
447
+#define XENMEM_sharing_op_debug_gref        6
448
+#define XENMEM_sharing_op_add_physmap       7
449
+#define XENMEM_sharing_op_audit             8
450
+
451
+#define XENMEM_SHARING_OP_S_HANDLE_INVALID  (-10)
452
+#define XENMEM_SHARING_OP_C_HANDLE_INVALID  (-9)
453
+
454
+/* The following allows sharing of grant refs. This is useful
455
+ * for sharing utilities sitting as "filters" in IO backends
456
+ * (e.g. memshr + blktap(2)). The IO backend is only exposed
457
+ * to grant references, and this allows sharing of the grefs */
458
+#define XENMEM_SHARING_OP_FIELD_IS_GREF_FLAG   (1ULL << 62)
459
+
460
+#define XENMEM_SHARING_OP_FIELD_MAKE_GREF(field, val)  \
461
+    (field) = (XENMEM_SHARING_OP_FIELD_IS_GREF_FLAG | val)
462
+#define XENMEM_SHARING_OP_FIELD_IS_GREF(field)         \
463
+    ((field) & XENMEM_SHARING_OP_FIELD_IS_GREF_FLAG)
464
+#define XENMEM_SHARING_OP_FIELD_GET_GREF(field)        \
465
+    ((field) & (~XENMEM_SHARING_OP_FIELD_IS_GREF_FLAG))
466
+
467
+struct xen_mem_sharing_op {
468
+    uint8_t     op;     /* XENMEM_sharing_op_* */
469
+    domid_t     domain;
470
+
471
+    union {
472
+        struct mem_sharing_op_nominate {  /* OP_NOMINATE_xxx           */
473
+            union {
474
+                uint64_aligned_t gfn;     /* IN: gfn to nominate       */
475
+                uint32_t      grant_ref;  /* IN: grant ref to nominate */
476
+            } u;
477
+            uint64_aligned_t  handle;     /* OUT: the handle           */
478
+        } nominate;
479
+        struct mem_sharing_op_share {     /* OP_SHARE/ADD_PHYSMAP */
480
+            uint64_aligned_t source_gfn;    /* IN: the gfn of the source page */
481
+            uint64_aligned_t source_handle; /* IN: handle to the source page */
482
+            uint64_aligned_t client_gfn;    /* IN: the client gfn */
483
+            uint64_aligned_t client_handle; /* IN: handle to the client page */
484
+            domid_t  client_domain; /* IN: the client domain id */
485
+        } share;
486
+        struct mem_sharing_op_debug {     /* OP_DEBUG_xxx */
487
+            union {
488
+                uint64_aligned_t gfn;      /* IN: gfn to debug          */
489
+                uint64_aligned_t mfn;      /* IN: mfn to debug          */
490
+                uint32_t gref;     /* IN: gref to debug         */
491
+            } u;
492
+        } debug;
493
+    } u;
494
+};
495
+typedef struct xen_mem_sharing_op xen_mem_sharing_op_t;
496
+DEFINE_XEN_GUEST_HANDLE(xen_mem_sharing_op_t);
497
+
498
+/*
499
+ * Attempt to stake a claim for a domain on a quantity of pages
500
+ * of system RAM, but _not_ assign specific pageframes.  Only
501
+ * arithmetic is performed so the hypercall is very fast and need
502
+ * not be preemptible, thus sidestepping time-of-check-time-of-use
503
+ * races for memory allocation.  Returns 0 if the hypervisor page
504
+ * allocator has atomically and successfully claimed the requested
505
+ * number of pages, else non-zero.
506
+ *
507
+ * Any domain may have only one active claim.  When sufficient memory
508
+ * has been allocated to resolve the claim, the claim silently expires.
509
+ * Claiming zero pages effectively resets any outstanding claim and
510
+ * is always successful.
511
+ *
512
+ * Note that a valid claim may be staked even after memory has been
513
+ * allocated for a domain.  In this case, the claim is not incremental,
514
+ * i.e. if the domain's tot_pages is 3, and a claim is staked for 10,
515
+ * only 7 additional pages are claimed.
516
+ *
517
+ * Caller must be privileged or the hypercall fails.
518
+ */
519
+#define XENMEM_claim_pages                  24
520
+
521
+/*
522
+ * XENMEM_claim_pages flags - the are no flags at this time.
523
+ * The zero value is appropiate.
524
+ */
525
+
526
+#endif /* defined(__XEN__) || defined(__XEN_TOOLS__) */
527
+
528
+/* Next available subop number is 26 */
529
+
530
+#endif /* __XEN_PUBLIC_MEMORY_H__ */
531
+
532
+/*
533
+ * Local variables:
534
+ * mode: C
535
+ * c-file-style: "BSD"
536
+ * c-basic-offset: 4
537
+ * tab-width: 4
538
+ * indent-tabs-mode: nil
539
+ * End:
540
+ */

+ 332
- 0
src/include/xen/trace.h View File

@@ -0,0 +1,332 @@
1
+/******************************************************************************
2
+ * include/public/trace.h
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to
6
+ * deal in the Software without restriction, including without limitation the
7
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8
+ * sell copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20
+ * DEALINGS IN THE SOFTWARE.
21
+ *
22
+ * Mark Williamson, (C) 2004 Intel Research Cambridge
23
+ * Copyright (C) 2005 Bin Ren
24
+ */
25
+
26
+#ifndef __XEN_PUBLIC_TRACE_H__
27
+#define __XEN_PUBLIC_TRACE_H__
28
+
29
+FILE_LICENCE ( MIT );
30
+
31
+#define TRACE_EXTRA_MAX    7
32
+#define TRACE_EXTRA_SHIFT 28
33
+
34
+/* Trace classes */
35
+#define TRC_CLS_SHIFT 16
36
+#define TRC_GEN      0x0001f000    /* General trace            */
37
+#define TRC_SCHED    0x0002f000    /* Xen Scheduler trace      */
38
+#define TRC_DOM0OP   0x0004f000    /* Xen DOM0 operation trace */
39
+#define TRC_HVM      0x0008f000    /* Xen HVM trace            */
40
+#define TRC_MEM      0x0010f000    /* Xen memory trace         */
41
+#define TRC_PV       0x0020f000    /* Xen PV traces            */
42
+#define TRC_SHADOW   0x0040f000    /* Xen shadow tracing       */
43
+#define TRC_HW       0x0080f000    /* Xen hardware-related traces */
44
+#define TRC_GUEST    0x0800f000    /* Guest-generated traces   */
45
+#define TRC_ALL      0x0ffff000
46
+#define TRC_HD_TO_EVENT(x) ((x)&0x0fffffff)
47
+#define TRC_HD_CYCLE_FLAG (1UL<<31)
48
+#define TRC_HD_INCLUDES_CYCLE_COUNT(x) ( !!( (x) & TRC_HD_CYCLE_FLAG ) )
49
+#define TRC_HD_EXTRA(x)    (((x)>>TRACE_EXTRA_SHIFT)&TRACE_EXTRA_MAX)
50
+
51
+/* Trace subclasses */
52
+#define TRC_SUBCLS_SHIFT 12
53
+
54
+/* trace subclasses for SVM */
55
+#define TRC_HVM_ENTRYEXIT   0x00081000   /* VMENTRY and #VMEXIT       */
56
+#define TRC_HVM_HANDLER     0x00082000   /* various HVM handlers      */
57
+#define TRC_HVM_EMUL        0x00084000   /* emulated devices */
58
+
59
+#define TRC_SCHED_MIN       0x00021000   /* Just runstate changes */
60
+#define TRC_SCHED_CLASS     0x00022000   /* Scheduler-specific    */
61
+#define TRC_SCHED_VERBOSE   0x00028000   /* More inclusive scheduling */
62
+
63
+/*
64
+ * The highest 3 bits of the last 12 bits of TRC_SCHED_CLASS above are
65
+ * reserved for encoding what scheduler produced the information. The
66
+ * actual event is encoded in the last 9 bits.
67
+ *
68
+ * This means we have 8 scheduling IDs available (which means at most 8
69
+ * schedulers generating events) and, in each scheduler, up to 512
70
+ * different events.
71
+ */
72
+#define TRC_SCHED_ID_BITS 3
73
+#define TRC_SCHED_ID_SHIFT (TRC_SUBCLS_SHIFT - TRC_SCHED_ID_BITS)
74
+#define TRC_SCHED_ID_MASK (((1UL<<TRC_SCHED_ID_BITS) - 1) << TRC_SCHED_ID_SHIFT)
75
+#define TRC_SCHED_EVT_MASK (~(TRC_SCHED_ID_MASK))
76
+
77
+/* Per-scheduler IDs, to identify scheduler specific events */
78
+#define TRC_SCHED_CSCHED   0
79
+#define TRC_SCHED_CSCHED2  1
80
+#define TRC_SCHED_SEDF     2
81
+#define TRC_SCHED_ARINC653 3
82
+
83
+/* Per-scheduler tracing */
84
+#define TRC_SCHED_CLASS_EVT(_c, _e) \
85
+  ( ( TRC_SCHED_CLASS | \
86
+      ((TRC_SCHED_##_c << TRC_SCHED_ID_SHIFT) & TRC_SCHED_ID_MASK) ) + \
87
+    (_e & TRC_SCHED_EVT_MASK) )
88
+
89
+/* Trace classes for Hardware */
90
+#define TRC_HW_PM           0x00801000   /* Power management traces */
91
+#define TRC_HW_IRQ          0x00802000   /* Traces relating to the handling of IRQs */
92
+
93
+/* Trace events per class */
94
+#define TRC_LOST_RECORDS        (TRC_GEN + 1)
95
+#define TRC_TRACE_WRAP_BUFFER  (TRC_GEN + 2)
96
+#define TRC_TRACE_CPU_CHANGE    (TRC_GEN + 3)
97
+
98
+#define TRC_SCHED_RUNSTATE_CHANGE   (TRC_SCHED_MIN + 1)
99
+#define TRC_SCHED_CONTINUE_RUNNING  (TRC_SCHED_MIN + 2)
100
+#define TRC_SCHED_DOM_ADD        (TRC_SCHED_VERBOSE +  1)
101
+#define TRC_SCHED_DOM_REM        (TRC_SCHED_VERBOSE +  2)
102
+#define TRC_SCHED_SLEEP          (TRC_SCHED_VERBOSE +  3)
103
+#define TRC_SCHED_WAKE           (TRC_SCHED_VERBOSE +  4)
104
+#define TRC_SCHED_YIELD          (TRC_SCHED_VERBOSE +  5)
105
+#define TRC_SCHED_BLOCK          (TRC_SCHED_VERBOSE +  6)
106
+#define TRC_SCHED_SHUTDOWN       (TRC_SCHED_VERBOSE +  7)
107
+#define TRC_SCHED_CTL            (TRC_SCHED_VERBOSE +  8)
108
+#define TRC_SCHED_ADJDOM         (TRC_SCHED_VERBOSE +  9)
109
+#define TRC_SCHED_SWITCH         (TRC_SCHED_VERBOSE + 10)
110
+#define TRC_SCHED_S_TIMER_FN     (TRC_SCHED_VERBOSE + 11)
111
+#define TRC_SCHED_T_TIMER_FN     (TRC_SCHED_VERBOSE + 12)
112
+#define TRC_SCHED_DOM_TIMER_FN   (TRC_SCHED_VERBOSE + 13)
113
+#define TRC_SCHED_SWITCH_INFPREV (TRC_SCHED_VERBOSE + 14)
114
+#define TRC_SCHED_SWITCH_INFNEXT (TRC_SCHED_VERBOSE + 15)
115
+#define TRC_SCHED_SHUTDOWN_CODE  (TRC_SCHED_VERBOSE + 16)
116
+
117
+#define TRC_MEM_PAGE_GRANT_MAP      (TRC_MEM + 1)
118
+#define TRC_MEM_PAGE_GRANT_UNMAP    (TRC_MEM + 2)
119
+#define TRC_MEM_PAGE_GRANT_TRANSFER (TRC_MEM + 3)
120
+#define TRC_MEM_SET_P2M_ENTRY       (TRC_MEM + 4)
121
+#define TRC_MEM_DECREASE_RESERVATION (TRC_MEM + 5)
122
+#define TRC_MEM_POD_POPULATE        (TRC_MEM + 16)
123
+#define TRC_MEM_POD_ZERO_RECLAIM    (TRC_MEM + 17)
124
+#define TRC_MEM_POD_SUPERPAGE_SPLINTER (TRC_MEM + 18)
125
+
126
+#define TRC_PV_ENTRY   0x00201000 /* Hypervisor entry points for PV guests. */
127
+#define TRC_PV_SUBCALL 0x00202000 /* Sub-call in a multicall hypercall */
128
+
129
+#define TRC_PV_HYPERCALL             (TRC_PV_ENTRY +  1)
130
+#define TRC_PV_TRAP                  (TRC_PV_ENTRY +  3)
131
+#define TRC_PV_PAGE_FAULT            (TRC_PV_ENTRY +  4)
132
+#define TRC_PV_FORCED_INVALID_OP     (TRC_PV_ENTRY +  5)
133
+#define TRC_PV_EMULATE_PRIVOP        (TRC_PV_ENTRY +  6)
134
+#define TRC_PV_EMULATE_4GB           (TRC_PV_ENTRY +  7)
135
+#define TRC_PV_MATH_STATE_RESTORE    (TRC_PV_ENTRY +  8)
136
+#define TRC_PV_PAGING_FIXUP          (TRC_PV_ENTRY +  9)
137
+#define TRC_PV_GDT_LDT_MAPPING_FAULT (TRC_PV_ENTRY + 10)
138
+#define TRC_PV_PTWR_EMULATION        (TRC_PV_ENTRY + 11)
139
+#define TRC_PV_PTWR_EMULATION_PAE    (TRC_PV_ENTRY + 12)
140
+#define TRC_PV_HYPERCALL_V2          (TRC_PV_ENTRY + 13)
141
+#define TRC_PV_HYPERCALL_SUBCALL     (TRC_PV_SUBCALL + 14)
142
+
143
+/*
144
+ * TRC_PV_HYPERCALL_V2 format
145
+ *
146
+ * Only some of the hypercall argument are recorded. Bit fields A0 to
147
+ * A5 in the first extra word are set if the argument is present and
148
+ * the arguments themselves are packed sequentially in the following
149
+ * words.
150
+ *
151
+ * The TRC_64_FLAG bit is not set for these events (even if there are
152
+ * 64-bit arguments in the record).
153
+ *
154
+ * Word
155
+ * 0    bit 31 30|29 28|27 26|25 24|23 22|21 20|19 ... 0
156
+ *          A5   |A4   |A3   |A2   |A1   |A0   |Hypercall op
157
+ * 1    First 32 bit (or low word of first 64 bit) arg in record
158
+ * 2    Second 32 bit (or high word of first 64 bit) arg in record
159
+ * ...
160
+ *
161
+ * A0-A5 bitfield values:
162
+ *
163
+ *   00b  Argument not present
164
+ *   01b  32-bit argument present
165
+ *   10b  64-bit argument present
166
+ *   11b  Reserved
167
+ */
168
+#define TRC_PV_HYPERCALL_V2_ARG_32(i) (0x1 << (20 + 2*(i)))
169
+#define TRC_PV_HYPERCALL_V2_ARG_64(i) (0x2 << (20 + 2*(i)))
170
+#define TRC_PV_HYPERCALL_V2_ARG_MASK  (0xfff00000)
171
+
172
+#define TRC_SHADOW_NOT_SHADOW                 (TRC_SHADOW +  1)
173
+#define TRC_SHADOW_FAST_PROPAGATE             (TRC_SHADOW +  2)
174
+#define TRC_SHADOW_FAST_MMIO                  (TRC_SHADOW +  3)
175
+#define TRC_SHADOW_FALSE_FAST_PATH            (TRC_SHADOW +  4)
176
+#define TRC_SHADOW_MMIO                       (TRC_SHADOW +  5)
177
+#define TRC_SHADOW_FIXUP                      (TRC_SHADOW +  6)
178
+#define TRC_SHADOW_DOMF_DYING                 (TRC_SHADOW +  7)
179
+#define TRC_SHADOW_EMULATE                    (TRC_SHADOW +  8)
180
+#define TRC_SHADOW_EMULATE_UNSHADOW_USER      (TRC_SHADOW +  9)
181
+#define TRC_SHADOW_EMULATE_UNSHADOW_EVTINJ    (TRC_SHADOW + 10)
182
+#define TRC_SHADOW_EMULATE_UNSHADOW_UNHANDLED (TRC_SHADOW + 11)
183
+#define TRC_SHADOW_WRMAP_BF                   (TRC_SHADOW + 12)
184
+#define TRC_SHADOW_PREALLOC_UNPIN             (TRC_SHADOW + 13)
185
+#define TRC_SHADOW_RESYNC_FULL                (TRC_SHADOW + 14)
186
+#define TRC_SHADOW_RESYNC_ONLY                (TRC_SHADOW + 15)
187
+
188
+/* trace events per subclass */
189
+#define TRC_HVM_NESTEDFLAG      (0x400)
190
+#define TRC_HVM_VMENTRY         (TRC_HVM_ENTRYEXIT + 0x01)
191
+#define TRC_HVM_VMEXIT          (TRC_HVM_ENTRYEXIT + 0x02)
192
+#define TRC_HVM_VMEXIT64        (TRC_HVM_ENTRYEXIT + TRC_64_FLAG + 0x02)
193
+#define TRC_HVM_PF_XEN          (TRC_HVM_HANDLER + 0x01)
194
+#define TRC_HVM_PF_XEN64        (TRC_HVM_HANDLER + TRC_64_FLAG + 0x01)
195
+#define TRC_HVM_PF_INJECT       (TRC_HVM_HANDLER + 0x02)
196
+#define TRC_HVM_PF_INJECT64     (TRC_HVM_HANDLER + TRC_64_FLAG + 0x02)
197
+#define TRC_HVM_INJ_EXC         (TRC_HVM_HANDLER + 0x03)
198
+#define TRC_HVM_INJ_VIRQ        (TRC_HVM_HANDLER + 0x04)
199
+#define TRC_HVM_REINJ_VIRQ      (TRC_HVM_HANDLER + 0x05)
200
+#define TRC_HVM_IO_READ         (TRC_HVM_HANDLER + 0x06)
201
+#define TRC_HVM_IO_WRITE        (TRC_HVM_HANDLER + 0x07)
202
+#define TRC_HVM_CR_READ         (TRC_HVM_HANDLER + 0x08)
203
+#define TRC_HVM_CR_READ64       (TRC_HVM_HANDLER + TRC_64_FLAG + 0x08)
204
+#define TRC_HVM_CR_WRITE        (TRC_HVM_HANDLER + 0x09)
205
+#define TRC_HVM_CR_WRITE64      (TRC_HVM_HANDLER + TRC_64_FLAG + 0x09)
206
+#define TRC_HVM_DR_READ         (TRC_HVM_HANDLER + 0x0A)
207
+#define TRC_HVM_DR_WRITE        (TRC_HVM_HANDLER + 0x0B)
208
+#define TRC_HVM_MSR_READ        (TRC_HVM_HANDLER + 0x0C)
209
+#define TRC_HVM_MSR_WRITE       (TRC_HVM_HANDLER + 0x0D)
210
+#define TRC_HVM_CPUID           (TRC_HVM_HANDLER + 0x0E)
211
+#define TRC_HVM_INTR            (TRC_HVM_HANDLER + 0x0F)
212
+#define TRC_HVM_NMI             (TRC_HVM_HANDLER + 0x10)
213
+#define TRC_HVM_SMI             (TRC_HVM_HANDLER + 0x11)
214
+#define TRC_HVM_VMMCALL         (TRC_HVM_HANDLER + 0x12)
215
+#define TRC_HVM_HLT             (TRC_HVM_HANDLER + 0x13)
216
+#define TRC_HVM_INVLPG          (TRC_HVM_HANDLER + 0x14)
217
+#define TRC_HVM_INVLPG64        (TRC_HVM_HANDLER + TRC_64_FLAG + 0x14)
218
+#define TRC_HVM_MCE             (TRC_HVM_HANDLER + 0x15)
219
+#define TRC_HVM_IOPORT_READ     (TRC_HVM_HANDLER + 0x16)
220
+#define TRC_HVM_IOMEM_READ      (TRC_HVM_HANDLER + 0x17)
221
+#define TRC_HVM_CLTS            (TRC_HVM_HANDLER + 0x18)
222
+#define TRC_HVM_LMSW            (TRC_HVM_HANDLER + 0x19)
223
+#define TRC_HVM_LMSW64          (TRC_HVM_HANDLER + TRC_64_FLAG + 0x19)
224
+#define TRC_HVM_RDTSC           (TRC_HVM_HANDLER + 0x1a)
225
+#define TRC_HVM_INTR_WINDOW     (TRC_HVM_HANDLER + 0x20)
226
+#define TRC_HVM_NPF             (TRC_HVM_HANDLER + 0x21)
227
+#define TRC_HVM_REALMODE_EMULATE (TRC_HVM_HANDLER + 0x22)
228
+#define TRC_HVM_TRAP             (TRC_HVM_HANDLER + 0x23)
229
+#define TRC_HVM_TRAP_DEBUG       (TRC_HVM_HANDLER + 0x24)
230
+#define TRC_HVM_VLAPIC           (TRC_HVM_HANDLER + 0x25)
231
+
232
+#define TRC_HVM_IOPORT_WRITE    (TRC_HVM_HANDLER + 0x216)
233
+#define TRC_HVM_IOMEM_WRITE     (TRC_HVM_HANDLER + 0x217)
234
+
235
+/* Trace events for emulated devices */
236
+#define TRC_HVM_EMUL_HPET_START_TIMER  (TRC_HVM_EMUL + 0x1)
237
+#define TRC_HVM_EMUL_PIT_START_TIMER   (TRC_HVM_EMUL + 0x2)
238
+#define TRC_HVM_EMUL_RTC_START_TIMER   (TRC_HVM_EMUL + 0x3)
239
+#define TRC_HVM_EMUL_LAPIC_START_TIMER (TRC_HVM_EMUL + 0x4)
240
+#define TRC_HVM_EMUL_HPET_STOP_TIMER   (TRC_HVM_EMUL + 0x5)
241
+#define TRC_HVM_EMUL_PIT_STOP_TIMER    (TRC_HVM_EMUL + 0x6)
242
+#define TRC_HVM_EMUL_RTC_STOP_TIMER    (TRC_HVM_EMUL + 0x7)
243
+#define TRC_HVM_EMUL_LAPIC_STOP_TIMER  (TRC_HVM_EMUL + 0x8)
244
+#define TRC_HVM_EMUL_PIT_TIMER_CB      (TRC_HVM_EMUL + 0x9)
245
+#define TRC_HVM_EMUL_LAPIC_TIMER_CB    (TRC_HVM_EMUL + 0xA)
246
+#define TRC_HVM_EMUL_PIC_INT_OUTPUT    (TRC_HVM_EMUL + 0xB)
247
+#define TRC_HVM_EMUL_PIC_KICK          (TRC_HVM_EMUL + 0xC)
248
+#define TRC_HVM_EMUL_PIC_INTACK        (TRC_HVM_EMUL + 0xD)
249
+#define TRC_HVM_EMUL_PIC_POSEDGE       (TRC_HVM_EMUL + 0xE)
250
+#define TRC_HVM_EMUL_PIC_NEGEDGE       (TRC_HVM_EMUL + 0xF)
251
+#define TRC_HVM_EMUL_PIC_PEND_IRQ_CALL (TRC_HVM_EMUL + 0x10)
252
+#define TRC_HVM_EMUL_LAPIC_PIC_INTR    (TRC_HVM_EMUL + 0x11)
253
+
254
+/* trace events for per class */
255
+#define TRC_PM_FREQ_CHANGE      (TRC_HW_PM + 0x01)
256
+#define TRC_PM_IDLE_ENTRY       (TRC_HW_PM + 0x02)
257
+#define TRC_PM_IDLE_EXIT        (TRC_HW_PM + 0x03)
258
+
259
+/* Trace events for IRQs */
260
+#define TRC_HW_IRQ_MOVE_CLEANUP_DELAY (TRC_HW_IRQ + 0x1)
261
+#define TRC_HW_IRQ_MOVE_CLEANUP       (TRC_HW_IRQ + 0x2)
262
+#define TRC_HW_IRQ_BIND_VECTOR        (TRC_HW_IRQ + 0x3)
263
+#define TRC_HW_IRQ_CLEAR_VECTOR       (TRC_HW_IRQ + 0x4)
264
+#define TRC_HW_IRQ_MOVE_FINISH        (TRC_HW_IRQ + 0x5)
265
+#define TRC_HW_IRQ_ASSIGN_VECTOR      (TRC_HW_IRQ + 0x6)
266
+#define TRC_HW_IRQ_UNMAPPED_VECTOR    (TRC_HW_IRQ + 0x7)
267
+#define TRC_HW_IRQ_HANDLED            (TRC_HW_IRQ + 0x8)
268
+
269
+/*
270
+ * Event Flags
271
+ *
272
+ * Some events (e.g, TRC_PV_TRAP and TRC_HVM_IOMEM_READ) have multiple
273
+ * record formats.  These event flags distinguish between the
274
+ * different formats.
275
+ */
276
+#define TRC_64_FLAG 0x100 /* Addresses are 64 bits (instead of 32 bits) */
277
+
278
+/* This structure represents a single trace buffer record. */
279
+struct t_rec {
280
+    uint32_t event:28;
281
+    uint32_t extra_u32:3;         /* # entries in trailing extra_u32[] array */
282
+    uint32_t cycles_included:1;   /* u.cycles or u.no_cycles? */
283
+    union {
284
+        struct {
285
+            uint32_t cycles_lo, cycles_hi; /* cycle counter timestamp */
286
+            uint32_t extra_u32[7];         /* event data items */
287
+        } cycles;
288
+        struct {
289
+            uint32_t extra_u32[7];         /* event data items */
290
+        } nocycles;
291
+    } u;
292
+};
293
+
294
+/*
295
+ * This structure contains the metadata for a single trace buffer.  The head
296
+ * field, indexes into an array of struct t_rec's.
297
+ */
298
+struct t_buf {
299
+    /* Assume the data buffer size is X.  X is generally not a power of 2.
300
+     * CONS and PROD are incremented modulo (2*X):
301
+     *     0 <= cons < 2*X
302
+     *     0 <= prod < 2*X
303
+     * This is done because addition modulo X breaks at 2^32 when X is not a
304
+     * power of 2:
305
+     *     (((2^32 - 1) % X) + 1) % X != (2^32) % X
306
+     */
307
+    uint32_t cons;   /* Offset of next item to be consumed by control tools. */
308
+    uint32_t prod;   /* Offset of next item to be produced by Xen.           */
309
+    /*  Records follow immediately after the meta-data header.    */
310
+};
311
+
312
+/* Structure used to pass MFNs to the trace buffers back to trace consumers.
313
+ * Offset is an offset into the mapped structure where the mfn list will be held.
314
+ * MFNs will be at ((unsigned long *)(t_info))+(t_info->cpu_offset[cpu]).
315
+ */
316
+struct t_info {
317
+    uint16_t tbuf_size; /* Size in pages of each trace buffer */
318
+    uint16_t mfn_offset[];  /* Offset within t_info structure of the page list per cpu */
319
+    /* MFN lists immediately after the header */
320
+};
321
+
322
+#endif /* __XEN_PUBLIC_TRACE_H__ */
323
+
324
+/*
325
+ * Local variables:
326
+ * mode: C
327
+ * c-file-style: "BSD"
328
+ * c-basic-offset: 4
329
+ * tab-width: 4
330
+ * indent-tabs-mode: nil
331
+ * End:
332
+ */

+ 98
- 0
src/include/xen/version.h View File

@@ -0,0 +1,98 @@
1
+/******************************************************************************
2
+ * version.h
3
+ *
4
+ * Xen version, type, and compile information.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to
8
+ * deal in the Software without restriction, including without limitation the
9
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10
+ * sell copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in
14
+ * all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22
+ * DEALINGS IN THE SOFTWARE.
23
+ *
24
+ * Copyright (c) 2005, Nguyen Anh Quynh <aquynh@gmail.com>
25
+ * Copyright (c) 2005, Keir Fraser <keir@xensource.com>
26
+ */
27
+
28
+#ifndef __XEN_PUBLIC_VERSION_H__
29
+#define __XEN_PUBLIC_VERSION_H__
30
+
31
+FILE_LICENCE ( MIT );
32
+
33
+#include "xen.h"
34
+
35
+/* NB. All ops return zero on success, except XENVER_{version,pagesize} */
36
+
37
+/* arg == NULL; returns major:minor (16:16). */
38
+#define XENVER_version      0
39
+
40
+/* arg == xen_extraversion_t. */
41
+#define XENVER_extraversion 1
42
+typedef char xen_extraversion_t[16];
43
+#define XEN_EXTRAVERSION_LEN (sizeof(xen_extraversion_t))
44
+
45
+/* arg == xen_compile_info_t. */
46
+#define XENVER_compile_info 2
47
+struct xen_compile_info {
48
+    char compiler[64];
49
+    char compile_by[16];
50
+    char compile_domain[32];
51
+    char compile_date[32];
52
+};
53
+typedef struct xen_compile_info xen_compile_info_t;
54
+
55
+#define XENVER_capabilities 3
56
+typedef char xen_capabilities_info_t[1024];
57
+#define XEN_CAPABILITIES_INFO_LEN (sizeof(xen_capabilities_info_t))
58
+
59
+#define XENVER_changeset 4
60
+typedef char xen_changeset_info_t[64];
61
+#define XEN_CHANGESET_INFO_LEN (sizeof(xen_changeset_info_t))
62
+
63
+#define XENVER_platform_parameters 5
64
+struct xen_platform_parameters {
65
+    xen_ulong_t virt_start;
66
+};
67
+typedef struct xen_platform_parameters xen_platform_parameters_t;
68
+
69
+#define XENVER_get_features 6
70
+struct xen_feature_info {
71
+    unsigned int submap_idx;    /* IN: which 32-bit submap to return */
72
+    uint32_t     submap;        /* OUT: 32-bit submap */
73
+};
74
+typedef struct xen_feature_info xen_feature_info_t;
75
+
76
+/* Declares the features reported by XENVER_get_features. */
77
+#include "features.h"
78
+
79
+/* arg == NULL; returns host memory page size. */
80
+#define XENVER_pagesize 7
81
+
82
+/* arg == xen_domain_handle_t. */
83
+#define XENVER_guest_handle 8
84
+
85
+#define XENVER_commandline 9
86
+typedef char xen_commandline_t[1024];
87
+
88
+#endif /* __XEN_PUBLIC_VERSION_H__ */
89
+
90
+/*
91
+ * Local variables:
92
+ * mode: C
93
+ * c-file-style: "BSD"
94
+ * c-basic-offset: 4
95
+ * tab-width: 4
96
+ * indent-tabs-mode: nil
97
+ * End:
98
+ */

+ 46
- 0
src/include/xen/xen-compat.h View File

@@ -0,0 +1,46 @@
1
+/******************************************************************************
2
+ * xen-compat.h
3
+ *
4
+ * Guest OS interface to Xen.  Compatibility layer.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to
8
+ * deal in the Software without restriction, including without limitation the
9
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10
+ * sell copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in
14
+ * all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22
+ * DEALINGS IN THE SOFTWARE.
23
+ *
24
+ * Copyright (c) 2006, Christian Limpach
25
+ */
26
+
27
+#ifndef __XEN_PUBLIC_XEN_COMPAT_H__
28
+#define __XEN_PUBLIC_XEN_COMPAT_H__
29
+
30
+FILE_LICENCE ( MIT );
31
+
32
+#define __XEN_LATEST_INTERFACE_VERSION__ 0x00040400
33
+
34
+#if defined(__XEN__) || defined(__XEN_TOOLS__)
35
+/* Xen is built with matching headers and implements the latest interface. */
36
+#define __XEN_INTERFACE_VERSION__ __XEN_LATEST_INTERFACE_VERSION__
37
+#elif !defined(__XEN_INTERFACE_VERSION__)
38
+/* Guests which do not specify a version get the legacy interface. */
39
+#define __XEN_INTERFACE_VERSION__ 0x00000000
40
+#endif
41
+
42
+#if __XEN_INTERFACE_VERSION__ > __XEN_LATEST_INTERFACE_VERSION__
43
+#error "These header files do not support the requested interface version."
44
+#endif
45
+
46
+#endif /* __XEN_PUBLIC_XEN_COMPAT_H__ */

+ 901
- 0
src/include/xen/xen.h View File

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

Loading…
Cancel
Save