Message ID | 20201102220651.22069-4-paul@crapouillou.net (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Add option to mmap GEM buffers cached, try 2 | expand |
Hi Christoph, Le mar. 3 nov. 2020 à 18:50, Christoph Hellwig <hch@infradead.org> a écrit : > On Mon, Nov 02, 2020 at 10:06:49PM +0000, Paul Cercueil wrote: >> This function can be used by drivers that need to mmap dumb buffers >> created with non-coherent backing memory. >> >> Signed-off-by: Paul Cercueil <paul@crapouillou.net> >> --- >> drivers/gpu/drm/drm_gem_cma_helper.c | 39 >> ++++++++++++++++++++++++++++ >> include/drm/drm_gem_cma_helper.h | 2 ++ >> 2 files changed, 41 insertions(+) >> >> diff --git a/drivers/gpu/drm/drm_gem_cma_helper.c >> b/drivers/gpu/drm/drm_gem_cma_helper.c >> index 3bdd67795e20..4ed63f4896bd 100644 >> --- a/drivers/gpu/drm/drm_gem_cma_helper.c >> +++ b/drivers/gpu/drm/drm_gem_cma_helper.c >> @@ -387,6 +387,45 @@ int drm_gem_cma_mmap(struct file *filp, struct >> vm_area_struct *vma) >> } >> EXPORT_SYMBOL_GPL(drm_gem_cma_mmap); >> >> +/** >> + * drm_gem_cma_mmap_noncoherent - memory-map a CMA GEM object with >> + * non-coherent cache attribute >> + * @filp: file object >> + * @vma: VMA for the area to be mapped >> + * >> + * Just like drm_gem_cma_mmap, but for a GEM object backed by >> non-coherent >> + * memory. >> + * >> + * Returns: >> + * 0 on success or a negative error code on failure. >> + */ >> +int drm_gem_cma_mmap_noncoherent(struct file *filp, struct >> vm_area_struct *vma) >> +{ >> + struct drm_gem_cma_object *cma_obj; >> + int ret; >> + >> + ret = drm_gem_mmap(filp, vma); >> + if (ret) >> + return ret; >> + >> + cma_obj = to_drm_gem_cma_obj(vma->vm_private_data); >> + >> + /* >> + * Clear the VM_PFNMAP flag that was set by drm_gem_mmap(), and >> set the >> + * vm_pgoff (used as a fake buffer offset by DRM) to 0 as we want >> to map >> + * the whole buffer. >> + */ >> + vma->vm_flags &= ~VM_PFNMAP; >> + vma->vm_pgoff = 0; >> + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags); >> + >> + return remap_pfn_range(vma, vma->vm_start, >> + cma_obj->paddr >> PAGE_SHIFT, >> + vma->vm_end - vma->vm_start, >> + vma->vm_page_prot); > > Per patch 1 cma_obj->paddr is the dma address, while remap_pfn_range > expects a physical address. This does not work. Ok, what would be the correct way to mmap_noncoherent? -Paul
Hi Christoph, Le mar. 3 nov. 2020 à 19:13, Paul Cercueil <paul@crapouillou.net> a écrit : > Hi Christoph, > > Le mar. 3 nov. 2020 à 18:50, Christoph Hellwig <hch@infradead.org> a > écrit : >> On Mon, Nov 02, 2020 at 10:06:49PM +0000, Paul Cercueil wrote: >>> This function can be used by drivers that need to mmap dumb buffers >>> created with non-coherent backing memory. >>> >>> Signed-off-by: Paul Cercueil <paul@crapouillou.net> >>> --- >>> drivers/gpu/drm/drm_gem_cma_helper.c | 39 >>> ++++++++++++++++++++++++++++ >>> include/drm/drm_gem_cma_helper.h | 2 ++ >>> 2 files changed, 41 insertions(+) >>> >>> diff --git a/drivers/gpu/drm/drm_gem_cma_helper.c >>> b/drivers/gpu/drm/drm_gem_cma_helper.c >>> index 3bdd67795e20..4ed63f4896bd 100644 >>> --- a/drivers/gpu/drm/drm_gem_cma_helper.c >>> +++ b/drivers/gpu/drm/drm_gem_cma_helper.c >>> @@ -387,6 +387,45 @@ int drm_gem_cma_mmap(struct file *filp, >>> struct vm_area_struct *vma) >>> } >>> EXPORT_SYMBOL_GPL(drm_gem_cma_mmap); >>> >>> +/** >>> + * drm_gem_cma_mmap_noncoherent - memory-map a CMA GEM object with >>> + * non-coherent cache attribute >>> + * @filp: file object >>> + * @vma: VMA for the area to be mapped >>> + * >>> + * Just like drm_gem_cma_mmap, but for a GEM object backed by >>> non-coherent >>> + * memory. >>> + * >>> + * Returns: >>> + * 0 on success or a negative error code on failure. >>> + */ >>> +int drm_gem_cma_mmap_noncoherent(struct file *filp, struct >>> vm_area_struct *vma) >>> +{ >>> + struct drm_gem_cma_object *cma_obj; >>> + int ret; >>> + >>> + ret = drm_gem_mmap(filp, vma); >>> + if (ret) >>> + return ret; >>> + >>> + cma_obj = to_drm_gem_cma_obj(vma->vm_private_data); >>> + >>> + /* >>> + * Clear the VM_PFNMAP flag that was set by drm_gem_mmap(), and >>> set the >>> + * vm_pgoff (used as a fake buffer offset by DRM) to 0 as we >>> want to map >>> + * the whole buffer. >>> + */ >>> + vma->vm_flags &= ~VM_PFNMAP; >>> + vma->vm_pgoff = 0; >>> + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags); >>> + >>> + return remap_pfn_range(vma, vma->vm_start, >>> + cma_obj->paddr >> PAGE_SHIFT, >>> + vma->vm_end - vma->vm_start, >>> + vma->vm_page_prot); >> >> Per patch 1 cma_obj->paddr is the dma address, while remap_pfn_range >> expects a physical address. This does not work. > > Ok, what would be the correct way to mmap_noncoherent? Waiting for your input here :) Cheers, -Paul
diff --git a/drivers/gpu/drm/drm_gem_cma_helper.c b/drivers/gpu/drm/drm_gem_cma_helper.c index 3bdd67795e20..4ed63f4896bd 100644 --- a/drivers/gpu/drm/drm_gem_cma_helper.c +++ b/drivers/gpu/drm/drm_gem_cma_helper.c @@ -387,6 +387,45 @@ int drm_gem_cma_mmap(struct file *filp, struct vm_area_struct *vma) } EXPORT_SYMBOL_GPL(drm_gem_cma_mmap); +/** + * drm_gem_cma_mmap_noncoherent - memory-map a CMA GEM object with + * non-coherent cache attribute + * @filp: file object + * @vma: VMA for the area to be mapped + * + * Just like drm_gem_cma_mmap, but for a GEM object backed by non-coherent + * memory. + * + * Returns: + * 0 on success or a negative error code on failure. + */ +int drm_gem_cma_mmap_noncoherent(struct file *filp, struct vm_area_struct *vma) +{ + struct drm_gem_cma_object *cma_obj; + int ret; + + ret = drm_gem_mmap(filp, vma); + if (ret) + return ret; + + cma_obj = to_drm_gem_cma_obj(vma->vm_private_data); + + /* + * Clear the VM_PFNMAP flag that was set by drm_gem_mmap(), and set the + * vm_pgoff (used as a fake buffer offset by DRM) to 0 as we want to map + * the whole buffer. + */ + vma->vm_flags &= ~VM_PFNMAP; + vma->vm_pgoff = 0; + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags); + + return remap_pfn_range(vma, vma->vm_start, + cma_obj->paddr >> PAGE_SHIFT, + vma->vm_end - vma->vm_start, + vma->vm_page_prot); +} +EXPORT_SYMBOL_GPL(drm_gem_cma_mmap_noncoherent); + #ifndef CONFIG_MMU /** * drm_gem_cma_get_unmapped_area - propose address for mapping in noMMU cases diff --git a/include/drm/drm_gem_cma_helper.h b/include/drm/drm_gem_cma_helper.h index d0e6a1cd0950..6b01ad5581c3 100644 --- a/include/drm/drm_gem_cma_helper.h +++ b/include/drm/drm_gem_cma_helper.h @@ -83,6 +83,8 @@ int drm_gem_cma_dumb_create_noncoherent(struct drm_file *file_priv, /* set vm_flags and we can change the VM attribute to other one at here */ int drm_gem_cma_mmap(struct file *filp, struct vm_area_struct *vma); +int drm_gem_cma_mmap_noncoherent(struct file *filep, struct vm_area_struct *vma); + /* allocate physical memory */ struct drm_gem_cma_object *drm_gem_cma_create(struct drm_device *drm, size_t size);
This function can be used by drivers that need to mmap dumb buffers created with non-coherent backing memory. Signed-off-by: Paul Cercueil <paul@crapouillou.net> --- drivers/gpu/drm/drm_gem_cma_helper.c | 39 ++++++++++++++++++++++++++++ include/drm/drm_gem_cma_helper.h | 2 ++ 2 files changed, 41 insertions(+)