All of lore.kernel.org
 help / color / mirror / Atom feed
From: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
To: qemu-devel@nongnu.org, Albert Esteve <aesteve@redhat.com>
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
	stefanha@gmail.com, alex.bennee@linaro.org, philmd@linaro.org,
	kraxel@redhat.com, marcandre.lureau@gmail.com,
	Albert Esteve <aesteve@redhat.com>
Subject: Re: [PATCH v4 2/5] hw/virtio: document SharedObject structures
Date: Tue, 20 Feb 2024 12:28:48 +0200	[thread overview]
Message-ID: <95hcp.21l4vcaudvyq@linaro.org> (raw)
In-Reply-To: <20240219143423.272012-3-aesteve@redhat.com>

On Mon, 19 Feb 2024 16:34, Albert Esteve <aesteve@redhat.com> wrote:
>Change VirtioSharedObject value type from
>a generic pointer to a union storing the different
>supported underlying types, which makes naming
>less confusing.
>
>With the update, use the chance to add kdoc
>to both the SharedObjectType enum and
>VirtioSharedObject struct.
>
>Signed-off-by: Albert Esteve <aesteve@redhat.com>
>---
> hw/display/virtio-dmabuf.c        |  8 ++++----
> include/hw/virtio/virtio-dmabuf.h | 25 ++++++++++++++++++++++++-
> 2 files changed, 28 insertions(+), 5 deletions(-)
>
>diff --git a/hw/display/virtio-dmabuf.c b/hw/display/virtio-dmabuf.c
>index 3dba4577ca..497cb6fa7c 100644
>--- a/hw/display/virtio-dmabuf.c
>+++ b/hw/display/virtio-dmabuf.c
>@@ -57,7 +57,7 @@ bool virtio_add_dmabuf(QemuUUID *uuid, int udmabuf_fd)
>     }
>     vso = g_new(VirtioSharedObject, 1);
>     vso->type = TYPE_DMABUF;
>-    vso->value = GINT_TO_POINTER(udmabuf_fd);
>+    vso->value.udma_buf = udmabuf_fd;
>     result = virtio_add_resource(uuid, vso);
>     if (!result) {
>         g_free(vso);
>@@ -75,7 +75,7 @@ bool virtio_add_vhost_device(QemuUUID *uuid, struct vhost_dev *dev)
>     }
>     vso = g_new(VirtioSharedObject, 1);
>     vso->type = TYPE_VHOST_DEV;
>-    vso->value = dev;
>+    vso->value.dev = dev;
>     result = virtio_add_resource(uuid, vso);
>     if (!result) {
>         g_free(vso);
>@@ -114,7 +114,7 @@ int virtio_lookup_dmabuf(const QemuUUID *uuid)
>         return -1;
>     }
>     assert(vso->type == TYPE_DMABUF);
>-    return GPOINTER_TO_INT(vso->value);
>+    return vso->value.udma_buf;
> }
> 
> struct vhost_dev *virtio_lookup_vhost_device(const QemuUUID *uuid)
>@@ -124,7 +124,7 @@ struct vhost_dev *virtio_lookup_vhost_device(const QemuUUID *uuid)
>         return NULL;
>     }
>     assert(vso->type == TYPE_VHOST_DEV);
>-    return (struct vhost_dev *) vso->value;
>+    return (struct vhost_dev *) vso->value.dev;

Is the casting still required?


> }
> 
> SharedObjectType virtio_object_type(const QemuUUID *uuid)
>diff --git a/include/hw/virtio/virtio-dmabuf.h b/include/hw/virtio/virtio-dmabuf.h
>index 627c3b6db7..891a43162d 100644
>--- a/include/hw/virtio/virtio-dmabuf.h
>+++ b/include/hw/virtio/virtio-dmabuf.h
>@@ -16,15 +16,38 @@
> #include "qemu/uuid.h"
> #include "vhost.h"
> 
>+/**
>+ * SharedObjectType:
>+ *
>+ * Identifies the type of the underlying type that the current lookup
>+ * table entry is holding.
>+ * 
>+ * TYPE_INVALID: Invalid entry
>+ * TYPE_DMABUF: Entry is a dmabuf file descriptor that can be directly
>+ *              shared with the requestor
>+ * TYPE_VHOST_DEV: Entry is a pointer to a vhost device that is holding
>+ *                 the shared object.


nit:

+ * TYPE_INVALID:   Invalid entry.
+ * TYPE_DMABUF:    Entry is a dmabuf file descriptor that can be
+ *                 directly shared with the requestor.
+ * TYPE_VHOST_DEV: Entry is a pointer to a vhost device that is holding
+ *                 the shared object.


>+ */
> typedef enum SharedObjectType {
>     TYPE_INVALID = 0,
>     TYPE_DMABUF,
>     TYPE_VHOST_DEV,
> } SharedObjectType;
> 
>+/**
>+ * VirtioSharedObject:
>+ * @type: Shared object type identifier
>+ * @value: Union containing to the underlying type
>+ * 
>+ * The VirtioSharedObject object provides a way to distinguish,
>+ * store, and handle the different types supported by the lookup table.
>+ */
> typedef struct VirtioSharedObject {
>     SharedObjectType type;
>-    gpointer value;
>+    union {
>+        struct vhost_dev *dev;  /* TYPE_VHOST_DEV */
>+        int udma_buf;           /* TYPE_DMABUF */
>+    } value;
> } VirtioSharedObject;
> 
> /**
>-- 
>2.43.1
>
>


  reply	other threads:[~2024-02-20 10:34 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-19 14:34 [PATCH v4 0/5] Virtio dmabuf improvements Albert Esteve
2024-02-19 14:34 ` [PATCH v4 1/5] hw/virtio: check owner for removing objects Albert Esteve
2024-02-19 14:34 ` [PATCH v4 2/5] hw/virtio: document SharedObject structures Albert Esteve
2024-02-20 10:28   ` Manos Pitsidianakis [this message]
2024-03-06 13:13     ` Albert Esteve
2024-02-19 14:34 ` [PATCH v4 3/5] hw/virtio: change dmabuf mutex to QemuMutex Albert Esteve
2024-02-20 10:34   ` Manos Pitsidianakis
2024-03-11 13:31     ` Albert Esteve
2024-03-12 20:47       ` Alex Bennée
2024-02-19 14:34 ` [PATCH v4 4/5] hw/virtio: cleanup shared resources Albert Esteve
2024-02-20 10:39   ` Manos Pitsidianakis
2024-03-12 18:13   ` Michael S. Tsirkin
2024-02-19 14:34 ` [PATCH v4 5/5] hw/virtio: rename virtio dmabuf API Albert Esteve
2024-03-12 18:23 ` [PATCH v4 0/5] Virtio dmabuf improvements Michael S. Tsirkin
2024-03-13  8:00   ` Albert Esteve

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=95hcp.21l4vcaudvyq@linaro.org \
    --to=manos.pitsidianakis@linaro.org \
    --cc=aesteve@redhat.com \
    --cc=alex.bennee@linaro.org \
    --cc=kraxel@redhat.com \
    --cc=marcandre.lureau@gmail.com \
    --cc=mst@redhat.com \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.