1/* $NetBSD: memory.h,v 1.1.1.1 2011/12/07 13:15:45 cegger Exp $ */ 2/****************************************************************************** 3 * memory.h 4 * 5 * Memory reservation and information. 6 * 7 * Permission is hereby granted, free of charge, to any person obtaining a copy 8 * of this software and associated documentation files (the "Software"), to 9 * deal in the Software without restriction, including without limitation the 10 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 11 * sell copies of the Software, and to permit persons to whom the Software is 12 * furnished to do so, subject to the following conditions: 13 * 14 * The above copyright notice and this permission notice shall be included in 15 * all copies or substantial portions of the Software. 16 * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 * DEALINGS IN THE SOFTWARE. 24 * 25 * Copyright (c) 2005, Keir Fraser <keir@xensource.com> 26 */ 27 28#ifndef __XEN_PUBLIC_MEMORY_H__ 29#define __XEN_PUBLIC_MEMORY_H__ 30 31#include "xen.h" 32 33/* 34 * Increase or decrease the specified domain's memory reservation. Returns the 35 * number of extents successfully allocated or freed. 36 * arg == addr of struct xen_memory_reservation. 37 */ 38#define XENMEM_increase_reservation 0 39#define XENMEM_decrease_reservation 1 40#define XENMEM_populate_physmap 6 41 42#if __XEN_INTERFACE_VERSION__ >= 0x00030209 43/* 44 * Maximum # bits addressable by the user of the allocated region (e.g., I/O 45 * devices often have a 32-bit limitation even in 64-bit systems). If zero 46 * then the user has no addressing restriction. This field is not used by 47 * XENMEM_decrease_reservation. 48 */ 49#define XENMEMF_address_bits(x) (x) 50#define XENMEMF_get_address_bits(x) ((x) & 0xffu) 51/* NUMA node to allocate from. */ 52#define XENMEMF_node(x) (((x) + 1) << 8) 53#define XENMEMF_get_node(x) ((((x) >> 8) - 1) & 0xffu) 54/* Flag to populate physmap with populate-on-demand entries */ 55#define XENMEMF_populate_on_demand (1<<16) 56/* Flag to request allocation only from the node specified */ 57#define XENMEMF_exact_node_request (1<<17) 58#define XENMEMF_exact_node(n) (XENMEMF_node(n) | XENMEMF_exact_node_request) 59#endif 60 61struct xen_memory_reservation { 62 63 /* 64 * XENMEM_increase_reservation: 65 * OUT: MFN (*not* GMFN) bases of extents that were allocated 66 * XENMEM_decrease_reservation: 67 * IN: GMFN bases of extents to free 68 * XENMEM_populate_physmap: 69 * IN: GPFN bases of extents to populate with memory 70 * OUT: GMFN bases of extents that were allocated 71 * (NB. This command also updates the mach_to_phys translation table) 72 */ 73 XEN_GUEST_HANDLE(xen_pfn_t) extent_start; 74 75 /* Number of extents, and size/alignment of each (2^extent_order pages). */ 76 xen_ulong_t nr_extents; 77 unsigned int extent_order; 78 79#if __XEN_INTERFACE_VERSION__ >= 0x00030209 80 /* XENMEMF flags. */ 81 unsigned int mem_flags; 82#else 83 unsigned int address_bits; 84#endif 85 86 /* 87 * Domain whose reservation is being changed. 88 * Unprivileged domains can specify only DOMID_SELF. 89 */ 90 domid_t domid; 91}; 92typedef struct xen_memory_reservation xen_memory_reservation_t; 93DEFINE_XEN_GUEST_HANDLE(xen_memory_reservation_t); 94 95/* 96 * An atomic exchange of memory pages. If return code is zero then 97 * @out.extent_list provides GMFNs of the newly-allocated memory. 98 * Returns zero on complete success, otherwise a negative error code. 99 * On complete success then always @nr_exchanged == @in.nr_extents. 100 * On partial success @nr_exchanged indicates how much work was done. 101 */ 102#define XENMEM_exchange 11 103struct xen_memory_exchange { 104 /* 105 * [IN] Details of memory extents to be exchanged (GMFN bases). 106 * Note that @in.address_bits is ignored and unused. 107 */ 108 struct xen_memory_reservation in; 109 110 /* 111 * [IN/OUT] Details of new memory extents. 112 * We require that: 113 * 1. @in.domid == @out.domid 114 * 2. @in.nr_extents << @in.extent_order == 115 * @out.nr_extents << @out.extent_order 116 * 3. @in.extent_start and @out.extent_start lists must not overlap 117 * 4. @out.extent_start lists GPFN bases to be populated 118 * 5. @out.extent_start is overwritten with allocated GMFN bases 119 */ 120 struct xen_memory_reservation out; 121 122 /* 123 * [OUT] Number of input extents that were successfully exchanged: 124 * 1. The first @nr_exchanged input extents were successfully 125 * deallocated. 126 * 2. The corresponding first entries in the output extent list correctly 127 * indicate the GMFNs that were successfully exchanged. 128 * 3. All other input and output extents are untouched. 129 * 4. If not all input exents are exchanged then the return code of this 130 * command will be non-zero. 131 * 5. THIS FIELD MUST BE INITIALISED TO ZERO BY THE CALLER! 132 */ 133 xen_ulong_t nr_exchanged; 134}; 135typedef struct xen_memory_exchange xen_memory_exchange_t; 136DEFINE_XEN_GUEST_HANDLE(xen_memory_exchange_t); 137 138/* 139 * Returns the maximum machine frame number of mapped RAM in this system. 140 * This command always succeeds (it never returns an error code). 141 * arg == NULL. 142 */ 143#define XENMEM_maximum_ram_page 2 144 145/* 146 * Returns the current or maximum memory reservation, in pages, of the 147 * specified domain (may be DOMID_SELF). Returns -ve errcode on failure. 148 * arg == addr of domid_t. 149 */ 150#define XENMEM_current_reservation 3 151#define XENMEM_maximum_reservation 4 152 153/* 154 * Returns the maximum GPFN in use by the guest, or -ve errcode on failure. 155 */ 156#define XENMEM_maximum_gpfn 14 157 158/* 159 * Returns a list of MFN bases of 2MB extents comprising the machine_to_phys 160 * mapping table. Architectures which do not have a m2p table do not implement 161 * this command. 162 * arg == addr of xen_machphys_mfn_list_t. 163 */ 164#define XENMEM_machphys_mfn_list 5 165struct xen_machphys_mfn_list { 166 /* 167 * Size of the 'extent_start' array. Fewer entries will be filled if the 168 * machphys table is smaller than max_extents * 2MB. 169 */ 170 unsigned int max_extents; 171 172 /* 173 * Pointer to buffer to fill with list of extent starts. If there are 174 * any large discontiguities in the machine address space, 2MB gaps in 175 * the machphys table will be represented by an MFN base of zero. 176 */ 177 XEN_GUEST_HANDLE(xen_pfn_t) extent_start; 178 179 /* 180 * Number of extents written to the above array. This will be smaller 181 * than 'max_extents' if the machphys table is smaller than max_e * 2MB. 182 */ 183 unsigned int nr_extents; 184}; 185typedef struct xen_machphys_mfn_list xen_machphys_mfn_list_t; 186DEFINE_XEN_GUEST_HANDLE(xen_machphys_mfn_list_t); 187 188/* 189 * Returns the location in virtual address space of the machine_to_phys 190 * mapping table. Architectures which do not have a m2p table, or which do not 191 * map it by default into guest address space, do not implement this command. 192 * arg == addr of xen_machphys_mapping_t. 193 */ 194#define XENMEM_machphys_mapping 12 195struct xen_machphys_mapping { 196 xen_ulong_t v_start, v_end; /* Start and end virtual addresses. */ 197 xen_ulong_t max_mfn; /* Maximum MFN that can be looked up. */ 198}; 199typedef struct xen_machphys_mapping xen_machphys_mapping_t; 200DEFINE_XEN_GUEST_HANDLE(xen_machphys_mapping_t); 201 202/* 203 * Sets the GPFN at which a particular page appears in the specified guest's 204 * pseudophysical address space. 205 * arg == addr of xen_add_to_physmap_t. 206 */ 207#define XENMEM_add_to_physmap 7 208struct xen_add_to_physmap { 209 /* Which domain to change the mapping for. */ 210 domid_t domid; 211 212 /* Source mapping space. */ 213#define XENMAPSPACE_shared_info 0 /* shared info page */ 214#define XENMAPSPACE_grant_table 1 /* grant table page */ 215#define XENMAPSPACE_gmfn 2 /* GMFN */ 216 unsigned int space; 217 218#define XENMAPIDX_grant_table_status 0x80000000 219 220 /* Index into source mapping space. */ 221 xen_ulong_t idx; 222 223 /* GPFN where the source mapping page should appear. */ 224 xen_pfn_t gpfn; 225}; 226typedef struct xen_add_to_physmap xen_add_to_physmap_t; 227DEFINE_XEN_GUEST_HANDLE(xen_add_to_physmap_t); 228 229/*** REMOVED ***/ 230/*#define XENMEM_translate_gpfn_list 8*/ 231 232/* 233 * Returns the pseudo-physical memory map as it was when the domain 234 * was started (specified by XENMEM_set_memory_map). 235 * arg == addr of xen_memory_map_t. 236 */ 237#define XENMEM_memory_map 9 238struct xen_memory_map { 239 /* 240 * On call the number of entries which can be stored in buffer. On 241 * return the number of entries which have been stored in 242 * buffer. 243 */ 244 unsigned int nr_entries; 245 246 /* 247 * Entries in the buffer are in the same format as returned by the 248 * BIOS INT 0x15 EAX=0xE820 call. 249 */ 250 XEN_GUEST_HANDLE(void) buffer; 251}; 252typedef struct xen_memory_map xen_memory_map_t; 253DEFINE_XEN_GUEST_HANDLE(xen_memory_map_t); 254 255/* 256 * Returns the real physical memory map. Passes the same structure as 257 * XENMEM_memory_map. 258 * arg == addr of xen_memory_map_t. 259 */ 260#define XENMEM_machine_memory_map 10 261 262/* 263 * Set the pseudo-physical memory map of a domain, as returned by 264 * XENMEM_memory_map. 265 * arg == addr of xen_foreign_memory_map_t. 266 */ 267#define XENMEM_set_memory_map 13 268struct xen_foreign_memory_map { 269 domid_t domid; 270 struct xen_memory_map map; 271}; 272typedef struct xen_foreign_memory_map xen_foreign_memory_map_t; 273DEFINE_XEN_GUEST_HANDLE(xen_foreign_memory_map_t); 274 275#define XENMEM_set_pod_target 16 276#define XENMEM_get_pod_target 17 277struct xen_pod_target { 278 /* IN */ 279 uint64_t target_pages; 280 /* OUT */ 281 uint64_t tot_pages; 282 uint64_t pod_cache_pages; 283 uint64_t pod_entries; 284 /* IN */ 285 domid_t domid; 286}; 287typedef struct xen_pod_target xen_pod_target_t; 288 289/* 290 * Get the number of MFNs saved through memory sharing. 291 * The call never fails. 292 */ 293#define XENMEM_get_sharing_freed_pages 18 294 295#endif /* __XEN_PUBLIC_MEMORY_H__ */ 296 297/* 298 * Local variables: 299 * mode: C 300 * c-set-style: "BSD" 301 * c-basic-offset: 4 302 * tab-width: 4 303 * indent-tabs-mode: nil 304 * End: 305 */ 306