From patchwork Mon Jan 14 19:41:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 155578 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp4040481jaa; Mon, 14 Jan 2019 11:42:21 -0800 (PST) X-Google-Smtp-Source: ALg8bN4oqqt8pYw6/6y4q0eCpa6BGKCPXIwOzKEpTMbG0we85nF/EO7UgDMV9Ju5tbbmlj/MNhxx X-Received: by 2002:a62:c711:: with SMTP id w17mr139169pfg.50.1547494941363; Mon, 14 Jan 2019 11:42:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547494941; cv=none; d=google.com; s=arc-20160816; b=Vi6ya4G37psSYkaEPfe0KttocRj5KOPgQsank4Wk3kvq0HLwIRunIfjxJKw1Lzt7a3 aBVgA7Iq9/TZ0PCo13vibmdFJOwv85FU5jsot08FuHEVCRjiVWvMOv6MHIp4iEyVzSq3 nRASI5sRQqCyxQYRCIG3cC0QGST4QCuQimBwmG86WQsRIybuXqUlm546rrld1dS+Qd75 6pjtjZylGGHufkX8QbC1dq3g7lNbswQ7y7xFWmstlXs4FzFP0oLTWDI1SBKXl67Ryf9J r0B8zXvh1X2J7OTHsv/fapWFQKfoZDVf4ViMPn+teUyamrkIzQ/WRTBo02HlP0I+EfBR NdjA== 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=SMVWf8S5qQu4nvxHW3aF7B34QEW9X1fPwQ6VU5Gu+DY=; b=PbXbJlHdLRedR+QqyEiw54R3/m5HYoWW0nojRNrKf/nlegoDFn5TGc/nRLDTz9uYfL 2gf5hgh7ucMj6JUyBxGRjXI6CknB6wnCSm1g4Cr8RU374sFaPELwA+mGwvlpdKs2ZuDY 0R3RdHc3OLapzXT/fbzaqGFDpUe+u+Z9qL7l/DiTDMCMN4w8vBPWjds/maU19Yoi7Lh5 r6akVS0+GF9XxkW4joG2PmeYSvfcY3dBvM9ZPeI6gYMFMYaFMastwOk9n6KY1XbviyVO 98yEeoQyiqnMQWYQ8MtmKjAhOEs5bwIvMXJTqn/tPi+wd+PVCaGQwGIt4WOzL5t+58Sf 8QDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=k0x3W17S; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-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 101si1185877pld.22.2019.01.14.11.42.20; Mon, 14 Jan 2019 11:42:21 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-arm-msm-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=k0x3W17S; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-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 S1726863AbfANTmT (ORCPT + 15 others); Mon, 14 Jan 2019 14:42:19 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:41060 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726833AbfANTmQ (ORCPT ); Mon, 14 Jan 2019 14:42:16 -0500 Received: by mail-wr1-f68.google.com with SMTP id x10so240771wrs.8 for ; Mon, 14 Jan 2019 11:42:15 -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=SMVWf8S5qQu4nvxHW3aF7B34QEW9X1fPwQ6VU5Gu+DY=; b=k0x3W17SuiYSteG11Gc0m9OKo1MyAuFmDtUW5axGlr2XXH19XnSz+MHtLGApPmof7p ckHUuBtJMBSZr16+qUqJMmW2eLDob84ttVM1MvdqkKJ9A+TcLWtv+lRf6kgyV4fPgl0r tI/QMFEfZPi+AcrI13Ugfo8IfTFtIgg/fAPY4= 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=SMVWf8S5qQu4nvxHW3aF7B34QEW9X1fPwQ6VU5Gu+DY=; b=kHq/mZON8EE2zUpZtx8sZI0nwuh/v/xLAdJH+h8xJ4k4UIscQlXhN751QbIK//LstT GO6mCh7pQxng0NpMr52Sgrn3u6oiJwFMUp+MN8JHSXU+j7WgxXe3OoYUNBP30W6nBkCx c5uA+I2bpkk6XJzrgIQ+UXbfysZz8bxtvhjiRYsGdZ24GKT+AFBPbAiOD9fyedoA4Ee0 Y8UhYLXdGCf2nXIYJotJAXKC5BNf8mJM5hwX4oHybuTrk1sPWA7C+4a+z1npZAhQVQt9 43dlUGqpNjAh8NqZgHdKmDvD+WUYum+DMtKjL8Z6ze2u0pPTjHzOv1x+3efZ+dCjsYB3 AskA== X-Gm-Message-State: AJcUukdGatTuSZgkwgYOm+QXG6OMXVs8IxoMMKuCeQZmKd8XK3H+DUz/ aH6fCagewi7n6H3Mo+9Gc3q6Zg== X-Received: by 2002:adf:d112:: with SMTP id a18mr66534wri.17.1547494933858; Mon, 14 Jan 2019 11:42:13 -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 b7sm66779996wrs.47.2019.01.14.11.42.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 14 Jan 2019 11:42:13 -0800 (PST) From: Srinivas Kandagatla To: robh+dt@kernel.org, gregkh@linuxfoundation.org, arnd@arndb.de Cc: mark.rutland@arm.com, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, bjorn.andersson@linaro.org, bkumar@qti.qualcomm.com, linux-arm-msm@vger.kernel.org, thierry.escande@linaro.org, Srinivas Kandagatla Subject: [PATCH v3 1/5] misc: dt-bindings: Add Qualcomm Fastrpc bindings Date: Mon, 14 Jan 2019 19:41:08 +0000 Message-Id: <20190114194112.32567-2-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190114194112.32567-1-srinivas.kandagatla@linaro.org> References: <20190114194112.32567-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@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 --- .../devicetree/bindings/misc/qcom,fastrpc.txt | 84 +++++++++++++++++++ 1 file changed, 84 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..004e636b4133 --- /dev/null +++ b/Documentation/devicetree/bindings/misc/qcom,fastrpc.txt @@ -0,0 +1,84 @@ +Qualcomm Technologies, Inc. FastRPC Driver + +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. + +- 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 node represents compute context banks available +on the dsp. The name of the nodes are not important. The properties of these +nodes are defined by the individual bindings for the specific service +- All Compute context banks MUST contain the following property: + +- compatible: + Usage: required + Value type: + Definition: must be "qcom,fastrpc-compute-cb" + +- reg + Usage: required + Value type: + Definition: Context Bank ID. + +- secured: + Usage: Optional + Value type: + Defination: Indicating context bank is secured + +- 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"; + lable = "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 Mon Jan 14 19:41:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 155581 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp4040850jaa; Mon, 14 Jan 2019 11:42:43 -0800 (PST) X-Google-Smtp-Source: ALg8bN6/+sY0ZriPr29nVP91MVKttYjrx0lV8ekVDnLKcZYf6Z6mQetLzONOLO+5gELnrGGGbbVQ X-Received: by 2002:a62:5884:: with SMTP id m126mr74430pfb.177.1547494963479; Mon, 14 Jan 2019 11:42:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547494963; cv=none; d=google.com; s=arc-20160816; b=WKmgbplwQkI+bFEN3pI0MZEj/4buP7N8Gq8OErrvfJKKl17r+b0jCYzZeuMfcWph8g zJG7eZoz1mwlSwEnyrxEMSs1Q98UHUoNsGL37nUZA0Ugv5RevACukPrI2w2XY6ukDUR1 /YwVdAy6cf77VN4VPf7Fo6n48YoBEWsvq2469iQgaChZ6gCi2HEqDtG7Qc5gXcnSvy8F +sVczq1Y6IcQ+ULENbfdKe/R1n7PFrDonJiaxMXPAshtOHxch/xFQhnSTCFiWOjLeN5M 7TGoOhcXEgOvsw5TNWkoIWsV7bPo2w9Jcc3kZbA14fyenLMLLCQia4LG6qzvldLIkM5w KPlg== 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=TGWMRgUa84leIvqNdPnLVf/SH/izWExH3OfySwLQBtc=; b=J1VJ+eYUn9ormV8vNDkX35oFbKt/K3CGPtUF7m3VcqxC10nV6hXdhRwurkNWwRxlmW lO+svMfSBkK86b1L7tluN8k2uWnR6Boh7I72C5CaLXeOhv/lPaT2TwNwDvEc13SRePHh +iUMAuE2UNastVc4duRJbgg/s7P10NhOfkYmYi8Jln6We4lwP6qRwBXG8B26s3xYAYYf r7NoQlSm73nQODRnezamisxe8+f6nMB4OUiUwoHOYkpA4XZ9jhD7ij56xCOpCyexlgMT SLqIvKW9qMKu0ncZwC4w4z5YU//oiEZyQqE0Mgqix6CGcU/oX32op6qXvI4381kIaxYE byiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=br3FnU4G; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-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 y73si1017425pgd.478.2019.01.14.11.42.43; Mon, 14 Jan 2019 11:42:43 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-arm-msm-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=br3FnU4G; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-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 S1726943AbfANTmW (ORCPT + 15 others); Mon, 14 Jan 2019 14:42:22 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:39271 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726910AbfANTmW (ORCPT ); Mon, 14 Jan 2019 14:42:22 -0500 Received: by mail-wm1-f67.google.com with SMTP id y8so827080wmi.4 for ; Mon, 14 Jan 2019 11:42:20 -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=TGWMRgUa84leIvqNdPnLVf/SH/izWExH3OfySwLQBtc=; b=br3FnU4Gy9vKFnmadRUEn+ySuQhx1TLmNcHsX9lSmXToW/fCrcIrVDXVFEAYbDhyc2 onw56Vm7miEoRIvEOQeNDetPuihdNj+CgULgPGEGBbu2rrbjTOa0XsCiXtM/nHkOLSoc WpaKqOYufCBH6wC578d9ZADwvKK30aNXFbfOM= 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=TGWMRgUa84leIvqNdPnLVf/SH/izWExH3OfySwLQBtc=; b=mByP2bYUWwIKe8e4ka0+TuDNZ4LgsMtbE+Wdl0v5cNqZ9n5IWkj7yW626Gxdab2Q5o EFCBLu3UY/YS3XNfUel0zpTsu2Qn6s4L6pfWptqJfgHKkFnIoMo7SGZ1AAxjr+pXivDk pqzYgLGIGgjiv+RZJVV2ziO8ehEVOne6zIDe9KxbmpICWRprYrJKBAt1EW15a7pcnpMD JCQCzLn28wbFx7e6T3ASzqyi8g1VWajIGIQq21MjUWDojHs8hDfhd5G2s9GzNEbQlYL4 mOnVej8jDsUjncsndhOr6pJHrfAfp2HebvlESqo/ufd7uzZdfiIvDvalAk09+1Y+aq52 b9Kw== X-Gm-Message-State: AJcUukeoRy4txRptCB/UPz5/vJUc0IIim41T0OlMe4qtSkH6giudBs3t MRivOuZjfKsnnZrqkGni4eH+CA== X-Received: by 2002:a1c:2902:: with SMTP id p2mr529173wmp.19.1547494939238; Mon, 14 Jan 2019 11:42:19 -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 b7sm66779996wrs.47.2019.01.14.11.42.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 14 Jan 2019 11:42:18 -0800 (PST) From: Srinivas Kandagatla To: robh+dt@kernel.org, gregkh@linuxfoundation.org, arnd@arndb.de Cc: mark.rutland@arm.com, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, bjorn.andersson@linaro.org, bkumar@qti.qualcomm.com, linux-arm-msm@vger.kernel.org, thierry.escande@linaro.org, Srinivas Kandagatla Subject: [PATCH v3 4/5] misc: fastrpc: Add support for create remote init process Date: Mon, 14 Jan 2019 19:41:11 +0000 Message-Id: <20190114194112.32567-5-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190114194112.32567-1-srinivas.kandagatla@linaro.org> References: <20190114194112.32567-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org This patch adds support to create or attach remote shell process. The shell process called fastrpc_shell_0 is usually loaded on the DSP when a user process is spawned. Most of the work is derived from various downstream Qualcomm kernels. Credits to various Qualcomm authors who have contributed to this code. Specially Tharun Kumar Merugu Co-developed-by: Thierry Escande Signed-off-by: Thierry Escande Signed-off-by: Srinivas Kandagatla --- drivers/misc/fastrpc.c | 141 +++++++++++++++++++++++++++++++++++- include/uapi/misc/fastrpc.h | 10 +++ 2 files changed, 150 insertions(+), 1 deletion(-) -- 2.20.1 diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index 6745e164ef12..c93960b5f3a5 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -29,7 +29,10 @@ #define FASTRPC_MAX_CRCLIST 64 #define FASTRPC_PHYS(p) ((p) & 0xffffffff) #define FASTRPC_CTX_MAX (256) +#define FASTRPC_INIT_HANDLE 1 #define FASTRPC_CTXID_MASK (0xFF0) +#define INIT_FILELEN_MAX (2 * 1024 * 1024) +#define INIT_MEMLEN_MAX (8 * 1024 * 1024) #define FASTRPC_DEVICE_NAME "fastrpc" /* Retrives number of input buffers from the scalars parameter */ @@ -60,6 +63,13 @@ #define FASTRPC_SCALARS(method, in, out) \ FASTRPC_BUILD_SCALARS(0, method, in, out, 0, 0) +/* Remote Method id table */ +#define FASTRPC_RMID_INIT_ATTACH 0 +#define FASTRPC_RMID_INIT_RELEASE 1 +#define FASTRPC_RMID_INIT_CREATE 6 +#define FASTRPC_RMID_INIT_CREATE_ATTR 7 +#define FASTRPC_RMID_INIT_CREATE_STATIC 8 + #define miscdev_to_cctx(d) container_of(d, struct fastrpc_channel_ctx, miscdev) static const char *domains[FASTRPC_DEV_MAX] = { "adsp", "mdsp", @@ -667,7 +677,96 @@ static int fastrpc_internal_invoke(struct fastrpc_user *fl, u32 kernel, fastrpc_context_free(ctx); if (err) - dev_err(fl->sctx->dev, "Error: Invoke Failed %d\n", err); + dev_dbg(fl->sctx->dev, "Error: Invoke Failed %d\n", err); + + return err; +} + +static int fastrpc_init_create_process(struct fastrpc_user *fl, + char __user *argp) +{ + struct fastrpc_init_create init; + struct fastrpc_invoke_args args[6]; + struct fastrpc_phy_page pages[1]; + struct fastrpc_map *map = NULL; + struct fastrpc_buf *imem = NULL; + int memlen; + int err; + struct { + int pgid; + u32 namelen; + u32 filelen; + u32 pageslen; + u32 attrs; + u32 siglen; + } inbuf; + u32 sc; + + if (copy_from_user(&init, argp, sizeof(init))) + return -EFAULT; + + if (init.filelen > INIT_FILELEN_MAX) + return -EINVAL; + + inbuf.pgid = fl->tgid; + inbuf.namelen = strlen(current->comm) + 1; + inbuf.filelen = init.filelen; + inbuf.pageslen = 1; + inbuf.attrs = init.attrs; + inbuf.siglen = init.siglen; + fl->pd = 1; + + if (init.filelen && init.filefd) { + err = fastrpc_map_create(fl, init.filefd, init.filelen, &map); + if (err) + goto bail; + } + + memlen = ALIGN(max(INIT_FILELEN_MAX, (int)init.filelen * 4), + 1024 * 1024); + err = fastrpc_buf_alloc(fl, fl->sctx->dev, memlen, + &imem); + if (err) + goto bail; + + fl->init_mem = imem; + args[0].ptr = (u64)(uintptr_t)&inbuf; + args[0].length = sizeof(inbuf); + args[0].fd = -1; + + args[1].ptr = (u64)(uintptr_t)current->comm; + args[1].length = inbuf.namelen; + args[1].fd = -1; + + args[2].ptr = (u64) init.file; + args[2].length = inbuf.filelen; + args[2].fd = init.filefd; + + pages[0].addr = imem->phys; + pages[0].size = imem->size; + + args[3].ptr = (u64)(uintptr_t) pages; + args[3].length = 1 * sizeof(*pages); + args[3].fd = -1; + + args[4].ptr = (u64)(uintptr_t)&inbuf.attrs; + args[4].length = sizeof(inbuf.attrs); + args[4].fd = -1; + + args[5].ptr = (u64)(uintptr_t) &inbuf.siglen; + args[5].length = sizeof(inbuf.siglen); + args[5].fd = -1; + + sc = FASTRPC_SCALARS(FASTRPC_RMID_INIT_CREATE, 4, 0); + if (init.attrs) + sc = FASTRPC_SCALARS(FASTRPC_RMID_INIT_CREATE_ATTR, 6, 0); + + err = fastrpc_internal_invoke(fl, true, FASTRPC_INIT_HANDLE, + sc, &args[0]); + +bail: + if (map) + fastrpc_map_put(map); return err; } @@ -701,6 +800,22 @@ static void fastrpc_session_free(struct fastrpc_channel_ctx *cctx, spin_unlock(&cctx->lock); } +static int fastrpc_release_current_dsp_process(struct fastrpc_user *fl) +{ + struct fastrpc_invoke_args args[1]; + int tgid = 0; + u32 sc; + + tgid = fl->tgid; + args[0].ptr = (u64)(uintptr_t) &tgid; + args[0].length = sizeof(tgid); + args[0].fd = -1; + sc = FASTRPC_SCALARS(FASTRPC_RMID_INIT_RELEASE, 1, 0); + + return fastrpc_internal_invoke(fl, true, FASTRPC_INIT_HANDLE, + sc, &args[0]); +} + static int fastrpc_device_release(struct inode *inode, struct file *file) { struct fastrpc_user *fl = (struct fastrpc_user *)file->private_data; @@ -708,6 +823,8 @@ static int fastrpc_device_release(struct inode *inode, struct file *file) struct fastrpc_invoke_ctx *ctx, *n; struct fastrpc_map *map, *m; + fastrpc_release_current_dsp_process(fl); + spin_lock(&cctx->lock); list_del(&fl->user); spin_unlock(&cctx->lock); @@ -755,6 +872,22 @@ static int fastrpc_device_open(struct inode *inode, struct file *filp) return 0; } +static int fastrpc_init_attach(struct fastrpc_user *fl) +{ + struct fastrpc_invoke_args args[1]; + int tgid = fl->tgid; + u32 sc; + + args[0].ptr = (u64)(uintptr_t) &tgid; + args[0].length = sizeof(tgid); + args[0].fd = -1; + sc = FASTRPC_SCALARS(FASTRPC_RMID_INIT_ATTACH, 1, 0); + fl->pd = 0; + + return fastrpc_internal_invoke(fl, true, FASTRPC_INIT_HANDLE, + sc, &args[0]); +} + static int fastrpc_invoke(struct fastrpc_user *fl, char __user *argp) { struct fastrpc_invoke_args *args = NULL; @@ -795,6 +928,12 @@ static long fastrpc_device_ioctl(struct file *file, unsigned int cmd, case FASTRPC_IOCTL_INVOKE: err = fastrpc_invoke(fl, argp); break; + case FASTRPC_IOCTL_INIT_ATTACH: + err = fastrpc_init_attach(fl); + break; + case FASTRPC_IOCTL_INIT_CREATE: + err = fastrpc_init_create_process(fl, argp); + break; default: err = -ENOTTY; dev_err(fl->sctx->dev, "bad ioctl: %d\n", cmd); diff --git a/include/uapi/misc/fastrpc.h b/include/uapi/misc/fastrpc.h index a69ef33dc37e..32d191c3b7bc 100644 --- a/include/uapi/misc/fastrpc.h +++ b/include/uapi/misc/fastrpc.h @@ -6,6 +6,8 @@ #include #define FASTRPC_IOCTL_INVOKE _IOWR('R', 3, struct fastrpc_invoke) +#define FASTRPC_IOCTL_INIT_ATTACH _IO('R', 4) +#define FASTRPC_IOCTL_INIT_CREATE _IOWR('R', 5, struct fastrpc_init_create) struct fastrpc_invoke_args { __u64 ptr; @@ -20,4 +22,12 @@ struct fastrpc_invoke { __u64 args; }; +struct fastrpc_init_create { + __u32 filelen; /* elf file length */ + __s32 filefd; /* fd for the file */ + __u32 attrs; + __u32 siglen; + __u64 file; /* pointer to elf file */ +}; + #endif /* __QCOM_FASTRPC_H__ */ From patchwork Mon Jan 14 19:41:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 155580 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp4040584jaa; Mon, 14 Jan 2019 11:42:27 -0800 (PST) X-Google-Smtp-Source: ALg8bN7BdIAw3KfatUn+hipFSX7r4fEdUU6KvjDK023YoI1civjREWY9DpeTxtLfQjCDl0oNVhCd X-Received: by 2002:a63:5d20:: with SMTP id r32mr70265pgb.329.1547494947590; Mon, 14 Jan 2019 11:42:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547494947; cv=none; d=google.com; s=arc-20160816; b=us2AMZ/XEeTGuvdoiErgb3+o5tCxHQa6PmYLvKIPjJRulPITN+CKU61Kq23gXAzv8c OCUosAzV5f9twTYcjTeXaNOzVXgDaCNwryd7B7GLPGFhzkHNjCAI9juF5QAKJvZBlsZU 6Vhpksb6qz+QfB3Me4VU+NkH9m92Ly4tOXbkwISe3Rbtz/Y2nRxdfFFJsSwayKURsFrO jnQcFtrjgJTjv+lKgiZohqYF8miLyqY95R7YQegckUC6Oml+07Gr5YWBMbmahpP4TPr4 G06K4BOUeilmbcqsmHV0yUpP+jRnsFphdj+QayvIWWRsnZq7T7iP9+iF+e1vZ8CuscNf Luxg== 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=jQ/JjeqoO/OkxqwgfmH36Hjr75RKiV9StGlibJEnNG0=; b=M6GzgOpYh7u9C0+L0WjJBOpnfbCq1kD5ciR5wHWThBNaPcNs++LO3TRoGLx3E52VJm QhR+0ts5j95axqUPZbc7z+eC3DeWTIo57UYH5TGOIp/J52hRhBDSGTAYKnXYAg8wnUdH ThDWs1W6l/1RA7v0EkxTkQMWBaysw4mwdtFnMSyeowmSg06B7APdhM1lrvDlErKZyHlF fxcxw4c7DfNi4kelwqQd2Ckjqzmj1MOUPHKdnIcmmUoJ2G1u4dcgQFCctGuPOBgTRHwb 6uibYtp4RvTBN1IoXQROIzvX+29deFVZCRoDmEQVwO++IZjIL3KW2c2NeqCwElqt6K0e ZNnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Vd4orD9k; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-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 o5si1152352pgs.497.2019.01.14.11.42.27; Mon, 14 Jan 2019 11:42:27 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-arm-msm-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=Vd4orD9k; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-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 S1726969AbfANTm0 (ORCPT + 15 others); Mon, 14 Jan 2019 14:42:26 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:54685 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726928AbfANTmX (ORCPT ); Mon, 14 Jan 2019 14:42:23 -0500 Received: by mail-wm1-f67.google.com with SMTP id a62so863353wmh.4 for ; Mon, 14 Jan 2019 11:42:21 -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=jQ/JjeqoO/OkxqwgfmH36Hjr75RKiV9StGlibJEnNG0=; b=Vd4orD9kBqAK0/2iGgagJOAOpwPaJFnXdCFT44RgqERGwQ9ZMViqNfhvomDRiCwPFR Gxw3EeZHMgl3nJmIqt/UO7MgDG9ytKzggxkcMwxunXNFXhVXJLHBHlQDJ8jGO3I+ox8z 91n5/9dSU6p4CI+ElkOKkMADdeoE17q5ZXJkQ= 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=jQ/JjeqoO/OkxqwgfmH36Hjr75RKiV9StGlibJEnNG0=; b=rNY6/7Vd8pU/d7RiAxT9PQP3AWCgOikiJSuF/M3n58DQDEJzI5gskW1KEjmauneBJT PSoao4D21AywACMzfy3puJerJ1DmQ0YV3ZOVAkEY0irNoGraYVjGweIkRg1EpqkUrN8W l+PI65jDP1sLZFZsuJYqcrNnuaNMGKTfJoDx4qHtFYxvYi713O/6lrBCdd3QkKH+Upku xzlsywSJMUl8USr3CX6ZXG14XZaYTbt90frOYEWU+doJwnlfkBLhEp3PrfHyqxWJIxO7 M4tKB1KGJZzd5GEK6sIg/hG1CeUJfNnNuq9Xb7evEvFO0Dihxv9hijzbPhqReLkAnASG 0m1Q== X-Gm-Message-State: AJcUukfKYB9IJInT+i9k07+Wb/mpRj8p4shr/16Oean2bDmgqCpcpwAi iUaXt3OC2Fh07piVrWev0n8zIA== X-Received: by 2002:a1c:f71a:: with SMTP id v26mr478645wmh.131.1547494940605; Mon, 14 Jan 2019 11:42:20 -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 b7sm66779996wrs.47.2019.01.14.11.42.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 14 Jan 2019 11:42:19 -0800 (PST) From: Srinivas Kandagatla To: robh+dt@kernel.org, gregkh@linuxfoundation.org, arnd@arndb.de Cc: mark.rutland@arm.com, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, bjorn.andersson@linaro.org, bkumar@qti.qualcomm.com, linux-arm-msm@vger.kernel.org, thierry.escande@linaro.org, Srinivas Kandagatla Subject: [PATCH v3 5/5] misc: fastrpc: Add support for dmabuf exporter Date: Mon, 14 Jan 2019 19:41:12 +0000 Message-Id: <20190114194112.32567-6-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190114194112.32567-1-srinivas.kandagatla@linaro.org> References: <20190114194112.32567-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org User process can involve dealing with big buffer sizes, and also passing buffers from one compute context bank to other compute context bank for complex dsp algorithms. This patch adds support to fastrpc to make it a proper dmabuf exporter to avoid making copies of buffers. Co-developed-by: Thierry Escande Signed-off-by: Thierry Escande Signed-off-by: Srinivas Kandagatla --- drivers/misc/fastrpc.c | 177 ++++++++++++++++++++++++++++++++++++ include/uapi/misc/fastrpc.h | 8 ++ 2 files changed, 185 insertions(+) -- 2.20.1 diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index c93960b5f3a5..0483e09f21b3 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -106,10 +106,20 @@ struct fastrpc_invoke_rsp { struct fastrpc_buf { struct fastrpc_user *fl; + struct dma_buf *dmabuf; struct device *dev; void *virt; u64 phys; u64 size; + /* Lock for dma buf attachments */ + struct mutex lock; + struct list_head attachments; +}; + +struct fastrpc_dma_buf_attachment { + struct device *dev; + struct sg_table sgt; + struct list_head node; }; struct fastrpc_map { @@ -247,6 +257,9 @@ static int fastrpc_buf_alloc(struct fastrpc_user *fl, struct device *dev, if (!buf) return -ENOMEM; + INIT_LIST_HEAD(&buf->attachments); + mutex_init(&buf->lock); + buf->fl = fl; buf->virt = NULL; buf->phys = 0; @@ -352,6 +365,110 @@ fastrpc_context_alloc(struct fastrpc_user *user, u32 kernel, u32 sc, return ERR_PTR(ret); } +static struct sg_table * +fastrpc_map_dma_buf(struct dma_buf_attachment *attachment, + enum dma_data_direction dir) +{ + struct fastrpc_dma_buf_attachment *a = attachment->priv; + struct sg_table *table; + + table = &a->sgt; + + if (!dma_map_sg(attachment->dev, table->sgl, table->nents, dir)) + return ERR_PTR(-ENOMEM); + + return table; +} + +static void fastrpc_unmap_dma_buf(struct dma_buf_attachment *attach, + struct sg_table *table, + enum dma_data_direction dir) +{ +} + +static void fastrpc_release(struct dma_buf *dmabuf) +{ + struct fastrpc_buf *buffer = dmabuf->priv; + + fastrpc_buf_free(buffer); +} + +static int fastrpc_dma_buf_attach(struct dma_buf *dmabuf, + struct dma_buf_attachment *attachment) +{ + struct fastrpc_dma_buf_attachment *a; + struct fastrpc_buf *buffer = dmabuf->priv; + int ret; + + a = kzalloc(sizeof(*a), GFP_KERNEL); + if (!a) + return -ENOMEM; + + ret = dma_get_sgtable(buffer->dev, &a->sgt, buffer->virt, + FASTRPC_PHYS(buffer->phys), buffer->size); + if (ret < 0) { + dev_err(buffer->dev, "failed to get scatterlist from DMA API\n"); + return -EINVAL; + } + + a->dev = attachment->dev; + INIT_LIST_HEAD(&a->node); + attachment->priv = a; + + mutex_lock(&buffer->lock); + list_add(&a->node, &buffer->attachments); + mutex_unlock(&buffer->lock); + + return 0; +} + +static void fastrpc_dma_buf_detatch(struct dma_buf *dmabuf, + struct dma_buf_attachment *attachment) +{ + struct fastrpc_dma_buf_attachment *a = attachment->priv; + struct fastrpc_buf *buffer = dmabuf->priv; + + mutex_lock(&buffer->lock); + list_del(&a->node); + mutex_unlock(&buffer->lock); + kfree(a); +} + +static void *fastrpc_kmap(struct dma_buf *dmabuf, unsigned long pgnum) +{ + struct fastrpc_buf *buf = dmabuf->priv; + + return buf->virt ? buf->virt + pgnum * PAGE_SIZE : NULL; +} + +static void *fastrpc_vmap(struct dma_buf *dmabuf) +{ + struct fastrpc_buf *buf = dmabuf->priv; + + return buf->virt; +} + +static int fastrpc_mmap(struct dma_buf *dmabuf, + struct vm_area_struct *vma) +{ + struct fastrpc_buf *buf = dmabuf->priv; + size_t size = vma->vm_end - vma->vm_start; + + return dma_mmap_coherent(buf->dev, vma, buf->virt, + FASTRPC_PHYS(buf->phys), size); +} + +static const struct dma_buf_ops fastrpc_dma_buf_ops = { + .attach = fastrpc_dma_buf_attach, + .detach = fastrpc_dma_buf_detatch, + .map_dma_buf = fastrpc_map_dma_buf, + .unmap_dma_buf = fastrpc_unmap_dma_buf, + .mmap = fastrpc_mmap, + .map = fastrpc_kmap, + .vmap = fastrpc_vmap, + .release = fastrpc_release, +}; + static int fastrpc_map_create(struct fastrpc_user *fl, int fd, u64 len, struct fastrpc_map **ppmap) { @@ -872,6 +989,60 @@ static int fastrpc_device_open(struct inode *inode, struct file *filp) return 0; } +static int fastrpc_dmabuf_free(struct fastrpc_user *fl, char __user *argp) +{ + struct dma_buf *buf; + int info; + + if (copy_from_user(&info, argp, sizeof(info))) + return -EFAULT; + + buf = dma_buf_get(info); + if (IS_ERR_OR_NULL(buf)) + return -EINVAL; + /* + * one for the last get and other for the ALLOC_DMA_BUFF ioctl + */ + dma_buf_put(buf); + dma_buf_put(buf); + + return 0; +} + +static int fastrpc_dmabuf_alloc(struct fastrpc_user *fl, char __user *argp) +{ + struct fastrpc_alloc_dma_buf bp; + DEFINE_DMA_BUF_EXPORT_INFO(exp_info); + struct fastrpc_buf *buf = NULL; + int err; + + if (copy_from_user(&bp, argp, sizeof(bp))) + return -EFAULT; + + err = fastrpc_buf_alloc(fl, fl->sctx->dev, bp.size, &buf); + if (err) + return err; + exp_info.ops = &fastrpc_dma_buf_ops; + exp_info.size = bp.size; + exp_info.flags = O_RDWR; + exp_info.priv = buf; + buf->dmabuf = dma_buf_export(&exp_info); + if (IS_ERR(buf->dmabuf)) + return PTR_ERR(buf->dmabuf); + + get_dma_buf(buf->dmabuf); + bp.fd = dma_buf_fd(buf->dmabuf, O_ACCMODE); + if (bp.fd < 0) { + dma_buf_put(buf->dmabuf); + return -EINVAL; + } + + if (copy_to_user(argp, &bp, sizeof(bp))) + return -EFAULT; + + return 0; +} + static int fastrpc_init_attach(struct fastrpc_user *fl) { struct fastrpc_invoke_args args[1]; @@ -934,6 +1105,12 @@ static long fastrpc_device_ioctl(struct file *file, unsigned int cmd, case FASTRPC_IOCTL_INIT_CREATE: err = fastrpc_init_create_process(fl, argp); break; + case FASTRPC_IOCTL_FREE_DMA_BUFF: + err = fastrpc_dmabuf_free(fl, argp); + break; + case FASTRPC_IOCTL_ALLOC_DMA_BUFF: + err = fastrpc_dmabuf_alloc(fl, argp); + break; default: err = -ENOTTY; dev_err(fl->sctx->dev, "bad ioctl: %d\n", cmd); diff --git a/include/uapi/misc/fastrpc.h b/include/uapi/misc/fastrpc.h index 32d191c3b7bc..6d701af9fc42 100644 --- a/include/uapi/misc/fastrpc.h +++ b/include/uapi/misc/fastrpc.h @@ -5,6 +5,8 @@ #include +#define FASTRPC_IOCTL_ALLOC_DMA_BUFF _IOWR('R', 1, struct fastrpc_alloc_dma_buf) +#define FASTRPC_IOCTL_FREE_DMA_BUFF _IOWR('R', 2, __u32) #define FASTRPC_IOCTL_INVOKE _IOWR('R', 3, struct fastrpc_invoke) #define FASTRPC_IOCTL_INIT_ATTACH _IO('R', 4) #define FASTRPC_IOCTL_INIT_CREATE _IOWR('R', 5, struct fastrpc_init_create) @@ -30,4 +32,10 @@ struct fastrpc_init_create { __u64 file; /* pointer to elf file */ }; +struct fastrpc_alloc_dma_buf { + __s32 fd; /* fd */ + __u32 flags; /* flags to map with */ + __u64 size; /* size */ +}; + #endif /* __QCOM_FASTRPC_H__ */