From patchwork Tue May 2 20:59:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sarangdhar Joshi X-Patchwork-Id: 9708601 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 11CBF60349 for ; Tue, 2 May 2017 20:59:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 026E82851A for ; Tue, 2 May 2017 20:59:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EB7F22858D; Tue, 2 May 2017 20:59:49 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8AC5E2851A for ; Tue, 2 May 2017 20:59:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=TKUvD1VBL0fNE3nmnqf4yeEvcyX8XT61kpninqrD3aQ=; b=n/q hQDorzaFrNK5S/Avctpj67wWbYRquf5ZXHdFKQw21yeWP7gjwZRbP85QRAw9vdUFkH+Mtuja2yy8A E1zVbVurC1lmVqMmCWsHUcNq1URKUlAO2TG3Tg/gXteEvHd1m8SFT7bda5CUE52dVw9mq75XReIB1 Q16n80XNnm+6JggzLbjhnhS6s+9G0AeafcZh4QKmY6teoTHbmEtQFVEUFyDhhQ0SA1xM0fY2zxQeD 29pta4RJQohZ7Dyp3M+Husa4espZ9UZHCbtsG1NMshqtsWwZbSbopWku0XU8A7tlS0mPvbcnXf+sW I/J65t0chABfyh9eBKjBMV3BcecllgA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1d5etg-0003Ul-9F; Tue, 02 May 2017 20:59:48 +0000 Received: from smtp.codeaurora.org ([198.145.29.96]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1d5etT-0003Ft-Dn for linux-arm-kernel@lists.infradead.org; Tue, 02 May 2017 20:59:37 +0000 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 09CD760B7E; Tue, 2 May 2017 20:59:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1493758755; bh=B5xjD5xX9S8dGrJXHgowbG650ZVO6g8STpzuBZyiTO4=; h=From:To:Cc:Subject:Date:From; b=NyWguEItnExSoWgGJcmexRBm1h41yPABRX8EJMBH9aMe911nY/KDH2s/MuaudZ2Gz bVXb697CjXlU3drcUWDZ/+ER9m6RV3k+FgdVfGSIyJJEuoyEHPmoPH8xv6GQNBTrP6 zf2NrjMl51ZWf8V4ekSG4NSbsNeMssw+DHgPl2SA= 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 B188B60AFE; Tue, 2 May 2017 20:59:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1493758754; bh=B5xjD5xX9S8dGrJXHgowbG650ZVO6g8STpzuBZyiTO4=; h=From:To:Cc:Subject:Date:From; b=Ja9XnOR+K3W89Pp9ZsfTgNGWhdZ+3McbVCDRwyNKjMit92pUC4hnWA9hnrwy88t+a Ocsru0PUsdQ8gC9c9kH4jltEyHBYjNEIpU+CXa+uvrAb+wgaEuGe7W1MWqsEuivWg2 BlIxesLKbAsPPmsuJGyfEdh1I1hn/6jrRFJAT8rk= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org B188B60AFE 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 Subject: [PATCH 1/2] remoteproc: Introduce rproc_{start,stop}() functions Date: Tue, 2 May 2017 13:59:01 -0700 Message-Id: <1493758742-26148-1-git-send-email-spjoshi@codeaurora.org> X-Mailer: git-send-email 1.9.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170502_135935_512871_5EEB89C3 X-CRM114-Status: GOOD ( 19.96 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Trilok Soni , linux-arm-msm@vger.kernel.org, Stephen Boyd , linux-kernel@vger.kernel.org, linux-remoteproc@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.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. The current 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 --- I had forgot to send the second patch (2/2) in this series earlier. Hence resending both patches as a series. drivers/remoteproc/remoteproc_core.c | 118 ++++++++++++++++++++++++++++++++--- 1 file changed, 110 insertions(+), 8 deletions(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 9fd9ca5..169abb3 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -851,6 +851,61 @@ 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 device *dev = &rproc->dev; + struct resource_table *table, *loaded_table; + 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->table_ptr as the + * resource table. The address of the vring along with the other + * allocated resources (carveouts etc) is stored in table_ptr. + * 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->table_ptr, tablesz); + + /* 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. */ @@ -993,6 +1048,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 @@ -1005,23 +1086,44 @@ static int rproc_trigger_auto_boot(struct rproc *rproc) */ int rproc_trigger_recovery(struct rproc *rproc) { + const struct firmware *firmware_p; + struct device *dev; + int ret; + dev_err(&rproc->dev, "recovering %s\n", rproc->name); init_completion(&rproc->crash_comp); - /* shut down the remote */ - /* TODO: make sure this works with rproc->power > 1 */ - rproc_shutdown(rproc); + dev = &rproc->dev; + + ret = mutex_lock_interruptible(&rproc->lock); + if (ret) + return ret; + + ret = rproc_stop(rproc); + if (ret) + goto unlock_mutex; /* wait until there is no more rproc users */ wait_for_completion(&rproc->crash_comp); - /* - * boot the remote processor up again - */ - rproc_boot(rproc); + /* load firmware */ + ret = request_firmware(&firmware_p, rproc->firmware, dev); + if (ret < 0) { + dev_err(dev, "request_firmware failed: %d\n", ret); + goto unlock_mutex; + } - return 0; + /* boot the remote processor up again */ + ret = rproc_start(rproc, firmware_p); + if (ret) + goto unlock_mutex; + + release_firmware(firmware_p); + +unlock_mutex: + mutex_unlock(&rproc->lock); + return ret; } /**