test-bdrv-drain: fix iothread_join() hang
[qemu/ar7.git] / include / sysemu / cryptodev-vhost.h
blobf42824fbde43cebbdd58ec8cef3c313d507367eb
1 /*
2 * QEMU Crypto Device Common Vhost Implement
4 * Copyright (c) 2016 HUAWEI TECHNOLOGIES CO., LTD.
6 * Authors:
7 * Gonglei <arei.gonglei@huawei.com>
8 * Jay Zhou <jianjay.zhou@huawei.com>
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
24 #ifndef CRYPTODEV_VHOST_H
25 #define CRYPTODEV_VHOST_H
27 #include "hw/virtio/vhost.h"
28 #include "hw/virtio/vhost-backend.h"
29 #include "chardev/char.h"
31 #include "sysemu/cryptodev.h"
34 typedef struct CryptoDevBackendVhostOptions {
35 VhostBackendType backend_type;
36 void *opaque;
37 int total_queues;
38 CryptoDevBackendClient *cc;
39 } CryptoDevBackendVhostOptions;
41 typedef struct CryptoDevBackendVhost {
42 struct vhost_dev dev;
43 struct vhost_virtqueue vqs[1];
44 int backend;
45 CryptoDevBackendClient *cc;
46 } CryptoDevBackendVhost;
48 /**
49 * cryptodev_vhost_get_max_queues:
50 * @crypto: the cryptodev backend common vhost object
52 * Get the maximum queue number of @crypto.
55 * Returns: the maximum queue number
57 uint64_t
58 cryptodev_vhost_get_max_queues(
59 CryptoDevBackendVhost *crypto);
62 /**
63 * cryptodev_vhost_init:
64 * @options: the common vhost object's option
66 * Creates a new cryptodev backend common vhost object
68 ** The returned object must be released with
69 * cryptodev_vhost_cleanup() when no
70 * longer required
72 * Returns: the cryptodev backend common vhost object
74 struct CryptoDevBackendVhost *
75 cryptodev_vhost_init(
76 CryptoDevBackendVhostOptions *options);
78 /**
79 * cryptodev_vhost_cleanup:
80 * @crypto: the cryptodev backend common vhost object
82 * Clean the resouce associated with @crypto that realizaed
83 * by cryptodev_vhost_init()
86 void cryptodev_vhost_cleanup(
87 CryptoDevBackendVhost *crypto);
89 /**
90 * cryptodev_get_vhost:
91 * @cc: the client object for each queue
92 * @b: the cryptodev backend common vhost object
93 * @queue: the cryptodev backend queue index
95 * Gets a new cryptodev backend common vhost object based on
96 * @b and @queue
98 * Returns: the cryptodev backend common vhost object
100 CryptoDevBackendVhost *
101 cryptodev_get_vhost(CryptoDevBackendClient *cc,
102 CryptoDevBackend *b,
103 uint16_t queue);
105 * cryptodev_vhost_start:
106 * @dev: the virtio crypto object
107 * @total_queues: the total count of queue
109 * Starts the vhost crypto logic
111 * Returns: 0 for success, negative for errors
113 int cryptodev_vhost_start(VirtIODevice *dev, int total_queues);
116 * cryptodev_vhost_stop:
117 * @dev: the virtio crypto object
118 * @total_queues: the total count of queue
120 * Stops the vhost crypto logic
123 void cryptodev_vhost_stop(VirtIODevice *dev, int total_queues);
126 * cryptodev_vhost_virtqueue_mask:
127 * @dev: the virtio crypto object
128 * @queue: the cryptodev backend queue index
129 * @idx: the virtqueue index
130 * @mask: mask or not (true or false)
132 * Mask/unmask events for @idx virtqueue on @dev device
135 void cryptodev_vhost_virtqueue_mask(VirtIODevice *dev,
136 int queue,
137 int idx, bool mask);
140 * cryptodev_vhost_virtqueue_pending:
141 * @dev: the virtio crypto object
142 * @queue: the cryptodev backend queue index
143 * @idx: the virtqueue index
145 * Test and clear event pending status for @idx virtqueue on @dev device.
146 * Should be called after unmask to avoid losing events.
148 * Returns: true for success, false for errors
150 bool cryptodev_vhost_virtqueue_pending(VirtIODevice *dev,
151 int queue, int idx);
153 #endif /* CRYPTODEV_VHOST_H */