xref: /openbmc/qemu/include/hw/xen/interface/memory.h (revision 8ac98aed)
1 /* SPDX-License-Identifier: MIT */
2 /******************************************************************************
3  * memory.h
4  *
5  * Memory reservation and information.
6  *
7  * Copyright (c) 2005, Keir Fraser <keir@xensource.com>
8  */
9 
10 #ifndef __XEN_PUBLIC_MEMORY_H__
11 #define __XEN_PUBLIC_MEMORY_H__
12 
13 #include "xen.h"
14 #include "physdev.h"
15 
16 /*
17  * Increase or decrease the specified domain's memory reservation. Returns the
18  * number of extents successfully allocated or freed.
19  * arg == addr of struct xen_memory_reservation.
20  */
21 #define XENMEM_increase_reservation 0
22 #define XENMEM_decrease_reservation 1
23 #define XENMEM_populate_physmap     6
24 
25 #if __XEN_INTERFACE_VERSION__ >= 0x00030209
26 /*
27  * Maximum # bits addressable by the user of the allocated region (e.g., I/O
28  * devices often have a 32-bit limitation even in 64-bit systems). If zero
29  * then the user has no addressing restriction. This field is not used by
30  * XENMEM_decrease_reservation.
31  */
32 #define XENMEMF_address_bits(x)     (x)
33 #define XENMEMF_get_address_bits(x) ((x) & 0xffu)
34 /* NUMA node to allocate from. */
35 #define XENMEMF_node(x)     (((x) + 1) << 8)
36 #define XENMEMF_get_node(x) ((((x) >> 8) - 1) & 0xffu)
37 /* Flag to populate physmap with populate-on-demand entries */
38 #define XENMEMF_populate_on_demand (1<<16)
39 /* Flag to request allocation only from the node specified */
40 #define XENMEMF_exact_node_request  (1<<17)
41 #define XENMEMF_exact_node(n) (XENMEMF_node(n) | XENMEMF_exact_node_request)
42 /* Flag to indicate the node specified is virtual node */
43 #define XENMEMF_vnode  (1<<18)
44 #endif
45 
46 struct xen_memory_reservation {
47 
48     /*
49      * XENMEM_increase_reservation:
50      *   OUT: MFN (*not* GMFN) bases of extents that were allocated
51      * XENMEM_decrease_reservation:
52      *   IN:  GMFN bases of extents to free
53      * XENMEM_populate_physmap:
54      *   IN:  GPFN bases of extents to populate with memory
55      *   OUT: GMFN bases of extents that were allocated
56      *   (NB. This command also updates the mach_to_phys translation table)
57      * XENMEM_claim_pages:
58      *   IN: must be zero
59      */
60     XEN_GUEST_HANDLE(xen_pfn_t) extent_start;
61 
62     /* Number of extents, and size/alignment of each (2^extent_order pages). */
63     xen_ulong_t    nr_extents;
64     unsigned int   extent_order;
65 
66 #if __XEN_INTERFACE_VERSION__ >= 0x00030209
67     /* XENMEMF flags. */
68     unsigned int   mem_flags;
69 #else
70     unsigned int   address_bits;
71 #endif
72 
73     /*
74      * Domain whose reservation is being changed.
75      * Unprivileged domains can specify only DOMID_SELF.
76      */
77     domid_t        domid;
78 };
79 typedef struct xen_memory_reservation xen_memory_reservation_t;
80 DEFINE_XEN_GUEST_HANDLE(xen_memory_reservation_t);
81 
82 /*
83  * An atomic exchange of memory pages. If return code is zero then
84  * @out.extent_list provides GMFNs of the newly-allocated memory.
85  * Returns zero on complete success, otherwise a negative error code.
86  * On complete success then always @nr_exchanged == @in.nr_extents.
87  * On partial success @nr_exchanged indicates how much work was done.
88  *
89  * Note that only PV guests can use this operation.
90  */
91 #define XENMEM_exchange             11
92 struct xen_memory_exchange {
93     /*
94      * [IN] Details of memory extents to be exchanged (GMFN bases).
95      * Note that @in.address_bits is ignored and unused.
96      */
97     struct xen_memory_reservation in;
98 
99     /*
100      * [IN/OUT] Details of new memory extents.
101      * We require that:
102      *  1. @in.domid == @out.domid
103      *  2. @in.nr_extents  << @in.extent_order ==
104      *     @out.nr_extents << @out.extent_order
105      *  3. @in.extent_start and @out.extent_start lists must not overlap
106      *  4. @out.extent_start lists GPFN bases to be populated
107      *  5. @out.extent_start is overwritten with allocated GMFN bases
108      */
109     struct xen_memory_reservation out;
110 
111     /*
112      * [OUT] Number of input extents that were successfully exchanged:
113      *  1. The first @nr_exchanged input extents were successfully
114      *     deallocated.
115      *  2. The corresponding first entries in the output extent list correctly
116      *     indicate the GMFNs that were successfully exchanged.
117      *  3. All other input and output extents are untouched.
118      *  4. If not all input exents are exchanged then the return code of this
119      *     command will be non-zero.
120      *  5. THIS FIELD MUST BE INITIALISED TO ZERO BY THE CALLER!
121      */
122     xen_ulong_t nr_exchanged;
123 };
124 typedef struct xen_memory_exchange xen_memory_exchange_t;
125 DEFINE_XEN_GUEST_HANDLE(xen_memory_exchange_t);
126 
127 /*
128  * Returns the maximum machine frame number of mapped RAM in this system.
129  * This command always succeeds (it never returns an error code).
130  * arg == NULL.
131  */
132 #define XENMEM_maximum_ram_page     2
133 
134 struct xen_memory_domain {
135     /* [IN] Domain information is being queried for. */
136     domid_t domid;
137 };
138 
139 /*
140  * Returns the current or maximum memory reservation, in pages, of the
141  * specified domain (may be DOMID_SELF). Returns -ve errcode on failure.
142  * arg == addr of struct xen_memory_domain.
143  */
144 #define XENMEM_current_reservation  3
145 #define XENMEM_maximum_reservation  4
146 
147 /*
148  * Returns the maximum GFN in use by the specified domain (may be DOMID_SELF).
149  * Returns -ve errcode on failure.
150  * arg == addr of struct xen_memory_domain.
151  */
152 #define XENMEM_maximum_gpfn         14
153 
154 /*
155  * Returns a list of MFN bases of 2MB extents comprising the machine_to_phys
156  * mapping table. Architectures which do not have a m2p table do not implement
157  * this command.
158  * arg == addr of xen_machphys_mfn_list_t.
159  */
160 #define XENMEM_machphys_mfn_list    5
161 struct xen_machphys_mfn_list {
162     /*
163      * Size of the 'extent_start' array. Fewer entries will be filled if the
164      * machphys table is smaller than max_extents * 2MB.
165      */
166     unsigned int max_extents;
167 
168     /*
169      * Pointer to buffer to fill with list of extent starts. If there are
170      * any large discontiguities in the machine address space, 2MB gaps in
171      * the machphys table will be represented by an MFN base of zero.
172      */
173     XEN_GUEST_HANDLE(xen_pfn_t) extent_start;
174 
175     /*
176      * Number of extents written to the above array. This will be smaller
177      * than 'max_extents' if the machphys table is smaller than max_e * 2MB.
178      */
179     unsigned int nr_extents;
180 };
181 typedef struct xen_machphys_mfn_list xen_machphys_mfn_list_t;
182 DEFINE_XEN_GUEST_HANDLE(xen_machphys_mfn_list_t);
183 
184 /*
185  * For a compat caller, this is identical to XENMEM_machphys_mfn_list.
186  *
187  * For a non compat caller, this functions similarly to
188  * XENMEM_machphys_mfn_list, but returns the mfns making up the compatibility
189  * m2p table.
190  */
191 #define XENMEM_machphys_compat_mfn_list     25
192 
193 /*
194  * Returns the location in virtual address space of the machine_to_phys
195  * mapping table. Architectures which do not have a m2p table, or which do not
196  * map it by default into guest address space, do not implement this command.
197  * arg == addr of xen_machphys_mapping_t.
198  */
199 #define XENMEM_machphys_mapping     12
200 struct xen_machphys_mapping {
201     xen_ulong_t v_start, v_end; /* Start and end virtual addresses.   */
202     xen_ulong_t max_mfn;        /* Maximum MFN that can be looked up. */
203 };
204 typedef struct xen_machphys_mapping xen_machphys_mapping_t;
205 DEFINE_XEN_GUEST_HANDLE(xen_machphys_mapping_t);
206 
207 /* Source mapping space. */
208 /* ` enum phys_map_space { */
209 #define XENMAPSPACE_shared_info  0 /* shared info page */
210 #define XENMAPSPACE_grant_table  1 /* grant table page */
211 #define XENMAPSPACE_gmfn         2 /* GMFN */
212 #define XENMAPSPACE_gmfn_range   3 /* GMFN range, XENMEM_add_to_physmap only. */
213 #define XENMAPSPACE_gmfn_foreign 4 /* GMFN from another dom,
214                                     * XENMEM_add_to_physmap_batch only. */
215 #define XENMAPSPACE_dev_mmio     5 /* device mmio region
216                                       ARM only; the region is mapped in
217                                       Stage-2 using the Normal Memory
218                                       Inner/Outer Write-Back Cacheable
219                                       memory attribute. */
220 /* ` } */
221 
222 /*
223  * Sets the GPFN at which a particular page appears in the specified guest's
224  * physical address space (translated guests only).
225  * arg == addr of xen_add_to_physmap_t.
226  */
227 #define XENMEM_add_to_physmap      7
228 struct xen_add_to_physmap {
229     /* Which domain to change the mapping for. */
230     domid_t domid;
231 
232     /* Number of pages to go through for gmfn_range */
233     uint16_t    size;
234 
235     unsigned int space; /* => enum phys_map_space */
236 
237 #define XENMAPIDX_grant_table_status 0x80000000
238 
239     /* Index into space being mapped. */
240     xen_ulong_t idx;
241 
242     /* GPFN in domid where the source mapping page should appear. */
243     xen_pfn_t     gpfn;
244 };
245 typedef struct xen_add_to_physmap xen_add_to_physmap_t;
246 DEFINE_XEN_GUEST_HANDLE(xen_add_to_physmap_t);
247 
248 /* A batched version of add_to_physmap. */
249 #define XENMEM_add_to_physmap_batch 23
250 struct xen_add_to_physmap_batch {
251     /* IN */
252     /* Which domain to change the mapping for. */
253     domid_t domid;
254     uint16_t space; /* => enum phys_map_space */
255 
256     /* Number of pages to go through */
257     uint16_t size;
258 
259 #if __XEN_INTERFACE_VERSION__ < 0x00040700
260     domid_t foreign_domid; /* IFF gmfn_foreign. Should be 0 for other spaces. */
261 #else
262     union xen_add_to_physmap_batch_extra {
263         domid_t foreign_domid; /* gmfn_foreign */
264         uint16_t res0;  /* All the other spaces. Should be 0 */
265     } u;
266 #endif
267 
268     /* Indexes into space being mapped. */
269     XEN_GUEST_HANDLE(xen_ulong_t) idxs;
270 
271     /* GPFN in domid where the source mapping page should appear. */
272     XEN_GUEST_HANDLE(xen_pfn_t) gpfns;
273 
274     /* OUT */
275 
276     /* Per index error code. */
277     XEN_GUEST_HANDLE(int) errs;
278 };
279 typedef struct xen_add_to_physmap_batch xen_add_to_physmap_batch_t;
280 DEFINE_XEN_GUEST_HANDLE(xen_add_to_physmap_batch_t);
281 
282 #if __XEN_INTERFACE_VERSION__ < 0x00040400
283 #define XENMEM_add_to_physmap_range XENMEM_add_to_physmap_batch
284 #define xen_add_to_physmap_range xen_add_to_physmap_batch
285 typedef struct xen_add_to_physmap_batch xen_add_to_physmap_range_t;
286 DEFINE_XEN_GUEST_HANDLE(xen_add_to_physmap_range_t);
287 #endif
288 
289 /*
290  * Unmaps the page appearing at a particular GPFN from the specified guest's
291  * physical address space (translated guests only).
292  * arg == addr of xen_remove_from_physmap_t.
293  */
294 #define XENMEM_remove_from_physmap      15
295 struct xen_remove_from_physmap {
296     /* Which domain to change the mapping for. */
297     domid_t domid;
298 
299     /* GPFN of the current mapping of the page. */
300     xen_pfn_t     gpfn;
301 };
302 typedef struct xen_remove_from_physmap xen_remove_from_physmap_t;
303 DEFINE_XEN_GUEST_HANDLE(xen_remove_from_physmap_t);
304 
305 /*** REMOVED ***/
306 /*#define XENMEM_translate_gpfn_list  8*/
307 
308 /*
309  * Returns the pseudo-physical memory map as it was when the domain
310  * was started (specified by XENMEM_set_memory_map).
311  * arg == addr of xen_memory_map_t.
312  */
313 #define XENMEM_memory_map           9
314 struct xen_memory_map {
315     /*
316      * On call the number of entries which can be stored in buffer. On
317      * return the number of entries which have been stored in
318      * buffer.
319      */
320     unsigned int nr_entries;
321 
322     /*
323      * Entries in the buffer are in the same format as returned by the
324      * BIOS INT 0x15 EAX=0xE820 call.
325      */
326     XEN_GUEST_HANDLE(void) buffer;
327 };
328 typedef struct xen_memory_map xen_memory_map_t;
329 DEFINE_XEN_GUEST_HANDLE(xen_memory_map_t);
330 
331 /*
332  * Returns the real physical memory map. Passes the same structure as
333  * XENMEM_memory_map.
334  * Specifying buffer as NULL will return the number of entries required
335  * to store the complete memory map.
336  * arg == addr of xen_memory_map_t.
337  */
338 #define XENMEM_machine_memory_map   10
339 
340 /*
341  * Set the pseudo-physical memory map of a domain, as returned by
342  * XENMEM_memory_map.
343  * arg == addr of xen_foreign_memory_map_t.
344  */
345 #define XENMEM_set_memory_map       13
346 struct xen_foreign_memory_map {
347     domid_t domid;
348     struct xen_memory_map map;
349 };
350 typedef struct xen_foreign_memory_map xen_foreign_memory_map_t;
351 DEFINE_XEN_GUEST_HANDLE(xen_foreign_memory_map_t);
352 
353 #define XENMEM_set_pod_target       16
354 #define XENMEM_get_pod_target       17
355 struct xen_pod_target {
356     /* IN */
357     uint64_t target_pages;
358     /* OUT */
359     uint64_t tot_pages;
360     uint64_t pod_cache_pages;
361     uint64_t pod_entries;
362     /* IN */
363     domid_t domid;
364 };
365 typedef struct xen_pod_target xen_pod_target_t;
366 
367 #if defined(__XEN__) || defined(__XEN_TOOLS__)
368 
369 #ifndef uint64_aligned_t
370 #define uint64_aligned_t uint64_t
371 #endif
372 
373 /*
374  * Get the number of MFNs saved through memory sharing.
375  * The call never fails.
376  */
377 #define XENMEM_get_sharing_freed_pages    18
378 #define XENMEM_get_sharing_shared_pages   19
379 
380 #define XENMEM_paging_op                    20
381 #define XENMEM_paging_op_nominate           0
382 #define XENMEM_paging_op_evict              1
383 #define XENMEM_paging_op_prep               2
384 
385 struct xen_mem_paging_op {
386     uint8_t     op;         /* XENMEM_paging_op_* */
387     domid_t     domain;
388 
389     /* IN: (XENMEM_paging_op_prep) buffer to immediately fill page from */
390     XEN_GUEST_HANDLE_64(const_uint8) buffer;
391     /* IN:  gfn of page being operated on */
392     uint64_aligned_t    gfn;
393 };
394 typedef struct xen_mem_paging_op xen_mem_paging_op_t;
395 DEFINE_XEN_GUEST_HANDLE(xen_mem_paging_op_t);
396 
397 #define XENMEM_access_op                    21
398 #define XENMEM_access_op_set_access         0
399 #define XENMEM_access_op_get_access         1
400 /*
401  * XENMEM_access_op_enable_emulate and XENMEM_access_op_disable_emulate are
402  * currently unused, but since they have been in use please do not reuse them.
403  *
404  * #define XENMEM_access_op_enable_emulate     2
405  * #define XENMEM_access_op_disable_emulate    3
406  */
407 #define XENMEM_access_op_set_access_multi   4
408 
409 typedef enum {
410     XENMEM_access_n,
411     XENMEM_access_r,
412     XENMEM_access_w,
413     XENMEM_access_rw,
414     XENMEM_access_x,
415     XENMEM_access_rx,
416     XENMEM_access_wx,
417     XENMEM_access_rwx,
418     /*
419      * Page starts off as r-x, but automatically
420      * change to r-w on a write
421      */
422     XENMEM_access_rx2rw,
423     /*
424      * Log access: starts off as n, automatically
425      * goes to rwx, generating an event without
426      * pausing the vcpu
427      */
428     XENMEM_access_n2rwx,
429     /* Take the domain default */
430     XENMEM_access_default
431 } xenmem_access_t;
432 
433 struct xen_mem_access_op {
434     /* XENMEM_access_op_* */
435     uint8_t op;
436     /* xenmem_access_t */
437     uint8_t access;
438     domid_t domid;
439     /*
440      * Number of pages for set op (or size of pfn_list for
441      * XENMEM_access_op_set_access_multi)
442      * Ignored on setting default access and other ops
443      */
444     uint32_t nr;
445     /*
446      * First pfn for set op
447      * pfn for get op
448      * ~0ull is used to set and get the default access for pages
449      */
450     uint64_aligned_t pfn;
451     /*
452      * List of pfns to set access for
453      * Used only with XENMEM_access_op_set_access_multi
454      */
455     XEN_GUEST_HANDLE(const_uint64) pfn_list;
456     /*
457      * Corresponding list of access settings for pfn_list
458      * Used only with XENMEM_access_op_set_access_multi
459      */
460     XEN_GUEST_HANDLE(const_uint8) access_list;
461 };
462 typedef struct xen_mem_access_op xen_mem_access_op_t;
463 DEFINE_XEN_GUEST_HANDLE(xen_mem_access_op_t);
464 
465 #define XENMEM_sharing_op                   22
466 #define XENMEM_sharing_op_nominate_gfn      0
467 #define XENMEM_sharing_op_nominate_gref     1
468 #define XENMEM_sharing_op_share             2
469 #define XENMEM_sharing_op_debug_gfn         3
470 #define XENMEM_sharing_op_debug_mfn         4
471 #define XENMEM_sharing_op_debug_gref        5
472 #define XENMEM_sharing_op_add_physmap       6
473 #define XENMEM_sharing_op_audit             7
474 #define XENMEM_sharing_op_range_share       8
475 #define XENMEM_sharing_op_fork              9
476 #define XENMEM_sharing_op_fork_reset        10
477 
478 #define XENMEM_SHARING_OP_S_HANDLE_INVALID  (-10)
479 #define XENMEM_SHARING_OP_C_HANDLE_INVALID  (-9)
480 
481 /* The following allows sharing of grant refs. This is useful
482  * for sharing utilities sitting as "filters" in IO backends
483  * (e.g. memshr + blktap(2)). The IO backend is only exposed
484  * to grant references, and this allows sharing of the grefs */
485 #define XENMEM_SHARING_OP_FIELD_IS_GREF_FLAG   (xen_mk_ullong(1) << 62)
486 
487 #define XENMEM_SHARING_OP_FIELD_MAKE_GREF(field, val)  \
488     (field) = (XENMEM_SHARING_OP_FIELD_IS_GREF_FLAG | val)
489 #define XENMEM_SHARING_OP_FIELD_IS_GREF(field)         \
490     ((field) & XENMEM_SHARING_OP_FIELD_IS_GREF_FLAG)
491 #define XENMEM_SHARING_OP_FIELD_GET_GREF(field)        \
492     ((field) & (~XENMEM_SHARING_OP_FIELD_IS_GREF_FLAG))
493 
494 struct xen_mem_sharing_op {
495     uint8_t     op;     /* XENMEM_sharing_op_* */
496     domid_t     domain;
497 
498     union {
499         struct mem_sharing_op_nominate {  /* OP_NOMINATE_xxx           */
500             union {
501                 uint64_aligned_t gfn;     /* IN: gfn to nominate       */
502                 uint32_t      grant_ref;  /* IN: grant ref to nominate */
503             } u;
504             uint64_aligned_t  handle;     /* OUT: the handle           */
505         } nominate;
506         struct mem_sharing_op_share {     /* OP_SHARE/ADD_PHYSMAP */
507             uint64_aligned_t source_gfn;    /* IN: the gfn of the source page */
508             uint64_aligned_t source_handle; /* IN: handle to the source page */
509             uint64_aligned_t client_gfn;    /* IN: the client gfn */
510             uint64_aligned_t client_handle; /* IN: handle to the client page */
511             domid_t  client_domain; /* IN: the client domain id */
512         } share;
513         struct mem_sharing_op_range {         /* OP_RANGE_SHARE */
514             uint64_aligned_t first_gfn;      /* IN: the first gfn */
515             uint64_aligned_t last_gfn;       /* IN: the last gfn */
516             uint64_aligned_t opaque;         /* Must be set to 0 */
517             domid_t client_domain;           /* IN: the client domain id */
518             uint16_t _pad[3];                /* Must be set to 0 */
519         } range;
520         struct mem_sharing_op_debug {     /* OP_DEBUG_xxx */
521             union {
522                 uint64_aligned_t gfn;      /* IN: gfn to debug          */
523                 uint64_aligned_t mfn;      /* IN: mfn to debug          */
524                 uint32_t gref;     /* IN: gref to debug         */
525             } u;
526         } debug;
527         struct mem_sharing_op_fork {      /* OP_FORK{,_RESET} */
528             domid_t parent_domain;        /* IN: parent's domain id */
529 /* Only makes sense for short-lived forks */
530 #define XENMEM_FORK_WITH_IOMMU_ALLOWED (1u << 0)
531 /* Only makes sense for short-lived forks */
532 #define XENMEM_FORK_BLOCK_INTERRUPTS   (1u << 1)
533 #define XENMEM_FORK_RESET_STATE        (1u << 2)
534 #define XENMEM_FORK_RESET_MEMORY       (1u << 3)
535             uint16_t flags;               /* IN: optional settings */
536             uint32_t pad;                 /* Must be set to 0 */
537         } fork;
538     } u;
539 };
540 typedef struct xen_mem_sharing_op xen_mem_sharing_op_t;
541 DEFINE_XEN_GUEST_HANDLE(xen_mem_sharing_op_t);
542 
543 /*
544  * Attempt to stake a claim for a domain on a quantity of pages
545  * of system RAM, but _not_ assign specific pageframes.  Only
546  * arithmetic is performed so the hypercall is very fast and need
547  * not be preemptible, thus sidestepping time-of-check-time-of-use
548  * races for memory allocation.  Returns 0 if the hypervisor page
549  * allocator has atomically and successfully claimed the requested
550  * number of pages, else non-zero.
551  *
552  * Any domain may have only one active claim.  When sufficient memory
553  * has been allocated to resolve the claim, the claim silently expires.
554  * Claiming zero pages effectively resets any outstanding claim and
555  * is always successful.
556  *
557  * Note that a valid claim may be staked even after memory has been
558  * allocated for a domain.  In this case, the claim is not incremental,
559  * i.e. if the domain's total page count is 3, and a claim is staked
560  * for 10, only 7 additional pages are claimed.
561  *
562  * Caller must be privileged or the hypercall fails.
563  */
564 #define XENMEM_claim_pages                  24
565 
566 /*
567  * XENMEM_claim_pages flags - the are no flags at this time.
568  * The zero value is appropriate.
569  */
570 
571 /*
572  * With some legacy devices, certain guest-physical addresses cannot safely
573  * be used for other purposes, e.g. to map guest RAM.  This hypercall
574  * enumerates those regions so the toolstack can avoid using them.
575  */
576 #define XENMEM_reserved_device_memory_map   27
577 struct xen_reserved_device_memory {
578     xen_pfn_t start_pfn;
579     xen_ulong_t nr_pages;
580 };
581 typedef struct xen_reserved_device_memory xen_reserved_device_memory_t;
582 DEFINE_XEN_GUEST_HANDLE(xen_reserved_device_memory_t);
583 
584 struct xen_reserved_device_memory_map {
585 #define XENMEM_RDM_ALL 1 /* Request all regions (ignore dev union). */
586     /* IN */
587     uint32_t flags;
588     /*
589      * IN/OUT
590      *
591      * Gets set to the required number of entries when too low,
592      * signaled by error code -ERANGE.
593      */
594     unsigned int nr_entries;
595     /* OUT */
596     XEN_GUEST_HANDLE(xen_reserved_device_memory_t) buffer;
597     /* IN */
598     union {
599         physdev_pci_device_t pci;
600     } dev;
601 };
602 typedef struct xen_reserved_device_memory_map xen_reserved_device_memory_map_t;
603 DEFINE_XEN_GUEST_HANDLE(xen_reserved_device_memory_map_t);
604 
605 #endif /* defined(__XEN__) || defined(__XEN_TOOLS__) */
606 
607 /*
608  * Get the pages for a particular guest resource, so that they can be
609  * mapped directly by a tools domain.
610  */
611 #define XENMEM_acquire_resource 28
612 struct xen_mem_acquire_resource {
613     /* IN - The domain whose resource is to be mapped */
614     domid_t domid;
615     /* IN - the type of resource */
616     uint16_t type;
617 
618 #define XENMEM_resource_ioreq_server 0
619 #define XENMEM_resource_grant_table 1
620 #define XENMEM_resource_vmtrace_buf 2
621 
622     /*
623      * IN - a type-specific resource identifier, which must be zero
624      *      unless stated otherwise.
625      *
626      * type == XENMEM_resource_ioreq_server -> id == ioreq server id
627      * type == XENMEM_resource_grant_table -> id defined below
628      */
629     uint32_t id;
630 
631 #define XENMEM_resource_grant_table_id_shared 0
632 #define XENMEM_resource_grant_table_id_status 1
633 
634     /*
635      * IN/OUT
636      *
637      * As an IN parameter number of frames of the resource to be mapped.
638      * This value may be updated over the course of the operation.
639      *
640      * When frame_list is NULL and nr_frames is 0, this is interpreted as a
641      * request for the size of the resource, which shall be returned in the
642      * nr_frames field.
643      *
644      * The size of a resource will never be zero, but a nonzero result doesn't
645      * guarantee that a subsequent mapping request will be successful.  There
646      * are further type/id specific constraints which may change between the
647      * two calls.
648      */
649     uint32_t nr_frames;
650     /*
651      * Padding field, must be zero on input.
652      * In a previous version this was an output field with the lowest bit
653      * named XENMEM_rsrc_acq_caller_owned. Future versions of this interface
654      * will not reuse this bit as an output with the field being zero on
655      * input.
656      */
657     uint32_t pad;
658     /*
659      * IN - the index of the initial frame to be mapped. This parameter
660      *      is ignored if nr_frames is 0.  This value may be updated
661      *      over the course of the operation.
662      */
663     uint64_t frame;
664 
665 #define XENMEM_resource_ioreq_server_frame_bufioreq 0
666 #define XENMEM_resource_ioreq_server_frame_ioreq(n) (1 + (n))
667 
668     /*
669      * IN/OUT - If the tools domain is PV then, upon return, frame_list
670      *          will be populated with the MFNs of the resource.
671      *          If the tools domain is HVM then it is expected that, on
672      *          entry, frame_list will be populated with a list of GFNs
673      *          that will be mapped to the MFNs of the resource.
674      *          If -EIO is returned then the frame_list has only been
675      *          partially mapped and it is up to the caller to unmap all
676      *          the GFNs.
677      *          This parameter may be NULL if nr_frames is 0.  This
678      *          value may be updated over the course of the operation.
679      */
680     XEN_GUEST_HANDLE(xen_pfn_t) frame_list;
681 };
682 typedef struct xen_mem_acquire_resource xen_mem_acquire_resource_t;
683 DEFINE_XEN_GUEST_HANDLE(xen_mem_acquire_resource_t);
684 
685 /*
686  * XENMEM_get_vnumainfo used by guest to get
687  * vNUMA topology from hypervisor.
688  */
689 #define XENMEM_get_vnumainfo                26
690 
691 /* vNUMA node memory ranges */
692 struct xen_vmemrange {
693     uint64_t start, end;
694     unsigned int flags;
695     unsigned int nid;
696 };
697 typedef struct xen_vmemrange xen_vmemrange_t;
698 DEFINE_XEN_GUEST_HANDLE(xen_vmemrange_t);
699 
700 /*
701  * vNUMA topology specifies vNUMA node number, distance table,
702  * memory ranges and vcpu mapping provided for guests.
703  * XENMEM_get_vnumainfo hypercall expects to see from guest
704  * nr_vnodes, nr_vmemranges and nr_vcpus to indicate available memory.
705  * After filling guests structures, nr_vnodes, nr_vmemranges and nr_vcpus
706  * copied back to guest. Domain returns expected values of nr_vnodes,
707  * nr_vmemranges and nr_vcpus to guest if the values where incorrect.
708  */
709 struct xen_vnuma_topology_info {
710     /* IN */
711     domid_t domid;
712     uint16_t pad;
713     /* IN/OUT */
714     unsigned int nr_vnodes;
715     unsigned int nr_vcpus;
716     unsigned int nr_vmemranges;
717     /* OUT */
718     union {
719         XEN_GUEST_HANDLE(uint) h;
720         uint64_t pad;
721     } vdistance;
722     union {
723         XEN_GUEST_HANDLE(uint) h;
724         uint64_t pad;
725     } vcpu_to_vnode;
726     union {
727         XEN_GUEST_HANDLE(xen_vmemrange_t) h;
728         uint64_t pad;
729     } vmemrange;
730 };
731 typedef struct xen_vnuma_topology_info xen_vnuma_topology_info_t;
732 DEFINE_XEN_GUEST_HANDLE(xen_vnuma_topology_info_t);
733 
734 /* Next available subop number is 29 */
735 
736 #endif /* __XEN_PUBLIC_MEMORY_H__ */
737 
738 /*
739  * Local variables:
740  * mode: C
741  * c-file-style: "BSD"
742  * c-basic-offset: 4
743  * tab-width: 4
744  * indent-tabs-mode: nil
745  * End:
746  */
747