Skip to content

Commit 7d08df5

Browse files
committed
drm/ttm: Add ttm_bo_access
Non-contiguous VRAM cannot easily be mapped in TTM nor can non-visible VRAM easily be accessed. Add ttm_bo_access, which is similar to ttm_bo_vm_access, to access such memory. v4: - Fix checkpatch warnings (CI) v5: - Fix checkpatch warnings (CI) v6: - Fix kernel doc (Auld) v7: - Move ttm_bo_access to ttm_bo_vm.c (Christian) Cc: Christian König <christian.koenig@amd.com> Reported-by: Christoph Manszewski <christoph.manszewski@intel.com> Suggested-by: Thomas Hellström <thomas.hellstrom@linux.intel.com> Signed-off-by: Matthew Brost <matthew.brost@intel.com> Tested-by: Mika Kuoppala <mika.kuoppala@linux.intel.com> Reviewed-by: Matthew Auld <matthew.auld@intel.com> Reviewed-by: Christian König <christian.koenig@amd.com> Link: https://patchwork.freedesktop.org/patch/msgid/20241126174615.2665852-3-matthew.brost@intel.com
1 parent f85dc3c commit 7d08df5

2 files changed

Lines changed: 34 additions & 8 deletions

File tree

drivers/gpu/drm/ttm/ttm_bo_vm.c

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -405,13 +405,25 @@ static int ttm_bo_vm_access_kmap(struct ttm_buffer_object *bo,
405405
return len;
406406
}
407407

408-
int ttm_bo_vm_access(struct vm_area_struct *vma, unsigned long addr,
409-
void *buf, int len, int write)
408+
/**
409+
* ttm_bo_access - Helper to access a buffer object
410+
*
411+
* @bo: ttm buffer object
412+
* @offset: access offset into buffer object
413+
* @buf: pointer to caller memory to read into or write from
414+
* @len: length of access
415+
* @write: write access
416+
*
417+
* Utility function to access a buffer object. Useful when buffer object cannot
418+
* be easily mapped (non-contiguous, non-visible, etc...). Should not directly
419+
* be exported to user space via a peak / poke interface.
420+
*
421+
* Returns:
422+
* @len if successful, negative error code on failure.
423+
*/
424+
int ttm_bo_access(struct ttm_buffer_object *bo, unsigned long offset,
425+
void *buf, int len, int write)
410426
{
411-
struct ttm_buffer_object *bo = vma->vm_private_data;
412-
unsigned long offset = (addr) - vma->vm_start +
413-
((vma->vm_pgoff - drm_vma_node_start(&bo->base.vma_node))
414-
<< PAGE_SHIFT);
415427
int ret;
416428

417429
if (len < 1 || (offset + len) > bo->base.size)
@@ -429,8 +441,8 @@ int ttm_bo_vm_access(struct vm_area_struct *vma, unsigned long addr,
429441
break;
430442
default:
431443
if (bo->bdev->funcs->access_memory)
432-
ret = bo->bdev->funcs->access_memory(
433-
bo, offset, buf, len, write);
444+
ret = bo->bdev->funcs->access_memory
445+
(bo, offset, buf, len, write);
434446
else
435447
ret = -EIO;
436448
}
@@ -439,6 +451,18 @@ int ttm_bo_vm_access(struct vm_area_struct *vma, unsigned long addr,
439451

440452
return ret;
441453
}
454+
EXPORT_SYMBOL(ttm_bo_access);
455+
456+
int ttm_bo_vm_access(struct vm_area_struct *vma, unsigned long addr,
457+
void *buf, int len, int write)
458+
{
459+
struct ttm_buffer_object *bo = vma->vm_private_data;
460+
unsigned long offset = (addr) - vma->vm_start +
461+
((vma->vm_pgoff - drm_vma_node_start(&bo->base.vma_node))
462+
<< PAGE_SHIFT);
463+
464+
return ttm_bo_access(bo, offset, buf, len, write);
465+
}
442466
EXPORT_SYMBOL(ttm_bo_vm_access);
443467

444468
static const struct vm_operations_struct ttm_bo_vm_ops = {

include/drm/ttm/ttm_bo.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,8 @@ void ttm_bo_unpin(struct ttm_buffer_object *bo);
421421
int ttm_bo_evict_first(struct ttm_device *bdev,
422422
struct ttm_resource_manager *man,
423423
struct ttm_operation_ctx *ctx);
424+
int ttm_bo_access(struct ttm_buffer_object *bo, unsigned long offset,
425+
void *buf, int len, int write);
424426
vm_fault_t ttm_bo_vm_reserve(struct ttm_buffer_object *bo,
425427
struct vm_fault *vmf);
426428
vm_fault_t ttm_bo_vm_fault_reserved(struct vm_fault *vmf,

0 commit comments

Comments
 (0)