Skip to contentSkip to conversation

fpga: support debug access to memory-mapped afu regions

PATCH RESEND Superseded Dominic Chen 2 participants 3 messages Mar 4, 2020

Subsystems (2)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 fpga: support debug access to memory-mapped afu regions

Allow debug access to memory-mapped regions using e.g. gdb.

---
 drivers/fpga/dfl-afu-main.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/fpga/dfl-afu-main.c +11 -0
index 02baa6a227c0..38983f9dde98 100644
@@ -459,6 +459,12 @@ static long afu_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 	return -EINVAL;
 }
 
+#ifdef CONFIG_HAVE_IOREMAP_PROT
+const struct vm_operations_struct afu_vma_ops = {
+	.access = generic_access_phys,
+};
+#endif /* CONFIG_HAVE_IOREMAP_PROT */
+
 static int afu_mmap(struct file *filp, struct vm_area_struct *vma)
 {
 	struct platform_device *pdev = filp->private_data;
@@ -488,6 +494,11 @@ static int afu_mmap(struct file *filp, struct vm_area_struct *vma)
 	    !(region.flags & DFL_PORT_REGION_WRITE))
 		return -EPERM;
 
+	// Support debug access to the mapping
+#ifdef CONFIG_HAVE_IOREMAP_PROT
+	vma->vm_ops = &afu_vma_ops;
+#endif /* CONFIG_HAVE_IOREMAP_PROT */
+
 	vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
 
 	return remap_pfn_range(vma, vma->vm_start,
Signature · 1 line
2.17.1
#1 lore raw

Hi Dominic,

Thanks a lot for this patch. Please see my comments inline.

Quoted 1 line · Dominic Chen

Allow debug access to memory-mapped regions using e.g. gdb.

Do you mind improving the title to something like

"fpga: dfl: afu: ...."

Quoted 11 lines
---
 drivers/fpga/dfl-afu-main.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/fpga/dfl-afu-main.c +0 -0
index 02baa6a227c0..38983f9dde98 100644

drivers/fpga/dfl-afu-main.c static long afu_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) · line 463

Quoted 5 lines
drivers/fpga/dfl-afu-main.c +2 -0
@@ -459,6 +459,12 @@ static long afu_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 	return -EINVAL;
 }
 
+#ifdef CONFIG_HAVE_IOREMAP_PROT
+const struct vm_operations_struct afu_vma_ops = {

let's add "static" for afu_vma_ops here.

drivers/fpga/dfl-afu-main.c static long afu_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) · line 467

Quoted 4 lines
drivers/fpga/dfl-afu-main.c +4 -0
+	.access = generic_access_phys,
+};
+#endif /* CONFIG_HAVE_IOREMAP_PROT */
+

What about

  static const struct vm_operations_struct afu_vma_ops = {
  #ifdef CONFIG_HAVE_IOREMAP_PROT
  	.access = generic_access_phys,
  #endif
  };

Then we just need one line below.

  vma->vm_ops = &afu_vma_ops;

Thanks
Hao

Quoted 17 lines
drivers/fpga/dfl-afu-main.c +5 -0
 static int afu_mmap(struct file *filp, struct vm_area_struct *vma)
 {
 	struct platform_device *pdev = filp->private_data;
@@ -488,6 +494,11 @@ static int afu_mmap(struct file *filp, struct vm_area_struct *vma)
 	    !(region.flags & DFL_PORT_REGION_WRITE))
 		return -EPERM;
 
+	// Support debug access to the mapping
+#ifdef CONFIG_HAVE_IOREMAP_PROT
+	vma->vm_ops = &afu_vma_ops;
+#endif /* CONFIG_HAVE_IOREMAP_PROT */
+
 	vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
 
 	return remap_pfn_range(vma, vma->vm_start,
Signature · 1 line
2.17.1
#2 lore raw

Sure, I will send out a v2.

Thanks,

Dominic

Quoted 64 lines · Wu Hao

Hi Dominic,

Thanks a lot for this patch. Please see my comments inline.

Quoted 1 line · Dominic Chen

Allow debug access to memory-mapped regions using e.g. gdb.

Do you mind improving the title to something like

   "fpga: dfl: afu: ...."
Quoted 10 lines
---
 drivers/fpga/dfl-afu-main.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/fpga/dfl-afu-main.c +0 -0
index 02baa6a227c0..38983f9dde98 100644

drivers/fpga/dfl-afu-main.c static long afu_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) · line 463

Quoted 5 lines
drivers/fpga/dfl-afu-main.c +2 -0
@@ -459,6 +459,12 @@ static long afu_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 	return -EINVAL;
 }
 
+#ifdef CONFIG_HAVE_IOREMAP_PROT
+const struct vm_operations_struct afu_vma_ops = {

let's add "static" for afu_vma_ops here.

drivers/fpga/dfl-afu-main.c static long afu_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) · line 467

Quoted 4 lines
drivers/fpga/dfl-afu-main.c +4 -0
+	.access = generic_access_phys,
+};
+#endif /* CONFIG_HAVE_IOREMAP_PROT */
+

What about

  static const struct vm_operations_struct afu_vma_ops = {
  #ifdef CONFIG_HAVE_IOREMAP_PROT
  	.access = generic_access_phys,
  #endif
  };

Then we just need one line below.

  vma->vm_ops = &afu_vma_ops;

Thanks
Hao

Quoted 17 lines
drivers/fpga/dfl-afu-main.c +5 -0
 static int afu_mmap(struct file *filp, struct vm_area_struct *vma)
 {
 	struct platform_device *pdev = filp->private_data;
@@ -488,6 +494,11 @@ static int afu_mmap(struct file *filp, struct vm_area_struct *vma)
 	    !(region.flags & DFL_PORT_REGION_WRITE))
 		return -EPERM;
 
+	// Support debug access to the mapping
+#ifdef CONFIG_HAVE_IOREMAP_PROT
+	vma->vm_ops = &afu_vma_ops;
+#endif /* CONFIG_HAVE_IOREMAP_PROT */
+
 	vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
 
 	return remap_pfn_range(vma, vma->vm_start,
Signature · 1 line
2.17.1