Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3170794imm; Tue, 29 May 2018 02:18:04 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpHoEgYdNAFNSwVeoGyOJlElqMj5jWHFl+h3Q5LmGU/Mfzei16n7D9aY7FsBzwG7vTxHSy3 X-Received: by 2002:a63:3d09:: with SMTP id k9-v6mr13444440pga.142.1527585484665; Tue, 29 May 2018 02:18:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527585484; cv=none; d=google.com; s=arc-20160816; b=DGTymaWiMZ75d8KujCBtfoC5/biU2S0zPCTBh2hEVzhottaWIWMcf/YO3T1U+3UPM3 lO6ZhPAi1AcPrsobC7P1Pawp5rjoERipYZjJM7N5xLm1Xc9bymEFOhphIbxIoqNAyjsW Rfltq1KCcCo4yLAQyLM/gNTpIGD8aetAHyEBF70oBoTAUj0YccOsdXGglWCTRtMtTf1e Q8AjhEis2Qa+NoOayefRpYgpG/+1Pek8pP4l2sMgWIMSHrNN1DPIJPjeIJuZJL76VpsB jTFBNFezp1FfiYAkunHB84zRe6uYBxCJBV1MDiAQwLlao3gLpa9cNFgVaRMYj6oGy+rw xOGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:autocrypt:openpgp:from:references:cc:to:subject :arc-authentication-results; bh=50tGoGWz3WXwpfIoRuc89Zr1Wj+DikQeZee79XQz8FU=; b=xTvmzf0JsqJ+mIB3ZeDMaJIBtnH0SyTvntkNL2yPJkFUp8tQtPQsuMp4ks8NHOvHX2 AgNP+4K6XR6/YVu5Oe1FDI8G9Kpm0SBp6bFH+8LsIiXgzNXYH1tZd3RvsiRNpv0CBhPo fs5dkga+ju2h3/TEL+k7v+I5L/QmLdKbB+mQtNwFqr5L08LPcnoyWnNOjtdwM56mQ/DY r/Y0kO4J3rF8kpunABFryxu//lL0eu8c5CumNcFs+R7sdudI9FLFLPECgPFAUnitLkaZ Z2jnws2y8n7g7UxZ2Dz0QJFHlohwkXiKjKR1iM0dSyajm74bTVCN7R0697TQWHRemATY Vw+g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y12-v6si17838197pgp.24.2018.05.29.02.17.50; Tue, 29 May 2018 02:18:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932761AbeE2JQ4 (ORCPT + 99 others); Tue, 29 May 2018 05:16:56 -0400 Received: from mx07-00178001.pphosted.com ([62.209.51.94]:46299 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932404AbeE2JQY (ORCPT ); Tue, 29 May 2018 05:16:24 -0400 Received: from pps.filterd (m0046668.ppops.net [127.0.0.1]) by mx07-.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id w4T9EPOY013960; Tue, 29 May 2018 11:16:22 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 2j89xpx2pq-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Tue, 29 May 2018 11:16:22 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 2A23938; Tue, 29 May 2018 09:16:22 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag3node1.st.com [10.75.127.7]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 074E016B5; Tue, 29 May 2018 09:16:22 +0000 (GMT) Received: from [10.201.23.162] (10.75.127.47) by SFHDAG3NODE1.st.com (10.75.127.7) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Tue, 29 May 2018 11:16:21 +0200 Subject: Re: [PATCH 5/5] remoteproc: Introduce prepare and unprepare for subdevices To: Alex Elder , , CC: , References: <20180515205345.8090-1-elder@linaro.org> <20180515205345.8090-6-elder@linaro.org> From: Arnaud Pouliquen Openpgp: preference=signencrypt Autocrypt: addr=arnaud.pouliquen@st.com; prefer-encrypt=mutual; keydata= xsFNBFZu+HIBEAC/bt4pnj18oKkUw40q1IXSPeDFOuuznWgFbjFS6Mrb8axwtnxeYicv0WAL rWhlhQ6W2TfKDJtkDygkfaZw7Nlsj57zXrzjVXuy4Vkezxtg7kvSLYItQAE8YFSOrBTL58Yd d5cAFz/9WbWGRf0o9MxFavvGQ9zkfHVd+Ytw6dJNP4DUys9260BoxKZZMaevxobh5Hnram6M gVBYGMuJf5tmkXD/FhxjWEZ5q8pCfqZTlN9IZn7S8d0tyFL7+nkeYldA2DdVplfXXieEEURQ aBjcZ7ZTrzu1X/1RrH1tIQE7dclxk5pr2xY8osNePmxSoi+4DJzpZeQ32U4wAyZ8Hs0i50rS VxZuT2xW7tlNcw147w+kR9+xugXrECo0v1uX7/ysgFnZ/YasN8E+osM2sfa7OYUloVX5KeUK yT58KAVkjUfo0OdtSmGkEkILWQLACFEFVJPz7/I8PisoqzLS4Jb8aXbrwgIg7d4NDgW2FddV X9jd1odJK5N68SZqRF+I8ndttRGK0o7NZHH4hxJg9jvyEELdgQAmjR9Vf0eZGNfowLCnVcLq s+8q3nQ1RrW5cRBgB8YT2kC8wwY5as8fhfp4846pe2b8Akh0+Vba5pXaTvtmdOMRrcS7CtF6 Ogf9zKAxPZxTp0qGUOLE3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UUwD5LKxRfmBWBgK 36tfTyducLyZtGB3mbJYfWeI7aiFgYsd5ehov6OIBlOz5iOshd97+wbbmziYEp6jWMIMX+Em zqSvS5ETZydayO5JBbw7fFBd1nGVYk1WL6Ll72g+iEnqgIckMtxey1TgfT7GhPkR7hl54ZAe 8mOik8I/F6EW8XyQAA2P Message-ID: <3580eff5-56ef-c2a0-c8eb-c27850598587@st.com> Date: Tue, 29 May 2018 11:16:20 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <20180515205345.8090-6-elder@linaro.org> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 8bit X-Originating-IP: [10.75.127.47] X-ClientProxiedBy: SFHDAG5NODE3.st.com (10.75.127.15) To SFHDAG3NODE1.st.com (10.75.127.7) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-05-29_03:,, signatures=0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello Alex, On 05/15/2018 10:53 PM, Alex Elder wrote: > From: Bjorn Andersson > > On rare occasions a subdevice might need to prepare some hardware > resources before a remote processor is booted, and clean up some > state after it has been shut down. > > One such example is the IP Accelerator found in various Qualcomm > platforms, which is accessed directly from both the modem remoteproc > and the application subsystem and requires an intricate lockstep > process when bringing the modem up and down. > > [elder@linaro.org: minor description and comment edits] > > Signed-off-by: Bjorn Andersson > Acked-by: Alex Elder > --- > drivers/remoteproc/remoteproc_core.c | 56 ++++++++++++++++++++++++++-- > include/linux/remoteproc.h | 4 ++ > 2 files changed, 57 insertions(+), 3 deletions(-) > > diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c > index 2ede7ae6f5bc..283b258f5e0f 100644 > --- a/drivers/remoteproc/remoteproc_core.c > +++ b/drivers/remoteproc/remoteproc_core.c > @@ -776,6 +776,30 @@ static int rproc_handle_resources(struct rproc *rproc, > return ret; > } > > +static int rproc_prepare_subdevices(struct rproc *rproc) > +{ > + struct rproc_subdev *subdev; > + int ret; > + > + list_for_each_entry(subdev, &rproc->subdevs, node) { > + if (subdev->prepare) { > + ret = subdev->prepare(subdev); > + if (ret) > + goto unroll_preparation; > + } > + } > + > + return 0; > + > +unroll_preparation: > + list_for_each_entry_continue_reverse(subdev, &rproc->subdevs, node) { > + if (subdev->unprepare) > + subdev->unprepare(subdev); > + } Here you could call rproc_unprepare_subdevices instead of duplicating the code. regards Arnaud > + > + return ret; > +} > + > static int rproc_start_subdevices(struct rproc *rproc) > { > struct rproc_subdev *subdev; > @@ -810,6 +834,16 @@ static void rproc_stop_subdevices(struct rproc *rproc, bool crashed) > } > } > > +static void rproc_unprepare_subdevices(struct rproc *rproc) > +{ > + struct rproc_subdev *subdev; > + > + list_for_each_entry_reverse(subdev, &rproc->subdevs, node) { > + if (subdev->unprepare) > + subdev->unprepare(subdev); > + } > +} > + > /** > * rproc_coredump_cleanup() - clean up dump_segments list > * @rproc: the remote processor handle > @@ -902,11 +936,18 @@ static int rproc_start(struct rproc *rproc, const struct firmware *fw) > rproc->table_ptr = loaded_table; > } > > + ret = rproc_prepare_subdevices(rproc); > + if (ret) { > + dev_err(dev, "failed to prepare subdevices for %s: %d\n", > + rproc->name, ret); > + return ret; > + } > + > /* power up the remote processor */ > ret = rproc->ops->start(rproc); > if (ret) { > dev_err(dev, "can't start rproc %s: %d\n", rproc->name, ret); > - return ret; > + goto unprepare_subdevices; > } > > /* Start any subdevices for the remote processor */ > @@ -914,8 +955,7 @@ static int rproc_start(struct rproc *rproc, const struct firmware *fw) > if (ret) { > dev_err(dev, "failed to probe subdevices for %s: %d\n", > rproc->name, ret); > - rproc->ops->stop(rproc); > - return ret; > + goto stop_rproc; > } > > rproc->state = RPROC_RUNNING; > @@ -923,6 +963,14 @@ static int rproc_start(struct rproc *rproc, const struct firmware *fw) > dev_info(dev, "remote processor %s is now up\n", rproc->name); > > return 0; > + > +stop_rproc: > + rproc->ops->stop(rproc); > + > +unprepare_subdevices: > + rproc_unprepare_subdevices(rproc); > + > + return ret; > } > > /* > @@ -1035,6 +1083,8 @@ static int rproc_stop(struct rproc *rproc, bool crashed) > return ret; > } > > + rproc_unprepare_subdevices(rproc); > + > rproc->state = RPROC_OFFLINE; > > dev_info(dev, "stopped remote processor %s\n", rproc->name); > diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h > index 8f1426330cca..e3c5d856b6da 100644 > --- a/include/linux/remoteproc.h > +++ b/include/linux/remoteproc.h > @@ -477,15 +477,19 @@ struct rproc { > /** > * struct rproc_subdev - subdevice tied to a remoteproc > * @node: list node related to the rproc subdevs list > + * @prepare: prepare function, called before the rproc is started > * @start: start function, called after the rproc has been started > * @stop: stop function, called before the rproc is stopped; the @crashed > * parameter indicates if this originates from a recovery > + * @unprepare: unprepare function, called after the rproc has been stopped > */ > struct rproc_subdev { > struct list_head node; > > + int (*prepare)(struct rproc_subdev *subdev); > int (*start)(struct rproc_subdev *subdev); > void (*stop)(struct rproc_subdev *subdev, bool crashed); > + void (*unprepare)(struct rproc_subdev *subdev); > }; > > /* we currently support only two vrings per rvdev */ >