From patchwork Fri Mar 24 19:22:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaying Liang X-Patchwork-Id: 9643927 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8C3CB601E9 for ; Fri, 24 Mar 2017 19:31:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7908F27D16 for ; Fri, 24 Mar 2017 19:31:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6CFE927E5A; Fri, 24 Mar 2017 19:31:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B860E27D16 for ; Fri, 24 Mar 2017 19:31:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S967175AbdCXTbt (ORCPT ); Fri, 24 Mar 2017 15:31:49 -0400 Received: from mail-co1nam03on0060.outbound.protection.outlook.com ([104.47.40.60]:7136 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S967059AbdCXTaB (ORCPT ); Fri, 24 Mar 2017 15:30:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector1-xilinx-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=+ijjhqUyndpuPd/LCgV4DD1tOSorKgd38xq19tQvCfA=; b=NLkPFq0hOu1eP4wrZrjZ778bPPbwsNldqNh6kluTJ49Lptfya0vB4elpgVbW6qGGr6+VoUvoMkyjd798rua0LCUHqdRM/7tgiZ8VgbX6aEDan1/fm869ZsxcHl0nt2PymXEvHMuDJuY3PD0D0WqLajqO/svZL/Dk8qOG5ZiyHSs= Received: from BY2PR02CA0023.namprd02.prod.outlook.com (10.141.216.13) by CY1PR0201MB0762.namprd02.prod.outlook.com (10.160.141.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.977.11; Fri, 24 Mar 2017 19:29:49 +0000 Received: from CY1NAM02FT052.eop-nam02.prod.protection.outlook.com (2a01:111:f400:7e45::203) by BY2PR02CA0023.outlook.office365.com (2a01:111:e400:2c40::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.991.14 via Frontend Transport; Fri, 24 Mar 2017 19:29:49 +0000 Authentication-Results: spf=pass (sender IP is 149.199.60.100) smtp.mailfrom=xilinx.com; vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=bestguesspass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.60.100 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.60.100; helo=xsj-pvapsmtpgw02; Received: from xsj-pvapsmtpgw02 (149.199.60.100) by CY1NAM02FT052.mail.protection.outlook.com (10.152.74.123) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.977.7 via Frontend Transport; Fri, 24 Mar 2017 19:29:48 +0000 Received: from unknown-38-66.xilinx.com ([149.199.38.66]:55323 helo=xsj-pvapsmtp01) by xsj-pvapsmtpgw02 with esmtp (Exim 4.63) (envelope-from ) id 1crUuB-0002ad-Mg; Fri, 24 Mar 2017 12:29:47 -0700 Received: from [127.0.0.1] (helo=localhost) by xsj-pvapsmtp01 with smtp (Exim 4.63) (envelope-from ) id 1crUuB-0002kt-IT; Fri, 24 Mar 2017 12:29:47 -0700 Received: from xsj-pvapsmtp01 (xsj-smtp.xilinx.com [149.199.38.66]) by xsj-smtp-dlp1.xlnx.xilinx.com (8.13.8/8.13.1) with ESMTP id v2OJTg2j010386; Fri, 24 Mar 2017 12:29:43 -0700 Received: from [172.19.2.167] (helo=xsjjliang50.xilinx.com) by xsj-pvapsmtp01 with esmtp (Exim 4.63) (envelope-from ) id 1crUu6-0002jg-P2; Fri, 24 Mar 2017 12:29:42 -0700 From: Wendy Liang To: CC: , , "Wendy Liang" , Wendy Liang , Michal Simek Subject: [RFC LINUX PATCH 05/19] remoteproc: check if remote is running the fw before reload fw Date: Fri, 24 Mar 2017 12:22:21 -0700 Message-ID: <1490383355-23176-6-git-send-email-jliang@xilinx.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1490383355-23176-1-git-send-email-jliang@xilinx.com> References: <1490383355-23176-1-git-send-email-jliang@xilinx.com> X-RCIS-Action: ALLOW X-TM-AS-Product-Ver: IMSS-7.1.0.1224-8.1.0.1062-22962.005 X-TM-AS-User-Approved-Sender: Yes;Yes X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:149.199.60.100; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(39840400002)(39860400002)(39450400003)(39410400002)(39850400002)(2980300002)(438002)(189002)(199003)(9170700003)(6666003)(2950100002)(54906002)(2906002)(38730400002)(107886003)(6916009)(110136004)(8936002)(81166006)(5003940100001)(8676002)(50986999)(189998001)(9786002)(76176999)(4326008)(47776003)(77096006)(50226002)(2351001)(5660300001)(106466001)(305945005)(36756003)(33646002)(356003)(36386004)(50466002)(48376002)(107986001)(217873001); DIR:OUT; SFP:1101; SCL:1; SRVR:CY1PR0201MB0762; H:xsj-pvapsmtpgw02; FPR:; SPF:Pass; MLV:sfv; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; CY1NAM02FT052; 1:UukCwMKLWZ1W2uKJoRqm6jB+cujWXl5vMSA5zfmPgHRgzdDVMQOkX+c7BqUyQIzGKuVhZ07WgKeHQ8WTq/23Colh/uW803sh8TIz0pDyXfRAVmv35EOVdpROCIOokWk54juf3MPzdL1C4cU4Dt02r0F6Dt0mAjk+lH5mcsK+/PqWv2yPaFPkDqV+c1f9NE3RJWQE5L5N/9T1CpZ5AgYN3yV8KrfIWP4iklKtO6jNp+4zYVRegVQb/ZmYBY95Lcz5WEiAutJRSkVmrEqZ3ixDu/4vdiP6bVEPjbXR3Z7gVRHu6w/U3QWTtP36MNhxFJx1Fi4+BKTeIsMynL9GX10HsECs7npVa4S3NmNmcBzamrI0q25hUCUtOTOVNQA9x+VK7gmLboA4sZ5/HTB4xqUFsiDN/kGNuJp3Xbw5Mv4qdpT93U/fpAMZ+2du8J7oSTAED8ED5EEuJECC3dZg7eXKMBRzTdQpzHn79/Kqchqz10JFzdnMWAgM643x7S+U+mN19ARxhciiSK2s0qeqzvFFW/6lfBJbg/PJ3EMaW74OOK7MYBuFeDyWur5AxZgQ2LaEldrnW6MmgafXQQLkOKCVmg== MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: 15cd332e-0797-4b0c-e358-08d472ec2291 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(8251501002)(2017030254075); SRVR:CY1PR0201MB0762; X-Microsoft-Exchange-Diagnostics: 1; CY1PR0201MB0762; 3:0fYSwfQavR5SIGkljaU/x7lnRzcSuZGDBfICRwuvw3c2qNak1hnn/8QotNGGY/Q/LpnZDnw0+kdOYYoQzMgMNGhG60vMKuGkYQ0aS41tkekAew/Sw5jukPWgAcMrC2GuYeBzuV+X+Y/7m4nEHIP0k+Eqmv12/lHIn/UuXWcHx2jSWMQTzDPAQ0UtPaH2lQSlDtzgfPrAb+0/et9Idm1O3N9H47GvCTEP7LRTrqjozMxC+f+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pHgZ8ksV+Ot1MAoqrN2S49tx7fuvnesjaPg3XJCXNiUVS+gAyX3B8huIR6EhuM+YR+k4x/b+3Lkn+GxXui2UUwpnDZFOEU2WPKHMLNnSjqNj1buG3bBREd2IxjnYZk0CR/KD3WDrOV2j2hMJqVEV4NtRYhY7Bmbvq+8au21ET5pwEvVy4VndaOBChsUh830nlRnqyT+kLhE2zPeq/Xq3YNej0A29WADF3uXpsVhCoQehUesHe49Fsc7foRBzmQZc+5O1Wekp/+dhpNuiVm6YZiII6QUdtzlGfmNo7F87XV54DqQ7FiwXp99n8zrTXVIqlIlg0+5SoOfupYAYDZxG6969m+Pe7Y4DP/1WqPzdhGQbCgz5k+MIF+Kh6oCco+VUWp5LlCQ52sFIyfea5/zECHn41ZsDUt1AJRPW7HugJzxSbFwrs99ffrGcQqBLPB87vmSQ85Vx9/hBbtsveX X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(192813158149592); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(13023025)(5005006)(13017025)(8121501046)(13015025)(13024025)(13018025)(3002001)(10201501046)(6055026)(6041248)(20161123562025)(20161123564025)(20161123560025)(20161123558025)(20161123555025)(6072148); SRVR:CY1PR0201MB0762; BCL:0; PCL:0; RULEID:; SRVR:CY1PR0201MB0762; X-Microsoft-Exchange-Diagnostics: 1; CY1PR0201MB0762; 4:0w0INZhgRGg7xplSAxiQfnwUIhq7FhEi02afXxH1mI2h5plLMu4AGSp+WuN5lkuXVgDhmkkFo2BYEj/LnLnuJtzU6D3ZR2qS513avuobYgp2Blj7GtOV22Nn3wmBmXdB/gJKvGniufvTLtfY0x4KiMYJ/pzVRy1IsjMSV5O9BKbTr9kXwr58vE2udzpE4B4NtKiliMRlOss4JXm/OFDVQDQsJSm6rgmKlghCP3SqZLmksgHXuSsXZxDTtBUp/oOye11A9miWewr6S3ABEHaIJbpv3WWrEn8WxirgTvI3K1xPhX3QPVL/2nHX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hE90gsdEIt+tK4t3y8BqqwUHpVXNw6WoJojXDmD2hwIevEVu8PSEdXWIk1ttClPlJ+pONHXNivfLsZNz+NHWUJL8KkPhdDa+aNWthUVuaMpmQUPMW/r9rcj69uxN+3TZPq1K6E1G356hWQgzXsRHF9IOGlGocXuZndBI4OD6V7BESJvbGMK+8EALdaloKoOGubcUr6jU=; 5:tWPJeZ1moVmA/5Gg1a1QJTodv4K2+tKZXMPx2Pi08mrVf70B02riz2ghbi+JWH1E5IxCV/ScGnw17DDRdZ+/i6SY1832Q/bT/q8BrcolTsxeL9InjJQxi0tmLoO4SpFiztNROftC1pdfGh6UuAbwbg==; 24:ozKli5H2xLLkm85KBvv78rlOgWFyWucmsO2lU61HjgGWaTHGhuHKFwxo3vcw1A7BmV+oxZvHTvl6PzpqElivEUtYxR8IWbSpyhmAxHaScAs= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; CY1PR0201MB0762; 7:qRh44b6lZyxq6iJi9QFybvSuBvaDBrIUimG1LoIcH7ms83lQs6dQHuxXA3ZhtMsmDk7pjwGJTNtOAIh90yZfitepy7aDyYyBT5uqKQbS2RNIIZWS3vhuu/whUt3kpm6IpLZbodkK2NOTMg97SIOKnSRy8mOmtQbmYbMmr0tU77Xcoj8g2Nf1zKGrpj+Y0GXbhqwF9B66w5r9nA70O8XOf9cxHN5YGbqmty7ZC8D3B+n0AvO1eddaKdX6vMd85khXEfEK6SIQc2cLT44UIwGmeGns9q9GxaILsRpAB4+G7P9DqlWny0ZPiPN1Rlf8k8cfXAqy4t1LFjAsnTXNHGIaDg== X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Mar 2017 19:29:48.0948 (UTC) X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c; Ip=[149.199.60.100]; Helo=[xsj-pvapsmtpgw02] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR0201MB0762 Sender: linux-remoteproc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Wendy Liang Add a function rproc_is_running_fw() to check if it needs to start the remote betfore it loads firmware and tries to start the remote. In some cases, when the master restarts, the remote is already running the expected firmware. In this case, we don't need to start the remote when the remoteproc driver starts. Signed-off-by: Wendy Liang Signed-off-by: Michal Simek --- drivers/remoteproc/remoteproc_core.c | 99 ++++++++++++++++++++++++++---------- 1 file changed, 71 insertions(+), 28 deletions(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index dfa2aad..f13f56d 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -898,6 +898,17 @@ static bool rproc_is_running(struct rproc *rproc) } /* + * check if the remote needs start. + */ +static bool rproc_is_running_fw(struct rproc *rproc, const struct firmware *fw) +{ + (void)rproc; + (void) fw; + + return false; +} + +/* * take a firmware and boot a remote processor with it. */ static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw) @@ -906,6 +917,7 @@ static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw) const char *name = rproc->firmware; struct resource_table *table, *loaded_table; int ret, tablesz; + bool is_running = false; ret = rproc_fw_sanity_check(rproc, fw); if (ret) @@ -948,6 +960,19 @@ static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw) /* reset max_notifyid */ rproc->max_notifyid = -1; + /* check if the rproc is already running the firmware */ + /* As it may be required to know if the remote is already running + * when handling the resource table, check if the remote is already + * running the expected firmware before handling the resource table. + */ + is_running = rproc_is_running_fw(rproc, fw); + if (is_running) { + rproc->state = RPROC_RUNNING_INDEPENDENT; + loaded_table = rproc_find_loaded_rsc_table(rproc, fw); + if (loaded_table) + rproc->table_ptr = loaded_table; + } + /* handle fw resources which are required to boot rproc */ ret = rproc_handle_resources(rproc, tablesz, rproc_loading_handlers); if (ret) { @@ -955,32 +980,54 @@ static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw) goto clean_up_resources; } - /* load the ELF segments to memory */ - ret = rproc_load_segments(rproc, fw); - if (ret) { - dev_err(dev, "Failed to load program segments: %d\n", ret); - goto clean_up_resources; - } + if (!is_running) { + /* If rproc is running, stop it first */ + if (rproc_is_running(rproc)) { + dev_info(dev, "Restarting the remote.\n"); + ret = rproc->ops->stop(rproc); + if (ret) { + atomic_inc(&rproc->power); + dev_err(dev, "can't stop rproc: %d\n", ret); + goto clean_up_resources; + } + } - /* - * The starting device has been given the rproc->cached_table as the - * resource table. The address of the vring along with the other - * allocated resources (carveouts etc) is stored in cached_table. - * In order to pass this information to the remote device we must copy - * this information to device memory. We also update the table_ptr so - * that any subsequent changes will be applied to the loaded version. - */ - loaded_table = rproc_find_loaded_rsc_table(rproc, fw); - if (loaded_table) { - memcpy(loaded_table, rproc->cached_table, tablesz); - rproc->table_ptr = loaded_table; - } + /* load the ELF segments to memory */ + ret = rproc_load_segments(rproc, fw); + if (ret) { + dev_err(dev, "Failed to load program segments: %d\n", + ret); + goto clean_up_resources; + } - /* power up the remote processor */ - ret = rproc->ops->start(rproc); - if (ret) { - dev_err(dev, "can't start rproc %s: %d\n", rproc->name, ret); - goto clean_up_resources; + /* + * The starting device has been given the rproc->cached_table + * as the resource table. The address of the vring along with + * the other allocated resources (carveouts etc) is stored in + * cached_table. In order to pass this information to the + * remote device we must copy this information to device + * memory. We also update the table_ptr so that any subsequent + * changes will be applied to the loaded version. + */ + loaded_table = rproc_find_loaded_rsc_table(rproc, fw); + if (loaded_table) { + memcpy(loaded_table, rproc->cached_table, tablesz); + rproc->table_ptr = loaded_table; + } + + /* power up the remote processor */ + ret = rproc->ops->start(rproc); + if (ret) { + dev_err(dev, "can't start rproc %s: %d\n", + rproc->name, ret); + goto clean_up_resources; + } + + rproc->state = RPROC_RUNNING; + + dev_info(dev, "remote processor %s is now up\n", rproc->name); + } else { + dev_info(dev, "remote is already running. Do not restart\n"); } /* probe any subdevices for the remote processor */ @@ -991,10 +1038,6 @@ static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw) goto stop_rproc; } - rproc->state = RPROC_RUNNING; - - dev_info(dev, "remote processor %s is now up\n", rproc->name); - return 0; stop_rproc: