From patchwork Tue Mar 24 21:46:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11456603 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2A81B1731 for ; Tue, 24 Mar 2020 21:46:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0D27E20735 for ; Tue, 24 Mar 2020 21:46:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="ku+B2AEO" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727747AbgCXVqW (ORCPT ); Tue, 24 Mar 2020 17:46:22 -0400 Received: from mail-pj1-f66.google.com ([209.85.216.66]:39376 "EHLO mail-pj1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727023AbgCXVqW (ORCPT ); Tue, 24 Mar 2020 17:46:22 -0400 Received: by mail-pj1-f66.google.com with SMTP id ck23so113227pjb.4 for ; Tue, 24 Mar 2020 14:46:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OyAEH5Ogm2ev5rgwlfYAIWzzoyq+qykv1xNnTlFgbyA=; b=ku+B2AEOOyrxmvBlN58Rgf+mxOpy6pPBJuv31u6NOiSeqxUdlv6InRNbC6odzvNoxz 7P3DHYZ5XLabGHpZeKgsSXgfjAAmmTenelGzoVGnqL2vhBwEnIo+dyQ2MbIE3YNGcoxW j4c8zCnTl8QB/LoP4ybFraBKb+iIu35OkbG7ofW1jJcorACVtlgEUuMFHWLhatdt/QQC IxH86amdJ7Txsr+VevPtIFfr0hA4tpu36WsKMBw6VuS4uDLZmdPkTifdnfOpMJ6uR+hf GoIz2BU38hY0XqB1RtqaYuQX6jMYxmhD2f8853zoCRPFSI1GrM+ORfH4MhRP7iWFiGkA X+xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OyAEH5Ogm2ev5rgwlfYAIWzzoyq+qykv1xNnTlFgbyA=; b=nifupguqyzjcjr4W7qroePf3NcN58brpX3T82huwROfADWe3LaWRzO/XaAhlUzrjGk E9uGN2aX4bgTclsStVRStq6JPmy7oVxOcwB5ETITG0hsHxY7ncLw6ZJcJRS9+x+jgEbk kDaW4acbWhyalfYZL4K1n9+FzvwbxJex4VazHH82hyxrKshZEtjQo/t4eqFb9yd+FR9j CsCq1mWclcY2cePa9T/1MzDuoB7zNg2AzmwEaHtUB+1UjPwo8iQH2DbFd4CTlmvL7aPp Se+Ba/tlttVfAZVIg4MgBQsmP6HaeawUFFtBzHMba9z675FfMz09vrpVMZcYwq6s5f9h n9/g== X-Gm-Message-State: ANhLgQ1qsfpFBL2szck7JwUlY0STlYjOnRv+9bxHRW45QGe8w3yHWXO9 eShlbj+nuvmrSKYsi8fRZkG5zyV6irU= X-Google-Smtp-Source: ADFU+vty9ozgiD40V2y1ZJAXbVDd23tHN3Gc6AC9+vw8i28gq9L+f4TITvGt246q+vJw8uyKe1nRSw== X-Received: by 2002:a17:90a:e50e:: with SMTP id t14mr7432906pjy.98.1585086381651; Tue, 24 Mar 2020 14:46:21 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id y131sm17070240pfb.78.2020.03.24.14.46.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Mar 2020 14:46:21 -0700 (PDT) From: Mathieu Poirier To: bjorn.andersson@linaro.org Cc: ohad@wizery.com, loic.pallardy@st.com, s-anna@ti.com, peng.fan@nxp.com, arnaud.pouliquen@st.com, fabien.dessenne@st.com, linux-remoteproc@vger.kernel.org Subject: [PATCH v2 15/17] remoteproc: Correctly deal with MCU synchronisation when changing FW image Date: Tue, 24 Mar 2020 15:46:01 -0600 Message-Id: <20200324214603.14979-16-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200324214603.14979-1-mathieu.poirier@linaro.org> References: <20200324214603.14979-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 Sender: linux-remoteproc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org This patch prevents the firmware image from being displayed or changed when the remoteproc core is synchronising with an MCU. This is needed since there is no guarantee about the nature of the firmware image that is loaded by the external entity. Signed-off-by: Mathieu Poirier --- drivers/remoteproc/remoteproc_sysfs.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/drivers/remoteproc/remoteproc_sysfs.c b/drivers/remoteproc/remoteproc_sysfs.c index 7f8536b73295..4956577ad4b4 100644 --- a/drivers/remoteproc/remoteproc_sysfs.c +++ b/drivers/remoteproc/remoteproc_sysfs.c @@ -13,9 +13,20 @@ static ssize_t firmware_show(struct device *dev, struct device_attribute *attr, char *buf) { + ssize_t ret; struct rproc *rproc = to_rproc(dev); - return sprintf(buf, "%s\n", rproc->firmware); + /* + * In most instances there is no guarantee about the firmware + * that was loaded by the external entity. As such simply don't + * print anything. + */ + if (rproc_sync_with_mcu(rproc)) + ret = sprintf(buf, "\n"); + else + ret = sprintf(buf, "%s\n", rproc->firmware); + + return ret; } /* Change firmware name via sysfs */ @@ -33,6 +44,18 @@ static ssize_t firmware_store(struct device *dev, return -EINVAL; } + /* + * There is no point in trying to change the firmware if the MCU + * is currently running or if loading of the image is done by + * another entity. + */ + if (rproc_sync_with_mcu(rproc)) { + dev_err(dev, + "can't change firmware while synchronising with MCU\n"); + err = -EBUSY; + goto out; + } + if (rproc->state != RPROC_OFFLINE) { dev_err(dev, "can't change firmware while running\n"); err = -EBUSY;