From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0950F327BEC for ; Sat, 19 Sep 2026 19:52:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789847557; cv=none; b=jYLipHql/HnGLbcQS6LHgHPp+6Bx1RpFxDs3YCD9Z4loy3ZdqL742uxalKsKaREJ/+cyWqjkvQkQKqhhMWLRDIHRx1VtxSJlWkt3Iei5/cheFcHipeXSWUUHhIA56qfylccHk85RywwJ63w7ziKhl54gYlKzIa7g3pt0/p4vTa4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789847557; c=relaxed/simple; bh=Jvz1aetF5qaB3hhl5mlqAFS7O5Y0rr1Fsho/GqbJjJo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=iqa51M5EpIKJMXyLKdt56SYcjL67K0m0P3Igc6cB5w2eEPye/H5eDtBGVSjbZ43BvuIV70Z+kAAeZVEe6xmRC0/irQqLVn9D1tBQnExwgg0/qCGNUQGBK0g+kqIBRZS/MTu6rNfQQz64jGjFuufn0HgSovjFNvhgf/bagPqTAFk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=UMWrwzPd; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=eKqSS+I4; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="UMWrwzPd"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="eKqSS+I4" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1789847553; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Z6bq9rh1jxtwh7i1hGqXeAGz6A2qnQCpk9W8nyzhRA8=; b=UMWrwzPdFLm3sbp76xcGn3LIBF9yQ5UEEBwQe42ZUrfQkkXM8UB8cbZewfawcuEcV/bWHp 9NIr5w4bPJ0dE2w2MOSbryr3L6+THMV39YTOtptSYG15/A5yz2rncAiIIQc56QXQdPf/Sn uMJuHvtheqs+Hng67hIeR27ovp8iS4k= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-288-MmMOkK9IMcqA2xcGrKaDmA-1; Sat, 19 Sep 2026 15:52:31 -0400 X-MC-Unique: MmMOkK9IMcqA2xcGrKaDmA-1 X-Mimecast-MFC-AGG-ID: MmMOkK9IMcqA2xcGrKaDmA_1789847550 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-49d156c917cso15533775e9.1 for ; Sat, 19 Sep 2026 12:52:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1789847550; x=1790452350; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=Z6bq9rh1jxtwh7i1hGqXeAGz6A2qnQCpk9W8nyzhRA8=; b=eKqSS+I4s+jJnhp+WKvdzdPOGf1fyPGXYg8I1XOA4EuLcHF0cbsuCoscMXb9DxrUF3 C3fW1HhVt5ZNBNdozNmJCIqghCDr/C6uXgFvn0WU7RxcEQPh0s8I97r0mb8xCygQudG1 4tb5z8MxCcMBCBZlQdC+UaWA/XjjsqAzmIFP5YV4lx3BXBmhr/EtM3xPnFaTaIvfd1Rb w77/ZsKtZFEQA+FbMkQsdwb6wRy0FLcltdBEgiSkekMrIOI11mIr3NY+6Vl/kuNLWGDc wyl0iqJdCF7dp+OV2teO5fwxT997rsFO9ulR6dkD6htWcR0UXASUaZ17tFHYqEc88IfC bEoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789847550; x=1790452350; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=Z6bq9rh1jxtwh7i1hGqXeAGz6A2qnQCpk9W8nyzhRA8=; b=d3hmXSXTWZ4hkZOG0nyAZjE0aVRW+wh2E1a0qFqYprgFL4VPoCOWF9iZKJPujbU7X5 5nei7xtd+dxGvghR+aKVGz7IldXjFZ1Wv3oCQJyoL5ChJ3NUb5fcWQNYA1Hi4w5JYR/R EO8nAmKaT/OVs/H0RYgPM3mNPxQzG3PpRT3HXwHbYFnn86f+7wVL1O0HrylmX+HkTw1w auJg2Ud3HJMH3h1bYdWilQFRr4MzKGADDcznwS+vyt8NSpj2SntrdG/UiLV+bR0T52DL 5gakbgprskzNBqL1+POgdkZZ7jFn0z60d8Jm3/b/mgAtZKp5WUgF197GR2GYHeYmtbZZ L7hg== X-Forwarded-Encrypted: i=1; AKwUvBxYjXiTTAoqRm0D8zI8XuFw28Q+tZHy6BRohA/6tW3yK5V0uQpz+bg73g7+gATu0AHdwHSOS2YgyZwBGxo=@vger.kernel.org X-Gm-Message-State: AFuF++lf8vrXrd0kcT3nj+LldsT/OO233ykyp6zqBw/keE5Q2pVZ0kTH fmKY79pneCG1AnRb4OyGtIqLenueVQDGKmm1iF0rNhEKgXBErAO52/+XcCQ5sW4xMYxs72udKZc ylIz7zi45q6BPVYoTe9DokE0DnCTf+av4LIa8cnCx0tyVCVAEh6/yHntU3nfr7OXBkhRzx7HFZQ == X-Gm-Gg: AYBFou0zVKo4VpyFspuNc+B0uYVKhlXSbZfyqU09tesBGUcwEJOAXF1WTmSemx6r+aJ gRwfBjZjp4f8kEcKsxVawYIRyjnq2jFgn9SLK9MVH9KaDODhjMm8T42f67bAxwXN7zSNj1VhRGj QybhLXd947KCfzL1+FpmI9MwJLcXcthpMBf0fsvujSaOGnKuF2c+VsmNSaItdWjAd4Jw86qQAoz miEmhLE2qzssRsc9e10gMEL9nMW9xwq0CIDsYDCiZ4uFPfxWVqOF3r/hDLldmYJmDcjltpJqG2Z g3QIJkkx1mM6FY3bbW3nqkAIx/xoI12GLu8Wyr47dlKi2MyGeZ4L+7dfq9n9ePoJldtE3kQzQI1 9XdgnyxJ5kpppttV7lRLNVns= X-Received: by 2002:a05:600c:1d06:b0:49e:8222:3451 with SMTP id 5b1f17b1804b1-49fc5001358mr97860375e9.14.1789847550015; Sat, 19 Sep 2026 12:52:30 -0700 (PDT) X-Received: by 2002:a05:600c:1d06:b0:49e:8222:3451 with SMTP id 5b1f17b1804b1-49fc5001358mr97860135e9.14.1789847549405; Sat, 19 Sep 2026 12:52:29 -0700 (PDT) Received: from redhat.com (IGLD-80-230-79-236.inter.net.il. [80.230.79.236]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49fc57547easm134803235e9.3.2026.09.19.12.52.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Sep 2026 12:52:28 -0700 (PDT) Date: Sat, 19 Sep 2026 15:52:25 -0400 From: "Michael S. Tsirkin" To: Brian Daniels Cc: Mauro Carvalho Chehab , adelva@google.com, aesteve@redhat.com, changyeon@google.com, daniel.almeida@collabora.com, eperezma@redhat.com, gnurou@gmail.com, gurchetansingh@google.com, hverkuil@xs4all.nl, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, nicolas.dufresne@collabora.com, virtualization@lists.linux.dev, xuanzhuo@linux.alibaba.com, dbassey@redhat.com, laurent.pinchart@ideasonboard.com Subject: Re: [PATCH v9 1/4] media: virtio: Add skeleton virtio-media driver Message-ID: <20260919154110-mutt-send-email-mst@kernel.org> References: <20260917171921.2810550-1-briandaniels@google.com> <20260917171921.2810550-2-briandaniels@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260917171921.2810550-2-briandaniels@google.com> On Thu, Sep 17, 2026 at 01:19:17PM -0400, Brian Daniels wrote: > From: Alexandre Courbot > > This patch adds a minimum viable virtio-media driver that binds to the > virtio device and registers a V4L2 device and a video device, but lacks > any actual functionality. > > It adds the UAPI header defining the protocol, internal driver headers, > Kconfig and Makefile entries, and MAINTAINERS entry. Many of the structs > in the protocol add reserved bits. These are present to ensure 64-bit > alignment. They are not intended to be used as reserved expansion for > the protocol in the future, so more reserved space is not required. > > The UAPI header includes videodev2.h, which itself does not currently > pass UAPI header validation (CONFIG_UAPI_HEADER_TEST=y). I've added > virtio_media.h to the same test exception list. > > Signed-off-by: Alexandre Courbot > Assisted-by: Antigravity:gemini-3.5-flash > Co-developed-by: Brian Daniels > Signed-off-by: Brian Daniels > --- > MAINTAINERS | 8 + > drivers/media/Kconfig | 13 + > drivers/media/Makefile | 2 + > drivers/media/virtio/Makefile | 7 + > drivers/media/virtio/virtio_media.h | 95 +++++++ > drivers/media/virtio/virtio_media_driver.c | 146 +++++++++++ > include/uapi/linux/virtio_media.h | 288 +++++++++++++++++++++ > usr/include/Makefile | 1 + > 8 files changed, 560 insertions(+) > create mode 100644 drivers/media/virtio/Makefile > create mode 100644 drivers/media/virtio/virtio_media.h > create mode 100644 drivers/media/virtio/virtio_media_driver.c > create mode 100644 include/uapi/linux/virtio_media.h > > diff --git a/MAINTAINERS b/MAINTAINERS > index 3a19da74d..d6b1e0b30 100644 > --- a/MAINTAINERS > +++ b/MAINTAINERS > @@ -28886,6 +28886,7 @@ F: Documentation/devicetree/bindings/virtio/ > F: Documentation/driver-api/virtio/ > F: drivers/block/virtio_blk.c > F: drivers/crypto/virtio/ > +F: drivers/media/virtio/ > F: drivers/vdpa/ > F: drivers/virtio/ > F: include/linux/vdpa.h > @@ -28998,6 +28999,13 @@ S: Maintained > F: drivers/iommu/virtio-iommu.c > F: include/uapi/linux/virtio_iommu.h > > +VIRTIO MEDIA DRIVER > +M: Brian Daniels > +L: linux-media@vger.kernel.org > +S: Maintained > +F: drivers/media/virtio/ > +F: include/uapi/linux/virtio_media.h > + > VIRTIO MEM DRIVER > M: David Hildenbrand > L: virtualization@lists.linux.dev > diff --git a/drivers/media/Kconfig b/drivers/media/Kconfig > index 6abc9302c..ce7d088e7 100644 > --- a/drivers/media/Kconfig > +++ b/drivers/media/Kconfig > @@ -136,6 +136,19 @@ config MEDIA_PLATFORM_SUPPORT > > Say Y when you want to be able to see such devices. > > +config MEDIA_VIRTIO > + tristate "Virtio-media Driver" > + depends on VIRTIO && VIDEO_DEV && 64BIT && (X86 || CPU_LITTLE_ENDIAN) > + select VIDEOBUF2_CORE > + select VIDEOBUF2_MEMOPS > + help > + Enables the virtio-media driver. > + > + This driver is used to virtualize media devices such as cameras or > + decoders from a host into a guest using the V4L2 protocol. > + > + If unsure, say N. > + > config MEDIA_TEST_SUPPORT > bool > prompt "Test drivers" if MEDIA_SUPPORT_FILTER > diff --git a/drivers/media/Makefile b/drivers/media/Makefile > index 20fac24e4..357e786cc 100644 > --- a/drivers/media/Makefile > +++ b/drivers/media/Makefile > @@ -23,6 +23,8 @@ obj-$(CONFIG_DVB_CORE) += dvb-core/ > # There are both core and drivers at RC subtree - merge before drivers > obj-y += rc/ > > +obj-$(CONFIG_MEDIA_VIRTIO) += virtio/ > + > obj-$(CONFIG_CEC_CORE) += cec/ > > # > diff --git a/drivers/media/virtio/Makefile b/drivers/media/virtio/Makefile > new file mode 100644 > index 000000000..09d9834da > --- /dev/null > +++ b/drivers/media/virtio/Makefile > @@ -0,0 +1,7 @@ > +# SPDX-License-Identifier: GPL-2.0 > +# > +# Makefile for the virtio-media device driver. > + > +virtio-media-objs := virtio_media_driver.o > + > +obj-$(CONFIG_MEDIA_VIRTIO) += virtio-media.o > diff --git a/drivers/media/virtio/virtio_media.h b/drivers/media/virtio/virtio_media.h > new file mode 100644 > index 000000000..7acb2b842 > --- /dev/null > +++ b/drivers/media/virtio/virtio_media.h > @@ -0,0 +1,95 @@ > +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0+ */ > + > +/* > + * Virtio-media structures & functions declarations. > + * > + * Copyright (c) 2024-2026 Google LLC. > + */ > + > +#ifndef __VIRTIO_MEDIA_H > +#define __VIRTIO_MEDIA_H > + > +#include > +#include > + > +#include "uapi/linux/virtio_media.h" > + > +#define DESC_CHAIN_MAX_LEN SG_MAX_SINGLE_ALLOC > + > +#define VIRTIO_MEDIA_DEFAULT_DRIVER_NAME "virtio-media" > + > +/** > + * struct virtio_media - Virtio-media device. > + * @v4l2_dev: v4l2_device for the media device. > + * @video_dev: video_device for the media device. > + * @virtio_dev: virtio device for the media device. > + * @commandq: virtio command queue. > + * @eventq: virtio event queue. > + * @eventq_work: work to run when events are received on @eventq. > + * @mmap_region: region into which MMAP buffers are mapped by the host. > + * @event_buffer: buffer for event descriptors. > + * @sessions: list of active sessions on the device. > + * @sessions_lock: protects @sessions and &struct virtio_media_session.list. > + * @events_lock: prevents concurrent processing of events. > + * @cmd: union of the device commands ``open`` and ``munmap``. The other > + * commands are handled by &struct virtio_media_session > + * @resp: union of responses to device commands ``open`` and ``munmap``. The > + * other responses are handled by &struct virtio_media_session > + * @vlock: serializes access to the command queue. > + * @wq: waitqueue for host responses on the command queue. > + */ > +struct virtio_media { > + struct v4l2_device v4l2_dev; > + struct video_device video_dev; > + > + struct virtio_device *virtio_dev; > + struct virtqueue *commandq; > + struct virtqueue *eventq; > + struct work_struct eventq_work; > + > + struct virtio_shm_region mmap_region; > + > + void *event_buffer; > + > + struct list_head sessions; > + struct mutex sessions_lock; /* protects sessions list */ > + > + struct mutex events_lock; /* prevents concurrent event processing */ > + > + __dma_from_device_group_begin(); > + union { > + struct virtio_media_cmd_open open; > + struct virtio_media_cmd_munmap munmap; > + } cmd; > + > + union { > + struct virtio_media_resp_open open; > + struct virtio_media_resp_munmap munmap; > + } resp; > + __dma_from_device_group_end(); > + > + struct mutex vlock; /* serializes command queue access */ > + wait_queue_head_t wq; > +}; > + > +static inline struct virtio_media * > +to_virtio_media(struct video_device *video_dev) > +{ > + return container_of(video_dev, struct virtio_media, video_dev); > +} > + > +/* virtio_media_driver.c */ > + > +int virtio_media_send_command(struct virtio_media *vv, struct scatterlist **sgs, > + const size_t out_sgs, const size_t in_sgs, > + size_t minimum_resp_len, size_t *resp_len); > +void virtio_media_process_events(struct virtio_media *vv); > + > +/* virtio_media_ioctls.c */ > + > +long virtio_media_device_ioctl(struct file *file, unsigned int cmd, > + unsigned long arg); > +extern const struct v4l2_ioctl_ops virtio_media_ioctl_ops; > + > +#endif // __VIRTIO_MEDIA_H > + > diff --git a/drivers/media/virtio/virtio_media_driver.c b/drivers/media/virtio/virtio_media_driver.c > new file mode 100644 > index 000000000..25f2ceaa6 > --- /dev/null > +++ b/drivers/media/virtio/virtio_media_driver.c > @@ -0,0 +1,146 @@ > +// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0+ > + > +/* > + * Virtio-media driver. > + * > + * Copyright (c) 2024-2026 Google LLC. > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include > +#include > + > +#include "uapi/linux/virtio_media.h" > +#include "virtio_media.h" > + > +static void commandq_callback(struct virtqueue *vq) > +{ > +} > + > +static void eventq_callback(struct virtqueue *vq) > +{ > +} > + > +static const struct v4l2_file_operations virtio_media_fops = { > + .owner = THIS_MODULE, > + .open = v4l2_fh_open, > + .release = v4l2_fh_release, > +}; > + > +static int virtio_media_probe(struct virtio_device *virtio_dev) > +{ > + struct device *dev = &virtio_dev->dev; > + struct virtqueue *vqs[2]; > + static struct virtqueue_info vq_info[2] = { > + { > + .name = "command", > + .callback = commandq_callback, > + }, > + { > + .name = "event", > + .callback = eventq_callback, > + }, > + }; > + struct virtio_media *vv; > + struct video_device *vd; > + int ret; > + > + vv = devm_kzalloc(dev, sizeof(*vv), GFP_KERNEL); > + if (!vv) > + return -ENOMEM; > + > + INIT_LIST_HEAD(&vv->sessions); > + mutex_init(&vv->sessions_lock); > + mutex_init(&vv->events_lock); > + mutex_init(&vv->vlock); > + > + vv->virtio_dev = virtio_dev; > + virtio_dev->priv = vv; > + > + init_waitqueue_head(&vv->wq); > + > + ret = v4l2_device_register(dev, &vv->v4l2_dev); > + if (ret) > + return ret; > + > + ret = virtio_find_vqs(virtio_dev, 2, vqs, vq_info, NULL); > + if (ret) > + goto err_find_vqs; > + > + vv->commandq = vqs[0]; > + vv->eventq = vqs[1]; > + > + vd = &vv->video_dev; > + vd->v4l2_dev = &vv->v4l2_dev; > + vd->vfl_type = VFL_TYPE_VIDEO; > + vd->fops = &virtio_media_fops; > + vd->release = video_device_release_empty; > + strscpy(vd->name, "virtio-media", sizeof(vd->name)); > + > + video_set_drvdata(vd, vv); > + > + vd->device_caps = virtio_cread32(virtio_dev, 0); please use offsetof device_caps not hard coded "0". Also, the spec says: struct virtio_media_config { le32 device_caps; le32 device_type; le8 card[32]; }; you (and v4l) should define them as le32 and use virtio_cread_le. > + if (vd->device_caps & (V4L2_CAP_VIDEO_M2M | V4L2_CAP_VIDEO_M2M_MPLANE)) > + vd->vfl_dir = VFL_DIR_M2M; > + else if (vd->device_caps & > + (V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_VIDEO_OUTPUT_MPLANE)) > + vd->vfl_dir = VFL_DIR_TX; > + else > + vd->vfl_dir = VFL_DIR_RX; > + > + ret = video_register_device(vd, virtio_cread32(virtio_dev, 4), 0); > + if (ret) > + goto err_register_device; > + > + virtio_device_ready(virtio_dev); > + > + return 0; > + > +err_register_device: > + virtio_dev->config->del_vqs(virtio_dev); > +err_find_vqs: > + v4l2_device_unregister(&vv->v4l2_dev); > + return ret; > +} > + > +static void virtio_media_remove(struct virtio_device *virtio_dev) > +{ > + struct virtio_media *vv = virtio_dev->priv; > + > + virtio_reset_device(virtio_dev); > + v4l2_device_unregister(&vv->v4l2_dev); > + virtio_dev->config->del_vqs(virtio_dev); > + video_unregister_device(&vv->video_dev); > +} > + > +static struct virtio_device_id id_table[] = { > + { VIRTIO_ID_MEDIA, VIRTIO_DEV_ANY_ID }, > + { 0 }, > +}; > + > +static unsigned int features[] = {}; > + > +static struct virtio_driver virtio_media_driver = { > + .feature_table = features, > + .feature_table_size = ARRAY_SIZE(features), > + .driver.name = VIRTIO_MEDIA_DEFAULT_DRIVER_NAME, > + .driver.owner = THIS_MODULE, > + .id_table = id_table, > + .probe = virtio_media_probe, > + .remove = virtio_media_remove, > +}; > + > +module_virtio_driver(virtio_media_driver); > + > +MODULE_DEVICE_TABLE(virtio, id_table); > +MODULE_DESCRIPTION("virtio media driver"); > +MODULE_AUTHOR("Alexandre Courbot "); > +MODULE_LICENSE("Dual BSD/GPL"); > diff --git a/include/uapi/linux/virtio_media.h b/include/uapi/linux/virtio_media.h > new file mode 100644 > index 000000000..ac3d75c75 > --- /dev/null > +++ b/include/uapi/linux/virtio_media.h > @@ -0,0 +1,288 @@ > +/* SPDX-License-Identifier: ((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) */ > + > +/* > + * Definitions of virtio-media protocol structures. > + * > + * Copyright (c) 2024-2026 Google LLC. > + */ > + > +#ifndef _UAPI__LINUX_VIRTIO_MEDIA_H > +#define _UAPI__LINUX_VIRTIO_MEDIA_H > + > +#include > +#include > + > +/* > + * Virtio protocol definition. > + */ > + > +/** > + * struct virtio_media_cmd_header - Header for all virtio-media commands. > + * @cmd: one of VIRTIO_MEDIA_CMD_*. > + * @__reserved: must be set to zero by the driver. > + * > + * This header starts all commands from the driver to the device on the > + * commandq. > + */ > +struct virtio_media_cmd_header { > + __le32 cmd; > + __le32 __reserved; > +}; > + > +/** > + * struct virtio_media_resp_header - Header for all virtio-media responses. > + * @status: 0 if the command was successful, or one of the standard Linux error > + * codes as a positive integer. > + * @__reserved: must be set to zero by the device. > + * > + * This header starts all responses from the device to the driver on the > + * commandq. > + */ > +struct virtio_media_resp_header { > + __le32 status; > + __le32 __reserved; > +}; > + > +/** > + * VIRTIO_MEDIA_CMD_OPEN - Command for creating a new session. > + * > + * This is the equivalent of calling ``open`` on a V4L2 device node. Upon > + * success, a session id is returned which can be used to perform other > + * commands on the session, notably ioctls. > + */ > +#define VIRTIO_MEDIA_CMD_OPEN 1 > + > +/** > + * struct virtio_media_cmd_open - Driver command for VIRTIO_MEDIA_CMD_OPEN. > + * @hdr: header with cmd member set to VIRTIO_MEDIA_CMD_OPEN. > + */ > +struct virtio_media_cmd_open { > + struct virtio_media_cmd_header hdr; > +}; > + > +/** > + * struct virtio_media_resp_open - Device response for VIRTIO_MEDIA_CMD_OPEN. > + * @hdr: header containing the status of the command. > + * @session_id: if &struct virtio_media_resp_header.status == 0, contains the > + * id of the newly created session. > + * @__reserved: must be set to zero by the device. > + */ > +struct virtio_media_resp_open { > + struct virtio_media_resp_header hdr; > + __le32 session_id; > + __le32 __reserved; > +}; > + > +/** > + * VIRTIO_MEDIA_CMD_CLOSE - Command for closing an active session. > + * > + * This is the equivalent of calling ``close`` on a previously opened V4L2 > + * session. All resources associated with this session will be freed and the > + * session ID shall not be used again after queueing this command. > + * > + * This command does not require a response from the device. > + */ > +#define VIRTIO_MEDIA_CMD_CLOSE 2 > + > +/** > + * struct virtio_media_cmd_close - Driver command for VIRTIO_MEDIA_CMD_CLOSE. > + * @hdr: header with cmd member set to VIRTIO_MEDIA_CMD_CLOSE. > + * @session_id: id of the session to close. > + * @__reserved: must be set to zero by the driver. > + */ > +struct virtio_media_cmd_close { > + struct virtio_media_cmd_header hdr; > + __le32 session_id; > + __le32 __reserved; > +}; > + > +/** > + * VIRTIO_MEDIA_CMD_IOCTL - Driver command for executing an ioctl. > + * > + * This command asks the device to run one of the ``VIDIOC_*`` ioctls on the > + * active session. > + * > + * The code of the ioctl is extracted from the VIDIOC_* definitions in > + * ``videodev2.h``, and consists of the second argument of the ``_IO*`` macro. > + * > + * Each ioctl has a payload, which is defined by the third argument of the > + * ``_IO*`` macro defining it. It can be writable by the driver (``_IOW``), the > + * device (``_IOR``), or both (``_IOWR``). > + * > + * If an ioctl is writable by the driver, it must be followed by a > + * driver-writable descriptor containing the payload. > + * > + * If an ioctl is writable by the device, it must be followed by a > + * device-writable descriptor of the size of the payload that the device will > + * write into. > + * > + */ > +#define VIRTIO_MEDIA_CMD_IOCTL 3 > + > +/** > + * struct virtio_media_cmd_ioctl - Driver command for VIRTIO_MEDIA_CMD_IOCTL. > + * @hdr: header with cmd member set to VIRTIO_MEDIA_CMD_IOCTL. > + * @session_id: id of the session to run the ioctl on. > + * @code: code of the ioctl to run. > + */ > +struct virtio_media_cmd_ioctl { > + struct virtio_media_cmd_header hdr; > + __le32 session_id; > + __le32 code; > +}; > + > +/** > + * struct virtio_media_resp_ioctl - Device response for VIRTIO_MEDIA_CMD_IOCTL. > + * @hdr: header containing the status of the ioctl. > + */ > +struct virtio_media_resp_ioctl { > + struct virtio_media_resp_header hdr; > +}; > + > +/** > + * struct virtio_media_sg_entry - Description of part of a scattered guest > + * memory. > + * @start: start guest address of the memory segment. > + * @len: length of this memory segment. > + * @__reserved: must be set to zero by the driver. > + */ > +struct virtio_media_sg_entry { > + __le64 start; > + __le32 len; > + __le32 __reserved; > +}; > + > +/** > + * VIRTIO_MEDIA_MMAP_FLAG_RW - Bit position of the VIRTIO_MEDIA_MMAP_FLAG_RW > + * flag. > + */ > +#define VIRTIO_MEDIA_MMAP_FLAG_RW 0 > + > +/** > + * VIRTIO_MEDIA_CMD_MMAP - Command for mapping a MMAP buffer into the driver's > + * address space. > + */ > +#define VIRTIO_MEDIA_CMD_MMAP 4 > + > +/** > + * struct virtio_media_cmd_mmap - Driver command for VIRTIO_MEDIA_CMD_MMAP. > + * @hdr: header with cmd member set to VIRTIO_MEDIA_CMD_MMAP. > + * @session_id: ID of the session we are mapping for. > + * @flags: combination of VIRTIO_MEDIA_MMAP_FLAG_*. > + * @offset: mem_offset field of the plane to map, as returned by > + * VIDIOC_QUERYBUF. > + */ > +struct virtio_media_cmd_mmap { > + struct virtio_media_cmd_header hdr; > + __le32 session_id; > + __le32 flags; > + __le32 offset; > +}; > + > +/** > + * struct virtio_media_resp_mmap - Device response for VIRTIO_MEDIA_CMD_MMAP. > + * @hdr: header containing the status of the command. > + * @driver_addr: offset into SHM region 0 of the start of the mapping. > + * @len: length of the mapping. > + */ > +struct virtio_media_resp_mmap { > + struct virtio_media_resp_header hdr; > + __le64 driver_addr; > + __le64 len; > +}; > + > +/** > + * VIRTIO_MEDIA_CMD_MUNMAP - Unmap a MMAP buffer previously mapped using > + * VIRTIO_MEDIA_CMD_MMAP. > + */ > +#define VIRTIO_MEDIA_CMD_MUNMAP 5 > + > +/** > + * struct virtio_media_cmd_munmap - Driver command for VIRTIO_MEDIA_CMD_MUNMAP. > + * @hdr: header with cmd member set to VIRTIO_MEDIA_CMD_MUNMAP. > + * @driver_addr: offset into SHM region 0 at which the buffer has been > + * previously mapped. > + */ > +struct virtio_media_cmd_munmap { > + struct virtio_media_cmd_header hdr; > + __le64 driver_addr; > +}; > + > +/** > + * struct virtio_media_resp_munmap - Device response for > + * VIRTIO_MEDIA_CMD_MUNMAP. > + * @hdr: header containing the status of the command. > + */ > +struct virtio_media_resp_munmap { > + struct virtio_media_resp_header hdr; > +}; > + > +/* The values for these events are set by the virtio-media specification. */ > +#define VIRTIO_MEDIA_EVT_ERROR 0 > +#define VIRTIO_MEDIA_EVT_DQBUF 1 > +#define VIRTIO_MEDIA_EVT_EVENT 2 > + > +/** > + * struct virtio_media_event_header - Header for events on the eventq. > + * @event: one of VIRTIO_MEDIA_EVT_* > + * @session_id: ID of the session the event applies to. > + */ > +struct virtio_media_event_header { > + __le32 event; > + __le32 session_id; > +}; > + > +/** > + * struct virtio_media_event_error - Unrecoverable device-side error. > + * @hdr: header for the event. > + * @errno: error code describing the kind of error that occurred. > + * @__reserved: must be set to zero by the device. > + * > + * Upon receiving this event, the session mentioned in the header is considered > + * corrupted and closed. > + */ > +struct virtio_media_event_error { > + struct virtio_media_event_header hdr; > + __le32 errno; > + __le32 __reserved; > +}; > + > +/* This is set to VIDEO_MAX_PLANES defined in include/uapi/linux/videodev2.h. > + * It is renamed here to match the constant that is defined in the virtio-media > + * specification. > + */ > +#define VIRTIO_MEDIA_MAX_PLANES VIDEO_MAX_PLANES > + > +/** > + * struct virtio_media_event_dqbuf - Dequeued buffer event. > + * @hdr: header for the event. > + * @buffer: &struct v4l2_buffer describing the buffer that has been dequeued. > + * @planes: plane information for the dequeued buffer. > + * > + * This event is used to signal that a buffer is not being used anymore by the > + * device and is returned to the driver. > + */ > +struct virtio_media_event_dqbuf { > + struct virtio_media_event_header hdr; > + struct v4l2_buffer buffer; > + struct v4l2_plane planes[VIRTIO_MEDIA_MAX_PLANES]; > +}; > + > +/** > + * struct virtio_media_event_event - V4L2 event. > + * @hdr: header for the event. > + * @event: description of the event that occurred. > + * > + * This event signals that a V4L2 event has been emitted for a session. > + */ > +struct virtio_media_event_event { > + struct virtio_media_event_header hdr; > + struct v4l2_event event; > +}; > + > +/* Maximum size of an event. We will queue descriptors of this size on the > + * eventq. > + */ > +#define VIRTIO_MEDIA_EVENT_MAX_SIZE sizeof(struct virtio_media_event_dqbuf) > + > +#endif // _UAPI__LINUX_VIRTIO_MEDIA_H > diff --git a/usr/include/Makefile b/usr/include/Makefile > index ee69dd9d9..df106b5d9 100644 > --- a/usr/include/Makefile > +++ b/usr/include/Makefile > @@ -37,6 +37,7 @@ no-header-test += linux/usb/audio.h > no-header-test += linux/v4l2-mediabus.h > no-header-test += linux/v4l2-subdev.h > no-header-test += linux/videodev2.h > +no-header-test += linux/virtio_media.h > no-header-test += linux/vm_sockets.h > no-header-test += sound/asequencer.h > no-header-test += sound/asoc.h > -- > 2.55.0.1082.g2b9226bbc0-goog