From patchwork Thu Mar 12 22:11:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11435545 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 E2CB992A for ; Thu, 12 Mar 2020 22:12:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C185A20716 for ; Thu, 12 Mar 2020 22:12:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="aUAMXlR0" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726705AbgCLWMD (ORCPT ); Thu, 12 Mar 2020 18:12:03 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:43852 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726513AbgCLWMD (ORCPT ); Thu, 12 Mar 2020 18:12:03 -0400 Received: by mail-pl1-f193.google.com with SMTP id f8so3218423plt.10 for ; Thu, 12 Mar 2020 15:12:01 -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=aUAMXlR0NzFBvljPDbORYTUF0uM/a/2wXqtl7krLYXm42EsRkZBsY+l2PDlSraloMw w5lspqPMFRGVWda3sW+ff6csuIyd/YS3d8B3LwgOwVWgBL4GxbpP3YCZ8QR075H1JvMb 5gMXa+d+EkXg9LxgzXsTFy0dDbZRQRhjLAGRWbOO/zEcSqXU5x+VONFkLVPrzGh5Kt1J G5L3/LE4qXvo9YS41ogJo2gkM/p1ZPzeg6JO7LoVsgao/ndxqlzIPGjl87eQTlJb9xIa mvPK65cnDHQL5d6w0WKWNNCtnhm+rnPzk//tHuYHzVbF97hLckJ6ORwv2MjDxOLg14Gi QmnA== 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=C3QLBL8n/wzo3+C4qit4jRI+YLwu507Zts340EUYgEclUvnOW3zZK9aRVJHlSvHrWT hKN/IrpdIKyW0RuZosJrRVmoeLsRlxupSFScef+l1HwWvhc/uYZwyWNdL0L9+Ac2RneD mZVY2Ur72cq59rgxROZa2wA5+SQjNhCsMFb3VZN5oQAHu89Gv438urmbZWbrgt8j/oHj STkDUCEHLo29IqrHRrpv6bi8hB8JDPu3YFe3rgVWzIoD7m1PDZnz5sVhnJFsBJsF8mww 3f1DMZkh+NgBsv7kB87y7SK+2P+HqEfBtl/t+eii7VBSimXJTsCCrrCCeytxlSWaSYgT OHKQ== X-Gm-Message-State: ANhLgQ0olSG75xVXI6mf9e3XTbWq7qWybUN/mVEZqrlC94LsGAnySK0N AFjCF/IakALskhV3Pdax+wenug== X-Google-Smtp-Source: ADFU+vuspi1loUZ6ndebAEE6L6FraC2faoWWvWlxEVi0NqTjpOt/iO1dbjr6P1RM0O14rSTyRvIhhQ== X-Received: by 2002:a17:902:fe83:: with SMTP id x3mr10255700plm.310.1584051121181; Thu, 12 Mar 2020 15:12:01 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id j2sm20945362pfg.169.2020.03.12.15.12.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Mar 2020 15:12:00 -0700 (PDT) From: Mathieu Poirier To: bjorn.andersson@linaro.org Cc: linux-remoteproc@vger.kernel.org, ohad@wizery.com, loic.pallardy@st.com, s-anna@ti.com, peng.fan@nxp.com, arnaud.pouliquen@st.com, fabien.dessenne@st.com Subject: [PATCH 01/18] remoteproc: Add new operation and state machine for MCU synchronisation Date: Thu, 12 Mar 2020 16:11:41 -0600 Message-Id: <20200312221158.3613-2-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200312221158.3613-1-mathieu.poirier@linaro.org> References: <20200312221158.3613-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 Thu Mar 12 22:11:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11435543 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 B91EC13B1 for ; Thu, 12 Mar 2020 22:12:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9822720716 for ; Thu, 12 Mar 2020 22:12:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="BFhFq2X7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726704AbgCLWMD (ORCPT ); Thu, 12 Mar 2020 18:12:03 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:39843 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726705AbgCLWMD (ORCPT ); Thu, 12 Mar 2020 18:12:03 -0400 Received: by mail-pg1-f196.google.com with SMTP id s2so3756062pgv.6 for ; Thu, 12 Mar 2020 15:12:02 -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=BFhFq2X7KQwK3uKbPtwbZBV09NhL3ivBezID3ytc3o88mN8i3HOBI7JwLVAnbYiZlN 9Od8pE8FYObQoTQVAjWS7Yu1AVE62cK7BxJfAKLu1yrbCsqewrWYV8IXk20ziyQbHpsf EfIgP2ahCGs6E5K2Xs7l6z6a0aEkFYZiyoDoOXq70JQ7X+mR3V1bsfAo1ffYjgj2yyQJ 2ryFSMgtas1XjeQ3YERQmpTaBDEKkH+z0gNTBBEETA5+T7kfPsGcFK9zgT1K15b7ogy+ NzvtSsZSGwNCbMeQ0OIhJxeocfJaz5pG7jeckMMQe8GmvgYxDf0NuHE+ADxzIdOGWfTz qHmA== 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=JhNjpJxvfRFaq3WIZU035Jc5RZpf9ENygedoh4G/bVnZOIj9cYLAAm7FB+DGU5oQoG lZpG1r9EMx4+MheLngSF83KkPs/d6NxqADn7z1eOdWKZoLNt3ww5aIk2SxcBlpJ8KLFL ahRfFH+nLwTCRib8laTFh+fSj2pwtD47KL9w7AzPt3I/7eXdpABZiSAviOqlJSCWk/my sVTBPdRhXAZ8Nu9qKb9CwdyGAGK6RtH+IAH0Fuim1DFGFHiOiXjq4+7w2gxiBKqA2CXz usjqpH2Yl6hqfTXw5LWlSgNrEiAZ9+Utfwwztgs6lIuPwzyaj3o0QiUuHf6z/HB0I006 DMJA== X-Gm-Message-State: ANhLgQ0Et7Il5k5ycBZabqglJeFWXKeL15bCE0QtA0CrfSy3jb9BzbYX feNLOQVJcIOY5MeW33LnFG+/Iw== X-Google-Smtp-Source: ADFU+vtx7vQQwNFhzcRfz8yTOymVQ7jLd1xJk23nmOH0KgIGgY0u+/gsg9Di8c2OVM1Myf1bxJEjjQ== X-Received: by 2002:a63:b34d:: with SMTP id x13mr9964435pgt.317.1584051122241; Thu, 12 Mar 2020 15:12:02 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id j2sm20945362pfg.169.2020.03.12.15.12.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Mar 2020 15:12:01 -0700 (PDT) From: Mathieu Poirier To: bjorn.andersson@linaro.org Cc: linux-remoteproc@vger.kernel.org, ohad@wizery.com, loic.pallardy@st.com, s-anna@ti.com, peng.fan@nxp.com, arnaud.pouliquen@st.com, fabien.dessenne@st.com Subject: [PATCH 02/18] remoteproc: Introduce function rproc_set_mcu_sync_state() Date: Thu, 12 Mar 2020 16:11:42 -0600 Message-Id: <20200312221158.3613-3-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200312221158.3613-1-mathieu.poirier@linaro.org> References: <20200312221158.3613-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 Thu Mar 12 22:11:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11435547 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 B9F3513B1 for ; Thu, 12 Mar 2020 22:12:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9912F206CD for ; Thu, 12 Mar 2020 22:12:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="Ek4JJAUT" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726680AbgCLWME (ORCPT ); Thu, 12 Mar 2020 18:12:04 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:34819 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726513AbgCLWME (ORCPT ); Thu, 12 Mar 2020 18:12:04 -0400 Received: by mail-pg1-f194.google.com with SMTP id 7so3761871pgr.2 for ; Thu, 12 Mar 2020 15:12:03 -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=Ek4JJAUTssPJkj2RkBPhViJS7YTAWApGGvcDEJPyfVjwRi4qYdcmYKSDA+y/oD3dex q2hTJ6OEOPKVCPi8GPp4CF4LAhMke1Cb1v6Tbc+Pm5K3zBzlUWfvs1gsylfZgJB2bYh4 dQdpaNJHV5+KkcW5V1eicGEtoJ45KIyMzGYXILKiAzp+7r4661o+97lpfIMdkYxsfNaC IG9WQnwPboo9rUHFvUxlS0eJTx1SNjitlX8Ikv6V61uzPGxH58gkFMWwCHWbo0oqw8kY R6T3ZWVG7fsN4Iw3nx0j8MNzHoiu9mxyVvAvSgvNRSIIVnuzrqoOp/9z53Fx0017tFPh 3JXQ== 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=JPDBw8YUVc9uvcHoPpx+IWNw8NLJhHy2zf4vl0LiylIcWlR090qgyfrYE4T8POPGbM diIV1TBhUuOCMZkP1nsN26t1h3RvJyBIR3H13nFqabFJylvGHu0/DKvfgIw4DOPv8yQf D334YXZ8isz0ht1QiOsDjLd/AnX0aZp8q2drZ76mfgCNKlN3TqVfn0iV7F/c2gNnd8PW 58wvykxvZqOIOJYvH1r226zy+jSPbs9v1JH1DKwhcE0nApB3j1Gmy5g29+UU2YbY8jvh BaNLuILyZJSZ1mIA/IirCvBOt+Rh0Mz0DDl9KZ+kWauZpMYbCyvi+NCXDqSWXZAKUtBN 8ErA== X-Gm-Message-State: ANhLgQ2Iuf9HhKfFlJJoJOfBs6UvRP2NtIR14sMQXJWpp6hWeTV/AFGS 2up0YHP75LKL754dgyQTJEE1TA== X-Google-Smtp-Source: ADFU+vuL5LJ12AY0ITSMBqKuOY02SWZG2pIYxohw4cmlu1tTrGfERNtDnoiyJ+9GPC5hotC+P2ZMPQ== X-Received: by 2002:aa7:9888:: with SMTP id r8mr8306988pfl.293.1584051123326; Thu, 12 Mar 2020 15:12:03 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id j2sm20945362pfg.169.2020.03.12.15.12.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Mar 2020 15:12:02 -0700 (PDT) From: Mathieu Poirier To: bjorn.andersson@linaro.org Cc: linux-remoteproc@vger.kernel.org, ohad@wizery.com, loic.pallardy@st.com, s-anna@ti.com, peng.fan@nxp.com, arnaud.pouliquen@st.com, fabien.dessenne@st.com Subject: [PATCH 03/18] remoteproc: Split firmware name allocation from rproc_alloc() Date: Thu, 12 Mar 2020 16:11:43 -0600 Message-Id: <20200312221158.3613-4-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200312221158.3613-1-mathieu.poirier@linaro.org> References: <20200312221158.3613-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 Thu Mar 12 22:11:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11435549 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 F329C13B1 for ; Thu, 12 Mar 2020 22:12:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D1CDB206CD for ; Thu, 12 Mar 2020 22:12:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="mnNIgAZh" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726710AbgCLWMF (ORCPT ); Thu, 12 Mar 2020 18:12:05 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:45878 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726513AbgCLWMF (ORCPT ); Thu, 12 Mar 2020 18:12:05 -0400 Received: by mail-pl1-f194.google.com with SMTP id b22so3211167pls.12 for ; Thu, 12 Mar 2020 15:12:04 -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=mnNIgAZhEkfbNmRvCDD4nxOEirRmHbxfaHD8eciCjCFfz3M+xZs56gFH0ufssr11JT DTTYTO3Dlm4F2mXINtStBj956pa7sqKeoMBDhldS8UPWxqJL1CAn5QaOzkcsURtZRXSG wmlMvnA9NpXWqxpErVQMeRyjbS2YBU2vPJ9unukW+FX5YoXajD+XRyv6g9wkNd6wiJxE FZcDtjb8DF7yAsU5xQ2p9XeBMgDkqirYR9ouwrtizmACkpSEfxRzqmtvRHaTAuh0JuVg unl0OHI+RzQ/07UNa7KV5AsCs24x8IvL7oRywW0/fRNpvD1TyPEpXL7uJQ0UQSyKn1ZS lKSQ== 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=XkLCRHujX/MizMGxcXJevqoDMeDJFPxtM5ct0J2E9GHD5riCsQ8eyIL76IzKLnkLgh aaoySLxGJFx025CJpKDolHBUkswifBfnZEvdZFGTpU2qi5WPQnF8tJrpuxQ2nJcdyw5/ P4YdtI+ZaDxBOvwbhrs5tJHjqIPGZRf3wmSU3Q73jtiT9qJfZaS4iqJfE/8OOFJIxuqq zDjeJJuWbDFM7Jdbs7UiJy8vdUUXtwDZot7tAXCUFBS2HNpDRSWvfRn9NlMrZ17a8Nfx PQ+JrRUYzl0x/mgXr88nKaiO9+y98xuzixpVoOUk5KolkFXTNsLIv7zxowPjJuD5mPDc t5Dg== X-Gm-Message-State: ANhLgQ2K01mlQAb3rX8Gr8vBWifc3gLct1CBLTFTo3isRmovU+a/sUyK rjNow8nyRBtdRAussUNcDor00A== X-Google-Smtp-Source: ADFU+vtueOVa1s9hQyYUTvQKGMxHGyEZiB1f2gB5sMbQyHQUKTN5wdooFevVmnDcmdURovjj7LZXcA== X-Received: by 2002:a17:902:34f:: with SMTP id 73mr9577679pld.50.1584051124344; Thu, 12 Mar 2020 15:12:04 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id j2sm20945362pfg.169.2020.03.12.15.12.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Mar 2020 15:12:04 -0700 (PDT) From: Mathieu Poirier To: bjorn.andersson@linaro.org Cc: linux-remoteproc@vger.kernel.org, ohad@wizery.com, loic.pallardy@st.com, s-anna@ti.com, peng.fan@nxp.com, arnaud.pouliquen@st.com, fabien.dessenne@st.com Subject: [PATCH 04/18] remoteproc: Split rproc_ops allocation from rproc_alloc() Date: Thu, 12 Mar 2020 16:11:44 -0600 Message-Id: <20200312221158.3613-5-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200312221158.3613-1-mathieu.poirier@linaro.org> References: <20200312221158.3613-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 Thu Mar 12 22:11:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11435551 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 9073692A for ; Thu, 12 Mar 2020 22:12:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6F7DC206CD for ; Thu, 12 Mar 2020 22:12:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="Hnj0kiHH" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726726AbgCLWMH (ORCPT ); Thu, 12 Mar 2020 18:12:07 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:40659 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726513AbgCLWMH (ORCPT ); Thu, 12 Mar 2020 18:12:07 -0400 Received: by mail-pf1-f193.google.com with SMTP id l184so3945615pfl.7 for ; Thu, 12 Mar 2020 15:12: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=8GchUXqImjod0MIPYLIdyQi94IM61hiNQIO0qzQ9Pt4=; b=Hnj0kiHHeDdK70HeJ2FaEBL5P6+5hWSQi24OtjNa2Gj/0KneIObuCq0NbjFe35u9U4 vmeG60xWh2r5vWq9eyPYGjEF9EADTdGGXy05nAgmnoA4J5rEh0IpHSKgIGZmneS74W/1 bRJLZheIM7YH45l2O5uNSnBzrB7dcqXPkvozPNXHls3bXmhM3M7zhT/t9/u5CeAq0PrV cPbJrHvSeSygSsZJf40ed1ZS7wV84HjCX27RihmlQCq9qZPvyAuHwoBiJhvldGvJ5dfo oPmODqGho1yZsynuUlO3HJDGkqJUmdDyR0OkdCs8KTt6zPFgDiPIchGKy/OqXgI0oY+j ubag== 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=lULRha1sHgI63UktKKt7grc2QachZhMD2B/MdIO8JC29K8Dyt2z9uNQMSFlwHPXAKw 33sDNzW6Lbunbgl7MA6F/GkT2ElUuT6/NJAu40MUGn/gHtv0j/E7wgrszJh1SUbVGptd QixQoFDoIFQnBLpcT5NkCeJETfMaZ8i1p6t/1IzMsZ0KSxEmN5PTAPBnBQfZlDucBsZN +QSW47TxD7Xlnb6amtDCcCbU6X0RCFSYo05XkHOZ4L/Rd32hLbx1yPVohYv27Y/LT/jF 0Mn+T+X04awpAGbJipJ8T1a4BlNQBtsv+W4MkZf0ytxWavRYCzDRYp1jcsr8sRKa5k2D 1BDA== X-Gm-Message-State: ANhLgQ01CuYwmtndFRpcUIY340MgUlaC/a+9s1V0sGEu6B0mJsDHeAJI 4ocAkkTJPVwK11xqS5yMy13ZBA== X-Google-Smtp-Source: ADFU+vu2EEs/qkth4QtFjVd8T3iiMjJPQ4G9gKL/d7sh2fiagCdve7ICh7sOZBpVaSpdrdDb6SRr7g== X-Received: by 2002:a63:7f05:: with SMTP id a5mr9851385pgd.327.1584051125521; Thu, 12 Mar 2020 15:12:05 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id j2sm20945362pfg.169.2020.03.12.15.12.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Mar 2020 15:12:05 -0700 (PDT) From: Mathieu Poirier To: bjorn.andersson@linaro.org Cc: linux-remoteproc@vger.kernel.org, ohad@wizery.com, loic.pallardy@st.com, s-anna@ti.com, peng.fan@nxp.com, arnaud.pouliquen@st.com, fabien.dessenne@st.com Subject: [PATCH 05/18] remoteproc: Get rid of tedious error path Date: Thu, 12 Mar 2020 16:11:45 -0600 Message-Id: <20200312221158.3613-6-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200312221158.3613-1-mathieu.poirier@linaro.org> References: <20200312221158.3613-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 Thu Mar 12 22:11:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11435553 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 B4AB692A for ; Thu, 12 Mar 2020 22:12:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 942C620716 for ; Thu, 12 Mar 2020 22:12:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="fiBTipyR" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726738AbgCLWMI (ORCPT ); Thu, 12 Mar 2020 18:12:08 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:37797 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726513AbgCLWMI (ORCPT ); Thu, 12 Mar 2020 18:12:08 -0400 Received: by mail-pl1-f196.google.com with SMTP id f16so3229298plj.4 for ; Thu, 12 Mar 2020 15:12: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=tFxiWY+kpD9874R08QypyBmwovyVbSqxX8VrEMv/frg=; b=fiBTipyRr08lPmdwYLAMi4kzK49oaPHip+yqgjtKO3PdaY14QQejruX7kDWDeXHFDm IIA3UlY6GGSqfBfWAWPFPieqFWxA7sOynQBjzUeNBP3dQKOcfDjcV7gYbQle9MHlaH0/ RMYRtXmBEO+GFazN5lwxUScDivBYJ4yu+nNVw537CqYdo7hcoJrGYfHLA7Geze0+yvy7 w1MrW9oSEXYVltlKf2UiYjR4A3B26F0UqT/vCO7wBRKXj11uUUuh/EwUxthQmjlkU0vd gwSHS3A4Zs+k6V210LTYk9V+BxTjO1Jq7gtF27A5paQwD3udZ0RinzzsWavyO3PIdtU9 uXhQ== 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=M8mghrktwKuMUaUrCLzuUoYjcCizV8qH5P5flv/650fLd5Oob9wpEppyT83XjNwN4G FrDzGhQEXEEMQRfEyVPn1X/iBkq4g/w8PvHZToz9usvK4qwYzqKY0yNuqyruMCrOMqk2 1FVgapSrgYtaxNw960OMLlUN2rpo3Q8QyhNeOIH5+yPkoWHOhz35a9s6dKBi8fIezLas sjLs8zOZkTSKMeCMvZEm9P9ar7zXFqXRHt58xJ2YBctzGt3UI9nnhobtJ7SlmwObgNO1 jJ3/+VuU//bv15qs0i/PVwxUGQUm1tuEB6YlAMYo/gOU/lscajiGiSgBCSsE8L8p/M0c b/Dg== X-Gm-Message-State: ANhLgQ2sD1/bmwWpphKSJZJ1C76Ys1K8A8qMfPUbCXC3vO0co47eN++a A12/hi3Vo//BRZBlSj51MeG5jb/QXl4= X-Google-Smtp-Source: ADFU+vsFTAPctg3t9oifDveiFQdECzEDzAm0IJNid/QduFnntZe/yd/3D/nvoxuOzSrXUYtuKxM23A== X-Received: by 2002:a17:90a:2489:: with SMTP id i9mr5996242pje.183.1584051126579; Thu, 12 Mar 2020 15:12:06 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id j2sm20945362pfg.169.2020.03.12.15.12.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Mar 2020 15:12:06 -0700 (PDT) From: Mathieu Poirier To: bjorn.andersson@linaro.org Cc: linux-remoteproc@vger.kernel.org, ohad@wizery.com, loic.pallardy@st.com, s-anna@ti.com, peng.fan@nxp.com, arnaud.pouliquen@st.com, fabien.dessenne@st.com Subject: [PATCH 06/18] remoteproc: Introduce function rproc_alloc_internals() Date: Thu, 12 Mar 2020 16:11:46 -0600 Message-Id: <20200312221158.3613-7-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200312221158.3613-1-mathieu.poirier@linaro.org> References: <20200312221158.3613-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 Thu Mar 12 22:11: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: 11435555 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 72BFC13B1 for ; Thu, 12 Mar 2020 22:12:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 47E33206CD for ; Thu, 12 Mar 2020 22:12:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="IdJEe3Ml" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726752AbgCLWMJ (ORCPT ); Thu, 12 Mar 2020 18:12:09 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:44657 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726733AbgCLWMI (ORCPT ); Thu, 12 Mar 2020 18:12:08 -0400 Received: by mail-pf1-f194.google.com with SMTP id b72so3938900pfb.11 for ; Thu, 12 Mar 2020 15:12:08 -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=IdJEe3MlLfHau72h39BVF1HFP4qncbdfY8qJ9CMM0GDfZWZjSLwF8Be76nWC996uY+ 9kwYU2RnhLwIIvh02jZ0PsY+ky/EEaUUkRAeboJ+yjPyM4y8pAcgtyJ7OyzvjwRsTghW C/MXPknl/a0NRbieh4OadIZAHMUZCIh2bclw+J8cAgAapx45NzYJczlk7zk1wu8DPYkH ThuSYVQxngtEuXyi2AQt7AeJpiV3lMkMcgBx9hhYC/JKgtCf9f+lrrJOt/OlagAYGdec 7+A3Nl+5naNPuq++rvHiw5E/CH/GTSEFV7jK/KnNcPHEuVKdAGB7dN9Vn8vQ98sBgJoV 7ClQ== 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=SM+58xypzeRhqtwYDNphf3oWvhru0cgC/y5sPksBG6D0xcQRxiURFZtTM+9DI+nKr+ 9pNhvPgOF0etO94z2R27SD4xu9yebaHj8p5ahMm2cAAijwRulQFQUjseYeUVEbFyt+rr iaLyAziPjbRqmrJj8OozwSphhF0Ollu8cmsMXbo0oU8H++0GQ6To9EPtRXJjJeGBpyX8 HZOaW36tamIyE5Bals9vXOLpvHI3/Hq++tKa0P/rlK7JqoLxp44TeGZt4grEHLd1fHcK 8ycZ45JSkRrvob7k7fvZpI51+WFTLPN/dGYRHVTgMZasMB+GZ+G9AAF/cgecKZ4e7XpM 0AqA== X-Gm-Message-State: ANhLgQ0XzoGhDQwIvZNkTNhBwEyea6H8z9Xcppb3qrPa8o11mnkmNCb9 GziGpQKoY/1kNaq4+56rIN4ouw== X-Google-Smtp-Source: ADFU+vuDCAohmEgv24TynF+hS6+qXPyphFkRxvopMJJtA0LWYTFlQQWT5JIWAoc1NC47CT+5wA7q7Q== X-Received: by 2002:a63:3d48:: with SMTP id k69mr9394734pga.395.1584051127711; Thu, 12 Mar 2020 15:12:07 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id j2sm20945362pfg.169.2020.03.12.15.12.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Mar 2020 15:12:07 -0700 (PDT) From: Mathieu Poirier To: bjorn.andersson@linaro.org Cc: linux-remoteproc@vger.kernel.org, ohad@wizery.com, loic.pallardy@st.com, s-anna@ti.com, peng.fan@nxp.com, arnaud.pouliquen@st.com, fabien.dessenne@st.com Subject: [PATCH 07/18] remoteproc: Introduce function rproc_alloc_state_machine() Date: Thu, 12 Mar 2020 16:11:47 -0600 Message-Id: <20200312221158.3613-8-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200312221158.3613-1-mathieu.poirier@linaro.org> References: <20200312221158.3613-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 Thu Mar 12 22:11: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: 11435561 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 5F2201668 for ; Thu, 12 Mar 2020 22:12:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3CDE2206CD for ; Thu, 12 Mar 2020 22:12:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="Pqqw3b1c" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726828AbgCLWMK (ORCPT ); Thu, 12 Mar 2020 18:12:10 -0400 Received: from mail-pj1-f67.google.com ([209.85.216.67]:39845 "EHLO mail-pj1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726733AbgCLWMJ (ORCPT ); Thu, 12 Mar 2020 18:12:09 -0400 Received: by mail-pj1-f67.google.com with SMTP id d8so3222765pje.4 for ; Thu, 12 Mar 2020 15:12: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=Pt7wDr4fqIMluK1YQKun6+ciCQDmnXKa037aAN4VvN0=; b=Pqqw3b1cGrDYt8qTciWQLdTFdP9cN5eyul6oQY2VWxuQIR+3gu/brPlYPz8bH80eDP wweBnZZyulcgHhHNxbtYblElIXJyH0FkH7Kwl4p5ofdDUhTPP+iPxqG4pvs94IhUDZVS 01wmp2txSX/qsEO7SIXNcJxH10WhCgTmhpNRXnCXsjeJic3RhNcy11q1qpbUdcxeiFvj JDUzrXCXb0v9sFObvGpCW1BdrpmQRYvFuhXgjbiyNfshGBcRfTnIrLx53H4hAGAfuksV zz6xGyauAGoZBFZNXuyE3qzG3ByFQKy1fm/BFZjtxJohPncs82cVI/SsnaX6zZmsiJS8 WBbg== 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=HCrf2SV1qq5gKLd8mS2nRsUU4Gw5nf9XYRCrjmUsFNehsu9P+0O/UDeF0xwts/NMTn 1cd0rpRzauchGyhGPPfJIbJ1WdMdP2bHdS+uMgCOYdzL911SVEb4f7xdKj5EVnhyewqK EDGbkdTy007TqIc1pBlTptW/GKE80AHwYGsQzSvrP84BZ5L9++ijXAsU2ucwfg8dbulU WbYMyqFHLbykGQJFZxOBLuNiGILHvR4lXauzgpxaUcchq4k3mqBMYin0QJy+oGnMpNzt kQReCymBDU2twNSe+/xSbif1RQ1e6x9r/anIuaMGi4+nwn+eKgSd0KWt5PZ4KX6N6ezz iTCQ== X-Gm-Message-State: ANhLgQ2Ag0RwA5wuGGqmPPiGtQmXDekv5N2rSZX4jaXSlHfEshGhb0t9 6JzhFGA5JRbDV/y7ftsfNc4giFhzNnQ= X-Google-Smtp-Source: ADFU+vsD3SKeFtreDq1UF7IqCuaUpNyMM3z4oCMait0xcf8w4h8rlU0B1M0m/opDROsRD0oS0NC2Nw== X-Received: by 2002:a17:90a:7f93:: with SMTP id m19mr6020436pjl.92.1584051128822; Thu, 12 Mar 2020 15:12:08 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id j2sm20945362pfg.169.2020.03.12.15.12.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Mar 2020 15:12:08 -0700 (PDT) From: Mathieu Poirier To: bjorn.andersson@linaro.org Cc: linux-remoteproc@vger.kernel.org, ohad@wizery.com, loic.pallardy@st.com, s-anna@ti.com, peng.fan@nxp.com, arnaud.pouliquen@st.com, fabien.dessenne@st.com Subject: [PATCH 08/18] remoteproc: Allocate synchronisation state machine Date: Thu, 12 Mar 2020 16:11:48 -0600 Message-Id: <20200312221158.3613-9-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200312221158.3613-1-mathieu.poirier@linaro.org> References: <20200312221158.3613-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 Thu Mar 12 22:11: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: 11435557 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 7033413B1 for ; Thu, 12 Mar 2020 22:12:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4EFE220716 for ; Thu, 12 Mar 2020 22:12:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="S4PtbD4o" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726898AbgCLWML (ORCPT ); Thu, 12 Mar 2020 18:12:11 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:40965 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726513AbgCLWMK (ORCPT ); Thu, 12 Mar 2020 18:12:10 -0400 Received: by mail-pf1-f195.google.com with SMTP id z65so3946790pfz.8 for ; Thu, 12 Mar 2020 15:12: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=1sBTPlRpGe/+85skyuSnsqWL2n7rjq2O/jQYsM8CMr4=; b=S4PtbD4oQAgUhOROL2L30qhN38KlsoV4ov3C2TQX91scgVZMMLoPTRsvzC4PdhMHAG n17ZjGdrytIz++w51QruwqLzyzey7TWxPqw6NbtQpyhP3osly4/BHRYxPWtK5Vqqb4ym F7H5I3QLqm+3jXeC7x6yPtIyFquLyt+NEFeL0Yijn8vjbdC51zcMnmCKTHmey15LifDj XCFoM71R7W8o69TN+fqvUkfG1df5JPgnSlQvA2q5Sy8VcjYxik3eSL4GplmvHzhEvWBv IVp/j5cUyT4cBWPLrjNfEywyr6VV34kmevRsbPKrGSx5KrrQDOlQ+AFDMvg1XhF6tbow DEWw== 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=1sBTPlRpGe/+85skyuSnsqWL2n7rjq2O/jQYsM8CMr4=; b=ZozMgkOzcMr3y4ir5Wbh25XHBHcy1uM8GxLwk5iVK5cTr/5rQn4EAxexgBIWat3eZc +OIugOXp7jJTZdT7BSyjqZCHE3gX6bza1aozn4KDyJ7KzNAoU5VXCSofD4ZbNEux+ClH LKMQ3inavGzC6C/vcoDMPF+LKYRzGLIVdDBES2oodCV9t8FtBY24Db6jIAGvSFUh0QKw p8J4HuWYhEtImrgK90x9lLV87s92IXqYsGHOY9D10zPiU26uJB0JNzjNg6PNRjO/GNXs 7S2r/UqSz+HUB90f6hKmlJrQld4NQ7eIevQECQQN5hH09vWoFEFMpjyns54rLT59Xe6D kMdw== X-Gm-Message-State: ANhLgQ0cz0oF2ceFKYax//TFz5slDGt8HYPrViioCbaEyV1c9p35S0xR FsG4mC05pMiOqtQRY4wPAnS+ow== X-Google-Smtp-Source: ADFU+vv425DJJoNxhoQvLTcPZv2X8FmBvawwcZ6QywDLMyXBiwgww7/CjuEy9WlQWrx3u9lsF2+i8Q== X-Received: by 2002:a63:ea4e:: with SMTP id l14mr9907712pgk.431.1584051129939; Thu, 12 Mar 2020 15:12:09 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id j2sm20945362pfg.169.2020.03.12.15.12.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Mar 2020 15:12:09 -0700 (PDT) From: Mathieu Poirier To: bjorn.andersson@linaro.org Cc: linux-remoteproc@vger.kernel.org, ohad@wizery.com, loic.pallardy@st.com, s-anna@ti.com, peng.fan@nxp.com, arnaud.pouliquen@st.com, fabien.dessenne@st.com Subject: [PATCH 09/18] remoteproc: Call the right core function based on synchronisation state Date: Thu, 12 Mar 2020 16:11:49 -0600 Message-Id: <20200312221158.3613-10-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200312221158.3613-1-mathieu.poirier@linaro.org> References: <20200312221158.3613-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 | 35 +++++++++++------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/drivers/remoteproc/remoteproc_internal.h b/drivers/remoteproc/remoteproc_internal.h index 73ea32df0156..53d63ee2c8bf 100644 --- a/drivers/remoteproc/remoteproc_internal.h +++ b/drivers/remoteproc/remoteproc_internal.h @@ -106,38 +106,40 @@ static inline void rproc_set_mcu_sync_state(struct rproc *rproc, } } +#define RPROC_OPS_HELPER(__operation, ...) \ + do { \ + if (rproc_sync_with_mcu(rproc) && \ + rproc->sync_ops && \ + rproc->sync_ops->__operation) \ + 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 +147,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 +155,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 Thu Mar 12 22:11: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: 11435559 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 2DCA592A for ; Thu, 12 Mar 2020 22:12:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0142E2071C for ; Thu, 12 Mar 2020 22:12:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="AtzT6ed3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726901AbgCLWMN (ORCPT ); Thu, 12 Mar 2020 18:12:13 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:45347 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726513AbgCLWMM (ORCPT ); Thu, 12 Mar 2020 18:12:12 -0400 Received: by mail-pf1-f193.google.com with SMTP id 2so3934637pfg.12 for ; Thu, 12 Mar 2020 15:12: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=FD0VTjAKokoI3E/7TSv80ZTX/OnmyOrZGmVSUVDTIJg=; b=AtzT6ed3RKo+TrBHWC/oRo/qy++U+kIyg8pEz/cAcAxFalTsfaNdcddt59hyBGMNEX 98z9yUyFG9eUnVqaey0BfiviUAngHMxHU21vQddA50UDn1oQesci2jnws/tLmTQKuqB4 rTL2jXB4JwlNU4EVGZN96IuPoDoki+B6xC0y16eiqSiNUM1k5W0bzbZH4/jJTt46OTfO wglG+BgrzMFltQBVUnbsLXa5zw6/uE003dJ25gpo4tRW/xQ260N/nfJfKv0hZ6Rse9NS m+PaVtH/Z+en8tP9A0aGfaYaIaL5O+X3vGx+enbSJyjSSaoAD7JdBkNDrq8G0uYkpFwI 6biw== 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=RPVEq0yJjac9C5lR9JoTHD0fyd7VwvXFjVQUFfGJTYKKZdRSfp8jh8xvisMxs/Nrm6 of3V/ebFnoSgwnE/n+YMh12Y3D/Dq/J/1rrH1iFg5dTna/pkfdGJdSJPUFv7VOKWiKTf Q17dhd05g5gjTWEefNuvW/o1JwogYqVUoneE65XlTfTc3XNE9vuQ8Ha+iLmYlJY90/bn jsohhB7HsSnyKdXfAoyIXZ2imjKnprunX+4NQdhg+orvohsGX+1Jj6SpxHPOp3EaJX/A ktrmUYmNGzDBbdfiP7ZMtlC7JeJ91GMXiA1vufZqpn73jBlM/GXwakS2PvrAuLAGwhmI t6lA== X-Gm-Message-State: ANhLgQ1uICQdsw6+Bd8RtRrdKL0emlSG2bpg1ROmlVLthCuf9F4gpTzM e/IjSe0tsfg30Zl+EoQPIEjxAw== X-Google-Smtp-Source: ADFU+vsNlTT9sk4Q7XMlGIB6bczoRUD+KopZ+EHzv7lRdNg8NnDkGjfii6ucP3dIao6OdeMgEXxNcQ== X-Received: by 2002:aa7:96b2:: with SMTP id g18mr10558338pfk.221.1584051130996; Thu, 12 Mar 2020 15:12:10 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id j2sm20945362pfg.169.2020.03.12.15.12.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Mar 2020 15:12:10 -0700 (PDT) From: Mathieu Poirier To: bjorn.andersson@linaro.org Cc: linux-remoteproc@vger.kernel.org, ohad@wizery.com, loic.pallardy@st.com, s-anna@ti.com, peng.fan@nxp.com, arnaud.pouliquen@st.com, fabien.dessenne@st.com Subject: [PATCH 10/18] remoteproc: Decouple firmware load and remoteproc booting Date: Thu, 12 Mar 2020 16:11:50 -0600 Message-Id: <20200312221158.3613-11-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200312221158.3613-1-mathieu.poirier@linaro.org> References: <20200312221158.3613-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 Thu Mar 12 22:11: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: 11435563 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 B9A9D92A for ; Thu, 12 Mar 2020 22:12:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 97A5E206CD for ; Thu, 12 Mar 2020 22:12:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="SCVgI5Xt" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726908AbgCLWMN (ORCPT ); Thu, 12 Mar 2020 18:12:13 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:37594 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726814AbgCLWMN (ORCPT ); Thu, 12 Mar 2020 18:12:13 -0400 Received: by mail-pf1-f195.google.com with SMTP id p14so3959230pfn.4 for ; Thu, 12 Mar 2020 15:12: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=vEoXsLC+v8mX4Vj+t+8zprwRGYdue84ZJZhMv1TU7d4=; b=SCVgI5XtVuEAaxg45te/VTYpHWW864jeuIp4KtBoTO0VM++HlKKMQ6DGyjW0f1D9dE prII1dfHfBmiKXI3qAeuYYW8I/cNyxW8O2XOrTMJoHw6YPfBJdsL+jEdbpg+ZuE75Dw+ UH2nGYJRUzJMZ5g/4F48q6sCipF2ZF3wZsJmYCZWO/3TbyS30soNDtWVK1hsaY626VmE AplJFKkkEtKIYq134wpLxaFp3lt36SkUeeQCotNbguCK37DATHIyVMlLFBvN8HjN08ox wbv/Ar+gnHI+J7p36ymcqTW+6wWUz88krY9t486xMELO0Vak4V0UxOukALZmkcuDjwWl 4CjQ== 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=hU9F8VEBpTlMCCeGw00UOSmzhF35qJ8ZvIq2G5IcfNKitpv9EDEFIO7Yo8tMQeb1Lc Atdpo8kyuYhP3ed1CQzRt/QYPxApfVQPXgR9SUy2G+OzNbpWXWZnmLm4DeEXX1kzqEsf 8tYax/eBYT2pgXBhAGRz4f4+Xiz5xcTq7E8qacvElli7u2qrOMqqPdyLOSFxvUUi6mqq LjNlmM8CLvjBfBsXYgy07VeQqVMj40mZZT0A3i3kcJZFuZSaetAZWMi0x5CROg1blaY1 6bqAVc57bOfwgvW1mc0Fmm1ywln2zhfvuLexlFPI+oFw/TNAOi4Qm9+Wb70xBQJOD2g2 qK8Q== X-Gm-Message-State: ANhLgQ0xpm+8S/U4qKJeyyihiIgHYT4NA0sm2tKH2y/ATjd4W7Kbjmtm 5HpY9Fh1pbcXfVOLwAOQpdbVJg== X-Google-Smtp-Source: ADFU+vvA1I4Lz9JWSZlABTRE9oXfu8PPIMhcQXdAwmtq1XDXEuKqM7yXOBhIXnywvfB0wLdWD/Gl3Q== X-Received: by 2002:a65:63ca:: with SMTP id n10mr9509453pgv.19.1584051132153; Thu, 12 Mar 2020 15:12:12 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id j2sm20945362pfg.169.2020.03.12.15.12.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Mar 2020 15:12:11 -0700 (PDT) From: Mathieu Poirier To: bjorn.andersson@linaro.org Cc: linux-remoteproc@vger.kernel.org, ohad@wizery.com, loic.pallardy@st.com, s-anna@ti.com, peng.fan@nxp.com, arnaud.pouliquen@st.com, fabien.dessenne@st.com Subject: [PATCH 11/18] remoteproc: Repurpose function rproc_trigger_auto_boot() Date: Thu, 12 Mar 2020 16:11:51 -0600 Message-Id: <20200312221158.3613-12-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200312221158.3613-1-mathieu.poirier@linaro.org> References: <20200312221158.3613-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 Thu Mar 12 22:11: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: 11435565 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 E429313B1 for ; Thu, 12 Mar 2020 22:12:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C23DE206CD for ; Thu, 12 Mar 2020 22:12:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="L1UVGnRz" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726909AbgCLWMP (ORCPT ); Thu, 12 Mar 2020 18:12:15 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:44914 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726513AbgCLWMO (ORCPT ); Thu, 12 Mar 2020 18:12:14 -0400 Received: by mail-pg1-f195.google.com with SMTP id 37so3746365pgm.11 for ; Thu, 12 Mar 2020 15:12: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=oTShSnKJqR8hoHXMOzKwWtyGKqtTdUnapLBABWvOQ/c=; b=L1UVGnRzsnRw8TqXBR9Wh9CsgNrENQ/iaVNF37wJlBZb1i9H80DDC1vzlGD3+XSBdv DMxeLPDxDvrUB854qd4XPasnaN+YT34SeDycxjCmElfkSDXpw0VtH/I5D30Vh1Xn8fs2 FwOHWr8eBpwfVASpjhioIXDz3MMrXSaCr5r7n6+m1D5/eGOF1eoS3DMaqnvYv10ZPdy0 FfAnLSUhoKRZeyxBytkmQsTnKfiHc88EjwjPslii8IOSZCiwPp/MZ2mXmpyAMp1VXuu7 XttlDLwF71UMEp7Xdlk99uJGkXK9Iso5Jgo9XeZHIIE0CMNH6iUjRODRFdPGH7CYKlut NfQQ== 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=oTShSnKJqR8hoHXMOzKwWtyGKqtTdUnapLBABWvOQ/c=; b=rkYldF85HeY5Msu415Awuq5Sjtz6xOe/U4HKcXTw8Zl2bKY1307ZkhF0E2jMMjmx8X XD35+fiMm/rZGHLVlXgJhGwyJ6fTFjnFCFQ+es1ctcBOUMqsVSGZsdh4quM9PtzoVv1L lDWZu5FfRpiqVHcJiiZJI6kyrG3C52FgbAcOwFF1mDTON+0G+JLShHGs+IHgJ7r9vJqn 3NdNF7wTrj6kVPxqjOq+oXjNeFpjnX6GEuvjYRSRX8iVtoVoCA9pqDJwD/dgxsthS26N D6O40YDjB19FMaisy3ICk5ajRegee5naP+XolmtWl6Uyfhb40jJYZJTZMIZf60fP3M5f YIJQ== X-Gm-Message-State: ANhLgQ0Q3OfmJ5vjFGLeBbs5B8ufY3IIcZqZurGTT1JijM36fXhW9uvL 6+avRzMs2chQTCftaO+c7R4gRg== X-Google-Smtp-Source: ADFU+vujmYOTFrP6hnXD0ve4i9OUEKyJGAg47lxi/QvazgroRQMVEbEecRh1L9bhQaZxFkOJ+gdF8A== X-Received: by 2002:a63:8342:: with SMTP id h63mr10079678pge.141.1584051133228; Thu, 12 Mar 2020 15:12:13 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id j2sm20945362pfg.169.2020.03.12.15.12.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Mar 2020 15:12:12 -0700 (PDT) From: Mathieu Poirier To: bjorn.andersson@linaro.org Cc: linux-remoteproc@vger.kernel.org, ohad@wizery.com, loic.pallardy@st.com, s-anna@ti.com, peng.fan@nxp.com, arnaud.pouliquen@st.com, fabien.dessenne@st.com Subject: [PATCH 12/18] remoteproc: Rename function rproc_fw_boot() Date: Thu, 12 Mar 2020 16:11:52 -0600 Message-Id: <20200312221158.3613-13-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200312221158.3613-1-mathieu.poirier@linaro.org> References: <20200312221158.3613-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 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index d57b47b0d6be..36c4d0f13ae9 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; @@ -1756,7 +1757,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 Thu Mar 12 22:11: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: 11435567 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 A904313B1 for ; Thu, 12 Mar 2020 22:12:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 87A47206CD for ; Thu, 12 Mar 2020 22:12:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="sQFmU7K7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726513AbgCLWMP (ORCPT ); Thu, 12 Mar 2020 18:12:15 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:46215 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726814AbgCLWMP (ORCPT ); Thu, 12 Mar 2020 18:12:15 -0400 Received: by mail-pg1-f195.google.com with SMTP id y30so3740239pga.13 for ; Thu, 12 Mar 2020 15:12: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=h/xfDWgWz4t2faWkW26xyNxR8CH/uChKJRUAVNNVX8A=; b=sQFmU7K79cej6jvKQClZa/2Wn5rYkfXSzv5khzyi48/WbWS8snbiuZm9vZZppDUkdL tabnn+XpOjlWbY8V50yTDfdLkhiVjG3ScmXfW0kUIAATDrWddtw8QrP8uzrDkdm9MtB7 aQZAw/r2jbvh770qCgc20hc+QSa2U3vDb+VBox3DKuS42iW3JeVYNS+CxKC2GbWgrkSe rJBry985hjqEgqVn2BCQzZ+CC1lhxJOavXy0TWDAgpa6/8gNcutovvkoI6kE1ohjV7Nb UYbXTdo1QNYwdLZPZbQNo9JNyhJKXBpKabyX/lEV0SejrK57OaOCH6PIIfr6bHudozFB pmig== 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=h/xfDWgWz4t2faWkW26xyNxR8CH/uChKJRUAVNNVX8A=; b=PSiOP8crKYb2ejF59NMC5lXKuaFYGykU0vO/enax6iH2lz8PClGA362yLYnW8BRN7i 5wPB0y2hV/8xxQvm+bxct3Z0O1Bjrl+o5Akm+eebJowIhGgyoromcvYdzQSPyxAzXJBA uhvbCpIblz0WLYuUWh1rNBHYB8fdezv4c48xgyYU2g+oIHy4+IoXl74LbdwHu/3Jaidt isQcwJFUqWhTtELLzZucxH2U/RY5i5dxQ2pp1QxYJZLkqEIYY4jttk3aL8eoZy1/A8jE HBADafBOrV3jRZ/JZVXNSvyfFpd65nx3pdx7GnY3MsDLzanmWQFGkKZ2AwrtcMP2pTVk gZfg== X-Gm-Message-State: ANhLgQ2NiW3uy+uxU2SnHXM5n52YqSwaIyr6Z7uowIXq6yTDEX8KFu6F okGKTNDA7+Lt09Qpk5gX80Tgxw== X-Google-Smtp-Source: ADFU+vvO2Fk8U07HkOm4KBwBtGa1TYecjIEL5/MieQy2GHTXhqqga3xito501sg3G34MJbGLVgsGjw== X-Received: by 2002:aa7:9588:: with SMTP id z8mr9919549pfj.240.1584051134333; Thu, 12 Mar 2020 15:12:14 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id j2sm20945362pfg.169.2020.03.12.15.12.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Mar 2020 15:12:13 -0700 (PDT) From: Mathieu Poirier To: bjorn.andersson@linaro.org Cc: linux-remoteproc@vger.kernel.org, ohad@wizery.com, loic.pallardy@st.com, s-anna@ti.com, peng.fan@nxp.com, arnaud.pouliquen@st.com, fabien.dessenne@st.com Subject: [PATCH 13/18] remoteproc: Introducting new functions to start and stop an MCU Date: Thu, 12 Mar 2020 16:11:53 -0600 Message-Id: <20200312221158.3613-14-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200312221158.3613-1-mathieu.poirier@linaro.org> References: <20200312221158.3613-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 36c4d0f13ae9..806201af9470 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: @@ -1483,7 +1483,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 53d63ee2c8bf..73a71ae12c01 100644 --- a/drivers/remoteproc/remoteproc_internal.h +++ b/drivers/remoteproc/remoteproc_internal.h @@ -159,4 +159,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 Thu Mar 12 22:11: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: 11435569 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 6D3C092A for ; Thu, 12 Mar 2020 22:12:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4BCDE206CD for ; Thu, 12 Mar 2020 22:12:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="GHNsrf4r" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726832AbgCLWMQ (ORCPT ); Thu, 12 Mar 2020 18:12:16 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:36773 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726814AbgCLWMQ (ORCPT ); Thu, 12 Mar 2020 18:12:16 -0400 Received: by mail-pg1-f195.google.com with SMTP id c7so3767012pgw.3 for ; Thu, 12 Mar 2020 15:12: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=vXhYKsEgtOtgmS2aSTH+9jrtvT5eBwGnQHEbD8f3LS4=; b=GHNsrf4r82idDLjJS2AHJnlBPM6GEbxGK0jOAdX44HLAjVn4joEGbqk6+nrTTtXiL8 6L+yr3xaYccZHD3RvVXnD0XZ5FK+2tuw3W7bXfxLIk7UxwhwW9TiMyYF5CpsxbNK08IT 1VO9ZFdiPLEzb0L5JttOfJhK9UlPSXJteWuFcllVUOp58wairbSGwBKzWzydMNORxQf5 BtWtsZeo1oOK4iMRAf+JxQdHMDKqyGlBWKRYotbWXdBCQPkTiSkfIaOayCSPfObnC1PU hrmCaXQpOmF6RgiCRdJ7vJLz8r+E/G9DQxBjz9fiy4fHwD/F3aeEkzxb3KhTEpWzu3UI g7gA== 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=vXhYKsEgtOtgmS2aSTH+9jrtvT5eBwGnQHEbD8f3LS4=; b=AiviNu3rW40jDhg7dUInX4dzkg7sAGeAkF1NuI+BoMIcEgfovk5fOqGBxS4yLqG6a6 cSoWl5p379qCbjjIaeUJaNcgHFDHKnSB+ka5MlpXUCMGGn2Udc62ZkmBr746ZExuxZMP xceLVCZty+BRka5q/TaMOHU70ocar+zeNMIO1djv3Bz9gwM3Kz5g2YzAYC6YujGEsdtg 79q7RpvZOmPl+eX9pu+KCfdx+7HmWG3rhgTD4eBTl8JQ6vr0Vwr2QZ0b/865ps/m8/in OqwrD25l1toe9wUGvGqCuZP/7c/PjarW6XqD+cCeXTBLB51GFULnm30avy2BNogqbhuO 5t2w== X-Gm-Message-State: ANhLgQ1tqVMQtlDx898gMHvf9H5rZuVQGVlriFV4r/LE/OQwKdOqUtuv JEKkILmiO0qYU+uGotYA7WITovWgP78= X-Google-Smtp-Source: ADFU+vsE2mHV0veywNiOl1WQtHYDlMdkrAltxtd+XxZXrYLdh90LH1fQGQJgzzIGFWE05nB2iXUBFw== X-Received: by 2002:a63:5f41:: with SMTP id t62mr9662004pgb.114.1584051135609; Thu, 12 Mar 2020 15:12:15 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id j2sm20945362pfg.169.2020.03.12.15.12.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Mar 2020 15:12:15 -0700 (PDT) From: Mathieu Poirier To: bjorn.andersson@linaro.org Cc: linux-remoteproc@vger.kernel.org, ohad@wizery.com, loic.pallardy@st.com, s-anna@ti.com, peng.fan@nxp.com, arnaud.pouliquen@st.com, fabien.dessenne@st.com Subject: [PATCH 14/18] remoteproc: Refactor function rproc_trigger_recovery() Date: Thu, 12 Mar 2020 16:11:54 -0600 Message-Id: <20200312221158.3613-15-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200312221158.3613-1-mathieu.poirier@linaro.org> References: <20200312221158.3613-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 806201af9470..7ea4397a9004 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1659,7 +1659,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; @@ -1676,14 +1676,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 Thu Mar 12 22:11: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: 11435571 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 8F92792A for ; Thu, 12 Mar 2020 22:12:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6DC1A206CD for ; Thu, 12 Mar 2020 22:12:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="IAiyvPZm" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726863AbgCLWMS (ORCPT ); Thu, 12 Mar 2020 18:12:18 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:34837 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726814AbgCLWMR (ORCPT ); Thu, 12 Mar 2020 18:12:17 -0400 Received: by mail-pg1-f193.google.com with SMTP id 7so3762162pgr.2 for ; Thu, 12 Mar 2020 15:12: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=OyAEH5Ogm2ev5rgwlfYAIWzzoyq+qykv1xNnTlFgbyA=; b=IAiyvPZm32U6z3XsX+mSpRQZ1E4PFzGOC2cu6jj0rBvvPG+/l7nAckIiCw7wQJgC98 Fi/SKwJbo7crVx3LjE9LntdIikWlspWBYb93YO6fW5sz/8vjINy87ShsaY/SV6JHxZZt fOEqjC349KXOZg8A7WSBLdabyEc/XvboFmyF9ES3aEG790AbSlUhmWhYbfWGQYc96x/C GmlZwlInVtlqtp03QrJoSxSkZnpkurbvJUP+5ut2+yzbf4RdPadjLrIhHpLQgRLT/Z3z LkcD+8+DURX1Jp1mPudG/+iH8T/ipNUoycUsrdHQxRQAmx1hVQHHppAwGFudwBS7e8rl yI0w== 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=XBn/xF1SFN8aywChR80yNkUaBWZfTW7dNXcDPiV7ZAg+7rSl4RQjdwltMPYDKC1tg/ OuOx64Mn+BLPEEPahC1CFnlvYBgGG8FL/nLq/58T078bTHO8JCO9KZub8J4PMvA7Hevt 792lIiPnv3LLktMmUeuUIPrsvgYW5wiHbIlK8ahJ8X60OmxOyqGXuVyMIuL5cTTnUC4r IIEt1DVpRVfYkb7jvGo9u8IFSkDNG2zwKgjTh5m5JotWeCHiyjZGUK3yPFO0D/ZnOu0p rM1nc0xL7JEgVU+e00ZXdY8wWkYCmFiyNcR1Ai+8EgkdGv9ILlnT0QSr/ZgMnxXMonhA JB9g== X-Gm-Message-State: ANhLgQ3hEff717yGvVDcz1KJugfFwuD6N6LCkAEagPHI0jJ+i0E8lno7 fVx9qXOTZYgIEsJsK+Gb/SALlQ== X-Google-Smtp-Source: ADFU+vuzHxWCeYNEf7MKu4lwaKllQEoaRR90gNFZmapLIbQ+eCMrF6mBzJcaTMLeXJU7qnJbT2Rxgw== X-Received: by 2002:a63:5547:: with SMTP id f7mr10046223pgm.166.1584051136698; Thu, 12 Mar 2020 15:12:16 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id j2sm20945362pfg.169.2020.03.12.15.12.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Mar 2020 15:12:16 -0700 (PDT) From: Mathieu Poirier To: bjorn.andersson@linaro.org Cc: linux-remoteproc@vger.kernel.org, ohad@wizery.com, loic.pallardy@st.com, s-anna@ti.com, peng.fan@nxp.com, arnaud.pouliquen@st.com, fabien.dessenne@st.com Subject: [PATCH 15/18] remoteproc: Correctly deal with MCU synchronisation when changing FW image Date: Thu, 12 Mar 2020 16:11:55 -0600 Message-Id: <20200312221158.3613-16-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200312221158.3613-1-mathieu.poirier@linaro.org> References: <20200312221158.3613-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 Thu Mar 12 22:11: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: 11435573 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 BE95D92A for ; Thu, 12 Mar 2020 22:12:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9D0D5206CD for ; Thu, 12 Mar 2020 22:12:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="Iy5l2iYj" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726910AbgCLWMT (ORCPT ); Thu, 12 Mar 2020 18:12:19 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:34897 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726814AbgCLWMT (ORCPT ); Thu, 12 Mar 2020 18:12:19 -0400 Received: by mail-pl1-f195.google.com with SMTP id g6so3232954plt.2 for ; Thu, 12 Mar 2020 15:12: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=IuukOSyWIrqfCKsQH/r2/YhsUvldyW+QBECojjMioRI=; b=Iy5l2iYj7jO97/P92FWBPKeXjiQZPbKDyiRIks/MGQb1ySBbyjKfuoH0ts8yzwcGZQ RTyeG2vPfD5Ncvnnpqq2TGjL7ImalLa2N7PBFIA16aBejnXq/Ait2fJwZqw8Ukz+r8yz xxol6HjX9nsNLLnANDj9ed3NWJ5SP9HN8Irn0vm8TU9TUcYYs6qzOusNdKzbuw1yvyEf EwWpUBQ/CKHk7PfzQnfNqd9z3dG/NSlnmH8TfPhgu/k5oJg1ZEhJWzGs8hIrbTbELlhU 6P18+sr8Pt5uOJW2AE4ztnLsNW0/nWbK8quoZsGpcC2OCtwWf3alu3Eq9tK8Zs+2/Xog FKWQ== 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=uAifkA/q+HRijD2oS4TYLuuPtlBhfOuxnrUph1HM1ekcrcHRNHfWQP6njLAtbsopRH wFnq/90bN8blfvAmfWphBzgphwcORz8Dky8o7EUgS+EuNye6VQhzmiBeOmBDmyZ4M4Q2 fE/KdtYSL6hGPFHCAjOSww8flamzjxRUDEAvA9tXUoi75d+PDVXSQUVJDmmTVGaYjRGU LkjpC1764+n1ndVmmi74M5BZ/fMvMpKF1oB3fvZn0fLc6zGEVXCYbkpxoSr6kouF/pip VplmXkOUztB2vhxNk9w+PzIRYcFZvO4Cx028kWhQuH2A9dJgmeVw5Ww+gYiCxAq6EAF+ JSjw== X-Gm-Message-State: ANhLgQ0Xyrq6lhWaMf0nwicqf6R5W0107ORWn+ij3ijvMO7AG/X+LA8+ BD+g/3E6utAxO8LEAqJJcXuULQ== X-Google-Smtp-Source: ADFU+vsbQ2dvj1TmYBF5mPI0cjX6DqtNLwkAh1mSpyn/9hbynvmkMeAJKtp34ZM5Wwl+CsjiMEq2ug== X-Received: by 2002:a17:90a:2ec7:: with SMTP id h7mr6563697pjs.107.1584051137869; Thu, 12 Mar 2020 15:12:17 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id j2sm20945362pfg.169.2020.03.12.15.12.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Mar 2020 15:12:17 -0700 (PDT) From: Mathieu Poirier To: bjorn.andersson@linaro.org Cc: linux-remoteproc@vger.kernel.org, ohad@wizery.com, loic.pallardy@st.com, s-anna@ti.com, peng.fan@nxp.com, arnaud.pouliquen@st.com, fabien.dessenne@st.com Subject: [PATCH 16/18] remoteproc: Correctly deal with MCU synchronisation when changing state Date: Thu, 12 Mar 2020 16:11:56 -0600 Message-Id: <20200312221158.3613-17-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200312221158.3613-1-mathieu.poirier@linaro.org> References: <20200312221158.3613-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 Thu Mar 12 22:11: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: 11435575 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 B0B6F13B1 for ; Thu, 12 Mar 2020 22:12:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8F51B206CD for ; Thu, 12 Mar 2020 22:12:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="d3ad8GEg" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726913AbgCLWMU (ORCPT ); Thu, 12 Mar 2020 18:12:20 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:45357 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726814AbgCLWMU (ORCPT ); Thu, 12 Mar 2020 18:12:20 -0400 Received: by mail-pf1-f195.google.com with SMTP id 2so3934787pfg.12 for ; Thu, 12 Mar 2020 15:12:19 -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=p7QdFESlb8Bs5GweNDaM0o+22PsENpp2NnEjZ0zQZ+k=; b=d3ad8GEggulvMDXbMkEzutP5wDdvj8p3S1fPELSWxgAxkPlH7hNApkvDpWJ+kgCJ9R Fk2YNvX6+e0K56qC4lsjQBy+DmFi5ZNuQlXLCOmqzgtV0J6yVK4ig9j3dXbGtZKDbL7R qyswQRz9ECj7oyv78kmouvaU2tnxxgvXeNacGtMYjfKosl1HBgnVofnguvIZBoPHfXRi ghmBqEYwZujUdk1qVMUdUBX3b3NlHHhI/E18zFZpt0qNUFjZhnJT550dQJ79+TsXBtXt WSsWSGZwijeKDNyHp4OL66x3ov+UXO+dChWwjnYOPV06tyS9H0Bp6PJVbYqxeknCDgWv mqXQ== 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=p7QdFESlb8Bs5GweNDaM0o+22PsENpp2NnEjZ0zQZ+k=; b=bftzTM4BaPjB2biLMKMm/RcyCe4l8DX2uFSSiwoY7ltMs2Czg/80OlX7cd7ZToQ2Md KrbOMgUQPQ0U5L2ad+P173pdHZ4vMS0hk0t74S0iR2AfEVaCP/N6bnTwIOwEAzBf2w42 9837jh4/XAOCHsXy5Bc9VR7RrodfmgwroY0quJcmKVW9wLhkkLnhmqfSr6IupTij7I5R WdQPDjQXo4/25rP7g/asnAj2IPWbiQ2Wixx9JENebrAUzjNNojKfKHZeKpmHT765SuaD aR8MmYY7DO359S0Pwt8DnNmj/gYZWS0JCBpZS5IR+Dd7e0FMsjArV5uwoW2C1kuuwvrS s6Jw== X-Gm-Message-State: ANhLgQ3MbriJEOsTT4YvJ82r9ejEwJiWzLN7TbCauga+1Lnt2IsItArS 4GQfMpteBceSxFcL8jfxWZQyYw== X-Google-Smtp-Source: ADFU+vvVI44ejzKBxSRmiQsWrsm78yRq37zEXAnLc5iX2xG7v4xyZ2llXxlXdOYHw1KLWMDLyvNdRA== X-Received: by 2002:a63:2b4e:: with SMTP id r75mr10113562pgr.32.1584051138923; Thu, 12 Mar 2020 15:12:18 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id j2sm20945362pfg.169.2020.03.12.15.12.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Mar 2020 15:12:18 -0700 (PDT) From: Mathieu Poirier To: bjorn.andersson@linaro.org Cc: linux-remoteproc@vger.kernel.org, ohad@wizery.com, loic.pallardy@st.com, s-anna@ti.com, peng.fan@nxp.com, arnaud.pouliquen@st.com, fabien.dessenne@st.com Subject: [PATCH 17/18] remoteproc: Make MCU synchronisation state changes on stop and crashed Date: Thu, 12 Mar 2020 16:11:57 -0600 Message-Id: <20200312221158.3613-18-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200312221158.3613-1-mathieu.poirier@linaro.org> References: <20200312221158.3613-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 7ea4397a9004..f776a474da97 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1720,6 +1720,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) @@ -1854,6 +1862,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); } From patchwork Thu Mar 12 22:11: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: 11435577 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 D4A5F13B1 for ; Thu, 12 Mar 2020 22:12:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A04F4206CD for ; Thu, 12 Mar 2020 22:12:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="Deyw2Yuy" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726917AbgCLWMV (ORCPT ); Thu, 12 Mar 2020 18:12:21 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:36222 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726814AbgCLWMV (ORCPT ); Thu, 12 Mar 2020 18:12:21 -0400 Received: by mail-pl1-f194.google.com with SMTP id g2so723096plo.3 for ; Thu, 12 Mar 2020 15:12: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=HLllXn7X6ZYAetG9wnBDeuGkqxnnfCDJmFR0GyYYgLc=; b=Deyw2YuyH9eOgoAIh+aVwVJshvhroUtWHNY0T8IX9ACTPxR5I+yIFbE5fit4eowwKQ 3YjHLkmzYYUbrwQefnyodWtaFJrqjiEMzUAwkOrbLm8DA8dD5NPkCPeR36igseOXCKaX raJYY5t/FxTcbrjGU9jHKm6hA9PZcBuh3IKgvyLNxy9YFNguk1W2MskaAJxu9Lgz/hl2 syyb6fJwMdNGcnF3ou/PO1yCZvn1mggZbkavR9nvGHVtZeLd5hsCM/Zz2NRcWwvNabg6 Hkgl7FE3taQbMdIW9WSyH0hub7UgurKzNya4l1rNkB29Rk56+5dt3TNdhvQuovDF9Lun 2s9w== 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=HLllXn7X6ZYAetG9wnBDeuGkqxnnfCDJmFR0GyYYgLc=; b=pHNeS6k1F4/9yS1ffVrIYldX7S4YD80EkpksYD/CwMt5KBxliabd6PWmI61mkkGVQz 6GJPdzp9KbTJFoe63veI82zgL3hs7p2LYAEbX2fWWLpWVfvdmiUYdb1rzvJzL0JmihCa QWySDKPWh47q5RWxtb+Z5GpEDy8jLEOlo0Mvstz1oDJ83UKu2C4ywiHvi7hmFva3GS1v 2mrii/lLvyvwdg5EXZqAQtl4xKZvluSXaSZwhPsA+DyEYqsskx7unDgRqZ1rxSFwmLv4 8tee0MZCVl+18lqTbZ6bC8kd69mx80zGOsKYY4nZCFH7gY0BRf72vdrNEXsG9sCQTc81 cgug== X-Gm-Message-State: ANhLgQ3zzRPf/y6uN0ougQf9HQ2JAFGL5IrCnEwnMo0AZYcO+9BTevFw l5YG+B/xWUMffmAcGTOhrxHmSw== X-Google-Smtp-Source: ADFU+vtRhB8GTqHj6vHrODDI52dGnB+cfyE+xEIKo8Dx89XdlRgL6Be0UZV2qjcExIQa74VrcDIJdg== X-Received: by 2002:a17:902:524:: with SMTP id 33mr10455071plf.241.1584051139951; Thu, 12 Mar 2020 15:12:19 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id j2sm20945362pfg.169.2020.03.12.15.12.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Mar 2020 15:12:19 -0700 (PDT) From: Mathieu Poirier To: bjorn.andersson@linaro.org Cc: linux-remoteproc@vger.kernel.org, ohad@wizery.com, loic.pallardy@st.com, s-anna@ti.com, peng.fan@nxp.com, arnaud.pouliquen@st.com, fabien.dessenne@st.com Subject: [PATCH 18/18] remoteproc: stm32: add support for co-processor booted before kernel Date: Thu, 12 Mar 2020 16:11:58 -0600 Message-Id: <20200312221158.3613-19-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200312221158.3613-1-mathieu.poirier@linaro.org> References: <20200312221158.3613-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 From: Fabien Dessenne Refactoring of the work from Fabien Dessenne and Arnaud Pouliquen originally published here [1]. Provided as an example only. Compiled tested but will likely crash horribly. [1]. https://patchwork.kernel.org/project/linux-remoteproc/list/?series=239877 --- drivers/remoteproc/stm32_rproc.c | 207 ++++++++++++++++++++++++++++++- 1 file changed, 201 insertions(+), 6 deletions(-) diff --git a/drivers/remoteproc/stm32_rproc.c b/drivers/remoteproc/stm32_rproc.c index a18f88044111..c3d5bb214ea7 100644 --- a/drivers/remoteproc/stm32_rproc.c +++ b/drivers/remoteproc/stm32_rproc.c @@ -38,6 +38,15 @@ #define STM32_MBX_VQ1_ID 1 #define STM32_MBX_SHUTDOWN "shutdown" +#define RSC_TBL_SIZE (1024) + +#define COPRO_STATE_OFF 0 +#define COPRO_STATE_INIT 1 +#define COPRO_STATE_CRUN 2 +#define COPRO_STATE_CSTOP 3 +#define COPRO_STATE_STANDBY 4 +#define COPRO_STATE_CRASH 5 + struct stm32_syscon { struct regmap *map; u32 reg; @@ -70,12 +79,14 @@ struct stm32_rproc { struct reset_control *rst; struct stm32_syscon hold_boot; struct stm32_syscon pdds; + struct stm32_syscon copro_state; int wdg_irq; u32 nb_rmems; struct stm32_rproc_mem *rmems; struct stm32_mbox mb[MBOX_NB_MBX]; struct workqueue_struct *workqueue; bool secured_soc; + void __iomem *rsc_va; }; static int stm32_rproc_pa_to_da(struct rproc *rproc, phys_addr_t pa, u64 *da) @@ -98,6 +109,28 @@ static int stm32_rproc_pa_to_da(struct rproc *rproc, phys_addr_t pa, u64 *da) return -EINVAL; } +static int stm32_rproc_da_to_pa(struct rproc *rproc, u64 da, phys_addr_t *pa) +{ + unsigned int i; + struct stm32_rproc *ddata = rproc->priv; + struct stm32_rproc_mem *p_mem; + + for (i = 0; i < ddata->nb_rmems; i++) { + p_mem = &ddata->rmems[i]; + + if (da < p_mem->dev_addr || + da >= p_mem->dev_addr + p_mem->size) + continue; + *pa = da - p_mem->dev_addr + p_mem->bus_addr; + dev_dbg(rproc->dev.parent, "da %llx to pa %#x\n", da, *pa); + return 0; + } + + dev_err(rproc->dev.parent, "can't translate da %llx\n", da); + + return -EINVAL; +} + static int stm32_rproc_mem_alloc(struct rproc *rproc, struct rproc_mem_entry *mem) { @@ -203,7 +236,17 @@ static int stm32_rproc_elf_load_rsc_table(struct rproc *rproc, return 0; } -static int stm32_rproc_parse_fw(struct rproc *rproc, const struct firmware *fw) +static struct resource_table * +stm32_rproc_elf_find_loaded_rsc_table_sync_mcu(struct rproc *rproc, + const struct firmware *fw) +{ + struct stm32_rproc *ddata = rproc->priv; + + return (struct resource_table *)ddata->rsc_va; +} + +static int __stm32_rproc_parse_fw(struct rproc *rproc, + const struct firmware *fw) { struct device *dev = rproc->dev.parent; struct device_node *np = dev->of_node; @@ -256,9 +299,48 @@ static int stm32_rproc_parse_fw(struct rproc *rproc, const struct firmware *fw) index++; } + return 0; +} + +static int stm32_rproc_parse_fw(struct rproc *rproc, const struct firmware *fw) +{ + int ret; + + ret = __stm32_rproc_parse_fw(rproc, fw); + return stm32_rproc_elf_load_rsc_table(rproc, fw); } +static int stm32_rproc_parse_fw_sync_mcu(struct rproc *rproc, + const struct firmware *fw) +{ + struct resource_table *table = NULL; + struct stm32_rproc *ddata = rproc->priv; + int ret; + + ret = __stm32_rproc_parse_fw(rproc, fw); + + if (ddata->rsc_va) { + table = (struct resource_table *)ddata->rsc_va; + /* Assuming that the resource table fits in 1kB is fair */ + rproc->cached_table = kmemdup(table, RSC_TBL_SIZE, GFP_KERNEL); + if (!rproc->cached_table) + return -ENOMEM; + + rproc->table_ptr = rproc->cached_table; + rproc->table_sz = RSC_TBL_SIZE; + return 0; + } + + rproc->cached_table = NULL; + rproc->table_ptr = NULL; + rproc->table_sz = 0; + + dev_warn(&rproc->dev, "no resource table found for this firmware\n"); + return 0; +} + + static irqreturn_t stm32_rproc_wdg(int irq, void *data) { struct rproc *rproc = data; @@ -429,6 +511,19 @@ static int stm32_rproc_start(struct rproc *rproc) } } + return stm32_rproc_set_hold_boot(rproc, true); +} + +static int stm32_rproc_start_sync_mcu(struct rproc *rproc) +{ + int err; + + stm32_rproc_add_coredump_trace(rproc); + + /* + * If M4 previously started by bootloader, just guarantee holdboot + * is set to catch any crash. + */ err = stm32_rproc_set_hold_boot(rproc, false); if (err) return err; @@ -476,6 +571,28 @@ static int stm32_rproc_stop(struct rproc *rproc) return 0; } +static int stm32_rproc_stop_sync_mcu(struct rproc *rproc) +{ + struct stm32_rproc *ddata = rproc->priv; + int err; + + err = stm32_rproc_stop(rproc); + if (err) + return err; + + /* update copro state to OFF */ + err = regmap_update_bits(ddata->copro_state.map, + ddata->copro_state.reg, + ddata->copro_state.mask, + COPRO_STATE_OFF); + if (err) { + dev_err(&rproc->dev, "failed to set copro state\n"); + return err; + } + + return 0; +} + static void stm32_rproc_kick(struct rproc *rproc, int vqid) { struct stm32_rproc *ddata = rproc->priv; @@ -498,6 +615,14 @@ static void stm32_rproc_kick(struct rproc *rproc, int vqid) } } +static struct rproc_ops st_rproc_ops_sync_mcu = { + .start = stm32_rproc_start_sync_mcu, + .stop = stm32_rproc_stop_sync_mcu, + .kick = stm32_rproc_kick, + .parse_fw = stm32_rproc_parse_fw_sync_mcu, + .find_loaded_rsc_table = stm32_rproc_elf_find_loaded_rsc_table_sync_mcu, +}; + static struct rproc_ops st_rproc_ops = { .start = stm32_rproc_start, .stop = stm32_rproc_stop, @@ -543,8 +668,10 @@ static int stm32_rproc_parse_dt(struct platform_device *pdev) struct device_node *np = dev->of_node; struct rproc *rproc = platform_get_drvdata(pdev); struct stm32_rproc *ddata = rproc->priv; - struct stm32_syscon tz; - unsigned int tzen; + struct stm32_syscon tz, rsctbl; + phys_addr_t rsc_pa; + u32 rsc_da; + unsigned int tzen, state; int err, irq; irq = platform_get_irq(pdev, 0); @@ -602,11 +729,72 @@ static int stm32_rproc_parse_dt(struct platform_device *pdev) err = stm32_rproc_get_syscon(np, "st,syscfg-pdds", &ddata->pdds); if (err) - dev_warn(dev, "failed to get pdds\n"); + dev_warn(dev, "pdds not supported\n"); rproc->auto_boot = of_property_read_bool(np, "st,auto-boot"); - return stm32_rproc_of_memory_translations(rproc); + err = stm32_rproc_of_memory_translations(rproc); + if (err) + return err; + + /* check if the coprocessor has been started from the bootloader */ + err = stm32_rproc_get_syscon(np, "st,syscfg-copro-state", + &ddata->copro_state); + if (err) { + /* no copro_state syscon (optional) */ + dev_warn(dev, "copro_state not supported\n"); + goto bail; + } + + err = regmap_read(ddata->copro_state.map, ddata->copro_state.reg, + &state); + if (err) { + dev_err(&rproc->dev, "failed to read copro state\n"); + return err; + } + + if (state == COPRO_STATE_CRUN) { + if (stm32_rproc_get_syscon(np, "st,syscfg-rsc-tbl", &rsctbl)) { + /* no rsc table syscon (optional) */ + dev_warn(dev, "rsc tbl syscon not supported\n"); + goto bail; + } + + err = regmap_read(rsctbl.map, rsctbl.reg, &rsc_da); + if (err) { + dev_err(&rproc->dev, "failed to read rsc tbl addr\n"); + return err; + } + if (!rsc_da) + /* no rsc table */ + goto bail; + + err = stm32_rproc_da_to_pa(rproc, rsc_da, &rsc_pa); + if (err) + return err; + + ddata->rsc_va = devm_ioremap_wc(dev, rsc_pa, RSC_TBL_SIZE); + if (IS_ERR_OR_NULL(ddata->rsc_va)) { + dev_err(dev, "Unable to map memory region: %pa+%zx\n", + &rsc_pa, RSC_TBL_SIZE); + ddata->rsc_va = NULL; + return -ENOMEM; + } + } +bail: + return 0; +} + +static struct rproc_sync_states stm32_sync_states = { + .on_init = true, /* sync with MCU when the kernel boots */ + .after_stop = false, /* don't sync with MCU if stopped from sysfs */ + .after_crash = false,/* don't sync with MCU after a crash */ +}; + +static bool stm32_sync_with_mcu(struct platform_device *pdev) +{ + /* Find something platform specific here */ + return true; } static int stm32_rproc_probe(struct platform_device *pdev) @@ -621,7 +809,14 @@ static int stm32_rproc_probe(struct platform_device *pdev) if (ret) return ret; - rproc = rproc_alloc(dev, np->name, &st_rproc_ops, NULL, sizeof(*ddata)); + if (stm32_sync_with_mcu(pdev)) + rproc = rproc_alloc(dev, np->name, &st_rproc_ops, + NULL, sizeof(*ddata)); + else + rproc = rproc_alloc_state_machine(dev, np->name, &st_rproc_ops, + &st_rproc_ops_sync_mcu, + &stm32_sync_states, NULL, + sizeof(*ddata)); if (!rproc) return -ENOMEM;