diff options
Diffstat (limited to 'driver')
-rw-r--r-- | driver/base.c | 2 | ||||
-rw-r--r-- | driver/compat.h | 40 | ||||
-rw-r--r-- | driver/int.c | 2 | ||||
-rw-r--r-- | driver/kmem.c | 3 | ||||
-rw-r--r-- | driver/rdma.c | 1 |
5 files changed, 44 insertions, 4 deletions
diff --git a/driver/base.c b/driver/base.c index 3cd42b8..d600a96 100644 --- a/driver/base.c +++ b/driver/base.c @@ -290,7 +290,7 @@ static int __init pcidriver_init(void) mod_info("Major %d allocated to nodename '%s'\n", MAJOR(pcidriver_devt), NODENAME); /* Register driver class */ - pcidriver_class = class_create(THIS_MODULE, NODENAME); + pcidriver_class = class_create_compat(THIS_MODULE, NODENAME); if (IS_ERR(pcidriver_class)) { mod_info("No sysfs support. Module not loaded.\n"); diff --git a/driver/compat.h b/driver/compat.h index 472ca4f..6b29b40 100644 --- a/driver/compat.h +++ b/driver/compat.h @@ -37,7 +37,9 @@ # define __devinitdata #endif -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,9,0) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(6,4,0) // or 6.3, to be checked (6.1 is definitively still old API) +# define get_user_pages_compat(vma, nr, pages) get_user_pages(vma, nr, FOLL_WRITE, pages) +#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4,9,0) # define get_user_pages_compat(vma, nr, pages) get_user_pages(vma, nr, FOLL_WRITE, pages, NULL) #elif LINUX_VERSION_CODE >= KERNEL_VERSION(4,6,0) # define get_user_pages_compat(vma, nr, pages) get_user_pages(vma, nr, 1, 0, pages, NULL) @@ -55,4 +57,40 @@ // https://lore.kernel.org/linux-mips/20191209194819.GA28157@lst.de/T/ #endif + +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,18,0) +# define pci_set_dma_mask(pdev, mask) dma_set_mask(&pdev->dev, mask) +# define pci_dma_mapping_error(pdev, dma_handle) dma_mapping_error(&pdev->dev, dma_handle) + +# define pci_map_sg(pdev, sg, nents, dir) dma_map_sg(&pdev->dev, sg, nents, dir) +# define pci_unmap_sg(pdev, sg, nents, dir) dma_unmap_sg(&pdev->dev, sg, nents, dir) +# define pci_dma_sync_sg_for_cpu(pdev, sg, nents, dir) dma_sync_sg_for_cpu(&pdev->dev, sg, nents, dir) +# define pci_dma_sync_sg_for_device(pdev, sg, nents, dir) dma_sync_sg_for_device(&pdev->dev, sg, nents, dir) + +# define pci_alloc_consistent(pdev, size, dma_handle) dma_alloc_coherent(&pdev->dev, size, dma_handle, GFP_KERNEL) +# define pci_free_consistent(pdev, size, vaddr, dma_handle) dma_free_coherent(&pdev->dev, size, vaddr, dma_handle) +# define pci_map_single(pdev, cpu_addr, size, direction) dma_map_single(&pdev->dev, cpu_addr, size, direction) +# define pci_unmap_single(pdev, dma_handle, size, direction) dma_unmap_single(&pdev->dev, dma_handle, size, direction) +# define pci_dma_sync_single_for_cpu(pdev, dma_handle, size, direction) dma_sync_single_for_cpu(&pdev->dev, dma_handle, size, direction) +# define pci_dma_sync_single_for_device(pdev, dma_handle, size, direction) dma_sync_single_for_device(&pdev->dev, dma_handle, size, direction) + +# define PCI_DMA_TODEVICE DMA_TO_DEVICE +# define PCI_DMA_FROMDEVICE DMA_FROM_DEVICE +# define PCI_DMA_BIDIRECTIONAL DMA_BIDIRECTIONAL +# define PCI_DMA_NONE DMA_NONE +#endif + +#if LINUX_VERSION_CODE >= KERNEL_VERSION(6,3,0) +# define vma_flags_set_compat(vma, flags) { mmap_write_lock(vma->vm_mm); vm_flags_set(vma, flags); mmap_write_unlock(vma->vm_mm); } +#else +# define vma_flags_set_compat(vma, flags) { vma->vm_flags |= VM_RESERVED; } +#endif + +#if LINUX_VERSION_CODE >= KERNEL_VERSION(6,4,0) +# define class_create_compat(mod, nodename) class_create(nodename) +#else +# define class_create_compat(mod, nodename) class_create(mod, nodename) +#endif + + #endif diff --git a/driver/int.c b/driver/int.c index 4bbfb26..08b90e5 100644 --- a/driver/int.c +++ b/driver/int.c @@ -16,7 +16,7 @@ #include <linux/cdev.h> #include <linux/wait.h> #include <linux/sched.h> -#include <stdbool.h> +//#include <stdbool.h> #include "base.h" diff --git a/driver/kmem.c b/driver/kmem.c index c1282be..aa367b7 100644 --- a/driver/kmem.c +++ b/driver/kmem.c @@ -613,8 +613,9 @@ int pcidriver_mmap_kmem(pcidriver_privdata_t *privdata, struct vm_area_struct *v } kmem_entry->refs += vma_size / PAGE_SIZE; + vma_flags_set_compat(vma, VM_RESERVED); // VM_DONTEXPAND | VM_DONTDUMP | VM_LOCKED; + - vma->vm_flags |= (VM_RESERVED); if ((kmem_entry->type&&PCILIB_KMEM_TYPE_MASK) == PCILIB_KMEM_TYPE_CONSISTENT) { // This is coherent memory, so it must not be cached. diff --git a/driver/rdma.c b/driver/rdma.c index 3b5dcaa..7684842 100644 --- a/driver/rdma.c +++ b/driver/rdma.c @@ -44,6 +44,7 @@ static unsigned long pcidriver_follow_pte(struct mm_struct *mm, unsigned long ad if (pmd_none(*pmd)) return 0; + // Seems not available out of kernel tree. See: https://lkml.indiana.edu/hypermail/linux/kernel/2307.3/08004.html pte = pte_offset_map_lock(mm, pmd, address, &ptl); if (!pte_none(*pte)) pfn = (pte_pfn(*pte) << PAGE_SHIFT); |