From patchwork Fri Jun 21 15:00:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard GENOUD X-Patchwork-Id: 13707750 Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [217.70.183.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A7A73208A8; Fri, 21 Jun 2024 15:01:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.193 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718982073; cv=none; b=grhqMP3iEBrBFhq56QDePmeBvCnZYYPuO+hjFPoYj4fjT/oHpaOetfdI/awzlwR4fLgqPBW6tL1KIYhEcRtbyA9iWq4vA9l4Wprdz6zF/2KW9ET5dt61A/hIHCSyv25QCQWhn5FwNHSKz/Hpjf7Saz4aD2SNguEvedNSwt1OEoo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718982073; c=relaxed/simple; bh=t0Qy22MrGv3aVpFGYWrgqFZdFYqVsgKbZyjJjDqP0Gk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TnDigFpZemilP9+wePJUy0NkGxGPK6VfmWsre3SXBEz99g4sj73e4GNN9wIu0dQTOmphY3jHyIvblcEptTFeMUVhGE8wkq4Cvmnn6Dvh8Wz3uIIkW7SeYc+QiNn4qMcWjsCQT4r004pq1whMxOgo6j/sJdWnMlviw+nZ2wmoSj8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=h3xUw6mt; arc=none smtp.client-ip=217.70.183.193 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="h3xUw6mt" Received: by mail.gandi.net (Postfix) with ESMTPSA id 2F1EC240007; Fri, 21 Jun 2024 15:01:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1718982067; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1BRiKHP7y9+z4NPu0dePgtaqHBp5JIDPh01b9uiscGo=; b=h3xUw6mt7PVsTONuDgVf4uSSsqKw8mg432SKkz4E4dAC2EYHhMvWJBvWxqdrgRxnoMoVEh qMtckIZuGYYds7wALZcgMl0XrYuz5jfuNUIbylzjbV5dDhBmc7sezjX83y1P+ICJK2Ag59 LmodvLrsal19nuTfggz9T4wt4Df/BAqAScaWsba1DZTkrbZ8MtEcB9Ht+snZjn7hBYkm46 EiQUYExGtvj3mJreTxQ0HbAr/E53mDIRt09p4cvY/hdrNS1hXaJxZyY8sSl5Zzz2yp4Yhy cAzyP2cZ6c/zCVBS402xL+i2GvfUMqGFryTcB9spSZXwykc3dlmFiOfm/CwE3g== From: Richard Genoud To: Bjorn Andersson , Mathieu Poirier Cc: Philipp Zabel , Suman Anna , Thomas Petazzoni , Alexandre Belloni , Udit Kumar , Thomas Richard , Gregory CLEMENT , Hari Nagalla , =?utf-8?q?Th=C3=A9o_Lebrun?= , linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, Richard Genoud Subject: [PATCH 1/4] remoteproc: k3-r5: Fix IPC-only mode detection Date: Fri, 21 Jun 2024 17:00:55 +0200 Message-ID: <20240621150058.319524-2-richard.genoud@bootlin.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240621150058.319524-1-richard.genoud@bootlin.com> References: <20240621150058.319524-1-richard.genoud@bootlin.com> Precedence: bulk X-Mailing-List: linux-remoteproc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-GND-Sasl: richard.genoud@bootlin.com ret variable was used to test reset status, get from reset_control_status() call. But this variable was overwritten by ti_sci_proc_get_status() a few lines bellow. And as ti_sci_proc_get_status() returns 0 or a negative value (in this latter case, followed by a return), the expression !ret was always true, Clearly, this was not what was intended: In the comment above it's said that "requires both local and module resets to be deasserted"; if reset_control_status() returns 0 it means that the reset line is deasserted. So, it's pretty clear that the return value of reset_control_status() was intended to be used instead of ti_sci_proc_get_status() return value. This could lead in an incorrect IPC-only mode detection if reset line is asserted (so reset_control_status() return > 0) and c_state != 0 and halted == 0. In this case, the old code would have detected an IPC-only mode instead of a mismatched mode. Fixes: 1168af40b1ad ("remoteproc: k3-r5: Add support for IPC-only mode for all R5Fs") Signed-off-by: Richard Genoud Reviewed-by: --- drivers/remoteproc/ti_k3_r5_remoteproc.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/remoteproc/ti_k3_r5_remoteproc.c b/drivers/remoteproc/ti_k3_r5_remoteproc.c index 50e486bcfa10..39a47540c590 100644 --- a/drivers/remoteproc/ti_k3_r5_remoteproc.c +++ b/drivers/remoteproc/ti_k3_r5_remoteproc.c @@ -1144,6 +1144,7 @@ static int k3_r5_rproc_configure_mode(struct k3_r5_rproc *kproc) u32 atcm_enable, btcm_enable, loczrama; struct k3_r5_core *core0; enum cluster_mode mode = cluster->mode; + int reset_ctrl_status; int ret; core0 = list_first_entry(&cluster->cores, struct k3_r5_core, elem); @@ -1160,11 +1161,11 @@ static int k3_r5_rproc_configure_mode(struct k3_r5_rproc *kproc) r_state, c_state); } - ret = reset_control_status(core->reset); - if (ret < 0) { + reset_ctrl_status = reset_control_status(core->reset); + if (reset_ctrl_status < 0) { dev_err(cdev, "failed to get initial local reset status, ret = %d\n", - ret); - return ret; + reset_ctrl_status); + return reset_ctrl_status; } /* @@ -1199,7 +1200,7 @@ static int k3_r5_rproc_configure_mode(struct k3_r5_rproc *kproc) * irrelevant if module reset is asserted (POR value has local reset * deasserted), and is deemed as remoteproc mode */ - if (c_state && !ret && !halted) { + if (c_state && !reset_ctrl_status && !halted) { dev_info(cdev, "configured R5F for IPC-only mode\n"); kproc->rproc->state = RPROC_DETACHED; ret = 1; @@ -1217,7 +1218,7 @@ static int k3_r5_rproc_configure_mode(struct k3_r5_rproc *kproc) ret = 0; } else { dev_err(cdev, "mismatched mode: local_reset = %s, module_reset = %s, core_state = %s\n", - !ret ? "deasserted" : "asserted", + !reset_ctrl_status ? "deasserted" : "asserted", c_state ? "deasserted" : "asserted", halted ? "halted" : "unhalted"); ret = -EINVAL; From patchwork Fri Jun 21 15:00:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard GENOUD X-Patchwork-Id: 13707748 Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [217.70.183.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D2833208A4; Fri, 21 Jun 2024 15:01:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.193 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718982073; cv=none; b=VFiQGg2HQQATTlezLekr8xEXSniF2Kmufp1Lc4UXaiETQEnYiGi4O92U9YUfmwwTFc/TN/ZV5tDoT1LM9iHBxoBZbCcyLaDuxdbnlcXysz7KOuX8mYXynT6MVLsACR484TLrfuJeHIkCvOXvgeKktxFeGU5fhpYjs6+fI2uPoS8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718982073; c=relaxed/simple; bh=7yFrKK9NIswCTWdAfTIfsx/jNUNR1eHx4Rejf20w65c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OKP+O3VFmNKfItUN3v2D9U3y6RfKJ1phqCkq5Q9mPE4GZDjLddWuQAR70xE3oBW2mM9qNIk3ySU/8/Xc9wxlVKFN1htd+oii8UNScMB4QBHDRv7/lZbM0oKbgnekDdlc/cjFOPIf4a1XPKtxwHkpVUMwEUDjVByEslahteoFRLE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=fNiaTLaQ; arc=none smtp.client-ip=217.70.183.193 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="fNiaTLaQ" Received: by mail.gandi.net (Postfix) with ESMTPSA id D35C1240008; Fri, 21 Jun 2024 15:01:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1718982068; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tuLEZHHASMyGiaostTM2FutUTf8a5tx361mkuNCLLj4=; b=fNiaTLaQ7vBx05LKbGRfUSLWjmS8KgAEq1aO1cU5WDDunmRf7qAnEK4yvEoRBPoJ71lo12 5Oj8GHdHTNZqrF4hiNsgLobtFTeJ+JZbwlje9B1EQa7p6u6QjwjdB0qkZLUfEBw3GO+kWo 90c7ozUla/VSJq+PFsK4mI9BebSxq5OQrYq04j4vSeDAM4grm75A2e+JIxUOoT5UTY4v3+ /CeXYWpRJshhqioRMkwYuqSUR1yP4BMEHmr7HzIis2VNcHRr6HNUAv0nEvi9eyC8sGFW62 SAC6YVt+dvEY9+TF7XGAHXSadjGfwCCvOhY8bNSkF1RWNiIIUoEoqpSiP72GLw== From: Richard Genoud To: Bjorn Andersson , Mathieu Poirier Cc: Philipp Zabel , Suman Anna , Thomas Petazzoni , Alexandre Belloni , Udit Kumar , Thomas Richard , Gregory CLEMENT , Hari Nagalla , =?utf-8?q?Th=C3=A9o_Lebrun?= , linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, Richard Genoud Subject: [PATCH 2/4] remoteproc: k3-r5: Introduce PM suspend/resume handlers Date: Fri, 21 Jun 2024 17:00:56 +0200 Message-ID: <20240621150058.319524-3-richard.genoud@bootlin.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240621150058.319524-1-richard.genoud@bootlin.com> References: <20240621150058.319524-1-richard.genoud@bootlin.com> Precedence: bulk X-Mailing-List: linux-remoteproc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-GND-Sasl: richard.genoud@bootlin.com This patch adds the support for system suspend/resume to the ti_k3_R5 remoteproc driver. In order to save maximum power, the approach here is to shutdown completely the cores that were started by the kernel (i.e. those in RUNNING state). Those which were started before the kernel (in attached mode) will be detached. The pm_notifier mechanism is used here because the remote procs firmwares have to be reloaded at resume, and thus the driver must have access to the file system were the firmware is stored. On suspend, the running remote procs are stopped, the attached remote procs are detached and processor control released. On resume, the reverse operation is done. Based on work from: Hari Nagalla Signed-off-by: Richard Genoud --- drivers/remoteproc/ti_k3_r5_remoteproc.c | 123 ++++++++++++++++++++++- 1 file changed, 121 insertions(+), 2 deletions(-) diff --git a/drivers/remoteproc/ti_k3_r5_remoteproc.c b/drivers/remoteproc/ti_k3_r5_remoteproc.c index 39a47540c590..1f18b08618c8 100644 --- a/drivers/remoteproc/ti_k3_r5_remoteproc.c +++ b/drivers/remoteproc/ti_k3_r5_remoteproc.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -112,6 +113,7 @@ struct k3_r5_cluster { struct list_head cores; wait_queue_head_t core_transition; const struct k3_r5_soc_data *soc_data; + struct notifier_block pm_notifier; }; /** @@ -577,7 +579,8 @@ static int k3_r5_rproc_start(struct rproc *rproc) /* do not allow core 1 to start before core 0 */ core0 = list_first_entry(&cluster->cores, struct k3_r5_core, elem); - if (core != core0 && core0->rproc->state == RPROC_OFFLINE) { + if (core != core0 && (core0->rproc->state == RPROC_OFFLINE || + core0->rproc->state == RPROC_SUSPENDED)) { dev_err(dev, "%s: can not start core 1 before core 0\n", __func__); ret = -EPERM; @@ -646,7 +649,8 @@ static int k3_r5_rproc_stop(struct rproc *rproc) /* do not allow core 0 to stop before core 1 */ core1 = list_last_entry(&cluster->cores, struct k3_r5_core, elem); - if (core != core1 && core1->rproc->state != RPROC_OFFLINE) { + if (core != core1 && core1->rproc->state != RPROC_OFFLINE && + core1->rproc->state != RPROC_SUSPENDED) { dev_err(dev, "%s: can not stop core 0 before core 1\n", __func__); ret = -EPERM; @@ -1238,6 +1242,117 @@ static int k3_r5_rproc_configure_mode(struct k3_r5_rproc *kproc) return ret; } +static int k3_r5_rproc_suspend(struct k3_r5_rproc *kproc) +{ + unsigned int rproc_state = kproc->rproc->state; + int ret; + + if (rproc_state != RPROC_RUNNING && rproc_state != RPROC_ATTACHED) + return 0; + + if (rproc_state == RPROC_RUNNING) + ret = rproc_shutdown(kproc->rproc); + else + ret = rproc_detach(kproc->rproc); + + if (ret) { + dev_err(kproc->dev, "Failed to %s rproc (%d)\n", + (rproc_state == RPROC_RUNNING) ? "shutdown" : "detach", + ret); + return ret; + } + + kproc->rproc->state = RPROC_SUSPENDED; + + return ret; +} + +static int k3_r5_rproc_resume(struct k3_r5_rproc *kproc) +{ + int ret; + + if (kproc->rproc->state != RPROC_SUSPENDED) + return 0; + + ret = k3_r5_rproc_configure_mode(kproc); + if (ret < 0) + return -EBUSY; + + /* + * ret > 0 for IPC-only mode + * ret == 0 for remote proc mode + */ + if (ret == 0) { + /* + * remote proc looses its configuration when powered off. + * So, we have to configure it again on resume. + */ + ret = k3_r5_rproc_configure(kproc); + if (ret < 0) { + dev_err(kproc->dev, "k3_r5_rproc_configure failed (%d)\n", ret); + return -EBUSY; + } + } + + return rproc_boot(kproc->rproc); +} + +static int k3_r5_cluster_pm_notifier_call(struct notifier_block *bl, + unsigned long state, void *unused) +{ + struct k3_r5_cluster *cluster = container_of(bl, struct k3_r5_cluster, + pm_notifier); + struct k3_r5_core *core; + int ret; + + switch (state) { + case PM_HIBERNATION_PREPARE: + case PM_RESTORE_PREPARE: + case PM_SUSPEND_PREPARE: + /* core1 should be suspended before core0 */ + list_for_each_entry_reverse(core, &cluster->cores, elem) { + /* + * In LOCKSTEP mode, rproc is allocated only for + * core0 + */ + if (core->rproc) { + ret = k3_r5_rproc_suspend(core->rproc->priv); + if (ret) + dev_warn(core->dev, + "k3_r5_rproc_suspend failed (%d)\n", ret); + } + + ret = ti_sci_proc_release(core->tsp); + if (ret) + dev_warn(core->dev, "ti_sci_proc_release failed (%d)\n", ret); + } + break; + case PM_POST_HIBERNATION: + case PM_POST_RESTORE: + case PM_POST_SUSPEND: + /* core0 should be started before core1 */ + list_for_each_entry(core, &cluster->cores, elem) { + ret = ti_sci_proc_request(core->tsp); + if (ret) + dev_warn(core->dev, "ti_sci_proc_request failed (%d)\n", ret); + + /* + * In LOCKSTEP mode, rproc is allocated only for + * core0 + */ + if (core->rproc) { + ret = k3_r5_rproc_resume(core->rproc->priv); + if (ret) + dev_warn(core->dev, + "k3_r5_rproc_resume failed (%d)\n", ret); + } + } + break; + } + + return 0; +} + static int k3_r5_cluster_rproc_init(struct platform_device *pdev) { struct k3_r5_cluster *cluster = platform_get_drvdata(pdev); @@ -1336,6 +1451,9 @@ static int k3_r5_cluster_rproc_init(struct platform_device *pdev) } } + cluster->pm_notifier.notifier_call = k3_r5_cluster_pm_notifier_call; + register_pm_notifier(&cluster->pm_notifier); + return 0; err_split: @@ -1402,6 +1520,7 @@ static void k3_r5_cluster_rproc_exit(void *data) rproc_free(rproc); core->rproc = NULL; } + unregister_pm_notifier(&cluster->pm_notifier); } static int k3_r5_core_of_get_internal_memories(struct platform_device *pdev, From patchwork Fri Jun 21 15:00:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard GENOUD X-Patchwork-Id: 13707749 Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [217.70.183.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D286B250EC; Fri, 21 Jun 2024 15:01:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.193 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718982073; cv=none; b=dUQXCnb1DHS2aQ4fk5xL0EF2P54Okme7AeXbYOKvoR+zUDzY6ytb+REy6uf/27R3du8y0RFdIdGSSxDEiQC06lHYnAHgLKRr2SFXhZqmZtyvMyiMA6wZvyw7SqWvChJCcK4aZX5KE3qLKQcwql1ZJbSlMDJMc7gjnoxL73hEVf0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718982073; c=relaxed/simple; bh=pMRaKVSGB844vR9DoFg3TYRLrXGGW7Jn25FhV1Gu344=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RX1kvwe8rBh2SQaYdlyj6v65uvLuk+EQFPzvTOBTm6Reeex6/129ej/ylM+12jORabA2Oo+KiuKkeDXltVv5B0NxERQvJGY07zhJ8YtUSpScZF51BGatPh1jI8JNrfPXmp4hmApn/gNPXnJNBvUmMBkSz+ED9MepjnFNxdI2wSI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=ewaHAY2G; arc=none smtp.client-ip=217.70.183.193 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="ewaHAY2G" Received: by mail.gandi.net (Postfix) with ESMTPSA id 8B47824000A; Fri, 21 Jun 2024 15:01:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1718982069; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=S3IObYGLRPk0AKUB9TG2rIfdLhnbghQZRr0H2amdorI=; b=ewaHAY2GhSBNigXagfVc2j7RKb0akdlPnHiIzJOwD/jaQAOm/8Wo2rublarYkrioqoDf93 R6yZyKAZRYJT9LE+Xn/TS9QgyZtqO3o14Zccmlvxfgf2Q7U9S0m4co3t2vqFblwJR1YA9Q qaI2Tua5tKJ4Grovyf8vdPWWXdYZMwe6mbWlpb+GKHwofvbe0g77Cg6iPNnMcJ4AyeeQ4F 6+MnSZVDGa12ulzyUbnzZJ+JS+IEc2qhju+wJ4dFIN8A1dp1sUx4ep48pC/fg0zZHIkxi3 Q6D8klXRp10SeoFAxsftyf0HiOKiI5ZmMXJw91bQpgfquk1In1UdgFlANUqpow== From: Richard Genoud To: Bjorn Andersson , Mathieu Poirier Cc: Philipp Zabel , Suman Anna , Thomas Petazzoni , Alexandre Belloni , Udit Kumar , Thomas Richard , Gregory CLEMENT , Hari Nagalla , =?utf-8?q?Th=C3=A9o_Lebrun?= , linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, Richard Genoud Subject: [PATCH 3/4] remoteproc: k3-r5: k3_r5_rproc_stop: code reorder Date: Fri, 21 Jun 2024 17:00:57 +0200 Message-ID: <20240621150058.319524-4-richard.genoud@bootlin.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240621150058.319524-1-richard.genoud@bootlin.com> References: <20240621150058.319524-1-richard.genoud@bootlin.com> Precedence: bulk X-Mailing-List: linux-remoteproc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-GND-Sasl: richard.genoud@bootlin.com In the next commit, a RP_MBOX_SHUTDOWN message will be sent in k3_r5_rproc_stop() to the remote proc (in lockstep on not) Thus, the sanity check "do not allow core 0 to stop before core 1" should be moved at the beginning of the function so that the generic case can be dealt with. In order to have an easier patch to review, those actions are broke in two patches: - this patch: moving the sanity check at the beginning (No functional change). - next patch: doing the real job (sending shutdown messages to remote procs before halting them). Basically, we had: - cluster_mode actions - !cluster_mode sanity check - !cluster_mode actions And now: - !cluster_mode sanity check - cluster_mode actions - !cluster_mode actions Signed-off-by: Richard Genoud --- drivers/remoteproc/ti_k3_r5_remoteproc.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/drivers/remoteproc/ti_k3_r5_remoteproc.c b/drivers/remoteproc/ti_k3_r5_remoteproc.c index 1f18b08618c8..a2ead87952c7 100644 --- a/drivers/remoteproc/ti_k3_r5_remoteproc.c +++ b/drivers/remoteproc/ti_k3_r5_remoteproc.c @@ -636,16 +636,8 @@ static int k3_r5_rproc_stop(struct rproc *rproc) struct k3_r5_core *core1, *core = kproc->core; int ret; - /* halt all applicable cores */ - if (cluster->mode == CLUSTER_MODE_LOCKSTEP) { - list_for_each_entry(core, &cluster->cores, elem) { - ret = k3_r5_core_halt(core); - if (ret) { - core = list_prev_entry(core, elem); - goto unroll_core_halt; - } - } - } else { + + if (cluster->mode != CLUSTER_MODE_LOCKSTEP) { /* do not allow core 0 to stop before core 1 */ core1 = list_last_entry(&cluster->cores, struct k3_r5_core, elem); @@ -656,6 +648,18 @@ static int k3_r5_rproc_stop(struct rproc *rproc) ret = -EPERM; goto out; } + } + + /* halt all applicable cores */ + if (cluster->mode == CLUSTER_MODE_LOCKSTEP) { + list_for_each_entry(core, &cluster->cores, elem) { + ret = k3_r5_core_halt(core); + if (ret) { + core = list_prev_entry(core, elem); + goto unroll_core_halt; + } + } + } else { ret = k3_r5_core_halt(core); if (ret) From patchwork Fri Jun 21 15:00:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard GENOUD X-Patchwork-Id: 13707751 Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [217.70.183.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5A09E25762; Fri, 21 Jun 2024 15:01:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.193 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718982073; cv=none; b=U4JsmQoS0G3e04WGNfNnEEvGzAXH4j1EU0IZ8CiVIZ71qgJRJXy5bDXFv/vEeqhjnyW258d9sSrEHMkv5XTnO/eNfeKQSEq1FQdJ7S33miH4W0lHpyTlF/wqvRgYKVnvvFa0+jegyhqN/ccB8koOfDvNpaesfXboDMjww0ZVSAo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718982073; c=relaxed/simple; bh=b+spiLBETXWAHz7iQ9Q/ImLDBrx7PrrMEhAnvpM2Bq8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=naJpVDYQdYz5O9mOjFqR35spyHbTT2iFM+zyfh5oL46PCWlk5Ufusu8IYDt+IwBFx+w03kTOK0GWtBhb7SbzH8s4ACk8ff1Q04U6GVvyjhg7h+JiJ7PdMWF3lSNrohJdQJvkG6buHeVemC7RqwbAtFO7fSfq7KYRCxy68xlLWdQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=E5KeRAAV; arc=none smtp.client-ip=217.70.183.193 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="E5KeRAAV" Received: by mail.gandi.net (Postfix) with ESMTPSA id 4491A240004; Fri, 21 Jun 2024 15:01:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1718982069; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=swFigz1dJFA6nW/teg50EkKWKn06yrLOy63UV2RCdiQ=; b=E5KeRAAVAvMZi7XTsmPjBCbYPFKE5Z4nadt8yBMhwgDQ8/jwMOmX5vha0VOhTYvZLl46u4 HrNmjhOIGRD4+K+KN3aPPPg55+kWz6recZon4G/5t5AA7K0aaWv10QzXPahCpbAXXQ7/Mz H9O5yEqbwIFhOSHaGfiPkZ/Umt0tDQh/XnriGLYU/d2UuOmU3jfHWMw76q4yxMR8o6HC4l MHCivm6SF2AxcHrxnqyov3h18C1Ra3Qceno/HducbT3EPmIfuuVXp49g5Xf006RteWDjsS hDUChpeu25TOEIge+qdzawX3/pvhJa0UYssSVBnPuYBi9fOW7BoDlxzfqmX8Lw== From: Richard Genoud To: Bjorn Andersson , Mathieu Poirier Cc: Philipp Zabel , Suman Anna , Thomas Petazzoni , Alexandre Belloni , Udit Kumar , Thomas Richard , Gregory CLEMENT , Hari Nagalla , =?utf-8?q?Th=C3=A9o_Lebrun?= , linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, Richard Genoud Subject: [PATCH 4/4] remoteproc: k3-r5: support for graceful stop of remote cores Date: Fri, 21 Jun 2024 17:00:58 +0200 Message-ID: <20240621150058.319524-5-richard.genoud@bootlin.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240621150058.319524-1-richard.genoud@bootlin.com> References: <20240621150058.319524-1-richard.genoud@bootlin.com> Precedence: bulk X-Mailing-List: linux-remoteproc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-GND-Sasl: richard.genoud@bootlin.com Introduce software IPC handshake between the K3-R5 remote proc driver and the R5 MCU to gracefully stop/reset the remote core. Upon a stop request, K3-R5 remote proc driver sends a RP_MBOX_SHUTDOWN mailbox message to the remote R5 core. The remote core is expected to: - relinquish all the resources acquired through Device Manager (DM) - disable its interrupts - send back a mailbox acknowledgment RP_MBOX_SHUDOWN_ACK - enter WFI state. Meanwhile, the K3-R5 remote proc driver does: - wait for the RP_MBOX_SHUTDOWN_ACK from the remote core - wait for the remote proc to enter WFI state - reset the remote core through device manager Based on work from: Hari Nagalla Signed-off-by: Richard Genoud --- drivers/remoteproc/omap_remoteproc.h | 9 +++++- drivers/remoteproc/ti_k3_r5_remoteproc.c | 40 ++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/drivers/remoteproc/omap_remoteproc.h b/drivers/remoteproc/omap_remoteproc.h index 828e13256c02..c008f11fa2a4 100644 --- a/drivers/remoteproc/omap_remoteproc.h +++ b/drivers/remoteproc/omap_remoteproc.h @@ -42,6 +42,11 @@ * @RP_MBOX_SUSPEND_CANCEL: a cancel suspend response from a remote processor * on a suspend request * + * @RP_MBOX_SHUTDOWN: shutdown request for the remote processor + * + * @RP_MBOX_SHUTDOWN_ACK: successful response from remote processor for a + * shutdown request. The remote processor should be in WFI state short after. + * * Introduce new message definitions if any here. * * @RP_MBOX_END_MSG: Indicates end of known/defined messages from remote core @@ -59,7 +64,9 @@ enum omap_rp_mbox_messages { RP_MBOX_SUSPEND_SYSTEM = 0xFFFFFF11, RP_MBOX_SUSPEND_ACK = 0xFFFFFF12, RP_MBOX_SUSPEND_CANCEL = 0xFFFFFF13, - RP_MBOX_END_MSG = 0xFFFFFF14, + RP_MBOX_SHUTDOWN = 0xFFFFFF14, + RP_MBOX_SHUTDOWN_ACK = 0xFFFFFF15, + RP_MBOX_END_MSG = 0xFFFFFF16, }; #endif /* _OMAP_RPMSG_H */ diff --git a/drivers/remoteproc/ti_k3_r5_remoteproc.c b/drivers/remoteproc/ti_k3_r5_remoteproc.c index a2ead87952c7..918a15e1dd9a 100644 --- a/drivers/remoteproc/ti_k3_r5_remoteproc.c +++ b/drivers/remoteproc/ti_k3_r5_remoteproc.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -172,8 +173,23 @@ struct k3_r5_rproc { struct k3_r5_core *core; struct k3_r5_mem *rmem; int num_rmems; + struct completion shutdown_complete; }; +/* + * This will return true if the remote core is in Wait For Interrupt state. + */ +static bool k3_r5_is_core_in_wfi(struct k3_r5_core *core) +{ + int ret; + u64 boot_vec; + u32 cfg, ctrl, stat; + + ret = ti_sci_proc_get_status(core->tsp, &boot_vec, &cfg, &ctrl, &stat); + + return !ret ? !!(stat & PROC_BOOT_STATUS_FLAG_R5_WFI) : false; +} + /** * k3_r5_rproc_mbox_callback() - inbound mailbox message handler * @client: mailbox client pointer used for requesting the mailbox channel @@ -209,6 +225,10 @@ static void k3_r5_rproc_mbox_callback(struct mbox_client *client, void *data) case RP_MBOX_ECHO_REPLY: dev_info(dev, "received echo reply from %s\n", name); break; + case RP_MBOX_SHUTDOWN_ACK: + dev_dbg(dev, "received shutdown_ack from %s\n", name); + complete(&kproc->shutdown_complete); + break; default: /* silently handle all other valid messages */ if (msg >= RP_MBOX_READY && msg < RP_MBOX_END_MSG) @@ -634,6 +654,7 @@ static int k3_r5_rproc_stop(struct rproc *rproc) struct k3_r5_cluster *cluster = kproc->cluster; struct device *dev = kproc->dev; struct k3_r5_core *core1, *core = kproc->core; + bool wfi; int ret; @@ -650,6 +671,24 @@ static int k3_r5_rproc_stop(struct rproc *rproc) } } + /* Send SHUTDOWN message to remote proc */ + reinit_completion(&kproc->shutdown_complete); + ret = mbox_send_message(kproc->mbox, (void *)RP_MBOX_SHUTDOWN); + if (ret < 0) { + dev_err(dev, "Sending SHUTDOWN message failed: %d. Halting core anyway.\n", ret); + } else { + ret = wait_for_completion_timeout(&kproc->shutdown_complete, + msecs_to_jiffies(1000)); + if (ret == 0) { + dev_err(dev, "Timeout waiting SHUTDOWN_ACK message. Halting core anyway.\n"); + } else { + ret = readx_poll_timeout(k3_r5_is_core_in_wfi, core, + wfi, wfi, 200, 2000); + if (ret) + dev_err(dev, "Timeout waiting for remote proc to be in WFI state. Halting core anyway.\n"); + } + } + /* halt all applicable cores */ if (cluster->mode == CLUSTER_MODE_LOCKSTEP) { list_for_each_entry(core, &cluster->cores, elem) { @@ -1410,6 +1449,7 @@ static int k3_r5_cluster_rproc_init(struct platform_device *pdev) goto err_config; } + init_completion(&kproc->shutdown_complete); init_rmem: k3_r5_adjust_tcm_sizes(kproc);