mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Charvi Mehta <charvi.mehta@arm.com>
To: linux-media@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org
Cc: Charvi Mehta <charvi.mehta@arm.com>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Philipp Zabel <p.zabel@pengutronix.de>,
	Vincenzo Frascino <vincenzo.frascino@arm.com>,
	Rathinavel Sankaralingam <rath.sankaralingam@arm.com>,
	Shobhit Pandey <shobhit.pandey@arm.com>
Subject: [RFC PATCH 03/28] media: mali-vpu: register V4L2 decoder device and add querycap ioctl
Date: Thu, 19 Nov 2026 15:37:33 +0000	[thread overview]
Message-ID: <20261119153758.1426673-4-charvi.mehta@arm.com> (raw)
In-Reply-To: <20261119153758.1426673-1-charvi.mehta@arm.com>

Register a V4L2 M2M decoder video device for the Mali VPU.
Add open and release file operations that allocate a per-file session.

Implement VIDIOC_QUERYCAP to report the driver and decoder identity.

Signed-off-by: Charvi Mehta <charvi.mehta@arm.com>
---
 drivers/media/platform/arm/mali-vpu/Kconfig   |  1 +
 drivers/media/platform/arm/mali-vpu/Makefile  |  3 +-
 .../platform/arm/mali-vpu/mali-vpu-device.h   | 15 ++++
 .../platform/arm/mali-vpu/mali-vpu-probe.c    | 59 +++++++++++++-
 .../platform/arm/mali-vpu/mali-vpu-session.h  | 26 +++++++
 .../platform/arm/mali-vpu/mali-vpu-vidioc.c   | 78 +++++++++++++++++++
 .../platform/arm/mali-vpu/mali-vpu-vidioc.h   | 15 ++++
 7 files changed, 195 insertions(+), 2 deletions(-)
 create mode 100644 drivers/media/platform/arm/mali-vpu/mali-vpu-session.h
 create mode 100644 drivers/media/platform/arm/mali-vpu/mali-vpu-vidioc.c
 create mode 100644 drivers/media/platform/arm/mali-vpu/mali-vpu-vidioc.h

diff --git a/drivers/media/platform/arm/mali-vpu/Kconfig b/drivers/media/platform/arm/mali-vpu/Kconfig
index 86403d7f424f9..d98872f2b7ec0 100644
--- a/drivers/media/platform/arm/mali-vpu/Kconfig
+++ b/drivers/media/platform/arm/mali-vpu/Kconfig
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0-only
 config VIDEO_MALI_VPU
 	tristate "ARM Mali VPU driver"
+	depends on V4L_MEM2MEM_DRIVERS
 	depends on VIDEO_DEV
 	depends on !CPU_BIG_ENDIAN
 	help
diff --git a/drivers/media/platform/arm/mali-vpu/Makefile b/drivers/media/platform/arm/mali-vpu/Makefile
index 22acf82e99a88..e659101bd0eac 100644
--- a/drivers/media/platform/arm/mali-vpu/Makefile
+++ b/drivers/media/platform/arm/mali-vpu/Makefile
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0-only
 
 mali-vpu-objs := mali-vpu-probe.o \
-		mali-vpu-variant-v76.o
+		mali-vpu-variant-v76.o \
+		mali-vpu-vidioc.o
 
 obj-$(CONFIG_VIDEO_MALI_VPU) += mali-vpu.o
diff --git a/drivers/media/platform/arm/mali-vpu/mali-vpu-device.h b/drivers/media/platform/arm/mali-vpu/mali-vpu-device.h
index 04160090e64df..d9b0801cbb520 100644
--- a/drivers/media/platform/arm/mali-vpu/mali-vpu-device.h
+++ b/drivers/media/platform/arm/mali-vpu/mali-vpu-device.h
@@ -7,11 +7,22 @@
 #define __MALI_VPU_DEVICE_H__
 
 #include <linux/device.h>
+#include <media/v4l2-device.h>
+
+#define MALI_VPU_DRV_NAME "mali-vpu"
 
 struct clk_bulk_data;
 struct mali_vpu_variant;
 struct reset_control_bulk_data;
 
