-
-
Notifications
You must be signed in to change notification settings - Fork 601
/
virtio-rng.hh
57 lines (42 loc) · 1.12 KB
/
virtio-rng.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
* Copyright (C) 2013 Cloudius Systems, Ltd.
*
* This work is open source software, licensed under the terms of the
* BSD license as described in the LICENSE file in the top-level directory.
*/
#ifndef VIRTIO_RNG_DRIVER_H
#define VIRTIO_RNG_DRIVER_H
#include <osv/condvar.h>
#include <osv/device.h>
#include <osv/mutex.h>
#include "drivers/virtio.hh"
#include "drivers/device.hh"
#include "drivers/random.hh"
#include <vector>
namespace virtio {
class rng : public virtio_driver, randomdev::hw_rng {
public:
enum {
VIRTIO_RNG_DEVICE_ID = 0x1005,
};
explicit rng(pci::device& dev);
virtual ~rng();
virtual std::string get_name() const { return "virtio-rng"; }
virtual size_t get_random_bytes(char* buf, size_t size) override;
static hw_driver* probe(hw_device* dev);
private:
void handle_irq();
bool ack_irq();
void worker();
void refill();
static const size_t _pool_size = 64;
std::vector<char> _entropy;
pci_interrupt _irq;
std::unique_ptr<sched::thread> _thread;
condvar _producer;
condvar _consumer;
vring* _queue;
mutex _mtx;
};
}
#endif