From patchwork Fri Oct 30 19:57:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11870691 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 77A7E697 for ; Fri, 30 Oct 2020 19:57:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4691F206DD for ; Fri, 30 Oct 2020 19:57:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="hv9kblV9" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727410AbgJ3T5R (ORCPT ); Fri, 30 Oct 2020 15:57:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726061AbgJ3T5Q (ORCPT ); Fri, 30 Oct 2020 15:57:16 -0400 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E671C0613CF for ; Fri, 30 Oct 2020 12:57:16 -0700 (PDT) Received: by mail-pf1-x444.google.com with SMTP id 133so6213581pfx.11 for ; Fri, 30 Oct 2020 12:57:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NAwcucSRPOvdUr2SPYKPCVd/pqIxd9KNTkWdNua/hYQ=; b=hv9kblV9NRZikDjW8YsqxR4e1fb2iYOtADdoC0JHwBxFSgXrhB/MMZxBAg8htzy9Yh jNuyenU6aylTfnBumpnBXqfEyOBgOqM1KmnSnpJ0rKJ56vFMbuoAF7IVTxG4zD79Wju4 d6vrCDaxPM3DTpk+mSnQMtZsma7mI5c+/KZwdfD+m1U4/7I8U1iByJki2OgvJD06MmIS t/y0tT+tids0JVh0kd0HfXHh5LZBqMsYkULe64qVy26qEPE53qk0D71HtjqbK+nHYqlR g1fKPLfnFd0jM/SQ4fPBtYOXYKmc8ZQktEMJsL/DaeavHNthDuFeiAUxTELrQ7ObR1Ps WyjQ== 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=NAwcucSRPOvdUr2SPYKPCVd/pqIxd9KNTkWdNua/hYQ=; b=iXLlnYhebw3Rmc9GABJKDlyKHfAB2bW6t8Mzb1sROPKay7ZxmgLdDGZKGf9tUIVUDW ENJyg+ky1R3Z6aMQXHbz8RacgAktbgQfGEyo0gBse66ZImBQDi759RAorEqXuqTqg9zD cg/KxmBC94iRJRWZkE8+H559uxu3dZ4Qxi3HGbHJKWwnpZGbKgbVWGN8wraM/GUqqdM+ mg4NzGc8VIa0TOtD041may8kX4oljHoySq99GUYYzPQ0WH7k/kBsxCtsj/b0REhchSHi bl2LGVtVgzhZdzTr/VT6DEfBlkU0P2CZQToLRSZOF15xTl26mxCsmlZbI7YtdLILBBIa U9oA== X-Gm-Message-State: AOAM531aV5tHFstcFFLxJGVyLvf2knyFFK27li/RWGVwQgkUBO5wCme+ hyxZSRqY7O9NLctsWbt6pjT7CY2nA0We9MtA X-Google-Smtp-Source: ABdhPJyWhwkQV28YUU4uUZuTQwKznPAIp4iOmdzrmHmLx5fxc5gRG5MFvK+utVl6JSIVHA3zmCPJ2Q== X-Received: by 2002:a63:380d:: with SMTP id f13mr3634650pga.105.1604087835937; Fri, 30 Oct 2020 12:57:15 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id o15sm6892640pfd.16.2020.10.30.12.57.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2020 12:57:15 -0700 (PDT) From: Mathieu Poirier To: ohad@wizery.com, bjorn.andersson@linaro.org Cc: linux-remoteproc@vger.kernel.org Subject: [PATCH v2 01/14] remoteproc: Re-check state in rproc_shutdown() Date: Fri, 30 Oct 2020 13:57:00 -0600 Message-Id: <20201030195713.1366341-2-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201030195713.1366341-1-mathieu.poirier@linaro.org> References: <20201030195713.1366341-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 Oct 30 19:57:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11870693 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1D24514B4 for ; Fri, 30 Oct 2020 19:57:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EBE57206ED for ; Fri, 30 Oct 2020 19:57:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="jw4joYpZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727415AbgJ3T5R (ORCPT ); Fri, 30 Oct 2020 15:57:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726061AbgJ3T5R (ORCPT ); Fri, 30 Oct 2020 15:57:17 -0400 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6EE2DC0613CF for ; Fri, 30 Oct 2020 12:57:17 -0700 (PDT) Received: by mail-pf1-x444.google.com with SMTP id x13so6217794pfa.9 for ; Fri, 30 Oct 2020 12:57:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MBmQ91t9OFZqUj6J/X6Gtj+N4na71uxGzfdyC0ILZQI=; b=jw4joYpZCjsHzGcHlXmjdZxePZQ2QhuLqfrbDTeUk7Vov9WPLA6joCp+5oBZ+ReH0F yumjxLqLy+FNgOXWi1x9ydeSPMx0DPWz31NMHNssK+SHMXtaWVz7qSOjRPZ/NYdeg6iv YscXvb90NllM/il0iAADYC3p6usbWROiyLjtn+fImCqdab+Ugll+somF/z309UxmVyXq 4s8ik47MByanncrgXdAtnFLVQhOR7HKdiucc0yqVVvPT7mBBSRS/t4hyq4YAGK31+PB8 rdaFuwF3eTYSPT4DyqEwBMkIjZ43DnnMLyR23tYyn3pZ8C/VYjFXKrOSCHpTSIIEcHzl Neng== 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=MBmQ91t9OFZqUj6J/X6Gtj+N4na71uxGzfdyC0ILZQI=; b=fLF7+TK4/St4vY9qbCqabVPrrog4QH9V342q2yekoyw3wQ09CGw4htYkwII76AugLX PNNXSJRWia9ii9buzsyj+eJfXDSwflZ5Igvs47FWG0r9yezjrIiePCXi+PFMiCAJC8xZ Hi/rpd2oHIVpdES2O/gDv2zU7Ko2X2Q6kqJV77xQKNGsj4BmOFHELYm+6pu6hn8AefuD CcjtagagohYzRXXJjUloP+si8n7T32X4p8eN4hey6K+iEBXIwBkxqoy+15WNnyoO8tl2 ENclc+pd4LDhjA7ka6ryUXb6yP47ziQiuD0/sQYVbMy7sRLsnpHGe3NnBgHtfVkE5VRH fUvg== X-Gm-Message-State: AOAM532yi3e7CFWMCBZ7qfdNgP1OWYycOJ8AgQk/1I9YJGP+FGr2zHl6 yefLj/kuLyT4huhRNHqWABDu2w== X-Google-Smtp-Source: ABdhPJxzuXnQtlYPiG9INAbm2uQldDu2ndmmixsKYs32AjnTFknenDMWf7YLTWvrgK3i4jlLW9ejdA== X-Received: by 2002:a63:fb50:: with SMTP id w16mr3402563pgj.202.1604087836986; Fri, 30 Oct 2020 12:57:16 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id o15sm6892640pfd.16.2020.10.30.12.57.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2020 12:57:16 -0700 (PDT) From: Mathieu Poirier To: ohad@wizery.com, bjorn.andersson@linaro.org Cc: linux-remoteproc@vger.kernel.org Subject: [PATCH v2 02/14] remoteproc: Remove useless check in rproc_del() Date: Fri, 30 Oct 2020 13:57:01 -0600 Message-Id: <20201030195713.1366341-3-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201030195713.1366341-1-mathieu.poirier@linaro.org> References: <20201030195713.1366341-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 Oct 30 19:57:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11870695 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1601A697 for ; Fri, 30 Oct 2020 19:57:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E540A206DD for ; Fri, 30 Oct 2020 19:57:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="DWh6cEJr" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727423AbgJ3T5S (ORCPT ); Fri, 30 Oct 2020 15:57:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726061AbgJ3T5S (ORCPT ); Fri, 30 Oct 2020 15:57:18 -0400 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72C64C0613CF for ; Fri, 30 Oct 2020 12:57:18 -0700 (PDT) Received: by mail-pg1-x542.google.com with SMTP id r10so6099665pgb.10 for ; Fri, 30 Oct 2020 12:57:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=yXdL4ecpHH1mL8S5GyV3JtEcnfM47x+V/iQcr/L7MnY=; b=DWh6cEJrr2LpkfUzIei3n6oExlgHffGkqhzzQsgK633PBlinOM/b5F7rqGtjyF/t01 nspgP/yd2viZMED7xD25NF+rKsg6pLEd7Y5DksPyjpWEjsS4rcbBqmdgFE/efZVphosx Sbb4NiFy2UkRYh4ZgZThK44RDYYhuSEMOb8wD9fhSgP/E+KlKEDtQitWi1GXrTF4wbWi xUn67AOMQnBeHGPAGClYTecOfWh2UNBrnQyFJoAmoHShEHbz+8IG1k+jijBwdGZ+qsTD Ucm0Kgh+kXId3hmQPT96vpga0WKKusXxnaLmdvI5kpOKRtm6SenVy77chrK4riOGRY5W cd3Q== 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=yXdL4ecpHH1mL8S5GyV3JtEcnfM47x+V/iQcr/L7MnY=; b=XyCjDyI9HaMdaUsTXmaBD1proH6xU138Qf1QaefIhP0rTZy56CXR0PV343a9Wz2oYq MpfpDcCMKA/DzxKSzmu9cbGsq0HzE9T+Xu0n0GpbleRhDM/nRr05Nf2l2Uqo75rxxxhs 47WFO+8Q+GHpb0sfRKuTZhpNuOmAbjdfbpey2rk0sXLRmmpql05V0stbB1q9JeXyIadj xvqrpN/9Ku8rEeBH8esOsfaxZW/a2PlppNQvCtMCocbulJLv8puQLrtxakfMIxwN1e/t vm8+VfdLJLvmbGCynEo001L9YXjq7tLtoL5jtEezFSIml2BRRtxvmkysfwMhPDttzlXI F0pA== X-Gm-Message-State: AOAM532Mn9+OXJfl9dcVVlCV8MJFF4WOXnXNwUdMRY1fbPjppt77CJee gnRuUgyULK2P/ftOXVWw4yuIBw== X-Google-Smtp-Source: ABdhPJxm/cRs+Z8Poix1EikBTVOm9AlbhGEagsLiJ20ixr1afoev8OF/ZSeSXmSXoUExyhjFI8dtXA== X-Received: by 2002:a63:313:: with SMTP id 19mr3441948pgd.18.1604087838080; Fri, 30 Oct 2020 12:57:18 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id o15sm6892640pfd.16.2020.10.30.12.57.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2020 12:57:17 -0700 (PDT) From: Mathieu Poirier To: ohad@wizery.com, bjorn.andersson@linaro.org Cc: linux-remoteproc@vger.kernel.org Subject: [PATCH v2 03/14] remoteproc: Add new RPROC_ATTACHED state Date: Fri, 30 Oct 2020 13:57:02 -0600 Message-Id: <20201030195713.1366341-4-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201030195713.1366341-1-mathieu.poirier@linaro.org> References: <20201030195713.1366341-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 3fa3ba6498e8..4564c4665a2c 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -403,6 +403,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 @@ -419,8 +421,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 Oct 30 19:57:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11870697 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 28D09697 for ; Fri, 30 Oct 2020 19:57:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F3FE0206ED for ; Fri, 30 Oct 2020 19:57:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="P7ugzlDA" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727240AbgJ3T5T (ORCPT ); Fri, 30 Oct 2020 15:57:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726061AbgJ3T5T (ORCPT ); Fri, 30 Oct 2020 15:57:19 -0400 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8306EC0613CF for ; Fri, 30 Oct 2020 12:57:19 -0700 (PDT) Received: by mail-pg1-x542.google.com with SMTP id h6so6112908pgk.4 for ; Fri, 30 Oct 2020 12:57:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AQKUy2WOGIwxSAiaY3BkIXBU/7c4r+yinzFDwKGfcZQ=; b=P7ugzlDAaqV2RZq5DLncXT+wLlVxFEgSlAlO0ce3BD/iR6b8t4Hdwo3/GbrkdgKUDz Yy8BpGVFTQlUKFk2YBXfHGK3w5CWty/FQ4zYLjWLiE5oyPxVFcm4jIIMAkvzA2PR7Yh9 +WbBRLs1kUQqtxU1jmmOrPXsuwYer0N5fcYMh727p6vVDukGAX3+tnGq2Ly00sot0Si3 NcrG+XZnDkXW/VHH1WQjnFYS1FVNB4oKmeQsYz6QGFdjpzOMhyWvPPZfG0oUHUmY1cLd NO91Tia+K4ZyFmfJRH7+GFXu0zv/0aJ83XPkY/gJlXJ9CEiDty9rb6gSzCknvQ5wSRZL MMFg== 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=AQKUy2WOGIwxSAiaY3BkIXBU/7c4r+yinzFDwKGfcZQ=; b=QL9hTdqHplpP9kh1lThAepda9sJAfc85q5KlUlnWMTs1tHjcmzhQ1+E9pbcHLYtRYL f7zSVQQ0lyhLfjpF4P3E3cLPU14ueiqBxGqnWQqKnsJ1wCASL6z7r5OV47gp9gs6L4G0 3AhTE16MeWlKz0DSWfqC4pgfCjExiAv09Tw9FnD/0zRhigJfixPUij0mCDXafFOhZ/z0 yYT7F2c7UVvCfW5h3Bul8zjNUJAQ7x8wdlHEgUNDTMwmycFXW0e3kNxLaEvcJ6M6vBHy /bfy2CeqRlv8Q0pXEEbw60IGGPJDQrx6fD2vKgiu3FVf1C896mZBfZjx9Tdoj+3URwpa 0oaQ== X-Gm-Message-State: AOAM5329bDfCXXzEviUJ5FJPdwEesFNplx5szU2XPpw1v7e/8pjXDCrt FKZJNkPetLGFSJVYWYVYHkxwzQ== X-Google-Smtp-Source: ABdhPJyCxOAiHeZVovskUfKKpQvhu7vsXRpz9z5ltDEEiuWN0ongpIxA4PRpGO3Zi0i8Tqzu2ErnYw== X-Received: by 2002:a17:90a:d490:: with SMTP id s16mr4538870pju.185.1604087839084; Fri, 30 Oct 2020 12:57:19 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id o15sm6892640pfd.16.2020.10.30.12.57.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2020 12:57:18 -0700 (PDT) From: Mathieu Poirier To: ohad@wizery.com, bjorn.andersson@linaro.org Cc: linux-remoteproc@vger.kernel.org Subject: [PATCH v2 04/14] remoteproc: Properly represent the attached state Date: Fri, 30 Oct 2020 13:57:03 -0600 Message-Id: <20201030195713.1366341-5-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201030195713.1366341-1-mathieu.poirier@linaro.org> References: <20201030195713.1366341-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 f36786b47a4f..63fba1b61840 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1444,7 +1444,7 @@ static int rproc_attach(struct rproc *rproc) goto stop_rproc; } - rproc->state = RPROC_RUNNING; + rproc->state = RPROC_ATTACHED; dev_info(dev, "remote processor %s is now attached\n", rproc->name); @@ -1659,14 +1659,6 @@ static int rproc_stop(struct rproc *rproc, bool crashed) rproc->state = RPROC_OFFLINE; - /* - * The remote processor has been stopped and is now offline, which means - * that the next time it is brought back online the remoteproc core will - * be responsible to load its firmware. As such it is no longer - * autonomous. - */ - rproc->autonomous = false; - dev_info(dev, "stopped remote processor %s\n", rproc->name); return 0; @@ -2017,16 +2009,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 4564c4665a2c..3fe2ae0bd1ca 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -510,7 +510,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 @@ -547,7 +546,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 Oct 30 19:57:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11870699 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2C74F14B4 for ; Fri, 30 Oct 2020 19:57:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 033B0206DD for ; Fri, 30 Oct 2020 19:57:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="Vp0P3H3c" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727424AbgJ3T5U (ORCPT ); Fri, 30 Oct 2020 15:57:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726061AbgJ3T5U (ORCPT ); Fri, 30 Oct 2020 15:57:20 -0400 Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C70BC0613CF for ; Fri, 30 Oct 2020 12:57:20 -0700 (PDT) Received: by mail-pg1-x543.google.com with SMTP id z24so6122633pgk.3 for ; Fri, 30 Oct 2020 12:57:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mrLtJwnZtNMIcZOlLWTtJgAHRo+y844wAreui1GDutQ=; b=Vp0P3H3ckXFAR3pNZMBh+1b/tSEfCJwXIr6dBFWRyghEVFBayC9tpE3fmtdOHF3LEG p+bTbbbdREWFW0/r3ccDaINhyPq5ze0bze2gbUc7K76J8xbYCz2PHccbH1yFx9MVRCb8 VxTYSI/2QuFOI6SnkAC9EJscJ6M+0/nZQ0XNTRf5swI2ygfHzib2SpoKKQOqK0ZSl+Ef gi+RICz1Oh//+WIAmLNlu1I834fMCUr3N8KThWhZisyNRDUoyN9kxB1F45tItyxRSXFc 0GtNwAv7NPVQsQoEvwJKYBQ1CFO9qMWn1iNDYNvwBatHkSvEHA5AYpdXK4prgAy4ZHeZ cvnQ== 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=mrLtJwnZtNMIcZOlLWTtJgAHRo+y844wAreui1GDutQ=; b=ffIPsR99R7bU0bK4XCJxdWQetf5+m3iVHkSNYR4qkr+CselOzy/dbse5H0ZTNzsMbE W7IhOyuF3AbZLwgjwOpG0zc+Lmb+RsTqqdAuJZG0TvTZ4RstfgqZTGZ8m+tA0A04fQjP jxCmlHKGVs+GPMRk89+/TDCM1h7atYxPe4R9wreC7g7CSm3vHOslC5cQ1AOf9E9a64Nl AI5D2uV8x7XeoE8EpqMM4V3m5SP1DRPYq5dYKZF7hbh4R70d/lhjCdnKy2iRvSfa3U9/ 9WnFj/SGAScEvb8nrBWnbn5rSFMQGCK0wHeaf5RzXD/ScgyjeuoUrV0T7B7rxC8iujQK dd6A== X-Gm-Message-State: AOAM530+BnDjl9mSk8Bq9rrHIU7HBMkk1nxH3qrFJ+ApAKdej9qAWTXV sOs9ei2so6+LQPZFgEcUcDDL/Bk74IKzPzMe X-Google-Smtp-Source: ABdhPJxRWPKSP7P1oKubSE8Z47y/zmRfYPOgsGLSzhZ/+1CgQdgYOztVHX1eu0BqQdkWJyIzx1jIdw== X-Received: by 2002:a63:1341:: with SMTP id 1mr3431255pgt.6.1604087840102; Fri, 30 Oct 2020 12:57:20 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id o15sm6892640pfd.16.2020.10.30.12.57.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2020 12:57:19 -0700 (PDT) From: Mathieu Poirier To: ohad@wizery.com, bjorn.andersson@linaro.org Cc: linux-remoteproc@vger.kernel.org Subject: [PATCH v2 05/14] remoteproc: Properly deal with a kernel panic when attached Date: Fri, 30 Oct 2020 13:57:04 -0600 Message-Id: <20201030195713.1366341-6-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201030195713.1366341-1-mathieu.poirier@linaro.org> References: <20201030195713.1366341-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 63fba1b61840..ed1f9ca4248b 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -2408,7 +2408,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 Oct 30 19:57:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11870701 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6748114C0 for ; Fri, 30 Oct 2020 19:57:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4159F206DD for ; Fri, 30 Oct 2020 19:57:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="lCP3qYVK" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727425AbgJ3T5V (ORCPT ); Fri, 30 Oct 2020 15:57:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726061AbgJ3T5V (ORCPT ); Fri, 30 Oct 2020 15:57:21 -0400 Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E0E2C0613CF for ; Fri, 30 Oct 2020 12:57:21 -0700 (PDT) Received: by mail-pg1-x543.google.com with SMTP id i7so4179757pgh.6 for ; Fri, 30 Oct 2020 12:57:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=17lNPnfnYERsOP404CgqrJGvHV3P1BkEJkBETqPR2b4=; b=lCP3qYVK5DQRRdjvKhloy29t4RywJpUdNDL2Mrr9YkX5yFWiWGYeTX65gJ3kAS8k/d MRk4rF82mk/p0yDj+vM0tg4DkWsOlIm2tzlMcJvy4isJ746jcjvf0gTEBI2SPwTcUIY0 ERsbPIF2Xh5rQkww/rEqEeBoSI4ruP5TADDhUFTE53qP94twq5hL5BVViNOx3i9HuVkl Zy8AWlZLMrflMNp3a7UFrsNRmR5YbF22I/prDaDbMs5dWF8AE3xnQax+/bDwx+q0GQeM Vts1YmGK6YyLlMqJRn8ZCQJKyQLDtKNr6VdhpHX9dwhdsdn91FWCNMfGh3l59YZ9Da8o 3Svw== 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=17lNPnfnYERsOP404CgqrJGvHV3P1BkEJkBETqPR2b4=; b=Z5AndfVDIZORE0mVZQVleTw1lxj+2j4DcIUNUivT04Z9vffisUVeN3+aYA97o5FAlB E1vOEtGNuuwMes8nz0rr4QR/D77m/0TJNa7zRGg3qZ7zzOadIAExb/UfcnRImXN6PHVu mlkNQC/w3kzWKGST+SdTAb5ufFfnkYPe9X6DmnWY7o9XJbitdePEpcKV9rXgX4waWxR9 +DsiSRSc2Voz5y3rTINaypWBHUElZs3r3mO3B6CDpH3OoM5gTPTCD4wlMURLL5szQ/eI MEi752HNWqC2ldbmtlWrXgfauP7FyitsLx6p3TLsZmTAtwA92TNe4SjvvOtoAtgiH2Sr XlqQ== X-Gm-Message-State: AOAM531uKjkvUZbXEcsR0xHBJJpZmHMfsyMoMaORQVYCwpq3Va5v1O5K izasmP3RD1n85TSpkHeG5x3njANIZ+JOnXz5 X-Google-Smtp-Source: ABdhPJwfGVuxHhsuuGCYrQfG7R/HCIL/6T98jl9JzEEZh8QABki+hYj3bHiJkJr8dztqpAwVibKg7Q== X-Received: by 2002:a17:90b:19c9:: with SMTP id nm9mr4714922pjb.6.1604087841137; Fri, 30 Oct 2020 12:57:21 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id o15sm6892640pfd.16.2020.10.30.12.57.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2020 12:57:20 -0700 (PDT) From: Mathieu Poirier To: ohad@wizery.com, bjorn.andersson@linaro.org Cc: linux-remoteproc@vger.kernel.org Subject: [PATCH v2 06/14] remoteproc: Add new detach() remoteproc operation Date: Fri, 30 Oct 2020 13:57:05 -0600 Message-Id: <20201030195713.1366341-7-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201030195713.1366341-1-mathieu.poirier@linaro.org> References: <20201030195713.1366341-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 --- include/linux/remoteproc.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h index 3fe2ae0bd1ca..3faff9bb4fb8 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: tell the remote processor that the core is going away * @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) @@ -382,6 +383,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 Oct 30 19:57:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11870703 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9CE5D697 for ; Fri, 30 Oct 2020 19:57:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7A476206ED for ; Fri, 30 Oct 2020 19:57:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="EnkkyAEn" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727368AbgJ3T5X (ORCPT ); Fri, 30 Oct 2020 15:57:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726061AbgJ3T5X (ORCPT ); Fri, 30 Oct 2020 15:57:23 -0400 Received: from mail-pl1-x643.google.com (mail-pl1-x643.google.com [IPv6:2607:f8b0:4864:20::643]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7DADCC0613CF for ; Fri, 30 Oct 2020 12:57:22 -0700 (PDT) Received: by mail-pl1-x643.google.com with SMTP id r3so3492387plo.1 for ; Fri, 30 Oct 2020 12:57:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Ym715g1RcqNwEBgWs15Kb/aIm1MPrO92erJOeAUiWqA=; b=EnkkyAEnQQPKsszCYfykTC/5x6Wnix7BIHeRFCBSxAx+9RszAnnY9wJYTJAj+H35/o coEqiLjaNIMS6kowLZqeEMfoh6gurJuqi8mmIfdhzsprFT6JURiHDqXFh4rCkx9CeBbJ XgBMj1McX5WFLHzxcb3+MqotJ+OyABOITAfiapM6VHxE9xHOnIcPe86OkxPOQ2qZJQSk MvTII7tbnFM0d+onFgIF5LOqDRyhsJVLPJSSiUb+fohuZQiOR6qxC3/q2n/ORvG+R9M9 x5rFjqTTGsIXGpQhn4W4Kea1fCPhNbPrT20ZwLPUQJu4/zBQ2//hIcgS6lQG80J7RW5X sBhA== 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=Ym715g1RcqNwEBgWs15Kb/aIm1MPrO92erJOeAUiWqA=; b=oIWlZ68/wm7Plbgyv/wrT5aUd0yoHuG1ZwmF8EQusXQXZayLpgIzvtxbsRrT/huBPo N3vYkBs3k2z/iPiiqEHodO3onjkKNeb+plN4XkIFNAd4z17k0uTZnUyfGUu37iC4u6+X L23WTr8OoAhcwx3tgl/4Kk9ZUL6ThX/E9BQjZAZs2vECkDP4lpD80pQjkw+vkHwanuIP OdpazPSZern15bD3Ap6ecL1m7s9w7povShYIfQAiPh43hAe7THttOkgvenTdHETbd/c9 NX80K5Sr+Fd6nQS08L3IPDWTOfAz7ccPdcqxxO8kHCMyJAeJgwcR0FnSa/5/qJbZAR4i UrUg== X-Gm-Message-State: AOAM533nVpYN2fIFUce8ldtYMQFfsynIX8uoDY91qLKki9Ws9L7izXk1 AXdABueIDFj7MvAfNAKN2Rh5yItUW6MgCGwe X-Google-Smtp-Source: ABdhPJwHPcnHXX1Ru3oxKil6QlCZ67CXDnGpXX/nXyK11n5ofdyDWCRx6xERiNTaTEXK+Vo2EMreVw== X-Received: by 2002:a17:902:9890:b029:d5:e447:6b32 with SMTP id s16-20020a1709029890b02900d5e4476b32mr10407342plp.51.1604087842082; Fri, 30 Oct 2020 12:57:22 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id o15sm6892640pfd.16.2020.10.30.12.57.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2020 12:57:21 -0700 (PDT) From: Mathieu Poirier To: ohad@wizery.com, bjorn.andersson@linaro.org Cc: linux-remoteproc@vger.kernel.org Subject: [PATCH v2 07/14] remoteproc: Introduce function __rproc_detach() Date: Fri, 30 Oct 2020 13:57:06 -0600 Message-Id: <20201030195713.1366341-8-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201030195713.1366341-1-mathieu.poirier@linaro.org> References: <20201030195713.1366341-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 | 31 ++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index ed1f9ca4248b..62e88ff65009 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1664,6 +1664,37 @@ static int rproc_stop(struct rproc *rproc, bool crashed) return 0; } +/* + * __rproc_detach(): Does the opposite of rproc_attach() + */ +static int __maybe_unused __rproc_detach(struct rproc *rproc) +{ + struct device *dev = &rproc->dev; + int ret; + + /* No need to continue if a detach() operation has not been provided */ + if (!rproc->ops->detach) + return -EINVAL; + + /* Stop any subdevices for the remote processor */ + rproc_stop_subdevices(rproc, false); + + /* Tell the remote processor the core isn't available anymore */ + ret = rproc->ops->detach(rproc); + if (ret) { + dev_err(dev, "can't detach from rproc: %d\n", ret); + 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 Oct 30 19:57:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11870705 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 53DA314C0 for ; Fri, 30 Oct 2020 19:57:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2D22B206DD for ; Fri, 30 Oct 2020 19:57:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="XU0AaVBZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727427AbgJ3T5Y (ORCPT ); Fri, 30 Oct 2020 15:57:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726061AbgJ3T5X (ORCPT ); Fri, 30 Oct 2020 15:57:23 -0400 Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B53DDC0613CF for ; Fri, 30 Oct 2020 12:57:23 -0700 (PDT) Received: by mail-pl1-x641.google.com with SMTP id j5so3479728plk.7 for ; Fri, 30 Oct 2020 12:57:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=d8vC964dzjnOG1s42jnfHaCETkISum3lh12P9W6/brk=; b=XU0AaVBZaCUu5iviJKd23NsekTDDlrchdezQ475j/IGe9Sqh3n6p5sYHESZvI9aAMs yDNxS2R4nunxR2GFhH8DtfDnWEhAOv1OtaGyGYTk/G2czyVpHFfWichr6mn7WXioXB0G rwRecT80Q4/2o+Z4XCI9rErGfX/sdwrtwvVFxKRrWddr05Y8QZE1HxnAvGEBckKUjz34 IWIV73p2ukxuwwAx154XkiVDBN+s4bim+WhLb/h+AD4elmQDdLpuRHg0djVOtaMnr2Is 4i/uXZbHmgQFySbrgdIO/xbS22t72VyOPnArKN4C6AfWy4fzx61OkwpIac7aGMy/qejo m4/g== 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=d8vC964dzjnOG1s42jnfHaCETkISum3lh12P9W6/brk=; b=aMqHcHCc060YuB/JNI61obSV+wQtS8xP0SwxgjGAvY1f0RkxdYsaA4W0DZvuehiVKZ jl1DsmRI3V5Wt4ESolflLQ/msU9TIWK3b3aUOxPUrHIhWV7It6u+KqJMwBQR6tpZslRu OuzNEVLAsPZavTKLIaL5Dve2ADJCZoM0mElAWf9s0UnOCI4aPzCHZgpWwCJ5etUxy4Wp OFz9IQ0qM2mFSg1Yg6PI6vOVu6nBkE+vypiNdgq7u76UfXlKtZGAWfqTS33EoTokD6BP mM0pz4A1XvI/JKd7oDyztwP1OYI+gMvpRqf2SbK1DFv8aZaFR20eBke1pK/bBnqVzYuA sOXg== X-Gm-Message-State: AOAM5330GyvLmzB035VODdGNrFb1DxP+jD8UHovbn2RWwPVr3hopjTyB r6IEhqMPUDqZ/VlUnNbNgrqd2w== X-Google-Smtp-Source: ABdhPJzjbUeUT9qw4f/Nje9c/zAci15NK8OAfwLQZdF27YLXRMkrZ+RLbAVwHCVDdvLfEUznBPVdVg== X-Received: by 2002:a17:902:21:b029:d2:564a:5dc6 with SMTP id 30-20020a1709020021b02900d2564a5dc6mr10654125pla.14.1604087843279; Fri, 30 Oct 2020 12:57:23 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id o15sm6892640pfd.16.2020.10.30.12.57.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2020 12:57:22 -0700 (PDT) From: Mathieu Poirier To: ohad@wizery.com, bjorn.andersson@linaro.org Cc: linux-remoteproc@vger.kernel.org Subject: [PATCH v2 08/14] remoteproc: Introduce function rproc_detach() Date: Fri, 30 Oct 2020 13:57:07 -0600 Message-Id: <20201030195713.1366341-9-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201030195713.1366341-1-mathieu.poirier@linaro.org> References: <20201030195713.1366341-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 | 65 +++++++++++++++++++++++++++- include/linux/remoteproc.h | 1 + 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 62e88ff65009..6b33a83960d2 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1667,7 +1667,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; @@ -1910,6 +1910,69 @@ 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); + + /* + * Set the remote processor's table pointer to NULL. Since mapping + * of the resource table to a virtual address is done in the platform + * driver, unmapping should also be done there. + */ + 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 3faff9bb4fb8..6713faab6959 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -656,6 +656,7 @@ rproc_of_resm_mem_entry_init(struct device *dev, u32 of_resm_idx, size_t len, int rproc_boot(struct rproc *rproc); void rproc_shutdown(struct rproc *rproc); +int rproc_detach(struct rproc *rproc); 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 Oct 30 19:57:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11870707 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7270514B4 for ; Fri, 30 Oct 2020 19:57:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 48C1D206DD for ; Fri, 30 Oct 2020 19:57:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="OYnlPOGc" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727430AbgJ3T5Z (ORCPT ); Fri, 30 Oct 2020 15:57:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726061AbgJ3T5Y (ORCPT ); Fri, 30 Oct 2020 15:57:24 -0400 Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C037BC0613CF for ; Fri, 30 Oct 2020 12:57:24 -0700 (PDT) Received: by mail-pl1-x642.google.com with SMTP id w11so3480339pll.8 for ; Fri, 30 Oct 2020 12:57:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zxmdSo4JQxLa2nmhFO59aat8O4WMfpdpurDih6vkxO4=; b=OYnlPOGcbQCb6HJcnxz4GQYzRWntTCV3CcOdX6D4yk5YxzIQexztrfV2frB7TGjwrZ 1djdaGNkzfuFWTLvyQsU5qfRIuOnI411by55ZLTRbwTEjMZ0HsEiTXJg9gM193aN/TqA cAyJYtFf5WZVTRclG9CF01lRgIi/mpndBCJA3NeMsAWtbZIUYTs6d7bgzfhQJ0LjriXT 1zbeaoBgMi9vFjavg8BYlS4u6foPIrxpvQxg0XPNgc737V4vE428vJukWCNplD/km/n5 xl0jNabJO0blBJY52EXXsMkAlK7ud9aGKHErrfkkMDsTrVcu+xZJ+davrr4kZxWDuZYB ky2g== 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=zxmdSo4JQxLa2nmhFO59aat8O4WMfpdpurDih6vkxO4=; b=U8gwvS8VRY1RxBxtlXMcJTdrzJcZ8W6xFZDjPpO82fOW2e1ktawPYjTFLg6bxtZUPH 5GqpXoRksShTJuv1H43sTKhEDK3LYYHzOAP4hmTVlg1ciTZJ0ieBUuZn75LgmUQM9LRq 4cDz9Lx8z4i8IzgNkaYhCQ1SfT9hBa+/39W+fzEVbnwd+Ccj+ksCSl51fsbopAxx5JLW RK7Mdywef9IKZf2TBMBjwJlezhBbeNGrwVjAJ5LI7Oae7h+danSZ6hPqnaO+8+uZLikm RHOHt20EkVE+trxEWvWU8zGFJrPXhV6st5KnhiVmbXvILkn5mgIPFLAV8kIqgiTx+eQT Ub3g== X-Gm-Message-State: AOAM533oMK+PKPiV5tvDjriJQ1qvvui/D1vCZEgl5XfpBDtZ4w9A2WJp S5OjkuOiOY3YbAilA6NzihI9Dg== X-Google-Smtp-Source: ABdhPJwUzcGbfhZIbX8FG3MRfWOU4qrSmv1/ivmk5gNLWskl4dPZ/gCXjh16B3S2NZRGLmxPsfG8Cg== X-Received: by 2002:a17:902:a50f:b029:d6:da2:aaa7 with SMTP id s15-20020a170902a50fb02900d60da2aaa7mr11005031plq.42.1604087844358; Fri, 30 Oct 2020 12:57:24 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id o15sm6892640pfd.16.2020.10.30.12.57.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2020 12:57:23 -0700 (PDT) From: Mathieu Poirier To: ohad@wizery.com, bjorn.andersson@linaro.org Cc: linux-remoteproc@vger.kernel.org Subject: [PATCH v2 09/14] remoteproc: Rename function rproc_actuate() Date: Fri, 30 Oct 2020 13:57:08 -0600 Message-Id: <20201030195713.1366341-10-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201030195713.1366341-1-mathieu.poirier@linaro.org> References: <20201030195713.1366341-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org Align what was done for rproc_detach() by renaming function rproc_actuate(). That way it is easier to figure out the opposite of each functions. Signed-off-by: Mathieu Poirier Reviewed-by: Peng Fan Reviewed-by: Arnaud Pouliquen --- drivers/remoteproc/remoteproc_core.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 6b33a83960d2..de5a5720d1e8 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; @@ -1825,7 +1825,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); @@ -1916,7 +1916,7 @@ EXPORT_SYMBOL(rproc_shutdown); * * @rproc: the remote processor * - * Detach a remote processor (previously attached to with rproc_actuate()). + * Detach a remote processor (previously attached to with rproc_attach()). * * In case @rproc is still being used by an additional user(s), then * this function will just decrement the power refcount and exit, From patchwork Fri Oct 30 19:57:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11870709 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7524814B4 for ; Fri, 30 Oct 2020 19:57:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4F3B6206DD for ; Fri, 30 Oct 2020 19:57:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="oGP3mucw" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727441AbgJ3T50 (ORCPT ); Fri, 30 Oct 2020 15:57:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726061AbgJ3T5Z (ORCPT ); Fri, 30 Oct 2020 15:57:25 -0400 Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3FFBC0613CF for ; Fri, 30 Oct 2020 12:57:25 -0700 (PDT) Received: by mail-pl1-x642.google.com with SMTP id z1so3467234plo.12 for ; Fri, 30 Oct 2020 12:57:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fqBYHqMZrZCViq4U5E3PDLbfevo4++oGEAd/a8uU46Q=; b=oGP3mucwxu9Y5z5WRp1/AZrThCwT/gL0/vVoflebetyj5fiiZSq4q6PlrX1RJGbPso nrnaJ66PGnr4zFzVoPasKq79AzhP6I/IBHnK43lqQBez0t6bgM6ay8Ae9vts89Nb38Ta O5pgGwWKemSN1+U48gEVlCiBnJwSFjzn9d8HKxGe2a/b3T4si6hP9/ccOg+eQBrK/5vv 29W49yGDE4xGDUwMoBxKkeec7Uvzv5FdMjiq8KSLdRyIeuggwqlmmNLfkz0Qulo5UCzy f94eA4JOfXjyp5yr3+BUPQU5S330K/ViXepe0x/5yNXdEpgTCsPzqf3KEkf8/tKJpk+9 Pknw== 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=fqBYHqMZrZCViq4U5E3PDLbfevo4++oGEAd/a8uU46Q=; b=jpwOe+Pn0SisJdPX5gK5x7zIT1MUTdEtiaFr2vUzD/9ZyPcWS2ur88UDcyOC0YlwW2 EX6iyYrzTZlaMAot9OLs7nAMlF2O2Snyts373rTjvUcv4w3qgn7f3mgqqA6JgqxBbxpJ WR4UZIiMCCZOm7WNEJlNAgMFQqvFryu5XEIpt2hsifG5LguE9mXVXVVqAND8BfDeiVtq ErdtdaA1BCF4Cd4pkKk4RMaPjO6bxQAtkK9uk8MhfhvNNSRkeuDQp80AgdfKRZsrKuYs 5kn4hQ9btfgA25gBTikaRlr/OolhGLWqQduTgbLuLyk2m4zaqMLDGea8DZ5iFuu0UIb3 Vk1A== X-Gm-Message-State: AOAM530RMhkFZPI5Dy+Uf/V5v3n4dXIHS/3kSGqIwbqDwDmFlPObey1r W/zeQURdp9wIy53zYyQl9q+YCQ== X-Google-Smtp-Source: ABdhPJxtzzjM5a/pUmxH8b9P2+NaL1fqtV+73cRTYc3UlrJ5A+iYXC0YzlIdcJ1J3GGyiXM6XV24Hg== X-Received: by 2002:a17:902:74ca:b029:d6:7963:5bae with SMTP id f10-20020a17090274cab02900d679635baemr10634795plt.4.1604087845451; Fri, 30 Oct 2020 12:57:25 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id o15sm6892640pfd.16.2020.10.30.12.57.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2020 12:57:24 -0700 (PDT) From: Mathieu Poirier To: ohad@wizery.com, bjorn.andersson@linaro.org Cc: linux-remoteproc@vger.kernel.org Subject: [PATCH v2 10/14] remoteproc: Add return value to function rproc_shutdown() Date: Fri, 30 Oct 2020 13:57:09 -0600 Message-Id: <20201030195713.1366341-11-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201030195713.1366341-1-mathieu.poirier@linaro.org> References: <20201030195713.1366341-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 --- drivers/remoteproc/remoteproc_core.c | 13 +++++++++---- include/linux/remoteproc.h | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index de5a5720d1e8..f58475f6dcab 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1869,7 +1869,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; @@ -1877,15 +1877,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) { @@ -1907,6 +1911,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 6713faab6959..71d4d4873164 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -655,7 +655,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); 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); From patchwork Fri Oct 30 19:57:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11870711 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 90B05697 for ; Fri, 30 Oct 2020 19:57:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 660FB206ED for ; Fri, 30 Oct 2020 19:57:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="TPGcCggK" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727452AbgJ3T51 (ORCPT ); Fri, 30 Oct 2020 15:57:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726061AbgJ3T51 (ORCPT ); Fri, 30 Oct 2020 15:57:27 -0400 Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E435FC0613CF for ; Fri, 30 Oct 2020 12:57:26 -0700 (PDT) Received: by mail-pl1-x641.google.com with SMTP id w11so3480378pll.8 for ; Fri, 30 Oct 2020 12:57:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YbXz95cBHuTD6slrQPDDMWERewQd5djkfELMnXVXJ+k=; b=TPGcCggKjlQlzOPaFB62QSBjJEG1nDSXoNZRFIaGF0jSWQY4CMtDh8da0JBN9sroQm 5aqfzTDkdcQc1BHt5QL8N5bXB3a4EVf8CEV5VXVMDPXgg9jjX1OaVQ8lpV8kNvmLZplY yEhDl8ItXdPFUki0DYmIhcptKX3T4G+Rsrm6ulDoJjP1DHgbJOo7zlRMNqP/Qti6QRpy JRgGE4uC0470W0cmYcdrgTgUlxLdu6UX2NaTh7hZV451NAipLgU1Jy0SD0QsYQHH6UQJ nHGggJtnAskyA+Ns5CKOqEyVzn+P7SpEM6KXomSGzovkFYm7wWnUFekdi7MHLMxYHL8O pHqQ== 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=YbXz95cBHuTD6slrQPDDMWERewQd5djkfELMnXVXJ+k=; b=BGH0TSEli3aS6GsO8ifzPYQluTdWXVg2PVFqlL6s7EtU4swWPJlZnvuj+L00vwXws9 gtx+eklgK/zPqE/UCdnWml3x+n7fPzGjO57o+X56f9bIzS+PUSHnQD4Rq/jEC08I1kMN L862WwTw4ty8Ss7DJyyiZnytvzkojnAcTHdAEmjC8f/4HsaRJp7/RMAhTNQZOU7+ALZn xwrA+pEmsN/Q9JUBp9FJ2YUhOq4oA7KrKxZRcUbELD70Y+1erJ7t5BDeqUo9oz8zEkZO neIgLaYcn/m7J6/sVsUYGZj5v8kJIFebfSmZoJMiuIB+w090gmtRiqjyhLWypQj/X5sT l+bg== X-Gm-Message-State: AOAM532KEjeWdnEvQJ6eob1lDsC1HlMauyQAgud0wJ1mwWy1AzfU519V Qa4RHvV91wwcHW2D6J07tS1DKw== X-Google-Smtp-Source: ABdhPJyVMHm51PFs2+SdBrCZZg20llug89N/1UXhIo+c40/XDY7VN7U258hIqa4AjzR+fdofu6OciQ== X-Received: by 2002:a17:902:76cc:b029:d6:6007:9372 with SMTP id j12-20020a17090276ccb02900d660079372mr9986613plt.50.1604087846502; Fri, 30 Oct 2020 12:57:26 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id o15sm6892640pfd.16.2020.10.30.12.57.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2020 12:57:25 -0700 (PDT) From: Mathieu Poirier To: ohad@wizery.com, bjorn.andersson@linaro.org Cc: linux-remoteproc@vger.kernel.org Subject: [PATCH v2 11/14] remoteproc: Properly deal with a stop request when attached Date: Fri, 30 Oct 2020 13:57:10 -0600 Message-Id: <20201030195713.1366341-12-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201030195713.1366341-1-mathieu.poirier@linaro.org> References: <20201030195713.1366341-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 f58475f6dcab..229fa2cad0bd 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1642,6 +1642,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); @@ -1880,7 +1884,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 Oct 30 19:57:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11870713 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8D4A114B4 for ; Fri, 30 Oct 2020 19:57:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6D59A206ED for ; Fri, 30 Oct 2020 19:57:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="wPWMYgB5" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727472AbgJ3T52 (ORCPT ); Fri, 30 Oct 2020 15:57:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726061AbgJ3T52 (ORCPT ); Fri, 30 Oct 2020 15:57:28 -0400 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F33A3C0613CF for ; Fri, 30 Oct 2020 12:57:27 -0700 (PDT) Received: by mail-pg1-x544.google.com with SMTP id 15so6091245pgd.12 for ; Fri, 30 Oct 2020 12:57:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WRY6fl6qdiJ37muV/R9kDKMsDgeMJstCKTSUeBcPTBY=; b=wPWMYgB5Rru9JhhRQy3CiX2nQVYJctuXhiaWRXQO15gYvqDUdo0tNI7bIDUlHabUv6 HeZw2Q8QMWW/XCi3GWOODH6VrhzXh39w0ipWzLtanyZkxgo839iByw6mAVf+Qom968Qv CNoht/ywiyaXSO1IKG3UpxpXCPEZP5mpnxmxn9ZtiX46xA5ff5kHkBWz3yj/tw9MHbnU xSjL0s2ezOjAotFJzJT4+FUvdvpbkhyHT521TwZBQO3OKqmJU1fO55lEPQ/JM7BzkYD1 nfLeIMTO/9yLawCh01qreYvyzKqwXcE5OJXtW2tz7yASTUKsTMkpUjJRZPH2hwQlUZz/ 5YgQ== 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=WRY6fl6qdiJ37muV/R9kDKMsDgeMJstCKTSUeBcPTBY=; b=NQH45I4vR7BUF52qUJeKTVKOYVbzVm8EdMBKaGD4OSH7LnJydv53gTuisv3kfqQaJC HZBeJ5WdvQIOFZmGHIOW24jDhHQGCsamZoFV+GTTsGR4eoa+l5rBTWy/UUXh9J2h7DuF iC3X2/FPaiTfmp3e1jIwDnaTEbdgWz5DI+8ykhKsHmI+TT1Uu5fHSI1KsaJ7jMTXVP2Q iVkMoOO7pGjQJucWbB6kWMvVXetoA+uQM+z8F7RkgdqFHJYGkYYn2LgYo9pwuozTp6+S ImH/9o5NX7EeJ2W5IhxtECtHUx5J2G5HYvO89MrucAfHfzdnT90nTX6x/n9UBTE5c0vr Z7SA== X-Gm-Message-State: AOAM533PmbpEplAk9eCRPaxJWlK70Enm9ka8KZ/bByj86ikxgzpdGuzy ZS3LJtg0bjtQIZGcrCQCdKIKksol0edSxFcb X-Google-Smtp-Source: ABdhPJzsfhoL31gUwlw6rtFL77NIe3Bpn2l1KbK2xhVbMZLGu9B19+vtXQqewWLE69KgikjFLCXsuQ== X-Received: by 2002:a62:154b:0:b029:155:df74:5a53 with SMTP id 72-20020a62154b0000b0290155df745a53mr10943478pfv.39.1604087847572; Fri, 30 Oct 2020 12:57:27 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id o15sm6892640pfd.16.2020.10.30.12.57.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2020 12:57:27 -0700 (PDT) From: Mathieu Poirier To: ohad@wizery.com, bjorn.andersson@linaro.org Cc: linux-remoteproc@vger.kernel.org Subject: [PATCH v2 12/14] remoteproc: Properly deal with detach request Date: Fri, 30 Oct 2020 13:57:11 -0600 Message-Id: <20201030195713.1366341-13-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201030195713.1366341-1-mathieu.poirier@linaro.org> References: <20201030195713.1366341-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 --- 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 d06f8d4919c7..3a3830e27050 100644 --- a/drivers/remoteproc/remoteproc_cdev.c +++ b/drivers/remoteproc/remoteproc_cdev.c @@ -42,6 +42,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 96751c087585..b05fad2178bb 100644 --- a/drivers/remoteproc/remoteproc_sysfs.c +++ b/drivers/remoteproc/remoteproc_sysfs.c @@ -235,6 +235,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 Oct 30 19:57: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: 11870715 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A170714B4 for ; Fri, 30 Oct 2020 19:57:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7C66B206ED for ; Fri, 30 Oct 2020 19:57:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="QZude2Ov" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727473AbgJ3T53 (ORCPT ); Fri, 30 Oct 2020 15:57:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726061AbgJ3T53 (ORCPT ); Fri, 30 Oct 2020 15:57:29 -0400 Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0ABA0C0613CF for ; Fri, 30 Oct 2020 12:57:29 -0700 (PDT) Received: by mail-pf1-x443.google.com with SMTP id a200so6211798pfa.10 for ; Fri, 30 Oct 2020 12:57:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uoPr57cz2pH3IKXMHyKccjcQtdX4qfFYD7I6XjUq9SU=; b=QZude2Ov7qAjvxsNSwkWrrEUh74v7DzLiMzVDvuKthlLzyrF1rHdGmVxLPJYcnFCni tBRQd9LYVpbPqlfzE2f9MnFKi9kwDHcpQC8/9NbJuaZ3FhNaOyZlE3cNW22mlfAeAbWn PnxUu5Bd0Xb/7+4CGuh4stOijTUW3+TOfC9CQT7Ue6DPKGAQWFJO10hCbUJ8IRJcSew+ BpgcGn5o8mzj9YjryGHOFORfBd2yxkm2+rWrqQhz7JA/YrW42llxR7PWCaU244YwSxQA bjRHhXoG+wbO7En99/omlFM2Q0UYCcHPrNXRhtZ6vcv8oLJGWGQPPj2Q6TrxCA1oXqF1 BdVg== 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=uoPr57cz2pH3IKXMHyKccjcQtdX4qfFYD7I6XjUq9SU=; b=g8ulsB6X9xHS1hjvY0ZLwmM2ujJXirDcs328z/izCpxqwrRr1YQvuDzQAg7av8WHro C3913SmOI5ySsvsVPoQi2TBXxzidaXvF+llH4pxKJqFv1qIpHxPGRbcFT3HBAlbYiXKs Uleh+ealUuG46O2R3bfy+bmLIz73SezMhFBClVLeHqYpX/IlW1FusmcafphsGGEyuG9Y tsn+8Gcvoy0TmLuqBfigUrJpUH6ALSchsYDYv7EwbLB/WsMAd3R7RFDxgwFEQ06lh32m qBb+3s4lM9Yj5DUcIlGhQM2YRjc/PULn2kGVOpBea8L7zR5mL6CvD1rOaTTJCYQZdKdw rkwg== X-Gm-Message-State: AOAM531u16yV2gqoVoZN8uN5iycPoJMdQV0USihr7vLTezS15bAF8XT0 Uw7ytNou1HtU6QwnrJjOI7Bj+g== X-Google-Smtp-Source: ABdhPJyOMI7hW0MT4rc+sPJaaOP/qfRMySSD6g1w+EwgvOGYBsJQnJu91kNkHUxf4Yw4j4Nk0P3lHw== X-Received: by 2002:aa7:80c9:0:b029:164:4ca1:fff with SMTP id a9-20020aa780c90000b02901644ca10fffmr10793236pfn.11.1604087848603; Fri, 30 Oct 2020 12:57:28 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id o15sm6892640pfd.16.2020.10.30.12.57.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2020 12:57:28 -0700 (PDT) From: Mathieu Poirier To: ohad@wizery.com, bjorn.andersson@linaro.org Cc: linux-remoteproc@vger.kernel.org Subject: [RFC v2 13/14] remoteproc: Add automation flags Date: Fri, 30 Oct 2020 13:57:12 -0600 Message-Id: <20201030195713.1366341-14-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201030195713.1366341-1-mathieu.poirier@linaro.org> References: <20201030195713.1366341-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org Adding flags to dictate how to handle a platform driver being removed or the remote processor crashing while in RPROC_ATTACHED state. Signed-off-by: Mathieu Poirier --- drivers/remoteproc/remoteproc_core.c | 25 +++++++++++++++++++++++++ include/linux/remoteproc.h | 5 +++++ 2 files changed, 30 insertions(+) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 229fa2cad0bd..d024367c63e5 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -2227,6 +2227,29 @@ 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_reboot, remote_crash; + + /* + * 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_reboot" is specified + * in the DT. + */ + core_reboot = of_property_read_bool(np, "autonomous_on_core_reboot"); + rproc->autonomous_on_core_reboot = core_reboot; + + /* + * When the remote processor crashes it will be detached from, and + * attached to, if "autonomous_on_remote_crash" is specified in the DT. + */ + remote_crash = of_property_read_bool(np, "autonomous_on_remote_crash"); + rproc->autonomous_on_core_reboot = core_reboot; +} + /** * rproc_alloc() - allocate a remote processor handle * @dev: the underlying device @@ -2285,6 +2308,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) { diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h index 71d4d4873164..9a6e79ef35d7 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -516,6 +516,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_reboot: 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; @@ -554,6 +557,8 @@ struct rproc { u16 elf_machine; struct cdev cdev; bool cdev_put_on_release; + bool autonomous_on_core_reboot : 1, + autonomous_on_remote_crash : 1; }; /** From patchwork Fri Oct 30 19:57: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: 11870717 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 526BE697 for ; Fri, 30 Oct 2020 19:57:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 290D7206DD for ; Fri, 30 Oct 2020 19:57:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="YNabOr3+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727134AbgJ3T5a (ORCPT ); Fri, 30 Oct 2020 15:57:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726061AbgJ3T5a (ORCPT ); Fri, 30 Oct 2020 15:57:30 -0400 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42EA4C0613CF for ; Fri, 30 Oct 2020 12:57:30 -0700 (PDT) Received: by mail-pf1-x441.google.com with SMTP id a200so6211841pfa.10 for ; Fri, 30 Oct 2020 12:57:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TtNrf4oE1QZKdPj5H3/YLMRhdwk0lWasvYrPepFrEZk=; b=YNabOr3+Y+D0EoKbiTUh2n9y1ILlUvyvbK3xjDnAqYkNSS7k1EQ5Mlgi230rrFNgBA gXQA1pF+3hgYgr1tC4k3J+CHbF779A+iu/ANsY+GW1kv/Uz9am5DbV69VFwjci/GPeg/ sNYgbaeEooJn0L2V5aLu4Mg4aZHf06DFddoX96mJGFNQJx0e1+TPZOTiAMw9rr/RrT7P I4RIlHxb8GlW/+3JaxycYVuYxaG2EJIBDHRVoO1+Crg3WQAu3P40hxJNaazUKLpPZhn3 LirhjhU0tzP4t7ppMVqUvhdQkJolA601ynm0C85HGM++jZkGdzamAuNQLWoOfGaLzyqG DBGg== 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=TtNrf4oE1QZKdPj5H3/YLMRhdwk0lWasvYrPepFrEZk=; b=oiAOU8lWc2S4U9wzsYpTzOdB+t06Y8WtLxBHnm5T+PRNY4+I453TQKNLgYXg5P4fuo ghuf33pxdLRDM5c32XabdRcy14reVTORwKxUXzPl1RgHlTZY5v6YSXG9niGSb7U5rUgG rNCA7NKEPiQB7nYn3GGmp3VtJst9O4ydXCVBdLNKf4pqEwFdCqDtSLxkUEKM8Pzq4Syq Ut4P/GdaQYtRrIylRruHngdqtg+rokcHapvY6e7sRRFo7y0zMtVw4xD+VBtC7+Grh6y6 xi6E73uSrsx5UOMoBByMl//ZgVQ+6/cHvcFJSRjGhzOqnBWEMU6/C5eqrKKjNQsmO0A+ 64uQ== X-Gm-Message-State: AOAM530ehAJJGdAsYG1OqRWZzQZdH/xbq0jVTeWxIOT1dxvBuTQ28J/X Z4aQ11IHQVE4izq8+JD7GpjwZ5AhoXd1azLZ X-Google-Smtp-Source: ABdhPJxIBAqlN9lGflS+FyEF462mVDZsr58w3N76+pigvbzdGjZwRYuZuZ0844pVRrBoyQ14yn4dxw== X-Received: by 2002:aa7:9682:0:b029:160:b81d:d715 with SMTP id f2-20020aa796820000b0290160b81dd715mr10784476pfk.69.1604087849845; Fri, 30 Oct 2020 12:57:29 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id o15sm6892640pfd.16.2020.10.30.12.57.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2020 12:57:29 -0700 (PDT) From: Mathieu Poirier To: ohad@wizery.com, bjorn.andersson@linaro.org Cc: linux-remoteproc@vger.kernel.org Subject: [RFC v2 14/14] remoteproc: Refactor rproc delete and cdev release path Date: Fri, 30 Oct 2020 13:57:13 -0600 Message-Id: <20201030195713.1366341-15-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201030195713.1366341-1-mathieu.poirier@linaro.org> References: <20201030195713.1366341-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 --- drivers/remoteproc/remoteproc_cdev.c | 13 ++++++++++++- drivers/remoteproc/remoteproc_core.c | 12 ++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/drivers/remoteproc/remoteproc_cdev.c b/drivers/remoteproc/remoteproc_cdev.c index 3a3830e27050..2e3f85920e5b 100644 --- a/drivers/remoteproc/remoteproc_cdev.c +++ b/drivers/remoteproc/remoteproc_cdev.c @@ -87,7 +87,18 @@ static int rproc_cdev_release(struct inode *inode, struct file *filp) { struct rproc *rproc = container_of(inode->i_cdev, struct rproc, cdev); - if (rproc->cdev_put_on_release && rproc->state == RPROC_RUNNING) + if (!rproc->cdev_put_on_release) + 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_reboot) + rproc_detach(rproc); + else rproc_shutdown(rproc); return 0; diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index d024367c63e5..9652e543c1ed 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -2393,8 +2393,16 @@ int rproc_del(struct rproc *rproc) 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_reboot) + rproc_detach(rproc); + else + rproc_shutdown(rproc); mutex_lock(&rproc->lock); rproc->state = RPROC_DELETED;