+/**
+ * enum mali_vpu_session_role - Mali VPU session role
+ * @MALI_VPU_DECODER: Video decoding session
+ */
+enum mali_vpu_session_role {
+	MALI_VPU_DECODER = 0,
+};
+
 /**
  * struct mali_vpu_dev - Mali VPU device
  * @dev: Reference to device structure.
@@ -22,6 +33,8 @@ struct reset_control_bulk_data;
  * @rst_count: Number of reset controls in @rst_list.
  * @irq: IRQ number for VPU.
  * @variant: Structure describing variant-specific features and capabilities.
+ * @v4l2_dev: V4L2 device structure for mali vpu.
+ * @vdev_dec: Video device structure for decoder.
  */
 struct mali_vpu_dev {
 	struct device			*dev;
@@ -33,6 +46,8 @@ struct mali_vpu_dev {
 	int				irq;
 
 	const struct mali_vpu_variant	*variant;
+	struct v4l2_device		v4l2_dev;
+	struct video_device		*vdev_dec;
 };
 
 #endif /* __MALI_VPU_DEVICE_H__ */
diff --git a/drivers/media/platform/arm/mali-vpu/mali-vpu-probe.c b/drivers/media/platform/arm/mali-vpu/mali-vpu-probe.c
index 49ecd6ac4554c..6d21cb731ee1d 100644
--- a/drivers/media/platform/arm/mali-vpu/mali-vpu-probe.c
+++ b/drivers/media/platform/arm/mali-vpu/mali-vpu-probe.c
@@ -15,10 +15,14 @@
 #include <linux/platform_device.h>
 #include <linux/reset.h>
 #include <linux/slab.h>
+#include <linux/string.h>
+#include <media/v4l2-dev.h>
+#include <media/v4l2-device.h>
 
 #include "mali-vpu-device.h"
 #include "mali-vpu-registers.h"
 #include "mali-vpu-variant.h"
+#include "mali-vpu-vidioc.h"
 
 /* VPU register access helpers */
 static u32 mali_vpu_read_reg(void __iomem *regs_base, u32 off)
@@ -119,6 +123,44 @@ static int mali_vpu_get_resources(struct mali_vpu_dev *vpu_dev)
 	return mali_vpu_get_resets(vpu_dev);
 }
 
+static int mali_vpu_register_video_device(struct mali_vpu_dev *vpu_dev,
+					  enum mali_vpu_session_role role)
+{
+	struct video_device *vdev;
+	int ret;
+
+	vdev = video_device_alloc();
+	if (!vdev)
+		return -ENOMEM;
+
+	vdev->release		= video_device_release;
+	vdev->fops		= &mali_vpu_fops;
+	vdev->vfl_dir		= VFL_DIR_M2M;
+	vdev->v4l2_dev		= &vpu_dev->v4l2_dev;
+	vdev->device_caps	= V4L2_CAP_VIDEO_M2M_MPLANE | V4L2_CAP_STREAMING;
+
+	if (role == MALI_VPU_DECODER) {
+		strscpy(vdev->name, "mali-vpu-decoder", sizeof(vdev->name));
+		vdev->ioctl_ops		= &mali_vpu_ioctl_ops_dec;
+		vpu_dev->vdev_dec	= vdev;
+	} else {
+		ret = -EINVAL;
+		goto err_vdev_release;
+	}
+
+	video_set_drvdata(vdev, vpu_dev);
+
+	ret = video_register_device(vdev, VFL_TYPE_VIDEO, -1);
+	if (ret)
+		goto err_vdev_release;
+
+	return 0;
+
+err_vdev_release:
+	video_device_release(vdev);
+	return ret;
+}
+
 static int mali_vpu_probe(struct platform_device *pdev)
 {
 	struct mali_vpu_dev *vpu_dev;
@@ -170,10 +212,22 @@ static int mali_vpu_probe(struct platform_device *pdev)
 		goto err_rst_clk;
 	}
 
+	ret = v4l2_device_register(&pdev->dev, &vpu_dev->v4l2_dev);
+	if (ret) {
+		dev_err(vpu_dev->dev, "failed to register V4L2 device\n");
+		goto err_rst_clk;
+	}
+
+	ret = mali_vpu_register_video_device(vpu_dev, MALI_VPU_DECODER);
+	if (ret)
+		goto err_unreg_v4l2;
+
 	platform_set_drvdata(pdev, vpu_dev);
 
 	return 0;
 
