1181624Skmacy/****************************************************************************** 2181624Skmacy * memory.h 3181624Skmacy * 4181624Skmacy * Memory reservation and information. 5181624Skmacy * 6181624Skmacy * Permission is hereby granted, free of charge, to any person obtaining a copy 7181624Skmacy * of this software and associated documentation files (the "Software"), to 8181624Skmacy * deal in the Software without restriction, including without limitation the 9181624Skmacy * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10181624Skmacy * sell copies of the Software, and to permit persons to whom the Software is 11181624Skmacy * furnished to do so, subject to the following conditions: 12181624Skmacy * 13181624Skmacy * The above copyright notice and this permission notice shall be included in 14181624Skmacy * all copies or substantial portions of the Software. 15181624Skmacy * 16181624Skmacy * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17181624Skmacy * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18181624Skmacy * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19181624Skmacy * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20181624Skmacy * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21181624Skmacy * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22181624Skmacy * DEALINGS IN THE SOFTWARE. 23181624Skmacy * 24181624Skmacy * Copyright (c) 2005, Keir Fraser <keir@xensource.com> 25181624Skmacy */ 26181624Skmacy 27181624Skmacy#ifndef __XEN_PUBLIC_MEMORY_H__ 28181624Skmacy#define __XEN_PUBLIC_MEMORY_H__ 29181624Skmacy 30251767Sgibbs#include "xen.h" 31251767Sgibbs 32181624Skmacy/* 33181624Skmacy * Increase or decrease the specified domain's memory reservation. Returns the 34181624Skmacy * number of extents successfully allocated or freed. 35181624Skmacy * arg == addr of struct xen_memory_reservation. 36181624Skmacy */ 37181624Skmacy#define XENMEM_increase_reservation 0 38181624Skmacy#define XENMEM_decrease_reservation 1 39181624Skmacy#define XENMEM_populate_physmap 6 40183375Skmacy 41183375Skmacy#if __XEN_INTERFACE_VERSION__ >= 0x00030209 42183375Skmacy/* 43183375Skmacy * Maximum # bits addressable by the user of the allocated region (e.g., I/O 44183375Skmacy * devices often have a 32-bit limitation even in 64-bit systems). If zero 45183375Skmacy * then the user has no addressing restriction. This field is not used by 46183375Skmacy * XENMEM_decrease_reservation. 47183375Skmacy */ 48183375Skmacy#define XENMEMF_address_bits(x) (x) 49183375Skmacy#define XENMEMF_get_address_bits(x) ((x) & 0xffu) 50183375Skmacy/* NUMA node to allocate from. */ 51183375Skmacy#define XENMEMF_node(x) (((x) + 1) << 8) 52183375Skmacy#define XENMEMF_get_node(x) ((((x) >> 8) - 1) & 0xffu) 53251767Sgibbs/* Flag to populate physmap with populate-on-demand entries */ 54251767Sgibbs#define XENMEMF_populate_on_demand (1<<16) 55251767Sgibbs/* Flag to request allocation only from the node specified */ 56251767Sgibbs#define XENMEMF_exact_node_request (1<<17) 57251767Sgibbs#define XENMEMF_exact_node(n) (XENMEMF_node(n) | XENMEMF_exact_node_request) 58183375Skmacy#endif 59183375Skmacy 60181624Skmacystruct xen_memory_reservation { 61181624Skmacy 62181624Skmacy /* 63181624Skmacy * XENMEM_increase_reservation: 64181624Skmacy * OUT: MFN (*not* GMFN) bases of extents that were allocated 65181624Skmacy * XENMEM_decrease_reservation: 66181624Skmacy * IN: GMFN bases of extents to free 67181624Skmacy * XENMEM_populate_physmap: 68181624Skmacy * IN: GPFN bases of extents to populate with memory 69181624Skmacy * OUT: GMFN bases of extents that were allocated 70181624Skmacy * (NB. This command also updates the mach_to_phys translation table) 71181624Skmacy */ 72183375Skmacy XEN_GUEST_HANDLE(xen_pfn_t) extent_start; 73181624Skmacy 74181624Skmacy /* Number of extents, and size/alignment of each (2^extent_order pages). */ 75181624Skmacy xen_ulong_t nr_extents; 76181624Skmacy unsigned int extent_order; 77181624Skmacy 78183375Skmacy#if __XEN_INTERFACE_VERSION__ >= 0x00030209 79183375Skmacy /* XENMEMF flags. */ 80183375Skmacy unsigned int mem_flags; 81183375Skmacy#else 82181624Skmacy unsigned int address_bits; 83183375Skmacy#endif 84181624Skmacy 85181624Skmacy /* 86181624Skmacy * Domain whose reservation is being changed. 87181624Skmacy * Unprivileged domains can specify only DOMID_SELF. 88181624Skmacy */ 89181624Skmacy domid_t domid; 90181624Skmacy}; 91181624Skmacytypedef struct xen_memory_reservation xen_memory_reservation_t; 92181624SkmacyDEFINE_XEN_GUEST_HANDLE(xen_memory_reservation_t); 93181624Skmacy 94181624Skmacy/* 95181624Skmacy * An atomic exchange of memory pages. If return code is zero then 96181624Skmacy * @out.extent_list provides GMFNs of the newly-allocated memory. 97181624Skmacy * Returns zero on complete success, otherwise a negative error code. 98181624Skmacy * On complete success then always @nr_exchanged == @in.nr_extents. 99181624Skmacy * On partial success @nr_exchanged indicates how much work was done. 100181624Skmacy */ 101181624Skmacy#define XENMEM_exchange 11 102181624Skmacystruct xen_memory_exchange { 103181624Skmacy /* 104181624Skmacy * [IN] Details of memory extents to be exchanged (GMFN bases). 105181624Skmacy * Note that @in.address_bits is ignored and unused. 106181624Skmacy */ 107181624Skmacy struct xen_memory_reservation in; 108181624Skmacy 109181624Skmacy /* 110181624Skmacy * [IN/OUT] Details of new memory extents. 111181624Skmacy * We require that: 112181624Skmacy * 1. @in.domid == @out.domid 113181624Skmacy * 2. @in.nr_extents << @in.extent_order == 114181624Skmacy * @out.nr_extents << @out.extent_order 115181624Skmacy * 3. @in.extent_start and @out.extent_start lists must not overlap 116181624Skmacy * 4. @out.extent_start lists GPFN bases to be populated 117181624Skmacy * 5. @out.extent_start is overwritten with allocated GMFN bases 118181624Skmacy */ 119181624Skmacy struct xen_memory_reservation out; 120181624Skmacy 121181624Skmacy /* 122181624Skmacy * [OUT] Number of input extents that were successfully exchanged: 123181624Skmacy * 1. The first @nr_exchanged input extents were successfully 124181624Skmacy * deallocated. 125181624Skmacy * 2. The corresponding first entries in the output extent list correctly 126181624Skmacy * indicate the GMFNs that were successfully exchanged. 127181624Skmacy * 3. All other input and output extents are untouched. 128181624Skmacy * 4. If not all input exents are exchanged then the return code of this 129181624Skmacy * command will be non-zero. 130181624Skmacy * 5. THIS FIELD MUST BE INITIALISED TO ZERO BY THE CALLER! 131181624Skmacy */ 132181624Skmacy xen_ulong_t nr_exchanged; 133181624Skmacy}; 134181624Skmacytypedef struct xen_memory_exchange xen_memory_exchange_t; 135181624SkmacyDEFINE_XEN_GUEST_HANDLE(xen_memory_exchange_t); 136181624Skmacy 137181624Skmacy/* 138181624Skmacy * Returns the maximum machine frame number of mapped RAM in this system. 139181624Skmacy * This command always succeeds (it never returns an error code). 140181624Skmacy * arg == NULL. 141181624Skmacy */ 142181624Skmacy#define XENMEM_maximum_ram_page 2 143181624Skmacy 144181624Skmacy/* 145181624Skmacy * Returns the current or maximum memory reservation, in pages, of the 146181624Skmacy * specified domain (may be DOMID_SELF). Returns -ve errcode on failure. 147181624Skmacy * arg == addr of domid_t. 148181624Skmacy */ 149181624Skmacy#define XENMEM_current_reservation 3 150181624Skmacy#define XENMEM_maximum_reservation 4 151181624Skmacy 152181624Skmacy/* 153181624Skmacy * Returns the maximum GPFN in use by the guest, or -ve errcode on failure. 154181624Skmacy */ 155181624Skmacy#define XENMEM_maximum_gpfn 14 156181624Skmacy 157181624Skmacy/* 158181624Skmacy * Returns a list of MFN bases of 2MB extents comprising the machine_to_phys 159181624Skmacy * mapping table. Architectures which do not have a m2p table do not implement 160181624Skmacy * this command. 161181624Skmacy * arg == addr of xen_machphys_mfn_list_t. 162181624Skmacy */ 163181624Skmacy#define XENMEM_machphys_mfn_list 5 164181624Skmacystruct xen_machphys_mfn_list { 165181624Skmacy /* 166181624Skmacy * Size of the 'extent_start' array. Fewer entries will be filled if the 167181624Skmacy * machphys table is smaller than max_extents * 2MB. 168181624Skmacy */ 169181624Skmacy unsigned int max_extents; 170181624Skmacy 171181624Skmacy /* 172181624Skmacy * Pointer to buffer to fill with list of extent starts. If there are 173181624Skmacy * any large discontiguities in the machine address space, 2MB gaps in 174181624Skmacy * the machphys table will be represented by an MFN base of zero. 175181624Skmacy */ 176183375Skmacy XEN_GUEST_HANDLE(xen_pfn_t) extent_start; 177181624Skmacy 178181624Skmacy /* 179181624Skmacy * Number of extents written to the above array. This will be smaller 180181624Skmacy * than 'max_extents' if the machphys table is smaller than max_e * 2MB. 181181624Skmacy */ 182181624Skmacy unsigned int nr_extents; 183181624Skmacy}; 184181624Skmacytypedef struct xen_machphys_mfn_list xen_machphys_mfn_list_t; 185181624SkmacyDEFINE_XEN_GUEST_HANDLE(xen_machphys_mfn_list_t); 186181624Skmacy 187181624Skmacy/* 188181624Skmacy * Returns the location in virtual address space of the machine_to_phys 189181624Skmacy * mapping table. Architectures which do not have a m2p table, or which do not 190181624Skmacy * map it by default into guest address space, do not implement this command. 191181624Skmacy * arg == addr of xen_machphys_mapping_t. 192181624Skmacy */ 193181624Skmacy#define XENMEM_machphys_mapping 12 194181624Skmacystruct xen_machphys_mapping { 195181624Skmacy xen_ulong_t v_start, v_end; /* Start and end virtual addresses. */ 196181624Skmacy xen_ulong_t max_mfn; /* Maximum MFN that can be looked up. */ 197181624Skmacy}; 198181624Skmacytypedef struct xen_machphys_mapping xen_machphys_mapping_t; 199181624SkmacyDEFINE_XEN_GUEST_HANDLE(xen_machphys_mapping_t); 200181624Skmacy 201181624Skmacy/* 202181624Skmacy * Sets the GPFN at which a particular page appears in the specified guest's 203181624Skmacy * pseudophysical address space. 204181624Skmacy * arg == addr of xen_add_to_physmap_t. 205181624Skmacy */ 206181624Skmacy#define XENMEM_add_to_physmap 7 207181624Skmacystruct xen_add_to_physmap { 208181624Skmacy /* Which domain to change the mapping for. */ 209181624Skmacy domid_t domid; 210181624Skmacy 211251767Sgibbs /* Number of pages to go through for gmfn_range */ 212251767Sgibbs uint16_t size; 213251767Sgibbs 214181624Skmacy /* Source mapping space. */ 215181624Skmacy#define XENMAPSPACE_shared_info 0 /* shared info page */ 216181624Skmacy#define XENMAPSPACE_grant_table 1 /* grant table page */ 217251767Sgibbs#define XENMAPSPACE_gmfn 2 /* GMFN */ 218251767Sgibbs#define XENMAPSPACE_gmfn_range 3 /* GMFN range */ 219181624Skmacy unsigned int space; 220181624Skmacy 221251767Sgibbs#define XENMAPIDX_grant_table_status 0x80000000 222251767Sgibbs 223181624Skmacy /* Index into source mapping space. */ 224181624Skmacy xen_ulong_t idx; 225181624Skmacy 226181624Skmacy /* GPFN where the source mapping page should appear. */ 227181624Skmacy xen_pfn_t gpfn; 228181624Skmacy}; 229181624Skmacytypedef struct xen_add_to_physmap xen_add_to_physmap_t; 230181624SkmacyDEFINE_XEN_GUEST_HANDLE(xen_add_to_physmap_t); 231181624Skmacy 232181624Skmacy/* 233183375Skmacy * Unmaps the page appearing at a particular GPFN from the specified guest's 234183375Skmacy * pseudophysical address space. 235183375Skmacy * arg == addr of xen_remove_from_physmap_t. 236183375Skmacy */ 237183375Skmacy#define XENMEM_remove_from_physmap 15 238183375Skmacystruct xen_remove_from_physmap { 239183375Skmacy /* Which domain to change the mapping for. */ 240183375Skmacy domid_t domid; 241183375Skmacy 242183375Skmacy /* GPFN of the current mapping of the page. */ 243183375Skmacy xen_pfn_t gpfn; 244183375Skmacy}; 245183375Skmacytypedef struct xen_remove_from_physmap xen_remove_from_physmap_t; 246183375SkmacyDEFINE_XEN_GUEST_HANDLE(xen_remove_from_physmap_t); 247183375Skmacy 248251767Sgibbs/*** REMOVED ***/ 249251767Sgibbs/*#define XENMEM_translate_gpfn_list 8*/ 250181624Skmacy 251181624Skmacy/* 252181624Skmacy * Returns the pseudo-physical memory map as it was when the domain 253181624Skmacy * was started (specified by XENMEM_set_memory_map). 254181624Skmacy * arg == addr of xen_memory_map_t. 255181624Skmacy */ 256181624Skmacy#define XENMEM_memory_map 9 257181624Skmacystruct xen_memory_map { 258181624Skmacy /* 259181624Skmacy * On call the number of entries which can be stored in buffer. On 260181624Skmacy * return the number of entries which have been stored in 261181624Skmacy * buffer. 262181624Skmacy */ 263181624Skmacy unsigned int nr_entries; 264181624Skmacy 265181624Skmacy /* 266181624Skmacy * Entries in the buffer are in the same format as returned by the 267181624Skmacy * BIOS INT 0x15 EAX=0xE820 call. 268181624Skmacy */ 269183375Skmacy XEN_GUEST_HANDLE(void) buffer; 270181624Skmacy}; 271181624Skmacytypedef struct xen_memory_map xen_memory_map_t; 272181624SkmacyDEFINE_XEN_GUEST_HANDLE(xen_memory_map_t); 273181624Skmacy 274181624Skmacy/* 275181624Skmacy * Returns the real physical memory map. Passes the same structure as 276181624Skmacy * XENMEM_memory_map. 277181624Skmacy * arg == addr of xen_memory_map_t. 278181624Skmacy */ 279181624Skmacy#define XENMEM_machine_memory_map 10 280181624Skmacy 281181624Skmacy/* 282181624Skmacy * Set the pseudo-physical memory map of a domain, as returned by 283181624Skmacy * XENMEM_memory_map. 284181624Skmacy * arg == addr of xen_foreign_memory_map_t. 285181624Skmacy */ 286181624Skmacy#define XENMEM_set_memory_map 13 287181624Skmacystruct xen_foreign_memory_map { 288181624Skmacy domid_t domid; 289181624Skmacy struct xen_memory_map map; 290181624Skmacy}; 291181624Skmacytypedef struct xen_foreign_memory_map xen_foreign_memory_map_t; 292181624SkmacyDEFINE_XEN_GUEST_HANDLE(xen_foreign_memory_map_t); 293181624Skmacy 294251767Sgibbs#define XENMEM_set_pod_target 16 295251767Sgibbs#define XENMEM_get_pod_target 17 296251767Sgibbsstruct xen_pod_target { 297251767Sgibbs /* IN */ 298251767Sgibbs uint64_t target_pages; 299251767Sgibbs /* OUT */ 300251767Sgibbs uint64_t tot_pages; 301251767Sgibbs uint64_t pod_cache_pages; 302251767Sgibbs uint64_t pod_entries; 303251767Sgibbs /* IN */ 304251767Sgibbs domid_t domid; 305251767Sgibbs}; 306251767Sgibbstypedef struct xen_pod_target xen_pod_target_t; 307251767Sgibbs 308251767Sgibbs#if defined(__XEN__) || defined(__XEN_TOOLS__) 309251767Sgibbs 310251767Sgibbs#ifndef uint64_aligned_t 311251767Sgibbs#define uint64_aligned_t uint64_t 312251767Sgibbs#endif 313251767Sgibbs 314251767Sgibbs/* 315251767Sgibbs * Get the number of MFNs saved through memory sharing. 316251767Sgibbs * The call never fails. 317251767Sgibbs */ 318251767Sgibbs#define XENMEM_get_sharing_freed_pages 18 319251767Sgibbs#define XENMEM_get_sharing_shared_pages 19 320251767Sgibbs 321251767Sgibbs#define XENMEM_paging_op 20 322251767Sgibbs#define XENMEM_paging_op_nominate 0 323251767Sgibbs#define XENMEM_paging_op_evict 1 324251767Sgibbs#define XENMEM_paging_op_prep 2 325251767Sgibbs 326251767Sgibbs#define XENMEM_access_op 21 327251767Sgibbs#define XENMEM_access_op_resume 0 328251767Sgibbs 329251767Sgibbsstruct xen_mem_event_op { 330251767Sgibbs uint8_t op; /* XENMEM_*_op_* */ 331251767Sgibbs domid_t domain; 332251767Sgibbs 333251767Sgibbs 334251767Sgibbs /* PAGING_PREP IN: buffer to immediately fill page in */ 335251767Sgibbs uint64_aligned_t buffer; 336251767Sgibbs /* Other OPs */ 337251767Sgibbs uint64_aligned_t gfn; /* IN: gfn of page being operated on */ 338251767Sgibbs}; 339251767Sgibbstypedef struct xen_mem_event_op xen_mem_event_op_t; 340251767SgibbsDEFINE_XEN_GUEST_HANDLE(xen_mem_event_op_t); 341251767Sgibbs 342251767Sgibbs#define XENMEM_sharing_op 22 343251767Sgibbs#define XENMEM_sharing_op_nominate_gfn 0 344251767Sgibbs#define XENMEM_sharing_op_nominate_gref 1 345251767Sgibbs#define XENMEM_sharing_op_share 2 346251767Sgibbs#define XENMEM_sharing_op_resume 3 347251767Sgibbs#define XENMEM_sharing_op_debug_gfn 4 348251767Sgibbs#define XENMEM_sharing_op_debug_mfn 5 349251767Sgibbs#define XENMEM_sharing_op_debug_gref 6 350251767Sgibbs#define XENMEM_sharing_op_add_physmap 7 351251767Sgibbs#define XENMEM_sharing_op_audit 8 352251767Sgibbs 353251767Sgibbs#define XENMEM_SHARING_OP_S_HANDLE_INVALID (-10) 354251767Sgibbs#define XENMEM_SHARING_OP_C_HANDLE_INVALID (-9) 355251767Sgibbs 356251767Sgibbs/* The following allows sharing of grant refs. This is useful 357251767Sgibbs * for sharing utilities sitting as "filters" in IO backends 358251767Sgibbs * (e.g. memshr + blktap(2)). The IO backend is only exposed 359251767Sgibbs * to grant references, and this allows sharing of the grefs */ 360251767Sgibbs#define XENMEM_SHARING_OP_FIELD_IS_GREF_FLAG (1ULL << 62) 361251767Sgibbs 362251767Sgibbs#define XENMEM_SHARING_OP_FIELD_MAKE_GREF(field, val) \ 363251767Sgibbs (field) = (XENMEM_SHARING_OP_FIELD_IS_GREF_FLAG | val) 364251767Sgibbs#define XENMEM_SHARING_OP_FIELD_IS_GREF(field) \ 365251767Sgibbs ((field) & XENMEM_SHARING_OP_FIELD_IS_GREF_FLAG) 366251767Sgibbs#define XENMEM_SHARING_OP_FIELD_GET_GREF(field) \ 367251767Sgibbs ((field) & (~XENMEM_SHARING_OP_FIELD_IS_GREF_FLAG)) 368251767Sgibbs 369251767Sgibbsstruct xen_mem_sharing_op { 370251767Sgibbs uint8_t op; /* XENMEM_sharing_op_* */ 371251767Sgibbs domid_t domain; 372251767Sgibbs 373251767Sgibbs union { 374251767Sgibbs struct mem_sharing_op_nominate { /* OP_NOMINATE_xxx */ 375251767Sgibbs union { 376251767Sgibbs uint64_aligned_t gfn; /* IN: gfn to nominate */ 377251767Sgibbs uint32_t grant_ref; /* IN: grant ref to nominate */ 378251767Sgibbs } u; 379251767Sgibbs uint64_aligned_t handle; /* OUT: the handle */ 380251767Sgibbs } nominate; 381251767Sgibbs struct mem_sharing_op_share { /* OP_SHARE/ADD_PHYSMAP */ 382251767Sgibbs uint64_aligned_t source_gfn; /* IN: the gfn of the source page */ 383251767Sgibbs uint64_aligned_t source_handle; /* IN: handle to the source page */ 384251767Sgibbs uint64_aligned_t client_gfn; /* IN: the client gfn */ 385251767Sgibbs uint64_aligned_t client_handle; /* IN: handle to the client page */ 386251767Sgibbs domid_t client_domain; /* IN: the client domain id */ 387251767Sgibbs } share; 388251767Sgibbs struct mem_sharing_op_debug { /* OP_DEBUG_xxx */ 389251767Sgibbs union { 390251767Sgibbs uint64_aligned_t gfn; /* IN: gfn to debug */ 391251767Sgibbs uint64_aligned_t mfn; /* IN: mfn to debug */ 392251767Sgibbs uint32_t gref; /* IN: gref to debug */ 393251767Sgibbs } u; 394251767Sgibbs } debug; 395251767Sgibbs } u; 396251767Sgibbs}; 397251767Sgibbstypedef struct xen_mem_sharing_op xen_mem_sharing_op_t; 398251767SgibbsDEFINE_XEN_GUEST_HANDLE(xen_mem_sharing_op_t); 399251767Sgibbs 400251767Sgibbs#endif /* defined(__XEN__) || defined(__XEN_TOOLS__) */ 401251767Sgibbs 402181624Skmacy#endif /* __XEN_PUBLIC_MEMORY_H__ */ 403181624Skmacy 404181624Skmacy/* 405181624Skmacy * Local variables: 406181624Skmacy * mode: C 407181624Skmacy * c-set-style: "BSD" 408181624Skmacy * c-basic-offset: 4 409181624Skmacy * tab-width: 4 410181624Skmacy * indent-tabs-mode: nil 411181624Skmacy * End: 412181624Skmacy */ 413