memory.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. /******************************************************************************
  2. * memory.h
  3. *
  4. * Memory reservation and information.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to
  8. * deal in the Software without restriction, including without limitation the
  9. * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  10. * sell copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  21. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  22. * DEALINGS IN THE SOFTWARE.
  23. *
  24. * Copyright (c) 2005, Keir Fraser <keir@xensource.com>
  25. */
  26. #ifndef __XEN_PUBLIC_MEMORY_H__
  27. #define __XEN_PUBLIC_MEMORY_H__
  28. /*
  29. * Increase or decrease the specified domain's memory reservation. Returns the
  30. * number of extents successfully allocated or freed.
  31. * arg == addr of struct xen_memory_reservation.
  32. */
  33. #define XENMEM_increase_reservation 0
  34. #define XENMEM_decrease_reservation 1
  35. #define XENMEM_populate_physmap 6
  36. #if __XEN_INTERFACE_VERSION__ >= 0x00030209
  37. /*
  38. * Maximum # bits addressable by the user of the allocated region (e.g., I/O
  39. * devices often have a 32-bit limitation even in 64-bit systems). If zero
  40. * then the user has no addressing restriction. This field is not used by
  41. * XENMEM_decrease_reservation.
  42. */
  43. #define XENMEMF_address_bits(x) (x)
  44. #define XENMEMF_get_address_bits(x) ((x) & 0xffu)
  45. /* NUMA node to allocate from. */
  46. #define XENMEMF_node(x) (((x) + 1) << 8)
  47. #define XENMEMF_get_node(x) ((((x) >> 8) - 1) & 0xffu)
  48. #endif
  49. struct xen_memory_reservation {
  50. /*
  51. * XENMEM_increase_reservation:
  52. * OUT: MFN (*not* GMFN) bases of extents that were allocated
  53. * XENMEM_decrease_reservation:
  54. * IN: GMFN bases of extents to free
  55. * XENMEM_populate_physmap:
  56. * IN: GPFN bases of extents to populate with memory
  57. * OUT: GMFN bases of extents that were allocated
  58. * (NB. This command also updates the mach_to_phys translation table)
  59. */
  60. XEN_GUEST_HANDLE(xen_pfn_t) extent_start;
  61. /* Number of extents, and size/alignment of each (2^extent_order pages). */
  62. xen_ulong_t nr_extents;
  63. unsigned int extent_order;
  64. #if __XEN_INTERFACE_VERSION__ >= 0x00030209
  65. /* XENMEMF flags. */
  66. unsigned int mem_flags;
  67. #else
  68. unsigned int address_bits;
  69. #endif
  70. /*
  71. * Domain whose reservation is being changed.
  72. * Unprivileged domains can specify only DOMID_SELF.
  73. */
  74. domid_t domid;
  75. };
  76. typedef struct xen_memory_reservation xen_memory_reservation_t;
  77. DEFINE_XEN_GUEST_HANDLE(xen_memory_reservation_t);
  78. /*
  79. * An atomic exchange of memory pages. If return code is zero then
  80. * @out.extent_list provides GMFNs of the newly-allocated memory.
  81. * Returns zero on complete success, otherwise a negative error code.
  82. * On complete success then always @nr_exchanged == @in.nr_extents.
  83. * On partial success @nr_exchanged indicates how much work was done.
  84. */
  85. #define XENMEM_exchange 11
  86. struct xen_memory_exchange {
  87. /*
  88. * [IN] Details of memory extents to be exchanged (GMFN bases).
  89. * Note that @in.address_bits is ignored and unused.
  90. */
  91. struct xen_memory_reservation in;
  92. /*
  93. * [IN/OUT] Details of new memory extents.
  94. * We require that:
  95. * 1. @in.domid == @out.domid
  96. * 2. @in.nr_extents << @in.extent_order ==
  97. * @out.nr_extents << @out.extent_order
  98. * 3. @in.extent_start and @out.extent_start lists must not overlap
  99. * 4. @out.extent_start lists GPFN bases to be populated
  100. * 5. @out.extent_start is overwritten with allocated GMFN bases
  101. */
  102. struct xen_memory_reservation out;
  103. /*
  104. * [OUT] Number of input extents that were successfully exchanged:
  105. * 1. The first @nr_exchanged input extents were successfully
  106. * deallocated.
  107. * 2. The corresponding first entries in the output extent list correctly
  108. * indicate the GMFNs that were successfully exchanged.
  109. * 3. All other input and output extents are untouched.
  110. * 4. If not all input exents are exchanged then the return code of this
  111. * command will be non-zero.
  112. * 5. THIS FIELD MUST BE INITIALISED TO ZERO BY THE CALLER!
  113. */
  114. xen_ulong_t nr_exchanged;
  115. };
  116. typedef struct xen_memory_exchange xen_memory_exchange_t;
  117. DEFINE_XEN_GUEST_HANDLE(xen_memory_exchange_t);
  118. /*
  119. * Returns the maximum machine frame number of mapped RAM in this system.
  120. * This command always succeeds (it never returns an error code).
  121. * arg == NULL.
  122. */
  123. #define XENMEM_maximum_ram_page 2
  124. /*
  125. * Returns the current or maximum memory reservation, in pages, of the
  126. * specified domain (may be DOMID_SELF). Returns -ve errcode on failure.
  127. * arg == addr of domid_t.
  128. */
  129. #define XENMEM_current_reservation 3
  130. #define XENMEM_maximum_reservation 4
  131. /*
  132. * Returns the maximum GPFN in use by the guest, or -ve errcode on failure.
  133. */
  134. #define XENMEM_maximum_gpfn 14
  135. /*
  136. * Returns a list of MFN bases of 2MB extents comprising the machine_to_phys
  137. * mapping table. Architectures which do not have a m2p table do not implement
  138. * this command.
  139. * arg == addr of xen_machphys_mfn_list_t.
  140. */
  141. #define XENMEM_machphys_mfn_list 5
  142. struct xen_machphys_mfn_list {
  143. /*
  144. * Size of the 'extent_start' array. Fewer entries will be filled if the
  145. * machphys table is smaller than max_extents * 2MB.
  146. */
  147. unsigned int max_extents;
  148. /*
  149. * Pointer to buffer to fill with list of extent starts. If there are
  150. * any large discontiguities in the machine address space, 2MB gaps in
  151. * the machphys table will be represented by an MFN base of zero.
  152. */
  153. XEN_GUEST_HANDLE(xen_pfn_t) extent_start;
  154. /*
  155. * Number of extents written to the above array. This will be smaller
  156. * than 'max_extents' if the machphys table is smaller than max_e * 2MB.
  157. */
  158. unsigned int nr_extents;
  159. };
  160. typedef struct xen_machphys_mfn_list xen_machphys_mfn_list_t;
  161. DEFINE_XEN_GUEST_HANDLE(xen_machphys_mfn_list_t);
  162. /*
  163. * Returns the location in virtual address space of the machine_to_phys
  164. * mapping table. Architectures which do not have a m2p table, or which do not
  165. * map it by default into guest address space, do not implement this command.
  166. * arg == addr of xen_machphys_mapping_t.
  167. */
  168. #define XENMEM_machphys_mapping 12
  169. struct xen_machphys_mapping {
  170. xen_ulong_t v_start, v_end; /* Start and end virtual addresses. */
  171. xen_ulong_t max_mfn; /* Maximum MFN that can be looked up. */
  172. };
  173. typedef struct xen_machphys_mapping xen_machphys_mapping_t;
  174. DEFINE_XEN_GUEST_HANDLE(xen_machphys_mapping_t);
  175. /*
  176. * Sets the GPFN at which a particular page appears in the specified guest's
  177. * pseudophysical address space.
  178. * arg == addr of xen_add_to_physmap_t.
  179. */
  180. #define XENMEM_add_to_physmap 7
  181. struct xen_add_to_physmap {
  182. /* Which domain to change the mapping for. */
  183. domid_t domid;
  184. /* Source mapping space. */
  185. #define XENMAPSPACE_shared_info 0 /* shared info page */
  186. #define XENMAPSPACE_grant_table 1 /* grant table page */
  187. #define XENMAPSPACE_mfn 2 /* usual MFN */
  188. unsigned int space;
  189. /* Index into source mapping space. */
  190. xen_ulong_t idx;
  191. /* GPFN where the source mapping page should appear. */
  192. xen_pfn_t gpfn;
  193. };
  194. typedef struct xen_add_to_physmap xen_add_to_physmap_t;
  195. DEFINE_XEN_GUEST_HANDLE(xen_add_to_physmap_t);
  196. /*
  197. * Unmaps the page appearing at a particular GPFN from the specified guest's
  198. * pseudophysical address space.
  199. * arg == addr of xen_remove_from_physmap_t.
  200. */
  201. #define XENMEM_remove_from_physmap 15
  202. struct xen_remove_from_physmap {
  203. /* Which domain to change the mapping for. */
  204. domid_t domid;
  205. /* GPFN of the current mapping of the page. */
  206. xen_pfn_t gpfn;
  207. };
  208. typedef struct xen_remove_from_physmap xen_remove_from_physmap_t;
  209. DEFINE_XEN_GUEST_HANDLE(xen_remove_from_physmap_t);
  210. /*
  211. * Translates a list of domain-specific GPFNs into MFNs. Returns a -ve error
  212. * code on failure. This call only works for auto-translated guests.
  213. */
  214. #define XENMEM_translate_gpfn_list 8
  215. struct xen_translate_gpfn_list {
  216. /* Which domain to translate for? */
  217. domid_t domid;
  218. /* Length of list. */
  219. xen_ulong_t nr_gpfns;
  220. /* List of GPFNs to translate. */
  221. XEN_GUEST_HANDLE(xen_pfn_t) gpfn_list;
  222. /*
  223. * Output list to contain MFN translations. May be the same as the input
  224. * list (in which case each input GPFN is overwritten with the output MFN).
  225. */
  226. XEN_GUEST_HANDLE(xen_pfn_t) mfn_list;
  227. };
  228. typedef struct xen_translate_gpfn_list xen_translate_gpfn_list_t;
  229. DEFINE_XEN_GUEST_HANDLE(xen_translate_gpfn_list_t);
  230. /*
  231. * Returns the pseudo-physical memory map as it was when the domain
  232. * was started (specified by XENMEM_set_memory_map).
  233. * arg == addr of xen_memory_map_t.
  234. */
  235. #define XENMEM_memory_map 9
  236. struct xen_memory_map {
  237. /*
  238. * On call the number of entries which can be stored in buffer. On
  239. * return the number of entries which have been stored in
  240. * buffer.
  241. */
  242. unsigned int nr_entries;
  243. /*
  244. * Entries in the buffer are in the same format as returned by the
  245. * BIOS INT 0x15 EAX=0xE820 call.
  246. */
  247. XEN_GUEST_HANDLE(void) buffer;
  248. };
  249. typedef struct xen_memory_map xen_memory_map_t;
  250. DEFINE_XEN_GUEST_HANDLE(xen_memory_map_t);
  251. /*
  252. * Returns the real physical memory map. Passes the same structure as
  253. * XENMEM_memory_map.
  254. * arg == addr of xen_memory_map_t.
  255. */
  256. #define XENMEM_machine_memory_map 10
  257. /*
  258. * Set the pseudo-physical memory map of a domain, as returned by
  259. * XENMEM_memory_map.
  260. * arg == addr of xen_foreign_memory_map_t.
  261. */
  262. #define XENMEM_set_memory_map 13
  263. struct xen_foreign_memory_map {
  264. domid_t domid;
  265. struct xen_memory_map map;
  266. };
  267. typedef struct xen_foreign_memory_map xen_foreign_memory_map_t;
  268. DEFINE_XEN_GUEST_HANDLE(xen_foreign_memory_map_t);
  269. #endif /* __XEN_PUBLIC_MEMORY_H__ */
  270. /*
  271. * Local variables:
  272. * mode: C
  273. * c-set-style: "BSD"
  274. * c-basic-offset: 4
  275. * tab-width: 4
  276. * indent-tabs-mode: nil
  277. * End:
  278. */