Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1158784pxu; Fri, 27 Nov 2020 00:47:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJxhtzvWKfRg8Pb6AeHfz+1EZXSqEVJa5qKVyX6hkdLJZu0IROss/oQFHFoA894QZY4YH20r X-Received: by 2002:a50:f30f:: with SMTP id p15mr6674767edm.4.1606466823051; Fri, 27 Nov 2020 00:47:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606466823; cv=none; d=google.com; s=arc-20160816; b=hwm45IFCKJ5d/wB/fZ5bIyBK+cC7f/sIVnHTHnHafIw86dy2ttWIXhPo1zfoHs7uTO J7UuUGqsRKPHoSjLnXKGjb3IZ1HMIFJf4IP+8IfkxxxYLarnKuvJfmbpCoRAirm+TBBU MRql7vf/lWW2nBNhB8mRXOnemW5QJW57JjRv7mGLp9LaLlAp+yP2caIA/pct7LEOx+r9 9jFHaqbQZQrPr88Y4LT8iTA5Gx6UlXKKGOvCroimkzKsjH2TP0kgVA1Sq+6V2BFQUiht 0lAyWJ5vMO+BkX48WfnJF6BPobpwPTpNoSru1i2NImnBM1bPISjAJh20wUZd4FKn1aRs EcKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=KivtPfxR+vLpQVUyPc6p5f+5FGXcViNdHdMf/M3HDLo=; b=MgVo1Hq8xrbib97mzsbkTUm5EbzGUwoqIdKgaTCoETa9B90TlmMLzkcsWgwZXnTLlX 7r8PYCqOGeEeK8/GbxYpON+N1yEBJtTW/XBctFD4Szin7LBf4HigdXvWj/Q3ckQqsLqj dU0LuetW1OSSAC6ywn5zLNCEEmcdxqMwq34uMhGX0cp7LLU0QaXB8K6myocJuFZ71Jjz EeypgDTqtW6VPFI0wCJpTRb3G1hplMtr6KCwmdUbKAhTy/ArWzAhN0r8HswSth4eaTme ghba+qHh6tOiV8q+ablfgBx/e/Svz6FjLbGonj1SBZ+lcekdyl++/AUwjrVs1DB/96RV MuMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=P1ayCxye; 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 j9si2420546ejo.609.2020.11.27.00.46.40; Fri, 27 Nov 2020 00:47:03 -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=P1ayCxye; 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 S2389225AbgKZW4w (ORCPT + 99 others); Thu, 26 Nov 2020 17:56:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388304AbgKZW4v (ORCPT ); Thu, 26 Nov 2020 17:56:51 -0500 Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49071C0613D4 for ; Thu, 26 Nov 2020 14:56:50 -0800 (PST) Received: by mail-pg1-x541.google.com with SMTP id f17so2751451pge.6 for ; Thu, 26 Nov 2020 14:56:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=KivtPfxR+vLpQVUyPc6p5f+5FGXcViNdHdMf/M3HDLo=; b=P1ayCxyeLlfeq2jtT8unukIoa/x5V+eBQ9HFPJ+lmZ2ulyXRUwUUb30OX22s9pX6zy 9voFEKAlhRcDDwM12cr5Rh0v0D7AHePVdT24Z6JILZcZY4hTmQPR5uh23Lr+sxoloTPV hzR3+4bLPavJ/yi1Bzn/2MLeSU8noDH2xO7qfDzTS2vSgkikvUGdV8w2FdiCXfjDmkqX 37GfIQQcmNsoL2c0+0pQ92WET3KlCS+rQbJiST8kLyuIok6PaIu2VpZxkhVxHlMpwr1n OQ5bd9kD4/VvERdSSLsAFte5Wm45xSynAWIhWWb7L69TBxkbSJIC5Pz5U8ORZmr7FaTT risQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=KivtPfxR+vLpQVUyPc6p5f+5FGXcViNdHdMf/M3HDLo=; b=sFBYOjwMl7E6f8tdM3QazvturLpt8GdUfizCCkxlFEH/pfSWorPFKvmuFRjY7XVb5i kgcINdSzy6R9Nu4pQ1KnXH4gRlL+UwuiNifJ+fibMyR81FR3BdQ2Jck5NPzs8TWA35+a hBezRRhZjjcK+ov2HvlFPXQ2bErgXpLscWi4gqSFRFWaIYCiRGrFa87LSZvnOtOjny3s l2uF+F7k/0gVEfZDggT10uo4HsL+sF/hDsMS+5XpAVjX3gboW8eWsxnTQn0hBU/vGwMI E/wPmRQBhT9nYxivjMWGnmMwj/1d8ltpiqGo+o5fjphTZOn6szfczUJiATUuNe2R/3tA 0CNw== X-Gm-Message-State: AOAM532O+a/5HPsdTg6dwQXdg5kpgkeu+Gfi7uMs2qSDWaOeB/obTTGK emU7apS1zt3l7pG8Sz0VN6PoIEzDI3TpwI8X X-Received: by 2002:aa7:9434:0:b029:18c:1c6a:2e0a with SMTP id y20-20020aa794340000b029018c1c6a2e0amr4439182pfo.8.1606431409634; Thu, 26 Nov 2020 14:56:49 -0800 (PST) Received: from xps15 (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id e5sm3685409pjl.51.2020.11.26.14.56.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Nov 2020 14:56:48 -0800 (PST) Date: Thu, 26 Nov 2020 15:56:47 -0700 From: Mathieu Poirier To: Suman Anna Cc: Bjorn Andersson , Grzegorz Jaszczyk , linux-remoteproc@vger.kernel.org, linux-omap@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] remoteproc: Add a rproc_set_firmware() API Message-ID: <20201126225647.GB897651@xps15> References: <20201121032042.6195-1-s-anna@ti.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201121032042.6195-1-s-anna@ti.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Nov 20, 2020 at 09:20:42PM -0600, Suman Anna wrote: > A new API, rproc_set_firmware() is added to allow the remoteproc platform > drivers and remoteproc client drivers to be able to configure a custom > firmware name that is different from the default name used during > remoteproc registration. This function is being introduced to provide > a kernel-level equivalent of the current sysfs interface to remoteproc > client drivers, and can only change firmwares when the remoteproc is > offline. This allows some remoteproc drivers to choose different firmwares > at runtime based on the functionality the remote processor is providing. > The TI PRU Ethernet driver will be an example of such usage as it > requires to use different firmwares for different supported protocols. > > Also, update the firmware_store() function used by the sysfs interface > to reuse this function to avoid code duplication. > > Signed-off-by: Suman Anna > --- > drivers/remoteproc/remoteproc_core.c | 63 +++++++++++++++++++++++++++ > drivers/remoteproc/remoteproc_sysfs.c | 33 +------------- > include/linux/remoteproc.h | 1 + > 3 files changed, 66 insertions(+), 31 deletions(-) > > diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c > index dab2c0f5caf0..46c2937ebea9 100644 > --- a/drivers/remoteproc/remoteproc_core.c > +++ b/drivers/remoteproc/remoteproc_core.c > @@ -1934,6 +1934,69 @@ struct rproc *rproc_get_by_phandle(phandle phandle) > #endif > EXPORT_SYMBOL(rproc_get_by_phandle); > > +/** > + * rproc_set_firmware() - assign a new firmware > + * @rproc: rproc handle to which the new firmware is being assigned > + * @fw_name: new firmware name to be assigned > + * > + * This function allows remoteproc drivers or clients to configure a custom > + * firmware name that is different from the default name used during remoteproc > + * registration. The function does not trigger a remote processor boot, > + * only sets the firmware name used for a subsequent boot. This function > + * should also be called only when the remote processor is offline. > + * > + * This allows either the userspace to configure a different name through > + * sysfs or a kernel-level remoteproc or a remoteproc client driver to set > + * a specific firmware when it is controlling the boot and shutdown of the > + * remote processor. > + * > + * Return: 0 on success or a negative value upon failure > + */ > +int rproc_set_firmware(struct rproc *rproc, const char *fw_name) > +{ > + struct device *dev; > + int ret, len; > + char *p; > + > + if (!rproc || !fw_name) > + return -EINVAL; > + > + dev = rproc->dev.parent; Since rproc->dev is available might as well use it. This is what the current implementation does. The side effect are only cosmetic though so with or without the change: Reviewed-by: Mathieu Poirier > + > + ret = mutex_lock_interruptible(&rproc->lock); > + if (ret) { > + dev_err(dev, "can't lock rproc %s: %d\n", rproc->name, ret); > + return -EINVAL; > + } > + > + if (rproc->state != RPROC_OFFLINE) { > + dev_err(dev, "can't change firmware while running\n"); > + ret = -EBUSY; > + goto out; > + } > + > + len = strcspn(fw_name, "\n"); > + if (!len) { > + dev_err(dev, "can't provide empty string for firmware name\n"); > + ret = -EINVAL; > + goto out; > + } > + > + p = kstrndup(fw_name, len, GFP_KERNEL); > + if (!p) { > + ret = -ENOMEM; > + goto out; > + } > + > + kfree(rproc->firmware); > + rproc->firmware = p; > + > +out: > + mutex_unlock(&rproc->lock); > + return ret; > +} > +EXPORT_SYMBOL(rproc_set_firmware); > + > static int rproc_validate(struct rproc *rproc) > { > switch (rproc->state) { > diff --git a/drivers/remoteproc/remoteproc_sysfs.c b/drivers/remoteproc/remoteproc_sysfs.c > index 3fd18a71c188..cf846caf2e1a 100644 > --- a/drivers/remoteproc/remoteproc_sysfs.c > +++ b/drivers/remoteproc/remoteproc_sysfs.c > @@ -159,42 +159,13 @@ static ssize_t firmware_store(struct device *dev, > const char *buf, size_t count) > { > struct rproc *rproc = to_rproc(dev); > - char *p; > - int err, len = count; > + int err; > > /* restrict sysfs operations if not allowed by remoteproc drivers */ > if (rproc->deny_sysfs_ops) > return -EPERM; > > - err = mutex_lock_interruptible(&rproc->lock); > - if (err) { > - dev_err(dev, "can't lock rproc %s: %d\n", rproc->name, err); > - return -EINVAL; > - } > - > - if (rproc->state != RPROC_OFFLINE) { > - dev_err(dev, "can't change firmware while running\n"); > - err = -EBUSY; > - goto out; > - } > - > - len = strcspn(buf, "\n"); > - if (!len) { > - dev_err(dev, "can't provide a NULL firmware\n"); > - err = -EINVAL; > - goto out; > - } > - > - p = kstrndup(buf, len, GFP_KERNEL); > - if (!p) { > - err = -ENOMEM; > - goto out; > - } > - > - kfree(rproc->firmware); > - rproc->firmware = p; > -out: > - mutex_unlock(&rproc->lock); > + err = rproc_set_firmware(rproc, buf); > > return err ? err : count; > } > diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h > index dbc3767f7d0e..6e04b99413f8 100644 > --- a/include/linux/remoteproc.h > +++ b/include/linux/remoteproc.h > @@ -655,6 +655,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_set_firmware(struct rproc *rproc, const char *fw_name); > void rproc_report_crash(struct rproc *rproc, enum rproc_crash_type type); > int rproc_coredump_add_segment(struct rproc *rproc, dma_addr_t da, size_t size); > int rproc_coredump_add_custom_segment(struct rproc *rproc, > -- > 2.28.0 >