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