Skip to contentSkip to conversation

fpga: dfl: afu: support debug access to memory-mapped afu regions

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

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 fpga: dfl: afu: 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 | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/fpga/dfl-afu-main.c +9 -0
index 02baa6a227c0..ec9dbd3d51b8 100644
@@ -459,6 +459,12 @@ static long afu_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 	return -EINVAL;
 }
 
+static const struct vm_operations_struct afu_vma_ops = {
+#ifdef CONFIG_HAVE_IOREMAP_PROT
+	.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,9 @@ 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
+	vma->vm_ops = &afu_vma_ops;
+
 	vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
 
 	return remap_pfn_range(vma, vma->vm_start,
Signature · 1 line
2.17.1
maintainer
#1 lore raw
Quoted 12 lines · Dominic Chen

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

---
 drivers/fpga/dfl-afu-main.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/fpga/dfl-afu-main.c +0 -0
index 02baa6a227c0..ec9dbd3d51b8 100644

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

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

I remember there were issues in the past with modules and this, are those resolved?

drivers/fpga/dfl-afu-main.c static int afu_mmap(struct file *filp, struct vm_area_struct *vma) · line 497

Quoted 10 lines
drivers/fpga/dfl-afu-main.c +3 -0
+};
+
 static int afu_mmap(struct file *filp, struct vm_area_struct *vma)
 {
 	struct platform_device *pdev = filp->private_data;
@@ -488,6 +494,9 @@ 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

Please use kernel style comments /* */ checkpatch.pl should catch this.

Quoted 8 lines
drivers/fpga/dfl-afu-main.c +2 -0
+	vma->vm_ops = &afu_vma_ops;
+
 	vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
 
 	return remap_pfn_range(vma, vma->vm_start,
Signature · 1 line
2.17.1

Thanks,
Moritz

#2 lore raw
Quoted 6 lines · Moritz Fischer

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

Quoted 4 lines
drivers/fpga/dfl-afu-main.c +4 -0
+static const struct vm_operations_struct afu_vma_ops = {
+#ifdef CONFIG_HAVE_IOREMAP_PROT
+	.access = generic_access_phys,
+#endif /* CONFIG_HAVE_IOREMAP_PROT */

I remember there were issues in the past with modules and this, are those resolved?

Are you referring to the generic_access_phys symbol not being exported? It looks like it became available to GPL modules starting with kernel v3.12.

Quoted 9 lines

drivers/fpga/dfl-afu-main.c static int afu_mmap(struct file *filp, struct vm_area_struct *vma) · line 497

Quoted 8 lines

static int afu_mmap(struct file *filp, struct vm_area_struct *vma) {

drivers/fpga/dfl-afu-main.c +1 -0
 	struct platform_device *pdev = filp->private_data;
@@ -488,6 +494,9 @@ 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

Please use kernel style comments /* */ checkpatch.pl should catch this.

Hmm, I did run checkpatch.pl, though it contains $allow_c99_comments = 1.  I'll send out v3 to fix this.

Thanks,

Dominic