2 * Virtio Shared dma-buf
4 * Copyright Red Hat, Inc. 2023
7 * Albert Esteve <aesteve@redhat.com>
9 * This work is licensed under the terms of the GNU GPL, version 2.
10 * See the COPYING file in the top-level directory.
13 #ifndef VIRTIO_DMABUF_H
14 #define VIRTIO_DMABUF_H
16 #include "qemu/uuid.h"
19 typedef enum SharedObjectType
{
25 typedef struct VirtioSharedObject
{
26 SharedObjectType type
;
31 * virtio_add_dmabuf() - Add a new dma-buf resource to the lookup table
32 * @uuid: new resource's UUID
33 * @dmabuf_fd: the dma-buf descriptor that will be stored and shared with
34 * other virtio devices. The caller retains ownership over the
35 * descriptor and its lifecycle.
37 * Note: @dmabuf_fd must be a valid (non-negative) file descriptor.
39 * Return: true if the UUID did not exist and the resource has been added,
40 * false if another resource with the same UUID already existed.
41 * Note that if it finds a repeated UUID, the resource is not inserted in
44 bool virtio_add_dmabuf(QemuUUID
*uuid
, int dmabuf_fd
);
47 * virtio_add_vhost_device() - Add a new exporter vhost device that holds the
48 * resource with the associated UUID
49 * @uuid: new resource's UUID
50 * @dev: the pointer to the vhost device that holds the resource. The caller
51 * retains ownership over the device struct and its lifecycle.
53 * Return: true if the UUID did not exist and the device has been tracked,
54 * false if another resource with the same UUID already existed.
55 * Note that if it finds a repeated UUID, the resource is not inserted in
58 bool virtio_add_vhost_device(QemuUUID
*uuid
, struct vhost_dev
*dev
);
61 * virtio_remove_resource() - Removes a resource from the lookup table
62 * @uuid: resource's UUID
64 * Return: true if the UUID has been found and removed from the lookup table.
66 bool virtio_remove_resource(const QemuUUID
*uuid
);
69 * virtio_lookup_dmabuf() - Looks for a dma-buf resource in the lookup table
70 * @uuid: resource's UUID
72 * Return: the dma-buf file descriptor integer, or -1 if the key is not found.
74 int virtio_lookup_dmabuf(const QemuUUID
*uuid
);
77 * virtio_lookup_vhost_device() - Looks for an exporter vhost device in the
79 * @uuid: resource's UUID
81 * Return: pointer to the vhost_dev struct, or NULL if the key is not found.
83 struct vhost_dev
*virtio_lookup_vhost_device(const QemuUUID
*uuid
);
86 * virtio_object_type() - Looks for the type of resource in the lookup table
87 * @uuid: resource's UUID
89 * Return: the type of resource associated with the UUID, or TYPE_INVALID if
90 * the key is not found.
92 SharedObjectType
virtio_object_type(const QemuUUID
*uuid
);
95 * virtio_free_resources() - Destroys all keys and values of the shared
96 * resources lookup table, and frees them
98 void virtio_free_resources(void);
100 #endif /* VIRTIO_DMABUF_H */