From patchwork Fri Mar 12 16:24:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 12135185 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 589D0C433E0 for ; Fri, 12 Mar 2021 16:25:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 266EC64F80 for ; Fri, 12 Mar 2021 16:25:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232506AbhCLQZC (ORCPT ); Fri, 12 Mar 2021 11:25:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232493AbhCLQY5 (ORCPT ); Fri, 12 Mar 2021 11:24:57 -0500 Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA598C061574 for ; Fri, 12 Mar 2021 08:24:56 -0800 (PST) Received: by mail-pg1-x534.google.com with SMTP id w34so15127483pga.8 for ; Fri, 12 Mar 2021 08:24:56 -0800 (PST) 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=2KkXz7Q+zlIq4fjTeJz23Qytt+RMPnrKFr7q6Kz46gw=; b=goU7+hhY1A+/8UPZ/6wfKNvo1Wd5VQk5jmBUyB4029x3LFD06OY4N/dUHCx+6JCMXN 4Gv604F1GGYcYScSB4t+ihHzgM2x8Ch7DVxgVNjczyeVTttmuU3DBliaoapfQk5O23Kg hiUyz5WqO+6GDpVzqB9HytOAgr9LMdDGgQLfcjzobhPwF9/CjmUhEgtIiKPMMsEH6CLp 2tpDMCtV8g1mZzaQ5Rocm2jwTzFqtBEpB8iKUmpUpHVZo1zXml1JKLnFf+I3Op6D5iHv sRNaLOOxIOXudYl7cgQogN2Pwugrii5UcRF2dH4UnCTzdcZcTQYoKD2wXsIGLdA0udHI IPmg== 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=2KkXz7Q+zlIq4fjTeJz23Qytt+RMPnrKFr7q6Kz46gw=; b=KqAWZexP1zmvw1UQVKdKKkyvp056sOWm9tN96DT36bwNjSM32INvWTf4+/r83EFt1x tnctGgw+kOKkTKsTXpLsA4KJiE5/vSlf7q7jJx5NBPRyZEcffNJ7NneQCQYzyJpLGwev 6YttQQbk3WyMLpUnm5BYyFXz1Vk+LyIBT83nKZkI0quAQWpgzQpoZG1nLa7Xa98LPrHd o7KHjuZED1Hi8NAwukvTNk1eMoRm9I1ZhakUGLlZLX2Zli1IBzfb9wBzn41WFWgxV3+T PKzYwSZnK9oKyETE/x51R9U4v+BOlZgfkdDYhBfE7kQ4Z8fTBP6mBmU4RGNpD2AuHeDK Icjw== X-Gm-Message-State: AOAM532hlmvtokejS4qcKFTFn+PS58oPg/Oam4VEEu1GAtzptyv9Qwz4 XkFd/bM4fmcZvnphKfTUC5QY+g== X-Google-Smtp-Source: ABdhPJykxgaKFWIUgas1xT2OFrRSUDk0+gKUmLvfAEZ0CH1C6V+Xud5HnYNRHhvdgH1YX++ceZwngA== X-Received: by 2002:a63:ea01:: with SMTP id c1mr4449870pgi.236.1615566296467; Fri, 12 Mar 2021 08:24:56 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id e8sm5899599pgb.35.2021.03.12.08.24.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 08:24:56 -0800 (PST) From: Mathieu Poirier To: bjorn.andersson@linaro.org, ohad@wizery.com Cc: arnaud.pouliquen@st.com, mcoquelin.stm32@gmail.com, alexandre.torgue@st.com, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v8 01/17] remoteproc: Remove useless check in rproc_del() Date: Fri, 12 Mar 2021 09:24:37 -0700 Message-Id: <20210312162453.1234145-2-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210312162453.1234145-1-mathieu.poirier@linaro.org> References: <20210312162453.1234145-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org Whether started at probe() time or thereafter from the command line, a remote processor needs to be shut down before the final cleanup phases can happen. Otherwise the system may be left in an unpredictable state where the remote processor is expecting the remoteproc core to be providing services when in fact it no longer exist. Invariably calling rproc_shutdown() is fine since it will return immediately if the remote processor has already been switched off. Signed-off-by: Mathieu Poirier Reviewed-by: Peng Fan Reviewed-by: Arnaud Pouliquen --- drivers/remoteproc/remoteproc_core.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index ab150765d124..d2704501b653 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -2347,10 +2347,8 @@ int rproc_del(struct rproc *rproc) if (!rproc) return -EINVAL; - /* if rproc is marked always-on, rproc_add() booted it */ /* TODO: make sure this works with rproc->power > 1 */ - if (rproc->auto_boot) - rproc_shutdown(rproc); + rproc_shutdown(rproc); mutex_lock(&rproc->lock); rproc->state = RPROC_DELETED; From patchwork Fri Mar 12 16:24:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 12135183 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BE948C433DB for ; Fri, 12 Mar 2021 16:25:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8F66965006 for ; Fri, 12 Mar 2021 16:25:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232444AbhCLQZC (ORCPT ); Fri, 12 Mar 2021 11:25:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232516AbhCLQY6 (ORCPT ); Fri, 12 Mar 2021 11:24:58 -0500 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17DB6C061761 for ; Fri, 12 Mar 2021 08:24:58 -0800 (PST) Received: by mail-pj1-x1034.google.com with SMTP id ga23-20020a17090b0397b02900c0b81bbcd4so10968367pjb.0 for ; Fri, 12 Mar 2021 08:24:58 -0800 (PST) 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=eI1kKtC7UxMHnJr2s3EPvhdO8fxk/LLGwiTP5XOosV0=; b=PN3I/N+cZw3h9ju32YnKPePdVIlkb9rWTDrPR1H+sf0iQBboillD1Ozy4XABXxlxgl tR4kfyyUndZXkQy20Ue4q6oIooAG7AkJz2xg6OvD5Qn0tdjfUbjRhp6dT+bLmAFnZgIn qabxVcYESCFKaeqal12xhsAQVuHOTqfj5i4e3QMLy/ku+D4TqNIJOeyE4sSycoodrqib zjQoWnmNoiQ3OGm1Bb30TwajPHCBVtMZwWrsoac6MJLyT98QT70mtWNAPHEd4C6vg3oc twqTOthuGaMeqEmLfGPKu6Oz9CUsSrqUZaf4/fBvp3m1ulko7FDGVjbdSZFw08+mhlfQ btYw== 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=eI1kKtC7UxMHnJr2s3EPvhdO8fxk/LLGwiTP5XOosV0=; b=QNMabpLY3YLPMibawzQCle2WBbPDAjqVTcfloRBb7lPgufaofeNP1Kua7rMr61xhSa tA63ASnjDRkWrBaQ3+0TLBdVb9vdwPyODqdgeWW678BHfZcHC0jUwRBmFbqwEObjNqBM u87hy+wRddb8d+harOuJy1nyyrspE88T+kE+z2fgKUoniLwtMxB+IZdtDM87p4sIrslK 302Xmt0VjI7btzJXrmdWTbXg3WbHXvdjhFJCmNNGEBmB7uB4HTqVouRp6CDLOxnYV7Sa iRyhN+ttxI4OCNGPFERQ7Hu1FfvS15aHV3JiTBdwlzaXm8MRUJmXqNDNmy7r2VCf9/B5 iNnA== X-Gm-Message-State: AOAM533hMirylPrMK3jhss4u0WGpRmhmvmqcYnnVNKrJVFt/nWL1g4mX k7ptS/tAyqR+xBvg5hwltnC9/A== X-Google-Smtp-Source: ABdhPJw9Ety41d9+1S0ehwGBAbtc5PtAZap9bz25QR71iiVhnp4ffpOMpyA/ro2c+7RUb10y9JaF0A== X-Received: by 2002:a17:90a:aa81:: with SMTP id l1mr15200425pjq.190.1615566297625; Fri, 12 Mar 2021 08:24:57 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id e8sm5899599pgb.35.2021.03.12.08.24.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 08:24:57 -0800 (PST) From: Mathieu Poirier To: bjorn.andersson@linaro.org, ohad@wizery.com Cc: arnaud.pouliquen@st.com, mcoquelin.stm32@gmail.com, alexandre.torgue@st.com, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v8 02/17] remoteproc: Rename function rproc_actuate() Date: Fri, 12 Mar 2021 09:24:38 -0700 Message-Id: <20210312162453.1234145-3-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210312162453.1234145-1-mathieu.poirier@linaro.org> References: <20210312162453.1234145-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org Rename function rproc_actuate() to rproc_attach(). That way it is easy to understand that it does the opposite of rproc_detach(). Signed-off-by: Mathieu Poirier Reviewed-by: Peng Fan Reviewed-by: Arnaud Pouliquen --- drivers/remoteproc/remoteproc_core.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index d2704501b653..7b66e1e96e4a 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1416,7 +1416,7 @@ static int rproc_start(struct rproc *rproc, const struct firmware *fw) return ret; } -static int rproc_attach(struct rproc *rproc) +static int __rproc_attach(struct rproc *rproc) { struct device *dev = &rproc->dev; int ret; @@ -1541,7 +1541,7 @@ static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw) * Attach to remote processor - similar to rproc_fw_boot() but without * the steps that deal with the firmware image. */ -static int rproc_actuate(struct rproc *rproc) +static int rproc_attach(struct rproc *rproc) { struct device *dev = &rproc->dev; int ret; @@ -1581,7 +1581,7 @@ static int rproc_actuate(struct rproc *rproc) goto clean_up_resources; } - ret = rproc_attach(rproc); + ret = __rproc_attach(rproc); if (ret) goto clean_up_resources; @@ -1802,7 +1802,7 @@ int rproc_boot(struct rproc *rproc) if (rproc->state == RPROC_DETACHED) { dev_info(dev, "attaching to %s\n", rproc->name); - ret = rproc_actuate(rproc); + ret = rproc_attach(rproc); } else { dev_info(dev, "powering up %s\n", rproc->name); From patchwork Fri Mar 12 16:24:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 12135187 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9D8A0C433E9 for ; Fri, 12 Mar 2021 16:25:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6BA1E6501F for ; Fri, 12 Mar 2021 16:25:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232516AbhCLQZC (ORCPT ); Fri, 12 Mar 2021 11:25:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232439AbhCLQY7 (ORCPT ); Fri, 12 Mar 2021 11:24:59 -0500 Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D9F4C061761 for ; Fri, 12 Mar 2021 08:24:59 -0800 (PST) Received: by mail-pg1-x52c.google.com with SMTP id v14so9270114pgq.2 for ; Fri, 12 Mar 2021 08:24:59 -0800 (PST) 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=waytkFv28UuOXcaaNeh19CxfKAUzKWp03mnaFrOUKvo=; b=dKfNn2iJY5E9p7zskcv9vdaz1urizBwgvTKpuJUzcyqpj4MgVPP8I/TnAVrOebY454 Z5NvWmlvMvJM0XH6nL3T4Hx2y75PcNMtSfM3JU6m8w6uTbLnnX2QLEYEN8yFpG+Za8By M20XrRlEtrpK+LuEt6CvpXDeKVG9QRn7talC8t90SM5HiBlDs5vZ8+49KrcM85UVt4z8 3yABuyzHsV3Q5L0rlkHH2DR0x9Om2ISFc7I418CjYQRN3nx8uoXyqtiQboA5/6yqRy/h /D/IuiUnaZ5pWORF2AIMCPh4mZAG5FXz97ppqCFqOr+Ly9R3l5rIXJcY2ydZEX+U2SPb vihw== 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=waytkFv28UuOXcaaNeh19CxfKAUzKWp03mnaFrOUKvo=; b=ND+lMRJMY69ZBCekdDzIikSgi/ITQApmx1FJsX1X99lENjoCY0hJlp6vUevJQWHVsJ t/IrsiOAW0mVEioLzEiyZty04Z1wSAa4bYSqQSCqj7tfq11d4rgZjvj9tF+QnC49OINf fwVN8tSnyQoe3TPhrtPp+FxGw+M8z1i99+OqSRc3zlK7J/BpOETRUpfR5wbizcRrnVIJ 586E13q+ccm5p6pf16H+WN9xN/qIF6UfdKk2CYvgdSHeUAVBAUwVUppCqNa1XCzvG9Mh O4IqhmkPU0bg/aJj1NK+MwjGg910tKdN0ZJBASNSTPrpLvoiSh+ACT0/YlLbF7PL+muu flyg== X-Gm-Message-State: AOAM530FI5+N7thff6VZJnM55+sgQn5AJfNnoB7ZtkPDS0IUrLhz/oeo 7wmRR+kVOcNrxl+tsh24U8riEw== X-Google-Smtp-Source: ABdhPJwe6MsgvkUtAkvoJC5S6pbE/3NgIMb3TzqdAmrlhzcoXLzkqS1fjpoI580QTCX+eKXoHnZoRw== X-Received: by 2002:a63:5924:: with SMTP id n36mr12926892pgb.183.1615566298659; Fri, 12 Mar 2021 08:24:58 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id e8sm5899599pgb.35.2021.03.12.08.24.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 08:24:58 -0800 (PST) From: Mathieu Poirier To: bjorn.andersson@linaro.org, ohad@wizery.com Cc: arnaud.pouliquen@st.com, mcoquelin.stm32@gmail.com, alexandre.torgue@st.com, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v8 03/17] remoteproc: Add new RPROC_ATTACHED state Date: Fri, 12 Mar 2021 09:24:39 -0700 Message-Id: <20210312162453.1234145-4-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210312162453.1234145-1-mathieu.poirier@linaro.org> References: <20210312162453.1234145-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org Add a new RPROC_ATTACHED state to take into account scenarios where the remoteproc core needs to attach to a remote processor that is booted by another entity. Signed-off-by: Mathieu Poirier Reviewed-by: Peng Fan Reviewed-by: Arnaud Pouliquen --- drivers/remoteproc/remoteproc_sysfs.c | 1 + include/linux/remoteproc.h | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/remoteproc/remoteproc_sysfs.c b/drivers/remoteproc/remoteproc_sysfs.c index 1dbef895e65e..4b4aab0d4c4b 100644 --- a/drivers/remoteproc/remoteproc_sysfs.c +++ b/drivers/remoteproc/remoteproc_sysfs.c @@ -172,6 +172,7 @@ static const char * const rproc_state_string[] = { [RPROC_RUNNING] = "running", [RPROC_CRASHED] = "crashed", [RPROC_DELETED] = "deleted", + [RPROC_ATTACHED] = "attached", [RPROC_DETACHED] = "detached", [RPROC_LAST] = "invalid", }; diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h index f28ee75d1005..b0a57ff73849 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -405,6 +405,8 @@ struct rproc_ops { * @RPROC_RUNNING: device is up and running * @RPROC_CRASHED: device has crashed; need to start recovery * @RPROC_DELETED: device is deleted + * @RPROC_ATTACHED: device has been booted by another entity and the core + * has attached to it * @RPROC_DETACHED: device has been booted by another entity and waiting * for the core to attach to it * @RPROC_LAST: just keep this one at the end @@ -421,8 +423,9 @@ enum rproc_state { RPROC_RUNNING = 2, RPROC_CRASHED = 3, RPROC_DELETED = 4, - RPROC_DETACHED = 5, - RPROC_LAST = 6, + RPROC_ATTACHED = 5, + RPROC_DETACHED = 6, + RPROC_LAST = 7, }; /** From patchwork Fri Mar 12 16:24:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 12135199 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6F617C4332B for ; Fri, 12 Mar 2021 16:26:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3B11364F80 for ; Fri, 12 Mar 2021 16:26:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231346AbhCLQZd (ORCPT ); Fri, 12 Mar 2021 11:25:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232623AbhCLQZA (ORCPT ); Fri, 12 Mar 2021 11:25:00 -0500 Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 29A6DC061762 for ; Fri, 12 Mar 2021 08:25:00 -0800 (PST) Received: by mail-pj1-x102e.google.com with SMTP id a22-20020a17090aa516b02900c1215e9b33so10967604pjq.5 for ; Fri, 12 Mar 2021 08:25:00 -0800 (PST) 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=EmIttTOsgDNM++s8zt1RjF9fKLTZIPRgfTRmynUwSgM=; b=bCHKr0/GSeFFSxm8Q4Nwz8kF8pe3oKPrzq/jVKb2PSnmVfo+sAl1PzrKRkSdZ8LMT0 GF+I7XJa+Ui+EG+02L631CsvB+VbdRTXD1Uoxg5OMvP2oDDElK7xUZi7v43MjutF7rhz 4TLz3TPulv8R10hGSYB4nDswd1dLCCl9+8d5TQyA6nE7N4Lm+9hL/N2AJI7w8618goxY 5SrjZqWdA+PG0KdaZ3bM6uukXKrEewTRQMkrGFM5Ql7eBdas5UGg/gdcwFhN+ONnsHS/ AXtilX1TdXRzHwsgaxg9kyaIAjz8kE22D9jLbk4iP1knKvwMZvjYP6g7UFp4Jb0ra+to GRxw== 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=EmIttTOsgDNM++s8zt1RjF9fKLTZIPRgfTRmynUwSgM=; b=gDYnlSTasV5v8cuabyVpipaWs76ok+66YxuFvtw2XU/zP9GIo+9L+pkuZvofCh8axD 4cMxixc8305zxoYdx3Uij0rULN9vn+x/3Ml/F/SqaMdTZJiewDg0uWZxQDMemnUUOyKs 3+WPaMoMdWEyIFtydcvWHNZy9EUq74/nU6EiIO3Dtq5eNk8ObZC9RIIFNTgeC+0PEOjs xKZx0eTpAcuBP1PyL6CS/Y0wS88hMNb1wWWICag7fmVxkVFNYJ4tvBkBKA08OsRGwfDa 0B4Yi+GXrrGkbSOgDkFNScZ8/LW+iNNRS46U+hqZJhk82hfJfga4Oi3ZVAEaY7mpwFkl L8jA== X-Gm-Message-State: AOAM531HnGfln4QhMU5Rt7t3H2L9jnRiuPPT/IUUT5gr+Ofy/i9zEoO7 j44F7bWkBxHM4NkBa7IkVPcJ8A== X-Google-Smtp-Source: ABdhPJxXJe5hKTDd4WF93xA2jimdLPApISq00YSPw79YUIexUQRALtvGUMqeh8UWjTrWHXuHQImaJg== X-Received: by 2002:a17:90b:100e:: with SMTP id gm14mr14916331pjb.217.1615566299668; Fri, 12 Mar 2021 08:24:59 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id e8sm5899599pgb.35.2021.03.12.08.24.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 08:24:59 -0800 (PST) From: Mathieu Poirier To: bjorn.andersson@linaro.org, ohad@wizery.com Cc: arnaud.pouliquen@st.com, mcoquelin.stm32@gmail.com, alexandre.torgue@st.com, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v8 04/17] remoteproc: Properly represent the attached state Date: Fri, 12 Mar 2021 09:24:40 -0700 Message-Id: <20210312162453.1234145-5-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210312162453.1234145-1-mathieu.poirier@linaro.org> References: <20210312162453.1234145-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org There is a need to know when a remote processor has been attached to rather than booted by the remoteproc core. In order to avoid manipulating two variables, i.e rproc::autonomous and rproc::state, get rid of the former and simply use the newly introduced RPROC_ATTACHED state. Signed-off-by: Mathieu Poirier Reviewed-by: Peng Fan Reviewed-by: Arnaud Pouliquen --- drivers/remoteproc/remoteproc_core.c | 20 +------------------- drivers/remoteproc/remoteproc_sysfs.c | 5 +---- include/linux/remoteproc.h | 2 -- 3 files changed, 2 insertions(+), 25 deletions(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 7b66e1e96e4a..8c7e9f1d50d7 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1444,7 +1444,7 @@ static int __rproc_attach(struct rproc *rproc) goto stop_rproc; } - rproc->state = RPROC_RUNNING; + rproc->state = RPROC_ATTACHED; dev_info(dev, "remote processor %s is now attached\n", rproc->name); @@ -1659,14 +1659,6 @@ static int rproc_stop(struct rproc *rproc, bool crashed) rproc->state = RPROC_OFFLINE; - /* - * The remote processor has been stopped and is now offline, which means - * that the next time it is brought back online the remoteproc core will - * be responsible to load its firmware. As such it is no longer - * autonomous. - */ - rproc->autonomous = false; - dev_info(dev, "stopped remote processor %s\n", rproc->name); return 0; @@ -2077,16 +2069,6 @@ int rproc_add(struct rproc *rproc) if (ret < 0) return ret; - /* - * Remind ourselves the remote processor has been attached to rather - * than booted by the remoteproc core. This is important because the - * RPROC_DETACHED state will be lost as soon as the remote processor - * has been attached to. Used in firmware_show() and reset in - * rproc_stop(). - */ - if (rproc->state == RPROC_DETACHED) - rproc->autonomous = true; - /* if rproc is marked always-on, request it to boot */ if (rproc->auto_boot) { ret = rproc_trigger_auto_boot(rproc); diff --git a/drivers/remoteproc/remoteproc_sysfs.c b/drivers/remoteproc/remoteproc_sysfs.c index 4b4aab0d4c4b..f9694def9b54 100644 --- a/drivers/remoteproc/remoteproc_sysfs.c +++ b/drivers/remoteproc/remoteproc_sysfs.c @@ -138,11 +138,8 @@ static ssize_t firmware_show(struct device *dev, struct device_attribute *attr, * If the remote processor has been started by an external * entity we have no idea of what image it is running. As such * simply display a generic string rather then rproc->firmware. - * - * Here we rely on the autonomous flag because a remote processor - * may have been attached to and currently in a running state. */ - if (rproc->autonomous) + if (rproc->state == RPROC_ATTACHED) firmware = "unknown"; return sprintf(buf, "%s\n", firmware); diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h index b0a57ff73849..6b0a0ed30a03 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -512,7 +512,6 @@ 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 - * @autonomous: true if an external entity has booted the remote processor * @dump_segments: list of segments in the firmware * @nb_vdev: number of vdev currently handled by rproc * @char_dev: character device of the rproc @@ -549,7 +548,6 @@ struct rproc { size_t table_sz; bool has_iommu; bool auto_boot; - bool autonomous; struct list_head dump_segments; int nb_vdev; u8 elf_class; From patchwork Fri Mar 12 16:24:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 12135195 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2FA77C433E6 for ; Fri, 12 Mar 2021 16:26:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ED73964F80 for ; Fri, 12 Mar 2021 16:26:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231922AbhCLQZe (ORCPT ); Fri, 12 Mar 2021 11:25:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232493AbhCLQZC (ORCPT ); Fri, 12 Mar 2021 11:25:02 -0500 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA8D8C061763 for ; Fri, 12 Mar 2021 08:25:02 -0800 (PST) Received: by mail-pj1-x1033.google.com with SMTP id x7-20020a17090a2b07b02900c0ea793940so10975853pjc.2 for ; Fri, 12 Mar 2021 08:25:02 -0800 (PST) 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=kdHxs7JLHKePLMQLEfdUiVSo/tj85hv+zhe9KF+ZdIk=; b=l7LAZxN9TdM84y6XXmSm1YUoVCBEHA/A7MD8+YJVgECWfDXYoyUjw/BJMkp2K2hbE7 jggP91z7N1uweUd6crM7s34B80FgnhpMHuROZ+CNPwUk/r7x42UQbj8WQJ/xFeZDyUmk 29zdD2iK3QUkNBuBmIkrneNmmEUL48kFUca9e+lib02FLexcVDD5unHCTICOM2TlaSe9 pNnfevgn94/uUM6rXqMJNUe5nPmpE7OLJF3W7qXzZpljPx/bF/WYFNQe7p9CnXOLnsRD 2qPbdcT0lIh5pPSM1M/cOkeceXB/WQo9Ycn5g8NKa/pbKAKh9WT2ZpRJ2w7LKgPLMXoK eFOg== 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=kdHxs7JLHKePLMQLEfdUiVSo/tj85hv+zhe9KF+ZdIk=; b=H3ZSd8/BR+Ugay5K/yduf5WdCIQ1ojOpww3IBDOcm+cHcquXACHq3rEoXHZjOB4LFz weYIhFDVcHWO9m4mmphTVaKrSvuIuLOhYWSUwdi0wBS8c9/Db3tuo0iLRneIvlAH3C2i WQhHAy/wRJN8epNKZ/+ZpmPuSpCecYIaPooFUspFE8be+ux1M86k6GgRvkGGUw1F++iQ dLT5XykmzKIAIsVehpOQmoVaVI8Vsze/ytZn99vkFmfp9wTnh83Pfeqrz1dbi7WnFxl9 MoYvH7+/eBYZ5zeL8Kz0WT2cxTsbxq9lV1d4XAQuN+SeOkQgQhzZSQiuOvTbJkKbba/+ jb3Q== X-Gm-Message-State: AOAM531JvRXdGYLQo7JuRSPD/DD43J3DbUFPiaoyd4Wj9vpEbO48zEFu Ww4WxsSCb4bfu5IR9g6JYKla6A== X-Google-Smtp-Source: ABdhPJwzIwsGCTHOunkv0cp96iuqqyuE9PCc+MYDxioKGcPZFRhCoV/IxRGWTzXDS8FwK7PnVBH8zQ== X-Received: by 2002:a17:902:344:b029:e4:a7ab:2e55 with SMTP id 62-20020a1709020344b02900e4a7ab2e55mr14592293pld.63.1615566300733; Fri, 12 Mar 2021 08:25:00 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id e8sm5899599pgb.35.2021.03.12.08.24.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 08:25:00 -0800 (PST) From: Mathieu Poirier To: bjorn.andersson@linaro.org, ohad@wizery.com Cc: arnaud.pouliquen@st.com, mcoquelin.stm32@gmail.com, alexandre.torgue@st.com, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v8 05/17] remoteproc: Add new get_loaded_rsc_table() to rproc_ops Date: Fri, 12 Mar 2021 09:24:41 -0700 Message-Id: <20210312162453.1234145-6-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210312162453.1234145-1-mathieu.poirier@linaro.org> References: <20210312162453.1234145-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org Add a new get_loaded_rsc_table() operation in order to support scenarios where the remoteproc core has booted a remote processor and detaches from it. When re-attaching to the remote processor, the core needs to know where the resource table has been placed in memory. Signed-off-by: Mathieu Poirier Reviewed-by: Arnaud Pouliquen --- drivers/remoteproc/remoteproc_core.c | 32 ++++++++++++++++++++++++ drivers/remoteproc/remoteproc_internal.h | 10 ++++++++ include/linux/remoteproc.h | 6 ++++- 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 8c7e9f1d50d7..bf6f6d15b1c3 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1537,6 +1537,32 @@ static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw) return ret; } +static int rproc_set_rsc_table(struct rproc *rproc) +{ + struct resource_table *table_ptr; + struct device *dev = &rproc->dev; + size_t table_sz; + int ret; + + table_ptr = rproc_get_loaded_rsc_table(rproc, &table_sz); + if (!table_ptr) { + /* Not having a resource table is acceptable */ + return 0; + } + + if (IS_ERR(table_ptr)) { + ret = PTR_ERR(table_ptr); + dev_err(dev, "can't load resource table: %d\n", ret); + return ret; + } + + rproc->cached_table = NULL; + rproc->table_ptr = table_ptr; + rproc->table_sz = table_sz; + + return 0; +} + /* * Attach to remote processor - similar to rproc_fw_boot() but without * the steps that deal with the firmware image. @@ -1556,6 +1582,12 @@ static int rproc_attach(struct rproc *rproc) return ret; } + ret = rproc_set_rsc_table(rproc); + if (ret) { + dev_err(dev, "can't load resource table: %d\n", ret); + goto disable_iommu; + } + /* reset max_notifyid */ rproc->max_notifyid = -1; diff --git a/drivers/remoteproc/remoteproc_internal.h b/drivers/remoteproc/remoteproc_internal.h index c34002888d2c..4f73aac7e60d 100644 --- a/drivers/remoteproc/remoteproc_internal.h +++ b/drivers/remoteproc/remoteproc_internal.h @@ -177,6 +177,16 @@ struct resource_table *rproc_find_loaded_rsc_table(struct rproc *rproc, return NULL; } +static inline +struct resource_table *rproc_get_loaded_rsc_table(struct rproc *rproc, + size_t *size) +{ + if (rproc->ops->get_loaded_rsc_table) + return rproc->ops->get_loaded_rsc_table(rproc, size); + + return NULL; +} + static inline bool rproc_u64_fit_in_size_t(u64 val) { diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h index 6b0a0ed30a03..51538a7d120d 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -368,7 +368,9 @@ enum rsc_handling_status { * RSC_HANDLED if resource was handled, RSC_IGNORED if not handled and a * negative value on error * @load_rsc_table: load resource table from firmware image - * @find_loaded_rsc_table: find the loaded resouce table + * @find_loaded_rsc_table: find the loaded resource table from firmware image + * @get_loaded_rsc_table: get resource table installed in memory + * by external entity * @load: load firmware to memory, where the remote processor * expects to find it * @sanity_check: sanity check the fw image @@ -390,6 +392,8 @@ struct rproc_ops { int offset, int avail); struct resource_table *(*find_loaded_rsc_table)( struct rproc *rproc, const struct firmware *fw); + struct resource_table *(*get_loaded_rsc_table)( + struct rproc *rproc, size_t *size); int (*load)(struct rproc *rproc, const struct firmware *fw); int (*sanity_check)(struct rproc *rproc, const struct firmware *fw); u64 (*get_boot_addr)(struct rproc *rproc, const struct firmware *fw); From patchwork Fri Mar 12 16:24:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 12135191 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, UNWANTED_LANGUAGE_BODY,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CD943C433DB for ; Fri, 12 Mar 2021 16:26:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 918A964F80 for ; Fri, 12 Mar 2021 16:26:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232768AbhCLQZc (ORCPT ); Fri, 12 Mar 2021 11:25:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230443AbhCLQZC (ORCPT ); Fri, 12 Mar 2021 11:25:02 -0500 Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4BFFFC061574 for ; Fri, 12 Mar 2021 08:25:02 -0800 (PST) Received: by mail-pl1-x62d.google.com with SMTP id z5so12165692plg.3 for ; Fri, 12 Mar 2021 08:25:02 -0800 (PST) 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=2jJc3BSjHAcYnbTw4MOaj/dDyMsPBuKZdItUtKx3Gk4=; b=BuPiFXVr9ILjW6BRcC0vAURG4AW5M5W1bgwxOa8DSibFoQw59vH3ilctesX66gtaVx iO9xsUIh7r/N7elOFwYN7Qwnc6AMeOZ5qlOYW7AJ8ElB7Mp/dDj5uayzRLsCVLi/NfcV WmKDxmukhcM3E2meMz8z/yKqZ8xEukZMgUANee2uMI85TEOBM6MDThyC1EG+a//KISTk 8j4M/3We/zQdiawkU51XupO2hwz9oJXfyPTboOt8AZZK77PcnS6/5OiXMKj1ET1ZRFvo fLHoL3cGa+9bKQeyalm45vMx8zvALHvaoYAT14Rk+lH+QcxlUKyDL9q6A8M+DVLtz8a3 Z9SQ== 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=2jJc3BSjHAcYnbTw4MOaj/dDyMsPBuKZdItUtKx3Gk4=; b=l06rUO8+wffW3xH3AFIeFuFGbT3AAP2GAfMHX4MA/HIApe34dVwLS5TYd7fFGhn5lH /BlipZ8WKxbR+gkM1V+E49Fc4m49ZPj48vN6NMBSOOthpaXOGalAmnR2RJXdTENrLKEx p1A6mu7QTtnBeu54TtnAlkNZfXXVk64L1YGIfOVQgWaI2sizWB2UatbIqKOabb6HpFVA 9KP6s/XE34ovvCcubGO57yOhas8h1ZIMb22MjrJa1aAOGAWpOWClj35946PihH6AAd5K s9kSJwo+D4e7Ugi3VSA4RywxOppm6KcCXA10zHJeK6QDD1jgsvR6lib2XwZsTU912aZc zf1w== X-Gm-Message-State: AOAM530RZaDfXMBtFVSgIC4T2cNiRSQ2gIV8NYVxUWTGVmBmyP8rkKYi nPjpLWIauy7hZzeeE60HGDV88A== X-Google-Smtp-Source: ABdhPJziMKPW5LeN0jA8gpQxr9WkynY3mbx3nWejxmhkoTdcUZ5/fOLoxXCfabBMPTXxjB0coUEy0g== X-Received: by 2002:a17:902:d64d:b029:de:8aaa:d6ba with SMTP id y13-20020a170902d64db02900de8aaad6bamr14167170plh.0.1615566301837; Fri, 12 Mar 2021 08:25:01 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id e8sm5899599pgb.35.2021.03.12.08.25.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 08:25:01 -0800 (PST) From: Mathieu Poirier To: bjorn.andersson@linaro.org, ohad@wizery.com Cc: arnaud.pouliquen@st.com, mcoquelin.stm32@gmail.com, alexandre.torgue@st.com, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v8 06/17] remoteproc: stm32: Move resource table setup to rproc_ops Date: Fri, 12 Mar 2021 09:24:42 -0700 Message-Id: <20210312162453.1234145-7-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210312162453.1234145-1-mathieu.poirier@linaro.org> References: <20210312162453.1234145-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org Move the setting of the resource table installed by an external entity to rproc_ops::get_loaded_rsc_table(). This is to support scenarios where a remote processor has been attached to but is detached at a later stage. To re-attach the remote processor, the address of the resource table needs to be available at a later time than the platform driver's probe() function. Signed-off-by: Mathieu Poirier Reviewed-by: Arnaud Pouliquen --- drivers/remoteproc/stm32_rproc.c | 141 +++++++++++++++---------------- 1 file changed, 68 insertions(+), 73 deletions(-) diff --git a/drivers/remoteproc/stm32_rproc.c b/drivers/remoteproc/stm32_rproc.c index ccb3c14a0023..f647e565014b 100644 --- a/drivers/remoteproc/stm32_rproc.c +++ b/drivers/remoteproc/stm32_rproc.c @@ -546,6 +546,73 @@ static void stm32_rproc_kick(struct rproc *rproc, int vqid) } } +static int stm32_rproc_da_to_pa(struct rproc *rproc, + u64 da, phys_addr_t *pa) +{ + struct stm32_rproc *ddata = rproc->priv; + struct device *dev = rproc->dev.parent; + struct stm32_rproc_mem *p_mem; + unsigned int i; + + 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(dev, "da %llx to pa %#x\n", da, *pa); + + return 0; + } + + dev_err(dev, "can't translate da %llx\n", da); + + return -EINVAL; +} + +static struct resource_table * +stm32_rproc_get_loaded_rsc_table(struct rproc *rproc, size_t *table_sz) +{ + struct stm32_rproc *ddata = rproc->priv; + struct device *dev = rproc->dev.parent; + phys_addr_t rsc_pa; + u32 rsc_da; + int err; + + /* The resource table has already been mapped, nothing to do */ + if (ddata->rsc_va) + goto done; + + err = regmap_read(ddata->rsctbl.map, ddata->rsctbl.reg, &rsc_da); + if (err) { + dev_err(dev, "failed to read rsc tbl addr\n"); + return ERR_PTR(-EINVAL); + } + + if (!rsc_da) + /* no rsc table */ + return ERR_PTR(-ENOENT); + + err = stm32_rproc_da_to_pa(rproc, rsc_da, &rsc_pa); + if (err) + return ERR_PTR(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 ERR_PTR(-ENOMEM); + } + +done: + /* Assuming the resource table fits in 1kB is fair */ + *table_sz = RSC_TBL_SIZE; + return (struct resource_table *)ddata->rsc_va; +} + static const struct rproc_ops st_rproc_ops = { .start = stm32_rproc_start, .stop = stm32_rproc_stop, @@ -554,6 +621,7 @@ static const struct rproc_ops st_rproc_ops = { .load = rproc_elf_load_segments, .parse_fw = stm32_rproc_parse_fw, .find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table, + .get_loaded_rsc_table = stm32_rproc_get_loaded_rsc_table, .sanity_check = rproc_elf_sanity_check, .get_boot_addr = rproc_elf_get_boot_addr, }; @@ -695,75 +763,6 @@ static int stm32_rproc_get_m4_status(struct stm32_rproc *ddata, return regmap_read(ddata->m4_state.map, ddata->m4_state.reg, state); } -static int stm32_rproc_da_to_pa(struct platform_device *pdev, - struct stm32_rproc *ddata, - u64 da, phys_addr_t *pa) -{ - struct device *dev = &pdev->dev; - struct stm32_rproc_mem *p_mem; - unsigned int i; - - 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(dev, "da %llx to pa %#x\n", da, *pa); - - return 0; - } - - dev_err(dev, "can't translate da %llx\n", da); - - return -EINVAL; -} - -static int stm32_rproc_get_loaded_rsc_table(struct platform_device *pdev, - struct rproc *rproc, - struct stm32_rproc *ddata) -{ - struct device *dev = &pdev->dev; - phys_addr_t rsc_pa; - u32 rsc_da; - int err; - - err = regmap_read(ddata->rsctbl.map, ddata->rsctbl.reg, &rsc_da); - if (err) { - dev_err(dev, "failed to read rsc tbl addr\n"); - return err; - } - - if (!rsc_da) - /* no rsc table */ - return 0; - - err = stm32_rproc_da_to_pa(pdev, ddata, 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; - } - - /* - * The resource table is already loaded in device memory, no need - * to work with a cached table. - */ - rproc->cached_table = NULL; - /* Assuming the resource table fits in 1kB is fair */ - rproc->table_sz = RSC_TBL_SIZE; - rproc->table_ptr = (struct resource_table *)ddata->rsc_va; - - return 0; -} - static int stm32_rproc_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -803,10 +802,6 @@ static int stm32_rproc_probe(struct platform_device *pdev) ret = stm32_rproc_parse_memory_regions(rproc); if (ret) goto free_resources; - - ret = stm32_rproc_get_loaded_rsc_table(pdev, rproc, ddata); - if (ret) - goto free_resources; } rproc->has_iommu = false; From patchwork Fri Mar 12 16:24:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 12135193 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1A68EC433E0 for ; Fri, 12 Mar 2021 16:26:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D671265006 for ; Fri, 12 Mar 2021 16:26:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232493AbhCLQZf (ORCPT ); Fri, 12 Mar 2021 11:25:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232529AbhCLQZE (ORCPT ); Fri, 12 Mar 2021 11:25:04 -0500 Received: from mail-pg1-x530.google.com (mail-pg1-x530.google.com [IPv6:2607:f8b0:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11AE0C061574 for ; Fri, 12 Mar 2021 08:25:04 -0800 (PST) Received: by mail-pg1-x530.google.com with SMTP id 16so9771692pgo.13 for ; Fri, 12 Mar 2021 08:25:04 -0800 (PST) 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=V6QBix4Xk7mXD3k02J6NEnaLX2tt4w4cfwoG6OuF1xs=; b=giiTC6LOrHmzbDHoMAWlZerTgjx0RGur9+eV8YUslHbUH97lzzNAmPacyIDi6HJt9E j7ZQXvozxg26YyjAn05q6UA49O2ExF0r3ktI4iAuTcCQH+iL1UbNJLwNLyV7rW9iXbCU jRsQaYt+tYt3kQyDqu4+2JD/BgRdKiHdNO7N/9viOevE9MgWpXl226Y/CG8+UsVI3mK5 s8Rf4/2AS5uQKDRrV+RR1XJAKydJMuAxvnG2WVFlWQdeK9GqUAxw/jXuntLOZqJ1phyp wV2uRDP4I3DjAb0Y69sSz4wloX3qLqVyRBpwZSgFI2SehimK/Bx2BIhn1101XriaHZEl s42g== 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=V6QBix4Xk7mXD3k02J6NEnaLX2tt4w4cfwoG6OuF1xs=; b=aWaJ+wwAqM3MitD0Qr4k6f9QCzjXUc9AUSWpIbW110T8+czh00uHXKA1eKd8//gQN8 7O8IkjZIUxDNekyEuW+Sr8eDdInOXglftBdPQ2AVjX/8xq38tytiU1dfGR4Kteu3RIJ5 agCuzB2Fk3aPVTLCC+WHfGeYRuyQkBjEQ+fz8LCq8r5zWbMM4jvPlYscATdomGPUgpBp MhYvHrjOumc6kx+toSX9znyetKd0SPBLjqUS1bqeU1lOAtASEpMWtOmzAdc/cLRQ4qNV QOGb0MaczINLS3W/Hv830Lbr1g7uoQAUDpKQy7k3XM3TNL4Dj1AzxqaxD7yPwSYYeleo 0MYg== X-Gm-Message-State: AOAM533gSHq/xqh/HDj36tBJcu4hKCeImPH5NZCQh8MP1pdZzlRlC162 uf+si/GXVTkjfqXqv8rVh4ZtJg== X-Google-Smtp-Source: ABdhPJxKS8aMKxiB0EWPGc6UKVjLBhFQVzj1avFQEzLyCsSGbeJWol9zgT6O2uoILTELLnt5e4ji/g== X-Received: by 2002:a62:1e46:0:b029:1f3:ad4f:9c6b with SMTP id e67-20020a621e460000b02901f3ad4f9c6bmr13436179pfe.64.1615566303604; Fri, 12 Mar 2021 08:25:03 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id e8sm5899599pgb.35.2021.03.12.08.25.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 08:25:03 -0800 (PST) From: Mathieu Poirier To: bjorn.andersson@linaro.org, ohad@wizery.com Cc: arnaud.pouliquen@st.com, mcoquelin.stm32@gmail.com, alexandre.torgue@st.com, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v8 07/17] remoteproc: stm32: Move memory parsing to rproc_ops Date: Fri, 12 Mar 2021 09:24:43 -0700 Message-Id: <20210312162453.1234145-8-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210312162453.1234145-1-mathieu.poirier@linaro.org> References: <20210312162453.1234145-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org From: Arnaud POULIQUEN Some actions such as memory resources reallocation are needed when trying to reattach a co-processor. Use the prepare() operation for these actions. Co-developed-by: Mathieu Poirier Signed-off-by: Mathieu Poirier Signed-off-by: Arnaud POULIQUEN --- drivers/remoteproc/remoteproc_core.c | 14 ++++++++++++-- drivers/remoteproc/stm32_rproc.c | 27 ++++++--------------------- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index bf6f6d15b1c3..1d8bb588d996 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1582,10 +1582,17 @@ static int rproc_attach(struct rproc *rproc) return ret; } + /* Do anything that is needed to boot the remote processor */ + ret = rproc_prepare_device(rproc); + if (ret) { + dev_err(dev, "can't prepare rproc %s: %d\n", rproc->name, ret); + goto disable_iommu; + } + ret = rproc_set_rsc_table(rproc); if (ret) { dev_err(dev, "can't load resource table: %d\n", ret); - goto disable_iommu; + goto unprepare_device; } /* reset max_notifyid */ @@ -1602,7 +1609,7 @@ static int rproc_attach(struct rproc *rproc) ret = rproc_handle_resources(rproc, rproc_loading_handlers); if (ret) { dev_err(dev, "Failed to process resources: %d\n", ret); - goto disable_iommu; + goto unprepare_device; } /* Allocate carveout resources associated to rproc */ @@ -1621,6 +1628,9 @@ static int rproc_attach(struct rproc *rproc) clean_up_resources: rproc_resource_cleanup(rproc); +unprepare_device: + /* release HW resources if needed */ + rproc_unprepare_device(rproc); disable_iommu: rproc_disable_iommu(rproc); return ret; diff --git a/drivers/remoteproc/stm32_rproc.c b/drivers/remoteproc/stm32_rproc.c index f647e565014b..3d45f51de4d0 100644 --- a/drivers/remoteproc/stm32_rproc.c +++ b/drivers/remoteproc/stm32_rproc.c @@ -207,16 +207,7 @@ static int stm32_rproc_mbox_idx(struct rproc *rproc, const unsigned char *name) return -EINVAL; } -static int stm32_rproc_elf_load_rsc_table(struct rproc *rproc, - const struct firmware *fw) -{ - if (rproc_elf_load_rsc_table(rproc, fw)) - dev_warn(&rproc->dev, "no resource table found for this firmware\n"); - - return 0; -} - -static int stm32_rproc_parse_memory_regions(struct rproc *rproc) +static int stm32_rproc_prepare(struct rproc *rproc) { struct device *dev = rproc->dev.parent; struct device_node *np = dev->of_node; @@ -274,12 +265,10 @@ static int stm32_rproc_parse_memory_regions(struct rproc *rproc) static int stm32_rproc_parse_fw(struct rproc *rproc, const struct firmware *fw) { - int ret = stm32_rproc_parse_memory_regions(rproc); - - if (ret) - return ret; + if (rproc_elf_load_rsc_table(rproc, fw)) + dev_warn(&rproc->dev, "no resource table found for this firmware\n"); - return stm32_rproc_elf_load_rsc_table(rproc, fw); + return 0; } static irqreturn_t stm32_rproc_wdg(int irq, void *data) @@ -614,6 +603,7 @@ stm32_rproc_get_loaded_rsc_table(struct rproc *rproc, size_t *table_sz) } static const struct rproc_ops st_rproc_ops = { + .prepare = stm32_rproc_prepare, .start = stm32_rproc_start, .stop = stm32_rproc_stop, .attach = stm32_rproc_attach, @@ -796,14 +786,9 @@ static int stm32_rproc_probe(struct platform_device *pdev) if (ret) goto free_rproc; - if (state == M4_STATE_CRUN) { + if (state == M4_STATE_CRUN) rproc->state = RPROC_DETACHED; - ret = stm32_rproc_parse_memory_regions(rproc); - if (ret) - goto free_resources; - } - rproc->has_iommu = false; ddata->workqueue = create_workqueue(dev_name(dev)); if (!ddata->workqueue) { From patchwork Fri Mar 12 16:24:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 12135197 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 80E0CC4332D for ; Fri, 12 Mar 2021 16:26:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 54BF265019 for ; Fri, 12 Mar 2021 16:26:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232575AbhCLQZf (ORCPT ); Fri, 12 Mar 2021 11:25:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232707AbhCLQZF (ORCPT ); Fri, 12 Mar 2021 11:25:05 -0500 Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42FC1C061574 for ; Fri, 12 Mar 2021 08:25:05 -0800 (PST) Received: by mail-pj1-x102e.google.com with SMTP id s21so5385361pjq.1 for ; Fri, 12 Mar 2021 08:25:05 -0800 (PST) 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=XYqKe5JHKTsf6qqgvmLT8SEOr6JSbsFQUrC6la75+Tk=; b=NSR3WPj9kVNOA3Z+lyfGa5gZK8OdIdz44lqCk0bWIR75Fl1XpX52MaSy+gCFgyriLE lk3wU8lymjl4n+0SAKdE1CIpBYg/f5vhemjcwiFSjYdBfe4sqHxIGz/+vYqBR2OQW3vg IJnDoVl6TVZ2ce64zpgNhkrPkjrEG1Bj5LpvC8HF9FKweSh44nXA9NdTL7tZPeVhj2xi jzPe8ViHhVICXCW919IGffk6+BuRtqZszzqbEDzkTvckOF4FuvM/0L8u7aO16VxXz9GN HEb7ln5+PTDT2fHC8gVGNdXOOrO+SmFIBMggLrCZjvZxAcz2XpQ08fyev+TxEdbqXvEd uVrQ== 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=XYqKe5JHKTsf6qqgvmLT8SEOr6JSbsFQUrC6la75+Tk=; b=EahD4a0/MHInT5cTiChOn/18TwXiyX6vwrkgSuNhzUCREDgBgn7Y9tFT1Rn2tw/CBW djVE2FAdCVwSl4d5tDa5NMK9s8fkua7T7aAGF/hZizOirFv/R5KH/XyCUYxt3HfQE9GF D8UFvYv77biceO7+fU3JcRRTn+c0bO4fc03SG/bsKCh7JXlTUpXfXuv+Zb/JgZExBG82 iAA0LzWE88U+z5Iy0+5/vSkzyWbOVlSCCEEPWv96Z2u5caazh2Y0uqKRISYOWduV01nS tJtQ8WkCiHcsnRv9XEG/PIpLrSqOrvN6PBiONANj7MAwsRWk+456WVqzWqd3910tLxHU rMMg== X-Gm-Message-State: AOAM533Qp59hQ8C5qWUNfDCXcgo4U9IAJD6BCaFtRgtgEFOxt0Fi7pgX xFhJ2m+xUz43F/2nts9AxLJOiw== X-Google-Smtp-Source: ABdhPJzBoHcM7FRG/IPPBelrke7jASa1grvRPE7jreUEMZqm67LUJ5ZCN/OtWi+sRjWc0lUdmo0C3A== X-Received: by 2002:a17:902:e806:b029:e5:cb85:dc4d with SMTP id u6-20020a170902e806b02900e5cb85dc4dmr14247156plg.11.1615566304850; Fri, 12 Mar 2021 08:25:04 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id e8sm5899599pgb.35.2021.03.12.08.25.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 08:25:04 -0800 (PST) From: Mathieu Poirier To: bjorn.andersson@linaro.org, ohad@wizery.com Cc: arnaud.pouliquen@st.com, mcoquelin.stm32@gmail.com, alexandre.torgue@st.com, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v8 08/17] remoteproc: Add new detach() remoteproc operation Date: Fri, 12 Mar 2021 09:24:44 -0700 Message-Id: <20210312162453.1234145-9-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210312162453.1234145-1-mathieu.poirier@linaro.org> References: <20210312162453.1234145-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org Add an new detach() operation in order to support scenarios where the remoteproc core is going away but the remote processor is kept operating. This could be the case when the system is rebooted or when the platform driver is removed. Signed-off-by: Mathieu Poirier Reviewed-by: Peng Fan Reviewed-by: Arnaud Pouliquen --- include/linux/remoteproc.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h index 51538a7d120d..eff55ec72e80 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -361,6 +361,7 @@ enum rsc_handling_status { * @start: power on the device and boot it * @stop: power off the device * @attach: attach to a device that his already powered up + * @detach: detach from a device, leaving it powered up * @kick: kick a virtqueue (virtqueue id given as a parameter) * @da_to_va: optional platform hook to perform address translations * @parse_fw: parse firmware to extract information (e.g. resource table) @@ -385,6 +386,7 @@ struct rproc_ops { int (*start)(struct rproc *rproc); int (*stop)(struct rproc *rproc); int (*attach)(struct rproc *rproc); + int (*detach)(struct rproc *rproc); void (*kick)(struct rproc *rproc, int vqid); void * (*da_to_va)(struct rproc *rproc, u64 da, size_t len); int (*parse_fw)(struct rproc *rproc, const struct firmware *fw); From patchwork Fri Mar 12 16:24:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 12135205 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AF717C43333 for ; Fri, 12 Mar 2021 16:26:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9596B64F80 for ; Fri, 12 Mar 2021 16:26:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232644AbhCLQZg (ORCPT ); Fri, 12 Mar 2021 11:25:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232471AbhCLQZG (ORCPT ); Fri, 12 Mar 2021 11:25:06 -0500 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5696FC061574 for ; Fri, 12 Mar 2021 08:25:06 -0800 (PST) Received: by mail-pl1-x62c.google.com with SMTP id d8so12140272plg.10 for ; Fri, 12 Mar 2021 08:25:06 -0800 (PST) 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=s41xNBSRWZdaT0/t4ukszEcW0OmYZRiq0VgJP9qHLTU=; b=N/OZ19vzKvAIJ45rejwYBpeamiYN00ABVqI68joDL+QjYaI9gYGoCi3Z+3GLz4XRb0 hI12xVXbF7V1IwT9jLhof8caFqkLO+IZm9vOUqiJbygWJDLp0mNFm4UyeR+hcrxf/cy+ iUkLGJs/uWcaBAqbAU1UgTlOMpffP4vypEvCfwf9L/vFp+lczPZGKm04wnJvRKhvMLOZ 18XIb+Uh61beMhRc1ouGNQMo/khePGxGrd3fU9jOpiWdT93Bc/3tZ2VWij1s4tAuXctX ATo2QZvC8ey9nk3OEqEs1zWSFu1IrX4PelzWOkOK6eoAvRbLZRmuZn65tL/iOLRkFvs+ FJfQ== 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=s41xNBSRWZdaT0/t4ukszEcW0OmYZRiq0VgJP9qHLTU=; b=WKkezQ6PcFNyQwEkIfMJdm7Ttc+WV4eMqs4vQp6FkcJFYy1H+pv85xGvAh1zzI6Yu6 mX5+99EVqMMbOo28sp/YwvNu4Zlw494KL79k8QjYtJUONtrJKBuI2BOImcLZ3GMtq/9d YtE2tYun96Xn5Z8C1RktD+OFyLUEQ6BNMrM8rmafExPxq4SpOAIoqi9cFJq8Lj004jQ4 g8HErrqO+LgLL1/2gF7YKny8JVoyMZ/R/xOpQ3iCGRk/pi4Vz2QW3jRnJRwWwXO7sjT9 DjEIXq3+1eP5A4RVbRH35xmrhBhIc9A8HUTygTd8CzMJIvmWQyZGn72mrPDlZ1YRyNmu MErA== X-Gm-Message-State: AOAM531AW+ZfPMZxyQZfG4nNEtQrhqgd1dVEmXTSvY26XcTS7C8xXtxB vnt+mEPxqWaMs+XExsBoCp5GZA== X-Google-Smtp-Source: ABdhPJy4xjO8O6EA3p4/QVUnSBaJ9fYPirTjbD+/VVyrO7DYDSm/KBsbvJSiwwZA7GMRhblw/5m7ug== X-Received: by 2002:a17:902:da91:b029:e5:cd82:b4c3 with SMTP id j17-20020a170902da91b02900e5cd82b4c3mr13938873plx.73.1615566305939; Fri, 12 Mar 2021 08:25:05 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id e8sm5899599pgb.35.2021.03.12.08.25.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 08:25:05 -0800 (PST) From: Mathieu Poirier To: bjorn.andersson@linaro.org, ohad@wizery.com Cc: arnaud.pouliquen@st.com, mcoquelin.stm32@gmail.com, alexandre.torgue@st.com, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v8 09/17] remoteproc: Introduce function __rproc_detach() Date: Fri, 12 Mar 2021 09:24:45 -0700 Message-Id: <20210312162453.1234145-10-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210312162453.1234145-1-mathieu.poirier@linaro.org> References: <20210312162453.1234145-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org Introduce function __rproc_detach() to perform the same kind of operation as rproc_stop(), but instead of switching off the remote processor using rproc->ops->stop(), it uses rproc->ops->detach(). That way it is possible for the core to release the resources associated with a remote processor while the latter is kept operating. Signed-off-by: Mathieu Poirier Reviewed-by: Peng Fan Reviewed-by: Arnaud Pouliquen --- drivers/remoteproc/remoteproc_core.c | 30 ++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 1d8bb588d996..f2a005eadfd5 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1706,6 +1706,36 @@ static int rproc_stop(struct rproc *rproc, bool crashed) return 0; } +/* + * __rproc_detach(): Does the opposite of __rproc_attach() + */ +static int __maybe_unused __rproc_detach(struct rproc *rproc) +{ + struct device *dev = &rproc->dev; + int ret; + + /* No need to continue if a detach() operation has not been provided */ + if (!rproc->ops->detach) + return -EINVAL; + + /* Stop any subdevices for the remote processor */ + rproc_stop_subdevices(rproc, false); + + /* Tell the remote processor the core isn't available anymore */ + ret = rproc->ops->detach(rproc); + if (ret) { + dev_err(dev, "can't detach from rproc: %d\n", ret); + return ret; + } + + rproc_unprepare_subdevices(rproc); + + rproc->state = RPROC_DETACHED; + + dev_info(dev, "detached remote processor %s\n", rproc->name); + + return 0; +} /** * rproc_trigger_recovery() - recover a remoteproc From patchwork Fri Mar 12 16:24:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 12135201 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9F76FC4332E for ; Fri, 12 Mar 2021 16:26:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 812B66502A for ; Fri, 12 Mar 2021 16:26:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232707AbhCLQZh (ORCPT ); Fri, 12 Mar 2021 11:25:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232602AbhCLQZH (ORCPT ); Fri, 12 Mar 2021 11:25:07 -0500 Received: from mail-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 533BEC061761 for ; Fri, 12 Mar 2021 08:25:07 -0800 (PST) Received: by mail-pg1-x529.google.com with SMTP id q5so3535893pgk.5 for ; Fri, 12 Mar 2021 08:25:07 -0800 (PST) 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=WeMR2UtisGi6ZgniJxY2/huWWVqD2xtcqc6NMb4K8/0=; b=hrmwJzSYPIeP/ikZT0FUOv6iNAG4dxqmaR+3RCyjsplRRAuMhA18kcECbj7vvnAfbe NaSOfAOhiwcTNuUncNMnaMH9m8xrQZ7x9QiU+6ereEKhmOunMqFONUNeV1lqMeUuFKoe chO/8SgS69s2HCvoIYZi8d3H2THRXm5sQHG3/IJqf4GF+bDjxxZvhRJo2il3Bah69cC/ EPhbDfb+9DCY7UCNVU4zDFokOlHJI2Tg3SEvq4E9lCEK0H5y5r0cWDirocy704YqjLT1 ylUxAxgSecBSJctZFQD9HYMltmPLUDKPPFVuZ5KabPkcxM0QEItPDsLWVfn3u+POM5wu yJbg== 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=WeMR2UtisGi6ZgniJxY2/huWWVqD2xtcqc6NMb4K8/0=; b=TAZrrf+rNHp7VG/k9QM4dA3OeVAvQAD3Yfv3IWs1IQGhqi+gn9uoh4ewJDHYHcEsuE daabW6Fuc6iJ+5dI1SCO85VT2EcbiKnf0JImfGzDBNyjDyPyRcKeq5q1TiDL2oV0TxJv Bv4lCao4D4I8+r1CUVn2rRi2G2Vz9Dc4qmLEETAwDne715RmB0gjtnLhKHvdhQq9Lo9p LaXpf7gBBtzi8O+KVissTf0X5T/vhqKDiP44Mu77sjEcIgJnD4ejErJ+3IJrMMSGkYle a+tjSnH/pSdpB3wG/BrFNZtU5Ral7t76/ssswZ5+82gWuZCoCGstIlw0oaBSdxzXDC4v IKkg== X-Gm-Message-State: AOAM531F0xxi5eCc9MJXlrNo5UNnPUEV6ODZnp2T4V6PAJE+zniV3sCv htV6oUmsuzVDO6q+xFFl/OiCdg== X-Google-Smtp-Source: ABdhPJzG1eDI723bt2kBSs0HFCqP+6RTmAujlcRDLukJBy4XPGPLLvd/XCuOcRq13/2rKSaBaiv9KA== X-Received: by 2002:a63:fc07:: with SMTP id j7mr12638054pgi.401.1615566306850; Fri, 12 Mar 2021 08:25:06 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id e8sm5899599pgb.35.2021.03.12.08.25.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 08:25:06 -0800 (PST) From: Mathieu Poirier To: bjorn.andersson@linaro.org, ohad@wizery.com Cc: arnaud.pouliquen@st.com, mcoquelin.stm32@gmail.com, alexandre.torgue@st.com, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v8 10/17] remoteproc: Introduce function rproc_detach() Date: Fri, 12 Mar 2021 09:24:46 -0700 Message-Id: <20210312162453.1234145-11-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210312162453.1234145-1-mathieu.poirier@linaro.org> References: <20210312162453.1234145-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org Introduce function rproc_detach() to enable the remoteproc core to release the resources associated with a remote processor without stopping its operation. Signed-off-by: Mathieu Poirier Reviewed-by: Arnaud Pouliquen --- drivers/remoteproc/remoteproc_core.c | 58 +++++++++++++++++++++++++++- include/linux/remoteproc.h | 1 + 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index f2a005eadfd5..5eaa47c3ba92 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1709,7 +1709,7 @@ static int rproc_stop(struct rproc *rproc, bool crashed) /* * __rproc_detach(): Does the opposite of __rproc_attach() */ -static int __maybe_unused __rproc_detach(struct rproc *rproc) +static int __rproc_detach(struct rproc *rproc) { struct device *dev = &rproc->dev; int ret; @@ -1948,6 +1948,62 @@ void rproc_shutdown(struct rproc *rproc) } EXPORT_SYMBOL(rproc_shutdown); +/** + * rproc_detach() - Detach the remote processor from the + * remoteproc core + * + * @rproc: the remote processor + * + * Detach a remote processor (previously attached to with rproc_attach()). + * + * In case @rproc is still being used by an additional user(s), then + * this function will just decrement the power refcount and exit, + * without disconnecting the device. + * + * Function rproc_detach() calls __rproc_detach() in order to let a remote + * processor know that services provided by the application processor are + * no longer available. From there it should be possible to remove the + * platform driver and even power cycle the application processor (if the HW + * supports it) without needing to switch off the remote processor. + */ +int rproc_detach(struct rproc *rproc) +{ + struct device *dev = &rproc->dev; + int ret; + + ret = mutex_lock_interruptible(&rproc->lock); + if (ret) { + dev_err(dev, "can't lock rproc %s: %d\n", rproc->name, ret); + return ret; + } + + /* if the remote proc is still needed, bail out */ + if (!atomic_dec_and_test(&rproc->power)) { + ret = 0; + goto out; + } + + ret = __rproc_detach(rproc); + if (ret) { + atomic_inc(&rproc->power); + goto out; + } + + /* clean up all acquired resources */ + rproc_resource_cleanup(rproc); + + /* release HW resources if needed */ + rproc_unprepare_device(rproc); + + rproc_disable_iommu(rproc); + + rproc->table_ptr = NULL; +out: + mutex_unlock(&rproc->lock); + return ret; +} +EXPORT_SYMBOL(rproc_detach); + /** * rproc_get_by_phandle() - find a remote processor by phandle * @phandle: phandle to the rproc diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h index eff55ec72e80..e1c843c19cc6 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -662,6 +662,7 @@ rproc_of_resm_mem_entry_init(struct device *dev, u32 of_resm_idx, size_t len, int rproc_boot(struct rproc *rproc); void rproc_shutdown(struct rproc *rproc); +int rproc_detach(struct rproc *rproc); int rproc_set_firmware(struct rproc *rproc, const char *fw_name); void rproc_report_crash(struct rproc *rproc, enum rproc_crash_type type); void rproc_coredump_using_sections(struct rproc *rproc); From patchwork Fri Mar 12 16:24:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 12135209 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4A466C4321A for ; Fri, 12 Mar 2021 16:26:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 155F764F80 for ; Fri, 12 Mar 2021 16:26:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232771AbhCLQZh (ORCPT ); Fri, 12 Mar 2021 11:25:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232466AbhCLQZI (ORCPT ); Fri, 12 Mar 2021 11:25:08 -0500 Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7108C061761 for ; Fri, 12 Mar 2021 08:25:08 -0800 (PST) Received: by mail-pg1-x52d.google.com with SMTP id o38so16186082pgm.9 for ; Fri, 12 Mar 2021 08:25:08 -0800 (PST) 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=R0TXzfTF++XcnwzyZM9Oeax7CL4rb6/mdtuV8iWH+MI=; b=Qc2yYkrxTGTq5jVFrq2PfpRWsvsAW6N4IX9Itic0y/cteOq/6udH2YGhsVaENOr8mG 4fH+eVpLyJjPrgd7NFFXC7hRWQkA0iTMSiBV557nUE2bMf7QFJz4K8Y7Nt4SQ0i6+KzM v4tF5lFD1646ow5RKJfFeE0aVMTelQeKH4+bWomE8I6Dcp4ji9dn0e4rtel2PxmafN6r 92OVZheg8uCy/v7VFDFQU1GG4c8249faYwV4U/c/cPbFx1Oqjw4e9Y+JhmMYIWRNcnIU Dxu6ze37qA9a6f3p/ZcLMMyLqwblWh+7oAYRdBCLwAC5SPUaJh6neZrVNIFZsDeCK8Oh bhJg== 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=R0TXzfTF++XcnwzyZM9Oeax7CL4rb6/mdtuV8iWH+MI=; b=jmzReEEfOByf30o4LO+PwpOC7oMtckdPp0/RwdMs2qsD9ggH0KsYwUVdtxfFF8PaK0 vn0MB2v44riTlSi1dlZ6kBzEGyBbjsp3MXlv7Ztk4RVV6oQ1XpBLT8bO15hqHFmjh//r YG5h5kOfgnhmo7cOPFbwrVOys+hTYWeUdoBMSuke+3SSYJ1CJiU7UMtnwGfjzLbpqFNk TcJjAtKxKJKbpbAxk76YJEe2oZC1RzWL14o3spFyOAEH30laOecUeU5imqo96tHtUeUW uFbx+LLTkRHuhz7K1dfNlX2EYo47M7UvX1hMt9gOBmDF8ZqzH5me/LgoOlKerTZQA80g bl1g== X-Gm-Message-State: AOAM533VSgYgyqLQ7WADNcKCtpdAEJ75YiCYpcXoqG5Dp25RhP3YnLuU gXEYnyrzsqLRvyWlwMZohOir2A== X-Google-Smtp-Source: ABdhPJwSfjAfXthMtfRPRHzlVt7WIFpKu5atR2lmyp0jiUhQQ3UI0Wh1HVqotOCWI0jvj6JWFZJP0Q== X-Received: by 2002:a63:4241:: with SMTP id p62mr12359250pga.453.1615566307948; Fri, 12 Mar 2021 08:25:07 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id e8sm5899599pgb.35.2021.03.12.08.25.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 08:25:07 -0800 (PST) From: Mathieu Poirier To: bjorn.andersson@linaro.org, ohad@wizery.com Cc: arnaud.pouliquen@st.com, mcoquelin.stm32@gmail.com, alexandre.torgue@st.com, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v8 11/17] remoteproc: Properly deal with the resource table when detaching Date: Fri, 12 Mar 2021 09:24:47 -0700 Message-Id: <20210312162453.1234145-12-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210312162453.1234145-1-mathieu.poirier@linaro.org> References: <20210312162453.1234145-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org If it is possible to detach the remote processor, keep an untouched copy of the resource table. That way we can start from the same resource table without having to worry about original values or what elements the startup code has changed when re-attaching to the remote processor. Signed-off-by: Mathieu Poirier Reviewed-by: Arnaud Pouliquen --- New for V8: - Checking return code for error in __rproc_datch(). --- drivers/remoteproc/remoteproc_core.c | 82 ++++++++++++++++++++++++++++ include/linux/remoteproc.h | 3 + 2 files changed, 85 insertions(+) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 5eaa47c3ba92..0f151dbcdc36 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1556,6 +1556,24 @@ static int rproc_set_rsc_table(struct rproc *rproc) return ret; } + /* + * If it is possible to detach the remote processor, keep an untouched + * copy of the resource table. That way we can start fresh again when + * the remote processor is re-attached, that is: + * + * DETACHED -> ATTACHED -> DETACHED -> ATTACHED + * + * Free'd in rproc_reset_rsc_table_on_detach() and + * rproc_reset_rsc_table_on_stop(). + */ + if (rproc->ops->detach) { + rproc->clean_table = kmemdup(table_ptr, table_sz, GFP_KERNEL); + if (!rproc->clean_table) + return -ENOMEM; + } else { + rproc->clean_table = NULL; + } + rproc->cached_table = NULL; rproc->table_ptr = table_ptr; rproc->table_sz = table_sz; @@ -1563,6 +1581,59 @@ static int rproc_set_rsc_table(struct rproc *rproc) return 0; } +static int rproc_reset_rsc_table_on_detach(struct rproc *rproc) +{ + struct resource_table *table_ptr; + + /* A resource table was never retrieved, nothing to do here */ + if (!rproc->table_ptr) + return 0; + + /* + * If we made it to this point a clean_table _must_ have been + * allocated in rproc_set_rsc_table(). If one isn't present + * something went really wrong and we must complain. + */ + if (WARN_ON(!rproc->clean_table)) + return -EINVAL; + + /* Remember where the external entity installed the resource table */ + table_ptr = rproc->table_ptr; + + /* + * If we made it here the remote processor was started by another + * entity and a cache table doesn't exist. As such make a copy of + * the resource table currently used by the remote processor and + * use that for the rest of the shutdown process. The memory + * allocated here is free'd in rproc_detach(). + */ + rproc->cached_table = kmemdup(rproc->table_ptr, + rproc->table_sz, GFP_KERNEL); + if (!rproc->cached_table) + return -ENOMEM; + + /* + * Use a copy of the resource table for the remainder of the + * shutdown process. + */ + rproc->table_ptr = rproc->cached_table; + + /* + * Reset the memory area where the firmware loaded the resource table + * to its original value. That way when we re-attach the remote + * processor the resource table is clean and ready to be used again. + */ + memcpy(table_ptr, rproc->clean_table, rproc->table_sz); + + /* + * The clean resource table is no longer needed. Allocated in + * rproc_set_rsc_table(). + */ + kfree(rproc->clean_table); + + return 0; +} + /* * Attach to remote processor - similar to rproc_fw_boot() but without * the steps that deal with the firmware image. @@ -1721,6 +1792,14 @@ static int __rproc_detach(struct rproc *rproc) /* Stop any subdevices for the remote processor */ rproc_stop_subdevices(rproc, false); + /* the installed resource table is no longer accessible */ + ret = rproc_reset_rsc_table_on_detach(rproc); + if (ret) { + dev_err(dev, "can't reset resource table: %d\n", ret); + return ret; + } + + /* Tell the remote processor the core isn't available anymore */ ret = rproc->ops->detach(rproc); if (ret) { @@ -1997,6 +2076,9 @@ int rproc_detach(struct rproc *rproc) rproc_disable_iommu(rproc); + /* Free the copy of the resource table */ + kfree(rproc->cached_table); + rproc->cached_table = NULL; rproc->table_ptr = NULL; out: mutex_unlock(&rproc->lock); diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h index e1c843c19cc6..e5f52a12a650 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -514,6 +514,8 @@ struct rproc_dump_segment { * @recovery_disabled: flag that state if recovery was disabled * @max_notifyid: largest allocated notify id. * @table_ptr: pointer to the resource table in effect + * @clean_table: copy of the resource table without modifications. Used + * when a remote processor is attached or detached from the core * @cached_table: copy of the resource table * @table_sz: size of @cached_table * @has_iommu: flag to indicate if remote processor is behind an MMU @@ -550,6 +552,7 @@ struct rproc { bool recovery_disabled; int max_notifyid; struct resource_table *table_ptr; + struct resource_table *clean_table; struct resource_table *cached_table; size_t table_sz; bool has_iommu; From patchwork Fri Mar 12 16:24:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 12135203 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BF20FC43332 for ; Fri, 12 Mar 2021 16:26:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A7D7164FD9 for ; Fri, 12 Mar 2021 16:26:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232603AbhCLQZi (ORCPT ); Fri, 12 Mar 2021 11:25:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232731AbhCLQZJ (ORCPT ); Fri, 12 Mar 2021 11:25:09 -0500 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D3D5C061761 for ; Fri, 12 Mar 2021 08:25:09 -0800 (PST) Received: by mail-pl1-x629.google.com with SMTP id s7so12150466plg.5 for ; Fri, 12 Mar 2021 08:25:09 -0800 (PST) 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=z++nDe1KbxQOwXuMBZocx2SGGQIMJC2S/9LC839MlY0=; b=dEFpi8aTE2Hk60yckTPByYR568S6yUjP9+TvhjVa2Mk/l9ACJ1m2UU4R6sSPSxPSMO RaV70NJQvdzkpX8/C98C7Uj+/Q46X9YPeunzqGsOfwYAQ+gykm43WATfCAszb5tyFmuv GST6g8cm1qQW1r8kYic1vLYpwNJdc1FL4JIX62mBrpdQj4+Vqvw7XVXCuYVNWd4uEPev lhue/blcKkOvz80iV6ApuJ1owjRkcHIYeDhPeGwwiMGO4ZzMpSNTWycONfAano5e7HMn rdAWBdkYF1PmTMf4Ejo0EJDDkh75vUmkeF0vJyuScsqy4vdbwwUtyP92yMSb+66mPMwu SbcA== 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=z++nDe1KbxQOwXuMBZocx2SGGQIMJC2S/9LC839MlY0=; b=n4W0Oz0uFbMwaJHeqUGq8zHjojg0OzF1RBpVxNntz88ydJ7fMBP1wDBXbjB/pu76z4 aTJ5rfHZ7xTFNWgOMZCZ6bWyOKr7W7exH4k/u0F9fvigg3G7PDdgcmQ0TZYj6GxQICe4 0RJ0maxW43Rs9NrJZSRhkCgUqdXQO8cC3Ii+pwJAkstxdaGjBIINyd6dyF/Ao/lF/W33 nQlLOgweZTAtQ6uzxijnA0aEj7/qRzijewYiLamcviakKahTYAKZQSl6i6S2Gxj20DnL Moo0XLadgqrvp0N5l+GL0RLfphqLVl2yXW9tGvbhcdt+meWl9M2JN5NskhXJeav4xcZC 5uaQ== X-Gm-Message-State: AOAM531MykTNGCX7LkOlHar/1kCbvzu3+8z3aWp1JE7/rHtd8H4buNKJ kFXGOxXxbmNdooltkblK7yPDBA== X-Google-Smtp-Source: ABdhPJwOn+TVghc8Zxb7SvYP0+bKSsV+pl4TagUXNGdkFQEe3TVTEiXDzb5Y0svsD+5a3xOP4wykMQ== X-Received: by 2002:a17:902:e5c8:b029:e4:c22d:4da6 with SMTP id u8-20020a170902e5c8b02900e4c22d4da6mr14523152plf.10.1615566309105; Fri, 12 Mar 2021 08:25:09 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id e8sm5899599pgb.35.2021.03.12.08.25.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 08:25:08 -0800 (PST) From: Mathieu Poirier To: bjorn.andersson@linaro.org, ohad@wizery.com Cc: arnaud.pouliquen@st.com, mcoquelin.stm32@gmail.com, alexandre.torgue@st.com, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v8 12/17] remoteproc: Properly deal with the resource table when stopping Date: Fri, 12 Mar 2021 09:24:48 -0700 Message-Id: <20210312162453.1234145-13-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210312162453.1234145-1-mathieu.poirier@linaro.org> References: <20210312162453.1234145-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org When a remote processor that was attached to is stopped, special care must be taken to make sure the shutdown process is similar to what it would be had it been started by the remoteproc core. This patch takes care of that by making a copy of the resource table currently used by the remote processor. From that point on the copy is used, as if the remote processor had been started by the remoteproc core. Signed-off-by: Mathieu Poirier Reviewed-by: Arnaud Pouliquen Reported-by: kernel test robot --- New for V8: - Removed variable @table_ptr as it served no purpose. --- drivers/remoteproc/remoteproc_core.c | 48 +++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 0f151dbcdc36..37b3b7d494e5 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1634,6 +1634,47 @@ static int rproc_reset_rsc_table_on_detach(struct rproc *rproc) return 0; } +static int rproc_reset_rsc_table_on_stop(struct rproc *rproc) +{ + /* A resource table was never retrieved, nothing to do here */ + if (!rproc->table_ptr) + return 0; + + /* + * If a cache table exists the remote processor was started by + * the remoteproc core. That cache table should be used for + * the rest of the shutdown process. + */ + if (rproc->cached_table) + goto out; + + /* + * If we made it here the remote processor was started by another + * entity and a cache table doesn't exist. As such make a copy of + * the resource table currently used by the remote processor and + * use that for the rest of the shutdown process. The memory + * allocated here is free'd in rproc_shutdown(). + */ + rproc->cached_table = kmemdup(rproc->table_ptr, + rproc->table_sz, GFP_KERNEL); + if (!rproc->cached_table) + return -ENOMEM; + + /* + * Since the remote processor is being switched off the clean table + * won't be needed. Allocated in rproc_set_rsc_table(). + */ + kfree(rproc->clean_table); + +out: + /* + * Use a copy of the resource table for the remainder of the + * shutdown process. + */ + rproc->table_ptr = rproc->cached_table; + return 0; +} + /* * Attach to remote processor - similar to rproc_fw_boot() but without * the steps that deal with the firmware image. @@ -1759,7 +1800,12 @@ static int rproc_stop(struct rproc *rproc, bool crashed) rproc_stop_subdevices(rproc, crashed); /* the installed resource table is no longer accessible */ - rproc->table_ptr = rproc->cached_table; + ret = rproc_reset_rsc_table_on_stop(rproc); + if (ret) { + dev_err(dev, "can't reset resource table: %d\n", ret); + return ret; + } + /* power off the remote processor */ ret = rproc->ops->stop(rproc); From patchwork Fri Mar 12 16:24:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 12135215 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 55733C4360C for ; Fri, 12 Mar 2021 16:26:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2DCD46501D for ; Fri, 12 Mar 2021 16:26:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232781AbhCLQZi (ORCPT ); Fri, 12 Mar 2021 11:25:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232736AbhCLQZL (ORCPT ); Fri, 12 Mar 2021 11:25:11 -0500 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7218C061574 for ; Fri, 12 Mar 2021 08:25:10 -0800 (PST) Received: by mail-pl1-x635.google.com with SMTP id a24so12142651plm.11 for ; Fri, 12 Mar 2021 08:25:10 -0800 (PST) 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=y4yyaBEGVAJuF1cE5I5KagCnyr0kxeqqDbz8hFkGXj4=; b=wCNDAmgVCqt2qIVMTG/QwQDP3qUWhxwn+eKFtTYBxSagINdG3dJtOLkpPvgRxGwavE T0E7P3teqFNvCRACI9e+CDt0fDTXOIiduA7xjT0HCzDTz2gZSR9mlIpPbTUxYLIm0bSW vkqy8RFMSVInXsgKXfrzAgaIIXq5Q725TQ5cqpXHnHxao5LxTY4ePygVKyuYSSVTmlE2 R66Llg+Pf9H0/+/glN2URVQ/31SIcc0M9tQ3Y4gWkCMP8AN0qhTNH3qw7EY4NJv73RpS segUMbKSmCxJDuyKydU4mSfBeV4exNmLS7qYtG55gH+nN94d5Fj3nIZ6XPw+fuejh3YY VgUA== 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=y4yyaBEGVAJuF1cE5I5KagCnyr0kxeqqDbz8hFkGXj4=; b=Ssq0d8a0n2p/ww9Y4/vsRD6psDQkmyR7Ybzj12qOyiPIYsRv2SJNfAuWC1FgSAskuI PXr+xqvFolAku96tYY8F+5zhmRgIAfSH7KRZmbtBIFnwRYgiDnr8MvzriQqdIEkmqhVL sn9FBJiFsvfnXituIZ+Xa8sdUWBUlWJO/jCQHmKEsrtB7S2BdBLcMLuD6Ygy8olJfmKc GGn9VrTO+2qZCmMKmJw9abH6lEvOedO5wJOU+ZnkT4Wu6C5hUb0rRf5RJWmqbPXYm8PV oB6zI4RCGKKR2lbJOvYBU5t4jBLMocOVkAG2nLv+xWMKE8QnR2LA+XfHJJZ7urzyEoDr qCFw== X-Gm-Message-State: AOAM530exwJIuwp9lUtnCG/ShY00LgsvV+duEbXdWCFBL6zP3nOn/n/9 NYRPpaxkB9M6mk5V4do/+Hkhpw== X-Google-Smtp-Source: ABdhPJxNuWURTnTc59nPIWCjU7CDO/E+RwrjkAMSR1hUaTIxUWU+BEPdBm+lexHx4pqNd0tHS82zFg== X-Received: by 2002:a17:903:30cd:b029:e4:93b5:3547 with SMTP id s13-20020a17090330cdb02900e493b53547mr13731867plc.53.1615566310435; Fri, 12 Mar 2021 08:25:10 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id e8sm5899599pgb.35.2021.03.12.08.25.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 08:25:09 -0800 (PST) From: Mathieu Poirier To: bjorn.andersson@linaro.org, ohad@wizery.com Cc: arnaud.pouliquen@st.com, mcoquelin.stm32@gmail.com, alexandre.torgue@st.com, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v8 13/17] remoteproc: Properly deal with a kernel panic when attached Date: Fri, 12 Mar 2021 09:24:49 -0700 Message-Id: <20210312162453.1234145-14-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210312162453.1234145-1-mathieu.poirier@linaro.org> References: <20210312162453.1234145-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org The panic handler operation of registered remote processors should also be called when remote processors have been attached to. Signed-off-by: Mathieu Poirier Reviewed-by: Peng Fan Reviewed-by: Arnaud Pouliquen --- drivers/remoteproc/remoteproc_core.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 37b3b7d494e5..c00f3f8bdfcc 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -2728,7 +2728,11 @@ static int rproc_panic_handler(struct notifier_block *nb, unsigned long event, rcu_read_lock(); list_for_each_entry_rcu(rproc, &rproc_list, node) { - if (!rproc->ops->panic || rproc->state != RPROC_RUNNING) + if (!rproc->ops->panic) + continue; + + if (rproc->state != RPROC_RUNNING && + rproc->state != RPROC_ATTACHED) continue; d = rproc->ops->panic(rproc); From patchwork Fri Mar 12 16:24:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 12135213 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 62B7EC4361A for ; Fri, 12 Mar 2021 16:26:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1311D65046 for ; Fri, 12 Mar 2021 16:26:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232795AbhCLQZi (ORCPT ); Fri, 12 Mar 2021 11:25:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232741AbhCLQZM (ORCPT ); Fri, 12 Mar 2021 11:25:12 -0500 Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD8D2C061574 for ; Fri, 12 Mar 2021 08:25:11 -0800 (PST) Received: by mail-pf1-x42b.google.com with SMTP id 16so2202233pfn.5 for ; Fri, 12 Mar 2021 08:25:11 -0800 (PST) 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=gj6WF/1oKuVocPkZDr0q35lcZZqhgtjB+hq21nBtWDQ=; b=gtz428PBLEgDloxKNuUGPr92ilupj59j2EfFWY0/N6WmAnATRxpQJlW+J2ee8AQHav xfm/Xf2HxlRVeNugLHL+U4NK/rWK5UJwdN7EfSosWKr3Zt4TBkWgoN5gxNkvHYyl37ew wTLuoegWNmHdbT1yapt1sRmrpbJFDYR80XDVQgf9zEXVpRYxrykMcKshqEyybiNI1g/+ jIPrVankCXpF2yQKIzgKc3SRrrvlTrz2bdl5FITvFh/l09kH6c8OChMhbgTMBAroPgIq dRrowcFVCygaFx/jN2st9jMIN6PuKz34cElkxvTGRjMivbDKekwO6IJqP8vq2Scn2hAs yumw== 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=gj6WF/1oKuVocPkZDr0q35lcZZqhgtjB+hq21nBtWDQ=; b=cor3tXSOhE5ENI9bmMUU/JHDqkIk+/QlzuL3U1FFlcgk7maReJBHqPq/T0swOKkHjI hzWulHDDgPsdKWqGEuRzA79rM8Utl0R6sKokEhK5uW1fp1o7ezTeoIvOEQPEuREBU5Sj q1qQKrir9Q72dH6F2LScui3sByalQ7pLkcRnyc9esznddDyQnqh/DOYicSAt9PeQ9HWf 9YyUzqoXhyOaHH56GkYqqvOO9QZ6b4YCsO6yRxlRGIcTZMPgqeX2/dEINOSHvJk133eZ jzOAZFPN4rEG+f2u5Ty2NZRQpXYeTtGCqY3eFDSMsQSwRbDhqyuYlmAkr67l8QYjObEB /rZQ== X-Gm-Message-State: AOAM532T7TNS0IVYjyvtXM9kIbxAlw4UVMq0DCYMPyCjqMU1EoPZrgVu ZiiTiCpT40lzvy+jJbI3IJQNIQ== X-Google-Smtp-Source: ABdhPJxGBgOg4XUMLZgE8bHRgl/Ot16rbp7CVs6Kqzly1An+KF889/k2eE5hVl0egydVPzDpTey4aQ== X-Received: by 2002:a63:135e:: with SMTP id 30mr12705562pgt.6.1615566311426; Fri, 12 Mar 2021 08:25:11 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id e8sm5899599pgb.35.2021.03.12.08.25.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 08:25:11 -0800 (PST) From: Mathieu Poirier To: bjorn.andersson@linaro.org, ohad@wizery.com Cc: arnaud.pouliquen@st.com, mcoquelin.stm32@gmail.com, alexandre.torgue@st.com, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v8 14/17] remoteproc: Properly deal with a start request when attached Date: Fri, 12 Mar 2021 09:24:50 -0700 Message-Id: <20210312162453.1234145-15-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210312162453.1234145-1-mathieu.poirier@linaro.org> References: <20210312162453.1234145-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org This patch takes into account scenarios where a remote processor has been attached to when receiving a "start" command from sysfs. As with the case with the running state, the command can't be carried out if the remote processor is already in operation. Signed-off-by: Mathieu Poirier Reviewed-by: Arnaud Pouliquen --- drivers/remoteproc/remoteproc_cdev.c | 3 ++- drivers/remoteproc/remoteproc_sysfs.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/remoteproc/remoteproc_cdev.c b/drivers/remoteproc/remoteproc_cdev.c index b19ea3057bde..b2cee9afb41b 100644 --- a/drivers/remoteproc/remoteproc_cdev.c +++ b/drivers/remoteproc/remoteproc_cdev.c @@ -32,7 +32,8 @@ static ssize_t rproc_cdev_write(struct file *filp, const char __user *buf, size_ return -EFAULT; if (!strncmp(cmd, "start", len)) { - if (rproc->state == RPROC_RUNNING) + if (rproc->state == RPROC_RUNNING || + rproc->state == RPROC_ATTACHED) return -EBUSY; ret = rproc_boot(rproc); diff --git a/drivers/remoteproc/remoteproc_sysfs.c b/drivers/remoteproc/remoteproc_sysfs.c index f9694def9b54..66801e6fe5cd 100644 --- a/drivers/remoteproc/remoteproc_sysfs.c +++ b/drivers/remoteproc/remoteproc_sysfs.c @@ -194,7 +194,8 @@ static ssize_t state_store(struct device *dev, int ret = 0; if (sysfs_streq(buf, "start")) { - if (rproc->state == RPROC_RUNNING) + if (rproc->state == RPROC_RUNNING || + rproc->state == RPROC_ATTACHED) return -EBUSY; ret = rproc_boot(rproc); From patchwork Fri Mar 12 16:24:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 12135211 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7709BC43603 for ; Fri, 12 Mar 2021 16:26:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4635065053 for ; Fri, 12 Mar 2021 16:26:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232799AbhCLQZj (ORCPT ); Fri, 12 Mar 2021 11:25:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232416AbhCLQZN (ORCPT ); Fri, 12 Mar 2021 11:25:13 -0500 Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB767C061574 for ; Fri, 12 Mar 2021 08:25:12 -0800 (PST) Received: by mail-pg1-x52b.google.com with SMTP id o10so16205135pgg.4 for ; Fri, 12 Mar 2021 08:25:12 -0800 (PST) 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=AZdJoSgIJXSU7DnQv8lIz2Iv+j4owVE3/6SK24bo6uk=; b=d1s1Hv3DdcHyErIEyqH3yVFpG5V3lO/hah7vzMM+o/RrmOi1nUUVJJOFQid7jaOFqu /Rczir59gxWk9v85psOknIOLGxz5eS7nnm7Ep6hKbqUDlwv6X4I03OwKAVgFjsUxH1HM BNLWxdZW38ZWyLki1U9PPsl0jwcvcalk0qqzsTPkbFM2aGqBnPn5hQNsZ8qC0VrReK9i 2GjsDzxSpOm0tQslrAm1L0BkD4b70za/K1TPwEkOLFIonRExzcK3V+kk+GRt1dRbyTV6 x1dovn6BBe6Dh/sU0KgszeIAzVaPQhtOf5oNCiKqXC99VHyUbYqyTNQWk/HfJVfs/mMD mgQA== 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=AZdJoSgIJXSU7DnQv8lIz2Iv+j4owVE3/6SK24bo6uk=; b=XfYE5yNEwjNioH0h0cvMNsAMoi6rCezhT2maRpgJRHxTdHgugT6cvADgeLeFQ2eLz+ A8TVilJbUEROC5ME6QvIpSrNiC+SesRP7BUXd7CQhUGrVVWsIiSS5w38lM+5Nt6MyBO0 YQ6WBtdSMmvv+xOrK8kT6TSTu5GkGLp39IkN6rF5FdzVEcM31MQYkTfa0/vEGfvymmuc UkstBRLxp6+m+pJwmCNnZj2BANyv/YXu0A+LiJqlqX+k5gaJsYqZtVMLt6Hi2tNvX4gJ R9LD6MB5IMmYSMWOQHy+HVL1T7PxAWb9bu9p2tDzH/kzB8CHJczcB+6rtxum3oxuDBLD jIqg== X-Gm-Message-State: AOAM530GvC+FmjH+k/AsGLo4xc5GZN+kZwFpB4+kEkAmmgUBlM3gn4S7 kaL34rK9R1Gsv0EzNgwJHRJItg== X-Google-Smtp-Source: ABdhPJxlMqe1nJc8niT81bokl2i7FzDOOm3XanPm1WN7Go5cCc4RR+0tUjxJNLyH76LMmwJwrNFCvw== X-Received: by 2002:a63:d0f:: with SMTP id c15mr12221198pgl.367.1615566312454; Fri, 12 Mar 2021 08:25:12 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id e8sm5899599pgb.35.2021.03.12.08.25.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 08:25:12 -0800 (PST) From: Mathieu Poirier To: bjorn.andersson@linaro.org, ohad@wizery.com Cc: arnaud.pouliquen@st.com, mcoquelin.stm32@gmail.com, alexandre.torgue@st.com, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v8 15/17] remoteproc: Properly deal with a stop request when attached Date: Fri, 12 Mar 2021 09:24:51 -0700 Message-Id: <20210312162453.1234145-16-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210312162453.1234145-1-mathieu.poirier@linaro.org> References: <20210312162453.1234145-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org Allow a remote processor that was started by another entity to be switched off by the remoteproc core. For that to happen a rproc::ops::stop() operation needs to be available. Signed-off-by: Mathieu Poirier Reviewed-by: Arnaud Pouliquen --- drivers/remoteproc/remoteproc_cdev.c | 3 ++- drivers/remoteproc/remoteproc_core.c | 4 ++++ drivers/remoteproc/remoteproc_sysfs.c | 3 ++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/remoteproc/remoteproc_cdev.c b/drivers/remoteproc/remoteproc_cdev.c index b2cee9afb41b..0249d8f6c3f8 100644 --- a/drivers/remoteproc/remoteproc_cdev.c +++ b/drivers/remoteproc/remoteproc_cdev.c @@ -38,7 +38,8 @@ static ssize_t rproc_cdev_write(struct file *filp, const char __user *buf, size_ ret = rproc_boot(rproc); } else if (!strncmp(cmd, "stop", len)) { - if (rproc->state != RPROC_RUNNING) + if (rproc->state != RPROC_RUNNING && + rproc->state != RPROC_ATTACHED) return -EINVAL; rproc_shutdown(rproc); diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index c00f3f8bdfcc..c985c5f6f2f8 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1796,6 +1796,10 @@ static int rproc_stop(struct rproc *rproc, bool crashed) struct device *dev = &rproc->dev; int ret; + /* No need to continue if a stop() operation has not been provided */ + if (!rproc->ops->stop) + return -EINVAL; + /* Stop any subdevices for the remote processor */ rproc_stop_subdevices(rproc, crashed); diff --git a/drivers/remoteproc/remoteproc_sysfs.c b/drivers/remoteproc/remoteproc_sysfs.c index 66801e6fe5cd..09eb700c5e7e 100644 --- a/drivers/remoteproc/remoteproc_sysfs.c +++ b/drivers/remoteproc/remoteproc_sysfs.c @@ -202,7 +202,8 @@ static ssize_t state_store(struct device *dev, if (ret) dev_err(&rproc->dev, "Boot failed: %d\n", ret); } else if (sysfs_streq(buf, "stop")) { - if (rproc->state != RPROC_RUNNING) + if (rproc->state != RPROC_RUNNING && + rproc->state != RPROC_ATTACHED) return -EINVAL; rproc_shutdown(rproc); From patchwork Fri Mar 12 16:24:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 12135207 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 651D0C433DB for ; Fri, 12 Mar 2021 16:26:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 34DC66501D for ; Fri, 12 Mar 2021 16:26:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231849AbhCLQZj (ORCPT ); Fri, 12 Mar 2021 11:25:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232757AbhCLQZP (ORCPT ); Fri, 12 Mar 2021 11:25:15 -0500 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C0C04C061762 for ; Fri, 12 Mar 2021 08:25:13 -0800 (PST) Received: by mail-pf1-x433.google.com with SMTP id y67so2208543pfb.2 for ; Fri, 12 Mar 2021 08:25:13 -0800 (PST) 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=NN7h66rSqKzczqrKUwACdy1DE0E9dT7gEJY334oVOV4=; b=DoxVu73kjDBB6G+GqFJuZWjDsELYStjGVY6plUBqlVW8SEESXd4UJfYhxlcENxplnE 1xJ85jHSD+DESiciZ/whQ0v9aVsTsCxif+CUVhw+6qZFG+jZR077sQ2MC6+yzs8jYm31 ceCUx/8XDTX9SftcjKYiPXuiIVKRII7oLCTjseZm5RvRVH4ZjhMNt8pl4Jox7SvI5Szv VZl1Qd3JBAMUkeeVCDFmYTofk0/nZ9zoYFwvlg2AxNilu/b0S5DrSjpUHHDxYYL9SRO8 ACKowoV+UgnPTI3nFETwbDA6ejSXNodP39T2sI31UwvblMk4PXFPZdssJYX+pYx8/oAg t7MA== 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=NN7h66rSqKzczqrKUwACdy1DE0E9dT7gEJY334oVOV4=; b=orDtCwPzreiKR0eXtN4OQJIdDgaO7ZmRAwMWWyZwWb8LimVdgkfR2/d8kyInLUWtSM jdv5QzAa9j7iYnfPN1NKqDtG8CDZRYsB1zYRYTqn5GuBtlzy1g6kTcT/JPPK+I63QFgJ 5hC9vSEMY2Mr+yelmcgc74I5yKqPUU/Ymlhf4qrU7ifjihgH0UQPVMwPhRZ6deL2v3xZ L2ci1R5diPAGPTeSs/5bVtMatLdxJY+o0xM39RZavz6DWp5bNxq574KOqBZifCEWGy/B PNFUy5SS27tgEobz6UhXfEYEOPKCThzVvmV6cIwLbKppnx0ZKe6nX8RO7cgmFIBPh/zF uUdw== X-Gm-Message-State: AOAM532OKtsP166gQMF4VmO2LRqZNEsubhGrQ7iJ50JOCtVquzEFjwH+ bQdpSDJEnOdyivrx7FcQFSIZqg== X-Google-Smtp-Source: ABdhPJzPJ7a7B2gKd7mX/cHBrA1bcydfqcm9yX2BF56Hal2O0TDosxxZI3SuKPX6uNk5f41tojh1pQ== X-Received: by 2002:a63:db57:: with SMTP id x23mr12394765pgi.432.1615566313341; Fri, 12 Mar 2021 08:25:13 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id e8sm5899599pgb.35.2021.03.12.08.25.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 08:25:13 -0800 (PST) From: Mathieu Poirier To: bjorn.andersson@linaro.org, ohad@wizery.com Cc: arnaud.pouliquen@st.com, mcoquelin.stm32@gmail.com, alexandre.torgue@st.com, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v8 16/17] remoteproc: Properly deal with a detach request when attached Date: Fri, 12 Mar 2021 09:24:52 -0700 Message-Id: <20210312162453.1234145-17-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210312162453.1234145-1-mathieu.poirier@linaro.org> References: <20210312162453.1234145-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org This patch introduces the capability to detach a remote processor that has been attached to by the remoteproc core. For that to happen a rproc::ops::detach() operation needs to be available. Signed-off-by: Mathieu Poirier Reviewed-by: Arnaud Pouliquen --- drivers/remoteproc/remoteproc_cdev.c | 5 +++++ drivers/remoteproc/remoteproc_sysfs.c | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/drivers/remoteproc/remoteproc_cdev.c b/drivers/remoteproc/remoteproc_cdev.c index 0249d8f6c3f8..2db494816d5f 100644 --- a/drivers/remoteproc/remoteproc_cdev.c +++ b/drivers/remoteproc/remoteproc_cdev.c @@ -43,6 +43,11 @@ static ssize_t rproc_cdev_write(struct file *filp, const char __user *buf, size_ return -EINVAL; rproc_shutdown(rproc); + } else if (!strncmp(cmd, "detach", len)) { + if (rproc->state != RPROC_ATTACHED) + return -EINVAL; + + ret = rproc_detach(rproc); } else { dev_err(&rproc->dev, "Unrecognized option\n"); ret = -EINVAL; diff --git a/drivers/remoteproc/remoteproc_sysfs.c b/drivers/remoteproc/remoteproc_sysfs.c index 09eb700c5e7e..ad3dd208024c 100644 --- a/drivers/remoteproc/remoteproc_sysfs.c +++ b/drivers/remoteproc/remoteproc_sysfs.c @@ -207,6 +207,11 @@ static ssize_t state_store(struct device *dev, return -EINVAL; rproc_shutdown(rproc); + } else if (sysfs_streq(buf, "detach")) { + if (rproc->state != RPROC_ATTACHED) + return -EINVAL; + + ret = rproc_detach(rproc); } else { dev_err(&rproc->dev, "Unrecognised option: %s\n", buf); ret = -EINVAL; From patchwork Fri Mar 12 16:24:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 12135217 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 73638C433E0 for ; Fri, 12 Mar 2021 16:26:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 451DB6502F for ; Fri, 12 Mar 2021 16:26:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232814AbhCLQZj (ORCPT ); Fri, 12 Mar 2021 11:25:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232764AbhCLQZP (ORCPT ); Fri, 12 Mar 2021 11:25:15 -0500 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 591C5C061574 for ; Fri, 12 Mar 2021 08:25:15 -0800 (PST) Received: by mail-pj1-x1031.google.com with SMTP id gb6so5389074pjb.0 for ; Fri, 12 Mar 2021 08:25:14 -0800 (PST) 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=iXhTHlq228l+0iB04Y1r45kd4DhCxMw3571PP4zILAA=; b=VEmmh5X9fa7g3DiKuaT8KWl1POaMjOAm+T7VEA/s9HtE3LAT5keAH5jFQKyhSL/xMS 9uJBXewfM5+b2Q2pTgzWrVmV+u5Zklkra+XF6ZoMjwzwl3nDrYS25Sca4ZwK34BjwuaT fKdOhGmGki2L5vZnbr5jVEN6XKD47xT2oYXdqvo0L1b8XCgR1uYJZdPlUcn/aXTAgURg I89r80V6WlTTOdGZi7HbkMFBU4jDHk1ojvazPOfgEmHUj9IT73xhKzFO6Wf7Ptw2JyoU U0VILhPzwdvcAg87OIl0CFSYeewaobSPcU6c2uZ3UFeD0/cPDtw51Z4qZKVRZebEgqPA pFWg== 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=iXhTHlq228l+0iB04Y1r45kd4DhCxMw3571PP4zILAA=; b=A511l/T5zaiRL80uX46hDc4OLnJKJ4kV1BrPVzj396SUNQ+eDaohPP7RfBcemNzU1p 8U6M9KzI26ImaYbWKT+8maXThMs6RZW7fHHbcMANCfqZ46y/3cSejAhDuK2QQp3zJIpF +yc+afef5UAq2omsBf6us4trMFK11kEvbTY9621LKtq4wfqmJKDfiIKKOQ4uBKHmVtMf BDXU0c4OXCYoeNoySxyzzsHfQ6iHARurFdqsdDFGjAVt/GbM9z8faAAzOLUdEUPXGP5+ k1Hj0tBiBHjfZkYwRDuhXlSI5AfT06hZTA2y0ssrU0EEW5zN3TLfOT7/wpXatVszs6XR RcUw== X-Gm-Message-State: AOAM532LQ1fnlkEdiyF03RA38ZF7OPZXrMwyFMqN+MUUi/CPE/OcoHFR Xbe2erC/9GlKnEYlP1J/I6ENnQ== X-Google-Smtp-Source: ABdhPJy+d0zi50bylh7i8kcjhGz8ezrVQ0JqGrqHc3fNPEHAakRBEC7HmvAmHSP7MeuNaCrxFhnHAg== X-Received: by 2002:a17:90a:a618:: with SMTP id c24mr15091131pjq.108.1615566314572; Fri, 12 Mar 2021 08:25:14 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id e8sm5899599pgb.35.2021.03.12.08.25.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 08:25:14 -0800 (PST) From: Mathieu Poirier To: bjorn.andersson@linaro.org, ohad@wizery.com Cc: arnaud.pouliquen@st.com, mcoquelin.stm32@gmail.com, alexandre.torgue@st.com, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v8 17/17] remoteproc: Refactor function rproc_cdev_release() Date: Fri, 12 Mar 2021 09:24:53 -0700 Message-Id: <20210312162453.1234145-18-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210312162453.1234145-1-mathieu.poirier@linaro.org> References: <20210312162453.1234145-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org Refactor function rproc_cdev_release() to take into account the current state of the remote processor when choosing the state to transition to. Signed-off-by: Mathieu Poirier --- drivers/remoteproc/remoteproc_cdev.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/remoteproc/remoteproc_cdev.c b/drivers/remoteproc/remoteproc_cdev.c index 2db494816d5f..0b8a84c04f76 100644 --- a/drivers/remoteproc/remoteproc_cdev.c +++ b/drivers/remoteproc/remoteproc_cdev.c @@ -86,11 +86,17 @@ static long rproc_device_ioctl(struct file *filp, unsigned int ioctl, unsigned l static int rproc_cdev_release(struct inode *inode, struct file *filp) { struct rproc *rproc = container_of(inode->i_cdev, struct rproc, cdev); + int ret = 0; + + if (!rproc->cdev_put_on_release) + return 0; - if (rproc->cdev_put_on_release && rproc->state == RPROC_RUNNING) + if (rproc->state == RPROC_RUNNING) rproc_shutdown(rproc); + else if (rproc->state == RPROC_ATTACHED) + ret = rproc_detach(rproc); - return 0; + return ret; } static const struct file_operations rproc_fops = {