329 lines · c
1/* SPDX-License-Identifier: MIT */2/******************************************************************************3 * memory.h4 *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 <linux/spinlock.h>14 15/*16 * Increase or decrease the specified domain's memory reservation. Returns a17 * -ve errcode on failure, or the # extents successfully allocated or freed.18 * arg == addr of struct xen_memory_reservation.19 */20#define XENMEM_increase_reservation 021#define XENMEM_decrease_reservation 122#define XENMEM_populate_physmap 623struct xen_memory_reservation {24 25 /*26 * XENMEM_increase_reservation:27 * OUT: MFN (*not* GMFN) bases of extents that were allocated28 * XENMEM_decrease_reservation:29 * IN: GMFN bases of extents to free30 * XENMEM_populate_physmap:31 * IN: GPFN bases of extents to populate with memory32 * OUT: GMFN bases of extents that were allocated33 * (NB. This command also updates the mach_to_phys translation table)34 */35 GUEST_HANDLE(xen_pfn_t) extent_start;36 37 /* Number of extents, and size/alignment of each (2^extent_order pages). */38 xen_ulong_t nr_extents;39 unsigned int extent_order;40 41 /*42 * Maximum # bits addressable by the user of the allocated region (e.g.,43 * I/O devices often have a 32-bit limitation even in 64-bit systems). If44 * zero then the user has no addressing restriction.45 * This field is not used by XENMEM_decrease_reservation.46 */47 unsigned int address_bits;48 49 /*50 * Domain whose reservation is being changed.51 * Unprivileged domains can specify only DOMID_SELF.52 */53 domid_t domid;54 55};56DEFINE_GUEST_HANDLE_STRUCT(xen_memory_reservation);57 58/*59 * An atomic exchange of memory pages. If return code is zero then60 * @out.extent_list provides GMFNs of the newly-allocated memory.61 * Returns zero on complete success, otherwise a negative error code.62 * On complete success then always @nr_exchanged == @in.nr_extents.63 * On partial success @nr_exchanged indicates how much work was done.64 */65#define XENMEM_exchange 1166struct xen_memory_exchange {67 /*68 * [IN] Details of memory extents to be exchanged (GMFN bases).69 * Note that @in.address_bits is ignored and unused.70 */71 struct xen_memory_reservation in;72 73 /*74 * [IN/OUT] Details of new memory extents.75 * We require that:76 * 1. @in.domid == @out.domid77 * 2. @in.nr_extents << @in.extent_order ==78 * @out.nr_extents << @out.extent_order79 * 3. @in.extent_start and @out.extent_start lists must not overlap80 * 4. @out.extent_start lists GPFN bases to be populated81 * 5. @out.extent_start is overwritten with allocated GMFN bases82 */83 struct xen_memory_reservation out;84 85 /*86 * [OUT] Number of input extents that were successfully exchanged:87 * 1. The first @nr_exchanged input extents were successfully88 * deallocated.89 * 2. The corresponding first entries in the output extent list correctly90 * indicate the GMFNs that were successfully exchanged.91 * 3. All other input and output extents are untouched.92 * 4. If not all input exents are exchanged then the return code of this93 * command will be non-zero.94 * 5. THIS FIELD MUST BE INITIALISED TO ZERO BY THE CALLER!95 */96 xen_ulong_t nr_exchanged;97};98 99DEFINE_GUEST_HANDLE_STRUCT(xen_memory_exchange);100/*101 * Returns the maximum machine frame number of mapped RAM in this system.102 * This command always succeeds (it never returns an error code).103 * arg == NULL.104 */105#define XENMEM_maximum_ram_page 2106 107/*108 * Returns the current or maximum memory reservation, in pages, of the109 * specified domain (may be DOMID_SELF). Returns -ve errcode on failure.110 * arg == addr of domid_t.111 */112#define XENMEM_current_reservation 3113#define XENMEM_maximum_reservation 4114 115/*116 * Returns a list of MFN bases of 2MB extents comprising the machine_to_phys117 * mapping table. Architectures which do not have a m2p table do not implement118 * this command.119 * arg == addr of xen_machphys_mfn_list_t.120 */121#define XENMEM_machphys_mfn_list 5122struct xen_machphys_mfn_list {123 /*124 * Size of the 'extent_start' array. Fewer entries will be filled if the125 * machphys table is smaller than max_extents * 2MB.126 */127 unsigned int max_extents;128 129 /*130 * Pointer to buffer to fill with list of extent starts. If there are131 * any large discontiguities in the machine address space, 2MB gaps in132 * the machphys table will be represented by an MFN base of zero.133 */134 GUEST_HANDLE(xen_pfn_t) extent_start;135 136 /*137 * Number of extents written to the above array. This will be smaller138 * than 'max_extents' if the machphys table is smaller than max_e * 2MB.139 */140 unsigned int nr_extents;141};142DEFINE_GUEST_HANDLE_STRUCT(xen_machphys_mfn_list);143 144/*145 * Returns the location in virtual address space of the machine_to_phys146 * mapping table. Architectures which do not have a m2p table, or which do not147 * map it by default into guest address space, do not implement this command.148 * arg == addr of xen_machphys_mapping_t.149 */150#define XENMEM_machphys_mapping 12151struct xen_machphys_mapping {152 xen_ulong_t v_start, v_end; /* Start and end virtual addresses. */153 xen_ulong_t max_mfn; /* Maximum MFN that can be looked up. */154};155DEFINE_GUEST_HANDLE_STRUCT(xen_machphys_mapping_t);156 157#define XENMAPSPACE_shared_info 0 /* shared info page */158#define XENMAPSPACE_grant_table 1 /* grant table page */159#define XENMAPSPACE_gmfn 2 /* GMFN */160#define XENMAPSPACE_gmfn_range 3 /* GMFN range, XENMEM_add_to_physmap only. */161#define XENMAPSPACE_gmfn_foreign 4 /* GMFN from another dom,162 * XENMEM_add_to_physmap_range only.163 */164#define XENMAPSPACE_dev_mmio 5 /* device mmio region */165 166/*167 * Sets the GPFN at which a particular page appears in the specified guest's168 * pseudophysical address space.169 * arg == addr of xen_add_to_physmap_t.170 */171#define XENMEM_add_to_physmap 7172struct xen_add_to_physmap {173 /* Which domain to change the mapping for. */174 domid_t domid;175 176 /* Number of pages to go through for gmfn_range */177 uint16_t size;178 179 /* Source mapping space. */180 unsigned int space;181 182 /* Index into source mapping space. */183 xen_ulong_t idx;184 185 /* GPFN where the source mapping page should appear. */186 xen_pfn_t gpfn;187};188DEFINE_GUEST_HANDLE_STRUCT(xen_add_to_physmap);189 190/*** REMOVED ***/191/*#define XENMEM_translate_gpfn_list 8*/192 193#define XENMEM_add_to_physmap_range 23194struct xen_add_to_physmap_range {195 /* IN */196 /* Which domain to change the mapping for. */197 domid_t domid;198 uint16_t space; /* => enum phys_map_space */199 200 /* Number of pages to go through */201 uint16_t size;202 domid_t foreign_domid; /* IFF gmfn_foreign */203 204 /* Indexes into space being mapped. */205 GUEST_HANDLE(xen_ulong_t) idxs;206 207 /* GPFN in domid where the source mapping page should appear. */208 GUEST_HANDLE(xen_pfn_t) gpfns;209 210 /* OUT */211 212 /* Per index error code. */213 GUEST_HANDLE(int) errs;214};215DEFINE_GUEST_HANDLE_STRUCT(xen_add_to_physmap_range);216 217/*218 * Returns the pseudo-physical memory map as it was when the domain219 * was started (specified by XENMEM_set_memory_map).220 * arg == addr of struct xen_memory_map.221 */222#define XENMEM_memory_map 9223struct xen_memory_map {224 /*225 * On call the number of entries which can be stored in buffer. On226 * return the number of entries which have been stored in227 * buffer.228 */229 unsigned int nr_entries;230 231 /*232 * Entries in the buffer are in the same format as returned by the233 * BIOS INT 0x15 EAX=0xE820 call.234 */235 GUEST_HANDLE(void) buffer;236};237DEFINE_GUEST_HANDLE_STRUCT(xen_memory_map);238 239/*240 * Returns the real physical memory map. Passes the same structure as241 * XENMEM_memory_map.242 * arg == addr of struct xen_memory_map.243 */244#define XENMEM_machine_memory_map 10245 246 247/*248 * Unmaps the page appearing at a particular GPFN from the specified guest's249 * pseudophysical address space.250 * arg == addr of xen_remove_from_physmap_t.251 */252#define XENMEM_remove_from_physmap 15253struct xen_remove_from_physmap {254 /* Which domain to change the mapping for. */255 domid_t domid;256 257 /* GPFN of the current mapping of the page. */258 xen_pfn_t gpfn;259};260DEFINE_GUEST_HANDLE_STRUCT(xen_remove_from_physmap);261 262/*263 * Get the pages for a particular guest resource, so that they can be264 * mapped directly by a tools domain.265 */266#define XENMEM_acquire_resource 28267struct xen_mem_acquire_resource {268 /* IN - The domain whose resource is to be mapped */269 domid_t domid;270 /* IN - the type of resource */271 uint16_t type;272 273#define XENMEM_resource_ioreq_server 0274#define XENMEM_resource_grant_table 1275 276 /*277 * IN - a type-specific resource identifier, which must be zero278 * unless stated otherwise.279 *280 * type == XENMEM_resource_ioreq_server -> id == ioreq server id281 * type == XENMEM_resource_grant_table -> id defined below282 */283 uint32_t id;284 285#define XENMEM_resource_grant_table_id_shared 0286#define XENMEM_resource_grant_table_id_status 1287 288 /* IN/OUT - As an IN parameter number of frames of the resource289 * to be mapped. However, if the specified value is 0 and290 * frame_list is NULL then this field will be set to the291 * maximum value supported by the implementation on return.292 */293 uint32_t nr_frames;294 /*295 * OUT - Must be zero on entry. On return this may contain a bitwise296 * OR of the following values.297 */298 uint32_t flags;299 300 /* The resource pages have been assigned to the calling domain */301#define _XENMEM_rsrc_acq_caller_owned 0302#define XENMEM_rsrc_acq_caller_owned (1u << _XENMEM_rsrc_acq_caller_owned)303 304 /*305 * IN - the index of the initial frame to be mapped. This parameter306 * is ignored if nr_frames is 0.307 */308 uint64_t frame;309 310#define XENMEM_resource_ioreq_server_frame_bufioreq 0311#define XENMEM_resource_ioreq_server_frame_ioreq(n) (1 + (n))312 313 /*314 * IN/OUT - If the tools domain is PV then, upon return, frame_list315 * will be populated with the MFNs of the resource.316 * If the tools domain is HVM then it is expected that, on317 * entry, frame_list will be populated with a list of GFNs318 * that will be mapped to the MFNs of the resource.319 * If -EIO is returned then the frame_list has only been320 * partially mapped and it is up to the caller to unmap all321 * the GFNs.322 * This parameter may be NULL if nr_frames is 0.323 */324 GUEST_HANDLE(xen_pfn_t) frame_list;325};326DEFINE_GUEST_HANDLE_STRUCT(xen_mem_acquire_resource);327 328#endif /* __XEN_PUBLIC_MEMORY_H__ */329