All of lore.kernel.org
 help / color / mirror / Atom feed
From: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
To: robh+dt@kernel.org, gregkh@linuxfoundation.org
Cc: devicetree@vger.kernel.org, ekangupt@qti.qualcomm.com,
	bkumar@qti.qualcomm.com, linux-kernel@vger.kernel.org,
	srini@kernel.org, bjorn.andersson@linaro.org,
	linux-arm-msm@vger.kernel.org,
	Vamsi Krishna Gattupalli <quic_vgattupa@quicinc.com>,
	Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Subject: [PATCH v3 10/12] misc: fastrpc: Add fdlist implementation
Date: Wed, 26 Jan 2022 13:53:02 +0000	[thread overview]
Message-ID: <20220126135304.16340-11-srinivas.kandagatla@linaro.org> (raw)
In-Reply-To: <20220126135304.16340-1-srinivas.kandagatla@linaro.org>

From: Vamsi Krishna Gattupalli <quic_vgattupa@quicinc.com>

Add fdlist implementation to support dma handles. fdlist is populated by
DSP if any map is no longer used and it is freed during put_args.

Signed-off-by: Vamsi Krishna Gattupalli <quic_vgattupa@quicinc.com>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 drivers/misc/fastrpc.c | 36 ++++++++++++++++++++++++++++++++----
 1 file changed, 32 insertions(+), 4 deletions(-)

diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
index 1c1815bed2c2..6052a9cb9e2c 100644
--- a/drivers/misc/fastrpc.c
+++ b/drivers/misc/fastrpc.c
@@ -319,7 +319,8 @@ static void fastrpc_map_get(struct fastrpc_map *map)
 		kref_get(&map->refcount);
 }
 
