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