xref: /openbmc/linux/include/xen/interface/memory.h (revision e84fe8a138fb1aa7aec8ef2fafb312ea5eb0f3dd)
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 
1567e77506aSIan Campbell /*
157a42089ddSJeremy Fitzhardinge  * Sets the GPFN at which a particular page appears in the specified guest's
158a42089ddSJeremy Fitzhardinge  * pseudophysical address space.
159a42089ddSJeremy Fitzhardinge  * arg == addr of xen_add_to_physmap_t.
160a42089ddSJeremy Fitzhardinge  */
161a42089ddSJeremy Fitzhardinge #define XENMEM_add_to_physmap      7
162a42089ddSJeremy Fitzhardinge struct xen_add_to_physmap {
163a42089ddSJeremy Fitzhardinge     /* Which domain to change the mapping for. */
164a42089ddSJeremy Fitzhardinge     domid_t domid;
165a42089ddSJeremy Fitzhardinge 
166b58aaa4bSStefano Stabellini     /* Number of pages to go through for gmfn_range */
167b58aaa4bSStefano Stabellini     uint16_t    size;
168b58aaa4bSStefano Stabellini 
169a42089ddSJeremy Fitzhardinge     /* Source mapping space. */
170a42089ddSJeremy Fitzhardinge #define XENMAPSPACE_shared_info 0 /* shared info page */
171a42089ddSJeremy Fitzhardinge #define XENMAPSPACE_grant_table 1 /* grant table page */
172a42089ddSJeremy Fitzhardinge     unsigned int space;
173a42089ddSJeremy Fitzhardinge 
174a42089ddSJeremy Fitzhardinge     /* Index into source mapping space. */
175256f631fSStefano Stabellini     xen_ulong_t idx;
176a42089ddSJeremy Fitzhardinge 
177a42089ddSJeremy Fitzhardinge     /* GPFN where the source mapping page should appear. */
178bd3f79b7SStefano Stabellini     xen_pfn_t gpfn;
179a42089ddSJeremy Fitzhardinge };
180bfdab126SIsaku Yamahata DEFINE_GUEST_HANDLE_STRUCT(xen_add_to_physmap);
181a42089ddSJeremy Fitzhardinge 
182*e84fe8a1SIan Campbell /*** REMOVED ***/
183*e84fe8a1SIan Campbell /*#define XENMEM_translate_gpfn_list  8*/
184a42089ddSJeremy Fitzhardinge 
18535ae11fdSIan Campbell /*
18635ae11fdSIan Campbell  * Returns the pseudo-physical memory map as it was when the domain
18735ae11fdSIan Campbell  * was started (specified by XENMEM_set_memory_map).
18835ae11fdSIan Campbell  * arg == addr of struct xen_memory_map.
18935ae11fdSIan Campbell  */
19035ae11fdSIan Campbell #define XENMEM_memory_map           9
19135ae11fdSIan Campbell struct xen_memory_map {
19235ae11fdSIan Campbell     /*
19335ae11fdSIan Campbell      * On call the number of entries which can be stored in buffer. On
19435ae11fdSIan Campbell      * return the number of entries which have been stored in
19535ae11fdSIan Campbell      * buffer.
19635ae11fdSIan Campbell      */
19735ae11fdSIan Campbell     unsigned int nr_entries;
19835ae11fdSIan Campbell 
19935ae11fdSIan Campbell     /*
20035ae11fdSIan Campbell      * Entries in the buffer are in the same format as returned by the
20135ae11fdSIan Campbell      * BIOS INT 0x15 EAX=0xE820 call.
20235ae11fdSIan Campbell      */
20335ae11fdSIan Campbell     GUEST_HANDLE(void) buffer;
20435ae11fdSIan Campbell };
20535ae11fdSIan Campbell DEFINE_GUEST_HANDLE_STRUCT(xen_memory_map);
20635ae11fdSIan Campbell 
20735ae11fdSIan Campbell /*
20835ae11fdSIan Campbell  * Returns the real physical memory map. Passes the same structure as
20935ae11fdSIan Campbell  * XENMEM_memory_map.
21035ae11fdSIan Campbell  * arg == addr of struct xen_memory_map.
21135ae11fdSIan Campbell  */
21235ae11fdSIan Campbell #define XENMEM_machine_memory_map   10
21335ae11fdSIan Campbell 
21419001c8cSAlex Nixon 
21519001c8cSAlex Nixon /*
21619001c8cSAlex Nixon  * Prevent the balloon driver from changing the memory reservation
21719001c8cSAlex Nixon  * during a driver critical region.
21819001c8cSAlex Nixon  */
21919001c8cSAlex Nixon extern spinlock_t xen_reservation_lock;
220a42089ddSJeremy Fitzhardinge #endif /* __XEN_PUBLIC_MEMORY_H__ */
221