Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp10276ybt; Tue, 7 Jul 2020 14:33:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy0lku2ECzYnTFYDYLwv7oICYWlUuTG2ibn83oAwmrTWd3X5fO3/6AbeU7aBom1YVMHNqAf X-Received: by 2002:a17:906:a253:: with SMTP id bi19mr47395336ejb.338.1594157635697; Tue, 07 Jul 2020 14:33:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594157635; cv=none; d=google.com; s=arc-20160816; b=gJVBK89Iovv37FnQdUCV5jC/2ujdzftE8xWty/fAzQDSiDkFR2909CNtzVeZPvADsC oi59DFIUbkCc5CSCEXvzbNk/3uu8zPnf6UYZAXCE7SFnEeC2O1TOMKB2fd8T4a70SUEG wc+HfGFDBT8+t7LVrtLvG6Dc59eWaSZ6Mptr0wVjUbXnjH1E/Hs3Gg5ujMmOnodf03Lc fF497hxhyPpioZaJ2axjzufTxVMwLSh0Ub28wboPYbKhb4g/yw7DJDNuOuXEK6fPwo4M c0++iSCtoKPXzFnEKOzydDaOJzjaGO8DIeoSNEGEhTE8sRq8ClBNLp8LQIiPowxrDIhz m1dg== 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=+3MCXBkEweRCBCXnKkbvCmuaqKQRYPJZEhIYqjzffxA=; b=LHfh5Cj6tXX+d49NxxYV6Dcl+/whjyYfxhYfvjh7Ff1WkaypukeT6Xx7fwzkoVGh8i n2hod/MTDiNn1YHwI8VC+e1AdnAKkppuufN/mj/9/bT8XqINbm7sHmf9J0W3HU4d6fcp IBTcozYrNR24jF6EjYl+h1jWC0wDDImkwbtiueCG9aXnKi9as8bdcvkBgIdfSIOCVibF c7nxGhQT/S81pBfBHdG+zyUuEgfg5+RgPTSSbgdCS0QvsE6Y25/l25NGlkTvj/uE2hui XsUPF1Ed0NgJeV31BIQNvc4HbI4QTKbU9qwIPhrPb9hAYQXHz9VSBEhYmQbTC3q4qfDa ZkRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GZsKvRtt; 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 h22si16380152ejf.599.2020.07.07.14.33.33; Tue, 07 Jul 2020 14:33:55 -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=GZsKvRtt; 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 S1729393AbgGGVbm (ORCPT + 99 others); Tue, 7 Jul 2020 17:31:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729312AbgGGVbW (ORCPT ); Tue, 7 Jul 2020 17:31:22 -0400 Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6FCA3C061755 for ; Tue, 7 Jul 2020 14:31:22 -0700 (PDT) Received: by mail-pj1-x1042.google.com with SMTP id l6so234995pjq.1 for ; Tue, 07 Jul 2020 14:31:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+3MCXBkEweRCBCXnKkbvCmuaqKQRYPJZEhIYqjzffxA=; b=GZsKvRttTVdpRXiFAFQqLB/OSr1mbj6jtRxZCmNENnI2UyhGQ97vFRT73Rf53p1Pw/ 7Kv8tMfvl8SbjnJPz7hAgz2qL96nPrs5yxXLMJaXlz7IDv1viQhZd5q0U8gi1u8EUQ62 I3TVIossUE8jTwWxWgD3bsaOGbA/z9LMxoQ1RVCFvVOP/kwVl80fSm3NS2bfjRNX73i5 bdPpi2ievzipfaZk06WjSrTQJs4zFvIv59xVdtWnb2usDFSd5y4yaBg4OjVK3udXkBWE 2yxbDGZ3Dbrv8WUhnmw9rQ/MqxfPgtE9PcZDdqSPjpPydg8wkR+dBP+gnZG2cTMr4D3Z xctg== 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=+3MCXBkEweRCBCXnKkbvCmuaqKQRYPJZEhIYqjzffxA=; b=dnxD1qavQ5e9VhQBAeBENu2VycEwqUym5elX6kSdcjYG7RYyEQcRfbcdhSlg5/1nR9 n5OHgdcVjpwHxidzGgXIDHcPA+CWwmjfx75QGzJ1jFoYdjUyEAGUzJzXO/bLPaoObKe/ QXKhKHmAoBGwKHN14DqV5J8h2k9IC/OWCKhe2Wm0Kk1RBxZbR4NtQj0blDtzjCO+Zmje H9Rcd6tT+k4hkGjAEbwW6FhMPQFH8EcVRITGQL3gCOlLAoupx2NgzvWnfvI3DTUT9j9R 83ek23yaLnkyd1mvBJiDjeTMfV7E4XkyxM8Qsm4YaxpxVkkg7nFescydOWeReqNALJDA 8m0Q== X-Gm-Message-State: AOAM5319iyYGxI+UglhhCEyb9oK9a9l11xwYJOEg2MHY6ATZjmV3BDEL NSSo458MVBgZP8eCzicCQ8z/CQ== X-Received: by 2002:a17:902:c411:: with SMTP id k17mr44127764plk.165.1594157482000; Tue, 07 Jul 2020 14:31:22 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id o128sm23560832pfg.127.2020.07.07.14.31.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jul 2020 14:31:21 -0700 (PDT) From: Mathieu Poirier To: ohad@wizery.com, bjorn.andersson@linaro.org, loic.pallardy@st.com, arnaud.pouliquen@st.com, mcoquelin.stm32@gmail.com, alexandre.torgue@st.com Cc: linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com Subject: [PATCH v5 06/11] remoteproc: stm32: Properly set co-processor state when attaching Date: Tue, 7 Jul 2020 15:31:07 -0600 Message-Id: <20200707213112.928383-7-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200707213112.928383-1-mathieu.poirier@linaro.org> References: <20200707213112.928383-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 Introduce the required mechanic to set the state of the M4 in order to properly deal with scenarios where the co-processor has been started by another entity. Mainly based on the work published by Arnaud Pouliquen [1]. [1]. https://patchwork.kernel.org/project/linux-remoteproc/list/?series=239877 Signed-off-by: Mathieu Poirier Reviewed-by: Bjorn Andersson --- drivers/remoteproc/stm32_rproc.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/drivers/remoteproc/stm32_rproc.c b/drivers/remoteproc/stm32_rproc.c index 961a53f67ec5..cbeb5ceb15c5 100644 --- a/drivers/remoteproc/stm32_rproc.c +++ b/drivers/remoteproc/stm32_rproc.c @@ -39,6 +39,13 @@ #define STM32_MBX_VQ1_ID 1 #define STM32_MBX_SHUTDOWN "shutdown" +#define M4_STATE_OFF 0 +#define M4_STATE_INI 1 +#define M4_STATE_CRUN 2 +#define M4_STATE_CSTOP 3 +#define M4_STATE_STANDBY 4 +#define M4_STATE_CRASH 5 + struct stm32_syscon { struct regmap *map; u32 reg; @@ -636,12 +643,30 @@ static int stm32_rproc_parse_dt(struct platform_device *pdev, return 0; } +static int stm32_rproc_get_m4_status(struct stm32_rproc *ddata, + unsigned int *state) +{ + /* See stm32_rproc_parse_dt() */ + if (!ddata->m4_state.map) { + /* + * We couldn't get the coprocessor's state, assume + * it is not running. + */ + state = M4_STATE_OFF; + return 0; + } + + return regmap_read(ddata->m4_state.map, ddata->m4_state.reg, state); +} + + static int stm32_rproc_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct stm32_rproc *ddata; struct device_node *np = dev->of_node; struct rproc *rproc; + unsigned int state; int ret; ret = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(32)); @@ -664,6 +689,13 @@ static int stm32_rproc_probe(struct platform_device *pdev) if (ret) goto free_rproc; + ret = stm32_rproc_get_m4_status(ddata, &state); + if (ret) + goto free_rproc; + + if (state == M4_STATE_CRUN) + rproc->state = RPROC_DETACHED; + rproc->has_iommu = false; ddata->workqueue = create_workqueue(dev_name(dev)); if (!ddata->workqueue) { -- 2.25.1