X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fdevices%2Fnvram.c;h=016cf10b3ba2461ee24ab45e51baeca2ae15f81b;hb=7d58ea47e874cf90da52904c250f133010c5d4bb;hp=9c121726c4ffd79c9b52a0296021a5ab8a8ca0db;hpb=19380bd81ad18d160a6c30804f91c531b87ac69d;p=palacios-OLD.git diff --git a/palacios/src/devices/nvram.c b/palacios/src/devices/nvram.c index 9c12172..016cf10 100644 --- a/palacios/src/devices/nvram.c +++ b/palacios/src/devices/nvram.c @@ -29,6 +29,7 @@ #include #include + #ifndef CONFIG_DEBUG_NVRAM #undef PrintDebug #define PrintDebug(fmt, args...) @@ -107,6 +108,8 @@ struct nvram_internal { struct vm_device * ide; struct v3_vm_info * vm; + + struct v3_timer *timer; v3_lock_t nvram_lock; @@ -288,6 +291,7 @@ static void update_time(struct nvram_internal * data, uint32_t period_us) { uint8_t * month = (uint8_t *)&(data->mem_state[NVRAM_REG_MONTH]); uint8_t * year = (uint8_t *)&(data->mem_state[NVRAM_REG_YEAR]); uint8_t * cent = (uint8_t *)&(data->mem_state[NVRAM_REG_IBM_CENTURY_BYTE]); + uint8_t * cent_ps2 = (uint8_t *)&(data->mem_state[NVRAM_REG_IBM_PS2_CENTURY_BYTE]); uint8_t * seca = (uint8_t *)&(data->mem_state[NVRAM_REG_SEC_ALARM]); uint8_t * mina = (uint8_t *)&(data->mem_state[NVRAM_REG_MIN_ALARM]); uint8_t * houra = (uint8_t *)&(data->mem_state[NVRAM_REG_HOUR_ALARM]); @@ -417,6 +421,7 @@ static void update_time(struct nvram_internal * data, uint32_t period_us) { *year = 0; carry = 1; add_to(cent, &carry, bcd); + *cent_ps2 = *cent; } } } @@ -460,7 +465,7 @@ static void update_time(struct nvram_internal * data, uint32_t period_us) { } } - +/* static int handle_timer_event(struct v3_vm_info * vm, struct v3_timer_event * evt, void * priv_data) { @@ -476,7 +481,22 @@ static int handle_timer_event(struct v3_vm_info * vm, return 0; } +*/ +static void nvram_update_timer(struct guest_info *vm, + ullong_t cpu_cycles, + ullong_t cpu_freq, + void *priv_data) +{ + struct nvram_internal *nvram_state = (struct nvram_internal *)priv_data; + uint32_t period_us; + + + period_us = (uint32_t) (1000000*cpu_cycles/cpu_freq); + + update_time(nvram_state,period_us); + +} static void set_memory_size(struct nvram_internal * nvram, addr_t bytes) { @@ -684,6 +704,7 @@ static int init_nvram_state(struct v3_vm_info * vm, struct nvram_internal * nvra set_memory(nvram, NVRAM_REG_WEEK_DAY, 0x1); set_memory(nvram, NVRAM_REG_YEAR, 0x08); set_memory(nvram, NVRAM_REG_IBM_CENTURY_BYTE, 0x20); + set_memory(nvram, NVRAM_REG_IBM_PS2_CENTURY_BYTE, 0x20); set_memory(nvram, NVRAM_REG_DIAGNOSTIC_STATUS, 0x00); @@ -776,8 +797,13 @@ static int nvram_write_data_port(struct guest_info * core, uint16_t port, static int nvram_free(struct nvram_internal * nvram_state) { - + // unregister host events + struct guest_info *info = &(nvram_state->vm->cores[0]); + + if (nvram_state->timer) { + v3_remove_timer(info,nvram_state->timer); + } V3_Free(nvram_state); return 0; @@ -785,6 +811,9 @@ static int nvram_free(struct nvram_internal * nvram_state) { +static struct v3_timer_ops timer_ops = { + .update_timer = nvram_update_timer, +}; static struct v3_device_ops dev_ops = { @@ -834,7 +863,13 @@ static int nvram_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { return -1; } - v3_hook_host_event(vm, HOST_TIMER_EVT, V3_HOST_EVENT_HANDLER(handle_timer_event), nvram_state); + // v3_hook_host_event(vm, HOST_TIMER_EVT, V3_HOST_EVENT_HANDLER(handle_timer_event), nvram_state); + nvram_state->timer = v3_add_timer(&(vm->cores[0]),&timer_ops,nvram_state); + + if (nvram_state->timer == NULL ) { + v3_remove_device(dev); + return -1; + } return 0; }