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