linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Scott Branden <scott.branden@broadcom.com>
To: Arnd Bergmann <arnd@arndb.de>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Scott Branden <scott.branden@broadcom.com>,
	Desmond Yan <desmond.yan@broadcom.com>
Cc: Kees Cook <keescook@chromium.org>,
	linux-kernel@vger.kernel.org,
	bcm-kernel-feedback-list@broadcom.com,
	Olof Johansson <olof@lixom.net>
Subject: [PATCH v7 11/13] misc: bcm-vk: add mmap function for exposing BAR2
Date: Tue, 17 Nov 2020 15:23:18 -0800	[thread overview]
Message-ID: <20201117232320.4958-12-scott.branden@broadcom.com> (raw)
In-Reply-To: <20201117232320.4958-1-scott.branden@broadcom.com>

Add mmap function that allows host application to open up BAR2 memory
for remote spooling out messages from the VK logger.

Co-developed-by: Desmond Yan <desmond.yan@broadcom.com>
Signed-off-by: Desmond Yan <desmond.yan@broadcom.com>
Signed-off-by: Scott Branden <scott.branden@broadcom.com>
---
 drivers/misc/bcm-vk/bcm_vk_dev.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/drivers/misc/bcm-vk/bcm_vk_dev.c b/drivers/misc/bcm-vk/bcm_vk_dev.c
index e572a7b18fab..cac07419f041 100644
--- a/drivers/misc/bcm-vk/bcm_vk_dev.c
+++ b/drivers/misc/bcm-vk/bcm_vk_dev.c
@@ -1199,6 +1199,29 @@ static long bcm_vk_reset(struct bcm_vk *vk, struct vk_reset __user *arg)
 	return ret;
 }
 
+static int bcm_vk_mmap(struct file *file, struct vm_area_struct *vma)
+{
+	struct bcm_vk_ctx *ctx = file->private_data;
+	struct bcm_vk *vk = container_of(ctx->miscdev, struct bcm_vk, miscdev);
+	unsigned long pg_size;
+
+	/* only BAR2 is mmap possible, which is bar num 4 due to 64bit */
+#define VK_MMAPABLE_BAR 4
+
+	pg_size = ((pci_resource_len(vk->pdev, VK_MMAPABLE_BAR) - 1)
+		    >> PAGE_SHIFT) + 1;
+	if (vma->vm_pgoff + vma_pages(vma) > pg_size)
+		return -EINVAL;
+
+	vma->vm_pgoff += (pci_resource_start(vk->pdev, VK_MMAPABLE_BAR)
+			  >> PAGE_SHIFT);
+	vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
+
+	return io_remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff,
+				  vma->vm_end - vma->vm_start,
+				  vma->vm_page_prot);
+}
+
 static long bcm_vk_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 {
 	long ret = -EINVAL;
@@ -1237,6 +1260,7 @@ static const struct file_operations bcm_vk_fops = {
 	.write = bcm_vk_write,
 	.poll = bcm_vk_poll,
 	.release = bcm_vk_release,
+	.mmap = bcm_vk_mmap,
 	.unlocked_ioctl = bcm_vk_ioctl,
 };
 
-- 
2.17.1


  parent reply	other threads:[~2020-11-17 23:25 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-17 23:23 [PATCH v7 00/13] Add Broadcom VK driver Scott Branden
2020-11-17 23:23 ` [PATCH v7 01/13] bcm-vk: add bcm_vk UAPI Scott Branden
2020-11-17 23:23 ` [PATCH v7 02/13] misc: bcm-vk: add Broadcom VK driver Scott Branden
2020-11-19 22:42   ` Pavel Machek
2020-11-19 23:16     ` Scott Branden
2020-11-17 23:23 ` [PATCH v7 03/13] misc: bcm-vk: add autoload support Scott Branden
2020-11-17 23:23 ` [PATCH v7 04/13] misc: bcm-vk: add misc device to Broadcom VK driver Scott Branden
2020-11-17 23:23 ` [PATCH v7 05/13] misc: bcm-vk: add triggers when host panic or reboots to notify card Scott Branden
2020-11-17 23:23 ` [PATCH v7 06/13] misc: bcm-vk: add open/release Scott Branden
2020-11-17 23:23 ` [PATCH v7 07/13] misc: bcm-vk: add ioctl load_image Scott Branden
2020-11-17 23:23 ` [PATCH v7 08/13] misc: bcm-vk: add get_card_info, peerlog_info, and proc_mon_info Scott Branden
2020-11-17 23:23 ` [PATCH v7 09/13] misc: bcm-vk: add VK messaging support Scott Branden
2020-11-17 23:23 ` [PATCH v7 10/13] misc: bcm-vk: reset_pid support Scott Branden
2020-11-17 23:23 ` Scott Branden [this message]
2020-11-17 23:23 ` [PATCH v7 12/13] MAINTAINERS: bcm-vk: add maintainer for Broadcom VK Driver Scott Branden
2020-11-17 23:23 ` [PATCH v7 13/13] misc: bcm-vk: add ttyVK support Scott Branden

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=20201117232320.4958-12-scott.branden@broadcom.com \
    --to=scott.branden@broadcom.com \
    --cc=arnd@arndb.de \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=desmond.yan@broadcom.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=olof@lixom.net \
    /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 NNTP newsgroup(s).