khypervisor
v1
|
00001 #include <generic_timer.h> 00002 #include <hvmm_trace.h> 00003 #include "generic_timer_regs.h" 00004 00005 #include <config/cfg_platform.h> 00006 00007 static void _generic_timer_hyp_irq_handler(int irq, void *regs, void *pdata); 00008 00009 static uint32_t _timer_irqs[GENERIC_TIMER_NUM_TYPES]; 00010 static uint32_t _tvals[GENERIC_TIMER_NUM_TYPES]; 00011 static generic_timer_callback_t _callback[GENERIC_TIMER_NUM_TYPES]; 00012 00013 hvmm_status_t generic_timer_init() 00014 { 00015 _timer_irqs[GENERIC_TIMER_HYP] = 26; 00016 _timer_irqs[GENERIC_TIMER_NSP] = 27; 00017 _timer_irqs[GENERIC_TIMER_VIR] = 30; 00018 00019 return HVMM_STATUS_SUCCESS; 00020 } 00021 00022 00023 hvmm_status_t generic_timer_set_tval(generic_timer_type_t type, uint32_t tval) 00024 { 00025 hvmm_status_t result = HVMM_STATUS_UNSUPPORTED_FEATURE; 00026 00027 if ( type == GENERIC_TIMER_HYP) { 00028 _tvals[type] = tval; 00029 generic_timer_reg_write(GENERIC_TIMER_REG_HYP_TVAL, tval); 00030 result = HVMM_STATUS_SUCCESS; 00031 } else { 00032 } 00033 00034 return result; 00035 } 00036 00037 hvmm_status_t generic_timer_enable_int(generic_timer_type_t type ) 00038 { 00039 uint32_t ctrl; 00040 hvmm_status_t result = HVMM_STATUS_UNSUPPORTED_FEATURE; 00041 00042 if ( type == GENERIC_TIMER_HYP ) { 00043 ctrl = generic_timer_reg_read(GENERIC_TIMER_REG_HYP_CTRL); 00044 ctrl |= GENERIC_TIMER_CTRL_ENABLE; 00045 ctrl &= ~GENERIC_TIMER_CTRL_IMASK; 00046 00047 generic_timer_reg_write(GENERIC_TIMER_REG_HYP_CTRL, ctrl); 00048 result = HVMM_STATUS_SUCCESS; 00049 } 00050 00051 return result; 00052 } 00053 00054 hvmm_status_t generic_timer_disable_int(generic_timer_type_t type) 00055 { 00056 uint32_t ctrl; 00057 hvmm_status_t result = HVMM_STATUS_UNSUPPORTED_FEATURE; 00058 00059 if ( type == GENERIC_TIMER_HYP ) { 00060 ctrl = generic_timer_reg_read(GENERIC_TIMER_REG_HYP_CTRL); 00061 ctrl &= ~GENERIC_TIMER_CTRL_ENABLE; 00062 ctrl |= GENERIC_TIMER_CTRL_IMASK; 00063 00064 generic_timer_reg_write(GENERIC_TIMER_REG_HYP_CTRL, ctrl); 00065 result = HVMM_STATUS_SUCCESS; 00066 } 00067 00068 return result; 00069 } 00070 00071 static void _generic_timer_hyp_irq_handler(int irq, void *regs, void *pdata) 00072 { 00073 _callback[GENERIC_TIMER_HYP](regs); 00074 } 00075 00076 hvmm_status_t generic_timer_enable_irq(generic_timer_type_t type) 00077 { 00078 hvmm_status_t result = HVMM_STATUS_UNSUPPORTED_FEATURE; 00079 00080 if ( type == GENERIC_TIMER_HYP ) { 00081 uint32_t irq = _timer_irqs[type]; 00082 00083 gic_test_set_irq_handler(irq, &_generic_timer_hyp_irq_handler, 0); 00084 00085 gic_test_configure_irq(irq, 00086 GIC_INT_POLARITY_LEVEL, 00087 gic_cpumask_current(), 00088 GIC_INT_PRIORITY_DEFAULT ); 00089 00090 result = HVMM_STATUS_SUCCESS; 00091 } 00092 return result; 00093 } 00094 00095 hvmm_status_t generic_timer_set_callback(generic_timer_type_t type, generic_timer_callback_t callback) 00096 { 00097 HVMM_TRACE_ENTER(); 00098 00099 _callback[type] = callback; 00100 00101 HVMM_TRACE_EXIT(); 00102 return HVMM_STATUS_SUCCESS; 00103 } 00104