diff mbox series

[v2] soc: qcom: Add support for mmap functionality.

Message ID 1549255543-15677-1-git-send-email-jankit@codeaurora.org (mailing list archive)
State New, archived
Headers show
Series [v2] soc: qcom: Add support for mmap functionality. | expand

Commit Message

Ankit Jain Feb. 4, 2019, 4:45 a.m. UTC
This change adds mmap functionality to rmtfs_mem driver.
Userspace application can map the address and use this
mapped address directly as buffer for read/write call to disk.
and avoid the read/write call to the shared path to copy the
buffer to userspace application.

Signed-off-by: Ankit Jain <jankit@codeaurora.org>
---
 drivers/soc/qcom/rmtfs_mem.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

Comments

Ankit Jain Feb. 19, 2019, 10:21 a.m. UTC | #1
Hi Bjorn,

I have addressed your comment.
Could you please provide the reviewed-by on this patch.

Regards,

Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, 
Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a 
Linux Foundation collaborative Project.

On 2019-02-04 10:15, Ankit Jain wrote:
> This change adds mmap functionality to rmtfs_mem driver.
> Userspace application can map the address and use this
> mapped address directly as buffer for read/write call to disk.
> and avoid the read/write call to the shared path to copy the
> buffer to userspace application.
> 
> Signed-off-by: Ankit Jain <jankit@codeaurora.org>
> ---
>  drivers/soc/qcom/rmtfs_mem.c | 21 +++++++++++++++++++++
>  1 file changed, 21 insertions(+)
> 
> diff --git a/drivers/soc/qcom/rmtfs_mem.c 
> b/drivers/soc/qcom/rmtfs_mem.c
> index 7200d76..6f5e8be 100644
> --- a/drivers/soc/qcom/rmtfs_mem.c
> +++ b/drivers/soc/qcom/rmtfs_mem.c
> @@ -137,6 +137,26 @@ static int qcom_rmtfs_mem_release(struct inode
> *inode, struct file *filp)
>  	.name           = "rmtfs",
>  };
> 
> +static int qcom_rmtfs_mem_mmap(struct file *filep, struct 
> vm_area_struct *vma)
> +{
> +	struct qcom_rmtfs_mem *rmtfs_mem = filep->private_data;
> +
> +	if (vma->vm_end - vma->vm_start > rmtfs_mem->size) {
> +		dev_dbg(&rmtfs_mem->dev,
> +			"vm_end[%lu] - vm_start[%lu] [%lu] > mem->size[%pa]\n",
> +			vma->vm_end, vma->vm_start,
> +			(vma->vm_end - vma->vm_start), &rmtfs_mem->size);
> +		return -EINVAL;
> +	}
> +
> +	vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
> +	return remap_pfn_range(vma,
> +			       vma->vm_start,
> +			       rmtfs_mem->addr >> PAGE_SHIFT,
> +			       vma->vm_end - vma->vm_start,
> +			       vma->vm_page_prot);
> +}
> +
>  static const struct file_operations qcom_rmtfs_mem_fops = {
>  	.owner = THIS_MODULE,
>  	.open = qcom_rmtfs_mem_open,
> @@ -144,6 +164,7 @@ static int qcom_rmtfs_mem_release(struct inode
> *inode, struct file *filp)
>  	.write = qcom_rmtfs_mem_write,
>  	.release = qcom_rmtfs_mem_release,
>  	.llseek = default_llseek,
> +	.mmap = qcom_rmtfs_mem_mmap,
>  };
> 
>  static void qcom_rmtfs_mem_release_device(struct device *dev)
Ankit Jain Feb. 28, 2019, 4:03 a.m. UTC | #2
Hi Andy Gross,

Could you please pick this change in next release? as there is no 
further comment on this change.
Bjorn Andersson March 1, 2019, 6:52 p.m. UTC | #3
On Sun 03 Feb 20:45 PST 2019, Ankit Jain wrote:

> This change adds mmap functionality to rmtfs_mem driver.
> Userspace application can map the address and use this
> mapped address directly as buffer for read/write call to disk.
> and avoid the read/write call to the shared path to copy the
> buffer to userspace application.
> 

Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>

