Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp399814ybk; Fri, 15 May 2020 03:48:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy960kEw3pByPL1tVyntfyiAPfBzYLHKUO2oZVi/hLrepSnWekOZZVUQCVh+UZltaJXD/Mw X-Received: by 2002:a17:906:fb0e:: with SMTP id lz14mr2166765ejb.237.1589539680179; Fri, 15 May 2020 03:48:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589539680; cv=none; d=google.com; s=arc-20160816; b=bn4unHsM/TWQOMbyK2TWT61I9sSIm15eSx+YVP+lKccajOd0N2TmwsKZih9Z0dGWaD nwGt5tKFaHfPFJP64Lzrusdw/3u29b+bj5pRwJI6l9IZmnKuiNyFmYiyyDYDJEbvw/pk leKV/SzsfakjgpRcghG2huXrinPCQ40NLfZmOunx4Y8ESvkjdHqAys+hc4FsaUEnqRSY Z9t2WO6U/B9pzuF+6ETPIVYHHYFBDBDfQw2A92/ixYfOvmXr/zMAHP671h6plb6OtwdW 79yC1Cus2HOd3mhxlE3jteSkzv5ZQCi9w016ac7atj7F9R+ANB7jTVRd+LmC4tQTvQFs Im7g== 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:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=uMoSFxE1HAT004D0LAk6GHlJldx5Vsx+cEoqJH5QPsk=; b=TY5pWYEJ3wL+PeVKpBpPefRP8l5xH1jyr6XWtEQ98dL+i85x7ovhrDTfT0eNwQlHQN rZKRdk4QbQoADnVGiCx5RppA/zsC9yCX5QUEF21i31WPK40iOTio3Mb1fnJtYX6txSD6 XLCjLWv+ZJ7AR00CzrdGsv0mPxCr7wfCQmOdmDlzJa0jWs4DY1/mGT4rzWU6AoVw2zUe /USy0i6/xyBcryqz1b+MX4/kNgyxK9xTbAMW8wyAar37VVYUjZUL2Gpt/pNUqwU90Wqr 9TkNsq4gB7aGVYrMFcklfJiigdT2YF9WFXsgG20HOybtYbsWVkpakKIdLuX9nRoYogLh 4nHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@crapouillou.net header.s=mail header.b="KL86JpV/"; 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=fail (p=NONE sp=NONE dis=NONE) header.from=crapouillou.net Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i18si1041525ejk.81.2020.05.15.03.47.36; Fri, 15 May 2020 03:48:00 -0700 (PDT) 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=fail header.i=@crapouillou.net header.s=mail header.b="KL86JpV/"; 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=fail (p=NONE sp=NONE dis=NONE) header.from=crapouillou.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728326AbgEOKn5 (ORCPT + 99 others); Fri, 15 May 2020 06:43:57 -0400 Received: from outils.crapouillou.net ([89.234.176.41]:41492 "EHLO crapouillou.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728013AbgEOKn4 (ORCPT ); Fri, 15 May 2020 06:43:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=crapouillou.net; s=mail; t=1589539426; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uMoSFxE1HAT004D0LAk6GHlJldx5Vsx+cEoqJH5QPsk=; b=KL86JpV/5wViERrHFIJtZYx6A0OwXo6PE0deNJQTcBBgrLX8JjN6rp3GOua5q551GlaP4Y v/8iCGzwikaF1CBk52w46rNqyxu61L+ue/u8f+JVKgmcuw4EuFpl691Fj7FP+va38dvESO 3bVa4ICp5LHxX87iqHn7cQaQ5PhryZY= From: Paul Cercueil To: Bjorn Andersson , Ohad Ben-Cohen , Arnaud Pouliquen Cc: od@zcrc.me, linux-remoteproc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Paul Cercueil Subject: [PATCH v7 2/5] remoteproc: Add device-managed variants of rproc_alloc/rproc_add Date: Fri, 15 May 2020 12:43:37 +0200 Message-Id: <20200515104340.10473-2-paul@crapouillou.net> In-Reply-To: <20200515104340.10473-1-paul@crapouillou.net> References: <20200515104340.10473-1-paul@crapouillou.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add API functions devm_rproc_alloc() and devm_rproc_add(), which behave like rproc_alloc() and rproc_add() respectively, but register their respective cleanup function to be called on driver detach. Signed-off-by: Paul Cercueil Reviewed-by: Bjorn Andersson --- Notes: v3: New patch v4: No change v5: - Fix return value documentation - Fix typo in documentation v6-v7: No change drivers/remoteproc/remoteproc_core.c | 67 ++++++++++++++++++++++++++++ include/linux/remoteproc.h | 5 +++ 2 files changed, 72 insertions(+) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index e12a54e67588..a7f96bc98406 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1949,6 +1949,33 @@ int rproc_add(struct rproc *rproc) } EXPORT_SYMBOL(rproc_add); +static void devm_rproc_remove(void *rproc) +{ + rproc_del(rproc); +} + +/** + * devm_rproc_add() - resource managed rproc_add() + * @dev: the underlying device + * @rproc: the remote processor handle to register + * + * This function performs like rproc_add() but the registered rproc device will + * automatically be removed on driver detach. + * + * Returns: 0 on success, negative errno on failure + */ +int devm_rproc_add(struct device *dev, struct rproc *rproc) +{ + int err; + + err = rproc_add(rproc); + if (err) + return err; + + return devm_add_action_or_reset(dev, devm_rproc_remove, rproc); +} +EXPORT_SYMBOL(devm_rproc_add); + /** * rproc_type_release() - release a remote processor instance * @dev: the rproc's device @@ -2171,6 +2198,46 @@ int rproc_del(struct rproc *rproc) } EXPORT_SYMBOL(rproc_del); +static void devm_rproc_free(struct device *dev, void *res) +{ + rproc_free(*(struct rproc **)res); +} + +/** + * devm_rproc_alloc() - resource managed rproc_alloc() + * @dev: the underlying device + * @name: name of this remote processor + * @ops: platform-specific handlers (mainly start/stop) + * @firmware: name of firmware file to load, can be NULL + * @len: length of private data needed by the rproc driver (in bytes) + * + * This function performs like rproc_alloc() but the acquired rproc device will + * automatically be released on driver detach. + * + * Returns: new rproc instance, or NULL on failure + */ +struct rproc *devm_rproc_alloc(struct device *dev, const char *name, + const struct rproc_ops *ops, + const char *firmware, int len) +{ + struct rproc **ptr, *rproc; + + ptr = devres_alloc(devm_rproc_free, sizeof(*ptr), GFP_KERNEL); + if (!ptr) + return ERR_PTR(-ENOMEM); + + rproc = rproc_alloc(dev, name, ops, firmware, len); + if (rproc) { + *ptr = rproc; + devres_add(dev, ptr); + } else { + devres_free(ptr); + } + + return rproc; +} +EXPORT_SYMBOL(devm_rproc_alloc); + /** * rproc_add_subdev() - add a subdevice to a remoteproc * @rproc: rproc handle to add the subdevice to diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h index 9c07d7958c53..8c9c0dda03c3 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -599,6 +599,11 @@ int rproc_add(struct rproc *rproc); int rproc_del(struct rproc *rproc); void rproc_free(struct rproc *rproc); +struct rproc *devm_rproc_alloc(struct device *dev, const char *name, + const struct rproc_ops *ops, + const char *firmware, int len); +int devm_rproc_add(struct device *dev, struct rproc *rproc); + void rproc_add_carveout(struct rproc *rproc, struct rproc_mem_entry *mem); struct rproc_mem_entry * -- 2.26.2