From patchwork Fri May 26 23:51:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sarangdhar Joshi X-Patchwork-Id: 9751279 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 6173E60393 for ; Sat, 27 May 2017 01:11:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5031428514 for ; Sat, 27 May 2017 01:11:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4E06C284C7; Sat, 27 May 2017 01:11:02 +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=unavailable 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 3C1F1285CF for ; Sat, 27 May 2017 01:10:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752621AbdE0BKS (ORCPT ); Fri, 26 May 2017 21:10:18 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:56412 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1948859AbdEZXvM (ORCPT ); Fri, 26 May 2017 19:51:12 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id EBB446146B; Fri, 26 May 2017 23:51:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1495842672; bh=yCOC+dG6pdoGmVNZFXfGan4Znd594XnD+yIgqoa249U=; h=From:To:Cc:Subject:Date:From; b=SJwGHSPnCsR6x0QG452FJwLO+K3oOd/zWfkmabS4i+x66CvWQeYyEZ7TWQUR1SUWd +kVCXkJM5g/L5+6COrC0WQlxS4rd1Klai/xH4j9+doegsvmqMSuRUnTkeaIGP51tPr LkAqDTE9KgywbyMe7/SxLAZi3TKKt4NKIsHajl8A= Received: from spjoshi-linux.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: spjoshi@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 7A8E36146B; Fri, 26 May 2017 23:51:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1495842670; bh=yCOC+dG6pdoGmVNZFXfGan4Znd594XnD+yIgqoa249U=; h=From:To:Cc:Subject:Date:From; b=MlpZzhlLfILRV6JbQuO86LrV8rdIaQiisPvdeclmYthF4PZE7U/FKvyIc+HmiD2x0 wSSfhfn+BCUTTet1sVAvEi0MecEkBGvOpOP/GY2CQKQjeqOAFvIWIytsWwwn0N1ynI pRjnIhWXEMGzTun9n5KD9Vhg00gjw/CPrsybQ0d8= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 7A8E36146B Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=spjoshi@codeaurora.org From: Sarangdhar Joshi To: Ohad Ben-Cohen , Bjorn Andersson , Loic Pallardy Cc: Sarangdhar Joshi , linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, Stephen Boyd , Trilok Soni Subject: [PATCH v3 1/2] remoteproc: Introduce rproc_{start, stop}() functions Date: Fri, 26 May 2017 16:51:00 -0700 Message-Id: <1495842661-8926-1-git-send-email-spjoshi@codeaurora.org> X-Mailer: git-send-email 1.9.1 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 In the context of recovering from crash, rproc_trigger_recovery() does rproc_shutdown() followed by rproc_boot(). The remoteproc resources are cleaned up in rproc_shutdown() and immediately reallocated in rproc_boot() which is an unnecessary overhead. Furthermore, we want the memory regions to be accessible after stopping the remote processor, to be able to extract the memory content for a coredump. This patch factors out the code in rproc_boot() and rproc_shutdown() path and introduces rproc_{start,stop}() in order to avoid resource allocation overhead. Signed-off-by: Sarangdhar Joshi --- Changes from v2: * Rebase on top of v4.12-rc1 drivers/remoteproc/remoteproc_core.c | 143 +++++++++++++++++++++-------------- 1 file changed, 87 insertions(+), 56 deletions(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 3dabb20..c8cb54b 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -847,6 +847,63 @@ static void rproc_resource_cleanup(struct rproc *rproc) kref_put(&rvdev->refcount, rproc_vdev_release); } +static int rproc_start(struct rproc *rproc, const struct firmware *fw) +{ + struct resource_table *table, *loaded_table; + struct device *dev = &rproc->dev; + int ret, tablesz; + + /* look for the resource table */ + table = rproc_find_rsc_table(rproc, fw, &tablesz); + if (!table) { + dev_err(dev, "Resouce table look up failed\n"); + return -EINVAL; + } + + /* 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); + return ret; + } + + /* + * 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); + return ret; + } + + /* probe any subdevices for the remote processor */ + ret = rproc_probe_subdevices(rproc); + if (ret) { + dev_err(dev, "failed to probe subdevices for %s: %d\n", + rproc->name, ret); + rproc->ops->stop(rproc); + return ret; + } + + rproc->state = RPROC_RUNNING; + + dev_info(dev, "remote processor %s is now up\n", rproc->name); + + return 0; +} + /* * take a firmware and boot a remote processor with it. */ @@ -854,7 +911,7 @@ static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw) { struct device *dev = &rproc->dev; const char *name = rproc->firmware; - struct resource_table *table, *loaded_table; + struct resource_table *table; int ret, tablesz; ret = rproc_fw_sanity_check(rproc, fw); @@ -905,50 +962,12 @@ 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; - } - - /* - * 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); + ret = rproc_start(rproc, fw); + if (ret) goto clean_up_resources; - } - - /* probe any subdevices for the remote processor */ - ret = rproc_probe_subdevices(rproc); - if (ret) { - dev_err(dev, "failed to probe subdevices for %s: %d\n", - rproc->name, ret); - goto stop_rproc; - } - - rproc->state = RPROC_RUNNING; - - dev_info(dev, "remote processor %s is now up\n", rproc->name); return 0; -stop_rproc: - rproc->ops->stop(rproc); clean_up_resources: rproc_resource_cleanup(rproc); clean_up: @@ -994,6 +1013,32 @@ static int rproc_trigger_auto_boot(struct rproc *rproc) return ret; } +static int rproc_stop(struct rproc *rproc) +{ + struct device *dev = &rproc->dev; + int ret; + + /* remove any subdevices for the remote processor */ + rproc_remove_subdevices(rproc); + + /* power off the remote processor */ + ret = rproc->ops->stop(rproc); + if (ret) { + dev_err(dev, "can't stop rproc: %d\n", ret); + return ret; + } + + /* if in crash state, unlock crash handler */ + if (rproc->state == RPROC_CRASHED) + complete_all(&rproc->crash_comp); + + rproc->state = RPROC_OFFLINE; + + dev_info(dev, "stopped remote processor %s\n", rproc->name); + + return 0; +} + /** * rproc_trigger_recovery() - recover a remoteproc * @rproc: the remote processor @@ -1163,14 +1208,9 @@ void rproc_shutdown(struct rproc *rproc) if (!atomic_dec_and_test(&rproc->power)) goto out; - /* remove any subdevices for the remote processor */ - rproc_remove_subdevices(rproc); - - /* power off the remote processor */ - ret = rproc->ops->stop(rproc); + ret = rproc_stop(rproc); if (ret) { atomic_inc(&rproc->power); - dev_err(dev, "can't stop rproc: %d\n", ret); goto out; } @@ -1183,15 +1223,6 @@ void rproc_shutdown(struct rproc *rproc) kfree(rproc->cached_table); rproc->cached_table = NULL; rproc->table_ptr = NULL; - - /* if in crash state, unlock crash handler */ - if (rproc->state == RPROC_CRASHED) - complete_all(&rproc->crash_comp); - - rproc->state = RPROC_OFFLINE; - - dev_info(dev, "stopped remote processor %s\n", rproc->name); - out: mutex_unlock(&rproc->lock); }