]> git.proxmox.com Git - mirror_qemu.git/blame - include/sysemu/rng.h
Include hw/hw.h exactly where needed
[mirror_qemu.git] / include / sysemu / rng.h
CommitLineData
a9b7b2ad
AL
1/*
2 * QEMU Random Number Generator Backend
3 *
4 * Copyright IBM, Corp. 2012
5 *
6 * Authors:
7 * Anthony Liguori <aliguori@us.ibm.com>
8 *
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.
11 */
12
13#ifndef QEMU_RNG_H
14#define QEMU_RNG_H
15
14cccb61 16#include "qom/object.h"
a9b7b2ad
AL
17
18#define TYPE_RNG_BACKEND "rng-backend"
19#define RNG_BACKEND(obj) \
20 OBJECT_CHECK(RngBackend, (obj), TYPE_RNG_BACKEND)
21#define RNG_BACKEND_GET_CLASS(obj) \
22 OBJECT_GET_CLASS(RngBackendClass, (obj), TYPE_RNG_BACKEND)
23#define RNG_BACKEND_CLASS(klass) \
24 OBJECT_CLASS_CHECK(RngBackendClass, (klass), TYPE_RNG_BACKEND)
25
74074e8a 26typedef struct RngRequest RngRequest;
a9b7b2ad
AL
27typedef struct RngBackendClass RngBackendClass;
28typedef struct RngBackend RngBackend;
29
30typedef void (EntropyReceiveFunc)(void *opaque,
31 const void *data,
32 size_t size);
33
74074e8a
LP
34struct RngRequest
35{
36 EntropyReceiveFunc *receive_entropy;
37 uint8_t *data;
38 void *opaque;
39 size_t offset;
40 size_t size;
443590c2 41 QSIMPLEQ_ENTRY(RngRequest) next;
74074e8a
LP
42};
43
a9b7b2ad
AL
44struct RngBackendClass
45{
46 ObjectClass parent_class;
47
60253ed1 48 void (*request_entropy)(RngBackend *s, RngRequest *req);
a9b7b2ad
AL
49
50 void (*opened)(RngBackend *s, Error **errp);
51};
52
53struct RngBackend
54{
55 Object parent;
56
57 /*< protected >*/
58 bool opened;
b58deb34 59 QSIMPLEQ_HEAD(, RngRequest) requests;
a9b7b2ad
AL
60};
61
9f14b0ad 62
a9b7b2ad
AL
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
69 *
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
42015c9a 73 * backend will queue each request and handle appropriately.
a9b7b2ad
AL
74 *
75 * The backend does not need to pass the full amount of data to @receive_entropy
42015c9a 76 * but will pass a value greater than 0.
a9b7b2ad
AL
77 */
78void rng_backend_request_entropy(RngBackend *s, size_t size,
79 EntropyReceiveFunc *receive_entropy,
80 void *opaque);
9f14b0ad
LP
81
82/**
83 * rng_backend_free_request:
84 * @s: the backend that created the request
85 * @req: the request to finalize
86 *
87 * Used by child rng backend classes to finalize requests once they've been
88 * processed. The request is removed from the list of active requests and
89 * deleted.
90 */
91void rng_backend_finalize_request(RngBackend *s, RngRequest *req);
a9b7b2ad 92#endif