1 /* SPDX-License-Identifier: MIT */ 1 /* SPDX-License-Identifier: MIT */ 2 /********************************************* 2 /****************************************************************************** 3 * memory.h 3 * memory.h 4 * 4 * 5 * Memory reservation and information. 5 * Memory reservation and information. 6 * 6 * 7 * Copyright (c) 2005, Keir Fraser <keir@xenso 7 * Copyright (c) 2005, Keir Fraser <keir@xensource.com> 8 */ 8 */ 9 9 10 #ifndef __XEN_PUBLIC_MEMORY_H__ 10 #ifndef __XEN_PUBLIC_MEMORY_H__ 11 #define __XEN_PUBLIC_MEMORY_H__ 11 #define __XEN_PUBLIC_MEMORY_H__ 12 12 13 #include <linux/spinlock.h> 13 #include <linux/spinlock.h> 14 14 15 /* 15 /* 16 * Increase or decrease the specified domain's 16 * Increase or decrease the specified domain's memory reservation. Returns a 17 * -ve errcode on failure, or the # extents su 17 * -ve errcode on failure, or the # extents successfully allocated or freed. 18 * arg == addr of struct xen_memory_reservatio 18 * arg == addr of struct xen_memory_reservation. 19 */ 19 */ 20 #define XENMEM_increase_reservation 0 20 #define XENMEM_increase_reservation 0 21 #define XENMEM_decrease_reservation 1 21 #define XENMEM_decrease_reservation 1 22 #define XENMEM_populate_physmap 6 22 #define XENMEM_populate_physmap 6 23 struct xen_memory_reservation { 23 struct xen_memory_reservation { 24 24 25 /* 25 /* 26 * XENMEM_increase_reservation: 26 * XENMEM_increase_reservation: 27 * OUT: MFN (*not* GMFN) bases of extent 27 * OUT: MFN (*not* GMFN) bases of extents that were allocated 28 * XENMEM_decrease_reservation: 28 * XENMEM_decrease_reservation: 29 * IN: GMFN bases of extents to free 29 * IN: GMFN bases of extents to free 30 * XENMEM_populate_physmap: 30 * XENMEM_populate_physmap: 31 * IN: GPFN bases of extents to populat 31 * IN: GPFN bases of extents to populate with memory 32 * OUT: GMFN bases of extents that were 32 * OUT: GMFN bases of extents that were allocated 33 * (NB. This command also updates the ma 33 * (NB. This command also updates the mach_to_phys translation table) 34 */ 34 */ 35 GUEST_HANDLE(xen_pfn_t) extent_start; 35 GUEST_HANDLE(xen_pfn_t) extent_start; 36 36 37 /* Number of extents, and size/alignment o 37 /* Number of extents, and size/alignment of each (2^extent_order pages). */ 38 xen_ulong_t nr_extents; 38 xen_ulong_t nr_extents; 39 unsigned int extent_order; 39 unsigned int extent_order; 40 40 41 /* 41 /* 42 * Maximum # bits addressable by the user 42 * Maximum # bits addressable by the user of the allocated region (e.g., 43 * I/O devices often have a 32-bit limitat 43 * I/O devices often have a 32-bit limitation even in 64-bit systems). If 44 * zero then the user has no addressing re 44 * zero then the user has no addressing restriction. 45 * This field is not used by XENMEM_decrea 45 * This field is not used by XENMEM_decrease_reservation. 46 */ 46 */ 47 unsigned int address_bits; 47 unsigned int address_bits; 48 48 49 /* 49 /* 50 * Domain whose reservation is being chang 50 * Domain whose reservation is being changed. 51 * Unprivileged domains can specify only D 51 * Unprivileged domains can specify only DOMID_SELF. 52 */ 52 */ 53 domid_t domid; 53 domid_t domid; 54 54 55 }; 55 }; 56 DEFINE_GUEST_HANDLE_STRUCT(xen_memory_reservat 56 DEFINE_GUEST_HANDLE_STRUCT(xen_memory_reservation); 57 57 58 /* 58 /* 59 * An atomic exchange of memory pages. If retu 59 * An atomic exchange of memory pages. If return code is zero then 60 * @out.extent_list provides GMFNs of the newl 60 * @out.extent_list provides GMFNs of the newly-allocated memory. 61 * Returns zero on complete success, otherwise 61 * Returns zero on complete success, otherwise a negative error code. 62 * On complete success then always @nr_exchang 62 * On complete success then always @nr_exchanged == @in.nr_extents. 63 * On partial success @nr_exchanged indicates 63 * On partial success @nr_exchanged indicates how much work was done. 64 */ 64 */ 65 #define XENMEM_exchange 11 65 #define XENMEM_exchange 11 66 struct xen_memory_exchange { 66 struct xen_memory_exchange { 67 /* 67 /* 68 * [IN] Details of memory extents to be ex 68 * [IN] Details of memory extents to be exchanged (GMFN bases). 69 * Note that @in.address_bits is ignored a 69 * Note that @in.address_bits is ignored and unused. 70 */ 70 */ 71 struct xen_memory_reservation in; 71 struct xen_memory_reservation in; 72 72 73 /* 73 /* 74 * [IN/OUT] Details of new memory extents. 74 * [IN/OUT] Details of new memory extents. 75 * We require that: 75 * We require that: 76 * 1. @in.domid == @out.domid 76 * 1. @in.domid == @out.domid 77 * 2. @in.nr_extents << @in.extent_order 77 * 2. @in.nr_extents << @in.extent_order == 78 * @out.nr_extents << @out.extent_orde 78 * @out.nr_extents << @out.extent_order 79 * 3. @in.extent_start and @out.extent_st 79 * 3. @in.extent_start and @out.extent_start lists must not overlap 80 * 4. @out.extent_start lists GPFN bases 80 * 4. @out.extent_start lists GPFN bases to be populated 81 * 5. @out.extent_start is overwritten wi 81 * 5. @out.extent_start is overwritten with allocated GMFN bases 82 */ 82 */ 83 struct xen_memory_reservation out; 83 struct xen_memory_reservation out; 84 84 85 /* 85 /* 86 * [OUT] Number of input extents that were 86 * [OUT] Number of input extents that were successfully exchanged: 87 * 1. The first @nr_exchanged input exten 87 * 1. The first @nr_exchanged input extents were successfully 88 * deallocated. 88 * deallocated. 89 * 2. The corresponding first entries in 89 * 2. The corresponding first entries in the output extent list correctly 90 * indicate the GMFNs that were succes 90 * indicate the GMFNs that were successfully exchanged. 91 * 3. All other input and output extents 91 * 3. All other input and output extents are untouched. 92 * 4. If not all input exents are exchang 92 * 4. If not all input exents are exchanged then the return code of this 93 * command will be non-zero. 93 * command will be non-zero. 94 * 5. THIS FIELD MUST BE INITIALISED TO Z 94 * 5. THIS FIELD MUST BE INITIALISED TO ZERO BY THE CALLER! 95 */ 95 */ 96 xen_ulong_t nr_exchanged; 96 xen_ulong_t nr_exchanged; 97 }; 97 }; 98 98 99 DEFINE_GUEST_HANDLE_STRUCT(xen_memory_exchange 99 DEFINE_GUEST_HANDLE_STRUCT(xen_memory_exchange); 100 /* 100 /* 101 * Returns the maximum machine frame number of 101 * Returns the maximum machine frame number of mapped RAM in this system. 102 * This command always succeeds (it never retu 102 * This command always succeeds (it never returns an error code). 103 * arg == NULL. 103 * arg == NULL. 104 */ 104 */ 105 #define XENMEM_maximum_ram_page 2 105 #define XENMEM_maximum_ram_page 2 106 106 107 /* 107 /* 108 * Returns the current or maximum memory reser 108 * Returns the current or maximum memory reservation, in pages, of the 109 * specified domain (may be DOMID_SELF). Retur 109 * specified domain (may be DOMID_SELF). Returns -ve errcode on failure. 110 * arg == addr of domid_t. 110 * arg == addr of domid_t. 111 */ 111 */ 112 #define XENMEM_current_reservation 3 112 #define XENMEM_current_reservation 3 113 #define XENMEM_maximum_reservation 4 113 #define XENMEM_maximum_reservation 4 114 114 115 /* 115 /* 116 * Returns a list of MFN bases of 2MB extents 116 * Returns a list of MFN bases of 2MB extents comprising the machine_to_phys 117 * mapping table. Architectures which do not h 117 * mapping table. Architectures which do not have a m2p table do not implement 118 * this command. 118 * this command. 119 * arg == addr of xen_machphys_mfn_list_t. 119 * arg == addr of xen_machphys_mfn_list_t. 120 */ 120 */ 121 #define XENMEM_machphys_mfn_list 5 121 #define XENMEM_machphys_mfn_list 5 122 struct xen_machphys_mfn_list { 122 struct xen_machphys_mfn_list { 123 /* 123 /* 124 * Size of the 'extent_start' array. Fewer 124 * Size of the 'extent_start' array. Fewer entries will be filled if the 125 * machphys table is smaller than max_exte 125 * machphys table is smaller than max_extents * 2MB. 126 */ 126 */ 127 unsigned int max_extents; 127 unsigned int max_extents; 128 128 129 /* 129 /* 130 * Pointer to buffer to fill with list of 130 * Pointer to buffer to fill with list of extent starts. If there are 131 * any large discontiguities in the machin 131 * any large discontiguities in the machine address space, 2MB gaps in 132 * the machphys table will be represented 132 * the machphys table will be represented by an MFN base of zero. 133 */ 133 */ 134 GUEST_HANDLE(xen_pfn_t) extent_start; 134 GUEST_HANDLE(xen_pfn_t) extent_start; 135 135 136 /* 136 /* 137 * Number of extents written to the above 137 * Number of extents written to the above array. This will be smaller 138 * than 'max_extents' if the machphys tabl 138 * than 'max_extents' if the machphys table is smaller than max_e * 2MB. 139 */ 139 */ 140 unsigned int nr_extents; 140 unsigned int nr_extents; 141 }; 141 }; 142 DEFINE_GUEST_HANDLE_STRUCT(xen_machphys_mfn_li 142 DEFINE_GUEST_HANDLE_STRUCT(xen_machphys_mfn_list); 143 143 144 /* 144 /* 145 * Returns the location in virtual address spa 145 * Returns the location in virtual address space of the machine_to_phys 146 * mapping table. Architectures which do not h 146 * mapping table. Architectures which do not have a m2p table, or which do not 147 * map it by default into guest address space, 147 * map it by default into guest address space, do not implement this command. 148 * arg == addr of xen_machphys_mapping_t. 148 * arg == addr of xen_machphys_mapping_t. 149 */ 149 */ 150 #define XENMEM_machphys_mapping 12 150 #define XENMEM_machphys_mapping 12 151 struct xen_machphys_mapping { 151 struct xen_machphys_mapping { 152 xen_ulong_t v_start, v_end; /* Start and e 152 xen_ulong_t v_start, v_end; /* Start and end virtual addresses. */ 153 xen_ulong_t max_mfn; /* Maximum MFN 153 xen_ulong_t max_mfn; /* Maximum MFN that can be looked up. */ 154 }; 154 }; 155 DEFINE_GUEST_HANDLE_STRUCT(xen_machphys_mappin 155 DEFINE_GUEST_HANDLE_STRUCT(xen_machphys_mapping_t); 156 156 157 #define XENMAPSPACE_shared_info 0 /* shared i 157 #define XENMAPSPACE_shared_info 0 /* shared info page */ 158 #define XENMAPSPACE_grant_table 1 /* grant ta 158 #define XENMAPSPACE_grant_table 1 /* grant table page */ 159 #define XENMAPSPACE_gmfn 2 /* GMFN */ 159 #define XENMAPSPACE_gmfn 2 /* GMFN */ 160 #define XENMAPSPACE_gmfn_range 3 /* GMFN ran 160 #define XENMAPSPACE_gmfn_range 3 /* GMFN range, XENMEM_add_to_physmap only. */ 161 #define XENMAPSPACE_gmfn_foreign 4 /* GMFN fro 161 #define XENMAPSPACE_gmfn_foreign 4 /* GMFN from another dom, 162 * XENMEM_a 162 * XENMEM_add_to_physmap_range only. 163 */ 163 */ 164 #define XENMAPSPACE_dev_mmio 5 /* device m 164 #define XENMAPSPACE_dev_mmio 5 /* device mmio region */ 165 165 166 /* 166 /* 167 * Sets the GPFN at which a particular page ap 167 * Sets the GPFN at which a particular page appears in the specified guest's 168 * pseudophysical address space. 168 * pseudophysical address space. 169 * arg == addr of xen_add_to_physmap_t. 169 * arg == addr of xen_add_to_physmap_t. 170 */ 170 */ 171 #define XENMEM_add_to_physmap 7 171 #define XENMEM_add_to_physmap 7 172 struct xen_add_to_physmap { 172 struct xen_add_to_physmap { 173 /* Which domain to change the mapping for. 173 /* Which domain to change the mapping for. */ 174 domid_t domid; 174 domid_t domid; 175 175 176 /* Number of pages to go through for gmfn_ 176 /* Number of pages to go through for gmfn_range */ 177 uint16_t size; 177 uint16_t size; 178 178 179 /* Source mapping space. */ 179 /* Source mapping space. */ 180 unsigned int space; 180 unsigned int space; 181 181 182 /* Index into source mapping space. */ 182 /* Index into source mapping space. */ 183 xen_ulong_t idx; 183 xen_ulong_t idx; 184 184 185 /* GPFN where the source mapping page shou 185 /* GPFN where the source mapping page should appear. */ 186 xen_pfn_t gpfn; 186 xen_pfn_t gpfn; 187 }; 187 }; 188 DEFINE_GUEST_HANDLE_STRUCT(xen_add_to_physmap) 188 DEFINE_GUEST_HANDLE_STRUCT(xen_add_to_physmap); 189 189 190 /*** REMOVED ***/ 190 /*** REMOVED ***/ 191 /*#define XENMEM_translate_gpfn_list 8*/ 191 /*#define XENMEM_translate_gpfn_list 8*/ 192 192 193 #define XENMEM_add_to_physmap_range 23 193 #define XENMEM_add_to_physmap_range 23 194 struct xen_add_to_physmap_range { 194 struct xen_add_to_physmap_range { 195 /* IN */ 195 /* IN */ 196 /* Which domain to change the mapping for. 196 /* Which domain to change the mapping for. */ 197 domid_t domid; 197 domid_t domid; 198 uint16_t space; /* => enum phys_map_space 198 uint16_t space; /* => enum phys_map_space */ 199 199 200 /* Number of pages to go through */ 200 /* Number of pages to go through */ 201 uint16_t size; 201 uint16_t size; 202 domid_t foreign_domid; /* IFF gmfn_foreign 202 domid_t foreign_domid; /* IFF gmfn_foreign */ 203 203 204 /* Indexes into space being mapped. */ 204 /* Indexes into space being mapped. */ 205 GUEST_HANDLE(xen_ulong_t) idxs; 205 GUEST_HANDLE(xen_ulong_t) idxs; 206 206 207 /* GPFN in domid where the source mapping 207 /* GPFN in domid where the source mapping page should appear. */ 208 GUEST_HANDLE(xen_pfn_t) gpfns; 208 GUEST_HANDLE(xen_pfn_t) gpfns; 209 209 210 /* OUT */ 210 /* OUT */ 211 211 212 /* Per index error code. */ 212 /* Per index error code. */ 213 GUEST_HANDLE(int) errs; 213 GUEST_HANDLE(int) errs; 214 }; 214 }; 215 DEFINE_GUEST_HANDLE_STRUCT(xen_add_to_physmap_ 215 DEFINE_GUEST_HANDLE_STRUCT(xen_add_to_physmap_range); 216 216 217 /* 217 /* 218 * Returns the pseudo-physical memory map as i 218 * Returns the pseudo-physical memory map as it was when the domain 219 * was started (specified by XENMEM_set_memory 219 * was started (specified by XENMEM_set_memory_map). 220 * arg == addr of struct xen_memory_map. 220 * arg == addr of struct xen_memory_map. 221 */ 221 */ 222 #define XENMEM_memory_map 9 222 #define XENMEM_memory_map 9 223 struct xen_memory_map { 223 struct xen_memory_map { 224 /* 224 /* 225 * On call the number of entries which can 225 * On call the number of entries which can be stored in buffer. On 226 * return the number of entries which have 226 * return the number of entries which have been stored in 227 * buffer. 227 * buffer. 228 */ 228 */ 229 unsigned int nr_entries; 229 unsigned int nr_entries; 230 230 231 /* 231 /* 232 * Entries in the buffer are in the same f 232 * Entries in the buffer are in the same format as returned by the 233 * BIOS INT 0x15 EAX=0xE820 call. 233 * BIOS INT 0x15 EAX=0xE820 call. 234 */ 234 */ 235 GUEST_HANDLE(void) buffer; 235 GUEST_HANDLE(void) buffer; 236 }; 236 }; 237 DEFINE_GUEST_HANDLE_STRUCT(xen_memory_map); 237 DEFINE_GUEST_HANDLE_STRUCT(xen_memory_map); 238 238 239 /* 239 /* 240 * Returns the real physical memory map. Passe 240 * Returns the real physical memory map. Passes the same structure as 241 * XENMEM_memory_map. 241 * XENMEM_memory_map. 242 * arg == addr of struct xen_memory_map. 242 * arg == addr of struct xen_memory_map. 243 */ 243 */ 244 #define XENMEM_machine_memory_map 10 244 #define XENMEM_machine_memory_map 10 245 245 246 246 247 /* 247 /* 248 * Unmaps the page appearing at a particular G 248 * Unmaps the page appearing at a particular GPFN from the specified guest's 249 * pseudophysical address space. 249 * pseudophysical address space. 250 * arg == addr of xen_remove_from_physmap_t. 250 * arg == addr of xen_remove_from_physmap_t. 251 */ 251 */ 252 #define XENMEM_remove_from_physmap 15 252 #define XENMEM_remove_from_physmap 15 253 struct xen_remove_from_physmap { 253 struct xen_remove_from_physmap { 254 /* Which domain to change the mapping for. 254 /* Which domain to change the mapping for. */ 255 domid_t domid; 255 domid_t domid; 256 256 257 /* GPFN of the current mapping of the page 257 /* GPFN of the current mapping of the page. */ 258 xen_pfn_t gpfn; 258 xen_pfn_t gpfn; 259 }; 259 }; 260 DEFINE_GUEST_HANDLE_STRUCT(xen_remove_from_phy 260 DEFINE_GUEST_HANDLE_STRUCT(xen_remove_from_physmap); 261 261 262 /* 262 /* 263 * Get the pages for a particular guest resour 263 * Get the pages for a particular guest resource, so that they can be 264 * mapped directly by a tools domain. 264 * mapped directly by a tools domain. 265 */ 265 */ 266 #define XENMEM_acquire_resource 28 266 #define XENMEM_acquire_resource 28 267 struct xen_mem_acquire_resource { 267 struct xen_mem_acquire_resource { 268 /* IN - The domain whose resource is to be 268 /* IN - The domain whose resource is to be mapped */ 269 domid_t domid; 269 domid_t domid; 270 /* IN - the type of resource */ 270 /* IN - the type of resource */ 271 uint16_t type; 271 uint16_t type; 272 272 273 #define XENMEM_resource_ioreq_server 0 273 #define XENMEM_resource_ioreq_server 0 274 #define XENMEM_resource_grant_table 1 274 #define XENMEM_resource_grant_table 1 275 275 276 /* 276 /* 277 * IN - a type-specific resource identifie 277 * IN - a type-specific resource identifier, which must be zero 278 * unless stated otherwise. 278 * unless stated otherwise. 279 * 279 * 280 * type == XENMEM_resource_ioreq_server -> 280 * type == XENMEM_resource_ioreq_server -> id == ioreq server id 281 * type == XENMEM_resource_grant_table -> 281 * type == XENMEM_resource_grant_table -> id defined below 282 */ 282 */ 283 uint32_t id; 283 uint32_t id; 284 284 285 #define XENMEM_resource_grant_table_id_shared 285 #define XENMEM_resource_grant_table_id_shared 0 286 #define XENMEM_resource_grant_table_id_status 286 #define XENMEM_resource_grant_table_id_status 1 287 287 288 /* IN/OUT - As an IN parameter number of f 288 /* IN/OUT - As an IN parameter number of frames of the resource 289 * to be mapped. However, if the 289 * to be mapped. However, if the specified value is 0 and 290 * frame_list is NULL then this f 290 * frame_list is NULL then this field will be set to the 291 * maximum value supported by the 291 * maximum value supported by the implementation on return. 292 */ 292 */ 293 uint32_t nr_frames; 293 uint32_t nr_frames; 294 /* 294 /* 295 * OUT - Must be zero on entry. On return 295 * OUT - Must be zero on entry. On return this may contain a bitwise 296 * OR of the following values. 296 * OR of the following values. 297 */ 297 */ 298 uint32_t flags; 298 uint32_t flags; 299 299 300 /* The resource pages have been assigned t 300 /* The resource pages have been assigned to the calling domain */ 301 #define _XENMEM_rsrc_acq_caller_owned 0 301 #define _XENMEM_rsrc_acq_caller_owned 0 302 #define XENMEM_rsrc_acq_caller_owned (1u << _X 302 #define XENMEM_rsrc_acq_caller_owned (1u << _XENMEM_rsrc_acq_caller_owned) 303 303 304 /* 304 /* 305 * IN - the index of the initial frame to 305 * IN - the index of the initial frame to be mapped. This parameter 306 * is ignored if nr_frames is 0. 306 * is ignored if nr_frames is 0. 307 */ 307 */ 308 uint64_t frame; 308 uint64_t frame; 309 309 310 #define XENMEM_resource_ioreq_server_frame_buf 310 #define XENMEM_resource_ioreq_server_frame_bufioreq 0 311 #define XENMEM_resource_ioreq_server_frame_ior 311 #define XENMEM_resource_ioreq_server_frame_ioreq(n) (1 + (n)) 312 312 313 /* 313 /* 314 * IN/OUT - If the tools domain is PV then 314 * IN/OUT - If the tools domain is PV then, upon return, frame_list 315 * will be populated with the MFN 315 * will be populated with the MFNs of the resource. 316 * If the tools domain is HVM the 316 * If the tools domain is HVM then it is expected that, on 317 * entry, frame_list will be popu 317 * entry, frame_list will be populated with a list of GFNs 318 * that will be mapped to the MFN 318 * that will be mapped to the MFNs of the resource. 319 * If -EIO is returned then the f 319 * If -EIO is returned then the frame_list has only been 320 * partially mapped and it is up 320 * partially mapped and it is up to the caller to unmap all 321 * the GFNs. 321 * the GFNs. 322 * This parameter may be NULL if 322 * This parameter may be NULL if nr_frames is 0. 323 */ 323 */ 324 GUEST_HANDLE(xen_pfn_t) frame_list; 324 GUEST_HANDLE(xen_pfn_t) frame_list; 325 }; 325 }; 326 DEFINE_GUEST_HANDLE_STRUCT(xen_mem_acquire_res 326 DEFINE_GUEST_HANDLE_STRUCT(xen_mem_acquire_resource); 327 327 328 #endif /* __XEN_PUBLIC_MEMORY_H__ */ 328 #endif /* __XEN_PUBLIC_MEMORY_H__ */ 329 329
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.