xref: /openbmc/linux/include/xen/interface/memory.h (revision 07d0c943663f82d9682856c0a7db7145a6c911d6)
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      */
34bd3f79b7SStefano Stabellini     GUEST_HANDLE(xen_pfn_t) extent_start;
35a42089ddSJeremy Fitzhardinge 
36a42089ddSJeremy Fitzhardinge     /* Number of extents, and size/alignment of each (2^extent_order pages). */
37256f631fSStefano Stabellini     xen_ulong_t  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      */
95256f631fSStefano Stabellini     xen_ulong_t 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      */
133bd3f79b7SStefano Stabellini     GUEST_HANDLE(xen_pfn_t) 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 /*
1447e77506aSIan Campbell  * Returns the location in virtual address space of the machine_to_phys
1457e77506aSIan Campbell  * mapping table. Architectures which do not have a m2p table, or which do not
1467e77506aSIan Campbell  * map it by default into guest address space, do not implement this command.
1477e77506aSIan Campbell  * arg == addr of xen_machphys_mapping_t.
1487e77506aSIan Campbell  */
1497e77506aSIan Campbell #define XENMEM_machphys_mapping     12
1507e77506aSIan Campbell struct xen_machphys_mapping {
151256f631fSStefano Stabellini     xen_ulong_t v_start, v_end; /* Start and end virtual addresses.   */
152256f631fSStefano Stabellini     xen_ulong_t max_mfn;        /* Maximum MFN that can be looked up. */
1537e77506aSIan Campbell };
1547e77506aSIan Campbell DEFINE_GUEST_HANDLE_STRUCT(xen_machphys_mapping_t);
1557e77506aSIan Campbell 
156f832da06SIan Campbell #define XENMAPSPACE_shared_info  0 /* shared info page */
157f832da06SIan Campbell #define XENMAPSPACE_grant_table  1 /* grant table page */
158f832da06SIan Campbell #define XENMAPSPACE_gmfn         2 /* GMFN */
159f832da06SIan Campbell #define XENMAPSPACE_gmfn_range   3 /* GMFN range, XENMEM_add_to_physmap only. */
160f832da06SIan Campbell #define XENMAPSPACE_gmfn_foreign 4 /* GMFN from another dom,
161f832da06SIan Campbell 				    * XENMEM_add_to_physmap_range only.
162f832da06SIan Campbell 				    */
163f832da06SIan Campbell 
1647e77506aSIan Campbell /*
165a42089ddSJeremy Fitzhardinge  * Sets the GPFN at which a particular page appears in the specified guest's
166a42089ddSJeremy Fitzhardinge  * pseudophysical address space.
167a42089ddSJeremy Fitzhardinge  * arg == addr of xen_add_to_physmap_t.
168a42089ddSJeremy Fitzhardinge  */
169a42089ddSJeremy Fitzhardinge #define XENMEM_add_to_physmap      7
170a42089ddSJeremy Fitzhardinge struct xen_add_to_physmap {
171a42089ddSJeremy Fitzhardinge     /* Which domain to change the mapping for. */
172a42089ddSJeremy Fitzhardinge     domid_t domid;
173a42089ddSJeremy Fitzhardinge 
174b58aaa4bSStefano Stabellini     /* Number of pages to go through for gmfn_range */
175b58aaa4bSStefano Stabellini     uint16_t    size;
176b58aaa4bSStefano Stabellini 
177a42089ddSJeremy Fitzhardinge     /* Source mapping space. */
178a42089ddSJeremy Fitzhardinge     unsigned int space;
179a42089ddSJeremy Fitzhardinge 
180a42089ddSJeremy Fitzhardinge     /* Index into source mapping space. */
181256f631fSStefano Stabellini     xen_ulong_t idx;
182a42089ddSJeremy Fitzhardinge 
183a42089ddSJeremy Fitzhardinge     /* GPFN where the source mapping page should appear. */
184bd3f79b7SStefano Stabellini     xen_pfn_t gpfn;
185a42089ddSJeremy Fitzhardinge };
186bfdab126SIsaku Yamahata DEFINE_GUEST_HANDLE_STRUCT(xen_add_to_physmap);
187a42089ddSJeremy Fitzhardinge 
188e84fe8a1SIan Campbell /*** REMOVED ***/
189e84fe8a1SIan Campbell /*#define XENMEM_translate_gpfn_list  8*/
190a42089ddSJeremy Fitzhardinge 
191f832da06SIan Campbell #define XENMEM_add_to_physmap_range 23
192f832da06SIan Campbell struct xen_add_to_physmap_range {
193*07d0c943SIan Campbell     /* IN */
194f832da06SIan Campbell     /* Which domain to change the mapping for. */
195f832da06SIan Campbell     domid_t domid;
196f832da06SIan Campbell     uint16_t space; /* => enum phys_map_space */
197f832da06SIan Campbell 
198f832da06SIan Campbell     /* Number of pages to go through */
199f832da06SIan Campbell     uint16_t size;
200f832da06SIan Campbell     domid_t foreign_domid; /* IFF gmfn_foreign */
201f832da06SIan Campbell 
202f832da06SIan Campbell     /* Indexes into space being mapped. */
203f832da06SIan Campbell     GUEST_HANDLE(xen_ulong_t) idxs;
204f832da06SIan Campbell 
205f832da06SIan Campbell     /* GPFN in domid where the source mapping page should appear. */
206f832da06SIan Campbell     GUEST_HANDLE(xen_pfn_t) gpfns;
207*07d0c943SIan Campbell 
208*07d0c943SIan Campbell     /* OUT */
209*07d0c943SIan Campbell 
210*07d0c943SIan Campbell     /* Per index error code. */
211*07d0c943SIan Campbell     GUEST_HANDLE(int) errs;
212f832da06SIan Campbell };
213f832da06SIan Campbell DEFINE_GUEST_HANDLE_STRUCT(xen_add_to_physmap_range);
214f832da06SIan Campbell 
21535ae11fdSIan Campbell /*
21635ae11fdSIan Campbell  * Returns the pseudo-physical memory map as it was when the domain
21735ae11fdSIan Campbell  * was started (specified by XENMEM_set_memory_map).
21835ae11fdSIan Campbell  * arg == addr of struct xen_memory_map.
21935ae11fdSIan Campbell  */
22035ae11fdSIan Campbell #define XENMEM_memory_map           9
22135ae11fdSIan Campbell struct xen_memory_map {
22235ae11fdSIan Campbell     /*
22335ae11fdSIan Campbell      * On call the number of entries which can be stored in buffer. On
22435ae11fdSIan Campbell      * return the number of entries which have been stored in
22535ae11fdSIan Campbell      * buffer.
22635ae11fdSIan Campbell      */
22735ae11fdSIan Campbell     unsigned int nr_entries;
22835ae11fdSIan Campbell 
22935ae11fdSIan Campbell     /*
23035ae11fdSIan Campbell      * Entries in the buffer are in the same format as returned by the
23135ae11fdSIan Campbell      * BIOS INT 0x15 EAX=0xE820 call.
23235ae11fdSIan Campbell      */
23335ae11fdSIan Campbell     GUEST_HANDLE(void) buffer;
23435ae11fdSIan Campbell };
23535ae11fdSIan Campbell DEFINE_GUEST_HANDLE_STRUCT(xen_memory_map);
23635ae11fdSIan Campbell 
23735ae11fdSIan Campbell /*
23835ae11fdSIan Campbell  * Returns the real physical memory map. Passes the same structure as
23935ae11fdSIan Campbell  * XENMEM_memory_map.
24035ae11fdSIan Campbell  * arg == addr of struct xen_memory_map.
24135ae11fdSIan Campbell  */
24235ae11fdSIan Campbell #define XENMEM_machine_memory_map   10
24335ae11fdSIan Campbell 
24419001c8cSAlex Nixon 
24519001c8cSAlex Nixon /*
24619001c8cSAlex Nixon  * Prevent the balloon driver from changing the memory reservation
24719001c8cSAlex Nixon  * during a driver critical region.
24819001c8cSAlex Nixon  */
24919001c8cSAlex Nixon extern spinlock_t xen_reservation_lock;
250f832da06SIan Campbell 
251f832da06SIan Campbell /*
252f832da06SIan Campbell  * Unmaps the page appearing at a particular GPFN from the specified guest's
253f832da06SIan Campbell  * pseudophysical address space.
254f832da06SIan Campbell  * arg == addr of xen_remove_from_physmap_t.
255f832da06SIan Campbell  */
256f832da06SIan Campbell #define XENMEM_remove_from_physmap      15
257f832da06SIan Campbell struct xen_remove_from_physmap {
258f832da06SIan Campbell     /* Which domain to change the mapping for. */
259f832da06SIan Campbell     domid_t domid;
260f832da06SIan Campbell 
261f832da06SIan Campbell     /* GPFN of the current mapping of the page. */
262f832da06SIan Campbell     xen_pfn_t gpfn;
263f832da06SIan Campbell };
264f832da06SIan Campbell DEFINE_GUEST_HANDLE_STRUCT(xen_remove_from_physmap);
265f832da06SIan Campbell 
266a42089ddSJeremy Fitzhardinge #endif /* __XEN_PUBLIC_MEMORY_H__ */
267