roms: Flush icache when writing roms to guest memory
[qemu/ar7.git] / backends / rng.c
blob85cb83f5e1ea9025b23b1596a5c05d4451e89218
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 #include "sysemu/rng.h"
14 #include "qapi/qmp/qerror.h"
16 void rng_backend_request_entropy(RngBackend *s, size_t size,
17 EntropyReceiveFunc *receive_entropy,
18 void *opaque)
20 RngBackendClass *k = RNG_BACKEND_GET_CLASS(s);
22 if (k->request_entropy) {
23 k->request_entropy(s, size, receive_entropy, opaque);
27 void rng_backend_cancel_requests(RngBackend *s)
29 RngBackendClass *k = RNG_BACKEND_GET_CLASS(s);
31 if (k->cancel_requests) {
32 k->cancel_requests(s);
36 static bool rng_backend_prop_get_opened(Object *obj, Error **errp)
38 RngBackend *s = RNG_BACKEND(obj);
40 return s->opened;
43 void rng_backend_open(RngBackend *s, Error **errp)
45 object_property_set_bool(OBJECT(s), true, "opened", errp);
48 static void rng_backend_prop_set_opened(Object *obj, bool value, Error **errp)
50 RngBackend *s = RNG_BACKEND(obj);
51 RngBackendClass *k = RNG_BACKEND_GET_CLASS(s);
53 if (value == s->opened) {
54 return;
57 if (!value && s->opened) {
58 error_set(errp, QERR_PERMISSION_DENIED);
59 return;
62 if (k->opened) {
63 k->opened(s, errp);
66 if (!error_is_set(errp)) {
67 s->opened = value;
71 static void rng_backend_init(Object *obj)
73 object_property_add_bool(obj, "opened",
74 rng_backend_prop_get_opened,
75 rng_backend_prop_set_opened,
76 NULL);
79 static const TypeInfo rng_backend_info = {
80 .name = TYPE_RNG_BACKEND,
81 .parent = TYPE_OBJECT,
82 .instance_size = sizeof(RngBackend),
83 .instance_init = rng_backend_init,
84 .class_size = sizeof(RngBackendClass),
85 .abstract = true,
88 static void register_types(void)
90 type_register_static(&rng_backend_info);
93 type_init(register_types);