+err_unreg_v4l2:
+	v4l2_device_unregister(&vpu_dev->v4l2_dev);
 err_rst_clk:
 	mali_vpu_assert_reset(vpu_dev);
 err_clk:
@@ -186,6 +240,9 @@ static void mali_vpu_remove(struct platform_device *pdev)
 {
 	struct mali_vpu_dev *vpu_dev = platform_get_drvdata(pdev);
 
+	video_unregister_device(vpu_dev->vdev_dec);
+	v4l2_device_unregister(&vpu_dev->v4l2_dev);
+
 	mali_vpu_assert_reset(vpu_dev);
 	mali_vpu_disable_clk(vpu_dev);
 
@@ -205,7 +262,7 @@ static struct platform_driver mali_vpu_driver = {
 	.probe = mali_vpu_probe,
 	.remove = mali_vpu_remove,
 	.driver = {
-		.name = "mali-vpu",
+		.name = MALI_VPU_DRV_NAME,
 		.of_match_table = mali_vpu_dt_match,
 	},
 };
diff --git a/drivers/media/platform/arm/mali-vpu/mali-vpu-session.h b/drivers/media/platform/arm/mali-vpu/mali-vpu-session.h
new file mode 100644
index 0000000000000..7166c53236f1a
--- /dev/null
+++ b/drivers/media/platform/arm/mali-vpu/mali-vpu-session.h
@@ -0,0 +1,26 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) 2026 ARM Limited.
+ */
+
+#ifndef __MALI_VPU_SESSION_H__
+#define __MALI_VPU_SESSION_H__
+
+#include <media/v4l2-fh.h>
+
+#include "mali-vpu-device.h"
+
+/**
+ * struct mali_vpu_session - holds per session state and resources.
+ * @vpu_dev: Reference to the parent device structure.
+ * @role: Role of this session.
+ * @fh: V4L2 file handle for this session.
+ */
+struct mali_vpu_session {
+	struct mali_vpu_dev		*vpu_dev;
+	enum mali_vpu_session_role	role;
+
+	struct v4l2_fh		fh;
+};
+
+#endif /* __MALI_VPU_SESSION_H__ */
diff --git a/drivers/media/platform/arm/mali-vpu/mali-vpu-vidioc.c b/drivers/media/platform/arm/mali-vpu/mali-vpu-vidioc.c
new file mode 100644
index 0000000000000..7a169b7b14bf3
--- /dev/null
+++ b/drivers/media/platform/arm/mali-vpu/mali-vpu-vidioc.c
@@ -0,0 +1,78 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2026 ARM Limited.
+ */
+
+#include <linux/errno.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/string.h>
+#include <media/v4l2-dev.h>
+#include <media/v4l2-fh.h>
+#include <media/v4l2-ioctl.h>
+
+#include "mali-vpu-session.h"
+#include "mali-vpu-vidioc.h"
+
+static int mali_vpu_open(struct file *filp)
+{
+	struct video_device *vdev	= video_devdata(filp);
+	struct mali_vpu_dev *vpu_dev	= video_drvdata(filp);
+	struct mali_vpu_session *sess;
+	int ret;
+
+	sess = kzalloc_obj(*sess);
+	if (!sess)
+		return -ENOMEM;
+
+	if (vdev == vpu_dev->vdev_dec) {
+		sess->role = MALI_VPU_DECODER;
+	} else {
+		ret = -EINVAL;
+		goto err_free_sess;
+	}
+
+	sess->vpu_dev = vpu_dev;
+
+	v4l2_fh_init(&sess->fh, vdev);
+	v4l2_fh_add(&sess->fh, filp);
+
+	return 0;
+
+err_free_sess:
+	kfree(sess);
+	return ret;
+}
+
+static int mali_vpu_release(struct file *filp)
+{
+	struct mali_vpu_session *sess = container_of(file_to_v4l2_fh(filp),
+						     struct mali_vpu_session, fh);
+
+	v4l2_fh_del(&sess->fh, filp);
+	v4l2_fh_exit(&sess->fh);
+	kfree(sess);
+	return 0;
+}
+
+const struct v4l2_file_operations mali_vpu_fops = {
+	.owner		= THIS_MODULE,
+	.open		= mali_vpu_open,
+	.release	= mali_vpu_release,
+	.unlocked_ioctl = video_ioctl2,
+};
+
+static int mali_vpu_querycap(struct file *filp, void *fh,
+			     struct v4l2_capability *cap)
+{
+	struct video_device *vdev = video_devdata(filp);
+
+	strscpy(cap->driver, MALI_VPU_DRV_NAME, sizeof(cap->driver));
+	strscpy(cap->card, vdev->name, sizeof(cap->card));
+
+	return 0;
+}
+
+const struct v4l2_ioctl_ops mali_vpu_ioctl_ops_dec = {
+	.vidioc_querycap = mali_vpu_querycap,
+};
diff --git a/drivers/media/platform/arm/mali-vpu/mali-vpu-vidioc.h b/drivers/media/platform/arm/mali-vpu/mali-vpu-vidioc.h
new file mode 100644
index 0000000000000..e1aedea5bbcb6
--- /dev/null
+++ b/drivers/media/platform/arm/mali-vpu/mali-vpu-vidioc.h
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) 2026 ARM Limited.
+ */
+
+#ifndef __MALI_VPU_VIDIOC_H__
+#define __MALI_VPU_VIDIOC_H__
+
+struct v4l2_file_operations;
+struct v4l2_ioctl_ops;
+
+extern const struct v4l2_file_operations mali_vpu_fops;
+extern const struct v4l2_ioctl_ops mali_vpu_ioctl_ops_dec;
+
+#endif /* __MALI_VPU_VIDIOC_H__ */
-- 
2.43.0


  parent reply	other threads:[~2026-11-19 15:38 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 15:37 [RFC PATCH 00/28] media: add arm Mali-V76 video decoder driver Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 01/28] dt-bindings: media: add Arm Mali-V76 VPU Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 02/28] media: mali-vpu: add Mali VPU platform driver Charvi Mehta
