diff options
| -rw-r--r-- | driver/Makefile | 2 | ||||
| -rw-r--r-- | driver/rdma.c | 53 | ||||
| -rw-r--r-- | driver/rdma.h | 9 | 
3 files changed, 63 insertions, 1 deletions
| diff --git a/driver/Makefile b/driver/Makefile index a783c3f..0a860bf 100644 --- a/driver/Makefile +++ b/driver/Makefile @@ -1,7 +1,7 @@  CONFIG_MODULE_SIG=n  obj-m := pciDriver.o -pciDriver-objs := base.o int.o umem.o kmem.o sysfs.o ioctl.o compat.o +pciDriver-objs := base.o int.o umem.o kmem.o sysfs.o ioctl.o compat.o rdma.o  KERNELDIR ?= /lib/modules/$(shell uname -r)/build  INSTALLDIR ?= /lib/modules/$(shell uname -r)/kernel/extra diff --git a/driver/rdma.c b/driver/rdma.c new file mode 100644 index 0000000..22a4a5e --- /dev/null +++ b/driver/rdma.c @@ -0,0 +1,53 @@ +#include <linux/version.h> +#include <linux/string.h> +#include <linux/types.h> +#include <linux/list.h> +#include <linux/pci.h> +#include <linux/wait.h> +#include <linux/mm.h> +#include <linux/pagemap.h> +#include <linux/hugetlb.h> + +#include "rdma.h" + +static unsigned long pcidriver_follow_pte(struct mm_struct *mm, unsigned long address) +{ +    pgd_t *pgd; +    pud_t *pud; +    pmd_t *pmd; +    pte_t *pte; + +    spinlock_t *ptl;  +    unsigned long pfn = 0; + + +    pgd = pgd_offset(mm, address); +    if (pgd_none(*pgd) || unlikely(pgd_bad(*pgd)))  +	return 0; +         +    pud = pud_offset(pgd, address); +    if (pud_none(*pud) || unlikely(pud_bad(*pud)))      +	return 0; + +    pmd = pmd_offset(pud, address); +    if (pmd_none(*pmd))  +	return 0; + +    pte = pte_offset_map_lock(mm, pmd, address, &ptl); +    if (!pte_none(*pte)) +	pfn = (pte_pfn(*pte) << PAGE_SHIFT); +    pte_unmap_unlock(pte, ptl);  + +    return pfn; +} + +unsigned long pcidriver_resolve_bar(unsigned long address) { +    unsigned long pfn; + +    address = (address >> PAGE_SHIFT) << PAGE_SHIFT; +    pfn = pcidriver_follow_pte(current->mm, address); + +    return pfn; +} + +EXPORT_SYMBOL(pcidriver_resolve_bar); diff --git a/driver/rdma.h b/driver/rdma.h new file mode 100644 index 0000000..4aeda78 --- /dev/null +++ b/driver/rdma.h @@ -0,0 +1,9 @@ +#ifndef _PCIDRIVER_RDMA_H +#define _PCIDRIVER_RDMA_H + +#include <linux/mm.h> +#include <linux/pagemap.h> + +extern unsigned long pcidriver_resolve_bar(unsigned long address); + +#endif /* _PCIDRIVER_RDMA_H */ | 
