diff options
author | Vasilii Chernov <vchernov@inr.ru> | 2016-03-02 10:28:04 +0100 |
---|---|---|
committer | Vasilii Chernov <vchernov@inr.ru> | 2016-03-02 10:28:04 +0100 |
commit | 8e7c95957ee73d6c11ef28f7c0e2319a11103783 (patch) | |
tree | 83df220932b3d88e071eda4c756e485dd48d50e9 /driver | |
parent | 8719b84a95805d109e21c20f05a0164315e1b38a (diff) | |
parent | 867bddcf7be374221a04b7ae89f93a5f5d703ee6 (diff) | |
download | pcitool-8e7c95957ee73d6c11ef28f7c0e2319a11103783.tar.gz pcitool-8e7c95957ee73d6c11ef28f7c0e2319a11103783.tar.bz2 pcitool-8e7c95957ee73d6c11ef28f7c0e2319a11103783.tar.xz pcitool-8e7c95957ee73d6c11ef28f7c0e2319a11103783.zip |
Merge with http://ufo.kit.edu/ufo/log/csa/pcitool 362 revision
Diffstat (limited to 'driver')
-rw-r--r-- | driver/Makefile | 2 | ||||
-rw-r--r-- | driver/kmem.c | 6 | ||||
-rw-r--r-- | driver/pciDriver.h | 3 | ||||
-rw-r--r-- | driver/rdma.c | 53 | ||||
-rw-r--r-- | driver/rdma.h | 9 |
5 files changed, 69 insertions, 4 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/kmem.c b/driver/kmem.c index 805ace1..9bc1eb7 100644 --- a/driver/kmem.c +++ b/driver/kmem.c @@ -86,7 +86,8 @@ int pcidriver_kmem_alloc(pcidriver_privdata_t *privdata, kmem_handle_t *kmem_han kmem_handle->handle_id = kmem_entry->id; - kmem_handle->pa = (unsigned long)(kmem_entry->dma_handle); + kmem_handle->ba = (unsigned long)(kmem_entry->dma_handle); + kmem_handle->pa = virt_to_phys((void*)kmem_entry->cpua); kmem_handle->flags = KMEM_FLAG_REUSED; if (kmem_entry->refs&KMEM_REF_HW) kmem_handle->flags |= KMEM_FLAG_REUSED_HW; @@ -197,7 +198,8 @@ int pcidriver_kmem_alloc(pcidriver_privdata_t *privdata, kmem_handle_t *kmem_han kmem_entry->size = kmem_handle->size; kmem_entry->cpua = (unsigned long)retptr; - kmem_handle->pa = (unsigned long)(kmem_entry->dma_handle); + kmem_handle->ba = (unsigned long)(kmem_entry->dma_handle); + kmem_handle->pa = virt_to_phys(retptr); kmem_entry->mode = 1; if (kmem_handle->flags&KMEM_FLAG_REUSE) { diff --git a/driver/pciDriver.h b/driver/pciDriver.h index 5d6221e..371bd88 100644 --- a/driver/pciDriver.h +++ b/driver/pciDriver.h @@ -58,7 +58,7 @@ #include <linux/ioctl.h> -#define PCIDRIVER_INTERFACE_VERSION 1 /**< Driver API version, only the pcilib with the same driver interface version is allowed */ +#define PCIDRIVER_INTERFACE_VERSION 2 /**< Driver API version, only the pcilib with the same driver interface version is allowed */ /* Identifies the PCI-E Xilinx ML605 */ #define PCIE_XILINX_VENDOR_ID 0x10ee @@ -154,6 +154,7 @@ typedef struct { typedef struct { unsigned long type; unsigned long pa; + unsigned long ba; unsigned long size; unsigned long align; unsigned long use; 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 */ |