From patchwork Fri Feb 1 13:09:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 157204 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp408622jaa; Fri, 1 Feb 2019 05:11:11 -0800 (PST) X-Google-Smtp-Source: AHgI3IbqHI3m0dt1ReRhqOSqMdkVKj4FjCeOlx5Q4pfGw3uqk4gojjiZhwEgSy3mva9etwQs0Jsi X-Received: by 2002:a63:85c6:: with SMTP id u189mr2152021pgd.156.1549026670939; Fri, 01 Feb 2019 05:11:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549026670; cv=none; d=google.com; s=arc-20160816; b=C2JdPxlZmWqt/dPPor9uQe5KykqZ4QAblZhzoZbgNbOiXU3A+xWBnMWROAlKh19fvS EYFwM+ebjA+9buMr1vduNdxZ8htkKyQeKtydYmsnBRakClSlY1g14dEsEE3ep6I03PDC V7xUUFcWwVBYZ5tOh9qJ+ITsNBl8Mof2jcvhZlb/S0NzIs5OCPKlsNJYrt77qdWjzRIB 7YrBIY3qoG4BeAL0KKuwgdouXCR7i4YOVuTRGfFgGiupGfXW/lfVCLl08h6Ua3nqZSp5 sG6SIY7khIwbKoPUG3O+X9fyKghxrFAwOsHLsuObR0Xt4QBGkEaJDwYC+Bk+/B5AZIUn d/ZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=bIjMZWBApTZOoaJL6tl091AuE0dnp0afLV6yVMOATA4=; b=1I0QEe/gOAT7PXuKsDqQwDcnK5hGg5zREa7KeF+M1EnFzckwE1LUABg4X0OMnbYAph 9WL8LVtzBrR6IlSwKvXAdwoVY3oM/1O4bCfWrhZTdVkoYVkN+MjFyBqSAcJjah9USlxg XMJqllMrKLm13kuhJ334OZ4f1linSdtwSEL6juAZguGKb434jZZ/PA3lRpHMWvWOYx9G ZNmXtsFGIyCZk0DlF+elEwOTDC4YZJiXub7eshG7KBqGTxZc1EycXDo5JiGEMwt4bTXR GxorC9ALpEMu9qBrU/fYHUQ4+aXbOjd+DX9PlpBAbHUgEC8JTTb0QpR9OLWRf7CA03K1 TVbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XiHcgq1a; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e7si7035636pgi.263.2019.02.01.05.11.09; Fri, 01 Feb 2019 05:11:10 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XiHcgq1a; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729449AbfBANLH (ORCPT + 31 others); Fri, 1 Feb 2019 08:11:07 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:40778 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727387AbfBANLG (ORCPT ); Fri, 1 Feb 2019 08:11:06 -0500 Received: by mail-wr1-f65.google.com with SMTP id p4so7016363wrt.7 for ; Fri, 01 Feb 2019 05:11:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bIjMZWBApTZOoaJL6tl091AuE0dnp0afLV6yVMOATA4=; b=XiHcgq1aAFJuWzvkuXssoWFFSvUcQIfrZgJK2K07DZgY1KWgvVd4+CsGUyjeS6aysD 2iavZyZYneQKqLpKtUYY/2jKuR/9TU8fyPpjldyd0Z3zgys6KCvJtJ+axz3BBCzHdjNk tBSTQ45hpSUE5IeZc0Uh/FHKD71nfP+PnQkFs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bIjMZWBApTZOoaJL6tl091AuE0dnp0afLV6yVMOATA4=; b=ZU5kLSCz875PqRWxkEkqiGr5D58+e56YFm/5G6YNHkBEQtZlBnD9EEnwyTc2IFVbKs G76T1yu95Pt1mxY8Y9oCS4xlCIciDRs3xS48aDLrIZz80prwK2/7j3M7jRDtwCNDQB16 eT+0OPnu6WWMfKFoPAOEkRvm/K4vdjukKxm4Vg6ri9qZnlIJwD9EQlJeNUkNn/E3bpQT k42Qv6UEtci5D/IjPYwApbnd8yxkam35Fz2mo5WlB+F3dccZZcqnw54ehRTQ/HeeT53E mSDtjWZs1RHo0CJ6SgQMG8nbi6uJWjNkhhIwqwmEbPg0W8pishHutiw+EUtLab45GvtH fAAg== X-Gm-Message-State: AJcUukeqzLOYVBOXHlcLCRPg7fRbo9jwFGDIMF5qpQniJbdTXSQ86iwM E3omyPH0Rn2+DnAniBtjLrHcxw== X-Received: by 2002:adf:f308:: with SMTP id i8mr36942302wro.219.1549026664301; Fri, 01 Feb 2019 05:11:04 -0800 (PST) Received: from srini-hackbox.lan (cpc89974-aztw32-2-0-cust43.18-1.cable.virginm.net. [86.30.250.44]) by smtp.gmail.com with ESMTPSA id a12sm12563461wro.18.2019.02.01.05.11.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 01 Feb 2019 05:11:03 -0800 (PST) From: Srinivas Kandagatla To: gregkh@linuxfoundation.org, arnd@arndb.de Cc: robh+dt@kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, bjorn.andersson@linaro.org, bkumar@qti.qualcomm.com, linux-arm-msm@vger.kernel.org, Srinivas Kandagatla , Thierry Escande , Rob Herring Subject: [PATCH v5 1/5] misc: dt-bindings: Add Qualcomm Fastrpc bindings Date: Fri, 1 Feb 2019 13:09:21 +0000 Message-Id: <20190201130925.27066-2-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190201130925.27066-1-srinivas.kandagatla@linaro.org> References: <20190201130925.27066-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The FastRPC driver implements an IPC (Inter-Processor Communication) mechanism that allows for clients to transparently make remote method invocations across DSP and APPS boundaries. This enables developers to offload tasks to the DSP and free up the application processor for other tasks. Co-developed-by: Thierry Escande Signed-off-by: Thierry Escande Signed-off-by: Srinivas Kandagatla Reviewed-by: Rob Herring --- .../devicetree/bindings/misc/qcom,fastrpc.txt | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 Documentation/devicetree/bindings/misc/qcom,fastrpc.txt -- 2.20.1 diff --git a/Documentation/devicetree/bindings/misc/qcom,fastrpc.txt b/Documentation/devicetree/bindings/misc/qcom,fastrpc.txt new file mode 100644 index 000000000000..2a1827ab50d2 --- /dev/null +++ b/Documentation/devicetree/bindings/misc/qcom,fastrpc.txt @@ -0,0 +1,78 @@ +Qualcomm Technologies, Inc. FastRPC Driver + +The FastRPC implements an IPC (Inter-Processor Communication) +mechanism that allows for clients to transparently make remote method +invocations across DSP and APPS boundaries. This enables developers +to offload tasks to the DSP and free up the application processor for +other tasks. + +- compatible: + Usage: required + Value type: + Definition: must be "qcom,fastrpc" + +- label + Usage: required + Value type: + Definition: should specify the dsp domain name this fastrpc + corresponds to. must be one of this: "adsp", "mdsp", "sdsp", "cdsp" + +- #address-cells + Usage: required + Value type: + Definition: Must be 1 + +- #size-cells + Usage: required + Value type: + Definition: Must be 0 + += COMPUTE BANKS +Each subnode of the Fastrpc represents compute context banks available +on the dsp. +- All Compute context banks MUST contain the following properties: + +- compatible: + Usage: required + Value type: + Definition: must be "qcom,fastrpc-compute-cb" + +- reg + Usage: required + Value type: + Definition: Context Bank ID. + +- qcom,nsessions: + Usage: Optional + Value type: + Defination: A value indicating how many sessions can share this + context bank. Defaults to 1 when this property + is not specified. + +Example: + +adsp-pil { + compatible = "qcom,msm8996-adsp-pil"; + ... + smd-edge { + label = "lpass"; + fastrpc { + compatible = "qcom,fastrpc"; + qcom,smd-channels = "fastrpcsmd-apps-dsp"; + label = "adsp"; + #address-cells = <1>; + #size-cells = <0>; + + cb@1 { + compatible = "qcom,fastrpc-compute-cb"; + reg = <1>; + }; + + cb@2 { + compatible = "qcom,fastrpc-compute-cb"; + reg = <2>; + }; + ... + }; + }; +}; From patchwork Fri Feb 1 13:09:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 157207 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp408728jaa; Fri, 1 Feb 2019 05:11:15 -0800 (PST) X-Google-Smtp-Source: AHgI3IZ457830kyeDzY5hnQzTQd6S2RaIbdvfMErl5nFp325GSu+9QZcXpMOtptf56sOYWwvyoPe X-Received: by 2002:a63:1a4b:: with SMTP id a11mr2245864pgm.254.1549026675422; Fri, 01 Feb 2019 05:11:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549026675; cv=none; d=google.com; s=arc-20160816; b=IGQ/QbDY08pGdHWtmUvTZOlK2m+sfBhlxR5pxZCqNNeHzuQBjhJJRTbzuT0tt6dZxI lv8WWYkrQaGNRKBSc0FboE4xeMxlcD3783IDNlFQOrwhbw8EJP9/XvY2Qdd702ph0KaD qEmipcFIQtDDrryT4gLR//6POCkAXDK7julA/y8xFxq3B1weDn744ArPtmPw/5kgWbAS 9GMyUyLRTZmTkoDvVRD+re6EJvVODXIPJQSWioLzGTH9gG+emDGIets3XDyR63gNI8a+ qitsRh82EFS9z9ZXOI0TVExCwGlw+fGBw6rZ1Jqth8bU+EqeHeN+d/mrpF3p55rZvZZt g06g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=dnjcDyUx4RSE7rN721Qv9vTeXijiBMnvH5H/E5EABH8=; b=rr7paZ7miuWG1ept1R68/yZUtJR5ffVZwH1JpoqnRjgsQRXi02au997HzjJlLJMStc qo4lQbJxeVV+PD7FhYzKyOB+KiDAeY+0B7eQ4QPeeATRRmBRsciRbs3pmNdWepENAK+n v8huIWs3wuDS97GpOzG4zlnmGW7Mbvhel1tMgFB/kynd0ylQOCwuEEjwfw5CUxTclim1 1jAxJDOwlnrj93krLSiuvpdZk7nmuIDt/5Jsk894ID5+Sc0GwoNJDNYHaOAT5xPGRup8 F7Usf8vmj0oJ1q9+1/UOEmRFibPzVKnS10a9rNGNoI+EyIKaax6UZwpTqMUHGuTYLXpy SKuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="NrKj/x7Z"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b28si6333800pgm.409.2019.02.01.05.11.15; Fri, 01 Feb 2019 05:11:15 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="NrKj/x7Z"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729576AbfBANLN (ORCPT + 31 others); Fri, 1 Feb 2019 08:11:13 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:33980 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729363AbfBANLI (ORCPT ); Fri, 1 Feb 2019 08:11:08 -0500 Received: by mail-wm1-f68.google.com with SMTP id y185so4519608wmd.1 for ; Fri, 01 Feb 2019 05:11:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dnjcDyUx4RSE7rN721Qv9vTeXijiBMnvH5H/E5EABH8=; b=NrKj/x7ZnzubvKDRq+nFCa/nvZKnXjX2z1fyRZDANx9LzUbaBwVxNnY4UUM1i1lz3X OTSOcozRyuKY2EW1DVBKiuKgvk3Ujc8Uh160rH15HrKKUqafs2dZRNn4sngSCRBkUxq0 sNhfh/E10WrHWVrHYwEpeDW8rrsvmWixTNNEI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dnjcDyUx4RSE7rN721Qv9vTeXijiBMnvH5H/E5EABH8=; b=kaDp7EU6SBt9J7evUUJVVPtwFSSGEE6FTdryjra5ogAlTMBUiVI2UePfs/LNbd4lmM /bOup2evsmbpZR0cyCzH2CK2AH4KlUydgzzmTK/7Ku5kpGfOHa0rmdbKv5JNm2YHRDSU urdslcrMepYT4W9Nzf/GTPPkrGlEzK5wYkkRZmd2tokX683USKe63rjuCxXfONbgGnwD Q7bussVsLrquorCvchrJT9cIOHSUSw4eAFRKaWRYYgyXuC6VjqAfuY+6v5oTYeI3WmVK 6tUD8B+oqg6uWYbS2ur7VG9YdIHR8Jll2frrWb+5vb8DizyPnCcGwRXPtVaJ6wCMAb0q u9RQ== X-Gm-Message-State: AHQUAuaK3vLZuvTH2s6KF+WymWezHvRwwZ5NbdrVpgmfyXTb8v3Vy08B BfQlIu060X6LlZfw0742dLJq+w== X-Received: by 2002:a1c:c64e:: with SMTP id w75mr2539323wmf.46.1549026665879; Fri, 01 Feb 2019 05:11:05 -0800 (PST) Received: from srini-hackbox.lan (cpc89974-aztw32-2-0-cust43.18-1.cable.virginm.net. [86.30.250.44]) by smtp.gmail.com with ESMTPSA id a12sm12563461wro.18.2019.02.01.05.11.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 01 Feb 2019 05:11:05 -0800 (PST) From: Srinivas Kandagatla To: gregkh@linuxfoundation.org, arnd@arndb.de Cc: robh+dt@kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, bjorn.andersson@linaro.org, bkumar@qti.qualcomm.com, linux-arm-msm@vger.kernel.org, Srinivas Kandagatla , Thierry Escande Subject: [PATCH v5 2/5] misc: fastrpc: Add Qualcomm fastrpc basic driver model Date: Fri, 1 Feb 2019 13:09:22 +0000 Message-Id: <20190201130925.27066-3-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190201130925.27066-1-srinivas.kandagatla@linaro.org> References: <20190201130925.27066-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch adds basic driver model for Qualcomm FastRPC driver which implements an IPC (Inter-Processor Communication) mechanism that allows for clients to transparently make remote method invocations across processor boundaries. Each DSP rpmsg channel is represented as fastrpc channel context and is exposed as a character device for userspace interface. Each compute context bank is represented as fastrpc-session-context, which are dynamically managed by the channel context char device. Co-developed-by: Thierry Escande Signed-off-by: Thierry Escande Signed-off-by: Srinivas Kandagatla --- drivers/misc/Kconfig | 10 ++ drivers/misc/Makefile | 1 + drivers/misc/fastrpc.c | 322 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 333 insertions(+) create mode 100644 drivers/misc/fastrpc.c -- 2.20.1 diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig index f417b06e11c5..7e0726253755 100644 --- a/drivers/misc/Kconfig +++ b/drivers/misc/Kconfig @@ -295,6 +295,16 @@ config QCOM_COINCELL to maintain PMIC register and RTC state in the absence of external power. +config QCOM_FASTRPC + tristate "Qualcomm FastRPC" + depends on ARCH_QCOM || COMPILE_TEST + depends on RPMSG + help + Provides a communication mechanism that allows for clients to + make remote method invocations across processor boundary to + applications DSP processor. Say M if you want to enable this + module. + config SGI_GRU tristate "SGI GRU driver" depends on X86_UV && SMP diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile index e39ccbbc1b3a..623d002c59ce 100644 --- a/drivers/misc/Makefile +++ b/drivers/misc/Makefile @@ -18,6 +18,7 @@ obj-$(CONFIG_TIFM_CORE) += tifm_core.o obj-$(CONFIG_TIFM_7XX1) += tifm_7xx1.o obj-$(CONFIG_PHANTOM) += phantom.o obj-$(CONFIG_QCOM_COINCELL) += qcom-coincell.o +obj-$(CONFIG_QCOM_FASTRPC) += fastrpc.o obj-$(CONFIG_SENSORS_BH1770) += bh1770glc.o obj-$(CONFIG_SENSORS_APDS990X) += apds990x.o obj-$(CONFIG_SGI_IOC4) += ioc4.o diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c new file mode 100644 index 000000000000..c86c7babf403 --- /dev/null +++ b/drivers/misc/fastrpc.c @@ -0,0 +1,322 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (c) 2011-2018, The Linux Foundation. All rights reserved. +// Copyright (c) 2018, Linaro Limited + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define ADSP_DOMAIN_ID (0) +#define MDSP_DOMAIN_ID (1) +#define SDSP_DOMAIN_ID (2) +#define CDSP_DOMAIN_ID (3) +#define FASTRPC_DEV_MAX 4 /* adsp, mdsp, slpi, cdsp*/ +#define FASTRPC_MAX_SESSIONS 9 /*8 compute, 1 cpz*/ +#define FASTRPC_CTX_MAX (256) +#define FASTRPC_CTXID_MASK (0xFF0) +#define FASTRPC_DEVICE_NAME "fastrpc" + +#define miscdev_to_cctx(d) container_of(d, struct fastrpc_channel_ctx, miscdev) + +static const char *domains[FASTRPC_DEV_MAX] = { "adsp", "mdsp", + "sdsp", "cdsp"}; + +struct fastrpc_session_ctx { + struct device *dev; + int sid; + bool used; + bool valid; +}; + +struct fastrpc_channel_ctx { + int domain_id; + int sesscount; + struct rpmsg_device *rpdev; + struct fastrpc_session_ctx session[FASTRPC_MAX_SESSIONS]; + spinlock_t lock; + struct idr ctx_idr; + struct list_head users; + struct miscdevice miscdev; +}; + +struct fastrpc_user { + struct list_head user; + struct list_head maps; + struct list_head pending; + + struct fastrpc_channel_ctx *cctx; + struct fastrpc_session_ctx *sctx; + + int tgid; + int pd; + /* Lock for lists */ + spinlock_t lock; + /* lock for allocations */ + struct mutex mutex; +}; + +static struct fastrpc_session_ctx *fastrpc_session_alloc( + struct fastrpc_channel_ctx *cctx) +{ + struct fastrpc_session_ctx *session = NULL; + int i; + + spin_lock(&cctx->lock); + for (i = 0; i < cctx->sesscount; i++) { + if (!cctx->session[i].used && cctx->session[i].valid) { + cctx->session[i].used = true; + session = &cctx->session[i]; + break; + } + } + spin_unlock(&cctx->lock); + + return session; +} + +static void fastrpc_session_free(struct fastrpc_channel_ctx *cctx, + struct fastrpc_session_ctx *session) +{ + spin_lock(&cctx->lock); + session->used = false; + spin_unlock(&cctx->lock); +} + +static int fastrpc_device_release(struct inode *inode, struct file *file) +{ + struct fastrpc_user *fl = (struct fastrpc_user *)file->private_data; + struct fastrpc_channel_ctx *cctx = fl->cctx; + + spin_lock(&cctx->lock); + list_del(&fl->user); + spin_unlock(&cctx->lock); + + fastrpc_session_free(fl->cctx, fl->sctx); + + mutex_destroy(&fl->mutex); + kfree(fl); + file->private_data = NULL; + + return 0; +} + +static int fastrpc_device_open(struct inode *inode, struct file *filp) +{ + struct fastrpc_channel_ctx *cctx = miscdev_to_cctx(filp->private_data); + struct fastrpc_user *fl = NULL; + + fl = kzalloc(sizeof(*fl), GFP_KERNEL); + if (!fl) + return -ENOMEM; + + filp->private_data = fl; + spin_lock_init(&fl->lock); + mutex_init(&fl->mutex); + INIT_LIST_HEAD(&fl->pending); + INIT_LIST_HEAD(&fl->maps); + INIT_LIST_HEAD(&fl->user); + fl->tgid = current->tgid; + fl->cctx = cctx; + spin_lock(&cctx->lock); + list_add_tail(&fl->user, &cctx->users); + spin_unlock(&cctx->lock); + fl->sctx = fastrpc_session_alloc(cctx); + + return 0; +} + +static const struct file_operations fastrpc_fops = { + .open = fastrpc_device_open, + .release = fastrpc_device_release, +}; + +static int fastrpc_cb_probe(struct platform_device *pdev) +{ + struct fastrpc_channel_ctx *cctx; + struct fastrpc_session_ctx *sess; + struct device *dev = &pdev->dev; + int i, sessions = 0; + + cctx = dev_get_drvdata(dev->parent); + if (!cctx) + return -EINVAL; + + of_property_read_u32(dev->of_node, "qcom,nsessions", &sessions); + + spin_lock(&cctx->lock); + sess = &cctx->session[cctx->sesscount]; + sess->used = false; + sess->valid = true; + sess->dev = dev; + dev_set_drvdata(dev, sess); + + if (of_property_read_u32(dev->of_node, "reg", &sess->sid)) + dev_info(dev, "FastRPC Session ID not specified in DT\n"); + + if (sessions > 0) { + struct fastrpc_session_ctx *dup_sess; + + for (i = 1; i < sessions; i++) { + if (cctx->sesscount++ >= FASTRPC_MAX_SESSIONS) + break; + dup_sess = &cctx->session[cctx->sesscount]; + memcpy(dup_sess, sess, sizeof(*dup_sess)); + } + } + cctx->sesscount++; + spin_unlock(&cctx->lock); + dma_set_mask(dev, DMA_BIT_MASK(32)); + + return 0; +} + +static int fastrpc_cb_remove(struct platform_device *pdev) +{ + struct fastrpc_channel_ctx *cctx = dev_get_drvdata(pdev->dev.parent); + struct fastrpc_session_ctx *sess = dev_get_drvdata(&pdev->dev); + int i; + + spin_lock(&cctx->lock); + for (i = 1; i < FASTRPC_MAX_SESSIONS; i++) { + if (cctx->session[i].sid == sess->sid) { + cctx->session[i].valid = false; + cctx->sesscount--; + } + } + spin_unlock(&cctx->lock); + + return 0; +} + +static const struct of_device_id fastrpc_match_table[] = { + { .compatible = "qcom,fastrpc-compute-cb", }, + {} +}; + +static struct platform_driver fastrpc_cb_driver = { + .probe = fastrpc_cb_probe, + .remove = fastrpc_cb_remove, + .driver = { + .name = "qcom,fastrpc-cb", + .of_match_table = fastrpc_match_table, + .suppress_bind_attrs = true, + }, +}; + +static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev) +{ + struct device *rdev = &rpdev->dev; + struct fastrpc_channel_ctx *data; + int i, err, domain_id = 0; + const char *domain; + + data = devm_kzalloc(rdev, sizeof(*data), GFP_KERNEL); + if (!data) + return -ENOMEM; + + err = of_property_read_string(rdev->of_node, "label", &domain); + if (err) { + dev_info(rdev, "FastRPC Domain not specified in DT\n"); + return err; + } + + for (i = 0; i < CDSP_DOMAIN_ID; i++) { + if (!strcmp(domains[i], domain)) { + domain_id = i; + break; + } + } + + if (domain_id > CDSP_DOMAIN_ID) { + dev_info(rdev, "FastRPC Invalid Domain ID %d\n", domain_id); + return -EINVAL; + } + + data->miscdev.minor = MISC_DYNAMIC_MINOR; + data->miscdev.name = kasprintf(GFP_KERNEL, "fastrpc-%s", + domains[domain_id]); + data->miscdev.fops = &fastrpc_fops; + err = misc_register(&data->miscdev); + if (err) + return err; + + dev_set_drvdata(&rpdev->dev, data); + dma_set_mask_and_coherent(rdev, DMA_BIT_MASK(32)); + INIT_LIST_HEAD(&data->users); + spin_lock_init(&data->lock); + idr_init(&data->ctx_idr); + data->domain_id = domain_id; + data->rpdev = rpdev; + + return of_platform_populate(rdev->of_node, NULL, NULL, rdev); +} + +static void fastrpc_rpmsg_remove(struct rpmsg_device *rpdev) +{ + struct fastrpc_channel_ctx *cctx = dev_get_drvdata(&rpdev->dev); + + misc_deregister(&cctx->miscdev); + of_platform_depopulate(&rpdev->dev); + kfree(cctx); +} + +static int fastrpc_rpmsg_callback(struct rpmsg_device *rpdev, void *data, + int len, void *priv, u32 addr) +{ + return 0; +} + +static const struct of_device_id fastrpc_rpmsg_of_match[] = { + { .compatible = "qcom,fastrpc" }, + { }, +}; +MODULE_DEVICE_TABLE(of, fastrpc_rpmsg_of_match); + +static struct rpmsg_driver fastrpc_driver = { + .probe = fastrpc_rpmsg_probe, + .remove = fastrpc_rpmsg_remove, + .callback = fastrpc_rpmsg_callback, + .drv = { + .name = "qcom,fastrpc", + .of_match_table = fastrpc_rpmsg_of_match, + }, +}; + +static int fastrpc_init(void) +{ + int ret; + + ret = platform_driver_register(&fastrpc_cb_driver); + if (ret < 0) { + pr_err("fastrpc: failed to register cb driver\n"); + return ret; + } + + ret = register_rpmsg_driver(&fastrpc_driver); + if (ret < 0) { + pr_err("fastrpc: failed to register rpmsg driver\n"); + platform_driver_unregister(&fastrpc_cb_driver); + return ret; + } + + return 0; +} +module_init(fastrpc_init); + +static void fastrpc_exit(void) +{ + platform_driver_unregister(&fastrpc_cb_driver); + unregister_rpmsg_driver(&fastrpc_driver); +} +module_exit(fastrpc_exit); + +MODULE_LICENSE("GPL v2");