Linux-FPGA Archive mirror
 help / color / mirror / Atom feed
From: Peter Colberg <peter.colberg@intel.com>
To: hao.wu@intel.com, yilun.xu@intel.com, gregkh@linuxfoundation.org,
	linux-fpga@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: aaron.j.grier@intel.com, tianfei.zhang@intel.com,
	russell.h.weight@intel.com, matthew.gerlach@linux.intel.com,
	marpagan@redhat.com, lgoncalv@redhat.com,
	Peter Colberg <peter.colberg@intel.com>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Subject: [PATCH] fpga: dfl: afu: use PFN_DOWN() and PFN_PHYS() helper macros
Date: Fri, 16 Jun 2023 18:42:09 -0400	[thread overview]
Message-ID: <20230616224209.20991-1-peter.colberg@intel.com> (raw)

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(-)

diff --git a/drivers/fpga/dfl-afu-dma-region.c b/drivers/fpga/dfl-afu-dma-region.c
index 02b60fde0430..e8d54cfbb301 100644
--- a/drivers/fpga/dfl-afu-dma-region.c
+++ b/drivers/fpga/dfl-afu-dma-region.c
@@ -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++)
diff --git a/drivers/fpga/dfl-afu-main.c b/drivers/fpga/dfl-afu-main.c
index 7f621e96d3b8..048c9b418c8b 100644
--- a/drivers/fpga/dfl-afu-main.c
+++ b/drivers/fpga/dfl-afu-main.c
@@ -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, &region);
 	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);
 }
 
-- 
2.28.0


             reply	other threads:[~2023-06-16 22:44 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-16 22:42 Peter Colberg [this message]
2023-06-19 13:46 ` [PATCH] fpga: dfl: afu: use PFN_DOWN() and PFN_PHYS() helper macros Greg KH
2023-06-19 13:54   ` Andy Shevchenko
2023-06-19 14:05     ` Greg KH
2023-06-19 19:56       ` [PATCH v2] " Peter Colberg
2023-06-27  6:26         ` Xu Yilun
2023-06-27 18:23           ` Andy Shevchenko
2023-06-28  5:56             ` Xu Yilun
2023-06-29  0:22               ` [PATCH v3] fpga: dfl: afu: use PFN_DOWN() helper macro Peter Colberg
2023-07-10  6:35                 ` Xu Yilun

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230616224209.20991-1-peter.colberg@intel.com \
    --to=peter.colberg@intel.com \
    --cc=aaron.j.grier@intel.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hao.wu@intel.com \
    --cc=lgoncalv@redhat.com \
    --cc=linux-fpga@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marpagan@redhat.com \
    --cc=matthew.gerlach@linux.intel.com \
    --cc=russell.h.weight@intel.com \
    --cc=tianfei.zhang@intel.com \
    --cc=yilun.xu@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).