And I've picked it up for inclusion in 5.2.

Regards,
Bjorn

> Signed-off-by: Ankit Jain <jankit@codeaurora.org>
> ---
>  drivers/soc/qcom/rmtfs_mem.c | 21 +++++++++++++++++++++
>  1 file changed, 21 insertions(+)
> 
> diff --git a/drivers/soc/qcom/rmtfs_mem.c b/drivers/soc/qcom/rmtfs_mem.c
> index 7200d76..6f5e8be 100644
> --- a/drivers/soc/qcom/rmtfs_mem.c
> +++ b/drivers/soc/qcom/rmtfs_mem.c
> @@ -137,6 +137,26 @@ static int qcom_rmtfs_mem_release(struct inode *inode, struct file *filp)
>  	.name           = "rmtfs",
>  };
>  
> +static int qcom_rmtfs_mem_mmap(struct file *filep, struct vm_area_struct *vma)
> +{
> +	struct qcom_rmtfs_mem *rmtfs_mem = filep->private_data;
> +
> +	if (vma->vm_end - vma->vm_start > rmtfs_mem->size) {
> +		dev_dbg(&rmtfs_mem->dev,
> +			"vm_end[%lu] - vm_start[%lu] [%lu] > mem->size[%pa]\n",
> +			vma->vm_end, vma->vm_start,
> +			(vma->vm_end - vma->vm_start), &rmtfs_mem->size);
> +		return -EINVAL;
> +	}
> +
> +	vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
> +	return remap_pfn_range(vma,
> +			       vma->vm_start,
> +			       rmtfs_mem->addr >> PAGE_SHIFT,
> +			       vma->vm_end - vma->vm_start,
> +			       vma->vm_page_prot);
> +}
> +
>  static const struct file_operations qcom_rmtfs_mem_fops = {
>  	.owner = THIS_MODULE,
>  	.open = qcom_rmtfs_mem_open,
> @@ -144,6 +164,7 @@ static int qcom_rmtfs_mem_release(struct inode *inode, struct file *filp)
>  	.write = qcom_rmtfs_mem_write,
>  	.release = qcom_rmtfs_mem_release,
>  	.llseek = default_llseek,
> +	.mmap = qcom_rmtfs_mem_mmap,
>  };
>  
>  static void qcom_rmtfs_mem_release_device(struct device *dev)
> -- 
> Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc.
> Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation collaborative Project.
>
Stephen Boyd March 4, 2019, 7:38 p.m. UTC | #4
Quoting Bjorn Andersson (2019-03-01 10:52:04)
> On Sun 03 Feb 20:45 PST 2019, Ankit Jain wrote:
> 
> > This change adds mmap functionality to rmtfs_mem driver.
> > Userspace application can map the address and use this
> > mapped address directly as buffer for read/write call to disk.
> > and avoid the read/write call to the shared path to copy the
> > buffer to userspace application.
> > 
> 
> Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>
> 
> And I've picked it up for inclusion in 5.2.
> 

Please put something in the subject like rmtfs (and drop the full stop
please), because right now it's hard to figure out what driver is
getting mmap support.
Bjorn Andersson March 4, 2019, 8:06 p.m. UTC | #5
On Mon 04 Mar 11:38 PST 2019, Stephen Boyd wrote:

> Quoting Bjorn Andersson (2019-03-01 10:52:04)
> > On Sun 03 Feb 20:45 PST 2019, Ankit Jain wrote:
> > 
> > > This change adds mmap functionality to rmtfs_mem driver.
> > > Userspace application can map the address and use this
> > > mapped address directly as buffer for read/write call to disk.
> > > and avoid the read/write call to the shared path to copy the
> > > buffer to userspace application.
> > > 
> > 
> > Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>
> > 
> > And I've picked it up for inclusion in 5.2.
> > 
> 
> Please put something in the subject like rmtfs (and drop the full stop
> please), because right now it's hard to figure out what driver is
> getting mmap support.
> 

