X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fdevices%2Fnvram.c;h=e811ec271d487afdfb1d80f2db275cfb764e72d3;hb=570ad6257ed18fbbc840c17a600f12f2dc44b010;hp=fb5b9eb6a4016855a5f857e53ecd5d58b27e078a;hpb=7841dc573457c334a0f3b6e9186d26b1776c400f;p=palacios.git diff --git a/palacios/src/devices/nvram.c b/palacios/src/devices/nvram.c index fb5b9eb..e811ec2 100644 --- a/palacios/src/devices/nvram.c +++ b/palacios/src/devices/nvram.c @@ -10,7 +10,7 @@ extern struct vmm_os_hooks *os_hooks; -typedef enum {NVRAM_READY,NVRAM_REG_POSTED} nvram_state_t; +typedef enum {NVRAM_READY, NVRAM_REG_POSTED} nvram_state_t; #define NVRAM_REG_MAX 256 @@ -52,7 +52,7 @@ struct nvram_internal { -int nvram_reset_device(struct vm_device *dev) +int nvram_reset_device(struct vm_device * dev) { struct nvram_internal *data = (struct nvram_internal *) dev->private_data; @@ -63,140 +63,106 @@ int nvram_reset_device(struct vm_device *dev) } -int nvram_init_device(struct vm_device *dev, struct vm_guest *vm) -{ - struct nvram_internal *data = (struct nvram_internal *) dev->private_data; - - memset(data->mem_state,0,NVRAM_REG_MAX); - nvram_reset_device(dev); - // hook ports - dev_mgr_hook_io(dev->vm, - dev, - NVRAM_REG_PORT, - DEVICE_EMULATED, - DEVICE_WRITE); - - dev_mgr_hook_io(dev->vm, - dev, - NVRAM_DATA_PORT, - DEVICE_EMULATED, - DEVICE_READWRITE); - return 0; -} -int nvram_deinit_device(struct vm_device *dev) +int nvram_start_device(struct vm_device *dev) { - - nvram_reset_device(dev); - - dev_mgr_unhook_device(dev->vm,dev); - return 0; } +int nvram_stop_device(struct vm_device *dev) +{ + return 0; +} -int nvram_start_device(struct vm_device *dev) +int nvram_write_reg_port(ushort_t port, + void * src, + uint_t length, + struct vm_device * dev) { - return 0; -} + struct nvram_internal *data = (struct nvram_internal *) dev->private_data; + memcpy(&(data->thereg), src, 1); -int nvram_stop_device(struct vm_device *dev) -{ return 0; } - -int nvram_read_io_port(ushort_t port_read, - void *address, +int nvram_read_data_port(ushort_t port, + void * dst, uint_t length, - struct vm_device *dev) + struct vm_device * dev) { struct nvram_internal *data = (struct nvram_internal *) dev->private_data; - switch (port_read) { - case NVRAM_REG_PORT: - // nonsense - memset(address,0,length); - break; - case NVRAM_DATA_PORT: - memcpy(address,&(data->mem_state[data->thereg]),1); - break; - default: - //bad - return -1; - } + memcpy(dst, &(data->mem_state[data->thereg]), 1); + return 0; } -int nvram_write_io_port(ushort_t port_written, - void *address, +int nvram_write_data_port(ushort_t port, + void * src, uint_t length, - struct vm_device *dev) + struct vm_device * dev) { struct nvram_internal *data = (struct nvram_internal *) dev->private_data; - switch (port_written) { - case NVRAM_REG_PORT: - memcpy(&(data->thereg),address,1); - break; - case NVRAM_DATA_PORT: - memcpy(&(data->mem_state[data->thereg]),address,1); - break; - default: - //bad - return -1; - } + memcpy(&(data->mem_state[data->thereg]), src, 1); + return 0; } -int nvram_read_mapped_memory(void *address_read, - void *address, - uint_t length, - struct vm_device *dev) -{ - return -1; + +int nvram_init_device(struct vm_device * dev) { + struct nvram_internal *data = (struct nvram_internal *) dev->private_data; + + memset(data->mem_state, 0, NVRAM_REG_MAX); + + nvram_reset_device(dev); + + // hook ports + dev_hook_io(dev, NVRAM_REG_PORT, NULL, &nvram_write_reg_port); + dev_hook_io(dev, NVRAM_DATA_PORT, &nvram_read_data_port, &nvram_write_data_port); + + return 0; } -int nvram_write_mapped_memory(void *address_written, - void *address, - uint_t length, - struct vm_device *dev) +int nvram_deinit_device(struct vm_device *dev) { - return -1; + + + dev_unhook_io(dev, NVRAM_REG_PORT); + dev_unhook_io(dev, NVRAM_DATA_PORT); + + nvram_reset_device(dev); + return 0; } -static struct vm_device nvram_template = - { .init_device = nvram_init_device, - .deinit_device = nvram_deinit_device, - .reset_device = nvram_reset_device, - .start_device = nvram_start_device, - .stop_device = nvram_stop_device, - .read_io_port = nvram_read_io_port, - .write_io_port = nvram_write_io_port, - .read_mapped_memory = nvram_read_mapped_memory, - .write_mapped_memory= nvram_write_mapped_memory, - }; -struct vm_device *nvram_create() -{ - struct vm_device *device = os_hooks->malloc(sizeof(struct vm_device)); +static struct vm_device_ops dev_ops = { + .init = nvram_init_device, + .deinit = nvram_deinit_device, + .reset = nvram_reset_device, + .start = nvram_start_device, + .stop = nvram_stop_device, +}; + + - *device = nvram_template; +struct vm_device *nvram_create() { + struct nvram_internal * nvram_state = os_hooks->malloc(sizeof(struct nvram_internal)); - device->private_data = os_hooks->malloc(sizeof(struct nvram_internal)); + struct vm_device *device = create_device("NVRAM", &dev_ops, nvram_state); return device; }