Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2552130pxb; Thu, 11 Feb 2021 15:54:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJzGUsAYBRflOUJlhJt7YjijvVwS26axUb3yAiAzTb1AbzcE4ji5Xp3vKs6WzBqpLIpQ+Tvf X-Received: by 2002:a05:6402:4d3:: with SMTP id n19mr645858edw.2.1613087698301; Thu, 11 Feb 2021 15:54:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613087698; cv=none; d=google.com; s=arc-20160816; b=JmpkEwnRT1vqc5sdSNNfcKWxeAq13MQauCIfVP+uXxHyabiCqcFrfidrMo0RckPXRZ yW2Xhm+A+/heLz/pEIOIusifxElVUxz3FqjnVubkImP7JcfJw4JATBNqTB4J9ujbclzF /xdGR6zmhdz8Kh4deS0MMvrYjrl+1CFnEy6ZApj6jTlfR0Dc01bbJmw+W9Lk1XvQMk9i smcVrUVMg19OaDjXjb5qn8SVA4ZoRzp78s6oSDpHHMckqhX9NCbDPJyV01ICXszxWpN2 qjIDyhL3WdO1NTYP6aee2PeA2WvEziTR63wZrUp4YnwXX8zuz6S4s3+5dTTaBWbAm0DJ GomQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=+0I2FxbDSsv8cQH5eSoJMFXvbpy5lOFWxMK2CkAG6co=; b=aCLa/dJvqpr6RPjLWslbsFNdzQ6PEMbA5Xf+e7a1wxzXI8AymvZ17Fl+5LWrjvHt+s OmnTapGY58FemBAPsVYS790baw4gBlV/U9W3bp5mwn85hF17UUFU+4W3XaZQWEoq5Kgd 6+PZ04sOTrAvJ5KilbV4loKflZ8eTzanthKjtl+EOxIqb3DvR9ds2I/LgCeOfqWwce71 IN7o4zWgZ2L9ivkHsdIF0Y1x/iZVoDahUE9UvrcRlgDU4oigloh4Lhb+wCdRtyOfcGtj SgROz2/SSrROR52EYatwkbUpXGCW+74lCRiCGsfn/BgGlL9o1SbtGJg9Lx8iOaf/aAf/ dszA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bCIeixkz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gx20si4769823ejb.599.2021.02.11.15.54.35; Thu, 11 Feb 2021 15:54:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bCIeixkz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230268AbhBKXx3 (ORCPT + 99 others); Thu, 11 Feb 2021 18:53:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230436AbhBKXue (ORCPT ); Thu, 11 Feb 2021 18:50:34 -0500 Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31CE9C0698CD for ; Thu, 11 Feb 2021 15:46:59 -0800 (PST) Received: by mail-pf1-x42a.google.com with SMTP id d26so4729505pfn.5 for ; Thu, 11 Feb 2021 15:46:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+0I2FxbDSsv8cQH5eSoJMFXvbpy5lOFWxMK2CkAG6co=; b=bCIeixkzJNEwVKPQsDrd499M79NaeE/5Qcm8AI5oQBm3ldjySTUXAI2Yb/sB8Az5KO doVYzyeXIzSQscA7IcfTX6pqSTsG3UzH5xq4y4IDFSYxckfc5zbkYFNFqSbw81BDqN3L DJQA1lArwqCBBC/3eTbYQX+QZ0OAiw7/JRCyRg2RU4nNjdyj9uk7sO56xiTRtcU6gDxN eBTuifKnwUKvCjQxcFxfkj1Ao0A1lf0yyijzVZhzjYslwrmfNQngmRJb55aIZxitGS/f vUw9efVAkFB5qXuBj8soe1CF+xGaUG74HAMBEc7h+3vo+/GyDGNZDsAbM1fmin0eVsvA acyg== 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=+0I2FxbDSsv8cQH5eSoJMFXvbpy5lOFWxMK2CkAG6co=; b=WeacKfLUXxU9q4BTU5r1636QDpLypDQpJgOY3V/qu7qYiZgGF9QrvqQ6HFzbdpSNYF OdxQ0rcFsAL2VlfKP16oDsn9DprqLJZp+uhkH3cEVDZJ68vfzcsG+X2KnmbxcRe43nlV 1/vjY3eMR6g99OZQfo3Phh8vLMRoYAkcGgUSCJAccnufouDd0jlhtZCuBLuQfzHEnkGW kpnRjW9zjResjG9zrjU8HtAMsDjdQtXZ1iPbujejbhdbTZCYIuv1ETLKpCGJT+tfoE5I 3fFt9Fv2aCfF09xB+vo4z7vMyEQL+lPuNhcLJITE1nMgb8t/qYsY/TFjBA78uajervUr vUmw== X-Gm-Message-State: AOAM531u62iAeunSRKp4NO0nOH1el6ckeMXieafgpTiCj1VTgD2NTezH J1UU+eR8s2EIOqg2Iw4xiICo/Q== X-Received: by 2002:aa7:9ab2:0:b029:1e3:c753:acd8 with SMTP id x18-20020aa79ab20000b02901e3c753acd8mr370600pfi.44.1613087218700; Thu, 11 Feb 2021 15:46:58 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id iq6sm5932740pjb.6.2021.02.11.15.46.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Feb 2021 15:46:58 -0800 (PST) From: Mathieu Poirier To: ohad@wizery.com, bjorn.andersson@linaro.org, arnaud.pouliquen@st.com Cc: robh+dt@kernel.org, mcoquelin.stm32@gmail.com, alexandre.torgue@st.com, linux-remoteproc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v5 19/19] remoteproc: Refactor rproc delete and cdev release path Date: Thu, 11 Feb 2021 16:46:27 -0700 Message-Id: <20210211234627.2669674-20-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210211234627.2669674-1-mathieu.poirier@linaro.org> References: <20210211234627.2669674-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 12bd177aa8cd..36b3592caf34 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -2413,6 +2413,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 @@ -2471,6 +2487,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) { @@ -2547,15 +2565,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; @@ -2574,7 +2602,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 5b49c4018e90..bd3ac6a47e47 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -524,6 +524,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; @@ -563,6 +566,7 @@ struct rproc { u16 elf_machine; struct cdev cdev; bool cdev_put_on_release; + bool autonomous_on_core_shutdown; }; /** -- 2.25.1