memory.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. /* SPDX-License-Identifier: GPL-2.0
  2. *
  3. * memory.h
  4. *
  5. * Memory reservation and information.
  6. *
  7. * Copyright (c) 2005, Keir Fraser <keir@xensource.com>
  8. */
  9. #ifndef __XEN_PUBLIC_MEMORY_H__
  10. #define __XEN_PUBLIC_MEMORY_H__
  11. /*
  12. * Increase or decrease the specified domain's memory reservation. Returns a
  13. * -ve errcode on failure, or the # extents successfully allocated or freed.
  14. * arg == addr of struct xen_memory_reservation.
  15. */
  16. #define XENMEM_increase_reservation 0
  17. #define XENMEM_decrease_reservation 1
  18. #define XENMEM_populate_physmap 6
  19. struct xen_memory_reservation {
  20. /*
  21. * XENMEM_increase_reservation:
  22. * OUT: MFN (*not* GMFN) bases of extents that were allocated
  23. * XENMEM_decrease_reservation:
  24. * IN: GMFN bases of extents to free
  25. * XENMEM_populate_physmap:
  26. * IN: GPFN bases of extents to populate with memory
  27. * OUT: GMFN bases of extents that were allocated
  28. * (NB. This command also updates the mach_to_phys translation table)
  29. */
  30. GUEST_HANDLE(xen_pfn_t)extent_start;
  31. /* Number of extents, and size/alignment of each (2^extent_order pages). */
  32. xen_ulong_t nr_extents;
  33. unsigned int extent_order;
  34. /*
  35. * Maximum # bits addressable by the user of the allocated region (e.g.,
  36. * I/O devices often have a 32-bit limitation even in 64-bit systems). If
  37. * zero then the user has no addressing restriction.
  38. * This field is not used by XENMEM_decrease_reservation.
  39. */
  40. unsigned int address_bits;
  41. /*
  42. * Domain whose reservation is being changed.
  43. * Unprivileged domains can specify only DOMID_SELF.
  44. */
  45. domid_t domid;
  46. };
  47. DEFINE_GUEST_HANDLE_STRUCT(xen_memory_reservation);
  48. /*
  49. * An atomic exchange of memory pages. If return code is zero then
  50. * @out.extent_list provides GMFNs of the newly-allocated memory.
  51. * Returns zero on complete success, otherwise a negative error code.
  52. * On complete success then always @nr_exchanged == @in.nr_extents.
  53. * On partial success @nr_exchanged indicates how much work was done.
  54. */
  55. #define XENMEM_exchange 11
  56. struct xen_memory_exchange {
  57. /*
  58. * [IN] Details of memory extents to be exchanged (GMFN bases).
  59. * Note that @in.address_bits is ignored and unused.
  60. */
  61. struct xen_memory_reservation in;
  62. /*
  63. * [IN/OUT] Details of new memory extents.
  64. * We require that:
  65. * 1. @in.domid == @out.domid
  66. * 2. @in.nr_extents << @in.extent_order ==
  67. * @out.nr_extents << @out.extent_order
  68. * 3. @in.extent_start and @out.extent_start lists must not overlap
  69. * 4. @out.extent_start lists GPFN bases to be populated
  70. * 5. @out.extent_start is overwritten with allocated GMFN bases
  71. */
  72. struct xen_memory_reservation out;
  73. /*
  74. * [OUT] Number of input extents that were successfully exchanged:
  75. * 1. The first @nr_exchanged input extents were successfully
  76. * deallocated.
  77. * 2. The corresponding first entries in the output extent list correctly
  78. * indicate the GMFNs that were successfully exchanged.
  79. * 3. All other input and output extents are untouched.
  80. * 4. If not all input exents are exchanged then the return code of this
  81. * command will be non-zero.
  82. * 5. THIS FIELD MUST BE INITIALISED TO ZERO BY THE CALLER!
  83. */
  84. xen_ulong_t nr_exchanged;
  85. };
  86. DEFINE_GUEST_HANDLE_STRUCT(xen_memory_exchange);
  87. /*
  88. * Returns the maximum machine frame number of mapped RAM in this system.
  89. * This command always succeeds (it never returns an error code).
  90. * arg == NULL.
  91. */
  92. #define XENMEM_maximum_ram_page 2
  93. /*
  94. * Returns the current or maximum memory reservation, in pages, of the
  95. * specified domain (may be DOMID_SELF). Returns -ve errcode on failure.
  96. * arg == addr of domid_t.
  97. */
  98. #define XENMEM_current_reservation 3
  99. #define XENMEM_maximum_reservation 4
  100. /*
  101. * Returns a list of MFN bases of 2MB extents comprising the machine_to_phys
  102. * mapping table. Architectures which do not have a m2p table do not implement
  103. * this command.
  104. * arg == addr of xen_machphys_mfn_list_t.
  105. */
  106. #define XENMEM_machphys_mfn_list 5
  107. struct xen_machphys_mfn_list {
  108. /*
  109. * Size of the 'extent_start' array. Fewer entries will be filled if the
  110. * machphys table is smaller than max_extents * 2MB.
  111. */
  112. unsigned int max_extents;
  113. /*
  114. * Pointer to buffer to fill with list of extent starts. If there are
  115. * any large discontiguities in the machine address space, 2MB gaps in
  116. * the machphys table will be represented by an MFN base of zero.
  117. */
  118. GUEST_HANDLE(xen_pfn_t)extent_start;
  119. /*
  120. * Number of extents written to the above array. This will be smaller
  121. * than 'max_extents' if the machphys table is smaller than max_e * 2MB.
  122. */
  123. unsigned int nr_extents;
  124. };
  125. DEFINE_GUEST_HANDLE_STRUCT(xen_machphys_mfn_list);
  126. /*
  127. * Returns the location in virtual address space of the machine_to_phys
  128. * mapping table. Architectures which do not have a m2p table, or which do not
  129. * map it by default into guest address space, do not implement this command.
  130. * arg == addr of xen_machphys_mapping_t.
  131. */
  132. #define XENMEM_machphys_mapping 12
  133. struct xen_machphys_mapping {
  134. xen_ulong_t v_start, v_end; /* Start and end virtual addresses. */
  135. xen_ulong_t max_mfn; /* Maximum MFN that can be looked up. */
  136. };
  137. DEFINE_GUEST_HANDLE_STRUCT(xen_machphys_mapping_t);
  138. #define XENMAPSPACE_shared_info 0 /* shared info page */
  139. #define XENMAPSPACE_grant_table 1 /* grant table page */
  140. #define XENMAPSPACE_gmfn 2 /* GMFN */
  141. #define XENMAPSPACE_gmfn_range 3 /* GMFN range, XENMEM_add_to_physmap only. */
  142. #define XENMAPSPACE_gmfn_foreign 4 /* GMFN from another dom,
  143. * XENMEM_add_to_physmap_range only.
  144. */
  145. #define XENMAPSPACE_dev_mmio 5 /* device mmio region */
  146. /*
  147. * Sets the GPFN at which a particular page appears in the specified guest's
  148. * pseudophysical address space.
  149. * arg == addr of xen_add_to_physmap_t.
  150. */
  151. #define XENMEM_add_to_physmap 7
  152. struct xen_add_to_physmap {
  153. /* Which domain to change the mapping for. */
  154. domid_t domid;
  155. /* Number of pages to go through for gmfn_range */
  156. u16 size;
  157. /* Source mapping space. */
  158. unsigned int space;
  159. /* Index into source mapping space. */
  160. xen_ulong_t idx;
  161. /* GPFN where the source mapping page should appear. */
  162. xen_pfn_t gpfn;
  163. };
  164. DEFINE_GUEST_HANDLE_STRUCT(xen_add_to_physmap);
  165. /*** REMOVED ***/
  166. /*#define XENMEM_translate_gpfn_list 8*/
  167. #define XENMEM_add_to_physmap_range 23
  168. struct xen_add_to_physmap_range {
  169. /* IN */
  170. /* Which domain to change the mapping for. */
  171. domid_t domid;
  172. u16 space; /* => enum phys_map_space */
  173. /* Number of pages to go through */
  174. u16 size;
  175. domid_t foreign_domid; /* IFF gmfn_foreign */
  176. /* Indexes into space being mapped. */
  177. GUEST_HANDLE(xen_ulong_t)idxs;
  178. /* GPFN in domid where the source mapping page should appear. */
  179. GUEST_HANDLE(xen_pfn_t)gpfns;
  180. /* OUT */
  181. /* Per index error code. */
  182. GUEST_HANDLE(int)errs;
  183. };
  184. DEFINE_GUEST_HANDLE_STRUCT(xen_add_to_physmap_range);
  185. /*
  186. * Returns the pseudo-physical memory map as it was when the domain
  187. * was started (specified by XENMEM_set_memory_map).
  188. * arg == addr of struct xen_memory_map.
  189. */
  190. #define XENMEM_memory_map 9
  191. struct xen_memory_map {
  192. /*
  193. * On call the number of entries which can be stored in buffer. On
  194. * return the number of entries which have been stored in
  195. * buffer.
  196. */
  197. unsigned int nr_entries;
  198. /*
  199. * Entries in the buffer are in the same format as returned by the
  200. * BIOS INT 0x15 EAX=0xE820 call.
  201. */
  202. GUEST_HANDLE(void)buffer;
  203. };
  204. DEFINE_GUEST_HANDLE_STRUCT(xen_memory_map);
  205. /*
  206. * Returns the real physical memory map. Passes the same structure as
  207. * XENMEM_memory_map.
  208. * arg == addr of struct xen_memory_map.
  209. */
  210. #define XENMEM_machine_memory_map 10
  211. /*
  212. * Unmaps the page appearing at a particular GPFN from the specified guest's
  213. * pseudophysical address space.
  214. * arg == addr of xen_remove_from_physmap_t.
  215. */
  216. #define XENMEM_remove_from_physmap 15
  217. struct xen_remove_from_physmap {
  218. /* Which domain to change the mapping for. */
  219. domid_t domid;
  220. /* GPFN of the current mapping of the page. */
  221. xen_pfn_t gpfn;
  222. };
  223. DEFINE_GUEST_HANDLE_STRUCT(xen_remove_from_physmap);
  224. /*
  225. * Get the pages for a particular guest resource, so that they can be
  226. * mapped directly by a tools domain.
  227. */
  228. #define XENMEM_acquire_resource 28
  229. struct xen_mem_acquire_resource {
  230. /* IN - The domain whose resource is to be mapped */
  231. domid_t domid;
  232. /* IN - the type of resource */
  233. u16 type;
  234. #define XENMEM_resource_ioreq_server 0
  235. #define XENMEM_resource_grant_table 1
  236. /*
  237. * IN - a type-specific resource identifier, which must be zero
  238. * unless stated otherwise.
  239. *
  240. * type == XENMEM_resource_ioreq_server -> id == ioreq server id
  241. * type == XENMEM_resource_grant_table -> id defined below
  242. */
  243. u32 id;
  244. #define XENMEM_resource_grant_table_id_shared 0
  245. #define XENMEM_resource_grant_table_id_status 1
  246. /* IN/OUT - As an IN parameter number of frames of the resource
  247. * to be mapped. However, if the specified value is 0 and
  248. * frame_list is NULL then this field will be set to the
  249. * maximum value supported by the implementation on return.
  250. */
  251. u32 nr_frames;
  252. /*
  253. * OUT - Must be zero on entry. On return this may contain a bitwise
  254. * OR of the following values.
  255. */
  256. u32 flags;
  257. /* The resource pages have been assigned to the calling domain */
  258. #define _XENMEM_rsrc_acq_caller_owned 0
  259. #define XENMEM_rsrc_acq_caller_owned (1u << _XENMEM_rsrc_acq_caller_owned)
  260. /*
  261. * IN - the index of the initial frame to be mapped. This parameter
  262. * is ignored if nr_frames is 0.
  263. */
  264. u64 frame;
  265. #define XENMEM_resource_ioreq_server_frame_bufioreq 0
  266. #define XENMEM_resource_ioreq_server_frame_ioreq(n) (1 + (n))
  267. /*
  268. * IN/OUT - If the tools domain is PV then, upon return, frame_list
  269. * will be populated with the MFNs of the resource.
  270. * If the tools domain is HVM then it is expected that, on
  271. * entry, frame_list will be populated with a list of GFNs
  272. * that will be mapped to the MFNs of the resource.
  273. * If -EIO is returned then the frame_list has only been
  274. * partially mapped and it is up to the caller to unmap all
  275. * the GFNs.
  276. * This parameter may be NULL if nr_frames is 0.
  277. */
  278. GUEST_HANDLE(xen_pfn_t)frame_list;
  279. };
  280. DEFINE_GUEST_HANDLE_STRUCT(xen_mem_acquire_resource);
  281. #endif /* __XEN_PUBLIC_MEMORY_H__ */