1843e198johnlev/******************************************************************************
2843e198johnlev * memory.h
3843e198johnlev *
4843e198johnlev * Memory reservation and information.
5843e198johnlev *
6843e198johnlev * Permission is hereby granted, free of charge, to any person obtaining a copy
7843e198johnlev * of this software and associated documentation files (the "Software"), to
8843e198johnlev * deal in the Software without restriction, including without limitation the
9843e198johnlev * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10843e198johnlev * sell copies of the Software, and to permit persons to whom the Software is
11843e198johnlev * furnished to do so, subject to the following conditions:
12843e198johnlev *
13843e198johnlev * The above copyright notice and this permission notice shall be included in
14843e198johnlev * all copies or substantial portions of the Software.
15843e198johnlev *
16843e198johnlev * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17843e198johnlev * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18843e198johnlev * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19843e198johnlev * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20843e198johnlev * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21843e198johnlev * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22843e198johnlev * DEALINGS IN THE SOFTWARE.
23843e198johnlev *
24843e198johnlev * Copyright (c) 2005, Keir Fraser <keir@xensource.com>
25843e198johnlev */
26843e198johnlev
27843e198johnlev#ifndef __XEN_PUBLIC_MEMORY_H__
28843e198johnlev#define __XEN_PUBLIC_MEMORY_H__
29843e198johnlev
30843e198johnlev/*
31843e198johnlev * Increase or decrease the specified domain's memory reservation. Returns the
32843e198johnlev * number of extents successfully allocated or freed.
33843e198johnlev * arg == addr of struct xen_memory_reservation.
34843e198johnlev */
35843e198johnlev#define XENMEM_increase_reservation 0
36843e198johnlev#define XENMEM_decrease_reservation 1
37843e198johnlev#define XENMEM_populate_physmap     6
38349b53dStuart Maybee
39349b53dStuart Maybee#if __XEN_INTERFACE_VERSION__ >= 0x00030209
40349b53dStuart Maybee/*
41349b53dStuart Maybee * Maximum # bits addressable by the user of the allocated region (e.g., I/O
42349b53dStuart Maybee * devices often have a 32-bit limitation even in 64-bit systems). If zero
43349b53dStuart Maybee * then the user has no addressing restriction. This field is not used by
44349b53dStuart Maybee * XENMEM_decrease_reservation.
45349b53dStuart Maybee */
46349b53dStuart Maybee#define XENMEMF_address_bits(x)     (x)
47349b53dStuart Maybee#define XENMEMF_get_address_bits(x) ((x) & 0xffu)
48349b53dStuart Maybee/* NUMA node to allocate from. */
49349b53dStuart Maybee#define XENMEMF_node(x)     (((x) + 1) << 8)
50349b53dStuart Maybee#define XENMEMF_get_node(x) ((((x) >> 8) - 1) & 0xffu)
51ad09f8bMark Johnson/* Flag to populate physmap with populate-on-demand entries */
52ad09f8bMark Johnson#define XENMEMF_populate_on_demand (1<<16)
53349b53dStuart Maybee#endif
54349b53dStuart Maybee
55843e198johnlevstruct xen_memory_reservation {
56843e198johnlev
57843e198johnlev    /*
58843e198johnlev     * XENMEM_increase_reservation:
59843e198johnlev     *   OUT: MFN (*not* GMFN) bases of extents that were allocated
60843e198johnlev     * XENMEM_decrease_reservation:
61843e198johnlev     *   IN:  GMFN bases of extents to free
62843e198johnlev     * XENMEM_populate_physmap:
63843e198johnlev     *   IN:  GPFN bases of extents to populate with memory
64843e198johnlev     *   OUT: GMFN bases of extents that were allocated
65843e198johnlev     *   (NB. This command also updates the mach_to_phys translation table)
66843e198johnlev     */
67843e198johnlev    XEN_GUEST_HANDLE(xen_pfn_t) extent_start;
68843e198johnlev
69843e198johnlev    /* Number of extents, and size/alignment of each (2^extent_order pages). */
70843e198johnlev    xen_ulong_t    nr_extents;
71843e198johnlev    unsigned int   extent_order;
72843e198johnlev
73349b53dStuart Maybee#if __XEN_INTERFACE_VERSION__ >= 0x00030209
74349b53dStuart Maybee    /* XENMEMF flags. */
75349b53dStuart Maybee    unsigned int   mem_flags;
76349b53dStuart Maybee#else
77843e198johnlev    unsigned int   address_bits;
78349b53dStuart Maybee#endif
79843e198johnlev
80843e198johnlev    /*
81843e198johnlev     * Domain whose reservation is being changed.
82843e198johnlev     * Unprivileged domains can specify only DOMID_SELF.
83843e198johnlev     */
84843e198johnlev    domid_t        domid;
85843e198johnlev};
86843e198johnlevtypedef struct xen_memory_reservation xen_memory_reservation_t;
87843e198johnlevDEFINE_XEN_GUEST_HANDLE(xen_memory_reservation_t);
88843e198johnlev
89843e198johnlev/*
90843e198johnlev * An atomic exchange of memory pages. If return code is zero then
91843e198johnlev * @out.extent_list provides GMFNs of the newly-allocated memory.
92843e198johnlev * Returns zero on complete success, otherwise a negative error code.
93843e198johnlev * On complete success then always @nr_exchanged == @in.nr_extents.
94843e198johnlev * On partial success @nr_exchanged indicates how much work was done.
95843e198johnlev */
96843e198johnlev#define XENMEM_exchange             11
97843e198johnlevstruct xen_memory_exchange {
98843e198johnlev    /*
99843e198johnlev     * [IN] Details of memory extents to be exchanged (GMFN bases).
100843e198johnlev     * Note that @in.address_bits is ignored and unused.
101843e198johnlev     */
102843e198johnlev    struct xen_memory_reservation in;
103843e198johnlev
104843e198johnlev    /*
105843e198johnlev     * [IN/OUT] Details of new memory extents.
106843e198johnlev     * We require that:
107843e198johnlev     *  1. @in.domid == @out.domid
108843e198johnlev     *  2. @in.nr_extents  << @in.extent_order ==
109843e198johnlev     *     @out.nr_extents << @out.extent_order
110843e198johnlev     *  3. @in.extent_start and @out.extent_start lists must not overlap
111843e198johnlev     *  4. @out.extent_start lists GPFN bases to be populated
112843e198johnlev     *  5. @out.extent_start is overwritten with allocated GMFN bases
113843e198johnlev     */
114843e198johnlev    struct xen_memory_reservation out;
115843e198johnlev
116843e198johnlev    /*
117843e198johnlev     * [OUT] Number of input extents that were successfully exchanged:
118843e198johnlev     *  1. The first @nr_exchanged input extents were successfully
119843e198johnlev     *     deallocated.
120843e198johnlev     *  2. The corresponding first entries in the output extent list correctly
121843e198johnlev     *     indicate the GMFNs that were successfully exchanged.
122843e198johnlev     *  3. All other input and output extents are untouched.
123843e198johnlev     *  4. If not all input exents are exchanged then the return code of this
124843e198johnlev     *     command will be non-zero.
125843e198johnlev     *  5. THIS FIELD MUST BE INITIALISED TO ZERO BY THE CALLER!
126843e198johnlev     */
127843e198johnlev    xen_ulong_t nr_exchanged;
128843e198johnlev};
129843e198johnlevtypedef struct xen_memory_exchange xen_memory_exchange_t;
130843e198johnlevDEFINE_XEN_GUEST_HANDLE(xen_memory_exchange_t);
131843e198johnlev
132843e198johnlev/*
133843e198johnlev * Returns the maximum machine frame number of mapped RAM in this system.
134843e198johnlev * This command always succeeds (it never returns an error code).
135843e198johnlev * arg == NULL.
136843e198johnlev */
137843e198johnlev#define XENMEM_maximum_ram_page     2
138843e198johnlev
139843e198johnlev/*
140843e198johnlev * Returns the current or maximum memory reservation, in pages, of the
141843e198johnlev * specified domain (may be DOMID_SELF). Returns -ve errcode on failure.
142843e198johnlev * arg == addr of domid_t.
143843e198johnlev */
144843e198johnlev#define XENMEM_current_reservation  3
145843e198johnlev#define XENMEM_maximum_reservation  4
146843e198johnlev
147843e198johnlev/*
148a576ab5rab * Returns the maximum GPFN in use by the guest, or -ve errcode on failure.
149a576ab5rab */
150a576ab5rab#define XENMEM_maximum_gpfn         14
151a576ab5rab
152a576ab5rab/*
153843e198johnlev * Returns a list of MFN bases of 2MB extents comprising the machine_to_phys
154843e198johnlev * mapping table. Architectures which do not have a m2p table do not implement
155843e198johnlev * this command.
156843e198johnlev * arg == addr of xen_machphys_mfn_list_t.
157843e198johnlev */
158843e198johnlev#define XENMEM_machphys_mfn_list    5
159843e198johnlevstruct xen_machphys_mfn_list {
160843e198johnlev    /*
161843e198johnlev     * Size of the 'extent_start' array. Fewer entries will be filled if the
162843e198johnlev     * machphys table is smaller than max_extents * 2MB.
163843e198johnlev     */
164843e198johnlev    unsigned int max_extents;
165843e198johnlev
166843e198johnlev    /*
167843e198johnlev     * Pointer to buffer to fill with list of extent starts. If there are
168843e198johnlev     * any large discontiguities in the machine address space, 2MB gaps in
169843e198johnlev     * the machphys table will be represented by an MFN base of zero.
170843e198johnlev     */
171843e198johnlev    XEN_GUEST_HANDLE(xen_pfn_t) extent_start;
172843e198johnlev
173843e198johnlev    /*
174843e198johnlev     * Number of extents written to the above array. This will be smaller
175843e198johnlev     * than 'max_extents' if the machphys table is smaller than max_e * 2MB.
176843e198johnlev     */
177843e198johnlev    unsigned int nr_extents;
178843e198johnlev};
179843e198johnlevtypedef struct xen_machphys_mfn_list xen_machphys_mfn_list_t;
180843e198johnlevDEFINE_XEN_GUEST_HANDLE(xen_machphys_mfn_list_t);
181843e198johnlev
182843e198johnlev/*
183843e198johnlev * Returns the location in virtual address space of the machine_to_phys
184843e198johnlev * mapping table. Architectures which do not have a m2p table, or which do not
185843e198johnlev * map it by default into guest address space, do not implement this command.
186843e198johnlev * arg == addr of xen_machphys_mapping_t.
187843e198johnlev */
188843e198johnlev#define XENMEM_machphys_mapping     12
189843e198johnlevstruct xen_machphys_mapping {
190843e198johnlev    xen_ulong_t v_start, v_end; /* Start and end virtual addresses.   */
191843e198johnlev    xen_ulong_t max_mfn;        /* Maximum MFN that can be looked up. */
192843e198johnlev};
193843e198johnlevtypedef struct xen_machphys_mapping xen_machphys_mapping_t;
194843e198johnlevDEFINE_XEN_GUEST_HANDLE(xen_machphys_mapping_t);
195843e198johnlev
196843e198johnlev/*
197843e198johnlev * Sets the GPFN at which a particular page appears in the specified guest's
198843e198johnlev * pseudophysical address space.
199843e198johnlev * arg == addr of xen_add_to_physmap_t.
200843e198johnlev */
201843e198johnlev#define XENMEM_add_to_physmap      7
202843e198johnlevstruct xen_add_to_physmap {
203843e198johnlev    /* Which domain to change the mapping for. */
204843e198johnlev    domid_t domid;
205843e198johnlev
206843e198johnlev    /* Source mapping space. */
207843e198johnlev#define XENMAPSPACE_shared_info 0 /* shared info page */
208843e198johnlev#define XENMAPSPACE_grant_table 1 /* grant table page */
209ad09f8bMark Johnson#define XENMAPSPACE_gmfn        2 /* GMFN */
210843e198johnlev    unsigned int space;
211843e198johnlev
212843e198johnlev    /* Index into source mapping space. */
213843e198johnlev    xen_ulong_t idx;
214843e198johnlev
215843e198johnlev    /* GPFN where the source mapping page should appear. */
216843e198johnlev    xen_pfn_t     gpfn;
217843e198johnlev};
218843e198johnlevtypedef struct xen_add_to_physmap xen_add_to_physmap_t;
219843e198johnlevDEFINE_XEN_GUEST_HANDLE(xen_add_to_physmap_t);
220843e198johnlev
221ad09f8bMark Johnson/*** REMOVED ***/
222ad09f8bMark Johnson/*#define XENMEM_translate_gpfn_list  8*/
223843e198johnlev
224843e198johnlev/*
225843e198johnlev * Returns the pseudo-physical memory map as it was when the domain
226843e198johnlev * was started (specified by XENMEM_set_memory_map).
227843e198johnlev * arg == addr of xen_memory_map_t.
228843e198johnlev */
229843e198johnlev#define XENMEM_memory_map           9
230843e198johnlevstruct xen_memory_map {
231843e198johnlev    /*
232843e198johnlev     * On call the number of entries which can be stored in buffer. On
233843e198johnlev     * return the number of entries which have been stored in
234843e198johnlev     * buffer.
235843e198johnlev     */
236843e198johnlev    unsigned int nr_entries;
237843e198johnlev
238843e198johnlev    /*
239843e198johnlev     * Entries in the buffer are in the same format as returned by the
240843e198johnlev     * BIOS INT 0x15 EAX=0xE820 call.
241843e198johnlev     */
242843e198johnlev    XEN_GUEST_HANDLE(void) buffer;
243843e198johnlev};
244843e198johnlevtypedef struct xen_memory_map xen_memory_map_t;
245843e198johnlevDEFINE_XEN_GUEST_HANDLE(xen_memory_map_t);
246843e198johnlev
247843e198johnlev/*
248843e198johnlev * Returns the real physical memory map. Passes the same structure as
249843e198johnlev * XENMEM_memory_map.
250843e198johnlev * arg == addr of xen_memory_map_t.
251843e198johnlev */
252843e198johnlev#define XENMEM_machine_memory_map   10
253843e198johnlev
254843e198johnlev/*
255843e198johnlev * Set the pseudo-physical memory map of a domain, as returned by
256843e198johnlev * XENMEM_memory_map.
257843e198johnlev * arg == addr of xen_foreign_memory_map_t.
258843e198johnlev */
259843e198johnlev#define XENMEM_set_memory_map       13
260843e198johnlevstruct xen_foreign_memory_map {
261843e198johnlev    domid_t domid;
262843e198johnlev    struct xen_memory_map map;
263843e198johnlev};
264843e198johnlevtypedef struct xen_foreign_memory_map xen_foreign_memory_map_t;
265843e198johnlevDEFINE_XEN_GUEST_HANDLE(xen_foreign_memory_map_t);
266843e198johnlev
267ad09f8bMark Johnson#define XENMEM_set_pod_target       16
268ad09f8bMark Johnson#define XENMEM_get_pod_target       17
269ad09f8bMark Johnsonstruct xen_pod_target {
270ad09f8bMark Johnson    /* IN */
271ad09f8bMark Johnson    uint64_t target_pages;
272ad09f8bMark Johnson    /* OUT */
273ad09f8bMark Johnson    uint64_t tot_pages;
274ad09f8bMark Johnson    uint64_t pod_cache_pages;
275ad09f8bMark Johnson    uint64_t pod_entries;
276ad09f8bMark Johnson    /* IN */
277ad09f8bMark Johnson    domid_t domid;
278ad09f8bMark Johnson};
279ad09f8bMark Johnsontypedef struct xen_pod_target xen_pod_target_t;
280843e198johnlev#endif /* __XEN_PUBLIC_MEMORY_H__ */
281843e198johnlev
282843e198johnlev/*
283843e198johnlev * Local variables:
284843e198johnlev * mode: C
285843e198johnlev * c-set-style: "BSD"
286843e198johnlev * c-basic-offset: 4
287843e198johnlev * tab-width: 4
288843e198johnlev * indent-tabs-mode: nil
289843e198johnlev * End:
290843e198johnlev */
291