From patchwork Tue Mar 24 21:45:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11456577 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 F327F1667 for ; Tue, 24 Mar 2020 21:46:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CC30A20735 for ; Tue, 24 Mar 2020 21:46:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="zxcFYf9D" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727747AbgCXVqJ (ORCPT ); Tue, 24 Mar 2020 17:46:09 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:41687 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727496AbgCXVqJ (ORCPT ); Tue, 24 Mar 2020 17:46:09 -0400 Received: by mail-pl1-f193.google.com with SMTP id t16so7960877plr.8 for ; Tue, 24 Mar 2020 14:46:06 -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=TWSxNFnGJBIPMEQTNGHQotLd44zttutJo5MRF9su1t4=; b=zxcFYf9D5ivs7NL1fJWU9DKvTEYRvv2+pz8u+UAwSaJicr9C1vivsK3U8ZFWHYM0X/ PeSQi/hnFbC98P2MT+0Y7gT7APcnVeKxo87s9JLBRNnZgS2qKKIe6ViVfWU68D3C6YCW GrMCgUEzJj21zOoAoA0OE3miQkoaTvqFlBBoJO+vmMxOdQWf1kuEjoJXZ/NE4Np7KFuI GcKc5b67hvrOhLi7L301Ym8F5Y68UQxdbH0wcJLlCQa2bU42sjDJ9XwVFvb+fbHsJH/4 JK9KmZUOc1NmOlyUCTPdxiPU1sSliY+SDlOVKjGwQxYCb46P4VIJOzEsthXw+7WC1BM/ jEKA== 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=TWSxNFnGJBIPMEQTNGHQotLd44zttutJo5MRF9su1t4=; b=a4lMV0anTJhPaIhaXTy8zMwJhRk/tdVpVnoYPCz/v9dZ9mGaRsUtSnVlrYKTgoJspM j7263URGwlMVZlgNhIfvQoXAQ8MBjhLinFkiKxr21CDoTA8/a/T9qV/bE/lV6A3r36yp O4kNww6Is8EmIZ2s9/jxLWkki/oX7ivuTQ6PBYZlO5u15gKStLbDonXAE3Sw/HvXmWk6 B1gB6kWGeO3e+ZaIUrFBBXxAQvpKI98nVKrQrppAvleFNsETqmlX7vfsTGGHkJ1qvTQI goAUICEJmVSv3sTB5pNiXYucdeQ5rza/h5wHxSiBtWQApEXNAkHOLDwuu1FaDMkt2Yum A9wg== X-Gm-Message-State: ANhLgQ34XANOxVOZ9fIN+4MTT7y4542bDq1XnnpyovlbbUM3BqocOoGB I1e7O63OddAgUz2ENr2YACI/SQ== X-Google-Smtp-Source: ADFU+vtSWDnZVA7UB+emoell4dW5xDcMCsyocIyJKMJ8/p4H+iXApuccMvF3ZVDQKfvCXFyny2S+pw== X-Received: by 2002:a17:902:694c:: with SMTP id k12mr57375plt.173.1585086366222; Tue, 24 Mar 2020 14:46:06 -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.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Mar 2020 14:46:05 -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 01/17] remoteproc: Add new operation and state machine for MCU synchronisation Date: Tue, 24 Mar 2020 15:45:47 -0600 Message-Id: <20200324214603.14979-2-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 Add a new rproc_ops sync_ops to support use cases where the remoteproc core is synchronisting with the MCU. When exactly to use the sync_ops is directed by the states in struct rproc_sync_states. Signed-off-by: Mathieu Poirier --- drivers/remoteproc/remoteproc_debugfs.c | 31 ++++++++++++++++++++++++ drivers/remoteproc/remoteproc_internal.h | 5 ++++ include/linux/remoteproc.h | 23 +++++++++++++++++- 3 files changed, 58 insertions(+), 1 deletion(-) diff --git a/drivers/remoteproc/remoteproc_debugfs.c b/drivers/remoteproc/remoteproc_debugfs.c index dd93cf04e17f..187bcc67f997 100644 --- a/drivers/remoteproc/remoteproc_debugfs.c +++ b/drivers/remoteproc/remoteproc_debugfs.c @@ -311,6 +311,35 @@ static const struct file_operations rproc_carveouts_ops = { .release = single_release, }; +/* Expose synchronisation states via debugfs */ +static int rproc_sync_states_show(struct seq_file *seq, void *p) +{ + struct rproc *rproc = seq->private; + + seq_printf(seq, "Sync with MCU: %s\n", + rproc->sync_with_mcu ? "true" : "false"); + seq_printf(seq, "On init: %s\n", + rproc->sync_states->on_init ? "true" : "false"); + seq_printf(seq, "After stop: %s\n", + rproc->sync_states->after_stop ? "true" : "false"); + seq_printf(seq, "After crash: %s\n", + rproc->sync_states->after_crash ? "true" : "false"); + + return 0; +} + +static int rproc_sync_states_open(struct inode *inode, struct file *file) +{ + return single_open(file, rproc_sync_states_show, inode->i_private); +} + +static const struct file_operations rproc_sync_states_ops = { + .open = rproc_sync_states_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + void rproc_remove_trace_file(struct dentry *tfile) { debugfs_remove(tfile); @@ -357,6 +386,8 @@ void rproc_create_debug_dir(struct rproc *rproc) rproc, &rproc_rsc_table_ops); debugfs_create_file("carveout_memories", 0400, rproc->dbg_dir, rproc, &rproc_carveouts_ops); + debugfs_create_file("sync_states", 0400, rproc->dbg_dir, + rproc, &rproc_sync_states_ops); } void __init rproc_init_debugfs(void) diff --git a/drivers/remoteproc/remoteproc_internal.h b/drivers/remoteproc/remoteproc_internal.h index 493ef9262411..5c93de5e00bb 100644 --- a/drivers/remoteproc/remoteproc_internal.h +++ b/drivers/remoteproc/remoteproc_internal.h @@ -63,6 +63,11 @@ struct resource_table *rproc_elf_find_loaded_rsc_table(struct rproc *rproc, struct rproc_mem_entry * rproc_find_carveout_by_name(struct rproc *rproc, const char *name, ...); +static inline bool rproc_sync_with_mcu(struct rproc *rproc) +{ + return rproc->sync_with_mcu; +} + static inline int rproc_fw_sanity_check(struct rproc *rproc, const struct firmware *fw) { diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h index 16ad66683ad0..d115e47d702d 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -353,6 +353,21 @@ enum rsc_handling_status { RSC_IGNORED = 1, }; +/** + * struct rproc_sync_states - platform specific states indicating which + * rproc_ops to use at specific times during + * the MCU lifecycle. + * @on_init: true if synchronising with MCU at system initialisation time + * @after_stop: true if synchronising with MCU after stopped from the + * command line + * @after_crash: true if synchonising with MCU after the MCU has crashed + */ +struct rproc_sync_states { + bool on_init; + bool after_stop; + bool after_crash; +}; + /** * struct rproc_ops - platform-specific device handlers * @start: power on the device and boot it @@ -456,6 +471,9 @@ struct rproc_dump_segment { * @firmware: name of firmware file to be loaded * @priv: private data which belongs to the platform-specific rproc module * @ops: platform-specific start/stop rproc handlers + * @sync_ops: paltform-specific start/stop rproc handlers when + * synchronising with a remote processor. + * @sync_states: Determine the rproc_ops to choose in specific states. * @dev: virtual device for refcounting and common remoteproc behavior * @power: refcount of users who need this rproc powered up * @state: state of the device @@ -479,6 +497,7 @@ struct rproc_dump_segment { * @table_sz: size of @cached_table * @has_iommu: flag to indicate if remote processor is behind an MMU * @auto_boot: flag to indicate if remote processor should be auto-started + * @sync_with_mcu: true if currently synchronising with MCU * @dump_segments: list of segments in the firmware * @nb_vdev: number of vdev currently handled by rproc */ @@ -488,7 +507,8 @@ struct rproc { const char *name; char *firmware; void *priv; - struct rproc_ops *ops; + struct rproc_ops *ops, *sync_ops; + struct rproc_sync_states *sync_states; struct device dev; atomic_t power; unsigned int state; @@ -512,6 +532,7 @@ struct rproc { size_t table_sz; bool has_iommu; bool auto_boot; + bool sync_with_mcu; struct list_head dump_segments; int nb_vdev; }; From patchwork Tue Mar 24 21:45:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11456575 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 1A18A139A for ; Tue, 24 Mar 2020 21:46:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F081C20735 for ; Tue, 24 Mar 2020 21:46:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="KcV9y+P6" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727613AbgCXVqI (ORCPT ); Tue, 24 Mar 2020 17:46:08 -0400 Received: from mail-pj1-f67.google.com ([209.85.216.67]:54023 "EHLO mail-pj1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727023AbgCXVqI (ORCPT ); Tue, 24 Mar 2020 17:46:08 -0400 Received: by mail-pj1-f67.google.com with SMTP id l36so114496pjb.3 for ; Tue, 24 Mar 2020 14:46:07 -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=5shZRfndISXfBha4KClPHdNwLMErJ5rqxlgWFeBzywE=; b=KcV9y+P6sG8Dm3u1f2FKxOoovt7sm9RoqC36GrgkerWs9vC8u1m2vnMo1FEA2VE8Yf q4rVilECjPTydX3wgBrRbSCDFjb+rE3hYH1FcXASK3bN8cZH/g3ETaJE2Ksa/+infgU/ SGoMp0ijYIJXKSNZPldD/6dOh1rXpjudi/HkhiFj/Y5CZgiXBdm5brtSNtRsFwAp0cH9 VC6XgB+YEfZLl7f2fEdT0UhfupbVZAwhTuVo1ZQjuspPJ3iG0bJr+17zJ+Cr3aGDNII0 4CxxUmcIvNxFZq6Owk4vsfsAt4eRkjHrEq2gbpq7SoUddlxTIHHGWs/QnoxMcfb7LR+z 3Jmg== 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=5shZRfndISXfBha4KClPHdNwLMErJ5rqxlgWFeBzywE=; b=WdHT5YtfrvVCiA0DhVSdEwJrSR99J9JjYEztBXZ/ZjCF36PDeEjII+NVjqCxPfXhql iZUUq5hGa78hO1uiHNQmx3Utjt2eTvjUEPwsq8KDDvE/ZBu2p3rp4Fxwgx9JXatJuQ2y R91Y5qjKVAExWv78PvYBt+146ZkmJywIiRaz23neyw5xjLQIYzbLlM6BZysdtCsygXFv x9c7CSE5MOXQRweWxYqBL0DKzt0pM1n8UoM1cUC34DbDMwYDeZdGkG6oh7FBWKwHY7x5 jNDxfdGqqyIb10mS0nfeTIzFCrBMehRW711h5qgtERKPsXY9L80vHMyNrfZqBih6+W0/ LDwA== X-Gm-Message-State: ANhLgQ1mwAYRgU4sP1bL0T4i6/fOalUMhw7uxxRNIPfn0zmjZ6DfbP7E UsEIJfgK4z5iL8zOdnc9cpeqzA== X-Google-Smtp-Source: ADFU+vswBINdAa+zXGEKoz3fdVV99/9cCFPimm+nMfTd3XBUjAE8yEb6jL5an4OuKd2rS8F0oSowmQ== X-Received: by 2002:a17:902:7488:: with SMTP id h8mr83004pll.264.1585086367389; Tue, 24 Mar 2020 14:46:07 -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.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Mar 2020 14:46:06 -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 02/17] remoteproc: Introduce function rproc_set_mcu_sync_state() Date: Tue, 24 Mar 2020 15:45:48 -0600 Message-Id: <20200324214603.14979-3-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 Introduce function rproc_set_mcu_sync_state() to set the synchronisation state of the MCU at various stages of the lifecycle process. Signed-off-by: Mathieu Poirier --- drivers/remoteproc/remoteproc_internal.h | 38 ++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/drivers/remoteproc/remoteproc_internal.h b/drivers/remoteproc/remoteproc_internal.h index 5c93de5e00bb..73ea32df0156 100644 --- a/drivers/remoteproc/remoteproc_internal.h +++ b/drivers/remoteproc/remoteproc_internal.h @@ -24,6 +24,26 @@ struct rproc_debug_trace { struct rproc_mem_entry trace_mem; }; +/* + * enum rproc_sync_states - remote processsor sync states + * @RPROC_SYNC_STATE_INIT state to use when the remoteproc core + * is initialising. + * @RPROC_SYNC_STATE_SHUTDOWN state to use after the remoteproc core + * has shutdown (rproc_shutdown()) the MCU. + * @RPROC_SYNC_STATE_CRASHED state to use after the MCU has crashed but + * has not been recovered by the remoteproc + * core yet. + * + * Keeping these separate from the enum rproc_state in order to avoid + * introducing coupling between the state of the MCU and the synchronisation + * operation to use. + */ +enum rproc_mcu_sync_states { + RPROC_SYNC_STATE_INIT, + RPROC_SYNC_STATE_SHUTDOWN, + RPROC_SYNC_STATE_CRASHED, +}; + /* from remoteproc_core.c */ void rproc_release(struct kref *kref); irqreturn_t rproc_vq_interrupt(struct rproc *rproc, int vq_id); @@ -68,6 +88,24 @@ static inline bool rproc_sync_with_mcu(struct rproc *rproc) return rproc->sync_with_mcu; } +static inline void rproc_set_mcu_sync_state(struct rproc *rproc, + unsigned int state) +{ + switch (state) { + case RPROC_SYNC_STATE_INIT: + rproc->sync_with_mcu = rproc->sync_states->on_init; + break; + case RPROC_SYNC_STATE_SHUTDOWN: + rproc->sync_with_mcu = rproc->sync_states->after_stop; + break; + case RPROC_SYNC_STATE_CRASHED: + rproc->sync_with_mcu = rproc->sync_states->after_crash; + break; + default: + break; + } +} + static inline int rproc_fw_sanity_check(struct rproc *rproc, const struct firmware *fw) { From patchwork Tue Mar 24 21:45:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11456579 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 A74E41667 for ; Tue, 24 Mar 2020 21:46:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 89E0A20735 for ; Tue, 24 Mar 2020 21:46:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="Eg2vGEA3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727846AbgCXVqK (ORCPT ); Tue, 24 Mar 2020 17:46:10 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:46964 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727023AbgCXVqK (ORCPT ); Tue, 24 Mar 2020 17:46:10 -0400 Received: by mail-pl1-f193.google.com with SMTP id s23so902910plq.13 for ; Tue, 24 Mar 2020 14:46:09 -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=r/B04jVPNZTcs3aQnGZX3vp28LZDLa2t2zmjCbTooYI=; b=Eg2vGEA3BuijCKI7fh2trvPm8rXRmlL1oRcujHLaSN3plb0Wx0XJekyhtDbWOd+fp8 +zlQayjEfkgF0Q3r2WlxXkvq8Q+fWZlwV0/eg0eb9jKfN72Q8rdOqLX20CoFVinchecF 0Q0d5eqM7qgVMF1nVg/6H4LXq1p5GxfsJ6ePvTIviZtgQf50m007ha9PVR1VzVaQoEA/ Vb0uAkI/6UE5WU9qLBZRXsMsb+hh0OFI4+aIwRhVzP7yMQ4cf886+m8WfaedNg6U/6UR gZPlfYKQfZHfF1WlXFGozhX2PUSvU3Y2lp25EF3N4DC6HPWWWer+1Tuh9Zikme1jCNf5 7WYg== 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=r/B04jVPNZTcs3aQnGZX3vp28LZDLa2t2zmjCbTooYI=; b=SU1W7lU+yC2aw/BtvKa2H52cSu9RVcy+5CXKXGcb+q2di+JyvXvE1RmN0q2I15uWgk KPcmamKZSU9SWtR8E7YM35nhSD3YrFBVqW/DLO7ckSZBBHiGMBVUpY+BbzfZjZ+oRTTL v/fskXBvH3Fx6SwHc5YZvxDyasSQNsZw713loLlHVnvMB3Zw/S95YTkKikpESN0g28wP ifBwUVydw8R24C5/XlYtvRC07loFBusDCyDWTX/KWEl7JluJqozaE0glimQrqF7r6MZH gQlrXGZi3th+aM6afhWUuop/gZucLyihdRr5fHoX9jGxG0+YMqGlWcMKGgGogNCK/l1x lJKg== X-Gm-Message-State: ANhLgQ14F6iCFsOGpqzj11ytgIi3AbzLG6VfLwqbJfzK6FloIvoEuuq/ K1PRdI6zMwQakYaV6y7ex2Gfzg== X-Google-Smtp-Source: ADFU+vuqWdebrsruwwTRck+Y9vXqdtRLcft+MI/d8jgAiAeFQFZHFo+grPHxB8nxydJZWqTeTmyzxQ== X-Received: by 2002:a17:902:d204:: with SMTP id t4mr81824ply.228.1585086368457; Tue, 24 Mar 2020 14:46:08 -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.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Mar 2020 14:46:08 -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 03/17] remoteproc: Split firmware name allocation from rproc_alloc() Date: Tue, 24 Mar 2020 15:45:49 -0600 Message-Id: <20200324214603.14979-4-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 Make the firmware name allocation a function on its own in order to introduce more flexibility to function rproc_alloc(). Signed-off-by: Mathieu Poirier --- drivers/remoteproc/remoteproc_core.c | 62 +++++++++++++++++----------- 1 file changed, 39 insertions(+), 23 deletions(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 097f33e4f1f3..c0871f69929b 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1962,6 +1962,36 @@ static const struct device_type rproc_type = { .release = rproc_type_release, }; +static int rproc_alloc_firmware(struct rproc *rproc, + const char *name, const char *firmware) +{ + char *p, *template = "rproc-%s-fw"; + int name_len; + + if (!rproc || !name) + return -EINVAL; + + if (!firmware) { + /* + * If the caller didn't pass in a firmware name then + * construct a default name. + */ + name_len = strlen(name) + strlen(template) - 2 + 1; + p = kmalloc(name_len, GFP_KERNEL); + if (!p) + return -ENOMEM; + snprintf(p, name_len, template, name); + } else { + p = kstrdup(firmware, GFP_KERNEL); + if (!p) + return -ENOMEM; + } + + rproc->firmware = p; + + return 0; +} + /** * rproc_alloc() - allocate a remote processor handle * @dev: the underlying device @@ -1990,42 +2020,24 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, const char *firmware, int len) { struct rproc *rproc; - char *p, *template = "rproc-%s-fw"; - int name_len; if (!dev || !name || !ops) return NULL; - if (!firmware) { - /* - * If the caller didn't pass in a firmware name then - * construct a default name. - */ - name_len = strlen(name) + strlen(template) - 2 + 1; - p = kmalloc(name_len, GFP_KERNEL); - if (!p) - return NULL; - snprintf(p, name_len, template, name); - } else { - p = kstrdup(firmware, GFP_KERNEL); - if (!p) - return NULL; - } - rproc = kzalloc(sizeof(struct rproc) + len, GFP_KERNEL); - if (!rproc) { - kfree(p); + if (!rproc) return NULL; - } + + if (rproc_alloc_firmware(rproc, name, firmware)) + goto free_rproc; rproc->ops = kmemdup(ops, sizeof(*ops), GFP_KERNEL); if (!rproc->ops) { - kfree(p); + kfree(rproc->firmware); kfree(rproc); return NULL; } - rproc->firmware = p; rproc->name = name; rproc->priv = &rproc[1]; rproc->auto_boot = true; @@ -2073,6 +2085,10 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, rproc->state = RPROC_OFFLINE; return rproc; + +free_rproc: + kfree(rproc); + return NULL; } EXPORT_SYMBOL(rproc_alloc); From patchwork Tue Mar 24 21:45:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11456581 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 52238139A for ; Tue, 24 Mar 2020 21:46:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3460F20735 for ; Tue, 24 Mar 2020 21:46:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="dMa9+bsh" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727023AbgCXVqL (ORCPT ); Tue, 24 Mar 2020 17:46:11 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:37643 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727496AbgCXVqK (ORCPT ); Tue, 24 Mar 2020 17:46:10 -0400 Received: by mail-pg1-f196.google.com with SMTP id a32so106206pga.4 for ; Tue, 24 Mar 2020 14:46:10 -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=SyGNEy80rIASHKptaoZBDFRWFD26JE8tajXEfFmZUNs=; b=dMa9+bshXwAoSHMdHxTd/WhFunA87+SrSIJeg8sgJ6RnQV8fnO9hPBHt5ugjOoYR+V d5810Y7J2kLN+yz74eTmJ86YTjn+LTXs0XhiHXtjB/MoGCa7OGj1oRfSrrIN1YRZ843/ fPTyyTySo/ELXv3+3mP+5AjypG4FOqoMpmbEMDtSFCXIaDIC+S1j5xyoxfmOLn8YmDvC /+rXRawVIE1VmeUW+M2QJf7QZ3Ih5sVnL/yi0lT1HY14wS0ie9gDsyGJoO7VkG0a35WM N/msUAqwGiON2JH9pEP0TJkvUsQR8K+/Sl/mJSUprzCbw/ZLb1RqRrkeWCJfTrYIZ3jT AnuA== 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=SyGNEy80rIASHKptaoZBDFRWFD26JE8tajXEfFmZUNs=; b=s359+K2eJgiOUCN72UdAKD80IMxpfDL8EI/KVD8Pk0fCvfvVi5tfo+LfXuXJ5QvT/T d+uRGYJZeRZmdVZPCKuR7E02pAo7f44BoG6TTjCAeq8qRYTlg5yHHQfwdhhw8SxTetRo QKK4ZYaCb/SgpTXiFOjuZy5U07HGkRPKD9zeYfmBTqC/bvOc46md03guKTZs3XY81Xzg rdIe7eDNGlka19hZecdQ+08aA05Eyj9bWudEhjh8XNyae+0WVlVeJ85WcQvAz3EBvef0 vmjCEcA8ecTZJSDaGVHHyRc9htxcKXIN64xMFhj44Zjl+Td4JEKuvL79HG5njehCOcLW 34Uw== X-Gm-Message-State: ANhLgQ3hKJdVCImcn2+EGixoQzygKu98y9oV0GE//Rdy0y2WR0Sf07nD TZ2E6pwBCYRnLZS8Ds+Wg5S2QpAOsWo= X-Google-Smtp-Source: ADFU+vsmPg/XKVUqu/uf9NfrZ/qPB1KL42SAJ3OriL7u2EXSc5HThVgABy81sYpa90yOfXp9M+5H5Q== X-Received: by 2002:a62:6503:: with SMTP id z3mr32439163pfb.232.1585086369525; Tue, 24 Mar 2020 14:46:09 -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.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Mar 2020 14:46:09 -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 04/17] remoteproc: Split rproc_ops allocation from rproc_alloc() Date: Tue, 24 Mar 2020 15:45:50 -0600 Message-Id: <20200324214603.14979-5-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 Make the rproc_ops allocation a function on its own in order to introduce more flexibility to function rproc_alloc(). Signed-off-by: Mathieu Poirier --- drivers/remoteproc/remoteproc_core.c | 45 ++++++++++++++++++---------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index c0871f69929b..d22e557f27ed 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1992,6 +1992,32 @@ static int rproc_alloc_firmware(struct rproc *rproc, return 0; } +static int rproc_alloc_ops(struct rproc *rproc, const struct rproc_ops *ops) +{ + if (!rproc) + return -EINVAL; + + /* Nothing to do if there isn't and ops to work with */ + if (!ops) + return 0; + + rproc->ops = kmemdup(ops, sizeof(*ops), GFP_KERNEL); + if (!rproc->ops) + return -ENOMEM; + + /* Default to ELF loader if no load function is specified */ + if (!rproc->ops->load) { + rproc->ops->load = rproc_elf_load_segments; + rproc->ops->parse_fw = rproc_elf_load_rsc_table; + rproc->ops->find_loaded_rsc_table = + rproc_elf_find_loaded_rsc_table; + rproc->ops->sanity_check = rproc_elf_sanity_check; + rproc->ops->get_boot_addr = rproc_elf_get_boot_addr; + } + + return 0; +} + /** * rproc_alloc() - allocate a remote processor handle * @dev: the underlying device @@ -2031,12 +2057,8 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, if (rproc_alloc_firmware(rproc, name, firmware)) goto free_rproc; - rproc->ops = kmemdup(ops, sizeof(*ops), GFP_KERNEL); - if (!rproc->ops) { - kfree(rproc->firmware); - kfree(rproc); - return NULL; - } + if (rproc_alloc_ops(rproc, ops)) + goto free_firmware; rproc->name = name; rproc->priv = &rproc[1]; @@ -2060,15 +2082,6 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, atomic_set(&rproc->power, 0); - /* Default to ELF loader if no load function is specified */ - if (!rproc->ops->load) { - rproc->ops->load = rproc_elf_load_segments; - rproc->ops->parse_fw = rproc_elf_load_rsc_table; - rproc->ops->find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table; - rproc->ops->sanity_check = rproc_elf_sanity_check; - rproc->ops->get_boot_addr = rproc_elf_get_boot_addr; - } - mutex_init(&rproc->lock); idr_init(&rproc->notifyids); @@ -2086,6 +2099,8 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, return rproc; +free_firmware: + kfree(rproc->firmware); free_rproc: kfree(rproc); return NULL; From patchwork Tue Mar 24 21:45:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11456583 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 238EB139A for ; Tue, 24 Mar 2020 21:46:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 05D4B20735 for ; Tue, 24 Mar 2020 21:46:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="gbCO4JLw" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727753AbgCXVqL (ORCPT ); Tue, 24 Mar 2020 17:46:11 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:40070 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727496AbgCXVqL (ORCPT ); Tue, 24 Mar 2020 17:46:11 -0400 Received: by mail-pl1-f193.google.com with SMTP id h11so7960407plk.7 for ; Tue, 24 Mar 2020 14:46:11 -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=8GchUXqImjod0MIPYLIdyQi94IM61hiNQIO0qzQ9Pt4=; b=gbCO4JLwY6TDXVCmIuMsusgmuR9aUXHMyKm9EkFu2hY3DqnfwghoaiV5NCVfkvx21a 5wL9IkoZxYfS+vRqX1y4PbzVSD3nGXvLhrRXGUIBJvTP01tJXKFIuCGpTPBFDgPOEJ9x FMSo8/J7IFg9WSXSg89rNF7/X13K45snH55J/l7f6LcsD0/9d+MpLZRpnlFAvfa5qpCS RAVW0E3gmevoQD4XnfCLAJ/Bo3otuJRMAfNeYpcWMHu/eulNUwsvwlld9gZuaV5uyk4D piTqHuwlgKHzTayWeHKJwx+rvGpizGTBF77HZF1Yv+6KlD9zIsF4mZUMMGH7Y6Ty7dS8 oNdA== 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=8GchUXqImjod0MIPYLIdyQi94IM61hiNQIO0qzQ9Pt4=; b=fLOal5FVCw87H7J7kHrBoZZ0ervcLUaXgtamANCFZHZ/OjLZGadkGNKQ8iaZOth+Tj wbQK5UracKrPgM6QZvswpgSyqM0nC3u8b46qNnyvZfXxCkOVL8Vx5g23JFAq2kmMLpCX NzDb89FAszzT1PEPARxNLtIE1Y8K0OGQJ7YdJyFFb4nMl8Xpzg2hUoWRylMOGVMeXOxg d/UZC8Y64wn1OHRJOSB4El/3dU7rBsfMyPEY0aM5fqj/r+o8gtworuNM2BpG9NDHdYqn XVL4pBYluSgyJ2W8SuAZrVHgAMKqBB9bcLfhrFl09lK8LivGzZp34J/C5zctmaKrWUBQ ApqQ== X-Gm-Message-State: ANhLgQ0BdsuCZYMmaOQYjGSBnYB2DudnIwYVG+zEzfcLjh46TFmCM4rS JIdc9veK93kwyg4Z9MWmr5vSKA== X-Google-Smtp-Source: ADFU+vu1HNZVKwVfMqd+Tu9OrwbYLlrIWjibYKA9JsBl2ZRQ4ch4xpFbYLQni8BMYZZc5b9BzgXLEw== X-Received: by 2002:a17:90a:db0e:: with SMTP id g14mr7154534pjv.186.1585086370615; Tue, 24 Mar 2020 14:46:10 -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.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Mar 2020 14:46:10 -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 05/17] remoteproc: Get rid of tedious error path Date: Tue, 24 Mar 2020 15:45:51 -0600 Message-Id: <20200324214603.14979-6-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 Get rid of tedious error management by moving firmware and operation allocation after calling device_initialize(). That way we take advantage of the automatic call to rproc_type_release() to cleanup after ourselves when put_device() is called. Signed-off-by: Mathieu Poirier --- drivers/remoteproc/remoteproc_core.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index d22e557f27ed..ee277bc5556c 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -2054,12 +2054,6 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, if (!rproc) return NULL; - if (rproc_alloc_firmware(rproc, name, firmware)) - goto free_rproc; - - if (rproc_alloc_ops(rproc, ops)) - goto free_firmware; - rproc->name = name; rproc->priv = &rproc[1]; rproc->auto_boot = true; @@ -2070,12 +2064,17 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, rproc->dev.class = &rproc_class; rproc->dev.driver_data = rproc; + if (rproc_alloc_firmware(rproc, name, firmware)) + goto out; + + if (rproc_alloc_ops(rproc, ops)) + goto out; + /* Assign a unique device index and name */ rproc->index = ida_simple_get(&rproc_dev_index, 0, 0, GFP_KERNEL); if (rproc->index < 0) { dev_err(dev, "ida_simple_get failed: %d\n", rproc->index); - put_device(&rproc->dev); - return NULL; + goto out; } dev_set_name(&rproc->dev, "remoteproc%d", rproc->index); @@ -2098,11 +2097,8 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, rproc->state = RPROC_OFFLINE; return rproc; - -free_firmware: - kfree(rproc->firmware); -free_rproc: - kfree(rproc); +out: + put_device(&rproc->dev); return NULL; } EXPORT_SYMBOL(rproc_alloc); From patchwork Tue Mar 24 21:45:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11456585 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 856EA1667 for ; Tue, 24 Mar 2020 21:46:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 63F7520735 for ; Tue, 24 Mar 2020 21:46:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="U3Sw+BPD" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728093AbgCXVqN (ORCPT ); Tue, 24 Mar 2020 17:46:13 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:41694 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727496AbgCXVqN (ORCPT ); Tue, 24 Mar 2020 17:46:13 -0400 Received: by mail-pl1-f196.google.com with SMTP id t16so7960975plr.8 for ; Tue, 24 Mar 2020 14:46:12 -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=tFxiWY+kpD9874R08QypyBmwovyVbSqxX8VrEMv/frg=; b=U3Sw+BPDHoIngWOvz6mMg/pNvs6kzx09JYkMiHCX3n+D7oJTPBU4Hv9x9CA3rn1Fgw 74TRVbrUQd8xgBjT2EAZMz/3D6IYCzpH6xiLfQIA/MGLNSkQKEnlV2NJnb9Uahg3/uEy phW9N20KNgmn1fqOxzY+tPGATBTXVGrkotaT4IbTDg1hiRhRyz8w1xtr0NIyQMcgvl0L /DSR7w1XVmcpCQPiNvtx/a7GvvwSRLZYX7hWw+LUV+hFgYqr6XN5e5ad/zSkSAkymdqW 9fJg8gQlDxJrM3yyxImXGAcV5tHk9j38jLSc3Q3gGPL+12jDbTo6fVUcxA65C1AvU4ks Jfhg== 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=tFxiWY+kpD9874R08QypyBmwovyVbSqxX8VrEMv/frg=; b=Z8N0sS/RsBH/KTzT1wgy/ucBD7v1uvP3MdvPKvpcyaBhVnOLoeZRdfMuyv8PLAxDBH WZdxQS5qe/XD/zeJf2mHLi4IrP6FRj4fB78aa7qDzshjEduKdpFp8GgTHlircVSOBdm1 y068yW+SqjpcYjdju2PRf+vM+ZAzyyswGQhcVE8xhTuLktSvNN89ccjno/CctG8ne0G3 AM5Zf7aFusSeEv/6lP3u0WO2KYvzNB6XUdidA8gweFpbkh5WZ7/ukzwwcqGwDluBO2S+ 1vNMyk084JoR4Dw+8soFkjzxgPbMuibr0mgc+lQvMO3vZbQ21r366SvFZpmMIDNADdbI HUHA== X-Gm-Message-State: ANhLgQ27rJu7XhSmRZfxv6f7jUakPvKJXd54y1F49UpV2ncUTN4+hxSC gwTS1eI5NYLaDBB9zlZXU2oMJQ== X-Google-Smtp-Source: ADFU+vs5DjXBMVZA0ts8TKazTWYB6TRYdbFXAQPeEUdrbFhFEQqQ9Lc51682BJXJ7jMhGJndXmt8jQ== X-Received: by 2002:a17:90a:2149:: with SMTP id a67mr7858031pje.190.1585086371678; Tue, 24 Mar 2020 14:46:11 -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.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Mar 2020 14:46:11 -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 06/17] remoteproc: Introduce function rproc_alloc_internals() Date: Tue, 24 Mar 2020 15:45:52 -0600 Message-Id: <20200324214603.14979-7-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 In preparation to allocate the synchronisation operation and state machine, spin off a new function in order to keep rproc_alloc() as clean as possible. Signed-off-by: Mathieu Poirier --- drivers/remoteproc/remoteproc_core.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index ee277bc5556c..9da245734db6 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -2018,6 +2018,26 @@ static int rproc_alloc_ops(struct rproc *rproc, const struct rproc_ops *ops) return 0; } +static int rproc_alloc_internals(struct rproc *rproc, const char *name, + const struct rproc_ops *boot_ops, + const char *firmware, int len) +{ + int ret; + + /* We have a boot_ops so allocate firmware name and operations */ + if (boot_ops) { + ret = rproc_alloc_firmware(rproc, name, firmware); + if (ret) + return ret; + + ret = rproc_alloc_ops(rproc, boot_ops); + if (ret) + return ret; + } + + return 0; +} + /** * rproc_alloc() - allocate a remote processor handle * @dev: the underlying device @@ -2064,10 +2084,8 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, rproc->dev.class = &rproc_class; rproc->dev.driver_data = rproc; - if (rproc_alloc_firmware(rproc, name, firmware)) - goto out; - - if (rproc_alloc_ops(rproc, ops)) + if (rproc_alloc_internals(rproc, name, ops, + firmware, len)) goto out; /* Assign a unique device index and name */ From patchwork Tue Mar 24 21:45:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11456587 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 9B7981667 for ; Tue, 24 Mar 2020 21:46:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7524C20735 for ; Tue, 24 Mar 2020 21:46:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="rtzE/5M9" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728138AbgCXVqO (ORCPT ); Tue, 24 Mar 2020 17:46:14 -0400 Received: from mail-pj1-f65.google.com ([209.85.216.65]:35746 "EHLO mail-pj1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727496AbgCXVqO (ORCPT ); Tue, 24 Mar 2020 17:46:14 -0400 Received: by mail-pj1-f65.google.com with SMTP id g9so122032pjp.0 for ; Tue, 24 Mar 2020 14:46:13 -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=QbjBu0ATLM3BmpV8WHI5IEU2v4grscwwtqHk7fsIIQw=; b=rtzE/5M99nDuAKNz3LxYarhD+443e/TDBme413kyR5bwiN6rD/EUrKarI4cNSHsqOT GSZy/dg3bWD3VE9kbfIQC09BCjGZnMvPss5uHvEvnUcSKlNoz+59AJYJUZTGCwYjJW2T lOiU1RLR2fHdKlyMhDL9gA4gS4ZtgYej5jZrBuibpZlYygv0+tWcKROj2m9AGL4wFT0d /W2jbm2kIXFwzFFf1y/YJT6Xk2mnWF2ZYVU0gpcRo0qiFGIg7Vg5kpZGV29o4UC8H7fw 0Zva9rmJKZnJ5QWMXC1jnPRZkoOLmQoz+s/NMlRSFIbr3yJnLFRRCwNx/H5C5TLZytSv h9wA== 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=QbjBu0ATLM3BmpV8WHI5IEU2v4grscwwtqHk7fsIIQw=; b=MNV610yd5oB3vFu9cL2qfdUHrQB3KEImZRM9dhDh1R75F3TAVcMlhCKi0p5+Z0S7vp VPdLUl3LMjEXTOFvPO3Yju7Mb80NBH8klwVdtFJA91x3EBLKlH4MV1f+NESV0HW6h0D8 nySTMHmBegY7+XeIjlUrXX+J9WO+LGXjhWqdNn5rsiZC9OvzjjHK0eHHbtq7TykP14mi 6PWDIldKgpvcUVLug8ZZC0VHF5JiL45GrnTXkUN9KzegDSMS20/xLNa5VUhRTZ3DHefe a74QJkIQuaF9u+N2r1bB36CgJ2zCSNdicFpRgeSbaJw4fXVHjv/xbuz1v5F1GRxz+K6q dmJw== X-Gm-Message-State: ANhLgQ2t5dP2F1KF60oZcDmJT3VyTjWDIGgzRW8TuYDbalnl95eZtUWo KylAWczTj3f9LT9qH2JySNGFdw== X-Google-Smtp-Source: ADFU+vvnEstv7qRIiHdT9l4U713r1pBfPe+bAQMbQFDRnJLSJCTg8nRz/maKKpEmWg8k8HP3GOHeIQ== X-Received: by 2002:a17:90a:d101:: with SMTP id l1mr8104205pju.130.1585086372781; Tue, 24 Mar 2020 14:46:12 -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.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Mar 2020 14:46:12 -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 07/17] remoteproc: Introduce function rproc_alloc_state_machine() Date: Tue, 24 Mar 2020 15:45:53 -0600 Message-Id: <20200324214603.14979-8-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 Introducing new function rproc_alloc_state_machine() to allocate the MCU synchronisation operations and position it as the central remoteproc core allocation function. Signed-off-by: Mathieu Poirier --- drivers/remoteproc/remoteproc_core.c | 84 +++++++++++++++++++++++++--- include/linux/remoteproc.h | 5 ++ 2 files changed, 81 insertions(+), 8 deletions(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 9da245734db6..02dbb826aa29 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1954,6 +1954,7 @@ static void rproc_type_release(struct device *dev) kfree(rproc->firmware); kfree(rproc->ops); + kfree(rproc->sync_ops); kfree(rproc); } @@ -2018,12 +2019,34 @@ static int rproc_alloc_ops(struct rproc *rproc, const struct rproc_ops *ops) return 0; } +static int rproc_alloc_sync_ops(struct rproc *rproc, + const struct rproc_ops *sync_ops) +{ + /* + * Given the unlimited amount of possibilities when + * synchronising with an MCU, no constraints are imposed + * on sync_ops. + */ + rproc->sync_ops = kmemdup(sync_ops, + sizeof(*sync_ops), GFP_KERNEL); + if (!rproc->sync_ops) + return -ENOMEM; + + return 0; +} + static int rproc_alloc_internals(struct rproc *rproc, const char *name, const struct rproc_ops *boot_ops, + const struct rproc_ops *sync_ops, + struct rproc_sync_states *sync_states, const char *firmware, int len) { int ret; + /* We need at least a boot or a sync ops. */ + if (!boot_ops && !sync_ops) + return -EINVAL; + /* We have a boot_ops so allocate firmware name and operations */ if (boot_ops) { ret = rproc_alloc_firmware(rproc, name, firmware); @@ -2035,14 +2058,23 @@ static int rproc_alloc_internals(struct rproc *rproc, const char *name, return ret; } + /* Allocate a sync_ops if need be */ + if (sync_ops) { + ret = rproc_alloc_sync_ops(rproc, sync_ops); + if (ret) + return ret; + } + return 0; } /** - * rproc_alloc() - allocate a remote processor handle + * rproc_alloc_state_machine() - allocate a remote processor handle * @dev: the underlying device * @name: name of this remote processor * @ops: platform-specific handlers (mainly start/stop) + * @sync_ops: platform-specific handlers for synchronising with MCU + * @sync_states: states in which @ops and @sync_ops are to be used * @firmware: name of firmware file to load, can be NULL * @len: length of private data needed by the rproc driver (in bytes) * @@ -2061,13 +2093,15 @@ static int rproc_alloc_internals(struct rproc *rproc, const char *name, * Note: _never_ directly deallocate @rproc, even if it was not registered * yet. Instead, when you need to unroll rproc_alloc(), use rproc_free(). */ -struct rproc *rproc_alloc(struct device *dev, const char *name, - const struct rproc_ops *ops, - const char *firmware, int len) +struct rproc *rproc_alloc_state_machine(struct device *dev, const char *name, + const struct rproc_ops *ops, + const struct rproc_ops *sync_ops, + struct rproc_sync_states *sync_states, + const char *firmware, int len) { struct rproc *rproc; - if (!dev || !name || !ops) + if (!dev || !name) return NULL; rproc = kzalloc(sizeof(struct rproc) + len, GFP_KERNEL); @@ -2084,8 +2118,8 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, rproc->dev.class = &rproc_class; rproc->dev.driver_data = rproc; - if (rproc_alloc_internals(rproc, name, ops, - firmware, len)) + if (rproc_alloc_internals(rproc, name, ops, sync_ops, + sync_states, firmware, len)) goto out; /* Assign a unique device index and name */ @@ -2119,7 +2153,41 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, put_device(&rproc->dev); return NULL; } -EXPORT_SYMBOL(rproc_alloc); +EXPORT_SYMBOL(rproc_alloc_state_machine); + +/** + * rproc_alloc() - allocate a remote processor handle + * @dev: the underlying device + * @name: name of this remote processor + * @ops: platform-specific handlers (mainly start/stop) + * @firmware: name of firmware file to load, can be NULL + * @len: length of private data needed by the rproc driver (in bytes) + * + * Allocates a new remote processor handle, but does not register + * it yet. if @firmware is NULL, a default name is used. + * + * This function should be used by rproc implementations during initialization + * of the remote processor. + * + * After creating an rproc handle using this function, and when ready, + * implementations should then call rproc_add() to complete + * the registration of the remote processor. + * + * On success the new rproc is returned, and on failure, NULL. + * + * Note: _never_ directly deallocate @rproc, even if it was not registered + * yet. Instead, when you need to unroll rproc_alloc(), use rproc_free(). + */ +struct rproc *rproc_alloc(struct device *dev, const char *name, + const struct rproc_ops *ops, + const char *firmware, int len) +{ + if (!name && !firmware) + return NULL; + + return rproc_alloc_state_machine(dev, name, ops, NULL, NULL, + firmware, len); +} /** * rproc_free() - unroll rproc_alloc() diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h index d115e47d702d..d1214487daac 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -611,6 +611,11 @@ struct rproc *rproc_get_by_child(struct device *dev); struct rproc *rproc_alloc(struct device *dev, const char *name, const struct rproc_ops *ops, const char *firmware, int len); +struct rproc *rproc_alloc_state_machine(struct device *dev, const char *name, + const struct rproc_ops *ops, + const struct rproc_ops *sync_ops, + struct rproc_sync_states *sync_states, + const char *firmware, int len); void rproc_put(struct rproc *rproc); int rproc_add(struct rproc *rproc); int rproc_del(struct rproc *rproc); From patchwork Tue Mar 24 21:45:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11456591 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 2BC0E1667 for ; Tue, 24 Mar 2020 21:46:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0DCEB20735 for ; Tue, 24 Mar 2020 21:46:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="wTAWnzLu" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727023AbgCXVqQ (ORCPT ); Tue, 24 Mar 2020 17:46:16 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:41695 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727496AbgCXVqQ (ORCPT ); Tue, 24 Mar 2020 17:46:16 -0400 Received: by mail-pl1-f196.google.com with SMTP id t16so7961000plr.8 for ; Tue, 24 Mar 2020 14:46:14 -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=Pt7wDr4fqIMluK1YQKun6+ciCQDmnXKa037aAN4VvN0=; b=wTAWnzLuPmePidvDl9kAOIEBDrW8lXosgGmRTY1Hx//4/vJZb4MDxK7GpWDHYA8aqo RCNJcDhebM2Oyhw3MmbqtH+FFoIcsdFhDl6wWR2h1cXC/zDyNpfggvLDg420ERV6OvDz JFvHKIlgyhWXovscywCiQtTy2ylRoOJJsqIPsDfvcyGtT9KvXZTQGy/RiBj45kG0qozB qNS9hp8VsmzGjty2SqnNBIfxpf0/surBUv+2PDLTm5Hc+nvIYf2uUMihbRCicsYD2qKk xk1EUyndvdlglOkvfGMeo1EeISJi91MIlIkIGgL4qWlGO5Jmnj/ey4GSqudZF+De/BT6 yDrw== 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=Pt7wDr4fqIMluK1YQKun6+ciCQDmnXKa037aAN4VvN0=; b=fdvyupNRTBAJaoTmD8P2JFwq5ibaeVy7g/MmpRej5+XAo+G0wv/VQ6kAyl0TZxuqjT vM9VXzT7bPzAtZ1Zls6iFm3H7rBj4cZIoE/tKqb2QZzxRk9PV+rsqXlXuTzlRY8gcUsd 8MiMuPtzGXajc6vrilJFQidBtgX3HmOL3c8WeBiSif5Y/W77ylV9/b5TyoVo6TwBgV3T DxcAPhKQUgYBnZfaY6rsdYPJLpwc4W8t5+RqiEU0yl98B6s1TI7C4Ggnvdo8ZTk+JX/7 XfykarMP84HmMgly8WErkOvvk42ICPfsKeFxEVj2YShDQxo7RzC91FtphpsdQCfTfyZd txmA== X-Gm-Message-State: ANhLgQ0fCp45Fu+cI29x2lhlJgGfllTyURjyN88gXazCWnEsFIHG/5lX 0G1P/6m69b8AUED0szm3sA9UoA== X-Google-Smtp-Source: ADFU+vuf964a96E6184jdAQb674Wqwxqy8meb0XjBg4DfdGwERMV/H+u6sg8Be5Xn50lxM6h2Rdx5g== X-Received: by 2002:a17:90a:c790:: with SMTP id gn16mr7873039pjb.146.1585086373922; Tue, 24 Mar 2020 14:46:13 -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.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Mar 2020 14:46:13 -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 08/17] remoteproc: Allocate synchronisation state machine Date: Tue, 24 Mar 2020 15:45:54 -0600 Message-Id: <20200324214603.14979-9-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 allocates a synchronisation state machine, either provided or not by users, in order to enact the proper behavior requested by the platform or specific scenarios. Signed-off-by: Mathieu Poirier --- drivers/remoteproc/remoteproc_core.c | 59 +++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 02dbb826aa29..1578a9c70422 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1955,6 +1955,7 @@ static void rproc_type_release(struct device *dev) kfree(rproc->firmware); kfree(rproc->ops); kfree(rproc->sync_ops); + kfree(rproc->sync_states); kfree(rproc); } @@ -2035,6 +2036,59 @@ static int rproc_alloc_sync_ops(struct rproc *rproc, return 0; } +static int rproc_alloc_sync_states(struct rproc *rproc, + const struct rproc_ops *boot_ops, + const struct rproc_ops *sync_ops, + struct rproc_sync_states *sync_states) +{ + struct rproc_sync_states *st; + + /* At least one set of operation is needed */ + if (!boot_ops && !sync_ops) + return -EINVAL; + + /* We have a synchronisation state machine, no need to build one */ + if (sync_states) { + st = kmemdup(sync_states, sizeof(*st), GFP_KERNEL); + if (!st) + return -ENOMEM; + + /* Nothing else to do */ + goto out; + } + + /* Allocate synchronisation state machine */ + st = kzalloc(sizeof(*st), GFP_KERNEL); + if (!st) + return -ENOMEM; + + /* + * We have a boot_ops and no sync_ops - build a state machine that + * does _not_ synchronise with an MCU. + */ + if (boot_ops && !sync_ops) { + st->on_init = st->after_stop = st->after_crash = false; + goto out; + } + + /* + * We have a sync_ops and an no boot_ops - build a state machine that + * _only_ synchronises with an MCU. + */ + if (sync_ops && !boot_ops) { + st->on_init = st->after_stop = st->after_crash = true; + goto out; + } + +out: + rproc->sync_with_mcu = st->on_init; + /* And the synchronisation state machine to use */ + rproc->sync_states = st; + /* Tell the core what to do when initialising */ + rproc_set_mcu_sync_state(rproc, RPROC_SYNC_STATE_INIT); + return 0; +} + static int rproc_alloc_internals(struct rproc *rproc, const char *name, const struct rproc_ops *boot_ops, const struct rproc_ops *sync_ops, @@ -2065,7 +2119,10 @@ static int rproc_alloc_internals(struct rproc *rproc, const char *name, return ret; } - return 0; + /* Finally allocate the synchronisation state machine */ + ret = rproc_alloc_sync_states(rproc, boot_ops, sync_ops, sync_states); + + return ret; } /** From patchwork Tue Mar 24 21:45:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11456589 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 6D52A139A for ; Tue, 24 Mar 2020 21:46:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4F8E820735 for ; Tue, 24 Mar 2020 21:46:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="SoQHI0Tz" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727613AbgCXVqQ (ORCPT ); Tue, 24 Mar 2020 17:46:16 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:42893 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727270AbgCXVqP (ORCPT ); Tue, 24 Mar 2020 17:46:15 -0400 Received: by mail-pl1-f194.google.com with SMTP id e1so2943691plt.9 for ; Tue, 24 Mar 2020 14:46:15 -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=gJHdU0ZEzYxJLygszYrGF0p3WNoeOx6WSquoQc0GbqY=; b=SoQHI0TzumallR0/Pxl7uAjuAyS/wWdU/IoX88zZubT2OOI0vd6RI3ivQSOIB+OZ9E 9DMuIDuv7l03k+uQduoiT6TGTdXb4PYf1zHI10xx+JDsZg/8O1XW1JVkfmULYL6/bhRT 2qHgyX9bzdNVPL70dDSskqykjvD6xyZa7VCYFbcU1wq5ks2k9WQwCZYJciQ1I7TyBJSF pQUkJkCOUZyTPYK7CP95auduA30fn5IVRepz4Aqt2Td9kj0EUO3exer+CLTDQZUVPzW5 utRQzQgR1TRbwT2peyDrOSIz2yzDqGAtTwbGJz5neWt8MWJM4NS13qlcYzG0WTROt7ca 9i/g== 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=gJHdU0ZEzYxJLygszYrGF0p3WNoeOx6WSquoQc0GbqY=; b=b98qt4OhIcFoYxgjIVvCZEbtu2QN3AWlhTwSwppgbQvruAWYbxBul94yjWl6buWYoL Zzbrf3jxHpoxAkcJsNr7BdYEl+VslaEglBHa79+pVm8xhPlUhx8vpqtVPnsG5SAlkJhi ih7t0XzLCLLGBITHidrTFqq8EHd2vZCRO3RSlGGflreUHSYmc1++i6JiLVb7x2BuIb2I 5d81zaMzKhlypQr1eReFJCDMgMrg7YkiIHpwewi4nNNu+MzBzWK1RXDhb8fb896k/erH 6FueD8HrlHCXWX6wq4SH6qRGlEsGAJEFXTPODSAJUDoOELYZ2lK9FmORXcLm7kH0Q7Jm gQKw== X-Gm-Message-State: ANhLgQ0tEDJSeYEcIIdLH5AGUphRE51+j0fk7TaObQOe1x8OC42DpvTJ FYQsvjDdI19RmP7CjXMK6xexeQ== X-Google-Smtp-Source: ADFU+vvzkoDyfmJEfZwfgeqvtbXSV2bEUaNmQ20D1HqnaMroA0yQkm7sVDpkyV3WcEQeO/HShuqE8w== X-Received: by 2002:a17:902:9a08:: with SMTP id v8mr93321plp.192.1585086374974; Tue, 24 Mar 2020 14:46:14 -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.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Mar 2020 14:46:14 -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 09/17] remoteproc: Call the right core function based on synchronisation state Date: Tue, 24 Mar 2020 15:45:55 -0600 Message-Id: <20200324214603.14979-10-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 Call the right core function based on whether we should synchronise with an MCU or boot it from scratch. Signed-off-by: Mathieu Poirier --- drivers/remoteproc/remoteproc_internal.h | 36 +++++++++++------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/drivers/remoteproc/remoteproc_internal.h b/drivers/remoteproc/remoteproc_internal.h index 73ea32df0156..5f711ceb97ba 100644 --- a/drivers/remoteproc/remoteproc_internal.h +++ b/drivers/remoteproc/remoteproc_internal.h @@ -106,38 +106,41 @@ static inline void rproc_set_mcu_sync_state(struct rproc *rproc, } } +#define RPROC_OPS_HELPER(__operation, ...) \ + do { \ + if (rproc_sync_with_mcu(rproc)) { \ + if (!rproc->sync_ops || \ + !rproc->sync_ops->__operation) \ + return 0; \ + return rproc->sync_ops->__operation(__VA_ARGS__); \ + } else if (rproc->ops && rproc->ops->__operation) \ + return rproc->ops->__operation(__VA_ARGS__); \ + } while (0) \ + static inline int rproc_fw_sanity_check(struct rproc *rproc, const struct firmware *fw) { - if (rproc->ops->sanity_check) - return rproc->ops->sanity_check(rproc, fw); - + RPROC_OPS_HELPER(sanity_check, rproc, fw); return 0; } static inline u32 rproc_get_boot_addr(struct rproc *rproc, const struct firmware *fw) { - if (rproc->ops->get_boot_addr) - return rproc->ops->get_boot_addr(rproc, fw); - + RPROC_OPS_HELPER(get_boot_addr, rproc, fw); return 0; } static inline int rproc_load_segments(struct rproc *rproc, const struct firmware *fw) { - if (rproc->ops->load) - return rproc->ops->load(rproc, fw); - + RPROC_OPS_HELPER(load, rproc, fw); return -EINVAL; } static inline int rproc_parse_fw(struct rproc *rproc, const struct firmware *fw) { - if (rproc->ops->parse_fw) - return rproc->ops->parse_fw(rproc, fw); - + RPROC_OPS_HELPER(parse_fw, rproc, fw); return 0; } @@ -145,10 +148,7 @@ static inline int rproc_handle_rsc(struct rproc *rproc, u32 rsc_type, void *rsc, int offset, int avail) { - if (rproc->ops->handle_rsc) - return rproc->ops->handle_rsc(rproc, rsc_type, rsc, offset, - avail); - + RPROC_OPS_HELPER(handle_rsc, rproc, rsc_type, rsc, offset, avail); return RSC_IGNORED; } @@ -156,9 +156,7 @@ static inline struct resource_table *rproc_find_loaded_rsc_table(struct rproc *rproc, const struct firmware *fw) { - if (rproc->ops->find_loaded_rsc_table) - return rproc->ops->find_loaded_rsc_table(rproc, fw); - + RPROC_OPS_HELPER(find_loaded_rsc_table, rproc, fw); return NULL; } From patchwork Tue Mar 24 21:45:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11456593 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 110221667 for ; Tue, 24 Mar 2020 21:46:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E700B20735 for ; Tue, 24 Mar 2020 21:46:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="X0si4Uzp" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727496AbgCXVqR (ORCPT ); Tue, 24 Mar 2020 17:46:17 -0400 Received: from mail-pj1-f65.google.com ([209.85.216.65]:37178 "EHLO mail-pj1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727270AbgCXVqR (ORCPT ); Tue, 24 Mar 2020 17:46:17 -0400 Received: by mail-pj1-f65.google.com with SMTP id o12so117384pjs.2 for ; Tue, 24 Mar 2020 14:46:16 -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=FD0VTjAKokoI3E/7TSv80ZTX/OnmyOrZGmVSUVDTIJg=; b=X0si4UzpveZE387HE3xqIDbdVehuh3/sYahGvdsSSBnSmagI0JJUgIo1QKMfVB9rLV X1G5NVHk9gs/GLx8LFbUoM3atL+sJ/AWTJ4lpjkNjSV7/wHRGojGiWSRtIxHQvFJK0pz JmUSFAS3jTvm5JEEDoe9zQvXsWfB82vOwxyq3YjL9zPKVgeVpwhJSK+3Epf8kn1GP/SQ w4KtEMWCJYmhTCJvx2z06DqpsIFe3fZ5CQfJfG7Xk5Kxdlu58s4noqAwtBDO9J/Jqa1h Q6+zjK3OSOG2G7d48g4hW2uOqZEpmRHol6s9wZvotpKUirXacDPx51sZorqXj1PD6AFJ U9gg== 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=FD0VTjAKokoI3E/7TSv80ZTX/OnmyOrZGmVSUVDTIJg=; b=Hg14hV/4drMp2v5GGQbbRzclar+eacCa2gopSu4BdyuoCabE7l+SM6AIsSSj4k8mJh 008ia4gQ/Qi9s44tdaYrWNenivf5sS/L4b3ngR2UN+WOW/A8d5NoVvy8skIx/Ssm/pef y59QFiHaxLcPtL+N/HsDKcvFO0Z4BJu9LBVgB4zCw+3AgB1Ji8pTFYkQjH8QI4nqT1TY 7cgGxPLglITWwr9wEokYrosCPIA1N9dE8eJ3BNJe0kJDwPL3G/hKZPMmyOTVW7lCNEpe mQ6fdjRB5sCdMf9JFUA54msQ2f/99xWSXCLk2NMtjUg+PHR8OLE4DZHGfoRIJAxkEE2T Z6mg== X-Gm-Message-State: ANhLgQ2TlEuoA/Uf1J4mLY/FRkJ4SD10lq9+kIoetJqGeEolzy5hpxSY aDXXDlXxtS9Pnopg+7GMWvwgTg== X-Google-Smtp-Source: ADFU+vuyVFYR0Q6ERF2hIjW9e6Rbjir8qpoxJZL/Zj/O/58q5uqcZ2nvBOv25NLwYkNmtHlzXs8lRw== X-Received: by 2002:a17:90a:36e5:: with SMTP id t92mr8029774pjb.51.1585086376044; Tue, 24 Mar 2020 14:46:16 -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.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Mar 2020 14:46:15 -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 10/17] remoteproc: Decouple firmware load and remoteproc booting Date: Tue, 24 Mar 2020 15:45:56 -0600 Message-Id: <20200324214603.14979-11-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 In preparation to support scenarios where MCU firmware is loaded and the MCU itself booted by another entity, split function rproc_boot() to decouple the functions of loading the firwmare and starting the initialisation process. That way we can reuse the functionality provided by the current implementation without invariably dealing with firmware loading. Signed-off-by: Mathieu Poirier --- drivers/remoteproc/remoteproc_core.c | 63 +++++++++++++++++----------- 1 file changed, 39 insertions(+), 24 deletions(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 1578a9c70422..7faee1396ef7 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1714,21 +1714,10 @@ static void rproc_crash_handler_work(struct work_struct *work) rproc_trigger_recovery(rproc); } -/** - * rproc_boot() - boot a remote processor - * @rproc: handle of a remote processor - * - * Boot a remote processor (i.e. load its firmware, power it on, ...). - * - * If the remote processor is already powered on, this function immediately - * returns (successfully). - * - * Returns 0 on success, and an appropriate error value otherwise. - */ -int rproc_boot(struct rproc *rproc) +static int rproc_actuate(struct rproc *rproc, + const struct firmware *firmware_p) { - const struct firmware *firmware_p; - struct device *dev; + struct device *dev = &rproc->dev; int ret; if (!rproc) { @@ -1736,8 +1725,6 @@ int rproc_boot(struct rproc *rproc) return -EINVAL; } - dev = &rproc->dev; - ret = mutex_lock_interruptible(&rproc->lock); if (ret) { dev_err(dev, "can't lock rproc %s: %d\n", rproc->name, ret); @@ -1756,24 +1743,52 @@ int rproc_boot(struct rproc *rproc) goto unlock_mutex; } - dev_info(dev, "powering up %s\n", rproc->name); + dev_info(dev, "%s %s\n", + firmware_p ? "powering up" : "syncing with", + rproc->name); + + ret = rproc_fw_boot(rproc, firmware_p); + if (ret) + atomic_dec(&rproc->power); + +unlock_mutex: + mutex_unlock(&rproc->lock); + return ret; +} + +/** + * rproc_boot() - boot a remote processor + * @rproc: handle of a remote processor + * + * Boot a remote processor (i.e. load its firmware, power it on, ...). + * + * If the remote processor is already powered on, this function immediately + * returns (successfully). + * + * Returns 0 on success, and an appropriate error value otherwise. + */ +int rproc_boot(struct rproc *rproc) +{ + const struct firmware *firmware_p; + struct device *dev = &rproc->dev; + int ret; + + if (!rproc) { + pr_err("invalid rproc handle\n"); + return -EINVAL; + } /* load firmware */ ret = request_firmware(&firmware_p, rproc->firmware, dev); if (ret < 0) { dev_err(dev, "request_firmware failed: %d\n", ret); - goto downref_rproc; + return ret; } - ret = rproc_fw_boot(rproc, firmware_p); + ret = rproc_actuate(rproc, firmware_p); release_firmware(firmware_p); -downref_rproc: - if (ret) - atomic_dec(&rproc->power); -unlock_mutex: - mutex_unlock(&rproc->lock); return ret; } EXPORT_SYMBOL(rproc_boot); From patchwork Tue Mar 24 21:45:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11456595 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 2F3A7139A for ; Tue, 24 Mar 2020 21:46:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 11F6F20735 for ; Tue, 24 Mar 2020 21:46:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="HLAM0/Bx" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727846AbgCXVqS (ORCPT ); Tue, 24 Mar 2020 17:46:18 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:44405 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727270AbgCXVqS (ORCPT ); Tue, 24 Mar 2020 17:46:18 -0400 Received: by mail-pl1-f193.google.com with SMTP id h11so7955157plr.11 for ; Tue, 24 Mar 2020 14:46:17 -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=vEoXsLC+v8mX4Vj+t+8zprwRGYdue84ZJZhMv1TU7d4=; b=HLAM0/Bx26njNKfeBfBtvRElPK5DtfXEjhAQKwOYTh+JBw9YpyvdJKK6CcoWapyaUE fhJGwc9KDFVTJ+CztiE1O8KmwyQO/yPfhzzGLhIwK57Dq2aDnCSbP9iQwNDCTcvcEuth RkoPWxvUQTogHLfihMHl0wv1xgUKyMryOhBNifRWhSriWMACvoaZaRTkI+IQksNP6Siz UxXC38nQntl9rMSjBX3QjS/xiPGtXK952IydgrDpKnmk83xYGQUPbAIz///8FYbIOrXp ttHBPgfsAl06eja9XIJ9wWT8rZTJYm9mYmkWnXevnI7+IPSLXbCB3bE4tABqTuPIgzze BkuA== 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=vEoXsLC+v8mX4Vj+t+8zprwRGYdue84ZJZhMv1TU7d4=; b=nwbOY7SJIhz5GkkfW5Df7Sx58TqEJGjvhwL2GFO0aTWCpSj6E5NzZnp8AWdJofPZsK W2Xi4N5wKtqw/wiUcavBjO3IZ3EtohHAdHzBa0LlPwR8Bsy1A3jG5lGUSWsgr7Q4FtrV 0/i8t1VbPRaNUcxCvhnTuDDMkOpWbC6ZURjpHndDlaYYVg5szjoBw29X6iRN6daAeh8q Mun5/mzX+zGx7rxwzLqXs6BOF3+Xk89B0GEfmcy+MDTm+Ym3bLwhFtcyTLLBshvtaGb+ DbylOn8GOAVPfn99U7TVHovPXHrhMzBTbvXc8HDMRnPd7xonJ23c6cE7xH763hK/OJnN 2HBQ== X-Gm-Message-State: ANhLgQ3j2V6HudbrLrv9i8sO0q9pmZKhpP39pLEGwOBvq5Yq2Q5DS6Z0 6YtGlD7w28+xyfTPCKLGz+U17Q== X-Google-Smtp-Source: ADFU+vsOYwi8bVRo9kg/aK7gW7d2BueKmOGms04upVPkNkRvXY5sHpOZC06IaUqpgvo8ZG3YUDONWw== X-Received: by 2002:a17:90a:868b:: with SMTP id p11mr6768pjn.34.1585086377348; Tue, 24 Mar 2020 14:46:17 -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.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Mar 2020 14:46:16 -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 11/17] remoteproc: Repurpose function rproc_trigger_auto_boot() Date: Tue, 24 Mar 2020 15:45:57 -0600 Message-Id: <20200324214603.14979-12-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 Repurpose function rproc_trigger_auto_boot() so that it can deal with scenarios where the MCU is already running. As such give it a new name to better represent the capabilities and add a call to rproc_actuate() if instructed by the platform code to synchronise with the MCU rather than boot it from scratch. Signed-off-by: Mathieu Poirier --- drivers/remoteproc/remoteproc_core.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 7faee1396ef7..d57b47b0d6be 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -51,6 +51,8 @@ static int rproc_alloc_carveout(struct rproc *rproc, struct rproc_mem_entry *mem); static int rproc_release_carveout(struct rproc *rproc, struct rproc_mem_entry *mem); +static int rproc_actuate(struct rproc *rproc, + const struct firmware *firmware_p); /* Unique indices for remoteproc devices */ static DEFINE_IDA(rproc_dev_index); @@ -1444,10 +1446,17 @@ static void rproc_auto_boot_callback(const struct firmware *fw, void *context) release_firmware(fw); } -static int rproc_trigger_auto_boot(struct rproc *rproc) +static int rproc_trigger_auto_initiate(struct rproc *rproc) { int ret; + /* + * The MCU is already booted, all we need to do is synchronise with it. + * No point dealing with a firmware image. + */ + if (rproc_sync_with_mcu(rproc)) + return rproc_actuate(rproc, NULL); + /* * We're initiating an asynchronous firmware loading, so we can * be built-in kernel code, without hanging the boot process. @@ -1931,9 +1940,12 @@ int rproc_add(struct rproc *rproc) /* create debugfs entries */ rproc_create_debug_dir(rproc); - /* if rproc is marked always-on, request it to boot */ + /* + * if rproc is marked always-on, request it to boot or synchronise + * with it. + */ if (rproc->auto_boot) { - ret = rproc_trigger_auto_boot(rproc); + ret = rproc_trigger_auto_initiate(rproc); if (ret < 0) return ret; } From patchwork Tue Mar 24 21:45:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11456597 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 C50BC17EF for ; Tue, 24 Mar 2020 21:46:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A79B320735 for ; Tue, 24 Mar 2020 21:46:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="gvMG5SoA" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727270AbgCXVqT (ORCPT ); Tue, 24 Mar 2020 17:46:19 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:34607 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727747AbgCXVqT (ORCPT ); Tue, 24 Mar 2020 17:46:19 -0400 Received: by mail-pg1-f196.google.com with SMTP id t3so114736pgn.1 for ; Tue, 24 Mar 2020 14:46:18 -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=0aC0W/518gjnn+FmK3AUNBAeb9XjXBNzVkVSx2D1XV4=; b=gvMG5SoAo4dcUk97Xr5oa52WsIphapj8PJlJj06zeoEbCNK99QJjmWkPCFGPK/1FXj 6wveLkR2bnULAtJLjgof+/MGPp0JpwYidPVq+JccBVtPoITcC1mxH7KBl4ot4GmAfmn1 4ioV8V3aI6wjJj7sV0WMAVp5R9DH6kHHBzgyaB5wFZEAIG3nvJIEMaPpLx2dKQrDPZWl cZWroPS3cvzzXkAP2cx2+UKiyvmCWMWYJtqSoPVc3QjCVNhGQH4m8n4+OSvLwfD7Omef WI+XdnIUJ72BDEJm4pVUktY7Y5iSWyB2f4Gl+k4+iOw3kYg1o5WKaYaGFm10KLlXoC/2 ucrw== 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=0aC0W/518gjnn+FmK3AUNBAeb9XjXBNzVkVSx2D1XV4=; b=j/zPu1mjwq3HbdWjVzMS7VlV8bYu+jWymGG3eAdCVpfQFZlHLkyImvU+wTUhgCotgr 2ioZAB+tnWaNbL8JpitfeDMlaLyqfj1SPLXpRSsOoo2wGhst3ZRhHpJuz0iEwoKYQaPd uq2VD0pik8wEwgwUGC1lf13kylyExlirwDbkgKa2GY8893gqlkB4tSrQEsZP+5wmVl15 3F+Qavz8CHUowm+AtO4pkvunQ9eDJ8je63JpHLBT22+lqaADy5paH74qj1WaY7UmVx3P SWutJtlKY2fVE+qfXbst6lU4oIRQnL42QDbQfaCT18lqiZBCqzv7mfqK5x/0raJdkkrc /6Cw== X-Gm-Message-State: ANhLgQ2nN4uQ/LG0nKqFEWc+Fl+97kDprokbrjQhcEyAIopMaDMMQcQW 6TQB4CVXoCxbn1Dkj7kQtuTjKg== X-Google-Smtp-Source: ADFU+vtUBtc3SqH18/USFJViwQ5ySwBzzIPJfBGZC+nxK84vxpsKWnS6uRBaRQ/dYKyJnDCALOamCQ== X-Received: by 2002:a63:c84c:: with SMTP id l12mr13984307pgi.225.1585086378357; Tue, 24 Mar 2020 14:46:18 -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.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Mar 2020 14:46:18 -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 12/17] remoteproc: Rename function rproc_fw_boot() Date: Tue, 24 Mar 2020 15:45:58 -0600 Message-Id: <20200324214603.14979-13-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 Renaming function rproc_fw_boot() in order to better reflect the work that is done when supporting scenarios where the remoteproc core is synchronising with an MCU. Signed-off-by: Mathieu Poirier --- drivers/remoteproc/remoteproc_core.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index d57b47b0d6be..488723fcb142 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1363,7 +1363,8 @@ static int rproc_start(struct rproc *rproc, const struct firmware *fw) /* * take a firmware and boot a remote processor with it. */ -static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw) +static int rproc_actuate_platform(struct rproc *rproc, + const struct firmware *fw) { struct device *dev = &rproc->dev; const char *name = rproc->firmware; @@ -1373,7 +1374,9 @@ static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw) if (ret) return ret; - dev_info(dev, "Booting fw image %s, size %zd\n", name, fw->size); + if (!rproc_sync_with_mcu(rproc)) + dev_info(dev, "Booting fw image %s, size %zd\n", + name, fw->size); /* * if enabling an IOMMU isn't relevant for this rproc, this is @@ -1756,7 +1759,7 @@ static int rproc_actuate(struct rproc *rproc, firmware_p ? "powering up" : "syncing with", rproc->name); - ret = rproc_fw_boot(rproc, firmware_p); + ret = rproc_actuate_platform(rproc, firmware_p); if (ret) atomic_dec(&rproc->power); From patchwork Tue Mar 24 21:45:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11456599 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 063CA139A for ; Tue, 24 Mar 2020 21:46:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DC6D820735 for ; Tue, 24 Mar 2020 21:46:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="qhK1pmGE" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727613AbgCXVqU (ORCPT ); Tue, 24 Mar 2020 17:46:20 -0400 Received: from mail-pj1-f68.google.com ([209.85.216.68]:51835 "EHLO mail-pj1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727747AbgCXVqU (ORCPT ); Tue, 24 Mar 2020 17:46:20 -0400 Received: by mail-pj1-f68.google.com with SMTP id w9so120490pjh.1 for ; Tue, 24 Mar 2020 14:46:20 -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=9b1+nNVbR3sCyMduzopiYh9Dkhm8/+7NJkp3fZXzhTU=; b=qhK1pmGESXCBcbwtx8gy6DGEPSkCDqNfNU7GDFfza/8+V0ckw+Oda4/p/ZICr0qt6G 8m+8fKuzcH//MNCVLjmORbF0frVmBAdBcI0aFUNLZZhxFvpyYSrlGrdm7+K3KHhp+p62 vHZOYEwueAaK9msnttS9umiLHJ5aWDnDYHLm40DIpFbedTztkr8UAllcpEgPTQPouBhs jyMjcCiqMkPiT4U8e3YeRsBJfDtznf8OOPNC80YCfmElsuau9S3oxP4+OjbkFx+P+B/L hWnewTpXRf5BDPeCy8lv9ue7I6O9MxtLjreijf/WSU6/QYjZ+jvrs5u3rxmYrCL91gfe sRKg== 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=9b1+nNVbR3sCyMduzopiYh9Dkhm8/+7NJkp3fZXzhTU=; b=BcL6IxDj3c8Vojz0kt3hE+UR5g0UoOh1PCoD7lo9UWHy7QElCcT4UrEsUnIf5cBqjv B1qW9rnxl/ivV4Lc55GVa3iQHaVCU1AMh7O0/94sPIQR7gGtQtBOCr2ZW+cF7eBVNPn3 7jQ5gxJTV1nOQXSVc08Iv5GXztyp5jtwanDwH2+veKrlNueL6ndvipH4/3L65oB3aZB3 5WAX0kTyq0dRZaEzvXU250e6G59vBDBo7QldVGX0alTCtve+0w8v0URvGGq8uzxFsoKH IUuXnUfh8/6OlCRmkFv+hzF7dpB/yc88VRa//ugcN27Nx0dVQvNpnwSXzUmoF5VEoIlJ c2qw== X-Gm-Message-State: ANhLgQ2vN5Pmk9WSCGQzV2iqdMZgYpR4YRpB3xB/XSmgQRD6dpZzD4cg riPM9wvckGLPOjCJt+NPpRbpeg== X-Google-Smtp-Source: ADFU+vuabZXdchfF8VWJJvUtTWkf8e4E0tGVizmq3qyPuLbqozcSBx4REc/mHqHtURwCIxPNIkTssA== X-Received: by 2002:a17:90a:252b:: with SMTP id j40mr7719175pje.189.1585086379462; Tue, 24 Mar 2020 14:46:19 -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.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Mar 2020 14:46:19 -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 13/17] remoteproc: Introducting new functions to start and stop an MCU Date: Tue, 24 Mar 2020 15:45:59 -0600 Message-Id: <20200324214603.14979-14-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 Add new functions to replace direct calling of rproc->ops->start() and rproc->ops->stop(). That way different behaviour can be played out when booting an MCU or synchronising with it. Signed-off-by: Mathieu Poirier --- drivers/remoteproc/remoteproc_core.c | 6 +++--- drivers/remoteproc/remoteproc_internal.h | 12 ++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 488723fcb142..d3c4d7e6ca25 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1330,7 +1330,7 @@ static int rproc_start(struct rproc *rproc, const struct firmware *fw) } /* power up the remote processor */ - ret = rproc->ops->start(rproc); + ret = rproc_start_hw(rproc); if (ret) { dev_err(dev, "can't start rproc %s: %d\n", rproc->name, ret); goto unprepare_subdevices; @@ -1351,7 +1351,7 @@ static int rproc_start(struct rproc *rproc, const struct firmware *fw) return 0; stop_rproc: - rproc->ops->stop(rproc); + rproc_stop_hw(rproc); unprepare_subdevices: rproc_unprepare_subdevices(rproc); reset_table_ptr: @@ -1485,7 +1485,7 @@ static int rproc_stop(struct rproc *rproc, bool crashed) rproc->table_ptr = rproc->cached_table; /* power off the remote processor */ - ret = rproc->ops->stop(rproc); + ret = rproc_stop_hw(rproc); if (ret) { dev_err(dev, "can't stop rproc: %d\n", ret); return ret; diff --git a/drivers/remoteproc/remoteproc_internal.h b/drivers/remoteproc/remoteproc_internal.h index 5f711ceb97ba..7ca23d46dfd4 100644 --- a/drivers/remoteproc/remoteproc_internal.h +++ b/drivers/remoteproc/remoteproc_internal.h @@ -160,4 +160,16 @@ struct resource_table *rproc_find_loaded_rsc_table(struct rproc *rproc, return NULL; } +static inline int rproc_start_hw(struct rproc *rproc) +{ + RPROC_OPS_HELPER(start, rproc); + return -EINVAL; +} + +static inline int rproc_stop_hw(struct rproc *rproc) +{ + RPROC_OPS_HELPER(stop, rproc); + return -EINVAL; +} + #endif /* REMOTEPROC_INTERNAL_H */ From patchwork Tue Mar 24 21:46:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11456601 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 81433139A for ; Tue, 24 Mar 2020 21:46:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 637A420735 for ; Tue, 24 Mar 2020 21:46:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="qwNweu48" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727753AbgCXVqW (ORCPT ); Tue, 24 Mar 2020 17:46:22 -0400 Received: from mail-pj1-f66.google.com ([209.85.216.66]:37181 "EHLO mail-pj1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727747AbgCXVqW (ORCPT ); Tue, 24 Mar 2020 17:46:22 -0400 Received: by mail-pj1-f66.google.com with SMTP id o12so117466pjs.2 for ; Tue, 24 Mar 2020 14:46:21 -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=r2iAuvZgT/vJ5kezK/zxo0dCdsSjLaGw8q76btUTT/Y=; b=qwNweu48IVdvuGMdb87/sFUcTFHpTKxprQOFQ+RUovMeiyhUkUaW97nOykXqm6kxmK HvgtqOabVYxBw+QLDaFjE8/iTnFvpgOu0mwQnneyoC88LZNrOZZYsH3peoJ2uTwncdkM 4NxeWavzid2gyAxdXDvUPaL1moPwqthGKo18UsW5wAgUj0uSTHzpuwcNrwqeS/yiWH/3 jidOo96MG8jUvry6IfQGuLJJCaukN4Tz2Pn0hSkcYmnXfEm6lZ3Eli4qyOxnXfVO/k6L XrgsZ2wkiE4HazU1IGULB0d5N4P31osijuKlhsEF3oqJHrEYu8hhgzQUPpt9l/69l7Ze CMGg== 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=r2iAuvZgT/vJ5kezK/zxo0dCdsSjLaGw8q76btUTT/Y=; b=lRd+BgTSQRwyyXvu+rA5kcz5GYPBsLuD8XmcPeLclacGeNl5e2kVAhQHIpyzhJ1dBA nPQbr7plBiei9eVMOwNzuS79wis6P81WuXk9rpJdn6TARgT5F/aOOsmcHZRTUVdX8zNt EOyvEV65sc7NkVjqAkvHpAE+a/X0vMPdIGY956WWzAPAf0s9UEgANPAbr3/o6UIHJ3PO jkdRzZSHLwMrlmm10mvlZNrppS8Tz4QCrKUU+7LVMDbZaNZgl63ewJRB4LAGe9ZAhlJr DJQetsL2C9GDt3nXSP+Bm05+m1NKJ+QhtkZF+2LbN9IoRqyjw28YAOUYxldEYTHe9cUJ qkQw== X-Gm-Message-State: ANhLgQ38EwEZx5fmBqWqrGc1TA/3JPvNkZeXvfpPPl/iQDLs8V7uCWWb O6KPt9py/ezcbqIk3AaR3JU6PQ== X-Google-Smtp-Source: ADFU+vsOjaugijeD6atzcjc3w+WVUWXGRjxQRBbF0YM6Oad8cecV8jgmvjnWlu370MhHooKWmFArNw== X-Received: by 2002:a17:90a:c715:: with SMTP id o21mr8059051pjt.160.1585086380559; Tue, 24 Mar 2020 14:46:20 -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.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Mar 2020 14:46:20 -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 14/17] remoteproc: Refactor function rproc_trigger_recovery() Date: Tue, 24 Mar 2020 15:46:00 -0600 Message-Id: <20200324214603.14979-15-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 Refactor function rproc_trigger_recovery() in order to avoid reloading the fw image when synchronising with an MCU rather than booting it. Signed-off-by: Mathieu Poirier --- drivers/remoteproc/remoteproc_core.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index d3c4d7e6ca25..dbb0a8467205 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1661,7 +1661,7 @@ static void rproc_coredump(struct rproc *rproc) */ int rproc_trigger_recovery(struct rproc *rproc) { - const struct firmware *firmware_p; + const struct firmware *firmware_p = NULL; struct device *dev = &rproc->dev; int ret; @@ -1678,14 +1678,16 @@ int rproc_trigger_recovery(struct rproc *rproc) /* generate coredump */ rproc_coredump(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; + /* load firmware if need be */ + if (!rproc_sync_with_mcu(rproc)) { + ret = request_firmware(&firmware_p, rproc->firmware, dev); + if (ret < 0) { + dev_err(dev, "request_firmware failed: %d\n", ret); + goto unlock_mutex; + } } - /* boot the remote processor up again */ + /* boot up or synchronise with the remote processor again */ ret = rproc_start(rproc, firmware_p); release_firmware(firmware_p); 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; From patchwork Tue Mar 24 21:46:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11456605 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 3132A1667 for ; Tue, 24 Mar 2020 21:46:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 139DA20735 for ; Tue, 24 Mar 2020 21:46:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="mpnsRTvR" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727496AbgCXVqX (ORCPT ); Tue, 24 Mar 2020 17:46:23 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:41704 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727023AbgCXVqX (ORCPT ); Tue, 24 Mar 2020 17:46:23 -0400 Received: by mail-pl1-f194.google.com with SMTP id t16so7961147plr.8 for ; Tue, 24 Mar 2020 14:46:23 -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=IuukOSyWIrqfCKsQH/r2/YhsUvldyW+QBECojjMioRI=; b=mpnsRTvRHOT6TJ220UZcITAv2yLm3274yOoI/zs/PoqStk4dXp0+Wvd6ZU4mCdEwLZ Yu0aOZbdZM6OO6dEsxDfc0RVDmhL+bjl5mYyaNPmanlid9d3A2OBl9vjTdtNdgO8W2/+ ZJPeV02stxnyw+ZVWF7Twte5EAV6JJI+WFGBIVVQNhyzAT8lIcMyd5aMSWNo11fPUlpc 3KxBMKF3FFBPHqL9WDwBl7Cet+DyC97rbS0rPrnoWgkjd9+1WRanbLLYaDL7TZ7avqOi eSodG2gQFXjBqHFsa7HD8PjOJwuFgRN/wvPK/CloKbUlCIU5sR3r/YluY4B8IG2FlAJz eWHw== 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=IuukOSyWIrqfCKsQH/r2/YhsUvldyW+QBECojjMioRI=; b=Jr7EhOo6GL4Sb2pErI/ZArYCMd6XIocPwI+c6p2oj59uj/ajMoBCtLnHQRMh3cYit9 ta1FdhotuAy23oOJ/5n0KclYwBPQ6RRXe3kDPp166uSYtxuwczDYQi86ZrnIiyIGvgKI hH79G4zYiNvcD7Ti3JO5oZRXxgmIHsUHwVP8/d1RxV5QBJyX1lQ3PWFuUJqDPzpw6g30 gNpRQYuMWH0Fs4LJEbTJXYOFlBj21sDG54fDvBDgbDqwVn4fsbTk6Tqujbg9h2reIq4I KC+JjxxH5ieAlATyn40YNjGNNbBo8Hk2HHgbRGim80VHfTZz9GjYcwUWn7rgljkgPrPV NTcA== X-Gm-Message-State: ANhLgQ0kY4lA3Dq/ndryGm9b+CYi4C9I6/e2IS1mZZPBL8xudp8sDJLD yVOFvYGcFSRlK3qk64vsGXDaug== X-Google-Smtp-Source: ADFU+vs8c/teB+/skfc7k72remy0g0+OE/dwictW1sV0wgW0GmkLNk5e6Vh2Wu48xjx6rqiDhVqpJw== X-Received: by 2002:a17:902:820a:: with SMTP id x10mr57134pln.179.1585086382671; Tue, 24 Mar 2020 14:46:22 -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.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Mar 2020 14:46:22 -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 16/17] remoteproc: Correctly deal with MCU synchronisation when changing state Date: Tue, 24 Mar 2020 15:46:02 -0600 Message-Id: <20200324214603.14979-17-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 deals with state changes when synchronising with an MCU. More specifically it prevents the MCU from being started if it already has been started by another entity. Similarly it prevents the AP from stopping the MCU if it hasn't been given the capability by platform firmware. Signed-off-by: Mathieu Poirier --- drivers/remoteproc/remoteproc_sysfs.c | 32 ++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/drivers/remoteproc/remoteproc_sysfs.c b/drivers/remoteproc/remoteproc_sysfs.c index 4956577ad4b4..741a3c152b82 100644 --- a/drivers/remoteproc/remoteproc_sysfs.c +++ b/drivers/remoteproc/remoteproc_sysfs.c @@ -108,6 +108,29 @@ static ssize_t state_show(struct device *dev, struct device_attribute *attr, return sprintf(buf, "%s\n", rproc_state_string[state]); } +static int rproc_can_shutdown(struct rproc *rproc) +{ + /* The MCU is not running, obviously an invalid operation. */ + if (rproc->state != RPROC_RUNNING) + return false; + + /* + * The MCU is not running (see above) and the remoteproc core is the + * lifecycle manager, no problem calling for a shutdown. + */ + if (!rproc_sync_with_mcu(rproc)) + return true; + + /* + * The MCU has been loaded by another entity (see above) and the + * platform code has _not_ given us the capability of stopping it. + */ + if (!rproc->sync_ops->stop) + return false; + + return true; +} + /* Change remote processor state via sysfs */ static ssize_t state_store(struct device *dev, struct device_attribute *attr, @@ -120,11 +143,18 @@ static ssize_t state_store(struct device *dev, if (rproc->state == RPROC_RUNNING) return -EBUSY; + /* + * In synchronisation mode, booting the MCU is the + * responsibility of an external entity. + */ + if (rproc_sync_with_mcu(rproc)) + return -EINVAL; + ret = rproc_boot(rproc); if (ret) dev_err(&rproc->dev, "Boot failed: %d\n", ret); } else if (sysfs_streq(buf, "stop")) { - if (rproc->state != RPROC_RUNNING) + if (!rproc_can_shutdown(rproc)) return -EINVAL; rproc_shutdown(rproc); From patchwork Tue Mar 24 21:46:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11456607 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 A828D1667 for ; Tue, 24 Mar 2020 21:46:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8A1A02077D for ; Tue, 24 Mar 2020 21:46:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="q/VMrtbp" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727270AbgCXVqZ (ORCPT ); Tue, 24 Mar 2020 17:46:25 -0400 Received: from mail-pj1-f67.google.com ([209.85.216.67]:55106 "EHLO mail-pj1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727023AbgCXVqZ (ORCPT ); Tue, 24 Mar 2020 17:46:25 -0400 Received: by mail-pj1-f67.google.com with SMTP id np9so112426pjb.4 for ; Tue, 24 Mar 2020 14:46:24 -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=vDKckchEP5jKnQNDmUYqNLCsBKtRywXgHyTH3809raQ=; b=q/VMrtbpFTwSTk1+rTP8692zKObFz0XPJXce/nDOQAH1Mecykiog/cx/rooBbG/1yi 7P3W38xqP/2GCSkGqMhq3/tkaBI+5cXg+ywE6Nw4bU3p3ZXyAQOiobUzsvrGuBy5waj+ tMLsdvoUANAJ+MAqPcObHUY5cksRm24AflxvNeXeKcGme5JtsuVCpTCYqZFIxTk754Qa YmYVyEjBgsBZiTW460VwuPQu1TyjNchnbFSzaqv8+2WxxlYSKPLJFxlpZwjz0AFTjfrX Vzoc53YygC/TxKQM557rtChB+qnZrTnW8N9xFp7lBMEK8f/9eB661HYMtlwx3PVHuzrN 2MJQ== 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=vDKckchEP5jKnQNDmUYqNLCsBKtRywXgHyTH3809raQ=; b=PUU4iKxF2pctiXMo/629MWfW4irGlzW0ijUNiSDiMB+HjPKnp9Zyj36AHgztxxzmdc mH2otYWHFZVukKyjwi/O8p+EfokRMcUYaSPIBHBesCuMDrE6pTLmJ0kGphBunndlb7Qp RFFgVIFgrsZjxr/x3qHdj3BwOf9CFirCqof9/0hJOJjv3iCYziNM+72wuh5h83y83hVg X9wKIBDLZu5tWLdoKTFoOslQkUhtts5dbFCKnH4IxCcUgHZVYzTLbAKkkpHDIdhSUXYu oEwi/2t8eJmwjFTrbyP5PevMq5dhigC+HxCsgdKzZHMv+vbzEv1btWl+4cOIScUPM8YX MJZw== X-Gm-Message-State: ANhLgQ1CWnallUsYh4CBvOnkixxI+OLc/YZethBgQ+94tGi1pWEFHmqh BGvQ/ZxNuNUTAYE5O2mDg1DluQ== X-Google-Smtp-Source: ADFU+vuPTNhWETaApnyd02KQpWAt8nSgcJdfkUiYCcBhYaJb0AGssspJB5xQVPFGHmWuYqLZdmqCQA== X-Received: by 2002:a17:90a:8586:: with SMTP id m6mr7633994pjn.121.1585086383778; Tue, 24 Mar 2020 14:46:23 -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.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Mar 2020 14:46:23 -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 17/17] remoteproc: Make MCU synchronisation state changes on stop and crashed Date: Tue, 24 Mar 2020 15:46:03 -0600 Message-Id: <20200324214603.14979-18-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 Call on the MCU synchronisation state machine to determine the synchronisation status to enact when the MCU is either stop from sysfs or has crashed. Signed-off-by: Mathieu Poirier --- drivers/remoteproc/remoteproc_core.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index dbb0a8467205..0608593cccc6 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1722,6 +1722,14 @@ static void rproc_crash_handler_work(struct work_struct *work) dev_err(dev, "handling crash #%u in %s\n", ++rproc->crash_cnt, rproc->name); + /* + * The MCU has crashed - tell the core what operation to + * use from hereon, i.e whether an external entity will + * reboot the MCU or it is now the remoteproc core's + * responsability. + */ + rproc_set_mcu_sync_state(rproc, RPROC_SYNC_STATE_CRASHED); + mutex_unlock(&rproc->lock); if (!rproc->recovery_disabled) @@ -1856,6 +1864,13 @@ void rproc_shutdown(struct rproc *rproc) kfree(rproc->cached_table); rproc->cached_table = NULL; rproc->table_ptr = NULL; + + /* + * The MCU has been switched off - tell the core what operation to + * use from hereon, i.e whether an external entity will reboot the + * MCU or it is now the remoteproc core's responsability. + */ + rproc_set_mcu_sync_state(rproc, RPROC_SYNC_STATE_SHUTDOWN); out: mutex_unlock(&rproc->lock); }