khypervisor  v1
vdev/vdev_timer.c
Go to the documentation of this file.
00001 #include "vdev_timer.h"
00002 #include <context.h>
00003 
00004 #include <log/print.h>
00005 
00006 struct vdev_timer_regs{
00007     uint32_t timer_mask;
00008 };
00009 
00010 static vdev_info_t _vdev_info;
00011 static struct vdev_timer_regs regs[NUM_GUESTS_STATIC]; 
00012 
00013 static vtimer_changed_status_callback_t _write_status = 0;
00014 
00015 void vtimer_set_callback_chagned_status(vtimer_changed_status_callback_t callback)
00016 {
00017     _write_status = callback;
00018 }
00019 
00020 static void vtimer_changed_status( vmid_t vmid, uint32_t status )
00021 {
00022     if( _write_status != 0 ) {
00023         _write_status( vmid, status );
00024     }
00025 }
00026 
00027 static hvmm_status_t access_handler(uint32_t write, uint32_t offset, uint32_t *pvalue, vdev_access_size_t access_size)
00028 {
00029     printh( "%s: %s offset:%d value:%x\n", __FUNCTION__, write ? "write" : "read", offset, write ? *pvalue : (uint32_t) pvalue );
00030     hvmm_status_t result = HVMM_STATUS_BAD_ACCESS;
00031     unsigned int vmid = context_current_vmid();
00032     if (!write) {
00033         // READ
00034         switch (offset){
00035         case 0x0:
00036             *pvalue = regs[vmid].timer_mask;
00037             result = HVMM_STATUS_SUCCESS;
00038             break;
00039         }
00040     } else { 
00041         //WRITE
00042         switch (offset){
00043         case 0x0:
00044             regs[vmid].timer_mask = *pvalue;
00045             vtimer_changed_status(vmid, *pvalue);
00046             result = HVMM_STATUS_SUCCESS;
00047             break;
00048         }
00049     }
00050     return result;
00051 }
00052 
00053 hvmm_status_t vdev_timer_init(uint32_t base_addr)
00054 {
00055     hvmm_status_t result = HVMM_STATUS_BUSY;
00056 
00057     _vdev_info.name     = "vtimer";
00058     _vdev_info.base     = base_addr; 
00059     _vdev_info.size     = sizeof(struct vdev_timer_regs);
00060     _vdev_info.handler  = access_handler;
00061 
00062     result = vdev_reg_device(&_vdev_info);
00063     if ( result == HVMM_STATUS_SUCCESS ) {
00064         printh("%s: vdev registered:'%s'\n", __FUNCTION__, _vdev_info.name);
00065     } else {
00066         printh("%s: Unable to register vdev:'%s' code=%x\n", __FUNCTION__, _vdev_info.name, result);
00067     }
00068     return result;
00069 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines