Merge tag 'pull-loongarch-20241016' of https://gitlab.com/gaosong/qemu into staging
[qemu/armbru.git] / include / hw / virtio / virtio-dmabuf.h
blob627c3b6db79ff8e184a49240ef91b916dbddda11
1 /*
2 * Virtio Shared dma-buf
4 * Copyright Red Hat, Inc. 2023
6 * Authors:
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"
17 #include "vhost.h"
19 typedef enum SharedObjectType {
20 TYPE_INVALID = 0,
21 TYPE_DMABUF,
22 TYPE_VHOST_DEV,
23 } SharedObjectType;
25 typedef struct VirtioSharedObject {
26 SharedObjectType type;
27 gpointer value;
28 } VirtioSharedObject;
30 /**
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
42 * the lookup table.
44 bool virtio_add_dmabuf(QemuUUID *uuid, int dmabuf_fd);
46 /**
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
56 * the lookup table.
58 bool virtio_add_vhost_device(QemuUUID *uuid, struct vhost_dev *dev);
60 /**
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);
68 /**
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);
76 /**
77 * virtio_lookup_vhost_device() - Looks for an exporter vhost device in the
78 * lookup table
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);
85 /**
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);
94 /**
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 */