xref: /openbmc/qemu/include/hw/xen/interface/hvm/hvm_op.h (revision 2b74dd91)
1 /* SPDX-License-Identifier: MIT */
2 /*
3  * Copyright (c) 2007, Keir Fraser
4  */
5 
6 #ifndef __XEN_PUBLIC_HVM_HVM_OP_H__
7 #define __XEN_PUBLIC_HVM_HVM_OP_H__
8 
9 #include "../xen.h"
10 #include "../trace.h"
11 #include "../event_channel.h"
12 
13 /* Get/set subcommands: extra argument == pointer to xen_hvm_param struct. */
14 #define HVMOP_set_param           0
15 #define HVMOP_get_param           1
16 struct xen_hvm_param {
17     domid_t  domid;    /* IN */
18     uint16_t pad;
19     uint32_t index;    /* IN */
20     uint64_t value;    /* IN/OUT */
21 };
22 typedef struct xen_hvm_param xen_hvm_param_t;
23 DEFINE_XEN_GUEST_HANDLE(xen_hvm_param_t);
24 
25 struct xen_hvm_altp2m_suppress_ve {
26     uint16_t view;
27     uint8_t suppress_ve; /* Boolean type. */
28     uint8_t pad1;
29     uint32_t pad2;
30     uint64_t gfn;
31 };
32 
33 struct xen_hvm_altp2m_suppress_ve_multi {
34     uint16_t view;
35     uint8_t suppress_ve; /* Boolean type. */
36     uint8_t pad1;
37     int32_t first_error; /* Should be set to 0. */
38     uint64_t first_gfn; /* Value may be updated. */
39     uint64_t last_gfn;
40     uint64_t first_error_gfn; /* Gfn of the first error. */
41 };
42 
43 #if __XEN_INTERFACE_VERSION__ < 0x00040900
44 
45 /* Set the logical level of one of a domain's PCI INTx wires. */
46 #define HVMOP_set_pci_intx_level  2
47 struct xen_hvm_set_pci_intx_level {
48     /* Domain to be updated. */
49     domid_t  domid;
50     /* PCI INTx identification in PCI topology (domain:bus:device:intx). */
51     uint8_t  domain, bus, device, intx;
52     /* Assertion level (0 = unasserted, 1 = asserted). */
53     uint8_t  level;
54 };
55 typedef struct xen_hvm_set_pci_intx_level xen_hvm_set_pci_intx_level_t;
56 DEFINE_XEN_GUEST_HANDLE(xen_hvm_set_pci_intx_level_t);
57 
58 /* Set the logical level of one of a domain's ISA IRQ wires. */
59 #define HVMOP_set_isa_irq_level   3
60 struct xen_hvm_set_isa_irq_level {
61     /* Domain to be updated. */
62     domid_t  domid;
63     /* ISA device identification, by ISA IRQ (0-15). */
64     uint8_t  isa_irq;
65     /* Assertion level (0 = unasserted, 1 = asserted). */
66     uint8_t  level;
67 };
68 typedef struct xen_hvm_set_isa_irq_level xen_hvm_set_isa_irq_level_t;
69 DEFINE_XEN_GUEST_HANDLE(xen_hvm_set_isa_irq_level_t);
70 
71 #define HVMOP_set_pci_link_route  4
72 struct xen_hvm_set_pci_link_route {
73     /* Domain to be updated. */
74     domid_t  domid;
75     /* PCI link identifier (0-3). */
76     uint8_t  link;
77     /* ISA IRQ (1-15), or 0 (disable link). */
78     uint8_t  isa_irq;
79 };
80 typedef struct xen_hvm_set_pci_link_route xen_hvm_set_pci_link_route_t;
81 DEFINE_XEN_GUEST_HANDLE(xen_hvm_set_pci_link_route_t);
82 
83 #endif /* __XEN_INTERFACE_VERSION__ < 0x00040900 */
84 
85 /* Flushes all VCPU TLBs: @arg must be NULL. */
86 #define HVMOP_flush_tlbs          5
87 
88 /*
89  * hvmmem_type_t should not be defined when generating the corresponding
90  * compat header. This will ensure that the improperly named HVMMEM_(*)
91  * values are defined only once.
92  */
93 #ifndef XEN_GENERATING_COMPAT_HEADERS
94 
95 typedef enum {
96     HVMMEM_ram_rw,             /* Normal read/write guest RAM */
97     HVMMEM_ram_ro,             /* Read-only; writes are discarded */
98     HVMMEM_mmio_dm,            /* Reads and write go to the device model */
99 #if __XEN_INTERFACE_VERSION__ < 0x00040700
100     HVMMEM_mmio_write_dm,      /* Read-only; writes go to the device model */
101 #else
102     HVMMEM_unused,             /* Placeholder; setting memory to this type
103                                   will fail for code after 4.7.0 */
104 #endif
105     HVMMEM_ioreq_server        /* Memory type claimed by an ioreq server; type
106                                   changes to this value are only allowed after
107                                   an ioreq server has claimed its ownership.
108                                   Only pages with HVMMEM_ram_rw are allowed to
109                                   change to this type; conversely, pages with
110                                   this type are only allowed to be changed back
111                                   to HVMMEM_ram_rw. */
112 } hvmmem_type_t;
113 
114 #endif /* XEN_GENERATING_COMPAT_HEADERS */
115 
116 /* Hint from PV drivers for pagetable destruction. */
117 #define HVMOP_pagetable_dying        9
118 struct xen_hvm_pagetable_dying {
119     /* Domain with a pagetable about to be destroyed. */
120     domid_t  domid;
121     uint16_t pad[3]; /* align next field on 8-byte boundary */
122     /* guest physical address of the toplevel pagetable dying */
123     uint64_t gpa;
124 };
125 typedef struct xen_hvm_pagetable_dying xen_hvm_pagetable_dying_t;
126 DEFINE_XEN_GUEST_HANDLE(xen_hvm_pagetable_dying_t);
127 
128 /* Get the current Xen time, in nanoseconds since system boot. */
129 #define HVMOP_get_time              10
130 struct xen_hvm_get_time {
131     uint64_t now;      /* OUT */
132 };
133 typedef struct xen_hvm_get_time xen_hvm_get_time_t;
134 DEFINE_XEN_GUEST_HANDLE(xen_hvm_get_time_t);
135 
136 #define HVMOP_xentrace              11
137 struct xen_hvm_xentrace {
138     uint16_t event, extra_bytes;
139     uint8_t extra[TRACE_EXTRA_MAX * sizeof(uint32_t)];
140 };
141 typedef struct xen_hvm_xentrace xen_hvm_xentrace_t;
142 DEFINE_XEN_GUEST_HANDLE(xen_hvm_xentrace_t);
143 
144 /* Following tools-only interfaces may change in future. */
145 #if defined(__XEN__) || defined(__XEN_TOOLS__)
146 
147 /* Deprecated by XENMEM_access_op_set_access */
148 #define HVMOP_set_mem_access        12
149 
150 /* Deprecated by XENMEM_access_op_get_access */
151 #define HVMOP_get_mem_access        13
152 
153 #endif /* defined(__XEN__) || defined(__XEN_TOOLS__) */
154 
155 #define HVMOP_get_mem_type    15
156 /* Return hvmmem_type_t for the specified pfn. */
157 struct xen_hvm_get_mem_type {
158     /* Domain to be queried. */
159     domid_t domid;
160     /* OUT variable. */
161     uint16_t mem_type;
162     uint16_t pad[2]; /* align next field on 8-byte boundary */
163     /* IN variable. */
164     uint64_t pfn;
165 };
166 typedef struct xen_hvm_get_mem_type xen_hvm_get_mem_type_t;
167 DEFINE_XEN_GUEST_HANDLE(xen_hvm_get_mem_type_t);
168 
169 /* Following tools-only interfaces may change in future. */
170 #if defined(__XEN__) || defined(__XEN_TOOLS__)
171 
172 /*
173  * Definitions relating to DMOP_create_ioreq_server. (Defined here for
174  * backwards compatibility).
175  */
176 
177 #define HVM_IOREQSRV_BUFIOREQ_OFF    0
178 #define HVM_IOREQSRV_BUFIOREQ_LEGACY 1
179 /*
180  * Use this when read_pointer gets updated atomically and
181  * the pointer pair gets read atomically:
182  */
183 #define HVM_IOREQSRV_BUFIOREQ_ATOMIC 2
184 
185 #endif /* defined(__XEN__) || defined(__XEN_TOOLS__) */
186 
187 #if defined(__i386__) || defined(__x86_64__)
188 
189 /*
190  * HVMOP_set_evtchn_upcall_vector: Set a <vector> that should be used for event
191  *                                 channel upcalls on the specified <vcpu>. If set,
192  *                                 this vector will be used in preference to the
193  *                                 domain global callback via (see
194  *                                 HVM_PARAM_CALLBACK_IRQ).
195  */
196 #define HVMOP_set_evtchn_upcall_vector 23
197 struct xen_hvm_evtchn_upcall_vector {
198     uint32_t vcpu;
199     uint8_t vector;
200 };
201 typedef struct xen_hvm_evtchn_upcall_vector xen_hvm_evtchn_upcall_vector_t;
202 DEFINE_XEN_GUEST_HANDLE(xen_hvm_evtchn_upcall_vector_t);
203 
204 #endif /* defined(__i386__) || defined(__x86_64__) */
205 
206 #define HVMOP_guest_request_vm_event 24
207 
208 /* HVMOP_altp2m: perform altp2m state operations */
209 #define HVMOP_altp2m 25
210 
211 #define HVMOP_ALTP2M_INTERFACE_VERSION 0x00000001
212 
213 struct xen_hvm_altp2m_domain_state {
214     /* IN or OUT variable on/off */
215     uint8_t state;
216 };
217 typedef struct xen_hvm_altp2m_domain_state xen_hvm_altp2m_domain_state_t;
218 DEFINE_XEN_GUEST_HANDLE(xen_hvm_altp2m_domain_state_t);
219 
220 struct xen_hvm_altp2m_vcpu_enable_notify {
221     uint32_t vcpu_id;
222     uint32_t pad;
223     /* #VE info area gfn */
224     uint64_t gfn;
225 };
226 typedef struct xen_hvm_altp2m_vcpu_enable_notify xen_hvm_altp2m_vcpu_enable_notify_t;
227 DEFINE_XEN_GUEST_HANDLE(xen_hvm_altp2m_vcpu_enable_notify_t);
228 
229 struct xen_hvm_altp2m_vcpu_disable_notify {
230     uint32_t vcpu_id;
231 };
232 typedef struct xen_hvm_altp2m_vcpu_disable_notify xen_hvm_altp2m_vcpu_disable_notify_t;
233 DEFINE_XEN_GUEST_HANDLE(xen_hvm_altp2m_vcpu_disable_notify_t);
234 
235 struct xen_hvm_altp2m_view {
236     /* IN/OUT variable */
237     uint16_t view;
238     uint16_t hvmmem_default_access; /* xenmem_access_t */
239 };
240 typedef struct xen_hvm_altp2m_view xen_hvm_altp2m_view_t;
241 DEFINE_XEN_GUEST_HANDLE(xen_hvm_altp2m_view_t);
242 
243 #if __XEN_INTERFACE_VERSION__ < 0x00040a00
244 struct xen_hvm_altp2m_set_mem_access {
245     /* view */
246     uint16_t view;
247     /* Memory type */
248     uint16_t access; /* xenmem_access_t */
249     uint32_t pad;
250     /* gfn */
251     uint64_t gfn;
252 };
253 typedef struct xen_hvm_altp2m_set_mem_access xen_hvm_altp2m_set_mem_access_t;
254 DEFINE_XEN_GUEST_HANDLE(xen_hvm_altp2m_set_mem_access_t);
255 #endif /* __XEN_INTERFACE_VERSION__ < 0x00040a00 */
256 
257 struct xen_hvm_altp2m_mem_access {
258     /* view */
259     uint16_t view;
260     /* Memory type */
261     uint16_t access; /* xenmem_access_t */
262     uint32_t pad;
263     /* gfn */
264     uint64_t gfn;
265 };
266 typedef struct xen_hvm_altp2m_mem_access xen_hvm_altp2m_mem_access_t;
267 DEFINE_XEN_GUEST_HANDLE(xen_hvm_altp2m_mem_access_t);
268 
269 struct xen_hvm_altp2m_set_mem_access_multi {
270     /* view */
271     uint16_t view;
272     uint16_t pad;
273     /* Number of pages */
274     uint32_t nr;
275     /*
276      * Used for continuation purposes.
277      * Must be set to zero upon initial invocation.
278      */
279     uint64_t opaque;
280     /* List of pfns to set access for */
281     XEN_GUEST_HANDLE(const_uint64) pfn_list;
282     /* Corresponding list of access settings for pfn_list */
283     XEN_GUEST_HANDLE(const_uint8) access_list;
284 };
285 
286 struct xen_hvm_altp2m_change_gfn {
287     /* view */
288     uint16_t view;
289     uint16_t pad1;
290     uint32_t pad2;
291     /* old gfn */
292     uint64_t old_gfn;
293     /* new gfn, INVALID_GFN (~0UL) means revert */
294     uint64_t new_gfn;
295 };
296 typedef struct xen_hvm_altp2m_change_gfn xen_hvm_altp2m_change_gfn_t;
297 DEFINE_XEN_GUEST_HANDLE(xen_hvm_altp2m_change_gfn_t);
298 
299 struct xen_hvm_altp2m_get_vcpu_p2m_idx {
300     uint32_t vcpu_id;
301     uint16_t altp2m_idx;
302 };
303 
304 struct xen_hvm_altp2m_set_visibility {
305     uint16_t altp2m_idx;
306     uint8_t visible;
307     uint8_t pad;
308 };
309 
310 struct xen_hvm_altp2m_op {
311     uint32_t version;   /* HVMOP_ALTP2M_INTERFACE_VERSION */
312     uint32_t cmd;
313 /* Get/set the altp2m state for a domain */
314 #define HVMOP_altp2m_get_domain_state     1
315 #define HVMOP_altp2m_set_domain_state     2
316 /* Set a given VCPU to receive altp2m event notifications */
317 #define HVMOP_altp2m_vcpu_enable_notify   3
318 /* Create a new view */
319 #define HVMOP_altp2m_create_p2m           4
320 /* Destroy a view */
321 #define HVMOP_altp2m_destroy_p2m          5
322 /* Switch view for an entire domain */
323 #define HVMOP_altp2m_switch_p2m           6
324 /* Notify that a page of memory is to have specific access types */
325 #define HVMOP_altp2m_set_mem_access       7
326 /* Change a p2m entry to have a different gfn->mfn mapping */
327 #define HVMOP_altp2m_change_gfn           8
328 /* Set access for an array of pages */
329 #define HVMOP_altp2m_set_mem_access_multi 9
330 /* Set the "Suppress #VE" bit on a page */
331 #define HVMOP_altp2m_set_suppress_ve      10
332 /* Get the "Suppress #VE" bit of a page */
333 #define HVMOP_altp2m_get_suppress_ve      11
334 /* Get the access of a page of memory from a certain view */
335 #define HVMOP_altp2m_get_mem_access       12
336 /* Disable altp2m event notifications for a given VCPU */
337 #define HVMOP_altp2m_vcpu_disable_notify  13
338 /* Get the active vcpu p2m index */
339 #define HVMOP_altp2m_get_p2m_idx          14
340 /* Set the "Supress #VE" bit for a range of pages */
341 #define HVMOP_altp2m_set_suppress_ve_multi 15
342 /* Set visibility for a given altp2m view */
343 #define HVMOP_altp2m_set_visibility       16
344     domid_t domain;
345     uint16_t pad1;
346     uint32_t pad2;
347     union {
348         struct xen_hvm_altp2m_domain_state         domain_state;
349         struct xen_hvm_altp2m_vcpu_enable_notify   enable_notify;
350         struct xen_hvm_altp2m_view                 view;
351 #if __XEN_INTERFACE_VERSION__ < 0x00040a00
352         struct xen_hvm_altp2m_set_mem_access       set_mem_access;
353 #endif /* __XEN_INTERFACE_VERSION__ < 0x00040a00 */
354         struct xen_hvm_altp2m_mem_access           mem_access;
355         struct xen_hvm_altp2m_change_gfn           change_gfn;
356         struct xen_hvm_altp2m_set_mem_access_multi set_mem_access_multi;
357         struct xen_hvm_altp2m_suppress_ve          suppress_ve;
358         struct xen_hvm_altp2m_suppress_ve_multi    suppress_ve_multi;
359         struct xen_hvm_altp2m_vcpu_disable_notify  disable_notify;
360         struct xen_hvm_altp2m_get_vcpu_p2m_idx     get_vcpu_p2m_idx;
361         struct xen_hvm_altp2m_set_visibility       set_visibility;
362         uint8_t pad[64];
363     } u;
364 };
365 typedef struct xen_hvm_altp2m_op xen_hvm_altp2m_op_t;
366 DEFINE_XEN_GUEST_HANDLE(xen_hvm_altp2m_op_t);
367 
368 #endif /* __XEN_PUBLIC_HVM_HVM_OP_H__ */
369 
370 /*
371  * Local variables:
372  * mode: C
373  * c-file-style: "BSD"
374  * c-basic-offset: 4
375  * tab-width: 4
376  * indent-tabs-mode: nil
377  * End:
378  */
379