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>
Cc: Kees Cook <keescook@chromium.org>,
linux-kernel@vger.kernel.org,
bcm-kernel-feedback-list@broadcom.com,
Desmond Yan <desmond.yan@broadcom.com>
Subject: [PATCH v5 13/15] misc: bcm-vk: add mmap function for exposing BAR2
Date: Wed, 30 Sep 2020 18:28:08 -0700 [thread overview]
Message-ID: <20201001012810.4172-14-scott.branden@broadcom.com> (raw)
In-Reply-To: <20201001012810.4172-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 1e3abb4eadee..9f2e57d505c6 100644
--- a/drivers/misc/bcm-vk/bcm_vk_dev.c
+++ b/drivers/misc/bcm-vk/bcm_vk_dev.c
@@ -1177,6 +1177,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;
@@ -1215,6 +1238,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
next prev parent reply other threads:[~2020-10-01 1:29 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-01 1:27 [PATCH v5 00/15] Add Broadcom VK driver Scott Branden
2020-10-01 1:27 ` [PATCH v5 01/15] bcm-vk: add bcm_vk UAPI Scott Branden
2020-10-01 1:27 ` [PATCH v5 02/15] misc: bcm-vk: add Broadcom VK driver Scott Branden
2020-10-01 1:27 ` [PATCH v5 03/15] misc: bcm-vk: add autoload support Scott Branden
2020-10-01 4:07 ` kernel test robot
2020-10-01 17:48 ` Scott Branden
2020-10-02 5:36 ` [kbuild-all] " Philip Li
2020-10-01 1:27 ` [PATCH v5 04/15] misc: bcm-vk: add misc device to Broadcom VK driver Scott Branden
2020-10-01 1:28 ` [PATCH v5 05/15] misc: bcm-vk: add triggers when host panic or reboots to notify card Scott Branden
2020-10-01 1:28 ` [PATCH v5 06/15] misc: bcm-vk: add open/release Scott Branden
2020-10-01 1:28 ` [PATCH v5 07/15] misc: bcm-vk: add ioctl load_image Scott Branden
2020-10-01 1:28 ` [PATCH v5 08/15] misc: bcm-vk: add get_card_info, peerlog_info, and proc_mon_info Scott Branden
2020-10-01 1:28 ` [PATCH v5 09/15] misc: bcm-vk: add VK messaging support Scott Branden
2020-10-01 1:43 ` Joe Perches
2020-10-01 18:27 ` Scott Branden
2020-10-01 1:28 ` [PATCH v5 10/15] misc: bcm-vk: reset_pid support Scott Branden
2020-10-01 1:28 ` [PATCH v5 11/15] misc: bcm-vk: add BCM_VK_QSTATS Scott Branden
2020-10-01 2:33 ` Florian Fainelli
2020-10-01 22:12 ` Scott Branden
2020-10-01 22:13 ` Florian Fainelli
2020-10-02 16:54 ` Scott Branden
2020-10-02 4:55 ` Greg Kroah-Hartman
2020-10-02 16:52 ` Scott Branden
2020-10-01 1:28 ` [PATCH v5 12/15] misc: bcm-vk: add sysfs interface Scott Branden
2020-10-01 2:30 ` Florian Fainelli
2020-10-01 22:17 ` Scott Branden
2020-10-01 1:28 ` Scott Branden [this message]
2020-10-01 1:28 ` [PATCH v5 14/15] MAINTAINERS: bcm-vk: add maintainer for Broadcom VK Driver Scott Branden
2020-10-01 1:28 ` [PATCH v5 15/15] misc: bcm-vk: add ttyVK support Scott Branden
2020-10-01 2:36 ` Florian Fainelli
2020-10-01 22:26 ` Scott Branden
2020-10-01 2:38 ` [PATCH v5 00/15] Add Broadcom VK driver Florian Fainelli
2020-10-01 12:24 ` Olof Johansson
2020-10-01 22:34 ` 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=20201001012810.4172-14-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 \
/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).