mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-08-05 16:54:27 +00:00
misc: bcm-vk: add mmap function for exposing BAR2
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> Acked-by: Olof Johansson <olof@lixom.net> Signed-off-by: Desmond Yan <desmond.yan@broadcom.com> Signed-off-by: Scott Branden <scott.branden@broadcom.com> Link: https://lore.kernel.org/r/20210120175827.14820-12-scott.branden@broadcom.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
d63d658f74
commit
483050c047
1 changed files with 24 additions and 0 deletions
|
@ -1199,6 +1199,29 @@ err_exit:
|
||||||
return ret;
|
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)
|
static long bcm_vk_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
|
||||||
{
|
{
|
||||||
long ret = -EINVAL;
|
long ret = -EINVAL;
|
||||||
|
@ -1237,6 +1260,7 @@ static const struct file_operations bcm_vk_fops = {
|
||||||
.write = bcm_vk_write,
|
.write = bcm_vk_write,
|
||||||
.poll = bcm_vk_poll,
|
.poll = bcm_vk_poll,
|
||||||
.release = bcm_vk_release,
|
.release = bcm_vk_release,
|
||||||
|
.mmap = bcm_vk_mmap,
|
||||||
.unlocked_ioctl = bcm_vk_ioctl,
|
.unlocked_ioctl = bcm_vk_ioctl,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue