From patchwork Tue Oct 11 13:39:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Redfearn X-Patchwork-Id: 9371033 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 38413607FD for ; Tue, 11 Oct 2016 13:42:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2B0EE29C2E for ; Tue, 11 Oct 2016 13:42:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1FA3A29C58; Tue, 11 Oct 2016 13:42:01 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 9281F29C2E for ; Tue, 11 Oct 2016 13:42:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753872AbcJKNlj (ORCPT ); Tue, 11 Oct 2016 09:41:39 -0400 Received: from mailapp02.imgtec.com ([217.156.133.132]:25389 "EHLO mailapp01.imgtec.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752657AbcJKNkJ (ORCPT ); Tue, 11 Oct 2016 09:40:09 -0400 Received: from HHMAIL03.hh.imgtec.org (unknown [10.44.0.21]) by Forcepoint Email with ESMTPS id 780A6996CDD1C; Tue, 11 Oct 2016 14:39:48 +0100 (IST) Received: from HHMAIL01.hh.imgtec.org (10.100.10.19) by HHMAIL03.hh.imgtec.org (10.44.0.21) with Microsoft SMTP Server (TLS) id 14.3.294.0; Tue, 11 Oct 2016 14:39:51 +0100 Received: from mredfearn-linux.le.imgtec.org (10.150.130.83) by HHMAIL01.hh.imgtec.org (10.100.10.21) with Microsoft SMTP Server (TLS) id 14.3.294.0; Tue, 11 Oct 2016 14:39:50 +0100 From: Matt Redfearn To: Bjorn Andersson , Ohad Ben-Cohen CC: , , "Matt Redfearn" Subject: [PATCH 2/4] remoteproc: Introduce rproc_change_firmware Date: Tue, 11 Oct 2016 14:39:43 +0100 Message-ID: <1476193185-32107-3-git-send-email-matt.redfearn@imgtec.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1476193185-32107-1-git-send-email-matt.redfearn@imgtec.com> References: <1476193185-32107-1-git-send-email-matt.redfearn@imgtec.com> MIME-Version: 1.0 X-Originating-IP: [10.150.130.83] 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 It is often desirable to be able to change the running firmware on a remote processor dynamically. This used to require a complete destruction and readdition of the struct rproc, but now that the firmware name is fixed length, it can be updated freely. So long as the remote processor is in RPROC_OFFLINE state, rproc_change_firmware() will free resources from the previous firmware and request a new one be loaded. Signed-off-by: Matt Redfearn --- drivers/remoteproc/remoteproc_core.c | 62 ++++++++++++++++++++++++++++++++ drivers/remoteproc/remoteproc_internal.h | 1 + 2 files changed, 63 insertions(+) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 48cd9d5afb69..2152b484f314 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1345,6 +1345,68 @@ static int rproc_set_firmware_name(struct rproc *rproc, const char *firmware) return 0; } +/** + * rproc_change_firmware() - change the loaded firmware on a remote processor + * @rproc: remote processor + * @firmware: name of firmware file to load, can be NULL + * + * Attempts to change the firmware loaded for a remote processor. The processor + * must be in RPROC_OFFLINE state. + * + * Any allocated resources for the exiting firmware are released, the new + * firmware name is set and then any virtio devices probed. + * + * Returns 0 on success and an appropriate error code otherwise. + * + * Note: this function initiates an asynchronous firmware loading + * context, which will look for virtio devices supported by the rproc's + * firmware. + * + * If found, those virtio devices will be created and added, so as a result + * of registering this remote processor, additional virtio drivers might be + * probed. + */ +int rproc_change_firmware(struct rproc *rproc, const char *firmware) +{ + struct device *dev = &rproc->dev; + struct rproc_vdev *rvdev, *rvtmp; + int ret; + + ret = mutex_lock_interruptible(&rproc->lock); + if (ret) { + dev_err(dev, "can't lock rproc %s: %d\n", rproc->name, ret); + return -EINVAL; + } + + if (rproc->state != RPROC_OFFLINE) { + dev_err(dev, "can't change firmware while running\n"); + ret = -EBUSY; + goto out; + } + + /* Wait for any pending firmware load */ + wait_for_completion(&rproc->firmware_loading_complete); + + /* clean up all acquired resources */ + rproc_resource_cleanup(rproc); + + /* clean up remote vdev entries */ + list_for_each_entry_safe(rvdev, rvtmp, &rproc->rvdevs, node) + rproc_remove_virtio_dev(rvdev); + + /* Free the copy of the resource table */ + kfree(rproc->cached_table); + + ret = rproc_set_firmware_name(rproc, firmware); + if (ret) + goto out; + + ret = rproc_add_virtio_devices(rproc); +out: + mutex_unlock(&rproc->lock); + return ret; +} + static struct device_type rproc_type = { .name = "remoteproc", .release = rproc_type_release, diff --git a/drivers/remoteproc/remoteproc_internal.h b/drivers/remoteproc/remoteproc_internal.h index 57e1de59bec8..837faf2677a6 100644 --- a/drivers/remoteproc/remoteproc_internal.h +++ b/drivers/remoteproc/remoteproc_internal.h @@ -49,6 +49,7 @@ struct rproc_fw_ops { void rproc_release(struct kref *kref); irqreturn_t rproc_vq_interrupt(struct rproc *rproc, int vq_id); int rproc_boot_nowait(struct rproc *rproc); +int rproc_change_firmware(struct rproc *rproc, const char *firmware); /* from remoteproc_virtio.c */ int rproc_add_virtio_dev(struct rproc_vdev *rvdev, int id);