From patchwork Fri Dec 18 17:32:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11982563 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=unavailable 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 D554DC4361B for ; Fri, 18 Dec 2020 17:33:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7A8FF23AC9 for ; Fri, 18 Dec 2020 17:33:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727967AbgLRRdc (ORCPT ); Fri, 18 Dec 2020 12:33:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732216AbgLRRdc (ORCPT ); Fri, 18 Dec 2020 12:33:32 -0500 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06C8AC061248 for ; Fri, 18 Dec 2020 09:32:32 -0800 (PST) Received: by mail-pl1-x632.google.com with SMTP id b8so1775125plx.0 for ; Fri, 18 Dec 2020 09:32:32 -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=gRhRZVtQaTMtklLhGYfbei+QaPodzo2py0ncJTxvT/s=; b=tNpsREt+XbPPv5QuoOhm9OqsITxalLxxOZfgF8GTLq+WJ8iOk5xzuavWPKfg58ioVE vBnZIyX/ncnJ2y40CyDTmSENMfPGcJewYu8oc3kJ5gXDZkQ35Pan0ThRHaPR4j8bNOFr dTa2k+0iXIbnE8vX66p/PMHDMBGHZkIVXf63lWQg4QHZsaFAbrdfmUqSzPgzV3SkxCiN cW227HbMVgiQ4M8uIXZeAKla3krZ6TzWemIzYMDGTUV1n5M6UZwJ8ZU3XQmivnqsNLFA EXNaCAd9JvVPPXBHFKQ7X9WuYH5XIhAaGzy5Z0igOM8Fo4zLsHKrqv0pq7vRF5UwrOUn I7lg== 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=gRhRZVtQaTMtklLhGYfbei+QaPodzo2py0ncJTxvT/s=; b=MnyFvvAQXoBq5PAHF9AnXdVpCTiyorpJ2F/y4//+nnjlLJOSOkVwf8DhdBIH9utEYz 5RyejHx/fXTF5tplI9672U5/Bs1cymzbv3yklyl6IaaCwLgRXLiXJXa5GFx4sm5OxlWU 2ZeKoozdI+55UzCxCdkwctctUo55T8NjXUxuCt93tsZVj4pmG6dxA/oMPxeKyTPpA4Pz zek7SxYtOWj09mT5rrR5ECwrzHl5EQOev9YjpccCFfgpTdIw6Lyo4XZzLrsy+WuyDwy3 ouM8P+mnw/c5G85EDlO49B53x44xcyqLGwMYAdKour73a0ClNc6m9C8eOTQPBHCzC508 XFkg== X-Gm-Message-State: AOAM53263gDeffx9rxKUZD83dVQwuTaqCSEwPdX7IXa9ZliZIQmyaVq0 xp8rK0+2Zyr878kpShvM18ENxQ== X-Google-Smtp-Source: ABdhPJyG/NZO9JMMo4KBjMYKSaNOPJm7mR6yfpLRHFGp5pZbF3G299VUhTFYpP1iX5qT8HulTiUHVA== X-Received: by 2002:a17:902:ed0d:b029:da:c83b:5f40 with SMTP id b13-20020a170902ed0db02900dac83b5f40mr5444448pld.20.1608312751595; Fri, 18 Dec 2020 09:32:31 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id l11sm9892957pgt.79.2020.12.18.09.32.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Dec 2020 09:32:30 -0800 (PST) From: Mathieu Poirier To: ohad@wizery.com, bjorn.andersson@linaro.org, robh+dt@kernel.org Cc: arnaud.pouliquen@st.com, linux-remoteproc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 01/17] dt-bindings: remoteproc: Add bindind to support autonomous processors Date: Fri, 18 Dec 2020 10:32:12 -0700 Message-Id: <20201218173228.2277032-2-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201218173228.2277032-1-mathieu.poirier@linaro.org> References: <20201218173228.2277032-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org This patch adds a binding to guide the remoteproc core on how to deal with remote processors in two cases: 1) When an application holding a reference to a remote processor character device interface crashes. 2) when the platform driver for a remote processor is removed. In both cases if "autonomous-on-core-reboot" is specified in the remote processor DT node, the remoteproc core will detach the remote processor rather than switching it off. Signed-off-by: Mathieu Poirier Reviewed-by: Rob Herring --- .../bindings/remoteproc/remoteproc-core.yaml | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Documentation/devicetree/bindings/remoteproc/remoteproc-core.yaml diff --git a/Documentation/devicetree/bindings/remoteproc/remoteproc-core.yaml b/Documentation/devicetree/bindings/remoteproc/remoteproc-core.yaml new file mode 100644 index 000000000000..e8bb8ef9031a --- /dev/null +++ b/Documentation/devicetree/bindings/remoteproc/remoteproc-core.yaml @@ -0,0 +1,27 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/remoteproc/remoteproc-core.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Binding(s) for a primary processor applicable to all ancillary + processors + +maintainers: + - Bjorn Andersson + - Mathieu Poirier + +description: + This document defines the bindings used by a primary processor to determine + the state it should leave an ancillary processor when the former is no longer + functioning. + +properties: + autonomous-on-core-reboot: + $ref: /schemas/types.yaml#/definitions/flag + description: + When specified the ancillary processor should be left operational when + the primary processor is no longer available. Otherwise the ancillary + processor should be made inoperative. + +additionalProperties: true From patchwork Fri Dec 18 17:32:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11982567 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 1B22FC2D0E4 for ; Fri, 18 Dec 2020 17:34:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D368023B70 for ; Fri, 18 Dec 2020 17:34:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732526AbgLRRdw (ORCPT ); Fri, 18 Dec 2020 12:33:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732354AbgLRRdv (ORCPT ); Fri, 18 Dec 2020 12:33:51 -0500 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C707C0611CB for ; Fri, 18 Dec 2020 09:32:33 -0800 (PST) Received: by mail-pj1-x1032.google.com with SMTP id m5so1701012pjv.5 for ; Fri, 18 Dec 2020 09:32:33 -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=quv8FgGcrBfpjdUziX+s2dGLHCpcEJuuhEHyCnt0I9w=; b=hWjlKc/uj59tXupMihyRyk6/qf5jTxj733rtsaPMHcWwyas3HRGdNDFySCMQMFDsLw MsQlakPxeBYW7HiRi3L/5gQsrLigaJK2SrUEYK4IGL4m/B1h6Qm7zzO/+R+qU/dxUeAc Z3VHqNIuAwma/8vga8q8ugF0ZpNAe3i4KndKnvjUzkaMxntPyLVi4459FM8BfHpdtIT2 siJkUbRIB3rg+D0KZXSsl83hf6P7FheSxhm20Ku6OHJnK5lO7gXl8IvKhhroO3XgiRMb 7yMbAakrbxAtg16bQf1fPw8aGoMA1qfQACManxDa4k9GVQxH7fNUaf1pGaBM7CksN04V n4ww== 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=quv8FgGcrBfpjdUziX+s2dGLHCpcEJuuhEHyCnt0I9w=; b=Kj7UO61TBtQcgxhplJNcKI3VR0H7hEIdaUnLt/oZaZ+4gjaNB6Up+eDcvHKw2qoKPb M4AQHyYOmBaHtP9zTc4nj/sB+P5OLBR+bkGuq86q6stV69ss5QBZl6fSqgTLBePc43/f DlrTbOaXHIYohIfgY1lUzVKv3zgWOLYVN2xWRotRIRaDAI4Ek5tW7Qtv6yBGGBeQvG+0 HxNkaBWne1KgLgV/wmM0C9p1kSbjyD+PcMwZiNhmy59NcsSaWNLxAjts5huwRZvoZtRS 65JLQsWA7VsripMjoysAa36EM55sNCn5pv3HKKnUxgxjhYHhNF+dSFBMDZgiG7XmIQcu yozw== X-Gm-Message-State: AOAM531kJxqGRcybi6NCMqWxjiOv76B9PxfxGKbZDfPiysPXRc6+bcP5 Q97Wu3FKCCxM0MgiI8dH3EqjEg== X-Google-Smtp-Source: ABdhPJwwNMzDaIJIDF40wcMocYDBjmZOfxV05QpIIQlCrh5xcj/fjQRwf5R9KrSWZAqtrnxHvxp6bw== X-Received: by 2002:a17:90a:c8d:: with SMTP id v13mr5283889pja.75.1608312752706; Fri, 18 Dec 2020 09:32:32 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id l11sm9892957pgt.79.2020.12.18.09.32.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Dec 2020 09:32:32 -0800 (PST) From: Mathieu Poirier To: ohad@wizery.com, bjorn.andersson@linaro.org, robh+dt@kernel.org Cc: arnaud.pouliquen@st.com, linux-remoteproc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 02/17] remoteproc: Re-check state in rproc_shutdown() Date: Fri, 18 Dec 2020 10:32:13 -0700 Message-Id: <20201218173228.2277032-3-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201218173228.2277032-1-mathieu.poirier@linaro.org> References: <20201218173228.2277032-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org The state of the remote processor may have changed between the time a call to rproc_shutdown() was made and the time it is executed. To avoid moving forward with an operation that may have been cancelled, recheck while holding the mutex. Cc: Signed-off-by: Mathieu Poirier Reviewed-by: Peng Fan Reviewed-by: Arnaud Pouliquen --- drivers/remoteproc/remoteproc_core.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index dab2c0f5caf0..e55568d1e7e2 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1857,6 +1857,9 @@ void rproc_shutdown(struct rproc *rproc) return; } + if (rproc->state != RPROC_RUNNING) + goto out; + /* if the remote proc is still needed, bail out */ if (!atomic_dec_and_test(&rproc->power)) goto out; From patchwork Fri Dec 18 17:32:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11982593 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=unavailable 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 2A55AC4361B for ; Fri, 18 Dec 2020 17:35:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E494123B6B for ; Fri, 18 Dec 2020 17:35:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732498AbgLRRdw (ORCPT ); Fri, 18 Dec 2020 12:33:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732480AbgLRRdv (ORCPT ); Fri, 18 Dec 2020 12:33:51 -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 3320EC0611CE for ; Fri, 18 Dec 2020 09:32:34 -0800 (PST) Received: by mail-pl1-x635.google.com with SMTP id b8so1775192plx.0 for ; Fri, 18 Dec 2020 09:32:34 -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=Dhrgj6KlTsZx4Q0NhpQquJvgjz/fkM6eRvngZm9P8MI=; b=CCTWyUnzE1ZanX60E/iLMHT0I8ZKWfPXwPWUJWfADUGe1anX5MYdsbtqq9PzKYM9/j n7OFo3P1s+0nskqFjWV2eOnXUxh+q3oIlb7YjcMN9vV5TS0FghgN1ctFHNf7Rs5OaNz0 a8foVoXrny67rmJYDx25RebAwa6Lrn/essn4udioOyBENIujDvSTMTEVSTk8Qvua6HIX F6eS1tPhvPc0tLr2Gt4TMUD4Gxhq6n9EZAt+jGOgvH+PUKd8fKp4GcO0SWVYVXMomcsO 94YO06VeiG0HGk4RyldO1QnAYqBw1oQ3vmmw06P0vDdLEFM5eh910MItWLsNhZOUaYT8 Lc9g== 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=Dhrgj6KlTsZx4Q0NhpQquJvgjz/fkM6eRvngZm9P8MI=; b=mlcioh9LDG8sjUDq/wRnuZ1yGITyJib1pASMhUez/Nwija7ogG3cyNQDh2++StV/C0 /SDF+B3Fwsb35yt4gHdxMeFWLqrunZHXXKvHlnBF8N59LyDMEUUif7I773ir+OmMLbSE KC7x+rCqc0FFhEa05N3I0g9/9O8J7iS9LbvsZzOB+EBVrM8/NAzRIHAQRJcxzVYGJToU meZqIAP0ACzvje2ZmDLU/VJFIhDYm0fXV0X6se2R3i2SpZRukuIr1vrnVn9QpeegeQEY fzVnc7W3vx2ief3LsU37ElRllFVaGv6gGw2zwoTbEdQGALqyjtqRWe1aoVHIRi2ozgB7 qPeQ== X-Gm-Message-State: AOAM53335LLKWW38Llb2vpSPy4Q8YCLvpIrH7R81nmGnsw15IayXsf5r uK3zFRGrZi1czWbgQbw0HNl8mwwxtUBWzlAC X-Google-Smtp-Source: ABdhPJz1O4ARyo97p4ERGZ8tIxm75Mh6Rpq8eLB1mpohO9enHdudp/vj45e4rQqTrMfnfxHaw63xAQ== X-Received: by 2002:a17:902:e9c5:b029:db:d1ae:46ba with SMTP id 5-20020a170902e9c5b02900dbd1ae46bamr5424989plk.38.1608312753708; Fri, 18 Dec 2020 09:32:33 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id l11sm9892957pgt.79.2020.12.18.09.32.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Dec 2020 09:32:33 -0800 (PST) From: Mathieu Poirier To: ohad@wizery.com, bjorn.andersson@linaro.org, robh+dt@kernel.org Cc: arnaud.pouliquen@st.com, linux-remoteproc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 03/17] remoteproc: Remove useless check in rproc_del() Date: Fri, 18 Dec 2020 10:32:14 -0700 Message-Id: <20201218173228.2277032-4-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201218173228.2277032-1-mathieu.poirier@linaro.org> References: <20201218173228.2277032-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 shutdown 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 e55568d1e7e2..f36786b47a4f 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -2283,10 +2283,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 Dec 18 17:32:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11982565 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 00592C4361B for ; Fri, 18 Dec 2020 17:34:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B8F1323B6B for ; Fri, 18 Dec 2020 17:34:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731339AbgLRRds (ORCPT ); Fri, 18 Dec 2020 12:33:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727945AbgLRRdr (ORCPT ); Fri, 18 Dec 2020 12:33:47 -0500 Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A651C0611E4 for ; Fri, 18 Dec 2020 09:32:35 -0800 (PST) Received: by mail-pg1-x535.google.com with SMTP id g18so1759115pgk.1 for ; Fri, 18 Dec 2020 09:32:35 -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=txg4LgzTONgLC7bOinTZzbCI37JS2siLcSWFwbF15Qk=; b=FT1wjtnmHCPECVPEQOVxWLN5IehXSRiI66FrjheH51idu4RnVyVuXK++01jSwEYClT KZcFQ0KFJhcsVGfoIH42EnumgM9kl6NEwU9q1v901FR335NFKd/uI3zQqmhFcU52+ZnU UrBN9FzQambsdleQEA8D+rYpufRq4QHqAZbw3u2I8hS4Ef79mMz71XebEFznG6UxpIN2 EKW/X23xQvlKzToX003uherA1MKSw08scJZVf8NMCxj1EVa/iXVQZ7+M7FUbWOoBQx5V bNimp0NbeQwOPco7XjifzHPkmZTafaMiWHnat4Mjv2WN1m2Z993yQZMHJGR4wx/4klCI C8QQ== 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=txg4LgzTONgLC7bOinTZzbCI37JS2siLcSWFwbF15Qk=; b=ISuwBaPuMOYaVbHfMZFGRDAIh24RhlNA7WvSorUhB86siUIedc9abUNxPkKTVwzMtv 4ocw6OMK20FV/EIDslv10oB6STV4rDN0HhA9u/eHoWYdrL/4fSMSDBKsGGLr3JiSeW9T xqOhEs+NdAQ2fpl2WxEc5gpjUkRwJlBSJoSbhWrG/bVUov5QFJAPA4I8yH4WnYs6KHkK i4H5m0gZuwySucIY9s7uBtLzzINkTh0HAVcpmULjELoVdqJa52CJ4txSemPgNCss4XM8 ownO9U9l4bR1687YJlMLQCOmp0GRfTVtUhB3v4JP9963+U26Wvzi+UuOckX6S0vJRSce gctg== X-Gm-Message-State: AOAM530XwbWvGuZI5lxGSN9caKTVH73A0Q1vGR1CrsD6YYaZiR0bDntC jMtRKCsouiwAvQpXER8XCFADwA== X-Google-Smtp-Source: ABdhPJxpl9rldBP7FevfT9lA0VGRaw7OCOci0QW9tFHtQzy20O1eC9TD5qAuoEvJvgQ74t1TCRI1AA== X-Received: by 2002:a63:2060:: with SMTP id r32mr5077740pgm.129.1608312754801; Fri, 18 Dec 2020 09:32:34 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id l11sm9892957pgt.79.2020.12.18.09.32.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Dec 2020 09:32:34 -0800 (PST) From: Mathieu Poirier To: ohad@wizery.com, bjorn.andersson@linaro.org, robh+dt@kernel.org Cc: arnaud.pouliquen@st.com, linux-remoteproc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 04/17] remoteproc: Rename function rproc_actuate() Date: Fri, 18 Dec 2020 10:32:15 -0700 Message-Id: <20201218173228.2277032-5-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201218173228.2277032-1-mathieu.poirier@linaro.org> References: <20201218173228.2277032-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 f36786b47a4f..d0f6b39b56f9 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 Dec 18 17:32:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11982573 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=unavailable 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 8CAE6C352A2 for ; Fri, 18 Dec 2020 17:34:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 50A7923B6B for ; Fri, 18 Dec 2020 17:34:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732761AbgLRReN (ORCPT ); Fri, 18 Dec 2020 12:34:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732752AbgLRReM (ORCPT ); Fri, 18 Dec 2020 12:34:12 -0500 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 682E2C0619D4 for ; Fri, 18 Dec 2020 09:32:36 -0800 (PST) Received: by mail-pj1-x1035.google.com with SMTP id b5so1717788pjl.0 for ; Fri, 18 Dec 2020 09:32:36 -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=veV/gWfMA9I6EK7puOMUDziv6Q4utmhzFu5s8pwfL6Y=; b=IsLC2tdb+Pf1zJzmBqdfU+7Lt9+J5U7obCdktnUBK+t6z1PscQocz5RbK7ptqQeZjh 69aoGazTQg7QNqyHvMLxy/ABKuxk9AgbBGPQNYMDymkMmlRzPg86LNJ1joQmNVaCdlgP g3w1obCYUxvM5RqGHIxQQMzCWI9CVpB4UvfmRhn1kpc+pRnEsU7xDo7EdhO4SPqhHle4 0hC5qeLZLQmoHqsR62Tjt1n6rFzv+0jyB/+ktGqldWh9wVVroMVkhLW6czNqzNSHOLXe W/4g2TJNzrN1P3SHIqN2FpEvfDWRqDJPIgIdT/bmTzzAeFqeuwhhze8+kFm6yPTSCDDR a8xg== 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=veV/gWfMA9I6EK7puOMUDziv6Q4utmhzFu5s8pwfL6Y=; b=e4vGTkQDoPRZ9S6ECseYpMdR7eUELFoJKkgQiufywBYMNm2F0Hal7+ftmbIdYSXjGV Ho6hJLOcYpiVoDsNt4jZdbafR2DxJXYJaEnqMe3+HMr3KyIZovosWUYbDYggDEw7h1/+ lqWrjWwZ4T9PxmyzUTdP7sDW8v/mnxr2BN2YOyTMpIMVdW2l62MI2kXwpUhm6Yiyo4CW CBHXRzx4xGrHbzknG4k5wzyQdP32r8aNNTr7TIuG6A6xAnlqktwQ6DS9stXh1+4krRqg VnlXJkua1Gz8bk9hu60aHDN+oDqjHkq62hZcFEKTN9YLTa+LgF0mJYygzeoSsg06jpfD eUEQ== X-Gm-Message-State: AOAM532jdeFebVIscLwm0IiQ4yGUOylCDqU3azqB/8tLYF+I3Bg8qYUn OSET5hSW2n0sEysqNUv7XlXZyQ== X-Google-Smtp-Source: ABdhPJzHmw4O0E81CRBdka7o0ha8Z0dVqrVsPj5ehQXfwhJdIdMg9OLEWdMOvxuxH3LsQllACxmV0Q== X-Received: by 2002:a17:90b:1249:: with SMTP id gx9mr5207245pjb.169.1608312755974; Fri, 18 Dec 2020 09:32:35 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id l11sm9892957pgt.79.2020.12.18.09.32.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Dec 2020 09:32:35 -0800 (PST) From: Mathieu Poirier To: ohad@wizery.com, bjorn.andersson@linaro.org, robh+dt@kernel.org Cc: arnaud.pouliquen@st.com, linux-remoteproc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 05/17] remoteproc: Add new get_loaded_rsc_table() remoteproc operation Date: Fri, 18 Dec 2020 10:32:16 -0700 Message-Id: <20201218173228.2277032-6-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201218173228.2277032-1-mathieu.poirier@linaro.org> References: <20201218173228.2277032-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org Add an 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 --- drivers/remoteproc/remoteproc_core.c | 6 ++++++ drivers/remoteproc/remoteproc_internal.h | 8 ++++++++ include/linux/remoteproc.h | 5 ++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index d0f6b39b56f9..3d87c910aca7 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1556,6 +1556,12 @@ static int rproc_attach(struct rproc *rproc) return ret; } + ret = rproc_get_loaded_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..c48b301d6ad1 100644 --- a/drivers/remoteproc/remoteproc_internal.h +++ b/drivers/remoteproc/remoteproc_internal.h @@ -177,6 +177,14 @@ struct resource_table *rproc_find_loaded_rsc_table(struct rproc *rproc, return NULL; } +static inline int rproc_get_loaded_rsc_table(struct rproc *rproc) +{ + if (rproc->ops->get_loaded_rsc_table) + return rproc->ops->get_loaded_rsc_table(rproc); + + return 0; +} + static inline bool rproc_u64_fit_in_size_t(u64 val) { diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h index 3fa3ba6498e8..571615e77e6f 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 @@ -389,6 +391,7 @@ struct rproc_ops { int offset, int avail); struct resource_table *(*find_loaded_rsc_table)( struct rproc *rproc, const struct firmware *fw); + int (*get_loaded_rsc_table)(struct rproc *rproc); 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 Dec 18 17:32:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11982595 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=unavailable 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 528B6C3526B for ; Fri, 18 Dec 2020 17:35:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2036C23B70 for ; Fri, 18 Dec 2020 17:35:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732655AbgLRReE (ORCPT ); Fri, 18 Dec 2020 12:34:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732521AbgLRReC (ORCPT ); Fri, 18 Dec 2020 12:34:02 -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 85780C0619D5 for ; Fri, 18 Dec 2020 09:32:37 -0800 (PST) Received: by mail-pg1-x52b.google.com with SMTP id n7so1759283pgg.2 for ; Fri, 18 Dec 2020 09:32:37 -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=g1R9Bq/TkbA5ZJxMb+U3jIOApLTRzPyrB4NxcI5os7I=; b=t5wRCamddvBbP1gidIz9qVvy3YaRueHBIcG8WR00lGkn2knegTeSlgbq5QlaM7VMJl LoOcQJ9rLi7XcIKluTKzOBWvB1hklOY/sFX/Q3J/uw7FWs5W8/Pl0pQ1IW9/fTcqCEln shYK9ZwSWbc64d1k1i9JO20A3s6BI2f7vUguLJFLhOr5PphEUXj/CQTssw7iJenbu4+R kfo1qvB8GiDiswP8UJ++4LiEJN57I/QnT+PG+ymdOYwyIn/vegZrq8Awq2EeSvzj56qB JzirrUAxmQeRZyMUEIUxyfVmfkj7Wu6SkJ0vRdTStTB44T70QDag4kqfbJjc8wyPA+b+ XkbQ== 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=g1R9Bq/TkbA5ZJxMb+U3jIOApLTRzPyrB4NxcI5os7I=; b=iGEXquNXFbzvsXx+NVrwXRtDUEx8jXh1RN09WpwKk/Nz62+j7iMnpsojHfX83Bpkow g8955aQNU0Ue/mz7lZriT+E6JSvje6Ch8YHwv+jNTAKrbinUNvBLrMc1iYjrhOGfun9S ejzFoY+GYPEbB35QdO+VH0jKUcgf2EXGMDDq4Q/WrfO5q70MOwJ2vfLoFzuEJB8yJpeG x81oyF9RLgKnpLGSclBMOXy5on3ZcgVyqm8z2m4BfnCHpHZXTOb481Z1S1CPPedSJiB7 OUwR9OuV8+vNJDtkWtvZyrGsLvCQ483uY+Co2uiQfAnMNSZs+RTzv/w8di5nqhS9WQ9G wUmA== X-Gm-Message-State: AOAM530cmHVp4Gm62fL6vS6ODm1H99q36V1Pms26FLTmI0+sSdZkwFfy NyQIQRC3S4GgBfel1iBXi1Kg+A== X-Google-Smtp-Source: ABdhPJz/vSSYTsXvkEMySgNmQol+y5TXIqrof7YPeVugtRHub1q2+gQsIrgAJK4N7v/aB6KE/YvhlA== X-Received: by 2002:a63:5843:: with SMTP id i3mr849381pgm.209.1608312757099; Fri, 18 Dec 2020 09:32:37 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id l11sm9892957pgt.79.2020.12.18.09.32.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Dec 2020 09:32:36 -0800 (PST) From: Mathieu Poirier To: ohad@wizery.com, bjorn.andersson@linaro.org, robh+dt@kernel.org Cc: arnaud.pouliquen@st.com, linux-remoteproc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 06/17] remoteproc: stm32: Move resource table setup to rproc_ops Date: Fri, 18 Dec 2020 10:32:17 -0700 Message-Id: <20201218173228.2277032-7-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201218173228.2277032-1-mathieu.poirier@linaro.org> References: <20201218173228.2277032-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 started by the core 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 --- drivers/remoteproc/stm32_rproc.c | 147 ++++++++++++++++--------------- 1 file changed, 74 insertions(+), 73 deletions(-) diff --git a/drivers/remoteproc/stm32_rproc.c b/drivers/remoteproc/stm32_rproc.c index d2414cc1d90d..c635f746e44a 100644 --- a/drivers/remoteproc/stm32_rproc.c +++ b/drivers/remoteproc/stm32_rproc.c @@ -541,6 +541,79 @@ 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 int stm32_rproc_get_loaded_rsc_table(struct rproc *rproc) +{ + 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; + } + + if (!rsc_da) + /* no rsc table */ + return 0; + + err = stm32_rproc_da_to_pa(rproc, rsc_da, &rsc_pa); + if (err) + return err; + + ddata->rsc_va = devm_ioremap_wc(dev, rsc_pa, RSC_TBL_SIZE); + if (IS_ERR_OR_NULL(ddata->rsc_va)) { + dev_err(dev, "Unable to map memory region: %pa+%zx\n", + &rsc_pa, RSC_TBL_SIZE); + ddata->rsc_va = NULL; + return -ENOMEM; + } + +done: + /* + * 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 struct rproc_ops st_rproc_ops = { .start = stm32_rproc_start, .stop = stm32_rproc_stop, @@ -549,6 +622,7 @@ static 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, }; @@ -692,75 +766,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; @@ -800,10 +805,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 Dec 18 17:32:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11982591 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=unavailable 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 3793EC3526D for ; Fri, 18 Dec 2020 17:35:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0808523B70 for ; Fri, 18 Dec 2020 17:35:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732873AbgLRRe2 (ORCPT ); Fri, 18 Dec 2020 12:34:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732870AbgLRRe2 (ORCPT ); Fri, 18 Dec 2020 12:34:28 -0500 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD703C0619D8 for ; Fri, 18 Dec 2020 09:32:38 -0800 (PST) Received: by mail-pl1-x636.google.com with SMTP id x12so1746632plr.10 for ; Fri, 18 Dec 2020 09:32:38 -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=9CEMg8/C2aYpmWeg0E4atqdzCFaHxz28xvWGUTHAaOU=; b=yGs7YdcFnxcZHUhZKvzMEbe1PoyRwerMN9vB8qmQpIYY5RgBnNuhxZWwwwB5/lvtFg 9aJAr/2jeVGd5E7TkoiosCRVL+V2SC9ScrAd1I7lPVLdPTptBIB/4ja3BZ22oVY/H6AH wpHzqrnB2kie/SygjiVg0/5VGSkus9A0nJfBMGaQyoLUrvLjKQUk9NxGCznEYIopt5cf wk7hTGXGofPIP6g70XV74OnoSi7Zd8w+swDXnkXafAcUjM3MJz8BdJ9PsuxasooCH7X0 igKonz3VPr3d+M7++I1Xnr/DrGqjSSPU6VGBw0JHnNO72G74JFt7Deq3r0RBR+Adc/bY w0JA== 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=9CEMg8/C2aYpmWeg0E4atqdzCFaHxz28xvWGUTHAaOU=; b=ZuEZt/23ZE/fR+nZraUn+YfTckkoN1Awao8mBvLvjaGD9kfNv/SUOFtrT70gHkZ91l Yv6vXFqqMenMjm4vnO/qJIAsj3Qh82EwX5REpLWRSg8UrGoLrFBQBXQn6sVa71aAStJw /cTjwSxCozp2KgCESOZhwZk3Mxf+oDvrnJavpswO+0EX8EX7t8BQ0ZNdkCbxosqlSQSw ZLo/c/lQ4bT2H1RhUlfBr/Y+aR6qhF3eaQGgm2XJHwNnq+1dwRG04tJt9YPD3EdS1YFb cbgCds1rGwYHUA8H2GAJm9V/bgjXL5tNKVZt4m3mbdFYLWM8V+2GOEwfjtc6qq1DXLjq uN+A== X-Gm-Message-State: AOAM531al6OweNZFm8CCBuYCdmrt4kdRWX/+7Va7ouRDeGN6RHXfe1uT mA6mihi7gaJd4O7kbfAChZgnMA== X-Google-Smtp-Source: ABdhPJyx4COQ1gqOq1bLZo5G263DD9QApp1/1tOEBa7Tyyg0pG3GsdzUzZUkAtVUJbF7z4bYaR6IYw== X-Received: by 2002:a17:90a:e28a:: with SMTP id d10mr5142068pjz.77.1608312758354; Fri, 18 Dec 2020 09:32:38 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id l11sm9892957pgt.79.2020.12.18.09.32.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Dec 2020 09:32:37 -0800 (PST) From: Mathieu Poirier To: ohad@wizery.com, bjorn.andersson@linaro.org, robh+dt@kernel.org Cc: arnaud.pouliquen@st.com, linux-remoteproc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 07/17] remoteproc: Add new RPROC_ATTACHED state Date: Fri, 18 Dec 2020 10:32:18 -0700 Message-Id: <20201218173228.2277032-8-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201218173228.2277032-1-mathieu.poirier@linaro.org> References: <20201218173228.2277032-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 d1cf7bf277c4..1167adcf8741 100644 --- a/drivers/remoteproc/remoteproc_sysfs.c +++ b/drivers/remoteproc/remoteproc_sysfs.c @@ -201,6 +201,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 571615e77e6f..f02958a6c001 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -406,6 +406,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 @@ -422,8 +424,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 Dec 18 17:32:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11982571 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 E6B19C35273 for ; Fri, 18 Dec 2020 17:34:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C01FA23B6B for ; Fri, 18 Dec 2020 17:34:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732713AbgLRReI (ORCPT ); Fri, 18 Dec 2020 12:34:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732694AbgLRReH (ORCPT ); Fri, 18 Dec 2020 12:34:07 -0500 Received: from mail-pg1-x52e.google.com (mail-pg1-x52e.google.com [IPv6:2607:f8b0:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1C47C0619DB for ; Fri, 18 Dec 2020 09:32:39 -0800 (PST) Received: by mail-pg1-x52e.google.com with SMTP id n7so1759352pgg.2 for ; Fri, 18 Dec 2020 09:32:39 -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=GfAYvBHbjdMUa8RWoEQi/iMGUW9VzhbWJlUDatd7jcU=; b=prkzIuN97+jNEpprDZ7gPj1HbaI732J7q4fHIF0k4XfYqWiNkOiy5j/hXbkunlilb2 gY5Z2ivhxKohvyOzzK4UOS7WX1imqUG1mpL8qHV5ZFcBDUZHXdqbwYiw9wNhy/yAEBdA g5+yW1w1R7HZpmhUAIAjVs7ceQYDBwCczyANRH1KDxABJs1B60hazMtOPJbB0eJfohhg vAEC5Ez0eIHHpxtVUHqfyLj5iSHZD+lhKR4+KsGnhVa1jZXKK3VEsbn09Yh9pZZqbJCD o9yp6hI2Z356ky++68fz7Q1gjr2tvzxdl77Nch9biWaLKVJ4BN7qbOMsQnSyint4wFvV U/OA== 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=GfAYvBHbjdMUa8RWoEQi/iMGUW9VzhbWJlUDatd7jcU=; b=XeMqw1iqC7pBgT4kbFZYEBURHRZOifOk3STYyi0OymK3jt+1gayGpWmS9aiWR+xWMQ +KFrHWp/qmkEUXHjYPgLb9Au/1VW8BumMduDQYO0NlDYFgkBHXpTZC+Yzxx8q+jZBn9S SdZM6d5vU0jdpOMY/LRgOoLFXEGHiI55puFXZP9jBAiqArRewE8jX2P2c49QRuOOXZ8G h7ZBWAnT/+wsHEAqN+130DQfF2w5yrNpY+wARkftRdibyP+wJ10D+DKuj0qOrU2fHNJ9 by+qWx8RKUxlJ6fetqWuTvrnl3x1c9P64vORI1xl1eE6Gatye9Eve3pEs/jPPLaCcbPW yMSw== X-Gm-Message-State: AOAM531kTfLT+/Y4sV2z86fiC3boSf2Vg8Y2Pf6P1VBlt6HPN9uIm2VR VNIsY0rNkg8Ioz3UIHep8WXh1Q== X-Google-Smtp-Source: ABdhPJyJv4r/lTmSSwsyWCMJwd0QGEMhsBG3iVOEJc1MbcZ0nVgXFTyh3zRFkhSSE8kWSaP6kGF6GQ== X-Received: by 2002:a63:b908:: with SMTP id z8mr5225658pge.396.1608312759574; Fri, 18 Dec 2020 09:32:39 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id l11sm9892957pgt.79.2020.12.18.09.32.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Dec 2020 09:32:38 -0800 (PST) From: Mathieu Poirier To: ohad@wizery.com, bjorn.andersson@linaro.org, robh+dt@kernel.org Cc: arnaud.pouliquen@st.com, linux-remoteproc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 08/17] remoteproc: Properly represent the attached state Date: Fri, 18 Dec 2020 10:32:19 -0700 Message-Id: <20201218173228.2277032-9-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201218173228.2277032-1-mathieu.poirier@linaro.org> References: <20201218173228.2277032-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 3d87c910aca7..19545b7925e2 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); @@ -1665,14 +1665,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; @@ -2023,16 +2015,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 1167adcf8741..99ff51fd9707 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 f02958a6c001..257a5005f93e 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -513,7 +513,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 @@ -550,7 +549,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 Dec 18 17:32:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11982569 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 C7E65C3526F for ; Fri, 18 Dec 2020 17:34:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A319F23B70 for ; Fri, 18 Dec 2020 17:34:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732694AbgLRReI (ORCPT ); Fri, 18 Dec 2020 12:34:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732697AbgLRReH (ORCPT ); Fri, 18 Dec 2020 12:34:07 -0500 Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2990EC0619E0 for ; Fri, 18 Dec 2020 09:32:41 -0800 (PST) Received: by mail-pg1-x532.google.com with SMTP id 15so1745099pgx.7 for ; Fri, 18 Dec 2020 09:32:41 -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=S1HgCKBSeYWceu/5Tsos67As2E/8FgrkAm9u2K2eWO4=; b=K3x5/W+4ULJWJq8l1Xd1CrmV5GLr2egnactNfaaxBBudoYDP98hWuY9AKWADXn3sNo rg8GirM0BO7YfJ6Xx/jTtMdlMnhoP1HC1SMcRAlMtni21IomvYF98rQ9V5uYtB7P8fuw jK05p4Xz1+HGRGpohfJXxFPnqPXtoFsL2qlnqbf/diJ+x+XukYL95mfJNYxypHI2uybz VB0lkh1qPoU3TrgQXk8THBwebaCScTknt+tyZqOAar1y0PXPA9m+rb7hhm4ieF7vVO1W FOoHkIvQup28bX6TAzsW4LKjS/884fW9yO5LVDXkBrbfvRDWrspz/gugSNIaOkDb40I9 vdKg== 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=S1HgCKBSeYWceu/5Tsos67As2E/8FgrkAm9u2K2eWO4=; b=XcQV8RorhKcV+OiSKsQHSDw2frKypc434pl9/OneM4UOTNInVsiwbSJZgIjLN8e9UX K30g6lMEWUHFNruAGQLNO9sZ77qvIi/NxnaiYUikBf/vopflVIw7XvYLfl+RXYxv6EkB hPTD9VXupThnIg9jnpZKWgcTLaDu3NgKizY+PHH/Om65+wXA1GlOFCBg/QCyNpEpH6TQ phUIvbqxbebvpVmIfD+kaJuQkJ2K01e+1QpoGhxia8py4Wb6drx+00PDPOY9ugmkFlK+ CFsLVbn9sNzNFyOkdde+8lRRcGR24S4fjGJCwsyXcRJCGoVzSegntDO69zNY09O3K3WS ie7A== X-Gm-Message-State: AOAM531b0ralvTJ7qNf4lXrRvDZQZGBGegLZ6ssiBXRC6h5SvcJupYEC DVTt6EGAsvGlOYHfbWq5VuTJcA== X-Google-Smtp-Source: ABdhPJz0u6bhRN0P+E0shxtDgSEotIsq6JFr2tK1pJBY/vhdVJJ5rnIxc8u9MwxAcby/zCik8akL1A== X-Received: by 2002:a62:19cc:0:b029:19e:321b:a22e with SMTP id 195-20020a6219cc0000b029019e321ba22emr4824607pfz.73.1608312760748; Fri, 18 Dec 2020 09:32:40 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id l11sm9892957pgt.79.2020.12.18.09.32.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Dec 2020 09:32:40 -0800 (PST) From: Mathieu Poirier To: ohad@wizery.com, bjorn.andersson@linaro.org, robh+dt@kernel.org Cc: arnaud.pouliquen@st.com, linux-remoteproc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 09/17] remoteproc: Properly deal with a kernel panic when attached Date: Fri, 18 Dec 2020 10:32:20 -0700 Message-Id: <20201218173228.2277032-10-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201218173228.2277032-1-mathieu.poirier@linaro.org> References: <20201218173228.2277032-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 19545b7925e2..fc28053c7f89 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -2414,7 +2414,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 Dec 18 17:32:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11982585 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=unavailable 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 50AA6C47435 for ; Fri, 18 Dec 2020 17:34:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 28A7423B6C for ; Fri, 18 Dec 2020 17:34:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732902AbgLRRee (ORCPT ); Fri, 18 Dec 2020 12:34:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732908AbgLRRec (ORCPT ); Fri, 18 Dec 2020 12:34:32 -0500 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3059CC0619E3 for ; Fri, 18 Dec 2020 09:32:42 -0800 (PST) Received: by mail-pf1-x432.google.com with SMTP id c79so1955605pfc.2 for ; Fri, 18 Dec 2020 09:32:42 -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=UE369EIBZVX7NEKYpAqFRWbqVEboyiDmoTqg7mEP3ho=; b=CjxlpfgFxYohq4V6dQAABJ7LtWFo36J+n71FUwHVblWZg4woCWLtdlLVEda0nM+ykH LW8zzer3KscVhQHeDYXyEPQUjcaj8tsmHwlw6jOx9VeoUg9nt0Drmr8CISbSkuSmdght huZOgv0vSZ1Sr4JdC5la9BWhQcYL3pM1URaNJYb2eqeti+QiTEKvKQ0RWKcuOKrrxhBH X9R9+v2CoHxRjz6UEumU3MCNW8b1gynT1C7RoDlupJ6srcEKXGhuzz7U/vxGWjbNS699 ZOQE/C50/hIcZR6PgPhS6LWvlPIbxb3BOC11B3abtkswhHEfMniA7RW7Ov5O2WpAqD5v CGyw== 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=UE369EIBZVX7NEKYpAqFRWbqVEboyiDmoTqg7mEP3ho=; b=CgJESFqQoWK1BvQ+c+P3/MAR+yufB6hEsAcA6JbIxikl50jFE1M1jCJnbJo2uUC030 n8JdIa67k8vK7g5DY0EruGIcwZxmjp+33Uc7sxF+/9pfyshpTQtJcwTQR3FT3yM/qIe9 Jx3yNyBSp4bCrXnjRlzh1oEzCJuHSJCTiZaeo3Rkt/Zt8Et5IahJR5aGv9+dRMbMm/X3 M5kLkZAD8RuTOOc5KjW/I+FbAX5dO62gs+uaAjVvHwGt9l4K41BtKh7i0BdCElhtTlJr dIwLIYZ6Je/zxDQEn70XxVQLibQDrwE/7HfFmMqUiWLWipFeFflwWVyvlim407t8HWCq fFMA== X-Gm-Message-State: AOAM530Bfl2Bt304cvJ0IDwIxjNpclTI+AaVnJ9D/zoI972yD6gOglcP YbBvv75N5MZt0ciyHnJVaFC5rw== X-Google-Smtp-Source: ABdhPJxWYQu1xh9x6SeT5oLCldmQ1WomSeYC9AMjEZj5v07RYMoFJGl3QXAxmlWMnISzyZnPS/qXYA== X-Received: by 2002:aa7:9312:0:b029:19d:fa90:3f42 with SMTP id 18-20020aa793120000b029019dfa903f42mr4887642pfj.18.1608312761769; Fri, 18 Dec 2020 09:32:41 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id l11sm9892957pgt.79.2020.12.18.09.32.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Dec 2020 09:32:41 -0800 (PST) From: Mathieu Poirier To: ohad@wizery.com, bjorn.andersson@linaro.org, robh+dt@kernel.org Cc: arnaud.pouliquen@st.com, linux-remoteproc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 10/17] remoteproc: Add new detach() remoteproc operation Date: Fri, 18 Dec 2020 10:32:21 -0700 Message-Id: <20201218173228.2277032-11-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201218173228.2277032-1-mathieu.poirier@linaro.org> References: <20201218173228.2277032-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 257a5005f93e..9bb34c3eb847 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) @@ -384,6 +385,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 Dec 18 17:32:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11982583 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=unavailable 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 B59BAC3527E for ; Fri, 18 Dec 2020 17:34:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8E5D023B6C for ; Fri, 18 Dec 2020 17:34:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732927AbgLRRee (ORCPT ); Fri, 18 Dec 2020 12:34:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732909AbgLRRec (ORCPT ); Fri, 18 Dec 2020 12:34:32 -0500 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3BDACC0619FA for ; Fri, 18 Dec 2020 09:32:43 -0800 (PST) Received: by mail-pf1-x42d.google.com with SMTP id h186so1958904pfe.0 for ; Fri, 18 Dec 2020 09:32:43 -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=kq/8af8gfyQHRLTjjFQpBmU8IlBKCx8ZUO1N7tlkmUM=; b=Xqy5A3cJrzblGn7kkF9K33fBX2hXDtOtmwTf+9wvM8bXNE3G4KFPGZ4lqjziYwxJIC 5pultxhG4IXdogclYCM3/RVu9w30nQ/ynI67lOSHfm5G4XPPb38I8BW7JhrBs9rMQr/o 8o7UCO+zUhE7aAlHdIwfSKBUs0ZqhWLPGpTB4a0Yu2Iww1eDG7BWSDr3a5xLqDhLrR3S rfDZ1zIn0jnkJTo5E45UmQkGvHRlFQ23IcYsUKGDddXxRQeG9GFO2hL4kg/gWvOgD0m5 breNaRghLvch90zF8EyPek85TkUj+UKKdQcvx3Yc/G4WFsilC6wDe0YE8WxWeilNvFKN iUHw== 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=kq/8af8gfyQHRLTjjFQpBmU8IlBKCx8ZUO1N7tlkmUM=; b=T72w2Q0FeXzr+l45oh0SfVzZbIXOltJat6COh5HpsDqVPChtvngmrYjn++RZDnM3QX e/dOQVU9qpz64kbYSB/H7XkNgwvVFh/ClWq8UDNGovorvFQp3hTLseduDB50V2ldvKGp fuoXVwfDonzz0cjhlQAPYbywetj2jzkw8quGB5PBCujfxGVhcFA6Xd/QAeJ7NxF21P2q O/2rKgBca/9ijFUTdmc9VlWH+FNQGOYh/nDcpQanHhrrQI8MLJQwVInvI3gQ2uKVMm0q q89vi89/YOySR0zgTiCXORoCeTJv4iit8DzTXm88GjzAmVBHKKLd3tETyra2Q8hIfVIv usMw== X-Gm-Message-State: AOAM5329AvNP0uqPkJm+78YviudRbHvSUyjPXP8XRAqDYJfKFiQdDBYf N9AtyJYQg7oJyRsS+IvN+MZ/QA== X-Google-Smtp-Source: ABdhPJwNj21hgIvlcHibG1MkQ4DsJhmLrpdyxNVyETJNxGhMSoeftqYfxD+zBCtmcy8HAPC7E2/Hnw== X-Received: by 2002:aa7:9f09:0:b029:19e:cb56:e124 with SMTP id g9-20020aa79f090000b029019ecb56e124mr5253730pfr.38.1608312762797; Fri, 18 Dec 2020 09:32:42 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id l11sm9892957pgt.79.2020.12.18.09.32.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Dec 2020 09:32:42 -0800 (PST) From: Mathieu Poirier To: ohad@wizery.com, bjorn.andersson@linaro.org, robh+dt@kernel.org Cc: arnaud.pouliquen@st.com, linux-remoteproc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 11/17] remoteproc: Introduce function __rproc_detach() Date: Fri, 18 Dec 2020 10:32:22 -0700 Message-Id: <20201218173228.2277032-12-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201218173228.2277032-1-mathieu.poirier@linaro.org> References: <20201218173228.2277032-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 --- drivers/remoteproc/remoteproc_core.c | 42 ++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index fc28053c7f89..e665ed4776c3 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1670,6 +1670,48 @@ 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); + + /* + * If the remote processors was started by the core then a cached_table + * is present and we must follow the same cleanup sequence as we would + * for a shutdown(). As it is in rproc_stop(), use the cached resource + * table for the rest of the detach process since ->table_ptr will + * become invalid as soon as carveouts are released in + * rproc_resource_cleanup(). + */ + if (rproc->cached_table) + rproc->table_ptr = rproc->cached_table; + + /* 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); + rproc_start_subdevices(rproc); + 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 Dec 18 17:32:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11982575 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 E0967C4361B for ; Fri, 18 Dec 2020 17:34:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8F62D23B6B for ; Fri, 18 Dec 2020 17:34:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732799AbgLRReT (ORCPT ); Fri, 18 Dec 2020 12:34:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732751AbgLRReS (ORCPT ); Fri, 18 Dec 2020 12:34:18 -0500 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 55598C061143 for ; Fri, 18 Dec 2020 09:32:44 -0800 (PST) Received: by mail-pj1-x1030.google.com with SMTP id f14so1663864pju.4 for ; Fri, 18 Dec 2020 09:32:44 -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=H4g2ghZevAZZMEldVnDmhvjfkN3XHebraEOrSS89kQg=; b=PiGtjane3hJdt4Yln3JhdBS07fwTZhgAKnMXQnHbOJg02WrEZY4pz3YJ6hr/Ztqkiw FsL0ZJomtWNko8fzcpuOOhFObhAwJMmucvfWrG32NYCh5SaQKS0jl2WOdtNykfh3LIsl gqj47HipepBxZM0Ahsq44RoEEdyquekivZtMsSTDX55neWf+4V0s3M4SmRAzJ/sLTf1a +bVuL+hPj0R0jQOWmWOqyiwk5iOBSJKJyvr47O6WdYhxY5lA9e8lSfLHOvklMPNAzivZ DEej6VIJ6XM3KakaIPcXrn7hN87taHfBENbmlBGkcmDJMlVdzOtS7dCfy82Wr53Ty6GX DI9Q== 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=H4g2ghZevAZZMEldVnDmhvjfkN3XHebraEOrSS89kQg=; b=cqrfjgtyb41agM0hJCSmBycaZWhlc7B9HnL2mP745jB2Wvg56EgE37ta293S+yBKPQ rCF79cL5+AnzQbK5odHkmJQ4D9Pw3akolVb9NYkZeoGaXaWHkgU+ZLNixHrG3iajOVZi 2NTA3jIw2zqOPBwifkvZ5Vg7EVfohie9U5+V2VpiiQn6RXQ4hL6xfrTuOW997j7iCHqh be5GOxpH9KX+/bgXF7f/trX593eM0KM7y1uTmKOGItcaah0I1b8+mPJb1NEr2HbnYlK3 O4kMOjMvhx1l/vNJBSTL5zKEMGL36g2XWO2kYxGs35mOiHrPY/eVFNEw6AO6LaF5B6AW VU/w== X-Gm-Message-State: AOAM531aZUcB2mxTKqwQf615LBhlN/Zj0Vv6XrmT+ypWccmVFLXdjPvs v0X0+2yVWTzs3eTKJ8NRKoGoMg== X-Google-Smtp-Source: ABdhPJxFlsdNpQczITSEa3R2bzJNrE8lUJjX1BO8NJEXHoY2yZi++2C8J1zqwuWx/8oENwP5aQEsVQ== X-Received: by 2002:a17:90a:d790:: with SMTP id z16mr5371190pju.88.1608312763918; Fri, 18 Dec 2020 09:32:43 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id l11sm9892957pgt.79.2020.12.18.09.32.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Dec 2020 09:32:43 -0800 (PST) From: Mathieu Poirier To: ohad@wizery.com, bjorn.andersson@linaro.org, robh+dt@kernel.org Cc: arnaud.pouliquen@st.com, linux-remoteproc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 12/17] remoteproc: Introduce function rproc_detach() Date: Fri, 18 Dec 2020 10:32:23 -0700 Message-Id: <20201218173228.2277032-13-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201218173228.2277032-1-mathieu.poirier@linaro.org> References: <20201218173228.2277032-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: Peng Fan --- drivers/remoteproc/remoteproc_core.c | 71 +++++++++++++++++++++++++++- include/linux/remoteproc.h | 2 + 2 files changed, 72 insertions(+), 1 deletion(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index e665ed4776c3..ece3f15070b9 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1673,7 +1673,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; @@ -1927,6 +1927,75 @@ 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_actuate()). + * + * 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 (rproc->state != RPROC_RUNNING && rproc->state != RPROC_ATTACHED) { + ret = -EPERM; + goto out; + } + + /* if the remote proc is still needed, bail out */ + if (!atomic_dec_and_test(&rproc->power)) { + ret = -EBUSY; + goto out; + } + + ret = __rproc_detach(rproc); + if (ret) { + atomic_inc(&rproc->power); + goto out; + } + + /* clean up all acquired resources */ + rproc_resource_cleanup(rproc); + + rproc_disable_iommu(rproc); + + /* + * If the remote processor was booted by the core the cached table needs + * to be freed and ->table_ptr set to NULL because it will be + * invalidated by rproc_resource_cleanup(). If the remote processor was + * attached to ->cached_table is NULL and kfree() returns right away. + * + * In either case ->table_ptr has to be set to NULL. It will be set + * again when the remote processor is re-attached to. + */ + kfree(rproc->cached_table); + rproc->cached_table = NULL; + 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 9bb34c3eb847..65ece6f177b7 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -659,6 +659,8 @@ 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); int rproc_coredump_add_segment(struct rproc *rproc, dma_addr_t da, size_t size); int rproc_coredump_add_custom_segment(struct rproc *rproc, From patchwork Fri Dec 18 17:32:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11982581 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=unavailable 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 1B0DFC35270 for ; Fri, 18 Dec 2020 17:34:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DC97223B6B for ; Fri, 18 Dec 2020 17:34:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732849AbgLRReY (ORCPT ); Fri, 18 Dec 2020 12:34:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732833AbgLRReW (ORCPT ); Fri, 18 Dec 2020 12:34:22 -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 B5A59C061A49 for ; Fri, 18 Dec 2020 09:32:45 -0800 (PST) Received: by mail-pf1-x42b.google.com with SMTP id q22so1917832pfk.12 for ; Fri, 18 Dec 2020 09:32:45 -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=uKSTphgWknohNFtSvHeL9OjdtOYRpK15kmrAWNQQraE=; b=Sgu23wLrVw115S9/YyqCMr2Y0KfHFTxj1vMq0A1WmMhO7T3Z3IYbXsGL9fZ9vZpWV+ NwvwjEizp4EZgh5DHKkTO+7opKvFbblxnzEKwtbWFxMdGkeSl34oRCksoIWEySV1QSXW XOMLxcxDPy/6TNC6cCL1lYiaRLXsjbb7O9Ubco0yEr39D99u5hoXsmke5LvldHNQhp46 YLb9nLKZFhQPXwmBCeLkmU6u2ZzV+25hq7ODVyshWIYIjNS+F5/bkEq/Ms+icIF0ismk 0Xb6XXvH1CH9opA0XIjWOq2BrhSF0Cs6RBbq4RUU2KLCUBFedI0ujuavSJ51FAex/r7V 3JNw== 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=uKSTphgWknohNFtSvHeL9OjdtOYRpK15kmrAWNQQraE=; b=M9OlFc/pFSbUsuxemUrMRxtrQcCAwfovIcEoHcpr55wmkFvuvA6QtPyGVlbmv7P993 6miAnMVLuTxYoUE6lnQPPOkXyzv2eyGPkOJjWDBBx0JCQkoNDpyO3RrNzOsABDJt4cYQ gSb+CD0yA6SktM1MfBpunjpCiGzr55jRyO19djA4AHAMcqPYOkaKzxN/QxY6157YQMNH i4+QAfbKTo1oqEpvnX4lHSJID25o/N/zoY6BUlPEIT8AceHsJgvEqBe3E7v7bWzfu7HL fJveQH1Ayg5g1k2OJQfwFLS0LlJT5AS21VA+XlfKWZLwDZe6W9tJkgcxstUyH2H8DJX8 Kowg== X-Gm-Message-State: AOAM533W7rtK6xAjVLG3TYQp1BjAGvdVZxkdH+I7JweAAu8L55u/Vz7E KRdDc+uMbJC07PyzI6DB17GXuQ== X-Google-Smtp-Source: ABdhPJxvEiUvC4NMjZYIqkx7yflVwE+0LHTRmVO1sN51YXmbr6EuTkm70GnXFugiDs6d8eKiUvaawg== X-Received: by 2002:a62:1749:0:b029:19d:960c:1bb8 with SMTP id 70-20020a6217490000b029019d960c1bb8mr5302964pfx.63.1608312765271; Fri, 18 Dec 2020 09:32:45 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id l11sm9892957pgt.79.2020.12.18.09.32.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Dec 2020 09:32:44 -0800 (PST) From: Mathieu Poirier To: ohad@wizery.com, bjorn.andersson@linaro.org, robh+dt@kernel.org Cc: arnaud.pouliquen@st.com, linux-remoteproc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 13/17] remoteproc: Add return value to function rproc_shutdown() Date: Fri, 18 Dec 2020 10:32:24 -0700 Message-Id: <20201218173228.2277032-14-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201218173228.2277032-1-mathieu.poirier@linaro.org> References: <20201218173228.2277032-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org Add a return value to function rproc_shutdown() in order to properly deal with error conditions that may occur. Signed-off-by: Mathieu Poirier Reviewed-by: Peng Fan Reviewed-by: Arnaud Pouliquen --- drivers/remoteproc/remoteproc_core.c | 19 ++++++++++++++----- include/linux/remoteproc.h | 2 +- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index ece3f15070b9..90057ad1bb6c 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1886,7 +1886,7 @@ EXPORT_SYMBOL(rproc_boot); * returns, and users can still use it with a subsequent rproc_boot(), if * needed. */ -void rproc_shutdown(struct rproc *rproc) +int rproc_shutdown(struct rproc *rproc) { struct device *dev = &rproc->dev; int ret; @@ -1894,15 +1894,19 @@ void rproc_shutdown(struct rproc *rproc) ret = mutex_lock_interruptible(&rproc->lock); if (ret) { dev_err(dev, "can't lock rproc %s: %d\n", rproc->name, ret); - return; + return ret; } - if (rproc->state != RPROC_RUNNING) + if (rproc->state != RPROC_RUNNING) { + ret = -EPERM; goto out; + } /* if the remote proc is still needed, bail out */ - if (!atomic_dec_and_test(&rproc->power)) + if (!atomic_dec_and_test(&rproc->power)) { + ret = -EBUSY; goto out; + } ret = rproc_stop(rproc, false); if (ret) { @@ -1914,7 +1918,11 @@ void rproc_shutdown(struct rproc *rproc) rproc_resource_cleanup(rproc); /* release HW resources if needed */ - rproc_unprepare_device(rproc); + ret = rproc_unprepare_device(rproc); + if (ret) { + atomic_inc(&rproc->power); + goto out; + } rproc_disable_iommu(rproc); @@ -1924,6 +1932,7 @@ void rproc_shutdown(struct rproc *rproc) rproc->table_ptr = NULL; out: mutex_unlock(&rproc->lock); + return ret; } EXPORT_SYMBOL(rproc_shutdown); diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h index 65ece6f177b7..aa5bceb72015 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -658,7 +658,7 @@ rproc_of_resm_mem_entry_init(struct device *dev, u32 of_resm_idx, size_t len, u32 da, const char *name, ...); int rproc_boot(struct rproc *rproc); -void rproc_shutdown(struct rproc *rproc); +int 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); From patchwork Fri Dec 18 17:32:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11982577 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 5F45EC2BBD5 for ; Fri, 18 Dec 2020 17:34:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 172BD23B6B for ; Fri, 18 Dec 2020 17:34:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732798AbgLRReX (ORCPT ); Fri, 18 Dec 2020 12:34:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732839AbgLRReX (ORCPT ); Fri, 18 Dec 2020 12:34:23 -0500 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1E93C061A4C for ; Fri, 18 Dec 2020 09:32:46 -0800 (PST) Received: by mail-pf1-x434.google.com with SMTP id w6so1961371pfu.1 for ; Fri, 18 Dec 2020 09:32:46 -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=mdgob6jb0rUl30rfuLBWyS6H4rN7qpxnzyGATQ2xIt0=; b=Z/bCGb665F1fxnTF+3LEJAjTLAyRytVrF5nB84gRSWFkw9pBOTDRyaetGJaVASDVf6 +nCf5Bzq1+bCfC0ZehUxmqVXTSEF7Ox4nPgslBlQKHFo2pX4hZzlnMxfuMhnTpEIy2t3 QX1JabKmP8D2ajzElTIJHWwsg0XxZf+Sdj4mOaaDI0x1Zf6hS/8e4LAS3GjSgbVQsycU uXtaDQOOvuGn6B9+d41ZrH+ckbZzv5tgX7LMEi7WxfusAahQEnVXcCvdEODCIMX6ulCo P3yNhh4uYuuNmDcUhd8xzicCX0lfgBiSzor5WZTOjIfdU4Pf4pHUCtMsPZ0nMFbppxC9 2IOQ== 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=mdgob6jb0rUl30rfuLBWyS6H4rN7qpxnzyGATQ2xIt0=; b=hgk4C2CMyDy7hubA9IsSyKSlNj8A38ioT1tf/crwwDWqEkdz3vE+kzZiKs5n/Ty1LJ vYLO9cu0NRaQzOwuRM22pDYuwBWfVHV5MbzWs1eUjoxHzMK56MUNDDM/qS9eYa8zh1uv eqVd/WR35jH0NKU3t86WZxabZhM9uCEoZyefrdf5Z/hnSrJ2ojuA5MBSLeCq5OYpV03C XWLAvOKEFI4QU182v8I1ngUB+FaHuJBa3JxBWRyLY2MRNKD36Grla6gB7fC/HxRWw6p0 Qdgc1Q9T1dMqlc+A1YhdGx95Z2MK8CXBpvnDRcLpQfJzQzsmUSAQLPGzfmOE+xJein53 UbZA== X-Gm-Message-State: AOAM532kNWJkWWqjsWJJRkkGVhXAgkRUYkNs5rzoBNLPCQNEjBVeAFLH O2txOqeA9on0JdZnawsu2440yg== X-Google-Smtp-Source: ABdhPJy/+ZjcVxtTwF++2jStA55jRMPC2aPW/4VFjoWMyt1jjjmt0nHwJ8iyT7Xxi66ffp3w1L1SkA== X-Received: by 2002:a63:2fc5:: with SMTP id v188mr4987089pgv.243.1608312766353; Fri, 18 Dec 2020 09:32:46 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id l11sm9892957pgt.79.2020.12.18.09.32.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Dec 2020 09:32:45 -0800 (PST) From: Mathieu Poirier To: ohad@wizery.com, bjorn.andersson@linaro.org, robh+dt@kernel.org Cc: arnaud.pouliquen@st.com, linux-remoteproc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 14/17] remoteproc: Properly deal with a stop request when attached Date: Fri, 18 Dec 2020 10:32:25 -0700 Message-Id: <20201218173228.2277032-15-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201218173228.2277032-1-mathieu.poirier@linaro.org> References: <20201218173228.2277032-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 stop a remote processor that has been attached to by the remoteproc core. For that to happen a rproc::ops::stop() operation need to be available. Signed-off-by: Mathieu Poirier Reviewed-by: Peng Fan Reviewed-by: Arnaud Pouliquen --- drivers/remoteproc/remoteproc_cdev.c | 5 +++-- drivers/remoteproc/remoteproc_core.c | 6 +++++- drivers/remoteproc/remoteproc_sysfs.c | 5 +++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/drivers/remoteproc/remoteproc_cdev.c b/drivers/remoteproc/remoteproc_cdev.c index b19ea3057bde..d06f8d4919c7 100644 --- a/drivers/remoteproc/remoteproc_cdev.c +++ b/drivers/remoteproc/remoteproc_cdev.c @@ -37,10 +37,11 @@ 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); + ret = rproc_shutdown(rproc); } else { dev_err(&rproc->dev, "Unrecognized option\n"); ret = -EINVAL; diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 90057ad1bb6c..2fe42ac7ca89 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1648,6 +1648,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); @@ -1897,7 +1901,7 @@ int rproc_shutdown(struct rproc *rproc) return ret; } - if (rproc->state != RPROC_RUNNING) { + if (rproc->state != RPROC_RUNNING && rproc->state != RPROC_ATTACHED) { ret = -EPERM; goto out; } diff --git a/drivers/remoteproc/remoteproc_sysfs.c b/drivers/remoteproc/remoteproc_sysfs.c index 99ff51fd9707..96751c087585 100644 --- a/drivers/remoteproc/remoteproc_sysfs.c +++ b/drivers/remoteproc/remoteproc_sysfs.c @@ -230,10 +230,11 @@ 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); + ret = rproc_shutdown(rproc); } else { dev_err(&rproc->dev, "Unrecognised option: %s\n", buf); ret = -EINVAL; From patchwork Fri Dec 18 17:32:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11982579 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 6CECBC3526D for ; Fri, 18 Dec 2020 17:34:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4193D23B6C for ; Fri, 18 Dec 2020 17:34:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732804AbgLRReY (ORCPT ); Fri, 18 Dec 2020 12:34:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732841AbgLRReX (ORCPT ); Fri, 18 Dec 2020 12:34:23 -0500 Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 113C4C061A4D for ; Fri, 18 Dec 2020 09:32:48 -0800 (PST) Received: by mail-pg1-x532.google.com with SMTP id e2so1749181pgi.5 for ; Fri, 18 Dec 2020 09:32:48 -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=vutdwpz2dUDTweVlb30ERc0HCxLnN2+/Hjzz5Y0E1bI=; b=BKXSrxbXnh6d2zRd2aZGKoJTdugQUWnvySJCEm8scXWnxe9+TXu4/81oD7MQ7cAa17 gBO+juB3m0O1fJjMKmtwbmlZgSx+e0JTk0c0HSQxxX0PtJqu1sIPMrzlHOrooOtCcSlV jBWWe3U8wAgF2HAAPUjjDl3dn+tkcgA2TspNkWMz0iMrwWGEqpVYwi9SA/2ycdhEX7EB ZroR/ixb5Fa5kmAWWEgaoiZgosqZ7gUGLmayhcP9HTnP7Q9Xz3hklPJzJNnEk/sy635S mZImmX9q2aaGbnoKtTFr/Lu2XDsdDRBFlAnGqEILryiXq7xAUF5u33LS7NVbe1lAjHJ7 TgaQ== 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=vutdwpz2dUDTweVlb30ERc0HCxLnN2+/Hjzz5Y0E1bI=; b=Fmxp4k5sZg9XfNWC9B7z8PpVuY+N7qYZXYZtXtYcJuiKLla+jzl7af6KlY99kqKpom /iAGehz//4HM1b4qGZdW/5LYsHiJG672Fqj9iT3/V2pUxirzlGGDP1KbzqR8ElYM0d2S LkihnwNNf8CMEiaEDJRv8+X+QvgD3+KI4XGQ0L9rxN6WLNYUlhtHS5FYdswSDjWny396 0JYCpLEFuC5hAtQE3V0lOD4GeZnhtnwR0x4gRPzLOoRZ97nPOnifwvUkn9+ZoQnLhfgG +QtRh8IGX1/fgiiFY2bqCDlvAL5s3LUJMFIoCNwYIcp8mvg7NUMHnpspe6u4j3EQn2Qk S8Hg== X-Gm-Message-State: AOAM533QwDJ1EOkkFTqQ3mklypK7urtWw8Taml1QpnSBOhrWjTxapYcv Akgk3V4CVZYR5fZ7NjekIBzd/FdaHjXFcw+A X-Google-Smtp-Source: ABdhPJyoSPdQNxv0nHKlET++OnaWfTpvXjLCfYQZndPk5Wlb1V3YDItJACWOCJnUBVrQbDsT25+Nuw== X-Received: by 2002:a65:4c4b:: with SMTP id l11mr1097792pgr.177.1608312767705; Fri, 18 Dec 2020 09:32:47 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id l11sm9892957pgt.79.2020.12.18.09.32.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Dec 2020 09:32:46 -0800 (PST) From: Mathieu Poirier To: ohad@wizery.com, bjorn.andersson@linaro.org, robh+dt@kernel.org Cc: arnaud.pouliquen@st.com, linux-remoteproc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 15/17] remoteproc: Properly deal with a start request when attached Date: Fri, 18 Dec 2020 10:32:26 -0700 Message-Id: <20201218173228.2277032-16-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201218173228.2277032-1-mathieu.poirier@linaro.org> References: <20201218173228.2277032-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 "running" case, 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 d06f8d4919c7..61541bc7d26c 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 96751c087585..298052c9d068 100644 --- a/drivers/remoteproc/remoteproc_sysfs.c +++ b/drivers/remoteproc/remoteproc_sysfs.c @@ -223,7 +223,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 Dec 18 17:32:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11982589 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=unavailable 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 1114EC3526B for ; Fri, 18 Dec 2020 17:35:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D692E23B6C for ; Fri, 18 Dec 2020 17:35:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727312AbgLRReu (ORCPT ); Fri, 18 Dec 2020 12:34:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732911AbgLRRed (ORCPT ); Fri, 18 Dec 2020 12:34:33 -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 429BAC0610F0 for ; Fri, 18 Dec 2020 09:32:49 -0800 (PST) Received: by mail-pf1-x42b.google.com with SMTP id d2so1943290pfq.5 for ; Fri, 18 Dec 2020 09:32:49 -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=r4WpCps/dmzg/nEPpmlNW78KzWKD4Zyq8EXXFVytS5s=; b=qmmI9vTp0A2LE/Vso7i2ivHcoYnFAy8QizlK1mNtLII2LdbDpKQg5kY27MrV9Ls3/Y JyNb4oQdv0aiQJnfE7G98FhNqpRsASuQI4IUzozKulAKGc6DiVsC3QuqAAW5MXtF10AJ WCvAlTsla+IZKPRiE6zc4BtjDc+6oag1IFC/7zvuQixp0Mbed8knKsbd8iD0Lio97L1E b5jyOCsr9zHZakNUZPDatWU+lKkkv8Vtojlt04oZy+yT40wy9jLIV73vRf8G9GiNwIwJ JZcIZjeywEqZ3Rchhzf43yBx8HFDCqgL61qhetW/1KdZGja12BnDKd5GQuqzXo23D5/g rAlA== 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=r4WpCps/dmzg/nEPpmlNW78KzWKD4Zyq8EXXFVytS5s=; b=ePW9Tg0hlvmQpDslytNpvel76x+r2iFVV9XWtSQh/DM1wmRIRJ5UWbodPO8hTqa7XP cE7a8ZAAMkL3mypQbBCrpdsguqSzUeNSd+CXiIbUctgDQIHVaEWCgB+BU9r9AjLUekxt gUVZ7InQ9j1bKWrQyc6P2Phrhmlau0CEjIxUu7zkFppBaPgzLVWxXav70VyfWDeBpv7Q jaX5FkwiRUrLGjnUxCASWkLoom2w0DHOfrU4n2Kwd3QZl8DASZocE+UO/amhsWJ1WESi d7mU9mf4XX26WwOjBfa4rPZYACT/VuttSOhNf9AIloh8QQvmgd8t0IrZfW7MHqA5ik0F Q+aQ== X-Gm-Message-State: AOAM533L5sLwzRMsUaJsTZWMCLfRk+OKWYp39DaS2cr57elygFMqTDDU EY2nllFUMhDNDCdbBzoJrxAphQ== X-Google-Smtp-Source: ABdhPJyHj7Z3LuRnodZ5FhdffYdSVbNG32Tpe3WzUH27PGKZDRQ91X4sBrPpU/k9Pk0GJ4SoCfwfiQ== X-Received: by 2002:a63:5c18:: with SMTP id q24mr5026246pgb.411.1608312768810; Fri, 18 Dec 2020 09:32:48 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id l11sm9892957pgt.79.2020.12.18.09.32.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Dec 2020 09:32:48 -0800 (PST) From: Mathieu Poirier To: ohad@wizery.com, bjorn.andersson@linaro.org, robh+dt@kernel.org Cc: arnaud.pouliquen@st.com, linux-remoteproc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 16/17] remoteproc: Properly deal with detach request Date: Fri, 18 Dec 2020 10:32:27 -0700 Message-Id: <20201218173228.2277032-17-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201218173228.2277032-1-mathieu.poirier@linaro.org> References: <20201218173228.2277032-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 or booted by the remoteproc core. For that to happen a rproc::ops::detach() operation need to be available. Signed-off-by: Mathieu Poirier Reviewed-by: Peng Fan Reviewed-by: Arnaud Pouliquen --- drivers/remoteproc/remoteproc_cdev.c | 6 ++++++ drivers/remoteproc/remoteproc_sysfs.c | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/drivers/remoteproc/remoteproc_cdev.c b/drivers/remoteproc/remoteproc_cdev.c index 61541bc7d26c..f7645f289563 100644 --- a/drivers/remoteproc/remoteproc_cdev.c +++ b/drivers/remoteproc/remoteproc_cdev.c @@ -43,6 +43,12 @@ static ssize_t rproc_cdev_write(struct file *filp, const char __user *buf, size_ return -EINVAL; ret = rproc_shutdown(rproc); + } else if (!strncmp(cmd, "detach", len)) { + if (rproc->state != RPROC_RUNNING && + 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 298052c9d068..ea7b067fe89a 100644 --- a/drivers/remoteproc/remoteproc_sysfs.c +++ b/drivers/remoteproc/remoteproc_sysfs.c @@ -236,6 +236,12 @@ static ssize_t state_store(struct device *dev, return -EINVAL; ret = rproc_shutdown(rproc); + } else if (sysfs_streq(buf, "detach")) { + if (rproc->state != RPROC_RUNNING && + 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 Dec 18 17:32:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11982587 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=unavailable 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 32511C352A6 for ; Fri, 18 Dec 2020 17:34:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F3AD123B6B for ; Fri, 18 Dec 2020 17:34:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732901AbgLRRej (ORCPT ); Fri, 18 Dec 2020 12:34:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732944AbgLRRei (ORCPT ); Fri, 18 Dec 2020 12:34:38 -0500 Received: from mail-pg1-x52e.google.com (mail-pg1-x52e.google.com [IPv6:2607:f8b0:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98239C0610FE for ; Fri, 18 Dec 2020 09:32:50 -0800 (PST) Received: by mail-pg1-x52e.google.com with SMTP id c22so1726829pgg.13 for ; Fri, 18 Dec 2020 09:32:50 -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=rkR5KGw6lOHFw7kU5pTdY0IIWw0NKqkih0SELdkxmb8=; b=DBREPFrFapCRqxKi8Q28381Uyq/Fj1Onz03ghAXR2urPxaEBt9myvb9C0ocMNAy/Rc nGenVzOCiuo6H9D+eFvdspI79dNwAvFPo437qhVdXkd7mP0qKfvJsUgMFWnCpl8B5TV6 jfSFuc3ZZ3Byz3Big60B/+a/8g3e0LAexUoBy0AZ1IOWevGhUOeP6a/9caskPtCraAvU rW5zgUZv6uO6A7RZy9ozBboq3SM3T64QBy7b6OOKkEVgKvPEq/VrCmMZgFLD9q3hj3RI T/6L+qXNepkj2Ey9qDGc4hZ7OPnywF9yBAWw6u/bUHbzHJdtouLJh8ctqSK+sqaleKpw 4/uQ== 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=rkR5KGw6lOHFw7kU5pTdY0IIWw0NKqkih0SELdkxmb8=; b=OBzPOOb8aBPv8EpT/15cZO6gmItLGn9brd67A5BFyY+8Lq12x5rKMYTtGsu2zEJS2g f9ZtMfuTmlSYxIVd0rOEoxhSe4Ej25hZKTsh77cZYRTIZZnrawepMb/gp8v+pHnEcPNn Q0d4A/6MWz5lThf1plcj8rdF9dA9VFak/yrMLKkesuT0SDqiw481svZMMHqT7knHykyI T+KJ6If3QF0ULuHAdjDfxHgdzEP4KZQTYfZvdjWoQZ5WD0SZa6asoZMJiAj+W/TeEsrV eAYwSzZmzP8UG2Jcn0JjyxAPvHshInn9w6Z7i3cWeC0Ez+ZTRKP3r03bqvYZoq5kfdu1 IbNQ== X-Gm-Message-State: AOAM531xxuRdmyjbSKWmpmkzVn8bpsaL13QWrOfs+fP67W9a/m8FZzUS wT58f1RJ4b7PnB0YR66EpkqVlg== X-Google-Smtp-Source: ABdhPJzIytOMrzVGGTOYToBrRlAebpcJAELAOgjt83DUeLFExl4B62ekoRHfgjde+hMzahmrkmqfPw== X-Received: by 2002:a63:fb49:: with SMTP id w9mr4988534pgj.403.1608312770144; Fri, 18 Dec 2020 09:32:50 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id l11sm9892957pgt.79.2020.12.18.09.32.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Dec 2020 09:32:49 -0800 (PST) From: Mathieu Poirier To: ohad@wizery.com, bjorn.andersson@linaro.org, robh+dt@kernel.org Cc: arnaud.pouliquen@st.com, linux-remoteproc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 17/17] remoteproc: Refactor rproc delete and cdev release path Date: Fri, 18 Dec 2020 10:32:28 -0700 Message-Id: <20201218173228.2277032-18-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201218173228.2277032-1-mathieu.poirier@linaro.org> References: <20201218173228.2277032-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org Refactor function rproc_del() and rproc_cdev_release() to take into account the policy specified in the device tree. Signed-off-by: Mathieu Poirier Reviewed-by: Arnaud Pouliquen --- drivers/remoteproc/remoteproc_cdev.c | 18 +++++++++++--- drivers/remoteproc/remoteproc_core.c | 36 ++++++++++++++++++++++++---- include/linux/remoteproc.h | 4 ++++ 3 files changed, 51 insertions(+), 7 deletions(-) diff --git a/drivers/remoteproc/remoteproc_cdev.c b/drivers/remoteproc/remoteproc_cdev.c index f7645f289563..9b2fb6fbf8e7 100644 --- a/drivers/remoteproc/remoteproc_cdev.c +++ b/drivers/remoteproc/remoteproc_cdev.c @@ -87,11 +87,23 @@ 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; - if (rproc->cdev_put_on_release && rproc->state == RPROC_RUNNING) - rproc_shutdown(rproc); + if (!rproc->cdev_put_on_release) + return 0; - return 0; + /* + * The application has crashed or is releasing its file handle. Detach + * or shutdown the remote processor based on the policy specified in the + * DT. No need to check rproc->state right away, it will be done + * in either rproc_detach() or rproc_shutdown(). + */ + if (rproc->autonomous_on_core_shutdown) + ret = rproc_detach(rproc); + else + ret = rproc_shutdown(rproc); + + return ret; } static const struct file_operations rproc_fops = { diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 2fe42ac7ca89..9f47a4ec0ec6 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -2254,6 +2254,22 @@ static int rproc_alloc_ops(struct rproc *rproc, const struct rproc_ops *ops) return 0; } +static void rproc_set_automation_flags(struct rproc *rproc) +{ + struct device *dev = rproc->dev.parent; + struct device_node *np = dev->of_node; + bool core_shutdown; + + /* + * When function rproc_cdev_release() or rproc_del() are called and + * the remote processor has been attached to, it will be detached from + * (rather than turned off) if "autonomous-on-core-shutdown is specified + * in the DT. + */ + core_shutdown = of_property_read_bool(np, "autonomous-on-core-shutdown"); + rproc->autonomous_on_core_shutdown = core_shutdown; +} + /** * rproc_alloc() - allocate a remote processor handle * @dev: the underlying device @@ -2312,6 +2328,8 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, if (rproc_alloc_ops(rproc, ops)) goto put_device; + rproc_set_automation_flags(rproc); + /* Assign a unique device index and name */ rproc->index = ida_simple_get(&rproc_dev_index, 0, 0, GFP_KERNEL); if (rproc->index < 0) { @@ -2388,15 +2406,25 @@ EXPORT_SYMBOL(rproc_put); * of the outstanding reference created by rproc_alloc. To decrement that * one last refcount, one still needs to call rproc_free(). * - * Returns 0 on success and -EINVAL if @rproc isn't valid. + * Returns 0 on success and a negative error code on failure. */ int rproc_del(struct rproc *rproc) { + int ret; + if (!rproc) return -EINVAL; - /* TODO: make sure this works with rproc->power > 1 */ - rproc_shutdown(rproc); + /* + * TODO: make sure this works with rproc->power > 1 + * + * No need to check rproc->state right away, it will be done in either + * rproc_detach() or rproc_shutdown(). + */ + if (rproc->autonomous_on_core_shutdown) + ret = rproc_detach(rproc); + else + ret = rproc_shutdown(rproc); mutex_lock(&rproc->lock); rproc->state = RPROC_DELETED; @@ -2415,7 +2443,7 @@ int rproc_del(struct rproc *rproc) device_del(&rproc->dev); - return 0; + return ret; } EXPORT_SYMBOL(rproc_del); diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h index aa5bceb72015..012bebbd324b 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -519,6 +519,9 @@ struct rproc_dump_segment { * @nb_vdev: number of vdev currently handled by rproc * @char_dev: character device of the rproc * @cdev_put_on_release: flag to indicate if remoteproc should be shutdown on @char_dev release + * @autonomous_on_core_shutdown: true if the remote processor should be detached + * from (rather than turned off) when the remoteproc + * core goes away. */ struct rproc { struct list_head node; @@ -557,6 +560,7 @@ struct rproc { u16 elf_machine; struct cdev cdev; bool cdev_put_on_release; + bool autonomous_on_core_shutdown; }; /**