xref: /titanic_52/usr/src/uts/common/xen/public/memory.h (revision 8e4728571e959f3afb368407b22125278412c9d4)
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 struct xen_memory_reservation {
39 
40     /*
41      * XENMEM_increase_reservation:
42      *   OUT: MFN (*not* GMFN) bases of extents that were allocated
43      * XENMEM_decrease_reservation:
44      *   IN:  GMFN bases of extents to free
45      * XENMEM_populate_physmap:
46      *   IN:  GPFN bases of extents to populate with memory
47      *   OUT: GMFN bases of extents that were allocated
48      *   (NB. This command also updates the mach_to_phys translation table)
49      */
50     XEN_GUEST_HANDLE(xen_pfn_t) extent_start;
51 
52     /* Number of extents, and size/alignment of each (2^extent_order pages). */
53     xen_ulong_t    nr_extents;
54     unsigned int   extent_order;
55 
56     /*
57      * Maximum # bits addressable by the user of the allocated region (e.g.,
58      * I/O devices often have a 32-bit limitation even in 64-bit systems). If
59      * zero then the user has no addressing restriction.
60      * This field is not used by XENMEM_decrease_reservation.
61      */
62     unsigned int   address_bits;
63 
64     /*
65      * Domain whose reservation is being changed.
66      * Unprivileged domains can specify only DOMID_SELF.
67      */
68     domid_t        domid;
69 };
70 typedef struct xen_memory_reservation xen_memory_reservation_t;
71 DEFINE_XEN_GUEST_HANDLE(xen_memory_reservation_t);
72 
73 /*
74  * An atomic exchange of memory pages. If return code is zero then
75  * @out.extent_list provides GMFNs of the newly-allocated memory.
76  * Returns zero on complete success, otherwise a negative error code.
77  * On complete success then always @nr_exchanged == @in.nr_extents.
78  * On partial success @nr_exchanged indicates how much work was done.
79  */
80 #define XENMEM_exchange             11
81 struct xen_memory_exchange {
82     /*
83      * [IN] Details of memory extents to be exchanged (GMFN bases).
84      * Note that @in.address_bits is ignored and unused.
85      */
86     struct xen_memory_reservation in;
87 
88     /*
89      * [IN/OUT] Details of new memory extents.
90      * We require that:
91      *  1. @in.domid == @out.domid
92      *  2. @in.nr_extents  << @in.extent_order ==
93      *     @out.nr_extents << @out.extent_order
94      *  3. @in.extent_start and @out.extent_start lists must not overlap
95      *  4. @out.extent_start lists GPFN bases to be populated
96      *  5. @out.extent_start is overwritten with allocated GMFN bases
97      */
98     struct xen_memory_reservation out;
99 
100     /*
101      * [OUT] Number of input extents that were successfully exchanged:
102      *  1. The first @nr_exchanged input extents were successfully
103      *     deallocated.
104      *  2. The corresponding first entries in the output extent list correctly
105      *     indicate the GMFNs that were successfully exchanged.
106      *  3. All other input and output extents are untouched.
107      *  4. If not all input exents are exchanged then the return code of this
108      *     command will be non-zero.
109      *  5. THIS FIELD MUST BE INITIALISED TO ZERO BY THE CALLER!
110      */
111     xen_ulong_t nr_exchanged;
112 };
113 typedef struct xen_memory_exchange xen_memory_exchange_t;
114 DEFINE_XEN_GUEST_HANDLE(xen_memory_exchange_t);
115 
116 /*
117  * Returns the maximum machine frame number of mapped RAM in this system.
118  * This command always succeeds (it never returns an error code).
119  * arg == NULL.
120  */
121 #define XENMEM_maximum_ram_page     2
122 
123 /*
124  * Returns the current or maximum memory reservation, in pages, of the
125  * specified domain (may be DOMID_SELF). Returns -ve errcode on failure.
126  * arg == addr of domid_t.
127  */
128 #define XENMEM_current_reservation  3
129 #define XENMEM_maximum_reservation  4
130 
131 /*
132  * Returns a list of MFN bases of 2MB extents comprising the machine_to_phys
133  * mapping table. Architectures which do not have a m2p table do not implement
134  * this command.
135  * arg == addr of xen_machphys_mfn_list_t.
136  */
137 #define XENMEM_machphys_mfn_list    5
138 struct xen_machphys_mfn_list {
139     /*
140      * Size of the 'extent_start' array. Fewer entries will be filled if the
141      * machphys table is smaller than max_extents * 2MB.
142      */
143     unsigned int max_extents;
144 
145     /*
146      * Pointer to buffer to fill with list of extent starts. If there are
147      * any large discontiguities in the machine address space, 2MB gaps in
148      * the machphys table will be represented by an MFN base of zero.
149      */
150     XEN_GUEST_HANDLE(xen_pfn_t) extent_start;
151 
152     /*
153      * Number of extents written to the above array. This will be smaller
154      * than 'max_extents' if the machphys table is smaller than max_e * 2MB.
155      */
156     unsigned int nr_extents;
157 };
158 typedef struct xen_machphys_mfn_list xen_machphys_mfn_list_t;
159 DEFINE_XEN_GUEST_HANDLE(xen_machphys_mfn_list_t);
160 
161 /*
162  * Returns the location in virtual address space of the machine_to_phys
163  * mapping table. Architectures which do not have a m2p table, or which do not
164  * map it by default into guest address space, do not implement this command.
165  * arg == addr of xen_machphys_mapping_t.
166  */
167 #define XENMEM_machphys_mapping     12
168 struct xen_machphys_mapping {
169     xen_ulong_t v_start, v_end; /* Start and end virtual addresses.   */
170     xen_ulong_t max_mfn;        /* Maximum MFN that can be looked up. */
171 };
172 typedef struct xen_machphys_mapping xen_machphys_mapping_t;
173 DEFINE_XEN_GUEST_HANDLE(xen_machphys_mapping_t);
174 
175 /*
176  * Sets the GPFN at which a particular page appears in the specified guest's
177  * pseudophysical address space.
178  * arg == addr of xen_add_to_physmap_t.
179  */
180 #define XENMEM_add_to_physmap      7
181 struct xen_add_to_physmap {
182     /* Which domain to change the mapping for. */
183     domid_t domid;
184 
185     /* Source mapping space. */
186 #define XENMAPSPACE_shared_info 0 /* shared info page */
187 #define XENMAPSPACE_grant_table 1 /* grant table page */
188     unsigned int space;
189 
190     /* Index into source mapping space. */
191     xen_ulong_t idx;
192 
193     /* GPFN where the source mapping page should appear. */
194     xen_pfn_t     gpfn;
195 };
196 typedef struct xen_add_to_physmap xen_add_to_physmap_t;
197 DEFINE_XEN_GUEST_HANDLE(xen_add_to_physmap_t);
198 
199 /*
200  * Translates a list of domain-specific GPFNs into MFNs. Returns a -ve error
201  * code on failure. This call only works for auto-translated guests.
202  */
203 #define XENMEM_translate_gpfn_list  8
204 struct xen_translate_gpfn_list {
205     /* Which domain to translate for? */
206     domid_t domid;
207 
208     /* Length of list. */
209     xen_ulong_t nr_gpfns;
210 
211     /* List of GPFNs to translate. */
212     XEN_GUEST_HANDLE(xen_pfn_t) gpfn_list;
213 
214     /*
215      * Output list to contain MFN translations. May be the same as the input
216      * list (in which case each input GPFN is overwritten with the output MFN).
217      */
218     XEN_GUEST_HANDLE(xen_pfn_t) mfn_list;
219 };
220 typedef struct xen_translate_gpfn_list xen_translate_gpfn_list_t;
221 DEFINE_XEN_GUEST_HANDLE(xen_translate_gpfn_list_t);
222 
223 /*
224  * Returns the pseudo-physical memory map as it was when the domain
225  * was started (specified by XENMEM_set_memory_map).
226  * arg == addr of xen_memory_map_t.
227  */
228 #define XENMEM_memory_map           9
229 struct xen_memory_map {
230     /*
231      * On call the number of entries which can be stored in buffer. On
232      * return the number of entries which have been stored in
233      * buffer.
234      */
235     unsigned int nr_entries;
236 
237     /*
238      * Entries in the buffer are in the same format as returned by the
239      * BIOS INT 0x15 EAX=0xE820 call.
240      */
241     XEN_GUEST_HANDLE(void) buffer;
242 };
243 typedef struct xen_memory_map xen_memory_map_t;
244 DEFINE_XEN_GUEST_HANDLE(xen_memory_map_t);
245 
246 /*
247  * Returns the real physical memory map. Passes the same structure as
248  * XENMEM_memory_map.
249  * arg == addr of xen_memory_map_t.
250  */
251 #define XENMEM_machine_memory_map   10
252 
253 /*
254  * Set the pseudo-physical memory map of a domain, as returned by
255  * XENMEM_memory_map.
256  * arg == addr of xen_foreign_memory_map_t.
257  */
258 #define XENMEM_set_memory_map       13
259 struct xen_foreign_memory_map {
260     domid_t domid;
261     struct xen_memory_map map;
262 };
263 typedef struct xen_foreign_memory_map xen_foreign_memory_map_t;
264 DEFINE_XEN_GUEST_HANDLE(xen_foreign_memory_map_t);
265 
266 #endif /* __XEN_PUBLIC_MEMORY_H__ */
267 
268 /*
269  * Local variables:
270  * mode: C
271  * c-set-style: "BSD"
272  * c-basic-offset: 4
273  * tab-width: 4
274  * indent-tabs-mode: nil
275  * End:
276  */
277