dma coherent memory user-space maps
From: Thomas HellstrÃm (VMware)
Date: Tue Oct 08 2019 - 08:34:23 EST
Hi, Christoph,
Following our previous discussion I wonder if something along the lines
of the following could work / be acceptible
typedef unsigned long dma_pfn_t /* Opaque pfn type. Arch dependent. This
could if needed be a struct with a pointer and an offset */
/* Similar to vmf_insert_mixed() */
vm_fault_t dma_vmf_insert_mixed(struct device *dev,
ÂÂÂ ÂÂÂ ÂÂÂ ÂÂÂ struct vm_area_struct *vma,
ÂÂÂ ÂÂÂ ÂÂÂ ÂÂÂ unsigned long addr,
ÂÂÂ ÂÂÂ ÂÂÂ ÂÂÂ dma_pfn_t dpfn,
ÂÂÂ ÂÂÂ ÂÂÂ ÂÂÂ unsigned long attrs);
/* Similar to vmf_insert_pfn_pmd() */
vm_fault_t dma_vmf_insert_pfn_pmd(struct device *dev,
ÂÂÂ ÂÂÂ ÂÂÂ ÂÂÂ Â struct vm_area_struct *vma,
ÂÂÂ ÂÂÂ ÂÂÂ ÂÂÂ Â unsigned long addr,
ÂÂÂ ÂÂÂ ÂÂÂ ÂÂÂ Â dma_pfn_t dpfn,
ÂÂÂ ÂÂÂ ÂÂÂ ÂÂÂ Â unsigned long attrs);
/* Like vmap, but takes struct dma_pfns. */
extern void *dma_vmap(struct device *dev,
ÂÂÂ ÂÂÂ ÂÂÂÂÂ dma_pfn_t dpfns[],
ÂÂÂ ÂÂÂ ÂÂÂÂÂ unsigned int count, unsigned long flags,
ÂÂÂ ÂÂÂ ÂÂÂÂÂ unsigned long attrs);
/* Obtain struct dma_pfn pointers from a dma coherent allocation */
int dma_get_dpfns(struct device *dev, void *cpu_addr, dma_addr_t dma_addr,
ÂÂÂ ÂÂÂ Â pgoff_t offset, pgoff_t num, dma_pfn_t dpfns[]);
I figure, for most if not all architectures we could use an ordinary pfn
as dma_pfn_t, but the dma layer would still have control over how those
pfns are obtained and how they are used in the kernel's mapping APIs.
If so, I could start looking at this, time permitting, for the cases
where the pfn can be obtained from the kernel address or from
arch_dma_coherent_to_pfn(), and also the needed work to have a tailored
vmap_pfn().
Thanks,
/Thomas