Thanks for being awake Stephen. As I haven't pushed my branch out, I
updated the commit in place.

Regards,
Bjorn
Stephen Boyd March 4, 2019, 11:29 p.m. UTC | #6
Quoting Ankit Jain (2019-02-03 20:45:43)
> diff --git a/drivers/soc/qcom/rmtfs_mem.c b/drivers/soc/qcom/rmtfs_mem.c
> index 7200d76..6f5e8be 100644
> --- a/drivers/soc/qcom/rmtfs_mem.c
> +++ b/drivers/soc/qcom/rmtfs_mem.c
> @@ -137,6 +137,26 @@ static int qcom_rmtfs_mem_release(struct inode *inode, struct file *filp)
>         .name           = "rmtfs",
>  };
>  
> +static int qcom_rmtfs_mem_mmap(struct file *filep, struct vm_area_struct *vma)
> +{
> +       struct qcom_rmtfs_mem *rmtfs_mem = filep->private_data;
> +
> +       if (vma->vm_end - vma->vm_start > rmtfs_mem->size) {
> +               dev_dbg(&rmtfs_mem->dev,
> +                       "vm_end[%lu] - vm_start[%lu] [%lu] > mem->size[%pa]\n",
> +                       vma->vm_end, vma->vm_start,
> +                       (vma->vm_end - vma->vm_start), &rmtfs_mem->size);
> +               return -EINVAL;
> +       }
> +
> +       vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
> +       return remap_pfn_range(vma,
> +                              vma->vm_start,
> +                              rmtfs_mem->addr >> PAGE_SHIFT,
> +                              vma->vm_end - vma->vm_start,
> +                              vma->vm_page_prot);

Just curious if we somehow enforce that the rmtfs_mem->size is a
multiple of a PAGE_SIZE page (which can be 4K, 16K, or even 64K on
arm64)? It's not like we're mapping in some extra stuff that isn't rmtfs
memory right?

> +}
> +
>  static const struct file_operations qcom_rmtfs_mem_fops = {
>         .owner = THIS_MODULE,
>         .open = qcom_rmtfs_mem_open,
diff mbox series

Patch

diff --git a/drivers/soc/qcom/rmtfs_mem.c b/drivers/soc/qcom/rmtfs_mem.c
index 7200d76..6f5e8be 100644
--- a/drivers/soc/qcom/rmtfs_mem.c
+++ b/drivers/soc/qcom/rmtfs_mem.c
@@ -137,6 +137,26 @@  static int qcom_rmtfs_mem_release(struct inode *inode, struct file *filp)
 	.name           = "rmtfs",
 };
 
+static int qcom_rmtfs_mem_mmap(struct file *filep, struct vm_area_struct *vma)
+{
+	struct qcom_rmtfs_mem *rmtfs_mem = filep->private_data;
+
+	if (vma->vm_end - vma->vm_start > rmtfs_mem->size) {
+		dev_dbg(&rmtfs_mem->dev,
+			"vm_end[%lu] - vm_start[%lu] [%lu] > mem->size[%pa]\n",
+			vma->vm_end, vma->vm_start,
+			(vma->vm_end - vma->vm_start), &rmtfs_mem->size);
+		return -EINVAL;
+	}
+
+	vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
+	return remap_pfn_range(vma,
+			       vma->vm_start,
+			       rmtfs_mem->addr >> PAGE_SHIFT,
+			       vma->vm_end - vma->vm_start,
+			       vma->vm_page_prot);
+}
+
 static const struct file_operations qcom_rmtfs_mem_fops = {
 	.owner = THIS_MODULE,
 	.open = qcom_rmtfs_mem_open,
@@ -144,6 +164,7 @@  static int qcom_rmtfs_mem_release(struct inode *inode, struct file *filp)
 	.write = qcom_rmtfs_mem_write,
 	.release = qcom_rmtfs_mem_release,
 	.llseek = default_llseek,
+	.mmap = qcom_rmtfs_mem_mmap,
 };
 
 static void qcom_rmtfs_mem_release_device(struct device *dev)