2026-11-19 15:37 ` Charvi Mehta [this message]
2026-11-19 15:37 ` [RFC PATCH 04/28] media: mali-vpu: initialize decoder format state Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 05/28] media: mali-vpu: add V4L2 mem2mem and VB2 queue support Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 06/28] media: mali-vpu: implement format query ioctls Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 07/28] media: mali-vpu: implement TRY_FMT and S_FMT ioctls Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 08/28] media: mali-vpu: register V76 decoder controls and introduce UAPI controls Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 09/28] media: mali-vpu: add MMU software page table manager Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 10/28] media: mali-vpu: add firmware cache infrastructure Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 11/28] media: mali-vpu: load firmware for decoder sessions Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 12/28] media: mali-vpu: prepare firmware address space Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 13/28] media: mali-vpu: add firmware message transport Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 14/28] media: mali-vpu: route decoder controls to firmware Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 15/28] media: mali-vpu: handle firmware RPC requests Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 16/28] media: mali-vpu: add LSID hardware support Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 17/28] media: mali-vpu: add single session scheduler Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 18/28] media: mali-vpu: handle firmware interrupts Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 19/28] media: mali-vpu: start decoder firmware through LSID scheduling Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 20/28] media: mali-vpu: implement vb2 buffer queue handling Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 21/28] media: mali-vpu: handle firmware buffer exchange Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 22/28] media: mali-vpu: handle fatal firmware error Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 23/28] media: mali-vpu: propagate buffer metadata Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 24/28] media: mali-vpu: add decoder EOS and DRC handling Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 25/28] media: mali-vpu: handle firmware buffer parameters Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 26/28] media: mali-vpu: handle firmware event responses Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 27/28] media: mali-vpu: add stateful decoder state machine Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 28/28] media: MAINTAINERS: add Arm Mali-V76 VPU driver Charvi Mehta

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=20261119153758.1426673-4-charvi.mehta@arm.com \
    --to=charvi.mehta@arm.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=p.zabel@pengutronix.de \
    --cc=rath.sankaralingam@arm.com \
    --cc=robh@kernel.org \
    --cc=shobhit.pandey@arm.com \
    --cc=vincenzo.frascino@arm.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®