memory.h revision 183375
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
30181624Skmacy/*
31181624Skmacy * Increase or decrease the specified domain's memory reservation. Returns the
32181624Skmacy * number of extents successfully allocated or freed.
33181624Skmacy * arg == addr of struct xen_memory_reservation.
34181624Skmacy */
35181624Skmacy#define XENMEM_increase_reservation 0
36181624Skmacy#define XENMEM_decrease_reservation 1
37181624Skmacy#define XENMEM_populate_physmap     6
38183375Skmacy
39183375Skmacy#if __XEN_INTERFACE_VERSION__ >= 0x00030209
40183375Skmacy/*
41183375Skmacy * Maximum # bits addressable by the user of the allocated region (e.g., I/O
42183375Skmacy * devices often have a 32-bit limitation even in 64-bit systems). If zero
43183375Skmacy * then the user has no addressing restriction. This field is not used by
44183375Skmacy * XENMEM_decrease_reservation.
45183375Skmacy */
46183375Skmacy#define XENMEMF_address_bits(x)     (x)
47183375Skmacy#define XENMEMF_get_address_bits(x) ((x) & 0xffu)
48183375Skmacy/* NUMA node to allocate from. */
49183375Skmacy#define XENMEMF_node(x)     (((x) + 1) << 8)
50183375Skmacy#define XENMEMF_get_node(x) ((((x) >> 8) - 1) & 0xffu)
51183375Skmacy#endif
52183375Skmacy
53181624Skmacystruct xen_memory_reservation {
54181624Skmacy
55181624Skmacy    /*
56181624Skmacy     * XENMEM_increase_reservation:
57181624Skmacy     *   OUT: MFN (*not* GMFN) bases of extents that were allocated
58181624Skmacy     * XENMEM_decrease_reservation:
59181624Skmacy     *   IN:  GMFN bases of extents to free
60181624Skmacy     * XENMEM_populate_physmap:
61181624Skmacy     *   IN:  GPFN bases of extents to populate with memory
62181624Skmacy     *   OUT: GMFN bases of extents that were allocated
63181624Skmacy     *   (NB. This command also updates the mach_to_phys translation table)
64181624Skmacy     */
65183375Skmacy    XEN_GUEST_HANDLE(xen_pfn_t) extent_start;
66181624Skmacy
67181624Skmacy    /* Number of extents, and size/alignment of each (2^extent_order pages). */
68181624Skmacy    xen_ulong_t    nr_extents;
69181624Skmacy    unsigned int   extent_order;
70181624Skmacy
71183375Skmacy#if __XEN_INTERFACE_VERSION__ >= 0x00030209
72183375Skmacy    /* XENMEMF flags. */
73183375Skmacy    unsigned int   mem_flags;
74183375Skmacy#else
75181624Skmacy    unsigned int   address_bits;
76183375Skmacy#endif
77181624Skmacy
78181624Skmacy    /*
79181624Skmacy     * Domain whose reservation is being changed.
80181624Skmacy     * Unprivileged domains can specify only DOMID_SELF.
81181624Skmacy     */
82181624Skmacy    domid_t        domid;
83181624Skmacy};
84181624Skmacytypedef struct xen_memory_reservation xen_memory_reservation_t;
85181624SkmacyDEFINE_XEN_GUEST_HANDLE(xen_memory_reservation_t);
86181624Skmacy
87181624Skmacy/*
88181624Skmacy * An atomic exchange of memory pages. If return code is zero then
89181624Skmacy * @out.extent_list provides GMFNs of the newly-allocated memory.
90181624Skmacy * Returns zero on complete success, otherwise a negative error code.
91181624Skmacy * On complete success then always @nr_exchanged == @in.nr_extents.
92181624Skmacy * On partial success @nr_exchanged indicates how much work was done.
93181624Skmacy */
94181624Skmacy#define XENMEM_exchange             11
95181624Skmacystruct xen_memory_exchange {
96181624Skmacy    /*
97181624Skmacy     * [IN] Details of memory extents to be exchanged (GMFN bases).
98181624Skmacy     * Note that @in.address_bits is ignored and unused.
99181624Skmacy     */
100181624Skmacy    struct xen_memory_reservation in;
101181624Skmacy
102181624Skmacy    /*
103181624Skmacy     * [IN/OUT] Details of new memory extents.
104181624Skmacy     * We require that:
105181624Skmacy     *  1. @in.domid == @out.domid
106181624Skmacy     *  2. @in.nr_extents  << @in.extent_order ==
107181624Skmacy     *     @out.nr_extents << @out.extent_order
108181624Skmacy     *  3. @in.extent_start and @out.extent_start lists must not overlap
109181624Skmacy     *  4. @out.extent_start lists GPFN bases to be populated
110181624Skmacy     *  5. @out.extent_start is overwritten with allocated GMFN bases
111181624Skmacy     */
112181624Skmacy    struct xen_memory_reservation out;
113181624Skmacy
114181624Skmacy    /*
115181624Skmacy     * [OUT] Number of input extents that were successfully exchanged:
116181624Skmacy     *  1. The first @nr_exchanged input extents were successfully
117181624Skmacy     *     deallocated.
118181624Skmacy     *  2. The corresponding first entries in the output extent list correctly
119181624Skmacy     *     indicate the GMFNs that were successfully exchanged.
120181624Skmacy     *  3. All other input and output extents are untouched.
121181624Skmacy     *  4. If not all input exents are exchanged then the return code of this
122181624Skmacy     *     command will be non-zero.
123181624Skmacy     *  5. THIS FIELD MUST BE INITIALISED TO ZERO BY THE CALLER!
124181624Skmacy     */
125181624Skmacy    xen_ulong_t nr_exchanged;
126181624Skmacy};
127181624Skmacytypedef struct xen_memory_exchange xen_memory_exchange_t;
128181624SkmacyDEFINE_XEN_GUEST_HANDLE(xen_memory_exchange_t);
129181624Skmacy
130181624Skmacy/*
131181624Skmacy * Returns the maximum machine frame number of mapped RAM in this system.
132181624Skmacy * This command always succeeds (it never returns an error code).
133181624Skmacy * arg == NULL.
134181624Skmacy */
135181624Skmacy#define XENMEM_maximum_ram_page     2
136181624Skmacy
137181624Skmacy/*
138181624Skmacy * Returns the current or maximum memory reservation, in pages, of the
139181624Skmacy * specified domain (may be DOMID_SELF). Returns -ve errcode on failure.
140181624Skmacy * arg == addr of domid_t.
141181624Skmacy */
142181624Skmacy#define XENMEM_current_reservation  3
143181624Skmacy#define XENMEM_maximum_reservation  4
144181624Skmacy
145181624Skmacy/*
146181624Skmacy * Returns the maximum GPFN in use by the guest, or -ve errcode on failure.
147181624Skmacy */
148181624Skmacy#define XENMEM_maximum_gpfn         14
149181624Skmacy
150181624Skmacy/*
151181624Skmacy * Returns a list of MFN bases of 2MB extents comprising the machine_to_phys
152181624Skmacy * mapping table. Architectures which do not have a m2p table do not implement
153181624Skmacy * this command.
154181624Skmacy * arg == addr of xen_machphys_mfn_list_t.
155181624Skmacy */
156181624Skmacy#define XENMEM_machphys_mfn_list    5
157181624Skmacystruct xen_machphys_mfn_list {
158181624Skmacy    /*
159181624Skmacy     * Size of the 'extent_start' array. Fewer entries will be filled if the
160181624Skmacy     * machphys table is smaller than max_extents * 2MB.
161181624Skmacy     */
162181624Skmacy    unsigned int max_extents;
163181624Skmacy
164181624Skmacy    /*
165181624Skmacy     * Pointer to buffer to fill with list of extent starts. If there are
166181624Skmacy     * any large discontiguities in the machine address space, 2MB gaps in
167181624Skmacy     * the machphys table will be represented by an MFN base of zero.
168181624Skmacy     */
169183375Skmacy    XEN_GUEST_HANDLE(xen_pfn_t) extent_start;
170181624Skmacy
171181624Skmacy    /*
172181624Skmacy     * Number of extents written to the above array. This will be smaller
173181624Skmacy     * than 'max_extents' if the machphys table is smaller than max_e * 2MB.
174181624Skmacy     */
175181624Skmacy    unsigned int nr_extents;
176181624Skmacy};
177181624Skmacytypedef struct xen_machphys_mfn_list xen_machphys_mfn_list_t;
178181624SkmacyDEFINE_XEN_GUEST_HANDLE(xen_machphys_mfn_list_t);
179181624Skmacy
180181624Skmacy/*
181181624Skmacy * Returns the location in virtual address space of the machine_to_phys
182181624Skmacy * mapping table. Architectures which do not have a m2p table, or which do not
183181624Skmacy * map it by default into guest address space, do not implement this command.
184181624Skmacy * arg == addr of xen_machphys_mapping_t.
185181624Skmacy */
186181624Skmacy#define XENMEM_machphys_mapping     12
187181624Skmacystruct xen_machphys_mapping {
188181624Skmacy    xen_ulong_t v_start, v_end; /* Start and end virtual addresses.   */
189181624Skmacy    xen_ulong_t max_mfn;        /* Maximum MFN that can be looked up. */
190181624Skmacy};
191181624Skmacytypedef struct xen_machphys_mapping xen_machphys_mapping_t;
192181624SkmacyDEFINE_XEN_GUEST_HANDLE(xen_machphys_mapping_t);
193181624Skmacy
194181624Skmacy/*
195181624Skmacy * Sets the GPFN at which a particular page appears in the specified guest's
196181624Skmacy * pseudophysical address space.
197181624Skmacy * arg == addr of xen_add_to_physmap_t.
198181624Skmacy */
199181624Skmacy#define XENMEM_add_to_physmap      7
200181624Skmacystruct xen_add_to_physmap {
201181624Skmacy    /* Which domain to change the mapping for. */
202181624Skmacy    domid_t domid;
203181624Skmacy
204181624Skmacy    /* Source mapping space. */
205181624Skmacy#define XENMAPSPACE_shared_info 0 /* shared info page */
206181624Skmacy#define XENMAPSPACE_grant_table 1 /* grant table page */
207183375Skmacy#define XENMAPSPACE_mfn         2 /* usual MFN */
208181624Skmacy    unsigned int space;
209181624Skmacy
210181624Skmacy    /* Index into source mapping space. */
211181624Skmacy    xen_ulong_t idx;
212181624Skmacy
213181624Skmacy    /* GPFN where the source mapping page should appear. */
214181624Skmacy    xen_pfn_t     gpfn;
215181624Skmacy};
216181624Skmacytypedef struct xen_add_to_physmap xen_add_to_physmap_t;
217181624SkmacyDEFINE_XEN_GUEST_HANDLE(xen_add_to_physmap_t);
218181624Skmacy
219181624Skmacy/*
220183375Skmacy * Unmaps the page appearing at a particular GPFN from the specified guest's
221183375Skmacy * pseudophysical address space.
222183375Skmacy * arg == addr of xen_remove_from_physmap_t.
223183375Skmacy */
224183375Skmacy#define XENMEM_remove_from_physmap      15
225183375Skmacystruct xen_remove_from_physmap {
226183375Skmacy    /* Which domain to change the mapping for. */
227183375Skmacy    domid_t domid;
228183375Skmacy
229183375Skmacy    /* GPFN of the current mapping of the page. */
230183375Skmacy    xen_pfn_t     gpfn;
231183375Skmacy};
232183375Skmacytypedef struct xen_remove_from_physmap xen_remove_from_physmap_t;
233183375SkmacyDEFINE_XEN_GUEST_HANDLE(xen_remove_from_physmap_t);
234183375Skmacy
235183375Skmacy/*
236181624Skmacy * Translates a list of domain-specific GPFNs into MFNs. Returns a -ve error
237181624Skmacy * code on failure. This call only works for auto-translated guests.
238181624Skmacy */
239181624Skmacy#define XENMEM_translate_gpfn_list  8
240181624Skmacystruct xen_translate_gpfn_list {
241181624Skmacy    /* Which domain to translate for? */
242181624Skmacy    domid_t domid;
243181624Skmacy
244181624Skmacy    /* Length of list. */
245181624Skmacy    xen_ulong_t nr_gpfns;
246181624Skmacy
247181624Skmacy    /* List of GPFNs to translate. */
248183375Skmacy    XEN_GUEST_HANDLE(xen_pfn_t) gpfn_list;
249181624Skmacy
250181624Skmacy    /*
251181624Skmacy     * Output list to contain MFN translations. May be the same as the input
252181624Skmacy     * list (in which case each input GPFN is overwritten with the output MFN).
253181624Skmacy     */
254183375Skmacy    XEN_GUEST_HANDLE(xen_pfn_t) mfn_list;
255181624Skmacy};
256181624Skmacytypedef struct xen_translate_gpfn_list xen_translate_gpfn_list_t;
257181624SkmacyDEFINE_XEN_GUEST_HANDLE(xen_translate_gpfn_list_t);
258181624Skmacy
259181624Skmacy/*
260181624Skmacy * Returns the pseudo-physical memory map as it was when the domain
261181624Skmacy * was started (specified by XENMEM_set_memory_map).
262181624Skmacy * arg == addr of xen_memory_map_t.
263181624Skmacy */
264181624Skmacy#define XENMEM_memory_map           9
265181624Skmacystruct xen_memory_map {
266181624Skmacy    /*
267181624Skmacy     * On call the number of entries which can be stored in buffer. On
268181624Skmacy     * return the number of entries which have been stored in
269181624Skmacy     * buffer.
270181624Skmacy     */
271181624Skmacy    unsigned int nr_entries;
272181624Skmacy
273181624Skmacy    /*
274181624Skmacy     * Entries in the buffer are in the same format as returned by the
275181624Skmacy     * BIOS INT 0x15 EAX=0xE820 call.
276181624Skmacy     */
277183375Skmacy    XEN_GUEST_HANDLE(void) buffer;
278181624Skmacy};
279181624Skmacytypedef struct xen_memory_map xen_memory_map_t;
280181624SkmacyDEFINE_XEN_GUEST_HANDLE(xen_memory_map_t);
281181624Skmacy
282181624Skmacy/*
283181624Skmacy * Returns the real physical memory map. Passes the same structure as
284181624Skmacy * XENMEM_memory_map.
285181624Skmacy * arg == addr of xen_memory_map_t.
286181624Skmacy */
287181624Skmacy#define XENMEM_machine_memory_map   10
288181624Skmacy
289181624Skmacy/*
290181624Skmacy * Set the pseudo-physical memory map of a domain, as returned by
291181624Skmacy * XENMEM_memory_map.
292181624Skmacy * arg == addr of xen_foreign_memory_map_t.
293181624Skmacy */
294181624Skmacy#define XENMEM_set_memory_map       13
295181624Skmacystruct xen_foreign_memory_map {
296181624Skmacy    domid_t domid;
297181624Skmacy    struct xen_memory_map map;
298181624Skmacy};
299181624Skmacytypedef struct xen_foreign_memory_map xen_foreign_memory_map_t;
300181624SkmacyDEFINE_XEN_GUEST_HANDLE(xen_foreign_memory_map_t);
301181624Skmacy
302181624Skmacy#endif /* __XEN_PUBLIC_MEMORY_H__ */
303181624Skmacy
304181624Skmacy/*
305181624Skmacy * Local variables:
306181624Skmacy * mode: C
307181624Skmacy * c-set-style: "BSD"
308181624Skmacy * c-basic-offset: 4
309181624Skmacy * tab-width: 4
310181624Skmacy * indent-tabs-mode: nil
311181624Skmacy * End:
312181624Skmacy */
313