You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

hvm_op.h 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. /*
  2. * Permission is hereby granted, free of charge, to any person obtaining a copy
  3. * of this software and associated documentation files (the "Software"), to
  4. * deal in the Software without restriction, including without limitation the
  5. * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  6. * sell copies of the Software, and to permit persons to whom the Software is
  7. * furnished to do so, subject to the following conditions:
  8. *
  9. * The above copyright notice and this permission notice shall be included in
  10. * all copies or substantial portions of the Software.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  17. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  18. * DEALINGS IN THE SOFTWARE.
  19. */
  20. #ifndef __XEN_PUBLIC_HVM_HVM_OP_H__
  21. #define __XEN_PUBLIC_HVM_HVM_OP_H__
  22. FILE_LICENCE ( MIT );
  23. #include "../xen.h"
  24. #include "../trace.h"
  25. #include "../event_channel.h"
  26. /* Get/set subcommands: extra argument == pointer to xen_hvm_param struct. */
  27. #define HVMOP_set_param 0
  28. #define HVMOP_get_param 1
  29. struct xen_hvm_param {
  30. domid_t domid; /* IN */
  31. uint32_t index; /* IN */
  32. uint64_t value; /* IN/OUT */
  33. };
  34. typedef struct xen_hvm_param xen_hvm_param_t;
  35. DEFINE_XEN_GUEST_HANDLE(xen_hvm_param_t);
  36. /* Set the logical level of one of a domain's PCI INTx wires. */
  37. #define HVMOP_set_pci_intx_level 2
  38. struct xen_hvm_set_pci_intx_level {
  39. /* Domain to be updated. */
  40. domid_t domid;
  41. /* PCI INTx identification in PCI topology (domain:bus:device:intx). */
  42. uint8_t domain, bus, device, intx;
  43. /* Assertion level (0 = unasserted, 1 = asserted). */
  44. uint8_t level;
  45. };
  46. typedef struct xen_hvm_set_pci_intx_level xen_hvm_set_pci_intx_level_t;
  47. DEFINE_XEN_GUEST_HANDLE(xen_hvm_set_pci_intx_level_t);
  48. /* Set the logical level of one of a domain's ISA IRQ wires. */
  49. #define HVMOP_set_isa_irq_level 3
  50. struct xen_hvm_set_isa_irq_level {
  51. /* Domain to be updated. */
  52. domid_t domid;
  53. /* ISA device identification, by ISA IRQ (0-15). */
  54. uint8_t isa_irq;
  55. /* Assertion level (0 = unasserted, 1 = asserted). */
  56. uint8_t level;
  57. };
  58. typedef struct xen_hvm_set_isa_irq_level xen_hvm_set_isa_irq_level_t;
  59. DEFINE_XEN_GUEST_HANDLE(xen_hvm_set_isa_irq_level_t);
  60. #define HVMOP_set_pci_link_route 4
  61. struct xen_hvm_set_pci_link_route {
  62. /* Domain to be updated. */
  63. domid_t domid;
  64. /* PCI link identifier (0-3). */
  65. uint8_t link;
  66. /* ISA IRQ (1-15), or 0 (disable link). */
  67. uint8_t isa_irq;
  68. };
  69. typedef struct xen_hvm_set_pci_link_route xen_hvm_set_pci_link_route_t;
  70. DEFINE_XEN_GUEST_HANDLE(xen_hvm_set_pci_link_route_t);
  71. /* Flushes all VCPU TLBs: @arg must be NULL. */
  72. #define HVMOP_flush_tlbs 5
  73. typedef enum {
  74. HVMMEM_ram_rw, /* Normal read/write guest RAM */
  75. HVMMEM_ram_ro, /* Read-only; writes are discarded */
  76. HVMMEM_mmio_dm, /* Reads and write go to the device model */
  77. } hvmmem_type_t;
  78. /* Following tools-only interfaces may change in future. */
  79. #if defined(__XEN__) || defined(__XEN_TOOLS__)
  80. /* Track dirty VRAM. */
  81. #define HVMOP_track_dirty_vram 6
  82. struct xen_hvm_track_dirty_vram {
  83. /* Domain to be tracked. */
  84. domid_t domid;
  85. /* Number of pages to track. */
  86. uint32_t nr;
  87. /* First pfn to track. */
  88. uint64_aligned_t first_pfn;
  89. /* OUT variable. */
  90. /* Dirty bitmap buffer. */
  91. XEN_GUEST_HANDLE_64(uint8) dirty_bitmap;
  92. };
  93. typedef struct xen_hvm_track_dirty_vram xen_hvm_track_dirty_vram_t;
  94. DEFINE_XEN_GUEST_HANDLE(xen_hvm_track_dirty_vram_t);
  95. /* Notify that some pages got modified by the Device Model. */
  96. #define HVMOP_modified_memory 7
  97. struct xen_hvm_modified_memory {
  98. /* Domain to be updated. */
  99. domid_t domid;
  100. /* Number of pages. */
  101. uint32_t nr;
  102. /* First pfn. */
  103. uint64_aligned_t first_pfn;
  104. };
  105. typedef struct xen_hvm_modified_memory xen_hvm_modified_memory_t;
  106. DEFINE_XEN_GUEST_HANDLE(xen_hvm_modified_memory_t);
  107. #define HVMOP_set_mem_type 8
  108. /* Notify that a region of memory is to be treated in a specific way. */
  109. struct xen_hvm_set_mem_type {
  110. /* Domain to be updated. */
  111. domid_t domid;
  112. /* Memory type */
  113. uint16_t hvmmem_type;
  114. /* Number of pages. */
  115. uint32_t nr;
  116. /* First pfn. */
  117. uint64_aligned_t first_pfn;
  118. };
  119. typedef struct xen_hvm_set_mem_type xen_hvm_set_mem_type_t;
  120. DEFINE_XEN_GUEST_HANDLE(xen_hvm_set_mem_type_t);
  121. #endif /* defined(__XEN__) || defined(__XEN_TOOLS__) */
  122. /* Hint from PV drivers for pagetable destruction. */
  123. #define HVMOP_pagetable_dying 9
  124. struct xen_hvm_pagetable_dying {
  125. /* Domain with a pagetable about to be destroyed. */
  126. domid_t domid;
  127. uint16_t pad[3]; /* align next field on 8-byte boundary */
  128. /* guest physical address of the toplevel pagetable dying */
  129. uint64_t gpa;
  130. };
  131. typedef struct xen_hvm_pagetable_dying xen_hvm_pagetable_dying_t;
  132. DEFINE_XEN_GUEST_HANDLE(xen_hvm_pagetable_dying_t);
  133. /* Get the current Xen time, in nanoseconds since system boot. */
  134. #define HVMOP_get_time 10
  135. struct xen_hvm_get_time {
  136. uint64_t now; /* OUT */
  137. };
  138. typedef struct xen_hvm_get_time xen_hvm_get_time_t;
  139. DEFINE_XEN_GUEST_HANDLE(xen_hvm_get_time_t);
  140. #define HVMOP_xentrace 11
  141. struct xen_hvm_xentrace {
  142. uint16_t event, extra_bytes;
  143. uint8_t extra[TRACE_EXTRA_MAX * sizeof(uint32_t)];
  144. };
  145. typedef struct xen_hvm_xentrace xen_hvm_xentrace_t;
  146. DEFINE_XEN_GUEST_HANDLE(xen_hvm_xentrace_t);
  147. /* Following tools-only interfaces may change in future. */
  148. #if defined(__XEN__) || defined(__XEN_TOOLS__)
  149. /* Deprecated by XENMEM_access_op_set_access */
  150. #define HVMOP_set_mem_access 12
  151. /* Deprecated by XENMEM_access_op_get_access */
  152. #define HVMOP_get_mem_access 13
  153. #define HVMOP_inject_trap 14
  154. /* Inject a trap into a VCPU, which will get taken up on the next
  155. * scheduling of it. Note that the caller should know enough of the
  156. * state of the CPU before injecting, to know what the effect of
  157. * injecting the trap will be.
  158. */
  159. struct xen_hvm_inject_trap {
  160. /* Domain to be queried. */
  161. domid_t domid;
  162. /* VCPU */
  163. uint32_t vcpuid;
  164. /* Vector number */
  165. uint32_t vector;
  166. /* Trap type (HVMOP_TRAP_*) */
  167. uint32_t type;
  168. /* NB. This enumeration precisely matches hvm.h:X86_EVENTTYPE_* */
  169. # define HVMOP_TRAP_ext_int 0 /* external interrupt */
  170. # define HVMOP_TRAP_nmi 2 /* nmi */
  171. # define HVMOP_TRAP_hw_exc 3 /* hardware exception */
  172. # define HVMOP_TRAP_sw_int 4 /* software interrupt (CD nn) */
  173. # define HVMOP_TRAP_pri_sw_exc 5 /* ICEBP (F1) */
  174. # define HVMOP_TRAP_sw_exc 6 /* INT3 (CC), INTO (CE) */
  175. /* Error code, or ~0u to skip */
  176. uint32_t error_code;
  177. /* Intruction length */
  178. uint32_t insn_len;
  179. /* CR2 for page faults */
  180. uint64_aligned_t cr2;
  181. };
  182. typedef struct xen_hvm_inject_trap xen_hvm_inject_trap_t;
  183. DEFINE_XEN_GUEST_HANDLE(xen_hvm_inject_trap_t);
  184. #endif /* defined(__XEN__) || defined(__XEN_TOOLS__) */
  185. #define HVMOP_get_mem_type 15
  186. /* Return hvmmem_type_t for the specified pfn. */
  187. struct xen_hvm_get_mem_type {
  188. /* Domain to be queried. */
  189. domid_t domid;
  190. /* OUT variable. */
  191. uint16_t mem_type;
  192. uint16_t pad[2]; /* align next field on 8-byte boundary */
  193. /* IN variable. */
  194. uint64_t pfn;
  195. };
  196. typedef struct xen_hvm_get_mem_type xen_hvm_get_mem_type_t;
  197. DEFINE_XEN_GUEST_HANDLE(xen_hvm_get_mem_type_t);
  198. /* Following tools-only interfaces may change in future. */
  199. #if defined(__XEN__) || defined(__XEN_TOOLS__)
  200. /* MSI injection for emulated devices */
  201. #define HVMOP_inject_msi 16
  202. struct xen_hvm_inject_msi {
  203. /* Domain to be injected */
  204. domid_t domid;
  205. /* Data -- lower 32 bits */
  206. uint32_t data;
  207. /* Address (0xfeexxxxx) */
  208. uint64_t addr;
  209. };
  210. typedef struct xen_hvm_inject_msi xen_hvm_inject_msi_t;
  211. DEFINE_XEN_GUEST_HANDLE(xen_hvm_inject_msi_t);
  212. /*
  213. * IOREQ Servers
  214. *
  215. * The interface between an I/O emulator an Xen is called an IOREQ Server.
  216. * A domain supports a single 'legacy' IOREQ Server which is instantiated if
  217. * parameter...
  218. *
  219. * HVM_PARAM_IOREQ_PFN is read (to get the gmfn containing the synchronous
  220. * ioreq structures), or...
  221. * HVM_PARAM_BUFIOREQ_PFN is read (to get the gmfn containing the buffered
  222. * ioreq ring), or...
  223. * HVM_PARAM_BUFIOREQ_EVTCHN is read (to get the event channel that Xen uses
  224. * to request buffered I/O emulation).
  225. *
  226. * The following hypercalls facilitate the creation of IOREQ Servers for
  227. * 'secondary' emulators which are invoked to implement port I/O, memory, or
  228. * PCI config space ranges which they explicitly register.
  229. */
  230. typedef uint16_t ioservid_t;
  231. /*
  232. * HVMOP_create_ioreq_server: Instantiate a new IOREQ Server for a secondary
  233. * emulator servicing domain <domid>.
  234. *
  235. * The <id> handed back is unique for <domid>. If <handle_bufioreq> is zero
  236. * the buffered ioreq ring will not be allocated and hence all emulation
  237. * requestes to this server will be synchronous.
  238. */
  239. #define HVMOP_create_ioreq_server 17
  240. struct xen_hvm_create_ioreq_server {
  241. domid_t domid; /* IN - domain to be serviced */
  242. uint8_t handle_bufioreq; /* IN - should server handle buffered ioreqs */
  243. ioservid_t id; /* OUT - server id */
  244. };
  245. typedef struct xen_hvm_create_ioreq_server xen_hvm_create_ioreq_server_t;
  246. DEFINE_XEN_GUEST_HANDLE(xen_hvm_create_ioreq_server_t);
  247. /*
  248. * HVMOP_get_ioreq_server_info: Get all the information necessary to access
  249. * IOREQ Server <id>.
  250. *
  251. * The emulator needs to map the synchronous ioreq structures and buffered
  252. * ioreq ring (if it exists) that Xen uses to request emulation. These are
  253. * hosted in domain <domid>'s gmfns <ioreq_pfn> and <bufioreq_pfn>
  254. * respectively. In addition, if the IOREQ Server is handling buffered
  255. * emulation requests, the emulator needs to bind to event channel
  256. * <bufioreq_port> to listen for them. (The event channels used for
  257. * synchronous emulation requests are specified in the per-CPU ioreq
  258. * structures in <ioreq_pfn>).
  259. * If the IOREQ Server is not handling buffered emulation requests then the
  260. * values handed back in <bufioreq_pfn> and <bufioreq_port> will both be 0.
  261. */
  262. #define HVMOP_get_ioreq_server_info 18
  263. struct xen_hvm_get_ioreq_server_info {
  264. domid_t domid; /* IN - domain to be serviced */
  265. ioservid_t id; /* IN - server id */
  266. evtchn_port_t bufioreq_port; /* OUT - buffered ioreq port */
  267. uint64_aligned_t ioreq_pfn; /* OUT - sync ioreq pfn */
  268. uint64_aligned_t bufioreq_pfn; /* OUT - buffered ioreq pfn */
  269. };
  270. typedef struct xen_hvm_get_ioreq_server_info xen_hvm_get_ioreq_server_info_t;
  271. DEFINE_XEN_GUEST_HANDLE(xen_hvm_get_ioreq_server_info_t);
  272. /*
  273. * HVM_map_io_range_to_ioreq_server: Register an I/O range of domain <domid>
  274. * for emulation by the client of IOREQ
  275. * Server <id>
  276. * HVM_unmap_io_range_from_ioreq_server: Deregister an I/O range of <domid>
  277. * for emulation by the client of IOREQ
  278. * Server <id>
  279. *
  280. * There are three types of I/O that can be emulated: port I/O, memory accesses
  281. * and PCI config space accesses. The <type> field denotes which type of range
  282. * the <start> and <end> (inclusive) fields are specifying.
  283. * PCI config space ranges are specified by segment/bus/device/function values
  284. * which should be encoded using the HVMOP_PCI_SBDF helper macro below.
  285. *
  286. * NOTE: unless an emulation request falls entirely within a range mapped
  287. * by a secondary emulator, it will not be passed to that emulator.
  288. */
  289. #define HVMOP_map_io_range_to_ioreq_server 19
  290. #define HVMOP_unmap_io_range_from_ioreq_server 20
  291. struct xen_hvm_io_range {
  292. domid_t domid; /* IN - domain to be serviced */
  293. ioservid_t id; /* IN - server id */
  294. uint32_t type; /* IN - type of range */
  295. # define HVMOP_IO_RANGE_PORT 0 /* I/O port range */
  296. # define HVMOP_IO_RANGE_MEMORY 1 /* MMIO range */
  297. # define HVMOP_IO_RANGE_PCI 2 /* PCI segment/bus/dev/func range */
  298. uint64_aligned_t start, end; /* IN - inclusive start and end of range */
  299. };
  300. typedef struct xen_hvm_io_range xen_hvm_io_range_t;
  301. DEFINE_XEN_GUEST_HANDLE(xen_hvm_io_range_t);
  302. #define HVMOP_PCI_SBDF(s,b,d,f) \
  303. ((((s) & 0xffff) << 16) | \
  304. (((b) & 0xff) << 8) | \
  305. (((d) & 0x1f) << 3) | \
  306. ((f) & 0x07))
  307. /*
  308. * HVMOP_destroy_ioreq_server: Destroy the IOREQ Server <id> servicing domain
  309. * <domid>.
  310. *
  311. * Any registered I/O ranges will be automatically deregistered.
  312. */
  313. #define HVMOP_destroy_ioreq_server 21
  314. struct xen_hvm_destroy_ioreq_server {
  315. domid_t domid; /* IN - domain to be serviced */
  316. ioservid_t id; /* IN - server id */
  317. };
  318. typedef struct xen_hvm_destroy_ioreq_server xen_hvm_destroy_ioreq_server_t;
  319. DEFINE_XEN_GUEST_HANDLE(xen_hvm_destroy_ioreq_server_t);
  320. /*
  321. * HVMOP_set_ioreq_server_state: Enable or disable the IOREQ Server <id> servicing
  322. * domain <domid>.
  323. *
  324. * The IOREQ Server will not be passed any emulation requests until it is in the
  325. * enabled state.
  326. * Note that the contents of the ioreq_pfn and bufioreq_fn (see
  327. * HVMOP_get_ioreq_server_info) are not meaningful until the IOREQ Server is in
  328. * the enabled state.
  329. */
  330. #define HVMOP_set_ioreq_server_state 22
  331. struct xen_hvm_set_ioreq_server_state {
  332. domid_t domid; /* IN - domain to be serviced */
  333. ioservid_t id; /* IN - server id */
  334. uint8_t enabled; /* IN - enabled? */
  335. };
  336. typedef struct xen_hvm_set_ioreq_server_state xen_hvm_set_ioreq_server_state_t;
  337. DEFINE_XEN_GUEST_HANDLE(xen_hvm_set_ioreq_server_state_t);
  338. #endif /* defined(__XEN__) || defined(__XEN_TOOLS__) */
  339. #endif /* __XEN_PUBLIC_HVM_HVM_OP_H__ */
  340. /*
  341. * Local variables:
  342. * mode: C
  343. * c-file-style: "BSD"
  344. * c-basic-offset: 4
  345. * tab-width: 4
  346. * indent-tabs-mode: nil
  347. * End:
  348. */