1a42089ddSJeremy Fitzhardinge /****************************************************************************** 2a42089ddSJeremy Fitzhardinge * memory.h 3a42089ddSJeremy Fitzhardinge * 4a42089ddSJeremy Fitzhardinge * Memory reservation and information. 5a42089ddSJeremy Fitzhardinge * 6a42089ddSJeremy Fitzhardinge * Copyright (c) 2005, Keir Fraser <keir@xensource.com> 7a42089ddSJeremy Fitzhardinge */ 8a42089ddSJeremy Fitzhardinge 9a42089ddSJeremy Fitzhardinge #ifndef __XEN_PUBLIC_MEMORY_H__ 10a42089ddSJeremy Fitzhardinge #define __XEN_PUBLIC_MEMORY_H__ 11a42089ddSJeremy Fitzhardinge 1219001c8cSAlex Nixon #include <linux/spinlock.h> 1319001c8cSAlex Nixon 14a42089ddSJeremy Fitzhardinge /* 15a42089ddSJeremy Fitzhardinge * Increase or decrease the specified domain's memory reservation. Returns a 16a42089ddSJeremy Fitzhardinge * -ve errcode on failure, or the # extents successfully allocated or freed. 17a42089ddSJeremy Fitzhardinge * arg == addr of struct xen_memory_reservation. 18a42089ddSJeremy Fitzhardinge */ 19a42089ddSJeremy Fitzhardinge #define XENMEM_increase_reservation 0 20a42089ddSJeremy Fitzhardinge #define XENMEM_decrease_reservation 1 21a42089ddSJeremy Fitzhardinge #define XENMEM_populate_physmap 6 22a42089ddSJeremy Fitzhardinge struct xen_memory_reservation { 23a42089ddSJeremy Fitzhardinge 24a42089ddSJeremy Fitzhardinge /* 25a42089ddSJeremy Fitzhardinge * XENMEM_increase_reservation: 26a42089ddSJeremy Fitzhardinge * OUT: MFN (*not* GMFN) bases of extents that were allocated 27a42089ddSJeremy Fitzhardinge * XENMEM_decrease_reservation: 28a42089ddSJeremy Fitzhardinge * IN: GMFN bases of extents to free 29a42089ddSJeremy Fitzhardinge * XENMEM_populate_physmap: 30a42089ddSJeremy Fitzhardinge * IN: GPFN bases of extents to populate with memory 31a42089ddSJeremy Fitzhardinge * OUT: GMFN bases of extents that were allocated 32a42089ddSJeremy Fitzhardinge * (NB. This command also updates the mach_to_phys translation table) 33a42089ddSJeremy Fitzhardinge */ 34bfdab126SIsaku Yamahata GUEST_HANDLE(ulong) extent_start; 35a42089ddSJeremy Fitzhardinge 36a42089ddSJeremy Fitzhardinge /* Number of extents, and size/alignment of each (2^extent_order pages). */ 37a42089ddSJeremy Fitzhardinge unsigned long nr_extents; 38a42089ddSJeremy Fitzhardinge unsigned int extent_order; 39a42089ddSJeremy Fitzhardinge 40a42089ddSJeremy Fitzhardinge /* 41a42089ddSJeremy Fitzhardinge * Maximum # bits addressable by the user of the allocated region (e.g., 42a42089ddSJeremy Fitzhardinge * I/O devices often have a 32-bit limitation even in 64-bit systems). If 43a42089ddSJeremy Fitzhardinge * zero then the user has no addressing restriction. 44a42089ddSJeremy Fitzhardinge * This field is not used by XENMEM_decrease_reservation. 45a42089ddSJeremy Fitzhardinge */ 46a42089ddSJeremy Fitzhardinge unsigned int address_bits; 47a42089ddSJeremy Fitzhardinge 48a42089ddSJeremy Fitzhardinge /* 49a42089ddSJeremy Fitzhardinge * Domain whose reservation is being changed. 50a42089ddSJeremy Fitzhardinge * Unprivileged domains can specify only DOMID_SELF. 51a42089ddSJeremy Fitzhardinge */ 52a42089ddSJeremy Fitzhardinge domid_t domid; 53a42089ddSJeremy Fitzhardinge 54a42089ddSJeremy Fitzhardinge }; 55bfdab126SIsaku Yamahata DEFINE_GUEST_HANDLE_STRUCT(xen_memory_reservation); 56a42089ddSJeremy Fitzhardinge 57a42089ddSJeremy Fitzhardinge /* 58*08bbc9daSAlex Nixon * An atomic exchange of memory pages. If return code is zero then 59*08bbc9daSAlex Nixon * @out.extent_list provides GMFNs of the newly-allocated memory. 60*08bbc9daSAlex Nixon * Returns zero on complete success, otherwise a negative error code. 61*08bbc9daSAlex Nixon * On complete success then always @nr_exchanged == @in.nr_extents. 62*08bbc9daSAlex Nixon * On partial success @nr_exchanged indicates how much work was done. 63*08bbc9daSAlex Nixon */ 64*08bbc9daSAlex Nixon #define XENMEM_exchange 11 65*08bbc9daSAlex Nixon struct xen_memory_exchange { 66*08bbc9daSAlex Nixon /* 67*08bbc9daSAlex Nixon * [IN] Details of memory extents to be exchanged (GMFN bases). 68*08bbc9daSAlex Nixon * Note that @in.address_bits is ignored and unused. 69*08bbc9daSAlex Nixon */ 70*08bbc9daSAlex Nixon struct xen_memory_reservation in; 71*08bbc9daSAlex Nixon 72*08bbc9daSAlex Nixon /* 73*08bbc9daSAlex Nixon * [IN/OUT] Details of new memory extents. 74*08bbc9daSAlex Nixon * We require that: 75*08bbc9daSAlex Nixon * 1. @in.domid == @out.domid 76*08bbc9daSAlex Nixon * 2. @in.nr_extents << @in.extent_order == 77*08bbc9daSAlex Nixon * @out.nr_extents << @out.extent_order 78*08bbc9daSAlex Nixon * 3. @in.extent_start and @out.extent_start lists must not overlap 79*08bbc9daSAlex Nixon * 4. @out.extent_start lists GPFN bases to be populated 80*08bbc9daSAlex Nixon * 5. @out.extent_start is overwritten with allocated GMFN bases 81*08bbc9daSAlex Nixon */ 82*08bbc9daSAlex Nixon struct xen_memory_reservation out; 83*08bbc9daSAlex Nixon 84*08bbc9daSAlex Nixon /* 85*08bbc9daSAlex Nixon * [OUT] Number of input extents that were successfully exchanged: 86*08bbc9daSAlex Nixon * 1. The first @nr_exchanged input extents were successfully 87*08bbc9daSAlex Nixon * deallocated. 88*08bbc9daSAlex Nixon * 2. The corresponding first entries in the output extent list correctly 89*08bbc9daSAlex Nixon * indicate the GMFNs that were successfully exchanged. 90*08bbc9daSAlex Nixon * 3. All other input and output extents are untouched. 91*08bbc9daSAlex Nixon * 4. If not all input exents are exchanged then the return code of this 92*08bbc9daSAlex Nixon * command will be non-zero. 93*08bbc9daSAlex Nixon * 5. THIS FIELD MUST BE INITIALISED TO ZERO BY THE CALLER! 94*08bbc9daSAlex Nixon */ 95*08bbc9daSAlex Nixon unsigned long nr_exchanged; 96*08bbc9daSAlex Nixon }; 97*08bbc9daSAlex Nixon 98*08bbc9daSAlex Nixon DEFINE_GUEST_HANDLE_STRUCT(xen_memory_exchange); 99*08bbc9daSAlex Nixon /* 100a42089ddSJeremy Fitzhardinge * Returns the maximum machine frame number of mapped RAM in this system. 101a42089ddSJeremy Fitzhardinge * This command always succeeds (it never returns an error code). 102a42089ddSJeremy Fitzhardinge * arg == NULL. 103a42089ddSJeremy Fitzhardinge */ 104a42089ddSJeremy Fitzhardinge #define XENMEM_maximum_ram_page 2 105a42089ddSJeremy Fitzhardinge 106a42089ddSJeremy Fitzhardinge /* 107a42089ddSJeremy Fitzhardinge * Returns the current or maximum memory reservation, in pages, of the 108a42089ddSJeremy Fitzhardinge * specified domain (may be DOMID_SELF). Returns -ve errcode on failure. 109a42089ddSJeremy Fitzhardinge * arg == addr of domid_t. 110a42089ddSJeremy Fitzhardinge */ 111a42089ddSJeremy Fitzhardinge #define XENMEM_current_reservation 3 112a42089ddSJeremy Fitzhardinge #define XENMEM_maximum_reservation 4 113a42089ddSJeremy Fitzhardinge 114a42089ddSJeremy Fitzhardinge /* 115a42089ddSJeremy Fitzhardinge * Returns a list of MFN bases of 2MB extents comprising the machine_to_phys 116a42089ddSJeremy Fitzhardinge * mapping table. Architectures which do not have a m2p table do not implement 117a42089ddSJeremy Fitzhardinge * this command. 118a42089ddSJeremy Fitzhardinge * arg == addr of xen_machphys_mfn_list_t. 119a42089ddSJeremy Fitzhardinge */ 120a42089ddSJeremy Fitzhardinge #define XENMEM_machphys_mfn_list 5 121a42089ddSJeremy Fitzhardinge struct xen_machphys_mfn_list { 122a42089ddSJeremy Fitzhardinge /* 123a42089ddSJeremy Fitzhardinge * Size of the 'extent_start' array. Fewer entries will be filled if the 124a42089ddSJeremy Fitzhardinge * machphys table is smaller than max_extents * 2MB. 125a42089ddSJeremy Fitzhardinge */ 126a42089ddSJeremy Fitzhardinge unsigned int max_extents; 127a42089ddSJeremy Fitzhardinge 128a42089ddSJeremy Fitzhardinge /* 129a42089ddSJeremy Fitzhardinge * Pointer to buffer to fill with list of extent starts. If there are 130a42089ddSJeremy Fitzhardinge * any large discontiguities in the machine address space, 2MB gaps in 131a42089ddSJeremy Fitzhardinge * the machphys table will be represented by an MFN base of zero. 132a42089ddSJeremy Fitzhardinge */ 133bfdab126SIsaku Yamahata GUEST_HANDLE(ulong) extent_start; 134a42089ddSJeremy Fitzhardinge 135a42089ddSJeremy Fitzhardinge /* 136a42089ddSJeremy Fitzhardinge * Number of extents written to the above array. This will be smaller 137a42089ddSJeremy Fitzhardinge * than 'max_extents' if the machphys table is smaller than max_e * 2MB. 138a42089ddSJeremy Fitzhardinge */ 139a42089ddSJeremy Fitzhardinge unsigned int nr_extents; 140a42089ddSJeremy Fitzhardinge }; 141bfdab126SIsaku Yamahata DEFINE_GUEST_HANDLE_STRUCT(xen_machphys_mfn_list); 142a42089ddSJeremy Fitzhardinge 143a42089ddSJeremy Fitzhardinge /* 144a42089ddSJeremy Fitzhardinge * Sets the GPFN at which a particular page appears in the specified guest's 145a42089ddSJeremy Fitzhardinge * pseudophysical address space. 146a42089ddSJeremy Fitzhardinge * arg == addr of xen_add_to_physmap_t. 147a42089ddSJeremy Fitzhardinge */ 148a42089ddSJeremy Fitzhardinge #define XENMEM_add_to_physmap 7 149a42089ddSJeremy Fitzhardinge struct xen_add_to_physmap { 150a42089ddSJeremy Fitzhardinge /* Which domain to change the mapping for. */ 151a42089ddSJeremy Fitzhardinge domid_t domid; 152a42089ddSJeremy Fitzhardinge 153a42089ddSJeremy Fitzhardinge /* Source mapping space. */ 154a42089ddSJeremy Fitzhardinge #define XENMAPSPACE_shared_info 0 /* shared info page */ 155a42089ddSJeremy Fitzhardinge #define XENMAPSPACE_grant_table 1 /* grant table page */ 156a42089ddSJeremy Fitzhardinge unsigned int space; 157a42089ddSJeremy Fitzhardinge 158a42089ddSJeremy Fitzhardinge /* Index into source mapping space. */ 159a42089ddSJeremy Fitzhardinge unsigned long idx; 160a42089ddSJeremy Fitzhardinge 161a42089ddSJeremy Fitzhardinge /* GPFN where the source mapping page should appear. */ 162a42089ddSJeremy Fitzhardinge unsigned long gpfn; 163a42089ddSJeremy Fitzhardinge }; 164bfdab126SIsaku Yamahata DEFINE_GUEST_HANDLE_STRUCT(xen_add_to_physmap); 165a42089ddSJeremy Fitzhardinge 166a42089ddSJeremy Fitzhardinge /* 167a42089ddSJeremy Fitzhardinge * Translates a list of domain-specific GPFNs into MFNs. Returns a -ve error 168a42089ddSJeremy Fitzhardinge * code on failure. This call only works for auto-translated guests. 169a42089ddSJeremy Fitzhardinge */ 170a42089ddSJeremy Fitzhardinge #define XENMEM_translate_gpfn_list 8 171a42089ddSJeremy Fitzhardinge struct xen_translate_gpfn_list { 172a42089ddSJeremy Fitzhardinge /* Which domain to translate for? */ 173a42089ddSJeremy Fitzhardinge domid_t domid; 174a42089ddSJeremy Fitzhardinge 175a42089ddSJeremy Fitzhardinge /* Length of list. */ 176a42089ddSJeremy Fitzhardinge unsigned long nr_gpfns; 177a42089ddSJeremy Fitzhardinge 178a42089ddSJeremy Fitzhardinge /* List of GPFNs to translate. */ 179bfdab126SIsaku Yamahata GUEST_HANDLE(ulong) gpfn_list; 180a42089ddSJeremy Fitzhardinge 181a42089ddSJeremy Fitzhardinge /* 182a42089ddSJeremy Fitzhardinge * Output list to contain MFN translations. May be the same as the input 183a42089ddSJeremy Fitzhardinge * list (in which case each input GPFN is overwritten with the output MFN). 184a42089ddSJeremy Fitzhardinge */ 185bfdab126SIsaku Yamahata GUEST_HANDLE(ulong) mfn_list; 186a42089ddSJeremy Fitzhardinge }; 187bfdab126SIsaku Yamahata DEFINE_GUEST_HANDLE_STRUCT(xen_translate_gpfn_list); 188a42089ddSJeremy Fitzhardinge 18919001c8cSAlex Nixon 19019001c8cSAlex Nixon /* 19119001c8cSAlex Nixon * Prevent the balloon driver from changing the memory reservation 19219001c8cSAlex Nixon * during a driver critical region. 19319001c8cSAlex Nixon */ 19419001c8cSAlex Nixon extern spinlock_t xen_reservation_lock; 195a42089ddSJeremy Fitzhardinge #endif /* __XEN_PUBLIC_MEMORY_H__ */ 196