fpga: dfl: afu: use PFN_DOWN() and PFN_PHYS() helper macros
Commit Message
Replace all shifts by PAGE_SHIFT with PFN_DOWN() and PFN_PHYS() helper
macros to convert between physical addresses and page frame numbers.
Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Peter Colberg <peter.colberg@intel.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/fpga/dfl-afu-dma-region.c | 7 ++++---
drivers/fpga/dfl-afu-main.c | 5 +++--
2 files changed, 7 insertions(+), 5 deletions(-)
Comments
On Fri, Jun 16, 2023 at 06:42:09PM -0400, Peter Colberg wrote:
> Replace all shifts by PAGE_SHIFT with PFN_DOWN() and PFN_PHYS() helper
> macros to convert between physical addresses and page frame numbers.
Is this a bugfix, or just a cleanup?
thanks,
greg k-h
On Mon, Jun 19, 2023 at 03:46:29PM +0200, Greg KH wrote:
> On Fri, Jun 16, 2023 at 06:42:09PM -0400, Peter Colberg wrote:
> > Replace all shifts by PAGE_SHIFT with PFN_DOWN() and PFN_PHYS() helper
> > macros to convert between physical addresses and page frame numbers.
>
> Is this a bugfix, or just a cleanup?
Cleanup.
On Mon, Jun 19, 2023 at 04:54:44PM +0300, Andy Shevchenko wrote:
> On Mon, Jun 19, 2023 at 03:46:29PM +0200, Greg KH wrote:
> > On Fri, Jun 16, 2023 at 06:42:09PM -0400, Peter Colberg wrote:
> > > Replace all shifts by PAGE_SHIFT with PFN_DOWN() and PFN_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
@@ -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++)
@@ -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);
}