2 * Jailhouse, a Linux-based partitioning hypervisor
4 * Copyright (c) Valentine Sinitsyn, 2014
7 * Valentine Sinitsyn <valentine.sinitsyn@gmail.com>
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
13 #ifndef _JAILHOUSE_ASM_VCPU_H
14 #define _JAILHOUSE_ASM_VCPU_H
16 #include <jailhouse/entry.h>
17 #include <jailhouse/cell-config.h>
18 #include <jailhouse/paging.h>
19 #include <jailhouse/types.h>
21 #include <asm/percpu.h>
22 #include <asm/processor.h>
24 #define X86_CR0_HOST_STATE \
25 (X86_CR0_PG | X86_CR0_WP | X86_CR0_NE | X86_CR0_ET | X86_CR0_TS | \
26 X86_CR0_MP | X86_CR0_PE)
27 #define X86_CR4_HOST_STATE X86_CR4_PAE
29 struct vcpu_io_bitmap {
34 struct vcpu_execution_state {
41 struct vcpu_io_intercept {
45 unsigned int inst_len;
49 struct vcpu_mmio_intercept {
54 int vcpu_vendor_init(void);
56 int vcpu_cell_init(struct cell *cell);
57 int vcpu_vendor_cell_init(struct cell *cell);
59 int vcpu_map_memory_region(struct cell *cell,
60 const struct jailhouse_memory *mem);
61 int vcpu_unmap_memory_region(struct cell *cell,
62 const struct jailhouse_memory *mem);
63 void vcpu_cell_exit(struct cell *cell);
64 void vcpu_vendor_cell_exit(struct cell *cell);
66 int vcpu_init(struct per_cpu *cpu_data);
67 void vcpu_exit(struct per_cpu *cpu_data);
69 void __attribute__((noreturn)) vcpu_activate_vmm(struct per_cpu *cpu_data);
70 void __attribute__((noreturn))
71 vcpu_deactivate_vmm(union registers *guest_regs);
73 void vcpu_handle_exit(union registers *guest_regs, struct per_cpu *cpu_data);
77 void vcpu_nmi_handler(void);
79 void vcpu_tlb_flush(void);
82 * vcpu_map_inst() and vcpu_get_inst_bytes() contract:
84 * On input, *size gives the number of bytes to get.
85 * On output, *size is the number of bytes available.
87 * If the function fails (returns NULL), *size is undefined.
90 const u8 *vcpu_map_inst(const struct guest_paging_structures *pg_structs,
91 unsigned long pc, unsigned int *size);
93 const u8 *vcpu_get_inst_bytes(const struct guest_paging_structures *pg_structs,
94 unsigned long pc, unsigned int *size);
96 void vcpu_skip_emulated_instruction(unsigned int inst_len);
98 void vcpu_vendor_get_cell_io_bitmap(struct cell *cell,
99 struct vcpu_io_bitmap *out);
101 void vcpu_vendor_get_execution_state(struct vcpu_execution_state *x_state);
102 void vcpu_vendor_get_io_intercept(struct vcpu_io_intercept *io);
103 void vcpu_vendor_get_mmio_intercept(struct vcpu_mmio_intercept *mmio);
105 bool vcpu_get_guest_paging_structs(struct guest_paging_structures *pg_structs);
107 void vcpu_vendor_set_guest_pat(unsigned long val);
109 void vcpu_handle_hypercall(union registers *guest_regs);
111 bool vcpu_handle_io_access(union registers *guest_regs);
112 bool vcpu_handle_mmio_access(union registers *guest_regs);
114 bool vcpu_handle_msr_read(union registers *guest_regs);
115 bool vcpu_handle_msr_write(union registers *guest_regs);
117 bool vcpu_handle_xsetbv(union registers *guest_regs);
119 void vcpu_reset(union registers *guest_regs);