xref: /onnv-gate/usr/src/uts/common/xen/public/memory.h (revision 10175:dd9708d1f561)
15084Sjohnlev /******************************************************************************
25084Sjohnlev  * memory.h
35084Sjohnlev  *
45084Sjohnlev  * Memory reservation and information.
55084Sjohnlev  *
65084Sjohnlev  * Permission is hereby granted, free of charge, to any person obtaining a copy
75084Sjohnlev  * of this software and associated documentation files (the "Software"), to
85084Sjohnlev  * deal in the Software without restriction, including without limitation the
95084Sjohnlev  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
105084Sjohnlev  * sell copies of the Software, and to permit persons to whom the Software is
115084Sjohnlev  * furnished to do so, subject to the following conditions:
125084Sjohnlev  *
135084Sjohnlev  * The above copyright notice and this permission notice shall be included in
145084Sjohnlev  * all copies or substantial portions of the Software.
155084Sjohnlev  *
165084Sjohnlev  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
175084Sjohnlev  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
185084Sjohnlev  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
195084Sjohnlev  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
205084Sjohnlev  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
215084Sjohnlev  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
225084Sjohnlev  * DEALINGS IN THE SOFTWARE.
235084Sjohnlev  *
245084Sjohnlev  * Copyright (c) 2005, Keir Fraser <keir@xensource.com>
255084Sjohnlev  */
265084Sjohnlev 
275084Sjohnlev #ifndef __XEN_PUBLIC_MEMORY_H__
285084Sjohnlev #define __XEN_PUBLIC_MEMORY_H__
295084Sjohnlev 
305084Sjohnlev /*
315084Sjohnlev  * Increase or decrease the specified domain's memory reservation. Returns the
325084Sjohnlev  * number of extents successfully allocated or freed.
335084Sjohnlev  * arg == addr of struct xen_memory_reservation.
345084Sjohnlev  */
355084Sjohnlev #define XENMEM_increase_reservation 0
365084Sjohnlev #define XENMEM_decrease_reservation 1
375084Sjohnlev #define XENMEM_populate_physmap     6
38*10175SStuart.Maybee@Sun.COM 
39*10175SStuart.Maybee@Sun.COM #if __XEN_INTERFACE_VERSION__ >= 0x00030209
40*10175SStuart.Maybee@Sun.COM /*
41*10175SStuart.Maybee@Sun.COM  * Maximum # bits addressable by the user of the allocated region (e.g., I/O
42*10175SStuart.Maybee@Sun.COM  * devices often have a 32-bit limitation even in 64-bit systems). If zero
43*10175SStuart.Maybee@Sun.COM  * then the user has no addressing restriction. This field is not used by
44*10175SStuart.Maybee@Sun.COM  * XENMEM_decrease_reservation.
45*10175SStuart.Maybee@Sun.COM  */
46*10175SStuart.Maybee@Sun.COM #define XENMEMF_address_bits(x)     (x)
47*10175SStuart.Maybee@Sun.COM #define XENMEMF_get_address_bits(x) ((x) & 0xffu)
48*10175SStuart.Maybee@Sun.COM /* NUMA node to allocate from. */
49*10175SStuart.Maybee@Sun.COM #define XENMEMF_node(x)     (((x) + 1) << 8)
50*10175SStuart.Maybee@Sun.COM #define XENMEMF_get_node(x) ((((x) >> 8) - 1) & 0xffu)
51*10175SStuart.Maybee@Sun.COM #endif
52*10175SStuart.Maybee@Sun.COM 
535084Sjohnlev struct xen_memory_reservation {
545084Sjohnlev 
555084Sjohnlev     /*
565084Sjohnlev      * XENMEM_increase_reservation:
575084Sjohnlev      *   OUT: MFN (*not* GMFN) bases of extents that were allocated
585084Sjohnlev      * XENMEM_decrease_reservation:
595084Sjohnlev      *   IN:  GMFN bases of extents to free
605084Sjohnlev      * XENMEM_populate_physmap:
615084Sjohnlev      *   IN:  GPFN bases of extents to populate with memory
625084Sjohnlev      *   OUT: GMFN bases of extents that were allocated
635084Sjohnlev      *   (NB. This command also updates the mach_to_phys translation table)
645084Sjohnlev      */
655084Sjohnlev     XEN_GUEST_HANDLE(xen_pfn_t) extent_start;
665084Sjohnlev 
675084Sjohnlev     /* Number of extents, and size/alignment of each (2^extent_order pages). */
685084Sjohnlev     xen_ulong_t    nr_extents;
695084Sjohnlev     unsigned int   extent_order;
705084Sjohnlev 
71*10175SStuart.Maybee@Sun.COM #if __XEN_INTERFACE_VERSION__ >= 0x00030209
72*10175SStuart.Maybee@Sun.COM     /* XENMEMF flags. */
73*10175SStuart.Maybee@Sun.COM     unsigned int   mem_flags;
74*10175SStuart.Maybee@Sun.COM #else
755084Sjohnlev     unsigned int   address_bits;
76*10175SStuart.Maybee@Sun.COM #endif
775084Sjohnlev 
785084Sjohnlev     /*
795084Sjohnlev      * Domain whose reservation is being changed.
805084Sjohnlev      * Unprivileged domains can specify only DOMID_SELF.
815084Sjohnlev      */
825084Sjohnlev     domid_t        domid;
835084Sjohnlev };
845084Sjohnlev typedef struct xen_memory_reservation xen_memory_reservation_t;
855084Sjohnlev DEFINE_XEN_GUEST_HANDLE(xen_memory_reservation_t);
865084Sjohnlev 
875084Sjohnlev /*
885084Sjohnlev  * An atomic exchange of memory pages. If return code is zero then
895084Sjohnlev  * @out.extent_list provides GMFNs of the newly-allocated memory.
905084Sjohnlev  * Returns zero on complete success, otherwise a negative error code.
915084Sjohnlev  * On complete success then always @nr_exchanged == @in.nr_extents.
925084Sjohnlev  * On partial success @nr_exchanged indicates how much work was done.
935084Sjohnlev  */
945084Sjohnlev #define XENMEM_exchange             11
955084Sjohnlev struct xen_memory_exchange {
965084Sjohnlev     /*
975084Sjohnlev      * [IN] Details of memory extents to be exchanged (GMFN bases).
985084Sjohnlev      * Note that @in.address_bits is ignored and unused.
995084Sjohnlev      */
1005084Sjohnlev     struct xen_memory_reservation in;
1015084Sjohnlev 
1025084Sjohnlev     /*
1035084Sjohnlev      * [IN/OUT] Details of new memory extents.
1045084Sjohnlev      * We require that:
1055084Sjohnlev      *  1. @in.domid == @out.domid
1065084Sjohnlev      *  2. @in.nr_extents  << @in.extent_order ==
1075084Sjohnlev      *     @out.nr_extents << @out.extent_order
1085084Sjohnlev      *  3. @in.extent_start and @out.extent_start lists must not overlap
1095084Sjohnlev      *  4. @out.extent_start lists GPFN bases to be populated
1105084Sjohnlev      *  5. @out.extent_start is overwritten with allocated GMFN bases
1115084Sjohnlev      */
1125084Sjohnlev     struct xen_memory_reservation out;
1135084Sjohnlev 
1145084Sjohnlev     /*
1155084Sjohnlev      * [OUT] Number of input extents that were successfully exchanged:
1165084Sjohnlev      *  1. The first @nr_exchanged input extents were successfully
1175084Sjohnlev      *     deallocated.
1185084Sjohnlev      *  2. The corresponding first entries in the output extent list correctly
1195084Sjohnlev      *     indicate the GMFNs that were successfully exchanged.
1205084Sjohnlev      *  3. All other input and output extents are untouched.
1215084Sjohnlev      *  4. If not all input exents are exchanged then the return code of this
1225084Sjohnlev      *     command will be non-zero.
1235084Sjohnlev      *  5. THIS FIELD MUST BE INITIALISED TO ZERO BY THE CALLER!
1245084Sjohnlev      */
1255084Sjohnlev     xen_ulong_t nr_exchanged;
1265084Sjohnlev };
1275084Sjohnlev typedef struct xen_memory_exchange xen_memory_exchange_t;
1285084Sjohnlev DEFINE_XEN_GUEST_HANDLE(xen_memory_exchange_t);
1295084Sjohnlev 
1305084Sjohnlev /*
1315084Sjohnlev  * Returns the maximum machine frame number of mapped RAM in this system.
1325084Sjohnlev  * This command always succeeds (it never returns an error code).
1335084Sjohnlev  * arg == NULL.
1345084Sjohnlev  */
1355084Sjohnlev #define XENMEM_maximum_ram_page     2
1365084Sjohnlev 
1375084Sjohnlev /*
1385084Sjohnlev  * Returns the current or maximum memory reservation, in pages, of the
1395084Sjohnlev  * specified domain (may be DOMID_SELF). Returns -ve errcode on failure.
1405084Sjohnlev  * arg == addr of domid_t.
1415084Sjohnlev  */
1425084Sjohnlev #define XENMEM_current_reservation  3
1435084Sjohnlev #define XENMEM_maximum_reservation  4
1445084Sjohnlev 
1455084Sjohnlev /*
1466144Srab  * Returns the maximum GPFN in use by the guest, or -ve errcode on failure.
1476144Srab  */
1486144Srab #define XENMEM_maximum_gpfn         14
1496144Srab 
1506144Srab /*
1515084Sjohnlev  * Returns a list of MFN bases of 2MB extents comprising the machine_to_phys
1525084Sjohnlev  * mapping table. Architectures which do not have a m2p table do not implement
1535084Sjohnlev  * this command.
1545084Sjohnlev  * arg == addr of xen_machphys_mfn_list_t.
1555084Sjohnlev  */
1565084Sjohnlev #define XENMEM_machphys_mfn_list    5
1575084Sjohnlev struct xen_machphys_mfn_list {
1585084Sjohnlev     /*
1595084Sjohnlev      * Size of the 'extent_start' array. Fewer entries will be filled if the
1605084Sjohnlev      * machphys table is smaller than max_extents * 2MB.
1615084Sjohnlev      */
1625084Sjohnlev     unsigned int max_extents;
1635084Sjohnlev 
1645084Sjohnlev     /*
1655084Sjohnlev      * Pointer to buffer to fill with list of extent starts. If there are
1665084Sjohnlev      * any large discontiguities in the machine address space, 2MB gaps in
1675084Sjohnlev      * the machphys table will be represented by an MFN base of zero.
1685084Sjohnlev      */
1695084Sjohnlev     XEN_GUEST_HANDLE(xen_pfn_t) extent_start;
1705084Sjohnlev 
1715084Sjohnlev     /*
1725084Sjohnlev      * Number of extents written to the above array. This will be smaller
1735084Sjohnlev      * than 'max_extents' if the machphys table is smaller than max_e * 2MB.
1745084Sjohnlev      */
1755084Sjohnlev     unsigned int nr_extents;
1765084Sjohnlev };
1775084Sjohnlev typedef struct xen_machphys_mfn_list xen_machphys_mfn_list_t;
1785084Sjohnlev DEFINE_XEN_GUEST_HANDLE(xen_machphys_mfn_list_t);
1795084Sjohnlev 
1805084Sjohnlev /*
1815084Sjohnlev  * Returns the location in virtual address space of the machine_to_phys
1825084Sjohnlev  * mapping table. Architectures which do not have a m2p table, or which do not
1835084Sjohnlev  * map it by default into guest address space, do not implement this command.
1845084Sjohnlev  * arg == addr of xen_machphys_mapping_t.
1855084Sjohnlev  */
1865084Sjohnlev #define XENMEM_machphys_mapping     12
1875084Sjohnlev struct xen_machphys_mapping {
1885084Sjohnlev     xen_ulong_t v_start, v_end; /* Start and end virtual addresses.   */
1895084Sjohnlev     xen_ulong_t max_mfn;        /* Maximum MFN that can be looked up. */
1905084Sjohnlev };
1915084Sjohnlev typedef struct xen_machphys_mapping xen_machphys_mapping_t;
1925084Sjohnlev DEFINE_XEN_GUEST_HANDLE(xen_machphys_mapping_t);
1935084Sjohnlev 
1945084Sjohnlev /*
1955084Sjohnlev  * Sets the GPFN at which a particular page appears in the specified guest's
1965084Sjohnlev  * pseudophysical address space.
1975084Sjohnlev  * arg == addr of xen_add_to_physmap_t.
1985084Sjohnlev  */
1995084Sjohnlev #define XENMEM_add_to_physmap      7
2005084Sjohnlev struct xen_add_to_physmap {
2015084Sjohnlev     /* Which domain to change the mapping for. */
2025084Sjohnlev     domid_t domid;
2035084Sjohnlev 
2045084Sjohnlev     /* Source mapping space. */
2055084Sjohnlev #define XENMAPSPACE_shared_info 0 /* shared info page */
2065084Sjohnlev #define XENMAPSPACE_grant_table 1 /* grant table page */
2075084Sjohnlev     unsigned int space;
2085084Sjohnlev 
2095084Sjohnlev     /* Index into source mapping space. */
2105084Sjohnlev     xen_ulong_t idx;
2115084Sjohnlev 
2125084Sjohnlev     /* GPFN where the source mapping page should appear. */
2135084Sjohnlev     xen_pfn_t     gpfn;
2145084Sjohnlev };
2155084Sjohnlev typedef struct xen_add_to_physmap xen_add_to_physmap_t;
2165084Sjohnlev DEFINE_XEN_GUEST_HANDLE(xen_add_to_physmap_t);
2175084Sjohnlev 
2185084Sjohnlev /*
2195084Sjohnlev  * Translates a list of domain-specific GPFNs into MFNs. Returns a -ve error
2205084Sjohnlev  * code on failure. This call only works for auto-translated guests.
2215084Sjohnlev  */
2225084Sjohnlev #define XENMEM_translate_gpfn_list  8
2235084Sjohnlev struct xen_translate_gpfn_list {
2245084Sjohnlev     /* Which domain to translate for? */
2255084Sjohnlev     domid_t domid;
2265084Sjohnlev 
2275084Sjohnlev     /* Length of list. */
2285084Sjohnlev     xen_ulong_t nr_gpfns;
2295084Sjohnlev 
2305084Sjohnlev     /* List of GPFNs to translate. */
2315084Sjohnlev     XEN_GUEST_HANDLE(xen_pfn_t) gpfn_list;
2325084Sjohnlev 
2335084Sjohnlev     /*
2345084Sjohnlev      * Output list to contain MFN translations. May be the same as the input
2355084Sjohnlev      * list (in which case each input GPFN is overwritten with the output MFN).
2365084Sjohnlev      */
2375084Sjohnlev     XEN_GUEST_HANDLE(xen_pfn_t) mfn_list;
2385084Sjohnlev };
2395084Sjohnlev typedef struct xen_translate_gpfn_list xen_translate_gpfn_list_t;
2405084Sjohnlev DEFINE_XEN_GUEST_HANDLE(xen_translate_gpfn_list_t);
2415084Sjohnlev 
2425084Sjohnlev /*
2435084Sjohnlev  * Returns the pseudo-physical memory map as it was when the domain
2445084Sjohnlev  * was started (specified by XENMEM_set_memory_map).
2455084Sjohnlev  * arg == addr of xen_memory_map_t.
2465084Sjohnlev  */
2475084Sjohnlev #define XENMEM_memory_map           9
2485084Sjohnlev struct xen_memory_map {
2495084Sjohnlev     /*
2505084Sjohnlev      * On call the number of entries which can be stored in buffer. On
2515084Sjohnlev      * return the number of entries which have been stored in
2525084Sjohnlev      * buffer.
2535084Sjohnlev      */
2545084Sjohnlev     unsigned int nr_entries;
2555084Sjohnlev 
2565084Sjohnlev     /*
2575084Sjohnlev      * Entries in the buffer are in the same format as returned by the
2585084Sjohnlev      * BIOS INT 0x15 EAX=0xE820 call.
2595084Sjohnlev      */
2605084Sjohnlev     XEN_GUEST_HANDLE(void) buffer;
2615084Sjohnlev };
2625084Sjohnlev typedef struct xen_memory_map xen_memory_map_t;
2635084Sjohnlev DEFINE_XEN_GUEST_HANDLE(xen_memory_map_t);
2645084Sjohnlev 
2655084Sjohnlev /*
2665084Sjohnlev  * Returns the real physical memory map. Passes the same structure as
2675084Sjohnlev  * XENMEM_memory_map.
2685084Sjohnlev  * arg == addr of xen_memory_map_t.
2695084Sjohnlev  */
2705084Sjohnlev #define XENMEM_machine_memory_map   10
2715084Sjohnlev 
2725084Sjohnlev /*
2735084Sjohnlev  * Set the pseudo-physical memory map of a domain, as returned by
2745084Sjohnlev  * XENMEM_memory_map.
2755084Sjohnlev  * arg == addr of xen_foreign_memory_map_t.
2765084Sjohnlev  */
2775084Sjohnlev #define XENMEM_set_memory_map       13
2785084Sjohnlev struct xen_foreign_memory_map {
2795084Sjohnlev     domid_t domid;
2805084Sjohnlev     struct xen_memory_map map;
2815084Sjohnlev };
2825084Sjohnlev typedef struct xen_foreign_memory_map xen_foreign_memory_map_t;
2835084Sjohnlev DEFINE_XEN_GUEST_HANDLE(xen_foreign_memory_map_t);
2845084Sjohnlev 
2855084Sjohnlev #endif /* __XEN_PUBLIC_MEMORY_H__ */
2865084Sjohnlev 
2875084Sjohnlev /*
2885084Sjohnlev  * Local variables:
2895084Sjohnlev  * mode: C
2905084Sjohnlev  * c-set-style: "BSD"
2915084Sjohnlev  * c-basic-offset: 4
2925084Sjohnlev  * tab-width: 4
2935084Sjohnlev  * indent-tabs-mode: nil
2945084Sjohnlev  * End:
2955084Sjohnlev  */
296