Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: MIT */
0002 /******************************************************************************
0003  * memory.h
0004  *
0005  * Memory reservation and information.
0006  *
0007  * Copyright (c) 2005, Keir Fraser <keir@xensource.com>
0008  */
0009 
0010 #ifndef __XEN_PUBLIC_MEMORY_H__
0011 #define __XEN_PUBLIC_MEMORY_H__
0012 
0013 #include <linux/spinlock.h>
0014 
0015 /*
0016  * Increase or decrease the specified domain's memory reservation. Returns a
0017  * -ve errcode on failure, or the # extents successfully allocated or freed.
0018  * arg == addr of struct xen_memory_reservation.
0019  */
0020 #define XENMEM_increase_reservation 0
0021 #define XENMEM_decrease_reservation 1
0022 #define XENMEM_populate_physmap     6
0023 struct xen_memory_reservation {
0024 
0025     /*
0026      * XENMEM_increase_reservation:
0027      *   OUT: MFN (*not* GMFN) bases of extents that were allocated
0028      * XENMEM_decrease_reservation:
0029      *   IN:  GMFN bases of extents to free
0030      * XENMEM_populate_physmap:
0031      *   IN:  GPFN bases of extents to populate with memory
0032      *   OUT: GMFN bases of extents that were allocated
0033      *   (NB. This command also updates the mach_to_phys translation table)
0034      */
0035     GUEST_HANDLE(xen_pfn_t) extent_start;
0036 
0037     /* Number of extents, and size/alignment of each (2^extent_order pages). */
0038     xen_ulong_t  nr_extents;
0039     unsigned int   extent_order;
0040 
0041     /*
0042      * Maximum # bits addressable by the user of the allocated region (e.g.,
0043      * I/O devices often have a 32-bit limitation even in 64-bit systems). If
0044      * zero then the user has no addressing restriction.
0045      * This field is not used by XENMEM_decrease_reservation.
0046      */
0047     unsigned int   address_bits;
0048 
0049     /*
0050      * Domain whose reservation is being changed.
0051      * Unprivileged domains can specify only DOMID_SELF.
0052      */
0053     domid_t        domid;
0054 
0055 };
0056 DEFINE_GUEST_HANDLE_STRUCT(xen_memory_reservation);
0057 
0058 /*
0059  * An atomic exchange of memory pages. If return code is zero then
0060  * @out.extent_list provides GMFNs of the newly-allocated memory.
0061  * Returns zero on complete success, otherwise a negative error code.
0062  * On complete success then always @nr_exchanged == @in.nr_extents.
0063  * On partial success @nr_exchanged indicates how much work was done.
0064  */
0065 #define XENMEM_exchange             11
0066 struct xen_memory_exchange {
0067     /*
0068      * [IN] Details of memory extents to be exchanged (GMFN bases).
0069      * Note that @in.address_bits is ignored and unused.
0070      */
0071     struct xen_memory_reservation in;
0072 
0073     /*
0074      * [IN/OUT] Details of new memory extents.
0075      * We require that:
0076      *  1. @in.domid == @out.domid
0077      *  2. @in.nr_extents  << @in.extent_order ==
0078      *     @out.nr_extents << @out.extent_order
0079      *  3. @in.extent_start and @out.extent_start lists must not overlap
0080      *  4. @out.extent_start lists GPFN bases to be populated
0081      *  5. @out.extent_start is overwritten with allocated GMFN bases
0082      */
0083     struct xen_memory_reservation out;
0084 
0085     /*
0086      * [OUT] Number of input extents that were successfully exchanged:
0087      *  1. The first @nr_exchanged input extents were successfully
0088      *     deallocated.
0089      *  2. The corresponding first entries in the output extent list correctly
0090      *     indicate the GMFNs that were successfully exchanged.
0091      *  3. All other input and output extents are untouched.
0092      *  4. If not all input exents are exchanged then the return code of this
0093      *     command will be non-zero.
0094      *  5. THIS FIELD MUST BE INITIALISED TO ZERO BY THE CALLER!
0095      */
0096     xen_ulong_t nr_exchanged;
0097 };
0098 
0099 DEFINE_GUEST_HANDLE_STRUCT(xen_memory_exchange);
0100 /*
0101  * Returns the maximum machine frame number of mapped RAM in this system.
0102  * This command always succeeds (it never returns an error code).
0103  * arg == NULL.
0104  */
0105 #define XENMEM_maximum_ram_page     2
0106 
0107 /*
0108  * Returns the current or maximum memory reservation, in pages, of the
0109  * specified domain (may be DOMID_SELF). Returns -ve errcode on failure.
0110  * arg == addr of domid_t.
0111  */
0112 #define XENMEM_current_reservation  3
0113 #define XENMEM_maximum_reservation  4
0114 
0115 /*
0116  * Returns a list of MFN bases of 2MB extents comprising the machine_to_phys
0117  * mapping table. Architectures which do not have a m2p table do not implement
0118  * this command.
0119  * arg == addr of xen_machphys_mfn_list_t.
0120  */
0121 #define XENMEM_machphys_mfn_list    5
0122 struct xen_machphys_mfn_list {
0123     /*
0124      * Size of the 'extent_start' array. Fewer entries will be filled if the
0125      * machphys table is smaller than max_extents * 2MB.
0126      */
0127     unsigned int max_extents;
0128 
0129     /*
0130      * Pointer to buffer to fill with list of extent starts. If there are
0131      * any large discontiguities in the machine address space, 2MB gaps in
0132      * the machphys table will be represented by an MFN base of zero.
0133      */
0134     GUEST_HANDLE(xen_pfn_t) extent_start;
0135 
0136     /*
0137      * Number of extents written to the above array. This will be smaller
0138      * than 'max_extents' if the machphys table is smaller than max_e * 2MB.
0139      */
0140     unsigned int nr_extents;
0141 };
0142 DEFINE_GUEST_HANDLE_STRUCT(xen_machphys_mfn_list);
0143 
0144 /*
0145  * Returns the location in virtual address space of the machine_to_phys
0146  * mapping table. Architectures which do not have a m2p table, or which do not
0147  * map it by default into guest address space, do not implement this command.
0148  * arg == addr of xen_machphys_mapping_t.
0149  */
0150 #define XENMEM_machphys_mapping     12
0151 struct xen_machphys_mapping {
0152     xen_ulong_t v_start, v_end; /* Start and end virtual addresses.   */
0153     xen_ulong_t max_mfn;        /* Maximum MFN that can be looked up. */
0154 };
0155 DEFINE_GUEST_HANDLE_STRUCT(xen_machphys_mapping_t);
0156 
0157 #define XENMAPSPACE_shared_info  0 /* shared info page */
0158 #define XENMAPSPACE_grant_table  1 /* grant table page */
0159 #define XENMAPSPACE_gmfn         2 /* GMFN */
0160 #define XENMAPSPACE_gmfn_range   3 /* GMFN range, XENMEM_add_to_physmap only. */
0161 #define XENMAPSPACE_gmfn_foreign 4 /* GMFN from another dom,
0162                     * XENMEM_add_to_physmap_range only.
0163                     */
0164 #define XENMAPSPACE_dev_mmio     5 /* device mmio region */
0165 
0166 /*
0167  * Sets the GPFN at which a particular page appears in the specified guest's
0168  * pseudophysical address space.
0169  * arg == addr of xen_add_to_physmap_t.
0170  */
0171 #define XENMEM_add_to_physmap      7
0172 struct xen_add_to_physmap {
0173     /* Which domain to change the mapping for. */
0174     domid_t domid;
0175 
0176     /* Number of pages to go through for gmfn_range */
0177     uint16_t    size;
0178 
0179     /* Source mapping space. */
0180     unsigned int space;
0181 
0182     /* Index into source mapping space. */
0183     xen_ulong_t idx;
0184 
0185     /* GPFN where the source mapping page should appear. */
0186     xen_pfn_t gpfn;
0187 };
0188 DEFINE_GUEST_HANDLE_STRUCT(xen_add_to_physmap);
0189 
0190 /*** REMOVED ***/
0191 /*#define XENMEM_translate_gpfn_list  8*/
0192 
0193 #define XENMEM_add_to_physmap_range 23
0194 struct xen_add_to_physmap_range {
0195     /* IN */
0196     /* Which domain to change the mapping for. */
0197     domid_t domid;
0198     uint16_t space; /* => enum phys_map_space */
0199 
0200     /* Number of pages to go through */
0201     uint16_t size;
0202     domid_t foreign_domid; /* IFF gmfn_foreign */
0203 
0204     /* Indexes into space being mapped. */
0205     GUEST_HANDLE(xen_ulong_t) idxs;
0206 
0207     /* GPFN in domid where the source mapping page should appear. */
0208     GUEST_HANDLE(xen_pfn_t) gpfns;
0209 
0210     /* OUT */
0211 
0212     /* Per index error code. */
0213     GUEST_HANDLE(int) errs;
0214 };
0215 DEFINE_GUEST_HANDLE_STRUCT(xen_add_to_physmap_range);
0216 
0217 /*
0218  * Returns the pseudo-physical memory map as it was when the domain
0219  * was started (specified by XENMEM_set_memory_map).
0220  * arg == addr of struct xen_memory_map.
0221  */
0222 #define XENMEM_memory_map           9
0223 struct xen_memory_map {
0224     /*
0225      * On call the number of entries which can be stored in buffer. On
0226      * return the number of entries which have been stored in
0227      * buffer.
0228      */
0229     unsigned int nr_entries;
0230 
0231     /*
0232      * Entries in the buffer are in the same format as returned by the
0233      * BIOS INT 0x15 EAX=0xE820 call.
0234      */
0235     GUEST_HANDLE(void) buffer;
0236 };
0237 DEFINE_GUEST_HANDLE_STRUCT(xen_memory_map);
0238 
0239 /*
0240  * Returns the real physical memory map. Passes the same structure as
0241  * XENMEM_memory_map.
0242  * arg == addr of struct xen_memory_map.
0243  */
0244 #define XENMEM_machine_memory_map   10
0245 
0246 
0247 /*
0248  * Unmaps the page appearing at a particular GPFN from the specified guest's
0249  * pseudophysical address space.
0250  * arg == addr of xen_remove_from_physmap_t.
0251  */
0252 #define XENMEM_remove_from_physmap      15
0253 struct xen_remove_from_physmap {
0254     /* Which domain to change the mapping for. */
0255     domid_t domid;
0256 
0257     /* GPFN of the current mapping of the page. */
0258     xen_pfn_t gpfn;
0259 };
0260 DEFINE_GUEST_HANDLE_STRUCT(xen_remove_from_physmap);
0261 
0262 /*
0263  * Get the pages for a particular guest resource, so that they can be
0264  * mapped directly by a tools domain.
0265  */
0266 #define XENMEM_acquire_resource 28
0267 struct xen_mem_acquire_resource {
0268     /* IN - The domain whose resource is to be mapped */
0269     domid_t domid;
0270     /* IN - the type of resource */
0271     uint16_t type;
0272 
0273 #define XENMEM_resource_ioreq_server 0
0274 #define XENMEM_resource_grant_table 1
0275 
0276     /*
0277      * IN - a type-specific resource identifier, which must be zero
0278      *      unless stated otherwise.
0279      *
0280      * type == XENMEM_resource_ioreq_server -> id == ioreq server id
0281      * type == XENMEM_resource_grant_table -> id defined below
0282      */
0283     uint32_t id;
0284 
0285 #define XENMEM_resource_grant_table_id_shared 0
0286 #define XENMEM_resource_grant_table_id_status 1
0287 
0288     /* IN/OUT - As an IN parameter number of frames of the resource
0289      *          to be mapped. However, if the specified value is 0 and
0290      *          frame_list is NULL then this field will be set to the
0291      *          maximum value supported by the implementation on return.
0292      */
0293     uint32_t nr_frames;
0294     /*
0295      * OUT - Must be zero on entry. On return this may contain a bitwise
0296      *       OR of the following values.
0297      */
0298     uint32_t flags;
0299 
0300     /* The resource pages have been assigned to the calling domain */
0301 #define _XENMEM_rsrc_acq_caller_owned 0
0302 #define XENMEM_rsrc_acq_caller_owned (1u << _XENMEM_rsrc_acq_caller_owned)
0303 
0304     /*
0305      * IN - the index of the initial frame to be mapped. This parameter
0306      *      is ignored if nr_frames is 0.
0307      */
0308     uint64_t frame;
0309 
0310 #define XENMEM_resource_ioreq_server_frame_bufioreq 0
0311 #define XENMEM_resource_ioreq_server_frame_ioreq(n) (1 + (n))
0312 
0313     /*
0314      * IN/OUT - If the tools domain is PV then, upon return, frame_list
0315      *          will be populated with the MFNs of the resource.
0316      *          If the tools domain is HVM then it is expected that, on
0317      *          entry, frame_list will be populated with a list of GFNs
0318      *          that will be mapped to the MFNs of the resource.
0319      *          If -EIO is returned then the frame_list has only been
0320      *          partially mapped and it is up to the caller to unmap all
0321      *          the GFNs.
0322      *          This parameter may be NULL if nr_frames is 0.
0323      */
0324     GUEST_HANDLE(xen_pfn_t) frame_list;
0325 };
0326 DEFINE_GUEST_HANDLE_STRUCT(xen_mem_acquire_resource);
0327 
0328 #endif /* __XEN_PUBLIC_MEMORY_H__ */