rng: move request queue from RngEgd to RngBackend
[qemu/ar7.git] / include / sysemu / rng.h
blobc744d827452e3c9162143cec57c059d3f08eb6d3
1 /*
2 * QEMU Random Number Generator Backend
4 * Copyright IBM, Corp. 2012
6 * Authors:
7 * Anthony Liguori <aliguori@us.ibm.com>
9 * This work is licensed under the terms of the GNU GPL, version 2 or later.
10 * See the COPYING file in the top-level directory.
13 #ifndef QEMU_RNG_H
14 #define QEMU_RNG_H
16 #include "qom/object.h"
17 #include "qemu-common.h"
19 #define TYPE_RNG_BACKEND "rng-backend"
20 #define RNG_BACKEND(obj) \
21 OBJECT_CHECK(RngBackend, (obj), TYPE_RNG_BACKEND)
22 #define RNG_BACKEND_GET_CLASS(obj) \
23 OBJECT_GET_CLASS(RngBackendClass, (obj), TYPE_RNG_BACKEND)
24 #define RNG_BACKEND_CLASS(klass) \
25 OBJECT_CLASS_CHECK(RngBackendClass, (klass), TYPE_RNG_BACKEND)
27 typedef struct RngRequest RngRequest;
28 typedef struct RngBackendClass RngBackendClass;
29 typedef struct RngBackend RngBackend;
31 typedef void (EntropyReceiveFunc)(void *opaque,
32 const void *data,
33 size_t size);
35 struct RngRequest
37 EntropyReceiveFunc *receive_entropy;
38 uint8_t *data;
39 void *opaque;
40 size_t offset;
41 size_t size;
44 struct RngBackendClass
46 ObjectClass parent_class;
48 void (*request_entropy)(RngBackend *s, size_t size,
49 EntropyReceiveFunc *receive_entropy, void *opaque);
51 void (*opened)(RngBackend *s, Error **errp);
54 struct RngBackend
56 Object parent;
58 /*< protected >*/
59 bool opened;
60 GSList *requests;
63 /**
64 * rng_backend_request_entropy:
65 * @s: the backend to request entropy from
66 * @size: the number of bytes of data to request
67 * @receive_entropy: a function to be invoked when entropy is available
68 * @opaque: data that should be passed to @receive_entropy
70 * This function is used by the front-end to request entropy from an entropy
71 * source. This function can be called multiple times before @receive_entropy
72 * is invoked with different values of @receive_entropy and @opaque. The
73 * backend will queue each request and handle appropriately.
75 * The backend does not need to pass the full amount of data to @receive_entropy
76 * but will pass a value greater than 0.
78 void rng_backend_request_entropy(RngBackend *s, size_t size,
79 EntropyReceiveFunc *receive_entropy,
80 void *opaque);
81 #endif