From patchwork Thu Aug 3 02:57:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 109289 Delivered-To: patch@linaro.org Received: by 10.140.101.6 with SMTP id t6csp213220qge; Wed, 2 Aug 2017 19:58:37 -0700 (PDT) X-Received: by 10.84.241.203 with SMTP id t11mr202144plm.159.1501729117361; Wed, 02 Aug 2017 19:58:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1501729117; cv=none; d=google.com; s=arc-20160816; b=Xfnj1AQ/Dk5Axk7XpF619FQaakt9gcUnKMI6j/cnweboHSXZcx06tFzfu/wqAx7tvE aBq6iC/kHfZ5DOaCxddDFlZkhjucfZrC+I5qgy8KaRfl0pXQTyOMDhTB/GyUSblbczQR FIkSVVem4DCgVQyg3sfPjeE/0mK/RZ1BG/rQEkA303YTk4e/j1F11Cs/Gr+wcKlPZrd/ oLUpV3L3/Kq/mmXYOdWwhAGOdoO4DtfvjyH1s0xHAmbJXfD1YDxdWoQjNWcYNls6fMXx 1u+Ojt0GlSlP6pMwy/fTW33kle3KUL2i+M8Pb0zaY2UD7NDfUeIL59cR7fnEOPUBcbT6 YeJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=LFl3v+j/wddWUECjal2uTd0vz/fF3I8KZ/j60KhZ3CM=; b=appmAUWi1qTpvBfVVpcgiTrSWyLXhL2Sy+5mcJz+F8h4OEm8Dl4aBw1StLwCLE3qrg eXALYv0qvp2mQeKDeuyFSFMIBAM7+YyzJUIyz/hlhqDtmrvIR1wVdfIFzNAJfMkpW37P iKcz/UnMGdQsORHkL0Q6DEJ5VDaEjfJen6YpHGwyfAg2Pph1RZTe+xr9eusDTLpOGGsM qUM9MmLQfLSh3xR3BJrW0H+ablMrXNpz1A4Gtc0YXyuYiJX9KcSHbszOqn+HJYherKB7 +H2hnIOmR9TRY9lno7WUaW/jqJGSNN4dlVw9TVw0SgUf3t7xymK6GCANbwNOEb7jVAGJ J5vQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.b=RIhCbpLY; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h6si13873617pgc.39.2017.08.02.19.58.37; Wed, 02 Aug 2017 19:58:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.b=RIhCbpLY; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751959AbdHCC6f (ORCPT + 6 others); Wed, 2 Aug 2017 22:58:35 -0400 Received: from mail-pf0-f179.google.com ([209.85.192.179]:34524 "EHLO mail-pf0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752145AbdHCC6F (ORCPT ); Wed, 2 Aug 2017 22:58:05 -0400 Received: by mail-pf0-f179.google.com with SMTP id o86so796934pfj.1 for ; Wed, 02 Aug 2017 19:58:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=GWqVjKFO1jLpEApz5ndtX2pZbU90RKIivnW3Cmf9Wgs=; b=RIhCbpLY6GJOmGBSPQZgQUo+R9IzCdhUBy+WYs9wUlRWW3JsZDsJtTSgvdN9+Surwe gvBEmWwYhw0KpfI/eHwSnNZN9Gg1UjeLdPgBbOX1qZbMo7NT0ZGPk/l62Cndn1TU95q0 NWzrxCFRn3iMuPRsD/bwXWBKmR7BD4gWvQxd8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=GWqVjKFO1jLpEApz5ndtX2pZbU90RKIivnW3Cmf9Wgs=; b=moYyzPfBCpYU7r5GH9jHt6+sL/TTRnB2XybyIyw4s2e84lOWglyjByM2dlOzzR7HGP Lip/cbyViKZChLsqOxqxvt/aAwrYerU7DTCyJf2GyuchAPbRc+TjiLrn27rj3ZLhLx+1 PlSG3rnZHdMpLFTpIvHtYamIrputacdpdiUVlK1u46ackjVqFrYOwN/V4mt/ubtoXRr/ eU5ChepkXftlfj60K/VKm2Ee9QeU/sERS11GCaUTlTlx+ezTsV5lRf0lYQkZcR5ZMyyc h5uqwI7gSfqSe/t7f+e9I6FMFRJTecaEjkwZhqtnR9r8E2hS923xfmzOuVU2Aux8NPQj 9jtw== X-Gm-Message-State: AIVw111r1wP+iQmg4XQvd92FNSRHbuh0CsVuTZv7sqGpI3oQT0C5O1xW tzzj1OPy1FE75ALp X-Received: by 10.84.217.208 with SMTP id d16mr235894plj.208.1501729084545; Wed, 02 Aug 2017 19:58:04 -0700 (PDT) Received: from localhost.localdomain (ip68-111-217-79.sd.sd.cox.net. [68.111.217.79]) by smtp.gmail.com with ESMTPSA id z83sm10722573pfd.10.2017.08.02.19.58.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 02 Aug 2017 19:58:03 -0700 (PDT) From: Bjorn Andersson To: Rob Herring , Frank Rowand , Andy Gross , David Brown Cc: Mark Rutland , linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-soc@vger.kernel.org Subject: [PATCH v2 4/5] soc: qcom: Remote FS memory driver Date: Wed, 2 Aug 2017 19:57:53 -0700 Message-Id: <20170803025754.19101-5-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.12.0 In-Reply-To: <20170803025754.19101-1-bjorn.andersson@linaro.org> References: <20170803025754.19101-1-bjorn.andersson@linaro.org> Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org The rfsa driver is used for allocating and exposing regions of shared memory with remote processors for the purpose of exchanging sector-data between the remote filesystem service and its clients. Signed-off-by: Bjorn Andersson --- Changes since v1: - RFSA device represented direclty by the reserved-memory node drivers/of/platform.c | 1 + drivers/soc/qcom/Kconfig | 8 ++ drivers/soc/qcom/Makefile | 1 + drivers/soc/qcom/rfsa.c | 262 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 272 insertions(+) create mode 100644 drivers/soc/qcom/rfsa.c -- 2.12.0 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/of/platform.c b/drivers/of/platform.c index 8c241a116b08..0356f31b07db 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -498,6 +498,7 @@ EXPORT_SYMBOL_GPL(of_platform_default_populate); #ifndef CONFIG_PPC static const char *rmem_compats[] = { + "qcom,rfsa", "ramoops", NULL }; diff --git a/drivers/soc/qcom/Kconfig b/drivers/soc/qcom/Kconfig index 9fca977ef18d..788a63cd430e 100644 --- a/drivers/soc/qcom/Kconfig +++ b/drivers/soc/qcom/Kconfig @@ -24,6 +24,14 @@ config QCOM_PM modes. It interface with various system drivers to put the cores in low power modes. +config QCOM_RFSA + tristate "Qualcomm Remote Filesystem Access driver" + help + The Qualcomm remote filesystem access driver is used for allocating + and exposing regions of shared memory with remote processors for the + purpose of exchanging sector-data between the remote filesystem + service and its clients. + config QCOM_SMEM tristate "Qualcomm Shared Memory Manager (SMEM)" depends on ARCH_QCOM diff --git a/drivers/soc/qcom/Makefile b/drivers/soc/qcom/Makefile index 414f0de274fa..d1bbc791ddc0 100644 --- a/drivers/soc/qcom/Makefile +++ b/drivers/soc/qcom/Makefile @@ -1,6 +1,7 @@ obj-$(CONFIG_QCOM_GSBI) += qcom_gsbi.o obj-$(CONFIG_QCOM_MDT_LOADER) += mdt_loader.o obj-$(CONFIG_QCOM_PM) += spm.o +obj-$(CONFIG_QCOM_RFSA) += rfsa.o obj-$(CONFIG_QCOM_SMD_RPM) += smd-rpm.o obj-$(CONFIG_QCOM_SMEM) += smem.o obj-$(CONFIG_QCOM_SMEM_STATE) += smem_state.o diff --git a/drivers/soc/qcom/rfsa.c b/drivers/soc/qcom/rfsa.c new file mode 100644 index 000000000000..1b9ec33cde48 --- /dev/null +++ b/drivers/soc/qcom/rfsa.c @@ -0,0 +1,262 @@ +/* + * Copyright (c) 2017 Linaro Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 and + * only version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define QCOM_RFSA_DEV_MAX (MINORMASK + 1) + +static dev_t qcom_rfsa_major; + +struct qcom_rfsa { + struct device dev; + struct cdev cdev; + + void *base; + phys_addr_t addr; + phys_addr_t size; + + unsigned int client_id; +}; + +static ssize_t qcom_rfsa_show(struct device *dev, + struct device_attribute *attr, + char *buf); + +static DEVICE_ATTR(phys_addr, 0400, qcom_rfsa_show, NULL); +static DEVICE_ATTR(size, 0400, qcom_rfsa_show, NULL); +static DEVICE_ATTR(client_id, 0400, qcom_rfsa_show, NULL); + +static ssize_t qcom_rfsa_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct qcom_rfsa *rfsa = container_of(dev, struct qcom_rfsa, dev); + + if (attr == &dev_attr_phys_addr) + return sprintf(buf, "%pa\n", &rfsa->addr); + if (attr == &dev_attr_size) + return sprintf(buf, "%pa\n", &rfsa->size); + if (attr == &dev_attr_client_id) + return sprintf(buf, "%d\n", rfsa->client_id); + + return -EINVAL; +} + +static struct attribute *qcom_rfsa_attrs[] = { + &dev_attr_phys_addr.attr, + &dev_attr_size.attr, + &dev_attr_client_id.attr, + NULL +}; +ATTRIBUTE_GROUPS(qcom_rfsa); + +static int qcom_rfsa_open(struct inode *inode, struct file *filp) +{ + struct qcom_rfsa *rfsa = container_of(inode->i_cdev, struct qcom_rfsa, cdev); + + get_device(&rfsa->dev); + filp->private_data = rfsa; + + return 0; +} +static ssize_t qcom_rfsa_read(struct file *filp, + char __user *buf, size_t count, loff_t *f_pos) +{ + struct qcom_rfsa *rfsa = filp->private_data; + + if (*f_pos >= rfsa->size) + return 0; + + if (*f_pos + count >= rfsa->size) + count = rfsa->size - *f_pos; + + if (copy_to_user(buf, rfsa->base + *f_pos, count)) + return -EFAULT; + + *f_pos += count; + return count; +} + +static ssize_t qcom_rfsa_write(struct file *filp, + const char __user *buf, size_t count, + loff_t *f_pos) +{ + struct qcom_rfsa *rfsa = filp->private_data; + + if (*f_pos >= rfsa->size) + return 0; + + if (*f_pos + count >= rfsa->size) + count = rfsa->size - *f_pos; + + if (copy_from_user(rfsa->base + *f_pos, buf, count)) + return -EFAULT; + + *f_pos += count; + return count; +} + +static int qcom_rfsa_release(struct inode *inode, struct file *filp) +{ + struct qcom_rfsa *rfsa = filp->private_data; + + put_device(&rfsa->dev); + + return 0; +} + +static const struct file_operations qcom_rfsa_fops = { + .owner = THIS_MODULE, + .open = qcom_rfsa_open, + .read = qcom_rfsa_read, + .write = qcom_rfsa_write, + .release = qcom_rfsa_release, + .llseek = default_llseek, +}; + +static void qcom_rfsa_release_device(struct device *dev) +{ + struct qcom_rfsa *rfsa = container_of(dev, struct qcom_rfsa, dev); + + kfree(rfsa); +} + +static int qcom_rfsa_probe(struct platform_device *pdev) +{ + struct device_node *node = pdev->dev.of_node; + struct reserved_mem *rmem; + struct qcom_rfsa *rfsa; + u32 client_id; + int ret; + + rmem = of_reserved_mem_get(node); + if (!rmem) { + dev_err(&pdev->dev, "failed to acquire memory region\n"); + return -EINVAL; + } + + ret = of_property_read_u32(node, "qcom,client-id", &client_id); + if (ret) { + dev_err(&pdev->dev, "failed to parse \"qcom,client-id\"\n"); + return ret; + + } + + rfsa = kzalloc(sizeof(*rfsa), GFP_KERNEL); + if (!rfsa) + return -ENOMEM; + + rfsa->addr = rmem->base; + rfsa->client_id = client_id; + rfsa->size = rmem->size; + + device_initialize(&rfsa->dev); + rfsa->dev.parent = &pdev->dev; + rfsa->dev.groups = qcom_rfsa_groups; + + cdev_init(&rfsa->cdev, &qcom_rfsa_fops); + rfsa->cdev.owner = THIS_MODULE; + + dev_set_name(&rfsa->dev, "qcom_rfsa%d", client_id); + rfsa->dev.id = client_id; + rfsa->dev.devt = MKDEV(MAJOR(qcom_rfsa_major), client_id); + + ret = cdev_device_add(&rfsa->cdev, &rfsa->dev); + if (ret) { + dev_err(&pdev->dev, "failed to add cdev: %d\n", ret); + put_device(&rfsa->dev); + return ret; + } + + rfsa->dev.release = qcom_rfsa_release_device; + + rfsa->base = devm_memremap(&rfsa->dev, rfsa->addr, rfsa->size, MEMREMAP_WC); + if (IS_ERR(rfsa->base)) { + dev_err(&pdev->dev, "failed to remap rfsa region\n"); + + device_del(&rfsa->dev); + put_device(&rfsa->dev); + + return PTR_ERR(rfsa->base); + } + + dev_set_drvdata(&pdev->dev, rfsa); + + return 0; +} + +static int qcom_rfsa_remove(struct platform_device *pdev) +{ + struct qcom_rfsa *rfsa = dev_get_drvdata(&pdev->dev); + + cdev_del(&rfsa->cdev); + device_del(&rfsa->dev); + put_device(&rfsa->dev); + + return 0; +} + +static const struct of_device_id qcom_rfsa_of_match[] = { + { .compatible = "qcom,rfsa" }, + {} +}; +MODULE_DEVICE_TABLE(of, qcom_rfsa_of_match); + +static struct platform_driver qcom_rfsa_driver = { + .probe = qcom_rfsa_probe, + .remove = qcom_rfsa_remove, + .driver = { + .name = "qcom_rfsa", + .of_match_table = qcom_rfsa_of_match, + }, +}; + +static int qcom_rfsa_init(void) +{ + int ret; + + ret = alloc_chrdev_region(&qcom_rfsa_major, 0, QCOM_RFSA_DEV_MAX, + "qcom_rfsa"); + if (ret < 0) { + pr_err("qcom_rfsa: failed to allocate char dev region\n"); + return ret; + } + + ret = platform_driver_register(&qcom_rfsa_driver); + if (ret < 0) { + pr_err("qcom_rfsa: failed to register rfsa driver\n"); + unregister_chrdev_region(qcom_rfsa_major, QCOM_RFSA_DEV_MAX); + } + + return ret; +} +module_init(qcom_rfsa_init); + +static void qcom_rfsa_exit(void) +{ + platform_driver_unregister(&qcom_rfsa_driver); + unregister_chrdev_region(qcom_rfsa_major, QCOM_RFSA_DEV_MAX); +} +module_exit(qcom_rfsa_exit);