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 /* 31 * Increase or decrease the specified domain's memory reservation. Returns the 32 * number of extents successfully allocated or freed. 33 * arg == addr of struct xen_memory_reservation. 34 */ 35 #define XENMEM_increase_reservation 0 36 #define XENMEM_decrease_reservation 1 37 #define XENMEM_populate_physmap 6 38 struct xen_memory_reservation { 39 40 /* 41 * XENMEM_increase_reservation: 42 * OUT: MFN (*not* GMFN) bases of extents that were allocated 43 * XENMEM_decrease_reservation: 44 * IN: GMFN bases of extents to free 45 * XENMEM_populate_physmap: 46 * IN: GPFN bases of extents to populate with memory 47 * OUT: GMFN bases of extents that were allocated 48 * (NB. This command also updates the mach_to_phys translation table) 49 */ 50 XEN_GUEST_HANDLE(xen_pfn_t) extent_start; 51 52 /* Number of extents, and size/alignment of each (2^extent_order pages). */ 53 xen_ulong_t nr_extents; 54 unsigned int extent_order; 55 56 /* 57 * Maximum # bits addressable by the user of the allocated region (e.g., 58 * I/O devices often have a 32-bit limitation even in 64-bit systems). If 59 * zero then the user has no addressing restriction. 60 * This field is not used by XENMEM_decrease_reservation. 61 */ 62 unsigned int address_bits; 63 64 /* 65 * Domain whose reservation is being changed. 66 * Unprivileged domains can specify only DOMID_SELF. 67 */ 68 domid_t domid; 69 }; 70 typedef struct xen_memory_reservation xen_memory_reservation_t; 71 DEFINE_XEN_GUEST_HANDLE(xen_memory_reservation_t); 72 73 /* 74 * An atomic exchange of memory pages. If return code is zero then 75 * @out.extent_list provides GMFNs of the newly-allocated memory. 76 * Returns zero on complete success, otherwise a negative error code. 77 * On complete success then always @nr_exchanged == @in.nr_extents. 78 * On partial success @nr_exchanged indicates how much work was done. 79 */ 80 #define XENMEM_exchange 11 81 struct xen_memory_exchange { 82 /* 83 * [IN] Details of memory extents to be exchanged (GMFN bases). 84 * Note that @in.address_bits is ignored and unused. 85 */ 86 struct xen_memory_reservation in; 87 88 /* 89 * [IN/OUT] Details of new memory extents. 90 * We require that: 91 * 1. @in.domid == @out.domid 92 * 2. @in.nr_extents << @in.extent_order == 93 * @out.nr_extents << @out.extent_order 94 * 3. @in.extent_start and @out.extent_start lists must not overlap 95 * 4. @out.extent_start lists GPFN bases to be populated 96 * 5. @out.extent_start is overwritten with allocated GMFN bases 97 */ 98 struct xen_memory_reservation out; 99 100 /* 101 * [OUT] Number of input extents that were successfully exchanged: 102 * 1. The first @nr_exchanged input extents were successfully 103 * deallocated. 104 * 2. The corresponding first entries in the output extent list correctly 105 * indicate the GMFNs that were successfully exchanged. 106 * 3. All other input and output extents are untouched. 107 * 4. If not all input exents are exchanged then the return code of this 108 * command will be non-zero. 109 * 5. THIS FIELD MUST BE INITIALISED TO ZERO BY THE CALLER! 110 */ 111 xen_ulong_t nr_exchanged; 112 }; 113 typedef struct xen_memory_exchange xen_memory_exchange_t; 114 DEFINE_XEN_GUEST_HANDLE(xen_memory_exchange_t); 115 116 /* 117 * Returns the maximum machine frame number of mapped RAM in this system. 118 * This command always succeeds (it never returns an error code). 119 * arg == NULL. 120 */ 121 #define XENMEM_maximum_ram_page 2 122 123 /* 124 * Returns the current or maximum memory reservation, in pages, of the 125 * specified domain (may be DOMID_SELF). Returns -ve errcode on failure. 126 * arg == addr of domid_t. 127 */ 128 #define XENMEM_current_reservation 3 129 #define XENMEM_maximum_reservation 4 130 131 /* 132 * Returns the maximum GPFN in use by the guest, or -ve errcode on failure. 133 */ 134 #define XENMEM_maximum_gpfn 14 135 136 /* 137 * Returns a list of MFN bases of 2MB extents comprising the machine_to_phys 138 * mapping table. Architectures which do not have a m2p table do not implement 139 * this command. 140 * arg == addr of xen_machphys_mfn_list_t. 141 */ 142 #define XENMEM_machphys_mfn_list 5 143 struct xen_machphys_mfn_list { 144 /* 145 * Size of the 'extent_start' array. Fewer entries will be filled if the 146 * machphys table is smaller than max_extents * 2MB. 147 */ 148 unsigned int max_extents; 149 150 /* 151 * Pointer to buffer to fill with list of extent starts. If there are 152 * any large discontiguities in the machine address space, 2MB gaps in 153 * the machphys table will be represented by an MFN base of zero. 154 */ 155 XEN_GUEST_HANDLE(xen_pfn_t) extent_start; 156 157 /* 158 * Number of extents written to the above array. This will be smaller 159 * than 'max_extents' if the machphys table is smaller than max_e * 2MB. 160 */ 161 unsigned int nr_extents; 162 }; 163 typedef struct xen_machphys_mfn_list xen_machphys_mfn_list_t; 164 DEFINE_XEN_GUEST_HANDLE(xen_machphys_mfn_list_t); 165 166 /* 167 * Returns the location in virtual address space of the machine_to_phys 168 * mapping table. Architectures which do not have a m2p table, or which do not 169 * map it by default into guest address space, do not implement this command. 170 * arg == addr of xen_machphys_mapping_t. 171 */ 172 #define XENMEM_machphys_mapping 12 173 struct xen_machphys_mapping { 174 xen_ulong_t v_start, v_end; /* Start and end virtual addresses. */ 175 xen_ulong_t max_mfn; /* Maximum MFN that can be looked up. */ 176 }; 177 typedef struct xen_machphys_mapping xen_machphys_mapping_t; 178 DEFINE_XEN_GUEST_HANDLE(xen_machphys_mapping_t); 179 180 /* 181 * Sets the GPFN at which a particular page appears in the specified guest's 182 * pseudophysical address space. 183 * arg == addr of xen_add_to_physmap_t. 184 */ 185 #define XENMEM_add_to_physmap 7 186 struct xen_add_to_physmap { 187 /* Which domain to change the mapping for. */ 188 domid_t domid; 189 190 /* Source mapping space. */ 191 #define XENMAPSPACE_shared_info 0 /* shared info page */ 192 #define XENMAPSPACE_grant_table 1 /* grant table page */ 193 unsigned int space; 194 195 /* Index into source mapping space. */ 196 xen_ulong_t idx; 197 198 /* GPFN where the source mapping page should appear. */ 199 xen_pfn_t gpfn; 200 }; 201 typedef struct xen_add_to_physmap xen_add_to_physmap_t; 202 DEFINE_XEN_GUEST_HANDLE(xen_add_to_physmap_t); 203 204 /* 205 * Translates a list of domain-specific GPFNs into MFNs. Returns a -ve error 206 * code on failure. This call only works for auto-translated guests. 207 */ 208 #define XENMEM_translate_gpfn_list 8 209 struct xen_translate_gpfn_list { 210 /* Which domain to translate for? */ 211 domid_t domid; 212 213 /* Length of list. */ 214 xen_ulong_t nr_gpfns; 215 216 /* List of GPFNs to translate. */ 217 XEN_GUEST_HANDLE(xen_pfn_t) gpfn_list; 218 219 /* 220 * Output list to contain MFN translations. May be the same as the input 221 * list (in which case each input GPFN is overwritten with the output MFN). 222 */ 223 XEN_GUEST_HANDLE(xen_pfn_t) mfn_list; 224 }; 225 typedef struct xen_translate_gpfn_list xen_translate_gpfn_list_t; 226 DEFINE_XEN_GUEST_HANDLE(xen_translate_gpfn_list_t); 227 228 /* 229 * Returns the pseudo-physical memory map as it was when the domain 230 * was started (specified by XENMEM_set_memory_map). 231 * arg == addr of xen_memory_map_t. 232 */ 233 #define XENMEM_memory_map 9 234 struct xen_memory_map { 235 /* 236 * On call the number of entries which can be stored in buffer. On 237 * return the number of entries which have been stored in 238 * buffer. 239 */ 240 unsigned int nr_entries; 241 242 /* 243 * Entries in the buffer are in the same format as returned by the 244 * BIOS INT 0x15 EAX=0xE820 call. 245 */ 246 XEN_GUEST_HANDLE(void) buffer; 247 }; 248 typedef struct xen_memory_map xen_memory_map_t; 249 DEFINE_XEN_GUEST_HANDLE(xen_memory_map_t); 250 251 /* 252 * Returns the real physical memory map. Passes the same structure as 253 * XENMEM_memory_map. 254 * arg == addr of xen_memory_map_t. 255 */ 256 #define XENMEM_machine_memory_map 10 257 258 /* 259 * Set the pseudo-physical memory map of a domain, as returned by 260 * XENMEM_memory_map. 261 * arg == addr of xen_foreign_memory_map_t. 262 */ 263 #define XENMEM_set_memory_map 13 264 struct xen_foreign_memory_map { 265 domid_t domid; 266 struct xen_memory_map map; 267 }; 268 typedef struct xen_foreign_memory_map xen_foreign_memory_map_t; 269 DEFINE_XEN_GUEST_HANDLE(xen_foreign_memory_map_t); 270 271 #endif /* __XEN_PUBLIC_MEMORY_H__ */ 272 273 /* 274 * Local variables: 275 * mode: C 276 * c-set-style: "BSD" 277 * c-basic-offset: 4 278 * tab-width: 4 279 * indent-tabs-mode: nil 280 * End: 281 */ 282