xref: /openbmc/linux/include/xen/interface/memory.h (revision 35ae11fd146384d222f3bb1f17eed1970cc92c36)
1a42089ddSJeremy Fitzhardinge /******************************************************************************
2a42089ddSJeremy Fitzhardinge  * memory.h
3a42089ddSJeremy Fitzhardinge  *
4a42089ddSJeremy Fitzhardinge  * Memory reservation and information.
5a42089ddSJeremy Fitzhardinge  *
6a42089ddSJeremy Fitzhardinge  * Copyright (c) 2005, Keir Fraser <keir@xensource.com>
7a42089ddSJeremy Fitzhardinge  */
8a42089ddSJeremy Fitzhardinge 
9a42089ddSJeremy Fitzhardinge #ifndef __XEN_PUBLIC_MEMORY_H__
10a42089ddSJeremy Fitzhardinge #define __XEN_PUBLIC_MEMORY_H__
11a42089ddSJeremy Fitzhardinge 
1219001c8cSAlex Nixon #include <linux/spinlock.h>
1319001c8cSAlex Nixon 
14a42089ddSJeremy Fitzhardinge /*
15a42089ddSJeremy Fitzhardinge  * Increase or decrease the specified domain's memory reservation. Returns a
16a42089ddSJeremy Fitzhardinge  * -ve errcode on failure, or the # extents successfully allocated or freed.
17a42089ddSJeremy Fitzhardinge  * arg == addr of struct xen_memory_reservation.
18a42089ddSJeremy Fitzhardinge  */
19a42089ddSJeremy Fitzhardinge #define XENMEM_increase_reservation 0
20a42089ddSJeremy Fitzhardinge #define XENMEM_decrease_reservation 1
21a42089ddSJeremy Fitzhardinge #define XENMEM_populate_physmap     6
22a42089ddSJeremy Fitzhardinge struct xen_memory_reservation {
23a42089ddSJeremy Fitzhardinge 
24a42089ddSJeremy Fitzhardinge     /*
25a42089ddSJeremy Fitzhardinge      * XENMEM_increase_reservation:
26a42089ddSJeremy Fitzhardinge      *   OUT: MFN (*not* GMFN) bases of extents that were allocated
27a42089ddSJeremy Fitzhardinge      * XENMEM_decrease_reservation:
28a42089ddSJeremy Fitzhardinge      *   IN:  GMFN bases of extents to free
29a42089ddSJeremy Fitzhardinge      * XENMEM_populate_physmap:
30a42089ddSJeremy Fitzhardinge      *   IN:  GPFN bases of extents to populate with memory
31a42089ddSJeremy Fitzhardinge      *   OUT: GMFN bases of extents that were allocated
32a42089ddSJeremy Fitzhardinge      *   (NB. This command also updates the mach_to_phys translation table)
33a42089ddSJeremy Fitzhardinge      */
34bfdab126SIsaku Yamahata     GUEST_HANDLE(ulong) extent_start;
35a42089ddSJeremy Fitzhardinge 
36a42089ddSJeremy Fitzhardinge     /* Number of extents, and size/alignment of each (2^extent_order pages). */
37a42089ddSJeremy Fitzhardinge     unsigned long  nr_extents;
38a42089ddSJeremy Fitzhardinge     unsigned int   extent_order;
39a42089ddSJeremy Fitzhardinge 
40a42089ddSJeremy Fitzhardinge     /*
41a42089ddSJeremy Fitzhardinge      * Maximum # bits addressable by the user of the allocated region (e.g.,
42a42089ddSJeremy Fitzhardinge      * I/O devices often have a 32-bit limitation even in 64-bit systems). If
43a42089ddSJeremy Fitzhardinge      * zero then the user has no addressing restriction.
44a42089ddSJeremy Fitzhardinge      * This field is not used by XENMEM_decrease_reservation.
45a42089ddSJeremy Fitzhardinge      */
46a42089ddSJeremy Fitzhardinge     unsigned int   address_bits;
47a42089ddSJeremy Fitzhardinge 
48a42089ddSJeremy Fitzhardinge     /*
49a42089ddSJeremy Fitzhardinge      * Domain whose reservation is being changed.
50a42089ddSJeremy Fitzhardinge      * Unprivileged domains can specify only DOMID_SELF.
51a42089ddSJeremy Fitzhardinge      */
52a42089ddSJeremy Fitzhardinge     domid_t        domid;
53a42089ddSJeremy Fitzhardinge 
54a42089ddSJeremy Fitzhardinge };
55bfdab126SIsaku Yamahata DEFINE_GUEST_HANDLE_STRUCT(xen_memory_reservation);
56a42089ddSJeremy Fitzhardinge 
57a42089ddSJeremy Fitzhardinge /*
5808bbc9daSAlex Nixon  * An atomic exchange of memory pages. If return code is zero then
5908bbc9daSAlex Nixon  * @out.extent_list provides GMFNs of the newly-allocated memory.
6008bbc9daSAlex Nixon  * Returns zero on complete success, otherwise a negative error code.
6108bbc9daSAlex Nixon  * On complete success then always @nr_exchanged == @in.nr_extents.
6208bbc9daSAlex Nixon  * On partial success @nr_exchanged indicates how much work was done.
6308bbc9daSAlex Nixon  */
6408bbc9daSAlex Nixon #define XENMEM_exchange             11
6508bbc9daSAlex Nixon struct xen_memory_exchange {
6608bbc9daSAlex Nixon     /*
6708bbc9daSAlex Nixon      * [IN] Details of memory extents to be exchanged (GMFN bases).
6808bbc9daSAlex Nixon      * Note that @in.address_bits is ignored and unused.
6908bbc9daSAlex Nixon      */
7008bbc9daSAlex Nixon     struct xen_memory_reservation in;
7108bbc9daSAlex Nixon 
7208bbc9daSAlex Nixon     /*
7308bbc9daSAlex Nixon      * [IN/OUT] Details of new memory extents.
7408bbc9daSAlex Nixon      * We require that:
7508bbc9daSAlex Nixon      *  1. @in.domid == @out.domid
7608bbc9daSAlex Nixon      *  2. @in.nr_extents  << @in.extent_order ==
7708bbc9daSAlex Nixon      *     @out.nr_extents << @out.extent_order
7808bbc9daSAlex Nixon      *  3. @in.extent_start and @out.extent_start lists must not overlap
7908bbc9daSAlex Nixon      *  4. @out.extent_start lists GPFN bases to be populated
8008bbc9daSAlex Nixon      *  5. @out.extent_start is overwritten with allocated GMFN bases
8108bbc9daSAlex Nixon      */
8208bbc9daSAlex Nixon     struct xen_memory_reservation out;
8308bbc9daSAlex Nixon 
8408bbc9daSAlex Nixon     /*
8508bbc9daSAlex Nixon      * [OUT] Number of input extents that were successfully exchanged:
8608bbc9daSAlex Nixon      *  1. The first @nr_exchanged input extents were successfully
8708bbc9daSAlex Nixon      *     deallocated.
8808bbc9daSAlex Nixon      *  2. The corresponding first entries in the output extent list correctly
8908bbc9daSAlex Nixon      *     indicate the GMFNs that were successfully exchanged.
9008bbc9daSAlex Nixon      *  3. All other input and output extents are untouched.
9108bbc9daSAlex Nixon      *  4. If not all input exents are exchanged then the return code of this
9208bbc9daSAlex Nixon      *     command will be non-zero.
9308bbc9daSAlex Nixon      *  5. THIS FIELD MUST BE INITIALISED TO ZERO BY THE CALLER!
9408bbc9daSAlex Nixon      */
9508bbc9daSAlex Nixon     unsigned long nr_exchanged;
9608bbc9daSAlex Nixon };
9708bbc9daSAlex Nixon 
9808bbc9daSAlex Nixon DEFINE_GUEST_HANDLE_STRUCT(xen_memory_exchange);
9908bbc9daSAlex Nixon /*
100a42089ddSJeremy Fitzhardinge  * Returns the maximum machine frame number of mapped RAM in this system.
101a42089ddSJeremy Fitzhardinge  * This command always succeeds (it never returns an error code).
102a42089ddSJeremy Fitzhardinge  * arg == NULL.
103a42089ddSJeremy Fitzhardinge  */
104a42089ddSJeremy Fitzhardinge #define XENMEM_maximum_ram_page     2
105a42089ddSJeremy Fitzhardinge 
106a42089ddSJeremy Fitzhardinge /*
107a42089ddSJeremy Fitzhardinge  * Returns the current or maximum memory reservation, in pages, of the
108a42089ddSJeremy Fitzhardinge  * specified domain (may be DOMID_SELF). Returns -ve errcode on failure.
109a42089ddSJeremy Fitzhardinge  * arg == addr of domid_t.
110a42089ddSJeremy Fitzhardinge  */
111a42089ddSJeremy Fitzhardinge #define XENMEM_current_reservation  3
112a42089ddSJeremy Fitzhardinge #define XENMEM_maximum_reservation  4
113a42089ddSJeremy Fitzhardinge 
114a42089ddSJeremy Fitzhardinge /*
115a42089ddSJeremy Fitzhardinge  * Returns a list of MFN bases of 2MB extents comprising the machine_to_phys
116a42089ddSJeremy Fitzhardinge  * mapping table. Architectures which do not have a m2p table do not implement
117a42089ddSJeremy Fitzhardinge  * this command.
118a42089ddSJeremy Fitzhardinge  * arg == addr of xen_machphys_mfn_list_t.
119a42089ddSJeremy Fitzhardinge  */
120a42089ddSJeremy Fitzhardinge #define XENMEM_machphys_mfn_list    5
121a42089ddSJeremy Fitzhardinge struct xen_machphys_mfn_list {
122a42089ddSJeremy Fitzhardinge     /*
123a42089ddSJeremy Fitzhardinge      * Size of the 'extent_start' array. Fewer entries will be filled if the
124a42089ddSJeremy Fitzhardinge      * machphys table is smaller than max_extents * 2MB.
125a42089ddSJeremy Fitzhardinge      */
126a42089ddSJeremy Fitzhardinge     unsigned int max_extents;
127a42089ddSJeremy Fitzhardinge 
128a42089ddSJeremy Fitzhardinge     /*
129a42089ddSJeremy Fitzhardinge      * Pointer to buffer to fill with list of extent starts. If there are
130a42089ddSJeremy Fitzhardinge      * any large discontiguities in the machine address space, 2MB gaps in
131a42089ddSJeremy Fitzhardinge      * the machphys table will be represented by an MFN base of zero.
132a42089ddSJeremy Fitzhardinge      */
133bfdab126SIsaku Yamahata     GUEST_HANDLE(ulong) extent_start;
134a42089ddSJeremy Fitzhardinge 
135a42089ddSJeremy Fitzhardinge     /*
136a42089ddSJeremy Fitzhardinge      * Number of extents written to the above array. This will be smaller
137a42089ddSJeremy Fitzhardinge      * than 'max_extents' if the machphys table is smaller than max_e * 2MB.
138a42089ddSJeremy Fitzhardinge      */
139a42089ddSJeremy Fitzhardinge     unsigned int nr_extents;
140a42089ddSJeremy Fitzhardinge };
141bfdab126SIsaku Yamahata DEFINE_GUEST_HANDLE_STRUCT(xen_machphys_mfn_list);
142a42089ddSJeremy Fitzhardinge 
143a42089ddSJeremy Fitzhardinge /*
144a42089ddSJeremy Fitzhardinge  * Sets the GPFN at which a particular page appears in the specified guest's
145a42089ddSJeremy Fitzhardinge  * pseudophysical address space.
146a42089ddSJeremy Fitzhardinge  * arg == addr of xen_add_to_physmap_t.
147a42089ddSJeremy Fitzhardinge  */
148a42089ddSJeremy Fitzhardinge #define XENMEM_add_to_physmap      7
149a42089ddSJeremy Fitzhardinge struct xen_add_to_physmap {
150a42089ddSJeremy Fitzhardinge     /* Which domain to change the mapping for. */
151a42089ddSJeremy Fitzhardinge     domid_t domid;
152a42089ddSJeremy Fitzhardinge 
153a42089ddSJeremy Fitzhardinge     /* Source mapping space. */
154a42089ddSJeremy Fitzhardinge #define XENMAPSPACE_shared_info 0 /* shared info page */
155a42089ddSJeremy Fitzhardinge #define XENMAPSPACE_grant_table 1 /* grant table page */
156a42089ddSJeremy Fitzhardinge     unsigned int space;
157a42089ddSJeremy Fitzhardinge 
158a42089ddSJeremy Fitzhardinge     /* Index into source mapping space. */
159a42089ddSJeremy Fitzhardinge     unsigned long idx;
160a42089ddSJeremy Fitzhardinge 
161a42089ddSJeremy Fitzhardinge     /* GPFN where the source mapping page should appear. */
162a42089ddSJeremy Fitzhardinge     unsigned long gpfn;
163a42089ddSJeremy Fitzhardinge };
164bfdab126SIsaku Yamahata DEFINE_GUEST_HANDLE_STRUCT(xen_add_to_physmap);
165a42089ddSJeremy Fitzhardinge 
166a42089ddSJeremy Fitzhardinge /*
167a42089ddSJeremy Fitzhardinge  * Translates a list of domain-specific GPFNs into MFNs. Returns a -ve error
168a42089ddSJeremy Fitzhardinge  * code on failure. This call only works for auto-translated guests.
169a42089ddSJeremy Fitzhardinge  */
170a42089ddSJeremy Fitzhardinge #define XENMEM_translate_gpfn_list  8
171a42089ddSJeremy Fitzhardinge struct xen_translate_gpfn_list {
172a42089ddSJeremy Fitzhardinge     /* Which domain to translate for? */
173a42089ddSJeremy Fitzhardinge     domid_t domid;
174a42089ddSJeremy Fitzhardinge 
175a42089ddSJeremy Fitzhardinge     /* Length of list. */
176a42089ddSJeremy Fitzhardinge     unsigned long nr_gpfns;
177a42089ddSJeremy Fitzhardinge 
178a42089ddSJeremy Fitzhardinge     /* List of GPFNs to translate. */
179bfdab126SIsaku Yamahata     GUEST_HANDLE(ulong) gpfn_list;
180a42089ddSJeremy Fitzhardinge 
181a42089ddSJeremy Fitzhardinge     /*
182a42089ddSJeremy Fitzhardinge      * Output list to contain MFN translations. May be the same as the input
183a42089ddSJeremy Fitzhardinge      * list (in which case each input GPFN is overwritten with the output MFN).
184a42089ddSJeremy Fitzhardinge      */
185bfdab126SIsaku Yamahata     GUEST_HANDLE(ulong) mfn_list;
186a42089ddSJeremy Fitzhardinge };
187bfdab126SIsaku Yamahata DEFINE_GUEST_HANDLE_STRUCT(xen_translate_gpfn_list);
188a42089ddSJeremy Fitzhardinge 
189*35ae11fdSIan Campbell /*
190*35ae11fdSIan Campbell  * Returns the pseudo-physical memory map as it was when the domain
191*35ae11fdSIan Campbell  * was started (specified by XENMEM_set_memory_map).
192*35ae11fdSIan Campbell  * arg == addr of struct xen_memory_map.
193*35ae11fdSIan Campbell  */
194*35ae11fdSIan Campbell #define XENMEM_memory_map           9
195*35ae11fdSIan Campbell struct xen_memory_map {
196*35ae11fdSIan Campbell     /*
197*35ae11fdSIan Campbell      * On call the number of entries which can be stored in buffer. On
198*35ae11fdSIan Campbell      * return the number of entries which have been stored in
199*35ae11fdSIan Campbell      * buffer.
200*35ae11fdSIan Campbell      */
201*35ae11fdSIan Campbell     unsigned int nr_entries;
202*35ae11fdSIan Campbell 
203*35ae11fdSIan Campbell     /*
204*35ae11fdSIan Campbell      * Entries in the buffer are in the same format as returned by the
205*35ae11fdSIan Campbell      * BIOS INT 0x15 EAX=0xE820 call.
206*35ae11fdSIan Campbell      */
207*35ae11fdSIan Campbell     GUEST_HANDLE(void) buffer;
208*35ae11fdSIan Campbell };
209*35ae11fdSIan Campbell DEFINE_GUEST_HANDLE_STRUCT(xen_memory_map);
210*35ae11fdSIan Campbell 
211*35ae11fdSIan Campbell /*
212*35ae11fdSIan Campbell  * Returns the real physical memory map. Passes the same structure as
213*35ae11fdSIan Campbell  * XENMEM_memory_map.
214*35ae11fdSIan Campbell  * arg == addr of struct xen_memory_map.
215*35ae11fdSIan Campbell  */
216*35ae11fdSIan Campbell #define XENMEM_machine_memory_map   10
217*35ae11fdSIan Campbell 
21819001c8cSAlex Nixon 
21919001c8cSAlex Nixon /*
22019001c8cSAlex Nixon  * Prevent the balloon driver from changing the memory reservation
22119001c8cSAlex Nixon  * during a driver critical region.
22219001c8cSAlex Nixon  */
22319001c8cSAlex Nixon extern spinlock_t xen_reservation_lock;
224a42089ddSJeremy Fitzhardinge #endif /* __XEN_PUBLIC_MEMORY_H__ */
225