15084Sjohnlev /****************************************************************************** 25084Sjohnlev * memory.h 35084Sjohnlev * 45084Sjohnlev * Memory reservation and information. 55084Sjohnlev * 65084Sjohnlev * Permission is hereby granted, free of charge, to any person obtaining a copy 75084Sjohnlev * of this software and associated documentation files (the "Software"), to 85084Sjohnlev * deal in the Software without restriction, including without limitation the 95084Sjohnlev * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 105084Sjohnlev * sell copies of the Software, and to permit persons to whom the Software is 115084Sjohnlev * furnished to do so, subject to the following conditions: 125084Sjohnlev * 135084Sjohnlev * The above copyright notice and this permission notice shall be included in 145084Sjohnlev * all copies or substantial portions of the Software. 155084Sjohnlev * 165084Sjohnlev * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 175084Sjohnlev * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 185084Sjohnlev * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 195084Sjohnlev * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 205084Sjohnlev * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 215084Sjohnlev * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 225084Sjohnlev * DEALINGS IN THE SOFTWARE. 235084Sjohnlev * 245084Sjohnlev * Copyright (c) 2005, Keir Fraser <keir@xensource.com> 255084Sjohnlev */ 265084Sjohnlev 275084Sjohnlev #ifndef __XEN_PUBLIC_MEMORY_H__ 285084Sjohnlev #define __XEN_PUBLIC_MEMORY_H__ 295084Sjohnlev 305084Sjohnlev /* 315084Sjohnlev * Increase or decrease the specified domain's memory reservation. Returns the 325084Sjohnlev * number of extents successfully allocated or freed. 335084Sjohnlev * arg == addr of struct xen_memory_reservation. 345084Sjohnlev */ 355084Sjohnlev #define XENMEM_increase_reservation 0 365084Sjohnlev #define XENMEM_decrease_reservation 1 375084Sjohnlev #define XENMEM_populate_physmap 6 3810175SStuart.Maybee@Sun.COM 3910175SStuart.Maybee@Sun.COM #if __XEN_INTERFACE_VERSION__ >= 0x00030209 4010175SStuart.Maybee@Sun.COM /* 4110175SStuart.Maybee@Sun.COM * Maximum # bits addressable by the user of the allocated region (e.g., I/O 4210175SStuart.Maybee@Sun.COM * devices often have a 32-bit limitation even in 64-bit systems). If zero 4310175SStuart.Maybee@Sun.COM * then the user has no addressing restriction. This field is not used by 4410175SStuart.Maybee@Sun.COM * XENMEM_decrease_reservation. 4510175SStuart.Maybee@Sun.COM */ 4610175SStuart.Maybee@Sun.COM #define XENMEMF_address_bits(x) (x) 4710175SStuart.Maybee@Sun.COM #define XENMEMF_get_address_bits(x) ((x) & 0xffu) 4810175SStuart.Maybee@Sun.COM /* NUMA node to allocate from. */ 4910175SStuart.Maybee@Sun.COM #define XENMEMF_node(x) (((x) + 1) << 8) 5010175SStuart.Maybee@Sun.COM #define XENMEMF_get_node(x) ((((x) >> 8) - 1) & 0xffu) 51*11120SMark.Johnson@Sun.COM /* Flag to populate physmap with populate-on-demand entries */ 52*11120SMark.Johnson@Sun.COM #define XENMEMF_populate_on_demand (1<<16) 5310175SStuart.Maybee@Sun.COM #endif 5410175SStuart.Maybee@Sun.COM 555084Sjohnlev struct xen_memory_reservation { 565084Sjohnlev 575084Sjohnlev /* 585084Sjohnlev * XENMEM_increase_reservation: 595084Sjohnlev * OUT: MFN (*not* GMFN) bases of extents that were allocated 605084Sjohnlev * XENMEM_decrease_reservation: 615084Sjohnlev * IN: GMFN bases of extents to free 625084Sjohnlev * XENMEM_populate_physmap: 635084Sjohnlev * IN: GPFN bases of extents to populate with memory 645084Sjohnlev * OUT: GMFN bases of extents that were allocated 655084Sjohnlev * (NB. This command also updates the mach_to_phys translation table) 665084Sjohnlev */ 675084Sjohnlev XEN_GUEST_HANDLE(xen_pfn_t) extent_start; 685084Sjohnlev 695084Sjohnlev /* Number of extents, and size/alignment of each (2^extent_order pages). */ 705084Sjohnlev xen_ulong_t nr_extents; 715084Sjohnlev unsigned int extent_order; 725084Sjohnlev 7310175SStuart.Maybee@Sun.COM #if __XEN_INTERFACE_VERSION__ >= 0x00030209 7410175SStuart.Maybee@Sun.COM /* XENMEMF flags. */ 7510175SStuart.Maybee@Sun.COM unsigned int mem_flags; 7610175SStuart.Maybee@Sun.COM #else 775084Sjohnlev unsigned int address_bits; 7810175SStuart.Maybee@Sun.COM #endif 795084Sjohnlev 805084Sjohnlev /* 815084Sjohnlev * Domain whose reservation is being changed. 825084Sjohnlev * Unprivileged domains can specify only DOMID_SELF. 835084Sjohnlev */ 845084Sjohnlev domid_t domid; 855084Sjohnlev }; 865084Sjohnlev typedef struct xen_memory_reservation xen_memory_reservation_t; 875084Sjohnlev DEFINE_XEN_GUEST_HANDLE(xen_memory_reservation_t); 885084Sjohnlev 895084Sjohnlev /* 905084Sjohnlev * An atomic exchange of memory pages. If return code is zero then 915084Sjohnlev * @out.extent_list provides GMFNs of the newly-allocated memory. 925084Sjohnlev * Returns zero on complete success, otherwise a negative error code. 935084Sjohnlev * On complete success then always @nr_exchanged == @in.nr_extents. 945084Sjohnlev * On partial success @nr_exchanged indicates how much work was done. 955084Sjohnlev */ 965084Sjohnlev #define XENMEM_exchange 11 975084Sjohnlev struct xen_memory_exchange { 985084Sjohnlev /* 995084Sjohnlev * [IN] Details of memory extents to be exchanged (GMFN bases). 1005084Sjohnlev * Note that @in.address_bits is ignored and unused. 1015084Sjohnlev */ 1025084Sjohnlev struct xen_memory_reservation in; 1035084Sjohnlev 1045084Sjohnlev /* 1055084Sjohnlev * [IN/OUT] Details of new memory extents. 1065084Sjohnlev * We require that: 1075084Sjohnlev * 1. @in.domid == @out.domid 1085084Sjohnlev * 2. @in.nr_extents << @in.extent_order == 1095084Sjohnlev * @out.nr_extents << @out.extent_order 1105084Sjohnlev * 3. @in.extent_start and @out.extent_start lists must not overlap 1115084Sjohnlev * 4. @out.extent_start lists GPFN bases to be populated 1125084Sjohnlev * 5. @out.extent_start is overwritten with allocated GMFN bases 1135084Sjohnlev */ 1145084Sjohnlev struct xen_memory_reservation out; 1155084Sjohnlev 1165084Sjohnlev /* 1175084Sjohnlev * [OUT] Number of input extents that were successfully exchanged: 1185084Sjohnlev * 1. The first @nr_exchanged input extents were successfully 1195084Sjohnlev * deallocated. 1205084Sjohnlev * 2. The corresponding first entries in the output extent list correctly 1215084Sjohnlev * indicate the GMFNs that were successfully exchanged. 1225084Sjohnlev * 3. All other input and output extents are untouched. 1235084Sjohnlev * 4. If not all input exents are exchanged then the return code of this 1245084Sjohnlev * command will be non-zero. 1255084Sjohnlev * 5. THIS FIELD MUST BE INITIALISED TO ZERO BY THE CALLER! 1265084Sjohnlev */ 1275084Sjohnlev xen_ulong_t nr_exchanged; 1285084Sjohnlev }; 1295084Sjohnlev typedef struct xen_memory_exchange xen_memory_exchange_t; 1305084Sjohnlev DEFINE_XEN_GUEST_HANDLE(xen_memory_exchange_t); 1315084Sjohnlev 1325084Sjohnlev /* 1335084Sjohnlev * Returns the maximum machine frame number of mapped RAM in this system. 1345084Sjohnlev * This command always succeeds (it never returns an error code). 1355084Sjohnlev * arg == NULL. 1365084Sjohnlev */ 1375084Sjohnlev #define XENMEM_maximum_ram_page 2 1385084Sjohnlev 1395084Sjohnlev /* 1405084Sjohnlev * Returns the current or maximum memory reservation, in pages, of the 1415084Sjohnlev * specified domain (may be DOMID_SELF). Returns -ve errcode on failure. 1425084Sjohnlev * arg == addr of domid_t. 1435084Sjohnlev */ 1445084Sjohnlev #define XENMEM_current_reservation 3 1455084Sjohnlev #define XENMEM_maximum_reservation 4 1465084Sjohnlev 1475084Sjohnlev /* 1486144Srab * Returns the maximum GPFN in use by the guest, or -ve errcode on failure. 1496144Srab */ 1506144Srab #define XENMEM_maximum_gpfn 14 1516144Srab 1526144Srab /* 1535084Sjohnlev * Returns a list of MFN bases of 2MB extents comprising the machine_to_phys 1545084Sjohnlev * mapping table. Architectures which do not have a m2p table do not implement 1555084Sjohnlev * this command. 1565084Sjohnlev * arg == addr of xen_machphys_mfn_list_t. 1575084Sjohnlev */ 1585084Sjohnlev #define XENMEM_machphys_mfn_list 5 1595084Sjohnlev struct xen_machphys_mfn_list { 1605084Sjohnlev /* 1615084Sjohnlev * Size of the 'extent_start' array. Fewer entries will be filled if the 1625084Sjohnlev * machphys table is smaller than max_extents * 2MB. 1635084Sjohnlev */ 1645084Sjohnlev unsigned int max_extents; 1655084Sjohnlev 1665084Sjohnlev /* 1675084Sjohnlev * Pointer to buffer to fill with list of extent starts. If there are 1685084Sjohnlev * any large discontiguities in the machine address space, 2MB gaps in 1695084Sjohnlev * the machphys table will be represented by an MFN base of zero. 1705084Sjohnlev */ 1715084Sjohnlev XEN_GUEST_HANDLE(xen_pfn_t) extent_start; 1725084Sjohnlev 1735084Sjohnlev /* 1745084Sjohnlev * Number of extents written to the above array. This will be smaller 1755084Sjohnlev * than 'max_extents' if the machphys table is smaller than max_e * 2MB. 1765084Sjohnlev */ 1775084Sjohnlev unsigned int nr_extents; 1785084Sjohnlev }; 1795084Sjohnlev typedef struct xen_machphys_mfn_list xen_machphys_mfn_list_t; 1805084Sjohnlev DEFINE_XEN_GUEST_HANDLE(xen_machphys_mfn_list_t); 1815084Sjohnlev 1825084Sjohnlev /* 1835084Sjohnlev * Returns the location in virtual address space of the machine_to_phys 1845084Sjohnlev * mapping table. Architectures which do not have a m2p table, or which do not 1855084Sjohnlev * map it by default into guest address space, do not implement this command. 1865084Sjohnlev * arg == addr of xen_machphys_mapping_t. 1875084Sjohnlev */ 1885084Sjohnlev #define XENMEM_machphys_mapping 12 1895084Sjohnlev struct xen_machphys_mapping { 1905084Sjohnlev xen_ulong_t v_start, v_end; /* Start and end virtual addresses. */ 1915084Sjohnlev xen_ulong_t max_mfn; /* Maximum MFN that can be looked up. */ 1925084Sjohnlev }; 1935084Sjohnlev typedef struct xen_machphys_mapping xen_machphys_mapping_t; 1945084Sjohnlev DEFINE_XEN_GUEST_HANDLE(xen_machphys_mapping_t); 1955084Sjohnlev 1965084Sjohnlev /* 1975084Sjohnlev * Sets the GPFN at which a particular page appears in the specified guest's 1985084Sjohnlev * pseudophysical address space. 1995084Sjohnlev * arg == addr of xen_add_to_physmap_t. 2005084Sjohnlev */ 2015084Sjohnlev #define XENMEM_add_to_physmap 7 2025084Sjohnlev struct xen_add_to_physmap { 2035084Sjohnlev /* Which domain to change the mapping for. */ 2045084Sjohnlev domid_t domid; 2055084Sjohnlev 2065084Sjohnlev /* Source mapping space. */ 2075084Sjohnlev #define XENMAPSPACE_shared_info 0 /* shared info page */ 2085084Sjohnlev #define XENMAPSPACE_grant_table 1 /* grant table page */ 209*11120SMark.Johnson@Sun.COM #define XENMAPSPACE_gmfn 2 /* GMFN */ 2105084Sjohnlev unsigned int space; 2115084Sjohnlev 2125084Sjohnlev /* Index into source mapping space. */ 2135084Sjohnlev xen_ulong_t idx; 2145084Sjohnlev 2155084Sjohnlev /* GPFN where the source mapping page should appear. */ 2165084Sjohnlev xen_pfn_t gpfn; 2175084Sjohnlev }; 2185084Sjohnlev typedef struct xen_add_to_physmap xen_add_to_physmap_t; 2195084Sjohnlev DEFINE_XEN_GUEST_HANDLE(xen_add_to_physmap_t); 2205084Sjohnlev 221*11120SMark.Johnson@Sun.COM /*** REMOVED ***/ 222*11120SMark.Johnson@Sun.COM /*#define XENMEM_translate_gpfn_list 8*/ 2235084Sjohnlev 2245084Sjohnlev /* 2255084Sjohnlev * Returns the pseudo-physical memory map as it was when the domain 2265084Sjohnlev * was started (specified by XENMEM_set_memory_map). 2275084Sjohnlev * arg == addr of xen_memory_map_t. 2285084Sjohnlev */ 2295084Sjohnlev #define XENMEM_memory_map 9 2305084Sjohnlev struct xen_memory_map { 2315084Sjohnlev /* 2325084Sjohnlev * On call the number of entries which can be stored in buffer. On 2335084Sjohnlev * return the number of entries which have been stored in 2345084Sjohnlev * buffer. 2355084Sjohnlev */ 2365084Sjohnlev unsigned int nr_entries; 2375084Sjohnlev 2385084Sjohnlev /* 2395084Sjohnlev * Entries in the buffer are in the same format as returned by the 2405084Sjohnlev * BIOS INT 0x15 EAX=0xE820 call. 2415084Sjohnlev */ 2425084Sjohnlev XEN_GUEST_HANDLE(void) buffer; 2435084Sjohnlev }; 2445084Sjohnlev typedef struct xen_memory_map xen_memory_map_t; 2455084Sjohnlev DEFINE_XEN_GUEST_HANDLE(xen_memory_map_t); 2465084Sjohnlev 2475084Sjohnlev /* 2485084Sjohnlev * Returns the real physical memory map. Passes the same structure as 2495084Sjohnlev * XENMEM_memory_map. 2505084Sjohnlev * arg == addr of xen_memory_map_t. 2515084Sjohnlev */ 2525084Sjohnlev #define XENMEM_machine_memory_map 10 2535084Sjohnlev 2545084Sjohnlev /* 2555084Sjohnlev * Set the pseudo-physical memory map of a domain, as returned by 2565084Sjohnlev * XENMEM_memory_map. 2575084Sjohnlev * arg == addr of xen_foreign_memory_map_t. 2585084Sjohnlev */ 2595084Sjohnlev #define XENMEM_set_memory_map 13 2605084Sjohnlev struct xen_foreign_memory_map { 2615084Sjohnlev domid_t domid; 2625084Sjohnlev struct xen_memory_map map; 2635084Sjohnlev }; 2645084Sjohnlev typedef struct xen_foreign_memory_map xen_foreign_memory_map_t; 2655084Sjohnlev DEFINE_XEN_GUEST_HANDLE(xen_foreign_memory_map_t); 2665084Sjohnlev 267*11120SMark.Johnson@Sun.COM #define XENMEM_set_pod_target 16 268*11120SMark.Johnson@Sun.COM #define XENMEM_get_pod_target 17 269*11120SMark.Johnson@Sun.COM struct xen_pod_target { 270*11120SMark.Johnson@Sun.COM /* IN */ 271*11120SMark.Johnson@Sun.COM uint64_t target_pages; 272*11120SMark.Johnson@Sun.COM /* OUT */ 273*11120SMark.Johnson@Sun.COM uint64_t tot_pages; 274*11120SMark.Johnson@Sun.COM uint64_t pod_cache_pages; 275*11120SMark.Johnson@Sun.COM uint64_t pod_entries; 276*11120SMark.Johnson@Sun.COM /* IN */ 277*11120SMark.Johnson@Sun.COM domid_t domid; 278*11120SMark.Johnson@Sun.COM }; 279*11120SMark.Johnson@Sun.COM typedef struct xen_pod_target xen_pod_target_t; 2805084Sjohnlev #endif /* __XEN_PUBLIC_MEMORY_H__ */ 2815084Sjohnlev 2825084Sjohnlev /* 2835084Sjohnlev * Local variables: 2845084Sjohnlev * mode: C 2855084Sjohnlev * c-set-style: "BSD" 2865084Sjohnlev * c-basic-offset: 4 2875084Sjohnlev * tab-width: 4 2885084Sjohnlev * indent-tabs-mode: nil 2895084Sjohnlev * End: 2905084Sjohnlev */ 291