khypervisor
v1
|
00001 #ifndef __CONTEXT_H__ 00002 #define __CONTEXT_H__ 00003 00004 #include <k-hypervisor-config.h> 00005 #include "arch_types.h" 00006 #include "vgic.h" 00007 #include "lpae.h" 00008 00009 #define ARCH_REGS_NUM_GPR 13 00010 00011 typedef enum { 00012 HYP_RESULT_ERET = 0, 00013 HYP_RESULT_STAY = 1 00014 } hyp_hvc_result_t; 00015 00016 struct arch_regs { 00017 uint32_t cpsr; /* CPSR */ 00018 uint32_t pc; /* Program Counter */ 00019 uint32_t lr; 00020 uint32_t gpr[ARCH_REGS_NUM_GPR]; /* R0 - R12 */ 00021 } __attribute((packed)); 00022 00023 /* co-processor registers: cp15, cp2 */ 00024 struct arch_regs_cop { 00025 uint32_t vbar; 00026 uint32_t ttbr0; 00027 uint32_t ttbr1; 00028 uint32_t ttbcr; 00029 uint32_t sctlr; 00030 }; 00031 00032 /* banked registers */ 00033 struct arch_regs_banked { 00034 uint32_t sp_usr; 00035 uint32_t spsr_svc; 00036 uint32_t sp_svc; 00037 uint32_t lr_svc; 00038 uint32_t spsr_abt; 00039 uint32_t sp_abt; 00040 uint32_t lr_abt; 00041 uint32_t spsr_und; 00042 uint32_t sp_und; 00043 uint32_t lr_und; 00044 uint32_t spsr_irq; 00045 uint32_t sp_irq; 00046 uint32_t lr_irq; 00047 00048 uint32_t spsr_fiq; 00049 //Cortex-A15 processor does not support sp_fiq 00050 //uint32_t sp_fiq; 00051 uint32_t lr_fiq; 00052 uint32_t r8_fiq; 00053 uint32_t r9_fiq; 00054 uint32_t r10_fiq; 00055 uint32_t r11_fiq; 00056 uint32_t r12_fiq; 00057 }; 00058 00059 struct hyp_guest_context { 00060 struct arch_regs regs; 00061 lpaed_t *ttbl; 00062 vmid_t vmid; 00063 struct vgic_status vgic_status; 00064 struct arch_regs_cop regs_cop; 00065 struct arch_regs_banked regs_banked; 00066 }; 00067 00068 void context_dump_regs( struct arch_regs *regs ); 00069 void context_switch_to_initial_guest(void); 00070 void context_init_guests(void); 00071 /* 00072 * Example: 00073 * // determine the next guest 00074 * 00075 * next = context_next_vmid(context_current_vmid()) 00076 * if ( next == VMID_INVALID ) next = context_first_vmid(); 00077 * 00078 * // request switching 00079 * context_switchto(next); 00080 * ... 00081 * // only once before leaving hyp mode 00082 * context_perform_switch(); 00083 */ 00084 hvmm_status_t context_perform_switch(void); 00085 00086 /* VMID of the current guest */ 00087 vmid_t context_current_vmid(void); 00088 00089 /* VMID of the next guest to be switched to */ 00090 vmid_t context_waiting_vmid(void); 00091 00092 /* Requests switch to the guest 'vmid' */ 00093 hvmm_status_t context_switchto(vmid_t vmid); 00094 hvmm_status_t context_switchto_lock(vmid_t vmid, uint8_t locked); 00095 00096 /* available guest vmid query */ 00097 vmid_t context_first_vmid(void); 00098 vmid_t context_last_vmid(void); 00099 vmid_t context_next_vmid(vmid_t ofvmid); 00100 struct hyp_guest_context *context_atvmid(vmid_t vmid); 00101 00102 void start_guest_os(void); 00103 00104 #endif // __CONTEXT_H__