/* SPDX-License-Identifier: MIT */1/******************************************************************************2* memory.h3*4* Memory reservation and information.5*6* Copyright (c) 2005, Keir Fraser <[email protected]>7*/89#ifndef __XEN_PUBLIC_MEMORY_H__10#define __XEN_PUBLIC_MEMORY_H__1112#include <linux/spinlock.h>1314/*15* Increase or decrease the specified domain's memory reservation. Returns a16* -ve errcode on failure, or the # extents successfully allocated or freed.17* arg == addr of struct xen_memory_reservation.18*/19#define XENMEM_increase_reservation 020#define XENMEM_decrease_reservation 121#define XENMEM_populate_physmap 622struct xen_memory_reservation {2324/*25* XENMEM_increase_reservation:26* OUT: MFN (*not* GMFN) bases of extents that were allocated27* XENMEM_decrease_reservation:28* IN: GMFN bases of extents to free29* XENMEM_populate_physmap:30* IN: GPFN bases of extents to populate with memory31* OUT: GMFN bases of extents that were allocated32* (NB. This command also updates the mach_to_phys translation table)33*/34GUEST_HANDLE(xen_pfn_t) extent_start;3536/* Number of extents, and size/alignment of each (2^extent_order pages). */37xen_ulong_t nr_extents;38unsigned int extent_order;3940/*41* Maximum # bits addressable by the user of the allocated region (e.g.,42* I/O devices often have a 32-bit limitation even in 64-bit systems). If43* zero then the user has no addressing restriction.44* This field is not used by XENMEM_decrease_reservation.45*/46unsigned int address_bits;4748/*49* Domain whose reservation is being changed.50* Unprivileged domains can specify only DOMID_SELF.51*/52domid_t domid;5354};55DEFINE_GUEST_HANDLE_STRUCT(xen_memory_reservation);5657/*58* An atomic exchange of memory pages. If return code is zero then59* @out.extent_list provides GMFNs of the newly-allocated memory.60* Returns zero on complete success, otherwise a negative error code.61* On complete success then always @nr_exchanged == @in.nr_extents.62* On partial success @nr_exchanged indicates how much work was done.63*/64#define XENMEM_exchange 1165struct xen_memory_exchange {66/*67* [IN] Details of memory extents to be exchanged (GMFN bases).68* Note that @in.address_bits is ignored and unused.69*/70struct xen_memory_reservation in;7172/*73* [IN/OUT] Details of new memory extents.74* We require that:75* 1. @in.domid == @out.domid76* 2. @in.nr_extents << @in.extent_order ==77* @out.nr_extents << @out.extent_order78* 3. @in.extent_start and @out.extent_start lists must not overlap79* 4. @out.extent_start lists GPFN bases to be populated80* 5. @out.extent_start is overwritten with allocated GMFN bases81*/82struct xen_memory_reservation out;8384/*85* [OUT] Number of input extents that were successfully exchanged:86* 1. The first @nr_exchanged input extents were successfully87* deallocated.88* 2. The corresponding first entries in the output extent list correctly89* indicate the GMFNs that were successfully exchanged.90* 3. All other input and output extents are untouched.91* 4. If not all input exents are exchanged then the return code of this92* command will be non-zero.93* 5. THIS FIELD MUST BE INITIALISED TO ZERO BY THE CALLER!94*/95xen_ulong_t nr_exchanged;96};9798DEFINE_GUEST_HANDLE_STRUCT(xen_memory_exchange);99/*100* Returns the maximum machine frame number of mapped RAM in this system.101* This command always succeeds (it never returns an error code).102* arg == NULL.103*/104#define XENMEM_maximum_ram_page 2105106/*107* Returns the current or maximum memory reservation, in pages, of the108* specified domain (may be DOMID_SELF). Returns -ve errcode on failure.109* arg == addr of domid_t.110*/111#define XENMEM_current_reservation 3112#define XENMEM_maximum_reservation 4113114/*115* Returns a list of MFN bases of 2MB extents comprising the machine_to_phys116* mapping table. Architectures which do not have a m2p table do not implement117* this command.118* arg == addr of xen_machphys_mfn_list_t.119*/120#define XENMEM_machphys_mfn_list 5121struct xen_machphys_mfn_list {122/*123* Size of the 'extent_start' array. Fewer entries will be filled if the124* machphys table is smaller than max_extents * 2MB.125*/126unsigned int max_extents;127128/*129* Pointer to buffer to fill with list of extent starts. If there are130* any large discontiguities in the machine address space, 2MB gaps in131* the machphys table will be represented by an MFN base of zero.132*/133GUEST_HANDLE(xen_pfn_t) extent_start;134135/*136* Number of extents written to the above array. This will be smaller137* than 'max_extents' if the machphys table is smaller than max_e * 2MB.138*/139unsigned int nr_extents;140};141DEFINE_GUEST_HANDLE_STRUCT(xen_machphys_mfn_list);142143/*144* Returns the location in virtual address space of the machine_to_phys145* mapping table. Architectures which do not have a m2p table, or which do not146* map it by default into guest address space, do not implement this command.147* arg == addr of xen_machphys_mapping_t.148*/149#define XENMEM_machphys_mapping 12150struct xen_machphys_mapping {151xen_ulong_t v_start, v_end; /* Start and end virtual addresses. */152xen_ulong_t max_mfn; /* Maximum MFN that can be looked up. */153};154DEFINE_GUEST_HANDLE_STRUCT(xen_machphys_mapping_t);155156#define XENMAPSPACE_shared_info 0 /* shared info page */157#define XENMAPSPACE_grant_table 1 /* grant table page */158#define XENMAPSPACE_gmfn 2 /* GMFN */159#define XENMAPSPACE_gmfn_range 3 /* GMFN range, XENMEM_add_to_physmap only. */160#define XENMAPSPACE_gmfn_foreign 4 /* GMFN from another dom,161* XENMEM_add_to_physmap_range only.162*/163#define XENMAPSPACE_dev_mmio 5 /* device mmio region */164165/*166* Sets the GPFN at which a particular page appears in the specified guest's167* pseudophysical address space.168* arg == addr of xen_add_to_physmap_t.169*/170#define XENMEM_add_to_physmap 7171struct xen_add_to_physmap {172/* Which domain to change the mapping for. */173domid_t domid;174175/* Number of pages to go through for gmfn_range */176uint16_t size;177178/* Source mapping space. */179unsigned int space;180181/* Index into source mapping space. */182xen_ulong_t idx;183184/* GPFN where the source mapping page should appear. */185xen_pfn_t gpfn;186};187DEFINE_GUEST_HANDLE_STRUCT(xen_add_to_physmap);188189/*** REMOVED ***/190/*#define XENMEM_translate_gpfn_list 8*/191192#define XENMEM_add_to_physmap_range 23193struct xen_add_to_physmap_range {194/* IN */195/* Which domain to change the mapping for. */196domid_t domid;197uint16_t space; /* => enum phys_map_space */198199/* Number of pages to go through */200uint16_t size;201domid_t foreign_domid; /* IFF gmfn_foreign */202203/* Indexes into space being mapped. */204GUEST_HANDLE(xen_ulong_t) idxs;205206/* GPFN in domid where the source mapping page should appear. */207GUEST_HANDLE(xen_pfn_t) gpfns;208209/* OUT */210211/* Per index error code. */212GUEST_HANDLE(int) errs;213};214DEFINE_GUEST_HANDLE_STRUCT(xen_add_to_physmap_range);215216/*217* Returns the pseudo-physical memory map as it was when the domain218* was started (specified by XENMEM_set_memory_map).219* arg == addr of struct xen_memory_map.220*/221#define XENMEM_memory_map 9222struct xen_memory_map {223/*224* On call the number of entries which can be stored in buffer. On225* return the number of entries which have been stored in226* buffer.227*/228unsigned int nr_entries;229230/*231* Entries in the buffer are in the same format as returned by the232* BIOS INT 0x15 EAX=0xE820 call.233*/234GUEST_HANDLE(void) buffer;235};236DEFINE_GUEST_HANDLE_STRUCT(xen_memory_map);237238/*239* Returns the real physical memory map. Passes the same structure as240* XENMEM_memory_map.241* arg == addr of struct xen_memory_map.242*/243#define XENMEM_machine_memory_map 10244245246/*247* Unmaps the page appearing at a particular GPFN from the specified guest's248* pseudophysical address space.249* arg == addr of xen_remove_from_physmap_t.250*/251#define XENMEM_remove_from_physmap 15252struct xen_remove_from_physmap {253/* Which domain to change the mapping for. */254domid_t domid;255256/* GPFN of the current mapping of the page. */257xen_pfn_t gpfn;258};259DEFINE_GUEST_HANDLE_STRUCT(xen_remove_from_physmap);260261/*262* Get the pages for a particular guest resource, so that they can be263* mapped directly by a tools domain.264*/265#define XENMEM_acquire_resource 28266struct xen_mem_acquire_resource {267/* IN - The domain whose resource is to be mapped */268domid_t domid;269/* IN - the type of resource */270uint16_t type;271272#define XENMEM_resource_ioreq_server 0273#define XENMEM_resource_grant_table 1274275/*276* IN - a type-specific resource identifier, which must be zero277* unless stated otherwise.278*279* type == XENMEM_resource_ioreq_server -> id == ioreq server id280* type == XENMEM_resource_grant_table -> id defined below281*/282uint32_t id;283284#define XENMEM_resource_grant_table_id_shared 0285#define XENMEM_resource_grant_table_id_status 1286287/* IN/OUT - As an IN parameter number of frames of the resource288* to be mapped. However, if the specified value is 0 and289* frame_list is NULL then this field will be set to the290* maximum value supported by the implementation on return.291*/292uint32_t nr_frames;293/*294* OUT - Must be zero on entry. On return this may contain a bitwise295* OR of the following values.296*/297uint32_t flags;298299/* The resource pages have been assigned to the calling domain */300#define _XENMEM_rsrc_acq_caller_owned 0301#define XENMEM_rsrc_acq_caller_owned (1u << _XENMEM_rsrc_acq_caller_owned)302303/*304* IN - the index of the initial frame to be mapped. This parameter305* is ignored if nr_frames is 0.306*/307uint64_t frame;308309#define XENMEM_resource_ioreq_server_frame_bufioreq 0310#define XENMEM_resource_ioreq_server_frame_ioreq(n) (1 + (n))311312/*313* IN/OUT - If the tools domain is PV then, upon return, frame_list314* will be populated with the MFNs of the resource.315* If the tools domain is HVM then it is expected that, on316* entry, frame_list will be populated with a list of GFNs317* that will be mapped to the MFNs of the resource.318* If -EIO is returned then the frame_list has only been319* partially mapped and it is up to the caller to unmap all320* the GFNs.321* This parameter may be NULL if nr_frames is 0.322*/323GUEST_HANDLE(xen_pfn_t) frame_list;324};325DEFINE_GUEST_HANDLE_STRUCT(xen_mem_acquire_resource);326327#endif /* __XEN_PUBLIC_MEMORY_H__ */328329330