2 * QEMU Crypto Device Common Vhost Implement
4 * Copyright (c) 2016 HUAWEI TECHNOLOGIES CO., LTD.
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 "qemu-common.h"
28 #include "hw/virtio/vhost.h"
29 #include "hw/virtio/vhost-backend.h"
30 #include "chardev/char.h"
32 #include "sysemu/cryptodev.h"
35 typedef struct CryptoDevBackendVhostOptions
{
36 VhostBackendType backend_type
;
39 CryptoDevBackendClient
*cc
;
40 } CryptoDevBackendVhostOptions
;
42 typedef struct CryptoDevBackendVhost
{
44 struct vhost_virtqueue vqs
[1];
46 CryptoDevBackendClient
*cc
;
47 } CryptoDevBackendVhost
;
50 * cryptodev_vhost_get_max_queues:
51 * @crypto: the cryptodev backend common vhost object
53 * Get the maximum queue number of @crypto.
56 * Returns: the maximum queue number
59 cryptodev_vhost_get_max_queues(
60 CryptoDevBackendVhost
*crypto
);
64 * cryptodev_vhost_init:
65 * @options: the common vhost object's option
67 * Creates a new cryptodev backend common vhost object
69 ** The returned object must be released with
70 * cryptodev_vhost_cleanup() when no
73 * Returns: the cryptodev backend common vhost object
75 struct CryptoDevBackendVhost
*
77 CryptoDevBackendVhostOptions
*options
);
80 * cryptodev_vhost_cleanup:
81 * @crypto: the cryptodev backend common vhost object
83 * Clean the resouce associated with @crypto that realizaed
84 * by cryptodev_vhost_init()
87 void cryptodev_vhost_cleanup(
88 CryptoDevBackendVhost
*crypto
);
91 * cryptodev_get_vhost:
92 * @cc: the client object for each queue
93 * @b: the cryptodev backend common vhost object
94 * @queue: the cryptodev backend queue index
96 * Gets a new cryptodev backend common vhost object based on
99 * Returns: the cryptodev backend common vhost object
101 CryptoDevBackendVhost
*
102 cryptodev_get_vhost(CryptoDevBackendClient
*cc
,
106 * cryptodev_vhost_start:
107 * @dev: the virtio crypto object
108 * @total_queues: the total count of queue
110 * Starts the vhost crypto logic
112 * Returns: 0 for success, negative for errors
114 int cryptodev_vhost_start(VirtIODevice
*dev
, int total_queues
);
117 * cryptodev_vhost_stop:
118 * @dev: the virtio crypto object
119 * @total_queues: the total count of queue
121 * Stops the vhost crypto logic
124 void cryptodev_vhost_stop(VirtIODevice
*dev
, int total_queues
);
127 * cryptodev_vhost_virtqueue_mask:
128 * @dev: the virtio crypto object
129 * @queue: the cryptodev backend queue index
130 * @idx: the virtqueue index
131 * @mask: mask or not (true or false)
133 * Mask/unmask events for @idx virtqueue on @dev device
136 void cryptodev_vhost_virtqueue_mask(VirtIODevice
*dev
,
141 * cryptodev_vhost_virtqueue_pending:
142 * @dev: the virtio crypto object
143 * @queue: the cryptodev backend queue index
144 * @idx: the virtqueue index
146 * Test and clear event pending status for @idx virtqueue on @dev device.
147 * Should be called after unmask to avoid losing events.
149 * Returns: true for success, false for errors
151 bool cryptodev_vhost_virtqueue_pending(VirtIODevice
*dev
,
154 #endif /* CRYPTODEV_VHOST_H */