fpga: dfl: afu: use PFN_DOWN() and PFN_PHYS() helper macros
Subsystems (2)
PATCH 1/1 fpga: dfl: afu: use PFN_DOWN() and PFN_PHYS() helper macros
Replace all shifts by PAGE_SHIFT with PFN_DOWN() and PFN_PHYS() helper macros to convert between physical addresses and page frame numbers.
--- drivers/fpga/dfl-afu-dma-region.c | 7 ++++--- drivers/fpga/dfl-afu-main.c | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-)
drivers/fpga/dfl-afu-dma-region.c +4 -3
@@ -10,6 +10,7 @@*/ #include <linux/dma-mapping.h> +#include <linux/pfn.h> #include <linux/sched/signal.h> #include <linux/uaccess.h> #include <linux/mm.h>
@@ -34,7 +35,7 @@ void afu_dma_region_init(struct dfl_feature_platform_data *pdata)static int afu_dma_pin_pages (struct dfl_feature_platform_data *pdata,struct dfl_afu_dma_region *region) { -int npages = region->length >>PAGE_SHIFT ; +int npages =PFN_DOWN (region->length);struct device *dev = &pdata->dev->dev;int ret, pinned;
@@ -82,7 +83,7 @@ static int afu_dma_pin_pages(struct dfl_feature_platform_data *pdata,static void afu_dma_unpin_pages (struct dfl_feature_platform_data *pdata,struct dfl_afu_dma_region *region) { -long npages = region->length >>PAGE_SHIFT ; +long npages =PFN_DOWN (region->length);struct device *dev = &pdata->dev->dev;unpin_user_pages (region->pages, npages);
@@ -101,7 +102,7 @@ static void afu_dma_unpin_pages(struct dfl_feature_platform_data *pdata,*/ static bool afu_dma_check_continuous_pages (struct dfl_afu_dma_region *region) { -int npages = region->length >>PAGE_SHIFT ; +int npages =PFN_DOWN (region->length);int i;for (i =0 ; i < npages -1 ; i++)
drivers/fpga/dfl-afu-main.c +3 -2
@@ -16,6 +16,7 @@#include <linux/kernel.h> #include <linux/module.h> +#include <linux/pfn.h> #include <linux/uaccess.h> #include <linux/fpga-dfl.h>
@@ -816,7 +817,7 @@ static int afu_mmap(struct file *filp, struct vm_area_struct *vma) pdata =dev_get_platdata (&pdev->dev); - offset = vma->vm_pgoff <<PAGE_SHIFT ; + offset =PFN_PHYS (vma->vm_pgoff); ret =afu_mmio_region_get_by_offset (pdata, offset, size, ®ion);if (ret)return ret;
@@ -837,7 +838,7 @@ static int afu_mmap(struct file *filp, struct vm_area_struct *vma) vma->vm_page_prot =pgprot_noncached (vma->vm_page_prot);return remap_pfn_range (vma, vma->vm_start, - (region.phys + (offset - region.offset)) >>PAGE_SHIFT , +PFN_DOWN (region.phys + (offset - region.offset)), size, vma->vm_page_prot); }
Signature · 1 line
2.28.0
Quoted 2 lines · Peter Colberg
Replace all shifts by
PAGE_SHIFTwithPFN_DOWN()andPFN_PHYS()helper macros to convert between physical addresses and page frame numbers.
Is this a bugfix, or just a cleanup?
thanks,
greg k-h
Quoted 5 lines · Greg KH
Quoted 2 lines · Peter Colberg
Replace all shifts by
PAGE_SHIFTwithPFN_DOWN()andPFN_PHYS()helper macros to convert between physical addresses and page frame numbers.Is this a bugfix, or just a cleanup?
Cleanup.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 8 lines · Andy Shevchenko
Quoted 5 lines · Greg KH
Quoted 2 lines · Peter Colberg
Replace all shifts by
PAGE_SHIFTwithPFN_DOWN()andPFN_PHYS()helper macros to convert between physical addresses and page frame numbers.Is this a bugfix, or just a cleanup?
Cleanup.
Great, can the text be worded to say that? As is, it does not give any hint either way.
thanks,
greg k-h
PATCH v2 1/1 fpga: dfl: afu: use PFN_DOWN() and PFN_PHYS() helper macros
Replace all shifts by PAGE_SHIFT with PFN_DOWN() and PFN_PHYS() helper macros to convert between physical addresses and page frame numbers.
These changes are cosmetic only; no functional changes.
---
v2:
- Comment in commit message that changes are cosmetic only
--- drivers/fpga/dfl-afu-dma-region.c | 7 ++++--- drivers/fpga/dfl-afu-main.c | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-)
drivers/fpga/dfl-afu-dma-region.c +4 -3
@@ -10,6 +10,7 @@*/ #include <linux/dma-mapping.h> +#include <linux/pfn.h> #include <linux/sched/signal.h> #include <linux/uaccess.h> #include <linux/mm.h>
@@ -34,7 +35,7 @@ void afu_dma_region_init(struct dfl_feature_platform_data *pdata)static int afu_dma_pin_pages (struct dfl_feature_platform_data *pdata,struct dfl_afu_dma_region *region) { -int npages = region->length >>PAGE_SHIFT ; +int npages =PFN_DOWN (region->length);struct device *dev = &pdata->dev->dev;int ret, pinned;
@@ -82,7 +83,7 @@ static int afu_dma_pin_pages(struct dfl_feature_platform_data *pdata,static void afu_dma_unpin_pages (struct dfl_feature_platform_data *pdata,struct dfl_afu_dma_region *region) { -long npages = region->length >>PAGE_SHIFT ; +long npages =PFN_DOWN (region->length);struct device *dev = &pdata->dev->dev;unpin_user_pages (region->pages, npages);
@@ -101,7 +102,7 @@ static void afu_dma_unpin_pages(struct dfl_feature_platform_data *pdata,*/ static bool afu_dma_check_continuous_pages (struct dfl_afu_dma_region *region) { -int npages = region->length >>PAGE_SHIFT ; +int npages =PFN_DOWN (region->length);int i;for (i =0 ; i < npages -1 ; i++)
drivers/fpga/dfl-afu-main.c +3 -2
@@ -16,6 +16,7 @@#include <linux/kernel.h> #include <linux/module.h> +#include <linux/pfn.h> #include <linux/uaccess.h> #include <linux/fpga-dfl.h>
@@ -816,7 +817,7 @@ static int afu_mmap(struct file *filp, struct vm_area_struct *vma) pdata =dev_get_platdata (&pdev->dev); - offset = vma->vm_pgoff <<PAGE_SHIFT ; + offset =PFN_PHYS (vma->vm_pgoff); ret =afu_mmio_region_get_by_offset (pdata, offset, size, ®ion);if (ret)return ret;
@@ -837,7 +838,7 @@ static int afu_mmap(struct file *filp, struct vm_area_struct *vma) vma->vm_page_prot =pgprot_noncached (vma->vm_page_prot);return remap_pfn_range (vma, vma->vm_start, - (region.phys + (offset - region.offset)) >>PAGE_SHIFT , +PFN_DOWN (region.phys + (offset - region.offset)), size, vma->vm_page_prot); }
Signature · 1 line
2.28.0
Xu Yilun
maintainerQuoted 29 lines · Peter Colberg
Replace all shifts by
PAGE_SHIFTwithPFN_DOWN()andPFN_PHYS()helper macros to convert between physical addresses and page frame numbers.These changes are cosmetic only; no functional changes.
Suggested-by Andy Shevchenko <[email protected]>Signed-off-by Peter Colberg <[email protected]>Reviewed-by Andy Shevchenko <[email protected]>---
v2:
- Comment in commit message that changes are cosmetic only--- drivers/fpga/dfl-afu-dma-region.c | 7 ++++--- drivers/fpga/dfl-afu-main.c | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-)drivers/fpga/dfl-afu-dma-region.c +1
-0@@ -10,6 +10,7 @@*/ #include <linux/dma-mapping.h> +#include <linux/pfn.h> #include <linux/sched/signal.h> #include <linux/uaccess.h> #include <linux/mm.h>
drivers/fpga/dfl-afu-dma-region.c void afu_dma_region_init(struct dfl_feature_platform_data *pdata) · line 38
Quoted 5 lines
drivers/fpga/dfl-afu-dma-region.c +1
-1@@ -34,7 +35,7 @@ void afu_dma_region_init(struct dfl_feature_platform_data *pdata)static int afu_dma_pin_pages (struct dfl_feature_platform_data *pdata,struct dfl_afu_dma_region *region) { -int npages = region->length >>PAGE_SHIFT ; +int npages =PFN_DOWN (region->length);
I don't much prefer this change, it is not doing the phy addr to pfn convertion. The macro name doesn't match what is doing here.
drivers/fpga/dfl-afu-dma-region.c static int afu_dma_pin_pages(struct dfl_feature_platform_data *pdata, · line 86
Quoted 9 lines
drivers/fpga/dfl-afu-dma-region.c +1
-1struct device *dev = &pdata->dev->dev;int ret, pinned;@@ -82,7 +83,7 @@ static int afu_dma_pin_pages(struct dfl_feature_platform_data *pdata,static void afu_dma_unpin_pages (struct dfl_feature_platform_data *pdata,struct dfl_afu_dma_region *region) { -long npages = region->length >>PAGE_SHIFT ; +long npages =PFN_DOWN (region->length);
ditto
drivers/fpga/dfl-afu-dma-region.c static void afu_dma_unpin_pages(struct dfl_feature_platform_data *pdata, · line 105
Quoted 9 lines
drivers/fpga/dfl-afu-dma-region.c +1
-1struct device *dev = &pdata->dev->dev;unpin_user_pages (region->pages, npages);@@ -101,7 +102,7 @@ static void afu_dma_unpin_pages(struct dfl_feature_platform_data *pdata,*/ static bool afu_dma_check_continuous_pages (struct dfl_afu_dma_region *region) { -int npages = region->length >>PAGE_SHIFT ; +int npages =PFN_DOWN (region->length);
ditto
Quoted 16 lines
drivers/fpga/dfl-afu-dma-region.c +0
-0int i;for (i =0 ; i < npages -1 ; i++)drivers/fpga/dfl-afu-main.c +1
-0@@ -16,6 +16,7 @@#include <linux/kernel.h> #include <linux/module.h> +#include <linux/pfn.h> #include <linux/uaccess.h> #include <linux/fpga-dfl.h>
drivers/fpga/dfl-afu-main.c static int afu_mmap(struct file *filp, struct vm_area_struct *vma) · line 820
Quoted 5 lines
drivers/fpga/dfl-afu-main.c +1
-1@@ -816,7 +817,7 @@ static int afu_mmap(struct file *filp, struct vm_area_struct *vma) pdata =dev_get_platdata (&pdev->dev); - offset = vma->vm_pgoff <<PAGE_SHIFT ; + offset =PFN_PHYS (vma->vm_pgoff);
ditto. The variables are offsets within file, not phys addr & pfn.
Quoted 15 lines
drivers/fpga/dfl-afu-main.c +1
-1ret =afu_mmio_region_get_by_offset (pdata, offset, size, ®ion);if (ret)return ret;@@ -837,7 +838,7 @@ static int afu_mmap(struct file *filp, struct vm_area_struct *vma) vma->vm_page_prot =pgprot_noncached (vma->vm_page_prot);return remap_pfn_range (vma, vma->vm_start, - (region.phys + (offset - region.offset)) >>PAGE_SHIFT , +PFN_DOWN (region.phys + (offset - region.offset)), size, vma->vm_page_prot); }Signature · 1 line
2.28.0
Quoted 1 line · Xu Yilun
On 2023-06-19 at 15:56:34 -0400, Peter Colberg wrote:
...
Quoted 5 lines
Review
Quoted 2 lines
(quoted diff) +1
-1- int npages = region->length >> PAGE_SHIFT; + int npages = PFN_DOWN(region->length);I don't much prefer this change, it is not doing the phy addr to pfn convertion. The macro name doesn't match what is doing here.
This macro converts length to pages. And it's not about phy addr.
...
Quoted 4 lines
drivers/fpga/dfl-afu-dma-region.c static int afu_dma_pin_pages(struct dfl_feature_platform_data *pdata, · line 86
Quoted 2 lines
drivers/fpga/dfl-afu-dma-region.c +1
-1-long npages = region->length >>PAGE_SHIFT ; +long npages =PFN_DOWN (region->length);ditto
Ditto.
...
Quoted 4 lines
Review
Quoted 2 lines
(quoted diff) +1
-1- int npages = region->length >> PAGE_SHIFT; + int npages = PFN_DOWN(region->length);ditto
Ditto.
...
Quoted 4 lines
drivers/fpga/dfl-afu-main.c static int afu_mmap(struct file *filp, struct vm_area_struct *vma) · line 820
Quoted 2 lines
drivers/fpga/dfl-afu-main.c +1
-1- offset = vma->vm_pgoff <<PAGE_SHIFT ; + offset =PFN_PHYS (vma->vm_pgoff);ditto. The variables are offsets within file, not phys addr & pfn.
Here I probably can agree.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Xu Yilun
maintainerQuoted 5 lines · Andy Shevchenko
Quoted 1 line · Xu Yilun
On 2023-06-19 at 15:56:34 -0400, Peter Colberg wrote:
...
Quoted 7 lines
Quoted 5 lines
Review
Quoted 2 lines
(quoted diff) +1
-1- int npages = region->length >> PAGE_SHIFT; + int npages = PFN_DOWN(region->length);I don't much prefer this change, it is not doing the phy addr to pfn convertion. The macro name doesn't match what is doing here.
This macro converts length to pages. And it's not about phy addr.
You are right.
Quoted 6 lines
Quoted 4 lines
drivers/fpga/dfl-afu-main.c static int afu_mmap(struct file *filp, struct vm_area_struct *vma) · line 820
Quoted 2 lines
drivers/fpga/dfl-afu-main.c +1
-1- offset = vma->vm_pgoff <<PAGE_SHIFT ; + offset =PFN_PHYS (vma->vm_pgoff);ditto. The variables are offsets within file, not phys addr & pfn.
Here I probably can agree.
OK. Remove this one, and others LGTM.
Thanks,
Yilun
Quoted 6 lines
Signature · 3 lines
-- With Best Regards, Andy Shevchenko
PATCH v3 1/1 fpga: dfl: afu: use PFN_DOWN() helper macro
Replace right shifts by PAGE_SHIFT with PFN_DOWN() helper macro to convert from physical addresses to page frame numbers.
These changes are cosmetic only; no functional changes.
---
v3:
- Revert afu_mmap(), which calculates file offsets, not physical pages v2:
- Comment in commit message that changes are cosmetic only
--- drivers/fpga/dfl-afu-dma-region.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/fpga/dfl-afu-dma-region.c +4 -3
@@ -10,6 +10,7 @@*/ #include <linux/dma-mapping.h> +#include <linux/pfn.h> #include <linux/sched/signal.h> #include <linux/uaccess.h> #include <linux/mm.h>
@@ -34,7 +35,7 @@ void afu_dma_region_init(struct dfl_feature_platform_data *pdata)static int afu_dma_pin_pages (struct dfl_feature_platform_data *pdata,struct dfl_afu_dma_region *region) { -int npages = region->length >>PAGE_SHIFT ; +int npages =PFN_DOWN (region->length);struct device *dev = &pdata->dev->dev;int ret, pinned;
@@ -82,7 +83,7 @@ static int afu_dma_pin_pages(struct dfl_feature_platform_data *pdata,static void afu_dma_unpin_pages (struct dfl_feature_platform_data *pdata,struct dfl_afu_dma_region *region) { -long npages = region->length >>PAGE_SHIFT ; +long npages =PFN_DOWN (region->length);struct device *dev = &pdata->dev->dev;unpin_user_pages (region->pages, npages);
@@ -101,7 +102,7 @@ static void afu_dma_unpin_pages(struct dfl_feature_platform_data *pdata,*/ static bool afu_dma_check_continuous_pages (struct dfl_afu_dma_region *region) { -int npages = region->length >>PAGE_SHIFT ; +int npages =PFN_DOWN (region->length);int i;for (i =0 ; i < npages -1 ; i++)
Signature · 1 line
2.28.0
Xu Yilun
maintainerRe: [PATCH v3] fpga: dfl: afu: use PFN_DOWN() helper macro
Quoted 48 lines · Peter Colberg
Replace right shifts by
PAGE_SHIFTwithPFN_DOWN()helper macro to convert from physical addresses to page frame numbers.These changes are cosmetic only; no functional changes.
Suggested-by Andy Shevchenko <[email protected]>Signed-off-by Peter Colberg <[email protected]>Reviewed-by Andy Shevchenko <[email protected]>---
v3:
- Revertafu_mmap(), which calculates file offsets, not physical pages v2:
- Comment in commit message that changes are cosmetic only--- drivers/fpga/dfl-afu-dma-region.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)drivers/fpga/dfl-afu-dma-region.c +3
-2@@ -10,6 +10,7 @@*/ #include <linux/dma-mapping.h> +#include <linux/pfn.h> #include <linux/sched/signal.h> #include <linux/uaccess.h> #include <linux/mm.h> @@ -34,7 +35,7 @@ void afu_dma_region_init(struct dfl_feature_platform_data *pdata)static int afu_dma_pin_pages (struct dfl_feature_platform_data *pdata,struct dfl_afu_dma_region *region) { -int npages = region->length >>PAGE_SHIFT ; +int npages =PFN_DOWN (region->length);struct device *dev = &pdata->dev->dev;int ret, pinned;@@ -82,7 +83,7 @@ static int afu_dma_pin_pages(struct dfl_feature_platform_data *pdata,static void afu_dma_unpin_pages (struct dfl_feature_platform_data *pdata,struct dfl_afu_dma_region *region) { -long npages = region->length >>PAGE_SHIFT ; +long npages =PFN_DOWN (region->length);struct device *dev = &pdata->dev->dev;unpin_user_pages (region->pages, npages);
drivers/fpga/dfl-afu-dma-region.c static void afu_dma_unpin_pages(struct dfl_feature_platform_data *pdata, · line 108
Quoted 8 lines
drivers/fpga/dfl-afu-dma-region.c +1
-1@@ -101,7 +102,7 @@ static void afu_dma_unpin_pages(struct dfl_feature_platform_data *pdata,*/ static bool afu_dma_check_continuous_pages (struct dfl_afu_dma_region *region) { -int npages = region->length >>PAGE_SHIFT ; +int npages =PFN_DOWN (region->length);int i;for (i =0 ; i < npages -1 ; i++)
@@ -837,7 +838,7 @@ static int afu_mmap(struct file *filp, struct vm_area_struct *vma)
vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
return remap_pfn_range(vma, vma->vm_start,
- (region.phys + (offset - region.offset)) >> PAGE_SHIFT,
+ PFN_DOWN(region.phys + (offset - region.offset)),
size, vma->vm_page_prot);Why is this change also dropped? Maybe use PHYS_PFN() instead?
Thanks,
Yilun
Quoted 3 lines
Signature · 1 line
2.28.0