Lines Matching refs:vrng
25 static bool is_guest_ready(VirtIORNG *vrng) in is_guest_ready() argument
27 VirtIODevice *vdev = VIRTIO_DEVICE(vrng); in is_guest_ready()
28 if (virtio_queue_ready(vrng->vq) in is_guest_ready()
32 trace_virtio_rng_guest_not_ready(vrng); in is_guest_ready()
44 static void virtio_rng_process(VirtIORNG *vrng);
49 VirtIORNG *vrng = opaque; in chr_read() local
50 VirtIODevice *vdev = VIRTIO_DEVICE(vrng); in chr_read()
55 if (!is_guest_ready(vrng)) { in chr_read()
64 trace_virtio_rng_cpu_is_stopped(vrng, size); in chr_read()
68 vrng->quota_remaining -= size; in chr_read()
72 elem = virtqueue_pop(vrng->vq, sizeof(VirtQueueElement)); in chr_read()
76 trace_virtio_rng_popped(vrng); in chr_read()
81 virtqueue_push(vrng->vq, elem, len); in chr_read()
82 trace_virtio_rng_pushed(vrng, len); in chr_read()
85 virtio_notify(vdev, vrng->vq); in chr_read()
87 if (!virtio_queue_empty(vrng->vq)) { in chr_read()
91 virtio_rng_process(vrng); in chr_read()
95 static void virtio_rng_process(VirtIORNG *vrng) in virtio_rng_process() argument
100 if (!is_guest_ready(vrng)) { in virtio_rng_process()
104 if (vrng->activate_timer) { in virtio_rng_process()
105 timer_mod(vrng->rate_limit_timer, in virtio_rng_process()
106 qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + vrng->conf.period_ms); in virtio_rng_process()
107 vrng->activate_timer = false; in virtio_rng_process()
110 if (vrng->quota_remaining < 0) { in virtio_rng_process()
113 quota = MIN((uint64_t)vrng->quota_remaining, (uint64_t)UINT32_MAX); in virtio_rng_process()
115 size = get_request_size(vrng->vq, quota); in virtio_rng_process()
117 trace_virtio_rng_request(vrng, size, quota); in virtio_rng_process()
119 size = MIN(vrng->quota_remaining, size); in virtio_rng_process()
121 rng_backend_request_entropy(vrng->rng, size, chr_read, vrng); in virtio_rng_process()
127 VirtIORNG *vrng = VIRTIO_RNG(vdev); in handle_input() local
128 virtio_rng_process(vrng); in handle_input()
139 VirtIORNG *vrng = opaque; in virtio_rng_vm_state_change() local
141 trace_virtio_rng_vm_state_change(vrng, running, state); in virtio_rng_vm_state_change()
148 if (running && is_guest_ready(vrng)) { in virtio_rng_vm_state_change()
149 virtio_rng_process(vrng); in virtio_rng_vm_state_change()
155 VirtIORNG *vrng = opaque; in check_rate_limit() local
157 vrng->quota_remaining = vrng->conf.max_bytes; in check_rate_limit()
158 virtio_rng_process(vrng); in check_rate_limit()
159 vrng->activate_timer = true; in check_rate_limit()
164 VirtIORNG *vrng = VIRTIO_RNG(vdev); in virtio_rng_set_status() local
172 virtio_rng_process(vrng); in virtio_rng_set_status()
178 VirtIORNG *vrng = VIRTIO_RNG(dev); in virtio_rng_device_realize() local
180 if (vrng->conf.period_ms <= 0) { in virtio_rng_device_realize()
187 if (vrng->conf.max_bytes == 0 || in virtio_rng_device_realize()
188 vrng->conf.max_bytes > INT64_MAX) { in virtio_rng_device_realize()
194 if (vrng->conf.rng == NULL) { in virtio_rng_device_realize()
213 vrng->rng = vrng->conf.rng; in virtio_rng_device_realize()
214 if (vrng->rng == NULL) { in virtio_rng_device_realize()
221 vrng->vq = virtio_add_queue(vdev, 8, handle_input); in virtio_rng_device_realize()
222 vrng->quota_remaining = vrng->conf.max_bytes; in virtio_rng_device_realize()
223 vrng->rate_limit_timer = timer_new_ms(QEMU_CLOCK_VIRTUAL, in virtio_rng_device_realize()
224 check_rate_limit, vrng); in virtio_rng_device_realize()
225 vrng->activate_timer = true; in virtio_rng_device_realize()
227 vrng->vmstate = qemu_add_vm_change_state_handler(virtio_rng_vm_state_change, in virtio_rng_device_realize()
228 vrng); in virtio_rng_device_realize()
234 VirtIORNG *vrng = VIRTIO_RNG(dev); in virtio_rng_device_unrealize() local
236 qemu_del_vm_change_state_handler(vrng->vmstate); in virtio_rng_device_unrealize()
237 timer_free(vrng->rate_limit_timer); in virtio_rng_device_unrealize()