Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  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. FILE_LICENCE ( MIT );
  29. #include "xen.h"
  30. /*
  31. * Increase or decrease the specified domain's memory reservation. Returns the
  32. * number of extents successfully allocated or freed.
  33. * arg == addr of struct xen_memory_reservation.
  34. */
  35. #define XENMEM_increase_reservation 0
  36. #define XENMEM_decrease_reservation 1
  37. #define XENMEM_populate_physmap 6
  38. #if __XEN_INTERFACE_VERSION__ >= 0x00030209
  39. /*
  40. * Maximum # bits addressable by the user of the allocated region (e.g., I/O
  41. * devices often have a 32-bit limitation even in 64-bit systems). If zero
  42. * then the user has no addressing restriction. This field is not used by
  43. * XENMEM_decrease_reservation.
  44. */
  45. #define XENMEMF_address_bits(x) (x)
  46. #define XENMEMF_get_address_bits(x) ((x) & 0xffu)
  47. /* NUMA node to allocate from. */
  48. #define XENMEMF_node(x) (((x) + 1) << 8)
  49. #define XENMEMF_get_node(x) ((((x) >> 8) - 1) & 0xffu)
  50. /* Flag to populate physmap with populate-on-demand entries */
  51. #define XENMEMF_populate_on_demand (1<<16)
  52. /* Flag to request allocation only from the node specified */
  53. #define XENMEMF_exact_node_request (1<<17)
  54. #define XENMEMF_exact_node(n) (XENMEMF_node(n) | XENMEMF_exact_node_request)
  55. #endif
  56. struct xen_memory_reservation {
  57. /*
  58. * XENMEM_increase_reservation:
  59. * OUT: MFN (*not* GMFN) bases of extents that were allocated
  60. * XENMEM_decrease_reservation:
  61. * IN: GMFN bases of extents to free
  62. * XENMEM_populate_physmap:
  63. * IN: GPFN bases of extents to populate with memory
  64. * OUT: GMFN bases of extents that were allocated
  65. * (NB. This command also updates the mach_to_phys translation table)
  66. * XENMEM_claim_pages:
  67. * IN: must be zero
  68. */
  69. XEN_GUEST_HANDLE(xen_pfn_t) extent_start;
  70. /* Number of extents, and size/alignment of each (2^extent_order pages). */
  71. xen_ulong_t nr_extents;
  72. unsigned int extent_order;
  73. #if __XEN_INTERFACE_VERSION__ >= 0x00030209
  74. /* XENMEMF flags. */
  75. unsigned int mem_flags;
  76. #else
  77. unsigned int address_bits;
  78. #endif
  79. /*
  80. * Domain whose reservation is being changed.
  81. * Unprivileged domains can specify only DOMID_SELF.
  82. */
  83. domid_t domid;
  84. };
  85. typedef struct xen_memory_reservation xen_memory_reservation_t;
  86. DEFINE_XEN_GUEST_HANDLE(xen_memory_reservation_t);
  87. /*
  88. * An atomic exchange of memory pages. If return code is zero then
  89. * @out.extent_list provides GMFNs of the newly-allocated memory.
  90. * Returns zero on complete success, otherwise a negative error code.
  91. * On complete success then always @nr_exchanged == @in.nr_extents.
  92. * On partial success @nr_exchanged indicates how much work was done.
  93. */
  94. #define XENMEM_exchange 11
  95. struct xen_memory_exchange {
  96. /*
  97. * [IN] Details of memory extents to be exchanged (GMFN bases).
  98. * Note that @in.address_bits is ignored and unused.
  99. */
  100. struct xen_memory_reservation in;
  101. /*
  102. * [IN/OUT] Details of new memory extents.
  103. * We require that:
  104. * 1. @in.domid == @out.domid
  105. * 2. @in.nr_extents << @in.extent_order ==
  106. * @out.nr_extents << @out.extent_order
  107. * 3. @in.extent_start and @out.extent_start lists must not overlap
  108. * 4. @out.extent_start lists GPFN bases to be populated
  109. * 5. @out.extent_start is overwritten with allocated GMFN bases
  110. */
  111. struct xen_memory_reservation out;
  112. /*
  113. * [OUT] Number of input extents that were successfully exchanged:
  114. * 1. The first @nr_exchanged input extents were successfully
  115. * deallocated.
  116. * 2. The corresponding first entries in the output extent list correctly
  117. * indicate the GMFNs that were successfully exchanged.
  118. * 3. All other input and output extents are untouched.
  119. * 4. If not all input exents are exchanged then the return code of this
  120. * command will be non-zero.
  121. * 5. THIS FIELD MUST BE INITIALISED TO ZERO BY THE CALLER!
  122. */
  123. xen_ulong_t nr_exchanged;
  124. };
  125. typedef struct xen_memory_exchange xen_memory_exchange_t;
  126. DEFINE_XEN_GUEST_HANDLE(xen_memory_exchange_t);
  127. /*
  128. * Returns the maximum machine frame number of mapped RAM in this system.
  129. * This command always succeeds (it never returns an error code).
  130. * arg == NULL.
  131. */
  132. #define XENMEM_maximum_ram_page 2
  133. /*
  134. * Returns the current or maximum memory reservation, in pages, of the
  135. * specified domain (may be DOMID_SELF). Returns -ve errcode on failure.
  136. * arg == addr of domid_t.
  137. */
  138. #define XENMEM_current_reservation 3
  139. #define XENMEM_maximum_reservation 4
  140. /*
  141. * Returns the maximum GPFN in use by the guest, or -ve errcode on failure.
  142. */
  143. #define XENMEM_maximum_gpfn 14
  144. /*
  145. * Returns a list of MFN bases of 2MB extents comprising the machine_to_phys
  146. * mapping table. Architectures which do not have a m2p table do not implement
  147. * this command.
  148. * arg == addr of xen_machphys_mfn_list_t.
  149. */
  150. #define XENMEM_machphys_mfn_list 5
  151. struct xen_machphys_mfn_list {
  152. /*
  153. * Size of the 'extent_start' array. Fewer entries will be filled if the
  154. * machphys table is smaller than max_extents * 2MB.
  155. */
  156. unsigned int max_extents;
  157. /*
  158. * Pointer to buffer to fill with list of extent starts. If there are
  159. * any large discontiguities in the machine address space, 2MB gaps in
  160. * the machphys table will be represented by an MFN base of zero.
  161. */
  162. XEN_GUEST_HANDLE(xen_pfn_t) extent_start;
  163. /*
  164. * Number of extents written to the above array. This will be smaller
  165. * than 'max_extents' if the machphys table is smaller than max_e * 2MB.
  166. */
  167. unsigned int nr_extents;
  168. };
  169. typedef struct xen_machphys_mfn_list xen_machphys_mfn_list_t;
  170. DEFINE_XEN_GUEST_HANDLE(xen_machphys_mfn_list_t);
  171. /*
  172. * For a compat caller, this is identical to XENMEM_machphys_mfn_list.
  173. *
  174. * For a non compat caller, this functions similarly to
  175. * XENMEM_machphys_mfn_list, but returns the mfns making up the compatibility
  176. * m2p table.
  177. */
  178. #define XENMEM_machphys_compat_mfn_list 25
  179. /*
  180. * Returns the location in virtual address space of the machine_to_phys
  181. * mapping table. Architectures which do not have a m2p table, or which do not
  182. * map it by default into guest address space, do not implement this command.
  183. * arg == addr of xen_machphys_mapping_t.
  184. */
  185. #define XENMEM_machphys_mapping 12
  186. struct xen_machphys_mapping {
  187. xen_ulong_t v_start, v_end; /* Start and end virtual addresses. */
  188. xen_ulong_t max_mfn; /* Maximum MFN that can be looked up. */
  189. };
  190. typedef struct xen_machphys_mapping xen_machphys_mapping_t;
  191. DEFINE_XEN_GUEST_HANDLE(xen_machphys_mapping_t);
  192. /* Source mapping space. */
  193. /* ` enum phys_map_space { */
  194. #define XENMAPSPACE_shared_info 0 /* shared info page */
  195. #define XENMAPSPACE_grant_table 1 /* grant table page */
  196. #define XENMAPSPACE_gmfn 2 /* GMFN */
  197. #define XENMAPSPACE_gmfn_range 3 /* GMFN range, XENMEM_add_to_physmap only. */
  198. #define XENMAPSPACE_gmfn_foreign 4 /* GMFN from another dom,
  199. * XENMEM_add_to_physmap_batch only. */
  200. /* ` } */
  201. /*
  202. * Sets the GPFN at which a particular page appears in the specified guest's
  203. * pseudophysical address space.
  204. * arg == addr of xen_add_to_physmap_t.
  205. */
  206. #define XENMEM_add_to_physmap 7
  207. struct xen_add_to_physmap {
  208. /* Which domain to change the mapping for. */
  209. domid_t domid;
  210. /* Number of pages to go through for gmfn_range */
  211. uint16_t size;
  212. unsigned int space; /* => enum phys_map_space */
  213. #define XENMAPIDX_grant_table_status 0x80000000
  214. /* Index into space being mapped. */
  215. xen_ulong_t idx;
  216. /* GPFN in domid where the source mapping page should appear. */
  217. xen_pfn_t gpfn;
  218. };
  219. typedef struct xen_add_to_physmap xen_add_to_physmap_t;
  220. DEFINE_XEN_GUEST_HANDLE(xen_add_to_physmap_t);
  221. /* A batched version of add_to_physmap. */
  222. #define XENMEM_add_to_physmap_batch 23
  223. struct xen_add_to_physmap_batch {
  224. /* IN */
  225. /* Which domain to change the mapping for. */
  226. domid_t domid;
  227. uint16_t space; /* => enum phys_map_space */
  228. /* Number of pages to go through */
  229. uint16_t size;
  230. domid_t foreign_domid; /* IFF gmfn_foreign */
  231. /* Indexes into space being mapped. */
  232. XEN_GUEST_HANDLE(xen_ulong_t) idxs;
  233. /* GPFN in domid where the source mapping page should appear. */
  234. XEN_GUEST_HANDLE(xen_pfn_t) gpfns;
  235. /* OUT */
  236. /* Per index error code. */
  237. XEN_GUEST_HANDLE(int) errs;
  238. };
  239. typedef struct xen_add_to_physmap_batch xen_add_to_physmap_batch_t;
  240. DEFINE_XEN_GUEST_HANDLE(xen_add_to_physmap_batch_t);
  241. #if __XEN_INTERFACE_VERSION__ < 0x00040400
  242. #define XENMEM_add_to_physmap_range XENMEM_add_to_physmap_batch
  243. #define xen_add_to_physmap_range xen_add_to_physmap_batch
  244. typedef struct xen_add_to_physmap_batch xen_add_to_physmap_range_t;
  245. DEFINE_XEN_GUEST_HANDLE(xen_add_to_physmap_range_t);
  246. #endif
  247. /*
  248. * Unmaps the page appearing at a particular GPFN from the specified guest's
  249. * pseudophysical address space.
  250. * arg == addr of xen_remove_from_physmap_t.
  251. */
  252. #define XENMEM_remove_from_physmap 15
  253. struct xen_remove_from_physmap {
  254. /* Which domain to change the mapping for. */
  255. domid_t domid;
  256. /* GPFN of the current mapping of the page. */
  257. xen_pfn_t gpfn;
  258. };
  259. typedef struct xen_remove_from_physmap xen_remove_from_physmap_t;
  260. DEFINE_XEN_GUEST_HANDLE(xen_remove_from_physmap_t);
  261. /*** REMOVED ***/
  262. /*#define XENMEM_translate_gpfn_list 8*/
  263. /*
  264. * Returns the pseudo-physical memory map as it was when the domain
  265. * was started (specified by XENMEM_set_memory_map).
  266. * arg == addr of xen_memory_map_t.
  267. */
  268. #define XENMEM_memory_map 9
  269. struct xen_memory_map {
  270. /*
  271. * On call the number of entries which can be stored in buffer. On
  272. * return the number of entries which have been stored in
  273. * buffer.
  274. */
  275. unsigned int nr_entries;
  276. /*
  277. * Entries in the buffer are in the same format as returned by the
  278. * BIOS INT 0x15 EAX=0xE820 call.
  279. */
  280. XEN_GUEST_HANDLE(void) buffer;
  281. };
  282. typedef struct xen_memory_map xen_memory_map_t;
  283. DEFINE_XEN_GUEST_HANDLE(xen_memory_map_t);
  284. /*
  285. * Returns the real physical memory map. Passes the same structure as
  286. * XENMEM_memory_map.
  287. * arg == addr of xen_memory_map_t.
  288. */
  289. #define XENMEM_machine_memory_map 10
  290. /*
  291. * Set the pseudo-physical memory map of a domain, as returned by
  292. * XENMEM_memory_map.
  293. * arg == addr of xen_foreign_memory_map_t.
  294. */
  295. #define XENMEM_set_memory_map 13
  296. struct xen_foreign_memory_map {
  297. domid_t domid;
  298. struct xen_memory_map map;
  299. };
  300. typedef struct xen_foreign_memory_map xen_foreign_memory_map_t;
  301. DEFINE_XEN_GUEST_HANDLE(xen_foreign_memory_map_t);
  302. #define XENMEM_set_pod_target 16
  303. #define XENMEM_get_pod_target 17
  304. struct xen_pod_target {
  305. /* IN */
  306. uint64_t target_pages;
  307. /* OUT */
  308. uint64_t tot_pages;
  309. uint64_t pod_cache_pages;
  310. uint64_t pod_entries;
  311. /* IN */
  312. domid_t domid;
  313. };
  314. typedef struct xen_pod_target xen_pod_target_t;
  315. #if defined(__XEN__) || defined(__XEN_TOOLS__)
  316. #ifndef uint64_aligned_t
  317. #define uint64_aligned_t uint64_t
  318. #endif
  319. /*
  320. * Get the number of MFNs saved through memory sharing.
  321. * The call never fails.
  322. */
  323. #define XENMEM_get_sharing_freed_pages 18
  324. #define XENMEM_get_sharing_shared_pages 19
  325. #define XENMEM_paging_op 20
  326. #define XENMEM_paging_op_nominate 0
  327. #define XENMEM_paging_op_evict 1
  328. #define XENMEM_paging_op_prep 2
  329. struct xen_mem_event_op {
  330. uint8_t op; /* XENMEM_*_op_* */
  331. domid_t domain;
  332. /* PAGING_PREP IN: buffer to immediately fill page in */
  333. uint64_aligned_t buffer;
  334. /* Other OPs */
  335. uint64_aligned_t gfn; /* IN: gfn of page being operated on */
  336. };
  337. typedef struct xen_mem_event_op xen_mem_event_op_t;
  338. DEFINE_XEN_GUEST_HANDLE(xen_mem_event_op_t);
  339. #define XENMEM_access_op 21
  340. #define XENMEM_access_op_resume 0
  341. #define XENMEM_access_op_set_access 1
  342. #define XENMEM_access_op_get_access 2
  343. typedef enum {
  344. XENMEM_access_n,
  345. XENMEM_access_r,
  346. XENMEM_access_w,
  347. XENMEM_access_rw,
  348. XENMEM_access_x,
  349. XENMEM_access_rx,
  350. XENMEM_access_wx,
  351. XENMEM_access_rwx,
  352. /*
  353. * Page starts off as r-x, but automatically
  354. * change to r-w on a write
  355. */
  356. XENMEM_access_rx2rw,
  357. /*
  358. * Log access: starts off as n, automatically
  359. * goes to rwx, generating an event without
  360. * pausing the vcpu
  361. */
  362. XENMEM_access_n2rwx,
  363. /* Take the domain default */
  364. XENMEM_access_default
  365. } xenmem_access_t;
  366. struct xen_mem_access_op {
  367. /* XENMEM_access_op_* */
  368. uint8_t op;
  369. /* xenmem_access_t */
  370. uint8_t access;
  371. domid_t domid;
  372. /*
  373. * Number of pages for set op
  374. * Ignored on setting default access and other ops
  375. */
  376. uint32_t nr;
  377. /*
  378. * First pfn for set op
  379. * pfn for get op
  380. * ~0ull is used to set and get the default access for pages
  381. */
  382. uint64_aligned_t pfn;
  383. };
  384. typedef struct xen_mem_access_op xen_mem_access_op_t;
  385. DEFINE_XEN_GUEST_HANDLE(xen_mem_access_op_t);
  386. #define XENMEM_sharing_op 22
  387. #define XENMEM_sharing_op_nominate_gfn 0
  388. #define XENMEM_sharing_op_nominate_gref 1
  389. #define XENMEM_sharing_op_share 2
  390. #define XENMEM_sharing_op_resume 3
  391. #define XENMEM_sharing_op_debug_gfn 4
  392. #define XENMEM_sharing_op_debug_mfn 5
  393. #define XENMEM_sharing_op_debug_gref 6
  394. #define XENMEM_sharing_op_add_physmap 7
  395. #define XENMEM_sharing_op_audit 8
  396. #define XENMEM_SHARING_OP_S_HANDLE_INVALID (-10)
  397. #define XENMEM_SHARING_OP_C_HANDLE_INVALID (-9)
  398. /* The following allows sharing of grant refs. This is useful
  399. * for sharing utilities sitting as "filters" in IO backends
  400. * (e.g. memshr + blktap(2)). The IO backend is only exposed
  401. * to grant references, and this allows sharing of the grefs */
  402. #define XENMEM_SHARING_OP_FIELD_IS_GREF_FLAG (1ULL << 62)
  403. #define XENMEM_SHARING_OP_FIELD_MAKE_GREF(field, val) \
  404. (field) = (XENMEM_SHARING_OP_FIELD_IS_GREF_FLAG | val)
  405. #define XENMEM_SHARING_OP_FIELD_IS_GREF(field) \
  406. ((field) & XENMEM_SHARING_OP_FIELD_IS_GREF_FLAG)
  407. #define XENMEM_SHARING_OP_FIELD_GET_GREF(field) \
  408. ((field) & (~XENMEM_SHARING_OP_FIELD_IS_GREF_FLAG))
  409. struct xen_mem_sharing_op {
  410. uint8_t op; /* XENMEM_sharing_op_* */
  411. domid_t domain;
  412. union {
  413. struct mem_sharing_op_nominate { /* OP_NOMINATE_xxx */
  414. union {
  415. uint64_aligned_t gfn; /* IN: gfn to nominate */
  416. uint32_t grant_ref; /* IN: grant ref to nominate */
  417. } u;
  418. uint64_aligned_t handle; /* OUT: the handle */
  419. } nominate;
  420. struct mem_sharing_op_share { /* OP_SHARE/ADD_PHYSMAP */
  421. uint64_aligned_t source_gfn; /* IN: the gfn of the source page */
  422. uint64_aligned_t source_handle; /* IN: handle to the source page */
  423. uint64_aligned_t client_gfn; /* IN: the client gfn */
  424. uint64_aligned_t client_handle; /* IN: handle to the client page */
  425. domid_t client_domain; /* IN: the client domain id */
  426. } share;
  427. struct mem_sharing_op_debug { /* OP_DEBUG_xxx */
  428. union {
  429. uint64_aligned_t gfn; /* IN: gfn to debug */
  430. uint64_aligned_t mfn; /* IN: mfn to debug */
  431. uint32_t gref; /* IN: gref to debug */
  432. } u;
  433. } debug;
  434. } u;
  435. };
  436. typedef struct xen_mem_sharing_op xen_mem_sharing_op_t;
  437. DEFINE_XEN_GUEST_HANDLE(xen_mem_sharing_op_t);
  438. /*
  439. * Attempt to stake a claim for a domain on a quantity of pages
  440. * of system RAM, but _not_ assign specific pageframes. Only
  441. * arithmetic is performed so the hypercall is very fast and need
  442. * not be preemptible, thus sidestepping time-of-check-time-of-use
  443. * races for memory allocation. Returns 0 if the hypervisor page
  444. * allocator has atomically and successfully claimed the requested
  445. * number of pages, else non-zero.
  446. *
  447. * Any domain may have only one active claim. When sufficient memory
  448. * has been allocated to resolve the claim, the claim silently expires.
  449. * Claiming zero pages effectively resets any outstanding claim and
  450. * is always successful.
  451. *
  452. * Note that a valid claim may be staked even after memory has been
  453. * allocated for a domain. In this case, the claim is not incremental,
  454. * i.e. if the domain's tot_pages is 3, and a claim is staked for 10,
  455. * only 7 additional pages are claimed.
  456. *
  457. * Caller must be privileged or the hypercall fails.
  458. */
  459. #define XENMEM_claim_pages 24
  460. /*
  461. * XENMEM_claim_pages flags - the are no flags at this time.
  462. * The zero value is appropiate.
  463. */
  464. #endif /* defined(__XEN__) || defined(__XEN_TOOLS__) */
  465. /* Next available subop number is 26 */
  466. #endif /* __XEN_PUBLIC_MEMORY_H__ */
  467. /*
  468. * Local variables:
  469. * mode: C
  470. * c-file-style: "BSD"
  471. * c-basic-offset: 4
  472. * tab-width: 4
  473. * indent-tabs-mode: nil
  474. * End:
  475. */