From patchwork Thu Mar 26 16:50:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rishabh Bhatnagar X-Patchwork-Id: 11460629 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0D44481 for ; Thu, 26 Mar 2020 16:50:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D7BDB2073E for ; Thu, 26 Mar 2020 16:50:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=mg.codeaurora.org header.i=@mg.codeaurora.org header.b="l9dSSwxZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727548AbgCZQuw (ORCPT ); Thu, 26 Mar 2020 12:50:52 -0400 Received: from mail26.static.mailgun.info ([104.130.122.26]:23016 "EHLO mail26.static.mailgun.info" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726163AbgCZQuv (ORCPT ); Thu, 26 Mar 2020 12:50:51 -0400 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1585241450; h=References: In-Reply-To: Message-Id: Date: Subject: Cc: To: From: Sender; bh=0MwlHtuDNa/a9rL+GOaesKKAFJQ6knJ6nRxs8znDSGA=; b=l9dSSwxZlwiZVHkXF/HFhMvOGEGH+EcxGO4gxyIptnqWls1L7tBXhi8/irKAEaqbsp10Sf/j Yn5V0PYUtNbsp/RijP/8QaCb8DyOwVHu/JbswPON+z3i7iL9uq4WnG/Lvn9d2AWL8Rbw+fa5 oYPR5IL6EH/Ab0jb+oceRft8iyI= X-Mailgun-Sending-Ip: 104.130.122.26 X-Mailgun-Sid: WyI4ZWZiZiIsICJsaW51eC1yZW1vdGVwcm9jQHZnZXIua2VybmVsLm9yZyIsICJiZTllNGEiXQ== Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by mxa.mailgun.org with ESMTP id 5e7cdd69.7ff84c898420-smtp-out-n03; Thu, 26 Mar 2020 16:50:49 -0000 (UTC) Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 112B0C433D2; Thu, 26 Mar 2020 16:50:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-caf-mail-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=2.0 tests=ALL_TRUSTED,SPF_NONE, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from rishabhb-linux.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: rishabhb) by smtp.codeaurora.org (Postfix) with ESMTPSA id 824CEC43636; Thu, 26 Mar 2020 16:50:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 824CEC43636 Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=none smtp.mailfrom=rishabhb@codeaurora.org From: Rishabh Bhatnagar To: linux-kernel@vger.kernel.org, linux-remoteproc@vger.kernel.org, bjorn.andersson@linaro.org, ohad@wizery.com Cc: psodagud@codeaurora.org, tsoni@codeaurora.org, sidgup@codeaurora.org, Rishabh Bhatnagar Subject: [PATCH 1/2] remoteproc: Add userspace char device driver Date: Thu, 26 Mar 2020 09:50:39 -0700 Message-Id: <1585241440-7572-2-git-send-email-rishabhb@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1585241440-7572-1-git-send-email-rishabhb@codeaurora.org> References: <1585241440-7572-1-git-send-email-rishabhb@codeaurora.org> Sender: linux-remoteproc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org Add the driver for creating the character device interface for userspace applications. The character device interface can be used in order to boot up and shutdown the remote processor. This might be helpful for remote processors that are booted by userspace applications and need to shutdown when the application crahes/shutsdown. Change-Id: If23c8986272bb7c943eb76665f127ff706f12394 Signed-off-by: Rishabh Bhatnagar Reported-by: kbuild test robot --- drivers/remoteproc/Makefile | 1 + drivers/remoteproc/remoteproc_internal.h | 6 +++ drivers/remoteproc/remoteproc_userspace.c | 90 +++++++++++++++++++++++++++++++ include/linux/remoteproc.h | 2 + 4 files changed, 99 insertions(+) create mode 100644 drivers/remoteproc/remoteproc_userspace.c diff --git a/drivers/remoteproc/Makefile b/drivers/remoteproc/Makefile index e30a1b1..facb3fa 100644 --- a/drivers/remoteproc/Makefile +++ b/drivers/remoteproc/Makefile @@ -7,6 +7,7 @@ obj-$(CONFIG_REMOTEPROC) += remoteproc.o remoteproc-y := remoteproc_core.o remoteproc-y += remoteproc_debugfs.o remoteproc-y += remoteproc_sysfs.o +remoteproc-y += remoteproc_userspace.o remoteproc-y += remoteproc_virtio.o remoteproc-y += remoteproc_elf_loader.o obj-$(CONFIG_IMX_REMOTEPROC) += imx_rproc.o diff --git a/drivers/remoteproc/remoteproc_internal.h b/drivers/remoteproc/remoteproc_internal.h index 493ef92..97513ba 100644 --- a/drivers/remoteproc/remoteproc_internal.h +++ b/drivers/remoteproc/remoteproc_internal.h @@ -47,6 +47,9 @@ struct dentry *rproc_create_trace_file(const char *name, struct rproc *rproc, int rproc_init_sysfs(void); void rproc_exit_sysfs(void); +void rproc_init_cdev(void); +void rproc_exit_cdev(void); + void rproc_free_vring(struct rproc_vring *rvring); int rproc_alloc_vring(struct rproc_vdev *rvdev, int i); @@ -63,6 +66,9 @@ struct resource_table *rproc_elf_find_loaded_rsc_table(struct rproc *rproc, struct rproc_mem_entry * rproc_find_carveout_by_name(struct rproc *rproc, const char *name, ...); +/* from remoteproc_userspace.c */ +int rproc_char_device_add(struct rproc *rproc); + static inline int rproc_fw_sanity_check(struct rproc *rproc, const struct firmware *fw) { diff --git a/drivers/remoteproc/remoteproc_userspace.c b/drivers/remoteproc/remoteproc_userspace.c new file mode 100644 index 0000000..2ef7679 --- /dev/null +++ b/drivers/remoteproc/remoteproc_userspace.c @@ -0,0 +1,90 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Character device interface driver for Remoteproc framework. + * + * Copyright (c) 2020, The Linux Foundation. All rights reserved. + */ + +#include +#include +#include +#include +#include + +#include "remoteproc_internal.h" + +#define NUM_RPROC_DEVICES 64 +static dev_t rproc_cdev; +static DEFINE_IDA(cdev_minor_ida); + +static int rproc_open(struct inode *inode, struct file *file) +{ + struct rproc *rproc; + + rproc = container_of(inode->i_cdev, struct rproc, char_dev); + if (!rproc) + return -EINVAL; + + return rproc_boot(rproc); +} + +static int rproc_release(struct inode *inode, struct file *file) +{ + struct rproc *rproc; + + rproc = container_of(inode->i_cdev, struct rproc, char_dev); + if (!rproc) + return -EINVAL; + + rproc_shutdown(rproc); + + return 0; +} + +static const struct file_operations rproc_fops = { + .open = rproc_open, + .release = rproc_release, +}; + +int rproc_char_device_add(struct rproc *rproc) +{ + int ret, minor; + dev_t cdevt; + + minor = ida_simple_get(&cdev_minor_ida, 0, NUM_RPROC_DEVICES, + GFP_KERNEL); + if (minor < 0) { + pr_err("%s: No more minor numbers left! rc:%d\n", __func__, + minor); + return -ENODEV; + } + + cdev_init(&rproc->char_dev, &rproc_fops); + rproc->char_dev.owner = THIS_MODULE; + + cdevt = MKDEV(MAJOR(rproc_cdev), minor); + ret = cdev_add(&rproc->char_dev, cdevt, 1); + if (ret < 0) + ida_simple_remove(&cdev_minor_ida, minor); + + rproc->dev.devt = cdevt; + + return ret; +} + +void __init rproc_init_cdev(void) +{ + int ret; + + ret = alloc_chrdev_region(&rproc_cdev, 0, NUM_RPROC_DEVICES, "rproc"); + if (ret < 0) { + pr_err("Failed to alloc rproc_cdev region, err %d\n", ret); + return; + } +} + +void __exit rproc_exit_cdev(void) +{ + unregister_chrdev_region(MKDEV(MAJOR(rproc_cdev), 0), + NUM_RPROC_DEVICES); +} diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h index 16ad666..c4ca796 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -37,6 +37,7 @@ #include #include +#include #include #include #include @@ -514,6 +515,7 @@ struct rproc { bool auto_boot; struct list_head dump_segments; int nb_vdev; + struct cdev char_dev; }; /** From patchwork Thu Mar 26 16:50:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rishabh Bhatnagar X-Patchwork-Id: 11460631 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2711081 for ; Thu, 26 Mar 2020 16:50:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 001AD2073E for ; Thu, 26 Mar 2020 16:50:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=mg.codeaurora.org header.i=@mg.codeaurora.org header.b="dKQ15067" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727541AbgCZQuu (ORCPT ); Thu, 26 Mar 2020 12:50:50 -0400 Received: from mail26.static.mailgun.info ([104.130.122.26]:50417 "EHLO mail26.static.mailgun.info" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727547AbgCZQuu (ORCPT ); Thu, 26 Mar 2020 12:50:50 -0400 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1585241449; h=References: In-Reply-To: Message-Id: Date: Subject: Cc: To: From: Sender; bh=oRDpgNgHb3P2llPWeY3N6gtLAEuwg4sVWEX58vo5LEE=; b=dKQ15067BzoQ8nkF4uXeDAd8yOdmksxi0PnzGzL1M4i4uXFKK0JvW+yZhru1ABfCu9h6zhAp vSOPYy0alybbHGtyLs40QNs1NPIsq2yuGAck+Ix+dX/3Jm5zkgBGBzooOoqxPgwJckFBi44p ZWoE6N0oAM0VPvZbK/GoUW42PBU= X-Mailgun-Sending-Ip: 104.130.122.26 X-Mailgun-Sid: WyI4ZWZiZiIsICJsaW51eC1yZW1vdGVwcm9jQHZnZXIua2VybmVsLm9yZyIsICJiZTllNGEiXQ== Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by mxa.mailgun.org with ESMTP id 5e7cdd69.7f3685436d50-smtp-out-n02; Thu, 26 Mar 2020 16:50:49 -0000 (UTC) Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 05D5AC433F2; Thu, 26 Mar 2020 16:50:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-caf-mail-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=2.0 tests=ALL_TRUSTED,SPF_NONE, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from rishabhb-linux.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: rishabhb) by smtp.codeaurora.org (Postfix) with ESMTPSA id 12206C433F2; Thu, 26 Mar 2020 16:50:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 12206C433F2 Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=none smtp.mailfrom=rishabhb@codeaurora.org From: Rishabh Bhatnagar To: linux-kernel@vger.kernel.org, linux-remoteproc@vger.kernel.org, bjorn.andersson@linaro.org, ohad@wizery.com Cc: psodagud@codeaurora.org, tsoni@codeaurora.org, sidgup@codeaurora.org, Rishabh Bhatnagar Subject: [PATCH 2/2] remoteproc: core: Register the character device interface Date: Thu, 26 Mar 2020 09:50:40 -0700 Message-Id: <1585241440-7572-3-git-send-email-rishabhb@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1585241440-7572-1-git-send-email-rishabhb@codeaurora.org> References: <1585241440-7572-1-git-send-email-rishabhb@codeaurora.org> Sender: linux-remoteproc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org Add the character device during rproc_add. This would create a character device node at /dev/subsys_. Userspace applications can interact with the remote processor using this interface rather than using sysfs node. To distinguish between different remote processor nodes the device name has been changed to include the rproc name appended to "rproc_" string. Change-Id: I2114f77f8d2b5fd97e281021ec9905ef5c2fb54c Signed-off-by: Rishabh Bhatnagar --- drivers/remoteproc/remoteproc_core.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 097f33e..f657983 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1907,6 +1907,12 @@ int rproc_add(struct rproc *rproc) struct device *dev = &rproc->dev; int ret; + ret = rproc_char_device_add(rproc); + if (ret) { + pr_err("error while adding character device\n"); + return ret; + } + ret = device_add(dev); if (ret < 0) return ret; @@ -2044,7 +2050,7 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, return NULL; } - dev_set_name(&rproc->dev, "remoteproc%d", rproc->index); + dev_set_name(&rproc->dev, "rproc_%s", rproc->name); atomic_set(&rproc->power, 0); @@ -2220,6 +2226,7 @@ static int __init remoteproc_init(void) { rproc_init_sysfs(); rproc_init_debugfs(); + rproc_init_cdev(); return 0; } @@ -2231,6 +2238,7 @@ static void __exit remoteproc_exit(void) rproc_exit_debugfs(); rproc_exit_sysfs(); + rproc_exit_cdev(); } module_exit(remoteproc_exit);