Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5435670imu; Sun, 25 Nov 2018 23:54:03 -0800 (PST) X-Google-Smtp-Source: AFSGD/WYdLItnDl5cEcq7gOfAbOOmEUO+UNE/CX84i8mXOd1FNQyVwDEccn9zmyPbN5kfncooB6i X-Received: by 2002:a63:b218:: with SMTP id x24mr23033633pge.223.1543218843444; Sun, 25 Nov 2018 23:54:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543218843; cv=none; d=google.com; s=arc-20160816; b=zZ3nYc9B7EXjssddaaLIEHy6C/OkQEQAYls7GEsOGxyAbcCEywW4jL3rkr4ftC9Zyt IOuJ8HFstuLrl5jYQt+Ho0S38xz409yRRhRWGj4BN0JP5WRwb4krIeFN18omhyDVyH+g EcPGIJObQF5nTghh6d6F0zLTIHkEphXQRIhQkmsWtPA7qi/TKHr4r8+2e5l82bde5MZd Dtcs/Zh11RIkZvRCpFByF6PbBYa5SRaJJrsMxffd5TDJe2YeiIYZfI19Kvv6aPMy2T+K E39AVHn3QmSYyOwPu10OjzMote89JgGsULqikkp7B835Zg9PaA2MG6XH87d/bydU6eWo HlkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=3g8PnxtfE4Aj4rp7f1734/PSgrBTxF/lNlXn7HscNMI=; b=GslEko38+FJSfkkUvNcrGNuexeiMg1dlPPo/ILjvt1HBUmZW2q3d9dLuKXht1eneeP 0tYvh9Wy3A13t/TAndnGyIPXJcJyikF3c+Mf0lA+BEHJXVQGICZ1KyFqggVnvEVlhtcB +4TytkT5cv07Jv8KnOInGVZyrZizlRK0GNOxBGR5PSZG0NFLYUiiNJZM/wBonV5es42i ajWqTIg/ELI2BnxoJEHffgMUEcA3RgDQAN7wnXtpgxX7aiS/AFKYKCBk8JFFROKt3w9Z Th4d51DeIQCsagsMjIpNDmR98d8jpMcrxQN8Vn+/KGjgDaRGvq/YoNAezXI5uQ1ankBu vs2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b="a7FL/XzJ"; 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; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x10si60001579pgl.209.2018.11.25.23.53.48; Sun, 25 Nov 2018 23:54:03 -0800 (PST) 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; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b="a7FL/XzJ"; 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; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726437AbeKZSqZ (ORCPT + 99 others); Mon, 26 Nov 2018 13:46:25 -0500 Received: from lelv0143.ext.ti.com ([198.47.23.248]:39958 "EHLO lelv0143.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726390AbeKZSqY (ORCPT ); Mon, 26 Nov 2018 13:46:24 -0500 Received: from lelv0265.itg.ti.com ([10.180.67.224]) by lelv0143.ext.ti.com (8.15.2/8.15.2) with ESMTP id wAQ7r4VH060646; Mon, 26 Nov 2018 01:53:04 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1543218784; bh=3g8PnxtfE4Aj4rp7f1734/PSgrBTxF/lNlXn7HscNMI=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=a7FL/XzJgwrBHPEEhC6Us4fv+hlJBVbDqOR66dt+/my3ao4z1Bav4oyQYuNoKJuOM m7SDVfyJInOkU46xbGN1XU/RWZZJpGShLq3sJ/j9ZW3wKgMlm5+tVF4yMQnQLgKnKl un6M2ozJIFdjRBbBQ9I0FyMPor2TxPUkhZsPCzjE= Received: from DLEE103.ent.ti.com (dlee103.ent.ti.com [157.170.170.33]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id wAQ7r4GI037908 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 26 Nov 2018 01:53:04 -0600 Received: from DLEE101.ent.ti.com (157.170.170.31) by DLEE103.ent.ti.com (157.170.170.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1591.10; Mon, 26 Nov 2018 01:53:02 -0600 Received: from dlep33.itg.ti.com (157.170.170.75) by DLEE101.ent.ti.com (157.170.170.31) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1591.10 via Frontend Transport; Mon, 26 Nov 2018 01:53:02 -0600 Received: from dlelxv97.itg.ti.com (dlelxv97.itg.ti.com [172.17.2.193]) by dlep33.itg.ti.com (8.14.3/8.13.8) with ESMTP id wAQ7r2pP019403; Mon, 26 Nov 2018 01:53:02 -0600 Received: from localhost.localdomain (vboxa0400828d.dhcp.ti.com [172.22.237.3]) by dlelxv97.itg.ti.com (8.14.3/8.13.8) with ESMTP id wAQ7qn1G024490; Mon, 26 Nov 2018 01:52:58 -0600 From: Roger Quadros To: , CC: , , , , , , , , , , , , , , , Subject: [PATCH 02/16] remoteproc: Add a rproc_set_firmware() API Date: Mon, 26 Nov 2018 09:52:35 +0200 Message-ID: <1543218769-5507-3-git-send-email-rogerq@ti.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1543218769-5507-1-git-send-email-rogerq@ti.com> References: <1543218769-5507-1-git-send-email-rogerq@ti.com> MIME-Version: 1.0 Content-Type: text/plain X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Suman Anna 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. This allows some remoteproc drivers to choose different firmwares at runtime when the remote processor is not running based on the functional feature it is providing using that remote processor. 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 | 61 +++++++++++++++++++++++++++++++++++ drivers/remoteproc/remoteproc_sysfs.c | 33 ++----------------- include/linux/remoteproc.h | 1 + 3 files changed, 64 insertions(+), 31 deletions(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 39458a7..581e6e8 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -2151,6 +2151,67 @@ void rproc_report_crash(struct rproc *rproc, enum rproc_crash_type type) } EXPORT_SYMBOL(rproc_report_crash); +/** + * 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. + * + * Returns 0 on success or a negative value upon failure + */ +int rproc_set_firmware(struct rproc *rproc, const char *fw_name) +{ + struct device *dev = rproc->dev.parent; + int ret, len; + char *p; + + if (!rproc || !fw_name) + return -EINVAL; + + 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 a NULL firmware\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 __init remoteproc_init(void) { rproc_init_sysfs(); diff --git a/drivers/remoteproc/remoteproc_sysfs.c b/drivers/remoteproc/remoteproc_sysfs.c index 3a4c3d7..6cf04a7 100644 --- a/drivers/remoteproc/remoteproc_sysfs.c +++ b/drivers/remoteproc/remoteproc_sysfs.c @@ -32,38 +32,9 @@ 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; - 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 9e01a44..063468b 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -604,6 +604,7 @@ rproc_of_resm_mem_entry_init(struct device *dev, u32 of_resm_idx, int 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, -- Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki