ia64/xen-unstable

annotate xen/include/public/memory.h @ 18394:dade7f0bdc8d

hvm: Use main memory for video memory.

When creating an HVM domain, if e.g. another domain is created before
qemu allocates video memory, the extra 8MB memory ballooning is not
available any more, because it got consumed by the other domain.

This fixes it by taking video memory from the main memory:

- make hvmloader use e820_malloc to reserve some of the main memory
and notify ioemu of its address through the Xen platform PCI card.
- add XENMAPSPACE_mfn to the xen_add_to_physmap memory op, to allow
ioemu to move the MFNs between the original position and the PCI
mapping, when LFB acceleration is disabled/enabled
- add a remove_from_physmap memory op, to allow ioemu to unmap it
completely for the case of old guests with acceleration disabled.
- add xc_domain_memory_translate_gpfn_list to libxc to allow ioemu to
get the MFNs of the video memory.
- have xend save the PCI memory space instead of ioemu: if a memory
page is there, the guest can access it like usual memory, so xend
can safely be responsible to save it. The extra benefit is that
live migration will apply the logdirty optimization there too.
- handle old saved images, populating the video memory from ioemu if
really needed.

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