From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f202.google.com (mail-qk1-f202.google.com [209.85.222.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5F8D93624C5 for ; Mon, 22 Jun 2026 20:44:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782161044; cv=none; b=c+x0C06eXgdKvnoRkjRWAh9H84x0SOsxdwoNXPQqeyniKRv2ULBG97dukTktPKfZhLR2fw0DPy/XY+nUrx1XluEtj05sSlXgxs5eJn8CQdCzde1Ewrw2Y8WZa+uhus1BENHBJ9x6z95P++KW8R0y7S2Ift0e30FOG0vbDBKbMxk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782161044; c=relaxed/simple; bh=2mJ61I5TJUNkGm0PDhijKpL+/E3zhoJyaxpTIBWn790=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=mcqI2ZifeOI3t3poFB8x9SEC0d7RCfOyuwKJSPpulnNb9179TWt4HJUwuko+TPvMZmnI69bDRvlvQH53wosEhbQDlRahFAsbSJiJf2L2ijRVOeDvFhc6UoLgocJsElE2dW0WA2j9loJwFX8OeJrPSMmCLbCBLd8pc5TzBqR3QRw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--briandaniels.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=HKPMNv3t; arc=none smtp.client-ip=209.85.222.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--briandaniels.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="HKPMNv3t" Received: by mail-qk1-f202.google.com with SMTP id af79cd13be357-92229624a71so476249185a.3 for ; Mon, 22 Jun 2026 13:44:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1782161042; x=1782765842; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=qPeGazJ7KQoOREISM/XZdRZoBpHzQAXAz7NAUNnaOTw=; b=HKPMNv3tOxdx6mQzdX2aOUc9w00BR4XQIeaqZnuEIsBZpz3cEOndy0pAp8DgLJ6MNJ r1kZ4aSqvm0wGC+CfIncOs28afVS08boIieHSbLND68j5e6ZjuEGmu5+AMzf0CnNVuUt ZxUK700RafyAy7nj0Ym1g7pcR5+y4BAbHOWRGG1Ny9xhGOMYRQlzAy3IXY2PKMOELg8d lP+XWSfUkWlyrBFGXzrqyEwwXJ+guY9SktRk++gDeBU8z8g5fMyT0+qjotXiuudeo27X 3XI6YuQ4rChchkBiqO9b8x8i06JuLPleE0QmIklStMElkWm5odUIUGvbVmszKwgj2Kp1 lNbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782161042; x=1782765842; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=qPeGazJ7KQoOREISM/XZdRZoBpHzQAXAz7NAUNnaOTw=; b=eHK9S/0AZPxtzpYXg2JsN9NJ7SIX1TV7zScB8L2dFspWQNO+KWHQRJ8MI+CYyEVslT Vz2PSAAZ1+oYzX17Ixm6u3ov9n9iq37OBP2MCG4cp/nuWLODKlY35zoAUrDcJTfF3tN/ 7uBqgvjgOT4IuXE0NZdZYTYReLwSXpm5MB7sRCB7i2HW3QyC7jgIodpzcdmVCLre0833 9rM8Mkr37LzPXkk5iefa1GZghnKXIz+KL3TpARdyEzAHj+/HCy7NgIDhPFaMIifcxhZJ 7H+rn5ad2YALAWp+gdxq6mW5zbYO375iNo1Q5Iy9PD/SFlApaVP6rN39+K9h2c1Zueiy BzOw== X-Forwarded-Encrypted: i=1; AFNElJ/cocuIbmDCWTVSpTP4h8+n76zNZfH+YFNwZg3SCTGIIbRL3KrwrGQDa606xjk68HY4RGANWC30AnYSKeU=@vger.kernel.org X-Gm-Message-State: AOJu0YwegLsnvly0KOnZW9N7A73VTmQy7KWMnfjt3ixVLz9UbckoIG/0 WB9WT6s94rIyDy9x8U8YxQI2zD2OCwakNSCkku3Dk8MhymaY42h43VmUZaXG7JiCCu/zH6rXSqz exBJvxogocM29mVKknrHbZ/buPxJ0 X-Received: from qknru1.prod.google.com ([2002:a05:620a:6841:b0:915:73e8:b754]) (user=briandaniels job=prod-delivery.src-stubby-dispatcher) by 2002:a05:620a:278a:b0:915:f27f:e70e with SMTP id af79cd13be357-9208f161e9bmr2529029185a.23.1782161042055; Mon, 22 Jun 2026 13:44:02 -0700 (PDT) Date: Mon, 22 Jun 2026 16:43:37 -0400 In-Reply-To: <20260622204343.1994418-1-briandaniels@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260622204343.1994418-1-briandaniels@google.com> X-Mailer: git-send-email 2.55.0.rc0.799.gd6f94ed593-goog Message-ID: <20260622204343.1994418-3-briandaniels@google.com> Subject: [PATCH v4 2/8] media: virtio: Add virtio-media driver structs and function declarations From: Brian Daniels To: Mauro Carvalho Chehab Cc: acourbot@google.com, 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, jasowang@redhat.com, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, mst@redhat.com, nicolas.dufresne@collabora.com, virtualization@lists.linux.dev, xuanzhuo@linux.alibaba.com, Brian Daniels Content-Type: text/plain; charset="UTF-8" From: Alexandre Courbot Add the structs and function declarations for the new virtio-media drvier. Signed-off-by: Alexandre Courbot Co-developed-by: Brian Daniels Signed-off-by: Brian Daniels --- drivers/media/virtio/virtio_media.h | 95 +++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 drivers/media/virtio/virtio_media.h diff --git a/drivers/media/virtio/virtio_media.h b/drivers/media/virtio/virtio_media.h new file mode 100644 index 000000000..52809d4e9 --- /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-2025 Google LLC. + */ + +#ifndef __VIRTIO_MEDIA_H +#define __VIRTIO_MEDIA_H + +#include +#include + +#include "protocol.h" + +#define DESC_CHAIN_MAX_LEN SG_MAX_SINGLE_ALLOC + +#define VIRTIO_MEDIA_DEFAULT_DRIVER_NAME "virtio-media" + +extern char *virtio_media_driver_name; +extern bool virtio_media_allow_userptr; + +/** + * 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 ``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 */ + + 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; + + 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 -- 2.55.0.rc0.799.gd6f94ed593-goog