Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp159137pxu; Thu, 3 Dec 2020 23:18:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJxoCXQ4gglHJKq6Q/YHel43os8uomVFJWQ4y6StWIKRpUUEL5HhanOgpa0SykwItqWEIaIK X-Received: by 2002:a17:906:e81:: with SMTP id p1mr5961819ejf.494.1607066315933; Thu, 03 Dec 2020 23:18:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1607066315; cv=pass; d=google.com; s=arc-20160816; b=bQmGDazUNt58VbxIlnjmKz06kb4+ISB/TX+YcgxjO9OWK0q0r+zvqMh6Xwe4fEqfro WCGreqrISJVimDULhRaAs5P/Q+Z6vCY8WEyecaP7beEboRbwIk0LQS6RkIsTnYeUzo39 JeH7Renh3rr0KBICf2A2s09wq8vibQV07AR85A3EGuBCO1Wu0yLBL34HjKGfz9GuweHd hsbExS5YAjspYUyKGlNdLvGtrrbKZkJRTzo9FqXsPghl5cARlPkB7mHNmWEXxTfqVPmX E6uv+P+IjX4zD/+ee7YOiZ9Fa+MbsyLBtk6bOOmVFJMXzCovoLFOXpIz3zMC/TZelS43 SkSA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=69mDimMzLu3IO5s4RcOT8U6CJdzR21tb+dih4rXAJvQ=; b=SLaoeYf+Fg18/JRtfz1mipNta/NJPX+uztxC9PcQDtlcQMz8X8QhsAQPbWAIj2ZE1Y TBb+PvySldQeifi0duo+F5gCihtwrDc90g8fRl5udKMlNmaGvttS9dJZDAtEFTgP/5Pb 1eILN9uGQNdUua/f8RN/Lf0h91EBk/6h7uNsqsJTb8UWCjOJNmcaBKeVfTCgv4A63HWQ eOqXSYvlYn3kjdn0EiJtypFCivLtK8Z5WcDbdvBhzCQHNH0kpxYiYXq6t0Cj0Akb1vkP uUezL0FsNcmgSNuSgzLz9LkMw8iw1LmBJj9N5Y2vU5LdtLtQHJaNQMEEKa7SSdkaRhX7 zI+g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@NXP1.onmicrosoft.com header.s=selector2-NXP1-onmicrosoft-com header.b=Zeu4uW7J; arc=pass (i=1 spf=pass spfdomain=oss.nxp.com dkim=pass dkdomain=oss.nxp.com dmarc=pass fromdomain=oss.nxp.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p90si2331015edd.341.2020.12.03.23.18.13; Thu, 03 Dec 2020 23:18:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@NXP1.onmicrosoft.com header.s=selector2-NXP1-onmicrosoft-com header.b=Zeu4uW7J; arc=pass (i=1 spf=pass spfdomain=oss.nxp.com dkim=pass dkdomain=oss.nxp.com dmarc=pass fromdomain=oss.nxp.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728682AbgLDHOp (ORCPT + 99 others); Fri, 4 Dec 2020 02:14:45 -0500 Received: from mail-eopbgr60075.outbound.protection.outlook.com ([40.107.6.75]:2951 "EHLO EUR04-DB3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728473AbgLDHOo (ORCPT ); Fri, 4 Dec 2020 02:14:44 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lCDO8BZrLqgpUq5M9hZxGaxlaCjMMc9bauKSX15ZYQSfN4TkHOaJW8dYJAoJFj0jnedBe5PpEFExiQHTIiPLfyxT3Gw4KS8cB3HtvO/Q0eZ4f2S3XY0oGIAOqm6Ps9jMeNs/spDQ3ShzuHZb02XBJA2aJiD0jriqUsD3qgbXfwjk8ETSa6L3qhQFITY6lbH/oMrHho1rHjgFHnMfI88UysBpySlbw5PkMgLAHUC8+w4dFVmhPUxV3FuexywceTHi0ZI4tdu1t5B52Onq8BfRTPoczrhu3CGilkj2M5kToUdnaZmFxhFHb3MO9yol3CACZspzQqhjoJfkK6I5ZLWy+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=69mDimMzLu3IO5s4RcOT8U6CJdzR21tb+dih4rXAJvQ=; b=NQR3pHt9kCK6Z4Qwoul53lgoHfzQf6eXahpVqQlV9KceCbc/jLVNaWJPqw/LlHpFMmi0wAwOMELRbOmXSve4vreGMxyICVV8yeYquF8vCYZkjUSThXgJMq2OtfNZfng+SNUS7LzVt61yqhd6ljGL1M6A3PgxzqYQDFC2sivpVOarBEcvXiGjBGhG7nVkwGPZTSVeaKAiCumyRsFjfwD7HmmjOzyJS21+yACNFycwTTNDBsJs9IP8Pw2GB88RUxTvCwdhx8yUVmY3I905VnKpGxjDnNKhuKmHlgyAHTbVxIMJJpblyOQje5hdOXItvEni4xBSwHiu/R6x3GH8MGLxCg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector2-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=69mDimMzLu3IO5s4RcOT8U6CJdzR21tb+dih4rXAJvQ=; b=Zeu4uW7J7t1enBkxtrgueQz3yHRWZE1ZJxBIk3w4iSHC/BvLVR+8kif9En/6Zz2wMH40ftKfKcFHod1Y09LupWyJQYigvshm7hcG2EktXOqTNsVCSaTcrRRIJHeQNmeU8l5aXREG3tEy8nEjNjcL978TNTlDjeQ+LAKvBh82ZTw= Authentication-Results: wizery.com; dkim=none (message not signed) header.d=none;wizery.com; dmarc=none action=none header.from=oss.nxp.com; Received: from DB6PR0402MB2760.eurprd04.prod.outlook.com (2603:10a6:4:a1::14) by DB7PR04MB4633.eurprd04.prod.outlook.com (2603:10a6:5:36::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.31; Fri, 4 Dec 2020 07:13:11 +0000 Received: from DB6PR0402MB2760.eurprd04.prod.outlook.com ([fe80::c964:9:850a:fc5]) by DB6PR0402MB2760.eurprd04.prod.outlook.com ([fe80::c964:9:850a:fc5%10]) with mapi id 15.20.3632.018; Fri, 4 Dec 2020 07:13:11 +0000 From: "Peng Fan (OSS)" To: ohad@wizery.com, bjorn.andersson@linaro.org, mathieu.poirier@linaro.org, o.rempel@pengutronix.de Cc: shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com, linux-imx@nxp.com, linux-remoteproc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Peng Fan , Richard Zhu Subject: [PATCH V3 5/7] remoteproc: imx_rproc: add i.MX specific parse fw hook Date: Fri, 4 Dec 2020 15:40:34 +0800 Message-Id: <20201204074036.23870-6-peng.fan@oss.nxp.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201204074036.23870-1-peng.fan@oss.nxp.com> References: <20201204074036.23870-1-peng.fan@oss.nxp.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [119.31.174.71] X-ClientProxiedBy: MAXPR0101CA0069.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:e::31) To DB6PR0402MB2760.eurprd04.prod.outlook.com (2603:10a6:4:a1::14) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from linux-1xn6.ap.freescale.net (119.31.174.71) by MAXPR0101CA0069.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:e::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3632.17 via Frontend Transport; Fri, 4 Dec 2020 07:13:06 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 4401f702-7dee-4b3e-057d-08d898240edf X-MS-TrafficTypeDiagnostic: DB7PR04MB4633: X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3276; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: lwEhT/1CZAmB4FULKZYBlrsBwexy5uhWObDAu40/QWmOuDJG2h3b1y6TKpp+mjbCzNMBRFzrKwImMOqoXVfXsbstBWnG0PRvG644pvaquG4njdTM2KwsPduN5ojf9Ni2dUPdmGio88TY5mG2oXdK5WRNNSmJ83Xq1sgtthX+8uc1QmkINuRw+Y3/NXfc4iiwGntF8a/oNHtKlGHOC3cHgWFBMe7lJJQ4flbAvPDGztHNLX3gNH+69co9AFbqQZqU2+iL4IxN1UkMk+xd6mMaZVhXj2zqC10HEz/ajRi3tzsdkKpsupppDAM5besy7izlTYdajxIjOm7JnnVq50c2KA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DB6PR0402MB2760.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(39860400002)(376002)(366004)(396003)(346002)(136003)(2616005)(86362001)(52116002)(6512007)(7416002)(1076003)(83380400001)(66946007)(66556008)(66476007)(478600001)(316002)(186003)(16526019)(8676002)(956004)(54906003)(6666004)(6506007)(2906002)(26005)(6486002)(8936002)(4326008)(5660300002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?OQjwKrhHaPDLjwGzgU0aL+HtuFpjlSAdLEN/48Z4MbvHD0YkEvl9i2S/i7eg?= =?us-ascii?Q?W9fRSn1qa6kT4aKTgkWhvprtQPLkPgLeo4yPkCW9dY2eR9uFMkm3UA6VisZa?= =?us-ascii?Q?lpXI0vcUkCA6UaVdq9DzYEH8ppcnHGrl+t5JulsW+jWUmx8cp21Xv4mJAEd5?= =?us-ascii?Q?rG4T9gjgCzf1r/c1DaYd/EGdKpGzAZMzc5Vk7bWLUCrqPPCIbmyVPeDZZsX1?= =?us-ascii?Q?t4VNMB7v6+pKH6ON4GhgJATjrlvNr2IGmvNeBzYVMZTe+EkqPwcgl8B3Tu8m?= =?us-ascii?Q?jzES3knjcDdD+G8W4xPgidaK7NmDBBy1JoZRWJDN+X5ffxWAtNQupsolSnJR?= =?us-ascii?Q?BuOiXZA+Vwb3IPoT0ZsKf0D9xPmwSwTnsWcl0Zopj0x6OHaWxbw3uJthduvX?= =?us-ascii?Q?/k7awyxYp6Yop5IrY4O7ksB465jn94bzto+H0VKUFBNTQVMuy4u2RjcegmEO?= =?us-ascii?Q?tCh8pny3EB6vAH4VODtQ/ZVvmWamKFjOJCtdBdu5jBKXXrMJvYbLWEJg27Bs?= =?us-ascii?Q?XGISOIDW0CL6mAscipz1dj1zLoy0Qp8bOWJfkrJHAGHzlicCO+KwtjJUPdXK?= =?us-ascii?Q?y0SwxW+uUa+F7FvCUNhZQ9MDhpxAqQNb80QlOKxV224YvvYbkb69X83BU+2S?= =?us-ascii?Q?KTjUzsErlTlCPIHhlz9XcwPX5GUksE2olpbNgt97Wwz+UlEruNAKLVj6lc42?= =?us-ascii?Q?qRcQxWdtbNSnm5GLlP6pXUVq+WoQ7SftDU8V81Or4rCMDZp8/1woBLBftJKb?= =?us-ascii?Q?NvBWA+gNGrBYqmf/YsjVP6g4FhmMhOWTMTNNKJD0uzrIxo9AuaYgz1Kuer6A?= =?us-ascii?Q?pWekHMxGMwsFPzcxYplGG/TIc1gCZcJR5IoLvZqkJ9uQuJ4MwuwSaQP/9caT?= =?us-ascii?Q?Q/agbcGvpJzI31HGOxA8Dy1bfHuYeICsw+z1fFaKIoba8tZ5RtGbKpb0E7qw?= =?us-ascii?Q?fdlMGWWcOXqryqWnuYQr4lc5R6cd6NM825Efl1TuFc7Cni/5Yw1z1WQTyhr5?= =?us-ascii?Q?fLw1?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4401f702-7dee-4b3e-057d-08d898240edf X-MS-Exchange-CrossTenant-AuthSource: DB6PR0402MB2760.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Dec 2020 07:13:11.1995 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 6EqkxG6qqdC2O9T+egeM49jbxHTlf/91EKt7VAtlR87tw83BErdeF0qRPcBlh2nwo2brNGnB3Q1a0iFX0KdG0A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR04MB4633 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Peng Fan The hook is used to parse memory-regions and load resource table from the address the remote processor published. Signed-off-by: Peng Fan Reviewed-by: Richard Zhu Reviewed-by: Mathieu Poirier --- drivers/remoteproc/imx_rproc.c | 93 ++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c index 15c7baa480d7..de44b7d6ae63 100644 --- a/drivers/remoteproc/imx_rproc.c +++ b/drivers/remoteproc/imx_rproc.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -243,10 +244,102 @@ static void *imx_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len) return va; } +static int imx_rproc_mem_alloc(struct rproc *rproc, + struct rproc_mem_entry *mem) +{ + struct device *dev = rproc->dev.parent; + void *va; + + dev_dbg(dev, "map memory: %p+%zx\n", &mem->dma, mem->len); + va = ioremap_wc(mem->dma, mem->len); + if (IS_ERR_OR_NULL(va)) { + dev_err(dev, "Unable to map memory region: %p+%zx\n", + &mem->dma, mem->len); + return -ENOMEM; + } + + /* Update memory entry va */ + mem->va = va; + + return 0; +} + +static int imx_rproc_mem_release(struct rproc *rproc, + struct rproc_mem_entry *mem) +{ + dev_dbg(rproc->dev.parent, "unmap memory: %pa\n", &mem->dma); + iounmap(mem->va); + + return 0; +} + +static int imx_rproc_parse_memory_regions(struct rproc *rproc) +{ + struct imx_rproc *priv = rproc->priv; + struct device_node *np = priv->dev->of_node; + struct of_phandle_iterator it; + struct rproc_mem_entry *mem; + struct reserved_mem *rmem; + u32 da; + + /* Register associated reserved memory regions */ + of_phandle_iterator_init(&it, np, "memory-region", NULL, 0); + while (of_phandle_iterator_next(&it) == 0) { + /* + * Ignore the first memory region which will be used vdev buffer. + * No need to do extra handlings, rproc_add_virtio_dev will handle it. + */ + if (!strcmp(it.node->name, "vdevbuffer")) + continue; + + rmem = of_reserved_mem_lookup(it.node); + if (!rmem) { + dev_err(priv->dev, "unable to acquire memory-region\n"); + return -EINVAL; + } + + /* No need to translate pa to da, i.MX use same map */ + da = rmem->base; + + /* Register memory region */ + mem = rproc_mem_entry_init(priv->dev, NULL, (dma_addr_t)rmem->base, rmem->size, da, + imx_rproc_mem_alloc, imx_rproc_mem_release, + it.node->name); + + if (mem) + rproc_coredump_add_segment(rproc, da, rmem->size); + else + return -ENOMEM; + + rproc_add_carveout(rproc, mem); + } + + return 0; +} + +static int imx_rproc_parse_fw(struct rproc *rproc, const struct firmware *fw) +{ + int ret = imx_rproc_parse_memory_regions(rproc); + + if (ret) + return ret; + + ret = rproc_elf_load_rsc_table(rproc, fw); + if (ret) + dev_info(&rproc->dev, "No resource table in elf\n"); + + return 0; +} + static const struct rproc_ops imx_rproc_ops = { .start = imx_rproc_start, .stop = imx_rproc_stop, .da_to_va = imx_rproc_da_to_va, + .load = rproc_elf_load_segments, + .parse_fw = imx_rproc_parse_fw, + .find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table, + .sanity_check = rproc_elf_sanity_check, + .get_boot_addr = rproc_elf_get_boot_addr, }; static int imx_rproc_addr_init(struct imx_rproc *priv, -- 2.28.0