Commit 5703c174ff8bd2072e6cb77d87fa3e85c98bf043
1 parent
c72d5bf8
cuda: improve date/time read/write
- Allow date/time to be written - Use qemu_get_timedate() to initialize the clock Signed-off-by: Aurelien Jarno <aurelien@aurel32.net> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6313 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
1 changed file
with
19 additions
and
4 deletions
hw/cuda.c
@@ -131,6 +131,8 @@ typedef struct CUDAState { | @@ -131,6 +131,8 @@ typedef struct CUDAState { | ||
131 | 131 | ||
132 | CUDATimer timers[2]; | 132 | CUDATimer timers[2]; |
133 | 133 | ||
134 | + uint32_t tick_offset; | ||
135 | + | ||
134 | uint8_t last_b; /* last value of B register */ | 136 | uint8_t last_b; /* last value of B register */ |
135 | uint8_t last_acr; /* last value of B register */ | 137 | uint8_t last_acr; /* last value of B register */ |
136 | 138 | ||
@@ -510,7 +512,8 @@ static void cuda_receive_packet(CUDAState *s, | @@ -510,7 +512,8 @@ static void cuda_receive_packet(CUDAState *s, | ||
510 | const uint8_t *data, int len) | 512 | const uint8_t *data, int len) |
511 | { | 513 | { |
512 | uint8_t obuf[16]; | 514 | uint8_t obuf[16]; |
513 | - int ti, autopoll; | 515 | + int autopoll; |
516 | + uint32_t ti; | ||
514 | 517 | ||
515 | switch(data[0]) { | 518 | switch(data[0]) { |
516 | case CUDA_AUTOPOLL: | 519 | case CUDA_AUTOPOLL: |
@@ -529,10 +532,16 @@ static void cuda_receive_packet(CUDAState *s, | @@ -529,10 +532,16 @@ static void cuda_receive_packet(CUDAState *s, | ||
529 | obuf[1] = data[1]; | 532 | obuf[1] = data[1]; |
530 | cuda_send_packet_to_host(s, obuf, 2); | 533 | cuda_send_packet_to_host(s, obuf, 2); |
531 | break; | 534 | break; |
532 | - case CUDA_GET_TIME: | ||
533 | case CUDA_SET_TIME: | 535 | case CUDA_SET_TIME: |
534 | - /* XXX: add time support ? */ | ||
535 | - ti = time(NULL) + RTC_OFFSET; | 536 | + ti = (((uint32_t)data[1]) << 24) + (((uint32_t)data[2]) << 16) + (((uint32_t)data[3]) << 8) + data[4]; |
537 | + s->tick_offset = ti - (qemu_get_clock(vm_clock) / ticks_per_sec); | ||
538 | + obuf[0] = CUDA_PACKET; | ||
539 | + obuf[1] = 0; | ||
540 | + obuf[2] = 0; | ||
541 | + cuda_send_packet_to_host(s, obuf, 3); | ||
542 | + break; | ||
543 | + case CUDA_GET_TIME: | ||
544 | + ti = s->tick_offset + (qemu_get_clock(vm_clock) / ticks_per_sec); | ||
536 | obuf[0] = CUDA_PACKET; | 545 | obuf[0] = CUDA_PACKET; |
537 | obuf[1] = 0; | 546 | obuf[1] = 0; |
538 | obuf[2] = 0; | 547 | obuf[2] = 0; |
@@ -663,6 +672,7 @@ static void cuda_save(QEMUFile *f, void *opaque) | @@ -663,6 +672,7 @@ static void cuda_save(QEMUFile *f, void *opaque) | ||
663 | qemu_put_ubyte(f, s->autopoll); | 672 | qemu_put_ubyte(f, s->autopoll); |
664 | qemu_put_buffer(f, s->data_in, sizeof(s->data_in)); | 673 | qemu_put_buffer(f, s->data_in, sizeof(s->data_in)); |
665 | qemu_put_buffer(f, s->data_out, sizeof(s->data_out)); | 674 | qemu_put_buffer(f, s->data_out, sizeof(s->data_out)); |
675 | + qemu_put_be32s(f, &s->tick_offset); | ||
666 | cuda_save_timer(f, &s->timers[0]); | 676 | cuda_save_timer(f, &s->timers[0]); |
667 | cuda_save_timer(f, &s->timers[1]); | 677 | cuda_save_timer(f, &s->timers[1]); |
668 | } | 678 | } |
@@ -700,6 +710,7 @@ static int cuda_load(QEMUFile *f, void *opaque, int version_id) | @@ -700,6 +710,7 @@ static int cuda_load(QEMUFile *f, void *opaque, int version_id) | ||
700 | s->autopoll = qemu_get_ubyte(f); | 710 | s->autopoll = qemu_get_ubyte(f); |
701 | qemu_get_buffer(f, s->data_in, sizeof(s->data_in)); | 711 | qemu_get_buffer(f, s->data_in, sizeof(s->data_in)); |
702 | qemu_get_buffer(f, s->data_out, sizeof(s->data_out)); | 712 | qemu_get_buffer(f, s->data_out, sizeof(s->data_out)); |
713 | + qemu_get_be32s(f, &s->tick_offset); | ||
703 | cuda_load_timer(f, &s->timers[0]); | 714 | cuda_load_timer(f, &s->timers[0]); |
704 | cuda_load_timer(f, &s->timers[1]); | 715 | cuda_load_timer(f, &s->timers[1]); |
705 | 716 | ||
@@ -735,6 +746,7 @@ static void cuda_reset(void *opaque) | @@ -735,6 +746,7 @@ static void cuda_reset(void *opaque) | ||
735 | 746 | ||
736 | void cuda_init (int *cuda_mem_index, qemu_irq irq) | 747 | void cuda_init (int *cuda_mem_index, qemu_irq irq) |
737 | { | 748 | { |
749 | + struct tm tm; | ||
738 | CUDAState *s = &cuda_state; | 750 | CUDAState *s = &cuda_state; |
739 | 751 | ||
740 | s->irq = irq; | 752 | s->irq = irq; |
@@ -744,6 +756,9 @@ void cuda_init (int *cuda_mem_index, qemu_irq irq) | @@ -744,6 +756,9 @@ void cuda_init (int *cuda_mem_index, qemu_irq irq) | ||
744 | 756 | ||
745 | s->timers[1].index = 1; | 757 | s->timers[1].index = 1; |
746 | 758 | ||
759 | + qemu_get_timedate(&tm, RTC_OFFSET); | ||
760 | + s->tick_offset = mktimegm(&tm); | ||
761 | + | ||
747 | s->adb_poll_timer = qemu_new_timer(vm_clock, cuda_adb_poll, s); | 762 | s->adb_poll_timer = qemu_new_timer(vm_clock, cuda_adb_poll, s); |
748 | *cuda_mem_index = cpu_register_io_memory(0, cuda_read, cuda_write, s); | 763 | *cuda_mem_index = cpu_register_io_memory(0, cuda_read, cuda_write, s); |
749 | register_savevm("cuda", -1, 1, cuda_save, cuda_load, s); | 764 | register_savevm("cuda", -1, 1, cuda_save, cuda_load, s); |