Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp130422ybz; Fri, 24 Apr 2020 13:04:43 -0700 (PDT) X-Google-Smtp-Source: APiQypJjquRQAIBvqnSmIRK/aDtK9C6saOoAD4WwzYqSBJpc1GEkwC8kSpyj2myvyy1GpBqlpfYu X-Received: by 2002:a50:abe2:: with SMTP id u89mr9397991edc.259.1587758683661; Fri, 24 Apr 2020 13:04:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587758683; cv=none; d=google.com; s=arc-20160816; b=Tf8XAcCpgOCsCekxQOR9Ei6RlXhIKQiBp6d3VQwk4DCa/B9yXeHTywOFxL5bV6D6XL V0jJt+w+h5vJXKWiP32nUUp8RFGVkuX9j0qGdAP0NlsqqUsEbm0uFz9wjoj8k1wubryn LXMl4kJsB6BuR3sthL7QhJuRFiWyg7zkZqSdoap7BPVkAoFzo7XMSYSrK4/pDv1weeBJ yyTkTBp0KGa0mfr5+HqqFkd2Z3wae590gwiXCdvTpaWRYoVfFoZ1RmCCK9WYNqNcmRTE KTQHXs8B0M6XsdRiezxVkeYBB/HVBkQDhVisvaBI9RS8a7zQg21NRhLbzuoYcy2fi0eC ZElg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=/8EQG22JXL8ro/80I28EMVnMy622Pquoagwe6M0KrVU=; b=wg9e1juyMJmX4AIJkUDXoPO5OosnOffq4eOe1kzze2393fcV0BIA44ewh2MkGtW7nm gR1r6cMMtY1GDQ0xU+Q1cSW2CyQ80d8IdlIlNkrWOZqRPcsJpo1FesSdaB5kIhFR1csK xm5IDUlveWS7DQtk71fpqIGCLQQuMQzuHfG0llMAisMxRqS9WdNgBebE9JgV3p1tvpWJ Gbmgb+Oz4wppaPBq2AB0vUoGSp90tRivra4wwIoBxWejFF8I/Uua0daluTwn/eEE+Hqv 1watzeJQ+forpzUwHT5dS+auCTJCmULtiNdPrsSjlTWftXI98eNwAERAnl7VRLGnJHXg 5/vQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bkgpsJhe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w7si3530231edr.309.2020.04.24.13.04.06; Fri, 24 Apr 2020 13:04:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bkgpsJhe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729552AbgDXUCP (ORCPT + 99 others); Fri, 24 Apr 2020 16:02:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729473AbgDXUBw (ORCPT ); Fri, 24 Apr 2020 16:01:52 -0400 Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28780C09B049 for ; Fri, 24 Apr 2020 13:01:51 -0700 (PDT) Received: by mail-pl1-x641.google.com with SMTP id k18so4129975pll.6 for ; Fri, 24 Apr 2020 13:01:51 -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=/8EQG22JXL8ro/80I28EMVnMy622Pquoagwe6M0KrVU=; b=bkgpsJheMHUDzSTUosy/UAmwFCjhd6C93gLM9hF6tuH8HE0JtCUDwchMJgA4bHZwLP 4+f1x8+0v/848OOPExzbK2I3sunvdbo5trOn22INE8ZwrpXG0YsszY6YCNaTw1LFt4lY XN72vfCJQTu+zmfwmIj5CHhW3OjXO2uMxf+/NdOGySfetVTtMhHgSzuchXCmesiwvz61 sctlSYlMaonWSsoBknhQ0UeQXNbWCA5tw9GbaJPOEjMemh924mF1FKK/BSqAELRs7mpc 1OLxUhPRlrtGb02Ieerk9XKr3T05xZzlamq5SxmhEy/mXhO79lDkbcb/RGM90w2y/YOM te2A== 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=/8EQG22JXL8ro/80I28EMVnMy622Pquoagwe6M0KrVU=; b=QIhaIdHG9EMm5d5BARNx1MfypP6hSe3IvbD1aKa0S33HyMIaMTDd8hbM0FiszWEYoR 1UTbYN1EON+4grTyQ2/sBNQz4kdNwXv1DrUHqas9EBUIlb3hNoS7PskRbKSVFZe8KFSe dnDWKK5tePtbB6JxONsSR/ompAX9xOruOTr+kzpkV8T9CJMOO4nGSRoWWs6mrBYSWimN hhEZ5jGW+G9PDedJWT7igHqwkq96ppdu0r+ryXGQZS/9yK4U46Qy0j253Dt7RMWUY6kS wn82LmWXG0nUgu9ZaQDSSkSo5fhL8rgkZJZx6eD5gCBf1kRTQ30b2mt6a4FlF/2spbLL AJFA== X-Gm-Message-State: AGi0PuYxw0f9glzCU//7JPPu6d6k4380hG1SpjFtp+9scTJmFJC9u4Q5 +TIXySYoMt5rdmy0/A5bmeS0SnSFto0= X-Received: by 2002:a17:90a:c702:: with SMTP id o2mr8185535pjt.196.1587758510506; Fri, 24 Apr 2020 13:01:50 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id o11sm5532224pgd.58.2020.04.24.13.01.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Apr 2020 13:01:49 -0700 (PDT) From: Mathieu Poirier To: bjorn.andersson@linaro.org, ohad@wizery.com Cc: loic.pallardy@st.com, arnaud.pouliquen@st.com, s-anna@ti.com, linux-remoteproc@vger.kernel.org, corbet@lwn.net, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 10/14] remoteproc: Deal with synchronisation when shutting down Date: Fri, 24 Apr 2020 14:01:31 -0600 Message-Id: <20200424200135.28825-11-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200424200135.28825-1-mathieu.poirier@linaro.org> References: <20200424200135.28825-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The remoteproc core must not allow function rproc_shutdown() to proceed if currently synchronising with a remote processor and the synchronisation operations of that remote processor does not support it. Also part of the process is to set the synchronisation flag so that the remoteproc core can make the right decisions when restarting the system. Signed-off-by: Mathieu Poirier --- drivers/remoteproc/remoteproc_core.c | 32 ++++++++++++++++++++++++ drivers/remoteproc/remoteproc_internal.h | 7 ++++++ 2 files changed, 39 insertions(+) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 3a84a38ba37b..48afa1f80a8f 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1849,6 +1849,27 @@ int rproc_boot(struct rproc *rproc) } EXPORT_SYMBOL(rproc_boot); +static bool rproc_can_shutdown(struct rproc *rproc) +{ + /* + * The remoteproc core is the lifecycle manager, no problem + * calling for a shutdown. + */ + if (!rproc_needs_syncing(rproc)) + return true; + + /* + * The remoteproc has been loaded by another entity (as per above + * condition) and the platform code has given us the capability + * of stopping it. + */ + if (rproc->sync_ops->stop) + return true; + + /* Any other condition should not be allowed */ + return false; +} + /** * rproc_shutdown() - power off the remote processor * @rproc: the remote processor @@ -1879,6 +1900,9 @@ void rproc_shutdown(struct rproc *rproc) return; } + if (!rproc_can_shutdown(rproc)) + goto out; + /* if the remote proc is still needed, bail out */ if (!atomic_dec_and_test(&rproc->power)) goto out; @@ -1898,6 +1922,14 @@ void rproc_shutdown(struct rproc *rproc) kfree(rproc->cached_table); rproc->cached_table = NULL; rproc->table_ptr = NULL; + + /* + * The remote processor has been switched off - tell the core what + * operation to use from hereon, i.e whether an external entity will + * reboot the remote processor or it is now the remoteproc core's + * responsability. + */ + rproc_set_sync_flag(rproc, RPROC_SYNC_STATE_SHUTDOWN); out: mutex_unlock(&rproc->lock); } diff --git a/drivers/remoteproc/remoteproc_internal.h b/drivers/remoteproc/remoteproc_internal.h index 61500981155c..7dcc0a26892b 100644 --- a/drivers/remoteproc/remoteproc_internal.h +++ b/drivers/remoteproc/remoteproc_internal.h @@ -27,6 +27,9 @@ struct rproc_debug_trace { /* * enum rproc_sync_states - remote processsor sync states * + * @RPROC_SYNC_STATE_SHUTDOWN state to use after the remoteproc core + * has shutdown (rproc_shutdown()) the + * remote processor. * @RPROC_SYNC_STATE_CRASHED state to use after the remote processor * has crashed but has not been recovered by * the remoteproc core yet. @@ -36,6 +39,7 @@ struct rproc_debug_trace { * operation to use. */ enum rproc_sync_states { + RPROC_SYNC_STATE_SHUTDOWN, RPROC_SYNC_STATE_CRASHED, }; @@ -43,6 +47,9 @@ static inline void rproc_set_sync_flag(struct rproc *rproc, enum rproc_sync_states state) { switch (state) { + case RPROC_SYNC_STATE_SHUTDOWN: + rproc->sync_with_rproc = rproc->sync_flags.after_stop; + break; case RPROC_SYNC_STATE_CRASHED: rproc->sync_with_rproc = rproc->sync_flags.after_crash; break; -- 2.20.1