xref: /openbmc/linux/include/xen/interface/memory.h (revision 03ab8e6297acd1bc0eedaa050e2a1635c576fd11)
1*9e2b3e83SJuergen Gross /* SPDX-License-Identifier: MIT */
2a42089ddSJeremy Fitzhardinge /******************************************************************************
3a42089ddSJeremy Fitzhardinge  * memory.h
4a42089ddSJeremy Fitzhardinge  *
5a42089ddSJeremy Fitzhardinge  * Memory reservation and information.
6a42089ddSJeremy Fitzhardinge  *
7a42089ddSJeremy Fitzhardinge  * Copyright (c) 2005, Keir Fraser <keir@xensource.com>
8a42089ddSJeremy Fitzhardinge  */
9a42089ddSJeremy Fitzhardinge 
10a42089ddSJeremy Fitzhardinge #ifndef __XEN_PUBLIC_MEMORY_H__
11a42089ddSJeremy Fitzhardinge #define __XEN_PUBLIC_MEMORY_H__
12a42089ddSJeremy Fitzhardinge 
1319001c8cSAlex Nixon #include <linux/spinlock.h>
1419001c8cSAlex Nixon 
15a42089ddSJeremy Fitzhardinge /*
16a42089ddSJeremy Fitzhardinge  * Increase or decrease the specified domain's memory reservation. Returns a
17a42089ddSJeremy Fitzhardinge  * -ve errcode on failure, or the # extents successfully allocated or freed.
18a42089ddSJeremy Fitzhardinge  * arg == addr of struct xen_memory_reservation.
19a42089ddSJeremy Fitzhardinge  */
20a42089ddSJeremy Fitzhardinge #define XENMEM_increase_reservation 0
21a42089ddSJeremy Fitzhardinge #define XENMEM_decrease_reservation 1
22a42089ddSJeremy Fitzhardinge #define XENMEM_populate_physmap     6
23a42089ddSJeremy Fitzhardinge struct xen_memory_reservation {
24a42089ddSJeremy Fitzhardinge 
25a42089ddSJeremy Fitzhardinge     /*
26a42089ddSJeremy Fitzhardinge      * XENMEM_increase_reservation:
27a42089ddSJeremy Fitzhardinge      *   OUT: MFN (*not* GMFN) bases of extents that were allocated
28a42089ddSJeremy Fitzhardinge      * XENMEM_decrease_reservation:
29a42089ddSJeremy Fitzhardinge      *   IN:  GMFN bases of extents to free
30a42089ddSJeremy Fitzhardinge      * XENMEM_populate_physmap:
31a42089ddSJeremy Fitzhardinge      *   IN:  GPFN bases of extents to populate with memory
32a42089ddSJeremy Fitzhardinge      *   OUT: GMFN bases of extents that were allocated
33a42089ddSJeremy Fitzhardinge      *   (NB. This command also updates the mach_to_phys translation table)
34a42089ddSJeremy Fitzhardinge      */
35bd3f79b7SStefano Stabellini     GUEST_HANDLE(xen_pfn_t) extent_start;
36a42089ddSJeremy Fitzhardinge 
37a42089ddSJeremy Fitzhardinge     /* Number of extents, and size/alignment of each (2^extent_order pages). */
38256f631fSStefano Stabellini     xen_ulong_t  nr_extents;
39a42089ddSJeremy Fitzhardinge     unsigned int   extent_order;
40a42089ddSJeremy Fitzhardinge 
41a42089ddSJeremy Fitzhardinge     /*
42a42089ddSJeremy Fitzhardinge      * Maximum # bits addressable by the user of the allocated region (e.g.,
43a42089ddSJeremy Fitzhardinge      * I/O devices often have a 32-bit limitation even in 64-bit systems). If
44a42089ddSJeremy Fitzhardinge      * zero then the user has no addressing restriction.
45a42089ddSJeremy Fitzhardinge      * This field is not used by XENMEM_decrease_reservation.
46a42089ddSJeremy Fitzhardinge      */
47a42089ddSJeremy Fitzhardinge     unsigned int   address_bits;
48a42089ddSJeremy Fitzhardinge 
49a42089ddSJeremy Fitzhardinge     /*
50a42089ddSJeremy Fitzhardinge      * Domain whose reservation is being changed.
51a42089ddSJeremy Fitzhardinge      * Unprivileged domains can specify only DOMID_SELF.
52a42089ddSJeremy Fitzhardinge      */
53a42089ddSJeremy Fitzhardinge     domid_t        domid;
54a42089ddSJeremy Fitzhardinge 
55a42089ddSJeremy Fitzhardinge };
56bfdab126SIsaku Yamahata DEFINE_GUEST_HANDLE_STRUCT(xen_memory_reservation);
57a42089ddSJeremy Fitzhardinge 
58a42089ddSJeremy Fitzhardinge /*
5908bbc9daSAlex Nixon  * An atomic exchange of memory pages. If return code is zero then
6008bbc9daSAlex Nixon  * @out.extent_list provides GMFNs of the newly-allocated memory.
6108bbc9daSAlex Nixon  * Returns zero on complete success, otherwise a negative error code.
6208bbc9daSAlex Nixon  * On complete success then always @nr_exchanged == @in.nr_extents.
6308bbc9daSAlex Nixon  * On partial success @nr_exchanged indicates how much work was done.
6408bbc9daSAlex Nixon  */
6508bbc9daSAlex Nixon #define XENMEM_exchange             11
6608bbc9daSAlex Nixon struct xen_memory_exchange {
6708bbc9daSAlex Nixon     /*
6808bbc9daSAlex Nixon      * [IN] Details of memory extents to be exchanged (GMFN bases).
6908bbc9daSAlex Nixon      * Note that @in.address_bits is ignored and unused.
7008bbc9daSAlex Nixon      */
7108bbc9daSAlex Nixon     struct xen_memory_reservation in;
7208bbc9daSAlex Nixon 
7308bbc9daSAlex Nixon     /*
7408bbc9daSAlex Nixon      * [IN/OUT] Details of new memory extents.
7508bbc9daSAlex Nixon      * We require that:
7608bbc9daSAlex Nixon      *  1. @in.domid == @out.domid
7708bbc9daSAlex Nixon      *  2. @in.nr_extents  << @in.extent_order ==
7808bbc9daSAlex Nixon      *     @out.nr_extents << @out.extent_order
7908bbc9daSAlex Nixon      *  3. @in.extent_start and @out.extent_start lists must not overlap
8008bbc9daSAlex Nixon      *  4. @out.extent_start lists GPFN bases to be populated
8108bbc9daSAlex Nixon      *  5. @out.extent_start is overwritten with allocated GMFN bases
8208bbc9daSAlex Nixon      */
8308bbc9daSAlex Nixon     struct xen_memory_reservation out;
8408bbc9daSAlex Nixon 
8508bbc9daSAlex Nixon     /*
8608bbc9daSAlex Nixon      * [OUT] Number of input extents that were successfully exchanged:
8708bbc9daSAlex Nixon      *  1. The first @nr_exchanged input extents were successfully
8808bbc9daSAlex Nixon      *     deallocated.
8908bbc9daSAlex Nixon      *  2. The corresponding first entries in the output extent list correctly
9008bbc9daSAlex Nixon      *     indicate the GMFNs that were successfully exchanged.
9108bbc9daSAlex Nixon      *  3. All other input and output extents are untouched.
9208bbc9daSAlex Nixon      *  4. If not all input exents are exchanged then the return code of this
9308bbc9daSAlex Nixon      *     command will be non-zero.
9408bbc9daSAlex Nixon      *  5. THIS FIELD MUST BE INITIALISED TO ZERO BY THE CALLER!
9508bbc9daSAlex Nixon      */
96256f631fSStefano Stabellini     xen_ulong_t nr_exchanged;
9708bbc9daSAlex Nixon };
9808bbc9daSAlex Nixon 
9908bbc9daSAlex Nixon DEFINE_GUEST_HANDLE_STRUCT(xen_memory_exchange);
10008bbc9daSAlex Nixon /*
101a42089ddSJeremy Fitzhardinge  * Returns the maximum machine frame number of mapped RAM in this system.
102a42089ddSJeremy Fitzhardinge  * This command always succeeds (it never returns an error code).
103a42089ddSJeremy Fitzhardinge  * arg == NULL.
104a42089ddSJeremy Fitzhardinge  */
105a42089ddSJeremy Fitzhardinge #define XENMEM_maximum_ram_page     2
106a42089ddSJeremy Fitzhardinge 
107a42089ddSJeremy Fitzhardinge /*
108a42089ddSJeremy Fitzhardinge  * Returns the current or maximum memory reservation, in pages, of the
109a42089ddSJeremy Fitzhardinge  * specified domain (may be DOMID_SELF). Returns -ve errcode on failure.
110a42089ddSJeremy Fitzhardinge  * arg == addr of domid_t.
111a42089ddSJeremy Fitzhardinge  */
112a42089ddSJeremy Fitzhardinge #define XENMEM_current_reservation  3
113a42089ddSJeremy Fitzhardinge #define XENMEM_maximum_reservation  4
114a42089ddSJeremy Fitzhardinge 
115a42089ddSJeremy Fitzhardinge /*
116a42089ddSJeremy Fitzhardinge  * Returns a list of MFN bases of 2MB extents comprising the machine_to_phys
117a42089ddSJeremy Fitzhardinge  * mapping table. Architectures which do not have a m2p table do not implement
118a42089ddSJeremy Fitzhardinge  * this command.
119a42089ddSJeremy Fitzhardinge  * arg == addr of xen_machphys_mfn_list_t.
120a42089ddSJeremy Fitzhardinge  */
121a42089ddSJeremy Fitzhardinge #define XENMEM_machphys_mfn_list    5
122a42089ddSJeremy Fitzhardinge struct xen_machphys_mfn_list {
123a42089ddSJeremy Fitzhardinge     /*
124a42089ddSJeremy Fitzhardinge      * Size of the 'extent_start' array. Fewer entries will be filled if the
125a42089ddSJeremy Fitzhardinge      * machphys table is smaller than max_extents * 2MB.
126a42089ddSJeremy Fitzhardinge      */
127a42089ddSJeremy Fitzhardinge     unsigned int max_extents;
128a42089ddSJeremy Fitzhardinge 
129a42089ddSJeremy Fitzhardinge     /*
130a42089ddSJeremy Fitzhardinge      * Pointer to buffer to fill with list of extent starts. If there are
131a42089ddSJeremy Fitzhardinge      * any large discontiguities in the machine address space, 2MB gaps in
132a42089ddSJeremy Fitzhardinge      * the machphys table will be represented by an MFN base of zero.
133a42089ddSJeremy Fitzhardinge      */
134bd3f79b7SStefano Stabellini     GUEST_HANDLE(xen_pfn_t) extent_start;
135a42089ddSJeremy Fitzhardinge 
136a42089ddSJeremy Fitzhardinge     /*
137a42089ddSJeremy Fitzhardinge      * Number of extents written to the above array. This will be smaller
138a42089ddSJeremy Fitzhardinge      * than 'max_extents' if the machphys table is smaller than max_e * 2MB.
139a42089ddSJeremy Fitzhardinge      */
140a42089ddSJeremy Fitzhardinge     unsigned int nr_extents;
141a42089ddSJeremy Fitzhardinge };
142bfdab126SIsaku Yamahata DEFINE_GUEST_HANDLE_STRUCT(xen_machphys_mfn_list);
143a42089ddSJeremy Fitzhardinge 
144a42089ddSJeremy Fitzhardinge /*
1457e77506aSIan Campbell  * Returns the location in virtual address space of the machine_to_phys
1467e77506aSIan Campbell  * mapping table. Architectures which do not have a m2p table, or which do not
1477e77506aSIan Campbell  * map it by default into guest address space, do not implement this command.
1487e77506aSIan Campbell  * arg == addr of xen_machphys_mapping_t.
1497e77506aSIan Campbell  */
1507e77506aSIan Campbell #define XENMEM_machphys_mapping     12
1517e77506aSIan Campbell struct xen_machphys_mapping {
152256f631fSStefano Stabellini     xen_ulong_t v_start, v_end; /* Start and end virtual addresses.   */
153256f631fSStefano Stabellini     xen_ulong_t max_mfn;        /* Maximum MFN that can be looked up. */
1547e77506aSIan Campbell };
1557e77506aSIan Campbell DEFINE_GUEST_HANDLE_STRUCT(xen_machphys_mapping_t);
1567e77506aSIan Campbell 
157f832da06SIan Campbell #define XENMAPSPACE_shared_info  0 /* shared info page */
158f832da06SIan Campbell #define XENMAPSPACE_grant_table  1 /* grant table page */
159f832da06SIan Campbell #define XENMAPSPACE_gmfn         2 /* GMFN */
160f832da06SIan Campbell #define XENMAPSPACE_gmfn_range   3 /* GMFN range, XENMEM_add_to_physmap only. */
161f832da06SIan Campbell #define XENMAPSPACE_gmfn_foreign 4 /* GMFN from another dom,
162f832da06SIan Campbell 				    * XENMEM_add_to_physmap_range only.
163f832da06SIan Campbell 				    */
164712a5b77SShannon Zhao #define XENMAPSPACE_dev_mmio     5 /* device mmio region */
165f832da06SIan Campbell 
1667e77506aSIan Campbell /*
167a42089ddSJeremy Fitzhardinge  * Sets the GPFN at which a particular page appears in the specified guest's
168a42089ddSJeremy Fitzhardinge  * pseudophysical address space.
169a42089ddSJeremy Fitzhardinge  * arg == addr of xen_add_to_physmap_t.
170a42089ddSJeremy Fitzhardinge  */
171a42089ddSJeremy Fitzhardinge #define XENMEM_add_to_physmap      7
172a42089ddSJeremy Fitzhardinge struct xen_add_to_physmap {
173a42089ddSJeremy Fitzhardinge     /* Which domain to change the mapping for. */
174a42089ddSJeremy Fitzhardinge     domid_t domid;
175a42089ddSJeremy Fitzhardinge 
176b58aaa4bSStefano Stabellini     /* Number of pages to go through for gmfn_range */
177b58aaa4bSStefano Stabellini     uint16_t    size;
178b58aaa4bSStefano Stabellini 
179a42089ddSJeremy Fitzhardinge     /* Source mapping space. */
180a42089ddSJeremy Fitzhardinge     unsigned int space;
181a42089ddSJeremy Fitzhardinge 
182a42089ddSJeremy Fitzhardinge     /* Index into source mapping space. */
183256f631fSStefano Stabellini     xen_ulong_t idx;
184a42089ddSJeremy Fitzhardinge 
185a42089ddSJeremy Fitzhardinge     /* GPFN where the source mapping page should appear. */
186bd3f79b7SStefano Stabellini     xen_pfn_t gpfn;
187a42089ddSJeremy Fitzhardinge };
188bfdab126SIsaku Yamahata DEFINE_GUEST_HANDLE_STRUCT(xen_add_to_physmap);
189a42089ddSJeremy Fitzhardinge 
190e84fe8a1SIan Campbell /*** REMOVED ***/
191e84fe8a1SIan Campbell /*#define XENMEM_translate_gpfn_list  8*/
192a42089ddSJeremy Fitzhardinge 
193f832da06SIan Campbell #define XENMEM_add_to_physmap_range 23
194f832da06SIan Campbell struct xen_add_to_physmap_range {
19507d0c943SIan Campbell     /* IN */
196f832da06SIan Campbell     /* Which domain to change the mapping for. */
197f832da06SIan Campbell     domid_t domid;
198f832da06SIan Campbell     uint16_t space; /* => enum phys_map_space */
199f832da06SIan Campbell 
200f832da06SIan Campbell     /* Number of pages to go through */
201f832da06SIan Campbell     uint16_t size;
202f832da06SIan Campbell     domid_t foreign_domid; /* IFF gmfn_foreign */
203f832da06SIan Campbell 
204f832da06SIan Campbell     /* Indexes into space being mapped. */
205f832da06SIan Campbell     GUEST_HANDLE(xen_ulong_t) idxs;
206f832da06SIan Campbell 
207f832da06SIan Campbell     /* GPFN in domid where the source mapping page should appear. */
208f832da06SIan Campbell     GUEST_HANDLE(xen_pfn_t) gpfns;
20907d0c943SIan Campbell 
21007d0c943SIan Campbell     /* OUT */
21107d0c943SIan Campbell 
21207d0c943SIan Campbell     /* Per index error code. */
21307d0c943SIan Campbell     GUEST_HANDLE(int) errs;
214f832da06SIan Campbell };
215f832da06SIan Campbell DEFINE_GUEST_HANDLE_STRUCT(xen_add_to_physmap_range);
216f832da06SIan Campbell 
21735ae11fdSIan Campbell /*
21835ae11fdSIan Campbell  * Returns the pseudo-physical memory map as it was when the domain
21935ae11fdSIan Campbell  * was started (specified by XENMEM_set_memory_map).
22035ae11fdSIan Campbell  * arg == addr of struct xen_memory_map.
22135ae11fdSIan Campbell  */
22235ae11fdSIan Campbell #define XENMEM_memory_map           9
22335ae11fdSIan Campbell struct xen_memory_map {
22435ae11fdSIan Campbell     /*
22535ae11fdSIan Campbell      * On call the number of entries which can be stored in buffer. On
22635ae11fdSIan Campbell      * return the number of entries which have been stored in
22735ae11fdSIan Campbell      * buffer.
22835ae11fdSIan Campbell      */
22935ae11fdSIan Campbell     unsigned int nr_entries;
23035ae11fdSIan Campbell 
23135ae11fdSIan Campbell     /*
23235ae11fdSIan Campbell      * Entries in the buffer are in the same format as returned by the
23335ae11fdSIan Campbell      * BIOS INT 0x15 EAX=0xE820 call.
23435ae11fdSIan Campbell      */
23535ae11fdSIan Campbell     GUEST_HANDLE(void) buffer;
23635ae11fdSIan Campbell };
23735ae11fdSIan Campbell DEFINE_GUEST_HANDLE_STRUCT(xen_memory_map);
23835ae11fdSIan Campbell 
23935ae11fdSIan Campbell /*
24035ae11fdSIan Campbell  * Returns the real physical memory map. Passes the same structure as
24135ae11fdSIan Campbell  * XENMEM_memory_map.
24235ae11fdSIan Campbell  * arg == addr of struct xen_memory_map.
24335ae11fdSIan Campbell  */
24435ae11fdSIan Campbell #define XENMEM_machine_memory_map   10
24535ae11fdSIan Campbell 
24619001c8cSAlex Nixon 
24719001c8cSAlex Nixon /*
248f832da06SIan Campbell  * Unmaps the page appearing at a particular GPFN from the specified guest's
249f832da06SIan Campbell  * pseudophysical address space.
250f832da06SIan Campbell  * arg == addr of xen_remove_from_physmap_t.
251f832da06SIan Campbell  */
252f832da06SIan Campbell #define XENMEM_remove_from_physmap      15
253f832da06SIan Campbell struct xen_remove_from_physmap {
254f832da06SIan Campbell     /* Which domain to change the mapping for. */
255f832da06SIan Campbell     domid_t domid;
256f832da06SIan Campbell 
257f832da06SIan Campbell     /* GPFN of the current mapping of the page. */
258f832da06SIan Campbell     xen_pfn_t gpfn;
259f832da06SIan Campbell };
260f832da06SIan Campbell DEFINE_GUEST_HANDLE_STRUCT(xen_remove_from_physmap);
261f832da06SIan Campbell 
2623ad08765SPaul Durrant /*
2633ad08765SPaul Durrant  * Get the pages for a particular guest resource, so that they can be
2643ad08765SPaul Durrant  * mapped directly by a tools domain.
2653ad08765SPaul Durrant  */
2663ad08765SPaul Durrant #define XENMEM_acquire_resource 28
2673ad08765SPaul Durrant struct xen_mem_acquire_resource {
2683ad08765SPaul Durrant     /* IN - The domain whose resource is to be mapped */
2693ad08765SPaul Durrant     domid_t domid;
2703ad08765SPaul Durrant     /* IN - the type of resource */
2713ad08765SPaul Durrant     uint16_t type;
2723ad08765SPaul Durrant 
2733ad08765SPaul Durrant #define XENMEM_resource_ioreq_server 0
2743ad08765SPaul Durrant #define XENMEM_resource_grant_table 1
2753ad08765SPaul Durrant 
2763ad08765SPaul Durrant     /*
2773ad08765SPaul Durrant      * IN - a type-specific resource identifier, which must be zero
2783ad08765SPaul Durrant      *      unless stated otherwise.
2793ad08765SPaul Durrant      *
2803ad08765SPaul Durrant      * type == XENMEM_resource_ioreq_server -> id == ioreq server id
2813ad08765SPaul Durrant      * type == XENMEM_resource_grant_table -> id defined below
2823ad08765SPaul Durrant      */
2833ad08765SPaul Durrant     uint32_t id;
2843ad08765SPaul Durrant 
2853ad08765SPaul Durrant #define XENMEM_resource_grant_table_id_shared 0
2863ad08765SPaul Durrant #define XENMEM_resource_grant_table_id_status 1
2873ad08765SPaul Durrant 
2883ad08765SPaul Durrant     /* IN/OUT - As an IN parameter number of frames of the resource
2893ad08765SPaul Durrant      *          to be mapped. However, if the specified value is 0 and
2903ad08765SPaul Durrant      *          frame_list is NULL then this field will be set to the
2913ad08765SPaul Durrant      *          maximum value supported by the implementation on return.
2923ad08765SPaul Durrant      */
2933ad08765SPaul Durrant     uint32_t nr_frames;
2943ad08765SPaul Durrant     /*
2953ad08765SPaul Durrant      * OUT - Must be zero on entry. On return this may contain a bitwise
2963ad08765SPaul Durrant      *       OR of the following values.
2973ad08765SPaul Durrant      */
2983ad08765SPaul Durrant     uint32_t flags;
2993ad08765SPaul Durrant 
3003ad08765SPaul Durrant     /* The resource pages have been assigned to the calling domain */
3013ad08765SPaul Durrant #define _XENMEM_rsrc_acq_caller_owned 0
3023ad08765SPaul Durrant #define XENMEM_rsrc_acq_caller_owned (1u << _XENMEM_rsrc_acq_caller_owned)
3033ad08765SPaul Durrant 
3043ad08765SPaul Durrant     /*
3053ad08765SPaul Durrant      * IN - the index of the initial frame to be mapped. This parameter
3063ad08765SPaul Durrant      *      is ignored if nr_frames is 0.
3073ad08765SPaul Durrant      */
3083ad08765SPaul Durrant     uint64_t frame;
3093ad08765SPaul Durrant 
3103ad08765SPaul Durrant #define XENMEM_resource_ioreq_server_frame_bufioreq 0
3113ad08765SPaul Durrant #define XENMEM_resource_ioreq_server_frame_ioreq(n) (1 + (n))
3123ad08765SPaul Durrant 
3133ad08765SPaul Durrant     /*
3143ad08765SPaul Durrant      * IN/OUT - If the tools domain is PV then, upon return, frame_list
3153ad08765SPaul Durrant      *          will be populated with the MFNs of the resource.
3163ad08765SPaul Durrant      *          If the tools domain is HVM then it is expected that, on
3173ad08765SPaul Durrant      *          entry, frame_list will be populated with a list of GFNs
3183ad08765SPaul Durrant      *          that will be mapped to the MFNs of the resource.
3193ad08765SPaul Durrant      *          If -EIO is returned then the frame_list has only been
3203ad08765SPaul Durrant      *          partially mapped and it is up to the caller to unmap all
3213ad08765SPaul Durrant      *          the GFNs.
3223ad08765SPaul Durrant      *          This parameter may be NULL if nr_frames is 0.
3233ad08765SPaul Durrant      */
3243ad08765SPaul Durrant     GUEST_HANDLE(xen_pfn_t) frame_list;
3253ad08765SPaul Durrant };
3263ad08765SPaul Durrant DEFINE_GUEST_HANDLE_STRUCT(xen_mem_acquire_resource);
3273ad08765SPaul Durrant 
328a42089ddSJeremy Fitzhardinge #endif /* __XEN_PUBLIC_MEMORY_H__ */
329