-static int fastrpc_map_find(struct fastrpc_user *fl, int fd,
+
+static int fastrpc_map_lookup(struct fastrpc_user *fl, int fd,
 			    struct fastrpc_map **ppmap)
 {
 	struct fastrpc_map *map = NULL;
@@ -327,7 +328,6 @@ static int fastrpc_map_find(struct fastrpc_user *fl, int fd,
 	mutex_lock(&fl->mutex);
 	list_for_each_entry(map, &fl->maps, node) {
 		if (map->fd == fd) {
-			fastrpc_map_get(map);
 			*ppmap = map;
 			mutex_unlock(&fl->mutex);
 			return 0;
@@ -338,6 +338,17 @@ static int fastrpc_map_find(struct fastrpc_user *fl, int fd,
 	return -ENOENT;
 }
 
+static int fastrpc_map_find(struct fastrpc_user *fl, int fd,
+			    struct fastrpc_map **ppmap)
+{
+	int ret = fastrpc_map_lookup(fl, fd, ppmap);
+
+	if (!ret)
+		fastrpc_map_get(*ppmap);
+
+	return ret;
+}
+
 static void fastrpc_buf_free(struct fastrpc_buf *buf)
 {
 	dma_free_coherent(buf->dev, buf->size, buf->virt,
@@ -410,7 +421,7 @@ static void fastrpc_context_free(struct kref *ref)
 	ctx = container_of(ref, struct fastrpc_invoke_ctx, refcount);
 	cctx = ctx->cctx;
 
-	for (i = 0; i < ctx->nscalars; i++)
+	for (i = 0; i < ctx->nbufs; i++)
 		fastrpc_map_put(ctx->maps[i]);
 
 	if (ctx->buf)
@@ -968,9 +979,19 @@ static int fastrpc_put_args(struct fastrpc_invoke_ctx *ctx,
 			    u32 kernel)
 {
 	struct fastrpc_remote_arg *rpra = ctx->rpra;
-	int i, inbufs;
+	struct fastrpc_user *fl = ctx->fl;
+	struct fastrpc_map *mmap = NULL;
+	struct fastrpc_invoke_buf *list;
+	struct fastrpc_phy_page *pages;
+	u64 *fdlist;
+	int i, inbufs, outbufs, handles;
 
 	inbufs = REMOTE_SCALARS_INBUFS(ctx->sc);
+	outbufs = REMOTE_SCALARS_OUTBUFS(ctx->sc);
+	handles = REMOTE_SCALARS_INHANDLES(ctx->sc) + REMOTE_SCALARS_OUTHANDLES(ctx->sc);
+	list = fastrpc_invoke_buf_start(rpra, ctx->nscalars);
+	pages = fastrpc_phy_page_start(list, ctx->nscalars);
+	fdlist = (uint64_t *)(pages + inbufs + outbufs + handles);
 
 	for (i = inbufs; i < ctx->nbufs; ++i) {
 		if (!ctx->maps[i]) {
@@ -987,6 +1008,13 @@ static int fastrpc_put_args(struct fastrpc_invoke_ctx *ctx,
 		}
 	}
 
+	for (i = 0; i < FASTRPC_MAX_FDLIST; i++) {
+		if (!fdlist[i])
+			break;
+		if (!fastrpc_map_lookup(fl, (int)fdlist[i], &mmap))
+			fastrpc_map_put(mmap);
+	}
+
 	return 0;
 }
 
-- 
2.21.0


  parent reply	other threads:[~2022-01-26 13:54 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-26 13:52 [PATCH v3 00/12] misc: fastrpc: Add missing DSP FastRPC features Srinivas Kandagatla
2022-01-26 13:52 ` [PATCH v3 01/12] misc: fastrpc: separate fastrpc device from channel context Srinivas Kandagatla
2022-01-26 13:52 ` [PATCH v3 02/12] misc: fastrpc: add support for FASTRPC_IOCTL_MEM_MAP/UNMAP Srinivas Kandagatla
2022-01-26 18:00   ` kernel test robot
2022-01-26 18:00     ` kernel test robot
2022-01-27  4:48   ` kernel test robot
2022-01-27  4:48     ` kernel test robot
2022-01-26 13:52 ` [PATCH v3 03/12] misc: fastrpc: Add support to get DSP capabilities Srinivas Kandagatla
2022-01-26 21:04   ` kernel test robot
2022-01-26 21:04     ` kernel test robot
2022-01-26 13:52 ` [PATCH v3 04/12] dt-bindings: misc: add property to support non-secure DSP Srinivas Kandagatla
2022-02-07 20:44   ` Rob Herring
2022-01-26 13:52 ` [PATCH v3 05/12] misc: fastrpc: add secure domain support Srinivas Kandagatla
2022-01-26 13:52 ` [PATCH v3 06/12] misc: fastrpc: check before loading process to the DSP Srinivas Kandagatla
2022-01-26 13:52 ` [PATCH v3 07/12] dt-bindings: misc: add fastrpc domain vmid property Srinivas Kandagatla
2022-02-07 20:45   ` Rob Herring
2022-01-26 13:53 ` [PATCH v3 08/12] misc: fastrpc: Add support to secure memory map Srinivas Kandagatla
2022-01-26 13:53 ` [PATCH v3 09/12] misc: fastrpc: Add helper function to get list and page Srinivas Kandagatla
2022-01-26 13:53 ` Srinivas Kandagatla [this message]
2022-01-26 13:53 ` [PATCH v3 11/12] misc: fastrpc: Add dma handle implementation Srinivas Kandagatla
2022-01-26 20:13   ` kernel test robot
2022-01-26 20:13     ` kernel test robot
2022-01-26 20:14   ` kernel test robot
2022-01-26 20:14     ` kernel test robot
2022-01-26 13:53 ` [PATCH v3 12/12] arm64: dts: qcom: add non-secure domain property to fastrpc nodes Srinivas Kandagatla
2022-04-08 13:37 ` [PATCH v3 00/12] misc: fastrpc: Add missing DSP FastRPC features patchwork-bot+linux-arm-msm
2022-01-27 10:15 [PATCH v3 01/12] misc: fastrpc: separate fastrpc device from channel context kernel test robot
2022-01-27 11:33 ` Dan Carpenter
2022-01-27 11:33 ` Dan Carpenter
2022-01-27 13:09 [PATCH v3 11/12] misc: fastrpc: Add dma handle implementation kernel test robot
2022-01-28  7:09 ` Dan Carpenter
2022-01-28  7:09 ` Dan Carpenter

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=20220126135304.16340-11-srinivas.kandagatla@linaro.org \
    --to=srinivas.kandagatla@linaro.org \
    --cc=bjorn.andersson@linaro.org \
    --cc=bkumar@qti.qualcomm.com \
    --cc=devicetree@vger.kernel.org \
    --cc=ekangupt@qti.qualcomm.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=quic_vgattupa@quicinc.com \
    --cc=robh+dt@kernel.org \
    --cc=srini@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 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.