From patchwork Tue Jan 19 07:35:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Fan X-Patchwork-Id: 366138 Delivered-To: patch@linaro.org Received: by 2002:a02:a60d:0:0:0:0:0 with SMTP id c13csp517403jam; Mon, 18 Jan 2021 23:53:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJxYNrvfZe/BuwT+n+8DrYjVq/ynPcL6GbaTq1Ja+bkMvKo1Ak1yR8U8yVDnDF2CLR/PCfY1 X-Received: by 2002:a17:906:414e:: with SMTP id l14mr809789ejk.476.1611042815249; Mon, 18 Jan 2021 23:53:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1611042815; cv=pass; d=google.com; s=arc-20160816; b=yMLN00kgI6+FrbbQyZL6ZgTQ7GR5NY45J5fSuF3aU54UR5AnHDLoHoiiUNmWIgrZsM l6nkb/niLjMdIpSb/O17OGw+h2jWvWT2dvkyBkuJvXuskVW/Ax5eIL2MFKnF75rjxq+S LnyZFXauRAcQvitE5t4/R+PFRgqmiw41ev9a22wp72OH7fl4NrQYO77PqirEmaHIjjtP gRjDC3HX8PLS2+kDwuzgzpaSsGH34NcywyedepqkLsYehic/8g90BefTQOLLJWnXP9nP Xv+IT/R3ertcJy1vIRbsXNzpRnKg/WiNz+MYr/dhqcZ6/6pbZY4ckOj/7y7Lj7WiHaRc 4lKw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=sPFDy9u0V0n4kcoaeuDH3f4yuir3vLJ07Nxch5aSlRA=; b=chWXjhROx8BW/83OByLGrK6l/yFYFdnLkgAtEoyJP8jWx5doZW97GNUWKbLn2At5iA afthuKdwjNTGuhQhtzyp2iMnN2MAJjdg8ZNiTtOsNPKUnPfBXOl+LZ81848ocJNZ1+YR JXEDPn9/9mUNa0y/33yjUK5LtXmwG2cBQzQNggILXbsEXYQ36+3GLwSBC1SoP5hbBuh4 WnIjRQjNPNpg8x4+UPI16phMYcIhOyF/FL06RK3W43wxSeUtzlZDB1rRLh8I0pTK2dSG jkrmwiwogv1wVSq6xtMRPBFJtFd+wpneG5D+vSZ3N4QUz3TXlcHSCKQkw4b/Sd0ZQUhe FUIQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=eZslOlrZ; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (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 v1si3167966ejj.430.2021.01.18.23.53.35; Mon, 18 Jan 2021 23:53:35 -0800 (PST) Received-SPF: pass (google.com: domain of devicetree-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=@nxp.com header.s=selector2 header.b=eZslOlrZ; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731266AbhASHx3 (ORCPT + 6 others); Tue, 19 Jan 2021 02:53:29 -0500 Received: from mail-eopbgr40046.outbound.protection.outlook.com ([40.107.4.46]:22240 "EHLO EUR03-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730749AbhASHsp (ORCPT ); Tue, 19 Jan 2021 02:48:45 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FCdr3HNzoilZaWLwane4A02G2FerTape4He3C01habW0066/175d9iLDNYT3iFjjEMl5VH4Nn+iKaP2Y9gTv8Zu08j23sWmKDfFo2Md+RApDdCEB03EteRA+BjrjV21phuGHHltjE9zObiUVZfBDyZPr/PuQmNbINxsHWHh6z7uEZXUdnzT/6u62YD4LVbJ/lyBytEPyVKt3GvYkSDWfDzYTgWt+gaD+rHcQplGVe6WwIoPlZr5GMmrIoM6JYm8GxLVvzzdhArfmwa6pzDY79pdLJpUz893Jr9PVCzOxdEZkx3DMpYGbMRozjp4+S6ZydCTwh3KlfcLqmneEwsfPEg== 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=sPFDy9u0V0n4kcoaeuDH3f4yuir3vLJ07Nxch5aSlRA=; b=I/4zXpMFUIdiwNUqCf3b3rTQM1xzH3S0dS+fbzXEPtDQE1kS9/YChG6E44oA/USAc0Ff323bHrSfRQ5LAC0LQxHHkRGIC9z4vybqoS88KpcdDfxmzFemHQsemL9x8noDC+UfZfk4YwE+ro2/z7CPpOjqVgVgwLP9nXi0xtc4ep00ztC6p6WNkSIZ8dhSA7Gh8oA94XKOjcyzGWY+XR+7rKbsseqzbLA/s6fXI5a62dyaUZ6/mONVAHIwmMTKJ4wvI+xHwhP4oT20UJEZkoJOpnw+KRYcay2ZFWY8hXHqCIHgZqi1wdX2CSty7gZzfANDd56RUCTS8pdaarUH2XsG6w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=sPFDy9u0V0n4kcoaeuDH3f4yuir3vLJ07Nxch5aSlRA=; b=eZslOlrZVnjwUOrVg4vRM7ZZZW2izG7NrNheZi0oy58MX2p9P87XHa7GC1jIp3C3ae1a2h45Vag88pDydklbV9rlISVGR7t05z4Gxpcz5e5xatQX0H1WCZ/UEtSWHCzXqhxcDA+OZeLaPzx9SdU6/iHtTmWjssysJqnPP5hLUb0= Authentication-Results: wizery.com; dkim=none (message not signed) header.d=none; wizery.com; dmarc=none action=none header.from=nxp.com; Received: from DB6PR0402MB2760.eurprd04.prod.outlook.com (2603:10a6:4:a1::14) by DB7PR04MB4492.eurprd04.prod.outlook.com (2603:10a6:5:39::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.10; Tue, 19 Jan 2021 07:46:16 +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.3763.014; Tue, 19 Jan 2021 07:46:16 +0000 From: peng.fan@nxp.com To: ohad@wizery.com, bjorn.andersson@linaro.org, mathieu.poirier@linaro.org, o.rempel@pengutronix.de, robh+dt@kernel.org, devicetree@vger.kernel.org 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, paul@crapouillou.net, matthias.bgg@gmail.com, agross@kernel.org, patrice.chotard@st.com, Peng Fan Subject: [PATCH V8 07/10] remoteproc: imx_rproc: add i.MX specific parse fw hook Date: Tue, 19 Jan 2021 15:35:08 +0800 Message-Id: <1611041711-15902-8-git-send-email-peng.fan@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1611041711-15902-1-git-send-email-peng.fan@nxp.com> References: <1611041711-15902-1-git-send-email-peng.fan@nxp.com> X-Originating-IP: [119.31.174.66] X-ClientProxiedBy: SG2PR04CA0161.apcprd04.prod.outlook.com (2603:1096:4::23) To DB6PR0402MB2760.eurprd04.prod.outlook.com (2603:10a6:4:a1::14) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (119.31.174.66) by SG2PR04CA0161.apcprd04.prod.outlook.com (2603:1096:4::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.20.3763.9 via Frontend Transport; Tue, 19 Jan 2021 07:46:10 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: c60b7638-442b-452d-eef7-08d8bc4e4d38 X-MS-TrafficTypeDiagnostic: DB7PR04MB4492: 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: ILBtxdOMEtsQf106kcSZ6XWUGeh2ox5ScN7RZ3lRvy8cNpsABISWk/nR33aqiXVGorgizlxaG+79xbK6Th56cxwplSnggPW4k5rrTK8S9HmRTP0JrT6z/ZpAd8LiWcMvLiLPFsk1JzbW8mSaNxYq/AXDRT/ddZRJs9idTds1P90cQq0pUi5yeS5ya9gJ5NNlmolb/CqHlNOjyYbEVeMw8/KVxSh+fOCDqD9rbgYM8vE+p3c55ybg8F7N+e0sZutXVrBBW09z7QRYjMbU10SKRjoFAVL3psboLuxPxR9GdeZ7i04pVZ/cE76vtsooNVKRCGWJ+iom+8wP+3rU+2GZ3mWyDp4z8Efno5evSvWcOjzWykY3BuuXq1b/7KnWCoXIgZmpyoZclO8GKksjt6q+OMWkrsw3s5/TklCpPFytgEt4OmBrLXLS0YfRHhw/X0D+jvnxwMsTE2asw5VbkITVEw== 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)(366004)(5660300002)(2906002)(66476007)(26005)(69590400011)(4326008)(66946007)(186003)(83380400001)(6486002)(6512007)(2616005)(86362001)(36756003)(52116002)(8676002)(6506007)(498600001)(7416002)(9686003)(16526019)(8936002)(66556008)(956004); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 6ElLOM1AjJ9VIA7rIMViRfsMZKk3i8zIRoVmGdtla5XvK98xoGZhncHrhi/8EKs5vUADHvqi/r4UER+x1ftHZh1Ig+M62+46KuBtzJXidgETnMZ4xHcEgHyMOEn6Co5iJ8kOU+FheJFiL2e/11E4dZ7rlW9ir2MYNrdlqrJwozpDLegw8mnK/9omJjJ+a9SO9qJLire7R0pScR9DrHggPaQFtpDT/kjCn21o6mJiySaXQ7+jtqaNyRYpkAISqih68u7bTFSD8zWK5vJn+oGEU98wzoxs5k8koFbgXwyA0UtbcE89n8HIh6a/DMfhrosuovlZegWI9VpMogFC0R7CdRJ38eCfgoyGqo96zkUIIUj5OK/Dcn5kyJ35btFsjfSThwCLJ1p34OiXUMUTQNO1gxauPUc69ifGpbwmWLm0zvoY3IUWqB4S+aiWBgKE7pf+C3fLh7bCJln/S0bCYVx0qOgt/jL0oHEZacCYFeham+L+wJpV7tEpj+A8zUC9UK+s0K38sqP5Xl5b/mPAPhBfz+tr02zy8O/Xfpz9A6FORm5XOVdYkwxLiA5NhOxzc59JXDjSpSQHx/U0rY5jJbdaoLnG/10oO1K87g3OcdnY6Ls1nxbAbUE8TCiboWdeveJWT5VKeNYsJl7vbQDOXMHN/xW0IIMWicY4URZBQ+dzFHQeu9UmpBAuR9H2rEnGLsLaFoSihsdNYAaD8JUa9gTbPVAtUZX28T0SILlRkpSRsA8PxtNN+Y09YOd1fgpRRfVL31AI0yMKULJQgwqbbbPbeNyKp5H3MOmkymFrv0V8nBckz5UmcmA9ZBn8+sR1Yy4kYFh7C86bwKJuag/m0oIILjJ4ADf88TXWtIaGGx1ybVkV3pOp67qYOrZUSssOXyMWCFUnuG1iGqClW8vDpFq9ZSz9+m5pyUmL92qcW7t83ljdaG+IfeSAZ8i12WB7uMFTyAqiCVodhOPoyLIwqxjMrTg91kA6VhPGmFHWfZEb00HcL4FDUXkAkNUuDs7njhU1 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: c60b7638-442b-452d-eef7-08d8bc4e4d38 X-MS-Exchange-CrossTenant-AuthSource: DB6PR0402MB2760.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2021 07:46:16.4411 (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: /WjyT8Bu3muiOXA81fUlxMMJEUmYQpJoVbDXkONyoiF+ZoWRnpYCrkxRmOerIAzUqLQST+doXYEau4U+lnIYcg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR04MB4492 Precedence: bulk List-ID: X-Mailing-List: devicetree@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. Reviewed-by: Richard Zhu Reviewed-by: Mathieu Poirier Signed-off-by: Peng Fan --- drivers/remoteproc/imx_rproc.c | 93 ++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) -- 2.28.0 diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c index 47fc1d06be6a..5ae1f5209548 100644 --- a/drivers/remoteproc/imx_rproc.c +++ b/drivers/remoteproc/imx_rproc.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -241,10 +242,102 @@ static void *imx_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool *i 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, "vdev0buffer")) + 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,