From: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
To: Ekansh Gupta <ekansh.gupta@oss.qualcomm.com>
Cc: Oded Gabbay <ogabbay@kernel.org>,
Jonathan Corbet <corbet@lwn.net>,
Shuah Khan <skhan@linuxfoundation.org>,
Joerg Roedel <joro@8bytes.org>, Will Deacon <will@kernel.org>,
Robin Murphy <robin.murphy@arm.com>,
Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
Maxime Ripard <mripard@kernel.org>,
Thomas Zimmermann <tzimmermann@suse.de>,
David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>,
Sumit Semwal <sumit.semwal@linaro.org>,
Christian König <christian.koenig@amd.com>,
dri-devel@lists.freedesktop.org, linux-doc@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org,
iommu@lists.linux.dev, linux-media@vger.kernel.org,
linaro-mm-sig@lists.linaro.org,
Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>,
Bharath Kumar <quic_bkumar@quicinc.com>,
Chenna Kesava Raju <quic_chennak@quicinc.com>
Subject: Re: [PATCH RFC 08/18] accel/qda: Add per-file DRM context and open/close handling
Date: Tue, 24 Feb 2026 00:20:50 +0200 [thread overview]
Message-ID: <rnhqwqtd66fmvmyobhrodzoa7x2etzjjh7xhqrn5hkmibms5cd@ucggzznrx7j6> (raw)
In-Reply-To: <20260224-qda-firstpost-v1-8-fe46a9c1a046@oss.qualcomm.com>
On Tue, Feb 24, 2026 at 12:39:02AM +0530, Ekansh Gupta wrote:
> Introduce per-file and per-user context for the QDA DRM accelerator
> driver. A new qda_file_priv structure is stored in file->driver_priv
> for each open file descriptor, and a qda_user object is allocated per
> client with a unique client_id generated from an atomic counter in
> qda_dev.
>
> The DRM driver now provides qda_open() and qda_postclose() callbacks.
> qda_open() resolves the qda_dev from the drm_device, allocates the
> qda_file_priv and qda_user structures, and attaches them to the DRM
> file. qda_postclose() tears down the per-file context and frees the
> qda_user object when the file is closed.
>
> This prepares the QDA driver to track per-process state for future
> features such as per-client memory mappings, job submission contexts,
> and access control over DSP compute resources.
Start by describing the problem instead of stuffing it to the end. Can
we use something better suited for this task, like IDR?
> Signed-off-by: Ekansh Gupta <ekansh.gupta@oss.qualcomm.com>
> ---
> drivers/accel/qda/qda_drv.c | 117 ++++++++++++++++++++++++++++++++++++++++++++
> drivers/accel/qda/qda_drv.h | 30 ++++++++++++
> 2 files changed, 147 insertions(+)
>
> diff --git a/drivers/accel/qda/qda_drv.c b/drivers/accel/qda/qda_drv.c
> index a9113ec78fa2..bf95fc782cf8 100644
> --- a/drivers/accel/qda/qda_drv.c
> +++ b/drivers/accel/qda/qda_drv.c
> @@ -12,11 +12,127 @@
> #include "qda_drv.h"
> #include "qda_rpmsg.h"
>
> +static struct qda_drm_priv *get_drm_priv_from_device(struct drm_device *dev)
> +{
> + if (!dev)
> + return NULL;
> +
> + return (struct qda_drm_priv *)dev->dev_private;
> +}
> +
> +static struct qda_dev *get_qdev_from_drm_device(struct drm_device *dev)
> +{
> + struct qda_drm_priv *drm_priv;
> +
> + if (!dev) {
> + qda_dbg(NULL, "Invalid drm_device\n");
> + return NULL;
> + }
> +
> + drm_priv = get_drm_priv_from_device(dev);
> + if (!drm_priv) {
> + qda_dbg(NULL, "No drm_priv in dev_private\n");
> + return NULL;
> + }
> +
> + return drm_priv->qdev;
> +}
> +
> +static struct qda_user *alloc_qda_user(struct qda_dev *qdev)
> +{
> + struct qda_user *qda_user;
> +
> + qda_user = kzalloc_obj(*qda_user, GFP_KERNEL);
> + if (!qda_user)
> + return NULL;
> +
> + qda_user->client_id = atomic_inc_return(&qdev->client_id_counter);
> + qda_user->qda_dev = qdev;
> +
> + qda_dbg(qdev, "Allocated qda_user with client_id=%u\n", qda_user->client_id);
> + return qda_user;
> +}
> +
> +static void free_qda_user(struct qda_user *qda_user)
> +{
> + if (!qda_user)
> + return;
> +
> + qda_dbg(qda_user->qda_dev, "Freeing qda_user client_id=%u\n", qda_user->client_id);
> +
> + kfree(qda_user);
> +}
> +
> +static int qda_open(struct drm_device *dev, struct drm_file *file)
> +{
> + struct qda_user *qda_user;
> + struct qda_file_priv *qda_file_priv;
> + struct qda_dev *qdev;
> +
> + if (!file) {
> + qda_dbg(NULL, "Invalid file pointer\n");
> + return -EINVAL;
> + }
> +
> + qdev = get_qdev_from_drm_device(dev);
> + if (!qdev) {
> + qda_dbg(NULL, "Failed to get qdev from drm_device\n");
> + return -EINVAL;
> + }
> +
> + qda_file_priv = kzalloc(sizeof(*qda_file_priv), GFP_KERNEL);
> + if (!qda_file_priv)
> + return -ENOMEM;
> +
> + qda_file_priv->pid = current->pid;
> +
> + qda_user = alloc_qda_user(qdev);
> + if (!qda_user) {
> + qda_dbg(qdev, "Failed to allocate qda_user\n");
> + kfree(qda_file_priv);
> + return -ENOMEM;
> + }
> +
> + file->driver_priv = qda_file_priv;
> + qda_file_priv->qda_user = qda_user;
> +
> + qda_dbg(qdev, "Device opened successfully for PID %d\n", current->pid);
> +
> + return 0;
> +}
> +
> +static void qda_postclose(struct drm_device *dev, struct drm_file *file)
> +{
> + struct qda_dev *qdev;
> + struct qda_file_priv *qda_file_priv;
> + struct qda_user *qda_user;
> +
> + qdev = get_qdev_from_drm_device(dev);
> + if (!qdev || atomic_read(&qdev->removing)) {
> + qda_dbg(NULL, "Device unavailable or removing\n");
> + return;
Even if it is being removed, no need to free the memory?
> + }
> +
> + qda_file_priv = (struct qda_file_priv *)file->driver_priv;
> + if (qda_file_priv) {
> + qda_user = qda_file_priv->qda_user;
> + if (qda_user)
> + free_qda_user(qda_user);
> +
> + kfree(qda_file_priv);
> + file->driver_priv = NULL;
> + }
> +
> + qda_dbg(qdev, "Device closed for PID %d\n", current->pid);
> +}
> +
> DEFINE_DRM_ACCEL_FOPS(qda_accel_fops);
>
> static struct drm_driver qda_drm_driver = {
> .driver_features = DRIVER_COMPUTE_ACCEL,
> .fops = &qda_accel_fops,
> + .open = qda_open,
> + .postclose = qda_postclose,
> .name = DRIVER_NAME,
> .desc = "Qualcomm DSP Accelerator Driver",
> };
> @@ -58,6 +174,7 @@ static void init_device_resources(struct qda_dev *qdev)
>
> mutex_init(&qdev->lock);
> atomic_set(&qdev->removing, 0);
> + atomic_set(&qdev->client_id_counter, 0);
> }
>
> static int init_memory_manager(struct qda_dev *qdev)
> diff --git a/drivers/accel/qda/qda_drv.h b/drivers/accel/qda/qda_drv.h
> index 2b80401a3741..e0ba37702a86 100644
> --- a/drivers/accel/qda/qda_drv.h
> +++ b/drivers/accel/qda/qda_drv.h
> @@ -10,6 +10,7 @@
> #include <linux/list.h>
> #include <linux/mutex.h>
> #include <linux/rpmsg.h>
> +#include <linux/types.h>
> #include <linux/xarray.h>
> #include <drm/drm_drv.h>
> #include <drm/drm_file.h>
> @@ -20,6 +21,33 @@
> /* Driver identification */
> #define DRIVER_NAME "qda"
>
> +/**
> + * struct qda_file_priv - Per-process private data for DRM file
> + *
> + * This structure tracks per-process state for each open file descriptor.
> + * It maintains the IOMMU device assignment and links to the legacy qda_user
> + * structure for compatibility with existing code.
> + */
> +struct qda_file_priv {
> + /* Process ID for tracking */
> + pid_t pid;
> + /* Pointer to qda_user structure for backward compatibility */
> + struct qda_user *qda_user;
> +};
> +
> +/**
> + * struct qda_user - Per-user context for remote processor interaction
> + *
> + * This structure maintains per-user state for interactions with the
> + * remote processor, including memory mappings and pending operations.
> + */
> +struct qda_user {
> + /* Unique client identifier */
> + u32 client_id;
> + /* Back-pointer to device structure */
> + struct qda_dev *qda_dev;
> +};
> +
> /**
> * struct qda_drm_priv - DRM device private data for QDA device
> *
> @@ -52,6 +80,8 @@ struct qda_dev {
> struct qda_drm_priv *drm_priv;
> /* Flag indicating device removal in progress */
> atomic_t removing;
> + /* Atomic counter for generating unique client IDs */
> + atomic_t client_id_counter;
> /* Name of the DSP (e.g., "cdsp", "adsp") */
> char dsp_name[16];
> /* Compute context-bank (CB) child devices */
>
> --
> 2.34.1
>
--
With best wishes
Dmitry
next prev parent reply other threads:[~2026-02-23 22:20 UTC|newest]
Thread overview: 81+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <vU2QyEVqOu-D3eGp7BZFICUeauxL32bwWzeidOAijoeVaJTk8KcRVsaQQD4MdFQEcaQTZ5RkzRsz9-Lhl1qsqg==@protonmail.internalid>
2026-02-23 19:08 ` [PATCH RFC 00/18] accel/qda: Introduce Qualcomm DSP Accelerator driver Ekansh Gupta
2026-02-23 19:08 ` [PATCH RFC 01/18] accel/qda: Add Qualcomm QDA DSP accelerator driver docs Ekansh Gupta
2026-02-23 21:17 ` Dmitry Baryshkov
2026-02-25 13:57 ` Ekansh Gupta
2026-02-25 17:17 ` Dmitry Baryshkov
2026-02-24 3:33 ` Trilok Soni
2026-02-25 14:17 ` Ekansh Gupta
2026-02-25 15:12 ` Bjorn Andersson
2026-02-25 19:16 ` Trilok Soni
2026-02-25 19:40 ` Dmitry Baryshkov
2026-02-25 23:18 ` Trilok Soni
2026-02-24 8:20 ` Claude review: " Claude Code Review Bot
2026-02-23 19:08 ` [PATCH RFC 02/18] accel/qda: Add Qualcomm DSP accelerator driver skeleton Ekansh Gupta
2026-02-23 21:52 ` Bjorn Andersson
2026-02-25 14:20 ` Ekansh Gupta
2026-02-24 8:20 ` Claude review: " Claude Code Review Bot
2026-02-23 19:08 ` [PATCH RFC 03/18] accel/qda: Add RPMsg transport for Qualcomm DSP accelerator Ekansh Gupta
2026-02-23 21:23 ` Dmitry Baryshkov
2026-02-23 21:50 ` Bjorn Andersson
2026-02-23 22:12 ` Dmitry Baryshkov
2026-02-23 22:25 ` Bjorn Andersson
2026-02-23 22:41 ` Dmitry Baryshkov
2026-02-25 17:16 ` Ekansh Gupta
2026-02-24 8:20 ` Claude review: " Claude Code Review Bot
2026-02-23 19:08 ` [PATCH RFC 04/18] accel/qda: Add built-in compute CB bus for QDA and integrate with IOMMU Ekansh Gupta
2026-02-23 22:44 ` Dmitry Baryshkov
2026-02-25 17:56 ` Ekansh Gupta
2026-02-25 19:09 ` Dmitry Baryshkov
2026-02-24 8:20 ` Claude review: " Claude Code Review Bot
2026-02-26 10:46 ` [PATCH RFC 04/18] " Krzysztof Kozlowski
2026-02-23 19:08 ` [PATCH RFC 05/18] accel/qda: Create compute CB devices on QDA compute bus Ekansh Gupta
2026-02-23 22:49 ` Dmitry Baryshkov
2026-02-26 8:38 ` Ekansh Gupta
2026-02-26 10:46 ` Dmitry Baryshkov
2026-02-24 8:20 ` Claude review: " Claude Code Review Bot
2026-02-23 19:09 ` [PATCH RFC 06/18] accel/qda: Add memory manager for CB devices Ekansh Gupta
2026-02-23 22:50 ` Dmitry Baryshkov
2026-02-23 23:11 ` Bjorn Andersson
2026-02-24 8:20 ` Claude review: " Claude Code Review Bot
2026-02-23 19:09 ` [PATCH RFC 07/18] accel/qda: Add DRM accel device registration for QDA driver Ekansh Gupta
2026-02-23 22:16 ` Dmitry Baryshkov
2026-02-24 8:20 ` Claude review: " Claude Code Review Bot
2026-02-23 19:09 ` [PATCH RFC 08/18] accel/qda: Add per-file DRM context and open/close handling Ekansh Gupta
2026-02-23 22:20 ` Dmitry Baryshkov [this message]
2026-02-24 8:20 ` Claude review: " Claude Code Review Bot
2026-02-23 19:09 ` [PATCH RFC 09/18] accel/qda: Add QUERY IOCTL and basic QDA UAPI header Ekansh Gupta
2026-02-23 22:24 ` Dmitry Baryshkov
2026-02-24 8:20 ` Claude review: " Claude Code Review Bot
2026-02-23 19:09 ` [PATCH RFC 10/18] accel/qda: Add DMA-backed GEM objects and memory manager integration Ekansh Gupta
2026-02-23 22:36 ` Dmitry Baryshkov
2026-02-24 8:20 ` Claude review: " Claude Code Review Bot
2026-02-23 19:09 ` [PATCH RFC 11/18] accel/qda: Add GEM_CREATE and GEM_MMAP_OFFSET IOCTLs Ekansh Gupta
2026-02-23 22:39 ` Dmitry Baryshkov
2026-02-24 8:20 ` Claude review: " Claude Code Review Bot
2026-02-24 9:05 ` [PATCH RFC 11/18] " Christian König
2026-02-23 19:09 ` [PATCH RFC 12/18] accel/qda: Add PRIME dma-buf import support Ekansh Gupta
2026-02-24 8:20 ` Claude review: " Claude Code Review Bot
2026-02-24 8:52 ` [PATCH RFC 12/18] " Matthew Brost
2026-02-24 9:12 ` Christian König
2026-02-23 19:09 ` [PATCH RFC 13/18] accel/qda: Add initial FastRPC attach and release support Ekansh Gupta
2026-02-23 23:07 ` Dmitry Baryshkov
2026-02-24 8:20 ` Claude review: " Claude Code Review Bot
2026-02-23 19:09 ` [PATCH RFC 14/18] accel/qda: Add FastRPC dynamic invocation support Ekansh Gupta
2026-02-23 23:10 ` Dmitry Baryshkov
2026-02-24 8:20 ` Claude review: " Claude Code Review Bot
2026-02-23 19:09 ` [PATCH RFC 15/18] accel/qda: Add FastRPC DSP process creation support Ekansh Gupta
2026-02-24 8:20 ` Claude review: " Claude Code Review Bot
2026-02-23 19:09 ` [PATCH RFC 16/18] accel/qda: Add FastRPC-based DSP memory mapping support Ekansh Gupta
2026-02-24 8:20 ` Claude review: " Claude Code Review Bot
2026-02-26 10:48 ` [PATCH RFC 16/18] " Krzysztof Kozlowski
2026-02-23 19:09 ` [PATCH RFC 17/18] accel/qda: Add FastRPC-based DSP memory unmapping support Ekansh Gupta
2026-02-24 8:20 ` Claude review: " Claude Code Review Bot
2026-02-23 19:09 ` [PATCH RFC 18/18] MAINTAINERS: Add MAINTAINERS entry for QDA driver Ekansh Gupta
2026-02-23 22:40 ` Dmitry Baryshkov
2026-02-24 8:20 ` Claude review: " Claude Code Review Bot
2026-02-23 22:03 ` [PATCH RFC 00/18] accel/qda: Introduce Qualcomm DSP Accelerator driver Bjorn Andersson
2026-02-24 3:37 ` Trilok Soni
2026-02-24 3:39 ` Trilok Soni
2026-02-24 6:39 ` Claude review: " Claude Code Review Bot
2026-02-25 13:42 ` [PATCH RFC 00/18] " Bryan O'Donoghue
2026-02-25 19:12 ` Dmitry Baryshkov
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=rnhqwqtd66fmvmyobhrodzoa7x2etzjjh7xhqrn5hkmibms5cd@ucggzznrx7j6 \
--to=dmitry.baryshkov@oss.qualcomm.com \
--cc=airlied@gmail.com \
--cc=christian.koenig@amd.com \
--cc=corbet@lwn.net \
--cc=dri-devel@lists.freedesktop.org \
--cc=ekansh.gupta@oss.qualcomm.com \
--cc=iommu@lists.linux.dev \
--cc=joro@8bytes.org \
--cc=linaro-mm-sig@lists.linaro.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=ogabbay@kernel.org \
--cc=quic_bkumar@quicinc.com \
--cc=quic_chennak@quicinc.com \
--cc=robin.murphy@arm.com \
--cc=simona@ffwll.ch \
--cc=skhan@linuxfoundation.org \
--cc=srinivas.kandagatla@oss.qualcomm.com \
--cc=sumit.semwal@linaro.org \
--cc=tzimmermann@suse.de \
--cc=will@kernel.org \
/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