X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fdevices%2Fgeneric.c;h=9c9b2902bae7aaf603783a00803c6df4ded32b35;hb=7e99758f3884f8f3d3f8895d9e4461f456331483;hp=21b2fc4201ff2c79cb1d4fe5ee09246e5f3c69fd;hpb=eaf7c604f327a4ab0435d5c88c0eaf418be3f3ea;p=palacios.git diff --git a/palacios/src/devices/generic.c b/palacios/src/devices/generic.c index 21b2fc4..9c9b290 100644 --- a/palacios/src/devices/generic.c +++ b/palacios/src/devices/generic.c @@ -26,11 +26,11 @@ #include #include -#ifdef CONFIG_HOST_DEVICE +#ifdef V3_CONFIG_HOST_DEVICE #include #endif -#ifndef CONFIG_DEBUG_GENERIC +#ifndef V3_CONFIG_DEBUG_GENERIC #undef PrintDebug #define PrintDebug(fmt, args...) #endif @@ -45,7 +45,7 @@ typedef enum {GENERIC_IGNORE, struct generic_internal { enum {GENERIC_PHYSICAL, GENERIC_HOST} forward_type; -#ifdef CONFIG_HOST_DEVICE +#ifdef V3_CONFIG_HOST_DEVICE v3_host_dev_t host_dev; #endif struct vm_device *dev; // me @@ -88,7 +88,7 @@ static int generic_write_port_passthrough(struct guest_info * core, } return length; break; -#ifdef CONFIG_HOST_DEVICE +#ifdef V3_CONFIG_HOST_DEVICE case GENERIC_HOST: if (state->host_dev) { return v3_host_dev_write_io(state->host_dev,port,src,length); @@ -109,7 +109,7 @@ static int generic_write_port_print_and_passthrough(struct guest_info * core, ui uint_t i; int rc; -#ifdef CONFIG_DEBUG_GENERIC +#ifdef V3_CONFIG_DEBUG_GENERIC struct generic_internal *state = (struct generic_internal *) priv_data; #endif @@ -162,7 +162,7 @@ static int generic_read_port_passthrough(struct guest_info * core, } return length; break; -#ifdef CONFIG_HOST_DEVICE +#ifdef V3_CONFIG_HOST_DEVICE case GENERIC_HOST: if (state->host_dev) { return v3_host_dev_read_io(state->host_dev,port,dst,length); @@ -183,7 +183,7 @@ static int generic_read_port_print_and_passthrough(struct guest_info * core, uin uint_t i; int rc; -#ifdef CONFIG_DEBUG_GENERIC +#ifdef V3_CONFIG_DEBUG_GENERIC struct generic_internal *state = (struct generic_internal *) priv_data; #endif @@ -217,7 +217,7 @@ static int generic_read_port_ignore(struct guest_info * core, uint16_t port, voi static int generic_read_port_print_and_ignore(struct guest_info * core, uint16_t port, void * src, uint_t length, void * priv_data) { -#ifdef CONFIG_DEBUG_GENERIC +#ifdef V3_CONFIG_DEBUG_GENERIC struct generic_internal *state = (struct generic_internal *) priv_data; #endif @@ -242,7 +242,7 @@ static int generic_write_port_print_and_ignore(struct guest_info * core, uint16_ uint_t length, void * priv_data) { int i; -#ifdef CONFIG_DEBUG_GENERIC +#ifdef V3_CONFIG_DEBUG_GENERIC struct generic_internal *state = (struct generic_internal *) priv_data; #endif @@ -278,7 +278,7 @@ static int generic_write_mem_passthrough(struct guest_info * core, memcpy(V3_VAddr((void*)gpa),src,len); return len; break; -#ifdef CONFIG_HOST_DEVICE +#ifdef V3_CONFIG_HOST_DEVICE case GENERIC_HOST: if (state->host_dev) { return v3_host_dev_write_mem(state->host_dev,gpa,src,len); @@ -300,7 +300,7 @@ static int generic_write_mem_print_and_passthrough(struct guest_info * core, uint_t len, void * priv) { -#ifdef CONFIG_DEBUG_GENERIC +#ifdef V3_CONFIG_DEBUG_GENERIC struct vm_device *dev = (struct vm_device *) priv; struct generic_internal *state = (struct generic_internal *) dev->private_data; #endif @@ -332,7 +332,7 @@ static int generic_write_mem_print_and_ignore(struct guest_info * core, uint_t len, void * priv) { -#ifdef CONFIG_DEBUG_GENERIC +#ifdef V3_CONFIG_DEBUG_GENERIC struct vm_device *dev = (struct vm_device *) priv; struct generic_internal *state = (struct generic_internal *) dev->private_data; #endif @@ -359,7 +359,7 @@ static int generic_read_mem_passthrough(struct guest_info * core, memcpy(dst,V3_VAddr((void*)gpa),len); return len; break; -#ifdef CONFIG_HOST_DEVICE +#ifdef V3_CONFIG_HOST_DEVICE case GENERIC_HOST: if (state->host_dev) { return v3_host_dev_read_mem(state->host_dev,gpa,dst,len); @@ -382,7 +382,7 @@ static int generic_read_mem_print_and_passthrough(struct guest_info * core, uint_t len, void * priv) { -#ifdef CONFIG_DEBUG_GENERIC +#ifdef V3_CONFIG_DEBUG_GENERIC struct vm_device *dev = (struct vm_device *) priv; struct generic_internal *state = (struct generic_internal *) dev->private_data; #endif @@ -405,7 +405,7 @@ static int generic_read_mem_ignore(struct guest_info * core, uint_t len, void * priv) { -#ifdef CONFIG_DEBUG_GENERIC +#ifdef V3_CONFIG_DEBUG_GENERIC struct vm_device *dev = (struct vm_device *) priv; struct generic_internal *state = (struct generic_internal *) dev->private_data; #endif @@ -439,7 +439,7 @@ static int generic_free(struct generic_internal * state) { PrintDebug("generic (%s): deinit_device\n", state->name); -#ifdef CONFIG_HOST_DEVICE +#ifdef V3_CONFIG_HOST_DEVICE if (state->host_dev) { v3_host_dev_close(state->host_dev); state->host_dev=0; @@ -565,7 +565,7 @@ static int add_mem_range(struct vm_device * dev, addr_t start, addr_t end, gener return -1; } break; - + case GENERIC_IGNORE: if (v3_hook_full_mem(dev->vm, V3_MEM_CORE_ANY, start, end+1, &generic_read_mem_ignore, @@ -578,10 +578,51 @@ static int add_mem_range(struct vm_device * dev, addr_t start, addr_t end, gener PrintError("generic (%s): huh?\n",state->name); break; } + + return 0; +} + + +#if 1 + +//This is a hack for host device testing and will be removed + +static int osdebug_hcall(struct guest_info *core, uint_t hcall_id, void * priv_data) +{ + struct generic_internal * state = (struct generic_internal *)priv_data; + + int msg_len = core->vm_regs.rcx; + addr_t msg_gpa = core->vm_regs.rbx; + int buf_is_va = core->vm_regs.rdx; + int i; + uint8_t c; + + PrintDebug("generic (%s): handling hypercall (len=%d) as sequence of port writes\n", + state->name, msg_len); + + + for (i=0;iname); + return -1; + } + } else { + if (v3_read_gpa_memory(core, msg_gpa+i, 1, &c) != 1) { + PrintError("generic (%s): Could not read debug message\n",state->name); + return -1; + } + } + if (generic_write_port_print_and_passthrough(core,0xc0c0,&c,1,priv_data)!=1) { + PrintError("generic (%s): write port passthrough failed\n",state->name); + return -1; + } + } return 0; } +#endif /* @@ -622,7 +663,7 @@ static int generic_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { struct generic_internal * state = NULL; char * dev_id = v3_cfg_val(cfg, "ID"); char * forward = v3_cfg_val(cfg, "forward"); -#ifdef CONFIG_HOST_DEVICE +#ifdef V3_CONFIG_HOST_DEVICE char * host_dev = v3_cfg_val(cfg, "hostdev"); #endif v3_cfg_tree_t * port_cfg = v3_cfg_subtree(cfg, "ports"); @@ -645,7 +686,7 @@ static int generic_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { if (!strcasecmp(forward,"physical_device")) { state->forward_type=GENERIC_PHYSICAL; } else if (!strcasecmp(forward,"host_device")) { -#ifdef CONFIG_HOST_DEVICE +#ifdef V3_CONFIG_HOST_DEVICE state->forward_type=GENERIC_HOST; #else PrintError("generic (%s): cannot configure host device since host device support is not built in\n", state->name); @@ -670,14 +711,14 @@ static int generic_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { state->dev=dev; -#ifdef CONFIG_HOST_DEVICE +#ifdef V3_CONFIG_HOST_DEVICE if (state->forward_type==GENERIC_HOST) { if (!host_dev) { PrintError("generic (%s): host forwarding requested, but no host device given\n", state->name); v3_remove_device(dev); return -1; } else { - state->host_dev = v3_host_dev_open(host_dev,V3_BUS_CLASS_DIRECT,dev); + state->host_dev = v3_host_dev_open(host_dev,V3_BUS_CLASS_DIRECT,dev,vm); if (!(state->host_dev)) { PrintError("generic (%s): unable to open host device \"%s\"\n", state->name,host_dev); v3_remove_device(dev); @@ -759,6 +800,14 @@ static int generic_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { mem_cfg = v3_cfg_next_branch(port_cfg); } + +#if 1 + // hack for os debug testing + if (strcasecmp(state->name,"os debug")==0) { + PrintDebug("generic (%s): adding hypercall for os debug device\n", state->name); + v3_register_hypercall(vm,0xc0c0,osdebug_hcall,state); + } +#endif PrintDebug("generic (%s): initialization complete\n", state->name);